2 card-opti92x-ad1848.c - driver for OPTi 82c92x based soundcards.
3 Copyright (C) 1998-2000 by Massimo Piccioni <dafastidio@libero.it>
5 Part of this code was developed at the Italian Ministry of Air Defence,
6 Sixth Division (oh, che pace ...), Rome.
8 Thanks to Maria Grazia Pollarini, Salvatore Vassallo.
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.
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.
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
26 #include <sound/driver.h>
29 #include <linux/delay.h>
30 #include <linux/init.h>
31 #include <linux/slab.h>
32 #include <linux/pnp.h>
33 #include <sound/core.h>
35 #include <sound/cs4231.h>
38 #include <sound/ad1848.h>
40 #include <sound/control.h>
41 #include <sound/pcm.h>
44 #include <sound/mpu401.h>
45 #include <sound/opl3.h>
47 #include <sound/opl4.h>
49 #define SNDRV_LEGACY_FIND_FREE_IRQ
50 #define SNDRV_LEGACY_FIND_FREE_DMA
52 #include <sound/initval.h>
54 MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
55 MODULE_CLASSES("{sound}");
56 MODULE_LICENSE("GPL");
58 MODULE_DESCRIPTION("OPTi93X");
59 MODULE_DEVICES("{{OPTi,82C931/3}}");
62 MODULE_DESCRIPTION("OPTi92X - CS4231");
63 MODULE_DEVICES("{{OPTi,82C924 (CS4231)},"
64 "{OPTi,82C925 (CS4231)}}");
66 MODULE_DESCRIPTION("OPTi92X - AD1848");
67 MODULE_DEVICES("{{OPTi,82C924 (AD1848)},"
68 "{OPTi,82C925 (AD1848)},"
73 static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
74 static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
75 //static int enable = SNDRV_DEFAULT_ENABLE1; /* Enable this card */
76 static int isapnp = 1; /* Enable ISA PnP detection */
77 static long port = SNDRV_DEFAULT_PORT1; /* 0x530,0xe80,0xf40,0x604 */
78 static long mpu_port = SNDRV_DEFAULT_PORT1; /* 0x300,0x310,0x320,0x330 */
79 static long fm_port = SNDRV_DEFAULT_PORT1; /* 0x388 */
80 static int irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10,11 */
81 static int mpu_irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10 */
82 static int dma1 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */
83 #if defined(CS4231) || defined(OPTi93X)
84 static int dma2 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */
85 #endif /* CS4231 || OPTi93X */
87 MODULE_PARM(index, "i");
88 MODULE_PARM_DESC(index, "Index value for opti9xx based soundcard.");
89 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
91 MODULE_PARM_DESC(id, "ID string for opti9xx based soundcard.");
92 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
93 //MODULE_PARM(enable, "i");
94 //MODULE_PARM_DESC(enable, "Enable opti9xx soundcard.");
95 //MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
96 MODULE_PARM(isapnp, "i");
97 MODULE_PARM_DESC(isapnp, "Enable ISA PnP detection for specified soundcard.");
98 MODULE_PARM_SYNTAX(isapnp, SNDRV_ISAPNP_DESC);
99 MODULE_PARM(port, "l");
100 MODULE_PARM_DESC(port, "WSS port # for opti9xx driver.");
101 MODULE_PARM_SYNTAX(port, SNDRV_PORT_DESC);
102 MODULE_PARM(mpu_port, "l");
103 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for opti9xx driver.");
104 MODULE_PARM_SYNTAX(mpu_port, SNDRV_PORT_DESC);
105 MODULE_PARM(fm_port, "l");
106 MODULE_PARM_DESC(fm_port, "FM port # for opti9xx driver.");
107 MODULE_PARM_SYNTAX(fm_port, SNDRV_PORT_DESC);
108 MODULE_PARM(irq, "i");
109 MODULE_PARM_DESC(irq, "WSS irq # for opti9xx driver.");
110 MODULE_PARM_SYNTAX(irq, SNDRV_IRQ_DESC);
111 MODULE_PARM(mpu_irq, "i");
112 MODULE_PARM_DESC(mpu_irq, "MPU-401 irq # for opti9xx driver.");
113 MODULE_PARM_SYNTAX(mpu_irq, SNDRV_IRQ_DESC);
114 MODULE_PARM(dma1, "i");
115 MODULE_PARM_DESC(dma1, "1st dma # for opti9xx driver.");
116 MODULE_PARM_SYNTAX(dma1, SNDRV_DMA_DESC);
117 #if defined(CS4231) || defined(OPTi93X)
118 MODULE_PARM(dma2, "i");
119 MODULE_PARM_DESC(dma2, "2nd dma # for opti9xx driver.");
120 MODULE_PARM_SYNTAX(dma2, SNDRV_DMA_DESC);
121 #endif /* CS4231 || OPTi93X */
123 #define OPTi9XX_HW_DETECT 0
124 #define OPTi9XX_HW_82C928 1
125 #define OPTi9XX_HW_82C929 2
126 #define OPTi9XX_HW_82C924 3
127 #define OPTi9XX_HW_82C925 4
128 #define OPTi9XX_HW_82C930 5
129 #define OPTi9XX_HW_82C931 6
130 #define OPTi9XX_HW_82C933 7
131 #define OPTi9XX_HW_LAST OPTi9XX_HW_82C933
133 #define OPTi9XX_MC_REG(n) n
135 typedef struct _snd_opti9xx opti9xx_t;
139 #define OPTi93X_INDEX 0x00
140 #define OPTi93X_DATA 0x01
141 #define OPTi93X_STATUS 0x02
142 #define OPTi93X_DDATA 0x03
143 #define OPTi93X_PORT(chip, r) ((chip)->port + OPTi93X_##r)
145 #define OPTi93X_MIXOUT_LEFT 0x00
146 #define OPTi93X_MIXOUT_RIGHT 0x01
147 #define OPTi93X_CD_LEFT_INPUT 0x02
148 #define OPTi93X_CD_RIGHT_INPUT 0x03
149 #define OPTi930_AUX_LEFT_INPUT 0x04
150 #define OPTi930_AUX_RIGHT_INPUT 0x05
151 #define OPTi931_FM_LEFT_INPUT 0x04
152 #define OPTi931_FM_RIGHT_INPUT 0x05
153 #define OPTi93X_DAC_LEFT 0x06
154 #define OPTi93X_DAC_RIGHT 0x07
155 #define OPTi93X_PLAY_FORMAT 0x08
156 #define OPTi93X_IFACE_CONF 0x09
157 #define OPTi93X_PIN_CTRL 0x0a
158 #define OPTi93X_ERR_INIT 0x0b
159 #define OPTi93X_ID 0x0c
160 #define OPTi93X_PLAY_UPR_CNT 0x0e
161 #define OPTi93X_PLAY_LWR_CNT 0x0f
162 #define OPTi931_AUX_LEFT_INPUT 0x10
163 #define OPTi931_AUX_RIGHT_INPUT 0x11
164 #define OPTi93X_LINE_LEFT_INPUT 0x12
165 #define OPTi93X_LINE_RIGHT_INPUT 0x13
166 #define OPTi93X_MIC_LEFT_INPUT 0x14
167 #define OPTi93X_MIC_RIGHT_INPUT 0x15
168 #define OPTi93X_OUT_LEFT 0x16
169 #define OPTi93X_OUT_RIGHT 0x17
170 #define OPTi93X_CAPT_FORMAT 0x1c
171 #define OPTi93X_CAPT_UPR_CNT 0x1e
172 #define OPTi93X_CAPT_LWR_CNT 0x1f
174 #define OPTi93X_TRD 0x20
175 #define OPTi93X_MCE 0x40
176 #define OPTi93X_INIT 0x80
178 #define OPTi93X_MIXOUT_MIC_GAIN 0x20
179 #define OPTi93X_MIXOUT_LINE 0x00
180 #define OPTi93X_MIXOUT_CD 0x40
181 #define OPTi93X_MIXOUT_MIC 0x80
182 #define OPTi93X_MIXOUT_MIXER 0xc0
184 #define OPTi93X_STEREO 0x10
185 #define OPTi93X_LINEAR_8 0x00
186 #define OPTi93X_ULAW_8 0x20
187 #define OPTi93X_LINEAR_16_LIT 0x40
188 #define OPTi93X_ALAW_8 0x60
189 #define OPTi93X_ADPCM_16 0xa0
190 #define OPTi93X_LINEAR_16_BIG 0xc0
192 #define OPTi93X_CAPTURE_PIO 0x80
193 #define OPTi93X_PLAYBACK_PIO 0x40
194 #define OPTi93X_AUTOCALIB 0x08
195 #define OPTi93X_SINGLE_DMA 0x04
196 #define OPTi93X_CAPTURE_ENABLE 0x02
197 #define OPTi93X_PLAYBACK_ENABLE 0x01
199 #define OPTi93X_IRQ_ENABLE 0x02
201 #define OPTi93X_DMA_REQUEST 0x10
202 #define OPTi93X_CALIB_IN_PROGRESS 0x20
204 #define OPTi93X_IRQ_PLAYBACK 0x04
205 #define OPTi93X_IRQ_CAPTURE 0x08
208 typedef struct _snd_opti93x opti93x_t;
210 struct _snd_opti93x {
212 struct resource *res_port;
218 unsigned short hardware;
219 unsigned char image[32];
221 unsigned char mce_bit;
229 snd_pcm_substream_t *playback_substream;
230 snd_pcm_substream_t *capture_substream;
231 unsigned int p_dma_size;
232 unsigned int c_dma_size;
235 #define OPTi93X_MODE_NONE 0x00
236 #define OPTi93X_MODE_PLAY 0x01
237 #define OPTi93X_MODE_CAPTURE 0x02
238 #define OPTi93X_MODE_OPEN (OPTi93X_MODE_PLAY | OPTi93X_MODE_CAPTURE)
242 struct _snd_opti9xx {
243 unsigned short hardware;
244 unsigned char password;
247 unsigned long mc_base;
248 struct resource *res_mc_base;
249 unsigned long mc_base_size;
251 unsigned long mc_indir_index;
253 unsigned long pwd_reg;
260 #if defined(CS4231) || defined(OPTi93X)
262 #endif /* CS4231 || OPTi93X */
271 struct pnp_dev *devmpu;
272 #endif /* CONFIG_PNP */
275 static int snd_opti9xx_first_hit = 1;
276 static snd_card_t *snd_opti9xx_legacy = SNDRV_DEFAULT_PTR1;
280 static struct pnp_card_device_id snd_opti9xx_pnpids[] = {
283 { .id = "OPT0924", .devs = { { "OPT0000" }, { "OPT0002" } }, .driver_data = 0x0924 },
285 { .id = "OPT0925", .devs = { { "OPT9250" }, { "OPT0002" } }, .driver_data = 0x0925 },
288 { .id = "OPT0931", .devs = { { "OPT9310" }, { "OPT0002" } }, .driver_data = 0x0931 },
293 MODULE_DEVICE_TABLE(pnp_card, snd_opti9xx_pnpids);
295 #endif /* CONFIG_PNP */
298 #define DRIVER_NAME "snd-card-opti93x"
300 #define DRIVER_NAME "snd-card-opti92x"
303 static char * snd_opti9xx_names[] = {
307 "82C930", "82C931", "82C933"
311 static long snd_legacy_find_free_ioport(long *port_table, long size)
313 while (*port_table != -1) {
314 struct resource *res;
315 if ((res = request_region(*port_table, size, "ALSA test")) != NULL) {
316 release_resource(res);
325 static int __devinit snd_opti9xx_init(opti9xx_t *chip, unsigned short hardware)
327 static int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2};
329 chip->hardware = hardware;
330 strcpy(chip->name, snd_opti9xx_names[hardware]);
332 chip->mc_base_size = opti9xx_mc_size[hardware];
334 spin_lock_init(&chip->lock);
339 #if defined(CS4231) || defined (OPTi93X)
341 #endif /* CS4231 || OPTi93X */
348 case OPTi9XX_HW_82C928:
349 case OPTi9XX_HW_82C929:
350 chip->mc_base = 0xf8c;
351 chip->password = (hardware == OPTi9XX_HW_82C928) ? 0xe2 : 0xe3;
355 case OPTi9XX_HW_82C924:
356 case OPTi9XX_HW_82C925:
357 chip->mc_base = 0xf8c;
358 chip->password = 0xe5;
363 case OPTi9XX_HW_82C930:
364 case OPTi9XX_HW_82C931:
365 case OPTi9XX_HW_82C933:
366 chip->mc_base = (hardware == OPTi9XX_HW_82C930) ? 0xf8f : 0xf8d;
367 chip->mc_indir_index = 0xe0e;
368 chip->password = 0xe4;
374 snd_printk("chip %d not supported\n", hardware);
380 static unsigned char snd_opti9xx_read(opti9xx_t *chip,
384 unsigned char retval = 0xff;
386 spin_lock_irqsave(&chip->lock, flags);
387 outb(chip->password, chip->mc_base + chip->pwd_reg);
389 switch (chip->hardware) {
391 case OPTi9XX_HW_82C924:
392 case OPTi9XX_HW_82C925:
394 outb(reg, chip->mc_base + 8);
395 outb(chip->password, chip->mc_base + chip->pwd_reg);
396 retval = inb(chip->mc_base + 9);
400 case OPTi9XX_HW_82C928:
401 case OPTi9XX_HW_82C929:
402 retval = inb(chip->mc_base + reg);
406 case OPTi9XX_HW_82C930:
407 case OPTi9XX_HW_82C931:
408 case OPTi9XX_HW_82C933:
409 outb(reg, chip->mc_indir_index);
410 outb(chip->password, chip->mc_base + chip->pwd_reg);
411 retval = inb(chip->mc_indir_index + 1);
416 snd_printk("chip %d not supported\n", chip->hardware);
419 spin_unlock_irqrestore(&chip->lock, flags);
423 static void snd_opti9xx_write(opti9xx_t *chip, unsigned char reg,
428 spin_lock_irqsave(&chip->lock, flags);
429 outb(chip->password, chip->mc_base + chip->pwd_reg);
431 switch (chip->hardware) {
433 case OPTi9XX_HW_82C924:
434 case OPTi9XX_HW_82C925:
436 outb(reg, chip->mc_base + 8);
437 outb(chip->password, chip->mc_base + chip->pwd_reg);
438 outb(value, chip->mc_base + 9);
442 case OPTi9XX_HW_82C928:
443 case OPTi9XX_HW_82C929:
444 outb(value, chip->mc_base + reg);
448 case OPTi9XX_HW_82C930:
449 case OPTi9XX_HW_82C931:
450 case OPTi9XX_HW_82C933:
451 outb(reg, chip->mc_indir_index);
452 outb(chip->password, chip->mc_base + chip->pwd_reg);
453 outb(value, chip->mc_indir_index + 1);
458 snd_printk("chip %d not supported\n", chip->hardware);
461 spin_unlock_irqrestore(&chip->lock, flags);
465 #define snd_opti9xx_write_mask(chip, reg, value, mask) \
466 snd_opti9xx_write(chip, reg, \
467 (snd_opti9xx_read(chip, reg) & ~(mask)) | ((value) & (mask)))
470 static int __devinit snd_opti9xx_configure(opti9xx_t *chip)
472 unsigned char wss_base_bits;
473 unsigned char irq_bits;
474 unsigned char dma_bits;
475 unsigned char mpu_port_bits = 0;
476 unsigned char mpu_irq_bits;
479 switch (chip->hardware) {
481 case OPTi9XX_HW_82C924:
482 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0xf0, 0xfc);
483 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02);
485 case OPTi9XX_HW_82C925:
486 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
487 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20);
488 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff);
490 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
492 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
496 case OPTi9XX_HW_82C928:
497 case OPTi9XX_HW_82C929:
498 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
499 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20);
501 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xa2, 0xae);
503 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c);
505 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
507 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
512 case OPTi9XX_HW_82C930:
513 case OPTi9XX_HW_82C931:
514 case OPTi9XX_HW_82C933:
515 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x03);
516 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0x00, 0xff);
517 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x10 |
518 (chip->hardware == OPTi9XX_HW_82C930 ? 0x00 : 0x04),
520 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x20, 0xbf);
525 snd_printk("chip %d not supported\n", chip->hardware);
529 switch (chip->wss_base) {
531 wss_base_bits = 0x00;
534 wss_base_bits = 0x03;
537 wss_base_bits = 0x01;
540 wss_base_bits = 0x02;
543 snd_printk("WSS port 0x%lx not valid\n", chip->wss_base);
546 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30);
554 //#endif /* OPTi93X */
568 snd_printk("WSS irq # %d not valid\n", chip->irq);
569 goto __skip_resources;
572 switch (chip->dma1) {
583 snd_printk("WSS dma1 # %d not valid\n", chip->dma1);
584 goto __skip_resources;
587 #if defined(CS4231) || defined(OPTi93X)
588 if (chip->dma1 == chip->dma2) {
589 snd_printk("don't want to share dmas\n");
593 switch (chip->dma2) {
598 snd_printk("WSS dma2 # %d not valid\n", chip->dma2);
599 goto __skip_resources;
602 #endif /* CS4231 || OPTi93X */
604 spin_lock_irqsave(&chip->lock, flags);
605 snd_opti9xx_write(chip, OPTi9XX_MC_REG(3), (irq_bits << 3 | dma_bits));
606 spin_unlock_irqrestore(&chip->lock, flags);
609 if (chip->hardware > OPTi9XX_HW_82C928) {
610 switch (chip->mpu_port) {
615 mpu_port_bits = 0x03;
618 mpu_port_bits = 0x02;
621 mpu_port_bits = 0x01;
624 mpu_port_bits = 0x00;
627 snd_printk("MPU-401 port 0x%lx not valid\n",
632 switch (chip->mpu_irq) {
646 snd_printk("MPU-401 irq # %d not valid\n",
651 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6),
652 (chip->mpu_port <= 0) ? 0x00 :
653 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
663 #define chip_t opti93x_t
665 static unsigned char snd_opti93x_default_image[32] =
667 0x00, /* 00/00 - l_mixout_outctrl */
668 0x00, /* 01/01 - r_mixout_outctrl */
669 0x88, /* 02/02 - l_cd_inctrl */
670 0x88, /* 03/03 - r_cd_inctrl */
671 0x88, /* 04/04 - l_a1/fm_inctrl */
672 0x88, /* 05/05 - r_a1/fm_inctrl */
673 0x80, /* 06/06 - l_dac_inctrl */
674 0x80, /* 07/07 - r_dac_inctrl */
675 0x00, /* 08/08 - ply_dataform_reg */
676 0x00, /* 09/09 - if_conf */
677 0x00, /* 0a/10 - pin_ctrl */
678 0x00, /* 0b/11 - err_init_reg */
679 0x0a, /* 0c/12 - id_reg */
680 0x00, /* 0d/13 - reserved */
681 0x00, /* 0e/14 - ply_upcount_reg */
682 0x00, /* 0f/15 - ply_lowcount_reg */
683 0x88, /* 10/16 - reserved/l_a1_inctrl */
684 0x88, /* 11/17 - reserved/r_a1_inctrl */
685 0x88, /* 12/18 - l_line_inctrl */
686 0x88, /* 13/19 - r_line_inctrl */
687 0x88, /* 14/20 - l_mic_inctrl */
688 0x88, /* 15/21 - r_mic_inctrl */
689 0x80, /* 16/22 - l_out_outctrl */
690 0x80, /* 17/23 - r_out_outctrl */
691 0x00, /* 18/24 - reserved */
692 0x00, /* 19/25 - reserved */
693 0x00, /* 1a/26 - reserved */
694 0x00, /* 1b/27 - reserved */
695 0x00, /* 1c/28 - cap_dataform_reg */
696 0x00, /* 1d/29 - reserved */
697 0x00, /* 1e/30 - cap_upcount_reg */
698 0x00 /* 1f/31 - cap_lowcount_reg */
702 static int snd_opti93x_busy_wait(opti93x_t *chip)
706 for (timeout = 250; timeout-- > 0; udelay(10))
707 if (!(inb(OPTi93X_PORT(chip, INDEX)) & OPTi93X_INIT))
710 snd_printk("chip still busy.\n");
714 static unsigned char snd_opti93x_in(opti93x_t *chip, unsigned char reg)
716 snd_opti93x_busy_wait(chip);
717 outb(chip->mce_bit | (reg & 0x1f), OPTi93X_PORT(chip, INDEX));
718 return inb(OPTi93X_PORT(chip, DATA));
721 static void snd_opti93x_out(opti93x_t *chip, unsigned char reg,
724 snd_opti93x_busy_wait(chip);
725 outb(chip->mce_bit | (reg & 0x1f), OPTi93X_PORT(chip, INDEX));
726 outb(value, OPTi93X_PORT(chip, DATA));
729 static void snd_opti93x_out_image(opti93x_t *chip, unsigned char reg,
732 snd_opti93x_out(chip, reg, chip->image[reg] = value);
735 static void snd_opti93x_out_mask(opti93x_t *chip, unsigned char reg,
736 unsigned char mask, unsigned char value)
738 snd_opti93x_out_image(chip, reg,
739 (chip->image[reg] & ~mask) | (value & mask));
743 static void snd_opti93x_mce_up(opti93x_t *chip)
745 snd_opti93x_busy_wait(chip);
747 chip->mce_bit = OPTi93X_MCE;
748 if (!(inb(OPTi93X_PORT(chip, INDEX)) & OPTi93X_MCE))
749 outb(chip->mce_bit, OPTi93X_PORT(chip, INDEX));
752 static void snd_opti93x_mce_down(opti93x_t *chip)
754 snd_opti93x_busy_wait(chip);
757 if (inb(OPTi93X_PORT(chip, INDEX)) & OPTi93X_MCE)
758 outb(chip->mce_bit, OPTi93X_PORT(chip, INDEX));
761 #define snd_opti93x_mute_reg(chip, reg, mute) \
762 snd_opti93x_out(chip, reg, mute ? 0x80 : chip->image[reg]);
764 static void snd_opti93x_mute(opti93x_t *chip, int mute)
768 spin_lock_irqsave(&chip->lock, flags);
771 if (chip->mute == mute) {
772 spin_unlock_irqrestore(&chip->lock, flags);
777 snd_opti93x_mute_reg(chip, OPTi93X_CD_LEFT_INPUT, mute);
778 snd_opti93x_mute_reg(chip, OPTi93X_CD_RIGHT_INPUT, mute);
779 switch (chip->hardware) {
780 case OPTi9XX_HW_82C930:
781 snd_opti93x_mute_reg(chip, OPTi930_AUX_LEFT_INPUT, mute);
782 snd_opti93x_mute_reg(chip, OPTi930_AUX_RIGHT_INPUT, mute);
784 case OPTi9XX_HW_82C931:
785 case OPTi9XX_HW_82C933:
786 snd_opti93x_mute_reg(chip, OPTi931_FM_LEFT_INPUT, mute);
787 snd_opti93x_mute_reg(chip, OPTi931_FM_RIGHT_INPUT, mute);
788 snd_opti93x_mute_reg(chip, OPTi931_AUX_LEFT_INPUT, mute);
789 snd_opti93x_mute_reg(chip, OPTi931_AUX_RIGHT_INPUT, mute);
791 snd_opti93x_mute_reg(chip, OPTi93X_DAC_LEFT, mute);
792 snd_opti93x_mute_reg(chip, OPTi93X_DAC_RIGHT, mute);
793 snd_opti93x_mute_reg(chip, OPTi93X_LINE_LEFT_INPUT, mute);
794 snd_opti93x_mute_reg(chip, OPTi93X_LINE_RIGHT_INPUT, mute);
795 snd_opti93x_mute_reg(chip, OPTi93X_MIC_LEFT_INPUT, mute);
796 snd_opti93x_mute_reg(chip, OPTi93X_MIC_RIGHT_INPUT, mute);
797 snd_opti93x_mute_reg(chip, OPTi93X_OUT_LEFT, mute);
798 snd_opti93x_mute_reg(chip, OPTi93X_OUT_RIGHT, mute);
800 spin_unlock_irqrestore(&chip->lock, flags);
804 static unsigned int snd_opti93x_get_count(unsigned char format,
807 switch (format & 0xe0) {
808 case OPTi93X_LINEAR_16_LIT:
809 case OPTi93X_LINEAR_16_BIG:
812 case OPTi93X_ADPCM_16:
815 return (format & OPTi93X_STEREO) ? (size >> 1) : size;
818 static unsigned int rates[] = { 5512, 6615, 8000, 9600, 11025, 16000,
819 18900, 22050, 27428, 32000, 33075, 37800,
821 #define RATES sizeof(rates) / sizeof(rates[0])
823 static snd_pcm_hw_constraint_list_t hw_constraints_rates = {
829 static unsigned char bits[] = { 0x01, 0x0f, 0x00, 0x0e, 0x03, 0x02,
830 0x05, 0x07, 0x04, 0x06, 0x0d, 0x09,
833 static unsigned char snd_opti93x_get_freq(unsigned int rate)
837 for (i = 0; i < RATES; i++) {
838 if (rate == rates[i])
842 return bits[RATES-1];
845 static unsigned char snd_opti93x_get_format(opti93x_t *chip,
846 unsigned int format, int channels)
848 unsigned char retval = OPTi93X_LINEAR_8;
851 case SNDRV_PCM_FORMAT_MU_LAW:
852 retval = OPTi93X_ULAW_8;
854 case SNDRV_PCM_FORMAT_A_LAW:
855 retval = OPTi93X_ALAW_8;
857 case SNDRV_PCM_FORMAT_S16_LE:
858 retval = OPTi93X_LINEAR_16_LIT;
860 case SNDRV_PCM_FORMAT_S16_BE:
861 retval = OPTi93X_LINEAR_16_BIG;
863 case SNDRV_PCM_FORMAT_IMA_ADPCM:
864 retval = OPTi93X_ADPCM_16;
866 return (channels > 1) ? (retval | OPTi93X_STEREO) : retval;
870 static void snd_opti93x_playback_format(opti93x_t *chip, unsigned char fmt)
875 spin_lock_irqsave(&chip->lock, flags);
876 snd_opti93x_mute(chip, 1);
878 snd_opti93x_mce_up(chip);
879 mask = (chip->mode & OPTi93X_MODE_CAPTURE) ? 0xf0 : 0xff;
880 snd_opti93x_out_mask(chip, OPTi93X_PLAY_FORMAT, mask, fmt);
881 snd_opti93x_mce_down(chip);
883 snd_opti93x_mute(chip, 0);
884 spin_unlock_irqrestore(&chip->lock, flags);
887 static void snd_opti93x_capture_format(opti93x_t *chip, unsigned char fmt)
891 spin_lock_irqsave(&chip->lock, flags);
892 snd_opti93x_mute(chip, 1);
894 snd_opti93x_mce_up(chip);
895 if (!(chip->mode & OPTi93X_MODE_PLAY))
896 snd_opti93x_out_mask(chip, OPTi93X_PLAY_FORMAT, 0x0f, fmt);
898 fmt = chip->image[OPTi93X_PLAY_FORMAT] & 0xf0;
899 snd_opti93x_out_image(chip, OPTi93X_CAPT_FORMAT, fmt);
900 snd_opti93x_mce_down(chip);
902 snd_opti93x_mute(chip, 0);
903 spin_unlock_irqrestore(&chip->lock, flags);
907 static int snd_opti93x_open(opti93x_t *chip, unsigned int mode)
911 spin_lock_irqsave(&chip->lock, flags);
913 if (chip->mode & mode) {
914 spin_unlock_irqrestore(&chip->lock, flags);
918 if (!(chip->mode & OPTi93X_MODE_OPEN)) {
919 outb(0x00, OPTi93X_PORT(chip, STATUS));
920 snd_opti93x_out_mask(chip, OPTi93X_PIN_CTRL,
921 OPTi93X_IRQ_ENABLE, OPTi93X_IRQ_ENABLE);
927 spin_unlock_irqrestore(&chip->lock, flags);
931 static void snd_opti93x_close(opti93x_t *chip, unsigned int mode)
935 spin_lock_irqsave(&chip->lock, flags);
938 if (chip->mode & OPTi93X_MODE_OPEN) {
939 spin_unlock_irqrestore(&chip->lock, flags);
943 snd_opti93x_mute(chip, 1);
945 outb(0, OPTi93X_PORT(chip, STATUS));
946 snd_opti93x_out_mask(chip, OPTi93X_PIN_CTRL, OPTi93X_IRQ_ENABLE,
947 ~OPTi93X_IRQ_ENABLE);
949 snd_opti93x_mce_up(chip);
950 snd_opti93x_out_image(chip, OPTi93X_IFACE_CONF, 0x00);
951 snd_opti93x_mce_down(chip);
954 snd_opti93x_mute(chip, 0);
955 spin_unlock_irqrestore(&chip->lock, flags);
958 static int snd_opti93x_trigger(snd_pcm_substream_t *substream,
959 unsigned char what, int cmd)
961 opti93x_t *chip = snd_pcm_substream_chip(substream);
964 case SNDRV_PCM_TRIGGER_START:
965 case SNDRV_PCM_TRIGGER_STOP:
967 unsigned int what = 0;
968 struct list_head *pos;
969 snd_pcm_substream_t *s;
970 snd_pcm_group_for_each(pos, substream) {
971 s = snd_pcm_group_substream_entry(pos);
972 if (s == chip->playback_substream) {
973 what |= OPTi93X_PLAYBACK_ENABLE;
974 snd_pcm_trigger_done(s, substream);
975 } else if (s == chip->capture_substream) {
976 what |= OPTi93X_CAPTURE_ENABLE;
977 snd_pcm_trigger_done(s, substream);
980 spin_lock(&chip->lock);
981 if (cmd == SNDRV_PCM_TRIGGER_START) {
982 snd_opti93x_out_mask(chip, OPTi93X_IFACE_CONF, what, what);
983 if (what & OPTi93X_CAPTURE_ENABLE)
986 snd_opti93x_out_mask(chip, OPTi93X_IFACE_CONF, what, 0x00);
987 spin_unlock(&chip->lock);
996 static int snd_opti93x_playback_trigger(snd_pcm_substream_t *substream, int cmd)
998 return snd_opti93x_trigger(substream,
999 OPTi93X_PLAYBACK_ENABLE, cmd);
1002 static int snd_opti93x_capture_trigger(snd_pcm_substream_t * substream, int cmd)
1004 return snd_opti93x_trigger(substream,
1005 OPTi93X_CAPTURE_ENABLE, cmd);
1008 static int snd_opti93x_hw_params(snd_pcm_substream_t * substream,
1009 snd_pcm_hw_params_t * hw_params)
1011 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1015 static int snd_opti93x_hw_free(snd_pcm_substream_t * substream)
1017 snd_pcm_lib_free_pages(substream);
1022 static int snd_opti93x_playback_prepare(snd_pcm_substream_t * substream)
1024 opti93x_t *chip = snd_pcm_substream_chip(substream);
1025 snd_pcm_runtime_t *runtime = substream->runtime;
1026 unsigned long flags;
1027 unsigned char format;
1028 unsigned int count = snd_pcm_lib_period_bytes(substream);
1029 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
1031 spin_lock_irqsave(&chip->lock, flags);
1033 chip->p_dma_size = size;
1034 snd_opti93x_out_mask(chip, OPTi93X_IFACE_CONF,
1035 OPTi93X_PLAYBACK_ENABLE | OPTi93X_PLAYBACK_PIO,
1036 ~(OPTi93X_PLAYBACK_ENABLE | OPTi93X_PLAYBACK_PIO));
1038 snd_dma_program(chip->dma1, runtime->dma_addr, size,
1039 DMA_MODE_WRITE | DMA_AUTOINIT);
1041 format = snd_opti93x_get_freq(runtime->rate);
1042 format |= snd_opti93x_get_format(chip, runtime->format,
1044 snd_opti93x_playback_format(chip, format);
1045 format = chip->image[OPTi93X_PLAY_FORMAT];
1047 count = snd_opti93x_get_count(format, count) - 1;
1048 snd_opti93x_out_image(chip, OPTi93X_PLAY_LWR_CNT, count);
1049 snd_opti93x_out_image(chip, OPTi93X_PLAY_UPR_CNT, count >> 8);
1051 spin_unlock_irqrestore(&chip->lock, flags);
1055 static int snd_opti93x_capture_prepare(snd_pcm_substream_t *substream)
1057 opti93x_t *chip = snd_pcm_substream_chip(substream);
1058 snd_pcm_runtime_t *runtime = substream->runtime;
1059 unsigned long flags;
1060 unsigned char format;
1061 unsigned int count = snd_pcm_lib_period_bytes(substream);
1062 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
1064 spin_lock_irqsave(&chip->lock, flags);
1066 chip->c_dma_size = size;
1067 snd_opti93x_out_mask(chip, OPTi93X_IFACE_CONF,
1068 OPTi93X_CAPTURE_ENABLE | OPTi93X_CAPTURE_PIO,
1069 (unsigned char)~(OPTi93X_CAPTURE_ENABLE | OPTi93X_CAPTURE_PIO));
1071 snd_dma_program(chip->dma2, runtime->dma_addr, size,
1072 DMA_MODE_READ | DMA_AUTOINIT);
1074 format = snd_opti93x_get_freq(runtime->rate);
1075 format |= snd_opti93x_get_format(chip, runtime->format,
1077 snd_opti93x_capture_format(chip, format);
1078 format = chip->image[OPTi93X_CAPT_FORMAT];
1080 count = snd_opti93x_get_count(format, count) - 1;
1081 snd_opti93x_out_image(chip, OPTi93X_CAPT_LWR_CNT, count);
1082 snd_opti93x_out_image(chip, OPTi93X_CAPT_UPR_CNT, count >> 8);
1084 spin_unlock_irqrestore(&chip->lock, flags);
1088 static snd_pcm_uframes_t snd_opti93x_playback_pointer(snd_pcm_substream_t *substream)
1090 opti93x_t *chip = snd_pcm_substream_chip(substream);
1093 if (!(chip->image[OPTi93X_IFACE_CONF] & OPTi93X_PLAYBACK_ENABLE))
1096 ptr = snd_dma_pointer(chip->dma1, chip->p_dma_size);
1097 return bytes_to_frames(substream->runtime, ptr);
1100 static snd_pcm_uframes_t snd_opti93x_capture_pointer(snd_pcm_substream_t *substream)
1102 opti93x_t *chip = snd_pcm_substream_chip(substream);
1105 if (!(chip->image[OPTi93X_IFACE_CONF] & OPTi93X_CAPTURE_ENABLE))
1108 ptr = snd_dma_pointer(chip->dma2, chip->c_dma_size);
1109 return bytes_to_frames(substream->runtime, ptr);
1113 static void snd_opti93x_overrange(opti93x_t *chip)
1115 unsigned long flags;
1117 spin_lock_irqsave(&chip->lock, flags);
1119 if (snd_opti93x_in(chip, OPTi93X_ERR_INIT) & (0x08 | 0x02))
1120 chip->capture_substream->runtime->overrange++;
1122 spin_unlock_irqrestore(&chip->lock, flags);
1125 irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1127 opti93x_t *codec = snd_magic_cast(opti93x_t, dev_id, return IRQ_NONE);
1128 unsigned char status;
1130 status = snd_opti9xx_read(codec->chip, OPTi9XX_MC_REG(11));
1131 if ((status & OPTi93X_IRQ_PLAYBACK) && codec->playback_substream)
1132 snd_pcm_period_elapsed(codec->playback_substream);
1133 if ((status & OPTi93X_IRQ_CAPTURE) && codec->capture_substream) {
1134 snd_opti93x_overrange(codec);
1135 snd_pcm_period_elapsed(codec->capture_substream);
1137 outb(0x00, OPTi93X_PORT(codec, STATUS));
1142 static snd_pcm_hardware_t snd_opti93x_playback = {
1143 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1144 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START),
1145 .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM |
1146 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE),
1147 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
1152 .buffer_bytes_max = (128*1024),
1153 .period_bytes_min = 64,
1154 .period_bytes_max = (128*1024),
1156 .periods_max = 1024,
1160 static snd_pcm_hardware_t snd_opti93x_capture = {
1161 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1162 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START),
1163 .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM |
1164 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE),
1165 .rates = SNDRV_PCM_RATE_8000_48000,
1170 .buffer_bytes_max = (128*1024),
1171 .period_bytes_min = 64,
1172 .period_bytes_max = (128*1024),
1174 .periods_max = 1024,
1178 static int snd_opti93x_playback_open(snd_pcm_substream_t *substream)
1181 opti93x_t *chip = snd_pcm_substream_chip(substream);
1182 snd_pcm_runtime_t *runtime = substream->runtime;
1184 if ((error = snd_opti93x_open(chip, OPTi93X_MODE_PLAY)) < 0)
1186 snd_pcm_set_sync(substream);
1187 chip->playback_substream = substream;
1188 runtime->hw = snd_opti93x_playback;
1189 snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.buffer_bytes_max);
1190 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1194 static int snd_opti93x_capture_open(snd_pcm_substream_t *substream)
1197 opti93x_t *chip = snd_pcm_substream_chip(substream);
1198 snd_pcm_runtime_t *runtime = substream->runtime;
1200 if ((error = snd_opti93x_open(chip, OPTi93X_MODE_CAPTURE)) < 0)
1202 runtime->hw = snd_opti93x_capture;
1203 snd_pcm_set_sync(substream);
1204 chip->capture_substream = substream;
1205 snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.buffer_bytes_max);
1206 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1210 static int snd_opti93x_playback_close(snd_pcm_substream_t *substream)
1212 opti93x_t *chip = snd_pcm_substream_chip(substream);
1214 chip->playback_substream = NULL;
1215 snd_opti93x_close(chip, OPTi93X_MODE_PLAY);
1219 static int snd_opti93x_capture_close(snd_pcm_substream_t *substream)
1221 opti93x_t *chip = snd_pcm_substream_chip(substream);
1223 chip->capture_substream = NULL;
1224 snd_opti93x_close(chip, OPTi93X_MODE_CAPTURE);
1229 static void snd_opti93x_init(opti93x_t *chip)
1231 unsigned long flags;
1234 spin_lock_irqsave(&chip->lock, flags);
1235 snd_opti93x_mce_up(chip);
1237 for (i = 0; i < 32; i++)
1238 snd_opti93x_out_image(chip, i, snd_opti93x_default_image[i]);
1240 snd_opti93x_mce_down(chip);
1241 spin_unlock_irqrestore(&chip->lock, flags);
1244 static int snd_opti93x_probe(opti93x_t *chip)
1246 unsigned long flags;
1249 spin_lock_irqsave(&chip->lock, flags);
1250 val = snd_opti93x_in(chip, OPTi93X_ID) & 0x0f;
1251 spin_unlock_irqrestore(&chip->lock, flags);
1253 return (val == 0x0a) ? 0 : -ENODEV;
1256 static int snd_opti93x_free(opti93x_t *chip)
1258 if (chip->res_port) {
1259 release_resource(chip->res_port);
1260 kfree_nocheck(chip->res_port);
1262 if (chip->dma1 >= 0) {
1263 disable_dma(chip->dma1);
1264 free_dma(chip->dma1);
1266 if (chip->dma2 >= 0) {
1267 disable_dma(chip->dma2);
1268 free_dma(chip->dma2);
1270 if (chip->irq >= 0) {
1271 free_irq(chip->irq, chip);
1273 snd_magic_kfree(chip);
1277 static int snd_opti93x_dev_free(snd_device_t *device)
1279 opti93x_t *chip = snd_magic_cast(opti93x_t, device->device_data, return -ENXIO);
1280 return snd_opti93x_free(chip);
1283 static const char *snd_opti93x_chip_id(opti93x_t *codec)
1285 switch (codec->hardware) {
1286 case OPTi9XX_HW_82C930: return "82C930";
1287 case OPTi9XX_HW_82C931: return "82C931";
1288 case OPTi9XX_HW_82C933: return "82C933";
1289 default: return "???";
1293 int snd_opti93x_create(snd_card_t *card, opti9xx_t *chip,
1297 static snd_device_ops_t ops = {
1298 .dev_free = snd_opti93x_dev_free,
1304 codec = snd_magic_kcalloc(opti93x_t, 0, GFP_KERNEL);
1311 if ((codec->res_port = request_region(chip->wss_base + 4, 4, "OPTI93x CODEC")) == NULL) {
1312 snd_printk(KERN_ERR "opti9xx: can't grab port 0x%lx\n", chip->wss_base + 4);
1313 snd_opti93x_free(codec);
1316 if (request_dma(dma1, "OPTI93x - 1")) {
1317 snd_printk(KERN_ERR "opti9xx: can't grab DMA1 %d\n", dma1);
1318 snd_opti93x_free(codec);
1321 codec->dma1 = chip->dma1;
1322 if (request_dma(dma2, "OPTI93x - 2")) {
1323 snd_printk(KERN_ERR "opti9xx: can't grab DMA2 %d\n", dma2);
1324 snd_opti93x_free(codec);
1327 codec->dma2 = chip->dma2;
1329 if (request_irq(chip->irq, snd_opti93x_interrupt, SA_INTERRUPT, DRIVER_NAME" - WSS", codec)) {
1330 snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", chip->irq);
1331 snd_opti93x_free(codec);
1336 codec->port = chip->wss_base + 4;
1337 codec->irq = chip->irq;
1339 spin_lock_init(&codec->lock);
1340 codec->hardware = chip->hardware;
1343 if ((error = snd_opti93x_probe(codec))) {
1344 snd_opti93x_free(codec);
1348 snd_opti93x_init(codec);
1350 /* Register device */
1351 if ((error = snd_device_new(card, SNDRV_DEV_LOWLEVEL, codec, &ops)) < 0) {
1352 snd_opti93x_free(codec);
1360 static snd_pcm_ops_t snd_opti93x_playback_ops = {
1361 .open = snd_opti93x_playback_open,
1362 .close = snd_opti93x_playback_close,
1363 .ioctl = snd_pcm_lib_ioctl,
1364 .hw_params = snd_opti93x_hw_params,
1365 .hw_free = snd_opti93x_hw_free,
1366 .prepare = snd_opti93x_playback_prepare,
1367 .trigger = snd_opti93x_playback_trigger,
1368 .pointer = snd_opti93x_playback_pointer,
1371 static snd_pcm_ops_t snd_opti93x_capture_ops = {
1372 .open = snd_opti93x_capture_open,
1373 .close = snd_opti93x_capture_close,
1374 .ioctl = snd_pcm_lib_ioctl,
1375 .hw_params = snd_opti93x_hw_params,
1376 .hw_free = snd_opti93x_hw_free,
1377 .prepare = snd_opti93x_capture_prepare,
1378 .trigger = snd_opti93x_capture_trigger,
1379 .pointer = snd_opti93x_capture_pointer,
1382 static void snd_opti93x_pcm_free(snd_pcm_t *pcm)
1384 opti93x_t *codec = snd_magic_cast(opti93x_t, pcm->private_data, return);
1386 snd_pcm_lib_preallocate_free_for_all(pcm);
1389 int snd_opti93x_pcm(opti93x_t *codec, int device, snd_pcm_t **rpcm)
1394 if ((error = snd_pcm_new(codec->card, "OPTi 82C93X", device, 1, 1, &pcm)))
1397 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_opti93x_playback_ops);
1398 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_opti93x_capture_ops);
1400 pcm->private_data = codec;
1401 pcm->private_free = snd_opti93x_pcm_free;
1402 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
1404 strcpy(pcm->name, snd_opti93x_chip_id(codec));
1406 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1408 64*1024, codec->dma1 > 3 || codec->dma2 > 3 ? 128*1024 : 64*1024);
1420 static int snd_opti93x_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1422 static char *texts[4] = {
1423 "Line1", "Aux", "Mic", "Mix"
1426 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1428 uinfo->value.enumerated.items = 4;
1429 if (uinfo->value.enumerated.item > 3)
1430 uinfo->value.enumerated.item = 3;
1431 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1435 static int snd_opti93x_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1437 opti93x_t *chip = snd_kcontrol_chip(kcontrol);
1438 unsigned long flags;
1440 spin_lock_irqsave(&chip->lock, flags);
1441 ucontrol->value.enumerated.item[0] = (chip->image[OPTi93X_MIXOUT_LEFT] & OPTi93X_MIXOUT_MIXER) >> 6;
1442 ucontrol->value.enumerated.item[1] = (chip->image[OPTi93X_MIXOUT_RIGHT] & OPTi93X_MIXOUT_MIXER) >> 6;
1443 spin_unlock_irqrestore(&chip->lock, flags);
1447 static int snd_opti93x_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1449 opti93x_t *chip = snd_kcontrol_chip(kcontrol);
1450 unsigned long flags;
1451 unsigned short left, right;
1454 if (ucontrol->value.enumerated.item[0] > 3 ||
1455 ucontrol->value.enumerated.item[1] > 3)
1457 left = ucontrol->value.enumerated.item[0] << 6;
1458 right = ucontrol->value.enumerated.item[1] << 6;
1459 spin_lock_irqsave(&chip->lock, flags);
1460 left = (chip->image[OPTi93X_MIXOUT_LEFT] & ~OPTi93X_MIXOUT_MIXER) | left;
1461 right = (chip->image[OPTi93X_MIXOUT_RIGHT] & ~OPTi93X_MIXOUT_MIXER) | right;
1462 change = left != chip->image[OPTi93X_MIXOUT_LEFT] ||
1463 right != chip->image[OPTi93X_MIXOUT_RIGHT];
1464 snd_opti93x_out_image(chip, OPTi93X_MIXOUT_LEFT, left);
1465 snd_opti93x_out_image(chip, OPTi93X_MIXOUT_RIGHT, right);
1466 spin_unlock_irqrestore(&chip->lock, flags);
1472 #define OPTi93X_SINGLE(xname, xindex, reg, shift, mask, invert) \
1473 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1474 .info = snd_opti93x_info_single, \
1475 .get = snd_opti93x_get_single, .put = snd_opti93x_put_single, \
1476 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
1478 static int snd_opti93x_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1480 int mask = (kcontrol->private_value >> 16) & 0xff;
1482 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1484 uinfo->value.integer.min = 0;
1485 uinfo->value.integer.max = mask;
1489 static int snd_opti93x_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1491 opti93x_t *chip = snd_kcontrol_chip(kcontrol);
1492 unsigned long flags;
1493 int reg = kcontrol->private_value & 0xff;
1494 int shift = (kcontrol->private_value >> 8) & 0xff;
1495 int mask = (kcontrol->private_value >> 16) & 0xff;
1496 int invert = (kcontrol->private_value >> 24) & 0xff;
1498 spin_lock_irqsave(&chip->lock, flags);
1499 ucontrol->value.integer.value[0] = (chip->image[reg] >> shift) & mask;
1500 spin_unlock_irqrestore(&chip->lock, flags);
1502 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1506 static int snd_opti93x_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1508 opti93x_t *chip = snd_kcontrol_chip(kcontrol);
1509 unsigned long flags;
1510 int reg = kcontrol->private_value & 0xff;
1511 int shift = (kcontrol->private_value >> 8) & 0xff;
1512 int mask = (kcontrol->private_value >> 16) & 0xff;
1513 int invert = (kcontrol->private_value >> 24) & 0xff;
1517 val = (ucontrol->value.integer.value[0] & mask);
1521 spin_lock_irqsave(&chip->lock, flags);
1522 val = (chip->image[reg] & ~(mask << shift)) | val;
1523 change = val != chip->image[reg];
1524 snd_opti93x_out(chip, reg, val);
1525 spin_unlock_irqrestore(&chip->lock, flags);
1531 #define OPTi93X_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
1532 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1533 .info = snd_opti93x_info_double, \
1534 .get = snd_opti93x_get_double, .put = snd_opti93x_put_double, \
1535 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
1537 #define OPTi93X_DOUBLE_INVERT_INVERT(xctl) \
1538 do { xctl.private_value ^= 22; } while (0)
1539 #define OPTi93X_DOUBLE_CHANGE_REGS(xctl, left_reg, right_reg) \
1540 do { xctl.private_value &= ~0x0000ffff; \
1541 xctl.private_value |= left_reg | (right_reg << 8); } while (0)
1543 static int snd_opti93x_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1545 int mask = (kcontrol->private_value >> 24) & 0xff;
1547 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1549 uinfo->value.integer.min = 0;
1550 uinfo->value.integer.max = mask;
1554 static int snd_opti93x_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1556 opti93x_t *chip = snd_kcontrol_chip(kcontrol);
1557 unsigned long flags;
1558 int left_reg = kcontrol->private_value & 0xff;
1559 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1560 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1561 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1562 int mask = (kcontrol->private_value >> 24) & 0xff;
1563 int invert = (kcontrol->private_value >> 22) & 1;
1565 spin_lock_irqsave(&chip->lock, flags);
1566 ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask;
1567 ucontrol->value.integer.value[1] = (chip->image[right_reg] >> shift_right) & mask;
1568 spin_unlock_irqrestore(&chip->lock, flags);
1570 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1571 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
1576 static int snd_opti93x_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1578 opti93x_t *chip = snd_kcontrol_chip(kcontrol);
1579 unsigned long flags;
1580 int left_reg = kcontrol->private_value & 0xff;
1581 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1582 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1583 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1584 int mask = (kcontrol->private_value >> 24) & 0xff;
1585 int invert = (kcontrol->private_value >> 22) & 1;
1587 unsigned short val1, val2;
1589 val1 = ucontrol->value.integer.value[0] & mask;
1590 val2 = ucontrol->value.integer.value[1] & mask;
1595 val1 <<= shift_left;
1596 val2 <<= shift_right;
1597 spin_lock_irqsave(&chip->lock, flags);
1598 val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1;
1599 val2 = (chip->image[right_reg] & ~(mask << shift_right)) | val2;
1600 change = val1 != chip->image[left_reg] || val2 != chip->image[right_reg];
1601 snd_opti93x_out_image(chip, left_reg, val1);
1602 snd_opti93x_out_image(chip, right_reg, val2);
1603 spin_unlock_irqrestore(&chip->lock, flags);
1607 #define OPTi93X_CONTROLS (sizeof(snd_opti93x_controls)/sizeof(snd_kcontrol_new_t))
1609 static snd_kcontrol_new_t snd_opti93x_controls[] = {
1610 OPTi93X_DOUBLE("Master Playback Switch", 0, OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1),
1611 OPTi93X_DOUBLE("Master Playback Volume", 0, OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1),
1612 OPTi93X_DOUBLE("PCM Playback Switch", 0, OPTi93X_DAC_LEFT, OPTi93X_DAC_RIGHT, 7, 7, 1, 1),
1613 OPTi93X_DOUBLE("PCM Playback Volume", 0, OPTi93X_DAC_LEFT, OPTi93X_DAC_RIGHT, 0, 0, 31, 1),
1614 OPTi93X_DOUBLE("FM Playback Switch", 0, OPTi931_FM_LEFT_INPUT, OPTi931_FM_RIGHT_INPUT, 7, 7, 1, 1),
1615 OPTi93X_DOUBLE("FM Playback Volume", 0, OPTi931_FM_LEFT_INPUT, OPTi931_FM_RIGHT_INPUT, 1, 1, 15, 1),
1616 OPTi93X_DOUBLE("Line Playback Switch", 0, OPTi93X_LINE_LEFT_INPUT, OPTi93X_LINE_RIGHT_INPUT, 7, 7, 1, 1),
1617 OPTi93X_DOUBLE("Line Playback Volume", 0, OPTi93X_LINE_LEFT_INPUT, OPTi93X_LINE_RIGHT_INPUT, 1, 1, 15, 1),
1618 OPTi93X_DOUBLE("Mic Playback Switch", 0, OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 7, 7, 1, 1),
1619 OPTi93X_DOUBLE("Mic Playback Volume", 0, OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 1, 1, 15, 1),
1620 OPTi93X_DOUBLE("Mic Boost", 0, OPTi93X_MIXOUT_LEFT, OPTi93X_MIXOUT_RIGHT, 5, 5, 1, 1),
1621 OPTi93X_DOUBLE("CD Playback Switch", 0, OPTi93X_CD_LEFT_INPUT, OPTi93X_CD_RIGHT_INPUT, 7, 7, 1, 1),
1622 OPTi93X_DOUBLE("CD Playback Volume", 0, OPTi93X_CD_LEFT_INPUT, OPTi93X_CD_RIGHT_INPUT, 1, 1, 15, 1),
1623 OPTi93X_DOUBLE("Aux Playback Switch", 0, OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 7, 7, 1, 1),
1624 OPTi93X_DOUBLE("Aux Playback Volume", 0, OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 1, 1, 15, 1),
1625 OPTi93X_DOUBLE("Capture Volume", 0, OPTi93X_MIXOUT_LEFT, OPTi93X_MIXOUT_RIGHT, 0, 0, 15, 0),
1627 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1628 .name = "Capture Source",
1629 .info = snd_opti93x_info_mux,
1630 .get = snd_opti93x_get_mux,
1631 .put = snd_opti93x_put_mux,
1635 int snd_opti93x_mixer(opti93x_t *chip)
1638 snd_kcontrol_new_t knew;
1642 snd_assert(chip != NULL && chip->card != NULL, return -EINVAL);
1646 strcpy(card->mixername, snd_opti93x_chip_id(chip));
1648 for (idx = 0; idx < OPTi93X_CONTROLS; idx++) {
1649 knew = snd_opti93x_controls[idx];
1650 if (chip->hardware == OPTi9XX_HW_82C930) {
1651 if (strstr(knew.name, "FM")) /* skip FM controls */
1653 else if (strcmp(knew.name, "Mic Playback Volume"))
1654 OPTi93X_DOUBLE_INVERT_INVERT(knew);
1655 else if (strstr(knew.name, "Aux"))
1656 OPTi93X_DOUBLE_CHANGE_REGS(knew, OPTi930_AUX_LEFT_INPUT, OPTi930_AUX_RIGHT_INPUT);
1657 else if (strcmp(knew.name, "PCM Playback Volume"))
1658 OPTi93X_DOUBLE_INVERT_INVERT(knew);
1659 else if (strcmp(knew.name, "Master Playback Volume"))
1660 OPTi93X_DOUBLE_INVERT_INVERT(knew);
1662 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_opti93x_controls[idx], chip))) < 0)
1668 #endif /* OPTi93X */
1670 static int __devinit snd_card_opti9xx_detect(snd_card_t *card, opti9xx_t *chip)
1675 for (i = OPTi9XX_HW_82C928; i < OPTi9XX_HW_82C930; i++) {
1676 unsigned char value;
1678 if ((err = snd_opti9xx_init(chip, i)) < 0)
1681 if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL)
1684 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(1));
1685 if ((value != 0xff) && (value != inb(chip->mc_base + 1)))
1686 if (value == snd_opti9xx_read(chip, OPTi9XX_MC_REG(1)))
1689 release_resource(chip->res_mc_base);
1690 kfree_nocheck(chip->res_mc_base);
1691 chip->res_mc_base = NULL;
1695 for (i = OPTi9XX_HW_82C931; i >= OPTi9XX_HW_82C930; i--) {
1696 unsigned long flags;
1697 unsigned char value;
1699 if ((err = snd_opti9xx_init(chip, i)) < 0)
1702 if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL)
1705 spin_lock_irqsave(&chip->lock, flags);
1706 outb(chip->password, chip->mc_base + chip->pwd_reg);
1707 outb(((chip->mc_indir_index & (1 << 8)) >> 4) |
1708 ((chip->mc_indir_index & 0xf0) >> 4), chip->mc_base);
1709 spin_unlock_irqrestore(&chip->lock, flags);
1711 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(7));
1712 snd_opti9xx_write(chip, OPTi9XX_MC_REG(7), 0xff - value);
1713 if (snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)) == 0xff - value)
1716 release_resource(chip->res_mc_base);
1717 kfree_nocheck(chip->res_mc_base);
1718 chip->res_mc_base = NULL;
1720 #endif /* OPTi93X */
1726 static int __devinit snd_card_opti9xx_pnp(opti9xx_t *chip, struct pnp_card_link *card,
1727 const struct pnp_card_device_id *pid)
1729 struct pnp_dev *pdev;
1730 struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
1733 chip->dev = pnp_request_card_device(card, pid->devs[0].id, NULL);
1734 if (chip->dev == NULL) {
1738 chip->devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
1741 pnp_init_resource_table(cfg);
1744 if (port != SNDRV_AUTO_PORT)
1745 pnp_resource_change(&cfg->port_resource[0], port + 4, 4);
1747 if (pid->driver_data != 0x0924 && port != SNDRV_AUTO_PORT)
1748 pnp_resource_change(&cfg->port_resource[1], port, 4);
1749 #endif /* OPTi93X */
1750 if (irq != SNDRV_AUTO_IRQ)
1751 pnp_resource_change(&cfg->irq_resource[0], irq, 1);
1752 if (dma1 != SNDRV_AUTO_DMA)
1753 pnp_resource_change(&cfg->dma_resource[0], dma1, 1);
1754 #if defined(CS4231) || defined(OPTi93X)
1755 if (dma2 != SNDRV_AUTO_DMA)
1756 pnp_resource_change(&cfg->dma_resource[1], dma2, 1);
1758 #ifdef snd_opti9xx_fixup_dma2
1759 snd_opti9xx_fixup_dma2(pdev);
1761 #endif /* CS4231 || OPTi93X */
1763 if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT)
1764 pnp_resource_change(&cfg->port_resource[1], fm_port, 4);
1766 if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT)
1767 pnp_resource_change(&cfg->port_resource[2], fm_port, 4);
1769 if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
1770 snd_printk(KERN_ERR "AUDIO the requested resources are invalid, using auto config\n");
1771 err = pnp_activate_dev(pdev);
1773 snd_printk(KERN_ERR "AUDIO pnp configure failure: %d\n", err);
1779 port = pnp_port_start(pdev, 0) - 4;
1780 fm_port = pnp_port_start(pdev, 1);
1782 if (pid->driver_data != 0x0924)
1783 port = pnp_port_start(pdev, 1);
1784 fm_port = pnp_port_start(pdev, 2);
1785 #endif /* OPTi93X */
1786 irq = pnp_irq(pdev, 0);
1787 dma1 = pnp_dma(pdev, 0);
1788 #if defined(CS4231) || defined(OPTi93X)
1789 dma2 = pnp_dma(pdev, 1);
1790 #endif /* CS4231 || OPTi93X */
1792 pdev = chip->devmpu;
1793 if (pdev && mpu_port > 0) {
1794 pnp_init_resource_table(cfg);
1796 if (mpu_port != SNDRV_AUTO_PORT)
1797 pnp_resource_change(&cfg->port_resource[0], mpu_port, 2);
1798 if (mpu_irq != SNDRV_AUTO_IRQ)
1799 pnp_resource_change(&cfg->irq_resource[0], mpu_irq, 1);
1801 if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
1802 snd_printk(KERN_ERR "AUDIO the requested resources are invalid, using auto config\n");
1803 err = pnp_activate_dev(pdev);
1805 snd_printk(KERN_ERR "AUDIO pnp configure failure\n");
1807 chip->devmpu = NULL;
1809 mpu_port = pnp_port_start(pdev, 0);
1810 mpu_irq = pnp_irq(pdev, 0);
1814 return pid->driver_data;
1816 #endif /* CONFIG_PNP */
1819 static int __devinit snd_card_opti9xx_resources(struct snd_card_opti9xx *chip,
1822 int error, i, pnp = 0;
1825 pnp = chip->dev != NULL;
1826 #endif /* CONFIG_PNP */
1829 if (chip->chip->hardware == OPTi9XX_HW_82C928)
1831 #endif /* OPTi93X */
1833 if (!pnp && (mpu_port == SNDRV_DEFAULT_PORT1)) {
1834 for (i = 0; possible_mpu_ports[i] != -1; i++)
1835 if (!snd_register_ioport(card, possible_mpu_ports[i], 2,
1836 DRIVER_NAME" - MPU-401", NULL)) {
1837 mpu_port = possible_mpu_ports[i];
1840 if (mpu_port == SNDRV_DEFAULT_PORT1)
1844 error = (mpu_port == -1) ? -ENODEV :
1845 snd_register_ioport(card, mpu_port, 2,
1846 DRIVER_NAME" - MPU-401", NULL);
1848 chip->chip->mpu_port = -1;
1849 else if (pnp && (irq == mpu_irq))
1850 chip->chip->mpu_irq = mpu_irq;
1851 else if (!snd_register_interrupt(card,
1852 DRIVER_NAME" - MPU-401",
1853 mpu_irq, SNDRV_IRQ_TYPE_ISA,
1854 snd_card_opti9xx_mpu_interrupt, chip,
1855 pnp ? no_alternatives : possible_mpu_irqs,
1856 &chip->mpuirqptr)) {
1857 chip->chip->mpu_port = mpu_port;
1858 chip->chip->mpu_irq = chip->mpuirqptr->irq;
1861 chip->chip->mpu_port = -1;
1863 if (!pnp && (port == SNDRV_DEFAULT_PORT1)) {
1864 for (i = 0; possible_ports[i] != -1; i++)
1865 if (!snd_register_ioport(card, possible_ports[i], 8,
1866 DRIVER_NAME" - WSS", NULL)) {
1867 port = possible_ports[i];
1870 if (port == SNDRV_DEFAULT_PORT1)
1873 else if ((error = snd_register_ioport(card, port, 8,
1874 DRIVER_NAME" - WSS", NULL)) < 0)
1876 chip->chip->wss_base = port;
1877 if ((error = snd_register_interrupt(card, DRIVER_NAME" - WSS",
1878 irq, SNDRV_IRQ_TYPE_ISA,
1879 snd_card_opti9xx_interrupt, chip,
1880 pnp ? no_alternatives : possible_irqs,
1881 &chip->irqptr)) < 0)
1883 chip->chip->irq = chip->irqptr->irq;
1884 if ((error = snd_register_dma_channel(card,
1885 #if defined(CS4231) || defined(OPTi93X)
1886 DRIVER_NAME" - WSS playback",
1888 DRIVER_NAME" - WSS",
1889 #endif /* CS4231 || OPTi93X */
1890 dma1, SNDRV_DMA_TYPE_ISA, dma1_size,
1891 pnp ? no_alternatives : possible_dma1s,
1892 &chip->dma1ptr)) < 0)
1894 chip->chip->dma1 = chip->dma1ptr->dma;
1895 #if defined(CS4231) || defined(OPTi93X)
1896 if ((error = snd_register_dma_channel(card, DRIVER_NAME" - WSS capture",
1897 dma2, SNDRV_DMA_TYPE_ISA, dma2_size,
1898 pnp ? no_alternatives :
1899 possible_dma2s[chip->dma1ptr->dma],
1900 &chip->dma2ptr)) < 0)
1902 chip->chip->dma2 = chip->dma2ptr->dma;
1903 #endif /* CS4231 || OPTi93X */
1905 if (snd_register_ioport(card,
1906 pnp ? fm_port : fm_port = 0x388, 4,
1907 DRIVER_NAME" - OPL", NULL) < 0)
1909 chip->chip->fm_port = fm_port;
1915 static void snd_card_opti9xx_free(snd_card_t *card)
1917 opti9xx_t *chip = (opti9xx_t *)card->private_data;
1920 if (chip->res_mc_base) {
1921 release_resource(chip->res_mc_base);
1922 kfree_nocheck(chip->res_mc_base);
1927 static int __devinit snd_card_opti9xx_probe(struct pnp_card_link *pcard,
1928 const struct pnp_card_device_id *pid)
1930 static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
1931 static long possible_mpu_ports[] = {0x300, 0x310, 0x320, 0x330, -1};
1933 static int possible_irqs[] = {5, 9, 10, 11, 7, -1};
1935 static int possible_irqs[] = {9, 10, 11, 7, -1};
1936 #endif /* OPTi93X */
1937 static int possible_mpu_irqs[] = {5, 9, 10, 7, -1};
1938 static int possible_dma1s[] = {3, 1, 0, -1};
1939 #if defined(CS4231) || defined(OPTi93X)
1940 static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};
1941 #endif /* CS4231 || OPTi93X */
1944 #if defined(OPTi93X)
1946 #elif defined(CS4231)
1954 snd_rawmidi_t *rmidi;
1958 #endif /* CONFIG_PNP */
1960 if (pcard && !snd_opti9xx_first_hit)
1962 if (!(card = snd_card_new(index, id, THIS_MODULE,
1963 sizeof(opti9xx_t))))
1965 card->private_free = snd_card_opti9xx_free;
1966 chip = (opti9xx_t *)card->private_data;
1969 if (isapnp && pcard && (hw = snd_card_opti9xx_pnp(chip, pcard, pid)) > 0) {
1972 hw = OPTi9XX_HW_82C924;
1975 hw = OPTi9XX_HW_82C925;
1978 hw = OPTi9XX_HW_82C931;
1981 snd_card_free(card);
1985 if ((error = snd_opti9xx_init(chip, hw))) {
1986 snd_card_free(card);
1989 if (hw <= OPTi9XX_HW_82C930)
1990 chip->mc_base -= 0x80;
1991 snd_card_set_dev(card, &pcard->card->dev);
1993 #endif /* CONFIG_PNP */
1994 if ((error = snd_card_opti9xx_detect(card, chip)) < 0) {
1995 snd_card_free(card);
2000 #endif /* CONFIG_PNP */
2002 if (! chip->res_mc_base &&
2003 (chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL) {
2004 snd_card_free(card);
2008 chip->wss_base = port;
2009 chip->fm_port = fm_port;
2010 chip->mpu_port = mpu_port;
2012 chip->mpu_irq = mpu_irq;
2014 #if defined(CS4231) || defined(OPTi93X)
2018 if (chip->wss_base == SNDRV_AUTO_PORT) {
2019 if ((chip->wss_base = snd_legacy_find_free_ioport(possible_ports, 4)) < 0) {
2020 snd_card_free(card);
2021 snd_printk("unable to find a free WSS port\n");
2028 if (chip->mpu_port == SNDRV_AUTO_PORT) {
2029 if ((chip->mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) {
2030 snd_card_free(card);
2031 snd_printk("unable to find a free MPU401 port\n");
2035 if (chip->irq == SNDRV_AUTO_IRQ) {
2036 if ((chip->irq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
2037 snd_card_free(card);
2038 snd_printk("unable to find a free IRQ\n");
2042 if (chip->mpu_irq == SNDRV_AUTO_IRQ) {
2043 if ((chip->mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) {
2044 snd_card_free(card);
2045 snd_printk("unable to find a free MPU401 IRQ\n");
2049 if (chip->dma1 == SNDRV_AUTO_DMA) {
2050 if ((chip->dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) {
2051 snd_card_free(card);
2052 snd_printk("unable to find a free DMA1\n");
2056 #if defined(CS4231) || defined(OPTi93X)
2057 if (chip->dma2 == SNDRV_AUTO_DMA) {
2058 if ((chip->dma2 = snd_legacy_find_free_dma(possible_dma2s[chip->dma1 % 4])) < 0) {
2059 snd_card_free(card);
2060 snd_printk("unable to find a free DMA2\n");
2070 if ((error = snd_opti9xx_configure(chip))) {
2071 snd_card_free(card);
2075 #if defined(OPTi93X)
2076 if ((error = snd_opti93x_create(card, chip, chip->dma1, chip->dma2, &codec))) {
2077 snd_card_free(card);
2080 if ((error = snd_opti93x_pcm(codec, 0, &pcm)) < 0) {
2081 snd_card_free(card);
2084 if ((error = snd_opti93x_mixer(codec)) < 0) {
2085 snd_card_free(card);
2088 #elif defined(CS4231)
2089 if ((error = snd_cs4231_create(card, chip->wss_base + 4, -1,
2090 chip->irq, chip->dma1, chip->dma2,
2094 snd_card_free(card);
2097 if ((error = snd_cs4231_pcm(codec, 0, &pcm)) < 0) {
2098 snd_card_free(card);
2101 if ((error = snd_cs4231_mixer(codec)) < 0) {
2102 snd_card_free(card);
2105 if ((error = snd_cs4231_timer(codec, 0, &timer)) < 0) {
2106 snd_card_free(card);
2110 if ((error = snd_ad1848_create(card, chip->wss_base + 4,
2111 chip->irq, chip->dma1,
2112 AD1848_HW_DETECT, &codec)) < 0) {
2113 snd_card_free(card);
2116 if ((error = snd_ad1848_pcm(codec, 0, &pcm)) < 0) {
2117 snd_card_free(card);
2120 if ((error = snd_ad1848_mixer(codec)) < 0) {
2121 snd_card_free(card);
2125 strcpy(card->driver, chip->name);
2126 sprintf(card->shortname, "OPTi %s", card->driver);
2127 #if defined(CS4231) || defined(OPTi93X)
2128 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d",
2129 card->shortname, pcm->name, chip->wss_base + 4,
2130 chip->irq, chip->dma1, chip->dma2);
2132 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
2133 card->shortname, pcm->name, chip->wss_base + 4,
2134 chip->irq, chip->dma1);
2135 #endif /* CS4231 || OPTi93X */
2137 if (chip->mpu_port <= 0 || chip->mpu_port == SNDRV_AUTO_PORT)
2140 if ((error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
2141 chip->mpu_port, 0, chip->mpu_irq, SA_INTERRUPT,
2143 snd_printk("no MPU-401 device at 0x%lx?\n", chip->mpu_port);
2145 if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) {
2146 opl3_t *opl3 = NULL;
2148 if (chip->hardware == OPTi9XX_HW_82C928 ||
2149 chip->hardware == OPTi9XX_HW_82C929 ||
2150 chip->hardware == OPTi9XX_HW_82C924) {
2152 /* assume we have an OPL4 */
2153 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
2155 if (snd_opl4_create(card,
2158 2, &opl3, &opl4) < 0) {
2159 /* no luck, use OPL3 instead */
2160 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
2164 #endif /* !OPTi93X */
2165 if (!opl3 && snd_opl3_create(card,
2168 OPL3_HW_AUTO, 0, &opl3) < 0) {
2169 snd_printk("no OPL device at 0x%lx-0x%lx\n",
2170 chip->fm_port, chip->fm_port + 4 - 1);
2173 if ((error = snd_opl3_timer_new(opl3,
2179 snd_card_free(card);
2182 if ((error = snd_opl3_hwdep_new(opl3, 0, 1, &synth)) < 0) {
2183 snd_card_free(card);
2189 if ((error = snd_card_register(card))) {
2190 snd_card_free(card);
2193 snd_opti9xx_first_hit = 0;
2195 pnp_set_card_drvdata(pcard, card);
2197 snd_opti9xx_legacy = card;
2202 static void __devexit snd_opti9xx_pnp_remove(struct pnp_card_link * pcard)
2204 snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
2206 snd_card_disconnect(card);
2207 snd_card_free_in_thread(card);
2208 snd_opti9xx_first_hit = 0;
2211 static struct pnp_card_driver opti9xx_pnpc_driver = {
2212 .flags = PNP_DRIVER_RES_DISABLE,
2214 .id_table = snd_opti9xx_pnpids,
2215 .probe = snd_card_opti9xx_probe,
2216 .remove = __devexit_p(snd_opti9xx_pnp_remove),
2220 static int __init alsa_card_opti9xx_init(void)
2225 cards = pnp_register_card_driver(&opti9xx_pnpc_driver);
2229 if (cards == 0 && (error = snd_card_opti9xx_probe(NULL, NULL)) < 0) {
2231 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
2235 printk(KERN_ERR "no OPTi 82C93x soundcard found\n");
2237 printk(KERN_ERR "no OPTi 82C92x soundcard found\n");
2238 #endif /* OPTi93X */
2245 static void __exit alsa_card_opti9xx_exit(void)
2248 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
2250 if (snd_opti9xx_legacy)
2251 snd_card_free(snd_opti9xx_legacy);
2254 module_init(alsa_card_opti9xx_init)
2255 module_exit(alsa_card_opti9xx_exit)
2259 /* format is: snd-opti9xx=enable,index,id,isapnp,
2260 port,mpu_port,fm_port,
2264 static int __init alsa_card_opti9xx_setup(char *str)
2266 int __attribute__ ((__unused__)) enable = 1;
2267 int __attribute__ ((__unused__)) pnp = INT_MAX;
2269 (void)(get_option(&str,&enable) == 2 &&
2270 get_option(&str,&index) == 2 &&
2271 get_id(&str,&id) == 2 &&
2272 get_option(&str,&pnp) == 2 &&
2273 get_option_long(&str,&port) == 2 &&
2274 get_option_long(&str,&mpu_port) == 2 &&
2275 get_option_long(&str,&fm_port) == 2 &&
2276 get_option(&str,&irq) == 2 &&
2277 get_option(&str,&mpu_irq) == 2 &&
2278 get_option(&str,&dma1) == 2
2279 #if defined(CS4231) || defined(OPTi93X)
2281 get_option(&str,&dma2) == 2
2291 #if defined(OPTi93X)
2292 __setup("snd-opti93x=", alsa_card_opti9xx_setup);
2293 #elif defined(CS4231)
2294 __setup("snd-opti92x-cs4231=", alsa_card_opti9xx_setup);
2296 __setup("snd-opti92x-ad1848=", alsa_card_opti9xx_setup);
2299 #endif /* ifndef MODULE */