11a59d1b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * ALSA driver for VIA VT82xx (South Bridge)
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds * VT82C686A/B/C, VT8233A/C, VT8235
61da177e4SLinus Torvalds *
7c1017a4cSJaroslav Kysela * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
81da177e4SLinus Torvalds * Tjeerd.Mulder <Tjeerd.Mulder@fujitsu-siemens.com>
91da177e4SLinus Torvalds * 2002 Takashi Iwai <tiwai@suse.de>
101da177e4SLinus Torvalds */
111da177e4SLinus Torvalds
121da177e4SLinus Torvalds /*
131da177e4SLinus Torvalds * Changes:
141da177e4SLinus Torvalds *
151da177e4SLinus Torvalds * Dec. 19, 2002 Takashi Iwai <tiwai@suse.de>
161da177e4SLinus Torvalds * - use the DSX channels for the first pcm playback.
171da177e4SLinus Torvalds * (on VIA8233, 8233C and 8235 only)
181da177e4SLinus Torvalds * this will allow you play simultaneously up to 4 streams.
191da177e4SLinus Torvalds * multi-channel playback is assigned to the second device
201da177e4SLinus Torvalds * on these chips.
211da177e4SLinus Torvalds * - support the secondary capture (on VIA8233/C,8235)
221da177e4SLinus Torvalds * - SPDIF support
231da177e4SLinus Torvalds * the DSX3 channel can be used for SPDIF output.
241da177e4SLinus Torvalds * on VIA8233A, this channel is assigned to the second pcm
251da177e4SLinus Torvalds * playback.
261da177e4SLinus Torvalds * the card config of alsa-lib will assign the correct
271da177e4SLinus Torvalds * device for applications.
281da177e4SLinus Torvalds * - clean up the code, separate low-level initialization
291da177e4SLinus Torvalds * routines for each chipset.
304f550df5SKarsten Wiese *
314f550df5SKarsten Wiese * Sep. 26, 2005 Karsten Wiese <annabellesgarden@yahoo.de>
324f550df5SKarsten Wiese * - Optimize position calculation for the 823x chips.
331da177e4SLinus Torvalds */
341da177e4SLinus Torvalds
356cbbfe1cSTakashi Iwai #include <linux/io.h>
361da177e4SLinus Torvalds #include <linux/delay.h>
371da177e4SLinus Torvalds #include <linux/interrupt.h>
381da177e4SLinus Torvalds #include <linux/init.h>
391da177e4SLinus Torvalds #include <linux/pci.h>
401da177e4SLinus Torvalds #include <linux/slab.h>
411da177e4SLinus Torvalds #include <linux/gameport.h>
4265a77217SPaul Gortmaker #include <linux/module.h>
431da177e4SLinus Torvalds #include <sound/core.h>
441da177e4SLinus Torvalds #include <sound/pcm.h>
451da177e4SLinus Torvalds #include <sound/pcm_params.h>
461da177e4SLinus Torvalds #include <sound/info.h>
477058c042STakashi Iwai #include <sound/tlv.h>
481da177e4SLinus Torvalds #include <sound/ac97_codec.h>
491da177e4SLinus Torvalds #include <sound/mpu401.h>
501da177e4SLinus Torvalds #include <sound/initval.h>
511da177e4SLinus Torvalds
521da177e4SLinus Torvalds #if 0
531da177e4SLinus Torvalds #define POINTER_DEBUG
541da177e4SLinus Torvalds #endif
551da177e4SLinus Torvalds
56c1017a4cSJaroslav Kysela MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
571da177e4SLinus Torvalds MODULE_DESCRIPTION("VIA VT82xx audio");
581da177e4SLinus Torvalds MODULE_LICENSE("GPL");
591da177e4SLinus Torvalds
60b2fac073SFabian Frederick #if IS_REACHABLE(CONFIG_GAMEPORT)
611da177e4SLinus Torvalds #define SUPPORT_JOYSTICK 1
621da177e4SLinus Torvalds #endif
631da177e4SLinus Torvalds
64b7fe4622SClemens Ladisch static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
65b7fe4622SClemens Ladisch static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
66b7fe4622SClemens Ladisch static long mpu_port;
671da177e4SLinus Torvalds #ifdef SUPPORT_JOYSTICK
68a67ff6a5SRusty Russell static bool joystick;
691da177e4SLinus Torvalds #endif
70b7fe4622SClemens Ladisch static int ac97_clock = 48000;
71b7fe4622SClemens Ladisch static char *ac97_quirk;
72b7fe4622SClemens Ladisch static int dxs_support;
73395c61d1SClemens Ladisch static int dxs_init_volume = 31;
74115551d9SSimon Arlott static int nodelay;
751da177e4SLinus Torvalds
76b7fe4622SClemens Ladisch module_param(index, int, 0444);
771da177e4SLinus Torvalds MODULE_PARM_DESC(index, "Index value for VIA 82xx bridge.");
78b7fe4622SClemens Ladisch module_param(id, charp, 0444);
791da177e4SLinus Torvalds MODULE_PARM_DESC(id, "ID string for VIA 82xx bridge.");
806192c41fSDavid Howells module_param_hw(mpu_port, long, ioport, 0444);
811da177e4SLinus Torvalds MODULE_PARM_DESC(mpu_port, "MPU-401 port. (VT82C686x only)");
821da177e4SLinus Torvalds #ifdef SUPPORT_JOYSTICK
83b7fe4622SClemens Ladisch module_param(joystick, bool, 0444);
841da177e4SLinus Torvalds MODULE_PARM_DESC(joystick, "Enable joystick. (VT82C686x only)");
851da177e4SLinus Torvalds #endif
86b7fe4622SClemens Ladisch module_param(ac97_clock, int, 0444);
871da177e4SLinus Torvalds MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz).");
88b7fe4622SClemens Ladisch module_param(ac97_quirk, charp, 0444);
891da177e4SLinus Torvalds MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware.");
90b7fe4622SClemens Ladisch module_param(dxs_support, int, 0444);
912d7eb7cbSSergey Vlasov 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)");
92395c61d1SClemens Ladisch module_param(dxs_init_volume, int, 0644);
93395c61d1SClemens Ladisch MODULE_PARM_DESC(dxs_init_volume, "initial DXS volume (0-31)");
94115551d9SSimon Arlott module_param(nodelay, int, 0444);
95115551d9SSimon Arlott MODULE_PARM_DESC(nodelay, "Disable 500ms init delay");
961da177e4SLinus Torvalds
972b3e584bSTakashi Iwai /* just for backward compatibility */
98a67ff6a5SRusty Russell static bool enable;
99698444f3STakashi Iwai module_param(enable, bool, 0444);
1002b3e584bSTakashi Iwai
1011da177e4SLinus Torvalds
1021da177e4SLinus Torvalds /* revision numbers for via686 */
1031da177e4SLinus Torvalds #define VIA_REV_686_A 0x10
1041da177e4SLinus Torvalds #define VIA_REV_686_B 0x11
1051da177e4SLinus Torvalds #define VIA_REV_686_C 0x12
1061da177e4SLinus Torvalds #define VIA_REV_686_D 0x13
1071da177e4SLinus Torvalds #define VIA_REV_686_E 0x14
1081da177e4SLinus Torvalds #define VIA_REV_686_H 0x20
1091da177e4SLinus Torvalds
1101da177e4SLinus Torvalds /* revision numbers for via8233 */
1111da177e4SLinus Torvalds #define VIA_REV_PRE_8233 0x10 /* not in market */
1121da177e4SLinus Torvalds #define VIA_REV_8233C 0x20 /* 2 rec, 4 pb, 1 multi-pb */
1131da177e4SLinus Torvalds #define VIA_REV_8233 0x30 /* 2 rec, 4 pb, 1 multi-pb, spdif */
1141da177e4SLinus Torvalds #define VIA_REV_8233A 0x40 /* 1 rec, 1 multi-pb, spdf */
1151da177e4SLinus Torvalds #define VIA_REV_8235 0x50 /* 2 rec, 4 pb, 1 multi-pb, spdif */
1161da177e4SLinus Torvalds #define VIA_REV_8237 0x60
1178263c65fSBastiaan Jacques #define VIA_REV_8251 0x70
1181da177e4SLinus Torvalds
1191da177e4SLinus Torvalds /*
1201da177e4SLinus Torvalds * Direct registers
1211da177e4SLinus Torvalds */
1221da177e4SLinus Torvalds
1231da177e4SLinus Torvalds #define VIAREG(via, x) ((via)->port + VIA_REG_##x)
1241da177e4SLinus Torvalds #define VIADEV_REG(viadev, x) ((viadev)->port + VIA_REG_##x)
1251da177e4SLinus Torvalds
1261da177e4SLinus Torvalds /* common offsets */
1271da177e4SLinus Torvalds #define VIA_REG_OFFSET_STATUS 0x00 /* byte - channel status */
1281da177e4SLinus Torvalds #define VIA_REG_STAT_ACTIVE 0x80 /* RO */
1294f550df5SKarsten Wiese #define VIA8233_SHADOW_STAT_ACTIVE 0x08 /* RO */
1301da177e4SLinus Torvalds #define VIA_REG_STAT_PAUSED 0x40 /* RO */
1311da177e4SLinus Torvalds #define VIA_REG_STAT_TRIGGER_QUEUED 0x08 /* RO */
1321da177e4SLinus Torvalds #define VIA_REG_STAT_STOPPED 0x04 /* RWC */
1331da177e4SLinus Torvalds #define VIA_REG_STAT_EOL 0x02 /* RWC */
1341da177e4SLinus Torvalds #define VIA_REG_STAT_FLAG 0x01 /* RWC */
1351da177e4SLinus Torvalds #define VIA_REG_OFFSET_CONTROL 0x01 /* byte - channel control */
1361da177e4SLinus Torvalds #define VIA_REG_CTRL_START 0x80 /* WO */
1371da177e4SLinus Torvalds #define VIA_REG_CTRL_TERMINATE 0x40 /* WO */
1381da177e4SLinus Torvalds #define VIA_REG_CTRL_AUTOSTART 0x20
1391da177e4SLinus Torvalds #define VIA_REG_CTRL_PAUSE 0x08 /* RW */
1401da177e4SLinus Torvalds #define VIA_REG_CTRL_INT_STOP 0x04
1411da177e4SLinus Torvalds #define VIA_REG_CTRL_INT_EOL 0x02
1421da177e4SLinus Torvalds #define VIA_REG_CTRL_INT_FLAG 0x01
1431da177e4SLinus Torvalds #define VIA_REG_CTRL_RESET 0x01 /* RW - probably reset? undocumented */
1441da177e4SLinus Torvalds #define VIA_REG_CTRL_INT (VIA_REG_CTRL_INT_FLAG | VIA_REG_CTRL_INT_EOL | VIA_REG_CTRL_AUTOSTART)
1451da177e4SLinus Torvalds #define VIA_REG_OFFSET_TYPE 0x02 /* byte - channel type (686 only) */
1461da177e4SLinus Torvalds #define VIA_REG_TYPE_AUTOSTART 0x80 /* RW - autostart at EOL */
1471da177e4SLinus Torvalds #define VIA_REG_TYPE_16BIT 0x20 /* RW */
1481da177e4SLinus Torvalds #define VIA_REG_TYPE_STEREO 0x10 /* RW */
1491da177e4SLinus Torvalds #define VIA_REG_TYPE_INT_LLINE 0x00
1501da177e4SLinus Torvalds #define VIA_REG_TYPE_INT_LSAMPLE 0x04
1511da177e4SLinus Torvalds #define VIA_REG_TYPE_INT_LESSONE 0x08
1521da177e4SLinus Torvalds #define VIA_REG_TYPE_INT_MASK 0x0c
1531da177e4SLinus Torvalds #define VIA_REG_TYPE_INT_EOL 0x02
1541da177e4SLinus Torvalds #define VIA_REG_TYPE_INT_FLAG 0x01
1551da177e4SLinus Torvalds #define VIA_REG_OFFSET_TABLE_PTR 0x04 /* dword - channel table pointer */
1561da177e4SLinus Torvalds #define VIA_REG_OFFSET_CURR_PTR 0x04 /* dword - channel current pointer */
1571da177e4SLinus Torvalds #define VIA_REG_OFFSET_STOP_IDX 0x08 /* dword - stop index, channel type, sample rate */
1581da177e4SLinus Torvalds #define VIA8233_REG_TYPE_16BIT 0x00200000 /* RW */
1591da177e4SLinus Torvalds #define VIA8233_REG_TYPE_STEREO 0x00100000 /* RW */
1601da177e4SLinus Torvalds #define VIA_REG_OFFSET_CURR_COUNT 0x0c /* dword - channel current count (24 bit) */
1611da177e4SLinus Torvalds #define VIA_REG_OFFSET_CURR_INDEX 0x0f /* byte - channel current index (for via8233 only) */
1621da177e4SLinus Torvalds
1631da177e4SLinus Torvalds #define DEFINE_VIA_REGSET(name,val) \
1641da177e4SLinus Torvalds enum {\
1651da177e4SLinus Torvalds VIA_REG_##name##_STATUS = (val),\
1661da177e4SLinus Torvalds VIA_REG_##name##_CONTROL = (val) + 0x01,\
1671da177e4SLinus Torvalds VIA_REG_##name##_TYPE = (val) + 0x02,\
1681da177e4SLinus Torvalds VIA_REG_##name##_TABLE_PTR = (val) + 0x04,\
1691da177e4SLinus Torvalds VIA_REG_##name##_CURR_PTR = (val) + 0x04,\
1701da177e4SLinus Torvalds VIA_REG_##name##_STOP_IDX = (val) + 0x08,\
1711da177e4SLinus Torvalds VIA_REG_##name##_CURR_COUNT = (val) + 0x0c,\
1721da177e4SLinus Torvalds }
1731da177e4SLinus Torvalds
1741da177e4SLinus Torvalds /* playback block */
1751da177e4SLinus Torvalds DEFINE_VIA_REGSET(PLAYBACK, 0x00);
1761da177e4SLinus Torvalds DEFINE_VIA_REGSET(CAPTURE, 0x10);
1771da177e4SLinus Torvalds DEFINE_VIA_REGSET(FM, 0x20);
1781da177e4SLinus Torvalds
1791da177e4SLinus Torvalds /* AC'97 */
1801da177e4SLinus Torvalds #define VIA_REG_AC97 0x80 /* dword */
1811da177e4SLinus Torvalds #define VIA_REG_AC97_CODEC_ID_MASK (3<<30)
1821da177e4SLinus Torvalds #define VIA_REG_AC97_CODEC_ID_SHIFT 30
1831da177e4SLinus Torvalds #define VIA_REG_AC97_CODEC_ID_PRIMARY 0x00
1841da177e4SLinus Torvalds #define VIA_REG_AC97_CODEC_ID_SECONDARY 0x01
1851da177e4SLinus Torvalds #define VIA_REG_AC97_SECONDARY_VALID (1<<27)
1861da177e4SLinus Torvalds #define VIA_REG_AC97_PRIMARY_VALID (1<<25)
1871da177e4SLinus Torvalds #define VIA_REG_AC97_BUSY (1<<24)
1881da177e4SLinus Torvalds #define VIA_REG_AC97_READ (1<<23)
1891da177e4SLinus Torvalds #define VIA_REG_AC97_CMD_SHIFT 16
1901da177e4SLinus Torvalds #define VIA_REG_AC97_CMD_MASK 0x7e
1911da177e4SLinus Torvalds #define VIA_REG_AC97_DATA_SHIFT 0
1921da177e4SLinus Torvalds #define VIA_REG_AC97_DATA_MASK 0xffff
1931da177e4SLinus Torvalds
1941da177e4SLinus Torvalds #define VIA_REG_SGD_SHADOW 0x84 /* dword */
1951da177e4SLinus Torvalds /* via686 */
1961da177e4SLinus Torvalds #define VIA_REG_SGD_STAT_PB_FLAG (1<<0)
1971da177e4SLinus Torvalds #define VIA_REG_SGD_STAT_CP_FLAG (1<<1)
1981da177e4SLinus Torvalds #define VIA_REG_SGD_STAT_FM_FLAG (1<<2)
1991da177e4SLinus Torvalds #define VIA_REG_SGD_STAT_PB_EOL (1<<4)
2001da177e4SLinus Torvalds #define VIA_REG_SGD_STAT_CP_EOL (1<<5)
2011da177e4SLinus Torvalds #define VIA_REG_SGD_STAT_FM_EOL (1<<6)
2021da177e4SLinus Torvalds #define VIA_REG_SGD_STAT_PB_STOP (1<<8)
2031da177e4SLinus Torvalds #define VIA_REG_SGD_STAT_CP_STOP (1<<9)
2041da177e4SLinus Torvalds #define VIA_REG_SGD_STAT_FM_STOP (1<<10)
2051da177e4SLinus Torvalds #define VIA_REG_SGD_STAT_PB_ACTIVE (1<<12)
2061da177e4SLinus Torvalds #define VIA_REG_SGD_STAT_CP_ACTIVE (1<<13)
2071da177e4SLinus Torvalds #define VIA_REG_SGD_STAT_FM_ACTIVE (1<<14)
2081da177e4SLinus Torvalds /* via8233 */
2091da177e4SLinus Torvalds #define VIA8233_REG_SGD_STAT_FLAG (1<<0)
2101da177e4SLinus Torvalds #define VIA8233_REG_SGD_STAT_EOL (1<<1)
2111da177e4SLinus Torvalds #define VIA8233_REG_SGD_STAT_STOP (1<<2)
2121da177e4SLinus Torvalds #define VIA8233_REG_SGD_STAT_ACTIVE (1<<3)
2131da177e4SLinus Torvalds #define VIA8233_INTR_MASK(chan) ((VIA8233_REG_SGD_STAT_FLAG|VIA8233_REG_SGD_STAT_EOL) << ((chan) * 4))
2141da177e4SLinus Torvalds #define VIA8233_REG_SGD_CHAN_SDX 0
2151da177e4SLinus Torvalds #define VIA8233_REG_SGD_CHAN_MULTI 4
2161da177e4SLinus Torvalds #define VIA8233_REG_SGD_CHAN_REC 6
2171da177e4SLinus Torvalds #define VIA8233_REG_SGD_CHAN_REC1 7
2181da177e4SLinus Torvalds
2191da177e4SLinus Torvalds #define VIA_REG_GPI_STATUS 0x88
2201da177e4SLinus Torvalds #define VIA_REG_GPI_INTR 0x8c
2211da177e4SLinus Torvalds
2221da177e4SLinus Torvalds /* multi-channel and capture registers for via8233 */
2231da177e4SLinus Torvalds DEFINE_VIA_REGSET(MULTPLAY, 0x40);
2241da177e4SLinus Torvalds DEFINE_VIA_REGSET(CAPTURE_8233, 0x60);
2251da177e4SLinus Torvalds
2261da177e4SLinus Torvalds /* via8233-specific registers */
2271da177e4SLinus Torvalds #define VIA_REG_OFS_PLAYBACK_VOLUME_L 0x02 /* byte */
2281da177e4SLinus Torvalds #define VIA_REG_OFS_PLAYBACK_VOLUME_R 0x03 /* byte */
2291da177e4SLinus Torvalds #define VIA_REG_OFS_MULTPLAY_FORMAT 0x02 /* byte - format and channels */
2301da177e4SLinus Torvalds #define VIA_REG_MULTPLAY_FMT_8BIT 0x00
2311da177e4SLinus Torvalds #define VIA_REG_MULTPLAY_FMT_16BIT 0x80
2321da177e4SLinus Torvalds #define VIA_REG_MULTPLAY_FMT_CH_MASK 0x70 /* # channels << 4 (valid = 1,2,4,6) */
2331da177e4SLinus Torvalds #define VIA_REG_OFS_CAPTURE_FIFO 0x02 /* byte - bit 6 = fifo enable */
2341da177e4SLinus Torvalds #define VIA_REG_CAPTURE_FIFO_ENABLE 0x40
2351da177e4SLinus Torvalds
2361da177e4SLinus Torvalds #define VIA_DXS_MAX_VOLUME 31 /* max. volume (attenuation) of reg 0x32/33 */
2371da177e4SLinus Torvalds
2381da177e4SLinus Torvalds #define VIA_REG_CAPTURE_CHANNEL 0x63 /* byte - input select */
2391da177e4SLinus Torvalds #define VIA_REG_CAPTURE_CHANNEL_MIC 0x4
2401da177e4SLinus Torvalds #define VIA_REG_CAPTURE_CHANNEL_LINE 0
2411da177e4SLinus Torvalds #define VIA_REG_CAPTURE_SELECT_CODEC 0x03 /* recording source codec (0 = primary) */
2421da177e4SLinus Torvalds
2431da177e4SLinus Torvalds #define VIA_TBL_BIT_FLAG 0x40000000
2441da177e4SLinus Torvalds #define VIA_TBL_BIT_EOL 0x80000000
2451da177e4SLinus Torvalds
2461da177e4SLinus Torvalds /* pci space */
2471da177e4SLinus Torvalds #define VIA_ACLINK_STAT 0x40
2481da177e4SLinus Torvalds #define VIA_ACLINK_C11_READY 0x20
2491da177e4SLinus Torvalds #define VIA_ACLINK_C10_READY 0x10
2501da177e4SLinus Torvalds #define VIA_ACLINK_C01_READY 0x04 /* secondary codec ready */
2511da177e4SLinus Torvalds #define VIA_ACLINK_LOWPOWER 0x02 /* low-power state */
2521da177e4SLinus Torvalds #define VIA_ACLINK_C00_READY 0x01 /* primary codec ready */
2531da177e4SLinus Torvalds #define VIA_ACLINK_CTRL 0x41
2541da177e4SLinus Torvalds #define VIA_ACLINK_CTRL_ENABLE 0x80 /* 0: disable, 1: enable */
2551da177e4SLinus Torvalds #define VIA_ACLINK_CTRL_RESET 0x40 /* 0: assert, 1: de-assert */
2561da177e4SLinus Torvalds #define VIA_ACLINK_CTRL_SYNC 0x20 /* 0: release SYNC, 1: force SYNC hi */
2571da177e4SLinus Torvalds #define VIA_ACLINK_CTRL_SDO 0x10 /* 0: release SDO, 1: force SDO hi */
2581da177e4SLinus Torvalds #define VIA_ACLINK_CTRL_VRA 0x08 /* 0: disable VRA, 1: enable VRA */
2591da177e4SLinus Torvalds #define VIA_ACLINK_CTRL_PCM 0x04 /* 0: disable PCM, 1: enable PCM */
2601da177e4SLinus Torvalds #define VIA_ACLINK_CTRL_FM 0x02 /* via686 only */
2611da177e4SLinus Torvalds #define VIA_ACLINK_CTRL_SB 0x01 /* via686 only */
2621da177e4SLinus Torvalds #define VIA_ACLINK_CTRL_INIT (VIA_ACLINK_CTRL_ENABLE|\
2631da177e4SLinus Torvalds VIA_ACLINK_CTRL_RESET|\
2641da177e4SLinus Torvalds VIA_ACLINK_CTRL_PCM|\
2651da177e4SLinus Torvalds VIA_ACLINK_CTRL_VRA)
2661da177e4SLinus Torvalds #define VIA_FUNC_ENABLE 0x42
2671da177e4SLinus Torvalds #define VIA_FUNC_MIDI_PNP 0x80 /* FIXME: it's 0x40 in the datasheet! */
2681da177e4SLinus Torvalds #define VIA_FUNC_MIDI_IRQMASK 0x40 /* FIXME: not documented! */
2691da177e4SLinus Torvalds #define VIA_FUNC_RX2C_WRITE 0x20
2701da177e4SLinus Torvalds #define VIA_FUNC_SB_FIFO_EMPTY 0x10
2711da177e4SLinus Torvalds #define VIA_FUNC_ENABLE_GAME 0x08
2721da177e4SLinus Torvalds #define VIA_FUNC_ENABLE_FM 0x04
2731da177e4SLinus Torvalds #define VIA_FUNC_ENABLE_MIDI 0x02
2741da177e4SLinus Torvalds #define VIA_FUNC_ENABLE_SB 0x01
2751da177e4SLinus Torvalds #define VIA_PNP_CONTROL 0x43
2761da177e4SLinus Torvalds #define VIA_FM_NMI_CTRL 0x48
2771da177e4SLinus Torvalds #define VIA8233_VOLCHG_CTRL 0x48
2781da177e4SLinus Torvalds #define VIA8233_SPDIF_CTRL 0x49
2791da177e4SLinus Torvalds #define VIA8233_SPDIF_DX3 0x08
2801da177e4SLinus Torvalds #define VIA8233_SPDIF_SLOT_MASK 0x03
2811da177e4SLinus Torvalds #define VIA8233_SPDIF_SLOT_1011 0x00
2821da177e4SLinus Torvalds #define VIA8233_SPDIF_SLOT_34 0x01
2831da177e4SLinus Torvalds #define VIA8233_SPDIF_SLOT_78 0x02
2841da177e4SLinus Torvalds #define VIA8233_SPDIF_SLOT_69 0x03
2851da177e4SLinus Torvalds
2861da177e4SLinus Torvalds /*
2871da177e4SLinus Torvalds */
2881da177e4SLinus Torvalds
2891da177e4SLinus Torvalds #define VIA_DXS_AUTO 0
2901da177e4SLinus Torvalds #define VIA_DXS_ENABLE 1
2911da177e4SLinus Torvalds #define VIA_DXS_DISABLE 2
2921da177e4SLinus Torvalds #define VIA_DXS_48K 3
2931da177e4SLinus Torvalds #define VIA_DXS_NO_VRA 4
2942d7eb7cbSSergey Vlasov #define VIA_DXS_SRC 5
2951da177e4SLinus Torvalds
2961da177e4SLinus Torvalds
2971da177e4SLinus Torvalds /*
2981da177e4SLinus Torvalds * pcm stream
2991da177e4SLinus Torvalds */
3001da177e4SLinus Torvalds
3011da177e4SLinus Torvalds struct snd_via_sg_table {
3021da177e4SLinus Torvalds unsigned int offset;
3031da177e4SLinus Torvalds unsigned int size;
3041da177e4SLinus Torvalds } ;
3051da177e4SLinus Torvalds
3061da177e4SLinus Torvalds #define VIA_TABLE_SIZE 255
3075503600aSTakashi Iwai #define VIA_MAX_BUFSIZE (1<<24)
3081da177e4SLinus Torvalds
309e437e3d7STakashi Iwai struct viadev {
3101da177e4SLinus Torvalds unsigned int reg_offset;
3111da177e4SLinus Torvalds unsigned long port;
3121da177e4SLinus Torvalds int direction; /* playback = 0, capture = 1 */
313e437e3d7STakashi Iwai struct snd_pcm_substream *substream;
3141da177e4SLinus Torvalds int running;
3151da177e4SLinus Torvalds unsigned int tbl_entries; /* # descriptors */
3161da177e4SLinus Torvalds struct snd_dma_buffer table;
3171da177e4SLinus Torvalds struct snd_via_sg_table *idx_table;
3181da177e4SLinus Torvalds /* for recovery from the unexpected pointer */
3191da177e4SLinus Torvalds unsigned int lastpos;
3201da177e4SLinus Torvalds unsigned int fragsize;
3211da177e4SLinus Torvalds unsigned int bufsize;
3221da177e4SLinus Torvalds unsigned int bufsize2;
3234f550df5SKarsten Wiese int hwptr_done; /* processed frame position in the buffer */
3244f550df5SKarsten Wiese int in_interrupt;
3254f550df5SKarsten Wiese int shadow_shift;
3261da177e4SLinus Torvalds };
3271da177e4SLinus Torvalds
3281da177e4SLinus Torvalds
3291da177e4SLinus Torvalds enum { TYPE_CARD_VIA686 = 1, TYPE_CARD_VIA8233 };
3301da177e4SLinus Torvalds enum { TYPE_VIA686, TYPE_VIA8233, TYPE_VIA8233A };
3311da177e4SLinus Torvalds
3321da177e4SLinus Torvalds #define VIA_MAX_DEVS 7 /* 4 playback, 1 multi, 2 capture */
3331da177e4SLinus Torvalds
3341da177e4SLinus Torvalds struct via_rate_lock {
3351da177e4SLinus Torvalds spinlock_t lock;
3361da177e4SLinus Torvalds int rate;
3371da177e4SLinus Torvalds int used;
3381da177e4SLinus Torvalds };
3391da177e4SLinus Torvalds
340e437e3d7STakashi Iwai struct via82xx {
3411da177e4SLinus Torvalds int irq;
3421da177e4SLinus Torvalds
3431da177e4SLinus Torvalds unsigned long port;
3441da177e4SLinus Torvalds struct resource *mpu_res;
3451da177e4SLinus Torvalds int chip_type;
3461da177e4SLinus Torvalds unsigned char revision;
3471da177e4SLinus Torvalds
3481da177e4SLinus Torvalds unsigned char old_legacy;
3491da177e4SLinus Torvalds unsigned char old_legacy_cfg;
350c7561cd8STakashi Iwai #ifdef CONFIG_PM_SLEEP
3511da177e4SLinus Torvalds unsigned char legacy_saved;
3521da177e4SLinus Torvalds unsigned char legacy_cfg_saved;
3531da177e4SLinus Torvalds unsigned char spdif_ctrl_saved;
3541da177e4SLinus Torvalds unsigned char capture_src_saved[2];
3551da177e4SLinus Torvalds unsigned int mpu_port_saved;
3561da177e4SLinus Torvalds #endif
3571da177e4SLinus Torvalds
35800f226d4SHonza Maly unsigned char playback_volume[4][2]; /* for VIA8233/C/8235; default = 0 */
35900f226d4SHonza Maly unsigned char playback_volume_c[2]; /* for VIA8233/C/8235; default = 0 */
3601da177e4SLinus Torvalds
3611da177e4SLinus Torvalds unsigned int intr_mask; /* SGD_SHADOW mask to check interrupts */
3621da177e4SLinus Torvalds
3631da177e4SLinus Torvalds struct pci_dev *pci;
364e437e3d7STakashi Iwai struct snd_card *card;
3651da177e4SLinus Torvalds
3661da177e4SLinus Torvalds unsigned int num_devs;
3671da177e4SLinus Torvalds unsigned int playback_devno, multi_devno, capture_devno;
368e437e3d7STakashi Iwai struct viadev devs[VIA_MAX_DEVS];
3691da177e4SLinus Torvalds struct via_rate_lock rates[2]; /* playback and capture */
3701da177e4SLinus Torvalds unsigned int dxs_fixed: 1; /* DXS channel accepts only 48kHz */
3711da177e4SLinus Torvalds unsigned int no_vra: 1; /* no need to set VRA on DXS channels */
3722d7eb7cbSSergey Vlasov unsigned int dxs_src: 1; /* use full SRC capabilities of DXS */
3731da177e4SLinus Torvalds unsigned int spdif_on: 1; /* only spdif rates work to external DACs */
3741da177e4SLinus Torvalds
375e437e3d7STakashi Iwai struct snd_pcm *pcms[2];
376e437e3d7STakashi Iwai struct snd_rawmidi *rmidi;
3773d009413SClemens Ladisch struct snd_kcontrol *dxs_controls[4];
3781da177e4SLinus Torvalds
379e437e3d7STakashi Iwai struct snd_ac97_bus *ac97_bus;
380e437e3d7STakashi Iwai struct snd_ac97 *ac97;
3811da177e4SLinus Torvalds unsigned int ac97_clock;
3821da177e4SLinus Torvalds unsigned int ac97_secondary; /* secondary AC'97 codec is present */
3831da177e4SLinus Torvalds
3841da177e4SLinus Torvalds spinlock_t reg_lock;
385e437e3d7STakashi Iwai struct snd_info_entry *proc_entry;
3861da177e4SLinus Torvalds
3871da177e4SLinus Torvalds #ifdef SUPPORT_JOYSTICK
3881da177e4SLinus Torvalds struct gameport *gameport;
3891da177e4SLinus Torvalds #endif
3901da177e4SLinus Torvalds };
3911da177e4SLinus Torvalds
3929baa3c34SBenoit Taine static const struct pci_device_id snd_via82xx_ids[] = {
3934f550df5SKarsten Wiese /* 0x1106, 0x3058 */
39428d27aaeSJoe Perches { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_82C686_5), TYPE_CARD_VIA686, }, /* 686A */
3954f550df5SKarsten Wiese /* 0x1106, 0x3059 */
39628d27aaeSJoe Perches { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_8233_5), TYPE_CARD_VIA8233, }, /* VT8233 */
3971da177e4SLinus Torvalds { 0, }
3981da177e4SLinus Torvalds };
3991da177e4SLinus Torvalds
4001da177e4SLinus Torvalds MODULE_DEVICE_TABLE(pci, snd_via82xx_ids);
4011da177e4SLinus Torvalds
4021da177e4SLinus Torvalds /*
4031da177e4SLinus Torvalds */
4041da177e4SLinus Torvalds
4051da177e4SLinus Torvalds /*
4061da177e4SLinus Torvalds * allocate and initialize the descriptor buffers
4071da177e4SLinus Torvalds * periods = number of periods
4081da177e4SLinus Torvalds * fragsize = period size in bytes
4091da177e4SLinus Torvalds */
build_via_table(struct viadev * dev,struct snd_pcm_substream * substream,struct pci_dev * pci,unsigned int periods,unsigned int fragsize)410e437e3d7STakashi Iwai static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substream,
4111da177e4SLinus Torvalds struct pci_dev *pci,
4121da177e4SLinus Torvalds unsigned int periods, unsigned int fragsize)
4131da177e4SLinus Torvalds {
4141da177e4SLinus Torvalds unsigned int i, idx, ofs, rest;
415e437e3d7STakashi Iwai struct via82xx *chip = snd_pcm_substream_chip(substream);
416c5bb0867STakashi Iwai __le32 *pgtbl;
4171da177e4SLinus Torvalds
4181da177e4SLinus Torvalds if (dev->table.area == NULL) {
4191da177e4SLinus Torvalds /* the start of each lists must be aligned to 8 bytes,
4201da177e4SLinus Torvalds * but the kernel pages are much bigger, so we don't care
4211da177e4SLinus Torvalds */
4226974f8adSTakashi Iwai if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &chip->pci->dev,
4231da177e4SLinus Torvalds PAGE_ALIGN(VIA_TABLE_SIZE * 2 * 8),
4241da177e4SLinus Torvalds &dev->table) < 0)
4251da177e4SLinus Torvalds return -ENOMEM;
4261da177e4SLinus Torvalds }
4271da177e4SLinus Torvalds if (! dev->idx_table) {
4286da2ec56SKees Cook dev->idx_table = kmalloc_array(VIA_TABLE_SIZE,
4296da2ec56SKees Cook sizeof(*dev->idx_table),
4306da2ec56SKees Cook GFP_KERNEL);
4311da177e4SLinus Torvalds if (! dev->idx_table)
4321da177e4SLinus Torvalds return -ENOMEM;
4331da177e4SLinus Torvalds }
4341da177e4SLinus Torvalds
4351da177e4SLinus Torvalds /* fill the entries */
4361da177e4SLinus Torvalds idx = 0;
4371da177e4SLinus Torvalds ofs = 0;
438c5bb0867STakashi Iwai pgtbl = (__le32 *)dev->table.area;
4391da177e4SLinus Torvalds for (i = 0; i < periods; i++) {
4401da177e4SLinus Torvalds rest = fragsize;
4411da177e4SLinus Torvalds /* fill descriptors for a period.
4421da177e4SLinus Torvalds * a period can be split to several descriptors if it's
4431da177e4SLinus Torvalds * over page boundary.
4441da177e4SLinus Torvalds */
4451da177e4SLinus Torvalds do {
4461da177e4SLinus Torvalds unsigned int r;
4471da177e4SLinus Torvalds unsigned int flag;
44877a23f26STakashi Iwai unsigned int addr;
4491da177e4SLinus Torvalds
4501da177e4SLinus Torvalds if (idx >= VIA_TABLE_SIZE) {
45159d3acfaSTakashi Iwai dev_err(&pci->dev, "too much table size!\n");
4521da177e4SLinus Torvalds return -EINVAL;
4531da177e4SLinus Torvalds }
45477a23f26STakashi Iwai addr = snd_pcm_sgbuf_get_addr(substream, ofs);
455c5bb0867STakashi Iwai pgtbl[idx << 1] = cpu_to_le32(addr);
4565503600aSTakashi Iwai r = snd_pcm_sgbuf_get_chunk_size(substream, ofs, rest);
4571da177e4SLinus Torvalds rest -= r;
4581da177e4SLinus Torvalds if (! rest) {
4591da177e4SLinus Torvalds if (i == periods - 1)
4601da177e4SLinus Torvalds flag = VIA_TBL_BIT_EOL; /* buffer boundary */
4611da177e4SLinus Torvalds else
4621da177e4SLinus Torvalds flag = VIA_TBL_BIT_FLAG; /* period boundary */
4631da177e4SLinus Torvalds } else
4641da177e4SLinus Torvalds flag = 0; /* period continues to the next */
465ee419653STakashi Iwai /*
46659d3acfaSTakashi Iwai dev_dbg(&pci->dev,
46759d3acfaSTakashi Iwai "tbl %d: at %d size %d (rest %d)\n",
46859d3acfaSTakashi Iwai idx, ofs, r, rest);
469ee419653STakashi Iwai */
470c5bb0867STakashi Iwai pgtbl[(idx<<1) + 1] = cpu_to_le32(r | flag);
4711da177e4SLinus Torvalds dev->idx_table[idx].offset = ofs;
4721da177e4SLinus Torvalds dev->idx_table[idx].size = r;
4731da177e4SLinus Torvalds ofs += r;
4741da177e4SLinus Torvalds idx++;
4751da177e4SLinus Torvalds } while (rest > 0);
4761da177e4SLinus Torvalds }
4771da177e4SLinus Torvalds dev->tbl_entries = idx;
4781da177e4SLinus Torvalds dev->bufsize = periods * fragsize;
4791da177e4SLinus Torvalds dev->bufsize2 = dev->bufsize / 2;
4801da177e4SLinus Torvalds dev->fragsize = fragsize;
4811da177e4SLinus Torvalds return 0;
4821da177e4SLinus Torvalds }
4831da177e4SLinus Torvalds
4841da177e4SLinus Torvalds
clean_via_table(struct viadev * dev,struct snd_pcm_substream * substream,struct pci_dev * pci)485e437e3d7STakashi Iwai static int clean_via_table(struct viadev *dev, struct snd_pcm_substream *substream,
4861da177e4SLinus Torvalds struct pci_dev *pci)
4871da177e4SLinus Torvalds {
4881da177e4SLinus Torvalds if (dev->table.area) {
4891da177e4SLinus Torvalds snd_dma_free_pages(&dev->table);
4901da177e4SLinus Torvalds dev->table.area = NULL;
4911da177e4SLinus Torvalds }
4921da177e4SLinus Torvalds kfree(dev->idx_table);
4931da177e4SLinus Torvalds dev->idx_table = NULL;
4941da177e4SLinus Torvalds return 0;
4951da177e4SLinus Torvalds }
4961da177e4SLinus Torvalds
4971da177e4SLinus Torvalds /*
4981da177e4SLinus Torvalds * Basic I/O
4991da177e4SLinus Torvalds */
5001da177e4SLinus Torvalds
snd_via82xx_codec_xread(struct via82xx * chip)501e437e3d7STakashi Iwai static inline unsigned int snd_via82xx_codec_xread(struct via82xx *chip)
5021da177e4SLinus Torvalds {
5031da177e4SLinus Torvalds return inl(VIAREG(chip, AC97));
5041da177e4SLinus Torvalds }
5051da177e4SLinus Torvalds
snd_via82xx_codec_xwrite(struct via82xx * chip,unsigned int val)506e437e3d7STakashi Iwai static inline void snd_via82xx_codec_xwrite(struct via82xx *chip, unsigned int val)
5071da177e4SLinus Torvalds {
5081da177e4SLinus Torvalds outl(val, VIAREG(chip, AC97));
5091da177e4SLinus Torvalds }
5101da177e4SLinus Torvalds
snd_via82xx_codec_ready(struct via82xx * chip,int secondary)511e437e3d7STakashi Iwai static int snd_via82xx_codec_ready(struct via82xx *chip, int secondary)
5121da177e4SLinus Torvalds {
5131da177e4SLinus Torvalds unsigned int timeout = 1000; /* 1ms */
5141da177e4SLinus Torvalds unsigned int val;
5151da177e4SLinus Torvalds
5161da177e4SLinus Torvalds while (timeout-- > 0) {
5171da177e4SLinus Torvalds udelay(1);
518afb342f0STakashi Iwai val = snd_via82xx_codec_xread(chip);
519afb342f0STakashi Iwai if (!(val & VIA_REG_AC97_BUSY))
5201da177e4SLinus Torvalds return val & 0xffff;
5211da177e4SLinus Torvalds }
52259d3acfaSTakashi Iwai dev_err(chip->card->dev, "codec_ready: codec %i is not ready [0x%x]\n",
523e437e3d7STakashi Iwai secondary, snd_via82xx_codec_xread(chip));
5241da177e4SLinus Torvalds return -EIO;
5251da177e4SLinus Torvalds }
5261da177e4SLinus Torvalds
snd_via82xx_codec_valid(struct via82xx * chip,int secondary)527e437e3d7STakashi Iwai static int snd_via82xx_codec_valid(struct via82xx *chip, int secondary)
5281da177e4SLinus Torvalds {
5291da177e4SLinus Torvalds unsigned int timeout = 1000; /* 1ms */
5301da177e4SLinus Torvalds unsigned int val, val1;
5311da177e4SLinus Torvalds unsigned int stat = !secondary ? VIA_REG_AC97_PRIMARY_VALID :
5321da177e4SLinus Torvalds VIA_REG_AC97_SECONDARY_VALID;
5331da177e4SLinus Torvalds
5341da177e4SLinus Torvalds while (timeout-- > 0) {
5351da177e4SLinus Torvalds val = snd_via82xx_codec_xread(chip);
5361da177e4SLinus Torvalds val1 = val & (VIA_REG_AC97_BUSY | stat);
5371da177e4SLinus Torvalds if (val1 == stat)
5381da177e4SLinus Torvalds return val & 0xffff;
5391da177e4SLinus Torvalds udelay(1);
5401da177e4SLinus Torvalds }
5411da177e4SLinus Torvalds return -EIO;
5421da177e4SLinus Torvalds }
5431da177e4SLinus Torvalds
snd_via82xx_codec_wait(struct snd_ac97 * ac97)544e437e3d7STakashi Iwai static void snd_via82xx_codec_wait(struct snd_ac97 *ac97)
5451da177e4SLinus Torvalds {
546e437e3d7STakashi Iwai struct via82xx *chip = ac97->private_data;
54786a5d9cfSPierre-Louis Bossart __always_unused int err;
5481da177e4SLinus Torvalds err = snd_via82xx_codec_ready(chip, ac97->num);
5491da177e4SLinus Torvalds /* here we need to wait fairly for long time.. */
550115551d9SSimon Arlott if (!nodelay)
551ef21ca24SNishanth Aravamudan msleep(500);
5521da177e4SLinus Torvalds }
5531da177e4SLinus Torvalds
snd_via82xx_codec_write(struct snd_ac97 * ac97,unsigned short reg,unsigned short val)554e437e3d7STakashi Iwai static void snd_via82xx_codec_write(struct snd_ac97 *ac97,
5551da177e4SLinus Torvalds unsigned short reg,
5561da177e4SLinus Torvalds unsigned short val)
5571da177e4SLinus Torvalds {
558e437e3d7STakashi Iwai struct via82xx *chip = ac97->private_data;
5591da177e4SLinus Torvalds unsigned int xval;
5601da177e4SLinus Torvalds
5611da177e4SLinus Torvalds xval = !ac97->num ? VIA_REG_AC97_CODEC_ID_PRIMARY : VIA_REG_AC97_CODEC_ID_SECONDARY;
5621da177e4SLinus Torvalds xval <<= VIA_REG_AC97_CODEC_ID_SHIFT;
5631da177e4SLinus Torvalds xval |= reg << VIA_REG_AC97_CMD_SHIFT;
5641da177e4SLinus Torvalds xval |= val << VIA_REG_AC97_DATA_SHIFT;
5651da177e4SLinus Torvalds snd_via82xx_codec_xwrite(chip, xval);
5661da177e4SLinus Torvalds snd_via82xx_codec_ready(chip, ac97->num);
5671da177e4SLinus Torvalds }
5681da177e4SLinus Torvalds
snd_via82xx_codec_read(struct snd_ac97 * ac97,unsigned short reg)569e437e3d7STakashi Iwai static unsigned short snd_via82xx_codec_read(struct snd_ac97 *ac97, unsigned short reg)
5701da177e4SLinus Torvalds {
571e437e3d7STakashi Iwai struct via82xx *chip = ac97->private_data;
5721da177e4SLinus Torvalds unsigned int xval, val = 0xffff;
5731da177e4SLinus Torvalds int again = 0;
5741da177e4SLinus Torvalds
5751da177e4SLinus Torvalds xval = ac97->num << VIA_REG_AC97_CODEC_ID_SHIFT;
5761da177e4SLinus Torvalds xval |= ac97->num ? VIA_REG_AC97_SECONDARY_VALID : VIA_REG_AC97_PRIMARY_VALID;
5771da177e4SLinus Torvalds xval |= VIA_REG_AC97_READ;
5781da177e4SLinus Torvalds xval |= (reg & 0x7f) << VIA_REG_AC97_CMD_SHIFT;
5791da177e4SLinus Torvalds while (1) {
5801da177e4SLinus Torvalds if (again++ > 3) {
58159d3acfaSTakashi Iwai dev_err(chip->card->dev,
58259d3acfaSTakashi Iwai "codec_read: codec %i is not valid [0x%x]\n",
583e437e3d7STakashi Iwai ac97->num, snd_via82xx_codec_xread(chip));
5841da177e4SLinus Torvalds return 0xffff;
5851da177e4SLinus Torvalds }
5861da177e4SLinus Torvalds snd_via82xx_codec_xwrite(chip, xval);
5871da177e4SLinus Torvalds udelay (20);
5881da177e4SLinus Torvalds if (snd_via82xx_codec_valid(chip, ac97->num) >= 0) {
5891da177e4SLinus Torvalds udelay(25);
5901da177e4SLinus Torvalds val = snd_via82xx_codec_xread(chip);
5911da177e4SLinus Torvalds break;
5921da177e4SLinus Torvalds }
5931da177e4SLinus Torvalds }
5941da177e4SLinus Torvalds return val & 0xffff;
5951da177e4SLinus Torvalds }
5961da177e4SLinus Torvalds
snd_via82xx_channel_reset(struct via82xx * chip,struct viadev * viadev)597e437e3d7STakashi Iwai static void snd_via82xx_channel_reset(struct via82xx *chip, struct viadev *viadev)
5981da177e4SLinus Torvalds {
5991da177e4SLinus Torvalds outb(VIA_REG_CTRL_PAUSE | VIA_REG_CTRL_TERMINATE | VIA_REG_CTRL_RESET,
6001da177e4SLinus Torvalds VIADEV_REG(viadev, OFFSET_CONTROL));
6011da177e4SLinus Torvalds inb(VIADEV_REG(viadev, OFFSET_CONTROL));
6021da177e4SLinus Torvalds udelay(50);
6031da177e4SLinus Torvalds /* disable interrupts */
6041da177e4SLinus Torvalds outb(0x00, VIADEV_REG(viadev, OFFSET_CONTROL));
6051da177e4SLinus Torvalds /* clear interrupts */
6061da177e4SLinus Torvalds outb(0x03, VIADEV_REG(viadev, OFFSET_STATUS));
6071da177e4SLinus Torvalds outb(0x00, VIADEV_REG(viadev, OFFSET_TYPE)); /* for via686 */
6081da177e4SLinus Torvalds // outl(0, VIADEV_REG(viadev, OFFSET_CURR_PTR));
6091da177e4SLinus Torvalds viadev->lastpos = 0;
6104f550df5SKarsten Wiese viadev->hwptr_done = 0;
6111da177e4SLinus Torvalds }
6121da177e4SLinus Torvalds
6131da177e4SLinus Torvalds
6141da177e4SLinus Torvalds /*
6151da177e4SLinus Torvalds * Interrupt handler
6164f550df5SKarsten Wiese * Used for 686 and 8233A
6171da177e4SLinus Torvalds */
snd_via686_interrupt(int irq,void * dev_id)6187d12e780SDavid Howells static irqreturn_t snd_via686_interrupt(int irq, void *dev_id)
6191da177e4SLinus Torvalds {
620e437e3d7STakashi Iwai struct via82xx *chip = dev_id;
6211da177e4SLinus Torvalds unsigned int status;
6221da177e4SLinus Torvalds unsigned int i;
6231da177e4SLinus Torvalds
6241da177e4SLinus Torvalds status = inl(VIAREG(chip, SGD_SHADOW));
6251da177e4SLinus Torvalds if (! (status & chip->intr_mask)) {
6261da177e4SLinus Torvalds if (chip->rmidi)
6271da177e4SLinus Torvalds /* check mpu401 interrupt */
6287d12e780SDavid Howells return snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
6291da177e4SLinus Torvalds return IRQ_NONE;
6301da177e4SLinus Torvalds }
6311da177e4SLinus Torvalds
6321da177e4SLinus Torvalds /* check status for each stream */
6331da177e4SLinus Torvalds spin_lock(&chip->reg_lock);
6341da177e4SLinus Torvalds for (i = 0; i < chip->num_devs; i++) {
635e437e3d7STakashi Iwai struct viadev *viadev = &chip->devs[i];
6361da177e4SLinus Torvalds unsigned char c_status = inb(VIADEV_REG(viadev, OFFSET_STATUS));
6374f550df5SKarsten Wiese if (! (c_status & (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG|VIA_REG_STAT_STOPPED)))
6381da177e4SLinus Torvalds continue;
6391da177e4SLinus Torvalds if (viadev->substream && viadev->running) {
6404f550df5SKarsten Wiese /*
6414f550df5SKarsten Wiese * Update hwptr_done based on 'period elapsed'
6424f550df5SKarsten Wiese * interrupts. We'll use it, when the chip returns 0
6434f550df5SKarsten Wiese * for OFFSET_CURR_COUNT.
6444f550df5SKarsten Wiese */
6454f550df5SKarsten Wiese if (c_status & VIA_REG_STAT_EOL)
6464f550df5SKarsten Wiese viadev->hwptr_done = 0;
6474f550df5SKarsten Wiese else
6484f550df5SKarsten Wiese viadev->hwptr_done += viadev->fragsize;
6494f550df5SKarsten Wiese viadev->in_interrupt = c_status;
6501da177e4SLinus Torvalds spin_unlock(&chip->reg_lock);
6511da177e4SLinus Torvalds snd_pcm_period_elapsed(viadev->substream);
6521da177e4SLinus Torvalds spin_lock(&chip->reg_lock);
6534f550df5SKarsten Wiese viadev->in_interrupt = 0;
6541da177e4SLinus Torvalds }
6551da177e4SLinus Torvalds outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */
6561da177e4SLinus Torvalds }
6571da177e4SLinus Torvalds spin_unlock(&chip->reg_lock);
6581da177e4SLinus Torvalds return IRQ_HANDLED;
6591da177e4SLinus Torvalds }
6601da177e4SLinus Torvalds
6611da177e4SLinus Torvalds /*
6624f550df5SKarsten Wiese * Interrupt handler
6634f550df5SKarsten Wiese */
snd_via8233_interrupt(int irq,void * dev_id)6647d12e780SDavid Howells static irqreturn_t snd_via8233_interrupt(int irq, void *dev_id)
6654f550df5SKarsten Wiese {
666e437e3d7STakashi Iwai struct via82xx *chip = dev_id;
6674f550df5SKarsten Wiese unsigned int status;
6684f550df5SKarsten Wiese unsigned int i;
6694f550df5SKarsten Wiese int irqreturn = 0;
6704f550df5SKarsten Wiese
6714f550df5SKarsten Wiese /* check status for each stream */
6724f550df5SKarsten Wiese spin_lock(&chip->reg_lock);
6734f550df5SKarsten Wiese status = inl(VIAREG(chip, SGD_SHADOW));
6744f550df5SKarsten Wiese
6754f550df5SKarsten Wiese for (i = 0; i < chip->num_devs; i++) {
676e437e3d7STakashi Iwai struct viadev *viadev = &chip->devs[i];
677e437e3d7STakashi Iwai struct snd_pcm_substream *substream;
6784f550df5SKarsten Wiese unsigned char c_status, shadow_status;
6794f550df5SKarsten Wiese
6804f550df5SKarsten Wiese shadow_status = (status >> viadev->shadow_shift) &
6814f550df5SKarsten Wiese (VIA8233_SHADOW_STAT_ACTIVE|VIA_REG_STAT_EOL|
6824f550df5SKarsten Wiese VIA_REG_STAT_FLAG);
6834f550df5SKarsten Wiese c_status = shadow_status & (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG);
6844f550df5SKarsten Wiese if (!c_status)
6854f550df5SKarsten Wiese continue;
6864f550df5SKarsten Wiese
6874f550df5SKarsten Wiese substream = viadev->substream;
6884f550df5SKarsten Wiese if (substream && viadev->running) {
6894f550df5SKarsten Wiese /*
6904f550df5SKarsten Wiese * Update hwptr_done based on 'period elapsed'
6914f550df5SKarsten Wiese * interrupts. We'll use it, when the chip returns 0
6924f550df5SKarsten Wiese * for OFFSET_CURR_COUNT.
6934f550df5SKarsten Wiese */
6944f550df5SKarsten Wiese if (c_status & VIA_REG_STAT_EOL)
6954f550df5SKarsten Wiese viadev->hwptr_done = 0;
6964f550df5SKarsten Wiese else
6974f550df5SKarsten Wiese viadev->hwptr_done += viadev->fragsize;
6984f550df5SKarsten Wiese viadev->in_interrupt = c_status;
6994f550df5SKarsten Wiese if (shadow_status & VIA8233_SHADOW_STAT_ACTIVE)
7004f550df5SKarsten Wiese viadev->in_interrupt |= VIA_REG_STAT_ACTIVE;
7014f550df5SKarsten Wiese spin_unlock(&chip->reg_lock);
7024f550df5SKarsten Wiese
7034f550df5SKarsten Wiese snd_pcm_period_elapsed(substream);
7044f550df5SKarsten Wiese
7054f550df5SKarsten Wiese spin_lock(&chip->reg_lock);
7064f550df5SKarsten Wiese viadev->in_interrupt = 0;
7074f550df5SKarsten Wiese }
7084f550df5SKarsten Wiese outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */
7094f550df5SKarsten Wiese irqreturn = 1;
7104f550df5SKarsten Wiese }
7114f550df5SKarsten Wiese spin_unlock(&chip->reg_lock);
7124f550df5SKarsten Wiese return IRQ_RETVAL(irqreturn);
7134f550df5SKarsten Wiese }
7144f550df5SKarsten Wiese
7154f550df5SKarsten Wiese /*
7161da177e4SLinus Torvalds * PCM callbacks
7171da177e4SLinus Torvalds */
7181da177e4SLinus Torvalds
7191da177e4SLinus Torvalds /*
7201da177e4SLinus Torvalds * trigger callback
7211da177e4SLinus Torvalds */
snd_via82xx_pcm_trigger(struct snd_pcm_substream * substream,int cmd)722e437e3d7STakashi Iwai static int snd_via82xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
7231da177e4SLinus Torvalds {
724e437e3d7STakashi Iwai struct via82xx *chip = snd_pcm_substream_chip(substream);
725e437e3d7STakashi Iwai struct viadev *viadev = substream->runtime->private_data;
7261da177e4SLinus Torvalds unsigned char val;
7271da177e4SLinus Torvalds
7281da177e4SLinus Torvalds if (chip->chip_type != TYPE_VIA686)
7291da177e4SLinus Torvalds val = VIA_REG_CTRL_INT;
7301da177e4SLinus Torvalds else
7311da177e4SLinus Torvalds val = 0;
7321da177e4SLinus Torvalds switch (cmd) {
7331da177e4SLinus Torvalds case SNDRV_PCM_TRIGGER_START:
73441e4845cSJaroslav Kysela case SNDRV_PCM_TRIGGER_RESUME:
7351da177e4SLinus Torvalds val |= VIA_REG_CTRL_START;
7361da177e4SLinus Torvalds viadev->running = 1;
7371da177e4SLinus Torvalds break;
7381da177e4SLinus Torvalds case SNDRV_PCM_TRIGGER_STOP:
73941e4845cSJaroslav Kysela case SNDRV_PCM_TRIGGER_SUSPEND:
7401da177e4SLinus Torvalds val = VIA_REG_CTRL_TERMINATE;
7411da177e4SLinus Torvalds viadev->running = 0;
7421da177e4SLinus Torvalds break;
7431da177e4SLinus Torvalds case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
7441da177e4SLinus Torvalds val |= VIA_REG_CTRL_PAUSE;
7451da177e4SLinus Torvalds viadev->running = 0;
7461da177e4SLinus Torvalds break;
7471da177e4SLinus Torvalds case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
7481da177e4SLinus Torvalds viadev->running = 1;
7491da177e4SLinus Torvalds break;
7501da177e4SLinus Torvalds default:
7511da177e4SLinus Torvalds return -EINVAL;
7521da177e4SLinus Torvalds }
7531da177e4SLinus Torvalds outb(val, VIADEV_REG(viadev, OFFSET_CONTROL));
7541da177e4SLinus Torvalds if (cmd == SNDRV_PCM_TRIGGER_STOP)
7551da177e4SLinus Torvalds snd_via82xx_channel_reset(chip, viadev);
7561da177e4SLinus Torvalds return 0;
7571da177e4SLinus Torvalds }
7581da177e4SLinus Torvalds
7591da177e4SLinus Torvalds
7601da177e4SLinus Torvalds /*
7611da177e4SLinus Torvalds * pointer callbacks
7621da177e4SLinus Torvalds */
7631da177e4SLinus Torvalds
7641da177e4SLinus Torvalds /*
7651da177e4SLinus Torvalds * calculate the linear position at the given sg-buffer index and the rest count
7661da177e4SLinus Torvalds */
7671da177e4SLinus Torvalds
7681da177e4SLinus Torvalds #define check_invalid_pos(viadev,pos) \
769e437e3d7STakashi Iwai ((pos) < viadev->lastpos && ((pos) >= viadev->bufsize2 ||\
770e437e3d7STakashi Iwai viadev->lastpos < viadev->bufsize2))
7711da177e4SLinus Torvalds
calc_linear_pos(struct via82xx * chip,struct viadev * viadev,unsigned int idx,unsigned int count)77259d3acfaSTakashi Iwai static inline unsigned int calc_linear_pos(struct via82xx *chip,
77359d3acfaSTakashi Iwai struct viadev *viadev,
77459d3acfaSTakashi Iwai unsigned int idx,
775e437e3d7STakashi Iwai unsigned int count)
7761da177e4SLinus Torvalds {
7771da177e4SLinus Torvalds unsigned int size, base, res;
7781da177e4SLinus Torvalds
7791da177e4SLinus Torvalds size = viadev->idx_table[idx].size;
7801da177e4SLinus Torvalds base = viadev->idx_table[idx].offset;
7811da177e4SLinus Torvalds res = base + size - count;
7824f550df5SKarsten Wiese if (res >= viadev->bufsize)
7834f550df5SKarsten Wiese res -= viadev->bufsize;
7841da177e4SLinus Torvalds
7851da177e4SLinus Torvalds /* check the validity of the calculated position */
7861da177e4SLinus Torvalds if (size < count) {
78759d3acfaSTakashi Iwai dev_dbg(chip->card->dev,
78859d3acfaSTakashi Iwai "invalid via82xx_cur_ptr (size = %d, count = %d)\n",
789e437e3d7STakashi Iwai (int)size, (int)count);
7901da177e4SLinus Torvalds res = viadev->lastpos;
7911da177e4SLinus Torvalds } else {
7921da177e4SLinus Torvalds if (! count) {
7931da177e4SLinus Torvalds /* Some mobos report count = 0 on the DMA boundary,
7941da177e4SLinus Torvalds * i.e. count = size indeed.
7951da177e4SLinus Torvalds * Let's check whether this step is above the expected size.
7961da177e4SLinus Torvalds */
7971da177e4SLinus Torvalds int delta = res - viadev->lastpos;
7981da177e4SLinus Torvalds if (delta < 0)
7991da177e4SLinus Torvalds delta += viadev->bufsize;
8001da177e4SLinus Torvalds if ((unsigned int)delta > viadev->fragsize)
8011da177e4SLinus Torvalds res = base;
8021da177e4SLinus Torvalds }
8031da177e4SLinus Torvalds if (check_invalid_pos(viadev, res)) {
8041da177e4SLinus Torvalds #ifdef POINTER_DEBUG
80559d3acfaSTakashi Iwai dev_dbg(chip->card->dev,
80659d3acfaSTakashi Iwai "fail: idx = %i/%i, lastpos = 0x%x, bufsize2 = 0x%x, offsize = 0x%x, size = 0x%x, count = 0x%x\n",
80759d3acfaSTakashi Iwai idx, viadev->tbl_entries,
808e437e3d7STakashi Iwai viadev->lastpos, viadev->bufsize2,
809e437e3d7STakashi Iwai viadev->idx_table[idx].offset,
810e437e3d7STakashi Iwai viadev->idx_table[idx].size, count);
8111da177e4SLinus Torvalds #endif
8121da177e4SLinus Torvalds /* count register returns full size when end of buffer is reached */
8131da177e4SLinus Torvalds res = base + size;
8141da177e4SLinus Torvalds if (check_invalid_pos(viadev, res)) {
81559d3acfaSTakashi Iwai dev_dbg(chip->card->dev,
81659d3acfaSTakashi Iwai "invalid via82xx_cur_ptr (2), using last valid pointer\n");
8171da177e4SLinus Torvalds res = viadev->lastpos;
8181da177e4SLinus Torvalds }
8191da177e4SLinus Torvalds }
8201da177e4SLinus Torvalds }
8211da177e4SLinus Torvalds return res;
8221da177e4SLinus Torvalds }
8231da177e4SLinus Torvalds
8241da177e4SLinus Torvalds /*
8251da177e4SLinus Torvalds * get the current pointer on via686
8261da177e4SLinus Torvalds */
snd_via686_pcm_pointer(struct snd_pcm_substream * substream)827e437e3d7STakashi Iwai static snd_pcm_uframes_t snd_via686_pcm_pointer(struct snd_pcm_substream *substream)
8281da177e4SLinus Torvalds {
829e437e3d7STakashi Iwai struct via82xx *chip = snd_pcm_substream_chip(substream);
830e437e3d7STakashi Iwai struct viadev *viadev = substream->runtime->private_data;
8311da177e4SLinus Torvalds unsigned int idx, ptr, count, res;
8321da177e4SLinus Torvalds
833da3cec35STakashi Iwai if (snd_BUG_ON(!viadev->tbl_entries))
834da3cec35STakashi Iwai return 0;
8351da177e4SLinus Torvalds if (!(inb(VIADEV_REG(viadev, OFFSET_STATUS)) & VIA_REG_STAT_ACTIVE))
8361da177e4SLinus Torvalds return 0;
8371da177e4SLinus Torvalds
8381da177e4SLinus Torvalds spin_lock(&chip->reg_lock);
8391da177e4SLinus Torvalds count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT)) & 0xffffff;
8401da177e4SLinus Torvalds /* The via686a does not have the current index register,
8411da177e4SLinus Torvalds * so we need to calculate the index from CURR_PTR.
8421da177e4SLinus Torvalds */
8431da177e4SLinus Torvalds ptr = inl(VIADEV_REG(viadev, OFFSET_CURR_PTR));
8441da177e4SLinus Torvalds if (ptr <= (unsigned int)viadev->table.addr)
8451da177e4SLinus Torvalds idx = 0;
8461da177e4SLinus Torvalds else /* CURR_PTR holds the address + 8 */
8471da177e4SLinus Torvalds idx = ((ptr - (unsigned int)viadev->table.addr) / 8 - 1) % viadev->tbl_entries;
84859d3acfaSTakashi Iwai res = calc_linear_pos(chip, viadev, idx, count);
8494f550df5SKarsten Wiese viadev->lastpos = res; /* remember the last position */
8501da177e4SLinus Torvalds spin_unlock(&chip->reg_lock);
8511da177e4SLinus Torvalds
8521da177e4SLinus Torvalds return bytes_to_frames(substream->runtime, res);
8531da177e4SLinus Torvalds }
8541da177e4SLinus Torvalds
8551da177e4SLinus Torvalds /*
8561da177e4SLinus Torvalds * get the current pointer on via823x
8571da177e4SLinus Torvalds */
snd_via8233_pcm_pointer(struct snd_pcm_substream * substream)858e437e3d7STakashi Iwai static snd_pcm_uframes_t snd_via8233_pcm_pointer(struct snd_pcm_substream *substream)
8591da177e4SLinus Torvalds {
860e437e3d7STakashi Iwai struct via82xx *chip = snd_pcm_substream_chip(substream);
861e437e3d7STakashi Iwai struct viadev *viadev = substream->runtime->private_data;
8621da177e4SLinus Torvalds unsigned int idx, count, res;
8634f550df5SKarsten Wiese int status;
8641da177e4SLinus Torvalds
865da3cec35STakashi Iwai if (snd_BUG_ON(!viadev->tbl_entries))
866da3cec35STakashi Iwai return 0;
8674f550df5SKarsten Wiese
8681da177e4SLinus Torvalds spin_lock(&chip->reg_lock);
8691da177e4SLinus Torvalds count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT));
8704f550df5SKarsten Wiese status = viadev->in_interrupt;
8714f550df5SKarsten Wiese if (!status)
8724f550df5SKarsten Wiese status = inb(VIADEV_REG(viadev, OFFSET_STATUS));
8734f550df5SKarsten Wiese
874c6cc0e3bSBastiaan Jacques /* An apparent bug in the 8251 is worked around by sending a
875c6cc0e3bSBastiaan Jacques * REG_CTRL_START. */
876c6cc0e3bSBastiaan Jacques if (chip->revision == VIA_REV_8251 && (status & VIA_REG_STAT_EOL))
877c6cc0e3bSBastiaan Jacques snd_via82xx_pcm_trigger(substream, SNDRV_PCM_TRIGGER_START);
878c6cc0e3bSBastiaan Jacques
8794f550df5SKarsten Wiese if (!(status & VIA_REG_STAT_ACTIVE)) {
8804f550df5SKarsten Wiese res = 0;
8814f550df5SKarsten Wiese goto unlock;
8824f550df5SKarsten Wiese }
8834f550df5SKarsten Wiese if (count & 0xffffff) {
8841da177e4SLinus Torvalds idx = count >> 24;
8851da177e4SLinus Torvalds if (idx >= viadev->tbl_entries) {
8861da177e4SLinus Torvalds #ifdef POINTER_DEBUG
88759d3acfaSTakashi Iwai dev_dbg(chip->card->dev,
88859d3acfaSTakashi Iwai "fail: invalid idx = %i/%i\n", idx,
889e437e3d7STakashi Iwai viadev->tbl_entries);
8901da177e4SLinus Torvalds #endif
8911da177e4SLinus Torvalds res = viadev->lastpos;
8921da177e4SLinus Torvalds } else {
8931da177e4SLinus Torvalds count &= 0xffffff;
89459d3acfaSTakashi Iwai res = calc_linear_pos(chip, viadev, idx, count);
8951da177e4SLinus Torvalds }
8964f550df5SKarsten Wiese } else {
8974f550df5SKarsten Wiese res = viadev->hwptr_done;
8984f550df5SKarsten Wiese if (!viadev->in_interrupt) {
8994f550df5SKarsten Wiese if (status & VIA_REG_STAT_EOL) {
9004f550df5SKarsten Wiese res = 0;
9014f550df5SKarsten Wiese } else
9024f550df5SKarsten Wiese if (status & VIA_REG_STAT_FLAG) {
9034f550df5SKarsten Wiese res += viadev->fragsize;
9044f550df5SKarsten Wiese }
9054f550df5SKarsten Wiese }
9064f550df5SKarsten Wiese }
9074f550df5SKarsten Wiese unlock:
9084f550df5SKarsten Wiese viadev->lastpos = res;
9091da177e4SLinus Torvalds spin_unlock(&chip->reg_lock);
9101da177e4SLinus Torvalds
9111da177e4SLinus Torvalds return bytes_to_frames(substream->runtime, res);
9121da177e4SLinus Torvalds }
9131da177e4SLinus Torvalds
9141da177e4SLinus Torvalds
9151da177e4SLinus Torvalds /*
9161da177e4SLinus Torvalds * hw_params callback:
9171da177e4SLinus Torvalds * allocate the buffer and build up the buffer description table
9181da177e4SLinus Torvalds */
snd_via82xx_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * hw_params)919e437e3d7STakashi Iwai static int snd_via82xx_hw_params(struct snd_pcm_substream *substream,
920e437e3d7STakashi Iwai struct snd_pcm_hw_params *hw_params)
9211da177e4SLinus Torvalds {
922e437e3d7STakashi Iwai struct via82xx *chip = snd_pcm_substream_chip(substream);
923e437e3d7STakashi Iwai struct viadev *viadev = substream->runtime->private_data;
9241da177e4SLinus Torvalds
9258e2c7524STakashi Iwai return build_via_table(viadev, substream, chip->pci,
9261da177e4SLinus Torvalds params_periods(hw_params),
9271da177e4SLinus Torvalds params_period_bytes(hw_params));
9281da177e4SLinus Torvalds }
9291da177e4SLinus Torvalds
9301da177e4SLinus Torvalds /*
9311da177e4SLinus Torvalds * hw_free callback:
9321da177e4SLinus Torvalds * clean up the buffer description table and release the buffer
9331da177e4SLinus Torvalds */
snd_via82xx_hw_free(struct snd_pcm_substream * substream)934e437e3d7STakashi Iwai static int snd_via82xx_hw_free(struct snd_pcm_substream *substream)
9351da177e4SLinus Torvalds {
936e437e3d7STakashi Iwai struct via82xx *chip = snd_pcm_substream_chip(substream);
937e437e3d7STakashi Iwai struct viadev *viadev = substream->runtime->private_data;
9381da177e4SLinus Torvalds
9391da177e4SLinus Torvalds clean_via_table(viadev, substream, chip->pci);
9401da177e4SLinus Torvalds return 0;
9411da177e4SLinus Torvalds }
9421da177e4SLinus Torvalds
9431da177e4SLinus Torvalds
9441da177e4SLinus Torvalds /*
9451da177e4SLinus Torvalds * set up the table pointer
9461da177e4SLinus Torvalds */
snd_via82xx_set_table_ptr(struct via82xx * chip,struct viadev * viadev)947e437e3d7STakashi Iwai static void snd_via82xx_set_table_ptr(struct via82xx *chip, struct viadev *viadev)
9481da177e4SLinus Torvalds {
9491da177e4SLinus Torvalds snd_via82xx_codec_ready(chip, 0);
9501da177e4SLinus Torvalds outl((u32)viadev->table.addr, VIADEV_REG(viadev, OFFSET_TABLE_PTR));
9511da177e4SLinus Torvalds udelay(20);
9521da177e4SLinus Torvalds snd_via82xx_codec_ready(chip, 0);
9531da177e4SLinus Torvalds }
9541da177e4SLinus Torvalds
9551da177e4SLinus Torvalds /*
9561da177e4SLinus Torvalds * prepare callback for playback and capture on via686
9571da177e4SLinus Torvalds */
via686_setup_format(struct via82xx * chip,struct viadev * viadev,struct snd_pcm_runtime * runtime)958e437e3d7STakashi Iwai static void via686_setup_format(struct via82xx *chip, struct viadev *viadev,
959e437e3d7STakashi Iwai struct snd_pcm_runtime *runtime)
9601da177e4SLinus Torvalds {
9611da177e4SLinus Torvalds snd_via82xx_channel_reset(chip, viadev);
9621da177e4SLinus Torvalds /* this must be set after channel_reset */
9631da177e4SLinus Torvalds snd_via82xx_set_table_ptr(chip, viadev);
9641da177e4SLinus Torvalds outb(VIA_REG_TYPE_AUTOSTART |
9651da177e4SLinus Torvalds (runtime->format == SNDRV_PCM_FORMAT_S16_LE ? VIA_REG_TYPE_16BIT : 0) |
9661da177e4SLinus Torvalds (runtime->channels > 1 ? VIA_REG_TYPE_STEREO : 0) |
9671da177e4SLinus Torvalds ((viadev->reg_offset & 0x10) == 0 ? VIA_REG_TYPE_INT_LSAMPLE : 0) |
9681da177e4SLinus Torvalds VIA_REG_TYPE_INT_EOL |
9691da177e4SLinus Torvalds VIA_REG_TYPE_INT_FLAG, VIADEV_REG(viadev, OFFSET_TYPE));
9701da177e4SLinus Torvalds }
9711da177e4SLinus Torvalds
snd_via686_playback_prepare(struct snd_pcm_substream * substream)972e437e3d7STakashi Iwai static int snd_via686_playback_prepare(struct snd_pcm_substream *substream)
9731da177e4SLinus Torvalds {
974e437e3d7STakashi Iwai struct via82xx *chip = snd_pcm_substream_chip(substream);
975e437e3d7STakashi Iwai struct viadev *viadev = substream->runtime->private_data;
976e437e3d7STakashi Iwai struct snd_pcm_runtime *runtime = substream->runtime;
9771da177e4SLinus Torvalds
9781da177e4SLinus Torvalds snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, runtime->rate);
9791da177e4SLinus Torvalds snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate);
9801da177e4SLinus Torvalds via686_setup_format(chip, viadev, runtime);
9811da177e4SLinus Torvalds return 0;
9821da177e4SLinus Torvalds }
9831da177e4SLinus Torvalds
snd_via686_capture_prepare(struct snd_pcm_substream * substream)984e437e3d7STakashi Iwai static int snd_via686_capture_prepare(struct snd_pcm_substream *substream)
9851da177e4SLinus Torvalds {
986e437e3d7STakashi Iwai struct via82xx *chip = snd_pcm_substream_chip(substream);
987e437e3d7STakashi Iwai struct viadev *viadev = substream->runtime->private_data;
988e437e3d7STakashi Iwai struct snd_pcm_runtime *runtime = substream->runtime;
9891da177e4SLinus Torvalds
9901da177e4SLinus Torvalds snd_ac97_set_rate(chip->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
9911da177e4SLinus Torvalds via686_setup_format(chip, viadev, runtime);
9921da177e4SLinus Torvalds return 0;
9931da177e4SLinus Torvalds }
9941da177e4SLinus Torvalds
9951da177e4SLinus Torvalds /*
9961da177e4SLinus Torvalds * lock the current rate
9971da177e4SLinus Torvalds */
via_lock_rate(struct via_rate_lock * rec,int rate)9981da177e4SLinus Torvalds static int via_lock_rate(struct via_rate_lock *rec, int rate)
9991da177e4SLinus Torvalds {
10001da177e4SLinus Torvalds int changed = 0;
10011da177e4SLinus Torvalds
10021da177e4SLinus Torvalds spin_lock_irq(&rec->lock);
10031da177e4SLinus Torvalds if (rec->rate != rate) {
10041da177e4SLinus Torvalds if (rec->rate && rec->used > 1) /* already set */
10051da177e4SLinus Torvalds changed = -EINVAL;
10061da177e4SLinus Torvalds else {
10071da177e4SLinus Torvalds rec->rate = rate;
10081da177e4SLinus Torvalds changed = 1;
10091da177e4SLinus Torvalds }
10101da177e4SLinus Torvalds }
10111da177e4SLinus Torvalds spin_unlock_irq(&rec->lock);
10121da177e4SLinus Torvalds return changed;
10131da177e4SLinus Torvalds }
10141da177e4SLinus Torvalds
10151da177e4SLinus Torvalds /*
10161da177e4SLinus Torvalds * prepare callback for DSX playback on via823x
10171da177e4SLinus Torvalds */
snd_via8233_playback_prepare(struct snd_pcm_substream * substream)1018e437e3d7STakashi Iwai static int snd_via8233_playback_prepare(struct snd_pcm_substream *substream)
10191da177e4SLinus Torvalds {
1020e437e3d7STakashi Iwai struct via82xx *chip = snd_pcm_substream_chip(substream);
1021e437e3d7STakashi Iwai struct viadev *viadev = substream->runtime->private_data;
1022e437e3d7STakashi Iwai struct snd_pcm_runtime *runtime = substream->runtime;
10232d7eb7cbSSergey Vlasov int ac97_rate = chip->dxs_src ? 48000 : runtime->rate;
10241da177e4SLinus Torvalds int rate_changed;
10251da177e4SLinus Torvalds u32 rbits;
10261da177e4SLinus Torvalds
1027afb342f0STakashi Iwai rate_changed = via_lock_rate(&chip->rates[0], ac97_rate);
1028afb342f0STakashi Iwai if (rate_changed < 0)
10291da177e4SLinus Torvalds return rate_changed;
103016d3f140STakashi Iwai if (rate_changed)
10311da177e4SLinus Torvalds snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE,
10321da177e4SLinus Torvalds chip->no_vra ? 48000 : runtime->rate);
103316d3f140STakashi Iwai if (chip->spdif_on && viadev->reg_offset == 0x30)
103416d3f140STakashi Iwai snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate);
103516d3f140STakashi Iwai
10361da177e4SLinus Torvalds if (runtime->rate == 48000)
10371da177e4SLinus Torvalds rbits = 0xfffff;
10381da177e4SLinus Torvalds else
1039e437e3d7STakashi Iwai rbits = (0x100000 / 48000) * runtime->rate +
1040e437e3d7STakashi Iwai ((0x100000 % 48000) * runtime->rate) / 48000;
1041da3cec35STakashi Iwai snd_BUG_ON(rbits & ~0xfffff);
10421da177e4SLinus Torvalds snd_via82xx_channel_reset(chip, viadev);
10431da177e4SLinus Torvalds snd_via82xx_set_table_ptr(chip, viadev);
1044e437e3d7STakashi Iwai outb(chip->playback_volume[viadev->reg_offset / 0x10][0],
1045e437e3d7STakashi Iwai VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_L));
1046e437e3d7STakashi Iwai outb(chip->playback_volume[viadev->reg_offset / 0x10][1],
1047e437e3d7STakashi Iwai VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_R));
10481da177e4SLinus Torvalds outl((runtime->format == SNDRV_PCM_FORMAT_S16_LE ? VIA8233_REG_TYPE_16BIT : 0) | /* format */
10491da177e4SLinus Torvalds (runtime->channels > 1 ? VIA8233_REG_TYPE_STEREO : 0) | /* stereo */
10501da177e4SLinus Torvalds rbits | /* rate */
10511da177e4SLinus Torvalds 0xff000000, /* STOP index is never reached */
10521da177e4SLinus Torvalds VIADEV_REG(viadev, OFFSET_STOP_IDX));
10531da177e4SLinus Torvalds udelay(20);
10541da177e4SLinus Torvalds snd_via82xx_codec_ready(chip, 0);
10551da177e4SLinus Torvalds return 0;
10561da177e4SLinus Torvalds }
10571da177e4SLinus Torvalds
10581da177e4SLinus Torvalds /*
10591da177e4SLinus Torvalds * prepare callback for multi-channel playback on via823x
10601da177e4SLinus Torvalds */
snd_via8233_multi_prepare(struct snd_pcm_substream * substream)1061e437e3d7STakashi Iwai static int snd_via8233_multi_prepare(struct snd_pcm_substream *substream)
10621da177e4SLinus Torvalds {
1063e437e3d7STakashi Iwai struct via82xx *chip = snd_pcm_substream_chip(substream);
1064e437e3d7STakashi Iwai struct viadev *viadev = substream->runtime->private_data;
1065e437e3d7STakashi Iwai struct snd_pcm_runtime *runtime = substream->runtime;
10661da177e4SLinus Torvalds unsigned int slots;
10671da177e4SLinus Torvalds int fmt;
10681da177e4SLinus Torvalds
10691da177e4SLinus Torvalds if (via_lock_rate(&chip->rates[0], runtime->rate) < 0)
10701da177e4SLinus Torvalds return -EINVAL;
10711da177e4SLinus Torvalds snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, runtime->rate);
10721da177e4SLinus Torvalds snd_ac97_set_rate(chip->ac97, AC97_PCM_SURR_DAC_RATE, runtime->rate);
10731da177e4SLinus Torvalds snd_ac97_set_rate(chip->ac97, AC97_PCM_LFE_DAC_RATE, runtime->rate);
10741da177e4SLinus Torvalds snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate);
10751da177e4SLinus Torvalds snd_via82xx_channel_reset(chip, viadev);
10761da177e4SLinus Torvalds snd_via82xx_set_table_ptr(chip, viadev);
10771da177e4SLinus Torvalds
1078e437e3d7STakashi Iwai fmt = (runtime->format == SNDRV_PCM_FORMAT_S16_LE) ?
1079e437e3d7STakashi Iwai VIA_REG_MULTPLAY_FMT_16BIT : VIA_REG_MULTPLAY_FMT_8BIT;
10801da177e4SLinus Torvalds fmt |= runtime->channels << 4;
10811da177e4SLinus Torvalds outb(fmt, VIADEV_REG(viadev, OFS_MULTPLAY_FORMAT));
10821da177e4SLinus Torvalds #if 0
10831da177e4SLinus Torvalds if (chip->revision == VIA_REV_8233A)
10841da177e4SLinus Torvalds slots = 0;
10851da177e4SLinus Torvalds else
10861da177e4SLinus Torvalds #endif
10871da177e4SLinus Torvalds {
10881da177e4SLinus Torvalds /* set sample number to slot 3, 4, 7, 8, 6, 9 (for VIA8233/C,8235) */
10891da177e4SLinus Torvalds /* corresponding to FL, FR, RL, RR, C, LFE ?? */
10901da177e4SLinus Torvalds switch (runtime->channels) {
10911da177e4SLinus Torvalds case 1: slots = (1<<0) | (1<<4); break;
10921da177e4SLinus Torvalds case 2: slots = (1<<0) | (2<<4); break;
10931da177e4SLinus Torvalds case 3: slots = (1<<0) | (2<<4) | (5<<8); break;
10941da177e4SLinus Torvalds case 4: slots = (1<<0) | (2<<4) | (3<<8) | (4<<12); break;
10951da177e4SLinus Torvalds case 5: slots = (1<<0) | (2<<4) | (3<<8) | (4<<12) | (5<<16); break;
10961da177e4SLinus Torvalds case 6: slots = (1<<0) | (2<<4) | (3<<8) | (4<<12) | (5<<16) | (6<<20); break;
10971da177e4SLinus Torvalds default: slots = 0; break;
10981da177e4SLinus Torvalds }
10991da177e4SLinus Torvalds }
11001da177e4SLinus Torvalds /* STOP index is never reached */
11011da177e4SLinus Torvalds outl(0xff000000 | slots, VIADEV_REG(viadev, OFFSET_STOP_IDX));
11021da177e4SLinus Torvalds udelay(20);
11031da177e4SLinus Torvalds snd_via82xx_codec_ready(chip, 0);
11041da177e4SLinus Torvalds return 0;
11051da177e4SLinus Torvalds }
11061da177e4SLinus Torvalds
11071da177e4SLinus Torvalds /*
11081da177e4SLinus Torvalds * prepare callback for capture on via823x
11091da177e4SLinus Torvalds */
snd_via8233_capture_prepare(struct snd_pcm_substream * substream)1110e437e3d7STakashi Iwai static int snd_via8233_capture_prepare(struct snd_pcm_substream *substream)
11111da177e4SLinus Torvalds {
1112e437e3d7STakashi Iwai struct via82xx *chip = snd_pcm_substream_chip(substream);
1113e437e3d7STakashi Iwai struct viadev *viadev = substream->runtime->private_data;
1114e437e3d7STakashi Iwai struct snd_pcm_runtime *runtime = substream->runtime;
11151da177e4SLinus Torvalds
11161da177e4SLinus Torvalds if (via_lock_rate(&chip->rates[1], runtime->rate) < 0)
11171da177e4SLinus Torvalds return -EINVAL;
11181da177e4SLinus Torvalds snd_ac97_set_rate(chip->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
11191da177e4SLinus Torvalds snd_via82xx_channel_reset(chip, viadev);
11201da177e4SLinus Torvalds snd_via82xx_set_table_ptr(chip, viadev);
11211da177e4SLinus Torvalds outb(VIA_REG_CAPTURE_FIFO_ENABLE, VIADEV_REG(viadev, OFS_CAPTURE_FIFO));
11221da177e4SLinus Torvalds outl((runtime->format == SNDRV_PCM_FORMAT_S16_LE ? VIA8233_REG_TYPE_16BIT : 0) |
11231da177e4SLinus Torvalds (runtime->channels > 1 ? VIA8233_REG_TYPE_STEREO : 0) |
11241da177e4SLinus Torvalds 0xff000000, /* STOP index is never reached */
11251da177e4SLinus Torvalds VIADEV_REG(viadev, OFFSET_STOP_IDX));
11261da177e4SLinus Torvalds udelay(20);
11271da177e4SLinus Torvalds snd_via82xx_codec_ready(chip, 0);
11281da177e4SLinus Torvalds return 0;
11291da177e4SLinus Torvalds }
11301da177e4SLinus Torvalds
11311da177e4SLinus Torvalds
11321da177e4SLinus Torvalds /*
11331da177e4SLinus Torvalds * pcm hardware definition, identical for both playback and capture
11341da177e4SLinus Torvalds */
1135dee49895SBhumika Goyal static const struct snd_pcm_hardware snd_via82xx_hw =
11361da177e4SLinus Torvalds {
11371da177e4SLinus Torvalds .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
11381da177e4SLinus Torvalds SNDRV_PCM_INFO_BLOCK_TRANSFER |
11391da177e4SLinus Torvalds SNDRV_PCM_INFO_MMAP_VALID |
114041e4845cSJaroslav Kysela /* SNDRV_PCM_INFO_RESUME | */
11411da177e4SLinus Torvalds SNDRV_PCM_INFO_PAUSE),
11421da177e4SLinus Torvalds .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
11431da177e4SLinus Torvalds .rates = SNDRV_PCM_RATE_48000,
11441da177e4SLinus Torvalds .rate_min = 48000,
11451da177e4SLinus Torvalds .rate_max = 48000,
11461da177e4SLinus Torvalds .channels_min = 1,
11471da177e4SLinus Torvalds .channels_max = 2,
11485503600aSTakashi Iwai .buffer_bytes_max = VIA_MAX_BUFSIZE,
11491da177e4SLinus Torvalds .period_bytes_min = 32,
11505503600aSTakashi Iwai .period_bytes_max = VIA_MAX_BUFSIZE / 2,
11511da177e4SLinus Torvalds .periods_min = 2,
11521da177e4SLinus Torvalds .periods_max = VIA_TABLE_SIZE / 2,
11531da177e4SLinus Torvalds .fifo_size = 0,
11541da177e4SLinus Torvalds };
11551da177e4SLinus Torvalds
11561da177e4SLinus Torvalds
11571da177e4SLinus Torvalds /*
11581da177e4SLinus Torvalds * open callback skeleton
11591da177e4SLinus Torvalds */
snd_via82xx_pcm_open(struct via82xx * chip,struct viadev * viadev,struct snd_pcm_substream * substream)1160e437e3d7STakashi Iwai static int snd_via82xx_pcm_open(struct via82xx *chip, struct viadev *viadev,
1161e437e3d7STakashi Iwai struct snd_pcm_substream *substream)
11621da177e4SLinus Torvalds {
1163e437e3d7STakashi Iwai struct snd_pcm_runtime *runtime = substream->runtime;
11641da177e4SLinus Torvalds int err;
11651da177e4SLinus Torvalds struct via_rate_lock *ratep;
11665495ffbdSClemens Ladisch bool use_src = false;
11671da177e4SLinus Torvalds
11681da177e4SLinus Torvalds runtime->hw = snd_via82xx_hw;
11691da177e4SLinus Torvalds
11701da177e4SLinus Torvalds /* set the hw rate condition */
11711da177e4SLinus Torvalds ratep = &chip->rates[viadev->direction];
11721da177e4SLinus Torvalds spin_lock_irq(&ratep->lock);
11731da177e4SLinus Torvalds ratep->used++;
11741da177e4SLinus Torvalds if (chip->spdif_on && viadev->reg_offset == 0x30) {
11751da177e4SLinus Torvalds /* DXS#3 and spdif is on */
11761da177e4SLinus Torvalds runtime->hw.rates = chip->ac97->rates[AC97_RATES_SPDIF];
11771da177e4SLinus Torvalds snd_pcm_limit_hw_rates(runtime);
11781da177e4SLinus Torvalds } else if (chip->dxs_fixed && viadev->reg_offset < 0x40) {
11791da177e4SLinus Torvalds /* fixed DXS playback rate */
11801da177e4SLinus Torvalds runtime->hw.rates = SNDRV_PCM_RATE_48000;
11811da177e4SLinus Torvalds runtime->hw.rate_min = runtime->hw.rate_max = 48000;
11822d7eb7cbSSergey Vlasov } else if (chip->dxs_src && viadev->reg_offset < 0x40) {
11832d7eb7cbSSergey Vlasov /* use full SRC capabilities of DXS */
11842d7eb7cbSSergey Vlasov runtime->hw.rates = (SNDRV_PCM_RATE_CONTINUOUS |
11852d7eb7cbSSergey Vlasov SNDRV_PCM_RATE_8000_48000);
11862d7eb7cbSSergey Vlasov runtime->hw.rate_min = 8000;
11872d7eb7cbSSergey Vlasov runtime->hw.rate_max = 48000;
11885495ffbdSClemens Ladisch use_src = true;
11891da177e4SLinus Torvalds } else if (! ratep->rate) {
11901da177e4SLinus Torvalds int idx = viadev->direction ? AC97_RATES_ADC : AC97_RATES_FRONT_DAC;
11911da177e4SLinus Torvalds runtime->hw.rates = chip->ac97->rates[idx];
11921da177e4SLinus Torvalds snd_pcm_limit_hw_rates(runtime);
11931da177e4SLinus Torvalds } else {
11941da177e4SLinus Torvalds /* a fixed rate */
11951da177e4SLinus Torvalds runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
11961da177e4SLinus Torvalds runtime->hw.rate_max = runtime->hw.rate_min = ratep->rate;
11971da177e4SLinus Torvalds }
11981da177e4SLinus Torvalds spin_unlock_irq(&ratep->lock);
11991da177e4SLinus Torvalds
12001da177e4SLinus Torvalds /* we may remove following constaint when we modify table entries
12011da177e4SLinus Torvalds in interrupt */
1202afb342f0STakashi Iwai err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
1203afb342f0STakashi Iwai if (err < 0)
12041da177e4SLinus Torvalds return err;
12051da177e4SLinus Torvalds
12065495ffbdSClemens Ladisch if (use_src) {
12075495ffbdSClemens Ladisch err = snd_pcm_hw_rule_noresample(runtime, 48000);
12085495ffbdSClemens Ladisch if (err < 0)
12095495ffbdSClemens Ladisch return err;
12105495ffbdSClemens Ladisch }
12115495ffbdSClemens Ladisch
12121da177e4SLinus Torvalds runtime->private_data = viadev;
12131da177e4SLinus Torvalds viadev->substream = substream;
12141da177e4SLinus Torvalds
12151da177e4SLinus Torvalds return 0;
12161da177e4SLinus Torvalds }
12171da177e4SLinus Torvalds
12181da177e4SLinus Torvalds
12191da177e4SLinus Torvalds /*
12203d009413SClemens Ladisch * open callback for playback on via686
12211da177e4SLinus Torvalds */
snd_via686_playback_open(struct snd_pcm_substream * substream)12223d009413SClemens Ladisch static int snd_via686_playback_open(struct snd_pcm_substream *substream)
12231da177e4SLinus Torvalds {
1224e437e3d7STakashi Iwai struct via82xx *chip = snd_pcm_substream_chip(substream);
1225e437e3d7STakashi Iwai struct viadev *viadev = &chip->devs[chip->playback_devno + substream->number];
12261da177e4SLinus Torvalds int err;
12271da177e4SLinus Torvalds
1228afb342f0STakashi Iwai err = snd_via82xx_pcm_open(chip, viadev, substream);
1229afb342f0STakashi Iwai if (err < 0)
12301da177e4SLinus Torvalds return err;
12311da177e4SLinus Torvalds return 0;
12321da177e4SLinus Torvalds }
12331da177e4SLinus Torvalds
12341da177e4SLinus Torvalds /*
12353d009413SClemens Ladisch * open callback for playback on via823x DXS
12363d009413SClemens Ladisch */
snd_via8233_playback_open(struct snd_pcm_substream * substream)12373d009413SClemens Ladisch static int snd_via8233_playback_open(struct snd_pcm_substream *substream)
12383d009413SClemens Ladisch {
12393d009413SClemens Ladisch struct via82xx *chip = snd_pcm_substream_chip(substream);
12403d009413SClemens Ladisch struct viadev *viadev;
12413d009413SClemens Ladisch unsigned int stream;
12423d009413SClemens Ladisch int err;
12433d009413SClemens Ladisch
12443d009413SClemens Ladisch viadev = &chip->devs[chip->playback_devno + substream->number];
1245afb342f0STakashi Iwai err = snd_via82xx_pcm_open(chip, viadev, substream);
1246afb342f0STakashi Iwai if (err < 0)
12473d009413SClemens Ladisch return err;
12483d009413SClemens Ladisch stream = viadev->reg_offset / 0x10;
12493d009413SClemens Ladisch if (chip->dxs_controls[stream]) {
1250395c61d1SClemens Ladisch chip->playback_volume[stream][0] =
1251395c61d1SClemens Ladisch VIA_DXS_MAX_VOLUME - (dxs_init_volume & 31);
1252395c61d1SClemens Ladisch chip->playback_volume[stream][1] =
1253395c61d1SClemens Ladisch VIA_DXS_MAX_VOLUME - (dxs_init_volume & 31);
12543d009413SClemens Ladisch chip->dxs_controls[stream]->vd[0].access &=
12553d009413SClemens Ladisch ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
12563d009413SClemens Ladisch snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE |
12573d009413SClemens Ladisch SNDRV_CTL_EVENT_MASK_INFO,
12583d009413SClemens Ladisch &chip->dxs_controls[stream]->id);
12593d009413SClemens Ladisch }
12603d009413SClemens Ladisch return 0;
12613d009413SClemens Ladisch }
12623d009413SClemens Ladisch
12633d009413SClemens Ladisch /*
12641da177e4SLinus Torvalds * open callback for playback on via823x multi-channel
12651da177e4SLinus Torvalds */
snd_via8233_multi_open(struct snd_pcm_substream * substream)1266e437e3d7STakashi Iwai static int snd_via8233_multi_open(struct snd_pcm_substream *substream)
12671da177e4SLinus Torvalds {
1268e437e3d7STakashi Iwai struct via82xx *chip = snd_pcm_substream_chip(substream);
1269e437e3d7STakashi Iwai struct viadev *viadev = &chip->devs[chip->multi_devno];
12701da177e4SLinus Torvalds int err;
12711da177e4SLinus Torvalds /* channels constraint for VIA8233A
12721da177e4SLinus Torvalds * 3 and 5 channels are not supported
12731da177e4SLinus Torvalds */
1274fbc57b2aSTakashi Iwai static const unsigned int channels[] = {
12751da177e4SLinus Torvalds 1, 2, 4, 6
12761da177e4SLinus Torvalds };
1277fbc57b2aSTakashi Iwai static const struct snd_pcm_hw_constraint_list hw_constraints_channels = {
12781da177e4SLinus Torvalds .count = ARRAY_SIZE(channels),
12791da177e4SLinus Torvalds .list = channels,
12801da177e4SLinus Torvalds .mask = 0,
12811da177e4SLinus Torvalds };
12821da177e4SLinus Torvalds
1283afb342f0STakashi Iwai err = snd_via82xx_pcm_open(chip, viadev, substream);
1284afb342f0STakashi Iwai if (err < 0)
12851da177e4SLinus Torvalds return err;
12861da177e4SLinus Torvalds substream->runtime->hw.channels_max = 6;
12871da177e4SLinus Torvalds if (chip->revision == VIA_REV_8233A)
1288e437e3d7STakashi Iwai snd_pcm_hw_constraint_list(substream->runtime, 0,
1289e437e3d7STakashi Iwai SNDRV_PCM_HW_PARAM_CHANNELS,
1290e437e3d7STakashi Iwai &hw_constraints_channels);
12911da177e4SLinus Torvalds return 0;
12921da177e4SLinus Torvalds }
12931da177e4SLinus Torvalds
12941da177e4SLinus Torvalds /*
12951da177e4SLinus Torvalds * open callback for capture on via686 and via823x
12961da177e4SLinus Torvalds */
snd_via82xx_capture_open(struct snd_pcm_substream * substream)1297e437e3d7STakashi Iwai static int snd_via82xx_capture_open(struct snd_pcm_substream *substream)
12981da177e4SLinus Torvalds {
1299e437e3d7STakashi Iwai struct via82xx *chip = snd_pcm_substream_chip(substream);
1300e437e3d7STakashi Iwai struct viadev *viadev = &chip->devs[chip->capture_devno + substream->pcm->device];
13011da177e4SLinus Torvalds
13021da177e4SLinus Torvalds return snd_via82xx_pcm_open(chip, viadev, substream);
13031da177e4SLinus Torvalds }
13041da177e4SLinus Torvalds
13051da177e4SLinus Torvalds /*
13061da177e4SLinus Torvalds * close callback
13071da177e4SLinus Torvalds */
snd_via82xx_pcm_close(struct snd_pcm_substream * substream)1308e437e3d7STakashi Iwai static int snd_via82xx_pcm_close(struct snd_pcm_substream *substream)
13091da177e4SLinus Torvalds {
1310e437e3d7STakashi Iwai struct via82xx *chip = snd_pcm_substream_chip(substream);
1311e437e3d7STakashi Iwai struct viadev *viadev = substream->runtime->private_data;
13121da177e4SLinus Torvalds struct via_rate_lock *ratep;
13131da177e4SLinus Torvalds
13141da177e4SLinus Torvalds /* release the rate lock */
13151da177e4SLinus Torvalds ratep = &chip->rates[viadev->direction];
13161da177e4SLinus Torvalds spin_lock_irq(&ratep->lock);
13171da177e4SLinus Torvalds ratep->used--;
13181da177e4SLinus Torvalds if (! ratep->used)
13191da177e4SLinus Torvalds ratep->rate = 0;
13201da177e4SLinus Torvalds spin_unlock_irq(&ratep->lock);
13216dbe6628STakashi Iwai if (! ratep->rate) {
13226dbe6628STakashi Iwai if (! viadev->direction) {
13236dbe6628STakashi Iwai snd_ac97_update_power(chip->ac97,
13246dbe6628STakashi Iwai AC97_PCM_FRONT_DAC_RATE, 0);
13256dbe6628STakashi Iwai snd_ac97_update_power(chip->ac97,
13266dbe6628STakashi Iwai AC97_PCM_SURR_DAC_RATE, 0);
13276dbe6628STakashi Iwai snd_ac97_update_power(chip->ac97,
13286dbe6628STakashi Iwai AC97_PCM_LFE_DAC_RATE, 0);
13296dbe6628STakashi Iwai } else
13306dbe6628STakashi Iwai snd_ac97_update_power(chip->ac97,
13316dbe6628STakashi Iwai AC97_PCM_LR_ADC_RATE, 0);
13326dbe6628STakashi Iwai }
13331da177e4SLinus Torvalds viadev->substream = NULL;
13341da177e4SLinus Torvalds return 0;
13351da177e4SLinus Torvalds }
13361da177e4SLinus Torvalds
snd_via8233_playback_close(struct snd_pcm_substream * substream)13373d009413SClemens Ladisch static int snd_via8233_playback_close(struct snd_pcm_substream *substream)
13383d009413SClemens Ladisch {
13393d009413SClemens Ladisch struct via82xx *chip = snd_pcm_substream_chip(substream);
13403d009413SClemens Ladisch struct viadev *viadev = substream->runtime->private_data;
13413d009413SClemens Ladisch unsigned int stream;
13423d009413SClemens Ladisch
13433d009413SClemens Ladisch stream = viadev->reg_offset / 0x10;
13443d009413SClemens Ladisch if (chip->dxs_controls[stream]) {
13453d009413SClemens Ladisch chip->dxs_controls[stream]->vd[0].access |=
13463d009413SClemens Ladisch SNDRV_CTL_ELEM_ACCESS_INACTIVE;
13473d009413SClemens Ladisch snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_INFO,
13483d009413SClemens Ladisch &chip->dxs_controls[stream]->id);
13493d009413SClemens Ladisch }
13503d009413SClemens Ladisch return snd_via82xx_pcm_close(substream);
13513d009413SClemens Ladisch }
13523d009413SClemens Ladisch
13531da177e4SLinus Torvalds
13541da177e4SLinus Torvalds /* via686 playback callbacks */
13556769e988SJulia Lawall static const struct snd_pcm_ops snd_via686_playback_ops = {
13563d009413SClemens Ladisch .open = snd_via686_playback_open,
13571da177e4SLinus Torvalds .close = snd_via82xx_pcm_close,
13581da177e4SLinus Torvalds .hw_params = snd_via82xx_hw_params,
13591da177e4SLinus Torvalds .hw_free = snd_via82xx_hw_free,
13601da177e4SLinus Torvalds .prepare = snd_via686_playback_prepare,
13611da177e4SLinus Torvalds .trigger = snd_via82xx_pcm_trigger,
13621da177e4SLinus Torvalds .pointer = snd_via686_pcm_pointer,
13631da177e4SLinus Torvalds };
13641da177e4SLinus Torvalds
13651da177e4SLinus Torvalds /* via686 capture callbacks */
13666769e988SJulia Lawall static const struct snd_pcm_ops snd_via686_capture_ops = {
13671da177e4SLinus Torvalds .open = snd_via82xx_capture_open,
13681da177e4SLinus Torvalds .close = snd_via82xx_pcm_close,
13691da177e4SLinus Torvalds .hw_params = snd_via82xx_hw_params,
13701da177e4SLinus Torvalds .hw_free = snd_via82xx_hw_free,
13711da177e4SLinus Torvalds .prepare = snd_via686_capture_prepare,
13721da177e4SLinus Torvalds .trigger = snd_via82xx_pcm_trigger,
13731da177e4SLinus Torvalds .pointer = snd_via686_pcm_pointer,
13741da177e4SLinus Torvalds };
13751da177e4SLinus Torvalds
13761da177e4SLinus Torvalds /* via823x DSX playback callbacks */
13776769e988SJulia Lawall static const struct snd_pcm_ops snd_via8233_playback_ops = {
13783d009413SClemens Ladisch .open = snd_via8233_playback_open,
13793d009413SClemens Ladisch .close = snd_via8233_playback_close,
13801da177e4SLinus Torvalds .hw_params = snd_via82xx_hw_params,
13811da177e4SLinus Torvalds .hw_free = snd_via82xx_hw_free,
13821da177e4SLinus Torvalds .prepare = snd_via8233_playback_prepare,
13831da177e4SLinus Torvalds .trigger = snd_via82xx_pcm_trigger,
13841da177e4SLinus Torvalds .pointer = snd_via8233_pcm_pointer,
13851da177e4SLinus Torvalds };
13861da177e4SLinus Torvalds
13871da177e4SLinus Torvalds /* via823x multi-channel playback callbacks */
13886769e988SJulia Lawall static const struct snd_pcm_ops snd_via8233_multi_ops = {
13891da177e4SLinus Torvalds .open = snd_via8233_multi_open,
13901da177e4SLinus Torvalds .close = snd_via82xx_pcm_close,
13911da177e4SLinus Torvalds .hw_params = snd_via82xx_hw_params,
13921da177e4SLinus Torvalds .hw_free = snd_via82xx_hw_free,
13931da177e4SLinus Torvalds .prepare = snd_via8233_multi_prepare,
13941da177e4SLinus Torvalds .trigger = snd_via82xx_pcm_trigger,
13951da177e4SLinus Torvalds .pointer = snd_via8233_pcm_pointer,
13961da177e4SLinus Torvalds };
13971da177e4SLinus Torvalds
13981da177e4SLinus Torvalds /* via823x capture callbacks */
13996769e988SJulia Lawall static const struct snd_pcm_ops snd_via8233_capture_ops = {
14001da177e4SLinus Torvalds .open = snd_via82xx_capture_open,
14011da177e4SLinus Torvalds .close = snd_via82xx_pcm_close,
14021da177e4SLinus Torvalds .hw_params = snd_via82xx_hw_params,
14031da177e4SLinus Torvalds .hw_free = snd_via82xx_hw_free,
14041da177e4SLinus Torvalds .prepare = snd_via8233_capture_prepare,
14051da177e4SLinus Torvalds .trigger = snd_via82xx_pcm_trigger,
14061da177e4SLinus Torvalds .pointer = snd_via8233_pcm_pointer,
14071da177e4SLinus Torvalds };
14081da177e4SLinus Torvalds
14091da177e4SLinus Torvalds
init_viadev(struct via82xx * chip,int idx,unsigned int reg_offset,int shadow_pos,int direction)1410e437e3d7STakashi Iwai static void init_viadev(struct via82xx *chip, int idx, unsigned int reg_offset,
1411e437e3d7STakashi Iwai int shadow_pos, int direction)
14121da177e4SLinus Torvalds {
14131da177e4SLinus Torvalds chip->devs[idx].reg_offset = reg_offset;
14144f550df5SKarsten Wiese chip->devs[idx].shadow_shift = shadow_pos * 4;
14151da177e4SLinus Torvalds chip->devs[idx].direction = direction;
14161da177e4SLinus Torvalds chip->devs[idx].port = chip->port + reg_offset;
14171da177e4SLinus Torvalds }
14181da177e4SLinus Torvalds
14191da177e4SLinus Torvalds /*
14201da177e4SLinus Torvalds * create pcm instances for VIA8233, 8233C and 8235 (not 8233A)
14211da177e4SLinus Torvalds */
snd_via8233_pcm_new(struct via82xx * chip)1422e23e7a14SBill Pemberton static int snd_via8233_pcm_new(struct via82xx *chip)
14231da177e4SLinus Torvalds {
1424e437e3d7STakashi Iwai struct snd_pcm *pcm;
1425e36e3b86STakashi Iwai struct snd_pcm_chmap *chmap;
14261da177e4SLinus Torvalds int i, err;
14271da177e4SLinus Torvalds
14281da177e4SLinus Torvalds chip->playback_devno = 0; /* x 4 */
14291da177e4SLinus Torvalds chip->multi_devno = 4; /* x 1 */
14301da177e4SLinus Torvalds chip->capture_devno = 5; /* x 2 */
14311da177e4SLinus Torvalds chip->num_devs = 7;
14321da177e4SLinus Torvalds chip->intr_mask = 0x33033333; /* FLAG|EOL for rec0-1, mc, sdx0-3 */
14331da177e4SLinus Torvalds
14341da177e4SLinus Torvalds /* PCM #0: 4 DSX playbacks and 1 capture */
14351da177e4SLinus Torvalds err = snd_pcm_new(chip->card, chip->card->shortname, 0, 4, 1, &pcm);
14361da177e4SLinus Torvalds if (err < 0)
14371da177e4SLinus Torvalds return err;
14381da177e4SLinus Torvalds snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_playback_ops);
14391da177e4SLinus Torvalds snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via8233_capture_ops);
14401da177e4SLinus Torvalds pcm->private_data = chip;
14411da177e4SLinus Torvalds strcpy(pcm->name, chip->card->shortname);
14421da177e4SLinus Torvalds chip->pcms[0] = pcm;
14431da177e4SLinus Torvalds /* set up playbacks */
14441da177e4SLinus Torvalds for (i = 0; i < 4; i++)
14454f550df5SKarsten Wiese init_viadev(chip, i, 0x10 * i, i, 0);
14461da177e4SLinus Torvalds /* capture */
14474f550df5SKarsten Wiese init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1);
14481da177e4SLinus Torvalds
14498e2c7524STakashi Iwai snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
14506974f8adSTakashi Iwai &chip->pci->dev,
14515503600aSTakashi Iwai 64*1024, VIA_MAX_BUFSIZE);
14521da177e4SLinus Torvalds
1453e36e3b86STakashi Iwai err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1454e36e3b86STakashi Iwai snd_pcm_std_chmaps, 2, 0,
1455e36e3b86STakashi Iwai &chmap);
1456e36e3b86STakashi Iwai if (err < 0)
1457e36e3b86STakashi Iwai return err;
1458e36e3b86STakashi Iwai
14591da177e4SLinus Torvalds /* PCM #1: multi-channel playback and 2nd capture */
14601da177e4SLinus Torvalds err = snd_pcm_new(chip->card, chip->card->shortname, 1, 1, 1, &pcm);
14611da177e4SLinus Torvalds if (err < 0)
14621da177e4SLinus Torvalds return err;
14631da177e4SLinus Torvalds snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_multi_ops);
14641da177e4SLinus Torvalds snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via8233_capture_ops);
14651da177e4SLinus Torvalds pcm->private_data = chip;
14661da177e4SLinus Torvalds strcpy(pcm->name, chip->card->shortname);
14671da177e4SLinus Torvalds chip->pcms[1] = pcm;
14681da177e4SLinus Torvalds /* set up playback */
14694f550df5SKarsten Wiese init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 4, 0);
14701da177e4SLinus Torvalds /* set up capture */
14714f550df5SKarsten Wiese init_viadev(chip, chip->capture_devno + 1, VIA_REG_CAPTURE_8233_STATUS + 0x10, 7, 1);
14721da177e4SLinus Torvalds
14738e2c7524STakashi Iwai snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
14746974f8adSTakashi Iwai &chip->pci->dev,
14755503600aSTakashi Iwai 64*1024, VIA_MAX_BUFSIZE);
1476e36e3b86STakashi Iwai
1477e36e3b86STakashi Iwai err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1478e36e3b86STakashi Iwai snd_pcm_alt_chmaps, 6, 0,
1479e36e3b86STakashi Iwai &chmap);
1480e36e3b86STakashi Iwai if (err < 0)
1481e36e3b86STakashi Iwai return err;
1482e36e3b86STakashi Iwai chip->ac97->chmaps[SNDRV_PCM_STREAM_PLAYBACK] = chmap;
1483e36e3b86STakashi Iwai
14841da177e4SLinus Torvalds return 0;
14851da177e4SLinus Torvalds }
14861da177e4SLinus Torvalds
14871da177e4SLinus Torvalds /*
14881da177e4SLinus Torvalds * create pcm instances for VIA8233A
14891da177e4SLinus Torvalds */
snd_via8233a_pcm_new(struct via82xx * chip)1490e23e7a14SBill Pemberton static int snd_via8233a_pcm_new(struct via82xx *chip)
14911da177e4SLinus Torvalds {
1492e437e3d7STakashi Iwai struct snd_pcm *pcm;
1493e36e3b86STakashi Iwai struct snd_pcm_chmap *chmap;
14941da177e4SLinus Torvalds int err;
14951da177e4SLinus Torvalds
14961da177e4SLinus Torvalds chip->multi_devno = 0;
14971da177e4SLinus Torvalds chip->playback_devno = 1;
14981da177e4SLinus Torvalds chip->capture_devno = 2;
14991da177e4SLinus Torvalds chip->num_devs = 3;
15001da177e4SLinus Torvalds chip->intr_mask = 0x03033000; /* FLAG|EOL for rec0, mc, sdx3 */
15011da177e4SLinus Torvalds
15021da177e4SLinus Torvalds /* PCM #0: multi-channel playback and capture */
15031da177e4SLinus Torvalds err = snd_pcm_new(chip->card, chip->card->shortname, 0, 1, 1, &pcm);
15041da177e4SLinus Torvalds if (err < 0)
15051da177e4SLinus Torvalds return err;
15061da177e4SLinus Torvalds snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_multi_ops);
15071da177e4SLinus Torvalds snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via8233_capture_ops);
15081da177e4SLinus Torvalds pcm->private_data = chip;
15091da177e4SLinus Torvalds strcpy(pcm->name, chip->card->shortname);
15101da177e4SLinus Torvalds chip->pcms[0] = pcm;
15111da177e4SLinus Torvalds /* set up playback */
15124f550df5SKarsten Wiese init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 4, 0);
15131da177e4SLinus Torvalds /* capture */
15144f550df5SKarsten Wiese init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1);
15151da177e4SLinus Torvalds
15168e2c7524STakashi Iwai snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
15176974f8adSTakashi Iwai &chip->pci->dev,
15185503600aSTakashi Iwai 64*1024, VIA_MAX_BUFSIZE);
15191da177e4SLinus Torvalds
1520e36e3b86STakashi Iwai err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1521e36e3b86STakashi Iwai snd_pcm_alt_chmaps, 6, 0,
1522e36e3b86STakashi Iwai &chmap);
1523e36e3b86STakashi Iwai if (err < 0)
1524e36e3b86STakashi Iwai return err;
1525e36e3b86STakashi Iwai chip->ac97->chmaps[SNDRV_PCM_STREAM_PLAYBACK] = chmap;
1526e36e3b86STakashi Iwai
15271da177e4SLinus Torvalds /* SPDIF supported? */
15281da177e4SLinus Torvalds if (! ac97_can_spdif(chip->ac97))
15291da177e4SLinus Torvalds return 0;
15301da177e4SLinus Torvalds
15311da177e4SLinus Torvalds /* PCM #1: DXS3 playback (for spdif) */
15321da177e4SLinus Torvalds err = snd_pcm_new(chip->card, chip->card->shortname, 1, 1, 0, &pcm);
15331da177e4SLinus Torvalds if (err < 0)
15341da177e4SLinus Torvalds return err;
15351da177e4SLinus Torvalds snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_playback_ops);
15361da177e4SLinus Torvalds pcm->private_data = chip;
15371da177e4SLinus Torvalds strcpy(pcm->name, chip->card->shortname);
15381da177e4SLinus Torvalds chip->pcms[1] = pcm;
15391da177e4SLinus Torvalds /* set up playback */
15404f550df5SKarsten Wiese init_viadev(chip, chip->playback_devno, 0x30, 3, 0);
15411da177e4SLinus Torvalds
15428e2c7524STakashi Iwai snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
15436974f8adSTakashi Iwai &chip->pci->dev,
15445503600aSTakashi Iwai 64*1024, VIA_MAX_BUFSIZE);
15451da177e4SLinus Torvalds return 0;
15461da177e4SLinus Torvalds }
15471da177e4SLinus Torvalds
15481da177e4SLinus Torvalds /*
15491da177e4SLinus Torvalds * create a pcm instance for via686a/b
15501da177e4SLinus Torvalds */
snd_via686_pcm_new(struct via82xx * chip)1551e23e7a14SBill Pemberton static int snd_via686_pcm_new(struct via82xx *chip)
15521da177e4SLinus Torvalds {
1553e437e3d7STakashi Iwai struct snd_pcm *pcm;
15541da177e4SLinus Torvalds int err;
15551da177e4SLinus Torvalds
15561da177e4SLinus Torvalds chip->playback_devno = 0;
15571da177e4SLinus Torvalds chip->capture_devno = 1;
15581da177e4SLinus Torvalds chip->num_devs = 2;
15591da177e4SLinus Torvalds chip->intr_mask = 0x77; /* FLAG | EOL for PB, CP, FM */
15601da177e4SLinus Torvalds
15611da177e4SLinus Torvalds err = snd_pcm_new(chip->card, chip->card->shortname, 0, 1, 1, &pcm);
15621da177e4SLinus Torvalds if (err < 0)
15631da177e4SLinus Torvalds return err;
15641da177e4SLinus Torvalds snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via686_playback_ops);
15651da177e4SLinus Torvalds snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via686_capture_ops);
15661da177e4SLinus Torvalds pcm->private_data = chip;
15671da177e4SLinus Torvalds strcpy(pcm->name, chip->card->shortname);
15681da177e4SLinus Torvalds chip->pcms[0] = pcm;
15694f550df5SKarsten Wiese init_viadev(chip, 0, VIA_REG_PLAYBACK_STATUS, 0, 0);
15704f550df5SKarsten Wiese init_viadev(chip, 1, VIA_REG_CAPTURE_STATUS, 0, 1);
15711da177e4SLinus Torvalds
15728e2c7524STakashi Iwai snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
15736974f8adSTakashi Iwai &chip->pci->dev,
15745503600aSTakashi Iwai 64*1024, VIA_MAX_BUFSIZE);
15751da177e4SLinus Torvalds return 0;
15761da177e4SLinus Torvalds }
15771da177e4SLinus Torvalds
15781da177e4SLinus Torvalds
15791da177e4SLinus Torvalds /*
15801da177e4SLinus Torvalds * Mixer part
15811da177e4SLinus Torvalds */
15821da177e4SLinus Torvalds
snd_via8233_capture_source_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1583e437e3d7STakashi Iwai static int snd_via8233_capture_source_info(struct snd_kcontrol *kcontrol,
1584e437e3d7STakashi Iwai struct snd_ctl_elem_info *uinfo)
15851da177e4SLinus Torvalds {
15861da177e4SLinus Torvalds /* formerly they were "Line" and "Mic", but it looks like that they
15871da177e4SLinus Torvalds * have nothing to do with the actual physical connections...
15881da177e4SLinus Torvalds */
15899883ab91STakashi Iwai static const char * const texts[2] = {
15901da177e4SLinus Torvalds "Input1", "Input2"
15911da177e4SLinus Torvalds };
15929883ab91STakashi Iwai return snd_ctl_enum_info(uinfo, 1, 2, texts);
15931da177e4SLinus Torvalds }
15941da177e4SLinus Torvalds
snd_via8233_capture_source_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1595e437e3d7STakashi Iwai static int snd_via8233_capture_source_get(struct snd_kcontrol *kcontrol,
1596e437e3d7STakashi Iwai struct snd_ctl_elem_value *ucontrol)
15971da177e4SLinus Torvalds {
1598e437e3d7STakashi Iwai struct via82xx *chip = snd_kcontrol_chip(kcontrol);
15991da177e4SLinus Torvalds unsigned long port = chip->port + (kcontrol->id.index ? (VIA_REG_CAPTURE_CHANNEL + 0x10) : VIA_REG_CAPTURE_CHANNEL);
16001da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = inb(port) & VIA_REG_CAPTURE_CHANNEL_MIC ? 1 : 0;
16011da177e4SLinus Torvalds return 0;
16021da177e4SLinus Torvalds }
16031da177e4SLinus Torvalds
snd_via8233_capture_source_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1604e437e3d7STakashi Iwai static int snd_via8233_capture_source_put(struct snd_kcontrol *kcontrol,
1605e437e3d7STakashi Iwai struct snd_ctl_elem_value *ucontrol)
16061da177e4SLinus Torvalds {
1607e437e3d7STakashi Iwai struct via82xx *chip = snd_kcontrol_chip(kcontrol);
16081da177e4SLinus Torvalds unsigned long port = chip->port + (kcontrol->id.index ? (VIA_REG_CAPTURE_CHANNEL + 0x10) : VIA_REG_CAPTURE_CHANNEL);
16091da177e4SLinus Torvalds u8 val, oval;
16101da177e4SLinus Torvalds
16111da177e4SLinus Torvalds spin_lock_irq(&chip->reg_lock);
16121da177e4SLinus Torvalds oval = inb(port);
16131da177e4SLinus Torvalds val = oval & ~VIA_REG_CAPTURE_CHANNEL_MIC;
16141da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0])
16151da177e4SLinus Torvalds val |= VIA_REG_CAPTURE_CHANNEL_MIC;
16161da177e4SLinus Torvalds if (val != oval)
16171da177e4SLinus Torvalds outb(val, port);
16181da177e4SLinus Torvalds spin_unlock_irq(&chip->reg_lock);
16191da177e4SLinus Torvalds return val != oval;
16201da177e4SLinus Torvalds }
16211da177e4SLinus Torvalds
1622e23e7a14SBill Pemberton static struct snd_kcontrol_new snd_via8233_capture_source = {
16231da177e4SLinus Torvalds .name = "Input Source Select",
16241da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
16251da177e4SLinus Torvalds .info = snd_via8233_capture_source_info,
16261da177e4SLinus Torvalds .get = snd_via8233_capture_source_get,
16271da177e4SLinus Torvalds .put = snd_via8233_capture_source_put,
16281da177e4SLinus Torvalds };
16291da177e4SLinus Torvalds
1630a5ce8890STakashi Iwai #define snd_via8233_dxs3_spdif_info snd_ctl_boolean_mono_info
16311da177e4SLinus Torvalds
snd_via8233_dxs3_spdif_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1632e437e3d7STakashi Iwai static int snd_via8233_dxs3_spdif_get(struct snd_kcontrol *kcontrol,
1633e437e3d7STakashi Iwai struct snd_ctl_elem_value *ucontrol)
16341da177e4SLinus Torvalds {
1635e437e3d7STakashi Iwai struct via82xx *chip = snd_kcontrol_chip(kcontrol);
16361da177e4SLinus Torvalds u8 val;
16371da177e4SLinus Torvalds
16381da177e4SLinus Torvalds pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &val);
16391da177e4SLinus Torvalds ucontrol->value.integer.value[0] = (val & VIA8233_SPDIF_DX3) ? 1 : 0;
16401da177e4SLinus Torvalds return 0;
16411da177e4SLinus Torvalds }
16421da177e4SLinus Torvalds
snd_via8233_dxs3_spdif_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1643e437e3d7STakashi Iwai static int snd_via8233_dxs3_spdif_put(struct snd_kcontrol *kcontrol,
1644e437e3d7STakashi Iwai struct snd_ctl_elem_value *ucontrol)
16451da177e4SLinus Torvalds {
1646e437e3d7STakashi Iwai struct via82xx *chip = snd_kcontrol_chip(kcontrol);
16471da177e4SLinus Torvalds u8 val, oval;
16481da177e4SLinus Torvalds
16491da177e4SLinus Torvalds pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &oval);
16501da177e4SLinus Torvalds val = oval & ~VIA8233_SPDIF_DX3;
16511da177e4SLinus Torvalds if (ucontrol->value.integer.value[0])
16521da177e4SLinus Torvalds val |= VIA8233_SPDIF_DX3;
16531da177e4SLinus Torvalds /* save the spdif flag for rate filtering */
16541da177e4SLinus Torvalds chip->spdif_on = ucontrol->value.integer.value[0] ? 1 : 0;
16551da177e4SLinus Torvalds if (val != oval) {
16561da177e4SLinus Torvalds pci_write_config_byte(chip->pci, VIA8233_SPDIF_CTRL, val);
16571da177e4SLinus Torvalds return 1;
16581da177e4SLinus Torvalds }
16591da177e4SLinus Torvalds return 0;
16601da177e4SLinus Torvalds }
16611da177e4SLinus Torvalds
1662f3b827e0SBhumika Goyal static const struct snd_kcontrol_new snd_via8233_dxs3_spdif_control = {
166310e8d78aSClemens Ladisch .name = SNDRV_CTL_NAME_IEC958("Output ",NONE,SWITCH),
16641da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
16651da177e4SLinus Torvalds .info = snd_via8233_dxs3_spdif_info,
16661da177e4SLinus Torvalds .get = snd_via8233_dxs3_spdif_get,
16671da177e4SLinus Torvalds .put = snd_via8233_dxs3_spdif_put,
16681da177e4SLinus Torvalds };
16691da177e4SLinus Torvalds
snd_via8233_dxs_volume_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1670e437e3d7STakashi Iwai static int snd_via8233_dxs_volume_info(struct snd_kcontrol *kcontrol,
1671e437e3d7STakashi Iwai struct snd_ctl_elem_info *uinfo)
16721da177e4SLinus Torvalds {
16731da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
16741da177e4SLinus Torvalds uinfo->count = 2;
16751da177e4SLinus Torvalds uinfo->value.integer.min = 0;
16761da177e4SLinus Torvalds uinfo->value.integer.max = VIA_DXS_MAX_VOLUME;
16771da177e4SLinus Torvalds return 0;
16781da177e4SLinus Torvalds }
16791da177e4SLinus Torvalds
snd_via8233_dxs_volume_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1680e437e3d7STakashi Iwai static int snd_via8233_dxs_volume_get(struct snd_kcontrol *kcontrol,
1681e437e3d7STakashi Iwai struct snd_ctl_elem_value *ucontrol)
16821da177e4SLinus Torvalds {
1683e437e3d7STakashi Iwai struct via82xx *chip = snd_kcontrol_chip(kcontrol);
16842fb930b5SClemens Ladisch unsigned int idx = kcontrol->id.subdevice;
168500f226d4SHonza Maly
168600f226d4SHonza Maly ucontrol->value.integer.value[0] = VIA_DXS_MAX_VOLUME - chip->playback_volume[idx][0];
168700f226d4SHonza Maly ucontrol->value.integer.value[1] = VIA_DXS_MAX_VOLUME - chip->playback_volume[idx][1];
168800f226d4SHonza Maly return 0;
168900f226d4SHonza Maly }
169000f226d4SHonza Maly
snd_via8233_pcmdxs_volume_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1691e437e3d7STakashi Iwai static int snd_via8233_pcmdxs_volume_get(struct snd_kcontrol *kcontrol,
1692e437e3d7STakashi Iwai struct snd_ctl_elem_value *ucontrol)
169300f226d4SHonza Maly {
1694e437e3d7STakashi Iwai struct via82xx *chip = snd_kcontrol_chip(kcontrol);
169500f226d4SHonza Maly ucontrol->value.integer.value[0] = VIA_DXS_MAX_VOLUME - chip->playback_volume_c[0];
169600f226d4SHonza Maly ucontrol->value.integer.value[1] = VIA_DXS_MAX_VOLUME - chip->playback_volume_c[1];
16971da177e4SLinus Torvalds return 0;
16981da177e4SLinus Torvalds }
16991da177e4SLinus Torvalds
snd_via8233_dxs_volume_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1700e437e3d7STakashi Iwai static int snd_via8233_dxs_volume_put(struct snd_kcontrol *kcontrol,
1701e437e3d7STakashi Iwai struct snd_ctl_elem_value *ucontrol)
17021da177e4SLinus Torvalds {
1703e437e3d7STakashi Iwai struct via82xx *chip = snd_kcontrol_chip(kcontrol);
17042fb930b5SClemens Ladisch unsigned int idx = kcontrol->id.subdevice;
170500f226d4SHonza Maly unsigned long port = chip->port + 0x10 * idx;
170600f226d4SHonza Maly unsigned char val;
170700f226d4SHonza Maly int i, change = 0;
170800f226d4SHonza Maly
170900f226d4SHonza Maly for (i = 0; i < 2; i++) {
171000f226d4SHonza Maly val = ucontrol->value.integer.value[i];
171100f226d4SHonza Maly if (val > VIA_DXS_MAX_VOLUME)
171200f226d4SHonza Maly val = VIA_DXS_MAX_VOLUME;
171300f226d4SHonza Maly val = VIA_DXS_MAX_VOLUME - val;
171400f226d4SHonza Maly change |= val != chip->playback_volume[idx][i];
171500f226d4SHonza Maly if (change) {
171600f226d4SHonza Maly chip->playback_volume[idx][i] = val;
171700f226d4SHonza Maly outb(val, port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i);
171800f226d4SHonza Maly }
171900f226d4SHonza Maly }
172000f226d4SHonza Maly return change;
172100f226d4SHonza Maly }
172200f226d4SHonza Maly
snd_via8233_pcmdxs_volume_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1723e437e3d7STakashi Iwai static int snd_via8233_pcmdxs_volume_put(struct snd_kcontrol *kcontrol,
1724e437e3d7STakashi Iwai struct snd_ctl_elem_value *ucontrol)
172500f226d4SHonza Maly {
1726e437e3d7STakashi Iwai struct via82xx *chip = snd_kcontrol_chip(kcontrol);
17271da177e4SLinus Torvalds unsigned int idx;
17281da177e4SLinus Torvalds unsigned char val;
17291da177e4SLinus Torvalds int i, change = 0;
17301da177e4SLinus Torvalds
17311da177e4SLinus Torvalds for (i = 0; i < 2; i++) {
17321da177e4SLinus Torvalds val = ucontrol->value.integer.value[i];
17331da177e4SLinus Torvalds if (val > VIA_DXS_MAX_VOLUME)
17341da177e4SLinus Torvalds val = VIA_DXS_MAX_VOLUME;
17351da177e4SLinus Torvalds val = VIA_DXS_MAX_VOLUME - val;
173600f226d4SHonza Maly if (val != chip->playback_volume_c[i]) {
17371da177e4SLinus Torvalds change = 1;
173800f226d4SHonza Maly chip->playback_volume_c[i] = val;
17391da177e4SLinus Torvalds for (idx = 0; idx < 4; idx++) {
17401da177e4SLinus Torvalds unsigned long port = chip->port + 0x10 * idx;
174100f226d4SHonza Maly chip->playback_volume[idx][i] = val;
17421da177e4SLinus Torvalds outb(val, port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i);
17431da177e4SLinus Torvalds }
17441da177e4SLinus Torvalds }
17451da177e4SLinus Torvalds }
17461da177e4SLinus Torvalds return change;
17471da177e4SLinus Torvalds }
17481da177e4SLinus Torvalds
1749b452e08eSClemens Ladisch static const DECLARE_TLV_DB_SCALE(db_scale_dxs, -4650, 150, 1);
17507058c042STakashi Iwai
1751f3b827e0SBhumika Goyal static const struct snd_kcontrol_new snd_via8233_pcmdxs_volume_control = {
17521da177e4SLinus Torvalds .name = "PCM Playback Volume",
17531da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
17547058c042STakashi Iwai .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
17557058c042STakashi Iwai SNDRV_CTL_ELEM_ACCESS_TLV_READ),
17561da177e4SLinus Torvalds .info = snd_via8233_dxs_volume_info,
175700f226d4SHonza Maly .get = snd_via8233_pcmdxs_volume_get,
175800f226d4SHonza Maly .put = snd_via8233_pcmdxs_volume_put,
17597058c042STakashi Iwai .tlv = { .p = db_scale_dxs }
176000f226d4SHonza Maly };
176100f226d4SHonza Maly
1762f3b827e0SBhumika Goyal static const struct snd_kcontrol_new snd_via8233_dxs_volume_control = {
17632fb930b5SClemens Ladisch .iface = SNDRV_CTL_ELEM_IFACE_PCM,
17642fb930b5SClemens Ladisch .device = 0,
17652fb930b5SClemens Ladisch /* .subdevice set later */
17662fb930b5SClemens Ladisch .name = "PCM Playback Volume",
17673d009413SClemens Ladisch .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
17683d009413SClemens Ladisch SNDRV_CTL_ELEM_ACCESS_TLV_READ |
17693d009413SClemens Ladisch SNDRV_CTL_ELEM_ACCESS_INACTIVE,
177000f226d4SHonza Maly .info = snd_via8233_dxs_volume_info,
17711da177e4SLinus Torvalds .get = snd_via8233_dxs_volume_get,
17721da177e4SLinus Torvalds .put = snd_via8233_dxs_volume_put,
17737058c042STakashi Iwai .tlv = { .p = db_scale_dxs }
17741da177e4SLinus Torvalds };
17751da177e4SLinus Torvalds
17761da177e4SLinus Torvalds /*
17771da177e4SLinus Torvalds */
17781da177e4SLinus Torvalds
snd_via82xx_mixer_free_ac97_bus(struct snd_ac97_bus * bus)1779e437e3d7STakashi Iwai static void snd_via82xx_mixer_free_ac97_bus(struct snd_ac97_bus *bus)
17801da177e4SLinus Torvalds {
1781e437e3d7STakashi Iwai struct via82xx *chip = bus->private_data;
17821da177e4SLinus Torvalds chip->ac97_bus = NULL;
17831da177e4SLinus Torvalds }
17841da177e4SLinus Torvalds
snd_via82xx_mixer_free_ac97(struct snd_ac97 * ac97)1785e437e3d7STakashi Iwai static void snd_via82xx_mixer_free_ac97(struct snd_ac97 *ac97)
17861da177e4SLinus Torvalds {
1787e437e3d7STakashi Iwai struct via82xx *chip = ac97->private_data;
17881da177e4SLinus Torvalds chip->ac97 = NULL;
17891da177e4SLinus Torvalds }
17901da177e4SLinus Torvalds
1791eab0fbfaSJoe Perches static const struct ac97_quirk ac97_quirks[] = {
17921da177e4SLinus Torvalds {
179369ad07cfSJaroslav Kysela .subvendor = 0x1106,
179469ad07cfSJaroslav Kysela .subdevice = 0x4161,
17951da177e4SLinus Torvalds .codec_id = 0x56494161, /* VT1612A */
17961da177e4SLinus Torvalds .name = "Soltek SL-75DRV5",
17971da177e4SLinus Torvalds .type = AC97_TUNE_NONE
17981da177e4SLinus Torvalds },
17991da177e4SLinus Torvalds { /* FIXME: which codec? */
180069ad07cfSJaroslav Kysela .subvendor = 0x1106,
180169ad07cfSJaroslav Kysela .subdevice = 0x4161,
18021da177e4SLinus Torvalds .name = "ASRock K7VT2",
18031da177e4SLinus Torvalds .type = AC97_TUNE_HP_ONLY
18041da177e4SLinus Torvalds },
18051da177e4SLinus Torvalds {
1806bf30a430SClemens Ladisch .subvendor = 0x110a,
1807bf30a430SClemens Ladisch .subdevice = 0x0079,
1808bf30a430SClemens Ladisch .name = "Fujitsu Siemens D1289",
1809bf30a430SClemens Ladisch .type = AC97_TUNE_HP_ONLY
1810bf30a430SClemens Ladisch },
1811bf30a430SClemens Ladisch {
181269ad07cfSJaroslav Kysela .subvendor = 0x1019,
181369ad07cfSJaroslav Kysela .subdevice = 0x0a81,
18141da177e4SLinus Torvalds .name = "ECS K7VTA3",
18151da177e4SLinus Torvalds .type = AC97_TUNE_HP_ONLY
18161da177e4SLinus Torvalds },
18171da177e4SLinus Torvalds {
181869ad07cfSJaroslav Kysela .subvendor = 0x1019,
181969ad07cfSJaroslav Kysela .subdevice = 0x0a85,
18201da177e4SLinus Torvalds .name = "ECS L7VMM2",
18211da177e4SLinus Torvalds .type = AC97_TUNE_HP_ONLY
18221da177e4SLinus Torvalds },
18231da177e4SLinus Torvalds {
1824942fd1ebSWalter Sheets .subvendor = 0x1019,
1825942fd1ebSWalter Sheets .subdevice = 0x1841,
1826942fd1ebSWalter Sheets .name = "ECS K7VTA3",
1827942fd1ebSWalter Sheets .type = AC97_TUNE_HP_ONLY
1828942fd1ebSWalter Sheets },
1829942fd1ebSWalter Sheets {
183069ad07cfSJaroslav Kysela .subvendor = 0x1849,
183169ad07cfSJaroslav Kysela .subdevice = 0x3059,
18321da177e4SLinus Torvalds .name = "ASRock K7VM2",
18331da177e4SLinus Torvalds .type = AC97_TUNE_HP_ONLY /* VT1616 */
18341da177e4SLinus Torvalds },
18351da177e4SLinus Torvalds {
183669ad07cfSJaroslav Kysela .subvendor = 0x14cd,
183769ad07cfSJaroslav Kysela .subdevice = 0x7002,
18381da177e4SLinus Torvalds .name = "Unknown",
18391da177e4SLinus Torvalds .type = AC97_TUNE_ALC_JACK
18401da177e4SLinus Torvalds },
18411da177e4SLinus Torvalds {
184269ad07cfSJaroslav Kysela .subvendor = 0x1071,
184369ad07cfSJaroslav Kysela .subdevice = 0x8590,
18441da177e4SLinus Torvalds .name = "Mitac Mobo",
18451da177e4SLinus Torvalds .type = AC97_TUNE_ALC_JACK
18461da177e4SLinus Torvalds },
18471da177e4SLinus Torvalds {
184869ad07cfSJaroslav Kysela .subvendor = 0x161f,
184969ad07cfSJaroslav Kysela .subdevice = 0x202b,
18501da177e4SLinus Torvalds .name = "Arima Notebook",
18511da177e4SLinus Torvalds .type = AC97_TUNE_HP_ONLY,
18521da177e4SLinus Torvalds },
1853dac8ddddSTakashi Iwai {
1854dac8ddddSTakashi Iwai .subvendor = 0x161f,
1855dac8ddddSTakashi Iwai .subdevice = 0x2032,
1856dac8ddddSTakashi Iwai .name = "Targa Traveller 811",
1857dac8ddddSTakashi Iwai .type = AC97_TUNE_HP_ONLY,
1858dac8ddddSTakashi Iwai },
1859d4199f01SDaniel T Chen {
1860d4199f01SDaniel T Chen .subvendor = 0x161f,
1861d4199f01SDaniel T Chen .subdevice = 0x2032,
1862d4199f01SDaniel T Chen .name = "m680x",
1863d4199f01SDaniel T Chen .type = AC97_TUNE_HP_ONLY, /* http://launchpad.net/bugs/38546 */
1864d4199f01SDaniel T Chen },
18659674513dSTakashi Iwai {
18669674513dSTakashi Iwai .subvendor = 0x1297,
18679674513dSTakashi Iwai .subdevice = 0xa232,
18689674513dSTakashi Iwai .name = "Shuttle AK32VN",
18699674513dSTakashi Iwai .type = AC97_TUNE_HP_ONLY
18709674513dSTakashi Iwai },
18711da177e4SLinus Torvalds { } /* terminator */
18721da177e4SLinus Torvalds };
18731da177e4SLinus Torvalds
snd_via82xx_mixer_new(struct via82xx * chip,const char * quirk_override)1874e23e7a14SBill Pemberton static int snd_via82xx_mixer_new(struct via82xx *chip, const char *quirk_override)
18751da177e4SLinus Torvalds {
1876e437e3d7STakashi Iwai struct snd_ac97_template ac97;
18771da177e4SLinus Torvalds int err;
187851055da5STakashi Iwai static const struct snd_ac97_bus_ops ops = {
18791da177e4SLinus Torvalds .write = snd_via82xx_codec_write,
18801da177e4SLinus Torvalds .read = snd_via82xx_codec_read,
18811da177e4SLinus Torvalds .wait = snd_via82xx_codec_wait,
18821da177e4SLinus Torvalds };
18831da177e4SLinus Torvalds
1884afb342f0STakashi Iwai err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus);
1885afb342f0STakashi Iwai if (err < 0)
18861da177e4SLinus Torvalds return err;
18871da177e4SLinus Torvalds chip->ac97_bus->private_free = snd_via82xx_mixer_free_ac97_bus;
18881da177e4SLinus Torvalds chip->ac97_bus->clock = chip->ac97_clock;
18891da177e4SLinus Torvalds
18901da177e4SLinus Torvalds memset(&ac97, 0, sizeof(ac97));
18911da177e4SLinus Torvalds ac97.private_data = chip;
18921da177e4SLinus Torvalds ac97.private_free = snd_via82xx_mixer_free_ac97;
18931da177e4SLinus Torvalds ac97.pci = chip->pci;
1894f1a63a38STakashi Iwai ac97.scaps = AC97_SCAP_SKIP_MODEM | AC97_SCAP_POWER_SAVE;
1895afb342f0STakashi Iwai err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97);
1896afb342f0STakashi Iwai if (err < 0)
18971da177e4SLinus Torvalds return err;
18981da177e4SLinus Torvalds
18991da177e4SLinus Torvalds snd_ac97_tune_hardware(chip->ac97, ac97_quirks, quirk_override);
19001da177e4SLinus Torvalds
19011da177e4SLinus Torvalds if (chip->chip_type != TYPE_VIA686) {
19021da177e4SLinus Torvalds /* use slot 10/11 */
19031da177e4SLinus Torvalds snd_ac97_update_bits(chip->ac97, AC97_EXTENDED_STATUS, 0x03 << 4, 0x03 << 4);
19041da177e4SLinus Torvalds }
19051da177e4SLinus Torvalds
19061da177e4SLinus Torvalds return 0;
19071da177e4SLinus Torvalds }
19081da177e4SLinus Torvalds
19091da177e4SLinus Torvalds #ifdef SUPPORT_JOYSTICK
19101da177e4SLinus Torvalds #define JOYSTICK_ADDR 0x200
snd_via686_create_gameport(struct via82xx * chip,unsigned char * legacy)1911e23e7a14SBill Pemberton static int snd_via686_create_gameport(struct via82xx *chip, unsigned char *legacy)
19121da177e4SLinus Torvalds {
19131da177e4SLinus Torvalds struct gameport *gp;
19141da177e4SLinus Torvalds
1915b7fe4622SClemens Ladisch if (!joystick)
19161da177e4SLinus Torvalds return -ENODEV;
19171da177e4SLinus Torvalds
1918afaf9975STakashi Iwai if (!devm_request_region(chip->card->dev, JOYSTICK_ADDR, 8,
1919afaf9975STakashi Iwai "VIA686 gameport")) {
192059d3acfaSTakashi Iwai dev_warn(chip->card->dev, "cannot reserve joystick port %#x\n",
1921e437e3d7STakashi Iwai JOYSTICK_ADDR);
19221da177e4SLinus Torvalds return -EBUSY;
19231da177e4SLinus Torvalds }
19241da177e4SLinus Torvalds
19251da177e4SLinus Torvalds chip->gameport = gp = gameport_allocate_port();
19261da177e4SLinus Torvalds if (!gp) {
192759d3acfaSTakashi Iwai dev_err(chip->card->dev,
192859d3acfaSTakashi Iwai "cannot allocate memory for gameport\n");
19291da177e4SLinus Torvalds return -ENOMEM;
19301da177e4SLinus Torvalds }
19311da177e4SLinus Torvalds
19321da177e4SLinus Torvalds gameport_set_name(gp, "VIA686 Gameport");
19331da177e4SLinus Torvalds gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci));
19341da177e4SLinus Torvalds gameport_set_dev_parent(gp, &chip->pci->dev);
19351da177e4SLinus Torvalds gp->io = JOYSTICK_ADDR;
19361da177e4SLinus Torvalds
19371da177e4SLinus Torvalds /* Enable legacy joystick port */
19381da177e4SLinus Torvalds *legacy |= VIA_FUNC_ENABLE_GAME;
19391da177e4SLinus Torvalds pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, *legacy);
19401da177e4SLinus Torvalds
19411da177e4SLinus Torvalds gameport_register_port(chip->gameport);
19421da177e4SLinus Torvalds
19431da177e4SLinus Torvalds return 0;
19441da177e4SLinus Torvalds }
19451da177e4SLinus Torvalds
snd_via686_free_gameport(struct via82xx * chip)1946e437e3d7STakashi Iwai static void snd_via686_free_gameport(struct via82xx *chip)
19471da177e4SLinus Torvalds {
19481da177e4SLinus Torvalds if (chip->gameport) {
19491da177e4SLinus Torvalds gameport_unregister_port(chip->gameport);
19501da177e4SLinus Torvalds chip->gameport = NULL;
19511da177e4SLinus Torvalds }
19521da177e4SLinus Torvalds }
19531da177e4SLinus Torvalds #else
snd_via686_create_gameport(struct via82xx * chip,unsigned char * legacy)1954e437e3d7STakashi Iwai static inline int snd_via686_create_gameport(struct via82xx *chip, unsigned char *legacy)
19551da177e4SLinus Torvalds {
19561da177e4SLinus Torvalds return -ENOSYS;
19571da177e4SLinus Torvalds }
snd_via686_free_gameport(struct via82xx * chip)1958e437e3d7STakashi Iwai static inline void snd_via686_free_gameport(struct via82xx *chip) { }
19591da177e4SLinus Torvalds #endif
19601da177e4SLinus Torvalds
19611da177e4SLinus Torvalds
19621da177e4SLinus Torvalds /*
19631da177e4SLinus Torvalds *
19641da177e4SLinus Torvalds */
19651da177e4SLinus Torvalds
snd_via8233_init_misc(struct via82xx * chip)1966e23e7a14SBill Pemberton static int snd_via8233_init_misc(struct via82xx *chip)
19671da177e4SLinus Torvalds {
19681da177e4SLinus Torvalds int i, err, caps;
19691da177e4SLinus Torvalds unsigned char val;
19701da177e4SLinus Torvalds
19711da177e4SLinus Torvalds caps = chip->chip_type == TYPE_VIA8233A ? 1 : 2;
19721da177e4SLinus Torvalds for (i = 0; i < caps; i++) {
19731da177e4SLinus Torvalds snd_via8233_capture_source.index = i;
19741da177e4SLinus Torvalds err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_capture_source, chip));
19751da177e4SLinus Torvalds if (err < 0)
19761da177e4SLinus Torvalds return err;
19771da177e4SLinus Torvalds }
19781da177e4SLinus Torvalds if (ac97_can_spdif(chip->ac97)) {
19791da177e4SLinus Torvalds err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_dxs3_spdif_control, chip));
19801da177e4SLinus Torvalds if (err < 0)
19811da177e4SLinus Torvalds return err;
19821da177e4SLinus Torvalds }
19831da177e4SLinus Torvalds if (chip->chip_type != TYPE_VIA8233A) {
19841da177e4SLinus Torvalds /* when no h/w PCM volume control is found, use DXS volume control
19851da177e4SLinus Torvalds * as the PCM vol control
19861da177e4SLinus Torvalds */
1987*a16ea09dSTakashi Iwai if (!snd_ctl_find_id_mixer(chip->card, "PCM Playback Volume")) {
198859d3acfaSTakashi Iwai dev_info(chip->card->dev,
198959d3acfaSTakashi Iwai "Using DXS as PCM Playback\n");
199000f226d4SHonza Maly err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_pcmdxs_volume_control, chip));
199100f226d4SHonza Maly if (err < 0)
199200f226d4SHonza Maly return err;
199300f226d4SHonza Maly }
199400f226d4SHonza Maly else /* Using DXS when PCM emulation is enabled is really weird */
199500f226d4SHonza Maly {
19962fb930b5SClemens Ladisch for (i = 0; i < 4; ++i) {
19972fb930b5SClemens Ladisch struct snd_kcontrol *kctl;
19982fb930b5SClemens Ladisch
19992fb930b5SClemens Ladisch kctl = snd_ctl_new1(
20002fb930b5SClemens Ladisch &snd_via8233_dxs_volume_control, chip);
20012fb930b5SClemens Ladisch if (!kctl)
20022fb930b5SClemens Ladisch return -ENOMEM;
20032fb930b5SClemens Ladisch kctl->id.subdevice = i;
20042fb930b5SClemens Ladisch err = snd_ctl_add(chip->card, kctl);
20051da177e4SLinus Torvalds if (err < 0)
20061da177e4SLinus Torvalds return err;
20073d009413SClemens Ladisch chip->dxs_controls[i] = kctl;
20081da177e4SLinus Torvalds }
20091da177e4SLinus Torvalds }
20102fb930b5SClemens Ladisch }
20111da177e4SLinus Torvalds /* select spdif data slot 10/11 */
20121da177e4SLinus Torvalds pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &val);
20131da177e4SLinus Torvalds val = (val & ~VIA8233_SPDIF_SLOT_MASK) | VIA8233_SPDIF_SLOT_1011;
20141da177e4SLinus Torvalds val &= ~VIA8233_SPDIF_DX3; /* SPDIF off as default */
20151da177e4SLinus Torvalds pci_write_config_byte(chip->pci, VIA8233_SPDIF_CTRL, val);
20161da177e4SLinus Torvalds
20171da177e4SLinus Torvalds return 0;
20181da177e4SLinus Torvalds }
20191da177e4SLinus Torvalds
snd_via686_init_misc(struct via82xx * chip)2020e23e7a14SBill Pemberton static int snd_via686_init_misc(struct via82xx *chip)
20211da177e4SLinus Torvalds {
20221da177e4SLinus Torvalds unsigned char legacy, legacy_cfg;
20231da177e4SLinus Torvalds int rev_h = 0;
20241da177e4SLinus Torvalds
20251da177e4SLinus Torvalds legacy = chip->old_legacy;
20261da177e4SLinus Torvalds legacy_cfg = chip->old_legacy_cfg;
20271da177e4SLinus Torvalds legacy |= VIA_FUNC_MIDI_IRQMASK; /* FIXME: correct? (disable MIDI) */
20281da177e4SLinus Torvalds legacy &= ~VIA_FUNC_ENABLE_GAME; /* disable joystick */
20291da177e4SLinus Torvalds if (chip->revision >= VIA_REV_686_H) {
20301da177e4SLinus Torvalds rev_h = 1;
2031b7fe4622SClemens Ladisch if (mpu_port >= 0x200) { /* force MIDI */
2032b7fe4622SClemens Ladisch mpu_port &= 0xfffc;
2033b7fe4622SClemens Ladisch pci_write_config_dword(chip->pci, 0x18, mpu_port | 0x01);
2034c7561cd8STakashi Iwai #ifdef CONFIG_PM_SLEEP
2035b7fe4622SClemens Ladisch chip->mpu_port_saved = mpu_port;
20361da177e4SLinus Torvalds #endif
20371da177e4SLinus Torvalds } else {
2038b7fe4622SClemens Ladisch mpu_port = pci_resource_start(chip->pci, 2);
20391da177e4SLinus Torvalds }
20401da177e4SLinus Torvalds } else {
2041b7fe4622SClemens Ladisch switch (mpu_port) { /* force MIDI */
20421da177e4SLinus Torvalds case 0x300:
20431da177e4SLinus Torvalds case 0x310:
20441da177e4SLinus Torvalds case 0x320:
20451da177e4SLinus Torvalds case 0x330:
20461da177e4SLinus Torvalds legacy_cfg &= ~(3 << 2);
2047b7fe4622SClemens Ladisch legacy_cfg |= (mpu_port & 0x0030) >> 2;
20481da177e4SLinus Torvalds break;
20491da177e4SLinus Torvalds default: /* no, use BIOS settings */
20501da177e4SLinus Torvalds if (legacy & VIA_FUNC_ENABLE_MIDI)
2051b7fe4622SClemens Ladisch mpu_port = 0x300 + ((legacy_cfg & 0x000c) << 2);
20521da177e4SLinus Torvalds break;
20531da177e4SLinus Torvalds }
20541da177e4SLinus Torvalds }
2055afb342f0STakashi Iwai if (mpu_port >= 0x200)
2056afaf9975STakashi Iwai chip->mpu_res = devm_request_region(&chip->pci->dev, mpu_port,
2057afaf9975STakashi Iwai 2, "VIA82xx MPU401");
2058afb342f0STakashi Iwai if (chip->mpu_res) {
20591da177e4SLinus Torvalds if (rev_h)
20601da177e4SLinus Torvalds legacy |= VIA_FUNC_MIDI_PNP; /* enable PCI I/O 2 */
20611da177e4SLinus Torvalds legacy |= VIA_FUNC_ENABLE_MIDI;
20621da177e4SLinus Torvalds } else {
20631da177e4SLinus Torvalds if (rev_h)
20641da177e4SLinus Torvalds legacy &= ~VIA_FUNC_MIDI_PNP; /* disable PCI I/O 2 */
20651da177e4SLinus Torvalds legacy &= ~VIA_FUNC_ENABLE_MIDI;
2066b7fe4622SClemens Ladisch mpu_port = 0;
20671da177e4SLinus Torvalds }
20681da177e4SLinus Torvalds
20691da177e4SLinus Torvalds pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy);
20701da177e4SLinus Torvalds pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, legacy_cfg);
20711da177e4SLinus Torvalds if (chip->mpu_res) {
20721da177e4SLinus Torvalds if (snd_mpu401_uart_new(chip->card, 0, MPU401_HW_VIA686A,
2073dba8b469SClemens Ladisch mpu_port, MPU401_INFO_INTEGRATED |
2074dba8b469SClemens Ladisch MPU401_INFO_IRQ_HOOK, -1,
2075dba8b469SClemens Ladisch &chip->rmidi) < 0) {
207659d3acfaSTakashi Iwai dev_warn(chip->card->dev,
207759d3acfaSTakashi Iwai "unable to initialize MPU-401 at 0x%lx, skipping\n",
207859d3acfaSTakashi Iwai mpu_port);
20791da177e4SLinus Torvalds legacy &= ~VIA_FUNC_ENABLE_MIDI;
20801da177e4SLinus Torvalds } else {
20811da177e4SLinus Torvalds legacy &= ~VIA_FUNC_MIDI_IRQMASK; /* enable MIDI interrupt */
20821da177e4SLinus Torvalds }
20831da177e4SLinus Torvalds pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy);
20841da177e4SLinus Torvalds }
20851da177e4SLinus Torvalds
2086b7fe4622SClemens Ladisch snd_via686_create_gameport(chip, &legacy);
20871da177e4SLinus Torvalds
2088c7561cd8STakashi Iwai #ifdef CONFIG_PM_SLEEP
20891da177e4SLinus Torvalds chip->legacy_saved = legacy;
20901da177e4SLinus Torvalds chip->legacy_cfg_saved = legacy_cfg;
20911da177e4SLinus Torvalds #endif
20921da177e4SLinus Torvalds
20931da177e4SLinus Torvalds return 0;
20941da177e4SLinus Torvalds }
20951da177e4SLinus Torvalds
20961da177e4SLinus Torvalds
20971da177e4SLinus Torvalds /*
20981da177e4SLinus Torvalds * proc interface
20991da177e4SLinus Torvalds */
snd_via82xx_proc_read(struct snd_info_entry * entry,struct snd_info_buffer * buffer)2100e437e3d7STakashi Iwai static void snd_via82xx_proc_read(struct snd_info_entry *entry,
2101e437e3d7STakashi Iwai struct snd_info_buffer *buffer)
21021da177e4SLinus Torvalds {
2103e437e3d7STakashi Iwai struct via82xx *chip = entry->private_data;
21041da177e4SLinus Torvalds int i;
21051da177e4SLinus Torvalds
21061da177e4SLinus Torvalds snd_iprintf(buffer, "%s\n\n", chip->card->longname);
21071da177e4SLinus Torvalds for (i = 0; i < 0xa0; i += 4) {
21081da177e4SLinus Torvalds snd_iprintf(buffer, "%02x: %08x\n", i, inl(chip->port + i));
21091da177e4SLinus Torvalds }
21101da177e4SLinus Torvalds }
21111da177e4SLinus Torvalds
snd_via82xx_proc_init(struct via82xx * chip)2112e23e7a14SBill Pemberton static void snd_via82xx_proc_init(struct via82xx *chip)
21131da177e4SLinus Torvalds {
211447f2769bSTakashi Iwai snd_card_ro_proc_new(chip->card, "via82xx", chip,
211547f2769bSTakashi Iwai snd_via82xx_proc_read);
21161da177e4SLinus Torvalds }
21171da177e4SLinus Torvalds
21181da177e4SLinus Torvalds /*
21191da177e4SLinus Torvalds *
21201da177e4SLinus Torvalds */
21211da177e4SLinus Torvalds
snd_via82xx_chip_init(struct via82xx * chip)2122e437e3d7STakashi Iwai static int snd_via82xx_chip_init(struct via82xx *chip)
21231da177e4SLinus Torvalds {
21241da177e4SLinus Torvalds unsigned int val;
2125ef21ca24SNishanth Aravamudan unsigned long end_time;
21261da177e4SLinus Torvalds unsigned char pval;
21271da177e4SLinus Torvalds
21281da177e4SLinus Torvalds #if 0 /* broken on K7M? */
21291da177e4SLinus Torvalds if (chip->chip_type == TYPE_VIA686)
21301da177e4SLinus Torvalds /* disable all legacy ports */
21311da177e4SLinus Torvalds pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, 0);
21321da177e4SLinus Torvalds #endif
21331da177e4SLinus Torvalds pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval);
21341da177e4SLinus Torvalds if (! (pval & VIA_ACLINK_C00_READY)) { /* codec not ready? */
21351da177e4SLinus Torvalds /* deassert ACLink reset, force SYNC */
21361da177e4SLinus Torvalds pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL,
21371da177e4SLinus Torvalds VIA_ACLINK_CTRL_ENABLE |
21381da177e4SLinus Torvalds VIA_ACLINK_CTRL_RESET |
21391da177e4SLinus Torvalds VIA_ACLINK_CTRL_SYNC);
21401da177e4SLinus Torvalds udelay(100);
21411da177e4SLinus Torvalds #if 1 /* FIXME: should we do full reset here for all chip models? */
21421da177e4SLinus Torvalds pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL, 0x00);
21431da177e4SLinus Torvalds udelay(100);
21441da177e4SLinus Torvalds #else
21451da177e4SLinus Torvalds /* deassert ACLink reset, force SYNC (warm AC'97 reset) */
21461da177e4SLinus Torvalds pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL,
21471da177e4SLinus Torvalds VIA_ACLINK_CTRL_RESET|VIA_ACLINK_CTRL_SYNC);
21481da177e4SLinus Torvalds udelay(2);
21491da177e4SLinus Torvalds #endif
21501da177e4SLinus Torvalds /* ACLink on, deassert ACLink reset, VSR, SGD data out */
21511da177e4SLinus Torvalds /* note - FM data out has trouble with non VRA codecs !! */
21521da177e4SLinus Torvalds pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL, VIA_ACLINK_CTRL_INIT);
21531da177e4SLinus Torvalds udelay(100);
21541da177e4SLinus Torvalds }
21551da177e4SLinus Torvalds
21561da177e4SLinus Torvalds /* Make sure VRA is enabled, in case we didn't do a
21571da177e4SLinus Torvalds * complete codec reset, above */
21581da177e4SLinus Torvalds pci_read_config_byte(chip->pci, VIA_ACLINK_CTRL, &pval);
21591da177e4SLinus Torvalds if ((pval & VIA_ACLINK_CTRL_INIT) != VIA_ACLINK_CTRL_INIT) {
21601da177e4SLinus Torvalds /* ACLink on, deassert ACLink reset, VSR, SGD data out */
21611da177e4SLinus Torvalds /* note - FM data out has trouble with non VRA codecs !! */
21621da177e4SLinus Torvalds pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL, VIA_ACLINK_CTRL_INIT);
21631da177e4SLinus Torvalds udelay(100);
21641da177e4SLinus Torvalds }
21651da177e4SLinus Torvalds
21661da177e4SLinus Torvalds /* wait until codec ready */
2167ef21ca24SNishanth Aravamudan end_time = jiffies + msecs_to_jiffies(750);
21681da177e4SLinus Torvalds do {
21691da177e4SLinus Torvalds pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval);
21701da177e4SLinus Torvalds if (pval & VIA_ACLINK_C00_READY) /* primary codec ready */
21711da177e4SLinus Torvalds break;
2172d86d0193SRene Herman schedule_timeout_uninterruptible(1);
2173ef21ca24SNishanth Aravamudan } while (time_before(jiffies, end_time));
21741da177e4SLinus Torvalds
2175afb342f0STakashi Iwai val = snd_via82xx_codec_xread(chip);
2176afb342f0STakashi Iwai if (val & VIA_REG_AC97_BUSY)
217759d3acfaSTakashi Iwai dev_err(chip->card->dev,
217859d3acfaSTakashi Iwai "AC'97 codec is not ready [0x%x]\n", val);
21791da177e4SLinus Torvalds
21801da177e4SLinus Torvalds #if 0 /* FIXME: we don't support the second codec yet so skip the detection now.. */
21811da177e4SLinus Torvalds snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ |
21821da177e4SLinus Torvalds VIA_REG_AC97_SECONDARY_VALID |
21831da177e4SLinus Torvalds (VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT));
2184ef21ca24SNishanth Aravamudan end_time = jiffies + msecs_to_jiffies(750);
21851da177e4SLinus Torvalds snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ |
21861da177e4SLinus Torvalds VIA_REG_AC97_SECONDARY_VALID |
21871da177e4SLinus Torvalds (VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT));
21881da177e4SLinus Torvalds do {
2189afb342f0STakashi Iwai val = snd_via82xx_codec_xread(chip);
2190afb342f0STakashi Iwai if (val & VIA_REG_AC97_SECONDARY_VALID) {
21911da177e4SLinus Torvalds chip->ac97_secondary = 1;
21921da177e4SLinus Torvalds goto __ac97_ok2;
21931da177e4SLinus Torvalds }
2194d86d0193SRene Herman schedule_timeout_uninterruptible(1);
2195ef21ca24SNishanth Aravamudan } while (time_before(jiffies, end_time));
21961da177e4SLinus Torvalds /* This is ok, the most of motherboards have only one codec */
21971da177e4SLinus Torvalds
21981da177e4SLinus Torvalds __ac97_ok2:
21991da177e4SLinus Torvalds #endif
22001da177e4SLinus Torvalds
22011da177e4SLinus Torvalds if (chip->chip_type == TYPE_VIA686) {
22021da177e4SLinus Torvalds /* route FM trap to IRQ, disable FM trap */
22031da177e4SLinus Torvalds pci_write_config_byte(chip->pci, VIA_FM_NMI_CTRL, 0);
22041da177e4SLinus Torvalds /* disable all GPI interrupts */
22051da177e4SLinus Torvalds outl(0, VIAREG(chip, GPI_INTR));
22061da177e4SLinus Torvalds }
22071da177e4SLinus Torvalds
22081da177e4SLinus Torvalds if (chip->chip_type != TYPE_VIA686) {
22091da177e4SLinus Torvalds /* Workaround for Award BIOS bug:
22101da177e4SLinus Torvalds * DXS channels don't work properly with VRA if MC97 is disabled.
22111da177e4SLinus Torvalds */
22121da177e4SLinus Torvalds struct pci_dev *pci;
22130dd119f7SJiri Slaby pci = pci_get_device(0x1106, 0x3068, NULL); /* MC97 */
22141da177e4SLinus Torvalds if (pci) {
22151da177e4SLinus Torvalds unsigned char data;
22161da177e4SLinus Torvalds pci_read_config_byte(pci, 0x44, &data);
22171da177e4SLinus Torvalds pci_write_config_byte(pci, 0x44, data | 0x40);
22180dd119f7SJiri Slaby pci_dev_put(pci);
22191da177e4SLinus Torvalds }
22201da177e4SLinus Torvalds }
22211da177e4SLinus Torvalds
22221da177e4SLinus Torvalds if (chip->chip_type != TYPE_VIA8233A) {
22231da177e4SLinus Torvalds int i, idx;
22241da177e4SLinus Torvalds for (idx = 0; idx < 4; idx++) {
22251da177e4SLinus Torvalds unsigned long port = chip->port + 0x10 * idx;
222600f226d4SHonza Maly for (i = 0; i < 2; i++) {
222700f226d4SHonza Maly chip->playback_volume[idx][i]=chip->playback_volume_c[i];
2228e437e3d7STakashi Iwai outb(chip->playback_volume_c[i],
2229e437e3d7STakashi Iwai port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i);
223000f226d4SHonza Maly }
22311da177e4SLinus Torvalds }
22321da177e4SLinus Torvalds }
22331da177e4SLinus Torvalds
22341da177e4SLinus Torvalds return 0;
22351da177e4SLinus Torvalds }
22361da177e4SLinus Torvalds
2237c7561cd8STakashi Iwai #ifdef CONFIG_PM_SLEEP
22381da177e4SLinus Torvalds /*
22391da177e4SLinus Torvalds * power management
22401da177e4SLinus Torvalds */
snd_via82xx_suspend(struct device * dev)224168cb2b55STakashi Iwai static int snd_via82xx_suspend(struct device *dev)
22421da177e4SLinus Torvalds {
224368cb2b55STakashi Iwai struct snd_card *card = dev_get_drvdata(dev);
224457feb835STakashi Iwai struct via82xx *chip = card->private_data;
22451da177e4SLinus Torvalds int i;
22461da177e4SLinus Torvalds
224757feb835STakashi Iwai snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
22481da177e4SLinus Torvalds for (i = 0; i < chip->num_devs; i++)
22491da177e4SLinus Torvalds snd_via82xx_channel_reset(chip, &chip->devs[i]);
22501da177e4SLinus Torvalds snd_ac97_suspend(chip->ac97);
22511da177e4SLinus Torvalds
22521da177e4SLinus Torvalds /* save misc values */
22531da177e4SLinus Torvalds if (chip->chip_type != TYPE_VIA686) {
22541da177e4SLinus Torvalds pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &chip->spdif_ctrl_saved);
22551da177e4SLinus Torvalds chip->capture_src_saved[0] = inb(chip->port + VIA_REG_CAPTURE_CHANNEL);
22561da177e4SLinus Torvalds chip->capture_src_saved[1] = inb(chip->port + VIA_REG_CAPTURE_CHANNEL + 0x10);
22571da177e4SLinus Torvalds }
22581da177e4SLinus Torvalds
22591da177e4SLinus Torvalds return 0;
22601da177e4SLinus Torvalds }
22611da177e4SLinus Torvalds
snd_via82xx_resume(struct device * dev)226268cb2b55STakashi Iwai static int snd_via82xx_resume(struct device *dev)
22631da177e4SLinus Torvalds {
226468cb2b55STakashi Iwai struct snd_card *card = dev_get_drvdata(dev);
226557feb835STakashi Iwai struct via82xx *chip = card->private_data;
22661da177e4SLinus Torvalds int i;
22671da177e4SLinus Torvalds
22681da177e4SLinus Torvalds snd_via82xx_chip_init(chip);
22691da177e4SLinus Torvalds
22701da177e4SLinus Torvalds if (chip->chip_type == TYPE_VIA686) {
22711da177e4SLinus Torvalds if (chip->mpu_port_saved)
22721da177e4SLinus Torvalds pci_write_config_dword(chip->pci, 0x18, chip->mpu_port_saved | 0x01);
22731da177e4SLinus Torvalds pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, chip->legacy_saved);
22741da177e4SLinus Torvalds pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, chip->legacy_cfg_saved);
22751da177e4SLinus Torvalds } else {
22761da177e4SLinus Torvalds pci_write_config_byte(chip->pci, VIA8233_SPDIF_CTRL, chip->spdif_ctrl_saved);
22771da177e4SLinus Torvalds outb(chip->capture_src_saved[0], chip->port + VIA_REG_CAPTURE_CHANNEL);
22781da177e4SLinus Torvalds outb(chip->capture_src_saved[1], chip->port + VIA_REG_CAPTURE_CHANNEL + 0x10);
22791da177e4SLinus Torvalds }
22801da177e4SLinus Torvalds
22811da177e4SLinus Torvalds snd_ac97_resume(chip->ac97);
22821da177e4SLinus Torvalds
22831da177e4SLinus Torvalds for (i = 0; i < chip->num_devs; i++)
22841da177e4SLinus Torvalds snd_via82xx_channel_reset(chip, &chip->devs[i]);
22851da177e4SLinus Torvalds
228657feb835STakashi Iwai snd_power_change_state(card, SNDRV_CTL_POWER_D0);
22871da177e4SLinus Torvalds return 0;
22881da177e4SLinus Torvalds }
228968cb2b55STakashi Iwai
229068cb2b55STakashi Iwai static SIMPLE_DEV_PM_OPS(snd_via82xx_pm, snd_via82xx_suspend, snd_via82xx_resume);
229168cb2b55STakashi Iwai #define SND_VIA82XX_PM_OPS &snd_via82xx_pm
229268cb2b55STakashi Iwai #else
229368cb2b55STakashi Iwai #define SND_VIA82XX_PM_OPS NULL
2294c7561cd8STakashi Iwai #endif /* CONFIG_PM_SLEEP */
22951da177e4SLinus Torvalds
snd_via82xx_free(struct snd_card * card)2296afaf9975STakashi Iwai static void snd_via82xx_free(struct snd_card *card)
22971da177e4SLinus Torvalds {
2298afaf9975STakashi Iwai struct via82xx *chip = card->private_data;
22991da177e4SLinus Torvalds unsigned int i;
23001da177e4SLinus Torvalds
23011da177e4SLinus Torvalds /* disable interrupts */
23021da177e4SLinus Torvalds for (i = 0; i < chip->num_devs; i++)
23031da177e4SLinus Torvalds snd_via82xx_channel_reset(chip, &chip->devs[i]);
2304f000fd80SJeff Garzik
23051da177e4SLinus Torvalds if (chip->chip_type == TYPE_VIA686) {
23061da177e4SLinus Torvalds snd_via686_free_gameport(chip);
23071da177e4SLinus Torvalds pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, chip->old_legacy);
23081da177e4SLinus Torvalds pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, chip->old_legacy_cfg);
23091da177e4SLinus Torvalds }
23101da177e4SLinus Torvalds }
23111da177e4SLinus Torvalds
snd_via82xx_create(struct snd_card * card,struct pci_dev * pci,int chip_type,int revision,unsigned int ac97_clock)2312e23e7a14SBill Pemberton static int snd_via82xx_create(struct snd_card *card,
23131da177e4SLinus Torvalds struct pci_dev *pci,
23141da177e4SLinus Torvalds int chip_type,
23151da177e4SLinus Torvalds int revision,
2316afaf9975STakashi Iwai unsigned int ac97_clock)
23171da177e4SLinus Torvalds {
2318afaf9975STakashi Iwai struct via82xx *chip = card->private_data;
23191da177e4SLinus Torvalds int err;
23201da177e4SLinus Torvalds
2321afaf9975STakashi Iwai err = pcim_enable_device(pci);
2322afb342f0STakashi Iwai if (err < 0)
23231da177e4SLinus Torvalds return err;
23241da177e4SLinus Torvalds
23251da177e4SLinus Torvalds chip->chip_type = chip_type;
23261da177e4SLinus Torvalds chip->revision = revision;
23271da177e4SLinus Torvalds
23281da177e4SLinus Torvalds spin_lock_init(&chip->reg_lock);
23291da177e4SLinus Torvalds spin_lock_init(&chip->rates[0].lock);
23301da177e4SLinus Torvalds spin_lock_init(&chip->rates[1].lock);
23311da177e4SLinus Torvalds chip->card = card;
23321da177e4SLinus Torvalds chip->pci = pci;
23331da177e4SLinus Torvalds chip->irq = -1;
23341da177e4SLinus Torvalds
23351da177e4SLinus Torvalds pci_read_config_byte(pci, VIA_FUNC_ENABLE, &chip->old_legacy);
23361da177e4SLinus Torvalds pci_read_config_byte(pci, VIA_PNP_CONTROL, &chip->old_legacy_cfg);
23371da177e4SLinus Torvalds pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE,
23381da177e4SLinus Torvalds chip->old_legacy & ~(VIA_FUNC_ENABLE_SB|VIA_FUNC_ENABLE_FM));
23391da177e4SLinus Torvalds
2340afb342f0STakashi Iwai err = pci_request_regions(pci, card->driver);
2341afaf9975STakashi Iwai if (err < 0)
23421da177e4SLinus Torvalds return err;
23431da177e4SLinus Torvalds chip->port = pci_resource_start(pci, 0);
2344afaf9975STakashi Iwai if (devm_request_irq(&pci->dev, pci->irq,
23454f550df5SKarsten Wiese chip_type == TYPE_VIA8233 ?
23464f550df5SKarsten Wiese snd_via8233_interrupt : snd_via686_interrupt,
2347437a5a46STakashi Iwai IRQF_SHARED,
2348934c2b6dSTakashi Iwai KBUILD_MODNAME, chip)) {
234959d3acfaSTakashi Iwai dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
23501da177e4SLinus Torvalds return -EBUSY;
23511da177e4SLinus Torvalds }
23521da177e4SLinus Torvalds chip->irq = pci->irq;
2353c47583b0STakashi Iwai card->sync_irq = chip->irq;
2354afaf9975STakashi Iwai card->private_free = snd_via82xx_free;
23551da177e4SLinus Torvalds if (ac97_clock >= 8000 && ac97_clock <= 48000)
23561da177e4SLinus Torvalds chip->ac97_clock = ac97_clock;
23571da177e4SLinus Torvalds
2358afb342f0STakashi Iwai err = snd_via82xx_chip_init(chip);
2359afaf9975STakashi Iwai if (err < 0)
23601da177e4SLinus Torvalds return err;
23611da177e4SLinus Torvalds
23621da177e4SLinus Torvalds /* The 8233 ac97 controller does not implement the master bit
23631da177e4SLinus Torvalds * in the pci command register. IMHO this is a violation of the PCI spec.
23641da177e4SLinus Torvalds * We call pci_set_master here because it does not hurt. */
23651da177e4SLinus Torvalds pci_set_master(pci);
23661da177e4SLinus Torvalds return 0;
23671da177e4SLinus Torvalds }
23681da177e4SLinus Torvalds
23691da177e4SLinus Torvalds struct via823x_info {
23701da177e4SLinus Torvalds int revision;
23711da177e4SLinus Torvalds char *name;
23721da177e4SLinus Torvalds int type;
23731da177e4SLinus Torvalds };
2374a05c0737STakashi Iwai static const struct via823x_info via823x_cards[] = {
23751da177e4SLinus Torvalds { VIA_REV_PRE_8233, "VIA 8233-Pre", TYPE_VIA8233 },
23761da177e4SLinus Torvalds { VIA_REV_8233C, "VIA 8233C", TYPE_VIA8233 },
23771da177e4SLinus Torvalds { VIA_REV_8233, "VIA 8233", TYPE_VIA8233 },
23781da177e4SLinus Torvalds { VIA_REV_8233A, "VIA 8233A", TYPE_VIA8233A },
23791da177e4SLinus Torvalds { VIA_REV_8235, "VIA 8235", TYPE_VIA8233 },
23801da177e4SLinus Torvalds { VIA_REV_8237, "VIA 8237", TYPE_VIA8233 },
23818263c65fSBastiaan Jacques { VIA_REV_8251, "VIA 8251", TYPE_VIA8233 },
23821da177e4SLinus Torvalds };
23831da177e4SLinus Torvalds
23841da177e4SLinus Torvalds /*
23851da177e4SLinus Torvalds * auto detection of DXS channel supports.
23861da177e4SLinus Torvalds */
23879d74958aSTakashi Iwai
238821641672STakashi Iwai static const struct snd_pci_quirk dxs_allowlist[] = {
23899d74958aSTakashi Iwai SND_PCI_QUIRK(0x1005, 0x4710, "Avance Logic Mobo", VIA_DXS_ENABLE),
23909d74958aSTakashi Iwai SND_PCI_QUIRK(0x1019, 0x0996, "ESC Mobo", VIA_DXS_48K),
23919d74958aSTakashi Iwai SND_PCI_QUIRK(0x1019, 0x0a81, "ECS K7VTA3 v8.0", VIA_DXS_NO_VRA),
23929d74958aSTakashi Iwai SND_PCI_QUIRK(0x1019, 0x0a85, "ECS L7VMM2", VIA_DXS_NO_VRA),
2393a85165c6STakashi Iwai SND_PCI_QUIRK_VENDOR(0x1019, "ESC K8", VIA_DXS_SRC),
23949d74958aSTakashi Iwai SND_PCI_QUIRK(0x1019, 0xaa01, "ESC K8T890-A", VIA_DXS_SRC),
23959d74958aSTakashi Iwai SND_PCI_QUIRK(0x1025, 0x0033, "Acer Inspire 1353LM", VIA_DXS_NO_VRA),
23969d74958aSTakashi Iwai SND_PCI_QUIRK(0x1025, 0x0046, "Acer Aspire 1524 WLMi", VIA_DXS_SRC),
2397a85165c6STakashi Iwai SND_PCI_QUIRK_VENDOR(0x1043, "ASUS A7/A8", VIA_DXS_NO_VRA),
2398a85165c6STakashi Iwai SND_PCI_QUIRK_VENDOR(0x1071, "Diverse Notebook", VIA_DXS_NO_VRA),
23999d74958aSTakashi Iwai SND_PCI_QUIRK(0x10cf, 0x118e, "FSC Laptop", VIA_DXS_ENABLE),
2400a85165c6STakashi Iwai SND_PCI_QUIRK_VENDOR(0x1106, "ASRock", VIA_DXS_SRC),
240111be265fSTakashi Iwai SND_PCI_QUIRK(0x1297, 0xa231, "Shuttle AK31v2", VIA_DXS_SRC),
24029674513dSTakashi Iwai SND_PCI_QUIRK(0x1297, 0xa232, "Shuttle", VIA_DXS_SRC),
24039674513dSTakashi Iwai SND_PCI_QUIRK(0x1297, 0xc160, "Shuttle Sk41G", VIA_DXS_SRC),
24049d74958aSTakashi Iwai SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte GA-7VAXP", VIA_DXS_ENABLE),
24059d74958aSTakashi Iwai SND_PCI_QUIRK(0x1462, 0x3800, "MSI KT266", VIA_DXS_ENABLE),
24069d74958aSTakashi Iwai SND_PCI_QUIRK(0x1462, 0x7120, "MSI KT4V", VIA_DXS_ENABLE),
24079d74958aSTakashi Iwai SND_PCI_QUIRK(0x1462, 0x7142, "MSI K8MM-V", VIA_DXS_ENABLE),
2408a85165c6STakashi Iwai SND_PCI_QUIRK_VENDOR(0x1462, "MSI Mobo", VIA_DXS_SRC),
24099d74958aSTakashi Iwai SND_PCI_QUIRK(0x147b, 0x1401, "ABIT KD7(-RAID)", VIA_DXS_ENABLE),
24109d74958aSTakashi Iwai SND_PCI_QUIRK(0x147b, 0x1411, "ABIT VA-20", VIA_DXS_ENABLE),
24119d74958aSTakashi Iwai SND_PCI_QUIRK(0x147b, 0x1413, "ABIT KV8 Pro", VIA_DXS_ENABLE),
24129d74958aSTakashi Iwai SND_PCI_QUIRK(0x147b, 0x1415, "ABIT AV8", VIA_DXS_NO_VRA),
24139d74958aSTakashi Iwai SND_PCI_QUIRK(0x14ff, 0x0403, "Twinhead mobo", VIA_DXS_ENABLE),
24149d74958aSTakashi Iwai SND_PCI_QUIRK(0x14ff, 0x0408, "Twinhead laptop", VIA_DXS_SRC),
24159d74958aSTakashi Iwai SND_PCI_QUIRK(0x1558, 0x4701, "Clevo D470", VIA_DXS_SRC),
24169d74958aSTakashi Iwai SND_PCI_QUIRK(0x1584, 0x8120, "Diverse Laptop", VIA_DXS_ENABLE),
24179d74958aSTakashi Iwai SND_PCI_QUIRK(0x1584, 0x8123, "Targa/Uniwill", VIA_DXS_NO_VRA),
24189d74958aSTakashi Iwai SND_PCI_QUIRK(0x161f, 0x202b, "Amira Notebook", VIA_DXS_NO_VRA),
24199d74958aSTakashi Iwai SND_PCI_QUIRK(0x161f, 0x2032, "m680x machines", VIA_DXS_48K),
24209d74958aSTakashi Iwai SND_PCI_QUIRK(0x1631, 0xe004, "PB EasyNote 3174", VIA_DXS_ENABLE),
24219d74958aSTakashi Iwai SND_PCI_QUIRK(0x1695, 0x3005, "EPoX EP-8K9A", VIA_DXS_ENABLE),
2422a85165c6STakashi Iwai SND_PCI_QUIRK_VENDOR(0x1695, "EPoX mobo", VIA_DXS_SRC),
2423a85165c6STakashi Iwai SND_PCI_QUIRK_VENDOR(0x16f3, "Jetway K8", VIA_DXS_SRC),
2424a85165c6STakashi Iwai SND_PCI_QUIRK_VENDOR(0x1734, "FSC Laptop", VIA_DXS_SRC),
24259d74958aSTakashi Iwai SND_PCI_QUIRK(0x1849, 0x3059, "ASRock K7VM2", VIA_DXS_NO_VRA),
2426a85165c6STakashi Iwai SND_PCI_QUIRK_VENDOR(0x1849, "ASRock mobo", VIA_DXS_SRC),
24279d74958aSTakashi Iwai SND_PCI_QUIRK(0x1919, 0x200a, "Soltek SL-K8", VIA_DXS_NO_VRA),
24289d74958aSTakashi Iwai SND_PCI_QUIRK(0x4005, 0x4710, "MSI K7T266", VIA_DXS_SRC),
24299d74958aSTakashi Iwai { } /* terminator */
24301da177e4SLinus Torvalds };
24311da177e4SLinus Torvalds
check_dxs_list(struct pci_dev * pci,int revision)2432e23e7a14SBill Pemberton static int check_dxs_list(struct pci_dev *pci, int revision)
24331da177e4SLinus Torvalds {
24349d74958aSTakashi Iwai const struct snd_pci_quirk *w;
24351da177e4SLinus Torvalds
243621641672STakashi Iwai w = snd_pci_quirk_lookup(pci, dxs_allowlist);
24379d74958aSTakashi Iwai if (w) {
243821641672STakashi Iwai dev_dbg(&pci->dev, "DXS allow list for %s found\n",
243986b27237STakashi Iwai snd_pci_quirk_name(w));
24409d74958aSTakashi Iwai return w->value;
24411da177e4SLinus Torvalds }
24421da177e4SLinus Torvalds
2443a769577bSTakashi Iwai /* for newer revision, default to DXS_SRC */
2444a769577bSTakashi Iwai if (revision >= VIA_REV_8235)
2445a769577bSTakashi Iwai return VIA_DXS_SRC;
2446a769577bSTakashi Iwai
24471da177e4SLinus Torvalds /*
24481da177e4SLinus Torvalds * not detected, try 48k rate only to be sure.
24491da177e4SLinus Torvalds */
245059d3acfaSTakashi Iwai dev_info(&pci->dev, "Assuming DXS channels with 48k fixed sample rate.\n");
245159d3acfaSTakashi Iwai dev_info(&pci->dev, " Please try dxs_support=5 option\n");
245259d3acfaSTakashi Iwai dev_info(&pci->dev, " and report if it works on your machine.\n");
245359d3acfaSTakashi Iwai dev_info(&pci->dev, " For more details, read ALSA-Configuration.txt.\n");
24541da177e4SLinus Torvalds return VIA_DXS_48K;
24551da177e4SLinus Torvalds };
24561da177e4SLinus Torvalds
__snd_via82xx_probe(struct pci_dev * pci,const struct pci_device_id * pci_id)245727a0963fSTakashi Iwai static int __snd_via82xx_probe(struct pci_dev *pci,
24581da177e4SLinus Torvalds const struct pci_device_id *pci_id)
24591da177e4SLinus Torvalds {
2460e437e3d7STakashi Iwai struct snd_card *card;
2461e437e3d7STakashi Iwai struct via82xx *chip;
24621da177e4SLinus Torvalds int chip_type = 0, card_type;
24631da177e4SLinus Torvalds unsigned int i;
24641da177e4SLinus Torvalds int err;
24651da177e4SLinus Torvalds
2466afaf9975STakashi Iwai err = snd_devm_card_new(&pci->dev, index, id, THIS_MODULE,
2467afaf9975STakashi Iwai sizeof(*chip), &card);
2468e58de7baSTakashi Iwai if (err < 0)
2469e58de7baSTakashi Iwai return err;
2470afaf9975STakashi Iwai chip = card->private_data;
24711da177e4SLinus Torvalds
24721da177e4SLinus Torvalds card_type = pci_id->driver_data;
24731da177e4SLinus Torvalds switch (card_type) {
24741da177e4SLinus Torvalds case TYPE_CARD_VIA686:
24751da177e4SLinus Torvalds strcpy(card->driver, "VIA686A");
247644c10138SAuke Kok sprintf(card->shortname, "VIA 82C686A/B rev%x", pci->revision);
24771da177e4SLinus Torvalds chip_type = TYPE_VIA686;
24781da177e4SLinus Torvalds break;
24791da177e4SLinus Torvalds case TYPE_CARD_VIA8233:
24801da177e4SLinus Torvalds chip_type = TYPE_VIA8233;
248144c10138SAuke Kok sprintf(card->shortname, "VIA 823x rev%x", pci->revision);
24821da177e4SLinus Torvalds for (i = 0; i < ARRAY_SIZE(via823x_cards); i++) {
248344c10138SAuke Kok if (pci->revision == via823x_cards[i].revision) {
24841da177e4SLinus Torvalds chip_type = via823x_cards[i].type;
24851da177e4SLinus Torvalds strcpy(card->shortname, via823x_cards[i].name);
24861da177e4SLinus Torvalds break;
24871da177e4SLinus Torvalds }
24881da177e4SLinus Torvalds }
24891da177e4SLinus Torvalds if (chip_type != TYPE_VIA8233A) {
2490b7fe4622SClemens Ladisch if (dxs_support == VIA_DXS_AUTO)
249144c10138SAuke Kok dxs_support = check_dxs_list(pci, pci->revision);
24921da177e4SLinus Torvalds /* force to use VIA8233 or 8233A model according to
24931da177e4SLinus Torvalds * dxs_support module option
24941da177e4SLinus Torvalds */
2495b7fe4622SClemens Ladisch if (dxs_support == VIA_DXS_DISABLE)
24961da177e4SLinus Torvalds chip_type = TYPE_VIA8233A;
24971da177e4SLinus Torvalds else
24981da177e4SLinus Torvalds chip_type = TYPE_VIA8233;
24991da177e4SLinus Torvalds }
25001da177e4SLinus Torvalds if (chip_type == TYPE_VIA8233A)
25011da177e4SLinus Torvalds strcpy(card->driver, "VIA8233A");
250244c10138SAuke Kok else if (pci->revision >= VIA_REV_8237)
25031da177e4SLinus Torvalds strcpy(card->driver, "VIA8237"); /* no slog assignment */
25041da177e4SLinus Torvalds else
25051da177e4SLinus Torvalds strcpy(card->driver, "VIA8233");
25061da177e4SLinus Torvalds break;
25071da177e4SLinus Torvalds default:
250859d3acfaSTakashi Iwai dev_err(card->dev, "invalid card type %d\n", card_type);
2509afaf9975STakashi Iwai return -EINVAL;
25101da177e4SLinus Torvalds }
25111da177e4SLinus Torvalds
2512afb342f0STakashi Iwai err = snd_via82xx_create(card, pci, chip_type, pci->revision,
2513afaf9975STakashi Iwai ac97_clock);
2514afb342f0STakashi Iwai if (err < 0)
2515afaf9975STakashi Iwai return err;
2516afb342f0STakashi Iwai err = snd_via82xx_mixer_new(chip, ac97_quirk);
2517afb342f0STakashi Iwai if (err < 0)
2518afaf9975STakashi Iwai return err;
25191da177e4SLinus Torvalds
25201da177e4SLinus Torvalds if (chip_type == TYPE_VIA686) {
2521afb342f0STakashi Iwai err = snd_via686_pcm_new(chip);
2522afb342f0STakashi Iwai if (err < 0)
2523afaf9975STakashi Iwai return err;
2524afb342f0STakashi Iwai err = snd_via686_init_misc(chip);
2525afb342f0STakashi Iwai if (err < 0)
2526afaf9975STakashi Iwai return err;
25271da177e4SLinus Torvalds } else {
25281da177e4SLinus Torvalds if (chip_type == TYPE_VIA8233A) {
2529afb342f0STakashi Iwai err = snd_via8233a_pcm_new(chip);
2530afb342f0STakashi Iwai if (err < 0)
2531afaf9975STakashi Iwai return err;
25321da177e4SLinus Torvalds // chip->dxs_fixed = 1; /* FIXME: use 48k for DXS #3? */
25331da177e4SLinus Torvalds } else {
2534afb342f0STakashi Iwai err = snd_via8233_pcm_new(chip);
2535afb342f0STakashi Iwai if (err < 0)
2536afaf9975STakashi Iwai return err;
2537b7fe4622SClemens Ladisch if (dxs_support == VIA_DXS_48K)
25381da177e4SLinus Torvalds chip->dxs_fixed = 1;
2539b7fe4622SClemens Ladisch else if (dxs_support == VIA_DXS_NO_VRA)
25401da177e4SLinus Torvalds chip->no_vra = 1;
2541b7fe4622SClemens Ladisch else if (dxs_support == VIA_DXS_SRC) {
25422d7eb7cbSSergey Vlasov chip->no_vra = 1;
25432d7eb7cbSSergey Vlasov chip->dxs_src = 1;
25442d7eb7cbSSergey Vlasov }
25451da177e4SLinus Torvalds }
2546afb342f0STakashi Iwai err = snd_via8233_init_misc(chip);
2547afb342f0STakashi Iwai if (err < 0)
2548afaf9975STakashi Iwai return err;
25491da177e4SLinus Torvalds }
25501da177e4SLinus Torvalds
25511da177e4SLinus Torvalds /* disable interrupts */
25521da177e4SLinus Torvalds for (i = 0; i < chip->num_devs; i++)
25531da177e4SLinus Torvalds snd_via82xx_channel_reset(chip, &chip->devs[i]);
25541da177e4SLinus Torvalds
25551da177e4SLinus Torvalds snprintf(card->longname, sizeof(card->longname),
25561da177e4SLinus Torvalds "%s with %s at %#lx, irq %d", card->shortname,
25571da177e4SLinus Torvalds snd_ac97_get_short_name(chip->ac97), chip->port, chip->irq);
25581da177e4SLinus Torvalds
25591da177e4SLinus Torvalds snd_via82xx_proc_init(chip);
25601da177e4SLinus Torvalds
2561afb342f0STakashi Iwai err = snd_card_register(card);
2562afaf9975STakashi Iwai if (err < 0)
25631da177e4SLinus Torvalds return err;
25641da177e4SLinus Torvalds pci_set_drvdata(pci, card);
25651da177e4SLinus Torvalds return 0;
25661da177e4SLinus Torvalds }
25671da177e4SLinus Torvalds
snd_via82xx_probe(struct pci_dev * pci,const struct pci_device_id * pci_id)256827a0963fSTakashi Iwai static int snd_via82xx_probe(struct pci_dev *pci,
256927a0963fSTakashi Iwai const struct pci_device_id *pci_id)
257027a0963fSTakashi Iwai {
257127a0963fSTakashi Iwai return snd_card_free_on_error(&pci->dev, __snd_via82xx_probe(pci, pci_id));
257227a0963fSTakashi Iwai }
257327a0963fSTakashi Iwai
2574e9f66d9bSTakashi Iwai static struct pci_driver via82xx_driver = {
25753733e424STakashi Iwai .name = KBUILD_MODNAME,
25761da177e4SLinus Torvalds .id_table = snd_via82xx_ids,
25771da177e4SLinus Torvalds .probe = snd_via82xx_probe,
257868cb2b55STakashi Iwai .driver = {
257968cb2b55STakashi Iwai .pm = SND_VIA82XX_PM_OPS,
258068cb2b55STakashi Iwai },
25811da177e4SLinus Torvalds };
25821da177e4SLinus Torvalds
2583e9f66d9bSTakashi Iwai module_pci_driver(via82xx_driver);
2584