Skip to content

Commit fbbf7fe

Browse files
committed
ASoC: wm8940: Convert to direct regmap API usage
This helps move us towards being able to remove the ASoC level I/O code. Signed-off-by: Mark Brown <broonie@linaro.org> Acked-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Acked-by: Jonathan Cameron <jic23@kernel.org>
1 parent 6435e5b commit fbbf7fe

1 file changed

Lines changed: 121 additions & 72 deletions

File tree

‎sound/soc/codecs/wm8940.c‎

Lines changed: 121 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <linux/delay.h>
2929
#include <linux/pm.h>
3030
#include <linux/i2c.h>
31-
#include <linux/spi/spi.h>
31+
#include <linux/regmap.h>
3232
#include <linux/slab.h>
3333
#include <sound/core.h>
3434
#include <sound/pcm.h>
@@ -41,78 +41,116 @@
4141

4242
struct wm8940_priv {
4343
unsigned int sysclk;
44-
enum snd_soc_control_type control_type;
44+
struct regmap *regmap;
4545
};
4646

47-
static int wm8940_volatile_register(struct snd_soc_codec *codec,
48-
unsigned int reg)
47+
static bool wm8940_volatile_register(struct device *dev, unsigned int reg)
4948
{
5049
switch (reg) {
5150
case WM8940_SOFTRESET:
52-
return 1;
51+
return true;
5352
default:
54-
return 0;
53+
return false;
54+
}
55+
}
56+
57+
static bool wm8940_readable_register(struct device *dev, unsigned int reg)
58+
{
59+
switch (reg) {
60+
case WM8940_SOFTRESET:
61+
case WM8940_POWER1:
62+
case WM8940_POWER2:
63+
case WM8940_POWER3:
64+
case WM8940_IFACE:
65+
case WM8940_COMPANDINGCTL:
66+
case WM8940_CLOCK:
67+
case WM8940_ADDCNTRL:
68+
case WM8940_GPIO:
69+
case WM8940_CTLINT:
70+
case WM8940_DAC:
71+
case WM8940_DACVOL:
72+
case WM8940_ADC:
73+
case WM8940_ADCVOL:
74+
case WM8940_NOTCH1:
75+
case WM8940_NOTCH2:
76+
case WM8940_NOTCH3:
77+
case WM8940_NOTCH4:
78+
case WM8940_NOTCH5:
79+
case WM8940_NOTCH6:
80+
case WM8940_NOTCH7:
81+
case WM8940_NOTCH8:
82+
case WM8940_DACLIM1:
83+
case WM8940_DACLIM2:
84+
case WM8940_ALC1:
85+
case WM8940_ALC2:
86+
case WM8940_ALC3:
87+
case WM8940_NOISEGATE:
88+
case WM8940_PLLN:
89+
case WM8940_PLLK1:
90+
case WM8940_PLLK2:
91+
case WM8940_PLLK3:
92+
case WM8940_ALC4:
93+
case WM8940_INPUTCTL:
94+
case WM8940_PGAGAIN:
95+
case WM8940_ADCBOOST:
96+
case WM8940_OUTPUTCTL:
97+
case WM8940_SPKMIX:
98+
case WM8940_SPKVOL:
99+
case WM8940_MONOMIX:
100+
return true;
101+
default:
102+
return false;
55103
}
56104
}
57105

