blob: 5105524b6f3866495f53cbdfef5c6b822f8c2aa9 [file] [log] [blame]
Thomas Gleixner09c434b2019-05-19 13:08:20 +01001// SPDX-License-Identifier: GPL-2.0-only
Rene Hermancf40a312006-03-28 12:38:20 +02002/*
3 * AdLib FM card driver.
4 */
5
Rene Hermancf40a312006-03-28 12:38:20 +02006#include <linux/kernel.h>
7#include <linux/module.h>
Rene Hermanab7942b2007-02-14 13:23:16 +01008#include <linux/isa.h>
Rene Hermancf40a312006-03-28 12:38:20 +02009#include <sound/core.h>
10#include <sound/initval.h>
11#include <sound/opl3.h>
12
13#define CRD_NAME "AdLib FM"
Rene Hermanab7942b2007-02-14 13:23:16 +010014#define DEV_NAME "adlib"
Rene Hermancf40a312006-03-28 12:38:20 +020015
16MODULE_DESCRIPTION(CRD_NAME);
17MODULE_AUTHOR("Rene Herman");
18MODULE_LICENSE("GPL");
19
20static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
21static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
Rusty Russella67ff6a2011-12-15 13:49:36 +103022static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;
Rene Hermancf40a312006-03-28 12:38:20 +020023static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
24
25module_param_array(index, int, NULL, 0444);
26MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
27module_param_array(id, charp, NULL, 0444);
28MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
29module_param_array(enable, bool, NULL, 0444);
30MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
David Howellse992ef52017-04-04 16:54:30 +010031module_param_hw_array(port, long, ioport, NULL, 0444);
Rene Hermancf40a312006-03-28 12:38:20 +020032MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
33
Bill Pemberton1bff2922012-12-06 12:35:21 -050034static int snd_adlib_match(struct device *dev, unsigned int n)
Rene Hermanab7942b2007-02-14 13:23:16 +010035{
36 if (!enable[n])
37 return 0;
38
39 if (port[n] == SNDRV_AUTO_PORT) {
Takashi Iwai0418ff02008-11-03 08:51:33 +010040 dev_err(dev, "please specify port\n");
Rene Hermanab7942b2007-02-14 13:23:16 +010041 return 0;
42 }
43 return 1;
44}
Rene Hermancf40a312006-03-28 12:38:20 +020045
46static void snd_adlib_free(struct snd_card *card)
47{
48 release_and_free_resource(card->private_data);
49}
50
Bill Pemberton1bff2922012-12-06 12:35:21 -050051static int snd_adlib_probe(struct device *dev, unsigned int n)
Rene Hermancf40a312006-03-28 12:38:20 +020052{
53 struct snd_card *card;
54 struct snd_opl3 *opl3;
Rene Hermanab7942b2007-02-14 13:23:16 +010055 int error;
Rene Hermancf40a312006-03-28 12:38:20 +020056
Takashi Iwai4323cc42014-01-29 13:03:56 +010057 error = snd_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
Takashi Iwaic95eadd2008-12-28 16:43:35 +010058 if (error < 0) {
Takashi Iwai0418ff02008-11-03 08:51:33 +010059 dev_err(dev, "could not create card\n");
Takashi Iwaic95eadd2008-12-28 16:43:35 +010060 return error;
Rene Hermancf40a312006-03-28 12:38:20 +020061 }
62
Rene Hermanab7942b2007-02-14 13:23:16 +010063 card->private_data = request_region(port[n], 4, CRD_NAME);
Rene Hermancf40a312006-03-28 12:38:20 +020064 if (!card->private_data) {
Takashi Iwai0418ff02008-11-03 08:51:33 +010065 dev_err(dev, "could not grab ports\n");
Rene Hermancf40a312006-03-28 12:38:20 +020066 error = -EBUSY;
Rene Hermanab7942b2007-02-14 13:23:16 +010067 goto out;
Rene Hermancf40a312006-03-28 12:38:20 +020068 }
69 card->private_free = snd_adlib_free;
70
Rene Hermanab7942b2007-02-14 13:23:16 +010071 strcpy(card->driver, DEV_NAME);
72 strcpy(card->shortname, CRD_NAME);
73 sprintf(card->longname, CRD_NAME " at %#lx", port[n]);
74
75 error = snd_opl3_create(card, port[n], port[n] + 2, OPL3_HW_AUTO, 1, &opl3);
Rene Hermancf40a312006-03-28 12:38:20 +020076 if (error < 0) {
Takashi Iwai0418ff02008-11-03 08:51:33 +010077 dev_err(dev, "could not create OPL\n");
Rene Hermanab7942b2007-02-14 13:23:16 +010078 goto out;
Rene Hermancf40a312006-03-28 12:38:20 +020079 }
80
81 error = snd_opl3_hwdep_new(opl3, 0, 0, NULL);
82 if (error < 0) {
Takashi Iwai0418ff02008-11-03 08:51:33 +010083 dev_err(dev, "could not create FM\n");
Rene Hermanab7942b2007-02-14 13:23:16 +010084 goto out;
Rene Hermancf40a312006-03-28 12:38:20 +020085 }
86
Rene Hermancf40a312006-03-28 12:38:20 +020087 error = snd_card_register(card);
88 if (error < 0) {
Takashi Iwai0418ff02008-11-03 08:51:33 +010089 dev_err(dev, "could not register card\n");
Rene Hermanab7942b2007-02-14 13:23:16 +010090 goto out;
Rene Hermancf40a312006-03-28 12:38:20 +020091 }
92
Rene Hermanab7942b2007-02-14 13:23:16 +010093 dev_set_drvdata(dev, card);
Rene Hermancf40a312006-03-28 12:38:20 +020094 return 0;
95
Rene Hermanab7942b2007-02-14 13:23:16 +010096out: snd_card_free(card);
97 return error;
Rene Hermancf40a312006-03-28 12:38:20 +020098}
99
Bill Pemberton1bff2922012-12-06 12:35:21 -0500100static int snd_adlib_remove(struct device *dev, unsigned int n)
Rene Hermancf40a312006-03-28 12:38:20 +0200101{
Rene Hermanab7942b2007-02-14 13:23:16 +0100102 snd_card_free(dev_get_drvdata(dev));
Rene Hermancf40a312006-03-28 12:38:20 +0200103 return 0;
104}
105
Rene Hermanab7942b2007-02-14 13:23:16 +0100106static struct isa_driver snd_adlib_driver = {
107 .match = snd_adlib_match,
Rene Hermancf40a312006-03-28 12:38:20 +0200108 .probe = snd_adlib_probe,
Bill Pemberton1bff2922012-12-06 12:35:21 -0500109 .remove = snd_adlib_remove,
Rene Hermancf40a312006-03-28 12:38:20 +0200110
111 .driver = {
Rene Hermanab7942b2007-02-14 13:23:16 +0100112 .name = DEV_NAME
Rene Hermancf40a312006-03-28 12:38:20 +0200113 }
114};
115
William Breathitt Gray1524c712016-05-31 11:56:52 -0400116module_isa_driver(snd_adlib_driver, SNDRV_CARDS);