53 #include <linux/pci.h>
54 #include <linux/slab.h>
55 #include <linux/gameport.h>
56 #include <linux/module.h>
75 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
76 #define SUPPORT_JOYSTICK 1
82 #ifdef SUPPORT_JOYSTICK
85 static int ac97_clock = 48000;
87 static int dxs_support;
88 static int dxs_init_volume = 31;
97 #ifdef SUPPORT_JOYSTICK
106 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)");
118 #define VIA_REV_686_A 0x10
119 #define VIA_REV_686_B 0x11
120 #define VIA_REV_686_C 0x12
121 #define VIA_REV_686_D 0x13
122 #define VIA_REV_686_E 0x14
123 #define VIA_REV_686_H 0x20
126 #define VIA_REV_PRE_8233 0x10
127 #define VIA_REV_8233C 0x20
128 #define VIA_REV_8233 0x30
129 #define VIA_REV_8233A 0x40
130 #define VIA_REV_8235 0x50
131 #define VIA_REV_8237 0x60
132 #define VIA_REV_8251 0x70
138 #define VIAREG(via, x) ((via)->port + VIA_REG_##x)
139 #define VIADEV_REG(viadev, x) ((viadev)->port + VIA_REG_##x)
142 #define VIA_REG_OFFSET_STATUS 0x00
143 #define VIA_REG_STAT_ACTIVE 0x80
144 #define VIA8233_SHADOW_STAT_ACTIVE 0x08
145 #define VIA_REG_STAT_PAUSED 0x40
146 #define VIA_REG_STAT_TRIGGER_QUEUED 0x08
147 #define VIA_REG_STAT_STOPPED 0x04
148 #define VIA_REG_STAT_EOL 0x02
149 #define VIA_REG_STAT_FLAG 0x01
150 #define VIA_REG_OFFSET_CONTROL 0x01
151 #define VIA_REG_CTRL_START 0x80
152 #define VIA_REG_CTRL_TERMINATE 0x40
153 #define VIA_REG_CTRL_AUTOSTART 0x20
154 #define VIA_REG_CTRL_PAUSE 0x08
155 #define VIA_REG_CTRL_INT_STOP 0x04
156 #define VIA_REG_CTRL_INT_EOL 0x02
157 #define VIA_REG_CTRL_INT_FLAG 0x01
158 #define VIA_REG_CTRL_RESET 0x01
159 #define VIA_REG_CTRL_INT (VIA_REG_CTRL_INT_FLAG | VIA_REG_CTRL_INT_EOL | VIA_REG_CTRL_AUTOSTART)
160 #define VIA_REG_OFFSET_TYPE 0x02
161 #define VIA_REG_TYPE_AUTOSTART 0x80
162 #define VIA_REG_TYPE_16BIT 0x20
163 #define VIA_REG_TYPE_STEREO 0x10
164 #define VIA_REG_TYPE_INT_LLINE 0x00
165 #define VIA_REG_TYPE_INT_LSAMPLE 0x04
166 #define VIA_REG_TYPE_INT_LESSONE 0x08
167 #define VIA_REG_TYPE_INT_MASK 0x0c
168 #define VIA_REG_TYPE_INT_EOL 0x02
169 #define VIA_REG_TYPE_INT_FLAG 0x01
170 #define VIA_REG_OFFSET_TABLE_PTR 0x04
171 #define VIA_REG_OFFSET_CURR_PTR 0x04
172 #define VIA_REG_OFFSET_STOP_IDX 0x08
173 #define VIA8233_REG_TYPE_16BIT 0x00200000
174 #define VIA8233_REG_TYPE_STEREO 0x00100000
175 #define VIA_REG_OFFSET_CURR_COUNT 0x0c
176 #define VIA_REG_OFFSET_CURR_INDEX 0x0f
178 #define DEFINE_VIA_REGSET(name,val) \
180 VIA_REG_##name##_STATUS = (val),\
181 VIA_REG_##name##_CONTROL = (val) + 0x01,\
182 VIA_REG_##name##_TYPE = (val) + 0x02,\
183 VIA_REG_##name##_TABLE_PTR = (val) + 0x04,\
184 VIA_REG_##name##_CURR_PTR = (val) + 0x04,\
185 VIA_REG_##name##_STOP_IDX = (val) + 0x08,\
186 VIA_REG_##name##_CURR_COUNT = (val) + 0x0c,\
195 #define VIA_REG_AC97 0x80
196 #define VIA_REG_AC97_CODEC_ID_MASK (3<<30)
197 #define VIA_REG_AC97_CODEC_ID_SHIFT 30
198 #define VIA_REG_AC97_CODEC_ID_PRIMARY 0x00
199 #define VIA_REG_AC97_CODEC_ID_SECONDARY 0x01
200 #define VIA_REG_AC97_SECONDARY_VALID (1<<27)
201 #define VIA_REG_AC97_PRIMARY_VALID (1<<25)
202 #define VIA_REG_AC97_BUSY (1<<24)
203 #define VIA_REG_AC97_READ (1<<23)
204 #define VIA_REG_AC97_CMD_SHIFT 16
205 #define VIA_REG_AC97_CMD_MASK 0x7e
206 #define VIA_REG_AC97_DATA_SHIFT 0
207 #define VIA_REG_AC97_DATA_MASK 0xffff
209 #define VIA_REG_SGD_SHADOW 0x84
211 #define VIA_REG_SGD_STAT_PB_FLAG (1<<0)
212 #define VIA_REG_SGD_STAT_CP_FLAG (1<<1)
213 #define VIA_REG_SGD_STAT_FM_FLAG (1<<2)
214 #define VIA_REG_SGD_STAT_PB_EOL (1<<4)
215 #define VIA_REG_SGD_STAT_CP_EOL (1<<5)
216 #define VIA_REG_SGD_STAT_FM_EOL (1<<6)
217 #define VIA_REG_SGD_STAT_PB_STOP (1<<8)
218 #define VIA_REG_SGD_STAT_CP_STOP (1<<9)
219 #define VIA_REG_SGD_STAT_FM_STOP (1<<10)
220 #define VIA_REG_SGD_STAT_PB_ACTIVE (1<<12)
221 #define VIA_REG_SGD_STAT_CP_ACTIVE (1<<13)
222 #define VIA_REG_SGD_STAT_FM_ACTIVE (1<<14)
224 #define VIA8233_REG_SGD_STAT_FLAG (1<<0)
225 #define VIA8233_REG_SGD_STAT_EOL (1<<1)
226 #define VIA8233_REG_SGD_STAT_STOP (1<<2)
227 #define VIA8233_REG_SGD_STAT_ACTIVE (1<<3)
228 #define VIA8233_INTR_MASK(chan) ((VIA8233_REG_SGD_STAT_FLAG|VIA8233_REG_SGD_STAT_EOL) << ((chan) * 4))
229 #define VIA8233_REG_SGD_CHAN_SDX 0
230 #define VIA8233_REG_SGD_CHAN_MULTI 4
231 #define VIA8233_REG_SGD_CHAN_REC 6
232 #define VIA8233_REG_SGD_CHAN_REC1 7
234 #define VIA_REG_GPI_STATUS 0x88
235 #define VIA_REG_GPI_INTR 0x8c
242 #define VIA_REG_OFS_PLAYBACK_VOLUME_L 0x02
243 #define VIA_REG_OFS_PLAYBACK_VOLUME_R 0x03
244 #define VIA_REG_OFS_MULTPLAY_FORMAT 0x02
245 #define VIA_REG_MULTPLAY_FMT_8BIT 0x00
246 #define VIA_REG_MULTPLAY_FMT_16BIT 0x80
247 #define VIA_REG_MULTPLAY_FMT_CH_MASK 0x70
248 #define VIA_REG_OFS_CAPTURE_FIFO 0x02
249 #define VIA_REG_CAPTURE_FIFO_ENABLE 0x40
251 #define VIA_DXS_MAX_VOLUME 31
253 #define VIA_REG_CAPTURE_CHANNEL 0x63
254 #define VIA_REG_CAPTURE_CHANNEL_MIC 0x4
255 #define VIA_REG_CAPTURE_CHANNEL_LINE 0
256 #define VIA_REG_CAPTURE_SELECT_CODEC 0x03
258 #define VIA_TBL_BIT_FLAG 0x40000000
259 #define VIA_TBL_BIT_EOL 0x80000000
262 #define VIA_ACLINK_STAT 0x40
263 #define VIA_ACLINK_C11_READY 0x20
264 #define VIA_ACLINK_C10_READY 0x10
265 #define VIA_ACLINK_C01_READY 0x04
266 #define VIA_ACLINK_LOWPOWER 0x02
267 #define VIA_ACLINK_C00_READY 0x01
268 #define VIA_ACLINK_CTRL 0x41
269 #define VIA_ACLINK_CTRL_ENABLE 0x80
270 #define VIA_ACLINK_CTRL_RESET 0x40
271 #define VIA_ACLINK_CTRL_SYNC 0x20
272 #define VIA_ACLINK_CTRL_SDO 0x10
273 #define VIA_ACLINK_CTRL_VRA 0x08
274 #define VIA_ACLINK_CTRL_PCM 0x04
275 #define VIA_ACLINK_CTRL_FM 0x02
276 #define VIA_ACLINK_CTRL_SB 0x01
277 #define VIA_ACLINK_CTRL_INIT (VIA_ACLINK_CTRL_ENABLE|\
278 VIA_ACLINK_CTRL_RESET|\
279 VIA_ACLINK_CTRL_PCM|\
281 #define VIA_FUNC_ENABLE 0x42
282 #define VIA_FUNC_MIDI_PNP 0x80
283 #define VIA_FUNC_MIDI_IRQMASK 0x40
284 #define VIA_FUNC_RX2C_WRITE 0x20
285 #define VIA_FUNC_SB_FIFO_EMPTY 0x10
286 #define VIA_FUNC_ENABLE_GAME 0x08
287 #define VIA_FUNC_ENABLE_FM 0x04
288 #define VIA_FUNC_ENABLE_MIDI 0x02
289 #define VIA_FUNC_ENABLE_SB 0x01
290 #define VIA_PNP_CONTROL 0x43
291 #define VIA_FM_NMI_CTRL 0x48
292 #define VIA8233_VOLCHG_CTRL 0x48
293 #define VIA8233_SPDIF_CTRL 0x49
294 #define VIA8233_SPDIF_DX3 0x08
295 #define VIA8233_SPDIF_SLOT_MASK 0x03
296 #define VIA8233_SPDIF_SLOT_1011 0x00
297 #define VIA8233_SPDIF_SLOT_34 0x01
298 #define VIA8233_SPDIF_SLOT_78 0x02
299 #define VIA8233_SPDIF_SLOT_69 0x03
304 #define VIA_DXS_AUTO 0
305 #define VIA_DXS_ENABLE 1
306 #define VIA_DXS_DISABLE 2
307 #define VIA_DXS_48K 3
308 #define VIA_DXS_NO_VRA 4
309 #define VIA_DXS_SRC 5
321 #define VIA_TABLE_SIZE 255
322 #define VIA_MAX_BUFSIZE (1<<24)
347 #define VIA_MAX_DEVS 7
365 #ifdef CONFIG_PM_SLEEP
366 unsigned char legacy_saved;
367 unsigned char legacy_cfg_saved;
368 unsigned char spdif_ctrl_saved;
369 unsigned char capture_src_saved[2];
370 unsigned int mpu_port_saved;
402 #ifdef SUPPORT_JOYSTICK
427 unsigned int periods,
unsigned int fragsize)
450 for (i = 0; i < periods; i++) {
465 addr = snd_pcm_sgbuf_get_addr(substream, ofs);
467 r = snd_pcm_sgbuf_get_chunk_size(substream, ofs, rest);
470 if (i == periods - 1)
488 dev->
bufsize = periods * fragsize;
498 if (dev->
table.area) {
511 static inline unsigned int snd_via82xx_codec_xread(
struct via82xx *chip)
516 static inline void snd_via82xx_codec_xwrite(
struct via82xx *chip,
unsigned int val)
521 static int snd_via82xx_codec_ready(
struct via82xx *chip,
int secondary)
526 while (timeout-- > 0) {
532 secondary, snd_via82xx_codec_xread(chip));
536 static int snd_via82xx_codec_valid(
struct via82xx *chip,
int secondary)
538 unsigned int timeout = 1000;
539 unsigned int val, val1;
543 while (timeout-- > 0) {
544 val = snd_via82xx_codec_xread(chip);
553 static void snd_via82xx_codec_wait(
struct snd_ac97 *
ac97)
557 err = snd_via82xx_codec_ready(chip, ac97->
num);
563 static void snd_via82xx_codec_write(
struct snd_ac97 *ac97,
574 snd_via82xx_codec_xwrite(chip, xval);
575 snd_via82xx_codec_ready(chip, ac97->
num);
578 static unsigned short snd_via82xx_codec_read(
struct snd_ac97 *ac97,
unsigned short reg)
581 unsigned int xval, val = 0xffff;
591 ac97->
num, snd_via82xx_codec_xread(chip));
594 snd_via82xx_codec_xwrite(chip, xval);
596 if (snd_via82xx_codec_valid(chip, ac97->
num) >= 0) {
598 val = snd_via82xx_codec_xread(chip);
642 for (i = 0; i < chip->
num_devs; i++) {
643 struct viadev *viadev = &chip->
devs[
i];
644 unsigned char c_status =
inb(
VIADEV_REG(viadev, OFFSET_STATUS));
672 static irqreturn_t snd_via8233_interrupt(
int irq,
void *dev_id)
683 for (i = 0; i < chip->
num_devs; i++) {
684 struct viadev *viadev = &chip->
devs[
i];
686 unsigned char c_status, shadow_status;
696 if (substream && viadev->
running) {
733 struct viadev *viadev = substream->
runtime->private_data;
763 snd_via82xx_channel_reset(chip, viadev);
776 #define check_invalid_pos(viadev,pos) \
777 ((pos) < viadev->lastpos && ((pos) >= viadev->bufsize2 ||\
778 viadev->lastpos < viadev->bufsize2))
780 static inline unsigned int calc_linear_pos(
struct viadev *viadev,
unsigned int idx,
787 res = base + size -
count;
794 (
int)size, (
int)count);
805 if ((
unsigned int)delta > viadev->
fragsize)
811 "bufsize2 = 0x%x, offsize = 0x%x, size = 0x%x, "
821 "using last valid pointer\n");
835 struct viadev *viadev = substream->
runtime->private_data;
844 count =
inl(
VIADEV_REG(viadev, OFFSET_CURR_COUNT)) & 0xffffff;
849 if (ptr <= (
unsigned int)viadev->
table.addr)
853 res = calc_linear_pos(viadev, idx, count);
857 return bytes_to_frames(substream->
runtime, res);
866 struct viadev *viadev = substream->
runtime->private_data;
884 if (!(status & VIA_REG_STAT_ACTIVE)) {
888 if (count & 0xffffff) {
898 res = calc_linear_pos(viadev, idx, count);
903 if (status & VIA_REG_STAT_EOL) {
915 return bytes_to_frames(substream->
runtime, res);
927 struct viadev *viadev = substream->
runtime->private_data;
933 err = build_via_table(viadev, substream, chip->
pci,
935 params_period_bytes(hw_params));
949 struct viadev *viadev = substream->
runtime->private_data;
951 clean_via_table(viadev, substream, chip->
pci);
960 static void snd_via82xx_set_table_ptr(
struct via82xx *chip,
struct viadev *viadev)
962 snd_via82xx_codec_ready(chip, 0);
965 snd_via82xx_codec_ready(chip, 0);
971 static void via686_setup_format(
struct via82xx *chip,
struct viadev *viadev,
974 snd_via82xx_channel_reset(chip, viadev);
976 snd_via82xx_set_table_ptr(chip, viadev);
988 struct viadev *viadev = substream->
runtime->private_data;
993 via686_setup_format(chip, viadev, runtime);
1000 struct viadev *viadev = substream->
runtime->private_data;
1004 via686_setup_format(chip, viadev, runtime);
1015 spin_lock_irq(&rec->
lock);
1016 if (rec->
rate != rate) {
1024 spin_unlock_irq(&rec->
lock);
1034 struct viadev *viadev = substream->
runtime->private_data;
1036 int ac97_rate = chip->
dxs_src ? 48000 : runtime->
rate;
1040 if ((rate_changed = via_lock_rate(&chip->
rates[0], ac97_rate)) < 0)
1041 return rate_changed;
1048 if (runtime->
rate == 48000)
1051 rbits = (0x100000 / 48000) * runtime->
rate +
1052 ((0x100000 % 48000) * runtime->
rate) / 48000;
1054 snd_via82xx_channel_reset(chip, viadev);
1055 snd_via82xx_set_table_ptr(chip, viadev);
1066 snd_via82xx_codec_ready(chip, 0);
1076 struct viadev *viadev = substream->
runtime->private_data;
1081 if (via_lock_rate(&chip->
rates[0], runtime->
rate) < 0)
1087 snd_via82xx_channel_reset(chip, viadev);
1088 snd_via82xx_set_table_ptr(chip, viadev);
1103 case 1: slots = (1<<0) | (1<<4);
break;
1104 case 2: slots = (1<<0) | (2<<4);
break;
1105 case 3: slots = (1<<0) | (2<<4) | (5<<8);
break;
1106 case 4: slots = (1<<0) | (2<<4) | (3<<8) | (4<<12);
break;
1107 case 5: slots = (1<<0) | (2<<4) | (3<<8) | (4<<12) | (5<<16);
break;
1108 case 6: slots = (1<<0) | (2<<4) | (3<<8) | (4<<12) | (5<<16) | (6<<20);
break;
1109 default: slots = 0;
break;
1115 snd_via82xx_codec_ready(chip, 0);
1125 struct viadev *viadev = substream->
runtime->private_data;
1128 if (via_lock_rate(&chip->
rates[1], runtime->
rate) < 0)
1131 snd_via82xx_channel_reset(chip, viadev);
1132 snd_via82xx_set_table_ptr(chip, viadev);
1139 snd_via82xx_codec_ready(chip, 0);
1172 static int snd_via82xx_pcm_open(
struct via82xx *chip,
struct viadev *viadev,
1178 bool use_src =
false;
1180 runtime->
hw = snd_via82xx_hw;
1184 spin_lock_irq(&ratep->
lock);
1193 runtime->
hw.rate_min = runtime->
hw.rate_max = 48000;
1198 runtime->
hw.rate_min = 8000;
1199 runtime->
hw.rate_max = 48000;
1201 }
else if (! ratep->
rate) {
1203 runtime->
hw.rates = chip->
ac97->rates[
idx];
1208 runtime->
hw.rate_max = runtime->
hw.rate_min = ratep->
rate;
1210 spin_unlock_irq(&ratep->
lock);
1239 if ((err = snd_via82xx_pcm_open(chip, viadev, substream)) < 0)
1250 struct viadev *viadev;
1255 if ((err = snd_via82xx_pcm_open(chip, viadev, substream)) < 0)
1292 if ((err = snd_via82xx_pcm_open(chip, viadev, substream)) < 0)
1294 substream->
runtime->hw.channels_max = 6;
1298 &hw_constraints_channels);
1310 return snd_via82xx_pcm_open(chip, viadev, substream);
1319 struct viadev *viadev = substream->
runtime->private_data;
1324 spin_lock_irq(&ratep->
lock);
1328 spin_unlock_irq(&ratep->
lock);
1329 if (! ratep->
rate) {
1331 snd_ac97_update_power(chip->
ac97,
1333 snd_ac97_update_power(chip->
ac97,
1335 snd_ac97_update_power(chip->
ac97,
1338 snd_ac97_update_power(chip->
ac97,
1348 struct viadev *viadev = substream->
runtime->private_data;
1349 unsigned int stream;
1358 return snd_via82xx_pcm_close(substream);
1363 static struct snd_pcm_ops snd_via686_playback_ops = {
1364 .open = snd_via686_playback_open,
1365 .close = snd_via82xx_pcm_close,
1367 .hw_params = snd_via82xx_hw_params,
1368 .hw_free = snd_via82xx_hw_free,
1369 .prepare = snd_via686_playback_prepare,
1370 .trigger = snd_via82xx_pcm_trigger,
1371 .pointer = snd_via686_pcm_pointer,
1376 static struct snd_pcm_ops snd_via686_capture_ops = {
1377 .open = snd_via82xx_capture_open,
1378 .close = snd_via82xx_pcm_close,
1380 .hw_params = snd_via82xx_hw_params,
1381 .hw_free = snd_via82xx_hw_free,
1382 .prepare = snd_via686_capture_prepare,
1383 .trigger = snd_via82xx_pcm_trigger,
1384 .pointer = snd_via686_pcm_pointer,
1389 static struct snd_pcm_ops snd_via8233_playback_ops = {
1390 .open = snd_via8233_playback_open,
1391 .close = snd_via8233_playback_close,
1393 .hw_params = snd_via82xx_hw_params,
1394 .hw_free = snd_via82xx_hw_free,
1395 .prepare = snd_via8233_playback_prepare,
1396 .trigger = snd_via82xx_pcm_trigger,
1397 .pointer = snd_via8233_pcm_pointer,
1402 static struct snd_pcm_ops snd_via8233_multi_ops = {
1403 .open = snd_via8233_multi_open,
1404 .close = snd_via82xx_pcm_close,
1406 .hw_params = snd_via82xx_hw_params,
1407 .hw_free = snd_via82xx_hw_free,
1408 .prepare = snd_via8233_multi_prepare,
1409 .trigger = snd_via82xx_pcm_trigger,
1410 .pointer = snd_via8233_pcm_pointer,
1415 static struct snd_pcm_ops snd_via8233_capture_ops = {
1416 .open = snd_via82xx_capture_open,
1417 .close = snd_via82xx_pcm_close,
1419 .hw_params = snd_via82xx_hw_params,
1420 .hw_free = snd_via82xx_hw_free,
1421 .prepare = snd_via8233_capture_prepare,
1422 .trigger = snd_via82xx_pcm_trigger,
1423 .pointer = snd_via8233_pcm_pointer,
1428 static void init_viadev(
struct via82xx *chip,
int idx,
unsigned int reg_offset,
1431 chip->
devs[
idx].reg_offset = reg_offset;
1432 chip->
devs[
idx].shadow_shift = shadow_pos * 4;
1462 for (i = 0; i < 4; i++)
1463 init_viadev(chip, i, 0x10 * i, i, 0);
1465 init_viadev(chip, chip->
capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1);
1487 init_viadev(chip, chip->
multi_devno, VIA_REG_MULTPLAY_STATUS, 4, 0);
1489 init_viadev(chip, chip->
capture_devno + 1, VIA_REG_CAPTURE_8233_STATUS + 0x10, 7, 1);
1530 init_viadev(chip, chip->
multi_devno, VIA_REG_MULTPLAY_STATUS, 4, 0);
1532 init_viadev(chip, chip->
capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1);
1546 if (! ac97_can_spdif(chip->
ac97))
1586 chip->
pcms[0] = pcm;
1587 init_viadev(chip, 0, VIA_REG_PLAYBACK_STATUS, 0, 0);
1588 init_viadev(chip, 1, VIA_REG_CAPTURE_STATUS, 0, 1);
1601 static int snd_via8233_capture_source_info(
struct snd_kcontrol *kcontrol,
1607 static char *texts[2] = {
1619 static int snd_via8233_capture_source_get(
struct snd_kcontrol *kcontrol,
1628 static int snd_via8233_capture_source_put(
struct snd_kcontrol *kcontrol,
1638 if (ucontrol->
value.enumerated.item[0])
1647 .name =
"Input Source Select",
1649 .info = snd_via8233_capture_source_info,
1650 .get = snd_via8233_capture_source_get,
1651 .put = snd_via8233_capture_source_put,
1654 #define snd_via8233_dxs3_spdif_info snd_ctl_boolean_mono_info
1656 static int snd_via8233_dxs3_spdif_get(
struct snd_kcontrol *kcontrol,
1667 static int snd_via8233_dxs3_spdif_put(
struct snd_kcontrol *kcontrol,
1675 if (ucontrol->
value.integer.value[0])
1686 static struct snd_kcontrol_new snd_via8233_dxs3_spdif_control __devinitdata = {
1690 .get = snd_via8233_dxs3_spdif_get,
1691 .put = snd_via8233_dxs3_spdif_put,
1694 static int snd_via8233_dxs_volume_info(
struct snd_kcontrol *kcontrol,
1704 static int snd_via8233_dxs_volume_get(
struct snd_kcontrol *kcontrol,
1708 unsigned int idx = kcontrol->
id.subdevice;
1715 static int snd_via8233_pcmdxs_volume_get(
struct snd_kcontrol *kcontrol,
1724 static int snd_via8233_dxs_volume_put(
struct snd_kcontrol *kcontrol,
1728 unsigned int idx = kcontrol->
id.subdevice;
1729 unsigned long port = chip->
port + 0x10 *
idx;
1733 for (i = 0; i < 2; i++) {
1734 val = ucontrol->
value.integer.value[
i];
1747 static int snd_via8233_pcmdxs_volume_put(
struct snd_kcontrol *kcontrol,
1755 for (i = 0; i < 2; i++) {
1756 val = ucontrol->
value.integer.value[
i];
1763 for (idx = 0; idx < 4; idx++) {
1764 unsigned long port = chip->
port + 0x10 *
idx;
1775 static struct snd_kcontrol_new snd_via8233_pcmdxs_volume_control __devinitdata = {
1776 .
name =
"PCM Playback Volume",
1780 .
info = snd_via8233_dxs_volume_info,
1781 .
get = snd_via8233_pcmdxs_volume_get,
1782 .
put = snd_via8233_pcmdxs_volume_put,
1783 .
tlv = { .p = db_scale_dxs }
1786 static struct snd_kcontrol_new snd_via8233_dxs_volume_control __devinitdata = {
1790 .name =
"PCM Playback Volume",
1794 .info = snd_via8233_dxs_volume_info,
1795 .get = snd_via8233_dxs_volume_get,
1796 .put = snd_via8233_dxs_volume_put,
1797 .tlv = { .p = db_scale_dxs }
1809 static void snd_via82xx_mixer_free_ac97(
struct snd_ac97 *ac97)
1817 .subvendor = 0x1106,
1818 .subdevice = 0x4161,
1819 .codec_id = 0x56494161,
1820 .name =
"Soltek SL-75DRV5",
1824 .subvendor = 0x1106,
1825 .subdevice = 0x4161,
1826 .name =
"ASRock K7VT2",
1830 .subvendor = 0x110a,
1831 .subdevice = 0x0079,
1832 .name =
"Fujitsu Siemens D1289",
1836 .subvendor = 0x1019,
1837 .subdevice = 0x0a81,
1838 .name =
"ECS K7VTA3",
1842 .subvendor = 0x1019,
1843 .subdevice = 0x0a85,
1844 .name =
"ECS L7VMM2",
1848 .subvendor = 0x1019,
1849 .subdevice = 0x1841,
1850 .name =
"ECS K7VTA3",
1854 .subvendor = 0x1849,
1855 .subdevice = 0x3059,
1856 .name =
"ASRock K7VM2",
1860 .subvendor = 0x14cd,
1861 .subdevice = 0x7002,
1866 .subvendor = 0x1071,
1867 .subdevice = 0x8590,
1868 .name =
"Mitac Mobo",
1872 .subvendor = 0x161f,
1873 .subdevice = 0x202b,
1874 .name =
"Arima Notebook",
1878 .subvendor = 0x161f,
1879 .subdevice = 0x2032,
1880 .name =
"Targa Traveller 811",
1884 .subvendor = 0x161f,
1885 .subdevice = 0x2032,
1890 .subvendor = 0x1297,
1891 .subdevice = 0xa232,
1892 .name =
"Shuttle AK32VN",
1898 static int __devinit snd_via82xx_mixer_new(
struct via82xx *chip,
const char *quirk_override)
1903 .write = snd_via82xx_codec_write,
1904 .read = snd_via82xx_codec_read,
1905 .wait = snd_via82xx_codec_wait,
1910 chip->
ac97_bus->private_free = snd_via82xx_mixer_free_ac97_bus;
1913 memset(&ac97, 0,
sizeof(ac97));
1931 #ifdef SUPPORT_JOYSTICK
1932 #define JOYSTICK_ADDR 0x200
1933 static int __devinit snd_via686_create_gameport(
struct via82xx *chip,
unsigned char *legacy)
1948 chip->gameport = gp = gameport_allocate_port();
1950 printk(
KERN_ERR "via82xx: cannot allocate memory for gameport\n");
1955 gameport_set_name(gp,
"VIA686 Gameport");
1957 gameport_set_dev_parent(gp, &chip->
pci->dev);
1958 gp->
io = JOYSTICK_ADDR;
1959 gameport_set_port_data(gp, r);
1965 gameport_register_port(chip->gameport);
1970 static void snd_via686_free_gameport(
struct via82xx *chip)
1972 if (chip->gameport) {
1973 struct resource *r = gameport_get_port_data(chip->gameport);
1976 chip->gameport =
NULL;
1981 static inline int snd_via686_create_gameport(
struct via82xx *chip,
unsigned char *legacy)
1985 static inline void snd_via686_free_gameport(
struct via82xx *chip) { }
1999 for (i = 0; i <
caps; i++) {
2000 snd_via8233_capture_source.index =
i;
2005 if (ac97_can_spdif(chip->
ac97)) {
2016 strcpy(
sid.name,
"PCM Playback Volume");
2026 for (i = 0; i < 4; ++
i) {
2030 &snd_via8233_dxs_volume_control, chip);
2033 kctl->
id.subdevice =
i;
2052 unsigned char legacy, legacy_cfg;
2061 if (mpu_port >= 0x200) {
2063 pci_write_config_dword(chip->
pci, 0x18, mpu_port | 0x01);
2064 #ifdef CONFIG_PM_SLEEP
2065 chip->mpu_port_saved = mpu_port;
2076 legacy_cfg &= ~(3 << 2);
2077 legacy_cfg |= (mpu_port & 0x0030) >> 2;
2081 mpu_port = 0x300 + ((legacy_cfg & 0x000c) << 2);
2085 if (mpu_port >= 0x200 &&
2104 &chip->
rmidi) < 0) {
2106 " at 0x%lx, skipping\n", mpu_port);
2114 snd_via686_create_gameport(chip, &legacy);
2116 #ifdef CONFIG_PM_SLEEP
2117 chip->legacy_saved = legacy;
2118 chip->legacy_cfg_saved = legacy_cfg;
2134 snd_iprintf(buffer,
"%s\n\n", chip->
card->longname);
2135 for (i = 0; i < 0xa0; i += 4) {
2136 snd_iprintf(buffer,
"%02x: %08x\n", i,
inl(chip->
port + i));
2144 if (! snd_card_proc_new(chip->
card,
"via82xx", &entry))
2145 snd_info_set_text_ops(entry, chip, snd_via82xx_proc_read);
2152 static int snd_via82xx_chip_init(
struct via82xx *chip)
2155 unsigned long end_time;
2200 if (pval & VIA_ACLINK_C00_READY)
2243 pci_read_config_byte(pci, 0x44, &data);
2244 pci_write_config_byte(pci, 0x44, data | 0x40);
2251 for (idx = 0; idx < 4; idx++) {
2252 unsigned long port = chip->
port + 0x10 *
idx;
2253 for (i = 0; i < 2; i++) {
2264 #ifdef CONFIG_PM_SLEEP
2268 static int snd_via82xx_suspend(
struct device *dev)
2276 for (i = 0; i < 2; i++)
2277 snd_pcm_suspend_all(chip->
pcms[i]);
2278 for (i = 0; i < chip->
num_devs; i++)
2279 snd_via82xx_channel_reset(chip, &chip->
devs[i]);
2281 snd_ac97_suspend(chip->
ac97);
2296 static int snd_via82xx_resume(
struct device *dev)
2307 "disabling device\n");
2313 snd_via82xx_chip_init(chip);
2316 if (chip->mpu_port_saved)
2317 pci_write_config_dword(chip->
pci, 0x18, chip->mpu_port_saved | 0x01);
2326 snd_ac97_resume(chip->
ac97);
2328 for (i = 0; i < chip->
num_devs; i++)
2329 snd_via82xx_channel_reset(chip, &chip->
devs[i]);
2335 static SIMPLE_DEV_PM_OPS(snd_via82xx_pm, snd_via82xx_suspend, snd_via82xx_resume);
2336 #define SND_VIA82XX_PM_OPS &snd_via82xx_pm
2338 #define SND_VIA82XX_PM_OPS NULL
2341 static int snd_via82xx_free(
struct via82xx *chip)
2348 for (i = 0; i < chip->
num_devs; i++)
2349 snd_via82xx_channel_reset(chip, &chip->
devs[i]);
2358 snd_via686_free_gameport(chip);
2370 return snd_via82xx_free(chip);
2383 .dev_free = snd_via82xx_dev_free,
2417 snd_via8233_interrupt : snd_via686_interrupt,
2419 KBUILD_MODNAME, chip)) {
2421 snd_via82xx_free(chip);
2425 if (ac97_clock >= 8000 && ac97_clock <= 48000)
2429 if ((err = snd_via82xx_chip_init(chip)) < 0) {
2430 snd_via82xx_free(chip);
2435 snd_via82xx_free(chip);
2455 static struct via823x_info via823x_cards[] __devinitdata = {
2469 static struct snd_pci_quirk dxs_whitelist[] __devinitdata = {
2470 SND_PCI_QUIRK(0x1005, 0x4710,
"Avance Logic Mobo",
VIA_DXS_ENABLE),
2471 SND_PCI_QUIRK(0x1019, 0x0996,
"ESC Mobo",
VIA_DXS_48K),
2472 SND_PCI_QUIRK(0x1019, 0x0a81,
"ECS K7VTA3 v8.0",
VIA_DXS_NO_VRA),
2474 SND_PCI_QUIRK_VENDOR(0x1019,
"ESC K8",
VIA_DXS_SRC),
2475 SND_PCI_QUIRK(0x1019, 0xaa01,
"ESC K8T890-A",
VIA_DXS_SRC),
2476 SND_PCI_QUIRK(0x1025, 0x0033,
"Acer Inspire 1353LM",
VIA_DXS_NO_VRA),
2477 SND_PCI_QUIRK(0x1025, 0x0046,
"Acer Aspire 1524 WLMi",
VIA_DXS_SRC),
2479 SND_PCI_QUIRK_VENDOR(0x1071,
"Diverse Notebook",
VIA_DXS_NO_VRA),
2481 SND_PCI_QUIRK_VENDOR(0x1106,
"ASRock",
VIA_DXS_SRC),
2482 SND_PCI_QUIRK(0x1297, 0xa231,
"Shuttle AK31v2",
VIA_DXS_SRC),
2483 SND_PCI_QUIRK(0x1297, 0xa232,
"Shuttle",
VIA_DXS_SRC),
2484 SND_PCI_QUIRK(0x1297, 0xc160,
"Shuttle Sk41G",
VIA_DXS_SRC),
2485 SND_PCI_QUIRK(0x1458, 0xa002,
"Gigabyte GA-7VAXP",
VIA_DXS_ENABLE),
2489 SND_PCI_QUIRK_VENDOR(0x1462,
"MSI Mobo",
VIA_DXS_SRC),
2490 SND_PCI_QUIRK(0x147b, 0x1401,
"ABIT KD7(-RAID)",
VIA_DXS_ENABLE),
2495 SND_PCI_QUIRK(0x14ff, 0x0408,
"Twinhead laptop",
VIA_DXS_SRC),
2496 SND_PCI_QUIRK(0x1558, 0x4701,
"Clevo D470",
VIA_DXS_SRC),
2500 SND_PCI_QUIRK(0x161f, 0x2032,
"m680x machines",
VIA_DXS_48K),
2501 SND_PCI_QUIRK(0x1631, 0xe004,
"PB EasyNote 3174",
VIA_DXS_ENABLE),
2503 SND_PCI_QUIRK_VENDOR(0x1695,
"EPoX mobo",
VIA_DXS_SRC),
2504 SND_PCI_QUIRK_VENDOR(0x16f3,
"Jetway K8",
VIA_DXS_SRC),
2505 SND_PCI_QUIRK_VENDOR(0x1734,
"FSC Laptop",
VIA_DXS_SRC),
2507 SND_PCI_QUIRK_VENDOR(0x1849,
"ASRock mobo",
VIA_DXS_SRC),
2509 SND_PCI_QUIRK(0x4005, 0x4710,
"MSI K7T266",
VIA_DXS_SRC),
2515 const struct snd_pci_quirk *
w;
2517 w = snd_pci_quirk_lookup(pci, dxs_whitelist);
2531 printk(
KERN_INFO "via82xx: Assuming DXS channels with 48k fixed sample rate.\n");
2534 printk(
KERN_INFO " For more details, read ALSA-Configuration.txt.\n");
2561 for (i = 0; i <
ARRAY_SIZE(via823x_cards); i++) {
2562 if (pci->
revision == via823x_cards[i].revision) {
2563 chip_type = via823x_cards[
i].type;
2570 dxs_support = check_dxs_list(pci, pci->
revision);
2592 if ((err = snd_via82xx_create(card, pci, chip_type, pci->
revision,
2593 ac97_clock, &chip)) < 0)
2596 if ((err = snd_via82xx_mixer_new(chip,
ac97_quirk)) < 0)
2600 if ((err = snd_via686_pcm_new(chip)) < 0 ||
2601 (err = snd_via686_init_misc(chip)) < 0)
2605 if ((err = snd_via8233a_pcm_new(chip)) < 0)
2609 if ((err = snd_via8233_pcm_new(chip)) < 0)
2620 if ((err = snd_via8233_init_misc(chip)) < 0)
2625 for (i = 0; i < chip->
num_devs; i++)
2626 snd_via82xx_channel_reset(chip, &chip->
devs[i]);
2629 "%s with %s at %#lx, irq %d", card->
shortname,
2632 snd_via82xx_proc_init(chip);
2638 pci_set_drvdata(pci, card);
2649 pci_set_drvdata(pci,
NULL);
2653 .name = KBUILD_MODNAME,
2654 .id_table = snd_via82xx_ids,
2655 .probe = snd_via82xx_probe,