blob: d68720724c91903cd593452e74c81029d6097317 [file] [log] [blame]
Rene Hermancf40a312006-03-28 12:38:20 +02001/*
2 * AdLib FM card driver.
3 */
4
5#include <sound/driver.h>
6#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;
22static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;
23static 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.");
31module_param_array(port, long, NULL, 0444);
32MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
33
Rene Hermanab7942b2007-02-14 13:23:16 +010034static int __devinit snd_adlib_match(struct device *dev, unsigned int n)
35{
36 if (!enable[n])
37 return 0;
38
39 if (port[n] == SNDRV_AUTO_PORT) {
40 snd_printk(KERN_ERR "%s: please specify port\n", dev->bus_id);
41 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
Rene Hermanab7942b2007-02-14 13:23:16 +010051static int __devinit 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
Rene Hermanab7942b2007-02-14 13:23:16 +010057 card = snd_card_new(index[n], id[n], THIS_MODULE, 0);
Rene Hermancf40a312006-03-28 12:38:20 +020058 if (!card) {
Rene Hermanab7942b2007-02-14 13:23:16 +010059 snd_printk(KERN_ERR "%s: could not create card\n", dev->bus_id);
60 return -EINVAL;
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) {
Rene Hermanab7942b2007-02-14 13:23:16 +010065 snd_printk(KERN_ERR "%s: could not grab ports\n", dev->bus_id);
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) {
Rene Hermanab7942b2007-02-14 13:23:16 +010077 snd_printk(KERN_ERR "%s: could not create OPL\n", dev->bus_id);
78 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) {
Rene Hermanab7942b2007-02-14 13:23:16 +010083 snd_printk(KERN_ERR "%s: could not create FM\n", dev->bus_id);
84 goto out;
Rene Hermancf40a312006-03-28 12:38:20 +020085 }
86
Rene Hermanab7942b2007-02-14 13:23:16 +010087 snd_card_set_dev(card, dev);
Rene Hermancf40a312006-03-28 12:38:20 +020088
89 error = snd_card_register(card);
90 if (error < 0) {
Rene Hermanab7942b2007-02-14 13:23:16 +010091 snd_printk(KERN_ERR "%s: could not register card\n", dev->bus_id);
92 goto out;
Rene Hermancf40a312006-03-28 12:38:20 +020093 }
94
Rene Hermanab7942b2007-02-14 13:23:16 +010095 dev_set_drvdata(dev, card);
Rene Hermancf40a312006-03-28 12:38:20 +020096 return 0;
97
Rene Hermanab7942b2007-02-14 13:23:16 +010098out: snd_card_free(card);
99 return error;
Rene Hermancf40a312006-03-28 12:38:20 +0200100}
101
Rene Hermanab7942b2007-02-14 13:23:16 +0100102static int __devexit snd_adlib_remove(struct device *dev, unsigned int n)
Rene Hermancf40a312006-03-28 12:38:20 +0200103{
Rene Hermanab7942b2007-02-14 13:23:16 +0100104 snd_card_free(dev_get_drvdata(dev));
105 dev_set_drvdata(dev, NULL);
Rene Hermancf40a312006-03-28 12:38:20 +0200106 return 0;
107}
108
Rene Hermanab7942b2007-02-14 13:23:16 +0100109static struct isa_driver snd_adlib_driver = {
110 .match = snd_adlib_match,
Rene Hermancf40a312006-03-28 12:38:20 +0200111 .probe = snd_adlib_probe,
112 .remove = __devexit_p(snd_adlib_remove),
113
114 .driver = {
Rene Hermanab7942b2007-02-14 13:23:16 +0100115 .name = DEV_NAME
Rene Hermancf40a312006-03-28 12:38:20 +0200116 }
117};
118
119static int __init alsa_card_adlib_init(void)
120{
Rene Hermanab7942b2007-02-14 13:23:16 +0100121 return isa_register_driver(&snd_adlib_driver, SNDRV_CARDS);
Rene Hermancf40a312006-03-28 12:38:20 +0200122}
123
124static void __exit alsa_card_adlib_exit(void)
125{
Rene Hermanab7942b2007-02-14 13:23:16 +0100126 isa_unregister_driver(&snd_adlib_driver);
Rene Hermancf40a312006-03-28 12:38:20 +0200127}
128
129module_init(alsa_card_adlib_init);
130module_exit(alsa_card_adlib_exit);