Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * ALSA driver for VIA VT82xx (South Bridge) |
| 4 | * |
| 5 | * VT82C686A/B/C, VT8233A/C, VT8235 |
| 6 | * |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 7 | * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * Tjeerd.Mulder <Tjeerd.Mulder@fujitsu-siemens.com> |
| 9 | * 2002 Takashi Iwai <tiwai@suse.de> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | /* |
| 13 | * Changes: |
| 14 | * |
| 15 | * Dec. 19, 2002 Takashi Iwai <tiwai@suse.de> |
| 16 | * - use the DSX channels for the first pcm playback. |
| 17 | * (on VIA8233, 8233C and 8235 only) |
| 18 | * this will allow you play simultaneously up to 4 streams. |
| 19 | * multi-channel playback is assigned to the second device |
| 20 | * on these chips. |
| 21 | * - support the secondary capture (on VIA8233/C,8235) |
| 22 | * - SPDIF support |
| 23 | * the DSX3 channel can be used for SPDIF output. |
| 24 | * on VIA8233A, this channel is assigned to the second pcm |
| 25 | * playback. |
| 26 | * the card config of alsa-lib will assign the correct |
| 27 | * device for applications. |
| 28 | * - clean up the code, separate low-level initialization |
| 29 | * routines for each chipset. |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 30 | * |
| 31 | * Sep. 26, 2005 Karsten Wiese <annabellesgarden@yahoo.de> |
| 32 | * - Optimize position calculation for the 823x chips. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | */ |
| 34 | |
Takashi Iwai | 6cbbfe1 | 2015-01-28 16:49:33 +0100 | [diff] [blame] | 35 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/delay.h> |
| 37 | #include <linux/interrupt.h> |
| 38 | #include <linux/init.h> |
| 39 | #include <linux/pci.h> |
| 40 | #include <linux/slab.h> |
| 41 | #include <linux/gameport.h> |
Paul Gortmaker | 65a7721 | 2011-07-15 13:13:37 -0400 | [diff] [blame] | 42 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <sound/core.h> |
| 44 | #include <sound/pcm.h> |
| 45 | #include <sound/pcm_params.h> |
| 46 | #include <sound/info.h> |
Takashi Iwai | 7058c04 | 2006-08-21 18:44:54 +0200 | [diff] [blame] | 47 | #include <sound/tlv.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <sound/ac97_codec.h> |
| 49 | #include <sound/mpu401.h> |
| 50 | #include <sound/initval.h> |
| 51 | |
| 52 | #if 0 |
| 53 | #define POINTER_DEBUG |
| 54 | #endif |
| 55 | |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 56 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | MODULE_DESCRIPTION("VIA VT82xx audio"); |
| 58 | MODULE_LICENSE("GPL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Fabian Frederick | b2fac07 | 2016-11-12 23:26:41 +0100 | [diff] [blame] | 60 | #if IS_REACHABLE(CONFIG_GAMEPORT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #define SUPPORT_JOYSTICK 1 |
| 62 | #endif |
| 63 | |
Clemens Ladisch | b7fe462 | 2005-10-04 08:46:51 +0200 | [diff] [blame] | 64 | static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */ |
| 65 | static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */ |
| 66 | static long mpu_port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #ifdef SUPPORT_JOYSTICK |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 68 | static bool joystick; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | #endif |
Clemens Ladisch | b7fe462 | 2005-10-04 08:46:51 +0200 | [diff] [blame] | 70 | static int ac97_clock = 48000; |
| 71 | static char *ac97_quirk; |
| 72 | static int dxs_support; |
Clemens Ladisch | 395c61d | 2010-07-12 16:27:24 +0200 | [diff] [blame] | 73 | static int dxs_init_volume = 31; |
Simon Arlott | 115551d | 2009-06-21 19:50:48 +0100 | [diff] [blame] | 74 | static int nodelay; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Clemens Ladisch | b7fe462 | 2005-10-04 08:46:51 +0200 | [diff] [blame] | 76 | module_param(index, int, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | MODULE_PARM_DESC(index, "Index value for VIA 82xx bridge."); |
Clemens Ladisch | b7fe462 | 2005-10-04 08:46:51 +0200 | [diff] [blame] | 78 | module_param(id, charp, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | MODULE_PARM_DESC(id, "ID string for VIA 82xx bridge."); |
David Howells | 6192c41 | 2017-04-04 16:54:30 +0100 | [diff] [blame] | 80 | module_param_hw(mpu_port, long, ioport, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | MODULE_PARM_DESC(mpu_port, "MPU-401 port. (VT82C686x only)"); |
| 82 | #ifdef SUPPORT_JOYSTICK |
Clemens Ladisch | b7fe462 | 2005-10-04 08:46:51 +0200 | [diff] [blame] | 83 | module_param(joystick, bool, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | MODULE_PARM_DESC(joystick, "Enable joystick. (VT82C686x only)"); |
| 85 | #endif |
Clemens Ladisch | b7fe462 | 2005-10-04 08:46:51 +0200 | [diff] [blame] | 86 | module_param(ac97_clock, int, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz)."); |
Clemens Ladisch | b7fe462 | 2005-10-04 08:46:51 +0200 | [diff] [blame] | 88 | module_param(ac97_quirk, charp, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware."); |
Clemens Ladisch | b7fe462 | 2005-10-04 08:46:51 +0200 | [diff] [blame] | 90 | module_param(dxs_support, int, 0444); |
Sergey Vlasov | 2d7eb7c | 2005-04-11 15:04:33 +0200 | [diff] [blame] | 91 | 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)"); |
Clemens Ladisch | 395c61d | 2010-07-12 16:27:24 +0200 | [diff] [blame] | 92 | module_param(dxs_init_volume, int, 0644); |
| 93 | MODULE_PARM_DESC(dxs_init_volume, "initial DXS volume (0-31)"); |
Simon Arlott | 115551d | 2009-06-21 19:50:48 +0100 | [diff] [blame] | 94 | module_param(nodelay, int, 0444); |
| 95 | MODULE_PARM_DESC(nodelay, "Disable 500ms init delay"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Takashi Iwai | 2b3e584 | 2005-10-06 13:47:23 +0200 | [diff] [blame] | 97 | /* just for backward compatibility */ |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 98 | static bool enable; |
Takashi Iwai | 698444f | 2005-10-20 16:53:49 +0200 | [diff] [blame] | 99 | module_param(enable, bool, 0444); |
Takashi Iwai | 2b3e584 | 2005-10-06 13:47:23 +0200 | [diff] [blame] | 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | /* revision numbers for via686 */ |
| 103 | #define VIA_REV_686_A 0x10 |
| 104 | #define VIA_REV_686_B 0x11 |
| 105 | #define VIA_REV_686_C 0x12 |
| 106 | #define VIA_REV_686_D 0x13 |
| 107 | #define VIA_REV_686_E 0x14 |
| 108 | #define VIA_REV_686_H 0x20 |
| 109 | |
| 110 | /* revision numbers for via8233 */ |
| 111 | #define VIA_REV_PRE_8233 0x10 /* not in market */ |
| 112 | #define VIA_REV_8233C 0x20 /* 2 rec, 4 pb, 1 multi-pb */ |
| 113 | #define VIA_REV_8233 0x30 /* 2 rec, 4 pb, 1 multi-pb, spdif */ |
| 114 | #define VIA_REV_8233A 0x40 /* 1 rec, 1 multi-pb, spdf */ |
| 115 | #define VIA_REV_8235 0x50 /* 2 rec, 4 pb, 1 multi-pb, spdif */ |
| 116 | #define VIA_REV_8237 0x60 |
Bastiaan Jacques | 8263c65 | 2006-04-18 17:04:04 +0200 | [diff] [blame] | 117 | #define VIA_REV_8251 0x70 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
| 119 | /* |
| 120 | * Direct registers |
| 121 | */ |
| 122 | |
| 123 | #define VIAREG(via, x) ((via)->port + VIA_REG_##x) |
| 124 | #define VIADEV_REG(viadev, x) ((viadev)->port + VIA_REG_##x) |
| 125 | |
| 126 | /* common offsets */ |
| 127 | #define VIA_REG_OFFSET_STATUS 0x00 /* byte - channel status */ |
| 128 | #define VIA_REG_STAT_ACTIVE 0x80 /* RO */ |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 129 | #define VIA8233_SHADOW_STAT_ACTIVE 0x08 /* RO */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | #define VIA_REG_STAT_PAUSED 0x40 /* RO */ |
| 131 | #define VIA_REG_STAT_TRIGGER_QUEUED 0x08 /* RO */ |
| 132 | #define VIA_REG_STAT_STOPPED 0x04 /* RWC */ |
| 133 | #define VIA_REG_STAT_EOL 0x02 /* RWC */ |
| 134 | #define VIA_REG_STAT_FLAG 0x01 /* RWC */ |
| 135 | #define VIA_REG_OFFSET_CONTROL 0x01 /* byte - channel control */ |
| 136 | #define VIA_REG_CTRL_START 0x80 /* WO */ |
| 137 | #define VIA_REG_CTRL_TERMINATE 0x40 /* WO */ |
| 138 | #define VIA_REG_CTRL_AUTOSTART 0x20 |
| 139 | #define VIA_REG_CTRL_PAUSE 0x08 /* RW */ |
| 140 | #define VIA_REG_CTRL_INT_STOP 0x04 |
| 141 | #define VIA_REG_CTRL_INT_EOL 0x02 |
| 142 | #define VIA_REG_CTRL_INT_FLAG 0x01 |
| 143 | #define VIA_REG_CTRL_RESET 0x01 /* RW - probably reset? undocumented */ |
| 144 | #define VIA_REG_CTRL_INT (VIA_REG_CTRL_INT_FLAG | VIA_REG_CTRL_INT_EOL | VIA_REG_CTRL_AUTOSTART) |
| 145 | #define VIA_REG_OFFSET_TYPE 0x02 /* byte - channel type (686 only) */ |
| 146 | #define VIA_REG_TYPE_AUTOSTART 0x80 /* RW - autostart at EOL */ |
| 147 | #define VIA_REG_TYPE_16BIT 0x20 /* RW */ |
| 148 | #define VIA_REG_TYPE_STEREO 0x10 /* RW */ |
| 149 | #define VIA_REG_TYPE_INT_LLINE 0x00 |
| 150 | #define VIA_REG_TYPE_INT_LSAMPLE 0x04 |
| 151 | #define VIA_REG_TYPE_INT_LESSONE 0x08 |
| 152 | #define VIA_REG_TYPE_INT_MASK 0x0c |
| 153 | #define VIA_REG_TYPE_INT_EOL 0x02 |
| 154 | #define VIA_REG_TYPE_INT_FLAG 0x01 |
| 155 | #define VIA_REG_OFFSET_TABLE_PTR 0x04 /* dword - channel table pointer */ |
| 156 | #define VIA_REG_OFFSET_CURR_PTR 0x04 /* dword - channel current pointer */ |
| 157 | #define VIA_REG_OFFSET_STOP_IDX 0x08 /* dword - stop index, channel type, sample rate */ |
| 158 | #define VIA8233_REG_TYPE_16BIT 0x00200000 /* RW */ |
| 159 | #define VIA8233_REG_TYPE_STEREO 0x00100000 /* RW */ |
| 160 | #define VIA_REG_OFFSET_CURR_COUNT 0x0c /* dword - channel current count (24 bit) */ |
| 161 | #define VIA_REG_OFFSET_CURR_INDEX 0x0f /* byte - channel current index (for via8233 only) */ |
| 162 | |
| 163 | #define DEFINE_VIA_REGSET(name,val) \ |
| 164 | enum {\ |
| 165 | VIA_REG_##name##_STATUS = (val),\ |
| 166 | VIA_REG_##name##_CONTROL = (val) + 0x01,\ |
| 167 | VIA_REG_##name##_TYPE = (val) + 0x02,\ |
| 168 | VIA_REG_##name##_TABLE_PTR = (val) + 0x04,\ |
| 169 | VIA_REG_##name##_CURR_PTR = (val) + 0x04,\ |
| 170 | VIA_REG_##name##_STOP_IDX = (val) + 0x08,\ |
| 171 | VIA_REG_##name##_CURR_COUNT = (val) + 0x0c,\ |
| 172 | } |
| 173 | |
| 174 | /* playback block */ |
| 175 | DEFINE_VIA_REGSET(PLAYBACK, 0x00); |
| 176 | DEFINE_VIA_REGSET(CAPTURE, 0x10); |
| 177 | DEFINE_VIA_REGSET(FM, 0x20); |
| 178 | |
| 179 | /* AC'97 */ |
| 180 | #define VIA_REG_AC97 0x80 /* dword */ |
| 181 | #define VIA_REG_AC97_CODEC_ID_MASK (3<<30) |
| 182 | #define VIA_REG_AC97_CODEC_ID_SHIFT 30 |
| 183 | #define VIA_REG_AC97_CODEC_ID_PRIMARY 0x00 |
| 184 | #define VIA_REG_AC97_CODEC_ID_SECONDARY 0x01 |
| 185 | #define VIA_REG_AC97_SECONDARY_VALID (1<<27) |
| 186 | #define VIA_REG_AC97_PRIMARY_VALID (1<<25) |
| 187 | #define VIA_REG_AC97_BUSY (1<<24) |
| 188 | #define VIA_REG_AC97_READ (1<<23) |
| 189 | #define VIA_REG_AC97_CMD_SHIFT 16 |
| 190 | #define VIA_REG_AC97_CMD_MASK 0x7e |
| 191 | #define VIA_REG_AC97_DATA_SHIFT 0 |
| 192 | #define VIA_REG_AC97_DATA_MASK 0xffff |
| 193 | |
| 194 | #define VIA_REG_SGD_SHADOW 0x84 /* dword */ |
| 195 | /* via686 */ |
| 196 | #define VIA_REG_SGD_STAT_PB_FLAG (1<<0) |
| 197 | #define VIA_REG_SGD_STAT_CP_FLAG (1<<1) |
| 198 | #define VIA_REG_SGD_STAT_FM_FLAG (1<<2) |
| 199 | #define VIA_REG_SGD_STAT_PB_EOL (1<<4) |
| 200 | #define VIA_REG_SGD_STAT_CP_EOL (1<<5) |
| 201 | #define VIA_REG_SGD_STAT_FM_EOL (1<<6) |
| 202 | #define VIA_REG_SGD_STAT_PB_STOP (1<<8) |
| 203 | #define VIA_REG_SGD_STAT_CP_STOP (1<<9) |
| 204 | #define VIA_REG_SGD_STAT_FM_STOP (1<<10) |
| 205 | #define VIA_REG_SGD_STAT_PB_ACTIVE (1<<12) |
| 206 | #define VIA_REG_SGD_STAT_CP_ACTIVE (1<<13) |
| 207 | #define VIA_REG_SGD_STAT_FM_ACTIVE (1<<14) |
| 208 | /* via8233 */ |
| 209 | #define VIA8233_REG_SGD_STAT_FLAG (1<<0) |
| 210 | #define VIA8233_REG_SGD_STAT_EOL (1<<1) |
| 211 | #define VIA8233_REG_SGD_STAT_STOP (1<<2) |
| 212 | #define VIA8233_REG_SGD_STAT_ACTIVE (1<<3) |
| 213 | #define VIA8233_INTR_MASK(chan) ((VIA8233_REG_SGD_STAT_FLAG|VIA8233_REG_SGD_STAT_EOL) << ((chan) * 4)) |
| 214 | #define VIA8233_REG_SGD_CHAN_SDX 0 |
| 215 | #define VIA8233_REG_SGD_CHAN_MULTI 4 |
| 216 | #define VIA8233_REG_SGD_CHAN_REC 6 |
| 217 | #define VIA8233_REG_SGD_CHAN_REC1 7 |
| 218 | |
| 219 | #define VIA_REG_GPI_STATUS 0x88 |
| 220 | #define VIA_REG_GPI_INTR 0x8c |
| 221 | |
| 222 | /* multi-channel and capture registers for via8233 */ |
| 223 | DEFINE_VIA_REGSET(MULTPLAY, 0x40); |
| 224 | DEFINE_VIA_REGSET(CAPTURE_8233, 0x60); |
| 225 | |
| 226 | /* via8233-specific registers */ |
| 227 | #define VIA_REG_OFS_PLAYBACK_VOLUME_L 0x02 /* byte */ |
| 228 | #define VIA_REG_OFS_PLAYBACK_VOLUME_R 0x03 /* byte */ |
| 229 | #define VIA_REG_OFS_MULTPLAY_FORMAT 0x02 /* byte - format and channels */ |
| 230 | #define VIA_REG_MULTPLAY_FMT_8BIT 0x00 |
| 231 | #define VIA_REG_MULTPLAY_FMT_16BIT 0x80 |
| 232 | #define VIA_REG_MULTPLAY_FMT_CH_MASK 0x70 /* # channels << 4 (valid = 1,2,4,6) */ |
| 233 | #define VIA_REG_OFS_CAPTURE_FIFO 0x02 /* byte - bit 6 = fifo enable */ |
| 234 | #define VIA_REG_CAPTURE_FIFO_ENABLE 0x40 |
| 235 | |
| 236 | #define VIA_DXS_MAX_VOLUME 31 /* max. volume (attenuation) of reg 0x32/33 */ |
| 237 | |
| 238 | #define VIA_REG_CAPTURE_CHANNEL 0x63 /* byte - input select */ |
| 239 | #define VIA_REG_CAPTURE_CHANNEL_MIC 0x4 |
| 240 | #define VIA_REG_CAPTURE_CHANNEL_LINE 0 |
| 241 | #define VIA_REG_CAPTURE_SELECT_CODEC 0x03 /* recording source codec (0 = primary) */ |
| 242 | |
| 243 | #define VIA_TBL_BIT_FLAG 0x40000000 |
| 244 | #define VIA_TBL_BIT_EOL 0x80000000 |
| 245 | |
| 246 | /* pci space */ |
| 247 | #define VIA_ACLINK_STAT 0x40 |
| 248 | #define VIA_ACLINK_C11_READY 0x20 |
| 249 | #define VIA_ACLINK_C10_READY 0x10 |
| 250 | #define VIA_ACLINK_C01_READY 0x04 /* secondary codec ready */ |
| 251 | #define VIA_ACLINK_LOWPOWER 0x02 /* low-power state */ |
| 252 | #define VIA_ACLINK_C00_READY 0x01 /* primary codec ready */ |
| 253 | #define VIA_ACLINK_CTRL 0x41 |
| 254 | #define VIA_ACLINK_CTRL_ENABLE 0x80 /* 0: disable, 1: enable */ |
| 255 | #define VIA_ACLINK_CTRL_RESET 0x40 /* 0: assert, 1: de-assert */ |
| 256 | #define VIA_ACLINK_CTRL_SYNC 0x20 /* 0: release SYNC, 1: force SYNC hi */ |
| 257 | #define VIA_ACLINK_CTRL_SDO 0x10 /* 0: release SDO, 1: force SDO hi */ |
| 258 | #define VIA_ACLINK_CTRL_VRA 0x08 /* 0: disable VRA, 1: enable VRA */ |
| 259 | #define VIA_ACLINK_CTRL_PCM 0x04 /* 0: disable PCM, 1: enable PCM */ |
| 260 | #define VIA_ACLINK_CTRL_FM 0x02 /* via686 only */ |
| 261 | #define VIA_ACLINK_CTRL_SB 0x01 /* via686 only */ |
| 262 | #define VIA_ACLINK_CTRL_INIT (VIA_ACLINK_CTRL_ENABLE|\ |
| 263 | VIA_ACLINK_CTRL_RESET|\ |
| 264 | VIA_ACLINK_CTRL_PCM|\ |
| 265 | VIA_ACLINK_CTRL_VRA) |
| 266 | #define VIA_FUNC_ENABLE 0x42 |
| 267 | #define VIA_FUNC_MIDI_PNP 0x80 /* FIXME: it's 0x40 in the datasheet! */ |
| 268 | #define VIA_FUNC_MIDI_IRQMASK 0x40 /* FIXME: not documented! */ |
| 269 | #define VIA_FUNC_RX2C_WRITE 0x20 |
| 270 | #define VIA_FUNC_SB_FIFO_EMPTY 0x10 |
| 271 | #define VIA_FUNC_ENABLE_GAME 0x08 |
| 272 | #define VIA_FUNC_ENABLE_FM 0x04 |
| 273 | #define VIA_FUNC_ENABLE_MIDI 0x02 |
| 274 | #define VIA_FUNC_ENABLE_SB 0x01 |
| 275 | #define VIA_PNP_CONTROL 0x43 |
| 276 | #define VIA_FM_NMI_CTRL 0x48 |
| 277 | #define VIA8233_VOLCHG_CTRL 0x48 |
| 278 | #define VIA8233_SPDIF_CTRL 0x49 |
| 279 | #define VIA8233_SPDIF_DX3 0x08 |
| 280 | #define VIA8233_SPDIF_SLOT_MASK 0x03 |
| 281 | #define VIA8233_SPDIF_SLOT_1011 0x00 |
| 282 | #define VIA8233_SPDIF_SLOT_34 0x01 |
| 283 | #define VIA8233_SPDIF_SLOT_78 0x02 |
| 284 | #define VIA8233_SPDIF_SLOT_69 0x03 |
| 285 | |
| 286 | /* |
| 287 | */ |
| 288 | |
| 289 | #define VIA_DXS_AUTO 0 |
| 290 | #define VIA_DXS_ENABLE 1 |
| 291 | #define VIA_DXS_DISABLE 2 |
| 292 | #define VIA_DXS_48K 3 |
| 293 | #define VIA_DXS_NO_VRA 4 |
Sergey Vlasov | 2d7eb7c | 2005-04-11 15:04:33 +0200 | [diff] [blame] | 294 | #define VIA_DXS_SRC 5 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
| 296 | |
| 297 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | * pcm stream |
| 299 | */ |
| 300 | |
| 301 | struct snd_via_sg_table { |
| 302 | unsigned int offset; |
| 303 | unsigned int size; |
| 304 | } ; |
| 305 | |
| 306 | #define VIA_TABLE_SIZE 255 |
Takashi Iwai | 5503600 | 2008-07-30 15:23:06 +0200 | [diff] [blame] | 307 | #define VIA_MAX_BUFSIZE (1<<24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 309 | struct viadev { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | unsigned int reg_offset; |
| 311 | unsigned long port; |
| 312 | int direction; /* playback = 0, capture = 1 */ |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 313 | struct snd_pcm_substream *substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | int running; |
| 315 | unsigned int tbl_entries; /* # descriptors */ |
| 316 | struct snd_dma_buffer table; |
| 317 | struct snd_via_sg_table *idx_table; |
| 318 | /* for recovery from the unexpected pointer */ |
| 319 | unsigned int lastpos; |
| 320 | unsigned int fragsize; |
| 321 | unsigned int bufsize; |
| 322 | unsigned int bufsize2; |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 323 | int hwptr_done; /* processed frame position in the buffer */ |
| 324 | int in_interrupt; |
| 325 | int shadow_shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | }; |
| 327 | |
| 328 | |
| 329 | enum { TYPE_CARD_VIA686 = 1, TYPE_CARD_VIA8233 }; |
| 330 | enum { TYPE_VIA686, TYPE_VIA8233, TYPE_VIA8233A }; |
| 331 | |
| 332 | #define VIA_MAX_DEVS 7 /* 4 playback, 1 multi, 2 capture */ |
| 333 | |
| 334 | struct via_rate_lock { |
| 335 | spinlock_t lock; |
| 336 | int rate; |
| 337 | int used; |
| 338 | }; |
| 339 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 340 | struct via82xx { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | int irq; |
| 342 | |
| 343 | unsigned long port; |
| 344 | struct resource *mpu_res; |
| 345 | int chip_type; |
| 346 | unsigned char revision; |
| 347 | |
| 348 | unsigned char old_legacy; |
| 349 | unsigned char old_legacy_cfg; |
Takashi Iwai | c7561cd | 2012-08-14 18:12:04 +0200 | [diff] [blame] | 350 | #ifdef CONFIG_PM_SLEEP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | unsigned char legacy_saved; |
| 352 | unsigned char legacy_cfg_saved; |
| 353 | unsigned char spdif_ctrl_saved; |
| 354 | unsigned char capture_src_saved[2]; |
| 355 | unsigned int mpu_port_saved; |
| 356 | #endif |
| 357 | |
Honza Maly | 00f226d | 2005-10-14 18:18:01 +0200 | [diff] [blame] | 358 | unsigned char playback_volume[4][2]; /* for VIA8233/C/8235; default = 0 */ |
| 359 | unsigned char playback_volume_c[2]; /* for VIA8233/C/8235; default = 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
| 361 | unsigned int intr_mask; /* SGD_SHADOW mask to check interrupts */ |
| 362 | |
| 363 | struct pci_dev *pci; |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 364 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
| 366 | unsigned int num_devs; |
| 367 | unsigned int playback_devno, multi_devno, capture_devno; |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 368 | struct viadev devs[VIA_MAX_DEVS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | struct via_rate_lock rates[2]; /* playback and capture */ |
| 370 | unsigned int dxs_fixed: 1; /* DXS channel accepts only 48kHz */ |
| 371 | unsigned int no_vra: 1; /* no need to set VRA on DXS channels */ |
Sergey Vlasov | 2d7eb7c | 2005-04-11 15:04:33 +0200 | [diff] [blame] | 372 | unsigned int dxs_src: 1; /* use full SRC capabilities of DXS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | unsigned int spdif_on: 1; /* only spdif rates work to external DACs */ |
| 374 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 375 | struct snd_pcm *pcms[2]; |
| 376 | struct snd_rawmidi *rmidi; |
Clemens Ladisch | 3d00941 | 2009-10-22 09:04:09 +0200 | [diff] [blame] | 377 | struct snd_kcontrol *dxs_controls[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 379 | struct snd_ac97_bus *ac97_bus; |
| 380 | struct snd_ac97 *ac97; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | unsigned int ac97_clock; |
| 382 | unsigned int ac97_secondary; /* secondary AC'97 codec is present */ |
| 383 | |
| 384 | spinlock_t reg_lock; |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 385 | struct snd_info_entry *proc_entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
| 387 | #ifdef SUPPORT_JOYSTICK |
| 388 | struct gameport *gameport; |
| 389 | #endif |
| 390 | }; |
| 391 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 392 | static const struct pci_device_id snd_via82xx_ids[] = { |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 393 | /* 0x1106, 0x3058 */ |
Joe Perches | 28d27aa | 2009-06-24 22:13:35 -0700 | [diff] [blame] | 394 | { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_82C686_5), TYPE_CARD_VIA686, }, /* 686A */ |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 395 | /* 0x1106, 0x3059 */ |
Joe Perches | 28d27aa | 2009-06-24 22:13:35 -0700 | [diff] [blame] | 396 | { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_8233_5), TYPE_CARD_VIA8233, }, /* VT8233 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | { 0, } |
| 398 | }; |
| 399 | |
| 400 | MODULE_DEVICE_TABLE(pci, snd_via82xx_ids); |
| 401 | |
| 402 | /* |
| 403 | */ |
| 404 | |
| 405 | /* |
| 406 | * allocate and initialize the descriptor buffers |
| 407 | * periods = number of periods |
| 408 | * fragsize = period size in bytes |
| 409 | */ |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 410 | static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | struct pci_dev *pci, |
| 412 | unsigned int periods, unsigned int fragsize) |
| 413 | { |
| 414 | unsigned int i, idx, ofs, rest; |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 415 | struct via82xx *chip = snd_pcm_substream_chip(substream); |
Takashi Iwai | c5bb086 | 2020-02-06 17:31:50 +0100 | [diff] [blame] | 416 | __le32 *pgtbl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
| 418 | if (dev->table.area == NULL) { |
| 419 | /* the start of each lists must be aligned to 8 bytes, |
| 420 | * but the kernel pages are much bigger, so we don't care |
| 421 | */ |
Takashi Iwai | 6974f8a | 2019-11-05 16:18:55 +0100 | [diff] [blame] | 422 | if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &chip->pci->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | PAGE_ALIGN(VIA_TABLE_SIZE * 2 * 8), |
| 424 | &dev->table) < 0) |
| 425 | return -ENOMEM; |
| 426 | } |
| 427 | if (! dev->idx_table) { |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 428 | dev->idx_table = kmalloc_array(VIA_TABLE_SIZE, |
| 429 | sizeof(*dev->idx_table), |
| 430 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | if (! dev->idx_table) |
| 432 | return -ENOMEM; |
| 433 | } |
| 434 | |
| 435 | /* fill the entries */ |
| 436 | idx = 0; |
| 437 | ofs = 0; |
Takashi Iwai | c5bb086 | 2020-02-06 17:31:50 +0100 | [diff] [blame] | 438 | pgtbl = (__le32 *)dev->table.area; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | for (i = 0; i < periods; i++) { |
| 440 | rest = fragsize; |
| 441 | /* fill descriptors for a period. |
| 442 | * a period can be split to several descriptors if it's |
| 443 | * over page boundary. |
| 444 | */ |
| 445 | do { |
| 446 | unsigned int r; |
| 447 | unsigned int flag; |
Takashi Iwai | 77a23f2 | 2008-08-21 13:00:13 +0200 | [diff] [blame] | 448 | unsigned int addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
| 450 | if (idx >= VIA_TABLE_SIZE) { |
Takashi Iwai | 59d3acfa | 2014-02-25 15:21:56 +0100 | [diff] [blame] | 451 | dev_err(&pci->dev, "too much table size!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | return -EINVAL; |
| 453 | } |
Takashi Iwai | 77a23f2 | 2008-08-21 13:00:13 +0200 | [diff] [blame] | 454 | addr = snd_pcm_sgbuf_get_addr(substream, ofs); |
Takashi Iwai | c5bb086 | 2020-02-06 17:31:50 +0100 | [diff] [blame] | 455 | pgtbl[idx << 1] = cpu_to_le32(addr); |
Takashi Iwai | 5503600 | 2008-07-30 15:23:06 +0200 | [diff] [blame] | 456 | r = snd_pcm_sgbuf_get_chunk_size(substream, ofs, rest); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | rest -= r; |
| 458 | if (! rest) { |
| 459 | if (i == periods - 1) |
| 460 | flag = VIA_TBL_BIT_EOL; /* buffer boundary */ |
| 461 | else |
| 462 | flag = VIA_TBL_BIT_FLAG; /* period boundary */ |
| 463 | } else |
| 464 | flag = 0; /* period continues to the next */ |
Takashi Iwai | ee41965 | 2009-02-05 16:11:31 +0100 | [diff] [blame] | 465 | /* |
Takashi Iwai | 59d3acfa | 2014-02-25 15:21:56 +0100 | [diff] [blame] | 466 | dev_dbg(&pci->dev, |
| 467 | "tbl %d: at %d size %d (rest %d)\n", |
| 468 | idx, ofs, r, rest); |
Takashi Iwai | ee41965 | 2009-02-05 16:11:31 +0100 | [diff] [blame] | 469 | */ |
Takashi Iwai | c5bb086 | 2020-02-06 17:31:50 +0100 | [diff] [blame] | 470 | pgtbl[(idx<<1) + 1] = cpu_to_le32(r | flag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | dev->idx_table[idx].offset = ofs; |
| 472 | dev->idx_table[idx].size = r; |
| 473 | ofs += r; |
| 474 | idx++; |
| 475 | } while (rest > 0); |
| 476 | } |
| 477 | dev->tbl_entries = idx; |
| 478 | dev->bufsize = periods * fragsize; |
| 479 | dev->bufsize2 = dev->bufsize / 2; |
| 480 | dev->fragsize = fragsize; |
| 481 | return 0; |
| 482 | } |
| 483 | |
| 484 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 485 | static int clean_via_table(struct viadev *dev, struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | struct pci_dev *pci) |
| 487 | { |
| 488 | if (dev->table.area) { |
| 489 | snd_dma_free_pages(&dev->table); |
| 490 | dev->table.area = NULL; |
| 491 | } |
Jesper Juhl | 4d57277 | 2005-05-30 17:30:32 +0200 | [diff] [blame] | 492 | kfree(dev->idx_table); |
| 493 | dev->idx_table = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | return 0; |
| 495 | } |
| 496 | |
| 497 | /* |
| 498 | * Basic I/O |
| 499 | */ |
| 500 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 501 | static inline unsigned int snd_via82xx_codec_xread(struct via82xx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | { |
| 503 | return inl(VIAREG(chip, AC97)); |
| 504 | } |
| 505 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 506 | static inline void snd_via82xx_codec_xwrite(struct via82xx *chip, unsigned int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | { |
| 508 | outl(val, VIAREG(chip, AC97)); |
| 509 | } |
| 510 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 511 | static int snd_via82xx_codec_ready(struct via82xx *chip, int secondary) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | { |
| 513 | unsigned int timeout = 1000; /* 1ms */ |
| 514 | unsigned int val; |
| 515 | |
| 516 | while (timeout-- > 0) { |
| 517 | udelay(1); |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 518 | val = snd_via82xx_codec_xread(chip); |
| 519 | if (!(val & VIA_REG_AC97_BUSY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | return val & 0xffff; |
| 521 | } |
Takashi Iwai | 59d3acfa | 2014-02-25 15:21:56 +0100 | [diff] [blame] | 522 | dev_err(chip->card->dev, "codec_ready: codec %i is not ready [0x%x]\n", |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 523 | secondary, snd_via82xx_codec_xread(chip)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | return -EIO; |
| 525 | } |
| 526 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 527 | static int snd_via82xx_codec_valid(struct via82xx *chip, int secondary) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | { |
| 529 | unsigned int timeout = 1000; /* 1ms */ |
| 530 | unsigned int val, val1; |
| 531 | unsigned int stat = !secondary ? VIA_REG_AC97_PRIMARY_VALID : |
| 532 | VIA_REG_AC97_SECONDARY_VALID; |
| 533 | |
| 534 | while (timeout-- > 0) { |
| 535 | val = snd_via82xx_codec_xread(chip); |
| 536 | val1 = val & (VIA_REG_AC97_BUSY | stat); |
| 537 | if (val1 == stat) |
| 538 | return val & 0xffff; |
| 539 | udelay(1); |
| 540 | } |
| 541 | return -EIO; |
| 542 | } |
| 543 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 544 | static void snd_via82xx_codec_wait(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 546 | struct via82xx *chip = ac97->private_data; |
Pierre-Louis Bossart | 86a5d9c | 2020-07-02 14:36:01 -0500 | [diff] [blame] | 547 | __always_unused int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | err = snd_via82xx_codec_ready(chip, ac97->num); |
| 549 | /* here we need to wait fairly for long time.. */ |
Simon Arlott | 115551d | 2009-06-21 19:50:48 +0100 | [diff] [blame] | 550 | if (!nodelay) |
| 551 | msleep(500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 554 | static void snd_via82xx_codec_write(struct snd_ac97 *ac97, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | unsigned short reg, |
| 556 | unsigned short val) |
| 557 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 558 | struct via82xx *chip = ac97->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | unsigned int xval; |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 560 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | xval = !ac97->num ? VIA_REG_AC97_CODEC_ID_PRIMARY : VIA_REG_AC97_CODEC_ID_SECONDARY; |
| 562 | xval <<= VIA_REG_AC97_CODEC_ID_SHIFT; |
| 563 | xval |= reg << VIA_REG_AC97_CMD_SHIFT; |
| 564 | xval |= val << VIA_REG_AC97_DATA_SHIFT; |
| 565 | snd_via82xx_codec_xwrite(chip, xval); |
| 566 | snd_via82xx_codec_ready(chip, ac97->num); |
| 567 | } |
| 568 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 569 | static unsigned short snd_via82xx_codec_read(struct snd_ac97 *ac97, unsigned short reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 571 | struct via82xx *chip = ac97->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | unsigned int xval, val = 0xffff; |
| 573 | int again = 0; |
| 574 | |
| 575 | xval = ac97->num << VIA_REG_AC97_CODEC_ID_SHIFT; |
| 576 | xval |= ac97->num ? VIA_REG_AC97_SECONDARY_VALID : VIA_REG_AC97_PRIMARY_VALID; |
| 577 | xval |= VIA_REG_AC97_READ; |
| 578 | xval |= (reg & 0x7f) << VIA_REG_AC97_CMD_SHIFT; |
| 579 | while (1) { |
| 580 | if (again++ > 3) { |
Takashi Iwai | 59d3acfa | 2014-02-25 15:21:56 +0100 | [diff] [blame] | 581 | dev_err(chip->card->dev, |
| 582 | "codec_read: codec %i is not valid [0x%x]\n", |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 583 | ac97->num, snd_via82xx_codec_xread(chip)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | return 0xffff; |
| 585 | } |
| 586 | snd_via82xx_codec_xwrite(chip, xval); |
| 587 | udelay (20); |
| 588 | if (snd_via82xx_codec_valid(chip, ac97->num) >= 0) { |
| 589 | udelay(25); |
| 590 | val = snd_via82xx_codec_xread(chip); |
| 591 | break; |
| 592 | } |
| 593 | } |
| 594 | return val & 0xffff; |
| 595 | } |
| 596 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 597 | static void snd_via82xx_channel_reset(struct via82xx *chip, struct viadev *viadev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | { |
| 599 | outb(VIA_REG_CTRL_PAUSE | VIA_REG_CTRL_TERMINATE | VIA_REG_CTRL_RESET, |
| 600 | VIADEV_REG(viadev, OFFSET_CONTROL)); |
| 601 | inb(VIADEV_REG(viadev, OFFSET_CONTROL)); |
| 602 | udelay(50); |
| 603 | /* disable interrupts */ |
| 604 | outb(0x00, VIADEV_REG(viadev, OFFSET_CONTROL)); |
| 605 | /* clear interrupts */ |
| 606 | outb(0x03, VIADEV_REG(viadev, OFFSET_STATUS)); |
| 607 | outb(0x00, VIADEV_REG(viadev, OFFSET_TYPE)); /* for via686 */ |
| 608 | // outl(0, VIADEV_REG(viadev, OFFSET_CURR_PTR)); |
| 609 | viadev->lastpos = 0; |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 610 | viadev->hwptr_done = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | |
| 614 | /* |
| 615 | * Interrupt handler |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 616 | * Used for 686 and 8233A |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 618 | static irqreturn_t snd_via686_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 620 | struct via82xx *chip = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | unsigned int status; |
| 622 | unsigned int i; |
| 623 | |
| 624 | status = inl(VIAREG(chip, SGD_SHADOW)); |
| 625 | if (! (status & chip->intr_mask)) { |
| 626 | if (chip->rmidi) |
| 627 | /* check mpu401 interrupt */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 628 | return snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | return IRQ_NONE; |
| 630 | } |
| 631 | |
| 632 | /* check status for each stream */ |
| 633 | spin_lock(&chip->reg_lock); |
| 634 | for (i = 0; i < chip->num_devs; i++) { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 635 | struct viadev *viadev = &chip->devs[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | unsigned char c_status = inb(VIADEV_REG(viadev, OFFSET_STATUS)); |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 637 | if (! (c_status & (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG|VIA_REG_STAT_STOPPED))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | continue; |
| 639 | if (viadev->substream && viadev->running) { |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 640 | /* |
| 641 | * Update hwptr_done based on 'period elapsed' |
| 642 | * interrupts. We'll use it, when the chip returns 0 |
| 643 | * for OFFSET_CURR_COUNT. |
| 644 | */ |
| 645 | if (c_status & VIA_REG_STAT_EOL) |
| 646 | viadev->hwptr_done = 0; |
| 647 | else |
| 648 | viadev->hwptr_done += viadev->fragsize; |
| 649 | viadev->in_interrupt = c_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | spin_unlock(&chip->reg_lock); |
| 651 | snd_pcm_period_elapsed(viadev->substream); |
| 652 | spin_lock(&chip->reg_lock); |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 653 | viadev->in_interrupt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | } |
| 655 | outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */ |
| 656 | } |
| 657 | spin_unlock(&chip->reg_lock); |
| 658 | return IRQ_HANDLED; |
| 659 | } |
| 660 | |
| 661 | /* |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 662 | * Interrupt handler |
| 663 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 664 | static irqreturn_t snd_via8233_interrupt(int irq, void *dev_id) |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 665 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 666 | struct via82xx *chip = dev_id; |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 667 | unsigned int status; |
| 668 | unsigned int i; |
| 669 | int irqreturn = 0; |
| 670 | |
| 671 | /* check status for each stream */ |
| 672 | spin_lock(&chip->reg_lock); |
| 673 | status = inl(VIAREG(chip, SGD_SHADOW)); |
| 674 | |
| 675 | for (i = 0; i < chip->num_devs; i++) { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 676 | struct viadev *viadev = &chip->devs[i]; |
| 677 | struct snd_pcm_substream *substream; |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 678 | unsigned char c_status, shadow_status; |
| 679 | |
| 680 | shadow_status = (status >> viadev->shadow_shift) & |
| 681 | (VIA8233_SHADOW_STAT_ACTIVE|VIA_REG_STAT_EOL| |
| 682 | VIA_REG_STAT_FLAG); |
| 683 | c_status = shadow_status & (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG); |
| 684 | if (!c_status) |
| 685 | continue; |
| 686 | |
| 687 | substream = viadev->substream; |
| 688 | if (substream && viadev->running) { |
| 689 | /* |
| 690 | * Update hwptr_done based on 'period elapsed' |
| 691 | * interrupts. We'll use it, when the chip returns 0 |
| 692 | * for OFFSET_CURR_COUNT. |
| 693 | */ |
| 694 | if (c_status & VIA_REG_STAT_EOL) |
| 695 | viadev->hwptr_done = 0; |
| 696 | else |
| 697 | viadev->hwptr_done += viadev->fragsize; |
| 698 | viadev->in_interrupt = c_status; |
| 699 | if (shadow_status & VIA8233_SHADOW_STAT_ACTIVE) |
| 700 | viadev->in_interrupt |= VIA_REG_STAT_ACTIVE; |
| 701 | spin_unlock(&chip->reg_lock); |
| 702 | |
| 703 | snd_pcm_period_elapsed(substream); |
| 704 | |
| 705 | spin_lock(&chip->reg_lock); |
| 706 | viadev->in_interrupt = 0; |
| 707 | } |
| 708 | outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */ |
| 709 | irqreturn = 1; |
| 710 | } |
| 711 | spin_unlock(&chip->reg_lock); |
| 712 | return IRQ_RETVAL(irqreturn); |
| 713 | } |
| 714 | |
| 715 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | * PCM callbacks |
| 717 | */ |
| 718 | |
| 719 | /* |
| 720 | * trigger callback |
| 721 | */ |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 722 | static int snd_via82xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 724 | struct via82xx *chip = snd_pcm_substream_chip(substream); |
| 725 | struct viadev *viadev = substream->runtime->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | unsigned char val; |
| 727 | |
| 728 | if (chip->chip_type != TYPE_VIA686) |
| 729 | val = VIA_REG_CTRL_INT; |
| 730 | else |
| 731 | val = 0; |
| 732 | switch (cmd) { |
| 733 | case SNDRV_PCM_TRIGGER_START: |
Jaroslav Kysela | 41e4845 | 2005-08-18 13:43:12 +0200 | [diff] [blame] | 734 | case SNDRV_PCM_TRIGGER_RESUME: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | val |= VIA_REG_CTRL_START; |
| 736 | viadev->running = 1; |
| 737 | break; |
| 738 | case SNDRV_PCM_TRIGGER_STOP: |
Jaroslav Kysela | 41e4845 | 2005-08-18 13:43:12 +0200 | [diff] [blame] | 739 | case SNDRV_PCM_TRIGGER_SUSPEND: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | val = VIA_REG_CTRL_TERMINATE; |
| 741 | viadev->running = 0; |
| 742 | break; |
| 743 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 744 | val |= VIA_REG_CTRL_PAUSE; |
| 745 | viadev->running = 0; |
| 746 | break; |
| 747 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 748 | viadev->running = 1; |
| 749 | break; |
| 750 | default: |
| 751 | return -EINVAL; |
| 752 | } |
| 753 | outb(val, VIADEV_REG(viadev, OFFSET_CONTROL)); |
| 754 | if (cmd == SNDRV_PCM_TRIGGER_STOP) |
| 755 | snd_via82xx_channel_reset(chip, viadev); |
| 756 | return 0; |
| 757 | } |
| 758 | |
| 759 | |
| 760 | /* |
| 761 | * pointer callbacks |
| 762 | */ |
| 763 | |
| 764 | /* |
| 765 | * calculate the linear position at the given sg-buffer index and the rest count |
| 766 | */ |
| 767 | |
| 768 | #define check_invalid_pos(viadev,pos) \ |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 769 | ((pos) < viadev->lastpos && ((pos) >= viadev->bufsize2 ||\ |
| 770 | viadev->lastpos < viadev->bufsize2)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | |
Takashi Iwai | 59d3acfa | 2014-02-25 15:21:56 +0100 | [diff] [blame] | 772 | static inline unsigned int calc_linear_pos(struct via82xx *chip, |
| 773 | struct viadev *viadev, |
| 774 | unsigned int idx, |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 775 | unsigned int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | { |
| 777 | unsigned int size, base, res; |
| 778 | |
| 779 | size = viadev->idx_table[idx].size; |
| 780 | base = viadev->idx_table[idx].offset; |
| 781 | res = base + size - count; |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 782 | if (res >= viadev->bufsize) |
| 783 | res -= viadev->bufsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | |
| 785 | /* check the validity of the calculated position */ |
| 786 | if (size < count) { |
Takashi Iwai | 59d3acfa | 2014-02-25 15:21:56 +0100 | [diff] [blame] | 787 | dev_dbg(chip->card->dev, |
| 788 | "invalid via82xx_cur_ptr (size = %d, count = %d)\n", |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 789 | (int)size, (int)count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | res = viadev->lastpos; |
| 791 | } else { |
| 792 | if (! count) { |
| 793 | /* Some mobos report count = 0 on the DMA boundary, |
| 794 | * i.e. count = size indeed. |
| 795 | * Let's check whether this step is above the expected size. |
| 796 | */ |
| 797 | int delta = res - viadev->lastpos; |
| 798 | if (delta < 0) |
| 799 | delta += viadev->bufsize; |
| 800 | if ((unsigned int)delta > viadev->fragsize) |
| 801 | res = base; |
| 802 | } |
| 803 | if (check_invalid_pos(viadev, res)) { |
| 804 | #ifdef POINTER_DEBUG |
Takashi Iwai | 59d3acfa | 2014-02-25 15:21:56 +0100 | [diff] [blame] | 805 | dev_dbg(chip->card->dev, |
| 806 | "fail: idx = %i/%i, lastpos = 0x%x, bufsize2 = 0x%x, offsize = 0x%x, size = 0x%x, count = 0x%x\n", |
| 807 | idx, viadev->tbl_entries, |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 808 | viadev->lastpos, viadev->bufsize2, |
| 809 | viadev->idx_table[idx].offset, |
| 810 | viadev->idx_table[idx].size, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | #endif |
| 812 | /* count register returns full size when end of buffer is reached */ |
| 813 | res = base + size; |
| 814 | if (check_invalid_pos(viadev, res)) { |
Takashi Iwai | 59d3acfa | 2014-02-25 15:21:56 +0100 | [diff] [blame] | 815 | dev_dbg(chip->card->dev, |
| 816 | "invalid via82xx_cur_ptr (2), using last valid pointer\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | res = viadev->lastpos; |
| 818 | } |
| 819 | } |
| 820 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | return res; |
| 822 | } |
| 823 | |
| 824 | /* |
| 825 | * get the current pointer on via686 |
| 826 | */ |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 827 | static snd_pcm_uframes_t snd_via686_pcm_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 829 | struct via82xx *chip = snd_pcm_substream_chip(substream); |
| 830 | struct viadev *viadev = substream->runtime->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | unsigned int idx, ptr, count, res; |
| 832 | |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 833 | if (snd_BUG_ON(!viadev->tbl_entries)) |
| 834 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | if (!(inb(VIADEV_REG(viadev, OFFSET_STATUS)) & VIA_REG_STAT_ACTIVE)) |
| 836 | return 0; |
| 837 | |
| 838 | spin_lock(&chip->reg_lock); |
| 839 | count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT)) & 0xffffff; |
| 840 | /* The via686a does not have the current index register, |
| 841 | * so we need to calculate the index from CURR_PTR. |
| 842 | */ |
| 843 | ptr = inl(VIADEV_REG(viadev, OFFSET_CURR_PTR)); |
| 844 | if (ptr <= (unsigned int)viadev->table.addr) |
| 845 | idx = 0; |
| 846 | else /* CURR_PTR holds the address + 8 */ |
| 847 | idx = ((ptr - (unsigned int)viadev->table.addr) / 8 - 1) % viadev->tbl_entries; |
Takashi Iwai | 59d3acfa | 2014-02-25 15:21:56 +0100 | [diff] [blame] | 848 | res = calc_linear_pos(chip, viadev, idx, count); |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 849 | viadev->lastpos = res; /* remember the last position */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | spin_unlock(&chip->reg_lock); |
| 851 | |
| 852 | return bytes_to_frames(substream->runtime, res); |
| 853 | } |
| 854 | |
| 855 | /* |
| 856 | * get the current pointer on via823x |
| 857 | */ |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 858 | static snd_pcm_uframes_t snd_via8233_pcm_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 860 | struct via82xx *chip = snd_pcm_substream_chip(substream); |
| 861 | struct viadev *viadev = substream->runtime->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | unsigned int idx, count, res; |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 863 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 865 | if (snd_BUG_ON(!viadev->tbl_entries)) |
| 866 | return 0; |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 867 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | spin_lock(&chip->reg_lock); |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 869 | count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT)); |
| 870 | status = viadev->in_interrupt; |
| 871 | if (!status) |
| 872 | status = inb(VIADEV_REG(viadev, OFFSET_STATUS)); |
| 873 | |
Bastiaan Jacques | c6cc0e3 | 2006-04-20 12:27:09 +0200 | [diff] [blame] | 874 | /* An apparent bug in the 8251 is worked around by sending a |
| 875 | * REG_CTRL_START. */ |
| 876 | if (chip->revision == VIA_REV_8251 && (status & VIA_REG_STAT_EOL)) |
| 877 | snd_via82xx_pcm_trigger(substream, SNDRV_PCM_TRIGGER_START); |
| 878 | |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 879 | if (!(status & VIA_REG_STAT_ACTIVE)) { |
Bastiaan Jacques | c6cc0e3 | 2006-04-20 12:27:09 +0200 | [diff] [blame] | 880 | res = 0; |
| 881 | goto unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | } |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 883 | if (count & 0xffffff) { |
| 884 | idx = count >> 24; |
| 885 | if (idx >= viadev->tbl_entries) { |
| 886 | #ifdef POINTER_DEBUG |
Takashi Iwai | 59d3acfa | 2014-02-25 15:21:56 +0100 | [diff] [blame] | 887 | dev_dbg(chip->card->dev, |
| 888 | "fail: invalid idx = %i/%i\n", idx, |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 889 | viadev->tbl_entries); |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 890 | #endif |
| 891 | res = viadev->lastpos; |
| 892 | } else { |
| 893 | count &= 0xffffff; |
Takashi Iwai | 59d3acfa | 2014-02-25 15:21:56 +0100 | [diff] [blame] | 894 | res = calc_linear_pos(chip, viadev, idx, count); |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 895 | } |
| 896 | } else { |
| 897 | res = viadev->hwptr_done; |
| 898 | if (!viadev->in_interrupt) { |
| 899 | if (status & VIA_REG_STAT_EOL) { |
| 900 | res = 0; |
| 901 | } else |
| 902 | if (status & VIA_REG_STAT_FLAG) { |
| 903 | res += viadev->fragsize; |
| 904 | } |
| 905 | } |
| 906 | } |
| 907 | unlock: |
| 908 | viadev->lastpos = res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | spin_unlock(&chip->reg_lock); |
| 910 | |
| 911 | return bytes_to_frames(substream->runtime, res); |
| 912 | } |
| 913 | |
| 914 | |
| 915 | /* |
| 916 | * hw_params callback: |
| 917 | * allocate the buffer and build up the buffer description table |
| 918 | */ |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 919 | static int snd_via82xx_hw_params(struct snd_pcm_substream *substream, |
| 920 | struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 922 | struct via82xx *chip = snd_pcm_substream_chip(substream); |
| 923 | struct viadev *viadev = substream->runtime->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | |
Takashi Iwai | 8e2c752 | 2019-12-09 10:49:27 +0100 | [diff] [blame] | 925 | return build_via_table(viadev, substream, chip->pci, |
| 926 | params_periods(hw_params), |
| 927 | params_period_bytes(hw_params)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | /* |
| 931 | * hw_free callback: |
| 932 | * clean up the buffer description table and release the buffer |
| 933 | */ |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 934 | static int snd_via82xx_hw_free(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 936 | struct via82xx *chip = snd_pcm_substream_chip(substream); |
| 937 | struct viadev *viadev = substream->runtime->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | |
| 939 | clean_via_table(viadev, substream, chip->pci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | return 0; |
| 941 | } |
| 942 | |
| 943 | |
| 944 | /* |
| 945 | * set up the table pointer |
| 946 | */ |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 947 | static void snd_via82xx_set_table_ptr(struct via82xx *chip, struct viadev *viadev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | { |
| 949 | snd_via82xx_codec_ready(chip, 0); |
| 950 | outl((u32)viadev->table.addr, VIADEV_REG(viadev, OFFSET_TABLE_PTR)); |
| 951 | udelay(20); |
| 952 | snd_via82xx_codec_ready(chip, 0); |
| 953 | } |
| 954 | |
| 955 | /* |
| 956 | * prepare callback for playback and capture on via686 |
| 957 | */ |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 958 | static void via686_setup_format(struct via82xx *chip, struct viadev *viadev, |
| 959 | struct snd_pcm_runtime *runtime) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | { |
| 961 | snd_via82xx_channel_reset(chip, viadev); |
| 962 | /* this must be set after channel_reset */ |
| 963 | snd_via82xx_set_table_ptr(chip, viadev); |
| 964 | outb(VIA_REG_TYPE_AUTOSTART | |
| 965 | (runtime->format == SNDRV_PCM_FORMAT_S16_LE ? VIA_REG_TYPE_16BIT : 0) | |
| 966 | (runtime->channels > 1 ? VIA_REG_TYPE_STEREO : 0) | |
| 967 | ((viadev->reg_offset & 0x10) == 0 ? VIA_REG_TYPE_INT_LSAMPLE : 0) | |
| 968 | VIA_REG_TYPE_INT_EOL | |
| 969 | VIA_REG_TYPE_INT_FLAG, VIADEV_REG(viadev, OFFSET_TYPE)); |
| 970 | } |
| 971 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 972 | static int snd_via686_playback_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 974 | struct via82xx *chip = snd_pcm_substream_chip(substream); |
| 975 | struct viadev *viadev = substream->runtime->private_data; |
| 976 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | |
| 978 | snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, runtime->rate); |
| 979 | snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate); |
| 980 | via686_setup_format(chip, viadev, runtime); |
| 981 | return 0; |
| 982 | } |
| 983 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 984 | static int snd_via686_capture_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 986 | struct via82xx *chip = snd_pcm_substream_chip(substream); |
| 987 | struct viadev *viadev = substream->runtime->private_data; |
| 988 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | |
| 990 | snd_ac97_set_rate(chip->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate); |
| 991 | via686_setup_format(chip, viadev, runtime); |
| 992 | return 0; |
| 993 | } |
| 994 | |
| 995 | /* |
| 996 | * lock the current rate |
| 997 | */ |
| 998 | static int via_lock_rate(struct via_rate_lock *rec, int rate) |
| 999 | { |
| 1000 | int changed = 0; |
| 1001 | |
| 1002 | spin_lock_irq(&rec->lock); |
| 1003 | if (rec->rate != rate) { |
| 1004 | if (rec->rate && rec->used > 1) /* already set */ |
| 1005 | changed = -EINVAL; |
| 1006 | else { |
| 1007 | rec->rate = rate; |
| 1008 | changed = 1; |
| 1009 | } |
| 1010 | } |
| 1011 | spin_unlock_irq(&rec->lock); |
| 1012 | return changed; |
| 1013 | } |
| 1014 | |
| 1015 | /* |
| 1016 | * prepare callback for DSX playback on via823x |
| 1017 | */ |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1018 | static int snd_via8233_playback_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1020 | struct via82xx *chip = snd_pcm_substream_chip(substream); |
| 1021 | struct viadev *viadev = substream->runtime->private_data; |
| 1022 | struct snd_pcm_runtime *runtime = substream->runtime; |
Sergey Vlasov | 2d7eb7c | 2005-04-11 15:04:33 +0200 | [diff] [blame] | 1023 | int ac97_rate = chip->dxs_src ? 48000 : runtime->rate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | int rate_changed; |
| 1025 | u32 rbits; |
| 1026 | |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 1027 | rate_changed = via_lock_rate(&chip->rates[0], ac97_rate); |
| 1028 | if (rate_changed < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | return rate_changed; |
Takashi Iwai | 16d3f14 | 2005-08-15 15:02:28 +0200 | [diff] [blame] | 1030 | if (rate_changed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, |
| 1032 | chip->no_vra ? 48000 : runtime->rate); |
Takashi Iwai | 16d3f14 | 2005-08-15 15:02:28 +0200 | [diff] [blame] | 1033 | if (chip->spdif_on && viadev->reg_offset == 0x30) |
| 1034 | snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate); |
| 1035 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | if (runtime->rate == 48000) |
| 1037 | rbits = 0xfffff; |
| 1038 | else |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1039 | rbits = (0x100000 / 48000) * runtime->rate + |
| 1040 | ((0x100000 % 48000) * runtime->rate) / 48000; |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 1041 | snd_BUG_ON(rbits & ~0xfffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | snd_via82xx_channel_reset(chip, viadev); |
| 1043 | snd_via82xx_set_table_ptr(chip, viadev); |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1044 | outb(chip->playback_volume[viadev->reg_offset / 0x10][0], |
| 1045 | VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_L)); |
| 1046 | outb(chip->playback_volume[viadev->reg_offset / 0x10][1], |
| 1047 | VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_R)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | outl((runtime->format == SNDRV_PCM_FORMAT_S16_LE ? VIA8233_REG_TYPE_16BIT : 0) | /* format */ |
| 1049 | (runtime->channels > 1 ? VIA8233_REG_TYPE_STEREO : 0) | /* stereo */ |
| 1050 | rbits | /* rate */ |
| 1051 | 0xff000000, /* STOP index is never reached */ |
| 1052 | VIADEV_REG(viadev, OFFSET_STOP_IDX)); |
| 1053 | udelay(20); |
| 1054 | snd_via82xx_codec_ready(chip, 0); |
| 1055 | return 0; |
| 1056 | } |
| 1057 | |
| 1058 | /* |
| 1059 | * prepare callback for multi-channel playback on via823x |
| 1060 | */ |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1061 | static int snd_via8233_multi_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1063 | struct via82xx *chip = snd_pcm_substream_chip(substream); |
| 1064 | struct viadev *viadev = substream->runtime->private_data; |
| 1065 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | unsigned int slots; |
| 1067 | int fmt; |
| 1068 | |
| 1069 | if (via_lock_rate(&chip->rates[0], runtime->rate) < 0) |
| 1070 | return -EINVAL; |
| 1071 | snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, runtime->rate); |
| 1072 | snd_ac97_set_rate(chip->ac97, AC97_PCM_SURR_DAC_RATE, runtime->rate); |
| 1073 | snd_ac97_set_rate(chip->ac97, AC97_PCM_LFE_DAC_RATE, runtime->rate); |
| 1074 | snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate); |
| 1075 | snd_via82xx_channel_reset(chip, viadev); |
| 1076 | snd_via82xx_set_table_ptr(chip, viadev); |
| 1077 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1078 | fmt = (runtime->format == SNDRV_PCM_FORMAT_S16_LE) ? |
| 1079 | VIA_REG_MULTPLAY_FMT_16BIT : VIA_REG_MULTPLAY_FMT_8BIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | fmt |= runtime->channels << 4; |
| 1081 | outb(fmt, VIADEV_REG(viadev, OFS_MULTPLAY_FORMAT)); |
| 1082 | #if 0 |
| 1083 | if (chip->revision == VIA_REV_8233A) |
| 1084 | slots = 0; |
| 1085 | else |
| 1086 | #endif |
| 1087 | { |
| 1088 | /* set sample number to slot 3, 4, 7, 8, 6, 9 (for VIA8233/C,8235) */ |
| 1089 | /* corresponding to FL, FR, RL, RR, C, LFE ?? */ |
| 1090 | switch (runtime->channels) { |
| 1091 | case 1: slots = (1<<0) | (1<<4); break; |
| 1092 | case 2: slots = (1<<0) | (2<<4); break; |
| 1093 | case 3: slots = (1<<0) | (2<<4) | (5<<8); break; |
| 1094 | case 4: slots = (1<<0) | (2<<4) | (3<<8) | (4<<12); break; |
| 1095 | case 5: slots = (1<<0) | (2<<4) | (3<<8) | (4<<12) | (5<<16); break; |
| 1096 | case 6: slots = (1<<0) | (2<<4) | (3<<8) | (4<<12) | (5<<16) | (6<<20); break; |
| 1097 | default: slots = 0; break; |
| 1098 | } |
| 1099 | } |
| 1100 | /* STOP index is never reached */ |
| 1101 | outl(0xff000000 | slots, VIADEV_REG(viadev, OFFSET_STOP_IDX)); |
| 1102 | udelay(20); |
| 1103 | snd_via82xx_codec_ready(chip, 0); |
| 1104 | return 0; |
| 1105 | } |
| 1106 | |
| 1107 | /* |
| 1108 | * prepare callback for capture on via823x |
| 1109 | */ |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1110 | static int snd_via8233_capture_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1112 | struct via82xx *chip = snd_pcm_substream_chip(substream); |
| 1113 | struct viadev *viadev = substream->runtime->private_data; |
| 1114 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | |
| 1116 | if (via_lock_rate(&chip->rates[1], runtime->rate) < 0) |
| 1117 | return -EINVAL; |
| 1118 | snd_ac97_set_rate(chip->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate); |
| 1119 | snd_via82xx_channel_reset(chip, viadev); |
| 1120 | snd_via82xx_set_table_ptr(chip, viadev); |
| 1121 | outb(VIA_REG_CAPTURE_FIFO_ENABLE, VIADEV_REG(viadev, OFS_CAPTURE_FIFO)); |
| 1122 | outl((runtime->format == SNDRV_PCM_FORMAT_S16_LE ? VIA8233_REG_TYPE_16BIT : 0) | |
| 1123 | (runtime->channels > 1 ? VIA8233_REG_TYPE_STEREO : 0) | |
| 1124 | 0xff000000, /* STOP index is never reached */ |
| 1125 | VIADEV_REG(viadev, OFFSET_STOP_IDX)); |
| 1126 | udelay(20); |
| 1127 | snd_via82xx_codec_ready(chip, 0); |
| 1128 | return 0; |
| 1129 | } |
| 1130 | |
| 1131 | |
| 1132 | /* |
| 1133 | * pcm hardware definition, identical for both playback and capture |
| 1134 | */ |
Bhumika Goyal | dee4989 | 2017-08-12 21:01:28 +0530 | [diff] [blame] | 1135 | static const struct snd_pcm_hardware snd_via82xx_hw = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | { |
| 1137 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 1138 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 1139 | SNDRV_PCM_INFO_MMAP_VALID | |
Jaroslav Kysela | 41e4845 | 2005-08-18 13:43:12 +0200 | [diff] [blame] | 1140 | /* SNDRV_PCM_INFO_RESUME | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | SNDRV_PCM_INFO_PAUSE), |
| 1142 | .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, |
| 1143 | .rates = SNDRV_PCM_RATE_48000, |
| 1144 | .rate_min = 48000, |
| 1145 | .rate_max = 48000, |
| 1146 | .channels_min = 1, |
| 1147 | .channels_max = 2, |
Takashi Iwai | 5503600 | 2008-07-30 15:23:06 +0200 | [diff] [blame] | 1148 | .buffer_bytes_max = VIA_MAX_BUFSIZE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | .period_bytes_min = 32, |
Takashi Iwai | 5503600 | 2008-07-30 15:23:06 +0200 | [diff] [blame] | 1150 | .period_bytes_max = VIA_MAX_BUFSIZE / 2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | .periods_min = 2, |
| 1152 | .periods_max = VIA_TABLE_SIZE / 2, |
| 1153 | .fifo_size = 0, |
| 1154 | }; |
| 1155 | |
| 1156 | |
| 1157 | /* |
| 1158 | * open callback skeleton |
| 1159 | */ |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1160 | static int snd_via82xx_pcm_open(struct via82xx *chip, struct viadev *viadev, |
| 1161 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1163 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | int err; |
| 1165 | struct via_rate_lock *ratep; |
Clemens Ladisch | 5495ffb | 2011-09-16 23:16:05 +0200 | [diff] [blame] | 1166 | bool use_src = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | |
| 1168 | runtime->hw = snd_via82xx_hw; |
| 1169 | |
| 1170 | /* set the hw rate condition */ |
| 1171 | ratep = &chip->rates[viadev->direction]; |
| 1172 | spin_lock_irq(&ratep->lock); |
| 1173 | ratep->used++; |
| 1174 | if (chip->spdif_on && viadev->reg_offset == 0x30) { |
| 1175 | /* DXS#3 and spdif is on */ |
| 1176 | runtime->hw.rates = chip->ac97->rates[AC97_RATES_SPDIF]; |
| 1177 | snd_pcm_limit_hw_rates(runtime); |
| 1178 | } else if (chip->dxs_fixed && viadev->reg_offset < 0x40) { |
| 1179 | /* fixed DXS playback rate */ |
| 1180 | runtime->hw.rates = SNDRV_PCM_RATE_48000; |
| 1181 | runtime->hw.rate_min = runtime->hw.rate_max = 48000; |
Sergey Vlasov | 2d7eb7c | 2005-04-11 15:04:33 +0200 | [diff] [blame] | 1182 | } else if (chip->dxs_src && viadev->reg_offset < 0x40) { |
| 1183 | /* use full SRC capabilities of DXS */ |
| 1184 | runtime->hw.rates = (SNDRV_PCM_RATE_CONTINUOUS | |
| 1185 | SNDRV_PCM_RATE_8000_48000); |
| 1186 | runtime->hw.rate_min = 8000; |
| 1187 | runtime->hw.rate_max = 48000; |
Clemens Ladisch | 5495ffb | 2011-09-16 23:16:05 +0200 | [diff] [blame] | 1188 | use_src = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | } else if (! ratep->rate) { |
| 1190 | int idx = viadev->direction ? AC97_RATES_ADC : AC97_RATES_FRONT_DAC; |
| 1191 | runtime->hw.rates = chip->ac97->rates[idx]; |
| 1192 | snd_pcm_limit_hw_rates(runtime); |
| 1193 | } else { |
| 1194 | /* a fixed rate */ |
| 1195 | runtime->hw.rates = SNDRV_PCM_RATE_KNOT; |
| 1196 | runtime->hw.rate_max = runtime->hw.rate_min = ratep->rate; |
| 1197 | } |
| 1198 | spin_unlock_irq(&ratep->lock); |
| 1199 | |
| 1200 | /* we may remove following constaint when we modify table entries |
| 1201 | in interrupt */ |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 1202 | err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); |
| 1203 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | return err; |
| 1205 | |
Clemens Ladisch | 5495ffb | 2011-09-16 23:16:05 +0200 | [diff] [blame] | 1206 | if (use_src) { |
| 1207 | err = snd_pcm_hw_rule_noresample(runtime, 48000); |
| 1208 | if (err < 0) |
| 1209 | return err; |
| 1210 | } |
| 1211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | runtime->private_data = viadev; |
| 1213 | viadev->substream = substream; |
| 1214 | |
| 1215 | return 0; |
| 1216 | } |
| 1217 | |
| 1218 | |
| 1219 | /* |
Clemens Ladisch | 3d00941 | 2009-10-22 09:04:09 +0200 | [diff] [blame] | 1220 | * open callback for playback on via686 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | */ |
Clemens Ladisch | 3d00941 | 2009-10-22 09:04:09 +0200 | [diff] [blame] | 1222 | static int snd_via686_playback_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1224 | struct via82xx *chip = snd_pcm_substream_chip(substream); |
| 1225 | struct viadev *viadev = &chip->devs[chip->playback_devno + substream->number]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | int err; |
| 1227 | |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 1228 | err = snd_via82xx_pcm_open(chip, viadev, substream); |
| 1229 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | return err; |
| 1231 | return 0; |
| 1232 | } |
| 1233 | |
| 1234 | /* |
Clemens Ladisch | 3d00941 | 2009-10-22 09:04:09 +0200 | [diff] [blame] | 1235 | * open callback for playback on via823x DXS |
| 1236 | */ |
| 1237 | static int snd_via8233_playback_open(struct snd_pcm_substream *substream) |
| 1238 | { |
| 1239 | struct via82xx *chip = snd_pcm_substream_chip(substream); |
| 1240 | struct viadev *viadev; |
| 1241 | unsigned int stream; |
| 1242 | int err; |
| 1243 | |
| 1244 | viadev = &chip->devs[chip->playback_devno + substream->number]; |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 1245 | err = snd_via82xx_pcm_open(chip, viadev, substream); |
| 1246 | if (err < 0) |
Clemens Ladisch | 3d00941 | 2009-10-22 09:04:09 +0200 | [diff] [blame] | 1247 | return err; |
| 1248 | stream = viadev->reg_offset / 0x10; |
| 1249 | if (chip->dxs_controls[stream]) { |
Clemens Ladisch | 395c61d | 2010-07-12 16:27:24 +0200 | [diff] [blame] | 1250 | chip->playback_volume[stream][0] = |
| 1251 | VIA_DXS_MAX_VOLUME - (dxs_init_volume & 31); |
| 1252 | chip->playback_volume[stream][1] = |
| 1253 | VIA_DXS_MAX_VOLUME - (dxs_init_volume & 31); |
Clemens Ladisch | 3d00941 | 2009-10-22 09:04:09 +0200 | [diff] [blame] | 1254 | chip->dxs_controls[stream]->vd[0].access &= |
| 1255 | ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; |
| 1256 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE | |
| 1257 | SNDRV_CTL_EVENT_MASK_INFO, |
| 1258 | &chip->dxs_controls[stream]->id); |
| 1259 | } |
| 1260 | return 0; |
| 1261 | } |
| 1262 | |
| 1263 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | * open callback for playback on via823x multi-channel |
| 1265 | */ |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1266 | static int snd_via8233_multi_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1268 | struct via82xx *chip = snd_pcm_substream_chip(substream); |
| 1269 | struct viadev *viadev = &chip->devs[chip->multi_devno]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | int err; |
| 1271 | /* channels constraint for VIA8233A |
| 1272 | * 3 and 5 channels are not supported |
| 1273 | */ |
Takashi Iwai | fbc57b2 | 2017-06-07 14:23:13 +0200 | [diff] [blame] | 1274 | static const unsigned int channels[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | 1, 2, 4, 6 |
| 1276 | }; |
Takashi Iwai | fbc57b2 | 2017-06-07 14:23:13 +0200 | [diff] [blame] | 1277 | static const struct snd_pcm_hw_constraint_list hw_constraints_channels = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | .count = ARRAY_SIZE(channels), |
| 1279 | .list = channels, |
| 1280 | .mask = 0, |
| 1281 | }; |
| 1282 | |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 1283 | err = snd_via82xx_pcm_open(chip, viadev, substream); |
| 1284 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | return err; |
| 1286 | substream->runtime->hw.channels_max = 6; |
| 1287 | if (chip->revision == VIA_REV_8233A) |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1288 | snd_pcm_hw_constraint_list(substream->runtime, 0, |
| 1289 | SNDRV_PCM_HW_PARAM_CHANNELS, |
| 1290 | &hw_constraints_channels); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | return 0; |
| 1292 | } |
| 1293 | |
| 1294 | /* |
| 1295 | * open callback for capture on via686 and via823x |
| 1296 | */ |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1297 | static int snd_via82xx_capture_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1299 | struct via82xx *chip = snd_pcm_substream_chip(substream); |
| 1300 | struct viadev *viadev = &chip->devs[chip->capture_devno + substream->pcm->device]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | |
| 1302 | return snd_via82xx_pcm_open(chip, viadev, substream); |
| 1303 | } |
| 1304 | |
| 1305 | /* |
| 1306 | * close callback |
| 1307 | */ |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1308 | static int snd_via82xx_pcm_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1310 | struct via82xx *chip = snd_pcm_substream_chip(substream); |
| 1311 | struct viadev *viadev = substream->runtime->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | struct via_rate_lock *ratep; |
| 1313 | |
| 1314 | /* release the rate lock */ |
| 1315 | ratep = &chip->rates[viadev->direction]; |
| 1316 | spin_lock_irq(&ratep->lock); |
| 1317 | ratep->used--; |
| 1318 | if (! ratep->used) |
| 1319 | ratep->rate = 0; |
| 1320 | spin_unlock_irq(&ratep->lock); |
Takashi Iwai | 6dbe662 | 2006-06-27 18:28:53 +0200 | [diff] [blame] | 1321 | if (! ratep->rate) { |
| 1322 | if (! viadev->direction) { |
| 1323 | snd_ac97_update_power(chip->ac97, |
| 1324 | AC97_PCM_FRONT_DAC_RATE, 0); |
| 1325 | snd_ac97_update_power(chip->ac97, |
| 1326 | AC97_PCM_SURR_DAC_RATE, 0); |
| 1327 | snd_ac97_update_power(chip->ac97, |
| 1328 | AC97_PCM_LFE_DAC_RATE, 0); |
| 1329 | } else |
| 1330 | snd_ac97_update_power(chip->ac97, |
| 1331 | AC97_PCM_LR_ADC_RATE, 0); |
| 1332 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | viadev->substream = NULL; |
| 1334 | return 0; |
| 1335 | } |
| 1336 | |
Clemens Ladisch | 3d00941 | 2009-10-22 09:04:09 +0200 | [diff] [blame] | 1337 | static int snd_via8233_playback_close(struct snd_pcm_substream *substream) |
| 1338 | { |
| 1339 | struct via82xx *chip = snd_pcm_substream_chip(substream); |
| 1340 | struct viadev *viadev = substream->runtime->private_data; |
| 1341 | unsigned int stream; |
| 1342 | |
| 1343 | stream = viadev->reg_offset / 0x10; |
| 1344 | if (chip->dxs_controls[stream]) { |
| 1345 | chip->dxs_controls[stream]->vd[0].access |= |
| 1346 | SNDRV_CTL_ELEM_ACCESS_INACTIVE; |
| 1347 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_INFO, |
| 1348 | &chip->dxs_controls[stream]->id); |
| 1349 | } |
| 1350 | return snd_via82xx_pcm_close(substream); |
| 1351 | } |
| 1352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | |
| 1354 | /* via686 playback callbacks */ |
Julia Lawall | 6769e988 | 2016-09-02 00:13:10 +0200 | [diff] [blame] | 1355 | static const struct snd_pcm_ops snd_via686_playback_ops = { |
Clemens Ladisch | 3d00941 | 2009-10-22 09:04:09 +0200 | [diff] [blame] | 1356 | .open = snd_via686_playback_open, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | .close = snd_via82xx_pcm_close, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | .hw_params = snd_via82xx_hw_params, |
| 1359 | .hw_free = snd_via82xx_hw_free, |
| 1360 | .prepare = snd_via686_playback_prepare, |
| 1361 | .trigger = snd_via82xx_pcm_trigger, |
| 1362 | .pointer = snd_via686_pcm_pointer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | }; |
| 1364 | |
| 1365 | /* via686 capture callbacks */ |
Julia Lawall | 6769e988 | 2016-09-02 00:13:10 +0200 | [diff] [blame] | 1366 | static const struct snd_pcm_ops snd_via686_capture_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | .open = snd_via82xx_capture_open, |
| 1368 | .close = snd_via82xx_pcm_close, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | .hw_params = snd_via82xx_hw_params, |
| 1370 | .hw_free = snd_via82xx_hw_free, |
| 1371 | .prepare = snd_via686_capture_prepare, |
| 1372 | .trigger = snd_via82xx_pcm_trigger, |
| 1373 | .pointer = snd_via686_pcm_pointer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | }; |
| 1375 | |
| 1376 | /* via823x DSX playback callbacks */ |
Julia Lawall | 6769e988 | 2016-09-02 00:13:10 +0200 | [diff] [blame] | 1377 | static const struct snd_pcm_ops snd_via8233_playback_ops = { |
Clemens Ladisch | 3d00941 | 2009-10-22 09:04:09 +0200 | [diff] [blame] | 1378 | .open = snd_via8233_playback_open, |
| 1379 | .close = snd_via8233_playback_close, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | .hw_params = snd_via82xx_hw_params, |
| 1381 | .hw_free = snd_via82xx_hw_free, |
| 1382 | .prepare = snd_via8233_playback_prepare, |
| 1383 | .trigger = snd_via82xx_pcm_trigger, |
| 1384 | .pointer = snd_via8233_pcm_pointer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | }; |
| 1386 | |
| 1387 | /* via823x multi-channel playback callbacks */ |
Julia Lawall | 6769e988 | 2016-09-02 00:13:10 +0200 | [diff] [blame] | 1388 | static const struct snd_pcm_ops snd_via8233_multi_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | .open = snd_via8233_multi_open, |
| 1390 | .close = snd_via82xx_pcm_close, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | .hw_params = snd_via82xx_hw_params, |
| 1392 | .hw_free = snd_via82xx_hw_free, |
| 1393 | .prepare = snd_via8233_multi_prepare, |
| 1394 | .trigger = snd_via82xx_pcm_trigger, |
| 1395 | .pointer = snd_via8233_pcm_pointer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | }; |
| 1397 | |
| 1398 | /* via823x capture callbacks */ |
Julia Lawall | 6769e988 | 2016-09-02 00:13:10 +0200 | [diff] [blame] | 1399 | static const struct snd_pcm_ops snd_via8233_capture_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | .open = snd_via82xx_capture_open, |
| 1401 | .close = snd_via82xx_pcm_close, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | .hw_params = snd_via82xx_hw_params, |
| 1403 | .hw_free = snd_via82xx_hw_free, |
| 1404 | .prepare = snd_via8233_capture_prepare, |
| 1405 | .trigger = snd_via82xx_pcm_trigger, |
| 1406 | .pointer = snd_via8233_pcm_pointer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | }; |
| 1408 | |
| 1409 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1410 | static void init_viadev(struct via82xx *chip, int idx, unsigned int reg_offset, |
| 1411 | int shadow_pos, int direction) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | { |
| 1413 | chip->devs[idx].reg_offset = reg_offset; |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 1414 | chip->devs[idx].shadow_shift = shadow_pos * 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | chip->devs[idx].direction = direction; |
| 1416 | chip->devs[idx].port = chip->port + reg_offset; |
| 1417 | } |
| 1418 | |
| 1419 | /* |
| 1420 | * create pcm instances for VIA8233, 8233C and 8235 (not 8233A) |
| 1421 | */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1422 | static int snd_via8233_pcm_new(struct via82xx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1424 | struct snd_pcm *pcm; |
Takashi Iwai | e36e3b8 | 2012-08-03 18:01:40 +0200 | [diff] [blame] | 1425 | struct snd_pcm_chmap *chmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | int i, err; |
| 1427 | |
| 1428 | chip->playback_devno = 0; /* x 4 */ |
| 1429 | chip->multi_devno = 4; /* x 1 */ |
| 1430 | chip->capture_devno = 5; /* x 2 */ |
| 1431 | chip->num_devs = 7; |
| 1432 | chip->intr_mask = 0x33033333; /* FLAG|EOL for rec0-1, mc, sdx0-3 */ |
| 1433 | |
| 1434 | /* PCM #0: 4 DSX playbacks and 1 capture */ |
| 1435 | err = snd_pcm_new(chip->card, chip->card->shortname, 0, 4, 1, &pcm); |
| 1436 | if (err < 0) |
| 1437 | return err; |
| 1438 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_playback_ops); |
| 1439 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via8233_capture_ops); |
| 1440 | pcm->private_data = chip; |
| 1441 | strcpy(pcm->name, chip->card->shortname); |
| 1442 | chip->pcms[0] = pcm; |
| 1443 | /* set up playbacks */ |
| 1444 | for (i = 0; i < 4; i++) |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 1445 | init_viadev(chip, i, 0x10 * i, i, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | /* capture */ |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 1447 | init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | |
Takashi Iwai | 8e2c752 | 2019-12-09 10:49:27 +0100 | [diff] [blame] | 1449 | snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_SG, |
| 1450 | &chip->pci->dev, |
| 1451 | 64*1024, VIA_MAX_BUFSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | |
Takashi Iwai | e36e3b8 | 2012-08-03 18:01:40 +0200 | [diff] [blame] | 1453 | err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 1454 | snd_pcm_std_chmaps, 2, 0, |
| 1455 | &chmap); |
| 1456 | if (err < 0) |
| 1457 | return err; |
| 1458 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | /* PCM #1: multi-channel playback and 2nd capture */ |
| 1460 | err = snd_pcm_new(chip->card, chip->card->shortname, 1, 1, 1, &pcm); |
| 1461 | if (err < 0) |
| 1462 | return err; |
| 1463 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_multi_ops); |
| 1464 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via8233_capture_ops); |
| 1465 | pcm->private_data = chip; |
| 1466 | strcpy(pcm->name, chip->card->shortname); |
| 1467 | chip->pcms[1] = pcm; |
| 1468 | /* set up playback */ |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 1469 | init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 4, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | /* set up capture */ |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 1471 | init_viadev(chip, chip->capture_devno + 1, VIA_REG_CAPTURE_8233_STATUS + 0x10, 7, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | |
Takashi Iwai | 8e2c752 | 2019-12-09 10:49:27 +0100 | [diff] [blame] | 1473 | snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_SG, |
| 1474 | &chip->pci->dev, |
| 1475 | 64*1024, VIA_MAX_BUFSIZE); |
Takashi Iwai | e36e3b8 | 2012-08-03 18:01:40 +0200 | [diff] [blame] | 1476 | |
| 1477 | err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 1478 | snd_pcm_alt_chmaps, 6, 0, |
| 1479 | &chmap); |
| 1480 | if (err < 0) |
| 1481 | return err; |
| 1482 | chip->ac97->chmaps[SNDRV_PCM_STREAM_PLAYBACK] = chmap; |
| 1483 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | return 0; |
| 1485 | } |
| 1486 | |
| 1487 | /* |
| 1488 | * create pcm instances for VIA8233A |
| 1489 | */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1490 | static int snd_via8233a_pcm_new(struct via82xx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1492 | struct snd_pcm *pcm; |
Takashi Iwai | e36e3b8 | 2012-08-03 18:01:40 +0200 | [diff] [blame] | 1493 | struct snd_pcm_chmap *chmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | int err; |
| 1495 | |
| 1496 | chip->multi_devno = 0; |
| 1497 | chip->playback_devno = 1; |
| 1498 | chip->capture_devno = 2; |
| 1499 | chip->num_devs = 3; |
| 1500 | chip->intr_mask = 0x03033000; /* FLAG|EOL for rec0, mc, sdx3 */ |
| 1501 | |
| 1502 | /* PCM #0: multi-channel playback and capture */ |
| 1503 | err = snd_pcm_new(chip->card, chip->card->shortname, 0, 1, 1, &pcm); |
| 1504 | if (err < 0) |
| 1505 | return err; |
| 1506 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_multi_ops); |
| 1507 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via8233_capture_ops); |
| 1508 | pcm->private_data = chip; |
| 1509 | strcpy(pcm->name, chip->card->shortname); |
| 1510 | chip->pcms[0] = pcm; |
| 1511 | /* set up playback */ |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 1512 | init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 4, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | /* capture */ |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 1514 | init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | |
Takashi Iwai | 8e2c752 | 2019-12-09 10:49:27 +0100 | [diff] [blame] | 1516 | snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_SG, |
| 1517 | &chip->pci->dev, |
| 1518 | 64*1024, VIA_MAX_BUFSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | |
Takashi Iwai | e36e3b8 | 2012-08-03 18:01:40 +0200 | [diff] [blame] | 1520 | err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 1521 | snd_pcm_alt_chmaps, 6, 0, |
| 1522 | &chmap); |
| 1523 | if (err < 0) |
| 1524 | return err; |
| 1525 | chip->ac97->chmaps[SNDRV_PCM_STREAM_PLAYBACK] = chmap; |
| 1526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | /* SPDIF supported? */ |
| 1528 | if (! ac97_can_spdif(chip->ac97)) |
| 1529 | return 0; |
| 1530 | |
| 1531 | /* PCM #1: DXS3 playback (for spdif) */ |
| 1532 | err = snd_pcm_new(chip->card, chip->card->shortname, 1, 1, 0, &pcm); |
| 1533 | if (err < 0) |
| 1534 | return err; |
| 1535 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_playback_ops); |
| 1536 | pcm->private_data = chip; |
| 1537 | strcpy(pcm->name, chip->card->shortname); |
| 1538 | chip->pcms[1] = pcm; |
| 1539 | /* set up playback */ |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 1540 | init_viadev(chip, chip->playback_devno, 0x30, 3, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | |
Takashi Iwai | 8e2c752 | 2019-12-09 10:49:27 +0100 | [diff] [blame] | 1542 | snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_SG, |
| 1543 | &chip->pci->dev, |
| 1544 | 64*1024, VIA_MAX_BUFSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | return 0; |
| 1546 | } |
| 1547 | |
| 1548 | /* |
| 1549 | * create a pcm instance for via686a/b |
| 1550 | */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1551 | static int snd_via686_pcm_new(struct via82xx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1553 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | int err; |
| 1555 | |
| 1556 | chip->playback_devno = 0; |
| 1557 | chip->capture_devno = 1; |
| 1558 | chip->num_devs = 2; |
| 1559 | chip->intr_mask = 0x77; /* FLAG | EOL for PB, CP, FM */ |
| 1560 | |
| 1561 | err = snd_pcm_new(chip->card, chip->card->shortname, 0, 1, 1, &pcm); |
| 1562 | if (err < 0) |
| 1563 | return err; |
| 1564 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via686_playback_ops); |
| 1565 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via686_capture_ops); |
| 1566 | pcm->private_data = chip; |
| 1567 | strcpy(pcm->name, chip->card->shortname); |
| 1568 | chip->pcms[0] = pcm; |
Karsten Wiese | 4f550df | 2005-10-18 14:31:07 +0200 | [diff] [blame] | 1569 | init_viadev(chip, 0, VIA_REG_PLAYBACK_STATUS, 0, 0); |
| 1570 | init_viadev(chip, 1, VIA_REG_CAPTURE_STATUS, 0, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | |
Takashi Iwai | 8e2c752 | 2019-12-09 10:49:27 +0100 | [diff] [blame] | 1572 | snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_SG, |
| 1573 | &chip->pci->dev, |
| 1574 | 64*1024, VIA_MAX_BUFSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | return 0; |
| 1576 | } |
| 1577 | |
| 1578 | |
| 1579 | /* |
| 1580 | * Mixer part |
| 1581 | */ |
| 1582 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1583 | static int snd_via8233_capture_source_info(struct snd_kcontrol *kcontrol, |
| 1584 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | { |
| 1586 | /* formerly they were "Line" and "Mic", but it looks like that they |
| 1587 | * have nothing to do with the actual physical connections... |
| 1588 | */ |
Takashi Iwai | 9883ab9 | 2014-10-20 18:20:18 +0200 | [diff] [blame] | 1589 | static const char * const texts[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | "Input1", "Input2" |
| 1591 | }; |
Takashi Iwai | 9883ab9 | 2014-10-20 18:20:18 +0200 | [diff] [blame] | 1592 | return snd_ctl_enum_info(uinfo, 1, 2, texts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | } |
| 1594 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1595 | static int snd_via8233_capture_source_get(struct snd_kcontrol *kcontrol, |
| 1596 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1598 | struct via82xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | unsigned long port = chip->port + (kcontrol->id.index ? (VIA_REG_CAPTURE_CHANNEL + 0x10) : VIA_REG_CAPTURE_CHANNEL); |
| 1600 | ucontrol->value.enumerated.item[0] = inb(port) & VIA_REG_CAPTURE_CHANNEL_MIC ? 1 : 0; |
| 1601 | return 0; |
| 1602 | } |
| 1603 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1604 | static int snd_via8233_capture_source_put(struct snd_kcontrol *kcontrol, |
| 1605 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1607 | struct via82xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | unsigned long port = chip->port + (kcontrol->id.index ? (VIA_REG_CAPTURE_CHANNEL + 0x10) : VIA_REG_CAPTURE_CHANNEL); |
| 1609 | u8 val, oval; |
| 1610 | |
| 1611 | spin_lock_irq(&chip->reg_lock); |
| 1612 | oval = inb(port); |
| 1613 | val = oval & ~VIA_REG_CAPTURE_CHANNEL_MIC; |
| 1614 | if (ucontrol->value.enumerated.item[0]) |
| 1615 | val |= VIA_REG_CAPTURE_CHANNEL_MIC; |
| 1616 | if (val != oval) |
| 1617 | outb(val, port); |
| 1618 | spin_unlock_irq(&chip->reg_lock); |
| 1619 | return val != oval; |
| 1620 | } |
| 1621 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1622 | static struct snd_kcontrol_new snd_via8233_capture_source = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | .name = "Input Source Select", |
| 1624 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1625 | .info = snd_via8233_capture_source_info, |
| 1626 | .get = snd_via8233_capture_source_get, |
| 1627 | .put = snd_via8233_capture_source_put, |
| 1628 | }; |
| 1629 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 1630 | #define snd_via8233_dxs3_spdif_info snd_ctl_boolean_mono_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1632 | static int snd_via8233_dxs3_spdif_get(struct snd_kcontrol *kcontrol, |
| 1633 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1635 | struct via82xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | u8 val; |
| 1637 | |
| 1638 | pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &val); |
| 1639 | ucontrol->value.integer.value[0] = (val & VIA8233_SPDIF_DX3) ? 1 : 0; |
| 1640 | return 0; |
| 1641 | } |
| 1642 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1643 | static int snd_via8233_dxs3_spdif_put(struct snd_kcontrol *kcontrol, |
| 1644 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1646 | struct via82xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | u8 val, oval; |
| 1648 | |
| 1649 | pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &oval); |
| 1650 | val = oval & ~VIA8233_SPDIF_DX3; |
| 1651 | if (ucontrol->value.integer.value[0]) |
| 1652 | val |= VIA8233_SPDIF_DX3; |
| 1653 | /* save the spdif flag for rate filtering */ |
| 1654 | chip->spdif_on = ucontrol->value.integer.value[0] ? 1 : 0; |
| 1655 | if (val != oval) { |
| 1656 | pci_write_config_byte(chip->pci, VIA8233_SPDIF_CTRL, val); |
| 1657 | return 1; |
| 1658 | } |
| 1659 | return 0; |
| 1660 | } |
| 1661 | |
Bhumika Goyal | f3b827e | 2017-02-20 00:18:09 +0530 | [diff] [blame] | 1662 | static const struct snd_kcontrol_new snd_via8233_dxs3_spdif_control = { |
Clemens Ladisch | 10e8d78 | 2005-08-03 13:40:08 +0200 | [diff] [blame] | 1663 | .name = SNDRV_CTL_NAME_IEC958("Output ",NONE,SWITCH), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1665 | .info = snd_via8233_dxs3_spdif_info, |
| 1666 | .get = snd_via8233_dxs3_spdif_get, |
| 1667 | .put = snd_via8233_dxs3_spdif_put, |
| 1668 | }; |
| 1669 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1670 | static int snd_via8233_dxs_volume_info(struct snd_kcontrol *kcontrol, |
| 1671 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | { |
| 1673 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1674 | uinfo->count = 2; |
| 1675 | uinfo->value.integer.min = 0; |
| 1676 | uinfo->value.integer.max = VIA_DXS_MAX_VOLUME; |
| 1677 | return 0; |
| 1678 | } |
| 1679 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1680 | static int snd_via8233_dxs_volume_get(struct snd_kcontrol *kcontrol, |
| 1681 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1683 | struct via82xx *chip = snd_kcontrol_chip(kcontrol); |
Clemens Ladisch | 2fb930b | 2009-10-06 08:21:04 +0200 | [diff] [blame] | 1684 | unsigned int idx = kcontrol->id.subdevice; |
Honza Maly | 00f226d | 2005-10-14 18:18:01 +0200 | [diff] [blame] | 1685 | |
| 1686 | ucontrol->value.integer.value[0] = VIA_DXS_MAX_VOLUME - chip->playback_volume[idx][0]; |
| 1687 | ucontrol->value.integer.value[1] = VIA_DXS_MAX_VOLUME - chip->playback_volume[idx][1]; |
| 1688 | return 0; |
| 1689 | } |
| 1690 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1691 | static int snd_via8233_pcmdxs_volume_get(struct snd_kcontrol *kcontrol, |
| 1692 | struct snd_ctl_elem_value *ucontrol) |
Honza Maly | 00f226d | 2005-10-14 18:18:01 +0200 | [diff] [blame] | 1693 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1694 | struct via82xx *chip = snd_kcontrol_chip(kcontrol); |
Honza Maly | 00f226d | 2005-10-14 18:18:01 +0200 | [diff] [blame] | 1695 | ucontrol->value.integer.value[0] = VIA_DXS_MAX_VOLUME - chip->playback_volume_c[0]; |
| 1696 | ucontrol->value.integer.value[1] = VIA_DXS_MAX_VOLUME - chip->playback_volume_c[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | return 0; |
| 1698 | } |
| 1699 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1700 | static int snd_via8233_dxs_volume_put(struct snd_kcontrol *kcontrol, |
| 1701 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1703 | struct via82xx *chip = snd_kcontrol_chip(kcontrol); |
Clemens Ladisch | 2fb930b | 2009-10-06 08:21:04 +0200 | [diff] [blame] | 1704 | unsigned int idx = kcontrol->id.subdevice; |
Honza Maly | 00f226d | 2005-10-14 18:18:01 +0200 | [diff] [blame] | 1705 | unsigned long port = chip->port + 0x10 * idx; |
| 1706 | unsigned char val; |
| 1707 | int i, change = 0; |
| 1708 | |
| 1709 | for (i = 0; i < 2; i++) { |
| 1710 | val = ucontrol->value.integer.value[i]; |
| 1711 | if (val > VIA_DXS_MAX_VOLUME) |
| 1712 | val = VIA_DXS_MAX_VOLUME; |
| 1713 | val = VIA_DXS_MAX_VOLUME - val; |
| 1714 | change |= val != chip->playback_volume[idx][i]; |
| 1715 | if (change) { |
| 1716 | chip->playback_volume[idx][i] = val; |
| 1717 | outb(val, port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i); |
| 1718 | } |
| 1719 | } |
| 1720 | return change; |
| 1721 | } |
| 1722 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1723 | static int snd_via8233_pcmdxs_volume_put(struct snd_kcontrol *kcontrol, |
| 1724 | struct snd_ctl_elem_value *ucontrol) |
Honza Maly | 00f226d | 2005-10-14 18:18:01 +0200 | [diff] [blame] | 1725 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1726 | struct via82xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | unsigned int idx; |
| 1728 | unsigned char val; |
| 1729 | int i, change = 0; |
| 1730 | |
| 1731 | for (i = 0; i < 2; i++) { |
| 1732 | val = ucontrol->value.integer.value[i]; |
| 1733 | if (val > VIA_DXS_MAX_VOLUME) |
| 1734 | val = VIA_DXS_MAX_VOLUME; |
| 1735 | val = VIA_DXS_MAX_VOLUME - val; |
Honza Maly | 00f226d | 2005-10-14 18:18:01 +0200 | [diff] [blame] | 1736 | if (val != chip->playback_volume_c[i]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | change = 1; |
Honza Maly | 00f226d | 2005-10-14 18:18:01 +0200 | [diff] [blame] | 1738 | chip->playback_volume_c[i] = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | for (idx = 0; idx < 4; idx++) { |
| 1740 | unsigned long port = chip->port + 0x10 * idx; |
Honza Maly | 00f226d | 2005-10-14 18:18:01 +0200 | [diff] [blame] | 1741 | chip->playback_volume[idx][i] = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | outb(val, port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i); |
| 1743 | } |
| 1744 | } |
| 1745 | } |
| 1746 | return change; |
| 1747 | } |
| 1748 | |
Clemens Ladisch | b452e08 | 2009-05-05 15:40:12 +0200 | [diff] [blame] | 1749 | static const DECLARE_TLV_DB_SCALE(db_scale_dxs, -4650, 150, 1); |
Takashi Iwai | 7058c04 | 2006-08-21 18:44:54 +0200 | [diff] [blame] | 1750 | |
Bhumika Goyal | f3b827e | 2017-02-20 00:18:09 +0530 | [diff] [blame] | 1751 | static const struct snd_kcontrol_new snd_via8233_pcmdxs_volume_control = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | .name = "PCM Playback Volume", |
| 1753 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Takashi Iwai | 7058c04 | 2006-08-21 18:44:54 +0200 | [diff] [blame] | 1754 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 1755 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | .info = snd_via8233_dxs_volume_info, |
Honza Maly | 00f226d | 2005-10-14 18:18:01 +0200 | [diff] [blame] | 1757 | .get = snd_via8233_pcmdxs_volume_get, |
| 1758 | .put = snd_via8233_pcmdxs_volume_put, |
Takashi Iwai | 7058c04 | 2006-08-21 18:44:54 +0200 | [diff] [blame] | 1759 | .tlv = { .p = db_scale_dxs } |
Honza Maly | 00f226d | 2005-10-14 18:18:01 +0200 | [diff] [blame] | 1760 | }; |
| 1761 | |
Bhumika Goyal | f3b827e | 2017-02-20 00:18:09 +0530 | [diff] [blame] | 1762 | static const struct snd_kcontrol_new snd_via8233_dxs_volume_control = { |
Clemens Ladisch | 2fb930b | 2009-10-06 08:21:04 +0200 | [diff] [blame] | 1763 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 1764 | .device = 0, |
| 1765 | /* .subdevice set later */ |
| 1766 | .name = "PCM Playback Volume", |
Clemens Ladisch | 3d00941 | 2009-10-22 09:04:09 +0200 | [diff] [blame] | 1767 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 1768 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | |
| 1769 | SNDRV_CTL_ELEM_ACCESS_INACTIVE, |
Honza Maly | 00f226d | 2005-10-14 18:18:01 +0200 | [diff] [blame] | 1770 | .info = snd_via8233_dxs_volume_info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | .get = snd_via8233_dxs_volume_get, |
| 1772 | .put = snd_via8233_dxs_volume_put, |
Takashi Iwai | 7058c04 | 2006-08-21 18:44:54 +0200 | [diff] [blame] | 1773 | .tlv = { .p = db_scale_dxs } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | }; |
| 1775 | |
| 1776 | /* |
| 1777 | */ |
| 1778 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1779 | static void snd_via82xx_mixer_free_ac97_bus(struct snd_ac97_bus *bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1781 | struct via82xx *chip = bus->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | chip->ac97_bus = NULL; |
| 1783 | } |
| 1784 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1785 | static void snd_via82xx_mixer_free_ac97(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1787 | struct via82xx *chip = ac97->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | chip->ac97 = NULL; |
| 1789 | } |
| 1790 | |
Joe Perches | eab0fbf | 2015-04-04 13:38:25 -0700 | [diff] [blame] | 1791 | static const struct ac97_quirk ac97_quirks[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | { |
Jaroslav Kysela | 69ad07c | 2005-05-30 14:48:16 +0200 | [diff] [blame] | 1793 | .subvendor = 0x1106, |
| 1794 | .subdevice = 0x4161, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | .codec_id = 0x56494161, /* VT1612A */ |
| 1796 | .name = "Soltek SL-75DRV5", |
| 1797 | .type = AC97_TUNE_NONE |
| 1798 | }, |
| 1799 | { /* FIXME: which codec? */ |
Jaroslav Kysela | 69ad07c | 2005-05-30 14:48:16 +0200 | [diff] [blame] | 1800 | .subvendor = 0x1106, |
| 1801 | .subdevice = 0x4161, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | .name = "ASRock K7VT2", |
| 1803 | .type = AC97_TUNE_HP_ONLY |
| 1804 | }, |
| 1805 | { |
Clemens Ladisch | bf30a43 | 2010-02-22 10:33:13 +0100 | [diff] [blame] | 1806 | .subvendor = 0x110a, |
| 1807 | .subdevice = 0x0079, |
| 1808 | .name = "Fujitsu Siemens D1289", |
| 1809 | .type = AC97_TUNE_HP_ONLY |
| 1810 | }, |
| 1811 | { |
Jaroslav Kysela | 69ad07c | 2005-05-30 14:48:16 +0200 | [diff] [blame] | 1812 | .subvendor = 0x1019, |
| 1813 | .subdevice = 0x0a81, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | .name = "ECS K7VTA3", |
| 1815 | .type = AC97_TUNE_HP_ONLY |
| 1816 | }, |
| 1817 | { |
Jaroslav Kysela | 69ad07c | 2005-05-30 14:48:16 +0200 | [diff] [blame] | 1818 | .subvendor = 0x1019, |
| 1819 | .subdevice = 0x0a85, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | .name = "ECS L7VMM2", |
| 1821 | .type = AC97_TUNE_HP_ONLY |
| 1822 | }, |
| 1823 | { |
Walter Sheets | 942fd1e | 2008-06-27 11:53:31 +0200 | [diff] [blame] | 1824 | .subvendor = 0x1019, |
| 1825 | .subdevice = 0x1841, |
| 1826 | .name = "ECS K7VTA3", |
| 1827 | .type = AC97_TUNE_HP_ONLY |
| 1828 | }, |
| 1829 | { |
Jaroslav Kysela | 69ad07c | 2005-05-30 14:48:16 +0200 | [diff] [blame] | 1830 | .subvendor = 0x1849, |
| 1831 | .subdevice = 0x3059, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | .name = "ASRock K7VM2", |
| 1833 | .type = AC97_TUNE_HP_ONLY /* VT1616 */ |
| 1834 | }, |
| 1835 | { |
Jaroslav Kysela | 69ad07c | 2005-05-30 14:48:16 +0200 | [diff] [blame] | 1836 | .subvendor = 0x14cd, |
| 1837 | .subdevice = 0x7002, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | .name = "Unknown", |
| 1839 | .type = AC97_TUNE_ALC_JACK |
| 1840 | }, |
| 1841 | { |
Jaroslav Kysela | 69ad07c | 2005-05-30 14:48:16 +0200 | [diff] [blame] | 1842 | .subvendor = 0x1071, |
| 1843 | .subdevice = 0x8590, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | .name = "Mitac Mobo", |
| 1845 | .type = AC97_TUNE_ALC_JACK |
| 1846 | }, |
| 1847 | { |
Jaroslav Kysela | 69ad07c | 2005-05-30 14:48:16 +0200 | [diff] [blame] | 1848 | .subvendor = 0x161f, |
| 1849 | .subdevice = 0x202b, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | .name = "Arima Notebook", |
| 1851 | .type = AC97_TUNE_HP_ONLY, |
| 1852 | }, |
Takashi Iwai | dac8ddd | 2005-12-14 12:00:46 +0100 | [diff] [blame] | 1853 | { |
| 1854 | .subvendor = 0x161f, |
| 1855 | .subdevice = 0x2032, |
| 1856 | .name = "Targa Traveller 811", |
| 1857 | .type = AC97_TUNE_HP_ONLY, |
| 1858 | }, |
Daniel T Chen | d4199f0 | 2006-06-16 16:21:54 +0200 | [diff] [blame] | 1859 | { |
| 1860 | .subvendor = 0x161f, |
| 1861 | .subdevice = 0x2032, |
| 1862 | .name = "m680x", |
| 1863 | .type = AC97_TUNE_HP_ONLY, /* http://launchpad.net/bugs/38546 */ |
| 1864 | }, |
Takashi Iwai | 9674513 | 2007-10-25 11:46:24 +0200 | [diff] [blame] | 1865 | { |
| 1866 | .subvendor = 0x1297, |
| 1867 | .subdevice = 0xa232, |
| 1868 | .name = "Shuttle AK32VN", |
| 1869 | .type = AC97_TUNE_HP_ONLY |
| 1870 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1871 | { } /* terminator */ |
| 1872 | }; |
| 1873 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1874 | static int snd_via82xx_mixer_new(struct via82xx *chip, const char *quirk_override) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1876 | struct snd_ac97_template ac97; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | int err; |
Takashi Iwai | 51055da | 2020-01-03 09:16:43 +0100 | [diff] [blame] | 1878 | static const struct snd_ac97_bus_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | .write = snd_via82xx_codec_write, |
| 1880 | .read = snd_via82xx_codec_read, |
| 1881 | .wait = snd_via82xx_codec_wait, |
| 1882 | }; |
| 1883 | |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 1884 | err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus); |
| 1885 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | return err; |
| 1887 | chip->ac97_bus->private_free = snd_via82xx_mixer_free_ac97_bus; |
| 1888 | chip->ac97_bus->clock = chip->ac97_clock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | |
| 1890 | memset(&ac97, 0, sizeof(ac97)); |
| 1891 | ac97.private_data = chip; |
| 1892 | ac97.private_free = snd_via82xx_mixer_free_ac97; |
| 1893 | ac97.pci = chip->pci; |
Takashi Iwai | f1a63a3 | 2006-10-24 18:25:29 +0200 | [diff] [blame] | 1894 | ac97.scaps = AC97_SCAP_SKIP_MODEM | AC97_SCAP_POWER_SAVE; |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 1895 | err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97); |
| 1896 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | return err; |
| 1898 | |
| 1899 | snd_ac97_tune_hardware(chip->ac97, ac97_quirks, quirk_override); |
| 1900 | |
| 1901 | if (chip->chip_type != TYPE_VIA686) { |
| 1902 | /* use slot 10/11 */ |
| 1903 | snd_ac97_update_bits(chip->ac97, AC97_EXTENDED_STATUS, 0x03 << 4, 0x03 << 4); |
| 1904 | } |
| 1905 | |
| 1906 | return 0; |
| 1907 | } |
| 1908 | |
| 1909 | #ifdef SUPPORT_JOYSTICK |
| 1910 | #define JOYSTICK_ADDR 0x200 |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1911 | static int snd_via686_create_gameport(struct via82xx *chip, unsigned char *legacy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | { |
| 1913 | struct gameport *gp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | |
Clemens Ladisch | b7fe462 | 2005-10-04 08:46:51 +0200 | [diff] [blame] | 1915 | if (!joystick) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | return -ENODEV; |
| 1917 | |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 1918 | if (!devm_request_region(chip->card->dev, JOYSTICK_ADDR, 8, |
| 1919 | "VIA686 gameport")) { |
Takashi Iwai | 59d3acfa | 2014-02-25 15:21:56 +0100 | [diff] [blame] | 1920 | dev_warn(chip->card->dev, "cannot reserve joystick port %#x\n", |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1921 | JOYSTICK_ADDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | return -EBUSY; |
| 1923 | } |
| 1924 | |
| 1925 | chip->gameport = gp = gameport_allocate_port(); |
| 1926 | if (!gp) { |
Takashi Iwai | 59d3acfa | 2014-02-25 15:21:56 +0100 | [diff] [blame] | 1927 | dev_err(chip->card->dev, |
| 1928 | "cannot allocate memory for gameport\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | return -ENOMEM; |
| 1930 | } |
| 1931 | |
| 1932 | gameport_set_name(gp, "VIA686 Gameport"); |
| 1933 | gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci)); |
| 1934 | gameport_set_dev_parent(gp, &chip->pci->dev); |
| 1935 | gp->io = JOYSTICK_ADDR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | |
| 1937 | /* Enable legacy joystick port */ |
| 1938 | *legacy |= VIA_FUNC_ENABLE_GAME; |
| 1939 | pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, *legacy); |
| 1940 | |
| 1941 | gameport_register_port(chip->gameport); |
| 1942 | |
| 1943 | return 0; |
| 1944 | } |
| 1945 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1946 | static void snd_via686_free_gameport(struct via82xx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | { |
| 1948 | if (chip->gameport) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | gameport_unregister_port(chip->gameport); |
| 1950 | chip->gameport = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | } |
| 1952 | } |
| 1953 | #else |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1954 | static inline int snd_via686_create_gameport(struct via82xx *chip, unsigned char *legacy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | { |
| 1956 | return -ENOSYS; |
| 1957 | } |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1958 | static inline void snd_via686_free_gameport(struct via82xx *chip) { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1959 | #endif |
| 1960 | |
| 1961 | |
| 1962 | /* |
| 1963 | * |
| 1964 | */ |
| 1965 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1966 | static int snd_via8233_init_misc(struct via82xx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | { |
| 1968 | int i, err, caps; |
| 1969 | unsigned char val; |
| 1970 | |
| 1971 | caps = chip->chip_type == TYPE_VIA8233A ? 1 : 2; |
| 1972 | for (i = 0; i < caps; i++) { |
| 1973 | snd_via8233_capture_source.index = i; |
| 1974 | err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_capture_source, chip)); |
| 1975 | if (err < 0) |
| 1976 | return err; |
| 1977 | } |
| 1978 | if (ac97_can_spdif(chip->ac97)) { |
| 1979 | err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_dxs3_spdif_control, chip)); |
| 1980 | if (err < 0) |
| 1981 | return err; |
| 1982 | } |
| 1983 | if (chip->chip_type != TYPE_VIA8233A) { |
| 1984 | /* when no h/w PCM volume control is found, use DXS volume control |
| 1985 | * as the PCM vol control |
| 1986 | */ |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 1987 | struct snd_ctl_elem_id sid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | memset(&sid, 0, sizeof(sid)); |
| 1989 | strcpy(sid.name, "PCM Playback Volume"); |
| 1990 | sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 1991 | if (! snd_ctl_find_id(chip->card, &sid)) { |
Takashi Iwai | 59d3acfa | 2014-02-25 15:21:56 +0100 | [diff] [blame] | 1992 | dev_info(chip->card->dev, |
| 1993 | "Using DXS as PCM Playback\n"); |
Honza Maly | 00f226d | 2005-10-14 18:18:01 +0200 | [diff] [blame] | 1994 | err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_pcmdxs_volume_control, chip)); |
| 1995 | if (err < 0) |
| 1996 | return err; |
| 1997 | } |
| 1998 | else /* Using DXS when PCM emulation is enabled is really weird */ |
| 1999 | { |
Clemens Ladisch | 2fb930b | 2009-10-06 08:21:04 +0200 | [diff] [blame] | 2000 | for (i = 0; i < 4; ++i) { |
| 2001 | struct snd_kcontrol *kctl; |
| 2002 | |
| 2003 | kctl = snd_ctl_new1( |
| 2004 | &snd_via8233_dxs_volume_control, chip); |
| 2005 | if (!kctl) |
| 2006 | return -ENOMEM; |
| 2007 | kctl->id.subdevice = i; |
| 2008 | err = snd_ctl_add(chip->card, kctl); |
| 2009 | if (err < 0) |
| 2010 | return err; |
Clemens Ladisch | 3d00941 | 2009-10-22 09:04:09 +0200 | [diff] [blame] | 2011 | chip->dxs_controls[i] = kctl; |
Clemens Ladisch | 2fb930b | 2009-10-06 08:21:04 +0200 | [diff] [blame] | 2012 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | } |
| 2014 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | /* select spdif data slot 10/11 */ |
| 2016 | pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &val); |
| 2017 | val = (val & ~VIA8233_SPDIF_SLOT_MASK) | VIA8233_SPDIF_SLOT_1011; |
| 2018 | val &= ~VIA8233_SPDIF_DX3; /* SPDIF off as default */ |
| 2019 | pci_write_config_byte(chip->pci, VIA8233_SPDIF_CTRL, val); |
| 2020 | |
| 2021 | return 0; |
| 2022 | } |
| 2023 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2024 | static int snd_via686_init_misc(struct via82xx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | { |
| 2026 | unsigned char legacy, legacy_cfg; |
| 2027 | int rev_h = 0; |
| 2028 | |
| 2029 | legacy = chip->old_legacy; |
| 2030 | legacy_cfg = chip->old_legacy_cfg; |
| 2031 | legacy |= VIA_FUNC_MIDI_IRQMASK; /* FIXME: correct? (disable MIDI) */ |
| 2032 | legacy &= ~VIA_FUNC_ENABLE_GAME; /* disable joystick */ |
| 2033 | if (chip->revision >= VIA_REV_686_H) { |
| 2034 | rev_h = 1; |
Clemens Ladisch | b7fe462 | 2005-10-04 08:46:51 +0200 | [diff] [blame] | 2035 | if (mpu_port >= 0x200) { /* force MIDI */ |
| 2036 | mpu_port &= 0xfffc; |
| 2037 | pci_write_config_dword(chip->pci, 0x18, mpu_port | 0x01); |
Takashi Iwai | c7561cd | 2012-08-14 18:12:04 +0200 | [diff] [blame] | 2038 | #ifdef CONFIG_PM_SLEEP |
Clemens Ladisch | b7fe462 | 2005-10-04 08:46:51 +0200 | [diff] [blame] | 2039 | chip->mpu_port_saved = mpu_port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | #endif |
| 2041 | } else { |
Clemens Ladisch | b7fe462 | 2005-10-04 08:46:51 +0200 | [diff] [blame] | 2042 | mpu_port = pci_resource_start(chip->pci, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | } |
| 2044 | } else { |
Clemens Ladisch | b7fe462 | 2005-10-04 08:46:51 +0200 | [diff] [blame] | 2045 | switch (mpu_port) { /* force MIDI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | case 0x300: |
| 2047 | case 0x310: |
| 2048 | case 0x320: |
| 2049 | case 0x330: |
| 2050 | legacy_cfg &= ~(3 << 2); |
Clemens Ladisch | b7fe462 | 2005-10-04 08:46:51 +0200 | [diff] [blame] | 2051 | legacy_cfg |= (mpu_port & 0x0030) >> 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | break; |
| 2053 | default: /* no, use BIOS settings */ |
| 2054 | if (legacy & VIA_FUNC_ENABLE_MIDI) |
Clemens Ladisch | b7fe462 | 2005-10-04 08:46:51 +0200 | [diff] [blame] | 2055 | mpu_port = 0x300 + ((legacy_cfg & 0x000c) << 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | break; |
| 2057 | } |
| 2058 | } |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 2059 | if (mpu_port >= 0x200) |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 2060 | chip->mpu_res = devm_request_region(&chip->pci->dev, mpu_port, |
| 2061 | 2, "VIA82xx MPU401"); |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 2062 | if (chip->mpu_res) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | if (rev_h) |
| 2064 | legacy |= VIA_FUNC_MIDI_PNP; /* enable PCI I/O 2 */ |
| 2065 | legacy |= VIA_FUNC_ENABLE_MIDI; |
| 2066 | } else { |
| 2067 | if (rev_h) |
| 2068 | legacy &= ~VIA_FUNC_MIDI_PNP; /* disable PCI I/O 2 */ |
| 2069 | legacy &= ~VIA_FUNC_ENABLE_MIDI; |
Clemens Ladisch | b7fe462 | 2005-10-04 08:46:51 +0200 | [diff] [blame] | 2070 | mpu_port = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy); |
| 2074 | pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, legacy_cfg); |
| 2075 | if (chip->mpu_res) { |
| 2076 | if (snd_mpu401_uart_new(chip->card, 0, MPU401_HW_VIA686A, |
Clemens Ladisch | dba8b46 | 2011-09-13 11:24:41 +0200 | [diff] [blame] | 2077 | mpu_port, MPU401_INFO_INTEGRATED | |
| 2078 | MPU401_INFO_IRQ_HOOK, -1, |
| 2079 | &chip->rmidi) < 0) { |
Takashi Iwai | 59d3acfa | 2014-02-25 15:21:56 +0100 | [diff] [blame] | 2080 | dev_warn(chip->card->dev, |
| 2081 | "unable to initialize MPU-401 at 0x%lx, skipping\n", |
| 2082 | mpu_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | legacy &= ~VIA_FUNC_ENABLE_MIDI; |
| 2084 | } else { |
| 2085 | legacy &= ~VIA_FUNC_MIDI_IRQMASK; /* enable MIDI interrupt */ |
| 2086 | } |
| 2087 | pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy); |
| 2088 | } |
| 2089 | |
Clemens Ladisch | b7fe462 | 2005-10-04 08:46:51 +0200 | [diff] [blame] | 2090 | snd_via686_create_gameport(chip, &legacy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | |
Takashi Iwai | c7561cd | 2012-08-14 18:12:04 +0200 | [diff] [blame] | 2092 | #ifdef CONFIG_PM_SLEEP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | chip->legacy_saved = legacy; |
| 2094 | chip->legacy_cfg_saved = legacy_cfg; |
| 2095 | #endif |
| 2096 | |
| 2097 | return 0; |
| 2098 | } |
| 2099 | |
| 2100 | |
| 2101 | /* |
| 2102 | * proc interface |
| 2103 | */ |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 2104 | static void snd_via82xx_proc_read(struct snd_info_entry *entry, |
| 2105 | struct snd_info_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2106 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 2107 | struct via82xx *chip = entry->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | int i; |
| 2109 | |
| 2110 | snd_iprintf(buffer, "%s\n\n", chip->card->longname); |
| 2111 | for (i = 0; i < 0xa0; i += 4) { |
| 2112 | snd_iprintf(buffer, "%02x: %08x\n", i, inl(chip->port + i)); |
| 2113 | } |
| 2114 | } |
| 2115 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2116 | static void snd_via82xx_proc_init(struct via82xx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | { |
Takashi Iwai | 47f2769 | 2019-02-04 16:01:39 +0100 | [diff] [blame] | 2118 | snd_card_ro_proc_new(chip->card, "via82xx", chip, |
| 2119 | snd_via82xx_proc_read); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | } |
| 2121 | |
| 2122 | /* |
| 2123 | * |
| 2124 | */ |
| 2125 | |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 2126 | static int snd_via82xx_chip_init(struct via82xx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | { |
| 2128 | unsigned int val; |
Nishanth Aravamudan | ef21ca2 | 2005-07-09 10:13:22 +0200 | [diff] [blame] | 2129 | unsigned long end_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | unsigned char pval; |
| 2131 | |
| 2132 | #if 0 /* broken on K7M? */ |
| 2133 | if (chip->chip_type == TYPE_VIA686) |
| 2134 | /* disable all legacy ports */ |
| 2135 | pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, 0); |
| 2136 | #endif |
| 2137 | pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval); |
| 2138 | if (! (pval & VIA_ACLINK_C00_READY)) { /* codec not ready? */ |
| 2139 | /* deassert ACLink reset, force SYNC */ |
| 2140 | pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL, |
| 2141 | VIA_ACLINK_CTRL_ENABLE | |
| 2142 | VIA_ACLINK_CTRL_RESET | |
| 2143 | VIA_ACLINK_CTRL_SYNC); |
| 2144 | udelay(100); |
| 2145 | #if 1 /* FIXME: should we do full reset here for all chip models? */ |
| 2146 | pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL, 0x00); |
| 2147 | udelay(100); |
| 2148 | #else |
| 2149 | /* deassert ACLink reset, force SYNC (warm AC'97 reset) */ |
| 2150 | pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL, |
| 2151 | VIA_ACLINK_CTRL_RESET|VIA_ACLINK_CTRL_SYNC); |
| 2152 | udelay(2); |
| 2153 | #endif |
| 2154 | /* ACLink on, deassert ACLink reset, VSR, SGD data out */ |
| 2155 | /* note - FM data out has trouble with non VRA codecs !! */ |
| 2156 | pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL, VIA_ACLINK_CTRL_INIT); |
| 2157 | udelay(100); |
| 2158 | } |
| 2159 | |
| 2160 | /* Make sure VRA is enabled, in case we didn't do a |
| 2161 | * complete codec reset, above */ |
| 2162 | pci_read_config_byte(chip->pci, VIA_ACLINK_CTRL, &pval); |
| 2163 | if ((pval & VIA_ACLINK_CTRL_INIT) != VIA_ACLINK_CTRL_INIT) { |
| 2164 | /* ACLink on, deassert ACLink reset, VSR, SGD data out */ |
| 2165 | /* note - FM data out has trouble with non VRA codecs !! */ |
| 2166 | pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL, VIA_ACLINK_CTRL_INIT); |
| 2167 | udelay(100); |
| 2168 | } |
| 2169 | |
| 2170 | /* wait until codec ready */ |
Nishanth Aravamudan | ef21ca2 | 2005-07-09 10:13:22 +0200 | [diff] [blame] | 2171 | end_time = jiffies + msecs_to_jiffies(750); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | do { |
| 2173 | pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval); |
| 2174 | if (pval & VIA_ACLINK_C00_READY) /* primary codec ready */ |
| 2175 | break; |
Rene Herman | d86d019 | 2007-09-18 18:10:49 +0200 | [diff] [blame] | 2176 | schedule_timeout_uninterruptible(1); |
Nishanth Aravamudan | ef21ca2 | 2005-07-09 10:13:22 +0200 | [diff] [blame] | 2177 | } while (time_before(jiffies, end_time)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 2179 | val = snd_via82xx_codec_xread(chip); |
| 2180 | if (val & VIA_REG_AC97_BUSY) |
Takashi Iwai | 59d3acfa | 2014-02-25 15:21:56 +0100 | [diff] [blame] | 2181 | dev_err(chip->card->dev, |
| 2182 | "AC'97 codec is not ready [0x%x]\n", val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | |
| 2184 | #if 0 /* FIXME: we don't support the second codec yet so skip the detection now.. */ |
| 2185 | snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ | |
| 2186 | VIA_REG_AC97_SECONDARY_VALID | |
| 2187 | (VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT)); |
Nishanth Aravamudan | ef21ca2 | 2005-07-09 10:13:22 +0200 | [diff] [blame] | 2188 | end_time = jiffies + msecs_to_jiffies(750); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ | |
| 2190 | VIA_REG_AC97_SECONDARY_VALID | |
| 2191 | (VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT)); |
| 2192 | do { |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 2193 | val = snd_via82xx_codec_xread(chip); |
| 2194 | if (val & VIA_REG_AC97_SECONDARY_VALID) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | chip->ac97_secondary = 1; |
| 2196 | goto __ac97_ok2; |
| 2197 | } |
Rene Herman | d86d019 | 2007-09-18 18:10:49 +0200 | [diff] [blame] | 2198 | schedule_timeout_uninterruptible(1); |
Nishanth Aravamudan | ef21ca2 | 2005-07-09 10:13:22 +0200 | [diff] [blame] | 2199 | } while (time_before(jiffies, end_time)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | /* This is ok, the most of motherboards have only one codec */ |
| 2201 | |
| 2202 | __ac97_ok2: |
| 2203 | #endif |
| 2204 | |
| 2205 | if (chip->chip_type == TYPE_VIA686) { |
| 2206 | /* route FM trap to IRQ, disable FM trap */ |
| 2207 | pci_write_config_byte(chip->pci, VIA_FM_NMI_CTRL, 0); |
| 2208 | /* disable all GPI interrupts */ |
| 2209 | outl(0, VIAREG(chip, GPI_INTR)); |
| 2210 | } |
| 2211 | |
| 2212 | if (chip->chip_type != TYPE_VIA686) { |
| 2213 | /* Workaround for Award BIOS bug: |
| 2214 | * DXS channels don't work properly with VRA if MC97 is disabled. |
| 2215 | */ |
| 2216 | struct pci_dev *pci; |
Jiri Slaby | 0dd119f | 2005-09-07 14:28:33 +0200 | [diff] [blame] | 2217 | pci = pci_get_device(0x1106, 0x3068, NULL); /* MC97 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | if (pci) { |
| 2219 | unsigned char data; |
| 2220 | pci_read_config_byte(pci, 0x44, &data); |
| 2221 | pci_write_config_byte(pci, 0x44, data | 0x40); |
Jiri Slaby | 0dd119f | 2005-09-07 14:28:33 +0200 | [diff] [blame] | 2222 | pci_dev_put(pci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | } |
| 2224 | } |
| 2225 | |
| 2226 | if (chip->chip_type != TYPE_VIA8233A) { |
| 2227 | int i, idx; |
| 2228 | for (idx = 0; idx < 4; idx++) { |
| 2229 | unsigned long port = chip->port + 0x10 * idx; |
Honza Maly | 00f226d | 2005-10-14 18:18:01 +0200 | [diff] [blame] | 2230 | for (i = 0; i < 2; i++) { |
| 2231 | chip->playback_volume[idx][i]=chip->playback_volume_c[i]; |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 2232 | outb(chip->playback_volume_c[i], |
| 2233 | port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i); |
Honza Maly | 00f226d | 2005-10-14 18:18:01 +0200 | [diff] [blame] | 2234 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | } |
| 2236 | } |
| 2237 | |
| 2238 | return 0; |
| 2239 | } |
| 2240 | |
Takashi Iwai | c7561cd | 2012-08-14 18:12:04 +0200 | [diff] [blame] | 2241 | #ifdef CONFIG_PM_SLEEP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | /* |
| 2243 | * power management |
| 2244 | */ |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 2245 | static int snd_via82xx_suspend(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | { |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 2247 | struct snd_card *card = dev_get_drvdata(dev); |
Takashi Iwai | 57feb83 | 2005-11-17 16:10:35 +0100 | [diff] [blame] | 2248 | struct via82xx *chip = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2249 | int i; |
| 2250 | |
Takashi Iwai | 57feb83 | 2005-11-17 16:10:35 +0100 | [diff] [blame] | 2251 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2252 | for (i = 0; i < chip->num_devs; i++) |
| 2253 | snd_via82xx_channel_reset(chip, &chip->devs[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2254 | snd_ac97_suspend(chip->ac97); |
| 2255 | |
| 2256 | /* save misc values */ |
| 2257 | if (chip->chip_type != TYPE_VIA686) { |
| 2258 | pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &chip->spdif_ctrl_saved); |
| 2259 | chip->capture_src_saved[0] = inb(chip->port + VIA_REG_CAPTURE_CHANNEL); |
| 2260 | chip->capture_src_saved[1] = inb(chip->port + VIA_REG_CAPTURE_CHANNEL + 0x10); |
| 2261 | } |
| 2262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 | return 0; |
| 2264 | } |
| 2265 | |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 2266 | static int snd_via82xx_resume(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | { |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 2268 | struct snd_card *card = dev_get_drvdata(dev); |
Takashi Iwai | 57feb83 | 2005-11-17 16:10:35 +0100 | [diff] [blame] | 2269 | struct via82xx *chip = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2270 | int i; |
| 2271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | snd_via82xx_chip_init(chip); |
| 2273 | |
| 2274 | if (chip->chip_type == TYPE_VIA686) { |
| 2275 | if (chip->mpu_port_saved) |
| 2276 | pci_write_config_dword(chip->pci, 0x18, chip->mpu_port_saved | 0x01); |
| 2277 | pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, chip->legacy_saved); |
| 2278 | pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, chip->legacy_cfg_saved); |
| 2279 | } else { |
| 2280 | pci_write_config_byte(chip->pci, VIA8233_SPDIF_CTRL, chip->spdif_ctrl_saved); |
| 2281 | outb(chip->capture_src_saved[0], chip->port + VIA_REG_CAPTURE_CHANNEL); |
| 2282 | outb(chip->capture_src_saved[1], chip->port + VIA_REG_CAPTURE_CHANNEL + 0x10); |
| 2283 | } |
| 2284 | |
| 2285 | snd_ac97_resume(chip->ac97); |
| 2286 | |
| 2287 | for (i = 0; i < chip->num_devs; i++) |
| 2288 | snd_via82xx_channel_reset(chip, &chip->devs[i]); |
| 2289 | |
Takashi Iwai | 57feb83 | 2005-11-17 16:10:35 +0100 | [diff] [blame] | 2290 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | return 0; |
| 2292 | } |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 2293 | |
| 2294 | static SIMPLE_DEV_PM_OPS(snd_via82xx_pm, snd_via82xx_suspend, snd_via82xx_resume); |
| 2295 | #define SND_VIA82XX_PM_OPS &snd_via82xx_pm |
| 2296 | #else |
| 2297 | #define SND_VIA82XX_PM_OPS NULL |
Takashi Iwai | c7561cd | 2012-08-14 18:12:04 +0200 | [diff] [blame] | 2298 | #endif /* CONFIG_PM_SLEEP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 2300 | static void snd_via82xx_free(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | { |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 2302 | struct via82xx *chip = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | unsigned int i; |
| 2304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2305 | /* disable interrupts */ |
| 2306 | for (i = 0; i < chip->num_devs; i++) |
| 2307 | snd_via82xx_channel_reset(chip, &chip->devs[i]); |
Jeff Garzik | f000fd8 | 2008-04-22 13:50:34 +0200 | [diff] [blame] | 2308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | if (chip->chip_type == TYPE_VIA686) { |
| 2310 | snd_via686_free_gameport(chip); |
| 2311 | pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, chip->old_legacy); |
| 2312 | pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, chip->old_legacy_cfg); |
| 2313 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2316 | static int snd_via82xx_create(struct snd_card *card, |
| 2317 | struct pci_dev *pci, |
| 2318 | int chip_type, |
| 2319 | int revision, |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 2320 | unsigned int ac97_clock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2321 | { |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 2322 | struct via82xx *chip = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 2325 | err = pcim_enable_device(pci); |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 2326 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | return err; |
| 2328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2329 | chip->chip_type = chip_type; |
| 2330 | chip->revision = revision; |
| 2331 | |
| 2332 | spin_lock_init(&chip->reg_lock); |
| 2333 | spin_lock_init(&chip->rates[0].lock); |
| 2334 | spin_lock_init(&chip->rates[1].lock); |
| 2335 | chip->card = card; |
| 2336 | chip->pci = pci; |
| 2337 | chip->irq = -1; |
| 2338 | |
| 2339 | pci_read_config_byte(pci, VIA_FUNC_ENABLE, &chip->old_legacy); |
| 2340 | pci_read_config_byte(pci, VIA_PNP_CONTROL, &chip->old_legacy_cfg); |
| 2341 | pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, |
| 2342 | chip->old_legacy & ~(VIA_FUNC_ENABLE_SB|VIA_FUNC_ENABLE_FM)); |
| 2343 | |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 2344 | err = pci_request_regions(pci, card->driver); |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 2345 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | chip->port = pci_resource_start(pci, 0); |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 2348 | if (devm_request_irq(&pci->dev, pci->irq, |
| 2349 | chip_type == TYPE_VIA8233 ? |
| 2350 | snd_via8233_interrupt : snd_via686_interrupt, |
| 2351 | IRQF_SHARED, |
| 2352 | KBUILD_MODNAME, chip)) { |
Takashi Iwai | 59d3acfa | 2014-02-25 15:21:56 +0100 | [diff] [blame] | 2353 | dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2354 | return -EBUSY; |
| 2355 | } |
| 2356 | chip->irq = pci->irq; |
Takashi Iwai | c47583b | 2019-12-10 07:34:36 +0100 | [diff] [blame] | 2357 | card->sync_irq = chip->irq; |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 2358 | card->private_free = snd_via82xx_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2359 | if (ac97_clock >= 8000 && ac97_clock <= 48000) |
| 2360 | chip->ac97_clock = ac97_clock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 2362 | err = snd_via82xx_chip_init(chip); |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 2363 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | |
| 2366 | /* The 8233 ac97 controller does not implement the master bit |
| 2367 | * in the pci command register. IMHO this is a violation of the PCI spec. |
| 2368 | * We call pci_set_master here because it does not hurt. */ |
| 2369 | pci_set_master(pci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2370 | return 0; |
| 2371 | } |
| 2372 | |
| 2373 | struct via823x_info { |
| 2374 | int revision; |
| 2375 | char *name; |
| 2376 | int type; |
| 2377 | }; |
Takashi Iwai | a05c073 | 2020-01-05 15:48:20 +0100 | [diff] [blame] | 2378 | static const struct via823x_info via823x_cards[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | { VIA_REV_PRE_8233, "VIA 8233-Pre", TYPE_VIA8233 }, |
| 2380 | { VIA_REV_8233C, "VIA 8233C", TYPE_VIA8233 }, |
| 2381 | { VIA_REV_8233, "VIA 8233", TYPE_VIA8233 }, |
| 2382 | { VIA_REV_8233A, "VIA 8233A", TYPE_VIA8233A }, |
| 2383 | { VIA_REV_8235, "VIA 8235", TYPE_VIA8233 }, |
| 2384 | { VIA_REV_8237, "VIA 8237", TYPE_VIA8233 }, |
Bastiaan Jacques | 8263c65 | 2006-04-18 17:04:04 +0200 | [diff] [blame] | 2385 | { VIA_REV_8251, "VIA 8251", TYPE_VIA8233 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | }; |
| 2387 | |
| 2388 | /* |
| 2389 | * auto detection of DXS channel supports. |
| 2390 | */ |
Takashi Iwai | 9d74958 | 2006-11-24 15:37:18 +0100 | [diff] [blame] | 2391 | |
Takashi Iwai | 21641672 | 2020-07-14 19:26:30 +0200 | [diff] [blame] | 2392 | static const struct snd_pci_quirk dxs_allowlist[] = { |
Takashi Iwai | 9d74958 | 2006-11-24 15:37:18 +0100 | [diff] [blame] | 2393 | SND_PCI_QUIRK(0x1005, 0x4710, "Avance Logic Mobo", VIA_DXS_ENABLE), |
| 2394 | SND_PCI_QUIRK(0x1019, 0x0996, "ESC Mobo", VIA_DXS_48K), |
| 2395 | SND_PCI_QUIRK(0x1019, 0x0a81, "ECS K7VTA3 v8.0", VIA_DXS_NO_VRA), |
| 2396 | SND_PCI_QUIRK(0x1019, 0x0a85, "ECS L7VMM2", VIA_DXS_NO_VRA), |
Takashi Iwai | a85165c | 2009-02-09 17:15:50 +0100 | [diff] [blame] | 2397 | SND_PCI_QUIRK_VENDOR(0x1019, "ESC K8", VIA_DXS_SRC), |
Takashi Iwai | 9d74958 | 2006-11-24 15:37:18 +0100 | [diff] [blame] | 2398 | SND_PCI_QUIRK(0x1019, 0xaa01, "ESC K8T890-A", VIA_DXS_SRC), |
| 2399 | SND_PCI_QUIRK(0x1025, 0x0033, "Acer Inspire 1353LM", VIA_DXS_NO_VRA), |
| 2400 | SND_PCI_QUIRK(0x1025, 0x0046, "Acer Aspire 1524 WLMi", VIA_DXS_SRC), |
Takashi Iwai | a85165c | 2009-02-09 17:15:50 +0100 | [diff] [blame] | 2401 | SND_PCI_QUIRK_VENDOR(0x1043, "ASUS A7/A8", VIA_DXS_NO_VRA), |
| 2402 | SND_PCI_QUIRK_VENDOR(0x1071, "Diverse Notebook", VIA_DXS_NO_VRA), |
Takashi Iwai | 9d74958 | 2006-11-24 15:37:18 +0100 | [diff] [blame] | 2403 | SND_PCI_QUIRK(0x10cf, 0x118e, "FSC Laptop", VIA_DXS_ENABLE), |
Takashi Iwai | a85165c | 2009-02-09 17:15:50 +0100 | [diff] [blame] | 2404 | SND_PCI_QUIRK_VENDOR(0x1106, "ASRock", VIA_DXS_SRC), |
Takashi Iwai | 11be265 | 2007-10-11 14:35:00 +0200 | [diff] [blame] | 2405 | SND_PCI_QUIRK(0x1297, 0xa231, "Shuttle AK31v2", VIA_DXS_SRC), |
Takashi Iwai | 9674513 | 2007-10-25 11:46:24 +0200 | [diff] [blame] | 2406 | SND_PCI_QUIRK(0x1297, 0xa232, "Shuttle", VIA_DXS_SRC), |
| 2407 | SND_PCI_QUIRK(0x1297, 0xc160, "Shuttle Sk41G", VIA_DXS_SRC), |
Takashi Iwai | 9d74958 | 2006-11-24 15:37:18 +0100 | [diff] [blame] | 2408 | SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte GA-7VAXP", VIA_DXS_ENABLE), |
| 2409 | SND_PCI_QUIRK(0x1462, 0x3800, "MSI KT266", VIA_DXS_ENABLE), |
| 2410 | SND_PCI_QUIRK(0x1462, 0x7120, "MSI KT4V", VIA_DXS_ENABLE), |
| 2411 | SND_PCI_QUIRK(0x1462, 0x7142, "MSI K8MM-V", VIA_DXS_ENABLE), |
Takashi Iwai | a85165c | 2009-02-09 17:15:50 +0100 | [diff] [blame] | 2412 | SND_PCI_QUIRK_VENDOR(0x1462, "MSI Mobo", VIA_DXS_SRC), |
Takashi Iwai | 9d74958 | 2006-11-24 15:37:18 +0100 | [diff] [blame] | 2413 | SND_PCI_QUIRK(0x147b, 0x1401, "ABIT KD7(-RAID)", VIA_DXS_ENABLE), |
| 2414 | SND_PCI_QUIRK(0x147b, 0x1411, "ABIT VA-20", VIA_DXS_ENABLE), |
| 2415 | SND_PCI_QUIRK(0x147b, 0x1413, "ABIT KV8 Pro", VIA_DXS_ENABLE), |
| 2416 | SND_PCI_QUIRK(0x147b, 0x1415, "ABIT AV8", VIA_DXS_NO_VRA), |
| 2417 | SND_PCI_QUIRK(0x14ff, 0x0403, "Twinhead mobo", VIA_DXS_ENABLE), |
| 2418 | SND_PCI_QUIRK(0x14ff, 0x0408, "Twinhead laptop", VIA_DXS_SRC), |
| 2419 | SND_PCI_QUIRK(0x1558, 0x4701, "Clevo D470", VIA_DXS_SRC), |
| 2420 | SND_PCI_QUIRK(0x1584, 0x8120, "Diverse Laptop", VIA_DXS_ENABLE), |
| 2421 | SND_PCI_QUIRK(0x1584, 0x8123, "Targa/Uniwill", VIA_DXS_NO_VRA), |
| 2422 | SND_PCI_QUIRK(0x161f, 0x202b, "Amira Notebook", VIA_DXS_NO_VRA), |
| 2423 | SND_PCI_QUIRK(0x161f, 0x2032, "m680x machines", VIA_DXS_48K), |
| 2424 | SND_PCI_QUIRK(0x1631, 0xe004, "PB EasyNote 3174", VIA_DXS_ENABLE), |
| 2425 | SND_PCI_QUIRK(0x1695, 0x3005, "EPoX EP-8K9A", VIA_DXS_ENABLE), |
Takashi Iwai | a85165c | 2009-02-09 17:15:50 +0100 | [diff] [blame] | 2426 | SND_PCI_QUIRK_VENDOR(0x1695, "EPoX mobo", VIA_DXS_SRC), |
| 2427 | SND_PCI_QUIRK_VENDOR(0x16f3, "Jetway K8", VIA_DXS_SRC), |
| 2428 | SND_PCI_QUIRK_VENDOR(0x1734, "FSC Laptop", VIA_DXS_SRC), |
Takashi Iwai | 9d74958 | 2006-11-24 15:37:18 +0100 | [diff] [blame] | 2429 | SND_PCI_QUIRK(0x1849, 0x3059, "ASRock K7VM2", VIA_DXS_NO_VRA), |
Takashi Iwai | a85165c | 2009-02-09 17:15:50 +0100 | [diff] [blame] | 2430 | SND_PCI_QUIRK_VENDOR(0x1849, "ASRock mobo", VIA_DXS_SRC), |
Takashi Iwai | 9d74958 | 2006-11-24 15:37:18 +0100 | [diff] [blame] | 2431 | SND_PCI_QUIRK(0x1919, 0x200a, "Soltek SL-K8", VIA_DXS_NO_VRA), |
| 2432 | SND_PCI_QUIRK(0x4005, 0x4710, "MSI K7T266", VIA_DXS_SRC), |
| 2433 | { } /* terminator */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | }; |
| 2435 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2436 | static int check_dxs_list(struct pci_dev *pci, int revision) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2437 | { |
Takashi Iwai | 9d74958 | 2006-11-24 15:37:18 +0100 | [diff] [blame] | 2438 | const struct snd_pci_quirk *w; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | |
Takashi Iwai | 21641672 | 2020-07-14 19:26:30 +0200 | [diff] [blame] | 2440 | w = snd_pci_quirk_lookup(pci, dxs_allowlist); |
Takashi Iwai | 9d74958 | 2006-11-24 15:37:18 +0100 | [diff] [blame] | 2441 | if (w) { |
Takashi Iwai | 21641672 | 2020-07-14 19:26:30 +0200 | [diff] [blame] | 2442 | dev_dbg(&pci->dev, "DXS allow list for %s found\n", |
Takashi Iwai | 86b2723 | 2013-01-25 10:54:07 +0100 | [diff] [blame] | 2443 | snd_pci_quirk_name(w)); |
Takashi Iwai | 9d74958 | 2006-11-24 15:37:18 +0100 | [diff] [blame] | 2444 | return w->value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | } |
| 2446 | |
Takashi Iwai | a769577 | 2006-04-27 16:56:07 +0200 | [diff] [blame] | 2447 | /* for newer revision, default to DXS_SRC */ |
| 2448 | if (revision >= VIA_REV_8235) |
| 2449 | return VIA_DXS_SRC; |
| 2450 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | /* |
| 2452 | * not detected, try 48k rate only to be sure. |
| 2453 | */ |
Takashi Iwai | 59d3acfa | 2014-02-25 15:21:56 +0100 | [diff] [blame] | 2454 | dev_info(&pci->dev, "Assuming DXS channels with 48k fixed sample rate.\n"); |
| 2455 | dev_info(&pci->dev, " Please try dxs_support=5 option\n"); |
| 2456 | dev_info(&pci->dev, " and report if it works on your machine.\n"); |
| 2457 | dev_info(&pci->dev, " For more details, read ALSA-Configuration.txt.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | return VIA_DXS_48K; |
| 2459 | }; |
| 2460 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2461 | static int snd_via82xx_probe(struct pci_dev *pci, |
| 2462 | const struct pci_device_id *pci_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2463 | { |
Takashi Iwai | e437e3d | 2005-11-17 15:06:15 +0100 | [diff] [blame] | 2464 | struct snd_card *card; |
| 2465 | struct via82xx *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | int chip_type = 0, card_type; |
| 2467 | unsigned int i; |
| 2468 | int err; |
| 2469 | |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 2470 | err = snd_devm_card_new(&pci->dev, index, id, THIS_MODULE, |
| 2471 | sizeof(*chip), &card); |
Takashi Iwai | e58de7b | 2008-12-28 16:44:30 +0100 | [diff] [blame] | 2472 | if (err < 0) |
| 2473 | return err; |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 2474 | chip = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2475 | |
| 2476 | card_type = pci_id->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2477 | switch (card_type) { |
| 2478 | case TYPE_CARD_VIA686: |
| 2479 | strcpy(card->driver, "VIA686A"); |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 2480 | sprintf(card->shortname, "VIA 82C686A/B rev%x", pci->revision); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2481 | chip_type = TYPE_VIA686; |
| 2482 | break; |
| 2483 | case TYPE_CARD_VIA8233: |
| 2484 | chip_type = TYPE_VIA8233; |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 2485 | sprintf(card->shortname, "VIA 823x rev%x", pci->revision); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2486 | for (i = 0; i < ARRAY_SIZE(via823x_cards); i++) { |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 2487 | if (pci->revision == via823x_cards[i].revision) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | chip_type = via823x_cards[i].type; |
| 2489 | strcpy(card->shortname, via823x_cards[i].name); |
| 2490 | break; |
| 2491 | } |
| 2492 | } |
| 2493 | if (chip_type != TYPE_VIA8233A) { |
Clemens Ladisch | b7fe462 | 2005-10-04 08:46:51 +0200 | [diff] [blame] | 2494 | if (dxs_support == VIA_DXS_AUTO) |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 2495 | dxs_support = check_dxs_list(pci, pci->revision); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | /* force to use VIA8233 or 8233A model according to |
| 2497 | * dxs_support module option |
| 2498 | */ |
Clemens Ladisch | b7fe462 | 2005-10-04 08:46:51 +0200 | [diff] [blame] | 2499 | if (dxs_support == VIA_DXS_DISABLE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | chip_type = TYPE_VIA8233A; |
| 2501 | else |
| 2502 | chip_type = TYPE_VIA8233; |
| 2503 | } |
| 2504 | if (chip_type == TYPE_VIA8233A) |
| 2505 | strcpy(card->driver, "VIA8233A"); |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 2506 | else if (pci->revision >= VIA_REV_8237) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | strcpy(card->driver, "VIA8237"); /* no slog assignment */ |
| 2508 | else |
| 2509 | strcpy(card->driver, "VIA8233"); |
| 2510 | break; |
| 2511 | default: |
Takashi Iwai | 59d3acfa | 2014-02-25 15:21:56 +0100 | [diff] [blame] | 2512 | dev_err(card->dev, "invalid card type %d\n", card_type); |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 2513 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | } |
| 2515 | |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 2516 | err = snd_via82xx_create(card, pci, chip_type, pci->revision, |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 2517 | ac97_clock); |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 2518 | if (err < 0) |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 2519 | return err; |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 2520 | err = snd_via82xx_mixer_new(chip, ac97_quirk); |
| 2521 | if (err < 0) |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 2522 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2523 | |
| 2524 | if (chip_type == TYPE_VIA686) { |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 2525 | err = snd_via686_pcm_new(chip); |
| 2526 | if (err < 0) |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 2527 | return err; |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 2528 | err = snd_via686_init_misc(chip); |
| 2529 | if (err < 0) |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 2530 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2531 | } else { |
| 2532 | if (chip_type == TYPE_VIA8233A) { |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 2533 | err = snd_via8233a_pcm_new(chip); |
| 2534 | if (err < 0) |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 2535 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | // chip->dxs_fixed = 1; /* FIXME: use 48k for DXS #3? */ |
| 2537 | } else { |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 2538 | err = snd_via8233_pcm_new(chip); |
| 2539 | if (err < 0) |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 2540 | return err; |
Clemens Ladisch | b7fe462 | 2005-10-04 08:46:51 +0200 | [diff] [blame] | 2541 | if (dxs_support == VIA_DXS_48K) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | chip->dxs_fixed = 1; |
Clemens Ladisch | b7fe462 | 2005-10-04 08:46:51 +0200 | [diff] [blame] | 2543 | else if (dxs_support == VIA_DXS_NO_VRA) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2544 | chip->no_vra = 1; |
Clemens Ladisch | b7fe462 | 2005-10-04 08:46:51 +0200 | [diff] [blame] | 2545 | else if (dxs_support == VIA_DXS_SRC) { |
Sergey Vlasov | 2d7eb7c | 2005-04-11 15:04:33 +0200 | [diff] [blame] | 2546 | chip->no_vra = 1; |
| 2547 | chip->dxs_src = 1; |
| 2548 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2549 | } |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 2550 | err = snd_via8233_init_misc(chip); |
| 2551 | if (err < 0) |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 2552 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 | } |
| 2554 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2555 | /* disable interrupts */ |
| 2556 | for (i = 0; i < chip->num_devs; i++) |
| 2557 | snd_via82xx_channel_reset(chip, &chip->devs[i]); |
| 2558 | |
| 2559 | snprintf(card->longname, sizeof(card->longname), |
| 2560 | "%s with %s at %#lx, irq %d", card->shortname, |
| 2561 | snd_ac97_get_short_name(chip->ac97), chip->port, chip->irq); |
| 2562 | |
| 2563 | snd_via82xx_proc_init(chip); |
| 2564 | |
Takashi Iwai | afb342f | 2021-06-08 16:05:07 +0200 | [diff] [blame] | 2565 | err = snd_card_register(card); |
Takashi Iwai | afaf997 | 2021-07-15 09:58:47 +0200 | [diff] [blame] | 2566 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2567 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2568 | pci_set_drvdata(pci, card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2569 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | } |
| 2571 | |
Takashi Iwai | e9f66d9 | 2012-04-24 12:25:00 +0200 | [diff] [blame] | 2572 | static struct pci_driver via82xx_driver = { |
Takashi Iwai | 3733e42 | 2011-06-10 16:20:20 +0200 | [diff] [blame] | 2573 | .name = KBUILD_MODNAME, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2574 | .id_table = snd_via82xx_ids, |
| 2575 | .probe = snd_via82xx_probe, |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 2576 | .driver = { |
| 2577 | .pm = SND_VIA82XX_PM_OPS, |
| 2578 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | }; |
| 2580 | |
Takashi Iwai | e9f66d9 | 2012-04-24 12:25:00 +0200 | [diff] [blame] | 2581 | module_pci_driver(via82xx_driver); |