diff options
Diffstat (limited to 'sound/pci/oxygen/xonar_cs43xx.c')
-rw-r--r-- | sound/pci/oxygen/xonar_cs43xx.c | 304 |
1 files changed, 304 insertions, 0 deletions
diff --git a/sound/pci/oxygen/xonar_cs43xx.c b/sound/pci/oxygen/xonar_cs43xx.c new file mode 100644 index 000000000000..8fb5797577dd --- /dev/null +++ b/sound/pci/oxygen/xonar_cs43xx.c | |||
@@ -0,0 +1,304 @@ | |||
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 | |||
46 | #include <linux/pci.h> | ||
47 | #include <linux/delay.h> | ||
48 | #include <sound/ac97_codec.h> | ||
49 | #include <sound/control.h> | ||
50 | #include <sound/core.h> | ||
51 | #include <sound/pcm.h> | ||
52 | #include <sound/pcm_params.h> | ||
53 | #include <sound/tlv.h> | ||
54 | #include "xonar.h" | ||
55 | #include "cs4398.h" | ||
56 | #include "cs4362a.h" | ||
57 | |||
58 | #define GPI_EXT_POWER 0x01 | ||
59 | #define GPIO_D1_OUTPUT_ENABLE 0x0001 | ||
60 | #define GPIO_D1_FRONT_PANEL 0x0002 | ||
61 | #define GPIO_D1_INPUT_ROUTE 0x0100 | ||
62 | |||
63 | #define I2C_DEVICE_CS4398 0x9e /* 10011, AD1=1, AD0=1, /W=0 */ | ||
64 | #define I2C_DEVICE_CS4362A 0x30 /* 001100, AD0=0, /W=0 */ | ||
65 | |||
66 | struct xonar_cs43xx { | ||
67 | struct xonar_generic generic; | ||
68 | u8 cs4398_fm; | ||
69 | u8 cs4362a_fm; | ||
70 | }; | ||
71 | |||
72 | static void cs4398_write(struct oxygen *chip, u8 reg, u8 value) | ||
73 | { | ||
74 | oxygen_write_i2c(chip, I2C_DEVICE_CS4398, reg, value); | ||
75 | } | ||
76 | |||
77 | static void cs4362a_write(struct oxygen *chip, u8 reg, u8 value) | ||
78 | { | ||
79 | oxygen_write_i2c(chip, I2C_DEVICE_CS4362A, reg, value); | ||
80 | } | ||
81 | |||
82 | static void update_cs4362a_volumes(struct oxygen *chip) | ||
83 | { | ||
84 | u8 mute; | ||
85 | |||
86 | mute = chip->dac_mute ? CS4362A_MUTE : 0; | ||
87 | cs4362a_write(chip, 7, (127 - chip->dac_volume[2]) | mute); | ||
88 | cs4362a_write(chip, 8, (127 - chip->dac_volume[3]) | mute); | ||
89 | cs4362a_write(chip, 10, (127 - chip->dac_volume[4]) | mute); | ||
90 | cs4362a_write(chip, 11, (127 - chip->dac_volume[5]) | mute); | ||
91 | cs4362a_write(chip, 13, (127 - chip->dac_volume[6]) | mute); | ||
92 | cs4362a_write(chip, 14, (127 - chip->dac_volume[7]) | mute); | ||
93 | } | ||
94 | |||
95 | static void update_cs43xx_volume(struct oxygen *chip) | ||
96 | { | ||
97 | cs4398_write(chip, 5, (127 - chip->dac_volume[0]) * 2); | ||
98 | cs4398_write(chip, 6, (127 - chip->dac_volume[1]) * 2); | ||
99 | update_cs4362a_volumes(chip); | ||
100 | } | ||
101 | |||
102 | static void update_cs43xx_mute(struct oxygen *chip) | ||
103 | { | ||
104 | u8 reg; | ||
105 | |||
106 | reg = CS4398_MUTEP_LOW | CS4398_PAMUTE; | ||
107 | if (chip->dac_mute) | ||
108 | reg |= CS4398_MUTE_B | CS4398_MUTE_A; | ||
109 | cs4398_write(chip, 4, reg); | ||
110 | update_cs4362a_volumes(chip); | ||
111 | } | ||
112 | |||
113 | static void cs43xx_init(struct oxygen *chip) | ||
114 | { | ||
115 | struct xonar_cs43xx *data = chip->model_data; | ||
116 | |||
117 | /* set CPEN (control port mode) and power down */ | ||
118 | cs4398_write(chip, 8, CS4398_CPEN | CS4398_PDN); | ||
119 | cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN); | ||
120 | /* configure */ | ||
121 | cs4398_write(chip, 2, data->cs4398_fm); | ||
122 | cs4398_write(chip, 3, CS4398_ATAPI_B_R | CS4398_ATAPI_A_L); | ||
123 | cs4398_write(chip, 7, CS4398_RMP_DN | CS4398_RMP_UP | | ||
124 | CS4398_ZERO_CROSS | CS4398_SOFT_RAMP); | ||
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, CS4362A_RMP_DN | CS4362A_DEM_NONE); | ||
129 | cs4362a_write(chip, 0x05, 0); | ||
130 | cs4362a_write(chip, 0x06, data->cs4362a_fm); | ||
131 | cs4362a_write(chip, 0x09, data->cs4362a_fm); | ||
132 | cs4362a_write(chip, 0x0c, data->cs4362a_fm); | ||
133 | update_cs43xx_volume(chip); | ||
134 | update_cs43xx_mute(chip); | ||
135 | /* clear power down */ | ||
136 | cs4398_write(chip, 8, CS4398_CPEN); | ||
137 | cs4362a_write(chip, 0x01, CS4362A_CPEN); | ||
138 | } | ||
139 | |||
140 | static void xonar_d1_init(struct oxygen *chip) | ||
141 | { | ||
142 | struct xonar_cs43xx *data = chip->model_data; | ||
143 | |||
144 | data->generic.anti_pop_delay = 800; | ||
145 | data->generic.output_enable_bit = GPIO_D1_OUTPUT_ENABLE; | ||
146 | data->cs4398_fm = CS4398_FM_SINGLE | CS4398_DEM_NONE | CS4398_DIF_LJUST; | ||
147 | data->cs4362a_fm = CS4362A_FM_SINGLE | | ||
148 | CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L; | ||
149 | |||
150 | oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS, | ||
151 | OXYGEN_2WIRE_LENGTH_8 | | ||
152 | OXYGEN_2WIRE_INTERRUPT_MASK | | ||
153 | OXYGEN_2WIRE_SPEED_FAST); | ||
154 | |||
155 | cs43xx_init(chip); | ||
156 | |||
157 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, | ||
158 | GPIO_D1_FRONT_PANEL | GPIO_D1_INPUT_ROUTE); | ||
159 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, | ||
160 | GPIO_D1_FRONT_PANEL | GPIO_D1_INPUT_ROUTE); | ||
161 | |||
162 | xonar_init_cs53x1(chip); | ||
163 | xonar_enable_output(chip); | ||
164 | |||
165 | snd_component_add(chip->card, "CS4398"); | ||
166 | snd_component_add(chip->card, "CS4362A"); | ||
167 | snd_component_add(chip->card, "CS5361"); | ||
168 | } | ||
169 | |||
170 | static void xonar_dx_init(struct oxygen *chip) | ||
171 | { | ||
172 | struct xonar_cs43xx *data = chip->model_data; | ||
173 | |||
174 | data->generic.ext_power_reg = OXYGEN_GPI_DATA; | ||
175 | data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK; | ||
176 | data->generic.ext_power_bit = GPI_EXT_POWER; | ||
177 | xonar_init_ext_power(chip); | ||
178 | xonar_d1_init(chip); | ||
179 | } | ||
180 | |||
181 | static void xonar_d1_cleanup(struct oxygen *chip) | ||
182 | { | ||
183 | xonar_disable_output(chip); | ||
184 | cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN); | ||
185 | oxygen_clear_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC); | ||
186 | } | ||
187 | |||
188 | static void xonar_d1_suspend(struct oxygen *chip) | ||
189 | { | ||
190 | xonar_d1_cleanup(chip); | ||
191 | } | ||
192 | |||
193 | static void xonar_d1_resume(struct oxygen *chip) | ||
194 | { | ||
195 | oxygen_set_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC); | ||
196 | msleep(1); | ||
197 | cs43xx_init(chip); | ||
198 | xonar_enable_output(chip); | ||
199 | } | ||
200 | |||
201 | static void set_cs43xx_params(struct oxygen *chip, | ||
202 | struct snd_pcm_hw_params *params) | ||
203 | { | ||
204 | struct xonar_cs43xx *data = chip->model_data; | ||
205 | |||
206 | data->cs4398_fm = CS4398_DEM_NONE | CS4398_DIF_LJUST; | ||
207 | data->cs4362a_fm = CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L; | ||
208 | if (params_rate(params) <= 50000) { | ||
209 | data->cs4398_fm |= CS4398_FM_SINGLE; | ||
210 | data->cs4362a_fm |= CS4362A_FM_SINGLE; | ||
211 | } else if (params_rate(params) <= 100000) { | ||
212 | data->cs4398_fm |= CS4398_FM_DOUBLE; | ||
213 | data->cs4362a_fm |= CS4362A_FM_DOUBLE; | ||
214 | } else { | ||
215 | data->cs4398_fm |= CS4398_FM_QUAD; | ||
216 | data->cs4362a_fm |= CS4362A_FM_QUAD; | ||
217 | } | ||
218 | cs4398_write(chip, 2, data->cs4398_fm); | ||
219 | cs4362a_write(chip, 0x06, data->cs4362a_fm); | ||
220 | cs4362a_write(chip, 0x09, data->cs4362a_fm); | ||
221 | cs4362a_write(chip, 0x0c, data->cs4362a_fm); | ||
222 | } | ||
223 | |||
224 | static const struct snd_kcontrol_new front_panel_switch = { | ||
225 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
226 | .name = "Front Panel Switch", | ||
227 | .info = snd_ctl_boolean_mono_info, | ||
228 | .get = xonar_gpio_bit_switch_get, | ||
229 | .put = xonar_gpio_bit_switch_put, | ||
230 | .private_value = GPIO_D1_FRONT_PANEL, | ||
231 | }; | ||
232 | |||
233 | static void xonar_d1_line_mic_ac97_switch(struct oxygen *chip, | ||
234 | unsigned int reg, unsigned int mute) | ||
235 | { | ||
236 | if (reg == AC97_LINE) { | ||
237 | spin_lock_irq(&chip->reg_lock); | ||
238 | oxygen_write16_masked(chip, OXYGEN_GPIO_DATA, | ||
239 | mute ? GPIO_D1_INPUT_ROUTE : 0, | ||
240 | GPIO_D1_INPUT_ROUTE); | ||
241 | spin_unlock_irq(&chip->reg_lock); | ||
242 | } | ||
243 | } | ||
244 | |||
245 | static const DECLARE_TLV_DB_SCALE(cs4362a_db_scale, -6000, 100, 0); | ||
246 | |||
247 | static int xonar_d1_control_filter(struct snd_kcontrol_new *template) | ||
248 | { | ||
249 | if (!strncmp(template->name, "CD Capture ", 11)) | ||
250 | return 1; /* no CD input */ | ||
251 | return 0; | ||
252 | } | ||
253 | |||
254 | static int xonar_d1_mixer_init(struct oxygen *chip) | ||
255 | { | ||
256 | return snd_ctl_add(chip->card, snd_ctl_new1(&front_panel_switch, chip)); | ||
257 | } | ||
258 | |||
259 | static const struct oxygen_model model_xonar_d1 = { | ||
260 | .longname = "Asus Virtuoso 100", | ||
261 | .chip = "AV200", | ||
262 | .init = xonar_d1_init, | ||
263 | .control_filter = xonar_d1_control_filter, | ||
264 | .mixer_init = xonar_d1_mixer_init, | ||
265 | .cleanup = xonar_d1_cleanup, | ||
266 | .suspend = xonar_d1_suspend, | ||
267 | .resume = xonar_d1_resume, | ||
268 | .set_dac_params = set_cs43xx_params, | ||
269 | .set_adc_params = xonar_set_cs53x1_params, | ||
270 | .update_dac_volume = update_cs43xx_volume, | ||
271 | .update_dac_mute = update_cs43xx_mute, | ||
272 | .ac97_switch = xonar_d1_line_mic_ac97_switch, | ||
273 | .dac_tlv = cs4362a_db_scale, | ||
274 | .model_data_size = sizeof(struct xonar_cs43xx), | ||
275 | .device_config = PLAYBACK_0_TO_I2S | | ||
276 | PLAYBACK_1_TO_SPDIF | | ||
277 | CAPTURE_0_FROM_I2S_2, | ||
278 | .dac_channels = 8, | ||
279 | .dac_volume_min = 127 - 60, | ||
280 | .dac_volume_max = 127, | ||
281 | .function_flags = OXYGEN_FUNCTION_2WIRE, | ||
282 | .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
283 | .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
284 | }; | ||
285 | |||
286 | int __devinit get_xonar_cs43xx_model(struct oxygen *chip, | ||
287 | const struct pci_device_id *id) | ||
288 | { | ||
289 | switch (id->subdevice) { | ||
290 | case 0x834f: | ||
291 | chip->model = model_xonar_d1; | ||
292 | chip->model.shortname = "Xonar D1"; | ||
293 | break; | ||
294 | case 0x8275: | ||
295 | case 0x8327: | ||
296 | chip->model = model_xonar_d1; | ||
297 | chip->model.shortname = "Xonar DX"; | ||
298 | chip->model.init = xonar_dx_init; | ||
299 | break; | ||
300 | default: | ||
301 | return -EINVAL; | ||
302 | } | ||
303 | return 0; | ||
304 | } | ||