diff options
author | Thomas Niederprüm <niederp@physik.uni-kl.de> | 2015-01-21 18:01:53 -0500 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2015-01-27 12:13:21 -0500 |
commit | a1be4cead9b9504aa6fc93b624975601cec8c188 (patch) | |
tree | b9906996ec050f722fe5924462c41addd9275cea /sound/soc/codecs | |
parent | 97bf6af1f928216fd6c5a66e8a57bfa95a659672 (diff) |
ASoC: sta32x: Convert to direct regmap API usage.
use the regmap API directly rather than relying on the snd_soc_read/write
functions as this seems to be in accordance with common practice.
Signed-off-by: Thomas Niederprüm <niederp@physik.uni-kl.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound/soc/codecs')
-rw-r--r-- | sound/soc/codecs/Kconfig | 1 | ||||
-rw-r--r-- | sound/soc/codecs/sta32x.c | 271 |
2 files changed, 152 insertions, 120 deletions
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index 8349f982a586..27e1e3b59649 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig | |||
@@ -581,6 +581,7 @@ config SND_SOC_SSM4567 | |||
581 | 581 | ||
582 | config SND_SOC_STA32X | 582 | config SND_SOC_STA32X |
583 | tristate | 583 | tristate |
584 | select REGMAP_I2C | ||
584 | 585 | ||
585 | config SND_SOC_STA350 | 586 | config SND_SOC_STA350 |
586 | tristate "STA350 speaker amplifier" | 587 | tristate "STA350 speaker amplifier" |
diff --git a/sound/soc/codecs/sta32x.c b/sound/soc/codecs/sta32x.c index 7e18200dd6a9..4517453b33b6 100644 --- a/sound/soc/codecs/sta32x.c +++ b/sound/soc/codecs/sta32x.c | |||
@@ -102,6 +102,35 @@ static const struct reg_default sta32x_regs[] = { | |||
102 | { 0x2c, 0x0c }, | 102 | { 0x2c, 0x0c }, |
103 | }; | 103 | }; |
104 | 104 | ||
105 | static const struct regmap_range sta32x_write_regs_range[] = { | ||
106 | regmap_reg_range(STA32X_CONFA, STA32X_AUTO2), | ||
107 | regmap_reg_range(STA32X_C1CFG, STA32X_FDRC2), | ||
108 | }; | ||
109 | |||
110 | static const struct regmap_range sta32x_read_regs_range[] = { | ||
111 | regmap_reg_range(STA32X_CONFA, STA32X_AUTO2), | ||
112 | regmap_reg_range(STA32X_C1CFG, STA32X_FDRC2), | ||
113 | }; | ||
114 | |||
115 | static const struct regmap_range sta32x_volatile_regs_range[] = { | ||
116 | regmap_reg_range(STA32X_CFADDR2, STA32X_CFUD), | ||
117 | }; | ||
118 | |||
119 | static const struct regmap_access_table sta32x_write_regs = { | ||
120 | .yes_ranges = sta32x_write_regs_range, | ||
121 | .n_yes_ranges = ARRAY_SIZE(sta32x_write_regs_range), | ||
122 | }; | ||
123 | |||
124 | static const struct regmap_access_table sta32x_read_regs = { | ||
125 | .yes_ranges = sta32x_read_regs_range, | ||
126 | .n_yes_ranges = ARRAY_SIZE(sta32x_read_regs_range), | ||
127 | }; | ||
128 | |||
129 | static const struct regmap_access_table sta32x_volatile_regs = { | ||
130 | .yes_ranges = sta32x_volatile_regs_range, | ||
131 | .n_yes_ranges = ARRAY_SIZE(sta32x_volatile_regs_range), | ||
132 | }; | ||
133 | |||
105 | /* regulator power supply names */ | 134 | /* regulator power supply names */ |
106 | static const char *sta32x_supply_names[] = { | 135 | static const char *sta32x_supply_names[] = { |
107 | "Vdda", /* analog supply, 3.3VV */ | 136 | "Vdda", /* analog supply, 3.3VV */ |
@@ -122,6 +151,7 @@ struct sta32x_priv { | |||
122 | u32 coef_shadow[STA32X_COEF_COUNT]; | 151 | u32 coef_shadow[STA32X_COEF_COUNT]; |
123 | struct delayed_work watchdog_work; | 152 | struct delayed_work watchdog_work; |
124 | int shutdown; | 153 | int shutdown; |
154 | struct mutex coeff_lock; | ||
125 | }; | 155 | }; |
126 | 156 | ||
127 | static const DECLARE_TLV_DB_SCALE(mvol_tlv, -12700, 50, 1); | 157 | static const DECLARE_TLV_DB_SCALE(mvol_tlv, -12700, 50, 1); |
@@ -244,29 +274,42 @@ static int sta32x_coefficient_get(struct snd_kcontrol *kcontrol, | |||
244 | struct snd_ctl_elem_value *ucontrol) | 274 | struct snd_ctl_elem_value *ucontrol) |
245 | { | 275 | { |
246 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); | 276 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
277 | struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec); | ||
247 | int numcoef = kcontrol->private_value >> 16; | 278 | int numcoef = kcontrol->private_value >> 16; |
248 | int index = kcontrol->private_value & 0xffff; | 279 | int index = kcontrol->private_value & 0xffff; |
249 | unsigned int cfud; | 280 | unsigned int cfud, val; |
250 | int i; | 281 | int i, ret = 0; |
282 | |||
283 | mutex_lock(&sta32x->coeff_lock); | ||
251 | 284 | ||
252 | /* preserve reserved bits in STA32X_CFUD */ | 285 | /* preserve reserved bits in STA32X_CFUD */ |
253 | cfud = snd_soc_read(codec, STA32X_CFUD) & 0xf0; | 286 | regmap_read(sta32x->regmap, STA32X_CFUD, &cfud); |
254 | /* chip documentation does not say if the bits are self clearing, | 287 | cfud &= 0xf0; |
255 | * so do it explicitly */ | 288 | /* |
256 | snd_soc_write(codec, STA32X_CFUD, cfud); | 289 | * chip documentation does not say if the bits are self clearing, |
290 | * so do it explicitly | ||
291 | */ | ||
292 | regmap_write(sta32x->regmap, STA32X_CFUD, cfud); | ||
257 | 293 | ||
258 | snd_soc_write(codec, STA32X_CFADDR2, index); | 294 | regmap_write(sta32x->regmap, STA32X_CFADDR2, index); |
259 | if (numcoef == 1) | 295 | if (numcoef == 1) { |
260 | snd_soc_write(codec, STA32X_CFUD, cfud | 0x04); | 296 | regmap_write(sta32x->regmap, STA32X_CFUD, cfud | 0x04); |
261 | else if (numcoef == 5) | 297 | } else if (numcoef == 5) { |
262 | snd_soc_write(codec, STA32X_CFUD, cfud | 0x08); | 298 | regmap_write(sta32x->regmap, STA32X_CFUD, cfud | 0x08); |
263 | else | 299 | } else { |
264 | return -EINVAL; | 300 | ret = -EINVAL; |
265 | for (i = 0; i < 3 * numcoef; i++) | 301 | goto exit_unlock; |
266 | ucontrol->value.bytes.data[i] = | 302 | } |
267 | snd_soc_read(codec, STA32X_B1CF1 + i); | ||
268 | 303 | ||
269 | return 0; | 304 | for (i = 0; i < 3 * numcoef; i++) { |
305 | regmap_read(sta32x->regmap, STA32X_B1CF1 + i, &val); | ||
306 | ucontrol->value.bytes.data[i] = val; | ||
307 | } | ||
308 | |||
309 | exit_unlock: | ||
310 | mutex_unlock(&sta32x->coeff_lock); | ||
311 | |||
312 | return ret; | ||
270 | } | 313 | } |
271 | 314 | ||
272 | static int sta32x_coefficient_put(struct snd_kcontrol *kcontrol, | 315 | static int sta32x_coefficient_put(struct snd_kcontrol *kcontrol, |
@@ -280,24 +323,27 @@ static int sta32x_coefficient_put(struct snd_kcontrol *kcontrol, | |||
280 | int i; | 323 | int i; |
281 | 324 | ||
282 | /* preserve reserved bits in STA32X_CFUD */ | 325 | /* preserve reserved bits in STA32X_CFUD */ |
283 | cfud = snd_soc_read(codec, STA32X_CFUD) & 0xf0; | 326 | regmap_read(sta32x->regmap, STA32X_CFUD, &cfud); |
284 | /* chip documentation does not say if the bits are self clearing, | 327 | cfud &= 0xf0; |
285 | * so do it explicitly */ | 328 | /* |
286 | snd_soc_write(codec, STA32X_CFUD, cfud); | 329 | * chip documentation does not say if the bits are self clearing, |
330 | * so do it explicitly | ||
331 | */ | ||
332 | regmap_write(sta32x->regmap, STA32X_CFUD, cfud); | ||
287 | 333 | ||
288 | snd_soc_write(codec, STA32X_CFADDR2, index); | 334 | regmap_write(sta32x->regmap, STA32X_CFADDR2, index); |
289 | for (i = 0; i < numcoef && (index + i < STA32X_COEF_COUNT); i++) | 335 | for (i = 0; i < numcoef && (index + i < STA32X_COEF_COUNT); i++) |
290 | sta32x->coef_shadow[index + i] = | 336 | sta32x->coef_shadow[index + i] = |
291 | (ucontrol->value.bytes.data[3 * i] << 16) | 337 | (ucontrol->value.bytes.data[3 * i] << 16) |
292 | | (ucontrol->value.bytes.data[3 * i + 1] << 8) | 338 | | (ucontrol->value.bytes.data[3 * i + 1] << 8) |
293 | | (ucontrol->value.bytes.data[3 * i + 2]); | 339 | | (ucontrol->value.bytes.data[3 * i + 2]); |
294 | for (i = 0; i < 3 * numcoef; i++) | 340 | for (i = 0; i < 3 * numcoef; i++) |
295 | snd_soc_write(codec, STA32X_B1CF1 + i, | 341 | regmap_write(sta32x->regmap, STA32X_B1CF1 + i, |
296 | ucontrol->value.bytes.data[i]); | 342 | ucontrol->value.bytes.data[i]); |
297 | if (numcoef == 1) | 343 | if (numcoef == 1) |
298 | snd_soc_write(codec, STA32X_CFUD, cfud | 0x01); | 344 | regmap_write(sta32x->regmap, STA32X_CFUD, cfud | 0x01); |
299 | else if (numcoef == 5) | 345 | else if (numcoef == 5) |
300 | snd_soc_write(codec, STA32X_CFUD, cfud | 0x02); | 346 | regmap_write(sta32x->regmap, STA32X_CFUD, cfud | 0x02); |
301 | else | 347 | else |
302 | return -EINVAL; | 348 | return -EINVAL; |
303 | 349 | ||
@@ -311,20 +357,23 @@ static int sta32x_sync_coef_shadow(struct snd_soc_codec *codec) | |||
311 | int i; | 357 | int i; |
312 | 358 | ||
313 | /* preserve reserved bits in STA32X_CFUD */ | 359 | /* preserve reserved bits in STA32X_CFUD */ |
314 | cfud = snd_soc_read(codec, STA32X_CFUD) & 0xf0; | 360 | regmap_read(sta32x->regmap, STA32X_CFUD, &cfud); |
361 | cfud &= 0xf0; | ||
315 | 362 | ||
316 | for (i = 0; i < STA32X_COEF_COUNT; i++) { | 363 | for (i = 0; i < STA32X_COEF_COUNT; i++) { |
317 | snd_soc_write(codec, STA32X_CFADDR2, i); | 364 | regmap_write(sta32x->regmap, STA32X_CFADDR2, i); |
318 | snd_soc_write(codec, STA32X_B1CF1, | 365 | regmap_write(sta32x->regmap, STA32X_B1CF1, |
319 | (sta32x->coef_shadow[i] >> 16) & 0xff); | 366 | (sta32x->coef_shadow[i] >> 16) & 0xff); |
320 | snd_soc_write(codec, STA32X_B1CF2, | 367 | regmap_write(sta32x->regmap, STA32X_B1CF2, |
321 | (sta32x->coef_shadow[i] >> 8) & 0xff); | 368 | (sta32x->coef_shadow[i] >> 8) & 0xff); |
322 | snd_soc_write(codec, STA32X_B1CF3, | 369 | regmap_write(sta32x->regmap, STA32X_B1CF3, |
323 | (sta32x->coef_shadow[i]) & 0xff); | 370 | (sta32x->coef_shadow[i]) & 0xff); |
324 | /* chip documentation does not say if the bits are | 371 | /* |
325 | * self-clearing, so do it explicitly */ | 372 | * chip documentation does not say if the bits are |
326 | snd_soc_write(codec, STA32X_CFUD, cfud); | 373 | * self-clearing, so do it explicitly |
327 | snd_soc_write(codec, STA32X_CFUD, cfud | 0x01); | 374 | */ |
375 | regmap_write(sta32x->regmap, STA32X_CFUD, cfud); | ||
376 | regmap_write(sta32x->regmap, STA32X_CFUD, cfud | 0x01); | ||
328 | } | 377 | } |
329 | return 0; | 378 | return 0; |
330 | } | 379 | } |
@@ -336,11 +385,11 @@ static int sta32x_cache_sync(struct snd_soc_codec *codec) | |||
336 | int rc; | 385 | int rc; |
337 | 386 | ||
338 | /* mute during register sync */ | 387 | /* mute during register sync */ |
339 | mute = snd_soc_read(codec, STA32X_MMUTE); | 388 | regmap_read(sta32x->regmap, STA32X_MMUTE, &mute); |
340 | snd_soc_write(codec, STA32X_MMUTE, mute | STA32X_MMUTE_MMUTE); | 389 | regmap_write(sta32x->regmap, STA32X_MMUTE, mute | STA32X_MMUTE_MMUTE); |
341 | sta32x_sync_coef_shadow(codec); | 390 | sta32x_sync_coef_shadow(codec); |
342 | rc = regcache_sync(sta32x->regmap); | 391 | rc = regcache_sync(sta32x->regmap); |
343 | snd_soc_write(codec, STA32X_MMUTE, mute); | 392 | regmap_write(sta32x->regmap, STA32X_MMUTE, mute); |
344 | return rc; | 393 | return rc; |
345 | } | 394 | } |
346 | 395 | ||
@@ -599,10 +648,7 @@ static int sta32x_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
599 | { | 648 | { |
600 | struct snd_soc_codec *codec = codec_dai->codec; | 649 | struct snd_soc_codec *codec = codec_dai->codec; |
601 | struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec); | 650 | struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec); |
602 | u8 confb = snd_soc_read(codec, STA32X_CONFB); | 651 | u8 confb = 0; |
603 | |||
604 | pr_debug("\n"); | ||
605 | confb &= ~(STA32X_CONFB_C1IM | STA32X_CONFB_C2IM); | ||
606 | 652 | ||
607 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | 653 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
608 | case SND_SOC_DAIFMT_CBS_CFS: | 654 | case SND_SOC_DAIFMT_CBS_CFS: |
@@ -632,8 +678,8 @@ static int sta32x_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
632 | return -EINVAL; | 678 | return -EINVAL; |
633 | } | 679 | } |
634 | 680 | ||
635 | snd_soc_write(codec, STA32X_CONFB, confb); | 681 | return regmap_update_bits(sta32x->regmap, STA32X_CONFB, |
636 | return 0; | 682 | STA32X_CONFB_C1IM | STA32X_CONFB_C2IM, confb); |
637 | } | 683 | } |
638 | 684 | ||
639 | /** | 685 | /** |
@@ -653,7 +699,7 @@ static int sta32x_hw_params(struct snd_pcm_substream *substream, | |||
653 | struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec); | 699 | struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec); |
654 | unsigned int rate; | 700 | unsigned int rate; |
655 | int i, mcs = -1, ir = -1; | 701 | int i, mcs = -1, ir = -1; |
656 | u8 confa, confb; | 702 | unsigned int confa, confb; |
657 | 703 | ||
658 | rate = params_rate(params); | 704 | rate = params_rate(params); |
659 | pr_debug("rate: %u\n", rate); | 705 | pr_debug("rate: %u\n", rate); |
@@ -672,12 +718,10 @@ static int sta32x_hw_params(struct snd_pcm_substream *substream, | |||
672 | if (mcs < 0) | 718 | if (mcs < 0) |
673 | return -EINVAL; | 719 | return -EINVAL; |
674 | 720 | ||
675 | confa = snd_soc_read(codec, STA32X_CONFA); | 721 | confa = (ir << STA32X_CONFA_IR_SHIFT) | |
676 | confa &= ~(STA32X_CONFA_MCS_MASK | STA32X_CONFA_IR_MASK); | 722 | (mcs << STA32X_CONFA_MCS_SHIFT); |
677 | confa |= (ir << STA32X_CONFA_IR_SHIFT) | (mcs << STA32X_CONFA_MCS_SHIFT); | 723 | confb = 0; |
678 | 724 | ||
679 | confb = snd_soc_read(codec, STA32X_CONFB); | ||
680 | confb &= ~(STA32X_CONFB_SAI_MASK | STA32X_CONFB_SAIFB); | ||
681 | switch (params_width(params)) { | 725 | switch (params_width(params)) { |
682 | case 24: | 726 | case 24: |
683 | pr_debug("24bit\n"); | 727 | pr_debug("24bit\n"); |
@@ -746,8 +790,20 @@ static int sta32x_hw_params(struct snd_pcm_substream *substream, | |||
746 | return -EINVAL; | 790 | return -EINVAL; |
747 | } | 791 | } |
748 | 792 | ||
749 | snd_soc_write(codec, STA32X_CONFA, confa); | 793 | ret = regmap_update_bits(sta32x->regmap, STA32X_CONFA, |
750 | snd_soc_write(codec, STA32X_CONFB, confb); | 794 | STA32X_CONFA_MCS_MASK | STA32X_CONFA_IR_MASK, |
795 | confa); | ||
796 | if (ret < 0) | ||
797 | return ret; | ||
798 | |||
799 | ret = regmap_update_bits(sta32x->regmap, STA32X_CONFB, | ||
800 | STA32X_CONFB_SAI_MASK | STA32X_CONFB_SAIFB, | ||
801 | confb); | ||
802 | if (ret < 0) | ||
803 | return ret; | ||
804 | |||
805 | return 0; | ||
806 | } | ||
751 | return 0; | 807 | return 0; |
752 | } | 808 | } |
753 | 809 | ||
@@ -773,7 +829,7 @@ static int sta32x_set_bias_level(struct snd_soc_codec *codec, | |||
773 | 829 | ||
774 | case SND_SOC_BIAS_PREPARE: | 830 | case SND_SOC_BIAS_PREPARE: |
775 | /* Full power on */ | 831 | /* Full power on */ |
776 | snd_soc_update_bits(codec, STA32X_CONFF, | 832 | regmap_update_bits(sta32x->regmap, STA32X_CONFF, |
777 | STA32X_CONFF_PWDN | STA32X_CONFF_EAPD, | 833 | STA32X_CONFF_PWDN | STA32X_CONFF_EAPD, |
778 | STA32X_CONFF_PWDN | STA32X_CONFF_EAPD); | 834 | STA32X_CONFF_PWDN | STA32X_CONFF_EAPD); |
779 | break; | 835 | break; |
@@ -792,19 +848,17 @@ static int sta32x_set_bias_level(struct snd_soc_codec *codec, | |||
792 | sta32x_watchdog_start(sta32x); | 848 | sta32x_watchdog_start(sta32x); |
793 | } | 849 | } |
794 | 850 | ||
795 | /* Power up to mute */ | 851 | /* Power down */ |
796 | /* FIXME */ | 852 | regmap_update_bits(sta32x->regmap, STA32X_CONFF, |
797 | snd_soc_update_bits(codec, STA32X_CONFF, | 853 | STA32X_CONFF_PWDN | STA32X_CONFF_EAPD, |
798 | STA32X_CONFF_PWDN | STA32X_CONFF_EAPD, | 854 | 0); |
799 | STA32X_CONFF_PWDN | STA32X_CONFF_EAPD); | ||
800 | 855 | ||
801 | break; | 856 | break; |
802 | 857 | ||
803 | case SND_SOC_BIAS_OFF: | 858 | case SND_SOC_BIAS_OFF: |
804 | /* The chip runs through the power down sequence for us. */ | 859 | /* The chip runs through the power down sequence for us. */ |
805 | snd_soc_update_bits(codec, STA32X_CONFF, | 860 | regmap_update_bits(sta32x->regmap, STA32X_CONFF, |
806 | STA32X_CONFF_PWDN | STA32X_CONFF_EAPD, | 861 | STA32X_CONFF_PWDN | STA32X_CONFF_EAPD, 0); |
807 | STA32X_CONFF_PWDN); | ||
808 | msleep(300); | 862 | msleep(300); |
809 | sta32x_watchdog_stop(sta32x); | 863 | sta32x_watchdog_stop(sta32x); |
810 | regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), | 864 | regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), |
@@ -836,11 +890,8 @@ static struct snd_soc_dai_driver sta32x_dai = { | |||
836 | static int sta32x_probe(struct snd_soc_codec *codec) | 890 | static int sta32x_probe(struct snd_soc_codec *codec) |
837 | { | 891 | { |
838 | struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec); | 892 | struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec); |
893 | struct sta32x_platform_data *pdata = sta32x->pdata; | ||
839 | int i, ret = 0, thermal = 0; | 894 | int i, ret = 0, thermal = 0; |
840 | |||
841 | sta32x->codec = codec; | ||
842 | sta32x->pdata = dev_get_platdata(codec->dev); | ||
843 | |||
844 | ret = regulator_bulk_enable(ARRAY_SIZE(sta32x->supplies), | 895 | ret = regulator_bulk_enable(ARRAY_SIZE(sta32x->supplies), |
845 | sta32x->supplies); | 896 | sta32x->supplies); |
846 | if (ret != 0) { | 897 | if (ret != 0) { |
@@ -848,50 +899,34 @@ static int sta32x_probe(struct snd_soc_codec *codec) | |||
848 | return ret; | 899 | return ret; |
849 | } | 900 | } |
850 | 901 | ||
851 | /* Chip documentation explicitly requires that the reset values | ||
852 | * of reserved register bits are left untouched. | ||
853 | * Write the register default value to cache for reserved registers, | ||
854 | * so the write to the these registers are suppressed by the cache | ||
855 | * restore code when it skips writes of default registers. | ||
856 | */ | ||
857 | regcache_cache_only(sta32x->regmap, true); | ||
858 | snd_soc_write(codec, STA32X_CONFC, 0xc2); | ||
859 | snd_soc_write(codec, STA32X_CONFE, 0xc2); | ||
860 | snd_soc_write(codec, STA32X_CONFF, 0x5c); | ||
861 | snd_soc_write(codec, STA32X_MMUTE, 0x10); | ||
862 | snd_soc_write(codec, STA32X_AUTO1, 0x60); | ||
863 | snd_soc_write(codec, STA32X_AUTO3, 0x00); | ||
864 | snd_soc_write(codec, STA32X_C3CFG, 0x40); | ||
865 | regcache_cache_only(sta32x->regmap, false); | ||
866 | |||
867 | /* set thermal warning adjustment and recovery */ | 902 | /* set thermal warning adjustment and recovery */ |
868 | if (!(sta32x->pdata->thermal_conf & STA32X_THERMAL_ADJUSTMENT_ENABLE)) | 903 | if (!pdata->thermal_warning_recovery) |
869 | thermal |= STA32X_CONFA_TWAB; | 904 | thermal |= STA32X_CONFA_TWAB; |
870 | if (!(sta32x->pdata->thermal_conf & STA32X_THERMAL_RECOVERY_ENABLE)) | 905 | if (!pdata->thermal_warning_adjustment) |
871 | thermal |= STA32X_CONFA_TWRB; | 906 | thermal |= STA32X_CONFA_TWRB; |
872 | snd_soc_update_bits(codec, STA32X_CONFA, | 907 | regmap_update_bits(sta32x->regmap, STA32X_CONFA, |
873 | STA32X_CONFA_TWAB | STA32X_CONFA_TWRB, | 908 | STA32X_CONFA_TWAB | STA32X_CONFA_TWRB, |
874 | thermal); | 909 | thermal); |
875 | 910 | ||
876 | /* select output configuration */ | 911 | /* select output configuration */ |
877 | snd_soc_update_bits(codec, STA32X_CONFF, | 912 | regmap_update_bits(sta32x->regmap, STA32X_CONFF, |
878 | STA32X_CONFF_OCFG_MASK, | 913 | STA32X_CONFF_OCFG_MASK, |
879 | sta32x->pdata->output_conf | 914 | pdata->output_conf |
880 | << STA32X_CONFF_OCFG_SHIFT); | 915 | << STA32X_CONFF_OCFG_SHIFT); |
881 | 916 | ||
882 | /* channel to output mapping */ | 917 | /* channel to output mapping */ |
883 | snd_soc_update_bits(codec, STA32X_C1CFG, | 918 | regmap_update_bits(sta32x->regmap, STA32X_C1CFG, |
884 | STA32X_CxCFG_OM_MASK, | 919 | STA32X_CxCFG_OM_MASK, |
885 | sta32x->pdata->ch1_output_mapping | 920 | pdata->ch1_output_mapping |
886 | << STA32X_CxCFG_OM_SHIFT); | 921 | << STA32X_CxCFG_OM_SHIFT); |
887 | snd_soc_update_bits(codec, STA32X_C2CFG, | 922 | regmap_update_bits(sta32x->regmap, STA32X_C2CFG, |
888 | STA32X_CxCFG_OM_MASK, | 923 | STA32X_CxCFG_OM_MASK, |
889 | sta32x->pdata->ch2_output_mapping | 924 | pdata->ch2_output_mapping |
890 | << STA32X_CxCFG_OM_SHIFT); | 925 | << STA32X_CxCFG_OM_SHIFT); |
891 | snd_soc_update_bits(codec, STA32X_C3CFG, | 926 | regmap_update_bits(sta32x->regmap, STA32X_C3CFG, |
892 | STA32X_CxCFG_OM_MASK, | 927 | STA32X_CxCFG_OM_MASK, |
893 | sta32x->pdata->ch3_output_mapping | 928 | pdata->ch3_output_mapping |
894 | << STA32X_CxCFG_OM_SHIFT); | 929 | << STA32X_CxCFG_OM_SHIFT); |
895 | 930 | ||
896 | /* initialize coefficient shadow RAM with reset values */ | 931 | /* initialize coefficient shadow RAM with reset values */ |
897 | for (i = 4; i <= 49; i += 5) | 932 | for (i = 4; i <= 49; i += 5) |
@@ -924,16 +959,6 @@ static int sta32x_remove(struct snd_soc_codec *codec) | |||
924 | return 0; | 959 | return 0; |
925 | } | 960 | } |
926 | 961 | ||
927 | static bool sta32x_reg_is_volatile(struct device *dev, unsigned int reg) | ||
928 | { | ||
929 | switch (reg) { | ||
930 | case STA32X_CONFA ... STA32X_L2ATRT: | ||
931 | case STA32X_MPCC1 ... STA32X_FDRC2: | ||
932 | return 0; | ||
933 | } | ||
934 | return 1; | ||
935 | } | ||
936 | |||
937 | static const struct snd_soc_codec_driver sta32x_codec = { | 962 | static const struct snd_soc_codec_driver sta32x_codec = { |
938 | .probe = sta32x_probe, | 963 | .probe = sta32x_probe, |
939 | .remove = sta32x_remove, | 964 | .remove = sta32x_remove, |
@@ -954,12 +979,16 @@ static const struct regmap_config sta32x_regmap = { | |||
954 | .reg_defaults = sta32x_regs, | 979 | .reg_defaults = sta32x_regs, |
955 | .num_reg_defaults = ARRAY_SIZE(sta32x_regs), | 980 | .num_reg_defaults = ARRAY_SIZE(sta32x_regs), |
956 | .cache_type = REGCACHE_RBTREE, | 981 | .cache_type = REGCACHE_RBTREE, |
957 | .volatile_reg = sta32x_reg_is_volatile, | 982 | .wr_table = &sta32x_write_regs, |
983 | .rd_table = &sta32x_read_regs, | ||
984 | .volatile_table = &sta32x_volatile_regs, | ||
985 | }; | ||
958 | }; | 986 | }; |
959 | 987 | ||
960 | static int sta32x_i2c_probe(struct i2c_client *i2c, | 988 | static int sta32x_i2c_probe(struct i2c_client *i2c, |
961 | const struct i2c_device_id *id) | 989 | const struct i2c_device_id *id) |
962 | { | 990 | { |
991 | struct device *dev = &i2c->dev; | ||
963 | struct sta32x_priv *sta32x; | 992 | struct sta32x_priv *sta32x; |
964 | int ret, i; | 993 | int ret, i; |
965 | 994 | ||
@@ -968,6 +997,8 @@ static int sta32x_i2c_probe(struct i2c_client *i2c, | |||
968 | if (!sta32x) | 997 | if (!sta32x) |
969 | return -ENOMEM; | 998 | return -ENOMEM; |
970 | 999 | ||
1000 | mutex_init(&sta32x->coeff_lock); | ||
1001 | sta32x->pdata = dev_get_platdata(dev); | ||
971 | /* regulators */ | 1002 | /* regulators */ |
972 | for (i = 0; i < ARRAY_SIZE(sta32x->supplies); i++) | 1003 | for (i = 0; i < ARRAY_SIZE(sta32x->supplies); i++) |
973 | sta32x->supplies[i].supply = sta32x_supply_names[i]; | 1004 | sta32x->supplies[i].supply = sta32x_supply_names[i]; |
@@ -982,15 +1013,15 @@ static int sta32x_i2c_probe(struct i2c_client *i2c, | |||
982 | sta32x->regmap = devm_regmap_init_i2c(i2c, &sta32x_regmap); | 1013 | sta32x->regmap = devm_regmap_init_i2c(i2c, &sta32x_regmap); |
983 | if (IS_ERR(sta32x->regmap)) { | 1014 | if (IS_ERR(sta32x->regmap)) { |
984 | ret = PTR_ERR(sta32x->regmap); | 1015 | ret = PTR_ERR(sta32x->regmap); |
985 | dev_err(&i2c->dev, "Failed to init regmap: %d\n", ret); | 1016 | dev_err(dev, "Failed to init regmap: %d\n", ret); |
986 | return ret; | 1017 | return ret; |
987 | } | 1018 | } |
988 | 1019 | ||
989 | i2c_set_clientdata(i2c, sta32x); | 1020 | i2c_set_clientdata(i2c, sta32x); |
990 | 1021 | ||
991 | ret = snd_soc_register_codec(&i2c->dev, &sta32x_codec, &sta32x_dai, 1); | 1022 | ret = snd_soc_register_codec(dev, &sta32x_codec, &sta32x_dai, 1); |
992 | if (ret != 0) | 1023 | if (ret < 0) |
993 | dev_err(&i2c->dev, "Failed to register codec (%d)\n", ret); | 1024 | dev_err(dev, "Failed to register codec (%d)\n", ret); |
994 | 1025 | ||
995 | return ret; | 1026 | return ret; |
996 | } | 1027 | } |