aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/sta32x.c
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2012-09-09 22:59:56 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-09-10 05:26:10 -0400
commit29fdf4fbbe0891349d8444bde4c09f9cfaf744b6 (patch)
tree40a9aa9338314bb7eb59da8409e6ba71a992844b /sound/soc/codecs/sta32x.c
parentaff041af948f5cdf51e2115f267957a89f28ac0f (diff)
ASoC: sta32x: Convert to regmap
Long term all drivers should be using regmap directly. This is more idiomatic and moves us towards the removal of the ASoC level cache code. The initialiasation of reserved register bits in probe() is slightly odd as the defaults being written don't appear to match the silicon defaults but the new code should have the same effect as the old code. The watchdog code will now unconditionally do a mute and unmute when resyncing but since we only sync when we are very sure there is something to sync this should have no impact. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Acked-by: Johannes Stezenbach <js@sig21.net>
Diffstat (limited to 'sound/soc/codecs/sta32x.c')
-rw-r--r--sound/soc/codecs/sta32x.c107
1 files changed, 80 insertions, 27 deletions
diff --git a/sound/soc/codecs/sta32x.c b/sound/soc/codecs/sta32x.c
index 039597e66987..0935bfe62471 100644
--- a/sound/soc/codecs/sta32x.c
+++ b/sound/soc/codecs/sta32x.c
@@ -24,6 +24,7 @@
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/pm.h> 25#include <linux/pm.h>
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include <linux/regmap.h>
27#include <linux/regulator/consumer.h> 28#include <linux/regulator/consumer.h>
28#include <linux/slab.h> 29#include <linux/slab.h>
29#include <linux/workqueue.h> 30#include <linux/workqueue.h>
@@ -55,12 +56,50 @@
55 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE) 56 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE)
56 57
57/* Power-up register defaults */ 58/* Power-up register defaults */
58static const u8 sta32x_regs[STA32X_REGISTER_COUNT] = { 59static const struct reg_default sta32x_regs[] = {
59 0x63, 0x80, 0xc2, 0x40, 0xc2, 0x5c, 0x10, 0xff, 0x60, 0x60, 60 { 0x0, 0x63 },
60 0x60, 0x80, 0x00, 0x00, 0x00, 0x40, 0x80, 0x77, 0x6a, 0x69, 61 { 0x1, 0x80 },
61 0x6a, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 62 { 0x2, 0xc2 },
62 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 63 { 0x3, 0x40 },
63 0xc0, 0xf3, 0x33, 0x00, 0x0c, 64 { 0x4, 0xc2 },
65 { 0x5, 0x5c },
66 { 0x6, 0x10 },
67 { 0x7, 0xff },
68 { 0x8, 0x60 },
69 { 0x9, 0x60 },
70 { 0xa, 0x60 },
71 { 0xb, 0x80 },
72 { 0xc, 0x00 },
73 { 0xd, 0x00 },
74 { 0xe, 0x00 },
75 { 0xf, 0x40 },
76 { 0x10, 0x80 },
77 { 0x11, 0x77 },
78 { 0x12, 0x6a },
79 { 0x13, 0x69 },
80 { 0x14, 0x6a },
81 { 0x15, 0x69 },
82 { 0x16, 0x00 },
83 { 0x17, 0x00 },
84 { 0x18, 0x00 },
85 { 0x19, 0x00 },
86 { 0x1a, 0x00 },
87 { 0x1b, 0x00 },
88 { 0x1c, 0x00 },
89 { 0x1d, 0x00 },
90 { 0x1e, 0x00 },
91 { 0x1f, 0x00 },
92 { 0x20, 0x00 },
93 { 0x21, 0x00 },
94 { 0x22, 0x00 },
95 { 0x23, 0x00 },
96 { 0x24, 0x00 },
97 { 0x25, 0x00 },
98 { 0x26, 0x00 },
99 { 0x27, 0x2d },
100 { 0x28, 0xc0 },
101 { 0x2b, 0x00 },
102 { 0x2c, 0x0c },
64}; 103};
65 104
66/* regulator power supply names */ 105/* regulator power supply names */
@@ -72,6 +111,7 @@ static const char *sta32x_supply_names[] = {
72 111
73/* codec private data */ 112/* codec private data */
74struct sta32x_priv { 113struct sta32x_priv {
114 struct regmap *regmap;
75 struct regulator_bulk_data supplies[ARRAY_SIZE(sta32x_supply_names)]; 115 struct regulator_bulk_data supplies[ARRAY_SIZE(sta32x_supply_names)];
76 struct snd_soc_codec *codec; 116 struct snd_soc_codec *codec;
77 struct sta32x_platform_data *pdata; 117 struct sta32x_platform_data *pdata;
@@ -291,17 +331,15 @@ static int sta32x_sync_coef_shadow(struct snd_soc_codec *codec)
291 331
292static int sta32x_cache_sync(struct snd_soc_codec *codec) 332static int sta32x_cache_sync(struct snd_soc_codec *codec)
293{ 333{
334 struct sta32x_priv *sta32x = codec->control_data;
294 unsigned int mute; 335 unsigned int mute;
295 int rc; 336 int rc;
296 337
297 if (!codec->cache_sync)
298 return 0;
299
300 /* mute during register sync */ 338 /* mute during register sync */
301 mute = snd_soc_read(codec, STA32X_MMUTE); 339 mute = snd_soc_read(codec, STA32X_MMUTE);
302 snd_soc_write(codec, STA32X_MMUTE, mute | STA32X_MMUTE_MMUTE); 340 snd_soc_write(codec, STA32X_MMUTE, mute | STA32X_MMUTE_MMUTE);
303 sta32x_sync_coef_shadow(codec); 341 sta32x_sync_coef_shadow(codec);
304 rc = snd_soc_cache_sync(codec); 342 rc = regcache_sync(sta32x->regmap);
305 snd_soc_write(codec, STA32X_MMUTE, mute); 343 snd_soc_write(codec, STA32X_MMUTE, mute);
306 return rc; 344 return rc;
307} 345}
@@ -316,11 +354,11 @@ static void sta32x_watchdog(struct work_struct *work)
316 354
317 /* check if sta32x has reset itself */ 355 /* check if sta32x has reset itself */
318 confa_cached = snd_soc_read(codec, STA32X_CONFA); 356 confa_cached = snd_soc_read(codec, STA32X_CONFA);
319 codec->cache_bypass = 1; 357 regcache_cache_bypass(sta32x->regmap, true);
320 confa = snd_soc_read(codec, STA32X_CONFA); 358 confa = snd_soc_read(codec, STA32X_CONFA);
321 codec->cache_bypass = 0; 359 regcache_cache_bypass(sta32x->regmap, false);
322 if (confa != confa_cached) { 360 if (confa != confa_cached) {
323 codec->cache_sync = 1; 361 regcache_mark_dirty(sta32x->regmap);
324 sta32x_cache_sync(codec); 362 sta32x_cache_sync(codec);
325 } 363 }
326 364
@@ -835,7 +873,8 @@ static int sta32x_probe(struct snd_soc_codec *codec)
835 /* Tell ASoC what kind of I/O to use to read the registers. ASoC will 873 /* Tell ASoC what kind of I/O to use to read the registers. ASoC will
836 * then do the I2C transactions itself. 874 * then do the I2C transactions itself.
837 */ 875 */
838 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C); 876 codec->control_data = sta32x->regmap;
877 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
839 if (ret < 0) { 878 if (ret < 0) {
840 dev_err(codec->dev, "failed to set cache I/O (ret=%i)\n", ret); 879 dev_err(codec->dev, "failed to set cache I/O (ret=%i)\n", ret);
841 goto err; 880 goto err;
@@ -847,13 +886,15 @@ static int sta32x_probe(struct snd_soc_codec *codec)
847 * so the write to the these registers are suppressed by the cache 886 * so the write to the these registers are suppressed by the cache
848 * restore code when it skips writes of default registers. 887 * restore code when it skips writes of default registers.
849 */ 888 */
850 snd_soc_cache_write(codec, STA32X_CONFC, 0xc2); 889 regcache_cache_only(sta32x->regmap, true);
851 snd_soc_cache_write(codec, STA32X_CONFE, 0xc2); 890 snd_soc_write(codec, STA32X_CONFC, 0xc2);
852 snd_soc_cache_write(codec, STA32X_CONFF, 0x5c); 891 snd_soc_write(codec, STA32X_CONFE, 0xc2);
853 snd_soc_cache_write(codec, STA32X_MMUTE, 0x10); 892 snd_soc_write(codec, STA32X_CONFF, 0x5c);
854 snd_soc_cache_write(codec, STA32X_AUTO1, 0x60); 893 snd_soc_write(codec, STA32X_MMUTE, 0x10);
855 snd_soc_cache_write(codec, STA32X_AUTO3, 0x00); 894 snd_soc_write(codec, STA32X_AUTO1, 0x60);
856 snd_soc_cache_write(codec, STA32X_C3CFG, 0x40); 895 snd_soc_write(codec, STA32X_AUTO3, 0x00);
896 snd_soc_write(codec, STA32X_C3CFG, 0x40);
897 regcache_cache_only(sta32x->regmap, false);
857 898
858 /* set thermal warning adjustment and recovery */ 899 /* set thermal warning adjustment and recovery */
859 if (!(sta32x->pdata->thermal_conf & STA32X_THERMAL_ADJUSTMENT_ENABLE)) 900 if (!(sta32x->pdata->thermal_conf & STA32X_THERMAL_ADJUSTMENT_ENABLE))
@@ -920,8 +961,7 @@ static int sta32x_remove(struct snd_soc_codec *codec)
920 return 0; 961 return 0;
921} 962}
922 963
923static int sta32x_reg_is_volatile(struct snd_soc_codec *codec, 964static bool sta32x_reg_is_volatile(struct device *dev, unsigned int reg)
924 unsigned int reg)
925{ 965{
926 switch (reg) { 966 switch (reg) {
927 case STA32X_CONFA ... STA32X_L2ATRT: 967 case STA32X_CONFA ... STA32X_L2ATRT:
@@ -936,10 +976,6 @@ static const struct snd_soc_codec_driver sta32x_codec = {
936 .remove = sta32x_remove, 976 .remove = sta32x_remove,
937 .suspend = sta32x_suspend, 977 .suspend = sta32x_suspend,
938 .resume = sta32x_resume, 978 .resume = sta32x_resume,
939 .reg_cache_size = STA32X_REGISTER_COUNT,
940 .reg_word_size = sizeof(u8),
941 .reg_cache_default = sta32x_regs,
942 .volatile_register = sta32x_reg_is_volatile,
943 .set_bias_level = sta32x_set_bias_level, 979 .set_bias_level = sta32x_set_bias_level,
944 .controls = sta32x_snd_controls, 980 .controls = sta32x_snd_controls,
945 .num_controls = ARRAY_SIZE(sta32x_snd_controls), 981 .num_controls = ARRAY_SIZE(sta32x_snd_controls),
@@ -949,6 +985,16 @@ static const struct snd_soc_codec_driver sta32x_codec = {
949 .num_dapm_routes = ARRAY_SIZE(sta32x_dapm_routes), 985 .num_dapm_routes = ARRAY_SIZE(sta32x_dapm_routes),
950}; 986};
951 987
988static const struct regmap_config sta32x_regmap = {
989 .reg_bits = 8,
990 .val_bits = 8,
991 .max_register = STA32X_FDRC2,
992 .reg_defaults = sta32x_regs,
993 .num_reg_defaults = ARRAY_SIZE(sta32x_regs),
994 .cache_type = REGCACHE_RBTREE,
995 .volatile_reg = sta32x_reg_is_volatile,
996};
997
952static __devinit int sta32x_i2c_probe(struct i2c_client *i2c, 998static __devinit int sta32x_i2c_probe(struct i2c_client *i2c,
953 const struct i2c_device_id *id) 999 const struct i2c_device_id *id)
954{ 1000{
@@ -971,6 +1017,13 @@ static __devinit int sta32x_i2c_probe(struct i2c_client *i2c,
971 return ret; 1017 return ret;
972 } 1018 }
973 1019
1020 sta32x->regmap = devm_regmap_init_i2c(i2c, &sta32x_regmap);
1021 if (IS_ERR(sta32x->regmap)) {
1022 ret = PTR_ERR(sta32x->regmap);
1023 dev_err(&i2c->dev, "Failed to init regmap: %d\n", ret);
1024 return ret;
1025 }
1026
974 i2c_set_clientdata(i2c, sta32x); 1027 i2c_set_clientdata(i2c, sta32x);
975 1028
976 ret = snd_soc_register_codec(&i2c->dev, &sta32x_codec, &sta32x_dai, 1); 1029 ret = snd_soc_register_codec(&i2c->dev, &sta32x_codec, &sta32x_dai, 1);