]> nv-tegra.nvidia Code Review - linux-2.6.git/blob - sound/isa/adlib.c
Merge git://git.infradead.org/battery-2.6
[linux-2.6.git] / sound / isa / adlib.c
1 /*
2  * AdLib FM card driver.
3  */
4
5 #include <sound/driver.h>
6 #include <linux/kernel.h>
7 #include <linux/module.h>
8 #include <linux/isa.h>
9 #include <sound/core.h>
10 #include <sound/initval.h>
11 #include <sound/opl3.h>
12
13 #define CRD_NAME "AdLib FM"
14 #define DEV_NAME "adlib"
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;
22 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;
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.");
31 module_param_array(port, long, NULL, 0444);
32 MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
33
34 static 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 }
45
46 static void snd_adlib_free(struct snd_card *card)
47 {
48         release_and_free_resource(card->private_data);
49 }
50
51 static int __devinit snd_adlib_probe(struct device *dev, unsigned int n)
52 {
53         struct snd_card *card;
54         struct snd_opl3 *opl3;
55         int error;
56
57         card = snd_card_new(index[n], id[n], THIS_MODULE, 0);
58         if (!card) {
59                 snd_printk(KERN_ERR "%s: could not create card\n", dev->bus_id);
60                 return -EINVAL;
61         }
62
63         card->private_data = request_region(port[n], 4, CRD_NAME);
64         if (!card->private_data) {
65                 snd_printk(KERN_ERR "%s: could not grab ports\n", dev->bus_id);
66                 error = -EBUSY;
67                 goto out;
68         }
69         card->private_free = snd_adlib_free;
70
71         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);
76         if (error < 0) {
77                 snd_printk(KERN_ERR "%s: could not create OPL\n", dev->bus_id);
78                 goto out;
79         }
80
81         error = snd_opl3_hwdep_new(opl3, 0, 0, NULL);
82         if (error < 0) {
83                 snd_printk(KERN_ERR "%s: could not create FM\n", dev->bus_id);
84                 goto out;
85         }
86
87         snd_card_set_dev(card, dev);
88
89         error = snd_card_register(card);
90         if (error < 0) {
91                 snd_printk(KERN_ERR "%s: could not register card\n", dev->bus_id);
92                 goto out;
93         }
94
95         dev_set_drvdata(dev, card);
96         return 0;
97
98 out:    snd_card_free(card);
99         return error;
100 }
101
102 static int __devexit snd_adlib_remove(struct device *dev, unsigned int n)
103 {
104         snd_card_free(dev_get_drvdata(dev));
105         dev_set_drvdata(dev, NULL);
106         return 0;
107 }
108
109 static struct isa_driver snd_adlib_driver = {
110         .match          = snd_adlib_match,
111         .probe          = snd_adlib_probe,
112         .remove         = __devexit_p(snd_adlib_remove),
113
114         .driver         = {
115                 .name   = DEV_NAME
116         }
117 };
118
119 static int __init alsa_card_adlib_init(void)
120 {
121         return isa_register_driver(&snd_adlib_driver, SNDRV_CARDS);
122 }
123
124 static void __exit alsa_card_adlib_exit(void)
125 {
126         isa_unregister_driver(&snd_adlib_driver);
127 }
128
129 module_init(alsa_card_adlib_init);
130 module_exit(alsa_card_adlib_exit);