alsa.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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_create(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. alsa_card->dev = dev;
  28. strlcpy(alsa_card->driver, "AppleOnbdAudio", sizeof(alsa_card->driver));
  29. strlcpy(alsa_card->shortname, name, sizeof(alsa_card->shortname));
  30. strlcpy(alsa_card->longname, name, sizeof(alsa_card->longname));
  31. strlcpy(alsa_card->mixername, name, sizeof(alsa_card->mixername));
  32. err = snd_card_register(aoa_card->alsa_card);
  33. if (err < 0) {
  34. printk(KERN_ERR "snd-aoa: couldn't register alsa card\n");
  35. snd_card_free(aoa_card->alsa_card);
  36. aoa_card = NULL;
  37. return err;
  38. }
  39. return 0;
  40. }
  41. struct snd_card *aoa_get_card(void)
  42. {
  43. if (aoa_card)
  44. return aoa_card->alsa_card;
  45. return NULL;
  46. }
  47. EXPORT_SYMBOL_GPL(aoa_get_card);
  48. void aoa_alsa_cleanup(void)
  49. {
  50. if (aoa_card) {
  51. snd_card_free(aoa_card->alsa_card);
  52. aoa_card = NULL;
  53. }
  54. }
  55. int aoa_snd_device_new(snd_device_type_t type,
  56. void * device_data, struct snd_device_ops * ops)
  57. {
  58. struct snd_card *card = aoa_get_card();
  59. int err;
  60. if (!card) return -ENOMEM;
  61. err = snd_device_new(card, type, device_data, ops);
  62. if (err) {
  63. printk(KERN_ERR "snd-aoa: failed to create snd device (%d)\n", err);
  64. return err;
  65. }
  66. err = snd_device_register(card, device_data);
  67. if (err) {
  68. printk(KERN_ERR "snd-aoa: failed to register "
  69. "snd device (%d)\n", err);
  70. printk(KERN_ERR "snd-aoa: have you forgotten the "
  71. "dev_register callback?\n");
  72. snd_device_free(card, device_data);
  73. }
  74. return err;
  75. }
  76. EXPORT_SYMBOL_GPL(aoa_snd_device_new);
  77. int aoa_snd_ctl_add(struct snd_kcontrol* control)
  78. {
  79. int err;
  80. if (!aoa_card) return -ENODEV;
  81. err = snd_ctl_add(aoa_card->alsa_card, control);
  82. if (err)
  83. printk(KERN_ERR "snd-aoa: failed to add alsa control (%d)\n",
  84. err);
  85. return err;
  86. }
  87. EXPORT_SYMBOL_GPL(aoa_snd_ctl_add);