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