2 * ALSA driver for VIA VT82xx (South Bridge)
4 * VT82C686A/B/C, VT8233A/C, VT8235
6 * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
7 * Tjeerd.Mulder <Tjeerd.Mulder@fujitsu-siemens.com>
8 * 2002 Takashi Iwai <tiwai@suse.de>
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
29 * Dec. 19, 2002 Takashi Iwai <tiwai@suse.de>
30 * - use the DSX channels for the first pcm playback.
31 * (on VIA8233, 8233C and 8235 only)
32 * this will allow you play simultaneously up to 4 streams.
33 * multi-channel playback is assigned to the second device
35 * - support the secondary capture (on VIA8233/C,8235)
37 * the DSX3 channel can be used for SPDIF output.
38 * on VIA8233A, this channel is assigned to the second pcm
40 * the card config of alsa-lib will assign the correct
41 * device for applications.
42 * - clean up the code, separate low-level initialization
43 * routines for each chipset.
45 * Sep. 26, 2005 Karsten Wiese <annabellesgarden@yahoo.de>
46 * - Optimize position calculation for the 823x chips.
50 #include <linux/delay.h>
51 #include <linux/interrupt.h>
52 #include <linux/init.h>
53 #include <linux/pci.h>
54 #include <linux/slab.h>
55 #include <linux/gameport.h>
56 #include <linux/module.h>
57 #include <sound/core.h>
58 #include <sound/pcm.h>
59 #include <sound/pcm_params.h>
60 #include <sound/info.h>
61 #include <sound/tlv.h>
62 #include <sound/ac97_codec.h>
63 #include <sound/mpu401.h>
64 #include <sound/initval.h>
70 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
71 MODULE_DESCRIPTION("VIA VT82xx audio");
72 MODULE_LICENSE("GPL");
73 MODULE_SUPPORTED_DEVICE("{{VIA,VT82C686A/B/C,pci},{VIA,VT8233A/C,8235}}");
75 #if IS_REACHABLE(CONFIG_GAMEPORT)
76 #define SUPPORT_JOYSTICK 1
79 static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
80 static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
82 #ifdef SUPPORT_JOYSTICK
85 static int ac97_clock = 48000;
86 static char *ac97_quirk;
87 static int dxs_support;
88 static int dxs_init_volume = 31;
91 module_param(index, int, 0444);
92 MODULE_PARM_DESC(index, "Index value for VIA 82xx bridge.");
93 module_param(id, charp, 0444);
94 MODULE_PARM_DESC(id, "ID string for VIA 82xx bridge.");
95 module_param_hw(mpu_port, long, ioport, 0444);
96 MODULE_PARM_DESC(mpu_port, "MPU-401 port. (VT82C686x only)");
97 #ifdef SUPPORT_JOYSTICK
98 module_param(joystick, bool, 0444);
99 MODULE_PARM_DESC(joystick, "Enable joystick. (VT82C686x only)");
101 module_param(ac97_clock, int, 0444);
102 MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz).");
103 module_param(ac97_quirk, charp, 0444);
104 MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware.");
105 module_param(dxs_support, int, 0444);
106 MODULE_PARM_DESC(dxs_support, "Support for DXS channels (0 = auto, 1 = enable, 2 = disable, 3 = 48k only, 4 = no VRA, 5 = enable any sample rate)");
107 module_param(dxs_init_volume, int, 0644);
108 MODULE_PARM_DESC(dxs_init_volume, "initial DXS volume (0-31)");
109 module_param(nodelay, int, 0444);
110 MODULE_PARM_DESC(nodelay, "Disable 500ms init delay");
112 /* just for backward compatibility */
114 module_param(enable, bool, 0444);
117 /* revision numbers for via686 */
118 #define VIA_REV_686_A 0x10
119 #define VIA_REV_686_B 0x11
120 #define VIA_REV_686_C 0x12
121 #define VIA_REV_686_D 0x13
122 #define VIA_REV_686_E 0x14
123 #define VIA_REV_686_H 0x20
125 /* revision numbers for via8233 */
126 #define VIA_REV_PRE_8233 0x10 /* not in market */
127 #define VIA_REV_8233C 0x20 /* 2 rec, 4 pb, 1 multi-pb */
128 #define VIA_REV_8233 0x30 /* 2 rec, 4 pb, 1 multi-pb, spdif */
129 #define VIA_REV_8233A 0x40 /* 1 rec, 1 multi-pb, spdf */
130 #define VIA_REV_8235 0x50 /* 2 rec, 4 pb, 1 multi-pb, spdif */
131 #define VIA_REV_8237 0x60
132 #define VIA_REV_8251 0x70
138 #define VIAREG(via, x) ((via)->port + VIA_REG_##x)
139 #define VIADEV_REG(viadev, x) ((viadev)->port + VIA_REG_##x)
142 #define VIA_REG_OFFSET_STATUS 0x00 /* byte - channel status */
143 #define VIA_REG_STAT_ACTIVE 0x80 /* RO */
144 #define VIA8233_SHADOW_STAT_ACTIVE 0x08 /* RO */
145 #define VIA_REG_STAT_PAUSED 0x40 /* RO */
146 #define VIA_REG_STAT_TRIGGER_QUEUED 0x08 /* RO */
147 #define VIA_REG_STAT_STOPPED 0x04 /* RWC */
148 #define VIA_REG_STAT_EOL 0x02 /* RWC */
149 #define VIA_REG_STAT_FLAG 0x01 /* RWC */
150 #define VIA_REG_OFFSET_CONTROL 0x01 /* byte - channel control */
151 #define VIA_REG_CTRL_START 0x80 /* WO */
152 #define VIA_REG_CTRL_TERMINATE 0x40 /* WO */
153 #define VIA_REG_CTRL_AUTOSTART 0x20
154 #define VIA_REG_CTRL_PAUSE 0x08 /* RW */
155 #define VIA_REG_CTRL_INT_STOP 0x04
156 #define VIA_REG_CTRL_INT_EOL 0x02
157 #define VIA_REG_CTRL_INT_FLAG 0x01
158 #define VIA_REG_CTRL_RESET 0x01 /* RW - probably reset? undocumented */
159 #define VIA_REG_CTRL_INT (VIA_REG_CTRL_INT_FLAG | VIA_REG_CTRL_INT_EOL | VIA_REG_CTRL_AUTOSTART)
160 #define VIA_REG_OFFSET_TYPE 0x02 /* byte - channel type (686 only) */
161 #define VIA_REG_TYPE_AUTOSTART 0x80 /* RW - autostart at EOL */
162 #define VIA_REG_TYPE_16BIT 0x20 /* RW */
163 #define VIA_REG_TYPE_STEREO 0x10 /* RW */
164 #define VIA_REG_TYPE_INT_LLINE 0x00
165 #define VIA_REG_TYPE_INT_LSAMPLE 0x04
166 #define VIA_REG_TYPE_INT_LESSONE 0x08
167 #define VIA_REG_TYPE_INT_MASK 0x0c
168 #define VIA_REG_TYPE_INT_EOL 0x02
169 #define VIA_REG_TYPE_INT_FLAG 0x01
170 #define VIA_REG_OFFSET_TABLE_PTR 0x04 /* dword - channel table pointer */
171 #define VIA_REG_OFFSET_CURR_PTR 0x04 /* dword - channel current pointer */
172 #define VIA_REG_OFFSET_STOP_IDX 0x08 /* dword - stop index, channel type, sample rate */
173 #define VIA8233_REG_TYPE_16BIT 0x00200000 /* RW */
174 #define VIA8233_REG_TYPE_STEREO 0x00100000 /* RW */
175 #define VIA_REG_OFFSET_CURR_COUNT 0x0c /* dword - channel current count (24 bit) */
176 #define VIA_REG_OFFSET_CURR_INDEX 0x0f /* byte - channel current index (for via8233 only) */
178 #define DEFINE_VIA_REGSET(name,val) \
180 VIA_REG_##name##_STATUS = (val),\
181 VIA_REG_##name##_CONTROL = (val) + 0x01,\
182 VIA_REG_##name##_TYPE = (val) + 0x02,\
183 VIA_REG_##name##_TABLE_PTR = (val) + 0x04,\
184 VIA_REG_##name##_CURR_PTR = (val) + 0x04,\
185 VIA_REG_##name##_STOP_IDX = (val) + 0x08,\
186 VIA_REG_##name##_CURR_COUNT = (val) + 0x0c,\
190 DEFINE_VIA_REGSET(PLAYBACK, 0x00);
191 DEFINE_VIA_REGSET(CAPTURE, 0x10);
192 DEFINE_VIA_REGSET(FM, 0x20);
195 #define VIA_REG_AC97 0x80 /* dword */
196 #define VIA_REG_AC97_CODEC_ID_MASK (3<<30)
197 #define VIA_REG_AC97_CODEC_ID_SHIFT 30
198 #define VIA_REG_AC97_CODEC_ID_PRIMARY 0x00
199 #define VIA_REG_AC97_CODEC_ID_SECONDARY 0x01
200 #define VIA_REG_AC97_SECONDARY_VALID (1<<27)
201 #define VIA_REG_AC97_PRIMARY_VALID (1<<25)
202 #define VIA_REG_AC97_BUSY (1<<24)
203 #define VIA_REG_AC97_READ (1<<23)
204 #define VIA_REG_AC97_CMD_SHIFT 16
205 #define VIA_REG_AC97_CMD_MASK 0x7e
206 #define VIA_REG_AC97_DATA_SHIFT 0
207 #define VIA_REG_AC97_DATA_MASK 0xffff
209 #define VIA_REG_SGD_SHADOW 0x84 /* dword */
211 #define VIA_REG_SGD_STAT_PB_FLAG (1<<0)
212 #define VIA_REG_SGD_STAT_CP_FLAG (1<<1)
213 #define VIA_REG_SGD_STAT_FM_FLAG (1<<2)
214 #define VIA_REG_SGD_STAT_PB_EOL (1<<4)
215 #define VIA_REG_SGD_STAT_CP_EOL (1<<5)
216 #define VIA_REG_SGD_STAT_FM_EOL (1<<6)
217 #define VIA_REG_SGD_STAT_PB_STOP (1<<8)
218 #define VIA_REG_SGD_STAT_CP_STOP (1<<9)
219 #define VIA_REG_SGD_STAT_FM_STOP (1<<10)
220 #define VIA_REG_SGD_STAT_PB_ACTIVE (1<<12)
221 #define VIA_REG_SGD_STAT_CP_ACTIVE (1<<13)
222 #define VIA_REG_SGD_STAT_FM_ACTIVE (1<<14)
224 #define VIA8233_REG_SGD_STAT_FLAG (1<<0)
225 #define VIA8233_REG_SGD_STAT_EOL (1<<1)
226 #define VIA8233_REG_SGD_STAT_STOP (1<<2)
227 #define VIA8233_REG_SGD_STAT_ACTIVE (1<<3)
228 #define VIA8233_INTR_MASK(chan) ((VIA8233_REG_SGD_STAT_FLAG|VIA8233_REG_SGD_STAT_EOL) << ((chan) * 4))
229 #define VIA8233_REG_SGD_CHAN_SDX 0
230 #define VIA8233_REG_SGD_CHAN_MULTI 4
231 #define VIA8233_REG_SGD_CHAN_REC 6
232 #define VIA8233_REG_SGD_CHAN_REC1 7
234 #define VIA_REG_GPI_STATUS 0x88
235 #define VIA_REG_GPI_INTR 0x8c
237 /* multi-channel and capture registers for via8233 */
238 DEFINE_VIA_REGSET(MULTPLAY, 0x40);
239 DEFINE_VIA_REGSET(CAPTURE_8233, 0x60);
241 /* via8233-specific registers */
242 #define VIA_REG_OFS_PLAYBACK_VOLUME_L 0x02 /* byte */
243 #define VIA_REG_OFS_PLAYBACK_VOLUME_R 0x03 /* byte */
244 #define VIA_REG_OFS_MULTPLAY_FORMAT 0x02 /* byte - format and channels */
245 #define VIA_REG_MULTPLAY_FMT_8BIT 0x00
246 #define VIA_REG_MULTPLAY_FMT_16BIT 0x80
247 #define VIA_REG_MULTPLAY_FMT_CH_MASK 0x70 /* # channels << 4 (valid = 1,2,4,6) */
248 #define VIA_REG_OFS_CAPTURE_FIFO 0x02 /* byte - bit 6 = fifo enable */
249 #define VIA_REG_CAPTURE_FIFO_ENABLE 0x40
251 #define VIA_DXS_MAX_VOLUME 31 /* max. volume (attenuation) of reg 0x32/33 */
253 #define VIA_REG_CAPTURE_CHANNEL 0x63 /* byte - input select */
254 #define VIA_REG_CAPTURE_CHANNEL_MIC 0x4
255 #define VIA_REG_CAPTURE_CHANNEL_LINE 0
256 #define VIA_REG_CAPTURE_SELECT_CODEC 0x03 /* recording source codec (0 = primary) */
258 #define VIA_TBL_BIT_FLAG 0x40000000
259 #define VIA_TBL_BIT_EOL 0x80000000
262 #define VIA_ACLINK_STAT 0x40
263 #define VIA_ACLINK_C11_READY 0x20
264 #define VIA_ACLINK_C10_READY 0x10
265 #define VIA_ACLINK_C01_READY 0x04 /* secondary codec ready */
266 #define VIA_ACLINK_LOWPOWER 0x02 /* low-power state */
267 #define VIA_ACLINK_C00_READY 0x01 /* primary codec ready */
268 #define VIA_ACLINK_CTRL 0x41
269 #define VIA_ACLINK_CTRL_ENABLE 0x80 /* 0: disable, 1: enable */
270 #define VIA_ACLINK_CTRL_RESET 0x40 /* 0: assert, 1: de-assert */
271 #define VIA_ACLINK_CTRL_SYNC 0x20 /* 0: release SYNC, 1: force SYNC hi */
272 #define VIA_ACLINK_CTRL_SDO 0x10 /* 0: release SDO, 1: force SDO hi */
273 #define VIA_ACLINK_CTRL_VRA 0x08 /* 0: disable VRA, 1: enable VRA */
274 #define VIA_ACLINK_CTRL_PCM 0x04 /* 0: disable PCM, 1: enable PCM */
275 #define VIA_ACLINK_CTRL_FM 0x02 /* via686 only */
276 #define VIA_ACLINK_CTRL_SB 0x01 /* via686 only */
277 #define VIA_ACLINK_CTRL_INIT (VIA_ACLINK_CTRL_ENABLE|\
278 VIA_ACLINK_CTRL_RESET|\
279 VIA_ACLINK_CTRL_PCM|\
281 #define VIA_FUNC_ENABLE 0x42
282 #define VIA_FUNC_MIDI_PNP 0x80 /* FIXME: it's 0x40 in the datasheet! */
283 #define VIA_FUNC_MIDI_IRQMASK 0x40 /* FIXME: not documented! */
284 #define VIA_FUNC_RX2C_WRITE 0x20
285 #define VIA_FUNC_SB_FIFO_EMPTY 0x10
286 #define VIA_FUNC_ENABLE_GAME 0x08
287 #define VIA_FUNC_ENABLE_FM 0x04
288 #define VIA_FUNC_ENABLE_MIDI 0x02
289 #define VIA_FUNC_ENABLE_SB 0x01
290 #define VIA_PNP_CONTROL 0x43
291 #define VIA_FM_NMI_CTRL 0x48
292 #define VIA8233_VOLCHG_CTRL 0x48
293 #define VIA8233_SPDIF_CTRL 0x49
294 #define VIA8233_SPDIF_DX3 0x08
295 #define VIA8233_SPDIF_SLOT_MASK 0x03
296 #define VIA8233_SPDIF_SLOT_1011 0x00
297 #define VIA8233_SPDIF_SLOT_34 0x01
298 #define VIA8233_SPDIF_SLOT_78 0x02
299 #define VIA8233_SPDIF_SLOT_69 0x03
304 #define VIA_DXS_AUTO 0
305 #define VIA_DXS_ENABLE 1
306 #define VIA_DXS_DISABLE 2
307 #define VIA_DXS_48K 3
308 #define VIA_DXS_NO_VRA 4
309 #define VIA_DXS_SRC 5
316 struct snd_via_sg_table {
321 #define VIA_TABLE_SIZE 255
322 #define VIA_MAX_BUFSIZE (1<<24)
325 unsigned int reg_offset;
327 int direction; /* playback = 0, capture = 1 */
328 struct snd_pcm_substream *substream;
330 unsigned int tbl_entries; /* # descriptors */
331 struct snd_dma_buffer table;
332 struct snd_via_sg_table *idx_table;
333 /* for recovery from the unexpected pointer */
334 unsigned int lastpos;
335 unsigned int fragsize;
336 unsigned int bufsize;
337 unsigned int bufsize2;
338 int hwptr_done; /* processed frame position in the buffer */
344 enum { TYPE_CARD_VIA686 = 1, TYPE_CARD_VIA8233 };
345 enum { TYPE_VIA686, TYPE_VIA8233, TYPE_VIA8233A };
347 #define VIA_MAX_DEVS 7 /* 4 playback, 1 multi, 2 capture */
349 struct via_rate_lock {
359 struct resource *mpu_res;
361 unsigned char revision;
363 unsigned char old_legacy;
364 unsigned char old_legacy_cfg;
365 #ifdef CONFIG_PM_SLEEP
366 unsigned char legacy_saved;
367 unsigned char legacy_cfg_saved;
368 unsigned char spdif_ctrl_saved;
369 unsigned char capture_src_saved[2];
370 unsigned int mpu_port_saved;
373 unsigned char playback_volume[4][2]; /* for VIA8233/C/8235; default = 0 */
374 unsigned char playback_volume_c[2]; /* for VIA8233/C/8235; default = 0 */
376 unsigned int intr_mask; /* SGD_SHADOW mask to check interrupts */
379 struct snd_card *card;
381 unsigned int num_devs;
382 unsigned int playback_devno, multi_devno, capture_devno;
383 struct viadev devs[VIA_MAX_DEVS];
384 struct via_rate_lock rates[2]; /* playback and capture */
385 unsigned int dxs_fixed: 1; /* DXS channel accepts only 48kHz */
386 unsigned int no_vra: 1; /* no need to set VRA on DXS channels */
387 unsigned int dxs_src: 1; /* use full SRC capabilities of DXS */
388 unsigned int spdif_on: 1; /* only spdif rates work to external DACs */
390 struct snd_pcm *pcms[2];
391 struct snd_rawmidi *rmidi;
392 struct snd_kcontrol *dxs_controls[4];
394 struct snd_ac97_bus *ac97_bus;
395 struct snd_ac97 *ac97;
396 unsigned int ac97_clock;
397 unsigned int ac97_secondary; /* secondary AC'97 codec is present */
400 struct snd_info_entry *proc_entry;
402 #ifdef SUPPORT_JOYSTICK
403 struct gameport *gameport;
407 static const struct pci_device_id snd_via82xx_ids[] = {
409 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_82C686_5), TYPE_CARD_VIA686, }, /* 686A */
411 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_8233_5), TYPE_CARD_VIA8233, }, /* VT8233 */
415 MODULE_DEVICE_TABLE(pci, snd_via82xx_ids);
421 * allocate and initialize the descriptor buffers
422 * periods = number of periods
423 * fragsize = period size in bytes
425 static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substream,
427 unsigned int periods, unsigned int fragsize)
429 unsigned int i, idx, ofs, rest;
430 struct via82xx *chip = snd_pcm_substream_chip(substream);
432 if (dev->table.area == NULL) {
433 /* the start of each lists must be aligned to 8 bytes,
434 * but the kernel pages are much bigger, so we don't care
436 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
437 PAGE_ALIGN(VIA_TABLE_SIZE * 2 * 8),
441 if (! dev->idx_table) {
442 dev->idx_table = kmalloc_array(VIA_TABLE_SIZE,
443 sizeof(*dev->idx_table),
445 if (! dev->idx_table)
449 /* fill the entries */
452 for (i = 0; i < periods; i++) {
454 /* fill descriptors for a period.
455 * a period can be split to several descriptors if it's
456 * over page boundary.
463 if (idx >= VIA_TABLE_SIZE) {
464 dev_err(&pci->dev, "too much table size!\n");
467 addr = snd_pcm_sgbuf_get_addr(substream, ofs);
468 ((u32 *)dev->table.area)[idx << 1] = cpu_to_le32(addr);
469 r = snd_pcm_sgbuf_get_chunk_size(substream, ofs, rest);
472 if (i == periods - 1)
473 flag = VIA_TBL_BIT_EOL; /* buffer boundary */
475 flag = VIA_TBL_BIT_FLAG; /* period boundary */
477 flag = 0; /* period continues to the next */
480 "tbl %d: at %d size %d (rest %d)\n",
483 ((u32 *)dev->table.area)[(idx<<1) + 1] = cpu_to_le32(r | flag);
484 dev->idx_table[idx].offset = ofs;
485 dev->idx_table[idx].size = r;
490 dev->tbl_entries = idx;
491 dev->bufsize = periods * fragsize;
492 dev->bufsize2 = dev->bufsize / 2;
493 dev->fragsize = fragsize;
498 static int clean_via_table(struct viadev *dev, struct snd_pcm_substream *substream,
501 if (dev->table.area) {
502 snd_dma_free_pages(&dev->table);
503 dev->table.area = NULL;
505 kfree(dev->idx_table);
506 dev->idx_table = NULL;
514 static inline unsigned int snd_via82xx_codec_xread(struct via82xx *chip)
516 return inl(VIAREG(chip, AC97));
519 static inline void snd_via82xx_codec_xwrite(struct via82xx *chip, unsigned int val)
521 outl(val, VIAREG(chip, AC97));
524 static int snd_via82xx_codec_ready(struct via82xx *chip, int secondary)
526 unsigned int timeout = 1000; /* 1ms */
529 while (timeout-- > 0) {
531 if (!((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY))
534 dev_err(chip->card->dev, "codec_ready: codec %i is not ready [0x%x]\n",
535 secondary, snd_via82xx_codec_xread(chip));
539 static int snd_via82xx_codec_valid(struct via82xx *chip, int secondary)
541 unsigned int timeout = 1000; /* 1ms */
542 unsigned int val, val1;
543 unsigned int stat = !secondary ? VIA_REG_AC97_PRIMARY_VALID :
544 VIA_REG_AC97_SECONDARY_VALID;
546 while (timeout-- > 0) {
547 val = snd_via82xx_codec_xread(chip);
548 val1 = val & (VIA_REG_AC97_BUSY | stat);
556 static void snd_via82xx_codec_wait(struct snd_ac97 *ac97)
558 struct via82xx *chip = ac97->private_data;
560 err = snd_via82xx_codec_ready(chip, ac97->num);
561 /* here we need to wait fairly for long time.. */
566 static void snd_via82xx_codec_write(struct snd_ac97 *ac97,
570 struct via82xx *chip = ac97->private_data;
573 xval = !ac97->num ? VIA_REG_AC97_CODEC_ID_PRIMARY : VIA_REG_AC97_CODEC_ID_SECONDARY;
574 xval <<= VIA_REG_AC97_CODEC_ID_SHIFT;
575 xval |= reg << VIA_REG_AC97_CMD_SHIFT;
576 xval |= val << VIA_REG_AC97_DATA_SHIFT;
577 snd_via82xx_codec_xwrite(chip, xval);
578 snd_via82xx_codec_ready(chip, ac97->num);
581 static unsigned short snd_via82xx_codec_read(struct snd_ac97 *ac97, unsigned short reg)
583 struct via82xx *chip = ac97->private_data;
584 unsigned int xval, val = 0xffff;
587 xval = ac97->num << VIA_REG_AC97_CODEC_ID_SHIFT;
588 xval |= ac97->num ? VIA_REG_AC97_SECONDARY_VALID : VIA_REG_AC97_PRIMARY_VALID;
589 xval |= VIA_REG_AC97_READ;
590 xval |= (reg & 0x7f) << VIA_REG_AC97_CMD_SHIFT;
593 dev_err(chip->card->dev,
594 "codec_read: codec %i is not valid [0x%x]\n",
595 ac97->num, snd_via82xx_codec_xread(chip));
598 snd_via82xx_codec_xwrite(chip, xval);
600 if (snd_via82xx_codec_valid(chip, ac97->num) >= 0) {
602 val = snd_via82xx_codec_xread(chip);
609 static void snd_via82xx_channel_reset(struct via82xx *chip, struct viadev *viadev)
611 outb(VIA_REG_CTRL_PAUSE | VIA_REG_CTRL_TERMINATE | VIA_REG_CTRL_RESET,
612 VIADEV_REG(viadev, OFFSET_CONTROL));
613 inb(VIADEV_REG(viadev, OFFSET_CONTROL));
615 /* disable interrupts */
616 outb(0x00, VIADEV_REG(viadev, OFFSET_CONTROL));
617 /* clear interrupts */
618 outb(0x03, VIADEV_REG(viadev, OFFSET_STATUS));
619 outb(0x00, VIADEV_REG(viadev, OFFSET_TYPE)); /* for via686 */
620 // outl(0, VIADEV_REG(viadev, OFFSET_CURR_PTR));
622 viadev->hwptr_done = 0;
628 * Used for 686 and 8233A
630 static irqreturn_t snd_via686_interrupt(int irq, void *dev_id)
632 struct via82xx *chip = dev_id;
636 status = inl(VIAREG(chip, SGD_SHADOW));
637 if (! (status & chip->intr_mask)) {
639 /* check mpu401 interrupt */
640 return snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
644 /* check status for each stream */
645 spin_lock(&chip->reg_lock);
646 for (i = 0; i < chip->num_devs; i++) {
647 struct viadev *viadev = &chip->devs[i];
648 unsigned char c_status = inb(VIADEV_REG(viadev, OFFSET_STATUS));
649 if (! (c_status & (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG|VIA_REG_STAT_STOPPED)))
651 if (viadev->substream && viadev->running) {
653 * Update hwptr_done based on 'period elapsed'
654 * interrupts. We'll use it, when the chip returns 0
655 * for OFFSET_CURR_COUNT.
657 if (c_status & VIA_REG_STAT_EOL)
658 viadev->hwptr_done = 0;
660 viadev->hwptr_done += viadev->fragsize;
661 viadev->in_interrupt = c_status;
662 spin_unlock(&chip->reg_lock);
663 snd_pcm_period_elapsed(viadev->substream);
664 spin_lock(&chip->reg_lock);
665 viadev->in_interrupt = 0;
667 outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */
669 spin_unlock(&chip->reg_lock);
676 static irqreturn_t snd_via8233_interrupt(int irq, void *dev_id)
678 struct via82xx *chip = dev_id;
683 /* check status for each stream */
684 spin_lock(&chip->reg_lock);
685 status = inl(VIAREG(chip, SGD_SHADOW));
687 for (i = 0; i < chip->num_devs; i++) {
688 struct viadev *viadev = &chip->devs[i];
689 struct snd_pcm_substream *substream;
690 unsigned char c_status, shadow_status;
692 shadow_status = (status >> viadev->shadow_shift) &
693 (VIA8233_SHADOW_STAT_ACTIVE|VIA_REG_STAT_EOL|
695 c_status = shadow_status & (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG);
699 substream = viadev->substream;
700 if (substream && viadev->running) {
702 * Update hwptr_done based on 'period elapsed'
703 * interrupts. We'll use it, when the chip returns 0
704 * for OFFSET_CURR_COUNT.
706 if (c_status & VIA_REG_STAT_EOL)
707 viadev->hwptr_done = 0;
709 viadev->hwptr_done += viadev->fragsize;
710 viadev->in_interrupt = c_status;
711 if (shadow_status & VIA8233_SHADOW_STAT_ACTIVE)
712 viadev->in_interrupt |= VIA_REG_STAT_ACTIVE;
713 spin_unlock(&chip->reg_lock);
715 snd_pcm_period_elapsed(substream);
717 spin_lock(&chip->reg_lock);
718 viadev->in_interrupt = 0;
720 outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */
723 spin_unlock(&chip->reg_lock);
724 return IRQ_RETVAL(irqreturn);
734 static int snd_via82xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
736 struct via82xx *chip = snd_pcm_substream_chip(substream);
737 struct viadev *viadev = substream->runtime->private_data;
740 if (chip->chip_type != TYPE_VIA686)
741 val = VIA_REG_CTRL_INT;
745 case SNDRV_PCM_TRIGGER_START:
746 case SNDRV_PCM_TRIGGER_RESUME:
747 val |= VIA_REG_CTRL_START;
750 case SNDRV_PCM_TRIGGER_STOP:
751 case SNDRV_PCM_TRIGGER_SUSPEND:
752 val = VIA_REG_CTRL_TERMINATE;
755 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
756 val |= VIA_REG_CTRL_PAUSE;
759 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
765 outb(val, VIADEV_REG(viadev, OFFSET_CONTROL));
766 if (cmd == SNDRV_PCM_TRIGGER_STOP)
767 snd_via82xx_channel_reset(chip, viadev);
777 * calculate the linear position at the given sg-buffer index and the rest count
780 #define check_invalid_pos(viadev,pos) \
781 ((pos) < viadev->lastpos && ((pos) >= viadev->bufsize2 ||\
782 viadev->lastpos < viadev->bufsize2))
784 static inline unsigned int calc_linear_pos(struct via82xx *chip,
785 struct viadev *viadev,
789 unsigned int size, base, res;
791 size = viadev->idx_table[idx].size;
792 base = viadev->idx_table[idx].offset;
793 res = base + size - count;
794 if (res >= viadev->bufsize)
795 res -= viadev->bufsize;
797 /* check the validity of the calculated position */
799 dev_dbg(chip->card->dev,
800 "invalid via82xx_cur_ptr (size = %d, count = %d)\n",
801 (int)size, (int)count);
802 res = viadev->lastpos;
805 /* Some mobos report count = 0 on the DMA boundary,
806 * i.e. count = size indeed.
807 * Let's check whether this step is above the expected size.
809 int delta = res - viadev->lastpos;
811 delta += viadev->bufsize;
812 if ((unsigned int)delta > viadev->fragsize)
815 if (check_invalid_pos(viadev, res)) {
817 dev_dbg(chip->card->dev,
818 "fail: idx = %i/%i, lastpos = 0x%x, bufsize2 = 0x%x, offsize = 0x%x, size = 0x%x, count = 0x%x\n",
819 idx, viadev->tbl_entries,
820 viadev->lastpos, viadev->bufsize2,
821 viadev->idx_table[idx].offset,
822 viadev->idx_table[idx].size, count);
824 /* count register returns full size when end of buffer is reached */
826 if (check_invalid_pos(viadev, res)) {
827 dev_dbg(chip->card->dev,
828 "invalid via82xx_cur_ptr (2), using last valid pointer\n");
829 res = viadev->lastpos;
837 * get the current pointer on via686
839 static snd_pcm_uframes_t snd_via686_pcm_pointer(struct snd_pcm_substream *substream)
841 struct via82xx *chip = snd_pcm_substream_chip(substream);
842 struct viadev *viadev = substream->runtime->private_data;
843 unsigned int idx, ptr, count, res;
845 if (snd_BUG_ON(!viadev->tbl_entries))
847 if (!(inb(VIADEV_REG(viadev, OFFSET_STATUS)) & VIA_REG_STAT_ACTIVE))
850 spin_lock(&chip->reg_lock);
851 count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT)) & 0xffffff;
852 /* The via686a does not have the current index register,
853 * so we need to calculate the index from CURR_PTR.
855 ptr = inl(VIADEV_REG(viadev, OFFSET_CURR_PTR));
856 if (ptr <= (unsigned int)viadev->table.addr)
858 else /* CURR_PTR holds the address + 8 */
859 idx = ((ptr - (unsigned int)viadev->table.addr) / 8 - 1) % viadev->tbl_entries;
860 res = calc_linear_pos(chip, viadev, idx, count);
861 viadev->lastpos = res; /* remember the last position */
862 spin_unlock(&chip->reg_lock);
864 return bytes_to_frames(substream->runtime, res);
868 * get the current pointer on via823x
870 static snd_pcm_uframes_t snd_via8233_pcm_pointer(struct snd_pcm_substream *substream)
872 struct via82xx *chip = snd_pcm_substream_chip(substream);
873 struct viadev *viadev = substream->runtime->private_data;
874 unsigned int idx, count, res;
877 if (snd_BUG_ON(!viadev->tbl_entries))
880 spin_lock(&chip->reg_lock);
881 count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT));
882 status = viadev->in_interrupt;
884 status = inb(VIADEV_REG(viadev, OFFSET_STATUS));
886 /* An apparent bug in the 8251 is worked around by sending a
888 if (chip->revision == VIA_REV_8251 && (status & VIA_REG_STAT_EOL))
889 snd_via82xx_pcm_trigger(substream, SNDRV_PCM_TRIGGER_START);
891 if (!(status & VIA_REG_STAT_ACTIVE)) {
895 if (count & 0xffffff) {
897 if (idx >= viadev->tbl_entries) {
899 dev_dbg(chip->card->dev,
900 "fail: invalid idx = %i/%i\n", idx,
901 viadev->tbl_entries);
903 res = viadev->lastpos;
906 res = calc_linear_pos(chip, viadev, idx, count);
909 res = viadev->hwptr_done;
910 if (!viadev->in_interrupt) {
911 if (status & VIA_REG_STAT_EOL) {
914 if (status & VIA_REG_STAT_FLAG) {
915 res += viadev->fragsize;
920 viadev->lastpos = res;
921 spin_unlock(&chip->reg_lock);
923 return bytes_to_frames(substream->runtime, res);
928 * hw_params callback:
929 * allocate the buffer and build up the buffer description table
931 static int snd_via82xx_hw_params(struct snd_pcm_substream *substream,
932 struct snd_pcm_hw_params *hw_params)
934 struct via82xx *chip = snd_pcm_substream_chip(substream);
935 struct viadev *viadev = substream->runtime->private_data;
938 err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
941 err = build_via_table(viadev, substream, chip->pci,
942 params_periods(hw_params),
943 params_period_bytes(hw_params));
952 * clean up the buffer description table and release the buffer
954 static int snd_via82xx_hw_free(struct snd_pcm_substream *substream)
956 struct via82xx *chip = snd_pcm_substream_chip(substream);
957 struct viadev *viadev = substream->runtime->private_data;
959 clean_via_table(viadev, substream, chip->pci);
960 snd_pcm_lib_free_pages(substream);
966 * set up the table pointer
968 static void snd_via82xx_set_table_ptr(struct via82xx *chip, struct viadev *viadev)
970 snd_via82xx_codec_ready(chip, 0);
971 outl((u32)viadev->table.addr, VIADEV_REG(viadev, OFFSET_TABLE_PTR));
973 snd_via82xx_codec_ready(chip, 0);
977 * prepare callback for playback and capture on via686
979 static void via686_setup_format(struct via82xx *chip, struct viadev *viadev,
980 struct snd_pcm_runtime *runtime)
982 snd_via82xx_channel_reset(chip, viadev);
983 /* this must be set after channel_reset */
984 snd_via82xx_set_table_ptr(chip, viadev);
985 outb(VIA_REG_TYPE_AUTOSTART |
986 (runtime->format == SNDRV_PCM_FORMAT_S16_LE ? VIA_REG_TYPE_16BIT : 0) |
987 (runtime->channels > 1 ? VIA_REG_TYPE_STEREO : 0) |
988 ((viadev->reg_offset & 0x10) == 0 ? VIA_REG_TYPE_INT_LSAMPLE : 0) |
989 VIA_REG_TYPE_INT_EOL |
990 VIA_REG_TYPE_INT_FLAG, VIADEV_REG(viadev, OFFSET_TYPE));
993 static int snd_via686_playback_prepare(struct snd_pcm_substream *substream)
995 struct via82xx *chip = snd_pcm_substream_chip(substream);
996 struct viadev *viadev = substream->runtime->private_data;
997 struct snd_pcm_runtime *runtime = substream->runtime;
999 snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, runtime->rate);
1000 snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate);
1001 via686_setup_format(chip, viadev, runtime);
1005 static int snd_via686_capture_prepare(struct snd_pcm_substream *substream)
1007 struct via82xx *chip = snd_pcm_substream_chip(substream);
1008 struct viadev *viadev = substream->runtime->private_data;
1009 struct snd_pcm_runtime *runtime = substream->runtime;
1011 snd_ac97_set_rate(chip->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
1012 via686_setup_format(chip, viadev, runtime);
1017 * lock the current rate
1019 static int via_lock_rate(struct via_rate_lock *rec, int rate)
1023 spin_lock_irq(&rec->lock);
1024 if (rec->rate != rate) {
1025 if (rec->rate && rec->used > 1) /* already set */
1032 spin_unlock_irq(&rec->lock);
1037 * prepare callback for DSX playback on via823x
1039 static int snd_via8233_playback_prepare(struct snd_pcm_substream *substream)
1041 struct via82xx *chip = snd_pcm_substream_chip(substream);
1042 struct viadev *viadev = substream->runtime->private_data;
1043 struct snd_pcm_runtime *runtime = substream->runtime;
1044 int ac97_rate = chip->dxs_src ? 48000 : runtime->rate;
1048 if ((rate_changed = via_lock_rate(&chip->rates[0], ac97_rate)) < 0)
1049 return rate_changed;
1051 snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE,
1052 chip->no_vra ? 48000 : runtime->rate);
1053 if (chip->spdif_on && viadev->reg_offset == 0x30)
1054 snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate);
1056 if (runtime->rate == 48000)
1059 rbits = (0x100000 / 48000) * runtime->rate +
1060 ((0x100000 % 48000) * runtime->rate) / 48000;
1061 snd_BUG_ON(rbits & ~0xfffff);
1062 snd_via82xx_channel_reset(chip, viadev);
1063 snd_via82xx_set_table_ptr(chip, viadev);
1064 outb(chip->playback_volume[viadev->reg_offset / 0x10][0],
1065 VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_L));
1066 outb(chip->playback_volume[viadev->reg_offset / 0x10][1],
1067 VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_R));
1068 outl((runtime->format == SNDRV_PCM_FORMAT_S16_LE ? VIA8233_REG_TYPE_16BIT : 0) | /* format */
1069 (runtime->channels > 1 ? VIA8233_REG_TYPE_STEREO : 0) | /* stereo */
1071 0xff000000, /* STOP index is never reached */
1072 VIADEV_REG(viadev, OFFSET_STOP_IDX));
1074 snd_via82xx_codec_ready(chip, 0);
1079 * prepare callback for multi-channel playback on via823x
1081 static int snd_via8233_multi_prepare(struct snd_pcm_substream *substream)
1083 struct via82xx *chip = snd_pcm_substream_chip(substream);
1084 struct viadev *viadev = substream->runtime->private_data;
1085 struct snd_pcm_runtime *runtime = substream->runtime;
1089 if (via_lock_rate(&chip->rates[0], runtime->rate) < 0)
1091 snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, runtime->rate);
1092 snd_ac97_set_rate(chip->ac97, AC97_PCM_SURR_DAC_RATE, runtime->rate);
1093 snd_ac97_set_rate(chip->ac97, AC97_PCM_LFE_DAC_RATE, runtime->rate);
1094 snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate);
1095 snd_via82xx_channel_reset(chip, viadev);
1096 snd_via82xx_set_table_ptr(chip, viadev);
1098 fmt = (runtime->format == SNDRV_PCM_FORMAT_S16_LE) ?
1099 VIA_REG_MULTPLAY_FMT_16BIT : VIA_REG_MULTPLAY_FMT_8BIT;
1100 fmt |= runtime->channels << 4;
1101 outb(fmt, VIADEV_REG(viadev, OFS_MULTPLAY_FORMAT));
1103 if (chip->revision == VIA_REV_8233A)
1108 /* set sample number to slot 3, 4, 7, 8, 6, 9 (for VIA8233/C,8235) */
1109 /* corresponding to FL, FR, RL, RR, C, LFE ?? */
1110 switch (runtime->channels) {
1111 case 1: slots = (1<<0) | (1<<4); break;
1112 case 2: slots = (1<<0) | (2<<4); break;
1113 case 3: slots = (1<<0) | (2<<4) | (5<<8); break;
1114 case 4: slots = (1<<0) | (2<<4) | (3<<8) | (4<<12); break;
1115 case 5: slots = (1<<0) | (2<<4) | (3<<8) | (4<<12) | (5<<16); break;
1116 case 6: slots = (1<<0) | (2<<4) | (3<<8) | (4<<12) | (5<<16) | (6<<20); break;
1117 default: slots = 0; break;
1120 /* STOP index is never reached */
1121 outl(0xff000000 | slots, VIADEV_REG(viadev, OFFSET_STOP_IDX));
1123 snd_via82xx_codec_ready(chip, 0);
1128 * prepare callback for capture on via823x
1130 static int snd_via8233_capture_prepare(struct snd_pcm_substream *substream)
1132 struct via82xx *chip = snd_pcm_substream_chip(substream);
1133 struct viadev *viadev = substream->runtime->private_data;
1134 struct snd_pcm_runtime *runtime = substream->runtime;
1136 if (via_lock_rate(&chip->rates[1], runtime->rate) < 0)
1138 snd_ac97_set_rate(chip->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
1139 snd_via82xx_channel_reset(chip, viadev);
1140 snd_via82xx_set_table_ptr(chip, viadev);
1141 outb(VIA_REG_CAPTURE_FIFO_ENABLE, VIADEV_REG(viadev, OFS_CAPTURE_FIFO));
1142 outl((runtime->format == SNDRV_PCM_FORMAT_S16_LE ? VIA8233_REG_TYPE_16BIT : 0) |
1143 (runtime->channels > 1 ? VIA8233_REG_TYPE_STEREO : 0) |
1144 0xff000000, /* STOP index is never reached */
1145 VIADEV_REG(viadev, OFFSET_STOP_IDX));
1147 snd_via82xx_codec_ready(chip, 0);
1153 * pcm hardware definition, identical for both playback and capture
1155 static const struct snd_pcm_hardware snd_via82xx_hw =
1157 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1158 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1159 SNDRV_PCM_INFO_MMAP_VALID |
1160 /* SNDRV_PCM_INFO_RESUME | */
1161 SNDRV_PCM_INFO_PAUSE),
1162 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
1163 .rates = SNDRV_PCM_RATE_48000,
1168 .buffer_bytes_max = VIA_MAX_BUFSIZE,
1169 .period_bytes_min = 32,
1170 .period_bytes_max = VIA_MAX_BUFSIZE / 2,
1172 .periods_max = VIA_TABLE_SIZE / 2,
1178 * open callback skeleton
1180 static int snd_via82xx_pcm_open(struct via82xx *chip, struct viadev *viadev,
1181 struct snd_pcm_substream *substream)
1183 struct snd_pcm_runtime *runtime = substream->runtime;
1185 struct via_rate_lock *ratep;
1186 bool use_src = false;
1188 runtime->hw = snd_via82xx_hw;
1190 /* set the hw rate condition */
1191 ratep = &chip->rates[viadev->direction];
1192 spin_lock_irq(&ratep->lock);
1194 if (chip->spdif_on && viadev->reg_offset == 0x30) {
1195 /* DXS#3 and spdif is on */
1196 runtime->hw.rates = chip->ac97->rates[AC97_RATES_SPDIF];
1197 snd_pcm_limit_hw_rates(runtime);
1198 } else if (chip->dxs_fixed && viadev->reg_offset < 0x40) {
1199 /* fixed DXS playback rate */
1200 runtime->hw.rates = SNDRV_PCM_RATE_48000;
1201 runtime->hw.rate_min = runtime->hw.rate_max = 48000;
1202 } else if (chip->dxs_src && viadev->reg_offset < 0x40) {
1203 /* use full SRC capabilities of DXS */
1204 runtime->hw.rates = (SNDRV_PCM_RATE_CONTINUOUS |
1205 SNDRV_PCM_RATE_8000_48000);
1206 runtime->hw.rate_min = 8000;
1207 runtime->hw.rate_max = 48000;
1209 } else if (! ratep->rate) {
1210 int idx = viadev->direction ? AC97_RATES_ADC : AC97_RATES_FRONT_DAC;
1211 runtime->hw.rates = chip->ac97->rates[idx];
1212 snd_pcm_limit_hw_rates(runtime);
1215 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
1216 runtime->hw.rate_max = runtime->hw.rate_min = ratep->rate;
1218 spin_unlock_irq(&ratep->lock);
1220 /* we may remove following constaint when we modify table entries
1222 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
1226 err = snd_pcm_hw_rule_noresample(runtime, 48000);
1231 runtime->private_data = viadev;
1232 viadev->substream = substream;
1239 * open callback for playback on via686
1241 static int snd_via686_playback_open(struct snd_pcm_substream *substream)
1243 struct via82xx *chip = snd_pcm_substream_chip(substream);
1244 struct viadev *viadev = &chip->devs[chip->playback_devno + substream->number];
1247 if ((err = snd_via82xx_pcm_open(chip, viadev, substream)) < 0)
1253 * open callback for playback on via823x DXS
1255 static int snd_via8233_playback_open(struct snd_pcm_substream *substream)
1257 struct via82xx *chip = snd_pcm_substream_chip(substream);
1258 struct viadev *viadev;
1259 unsigned int stream;
1262 viadev = &chip->devs[chip->playback_devno + substream->number];
1263 if ((err = snd_via82xx_pcm_open(chip, viadev, substream)) < 0)
1265 stream = viadev->reg_offset / 0x10;
1266 if (chip->dxs_controls[stream]) {
1267 chip->playback_volume[stream][0] =
1268 VIA_DXS_MAX_VOLUME - (dxs_init_volume & 31);
1269 chip->playback_volume[stream][1] =
1270 VIA_DXS_MAX_VOLUME - (dxs_init_volume & 31);
1271 chip->dxs_controls[stream]->vd[0].access &=
1272 ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1273 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE |
1274 SNDRV_CTL_EVENT_MASK_INFO,
1275 &chip->dxs_controls[stream]->id);
1281 * open callback for playback on via823x multi-channel
1283 static int snd_via8233_multi_open(struct snd_pcm_substream *substream)
1285 struct via82xx *chip = snd_pcm_substream_chip(substream);
1286 struct viadev *viadev = &chip->devs[chip->multi_devno];
1288 /* channels constraint for VIA8233A
1289 * 3 and 5 channels are not supported
1291 static const unsigned int channels[] = {
1294 static const struct snd_pcm_hw_constraint_list hw_constraints_channels = {
1295 .count = ARRAY_SIZE(channels),
1300 if ((err = snd_via82xx_pcm_open(chip, viadev, substream)) < 0)
1302 substream->runtime->hw.channels_max = 6;
1303 if (chip->revision == VIA_REV_8233A)
1304 snd_pcm_hw_constraint_list(substream->runtime, 0,
1305 SNDRV_PCM_HW_PARAM_CHANNELS,
1306 &hw_constraints_channels);
1311 * open callback for capture on via686 and via823x
1313 static int snd_via82xx_capture_open(struct snd_pcm_substream *substream)
1315 struct via82xx *chip = snd_pcm_substream_chip(substream);
1316 struct viadev *viadev = &chip->devs[chip->capture_devno + substream->pcm->device];
1318 return snd_via82xx_pcm_open(chip, viadev, substream);
1324 static int snd_via82xx_pcm_close(struct snd_pcm_substream *substream)
1326 struct via82xx *chip = snd_pcm_substream_chip(substream);
1327 struct viadev *viadev = substream->runtime->private_data;
1328 struct via_rate_lock *ratep;
1330 /* release the rate lock */
1331 ratep = &chip->rates[viadev->direction];
1332 spin_lock_irq(&ratep->lock);
1336 spin_unlock_irq(&ratep->lock);
1337 if (! ratep->rate) {
1338 if (! viadev->direction) {
1339 snd_ac97_update_power(chip->ac97,
1340 AC97_PCM_FRONT_DAC_RATE, 0);
1341 snd_ac97_update_power(chip->ac97,
1342 AC97_PCM_SURR_DAC_RATE, 0);
1343 snd_ac97_update_power(chip->ac97,
1344 AC97_PCM_LFE_DAC_RATE, 0);
1346 snd_ac97_update_power(chip->ac97,
1347 AC97_PCM_LR_ADC_RATE, 0);
1349 viadev->substream = NULL;
1353 static int snd_via8233_playback_close(struct snd_pcm_substream *substream)
1355 struct via82xx *chip = snd_pcm_substream_chip(substream);
1356 struct viadev *viadev = substream->runtime->private_data;
1357 unsigned int stream;
1359 stream = viadev->reg_offset / 0x10;
1360 if (chip->dxs_controls[stream]) {
1361 chip->dxs_controls[stream]->vd[0].access |=
1362 SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1363 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_INFO,
1364 &chip->dxs_controls[stream]->id);
1366 return snd_via82xx_pcm_close(substream);
1370 /* via686 playback callbacks */
1371 static const struct snd_pcm_ops snd_via686_playback_ops = {
1372 .open = snd_via686_playback_open,
1373 .close = snd_via82xx_pcm_close,
1374 .ioctl = snd_pcm_lib_ioctl,
1375 .hw_params = snd_via82xx_hw_params,
1376 .hw_free = snd_via82xx_hw_free,
1377 .prepare = snd_via686_playback_prepare,
1378 .trigger = snd_via82xx_pcm_trigger,
1379 .pointer = snd_via686_pcm_pointer,
1380 .page = snd_pcm_sgbuf_ops_page,
1383 /* via686 capture callbacks */
1384 static const struct snd_pcm_ops snd_via686_capture_ops = {
1385 .open = snd_via82xx_capture_open,
1386 .close = snd_via82xx_pcm_close,
1387 .ioctl = snd_pcm_lib_ioctl,
1388 .hw_params = snd_via82xx_hw_params,
1389 .hw_free = snd_via82xx_hw_free,
1390 .prepare = snd_via686_capture_prepare,
1391 .trigger = snd_via82xx_pcm_trigger,
1392 .pointer = snd_via686_pcm_pointer,
1393 .page = snd_pcm_sgbuf_ops_page,
1396 /* via823x DSX playback callbacks */
1397 static const struct snd_pcm_ops snd_via8233_playback_ops = {
1398 .open = snd_via8233_playback_open,
1399 .close = snd_via8233_playback_close,
1400 .ioctl = snd_pcm_lib_ioctl,
1401 .hw_params = snd_via82xx_hw_params,
1402 .hw_free = snd_via82xx_hw_free,
1403 .prepare = snd_via8233_playback_prepare,
1404 .trigger = snd_via82xx_pcm_trigger,
1405 .pointer = snd_via8233_pcm_pointer,
1406 .page = snd_pcm_sgbuf_ops_page,
1409 /* via823x multi-channel playback callbacks */
1410 static const struct snd_pcm_ops snd_via8233_multi_ops = {
1411 .open = snd_via8233_multi_open,
1412 .close = snd_via82xx_pcm_close,
1413 .ioctl = snd_pcm_lib_ioctl,
1414 .hw_params = snd_via82xx_hw_params,
1415 .hw_free = snd_via82xx_hw_free,
1416 .prepare = snd_via8233_multi_prepare,
1417 .trigger = snd_via82xx_pcm_trigger,
1418 .pointer = snd_via8233_pcm_pointer,
1419 .page = snd_pcm_sgbuf_ops_page,
1422 /* via823x capture callbacks */
1423 static const struct snd_pcm_ops snd_via8233_capture_ops = {
1424 .open = snd_via82xx_capture_open,
1425 .close = snd_via82xx_pcm_close,
1426 .ioctl = snd_pcm_lib_ioctl,
1427 .hw_params = snd_via82xx_hw_params,
1428 .hw_free = snd_via82xx_hw_free,
1429 .prepare = snd_via8233_capture_prepare,
1430 .trigger = snd_via82xx_pcm_trigger,
1431 .pointer = snd_via8233_pcm_pointer,
1432 .page = snd_pcm_sgbuf_ops_page,
1436 static void init_viadev(struct via82xx *chip, int idx, unsigned int reg_offset,
1437 int shadow_pos, int direction)
1439 chip->devs[idx].reg_offset = reg_offset;
1440 chip->devs[idx].shadow_shift = shadow_pos * 4;
1441 chip->devs[idx].direction = direction;
1442 chip->devs[idx].port = chip->port + reg_offset;
1446 * create pcm instances for VIA8233, 8233C and 8235 (not 8233A)
1448 static int snd_via8233_pcm_new(struct via82xx *chip)
1450 struct snd_pcm *pcm;
1451 struct snd_pcm_chmap *chmap;
1454 chip->playback_devno = 0; /* x 4 */
1455 chip->multi_devno = 4; /* x 1 */
1456 chip->capture_devno = 5; /* x 2 */
1458 chip->intr_mask = 0x33033333; /* FLAG|EOL for rec0-1, mc, sdx0-3 */
1460 /* PCM #0: 4 DSX playbacks and 1 capture */
1461 err = snd_pcm_new(chip->card, chip->card->shortname, 0, 4, 1, &pcm);
1464 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_playback_ops);
1465 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via8233_capture_ops);
1466 pcm->private_data = chip;
1467 strcpy(pcm->name, chip->card->shortname);
1468 chip->pcms[0] = pcm;
1469 /* set up playbacks */
1470 for (i = 0; i < 4; i++)
1471 init_viadev(chip, i, 0x10 * i, i, 0);
1473 init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1);
1475 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1476 snd_dma_pci_data(chip->pci),
1477 64*1024, VIA_MAX_BUFSIZE);
1479 err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1480 snd_pcm_std_chmaps, 2, 0,
1485 /* PCM #1: multi-channel playback and 2nd capture */
1486 err = snd_pcm_new(chip->card, chip->card->shortname, 1, 1, 1, &pcm);
1489 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_multi_ops);
1490 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via8233_capture_ops);
1491 pcm->private_data = chip;
1492 strcpy(pcm->name, chip->card->shortname);
1493 chip->pcms[1] = pcm;
1494 /* set up playback */
1495 init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 4, 0);
1496 /* set up capture */
1497 init_viadev(chip, chip->capture_devno + 1, VIA_REG_CAPTURE_8233_STATUS + 0x10, 7, 1);
1499 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1500 snd_dma_pci_data(chip->pci),
1501 64*1024, VIA_MAX_BUFSIZE);
1503 err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1504 snd_pcm_alt_chmaps, 6, 0,
1508 chip->ac97->chmaps[SNDRV_PCM_STREAM_PLAYBACK] = chmap;
1514 * create pcm instances for VIA8233A
1516 static int snd_via8233a_pcm_new(struct via82xx *chip)
1518 struct snd_pcm *pcm;
1519 struct snd_pcm_chmap *chmap;
1522 chip->multi_devno = 0;
1523 chip->playback_devno = 1;
1524 chip->capture_devno = 2;
1526 chip->intr_mask = 0x03033000; /* FLAG|EOL for rec0, mc, sdx3 */
1528 /* PCM #0: multi-channel playback and capture */
1529 err = snd_pcm_new(chip->card, chip->card->shortname, 0, 1, 1, &pcm);
1532 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_multi_ops);
1533 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via8233_capture_ops);
1534 pcm->private_data = chip;
1535 strcpy(pcm->name, chip->card->shortname);
1536 chip->pcms[0] = pcm;
1537 /* set up playback */
1538 init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 4, 0);
1540 init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1);
1542 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1543 snd_dma_pci_data(chip->pci),
1544 64*1024, VIA_MAX_BUFSIZE);
1546 err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1547 snd_pcm_alt_chmaps, 6, 0,
1551 chip->ac97->chmaps[SNDRV_PCM_STREAM_PLAYBACK] = chmap;
1553 /* SPDIF supported? */
1554 if (! ac97_can_spdif(chip->ac97))
1557 /* PCM #1: DXS3 playback (for spdif) */
1558 err = snd_pcm_new(chip->card, chip->card->shortname, 1, 1, 0, &pcm);
1561 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_playback_ops);
1562 pcm->private_data = chip;
1563 strcpy(pcm->name, chip->card->shortname);
1564 chip->pcms[1] = pcm;
1565 /* set up playback */
1566 init_viadev(chip, chip->playback_devno, 0x30, 3, 0);
1568 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1569 snd_dma_pci_data(chip->pci),
1570 64*1024, VIA_MAX_BUFSIZE);
1575 * create a pcm instance for via686a/b
1577 static int snd_via686_pcm_new(struct via82xx *chip)
1579 struct snd_pcm *pcm;
1582 chip->playback_devno = 0;
1583 chip->capture_devno = 1;
1585 chip->intr_mask = 0x77; /* FLAG | EOL for PB, CP, FM */
1587 err = snd_pcm_new(chip->card, chip->card->shortname, 0, 1, 1, &pcm);
1590 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via686_playback_ops);
1591 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via686_capture_ops);
1592 pcm->private_data = chip;
1593 strcpy(pcm->name, chip->card->shortname);
1594 chip->pcms[0] = pcm;
1595 init_viadev(chip, 0, VIA_REG_PLAYBACK_STATUS, 0, 0);
1596 init_viadev(chip, 1, VIA_REG_CAPTURE_STATUS, 0, 1);
1598 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1599 snd_dma_pci_data(chip->pci),
1600 64*1024, VIA_MAX_BUFSIZE);
1609 static int snd_via8233_capture_source_info(struct snd_kcontrol *kcontrol,
1610 struct snd_ctl_elem_info *uinfo)
1612 /* formerly they were "Line" and "Mic", but it looks like that they
1613 * have nothing to do with the actual physical connections...
1615 static const char * const texts[2] = {
1618 return snd_ctl_enum_info(uinfo, 1, 2, texts);
1621 static int snd_via8233_capture_source_get(struct snd_kcontrol *kcontrol,
1622 struct snd_ctl_elem_value *ucontrol)
1624 struct via82xx *chip = snd_kcontrol_chip(kcontrol);
1625 unsigned long port = chip->port + (kcontrol->id.index ? (VIA_REG_CAPTURE_CHANNEL + 0x10) : VIA_REG_CAPTURE_CHANNEL);
1626 ucontrol->value.enumerated.item[0] = inb(port) & VIA_REG_CAPTURE_CHANNEL_MIC ? 1 : 0;
1630 static int snd_via8233_capture_source_put(struct snd_kcontrol *kcontrol,
1631 struct snd_ctl_elem_value *ucontrol)
1633 struct via82xx *chip = snd_kcontrol_chip(kcontrol);
1634 unsigned long port = chip->port + (kcontrol->id.index ? (VIA_REG_CAPTURE_CHANNEL + 0x10) : VIA_REG_CAPTURE_CHANNEL);
1637 spin_lock_irq(&chip->reg_lock);
1639 val = oval & ~VIA_REG_CAPTURE_CHANNEL_MIC;
1640 if (ucontrol->value.enumerated.item[0])
1641 val |= VIA_REG_CAPTURE_CHANNEL_MIC;
1644 spin_unlock_irq(&chip->reg_lock);
1648 static struct snd_kcontrol_new snd_via8233_capture_source = {
1649 .name = "Input Source Select",
1650 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1651 .info = snd_via8233_capture_source_info,
1652 .get = snd_via8233_capture_source_get,
1653 .put = snd_via8233_capture_source_put,
1656 #define snd_via8233_dxs3_spdif_info snd_ctl_boolean_mono_info
1658 static int snd_via8233_dxs3_spdif_get(struct snd_kcontrol *kcontrol,
1659 struct snd_ctl_elem_value *ucontrol)
1661 struct via82xx *chip = snd_kcontrol_chip(kcontrol);
1664 pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &val);
1665 ucontrol->value.integer.value[0] = (val & VIA8233_SPDIF_DX3) ? 1 : 0;
1669 static int snd_via8233_dxs3_spdif_put(struct snd_kcontrol *kcontrol,
1670 struct snd_ctl_elem_value *ucontrol)
1672 struct via82xx *chip = snd_kcontrol_chip(kcontrol);
1675 pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &oval);
1676 val = oval & ~VIA8233_SPDIF_DX3;
1677 if (ucontrol->value.integer.value[0])
1678 val |= VIA8233_SPDIF_DX3;
1679 /* save the spdif flag for rate filtering */
1680 chip->spdif_on = ucontrol->value.integer.value[0] ? 1 : 0;
1682 pci_write_config_byte(chip->pci, VIA8233_SPDIF_CTRL, val);
1688 static const struct snd_kcontrol_new snd_via8233_dxs3_spdif_control = {
1689 .name = SNDRV_CTL_NAME_IEC958("Output ",NONE,SWITCH),
1690 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1691 .info = snd_via8233_dxs3_spdif_info,
1692 .get = snd_via8233_dxs3_spdif_get,
1693 .put = snd_via8233_dxs3_spdif_put,
1696 static int snd_via8233_dxs_volume_info(struct snd_kcontrol *kcontrol,
1697 struct snd_ctl_elem_info *uinfo)
1699 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1701 uinfo->value.integer.min = 0;
1702 uinfo->value.integer.max = VIA_DXS_MAX_VOLUME;
1706 static int snd_via8233_dxs_volume_get(struct snd_kcontrol *kcontrol,
1707 struct snd_ctl_elem_value *ucontrol)
1709 struct via82xx *chip = snd_kcontrol_chip(kcontrol);
1710 unsigned int idx = kcontrol->id.subdevice;
1712 ucontrol->value.integer.value[0] = VIA_DXS_MAX_VOLUME - chip->playback_volume[idx][0];
1713 ucontrol->value.integer.value[1] = VIA_DXS_MAX_VOLUME - chip->playback_volume[idx][1];
1717 static int snd_via8233_pcmdxs_volume_get(struct snd_kcontrol *kcontrol,
1718 struct snd_ctl_elem_value *ucontrol)
1720 struct via82xx *chip = snd_kcontrol_chip(kcontrol);
1721 ucontrol->value.integer.value[0] = VIA_DXS_MAX_VOLUME - chip->playback_volume_c[0];
1722 ucontrol->value.integer.value[1] = VIA_DXS_MAX_VOLUME - chip->playback_volume_c[1];
1726 static int snd_via8233_dxs_volume_put(struct snd_kcontrol *kcontrol,
1727 struct snd_ctl_elem_value *ucontrol)
1729 struct via82xx *chip = snd_kcontrol_chip(kcontrol);
1730 unsigned int idx = kcontrol->id.subdevice;
1731 unsigned long port = chip->port + 0x10 * idx;
1735 for (i = 0; i < 2; i++) {
1736 val = ucontrol->value.integer.value[i];
1737 if (val > VIA_DXS_MAX_VOLUME)
1738 val = VIA_DXS_MAX_VOLUME;
1739 val = VIA_DXS_MAX_VOLUME - val;
1740 change |= val != chip->playback_volume[idx][i];
1742 chip->playback_volume[idx][i] = val;
1743 outb(val, port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i);
1749 static int snd_via8233_pcmdxs_volume_put(struct snd_kcontrol *kcontrol,
1750 struct snd_ctl_elem_value *ucontrol)
1752 struct via82xx *chip = snd_kcontrol_chip(kcontrol);
1757 for (i = 0; i < 2; i++) {
1758 val = ucontrol->value.integer.value[i];
1759 if (val > VIA_DXS_MAX_VOLUME)
1760 val = VIA_DXS_MAX_VOLUME;
1761 val = VIA_DXS_MAX_VOLUME - val;
1762 if (val != chip->playback_volume_c[i]) {
1764 chip->playback_volume_c[i] = val;
1765 for (idx = 0; idx < 4; idx++) {
1766 unsigned long port = chip->port + 0x10 * idx;
1767 chip->playback_volume[idx][i] = val;
1768 outb(val, port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i);
1775 static const DECLARE_TLV_DB_SCALE(db_scale_dxs, -4650, 150, 1);
1777 static const struct snd_kcontrol_new snd_via8233_pcmdxs_volume_control = {
1778 .name = "PCM Playback Volume",
1779 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1780 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1781 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1782 .info = snd_via8233_dxs_volume_info,
1783 .get = snd_via8233_pcmdxs_volume_get,
1784 .put = snd_via8233_pcmdxs_volume_put,
1785 .tlv = { .p = db_scale_dxs }
1788 static const struct snd_kcontrol_new snd_via8233_dxs_volume_control = {
1789 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1791 /* .subdevice set later */
1792 .name = "PCM Playback Volume",
1793 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1794 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
1795 SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1796 .info = snd_via8233_dxs_volume_info,
1797 .get = snd_via8233_dxs_volume_get,
1798 .put = snd_via8233_dxs_volume_put,
1799 .tlv = { .p = db_scale_dxs }
1805 static void snd_via82xx_mixer_free_ac97_bus(struct snd_ac97_bus *bus)
1807 struct via82xx *chip = bus->private_data;
1808 chip->ac97_bus = NULL;
1811 static void snd_via82xx_mixer_free_ac97(struct snd_ac97 *ac97)
1813 struct via82xx *chip = ac97->private_data;
1817 static const struct ac97_quirk ac97_quirks[] = {
1819 .subvendor = 0x1106,
1820 .subdevice = 0x4161,
1821 .codec_id = 0x56494161, /* VT1612A */
1822 .name = "Soltek SL-75DRV5",
1823 .type = AC97_TUNE_NONE
1825 { /* FIXME: which codec? */
1826 .subvendor = 0x1106,
1827 .subdevice = 0x4161,
1828 .name = "ASRock K7VT2",
1829 .type = AC97_TUNE_HP_ONLY
1832 .subvendor = 0x110a,
1833 .subdevice = 0x0079,
1834 .name = "Fujitsu Siemens D1289",
1835 .type = AC97_TUNE_HP_ONLY
1838 .subvendor = 0x1019,
1839 .subdevice = 0x0a81,
1840 .name = "ECS K7VTA3",
1841 .type = AC97_TUNE_HP_ONLY
1844 .subvendor = 0x1019,
1845 .subdevice = 0x0a85,
1846 .name = "ECS L7VMM2",
1847 .type = AC97_TUNE_HP_ONLY
1850 .subvendor = 0x1019,
1851 .subdevice = 0x1841,
1852 .name = "ECS K7VTA3",
1853 .type = AC97_TUNE_HP_ONLY
1856 .subvendor = 0x1849,
1857 .subdevice = 0x3059,
1858 .name = "ASRock K7VM2",
1859 .type = AC97_TUNE_HP_ONLY /* VT1616 */
1862 .subvendor = 0x14cd,
1863 .subdevice = 0x7002,
1865 .type = AC97_TUNE_ALC_JACK
1868 .subvendor = 0x1071,
1869 .subdevice = 0x8590,
1870 .name = "Mitac Mobo",
1871 .type = AC97_TUNE_ALC_JACK
1874 .subvendor = 0x161f,
1875 .subdevice = 0x202b,
1876 .name = "Arima Notebook",
1877 .type = AC97_TUNE_HP_ONLY,
1880 .subvendor = 0x161f,
1881 .subdevice = 0x2032,
1882 .name = "Targa Traveller 811",
1883 .type = AC97_TUNE_HP_ONLY,
1886 .subvendor = 0x161f,
1887 .subdevice = 0x2032,
1889 .type = AC97_TUNE_HP_ONLY, /* http://launchpad.net/bugs/38546 */
1892 .subvendor = 0x1297,
1893 .subdevice = 0xa232,
1894 .name = "Shuttle AK32VN",
1895 .type = AC97_TUNE_HP_ONLY
1897 { } /* terminator */
1900 static int snd_via82xx_mixer_new(struct via82xx *chip, const char *quirk_override)
1902 struct snd_ac97_template ac97;
1904 static struct snd_ac97_bus_ops ops = {
1905 .write = snd_via82xx_codec_write,
1906 .read = snd_via82xx_codec_read,
1907 .wait = snd_via82xx_codec_wait,
1910 if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus)) < 0)
1912 chip->ac97_bus->private_free = snd_via82xx_mixer_free_ac97_bus;
1913 chip->ac97_bus->clock = chip->ac97_clock;
1915 memset(&ac97, 0, sizeof(ac97));
1916 ac97.private_data = chip;
1917 ac97.private_free = snd_via82xx_mixer_free_ac97;
1918 ac97.pci = chip->pci;
1919 ac97.scaps = AC97_SCAP_SKIP_MODEM | AC97_SCAP_POWER_SAVE;
1920 if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97)) < 0)
1923 snd_ac97_tune_hardware(chip->ac97, ac97_quirks, quirk_override);
1925 if (chip->chip_type != TYPE_VIA686) {
1926 /* use slot 10/11 */
1927 snd_ac97_update_bits(chip->ac97, AC97_EXTENDED_STATUS, 0x03 << 4, 0x03 << 4);
1933 #ifdef SUPPORT_JOYSTICK
1934 #define JOYSTICK_ADDR 0x200
1935 static int snd_via686_create_gameport(struct via82xx *chip, unsigned char *legacy)
1937 struct gameport *gp;
1943 r = request_region(JOYSTICK_ADDR, 8, "VIA686 gameport");
1945 dev_warn(chip->card->dev, "cannot reserve joystick port %#x\n",
1950 chip->gameport = gp = gameport_allocate_port();
1952 dev_err(chip->card->dev,
1953 "cannot allocate memory for gameport\n");
1954 release_and_free_resource(r);
1958 gameport_set_name(gp, "VIA686 Gameport");
1959 gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci));
1960 gameport_set_dev_parent(gp, &chip->pci->dev);
1961 gp->io = JOYSTICK_ADDR;
1962 gameport_set_port_data(gp, r);
1964 /* Enable legacy joystick port */
1965 *legacy |= VIA_FUNC_ENABLE_GAME;
1966 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, *legacy);
1968 gameport_register_port(chip->gameport);
1973 static void snd_via686_free_gameport(struct via82xx *chip)
1975 if (chip->gameport) {
1976 struct resource *r = gameport_get_port_data(chip->gameport);
1978 gameport_unregister_port(chip->gameport);
1979 chip->gameport = NULL;
1980 release_and_free_resource(r);
1984 static inline int snd_via686_create_gameport(struct via82xx *chip, unsigned char *legacy)
1988 static inline void snd_via686_free_gameport(struct via82xx *chip) { }
1996 static int snd_via8233_init_misc(struct via82xx *chip)
2001 caps = chip->chip_type == TYPE_VIA8233A ? 1 : 2;
2002 for (i = 0; i < caps; i++) {
2003 snd_via8233_capture_source.index = i;
2004 err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_capture_source, chip));
2008 if (ac97_can_spdif(chip->ac97)) {
2009 err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_dxs3_spdif_control, chip));
2013 if (chip->chip_type != TYPE_VIA8233A) {
2014 /* when no h/w PCM volume control is found, use DXS volume control
2015 * as the PCM vol control
2017 struct snd_ctl_elem_id sid;
2018 memset(&sid, 0, sizeof(sid));
2019 strcpy(sid.name, "PCM Playback Volume");
2020 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2021 if (! snd_ctl_find_id(chip->card, &sid)) {
2022 dev_info(chip->card->dev,
2023 "Using DXS as PCM Playback\n");
2024 err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_pcmdxs_volume_control, chip));
2028 else /* Using DXS when PCM emulation is enabled is really weird */
2030 for (i = 0; i < 4; ++i) {
2031 struct snd_kcontrol *kctl;
2033 kctl = snd_ctl_new1(
2034 &snd_via8233_dxs_volume_control, chip);
2037 kctl->id.subdevice = i;
2038 err = snd_ctl_add(chip->card, kctl);
2041 chip->dxs_controls[i] = kctl;
2045 /* select spdif data slot 10/11 */
2046 pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &val);
2047 val = (val & ~VIA8233_SPDIF_SLOT_MASK) | VIA8233_SPDIF_SLOT_1011;
2048 val &= ~VIA8233_SPDIF_DX3; /* SPDIF off as default */
2049 pci_write_config_byte(chip->pci, VIA8233_SPDIF_CTRL, val);
2054 static int snd_via686_init_misc(struct via82xx *chip)
2056 unsigned char legacy, legacy_cfg;
2059 legacy = chip->old_legacy;
2060 legacy_cfg = chip->old_legacy_cfg;
2061 legacy |= VIA_FUNC_MIDI_IRQMASK; /* FIXME: correct? (disable MIDI) */
2062 legacy &= ~VIA_FUNC_ENABLE_GAME; /* disable joystick */
2063 if (chip->revision >= VIA_REV_686_H) {
2065 if (mpu_port >= 0x200) { /* force MIDI */
2067 pci_write_config_dword(chip->pci, 0x18, mpu_port | 0x01);
2068 #ifdef CONFIG_PM_SLEEP
2069 chip->mpu_port_saved = mpu_port;
2072 mpu_port = pci_resource_start(chip->pci, 2);
2075 switch (mpu_port) { /* force MIDI */
2080 legacy_cfg &= ~(3 << 2);
2081 legacy_cfg |= (mpu_port & 0x0030) >> 2;
2083 default: /* no, use BIOS settings */
2084 if (legacy & VIA_FUNC_ENABLE_MIDI)
2085 mpu_port = 0x300 + ((legacy_cfg & 0x000c) << 2);
2089 if (mpu_port >= 0x200 &&
2090 (chip->mpu_res = request_region(mpu_port, 2, "VIA82xx MPU401"))
2093 legacy |= VIA_FUNC_MIDI_PNP; /* enable PCI I/O 2 */
2094 legacy |= VIA_FUNC_ENABLE_MIDI;
2097 legacy &= ~VIA_FUNC_MIDI_PNP; /* disable PCI I/O 2 */
2098 legacy &= ~VIA_FUNC_ENABLE_MIDI;
2102 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy);
2103 pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, legacy_cfg);
2104 if (chip->mpu_res) {
2105 if (snd_mpu401_uart_new(chip->card, 0, MPU401_HW_VIA686A,
2106 mpu_port, MPU401_INFO_INTEGRATED |
2107 MPU401_INFO_IRQ_HOOK, -1,
2108 &chip->rmidi) < 0) {
2109 dev_warn(chip->card->dev,
2110 "unable to initialize MPU-401 at 0x%lx, skipping\n",
2112 legacy &= ~VIA_FUNC_ENABLE_MIDI;
2114 legacy &= ~VIA_FUNC_MIDI_IRQMASK; /* enable MIDI interrupt */
2116 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy);
2119 snd_via686_create_gameport(chip, &legacy);
2121 #ifdef CONFIG_PM_SLEEP
2122 chip->legacy_saved = legacy;
2123 chip->legacy_cfg_saved = legacy_cfg;
2133 static void snd_via82xx_proc_read(struct snd_info_entry *entry,
2134 struct snd_info_buffer *buffer)
2136 struct via82xx *chip = entry->private_data;
2139 snd_iprintf(buffer, "%s\n\n", chip->card->longname);
2140 for (i = 0; i < 0xa0; i += 4) {
2141 snd_iprintf(buffer, "%02x: %08x\n", i, inl(chip->port + i));
2145 static void snd_via82xx_proc_init(struct via82xx *chip)
2147 snd_card_ro_proc_new(chip->card, "via82xx", chip,
2148 snd_via82xx_proc_read);
2155 static int snd_via82xx_chip_init(struct via82xx *chip)
2158 unsigned long end_time;
2161 #if 0 /* broken on K7M? */
2162 if (chip->chip_type == TYPE_VIA686)
2163 /* disable all legacy ports */
2164 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, 0);
2166 pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval);
2167 if (! (pval & VIA_ACLINK_C00_READY)) { /* codec not ready? */
2168 /* deassert ACLink reset, force SYNC */
2169 pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL,
2170 VIA_ACLINK_CTRL_ENABLE |
2171 VIA_ACLINK_CTRL_RESET |
2172 VIA_ACLINK_CTRL_SYNC);
2174 #if 1 /* FIXME: should we do full reset here for all chip models? */
2175 pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL, 0x00);
2178 /* deassert ACLink reset, force SYNC (warm AC'97 reset) */
2179 pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL,
2180 VIA_ACLINK_CTRL_RESET|VIA_ACLINK_CTRL_SYNC);
2183 /* ACLink on, deassert ACLink reset, VSR, SGD data out */
2184 /* note - FM data out has trouble with non VRA codecs !! */
2185 pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL, VIA_ACLINK_CTRL_INIT);
2189 /* Make sure VRA is enabled, in case we didn't do a
2190 * complete codec reset, above */
2191 pci_read_config_byte(chip->pci, VIA_ACLINK_CTRL, &pval);
2192 if ((pval & VIA_ACLINK_CTRL_INIT) != VIA_ACLINK_CTRL_INIT) {
2193 /* ACLink on, deassert ACLink reset, VSR, SGD data out */
2194 /* note - FM data out has trouble with non VRA codecs !! */
2195 pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL, VIA_ACLINK_CTRL_INIT);
2199 /* wait until codec ready */
2200 end_time = jiffies + msecs_to_jiffies(750);
2202 pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval);
2203 if (pval & VIA_ACLINK_C00_READY) /* primary codec ready */
2205 schedule_timeout_uninterruptible(1);
2206 } while (time_before(jiffies, end_time));
2208 if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY)
2209 dev_err(chip->card->dev,
2210 "AC'97 codec is not ready [0x%x]\n", val);
2212 #if 0 /* FIXME: we don't support the second codec yet so skip the detection now.. */
2213 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ |
2214 VIA_REG_AC97_SECONDARY_VALID |
2215 (VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT));
2216 end_time = jiffies + msecs_to_jiffies(750);
2217 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ |
2218 VIA_REG_AC97_SECONDARY_VALID |
2219 (VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT));
2221 if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_SECONDARY_VALID) {
2222 chip->ac97_secondary = 1;
2225 schedule_timeout_uninterruptible(1);
2226 } while (time_before(jiffies, end_time));
2227 /* This is ok, the most of motherboards have only one codec */
2232 if (chip->chip_type == TYPE_VIA686) {
2233 /* route FM trap to IRQ, disable FM trap */
2234 pci_write_config_byte(chip->pci, VIA_FM_NMI_CTRL, 0);
2235 /* disable all GPI interrupts */
2236 outl(0, VIAREG(chip, GPI_INTR));
2239 if (chip->chip_type != TYPE_VIA686) {
2240 /* Workaround for Award BIOS bug:
2241 * DXS channels don't work properly with VRA if MC97 is disabled.
2243 struct pci_dev *pci;
2244 pci = pci_get_device(0x1106, 0x3068, NULL); /* MC97 */
2247 pci_read_config_byte(pci, 0x44, &data);
2248 pci_write_config_byte(pci, 0x44, data | 0x40);
2253 if (chip->chip_type != TYPE_VIA8233A) {
2255 for (idx = 0; idx < 4; idx++) {
2256 unsigned long port = chip->port + 0x10 * idx;
2257 for (i = 0; i < 2; i++) {
2258 chip->playback_volume[idx][i]=chip->playback_volume_c[i];
2259 outb(chip->playback_volume_c[i],
2260 port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i);
2268 #ifdef CONFIG_PM_SLEEP
2272 static int snd_via82xx_suspend(struct device *dev)
2274 struct snd_card *card = dev_get_drvdata(dev);
2275 struct via82xx *chip = card->private_data;
2278 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
2279 for (i = 0; i < chip->num_devs; i++)
2280 snd_via82xx_channel_reset(chip, &chip->devs[i]);
2281 synchronize_irq(chip->irq);
2282 snd_ac97_suspend(chip->ac97);
2284 /* save misc values */
2285 if (chip->chip_type != TYPE_VIA686) {
2286 pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &chip->spdif_ctrl_saved);
2287 chip->capture_src_saved[0] = inb(chip->port + VIA_REG_CAPTURE_CHANNEL);
2288 chip->capture_src_saved[1] = inb(chip->port + VIA_REG_CAPTURE_CHANNEL + 0x10);
2294 static int snd_via82xx_resume(struct device *dev)
2296 struct snd_card *card = dev_get_drvdata(dev);
2297 struct via82xx *chip = card->private_data;
2300 snd_via82xx_chip_init(chip);
2302 if (chip->chip_type == TYPE_VIA686) {
2303 if (chip->mpu_port_saved)
2304 pci_write_config_dword(chip->pci, 0x18, chip->mpu_port_saved | 0x01);
2305 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, chip->legacy_saved);
2306 pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, chip->legacy_cfg_saved);
2308 pci_write_config_byte(chip->pci, VIA8233_SPDIF_CTRL, chip->spdif_ctrl_saved);
2309 outb(chip->capture_src_saved[0], chip->port + VIA_REG_CAPTURE_CHANNEL);
2310 outb(chip->capture_src_saved[1], chip->port + VIA_REG_CAPTURE_CHANNEL + 0x10);
2313 snd_ac97_resume(chip->ac97);
2315 for (i = 0; i < chip->num_devs; i++)
2316 snd_via82xx_channel_reset(chip, &chip->devs[i]);
2318 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
2322 static SIMPLE_DEV_PM_OPS(snd_via82xx_pm, snd_via82xx_suspend, snd_via82xx_resume);
2323 #define SND_VIA82XX_PM_OPS &snd_via82xx_pm
2325 #define SND_VIA82XX_PM_OPS NULL
2326 #endif /* CONFIG_PM_SLEEP */
2328 static int snd_via82xx_free(struct via82xx *chip)
2334 /* disable interrupts */
2335 for (i = 0; i < chip->num_devs; i++)
2336 snd_via82xx_channel_reset(chip, &chip->devs[i]);
2339 free_irq(chip->irq, chip);
2341 release_and_free_resource(chip->mpu_res);
2342 pci_release_regions(chip->pci);
2344 if (chip->chip_type == TYPE_VIA686) {
2345 snd_via686_free_gameport(chip);
2346 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, chip->old_legacy);
2347 pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, chip->old_legacy_cfg);
2349 pci_disable_device(chip->pci);
2354 static int snd_via82xx_dev_free(struct snd_device *device)
2356 struct via82xx *chip = device->device_data;
2357 return snd_via82xx_free(chip);
2360 static int snd_via82xx_create(struct snd_card *card,
2361 struct pci_dev *pci,
2364 unsigned int ac97_clock,
2365 struct via82xx **r_via)
2367 struct via82xx *chip;
2369 static struct snd_device_ops ops = {
2370 .dev_free = snd_via82xx_dev_free,
2373 if ((err = pci_enable_device(pci)) < 0)
2376 if ((chip = kzalloc(sizeof(*chip), GFP_KERNEL)) == NULL) {
2377 pci_disable_device(pci);
2381 chip->chip_type = chip_type;
2382 chip->revision = revision;
2384 spin_lock_init(&chip->reg_lock);
2385 spin_lock_init(&chip->rates[0].lock);
2386 spin_lock_init(&chip->rates[1].lock);
2391 pci_read_config_byte(pci, VIA_FUNC_ENABLE, &chip->old_legacy);
2392 pci_read_config_byte(pci, VIA_PNP_CONTROL, &chip->old_legacy_cfg);
2393 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE,
2394 chip->old_legacy & ~(VIA_FUNC_ENABLE_SB|VIA_FUNC_ENABLE_FM));
2396 if ((err = pci_request_regions(pci, card->driver)) < 0) {
2398 pci_disable_device(pci);
2401 chip->port = pci_resource_start(pci, 0);
2402 if (request_irq(pci->irq,
2403 chip_type == TYPE_VIA8233 ?
2404 snd_via8233_interrupt : snd_via686_interrupt,
2406 KBUILD_MODNAME, chip)) {
2407 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
2408 snd_via82xx_free(chip);
2411 chip->irq = pci->irq;
2412 if (ac97_clock >= 8000 && ac97_clock <= 48000)
2413 chip->ac97_clock = ac97_clock;
2414 synchronize_irq(chip->irq);
2416 if ((err = snd_via82xx_chip_init(chip)) < 0) {
2417 snd_via82xx_free(chip);
2421 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
2422 snd_via82xx_free(chip);
2426 /* The 8233 ac97 controller does not implement the master bit
2427 * in the pci command register. IMHO this is a violation of the PCI spec.
2428 * We call pci_set_master here because it does not hurt. */
2429 pci_set_master(pci);
2435 struct via823x_info {
2440 static struct via823x_info via823x_cards[] = {
2441 { VIA_REV_PRE_8233, "VIA 8233-Pre", TYPE_VIA8233 },
2442 { VIA_REV_8233C, "VIA 8233C", TYPE_VIA8233 },
2443 { VIA_REV_8233, "VIA 8233", TYPE_VIA8233 },
2444 { VIA_REV_8233A, "VIA 8233A", TYPE_VIA8233A },
2445 { VIA_REV_8235, "VIA 8235", TYPE_VIA8233 },
2446 { VIA_REV_8237, "VIA 8237", TYPE_VIA8233 },
2447 { VIA_REV_8251, "VIA 8251", TYPE_VIA8233 },
2451 * auto detection of DXS channel supports.
2454 static struct snd_pci_quirk dxs_whitelist[] = {
2455 SND_PCI_QUIRK(0x1005, 0x4710, "Avance Logic Mobo", VIA_DXS_ENABLE),
2456 SND_PCI_QUIRK(0x1019, 0x0996, "ESC Mobo", VIA_DXS_48K),
2457 SND_PCI_QUIRK(0x1019, 0x0a81, "ECS K7VTA3 v8.0", VIA_DXS_NO_VRA),
2458 SND_PCI_QUIRK(0x1019, 0x0a85, "ECS L7VMM2", VIA_DXS_NO_VRA),
2459 SND_PCI_QUIRK_VENDOR(0x1019, "ESC K8", VIA_DXS_SRC),
2460 SND_PCI_QUIRK(0x1019, 0xaa01, "ESC K8T890-A", VIA_DXS_SRC),
2461 SND_PCI_QUIRK(0x1025, 0x0033, "Acer Inspire 1353LM", VIA_DXS_NO_VRA),
2462 SND_PCI_QUIRK(0x1025, 0x0046, "Acer Aspire 1524 WLMi", VIA_DXS_SRC),
2463 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS A7/A8", VIA_DXS_NO_VRA),
2464 SND_PCI_QUIRK_VENDOR(0x1071, "Diverse Notebook", VIA_DXS_NO_VRA),
2465 SND_PCI_QUIRK(0x10cf, 0x118e, "FSC Laptop", VIA_DXS_ENABLE),
2466 SND_PCI_QUIRK_VENDOR(0x1106, "ASRock", VIA_DXS_SRC),
2467 SND_PCI_QUIRK(0x1297, 0xa231, "Shuttle AK31v2", VIA_DXS_SRC),
2468 SND_PCI_QUIRK(0x1297, 0xa232, "Shuttle", VIA_DXS_SRC),
2469 SND_PCI_QUIRK(0x1297, 0xc160, "Shuttle Sk41G", VIA_DXS_SRC),
2470 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte GA-7VAXP", VIA_DXS_ENABLE),
2471 SND_PCI_QUIRK(0x1462, 0x3800, "MSI KT266", VIA_DXS_ENABLE),
2472 SND_PCI_QUIRK(0x1462, 0x7120, "MSI KT4V", VIA_DXS_ENABLE),
2473 SND_PCI_QUIRK(0x1462, 0x7142, "MSI K8MM-V", VIA_DXS_ENABLE),
2474 SND_PCI_QUIRK_VENDOR(0x1462, "MSI Mobo", VIA_DXS_SRC),
2475 SND_PCI_QUIRK(0x147b, 0x1401, "ABIT KD7(-RAID)", VIA_DXS_ENABLE),
2476 SND_PCI_QUIRK(0x147b, 0x1411, "ABIT VA-20", VIA_DXS_ENABLE),
2477 SND_PCI_QUIRK(0x147b, 0x1413, "ABIT KV8 Pro", VIA_DXS_ENABLE),
2478 SND_PCI_QUIRK(0x147b, 0x1415, "ABIT AV8", VIA_DXS_NO_VRA),
2479 SND_PCI_QUIRK(0x14ff, 0x0403, "Twinhead mobo", VIA_DXS_ENABLE),
2480 SND_PCI_QUIRK(0x14ff, 0x0408, "Twinhead laptop", VIA_DXS_SRC),
2481 SND_PCI_QUIRK(0x1558, 0x4701, "Clevo D470", VIA_DXS_SRC),
2482 SND_PCI_QUIRK(0x1584, 0x8120, "Diverse Laptop", VIA_DXS_ENABLE),
2483 SND_PCI_QUIRK(0x1584, 0x8123, "Targa/Uniwill", VIA_DXS_NO_VRA),
2484 SND_PCI_QUIRK(0x161f, 0x202b, "Amira Notebook", VIA_DXS_NO_VRA),
2485 SND_PCI_QUIRK(0x161f, 0x2032, "m680x machines", VIA_DXS_48K),
2486 SND_PCI_QUIRK(0x1631, 0xe004, "PB EasyNote 3174", VIA_DXS_ENABLE),
2487 SND_PCI_QUIRK(0x1695, 0x3005, "EPoX EP-8K9A", VIA_DXS_ENABLE),
2488 SND_PCI_QUIRK_VENDOR(0x1695, "EPoX mobo", VIA_DXS_SRC),
2489 SND_PCI_QUIRK_VENDOR(0x16f3, "Jetway K8", VIA_DXS_SRC),
2490 SND_PCI_QUIRK_VENDOR(0x1734, "FSC Laptop", VIA_DXS_SRC),
2491 SND_PCI_QUIRK(0x1849, 0x3059, "ASRock K7VM2", VIA_DXS_NO_VRA),
2492 SND_PCI_QUIRK_VENDOR(0x1849, "ASRock mobo", VIA_DXS_SRC),
2493 SND_PCI_QUIRK(0x1919, 0x200a, "Soltek SL-K8", VIA_DXS_NO_VRA),
2494 SND_PCI_QUIRK(0x4005, 0x4710, "MSI K7T266", VIA_DXS_SRC),
2495 { } /* terminator */
2498 static int check_dxs_list(struct pci_dev *pci, int revision)
2500 const struct snd_pci_quirk *w;
2502 w = snd_pci_quirk_lookup(pci, dxs_whitelist);
2504 dev_dbg(&pci->dev, "DXS white list for %s found\n",
2505 snd_pci_quirk_name(w));
2509 /* for newer revision, default to DXS_SRC */
2510 if (revision >= VIA_REV_8235)
2514 * not detected, try 48k rate only to be sure.
2516 dev_info(&pci->dev, "Assuming DXS channels with 48k fixed sample rate.\n");
2517 dev_info(&pci->dev, " Please try dxs_support=5 option\n");
2518 dev_info(&pci->dev, " and report if it works on your machine.\n");
2519 dev_info(&pci->dev, " For more details, read ALSA-Configuration.txt.\n");
2523 static int snd_via82xx_probe(struct pci_dev *pci,
2524 const struct pci_device_id *pci_id)
2526 struct snd_card *card;
2527 struct via82xx *chip;
2528 int chip_type = 0, card_type;
2532 err = snd_card_new(&pci->dev, index, id, THIS_MODULE, 0, &card);
2536 card_type = pci_id->driver_data;
2537 switch (card_type) {
2538 case TYPE_CARD_VIA686:
2539 strcpy(card->driver, "VIA686A");
2540 sprintf(card->shortname, "VIA 82C686A/B rev%x", pci->revision);
2541 chip_type = TYPE_VIA686;
2543 case TYPE_CARD_VIA8233:
2544 chip_type = TYPE_VIA8233;
2545 sprintf(card->shortname, "VIA 823x rev%x", pci->revision);
2546 for (i = 0; i < ARRAY_SIZE(via823x_cards); i++) {
2547 if (pci->revision == via823x_cards[i].revision) {
2548 chip_type = via823x_cards[i].type;
2549 strcpy(card->shortname, via823x_cards[i].name);
2553 if (chip_type != TYPE_VIA8233A) {
2554 if (dxs_support == VIA_DXS_AUTO)
2555 dxs_support = check_dxs_list(pci, pci->revision);
2556 /* force to use VIA8233 or 8233A model according to
2557 * dxs_support module option
2559 if (dxs_support == VIA_DXS_DISABLE)
2560 chip_type = TYPE_VIA8233A;
2562 chip_type = TYPE_VIA8233;
2564 if (chip_type == TYPE_VIA8233A)
2565 strcpy(card->driver, "VIA8233A");
2566 else if (pci->revision >= VIA_REV_8237)
2567 strcpy(card->driver, "VIA8237"); /* no slog assignment */
2569 strcpy(card->driver, "VIA8233");
2572 dev_err(card->dev, "invalid card type %d\n", card_type);
2577 if ((err = snd_via82xx_create(card, pci, chip_type, pci->revision,
2578 ac97_clock, &chip)) < 0)
2580 card->private_data = chip;
2581 if ((err = snd_via82xx_mixer_new(chip, ac97_quirk)) < 0)
2584 if (chip_type == TYPE_VIA686) {
2585 if ((err = snd_via686_pcm_new(chip)) < 0 ||
2586 (err = snd_via686_init_misc(chip)) < 0)
2589 if (chip_type == TYPE_VIA8233A) {
2590 if ((err = snd_via8233a_pcm_new(chip)) < 0)
2592 // chip->dxs_fixed = 1; /* FIXME: use 48k for DXS #3? */
2594 if ((err = snd_via8233_pcm_new(chip)) < 0)
2596 if (dxs_support == VIA_DXS_48K)
2597 chip->dxs_fixed = 1;
2598 else if (dxs_support == VIA_DXS_NO_VRA)
2600 else if (dxs_support == VIA_DXS_SRC) {
2605 if ((err = snd_via8233_init_misc(chip)) < 0)
2609 /* disable interrupts */
2610 for (i = 0; i < chip->num_devs; i++)
2611 snd_via82xx_channel_reset(chip, &chip->devs[i]);
2613 snprintf(card->longname, sizeof(card->longname),
2614 "%s with %s at %#lx, irq %d", card->shortname,
2615 snd_ac97_get_short_name(chip->ac97), chip->port, chip->irq);
2617 snd_via82xx_proc_init(chip);
2619 if ((err = snd_card_register(card)) < 0) {
2620 snd_card_free(card);
2623 pci_set_drvdata(pci, card);
2627 snd_card_free(card);
2631 static void snd_via82xx_remove(struct pci_dev *pci)
2633 snd_card_free(pci_get_drvdata(pci));
2636 static struct pci_driver via82xx_driver = {
2637 .name = KBUILD_MODNAME,
2638 .id_table = snd_via82xx_ids,
2639 .probe = snd_via82xx_probe,
2640 .remove = snd_via82xx_remove,
2642 .pm = SND_VIA82XX_PM_OPS,
2646 module_pci_driver(via82xx_driver);