1 // SPDX-License-Identifier: GPL-2.0-only << 2 /* 1 /* 3 * AdLib FM card driver. 2 * AdLib FM card driver. 4 */ 3 */ 5 4 6 #include <linux/kernel.h> 5 #include <linux/kernel.h> 7 #include <linux/module.h> 6 #include <linux/module.h> 8 #include <linux/isa.h> 7 #include <linux/isa.h> 9 #include <sound/core.h> 8 #include <sound/core.h> 10 #include <sound/initval.h> 9 #include <sound/initval.h> 11 #include <sound/opl3.h> 10 #include <sound/opl3.h> 12 11 13 #define CRD_NAME "AdLib FM" 12 #define CRD_NAME "AdLib FM" 14 #define DEV_NAME "adlib" 13 #define DEV_NAME "adlib" 15 14 16 MODULE_DESCRIPTION(CRD_NAME); 15 MODULE_DESCRIPTION(CRD_NAME); 17 MODULE_AUTHOR("Rene Herman"); 16 MODULE_AUTHOR("Rene Herman"); 18 MODULE_LICENSE("GPL"); 17 MODULE_LICENSE("GPL"); 19 18 20 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_ 19 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; 21 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_S 20 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; 22 static bool enable[SNDRV_CARDS] = SNDRV_DEFAUL !! 21 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; 23 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_ 22 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; 24 23 25 module_param_array(index, int, NULL, 0444); 24 module_param_array(index, int, NULL, 0444); 26 MODULE_PARM_DESC(index, "Index value for " CRD 25 MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard."); 27 module_param_array(id, charp, NULL, 0444); 26 module_param_array(id, charp, NULL, 0444); 28 MODULE_PARM_DESC(id, "ID string for " CRD_NAME 27 MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard."); 29 module_param_array(enable, bool, NULL, 0444); 28 module_param_array(enable, bool, NULL, 0444); 30 MODULE_PARM_DESC(enable, "Enable " CRD_NAME " 29 MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard."); 31 module_param_hw_array(port, long, ioport, NULL !! 30 module_param_array(port, long, NULL, 0444); 32 MODULE_PARM_DESC(port, "Port # for " CRD_NAME 31 MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver."); 33 32 34 static int snd_adlib_match(struct device *dev, !! 33 static int __devinit snd_adlib_match(struct device *dev, unsigned int n) 35 { 34 { 36 if (!enable[n]) 35 if (!enable[n]) 37 return 0; 36 return 0; 38 37 39 if (port[n] == SNDRV_AUTO_PORT) { 38 if (port[n] == SNDRV_AUTO_PORT) { 40 dev_err(dev, "please specify p 39 dev_err(dev, "please specify port\n"); 41 return 0; 40 return 0; 42 } 41 } 43 return 1; 42 return 1; 44 } 43 } 45 44 46 static int snd_adlib_probe(struct device *dev, !! 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) 47 { 51 { 48 struct snd_card *card; 52 struct snd_card *card; 49 struct snd_opl3 *opl3; 53 struct snd_opl3 *opl3; 50 int error; 54 int error; 51 55 52 error = snd_devm_card_new(dev, index[n !! 56 error = snd_card_create(index[n], id[n], THIS_MODULE, 0, &card); 53 if (error < 0) { 57 if (error < 0) { 54 dev_err(dev, "could not create 58 dev_err(dev, "could not create card\n"); 55 return error; 59 return error; 56 } 60 } 57 61 58 card->private_data = devm_request_regi !! 62 card->private_data = request_region(port[n], 4, CRD_NAME); 59 if (!card->private_data) { 63 if (!card->private_data) { 60 dev_err(dev, "could not grab p 64 dev_err(dev, "could not grab ports\n"); 61 return -EBUSY; !! 65 error = -EBUSY; >> 66 goto out; 62 } 67 } >> 68 card->private_free = snd_adlib_free; 63 69 64 strcpy(card->driver, DEV_NAME); 70 strcpy(card->driver, DEV_NAME); 65 strcpy(card->shortname, CRD_NAME); 71 strcpy(card->shortname, CRD_NAME); 66 sprintf(card->longname, CRD_NAME " at 72 sprintf(card->longname, CRD_NAME " at %#lx", port[n]); 67 73 68 error = snd_opl3_create(card, port[n], 74 error = snd_opl3_create(card, port[n], port[n] + 2, OPL3_HW_AUTO, 1, &opl3); 69 if (error < 0) { 75 if (error < 0) { 70 dev_err(dev, "could not create 76 dev_err(dev, "could not create OPL\n"); 71 return error; !! 77 goto out; 72 } 78 } 73 79 74 error = snd_opl3_hwdep_new(opl3, 0, 0, 80 error = snd_opl3_hwdep_new(opl3, 0, 0, NULL); 75 if (error < 0) { 81 if (error < 0) { 76 dev_err(dev, "could not create 82 dev_err(dev, "could not create FM\n"); 77 return error; !! 83 goto out; 78 } 84 } 79 85 >> 86 snd_card_set_dev(card, dev); >> 87 80 error = snd_card_register(card); 88 error = snd_card_register(card); 81 if (error < 0) { 89 if (error < 0) { 82 dev_err(dev, "could not regist 90 dev_err(dev, "could not register card\n"); 83 return error; !! 91 goto out; 84 } 92 } 85 93 86 dev_set_drvdata(dev, card); 94 dev_set_drvdata(dev, card); 87 return 0; 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; 88 } 106 } 89 107 90 static struct isa_driver snd_adlib_driver = { 108 static struct isa_driver snd_adlib_driver = { 91 .match = snd_adlib_match, 109 .match = snd_adlib_match, 92 .probe = snd_adlib_probe, 110 .probe = snd_adlib_probe, >> 111 .remove = __devexit_p(snd_adlib_remove), 93 112 94 .driver = { 113 .driver = { 95 .name = DEV_NAME 114 .name = DEV_NAME 96 } 115 } 97 }; 116 }; 98 117 99 module_isa_driver(snd_adlib_driver, SNDRV_CARD !! 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); 100 130
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.