diff options
author | Clemens Ladisch <clemens@ladisch.de> | 2009-09-28 05:11:27 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2009-09-28 05:53:38 -0400 |
commit | 65c3ac885ce9852852b895a4a62212f62cb5f2e9 (patch) | |
tree | 03f150871f6ff7c4e3b6d36c694e50b9c8318e13 | |
parent | 362bc24d6746bcd49bb4853fc5aa7d4c728b3f9e (diff) |
sound: virtuoso: split virtuoso.c
The virtuoso.c file has become rather big. This patch splits it up so
that only code for very similar card models is in one file.
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r-- | sound/pci/oxygen/Makefile | 3 | ||||
-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 | 304 | ||||
-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 | 660 |
7 files changed, 1290 insertions, 1092 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/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..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 | } | ||
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..eb5f015fcd23 --- /dev/null +++ b/sound/pci/oxygen/xonar_pcm179x.c | |||
@@ -0,0 +1,660 @@ | |||
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 | |||
37 | /* | ||
38 | * Xonar HDAV1.3 (Deluxe) | ||
39 | * ---------------------- | ||
40 | * | ||
41 | * CMI8788: | ||
42 | * | ||
43 | * I²C <-> PCM1796 (front) | ||
44 | * | ||
45 | * GPI 0 <- external power present | ||
46 | * | ||
47 | * GPIO 0 -> enable output to speakers | ||
48 | * GPIO 2 -> M0 of CS5381 | ||
49 | * GPIO 3 -> M1 of CS5381 | ||
50 | * GPIO 8 -> route input jack to line-in (0) or mic-in (1) | ||
51 | * | ||
52 | * TXD -> HDMI controller | ||
53 | * RXD <- HDMI controller | ||
54 | * | ||
55 | * PCM1796 front: AD1,0 <- 0,0 | ||
56 | * | ||
57 | * no daughterboard | ||
58 | * ---------------- | ||
59 | * | ||
60 | * GPIO 4 <- 1 | ||
61 | * | ||
62 | * H6 daughterboard | ||
63 | * ---------------- | ||
64 | * | ||
65 | * GPIO 4 <- 0 | ||
66 | * GPIO 5 <- 0 | ||
67 | * | ||
68 | * I²C <-> PCM1796 (surround) | ||
69 | * <-> PCM1796 (center/LFE) | ||
70 | * <-> PCM1796 (back) | ||
71 | * | ||
72 | * PCM1796 surround: AD1,0 <- 0,1 | ||
73 | * PCM1796 center/LFE: AD1,0 <- 1,0 | ||
74 | * PCM1796 back: AD1,0 <- 1,1 | ||
75 | * | ||
76 | * unknown daughterboard | ||
77 | * --------------------- | ||
78 | * | ||
79 | * GPIO 4 <- 0 | ||
80 | * GPIO 5 <- 1 | ||
81 | * | ||
82 | * I²C <-> CS4362A (surround, center/LFE, back) | ||
83 | * | ||
84 | * CS4362A: AD0 <- 0 | ||
85 | */ | ||
86 | |||
87 | /* | ||
88 | * Xonar Essence ST (Deluxe)/STX | ||
89 | * ----------------------------- | ||
90 | * | ||
91 | * CMI8788: | ||
92 | * | ||
93 | * I²C <-> PCM1792A | ||
94 | * | ||
95 | * GPI 0 <- external power present (STX only) | ||
96 | * | ||
97 | * GPIO 0 -> enable output to speakers | ||
98 | * GPIO 1 -> route HP to front panel (0) or rear jack (1) | ||
99 | * GPIO 2 -> M0 of CS5381 | ||
100 | * GPIO 3 -> M1 of CS5381 | ||
101 | * GPIO 7 -> route output to speaker jacks (0) or HP (1) | ||
102 | * GPIO 8 -> route input jack to line-in (0) or mic-in (1) | ||
103 | * | ||
104 | * PCM1792A: | ||
105 | * | ||
106 | * AD1,0 <- 0,0 | ||
107 | * | ||
108 | * H6 daughterboard | ||
109 | * ---------------- | ||
110 | * | ||
111 | * GPIO 4 <- 0 | ||
112 | * GPIO 5 <- 0 | ||
113 | */ | ||
114 | |||
115 | #include <linux/pci.h> | ||
116 | #include <linux/delay.h> | ||
117 | #include <linux/mutex.h> | ||
118 | #include <sound/ac97_codec.h> | ||
119 | #include <sound/control.h> | ||
120 | #include <sound/core.h> | ||
121 | #include <sound/pcm.h> | ||
122 | #include <sound/pcm_params.h> | ||
123 | #include <sound/tlv.h> | ||
124 | #include "xonar.h" | ||
125 | #include "cm9780.h" | ||
126 | #include "pcm1796.h" | ||
127 | |||
128 | |||
129 | #define GPIO_D2X_EXT_POWER 0x0020 | ||
130 | #define GPIO_D2_ALT 0x0080 | ||
131 | #define GPIO_D2_OUTPUT_ENABLE 0x0100 | ||
132 | |||
133 | #define GPI_EXT_POWER 0x01 | ||
134 | #define GPIO_INPUT_ROUTE 0x0100 | ||
135 | |||
136 | #define GPIO_HDAV_OUTPUT_ENABLE 0x0001 | ||
137 | |||
138 | #define GPIO_DB_MASK 0x0030 | ||
139 | #define GPIO_DB_H6 0x0000 | ||
140 | |||
141 | #define GPIO_ST_OUTPUT_ENABLE 0x0001 | ||
142 | #define GPIO_ST_HP_REAR 0x0002 | ||
143 | #define GPIO_ST_HP 0x0080 | ||
144 | |||
145 | #define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ii, /W=0 */ | ||
146 | |||
147 | |||
148 | struct xonar_pcm179x { | ||
149 | struct xonar_generic generic; | ||
150 | unsigned int dacs; | ||
151 | u8 oversampling; | ||
152 | }; | ||
153 | |||
154 | struct xonar_hdav { | ||
155 | struct xonar_pcm179x pcm179x; | ||
156 | struct xonar_hdmi hdmi; | ||
157 | }; | ||
158 | |||
159 | |||
160 | static inline void pcm1796_write_spi(struct oxygen *chip, unsigned int codec, | ||
161 | u8 reg, u8 value) | ||
162 | { | ||
163 | /* maps ALSA channel pair number to SPI output */ | ||
164 | static const u8 codec_map[4] = { | ||
165 | 0, 1, 2, 4 | ||
166 | }; | ||
167 | oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER | | ||
168 | OXYGEN_SPI_DATA_LENGTH_2 | | ||
169 | OXYGEN_SPI_CLOCK_160 | | ||
170 | (codec_map[codec] << OXYGEN_SPI_CODEC_SHIFT) | | ||
171 | OXYGEN_SPI_CEN_LATCH_CLOCK_HI, | ||
172 | (reg << 8) | value); | ||
173 | } | ||
174 | |||
175 | static inline void pcm1796_write_i2c(struct oxygen *chip, unsigned int codec, | ||
176 | u8 reg, u8 value) | ||
177 | { | ||
178 | oxygen_write_i2c(chip, I2C_DEVICE_PCM1796(codec), reg, value); | ||
179 | } | ||
180 | |||
181 | static void pcm1796_write(struct oxygen *chip, unsigned int codec, | ||
182 | u8 reg, u8 value) | ||
183 | { | ||
184 | if ((chip->model.function_flags & OXYGEN_FUNCTION_2WIRE_SPI_MASK) == | ||
185 | OXYGEN_FUNCTION_SPI) | ||
186 | pcm1796_write_spi(chip, codec, reg, value); | ||
187 | else | ||
188 | pcm1796_write_i2c(chip, codec, reg, value); | ||
189 | } | ||
190 | |||
191 | static void update_pcm1796_volume(struct oxygen *chip) | ||
192 | { | ||
193 | struct xonar_pcm179x *data = chip->model_data; | ||
194 | unsigned int i; | ||
195 | |||
196 | for (i = 0; i < data->dacs; ++i) { | ||
197 | pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]); | ||
198 | pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]); | ||
199 | } | ||
200 | } | ||
201 | |||
202 | static void update_pcm1796_mute(struct oxygen *chip) | ||
203 | { | ||
204 | struct xonar_pcm179x *data = chip->model_data; | ||
205 | unsigned int i; | ||
206 | u8 value; | ||
207 | |||
208 | value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD; | ||
209 | if (chip->dac_mute) | ||
210 | value |= PCM1796_MUTE; | ||
211 | for (i = 0; i < data->dacs; ++i) | ||
212 | pcm1796_write(chip, i, 18, value); | ||
213 | } | ||
214 | |||
215 | static void pcm1796_init(struct oxygen *chip) | ||
216 | { | ||
217 | struct xonar_pcm179x *data = chip->model_data; | ||
218 | unsigned int i; | ||
219 | |||
220 | for (i = 0; i < data->dacs; ++i) { | ||
221 | pcm1796_write(chip, i, 19, PCM1796_FLT_SHARP | PCM1796_ATS_1); | ||
222 | pcm1796_write(chip, i, 20, data->oversampling); | ||
223 | pcm1796_write(chip, i, 21, 0); | ||
224 | } | ||
225 | update_pcm1796_mute(chip); /* set ATLD before ATL/ATR */ | ||
226 | update_pcm1796_volume(chip); | ||
227 | } | ||
228 | |||
229 | static void xonar_d2_init(struct oxygen *chip) | ||
230 | { | ||
231 | struct xonar_pcm179x *data = chip->model_data; | ||
232 | |||
233 | data->generic.anti_pop_delay = 300; | ||
234 | data->generic.output_enable_bit = GPIO_D2_OUTPUT_ENABLE; | ||
235 | data->dacs = 4; | ||
236 | data->oversampling = PCM1796_OS_64; | ||
237 | |||
238 | pcm1796_init(chip); | ||
239 | |||
240 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT); | ||
241 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT); | ||
242 | |||
243 | oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC); | ||
244 | |||
245 | xonar_init_cs53x1(chip); | ||
246 | xonar_enable_output(chip); | ||
247 | |||
248 | snd_component_add(chip->card, "PCM1796"); | ||
249 | snd_component_add(chip->card, "CS5381"); | ||
250 | } | ||
251 | |||
252 | static void xonar_d2x_init(struct oxygen *chip) | ||
253 | { | ||
254 | struct xonar_pcm179x *data = chip->model_data; | ||
255 | |||
256 | data->generic.ext_power_reg = OXYGEN_GPIO_DATA; | ||
257 | data->generic.ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK; | ||
258 | data->generic.ext_power_bit = GPIO_D2X_EXT_POWER; | ||
259 | oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER); | ||
260 | xonar_init_ext_power(chip); | ||
261 | xonar_d2_init(chip); | ||
262 | } | ||
263 | |||
264 | static void xonar_hdav_init(struct oxygen *chip) | ||
265 | { | ||
266 | struct xonar_hdav *data = chip->model_data; | ||
267 | |||
268 | oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS, | ||
269 | OXYGEN_2WIRE_LENGTH_8 | | ||
270 | OXYGEN_2WIRE_INTERRUPT_MASK | | ||
271 | OXYGEN_2WIRE_SPEED_FAST); | ||
272 | |||
273 | data->pcm179x.generic.anti_pop_delay = 100; | ||
274 | data->pcm179x.generic.output_enable_bit = GPIO_HDAV_OUTPUT_ENABLE; | ||
275 | data->pcm179x.generic.ext_power_reg = OXYGEN_GPI_DATA; | ||
276 | data->pcm179x.generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK; | ||
277 | data->pcm179x.generic.ext_power_bit = GPI_EXT_POWER; | ||
278 | data->pcm179x.dacs = chip->model.private_data ? 4 : 1; | ||
279 | data->pcm179x.oversampling = PCM1796_OS_64; | ||
280 | |||
281 | pcm1796_init(chip); | ||
282 | |||
283 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_INPUT_ROUTE); | ||
284 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_INPUT_ROUTE); | ||
285 | |||
286 | xonar_init_cs53x1(chip); | ||
287 | xonar_init_ext_power(chip); | ||
288 | xonar_hdmi_init(chip, &data->hdmi); | ||
289 | xonar_enable_output(chip); | ||
290 | |||
291 | snd_component_add(chip->card, "PCM1796"); | ||
292 | snd_component_add(chip->card, "CS5381"); | ||
293 | } | ||
294 | |||
295 | static void xonar_st_init(struct oxygen *chip) | ||
296 | { | ||
297 | struct xonar_pcm179x *data = chip->model_data; | ||
298 | |||
299 | oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS, | ||
300 | OXYGEN_2WIRE_LENGTH_8 | | ||
301 | OXYGEN_2WIRE_INTERRUPT_MASK | | ||
302 | OXYGEN_2WIRE_SPEED_FAST); | ||
303 | |||
304 | data->generic.anti_pop_delay = 100; | ||
305 | data->generic.output_enable_bit = GPIO_ST_OUTPUT_ENABLE; | ||
306 | data->dacs = chip->model.private_data ? 4 : 1; | ||
307 | data->oversampling = PCM1796_OS_64; | ||
308 | |||
309 | pcm1796_init(chip); | ||
310 | |||
311 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, | ||
312 | GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP); | ||
313 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, | ||
314 | GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP); | ||
315 | |||
316 | xonar_init_cs53x1(chip); | ||
317 | xonar_enable_output(chip); | ||
318 | |||
319 | snd_component_add(chip->card, "PCM1792A"); | ||
320 | snd_component_add(chip->card, "CS5381"); | ||
321 | } | ||
322 | |||
323 | static void xonar_stx_init(struct oxygen *chip) | ||
324 | { | ||
325 | struct xonar_pcm179x *data = chip->model_data; | ||
326 | |||
327 | data->generic.ext_power_reg = OXYGEN_GPI_DATA; | ||
328 | data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK; | ||
329 | data->generic.ext_power_bit = GPI_EXT_POWER; | ||
330 | xonar_init_ext_power(chip); | ||
331 | xonar_st_init(chip); | ||
332 | } | ||
333 | |||
334 | static void xonar_d2_cleanup(struct oxygen *chip) | ||
335 | { | ||
336 | xonar_disable_output(chip); | ||
337 | } | ||
338 | |||
339 | static void xonar_hdav_cleanup(struct oxygen *chip) | ||
340 | { | ||
341 | xonar_hdmi_cleanup(chip); | ||
342 | xonar_disable_output(chip); | ||
343 | msleep(2); | ||
344 | } | ||
345 | |||
346 | static void xonar_st_cleanup(struct oxygen *chip) | ||
347 | { | ||
348 | xonar_disable_output(chip); | ||
349 | } | ||
350 | |||
351 | static void xonar_d2_suspend(struct oxygen *chip) | ||
352 | { | ||
353 | xonar_d2_cleanup(chip); | ||
354 | } | ||
355 | |||
356 | static void xonar_hdav_suspend(struct oxygen *chip) | ||
357 | { | ||
358 | xonar_hdav_cleanup(chip); | ||
359 | } | ||
360 | |||
361 | static void xonar_st_suspend(struct oxygen *chip) | ||
362 | { | ||
363 | xonar_st_cleanup(chip); | ||
364 | } | ||
365 | |||
366 | static void xonar_d2_resume(struct oxygen *chip) | ||
367 | { | ||
368 | pcm1796_init(chip); | ||
369 | xonar_enable_output(chip); | ||
370 | } | ||
371 | |||
372 | static void xonar_hdav_resume(struct oxygen *chip) | ||
373 | { | ||
374 | struct xonar_hdav *data = chip->model_data; | ||
375 | |||
376 | pcm1796_init(chip); | ||
377 | xonar_hdmi_resume(chip, &data->hdmi); | ||
378 | xonar_enable_output(chip); | ||
379 | } | ||
380 | |||
381 | static void xonar_st_resume(struct oxygen *chip) | ||
382 | { | ||
383 | pcm1796_init(chip); | ||
384 | xonar_enable_output(chip); | ||
385 | } | ||
386 | |||
387 | static void set_pcm1796_params(struct oxygen *chip, | ||
388 | struct snd_pcm_hw_params *params) | ||
389 | { | ||
390 | struct xonar_pcm179x *data = chip->model_data; | ||
391 | unsigned int i; | ||
392 | |||
393 | data->oversampling = | ||
394 | params_rate(params) >= 96000 ? PCM1796_OS_32 : PCM1796_OS_64; | ||
395 | for (i = 0; i < data->dacs; ++i) | ||
396 | pcm1796_write(chip, i, 20, data->oversampling); | ||
397 | } | ||
398 | |||
399 | static void set_hdav_params(struct oxygen *chip, | ||
400 | struct snd_pcm_hw_params *params) | ||
401 | { | ||
402 | struct xonar_hdav *data = chip->model_data; | ||
403 | |||
404 | set_pcm1796_params(chip, params); | ||
405 | xonar_set_hdmi_params(chip, &data->hdmi, params); | ||
406 | } | ||
407 | |||
408 | static const struct snd_kcontrol_new alt_switch = { | ||
409 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
410 | .name = "Analog Loopback Switch", | ||
411 | .info = snd_ctl_boolean_mono_info, | ||
412 | .get = xonar_gpio_bit_switch_get, | ||
413 | .put = xonar_gpio_bit_switch_put, | ||
414 | .private_value = GPIO_D2_ALT, | ||
415 | }; | ||
416 | |||
417 | static int st_output_switch_info(struct snd_kcontrol *ctl, | ||
418 | struct snd_ctl_elem_info *info) | ||
419 | { | ||
420 | static const char *const names[3] = { | ||
421 | "Speakers", "Headphones", "FP Headphones" | ||
422 | }; | ||
423 | |||
424 | info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | ||
425 | info->count = 1; | ||
426 | info->value.enumerated.items = 3; | ||
427 | if (info->value.enumerated.item >= 3) | ||
428 | info->value.enumerated.item = 2; | ||
429 | strcpy(info->value.enumerated.name, names[info->value.enumerated.item]); | ||
430 | return 0; | ||
431 | } | ||
432 | |||
433 | static int st_output_switch_get(struct snd_kcontrol *ctl, | ||
434 | struct snd_ctl_elem_value *value) | ||
435 | { | ||
436 | struct oxygen *chip = ctl->private_data; | ||
437 | u16 gpio; | ||
438 | |||
439 | gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA); | ||
440 | if (!(gpio & GPIO_ST_HP)) | ||
441 | value->value.enumerated.item[0] = 0; | ||
442 | else if (gpio & GPIO_ST_HP_REAR) | ||
443 | value->value.enumerated.item[0] = 1; | ||
444 | else | ||
445 | value->value.enumerated.item[0] = 2; | ||
446 | return 0; | ||
447 | } | ||
448 | |||
449 | |||
450 | static int st_output_switch_put(struct snd_kcontrol *ctl, | ||
451 | struct snd_ctl_elem_value *value) | ||
452 | { | ||
453 | struct oxygen *chip = ctl->private_data; | ||
454 | u16 gpio_old, gpio; | ||
455 | |||
456 | mutex_lock(&chip->mutex); | ||
457 | gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA); | ||
458 | gpio = gpio_old; | ||
459 | switch (value->value.enumerated.item[0]) { | ||
460 | case 0: | ||
461 | gpio &= ~(GPIO_ST_HP | GPIO_ST_HP_REAR); | ||
462 | break; | ||
463 | case 1: | ||
464 | gpio |= GPIO_ST_HP | GPIO_ST_HP_REAR; | ||
465 | break; | ||
466 | case 2: | ||
467 | gpio = (gpio | GPIO_ST_HP) & ~GPIO_ST_HP_REAR; | ||
468 | break; | ||
469 | } | ||
470 | oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio); | ||
471 | mutex_unlock(&chip->mutex); | ||
472 | return gpio != gpio_old; | ||
473 | } | ||
474 | |||
475 | static const struct snd_kcontrol_new st_output_switch = { | ||
476 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
477 | .name = "Analog Output", | ||
478 | .info = st_output_switch_info, | ||
479 | .get = st_output_switch_get, | ||
480 | .put = st_output_switch_put, | ||
481 | }; | ||
482 | |||
483 | static void xonar_line_mic_ac97_switch(struct oxygen *chip, | ||
484 | unsigned int reg, unsigned int mute) | ||
485 | { | ||
486 | if (reg == AC97_LINE) { | ||
487 | spin_lock_irq(&chip->reg_lock); | ||
488 | oxygen_write16_masked(chip, OXYGEN_GPIO_DATA, | ||
489 | mute ? GPIO_INPUT_ROUTE : 0, | ||
490 | GPIO_INPUT_ROUTE); | ||
491 | spin_unlock_irq(&chip->reg_lock); | ||
492 | } | ||
493 | } | ||
494 | |||
495 | static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -6000, 50, 0); | ||
496 | |||
497 | static int xonar_d2_control_filter(struct snd_kcontrol_new *template) | ||
498 | { | ||
499 | if (!strncmp(template->name, "CD Capture ", 11)) | ||
500 | /* CD in is actually connected to the video in pin */ | ||
501 | template->private_value ^= AC97_CD ^ AC97_VIDEO; | ||
502 | return 0; | ||
503 | } | ||
504 | |||
505 | static int xonar_st_control_filter(struct snd_kcontrol_new *template) | ||
506 | { | ||
507 | if (!strncmp(template->name, "CD Capture ", 11)) | ||
508 | return 1; /* no CD input */ | ||
509 | if (!strcmp(template->name, "Stereo Upmixing")) | ||
510 | return 1; /* stereo only - we don't need upmixing */ | ||
511 | return 0; | ||
512 | } | ||
513 | |||
514 | static int xonar_d2_mixer_init(struct oxygen *chip) | ||
515 | { | ||
516 | return snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip)); | ||
517 | } | ||
518 | |||
519 | static int xonar_st_mixer_init(struct oxygen *chip) | ||
520 | { | ||
521 | return snd_ctl_add(chip->card, snd_ctl_new1(&st_output_switch, chip)); | ||
522 | } | ||
523 | |||
524 | static const struct oxygen_model model_xonar_d2 = { | ||
525 | .longname = "Asus Virtuoso 200", | ||
526 | .chip = "AV200", | ||
527 | .init = xonar_d2_init, | ||
528 | .control_filter = xonar_d2_control_filter, | ||
529 | .mixer_init = xonar_d2_mixer_init, | ||
530 | .cleanup = xonar_d2_cleanup, | ||
531 | .suspend = xonar_d2_suspend, | ||
532 | .resume = xonar_d2_resume, | ||
533 | .set_dac_params = set_pcm1796_params, | ||
534 | .set_adc_params = xonar_set_cs53x1_params, | ||
535 | .update_dac_volume = update_pcm1796_volume, | ||
536 | .update_dac_mute = update_pcm1796_mute, | ||
537 | .dac_tlv = pcm1796_db_scale, | ||
538 | .model_data_size = sizeof(struct xonar_pcm179x), | ||
539 | .device_config = PLAYBACK_0_TO_I2S | | ||
540 | PLAYBACK_1_TO_SPDIF | | ||
541 | CAPTURE_0_FROM_I2S_2 | | ||
542 | CAPTURE_1_FROM_SPDIF | | ||
543 | MIDI_OUTPUT | | ||
544 | MIDI_INPUT, | ||
545 | .dac_channels = 8, | ||
546 | .dac_volume_min = 255 - 2*60, | ||
547 | .dac_volume_max = 255, | ||
548 | .misc_flags = OXYGEN_MISC_MIDI, | ||
549 | .function_flags = OXYGEN_FUNCTION_SPI | | ||
550 | OXYGEN_FUNCTION_ENABLE_SPI_4_5, | ||
551 | .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
552 | .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
553 | }; | ||
554 | |||
555 | static const struct oxygen_model model_xonar_hdav = { | ||
556 | .longname = "Asus Virtuoso 200", | ||
557 | .chip = "AV200", | ||
558 | .init = xonar_hdav_init, | ||
559 | .cleanup = xonar_hdav_cleanup, | ||
560 | .suspend = xonar_hdav_suspend, | ||
561 | .resume = xonar_hdav_resume, | ||
562 | .pcm_hardware_filter = xonar_hdmi_pcm_hardware_filter, | ||
563 | .set_dac_params = set_hdav_params, | ||
564 | .set_adc_params = xonar_set_cs53x1_params, | ||
565 | .update_dac_volume = update_pcm1796_volume, | ||
566 | .update_dac_mute = update_pcm1796_mute, | ||
567 | .uart_input = xonar_hdmi_uart_input, | ||
568 | .ac97_switch = xonar_line_mic_ac97_switch, | ||
569 | .dac_tlv = pcm1796_db_scale, | ||
570 | .model_data_size = sizeof(struct xonar_hdav), | ||
571 | .device_config = PLAYBACK_0_TO_I2S | | ||
572 | PLAYBACK_1_TO_SPDIF | | ||
573 | CAPTURE_0_FROM_I2S_2 | | ||
574 | CAPTURE_1_FROM_SPDIF, | ||
575 | .dac_channels = 8, | ||
576 | .dac_volume_min = 255 - 2*60, | ||
577 | .dac_volume_max = 255, | ||
578 | .misc_flags = OXYGEN_MISC_MIDI, | ||
579 | .function_flags = OXYGEN_FUNCTION_2WIRE, | ||
580 | .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
581 | .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
582 | }; | ||
583 | |||
584 | static const struct oxygen_model model_xonar_st = { | ||
585 | .longname = "Asus Virtuoso 100", | ||
586 | .chip = "AV200", | ||
587 | .init = xonar_st_init, | ||
588 | .control_filter = xonar_st_control_filter, | ||
589 | .mixer_init = xonar_st_mixer_init, | ||
590 | .cleanup = xonar_st_cleanup, | ||
591 | .suspend = xonar_st_suspend, | ||
592 | .resume = xonar_st_resume, | ||
593 | .set_dac_params = set_pcm1796_params, | ||
594 | .set_adc_params = xonar_set_cs53x1_params, | ||
595 | .update_dac_volume = update_pcm1796_volume, | ||
596 | .update_dac_mute = update_pcm1796_mute, | ||
597 | .ac97_switch = xonar_line_mic_ac97_switch, | ||
598 | .dac_tlv = pcm1796_db_scale, | ||
599 | .model_data_size = sizeof(struct xonar_pcm179x), | ||
600 | .device_config = PLAYBACK_0_TO_I2S | | ||
601 | PLAYBACK_1_TO_SPDIF | | ||
602 | CAPTURE_0_FROM_I2S_2, | ||
603 | .dac_channels = 2, | ||
604 | .dac_volume_min = 255 - 2*60, | ||
605 | .dac_volume_max = 255, | ||
606 | .function_flags = OXYGEN_FUNCTION_2WIRE, | ||
607 | .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
608 | .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, | ||
609 | }; | ||
610 | |||
611 | int __devinit get_xonar_pcm179x_model(struct oxygen *chip, | ||
612 | const struct pci_device_id *id) | ||
613 | { | ||
614 | switch (id->subdevice) { | ||
615 | case 0x8269: | ||
616 | chip->model = model_xonar_d2; | ||
617 | chip->model.shortname = "Xonar D2"; | ||
618 | break; | ||
619 | case 0x82b7: | ||
620 | chip->model = model_xonar_d2; | ||
621 | chip->model.shortname = "Xonar D2X"; | ||
622 | chip->model.init = xonar_d2x_init; | ||
623 | break; | ||
624 | case 0x8314: | ||
625 | chip->model = model_xonar_hdav; | ||
626 | oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK); | ||
627 | switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) { | ||
628 | default: | ||
629 | chip->model.shortname = "Xonar HDAV1.3"; | ||
630 | break; | ||
631 | case GPIO_DB_H6: | ||
632 | chip->model.shortname = "Xonar HDAV1.3+H6"; | ||
633 | chip->model.private_data = 1; | ||
634 | break; | ||
635 | } | ||
636 | break; | ||
637 | case 0x835d: | ||
638 | chip->model = model_xonar_st; | ||
639 | oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK); | ||
640 | switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) { | ||
641 | default: | ||
642 | chip->model.shortname = "Xonar ST"; | ||
643 | break; | ||
644 | case GPIO_DB_H6: | ||
645 | chip->model.shortname = "Xonar ST+H6"; | ||
646 | chip->model.dac_channels = 8; | ||
647 | chip->model.private_data = 1; | ||
648 | break; | ||
649 | } | ||
650 | break; | ||
651 | case 0x835c: | ||
652 | chip->model = model_xonar_st; | ||
653 | chip->model.shortname = "Xonar STX"; | ||
654 | chip->model.init = xonar_stx_init; | ||
655 | break; | ||
656 | default: | ||
657 | return -EINVAL; | ||
658 | } | ||
659 | return 0; | ||
660 | } | ||