aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sound/isa/ad1848/ad1848.c167
1 files changed, 67 insertions, 100 deletions
diff --git a/sound/isa/ad1848/ad1848.c b/sound/isa/ad1848/ad1848.c
index 74e501dea8b1..d09a7fa86545 100644
--- a/sound/isa/ad1848/ad1848.c
+++ b/sound/isa/ad1848/ad1848.c
@@ -24,7 +24,7 @@
24#include <sound/driver.h> 24#include <sound/driver.h>
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/platform_device.h> 27#include <linux/isa.h>
28#include <linux/time.h> 28#include <linux/time.h>
29#include <linux/wait.h> 29#include <linux/wait.h>
30#include <linux/moduleparam.h> 30#include <linux/moduleparam.h>
@@ -32,8 +32,11 @@
32#include <sound/ad1848.h> 32#include <sound/ad1848.h>
33#include <sound/initval.h> 33#include <sound/initval.h>
34 34
35#define CRD_NAME "Generic AD1848/AD1847/CS4248"
36#define DEV_NAME "ad1848"
37
38MODULE_DESCRIPTION(CRD_NAME);
35MODULE_AUTHOR("Tugrul Galatali <galatalt@stuy.edu>, Jaroslav Kysela <perex@suse.cz>"); 39MODULE_AUTHOR("Tugrul Galatali <galatalt@stuy.edu>, Jaroslav Kysela <perex@suse.cz>");
36MODULE_DESCRIPTION("AD1848/AD1847/CS4248");
37MODULE_LICENSE("GPL"); 40MODULE_LICENSE("GPL");
38MODULE_SUPPORTED_DEVICE("{{Analog Devices,AD1848}," 41MODULE_SUPPORTED_DEVICE("{{Analog Devices,AD1848},"
39 "{Analog Devices,AD1847}," 42 "{Analog Devices,AD1847},"
@@ -48,95 +51,98 @@ static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
48static int thinkpad[SNDRV_CARDS]; /* Thinkpad special case */ 51static int thinkpad[SNDRV_CARDS]; /* Thinkpad special case */
49 52
50module_param_array(index, int, NULL, 0444); 53module_param_array(index, int, NULL, 0444);
51MODULE_PARM_DESC(index, "Index value for AD1848 soundcard."); 54MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
52module_param_array(id, charp, NULL, 0444); 55module_param_array(id, charp, NULL, 0444);
53MODULE_PARM_DESC(id, "ID string for AD1848 soundcard."); 56MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
54module_param_array(enable, bool, NULL, 0444); 57module_param_array(enable, bool, NULL, 0444);
55MODULE_PARM_DESC(enable, "Enable AD1848 soundcard."); 58MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
56module_param_array(port, long, NULL, 0444); 59module_param_array(port, long, NULL, 0444);
57MODULE_PARM_DESC(port, "Port # for AD1848 driver."); 60MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
58module_param_array(irq, int, NULL, 0444); 61module_param_array(irq, int, NULL, 0444);
59MODULE_PARM_DESC(irq, "IRQ # for AD1848 driver."); 62MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver.");
60module_param_array(dma1, int, NULL, 0444); 63module_param_array(dma1, int, NULL, 0444);
61MODULE_PARM_DESC(dma1, "DMA1 # for AD1848 driver."); 64MODULE_PARM_DESC(dma1, "DMA1 # for " CRD_NAME " driver.");
62module_param_array(thinkpad, bool, NULL, 0444); 65module_param_array(thinkpad, bool, NULL, 0444);
63MODULE_PARM_DESC(thinkpad, "Enable only for the onboard CS4248 of IBM Thinkpad 360/750/755 series."); 66MODULE_PARM_DESC(thinkpad, "Enable only for the onboard CS4248 of IBM Thinkpad 360/750/755 series.");
64 67
65static struct platform_device *devices[SNDRV_CARDS]; 68static int __devinit snd_ad1848_match(struct device *dev, unsigned int n)
69{
70 if (!enable[n])
71 return 0;
66 72
73 if (port[n] == SNDRV_AUTO_PORT) {
74 snd_printk(KERN_ERR "%s: please specify port\n", dev->bus_id);
75 return 0;
76 }
77 if (irq[n] == SNDRV_AUTO_IRQ) {
78 snd_printk(KERN_ERR "%s: please specify irq\n", dev->bus_id);
79 return 0;
80 }
81 if (dma1[n] == SNDRV_AUTO_DMA) {
82 snd_printk(KERN_ERR "%s: please specify dma1\n", dev->bus_id);
83 return 0;
84 }
85 return 1;
86}
67 87
68static int __devinit snd_ad1848_probe(struct platform_device *pdev) 88static int __devinit snd_ad1848_probe(struct device *dev, unsigned int n)
69{ 89{
70 int dev = pdev->id;
71 struct snd_card *card; 90 struct snd_card *card;
72 struct snd_ad1848 *chip; 91 struct snd_ad1848 *chip;
73 struct snd_pcm *pcm; 92 struct snd_pcm *pcm;
74 int err; 93 int error;
75 94
76 if (port[dev] == SNDRV_AUTO_PORT) { 95 card = snd_card_new(index[n], id[n], THIS_MODULE, 0);
77 snd_printk(KERN_ERR "ad1848: specify port\n"); 96 if (!card)
78 return -EINVAL; 97 return -EINVAL;
79 }
80 if (irq[dev] == SNDRV_AUTO_IRQ) {
81 snd_printk(KERN_ERR "ad1848: specify irq\n");
82 return -EINVAL;
83 }
84 if (dma1[dev] == SNDRV_AUTO_DMA) {
85 snd_printk(KERN_ERR "ad1848: specify dma1\n");
86 return -EINVAL;
87 }
88 98
89 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 99 error = snd_ad1848_create(card, port[n], irq[n], dma1[n],
90 if (card == NULL) 100 thinkpad[n] ? AD1848_HW_THINKPAD : AD1848_HW_DETECT, &chip);
91 return -ENOMEM; 101 if (error < 0)
102 goto out;
92 103
93 if ((err = snd_ad1848_create(card, port[dev],
94 irq[dev],
95 dma1[dev],
96 thinkpad[dev] ? AD1848_HW_THINKPAD : AD1848_HW_DETECT,
97 &chip)) < 0)
98 goto _err;
99 card->private_data = chip; 104 card->private_data = chip;
100 105
101 if ((err = snd_ad1848_pcm(chip, 0, &pcm)) < 0) 106 error = snd_ad1848_pcm(chip, 0, &pcm);
102 goto _err; 107 if (error < 0)
108 goto out;
103 109
104 if ((err = snd_ad1848_mixer(chip)) < 0) 110 error = snd_ad1848_mixer(chip);
105 goto _err; 111 if (error < 0)
112 goto out;
106 113
107 strcpy(card->driver, "AD1848"); 114 strcpy(card->driver, "AD1848");
108 strcpy(card->shortname, pcm->name); 115 strcpy(card->shortname, pcm->name);
109 116
110 sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d", 117 sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
111 pcm->name, chip->port, irq[dev], dma1[dev]); 118 pcm->name, chip->port, irq[n], dma1[n]);
112 119 if (thinkpad[n])
113 if (thinkpad[dev])
114 strcat(card->longname, " [Thinkpad]"); 120 strcat(card->longname, " [Thinkpad]");
115 121
116 snd_card_set_dev(card, &pdev->dev); 122 snd_card_set_dev(card, dev);
117 123
118 if ((err = snd_card_register(card)) < 0) 124 error = snd_card_register(card);
119 goto _err; 125 if (error < 0)
126 goto out;
120 127
121 platform_set_drvdata(pdev, card); 128 dev_set_drvdata(dev, card);
122 return 0; 129 return 0;
123 130
124 _err: 131out: snd_card_free(card);
125 snd_card_free(card); 132 return error;
126 return err;
127} 133}
128 134
129static int __devexit snd_ad1848_remove(struct platform_device *devptr) 135static int __devexit snd_ad1848_remove(struct device *dev, unsigned int n)
130{ 136{
131 snd_card_free(platform_get_drvdata(devptr)); 137 snd_card_free(dev_get_drvdata(dev));
132 platform_set_drvdata(devptr, NULL); 138 dev_set_drvdata(dev, NULL);
133 return 0; 139 return 0;
134} 140}
135 141
136#ifdef CONFIG_PM 142#ifdef CONFIG_PM
137static int snd_ad1848_suspend(struct platform_device *pdev, pm_message_t state) 143static int snd_ad1848_suspend(struct device *dev, unsigned int n, pm_message_t state)
138{ 144{
139 struct snd_card *card = platform_get_drvdata(pdev); 145 struct snd_card *card = dev_get_drvdata(dev);
140 struct snd_ad1848 *chip = card->private_data; 146 struct snd_ad1848 *chip = card->private_data;
141 147
142 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 148 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
@@ -144,9 +150,9 @@ static int snd_ad1848_suspend(struct platform_device *pdev, pm_message_t state)
144 return 0; 150 return 0;
145} 151}
146 152
147static int snd_ad1848_resume(struct platform_device *pdev) 153static int snd_ad1848_resume(struct device *dev, unsigned int n)
148{ 154{
149 struct snd_card *card = platform_get_drvdata(pdev); 155 struct snd_card *card = dev_get_drvdata(dev);
150 struct snd_ad1848 *chip = card->private_data; 156 struct snd_ad1848 *chip = card->private_data;
151 157
152 chip->resume(chip); 158 chip->resume(chip);
@@ -155,9 +161,8 @@ static int snd_ad1848_resume(struct platform_device *pdev)
155} 161}
156#endif 162#endif
157 163
158#define SND_AD1848_DRIVER "snd_ad1848" 164static struct isa_driver snd_ad1848_driver = {
159 165 .match = snd_ad1848_match,
160static struct platform_driver snd_ad1848_driver = {
161 .probe = snd_ad1848_probe, 166 .probe = snd_ad1848_probe,
162 .remove = __devexit_p(snd_ad1848_remove), 167 .remove = __devexit_p(snd_ad1848_remove),
163#ifdef CONFIG_PM 168#ifdef CONFIG_PM
@@ -165,57 +170,19 @@ static struct platform_driver snd_ad1848_driver = {
165 .resume = snd_ad1848_resume, 170 .resume = snd_ad1848_resume,
166#endif 171#endif
167 .driver = { 172 .driver = {
168 .name = SND_AD1848_DRIVER 173 .name = DEV_NAME
169 }, 174 }
170}; 175};
171 176
172static void __init_or_module snd_ad1848_unregister_all(void)
173{
174 int i;
175
176 for (i = 0; i < ARRAY_SIZE(devices); ++i)
177 platform_device_unregister(devices[i]);
178 platform_driver_unregister(&snd_ad1848_driver);
179}
180
181static int __init alsa_card_ad1848_init(void) 177static int __init alsa_card_ad1848_init(void)
182{ 178{
183 int i, cards, err; 179 return isa_register_driver(&snd_ad1848_driver, SNDRV_CARDS);
184
185 err = platform_driver_register(&snd_ad1848_driver);
186 if (err < 0)
187 return err;
188
189 cards = 0;
190 for (i = 0; i < SNDRV_CARDS; i++) {
191 struct platform_device *device;
192 if (! enable[i])
193 continue;
194 device = platform_device_register_simple(SND_AD1848_DRIVER,
195 i, NULL, 0);
196 if (IS_ERR(device))
197 continue;
198 if (!platform_get_drvdata(device)) {
199 platform_device_unregister(device);
200 continue;
201 }
202 devices[i] = device;
203 cards++;
204 }
205 if (!cards) {
206#ifdef MODULE
207 printk(KERN_ERR "AD1848 soundcard not found or device busy\n");
208#endif
209 snd_ad1848_unregister_all();
210 return -ENODEV;
211 }
212 return 0;
213} 180}
214 181
215static void __exit alsa_card_ad1848_exit(void) 182static void __exit alsa_card_ad1848_exit(void)
216{ 183{
217 snd_ad1848_unregister_all(); 184 isa_unregister_driver(&snd_ad1848_driver);
218} 185}
219 186
220module_init(alsa_card_ad1848_init) 187module_init(alsa_card_ad1848_init);
221module_exit(alsa_card_ad1848_exit) 188module_exit(alsa_card_ad1848_exit);