diff options
author | Peter Ujfalusi <peter.ujfalusi@nokia.com> | 2010-07-28 08:26:54 -0400 |
---|---|---|
committer | Liam Girdwood <lrg@slimlogic.co.uk> | 2010-07-29 05:21:04 -0400 |
commit | f430a27f05d42d26d3e438aa262a92565170573f (patch) | |
tree | f448771488ceeda1aa3488d166d2d9a4302dc2b8 | |
parent | b93cc9f19bade9e9ddd41958352168dc0d266f48 (diff) |
ASoC: tlv320dac33: Revisit the FIFO Mode1 handling
Replace the hardwired latency definition with platform data
parameter, and simplify the nSample parameter calculation.
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>
-rw-r--r-- | include/sound/tlv320dac33-plat.h | 1 | ||||
-rw-r--r-- | sound/soc/codecs/tlv320dac33.c | 71 |
2 files changed, 35 insertions, 37 deletions
diff --git a/include/sound/tlv320dac33-plat.h b/include/sound/tlv320dac33-plat.h index 3f428d53195b..1aa7bdbc208c 100644 --- a/include/sound/tlv320dac33-plat.h +++ b/include/sound/tlv320dac33-plat.h | |||
@@ -15,6 +15,7 @@ | |||
15 | 15 | ||
16 | struct tlv320dac33_platform_data { | 16 | struct tlv320dac33_platform_data { |
17 | int power_gpio; | 17 | int power_gpio; |
18 | int mode1_latency; /* latency caused by the i2c writes in us */ | ||
18 | int keep_bclk; /* Keep the BCLK running in FIFO modes */ | 19 | int keep_bclk; /* Keep the BCLK running in FIFO modes */ |
19 | u8 burst_bclkdiv; | 20 | u8 burst_bclkdiv; |
20 | }; | 21 | }; |
diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c index 2fa946ce23a2..ced6fbbc9d91 100644 --- a/sound/soc/codecs/tlv320dac33.c +++ b/sound/soc/codecs/tlv320dac33.c | |||
@@ -49,8 +49,6 @@ | |||
49 | 49 | ||
50 | #define NSAMPLE_MAX 5700 | 50 | #define NSAMPLE_MAX 5700 |
51 | 51 | ||
52 | #define LATENCY_TIME_MS 20 | ||
53 | |||
54 | #define MODE7_LTHR 10 | 52 | #define MODE7_LTHR 10 |
55 | #define MODE7_UTHR (DAC33_BUFFER_SIZE_SAMPLES - 10) | 53 | #define MODE7_UTHR (DAC33_BUFFER_SIZE_SAMPLES - 10) |
56 | 54 | ||
@@ -107,6 +105,8 @@ struct tlv320dac33_priv { | |||
107 | * this */ | 105 | * this */ |
108 | enum dac33_fifo_modes fifo_mode;/* FIFO mode selection */ | 106 | enum dac33_fifo_modes fifo_mode;/* FIFO mode selection */ |
109 | unsigned int nsample; /* burst read amount from host */ | 107 | unsigned int nsample; /* burst read amount from host */ |
108 | int mode1_latency; /* latency caused by the i2c writes in | ||
109 | * us */ | ||
110 | u8 burst_bclkdiv; /* BCLK divider value in burst mode */ | 110 | u8 burst_bclkdiv; /* BCLK divider value in burst mode */ |
111 | unsigned int burst_rate; /* Interface speed in Burst modes */ | 111 | unsigned int burst_rate; /* Interface speed in Burst modes */ |
112 | 112 | ||
@@ -649,7 +649,7 @@ static inline void dac33_prefill_handler(struct tlv320dac33_priv *dac33) | |||
649 | switch (dac33->fifo_mode) { | 649 | switch (dac33->fifo_mode) { |
650 | case DAC33_FIFO_MODE1: | 650 | case DAC33_FIFO_MODE1: |
651 | dac33_write16(codec, DAC33_NSAMPLE_MSB, | 651 | dac33_write16(codec, DAC33_NSAMPLE_MSB, |
652 | DAC33_THRREG(dac33->nsample + dac33->alarm_threshold)); | 652 | DAC33_THRREG(dac33->nsample)); |
653 | 653 | ||
654 | /* Take the timestamps */ | 654 | /* Take the timestamps */ |
655 | spin_lock_irq(&dac33->lock); | 655 | spin_lock_irq(&dac33->lock); |
@@ -798,6 +798,10 @@ static void dac33_shutdown(struct snd_pcm_substream *substream, | |||
798 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | 798 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); |
799 | 799 | ||
800 | dac33->substream = NULL; | 800 | dac33->substream = NULL; |
801 | |||
802 | /* Reset the nSample restrictions */ | ||
803 | dac33->nsample_min = 0; | ||
804 | dac33->nsample_max = NSAMPLE_MAX; | ||
801 | } | 805 | } |
802 | 806 | ||
803 | static int dac33_hw_params(struct snd_pcm_substream *substream, | 807 | static int dac33_hw_params(struct snd_pcm_substream *substream, |
@@ -1040,48 +1044,38 @@ static void dac33_calculate_times(struct snd_pcm_substream *substream) | |||
1040 | struct snd_soc_device *socdev = rtd->socdev; | 1044 | struct snd_soc_device *socdev = rtd->socdev; |
1041 | struct snd_soc_codec *codec = socdev->card->codec; | 1045 | struct snd_soc_codec *codec = socdev->card->codec; |
1042 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); | 1046 | struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); |
1047 | unsigned int period_size = substream->runtime->period_size; | ||
1048 | unsigned int rate = substream->runtime->rate; | ||
1043 | unsigned int nsample_limit; | 1049 | unsigned int nsample_limit; |
1044 | 1050 | ||
1045 | /* In bypass mode we don't need to calculate */ | 1051 | /* In bypass mode we don't need to calculate */ |
1046 | if (!dac33->fifo_mode) | 1052 | if (!dac33->fifo_mode) |
1047 | return; | 1053 | return; |
1048 | 1054 | ||
1049 | /* Number of samples (16bit, stereo) in one period */ | ||
1050 | dac33->nsample_min = snd_pcm_lib_period_bytes(substream) / 4; | ||
1051 | |||
1052 | /* Number of samples (16bit, stereo) in ALSA buffer */ | ||
1053 | dac33->nsample_max = snd_pcm_lib_buffer_bytes(substream) / 4; | ||
1054 | /* Subtract one period from the total */ | ||
1055 | dac33->nsample_max -= dac33->nsample_min; | ||
1056 | |||
1057 | /* Number of samples for LATENCY_TIME_MS / 2 */ | ||
1058 | dac33->alarm_threshold = substream->runtime->rate / | ||
1059 | (1000 / (LATENCY_TIME_MS / 2)); | ||
1060 | |||
1061 | /* Find and fix up the lowest nsmaple limit */ | ||
1062 | nsample_limit = substream->runtime->rate / (1000 / LATENCY_TIME_MS); | ||
1063 | |||
1064 | if (dac33->nsample_min < nsample_limit) | ||
1065 | dac33->nsample_min = nsample_limit; | ||
1066 | |||
1067 | if (dac33->nsample < dac33->nsample_min) | ||
1068 | dac33->nsample = dac33->nsample_min; | ||
1069 | |||
1070 | /* | ||
1071 | * Find and fix up the highest nsmaple limit | ||
1072 | * In order to not overflow the DAC33 buffer substract the | ||
1073 | * alarm_threshold value from the size of the DAC33 buffer | ||
1074 | */ | ||
1075 | nsample_limit = DAC33_BUFFER_SIZE_SAMPLES - dac33->alarm_threshold; | ||
1076 | |||
1077 | if (dac33->nsample_max > nsample_limit) | ||
1078 | dac33->nsample_max = nsample_limit; | ||
1079 | |||
1080 | if (dac33->nsample > dac33->nsample_max) | ||
1081 | dac33->nsample = dac33->nsample_max; | ||
1082 | |||
1083 | switch (dac33->fifo_mode) { | 1055 | switch (dac33->fifo_mode) { |
1084 | case DAC33_FIFO_MODE1: | 1056 | case DAC33_FIFO_MODE1: |
1057 | /* Number of samples under i2c latency */ | ||
1058 | dac33->alarm_threshold = US_TO_SAMPLES(rate, | ||
1059 | dac33->mode1_latency); | ||
1060 | /* nSample time shall not be shorter than i2c latency */ | ||
1061 | dac33->nsample_min = dac33->alarm_threshold; | ||
1062 | /* | ||
1063 | * nSample should not be bigger than alsa buffer minus | ||
1064 | * size of one period to avoid overruns | ||
1065 | */ | ||
1066 | dac33->nsample_max = substream->runtime->buffer_size - | ||
1067 | period_size; | ||
1068 | nsample_limit = DAC33_BUFFER_SIZE_SAMPLES - | ||
1069 | dac33->alarm_threshold; | ||
1070 | if (dac33->nsample_max > nsample_limit) | ||
1071 | dac33->nsample_max = nsample_limit; | ||
1072 | |||
1073 | /* Correct the nSample if it is outside of the ranges */ | ||
1074 | if (dac33->nsample < dac33->nsample_min) | ||
1075 | dac33->nsample = dac33->nsample_min; | ||
1076 | if (dac33->nsample > dac33->nsample_max) | ||
1077 | dac33->nsample = dac33->nsample_max; | ||
1078 | |||
1085 | dac33->mode1_us_burst = SAMPLES_TO_US(dac33->burst_rate, | 1079 | dac33->mode1_us_burst = SAMPLES_TO_US(dac33->burst_rate, |
1086 | dac33->nsample); | 1080 | dac33->nsample); |
1087 | dac33->t_stamp1 = 0; | 1081 | dac33->t_stamp1 = 0; |
@@ -1519,6 +1513,9 @@ static int __devinit dac33_i2c_probe(struct i2c_client *client, | |||
1519 | /* Pre calculate the burst rate */ | 1513 | /* Pre calculate the burst rate */ |
1520 | dac33->burst_rate = BURST_BASEFREQ_HZ / dac33->burst_bclkdiv / 32; | 1514 | dac33->burst_rate = BURST_BASEFREQ_HZ / dac33->burst_bclkdiv / 32; |
1521 | dac33->keep_bclk = pdata->keep_bclk; | 1515 | dac33->keep_bclk = pdata->keep_bclk; |
1516 | dac33->mode1_latency = pdata->mode1_latency; | ||
1517 | if (!dac33->mode1_latency) | ||
1518 | dac33->mode1_latency = 10000; /* 10ms */ | ||
1522 | dac33->irq = client->irq; | 1519 | dac33->irq = client->irq; |
1523 | dac33->nsample = NSAMPLE_MAX; | 1520 | dac33->nsample = NSAMPLE_MAX; |
1524 | dac33->nsample_max = NSAMPLE_MAX; | 1521 | dac33->nsample_max = NSAMPLE_MAX; |