diff options
author | Peter Ujfalusi <peter.ujfalusi@nokia.com> | 2010-12-22 03:45:17 -0500 |
---|---|---|
committer | Liam Girdwood <lrg@slimlogic.co.uk> | 2010-12-23 09:38:33 -0500 |
commit | 549675ed658761b9a84cb579795c9ec1da227fea (patch) | |
tree | e654797f639078ca02b9cd3ebf2501642a08c4cb /sound/soc/codecs | |
parent | 3591f4cd53a3835e6d59dd509337503c2c61173e (diff) |
ASoC: tlv320dac33: Some cleanup for 32/24 bit support
Change the structure of FIFO handling in order to
pave the way for adding 32/24 bit audio support.
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@nokia.com>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
Diffstat (limited to 'sound/soc/codecs')
-rw-r--r-- | sound/soc/codecs/tlv320dac33.c | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c index c574ae238973..05a4e9fade47 100644 --- a/sound/soc/codecs/tlv320dac33.c +++ b/sound/soc/codecs/tlv320dac33.c | |||
@@ -42,12 +42,15 @@ | |||
42 | #include <sound/tlv320dac33-plat.h> | 42 | #include <sound/tlv320dac33-plat.h> |
43 | #include "tlv320dac33.h" | 43 | #include "tlv320dac33.h" |
44 | 44 | ||
45 | #define DAC33_BUFFER_SIZE_BYTES 24576 /* bytes, 12288 16 bit words, | 45 | /* |
46 | * 6144 stereo */ | 46 | * The internal FIFO is 24576 bytes long |
47 | #define DAC33_BUFFER_SIZE_SAMPLES 6144 | 47 | * It can be configured to hold 16bit or 24bit samples |
48 | 48 | * In 16bit configuration the FIFO can hold 6144 stereo samples | |
49 | #define MODE7_LTHR 10 | 49 | * In 24bit configuration the FIFO can hold 4096 stereo samples |
50 | #define MODE7_UTHR (DAC33_BUFFER_SIZE_SAMPLES - 10) | 50 | */ |
51 | #define DAC33_FIFO_SIZE_16BIT 6144 | ||
52 | #define DAC33_FIFO_SIZE_24BIT 4096 | ||
53 | #define DAC33_MODE7_MARGIN 10 /* Safety margin for FIFO in Mode7 */ | ||
51 | 54 | ||
52 | #define BURST_BASEFREQ_HZ 49152000 | 55 | #define BURST_BASEFREQ_HZ 49152000 |
53 | 56 | ||
@@ -98,6 +101,7 @@ struct tlv320dac33_priv { | |||
98 | 101 | ||
99 | 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 */ |
100 | 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 */ | ||
101 | unsigned int nsample; /* burst read amount from host */ | 105 | unsigned int nsample; /* burst read amount from host */ |
102 | int mode1_latency; /* latency caused by the i2c writes in | 106 | int mode1_latency; /* latency caused by the i2c writes in |
103 | * us */ | 107 | * us */ |
@@ -650,7 +654,7 @@ static inline void dac33_prefill_handler(struct tlv320dac33_priv *dac33) | |||
650 | spin_unlock_irq(&dac33->lock); | 654 | spin_unlock_irq(&dac33->lock); |
651 | 655 | ||
652 | dac33_write16(codec, DAC33_PREFILL_MSB, | 656 | dac33_write16(codec, DAC33_PREFILL_MSB, |
653 | DAC33_THRREG(MODE7_LTHR)); | 657 | DAC33_THRREG(DAC33_MODE7_MARGIN)); |
654 | 658 | ||
655 | /* Enable Upper Threshold IRQ */ | 659 | /* Enable Upper Threshold IRQ */ |
656 | dac33_write(codec, DAC33_FIFO_IRQ_MASK, DAC33_MUT); | 660 | dac33_write(codec, DAC33_FIFO_IRQ_MASK, DAC33_MUT); |
@@ -773,12 +777,15 @@ static void dac33_shutdown(struct snd_pcm_substream *substream, | |||
773 | dac33->substream = NULL; | 777 | dac33->substream = NULL; |
774 | } | 778 | } |
775 | 779 | ||
780 | #define CALC_BURST_RATE(bclkdiv, bclk_per_sample) \ | ||
781 | (BURST_BASEFREQ_HZ / bclkdiv / bclk_per_sample) | ||
776 | static int dac33_hw_params(struct snd_pcm_substream *substream, | 782 | static int dac33_hw_params(struct snd_pcm_substream *substream, |
777 | struct snd_pcm_hw_params *params, | 783 | struct snd_pcm_hw_params *params, |
778 | struct snd_soc_dai *dai) | 784 | struct snd_soc_dai *dai) |
779 | { | 785 | { |
780 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 786 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
781 | struct snd_soc_codec *codec = rtd->codec; | 787 | struct snd_soc_codec *codec = rtd->codec; |
788 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | ||
782 | 789 | ||
783 | /* Check parameters for validity */ | 790 | /* Check parameters for validity */ |
784 | switch (params_rate(params)) { | 791 | switch (params_rate(params)) { |
@@ -793,6 +800,8 @@ static int dac33_hw_params(struct snd_pcm_substream *substream, | |||
793 | 800 | ||
794 | switch (params_format(params)) { | 801 | switch (params_format(params)) { |
795 | case SNDRV_PCM_FORMAT_S16_LE: | 802 | case SNDRV_PCM_FORMAT_S16_LE: |
803 | dac33->fifo_size = DAC33_FIFO_SIZE_16BIT; | ||
804 | dac33->burst_rate = CALC_BURST_RATE(dac33->burst_bclkdiv, 32); | ||
796 | break; | 805 | break; |
797 | default: | 806 | default: |
798 | dev_err(codec->dev, "unsupported format %d\n", | 807 | dev_err(codec->dev, "unsupported format %d\n", |
@@ -994,7 +1003,8 @@ static int dac33_prepare_chip(struct snd_pcm_substream *substream) | |||
994 | * at the bottom, and also at the top of the FIFO | 1003 | * at the bottom, and also at the top of the FIFO |
995 | */ | 1004 | */ |
996 | dac33_write16(codec, DAC33_UTHR_MSB, DAC33_THRREG(dac33->uthr)); | 1005 | dac33_write16(codec, DAC33_UTHR_MSB, DAC33_THRREG(dac33->uthr)); |
997 | dac33_write16(codec, DAC33_LTHR_MSB, DAC33_THRREG(MODE7_LTHR)); | 1006 | dac33_write16(codec, DAC33_LTHR_MSB, |
1007 | DAC33_THRREG(DAC33_MODE7_MARGIN)); | ||
998 | break; | 1008 | break; |
999 | default: | 1009 | default: |
1000 | break; | 1010 | break; |
@@ -1023,8 +1033,7 @@ static void dac33_calculate_times(struct snd_pcm_substream *substream) | |||
1023 | /* Number of samples under i2c latency */ | 1033 | /* Number of samples under i2c latency */ |
1024 | dac33->alarm_threshold = US_TO_SAMPLES(rate, | 1034 | dac33->alarm_threshold = US_TO_SAMPLES(rate, |
1025 | dac33->mode1_latency); | 1035 | dac33->mode1_latency); |
1026 | nsample_limit = DAC33_BUFFER_SIZE_SAMPLES - | 1036 | nsample_limit = dac33->fifo_size - dac33->alarm_threshold; |
1027 | dac33->alarm_threshold; | ||
1028 | 1037 | ||
1029 | if (period_size <= dac33->alarm_threshold) | 1038 | if (period_size <= dac33->alarm_threshold) |
1030 | /* | 1039 | /* |
@@ -1048,14 +1057,14 @@ static void dac33_calculate_times(struct snd_pcm_substream *substream) | |||
1048 | case DAC33_FIFO_MODE7: | 1057 | case DAC33_FIFO_MODE7: |
1049 | dac33->uthr = UTHR_FROM_PERIOD_SIZE(period_size, rate, | 1058 | dac33->uthr = UTHR_FROM_PERIOD_SIZE(period_size, rate, |
1050 | dac33->burst_rate) + 9; | 1059 | dac33->burst_rate) + 9; |
1051 | if (dac33->uthr > MODE7_UTHR) | 1060 | if (dac33->uthr > (dac33->fifo_size - DAC33_MODE7_MARGIN)) |
1052 | dac33->uthr = MODE7_UTHR; | 1061 | dac33->uthr = dac33->fifo_size - DAC33_MODE7_MARGIN; |
1053 | if (dac33->uthr < (MODE7_LTHR + 10)) | 1062 | if (dac33->uthr < (DAC33_MODE7_MARGIN + 10)) |
1054 | dac33->uthr = (MODE7_LTHR + 10); | 1063 | dac33->uthr = (DAC33_MODE7_MARGIN + 10); |
1055 | 1064 | ||
1056 | dac33->mode7_us_to_lthr = | 1065 | dac33->mode7_us_to_lthr = |
1057 | SAMPLES_TO_US(substream->runtime->rate, | 1066 | SAMPLES_TO_US(substream->runtime->rate, |
1058 | dac33->uthr - MODE7_LTHR + 1); | 1067 | dac33->uthr - DAC33_MODE7_MARGIN + 1); |
1059 | dac33->t_stamp1 = 0; | 1068 | dac33->t_stamp1 = 0; |
1060 | break; | 1069 | break; |
1061 | default: | 1070 | default: |
@@ -1173,8 +1182,8 @@ static snd_pcm_sframes_t dac33_dai_delay( | |||
1173 | samples += (samples_in - samples_out); | 1182 | samples += (samples_in - samples_out); |
1174 | 1183 | ||
1175 | if (likely(samples > 0)) | 1184 | if (likely(samples > 0)) |
1176 | delay = samples > DAC33_BUFFER_SIZE_SAMPLES ? | 1185 | delay = samples > dac33->fifo_size ? |
1177 | DAC33_BUFFER_SIZE_SAMPLES : samples; | 1186 | dac33->fifo_size : samples; |
1178 | else | 1187 | else |
1179 | delay = 0; | 1188 | delay = 0; |
1180 | } | 1189 | } |
@@ -1226,7 +1235,7 @@ static snd_pcm_sframes_t dac33_dai_delay( | |||
1226 | samples_in = US_TO_SAMPLES( | 1235 | samples_in = US_TO_SAMPLES( |
1227 | dac33->burst_rate, | 1236 | dac33->burst_rate, |
1228 | time_delta); | 1237 | time_delta); |
1229 | delay = MODE7_LTHR + samples_in - samples_out; | 1238 | delay = DAC33_MODE7_MARGIN + samples_in - samples_out; |
1230 | 1239 | ||
1231 | if (unlikely(delay > uthr)) | 1240 | if (unlikely(delay > uthr)) |
1232 | delay = uthr; | 1241 | delay = uthr; |
@@ -1477,8 +1486,6 @@ static int __devinit dac33_i2c_probe(struct i2c_client *client, | |||
1477 | 1486 | ||
1478 | dac33->power_gpio = pdata->power_gpio; | 1487 | dac33->power_gpio = pdata->power_gpio; |
1479 | dac33->burst_bclkdiv = pdata->burst_bclkdiv; | 1488 | dac33->burst_bclkdiv = pdata->burst_bclkdiv; |
1480 | /* Pre calculate the burst rate */ | ||
1481 | dac33->burst_rate = BURST_BASEFREQ_HZ / dac33->burst_bclkdiv / 32; | ||
1482 | dac33->keep_bclk = pdata->keep_bclk; | 1489 | dac33->keep_bclk = pdata->keep_bclk; |
1483 | dac33->mode1_latency = pdata->mode1_latency; | 1490 | dac33->mode1_latency = pdata->mode1_latency; |
1484 | if (!dac33->mode1_latency) | 1491 | if (!dac33->mode1_latency) |