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