blob: 35659218710f93f1d738b327f4f43c650b8043cc [file] [log] [blame]
Rene Hermancf40a312006-03-28 12:38:20 +02001/*
2 * AdLib FM card driver.
3 */
4
Rene Hermancf40a312006-03-28 12:38:20 +02005#include <linux/kernel.h>
6#include <linux/module.h>
Rene Hermanab7942b2007-02-14 13:23:16 +01007#include <linux/isa.h>
Rene Hermancf40a312006-03-28 12:38:20 +02008#include <sound/core.h>
9#include <sound/initval.h>
10#include <sound/opl3.h>
11
12#define CRD_NAME "AdLib FM"
Rene Hermanab7942b2007-02-14 13:23:16 +010013#define DEV_NAME "adlib"
Rene Hermancf40a312006-03-28 12:38:20 +020014
15MODULE_DESCRIPTION(CRD_NAME);
16MODULE_AUTHOR("Rene Herman");
17MODULE_LICENSE("GPL");
18
19static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
20static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
Rusty Russella67ff6a2011-12-15 13:49:36 +103021static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;
Rene Hermancf40a312006-03-28 12:38:20 +020022static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
23
24module_param_array(index, int, NULL, 0444);
25MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
26module_param_array(id, charp, NULL, 0444);
27MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
28module_param_array(enable, bool, NULL, 0444);
29MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
30module_param_array(port, long, NULL, 0444);
31MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
32
Bill Pemberton1bff2922012-12-06 12:35:21 -050033static int snd_adlib_match(struct device *dev, unsigned int n)
Rene Hermanab7942b2007-02-14 13:23:16 +010034{
35 if (!enable[n])
36 return 0;
37
38 if (port[n] == SNDRV_AUTO_PORT) {
Takashi Iwai0418ff02008-11-03 08:51:33 +010039 dev_err(dev, "please specify port\n");
Rene Hermanab7942b2007-02-14 13:23:16 +010040 return 0;
41 }
42 return 1;
43}
Rene Hermancf40a312006-03-28 12:38:20 +020044
45static void snd_adlib_free(struct snd_card *card)
46{
47 release_and_free_resource(card->private_data);
48}
49
Bill Pemberton1bff2922012-12-06 12:35:21 -050050static int snd_adlib_probe(struct device *dev, unsigned int n)
Rene Hermancf40a312006-03-28 12:38:20 +020051{
52 struct snd_card *card;
53 struct snd_opl3 *opl3;
Rene Hermanab7942b2007-02-14 13:23:16 +010054 int error;
Rene Hermancf40a312006-03-28 12:38:20 +020055
Takashi Iwaic95eadd2008-12-28 16:43:35 +010056 error = snd_card_create(index[n], id[n], THIS_MODULE, 0, &card);
57 if (error < 0) {
Takashi Iwai0418ff02008-11-03 08:51:33 +010058 dev_err(dev, "could not create card\n");
Takashi Iwaic95eadd2008-12-28 16:43:35 +010059 return error;
Rene Hermancf40a312006-03-28 12:38:20 +020060 }
61
Rene Hermanab7942b2007-02-14 13:23:16 +010062 card->private_data = request_region(port[n], 4, CRD_NAME);
Rene Hermancf40a312006-03-28 12:38:20 +020063 if (!card->private_data) {
Takashi Iwai0418ff02008-11-03 08:51:33 +010064 dev_err(dev, "could not grab ports\n");
Rene Hermancf40a312006-03-28 12:38:20 +020065 error = -EBUSY;
Rene Hermanab7942b2007-02-14 13:23:16 +010066 goto out;
Rene Hermancf40a312006-03-28 12:38:20 +020067 }
68 card->private_free = snd_adlib_free;
69
Rene Hermanab7942b2007-02-14 13:23:16 +010070 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 Hermancf40a312006-03-28 12:38:20 +020075 if (error < 0) {
Takashi Iwai0418ff02008-11-03 08:51:33 +010076 dev_err(dev, "could not create OPL\n");
Rene Hermanab7942b2007-02-14 13:23:16 +010077 goto out;
Rene Hermancf40a312006-03-28 12:38:20 +020078 }
79
80 error = snd_opl3_hwdep_new(opl3, 0, 0, NULL);
81 if (error < 0) {
Takashi Iwai0418ff02008-11-03 08:51:33 +010082 dev_err(dev, "could not create FM\n");
Rene Hermanab7942b2007-02-14 13:23:16 +010083 goto out;
Rene Hermancf40a312006-03-28 12:38:20 +020084 }
85
Rene Hermanab7942b2007-02-14 13:23:16 +010086 snd_card_set_dev(card, dev);
Rene Hermancf40a312006-03-28 12:38:20 +020087
88 error = snd_card_register(card);
89 if (error < 0) {
Takashi Iwai0418ff02008-11-03 08:51:33 +010090 dev_err(dev, "could not register card\n");
Rene Hermanab7942b2007-02-14 13:23:16 +010091 goto out;
Rene Hermancf40a312006-03-28 12:38:20 +020092 }
93
Rene Hermanab7942b2007-02-14 13:23:16 +010094 dev_set_drvdata(dev, card);
Rene Hermancf40a312006-03-28 12:38:20 +020095 return 0;
96
Rene Hermanab7942b2007-02-14 13:23:16 +010097out: snd_card_free(card);
98 return error;
Rene Hermancf40a312006-03-28 12:38:20 +020099}
100
Bill Pemberton1bff2922012-12-06 12:35:21 -0500101static int snd_adlib_remove(struct device *dev, unsigned int n)
Rene Hermancf40a312006-03-28 12:38:20 +0200102{
Rene Hermanab7942b2007-02-14 13:23:16 +0100103 snd_card_free(dev_get_drvdata(dev));
Rene Hermancf40a312006-03-28 12:38:20 +0200104 return 0;
105}
106
Rene Hermanab7942b2007-02-14 13:23:16 +0100107static struct isa_driver snd_adlib_driver = {
108 .match = snd_adlib_match,
Rene Hermancf40a312006-03-28 12:38:20 +0200109 .probe = snd_adlib_probe,
Bill Pemberton1bff2922012-12-06 12:35:21 -0500110 .remove = snd_adlib_remove,
Rene Hermancf40a312006-03-28 12:38:20 +0200111
112 .driver = {
Rene Hermanab7942b2007-02-14 13:23:16 +0100113 .name = DEV_NAME
Rene Hermancf40a312006-03-28 12:38:20 +0200114 }
115};
116
117static int __init alsa_card_adlib_init(void)
118{
Rene Hermanab7942b2007-02-14 13:23:16 +0100119 return isa_register_driver(&snd_adlib_driver, SNDRV_CARDS);
Rene Hermancf40a312006-03-28 12:38:20 +0200120}
121
122static void __exit alsa_card_adlib_exit(void)
123{
Rene Hermanab7942b2007-02-14 13:23:16 +0100124 isa_unregister_driver(&snd_adlib_driver);
Rene Hermancf40a312006-03-28 12:38:20 +0200125}
126
127module_init(alsa_card_adlib_init);
128module_exit(alsa_card_adlib_exit);