aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/oxygen/oxygen.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci/oxygen/oxygen.c')
-rw-r--r--sound/pci/oxygen/oxygen.c248
1 files changed, 199 insertions, 49 deletions
diff --git a/sound/pci/oxygen/oxygen.c b/sound/pci/oxygen/oxygen.c
index 72db4c39007f..acbedebcffd9 100644
--- a/sound/pci/oxygen/oxygen.c
+++ b/sound/pci/oxygen/oxygen.c
@@ -18,6 +18,8 @@
18 */ 18 */
19 19
20/* 20/*
21 * CMI8788:
22 *
21 * SPI 0 -> 1st AK4396 (front) 23 * SPI 0 -> 1st AK4396 (front)
22 * SPI 1 -> 2nd AK4396 (surround) 24 * SPI 1 -> 2nd AK4396 (surround)
23 * SPI 2 -> 3rd AK4396 (center/LFE) 25 * SPI 2 -> 3rd AK4396 (center/LFE)
@@ -27,6 +29,10 @@
27 * GPIO 0 -> DFS0 of AK5385 29 * GPIO 0 -> DFS0 of AK5385
28 * GPIO 1 -> DFS1 of AK5385 30 * GPIO 1 -> DFS1 of AK5385
29 * GPIO 8 -> enable headphone amplifier on HT-Omega models 31 * GPIO 8 -> enable headphone amplifier on HT-Omega models
32 *
33 * CM9780:
34 *
35 * GPO 0 -> route line-in (0) or AC97 output (1) to ADC input
30 */ 36 */
31 37
32#include <linux/delay.h> 38#include <linux/delay.h>
@@ -91,8 +97,8 @@ MODULE_DEVICE_TABLE(pci, oxygen_ids);
91#define GPIO_CLARO_HP 0x0100 97#define GPIO_CLARO_HP 0x0100
92 98
93struct generic_data { 99struct generic_data {
94 u8 ak4396_ctl2; 100 u8 ak4396_regs[4][5];
95 u16 saved_wm8785_registers[2]; 101 u16 wm8785_regs[3];
96}; 102};
97 103
98static void ak4396_write(struct oxygen *chip, unsigned int codec, 104static void ak4396_write(struct oxygen *chip, unsigned int codec,
@@ -102,12 +108,24 @@ static void ak4396_write(struct oxygen *chip, unsigned int codec,
102 static const u8 codec_spi_map[4] = { 108 static const u8 codec_spi_map[4] = {
103 0, 1, 2, 4 109 0, 1, 2, 4
104 }; 110 };
111 struct generic_data *data = chip->model_data;
112
105 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER | 113 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
106 OXYGEN_SPI_DATA_LENGTH_2 | 114 OXYGEN_SPI_DATA_LENGTH_2 |
107 OXYGEN_SPI_CLOCK_160 | 115 OXYGEN_SPI_CLOCK_160 |
108 (codec_spi_map[codec] << OXYGEN_SPI_CODEC_SHIFT) | 116 (codec_spi_map[codec] << OXYGEN_SPI_CODEC_SHIFT) |
109 OXYGEN_SPI_CEN_LATCH_CLOCK_HI, 117 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
110 AK4396_WRITE | (reg << 8) | value); 118 AK4396_WRITE | (reg << 8) | value);
119 data->ak4396_regs[codec][reg] = value;
120}
121
122static void ak4396_write_cached(struct oxygen *chip, unsigned int codec,
123 u8 reg, u8 value)
124{
125 struct generic_data *data = chip->model_data;
126
127 if (value != data->ak4396_regs[codec][reg])
128 ak4396_write(chip, codec, reg, value);
111} 129}
112 130
113static void wm8785_write(struct oxygen *chip, u8 reg, unsigned int value) 131static void wm8785_write(struct oxygen *chip, u8 reg, unsigned int value)
@@ -120,20 +138,8 @@ static void wm8785_write(struct oxygen *chip, u8 reg, unsigned int value)
120 (3 << OXYGEN_SPI_CODEC_SHIFT) | 138 (3 << OXYGEN_SPI_CODEC_SHIFT) |
121 OXYGEN_SPI_CEN_LATCH_CLOCK_LO, 139 OXYGEN_SPI_CEN_LATCH_CLOCK_LO,
122 (reg << 9) | value); 140 (reg << 9) | value);
123 if (reg < ARRAY_SIZE(data->saved_wm8785_registers)) 141 if (reg < ARRAY_SIZE(data->wm8785_regs))
124 data->saved_wm8785_registers[reg] = value; 142 data->wm8785_regs[reg] = value;
125}
126
127static void update_ak4396_volume(struct oxygen *chip)
128{
129 unsigned int i;
130
131 for (i = 0; i < 4; ++i) {
132 ak4396_write(chip, i,
133 AK4396_LCH_ATT, chip->dac_volume[i * 2]);
134 ak4396_write(chip, i,
135 AK4396_RCH_ATT, chip->dac_volume[i * 2 + 1]);
136 }
137} 143}
138 144
139static void ak4396_registers_init(struct oxygen *chip) 145static void ak4396_registers_init(struct oxygen *chip)
@@ -142,21 +148,25 @@ static void ak4396_registers_init(struct oxygen *chip)
142 unsigned int i; 148 unsigned int i;
143 149
144 for (i = 0; i < 4; ++i) { 150 for (i = 0; i < 4; ++i) {
145 ak4396_write(chip, i, 151 ak4396_write(chip, i, AK4396_CONTROL_1,
146 AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN); 152 AK4396_DIF_24_MSB | AK4396_RSTN);
147 ak4396_write(chip, i, 153 ak4396_write(chip, i, AK4396_CONTROL_2,
148 AK4396_CONTROL_2, data->ak4396_ctl2); 154 data->ak4396_regs[0][AK4396_CONTROL_2]);
149 ak4396_write(chip, i, 155 ak4396_write(chip, i, AK4396_CONTROL_3,
150 AK4396_CONTROL_3, AK4396_PCM); 156 AK4396_PCM);
157 ak4396_write(chip, i, AK4396_LCH_ATT,
158 chip->dac_volume[i * 2]);
159 ak4396_write(chip, i, AK4396_RCH_ATT,
160 chip->dac_volume[i * 2 + 1]);
151 } 161 }
152 update_ak4396_volume(chip);
153} 162}
154 163
155static void ak4396_init(struct oxygen *chip) 164static void ak4396_init(struct oxygen *chip)
156{ 165{
157 struct generic_data *data = chip->model_data; 166 struct generic_data *data = chip->model_data;
158 167
159 data->ak4396_ctl2 = AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL; 168 data->ak4396_regs[0][AK4396_CONTROL_2] =
169 AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
160 ak4396_registers_init(chip); 170 ak4396_registers_init(chip);
161 snd_component_add(chip->card, "AK4396"); 171 snd_component_add(chip->card, "AK4396");
162} 172}
@@ -173,17 +183,17 @@ static void wm8785_registers_init(struct oxygen *chip)
173 struct generic_data *data = chip->model_data; 183 struct generic_data *data = chip->model_data;
174 184
175 wm8785_write(chip, WM8785_R7, 0); 185 wm8785_write(chip, WM8785_R7, 0);
176 wm8785_write(chip, WM8785_R0, data->saved_wm8785_registers[0]); 186 wm8785_write(chip, WM8785_R0, data->wm8785_regs[0]);
177 wm8785_write(chip, WM8785_R1, data->saved_wm8785_registers[1]); 187 wm8785_write(chip, WM8785_R2, data->wm8785_regs[2]);
178} 188}
179 189
180static void wm8785_init(struct oxygen *chip) 190static void wm8785_init(struct oxygen *chip)
181{ 191{
182 struct generic_data *data = chip->model_data; 192 struct generic_data *data = chip->model_data;
183 193
184 data->saved_wm8785_registers[0] = WM8785_MCR_SLAVE | 194 data->wm8785_regs[0] =
185 WM8785_OSR_SINGLE | WM8785_FORMAT_LJUST; 195 WM8785_MCR_SLAVE | WM8785_OSR_SINGLE | WM8785_FORMAT_LJUST;
186 data->saved_wm8785_registers[1] = WM8785_WL_24; 196 data->wm8785_regs[2] = WM8785_HPFR | WM8785_HPFL;
187 wm8785_registers_init(chip); 197 wm8785_registers_init(chip);
188 snd_component_add(chip->card, "WM8785"); 198 snd_component_add(chip->card, "WM8785");
189} 199}
@@ -264,24 +274,36 @@ static void set_ak4396_params(struct oxygen *chip,
264 unsigned int i; 274 unsigned int i;
265 u8 value; 275 u8 value;
266 276
267 value = data->ak4396_ctl2 & ~AK4396_DFS_MASK; 277 value = data->ak4396_regs[0][AK4396_CONTROL_2] & ~AK4396_DFS_MASK;
268 if (params_rate(params) <= 54000) 278 if (params_rate(params) <= 54000)
269 value |= AK4396_DFS_NORMAL; 279 value |= AK4396_DFS_NORMAL;
270 else if (params_rate(params) <= 108000) 280 else if (params_rate(params) <= 108000)
271 value |= AK4396_DFS_DOUBLE; 281 value |= AK4396_DFS_DOUBLE;
272 else 282 else
273 value |= AK4396_DFS_QUAD; 283 value |= AK4396_DFS_QUAD;
274 data->ak4396_ctl2 = value;
275 284
276 msleep(1); /* wait for the new MCLK to become stable */ 285 msleep(1); /* wait for the new MCLK to become stable */
277 286
287 if (value != data->ak4396_regs[0][AK4396_CONTROL_2]) {
288 for (i = 0; i < 4; ++i) {
289 ak4396_write(chip, i, AK4396_CONTROL_1,
290 AK4396_DIF_24_MSB);
291 ak4396_write(chip, i, AK4396_CONTROL_2, value);
292 ak4396_write(chip, i, AK4396_CONTROL_1,
293 AK4396_DIF_24_MSB | AK4396_RSTN);
294 }
295 }
296}
297
298static void update_ak4396_volume(struct oxygen *chip)
299{
300 unsigned int i;
301
278 for (i = 0; i < 4; ++i) { 302 for (i = 0; i < 4; ++i) {
279 ak4396_write(chip, i, 303 ak4396_write_cached(chip, i, AK4396_LCH_ATT,
280 AK4396_CONTROL_1, AK4396_DIF_24_MSB); 304 chip->dac_volume[i * 2]);
281 ak4396_write(chip, i, 305 ak4396_write_cached(chip, i, AK4396_RCH_ATT,
282 AK4396_CONTROL_2, value); 306 chip->dac_volume[i * 2 + 1]);
283 ak4396_write(chip, i,
284 AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
285 } 307 }
286} 308}
287 309
@@ -291,21 +313,19 @@ static void update_ak4396_mute(struct oxygen *chip)
291 unsigned int i; 313 unsigned int i;
292 u8 value; 314 u8 value;
293 315
294 value = data->ak4396_ctl2 & ~AK4396_SMUTE; 316 value = data->ak4396_regs[0][AK4396_CONTROL_2] & ~AK4396_SMUTE;
295 if (chip->dac_mute) 317 if (chip->dac_mute)
296 value |= AK4396_SMUTE; 318 value |= AK4396_SMUTE;
297 data->ak4396_ctl2 = value;
298 for (i = 0; i < 4; ++i) 319 for (i = 0; i < 4; ++i)
299 ak4396_write(chip, i, AK4396_CONTROL_2, value); 320 ak4396_write_cached(chip, i, AK4396_CONTROL_2, value);
300} 321}
301 322
302static void set_wm8785_params(struct oxygen *chip, 323static void set_wm8785_params(struct oxygen *chip,
303 struct snd_pcm_hw_params *params) 324 struct snd_pcm_hw_params *params)
304{ 325{
326 struct generic_data *data = chip->model_data;
305 unsigned int value; 327 unsigned int value;
306 328
307 wm8785_write(chip, WM8785_R7, 0);
308
309 value = WM8785_MCR_SLAVE | WM8785_FORMAT_LJUST; 329 value = WM8785_MCR_SLAVE | WM8785_FORMAT_LJUST;
310 if (params_rate(params) <= 48000) 330 if (params_rate(params) <= 48000)
311 value |= WM8785_OSR_SINGLE; 331 value |= WM8785_OSR_SINGLE;
@@ -313,13 +333,11 @@ static void set_wm8785_params(struct oxygen *chip,
313 value |= WM8785_OSR_DOUBLE; 333 value |= WM8785_OSR_DOUBLE;
314 else 334 else
315 value |= WM8785_OSR_QUAD; 335 value |= WM8785_OSR_QUAD;
316 wm8785_write(chip, WM8785_R0, value); 336 if (value != data->wm8785_regs[0]) {
317 337 wm8785_write(chip, WM8785_R7, 0);
318 if (snd_pcm_format_width(params_format(params)) <= 16) 338 wm8785_write(chip, WM8785_R0, value);
319 value = WM8785_WL_16; 339 wm8785_write(chip, WM8785_R2, data->wm8785_regs[2]);
320 else 340 }
321 value = WM8785_WL_24;
322 wm8785_write(chip, WM8785_R1, value);
323} 341}
324 342
325static void set_ak5385_params(struct oxygen *chip, 343static void set_ak5385_params(struct oxygen *chip,
@@ -337,6 +355,134 @@ static void set_ak5385_params(struct oxygen *chip,
337 value, GPIO_AK5385_DFS_MASK); 355 value, GPIO_AK5385_DFS_MASK);
338} 356}
339 357
358static int rolloff_info(struct snd_kcontrol *ctl,
359 struct snd_ctl_elem_info *info)
360{
361 static const char *const names[2] = {
362 "Sharp Roll-off", "Slow Roll-off"
363 };
364
365 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
366 info->count = 1;
367 info->value.enumerated.items = 2;
368 if (info->value.enumerated.item >= 2)
369 info->value.enumerated.item = 1;
370 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
371 return 0;
372}
373
374static int rolloff_get(struct snd_kcontrol *ctl,
375 struct snd_ctl_elem_value *value)
376{
377 struct oxygen *chip = ctl->private_data;
378 struct generic_data *data = chip->model_data;
379
380 value->value.enumerated.item[0] =
381 (data->ak4396_regs[0][AK4396_CONTROL_2] & AK4396_SLOW) != 0;
382 return 0;
383}
384
385static int rolloff_put(struct snd_kcontrol *ctl,
386 struct snd_ctl_elem_value *value)
387{
388 struct oxygen *chip = ctl->private_data;
389 struct generic_data *data = chip->model_data;
390 unsigned int i;
391 int changed;
392 u8 reg;
393
394 mutex_lock(&chip->mutex);
395 reg = data->ak4396_regs[0][AK4396_CONTROL_2];
396 if (value->value.enumerated.item[0])
397 reg |= AK4396_SLOW;
398 else
399 reg &= ~AK4396_SLOW;
400 changed = reg != data->ak4396_regs[0][AK4396_CONTROL_2];
401 if (changed) {
402 for (i = 0; i < 4; ++i)
403 ak4396_write(chip, i, AK4396_CONTROL_2, reg);
404 }
405 mutex_unlock(&chip->mutex);
406 return changed;
407}
408
409static const struct snd_kcontrol_new rolloff_control = {
410 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
411 .name = "DAC Filter Playback Enum",
412 .info = rolloff_info,
413 .get = rolloff_get,
414 .put = rolloff_put,
415};
416
417static int hpf_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
418{
419 static const char *const names[2] = {
420 "None", "High-pass Filter"
421 };
422
423 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
424 info->count = 1;
425 info->value.enumerated.items = 2;
426 if (info->value.enumerated.item >= 2)
427 info->value.enumerated.item = 1;
428 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
429 return 0;
430}
431
432static int hpf_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
433{
434 struct oxygen *chip = ctl->private_data;
435 struct generic_data *data = chip->model_data;
436
437 value->value.enumerated.item[0] =
438 (data->wm8785_regs[WM8785_R2] & WM8785_HPFR) != 0;
439 return 0;
440}
441
442static int hpf_put(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
443{
444 struct oxygen *chip = ctl->private_data;
445 struct generic_data *data = chip->model_data;
446 unsigned int reg;
447 int changed;
448
449 mutex_lock(&chip->mutex);
450 reg = data->wm8785_regs[WM8785_R2] & ~(WM8785_HPFR | WM8785_HPFL);
451 if (value->value.enumerated.item[0])
452 reg |= WM8785_HPFR | WM8785_HPFL;
453 changed = reg != data->wm8785_regs[WM8785_R2];
454 if (changed)
455 wm8785_write(chip, WM8785_R2, reg);
456 mutex_unlock(&chip->mutex);
457 return changed;
458}
459
460static const struct snd_kcontrol_new hpf_control = {
461 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
462 .name = "ADC Filter Capture Enum",
463 .info = hpf_info,
464 .get = hpf_get,
465 .put = hpf_put,
466};
467
468static int generic_mixer_init(struct oxygen *chip)
469{
470 return snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip));
471}
472
473static int generic_wm8785_mixer_init(struct oxygen *chip)
474{
475 int err;
476
477 err = generic_mixer_init(chip);
478 if (err < 0)
479 return err;
480 err = snd_ctl_add(chip->card, snd_ctl_new1(&hpf_control, chip));
481 if (err < 0)
482 return err;
483 return 0;
484}
485
340static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0); 486static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
341 487
342static const struct oxygen_model model_generic = { 488static const struct oxygen_model model_generic = {
@@ -344,8 +490,10 @@ static const struct oxygen_model model_generic = {
344 .longname = "C-Media Oxygen HD Audio", 490 .longname = "C-Media Oxygen HD Audio",
345 .chip = "CMI8788", 491 .chip = "CMI8788",
346 .init = generic_init, 492 .init = generic_init,
493 .mixer_init = generic_wm8785_mixer_init,
347 .cleanup = generic_cleanup, 494 .cleanup = generic_cleanup,
348 .resume = generic_resume, 495 .resume = generic_resume,
496 .get_i2s_mclk = oxygen_default_i2s_mclk,
349 .set_dac_params = set_ak4396_params, 497 .set_dac_params = set_ak4396_params,
350 .set_adc_params = set_wm8785_params, 498 .set_adc_params = set_wm8785_params,
351 .update_dac_volume = update_ak4396_volume, 499 .update_dac_volume = update_ak4396_volume,
@@ -374,6 +522,7 @@ static int __devinit get_oxygen_model(struct oxygen *chip,
374 switch (id->driver_data) { 522 switch (id->driver_data) {
375 case MODEL_MERIDIAN: 523 case MODEL_MERIDIAN:
376 chip->model.init = meridian_init; 524 chip->model.init = meridian_init;
525 chip->model.mixer_init = generic_mixer_init;
377 chip->model.resume = meridian_resume; 526 chip->model.resume = meridian_resume;
378 chip->model.set_adc_params = set_ak5385_params; 527 chip->model.set_adc_params = set_ak5385_params;
379 chip->model.device_config = PLAYBACK_0_TO_I2S | 528 chip->model.device_config = PLAYBACK_0_TO_I2S |
@@ -389,6 +538,7 @@ static int __devinit get_oxygen_model(struct oxygen *chip,
389 break; 538 break;
390 case MODEL_CLARO_HALO: 539 case MODEL_CLARO_HALO:
391 chip->model.init = claro_halo_init; 540 chip->model.init = claro_halo_init;
541 chip->model.mixer_init = generic_mixer_init;
392 chip->model.cleanup = claro_cleanup; 542 chip->model.cleanup = claro_cleanup;
393 chip->model.suspend = claro_suspend; 543 chip->model.suspend = claro_suspend;
394 chip->model.resume = claro_resume; 544 chip->model.resume = claro_resume;