diff options
Diffstat (limited to 'sound/soc/codecs/tlv320dac33.c')
-rw-r--r-- | sound/soc/codecs/tlv320dac33.c | 334 |
1 files changed, 154 insertions, 180 deletions
diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c index c5ab8c805771..71d7be8ac488 100644 --- a/sound/soc/codecs/tlv320dac33.c +++ b/sound/soc/codecs/tlv320dac33.c | |||
@@ -36,21 +36,21 @@ | |||
36 | #include <sound/pcm.h> | 36 | #include <sound/pcm.h> |
37 | #include <sound/pcm_params.h> | 37 | #include <sound/pcm_params.h> |
38 | #include <sound/soc.h> | 38 | #include <sound/soc.h> |
39 | #include <sound/soc-dapm.h> | ||
40 | #include <sound/initval.h> | 39 | #include <sound/initval.h> |
41 | #include <sound/tlv.h> | 40 | #include <sound/tlv.h> |
42 | 41 | ||
43 | #include <sound/tlv320dac33-plat.h> | 42 | #include <sound/tlv320dac33-plat.h> |
44 | #include "tlv320dac33.h" | 43 | #include "tlv320dac33.h" |
45 | 44 | ||
46 | #define DAC33_BUFFER_SIZE_BYTES 24576 /* bytes, 12288 16 bit words, | 45 | /* |
47 | * 6144 stereo */ | 46 | * The internal FIFO is 24576 bytes long |
48 | #define DAC33_BUFFER_SIZE_SAMPLES 6144 | 47 | * It can be configured to hold 16bit or 24bit samples |
49 | 48 | * In 16bit configuration the FIFO can hold 6144 stereo samples | |
50 | #define NSAMPLE_MAX 5700 | 49 | * In 24bit configuration the FIFO can hold 4096 stereo samples |
51 | 50 | */ | |
52 | #define MODE7_LTHR 10 | 51 | #define DAC33_FIFO_SIZE_16BIT 6144 |
53 | #define MODE7_UTHR (DAC33_BUFFER_SIZE_SAMPLES - 10) | 52 | #define DAC33_FIFO_SIZE_24BIT 4096 |
53 | #define DAC33_MODE7_MARGIN 10 /* Safety margin for FIFO in Mode7 */ | ||
54 | 54 | ||
55 | #define BURST_BASEFREQ_HZ 49152000 | 55 | #define BURST_BASEFREQ_HZ 49152000 |
56 | 56 | ||
@@ -100,16 +100,11 @@ struct tlv320dac33_priv { | |||
100 | unsigned int refclk; | 100 | unsigned int refclk; |
101 | 101 | ||
102 | unsigned int alarm_threshold; /* set to be half of LATENCY_TIME_MS */ | 102 | unsigned int alarm_threshold; /* set to be half of LATENCY_TIME_MS */ |
103 | unsigned int nsample_min; /* nsample should not be lower than | ||
104 | * this */ | ||
105 | unsigned int nsample_max; /* nsample should not be higher than | ||
106 | * this */ | ||
107 | enum dac33_fifo_modes fifo_mode;/* FIFO mode selection */ | 103 | enum dac33_fifo_modes fifo_mode;/* FIFO mode selection */ |
104 | unsigned int fifo_size; /* Size of the FIFO in samples */ | ||
108 | unsigned int nsample; /* burst read amount from host */ | 105 | unsigned int nsample; /* burst read amount from host */ |
109 | int mode1_latency; /* latency caused by the i2c writes in | 106 | int mode1_latency; /* latency caused by the i2c writes in |
110 | * us */ | 107 | * us */ |
111 | int auto_fifo_config; /* Configure the FIFO based on the | ||
112 | * period size */ | ||
113 | u8 burst_bclkdiv; /* BCLK divider value in burst mode */ | 108 | u8 burst_bclkdiv; /* BCLK divider value in burst mode */ |
114 | unsigned int burst_rate; /* Interface speed in Burst modes */ | 109 | unsigned int burst_rate; /* Interface speed in Burst modes */ |
115 | 110 | ||
@@ -303,7 +298,6 @@ static void dac33_init_chip(struct snd_soc_codec *codec) | |||
303 | if (unlikely(!dac33->chip_power)) | 298 | if (unlikely(!dac33->chip_power)) |
304 | return; | 299 | return; |
305 | 300 | ||
306 | /* 44-46: DAC Control Registers */ | ||
307 | /* A : DAC sample rate Fsref/1.5 */ | 301 | /* A : DAC sample rate Fsref/1.5 */ |
308 | dac33_write(codec, DAC33_DAC_CTRL_A, DAC33_DACRATE(0)); | 302 | dac33_write(codec, DAC33_DAC_CTRL_A, DAC33_DACRATE(0)); |
309 | /* B : DAC src=normal, not muted */ | 303 | /* B : DAC src=normal, not muted */ |
@@ -316,8 +310,6 @@ static void dac33_init_chip(struct snd_soc_codec *codec) | |||
316 | clock source = internal osc (?) */ | 310 | clock source = internal osc (?) */ |
317 | dac33_write(codec, DAC33_ANA_VOL_SOFT_STEP_CTRL, DAC33_VOLCLKEN); | 311 | dac33_write(codec, DAC33_ANA_VOL_SOFT_STEP_CTRL, DAC33_VOLCLKEN); |
318 | 312 | ||
319 | dac33_write(codec, DAC33_PWR_CTRL, DAC33_PDNALLB); | ||
320 | |||
321 | /* Restore only selected registers (gains mostly) */ | 313 | /* Restore only selected registers (gains mostly) */ |
322 | dac33_write(codec, DAC33_LDAC_DIG_VOL_CTRL, | 314 | dac33_write(codec, DAC33_LDAC_DIG_VOL_CTRL, |
323 | dac33_read_reg_cache(codec, DAC33_LDAC_DIG_VOL_CTRL)); | 315 | dac33_read_reg_cache(codec, DAC33_LDAC_DIG_VOL_CTRL)); |
@@ -328,6 +320,10 @@ static void dac33_init_chip(struct snd_soc_codec *codec) | |||
328 | dac33_read_reg_cache(codec, DAC33_LINEL_TO_LLO_VOL)); | 320 | dac33_read_reg_cache(codec, DAC33_LINEL_TO_LLO_VOL)); |
329 | dac33_write(codec, DAC33_LINER_TO_RLO_VOL, | 321 | dac33_write(codec, DAC33_LINER_TO_RLO_VOL, |
330 | dac33_read_reg_cache(codec, DAC33_LINER_TO_RLO_VOL)); | 322 | dac33_read_reg_cache(codec, DAC33_LINER_TO_RLO_VOL)); |
323 | |||
324 | dac33_write(codec, DAC33_OUT_AMP_CTRL, | ||
325 | dac33_read_reg_cache(codec, DAC33_OUT_AMP_CTRL)); | ||
326 | |||
331 | } | 327 | } |
332 | 328 | ||
333 | static inline int dac33_read_id(struct snd_soc_codec *codec) | 329 | static inline int dac33_read_id(struct snd_soc_codec *codec) |
@@ -357,6 +353,21 @@ static inline void dac33_soft_power(struct snd_soc_codec *codec, int power) | |||
357 | dac33_write(codec, DAC33_PWR_CTRL, reg); | 353 | dac33_write(codec, DAC33_PWR_CTRL, reg); |
358 | } | 354 | } |
359 | 355 | ||
356 | static inline void dac33_disable_digital(struct snd_soc_codec *codec) | ||
357 | { | ||
358 | u8 reg; | ||
359 | |||
360 | /* Stop the DAI clock */ | ||
361 | reg = dac33_read_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_B); | ||
362 | reg &= ~DAC33_BCLKON; | ||
363 | dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_B, reg); | ||
364 | |||
365 | /* Power down the Oscillator, and DACs */ | ||
366 | reg = dac33_read_reg_cache(codec, DAC33_PWR_CTRL); | ||
367 | reg &= ~(DAC33_OSCPDNB | DAC33_DACRPDNB | DAC33_DACLPDNB); | ||
368 | dac33_write(codec, DAC33_PWR_CTRL, reg); | ||
369 | } | ||
370 | |||
360 | static int dac33_hard_power(struct snd_soc_codec *codec, int power) | 371 | static int dac33_hard_power(struct snd_soc_codec *codec, int power) |
361 | { | 372 | { |
362 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | 373 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); |
@@ -405,7 +416,7 @@ exit: | |||
405 | return ret; | 416 | return ret; |
406 | } | 417 | } |
407 | 418 | ||
408 | static int playback_event(struct snd_soc_dapm_widget *w, | 419 | static int dac33_playback_event(struct snd_soc_dapm_widget *w, |
409 | struct snd_kcontrol *kcontrol, int event) | 420 | struct snd_kcontrol *kcontrol, int event) |
410 | { | 421 | { |
411 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(w->codec); | 422 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(w->codec); |
@@ -417,77 +428,13 @@ static int playback_event(struct snd_soc_dapm_widget *w, | |||
417 | dac33_prepare_chip(dac33->substream); | 428 | dac33_prepare_chip(dac33->substream); |
418 | } | 429 | } |
419 | break; | 430 | break; |
431 | case SND_SOC_DAPM_POST_PMD: | ||
432 | dac33_disable_digital(w->codec); | ||
433 | break; | ||
420 | } | 434 | } |
421 | return 0; | 435 | return 0; |
422 | } | 436 | } |
423 | 437 | ||
424 | static int dac33_get_nsample(struct snd_kcontrol *kcontrol, | ||
425 | struct snd_ctl_elem_value *ucontrol) | ||
426 | { | ||
427 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
428 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | ||
429 | |||
430 | ucontrol->value.integer.value[0] = dac33->nsample; | ||
431 | |||
432 | return 0; | ||
433 | } | ||
434 | |||
435 | static int dac33_set_nsample(struct snd_kcontrol *kcontrol, | ||
436 | struct snd_ctl_elem_value *ucontrol) | ||
437 | { | ||
438 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
439 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | ||
440 | int ret = 0; | ||
441 | |||
442 | if (dac33->nsample == ucontrol->value.integer.value[0]) | ||
443 | return 0; | ||
444 | |||
445 | if (ucontrol->value.integer.value[0] < dac33->nsample_min || | ||
446 | ucontrol->value.integer.value[0] > dac33->nsample_max) { | ||
447 | ret = -EINVAL; | ||
448 | } else { | ||
449 | dac33->nsample = ucontrol->value.integer.value[0]; | ||
450 | /* Re calculate the burst time */ | ||
451 | dac33->mode1_us_burst = SAMPLES_TO_US(dac33->burst_rate, | ||
452 | dac33->nsample); | ||
453 | } | ||
454 | |||
455 | return ret; | ||
456 | } | ||
457 | |||
458 | static int dac33_get_uthr(struct snd_kcontrol *kcontrol, | ||
459 | struct snd_ctl_elem_value *ucontrol) | ||
460 | { | ||
461 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
462 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | ||
463 | |||
464 | ucontrol->value.integer.value[0] = dac33->uthr; | ||
465 | |||
466 | return 0; | ||
467 | } | ||
468 | |||
469 | static int dac33_set_uthr(struct snd_kcontrol *kcontrol, | ||
470 | struct snd_ctl_elem_value *ucontrol) | ||
471 | { | ||
472 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
473 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | ||
474 | int ret = 0; | ||
475 | |||
476 | if (dac33->substream) | ||
477 | return -EBUSY; | ||
478 | |||
479 | if (dac33->uthr == ucontrol->value.integer.value[0]) | ||
480 | return 0; | ||
481 | |||
482 | if (ucontrol->value.integer.value[0] < (MODE7_LTHR + 10) || | ||
483 | ucontrol->value.integer.value[0] > MODE7_UTHR) | ||
484 | ret = -EINVAL; | ||
485 | else | ||
486 | dac33->uthr = ucontrol->value.integer.value[0]; | ||
487 | |||
488 | return ret; | ||
489 | } | ||
490 | |||
491 | static int dac33_get_fifo_mode(struct snd_kcontrol *kcontrol, | 438 | static int dac33_get_fifo_mode(struct snd_kcontrol *kcontrol, |
492 | struct snd_ctl_elem_value *ucontrol) | 439 | struct snd_ctl_elem_value *ucontrol) |
493 | { | 440 | { |
@@ -572,13 +519,6 @@ static const struct snd_kcontrol_new dac33_mode_snd_controls[] = { | |||
572 | dac33_get_fifo_mode, dac33_set_fifo_mode), | 519 | dac33_get_fifo_mode, dac33_set_fifo_mode), |
573 | }; | 520 | }; |
574 | 521 | ||
575 | static const struct snd_kcontrol_new dac33_fifo_snd_controls[] = { | ||
576 | SOC_SINGLE_EXT("nSample", 0, 0, 5900, 0, | ||
577 | dac33_get_nsample, dac33_set_nsample), | ||
578 | SOC_SINGLE_EXT("UTHR", 0, 0, MODE7_UTHR, 0, | ||
579 | dac33_get_uthr, dac33_set_uthr), | ||
580 | }; | ||
581 | |||
582 | /* Analog bypass */ | 522 | /* Analog bypass */ |
583 | static const struct snd_kcontrol_new dac33_dapm_abypassl_control = | 523 | static const struct snd_kcontrol_new dac33_dapm_abypassl_control = |
584 | SOC_DAPM_SINGLE("Switch", DAC33_LINEL_TO_LLO_VOL, 7, 1, 1); | 524 | SOC_DAPM_SINGLE("Switch", DAC33_LINEL_TO_LLO_VOL, 7, 1, 1); |
@@ -586,6 +526,25 @@ static const struct snd_kcontrol_new dac33_dapm_abypassl_control = | |||
586 | static const struct snd_kcontrol_new dac33_dapm_abypassr_control = | 526 | static const struct snd_kcontrol_new dac33_dapm_abypassr_control = |
587 | SOC_DAPM_SINGLE("Switch", DAC33_LINER_TO_RLO_VOL, 7, 1, 1); | 527 | SOC_DAPM_SINGLE("Switch", DAC33_LINER_TO_RLO_VOL, 7, 1, 1); |
588 | 528 | ||
529 | /* LOP L/R invert selection */ | ||
530 | static const char *dac33_lr_lom_texts[] = {"DAC", "LOP"}; | ||
531 | |||
532 | static const struct soc_enum dac33_left_lom_enum = | ||
533 | SOC_ENUM_SINGLE(DAC33_OUT_AMP_CTRL, 3, | ||
534 | ARRAY_SIZE(dac33_lr_lom_texts), | ||
535 | dac33_lr_lom_texts); | ||
536 | |||
537 | static const struct snd_kcontrol_new dac33_dapm_left_lom_control = | ||
538 | SOC_DAPM_ENUM("Route", dac33_left_lom_enum); | ||
539 | |||
540 | static const struct soc_enum dac33_right_lom_enum = | ||
541 | SOC_ENUM_SINGLE(DAC33_OUT_AMP_CTRL, 2, | ||
542 | ARRAY_SIZE(dac33_lr_lom_texts), | ||
543 | dac33_lr_lom_texts); | ||
544 | |||
545 | static const struct snd_kcontrol_new dac33_dapm_right_lom_control = | ||
546 | SOC_DAPM_ENUM("Route", dac33_right_lom_enum); | ||
547 | |||
589 | static const struct snd_soc_dapm_widget dac33_dapm_widgets[] = { | 548 | static const struct snd_soc_dapm_widget dac33_dapm_widgets[] = { |
590 | SND_SOC_DAPM_OUTPUT("LEFT_LO"), | 549 | SND_SOC_DAPM_OUTPUT("LEFT_LO"), |
591 | SND_SOC_DAPM_OUTPUT("RIGHT_LO"), | 550 | SND_SOC_DAPM_OUTPUT("RIGHT_LO"), |
@@ -593,8 +552,8 @@ static const struct snd_soc_dapm_widget dac33_dapm_widgets[] = { | |||
593 | SND_SOC_DAPM_INPUT("LINEL"), | 552 | SND_SOC_DAPM_INPUT("LINEL"), |
594 | SND_SOC_DAPM_INPUT("LINER"), | 553 | SND_SOC_DAPM_INPUT("LINER"), |
595 | 554 | ||
596 | SND_SOC_DAPM_DAC("DACL", "Left Playback", DAC33_LDAC_PWR_CTRL, 2, 0), | 555 | SND_SOC_DAPM_DAC("DACL", "Left Playback", SND_SOC_NOPM, 0, 0), |
597 | SND_SOC_DAPM_DAC("DACR", "Right Playback", DAC33_RDAC_PWR_CTRL, 2, 0), | 556 | SND_SOC_DAPM_DAC("DACR", "Right Playback", SND_SOC_NOPM, 0, 0), |
598 | 557 | ||
599 | /* Analog bypass */ | 558 | /* Analog bypass */ |
600 | SND_SOC_DAPM_SWITCH("Analog Left Bypass", SND_SOC_NOPM, 0, 0, | 559 | SND_SOC_DAPM_SWITCH("Analog Left Bypass", SND_SOC_NOPM, 0, 0, |
@@ -602,12 +561,30 @@ static const struct snd_soc_dapm_widget dac33_dapm_widgets[] = { | |||
602 | SND_SOC_DAPM_SWITCH("Analog Right Bypass", SND_SOC_NOPM, 0, 0, | 561 | SND_SOC_DAPM_SWITCH("Analog Right Bypass", SND_SOC_NOPM, 0, 0, |
603 | &dac33_dapm_abypassr_control), | 562 | &dac33_dapm_abypassr_control), |
604 | 563 | ||
605 | SND_SOC_DAPM_REG(snd_soc_dapm_mixer, "Output Left Amp Power", | 564 | SND_SOC_DAPM_MUX("Left LOM Inverted From", SND_SOC_NOPM, 0, 0, |
565 | &dac33_dapm_left_lom_control), | ||
566 | SND_SOC_DAPM_MUX("Right LOM Inverted From", SND_SOC_NOPM, 0, 0, | ||
567 | &dac33_dapm_right_lom_control), | ||
568 | /* | ||
569 | * For DAPM path, when only the anlog bypass path is enabled, and the | ||
570 | * LOP inverted from the corresponding DAC side. | ||
571 | * This is needed, so we can attach the DAC power supply in this case. | ||
572 | */ | ||
573 | SND_SOC_DAPM_PGA("Left Bypass PGA", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
574 | SND_SOC_DAPM_PGA("Right Bypass PGA", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
575 | |||
576 | SND_SOC_DAPM_REG(snd_soc_dapm_mixer, "Output Left Amplifier", | ||
606 | DAC33_OUT_AMP_PWR_CTRL, 6, 3, 3, 0), | 577 | DAC33_OUT_AMP_PWR_CTRL, 6, 3, 3, 0), |
607 | SND_SOC_DAPM_REG(snd_soc_dapm_mixer, "Output Right Amp Power", | 578 | SND_SOC_DAPM_REG(snd_soc_dapm_mixer, "Output Right Amplifier", |
608 | DAC33_OUT_AMP_PWR_CTRL, 4, 3, 3, 0), | 579 | DAC33_OUT_AMP_PWR_CTRL, 4, 3, 3, 0), |
609 | 580 | ||
610 | SND_SOC_DAPM_PRE("Prepare Playback", playback_event), | 581 | SND_SOC_DAPM_SUPPLY("Left DAC Power", |
582 | DAC33_LDAC_PWR_CTRL, 2, 0, NULL, 0), | ||
583 | SND_SOC_DAPM_SUPPLY("Right DAC Power", | ||
584 | DAC33_RDAC_PWR_CTRL, 2, 0, NULL, 0), | ||
585 | |||
586 | SND_SOC_DAPM_PRE("Pre Playback", dac33_playback_event), | ||
587 | SND_SOC_DAPM_POST("Post Playback", dac33_playback_event), | ||
611 | }; | 588 | }; |
612 | 589 | ||
613 | static const struct snd_soc_dapm_route audio_map[] = { | 590 | static const struct snd_soc_dapm_route audio_map[] = { |
@@ -615,24 +592,39 @@ static const struct snd_soc_dapm_route audio_map[] = { | |||
615 | {"Analog Left Bypass", "Switch", "LINEL"}, | 592 | {"Analog Left Bypass", "Switch", "LINEL"}, |
616 | {"Analog Right Bypass", "Switch", "LINER"}, | 593 | {"Analog Right Bypass", "Switch", "LINER"}, |
617 | 594 | ||
618 | {"Output Left Amp Power", NULL, "DACL"}, | 595 | {"Output Left Amplifier", NULL, "DACL"}, |
619 | {"Output Right Amp Power", NULL, "DACR"}, | 596 | {"Output Right Amplifier", NULL, "DACR"}, |
620 | 597 | ||
621 | {"Output Left Amp Power", NULL, "Analog Left Bypass"}, | 598 | {"Left Bypass PGA", NULL, "Analog Left Bypass"}, |
622 | {"Output Right Amp Power", NULL, "Analog Right Bypass"}, | 599 | {"Right Bypass PGA", NULL, "Analog Right Bypass"}, |
600 | |||
601 | {"Left LOM Inverted From", "DAC", "Left Bypass PGA"}, | ||
602 | {"Right LOM Inverted From", "DAC", "Right Bypass PGA"}, | ||
603 | {"Left LOM Inverted From", "LOP", "Analog Left Bypass"}, | ||
604 | {"Right LOM Inverted From", "LOP", "Analog Right Bypass"}, | ||
605 | |||
606 | {"Output Left Amplifier", NULL, "Left LOM Inverted From"}, | ||
607 | {"Output Right Amplifier", NULL, "Right LOM Inverted From"}, | ||
608 | |||
609 | {"DACL", NULL, "Left DAC Power"}, | ||
610 | {"DACR", NULL, "Right DAC Power"}, | ||
611 | |||
612 | {"Left Bypass PGA", NULL, "Left DAC Power"}, | ||
613 | {"Right Bypass PGA", NULL, "Right DAC Power"}, | ||
623 | 614 | ||
624 | /* output */ | 615 | /* output */ |
625 | {"LEFT_LO", NULL, "Output Left Amp Power"}, | 616 | {"LEFT_LO", NULL, "Output Left Amplifier"}, |
626 | {"RIGHT_LO", NULL, "Output Right Amp Power"}, | 617 | {"RIGHT_LO", NULL, "Output Right Amplifier"}, |
627 | }; | 618 | }; |
628 | 619 | ||
629 | static int dac33_add_widgets(struct snd_soc_codec *codec) | 620 | static int dac33_add_widgets(struct snd_soc_codec *codec) |
630 | { | 621 | { |
631 | snd_soc_dapm_new_controls(codec, dac33_dapm_widgets, | 622 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
632 | ARRAY_SIZE(dac33_dapm_widgets)); | ||
633 | 623 | ||
624 | snd_soc_dapm_new_controls(dapm, dac33_dapm_widgets, | ||
625 | ARRAY_SIZE(dac33_dapm_widgets)); | ||
634 | /* set up audio path interconnects */ | 626 | /* set up audio path interconnects */ |
635 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); | 627 | snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map)); |
636 | 628 | ||
637 | return 0; | 629 | return 0; |
638 | } | 630 | } |
@@ -640,16 +632,18 @@ static int dac33_add_widgets(struct snd_soc_codec *codec) | |||
640 | static int dac33_set_bias_level(struct snd_soc_codec *codec, | 632 | static int dac33_set_bias_level(struct snd_soc_codec *codec, |
641 | enum snd_soc_bias_level level) | 633 | enum snd_soc_bias_level level) |
642 | { | 634 | { |
635 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | ||
643 | int ret; | 636 | int ret; |
644 | 637 | ||
645 | switch (level) { | 638 | switch (level) { |
646 | case SND_SOC_BIAS_ON: | 639 | case SND_SOC_BIAS_ON: |
647 | dac33_soft_power(codec, 1); | 640 | if (!dac33->substream) |
641 | dac33_soft_power(codec, 1); | ||
648 | break; | 642 | break; |
649 | case SND_SOC_BIAS_PREPARE: | 643 | case SND_SOC_BIAS_PREPARE: |
650 | break; | 644 | break; |
651 | case SND_SOC_BIAS_STANDBY: | 645 | case SND_SOC_BIAS_STANDBY: |
652 | if (codec->bias_level == SND_SOC_BIAS_OFF) { | 646 | if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { |
653 | /* Coming from OFF, switch on the codec */ | 647 | /* Coming from OFF, switch on the codec */ |
654 | ret = dac33_hard_power(codec, 1); | 648 | ret = dac33_hard_power(codec, 1); |
655 | if (ret != 0) | 649 | if (ret != 0) |
@@ -660,14 +654,14 @@ static int dac33_set_bias_level(struct snd_soc_codec *codec, | |||
660 | break; | 654 | break; |
661 | case SND_SOC_BIAS_OFF: | 655 | case SND_SOC_BIAS_OFF: |
662 | /* Do not power off, when the codec is already off */ | 656 | /* Do not power off, when the codec is already off */ |
663 | if (codec->bias_level == SND_SOC_BIAS_OFF) | 657 | if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) |
664 | return 0; | 658 | return 0; |
665 | ret = dac33_hard_power(codec, 0); | 659 | ret = dac33_hard_power(codec, 0); |
666 | if (ret != 0) | 660 | if (ret != 0) |
667 | return ret; | 661 | return ret; |
668 | break; | 662 | break; |
669 | } | 663 | } |
670 | codec->bias_level = level; | 664 | codec->dapm.bias_level = level; |
671 | 665 | ||
672 | return 0; | 666 | return 0; |
673 | } | 667 | } |
@@ -705,7 +699,7 @@ static inline void dac33_prefill_handler(struct tlv320dac33_priv *dac33) | |||
705 | spin_unlock_irq(&dac33->lock); | 699 | spin_unlock_irq(&dac33->lock); |
706 | 700 | ||
707 | dac33_write16(codec, DAC33_PREFILL_MSB, | 701 | dac33_write16(codec, DAC33_PREFILL_MSB, |
708 | DAC33_THRREG(MODE7_LTHR)); | 702 | DAC33_THRREG(DAC33_MODE7_MARGIN)); |
709 | 703 | ||
710 | /* Enable Upper Threshold IRQ */ | 704 | /* Enable Upper Threshold IRQ */ |
711 | dac33_write(codec, DAC33_FIFO_IRQ_MASK, DAC33_MUT); | 705 | dac33_write(codec, DAC33_FIFO_IRQ_MASK, DAC33_MUT); |
@@ -815,6 +809,8 @@ static int dac33_startup(struct snd_pcm_substream *substream, | |||
815 | /* Stream started, save the substream pointer */ | 809 | /* Stream started, save the substream pointer */ |
816 | dac33->substream = substream; | 810 | dac33->substream = substream; |
817 | 811 | ||
812 | snd_pcm_hw_constraint_msbits(substream->runtime, 0, 32, 24); | ||
813 | |||
818 | return 0; | 814 | return 0; |
819 | } | 815 | } |
820 | 816 | ||
@@ -826,18 +822,17 @@ static void dac33_shutdown(struct snd_pcm_substream *substream, | |||
826 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | 822 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); |
827 | 823 | ||
828 | dac33->substream = NULL; | 824 | dac33->substream = NULL; |
829 | |||
830 | /* Reset the nSample restrictions */ | ||
831 | dac33->nsample_min = 0; | ||
832 | dac33->nsample_max = NSAMPLE_MAX; | ||
833 | } | 825 | } |
834 | 826 | ||
827 | #define CALC_BURST_RATE(bclkdiv, bclk_per_sample) \ | ||
828 | (BURST_BASEFREQ_HZ / bclkdiv / bclk_per_sample) | ||
835 | static int dac33_hw_params(struct snd_pcm_substream *substream, | 829 | static int dac33_hw_params(struct snd_pcm_substream *substream, |
836 | struct snd_pcm_hw_params *params, | 830 | struct snd_pcm_hw_params *params, |
837 | struct snd_soc_dai *dai) | 831 | struct snd_soc_dai *dai) |
838 | { | 832 | { |
839 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 833 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
840 | struct snd_soc_codec *codec = rtd->codec; | 834 | struct snd_soc_codec *codec = rtd->codec; |
835 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | ||
841 | 836 | ||
842 | /* Check parameters for validity */ | 837 | /* Check parameters for validity */ |
843 | switch (params_rate(params)) { | 838 | switch (params_rate(params)) { |
@@ -852,6 +847,12 @@ static int dac33_hw_params(struct snd_pcm_substream *substream, | |||
852 | 847 | ||
853 | switch (params_format(params)) { | 848 | switch (params_format(params)) { |
854 | case SNDRV_PCM_FORMAT_S16_LE: | 849 | case SNDRV_PCM_FORMAT_S16_LE: |
850 | dac33->fifo_size = DAC33_FIFO_SIZE_16BIT; | ||
851 | dac33->burst_rate = CALC_BURST_RATE(dac33->burst_bclkdiv, 32); | ||
852 | break; | ||
853 | case SNDRV_PCM_FORMAT_S32_LE: | ||
854 | dac33->fifo_size = DAC33_FIFO_SIZE_24BIT; | ||
855 | dac33->burst_rate = CALC_BURST_RATE(dac33->burst_bclkdiv, 64); | ||
855 | break; | 856 | break; |
856 | default: | 857 | default: |
857 | dev_err(codec->dev, "unsupported format %d\n", | 858 | dev_err(codec->dev, "unsupported format %d\n", |
@@ -906,6 +907,9 @@ static int dac33_prepare_chip(struct snd_pcm_substream *substream) | |||
906 | aictrl_a |= (DAC33_NCYCL_16 | DAC33_WLEN_16); | 907 | aictrl_a |= (DAC33_NCYCL_16 | DAC33_WLEN_16); |
907 | fifoctrl_a |= DAC33_WIDTH; | 908 | fifoctrl_a |= DAC33_WIDTH; |
908 | break; | 909 | break; |
910 | case SNDRV_PCM_FORMAT_S32_LE: | ||
911 | aictrl_a |= (DAC33_NCYCL_32 | DAC33_WLEN_24); | ||
912 | break; | ||
909 | default: | 913 | default: |
910 | dev_err(codec->dev, "unsupported format %d\n", | 914 | dev_err(codec->dev, "unsupported format %d\n", |
911 | substream->runtime->format); | 915 | substream->runtime->format); |
@@ -1040,7 +1044,10 @@ static int dac33_prepare_chip(struct snd_pcm_substream *substream) | |||
1040 | dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_C, | 1044 | dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_C, |
1041 | dac33->burst_bclkdiv); | 1045 | dac33->burst_bclkdiv); |
1042 | else | 1046 | else |
1043 | dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_C, 32); | 1047 | if (substream->runtime->format == SNDRV_PCM_FORMAT_S16_LE) |
1048 | dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_C, 32); | ||
1049 | else | ||
1050 | dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_C, 16); | ||
1044 | 1051 | ||
1045 | switch (dac33->fifo_mode) { | 1052 | switch (dac33->fifo_mode) { |
1046 | case DAC33_FIFO_MODE1: | 1053 | case DAC33_FIFO_MODE1: |
@@ -1053,7 +1060,8 @@ static int dac33_prepare_chip(struct snd_pcm_substream *substream) | |||
1053 | * at the bottom, and also at the top of the FIFO | 1060 | * at the bottom, and also at the top of the FIFO |
1054 | */ | 1061 | */ |
1055 | dac33_write16(codec, DAC33_UTHR_MSB, DAC33_THRREG(dac33->uthr)); | 1062 | dac33_write16(codec, DAC33_UTHR_MSB, DAC33_THRREG(dac33->uthr)); |
1056 | dac33_write16(codec, DAC33_LTHR_MSB, DAC33_THRREG(MODE7_LTHR)); | 1063 | dac33_write16(codec, DAC33_LTHR_MSB, |
1064 | DAC33_THRREG(DAC33_MODE7_MARGIN)); | ||
1057 | break; | 1065 | break; |
1058 | default: | 1066 | default: |
1059 | break; | 1067 | break; |
@@ -1082,42 +1090,21 @@ static void dac33_calculate_times(struct snd_pcm_substream *substream) | |||
1082 | /* Number of samples under i2c latency */ | 1090 | /* Number of samples under i2c latency */ |
1083 | dac33->alarm_threshold = US_TO_SAMPLES(rate, | 1091 | dac33->alarm_threshold = US_TO_SAMPLES(rate, |
1084 | dac33->mode1_latency); | 1092 | dac33->mode1_latency); |
1085 | nsample_limit = DAC33_BUFFER_SIZE_SAMPLES - | 1093 | nsample_limit = dac33->fifo_size - dac33->alarm_threshold; |
1086 | dac33->alarm_threshold; | 1094 | |
1087 | 1095 | if (period_size <= dac33->alarm_threshold) | |
1088 | if (dac33->auto_fifo_config) { | ||
1089 | if (period_size <= dac33->alarm_threshold) | ||
1090 | /* | ||
1091 | * Configure nSamaple to number of periods, | ||
1092 | * which covers the latency requironment. | ||
1093 | */ | ||
1094 | dac33->nsample = period_size * | ||
1095 | ((dac33->alarm_threshold / period_size) + | ||
1096 | (dac33->alarm_threshold % period_size ? | ||
1097 | 1 : 0)); | ||
1098 | else if (period_size > nsample_limit) | ||
1099 | dac33->nsample = nsample_limit; | ||
1100 | else | ||
1101 | dac33->nsample = period_size; | ||
1102 | } else { | ||
1103 | /* nSample time shall not be shorter than i2c latency */ | ||
1104 | dac33->nsample_min = dac33->alarm_threshold; | ||
1105 | /* | 1096 | /* |
1106 | * nSample should not be bigger than alsa buffer minus | 1097 | * Configure nSamaple to number of periods, |
1107 | * size of one period to avoid overruns | 1098 | * which covers the latency requironment. |
1108 | */ | 1099 | */ |
1109 | dac33->nsample_max = substream->runtime->buffer_size - | 1100 | dac33->nsample = period_size * |
1110 | period_size; | 1101 | ((dac33->alarm_threshold / period_size) + |
1111 | 1102 | (dac33->alarm_threshold % period_size ? | |
1112 | if (dac33->nsample_max > nsample_limit) | 1103 | 1 : 0)); |
1113 | dac33->nsample_max = nsample_limit; | 1104 | else if (period_size > nsample_limit) |
1114 | 1105 | dac33->nsample = nsample_limit; | |
1115 | /* Correct the nSample if it is outside of the ranges */ | 1106 | else |
1116 | if (dac33->nsample < dac33->nsample_min) | 1107 | dac33->nsample = period_size; |
1117 | dac33->nsample = dac33->nsample_min; | ||
1118 | if (dac33->nsample > dac33->nsample_max) | ||
1119 | dac33->nsample = dac33->nsample_max; | ||
1120 | } | ||
1121 | 1108 | ||
1122 | dac33->mode1_us_burst = SAMPLES_TO_US(dac33->burst_rate, | 1109 | dac33->mode1_us_burst = SAMPLES_TO_US(dac33->burst_rate, |
1123 | dac33->nsample); | 1110 | dac33->nsample); |
@@ -1125,19 +1112,16 @@ static void dac33_calculate_times(struct snd_pcm_substream *substream) | |||
1125 | dac33->t_stamp2 = 0; | 1112 | dac33->t_stamp2 = 0; |
1126 | break; | 1113 | break; |
1127 | case DAC33_FIFO_MODE7: | 1114 | case DAC33_FIFO_MODE7: |
1128 | if (dac33->auto_fifo_config) { | 1115 | dac33->uthr = UTHR_FROM_PERIOD_SIZE(period_size, rate, |
1129 | dac33->uthr = UTHR_FROM_PERIOD_SIZE( | 1116 | dac33->burst_rate) + 9; |
1130 | period_size, | 1117 | if (dac33->uthr > (dac33->fifo_size - DAC33_MODE7_MARGIN)) |
1131 | rate, | 1118 | dac33->uthr = dac33->fifo_size - DAC33_MODE7_MARGIN; |
1132 | dac33->burst_rate) + 9; | 1119 | if (dac33->uthr < (DAC33_MODE7_MARGIN + 10)) |
1133 | if (dac33->uthr > MODE7_UTHR) | 1120 | dac33->uthr = (DAC33_MODE7_MARGIN + 10); |
1134 | dac33->uthr = MODE7_UTHR; | 1121 | |
1135 | if (dac33->uthr < (MODE7_LTHR + 10)) | ||
1136 | dac33->uthr = (MODE7_LTHR + 10); | ||
1137 | } | ||
1138 | dac33->mode7_us_to_lthr = | 1122 | dac33->mode7_us_to_lthr = |
1139 | SAMPLES_TO_US(substream->runtime->rate, | 1123 | SAMPLES_TO_US(substream->runtime->rate, |
1140 | dac33->uthr - MODE7_LTHR + 1); | 1124 | dac33->uthr - DAC33_MODE7_MARGIN + 1); |
1141 | dac33->t_stamp1 = 0; | 1125 | dac33->t_stamp1 = 0; |
1142 | break; | 1126 | break; |
1143 | default: | 1127 | default: |
@@ -1255,8 +1239,8 @@ static snd_pcm_sframes_t dac33_dai_delay( | |||
1255 | samples += (samples_in - samples_out); | 1239 | samples += (samples_in - samples_out); |
1256 | 1240 | ||
1257 | if (likely(samples > 0)) | 1241 | if (likely(samples > 0)) |
1258 | delay = samples > DAC33_BUFFER_SIZE_SAMPLES ? | 1242 | delay = samples > dac33->fifo_size ? |
1259 | DAC33_BUFFER_SIZE_SAMPLES : samples; | 1243 | dac33->fifo_size : samples; |
1260 | else | 1244 | else |
1261 | delay = 0; | 1245 | delay = 0; |
1262 | } | 1246 | } |
@@ -1308,7 +1292,7 @@ static snd_pcm_sframes_t dac33_dai_delay( | |||
1308 | samples_in = US_TO_SAMPLES( | 1292 | samples_in = US_TO_SAMPLES( |
1309 | dac33->burst_rate, | 1293 | dac33->burst_rate, |
1310 | time_delta); | 1294 | time_delta); |
1311 | delay = MODE7_LTHR + samples_in - samples_out; | 1295 | delay = DAC33_MODE7_MARGIN + samples_in - samples_out; |
1312 | 1296 | ||
1313 | if (unlikely(delay > uthr)) | 1297 | if (unlikely(delay > uthr)) |
1314 | delay = uthr; | 1298 | delay = uthr; |
@@ -1415,7 +1399,7 @@ static int dac33_soc_probe(struct snd_soc_codec *codec) | |||
1415 | 1399 | ||
1416 | codec->control_data = dac33->control_data; | 1400 | codec->control_data = dac33->control_data; |
1417 | codec->hw_write = (hw_write_t) i2c_master_send; | 1401 | codec->hw_write = (hw_write_t) i2c_master_send; |
1418 | codec->idle_bias_off = 1; | 1402 | codec->dapm.idle_bias_off = 1; |
1419 | dac33->codec = codec; | 1403 | dac33->codec = codec; |
1420 | 1404 | ||
1421 | /* Read the tlv320dac33 ID registers */ | 1405 | /* Read the tlv320dac33 ID registers */ |
@@ -1459,14 +1443,10 @@ static int dac33_soc_probe(struct snd_soc_codec *codec) | |||
1459 | snd_soc_add_controls(codec, dac33_snd_controls, | 1443 | snd_soc_add_controls(codec, dac33_snd_controls, |
1460 | ARRAY_SIZE(dac33_snd_controls)); | 1444 | ARRAY_SIZE(dac33_snd_controls)); |
1461 | /* Only add the FIFO controls, if we have valid IRQ number */ | 1445 | /* Only add the FIFO controls, if we have valid IRQ number */ |
1462 | if (dac33->irq >= 0) { | 1446 | if (dac33->irq >= 0) |
1463 | snd_soc_add_controls(codec, dac33_mode_snd_controls, | 1447 | snd_soc_add_controls(codec, dac33_mode_snd_controls, |
1464 | ARRAY_SIZE(dac33_mode_snd_controls)); | 1448 | ARRAY_SIZE(dac33_mode_snd_controls)); |
1465 | /* FIFO usage controls only, if autoio config is not selected */ | 1449 | |
1466 | if (!dac33->auto_fifo_config) | ||
1467 | snd_soc_add_controls(codec, dac33_fifo_snd_controls, | ||
1468 | ARRAY_SIZE(dac33_fifo_snd_controls)); | ||
1469 | } | ||
1470 | dac33_add_widgets(codec); | 1450 | dac33_add_widgets(codec); |
1471 | 1451 | ||
1472 | err_power: | 1452 | err_power: |
@@ -1515,7 +1495,7 @@ static struct snd_soc_codec_driver soc_codec_dev_tlv320dac33 = { | |||
1515 | 1495 | ||
1516 | #define DAC33_RATES (SNDRV_PCM_RATE_44100 | \ | 1496 | #define DAC33_RATES (SNDRV_PCM_RATE_44100 | \ |
1517 | SNDRV_PCM_RATE_48000) | 1497 | SNDRV_PCM_RATE_48000) |
1518 | #define DAC33_FORMATS SNDRV_PCM_FMTBIT_S16_LE | 1498 | #define DAC33_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE) |
1519 | 1499 | ||
1520 | static struct snd_soc_dai_ops dac33_dai_ops = { | 1500 | static struct snd_soc_dai_ops dac33_dai_ops = { |
1521 | .startup = dac33_startup, | 1501 | .startup = dac33_startup, |
@@ -1563,17 +1543,11 @@ static int __devinit dac33_i2c_probe(struct i2c_client *client, | |||
1563 | 1543 | ||
1564 | dac33->power_gpio = pdata->power_gpio; | 1544 | dac33->power_gpio = pdata->power_gpio; |
1565 | dac33->burst_bclkdiv = pdata->burst_bclkdiv; | 1545 | dac33->burst_bclkdiv = pdata->burst_bclkdiv; |
1566 | /* Pre calculate the burst rate */ | ||
1567 | dac33->burst_rate = BURST_BASEFREQ_HZ / dac33->burst_bclkdiv / 32; | ||
1568 | dac33->keep_bclk = pdata->keep_bclk; | 1546 | dac33->keep_bclk = pdata->keep_bclk; |
1569 | dac33->auto_fifo_config = pdata->auto_fifo_config; | ||
1570 | dac33->mode1_latency = pdata->mode1_latency; | 1547 | dac33->mode1_latency = pdata->mode1_latency; |
1571 | if (!dac33->mode1_latency) | 1548 | if (!dac33->mode1_latency) |
1572 | dac33->mode1_latency = 10000; /* 10ms */ | 1549 | dac33->mode1_latency = 10000; /* 10ms */ |
1573 | dac33->irq = client->irq; | 1550 | dac33->irq = client->irq; |
1574 | dac33->nsample = NSAMPLE_MAX; | ||
1575 | dac33->nsample_max = NSAMPLE_MAX; | ||
1576 | dac33->uthr = MODE7_UTHR; | ||
1577 | /* Disable FIFO use by default */ | 1551 | /* Disable FIFO use by default */ |
1578 | dac33->fifo_mode = DAC33_FIFO_BYPASS; | 1552 | dac33->fifo_mode = DAC33_FIFO_BYPASS; |
1579 | 1553 | ||