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