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 <linux/moduleparam.h>
34 #include <sound/core.h>
36 #include <sound/cs4231.h>
39 #include <sound/ad1848.h>
41 #include <sound/control.h>
42 #include <sound/pcm.h>
45 #include <sound/mpu401.h>
46 #include <sound/opl3.h>
48 #include <sound/opl4.h>
50 #define SNDRV_LEGACY_FIND_FREE_IRQ
51 #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_param(index, int, 0444);
88 MODULE_PARM_DESC(index, "Index value for opti9xx based soundcard.");
89 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
90 module_param(id, charp, 0444);
91 MODULE_PARM_DESC(id, "ID string for opti9xx based soundcard.");
92 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
93 //module_param(enable, bool, 0444);
94 //MODULE_PARM_DESC(enable, "Enable opti9xx soundcard.");
95 //MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
96 module_param(isapnp, bool, 0444);
97 MODULE_PARM_DESC(isapnp, "Enable ISA PnP detection for specified soundcard.");
98 MODULE_PARM_SYNTAX(isapnp, SNDRV_ISAPNP_DESC);
99 module_param(port, long, 0444);
100 MODULE_PARM_DESC(port, "WSS port # for opti9xx driver.");
101 MODULE_PARM_SYNTAX(port, SNDRV_PORT_DESC);
102 module_param(mpu_port, long, 0444);
103 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for opti9xx driver.");
104 MODULE_PARM_SYNTAX(mpu_port, SNDRV_PORT_DESC);
105 module_param(fm_port, long, 0444);
106 MODULE_PARM_DESC(fm_port, "FM port # for opti9xx driver.");
107 MODULE_PARM_SYNTAX(fm_port, SNDRV_PORT_DESC);
108 module_param(irq, int, 0444);
109 MODULE_PARM_DESC(irq, "WSS irq # for opti9xx driver.");
110 MODULE_PARM_SYNTAX(irq, SNDRV_IRQ_DESC);
111 module_param(mpu_irq, int, 0444);
112 MODULE_PARM_DESC(mpu_irq, "MPU-401 irq # for opti9xx driver.");
113 MODULE_PARM_SYNTAX(mpu_irq, SNDRV_IRQ_DESC);
114 module_param(dma1, int, 0444);
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_param(dma2, int, 0444);
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);
606 outb(irq_bits << 3 | dma_bits, chip->wss_base);
608 snd_opti9xx_write(chip, OPTi9XX_MC_REG(3), (irq_bits << 3 | dma_bits));
610 spin_unlock_irqrestore(&chip->lock, flags);
613 if (chip->hardware > OPTi9XX_HW_82C928) {
614 switch (chip->mpu_port) {
619 mpu_port_bits = 0x03;
622 mpu_port_bits = 0x02;
625 mpu_port_bits = 0x01;
628 mpu_port_bits = 0x00;
631 snd_printk("MPU-401 port 0x%lx not valid\n",
636 switch (chip->mpu_irq) {
650 snd_printk("MPU-401 irq # %d not valid\n",
655 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6),
656 (chip->mpu_port <= 0) ? 0x00 :
657 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
667 #define chip_t opti93x_t
669 static unsigned char snd_opti93x_default_image[32] =
671 0x00, /* 00/00 - l_mixout_outctrl */
672 0x00, /* 01/01 - r_mixout_outctrl */
673 0x88, /* 02/02 - l_cd_inctrl */
674 0x88, /* 03/03 - r_cd_inctrl */
675 0x88, /* 04/04 - l_a1/fm_inctrl */
676 0x88, /* 05/05 - r_a1/fm_inctrl */
677 0x80, /* 06/06 - l_dac_inctrl */
678 0x80, /* 07/07 - r_dac_inctrl */
679 0x00, /* 08/08 - ply_dataform_reg */
680 0x00, /* 09/09 - if_conf */
681 0x00, /* 0a/10 - pin_ctrl */
682 0x00, /* 0b/11 - err_init_reg */
683 0x0a, /* 0c/12 - id_reg */
684 0x00, /* 0d/13 - reserved */
685 0x00, /* 0e/14 - ply_upcount_reg */
686 0x00, /* 0f/15 - ply_lowcount_reg */
687 0x88, /* 10/16 - reserved/l_a1_inctrl */
688 0x88, /* 11/17 - reserved/r_a1_inctrl */
689 0x88, /* 12/18 - l_line_inctrl */
690 0x88, /* 13/19 - r_line_inctrl */
691 0x88, /* 14/20 - l_mic_inctrl */
692 0x88, /* 15/21 - r_mic_inctrl */
693 0x80, /* 16/22 - l_out_outctrl */
694 0x80, /* 17/23 - r_out_outctrl */
695 0x00, /* 18/24 - reserved */
696 0x00, /* 19/25 - reserved */
697 0x00, /* 1a/26 - reserved */
698 0x00, /* 1b/27 - reserved */
699 0x00, /* 1c/28 - cap_dataform_reg */
700 0x00, /* 1d/29 - reserved */
701 0x00, /* 1e/30 - cap_upcount_reg */
702 0x00 /* 1f/31 - cap_lowcount_reg */
706 static int snd_opti93x_busy_wait(opti93x_t *chip)
710 for (timeout = 250; timeout-- > 0; udelay(10))
711 if (!(inb(OPTi93X_PORT(chip, INDEX)) & OPTi93X_INIT))
714 snd_printk("chip still busy.\n");
718 static unsigned char snd_opti93x_in(opti93x_t *chip, unsigned char reg)
720 snd_opti93x_busy_wait(chip);
721 outb(chip->mce_bit | (reg & 0x1f), OPTi93X_PORT(chip, INDEX));
722 return inb(OPTi93X_PORT(chip, DATA));
725 static void snd_opti93x_out(opti93x_t *chip, unsigned char reg,
728 snd_opti93x_busy_wait(chip);
729 outb(chip->mce_bit | (reg & 0x1f), OPTi93X_PORT(chip, INDEX));
730 outb(value, OPTi93X_PORT(chip, DATA));
733 static void snd_opti93x_out_image(opti93x_t *chip, unsigned char reg,
736 snd_opti93x_out(chip, reg, chip->image[reg] = value);
739 static void snd_opti93x_out_mask(opti93x_t *chip, unsigned char reg,
740 unsigned char mask, unsigned char value)
742 snd_opti93x_out_image(chip, reg,
743 (chip->image[reg] & ~mask) | (value & mask));
747 static void snd_opti93x_mce_up(opti93x_t *chip)
749 snd_opti93x_busy_wait(chip);
751 chip->mce_bit = OPTi93X_MCE;
752 if (!(inb(OPTi93X_PORT(chip, INDEX)) & OPTi93X_MCE))
753 outb(chip->mce_bit, OPTi93X_PORT(chip, INDEX));
756 static void snd_opti93x_mce_down(opti93x_t *chip)
758 snd_opti93x_busy_wait(chip);
761 if (inb(OPTi93X_PORT(chip, INDEX)) & OPTi93X_MCE)
762 outb(chip->mce_bit, OPTi93X_PORT(chip, INDEX));
765 #define snd_opti93x_mute_reg(chip, reg, mute) \
766 snd_opti93x_out(chip, reg, mute ? 0x80 : chip->image[reg]);
768 static void snd_opti93x_mute(opti93x_t *chip, int mute)
772 spin_lock_irqsave(&chip->lock, flags);
775 if (chip->mute == mute) {
776 spin_unlock_irqrestore(&chip->lock, flags);
781 snd_opti93x_mute_reg(chip, OPTi93X_CD_LEFT_INPUT, mute);
782 snd_opti93x_mute_reg(chip, OPTi93X_CD_RIGHT_INPUT, mute);
783 switch (chip->hardware) {
784 case OPTi9XX_HW_82C930:
785 snd_opti93x_mute_reg(chip, OPTi930_AUX_LEFT_INPUT, mute);
786 snd_opti93x_mute_reg(chip, OPTi930_AUX_RIGHT_INPUT, mute);
788 case OPTi9XX_HW_82C931:
789 case OPTi9XX_HW_82C933:
790 snd_opti93x_mute_reg(chip, OPTi931_FM_LEFT_INPUT, mute);
791 snd_opti93x_mute_reg(chip, OPTi931_FM_RIGHT_INPUT, mute);
792 snd_opti93x_mute_reg(chip, OPTi931_AUX_LEFT_INPUT, mute);
793 snd_opti93x_mute_reg(chip, OPTi931_AUX_RIGHT_INPUT, mute);
795 snd_opti93x_mute_reg(chip, OPTi93X_DAC_LEFT, mute);
796 snd_opti93x_mute_reg(chip, OPTi93X_DAC_RIGHT, mute);
797 snd_opti93x_mute_reg(chip, OPTi93X_LINE_LEFT_INPUT, mute);
798 snd_opti93x_mute_reg(chip, OPTi93X_LINE_RIGHT_INPUT, mute);
799 snd_opti93x_mute_reg(chip, OPTi93X_MIC_LEFT_INPUT, mute);
800 snd_opti93x_mute_reg(chip, OPTi93X_MIC_RIGHT_INPUT, mute);
801 snd_opti93x_mute_reg(chip, OPTi93X_OUT_LEFT, mute);
802 snd_opti93x_mute_reg(chip, OPTi93X_OUT_RIGHT, mute);
804 spin_unlock_irqrestore(&chip->lock, flags);
808 static unsigned int snd_opti93x_get_count(unsigned char format,
811 switch (format & 0xe0) {
812 case OPTi93X_LINEAR_16_LIT:
813 case OPTi93X_LINEAR_16_BIG:
816 case OPTi93X_ADPCM_16:
819 return (format & OPTi93X_STEREO) ? (size >> 1) : size;
822 static unsigned int rates[] = { 5512, 6615, 8000, 9600, 11025, 16000,
823 18900, 22050, 27428, 32000, 33075, 37800,
825 #define RATES sizeof(rates) / sizeof(rates[0])
827 static snd_pcm_hw_constraint_list_t hw_constraints_rates = {
833 static unsigned char bits[] = { 0x01, 0x0f, 0x00, 0x0e, 0x03, 0x02,
834 0x05, 0x07, 0x04, 0x06, 0x0d, 0x09,
837 static unsigned char snd_opti93x_get_freq(unsigned int rate)
841 for (i = 0; i < RATES; i++) {
842 if (rate == rates[i])
846 return bits[RATES-1];
849 static unsigned char snd_opti93x_get_format(opti93x_t *chip,
850 unsigned int format, int channels)
852 unsigned char retval = OPTi93X_LINEAR_8;
855 case SNDRV_PCM_FORMAT_MU_LAW:
856 retval = OPTi93X_ULAW_8;
858 case SNDRV_PCM_FORMAT_A_LAW:
859 retval = OPTi93X_ALAW_8;
861 case SNDRV_PCM_FORMAT_S16_LE:
862 retval = OPTi93X_LINEAR_16_LIT;
864 case SNDRV_PCM_FORMAT_S16_BE:
865 retval = OPTi93X_LINEAR_16_BIG;
867 case SNDRV_PCM_FORMAT_IMA_ADPCM:
868 retval = OPTi93X_ADPCM_16;
870 return (channels > 1) ? (retval | OPTi93X_STEREO) : retval;
874 static void snd_opti93x_playback_format(opti93x_t *chip, unsigned char fmt)
879 spin_lock_irqsave(&chip->lock, flags);
880 snd_opti93x_mute(chip, 1);
882 snd_opti93x_mce_up(chip);
883 mask = (chip->mode & OPTi93X_MODE_CAPTURE) ? 0xf0 : 0xff;
884 snd_opti93x_out_mask(chip, OPTi93X_PLAY_FORMAT, mask, fmt);
885 snd_opti93x_mce_down(chip);
887 snd_opti93x_mute(chip, 0);
888 spin_unlock_irqrestore(&chip->lock, flags);
891 static void snd_opti93x_capture_format(opti93x_t *chip, unsigned char fmt)
895 spin_lock_irqsave(&chip->lock, flags);
896 snd_opti93x_mute(chip, 1);
898 snd_opti93x_mce_up(chip);
899 if (!(chip->mode & OPTi93X_MODE_PLAY))
900 snd_opti93x_out_mask(chip, OPTi93X_PLAY_FORMAT, 0x0f, fmt);
902 fmt = chip->image[OPTi93X_PLAY_FORMAT] & 0xf0;
903 snd_opti93x_out_image(chip, OPTi93X_CAPT_FORMAT, fmt);
904 snd_opti93x_mce_down(chip);
906 snd_opti93x_mute(chip, 0);
907 spin_unlock_irqrestore(&chip->lock, flags);
911 static int snd_opti93x_open(opti93x_t *chip, unsigned int mode)
915 spin_lock_irqsave(&chip->lock, flags);
917 if (chip->mode & mode) {
918 spin_unlock_irqrestore(&chip->lock, flags);
922 if (!(chip->mode & OPTi93X_MODE_OPEN)) {
923 outb(0x00, OPTi93X_PORT(chip, STATUS));
924 snd_opti93x_out_mask(chip, OPTi93X_PIN_CTRL,
925 OPTi93X_IRQ_ENABLE, OPTi93X_IRQ_ENABLE);
931 spin_unlock_irqrestore(&chip->lock, flags);
935 static void snd_opti93x_close(opti93x_t *chip, unsigned int mode)
939 spin_lock_irqsave(&chip->lock, flags);
942 if (chip->mode & OPTi93X_MODE_OPEN) {
943 spin_unlock_irqrestore(&chip->lock, flags);
947 snd_opti93x_mute(chip, 1);
949 outb(0, OPTi93X_PORT(chip, STATUS));
950 snd_opti93x_out_mask(chip, OPTi93X_PIN_CTRL, OPTi93X_IRQ_ENABLE,
951 ~OPTi93X_IRQ_ENABLE);
953 snd_opti93x_mce_up(chip);
954 snd_opti93x_out_image(chip, OPTi93X_IFACE_CONF, 0x00);
955 snd_opti93x_mce_down(chip);
958 snd_opti93x_mute(chip, 0);
959 spin_unlock_irqrestore(&chip->lock, flags);
962 static int snd_opti93x_trigger(snd_pcm_substream_t *substream,
963 unsigned char what, int cmd)
965 opti93x_t *chip = snd_pcm_substream_chip(substream);
968 case SNDRV_PCM_TRIGGER_START:
969 case SNDRV_PCM_TRIGGER_STOP:
971 unsigned int what = 0;
972 struct list_head *pos;
973 snd_pcm_substream_t *s;
974 snd_pcm_group_for_each(pos, substream) {
975 s = snd_pcm_group_substream_entry(pos);
976 if (s == chip->playback_substream) {
977 what |= OPTi93X_PLAYBACK_ENABLE;
978 snd_pcm_trigger_done(s, substream);
979 } else if (s == chip->capture_substream) {
980 what |= OPTi93X_CAPTURE_ENABLE;
981 snd_pcm_trigger_done(s, substream);
984 spin_lock(&chip->lock);
985 if (cmd == SNDRV_PCM_TRIGGER_START) {
986 snd_opti93x_out_mask(chip, OPTi93X_IFACE_CONF, what, what);
987 if (what & OPTi93X_CAPTURE_ENABLE)
990 snd_opti93x_out_mask(chip, OPTi93X_IFACE_CONF, what, 0x00);
991 spin_unlock(&chip->lock);
1000 static int snd_opti93x_playback_trigger(snd_pcm_substream_t *substream, int cmd)
1002 return snd_opti93x_trigger(substream,
1003 OPTi93X_PLAYBACK_ENABLE, cmd);
1006 static int snd_opti93x_capture_trigger(snd_pcm_substream_t * substream, int cmd)
1008 return snd_opti93x_trigger(substream,
1009 OPTi93X_CAPTURE_ENABLE, cmd);
1012 static int snd_opti93x_hw_params(snd_pcm_substream_t * substream,
1013 snd_pcm_hw_params_t * hw_params)
1015 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1019 static int snd_opti93x_hw_free(snd_pcm_substream_t * substream)
1021 snd_pcm_lib_free_pages(substream);
1026 static int snd_opti93x_playback_prepare(snd_pcm_substream_t * substream)
1028 opti93x_t *chip = snd_pcm_substream_chip(substream);
1029 snd_pcm_runtime_t *runtime = substream->runtime;
1030 unsigned long flags;
1031 unsigned char format;
1032 unsigned int count = snd_pcm_lib_period_bytes(substream);
1033 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
1035 spin_lock_irqsave(&chip->lock, flags);
1037 chip->p_dma_size = size;
1038 snd_opti93x_out_mask(chip, OPTi93X_IFACE_CONF,
1039 OPTi93X_PLAYBACK_ENABLE | OPTi93X_PLAYBACK_PIO,
1040 ~(OPTi93X_PLAYBACK_ENABLE | OPTi93X_PLAYBACK_PIO));
1042 snd_dma_program(chip->dma1, runtime->dma_addr, size,
1043 DMA_MODE_WRITE | DMA_AUTOINIT);
1045 format = snd_opti93x_get_freq(runtime->rate);
1046 format |= snd_opti93x_get_format(chip, runtime->format,
1048 snd_opti93x_playback_format(chip, format);
1049 format = chip->image[OPTi93X_PLAY_FORMAT];
1051 count = snd_opti93x_get_count(format, count) - 1;
1052 snd_opti93x_out_image(chip, OPTi93X_PLAY_LWR_CNT, count);
1053 snd_opti93x_out_image(chip, OPTi93X_PLAY_UPR_CNT, count >> 8);
1055 spin_unlock_irqrestore(&chip->lock, flags);
1059 static int snd_opti93x_capture_prepare(snd_pcm_substream_t *substream)
1061 opti93x_t *chip = snd_pcm_substream_chip(substream);
1062 snd_pcm_runtime_t *runtime = substream->runtime;
1063 unsigned long flags;
1064 unsigned char format;
1065 unsigned int count = snd_pcm_lib_period_bytes(substream);
1066 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
1068 spin_lock_irqsave(&chip->lock, flags);
1070 chip->c_dma_size = size;
1071 snd_opti93x_out_mask(chip, OPTi93X_IFACE_CONF,
1072 OPTi93X_CAPTURE_ENABLE | OPTi93X_CAPTURE_PIO,
1073 (unsigned char)~(OPTi93X_CAPTURE_ENABLE | OPTi93X_CAPTURE_PIO));
1075 snd_dma_program(chip->dma2, runtime->dma_addr, size,
1076 DMA_MODE_READ | DMA_AUTOINIT);
1078 format = snd_opti93x_get_freq(runtime->rate);
1079 format |= snd_opti93x_get_format(chip, runtime->format,
1081 snd_opti93x_capture_format(chip, format);
1082 format = chip->image[OPTi93X_CAPT_FORMAT];
1084 count = snd_opti93x_get_count(format, count) - 1;
1085 snd_opti93x_out_image(chip, OPTi93X_CAPT_LWR_CNT, count);
1086 snd_opti93x_out_image(chip, OPTi93X_CAPT_UPR_CNT, count >> 8);
1088 spin_unlock_irqrestore(&chip->lock, flags);
1092 static snd_pcm_uframes_t snd_opti93x_playback_pointer(snd_pcm_substream_t *substream)
1094 opti93x_t *chip = snd_pcm_substream_chip(substream);
1097 if (!(chip->image[OPTi93X_IFACE_CONF] & OPTi93X_PLAYBACK_ENABLE))
1100 ptr = snd_dma_pointer(chip->dma1, chip->p_dma_size);
1101 return bytes_to_frames(substream->runtime, ptr);
1104 static snd_pcm_uframes_t snd_opti93x_capture_pointer(snd_pcm_substream_t *substream)
1106 opti93x_t *chip = snd_pcm_substream_chip(substream);
1109 if (!(chip->image[OPTi93X_IFACE_CONF] & OPTi93X_CAPTURE_ENABLE))
1112 ptr = snd_dma_pointer(chip->dma2, chip->c_dma_size);
1113 return bytes_to_frames(substream->runtime, ptr);
1117 static void snd_opti93x_overrange(opti93x_t *chip)
1119 unsigned long flags;
1121 spin_lock_irqsave(&chip->lock, flags);
1123 if (snd_opti93x_in(chip, OPTi93X_ERR_INIT) & (0x08 | 0x02))
1124 chip->capture_substream->runtime->overrange++;
1126 spin_unlock_irqrestore(&chip->lock, flags);
1129 irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1131 opti93x_t *codec = snd_magic_cast(opti93x_t, dev_id, return IRQ_NONE);
1132 unsigned char status;
1134 status = snd_opti9xx_read(codec->chip, OPTi9XX_MC_REG(11));
1135 if ((status & OPTi93X_IRQ_PLAYBACK) && codec->playback_substream)
1136 snd_pcm_period_elapsed(codec->playback_substream);
1137 if ((status & OPTi93X_IRQ_CAPTURE) && codec->capture_substream) {
1138 snd_opti93x_overrange(codec);
1139 snd_pcm_period_elapsed(codec->capture_substream);
1141 outb(0x00, OPTi93X_PORT(codec, STATUS));
1146 static snd_pcm_hardware_t snd_opti93x_playback = {
1147 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1148 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START),
1149 .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM |
1150 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE),
1151 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
1156 .buffer_bytes_max = (128*1024),
1157 .period_bytes_min = 64,
1158 .period_bytes_max = (128*1024),
1160 .periods_max = 1024,
1164 static snd_pcm_hardware_t snd_opti93x_capture = {
1165 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1166 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START),
1167 .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM |
1168 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE),
1169 .rates = SNDRV_PCM_RATE_8000_48000,
1174 .buffer_bytes_max = (128*1024),
1175 .period_bytes_min = 64,
1176 .period_bytes_max = (128*1024),
1178 .periods_max = 1024,
1182 static int snd_opti93x_playback_open(snd_pcm_substream_t *substream)
1185 opti93x_t *chip = snd_pcm_substream_chip(substream);
1186 snd_pcm_runtime_t *runtime = substream->runtime;
1188 if ((error = snd_opti93x_open(chip, OPTi93X_MODE_PLAY)) < 0)
1190 snd_pcm_set_sync(substream);
1191 chip->playback_substream = substream;
1192 runtime->hw = snd_opti93x_playback;
1193 snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.buffer_bytes_max);
1194 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1198 static int snd_opti93x_capture_open(snd_pcm_substream_t *substream)
1201 opti93x_t *chip = snd_pcm_substream_chip(substream);
1202 snd_pcm_runtime_t *runtime = substream->runtime;
1204 if ((error = snd_opti93x_open(chip, OPTi93X_MODE_CAPTURE)) < 0)
1206 runtime->hw = snd_opti93x_capture;
1207 snd_pcm_set_sync(substream);
1208 chip->capture_substream = substream;
1209 snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.buffer_bytes_max);
1210 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
1214 static int snd_opti93x_playback_close(snd_pcm_substream_t *substream)
1216 opti93x_t *chip = snd_pcm_substream_chip(substream);
1218 chip->playback_substream = NULL;
1219 snd_opti93x_close(chip, OPTi93X_MODE_PLAY);
1223 static int snd_opti93x_capture_close(snd_pcm_substream_t *substream)
1225 opti93x_t *chip = snd_pcm_substream_chip(substream);
1227 chip->capture_substream = NULL;
1228 snd_opti93x_close(chip, OPTi93X_MODE_CAPTURE);
1233 static void snd_opti93x_init(opti93x_t *chip)
1235 unsigned long flags;
1238 spin_lock_irqsave(&chip->lock, flags);
1239 snd_opti93x_mce_up(chip);
1241 for (i = 0; i < 32; i++)
1242 snd_opti93x_out_image(chip, i, snd_opti93x_default_image[i]);
1244 snd_opti93x_mce_down(chip);
1245 spin_unlock_irqrestore(&chip->lock, flags);
1248 static int snd_opti93x_probe(opti93x_t *chip)
1250 unsigned long flags;
1253 spin_lock_irqsave(&chip->lock, flags);
1254 val = snd_opti93x_in(chip, OPTi93X_ID) & 0x0f;
1255 spin_unlock_irqrestore(&chip->lock, flags);
1257 return (val == 0x0a) ? 0 : -ENODEV;
1260 static int snd_opti93x_free(opti93x_t *chip)
1262 if (chip->res_port) {
1263 release_resource(chip->res_port);
1264 kfree_nocheck(chip->res_port);
1266 if (chip->dma1 >= 0) {
1267 disable_dma(chip->dma1);
1268 free_dma(chip->dma1);
1270 if (chip->dma2 >= 0) {
1271 disable_dma(chip->dma2);
1272 free_dma(chip->dma2);
1274 if (chip->irq >= 0) {
1275 free_irq(chip->irq, chip);
1277 snd_magic_kfree(chip);
1281 static int snd_opti93x_dev_free(snd_device_t *device)
1283 opti93x_t *chip = snd_magic_cast(opti93x_t, device->device_data, return -ENXIO);
1284 return snd_opti93x_free(chip);
1287 static const char *snd_opti93x_chip_id(opti93x_t *codec)
1289 switch (codec->hardware) {
1290 case OPTi9XX_HW_82C930: return "82C930";
1291 case OPTi9XX_HW_82C931: return "82C931";
1292 case OPTi9XX_HW_82C933: return "82C933";
1293 default: return "???";
1297 int snd_opti93x_create(snd_card_t *card, opti9xx_t *chip,
1301 static snd_device_ops_t ops = {
1302 .dev_free = snd_opti93x_dev_free,
1308 codec = snd_magic_kcalloc(opti93x_t, 0, GFP_KERNEL);
1315 if ((codec->res_port = request_region(chip->wss_base + 4, 4, "OPTI93x CODEC")) == NULL) {
1316 snd_printk(KERN_ERR "opti9xx: can't grab port 0x%lx\n", chip->wss_base + 4);
1317 snd_opti93x_free(codec);
1320 if (request_dma(dma1, "OPTI93x - 1")) {
1321 snd_printk(KERN_ERR "opti9xx: can't grab DMA1 %d\n", dma1);
1322 snd_opti93x_free(codec);
1325 codec->dma1 = chip->dma1;
1326 if (request_dma(dma2, "OPTI93x - 2")) {
1327 snd_printk(KERN_ERR "opti9xx: can't grab DMA2 %d\n", dma2);
1328 snd_opti93x_free(codec);
1331 codec->dma2 = chip->dma2;
1333 if (request_irq(chip->irq, snd_opti93x_interrupt, SA_INTERRUPT, DRIVER_NAME" - WSS", codec)) {
1334 snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", chip->irq);
1335 snd_opti93x_free(codec);
1340 codec->port = chip->wss_base + 4;
1341 codec->irq = chip->irq;
1343 spin_lock_init(&codec->lock);
1344 codec->hardware = chip->hardware;
1347 if ((error = snd_opti93x_probe(codec))) {
1348 snd_opti93x_free(codec);
1352 snd_opti93x_init(codec);
1354 /* Register device */
1355 if ((error = snd_device_new(card, SNDRV_DEV_LOWLEVEL, codec, &ops)) < 0) {
1356 snd_opti93x_free(codec);
1364 static snd_pcm_ops_t snd_opti93x_playback_ops = {
1365 .open = snd_opti93x_playback_open,
1366 .close = snd_opti93x_playback_close,
1367 .ioctl = snd_pcm_lib_ioctl,
1368 .hw_params = snd_opti93x_hw_params,
1369 .hw_free = snd_opti93x_hw_free,
1370 .prepare = snd_opti93x_playback_prepare,
1371 .trigger = snd_opti93x_playback_trigger,
1372 .pointer = snd_opti93x_playback_pointer,
1375 static snd_pcm_ops_t snd_opti93x_capture_ops = {
1376 .open = snd_opti93x_capture_open,
1377 .close = snd_opti93x_capture_close,
1378 .ioctl = snd_pcm_lib_ioctl,
1379 .hw_params = snd_opti93x_hw_params,
1380 .hw_free = snd_opti93x_hw_free,
1381 .prepare = snd_opti93x_capture_prepare,
1382 .trigger = snd_opti93x_capture_trigger,
1383 .pointer = snd_opti93x_capture_pointer,
1386 static void snd_opti93x_pcm_free(snd_pcm_t *pcm)
1388 opti93x_t *codec = snd_magic_cast(opti93x_t, pcm->private_data, return);
1390 snd_pcm_lib_preallocate_free_for_all(pcm);
1393 int snd_opti93x_pcm(opti93x_t *codec, int device, snd_pcm_t **rpcm)
1398 if ((error = snd_pcm_new(codec->card, "OPTi 82C93X", device, 1, 1, &pcm)))
1401 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_opti93x_playback_ops);
1402 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_opti93x_capture_ops);
1404 pcm->private_data = codec;
1405 pcm->private_free = snd_opti93x_pcm_free;
1406 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
1408 strcpy(pcm->name, snd_opti93x_chip_id(codec));
1410 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1412 64*1024, codec->dma1 > 3 || codec->dma2 > 3 ? 128*1024 : 64*1024);
1424 static int snd_opti93x_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1426 static char *texts[4] = {
1427 "Line1", "Aux", "Mic", "Mix"
1430 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1432 uinfo->value.enumerated.items = 4;
1433 if (uinfo->value.enumerated.item > 3)
1434 uinfo->value.enumerated.item = 3;
1435 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1439 static int snd_opti93x_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1441 opti93x_t *chip = snd_kcontrol_chip(kcontrol);
1442 unsigned long flags;
1444 spin_lock_irqsave(&chip->lock, flags);
1445 ucontrol->value.enumerated.item[0] = (chip->image[OPTi93X_MIXOUT_LEFT] & OPTi93X_MIXOUT_MIXER) >> 6;
1446 ucontrol->value.enumerated.item[1] = (chip->image[OPTi93X_MIXOUT_RIGHT] & OPTi93X_MIXOUT_MIXER) >> 6;
1447 spin_unlock_irqrestore(&chip->lock, flags);
1451 static int snd_opti93x_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1453 opti93x_t *chip = snd_kcontrol_chip(kcontrol);
1454 unsigned long flags;
1455 unsigned short left, right;
1458 if (ucontrol->value.enumerated.item[0] > 3 ||
1459 ucontrol->value.enumerated.item[1] > 3)
1461 left = ucontrol->value.enumerated.item[0] << 6;
1462 right = ucontrol->value.enumerated.item[1] << 6;
1463 spin_lock_irqsave(&chip->lock, flags);
1464 left = (chip->image[OPTi93X_MIXOUT_LEFT] & ~OPTi93X_MIXOUT_MIXER) | left;
1465 right = (chip->image[OPTi93X_MIXOUT_RIGHT] & ~OPTi93X_MIXOUT_MIXER) | right;
1466 change = left != chip->image[OPTi93X_MIXOUT_LEFT] ||
1467 right != chip->image[OPTi93X_MIXOUT_RIGHT];
1468 snd_opti93x_out_image(chip, OPTi93X_MIXOUT_LEFT, left);
1469 snd_opti93x_out_image(chip, OPTi93X_MIXOUT_RIGHT, right);
1470 spin_unlock_irqrestore(&chip->lock, flags);
1476 #define OPTi93X_SINGLE(xname, xindex, reg, shift, mask, invert) \
1477 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1478 .info = snd_opti93x_info_single, \
1479 .get = snd_opti93x_get_single, .put = snd_opti93x_put_single, \
1480 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
1482 static int snd_opti93x_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1484 int mask = (kcontrol->private_value >> 16) & 0xff;
1486 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1488 uinfo->value.integer.min = 0;
1489 uinfo->value.integer.max = mask;
1493 static int snd_opti93x_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1495 opti93x_t *chip = snd_kcontrol_chip(kcontrol);
1496 unsigned long flags;
1497 int reg = kcontrol->private_value & 0xff;
1498 int shift = (kcontrol->private_value >> 8) & 0xff;
1499 int mask = (kcontrol->private_value >> 16) & 0xff;
1500 int invert = (kcontrol->private_value >> 24) & 0xff;
1502 spin_lock_irqsave(&chip->lock, flags);
1503 ucontrol->value.integer.value[0] = (chip->image[reg] >> shift) & mask;
1504 spin_unlock_irqrestore(&chip->lock, flags);
1506 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1510 static int snd_opti93x_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1512 opti93x_t *chip = snd_kcontrol_chip(kcontrol);
1513 unsigned long flags;
1514 int reg = kcontrol->private_value & 0xff;
1515 int shift = (kcontrol->private_value >> 8) & 0xff;
1516 int mask = (kcontrol->private_value >> 16) & 0xff;
1517 int invert = (kcontrol->private_value >> 24) & 0xff;
1521 val = (ucontrol->value.integer.value[0] & mask);
1525 spin_lock_irqsave(&chip->lock, flags);
1526 val = (chip->image[reg] & ~(mask << shift)) | val;
1527 change = val != chip->image[reg];
1528 snd_opti93x_out(chip, reg, val);
1529 spin_unlock_irqrestore(&chip->lock, flags);
1535 #define OPTi93X_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
1536 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1537 .info = snd_opti93x_info_double, \
1538 .get = snd_opti93x_get_double, .put = snd_opti93x_put_double, \
1539 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
1541 #define OPTi93X_DOUBLE_INVERT_INVERT(xctl) \
1542 do { xctl.private_value ^= 22; } while (0)
1543 #define OPTi93X_DOUBLE_CHANGE_REGS(xctl, left_reg, right_reg) \
1544 do { xctl.private_value &= ~0x0000ffff; \
1545 xctl.private_value |= left_reg | (right_reg << 8); } while (0)
1547 static int snd_opti93x_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1549 int mask = (kcontrol->private_value >> 24) & 0xff;
1551 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1553 uinfo->value.integer.min = 0;
1554 uinfo->value.integer.max = mask;
1558 static int snd_opti93x_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1560 opti93x_t *chip = snd_kcontrol_chip(kcontrol);
1561 unsigned long flags;
1562 int left_reg = kcontrol->private_value & 0xff;
1563 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1564 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1565 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1566 int mask = (kcontrol->private_value >> 24) & 0xff;
1567 int invert = (kcontrol->private_value >> 22) & 1;
1569 spin_lock_irqsave(&chip->lock, flags);
1570 ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask;
1571 ucontrol->value.integer.value[1] = (chip->image[right_reg] >> shift_right) & mask;
1572 spin_unlock_irqrestore(&chip->lock, flags);
1574 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1575 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
1580 static int snd_opti93x_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1582 opti93x_t *chip = snd_kcontrol_chip(kcontrol);
1583 unsigned long flags;
1584 int left_reg = kcontrol->private_value & 0xff;
1585 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1586 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1587 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1588 int mask = (kcontrol->private_value >> 24) & 0xff;
1589 int invert = (kcontrol->private_value >> 22) & 1;
1591 unsigned short val1, val2;
1593 val1 = ucontrol->value.integer.value[0] & mask;
1594 val2 = ucontrol->value.integer.value[1] & mask;
1599 val1 <<= shift_left;
1600 val2 <<= shift_right;
1601 spin_lock_irqsave(&chip->lock, flags);
1602 val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1;
1603 val2 = (chip->image[right_reg] & ~(mask << shift_right)) | val2;
1604 change = val1 != chip->image[left_reg] || val2 != chip->image[right_reg];
1605 snd_opti93x_out_image(chip, left_reg, val1);
1606 snd_opti93x_out_image(chip, right_reg, val2);
1607 spin_unlock_irqrestore(&chip->lock, flags);
1611 #define OPTi93X_CONTROLS (sizeof(snd_opti93x_controls)/sizeof(snd_kcontrol_new_t))
1613 static snd_kcontrol_new_t snd_opti93x_controls[] = {
1614 OPTi93X_DOUBLE("Master Playback Switch", 0, OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1),
1615 OPTi93X_DOUBLE("Master Playback Volume", 0, OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1),
1616 OPTi93X_DOUBLE("PCM Playback Switch", 0, OPTi93X_DAC_LEFT, OPTi93X_DAC_RIGHT, 7, 7, 1, 1),
1617 OPTi93X_DOUBLE("PCM Playback Volume", 0, OPTi93X_DAC_LEFT, OPTi93X_DAC_RIGHT, 0, 0, 31, 1),
1618 OPTi93X_DOUBLE("FM Playback Switch", 0, OPTi931_FM_LEFT_INPUT, OPTi931_FM_RIGHT_INPUT, 7, 7, 1, 1),
1619 OPTi93X_DOUBLE("FM Playback Volume", 0, OPTi931_FM_LEFT_INPUT, OPTi931_FM_RIGHT_INPUT, 1, 1, 15, 1),
1620 OPTi93X_DOUBLE("Line Playback Switch", 0, OPTi93X_LINE_LEFT_INPUT, OPTi93X_LINE_RIGHT_INPUT, 7, 7, 1, 1),
1621 OPTi93X_DOUBLE("Line Playback Volume", 0, OPTi93X_LINE_LEFT_INPUT, OPTi93X_LINE_RIGHT_INPUT, 1, 1, 15, 1),
1622 OPTi93X_DOUBLE("Mic Playback Switch", 0, OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 7, 7, 1, 1),
1623 OPTi93X_DOUBLE("Mic Playback Volume", 0, OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 1, 1, 15, 1),
1624 OPTi93X_DOUBLE("Mic Boost", 0, OPTi93X_MIXOUT_LEFT, OPTi93X_MIXOUT_RIGHT, 5, 5, 1, 1),
1625 OPTi93X_DOUBLE("CD Playback Switch", 0, OPTi93X_CD_LEFT_INPUT, OPTi93X_CD_RIGHT_INPUT, 7, 7, 1, 1),
1626 OPTi93X_DOUBLE("CD Playback Volume", 0, OPTi93X_CD_LEFT_INPUT, OPTi93X_CD_RIGHT_INPUT, 1, 1, 15, 1),
1627 OPTi93X_DOUBLE("Aux Playback Switch", 0, OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 7, 7, 1, 1),
1628 OPTi93X_DOUBLE("Aux Playback Volume", 0, OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 1, 1, 15, 1),
1629 OPTi93X_DOUBLE("Capture Volume", 0, OPTi93X_MIXOUT_LEFT, OPTi93X_MIXOUT_RIGHT, 0, 0, 15, 0),
1631 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1632 .name = "Capture Source",
1633 .info = snd_opti93x_info_mux,
1634 .get = snd_opti93x_get_mux,
1635 .put = snd_opti93x_put_mux,
1639 int snd_opti93x_mixer(opti93x_t *chip)
1642 snd_kcontrol_new_t knew;
1646 snd_assert(chip != NULL && chip->card != NULL, return -EINVAL);
1650 strcpy(card->mixername, snd_opti93x_chip_id(chip));
1652 for (idx = 0; idx < OPTi93X_CONTROLS; idx++) {
1653 knew = snd_opti93x_controls[idx];
1654 if (chip->hardware == OPTi9XX_HW_82C930) {
1655 if (strstr(knew.name, "FM")) /* skip FM controls */
1657 else if (strcmp(knew.name, "Mic Playback Volume"))
1658 OPTi93X_DOUBLE_INVERT_INVERT(knew);
1659 else if (strstr(knew.name, "Aux"))
1660 OPTi93X_DOUBLE_CHANGE_REGS(knew, OPTi930_AUX_LEFT_INPUT, OPTi930_AUX_RIGHT_INPUT);
1661 else if (strcmp(knew.name, "PCM Playback Volume"))
1662 OPTi93X_DOUBLE_INVERT_INVERT(knew);
1663 else if (strcmp(knew.name, "Master Playback Volume"))
1664 OPTi93X_DOUBLE_INVERT_INVERT(knew);
1666 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_opti93x_controls[idx], chip))) < 0)
1672 #endif /* OPTi93X */
1674 static int __devinit snd_card_opti9xx_detect(snd_card_t *card, opti9xx_t *chip)
1679 for (i = OPTi9XX_HW_82C928; i < OPTi9XX_HW_82C930; i++) {
1680 unsigned char value;
1682 if ((err = snd_opti9xx_init(chip, i)) < 0)
1685 if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL)
1688 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(1));
1689 if ((value != 0xff) && (value != inb(chip->mc_base + 1)))
1690 if (value == snd_opti9xx_read(chip, OPTi9XX_MC_REG(1)))
1693 release_resource(chip->res_mc_base);
1694 kfree_nocheck(chip->res_mc_base);
1695 chip->res_mc_base = NULL;
1699 for (i = OPTi9XX_HW_82C931; i >= OPTi9XX_HW_82C930; i--) {
1700 unsigned long flags;
1701 unsigned char value;
1703 if ((err = snd_opti9xx_init(chip, i)) < 0)
1706 if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL)
1709 spin_lock_irqsave(&chip->lock, flags);
1710 outb(chip->password, chip->mc_base + chip->pwd_reg);
1711 outb(((chip->mc_indir_index & (1 << 8)) >> 4) |
1712 ((chip->mc_indir_index & 0xf0) >> 4), chip->mc_base);
1713 spin_unlock_irqrestore(&chip->lock, flags);
1715 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(7));
1716 snd_opti9xx_write(chip, OPTi9XX_MC_REG(7), 0xff - value);
1717 if (snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)) == 0xff - value)
1720 release_resource(chip->res_mc_base);
1721 kfree_nocheck(chip->res_mc_base);
1722 chip->res_mc_base = NULL;
1724 #endif /* OPTi93X */
1730 static int __devinit snd_card_opti9xx_pnp(opti9xx_t *chip, struct pnp_card_link *card,
1731 const struct pnp_card_device_id *pid)
1733 struct pnp_dev *pdev;
1734 struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
1737 chip->dev = pnp_request_card_device(card, pid->devs[0].id, NULL);
1738 if (chip->dev == NULL) {
1742 chip->devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
1745 pnp_init_resource_table(cfg);
1748 if (port != SNDRV_AUTO_PORT)
1749 pnp_resource_change(&cfg->port_resource[0], port + 4, 4);
1751 if (pid->driver_data != 0x0924 && port != SNDRV_AUTO_PORT)
1752 pnp_resource_change(&cfg->port_resource[1], port, 4);
1753 #endif /* OPTi93X */
1754 if (irq != SNDRV_AUTO_IRQ)
1755 pnp_resource_change(&cfg->irq_resource[0], irq, 1);
1756 if (dma1 != SNDRV_AUTO_DMA)
1757 pnp_resource_change(&cfg->dma_resource[0], dma1, 1);
1758 #if defined(CS4231) || defined(OPTi93X)
1759 if (dma2 != SNDRV_AUTO_DMA)
1760 pnp_resource_change(&cfg->dma_resource[1], dma2, 1);
1762 #ifdef snd_opti9xx_fixup_dma2
1763 snd_opti9xx_fixup_dma2(pdev);
1765 #endif /* CS4231 || OPTi93X */
1767 if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT)
1768 pnp_resource_change(&cfg->port_resource[1], fm_port, 4);
1770 if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT)
1771 pnp_resource_change(&cfg->port_resource[2], fm_port, 4);
1773 if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
1774 snd_printk(KERN_ERR "AUDIO the requested resources are invalid, using auto config\n");
1775 err = pnp_activate_dev(pdev);
1777 snd_printk(KERN_ERR "AUDIO pnp configure failure: %d\n", err);
1783 port = pnp_port_start(pdev, 0) - 4;
1784 fm_port = pnp_port_start(pdev, 1);
1786 if (pid->driver_data != 0x0924)
1787 port = pnp_port_start(pdev, 1);
1788 fm_port = pnp_port_start(pdev, 2);
1789 #endif /* OPTi93X */
1790 irq = pnp_irq(pdev, 0);
1791 dma1 = pnp_dma(pdev, 0);
1792 #if defined(CS4231) || defined(OPTi93X)
1793 dma2 = pnp_dma(pdev, 1);
1794 #endif /* CS4231 || OPTi93X */
1796 pdev = chip->devmpu;
1797 if (pdev && mpu_port > 0) {
1798 pnp_init_resource_table(cfg);
1800 if (mpu_port != SNDRV_AUTO_PORT)
1801 pnp_resource_change(&cfg->port_resource[0], mpu_port, 2);
1802 if (mpu_irq != SNDRV_AUTO_IRQ)
1803 pnp_resource_change(&cfg->irq_resource[0], mpu_irq, 1);
1805 if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
1806 snd_printk(KERN_ERR "AUDIO the requested resources are invalid, using auto config\n");
1807 err = pnp_activate_dev(pdev);
1809 snd_printk(KERN_ERR "AUDIO pnp configure failure\n");
1811 chip->devmpu = NULL;
1813 mpu_port = pnp_port_start(pdev, 0);
1814 mpu_irq = pnp_irq(pdev, 0);
1818 return pid->driver_data;
1820 #endif /* CONFIG_PNP */
1823 static int __devinit snd_card_opti9xx_resources(struct snd_card_opti9xx *chip,
1826 int error, i, pnp = 0;
1829 pnp = chip->dev != NULL;
1830 #endif /* CONFIG_PNP */
1833 if (chip->chip->hardware == OPTi9XX_HW_82C928)
1835 #endif /* OPTi93X */
1837 if (!pnp && (mpu_port == SNDRV_DEFAULT_PORT1)) {
1838 for (i = 0; possible_mpu_ports[i] != -1; i++)
1839 if (!snd_register_ioport(card, possible_mpu_ports[i], 2,
1840 DRIVER_NAME" - MPU-401", NULL)) {
1841 mpu_port = possible_mpu_ports[i];
1844 if (mpu_port == SNDRV_DEFAULT_PORT1)
1848 error = (mpu_port == -1) ? -ENODEV :
1849 snd_register_ioport(card, mpu_port, 2,
1850 DRIVER_NAME" - MPU-401", NULL);
1852 chip->chip->mpu_port = -1;
1853 else if (pnp && (irq == mpu_irq))
1854 chip->chip->mpu_irq = mpu_irq;
1855 else if (!snd_register_interrupt(card,
1856 DRIVER_NAME" - MPU-401",
1857 mpu_irq, SNDRV_IRQ_TYPE_ISA,
1858 snd_card_opti9xx_mpu_interrupt, chip,
1859 pnp ? no_alternatives : possible_mpu_irqs,
1860 &chip->mpuirqptr)) {
1861 chip->chip->mpu_port = mpu_port;
1862 chip->chip->mpu_irq = chip->mpuirqptr->irq;
1865 chip->chip->mpu_port = -1;
1867 if (!pnp && (port == SNDRV_DEFAULT_PORT1)) {
1868 for (i = 0; possible_ports[i] != -1; i++)
1869 if (!snd_register_ioport(card, possible_ports[i], 8,
1870 DRIVER_NAME" - WSS", NULL)) {
1871 port = possible_ports[i];
1874 if (port == SNDRV_DEFAULT_PORT1)
1877 else if ((error = snd_register_ioport(card, port, 8,
1878 DRIVER_NAME" - WSS", NULL)) < 0)
1880 chip->chip->wss_base = port;
1881 if ((error = snd_register_interrupt(card, DRIVER_NAME" - WSS",
1882 irq, SNDRV_IRQ_TYPE_ISA,
1883 snd_card_opti9xx_interrupt, chip,
1884 pnp ? no_alternatives : possible_irqs,
1885 &chip->irqptr)) < 0)
1887 chip->chip->irq = chip->irqptr->irq;
1888 if ((error = snd_register_dma_channel(card,
1889 #if defined(CS4231) || defined(OPTi93X)
1890 DRIVER_NAME" - WSS playback",
1892 DRIVER_NAME" - WSS",
1893 #endif /* CS4231 || OPTi93X */
1894 dma1, SNDRV_DMA_TYPE_ISA, dma1_size,
1895 pnp ? no_alternatives : possible_dma1s,
1896 &chip->dma1ptr)) < 0)
1898 chip->chip->dma1 = chip->dma1ptr->dma;
1899 #if defined(CS4231) || defined(OPTi93X)
1900 if ((error = snd_register_dma_channel(card, DRIVER_NAME" - WSS capture",
1901 dma2, SNDRV_DMA_TYPE_ISA, dma2_size,
1902 pnp ? no_alternatives :
1903 possible_dma2s[chip->dma1ptr->dma],
1904 &chip->dma2ptr)) < 0)
1906 chip->chip->dma2 = chip->dma2ptr->dma;
1907 #endif /* CS4231 || OPTi93X */
1909 if (snd_register_ioport(card,
1910 pnp ? fm_port : fm_port = 0x388, 4,
1911 DRIVER_NAME" - OPL", NULL) < 0)
1913 chip->chip->fm_port = fm_port;
1919 static void snd_card_opti9xx_free(snd_card_t *card)
1921 opti9xx_t *chip = (opti9xx_t *)card->private_data;
1924 if (chip->res_mc_base) {
1925 release_resource(chip->res_mc_base);
1926 kfree_nocheck(chip->res_mc_base);
1931 static int __devinit snd_card_opti9xx_probe(struct pnp_card_link *pcard,
1932 const struct pnp_card_device_id *pid)
1934 static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
1935 static long possible_mpu_ports[] = {0x300, 0x310, 0x320, 0x330, -1};
1937 static int possible_irqs[] = {5, 9, 10, 11, 7, -1};
1939 static int possible_irqs[] = {9, 10, 11, 7, -1};
1940 #endif /* OPTi93X */
1941 static int possible_mpu_irqs[] = {5, 9, 10, 7, -1};
1942 static int possible_dma1s[] = {3, 1, 0, -1};
1943 #if defined(CS4231) || defined(OPTi93X)
1944 static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};
1945 #endif /* CS4231 || OPTi93X */
1948 #if defined(OPTi93X)
1950 #elif defined(CS4231)
1958 snd_rawmidi_t *rmidi;
1962 #endif /* CONFIG_PNP */
1964 if (pcard && !snd_opti9xx_first_hit)
1966 if (!(card = snd_card_new(index, id, THIS_MODULE,
1967 sizeof(opti9xx_t))))
1969 card->private_free = snd_card_opti9xx_free;
1970 chip = (opti9xx_t *)card->private_data;
1973 if (isapnp && pcard && (hw = snd_card_opti9xx_pnp(chip, pcard, pid)) > 0) {
1976 hw = OPTi9XX_HW_82C924;
1979 hw = OPTi9XX_HW_82C925;
1982 hw = OPTi9XX_HW_82C931;
1985 snd_card_free(card);
1989 if ((error = snd_opti9xx_init(chip, hw))) {
1990 snd_card_free(card);
1993 if (hw <= OPTi9XX_HW_82C930)
1994 chip->mc_base -= 0x80;
1995 snd_card_set_dev(card, &pcard->card->dev);
1997 #endif /* CONFIG_PNP */
1998 if ((error = snd_card_opti9xx_detect(card, chip)) < 0) {
1999 snd_card_free(card);
2004 #endif /* CONFIG_PNP */
2006 if (! chip->res_mc_base &&
2007 (chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL) {
2008 snd_card_free(card);
2012 chip->wss_base = port;
2013 chip->fm_port = fm_port;
2014 chip->mpu_port = mpu_port;
2016 chip->mpu_irq = mpu_irq;
2018 #if defined(CS4231) || defined(OPTi93X)
2022 if (chip->wss_base == SNDRV_AUTO_PORT) {
2023 if ((chip->wss_base = snd_legacy_find_free_ioport(possible_ports, 4)) < 0) {
2024 snd_card_free(card);
2025 snd_printk("unable to find a free WSS port\n");
2032 if (chip->mpu_port == SNDRV_AUTO_PORT) {
2033 if ((chip->mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) {
2034 snd_card_free(card);
2035 snd_printk("unable to find a free MPU401 port\n");
2039 if (chip->irq == SNDRV_AUTO_IRQ) {
2040 if ((chip->irq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
2041 snd_card_free(card);
2042 snd_printk("unable to find a free IRQ\n");
2046 if (chip->mpu_irq == SNDRV_AUTO_IRQ) {
2047 if ((chip->mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) {
2048 snd_card_free(card);
2049 snd_printk("unable to find a free MPU401 IRQ\n");
2053 if (chip->dma1 == SNDRV_AUTO_DMA) {
2054 if ((chip->dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) {
2055 snd_card_free(card);
2056 snd_printk("unable to find a free DMA1\n");
2060 #if defined(CS4231) || defined(OPTi93X)
2061 if (chip->dma2 == SNDRV_AUTO_DMA) {
2062 if ((chip->dma2 = snd_legacy_find_free_dma(possible_dma2s[chip->dma1 % 4])) < 0) {
2063 snd_card_free(card);
2064 snd_printk("unable to find a free DMA2\n");
2074 if ((error = snd_opti9xx_configure(chip))) {
2075 snd_card_free(card);
2079 #if defined(OPTi93X)
2080 if ((error = snd_opti93x_create(card, chip, chip->dma1, chip->dma2, &codec))) {
2081 snd_card_free(card);
2084 if ((error = snd_opti93x_pcm(codec, 0, &pcm)) < 0) {
2085 snd_card_free(card);
2088 if ((error = snd_opti93x_mixer(codec)) < 0) {
2089 snd_card_free(card);
2092 #elif defined(CS4231)
2093 if ((error = snd_cs4231_create(card, chip->wss_base + 4, -1,
2094 chip->irq, chip->dma1, chip->dma2,
2098 snd_card_free(card);
2101 if ((error = snd_cs4231_pcm(codec, 0, &pcm)) < 0) {
2102 snd_card_free(card);
2105 if ((error = snd_cs4231_mixer(codec)) < 0) {
2106 snd_card_free(card);
2109 if ((error = snd_cs4231_timer(codec, 0, &timer)) < 0) {
2110 snd_card_free(card);
2114 if ((error = snd_ad1848_create(card, chip->wss_base + 4,
2115 chip->irq, chip->dma1,
2116 AD1848_HW_DETECT, &codec)) < 0) {
2117 snd_card_free(card);
2120 if ((error = snd_ad1848_pcm(codec, 0, &pcm)) < 0) {
2121 snd_card_free(card);
2124 if ((error = snd_ad1848_mixer(codec)) < 0) {
2125 snd_card_free(card);
2129 strcpy(card->driver, chip->name);
2130 sprintf(card->shortname, "OPTi %s", card->driver);
2131 #if defined(CS4231) || defined(OPTi93X)
2132 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d",
2133 card->shortname, pcm->name, chip->wss_base + 4,
2134 chip->irq, chip->dma1, chip->dma2);
2136 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
2137 card->shortname, pcm->name, chip->wss_base + 4,
2138 chip->irq, chip->dma1);
2139 #endif /* CS4231 || OPTi93X */
2141 if (chip->mpu_port <= 0 || chip->mpu_port == SNDRV_AUTO_PORT)
2144 if ((error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
2145 chip->mpu_port, 0, chip->mpu_irq, SA_INTERRUPT,
2147 snd_printk("no MPU-401 device at 0x%lx?\n", chip->mpu_port);
2149 if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) {
2150 opl3_t *opl3 = NULL;
2152 if (chip->hardware == OPTi9XX_HW_82C928 ||
2153 chip->hardware == OPTi9XX_HW_82C929 ||
2154 chip->hardware == OPTi9XX_HW_82C924) {
2156 /* assume we have an OPL4 */
2157 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
2159 if (snd_opl4_create(card,
2162 2, &opl3, &opl4) < 0) {
2163 /* no luck, use OPL3 instead */
2164 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
2168 #endif /* !OPTi93X */
2169 if (!opl3 && snd_opl3_create(card,
2172 OPL3_HW_AUTO, 0, &opl3) < 0) {
2173 snd_printk("no OPL device at 0x%lx-0x%lx\n",
2174 chip->fm_port, chip->fm_port + 4 - 1);
2177 if ((error = snd_opl3_timer_new(opl3,
2183 snd_card_free(card);
2186 if ((error = snd_opl3_hwdep_new(opl3, 0, 1, &synth)) < 0) {
2187 snd_card_free(card);
2193 if ((error = snd_card_register(card))) {
2194 snd_card_free(card);
2197 snd_opti9xx_first_hit = 0;
2199 pnp_set_card_drvdata(pcard, card);
2201 snd_opti9xx_legacy = card;
2206 static void __devexit snd_opti9xx_pnp_remove(struct pnp_card_link * pcard)
2208 snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
2210 snd_card_disconnect(card);
2211 snd_card_free_in_thread(card);
2212 snd_opti9xx_first_hit = 0;
2215 static struct pnp_card_driver opti9xx_pnpc_driver = {
2216 .flags = PNP_DRIVER_RES_DISABLE,
2218 .id_table = snd_opti9xx_pnpids,
2219 .probe = snd_card_opti9xx_probe,
2220 .remove = __devexit_p(snd_opti9xx_pnp_remove),
2224 static int __init alsa_card_opti9xx_init(void)
2229 cards = pnp_register_card_driver(&opti9xx_pnpc_driver);
2233 if (cards == 0 && (error = snd_card_opti9xx_probe(NULL, NULL)) < 0) {
2235 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
2239 printk(KERN_ERR "no OPTi 82C93x soundcard found\n");
2241 printk(KERN_ERR "no OPTi 82C92x soundcard found\n");
2242 #endif /* OPTi93X */
2249 static void __exit alsa_card_opti9xx_exit(void)
2252 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
2254 if (snd_opti9xx_legacy)
2255 snd_card_free(snd_opti9xx_legacy);
2258 module_init(alsa_card_opti9xx_init)
2259 module_exit(alsa_card_opti9xx_exit)