blob: 2a1e2f5d12c2abe78e99192d31c14d39b55b7f13 [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>
Martin Langer1841f6132006-03-27 12:41:01 +020028#include <linux/delay.h>
29#include <linux/slab.h>
30#include <linux/ioport.h>
31#include <linux/moduleparam.h>
32#include <asm/io.h>
33#include <asm/dma.h>
34#include <sound/core.h>
35#include <sound/cs4231.h>
36#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>
43#include "miro.h"
44
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;
63
64module_param(index, int, 0444);
65MODULE_PARM_DESC(index, "Index value for miro soundcard.");
66module_param(id, charp, 0444);
67MODULE_PARM_DESC(id, "ID string for miro soundcard.");
68module_param(port, long, 0444);
69MODULE_PARM_DESC(port, "WSS port # for miro driver.");
70module_param(mpu_port, long, 0444);
71MODULE_PARM_DESC(mpu_port, "MPU-401 port # for miro driver.");
72module_param(fm_port, long, 0444);
73MODULE_PARM_DESC(fm_port, "FM Port # for miro driver.");
74module_param(irq, int, 0444);
75MODULE_PARM_DESC(irq, "WSS irq # for miro driver.");
76module_param(mpu_irq, int, 0444);
77MODULE_PARM_DESC(mpu_irq, "MPU-401 irq # for miro driver.");
78module_param(dma1, int, 0444);
79MODULE_PARM_DESC(dma1, "1st dma # for miro driver.");
80module_param(dma2, int, 0444);
81MODULE_PARM_DESC(dma2, "2nd dma # for miro driver.");
82module_param(wss, int, 0444);
83MODULE_PARM_DESC(wss, "wss mode");
84module_param(ide, int, 0444);
85MODULE_PARM_DESC(ide, "enable ide port");
86
87#define OPTi9XX_HW_DETECT 0
88#define OPTi9XX_HW_82C928 1
89#define OPTi9XX_HW_82C929 2
90#define OPTi9XX_HW_82C924 3
91#define OPTi9XX_HW_82C925 4
92#define OPTi9XX_HW_82C930 5
93#define OPTi9XX_HW_82C931 6
94#define OPTi9XX_HW_82C933 7
95#define OPTi9XX_HW_LAST OPTi9XX_HW_82C933
96
97#define OPTi9XX_MC_REG(n) n
98
99
100struct snd_miro {
101 unsigned short hardware;
102 unsigned char password;
103 char name[7];
104
105 struct resource *res_mc_base;
106 struct resource *res_aci_port;
107
108 unsigned long mc_base;
109 unsigned long mc_base_size;
110 unsigned long pwd_reg;
111
112 spinlock_t lock;
113 struct snd_card *card;
114 struct snd_pcm *pcm;
115
116 long wss_base;
117 int irq;
118 int dma1;
119 int dma2;
120
121 long fm_port;
122
123 long mpu_port;
124 int mpu_irq;
125
126 unsigned long aci_port;
127 int aci_vendor;
128 int aci_product;
129 int aci_version;
130 int aci_amp;
131 int aci_preamp;
132 int aci_solomode;
133
134 struct mutex aci_mutex;
135};
136
137static void snd_miro_proc_init(struct snd_miro * miro);
138
Martin Langer1841f6132006-03-27 12:41:01 +0200139static char * snd_opti9xx_names[] = {
140 "unkown",
141 "82C928", "82C929",
142 "82C924", "82C925",
143 "82C930", "82C931", "82C933"
144};
145
146/*
147 * ACI control
148 */
149
150static int aci_busy_wait(struct snd_miro * miro)
151{
152 long timeout;
153 unsigned char byte;
154
155 for (timeout = 1; timeout <= ACI_MINTIME+30; timeout++) {
156 if (((byte=inb(miro->aci_port + ACI_REG_BUSY)) & 1) == 0) {
157 if (timeout >= ACI_MINTIME)
158 snd_printd("aci ready in round %ld.\n",
159 timeout-ACI_MINTIME);
160 return byte;
161 }
162 if (timeout >= ACI_MINTIME) {
163 long out=10*HZ;
164 switch (timeout-ACI_MINTIME) {
165 case 0 ... 9:
166 out /= 10;
167 case 10 ... 19:
168 out /= 10;
169 case 20 ... 30:
170 out /= 10;
171 default:
172 set_current_state(TASK_UNINTERRUPTIBLE);
173 schedule_timeout(out);
174 break;
175 }
176 }
177 }
178 snd_printk(KERN_ERR "aci_busy_wait() time out\n");
179 return -EBUSY;
180}
181
182static inline int aci_write(struct snd_miro * miro, unsigned char byte)
183{
184 if (aci_busy_wait(miro) >= 0) {
185 outb(byte, miro->aci_port + ACI_REG_COMMAND);
186 return 0;
187 } else {
188 snd_printk(KERN_ERR "aci busy, aci_write(0x%x) stopped.\n", byte);
189 return -EBUSY;
190 }
191}
192
193static inline int aci_read(struct snd_miro * miro)
194{
195 unsigned char byte;
196
197 if (aci_busy_wait(miro) >= 0) {
198 byte=inb(miro->aci_port + ACI_REG_STATUS);
199 return byte;
200 } else {
201 snd_printk(KERN_ERR "aci busy, aci_read() stopped.\n");
202 return -EBUSY;
203 }
204}
205
206static int aci_cmd(struct snd_miro * miro, int write1, int write2, int write3)
207{
208 int write[] = {write1, write2, write3};
209 int value, i;
210
211 if (mutex_lock_interruptible(&miro->aci_mutex))
212 return -EINTR;
213
214 for (i=0; i<3; i++) {
215 if (write[i]< 0 || write[i] > 255)
216 break;
217 else {
218 value = aci_write(miro, write[i]);
219 if (value < 0)
220 goto out;
221 }
222 }
223
224 value = aci_read(miro);
225
226out: mutex_unlock(&miro->aci_mutex);
227 return value;
228}
229
230static int aci_getvalue(struct snd_miro * miro, unsigned char index)
231{
232 return aci_cmd(miro, ACI_STATUS, index, -1);
233}
234
235static int aci_setvalue(struct snd_miro * miro, unsigned char index, int value)
236{
237 return aci_cmd(miro, index, value, -1);
238}
239
240/*
241 * MIXER part
242 */
243
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200244#define snd_miro_info_capture snd_ctl_boolean_mono_info
Martin Langer1841f6132006-03-27 12:41:01 +0200245
246static int snd_miro_get_capture(struct snd_kcontrol *kcontrol,
247 struct snd_ctl_elem_value *ucontrol)
248{
249 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
250 int value;
251
252 if ((value = aci_getvalue(miro, ACI_S_GENERAL)) < 0) {
253 snd_printk(KERN_ERR "snd_miro_get_capture() failed: %d\n", value);
254 return value;
255 }
256
257 ucontrol->value.integer.value[0] = value & 0x20;
258
259 return 0;
260}
261
262static int snd_miro_put_capture(struct snd_kcontrol *kcontrol,
263 struct snd_ctl_elem_value *ucontrol)
264{
265 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
266 int change, value, error;
267
268 value = !(ucontrol->value.integer.value[0]);
269
270 if ((error = aci_setvalue(miro, ACI_SET_SOLOMODE, value)) < 0) {
271 snd_printk(KERN_ERR "snd_miro_put_capture() failed: %d\n", error);
272 return error;
273 }
274
275 change = (value != miro->aci_solomode);
276 miro->aci_solomode = value;
277
278 return change;
279}
280
281static int snd_miro_info_preamp(struct snd_kcontrol *kcontrol,
282 struct snd_ctl_elem_info *uinfo)
283{
284 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
285 uinfo->count = 1;
286 uinfo->value.integer.min = 0;
287 uinfo->value.integer.max = 3;
288
289 return 0;
290}
291
292static int snd_miro_get_preamp(struct snd_kcontrol *kcontrol,
293 struct snd_ctl_elem_value *ucontrol)
294{
295 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
296 int value;
297
298 if (miro->aci_version <= 176) {
299
300 /*
301 OSS says it's not readable with versions < 176.
302 But it doesn't work on my card,
303 which is a PCM12 with aci_version = 176.
304 */
305
306 ucontrol->value.integer.value[0] = miro->aci_preamp;
307 return 0;
308 }
309
310 if ((value = aci_getvalue(miro, ACI_GET_PREAMP)) < 0) {
311 snd_printk(KERN_ERR "snd_miro_get_preamp() failed: %d\n", value);
312 return value;
313 }
314
315 ucontrol->value.integer.value[0] = value;
316
317 return 0;
318}
319
320static int snd_miro_put_preamp(struct snd_kcontrol *kcontrol,
321 struct snd_ctl_elem_value *ucontrol)
322{
323 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
324 int error, value, change;
325
326 value = ucontrol->value.integer.value[0];
327
328 if ((error = aci_setvalue(miro, ACI_SET_PREAMP, value)) < 0) {
329 snd_printk(KERN_ERR "snd_miro_put_preamp() failed: %d\n", error);
330 return error;
331 }
332
333 change = (value != miro->aci_preamp);
334 miro->aci_preamp = value;
335
336 return change;
337}
338
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200339#define snd_miro_info_amp snd_ctl_boolean_mono_info
Martin Langer1841f6132006-03-27 12:41:01 +0200340
341static int snd_miro_get_amp(struct snd_kcontrol *kcontrol,
342 struct snd_ctl_elem_value *ucontrol)
343{
344 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
345 ucontrol->value.integer.value[0] = miro->aci_amp;
346
347 return 0;
348}
349
350static int snd_miro_put_amp(struct snd_kcontrol *kcontrol,
351 struct snd_ctl_elem_value *ucontrol)
352{
353 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
354 int error, value, change;
355
356 value = ucontrol->value.integer.value[0];
357
358 if ((error = aci_setvalue(miro, ACI_SET_POWERAMP, value)) < 0) {
359 snd_printk(KERN_ERR "snd_miro_put_amp() to %d failed: %d\n", value, error);
360 return error;
361 }
362
363 change = (value != miro->aci_amp);
364 miro->aci_amp = value;
365
366 return change;
367}
368
369#define MIRO_DOUBLE(ctl_name, ctl_index, get_right_reg, set_right_reg) \
370{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
371 .name = ctl_name, \
372 .index = ctl_index, \
373 .info = snd_miro_info_double, \
374 .get = snd_miro_get_double, \
375 .put = snd_miro_put_double, \
376 .private_value = get_right_reg | (set_right_reg << 8) \
377}
378
379static int snd_miro_info_double(struct snd_kcontrol *kcontrol,
380 struct snd_ctl_elem_info *uinfo)
381{
382 int reg = kcontrol->private_value & 0xff;
383
384 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
385 uinfo->count = 2;
386
387 if ((reg >= ACI_GET_EQ1) && (reg <= ACI_GET_EQ7)) {
388
389 /* equalizer elements */
390
391 uinfo->value.integer.min = - 0x7f;
392 uinfo->value.integer.max = 0x7f;
393 } else {
394
395 /* non-equalizer elements */
396
397 uinfo->value.integer.min = 0;
398 uinfo->value.integer.max = 0x20;
399 }
400
401 return 0;
402}
403
404static int snd_miro_get_double(struct snd_kcontrol *kcontrol,
405 struct snd_ctl_elem_value *uinfo)
406{
407 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
408 int left_val, right_val;
409
410 int right_reg = kcontrol->private_value & 0xff;
411 int left_reg = right_reg + 1;
412
413 if ((right_val = aci_getvalue(miro, right_reg)) < 0) {
414 snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", right_reg, right_val);
415 return right_val;
416 }
417
418 if ((left_val = aci_getvalue(miro, left_reg)) < 0) {
419 snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", left_reg, left_val);
420 return left_val;
421 }
422
423 if ((right_reg >= ACI_GET_EQ1) && (right_reg <= ACI_GET_EQ7)) {
424
425 /* equalizer elements */
426
427 if (left_val < 0x80) {
428 uinfo->value.integer.value[0] = left_val;
429 } else {
430 uinfo->value.integer.value[0] = 0x80 - left_val;
431 }
432
433 if (right_val < 0x80) {
434 uinfo->value.integer.value[1] = right_val;
435 } else {
436 uinfo->value.integer.value[1] = 0x80 - right_val;
437 }
438
439 } else {
440
441 /* non-equalizer elements */
442
443 uinfo->value.integer.value[0] = 0x20 - left_val;
444 uinfo->value.integer.value[1] = 0x20 - right_val;
445 }
446
447 return 0;
448}
449
450static int snd_miro_put_double(struct snd_kcontrol *kcontrol,
451 struct snd_ctl_elem_value *ucontrol)
452{
453 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
454 int left, right, left_old, right_old;
455 int setreg_left, setreg_right, getreg_left, getreg_right;
456 int change, error;
457
458 left = ucontrol->value.integer.value[0];
459 right = ucontrol->value.integer.value[1];
460
461 setreg_right = (kcontrol->private_value >> 8) & 0xff;
462 if (setreg_right == ACI_SET_MASTER) {
463 setreg_left = setreg_right + 1;
464 } else {
465 setreg_left = setreg_right + 8;
466 }
467
468 getreg_right = kcontrol->private_value & 0xff;
469 getreg_left = getreg_right + 1;
470
471 if ((left_old = aci_getvalue(miro, getreg_left)) < 0) {
472 snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", getreg_left, left_old);
473 return left_old;
474 }
475
476 if ((right_old = aci_getvalue(miro, getreg_right)) < 0) {
477 snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", getreg_right, right_old);
478 return right_old;
479 }
480
481 if ((getreg_right >= ACI_GET_EQ1) && (getreg_right <= ACI_GET_EQ7)) {
482
483 /* equalizer elements */
484
Takashi Iwai3b892462007-11-15 16:17:24 +0100485 if (left < -0x7f || left > 0x7f ||
486 right < -0x7f || right > 0x7f)
487 return -EINVAL;
488
Martin Langer1841f6132006-03-27 12:41:01 +0200489 if (left_old > 0x80)
490 left_old = 0x80 - left_old;
491 if (right_old > 0x80)
492 right_old = 0x80 - right_old;
493
494 if (left >= 0) {
495 if ((error = aci_setvalue(miro, setreg_left, left)) < 0) {
496 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
497 left, error);
498 return error;
499 }
500 } else {
501 if ((error = aci_setvalue(miro, setreg_left, 0x80 - left)) < 0) {
502 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
503 0x80 - left, error);
504 return error;
505 }
506 }
507
508 if (right >= 0) {
509 if ((error = aci_setvalue(miro, setreg_right, right)) < 0) {
510 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
511 right, error);
512 return error;
513 }
514 } else {
515 if ((error = aci_setvalue(miro, setreg_right, 0x80 - right)) < 0) {
516 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
517 0x80 - right, error);
518 return error;
519 }
520 }
521
522 } else {
523
524 /* non-equalizer elements */
525
Takashi Iwai3b892462007-11-15 16:17:24 +0100526 if (left < 0 || left > 0x20 ||
527 right < 0 || right > 0x20)
528 return -EINVAL;
529
Martin Langer1841f6132006-03-27 12:41:01 +0200530 left_old = 0x20 - left_old;
531 right_old = 0x20 - right_old;
532
533 if ((error = aci_setvalue(miro, setreg_left, 0x20 - left)) < 0) {
534 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
535 0x20 - left, error);
536 return error;
537 }
538 if ((error = aci_setvalue(miro, setreg_right, 0x20 - right)) < 0) {
539 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
540 0x20 - right, error);
541 return error;
542 }
543 }
544
545 change = (left != left_old) || (right != right_old);
546
547 return change;
548}
549
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100550static struct snd_kcontrol_new snd_miro_controls[] __devinitdata = {
Martin Langer1841f6132006-03-27 12:41:01 +0200551MIRO_DOUBLE("Master Playback Volume", 0, ACI_GET_MASTER, ACI_SET_MASTER),
552MIRO_DOUBLE("Mic Playback Volume", 1, ACI_GET_MIC, ACI_SET_MIC),
553MIRO_DOUBLE("Line Playback Volume", 1, ACI_GET_LINE, ACI_SET_LINE),
554MIRO_DOUBLE("CD Playback Volume", 0, ACI_GET_CD, ACI_SET_CD),
555MIRO_DOUBLE("Synth Playback Volume", 0, ACI_GET_SYNTH, ACI_SET_SYNTH),
556MIRO_DOUBLE("PCM Playback Volume", 1, ACI_GET_PCM, ACI_SET_PCM),
557MIRO_DOUBLE("Aux Playback Volume", 2, ACI_GET_LINE2, ACI_SET_LINE2),
558};
559
560/* Equalizer with seven bands (only PCM20)
561 from -12dB up to +12dB on each band */
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100562static struct snd_kcontrol_new snd_miro_eq_controls[] __devinitdata = {
Martin Langer1841f6132006-03-27 12:41:01 +0200563MIRO_DOUBLE("Tone Control - 28 Hz", 0, ACI_GET_EQ1, ACI_SET_EQ1),
564MIRO_DOUBLE("Tone Control - 160 Hz", 0, ACI_GET_EQ2, ACI_SET_EQ2),
565MIRO_DOUBLE("Tone Control - 400 Hz", 0, ACI_GET_EQ3, ACI_SET_EQ3),
566MIRO_DOUBLE("Tone Control - 1 kHz", 0, ACI_GET_EQ4, ACI_SET_EQ4),
567MIRO_DOUBLE("Tone Control - 2.5 kHz", 0, ACI_GET_EQ5, ACI_SET_EQ5),
568MIRO_DOUBLE("Tone Control - 6.3 kHz", 0, ACI_GET_EQ6, ACI_SET_EQ6),
569MIRO_DOUBLE("Tone Control - 16 kHz", 0, ACI_GET_EQ7, ACI_SET_EQ7),
570};
571
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100572static struct snd_kcontrol_new snd_miro_radio_control[] __devinitdata = {
Martin Langer1841f6132006-03-27 12:41:01 +0200573MIRO_DOUBLE("Radio Playback Volume", 0, ACI_GET_LINE1, ACI_SET_LINE1),
574};
575
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100576static struct snd_kcontrol_new snd_miro_line_control[] __devinitdata = {
Martin Langer1841f6132006-03-27 12:41:01 +0200577MIRO_DOUBLE("Line Playback Volume", 2, ACI_GET_LINE1, ACI_SET_LINE1),
578};
579
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100580static struct snd_kcontrol_new snd_miro_preamp_control[] __devinitdata = {
Martin Langer1841f6132006-03-27 12:41:01 +0200581{
582 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
583 .name = "Mic Boost",
584 .index = 1,
585 .info = snd_miro_info_preamp,
586 .get = snd_miro_get_preamp,
587 .put = snd_miro_put_preamp,
588}};
589
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100590static struct snd_kcontrol_new snd_miro_amp_control[] __devinitdata = {
Martin Langer1841f6132006-03-27 12:41:01 +0200591{
592 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
593 .name = "Line Boost",
594 .index = 0,
595 .info = snd_miro_info_amp,
596 .get = snd_miro_get_amp,
597 .put = snd_miro_put_amp,
598}};
599
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100600static struct snd_kcontrol_new snd_miro_capture_control[] __devinitdata = {
Martin Langer1841f6132006-03-27 12:41:01 +0200601{
602 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
603 .name = "PCM Capture Switch",
604 .index = 0,
605 .info = snd_miro_info_capture,
606 .get = snd_miro_get_capture,
607 .put = snd_miro_put_capture,
608}};
609
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100610static unsigned char aci_init_values[][2] __devinitdata = {
Martin Langer1841f6132006-03-27 12:41:01 +0200611 { ACI_SET_MUTE, 0x00 },
612 { ACI_SET_POWERAMP, 0x00 },
613 { ACI_SET_PREAMP, 0x00 },
614 { ACI_SET_SOLOMODE, 0x00 },
615 { ACI_SET_MIC + 0, 0x20 },
616 { ACI_SET_MIC + 8, 0x20 },
617 { ACI_SET_LINE + 0, 0x20 },
618 { ACI_SET_LINE + 8, 0x20 },
619 { ACI_SET_CD + 0, 0x20 },
620 { ACI_SET_CD + 8, 0x20 },
621 { ACI_SET_PCM + 0, 0x20 },
622 { ACI_SET_PCM + 8, 0x20 },
623 { ACI_SET_LINE1 + 0, 0x20 },
624 { ACI_SET_LINE1 + 8, 0x20 },
625 { ACI_SET_LINE2 + 0, 0x20 },
626 { ACI_SET_LINE2 + 8, 0x20 },
627 { ACI_SET_SYNTH + 0, 0x20 },
628 { ACI_SET_SYNTH + 8, 0x20 },
629 { ACI_SET_MASTER + 0, 0x20 },
630 { ACI_SET_MASTER + 1, 0x20 },
631};
632
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100633static int __devinit snd_set_aci_init_values(struct snd_miro *miro)
Martin Langer1841f6132006-03-27 12:41:01 +0200634{
635 int idx, error;
636
637 /* enable WSS on PCM1 */
638
639 if ((miro->aci_product == 'A') && wss) {
640 if ((error = aci_setvalue(miro, ACI_SET_WSS, wss)) < 0) {
641 snd_printk(KERN_ERR "enabling WSS mode failed\n");
642 return error;
643 }
644 }
645
646 /* enable IDE port */
647
648 if (ide) {
649 if ((error = aci_setvalue(miro, ACI_SET_IDE, ide)) < 0) {
650 snd_printk(KERN_ERR "enabling IDE port failed\n");
651 return error;
652 }
653 }
654
655 /* set common aci values */
656
657 for (idx = 0; idx < ARRAY_SIZE(aci_init_values); idx++)
658 if ((error = aci_setvalue(miro, aci_init_values[idx][0],
659 aci_init_values[idx][1])) < 0) {
660 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
661 aci_init_values[idx][0], error);
662 return error;
663 }
664
665 miro->aci_amp = 0;
666 miro->aci_preamp = 0;
667 miro->aci_solomode = 1;
668
669 return 0;
670}
671
Randy Dunlap9478bc32008-01-23 11:52:38 +0100672static int __devinit snd_miro_mixer(struct snd_miro *miro)
Martin Langer1841f6132006-03-27 12:41:01 +0200673{
674 struct snd_card *card;
675 unsigned int idx;
676 int err;
677
678 snd_assert(miro != NULL && miro->card != NULL, return -EINVAL);
679
680 card = miro->card;
681
682 switch (miro->hardware) {
683 case OPTi9XX_HW_82C924:
684 strcpy(card->mixername, "ACI & OPTi924");
685 break;
686 case OPTi9XX_HW_82C929:
687 strcpy(card->mixername, "ACI & OPTi929");
688 break;
689 default:
690 snd_BUG();
691 break;
692 }
693
694 for (idx = 0; idx < ARRAY_SIZE(snd_miro_controls); idx++) {
695 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_controls[idx], miro))) < 0)
696 return err;
697 }
698
699 if ((miro->aci_product == 'A') || (miro->aci_product == 'B')) {
700 /* PCM1/PCM12 with power-amp and Line 2 */
701 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_line_control[0], miro))) < 0)
702 return err;
703 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_amp_control[0], miro))) < 0)
704 return err;
705 }
706
707 if ((miro->aci_product == 'B') || (miro->aci_product == 'C')) {
708 /* PCM12/PCM20 with mic-preamp */
709 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_preamp_control[0], miro))) < 0)
710 return err;
711 if (miro->aci_version >= 176)
712 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_capture_control[0], miro))) < 0)
713 return err;
714 }
715
716 if (miro->aci_product == 'C') {
717 /* PCM20 with radio and 7 band equalizer */
718 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_radio_control[0], miro))) < 0)
719 return err;
720 for (idx = 0; idx < ARRAY_SIZE(snd_miro_eq_controls); idx++) {
721 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_eq_controls[idx], miro))) < 0)
722 return err;
723 }
724 }
725
726 return 0;
727}
728
729static long snd_legacy_find_free_ioport(long *port_table, long size)
730{
731 while (*port_table != -1) {
732 struct resource *res;
733 if ((res = request_region(*port_table, size,
734 "ALSA test")) != NULL) {
Takashi Iwai10d150e2006-03-27 13:42:39 +0200735 release_and_free_resource(res);
Martin Langer1841f6132006-03-27 12:41:01 +0200736 return *port_table;
737 }
738 port_table++;
739 }
740 return -1;
741}
742
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100743static int __devinit snd_miro_init(struct snd_miro *chip,
744 unsigned short hardware)
Martin Langer1841f6132006-03-27 12:41:01 +0200745{
746 static int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2};
747
748 chip->hardware = hardware;
749 strcpy(chip->name, snd_opti9xx_names[hardware]);
750
751 chip->mc_base_size = opti9xx_mc_size[hardware];
752
753 spin_lock_init(&chip->lock);
754
755 chip->wss_base = -1;
756 chip->irq = -1;
757 chip->dma1 = -1;
758 chip->dma2 = -1;
759 chip->fm_port = -1;
760 chip->mpu_port = -1;
761 chip->mpu_irq = -1;
762
763 switch (hardware) {
764 case OPTi9XX_HW_82C929:
765 chip->mc_base = 0xf8c;
766 chip->password = 0xe3;
767 chip->pwd_reg = 3;
768 break;
769
770 case OPTi9XX_HW_82C924:
771 chip->mc_base = 0xf8c;
772 chip->password = 0xe5;
773 chip->pwd_reg = 3;
774 break;
775
776 default:
777 snd_printk(KERN_ERR "sorry, no support for %d\n", hardware);
778 return -ENODEV;
779 }
780
781 return 0;
782}
783
784static unsigned char snd_miro_read(struct snd_miro *chip,
785 unsigned char reg)
786{
787 unsigned long flags;
788 unsigned char retval = 0xff;
789
790 spin_lock_irqsave(&chip->lock, flags);
791 outb(chip->password, chip->mc_base + chip->pwd_reg);
792
793 switch (chip->hardware) {
794 case OPTi9XX_HW_82C924:
795 if (reg > 7) {
796 outb(reg, chip->mc_base + 8);
797 outb(chip->password, chip->mc_base + chip->pwd_reg);
798 retval = inb(chip->mc_base + 9);
799 break;
800 }
801
802 case OPTi9XX_HW_82C929:
803 retval = inb(chip->mc_base + reg);
804 break;
805
806 default:
807 snd_printk(KERN_ERR "sorry, no support for %d\n", chip->hardware);
808 }
809
810 spin_unlock_irqrestore(&chip->lock, flags);
811 return retval;
812}
813
814static void snd_miro_write(struct snd_miro *chip, unsigned char reg,
815 unsigned char value)
816{
817 unsigned long flags;
818
819 spin_lock_irqsave(&chip->lock, flags);
820 outb(chip->password, chip->mc_base + chip->pwd_reg);
821
822 switch (chip->hardware) {
823 case OPTi9XX_HW_82C924:
824 if (reg > 7) {
825 outb(reg, chip->mc_base + 8);
826 outb(chip->password, chip->mc_base + chip->pwd_reg);
827 outb(value, chip->mc_base + 9);
828 break;
829 }
830
831 case OPTi9XX_HW_82C929:
832 outb(value, chip->mc_base + reg);
833 break;
834
835 default:
836 snd_printk(KERN_ERR "sorry, no support for %d\n", chip->hardware);
837 }
838
839 spin_unlock_irqrestore(&chip->lock, flags);
840}
841
842
843#define snd_miro_write_mask(chip, reg, value, mask) \
844 snd_miro_write(chip, reg, \
845 (snd_miro_read(chip, reg) & ~(mask)) | ((value) & (mask)))
846
847/*
848 * Proc Interface
849 */
850
851static void snd_miro_proc_read(struct snd_info_entry * entry,
852 struct snd_info_buffer *buffer)
853{
854 struct snd_miro *miro = (struct snd_miro *) entry->private_data;
855 char* model = "unknown";
856
857 /* miroSOUND PCM1 pro, early PCM12 */
858
859 if ((miro->hardware == OPTi9XX_HW_82C929) &&
860 (miro->aci_vendor == 'm') &&
861 (miro->aci_product == 'A')) {
862 switch(miro->aci_version) {
863 case 3:
864 model = "miroSOUND PCM1 pro";
865 break;
866 default:
867 model = "miroSOUND PCM1 pro / (early) PCM12";
868 break;
869 }
870 }
871
872 /* miroSOUND PCM12, PCM12 (Rev. E), PCM12 pnp */
873
874 if ((miro->hardware == OPTi9XX_HW_82C924) &&
875 (miro->aci_vendor == 'm') &&
876 (miro->aci_product == 'B')) {
877 switch(miro->aci_version) {
878 case 4:
879 model = "miroSOUND PCM12";
880 break;
881 case 176:
882 model = "miroSOUND PCM12 (Rev. E)";
883 break;
884 default:
885 model = "miroSOUND PCM12 / PCM12 pnp";
886 break;
887 }
888 }
889
890 /* miroSOUND PCM20 radio */
891
892 if ((miro->hardware == OPTi9XX_HW_82C924) &&
893 (miro->aci_vendor == 'm') &&
894 (miro->aci_product == 'C')) {
895 switch(miro->aci_version) {
896 case 7:
897 model = "miroSOUND PCM20 radio (Rev. E)";
898 break;
899 default:
900 model = "miroSOUND PCM20 radio";
901 break;
902 }
903 }
904
905 snd_iprintf(buffer, "\nGeneral information:\n");
906 snd_iprintf(buffer, " model : %s\n", model);
907 snd_iprintf(buffer, " opti : %s\n", miro->name);
908 snd_iprintf(buffer, " codec : %s\n", miro->pcm->name);
909 snd_iprintf(buffer, " port : 0x%lx\n", miro->wss_base);
910 snd_iprintf(buffer, " irq : %d\n", miro->irq);
911 snd_iprintf(buffer, " dma : %d,%d\n\n", miro->dma1, miro->dma2);
912
913 snd_iprintf(buffer, "MPU-401:\n");
914 snd_iprintf(buffer, " port : 0x%lx\n", miro->mpu_port);
915 snd_iprintf(buffer, " irq : %d\n\n", miro->mpu_irq);
916
917 snd_iprintf(buffer, "ACI information:\n");
918 snd_iprintf(buffer, " vendor : ");
919 switch(miro->aci_vendor) {
920 case 'm':
921 snd_iprintf(buffer, "Miro\n");
922 break;
923 default:
924 snd_iprintf(buffer, "unknown (0x%x)\n", miro->aci_vendor);
925 break;
926 }
927
928 snd_iprintf(buffer, " product : ");
929 switch(miro->aci_product) {
930 case 'A':
931 snd_iprintf(buffer, "miroSOUND PCM1 pro / (early) PCM12\n");
932 break;
933 case 'B':
934 snd_iprintf(buffer, "miroSOUND PCM12\n");
935 break;
936 case 'C':
937 snd_iprintf(buffer, "miroSOUND PCM20 radio\n");
938 break;
939 default:
940 snd_iprintf(buffer, "unknown (0x%x)\n", miro->aci_product);
941 break;
942 }
943
944 snd_iprintf(buffer, " firmware: %d (0x%x)\n",
945 miro->aci_version, miro->aci_version);
946 snd_iprintf(buffer, " port : 0x%lx-0x%lx\n",
947 miro->aci_port, miro->aci_port+2);
948 snd_iprintf(buffer, " wss : 0x%x\n", wss);
949 snd_iprintf(buffer, " ide : 0x%x\n", ide);
950 snd_iprintf(buffer, " solomode: 0x%x\n", miro->aci_solomode);
951 snd_iprintf(buffer, " amp : 0x%x\n", miro->aci_amp);
952 snd_iprintf(buffer, " preamp : 0x%x\n", miro->aci_preamp);
953}
954
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100955static void __devinit snd_miro_proc_init(struct snd_miro * miro)
Martin Langer1841f6132006-03-27 12:41:01 +0200956{
957 struct snd_info_entry *entry;
958
959 if (! snd_card_proc_new(miro->card, "miro", &entry))
Takashi Iwaibf850202006-04-28 15:13:41 +0200960 snd_info_set_text_ops(entry, miro, snd_miro_proc_read);
Martin Langer1841f6132006-03-27 12:41:01 +0200961}
962
963/*
964 * Init
965 */
966
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100967static int __devinit snd_miro_configure(struct snd_miro *chip)
Martin Langer1841f6132006-03-27 12:41:01 +0200968{
969 unsigned char wss_base_bits;
970 unsigned char irq_bits;
971 unsigned char dma_bits;
972 unsigned char mpu_port_bits = 0;
973 unsigned char mpu_irq_bits;
974 unsigned long flags;
975
976 switch (chip->hardware) {
977 case OPTi9XX_HW_82C924:
978 snd_miro_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02);
979 snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
980 snd_miro_write_mask(chip, OPTi9XX_MC_REG(2), 0x20, 0x20); /* OPL4 */
981 snd_miro_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff);
982 snd_miro_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
983 break;
984 case OPTi9XX_HW_82C929:
985 /* untested init commands for OPTi929 */
986 snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
987 snd_miro_write_mask(chip, OPTi9XX_MC_REG(2), 0x20, 0x20); /* OPL4 */
988 snd_miro_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c);
989 snd_miro_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
990 break;
991 default:
992 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
993 return -EINVAL;
994 }
995
996 switch (chip->wss_base) {
997 case 0x530:
998 wss_base_bits = 0x00;
999 break;
1000 case 0x604:
1001 wss_base_bits = 0x03;
1002 break;
1003 case 0xe80:
1004 wss_base_bits = 0x01;
1005 break;
1006 case 0xf40:
1007 wss_base_bits = 0x02;
1008 break;
1009 default:
1010 snd_printk(KERN_ERR "WSS port 0x%lx not valid\n", chip->wss_base);
1011 goto __skip_base;
1012 }
1013 snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30);
1014
1015__skip_base:
1016 switch (chip->irq) {
1017 case 5:
1018 irq_bits = 0x05;
1019 break;
1020 case 7:
1021 irq_bits = 0x01;
1022 break;
1023 case 9:
1024 irq_bits = 0x02;
1025 break;
1026 case 10:
1027 irq_bits = 0x03;
1028 break;
1029 case 11:
1030 irq_bits = 0x04;
1031 break;
1032 default:
1033 snd_printk(KERN_ERR "WSS irq # %d not valid\n", chip->irq);
1034 goto __skip_resources;
1035 }
1036
1037 switch (chip->dma1) {
1038 case 0:
1039 dma_bits = 0x01;
1040 break;
1041 case 1:
1042 dma_bits = 0x02;
1043 break;
1044 case 3:
1045 dma_bits = 0x03;
1046 break;
1047 default:
1048 snd_printk(KERN_ERR "WSS dma1 # %d not valid\n", chip->dma1);
1049 goto __skip_resources;
1050 }
1051
1052 if (chip->dma1 == chip->dma2) {
1053 snd_printk(KERN_ERR "don't want to share dmas\n");
1054 return -EBUSY;
1055 }
1056
1057 switch (chip->dma2) {
1058 case 0:
1059 case 1:
1060 break;
1061 default:
1062 snd_printk(KERN_ERR "WSS dma2 # %d not valid\n", chip->dma2);
1063 goto __skip_resources;
1064 }
1065 dma_bits |= 0x04;
1066
1067 spin_lock_irqsave(&chip->lock, flags);
1068 outb(irq_bits << 3 | dma_bits, chip->wss_base);
1069 spin_unlock_irqrestore(&chip->lock, flags);
1070
1071__skip_resources:
1072 if (chip->hardware > OPTi9XX_HW_82C928) {
1073 switch (chip->mpu_port) {
1074 case 0:
1075 case -1:
1076 break;
1077 case 0x300:
1078 mpu_port_bits = 0x03;
1079 break;
1080 case 0x310:
1081 mpu_port_bits = 0x02;
1082 break;
1083 case 0x320:
1084 mpu_port_bits = 0x01;
1085 break;
1086 case 0x330:
1087 mpu_port_bits = 0x00;
1088 break;
1089 default:
1090 snd_printk(KERN_ERR "MPU-401 port 0x%lx not valid\n",
1091 chip->mpu_port);
1092 goto __skip_mpu;
1093 }
1094
1095 switch (chip->mpu_irq) {
1096 case 5:
1097 mpu_irq_bits = 0x02;
1098 break;
1099 case 7:
1100 mpu_irq_bits = 0x03;
1101 break;
1102 case 9:
1103 mpu_irq_bits = 0x00;
1104 break;
1105 case 10:
1106 mpu_irq_bits = 0x01;
1107 break;
1108 default:
1109 snd_printk(KERN_ERR "MPU-401 irq # %d not valid\n",
1110 chip->mpu_irq);
1111 goto __skip_mpu;
1112 }
1113
1114 snd_miro_write_mask(chip, OPTi9XX_MC_REG(6),
1115 (chip->mpu_port <= 0) ? 0x00 :
1116 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
1117 0xf8);
1118 }
1119__skip_mpu:
1120
1121 return 0;
1122}
1123
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001124static int __devinit snd_card_miro_detect(struct snd_card *card,
1125 struct snd_miro *chip)
Martin Langer1841f6132006-03-27 12:41:01 +02001126{
1127 int i, err;
1128 unsigned char value;
1129
1130 for (i = OPTi9XX_HW_82C929; i <= OPTi9XX_HW_82C924; i++) {
1131
1132 if ((err = snd_miro_init(chip, i)) < 0)
1133 return err;
1134
1135 if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL)
1136 continue;
1137
1138 value = snd_miro_read(chip, OPTi9XX_MC_REG(1));
1139 if ((value != 0xff) && (value != inb(chip->mc_base + 1)))
1140 if (value == snd_miro_read(chip, OPTi9XX_MC_REG(1)))
1141 return 1;
1142
Takashi Iwai10d150e2006-03-27 13:42:39 +02001143 release_and_free_resource(chip->res_mc_base);
Martin Langer1841f6132006-03-27 12:41:01 +02001144 chip->res_mc_base = NULL;
1145
1146 }
1147
1148 return -ENODEV;
1149}
1150
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001151static int __devinit snd_card_miro_aci_detect(struct snd_card *card,
1152 struct snd_miro * miro)
Martin Langer1841f6132006-03-27 12:41:01 +02001153{
1154 unsigned char regval;
1155 int i;
1156
1157 mutex_init(&miro->aci_mutex);
1158
1159 /* get ACI port from OPTi9xx MC 4 */
1160
1161 miro->mc_base = 0xf8c;
1162 regval=inb(miro->mc_base + 4);
1163 miro->aci_port = (regval & 0x10) ? 0x344: 0x354;
1164
1165 if ((miro->res_aci_port = request_region(miro->aci_port, 3, "miro aci")) == NULL) {
1166 snd_printk(KERN_ERR "aci i/o area 0x%lx-0x%lx already used.\n",
1167 miro->aci_port, miro->aci_port+2);
1168 return -ENOMEM;
1169 }
1170
1171 /* force ACI into a known state */
1172 for (i = 0; i < 3; i++)
1173 if (aci_cmd(miro, ACI_ERROR_OP, -1, -1) < 0) {
Martin Langer1841f6132006-03-27 12:41:01 +02001174 snd_printk(KERN_ERR "can't force aci into known state.\n");
1175 return -ENXIO;
1176 }
1177
1178 if ((miro->aci_vendor=aci_cmd(miro, ACI_READ_IDCODE, -1, -1)) < 0 ||
1179 (miro->aci_product=aci_cmd(miro, ACI_READ_IDCODE, -1, -1)) < 0) {
Martin Langer1841f6132006-03-27 12:41:01 +02001180 snd_printk(KERN_ERR "can't read aci id on 0x%lx.\n", miro->aci_port);
1181 return -ENXIO;
1182 }
1183
1184 if ((miro->aci_version=aci_cmd(miro, ACI_READ_VERSION, -1, -1)) < 0) {
Martin Langer1841f6132006-03-27 12:41:01 +02001185 snd_printk(KERN_ERR "can't read aci version on 0x%lx.\n",
1186 miro->aci_port);
1187 return -ENXIO;
1188 }
1189
1190 if (aci_cmd(miro, ACI_INIT, -1, -1) < 0 ||
1191 aci_cmd(miro, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0 ||
1192 aci_cmd(miro, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0) {
1193 snd_printk(KERN_ERR "can't initialize aci.\n");
1194 return -ENXIO;
1195 }
1196
1197 return 0;
1198}
1199
1200static void snd_card_miro_free(struct snd_card *card)
1201{
1202 struct snd_miro *miro = card->private_data;
1203
1204 release_and_free_resource(miro->res_aci_port);
1205 release_and_free_resource(miro->res_mc_base);
1206}
1207
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001208static int __devinit snd_miro_match(struct device *devptr, unsigned int n)
1209{
1210 return 1;
1211}
1212
1213static int __devinit snd_miro_probe(struct device *devptr, unsigned int n)
Martin Langer1841f6132006-03-27 12:41:01 +02001214{
1215 static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
1216 static long possible_mpu_ports[] = {0x330, 0x300, 0x310, 0x320, -1};
1217 static int possible_irqs[] = {11, 9, 10, 7, -1};
1218 static int possible_mpu_irqs[] = {10, 5, 9, 7, -1};
1219 static int possible_dma1s[] = {3, 1, 0, -1};
1220 static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};
1221
1222 int error;
1223 struct snd_miro *miro;
1224 struct snd_cs4231 *codec;
1225 struct snd_timer *timer;
1226 struct snd_card *card;
1227 struct snd_pcm *pcm;
1228 struct snd_rawmidi *rmidi;
1229
1230 if (!(card = snd_card_new(index, id, THIS_MODULE,
1231 sizeof(struct snd_miro))))
1232 return -ENOMEM;
1233
1234 card->private_free = snd_card_miro_free;
1235 miro = card->private_data;
1236 miro->card = card;
1237
1238 if ((error = snd_card_miro_aci_detect(card, miro)) < 0) {
1239 snd_card_free(card);
1240 snd_printk(KERN_ERR "unable to detect aci chip\n");
1241 return -ENODEV;
1242 }
1243
1244 /* init proc interface */
1245 snd_miro_proc_init(miro);
1246
1247 if ((error = snd_card_miro_detect(card, miro)) < 0) {
1248 snd_card_free(card);
1249 snd_printk(KERN_ERR "unable to detect OPTi9xx chip\n");
1250 return -ENODEV;
1251 }
1252
1253 if (! miro->res_mc_base &&
1254 (miro->res_mc_base = request_region(miro->mc_base, miro->mc_base_size,
1255 "miro (OPTi9xx MC)")) == NULL) {
1256 snd_card_free(card);
1257 snd_printk(KERN_ERR "request for OPTI9xx MC failed\n");
1258 return -ENOMEM;
1259 }
1260
1261 miro->wss_base = port;
1262 miro->fm_port = fm_port;
1263 miro->mpu_port = mpu_port;
1264 miro->irq = irq;
1265 miro->mpu_irq = mpu_irq;
1266 miro->dma1 = dma1;
1267 miro->dma2 = dma2;
1268
1269 if (miro->wss_base == SNDRV_AUTO_PORT) {
1270 if ((miro->wss_base = snd_legacy_find_free_ioport(possible_ports, 4)) < 0) {
1271 snd_card_free(card);
1272 snd_printk(KERN_ERR "unable to find a free WSS port\n");
1273 return -EBUSY;
1274 }
1275 }
1276
1277 if (miro->mpu_port == SNDRV_AUTO_PORT) {
1278 if ((miro->mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) {
1279 snd_card_free(card);
1280 snd_printk(KERN_ERR "unable to find a free MPU401 port\n");
1281 return -EBUSY;
1282 }
1283 }
1284 if (miro->irq == SNDRV_AUTO_IRQ) {
1285 if ((miro->irq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
1286 snd_card_free(card);
1287 snd_printk(KERN_ERR "unable to find a free IRQ\n");
1288 return -EBUSY;
1289 }
1290 }
1291 if (miro->mpu_irq == SNDRV_AUTO_IRQ) {
1292 if ((miro->mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) {
1293 snd_card_free(card);
1294 snd_printk(KERN_ERR "unable to find a free MPU401 IRQ\n");
1295 return -EBUSY;
1296 }
1297 }
1298 if (miro->dma1 == SNDRV_AUTO_DMA) {
1299 if ((miro->dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) {
1300 snd_card_free(card);
1301 snd_printk(KERN_ERR "unable to find a free DMA1\n");
1302 return -EBUSY;
1303 }
1304 }
1305 if (miro->dma2 == SNDRV_AUTO_DMA) {
1306 if ((miro->dma2 = snd_legacy_find_free_dma(possible_dma2s[miro->dma1 % 4])) < 0) {
1307 snd_card_free(card);
1308 snd_printk(KERN_ERR "unable to find a free DMA2\n");
1309 return -EBUSY;
1310 }
1311 }
1312
1313 if ((error = snd_miro_configure(miro))) {
1314 snd_card_free(card);
1315 return error;
1316 }
1317
1318 if ((error = snd_cs4231_create(card, miro->wss_base + 4, -1,
1319 miro->irq, miro->dma1, miro->dma2,
1320 CS4231_HW_AD1845,
1321 0,
1322 &codec)) < 0) {
1323 snd_card_free(card);
1324 return error;
1325 }
1326
1327 if ((error = snd_cs4231_pcm(codec, 0, &pcm)) < 0) {
1328 snd_card_free(card);
1329 return error;
1330 }
1331 if ((error = snd_cs4231_mixer(codec)) < 0) {
1332 snd_card_free(card);
1333 return error;
1334 }
1335 if ((error = snd_cs4231_timer(codec, 0, &timer)) < 0) {
1336 snd_card_free(card);
1337 return error;
1338 }
1339
1340 miro->pcm = pcm;
1341
1342 if ((error = snd_miro_mixer(miro)) < 0) {
1343 snd_card_free(card);
1344 return error;
1345 }
1346
1347 if (miro->aci_vendor == 'm') {
1348 /* It looks like a miro sound card. */
1349 switch (miro->aci_product) {
1350 case 'A':
1351 sprintf(card->shortname,
1352 "miroSOUND PCM1 pro / PCM12");
1353 break;
1354 case 'B':
1355 sprintf(card->shortname,
1356 "miroSOUND PCM12");
1357 break;
1358 case 'C':
1359 sprintf(card->shortname,
1360 "miroSOUND PCM20 radio");
1361 break;
1362 default:
1363 sprintf(card->shortname,
1364 "unknown miro");
1365 snd_printk(KERN_INFO "unknown miro aci id\n");
1366 break;
1367 }
1368 } else {
1369 snd_printk(KERN_INFO "found unsupported aci card\n");
1370 sprintf(card->shortname, "unknown Cardinal Technologies");
1371 }
1372
1373 strcpy(card->driver, "miro");
1374 sprintf(card->longname, "%s: OPTi%s, %s at 0x%lx, irq %d, dma %d&%d",
1375 card->shortname, miro->name, pcm->name, miro->wss_base + 4,
1376 miro->irq, miro->dma1, miro->dma2);
1377
1378 if (miro->mpu_port <= 0 || miro->mpu_port == SNDRV_AUTO_PORT)
1379 rmidi = NULL;
1380 else
1381 if ((error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
Thomas Gleixner65ca68b2006-07-01 19:29:46 -07001382 miro->mpu_port, 0, miro->mpu_irq, IRQF_DISABLED,
Martin Langer1841f6132006-03-27 12:41:01 +02001383 &rmidi)))
1384 snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n", miro->mpu_port);
1385
1386 if (miro->fm_port > 0 && miro->fm_port != SNDRV_AUTO_PORT) {
1387 struct snd_opl3 *opl3 = NULL;
1388 struct snd_opl4 *opl4;
1389 if (snd_opl4_create(card, miro->fm_port, miro->fm_port - 8,
1390 2, &opl3, &opl4) < 0)
1391 snd_printk(KERN_WARNING "no OPL4 device at 0x%lx\n", miro->fm_port);
1392 }
1393
1394 if ((error = snd_set_aci_init_values(miro)) < 0) {
1395 snd_card_free(card);
1396 return error;
1397 }
1398
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001399 snd_card_set_dev(card, devptr);
Martin Langer1841f6132006-03-27 12:41:01 +02001400
1401 if ((error = snd_card_register(card))) {
1402 snd_card_free(card);
1403 return error;
1404 }
1405
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001406 dev_set_drvdata(devptr, card);
Martin Langer1841f6132006-03-27 12:41:01 +02001407 return 0;
1408}
1409
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001410static int __devexit snd_miro_remove(struct device *devptr, unsigned int dev)
Martin Langer1841f6132006-03-27 12:41:01 +02001411{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001412 snd_card_free(dev_get_drvdata(devptr));
1413 dev_set_drvdata(devptr, NULL);
Martin Langer1841f6132006-03-27 12:41:01 +02001414 return 0;
1415}
1416
Rene Herman83c51c02007-03-20 11:33:46 +01001417#define DEV_NAME "miro"
1418
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001419static struct isa_driver snd_miro_driver = {
1420 .match = snd_miro_match,
Martin Langer1841f6132006-03-27 12:41:01 +02001421 .probe = snd_miro_probe,
1422 .remove = __devexit_p(snd_miro_remove),
1423 /* FIXME: suspend/resume */
1424 .driver = {
Rene Herman83c51c02007-03-20 11:33:46 +01001425 .name = DEV_NAME
Martin Langer1841f6132006-03-27 12:41:01 +02001426 },
1427};
1428
1429static int __init alsa_card_miro_init(void)
1430{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001431 return isa_register_driver(&snd_miro_driver, 1);
Martin Langer1841f6132006-03-27 12:41:01 +02001432}
1433
1434static void __exit alsa_card_miro_exit(void)
1435{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001436 isa_unregister_driver(&snd_miro_driver);
Martin Langer1841f6132006-03-27 12:41:01 +02001437}
1438
1439module_init(alsa_card_miro_init)
1440module_exit(alsa_card_miro_exit)