58-
static u16 wm8940_reg_defaults[] = {
59-
0x8940, /* Soft Reset */
60-
0x0000, /* Power 1 */
61-
0x0000, /* Power 2 */
62-
0x0000, /* Power 3 */
63-
0x0010, /* Interface Control */
64-
0x0000, /* Companding Control */
65-
0x0140, /* Clock Control */
66-
0x0000, /* Additional Controls */
67-
0x0000, /* GPIO Control */
68-
0x0002, /* Auto Increment Control */
69-
0x0000, /* DAC Control */
70-
0x00FF, /* DAC Volume */
71-
0,
72-
0,
73-
0x0100, /* ADC Control */
74-
0x00FF, /* ADC Volume */
75-
0x0000, /* Notch Filter 1 Control 1 */
76-
0x0000, /* Notch Filter 1 Control 2 */
77-
0x0000, /* Notch Filter 2 Control 1 */
78-
0x0000, /* Notch Filter 2 Control 2 */
79-
0x0000, /* Notch Filter 3 Control 1 */
80-
0x0000, /* Notch Filter 3 Control 2 */
81-
0x0000, /* Notch Filter 4 Control 1 */
82-
0x0000, /* Notch Filter 4 Control 2 */
83-
0x0032, /* DAC Limit Control 1 */
84-
0x0000, /* DAC Limit Control 2 */
85-
0,
86-
0,
87-
0,
88-
0,
89-
0,
90-
0,
91-
0x0038, /* ALC Control 1 */
92-
0x000B, /* ALC Control 2 */
93-
0x0032, /* ALC Control 3 */
94-
0x0000, /* Noise Gate */
95-
0x0041, /* PLLN */
96-
0x000C, /* PLLK1 */
97-
0x0093, /* PLLK2 */
98-
0x00E9, /* PLLK3 */
99-
0,
100-
0,
101-
0x0030, /* ALC Control 4 */
102-
0,
103-
0x0002, /* Input Control */
104-
0x0050, /* PGA Gain */
105-
0,
106-
0x0002, /* ADC Boost Control */
107-
0,
108-
0x0002, /* Output Control */
109-
0x0000, /* Speaker Mixer Control */
110-
0,
111-
0,
112-
0,
113-
0x0079, /* Speaker Volume */
114-
0,
115-
0x0000, /* Mono Mixer Control */
106+
static const struct reg_default wm8940_reg_defaults[] = {
107+
{ 0x1, 0x0000 }, /* Power 1 */
108+
{ 0x2, 0x0000 }, /* Power 2 */
109+
{ 0x3, 0x0000 }, /* Power 3 */
110+
{ 0x4, 0x0010 }, /* Interface Control */
111+
{ 0x5, 0x0000 }, /* Companding Control */
112+
{ 0x6, 0x0140 }, /* Clock Control */
113+
{ 0x7, 0x0000 }, /* Additional Controls */
114+
{ 0x8, 0x0000 }, /* GPIO Control */
115+
{ 0x9, 0x0002 }, /* Auto Increment Control */
116+
{ 0xa, 0x0000 }, /* DAC Control */
117+
{ 0xb, 0x00FF }, /* DAC Volume */
118+
119+
{ 0xe, 0x0100 }, /* ADC Control */
120+
{ 0xf, 0x00FF }, /* ADC Volume */
121+
{ 0x10, 0x0000 }, /* Notch Filter 1 Control 1 */
122+
{ 0x11, 0x0000 }, /* Notch Filter 1 Control 2 */
123+
{ 0x12, 0x0000 }, /* Notch Filter 2 Control 1 */
124+
{ 0x13, 0x0000 }, /* Notch Filter 2 Control 2 */
125+
{ 0x14, 0x0000 }, /* Notch Filter 3 Control 1 */
126+
{ 0x15, 0x0000 }, /* Notch Filter 3 Control 2 */
127+
{ 0x16, 0x0000 }, /* Notch Filter 4 Control 1 */
128+
{ 0x17, 0x0000 }, /* Notch Filter 4 Control 2 */
129+
{ 0x18, 0x0032 }, /* DAC Limit Control 1 */
130+
{ 0x19, 0x0000 }, /* DAC Limit Control 2 */
131+
132+
{ 0x20, 0x0038 }, /* ALC Control 1 */
133+
{ 0x21, 0x000B }, /* ALC Control 2 */
134+
{ 0x22, 0x0032 }, /* ALC Control 3 */
135+
{ 0x23, 0x0000 }, /* Noise Gate */
136+
{ 0x24, 0x0041 }, /* PLLN */
137+
{ 0x25, 0x000C }, /* PLLK1 */
138+
{ 0x26, 0x0093 }, /* PLLK2 */
139+
{ 0x27, 0x00E9 }, /* PLLK3 */
140+
141+
{ 0x2a, 0x0030 }, /* ALC Control 4 */
142+
143+
{ 0x2c, 0x0002 }, /* Input Control */
144+
{ 0x2d, 0x0050 }, /* PGA Gain */
145+
146+
{ 0x2f, 0x0002 }, /* ADC Boost Control */
147+
148+
{ 0x31, 0x0002 }, /* Output Control */
149+
{ 0x32, 0x0000 }, /* Speaker Mixer Control */
150+
151+
{ 0x36, 0x0079 }, /* Speaker Volume */
152+
153+
{ 0x38, 0x0000 }, /* Mono Mixer Control */
116154
};
117155

118156
static const char *wm8940_companding[] = { "Off", "NC", "u-law", "A-law" };
@@ -431,6 +469,7 @@ static int wm8940_mute(struct snd_soc_dai *dai, int mute)
431469
static int wm8940_set_bias_level(struct snd_soc_codec *codec,
432470
enum snd_soc_bias_level level)
433471
{
472+
struct wm8940_priv *wm8940 = snd_soc_codec_get_drvdata(codec);
434473
u16 val;
435474
u16 pwr_reg = snd_soc_read(codec, WM8940_POWER1) & 0x1F0;
436475
int ret = 0;
@@ -454,7 +493,7 @@ static int wm8940_set_bias_level(struct snd_soc_codec *codec,
454493
break;
455494
case SND_SOC_BIAS_STANDBY:
456495
if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
457-
ret = snd_soc_cache_sync(codec);
496+
ret = regcache_sync(wm8940->regmap);
458497
if (ret < 0) {
459498
dev_err(codec->dev, "Failed to sync cache: %d\n", ret);
460499
return ret;
@@ -669,12 +708,11 @@ static int wm8940_resume(struct snd_soc_codec *codec)
669708

670709
static int wm8940_probe(struct snd_soc_codec *codec)
671710
{
672-
struct wm8940_priv *wm8940 = snd_soc_codec_get_drvdata(codec);
673711
struct wm8940_setup_data *pdata = codec->dev->platform_data;
674712
int ret;
675713
u16 reg;
676714

677-
ret = snd_soc_codec_set_cache_io(codec, 8, 16, wm8940->control_type);
715+
ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP);
678716
if (ret < 0) {
679717
dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
680718
return ret;
@@ -722,10 +760,18 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8940 = {
722760
.num_dapm_widgets = ARRAY_SIZE(wm8940_dapm_widgets),
723761
.dapm_routes = wm8940_dapm_routes,
724762
.num_dapm_routes = ARRAY_SIZE(wm8940_dapm_routes),
725-
.reg_cache_size = ARRAY_SIZE(wm8940_reg_defaults),
726-
.reg_word_size = sizeof(u16),
727-
.reg_cache_default = wm8940_reg_defaults,
728-
.volatile_register = wm8940_volatile_register,
763+
};
764+
765+
static const struct regmap_config wm8940_regmap = {
766+
.reg_bits = 8,
767+
.val_bits = 16,
768+
769+
.max_register = WM8940_MONOMIX,
770+
.reg_defaults = wm8940_reg_defaults,
771+
.num_reg_defaults = ARRAY_SIZE(wm8940_reg_defaults),
772+
773+
.readable_reg = wm8940_readable_register,
774+
.volatile_reg = wm8940_volatile_register,
729775
};
730776

731777
static int wm8940_i2c_probe(struct i2c_client *i2c,
@@ -739,8 +785,11 @@ static int wm8940_i2c_probe(struct i2c_client *i2c,
739785
if (wm8940 == NULL)
740786
return -ENOMEM;
741787

788+
wm8940->regmap = devm_regmap_init_i2c(i2c, &wm8940_regmap);
789+
if (IS_ERR(wm8940->regmap))
790+
return PTR_ERR(wm8940->regmap);
791+
742792
i2c_set_clientdata(i2c, wm8940);
743-
wm8940->control_type = SND_SOC_I2C;
744793

745794
ret = snd_soc_register_codec(&i2c->dev,
746795
&soc_codec_dev_wm8940, &wm8940_dai, 1);

0 commit comments

Comments
 (0)