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