alsa.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Apple Onboard Audio Alsa helpers
  3. *
  4. * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
  5. *
  6. * GPL v2, can be found in COPYING.
  7. */
  8. #include <linux/module.h>
  9. #include "alsa.h"
  10. static int index = -1;
  11. module_param(index, int, 0444);
  12. MODULE_PARM_DESC(index, "index for AOA sound card.");
  13. static struct aoa_card *aoa_card;
  14. int aoa_alsa_init(char *name, struct module *mod, struct device *dev)
  15. {
  16. struct snd_card *alsa_card;
  17. int err;
  18. if (aoa_card)
  19. /* cannot be EEXIST due to usage in aoa_fabric_register */
  20. return -EBUSY;
  21. err = snd_card_new(dev, index, name, mod, sizeof(struct aoa_card),
  22. &alsa_card);
  23. if (err < 0)
  24. return err;
  25. aoa_card = alsa_card->private_data;
  26. aoa_card->alsa_card = alsa_card;
  27. strlcpy(alsa_card->driver, "AppleOnbdAudio", sizeof(alsa_card->driver));
  28. strlcpy(alsa_card->shortname, name, sizeof(alsa_card->shortname));
  29. strlcpy(alsa_card->longname, name, sizeof(alsa_card->longname));
  30. strlcpy(alsa_card->mixername, name, sizeof(alsa_card->mixername));
  31. err = snd_card_register(aoa_card->alsa_card);
  32. if (err < 0) {
  33. printk(KERN_ERR "snd-aoa: couldn't register alsa card\n");
  34. snd_card_free(aoa_card->alsa_card);
  35. aoa_card = NULL;
  36. return err;
  37. }
  38. return 0;
  39. }
  40. struct snd_card *aoa_get_card(void)
  41. {
  42. if (aoa_card)
  43. return aoa_card->alsa_card;
  44. return NULL;
  45. }
  46. EXPORT_SYMBOL_GPL(aoa_get_card);
  47. void aoa_alsa_cleanup(void)
  48. {
  49. if (aoa_card) {
  50. snd_card_free(aoa_card->alsa_card);
  51. aoa_card = NULL;
  52. }
  53. }
  54. int aoa_snd_device_new(enum snd_device_type type,
  55. void * device_data, struct snd_device_ops * ops)
  56. {
  57. struct snd_card *card = aoa_get_card();
  58. int err;
  59. if (!card) return -ENOMEM;
  60. err = snd_device_new(card, type, device_data, ops);
  61. if (err) {
  62. printk(KERN_ERR "snd-aoa: failed to create snd device (%d)\n", err);
  63. return err;
  64. }
  65. err = snd_device_register(card, device_data);
  66. if (err) {
  67. printk(KERN_ERR "snd-aoa: failed to register "
  68. "snd device (%d)\n", err);
  69. printk(KERN_ERR "snd-aoa: have you forgotten the "
  70. "dev_register callback?\n");
  71. snd_device_free(card, device_data);
  72. }
  73. return err;
  74. }
  75. EXPORT_SYMBOL_GPL(aoa_snd_device_new);
  76. int aoa_snd_ctl_add(struct snd_kcontrol* control)
  77. {
  78. int err;
  79. if (!aoa_card) return -ENODEV;
  80. err = snd_ctl_add(aoa_card->alsa_card, control);
  81. if (err)
  82. printk(KERN_ERR "snd-aoa: failed to add alsa control (%d)\n",
  83. err);
  84. return err;
  85. }
  86. EXPORT_SYMBOL_GPL(aoa_snd_ctl_add);