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