Thomas Gleixner | 09c434b | 2019-05-19 13:08:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 2 | /* |
| 3 | * AdLib FM card driver. |
| 4 | */ |
| 5 | |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 6 | #include <linux/kernel.h> |
| 7 | #include <linux/module.h> |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 8 | #include <linux/isa.h> |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 9 | #include <sound/core.h> |
| 10 | #include <sound/initval.h> |
| 11 | #include <sound/opl3.h> |
| 12 | |
| 13 | #define CRD_NAME "AdLib FM" |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 14 | #define DEV_NAME "adlib" |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 15 | |
| 16 | MODULE_DESCRIPTION(CRD_NAME); |
| 17 | MODULE_AUTHOR("Rene Herman"); |
| 18 | MODULE_LICENSE("GPL"); |
| 19 | |
| 20 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; |
| 21 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 22 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 23 | static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; |
| 24 | |
| 25 | module_param_array(index, int, NULL, 0444); |
| 26 | MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard."); |
| 27 | module_param_array(id, charp, NULL, 0444); |
| 28 | MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard."); |
| 29 | module_param_array(enable, bool, NULL, 0444); |
| 30 | MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard."); |
David Howells | e992ef5 | 2017-04-04 16:54:30 +0100 | [diff] [blame] | 31 | module_param_hw_array(port, long, ioport, NULL, 0444); |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 32 | MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver."); |
| 33 | |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 34 | static int snd_adlib_match(struct device *dev, unsigned int n) |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 35 | { |
| 36 | if (!enable[n]) |
| 37 | return 0; |
| 38 | |
| 39 | if (port[n] == SNDRV_AUTO_PORT) { |
Takashi Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 40 | dev_err(dev, "please specify port\n"); |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 41 | return 0; |
| 42 | } |
| 43 | return 1; |
| 44 | } |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 45 | |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 46 | static int snd_adlib_probe(struct device *dev, unsigned int n) |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 47 | { |
| 48 | struct snd_card *card; |
| 49 | struct snd_opl3 *opl3; |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 50 | int error; |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 51 | |
Takashi Iwai | 5d50e34 | 2021-07-15 09:59:18 +0200 | [diff] [blame] | 52 | error = snd_devm_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card); |
Takashi Iwai | c95eadd | 2008-12-28 16:43:35 +0100 | [diff] [blame] | 53 | if (error < 0) { |
Takashi Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 54 | dev_err(dev, "could not create card\n"); |
Takashi Iwai | c95eadd | 2008-12-28 16:43:35 +0100 | [diff] [blame] | 55 | return error; |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 56 | } |
| 57 | |
Takashi Iwai | 5d50e34 | 2021-07-15 09:59:18 +0200 | [diff] [blame] | 58 | card->private_data = devm_request_region(dev, port[n], 4, CRD_NAME); |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 59 | if (!card->private_data) { |
Takashi Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 60 | dev_err(dev, "could not grab ports\n"); |
Takashi Iwai | 5d50e34 | 2021-07-15 09:59:18 +0200 | [diff] [blame] | 61 | return -EBUSY; |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 62 | } |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 63 | |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 64 | strcpy(card->driver, DEV_NAME); |
| 65 | strcpy(card->shortname, CRD_NAME); |
| 66 | sprintf(card->longname, CRD_NAME " at %#lx", port[n]); |
| 67 | |
| 68 | 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] | 69 | if (error < 0) { |
Takashi Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 70 | dev_err(dev, "could not create OPL\n"); |
Takashi Iwai | 5d50e34 | 2021-07-15 09:59:18 +0200 | [diff] [blame] | 71 | return error; |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | error = snd_opl3_hwdep_new(opl3, 0, 0, NULL); |
| 75 | if (error < 0) { |
Takashi Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 76 | dev_err(dev, "could not create FM\n"); |
Takashi Iwai | 5d50e34 | 2021-07-15 09:59:18 +0200 | [diff] [blame] | 77 | return error; |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 78 | } |
| 79 | |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 80 | error = snd_card_register(card); |
| 81 | if (error < 0) { |
Takashi Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 82 | dev_err(dev, "could not register card\n"); |
Takashi Iwai | 5d50e34 | 2021-07-15 09:59:18 +0200 | [diff] [blame] | 83 | return error; |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 84 | } |
| 85 | |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 86 | dev_set_drvdata(dev, card); |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 87 | return 0; |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 88 | } |
| 89 | |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 90 | static struct isa_driver snd_adlib_driver = { |
| 91 | .match = snd_adlib_match, |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 92 | .probe = snd_adlib_probe, |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 93 | |
| 94 | .driver = { |
Rene Herman | ab7942b | 2007-02-14 13:23:16 +0100 | [diff] [blame] | 95 | .name = DEV_NAME |
Rene Herman | cf40a31 | 2006-03-28 12:38:20 +0200 | [diff] [blame] | 96 | } |
| 97 | }; |
| 98 | |
William Breathitt Gray | 1524c71 | 2016-05-31 11:56:52 -0400 | [diff] [blame] | 99 | module_isa_driver(snd_adlib_driver, SNDRV_CARDS); |