adlib.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * AdLib FM card driver.
  3. */
  4. #include <sound/driver.h>
  5. #include <linux/kernel.h>
  6. #include <linux/module.h>
  7. #include <linux/isa.h>
  8. #include <sound/core.h>
  9. #include <sound/initval.h>
  10. #include <sound/opl3.h>
  11. #define CRD_NAME "AdLib FM"
  12. #define DEV_NAME "adlib"
  13. MODULE_DESCRIPTION(CRD_NAME);
  14. MODULE_AUTHOR("Rene Herman");
  15. MODULE_LICENSE("GPL");
  16. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
  17. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
  18. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;
  19. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  20. module_param_array(index, int, NULL, 0444);
  21. MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
  22. module_param_array(id, charp, NULL, 0444);
  23. MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
  24. module_param_array(enable, bool, NULL, 0444);
  25. MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
  26. module_param_array(port, long, NULL, 0444);
  27. MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
  28. static int __devinit snd_adlib_match(struct device *dev, unsigned int n)
  29. {
  30. if (!enable[n])
  31. return 0;
  32. if (port[n] == SNDRV_AUTO_PORT) {
  33. snd_printk(KERN_ERR "%s: please specify port\n", dev->bus_id);
  34. return 0;
  35. }
  36. return 1;
  37. }
  38. static void snd_adlib_free(struct snd_card *card)
  39. {
  40. release_and_free_resource(card->private_data);
  41. }
  42. static int __devinit snd_adlib_probe(struct device *dev, unsigned int n)
  43. {
  44. struct snd_card *card;
  45. struct snd_opl3 *opl3;
  46. int error;
  47. card = snd_card_new(index[n], id[n], THIS_MODULE, 0);
  48. if (!card) {
  49. snd_printk(KERN_ERR "%s: could not create card\n", dev->bus_id);
  50. return -EINVAL;
  51. }
  52. card->private_data = request_region(port[n], 4, CRD_NAME);
  53. if (!card->private_data) {
  54. snd_printk(KERN_ERR "%s: could not grab ports\n", dev->bus_id);
  55. error = -EBUSY;
  56. goto out;
  57. }
  58. card->private_free = snd_adlib_free;
  59. strcpy(card->driver, DEV_NAME);
  60. strcpy(card->shortname, CRD_NAME);
  61. sprintf(card->longname, CRD_NAME " at %#lx", port[n]);
  62. error = snd_opl3_create(card, port[n], port[n] + 2, OPL3_HW_AUTO, 1, &opl3);
  63. if (error < 0) {
  64. snd_printk(KERN_ERR "%s: could not create OPL\n", dev->bus_id);
  65. goto out;
  66. }
  67. error = snd_opl3_hwdep_new(opl3, 0, 0, NULL);
  68. if (error < 0) {
  69. snd_printk(KERN_ERR "%s: could not create FM\n", dev->bus_id);
  70. goto out;
  71. }
  72. snd_card_set_dev(card, dev);
  73. error = snd_card_register(card);
  74. if (error < 0) {
  75. snd_printk(KERN_ERR "%s: could not register card\n", dev->bus_id);
  76. goto out;
  77. }
  78. dev_set_drvdata(dev, card);
  79. return 0;
  80. out: snd_card_free(card);
  81. return error;
  82. }
  83. static int __devexit snd_adlib_remove(struct device *dev, unsigned int n)
  84. {
  85. snd_card_free(dev_get_drvdata(dev));
  86. dev_set_drvdata(dev, NULL);
  87. return 0;
  88. }
  89. static struct isa_driver snd_adlib_driver = {
  90. .match = snd_adlib_match,
  91. .probe = snd_adlib_probe,
  92. .remove = __devexit_p(snd_adlib_remove),
  93. .driver = {
  94. .name = DEV_NAME
  95. }
  96. };
  97. static int __init alsa_card_adlib_init(void)
  98. {
  99. return isa_register_driver(&snd_adlib_driver, SNDRV_CARDS);
  100. }
  101. static void __exit alsa_card_adlib_exit(void)
  102. {
  103. isa_unregister_driver(&snd_adlib_driver);
  104. }
  105. module_init(alsa_card_adlib_init);
  106. module_exit(alsa_card_adlib_exit);