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