Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 1 | /* |
| 2 | * AdLib FM card driver. |
| 3 | */ |
| 4 | |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 5 | #include <linux/kernel.h> |
| 6 | #include <linux/module.h> |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 7 | #include <linux/isa.h> |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 8 | #include <sound/core.h> |
| 9 | #include <sound/initval.h> |
| 10 | #include <sound/opl3.h> |
| 11 | |
| 12 | #define CRD_NAME "AdLib FM" |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 13 | #define DEV_NAME "adlib" |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 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; |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 21 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 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 | |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 33 | static int snd_adlib_match(struct device *dev, unsigned int n) |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 34 | { |
| 35 | if (!enable[n]) |
| 36 | return 0; |
| 37 | |
| 38 | if (port[n] == SNDRV_AUTO_PORT) { |
Takashi Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 39 | dev_err(dev, "please specify port\n"); |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 40 | return 0; |
| 41 | } |
| 42 | return 1; |
| 43 | } |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 44 | |
| 45 | static void snd_adlib_free(struct snd_card *card) |
| 46 | { |
| 47 | release_and_free_resource(card->private_data); |
| 48 | } |
| 49 | |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 50 | static int snd_adlib_probe(struct device *dev, unsigned int n) |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 51 | { |
| 52 | struct snd_card *card; |
| 53 | struct snd_opl3 *opl3; |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 54 | int error; |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 55 | |
Takashi Iwai | 4323cc4 | 2014-01-29 13:03:56 +0100 | [diff] [blame] | 56 | error = snd_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card); |
Takashi Iwai | c95eadd | 2008-12-28 16:43:35 +0100 | [diff] [blame] | 57 | if (error < 0) { |
Takashi Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 58 | dev_err(dev, "could not create card\n"); |
Takashi Iwai | c95eadd | 2008-12-28 16:43:35 +0100 | [diff] [blame] | 59 | return error; |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 60 | } |
| 61 | |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 62 | card->private_data = request_region(port[n], 4, CRD_NAME); |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 63 | if (!card->private_data) { |
Takashi Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 64 | dev_err(dev, "could not grab ports\n"); |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 65 | error = -EBUSY; |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 66 | goto out; |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 67 | } |
| 68 | card->private_free = snd_adlib_free; |
| 69 | |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 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); |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 75 | if (error < 0) { |
Takashi Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 76 | dev_err(dev, "could not create OPL\n"); |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 77 | goto out; |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | error = snd_opl3_hwdep_new(opl3, 0, 0, NULL); |
| 81 | if (error < 0) { |
Takashi Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 82 | dev_err(dev, "could not create FM\n"); |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 83 | goto out; |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 84 | } |
| 85 | |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 86 | error = snd_card_register(card); |
| 87 | if (error < 0) { |
Takashi Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 88 | dev_err(dev, "could not register card\n"); |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 89 | goto out; |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 90 | } |
| 91 | |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 92 | dev_set_drvdata(dev, card); |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 93 | return 0; |
| 94 | |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 95 | out: snd_card_free(card); |
| 96 | return error; |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 97 | } |
| 98 | |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 99 | static int snd_adlib_remove(struct device *dev, unsigned int n) |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 100 | { |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 101 | snd_card_free(dev_get_drvdata(dev)); |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 102 | return 0; |
| 103 | } |
| 104 | |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 105 | static struct isa_driver snd_adlib_driver = { |
| 106 | .match = snd_adlib_match, |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 107 | .probe = snd_adlib_probe, |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 108 | .remove = snd_adlib_remove, |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 109 | |
| 110 | .driver = { |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 111 | .name = DEV_NAME |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 112 | } |
| 113 | }; |
| 114 | |
| 115 | static int __init alsa_card_adlib_init(void) |
| 116 | { |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 117 | return isa_register_driver(&snd_adlib_driver, SNDRV_CARDS); |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | static void __exit alsa_card_adlib_exit(void) |
| 121 | { |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 122 | isa_unregister_driver(&snd_adlib_driver); |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | module_init(alsa_card_adlib_init); |
| 126 | module_exit(alsa_card_adlib_exit); |