diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-05-08 10:52:55 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-05-09 07:54:07 -0400 |
commit | 01476801c68166ede4b1abe66b8bf386675cb5e6 (patch) | |
tree | 2d93f08aa1255ed477ac94d52a63e90a92e932f5 /sound/soc/codecs/rt5631.c | |
parent | 03730b8782ed0dc12c0cdb61ba3f07f1d36fba51 (diff) |
ASoC: rt5631: Convert to direct regmap API usage
We're trying to remove all usage of the ASoc level cache and I/O code and
for a device like this with a pretty sparse register map the rbtree cache
is a better idea anyway.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/codecs/rt5631.c')
-rw-r--r-- | sound/soc/codecs/rt5631.c | 95 |
1 files changed, 54 insertions, 41 deletions
diff --git a/sound/soc/codecs/rt5631.c b/sound/soc/codecs/rt5631.c index a64f2a75c365..960d0e93cce9 100644 --- a/sound/soc/codecs/rt5631.c +++ b/sound/soc/codecs/rt5631.c | |||
@@ -18,7 +18,7 @@ | |||
18 | #include <linux/delay.h> | 18 | #include <linux/delay.h> |
19 | #include <linux/pm.h> | 19 | #include <linux/pm.h> |
20 | #include <linux/i2c.h> | 20 | #include <linux/i2c.h> |
21 | #include <linux/spi/spi.h> | 21 | #include <linux/regmap.h> |
22 | #include <sound/core.h> | 22 | #include <sound/core.h> |
23 | #include <sound/pcm.h> | 23 | #include <sound/pcm.h> |
24 | #include <sound/pcm_params.h> | 24 | #include <sound/pcm_params.h> |
@@ -30,6 +30,7 @@ | |||
30 | #include "rt5631.h" | 30 | #include "rt5631.h" |
31 | 31 | ||
32 | struct rt5631_priv { | 32 | struct rt5631_priv { |
33 | struct regmap *regmap; | ||
33 | int codec_version; | 34 | int codec_version; |
34 | int master; | 35 | int master; |
35 | int sysclk; | 36 | int sysclk; |
@@ -38,33 +39,33 @@ struct rt5631_priv { | |||
38 | int dmic_used_flag; | 39 | int dmic_used_flag; |
39 | }; | 40 | }; |
40 | 41 | ||
41 | static const u16 rt5631_reg[RT5631_VENDOR_ID2 + 1] = { | 42 | static const struct reg_default rt5631_reg[] = { |
42 | [RT5631_SPK_OUT_VOL] = 0x8888, | 43 | { RT5631_SPK_OUT_VOL, 0x8888 }, |
43 | [RT5631_HP_OUT_VOL] = 0x8080, | 44 | { RT5631_HP_OUT_VOL, 0x8080 }, |
44 | [RT5631_MONO_AXO_1_2_VOL] = 0xa080, | 45 | { RT5631_MONO_AXO_1_2_VOL, 0xa080 }, |
45 | [RT5631_AUX_IN_VOL] = 0x0808, | 46 | { RT5631_AUX_IN_VOL, 0x0808 }, |
46 | [RT5631_ADC_REC_MIXER] = 0xf0f0, | 47 | { RT5631_ADC_REC_MIXER, 0xf0f0 }, |
47 | [RT5631_VDAC_DIG_VOL] = 0x0010, | 48 | { RT5631_VDAC_DIG_VOL, 0x0010 }, |
48 | [RT5631_OUTMIXER_L_CTRL] = 0xffc0, | 49 | { RT5631_OUTMIXER_L_CTRL, 0xffc0 }, |
49 | [RT5631_OUTMIXER_R_CTRL] = 0xffc0, | 50 | { RT5631_OUTMIXER_R_CTRL, 0xffc0 }, |
50 | [RT5631_AXO1MIXER_CTRL] = 0x88c0, | 51 | { RT5631_AXO1MIXER_CTRL, 0x88c0 }, |
51 | [RT5631_AXO2MIXER_CTRL] = 0x88c0, | 52 | { RT5631_AXO2MIXER_CTRL, 0x88c0 }, |
52 | [RT5631_DIG_MIC_CTRL] = 0x3000, | 53 | { RT5631_DIG_MIC_CTRL, 0x3000 }, |
53 | [RT5631_MONO_INPUT_VOL] = 0x8808, | 54 | { RT5631_MONO_INPUT_VOL, 0x8808 }, |
54 | [RT5631_SPK_MIXER_CTRL] = 0xf8f8, | 55 | { RT5631_SPK_MIXER_CTRL, 0xf8f8 }, |
55 | [RT5631_SPK_MONO_OUT_CTRL] = 0xfc00, | 56 | { RT5631_SPK_MONO_OUT_CTRL, 0xfc00 }, |
56 | [RT5631_SPK_MONO_HP_OUT_CTRL] = 0x4440, | 57 | { RT5631_SPK_MONO_HP_OUT_CTRL, 0x4440 }, |
57 | [RT5631_SDP_CTRL] = 0x8000, | 58 | { RT5631_SDP_CTRL, 0x8000 }, |
58 | [RT5631_MONO_SDP_CTRL] = 0x8000, | 59 | { RT5631_MONO_SDP_CTRL, 0x8000 }, |
59 | [RT5631_STEREO_AD_DA_CLK_CTRL] = 0x2010, | 60 | { RT5631_STEREO_AD_DA_CLK_CTRL, 0x2010 }, |
60 | [RT5631_GEN_PUR_CTRL_REG] = 0x0e00, | 61 | { RT5631_GEN_PUR_CTRL_REG, 0x0e00 }, |
61 | [RT5631_INT_ST_IRQ_CTRL_2] = 0x071a, | 62 | { RT5631_INT_ST_IRQ_CTRL_2, 0x071a }, |
62 | [RT5631_MISC_CTRL] = 0x2040, | 63 | { RT5631_MISC_CTRL, 0x2040 }, |
63 | [RT5631_DEPOP_FUN_CTRL_2] = 0x8000, | 64 | { RT5631_DEPOP_FUN_CTRL_2, 0x8000 }, |
64 | [RT5631_SOFT_VOL_CTRL] = 0x07e0, | 65 | { RT5631_SOFT_VOL_CTRL, 0x07e0 }, |
65 | [RT5631_ALC_CTRL_1] = 0x0206, | 66 | { RT5631_ALC_CTRL_1, 0x0206 }, |
66 | [RT5631_ALC_CTRL_3] = 0x2000, | 67 | { RT5631_ALC_CTRL_3, 0x2000 }, |
67 | [RT5631_PSEUDO_SPATL_CTRL] = 0x0553, | 68 | { RT5631_PSEUDO_SPATL_CTRL, 0x0553 }, |
68 | }; | 69 | }; |
69 | 70 | ||
70 | /** | 71 | /** |
@@ -96,8 +97,7 @@ static int rt5631_reset(struct snd_soc_codec *codec) | |||
96 | return snd_soc_write(codec, RT5631_RESET, 0); | 97 | return snd_soc_write(codec, RT5631_RESET, 0); |
97 | } | 98 | } |
98 | 99 | ||
99 | static int rt5631_volatile_register(struct snd_soc_codec *codec, | 100 | static bool rt5631_volatile_register(struct device *dev, unsigned int reg) |
100 | unsigned int reg) | ||
101 | { | 101 | { |
102 | switch (reg) { | 102 | switch (reg) { |
103 | case RT5631_RESET: | 103 | case RT5631_RESET: |
@@ -111,8 +111,7 @@ static int rt5631_volatile_register(struct snd_soc_codec *codec, | |||
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | static int rt5631_readable_register(struct snd_soc_codec *codec, | 114 | static bool rt5631_readable_register(struct device *dev, unsigned int reg) |
115 | unsigned int reg) | ||
116 | { | 115 | { |
117 | switch (reg) { | 116 | switch (reg) { |
118 | case RT5631_RESET: | 117 | case RT5631_RESET: |
@@ -1543,6 +1542,8 @@ static int rt5631_codec_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id, | |||
1543 | static int rt5631_set_bias_level(struct snd_soc_codec *codec, | 1542 | static int rt5631_set_bias_level(struct snd_soc_codec *codec, |
1544 | enum snd_soc_bias_level level) | 1543 | enum snd_soc_bias_level level) |
1545 | { | 1544 | { |
1545 | struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec); | ||
1546 | |||
1546 | switch (level) { | 1547 | switch (level) { |
1547 | case SND_SOC_BIAS_ON: | 1548 | case SND_SOC_BIAS_ON: |
1548 | case SND_SOC_BIAS_PREPARE: | 1549 | case SND_SOC_BIAS_PREPARE: |
@@ -1560,8 +1561,8 @@ static int rt5631_set_bias_level(struct snd_soc_codec *codec, | |||
1560 | snd_soc_update_bits(codec, RT5631_PWR_MANAG_ADD3, | 1561 | snd_soc_update_bits(codec, RT5631_PWR_MANAG_ADD3, |
1561 | RT5631_PWR_FAST_VREF_CTRL, | 1562 | RT5631_PWR_FAST_VREF_CTRL, |
1562 | RT5631_PWR_FAST_VREF_CTRL); | 1563 | RT5631_PWR_FAST_VREF_CTRL); |
1563 | codec->cache_only = false; | 1564 | regcache_cache_only(rt5631->regmap, false); |
1564 | snd_soc_cache_sync(codec); | 1565 | regcache_sync(rt5631->regmap); |
1565 | } | 1566 | } |
1566 | break; | 1567 | break; |
1567 | 1568 | ||
@@ -1586,7 +1587,9 @@ static int rt5631_probe(struct snd_soc_codec *codec) | |||
1586 | unsigned int val; | 1587 | unsigned int val; |
1587 | int ret; | 1588 | int ret; |
1588 | 1589 | ||
1589 | ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C); | 1590 | codec->control_data = rt5631->regmap; |
1591 | |||
1592 | ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP); | ||
1590 | if (ret != 0) { | 1593 | if (ret != 0) { |
1591 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); | 1594 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
1592 | return ret; | 1595 | return ret; |
@@ -1697,12 +1700,6 @@ static struct snd_soc_codec_driver soc_codec_dev_rt5631 = { | |||
1697 | .suspend = rt5631_suspend, | 1700 | .suspend = rt5631_suspend, |
1698 | .resume = rt5631_resume, | 1701 | .resume = rt5631_resume, |
1699 | .set_bias_level = rt5631_set_bias_level, | 1702 | .set_bias_level = rt5631_set_bias_level, |
1700 | .reg_cache_size = RT5631_VENDOR_ID2 + 1, | ||
1701 | .reg_word_size = sizeof(u16), | ||
1702 | .reg_cache_default = rt5631_reg, | ||
1703 | .volatile_register = rt5631_volatile_register, | ||
1704 | .readable_register = rt5631_readable_register, | ||
1705 | .reg_cache_step = 1, | ||
1706 | .controls = rt5631_snd_controls, | 1703 | .controls = rt5631_snd_controls, |
1707 | .num_controls = ARRAY_SIZE(rt5631_snd_controls), | 1704 | .num_controls = ARRAY_SIZE(rt5631_snd_controls), |
1708 | .dapm_widgets = rt5631_dapm_widgets, | 1705 | .dapm_widgets = rt5631_dapm_widgets, |
@@ -1717,6 +1714,18 @@ static const struct i2c_device_id rt5631_i2c_id[] = { | |||
1717 | }; | 1714 | }; |
1718 | MODULE_DEVICE_TABLE(i2c, rt5631_i2c_id); | 1715 | MODULE_DEVICE_TABLE(i2c, rt5631_i2c_id); |
1719 | 1716 | ||
1717 | static const struct regmap_config rt5631_regmap_config = { | ||
1718 | .reg_bits = 8, | ||
1719 | .val_bits = 16, | ||
1720 | |||
1721 | .readable_reg = rt5631_readable_register, | ||
1722 | .volatile_reg = rt5631_volatile_register, | ||
1723 | .max_register = RT5631_VENDOR_ID2, | ||
1724 | .reg_defaults = rt5631_reg, | ||
1725 | .num_reg_defaults = ARRAY_SIZE(rt5631_reg), | ||
1726 | .cache_type = REGCACHE_RBTREE, | ||
1727 | }; | ||
1728 | |||
1720 | static int rt5631_i2c_probe(struct i2c_client *i2c, | 1729 | static int rt5631_i2c_probe(struct i2c_client *i2c, |
1721 | const struct i2c_device_id *id) | 1730 | const struct i2c_device_id *id) |
1722 | { | 1731 | { |
@@ -1730,6 +1739,10 @@ static int rt5631_i2c_probe(struct i2c_client *i2c, | |||
1730 | 1739 | ||
1731 | i2c_set_clientdata(i2c, rt5631); | 1740 | i2c_set_clientdata(i2c, rt5631); |
1732 | 1741 | ||
1742 | rt5631->regmap = devm_regmap_init_i2c(i2c, &rt5631_regmap_config); | ||
1743 | if (IS_ERR(rt5631->regmap)) | ||
1744 | return PTR_ERR(rt5631->regmap); | ||
1745 | |||
1733 | ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5631, | 1746 | ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5631, |
1734 | rt5631_dai, ARRAY_SIZE(rt5631_dai)); | 1747 | rt5631_dai, ARRAY_SIZE(rt5631_dai)); |
1735 | return ret; | 1748 | return ret; |