summaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorShengjiu Wang <b02247@freescale.com>2014-07-02 17:24:45 +0800
committerNitin Garg <nitin.garg@freescale.com>2015-01-15 21:17:58 -0600
commit204aa5280ca6979596f326aefe897e75ebcd6aa2 (patch)
tree26862c354c68829c876a72f60f35cb8c0a6c248a /sound
parent0709f079c4bd78fac88e06d7dfb5e77cf3a47e8a (diff)
ENGR00320849-1 ASoC: cs4xx8: fix the setting of Functional mode
Failed case: arecord -Dhw:0,1 -f S16_LE -r 96000 -c 2 -traw | aplay -Dhw:0,0 -f S16_LE -r 96000 -c 2 -traw. There is no sound when use this case.The reason is that the setting of Functional mode is not correct. Signed-off-by: Shengjiu Wang <b02247@freescale.com> (cherry picked from commit be1ef3bb8da5c263345ebdad4a7c218a095d0f48)
Diffstat (limited to 'sound')
-rw-r--r--sound/soc/codecs/cs42xx8.c108
1 files changed, 89 insertions, 19 deletions
diff --git a/sound/soc/codecs/cs42xx8.c b/sound/soc/codecs/cs42xx8.c
index 1e2a44732a8e..b7f7db54ca24 100644
--- a/sound/soc/codecs/cs42xx8.c
+++ b/sound/soc/codecs/cs42xx8.c
@@ -44,6 +44,7 @@ struct cs42xx8_priv {
bool slave_mode;
unsigned long sysclk;
+ int rate[2];
};
/* -127.5dB to 0dB with step of 0.5dB */
@@ -185,21 +186,18 @@ static const struct snd_soc_dapm_route cs42xx8_adc3_dapm_routes[] = {
};
struct cs42xx8_ratios {
- unsigned int ratio;
- unsigned char speed;
- unsigned char mclk;
+ unsigned int mfreq;
+ unsigned int min_mclk;
+ unsigned int max_mclk;
+ unsigned int ratio[3];
};
static const struct cs42xx8_ratios cs42xx8_ratios[] = {
- { 64, CS42XX8_FM_QUAD, CS42XX8_FUNCMOD_MFREQ_256(4) },
- { 96, CS42XX8_FM_QUAD, CS42XX8_FUNCMOD_MFREQ_384(4) },
- { 128, CS42XX8_FM_QUAD, CS42XX8_FUNCMOD_MFREQ_512(4) },
- { 192, CS42XX8_FM_QUAD, CS42XX8_FUNCMOD_MFREQ_768(4) },
- { 256, CS42XX8_FM_SINGLE, CS42XX8_FUNCMOD_MFREQ_256(1) },
- { 384, CS42XX8_FM_SINGLE, CS42XX8_FUNCMOD_MFREQ_384(1) },
- { 512, CS42XX8_FM_SINGLE, CS42XX8_FUNCMOD_MFREQ_512(1) },
- { 768, CS42XX8_FM_SINGLE, CS42XX8_FUNCMOD_MFREQ_768(1) },
- { 1024, CS42XX8_FM_SINGLE, CS42XX8_FUNCMOD_MFREQ_1024(1) }
+ { 0, 1029000, 12800000, {256, 128, 64} },
+ { 2, 1536000, 19200000, {384, 192, 96} },
+ { 4, 2048000, 25600000, {512, 256, 128} },
+ { 6, 3072000, 38400000, {768, 384, 192} },
+ { 8, 4096000, 51200000, {1024, 512, 256} },
};
static int cs42xx8_set_dai_sysclk(struct snd_soc_dai *codec_dai,
@@ -266,12 +264,67 @@ static int cs42xx8_hw_params(struct snd_pcm_substream *substream,
struct snd_soc_codec *codec = dai->codec;
struct cs42xx8_priv *cs42xx8 = snd_soc_codec_get_drvdata(codec);
bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
- u32 ratio = cs42xx8->sysclk / params_rate(params);
+ u32 rate = params_rate(params);
+ u32 ratio_tx, ratio_rx;
+ u32 rate_tx, rate_rx;
+ u32 fm_tx, fm_rx;
u32 i, fm, val, mask;
- for (i = 0; i < ARRAY_SIZE(cs42xx8_ratios); i++) {
- if (cs42xx8_ratios[i].ratio == ratio)
- break;
+ rate_tx = tx ? rate : cs42xx8->rate[0];
+ rate_rx = tx ? cs42xx8->rate[1] : rate;
+
+ ratio_tx = rate_tx > 0 ? cs42xx8->sysclk / rate_tx : 0;
+ ratio_rx = rate_rx > 0 ? cs42xx8->sysclk / rate_rx : 0;
+
+ if (cs42xx8->slave_mode) {
+ fm_rx = CS42XX8_FM_AUTO;
+ fm_tx = CS42XX8_FM_AUTO;
+ } else {
+ if (rate_tx >= 0 && rate_tx < 50000)
+ fm_tx = CS42XX8_FM_SINGLE;
+ else if (rate_tx > 50000 && rate_tx < 100000)
+ fm_tx = CS42XX8_FM_DOUBLE;
+ else if (rate_tx > 100000 && rate_tx < 200000)
+ fm_tx = CS42XX8_FM_QUAD;
+ else {
+ dev_err(codec->dev, "unsupported sample rate or rate combine\n");
+ return -EINVAL;
+ }
+
+ if (rate_rx >= 0 && rate_rx < 50000)
+ fm_rx = CS42XX8_FM_SINGLE;
+ else if (rate_rx > 50000 && rate_rx < 100000)
+ fm_rx = CS42XX8_FM_DOUBLE;
+ else if (rate_rx > 100000 && rate_rx < 200000)
+ fm_rx = CS42XX8_FM_QUAD;
+ else {
+ dev_err(codec->dev, "unsupported sample rate or rate combine\n");
+ return -EINVAL;
+ }
+ }
+
+ fm = tx ? fm_tx : fm_rx;
+
+ if (fm == CS42XX8_FM_AUTO) {
+ for (i = 0; i < ARRAY_SIZE(cs42xx8_ratios); i++) {
+ if ((ratio_tx > 0 ? (cs42xx8_ratios[i].ratio[0] == ratio_tx ||
+ cs42xx8_ratios[i].ratio[1] == ratio_tx ||
+ cs42xx8_ratios[i].ratio[2] == ratio_tx) : true) &&
+ (ratio_rx > 0 ? (cs42xx8_ratios[i].ratio[0] == ratio_rx ||
+ cs42xx8_ratios[i].ratio[1] == ratio_rx ||
+ cs42xx8_ratios[i].ratio[2] == ratio_rx) : true) &&
+ cs42xx8->sysclk >= cs42xx8_ratios[i].min_mclk &&
+ cs42xx8->sysclk <= cs42xx8_ratios[i].max_mclk)
+ break;
+ }
+ } else {
+ for (i = 0; i < ARRAY_SIZE(cs42xx8_ratios); i++) {
+ if ((ratio_tx > 0 ? (cs42xx8_ratios[i].ratio[fm_tx] == ratio_tx) : true) &&
+ (ratio_rx > 0 ? (cs42xx8_ratios[i].ratio[fm_rx] == ratio_rx) : true) &&
+ cs42xx8->sysclk >= cs42xx8_ratios[i].min_mclk &&
+ cs42xx8->sysclk <= cs42xx8_ratios[i].max_mclk)
+ break;
+ }
}
if (i == ARRAY_SIZE(cs42xx8_ratios)) {
@@ -279,10 +332,10 @@ static int cs42xx8_hw_params(struct snd_pcm_substream *substream,
return -EINVAL;
}
- mask = CS42XX8_FUNCMOD_MFREQ_MASK;
- val = cs42xx8_ratios[i].mclk;
+ cs42xx8->rate[substream->stream] = rate;
- fm = cs42xx8->slave_mode ? CS42XX8_FM_AUTO : cs42xx8_ratios[i].speed;
+ mask = CS42XX8_FUNCMOD_MFREQ_MASK;
+ val = cs42xx8_ratios[i].mfreq;
regmap_update_bits(cs42xx8->regmap, CS42XX8_FUNCMOD,
CS42XX8_FUNCMOD_xC_FM_MASK(tx) | mask,
@@ -291,6 +344,22 @@ static int cs42xx8_hw_params(struct snd_pcm_substream *substream,
return 0;
}
+static int cs42xx8_hw_free(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct snd_soc_codec *codec = rtd->codec;
+ struct cs42xx8_priv *cs42xx8 = snd_soc_codec_get_drvdata(codec);
+ bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
+
+ cs42xx8->rate[substream->stream] = 0;
+
+ regmap_update_bits(cs42xx8->regmap, CS42XX8_FUNCMOD,
+ CS42XX8_FUNCMOD_xC_FM_MASK(tx),
+ CS42XX8_FUNCMOD_xC_FM(tx, CS42XX8_FM_AUTO));
+ return 0;
+}
+
static int cs42xx8_digital_mute(struct snd_soc_dai *dai, int mute)
{
struct snd_soc_codec *codec = dai->codec;
@@ -306,6 +375,7 @@ static const struct snd_soc_dai_ops cs42xx8_dai_ops = {
.set_fmt = cs42xx8_set_dai_fmt,
.set_sysclk = cs42xx8_set_dai_sysclk,
.hw_params = cs42xx8_hw_params,
+ .hw_free = cs42xx8_hw_free,
.digital_mute = cs42xx8_digital_mute,
};