aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCharles Keepax <ckeepax@opensource.wolfsonmicro.com>2014-06-06 09:14:05 -0400
committerMark Brown <broonie@linaro.org>2014-06-09 16:19:50 -0400
commitcc9e92431ee9c7fe974266e0e6533a1a68e45539 (patch)
tree531abd966bb661d7c097f8074ec9f469fe5ed3c9
parented70f3a264e9f746eaf17c96ccc4c9b7eda742dc (diff)
ASoC: wm5102: Add controls to allow shaping of ultrasonic response
Add controls to allow custom shaping of the ultrasonic response. This custom shaping can be turned on/off at runtime, although, it should be noted that settings will not affect a currently open audio stream, they will be applied when the next audio stream is started. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--include/linux/mfd/arizona/core.h3
-rw-r--r--sound/soc/codecs/arizona.c34
-rw-r--r--sound/soc/codecs/wm5102.c62
3 files changed, 99 insertions, 0 deletions
diff --git a/include/linux/mfd/arizona/core.h b/include/linux/mfd/arizona/core.h
index 11783b511b9a..55926517d50b 100644
--- a/include/linux/mfd/arizona/core.h
+++ b/include/linux/mfd/arizona/core.h
@@ -113,6 +113,9 @@ struct arizona {
113 113
114 int tdm_width[ARIZONA_MAX_AIF]; 114 int tdm_width[ARIZONA_MAX_AIF];
115 int tdm_slots[ARIZONA_MAX_AIF]; 115 int tdm_slots[ARIZONA_MAX_AIF];
116
117 uint16_t dac_comp_coeff;
118 uint8_t dac_comp_enabled;
116}; 119};
117 120
118int arizona_clk32k_enable(struct arizona *arizona); 121int arizona_clk32k_enable(struct arizona *arizona);
diff --git a/sound/soc/codecs/arizona.c b/sound/soc/codecs/arizona.c
index e77f61c387f7..41b56ee6ff51 100644
--- a/sound/soc/codecs/arizona.c
+++ b/sound/soc/codecs/arizona.c
@@ -1127,6 +1127,31 @@ static int arizona_startup(struct snd_pcm_substream *substream,
1127 constraint); 1127 constraint);
1128} 1128}
1129 1129
1130static void arizona_wm5102_set_dac_comp(struct snd_soc_codec *codec,
1131 unsigned int rate)
1132{
1133 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
1134 struct arizona *arizona = priv->arizona;
1135 struct reg_default dac_comp[] = {
1136 { 0x80, 0x3 },
1137 { ARIZONA_DAC_COMP_1, 0 },
1138 { ARIZONA_DAC_COMP_2, 0 },
1139 { 0x80, 0x0 },
1140 };
1141
1142 mutex_lock(&codec->mutex);
1143
1144 dac_comp[1].def = arizona->dac_comp_coeff;
1145 if (rate >= 176400)
1146 dac_comp[2].def = arizona->dac_comp_enabled;
1147
1148 mutex_unlock(&codec->mutex);
1149
1150 regmap_multi_reg_write(arizona->regmap,
1151 dac_comp,
1152 ARRAY_SIZE(dac_comp));
1153}
1154
1130static int arizona_hw_params_rate(struct snd_pcm_substream *substream, 1155static int arizona_hw_params_rate(struct snd_pcm_substream *substream,
1131 struct snd_pcm_hw_params *params, 1156 struct snd_pcm_hw_params *params,
1132 struct snd_soc_dai *dai) 1157 struct snd_soc_dai *dai)
@@ -1153,6 +1178,15 @@ static int arizona_hw_params_rate(struct snd_pcm_substream *substream,
1153 1178
1154 switch (dai_priv->clk) { 1179 switch (dai_priv->clk) {
1155 case ARIZONA_CLK_SYSCLK: 1180 case ARIZONA_CLK_SYSCLK:
1181 switch (priv->arizona->type) {
1182 case WM5102:
1183 arizona_wm5102_set_dac_comp(codec,
1184 params_rate(params));
1185 break;
1186 default:
1187 break;
1188 }
1189
1156 snd_soc_update_bits(codec, ARIZONA_SAMPLE_RATE_1, 1190 snd_soc_update_bits(codec, ARIZONA_SAMPLE_RATE_1,
1157 ARIZONA_SAMPLE_RATE_1_MASK, sr_val); 1191 ARIZONA_SAMPLE_RATE_1_MASK, sr_val);
1158 if (base) 1192 if (base)
diff --git a/sound/soc/codecs/wm5102.c b/sound/soc/codecs/wm5102.c
index dcf1d12cfef8..7bf2397fc25a 100644
--- a/sound/soc/codecs/wm5102.c
+++ b/sound/soc/codecs/wm5102.c
@@ -612,6 +612,62 @@ static int wm5102_sysclk_ev(struct snd_soc_dapm_widget *w,
612 return 0; 612 return 0;
613} 613}
614 614
615static int wm5102_out_comp_coeff_get(struct snd_kcontrol *kcontrol,
616 struct snd_ctl_elem_value *ucontrol)
617{
618 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
619 struct arizona *arizona = dev_get_drvdata(codec->dev->parent);
620 uint16_t data;
621
622 mutex_lock(&codec->mutex);
623 data = cpu_to_be16(arizona->dac_comp_coeff);
624 memcpy(ucontrol->value.bytes.data, &data, sizeof(data));
625 mutex_unlock(&codec->mutex);
626
627 return 0;
628}
629
630static int wm5102_out_comp_coeff_put(struct snd_kcontrol *kcontrol,
631 struct snd_ctl_elem_value *ucontrol)
632{
633 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
634 struct arizona *arizona = dev_get_drvdata(codec->dev->parent);
635
636 mutex_lock(&codec->mutex);
637 memcpy(&arizona->dac_comp_coeff, ucontrol->value.bytes.data,
638 sizeof(arizona->dac_comp_coeff));
639 arizona->dac_comp_coeff = be16_to_cpu(arizona->dac_comp_coeff);
640 mutex_unlock(&codec->mutex);
641
642 return 0;
643}
644
645static int wm5102_out_comp_switch_get(struct snd_kcontrol *kcontrol,
646 struct snd_ctl_elem_value *ucontrol)
647{
648 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
649 struct arizona *arizona = dev_get_drvdata(codec->dev->parent);
650
651 mutex_lock(&codec->mutex);
652 ucontrol->value.integer.value[0] = arizona->dac_comp_enabled;
653 mutex_unlock(&codec->mutex);
654
655 return 0;
656}
657
658static int wm5102_out_comp_switch_put(struct snd_kcontrol *kcontrol,
659 struct snd_ctl_elem_value *ucontrol)
660{
661 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
662 struct arizona *arizona = dev_get_drvdata(codec->dev->parent);
663
664 mutex_lock(&codec->mutex);
665 arizona->dac_comp_enabled = ucontrol->value.integer.value[0];
666 mutex_unlock(&codec->mutex);
667
668 return 0;
669}
670
615static const char *wm5102_osr_text[] = { 671static const char *wm5102_osr_text[] = {
616 "Low power", "Normal", "High performance", 672 "Low power", "Normal", "High performance",
617}; 673};
@@ -843,6 +899,12 @@ SOC_SINGLE_TLV("Noise Gate Threshold Volume", ARIZONA_NOISE_GATE_CONTROL,
843 ARIZONA_NGATE_THR_SHIFT, 7, 1, ng_tlv), 899 ARIZONA_NGATE_THR_SHIFT, 7, 1, ng_tlv),
844SOC_ENUM("Noise Gate Hold", arizona_ng_hold), 900SOC_ENUM("Noise Gate Hold", arizona_ng_hold),
845 901
902SND_SOC_BYTES_EXT("Output Compensation Coefficient", 2,
903 wm5102_out_comp_coeff_get, wm5102_out_comp_coeff_put),
904
905SOC_SINGLE_EXT("Output Compensation Switch", 0, 0, 1, 0,
906 wm5102_out_comp_switch_get, wm5102_out_comp_switch_put),
907
846WM5102_NG_SRC("HPOUT1L", ARIZONA_NOISE_GATE_SELECT_1L), 908WM5102_NG_SRC("HPOUT1L", ARIZONA_NOISE_GATE_SELECT_1L),
847WM5102_NG_SRC("HPOUT1R", ARIZONA_NOISE_GATE_SELECT_1R), 909WM5102_NG_SRC("HPOUT1R", ARIZONA_NOISE_GATE_SELECT_1R),
848WM5102_NG_SRC("HPOUT2L", ARIZONA_NOISE_GATE_SELECT_2L), 910WM5102_NG_SRC("HPOUT2L", ARIZONA_NOISE_GATE_SELECT_2L),