2019-05-27 09:55:05 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* ALSA driver for VIA VT82xx (South Bridge)
|
|
|
|
*
|
|
|
|
* VT82C686A/B/C, VT8233A/C, VT8235
|
|
|
|
*
|
2007-10-15 11:50:19 +04:00
|
|
|
* Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
|
2005-04-17 02:20:36 +04:00
|
|
|
* Tjeerd.Mulder <Tjeerd.Mulder@fujitsu-siemens.com>
|
|
|
|
* 2002 Takashi Iwai <tiwai@suse.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Changes:
|
|
|
|
*
|
|
|
|
* Dec. 19, 2002 Takashi Iwai <tiwai@suse.de>
|
|
|
|
* - use the DSX channels for the first pcm playback.
|
|
|
|
* (on VIA8233, 8233C and 8235 only)
|
|
|
|
* this will allow you play simultaneously up to 4 streams.
|
|
|
|
* multi-channel playback is assigned to the second device
|
|
|
|
* on these chips.
|
|
|
|
* - support the secondary capture (on VIA8233/C,8235)
|
|
|
|
* - SPDIF support
|
|
|
|
* the DSX3 channel can be used for SPDIF output.
|
|
|
|
* on VIA8233A, this channel is assigned to the second pcm
|
|
|
|
* playback.
|
|
|
|
* the card config of alsa-lib will assign the correct
|
|
|
|
* device for applications.
|
|
|
|
* - clean up the code, separate low-level initialization
|
|
|
|
* routines for each chipset.
|
2005-10-18 16:31:07 +04:00
|
|
|
*
|
|
|
|
* Sep. 26, 2005 Karsten Wiese <annabellesgarden@yahoo.de>
|
|
|
|
* - Optimize position calculation for the 823x chips.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
|
2015-01-28 18:49:33 +03:00
|
|
|
#include <linux/io.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/gameport.h>
|
2011-07-15 21:13:37 +04:00
|
|
|
#include <linux/module.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
#include <sound/info.h>
|
2006-08-21 20:44:54 +04:00
|
|
|
#include <sound/tlv.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <sound/ac97_codec.h>
|
|
|
|
#include <sound/mpu401.h>
|
|
|
|
#include <sound/initval.h>
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#define POINTER_DEBUG
|
|
|
|
#endif
|
|
|
|
|
2007-10-15 11:50:19 +04:00
|
|
|
MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
|
2005-04-17 02:20:36 +04:00
|
|
|
MODULE_DESCRIPTION("VIA VT82xx audio");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_SUPPORTED_DEVICE("{{VIA,VT82C686A/B/C,pci},{VIA,VT8233A/C,8235}}");
|
|
|
|
|
2016-11-13 01:26:41 +03:00
|
|
|
#if IS_REACHABLE(CONFIG_GAMEPORT)
|
2005-04-17 02:20:36 +04:00
|
|
|
#define SUPPORT_JOYSTICK 1
|
|
|
|
#endif
|
|
|
|
|
2005-10-04 10:46:51 +04:00
|
|
|
static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
|
|
|
|
static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
|
|
|
|
static long mpu_port;
|
2005-04-17 02:20:36 +04:00
|
|
|
#ifdef SUPPORT_JOYSTICK
|
2011-12-15 07:19:36 +04:00
|
|
|
static bool joystick;
|
2005-04-17 02:20:36 +04:00
|
|
|
#endif
|
2005-10-04 10:46:51 +04:00
|
|
|
static int ac97_clock = 48000;
|
|
|
|
static char *ac97_quirk;
|
|
|
|
static int dxs_support;
|
2010-07-12 18:27:24 +04:00
|
|
|
static int dxs_init_volume = 31;
|
2009-06-21 22:50:48 +04:00
|
|
|
static int nodelay;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-10-04 10:46:51 +04:00
|
|
|
module_param(index, int, 0444);
|
2005-04-17 02:20:36 +04:00
|
|
|
MODULE_PARM_DESC(index, "Index value for VIA 82xx bridge.");
|
2005-10-04 10:46:51 +04:00
|
|
|
module_param(id, charp, 0444);
|
2005-04-17 02:20:36 +04:00
|
|
|
MODULE_PARM_DESC(id, "ID string for VIA 82xx bridge.");
|
2017-04-04 18:54:30 +03:00
|
|
|
module_param_hw(mpu_port, long, ioport, 0444);
|
2005-04-17 02:20:36 +04:00
|
|
|
MODULE_PARM_DESC(mpu_port, "MPU-401 port. (VT82C686x only)");
|
|
|
|
#ifdef SUPPORT_JOYSTICK
|
2005-10-04 10:46:51 +04:00
|
|
|
module_param(joystick, bool, 0444);
|
2005-04-17 02:20:36 +04:00
|
|
|
MODULE_PARM_DESC(joystick, "Enable joystick. (VT82C686x only)");
|
|
|
|
#endif
|
2005-10-04 10:46:51 +04:00
|
|
|
module_param(ac97_clock, int, 0444);
|
2005-04-17 02:20:36 +04:00
|
|
|
MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz).");
|
2005-10-04 10:46:51 +04:00
|
|
|
module_param(ac97_quirk, charp, 0444);
|
2005-04-17 02:20:36 +04:00
|
|
|
MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware.");
|
2005-10-04 10:46:51 +04:00
|
|
|
module_param(dxs_support, int, 0444);
|
2005-04-11 17:04:33 +04:00
|
|
|
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)");
|
2010-07-12 18:27:24 +04:00
|
|
|
module_param(dxs_init_volume, int, 0644);
|
|
|
|
MODULE_PARM_DESC(dxs_init_volume, "initial DXS volume (0-31)");
|
2009-06-21 22:50:48 +04:00
|
|
|
module_param(nodelay, int, 0444);
|
|
|
|
MODULE_PARM_DESC(nodelay, "Disable 500ms init delay");
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-10-06 15:47:23 +04:00
|
|
|
/* just for backward compatibility */
|
2011-12-15 07:19:36 +04:00
|
|
|
static bool enable;
|
2005-10-20 18:53:49 +04:00
|
|
|
module_param(enable, bool, 0444);
|
2005-10-06 15:47:23 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* revision numbers for via686 */
|
|
|
|
#define VIA_REV_686_A 0x10
|
|
|
|
#define VIA_REV_686_B 0x11
|
|
|
|
#define VIA_REV_686_C 0x12
|
|
|
|
#define VIA_REV_686_D 0x13
|
|
|
|
#define VIA_REV_686_E 0x14
|
|
|
|
#define VIA_REV_686_H 0x20
|
|
|
|
|
|
|
|
/* revision numbers for via8233 */
|
|
|
|
#define VIA_REV_PRE_8233 0x10 /* not in market */
|
|
|
|
#define VIA_REV_8233C 0x20 /* 2 rec, 4 pb, 1 multi-pb */
|
|
|
|
#define VIA_REV_8233 0x30 /* 2 rec, 4 pb, 1 multi-pb, spdif */
|
|
|
|
#define VIA_REV_8233A 0x40 /* 1 rec, 1 multi-pb, spdf */
|
|
|
|
#define VIA_REV_8235 0x50 /* 2 rec, 4 pb, 1 multi-pb, spdif */
|
|
|
|
#define VIA_REV_8237 0x60
|
2006-04-18 19:04:04 +04:00
|
|
|
#define VIA_REV_8251 0x70
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Direct registers
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define VIAREG(via, x) ((via)->port + VIA_REG_##x)
|
|
|
|
#define VIADEV_REG(viadev, x) ((viadev)->port + VIA_REG_##x)
|
|
|
|
|
|
|
|
/* common offsets */
|
|
|
|
#define VIA_REG_OFFSET_STATUS 0x00 /* byte - channel status */
|
|
|
|
#define VIA_REG_STAT_ACTIVE 0x80 /* RO */
|
2005-10-18 16:31:07 +04:00
|
|
|
#define VIA8233_SHADOW_STAT_ACTIVE 0x08 /* RO */
|
2005-04-17 02:20:36 +04:00
|
|
|
#define VIA_REG_STAT_PAUSED 0x40 /* RO */
|
|
|
|
#define VIA_REG_STAT_TRIGGER_QUEUED 0x08 /* RO */
|
|
|
|
#define VIA_REG_STAT_STOPPED 0x04 /* RWC */
|
|
|
|
#define VIA_REG_STAT_EOL 0x02 /* RWC */
|
|
|
|
#define VIA_REG_STAT_FLAG 0x01 /* RWC */
|
|
|
|
#define VIA_REG_OFFSET_CONTROL 0x01 /* byte - channel control */
|
|
|
|
#define VIA_REG_CTRL_START 0x80 /* WO */
|
|
|
|
#define VIA_REG_CTRL_TERMINATE 0x40 /* WO */
|
|
|
|
#define VIA_REG_CTRL_AUTOSTART 0x20
|
|
|
|
#define VIA_REG_CTRL_PAUSE 0x08 /* RW */
|
|
|
|
#define VIA_REG_CTRL_INT_STOP 0x04
|
|
|
|
#define VIA_REG_CTRL_INT_EOL 0x02
|
|
|
|
#define VIA_REG_CTRL_INT_FLAG 0x01
|
|
|
|
#define VIA_REG_CTRL_RESET 0x01 /* RW - probably reset? undocumented */
|
|
|
|
#define VIA_REG_CTRL_INT (VIA_REG_CTRL_INT_FLAG | VIA_REG_CTRL_INT_EOL | VIA_REG_CTRL_AUTOSTART)
|
|
|
|
#define VIA_REG_OFFSET_TYPE 0x02 /* byte - channel type (686 only) */
|
|
|
|
#define VIA_REG_TYPE_AUTOSTART 0x80 /* RW - autostart at EOL */
|
|
|
|
#define VIA_REG_TYPE_16BIT 0x20 /* RW */
|
|
|
|
#define VIA_REG_TYPE_STEREO 0x10 /* RW */
|
|
|
|
#define VIA_REG_TYPE_INT_LLINE 0x00
|
|
|
|
#define VIA_REG_TYPE_INT_LSAMPLE 0x04
|
|
|
|
#define VIA_REG_TYPE_INT_LESSONE 0x08
|
|
|
|
#define VIA_REG_TYPE_INT_MASK 0x0c
|
|
|
|
#define VIA_REG_TYPE_INT_EOL 0x02
|
|
|
|
#define VIA_REG_TYPE_INT_FLAG 0x01
|
|
|
|
#define VIA_REG_OFFSET_TABLE_PTR 0x04 /* dword - channel table pointer */
|
|
|
|
#define VIA_REG_OFFSET_CURR_PTR 0x04 /* dword - channel current pointer */
|
|
|
|
#define VIA_REG_OFFSET_STOP_IDX 0x08 /* dword - stop index, channel type, sample rate */
|
|
|
|
#define VIA8233_REG_TYPE_16BIT 0x00200000 /* RW */
|
|
|
|
#define VIA8233_REG_TYPE_STEREO 0x00100000 /* RW */
|
|
|
|
#define VIA_REG_OFFSET_CURR_COUNT 0x0c /* dword - channel current count (24 bit) */
|
|
|
|
#define VIA_REG_OFFSET_CURR_INDEX 0x0f /* byte - channel current index (for via8233 only) */
|
|
|
|
|
|
|
|
#define DEFINE_VIA_REGSET(name,val) \
|
|
|
|
enum {\
|
|
|
|
VIA_REG_##name##_STATUS = (val),\
|
|
|
|
VIA_REG_##name##_CONTROL = (val) + 0x01,\
|
|
|
|
VIA_REG_##name##_TYPE = (val) + 0x02,\
|
|
|
|
VIA_REG_##name##_TABLE_PTR = (val) + 0x04,\
|
|
|
|
VIA_REG_##name##_CURR_PTR = (val) + 0x04,\
|
|
|
|
VIA_REG_##name##_STOP_IDX = (val) + 0x08,\
|
|
|
|
VIA_REG_##name##_CURR_COUNT = (val) + 0x0c,\
|
|
|
|
}
|
|
|
|
|
|
|
|
/* playback block */
|
|
|
|
DEFINE_VIA_REGSET(PLAYBACK, 0x00);
|
|
|
|
DEFINE_VIA_REGSET(CAPTURE, 0x10);
|
|
|
|
DEFINE_VIA_REGSET(FM, 0x20);
|
|
|
|
|
|
|
|
/* AC'97 */
|
|
|
|
#define VIA_REG_AC97 0x80 /* dword */
|
|
|
|
#define VIA_REG_AC97_CODEC_ID_MASK (3<<30)
|
|
|
|
#define VIA_REG_AC97_CODEC_ID_SHIFT 30
|
|
|
|
#define VIA_REG_AC97_CODEC_ID_PRIMARY 0x00
|
|
|
|
#define VIA_REG_AC97_CODEC_ID_SECONDARY 0x01
|
|
|
|
#define VIA_REG_AC97_SECONDARY_VALID (1<<27)
|
|
|
|
#define VIA_REG_AC97_PRIMARY_VALID (1<<25)
|
|
|
|
#define VIA_REG_AC97_BUSY (1<<24)
|
|
|
|
#define VIA_REG_AC97_READ (1<<23)
|
|
|
|
#define VIA_REG_AC97_CMD_SHIFT 16
|
|
|
|
#define VIA_REG_AC97_CMD_MASK 0x7e
|
|
|
|
#define VIA_REG_AC97_DATA_SHIFT 0
|
|
|
|
#define VIA_REG_AC97_DATA_MASK 0xffff
|
|
|
|
|
|
|
|
#define VIA_REG_SGD_SHADOW 0x84 /* dword */
|
|
|
|
/* via686 */
|
|
|
|
#define VIA_REG_SGD_STAT_PB_FLAG (1<<0)
|
|
|
|
#define VIA_REG_SGD_STAT_CP_FLAG (1<<1)
|
|
|
|
#define VIA_REG_SGD_STAT_FM_FLAG (1<<2)
|
|
|
|
#define VIA_REG_SGD_STAT_PB_EOL (1<<4)
|
|
|
|
#define VIA_REG_SGD_STAT_CP_EOL (1<<5)
|
|
|
|
#define VIA_REG_SGD_STAT_FM_EOL (1<<6)
|
|
|
|
#define VIA_REG_SGD_STAT_PB_STOP (1<<8)
|
|
|
|
#define VIA_REG_SGD_STAT_CP_STOP (1<<9)
|
|
|
|
#define VIA_REG_SGD_STAT_FM_STOP (1<<10)
|
|
|
|
#define VIA_REG_SGD_STAT_PB_ACTIVE (1<<12)
|
|
|
|
#define VIA_REG_SGD_STAT_CP_ACTIVE (1<<13)
|
|
|
|
#define VIA_REG_SGD_STAT_FM_ACTIVE (1<<14)
|
|
|
|
/* via8233 */
|
|
|
|
#define VIA8233_REG_SGD_STAT_FLAG (1<<0)
|
|
|
|
#define VIA8233_REG_SGD_STAT_EOL (1<<1)
|
|
|
|
#define VIA8233_REG_SGD_STAT_STOP (1<<2)
|
|
|
|
#define VIA8233_REG_SGD_STAT_ACTIVE (1<<3)
|
|
|
|
#define VIA8233_INTR_MASK(chan) ((VIA8233_REG_SGD_STAT_FLAG|VIA8233_REG_SGD_STAT_EOL) << ((chan) * 4))
|
|
|
|
#define VIA8233_REG_SGD_CHAN_SDX 0
|
|
|
|
#define VIA8233_REG_SGD_CHAN_MULTI 4
|
|
|
|
#define VIA8233_REG_SGD_CHAN_REC 6
|
|
|
|
#define VIA8233_REG_SGD_CHAN_REC1 7
|
|
|
|
|
|
|
|
#define VIA_REG_GPI_STATUS 0x88
|
|
|
|
#define VIA_REG_GPI_INTR 0x8c
|
|
|
|
|
|
|
|
/* multi-channel and capture registers for via8233 */
|
|
|
|
DEFINE_VIA_REGSET(MULTPLAY, 0x40);
|
|
|
|
DEFINE_VIA_REGSET(CAPTURE_8233, 0x60);
|
|
|
|
|
|
|
|
/* via8233-specific registers */
|
|
|
|
#define VIA_REG_OFS_PLAYBACK_VOLUME_L 0x02 /* byte */
|
|
|
|
#define VIA_REG_OFS_PLAYBACK_VOLUME_R 0x03 /* byte */
|
|
|
|
#define VIA_REG_OFS_MULTPLAY_FORMAT 0x02 /* byte - format and channels */
|
|
|
|
#define VIA_REG_MULTPLAY_FMT_8BIT 0x00
|
|
|
|
#define VIA_REG_MULTPLAY_FMT_16BIT 0x80
|
|
|
|
#define VIA_REG_MULTPLAY_FMT_CH_MASK 0x70 /* # channels << 4 (valid = 1,2,4,6) */
|
|
|
|
#define VIA_REG_OFS_CAPTURE_FIFO 0x02 /* byte - bit 6 = fifo enable */
|
|
|
|
#define VIA_REG_CAPTURE_FIFO_ENABLE 0x40
|
|
|
|
|
|
|
|
#define VIA_DXS_MAX_VOLUME 31 /* max. volume (attenuation) of reg 0x32/33 */
|
|
|
|
|
|
|
|
#define VIA_REG_CAPTURE_CHANNEL 0x63 /* byte - input select */
|
|
|
|
#define VIA_REG_CAPTURE_CHANNEL_MIC 0x4
|
|
|
|
#define VIA_REG_CAPTURE_CHANNEL_LINE 0
|
|
|
|
#define VIA_REG_CAPTURE_SELECT_CODEC 0x03 /* recording source codec (0 = primary) */
|
|
|
|
|
|
|
|
#define VIA_TBL_BIT_FLAG 0x40000000
|
|
|
|
#define VIA_TBL_BIT_EOL 0x80000000
|
|
|
|
|
|
|
|
/* pci space */
|
|
|
|
#define VIA_ACLINK_STAT 0x40
|
|
|
|
#define VIA_ACLINK_C11_READY 0x20
|
|
|
|
#define VIA_ACLINK_C10_READY 0x10
|
|
|
|
#define VIA_ACLINK_C01_READY 0x04 /* secondary codec ready */
|
|
|
|
#define VIA_ACLINK_LOWPOWER 0x02 /* low-power state */
|
|
|
|
#define VIA_ACLINK_C00_READY 0x01 /* primary codec ready */
|
|
|
|
#define VIA_ACLINK_CTRL 0x41
|
|
|
|
#define VIA_ACLINK_CTRL_ENABLE 0x80 /* 0: disable, 1: enable */
|
|
|
|
#define VIA_ACLINK_CTRL_RESET 0x40 /* 0: assert, 1: de-assert */
|
|
|
|
#define VIA_ACLINK_CTRL_SYNC 0x20 /* 0: release SYNC, 1: force SYNC hi */
|
|
|
|
#define VIA_ACLINK_CTRL_SDO 0x10 /* 0: release SDO, 1: force SDO hi */
|
|
|
|
#define VIA_ACLINK_CTRL_VRA 0x08 /* 0: disable VRA, 1: enable VRA */
|
|
|
|
#define VIA_ACLINK_CTRL_PCM 0x04 /* 0: disable PCM, 1: enable PCM */
|
|
|
|
#define VIA_ACLINK_CTRL_FM 0x02 /* via686 only */
|
|
|
|
#define VIA_ACLINK_CTRL_SB 0x01 /* via686 only */
|
|
|
|
#define VIA_ACLINK_CTRL_INIT (VIA_ACLINK_CTRL_ENABLE|\
|
|
|
|
VIA_ACLINK_CTRL_RESET|\
|
|
|
|
VIA_ACLINK_CTRL_PCM|\
|
|
|
|
VIA_ACLINK_CTRL_VRA)
|
|
|
|
#define VIA_FUNC_ENABLE 0x42
|
|
|
|
#define VIA_FUNC_MIDI_PNP 0x80 /* FIXME: it's 0x40 in the datasheet! */
|
|
|
|
#define VIA_FUNC_MIDI_IRQMASK 0x40 /* FIXME: not documented! */
|
|
|
|
#define VIA_FUNC_RX2C_WRITE 0x20
|
|
|
|
#define VIA_FUNC_SB_FIFO_EMPTY 0x10
|
|
|
|
#define VIA_FUNC_ENABLE_GAME 0x08
|
|
|
|
#define VIA_FUNC_ENABLE_FM 0x04
|
|
|
|
#define VIA_FUNC_ENABLE_MIDI 0x02
|
|
|
|
#define VIA_FUNC_ENABLE_SB 0x01
|
|
|
|
#define VIA_PNP_CONTROL 0x43
|
|
|
|
#define VIA_FM_NMI_CTRL 0x48
|
|
|
|
#define VIA8233_VOLCHG_CTRL 0x48
|
|
|
|
#define VIA8233_SPDIF_CTRL 0x49
|
|
|
|
#define VIA8233_SPDIF_DX3 0x08
|
|
|
|
#define VIA8233_SPDIF_SLOT_MASK 0x03
|
|
|
|
#define VIA8233_SPDIF_SLOT_1011 0x00
|
|
|
|
#define VIA8233_SPDIF_SLOT_34 0x01
|
|
|
|
#define VIA8233_SPDIF_SLOT_78 0x02
|
|
|
|
#define VIA8233_SPDIF_SLOT_69 0x03
|
|
|
|
|
|
|
|
/*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define VIA_DXS_AUTO 0
|
|
|
|
#define VIA_DXS_ENABLE 1
|
|
|
|
#define VIA_DXS_DISABLE 2
|
|
|
|
#define VIA_DXS_48K 3
|
|
|
|
#define VIA_DXS_NO_VRA 4
|
2005-04-11 17:04:33 +04:00
|
|
|
#define VIA_DXS_SRC 5
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pcm stream
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct snd_via_sg_table {
|
|
|
|
unsigned int offset;
|
|
|
|
unsigned int size;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
#define VIA_TABLE_SIZE 255
|
2008-07-30 17:23:06 +04:00
|
|
|
#define VIA_MAX_BUFSIZE (1<<24)
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
struct viadev {
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned int reg_offset;
|
|
|
|
unsigned long port;
|
|
|
|
int direction; /* playback = 0, capture = 1 */
|
2005-11-17 17:06:15 +03:00
|
|
|
struct snd_pcm_substream *substream;
|
2005-04-17 02:20:36 +04:00
|
|
|
int running;
|
|
|
|
unsigned int tbl_entries; /* # descriptors */
|
|
|
|
struct snd_dma_buffer table;
|
|
|
|
struct snd_via_sg_table *idx_table;
|
|
|
|
/* for recovery from the unexpected pointer */
|
|
|
|
unsigned int lastpos;
|
|
|
|
unsigned int fragsize;
|
|
|
|
unsigned int bufsize;
|
|
|
|
unsigned int bufsize2;
|
2005-10-18 16:31:07 +04:00
|
|
|
int hwptr_done; /* processed frame position in the buffer */
|
|
|
|
int in_interrupt;
|
|
|
|
int shadow_shift;
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum { TYPE_CARD_VIA686 = 1, TYPE_CARD_VIA8233 };
|
|
|
|
enum { TYPE_VIA686, TYPE_VIA8233, TYPE_VIA8233A };
|
|
|
|
|
|
|
|
#define VIA_MAX_DEVS 7 /* 4 playback, 1 multi, 2 capture */
|
|
|
|
|
|
|
|
struct via_rate_lock {
|
|
|
|
spinlock_t lock;
|
|
|
|
int rate;
|
|
|
|
int used;
|
|
|
|
};
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx {
|
2005-04-17 02:20:36 +04:00
|
|
|
int irq;
|
|
|
|
|
|
|
|
unsigned long port;
|
|
|
|
struct resource *mpu_res;
|
|
|
|
int chip_type;
|
|
|
|
unsigned char revision;
|
|
|
|
|
|
|
|
unsigned char old_legacy;
|
|
|
|
unsigned char old_legacy_cfg;
|
2012-08-14 20:12:04 +04:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned char legacy_saved;
|
|
|
|
unsigned char legacy_cfg_saved;
|
|
|
|
unsigned char spdif_ctrl_saved;
|
|
|
|
unsigned char capture_src_saved[2];
|
|
|
|
unsigned int mpu_port_saved;
|
|
|
|
#endif
|
|
|
|
|
2005-10-14 20:18:01 +04:00
|
|
|
unsigned char playback_volume[4][2]; /* for VIA8233/C/8235; default = 0 */
|
|
|
|
unsigned char playback_volume_c[2]; /* for VIA8233/C/8235; default = 0 */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
unsigned int intr_mask; /* SGD_SHADOW mask to check interrupts */
|
|
|
|
|
|
|
|
struct pci_dev *pci;
|
2005-11-17 17:06:15 +03:00
|
|
|
struct snd_card *card;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
unsigned int num_devs;
|
|
|
|
unsigned int playback_devno, multi_devno, capture_devno;
|
2005-11-17 17:06:15 +03:00
|
|
|
struct viadev devs[VIA_MAX_DEVS];
|
2005-04-17 02:20:36 +04:00
|
|
|
struct via_rate_lock rates[2]; /* playback and capture */
|
|
|
|
unsigned int dxs_fixed: 1; /* DXS channel accepts only 48kHz */
|
|
|
|
unsigned int no_vra: 1; /* no need to set VRA on DXS channels */
|
2005-04-11 17:04:33 +04:00
|
|
|
unsigned int dxs_src: 1; /* use full SRC capabilities of DXS */
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned int spdif_on: 1; /* only spdif rates work to external DACs */
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
struct snd_pcm *pcms[2];
|
|
|
|
struct snd_rawmidi *rmidi;
|
2009-10-22 11:04:09 +04:00
|
|
|
struct snd_kcontrol *dxs_controls[4];
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
struct snd_ac97_bus *ac97_bus;
|
|
|
|
struct snd_ac97 *ac97;
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned int ac97_clock;
|
|
|
|
unsigned int ac97_secondary; /* secondary AC'97 codec is present */
|
|
|
|
|
|
|
|
spinlock_t reg_lock;
|
2005-11-17 17:06:15 +03:00
|
|
|
struct snd_info_entry *proc_entry;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
#ifdef SUPPORT_JOYSTICK
|
|
|
|
struct gameport *gameport;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2014-08-08 17:56:03 +04:00
|
|
|
static const struct pci_device_id snd_via82xx_ids[] = {
|
2005-10-18 16:31:07 +04:00
|
|
|
/* 0x1106, 0x3058 */
|
2009-06-25 09:13:35 +04:00
|
|
|
{ PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_82C686_5), TYPE_CARD_VIA686, }, /* 686A */
|
2005-10-18 16:31:07 +04:00
|
|
|
/* 0x1106, 0x3059 */
|
2009-06-25 09:13:35 +04:00
|
|
|
{ PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_8233_5), TYPE_CARD_VIA8233, }, /* VT8233 */
|
2005-04-17 02:20:36 +04:00
|
|
|
{ 0, }
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(pci, snd_via82xx_ids);
|
|
|
|
|
|
|
|
/*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* allocate and initialize the descriptor buffers
|
|
|
|
* periods = number of periods
|
|
|
|
* fragsize = period size in bytes
|
|
|
|
*/
|
2005-11-17 17:06:15 +03:00
|
|
|
static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substream,
|
2005-04-17 02:20:36 +04:00
|
|
|
struct pci_dev *pci,
|
|
|
|
unsigned int periods, unsigned int fragsize)
|
|
|
|
{
|
|
|
|
unsigned int i, idx, ofs, rest;
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_pcm_substream_chip(substream);
|
2020-02-06 19:31:50 +03:00
|
|
|
__le32 *pgtbl;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (dev->table.area == NULL) {
|
|
|
|
/* the start of each lists must be aligned to 8 bytes,
|
|
|
|
* but the kernel pages are much bigger, so we don't care
|
|
|
|
*/
|
2019-11-05 18:18:55 +03:00
|
|
|
if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &chip->pci->dev,
|
2005-04-17 02:20:36 +04:00
|
|
|
PAGE_ALIGN(VIA_TABLE_SIZE * 2 * 8),
|
|
|
|
&dev->table) < 0)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
if (! dev->idx_table) {
|
treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:
kmalloc(a * b, gfp)
with:
kmalloc_array(a * b, gfp)
as well as handling cases of:
kmalloc(a * b * c, gfp)
with:
kmalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kmalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kmalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The tools/ directory was manually excluded, since it has its own
implementation of kmalloc().
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kmalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kmalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kmalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kmalloc
+ kmalloc_array
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kmalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kmalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kmalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kmalloc(sizeof(THING) * C2, ...)
|
kmalloc(sizeof(TYPE) * C2, ...)
|
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(C1 * C2, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * E2
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 23:55:00 +03:00
|
|
|
dev->idx_table = kmalloc_array(VIA_TABLE_SIZE,
|
|
|
|
sizeof(*dev->idx_table),
|
|
|
|
GFP_KERNEL);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (! dev->idx_table)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fill the entries */
|
|
|
|
idx = 0;
|
|
|
|
ofs = 0;
|
2020-02-06 19:31:50 +03:00
|
|
|
pgtbl = (__le32 *)dev->table.area;
|
2005-04-17 02:20:36 +04:00
|
|
|
for (i = 0; i < periods; i++) {
|
|
|
|
rest = fragsize;
|
|
|
|
/* fill descriptors for a period.
|
|
|
|
* a period can be split to several descriptors if it's
|
|
|
|
* over page boundary.
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
unsigned int r;
|
|
|
|
unsigned int flag;
|
2008-08-21 15:00:13 +04:00
|
|
|
unsigned int addr;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (idx >= VIA_TABLE_SIZE) {
|
2014-02-25 18:21:56 +04:00
|
|
|
dev_err(&pci->dev, "too much table size!\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2008-08-21 15:00:13 +04:00
|
|
|
addr = snd_pcm_sgbuf_get_addr(substream, ofs);
|
2020-02-06 19:31:50 +03:00
|
|
|
pgtbl[idx << 1] = cpu_to_le32(addr);
|
2008-07-30 17:23:06 +04:00
|
|
|
r = snd_pcm_sgbuf_get_chunk_size(substream, ofs, rest);
|
2005-04-17 02:20:36 +04:00
|
|
|
rest -= r;
|
|
|
|
if (! rest) {
|
|
|
|
if (i == periods - 1)
|
|
|
|
flag = VIA_TBL_BIT_EOL; /* buffer boundary */
|
|
|
|
else
|
|
|
|
flag = VIA_TBL_BIT_FLAG; /* period boundary */
|
|
|
|
} else
|
|
|
|
flag = 0; /* period continues to the next */
|
2009-02-05 18:11:31 +03:00
|
|
|
/*
|
2014-02-25 18:21:56 +04:00
|
|
|
dev_dbg(&pci->dev,
|
|
|
|
"tbl %d: at %d size %d (rest %d)\n",
|
|
|
|
idx, ofs, r, rest);
|
2009-02-05 18:11:31 +03:00
|
|
|
*/
|
2020-02-06 19:31:50 +03:00
|
|
|
pgtbl[(idx<<1) + 1] = cpu_to_le32(r | flag);
|
2005-04-17 02:20:36 +04:00
|
|
|
dev->idx_table[idx].offset = ofs;
|
|
|
|
dev->idx_table[idx].size = r;
|
|
|
|
ofs += r;
|
|
|
|
idx++;
|
|
|
|
} while (rest > 0);
|
|
|
|
}
|
|
|
|
dev->tbl_entries = idx;
|
|
|
|
dev->bufsize = periods * fragsize;
|
|
|
|
dev->bufsize2 = dev->bufsize / 2;
|
|
|
|
dev->fragsize = fragsize;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static int clean_via_table(struct viadev *dev, struct snd_pcm_substream *substream,
|
2005-04-17 02:20:36 +04:00
|
|
|
struct pci_dev *pci)
|
|
|
|
{
|
|
|
|
if (dev->table.area) {
|
|
|
|
snd_dma_free_pages(&dev->table);
|
|
|
|
dev->table.area = NULL;
|
|
|
|
}
|
[ALSA] Remove redundant NULL checks before kfree
Timer Midlevel,ALSA sequencer,ALSA<-OSS sequencer,Digigram VX core
I2C tea6330t,GUS Library,VIA82xx driver,VIA82xx-modem driver
CA0106 driver,CS46xx driver,EMU10K1/EMU10K2 driver,YMFPCI driver
Digigram VX Pocket driver,Common EMU synth,USB generic driver,USB USX2Y
Checking a pointer for NULL before calling kfree() on it is redundant,
kfree() deals with NULL pointers just fine.
This patch removes such checks from sound/
This patch also makes another, but closely related, change.
It avoids casting pointers about to be kfree()'ed.
Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2005-05-30 19:30:32 +04:00
|
|
|
kfree(dev->idx_table);
|
|
|
|
dev->idx_table = NULL;
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Basic I/O
|
|
|
|
*/
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static inline unsigned int snd_via82xx_codec_xread(struct via82xx *chip)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
return inl(VIAREG(chip, AC97));
|
|
|
|
}
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static inline void snd_via82xx_codec_xwrite(struct via82xx *chip, unsigned int val)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
outl(val, VIAREG(chip, AC97));
|
|
|
|
}
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via82xx_codec_ready(struct via82xx *chip, int secondary)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
unsigned int timeout = 1000; /* 1ms */
|
|
|
|
unsigned int val;
|
|
|
|
|
|
|
|
while (timeout-- > 0) {
|
|
|
|
udelay(1);
|
|
|
|
if (!((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY))
|
|
|
|
return val & 0xffff;
|
|
|
|
}
|
2014-02-25 18:21:56 +04:00
|
|
|
dev_err(chip->card->dev, "codec_ready: codec %i is not ready [0x%x]\n",
|
2005-11-17 17:06:15 +03:00
|
|
|
secondary, snd_via82xx_codec_xread(chip));
|
2005-04-17 02:20:36 +04:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via82xx_codec_valid(struct via82xx *chip, int secondary)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
unsigned int timeout = 1000; /* 1ms */
|
|
|
|
unsigned int val, val1;
|
|
|
|
unsigned int stat = !secondary ? VIA_REG_AC97_PRIMARY_VALID :
|
|
|
|
VIA_REG_AC97_SECONDARY_VALID;
|
|
|
|
|
|
|
|
while (timeout-- > 0) {
|
|
|
|
val = snd_via82xx_codec_xread(chip);
|
|
|
|
val1 = val & (VIA_REG_AC97_BUSY | stat);
|
|
|
|
if (val1 == stat)
|
|
|
|
return val & 0xffff;
|
|
|
|
udelay(1);
|
|
|
|
}
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static void snd_via82xx_codec_wait(struct snd_ac97 *ac97)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = ac97->private_data;
|
2005-04-17 02:20:36 +04:00
|
|
|
int err;
|
|
|
|
err = snd_via82xx_codec_ready(chip, ac97->num);
|
|
|
|
/* here we need to wait fairly for long time.. */
|
2009-06-21 22:50:48 +04:00
|
|
|
if (!nodelay)
|
|
|
|
msleep(500);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static void snd_via82xx_codec_write(struct snd_ac97 *ac97,
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned short reg,
|
|
|
|
unsigned short val)
|
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = ac97->private_data;
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned int xval;
|
2005-10-18 16:31:07 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
xval = !ac97->num ? VIA_REG_AC97_CODEC_ID_PRIMARY : VIA_REG_AC97_CODEC_ID_SECONDARY;
|
|
|
|
xval <<= VIA_REG_AC97_CODEC_ID_SHIFT;
|
|
|
|
xval |= reg << VIA_REG_AC97_CMD_SHIFT;
|
|
|
|
xval |= val << VIA_REG_AC97_DATA_SHIFT;
|
|
|
|
snd_via82xx_codec_xwrite(chip, xval);
|
|
|
|
snd_via82xx_codec_ready(chip, ac97->num);
|
|
|
|
}
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static unsigned short snd_via82xx_codec_read(struct snd_ac97 *ac97, unsigned short reg)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = ac97->private_data;
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned int xval, val = 0xffff;
|
|
|
|
int again = 0;
|
|
|
|
|
|
|
|
xval = ac97->num << VIA_REG_AC97_CODEC_ID_SHIFT;
|
|
|
|
xval |= ac97->num ? VIA_REG_AC97_SECONDARY_VALID : VIA_REG_AC97_PRIMARY_VALID;
|
|
|
|
xval |= VIA_REG_AC97_READ;
|
|
|
|
xval |= (reg & 0x7f) << VIA_REG_AC97_CMD_SHIFT;
|
|
|
|
while (1) {
|
|
|
|
if (again++ > 3) {
|
2014-02-25 18:21:56 +04:00
|
|
|
dev_err(chip->card->dev,
|
|
|
|
"codec_read: codec %i is not valid [0x%x]\n",
|
2005-11-17 17:06:15 +03:00
|
|
|
ac97->num, snd_via82xx_codec_xread(chip));
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0xffff;
|
|
|
|
}
|
|
|
|
snd_via82xx_codec_xwrite(chip, xval);
|
|
|
|
udelay (20);
|
|
|
|
if (snd_via82xx_codec_valid(chip, ac97->num) >= 0) {
|
|
|
|
udelay(25);
|
|
|
|
val = snd_via82xx_codec_xread(chip);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return val & 0xffff;
|
|
|
|
}
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static void snd_via82xx_channel_reset(struct via82xx *chip, struct viadev *viadev)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
outb(VIA_REG_CTRL_PAUSE | VIA_REG_CTRL_TERMINATE | VIA_REG_CTRL_RESET,
|
|
|
|
VIADEV_REG(viadev, OFFSET_CONTROL));
|
|
|
|
inb(VIADEV_REG(viadev, OFFSET_CONTROL));
|
|
|
|
udelay(50);
|
|
|
|
/* disable interrupts */
|
|
|
|
outb(0x00, VIADEV_REG(viadev, OFFSET_CONTROL));
|
|
|
|
/* clear interrupts */
|
|
|
|
outb(0x03, VIADEV_REG(viadev, OFFSET_STATUS));
|
|
|
|
outb(0x00, VIADEV_REG(viadev, OFFSET_TYPE)); /* for via686 */
|
|
|
|
// outl(0, VIADEV_REG(viadev, OFFSET_CURR_PTR));
|
|
|
|
viadev->lastpos = 0;
|
2005-10-18 16:31:07 +04:00
|
|
|
viadev->hwptr_done = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interrupt handler
|
2005-10-18 16:31:07 +04:00
|
|
|
* Used for 686 and 8233A
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
|
|
|
static irqreturn_t snd_via686_interrupt(int irq, void *dev_id)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = dev_id;
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned int status;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
status = inl(VIAREG(chip, SGD_SHADOW));
|
|
|
|
if (! (status & chip->intr_mask)) {
|
|
|
|
if (chip->rmidi)
|
|
|
|
/* check mpu401 interrupt */
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
|
|
|
return snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
|
2005-04-17 02:20:36 +04:00
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check status for each stream */
|
|
|
|
spin_lock(&chip->reg_lock);
|
|
|
|
for (i = 0; i < chip->num_devs; i++) {
|
2005-11-17 17:06:15 +03:00
|
|
|
struct viadev *viadev = &chip->devs[i];
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned char c_status = inb(VIADEV_REG(viadev, OFFSET_STATUS));
|
2005-10-18 16:31:07 +04:00
|
|
|
if (! (c_status & (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG|VIA_REG_STAT_STOPPED)))
|
2005-04-17 02:20:36 +04:00
|
|
|
continue;
|
|
|
|
if (viadev->substream && viadev->running) {
|
2005-10-18 16:31:07 +04:00
|
|
|
/*
|
|
|
|
* Update hwptr_done based on 'period elapsed'
|
|
|
|
* interrupts. We'll use it, when the chip returns 0
|
|
|
|
* for OFFSET_CURR_COUNT.
|
|
|
|
*/
|
|
|
|
if (c_status & VIA_REG_STAT_EOL)
|
|
|
|
viadev->hwptr_done = 0;
|
|
|
|
else
|
|
|
|
viadev->hwptr_done += viadev->fragsize;
|
|
|
|
viadev->in_interrupt = c_status;
|
2005-04-17 02:20:36 +04:00
|
|
|
spin_unlock(&chip->reg_lock);
|
|
|
|
snd_pcm_period_elapsed(viadev->substream);
|
|
|
|
spin_lock(&chip->reg_lock);
|
2005-10-18 16:31:07 +04:00
|
|
|
viadev->in_interrupt = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */
|
|
|
|
}
|
|
|
|
spin_unlock(&chip->reg_lock);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2005-10-18 16:31:07 +04:00
|
|
|
/*
|
|
|
|
* Interrupt handler
|
|
|
|
*/
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
|
|
|
static irqreturn_t snd_via8233_interrupt(int irq, void *dev_id)
|
2005-10-18 16:31:07 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = dev_id;
|
2005-10-18 16:31:07 +04:00
|
|
|
unsigned int status;
|
|
|
|
unsigned int i;
|
|
|
|
int irqreturn = 0;
|
|
|
|
|
|
|
|
/* check status for each stream */
|
|
|
|
spin_lock(&chip->reg_lock);
|
|
|
|
status = inl(VIAREG(chip, SGD_SHADOW));
|
|
|
|
|
|
|
|
for (i = 0; i < chip->num_devs; i++) {
|
2005-11-17 17:06:15 +03:00
|
|
|
struct viadev *viadev = &chip->devs[i];
|
|
|
|
struct snd_pcm_substream *substream;
|
2005-10-18 16:31:07 +04:00
|
|
|
unsigned char c_status, shadow_status;
|
|
|
|
|
|
|
|
shadow_status = (status >> viadev->shadow_shift) &
|
|
|
|
(VIA8233_SHADOW_STAT_ACTIVE|VIA_REG_STAT_EOL|
|
|
|
|
VIA_REG_STAT_FLAG);
|
|
|
|
c_status = shadow_status & (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG);
|
|
|
|
if (!c_status)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
substream = viadev->substream;
|
|
|
|
if (substream && viadev->running) {
|
|
|
|
/*
|
|
|
|
* Update hwptr_done based on 'period elapsed'
|
|
|
|
* interrupts. We'll use it, when the chip returns 0
|
|
|
|
* for OFFSET_CURR_COUNT.
|
|
|
|
*/
|
|
|
|
if (c_status & VIA_REG_STAT_EOL)
|
|
|
|
viadev->hwptr_done = 0;
|
|
|
|
else
|
|
|
|
viadev->hwptr_done += viadev->fragsize;
|
|
|
|
viadev->in_interrupt = c_status;
|
|
|
|
if (shadow_status & VIA8233_SHADOW_STAT_ACTIVE)
|
|
|
|
viadev->in_interrupt |= VIA_REG_STAT_ACTIVE;
|
|
|
|
spin_unlock(&chip->reg_lock);
|
|
|
|
|
|
|
|
snd_pcm_period_elapsed(substream);
|
|
|
|
|
|
|
|
spin_lock(&chip->reg_lock);
|
|
|
|
viadev->in_interrupt = 0;
|
|
|
|
}
|
|
|
|
outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */
|
|
|
|
irqreturn = 1;
|
|
|
|
}
|
|
|
|
spin_unlock(&chip->reg_lock);
|
|
|
|
return IRQ_RETVAL(irqreturn);
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* PCM callbacks
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* trigger callback
|
|
|
|
*/
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via82xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_pcm_substream_chip(substream);
|
|
|
|
struct viadev *viadev = substream->runtime->private_data;
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned char val;
|
|
|
|
|
|
|
|
if (chip->chip_type != TYPE_VIA686)
|
|
|
|
val = VIA_REG_CTRL_INT;
|
|
|
|
else
|
|
|
|
val = 0;
|
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_PCM_TRIGGER_START:
|
2005-08-18 15:43:12 +04:00
|
|
|
case SNDRV_PCM_TRIGGER_RESUME:
|
2005-04-17 02:20:36 +04:00
|
|
|
val |= VIA_REG_CTRL_START;
|
|
|
|
viadev->running = 1;
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
2005-08-18 15:43:12 +04:00
|
|
|
case SNDRV_PCM_TRIGGER_SUSPEND:
|
2005-04-17 02:20:36 +04:00
|
|
|
val = VIA_REG_CTRL_TERMINATE;
|
|
|
|
viadev->running = 0;
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
|
|
|
val |= VIA_REG_CTRL_PAUSE;
|
|
|
|
viadev->running = 0;
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
|
|
|
|
viadev->running = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
outb(val, VIADEV_REG(viadev, OFFSET_CONTROL));
|
|
|
|
if (cmd == SNDRV_PCM_TRIGGER_STOP)
|
|
|
|
snd_via82xx_channel_reset(chip, viadev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pointer callbacks
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* calculate the linear position at the given sg-buffer index and the rest count
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define check_invalid_pos(viadev,pos) \
|
2005-11-17 17:06:15 +03:00
|
|
|
((pos) < viadev->lastpos && ((pos) >= viadev->bufsize2 ||\
|
|
|
|
viadev->lastpos < viadev->bufsize2))
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-02-25 18:21:56 +04:00
|
|
|
static inline unsigned int calc_linear_pos(struct via82xx *chip,
|
|
|
|
struct viadev *viadev,
|
|
|
|
unsigned int idx,
|
2005-11-17 17:06:15 +03:00
|
|
|
unsigned int count)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
unsigned int size, base, res;
|
|
|
|
|
|
|
|
size = viadev->idx_table[idx].size;
|
|
|
|
base = viadev->idx_table[idx].offset;
|
|
|
|
res = base + size - count;
|
2005-10-18 16:31:07 +04:00
|
|
|
if (res >= viadev->bufsize)
|
|
|
|
res -= viadev->bufsize;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* check the validity of the calculated position */
|
|
|
|
if (size < count) {
|
2014-02-25 18:21:56 +04:00
|
|
|
dev_dbg(chip->card->dev,
|
|
|
|
"invalid via82xx_cur_ptr (size = %d, count = %d)\n",
|
2005-11-17 17:06:15 +03:00
|
|
|
(int)size, (int)count);
|
2005-04-17 02:20:36 +04:00
|
|
|
res = viadev->lastpos;
|
|
|
|
} else {
|
|
|
|
if (! count) {
|
|
|
|
/* Some mobos report count = 0 on the DMA boundary,
|
|
|
|
* i.e. count = size indeed.
|
|
|
|
* Let's check whether this step is above the expected size.
|
|
|
|
*/
|
|
|
|
int delta = res - viadev->lastpos;
|
|
|
|
if (delta < 0)
|
|
|
|
delta += viadev->bufsize;
|
|
|
|
if ((unsigned int)delta > viadev->fragsize)
|
|
|
|
res = base;
|
|
|
|
}
|
|
|
|
if (check_invalid_pos(viadev, res)) {
|
|
|
|
#ifdef POINTER_DEBUG
|
2014-02-25 18:21:56 +04:00
|
|
|
dev_dbg(chip->card->dev,
|
|
|
|
"fail: idx = %i/%i, lastpos = 0x%x, bufsize2 = 0x%x, offsize = 0x%x, size = 0x%x, count = 0x%x\n",
|
|
|
|
idx, viadev->tbl_entries,
|
2005-11-17 17:06:15 +03:00
|
|
|
viadev->lastpos, viadev->bufsize2,
|
|
|
|
viadev->idx_table[idx].offset,
|
|
|
|
viadev->idx_table[idx].size, count);
|
2005-04-17 02:20:36 +04:00
|
|
|
#endif
|
|
|
|
/* count register returns full size when end of buffer is reached */
|
|
|
|
res = base + size;
|
|
|
|
if (check_invalid_pos(viadev, res)) {
|
2014-02-25 18:21:56 +04:00
|
|
|
dev_dbg(chip->card->dev,
|
|
|
|
"invalid via82xx_cur_ptr (2), using last valid pointer\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
res = viadev->lastpos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get the current pointer on via686
|
|
|
|
*/
|
2005-11-17 17:06:15 +03:00
|
|
|
static snd_pcm_uframes_t snd_via686_pcm_pointer(struct snd_pcm_substream *substream)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_pcm_substream_chip(substream);
|
|
|
|
struct viadev *viadev = substream->runtime->private_data;
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned int idx, ptr, count, res;
|
|
|
|
|
2008-08-08 19:12:14 +04:00
|
|
|
if (snd_BUG_ON(!viadev->tbl_entries))
|
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (!(inb(VIADEV_REG(viadev, OFFSET_STATUS)) & VIA_REG_STAT_ACTIVE))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
spin_lock(&chip->reg_lock);
|
|
|
|
count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT)) & 0xffffff;
|
|
|
|
/* The via686a does not have the current index register,
|
|
|
|
* so we need to calculate the index from CURR_PTR.
|
|
|
|
*/
|
|
|
|
ptr = inl(VIADEV_REG(viadev, OFFSET_CURR_PTR));
|
|
|
|
if (ptr <= (unsigned int)viadev->table.addr)
|
|
|
|
idx = 0;
|
|
|
|
else /* CURR_PTR holds the address + 8 */
|
|
|
|
idx = ((ptr - (unsigned int)viadev->table.addr) / 8 - 1) % viadev->tbl_entries;
|
2014-02-25 18:21:56 +04:00
|
|
|
res = calc_linear_pos(chip, viadev, idx, count);
|
2005-10-18 16:31:07 +04:00
|
|
|
viadev->lastpos = res; /* remember the last position */
|
2005-04-17 02:20:36 +04:00
|
|
|
spin_unlock(&chip->reg_lock);
|
|
|
|
|
|
|
|
return bytes_to_frames(substream->runtime, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get the current pointer on via823x
|
|
|
|
*/
|
2005-11-17 17:06:15 +03:00
|
|
|
static snd_pcm_uframes_t snd_via8233_pcm_pointer(struct snd_pcm_substream *substream)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_pcm_substream_chip(substream);
|
|
|
|
struct viadev *viadev = substream->runtime->private_data;
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned int idx, count, res;
|
2005-10-18 16:31:07 +04:00
|
|
|
int status;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-08-08 19:12:14 +04:00
|
|
|
if (snd_BUG_ON(!viadev->tbl_entries))
|
|
|
|
return 0;
|
2005-10-18 16:31:07 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
spin_lock(&chip->reg_lock);
|
2005-10-18 16:31:07 +04:00
|
|
|
count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT));
|
|
|
|
status = viadev->in_interrupt;
|
|
|
|
if (!status)
|
|
|
|
status = inb(VIADEV_REG(viadev, OFFSET_STATUS));
|
|
|
|
|
2006-04-20 14:27:09 +04:00
|
|
|
/* An apparent bug in the 8251 is worked around by sending a
|
|
|
|
* REG_CTRL_START. */
|
|
|
|
if (chip->revision == VIA_REV_8251 && (status & VIA_REG_STAT_EOL))
|
|
|
|
snd_via82xx_pcm_trigger(substream, SNDRV_PCM_TRIGGER_START);
|
|
|
|
|
2005-10-18 16:31:07 +04:00
|
|
|
if (!(status & VIA_REG_STAT_ACTIVE)) {
|
2006-04-20 14:27:09 +04:00
|
|
|
res = 0;
|
|
|
|
goto unlock;
|
2005-10-18 16:31:07 +04:00
|
|
|
}
|
|
|
|
if (count & 0xffffff) {
|
|
|
|
idx = count >> 24;
|
|
|
|
if (idx >= viadev->tbl_entries) {
|
2005-04-17 02:20:36 +04:00
|
|
|
#ifdef POINTER_DEBUG
|
2014-02-25 18:21:56 +04:00
|
|
|
dev_dbg(chip->card->dev,
|
|
|
|
"fail: invalid idx = %i/%i\n", idx,
|
2005-11-17 17:06:15 +03:00
|
|
|
viadev->tbl_entries);
|
2005-04-17 02:20:36 +04:00
|
|
|
#endif
|
2005-10-18 16:31:07 +04:00
|
|
|
res = viadev->lastpos;
|
|
|
|
} else {
|
|
|
|
count &= 0xffffff;
|
2014-02-25 18:21:56 +04:00
|
|
|
res = calc_linear_pos(chip, viadev, idx, count);
|
2005-10-18 16:31:07 +04:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
} else {
|
2005-10-18 16:31:07 +04:00
|
|
|
res = viadev->hwptr_done;
|
|
|
|
if (!viadev->in_interrupt) {
|
|
|
|
if (status & VIA_REG_STAT_EOL) {
|
|
|
|
res = 0;
|
|
|
|
} else
|
|
|
|
if (status & VIA_REG_STAT_FLAG) {
|
|
|
|
res += viadev->fragsize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unlock:
|
|
|
|
viadev->lastpos = res;
|
2005-04-17 02:20:36 +04:00
|
|
|
spin_unlock(&chip->reg_lock);
|
|
|
|
|
|
|
|
return bytes_to_frames(substream->runtime, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* hw_params callback:
|
|
|
|
* allocate the buffer and build up the buffer description table
|
|
|
|
*/
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via82xx_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *hw_params)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_pcm_substream_chip(substream);
|
|
|
|
struct viadev *viadev = substream->runtime->private_data;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2019-12-09 12:49:27 +03:00
|
|
|
return build_via_table(viadev, substream, chip->pci,
|
|
|
|
params_periods(hw_params),
|
|
|
|
params_period_bytes(hw_params));
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* hw_free callback:
|
|
|
|
* clean up the buffer description table and release the buffer
|
|
|
|
*/
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via82xx_hw_free(struct snd_pcm_substream *substream)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_pcm_substream_chip(substream);
|
|
|
|
struct viadev *viadev = substream->runtime->private_data;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
clean_via_table(viadev, substream, chip->pci);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set up the table pointer
|
|
|
|
*/
|
2005-11-17 17:06:15 +03:00
|
|
|
static void snd_via82xx_set_table_ptr(struct via82xx *chip, struct viadev *viadev)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
snd_via82xx_codec_ready(chip, 0);
|
|
|
|
outl((u32)viadev->table.addr, VIADEV_REG(viadev, OFFSET_TABLE_PTR));
|
|
|
|
udelay(20);
|
|
|
|
snd_via82xx_codec_ready(chip, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* prepare callback for playback and capture on via686
|
|
|
|
*/
|
2005-11-17 17:06:15 +03:00
|
|
|
static void via686_setup_format(struct via82xx *chip, struct viadev *viadev,
|
|
|
|
struct snd_pcm_runtime *runtime)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
snd_via82xx_channel_reset(chip, viadev);
|
|
|
|
/* this must be set after channel_reset */
|
|
|
|
snd_via82xx_set_table_ptr(chip, viadev);
|
|
|
|
outb(VIA_REG_TYPE_AUTOSTART |
|
|
|
|
(runtime->format == SNDRV_PCM_FORMAT_S16_LE ? VIA_REG_TYPE_16BIT : 0) |
|
|
|
|
(runtime->channels > 1 ? VIA_REG_TYPE_STEREO : 0) |
|
|
|
|
((viadev->reg_offset & 0x10) == 0 ? VIA_REG_TYPE_INT_LSAMPLE : 0) |
|
|
|
|
VIA_REG_TYPE_INT_EOL |
|
|
|
|
VIA_REG_TYPE_INT_FLAG, VIADEV_REG(viadev, OFFSET_TYPE));
|
|
|
|
}
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via686_playback_prepare(struct snd_pcm_substream *substream)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_pcm_substream_chip(substream);
|
|
|
|
struct viadev *viadev = substream->runtime->private_data;
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, runtime->rate);
|
|
|
|
snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate);
|
|
|
|
via686_setup_format(chip, viadev, runtime);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via686_capture_prepare(struct snd_pcm_substream *substream)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_pcm_substream_chip(substream);
|
|
|
|
struct viadev *viadev = substream->runtime->private_data;
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
snd_ac97_set_rate(chip->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
|
|
|
|
via686_setup_format(chip, viadev, runtime);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* lock the current rate
|
|
|
|
*/
|
|
|
|
static int via_lock_rate(struct via_rate_lock *rec, int rate)
|
|
|
|
{
|
|
|
|
int changed = 0;
|
|
|
|
|
|
|
|
spin_lock_irq(&rec->lock);
|
|
|
|
if (rec->rate != rate) {
|
|
|
|
if (rec->rate && rec->used > 1) /* already set */
|
|
|
|
changed = -EINVAL;
|
|
|
|
else {
|
|
|
|
rec->rate = rate;
|
|
|
|
changed = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock_irq(&rec->lock);
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* prepare callback for DSX playback on via823x
|
|
|
|
*/
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via8233_playback_prepare(struct snd_pcm_substream *substream)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_pcm_substream_chip(substream);
|
|
|
|
struct viadev *viadev = substream->runtime->private_data;
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
2005-04-11 17:04:33 +04:00
|
|
|
int ac97_rate = chip->dxs_src ? 48000 : runtime->rate;
|
2005-04-17 02:20:36 +04:00
|
|
|
int rate_changed;
|
|
|
|
u32 rbits;
|
|
|
|
|
2005-04-11 17:04:33 +04:00
|
|
|
if ((rate_changed = via_lock_rate(&chip->rates[0], ac97_rate)) < 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
return rate_changed;
|
2005-08-15 17:02:28 +04:00
|
|
|
if (rate_changed)
|
2005-04-17 02:20:36 +04:00
|
|
|
snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE,
|
|
|
|
chip->no_vra ? 48000 : runtime->rate);
|
2005-08-15 17:02:28 +04:00
|
|
|
if (chip->spdif_on && viadev->reg_offset == 0x30)
|
|
|
|
snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate);
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
if (runtime->rate == 48000)
|
|
|
|
rbits = 0xfffff;
|
|
|
|
else
|
2005-11-17 17:06:15 +03:00
|
|
|
rbits = (0x100000 / 48000) * runtime->rate +
|
|
|
|
((0x100000 % 48000) * runtime->rate) / 48000;
|
2008-08-08 19:12:14 +04:00
|
|
|
snd_BUG_ON(rbits & ~0xfffff);
|
2005-04-17 02:20:36 +04:00
|
|
|
snd_via82xx_channel_reset(chip, viadev);
|
|
|
|
snd_via82xx_set_table_ptr(chip, viadev);
|
2005-11-17 17:06:15 +03:00
|
|
|
outb(chip->playback_volume[viadev->reg_offset / 0x10][0],
|
|
|
|
VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_L));
|
|
|
|
outb(chip->playback_volume[viadev->reg_offset / 0x10][1],
|
|
|
|
VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_R));
|
2005-04-17 02:20:36 +04:00
|
|
|
outl((runtime->format == SNDRV_PCM_FORMAT_S16_LE ? VIA8233_REG_TYPE_16BIT : 0) | /* format */
|
|
|
|
(runtime->channels > 1 ? VIA8233_REG_TYPE_STEREO : 0) | /* stereo */
|
|
|
|
rbits | /* rate */
|
|
|
|
0xff000000, /* STOP index is never reached */
|
|
|
|
VIADEV_REG(viadev, OFFSET_STOP_IDX));
|
|
|
|
udelay(20);
|
|
|
|
snd_via82xx_codec_ready(chip, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* prepare callback for multi-channel playback on via823x
|
|
|
|
*/
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via8233_multi_prepare(struct snd_pcm_substream *substream)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_pcm_substream_chip(substream);
|
|
|
|
struct viadev *viadev = substream->runtime->private_data;
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned int slots;
|
|
|
|
int fmt;
|
|
|
|
|
|
|
|
if (via_lock_rate(&chip->rates[0], runtime->rate) < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, runtime->rate);
|
|
|
|
snd_ac97_set_rate(chip->ac97, AC97_PCM_SURR_DAC_RATE, runtime->rate);
|
|
|
|
snd_ac97_set_rate(chip->ac97, AC97_PCM_LFE_DAC_RATE, runtime->rate);
|
|
|
|
snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate);
|
|
|
|
snd_via82xx_channel_reset(chip, viadev);
|
|
|
|
snd_via82xx_set_table_ptr(chip, viadev);
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
fmt = (runtime->format == SNDRV_PCM_FORMAT_S16_LE) ?
|
|
|
|
VIA_REG_MULTPLAY_FMT_16BIT : VIA_REG_MULTPLAY_FMT_8BIT;
|
2005-04-17 02:20:36 +04:00
|
|
|
fmt |= runtime->channels << 4;
|
|
|
|
outb(fmt, VIADEV_REG(viadev, OFS_MULTPLAY_FORMAT));
|
|
|
|
#if 0
|
|
|
|
if (chip->revision == VIA_REV_8233A)
|
|
|
|
slots = 0;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* set sample number to slot 3, 4, 7, 8, 6, 9 (for VIA8233/C,8235) */
|
|
|
|
/* corresponding to FL, FR, RL, RR, C, LFE ?? */
|
|
|
|
switch (runtime->channels) {
|
|
|
|
case 1: slots = (1<<0) | (1<<4); break;
|
|
|
|
case 2: slots = (1<<0) | (2<<4); break;
|
|
|
|
case 3: slots = (1<<0) | (2<<4) | (5<<8); break;
|
|
|
|
case 4: slots = (1<<0) | (2<<4) | (3<<8) | (4<<12); break;
|
|
|
|
case 5: slots = (1<<0) | (2<<4) | (3<<8) | (4<<12) | (5<<16); break;
|
|
|
|
case 6: slots = (1<<0) | (2<<4) | (3<<8) | (4<<12) | (5<<16) | (6<<20); break;
|
|
|
|
default: slots = 0; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* STOP index is never reached */
|
|
|
|
outl(0xff000000 | slots, VIADEV_REG(viadev, OFFSET_STOP_IDX));
|
|
|
|
udelay(20);
|
|
|
|
snd_via82xx_codec_ready(chip, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* prepare callback for capture on via823x
|
|
|
|
*/
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via8233_capture_prepare(struct snd_pcm_substream *substream)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_pcm_substream_chip(substream);
|
|
|
|
struct viadev *viadev = substream->runtime->private_data;
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (via_lock_rate(&chip->rates[1], runtime->rate) < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
snd_ac97_set_rate(chip->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
|
|
|
|
snd_via82xx_channel_reset(chip, viadev);
|
|
|
|
snd_via82xx_set_table_ptr(chip, viadev);
|
|
|
|
outb(VIA_REG_CAPTURE_FIFO_ENABLE, VIADEV_REG(viadev, OFS_CAPTURE_FIFO));
|
|
|
|
outl((runtime->format == SNDRV_PCM_FORMAT_S16_LE ? VIA8233_REG_TYPE_16BIT : 0) |
|
|
|
|
(runtime->channels > 1 ? VIA8233_REG_TYPE_STEREO : 0) |
|
|
|
|
0xff000000, /* STOP index is never reached */
|
|
|
|
VIADEV_REG(viadev, OFFSET_STOP_IDX));
|
|
|
|
udelay(20);
|
|
|
|
snd_via82xx_codec_ready(chip, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pcm hardware definition, identical for both playback and capture
|
|
|
|
*/
|
2017-08-12 18:31:28 +03:00
|
|
|
static const struct snd_pcm_hardware snd_via82xx_hw =
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
.info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
|
|
|
|
SNDRV_PCM_INFO_BLOCK_TRANSFER |
|
|
|
|
SNDRV_PCM_INFO_MMAP_VALID |
|
2005-08-18 15:43:12 +04:00
|
|
|
/* SNDRV_PCM_INFO_RESUME | */
|
2005-04-17 02:20:36 +04:00
|
|
|
SNDRV_PCM_INFO_PAUSE),
|
|
|
|
.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
|
|
|
|
.rates = SNDRV_PCM_RATE_48000,
|
|
|
|
.rate_min = 48000,
|
|
|
|
.rate_max = 48000,
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 2,
|
2008-07-30 17:23:06 +04:00
|
|
|
.buffer_bytes_max = VIA_MAX_BUFSIZE,
|
2005-04-17 02:20:36 +04:00
|
|
|
.period_bytes_min = 32,
|
2008-07-30 17:23:06 +04:00
|
|
|
.period_bytes_max = VIA_MAX_BUFSIZE / 2,
|
2005-04-17 02:20:36 +04:00
|
|
|
.periods_min = 2,
|
|
|
|
.periods_max = VIA_TABLE_SIZE / 2,
|
|
|
|
.fifo_size = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* open callback skeleton
|
|
|
|
*/
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via82xx_pcm_open(struct via82xx *chip, struct viadev *viadev,
|
|
|
|
struct snd_pcm_substream *substream)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
2005-04-17 02:20:36 +04:00
|
|
|
int err;
|
|
|
|
struct via_rate_lock *ratep;
|
2011-09-17 01:16:05 +04:00
|
|
|
bool use_src = false;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
runtime->hw = snd_via82xx_hw;
|
|
|
|
|
|
|
|
/* set the hw rate condition */
|
|
|
|
ratep = &chip->rates[viadev->direction];
|
|
|
|
spin_lock_irq(&ratep->lock);
|
|
|
|
ratep->used++;
|
|
|
|
if (chip->spdif_on && viadev->reg_offset == 0x30) {
|
|
|
|
/* DXS#3 and spdif is on */
|
|
|
|
runtime->hw.rates = chip->ac97->rates[AC97_RATES_SPDIF];
|
|
|
|
snd_pcm_limit_hw_rates(runtime);
|
|
|
|
} else if (chip->dxs_fixed && viadev->reg_offset < 0x40) {
|
|
|
|
/* fixed DXS playback rate */
|
|
|
|
runtime->hw.rates = SNDRV_PCM_RATE_48000;
|
|
|
|
runtime->hw.rate_min = runtime->hw.rate_max = 48000;
|
2005-04-11 17:04:33 +04:00
|
|
|
} else if (chip->dxs_src && viadev->reg_offset < 0x40) {
|
|
|
|
/* use full SRC capabilities of DXS */
|
|
|
|
runtime->hw.rates = (SNDRV_PCM_RATE_CONTINUOUS |
|
|
|
|
SNDRV_PCM_RATE_8000_48000);
|
|
|
|
runtime->hw.rate_min = 8000;
|
|
|
|
runtime->hw.rate_max = 48000;
|
2011-09-17 01:16:05 +04:00
|
|
|
use_src = true;
|
2005-04-17 02:20:36 +04:00
|
|
|
} else if (! ratep->rate) {
|
|
|
|
int idx = viadev->direction ? AC97_RATES_ADC : AC97_RATES_FRONT_DAC;
|
|
|
|
runtime->hw.rates = chip->ac97->rates[idx];
|
|
|
|
snd_pcm_limit_hw_rates(runtime);
|
|
|
|
} else {
|
|
|
|
/* a fixed rate */
|
|
|
|
runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
|
|
|
|
runtime->hw.rate_max = runtime->hw.rate_min = ratep->rate;
|
|
|
|
}
|
|
|
|
spin_unlock_irq(&ratep->lock);
|
|
|
|
|
|
|
|
/* we may remove following constaint when we modify table entries
|
|
|
|
in interrupt */
|
|
|
|
if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
|
|
|
|
return err;
|
|
|
|
|
2011-09-17 01:16:05 +04:00
|
|
|
if (use_src) {
|
|
|
|
err = snd_pcm_hw_rule_noresample(runtime, 48000);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
runtime->private_data = viadev;
|
|
|
|
viadev->substream = substream;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-10-22 11:04:09 +04:00
|
|
|
* open callback for playback on via686
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
2009-10-22 11:04:09 +04:00
|
|
|
static int snd_via686_playback_open(struct snd_pcm_substream *substream)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_pcm_substream_chip(substream);
|
|
|
|
struct viadev *viadev = &chip->devs[chip->playback_devno + substream->number];
|
2005-04-17 02:20:36 +04:00
|
|
|
int err;
|
|
|
|
|
|
|
|
if ((err = snd_via82xx_pcm_open(chip, viadev, substream)) < 0)
|
|
|
|
return err;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-22 11:04:09 +04:00
|
|
|
/*
|
|
|
|
* open callback for playback on via823x DXS
|
|
|
|
*/
|
|
|
|
static int snd_via8233_playback_open(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
struct via82xx *chip = snd_pcm_substream_chip(substream);
|
|
|
|
struct viadev *viadev;
|
|
|
|
unsigned int stream;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
viadev = &chip->devs[chip->playback_devno + substream->number];
|
|
|
|
if ((err = snd_via82xx_pcm_open(chip, viadev, substream)) < 0)
|
|
|
|
return err;
|
|
|
|
stream = viadev->reg_offset / 0x10;
|
|
|
|
if (chip->dxs_controls[stream]) {
|
2010-07-12 18:27:24 +04:00
|
|
|
chip->playback_volume[stream][0] =
|
|
|
|
VIA_DXS_MAX_VOLUME - (dxs_init_volume & 31);
|
|
|
|
chip->playback_volume[stream][1] =
|
|
|
|
VIA_DXS_MAX_VOLUME - (dxs_init_volume & 31);
|
2009-10-22 11:04:09 +04:00
|
|
|
chip->dxs_controls[stream]->vd[0].access &=
|
|
|
|
~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
|
|
|
|
snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE |
|
|
|
|
SNDRV_CTL_EVENT_MASK_INFO,
|
|
|
|
&chip->dxs_controls[stream]->id);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* open callback for playback on via823x multi-channel
|
|
|
|
*/
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via8233_multi_open(struct snd_pcm_substream *substream)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_pcm_substream_chip(substream);
|
|
|
|
struct viadev *viadev = &chip->devs[chip->multi_devno];
|
2005-04-17 02:20:36 +04:00
|
|
|
int err;
|
|
|
|
/* channels constraint for VIA8233A
|
|
|
|
* 3 and 5 channels are not supported
|
|
|
|
*/
|
2017-06-07 15:23:13 +03:00
|
|
|
static const unsigned int channels[] = {
|
2005-04-17 02:20:36 +04:00
|
|
|
1, 2, 4, 6
|
|
|
|
};
|
2017-06-07 15:23:13 +03:00
|
|
|
static const struct snd_pcm_hw_constraint_list hw_constraints_channels = {
|
2005-04-17 02:20:36 +04:00
|
|
|
.count = ARRAY_SIZE(channels),
|
|
|
|
.list = channels,
|
|
|
|
.mask = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
if ((err = snd_via82xx_pcm_open(chip, viadev, substream)) < 0)
|
|
|
|
return err;
|
|
|
|
substream->runtime->hw.channels_max = 6;
|
|
|
|
if (chip->revision == VIA_REV_8233A)
|
2005-11-17 17:06:15 +03:00
|
|
|
snd_pcm_hw_constraint_list(substream->runtime, 0,
|
|
|
|
SNDRV_PCM_HW_PARAM_CHANNELS,
|
|
|
|
&hw_constraints_channels);
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* open callback for capture on via686 and via823x
|
|
|
|
*/
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via82xx_capture_open(struct snd_pcm_substream *substream)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_pcm_substream_chip(substream);
|
|
|
|
struct viadev *viadev = &chip->devs[chip->capture_devno + substream->pcm->device];
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
return snd_via82xx_pcm_open(chip, viadev, substream);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* close callback
|
|
|
|
*/
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via82xx_pcm_close(struct snd_pcm_substream *substream)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_pcm_substream_chip(substream);
|
|
|
|
struct viadev *viadev = substream->runtime->private_data;
|
2005-04-17 02:20:36 +04:00
|
|
|
struct via_rate_lock *ratep;
|
|
|
|
|
|
|
|
/* release the rate lock */
|
|
|
|
ratep = &chip->rates[viadev->direction];
|
|
|
|
spin_lock_irq(&ratep->lock);
|
|
|
|
ratep->used--;
|
|
|
|
if (! ratep->used)
|
|
|
|
ratep->rate = 0;
|
|
|
|
spin_unlock_irq(&ratep->lock);
|
2006-06-27 20:28:53 +04:00
|
|
|
if (! ratep->rate) {
|
|
|
|
if (! viadev->direction) {
|
|
|
|
snd_ac97_update_power(chip->ac97,
|
|
|
|
AC97_PCM_FRONT_DAC_RATE, 0);
|
|
|
|
snd_ac97_update_power(chip->ac97,
|
|
|
|
AC97_PCM_SURR_DAC_RATE, 0);
|
|
|
|
snd_ac97_update_power(chip->ac97,
|
|
|
|
AC97_PCM_LFE_DAC_RATE, 0);
|
|
|
|
} else
|
|
|
|
snd_ac97_update_power(chip->ac97,
|
|
|
|
AC97_PCM_LR_ADC_RATE, 0);
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
viadev->substream = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-22 11:04:09 +04:00
|
|
|
static int snd_via8233_playback_close(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
struct via82xx *chip = snd_pcm_substream_chip(substream);
|
|
|
|
struct viadev *viadev = substream->runtime->private_data;
|
|
|
|
unsigned int stream;
|
|
|
|
|
|
|
|
stream = viadev->reg_offset / 0x10;
|
|
|
|
if (chip->dxs_controls[stream]) {
|
|
|
|
chip->dxs_controls[stream]->vd[0].access |=
|
|
|
|
SNDRV_CTL_ELEM_ACCESS_INACTIVE;
|
|
|
|
snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_INFO,
|
|
|
|
&chip->dxs_controls[stream]->id);
|
|
|
|
}
|
|
|
|
return snd_via82xx_pcm_close(substream);
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* via686 playback callbacks */
|
2016-09-02 01:13:10 +03:00
|
|
|
static const struct snd_pcm_ops snd_via686_playback_ops = {
|
2009-10-22 11:04:09 +04:00
|
|
|
.open = snd_via686_playback_open,
|
2005-04-17 02:20:36 +04:00
|
|
|
.close = snd_via82xx_pcm_close,
|
|
|
|
.hw_params = snd_via82xx_hw_params,
|
|
|
|
.hw_free = snd_via82xx_hw_free,
|
|
|
|
.prepare = snd_via686_playback_prepare,
|
|
|
|
.trigger = snd_via82xx_pcm_trigger,
|
|
|
|
.pointer = snd_via686_pcm_pointer,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* via686 capture callbacks */
|
2016-09-02 01:13:10 +03:00
|
|
|
static const struct snd_pcm_ops snd_via686_capture_ops = {
|
2005-04-17 02:20:36 +04:00
|
|
|
.open = snd_via82xx_capture_open,
|
|
|
|
.close = snd_via82xx_pcm_close,
|
|
|
|
.hw_params = snd_via82xx_hw_params,
|
|
|
|
.hw_free = snd_via82xx_hw_free,
|
|
|
|
.prepare = snd_via686_capture_prepare,
|
|
|
|
.trigger = snd_via82xx_pcm_trigger,
|
|
|
|
.pointer = snd_via686_pcm_pointer,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* via823x DSX playback callbacks */
|
2016-09-02 01:13:10 +03:00
|
|
|
static const struct snd_pcm_ops snd_via8233_playback_ops = {
|
2009-10-22 11:04:09 +04:00
|
|
|
.open = snd_via8233_playback_open,
|
|
|
|
.close = snd_via8233_playback_close,
|
2005-04-17 02:20:36 +04:00
|
|
|
.hw_params = snd_via82xx_hw_params,
|
|
|
|
.hw_free = snd_via82xx_hw_free,
|
|
|
|
.prepare = snd_via8233_playback_prepare,
|
|
|
|
.trigger = snd_via82xx_pcm_trigger,
|
|
|
|
.pointer = snd_via8233_pcm_pointer,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* via823x multi-channel playback callbacks */
|
2016-09-02 01:13:10 +03:00
|
|
|
static const struct snd_pcm_ops snd_via8233_multi_ops = {
|
2005-04-17 02:20:36 +04:00
|
|
|
.open = snd_via8233_multi_open,
|
|
|
|
.close = snd_via82xx_pcm_close,
|
|
|
|
.hw_params = snd_via82xx_hw_params,
|
|
|
|
.hw_free = snd_via82xx_hw_free,
|
|
|
|
.prepare = snd_via8233_multi_prepare,
|
|
|
|
.trigger = snd_via82xx_pcm_trigger,
|
|
|
|
.pointer = snd_via8233_pcm_pointer,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* via823x capture callbacks */
|
2016-09-02 01:13:10 +03:00
|
|
|
static const struct snd_pcm_ops snd_via8233_capture_ops = {
|
2005-04-17 02:20:36 +04:00
|
|
|
.open = snd_via82xx_capture_open,
|
|
|
|
.close = snd_via82xx_pcm_close,
|
|
|
|
.hw_params = snd_via82xx_hw_params,
|
|
|
|
.hw_free = snd_via82xx_hw_free,
|
|
|
|
.prepare = snd_via8233_capture_prepare,
|
|
|
|
.trigger = snd_via82xx_pcm_trigger,
|
|
|
|
.pointer = snd_via8233_pcm_pointer,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static void init_viadev(struct via82xx *chip, int idx, unsigned int reg_offset,
|
|
|
|
int shadow_pos, int direction)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
chip->devs[idx].reg_offset = reg_offset;
|
2005-10-18 16:31:07 +04:00
|
|
|
chip->devs[idx].shadow_shift = shadow_pos * 4;
|
2005-04-17 02:20:36 +04:00
|
|
|
chip->devs[idx].direction = direction;
|
|
|
|
chip->devs[idx].port = chip->port + reg_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* create pcm instances for VIA8233, 8233C and 8235 (not 8233A)
|
|
|
|
*/
|
2012-12-06 21:35:10 +04:00
|
|
|
static int snd_via8233_pcm_new(struct via82xx *chip)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct snd_pcm *pcm;
|
2012-08-03 20:01:40 +04:00
|
|
|
struct snd_pcm_chmap *chmap;
|
2005-04-17 02:20:36 +04:00
|
|
|
int i, err;
|
|
|
|
|
|
|
|
chip->playback_devno = 0; /* x 4 */
|
|
|
|
chip->multi_devno = 4; /* x 1 */
|
|
|
|
chip->capture_devno = 5; /* x 2 */
|
|
|
|
chip->num_devs = 7;
|
|
|
|
chip->intr_mask = 0x33033333; /* FLAG|EOL for rec0-1, mc, sdx0-3 */
|
|
|
|
|
|
|
|
/* PCM #0: 4 DSX playbacks and 1 capture */
|
|
|
|
err = snd_pcm_new(chip->card, chip->card->shortname, 0, 4, 1, &pcm);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_playback_ops);
|
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via8233_capture_ops);
|
|
|
|
pcm->private_data = chip;
|
|
|
|
strcpy(pcm->name, chip->card->shortname);
|
|
|
|
chip->pcms[0] = pcm;
|
|
|
|
/* set up playbacks */
|
|
|
|
for (i = 0; i < 4; i++)
|
2005-10-18 16:31:07 +04:00
|
|
|
init_viadev(chip, i, 0x10 * i, i, 0);
|
2005-04-17 02:20:36 +04:00
|
|
|
/* capture */
|
2005-10-18 16:31:07 +04:00
|
|
|
init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2019-12-09 12:49:27 +03:00
|
|
|
snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
|
|
|
|
&chip->pci->dev,
|
|
|
|
64*1024, VIA_MAX_BUFSIZE);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-08-03 20:01:40 +04:00
|
|
|
err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
|
|
|
|
snd_pcm_std_chmaps, 2, 0,
|
|
|
|
&chmap);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* PCM #1: multi-channel playback and 2nd capture */
|
|
|
|
err = snd_pcm_new(chip->card, chip->card->shortname, 1, 1, 1, &pcm);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_multi_ops);
|
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via8233_capture_ops);
|
|
|
|
pcm->private_data = chip;
|
|
|
|
strcpy(pcm->name, chip->card->shortname);
|
|
|
|
chip->pcms[1] = pcm;
|
|
|
|
/* set up playback */
|
2005-10-18 16:31:07 +04:00
|
|
|
init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 4, 0);
|
2005-04-17 02:20:36 +04:00
|
|
|
/* set up capture */
|
2005-10-18 16:31:07 +04:00
|
|
|
init_viadev(chip, chip->capture_devno + 1, VIA_REG_CAPTURE_8233_STATUS + 0x10, 7, 1);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2019-12-09 12:49:27 +03:00
|
|
|
snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
|
|
|
|
&chip->pci->dev,
|
|
|
|
64*1024, VIA_MAX_BUFSIZE);
|
2012-08-03 20:01:40 +04:00
|
|
|
|
|
|
|
err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
|
|
|
|
snd_pcm_alt_chmaps, 6, 0,
|
|
|
|
&chmap);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
chip->ac97->chmaps[SNDRV_PCM_STREAM_PLAYBACK] = chmap;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* create pcm instances for VIA8233A
|
|
|
|
*/
|
2012-12-06 21:35:10 +04:00
|
|
|
static int snd_via8233a_pcm_new(struct via82xx *chip)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct snd_pcm *pcm;
|
2012-08-03 20:01:40 +04:00
|
|
|
struct snd_pcm_chmap *chmap;
|
2005-04-17 02:20:36 +04:00
|
|
|
int err;
|
|
|
|
|
|
|
|
chip->multi_devno = 0;
|
|
|
|
chip->playback_devno = 1;
|
|
|
|
chip->capture_devno = 2;
|
|
|
|
chip->num_devs = 3;
|
|
|
|
chip->intr_mask = 0x03033000; /* FLAG|EOL for rec0, mc, sdx3 */
|
|
|
|
|
|
|
|
/* PCM #0: multi-channel playback and capture */
|
|
|
|
err = snd_pcm_new(chip->card, chip->card->shortname, 0, 1, 1, &pcm);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_multi_ops);
|
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via8233_capture_ops);
|
|
|
|
pcm->private_data = chip;
|
|
|
|
strcpy(pcm->name, chip->card->shortname);
|
|
|
|
chip->pcms[0] = pcm;
|
|
|
|
/* set up playback */
|
2005-10-18 16:31:07 +04:00
|
|
|
init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 4, 0);
|
2005-04-17 02:20:36 +04:00
|
|
|
/* capture */
|
2005-10-18 16:31:07 +04:00
|
|
|
init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2019-12-09 12:49:27 +03:00
|
|
|
snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
|
|
|
|
&chip->pci->dev,
|
|
|
|
64*1024, VIA_MAX_BUFSIZE);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-08-03 20:01:40 +04:00
|
|
|
err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
|
|
|
|
snd_pcm_alt_chmaps, 6, 0,
|
|
|
|
&chmap);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
chip->ac97->chmaps[SNDRV_PCM_STREAM_PLAYBACK] = chmap;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* SPDIF supported? */
|
|
|
|
if (! ac97_can_spdif(chip->ac97))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* PCM #1: DXS3 playback (for spdif) */
|
|
|
|
err = snd_pcm_new(chip->card, chip->card->shortname, 1, 1, 0, &pcm);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_playback_ops);
|
|
|
|
pcm->private_data = chip;
|
|
|
|
strcpy(pcm->name, chip->card->shortname);
|
|
|
|
chip->pcms[1] = pcm;
|
|
|
|
/* set up playback */
|
2005-10-18 16:31:07 +04:00
|
|
|
init_viadev(chip, chip->playback_devno, 0x30, 3, 0);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2019-12-09 12:49:27 +03:00
|
|
|
snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
|
|
|
|
&chip->pci->dev,
|
|
|
|
64*1024, VIA_MAX_BUFSIZE);
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* create a pcm instance for via686a/b
|
|
|
|
*/
|
2012-12-06 21:35:10 +04:00
|
|
|
static int snd_via686_pcm_new(struct via82xx *chip)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct snd_pcm *pcm;
|
2005-04-17 02:20:36 +04:00
|
|
|
int err;
|
|
|
|
|
|
|
|
chip->playback_devno = 0;
|
|
|
|
chip->capture_devno = 1;
|
|
|
|
chip->num_devs = 2;
|
|
|
|
chip->intr_mask = 0x77; /* FLAG | EOL for PB, CP, FM */
|
|
|
|
|
|
|
|
err = snd_pcm_new(chip->card, chip->card->shortname, 0, 1, 1, &pcm);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via686_playback_ops);
|
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via686_capture_ops);
|
|
|
|
pcm->private_data = chip;
|
|
|
|
strcpy(pcm->name, chip->card->shortname);
|
|
|
|
chip->pcms[0] = pcm;
|
2005-10-18 16:31:07 +04:00
|
|
|
init_viadev(chip, 0, VIA_REG_PLAYBACK_STATUS, 0, 0);
|
|
|
|
init_viadev(chip, 1, VIA_REG_CAPTURE_STATUS, 0, 1);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2019-12-09 12:49:27 +03:00
|
|
|
snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
|
|
|
|
&chip->pci->dev,
|
|
|
|
64*1024, VIA_MAX_BUFSIZE);
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mixer part
|
|
|
|
*/
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via8233_capture_source_info(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
/* formerly they were "Line" and "Mic", but it looks like that they
|
|
|
|
* have nothing to do with the actual physical connections...
|
|
|
|
*/
|
2014-10-20 20:20:18 +04:00
|
|
|
static const char * const texts[2] = {
|
2005-04-17 02:20:36 +04:00
|
|
|
"Input1", "Input2"
|
|
|
|
};
|
2014-10-20 20:20:18 +04:00
|
|
|
return snd_ctl_enum_info(uinfo, 1, 2, texts);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via8233_capture_source_get(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_kcontrol_chip(kcontrol);
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned long port = chip->port + (kcontrol->id.index ? (VIA_REG_CAPTURE_CHANNEL + 0x10) : VIA_REG_CAPTURE_CHANNEL);
|
|
|
|
ucontrol->value.enumerated.item[0] = inb(port) & VIA_REG_CAPTURE_CHANNEL_MIC ? 1 : 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via8233_capture_source_put(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_kcontrol_chip(kcontrol);
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned long port = chip->port + (kcontrol->id.index ? (VIA_REG_CAPTURE_CHANNEL + 0x10) : VIA_REG_CAPTURE_CHANNEL);
|
|
|
|
u8 val, oval;
|
|
|
|
|
|
|
|
spin_lock_irq(&chip->reg_lock);
|
|
|
|
oval = inb(port);
|
|
|
|
val = oval & ~VIA_REG_CAPTURE_CHANNEL_MIC;
|
|
|
|
if (ucontrol->value.enumerated.item[0])
|
|
|
|
val |= VIA_REG_CAPTURE_CHANNEL_MIC;
|
|
|
|
if (val != oval)
|
|
|
|
outb(val, port);
|
|
|
|
spin_unlock_irq(&chip->reg_lock);
|
|
|
|
return val != oval;
|
|
|
|
}
|
|
|
|
|
2012-12-06 21:35:10 +04:00
|
|
|
static struct snd_kcontrol_new snd_via8233_capture_source = {
|
2005-04-17 02:20:36 +04:00
|
|
|
.name = "Input Source Select",
|
|
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
|
|
|
.info = snd_via8233_capture_source_info,
|
|
|
|
.get = snd_via8233_capture_source_get,
|
|
|
|
.put = snd_via8233_capture_source_put,
|
|
|
|
};
|
|
|
|
|
2007-07-23 17:42:26 +04:00
|
|
|
#define snd_via8233_dxs3_spdif_info snd_ctl_boolean_mono_info
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via8233_dxs3_spdif_get(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_kcontrol_chip(kcontrol);
|
2005-04-17 02:20:36 +04:00
|
|
|
u8 val;
|
|
|
|
|
|
|
|
pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &val);
|
|
|
|
ucontrol->value.integer.value[0] = (val & VIA8233_SPDIF_DX3) ? 1 : 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via8233_dxs3_spdif_put(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_kcontrol_chip(kcontrol);
|
2005-04-17 02:20:36 +04:00
|
|
|
u8 val, oval;
|
|
|
|
|
|
|
|
pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &oval);
|
|
|
|
val = oval & ~VIA8233_SPDIF_DX3;
|
|
|
|
if (ucontrol->value.integer.value[0])
|
|
|
|
val |= VIA8233_SPDIF_DX3;
|
|
|
|
/* save the spdif flag for rate filtering */
|
|
|
|
chip->spdif_on = ucontrol->value.integer.value[0] ? 1 : 0;
|
|
|
|
if (val != oval) {
|
|
|
|
pci_write_config_byte(chip->pci, VIA8233_SPDIF_CTRL, val);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-19 21:48:09 +03:00
|
|
|
static const struct snd_kcontrol_new snd_via8233_dxs3_spdif_control = {
|
2005-08-03 15:40:08 +04:00
|
|
|
.name = SNDRV_CTL_NAME_IEC958("Output ",NONE,SWITCH),
|
2005-04-17 02:20:36 +04:00
|
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
|
|
|
.info = snd_via8233_dxs3_spdif_info,
|
|
|
|
.get = snd_via8233_dxs3_spdif_get,
|
|
|
|
.put = snd_via8233_dxs3_spdif_put,
|
|
|
|
};
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via8233_dxs_volume_info(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
|
|
|
uinfo->count = 2;
|
|
|
|
uinfo->value.integer.min = 0;
|
|
|
|
uinfo->value.integer.max = VIA_DXS_MAX_VOLUME;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via8233_dxs_volume_get(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_kcontrol_chip(kcontrol);
|
2009-10-06 10:21:04 +04:00
|
|
|
unsigned int idx = kcontrol->id.subdevice;
|
2005-10-14 20:18:01 +04:00
|
|
|
|
|
|
|
ucontrol->value.integer.value[0] = VIA_DXS_MAX_VOLUME - chip->playback_volume[idx][0];
|
|
|
|
ucontrol->value.integer.value[1] = VIA_DXS_MAX_VOLUME - chip->playback_volume[idx][1];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via8233_pcmdxs_volume_get(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-10-14 20:18:01 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_kcontrol_chip(kcontrol);
|
2005-10-14 20:18:01 +04:00
|
|
|
ucontrol->value.integer.value[0] = VIA_DXS_MAX_VOLUME - chip->playback_volume_c[0];
|
|
|
|
ucontrol->value.integer.value[1] = VIA_DXS_MAX_VOLUME - chip->playback_volume_c[1];
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via8233_dxs_volume_put(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-10-14 20:18:01 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_kcontrol_chip(kcontrol);
|
2009-10-06 10:21:04 +04:00
|
|
|
unsigned int idx = kcontrol->id.subdevice;
|
2005-10-14 20:18:01 +04:00
|
|
|
unsigned long port = chip->port + 0x10 * idx;
|
|
|
|
unsigned char val;
|
|
|
|
int i, change = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
val = ucontrol->value.integer.value[i];
|
|
|
|
if (val > VIA_DXS_MAX_VOLUME)
|
|
|
|
val = VIA_DXS_MAX_VOLUME;
|
|
|
|
val = VIA_DXS_MAX_VOLUME - val;
|
|
|
|
change |= val != chip->playback_volume[idx][i];
|
|
|
|
if (change) {
|
|
|
|
chip->playback_volume[idx][i] = val;
|
|
|
|
outb(val, port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return change;
|
|
|
|
}
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via8233_pcmdxs_volume_put(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = snd_kcontrol_chip(kcontrol);
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned int idx;
|
|
|
|
unsigned char val;
|
|
|
|
int i, change = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
val = ucontrol->value.integer.value[i];
|
|
|
|
if (val > VIA_DXS_MAX_VOLUME)
|
|
|
|
val = VIA_DXS_MAX_VOLUME;
|
|
|
|
val = VIA_DXS_MAX_VOLUME - val;
|
2005-10-14 20:18:01 +04:00
|
|
|
if (val != chip->playback_volume_c[i]) {
|
2005-04-17 02:20:36 +04:00
|
|
|
change = 1;
|
2005-10-14 20:18:01 +04:00
|
|
|
chip->playback_volume_c[i] = val;
|
2005-04-17 02:20:36 +04:00
|
|
|
for (idx = 0; idx < 4; idx++) {
|
|
|
|
unsigned long port = chip->port + 0x10 * idx;
|
2005-10-14 20:18:01 +04:00
|
|
|
chip->playback_volume[idx][i] = val;
|
2005-04-17 02:20:36 +04:00
|
|
|
outb(val, port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return change;
|
|
|
|
}
|
|
|
|
|
2009-05-05 17:40:12 +04:00
|
|
|
static const DECLARE_TLV_DB_SCALE(db_scale_dxs, -4650, 150, 1);
|
2006-08-21 20:44:54 +04:00
|
|
|
|
2017-02-19 21:48:09 +03:00
|
|
|
static const struct snd_kcontrol_new snd_via8233_pcmdxs_volume_control = {
|
2005-04-17 02:20:36 +04:00
|
|
|
.name = "PCM Playback Volume",
|
|
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
2006-08-21 20:44:54 +04:00
|
|
|
.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
|
|
|
|
SNDRV_CTL_ELEM_ACCESS_TLV_READ),
|
2005-04-17 02:20:36 +04:00
|
|
|
.info = snd_via8233_dxs_volume_info,
|
2005-10-14 20:18:01 +04:00
|
|
|
.get = snd_via8233_pcmdxs_volume_get,
|
|
|
|
.put = snd_via8233_pcmdxs_volume_put,
|
2006-08-21 20:44:54 +04:00
|
|
|
.tlv = { .p = db_scale_dxs }
|
2005-10-14 20:18:01 +04:00
|
|
|
};
|
|
|
|
|
2017-02-19 21:48:09 +03:00
|
|
|
static const struct snd_kcontrol_new snd_via8233_dxs_volume_control = {
|
2009-10-06 10:21:04 +04:00
|
|
|
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
|
|
|
|
.device = 0,
|
|
|
|
/* .subdevice set later */
|
|
|
|
.name = "PCM Playback Volume",
|
2009-10-22 11:04:09 +04:00
|
|
|
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
|
|
|
|
SNDRV_CTL_ELEM_ACCESS_TLV_READ |
|
|
|
|
SNDRV_CTL_ELEM_ACCESS_INACTIVE,
|
2005-10-14 20:18:01 +04:00
|
|
|
.info = snd_via8233_dxs_volume_info,
|
2005-04-17 02:20:36 +04:00
|
|
|
.get = snd_via8233_dxs_volume_get,
|
|
|
|
.put = snd_via8233_dxs_volume_put,
|
2006-08-21 20:44:54 +04:00
|
|
|
.tlv = { .p = db_scale_dxs }
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
*/
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static void snd_via82xx_mixer_free_ac97_bus(struct snd_ac97_bus *bus)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = bus->private_data;
|
2005-04-17 02:20:36 +04:00
|
|
|
chip->ac97_bus = NULL;
|
|
|
|
}
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static void snd_via82xx_mixer_free_ac97(struct snd_ac97 *ac97)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = ac97->private_data;
|
2005-04-17 02:20:36 +04:00
|
|
|
chip->ac97 = NULL;
|
|
|
|
}
|
|
|
|
|
2015-04-04 23:38:25 +03:00
|
|
|
static const struct ac97_quirk ac97_quirks[] = {
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-05-30 16:48:16 +04:00
|
|
|
.subvendor = 0x1106,
|
|
|
|
.subdevice = 0x4161,
|
2005-04-17 02:20:36 +04:00
|
|
|
.codec_id = 0x56494161, /* VT1612A */
|
|
|
|
.name = "Soltek SL-75DRV5",
|
|
|
|
.type = AC97_TUNE_NONE
|
|
|
|
},
|
|
|
|
{ /* FIXME: which codec? */
|
2005-05-30 16:48:16 +04:00
|
|
|
.subvendor = 0x1106,
|
|
|
|
.subdevice = 0x4161,
|
2005-04-17 02:20:36 +04:00
|
|
|
.name = "ASRock K7VT2",
|
|
|
|
.type = AC97_TUNE_HP_ONLY
|
|
|
|
},
|
2010-02-22 12:33:13 +03:00
|
|
|
{
|
|
|
|
.subvendor = 0x110a,
|
|
|
|
.subdevice = 0x0079,
|
|
|
|
.name = "Fujitsu Siemens D1289",
|
|
|
|
.type = AC97_TUNE_HP_ONLY
|
|
|
|
},
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-05-30 16:48:16 +04:00
|
|
|
.subvendor = 0x1019,
|
|
|
|
.subdevice = 0x0a81,
|
2005-04-17 02:20:36 +04:00
|
|
|
.name = "ECS K7VTA3",
|
|
|
|
.type = AC97_TUNE_HP_ONLY
|
|
|
|
},
|
|
|
|
{
|
2005-05-30 16:48:16 +04:00
|
|
|
.subvendor = 0x1019,
|
|
|
|
.subdevice = 0x0a85,
|
2005-04-17 02:20:36 +04:00
|
|
|
.name = "ECS L7VMM2",
|
|
|
|
.type = AC97_TUNE_HP_ONLY
|
|
|
|
},
|
2008-06-27 13:53:31 +04:00
|
|
|
{
|
|
|
|
.subvendor = 0x1019,
|
|
|
|
.subdevice = 0x1841,
|
|
|
|
.name = "ECS K7VTA3",
|
|
|
|
.type = AC97_TUNE_HP_ONLY
|
|
|
|
},
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-05-30 16:48:16 +04:00
|
|
|
.subvendor = 0x1849,
|
|
|
|
.subdevice = 0x3059,
|
2005-04-17 02:20:36 +04:00
|
|
|
.name = "ASRock K7VM2",
|
|
|
|
.type = AC97_TUNE_HP_ONLY /* VT1616 */
|
|
|
|
},
|
|
|
|
{
|
2005-05-30 16:48:16 +04:00
|
|
|
.subvendor = 0x14cd,
|
|
|
|
.subdevice = 0x7002,
|
2005-04-17 02:20:36 +04:00
|
|
|
.name = "Unknown",
|
|
|
|
.type = AC97_TUNE_ALC_JACK
|
|
|
|
},
|
|
|
|
{
|
2005-05-30 16:48:16 +04:00
|
|
|
.subvendor = 0x1071,
|
|
|
|
.subdevice = 0x8590,
|
2005-04-17 02:20:36 +04:00
|
|
|
.name = "Mitac Mobo",
|
|
|
|
.type = AC97_TUNE_ALC_JACK
|
|
|
|
},
|
|
|
|
{
|
2005-05-30 16:48:16 +04:00
|
|
|
.subvendor = 0x161f,
|
|
|
|
.subdevice = 0x202b,
|
2005-04-17 02:20:36 +04:00
|
|
|
.name = "Arima Notebook",
|
|
|
|
.type = AC97_TUNE_HP_ONLY,
|
|
|
|
},
|
2005-12-14 14:00:46 +03:00
|
|
|
{
|
|
|
|
.subvendor = 0x161f,
|
|
|
|
.subdevice = 0x2032,
|
|
|
|
.name = "Targa Traveller 811",
|
|
|
|
.type = AC97_TUNE_HP_ONLY,
|
|
|
|
},
|
2006-06-16 18:21:54 +04:00
|
|
|
{
|
|
|
|
.subvendor = 0x161f,
|
|
|
|
.subdevice = 0x2032,
|
|
|
|
.name = "m680x",
|
|
|
|
.type = AC97_TUNE_HP_ONLY, /* http://launchpad.net/bugs/38546 */
|
|
|
|
},
|
2007-10-25 13:46:24 +04:00
|
|
|
{
|
|
|
|
.subvendor = 0x1297,
|
|
|
|
.subdevice = 0xa232,
|
|
|
|
.name = "Shuttle AK32VN",
|
|
|
|
.type = AC97_TUNE_HP_ONLY
|
|
|
|
},
|
2005-04-17 02:20:36 +04:00
|
|
|
{ } /* terminator */
|
|
|
|
};
|
|
|
|
|
2012-12-06 21:35:10 +04:00
|
|
|
static int snd_via82xx_mixer_new(struct via82xx *chip, const char *quirk_override)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct snd_ac97_template ac97;
|
2005-04-17 02:20:36 +04:00
|
|
|
int err;
|
2020-01-03 11:16:43 +03:00
|
|
|
static const struct snd_ac97_bus_ops ops = {
|
2005-04-17 02:20:36 +04:00
|
|
|
.write = snd_via82xx_codec_write,
|
|
|
|
.read = snd_via82xx_codec_read,
|
|
|
|
.wait = snd_via82xx_codec_wait,
|
|
|
|
};
|
|
|
|
|
|
|
|
if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus)) < 0)
|
|
|
|
return err;
|
|
|
|
chip->ac97_bus->private_free = snd_via82xx_mixer_free_ac97_bus;
|
|
|
|
chip->ac97_bus->clock = chip->ac97_clock;
|
|
|
|
|
|
|
|
memset(&ac97, 0, sizeof(ac97));
|
|
|
|
ac97.private_data = chip;
|
|
|
|
ac97.private_free = snd_via82xx_mixer_free_ac97;
|
|
|
|
ac97.pci = chip->pci;
|
2006-10-24 20:25:29 +04:00
|
|
|
ac97.scaps = AC97_SCAP_SKIP_MODEM | AC97_SCAP_POWER_SAVE;
|
2005-04-17 02:20:36 +04:00
|
|
|
if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97)) < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
snd_ac97_tune_hardware(chip->ac97, ac97_quirks, quirk_override);
|
|
|
|
|
|
|
|
if (chip->chip_type != TYPE_VIA686) {
|
|
|
|
/* use slot 10/11 */
|
|
|
|
snd_ac97_update_bits(chip->ac97, AC97_EXTENDED_STATUS, 0x03 << 4, 0x03 << 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SUPPORT_JOYSTICK
|
|
|
|
#define JOYSTICK_ADDR 0x200
|
2012-12-06 21:35:10 +04:00
|
|
|
static int snd_via686_create_gameport(struct via82xx *chip, unsigned char *legacy)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct gameport *gp;
|
|
|
|
struct resource *r;
|
|
|
|
|
2005-10-04 10:46:51 +04:00
|
|
|
if (!joystick)
|
2005-04-17 02:20:36 +04:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
r = request_region(JOYSTICK_ADDR, 8, "VIA686 gameport");
|
|
|
|
if (!r) {
|
2014-02-25 18:21:56 +04:00
|
|
|
dev_warn(chip->card->dev, "cannot reserve joystick port %#x\n",
|
2005-11-17 17:06:15 +03:00
|
|
|
JOYSTICK_ADDR);
|
2005-04-17 02:20:36 +04:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
chip->gameport = gp = gameport_allocate_port();
|
|
|
|
if (!gp) {
|
2014-02-25 18:21:56 +04:00
|
|
|
dev_err(chip->card->dev,
|
|
|
|
"cannot allocate memory for gameport\n");
|
2005-10-10 13:56:31 +04:00
|
|
|
release_and_free_resource(r);
|
2005-04-17 02:20:36 +04:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
gameport_set_name(gp, "VIA686 Gameport");
|
|
|
|
gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci));
|
|
|
|
gameport_set_dev_parent(gp, &chip->pci->dev);
|
|
|
|
gp->io = JOYSTICK_ADDR;
|
|
|
|
gameport_set_port_data(gp, r);
|
|
|
|
|
|
|
|
/* Enable legacy joystick port */
|
|
|
|
*legacy |= VIA_FUNC_ENABLE_GAME;
|
|
|
|
pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, *legacy);
|
|
|
|
|
|
|
|
gameport_register_port(chip->gameport);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static void snd_via686_free_gameport(struct via82xx *chip)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
if (chip->gameport) {
|
|
|
|
struct resource *r = gameport_get_port_data(chip->gameport);
|
|
|
|
|
|
|
|
gameport_unregister_port(chip->gameport);
|
|
|
|
chip->gameport = NULL;
|
2005-10-10 13:56:31 +04:00
|
|
|
release_and_free_resource(r);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2005-11-17 17:06:15 +03:00
|
|
|
static inline int snd_via686_create_gameport(struct via82xx *chip, unsigned char *legacy)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
2005-11-17 17:06:15 +03:00
|
|
|
static inline void snd_via686_free_gameport(struct via82xx *chip) { }
|
2005-04-17 02:20:36 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-12-06 21:35:10 +04:00
|
|
|
static int snd_via8233_init_misc(struct via82xx *chip)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
int i, err, caps;
|
|
|
|
unsigned char val;
|
|
|
|
|
|
|
|
caps = chip->chip_type == TYPE_VIA8233A ? 1 : 2;
|
|
|
|
for (i = 0; i < caps; i++) {
|
|
|
|
snd_via8233_capture_source.index = i;
|
|
|
|
err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_capture_source, chip));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
if (ac97_can_spdif(chip->ac97)) {
|
|
|
|
err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_dxs3_spdif_control, chip));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
if (chip->chip_type != TYPE_VIA8233A) {
|
|
|
|
/* when no h/w PCM volume control is found, use DXS volume control
|
|
|
|
* as the PCM vol control
|
|
|
|
*/
|
2005-11-17 17:06:15 +03:00
|
|
|
struct snd_ctl_elem_id sid;
|
2005-04-17 02:20:36 +04:00
|
|
|
memset(&sid, 0, sizeof(sid));
|
|
|
|
strcpy(sid.name, "PCM Playback Volume");
|
|
|
|
sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
|
|
|
|
if (! snd_ctl_find_id(chip->card, &sid)) {
|
2014-02-25 18:21:56 +04:00
|
|
|
dev_info(chip->card->dev,
|
|
|
|
"Using DXS as PCM Playback\n");
|
2005-10-14 20:18:01 +04:00
|
|
|
err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_pcmdxs_volume_control, chip));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
else /* Using DXS when PCM emulation is enabled is really weird */
|
|
|
|
{
|
2009-10-06 10:21:04 +04:00
|
|
|
for (i = 0; i < 4; ++i) {
|
|
|
|
struct snd_kcontrol *kctl;
|
|
|
|
|
|
|
|
kctl = snd_ctl_new1(
|
|
|
|
&snd_via8233_dxs_volume_control, chip);
|
|
|
|
if (!kctl)
|
|
|
|
return -ENOMEM;
|
|
|
|
kctl->id.subdevice = i;
|
|
|
|
err = snd_ctl_add(chip->card, kctl);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
2009-10-22 11:04:09 +04:00
|
|
|
chip->dxs_controls[i] = kctl;
|
2009-10-06 10:21:04 +04:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* select spdif data slot 10/11 */
|
|
|
|
pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &val);
|
|
|
|
val = (val & ~VIA8233_SPDIF_SLOT_MASK) | VIA8233_SPDIF_SLOT_1011;
|
|
|
|
val &= ~VIA8233_SPDIF_DX3; /* SPDIF off as default */
|
|
|
|
pci_write_config_byte(chip->pci, VIA8233_SPDIF_CTRL, val);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-06 21:35:10 +04:00
|
|
|
static int snd_via686_init_misc(struct via82xx *chip)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
unsigned char legacy, legacy_cfg;
|
|
|
|
int rev_h = 0;
|
|
|
|
|
|
|
|
legacy = chip->old_legacy;
|
|
|
|
legacy_cfg = chip->old_legacy_cfg;
|
|
|
|
legacy |= VIA_FUNC_MIDI_IRQMASK; /* FIXME: correct? (disable MIDI) */
|
|
|
|
legacy &= ~VIA_FUNC_ENABLE_GAME; /* disable joystick */
|
|
|
|
if (chip->revision >= VIA_REV_686_H) {
|
|
|
|
rev_h = 1;
|
2005-10-04 10:46:51 +04:00
|
|
|
if (mpu_port >= 0x200) { /* force MIDI */
|
|
|
|
mpu_port &= 0xfffc;
|
|
|
|
pci_write_config_dword(chip->pci, 0x18, mpu_port | 0x01);
|
2012-08-14 20:12:04 +04:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2005-10-04 10:46:51 +04:00
|
|
|
chip->mpu_port_saved = mpu_port;
|
2005-04-17 02:20:36 +04:00
|
|
|
#endif
|
|
|
|
} else {
|
2005-10-04 10:46:51 +04:00
|
|
|
mpu_port = pci_resource_start(chip->pci, 2);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
} else {
|
2005-10-04 10:46:51 +04:00
|
|
|
switch (mpu_port) { /* force MIDI */
|
2005-04-17 02:20:36 +04:00
|
|
|
case 0x300:
|
|
|
|
case 0x310:
|
|
|
|
case 0x320:
|
|
|
|
case 0x330:
|
|
|
|
legacy_cfg &= ~(3 << 2);
|
2005-10-04 10:46:51 +04:00
|
|
|
legacy_cfg |= (mpu_port & 0x0030) >> 2;
|
2005-04-17 02:20:36 +04:00
|
|
|
break;
|
|
|
|
default: /* no, use BIOS settings */
|
|
|
|
if (legacy & VIA_FUNC_ENABLE_MIDI)
|
2005-10-04 10:46:51 +04:00
|
|
|
mpu_port = 0x300 + ((legacy_cfg & 0x000c) << 2);
|
2005-04-17 02:20:36 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-10-04 10:46:51 +04:00
|
|
|
if (mpu_port >= 0x200 &&
|
|
|
|
(chip->mpu_res = request_region(mpu_port, 2, "VIA82xx MPU401"))
|
|
|
|
!= NULL) {
|
2005-04-17 02:20:36 +04:00
|
|
|
if (rev_h)
|
|
|
|
legacy |= VIA_FUNC_MIDI_PNP; /* enable PCI I/O 2 */
|
|
|
|
legacy |= VIA_FUNC_ENABLE_MIDI;
|
|
|
|
} else {
|
|
|
|
if (rev_h)
|
|
|
|
legacy &= ~VIA_FUNC_MIDI_PNP; /* disable PCI I/O 2 */
|
|
|
|
legacy &= ~VIA_FUNC_ENABLE_MIDI;
|
2005-10-04 10:46:51 +04:00
|
|
|
mpu_port = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy);
|
|
|
|
pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, legacy_cfg);
|
|
|
|
if (chip->mpu_res) {
|
|
|
|
if (snd_mpu401_uart_new(chip->card, 0, MPU401_HW_VIA686A,
|
ALSA: mpu401: clean up interrupt specification
The semantics of snd_mpu401_uart_new()'s interrupt parameters are
somewhat counterintuitive: To prevent the function from allocating its
own interrupt, either the irq number must be invalid, or the irq_flags
parameter must be zero. At the same time, the irq parameter being
invalid specifies that the mpu401 code has to work without an interrupt
allocated by the caller. This implies that, if there is an interrupt
and it is allocated by the caller, the irq parameter must be set to
a valid-looking number which then isn't actually used.
With the removal of IRQF_DISABLED, zero becomes a valid irq_flags value,
which forces us to handle the parameters differently.
This patch introduces a new flag MPU401_INFO_IRQ_HOOK for when the
device interrupt is handled by the caller, and makes the allocation of
the interrupt to depend only on the irq parameter. As suggested by
Takashi, the irq_flags parameter was dropped because, when used, it had
the constant value IRQF_DISABLED.
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2011-09-13 13:24:41 +04:00
|
|
|
mpu_port, MPU401_INFO_INTEGRATED |
|
|
|
|
MPU401_INFO_IRQ_HOOK, -1,
|
|
|
|
&chip->rmidi) < 0) {
|
2014-02-25 18:21:56 +04:00
|
|
|
dev_warn(chip->card->dev,
|
|
|
|
"unable to initialize MPU-401 at 0x%lx, skipping\n",
|
|
|
|
mpu_port);
|
2005-04-17 02:20:36 +04:00
|
|
|
legacy &= ~VIA_FUNC_ENABLE_MIDI;
|
|
|
|
} else {
|
|
|
|
legacy &= ~VIA_FUNC_MIDI_IRQMASK; /* enable MIDI interrupt */
|
|
|
|
}
|
|
|
|
pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy);
|
|
|
|
}
|
|
|
|
|
2005-10-04 10:46:51 +04:00
|
|
|
snd_via686_create_gameport(chip, &legacy);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-08-14 20:12:04 +04:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2005-04-17 02:20:36 +04:00
|
|
|
chip->legacy_saved = legacy;
|
|
|
|
chip->legacy_cfg_saved = legacy_cfg;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* proc interface
|
|
|
|
*/
|
2005-11-17 17:06:15 +03:00
|
|
|
static void snd_via82xx_proc_read(struct snd_info_entry *entry,
|
|
|
|
struct snd_info_buffer *buffer)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = entry->private_data;
|
2005-04-17 02:20:36 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
snd_iprintf(buffer, "%s\n\n", chip->card->longname);
|
|
|
|
for (i = 0; i < 0xa0; i += 4) {
|
|
|
|
snd_iprintf(buffer, "%02x: %08x\n", i, inl(chip->port + i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-06 21:35:10 +04:00
|
|
|
static void snd_via82xx_proc_init(struct via82xx *chip)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2019-02-04 18:01:39 +03:00
|
|
|
snd_card_ro_proc_new(chip->card, "via82xx", chip,
|
|
|
|
snd_via82xx_proc_read);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via82xx_chip_init(struct via82xx *chip)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
unsigned int val;
|
[ALSA] sound/pci: fix-up sleeping paths
ENS1370/1+ driver,ES1968 driver,Intel8x0 driver,VIA82xx driver
VIA82xx-modem driver,AC97 Codec,ALI5451 driver,CS46xx driver
MIXART driver,RME HDSP driver,Trident driver,YMFPCI driver
Description: Fix-up sleeping in sound/pci. These changes fall under the
following two categories:
1) Replace schedule_timeout() with msleep() to guarantee the
task delays as expected. This also involved replacing/removing
custom sleep functions.
2) Do not assume jiffies will only increment by one if you
request a 1 jiffy sleep, i.e. use time_after/time_before in
while loops.
Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>
Signed-off-by: Jaroslav Kysela <perex@suse.cz>
2005-07-09 12:13:22 +04:00
|
|
|
unsigned long end_time;
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned char pval;
|
|
|
|
|
|
|
|
#if 0 /* broken on K7M? */
|
|
|
|
if (chip->chip_type == TYPE_VIA686)
|
|
|
|
/* disable all legacy ports */
|
|
|
|
pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, 0);
|
|
|
|
#endif
|
|
|
|
pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval);
|
|
|
|
if (! (pval & VIA_ACLINK_C00_READY)) { /* codec not ready? */
|
|
|
|
/* deassert ACLink reset, force SYNC */
|
|
|
|
pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL,
|
|
|
|
VIA_ACLINK_CTRL_ENABLE |
|
|
|
|
VIA_ACLINK_CTRL_RESET |
|
|
|
|
VIA_ACLINK_CTRL_SYNC);
|
|
|
|
udelay(100);
|
|
|
|
#if 1 /* FIXME: should we do full reset here for all chip models? */
|
|
|
|
pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL, 0x00);
|
|
|
|
udelay(100);
|
|
|
|
#else
|
|
|
|
/* deassert ACLink reset, force SYNC (warm AC'97 reset) */
|
|
|
|
pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL,
|
|
|
|
VIA_ACLINK_CTRL_RESET|VIA_ACLINK_CTRL_SYNC);
|
|
|
|
udelay(2);
|
|
|
|
#endif
|
|
|
|
/* ACLink on, deassert ACLink reset, VSR, SGD data out */
|
|
|
|
/* note - FM data out has trouble with non VRA codecs !! */
|
|
|
|
pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL, VIA_ACLINK_CTRL_INIT);
|
|
|
|
udelay(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure VRA is enabled, in case we didn't do a
|
|
|
|
* complete codec reset, above */
|
|
|
|
pci_read_config_byte(chip->pci, VIA_ACLINK_CTRL, &pval);
|
|
|
|
if ((pval & VIA_ACLINK_CTRL_INIT) != VIA_ACLINK_CTRL_INIT) {
|
|
|
|
/* ACLink on, deassert ACLink reset, VSR, SGD data out */
|
|
|
|
/* note - FM data out has trouble with non VRA codecs !! */
|
|
|
|
pci_write_config_byte(chip->pci, VIA_ACLINK_CTRL, VIA_ACLINK_CTRL_INIT);
|
|
|
|
udelay(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wait until codec ready */
|
[ALSA] sound/pci: fix-up sleeping paths
ENS1370/1+ driver,ES1968 driver,Intel8x0 driver,VIA82xx driver
VIA82xx-modem driver,AC97 Codec,ALI5451 driver,CS46xx driver
MIXART driver,RME HDSP driver,Trident driver,YMFPCI driver
Description: Fix-up sleeping in sound/pci. These changes fall under the
following two categories:
1) Replace schedule_timeout() with msleep() to guarantee the
task delays as expected. This also involved replacing/removing
custom sleep functions.
2) Do not assume jiffies will only increment by one if you
request a 1 jiffy sleep, i.e. use time_after/time_before in
while loops.
Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>
Signed-off-by: Jaroslav Kysela <perex@suse.cz>
2005-07-09 12:13:22 +04:00
|
|
|
end_time = jiffies + msecs_to_jiffies(750);
|
2005-04-17 02:20:36 +04:00
|
|
|
do {
|
|
|
|
pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval);
|
|
|
|
if (pval & VIA_ACLINK_C00_READY) /* primary codec ready */
|
|
|
|
break;
|
2007-09-18 20:10:49 +04:00
|
|
|
schedule_timeout_uninterruptible(1);
|
[ALSA] sound/pci: fix-up sleeping paths
ENS1370/1+ driver,ES1968 driver,Intel8x0 driver,VIA82xx driver
VIA82xx-modem driver,AC97 Codec,ALI5451 driver,CS46xx driver
MIXART driver,RME HDSP driver,Trident driver,YMFPCI driver
Description: Fix-up sleeping in sound/pci. These changes fall under the
following two categories:
1) Replace schedule_timeout() with msleep() to guarantee the
task delays as expected. This also involved replacing/removing
custom sleep functions.
2) Do not assume jiffies will only increment by one if you
request a 1 jiffy sleep, i.e. use time_after/time_before in
while loops.
Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>
Signed-off-by: Jaroslav Kysela <perex@suse.cz>
2005-07-09 12:13:22 +04:00
|
|
|
} while (time_before(jiffies, end_time));
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY)
|
2014-02-25 18:21:56 +04:00
|
|
|
dev_err(chip->card->dev,
|
|
|
|
"AC'97 codec is not ready [0x%x]\n", val);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
#if 0 /* FIXME: we don't support the second codec yet so skip the detection now.. */
|
|
|
|
snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ |
|
|
|
|
VIA_REG_AC97_SECONDARY_VALID |
|
|
|
|
(VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT));
|
[ALSA] sound/pci: fix-up sleeping paths
ENS1370/1+ driver,ES1968 driver,Intel8x0 driver,VIA82xx driver
VIA82xx-modem driver,AC97 Codec,ALI5451 driver,CS46xx driver
MIXART driver,RME HDSP driver,Trident driver,YMFPCI driver
Description: Fix-up sleeping in sound/pci. These changes fall under the
following two categories:
1) Replace schedule_timeout() with msleep() to guarantee the
task delays as expected. This also involved replacing/removing
custom sleep functions.
2) Do not assume jiffies will only increment by one if you
request a 1 jiffy sleep, i.e. use time_after/time_before in
while loops.
Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>
Signed-off-by: Jaroslav Kysela <perex@suse.cz>
2005-07-09 12:13:22 +04:00
|
|
|
end_time = jiffies + msecs_to_jiffies(750);
|
2005-04-17 02:20:36 +04:00
|
|
|
snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ |
|
|
|
|
VIA_REG_AC97_SECONDARY_VALID |
|
|
|
|
(VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT));
|
|
|
|
do {
|
|
|
|
if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_SECONDARY_VALID) {
|
|
|
|
chip->ac97_secondary = 1;
|
|
|
|
goto __ac97_ok2;
|
|
|
|
}
|
2007-09-18 20:10:49 +04:00
|
|
|
schedule_timeout_uninterruptible(1);
|
[ALSA] sound/pci: fix-up sleeping paths
ENS1370/1+ driver,ES1968 driver,Intel8x0 driver,VIA82xx driver
VIA82xx-modem driver,AC97 Codec,ALI5451 driver,CS46xx driver
MIXART driver,RME HDSP driver,Trident driver,YMFPCI driver
Description: Fix-up sleeping in sound/pci. These changes fall under the
following two categories:
1) Replace schedule_timeout() with msleep() to guarantee the
task delays as expected. This also involved replacing/removing
custom sleep functions.
2) Do not assume jiffies will only increment by one if you
request a 1 jiffy sleep, i.e. use time_after/time_before in
while loops.
Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>
Signed-off-by: Jaroslav Kysela <perex@suse.cz>
2005-07-09 12:13:22 +04:00
|
|
|
} while (time_before(jiffies, end_time));
|
2005-04-17 02:20:36 +04:00
|
|
|
/* This is ok, the most of motherboards have only one codec */
|
|
|
|
|
|
|
|
__ac97_ok2:
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (chip->chip_type == TYPE_VIA686) {
|
|
|
|
/* route FM trap to IRQ, disable FM trap */
|
|
|
|
pci_write_config_byte(chip->pci, VIA_FM_NMI_CTRL, 0);
|
|
|
|
/* disable all GPI interrupts */
|
|
|
|
outl(0, VIAREG(chip, GPI_INTR));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chip->chip_type != TYPE_VIA686) {
|
|
|
|
/* Workaround for Award BIOS bug:
|
|
|
|
* DXS channels don't work properly with VRA if MC97 is disabled.
|
|
|
|
*/
|
|
|
|
struct pci_dev *pci;
|
2005-09-07 16:28:33 +04:00
|
|
|
pci = pci_get_device(0x1106, 0x3068, NULL); /* MC97 */
|
2005-04-17 02:20:36 +04:00
|
|
|
if (pci) {
|
|
|
|
unsigned char data;
|
|
|
|
pci_read_config_byte(pci, 0x44, &data);
|
|
|
|
pci_write_config_byte(pci, 0x44, data | 0x40);
|
2005-09-07 16:28:33 +04:00
|
|
|
pci_dev_put(pci);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chip->chip_type != TYPE_VIA8233A) {
|
|
|
|
int i, idx;
|
|
|
|
for (idx = 0; idx < 4; idx++) {
|
|
|
|
unsigned long port = chip->port + 0x10 * idx;
|
2005-10-14 20:18:01 +04:00
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
chip->playback_volume[idx][i]=chip->playback_volume_c[i];
|
2005-11-17 17:06:15 +03:00
|
|
|
outb(chip->playback_volume_c[i],
|
|
|
|
port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i);
|
2005-10-14 20:18:01 +04:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-14 20:12:04 +04:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* power management
|
|
|
|
*/
|
2012-07-02 17:20:37 +04:00
|
|
|
static int snd_via82xx_suspend(struct device *dev)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2012-07-02 17:20:37 +04:00
|
|
|
struct snd_card *card = dev_get_drvdata(dev);
|
2005-11-17 18:10:35 +03:00
|
|
|
struct via82xx *chip = card->private_data;
|
2005-04-17 02:20:36 +04:00
|
|
|
int i;
|
|
|
|
|
2005-11-17 18:10:35 +03:00
|
|
|
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
|
2005-04-17 02:20:36 +04:00
|
|
|
for (i = 0; i < chip->num_devs; i++)
|
|
|
|
snd_via82xx_channel_reset(chip, &chip->devs[i]);
|
|
|
|
snd_ac97_suspend(chip->ac97);
|
|
|
|
|
|
|
|
/* save misc values */
|
|
|
|
if (chip->chip_type != TYPE_VIA686) {
|
|
|
|
pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &chip->spdif_ctrl_saved);
|
|
|
|
chip->capture_src_saved[0] = inb(chip->port + VIA_REG_CAPTURE_CHANNEL);
|
|
|
|
chip->capture_src_saved[1] = inb(chip->port + VIA_REG_CAPTURE_CHANNEL + 0x10);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-02 17:20:37 +04:00
|
|
|
static int snd_via82xx_resume(struct device *dev)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2012-07-02 17:20:37 +04:00
|
|
|
struct snd_card *card = dev_get_drvdata(dev);
|
2005-11-17 18:10:35 +03:00
|
|
|
struct via82xx *chip = card->private_data;
|
2005-04-17 02:20:36 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
snd_via82xx_chip_init(chip);
|
|
|
|
|
|
|
|
if (chip->chip_type == TYPE_VIA686) {
|
|
|
|
if (chip->mpu_port_saved)
|
|
|
|
pci_write_config_dword(chip->pci, 0x18, chip->mpu_port_saved | 0x01);
|
|
|
|
pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, chip->legacy_saved);
|
|
|
|
pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, chip->legacy_cfg_saved);
|
|
|
|
} else {
|
|
|
|
pci_write_config_byte(chip->pci, VIA8233_SPDIF_CTRL, chip->spdif_ctrl_saved);
|
|
|
|
outb(chip->capture_src_saved[0], chip->port + VIA_REG_CAPTURE_CHANNEL);
|
|
|
|
outb(chip->capture_src_saved[1], chip->port + VIA_REG_CAPTURE_CHANNEL + 0x10);
|
|
|
|
}
|
|
|
|
|
|
|
|
snd_ac97_resume(chip->ac97);
|
|
|
|
|
|
|
|
for (i = 0; i < chip->num_devs; i++)
|
|
|
|
snd_via82xx_channel_reset(chip, &chip->devs[i]);
|
|
|
|
|
2005-11-17 18:10:35 +03:00
|
|
|
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2012-07-02 17:20:37 +04:00
|
|
|
|
|
|
|
static SIMPLE_DEV_PM_OPS(snd_via82xx_pm, snd_via82xx_suspend, snd_via82xx_resume);
|
|
|
|
#define SND_VIA82XX_PM_OPS &snd_via82xx_pm
|
|
|
|
#else
|
|
|
|
#define SND_VIA82XX_PM_OPS NULL
|
2012-08-14 20:12:04 +04:00
|
|
|
#endif /* CONFIG_PM_SLEEP */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via82xx_free(struct via82xx *chip)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (chip->irq < 0)
|
|
|
|
goto __end_hw;
|
|
|
|
/* disable interrupts */
|
|
|
|
for (i = 0; i < chip->num_devs; i++)
|
|
|
|
snd_via82xx_channel_reset(chip, &chip->devs[i]);
|
2008-04-22 15:50:34 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
if (chip->irq >= 0)
|
2005-11-17 17:06:15 +03:00
|
|
|
free_irq(chip->irq, chip);
|
2007-12-14 14:51:24 +03:00
|
|
|
__end_hw:
|
2005-10-10 13:56:31 +04:00
|
|
|
release_and_free_resource(chip->mpu_res);
|
2005-04-17 02:20:36 +04:00
|
|
|
pci_release_regions(chip->pci);
|
|
|
|
|
|
|
|
if (chip->chip_type == TYPE_VIA686) {
|
|
|
|
snd_via686_free_gameport(chip);
|
|
|
|
pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, chip->old_legacy);
|
|
|
|
pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, chip->old_legacy_cfg);
|
|
|
|
}
|
|
|
|
pci_disable_device(chip->pci);
|
|
|
|
kfree(chip);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 17:06:15 +03:00
|
|
|
static int snd_via82xx_dev_free(struct snd_device *device)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip = device->device_data;
|
2005-04-17 02:20:36 +04:00
|
|
|
return snd_via82xx_free(chip);
|
|
|
|
}
|
|
|
|
|
2012-12-06 21:35:10 +04:00
|
|
|
static int snd_via82xx_create(struct snd_card *card,
|
|
|
|
struct pci_dev *pci,
|
|
|
|
int chip_type,
|
|
|
|
int revision,
|
|
|
|
unsigned int ac97_clock,
|
|
|
|
struct via82xx **r_via)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct via82xx *chip;
|
2005-04-17 02:20:36 +04:00
|
|
|
int err;
|
2020-01-03 11:16:25 +03:00
|
|
|
static const struct snd_device_ops ops = {
|
2005-04-17 02:20:36 +04:00
|
|
|
.dev_free = snd_via82xx_dev_free,
|
|
|
|
};
|
|
|
|
|
|
|
|
if ((err = pci_enable_device(pci)) < 0)
|
|
|
|
return err;
|
|
|
|
|
[ALSA] Replace with kzalloc() - pci stuff
AD1889 driver,ATIIXP driver,ATIIXP-modem driver,AZT3328 driver
BT87x driver,CMIPCI driver,CS4281 driver,ENS1370/1+ driver
ES1938 driver,ES1968 driver,FM801 driver,Intel8x0 driver
Intel8x0-modem driver,Maestro3 driver,SonicVibes driver,VIA82xx driver
VIA82xx-modem driver,AC97 Codec,AK4531 codec,au88x0 driver
CA0106 driver,CS46xx driver,EMU10K1/EMU10K2 driver,HDA Codec driver
HDA generic driver,HDA Intel driver,ICE1712 driver,ICE1724 driver
KORG1212 driver,MIXART driver,NM256 driver,Trident driver,YMFPCI driver
Replace kcalloc(1,..) with kzalloc().
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2005-09-09 16:21:46 +04:00
|
|
|
if ((chip = kzalloc(sizeof(*chip), GFP_KERNEL)) == NULL) {
|
2005-04-17 02:20:36 +04:00
|
|
|
pci_disable_device(pci);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
chip->chip_type = chip_type;
|
|
|
|
chip->revision = revision;
|
|
|
|
|
|
|
|
spin_lock_init(&chip->reg_lock);
|
|
|
|
spin_lock_init(&chip->rates[0].lock);
|
|
|
|
spin_lock_init(&chip->rates[1].lock);
|
|
|
|
chip->card = card;
|
|
|
|
chip->pci = pci;
|
|
|
|
chip->irq = -1;
|
|
|
|
|
|
|
|
pci_read_config_byte(pci, VIA_FUNC_ENABLE, &chip->old_legacy);
|
|
|
|
pci_read_config_byte(pci, VIA_PNP_CONTROL, &chip->old_legacy_cfg);
|
|
|
|
pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE,
|
|
|
|
chip->old_legacy & ~(VIA_FUNC_ENABLE_SB|VIA_FUNC_ENABLE_FM));
|
|
|
|
|
|
|
|
if ((err = pci_request_regions(pci, card->driver)) < 0) {
|
|
|
|
kfree(chip);
|
|
|
|
pci_disable_device(pci);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
chip->port = pci_resource_start(pci, 0);
|
2005-10-18 16:31:07 +04:00
|
|
|
if (request_irq(pci->irq,
|
|
|
|
chip_type == TYPE_VIA8233 ?
|
|
|
|
snd_via8233_interrupt : snd_via686_interrupt,
|
2006-11-21 14:14:23 +03:00
|
|
|
IRQF_SHARED,
|
2011-06-10 18:36:37 +04:00
|
|
|
KBUILD_MODNAME, chip)) {
|
2014-02-25 18:21:56 +04:00
|
|
|
dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
|
2005-04-17 02:20:36 +04:00
|
|
|
snd_via82xx_free(chip);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
chip->irq = pci->irq;
|
2019-12-10 09:34:36 +03:00
|
|
|
card->sync_irq = chip->irq;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (ac97_clock >= 8000 && ac97_clock <= 48000)
|
|
|
|
chip->ac97_clock = ac97_clock;
|
|
|
|
|
|
|
|
if ((err = snd_via82xx_chip_init(chip)) < 0) {
|
|
|
|
snd_via82xx_free(chip);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
|
|
|
|
snd_via82xx_free(chip);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The 8233 ac97 controller does not implement the master bit
|
|
|
|
* in the pci command register. IMHO this is a violation of the PCI spec.
|
|
|
|
* We call pci_set_master here because it does not hurt. */
|
|
|
|
pci_set_master(pci);
|
|
|
|
|
|
|
|
*r_via = chip;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct via823x_info {
|
|
|
|
int revision;
|
|
|
|
char *name;
|
|
|
|
int type;
|
|
|
|
};
|
2020-01-05 17:48:20 +03:00
|
|
|
static const struct via823x_info via823x_cards[] = {
|
2005-04-17 02:20:36 +04:00
|
|
|
{ VIA_REV_PRE_8233, "VIA 8233-Pre", TYPE_VIA8233 },
|
|
|
|
{ VIA_REV_8233C, "VIA 8233C", TYPE_VIA8233 },
|
|
|
|
{ VIA_REV_8233, "VIA 8233", TYPE_VIA8233 },
|
|
|
|
{ VIA_REV_8233A, "VIA 8233A", TYPE_VIA8233A },
|
|
|
|
{ VIA_REV_8235, "VIA 8235", TYPE_VIA8233 },
|
|
|
|
{ VIA_REV_8237, "VIA 8237", TYPE_VIA8233 },
|
2006-04-18 19:04:04 +04:00
|
|
|
{ VIA_REV_8251, "VIA 8251", TYPE_VIA8233 },
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* auto detection of DXS channel supports.
|
|
|
|
*/
|
2006-11-24 17:37:18 +03:00
|
|
|
|
2020-01-03 11:17:14 +03:00
|
|
|
static const struct snd_pci_quirk dxs_whitelist[] = {
|
2006-11-24 17:37:18 +03:00
|
|
|
SND_PCI_QUIRK(0x1005, 0x4710, "Avance Logic Mobo", VIA_DXS_ENABLE),
|
|
|
|
SND_PCI_QUIRK(0x1019, 0x0996, "ESC Mobo", VIA_DXS_48K),
|
|
|
|
SND_PCI_QUIRK(0x1019, 0x0a81, "ECS K7VTA3 v8.0", VIA_DXS_NO_VRA),
|
|
|
|
SND_PCI_QUIRK(0x1019, 0x0a85, "ECS L7VMM2", VIA_DXS_NO_VRA),
|
2009-02-09 19:15:50 +03:00
|
|
|
SND_PCI_QUIRK_VENDOR(0x1019, "ESC K8", VIA_DXS_SRC),
|
2006-11-24 17:37:18 +03:00
|
|
|
SND_PCI_QUIRK(0x1019, 0xaa01, "ESC K8T890-A", VIA_DXS_SRC),
|
|
|
|
SND_PCI_QUIRK(0x1025, 0x0033, "Acer Inspire 1353LM", VIA_DXS_NO_VRA),
|
|
|
|
SND_PCI_QUIRK(0x1025, 0x0046, "Acer Aspire 1524 WLMi", VIA_DXS_SRC),
|
2009-02-09 19:15:50 +03:00
|
|
|
SND_PCI_QUIRK_VENDOR(0x1043, "ASUS A7/A8", VIA_DXS_NO_VRA),
|
|
|
|
SND_PCI_QUIRK_VENDOR(0x1071, "Diverse Notebook", VIA_DXS_NO_VRA),
|
2006-11-24 17:37:18 +03:00
|
|
|
SND_PCI_QUIRK(0x10cf, 0x118e, "FSC Laptop", VIA_DXS_ENABLE),
|
2009-02-09 19:15:50 +03:00
|
|
|
SND_PCI_QUIRK_VENDOR(0x1106, "ASRock", VIA_DXS_SRC),
|
2007-10-11 16:35:00 +04:00
|
|
|
SND_PCI_QUIRK(0x1297, 0xa231, "Shuttle AK31v2", VIA_DXS_SRC),
|
2007-10-25 13:46:24 +04:00
|
|
|
SND_PCI_QUIRK(0x1297, 0xa232, "Shuttle", VIA_DXS_SRC),
|
|
|
|
SND_PCI_QUIRK(0x1297, 0xc160, "Shuttle Sk41G", VIA_DXS_SRC),
|
2006-11-24 17:37:18 +03:00
|
|
|
SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte GA-7VAXP", VIA_DXS_ENABLE),
|
|
|
|
SND_PCI_QUIRK(0x1462, 0x3800, "MSI KT266", VIA_DXS_ENABLE),
|
|
|
|
SND_PCI_QUIRK(0x1462, 0x7120, "MSI KT4V", VIA_DXS_ENABLE),
|
|
|
|
SND_PCI_QUIRK(0x1462, 0x7142, "MSI K8MM-V", VIA_DXS_ENABLE),
|
2009-02-09 19:15:50 +03:00
|
|
|
SND_PCI_QUIRK_VENDOR(0x1462, "MSI Mobo", VIA_DXS_SRC),
|
2006-11-24 17:37:18 +03:00
|
|
|
SND_PCI_QUIRK(0x147b, 0x1401, "ABIT KD7(-RAID)", VIA_DXS_ENABLE),
|
|
|
|
SND_PCI_QUIRK(0x147b, 0x1411, "ABIT VA-20", VIA_DXS_ENABLE),
|
|
|
|
SND_PCI_QUIRK(0x147b, 0x1413, "ABIT KV8 Pro", VIA_DXS_ENABLE),
|
|
|
|
SND_PCI_QUIRK(0x147b, 0x1415, "ABIT AV8", VIA_DXS_NO_VRA),
|
|
|
|
SND_PCI_QUIRK(0x14ff, 0x0403, "Twinhead mobo", VIA_DXS_ENABLE),
|
|
|
|
SND_PCI_QUIRK(0x14ff, 0x0408, "Twinhead laptop", VIA_DXS_SRC),
|
|
|
|
SND_PCI_QUIRK(0x1558, 0x4701, "Clevo D470", VIA_DXS_SRC),
|
|
|
|
SND_PCI_QUIRK(0x1584, 0x8120, "Diverse Laptop", VIA_DXS_ENABLE),
|
|
|
|
SND_PCI_QUIRK(0x1584, 0x8123, "Targa/Uniwill", VIA_DXS_NO_VRA),
|
|
|
|
SND_PCI_QUIRK(0x161f, 0x202b, "Amira Notebook", VIA_DXS_NO_VRA),
|
|
|
|
SND_PCI_QUIRK(0x161f, 0x2032, "m680x machines", VIA_DXS_48K),
|
|
|
|
SND_PCI_QUIRK(0x1631, 0xe004, "PB EasyNote 3174", VIA_DXS_ENABLE),
|
|
|
|
SND_PCI_QUIRK(0x1695, 0x3005, "EPoX EP-8K9A", VIA_DXS_ENABLE),
|
2009-02-09 19:15:50 +03:00
|
|
|
SND_PCI_QUIRK_VENDOR(0x1695, "EPoX mobo", VIA_DXS_SRC),
|
|
|
|
SND_PCI_QUIRK_VENDOR(0x16f3, "Jetway K8", VIA_DXS_SRC),
|
|
|
|
SND_PCI_QUIRK_VENDOR(0x1734, "FSC Laptop", VIA_DXS_SRC),
|
2006-11-24 17:37:18 +03:00
|
|
|
SND_PCI_QUIRK(0x1849, 0x3059, "ASRock K7VM2", VIA_DXS_NO_VRA),
|
2009-02-09 19:15:50 +03:00
|
|
|
SND_PCI_QUIRK_VENDOR(0x1849, "ASRock mobo", VIA_DXS_SRC),
|
2006-11-24 17:37:18 +03:00
|
|
|
SND_PCI_QUIRK(0x1919, 0x200a, "Soltek SL-K8", VIA_DXS_NO_VRA),
|
|
|
|
SND_PCI_QUIRK(0x4005, 0x4710, "MSI K7T266", VIA_DXS_SRC),
|
|
|
|
{ } /* terminator */
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
2012-12-06 21:35:10 +04:00
|
|
|
static int check_dxs_list(struct pci_dev *pci, int revision)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2006-11-24 17:37:18 +03:00
|
|
|
const struct snd_pci_quirk *w;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-11-24 17:37:18 +03:00
|
|
|
w = snd_pci_quirk_lookup(pci, dxs_whitelist);
|
|
|
|
if (w) {
|
2014-02-25 18:21:56 +04:00
|
|
|
dev_dbg(&pci->dev, "DXS white list for %s found\n",
|
2013-01-25 13:54:07 +04:00
|
|
|
snd_pci_quirk_name(w));
|
2006-11-24 17:37:18 +03:00
|
|
|
return w->value;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2006-04-27 18:56:07 +04:00
|
|
|
/* for newer revision, default to DXS_SRC */
|
|
|
|
if (revision >= VIA_REV_8235)
|
|
|
|
return VIA_DXS_SRC;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* not detected, try 48k rate only to be sure.
|
|
|
|
*/
|
2014-02-25 18:21:56 +04:00
|
|
|
dev_info(&pci->dev, "Assuming DXS channels with 48k fixed sample rate.\n");
|
|
|
|
dev_info(&pci->dev, " Please try dxs_support=5 option\n");
|
|
|
|
dev_info(&pci->dev, " and report if it works on your machine.\n");
|
|
|
|
dev_info(&pci->dev, " For more details, read ALSA-Configuration.txt.\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
return VIA_DXS_48K;
|
|
|
|
};
|
|
|
|
|
2012-12-06 21:35:10 +04:00
|
|
|
static int snd_via82xx_probe(struct pci_dev *pci,
|
|
|
|
const struct pci_device_id *pci_id)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-11-17 17:06:15 +03:00
|
|
|
struct snd_card *card;
|
|
|
|
struct via82xx *chip;
|
2005-04-17 02:20:36 +04:00
|
|
|
int chip_type = 0, card_type;
|
|
|
|
unsigned int i;
|
|
|
|
int err;
|
|
|
|
|
2014-01-29 17:20:19 +04:00
|
|
|
err = snd_card_new(&pci->dev, index, id, THIS_MODULE, 0, &card);
|
2008-12-28 18:44:30 +03:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
card_type = pci_id->driver_data;
|
|
|
|
switch (card_type) {
|
|
|
|
case TYPE_CARD_VIA686:
|
|
|
|
strcpy(card->driver, "VIA686A");
|
2007-06-09 02:46:36 +04:00
|
|
|
sprintf(card->shortname, "VIA 82C686A/B rev%x", pci->revision);
|
2005-04-17 02:20:36 +04:00
|
|
|
chip_type = TYPE_VIA686;
|
|
|
|
break;
|
|
|
|
case TYPE_CARD_VIA8233:
|
|
|
|
chip_type = TYPE_VIA8233;
|
2007-06-09 02:46:36 +04:00
|
|
|
sprintf(card->shortname, "VIA 823x rev%x", pci->revision);
|
2005-04-17 02:20:36 +04:00
|
|
|
for (i = 0; i < ARRAY_SIZE(via823x_cards); i++) {
|
2007-06-09 02:46:36 +04:00
|
|
|
if (pci->revision == via823x_cards[i].revision) {
|
2005-04-17 02:20:36 +04:00
|
|
|
chip_type = via823x_cards[i].type;
|
|
|
|
strcpy(card->shortname, via823x_cards[i].name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (chip_type != TYPE_VIA8233A) {
|
2005-10-04 10:46:51 +04:00
|
|
|
if (dxs_support == VIA_DXS_AUTO)
|
2007-06-09 02:46:36 +04:00
|
|
|
dxs_support = check_dxs_list(pci, pci->revision);
|
2005-04-17 02:20:36 +04:00
|
|
|
/* force to use VIA8233 or 8233A model according to
|
|
|
|
* dxs_support module option
|
|
|
|
*/
|
2005-10-04 10:46:51 +04:00
|
|
|
if (dxs_support == VIA_DXS_DISABLE)
|
2005-04-17 02:20:36 +04:00
|
|
|
chip_type = TYPE_VIA8233A;
|
|
|
|
else
|
|
|
|
chip_type = TYPE_VIA8233;
|
|
|
|
}
|
|
|
|
if (chip_type == TYPE_VIA8233A)
|
|
|
|
strcpy(card->driver, "VIA8233A");
|
2007-06-09 02:46:36 +04:00
|
|
|
else if (pci->revision >= VIA_REV_8237)
|
2005-04-17 02:20:36 +04:00
|
|
|
strcpy(card->driver, "VIA8237"); /* no slog assignment */
|
|
|
|
else
|
|
|
|
strcpy(card->driver, "VIA8233");
|
|
|
|
break;
|
|
|
|
default:
|
2014-02-25 18:21:56 +04:00
|
|
|
dev_err(card->dev, "invalid card type %d\n", card_type);
|
2005-04-17 02:20:36 +04:00
|
|
|
err = -EINVAL;
|
|
|
|
goto __error;
|
|
|
|
}
|
|
|
|
|
2007-06-09 02:46:36 +04:00
|
|
|
if ((err = snd_via82xx_create(card, pci, chip_type, pci->revision,
|
2005-10-04 10:46:51 +04:00
|
|
|
ac97_clock, &chip)) < 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
goto __error;
|
2005-11-17 18:10:35 +03:00
|
|
|
card->private_data = chip;
|
2005-10-04 10:46:51 +04:00
|
|
|
if ((err = snd_via82xx_mixer_new(chip, ac97_quirk)) < 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
goto __error;
|
|
|
|
|
|
|
|
if (chip_type == TYPE_VIA686) {
|
|
|
|
if ((err = snd_via686_pcm_new(chip)) < 0 ||
|
2005-10-04 10:46:51 +04:00
|
|
|
(err = snd_via686_init_misc(chip)) < 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
goto __error;
|
|
|
|
} else {
|
|
|
|
if (chip_type == TYPE_VIA8233A) {
|
|
|
|
if ((err = snd_via8233a_pcm_new(chip)) < 0)
|
|
|
|
goto __error;
|
|
|
|
// chip->dxs_fixed = 1; /* FIXME: use 48k for DXS #3? */
|
|
|
|
} else {
|
|
|
|
if ((err = snd_via8233_pcm_new(chip)) < 0)
|
|
|
|
goto __error;
|
2005-10-04 10:46:51 +04:00
|
|
|
if (dxs_support == VIA_DXS_48K)
|
2005-04-17 02:20:36 +04:00
|
|
|
chip->dxs_fixed = 1;
|
2005-10-04 10:46:51 +04:00
|
|
|
else if (dxs_support == VIA_DXS_NO_VRA)
|
2005-04-17 02:20:36 +04:00
|
|
|
chip->no_vra = 1;
|
2005-10-04 10:46:51 +04:00
|
|
|
else if (dxs_support == VIA_DXS_SRC) {
|
2005-04-11 17:04:33 +04:00
|
|
|
chip->no_vra = 1;
|
|
|
|
chip->dxs_src = 1;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2005-10-04 10:46:51 +04:00
|
|
|
if ((err = snd_via8233_init_misc(chip)) < 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
goto __error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* disable interrupts */
|
|
|
|
for (i = 0; i < chip->num_devs; i++)
|
|
|
|
snd_via82xx_channel_reset(chip, &chip->devs[i]);
|
|
|
|
|
|
|
|
snprintf(card->longname, sizeof(card->longname),
|
|
|
|
"%s with %s at %#lx, irq %d", card->shortname,
|
|
|
|
snd_ac97_get_short_name(chip->ac97), chip->port, chip->irq);
|
|
|
|
|
|
|
|
snd_via82xx_proc_init(chip);
|
|
|
|
|
|
|
|
if ((err = snd_card_register(card)) < 0) {
|
|
|
|
snd_card_free(card);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
pci_set_drvdata(pci, card);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
__error:
|
|
|
|
snd_card_free(card);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-12-06 21:35:10 +04:00
|
|
|
static void snd_via82xx_remove(struct pci_dev *pci)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
snd_card_free(pci_get_drvdata(pci));
|
|
|
|
}
|
|
|
|
|
2012-04-24 14:25:00 +04:00
|
|
|
static struct pci_driver via82xx_driver = {
|
2011-06-10 18:20:20 +04:00
|
|
|
.name = KBUILD_MODNAME,
|
2005-04-17 02:20:36 +04:00
|
|
|
.id_table = snd_via82xx_ids,
|
|
|
|
.probe = snd_via82xx_probe,
|
2012-12-06 21:35:10 +04:00
|
|
|
.remove = snd_via82xx_remove,
|
2012-07-02 17:20:37 +04:00
|
|
|
.driver = {
|
|
|
|
.pm = SND_VIA82XX_PM_OPS,
|
|
|
|
},
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
2012-04-24 14:25:00 +04:00
|
|
|
module_pci_driver(via82xx_driver);
|