diff options
author | Takashi Iwai <tiwai@suse.de> | 2009-12-01 09:56:52 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2009-12-01 09:56:52 -0500 |
commit | 9e298f449e667833c4cafad040ce8025a8ba1eed (patch) | |
tree | 5b05c9c36c305a99d4b6699427ab902b87db90fb /sound | |
parent | 2f703e7a2ea5f6d5ea14a7b2cd0d31be07839ac6 (diff) | |
parent | 62428f7b8c873d43be8201e66392c3aad82fec93 (diff) |
Merge branch 'topic/oxygen' into topic/hda
Diffstat (limited to 'sound')
-rw-r--r-- | sound/pci/oxygen/Makefile | 3 | ||||
-rw-r--r-- | sound/pci/oxygen/cs2000.h | 83 | ||||
-rw-r--r-- | sound/pci/oxygen/hifier.c | 61 | ||||
-rw-r--r-- | sound/pci/oxygen/oxygen.c | 248 | ||||
-rw-r--r-- | sound/pci/oxygen/oxygen.h | 5 | ||||
-rw-r--r-- | sound/pci/oxygen/oxygen_lib.c | 29 | ||||
-rw-r--r-- | sound/pci/oxygen/oxygen_mixer.c | 52 | ||||
-rw-r--r-- | sound/pci/oxygen/oxygen_pcm.c | 19 | ||||
-rw-r--r-- | sound/pci/oxygen/virtuoso.c | 1105 | ||||
-rw-r--r-- | sound/pci/oxygen/xonar.h | 50 | ||||
-rw-r--r-- | sound/pci/oxygen/xonar_cs43xx.c | 434 | ||||
-rw-r--r-- | sound/pci/oxygen/xonar_hdmi.c | 128 | ||||
-rw-r--r-- | sound/pci/oxygen/xonar_lib.c | 132 | ||||
-rw-r--r-- | sound/pci/oxygen/xonar_pcm179x.c | 1115 |
14 files changed, 2276 insertions, 1188 deletions
diff --git a/sound/pci/oxygen/Makefile b/sound/pci/oxygen/Makefile index 4ba07d42fd1d..389941cf6100 100644 --- a/sound/pci/oxygen/Makefile +++ b/sound/pci/oxygen/Makefile | |||
@@ -1,7 +1,8 @@ | |||
1 | snd-oxygen-lib-objs := oxygen_io.o oxygen_lib.o oxygen_mixer.o oxygen_pcm.o | 1 | snd-oxygen-lib-objs := oxygen_io.o oxygen_lib.o oxygen_mixer.o oxygen_pcm.o |
2 | snd-hifier-objs := hifier.o | 2 | snd-hifier-objs := hifier.o |
3 | snd-oxygen-objs := oxygen.o | 3 | snd-oxygen-objs := oxygen.o |
4 | snd-virtuoso-objs := virtuoso.o | 4 | snd-virtuoso-objs := virtuoso.o xonar_lib.o \ |
5 | xonar_pcm179x.o xonar_cs43xx.o xonar_hdmi.o | ||
5 | 6 | ||
6 | obj-$(CONFIG_SND_OXYGEN_LIB) += snd-oxygen-lib.o | 7 | obj-$(CONFIG_SND_OXYGEN_LIB) += snd-oxygen-lib.o |
7 | obj-$(CONFIG_SND_HIFIER) += snd-hifier.o | 8 | obj-$(CONFIG_SND_HIFIER) += snd-hifier.o |
diff --git a/sound/pci/oxygen/cs2000.h b/sound/pci/oxygen/cs2000.h new file mode 100644 index 000000000000..c3501bdb5edc --- /dev/null +++ b/sound/pci/oxygen/cs2000.h | |||
@@ -0,0 +1,83 @@ | |||
1 | #ifndef CS2000_H_INCLUDED | ||
2 | #define CS2000_H_INCLUDED | ||
3 | |||
4 | #define CS2000_DEV_ID 0x01 | ||
5 | #define CS2000_DEV_CTRL 0x02 | ||
6 | #define CS2000_DEV_CFG_1 0x03 | ||
7 | #define CS2000_DEV_CFG_2 0x04 | ||
8 | #define CS2000_GLOBAL_CFG 0x05 | ||
9 | #define CS2000_RATIO_0 0x06 /* 32 bits, big endian */ | ||
10 | #define CS2000_RATIO_1 0x0a | ||
11 | #define CS2000_RATIO_2 0x0e | ||
12 | #define CS2000_RATIO_3 0x12 | ||
13 | #define CS2000_FUN_CFG_1 0x16 | ||
14 | #define CS2000_FUN_CFG_2 0x17 | ||
15 | #define CS2000_FUN_CFG_3 0x1e | ||
16 | |||
17 | /* DEV_ID */ | ||
18 | #define CS2000_DEVICE_MASK 0xf8 | ||
19 | #define CS2000_REVISION_MASK 0x07 | ||
20 | |||
21 | /* DEV_CTRL */ | ||
22 | #define CS2000_UNLOCK 0x80 | ||
23 | #define CS2000_AUX_OUT_DIS 0x02 | ||
24 | #define CS2000_CLK_OUT_DIS 0x01 | ||
25 | |||
26 | /* DEV_CFG_1 */ | ||
27 | #define CS2000_R_MOD_SEL_MASK 0xe0 | ||
28 | #define CS2000_R_MOD_SEL_1 0x00 | ||
29 | #define CS2000_R_MOD_SEL_2 0x20 | ||
30 | #define CS2000_R_MOD_SEL_4 0x40 | ||
31 | #define CS2000_R_MOD_SEL_8 0x60 | ||
32 | #define CS2000_R_MOD_SEL_1_2 0x80 | ||
33 | #define CS2000_R_MOD_SEL_1_4 0xa0 | ||
34 | #define CS2000_R_MOD_SEL_1_8 0xc0 | ||
35 | #define CS2000_R_MOD_SEL_1_16 0xe0 | ||
36 | #define CS2000_R_SEL_MASK 0x18 | ||
37 | #define CS2000_R_SEL_SHIFT 3 | ||
38 | #define CS2000_AUX_OUT_SRC_MASK 0x06 | ||
39 | #define CS2000_AUX_OUT_SRC_REF_CLK 0x00 | ||
40 | #define CS2000_AUX_OUT_SRC_CLK_IN 0x02 | ||
41 | #define CS2000_AUX_OUT_SRC_CLK_OUT 0x04 | ||
42 | #define CS2000_AUX_OUT_SRC_PLL_LOCK 0x06 | ||
43 | #define CS2000_EN_DEV_CFG_1 0x01 | ||
44 | |||
45 | /* DEV_CFG_2 */ | ||
46 | #define CS2000_LOCK_CLK_MASK 0x06 | ||
47 | #define CS2000_LOCK_CLK_SHIFT 1 | ||
48 | #define CS2000_FRAC_N_SRC_MASK 0x01 | ||
49 | #define CS2000_FRAC_N_SRC_STATIC 0x00 | ||
50 | #define CS2000_FRAC_N_SRC_DYNAMIC 0x01 | ||
51 | |||
52 | /* GLOBAL_CFG */ | ||
53 | #define CS2000_FREEZE 0x08 | ||
54 | #define CS2000_EN_DEV_CFG_2 0x01 | ||
55 | |||
56 | /* FUN_CFG_1 */ | ||
57 | #define CS2000_CLK_SKIP_EN 0x80 | ||
58 | #define CS2000_AUX_LOCK_CFG_MASK 0x40 | ||
59 | #define CS2000_AUX_LOCK_CFG_PP_HIGH 0x00 | ||
60 | #define CS2000_AUX_LOCK_CFG_OD_LOW 0x40 | ||
61 | #define CS2000_REF_CLK_DIV_MASK 0x18 | ||
62 | #define CS2000_REF_CLK_DIV_4 0x00 | ||
63 | #define CS2000_REF_CLK_DIV_2 0x08 | ||
64 | #define CS2000_REF_CLK_DIV_1 0x10 | ||
65 | |||
66 | /* FUN_CFG_2 */ | ||
67 | #define CS2000_CLK_OUT_UNL 0x10 | ||
68 | #define CS2000_L_F_RATIO_CFG_MASK 0x08 | ||
69 | #define CS2000_L_F_RATIO_CFG_20_12 0x00 | ||
70 | #define CS2000_L_F_RATIO_CFG_12_20 0x08 | ||
71 | |||
72 | /* FUN_CFG_3 */ | ||
73 | #define CS2000_CLK_IN_BW_MASK 0x70 | ||
74 | #define CS2000_CLK_IN_BW_1 0x00 | ||
75 | #define CS2000_CLK_IN_BW_2 0x10 | ||
76 | #define CS2000_CLK_IN_BW_4 0x20 | ||
77 | #define CS2000_CLK_IN_BW_8 0x30 | ||
78 | #define CS2000_CLK_IN_BW_16 0x40 | ||
79 | #define CS2000_CLK_IN_BW_32 0x50 | ||
80 | #define CS2000_CLK_IN_BW_64 0x60 | ||
81 | #define CS2000_CLK_IN_BW_128 0x70 | ||
82 | |||
83 | #endif | ||
diff --git a/sound/pci/oxygen/hifier.c b/sound/pci/oxygen/hifier.c index 84ef13183419..e3c229b63311 100644 --- a/sound/pci/oxygen/hifier.c +++ b/sound/pci/oxygen/hifier.c | |||
@@ -17,6 +17,12 @@ | |||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | */ | 18 | */ |
19 | 19 | ||
20 | /* | ||
21 | * CMI8788: | ||
22 | * | ||
23 | * SPI 0 -> AK4396 | ||
24 | */ | ||
25 | |||
20 | #include <linux/delay.h> | 26 | #include <linux/delay.h> |
21 | #include <linux/pci.h> | 27 | #include <linux/pci.h> |
22 | #include <sound/control.h> | 28 | #include <sound/control.h> |
@@ -51,23 +57,28 @@ static struct pci_device_id hifier_ids[] __devinitdata = { | |||
51 | MODULE_DEVICE_TABLE(pci, hifier_ids); | 57 | MODULE_DEVICE_TABLE(pci, hifier_ids); |
52 | 58 | ||
53 | struct hifier_data { | 59 | struct hifier_data { |
54 | u8 ak4396_ctl2; | 60 | u8 ak4396_regs[5]; |
55 | }; | 61 | }; |
56 | 62 | ||
57 | static void ak4396_write(struct oxygen *chip, u8 reg, u8 value) | 63 | static void ak4396_write(struct oxygen *chip, u8 reg, u8 value) |
58 | { | 64 | { |
65 | struct hifier_data *data = chip->model_data; | ||
66 | |||
59 | oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER | | 67 | oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER | |
60 | OXYGEN_SPI_DATA_LENGTH_2 | | 68 | OXYGEN_SPI_DATA_LENGTH_2 | |
61 | OXYGEN_SPI_CLOCK_160 | | 69 | OXYGEN_SPI_CLOCK_160 | |
62 | (0 << OXYGEN_SPI_CODEC_SHIFT) | | 70 | (0 << OXYGEN_SPI_CODEC_SHIFT) | |
63 | OXYGEN_SPI_CEN_LATCH_CLOCK_HI, | 71 | OXYGEN_SPI_CEN_LATCH_CLOCK_HI, |
64 | AK4396_WRITE | (reg << 8) | value); | 72 | AK4396_WRITE | (reg << 8) | value); |
73 | data->ak4396_regs[reg] = value; | ||
65 | } | 74 | } |
66 | 75 | ||
67 | static void update_ak4396_volume(struct oxygen *chip) | 76 | static void ak4396_write_cached(struct oxygen *chip, u8 reg, u8 value) |
68 | { | 77 | { |
69 | ak4396_write(chip, AK4396_LCH_ATT, chip->dac_volume[0]); | 78 | struct hifier_data *data = chip->model_data; |
70 | ak4396_write(chip, AK4396_RCH_ATT, chip->dac_volume[1]); | 79 | |
80 | if (value != data->ak4396_regs[reg]) | ||
81 | ak4396_write(chip, reg, value); | ||
71 | } | 82 | } |
72 | 83 | ||
73 | static void hifier_registers_init(struct oxygen *chip) | 84 | static void hifier_registers_init(struct oxygen *chip) |
@@ -75,16 +86,19 @@ static void hifier_registers_init(struct oxygen *chip) | |||
75 | struct hifier_data *data = chip->model_data; | 86 | struct hifier_data *data = chip->model_data; |
76 | 87 | ||
77 | ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN); | 88 | ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN); |
78 | ak4396_write(chip, AK4396_CONTROL_2, data->ak4396_ctl2); | 89 | ak4396_write(chip, AK4396_CONTROL_2, |
90 | data->ak4396_regs[AK4396_CONTROL_2]); | ||
79 | ak4396_write(chip, AK4396_CONTROL_3, AK4396_PCM); | 91 | ak4396_write(chip, AK4396_CONTROL_3, AK4396_PCM); |
80 | update_ak4396_volume(chip); | 92 | ak4396_write(chip, AK4396_LCH_ATT, chip->dac_volume[0]); |
93 | ak4396_write(chip, AK4396_RCH_ATT, chip->dac_volume[1]); | ||
81 | } | 94 | } |
82 | 95 | ||
83 | static void hifier_init(struct oxygen *chip) | 96 | static void hifier_init(struct oxygen *chip) |
84 | { | 97 | { |
85 | struct hifier_data *data = chip->model_data; | 98 | struct hifier_data *data = chip->model_data; |
86 | 99 | ||
87 | data->ak4396_ctl2 = AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL; | 100 | data->ak4396_regs[AK4396_CONTROL_2] = |
101 | AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL; | ||
88 | hifier_registers_init(chip); | 102 | hifier_registers_init(chip); |
89 | 103 | ||
90 | snd_component_add(chip->card, "AK4396"); | 104 | snd_component_add(chip->card, "AK4396"); |
@@ -106,20 +120,29 @@ static void set_ak4396_params(struct oxygen *chip, | |||
106 | struct hifier_data *data = chip->model_data; | 120 | struct hifier_data *data = chip->model_data; |
107 | u8 value; | 121 | u8 value; |
108 | 122 | ||
109 | value = data->ak4396_ctl2 & ~AK4396_DFS_MASK; | 123 | value = data->ak4396_regs[AK4396_CONTROL_2] & ~AK4396_DFS_MASK; |
110 | if (params_rate(params) <= 54000) | 124 | if (params_rate(params) <= 54000) |
111 | value |= AK4396_DFS_NORMAL; | 125 | value |= AK4396_DFS_NORMAL; |
112 | else if (params_rate(params) <= 108000) | 126 | else if (params_rate(params) <= 108000) |
113 | value |= AK4396_DFS_DOUBLE; | 127 | value |= AK4396_DFS_DOUBLE; |
114 | else | 128 | else |
115 | value |= AK4396_DFS_QUAD; | 129 | value |= AK4396_DFS_QUAD; |
116 | data->ak4396_ctl2 = value; | ||
117 | 130 | ||
118 | msleep(1); /* wait for the new MCLK to become stable */ | 131 | msleep(1); /* wait for the new MCLK to become stable */ |
119 | 132 | ||
120 | ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB); | 133 | if (value != data->ak4396_regs[AK4396_CONTROL_2]) { |
121 | ak4396_write(chip, AK4396_CONTROL_2, value); | 134 | ak4396_write(chip, AK4396_CONTROL_1, |
122 | ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN); | 135 | AK4396_DIF_24_MSB); |
136 | ak4396_write(chip, AK4396_CONTROL_2, value); | ||
137 | ak4396_write(chip, AK4396_CONTROL_1, | ||
138 | AK4396_DIF_24_MSB | AK4396_RSTN); | ||
139 | } | ||
140 | } | ||
141 | |||
142 | static void update_ak4396_volume(struct oxygen *chip) | ||
143 | { | ||
144 | ak4396_write_cached(chip, AK4396_LCH_ATT, chip->dac_volume[0]); | ||
145 | ak4396_write_cached(chip, AK4396_RCH_ATT, chip->dac_volume[1]); | ||
123 | } | 146 | } |
124 | 147 | ||
125 | static void update_ak4396_mute(struct oxygen *chip) | 148 | static void update_ak4396_mute(struct oxygen *chip) |
@@ -127,11 +150,10 @@ static void update_ak4396_mute(struct oxygen *chip) | |||
127 | struct hifier_data *data = chip->model_data; | 150 | struct hifier_data *data = chip->model_data; |
128 | u8 value; | 151 | u8 value; |
129 | 152 | ||
130 | value = data->ak4396_ctl2 & ~AK4396_SMUTE; | 153 | value = data->ak4396_regs[AK4396_CONTROL_2] & ~AK4396_SMUTE; |
131 | if (chip->dac_mute) | 154 | if (chip->dac_mute) |
132 | value |= AK4396_SMUTE; | 155 | value |= AK4396_SMUTE; |
133 | data->ak4396_ctl2 = value; | 156 | ak4396_write_cached(chip, AK4396_CONTROL_2, value); |
134 | ak4396_write(chip, AK4396_CONTROL_2, value); | ||
135 | } | 157 | } |
136 | 158 | ||
137 | static void set_cs5340_params(struct oxygen *chip, | 159 | static void set_cs5340_params(struct oxygen *chip, |
@@ -141,21 +163,14 @@ static void set_cs5340_params(struct oxygen *chip, | |||
141 | 163 | ||
142 | static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0); | 164 | static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0); |
143 | 165 | ||
144 | static int hifier_control_filter(struct snd_kcontrol_new *template) | ||
145 | { | ||
146 | if (!strcmp(template->name, "Stereo Upmixing")) | ||
147 | return 1; /* stereo only - we don't need upmixing */ | ||
148 | return 0; | ||
149 | } | ||
150 | |||
151 | static const struct oxygen_model model_hifier = { | 166 | static const struct oxygen_model model_hifier = { |
152 | .shortname = "C-Media CMI8787", | 167 | .shortname = "C-Media CMI8787", |
153 | .longname = "C-Media Oxygen HD Audio", | 168 | .longname = "C-Media Oxygen HD Audio", |
154 | .chip = "CMI8788", | 169 | .chip = "CMI8788", |
155 | .init = hifier_init, | 170 | .init = hifier_init, |
156 | .control_filter = hifier_control_filter, | ||
157 | .cleanup = hifier_cleanup, | 171 | .cleanup = hifier_cleanup, |
158 | .resume = hifier_resume, | 172 | .resume = hifier_resume, |
173 | .get_i2s_mclk = oxygen_default_i2s_mclk, | ||
159 | .set_dac_params = set_ak4396_params, | 174 | .set_dac_params = set_ak4396_params, |
160 | .set_adc_params = set_cs5340_params, | 175 | .set_adc_params = set_cs5340_params, |
161 | .update_dac_volume = update_ak4396_volume, | 176 | .update_dac_volume = update_ak4396_volume, |
diff --git a/sound/pci/oxygen/oxygen.c b/sound/pci/oxygen/oxygen.c index 72db4c39007f..acbedebcffd9 100644 --- a/sound/pci/oxygen/oxygen.c +++ b/sound/pci/oxygen/oxygen.c | |||
@@ -18,6 +18,8 @@ | |||
18 | */ | 18 | */ |
19 | 19 | ||
20 | /* | 20 | /* |
21 | * CMI8788: | ||
22 | * | ||
21 | * SPI 0 -> 1st AK4396 (front) | 23 | * SPI 0 -> 1st AK4396 (front) |
22 | * SPI 1 -> 2nd AK4396 (surround) | 24 | * SPI 1 -> 2nd AK4396 (surround) |
23 | * SPI 2 -> 3rd AK4396 (center/LFE) | 25 | * SPI 2 -> 3rd AK4396 (center/LFE) |
@@ -27,6 +29,10 @@ | |||
27 | * GPIO 0 -> DFS0 of AK5385 | 29 | * GPIO 0 -> DFS0 of AK5385 |
28 | * GPIO 1 -> DFS1 of AK5385 | 30 | * GPIO 1 -> DFS1 of AK5385 |
29 | * GPIO 8 -> enable headphone amplifier on HT-Omega models | 31 | * GPIO 8 -> enable headphone amplifier on HT-Omega models |
32 | * | ||
33 | * CM9780: | ||
34 | * | ||
35 | * GPO 0 -> route line-in (0) or AC97 output (1) to ADC input | ||
30 | */ | 36 | */ |
31 | 37 | ||
32 | #include <linux/delay.h> | 38 | #include <linux/delay.h> |
@@ -91,8 +97,8 @@ MODULE_DEVICE_TABLE(pci, oxygen_ids); | |||
91 | #define GPIO_CLARO_HP 0x0100 | 97 | #define GPIO_CLARO_HP 0x0100 |
92 | 98 | ||
93 | struct generic_data { | 99 | struct generic_data { |
94 | u8 ak4396_ctl2; | 100 | u8 ak4396_regs[4][5]; |
95 | u16 saved_wm8785_registers[2]; | 101 | u16 wm8785_regs[3]; |
96 | }; | 102 | }; |
97 | 103 | ||
98 | static void ak4396_write(struct oxygen *chip, unsigned int codec, | 104 | static void ak4396_write(struct oxygen *chip, unsigned int codec, |
@@ -102,12 +108,24 @@ static void ak4396_write(struct oxygen *chip, unsigned int codec, | |||
102 | static const u8 codec_spi_map[4] = { | 108 | static const u8 codec_spi_map[4] = { |
103 | 0, 1, 2, 4 | 109 | 0, 1, 2, 4 |
104 | }; | 110 | }; |
111 | struct generic_data *data = chip->model_data; | ||
112 | |||
105 | oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER | | 113 | oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER | |
106 | OXYGEN_SPI_DATA_LENGTH_2 | | 114 | OXYGEN_SPI_DATA_LENGTH_2 | |
107 | OXYGEN_SPI_CLOCK_160 | | 115 | OXYGEN_SPI_CLOCK_160 | |
108 | (codec_spi_map[codec] << OXYGEN_SPI_CODEC_SHIFT) | | 116 | (codec_spi_map[codec] << OXYGEN_SPI_CODEC_SHIFT) | |
109 | OXYGEN_SPI_CEN_LATCH_CLOCK_HI, | 117 | OXYGEN_SPI_CEN_LATCH_CLOCK_HI, |
110 | AK4396_WRITE | (reg << 8) | value); | 118 | AK4396_WRITE | (reg << 8) | value); |
119 | data->ak4396_regs[codec][reg] = value; | ||
120 | } | ||
121 | |||
122 | static void ak4396_write_cached(struct oxygen *chip, unsigned int codec, | ||
123 | u8 reg, u8 value) | ||
124 | { | ||
125 | struct generic_data *data = chip->model_data; | ||
126 | |||
127 | if (value != data->ak4396_regs[codec][reg]) | ||
128 | ak4396_write(chip, codec, reg, value); | ||
111 | } | 129 | } |
112 | 130 | ||
113 | static void wm8785_write(struct oxygen *chip, u8 reg, unsigned int value) | 131 | static void wm8785_write(struct oxygen *chip, u8 reg, unsigned int value) |
@@ -120,20 +138,8 @@ static void wm8785_write(struct oxygen *chip, u8 reg, unsigned int value) | |||
120 | (3 << OXYGEN_SPI_CODEC_SHIFT) | | 138 | (3 << OXYGEN_SPI_CODEC_SHIFT) | |
121 | OXYGEN_SPI_CEN_LATCH_CLOCK_LO, | 139 | OXYGEN_SPI_CEN_LATCH_CLOCK_LO, |
122 | (reg << 9) | value); | 140 | (reg << 9) | value); |
123 | if (reg < ARRAY_SIZE(data->saved_wm8785_registers)) | 141 | if (reg < ARRAY_SIZE(data->wm8785_regs)) |
124 | data->saved_wm8785_registers[reg] = value; | 142 | data->wm8785_regs[reg] = value; |
125 | } | ||
126 | |||
127 | static void update_ak4396_volume(struct oxygen *chip) | ||
128 | { | ||
129 | unsigned int i; | ||
130 | |||
131 | for (i = 0; i < 4; ++i) { | ||
132 | ak4396_write(chip, i, | ||
133 | AK4396_LCH_ATT, chip->dac_volume[i * 2]); | ||
134 | ak4396_write(chip, i, | ||
135 | AK4396_RCH_ATT, chip->dac_volume[i * 2 + 1]); | ||
136 | } | ||
137 | } | 143 | } |
138 | 144 | ||
139 | static void ak4396_registers_init(struct oxygen *chip) | 145 | static void ak4396_registers_init(struct oxygen *chip) |
@@ -142,21 +148,25 @@ static void ak4396_registers_init(struct oxygen *chip) | |||
142 | unsigned int i; | 148 | unsigned int i; |
143 | 149 | ||
144 | for (i = 0; i < 4; ++i) { | 150 | for (i = 0; i < 4; ++i) { |
145 | ak4396_write(chip, i, | 151 | ak4396_write(chip, i, AK4396_CONTROL_1, |
146 | AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN); | 152 | AK4396_DIF_24_MSB | AK4396_RSTN); |
147 | ak4396_write(chip, i, | 153 | ak4396_write(chip, i, AK4396_CONTROL_2, |
148 | AK4396_CONTROL_2, data->ak4396_ctl2); | 154 | data->ak4396_regs[0][AK4396_CONTROL_2]); |
149 | ak4396_write(chip, i, | 155 | ak4396_write(chip, i, AK4396_CONTROL_3, |
150 | AK4396_CONTROL_3, AK4396_PCM); | 156 | AK4396_PCM); |
157 | ak4396_write(chip, i, AK4396_LCH_ATT, | ||
158 | chip->dac_volume[i * 2]); | ||
159 | ak4396_write(chip, i, AK4396_RCH_ATT, | ||
160 | chip->dac_volume[i * 2 + 1]); | ||
151 | } | 161 | } |
152 | update_ak4396_volume(chip); | ||
153 | } | 162 | } |
154 | 163 | ||
155 | static void ak4396_init(struct oxygen *chip) | 164 | static void ak4396_init(struct oxygen *chip) |
156 | { | 165 | { |
157 | struct generic_data *data = chip->model_data; | 166 | struct generic_data *data = chip->model_data; |
158 | 167 | ||
159 | data->ak4396_ctl2 = AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL; | 168 | data->ak4396_regs[0][AK4396_CONTROL_2] = |
169 | AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL; | ||
160 | ak4396_registers_init(chip); | 170 | ak4396_registers_init(chip); |
161 | snd_component_add(chip->card, "AK4396"); | 171 | snd_component_add(chip->card, "AK4396"); |
162 | } | 172 | } |
@@ -173,17 +183,17 @@ static void wm8785_registers_init(struct oxygen *chip) | |||
173 | struct generic_data *data = chip->model_data; | 183 | struct generic_data *data = chip->model_data; |
174 | 184 | ||
175 | wm8785_write(chip, WM8785_R7, 0); | 185 | wm8785_write(chip, WM8785_R7, 0); |
176 | wm8785_write(chip, WM8785_R0, data->saved_wm8785_registers[0]); | 186 | wm8785_write(chip, WM8785_R0, data->wm8785_regs[0]); |
177 | wm8785_write(chip, WM8785_R1, data->saved_wm8785_registers[1]); | 187 | wm8785_write(chip, WM8785_R2, data->wm8785_regs[2]); |
178 | } | 188 | } |
179 | 189 | ||
180 | static void wm8785_init(struct oxygen *chip) | 190 | static void wm8785_init(struct oxygen *chip) |
181 | { | 191 | { |
182 | struct generic_data *data = chip->model_data; | 192 | struct generic_data *data = chip->model_data; |
183 | 193 | ||
184 | data->saved_wm8785_registers[0] = WM8785_MCR_SLAVE | | 194 | data->wm8785_regs[0] = |
185 | WM8785_OSR_SINGLE | WM8785_FORMAT_LJUST; | 195 | WM8785_MCR_SLAVE | WM8785_OSR_SINGLE | WM8785_FORMAT_LJUST; |
186 | data->saved_wm8785_registers[1] = WM8785_WL_24; | 196 | data->wm8785_regs[2] = WM8785_HPFR | WM8785_HPFL; |
187 | wm8785_registers_init(chip); | 197 | wm8785_registers_init(chip); |
188 | snd_component_add(chip->card, "WM8785"); | 198 | snd_component_add(chip->card, "WM8785"); |
189 | } | 199 | } |
@@ -264,24 +274,36 @@ static void set_ak4396_params(struct oxygen *chip, | |||
264 | unsigned int i; | 274 | unsigned int i; |
265 | u8 value; | 275 | u8 value; |
266 | 276 | ||
267 | value = data->ak4396_ctl2 & ~AK4396_DFS_MASK; | 277 | value = data->ak4396_regs[0][AK4396_CONTROL_2] & ~AK4396_DFS_MASK; |
268 | if (params_rate(params) <= 54000) | 278 | if (params_rate(params) <= 54000) |
269 | value |= AK4396_DFS_NORMAL; | 279 | value |= AK4396_DFS_NORMAL; |
270 | else if (params_rate(params) <= 108000) | 280 | else if (params_rate(params) <= 108000) |
271 | value |= AK4396_DFS_DOUBLE; | 281 | value |= AK4396_DFS_DOUBLE; |
272 | else | 282 | else |
273 | value |= AK4396_DFS_QUAD; | 283 | value |= AK4396_DFS_QUAD; |
274 | data->ak4396_ctl2 = value; | ||
275 | 284 | ||
276 | msleep(1); /* wait for the new MCLK to become stable */ | 285 | msleep(1); /* wait for the new MCLK to become stable */ |
277 | 286 | ||
287 | if (value != data->ak4396_regs[0][AK4396_CONTROL_2]) { | ||
288 | for (i = 0; i < 4; ++i) { | ||
289 | ak4396_write(chip, i, AK4396_CONTROL_1, | ||
290 | AK4396_DIF_24_MSB); | ||
291 | ak4396_write(chip, i, AK4396_CONTROL_2, value); | ||
292 | ak4396_write(chip, i, AK4396_CONTROL_1, | ||
293 | AK4396_DIF_24_MSB | AK4396_RSTN); | ||
294 | } | ||
295 | } | ||
296 | } | ||
297 | |||
298 | static void update_ak4396_volume(struct oxygen *chip) | ||
299 | { | ||
300 | unsigned int i; | ||
301 | |||
278 | for (i = 0; i < 4; ++i) { | 302 | for (i = 0; i < 4; ++i) { |
279 | ak4396_write(chip, i, | 303 | ak4396_write_cached(chip, i, AK4396_LCH_ATT, |
280 | AK4396_CONTROL_1, AK4396_DIF_24_MSB); | 304 | chip->dac_volume[i * 2]); |
281 | ak4396_write(chip, i, | 305 | ak4396_write_cached(chip, i, AK4396_RCH_ATT, |
282 | AK4396_CONTROL_2, value); | 306 | chip->dac_volume[i * 2 + 1]); |
283 | ak4396_write(chip, i, | ||
284 | AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN); | ||
285 | } | 307 | } |
286 | } | 308 | } |
287 | 309 | ||
@@ -291,21 +313,19 @@ static void update_ak4396_mute(struct oxygen *chip) | |||
291 | unsigned int i; | 313 | unsigned int i; |
292 | u8 value; | 314 | u8 value; |
293 | 315 | ||
294 | value = data->ak4396_ctl2 & ~AK4396_SMUTE; | 316 | value = data->ak4396_regs[0][AK4396_CONTROL_2] & ~AK4396_SMUTE; |
295 | if (chip->dac_mute) | 317 | if (chip->dac_mute) |
296 | value |= AK4396_SMUTE; | 318 | value |= AK4396_SMUTE; |
297 | data->ak4396_ctl2 = value; | ||
298 | for (i = 0; i < 4; ++i) | 319 | for (i = 0; i < 4; ++i) |
299 | ak4396_write(chip, i, AK4396_CONTROL_2, value); | 320 | ak4396_write_cached(chip, i, AK4396_CONTROL_2, value); |
300 | } | 321 | } |
301 | 322 | ||
302 | static void set_wm8785_params(struct oxygen *chip, | 323 | static void set_wm8785_params(struct oxygen *chip, |
303 | struct snd_pcm_hw_params *params) | 324 | struct snd_pcm_hw_params *params) |
304 | { | 325 | { |
326 | struct generic_data *data = chip->model_data; | ||
305 | unsigned int value; | 327 | unsigned int value; |
306 | 328 | ||
307 | wm8785_write(chip, WM8785_R7, 0); | ||
308 | |||
309 | value = WM8785_MCR_SLAVE | WM8785_FORMAT_LJUST; | 329 | value = WM8785_MCR_SLAVE | WM8785_FORMAT_LJUST; |
310 | if (params_rate(params) <= 48000) | 330 | if (params_rate(params) <= 48000) |
311 | value |= WM8785_OSR_SINGLE; | 331 | value |= WM8785_OSR_SINGLE; |
@@ -313,13 +333,11 @@ static void set_wm8785_params(struct oxygen *chip, | |||
313 | value |= WM8785_OSR_DOUBLE; | 333 | value |= WM8785_OSR_DOUBLE; |
314 | else | 334 | else |
315 | value |= WM8785_OSR_QUAD; | 335 | value |= WM8785_OSR_QUAD; |
316 | wm8785_write(chip, WM8785_R0, value); | 336 | if (value != data->wm8785_regs[0]) { |
317 | 337 | wm8785_write(chip, WM8785_R7, 0); | |
318 | if (snd_pcm_format_width(params_format(params)) <= 16) | 338 | wm8785_write(chip, WM8785_R0, value); |
319 | value = WM8785_WL_16; | 339 | wm8785_write(chip, WM8785_R2, data->wm8785_regs[2]); |
320 | else | 340 | } |
321 | value = WM8785_WL_24; | ||
322 | wm8785_write(chip, WM8785_R1, value); | ||
323 | } | 341 | } |
324 | 342 | ||
325 | static void set_ak5385_params(struct oxygen *chip, | 343 | static void set_ak5385_params(struct oxygen *chip, |
@@ -337,6 +355,134 @@ static void set_ak5385_params(struct oxygen *chip, | |||
337 | value, GPIO_AK5385_DFS_MASK); | 355 | value, GPIO_AK5385_DFS_MASK); |
338 | } | 356 | } |
339 | 357 | ||
358 | static int rolloff_info(struct snd_kcontrol *ctl, | ||
359 | struct snd_ctl_elem_info *info) | ||
360 | { | ||
361 | static const char *const names[2] = { | ||
362 | "Sharp Roll-off", "Slow Roll-off" | ||
363 | }; | ||
364 | |||
365 | info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | ||
366 | info->count = 1; | ||
367 | info->value.enumerated.items = 2; | ||
368 | if (info->value.enumerated.item >= 2) | ||
369 | info->value.enumerated.item = 1; | ||
370 | strcpy(info->value.enumerated.name, names[info->value.enumerated.item]); | ||
371 | return 0; | ||
372 | } | ||
373 | |||
374 | static int rolloff_get(struct snd_kcontrol *ctl, | ||
375 | struct snd_ctl_elem_value *value) | ||
376 | { | ||
377 | struct oxygen *chip = ctl->private_data; | ||
378 | struct generic_data *data = chip->model_data; | ||
379 | |||
380 | value->value.enumerated.item[0] = | ||
381 | (data->ak4396_regs[0][AK4396_CONTROL_2] & AK4396_SLOW) != 0; | ||
382 | return 0; | ||
383 | } | ||
384 | |||
385 | static int rolloff_put(struct snd_kcontrol *ctl, | ||
386 | struct snd_ctl_elem_value *value) | ||
387 | { | ||
388 | struct oxygen *chip = ctl->private_data; | ||
389 | struct generic_data *data = chip->model_data; | ||
390 | unsigned int i; | ||
391 | int changed; | ||
392 | u8 reg; | ||
393 | |||
394 | mutex_lock(&chip->mutex); | ||
395 | reg = data->ak4396_regs[0][AK4396_CONTROL_2]; | ||
396 | if (value->value.enumerated.item[0]) | ||
397 | reg |= AK4396_SLOW; | ||
398 | else | ||
399 | reg &= ~AK4396_SLOW; | ||
400 | changed = reg != data->ak4396_regs[0][AK4396_CONTROL_2]; | ||
401 | if (changed) { | ||
402 | for (i = 0; i < 4; ++i) | ||
403 | ak4396_write(chip, i, AK4396_CONTROL_2, reg); | ||
404 | } | ||
405 | mutex_unlock(&chip->mutex); | ||
406 | return changed; | ||
407 | } | ||
408 | |||
409 | static const struct snd_kcontrol_new rolloff_control = { | ||
410 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
411 | .name = "DAC Filter Playback Enum", | ||
412 | .info = rolloff_info, | ||
413 | .get = rolloff_get, | ||
414 | .put = rolloff_put, | ||
415 | }; | ||
416 | |||
417 | static int hpf_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info) | ||
418 | { | ||
419 | static const char *const names[2] = { | ||
420 | "None", "High-pass Filter" | ||
421 | }; | ||
422 | |||
423 | info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | ||
424 | info->count = 1; | ||
425 | info->value.enumerated.items = 2; | ||
426 | if (info->value.enumerated.item >= 2) | ||
427 | info->value.enumerated.item = 1; | ||
428 | strcpy(info->value.enumerated.name, names[info->value.enumerated.item]); | ||
429 | return 0; | ||
430 | } | ||
431 | |||
432 | static int hpf_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) | ||
433 | { | ||
434 | struct oxygen *chip = ctl->private_data; | ||
435 | struct generic_data *data = chip->model_data; | ||
436 | |||
437 | value->value.enumerated.item[0] = | ||
438 | (data->wm8785_regs[WM8785_R2] & WM8785_HPFR) != 0; | ||
439 | return 0; | ||
440 | } | ||
441 | |||
442 | static int hpf_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) | ||
443 | { | ||
444 | struct oxygen *chip = ctl->private_data; | ||
445 | struct generic_data *data = chip->model_data; | ||
446 | unsigned int reg; | ||
447 | int changed; | ||
448 | |||
449 | mutex_lock(&chip->mutex); | ||
450 | reg = data->wm8785_regs[WM8785_R2] & ~(WM8785_HPFR | WM8785_HPFL); | ||
451 | if (value->value.enumerated.item[0]) | ||
452 | reg |= WM8785_HPFR | WM8785_HPFL; | ||
453 | changed = reg != data->wm8785_regs[WM8785_R2]; | ||
454 | if (changed) | ||
455 | wm8785_write(chip, WM8785_R2, reg); | ||
456 | mutex_unlock(&chip->mutex); | ||
457 | return changed; | ||
458 | } | ||
459 | |||
460 | static const struct snd_kcontrol_new hpf_control = { | ||
461 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
462 | .name = "ADC Filter Capture Enum", | ||
463 | .info = hpf_info, | ||
464 | .get = hpf_get, | ||
465 | .put = hpf_put, | ||
466 | }; | ||
467 | |||
468 | static int generic_mixer_init(struct oxygen *chip) | ||
469 | { | ||
470 | return snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip)); | ||
471 | } | ||
472 | |||
473 | static int generic_wm8785_mixer_init(struct oxygen *chip) | ||
474 | { | ||
475 | int err; | ||
476 | |||
477 | err = generic_mixer_init(chip); | ||
478 | if (err < 0) | ||
479 | return err; | ||
480 | err = snd_ctl_add(chip->card, snd_ctl_new1(&hpf_control, chip)); | ||
481 | if (err < 0) | ||
482 | return err; | ||
483 | return 0; | ||
484 | } | ||
485 | |||
340 | static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0); | 486 | static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0); |
341 | 487 | ||
342 | static const struct oxygen_model model_generic = { | 488 | static const struct oxygen_model model_generic = { |
@@ -344,8 +490,10 @@ static const struct oxygen_model model_generic = { | |||
344 | .longname = "C-Media Oxygen HD Audio", | 490 | .longname = "C-Media Oxygen HD Audio", |
345 | .chip = "CMI8788", | 491 | .chip = "CMI8788", |
346 | .init = generic_init, | 492 | .init = generic_init, |
493 | .mixer_init = generic_wm8785_mixer_init, | ||
347 | .cleanup = generic_cleanup, | 494 | .cleanup = generic_cleanup, |
348 | .resume = generic_resume, | 495 | .resume = generic_resume, |
496 | .get_i2s_mclk = oxygen_default_i2s_mclk, | ||
349 | .set_dac_params = set_ak4396_params, | 497 | .set_dac_params = set_ak4396_params, |
350 | .set_adc_params = set_wm8785_params, | 498 | .set_adc_params = set_wm8785_params, |
351 | .update_dac_volume = update_ak4396_volume, | 499 | .update_dac_volume = update_ak4396_volume, |
@@ -374,6 +522,7 @@ static int __devinit get_oxygen_model(struct oxygen *chip, | |||
374 | switch (id->driver_data) { | 522 | switch (id->driver_data) { |
375 | case MODEL_MERIDIAN: | 523 | case MODEL_MERIDIAN: |
376 | chip->model.init = meridian_init; | 524 | chip->model.init = meridian_init; |
525 | chip->model.mixer_init = generic_mixer_init; | ||
377 | chip->model.resume = meridian_resume; | 526 | chip->model.resume = meridian_resume; |
378 | chip->model.set_adc_params = set_ak5385_params; | 527 | chip->model.set_adc_params = set_ak5385_params; |
379 | chip->model.device_config = PLAYBACK_0_TO_I2S | | 528 | chip->model.device_config = PLAYBACK_0_TO_I2S | |
@@ -389,6 +538,7 @@ static int __devinit get_oxygen_model(struct oxygen *chip, | |||
389 | break; | 538 | break; |
390 | case MODEL_CLARO_HALO: | 539 | case MODEL_CLARO_HALO: |
391 | chip->model.init = claro_halo_init; | 540 | chip->model.init = claro_halo_init; |
541 | chip->model.mixer_init = generic_mixer_init; | ||
392 | chip->model.cleanup = claro_cleanup; | 542 | chip->model.cleanup = claro_cleanup; |
393 | chip->model.suspend = claro_suspend; | 543 | chip->model.suspend = claro_suspend; |
394 | chip->model.resume = claro_resume; | 544 | chip->model.resume = claro_resume; |
diff --git a/sound/pci/oxygen/oxygen.h b/sound/pci/oxygen/oxygen.h index bd615dbffadb..6147216af744 100644 --- a/sound/pci/oxygen/oxygen.h +++ b/sound/pci/oxygen/oxygen.h | |||
@@ -78,12 +78,15 @@ struct oxygen_model { | |||
78 | void (*resume)(struct oxygen *chip); | 78 | void (*resume)(struct oxygen *chip); |
79 | void (*pcm_hardware_filter)(unsigned int channel, | 79 | void (*pcm_hardware_filter)(unsigned int channel, |
80 | struct snd_pcm_hardware *hardware); | 80 | struct snd_pcm_hardware *hardware); |
81 | unsigned int (*get_i2s_mclk)(struct oxygen *chip, unsigned int channel, | ||
82 | struct snd_pcm_hw_params *hw_params); | ||
81 | void (*set_dac_params)(struct oxygen *chip, | 83 | void (*set_dac_params)(struct oxygen *chip, |
82 | struct snd_pcm_hw_params *params); | 84 | struct snd_pcm_hw_params *params); |
83 | void (*set_adc_params)(struct oxygen *chip, | 85 | void (*set_adc_params)(struct oxygen *chip, |
84 | struct snd_pcm_hw_params *params); | 86 | struct snd_pcm_hw_params *params); |
85 | void (*update_dac_volume)(struct oxygen *chip); | 87 | void (*update_dac_volume)(struct oxygen *chip); |
86 | void (*update_dac_mute)(struct oxygen *chip); | 88 | void (*update_dac_mute)(struct oxygen *chip); |
89 | void (*update_center_lfe_mix)(struct oxygen *chip, bool mixed); | ||
87 | void (*gpio_changed)(struct oxygen *chip); | 90 | void (*gpio_changed)(struct oxygen *chip); |
88 | void (*uart_input)(struct oxygen *chip); | 91 | void (*uart_input)(struct oxygen *chip); |
89 | void (*ac97_switch)(struct oxygen *chip, | 92 | void (*ac97_switch)(struct oxygen *chip, |
@@ -162,6 +165,8 @@ void oxygen_update_spdif_source(struct oxygen *chip); | |||
162 | /* oxygen_pcm.c */ | 165 | /* oxygen_pcm.c */ |
163 | 166 | ||
164 | int oxygen_pcm_init(struct oxygen *chip); | 167 | int oxygen_pcm_init(struct oxygen *chip); |
168 | unsigned int oxygen_default_i2s_mclk(struct oxygen *chip, unsigned int channel, | ||
169 | struct snd_pcm_hw_params *hw_params); | ||
165 | 170 | ||
166 | /* oxygen_io.c */ | 171 | /* oxygen_io.c */ |
167 | 172 | ||
diff --git a/sound/pci/oxygen/oxygen_lib.c b/sound/pci/oxygen/oxygen_lib.c index 9a8936e20744..9c5e6450eebb 100644 --- a/sound/pci/oxygen/oxygen_lib.c +++ b/sound/pci/oxygen/oxygen_lib.c | |||
@@ -278,7 +278,11 @@ oxygen_search_pci_id(struct oxygen *chip, const struct pci_device_id ids[]) | |||
278 | static void oxygen_restore_eeprom(struct oxygen *chip, | 278 | static void oxygen_restore_eeprom(struct oxygen *chip, |
279 | const struct pci_device_id *id) | 279 | const struct pci_device_id *id) |
280 | { | 280 | { |
281 | if (oxygen_read_eeprom(chip, 0) != OXYGEN_EEPROM_ID) { | 281 | u16 eeprom_id; |
282 | |||
283 | eeprom_id = oxygen_read_eeprom(chip, 0); | ||
284 | if (eeprom_id != OXYGEN_EEPROM_ID && | ||
285 | (eeprom_id != 0xffff || id->subdevice != 0x8788)) { | ||
282 | /* | 286 | /* |
283 | * This function gets called only when a known card model has | 287 | * This function gets called only when a known card model has |
284 | * been detected, i.e., we know there is a valid subsystem | 288 | * been detected, i.e., we know there is a valid subsystem |
@@ -303,6 +307,28 @@ static void oxygen_restore_eeprom(struct oxygen *chip, | |||
303 | } | 307 | } |
304 | } | 308 | } |
305 | 309 | ||
310 | static void pci_bridge_magic(void) | ||
311 | { | ||
312 | struct pci_dev *pci = NULL; | ||
313 | u32 tmp; | ||
314 | |||
315 | for (;;) { | ||
316 | /* If there is any Pericom PI7C9X110 PCI-E/PCI bridge ... */ | ||
317 | pci = pci_get_device(0x12d8, 0xe110, pci); | ||
318 | if (!pci) | ||
319 | break; | ||
320 | /* | ||
321 | * ... configure its secondary internal arbiter to park to | ||
322 | * the secondary port, instead of to the last master. | ||
323 | */ | ||
324 | if (!pci_read_config_dword(pci, 0x40, &tmp)) { | ||
325 | tmp |= 1; | ||
326 | pci_write_config_dword(pci, 0x40, tmp); | ||
327 | } | ||
328 | /* Why? Try asking C-Media. */ | ||
329 | } | ||
330 | } | ||
331 | |||
306 | static void oxygen_init(struct oxygen *chip) | 332 | static void oxygen_init(struct oxygen *chip) |
307 | { | 333 | { |
308 | unsigned int i; | 334 | unsigned int i; |
@@ -581,6 +607,7 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id, | |||
581 | snd_card_set_dev(card, &pci->dev); | 607 | snd_card_set_dev(card, &pci->dev); |
582 | card->private_free = oxygen_card_free; | 608 | card->private_free = oxygen_card_free; |
583 | 609 | ||
610 | pci_bridge_magic(); | ||
584 | oxygen_init(chip); | 611 | oxygen_init(chip); |
585 | chip->model.init(chip); | 612 | chip->model.init(chip); |
586 | 613 | ||
diff --git a/sound/pci/oxygen/oxygen_mixer.c b/sound/pci/oxygen/oxygen_mixer.c index 5401c547c4e3..f375b8a27862 100644 --- a/sound/pci/oxygen/oxygen_mixer.c +++ b/sound/pci/oxygen/oxygen_mixer.c | |||
@@ -99,11 +99,15 @@ static int dac_mute_put(struct snd_kcontrol *ctl, | |||
99 | 99 | ||
100 | static int upmix_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info) | 100 | static int upmix_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info) |
101 | { | 101 | { |
102 | static const char *const names[3] = { | 102 | static const char *const names[5] = { |
103 | "Front", "Front+Surround", "Front+Surround+Back" | 103 | "Front", |
104 | "Front+Surround", | ||
105 | "Front+Surround+Back", | ||
106 | "Front+Surround+Center/LFE", | ||
107 | "Front+Surround+Center/LFE+Back", | ||
104 | }; | 108 | }; |
105 | struct oxygen *chip = ctl->private_data; | 109 | struct oxygen *chip = ctl->private_data; |
106 | unsigned int count = 2 + (chip->model.dac_channels == 8); | 110 | unsigned int count = chip->model.update_center_lfe_mix ? 5 : 3; |
107 | 111 | ||
108 | info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | 112 | info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
109 | info->count = 1; | 113 | info->count = 1; |
@@ -127,7 +131,7 @@ static int upmix_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) | |||
127 | void oxygen_update_dac_routing(struct oxygen *chip) | 131 | void oxygen_update_dac_routing(struct oxygen *chip) |
128 | { | 132 | { |
129 | /* DAC 0: front, DAC 1: surround, DAC 2: center/LFE, DAC 3: back */ | 133 | /* DAC 0: front, DAC 1: surround, DAC 2: center/LFE, DAC 3: back */ |
130 | static const unsigned int reg_values[3] = { | 134 | static const unsigned int reg_values[5] = { |
131 | /* stereo -> front */ | 135 | /* stereo -> front */ |
132 | (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) | | 136 | (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) | |
133 | (1 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) | | 137 | (1 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) | |
@@ -143,6 +147,16 @@ void oxygen_update_dac_routing(struct oxygen *chip) | |||
143 | (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) | | 147 | (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) | |
144 | (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) | | 148 | (2 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) | |
145 | (0 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT), | 149 | (0 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT), |
150 | /* stereo -> front+surround+center/LFE */ | ||
151 | (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) | | ||
152 | (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) | | ||
153 | (0 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) | | ||
154 | (3 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT), | ||
155 | /* stereo -> front+surround+center/LFE+back */ | ||
156 | (0 << OXYGEN_PLAY_DAC0_SOURCE_SHIFT) | | ||
157 | (0 << OXYGEN_PLAY_DAC1_SOURCE_SHIFT) | | ||
158 | (0 << OXYGEN_PLAY_DAC2_SOURCE_SHIFT) | | ||
159 | (0 << OXYGEN_PLAY_DAC3_SOURCE_SHIFT), | ||
146 | }; | 160 | }; |
147 | u8 channels; | 161 | u8 channels; |
148 | unsigned int reg_value; | 162 | unsigned int reg_value; |
@@ -167,22 +181,23 @@ void oxygen_update_dac_routing(struct oxygen *chip) | |||
167 | OXYGEN_PLAY_DAC1_SOURCE_MASK | | 181 | OXYGEN_PLAY_DAC1_SOURCE_MASK | |
168 | OXYGEN_PLAY_DAC2_SOURCE_MASK | | 182 | OXYGEN_PLAY_DAC2_SOURCE_MASK | |
169 | OXYGEN_PLAY_DAC3_SOURCE_MASK); | 183 | OXYGEN_PLAY_DAC3_SOURCE_MASK); |
184 | if (chip->model.update_center_lfe_mix) | ||
185 | chip->model.update_center_lfe_mix(chip, chip->dac_routing > 2); | ||
170 | } | 186 | } |
171 | 187 | ||
172 | static int upmix_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) | 188 | static int upmix_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value) |
173 | { | 189 | { |
174 | struct oxygen *chip = ctl->private_data; | 190 | struct oxygen *chip = ctl->private_data; |
175 | unsigned int count = 2 + (chip->model.dac_channels == 8); | 191 | unsigned int count = chip->model.update_center_lfe_mix ? 5 : 3; |
176 | int changed; | 192 | int changed; |
177 | 193 | ||
194 | if (value->value.enumerated.item[0] >= count) | ||
195 | return -EINVAL; | ||
178 | mutex_lock(&chip->mutex); | 196 | mutex_lock(&chip->mutex); |
179 | changed = value->value.enumerated.item[0] != chip->dac_routing; | 197 | changed = value->value.enumerated.item[0] != chip->dac_routing; |
180 | if (changed) { | 198 | if (changed) { |
181 | chip->dac_routing = min(value->value.enumerated.item[0], | 199 | chip->dac_routing = value->value.enumerated.item[0]; |
182 | count - 1); | ||
183 | spin_lock_irq(&chip->reg_lock); | ||
184 | oxygen_update_dac_routing(chip); | 200 | oxygen_update_dac_routing(chip); |
185 | spin_unlock_irq(&chip->reg_lock); | ||
186 | } | 201 | } |
187 | mutex_unlock(&chip->mutex); | 202 | mutex_unlock(&chip->mutex); |
188 | return changed; | 203 | return changed; |
@@ -790,7 +805,7 @@ static const struct { | |||
790 | .controls = { | 805 | .controls = { |
791 | { | 806 | { |
792 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 807 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
793 | .name = "Analog Input Monitor Switch", | 808 | .name = "Analog Input Monitor Playback Switch", |
794 | .info = snd_ctl_boolean_mono_info, | 809 | .info = snd_ctl_boolean_mono_info, |
795 | .get = monitor_get, | 810 | .get = monitor_get, |
796 | .put = monitor_put, | 811 | .put = monitor_put, |
@@ -798,7 +813,7 @@ static const struct { | |||
798 | }, | 813 | }, |
799 | { | 814 | { |
800 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 815 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
801 | .name = "Analog Input Monitor Volume", | 816 | .name = "Analog Input Monitor Playback Volume", |
802 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | | 817 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | |
803 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, | 818 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, |
804 | .info = monitor_volume_info, | 819 | .info = monitor_volume_info, |
@@ -815,7 +830,7 @@ static const struct { | |||
815 | .controls = { | 830 | .controls = { |
816 | { | 831 | { |
817 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 832 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
818 | .name = "Analog Input Monitor Switch", | 833 | .name = "Analog Input Monitor Playback Switch", |
819 | .info = snd_ctl_boolean_mono_info, | 834 | .info = snd_ctl_boolean_mono_info, |
820 | .get = monitor_get, | 835 | .get = monitor_get, |
821 | .put = monitor_put, | 836 | .put = monitor_put, |
@@ -823,7 +838,7 @@ static const struct { | |||
823 | }, | 838 | }, |
824 | { | 839 | { |
825 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 840 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
826 | .name = "Analog Input Monitor Volume", | 841 | .name = "Analog Input Monitor Playback Volume", |
827 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | | 842 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | |
828 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, | 843 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, |
829 | .info = monitor_volume_info, | 844 | .info = monitor_volume_info, |
@@ -840,7 +855,7 @@ static const struct { | |||
840 | .controls = { | 855 | .controls = { |
841 | { | 856 | { |
842 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 857 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
843 | .name = "Analog Input Monitor Switch", | 858 | .name = "Analog Input Monitor Playback Switch", |
844 | .index = 1, | 859 | .index = 1, |
845 | .info = snd_ctl_boolean_mono_info, | 860 | .info = snd_ctl_boolean_mono_info, |
846 | .get = monitor_get, | 861 | .get = monitor_get, |
@@ -849,7 +864,7 @@ static const struct { | |||
849 | }, | 864 | }, |
850 | { | 865 | { |
851 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 866 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
852 | .name = "Analog Input Monitor Volume", | 867 | .name = "Analog Input Monitor Playback Volume", |
853 | .index = 1, | 868 | .index = 1, |
854 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | | 869 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | |
855 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, | 870 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, |
@@ -867,7 +882,7 @@ static const struct { | |||
867 | .controls = { | 882 | .controls = { |
868 | { | 883 | { |
869 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 884 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
870 | .name = "Digital Input Monitor Switch", | 885 | .name = "Digital Input Monitor Playback Switch", |
871 | .info = snd_ctl_boolean_mono_info, | 886 | .info = snd_ctl_boolean_mono_info, |
872 | .get = monitor_get, | 887 | .get = monitor_get, |
873 | .put = monitor_put, | 888 | .put = monitor_put, |
@@ -875,7 +890,7 @@ static const struct { | |||
875 | }, | 890 | }, |
876 | { | 891 | { |
877 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 892 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
878 | .name = "Digital Input Monitor Volume", | 893 | .name = "Digital Input Monitor Playback Volume", |
879 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | | 894 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | |
880 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, | 895 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, |
881 | .info = monitor_volume_info, | 896 | .info = monitor_volume_info, |
@@ -954,6 +969,9 @@ static int add_controls(struct oxygen *chip, | |||
954 | if (err == 1) | 969 | if (err == 1) |
955 | continue; | 970 | continue; |
956 | } | 971 | } |
972 | if (!strcmp(template.name, "Stereo Upmixing") && | ||
973 | chip->model.dac_channels == 2) | ||
974 | continue; | ||
957 | if (!strcmp(template.name, "Master Playback Volume") && | 975 | if (!strcmp(template.name, "Master Playback Volume") && |
958 | chip->model.dac_tlv) { | 976 | chip->model.dac_tlv) { |
959 | template.tlv.p = chip->model.dac_tlv; | 977 | template.tlv.p = chip->model.dac_tlv; |
diff --git a/sound/pci/oxygen/oxygen_pcm.c b/sound/pci/oxygen/oxygen_pcm.c index ef2345d82b86..9dff6954c397 100644 --- a/sound/pci/oxygen/oxygen_pcm.c +++ b/sound/pci/oxygen/oxygen_pcm.c | |||
@@ -271,13 +271,16 @@ static unsigned int oxygen_rate(struct snd_pcm_hw_params *hw_params) | |||
271 | } | 271 | } |
272 | } | 272 | } |
273 | 273 | ||
274 | static unsigned int oxygen_i2s_mclk(struct snd_pcm_hw_params *hw_params) | 274 | unsigned int oxygen_default_i2s_mclk(struct oxygen *chip, |
275 | unsigned int channel, | ||
276 | struct snd_pcm_hw_params *hw_params) | ||
275 | { | 277 | { |
276 | if (params_rate(hw_params) <= 96000) | 278 | if (params_rate(hw_params) <= 96000) |
277 | return OXYGEN_I2S_MCLK_256; | 279 | return OXYGEN_I2S_MCLK_256; |
278 | else | 280 | else |
279 | return OXYGEN_I2S_MCLK_128; | 281 | return OXYGEN_I2S_MCLK_128; |
280 | } | 282 | } |
283 | EXPORT_SYMBOL(oxygen_default_i2s_mclk); | ||
281 | 284 | ||
282 | static unsigned int oxygen_i2s_bits(struct snd_pcm_hw_params *hw_params) | 285 | static unsigned int oxygen_i2s_bits(struct snd_pcm_hw_params *hw_params) |
283 | { | 286 | { |
@@ -354,7 +357,7 @@ static int oxygen_rec_a_hw_params(struct snd_pcm_substream *substream, | |||
354 | OXYGEN_REC_FORMAT_A_MASK); | 357 | OXYGEN_REC_FORMAT_A_MASK); |
355 | oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, | 358 | oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, |
356 | oxygen_rate(hw_params) | | 359 | oxygen_rate(hw_params) | |
357 | oxygen_i2s_mclk(hw_params) | | 360 | chip->model.get_i2s_mclk(chip, PCM_A, hw_params) | |
358 | chip->model.adc_i2s_format | | 361 | chip->model.adc_i2s_format | |
359 | oxygen_i2s_bits(hw_params), | 362 | oxygen_i2s_bits(hw_params), |
360 | OXYGEN_I2S_RATE_MASK | | 363 | OXYGEN_I2S_RATE_MASK | |
@@ -390,7 +393,8 @@ static int oxygen_rec_b_hw_params(struct snd_pcm_substream *substream, | |||
390 | if (!is_ac97) | 393 | if (!is_ac97) |
391 | oxygen_write16_masked(chip, OXYGEN_I2S_B_FORMAT, | 394 | oxygen_write16_masked(chip, OXYGEN_I2S_B_FORMAT, |
392 | oxygen_rate(hw_params) | | 395 | oxygen_rate(hw_params) | |
393 | oxygen_i2s_mclk(hw_params) | | 396 | chip->model.get_i2s_mclk(chip, PCM_B, |
397 | hw_params) | | ||
394 | chip->model.adc_i2s_format | | 398 | chip->model.adc_i2s_format | |
395 | oxygen_i2s_bits(hw_params), | 399 | oxygen_i2s_bits(hw_params), |
396 | OXYGEN_I2S_RATE_MASK | | 400 | OXYGEN_I2S_RATE_MASK | |
@@ -435,6 +439,7 @@ static int oxygen_spdif_hw_params(struct snd_pcm_substream *substream, | |||
435 | if (err < 0) | 439 | if (err < 0) |
436 | return err; | 440 | return err; |
437 | 441 | ||
442 | mutex_lock(&chip->mutex); | ||
438 | spin_lock_irq(&chip->reg_lock); | 443 | spin_lock_irq(&chip->reg_lock); |
439 | oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL, | 444 | oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL, |
440 | OXYGEN_SPDIF_OUT_ENABLE); | 445 | OXYGEN_SPDIF_OUT_ENABLE); |
@@ -446,6 +451,7 @@ static int oxygen_spdif_hw_params(struct snd_pcm_substream *substream, | |||
446 | OXYGEN_SPDIF_OUT_RATE_MASK); | 451 | OXYGEN_SPDIF_OUT_RATE_MASK); |
447 | oxygen_update_spdif_source(chip); | 452 | oxygen_update_spdif_source(chip); |
448 | spin_unlock_irq(&chip->reg_lock); | 453 | spin_unlock_irq(&chip->reg_lock); |
454 | mutex_unlock(&chip->mutex); | ||
449 | return 0; | 455 | return 0; |
450 | } | 456 | } |
451 | 457 | ||
@@ -459,6 +465,7 @@ static int oxygen_multich_hw_params(struct snd_pcm_substream *substream, | |||
459 | if (err < 0) | 465 | if (err < 0) |
460 | return err; | 466 | return err; |
461 | 467 | ||
468 | mutex_lock(&chip->mutex); | ||
462 | spin_lock_irq(&chip->reg_lock); | 469 | spin_lock_irq(&chip->reg_lock); |
463 | oxygen_write8_masked(chip, OXYGEN_PLAY_CHANNELS, | 470 | oxygen_write8_masked(chip, OXYGEN_PLAY_CHANNELS, |
464 | oxygen_play_channels(hw_params), | 471 | oxygen_play_channels(hw_params), |
@@ -469,18 +476,18 @@ static int oxygen_multich_hw_params(struct snd_pcm_substream *substream, | |||
469 | oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT, | 476 | oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT, |
470 | oxygen_rate(hw_params) | | 477 | oxygen_rate(hw_params) | |
471 | chip->model.dac_i2s_format | | 478 | chip->model.dac_i2s_format | |
472 | oxygen_i2s_mclk(hw_params) | | 479 | chip->model.get_i2s_mclk(chip, PCM_MULTICH, |
480 | hw_params) | | ||
473 | oxygen_i2s_bits(hw_params), | 481 | oxygen_i2s_bits(hw_params), |
474 | OXYGEN_I2S_RATE_MASK | | 482 | OXYGEN_I2S_RATE_MASK | |
475 | OXYGEN_I2S_FORMAT_MASK | | 483 | OXYGEN_I2S_FORMAT_MASK | |
476 | OXYGEN_I2S_MCLK_MASK | | 484 | OXYGEN_I2S_MCLK_MASK | |
477 | OXYGEN_I2S_BITS_MASK); | 485 | OXYGEN_I2S_BITS_MASK); |
478 | oxygen_update_dac_routing(chip); | ||
479 | oxygen_update_spdif_source(chip); | 486 | oxygen_update_spdif_source(chip); |
480 | spin_unlock_irq(&chip->reg_lock); | 487 | spin_unlock_irq(&chip->reg_lock); |
481 | 488 | ||
482 | mutex_lock(&chip->mutex); | ||
483 | chip->model.set_dac_params(chip, hw_params); | 489 | chip->model.set_dac_params(chip, hw_params); |
490 | oxygen_update_dac_routing(chip); | ||
484 | mutex_unlock(&chip->mutex); | 491 | mutex_unlock(&chip->mutex); |
485 | return 0; | 492 | return 0; |
486 | } | 493 | } |
diff --git a/sound/pci/oxygen/virtuoso.c b/sound/pci/oxygen/virtuoso.c index 6ebcb6bdd712..6accaf9580b2 100644 --- a/sound/pci/oxygen/virtuoso.c +++ b/sound/pci/oxygen/virtuoso.c | |||
@@ -17,145 +17,12 @@ | |||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | */ | 18 | */ |
19 | 19 | ||
20 | /* | ||
21 | * Xonar D2/D2X | ||
22 | * ------------ | ||
23 | * | ||
24 | * CMI8788: | ||
25 | * | ||
26 | * SPI 0 -> 1st PCM1796 (front) | ||
27 | * SPI 1 -> 2nd PCM1796 (surround) | ||
28 | * SPI 2 -> 3rd PCM1796 (center/LFE) | ||
29 | * SPI 4 -> 4th PCM1796 (back) | ||
30 | * | ||
31 | * GPIO 2 -> M0 of CS5381 | ||
32 | * GPIO 3 -> M1 of CS5381 | ||
33 | * GPIO 5 <- external power present (D2X only) | ||
34 | * GPIO 7 -> ALT | ||
35 | * GPIO 8 -> enable output to speakers | ||
36 | */ | ||
37 | |||
38 | /* | ||
39 | * Xonar D1/DX | ||
40 | * ----------- | ||
41 | * | ||
42 | * CMI8788: | ||
43 | * | ||
44 | * I²C <-> CS4398 (front) | ||
45 | * <-> CS4362A (surround, center/LFE, back) | ||
46 | * | ||
47 | * GPI 0 <- external power present (DX only) | ||
48 | * | ||
49 | * GPIO 0 -> enable output to speakers | ||
50 | * GPIO 1 -> enable front panel I/O | ||
51 | * GPIO 2 -> M0 of CS5361 | ||
52 | * GPIO 3 -> M1 of CS5361 | ||
53 | * GPIO 8 -> route input jack to line-in (0) or mic-in (1) | ||
54 | * | ||
55 | * CS4398: | ||
56 | * | ||
57 | * AD0 <- 1 | ||
58 | * AD1 <- 1 | ||
59 | * | ||
60 | * CS4362A: | ||
61 | * | ||
62 | * AD0 <- 0 | ||
63 | */ | ||
64 | |||
65 | /* | ||
66 | * Xonar HDAV1.3 (Deluxe) | ||
67 | * ---------------------- | ||
68 | * | ||
69 | * CMI8788: | ||
70 | * | ||
71 | * I²C <-> PCM1796 (front) | ||
72 | * | ||
73 | * GPI 0 <- external power present | ||
74 | * | ||
75 | * GPIO 0 -> enable output to speakers | ||
76 | * GPIO 2 -> M0 of CS5381 | ||
77 | * GPIO 3 -> M1 of CS5381 | ||
78 | * GPIO 8 -> route input jack to line-in (0) or mic-in (1) | ||
79 | * | ||
80 | * TXD -> HDMI controller | ||
81 | * RXD <- HDMI controller | ||
82 | * | ||
83 | * PCM1796 front: AD1,0 <- 0,0 | ||
84 | * | ||
85 | * no daughterboard | ||
86 | * ---------------- | ||
87 | * | ||
88 | * GPIO 4 <- 1 | ||
89 | * | ||
90 | * H6 daughterboard | ||
91 | * ---------------- | ||
92 | * | ||
93 | * GPIO 4 <- 0 | ||
94 | * GPIO 5 <- 0 | ||
95 | * | ||
96 | * I²C <-> PCM1796 (surround) | ||
97 | * <-> PCM1796 (center/LFE) | ||
98 | * <-> PCM1796 (back) | ||
99 | * | ||
100 | * PCM1796 surround: AD1,0 <- 0,1 | ||
101 | * PCM1796 center/LFE: AD1,0 <- 1,0 | ||
102 | * PCM1796 back: AD1,0 <- 1,1 | ||
103 | * | ||
104 | * unknown daughterboard | ||
105 | * --------------------- | ||
106 | * | ||
107 | * GPIO 4 <- 0 | ||
108 | * GPIO 5 <- 1 | ||
109 | * | ||
110 | * I²C <-> CS4362A (surround, center/LFE, back) | ||
111 | * | ||
112 | * CS4362A: AD0 <- 0 | ||
113 | */ | ||
114 | |||
115 | /* | ||
116 | * Xonar Essence ST (Deluxe)/STX | ||
117 | * ----------------------------- | ||
118 | * | ||
119 | * CMI8788: | ||
120 | * | ||
121 | * I²C <-> PCM1792A | ||
122 | * | ||
123 | * GPI 0 <- external power present | ||
124 | * | ||
125 | * GPIO 0 -> enable output to speakers | ||
126 | * GPIO 1 -> route HP to front panel (0) or rear jack (1) | ||
127 | * GPIO 2 -> M0 of CS5381 | ||
128 | * GPIO 3 -> M1 of CS5381 | ||
129 | * GPIO 7 -> route output to speaker jacks (0) or HP (1) | ||
130 | * GPIO 8 -> route input jack to line-in (0) or mic-in (1) | ||
131 | * | ||
132 | * PCM1792A: | ||
133 | * | ||
134 | * AD0 <- 0 | ||
135 | * | ||
136 | * H6 daughterboard | ||
137 | * ---------------- | ||
138 | * | ||
139 | * GPIO 4 <- 0 | ||
140 | * GPIO 5 <- 0 | ||
141 | */ | ||
142 | |||
143 | #include <linux/pci.h> | 20 | #include <linux/pci.h> |
144 | #include <linux/delay.h> | 21 | #include <linux/delay.h> |
145 | #include <linux/mutex.h> | ||
146 | #include <sound/ac97_codec.h> | ||
147 | #include <sound/asoundef.h> | ||
148 | #include <sound/control.h> | ||
149 | #include <sound/core.h> | 22 | #include <sound/core.h> |
150 | #include <sound/initval.h> | 23 | #include <sound/initval.h> |
151 | #include <sound/pcm.h> | 24 | #include <sound/pcm.h> |
152 | #include <sound/pcm_params.h> | 25 | #include "xonar.h" |
153 | #include <sound/tlv.h> | ||
154 | #include "oxygen.h" | ||
155 | #include "cm9780.h" | ||
156 | #include "pcm1796.h" | ||
157 | #include "cs4398.h" | ||
158 | #include "cs4362a.h" | ||
159 | 26 | ||
160 | MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); | 27 | MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); |
161 | MODULE_DESCRIPTION("Asus AVx00 driver"); | 28 | MODULE_DESCRIPTION("Asus AVx00 driver"); |
@@ -173,972 +40,28 @@ MODULE_PARM_DESC(id, "ID string"); | |||
173 | module_param_array(enable, bool, NULL, 0444); | 40 | module_param_array(enable, bool, NULL, 0444); |
174 | MODULE_PARM_DESC(enable, "enable card"); | 41 | MODULE_PARM_DESC(enable, "enable card"); |
175 | 42 | ||
176 | enum { | ||
177 | MODEL_D2, | ||
178 | MODEL_D2X, | ||
179 | MODEL_D1, | ||
180 | MODEL_DX, | ||
181 | MODEL_HDAV, /* without daughterboard */ | ||
182 | MODEL_HDAV_H6, /* with H6 daughterboard */ | ||
183 | MODEL_ST, | ||
184 | MODEL_ST_H6, | ||
185 | MODEL_STX, | ||
186 | }; | ||
187 | |||
188 | static struct pci_device_id xonar_ids[] __devinitdata = { | 43 | static struct pci_device_id xonar_ids[] __devinitdata = { |
189 | { OXYGEN_PCI_SUBID(0x1043, 0x8269), .driver_data = MODEL_D2 }, | 44 | { OXYGEN_PCI_SUBID(0x1043, 0x8269) }, |
190 | { OXYGEN_PCI_SUBID(0x1043, 0x8275), .driver_data = MODEL_DX }, | 45 | { OXYGEN_PCI_SUBID(0x1043, 0x8275) }, |
191 | { OXYGEN_PCI_SUBID(0x1043, 0x82b7), .driver_data = MODEL_D2X }, | 46 | { OXYGEN_PCI_SUBID(0x1043, 0x82b7) }, |
192 | { OXYGEN_PCI_SUBID(0x1043, 0x8314), .driver_data = MODEL_HDAV }, | 47 | { OXYGEN_PCI_SUBID(0x1043, 0x8314) }, |
193 | { OXYGEN_PCI_SUBID(0x1043, 0x8327), .driver_data = MODEL_DX }, | 48 | { OXYGEN_PCI_SUBID(0x1043, 0x8327) }, |
194 | { OXYGEN_PCI_SUBID(0x1043, 0x834f), .driver_data = MODEL_D1 }, | 49 | { OXYGEN_PCI_SUBID(0x1043, 0x834f) }, |
195 | { OXYGEN_PCI_SUBID(0x1043, 0x835c), .driver_data = MODEL_STX }, | 50 | { OXYGEN_PCI_SUBID(0x1043, 0x835c) }, |
196 | { OXYGEN_PCI_SUBID(0x1043, 0x835d), .driver_data = MODEL_ST }, | 51 | { OXYGEN_PCI_SUBID(0x1043, 0x835d) }, |
197 | { OXYGEN_PCI_SUBID_BROKEN_EEPROM }, | 52 | { OXYGEN_PCI_SUBID_BROKEN_EEPROM }, |
198 | { } | 53 | { } |
199 | }; | 54 | }; |
200 | MODULE_DEVICE_TABLE(pci, xonar_ids); | 55 | MODULE_DEVICE_TABLE(pci, xonar_ids); |
201 | 56 | ||
202 | |||
203 | #define GPIO_CS53x1_M_MASK 0x000c | ||
204 | #define GPIO_CS53x1_M_SINGLE 0x0000 | ||
205 | #define GPIO_CS53x1_M_DOUBLE 0x0004 | ||
206 | #define GPIO_CS53x1_M_QUAD 0x0008 | ||
207 | |||
208 | #define GPIO_D2X_EXT_POWER 0x0020 | ||
209 | #define GPIO_D2_ALT 0x0080 | ||
210 | #define GPIO_D2_OUTPUT_ENABLE 0x0100 | ||
211 | |||
212 | #define GPI_DX_EXT_POWER 0x01 | ||
213 | #define GPIO_DX_OUTPUT_ENABLE 0x0001 | ||
214 | #define GPIO_DX_FRONT_PANEL 0x0002 | ||
215 | #define GPIO_DX_INPUT_ROUTE 0x0100 | ||
216 | |||
217 | #define GPIO_DB_MASK 0x0030 | ||
218 | #define GPIO_DB_H6 0x0000 | ||
219 | #define GPIO_DB_XX 0x0020 | ||
220 | |||
221 | #define GPIO_ST_HP_REAR 0x0002 | ||
222 | #define GPIO_ST_HP 0x0080 | ||
223 | |||
224 | #define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ADx=i, /W=0 */ | ||
225 | #define I2C_DEVICE_CS4398 0x9e /* 10011, AD1=1, AD0=1, /W=0 */ | ||
226 | #define I2C_DEVICE_CS4362A 0x30 /* 001100, AD0=0, /W=0 */ | ||
227 | |||
228 | struct xonar_data { | ||
229 | unsigned int anti_pop_delay; | ||
230 | unsigned int dacs; | ||
231 | u16 output_enable_bit; | ||
232 | u8 ext_power_reg; | ||
233 | u8 ext_power_int_reg; | ||
234 | u8 ext_power_bit; | ||
235 | u8 has_power; | ||
236 | u8 pcm1796_oversampling; | ||
237 | u8 cs4398_fm; | ||
238 | u8 cs4362a_fm; | ||
239 | u8 hdmi_params[5]; | ||
240 | }; | ||
241 | |||
242 | static void xonar_gpio_changed(struct oxygen *chip); | ||
243 | |||
244 | static inline void pcm1796_write_spi(struct oxygen *chip, unsigned int codec, | ||
245 | u8 reg, u8 value) | ||
246 | { | ||
247 | /* maps ALSA channel pair number to SPI output */ | ||
248 | static const u8 codec_map[4] = { | ||
249 | 0, 1, 2, 4 | ||
250 | }; | ||
251 | oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER | | ||
252 | OXYGEN_SPI_DATA_LENGTH_2 | | ||
253 | OXYGEN_SPI_CLOCK_160 | | ||
254 | (codec_map[codec] << OXYGEN_SPI_CODEC_SHIFT) | | ||
255 | OXYGEN_SPI_CEN_LATCH_CLOCK_HI, | ||
256 | (reg << 8) | value); | ||
257 | } | ||
258 | |||
259 | static inline void pcm1796_write_i2c(struct oxygen *chip, unsigned int codec, | ||
260 | u8 reg, u8 value) | ||
261 | { | ||
262 | oxygen_write_i2c(chip, I2C_DEVICE_PCM1796(codec), reg, value); | ||
263 | } | ||
264 | |||
265 | static void pcm1796_write(struct oxygen *chip, unsigned int codec, | ||
266 | u8 reg, u8 value) | ||
267 | { | ||
268 | if ((chip->model.function_flags & OXYGEN_FUNCTION_2WIRE_SPI_MASK) == | ||
269 | OXYGEN_FUNCTION_SPI) | ||
270 | pcm1796_write_spi(chip, codec, reg, value); | ||
271 | else | ||
272 | pcm1796_write_i2c(chip, codec, reg, value); | ||
273 | } | ||
274 | |||
275 | static void cs4398_write(struct oxygen *chip, u8 reg, u8 value) | ||
276 | { | ||
277 | oxygen_write_i2c(chip, I2C_DEVICE_CS4398, reg, value); | ||
278 | } | ||
279 | |||
280 | static void cs4362a_write(struct oxygen *chip, u8 reg, u8 value) | ||
281 | { | ||
282 | oxygen_write_i2c(chip, I2C_DEVICE_CS4362A, reg, value); | ||
283 | } | ||
284 | |||
285 | static void hdmi_write_command(struct oxygen *chip, u8 command, | ||
286 | unsigned int count, const u8 *params) | ||
287 | { | ||
288 | unsigned int i; | ||
289 | u8 checksum; | ||
290 | |||
291 | oxygen_write_uart(chip, 0xfb); | ||
292 | oxygen_write_uart(chip, 0xef); | ||
293 | oxygen_write_uart(chip, command); | ||
294 | oxygen_write_uart(chip, count); | ||
295 | for (i = 0; i < count; ++i) | ||
296 | oxygen_write_uart(chip, params[i]); | ||
297 | checksum = 0xfb + 0xef + command + count; | ||
298 | for (i = 0; i < count; ++i) | ||
299 | checksum += params[i]; | ||
300 | oxygen_write_uart(chip, checksum); | ||
301 | } | ||
302 | |||
303 | static void xonar_enable_output(struct oxygen *chip) | ||
304 | { | ||
305 | struct xonar_data *data = chip->model_data; | ||
306 | |||
307 | msleep(data->anti_pop_delay); | ||
308 | oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit); | ||
309 | } | ||
310 | |||
311 | static void xonar_common_init(struct oxygen *chip) | ||
312 | { | ||
313 | struct xonar_data *data = chip->model_data; | ||
314 | |||
315 | if (data->ext_power_reg) { | ||
316 | oxygen_set_bits8(chip, data->ext_power_int_reg, | ||
317 | data->ext_power_bit); | ||
318 | chip->interrupt_mask |= OXYGEN_INT_GPIO; | ||
319 | chip->model.gpio_changed = xonar_gpio_changed; | ||
320 | data->has_power = !!(oxygen_read8(chip, data->ext_power_reg) | ||
321 | & data->ext_power_bit); | ||
322 | } | ||
323 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, | ||
324 | GPIO_CS53x1_M_MASK | data->output_enable_bit); | ||
325 | oxygen_write16_masked(chip, OXYGEN_GPIO_DATA, | ||
326 | GPIO_CS53x1_M_SINGLE, GPIO_CS53x1_M_MASK); | ||
327 | oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC); | ||
328 | xonar_enable_output(chip); | ||
329 | } | ||
330 | |||
331 | static void update_pcm1796_volume(struct oxygen *chip) | ||
332 | { | ||
333 | struct xonar_data *data = chip->model_data; | ||
334 | unsigned int i; | ||
335 | |||
336 | for (i = 0; i < data->dacs; ++i) { | ||
337 | pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]); | ||
338 | pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]); | ||
339 | } | ||
340 | } | ||
341 | |||
342 | static void update_pcm1796_mute(struct oxygen *chip) | ||
343 | { | ||
344 | struct xonar_data *data = chip->model_data; | ||
345 | unsigned int i; | ||
346 | u8 value; | ||
347 | |||
348 | value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD; | ||
349 | if (chip->dac_mute) | ||
350 | value |= PCM1796_MUTE; | ||
351 | for (i = 0; i < data->dacs; ++i) | ||
352 | pcm1796_write(chip, i, 18, value); | ||
353 | } | ||
354 | |||
355 | static void pcm1796_init(struct oxygen *chip) | ||
356 | { | ||
357 | struct xonar_data *data = chip->model_data; | ||
358 | unsigned int i; | ||
359 | |||
360 | for (i = 0; i < data->dacs; ++i) { | ||
361 | pcm1796_write(chip, i, 19, PCM1796_FLT_SHARP | PCM1796_ATS_1); | ||
362 | pcm1796_write(chip, i, 20, data->pcm1796_oversampling); | ||
363 | pcm1796_write(chip, i, 21, 0); | ||
364 | } | ||
365 | update_pcm1796_mute(chip); /* set ATLD before ATL/ATR */ | ||
366 | update_pcm1796_volume(chip); | ||
367 | } | ||
368 | |||
369 | static void xonar_d2_init(struct oxygen *chip) | ||
370 | { | ||
371 | struct xonar_data *data = chip->model_data; | ||
372 | |||
373 | data->anti_pop_delay = 300; | ||
374 | data->dacs = 4; | ||
375 | data->output_enable_bit = GPIO_D2_OUTPUT_ENABLE; | ||
376 | data->pcm1796_oversampling = PCM1796_OS_64; | ||
377 | |||
378 | pcm1796_init(chip); | ||
379 | |||
380 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT); | ||
381 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT); | ||
382 | |||
383 | xonar_common_init(chip); | ||
384 | |||
385 | snd_component_add(chip->card, "PCM1796"); | ||
386 | snd_component_add(chip->card, "CS5381"); | ||
387 | } | ||
388 | |||
389 | static void xonar_d2x_init(struct oxygen *chip) | ||
390 | { | ||
391 | struct xonar_data *data = chip->model_data; | ||
392 | |||
393 | data->ext_power_reg = OXYGEN_GPIO_DATA; | ||
394 | data->ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK; | ||
395 | data->ext_power_bit = GPIO_D2X_EXT_POWER; | ||
396 | oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER); | ||
397 | |||
398 | xonar_d2_init(chip); | ||
399 | } | ||
400 | |||
401 | static void update_cs4362a_volumes(struct oxygen *chip) | ||
402 | { | ||
403 | u8 mute; | ||
404 | |||
405 | mute = chip->dac_mute ? CS4362A_MUTE : 0; | ||
406 | cs4362a_write(chip, 7, (127 - chip->dac_volume[2]) | mute); | ||
407 | cs4362a_write(chip, 8, (127 - chip->dac_volume[3]) | mute); | ||
408 | cs4362a_write(chip, 10, (127 - chip->dac_volume[4]) | mute); | ||
409 | cs4362a_write(chip, 11, (127 - chip->dac_volume[5]) | mute); | ||
410 | cs4362a_write(chip, 13, (127 - chip->dac_volume[6]) | mute); | ||
411 | cs4362a_write(chip, 14, (127 - chip->dac_volume[7]) | mute); | ||
412 | } | ||
413 | |||
414 | static void update_cs43xx_volume(struct oxygen *chip) | ||
415 | { | ||
416 | cs4398_write(chip, 5, (127 - chip->dac_volume[0]) * 2); | ||
417 | cs4398_write(chip, 6, (127 - chip->dac_volume[1]) * 2); | ||
418 | update_cs4362a_volumes(chip); | ||
419 | } | ||
420 | |||
421 | static void update_cs43xx_mute(struct oxygen *chip) | ||
422 | { | ||
423 | u8 reg; | ||
424 | |||
425 | reg = CS4398_MUTEP_LOW | CS4398_PAMUTE; | ||
426 | if (chip->dac_mute) | ||
427 | reg |= CS4398_MUTE_B | CS4398_MUTE_A; | ||
428 | cs4398_write(chip, 4, reg); | ||
429 | update_cs4362a_volumes(chip); | ||
430 | } | ||
431 | |||
432 | static void cs43xx_init(struct oxygen *chip) | ||
433 | { | ||
434 | struct xonar_data *data = chip->model_data; | ||
435 | |||
436 | /* set CPEN (control port mode) and power down */ | ||
437 | cs4398_write(chip, 8, CS4398_CPEN | CS4398_PDN); | ||
438 | cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN); | ||
439 | /* configure */ | ||
440 | cs4398_write(chip, 2, data->cs4398_fm); | ||
441 | cs4398_write(chip, 3, CS4398_ATAPI_B_R | CS4398_ATAPI_A_L); | ||
442 | cs4398_write(chip, 7, CS4398_RMP_DN | CS4398_RMP_UP | | ||
443 | CS4398_ZERO_CROSS | CS4398_SOFT_RAMP); | ||
444 | cs4362a_write(chip, 0x02, CS4362A_DIF_LJUST); | ||
445 | cs4362a_write(chip, 0x03, CS4362A_MUTEC_6 | CS4362A_AMUTE | | ||
446 | CS4362A_RMP_UP | CS4362A_ZERO_CROSS | CS4362A_SOFT_RAMP); | ||
447 | cs4362a_write(chip, 0x04, CS4362A_RMP_DN | CS4362A_DEM_NONE); | ||
448 | cs4362a_write(chip, 0x05, 0); | ||
449 | cs4362a_write(chip, 0x06, data->cs4362a_fm); | ||
450 | cs4362a_write(chip, 0x09, data->cs4362a_fm); | ||
451 | cs4362a_write(chip, 0x0c, data->cs4362a_fm); | ||
452 | update_cs43xx_volume(chip); | ||
453 | update_cs43xx_mute(chip); | ||
454 | /* clear power down */ | ||
455 | cs4398_write(chip, 8, CS4398_CPEN); | ||
456 | cs4362a_write(chip, 0x01, CS4362A_CPEN); | ||
457 | } | ||
458 | |||
459 | static void xonar_d1_init(struct oxygen *chip) | ||
460 | { | ||
461 | struct xonar_data *data = chip->model_data; | ||
462 | |||
463 | data->anti_pop_delay = 800; | ||
464 | data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE; | ||
465 | data->cs4398_fm = CS4398_FM_SINGLE | CS4398_DEM_NONE | CS4398_DIF_LJUST; | ||
466 | data->cs4362a_fm = CS4362A_FM_SINGLE | | ||
467 | CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L; | ||
468 | |||
469 | oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS, | ||
470 | OXYGEN_2WIRE_LENGTH_8 | | ||
471 | OXYGEN_2WIRE_INTERRUPT_MASK | | ||
472 | OXYGEN_2WIRE_SPEED_FAST); | ||
473 | |||
474 | cs43xx_init(chip); | ||
475 | |||
476 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, | ||
477 | GPIO_DX_FRONT_PANEL | GPIO_DX_INPUT_ROUTE); | ||
478 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, | ||
479 | GPIO_DX_FRONT_PANEL | GPIO_DX_INPUT_ROUTE); | ||
480 | |||
481 | xonar_common_init(chip); | ||
482 | |||
483 | snd_component_add(chip->card, "CS4398"); | ||
484 | snd_component_add(chip->card, "CS4362A"); | ||
485 | snd_component_add(chip->card, "CS5361"); | ||
486 | } | ||
487 | |||
488 | static void xonar_dx_init(struct oxygen *chip) | ||
489 | { | ||
490 | struct xonar_data *data = chip->model_data; | ||
491 | |||
492 | data->ext_power_reg = OXYGEN_GPI_DATA; | ||
493 | data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK; | ||
494 | data->ext_power_bit = GPI_DX_EXT_POWER; | ||
495 | |||
496 | xonar_d1_init(chip); | ||
497 | } | ||
498 | |||
499 | static void xonar_hdav_init(struct oxygen *chip) | ||
500 | { | ||
501 | struct xonar_data *data = chip->model_data; | ||
502 | u8 param; | ||
503 | |||
504 | oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS, | ||
505 | OXYGEN_2WIRE_LENGTH_8 | | ||
506 | OXYGEN_2WIRE_INTERRUPT_MASK | | ||
507 | OXYGEN_2WIRE_SPEED_FAST); | ||
508 | |||
509 | data->anti_pop_delay = 100; | ||
510 | data->dacs = chip->model.private_data == MODEL_HDAV_H6 ? 4 : 1; | ||
511 | data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE; | ||
512 | data->ext_power_reg = OXYGEN_GPI_DATA; | ||
513 | data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK; | ||
514 | data->ext_power_bit = GPI_DX_EXT_POWER; | ||
515 | data->pcm1796_oversampling = PCM1796_OS_64; | ||
516 | |||
517 | pcm1796_init(chip); | ||
518 | |||
519 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DX_INPUT_ROUTE); | ||
520 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_DX_INPUT_ROUTE); | ||
521 | |||
522 | oxygen_reset_uart(chip); | ||
523 | param = 0; | ||
524 | hdmi_write_command(chip, 0x61, 1, ¶m); | ||
525 | param = 1; | ||
526 | hdmi_write_command(chip, 0x74, 1, ¶m); | ||
527 | data->hdmi_params[1] = IEC958_AES3_CON_FS_48000; | ||
528 | data->hdmi_params[4] = 1; | ||
529 | hdmi_write_command(chip, 0x54, 5, data->hdmi_params); | ||
530 | |||
531 | xonar_common_init(chip); | ||
532 | |||
533 | snd_component_add(chip->card, "PCM1796"); | ||
534 | snd_component_add(chip->card, "CS5381"); | ||
535 | } | ||
536 | |||
537 | static void xonar_st_init(struct oxygen *chip) | ||
538 | { | ||
539 | struct xonar_data *data = chip->model_data; | ||
540 | |||
541 | oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS, | ||
542 | OXYGEN_2WIRE_LENGTH_8 | | ||
543 | OXYGEN_2WIRE_INTERRUPT_MASK | | ||
544 | OXYGEN_2WIRE_SPEED_FAST); | ||
545 | |||
546 | if (chip->model.private_data == MODEL_ST_H6) | ||
547 | chip->model.dac_channels = 8; | ||
548 | data->anti_pop_delay = 100; | ||
549 | data->dacs = chip->model.private_data == MODEL_ST_H6 ? 4 : 1; | ||
550 | data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE; | ||
551 | data->pcm1796_oversampling = PCM1796_OS_64; | ||
552 | |||
553 | pcm1796_init(chip); | ||
554 | |||
555 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, | ||
556 | GPIO_DX_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP); | ||
557 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, | ||
558 | GPIO_DX_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP); | ||
559 | |||
560 | xonar_common_init(chip); | ||
561 | |||
562 | snd_component_add(chip->card, "PCM1792A"); | ||
563 | snd_component_add(chip->card, "CS5381"); | ||
564 | } | ||
565 | |||
566 | static void xonar_stx_init(struct oxygen *chip) | ||
567 | { | ||
568 | struct xonar_data *data = chip->model_data; | ||
569 | |||
570 | data->ext_power_reg = OXYGEN_GPI_DATA; | ||
571 | data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK; | ||
572 | data->ext_power_bit = GPI_DX_EXT_POWER; | ||
573 | |||
574 | xonar_st_init(chip); | ||
575 | } | ||
576 | |||
577 | static void xonar_disable_output(struct oxygen *chip) | ||
578 | { | ||
579 | struct xonar_data *data = chip->model_data; | ||
580 | |||
581 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit); | ||
582 | } | ||
583 | |||
584 | static void xonar_d2_cleanup(struct oxygen *chip) | ||
585 | { | ||
586 | xonar_disable_output(chip); | ||
587 | } | ||
588 | |||
589 | static void xonar_d1_cleanup(struct oxygen *chip) | ||
590 | { | ||
591 | xonar_disable_output(chip); | ||
592 | cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN); | ||
593 | oxygen_clear_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC); | ||
594 | } | ||
595 | |||
596 | static void xonar_hdav_cleanup(struct oxygen *chip) | ||
597 | { | ||
598 | u8 param = 0; | ||
599 | |||
600 | hdmi_write_command(chip, 0x74, 1, ¶m); | ||
601 | xonar_disable_output(chip); | ||
602 | } | ||
603 | |||
604 | static void xonar_st_cleanup(struct oxygen *chip) | ||
605 | { | ||
606 | xonar_disable_output(chip); | ||
607 | } | ||
608 | |||
609 | static void xonar_d2_suspend(struct oxygen *chip) | ||
610 | { | ||
611 | xonar_d2_cleanup(chip); | ||
612 | } | ||
613 | |||
614 | static void xonar_d1_suspend(struct oxygen *chip) | ||
615 | { | ||
616 | xonar_d1_cleanup(chip); | ||
617 | } | ||
618 | |||
619 | static void xonar_hdav_suspend(struct oxygen *chip) | ||
620 | { | ||
621 | xonar_hdav_cleanup(chip); | ||
622 | msleep(2); | ||
623 | } | ||
624 | |||
625 | static void xonar_st_suspend(struct oxygen *chip) | ||
626 | { | ||
627 | xonar_st_cleanup(chip); | ||
628 | } | ||
629 | |||
630 | static void xonar_d2_resume(struct oxygen *chip) | ||
631 | { | ||
632 | pcm1796_init(chip); | ||
633 | xonar_enable_output(chip); | ||
634 | } | ||
635 | |||
636 | static void xonar_d1_resume(struct oxygen *chip) | ||
637 | { | ||
638 | oxygen_set_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC); | ||
639 | msleep(1); | ||
640 | cs43xx_init(chip); | ||
641 | xonar_enable_output(chip); | ||
642 | } | ||
643 | |||
644 | static void xonar_hdav_resume(struct oxygen *chip) | ||
645 | { | ||
646 | struct xonar_data *data = chip->model_data; | ||
647 | u8 param; | ||
648 | |||
649 | oxygen_reset_uart(chip); | ||
650 | param = 0; | ||
651 | hdmi_write_command(chip, 0x61, 1, ¶m); | ||
652 | param = 1; | ||
653 | hdmi_write_command(chip, 0x74, 1, ¶m); | ||
654 | hdmi_write_command(chip, 0x54, 5, data->hdmi_params); | ||
655 | pcm1796_init(chip); | ||
656 | xonar_enable_output(chip); | ||
657 | } | ||
658 | |||
659 | static void xonar_st_resume(struct oxygen *chip) | ||
660 | { | ||
661 | pcm1796_init(chip); | ||
662 | xonar_enable_output(chip); | ||
663 | } | ||
664 | |||
665 | static void xonar_hdav_pcm_hardware_filter(unsigned int channel, | ||
666 | struct snd_pcm_hardware *hardware) | ||
667 | { | ||
668 | if (channel == PCM_MULTICH) { | ||
669 | hardware->rates = SNDRV_PCM_RATE_44100 | | ||
670 | SNDRV_PCM_RATE_48000 | | ||
671 | SNDRV_PCM_RATE_96000 | | ||
672 | SNDRV_PCM_RATE_192000; | ||
673 | hardware->rate_min = 44100; | ||
674 | } | ||
675 | } | ||
676 | |||
677 | static void set_pcm1796_params(struct oxygen *chip, | ||
678 | struct snd_pcm_hw_params *params) | ||
679 | { | ||
680 | struct xonar_data *data = chip->model_data; | ||
681 | unsigned int i; | ||
682 | |||
683 | data->pcm1796_oversampling = | ||
684 | params_rate(params) >= 96000 ? PCM1796_OS_32 : PCM1796_OS_64; | ||
685 | for (i = 0; i < data->dacs; ++i) | ||
686 | pcm1796_write(chip, i, 20, data->pcm1796_oversampling); | ||
687 | } | ||
688 | |||
689 | static void set_cs53x1_params(struct oxygen *chip, | ||
690 | struct snd_pcm_hw_params *params) | ||
691 | { | ||
692 | unsigned int value; | ||
693 | |||
694 | if (params_rate(params) <= 54000) | ||
695 | value = GPIO_CS53x1_M_SINGLE; | ||
696 | else if (params_rate(params) <= 108000) | ||
697 | value = GPIO_CS53x1_M_DOUBLE; | ||
698 | else | ||
699 | value = GPIO_CS53x1_M_QUAD; | ||
700 | oxygen_write16_masked(chip, OXYGEN_GPIO_DATA, | ||
701 | value, GPIO_CS53x1_M_MASK); | ||
702 | } | ||
703 | |||
704 | static void set_cs43xx_params(struct oxygen *chip, | ||
705 | struct snd_pcm_hw_params *params) | ||
706 | { | ||
707 | struct xonar_data *data = chip->model_data; | ||
708 | |||
709 | data->cs4398_fm = CS4398_DEM_NONE | CS4398_DIF_LJUST; | ||
710 | data->cs4362a_fm = CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L; | ||
711 | if (params_rate(params) <= 50000) { | ||
712 | data->cs4398_fm |= CS4398_FM_SINGLE; | ||
713 | data->cs4362a_fm |= CS4362A_FM_SINGLE; | ||
714 | } else if (params_rate(params) <= 100000) { | ||
715 | data->cs4398_fm |= CS4398_FM_DOUBLE; | ||
716 | data->cs4362a_fm |= CS4362A_FM_DOUBLE; | ||
717 | } else { | ||
718 | data->cs4398_fm |= CS4398_FM_QUAD; | ||
719 | data->cs4362a_fm |= CS4362A_FM_QUAD; | ||
720 | } | ||
721 | cs4398_write(chip, 2, data->cs4398_fm); | ||
722 | cs4362a_write(chip, 0x06, data->cs4362a_fm); | ||
723 | cs4362a_write(chip, 0x09, data->cs4362a_fm); | ||
724 | cs4362a_write(chip, 0x0c, data->cs4362a_fm); | ||
725 | } | ||
726 | |||
727 | static void set_hdmi_params(struct oxygen *chip, | ||
728 | struct snd_pcm_hw_params *params) | ||
729 | { | ||
730 | struct xonar_data *data = chip->model_data; | ||
731 | |||
732 | data->hdmi_params[0] = 0; /* 1 = non-audio */ | ||
733 | switch (params_rate(params)) { | ||
734 | case 44100: | ||
735 | data->hdmi_params[1] = IEC958_AES3_CON_FS_44100; | ||
736 | break; | ||
737 | case 48000: | ||
738 | data->hdmi_params[1] = IEC958_AES3_CON_FS_48000; | ||
739 | break; | ||
740 | default: /* 96000 */ | ||
741 | data->hdmi_params[1] = IEC958_AES3_CON_FS_96000; | ||
742 | break; | ||
743 | case 192000: | ||
744 | data->hdmi_params[1] = IEC958_AES3_CON_FS_192000; | ||
745 | break; | ||
746 | } | ||
747 | data->hdmi_params[2] = params_channels(params) / 2 - 1; | ||
748 | if (params_format(params) == SNDRV_PCM_FORMAT_S16_LE) | ||
749 | data->hdmi_params[3] = 0; | ||
750 | else | ||
751 | data->hdmi_params[3] = 0xc0; | ||
752 | data->hdmi_params[4] = 1; /* ? */ | ||
753 | hdmi_write_command(chip, 0x54, 5, data->hdmi_params); | ||
754 | } | ||
755 | |||
756 | static void set_hdav_params(struct oxygen *chip, | ||
757 | struct snd_pcm_hw_params *params) | ||
758 | { | ||
759 | set_pcm1796_params(chip, params); | ||
760 | set_hdmi_params(chip, params); | ||
761 | } | ||
762 | |||
763 | static void xonar_gpio_changed(struct oxygen *chip) | ||
764 | { | ||
765 | struct xonar_data *data = chip->model_data; | ||
766 | u8 has_power; | ||
767 | |||
768 | has_power = !!(oxygen_read8(chip, data->ext_power_reg) | ||
769 | & data->ext_power_bit); | ||
770 | if (has_power != data->has_power) { | ||
771 | data->has_power = has_power; | ||
772 | if (has_power) { | ||
773 | snd_printk(KERN_NOTICE "power restored\n"); | ||
774 | } else { | ||
775 | snd_printk(KERN_CRIT | ||
776 | "Hey! Don't unplug the power cable!\n"); | ||
777 | /* TODO: stop PCMs */ | ||
778 | } | ||
779 | } | ||
780 | } | ||
781 | |||
782 | static void xonar_hdav_uart_input(struct oxygen *chip) | ||
783 | { | ||
784 | if (chip->uart_input_count >= 2 && | ||
785 | chip->uart_input[chip->uart_input_count - 2] == 'O' && | ||
786 | chip->uart_input[chip->uart_input_count - 1] == 'K') { | ||
787 | printk(KERN_DEBUG "message from Xonar HDAV HDMI chip received:\n"); | ||
788 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, | ||
789 | chip->uart_input, chip->uart_input_count); | ||
790 | chip->uart_input_count = 0; | ||
791 | } | ||
792 | } | ||
793 | |||
794 | static int gpio_bit_switch_get(struct snd_kcontrol *ctl, | ||
795 | struct snd_ctl_elem_value *value) | ||
796 | { | ||
797 | struct oxygen *chip = ctl->private_data; | ||
798 | u16 bit = ctl->private_value; | ||
799 | |||
800 | value->value.integer.value[0] = | ||
801 | !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & bit); | ||
802 | return 0; | ||
803 | } | ||
804 | |||
805 | static int gpio_bit_switch_put(struct snd_kcontrol *ctl, | ||
806 | struct snd_ctl_elem_value *value) | ||
807 | { | ||
808 | struct oxygen *chip = ctl->private_data; | ||
809 | u16 bit = ctl->private_value; | ||
810 | u16 old_bits, new_bits; | ||
811 | int changed; | ||
812 | |||
813 | spin_lock_irq(&chip->reg_lock); | ||
814 | old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA); | ||
815 | if (value->value.integer.value[0]) | ||
816 | new_bits = old_bits | bit; | ||
817 | else | ||
818 | new_bits = old_bits & ~bit; | ||
819 | changed = new_bits != old_bits; | ||
820 | if (changed) | ||
821 | oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits); | ||
822 | spin_unlock_irq(&chip->reg_lock); | ||
823 | return changed; | ||
824 | } | ||
825 | |||
826 | static const struct snd_kcontrol_new alt_switch = { | ||
827 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
828 | .name = "Analog Loopback Switch", | ||
829 | .info = snd_ctl_boolean_mono_info, | ||
830 | .get = gpio_bit_switch_get, | ||
831 | .put = gpio_bit_switch_put, | ||
832 | .private_value = GPIO_D2_ALT, | ||
833 | }; | ||
834 | |||
835 | static const struct snd_kcontrol_new front_panel_switch = { | ||
836 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
837 | .name = "Front Panel Switch", | ||
838 | .info = snd_ctl_boolean_mono_info, | ||
839 | .get = gpio_bit_switch_get, | ||
840 | .put = gpio_bit_switch_put, | ||
841 | .private_value = GPIO_DX_FRONT_PANEL, | ||
842 | }; | ||
843 | |||
844 | static int st_output_switch_info(struct snd_kcontrol *ctl, | ||
845 | struct snd_ctl_elem_info *info) | ||
846 | { | ||
847 | static const char *const names[3] = { | ||
848 | "Speakers", "Headphones", "FP Headphones" | ||
849 | }; | ||
850 | |||
851 | info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | ||
852 | info->count = 1; | ||
853 | info->value.enumerated.items = 3; | ||
854 | if (info->value.enumerated.item >= 3) | ||
855 | info->value.enumerated.item = 2; | ||
856 | strcpy(info->value.enumerated.name, names[info->value.enumerated.item]); | ||
857 | return 0; | ||
858 | } | ||
859 | |||
860 | static int st_output_switch_get(struct snd_kcontrol *ctl, | ||
861 | struct snd_ctl_elem_value *value) | ||
862 | { | ||
863 | struct oxygen *chip = ctl->private_data; | ||
864 | u16 gpio; | ||
865 | |||
866 | gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA); | ||
867 | if (!(gpio & GPIO_ST_HP)) | ||
868 | value->value.enumerated.item[0] = 0; | ||
869 | else if (gpio & GPIO_ST_HP_REAR) | ||
870 | value->value.enumerated.item[0] = 1; | ||
871 | else | ||
872 | value->value.enumerated.item[0] = 2; | ||
873 | return 0; | ||
874 | } | ||
875 | |||
876 | |||
877 | static int st_output_switch_put(struct snd_kcontrol *ctl, | ||
878 | struct snd_ctl_elem_value *value) | ||
879 | { | ||
880 | struct oxygen *chip = ctl->private_data; | ||
881 | u16 gpio_old, gpio; | ||
882 | |||
883 | mutex_lock(&chip->mutex); | ||
884 | gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA); | ||
885 | gpio = gpio_old; | ||
886 | switch (value->value.enumerated.item[0]) { | ||
887 | case 0: | ||
888 | gpio &= ~(GPIO_ST_HP | GPIO_ST_HP_REAR); | ||
889 | break; | ||
890 | case 1: | ||
891 | gpio |= GPIO_ST_HP | GPIO_ST_HP_REAR; | ||
892 | break; | ||
893 | case 2: | ||
894 | gpio = (gpio | GPIO_ST_HP) & ~GPIO_ST_HP_REAR; | ||
895 | break; | ||
896 | } | ||
897 | oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio); | ||
898 | mutex_unlock(&chip->mutex); | ||
899 | return gpio != gpio_old; | ||
900 | } | ||
901 | |||
902 | static const struct snd_kcontrol_new st_output_switch = { | ||
903 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
904 | .name = "Analog Output", | ||
905 | .info = st_output_switch_info, | ||
906 | .get = st_output_switch_get, | ||
907 | .put = st_output_switch_put, | ||
908 | }; | ||
909 | |||
910 | static void xonar_line_mic_ac97_switch(struct oxygen *chip, | ||
911 | unsigned int reg, unsigned int mute) | ||
912 | { | ||
913 | if (reg == AC97_LINE) { | ||
914 | spin_lock_irq(&chip->reg_lock); | ||
915 | oxygen_write16_masked(chip, OXYGEN_GPIO_DATA, | ||
916 | mute ? GPIO_DX_INPUT_ROUTE : 0, | ||
917 | GPIO_DX_INPUT_ROUTE); | ||
918 | spin_unlock_irq(&chip->reg_lock); | ||
919 | } | ||
920 | } | ||
921 | |||
922 | static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -6000, 50, 0); | ||
923 | static const DECLARE_TLV_DB_SCALE(cs4362a_db_scale, -6000, 100, 0); | ||
924 | |||
925 | static int xonar_d2_control_filter(struct snd_kcontrol_new *template) | ||
926 | { | ||
927 | if (!strncmp(template->name, "CD Capture ", 11)) | ||
928 | /* CD in is actually connected to the video in pin */ | ||
929 | template->private_value ^= AC97_CD ^ AC97_VIDEO; | ||
930 | return 0; | ||
931 | } | ||
932 | |||
933 | static int xonar_d1_control_filter(struct snd_kcontrol_new *template) | ||
934 | { | ||
935 | if (!strncmp(template->name, "CD Capture ", 11)) | ||
936 | return 1; /* no CD input */ | ||
937 | return 0; | ||
938 | } | ||
939 | |||
940 | static int xonar_st_control_filter(struct snd_kcontrol_new *template) | ||
941 | { | ||
942 | if (!strncmp(template->name, "CD Capture ", 11)) | ||
943 | return 1; /* no CD input */ | ||
944 | if (!strcmp(template->name, "Stereo Upmixing")) | ||
945 | return 1; /* stereo only - we don't need upmixing */ | ||
946 | return 0; | ||
947 | } | ||
948 | |||
949 | static int xonar_d2_mixer_init(struct oxygen *chip) | ||
950 | { | ||
951 | return snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip)); | ||
952 | } | ||
953 | |||
954 | static int xonar_d1_mixer_init(struct oxygen *chip) | ||
955 | { | ||
956 | return snd_ctl_add(chip->card, snd_ctl_new1(&front_panel_switch, chip)); | ||
957 | } | ||
958 | |||
959 | static int xonar_st_mixer_init(struct oxygen *chip) | ||
960 | { | ||
961 | return snd_ctl_add(chip->card, snd_ctl_new1(&st_output_switch, chip)); | ||
962 | } | ||
963 | |||
964 | static const struct oxygen_model model_xonar_d2 = { | ||
965 | .longname = "Asus Virtuoso 200", | ||
966 | .chip = "AV200", | ||
967 | .init = xonar_d2_init, | ||
968 | .control_filter = xonar_d2_control_filter, | ||
969 | .mixer_init = xonar_d2_mixer_init, | ||
970 | .cleanup = xonar_d2_cleanup, | ||
971 | .suspend = xonar_d2_suspend, | ||
972 | .resume = xonar_d2_resume, | ||
973 | .set_dac_params = set_pcm1796_params, | ||
974 | .set_adc_params = set_cs53x1_params, | ||
975 | .update_dac_volume = update_pcm1796_volume, | ||
976 | .update_dac_mute = update_pcm1796_mute, | ||
977 | .dac_tlv = pcm1796_db_scale, | ||
978 | .model_data_size = sizeof(struct xonar_data), | ||
979 | .device_config = PLAYBACK_0_TO_I2S | | ||
980 | PLAYBACK_1_TO_SPDIF | | ||
981 | CAPTURE_0_FROM_I2S_2 | | ||
982 | CAPTURE_1_FROM_SPDIF | | ||
983 | MIDI_OUTPUT | | ||
984 | MIDI_INPUT, | ||
985 | .dac_channels = 8, | ||
986 | .dac_volume_min = 255 - 2*60, | ||
987 | .dac_volume_max = 255, | ||
988 | .misc_flags = OXYGEN_MISC_MIDI, | ||
989 | .function_flags = OXYGEN_FUNCTION_SPI | | ||
990 | OXYGEN_FUNCTION_ENABLE_SPI_4_5, | ||
991 | .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
992 | .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
993 | }; | ||
994 | |||
995 | static const struct oxygen_model model_xonar_d1 = { | ||
996 | .longname = "Asus Virtuoso 100", | ||
997 | .chip = "AV200", | ||
998 | .init = xonar_d1_init, | ||
999 | .control_filter = xonar_d1_control_filter, | ||
1000 | .mixer_init = xonar_d1_mixer_init, | ||
1001 | .cleanup = xonar_d1_cleanup, | ||
1002 | .suspend = xonar_d1_suspend, | ||
1003 | .resume = xonar_d1_resume, | ||
1004 | .set_dac_params = set_cs43xx_params, | ||
1005 | .set_adc_params = set_cs53x1_params, | ||
1006 | .update_dac_volume = update_cs43xx_volume, | ||
1007 | .update_dac_mute = update_cs43xx_mute, | ||
1008 | .ac97_switch = xonar_line_mic_ac97_switch, | ||
1009 | .dac_tlv = cs4362a_db_scale, | ||
1010 | .model_data_size = sizeof(struct xonar_data), | ||
1011 | .device_config = PLAYBACK_0_TO_I2S | | ||
1012 | PLAYBACK_1_TO_SPDIF | | ||
1013 | CAPTURE_0_FROM_I2S_2, | ||
1014 | .dac_channels = 8, | ||
1015 | .dac_volume_min = 127 - 60, | ||
1016 | .dac_volume_max = 127, | ||
1017 | .function_flags = OXYGEN_FUNCTION_2WIRE, | ||
1018 | .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
1019 | .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
1020 | }; | ||
1021 | |||
1022 | static const struct oxygen_model model_xonar_hdav = { | ||
1023 | .longname = "Asus Virtuoso 200", | ||
1024 | .chip = "AV200", | ||
1025 | .init = xonar_hdav_init, | ||
1026 | .cleanup = xonar_hdav_cleanup, | ||
1027 | .suspend = xonar_hdav_suspend, | ||
1028 | .resume = xonar_hdav_resume, | ||
1029 | .pcm_hardware_filter = xonar_hdav_pcm_hardware_filter, | ||
1030 | .set_dac_params = set_hdav_params, | ||
1031 | .set_adc_params = set_cs53x1_params, | ||
1032 | .update_dac_volume = update_pcm1796_volume, | ||
1033 | .update_dac_mute = update_pcm1796_mute, | ||
1034 | .uart_input = xonar_hdav_uart_input, | ||
1035 | .ac97_switch = xonar_line_mic_ac97_switch, | ||
1036 | .dac_tlv = pcm1796_db_scale, | ||
1037 | .model_data_size = sizeof(struct xonar_data), | ||
1038 | .device_config = PLAYBACK_0_TO_I2S | | ||
1039 | PLAYBACK_1_TO_SPDIF | | ||
1040 | CAPTURE_0_FROM_I2S_2 | | ||
1041 | CAPTURE_1_FROM_SPDIF, | ||
1042 | .dac_channels = 8, | ||
1043 | .dac_volume_min = 255 - 2*60, | ||
1044 | .dac_volume_max = 255, | ||
1045 | .misc_flags = OXYGEN_MISC_MIDI, | ||
1046 | .function_flags = OXYGEN_FUNCTION_2WIRE, | ||
1047 | .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
1048 | .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
1049 | }; | ||
1050 | |||
1051 | static const struct oxygen_model model_xonar_st = { | ||
1052 | .longname = "Asus Virtuoso 100", | ||
1053 | .chip = "AV200", | ||
1054 | .init = xonar_st_init, | ||
1055 | .control_filter = xonar_st_control_filter, | ||
1056 | .mixer_init = xonar_st_mixer_init, | ||
1057 | .cleanup = xonar_st_cleanup, | ||
1058 | .suspend = xonar_st_suspend, | ||
1059 | .resume = xonar_st_resume, | ||
1060 | .set_dac_params = set_pcm1796_params, | ||
1061 | .set_adc_params = set_cs53x1_params, | ||
1062 | .update_dac_volume = update_pcm1796_volume, | ||
1063 | .update_dac_mute = update_pcm1796_mute, | ||
1064 | .ac97_switch = xonar_line_mic_ac97_switch, | ||
1065 | .dac_tlv = pcm1796_db_scale, | ||
1066 | .model_data_size = sizeof(struct xonar_data), | ||
1067 | .device_config = PLAYBACK_0_TO_I2S | | ||
1068 | PLAYBACK_1_TO_SPDIF | | ||
1069 | CAPTURE_0_FROM_I2S_2, | ||
1070 | .dac_channels = 2, | ||
1071 | .dac_volume_min = 255 - 2*60, | ||
1072 | .dac_volume_max = 255, | ||
1073 | .function_flags = OXYGEN_FUNCTION_2WIRE, | ||
1074 | .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
1075 | .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
1076 | }; | ||
1077 | |||
1078 | static int __devinit get_xonar_model(struct oxygen *chip, | 57 | static int __devinit get_xonar_model(struct oxygen *chip, |
1079 | const struct pci_device_id *id) | 58 | const struct pci_device_id *id) |
1080 | { | 59 | { |
1081 | static const struct oxygen_model *const models[] = { | 60 | if (get_xonar_pcm179x_model(chip, id) >= 0) |
1082 | [MODEL_D1] = &model_xonar_d1, | 61 | return 0; |
1083 | [MODEL_DX] = &model_xonar_d1, | 62 | if (get_xonar_cs43xx_model(chip, id) >= 0) |
1084 | [MODEL_D2] = &model_xonar_d2, | 63 | return 0; |
1085 | [MODEL_D2X] = &model_xonar_d2, | 64 | return -EINVAL; |
1086 | [MODEL_HDAV] = &model_xonar_hdav, | ||
1087 | [MODEL_ST] = &model_xonar_st, | ||
1088 | [MODEL_STX] = &model_xonar_st, | ||
1089 | }; | ||
1090 | static const char *const names[] = { | ||
1091 | [MODEL_D1] = "Xonar D1", | ||
1092 | [MODEL_DX] = "Xonar DX", | ||
1093 | [MODEL_D2] = "Xonar D2", | ||
1094 | [MODEL_D2X] = "Xonar D2X", | ||
1095 | [MODEL_HDAV] = "Xonar HDAV1.3", | ||
1096 | [MODEL_HDAV_H6] = "Xonar HDAV1.3+H6", | ||
1097 | [MODEL_ST] = "Xonar Essence ST", | ||
1098 | [MODEL_ST_H6] = "Xonar Essence ST+H6", | ||
1099 | [MODEL_STX] = "Xonar Essence STX", | ||
1100 | }; | ||
1101 | unsigned int model = id->driver_data; | ||
1102 | |||
1103 | if (model >= ARRAY_SIZE(models) || !models[model]) | ||
1104 | return -EINVAL; | ||
1105 | chip->model = *models[model]; | ||
1106 | |||
1107 | switch (model) { | ||
1108 | case MODEL_D2X: | ||
1109 | chip->model.init = xonar_d2x_init; | ||
1110 | break; | ||
1111 | case MODEL_DX: | ||
1112 | chip->model.init = xonar_dx_init; | ||
1113 | break; | ||
1114 | case MODEL_HDAV: | ||
1115 | oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK); | ||
1116 | switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) { | ||
1117 | case GPIO_DB_H6: | ||
1118 | model = MODEL_HDAV_H6; | ||
1119 | break; | ||
1120 | case GPIO_DB_XX: | ||
1121 | snd_printk(KERN_ERR "unknown daughterboard\n"); | ||
1122 | return -ENODEV; | ||
1123 | } | ||
1124 | break; | ||
1125 | case MODEL_ST: | ||
1126 | oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK); | ||
1127 | switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) { | ||
1128 | case GPIO_DB_H6: | ||
1129 | model = MODEL_ST_H6; | ||
1130 | break; | ||
1131 | } | ||
1132 | break; | ||
1133 | case MODEL_STX: | ||
1134 | chip->model.init = xonar_stx_init; | ||
1135 | oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK); | ||
1136 | break; | ||
1137 | } | ||
1138 | |||
1139 | chip->model.shortname = names[model]; | ||
1140 | chip->model.private_data = model; | ||
1141 | return 0; | ||
1142 | } | 65 | } |
1143 | 66 | ||
1144 | static int __devinit xonar_probe(struct pci_dev *pci, | 67 | static int __devinit xonar_probe(struct pci_dev *pci, |
diff --git a/sound/pci/oxygen/xonar.h b/sound/pci/oxygen/xonar.h new file mode 100644 index 000000000000..89b3ed814d64 --- /dev/null +++ b/sound/pci/oxygen/xonar.h | |||
@@ -0,0 +1,50 @@ | |||
1 | #ifndef XONAR_H_INCLUDED | ||
2 | #define XONAR_H_INCLUDED | ||
3 | |||
4 | #include "oxygen.h" | ||
5 | |||
6 | struct xonar_generic { | ||
7 | unsigned int anti_pop_delay; | ||
8 | u16 output_enable_bit; | ||
9 | u8 ext_power_reg; | ||
10 | u8 ext_power_int_reg; | ||
11 | u8 ext_power_bit; | ||
12 | u8 has_power; | ||
13 | }; | ||
14 | |||
15 | struct xonar_hdmi { | ||
16 | u8 params[5]; | ||
17 | }; | ||
18 | |||
19 | /* generic helper functions */ | ||
20 | |||
21 | void xonar_enable_output(struct oxygen *chip); | ||
22 | void xonar_disable_output(struct oxygen *chip); | ||
23 | void xonar_init_ext_power(struct oxygen *chip); | ||
24 | void xonar_init_cs53x1(struct oxygen *chip); | ||
25 | void xonar_set_cs53x1_params(struct oxygen *chip, | ||
26 | struct snd_pcm_hw_params *params); | ||
27 | int xonar_gpio_bit_switch_get(struct snd_kcontrol *ctl, | ||
28 | struct snd_ctl_elem_value *value); | ||
29 | int xonar_gpio_bit_switch_put(struct snd_kcontrol *ctl, | ||
30 | struct snd_ctl_elem_value *value); | ||
31 | |||
32 | /* model-specific card drivers */ | ||
33 | |||
34 | int get_xonar_pcm179x_model(struct oxygen *chip, | ||
35 | const struct pci_device_id *id); | ||
36 | int get_xonar_cs43xx_model(struct oxygen *chip, | ||
37 | const struct pci_device_id *id); | ||
38 | |||
39 | /* HDMI helper functions */ | ||
40 | |||
41 | void xonar_hdmi_init(struct oxygen *chip, struct xonar_hdmi *data); | ||
42 | void xonar_hdmi_cleanup(struct oxygen *chip); | ||
43 | void xonar_hdmi_resume(struct oxygen *chip, struct xonar_hdmi *hdmi); | ||
44 | void xonar_hdmi_pcm_hardware_filter(unsigned int channel, | ||
45 | struct snd_pcm_hardware *hardware); | ||
46 | void xonar_set_hdmi_params(struct oxygen *chip, struct xonar_hdmi *hdmi, | ||
47 | struct snd_pcm_hw_params *params); | ||
48 | void xonar_hdmi_uart_input(struct oxygen *chip); | ||
49 | |||
50 | #endif | ||
diff --git a/sound/pci/oxygen/xonar_cs43xx.c b/sound/pci/oxygen/xonar_cs43xx.c new file mode 100644 index 000000000000..16c226bfcd2b --- /dev/null +++ b/sound/pci/oxygen/xonar_cs43xx.c | |||
@@ -0,0 +1,434 @@ | |||
1 | /* | ||
2 | * card driver for models with CS4398/CS4362A DACs (Xonar D1/DX) | ||
3 | * | ||
4 | * Copyright (c) Clemens Ladisch <clemens@ladisch.de> | ||
5 | * | ||
6 | * | ||
7 | * This driver is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License, version 2. | ||
9 | * | ||
10 | * This driver is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this driver; if not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | /* | ||
20 | * Xonar D1/DX | ||
21 | * ----------- | ||
22 | * | ||
23 | * CMI8788: | ||
24 | * | ||
25 | * I²C <-> CS4398 (front) | ||
26 | * <-> CS4362A (surround, center/LFE, back) | ||
27 | * | ||
28 | * GPI 0 <- external power present (DX only) | ||
29 | * | ||
30 | * GPIO 0 -> enable output to speakers | ||
31 | * GPIO 1 -> enable front panel I/O | ||
32 | * GPIO 2 -> M0 of CS5361 | ||
33 | * GPIO 3 -> M1 of CS5361 | ||
34 | * GPIO 8 -> route input jack to line-in (0) or mic-in (1) | ||
35 | * | ||
36 | * CS4398: | ||
37 | * | ||
38 | * AD0 <- 1 | ||
39 | * AD1 <- 1 | ||
40 | * | ||
41 | * CS4362A: | ||
42 | * | ||
43 | * AD0 <- 0 | ||
44 | * | ||
45 | * CM9780: | ||
46 | * | ||
47 | * GPO 0 -> route line-in (0) or AC97 output (1) to CS5361 input | ||
48 | */ | ||
49 | |||
50 | #include <linux/pci.h> | ||
51 | #include <linux/delay.h> | ||
52 | #include <sound/ac97_codec.h> | ||
53 | #include <sound/control.h> | ||
54 | #include <sound/core.h> | ||
55 | #include <sound/pcm.h> | ||
56 | #include <sound/pcm_params.h> | ||
57 | #include <sound/tlv.h> | ||
58 | #include "xonar.h" | ||
59 | #include "cs4398.h" | ||
60 | #include "cs4362a.h" | ||
61 | |||
62 | #define GPI_EXT_POWER 0x01 | ||
63 | #define GPIO_D1_OUTPUT_ENABLE 0x0001 | ||
64 | #define GPIO_D1_FRONT_PANEL 0x0002 | ||
65 | #define GPIO_D1_INPUT_ROUTE 0x0100 | ||
66 | |||
67 | #define I2C_DEVICE_CS4398 0x9e /* 10011, AD1=1, AD0=1, /W=0 */ | ||
68 | #define I2C_DEVICE_CS4362A 0x30 /* 001100, AD0=0, /W=0 */ | ||
69 | |||
70 | struct xonar_cs43xx { | ||
71 | struct xonar_generic generic; | ||
72 | u8 cs4398_regs[8]; | ||
73 | u8 cs4362a_regs[15]; | ||
74 | }; | ||
75 | |||
76 | static void cs4398_write(struct oxygen *chip, u8 reg, u8 value) | ||
77 | { | ||
78 | struct xonar_cs43xx *data = chip->model_data; | ||
79 | |||
80 | oxygen_write_i2c(chip, I2C_DEVICE_CS4398, reg, value); | ||
81 | if (reg < ARRAY_SIZE(data->cs4398_regs)) | ||
82 | data->cs4398_regs[reg] = value; | ||
83 | } | ||
84 | |||
85 | static void cs4398_write_cached(struct oxygen *chip, u8 reg, u8 value) | ||
86 | { | ||
87 | struct xonar_cs43xx *data = chip->model_data; | ||
88 | |||
89 | if (value != data->cs4398_regs[reg]) | ||
90 | cs4398_write(chip, reg, value); | ||
91 | } | ||
92 | |||
93 | static void cs4362a_write(struct oxygen *chip, u8 reg, u8 value) | ||
94 | { | ||
95 | struct xonar_cs43xx *data = chip->model_data; | ||
96 | |||
97 | oxygen_write_i2c(chip, I2C_DEVICE_CS4362A, reg, value); | ||
98 | if (reg < ARRAY_SIZE(data->cs4362a_regs)) | ||
99 | data->cs4362a_regs[reg] = value; | ||
100 | } | ||
101 | |||
102 | static void cs4362a_write_cached(struct oxygen *chip, u8 reg, u8 value) | ||
103 | { | ||
104 | struct xonar_cs43xx *data = chip->model_data; | ||
105 | |||
106 | if (value != data->cs4362a_regs[reg]) | ||
107 | cs4362a_write(chip, reg, value); | ||
108 | } | ||
109 | |||
110 | static void cs43xx_registers_init(struct oxygen *chip) | ||
111 | { | ||
112 | struct xonar_cs43xx *data = chip->model_data; | ||
113 | unsigned int i; | ||
114 | |||
115 | /* set CPEN (control port mode) and power down */ | ||
116 | cs4398_write(chip, 8, CS4398_CPEN | CS4398_PDN); | ||
117 | cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN); | ||
118 | /* configure */ | ||
119 | cs4398_write(chip, 2, data->cs4398_regs[2]); | ||
120 | cs4398_write(chip, 3, CS4398_ATAPI_B_R | CS4398_ATAPI_A_L); | ||
121 | cs4398_write(chip, 4, data->cs4398_regs[4]); | ||
122 | cs4398_write(chip, 5, data->cs4398_regs[5]); | ||
123 | cs4398_write(chip, 6, data->cs4398_regs[6]); | ||
124 | cs4398_write(chip, 7, data->cs4398_regs[7]); | ||
125 | cs4362a_write(chip, 0x02, CS4362A_DIF_LJUST); | ||
126 | cs4362a_write(chip, 0x03, CS4362A_MUTEC_6 | CS4362A_AMUTE | | ||
127 | CS4362A_RMP_UP | CS4362A_ZERO_CROSS | CS4362A_SOFT_RAMP); | ||
128 | cs4362a_write(chip, 0x04, data->cs4362a_regs[0x04]); | ||
129 | cs4362a_write(chip, 0x05, 0); | ||
130 | for (i = 6; i <= 14; ++i) | ||
131 | cs4362a_write(chip, i, data->cs4362a_regs[i]); | ||
132 | /* clear power down */ | ||
133 | cs4398_write(chip, 8, CS4398_CPEN); | ||
134 | cs4362a_write(chip, 0x01, CS4362A_CPEN); | ||
135 | } | ||
136 | |||
137 | static void xonar_d1_init(struct oxygen *chip) | ||
138 | { | ||
139 | struct xonar_cs43xx *data = chip->model_data; | ||
140 | |||
141 | data->generic.anti_pop_delay = 800; | ||
142 | data->generic.output_enable_bit = GPIO_D1_OUTPUT_ENABLE; | ||
143 | data->cs4398_regs[2] = | ||
144 | CS4398_FM_SINGLE | CS4398_DEM_NONE | CS4398_DIF_LJUST; | ||
145 | data->cs4398_regs[4] = CS4398_MUTEP_LOW | | ||
146 | CS4398_MUTE_B | CS4398_MUTE_A | CS4398_PAMUTE; | ||
147 | data->cs4398_regs[5] = 60 * 2; | ||
148 | data->cs4398_regs[6] = 60 * 2; | ||
149 | data->cs4398_regs[7] = CS4398_RMP_DN | CS4398_RMP_UP | | ||
150 | CS4398_ZERO_CROSS | CS4398_SOFT_RAMP; | ||
151 | data->cs4362a_regs[4] = CS4362A_RMP_DN | CS4362A_DEM_NONE; | ||
152 | data->cs4362a_regs[6] = CS4362A_FM_SINGLE | | ||
153 | CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L; | ||
154 | data->cs4362a_regs[7] = 60 | CS4362A_MUTE; | ||
155 | data->cs4362a_regs[8] = 60 | CS4362A_MUTE; | ||
156 | data->cs4362a_regs[9] = data->cs4362a_regs[6]; | ||
157 | data->cs4362a_regs[10] = 60 | CS4362A_MUTE; | ||
158 | data->cs4362a_regs[11] = 60 | CS4362A_MUTE; | ||
159 | data->cs4362a_regs[12] = data->cs4362a_regs[6]; | ||
160 | data->cs4362a_regs[13] = 60 | CS4362A_MUTE; | ||
161 | data->cs4362a_regs[14] = 60 | CS4362A_MUTE; | ||
162 | |||
163 | oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS, | ||
164 | OXYGEN_2WIRE_LENGTH_8 | | ||
165 | OXYGEN_2WIRE_INTERRUPT_MASK | | ||
166 | OXYGEN_2WIRE_SPEED_FAST); | ||
167 | |||
168 | cs43xx_registers_init(chip); | ||
169 | |||
170 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, | ||
171 | GPIO_D1_FRONT_PANEL | GPIO_D1_INPUT_ROUTE); | ||
172 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, | ||
173 | GPIO_D1_FRONT_PANEL | GPIO_D1_INPUT_ROUTE); | ||
174 | |||
175 | xonar_init_cs53x1(chip); | ||
176 | xonar_enable_output(chip); | ||
177 | |||
178 | snd_component_add(chip->card, "CS4398"); | ||
179 | snd_component_add(chip->card, "CS4362A"); | ||
180 | snd_component_add(chip->card, "CS5361"); | ||
181 | } | ||
182 | |||
183 | static void xonar_dx_init(struct oxygen *chip) | ||
184 | { | ||
185 | struct xonar_cs43xx *data = chip->model_data; | ||
186 | |||
187 | data->generic.ext_power_reg = OXYGEN_GPI_DATA; | ||
188 | data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK; | ||
189 | data->generic.ext_power_bit = GPI_EXT_POWER; | ||
190 | xonar_init_ext_power(chip); | ||
191 | xonar_d1_init(chip); | ||
192 | } | ||
193 | |||
194 | static void xonar_d1_cleanup(struct oxygen *chip) | ||
195 | { | ||
196 | xonar_disable_output(chip); | ||
197 | cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN); | ||
198 | oxygen_clear_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC); | ||
199 | } | ||
200 | |||
201 | static void xonar_d1_suspend(struct oxygen *chip) | ||
202 | { | ||
203 | xonar_d1_cleanup(chip); | ||
204 | } | ||
205 | |||
206 | static void xonar_d1_resume(struct oxygen *chip) | ||
207 | { | ||
208 | oxygen_set_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC); | ||
209 | msleep(1); | ||
210 | cs43xx_registers_init(chip); | ||
211 | xonar_enable_output(chip); | ||
212 | } | ||
213 | |||
214 | static void set_cs43xx_params(struct oxygen *chip, | ||
215 | struct snd_pcm_hw_params *params) | ||
216 | { | ||
217 | struct xonar_cs43xx *data = chip->model_data; | ||
218 | u8 cs4398_fm, cs4362a_fm; | ||
219 | |||
220 | if (params_rate(params) <= 50000) { | ||
221 | cs4398_fm = CS4398_FM_SINGLE; | ||
222 | cs4362a_fm = CS4362A_FM_SINGLE; | ||
223 | } else if (params_rate(params) <= 100000) { | ||
224 | cs4398_fm = CS4398_FM_DOUBLE; | ||
225 | cs4362a_fm = CS4362A_FM_DOUBLE; | ||
226 | } else { | ||
227 | cs4398_fm = CS4398_FM_QUAD; | ||
228 | cs4362a_fm = CS4362A_FM_QUAD; | ||
229 | } | ||
230 | cs4398_fm |= CS4398_DEM_NONE | CS4398_DIF_LJUST; | ||
231 | cs4398_write_cached(chip, 2, cs4398_fm); | ||
232 | cs4362a_fm |= data->cs4362a_regs[6] & ~CS4362A_FM_MASK; | ||
233 | cs4362a_write_cached(chip, 6, cs4362a_fm); | ||
234 | cs4362a_write_cached(chip, 12, cs4362a_fm); | ||
235 | cs4362a_fm &= CS4362A_FM_MASK; | ||
236 | cs4362a_fm |= data->cs4362a_regs[9] & ~CS4362A_FM_MASK; | ||
237 | cs4362a_write_cached(chip, 9, cs4362a_fm); | ||
238 | } | ||
239 | |||
240 | static void update_cs4362a_volumes(struct oxygen *chip) | ||
241 | { | ||
242 | unsigned int i; | ||
243 | u8 mute; | ||
244 | |||
245 | mute = chip->dac_mute ? CS4362A_MUTE : 0; | ||
246 | for (i = 0; i < 6; ++i) | ||
247 | cs4362a_write_cached(chip, 7 + i + i / 2, | ||
248 | (127 - chip->dac_volume[2 + i]) | mute); | ||
249 | } | ||
250 | |||
251 | static void update_cs43xx_volume(struct oxygen *chip) | ||
252 | { | ||
253 | cs4398_write_cached(chip, 5, (127 - chip->dac_volume[0]) * 2); | ||
254 | cs4398_write_cached(chip, 6, (127 - chip->dac_volume[1]) * 2); | ||
255 | update_cs4362a_volumes(chip); | ||
256 | } | ||
257 | |||
258 | static void update_cs43xx_mute(struct oxygen *chip) | ||
259 | { | ||
260 | u8 reg; | ||
261 | |||
262 | reg = CS4398_MUTEP_LOW | CS4398_PAMUTE; | ||
263 | if (chip->dac_mute) | ||
264 | reg |= CS4398_MUTE_B | CS4398_MUTE_A; | ||
265 | cs4398_write_cached(chip, 4, reg); | ||
266 | update_cs4362a_volumes(chip); | ||
267 | } | ||
268 | |||
269 | static void update_cs43xx_center_lfe_mix(struct oxygen *chip, bool mixed) | ||
270 | { | ||
271 | struct xonar_cs43xx *data = chip->model_data; | ||
272 | u8 reg; | ||
273 | |||
274 | reg = data->cs4362a_regs[9] & ~CS4362A_ATAPI_MASK; | ||
275 | if (mixed) | ||
276 | reg |= CS4362A_ATAPI_B_LR | CS4362A_ATAPI_A_LR; | ||
277 | else | ||
278 | reg |= CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L; | ||
279 | cs4362a_write_cached(chip, 9, reg); | ||
280 | } | ||
281 | |||
282 | static const struct snd_kcontrol_new front_panel_switch = { | ||
283 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
284 | .name = "Front Panel Switch", | ||
285 | .info = snd_ctl_boolean_mono_info, | ||
286 | .get = xonar_gpio_bit_switch_get, | ||
287 | .put = xonar_gpio_bit_switch_put, | ||
288 | .private_value = GPIO_D1_FRONT_PANEL, | ||
289 | }; | ||
290 | |||
291 | static int rolloff_info(struct snd_kcontrol *ctl, | ||
292 | struct snd_ctl_elem_info *info) | ||
293 | { | ||
294 | static const char *const names[2] = { | ||
295 | "Fast Roll-off", "Slow Roll-off" | ||
296 | }; | ||
297 | |||
298 | info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | ||
299 | info->count = 1; | ||
300 | info->value.enumerated.items = 2; | ||
301 | if (info->value.enumerated.item >= 2) | ||
302 | info->value.enumerated.item = 1; | ||
303 | strcpy(info->value.enumerated.name, names[info->value.enumerated.item]); | ||
304 | return 0; | ||
305 | } | ||
306 | |||
307 | static int rolloff_get(struct snd_kcontrol *ctl, | ||
308 | struct snd_ctl_elem_value *value) | ||
309 | { | ||
310 | struct oxygen *chip = ctl->private_data; | ||
311 | struct xonar_cs43xx *data = chip->model_data; | ||
312 | |||
313 | value->value.enumerated.item[0] = | ||
314 | (data->cs4398_regs[7] & CS4398_FILT_SEL) != 0; | ||
315 | return 0; | ||
316 | } | ||
317 | |||
318 | static int rolloff_put(struct snd_kcontrol *ctl, | ||
319 | struct snd_ctl_elem_value *value) | ||
320 | { | ||
321 | struct oxygen *chip = ctl->private_data; | ||
322 | struct xonar_cs43xx *data = chip->model_data; | ||
323 | int changed; | ||
324 | u8 reg; | ||
325 | |||
326 | mutex_lock(&chip->mutex); | ||
327 | reg = data->cs4398_regs[7]; | ||
328 | if (value->value.enumerated.item[0]) | ||
329 | reg |= CS4398_FILT_SEL; | ||
330 | else | ||
331 | reg &= ~CS4398_FILT_SEL; | ||
332 | changed = reg != data->cs4398_regs[7]; | ||
333 | if (changed) { | ||
334 | cs4398_write(chip, 7, reg); | ||
335 | if (reg & CS4398_FILT_SEL) | ||
336 | reg = data->cs4362a_regs[0x04] | CS4362A_FILT_SEL; | ||
337 | else | ||
338 | reg = data->cs4362a_regs[0x04] & ~CS4362A_FILT_SEL; | ||
339 | cs4362a_write(chip, 0x04, reg); | ||
340 | } | ||
341 | mutex_unlock(&chip->mutex); | ||
342 | return changed; | ||
343 | } | ||
344 | |||
345 | static const struct snd_kcontrol_new rolloff_control = { | ||
346 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
347 | .name = "DAC Filter Playback Enum", | ||
348 | .info = rolloff_info, | ||
349 | .get = rolloff_get, | ||
350 | .put = rolloff_put, | ||
351 | }; | ||
352 | |||
353 | static void xonar_d1_line_mic_ac97_switch(struct oxygen *chip, | ||
354 | unsigned int reg, unsigned int mute) | ||
355 | { | ||
356 | if (reg == AC97_LINE) { | ||
357 | spin_lock_irq(&chip->reg_lock); | ||
358 | oxygen_write16_masked(chip, OXYGEN_GPIO_DATA, | ||
359 | mute ? GPIO_D1_INPUT_ROUTE : 0, | ||
360 | GPIO_D1_INPUT_ROUTE); | ||
361 | spin_unlock_irq(&chip->reg_lock); | ||
362 | } | ||
363 | } | ||
364 | |||
365 | static const DECLARE_TLV_DB_SCALE(cs4362a_db_scale, -6000, 100, 0); | ||
366 | |||
367 | static int xonar_d1_control_filter(struct snd_kcontrol_new *template) | ||
368 | { | ||
369 | if (!strncmp(template->name, "CD Capture ", 11)) | ||
370 | return 1; /* no CD input */ | ||
371 | return 0; | ||
372 | } | ||
373 | |||
374 | static int xonar_d1_mixer_init(struct oxygen *chip) | ||
375 | { | ||
376 | int err; | ||
377 | |||
378 | err = snd_ctl_add(chip->card, snd_ctl_new1(&front_panel_switch, chip)); | ||
379 | if (err < 0) | ||
380 | return err; | ||
381 | err = snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip)); | ||
382 | if (err < 0) | ||
383 | return err; | ||
384 | return 0; | ||
385 | } | ||
386 | |||
387 | static const struct oxygen_model model_xonar_d1 = { | ||
388 | .longname = "Asus Virtuoso 100", | ||
389 | .chip = "AV200", | ||
390 | .init = xonar_d1_init, | ||
391 | .control_filter = xonar_d1_control_filter, | ||
392 | .mixer_init = xonar_d1_mixer_init, | ||
393 | .cleanup = xonar_d1_cleanup, | ||
394 | .suspend = xonar_d1_suspend, | ||
395 | .resume = xonar_d1_resume, | ||
396 | .get_i2s_mclk = oxygen_default_i2s_mclk, | ||
397 | .set_dac_params = set_cs43xx_params, | ||
398 | .set_adc_params = xonar_set_cs53x1_params, | ||
399 | .update_dac_volume = update_cs43xx_volume, | ||
400 | .update_dac_mute = update_cs43xx_mute, | ||
401 | .update_center_lfe_mix = update_cs43xx_center_lfe_mix, | ||
402 | .ac97_switch = xonar_d1_line_mic_ac97_switch, | ||
403 | .dac_tlv = cs4362a_db_scale, | ||
404 | .model_data_size = sizeof(struct xonar_cs43xx), | ||
405 | .device_config = PLAYBACK_0_TO_I2S | | ||
406 | PLAYBACK_1_TO_SPDIF | | ||
407 | CAPTURE_0_FROM_I2S_2, | ||
408 | .dac_channels = 8, | ||
409 | .dac_volume_min = 127 - 60, | ||
410 | .dac_volume_max = 127, | ||
411 | .function_flags = OXYGEN_FUNCTION_2WIRE, | ||
412 | .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
413 | .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
414 | }; | ||
415 | |||
416 | int __devinit get_xonar_cs43xx_model(struct oxygen *chip, | ||
417 | const struct pci_device_id *id) | ||
418 | { | ||
419 | switch (id->subdevice) { | ||
420 | case 0x834f: | ||
421 | chip->model = model_xonar_d1; | ||
422 | chip->model.shortname = "Xonar D1"; | ||
423 | break; | ||
424 | case 0x8275: | ||
425 | case 0x8327: | ||
426 | chip->model = model_xonar_d1; | ||
427 | chip->model.shortname = "Xonar DX"; | ||
428 | chip->model.init = xonar_dx_init; | ||
429 | break; | ||
430 | default: | ||
431 | return -EINVAL; | ||
432 | } | ||
433 | return 0; | ||
434 | } | ||
diff --git a/sound/pci/oxygen/xonar_hdmi.c b/sound/pci/oxygen/xonar_hdmi.c new file mode 100644 index 000000000000..b12db1f1cea9 --- /dev/null +++ b/sound/pci/oxygen/xonar_hdmi.c | |||
@@ -0,0 +1,128 @@ | |||
1 | /* | ||
2 | * helper functions for HDMI models (Xonar HDAV1.3) | ||
3 | * | ||
4 | * Copyright (c) Clemens Ladisch <clemens@ladisch.de> | ||
5 | * | ||
6 | * | ||
7 | * This driver is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License, version 2. | ||
9 | * | ||
10 | * This driver is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this driver; if not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #include <linux/pci.h> | ||
20 | #include <linux/delay.h> | ||
21 | #include <sound/asoundef.h> | ||
22 | #include <sound/control.h> | ||
23 | #include <sound/core.h> | ||
24 | #include <sound/pcm.h> | ||
25 | #include <sound/pcm_params.h> | ||
26 | #include <sound/tlv.h> | ||
27 | #include "xonar.h" | ||
28 | |||
29 | static void hdmi_write_command(struct oxygen *chip, u8 command, | ||
30 | unsigned int count, const u8 *params) | ||
31 | { | ||
32 | unsigned int i; | ||
33 | u8 checksum; | ||
34 | |||
35 | oxygen_write_uart(chip, 0xfb); | ||
36 | oxygen_write_uart(chip, 0xef); | ||
37 | oxygen_write_uart(chip, command); | ||
38 | oxygen_write_uart(chip, count); | ||
39 | for (i = 0; i < count; ++i) | ||
40 | oxygen_write_uart(chip, params[i]); | ||
41 | checksum = 0xfb + 0xef + command + count; | ||
42 | for (i = 0; i < count; ++i) | ||
43 | checksum += params[i]; | ||
44 | oxygen_write_uart(chip, checksum); | ||
45 | } | ||
46 | |||
47 | static void xonar_hdmi_init_commands(struct oxygen *chip, | ||
48 | struct xonar_hdmi *hdmi) | ||
49 | { | ||
50 | u8 param; | ||
51 | |||
52 | oxygen_reset_uart(chip); | ||
53 | param = 0; | ||
54 | hdmi_write_command(chip, 0x61, 1, ¶m); | ||
55 | param = 1; | ||
56 | hdmi_write_command(chip, 0x74, 1, ¶m); | ||
57 | hdmi_write_command(chip, 0x54, 5, hdmi->params); | ||
58 | } | ||
59 | |||
60 | void xonar_hdmi_init(struct oxygen *chip, struct xonar_hdmi *hdmi) | ||
61 | { | ||
62 | hdmi->params[1] = IEC958_AES3_CON_FS_48000; | ||
63 | hdmi->params[4] = 1; | ||
64 | xonar_hdmi_init_commands(chip, hdmi); | ||
65 | } | ||
66 | |||
67 | void xonar_hdmi_cleanup(struct oxygen *chip) | ||
68 | { | ||
69 | u8 param = 0; | ||
70 | |||
71 | hdmi_write_command(chip, 0x74, 1, ¶m); | ||
72 | } | ||
73 | |||
74 | void xonar_hdmi_resume(struct oxygen *chip, struct xonar_hdmi *hdmi) | ||
75 | { | ||
76 | xonar_hdmi_init_commands(chip, hdmi); | ||
77 | } | ||
78 | |||
79 | void xonar_hdmi_pcm_hardware_filter(unsigned int channel, | ||
80 | struct snd_pcm_hardware *hardware) | ||
81 | { | ||
82 | if (channel == PCM_MULTICH) { | ||
83 | hardware->rates = SNDRV_PCM_RATE_44100 | | ||
84 | SNDRV_PCM_RATE_48000 | | ||
85 | SNDRV_PCM_RATE_96000 | | ||
86 | SNDRV_PCM_RATE_192000; | ||
87 | hardware->rate_min = 44100; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | void xonar_set_hdmi_params(struct oxygen *chip, struct xonar_hdmi *hdmi, | ||
92 | struct snd_pcm_hw_params *params) | ||
93 | { | ||
94 | hdmi->params[0] = 0; /* 1 = non-audio */ | ||
95 | switch (params_rate(params)) { | ||
96 | case 44100: | ||
97 | hdmi->params[1] = IEC958_AES3_CON_FS_44100; | ||
98 | break; | ||
99 | case 48000: | ||
100 | hdmi->params[1] = IEC958_AES3_CON_FS_48000; | ||
101 | break; | ||
102 | default: /* 96000 */ | ||
103 | hdmi->params[1] = IEC958_AES3_CON_FS_96000; | ||
104 | break; | ||
105 | case 192000: | ||
106 | hdmi->params[1] = IEC958_AES3_CON_FS_192000; | ||
107 | break; | ||
108 | } | ||
109 | hdmi->params[2] = params_channels(params) / 2 - 1; | ||
110 | if (params_format(params) == SNDRV_PCM_FORMAT_S16_LE) | ||
111 | hdmi->params[3] = 0; | ||
112 | else | ||
113 | hdmi->params[3] = 0xc0; | ||
114 | hdmi->params[4] = 1; /* ? */ | ||
115 | hdmi_write_command(chip, 0x54, 5, hdmi->params); | ||
116 | } | ||
117 | |||
118 | void xonar_hdmi_uart_input(struct oxygen *chip) | ||
119 | { | ||
120 | if (chip->uart_input_count >= 2 && | ||
121 | chip->uart_input[chip->uart_input_count - 2] == 'O' && | ||
122 | chip->uart_input[chip->uart_input_count - 1] == 'K') { | ||
123 | printk(KERN_DEBUG "message from HDMI chip received:\n"); | ||
124 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, | ||
125 | chip->uart_input, chip->uart_input_count); | ||
126 | chip->uart_input_count = 0; | ||
127 | } | ||
128 | } | ||
diff --git a/sound/pci/oxygen/xonar_lib.c b/sound/pci/oxygen/xonar_lib.c new file mode 100644 index 000000000000..b3ff71316653 --- /dev/null +++ b/sound/pci/oxygen/xonar_lib.c | |||
@@ -0,0 +1,132 @@ | |||
1 | /* | ||
2 | * helper functions for Asus Xonar cards | ||
3 | * | ||
4 | * Copyright (c) Clemens Ladisch <clemens@ladisch.de> | ||
5 | * | ||
6 | * | ||
7 | * This driver is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License, version 2. | ||
9 | * | ||
10 | * This driver is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this driver; if not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #include <linux/delay.h> | ||
20 | #include <sound/core.h> | ||
21 | #include <sound/control.h> | ||
22 | #include <sound/pcm.h> | ||
23 | #include <sound/pcm_params.h> | ||
24 | #include "xonar.h" | ||
25 | |||
26 | |||
27 | #define GPIO_CS53x1_M_MASK 0x000c | ||
28 | #define GPIO_CS53x1_M_SINGLE 0x0000 | ||
29 | #define GPIO_CS53x1_M_DOUBLE 0x0004 | ||
30 | #define GPIO_CS53x1_M_QUAD 0x0008 | ||
31 | |||
32 | |||
33 | void xonar_enable_output(struct oxygen *chip) | ||
34 | { | ||
35 | struct xonar_generic *data = chip->model_data; | ||
36 | |||
37 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, data->output_enable_bit); | ||
38 | msleep(data->anti_pop_delay); | ||
39 | oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit); | ||
40 | } | ||
41 | |||
42 | void xonar_disable_output(struct oxygen *chip) | ||
43 | { | ||
44 | struct xonar_generic *data = chip->model_data; | ||
45 | |||
46 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit); | ||
47 | } | ||
48 | |||
49 | static void xonar_ext_power_gpio_changed(struct oxygen *chip) | ||
50 | { | ||
51 | struct xonar_generic *data = chip->model_data; | ||
52 | u8 has_power; | ||
53 | |||
54 | has_power = !!(oxygen_read8(chip, data->ext_power_reg) | ||
55 | & data->ext_power_bit); | ||
56 | if (has_power != data->has_power) { | ||
57 | data->has_power = has_power; | ||
58 | if (has_power) { | ||
59 | snd_printk(KERN_NOTICE "power restored\n"); | ||
60 | } else { | ||
61 | snd_printk(KERN_CRIT | ||
62 | "Hey! Don't unplug the power cable!\n"); | ||
63 | /* TODO: stop PCMs */ | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | |||
68 | void xonar_init_ext_power(struct oxygen *chip) | ||
69 | { | ||
70 | struct xonar_generic *data = chip->model_data; | ||
71 | |||
72 | oxygen_set_bits8(chip, data->ext_power_int_reg, | ||
73 | data->ext_power_bit); | ||
74 | chip->interrupt_mask |= OXYGEN_INT_GPIO; | ||
75 | chip->model.gpio_changed = xonar_ext_power_gpio_changed; | ||
76 | data->has_power = !!(oxygen_read8(chip, data->ext_power_reg) | ||
77 | & data->ext_power_bit); | ||
78 | } | ||
79 | |||
80 | void xonar_init_cs53x1(struct oxygen *chip) | ||
81 | { | ||
82 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_CS53x1_M_MASK); | ||
83 | oxygen_write16_masked(chip, OXYGEN_GPIO_DATA, | ||
84 | GPIO_CS53x1_M_SINGLE, GPIO_CS53x1_M_MASK); | ||
85 | } | ||
86 | |||
87 | void xonar_set_cs53x1_params(struct oxygen *chip, | ||
88 | struct snd_pcm_hw_params *params) | ||
89 | { | ||
90 | unsigned int value; | ||
91 | |||
92 | if (params_rate(params) <= 54000) | ||
93 | value = GPIO_CS53x1_M_SINGLE; | ||
94 | else if (params_rate(params) <= 108000) | ||
95 | value = GPIO_CS53x1_M_DOUBLE; | ||
96 | else | ||
97 | value = GPIO_CS53x1_M_QUAD; | ||
98 | oxygen_write16_masked(chip, OXYGEN_GPIO_DATA, | ||
99 | value, GPIO_CS53x1_M_MASK); | ||
100 | } | ||
101 | |||
102 | int xonar_gpio_bit_switch_get(struct snd_kcontrol *ctl, | ||
103 | struct snd_ctl_elem_value *value) | ||
104 | { | ||
105 | struct oxygen *chip = ctl->private_data; | ||
106 | u16 bit = ctl->private_value; | ||
107 | |||
108 | value->value.integer.value[0] = | ||
109 | !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & bit); | ||
110 | return 0; | ||
111 | } | ||
112 | |||
113 | int xonar_gpio_bit_switch_put(struct snd_kcontrol *ctl, | ||
114 | struct snd_ctl_elem_value *value) | ||
115 | { | ||
116 | struct oxygen *chip = ctl->private_data; | ||
117 | u16 bit = ctl->private_value; | ||
118 | u16 old_bits, new_bits; | ||
119 | int changed; | ||
120 | |||
121 | spin_lock_irq(&chip->reg_lock); | ||
122 | old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA); | ||
123 | if (value->value.integer.value[0]) | ||
124 | new_bits = old_bits | bit; | ||
125 | else | ||
126 | new_bits = old_bits & ~bit; | ||
127 | changed = new_bits != old_bits; | ||
128 | if (changed) | ||
129 | oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits); | ||
130 | spin_unlock_irq(&chip->reg_lock); | ||
131 | return changed; | ||
132 | } | ||
diff --git a/sound/pci/oxygen/xonar_pcm179x.c b/sound/pci/oxygen/xonar_pcm179x.c new file mode 100644 index 000000000000..ba18fb546b4f --- /dev/null +++ b/sound/pci/oxygen/xonar_pcm179x.c | |||
@@ -0,0 +1,1115 @@ | |||
1 | /* | ||
2 | * card driver for models with PCM1796 DACs (Xonar D2/D2X/HDAV1.3/ST/STX) | ||
3 | * | ||
4 | * Copyright (c) Clemens Ladisch <clemens@ladisch.de> | ||
5 | * | ||
6 | * | ||
7 | * This driver is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License, version 2. | ||
9 | * | ||
10 | * This driver is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this driver; if not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | /* | ||
20 | * Xonar D2/D2X | ||
21 | * ------------ | ||
22 | * | ||
23 | * CMI8788: | ||
24 | * | ||
25 | * SPI 0 -> 1st PCM1796 (front) | ||
26 | * SPI 1 -> 2nd PCM1796 (surround) | ||
27 | * SPI 2 -> 3rd PCM1796 (center/LFE) | ||
28 | * SPI 4 -> 4th PCM1796 (back) | ||
29 | * | ||
30 | * GPIO 2 -> M0 of CS5381 | ||
31 | * GPIO 3 -> M1 of CS5381 | ||
32 | * GPIO 5 <- external power present (D2X only) | ||
33 | * GPIO 7 -> ALT | ||
34 | * GPIO 8 -> enable output to speakers | ||
35 | * | ||
36 | * CM9780: | ||
37 | * | ||
38 | * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input | ||
39 | */ | ||
40 | |||
41 | /* | ||
42 | * Xonar HDAV1.3 (Deluxe) | ||
43 | * ---------------------- | ||
44 | * | ||
45 | * CMI8788: | ||
46 | * | ||
47 | * I²C <-> PCM1796 (front) | ||
48 | * | ||
49 | * GPI 0 <- external power present | ||
50 | * | ||
51 | * GPIO 0 -> enable output to speakers | ||
52 | * GPIO 2 -> M0 of CS5381 | ||
53 | * GPIO 3 -> M1 of CS5381 | ||
54 | * GPIO 8 -> route input jack to line-in (0) or mic-in (1) | ||
55 | * | ||
56 | * TXD -> HDMI controller | ||
57 | * RXD <- HDMI controller | ||
58 | * | ||
59 | * PCM1796 front: AD1,0 <- 0,0 | ||
60 | * | ||
61 | * CM9780: | ||
62 | * | ||
63 | * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input | ||
64 | * | ||
65 | * no daughterboard | ||
66 | * ---------------- | ||
67 | * | ||
68 | * GPIO 4 <- 1 | ||
69 | * | ||
70 | * H6 daughterboard | ||
71 | * ---------------- | ||
72 | * | ||
73 | * GPIO 4 <- 0 | ||
74 | * GPIO 5 <- 0 | ||
75 | * | ||
76 | * I²C <-> PCM1796 (surround) | ||
77 | * <-> PCM1796 (center/LFE) | ||
78 | * <-> PCM1796 (back) | ||
79 | * | ||
80 | * PCM1796 surround: AD1,0 <- 0,1 | ||
81 | * PCM1796 center/LFE: AD1,0 <- 1,0 | ||
82 | * PCM1796 back: AD1,0 <- 1,1 | ||
83 | * | ||
84 | * unknown daughterboard | ||
85 | * --------------------- | ||
86 | * | ||
87 | * GPIO 4 <- 0 | ||
88 | * GPIO 5 <- 1 | ||
89 | * | ||
90 | * I²C <-> CS4362A (surround, center/LFE, back) | ||
91 | * | ||
92 | * CS4362A: AD0 <- 0 | ||
93 | */ | ||
94 | |||
95 | /* | ||
96 | * Xonar Essence ST (Deluxe)/STX | ||
97 | * ----------------------------- | ||
98 | * | ||
99 | * CMI8788: | ||
100 | * | ||
101 | * I²C <-> PCM1792A | ||
102 | * <-> CS2000 (ST only) | ||
103 | * | ||
104 | * ADC1 MCLK -> REF_CLK of CS2000 (ST only) | ||
105 | * | ||
106 | * GPI 0 <- external power present (STX only) | ||
107 | * | ||
108 | * GPIO 0 -> enable output to speakers | ||
109 | * GPIO 1 -> route HP to front panel (0) or rear jack (1) | ||
110 | * GPIO 2 -> M0 of CS5381 | ||
111 | * GPIO 3 -> M1 of CS5381 | ||
112 | * GPIO 7 -> route output to speaker jacks (0) or HP (1) | ||
113 | * GPIO 8 -> route input jack to line-in (0) or mic-in (1) | ||
114 | * | ||
115 | * PCM1792A: | ||
116 | * | ||
117 | * AD1,0 <- 0,0 | ||
118 | * SCK <- CLK_OUT of CS2000 (ST only) | ||
119 | * | ||
120 | * CS2000: | ||
121 | * | ||
122 | * AD0 <- 0 | ||
123 | * | ||
124 | * CM9780: | ||
125 | * | ||
126 | * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input | ||
127 | * | ||
128 | * H6 daughterboard | ||
129 | * ---------------- | ||
130 | * | ||
131 | * GPIO 4 <- 0 | ||
132 | * GPIO 5 <- 0 | ||
133 | */ | ||
134 | |||
135 | #include <linux/pci.h> | ||
136 | #include <linux/delay.h> | ||
137 | #include <linux/mutex.h> | ||
138 | #include <sound/ac97_codec.h> | ||
139 | #include <sound/control.h> | ||
140 | #include <sound/core.h> | ||
141 | #include <sound/pcm.h> | ||
142 | #include <sound/pcm_params.h> | ||
143 | #include <sound/tlv.h> | ||
144 | #include "xonar.h" | ||
145 | #include "cm9780.h" | ||
146 | #include "pcm1796.h" | ||
147 | #include "cs2000.h" | ||
148 | |||
149 | |||
150 | #define GPIO_D2X_EXT_POWER 0x0020 | ||
151 | #define GPIO_D2_ALT 0x0080 | ||
152 | #define GPIO_D2_OUTPUT_ENABLE 0x0100 | ||
153 | |||
154 | #define GPI_EXT_POWER 0x01 | ||
155 | #define GPIO_INPUT_ROUTE 0x0100 | ||
156 | |||
157 | #define GPIO_HDAV_OUTPUT_ENABLE 0x0001 | ||
158 | |||
159 | #define GPIO_DB_MASK 0x0030 | ||
160 | #define GPIO_DB_H6 0x0000 | ||
161 | |||
162 | #define GPIO_ST_OUTPUT_ENABLE 0x0001 | ||
163 | #define GPIO_ST_HP_REAR 0x0002 | ||
164 | #define GPIO_ST_HP 0x0080 | ||
165 | |||
166 | #define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ii, /W=0 */ | ||
167 | #define I2C_DEVICE_CS2000 0x9c /* 100111, 0, /W=0 */ | ||
168 | |||
169 | #define PCM1796_REG_BASE 16 | ||
170 | |||
171 | |||
172 | struct xonar_pcm179x { | ||
173 | struct xonar_generic generic; | ||
174 | unsigned int dacs; | ||
175 | u8 pcm1796_regs[4][5]; | ||
176 | unsigned int current_rate; | ||
177 | bool os_128; | ||
178 | bool hp_active; | ||
179 | s8 hp_gain_offset; | ||
180 | bool has_cs2000; | ||
181 | u8 cs2000_fun_cfg_1; | ||
182 | }; | ||
183 | |||
184 | struct xonar_hdav { | ||
185 | struct xonar_pcm179x pcm179x; | ||
186 | struct xonar_hdmi hdmi; | ||
187 | }; | ||
188 | |||
189 | |||
190 | static inline void pcm1796_write_spi(struct oxygen *chip, unsigned int codec, | ||
191 | u8 reg, u8 value) | ||
192 | { | ||
193 | /* maps ALSA channel pair number to SPI output */ | ||
194 | static const u8 codec_map[4] = { | ||
195 | 0, 1, 2, 4 | ||
196 | }; | ||
197 | oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER | | ||
198 | OXYGEN_SPI_DATA_LENGTH_2 | | ||
199 | OXYGEN_SPI_CLOCK_160 | | ||
200 | (codec_map[codec] << OXYGEN_SPI_CODEC_SHIFT) | | ||
201 | OXYGEN_SPI_CEN_LATCH_CLOCK_HI, | ||
202 | (reg << 8) | value); | ||
203 | } | ||
204 | |||
205 | static inline void pcm1796_write_i2c(struct oxygen *chip, unsigned int codec, | ||
206 | u8 reg, u8 value) | ||
207 | { | ||
208 | oxygen_write_i2c(chip, I2C_DEVICE_PCM1796(codec), reg, value); | ||
209 | } | ||
210 | |||
211 | static void pcm1796_write(struct oxygen *chip, unsigned int codec, | ||
212 | u8 reg, u8 value) | ||
213 | { | ||
214 | struct xonar_pcm179x *data = chip->model_data; | ||
215 | |||
216 | if ((chip->model.function_flags & OXYGEN_FUNCTION_2WIRE_SPI_MASK) == | ||
217 | OXYGEN_FUNCTION_SPI) | ||
218 | pcm1796_write_spi(chip, codec, reg, value); | ||
219 | else | ||
220 | pcm1796_write_i2c(chip, codec, reg, value); | ||
221 | if ((unsigned int)(reg - PCM1796_REG_BASE) | ||
222 | < ARRAY_SIZE(data->pcm1796_regs[codec])) | ||
223 | data->pcm1796_regs[codec][reg - PCM1796_REG_BASE] = value; | ||
224 | } | ||
225 | |||
226 | static void pcm1796_write_cached(struct oxygen *chip, unsigned int codec, | ||
227 | u8 reg, u8 value) | ||
228 | { | ||
229 | struct xonar_pcm179x *data = chip->model_data; | ||
230 | |||
231 | if (value != data->pcm1796_regs[codec][reg - PCM1796_REG_BASE]) | ||
232 | pcm1796_write(chip, codec, reg, value); | ||
233 | } | ||
234 | |||
235 | static void cs2000_write(struct oxygen *chip, u8 reg, u8 value) | ||
236 | { | ||
237 | struct xonar_pcm179x *data = chip->model_data; | ||
238 | |||
239 | oxygen_write_i2c(chip, I2C_DEVICE_CS2000, reg, value); | ||
240 | if (reg == CS2000_FUN_CFG_1) | ||
241 | data->cs2000_fun_cfg_1 = value; | ||
242 | } | ||
243 | |||
244 | static void cs2000_write_cached(struct oxygen *chip, u8 reg, u8 value) | ||
245 | { | ||
246 | struct xonar_pcm179x *data = chip->model_data; | ||
247 | |||
248 | if (reg != CS2000_FUN_CFG_1 || | ||
249 | value != data->cs2000_fun_cfg_1) | ||
250 | cs2000_write(chip, reg, value); | ||
251 | } | ||
252 | |||
253 | static void pcm1796_registers_init(struct oxygen *chip) | ||
254 | { | ||
255 | struct xonar_pcm179x *data = chip->model_data; | ||
256 | unsigned int i; | ||
257 | s8 gain_offset; | ||
258 | |||
259 | gain_offset = data->hp_active ? data->hp_gain_offset : 0; | ||
260 | for (i = 0; i < data->dacs; ++i) { | ||
261 | /* set ATLD before ATL/ATR */ | ||
262 | pcm1796_write(chip, i, 18, | ||
263 | data->pcm1796_regs[0][18 - PCM1796_REG_BASE]); | ||
264 | pcm1796_write(chip, i, 16, chip->dac_volume[i * 2] | ||
265 | + gain_offset); | ||
266 | pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1] | ||
267 | + gain_offset); | ||
268 | pcm1796_write(chip, i, 19, | ||
269 | data->pcm1796_regs[0][19 - PCM1796_REG_BASE]); | ||
270 | pcm1796_write(chip, i, 20, | ||
271 | data->pcm1796_regs[0][20 - PCM1796_REG_BASE]); | ||
272 | pcm1796_write(chip, i, 21, 0); | ||
273 | } | ||
274 | } | ||
275 | |||
276 | static void pcm1796_init(struct oxygen *chip) | ||
277 | { | ||
278 | struct xonar_pcm179x *data = chip->model_data; | ||
279 | |||
280 | data->pcm1796_regs[0][18 - PCM1796_REG_BASE] = PCM1796_MUTE | | ||
281 | PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD; | ||
282 | data->pcm1796_regs[0][19 - PCM1796_REG_BASE] = | ||
283 | PCM1796_FLT_SHARP | PCM1796_ATS_1; | ||
284 | data->pcm1796_regs[0][20 - PCM1796_REG_BASE] = PCM1796_OS_64; | ||
285 | pcm1796_registers_init(chip); | ||
286 | data->current_rate = 48000; | ||
287 | } | ||
288 | |||
289 | static void xonar_d2_init(struct oxygen *chip) | ||
290 | { | ||
291 | struct xonar_pcm179x *data = chip->model_data; | ||
292 | |||
293 | data->generic.anti_pop_delay = 300; | ||
294 | data->generic.output_enable_bit = GPIO_D2_OUTPUT_ENABLE; | ||
295 | data->dacs = 4; | ||
296 | |||
297 | pcm1796_init(chip); | ||
298 | |||
299 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT); | ||
300 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT); | ||
301 | |||
302 | oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC); | ||
303 | |||
304 | xonar_init_cs53x1(chip); | ||
305 | xonar_enable_output(chip); | ||
306 | |||
307 | snd_component_add(chip->card, "PCM1796"); | ||
308 | snd_component_add(chip->card, "CS5381"); | ||
309 | } | ||
310 | |||
311 | static void xonar_d2x_init(struct oxygen *chip) | ||
312 | { | ||
313 | struct xonar_pcm179x *data = chip->model_data; | ||
314 | |||
315 | data->generic.ext_power_reg = OXYGEN_GPIO_DATA; | ||
316 | data->generic.ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK; | ||
317 | data->generic.ext_power_bit = GPIO_D2X_EXT_POWER; | ||
318 | oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER); | ||
319 | xonar_init_ext_power(chip); | ||
320 | xonar_d2_init(chip); | ||
321 | } | ||
322 | |||
323 | static void xonar_hdav_init(struct oxygen *chip) | ||
324 | { | ||
325 | struct xonar_hdav *data = chip->model_data; | ||
326 | |||
327 | oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS, | ||
328 | OXYGEN_2WIRE_LENGTH_8 | | ||
329 | OXYGEN_2WIRE_INTERRUPT_MASK | | ||
330 | OXYGEN_2WIRE_SPEED_FAST); | ||
331 | |||
332 | data->pcm179x.generic.anti_pop_delay = 100; | ||
333 | data->pcm179x.generic.output_enable_bit = GPIO_HDAV_OUTPUT_ENABLE; | ||
334 | data->pcm179x.generic.ext_power_reg = OXYGEN_GPI_DATA; | ||
335 | data->pcm179x.generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK; | ||
336 | data->pcm179x.generic.ext_power_bit = GPI_EXT_POWER; | ||
337 | data->pcm179x.dacs = chip->model.private_data ? 4 : 1; | ||
338 | |||
339 | pcm1796_init(chip); | ||
340 | |||
341 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_INPUT_ROUTE); | ||
342 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_INPUT_ROUTE); | ||
343 | |||
344 | xonar_init_cs53x1(chip); | ||
345 | xonar_init_ext_power(chip); | ||
346 | xonar_hdmi_init(chip, &data->hdmi); | ||
347 | xonar_enable_output(chip); | ||
348 | |||
349 | snd_component_add(chip->card, "PCM1796"); | ||
350 | snd_component_add(chip->card, "CS5381"); | ||
351 | } | ||
352 | |||
353 | static void xonar_st_init_i2c(struct oxygen *chip) | ||
354 | { | ||
355 | oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS, | ||
356 | OXYGEN_2WIRE_LENGTH_8 | | ||
357 | OXYGEN_2WIRE_INTERRUPT_MASK | | ||
358 | OXYGEN_2WIRE_SPEED_FAST); | ||
359 | } | ||
360 | |||
361 | static void xonar_st_init_common(struct oxygen *chip) | ||
362 | { | ||
363 | struct xonar_pcm179x *data = chip->model_data; | ||
364 | |||
365 | data->generic.anti_pop_delay = 100; | ||
366 | data->generic.output_enable_bit = GPIO_ST_OUTPUT_ENABLE; | ||
367 | data->dacs = chip->model.private_data ? 4 : 1; | ||
368 | data->hp_gain_offset = 2*-18; | ||
369 | |||
370 | pcm1796_init(chip); | ||
371 | |||
372 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, | ||
373 | GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP); | ||
374 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, | ||
375 | GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP); | ||
376 | |||
377 | xonar_init_cs53x1(chip); | ||
378 | xonar_enable_output(chip); | ||
379 | |||
380 | snd_component_add(chip->card, "PCM1792A"); | ||
381 | snd_component_add(chip->card, "CS5381"); | ||
382 | } | ||
383 | |||
384 | static void cs2000_registers_init(struct oxygen *chip) | ||
385 | { | ||
386 | struct xonar_pcm179x *data = chip->model_data; | ||
387 | |||
388 | cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_FREEZE); | ||
389 | cs2000_write(chip, CS2000_DEV_CTRL, 0); | ||
390 | cs2000_write(chip, CS2000_DEV_CFG_1, | ||
391 | CS2000_R_MOD_SEL_1 | | ||
392 | (0 << CS2000_R_SEL_SHIFT) | | ||
393 | CS2000_AUX_OUT_SRC_REF_CLK | | ||
394 | CS2000_EN_DEV_CFG_1); | ||
395 | cs2000_write(chip, CS2000_DEV_CFG_2, | ||
396 | (0 << CS2000_LOCK_CLK_SHIFT) | | ||
397 | CS2000_FRAC_N_SRC_STATIC); | ||
398 | cs2000_write(chip, CS2000_RATIO_0 + 0, 0x00); /* 1.0 */ | ||
399 | cs2000_write(chip, CS2000_RATIO_0 + 1, 0x10); | ||
400 | cs2000_write(chip, CS2000_RATIO_0 + 2, 0x00); | ||
401 | cs2000_write(chip, CS2000_RATIO_0 + 3, 0x00); | ||
402 | cs2000_write(chip, CS2000_FUN_CFG_1, data->cs2000_fun_cfg_1); | ||
403 | cs2000_write(chip, CS2000_FUN_CFG_2, 0); | ||
404 | cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_EN_DEV_CFG_2); | ||
405 | } | ||
406 | |||
407 | static void xonar_st_init(struct oxygen *chip) | ||
408 | { | ||
409 | struct xonar_pcm179x *data = chip->model_data; | ||
410 | |||
411 | data->has_cs2000 = 1; | ||
412 | data->cs2000_fun_cfg_1 = CS2000_REF_CLK_DIV_1; | ||
413 | |||
414 | oxygen_write16(chip, OXYGEN_I2S_A_FORMAT, | ||
415 | OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_I2S | | ||
416 | OXYGEN_I2S_MCLK_128 | OXYGEN_I2S_BITS_16 | | ||
417 | OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64); | ||
418 | |||
419 | xonar_st_init_i2c(chip); | ||
420 | cs2000_registers_init(chip); | ||
421 | xonar_st_init_common(chip); | ||
422 | |||
423 | snd_component_add(chip->card, "CS2000"); | ||
424 | } | ||
425 | |||
426 | static void xonar_stx_init(struct oxygen *chip) | ||
427 | { | ||
428 | struct xonar_pcm179x *data = chip->model_data; | ||
429 | |||
430 | xonar_st_init_i2c(chip); | ||
431 | data->generic.ext_power_reg = OXYGEN_GPI_DATA; | ||
432 | data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK; | ||
433 | data->generic.ext_power_bit = GPI_EXT_POWER; | ||
434 | xonar_init_ext_power(chip); | ||
435 | xonar_st_init_common(chip); | ||
436 | } | ||
437 | |||
438 | static void xonar_d2_cleanup(struct oxygen *chip) | ||
439 | { | ||
440 | xonar_disable_output(chip); | ||
441 | } | ||
442 | |||
443 | static void xonar_hdav_cleanup(struct oxygen *chip) | ||
444 | { | ||
445 | xonar_hdmi_cleanup(chip); | ||
446 | xonar_disable_output(chip); | ||
447 | msleep(2); | ||
448 | } | ||
449 | |||
450 | static void xonar_st_cleanup(struct oxygen *chip) | ||
451 | { | ||
452 | xonar_disable_output(chip); | ||
453 | } | ||
454 | |||
455 | static void xonar_d2_suspend(struct oxygen *chip) | ||
456 | { | ||
457 | xonar_d2_cleanup(chip); | ||
458 | } | ||
459 | |||
460 | static void xonar_hdav_suspend(struct oxygen *chip) | ||
461 | { | ||
462 | xonar_hdav_cleanup(chip); | ||
463 | } | ||
464 | |||
465 | static void xonar_st_suspend(struct oxygen *chip) | ||
466 | { | ||
467 | xonar_st_cleanup(chip); | ||
468 | } | ||
469 | |||
470 | static void xonar_d2_resume(struct oxygen *chip) | ||
471 | { | ||
472 | pcm1796_registers_init(chip); | ||
473 | xonar_enable_output(chip); | ||
474 | } | ||
475 | |||
476 | static void xonar_hdav_resume(struct oxygen *chip) | ||
477 | { | ||
478 | struct xonar_hdav *data = chip->model_data; | ||
479 | |||
480 | pcm1796_registers_init(chip); | ||
481 | xonar_hdmi_resume(chip, &data->hdmi); | ||
482 | xonar_enable_output(chip); | ||
483 | } | ||
484 | |||
485 | static void xonar_stx_resume(struct oxygen *chip) | ||
486 | { | ||
487 | pcm1796_registers_init(chip); | ||
488 | xonar_enable_output(chip); | ||
489 | } | ||
490 | |||
491 | static void xonar_st_resume(struct oxygen *chip) | ||
492 | { | ||
493 | cs2000_registers_init(chip); | ||
494 | xonar_stx_resume(chip); | ||
495 | } | ||
496 | |||
497 | static unsigned int mclk_from_rate(struct oxygen *chip, unsigned int rate) | ||
498 | { | ||
499 | struct xonar_pcm179x *data = chip->model_data; | ||
500 | |||
501 | if (rate <= 32000) | ||
502 | return OXYGEN_I2S_MCLK_512; | ||
503 | else if (rate <= 48000 && data->os_128) | ||
504 | return OXYGEN_I2S_MCLK_512; | ||
505 | else if (rate <= 96000) | ||
506 | return OXYGEN_I2S_MCLK_256; | ||
507 | else | ||
508 | return OXYGEN_I2S_MCLK_128; | ||
509 | } | ||
510 | |||
511 | static unsigned int get_pcm1796_i2s_mclk(struct oxygen *chip, | ||
512 | unsigned int channel, | ||
513 | struct snd_pcm_hw_params *params) | ||
514 | { | ||
515 | if (channel == PCM_MULTICH) | ||
516 | return mclk_from_rate(chip, params_rate(params)); | ||
517 | else | ||
518 | return oxygen_default_i2s_mclk(chip, channel, params); | ||
519 | } | ||
520 | |||
521 | static void update_pcm1796_oversampling(struct oxygen *chip) | ||
522 | { | ||
523 | struct xonar_pcm179x *data = chip->model_data; | ||
524 | unsigned int i; | ||
525 | u8 reg; | ||
526 | |||
527 | if (data->current_rate <= 32000) | ||
528 | reg = PCM1796_OS_128; | ||
529 | else if (data->current_rate <= 48000 && data->os_128) | ||
530 | reg = PCM1796_OS_128; | ||
531 | else if (data->current_rate <= 96000 || data->os_128) | ||
532 | reg = PCM1796_OS_64; | ||
533 | else | ||
534 | reg = PCM1796_OS_32; | ||
535 | for (i = 0; i < data->dacs; ++i) | ||
536 | pcm1796_write_cached(chip, i, 20, reg); | ||
537 | } | ||
538 | |||
539 | static void set_pcm1796_params(struct oxygen *chip, | ||
540 | struct snd_pcm_hw_params *params) | ||
541 | { | ||
542 | struct xonar_pcm179x *data = chip->model_data; | ||
543 | |||
544 | data->current_rate = params_rate(params); | ||
545 | update_pcm1796_oversampling(chip); | ||
546 | } | ||
547 | |||
548 | static void update_pcm1796_volume(struct oxygen *chip) | ||
549 | { | ||
550 | struct xonar_pcm179x *data = chip->model_data; | ||
551 | unsigned int i; | ||
552 | s8 gain_offset; | ||
553 | |||
554 | gain_offset = data->hp_active ? data->hp_gain_offset : 0; | ||
555 | for (i = 0; i < data->dacs; ++i) { | ||
556 | pcm1796_write_cached(chip, i, 16, chip->dac_volume[i * 2] | ||
557 | + gain_offset); | ||
558 | pcm1796_write_cached(chip, i, 17, chip->dac_volume[i * 2 + 1] | ||
559 | + gain_offset); | ||
560 | } | ||
561 | } | ||
562 | |||
563 | static void update_pcm1796_mute(struct oxygen *chip) | ||
564 | { | ||
565 | struct xonar_pcm179x *data = chip->model_data; | ||
566 | unsigned int i; | ||
567 | u8 value; | ||
568 | |||
569 | value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD; | ||
570 | if (chip->dac_mute) | ||
571 | value |= PCM1796_MUTE; | ||
572 | for (i = 0; i < data->dacs; ++i) | ||
573 | pcm1796_write_cached(chip, i, 18, value); | ||
574 | } | ||
575 | |||
576 | static void update_cs2000_rate(struct oxygen *chip, unsigned int rate) | ||
577 | { | ||
578 | struct xonar_pcm179x *data = chip->model_data; | ||
579 | u8 rate_mclk, reg; | ||
580 | |||
581 | switch (rate) { | ||
582 | /* XXX Why is the I2S A MCLK half the actual I2S MCLK? */ | ||
583 | case 32000: | ||
584 | rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_256; | ||
585 | break; | ||
586 | case 44100: | ||
587 | if (data->os_128) | ||
588 | rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256; | ||
589 | else | ||
590 | rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_128; | ||
591 | break; | ||
592 | default: /* 48000 */ | ||
593 | if (data->os_128) | ||
594 | rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256; | ||
595 | else | ||
596 | rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_128; | ||
597 | break; | ||
598 | case 64000: | ||
599 | rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_256; | ||
600 | break; | ||
601 | case 88200: | ||
602 | rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256; | ||
603 | break; | ||
604 | case 96000: | ||
605 | rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256; | ||
606 | break; | ||
607 | case 176400: | ||
608 | rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256; | ||
609 | break; | ||
610 | case 192000: | ||
611 | rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256; | ||
612 | break; | ||
613 | } | ||
614 | oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, rate_mclk, | ||
615 | OXYGEN_I2S_RATE_MASK | OXYGEN_I2S_MCLK_MASK); | ||
616 | if ((rate_mclk & OXYGEN_I2S_MCLK_MASK) <= OXYGEN_I2S_MCLK_128) | ||
617 | reg = CS2000_REF_CLK_DIV_1; | ||
618 | else | ||
619 | reg = CS2000_REF_CLK_DIV_2; | ||
620 | cs2000_write_cached(chip, CS2000_FUN_CFG_1, reg); | ||
621 | } | ||
622 | |||
623 | static void set_st_params(struct oxygen *chip, | ||
624 | struct snd_pcm_hw_params *params) | ||
625 | { | ||
626 | update_cs2000_rate(chip, params_rate(params)); | ||
627 | set_pcm1796_params(chip, params); | ||
628 | } | ||
629 | |||
630 | static void set_hdav_params(struct oxygen *chip, | ||
631 | struct snd_pcm_hw_params *params) | ||
632 | { | ||
633 | struct xonar_hdav *data = chip->model_data; | ||
634 | |||
635 | set_pcm1796_params(chip, params); | ||
636 | xonar_set_hdmi_params(chip, &data->hdmi, params); | ||
637 | } | ||
638 | |||
639 | static const struct snd_kcontrol_new alt_switch = { | ||
640 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
641 | .name = "Analog Loopback Switch", | ||
642 | .info = snd_ctl_boolean_mono_info, | ||
643 | .get = xonar_gpio_bit_switch_get, | ||
644 | .put = xonar_gpio_bit_switch_put, | ||
645 | .private_value = GPIO_D2_ALT, | ||
646 | }; | ||
647 | |||
648 | static int rolloff_info(struct snd_kcontrol *ctl, | ||
649 | struct snd_ctl_elem_info *info) | ||
650 | { | ||
651 | static const char *const names[2] = { | ||
652 | "Sharp Roll-off", "Slow Roll-off" | ||
653 | }; | ||
654 | |||
655 | info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | ||
656 | info->count = 1; | ||
657 | info->value.enumerated.items = 2; | ||
658 | if (info->value.enumerated.item >= 2) | ||
659 | info->value.enumerated.item = 1; | ||
660 | strcpy(info->value.enumerated.name, names[info->value.enumerated.item]); | ||
661 | return 0; | ||
662 | } | ||
663 | |||
664 | static int rolloff_get(struct snd_kcontrol *ctl, | ||
665 | struct snd_ctl_elem_value *value) | ||
666 | { | ||
667 | struct oxygen *chip = ctl->private_data; | ||
668 | struct xonar_pcm179x *data = chip->model_data; | ||
669 | |||
670 | value->value.enumerated.item[0] = | ||
671 | (data->pcm1796_regs[0][19 - PCM1796_REG_BASE] & | ||
672 | PCM1796_FLT_MASK) != PCM1796_FLT_SHARP; | ||
673 | return 0; | ||
674 | } | ||
675 | |||
676 | static int rolloff_put(struct snd_kcontrol *ctl, | ||
677 | struct snd_ctl_elem_value *value) | ||
678 | { | ||
679 | struct oxygen *chip = ctl->private_data; | ||
680 | struct xonar_pcm179x *data = chip->model_data; | ||
681 | unsigned int i; | ||
682 | int changed; | ||
683 | u8 reg; | ||
684 | |||
685 | mutex_lock(&chip->mutex); | ||
686 | reg = data->pcm1796_regs[0][19 - PCM1796_REG_BASE]; | ||
687 | reg &= ~PCM1796_FLT_MASK; | ||
688 | if (!value->value.enumerated.item[0]) | ||
689 | reg |= PCM1796_FLT_SHARP; | ||
690 | else | ||
691 | reg |= PCM1796_FLT_SLOW; | ||
692 | changed = reg != data->pcm1796_regs[0][19 - PCM1796_REG_BASE]; | ||
693 | if (changed) { | ||
694 | for (i = 0; i < data->dacs; ++i) | ||
695 | pcm1796_write(chip, i, 19, reg); | ||
696 | } | ||
697 | mutex_unlock(&chip->mutex); | ||
698 | return changed; | ||
699 | } | ||
700 | |||
701 | static const struct snd_kcontrol_new rolloff_control = { | ||
702 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
703 | .name = "DAC Filter Playback Enum", | ||
704 | .info = rolloff_info, | ||
705 | .get = rolloff_get, | ||
706 | .put = rolloff_put, | ||
707 | }; | ||
708 | |||
709 | static int os_128_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info) | ||
710 | { | ||
711 | static const char *const names[2] = { "64x", "128x" }; | ||
712 | |||
713 | info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | ||
714 | info->count = 1; | ||
715 | info->value.enumerated.items = 2; | ||
716 | if (info->value.enumerated.item >= 2) | ||
717 | info->value.enumerated.item = 1; | ||
718 | strcpy(info->value.enumerated.name, names[info->value.enumerated.item]); | ||
719 | return 0; | ||
720 | } | ||
721 | |||
722 | static int os_128_get(struct snd_kcontrol *ctl, | ||
723 | struct snd_ctl_elem_value *value) | ||
724 | { | ||
725 | struct oxygen *chip = ctl->private_data; | ||
726 | struct xonar_pcm179x *data = chip->model_data; | ||
727 | |||
728 | value->value.enumerated.item[0] = data->os_128; | ||
729 | return 0; | ||
730 | } | ||
731 | |||
732 | static int os_128_put(struct snd_kcontrol *ctl, | ||
733 | struct snd_ctl_elem_value *value) | ||
734 | { | ||
735 | struct oxygen *chip = ctl->private_data; | ||
736 | struct xonar_pcm179x *data = chip->model_data; | ||
737 | int changed; | ||
738 | |||
739 | mutex_lock(&chip->mutex); | ||
740 | changed = value->value.enumerated.item[0] != data->os_128; | ||
741 | if (changed) { | ||
742 | data->os_128 = value->value.enumerated.item[0]; | ||
743 | if (data->has_cs2000) | ||
744 | update_cs2000_rate(chip, data->current_rate); | ||
745 | oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT, | ||
746 | mclk_from_rate(chip, data->current_rate), | ||
747 | OXYGEN_I2S_MCLK_MASK); | ||
748 | update_pcm1796_oversampling(chip); | ||
749 | } | ||
750 | mutex_unlock(&chip->mutex); | ||
751 | return changed; | ||
752 | } | ||
753 | |||
754 | static const struct snd_kcontrol_new os_128_control = { | ||
755 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
756 | .name = "DAC Oversampling Playback Enum", | ||
757 | .info = os_128_info, | ||
758 | .get = os_128_get, | ||
759 | .put = os_128_put, | ||
760 | }; | ||
761 | |||
762 | static int st_output_switch_info(struct snd_kcontrol *ctl, | ||
763 | struct snd_ctl_elem_info *info) | ||
764 | { | ||
765 | static const char *const names[3] = { | ||
766 | "Speakers", "Headphones", "FP Headphones" | ||
767 | }; | ||
768 | |||
769 | info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | ||
770 | info->count = 1; | ||
771 | info->value.enumerated.items = 3; | ||
772 | if (info->value.enumerated.item >= 3) | ||
773 | info->value.enumerated.item = 2; | ||
774 | strcpy(info->value.enumerated.name, names[info->value.enumerated.item]); | ||
775 | return 0; | ||
776 | } | ||
777 | |||
778 | static int st_output_switch_get(struct snd_kcontrol *ctl, | ||
779 | struct snd_ctl_elem_value *value) | ||
780 | { | ||
781 | struct oxygen *chip = ctl->private_data; | ||
782 | u16 gpio; | ||
783 | |||
784 | gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA); | ||
785 | if (!(gpio & GPIO_ST_HP)) | ||
786 | value->value.enumerated.item[0] = 0; | ||
787 | else if (gpio & GPIO_ST_HP_REAR) | ||
788 | value->value.enumerated.item[0] = 1; | ||
789 | else | ||
790 | value->value.enumerated.item[0] = 2; | ||
791 | return 0; | ||
792 | } | ||
793 | |||
794 | |||
795 | static int st_output_switch_put(struct snd_kcontrol *ctl, | ||
796 | struct snd_ctl_elem_value *value) | ||
797 | { | ||
798 | struct oxygen *chip = ctl->private_data; | ||
799 | struct xonar_pcm179x *data = chip->model_data; | ||
800 | u16 gpio_old, gpio; | ||
801 | |||
802 | mutex_lock(&chip->mutex); | ||
803 | gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA); | ||
804 | gpio = gpio_old; | ||
805 | switch (value->value.enumerated.item[0]) { | ||
806 | case 0: | ||
807 | gpio &= ~(GPIO_ST_HP | GPIO_ST_HP_REAR); | ||
808 | break; | ||
809 | case 1: | ||
810 | gpio |= GPIO_ST_HP | GPIO_ST_HP_REAR; | ||
811 | break; | ||
812 | case 2: | ||
813 | gpio = (gpio | GPIO_ST_HP) & ~GPIO_ST_HP_REAR; | ||
814 | break; | ||
815 | } | ||
816 | oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio); | ||
817 | data->hp_active = gpio & GPIO_ST_HP; | ||
818 | update_pcm1796_volume(chip); | ||
819 | mutex_unlock(&chip->mutex); | ||
820 | return gpio != gpio_old; | ||
821 | } | ||
822 | |||
823 | static int st_hp_volume_offset_info(struct snd_kcontrol *ctl, | ||
824 | struct snd_ctl_elem_info *info) | ||
825 | { | ||
826 | static const char *const names[3] = { | ||
827 | "< 64 ohms", "64-300 ohms", "300-600 ohms" | ||
828 | }; | ||
829 | |||
830 | info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | ||
831 | info->count = 1; | ||
832 | info->value.enumerated.items = 3; | ||
833 | if (info->value.enumerated.item > 2) | ||
834 | info->value.enumerated.item = 2; | ||
835 | strcpy(info->value.enumerated.name, names[info->value.enumerated.item]); | ||
836 | return 0; | ||
837 | } | ||
838 | |||
839 | static int st_hp_volume_offset_get(struct snd_kcontrol *ctl, | ||
840 | struct snd_ctl_elem_value *value) | ||
841 | { | ||
842 | struct oxygen *chip = ctl->private_data; | ||
843 | struct xonar_pcm179x *data = chip->model_data; | ||
844 | |||
845 | mutex_lock(&chip->mutex); | ||
846 | if (data->hp_gain_offset < 2*-6) | ||
847 | value->value.enumerated.item[0] = 0; | ||
848 | else if (data->hp_gain_offset < 0) | ||
849 | value->value.enumerated.item[0] = 1; | ||
850 | else | ||
851 | value->value.enumerated.item[0] = 2; | ||
852 | mutex_unlock(&chip->mutex); | ||
853 | return 0; | ||
854 | } | ||
855 | |||
856 | |||
857 | static int st_hp_volume_offset_put(struct snd_kcontrol *ctl, | ||
858 | struct snd_ctl_elem_value *value) | ||
859 | { | ||
860 | static const s8 offsets[] = { 2*-18, 2*-6, 0 }; | ||
861 | struct oxygen *chip = ctl->private_data; | ||
862 | struct xonar_pcm179x *data = chip->model_data; | ||
863 | s8 offset; | ||
864 | int changed; | ||
865 | |||
866 | if (value->value.enumerated.item[0] > 2) | ||
867 | return -EINVAL; | ||
868 | offset = offsets[value->value.enumerated.item[0]]; | ||
869 | mutex_lock(&chip->mutex); | ||
870 | changed = offset != data->hp_gain_offset; | ||
871 | if (changed) { | ||
872 | data->hp_gain_offset = offset; | ||
873 | update_pcm1796_volume(chip); | ||
874 | } | ||
875 | mutex_unlock(&chip->mutex); | ||
876 | return changed; | ||
877 | } | ||
878 | |||
879 | static const struct snd_kcontrol_new st_controls[] = { | ||
880 | { | ||
881 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
882 | .name = "Analog Output", | ||
883 | .info = st_output_switch_info, | ||
884 | .get = st_output_switch_get, | ||
885 | .put = st_output_switch_put, | ||
886 | }, | ||
887 | { | ||
888 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
889 | .name = "Headphones Impedance Playback Enum", | ||
890 | .info = st_hp_volume_offset_info, | ||
891 | .get = st_hp_volume_offset_get, | ||
892 | .put = st_hp_volume_offset_put, | ||
893 | }, | ||
894 | }; | ||
895 | |||
896 | static void xonar_line_mic_ac97_switch(struct oxygen *chip, | ||
897 | unsigned int reg, unsigned int mute) | ||
898 | { | ||
899 | if (reg == AC97_LINE) { | ||
900 | spin_lock_irq(&chip->reg_lock); | ||
901 | oxygen_write16_masked(chip, OXYGEN_GPIO_DATA, | ||
902 | mute ? GPIO_INPUT_ROUTE : 0, | ||
903 | GPIO_INPUT_ROUTE); | ||
904 | spin_unlock_irq(&chip->reg_lock); | ||
905 | } | ||
906 | } | ||
907 | |||
908 | static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -6000, 50, 0); | ||
909 | |||
910 | static int xonar_d2_control_filter(struct snd_kcontrol_new *template) | ||
911 | { | ||
912 | if (!strncmp(template->name, "CD Capture ", 11)) | ||
913 | /* CD in is actually connected to the video in pin */ | ||
914 | template->private_value ^= AC97_CD ^ AC97_VIDEO; | ||
915 | return 0; | ||
916 | } | ||
917 | |||
918 | static int xonar_st_control_filter(struct snd_kcontrol_new *template) | ||
919 | { | ||
920 | if (!strncmp(template->name, "CD Capture ", 11)) | ||
921 | return 1; /* no CD input */ | ||
922 | return 0; | ||
923 | } | ||
924 | |||
925 | static int add_pcm1796_controls(struct oxygen *chip) | ||
926 | { | ||
927 | int err; | ||
928 | |||
929 | err = snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip)); | ||
930 | if (err < 0) | ||
931 | return err; | ||
932 | err = snd_ctl_add(chip->card, snd_ctl_new1(&os_128_control, chip)); | ||
933 | if (err < 0) | ||
934 | return err; | ||
935 | return 0; | ||
936 | } | ||
937 | |||
938 | static int xonar_d2_mixer_init(struct oxygen *chip) | ||
939 | { | ||
940 | int err; | ||
941 | |||
942 | err = snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip)); | ||
943 | if (err < 0) | ||
944 | return err; | ||
945 | err = add_pcm1796_controls(chip); | ||
946 | if (err < 0) | ||
947 | return err; | ||
948 | return 0; | ||
949 | } | ||
950 | |||
951 | static int xonar_hdav_mixer_init(struct oxygen *chip) | ||
952 | { | ||
953 | return add_pcm1796_controls(chip); | ||
954 | } | ||
955 | |||
956 | static int xonar_st_mixer_init(struct oxygen *chip) | ||
957 | { | ||
958 | unsigned int i; | ||
959 | int err; | ||
960 | |||
961 | for (i = 0; i < ARRAY_SIZE(st_controls); ++i) { | ||
962 | err = snd_ctl_add(chip->card, | ||
963 | snd_ctl_new1(&st_controls[i], chip)); | ||
964 | if (err < 0) | ||
965 | return err; | ||
966 | } | ||
967 | err = add_pcm1796_controls(chip); | ||
968 | if (err < 0) | ||
969 | return err; | ||
970 | return 0; | ||
971 | } | ||
972 | |||
973 | static const struct oxygen_model model_xonar_d2 = { | ||
974 | .longname = "Asus Virtuoso 200", | ||
975 | .chip = "AV200", | ||
976 | .init = xonar_d2_init, | ||
977 | .control_filter = xonar_d2_control_filter, | ||
978 | .mixer_init = xonar_d2_mixer_init, | ||
979 | .cleanup = xonar_d2_cleanup, | ||
980 | .suspend = xonar_d2_suspend, | ||
981 | .resume = xonar_d2_resume, | ||
982 | .get_i2s_mclk = get_pcm1796_i2s_mclk, | ||
983 | .set_dac_params = set_pcm1796_params, | ||
984 | .set_adc_params = xonar_set_cs53x1_params, | ||
985 | .update_dac_volume = update_pcm1796_volume, | ||
986 | .update_dac_mute = update_pcm1796_mute, | ||
987 | .dac_tlv = pcm1796_db_scale, | ||
988 | .model_data_size = sizeof(struct xonar_pcm179x), | ||
989 | .device_config = PLAYBACK_0_TO_I2S | | ||
990 | PLAYBACK_1_TO_SPDIF | | ||
991 | CAPTURE_0_FROM_I2S_2 | | ||
992 | CAPTURE_1_FROM_SPDIF | | ||
993 | MIDI_OUTPUT | | ||
994 | MIDI_INPUT, | ||
995 | .dac_channels = 8, | ||
996 | .dac_volume_min = 255 - 2*60, | ||
997 | .dac_volume_max = 255, | ||
998 | .misc_flags = OXYGEN_MISC_MIDI, | ||
999 | .function_flags = OXYGEN_FUNCTION_SPI | | ||
1000 | OXYGEN_FUNCTION_ENABLE_SPI_4_5, | ||
1001 | .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
1002 | .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
1003 | }; | ||
1004 | |||
1005 | static const struct oxygen_model model_xonar_hdav = { | ||
1006 | .longname = "Asus Virtuoso 200", | ||
1007 | .chip = "AV200", | ||
1008 | .init = xonar_hdav_init, | ||
1009 | .mixer_init = xonar_hdav_mixer_init, | ||
1010 | .cleanup = xonar_hdav_cleanup, | ||
1011 | .suspend = xonar_hdav_suspend, | ||
1012 | .resume = xonar_hdav_resume, | ||
1013 | .pcm_hardware_filter = xonar_hdmi_pcm_hardware_filter, | ||
1014 | .get_i2s_mclk = get_pcm1796_i2s_mclk, | ||
1015 | .set_dac_params = set_hdav_params, | ||
1016 | .set_adc_params = xonar_set_cs53x1_params, | ||
1017 | .update_dac_volume = update_pcm1796_volume, | ||
1018 | .update_dac_mute = update_pcm1796_mute, | ||
1019 | .uart_input = xonar_hdmi_uart_input, | ||
1020 | .ac97_switch = xonar_line_mic_ac97_switch, | ||
1021 | .dac_tlv = pcm1796_db_scale, | ||
1022 | .model_data_size = sizeof(struct xonar_hdav), | ||
1023 | .device_config = PLAYBACK_0_TO_I2S | | ||
1024 | PLAYBACK_1_TO_SPDIF | | ||
1025 | CAPTURE_0_FROM_I2S_2 | | ||
1026 | CAPTURE_1_FROM_SPDIF, | ||
1027 | .dac_channels = 8, | ||
1028 | .dac_volume_min = 255 - 2*60, | ||
1029 | .dac_volume_max = 255, | ||
1030 | .misc_flags = OXYGEN_MISC_MIDI, | ||
1031 | .function_flags = OXYGEN_FUNCTION_2WIRE, | ||
1032 | .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
1033 | .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
1034 | }; | ||
1035 | |||
1036 | static const struct oxygen_model model_xonar_st = { | ||
1037 | .longname = "Asus Virtuoso 100", | ||
1038 | .chip = "AV200", | ||
1039 | .init = xonar_st_init, | ||
1040 | .control_filter = xonar_st_control_filter, | ||
1041 | .mixer_init = xonar_st_mixer_init, | ||
1042 | .cleanup = xonar_st_cleanup, | ||
1043 | .suspend = xonar_st_suspend, | ||
1044 | .resume = xonar_st_resume, | ||
1045 | .get_i2s_mclk = get_pcm1796_i2s_mclk, | ||
1046 | .set_dac_params = set_st_params, | ||
1047 | .set_adc_params = xonar_set_cs53x1_params, | ||
1048 | .update_dac_volume = update_pcm1796_volume, | ||
1049 | .update_dac_mute = update_pcm1796_mute, | ||
1050 | .ac97_switch = xonar_line_mic_ac97_switch, | ||
1051 | .dac_tlv = pcm1796_db_scale, | ||
1052 | .model_data_size = sizeof(struct xonar_pcm179x), | ||
1053 | .device_config = PLAYBACK_0_TO_I2S | | ||
1054 | PLAYBACK_1_TO_SPDIF | | ||
1055 | CAPTURE_0_FROM_I2S_2, | ||
1056 | .dac_channels = 2, | ||
1057 | .dac_volume_min = 255 - 2*60, | ||
1058 | .dac_volume_max = 255, | ||
1059 | .function_flags = OXYGEN_FUNCTION_2WIRE, | ||
1060 | .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
1061 | .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
1062 | }; | ||
1063 | |||
1064 | int __devinit get_xonar_pcm179x_model(struct oxygen *chip, | ||
1065 | const struct pci_device_id *id) | ||
1066 | { | ||
1067 | switch (id->subdevice) { | ||
1068 | case 0x8269: | ||
1069 | chip->model = model_xonar_d2; | ||
1070 | chip->model.shortname = "Xonar D2"; | ||
1071 | break; | ||
1072 | case 0x82b7: | ||
1073 | chip->model = model_xonar_d2; | ||
1074 | chip->model.shortname = "Xonar D2X"; | ||
1075 | chip->model.init = xonar_d2x_init; | ||
1076 | break; | ||
1077 | case 0x8314: | ||
1078 | chip->model = model_xonar_hdav; | ||
1079 | oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK); | ||
1080 | switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) { | ||
1081 | default: | ||
1082 | chip->model.shortname = "Xonar HDAV1.3"; | ||
1083 | break; | ||
1084 | case GPIO_DB_H6: | ||
1085 | chip->model.shortname = "Xonar HDAV1.3+H6"; | ||
1086 | chip->model.private_data = 1; | ||
1087 | break; | ||
1088 | } | ||
1089 | break; | ||
1090 | case 0x835d: | ||
1091 | chip->model = model_xonar_st; | ||
1092 | oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK); | ||
1093 | switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) { | ||
1094 | default: | ||
1095 | chip->model.shortname = "Xonar ST"; | ||
1096 | break; | ||
1097 | case GPIO_DB_H6: | ||
1098 | chip->model.shortname = "Xonar ST+H6"; | ||
1099 | chip->model.dac_channels = 8; | ||
1100 | chip->model.private_data = 1; | ||
1101 | break; | ||
1102 | } | ||
1103 | break; | ||
1104 | case 0x835c: | ||
1105 | chip->model = model_xonar_st; | ||
1106 | chip->model.shortname = "Xonar STX"; | ||
1107 | chip->model.init = xonar_stx_init; | ||
1108 | chip->model.resume = xonar_stx_resume; | ||
1109 | chip->model.set_dac_params = set_pcm1796_params; | ||
1110 | break; | ||
1111 | default: | ||
1112 | return -EINVAL; | ||
1113 | } | ||
1114 | return 0; | ||
1115 | } | ||