diff options
| -rw-r--r-- | sound/soc/codecs/tlv320dac33.c | 157 |
1 files changed, 20 insertions, 137 deletions
diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c index 776ac80cc1a8..c574ae238973 100644 --- a/sound/soc/codecs/tlv320dac33.c +++ b/sound/soc/codecs/tlv320dac33.c | |||
| @@ -46,8 +46,6 @@ | |||
| 46 | * 6144 stereo */ | 46 | * 6144 stereo */ |
| 47 | #define DAC33_BUFFER_SIZE_SAMPLES 6144 | 47 | #define DAC33_BUFFER_SIZE_SAMPLES 6144 |
| 48 | 48 | ||
| 49 | #define NSAMPLE_MAX 5700 | ||
| 50 | |||
| 51 | #define MODE7_LTHR 10 | 49 | #define MODE7_LTHR 10 |
| 52 | #define MODE7_UTHR (DAC33_BUFFER_SIZE_SAMPLES - 10) | 50 | #define MODE7_UTHR (DAC33_BUFFER_SIZE_SAMPLES - 10) |
| 53 | 51 | ||
| @@ -99,16 +97,10 @@ struct tlv320dac33_priv { | |||
| 99 | unsigned int refclk; | 97 | unsigned int refclk; |
| 100 | 98 | ||
| 101 | unsigned int alarm_threshold; /* set to be half of LATENCY_TIME_MS */ | 99 | unsigned int alarm_threshold; /* set to be half of LATENCY_TIME_MS */ |
| 102 | unsigned int nsample_min; /* nsample should not be lower than | ||
| 103 | * this */ | ||
| 104 | unsigned int nsample_max; /* nsample should not be higher than | ||
| 105 | * this */ | ||
| 106 | enum dac33_fifo_modes fifo_mode;/* FIFO mode selection */ | 100 | enum dac33_fifo_modes fifo_mode;/* FIFO mode selection */ |
| 107 | unsigned int nsample; /* burst read amount from host */ | 101 | unsigned int nsample; /* burst read amount from host */ |
| 108 | int mode1_latency; /* latency caused by the i2c writes in | 102 | int mode1_latency; /* latency caused by the i2c writes in |
| 109 | * us */ | 103 | * us */ |
| 110 | int auto_fifo_config; /* Configure the FIFO based on the | ||
| 111 | * period size */ | ||
| 112 | u8 burst_bclkdiv; /* BCLK divider value in burst mode */ | 104 | u8 burst_bclkdiv; /* BCLK divider value in burst mode */ |
| 113 | unsigned int burst_rate; /* Interface speed in Burst modes */ | 105 | unsigned int burst_rate; /* Interface speed in Burst modes */ |
| 114 | 106 | ||
| @@ -436,73 +428,6 @@ static int dac33_playback_event(struct snd_soc_dapm_widget *w, | |||
| 436 | return 0; | 428 | return 0; |
| 437 | } | 429 | } |
| 438 | 430 | ||
| 439 | static int dac33_get_nsample(struct snd_kcontrol *kcontrol, | ||
| 440 | struct snd_ctl_elem_value *ucontrol) | ||
| 441 | { | ||
| 442 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
| 443 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | ||
| 444 | |||
| 445 | ucontrol->value.integer.value[0] = dac33->nsample; | ||
| 446 | |||
| 447 | return 0; | ||
| 448 | } | ||
| 449 | |||
| 450 | static int dac33_set_nsample(struct snd_kcontrol *kcontrol, | ||
| 451 | struct snd_ctl_elem_value *ucontrol) | ||
| 452 | { | ||
| 453 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
| 454 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | ||
| 455 | int ret = 0; | ||
| 456 | |||
| 457 | if (dac33->nsample == ucontrol->value.integer.value[0]) | ||
| 458 | return 0; | ||
| 459 | |||
| 460 | if (ucontrol->value.integer.value[0] < dac33->nsample_min || | ||
| 461 | ucontrol->value.integer.value[0] > dac33->nsample_max) { | ||
| 462 | ret = -EINVAL; | ||
| 463 | } else { | ||
| 464 | dac33->nsample = ucontrol->value.integer.value[0]; | ||
| 465 | /* Re calculate the burst time */ | ||
| 466 | dac33->mode1_us_burst = SAMPLES_TO_US(dac33->burst_rate, | ||
| 467 | dac33->nsample); | ||
| 468 | } | ||
| 469 | |||
| 470 | return ret; | ||
| 471 | } | ||
| 472 | |||
| 473 | static int dac33_get_uthr(struct snd_kcontrol *kcontrol, | ||
| 474 | struct snd_ctl_elem_value *ucontrol) | ||
| 475 | { | ||
| 476 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
| 477 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | ||
| 478 | |||
| 479 | ucontrol->value.integer.value[0] = dac33->uthr; | ||
| 480 | |||
| 481 | return 0; | ||
| 482 | } | ||
| 483 | |||
| 484 | static int dac33_set_uthr(struct snd_kcontrol *kcontrol, | ||
| 485 | struct snd_ctl_elem_value *ucontrol) | ||
| 486 | { | ||
| 487 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
| 488 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | ||
| 489 | int ret = 0; | ||
| 490 | |||
| 491 | if (dac33->substream) | ||
| 492 | return -EBUSY; | ||
| 493 | |||
| 494 | if (dac33->uthr == ucontrol->value.integer.value[0]) | ||
| 495 | return 0; | ||
| 496 | |||
| 497 | if (ucontrol->value.integer.value[0] < (MODE7_LTHR + 10) || | ||
| 498 | ucontrol->value.integer.value[0] > MODE7_UTHR) | ||
| 499 | ret = -EINVAL; | ||
| 500 | else | ||
| 501 | dac33->uthr = ucontrol->value.integer.value[0]; | ||
| 502 | |||
| 503 | return ret; | ||
| 504 | } | ||
| 505 | |||
| 506 | static int dac33_get_fifo_mode(struct snd_kcontrol *kcontrol, | 431 | static int dac33_get_fifo_mode(struct snd_kcontrol *kcontrol, |
| 507 | struct snd_ctl_elem_value *ucontrol) | 432 | struct snd_ctl_elem_value *ucontrol) |
| 508 | { | 433 | { |
| @@ -587,13 +512,6 @@ static const struct snd_kcontrol_new dac33_mode_snd_controls[] = { | |||
| 587 | dac33_get_fifo_mode, dac33_set_fifo_mode), | 512 | dac33_get_fifo_mode, dac33_set_fifo_mode), |
| 588 | }; | 513 | }; |
| 589 | 514 | ||
| 590 | static const struct snd_kcontrol_new dac33_fifo_snd_controls[] = { | ||
| 591 | SOC_SINGLE_EXT("nSample", 0, 0, 5900, 0, | ||
| 592 | dac33_get_nsample, dac33_set_nsample), | ||
| 593 | SOC_SINGLE_EXT("UTHR", 0, 0, MODE7_UTHR, 0, | ||
| 594 | dac33_get_uthr, dac33_set_uthr), | ||
| 595 | }; | ||
| 596 | |||
| 597 | /* Analog bypass */ | 515 | /* Analog bypass */ |
| 598 | static const struct snd_kcontrol_new dac33_dapm_abypassl_control = | 516 | static const struct snd_kcontrol_new dac33_dapm_abypassl_control = |
| 599 | SOC_DAPM_SINGLE("Switch", DAC33_LINEL_TO_LLO_VOL, 7, 1, 1); | 517 | SOC_DAPM_SINGLE("Switch", DAC33_LINEL_TO_LLO_VOL, 7, 1, 1); |
| @@ -853,10 +771,6 @@ static void dac33_shutdown(struct snd_pcm_substream *substream, | |||
| 853 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | 771 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); |
| 854 | 772 | ||
| 855 | dac33->substream = NULL; | 773 | dac33->substream = NULL; |
| 856 | |||
| 857 | /* Reset the nSample restrictions */ | ||
| 858 | dac33->nsample_min = 0; | ||
| 859 | dac33->nsample_max = NSAMPLE_MAX; | ||
| 860 | } | 774 | } |
| 861 | 775 | ||
| 862 | static int dac33_hw_params(struct snd_pcm_substream *substream, | 776 | static int dac33_hw_params(struct snd_pcm_substream *substream, |
| @@ -1112,39 +1026,19 @@ static void dac33_calculate_times(struct snd_pcm_substream *substream) | |||
| 1112 | nsample_limit = DAC33_BUFFER_SIZE_SAMPLES - | 1026 | nsample_limit = DAC33_BUFFER_SIZE_SAMPLES - |
| 1113 | dac33->alarm_threshold; | 1027 | dac33->alarm_threshold; |
| 1114 | 1028 | ||
| 1115 | if (dac33->auto_fifo_config) { | 1029 | if (period_size <= dac33->alarm_threshold) |
| 1116 | if (period_size <= dac33->alarm_threshold) | ||
| 1117 | /* | ||
| 1118 | * Configure nSamaple to number of periods, | ||
| 1119 | * which covers the latency requironment. | ||
| 1120 | */ | ||
| 1121 | dac33->nsample = period_size * | ||
| 1122 | ((dac33->alarm_threshold / period_size) + | ||
| 1123 | (dac33->alarm_threshold % period_size ? | ||
| 1124 | 1 : 0)); | ||
| 1125 | else if (period_size > nsample_limit) | ||
| 1126 | dac33->nsample = nsample_limit; | ||
| 1127 | else | ||
| 1128 | dac33->nsample = period_size; | ||
| 1129 | } else { | ||
| 1130 | /* nSample time shall not be shorter than i2c latency */ | ||
| 1131 | dac33->nsample_min = dac33->alarm_threshold; | ||
| 1132 | /* | 1030 | /* |
| 1133 | * nSample should not be bigger than alsa buffer minus | 1031 | * Configure nSamaple to number of periods, |
| 1134 | * size of one period to avoid overruns | 1032 | * which covers the latency requironment. |
| 1135 | */ | 1033 | */ |
| 1136 | dac33->nsample_max = substream->runtime->buffer_size - | 1034 | dac33->nsample = period_size * |
| 1137 | period_size; | 1035 | ((dac33->alarm_threshold / period_size) + |
| 1138 | 1036 | (dac33->alarm_threshold % period_size ? | |
| 1139 | if (dac33->nsample_max > nsample_limit) | 1037 | 1 : 0)); |
| 1140 | dac33->nsample_max = nsample_limit; | 1038 | else if (period_size > nsample_limit) |
| 1141 | 1039 | dac33->nsample = nsample_limit; | |
| 1142 | /* Correct the nSample if it is outside of the ranges */ | 1040 | else |
| 1143 | if (dac33->nsample < dac33->nsample_min) | 1041 | dac33->nsample = period_size; |
| 1144 | dac33->nsample = dac33->nsample_min; | ||
| 1145 | if (dac33->nsample > dac33->nsample_max) | ||
| 1146 | dac33->nsample = dac33->nsample_max; | ||
| 1147 | } | ||
| 1148 | 1042 | ||
