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