blob: c24594c866f458adbcdd155e025d4f2ba9c78ebf [file] [log] [blame]
Martin Langer1841f6132006-03-27 12:41:01 +02001/*
2 * ALSA soundcard driver for Miro miroSOUND PCM1 pro
3 * miroSOUND PCM12
4 * miroSOUND PCM20 Radio
5 *
6 * Copyright (C) 2004-2005 Martin Langer <martin-langer@gmx.de>
7 *
8 * Based on OSS ACI and ALSA OPTi9xx drivers
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
Martin Langer1841f6132006-03-27 12:41:01 +020025#include <linux/init.h>
26#include <linux/err.h>
Takashi Iwai5e24c1c2007-02-22 12:50:54 +010027#include <linux/isa.h>
Krzysztof Helt306ecee2009-11-30 07:46:56 +010028#include <linux/pnp.h>
Martin Langer1841f6132006-03-27 12:41:01 +020029#include <linux/delay.h>
Martin Langer1841f6132006-03-27 12:41:01 +020030#include <linux/ioport.h>
Paul Gortmaker65a77212011-07-15 13:13:37 -040031#include <linux/module.h>
Martin Langer1841f6132006-03-27 12:41:01 +020032#include <asm/io.h>
33#include <asm/dma.h>
34#include <sound/core.h>
Krzysztof Helt61ef19d2008-07-31 21:02:42 +020035#include <sound/wss.h>
Martin Langer1841f6132006-03-27 12:41:01 +020036#include <sound/mpu401.h>
37#include <sound/opl4.h>
38#include <sound/control.h>
39#include <sound/info.h>
40#define SNDRV_LEGACY_FIND_FREE_IRQ
41#define SNDRV_LEGACY_FIND_FREE_DMA
42#include <sound/initval.h>
Krzysztof Helt9aeba622009-11-22 17:23:45 +010043#include <sound/aci.h>
Martin Langer1841f6132006-03-27 12:41:01 +020044
45MODULE_AUTHOR("Martin Langer <martin-langer@gmx.de>");
46MODULE_LICENSE("GPL");
47MODULE_DESCRIPTION("Miro miroSOUND PCM1 pro, PCM12, PCM20 Radio");
48MODULE_SUPPORTED_DEVICE("{{Miro,miroSOUND PCM1 pro}, "
49 "{Miro,miroSOUND PCM12}, "
50 "{Miro,miroSOUND PCM20 Radio}}");
51
52static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
53static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
54static long port = SNDRV_DEFAULT_PORT1; /* 0x530,0xe80,0xf40,0x604 */
55static long mpu_port = SNDRV_DEFAULT_PORT1; /* 0x300,0x310,0x320,0x330 */
56static long fm_port = SNDRV_DEFAULT_PORT1; /* 0x388 */
57static int irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10,11 */
58static int mpu_irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10 */
59static int dma1 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */
60static int dma2 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */
61static int wss;
62static int ide;
Krzysztof Helt306ecee2009-11-30 07:46:56 +010063#ifdef CONFIG_PNP
Rusty Russella67ff6a2011-12-15 13:49:36 +103064static bool isapnp = 1; /* Enable ISA PnP detection */
Krzysztof Helt306ecee2009-11-30 07:46:56 +010065#endif
Martin Langer1841f6132006-03-27 12:41:01 +020066
67module_param(index, int, 0444);
68MODULE_PARM_DESC(index, "Index value for miro soundcard.");
69module_param(id, charp, 0444);
70MODULE_PARM_DESC(id, "ID string for miro soundcard.");
71module_param(port, long, 0444);
72MODULE_PARM_DESC(port, "WSS port # for miro driver.");
73module_param(mpu_port, long, 0444);
74MODULE_PARM_DESC(mpu_port, "MPU-401 port # for miro driver.");
75module_param(fm_port, long, 0444);
76MODULE_PARM_DESC(fm_port, "FM Port # for miro driver.");
77module_param(irq, int, 0444);
78MODULE_PARM_DESC(irq, "WSS irq # for miro driver.");
79module_param(mpu_irq, int, 0444);
80MODULE_PARM_DESC(mpu_irq, "MPU-401 irq # for miro driver.");
81module_param(dma1, int, 0444);
82MODULE_PARM_DESC(dma1, "1st dma # for miro driver.");
83module_param(dma2, int, 0444);
84MODULE_PARM_DESC(dma2, "2nd dma # for miro driver.");
85module_param(wss, int, 0444);
86MODULE_PARM_DESC(wss, "wss mode");
87module_param(ide, int, 0444);
88MODULE_PARM_DESC(ide, "enable ide port");
Krzysztof Helt306ecee2009-11-30 07:46:56 +010089#ifdef CONFIG_PNP
90module_param(isapnp, bool, 0444);
91MODULE_PARM_DESC(isapnp, "Enable ISA PnP detection for specified soundcard.");
92#endif
Martin Langer1841f6132006-03-27 12:41:01 +020093
94#define OPTi9XX_HW_DETECT 0
95#define OPTi9XX_HW_82C928 1
96#define OPTi9XX_HW_82C929 2
97#define OPTi9XX_HW_82C924 3
98#define OPTi9XX_HW_82C925 4
99#define OPTi9XX_HW_82C930 5
100#define OPTi9XX_HW_82C931 6
101#define OPTi9XX_HW_82C933 7
102#define OPTi9XX_HW_LAST OPTi9XX_HW_82C933
103
104#define OPTi9XX_MC_REG(n) n
105
Martin Langer1841f6132006-03-27 12:41:01 +0200106struct snd_miro {
107 unsigned short hardware;
108 unsigned char password;
109 char name[7];
110
111 struct resource *res_mc_base;
112 struct resource *res_aci_port;
113
114 unsigned long mc_base;
115 unsigned long mc_base_size;
116 unsigned long pwd_reg;
117
118 spinlock_t lock;
Martin Langer1841f6132006-03-27 12:41:01 +0200119 struct snd_pcm *pcm;
120
121 long wss_base;
122 int irq;
123 int dma1;
124 int dma2;
125
Martin Langer1841f6132006-03-27 12:41:01 +0200126 long mpu_port;
127 int mpu_irq;
128
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100129 struct snd_miro_aci *aci;
Martin Langer1841f6132006-03-27 12:41:01 +0200130};
131
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100132static struct snd_miro_aci aci_device;
133
Martin Langer1841f6132006-03-27 12:41:01 +0200134static char * snd_opti9xx_names[] = {
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200135 "unknown",
Martin Langer1841f6132006-03-27 12:41:01 +0200136 "82C928", "82C929",
137 "82C924", "82C925",
138 "82C930", "82C931", "82C933"
139};
140
Krzysztof Helt306ecee2009-11-30 07:46:56 +0100141static int snd_miro_pnp_is_probed;
142
143#ifdef CONFIG_PNP
144
145static struct pnp_card_device_id snd_miro_pnpids[] = {
146 /* PCM20 and PCM12 in PnP mode */
147 { .id = "MIR0924",
148 .devs = { { "MIR0000" }, { "MIR0002" }, { "MIR0005" } }, },
149 { .id = "" }
150};
151
152MODULE_DEVICE_TABLE(pnp_card, snd_miro_pnpids);
153
154#endif /* CONFIG_PNP */
155
Martin Langer1841f6132006-03-27 12:41:01 +0200156/*
157 * ACI control
158 */
159
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100160static int aci_busy_wait(struct snd_miro_aci *aci)
Martin Langer1841f6132006-03-27 12:41:01 +0200161{
162 long timeout;
163 unsigned char byte;
164
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100165 for (timeout = 1; timeout <= ACI_MINTIME + 30; timeout++) {
166 byte = inb(aci->aci_port + ACI_REG_BUSY);
167 if ((byte & 1) == 0) {
Martin Langer1841f6132006-03-27 12:41:01 +0200168 if (timeout >= ACI_MINTIME)
169 snd_printd("aci ready in round %ld.\n",
170 timeout-ACI_MINTIME);
171 return byte;
172 }
173 if (timeout >= ACI_MINTIME) {
174 long out=10*HZ;
175 switch (timeout-ACI_MINTIME) {
176 case 0 ... 9:
177 out /= 10;
178 case 10 ... 19:
179 out /= 10;
180 case 20 ... 30:
181 out /= 10;
182 default:
183 set_current_state(TASK_UNINTERRUPTIBLE);
184 schedule_timeout(out);
185 break;
186 }
187 }
188 }
189 snd_printk(KERN_ERR "aci_busy_wait() time out\n");
190 return -EBUSY;
191}
192
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100193static inline int aci_write(struct snd_miro_aci *aci, unsigned char byte)
Martin Langer1841f6132006-03-27 12:41:01 +0200194{
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100195 if (aci_busy_wait(aci) >= 0) {
196 outb(byte, aci->aci_port + ACI_REG_COMMAND);
Martin Langer1841f6132006-03-27 12:41:01 +0200197 return 0;
198 } else {
199 snd_printk(KERN_ERR "aci busy, aci_write(0x%x) stopped.\n", byte);
200 return -EBUSY;
201 }
202}
203
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100204static inline int aci_read(struct snd_miro_aci *aci)
Martin Langer1841f6132006-03-27 12:41:01 +0200205{
206 unsigned char byte;
207
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100208 if (aci_busy_wait(aci) >= 0) {
209 byte = inb(aci->aci_port + ACI_REG_STATUS);
Martin Langer1841f6132006-03-27 12:41:01 +0200210 return byte;
211 } else {
212 snd_printk(KERN_ERR "aci busy, aci_read() stopped.\n");
213 return -EBUSY;
214 }
215}
216
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100217int snd_aci_cmd(struct snd_miro_aci *aci, int write1, int write2, int write3)
Martin Langer1841f6132006-03-27 12:41:01 +0200218{
219 int write[] = {write1, write2, write3};
220 int value, i;
221
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100222 if (mutex_lock_interruptible(&aci->aci_mutex))
Martin Langer1841f6132006-03-27 12:41:01 +0200223 return -EINTR;
224
225 for (i=0; i<3; i++) {
226 if (write[i]< 0 || write[i] > 255)
227 break;
228 else {
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100229 value = aci_write(aci, write[i]);
Martin Langer1841f6132006-03-27 12:41:01 +0200230 if (value < 0)
231 goto out;
232 }
233 }
234
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100235 value = aci_read(aci);
Martin Langer1841f6132006-03-27 12:41:01 +0200236
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100237out: mutex_unlock(&aci->aci_mutex);
Martin Langer1841f6132006-03-27 12:41:01 +0200238 return value;
239}
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100240EXPORT_SYMBOL(snd_aci_cmd);
Martin Langer1841f6132006-03-27 12:41:01 +0200241
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100242static int aci_getvalue(struct snd_miro_aci *aci, unsigned char index)
Martin Langer1841f6132006-03-27 12:41:01 +0200243{
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100244 return snd_aci_cmd(aci, ACI_STATUS, index, -1);
Martin Langer1841f6132006-03-27 12:41:01 +0200245}
246
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100247static int aci_setvalue(struct snd_miro_aci *aci, unsigned char index,
248 int value)
Martin Langer1841f6132006-03-27 12:41:01 +0200249{
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100250 return snd_aci_cmd(aci, index, value, -1);
Martin Langer1841f6132006-03-27 12:41:01 +0200251}
252
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100253struct snd_miro_aci *snd_aci_get_aci(void)
254{
255 if (aci_device.aci_port == 0)
256 return NULL;
257 return &aci_device;
258}
259EXPORT_SYMBOL(snd_aci_get_aci);
260
Martin Langer1841f6132006-03-27 12:41:01 +0200261/*
262 * MIXER part
263 */
264
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200265#define snd_miro_info_capture snd_ctl_boolean_mono_info
Martin Langer1841f6132006-03-27 12:41:01 +0200266
267static int snd_miro_get_capture(struct snd_kcontrol *kcontrol,
268 struct snd_ctl_elem_value *ucontrol)
269{
270 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
271 int value;
272
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100273 value = aci_getvalue(miro->aci, ACI_S_GENERAL);
274 if (value < 0) {
275 snd_printk(KERN_ERR "snd_miro_get_capture() failed: %d\n",
276 value);
Martin Langer1841f6132006-03-27 12:41:01 +0200277 return value;
278 }
279
280 ucontrol->value.integer.value[0] = value & 0x20;
281
282 return 0;
283}
284
285static int snd_miro_put_capture(struct snd_kcontrol *kcontrol,
286 struct snd_ctl_elem_value *ucontrol)
287{
288 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
289 int change, value, error;
290
291 value = !(ucontrol->value.integer.value[0]);
292
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100293 error = aci_setvalue(miro->aci, ACI_SET_SOLOMODE, value);
294 if (error < 0) {
295 snd_printk(KERN_ERR "snd_miro_put_capture() failed: %d\n",
296 error);
Martin Langer1841f6132006-03-27 12:41:01 +0200297 return error;
298 }
299
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100300 change = (value != miro->aci->aci_solomode);
301 miro->aci->aci_solomode = value;
Martin Langer1841f6132006-03-27 12:41:01 +0200302
303 return change;
304}
305
306static int snd_miro_info_preamp(struct snd_kcontrol *kcontrol,
307 struct snd_ctl_elem_info *uinfo)
308{
309 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
310 uinfo->count = 1;
311 uinfo->value.integer.min = 0;
312 uinfo->value.integer.max = 3;
313
314 return 0;
315}
316
317static int snd_miro_get_preamp(struct snd_kcontrol *kcontrol,
318 struct snd_ctl_elem_value *ucontrol)
319{
320 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
321 int value;
322
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100323 if (miro->aci->aci_version <= 176) {
Martin Langer1841f6132006-03-27 12:41:01 +0200324
325 /*
326 OSS says it's not readable with versions < 176.
327 But it doesn't work on my card,
328 which is a PCM12 with aci_version = 176.
329 */
330
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100331 ucontrol->value.integer.value[0] = miro->aci->aci_preamp;
Martin Langer1841f6132006-03-27 12:41:01 +0200332 return 0;
333 }
334
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100335 value = aci_getvalue(miro->aci, ACI_GET_PREAMP);
336 if (value < 0) {
337 snd_printk(KERN_ERR "snd_miro_get_preamp() failed: %d\n",
338 value);
Martin Langer1841f6132006-03-27 12:41:01 +0200339 return value;
340 }
341
342 ucontrol->value.integer.value[0] = value;
343
344 return 0;
345}
346
347static int snd_miro_put_preamp(struct snd_kcontrol *kcontrol,
348 struct snd_ctl_elem_value *ucontrol)
349{
350 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
351 int error, value, change;
352
353 value = ucontrol->value.integer.value[0];
354
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100355 error = aci_setvalue(miro->aci, ACI_SET_PREAMP, value);
356 if (error < 0) {
357 snd_printk(KERN_ERR "snd_miro_put_preamp() failed: %d\n",
358 error);
Martin Langer1841f6132006-03-27 12:41:01 +0200359 return error;
360 }
361
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100362 change = (value != miro->aci->aci_preamp);
363 miro->aci->aci_preamp = value;
Martin Langer1841f6132006-03-27 12:41:01 +0200364
365 return change;
366}
367
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200368#define snd_miro_info_amp snd_ctl_boolean_mono_info
Martin Langer1841f6132006-03-27 12:41:01 +0200369
370static int snd_miro_get_amp(struct snd_kcontrol *kcontrol,
371 struct snd_ctl_elem_value *ucontrol)
372{
373 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100374 ucontrol->value.integer.value[0] = miro->aci->aci_amp;
Martin Langer1841f6132006-03-27 12:41:01 +0200375
376 return 0;
377}
378
379static int snd_miro_put_amp(struct snd_kcontrol *kcontrol,
380 struct snd_ctl_elem_value *ucontrol)
381{
382 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
383 int error, value, change;
384
385 value = ucontrol->value.integer.value[0];
386
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100387 error = aci_setvalue(miro->aci, ACI_SET_POWERAMP, value);
388 if (error < 0) {
Martin Langer1841f6132006-03-27 12:41:01 +0200389 snd_printk(KERN_ERR "snd_miro_put_amp() to %d failed: %d\n", value, error);
390 return error;
391 }
392
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100393 change = (value != miro->aci->aci_amp);
394 miro->aci->aci_amp = value;
Martin Langer1841f6132006-03-27 12:41:01 +0200395
396 return change;
397}
398
399#define MIRO_DOUBLE(ctl_name, ctl_index, get_right_reg, set_right_reg) \
400{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
401 .name = ctl_name, \
402 .index = ctl_index, \
403 .info = snd_miro_info_double, \
404 .get = snd_miro_get_double, \
405 .put = snd_miro_put_double, \
406 .private_value = get_right_reg | (set_right_reg << 8) \
407}
408
409static int snd_miro_info_double(struct snd_kcontrol *kcontrol,
410 struct snd_ctl_elem_info *uinfo)
411{
412 int reg = kcontrol->private_value & 0xff;
413
414 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
415 uinfo->count = 2;
416
417 if ((reg >= ACI_GET_EQ1) && (reg <= ACI_GET_EQ7)) {
418
419 /* equalizer elements */
420
421 uinfo->value.integer.min = - 0x7f;
422 uinfo->value.integer.max = 0x7f;
423 } else {
424
425 /* non-equalizer elements */
426
427 uinfo->value.integer.min = 0;
428 uinfo->value.integer.max = 0x20;
429 }
430
431 return 0;
432}
433
434static int snd_miro_get_double(struct snd_kcontrol *kcontrol,
435 struct snd_ctl_elem_value *uinfo)
436{
437 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
438 int left_val, right_val;
439
440 int right_reg = kcontrol->private_value & 0xff;
441 int left_reg = right_reg + 1;
442
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100443 right_val = aci_getvalue(miro->aci, right_reg);
444 if (right_val < 0) {
Martin Langer1841f6132006-03-27 12:41:01 +0200445 snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", right_reg, right_val);
446 return right_val;
447 }
448
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100449 left_val = aci_getvalue(miro->aci, left_reg);
450 if (left_val < 0) {
Martin Langer1841f6132006-03-27 12:41:01 +0200451 snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", left_reg, left_val);
452 return left_val;
453 }
454
455 if ((right_reg >= ACI_GET_EQ1) && (right_reg <= ACI_GET_EQ7)) {
456
457 /* equalizer elements */
458
459 if (left_val < 0x80) {
460 uinfo->value.integer.value[0] = left_val;
461 } else {
462 uinfo->value.integer.value[0] = 0x80 - left_val;
463 }
464
465 if (right_val < 0x80) {
466 uinfo->value.integer.value[1] = right_val;
467 } else {
468 uinfo->value.integer.value[1] = 0x80 - right_val;
469 }
470
471 } else {
472
473 /* non-equalizer elements */
474
475 uinfo->value.integer.value[0] = 0x20 - left_val;
476 uinfo->value.integer.value[1] = 0x20 - right_val;
477 }
478
479 return 0;
480}
481
482static int snd_miro_put_double(struct snd_kcontrol *kcontrol,
483 struct snd_ctl_elem_value *ucontrol)
484{
485 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100486 struct snd_miro_aci *aci = miro->aci;
Martin Langer1841f6132006-03-27 12:41:01 +0200487 int left, right, left_old, right_old;
488 int setreg_left, setreg_right, getreg_left, getreg_right;
489 int change, error;
490
491 left = ucontrol->value.integer.value[0];
492 right = ucontrol->value.integer.value[1];
493
494 setreg_right = (kcontrol->private_value >> 8) & 0xff;
Krzysztof Helt616ad592009-11-21 01:01:18 +0100495 setreg_left = setreg_right + 8;
496 if (setreg_right == ACI_SET_MASTER)
497 setreg_left -= 7;
Martin Langer1841f6132006-03-27 12:41:01 +0200498
499 getreg_right = kcontrol->private_value & 0xff;
500 getreg_left = getreg_right + 1;
501
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100502 left_old = aci_getvalue(aci, getreg_left);
503 if (left_old < 0) {
Martin Langer1841f6132006-03-27 12:41:01 +0200504 snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", getreg_left, left_old);
505 return left_old;
506 }
507
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100508 right_old = aci_getvalue(aci, getreg_right);
509 if (right_old < 0) {
Martin Langer1841f6132006-03-27 12:41:01 +0200510 snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", getreg_right, right_old);
511 return right_old;
512 }
513
514 if ((getreg_right >= ACI_GET_EQ1) && (getreg_right <= ACI_GET_EQ7)) {
515
516 /* equalizer elements */
517
Takashi Iwai3b892462007-11-15 16:17:24 +0100518 if (left < -0x7f || left > 0x7f ||
519 right < -0x7f || right > 0x7f)
520 return -EINVAL;
521
Martin Langer1841f6132006-03-27 12:41:01 +0200522 if (left_old > 0x80)
523 left_old = 0x80 - left_old;
524 if (right_old > 0x80)
525 right_old = 0x80 - right_old;
526
527 if (left >= 0) {
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100528 error = aci_setvalue(aci, setreg_left, left);
529 if (error < 0) {
Martin Langer1841f6132006-03-27 12:41:01 +0200530 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
531 left, error);
532 return error;
533 }
534 } else {
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100535 error = aci_setvalue(aci, setreg_left, 0x80 - left);
536 if (error < 0) {
Martin Langer1841f6132006-03-27 12:41:01 +0200537 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
538 0x80 - left, error);
539 return error;
540 }
541 }
542
543 if (right >= 0) {
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100544 error = aci_setvalue(aci, setreg_right, right);
545 if (error < 0) {
Martin Langer1841f6132006-03-27 12:41:01 +0200546 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
547 right, error);
548 return error;
549 }
550 } else {
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100551 error = aci_setvalue(aci, setreg_right, 0x80 - right);
552 if (error < 0) {
Martin Langer1841f6132006-03-27 12:41:01 +0200553 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
554 0x80 - right, error);
555 return error;
556 }
557 }
558
559 } else {
560
561 /* non-equalizer elements */
562
Takashi Iwai3b892462007-11-15 16:17:24 +0100563 if (left < 0 || left > 0x20 ||
564 right < 0 || right > 0x20)
565 return -EINVAL;
566
Martin Langer1841f6132006-03-27 12:41:01 +0200567 left_old = 0x20 - left_old;
568 right_old = 0x20 - right_old;
569
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100570 error = aci_setvalue(aci, setreg_left, 0x20 - left);
571 if (error < 0) {
Martin Langer1841f6132006-03-27 12:41:01 +0200572 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
573 0x20 - left, error);
574 return error;
575 }
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100576 error = aci_setvalue(aci, setreg_right, 0x20 - right);
577 if (error < 0) {
Martin Langer1841f6132006-03-27 12:41:01 +0200578 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
579 0x20 - right, error);
580 return error;
581 }
582 }
583
584 change = (left != left_old) || (right != right_old);
585
586 return change;
587}
588
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100589static struct snd_kcontrol_new snd_miro_controls[] __devinitdata = {
Martin Langer1841f6132006-03-27 12:41:01 +0200590MIRO_DOUBLE("Master Playback Volume", 0, ACI_GET_MASTER, ACI_SET_MASTER),
591MIRO_DOUBLE("Mic Playback Volume", 1, ACI_GET_MIC, ACI_SET_MIC),
592MIRO_DOUBLE("Line Playback Volume", 1, ACI_GET_LINE, ACI_SET_LINE),
593MIRO_DOUBLE("CD Playback Volume", 0, ACI_GET_CD, ACI_SET_CD),
594MIRO_DOUBLE("Synth Playback Volume", 0, ACI_GET_SYNTH, ACI_SET_SYNTH),
595MIRO_DOUBLE("PCM Playback Volume", 1, ACI_GET_PCM, ACI_SET_PCM),
596MIRO_DOUBLE("Aux Playback Volume", 2, ACI_GET_LINE2, ACI_SET_LINE2),
597};
598
599/* Equalizer with seven bands (only PCM20)
600 from -12dB up to +12dB on each band */
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100601static struct snd_kcontrol_new snd_miro_eq_controls[] __devinitdata = {
Martin Langer1841f6132006-03-27 12:41:01 +0200602MIRO_DOUBLE("Tone Control - 28 Hz", 0, ACI_GET_EQ1, ACI_SET_EQ1),
603MIRO_DOUBLE("Tone Control - 160 Hz", 0, ACI_GET_EQ2, ACI_SET_EQ2),
604MIRO_DOUBLE("Tone Control - 400 Hz", 0, ACI_GET_EQ3, ACI_SET_EQ3),
605MIRO_DOUBLE("Tone Control - 1 kHz", 0, ACI_GET_EQ4, ACI_SET_EQ4),
606MIRO_DOUBLE("Tone Control - 2.5 kHz", 0, ACI_GET_EQ5, ACI_SET_EQ5),
607MIRO_DOUBLE("Tone Control - 6.3 kHz", 0, ACI_GET_EQ6, ACI_SET_EQ6),
608MIRO_DOUBLE("Tone Control - 16 kHz", 0, ACI_GET_EQ7, ACI_SET_EQ7),
609};
610
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100611static struct snd_kcontrol_new snd_miro_radio_control[] __devinitdata = {
Martin Langer1841f6132006-03-27 12:41:01 +0200612MIRO_DOUBLE("Radio Playback Volume", 0, ACI_GET_LINE1, ACI_SET_LINE1),
613};
614
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100615static struct snd_kcontrol_new snd_miro_line_control[] __devinitdata = {
Martin Langer1841f6132006-03-27 12:41:01 +0200616MIRO_DOUBLE("Line Playback Volume", 2, ACI_GET_LINE1, ACI_SET_LINE1),
617};
618
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100619static struct snd_kcontrol_new snd_miro_preamp_control[] __devinitdata = {
Martin Langer1841f6132006-03-27 12:41:01 +0200620{
621 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
622 .name = "Mic Boost",
623 .index = 1,
624 .info = snd_miro_info_preamp,
625 .get = snd_miro_get_preamp,
626 .put = snd_miro_put_preamp,
627}};
628
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100629static struct snd_kcontrol_new snd_miro_amp_control[] __devinitdata = {
Martin Langer1841f6132006-03-27 12:41:01 +0200630{
631 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
632 .name = "Line Boost",
633 .index = 0,
634 .info = snd_miro_info_amp,
635 .get = snd_miro_get_amp,
636 .put = snd_miro_put_amp,
637}};
638
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100639static struct snd_kcontrol_new snd_miro_capture_control[] __devinitdata = {
Martin Langer1841f6132006-03-27 12:41:01 +0200640{
641 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
642 .name = "PCM Capture Switch",
643 .index = 0,
644 .info = snd_miro_info_capture,
645 .get = snd_miro_get_capture,
646 .put = snd_miro_put_capture,
647}};
648
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100649static unsigned char aci_init_values[][2] __devinitdata = {
Martin Langer1841f6132006-03-27 12:41:01 +0200650 { ACI_SET_MUTE, 0x00 },
651 { ACI_SET_POWERAMP, 0x00 },
652 { ACI_SET_PREAMP, 0x00 },
653 { ACI_SET_SOLOMODE, 0x00 },
654 { ACI_SET_MIC + 0, 0x20 },
655 { ACI_SET_MIC + 8, 0x20 },
656 { ACI_SET_LINE + 0, 0x20 },
657 { ACI_SET_LINE + 8, 0x20 },
658 { ACI_SET_CD + 0, 0x20 },
659 { ACI_SET_CD + 8, 0x20 },
660 { ACI_SET_PCM + 0, 0x20 },
661 { ACI_SET_PCM + 8, 0x20 },
662 { ACI_SET_LINE1 + 0, 0x20 },
663 { ACI_SET_LINE1 + 8, 0x20 },
664 { ACI_SET_LINE2 + 0, 0x20 },
665 { ACI_SET_LINE2 + 8, 0x20 },
666 { ACI_SET_SYNTH + 0, 0x20 },
667 { ACI_SET_SYNTH + 8, 0x20 },
668 { ACI_SET_MASTER + 0, 0x20 },
669 { ACI_SET_MASTER + 1, 0x20 },
670};
671
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100672static int __devinit snd_set_aci_init_values(struct snd_miro *miro)
Martin Langer1841f6132006-03-27 12:41:01 +0200673{
674 int idx, error;
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100675 struct snd_miro_aci *aci = miro->aci;
Martin Langer1841f6132006-03-27 12:41:01 +0200676
677 /* enable WSS on PCM1 */
678
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100679 if ((aci->aci_product == 'A') && wss) {
680 error = aci_setvalue(aci, ACI_SET_WSS, wss);
681 if (error < 0) {
Martin Langer1841f6132006-03-27 12:41:01 +0200682 snd_printk(KERN_ERR "enabling WSS mode failed\n");
683 return error;
684 }
685 }
686
687 /* enable IDE port */
688
689 if (ide) {
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100690 error = aci_setvalue(aci, ACI_SET_IDE, ide);
691 if (error < 0) {
Martin Langer1841f6132006-03-27 12:41:01 +0200692 snd_printk(KERN_ERR "enabling IDE port failed\n");
693 return error;
694 }
695 }
696
697 /* set common aci values */
698
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100699 for (idx = 0; idx < ARRAY_SIZE(aci_init_values); idx++) {
700 error = aci_setvalue(aci, aci_init_values[idx][0],
701 aci_init_values[idx][1]);
702 if (error < 0) {
Martin Langer1841f6132006-03-27 12:41:01 +0200703 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
704 aci_init_values[idx][0], error);
705 return error;
706 }
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100707 }
708 aci->aci_amp = 0;
709 aci->aci_preamp = 0;
710 aci->aci_solomode = 1;
Martin Langer1841f6132006-03-27 12:41:01 +0200711
712 return 0;
713}
714
Krzysztof Helt616ad592009-11-21 01:01:18 +0100715static int __devinit snd_miro_mixer(struct snd_card *card,
716 struct snd_miro *miro)
Martin Langer1841f6132006-03-27 12:41:01 +0200717{
Martin Langer1841f6132006-03-27 12:41:01 +0200718 unsigned int idx;
719 int err;
720
Krzysztof Helt616ad592009-11-21 01:01:18 +0100721 if (snd_BUG_ON(!miro || !card))
Takashi Iwai622207d2008-08-08 17:11:45 +0200722 return -EINVAL;
Martin Langer1841f6132006-03-27 12:41:01 +0200723
Martin Langer1841f6132006-03-27 12:41:01 +0200724 switch (miro->hardware) {
725 case OPTi9XX_HW_82C924:
726 strcpy(card->mixername, "ACI & OPTi924");
727 break;
728 case OPTi9XX_HW_82C929:
729 strcpy(card->mixername, "ACI & OPTi929");
730 break;
731 default:
732 snd_BUG();
733 break;
734 }
735
736 for (idx = 0; idx < ARRAY_SIZE(snd_miro_controls); idx++) {
737 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_controls[idx], miro))) < 0)
738 return err;
739 }
740
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100741 if ((miro->aci->aci_product == 'A') ||
742 (miro->aci->aci_product == 'B')) {
Martin Langer1841f6132006-03-27 12:41:01 +0200743 /* PCM1/PCM12 with power-amp and Line 2 */
744 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_line_control[0], miro))) < 0)
745 return err;
746 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_amp_control[0], miro))) < 0)
747 return err;
748 }
749
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100750 if ((miro->aci->aci_product == 'B') ||
751 (miro->aci->aci_product == 'C')) {
Martin Langer1841f6132006-03-27 12:41:01 +0200752 /* PCM12/PCM20 with mic-preamp */
753 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_preamp_control[0], miro))) < 0)
754 return err;
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100755 if (miro->aci->aci_version >= 176)
Martin Langer1841f6132006-03-27 12:41:01 +0200756 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_capture_control[0], miro))) < 0)
757 return err;
758 }
759
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100760 if (miro->aci->aci_product == 'C') {
Martin Langer1841f6132006-03-27 12:41:01 +0200761 /* PCM20 with radio and 7 band equalizer */
762 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_radio_control[0], miro))) < 0)
763 return err;
764 for (idx = 0; idx < ARRAY_SIZE(snd_miro_eq_controls); idx++) {
765 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_eq_controls[idx], miro))) < 0)
766 return err;
767 }
768 }
769
770 return 0;
771}
772
773static long snd_legacy_find_free_ioport(long *port_table, long size)
774{
775 while (*port_table != -1) {
776 struct resource *res;
777 if ((res = request_region(*port_table, size,
778 "ALSA test")) != NULL) {
Takashi Iwai10d150e2006-03-27 13:42:39 +0200779 release_and_free_resource(res);
Martin Langer1841f6132006-03-27 12:41:01 +0200780 return *port_table;
781 }
782 port_table++;
783 }
784 return -1;
785}
786
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100787static int __devinit snd_miro_init(struct snd_miro *chip,
788 unsigned short hardware)
Martin Langer1841f6132006-03-27 12:41:01 +0200789{
790 static int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2};
791
792 chip->hardware = hardware;
793 strcpy(chip->name, snd_opti9xx_names[hardware]);
794
795 chip->mc_base_size = opti9xx_mc_size[hardware];
796
797 spin_lock_init(&chip->lock);
798
799 chip->wss_base = -1;
800 chip->irq = -1;
801 chip->dma1 = -1;
802 chip->dma2 = -1;
Martin Langer1841f6132006-03-27 12:41:01 +0200803 chip->mpu_port = -1;
804 chip->mpu_irq = -1;
805
Krzysztof Helt306ecee2009-11-30 07:46:56 +0100806 chip->pwd_reg = 3;
807
808#ifdef CONFIG_PNP
809 if (isapnp && chip->mc_base)
810 /* PnP resource gives the least 10 bits */
811 chip->mc_base |= 0xc00;
812 else
813#endif
814 chip->mc_base = 0xf8c;
815
Martin Langer1841f6132006-03-27 12:41:01 +0200816 switch (hardware) {
817 case OPTi9XX_HW_82C929:
Martin Langer1841f6132006-03-27 12:41:01 +0200818 chip->password = 0xe3;
Martin Langer1841f6132006-03-27 12:41:01 +0200819 break;
820
821 case OPTi9XX_HW_82C924:
Martin Langer1841f6132006-03-27 12:41:01 +0200822 chip->password = 0xe5;
Martin Langer1841f6132006-03-27 12:41:01 +0200823 break;
824
825 default:
826 snd_printk(KERN_ERR "sorry, no support for %d\n", hardware);
827 return -ENODEV;
828 }
829
830 return 0;
831}
832
833static unsigned char snd_miro_read(struct snd_miro *chip,
834 unsigned char reg)
835{
836 unsigned long flags;
837 unsigned char retval = 0xff;
838
839 spin_lock_irqsave(&chip->lock, flags);
840 outb(chip->password, chip->mc_base + chip->pwd_reg);
841
842 switch (chip->hardware) {
843 case OPTi9XX_HW_82C924:
844 if (reg > 7) {
845 outb(reg, chip->mc_base + 8);
846 outb(chip->password, chip->mc_base + chip->pwd_reg);
847 retval = inb(chip->mc_base + 9);
848 break;
849 }
850
851 case OPTi9XX_HW_82C929:
852 retval = inb(chip->mc_base + reg);
853 break;
854
855 default:
856 snd_printk(KERN_ERR "sorry, no support for %d\n", chip->hardware);
857 }
858
859 spin_unlock_irqrestore(&chip->lock, flags);
860 return retval;
861}
862
863static void snd_miro_write(struct snd_miro *chip, unsigned char reg,
864 unsigned char value)
865{
866 unsigned long flags;
867
868 spin_lock_irqsave(&chip->lock, flags);
869 outb(chip->password, chip->mc_base + chip->pwd_reg);
870
871 switch (chip->hardware) {
872 case OPTi9XX_HW_82C924:
873 if (reg > 7) {
874 outb(reg, chip->mc_base + 8);
875 outb(chip->password, chip->mc_base + chip->pwd_reg);
876 outb(value, chip->mc_base + 9);
877 break;
878 }
879
880 case OPTi9XX_HW_82C929:
881 outb(value, chip->mc_base + reg);
882 break;
883
884 default:
885 snd_printk(KERN_ERR "sorry, no support for %d\n", chip->hardware);
886 }
887
888 spin_unlock_irqrestore(&chip->lock, flags);
889}
890
891
892#define snd_miro_write_mask(chip, reg, value, mask) \
893 snd_miro_write(chip, reg, \
894 (snd_miro_read(chip, reg) & ~(mask)) | ((value) & (mask)))
895
896/*
897 * Proc Interface
898 */
899
900static void snd_miro_proc_read(struct snd_info_entry * entry,
901 struct snd_info_buffer *buffer)
902{
903 struct snd_miro *miro = (struct snd_miro *) entry->private_data;
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100904 struct snd_miro_aci *aci = miro->aci;
Martin Langer1841f6132006-03-27 12:41:01 +0200905 char* model = "unknown";
906
907 /* miroSOUND PCM1 pro, early PCM12 */
908
909 if ((miro->hardware == OPTi9XX_HW_82C929) &&
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100910 (aci->aci_vendor == 'm') &&
911 (aci->aci_product == 'A')) {
912 switch (aci->aci_version) {
Martin Langer1841f6132006-03-27 12:41:01 +0200913 case 3:
914 model = "miroSOUND PCM1 pro";
915 break;
916 default:
917 model = "miroSOUND PCM1 pro / (early) PCM12";
918 break;
919 }
920 }
921
922 /* miroSOUND PCM12, PCM12 (Rev. E), PCM12 pnp */
923
924 if ((miro->hardware == OPTi9XX_HW_82C924) &&
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100925 (aci->aci_vendor == 'm') &&
926 (aci->aci_product == 'B')) {
927 switch (aci->aci_version) {
Martin Langer1841f6132006-03-27 12:41:01 +0200928 case 4:
929 model = "miroSOUND PCM12";
930 break;
931 case 176:
932 model = "miroSOUND PCM12 (Rev. E)";
933 break;
934 default:
935 model = "miroSOUND PCM12 / PCM12 pnp";
936 break;
937 }
938 }
939
940 /* miroSOUND PCM20 radio */
941
942 if ((miro->hardware == OPTi9XX_HW_82C924) &&
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100943 (aci->aci_vendor == 'm') &&
944 (aci->aci_product == 'C')) {
945 switch (aci->aci_version) {
Martin Langer1841f6132006-03-27 12:41:01 +0200946 case 7:
947 model = "miroSOUND PCM20 radio (Rev. E)";
948 break;
949 default:
950 model = "miroSOUND PCM20 radio";
951 break;
952 }
953 }
954
955 snd_iprintf(buffer, "\nGeneral information:\n");
956 snd_iprintf(buffer, " model : %s\n", model);
957 snd_iprintf(buffer, " opti : %s\n", miro->name);
958 snd_iprintf(buffer, " codec : %s\n", miro->pcm->name);
959 snd_iprintf(buffer, " port : 0x%lx\n", miro->wss_base);
960 snd_iprintf(buffer, " irq : %d\n", miro->irq);
961 snd_iprintf(buffer, " dma : %d,%d\n\n", miro->dma1, miro->dma2);
962
963 snd_iprintf(buffer, "MPU-401:\n");
964 snd_iprintf(buffer, " port : 0x%lx\n", miro->mpu_port);
965 snd_iprintf(buffer, " irq : %d\n\n", miro->mpu_irq);
966
967 snd_iprintf(buffer, "ACI information:\n");
968 snd_iprintf(buffer, " vendor : ");
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100969 switch (aci->aci_vendor) {
Martin Langer1841f6132006-03-27 12:41:01 +0200970 case 'm':
971 snd_iprintf(buffer, "Miro\n");
972 break;
973 default:
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100974 snd_iprintf(buffer, "unknown (0x%x)\n", aci->aci_vendor);
Martin Langer1841f6132006-03-27 12:41:01 +0200975 break;
976 }
977
978 snd_iprintf(buffer, " product : ");
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100979 switch (aci->aci_product) {
Martin Langer1841f6132006-03-27 12:41:01 +0200980 case 'A':
981 snd_iprintf(buffer, "miroSOUND PCM1 pro / (early) PCM12\n");
982 break;
983 case 'B':
984 snd_iprintf(buffer, "miroSOUND PCM12\n");
985 break;
986 case 'C':
987 snd_iprintf(buffer, "miroSOUND PCM20 radio\n");
988 break;
989 default:
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100990 snd_iprintf(buffer, "unknown (0x%x)\n", aci->aci_product);
Martin Langer1841f6132006-03-27 12:41:01 +0200991 break;
992 }
993
994 snd_iprintf(buffer, " firmware: %d (0x%x)\n",
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100995 aci->aci_version, aci->aci_version);
Martin Langer1841f6132006-03-27 12:41:01 +0200996 snd_iprintf(buffer, " port : 0x%lx-0x%lx\n",
Krzysztof Helt9dc91202009-11-22 17:26:34 +0100997 aci->aci_port, aci->aci_port+2);
Martin Langer1841f6132006-03-27 12:41:01 +0200998 snd_iprintf(buffer, " wss : 0x%x\n", wss);
999 snd_iprintf(buffer, " ide : 0x%x\n", ide);
Krzysztof Helt9dc91202009-11-22 17:26:34 +01001000 snd_iprintf(buffer, " solomode: 0x%x\n", aci->aci_solomode);
1001 snd_iprintf(buffer, " amp : 0x%x\n", aci->aci_amp);
1002 snd_iprintf(buffer, " preamp : 0x%x\n", aci->aci_preamp);
Martin Langer1841f6132006-03-27 12:41:01 +02001003}
1004
Krzysztof Helt616ad592009-11-21 01:01:18 +01001005static void __devinit snd_miro_proc_init(struct snd_card *card,
1006 struct snd_miro *miro)
Martin Langer1841f6132006-03-27 12:41:01 +02001007{
1008 struct snd_info_entry *entry;
1009
Krzysztof Helt616ad592009-11-21 01:01:18 +01001010 if (!snd_card_proc_new(card, "miro", &entry))
Takashi Iwaibf850202006-04-28 15:13:41 +02001011 snd_info_set_text_ops(entry, miro, snd_miro_proc_read);
Martin Langer1841f6132006-03-27 12:41:01 +02001012}
1013
1014/*
1015 * Init
1016 */
1017
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001018static int __devinit snd_miro_configure(struct snd_miro *chip)
Martin Langer1841f6132006-03-27 12:41:01 +02001019{
1020 unsigned char wss_base_bits;
1021 unsigned char irq_bits;
1022 unsigned char dma_bits;
1023 unsigned char mpu_port_bits = 0;
1024 unsigned char mpu_irq_bits;
1025 unsigned long flags;
1026
Krzysztof Helt616ad592009-11-21 01:01:18 +01001027 snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
1028 snd_miro_write_mask(chip, OPTi9XX_MC_REG(2), 0x20, 0x20); /* OPL4 */
1029 snd_miro_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
1030
Martin Langer1841f6132006-03-27 12:41:01 +02001031 switch (chip->hardware) {
1032 case OPTi9XX_HW_82C924:
1033 snd_miro_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02);
Martin Langer1841f6132006-03-27 12:41:01 +02001034 snd_miro_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff);
Martin Langer1841f6132006-03-27 12:41:01 +02001035 break;
1036 case OPTi9XX_HW_82C929:
1037 /* untested init commands for OPTi929 */
Martin Langer1841f6132006-03-27 12:41:01 +02001038 snd_miro_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c);
Martin Langer1841f6132006-03-27 12:41:01 +02001039 break;
1040 default:
1041 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
1042 return -EINVAL;
1043 }
1044
Krzysztof Helt306ecee2009-11-30 07:46:56 +01001045 /* PnP resource says it decodes only 10 bits of address */
1046 switch (chip->wss_base & 0x3ff) {
1047 case 0x130:
1048 chip->wss_base = 0x530;
Martin Langer1841f6132006-03-27 12:41:01 +02001049 wss_base_bits = 0x00;
1050 break;
Krzysztof Helt306ecee2009-11-30 07:46:56 +01001051 case 0x204:
1052 chip->wss_base = 0x604;
Martin Langer1841f6132006-03-27 12:41:01 +02001053 wss_base_bits = 0x03;
1054 break;
Krzysztof Helt306ecee2009-11-30 07:46:56 +01001055 case 0x280:
1056 chip->wss_base = 0xe80;
Martin Langer1841f6132006-03-27 12:41:01 +02001057 wss_base_bits = 0x01;
1058 break;
Krzysztof Helt306ecee2009-11-30 07:46:56 +01001059 case 0x340:
1060 chip->wss_base = 0xf40;
Martin Langer1841f6132006-03-27 12:41:01 +02001061 wss_base_bits = 0x02;
1062 break;
1063 default:
1064 snd_printk(KERN_ERR "WSS port 0x%lx not valid\n", chip->wss_base);
1065 goto __skip_base;
1066 }
1067 snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30);
1068
1069__skip_base:
1070 switch (chip->irq) {
1071 case 5:
1072 irq_bits = 0x05;
1073 break;
1074 case 7:
1075 irq_bits = 0x01;
1076 break;
1077 case 9:
1078 irq_bits = 0x02;
1079 break;
1080 case 10:
1081 irq_bits = 0x03;
1082 break;
1083 case 11:
1084 irq_bits = 0x04;
1085 break;
1086 default:
1087 snd_printk(KERN_ERR "WSS irq # %d not valid\n", chip->irq);
1088 goto __skip_resources;
1089 }
1090
1091 switch (chip->dma1) {
1092 case 0:
1093 dma_bits = 0x01;
1094 break;
1095 case 1:
1096 dma_bits = 0x02;
1097 break;
1098 case 3:
1099 dma_bits = 0x03;
1100 break;
1101 default:
1102 snd_printk(KERN_ERR "WSS dma1 # %d not valid\n", chip->dma1);
1103 goto __skip_resources;
1104 }
1105
1106 if (chip->dma1 == chip->dma2) {
1107 snd_printk(KERN_ERR "don't want to share dmas\n");
1108 return -EBUSY;
1109 }
1110
1111 switch (chip->dma2) {
1112 case 0:
1113 case 1:
1114 break;
1115 default:
1116 snd_printk(KERN_ERR "WSS dma2 # %d not valid\n", chip->dma2);
1117 goto __skip_resources;
1118 }
1119 dma_bits |= 0x04;
1120
1121 spin_lock_irqsave(&chip->lock, flags);
1122 outb(irq_bits << 3 | dma_bits, chip->wss_base);
1123 spin_unlock_irqrestore(&chip->lock, flags);
1124
1125__skip_resources:
1126 if (chip->hardware > OPTi9XX_HW_82C928) {
1127 switch (chip->mpu_port) {
1128 case 0:
1129 case -1:
1130 break;
1131 case 0x300:
1132 mpu_port_bits = 0x03;
1133 break;
1134 case 0x310:
1135 mpu_port_bits = 0x02;
1136 break;
1137 case 0x320:
1138 mpu_port_bits = 0x01;
1139 break;
1140 case 0x330:
1141 mpu_port_bits = 0x00;
1142 break;
1143 default:
1144 snd_printk(KERN_ERR "MPU-401 port 0x%lx not valid\n",
1145 chip->mpu_port);
1146 goto __skip_mpu;
1147 }
1148
1149 switch (chip->mpu_irq) {
1150 case 5:
1151 mpu_irq_bits = 0x02;
1152 break;
1153 case 7:
1154 mpu_irq_bits = 0x03;
1155 break;
1156 case 9:
1157 mpu_irq_bits = 0x00;
1158 break;
1159 case 10:
1160 mpu_irq_bits = 0x01;
1161 break;
1162 default:
1163 snd_printk(KERN_ERR "MPU-401 irq # %d not valid\n",
1164 chip->mpu_irq);
1165 goto __skip_mpu;
1166 }
1167
1168 snd_miro_write_mask(chip, OPTi9XX_MC_REG(6),
1169 (chip->mpu_port <= 0) ? 0x00 :
1170 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
1171 0xf8);
1172 }
1173__skip_mpu:
1174
1175 return 0;
1176}
1177
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001178static int __devinit snd_miro_opti_check(struct snd_miro *chip)
1179{
1180 unsigned char value;
1181
1182 chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size,
1183 "OPTi9xx MC");
1184 if (chip->res_mc_base == NULL)
1185 return -ENOMEM;
1186
1187 value = snd_miro_read(chip, OPTi9XX_MC_REG(1));
1188 if (value != 0xff && value != inb(chip->mc_base + OPTi9XX_MC_REG(1)))
1189 if (value == snd_miro_read(chip, OPTi9XX_MC_REG(1)))
1190 return 0;
1191
1192 release_and_free_resource(chip->res_mc_base);
1193 chip->res_mc_base = NULL;
1194
1195 return -ENODEV;
1196}
1197
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001198static int __devinit snd_card_miro_detect(struct snd_card *card,
1199 struct snd_miro *chip)
Martin Langer1841f6132006-03-27 12:41:01 +02001200{
1201 int i, err;
Martin Langer1841f6132006-03-27 12:41:01 +02001202
1203 for (i = OPTi9XX_HW_82C929; i <= OPTi9XX_HW_82C924; i++) {
1204
1205 if ((err = snd_miro_init(chip, i)) < 0)
1206 return err;
1207
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001208 err = snd_miro_opti_check(chip);
1209 if (err == 0)
1210 return 1;
Martin Langer1841f6132006-03-27 12:41:01 +02001211 }
1212
1213 return -ENODEV;
1214}
1215
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001216static int __devinit snd_card_miro_aci_detect(struct snd_card *card,
Krzysztof Helt9dc91202009-11-22 17:26:34 +01001217 struct snd_miro *miro)
Martin Langer1841f6132006-03-27 12:41:01 +02001218{
1219 unsigned char regval;
1220 int i;
Krzysztof Helt9dc91202009-11-22 17:26:34 +01001221 struct snd_miro_aci *aci = &aci_device;
Martin Langer1841f6132006-03-27 12:41:01 +02001222
Krzysztof Helt9dc91202009-11-22 17:26:34 +01001223 miro->aci = aci;
1224
1225 mutex_init(&aci->aci_mutex);
Martin Langer1841f6132006-03-27 12:41:01 +02001226
1227 /* get ACI port from OPTi9xx MC 4 */
1228
Martin Langer1841f6132006-03-27 12:41:01 +02001229 regval=inb(miro->mc_base + 4);
Krzysztof Helt9dc91202009-11-22 17:26:34 +01001230 aci->aci_port = (regval & 0x10) ? 0x344 : 0x354;
Martin Langer1841f6132006-03-27 12:41:01 +02001231
Krzysztof Helt9dc91202009-11-22 17:26:34 +01001232 miro->res_aci_port = request_region(aci->aci_port, 3, "miro aci");
1233 if (miro->res_aci_port == NULL) {
Martin Langer1841f6132006-03-27 12:41:01 +02001234 snd_printk(KERN_ERR "aci i/o area 0x%lx-0x%lx already used.\n",
Krzysztof Helt9dc91202009-11-22 17:26:34 +01001235 aci->aci_port, aci->aci_port+2);
Martin Langer1841f6132006-03-27 12:41:01 +02001236 return -ENOMEM;
1237 }
1238
1239 /* force ACI into a known state */
1240 for (i = 0; i < 3; i++)
Krzysztof Helt9dc91202009-11-22 17:26:34 +01001241 if (snd_aci_cmd(aci, ACI_ERROR_OP, -1, -1) < 0) {
Martin Langer1841f6132006-03-27 12:41:01 +02001242 snd_printk(KERN_ERR "can't force aci into known state.\n");
1243 return -ENXIO;
1244 }
1245
Krzysztof Helt9dc91202009-11-22 17:26:34 +01001246 aci->aci_vendor = snd_aci_cmd(aci, ACI_READ_IDCODE, -1, -1);
1247 aci->aci_product = snd_aci_cmd(aci, ACI_READ_IDCODE, -1, -1);
1248 if (aci->aci_vendor < 0 || aci->aci_product < 0) {
1249 snd_printk(KERN_ERR "can't read aci id on 0x%lx.\n",
1250 aci->aci_port);
Martin Langer1841f6132006-03-27 12:41:01 +02001251 return -ENXIO;
1252 }
1253
Krzysztof Helt9dc91202009-11-22 17:26:34 +01001254 aci->aci_version = snd_aci_cmd(aci, ACI_READ_VERSION, -1, -1);
1255 if (aci->aci_version < 0) {
Martin Langer1841f6132006-03-27 12:41:01 +02001256 snd_printk(KERN_ERR "can't read aci version on 0x%lx.\n",
Krzysztof Helt9dc91202009-11-22 17:26:34 +01001257 aci->aci_port);
Martin Langer1841f6132006-03-27 12:41:01 +02001258 return -ENXIO;
1259 }
1260
Krzysztof Helt9dc91202009-11-22 17:26:34 +01001261 if (snd_aci_cmd(aci, ACI_INIT, -1, -1) < 0 ||
1262 snd_aci_cmd(aci, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0 ||
1263 snd_aci_cmd(aci, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0) {
Martin Langer1841f6132006-03-27 12:41:01 +02001264 snd_printk(KERN_ERR "can't initialize aci.\n");
1265 return -ENXIO;
1266 }
1267
1268 return 0;
1269}
1270
1271static void snd_card_miro_free(struct snd_card *card)
1272{
1273 struct snd_miro *miro = card->private_data;
Krzysztof Helt306ecee2009-11-30 07:46:56 +01001274
Martin Langer1841f6132006-03-27 12:41:01 +02001275 release_and_free_resource(miro->res_aci_port);
Krzysztof Helt87000552009-11-27 11:20:56 +01001276 if (miro->aci)
1277 miro->aci->aci_port = 0;
Martin Langer1841f6132006-03-27 12:41:01 +02001278 release_and_free_resource(miro->res_mc_base);
1279}
1280
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001281static int __devinit snd_miro_probe(struct snd_card *card)
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001282{
Martin Langer1841f6132006-03-27 12:41:01 +02001283 int error;
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001284 struct snd_miro *miro = card->private_data;
Krzysztof Helt7779f752008-07-31 21:03:41 +02001285 struct snd_wss *codec;
Martin Langer1841f6132006-03-27 12:41:01 +02001286 struct snd_timer *timer;
Martin Langer1841f6132006-03-27 12:41:01 +02001287 struct snd_pcm *pcm;
1288 struct snd_rawmidi *rmidi;
1289
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001290 if (!miro->res_mc_base) {
1291 miro->res_mc_base = request_region(miro->mc_base,
1292 miro->mc_base_size,
1293 "miro (OPTi9xx MC)");
1294 if (miro->res_mc_base == NULL) {
1295 snd_printk(KERN_ERR "request for OPTI9xx MC failed\n");
1296 return -ENOMEM;
1297 }
Krzysztof Helt616ad592009-11-21 01:01:18 +01001298 }
Martin Langer1841f6132006-03-27 12:41:01 +02001299
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001300 error = snd_card_miro_aci_detect(card, miro);
1301 if (error < 0) {
Martin Langer1841f6132006-03-27 12:41:01 +02001302 snd_card_free(card);
1303 snd_printk(KERN_ERR "unable to detect aci chip\n");
1304 return -ENODEV;
1305 }
1306
Martin Langer1841f6132006-03-27 12:41:01 +02001307 miro->wss_base = port;
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001308 miro->mpu_port = mpu_port;
Martin Langer1841f6132006-03-27 12:41:01 +02001309 miro->irq = irq;
1310 miro->mpu_irq = mpu_irq;
1311 miro->dma1 = dma1;
1312 miro->dma2 = dma2;
1313
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001314 /* init proc interface */
1315 snd_miro_proc_init(card, miro);
Martin Langer1841f6132006-03-27 12:41:01 +02001316
Krzysztof Helt7779f752008-07-31 21:03:41 +02001317 error = snd_miro_configure(miro);
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001318 if (error)
Martin Langer1841f6132006-03-27 12:41:01 +02001319 return error;
Martin Langer1841f6132006-03-27 12:41:01 +02001320
Krzysztof Helt7779f752008-07-31 21:03:41 +02001321 error = snd_wss_create(card, miro->wss_base + 4, -1,
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001322 miro->irq, miro->dma1, miro->dma2,
1323 WSS_HW_DETECT, 0, &codec);
1324 if (error < 0)
Martin Langer1841f6132006-03-27 12:41:01 +02001325 return error;
Martin Langer1841f6132006-03-27 12:41:01 +02001326
Krzysztof Helt7779f752008-07-31 21:03:41 +02001327 error = snd_wss_pcm(codec, 0, &pcm);
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001328 if (error < 0)
Martin Langer1841f6132006-03-27 12:41:01 +02001329 return error;
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001330
Krzysztof Helt7779f752008-07-31 21:03:41 +02001331 error = snd_wss_mixer(codec);
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001332 if (error < 0)
Martin Langer1841f6132006-03-27 12:41:01 +02001333 return error;
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001334
Krzysztof Helt7779f752008-07-31 21:03:41 +02001335 error = snd_wss_timer(codec, 0, &timer);
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001336 if (error < 0)
Martin Langer1841f6132006-03-27 12:41:01 +02001337 return error;
Martin Langer1841f6132006-03-27 12:41:01 +02001338
1339 miro->pcm = pcm;
1340
Krzysztof Helt616ad592009-11-21 01:01:18 +01001341 error = snd_miro_mixer(card, miro);
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001342 if (error < 0)
Martin Langer1841f6132006-03-27 12:41:01 +02001343 return error;
Martin Langer1841f6132006-03-27 12:41:01 +02001344
Krzysztof Helt9dc91202009-11-22 17:26:34 +01001345 if (miro->aci->aci_vendor == 'm') {
Martin Langer1841f6132006-03-27 12:41:01 +02001346 /* It looks like a miro sound card. */
Krzysztof Helt9dc91202009-11-22 17:26:34 +01001347 switch (miro->aci->aci_product) {
Martin Langer1841f6132006-03-27 12:41:01 +02001348 case 'A':
1349 sprintf(card->shortname,
1350 "miroSOUND PCM1 pro / PCM12");
1351 break;
1352 case 'B':
1353 sprintf(card->shortname,
1354 "miroSOUND PCM12");
1355 break;
1356 case 'C':
1357 sprintf(card->shortname,
1358 "miroSOUND PCM20 radio");
1359 break;
1360 default:
1361 sprintf(card->shortname,
1362 "unknown miro");
1363 snd_printk(KERN_INFO "unknown miro aci id\n");
1364 break;
1365 }
1366 } else {
1367 snd_printk(KERN_INFO "found unsupported aci card\n");
1368 sprintf(card->shortname, "unknown Cardinal Technologies");
1369 }
1370
1371 strcpy(card->driver, "miro");
1372 sprintf(card->longname, "%s: OPTi%s, %s at 0x%lx, irq %d, dma %d&%d",
1373 card->shortname, miro->name, pcm->name, miro->wss_base + 4,
1374 miro->irq, miro->dma1, miro->dma2);
1375
Krzysztof Heltb67cad92009-11-17 18:35:41 +01001376 if (mpu_port <= 0 || mpu_port == SNDRV_AUTO_PORT)
Martin Langer1841f6132006-03-27 12:41:01 +02001377 rmidi = NULL;
Krzysztof Heltb67cad92009-11-17 18:35:41 +01001378 else {
1379 error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
Clemens Ladischdba8b462011-09-13 11:24:41 +02001380 mpu_port, 0, miro->mpu_irq, &rmidi);
Krzysztof Heltb67cad92009-11-17 18:35:41 +01001381 if (error < 0)
1382 snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
1383 mpu_port);
1384 }
Martin Langer1841f6132006-03-27 12:41:01 +02001385
Krzysztof Heltb67cad92009-11-17 18:35:41 +01001386 if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) {
Martin Langer1841f6132006-03-27 12:41:01 +02001387 struct snd_opl3 *opl3 = NULL;
1388 struct snd_opl4 *opl4;
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001389
Krzysztof Heltb67cad92009-11-17 18:35:41 +01001390 if (snd_opl4_create(card, fm_port, fm_port - 8,
Martin Langer1841f6132006-03-27 12:41:01 +02001391 2, &opl3, &opl4) < 0)
Krzysztof Heltb67cad92009-11-17 18:35:41 +01001392 snd_printk(KERN_WARNING "no OPL4 device at 0x%lx\n",
1393 fm_port);
Martin Langer1841f6132006-03-27 12:41:01 +02001394 }
1395
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001396 error = snd_set_aci_init_values(miro);
1397 if (error < 0)
Martin Langer1841f6132006-03-27 12:41:01 +02001398 return error;
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001399
1400 return snd_card_register(card);
1401}
1402
1403static int __devinit snd_miro_isa_match(struct device *devptr, unsigned int n)
1404{
Krzysztof Helt306ecee2009-11-30 07:46:56 +01001405#ifdef CONFIG_PNP
1406 if (snd_miro_pnp_is_probed)
1407 return 0;
1408 if (isapnp)
1409 return 0;
1410#endif
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001411 return 1;
1412}
1413
1414static int __devinit snd_miro_isa_probe(struct device *devptr, unsigned int n)
1415{
1416 static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
1417 static long possible_mpu_ports[] = {0x330, 0x300, 0x310, 0x320, -1};
1418 static int possible_irqs[] = {11, 9, 10, 7, -1};
1419 static int possible_mpu_irqs[] = {10, 5, 9, 7, -1};
1420 static int possible_dma1s[] = {3, 1, 0, -1};
1421 static int possible_dma2s[][2] = { {1, -1}, {0, -1}, {-1, -1},
1422 {0, -1} };
1423
1424 int error;
1425 struct snd_miro *miro;
1426 struct snd_card *card;
1427
1428 error = snd_card_create(index, id, THIS_MODULE,
1429 sizeof(struct snd_miro), &card);
1430 if (error < 0)
1431 return error;
1432
1433 card->private_free = snd_card_miro_free;
1434 miro = card->private_data;
1435
1436 error = snd_card_miro_detect(card, miro);
1437 if (error < 0) {
1438 snd_card_free(card);
1439 snd_printk(KERN_ERR "unable to detect OPTi9xx chip\n");
1440 return -ENODEV;
1441 }
1442
1443 if (port == SNDRV_AUTO_PORT) {
1444 port = snd_legacy_find_free_ioport(possible_ports, 4);
1445 if (port < 0) {
1446 snd_card_free(card);
1447 snd_printk(KERN_ERR "unable to find a free WSS port\n");
1448 return -EBUSY;
1449 }
1450 }
1451
1452 if (mpu_port == SNDRV_AUTO_PORT) {
1453 mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2);
1454 if (mpu_port < 0) {
1455 snd_card_free(card);
1456 snd_printk(KERN_ERR
1457 "unable to find a free MPU401 port\n");
1458 return -EBUSY;
1459 }
1460 }
1461
1462 if (irq == SNDRV_AUTO_IRQ) {
1463 irq = snd_legacy_find_free_irq(possible_irqs);
1464 if (irq < 0) {
1465 snd_card_free(card);
1466 snd_printk(KERN_ERR "unable to find a free IRQ\n");
1467 return -EBUSY;
1468 }
1469 }
1470 if (mpu_irq == SNDRV_AUTO_IRQ) {
1471 mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs);
1472 if (mpu_irq < 0) {
1473 snd_card_free(card);
1474 snd_printk(KERN_ERR
1475 "unable to find a free MPU401 IRQ\n");
1476 return -EBUSY;
1477 }
1478 }
1479 if (dma1 == SNDRV_AUTO_DMA) {
1480 dma1 = snd_legacy_find_free_dma(possible_dma1s);
1481 if (dma1 < 0) {
1482 snd_card_free(card);
1483 snd_printk(KERN_ERR "unable to find a free DMA1\n");
1484 return -EBUSY;
1485 }
1486 }
1487 if (dma2 == SNDRV_AUTO_DMA) {
1488 dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4]);
1489 if (dma2 < 0) {
1490 snd_card_free(card);
1491 snd_printk(KERN_ERR "unable to find a free DMA2\n");
1492 return -EBUSY;
1493 }
Martin Langer1841f6132006-03-27 12:41:01 +02001494 }
1495
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001496 snd_card_set_dev(card, devptr);
Martin Langer1841f6132006-03-27 12:41:01 +02001497
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001498 error = snd_miro_probe(card);
1499 if (error < 0) {
Martin Langer1841f6132006-03-27 12:41:01 +02001500 snd_card_free(card);
1501 return error;
1502 }
1503
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001504 dev_set_drvdata(devptr, card);
Martin Langer1841f6132006-03-27 12:41:01 +02001505 return 0;
1506}
1507
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001508static int __devexit snd_miro_isa_remove(struct device *devptr,
1509 unsigned int dev)
Martin Langer1841f6132006-03-27 12:41:01 +02001510{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001511 snd_card_free(dev_get_drvdata(devptr));
1512 dev_set_drvdata(devptr, NULL);
Martin Langer1841f6132006-03-27 12:41:01 +02001513 return 0;
1514}
1515
Rene Herman83c51c02007-03-20 11:33:46 +01001516#define DEV_NAME "miro"
1517
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001518static struct isa_driver snd_miro_driver = {
Krzysztof Helt70a5f112009-11-30 07:45:47 +01001519 .match = snd_miro_isa_match,
1520 .probe = snd_miro_isa_probe,
1521 .remove = __devexit_p(snd_miro_isa_remove),
Martin Langer1841f6132006-03-27 12:41:01 +02001522 /* FIXME: suspend/resume */
1523 .driver = {
Rene Herman83c51c02007-03-20 11:33:46 +01001524 .name = DEV_NAME
Martin Langer1841f6132006-03-27 12:41:01 +02001525 },
1526};
1527
Krzysztof Helt306ecee2009-11-30 07:46:56 +01001528#ifdef CONFIG_PNP
1529
1530static int __devinit snd_card_miro_pnp(struct snd_miro *chip,
1531 struct pnp_card_link *card,
1532 const struct pnp_card_device_id *pid)
1533{
1534 struct pnp_dev *pdev;
1535 int err;
1536 struct pnp_dev *devmpu;
1537 struct pnp_dev *devmc;
1538
1539 pdev = pnp_request_card_device(card, pid->devs[0].id, NULL);
1540 if (pdev == NULL)
1541 return -EBUSY;
1542
1543 devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
1544 if (devmpu == NULL)
1545 return -EBUSY;
1546
1547 devmc = pnp_request_card_device(card, pid->devs[2].id, NULL);
1548 if (devmc == NULL)
1549 return -EBUSY;
1550
1551 err = pnp_activate_dev(pdev);
1552 if (err < 0) {
1553 snd_printk(KERN_ERR "AUDIO pnp configure failure: %d\n", err);
1554 return err;
1555 }
1556
1557 err = pnp_activate_dev(devmc);
1558 if (err < 0) {
Krzysztof Heltfd8d4732010-03-03 19:41:44 +01001559 snd_printk(KERN_ERR "MC pnp configure failure: %d\n",
Krzysztof Helt306ecee2009-11-30 07:46:56 +01001560 err);
1561 return err;
1562 }
1563
1564 port = pnp_port_start(pdev, 1);
1565 fm_port = pnp_port_start(pdev, 2) + 8;
1566
1567 /*
1568 * The MC(0) is never accessed and the miroSOUND PCM20 card does not
1569 * include it in the PnP resource range. OPTI93x include it.
1570 */
1571 chip->mc_base = pnp_port_start(devmc, 0) - 1;
1572 chip->mc_base_size = pnp_port_len(devmc, 0) + 1;
1573
1574 irq = pnp_irq(pdev, 0);
1575 dma1 = pnp_dma(pdev, 0);
1576 dma2 = pnp_dma(pdev, 1);
1577
1578 if (mpu_port > 0) {
1579 err = pnp_activate_dev(devmpu);
1580 if (err < 0) {
1581 snd_printk(KERN_ERR "MPU401 pnp configure failure\n");
1582 mpu_port = -1;
1583 return err;
1584 }
1585 mpu_port = pnp_port_start(devmpu, 0);
1586 mpu_irq = pnp_irq(devmpu, 0);
1587 }
1588 return 0;
1589}
1590
1591static int __devinit snd_miro_pnp_probe(struct pnp_card_link *pcard,
1592 const struct pnp_card_device_id *pid)
1593{
1594 struct snd_card *card;
1595 int err;
1596 struct snd_miro *miro;
1597
1598 if (snd_miro_pnp_is_probed)
1599 return -EBUSY;
1600 if (!isapnp)
1601 return -ENODEV;
1602 err = snd_card_create(index, id, THIS_MODULE,
1603 sizeof(struct snd_miro), &card);
1604 if (err < 0)
1605 return err;
1606
1607 card->private_free = snd_card_miro_free;
1608 miro = card->private_data;
1609
1610 err = snd_card_miro_pnp(miro, pcard, pid);
1611 if (err) {
1612 snd_card_free(card);
1613 return err;
1614 }
1615
1616 /* only miroSOUND PCM20 and PCM12 == OPTi924 */
1617 err = snd_miro_init(miro, OPTi9XX_HW_82C924);
1618 if (err) {
1619 snd_card_free(card);
1620 return err;
1621 }
1622
1623 err = snd_miro_opti_check(miro);
1624 if (err) {
1625 snd_printk(KERN_ERR "OPTI chip not found\n");
1626 snd_card_free(card);
1627 return err;
1628 }
1629
1630 snd_card_set_dev(card, &pcard->card->dev);
1631 err = snd_miro_probe(card);
1632 if (err < 0) {
1633 snd_card_free(card);
1634 return err;
1635 }
1636 pnp_set_card_drvdata(pcard, card);
1637 snd_miro_pnp_is_probed = 1;
1638 return 0;
1639}
1640
1641static void __devexit snd_miro_pnp_remove(struct pnp_card_link * pcard)
1642{
1643 snd_card_free(pnp_get_card_drvdata(pcard));
1644 pnp_set_card_drvdata(pcard, NULL);
1645 snd_miro_pnp_is_probed = 0;
1646}
1647
1648static struct pnp_card_driver miro_pnpc_driver = {
1649 .flags = PNP_DRIVER_RES_DISABLE,
1650 .name = "miro",
1651 .id_table = snd_miro_pnpids,
1652 .probe = snd_miro_pnp_probe,
1653 .remove = __devexit_p(snd_miro_pnp_remove),
1654};
1655#endif
1656
Martin Langer1841f6132006-03-27 12:41:01 +02001657static int __init alsa_card_miro_init(void)
1658{
Krzysztof Helt306ecee2009-11-30 07:46:56 +01001659#ifdef CONFIG_PNP
1660 pnp_register_card_driver(&miro_pnpc_driver);
1661 if (snd_miro_pnp_is_probed)
1662 return 0;
1663 pnp_unregister_card_driver(&miro_pnpc_driver);
1664#endif
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001665 return isa_register_driver(&snd_miro_driver, 1);
Martin Langer1841f6132006-03-27 12:41:01 +02001666}
1667
1668static void __exit alsa_card_miro_exit(void)
1669{
Krzysztof Helt306ecee2009-11-30 07:46:56 +01001670 if (!snd_miro_pnp_is_probed) {
1671 isa_unregister_driver(&snd_miro_driver);
1672 return;
1673 }
1674#ifdef CONFIG_PNP
1675 pnp_unregister_card_driver(&miro_pnpc_driver);
1676#endif
Martin Langer1841f6132006-03-27 12:41:01 +02001677}
1678
1679module_init(alsa_card_miro_init)
1680module_exit(alsa_card_miro_exit)