aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sound/soc/codecs/tlv320dac33.c157
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
439static 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
450static 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
473static 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
484static 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
506static int dac33_get_fifo_mode(struct snd_kcontrol *kcontrol, 431static 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
590static 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 */
598static const struct snd_kcontrol_new dac33_dapm_abypassl_control = 516static 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
862static int dac33_hw_params(struct snd_pcm_substream *substream, 776static 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
1149 dac33->mode1_us_burst = SAMPLES_TO_US(dac33->burst_rate, 1043 dac33->mode1_us_burst = SAMPLES_TO_US(dac33->burst_rate,
1150 dac33->nsample); 1044 dac33->nsample);
@@ -1152,16 +1046,13 @@ static void dac33_calculate_times(struct snd_pcm_substream *substream)
1152 dac33->t_stamp2 = 0; 1046 dac33->t_stamp2 = 0;
1153 break; 1047 break;
1154 case DAC33_FIFO_MODE7: 1048 case DAC33_FIFO_MODE7:
1155 if (dac33->auto_fifo_config) { 1049 dac33->uthr = UTHR_FROM_PERIOD_SIZE(period_size, rate,
1156 dac33->uthr = UTHR_FROM_PERIOD_SIZE( 1050 dac33->burst_rate) + 9;
1157 period_size, 1051 if (dac33->uthr > MODE7_UTHR)
1158 rate, 1052 dac33->uthr = MODE7_UTHR;
1159 dac33->burst_rate) + 9; 1053 if (dac33->uthr < (MODE7_LTHR + 10))
1160 if (dac33->uthr > MODE7_UTHR) 1054 dac33->uthr = (MODE7_LTHR + 10);
1161 dac33->uthr = MODE7_UTHR; 1055
1162 if (dac33->uthr < (MODE7_LTHR + 10))
1163 dac33->uthr = (MODE7_LTHR + 10);
1164 }
1165 dac33->mode7_us_to_lthr = 1056 dac33->mode7_us_to_lthr =
1166 SAMPLES_TO_US(substream->runtime->rate, 1057 SAMPLES_TO_US(substream->runtime->rate,
1167 dac33->uthr - MODE7_LTHR + 1); 1058 dac33->uthr - MODE7_LTHR + 1);
@@ -1486,14 +1377,10 @@ static int dac33_soc_probe(struct snd_soc_codec *codec)
1486 snd_soc_add_controls(codec, dac33_snd_controls, 1377 snd_soc_add_controls(codec, dac33_snd_controls,
1487 ARRAY_SIZE(dac33_snd_controls)); 1378 ARRAY_SIZE(dac33_snd_controls));
1488 /* Only add the FIFO controls, if we have valid IRQ number */ 1379 /* Only add the FIFO controls, if we have valid IRQ number */
1489 if (dac33->irq >= 0) { 1380 if (dac33->irq >= 0)
1490 snd_soc_add_controls(codec, dac33_mode_snd_controls, 1381 snd_soc_add_controls(codec, dac33_mode_snd_controls,
1491 ARRAY_SIZE(dac33_mode_snd_controls)); 1382 ARRAY_SIZE(dac33_mode_snd_controls));
1492 /* FIFO usage controls only, if autoio config is not selected */ 1383
1493 if (!dac33->auto_fifo_config)
1494 snd_soc_add_controls(codec, dac33_fifo_snd_controls,
1495 ARRAY_SIZE(dac33_fifo_snd_controls));
1496 }
1497 dac33_add_widgets(codec); 1384 dac33_add_widgets(codec);
1498 1385
1499err_power: 1386err_power:
@@ -1593,14 +1480,10 @@ static int __devinit dac33_i2c_probe(struct i2c_client *client,
1593 /* Pre calculate the burst rate */ 1480 /* Pre calculate the burst rate */
1594 dac33->burst_rate = BURST_BASEFREQ_HZ / dac33->burst_bclkdiv / 32; 1481 dac33->burst_rate = BURST_BASEFREQ_HZ / dac33->burst_bclkdiv / 32;
1595 dac33->keep_bclk = pdata->keep_bclk; 1482 dac33->keep_bclk = pdata->keep_bclk;
1596 dac33->auto_fifo_config = pdata->auto_fifo_config;
1597 dac33->mode1_latency = pdata->mode1_latency; 1483 dac33->mode1_latency = pdata->mode1_latency;
1598 if (!dac33->mode1_latency) 1484 if (!dac33->mode1_latency)
1599 dac33->mode1_latency = 10000; /* 10ms */ 1485 dac33->mode1_latency = 10000; /* 10ms */
1600 dac33->irq = client->irq; 1486 dac33->irq = client->irq;
1601 dac33->nsample = NSAMPLE_MAX;
1602 dac33->nsample_max = NSAMPLE_MAX;
1603 dac33->uthr = MODE7_UTHR;
1604 /* Disable FIFO use by default */ 1487 /* Disable FIFO use by default */
1605 dac33->fifo_mode = DAC33_FIFO_BYPASS; 1488 dac33->fifo_mode = DAC33_FIFO_BYPASS;
1606 1489