1 // SPDX-License-Identifier: GPL-2.0-only
3 * wm8770.c -- WM8770 ALSA SoC Audio driver
5 * Copyright 2010 Wolfson Microelectronics plc
7 * Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
10 #include <linux/module.h>
11 #include <linux/moduleparam.h>
12 #include <linux/init.h>
13 #include <linux/delay.h>
14 #include <linux/of_device.h>
16 #include <linux/spi/spi.h>
17 #include <linux/regmap.h>
18 #include <linux/regulator/consumer.h>
19 #include <linux/slab.h>
20 #include <sound/core.h>
21 #include <sound/pcm.h>
22 #include <sound/pcm_params.h>
23 #include <sound/soc.h>
24 #include <sound/initval.h>
25 #include <sound/tlv.h>
29 #define WM8770_NUM_SUPPLIES 3
30 static const char *wm8770_supply_names
[WM8770_NUM_SUPPLIES
] = {
36 static const struct reg_default wm8770_reg_defaults
[] = {
70 static bool wm8770_volatile_reg(struct device
*dev
, unsigned int reg
)
81 struct regmap
*regmap
;
82 struct regulator_bulk_data supplies
[WM8770_NUM_SUPPLIES
];
83 struct notifier_block disable_nb
[WM8770_NUM_SUPPLIES
];
84 struct snd_soc_component
*component
;
88 static int vout12supply_event(struct snd_soc_dapm_widget
*w
,
89 struct snd_kcontrol
*kcontrol
, int event
);
90 static int vout34supply_event(struct snd_soc_dapm_widget
*w
,
91 struct snd_kcontrol
*kcontrol
, int event
);
94 * We can't use the same notifier block for more than one supply and
95 * there's no way I can see to get from a callback to the caller
96 * except container_of().
98 #define WM8770_REGULATOR_EVENT(n) \
99 static int wm8770_regulator_event_##n(struct notifier_block *nb, \
100 unsigned long event, void *data) \
102 struct wm8770_priv *wm8770 = container_of(nb, struct wm8770_priv, \
104 if (event & REGULATOR_EVENT_DISABLE) { \
105 regcache_mark_dirty(wm8770->regmap); \
110 WM8770_REGULATOR_EVENT(0)
111 WM8770_REGULATOR_EVENT(1)
112 WM8770_REGULATOR_EVENT(2)
114 static const DECLARE_TLV_DB_SCALE(adc_tlv
, -1200, 100, 0);
115 static const DECLARE_TLV_DB_SCALE(dac_dig_tlv
, -12750, 50, 1);
116 static const DECLARE_TLV_DB_SCALE(dac_alg_tlv
, -12700, 100, 1);
118 static const char *dac_phase_text
[][2] = {
119 { "DAC1 Normal", "DAC1 Inverted" },
120 { "DAC2 Normal", "DAC2 Inverted" },
121 { "DAC3 Normal", "DAC3 Inverted" },
122 { "DAC4 Normal", "DAC4 Inverted" },
125 static const struct soc_enum dac_phase
[] = {
126 SOC_ENUM_DOUBLE(WM8770_DACPHASE
, 0, 1, 2, dac_phase_text
[0]),
127 SOC_ENUM_DOUBLE(WM8770_DACPHASE
, 2, 3, 2, dac_phase_text
[1]),
128 SOC_ENUM_DOUBLE(WM8770_DACPHASE
, 4, 5, 2, dac_phase_text
[2]),
129 SOC_ENUM_DOUBLE(WM8770_DACPHASE
, 6, 7, 2, dac_phase_text
[3]),
132 static const struct snd_kcontrol_new wm8770_snd_controls
[] = {
133 /* global DAC playback controls */
134 SOC_SINGLE_TLV("DAC Playback Volume", WM8770_MSDIGVOL
, 0, 255, 0,
136 SOC_SINGLE("DAC Playback Switch", WM8770_DACMUTE
, 4, 1, 1),
137 SOC_SINGLE("DAC Playback ZC Switch", WM8770_DACCTRL1
, 0, 1, 0),
139 /* global VOUT playback controls */
140 SOC_SINGLE_TLV("VOUT Playback Volume", WM8770_MSALGVOL
, 0, 127, 0,
142 SOC_SINGLE("VOUT Playback ZC Switch", WM8770_MSALGVOL
, 7, 1, 0),
144 /* VOUT1/2/3/4 specific controls */
145 SOC_DOUBLE_R_TLV("VOUT1 Playback Volume", WM8770_VOUT1LVOL
,
146 WM8770_VOUT1RVOL
, 0, 127, 0, dac_alg_tlv
),
147 SOC_DOUBLE_R("VOUT1 Playback ZC Switch", WM8770_VOUT1LVOL
,
148 WM8770_VOUT1RVOL
, 7, 1, 0),
149 SOC_DOUBLE_R_TLV("VOUT2 Playback Volume", WM8770_VOUT2LVOL
,
150 WM8770_VOUT2RVOL
, 0, 127, 0, dac_alg_tlv
),
151 SOC_DOUBLE_R("VOUT2 Playback ZC Switch", WM8770_VOUT2LVOL
,
152 WM8770_VOUT2RVOL
, 7, 1, 0),
153 SOC_DOUBLE_R_TLV("VOUT3 Playback Volume", WM8770_VOUT3LVOL
,
154 WM8770_VOUT3RVOL
, 0, 127, 0, dac_alg_tlv
),
155 SOC_DOUBLE_R("VOUT3 Playback ZC Switch", WM8770_VOUT3LVOL
,
156 WM8770_VOUT3RVOL
, 7, 1, 0),
157 SOC_DOUBLE_R_TLV("VOUT4 Playback Volume", WM8770_VOUT4LVOL
,
158 WM8770_VOUT4RVOL
, 0, 127, 0, dac_alg_tlv
),
159 SOC_DOUBLE_R("VOUT4 Playback ZC Switch", WM8770_VOUT4LVOL
,
160 WM8770_VOUT4RVOL
, 7, 1, 0),
162 /* DAC1/2/3/4 specific controls */
163 SOC_DOUBLE_R_TLV("DAC1 Playback Volume", WM8770_DAC1LVOL
,
164 WM8770_DAC1RVOL
, 0, 255, 0, dac_dig_tlv
),
165 SOC_SINGLE("DAC1 Deemphasis Switch", WM8770_DACCTRL2
, 0, 1, 0),
166 SOC_ENUM("DAC1 Phase", dac_phase
[0]),
167 SOC_DOUBLE_R_TLV("DAC2 Playback Volume", WM8770_DAC2LVOL
,
168 WM8770_DAC2RVOL
, 0, 255, 0, dac_dig_tlv
),
169 SOC_SINGLE("DAC2 Deemphasis Switch", WM8770_DACCTRL2
, 1, 1, 0),
170 SOC_ENUM("DAC2 Phase", dac_phase
[1]),
171 SOC_DOUBLE_R_TLV("DAC3 Playback Volume", WM8770_DAC3LVOL
,
172 WM8770_DAC3RVOL
, 0, 255, 0, dac_dig_tlv
),
173 SOC_SINGLE("DAC3 Deemphasis Switch", WM8770_DACCTRL2
, 2, 1, 0),
174 SOC_ENUM("DAC3 Phase", dac_phase
[2]),
175 SOC_DOUBLE_R_TLV("DAC4 Playback Volume", WM8770_DAC4LVOL
,
176 WM8770_DAC4RVOL
, 0, 255, 0, dac_dig_tlv
),
177 SOC_SINGLE("DAC4 Deemphasis Switch", WM8770_DACCTRL2
, 3, 1, 0),
178 SOC_ENUM("DAC4 Phase", dac_phase
[3]),
180 /* ADC specific controls */
181 SOC_DOUBLE_R_TLV("Capture Volume", WM8770_ADCLCTRL
, WM8770_ADCRCTRL
,
183 SOC_DOUBLE_R("Capture Switch", WM8770_ADCLCTRL
, WM8770_ADCRCTRL
,
187 SOC_SINGLE("ADC 128x Oversampling Switch", WM8770_MSTRCTRL
, 3, 1, 0),
188 SOC_SINGLE("ADC Highpass Filter Switch", WM8770_IFACECTRL
, 8, 1, 1)
191 static const char *ain_text
[] = {
192 "AIN1", "AIN2", "AIN3", "AIN4",
193 "AIN5", "AIN6", "AIN7", "AIN8"
196 static SOC_ENUM_DOUBLE_DECL(ain_enum
,
197 WM8770_ADCMUX
, 0, 4, ain_text
);
199 static const struct snd_kcontrol_new ain_mux
=
200 SOC_DAPM_ENUM("Capture Mux", ain_enum
);
202 static const struct snd_kcontrol_new vout1_mix_controls
[] = {
203 SOC_DAPM_SINGLE("DAC1 Switch", WM8770_OUTMUX1
, 0, 1, 0),
204 SOC_DAPM_SINGLE("AUX1 Switch", WM8770_OUTMUX1
, 1, 1, 0),
205 SOC_DAPM_SINGLE("Bypass Switch", WM8770_OUTMUX1
, 2, 1, 0)
208 static const struct snd_kcontrol_new vout2_mix_controls
[] = {
209 SOC_DAPM_SINGLE("DAC2 Switch", WM8770_OUTMUX1
, 3, 1, 0),
210 SOC_DAPM_SINGLE("AUX2 Switch", WM8770_OUTMUX1
, 4, 1, 0),
211 SOC_DAPM_SINGLE("Bypass Switch", WM8770_OUTMUX1
, 5, 1, 0)
214 static const struct snd_kcontrol_new vout3_mix_controls
[] = {
215 SOC_DAPM_SINGLE("DAC3 Switch", WM8770_OUTMUX2
, 0, 1, 0),
216 SOC_DAPM_SINGLE("AUX3 Switch", WM8770_OUTMUX2
, 1, 1, 0),
217 SOC_DAPM_SINGLE("Bypass Switch", WM8770_OUTMUX2
, 2, 1, 0)
220 static const struct snd_kcontrol_new vout4_mix_controls
[] = {
221 SOC_DAPM_SINGLE("DAC4 Switch", WM8770_OUTMUX2
, 3, 1, 0),
222 SOC_DAPM_SINGLE("Bypass Switch", WM8770_OUTMUX2
, 4, 1, 0)
225 static const struct snd_soc_dapm_widget wm8770_dapm_widgets
[] = {
226 SND_SOC_DAPM_INPUT("AUX1"),
227 SND_SOC_DAPM_INPUT("AUX2"),
228 SND_SOC_DAPM_INPUT("AUX3"),
230 SND_SOC_DAPM_INPUT("AIN1"),
231 SND_SOC_DAPM_INPUT("AIN2"),
232 SND_SOC_DAPM_INPUT("AIN3"),
233 SND_SOC_DAPM_INPUT("AIN4"),
234 SND_SOC_DAPM_INPUT("AIN5"),
235 SND_SOC_DAPM_INPUT("AIN6"),
236 SND_SOC_DAPM_INPUT("AIN7"),
237 SND_SOC_DAPM_INPUT("AIN8"),
239 SND_SOC_DAPM_MUX("Capture Mux", WM8770_ADCMUX
, 8, 1, &ain_mux
),
241 SND_SOC_DAPM_ADC("ADC", "Capture", WM8770_PWDNCTRL
, 1, 1),
243 SND_SOC_DAPM_DAC("DAC1", "Playback", WM8770_PWDNCTRL
, 2, 1),
244 SND_SOC_DAPM_DAC("DAC2", "Playback", WM8770_PWDNCTRL
, 3, 1),
245 SND_SOC_DAPM_DAC("DAC3", "Playback", WM8770_PWDNCTRL
, 4, 1),
246 SND_SOC_DAPM_DAC("DAC4", "Playback", WM8770_PWDNCTRL
, 5, 1),
248 SND_SOC_DAPM_SUPPLY("VOUT12 Supply", SND_SOC_NOPM
, 0, 0,
249 vout12supply_event
, SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
250 SND_SOC_DAPM_SUPPLY("VOUT34 Supply", SND_SOC_NOPM
, 0, 0,
251 vout34supply_event
, SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
253 SND_SOC_DAPM_MIXER("VOUT1 Mixer", SND_SOC_NOPM
, 0, 0,
254 vout1_mix_controls
, ARRAY_SIZE(vout1_mix_controls
)),
255 SND_SOC_DAPM_MIXER("VOUT2 Mixer", SND_SOC_NOPM
, 0, 0,
256 vout2_mix_controls
, ARRAY_SIZE(vout2_mix_controls
)),
257 SND_SOC_DAPM_MIXER("VOUT3 Mixer", SND_SOC_NOPM
, 0, 0,
258 vout3_mix_controls
, ARRAY_SIZE(vout3_mix_controls
)),
259 SND_SOC_DAPM_MIXER("VOUT4 Mixer", SND_SOC_NOPM
, 0, 0,
260 vout4_mix_controls
, ARRAY_SIZE(vout4_mix_controls
)),
262 SND_SOC_DAPM_OUTPUT("VOUT1"),
263 SND_SOC_DAPM_OUTPUT("VOUT2"),
264 SND_SOC_DAPM_OUTPUT("VOUT3"),
265 SND_SOC_DAPM_OUTPUT("VOUT4")
268 static const struct snd_soc_dapm_route wm8770_intercon
[] = {
269 { "Capture Mux", "AIN1", "AIN1" },
270 { "Capture Mux", "AIN2", "AIN2" },
271 { "Capture Mux", "AIN3", "AIN3" },
272 { "Capture Mux", "AIN4", "AIN4" },
273 { "Capture Mux", "AIN5", "AIN5" },
274 { "Capture Mux", "AIN6", "AIN6" },
275 { "Capture Mux", "AIN7", "AIN7" },
276 { "Capture Mux", "AIN8", "AIN8" },
278 { "ADC", NULL
, "Capture Mux" },
280 { "VOUT1 Mixer", NULL
, "VOUT12 Supply" },
281 { "VOUT1 Mixer", "DAC1 Switch", "DAC1" },
282 { "VOUT1 Mixer", "AUX1 Switch", "AUX1" },
283 { "VOUT1 Mixer", "Bypass Switch", "Capture Mux" },
285 { "VOUT2 Mixer", NULL
, "VOUT12 Supply" },
286 { "VOUT2 Mixer", "DAC2 Switch", "DAC2" },
287 { "VOUT2 Mixer", "AUX2 Switch", "AUX2" },
288 { "VOUT2 Mixer", "Bypass Switch", "Capture Mux" },
290 { "VOUT3 Mixer", NULL
, "VOUT34 Supply" },
291 { "VOUT3 Mixer", "DAC3 Switch", "DAC3" },
292 { "VOUT3 Mixer", "AUX3 Switch", "AUX3" },
293 { "VOUT3 Mixer", "Bypass Switch", "Capture Mux" },
295 { "VOUT4 Mixer", NULL
, "VOUT34 Supply" },
296 { "VOUT4 Mixer", "DAC4 Switch", "DAC4" },
297 { "VOUT4 Mixer", "Bypass Switch", "Capture Mux" },
299 { "VOUT1", NULL
, "VOUT1 Mixer" },
300 { "VOUT2", NULL
, "VOUT2 Mixer" },
301 { "VOUT3", NULL
, "VOUT3 Mixer" },
302 { "VOUT4", NULL
, "VOUT4 Mixer" }
305 static int vout12supply_event(struct snd_soc_dapm_widget
*w
,
306 struct snd_kcontrol
*kcontrol
, int event
)
308 struct snd_soc_component
*component
= snd_soc_dapm_to_component(w
->dapm
);
311 case SND_SOC_DAPM_PRE_PMU
:
312 snd_soc_component_update_bits(component
, WM8770_OUTMUX1
, 0x180, 0);
314 case SND_SOC_DAPM_POST_PMD
:
315 snd_soc_component_update_bits(component
, WM8770_OUTMUX1
, 0x180, 0x180);
322 static int vout34supply_event(struct snd_soc_dapm_widget
*w
,
323 struct snd_kcontrol
*kcontrol
, int event
)
325 struct snd_soc_component
*component
= snd_soc_dapm_to_component(w
->dapm
);
328 case SND_SOC_DAPM_PRE_PMU
:
329 snd_soc_component_update_bits(component
, WM8770_OUTMUX2
, 0x180, 0);
331 case SND_SOC_DAPM_POST_PMD
:
332 snd_soc_component_update_bits(component
, WM8770_OUTMUX2
, 0x180, 0x180);
339 static int wm8770_reset(struct snd_soc_component
*component
)
341 return snd_soc_component_write(component
, WM8770_RESET
, 0);
344 static int wm8770_set_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
346 struct snd_soc_component
*component
;
349 component
= dai
->component
;
351 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
352 case SND_SOC_DAIFMT_CBM_CFM
:
355 case SND_SOC_DAIFMT_CBS_CFS
:
363 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
364 case SND_SOC_DAIFMT_I2S
:
367 case SND_SOC_DAIFMT_RIGHT_J
:
369 case SND_SOC_DAIFMT_LEFT_J
:
376 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
377 case SND_SOC_DAIFMT_NB_NF
:
379 case SND_SOC_DAIFMT_IB_IF
:
382 case SND_SOC_DAIFMT_IB_NF
:
385 case SND_SOC_DAIFMT_NB_IF
:
392 snd_soc_component_update_bits(component
, WM8770_IFACECTRL
, 0xf, iface
);
393 snd_soc_component_update_bits(component
, WM8770_MSTRCTRL
, 0x100, master
);
398 static const int mclk_ratios
[] = {
407 static int wm8770_hw_params(struct snd_pcm_substream
*substream
,
408 struct snd_pcm_hw_params
*params
,
409 struct snd_soc_dai
*dai
)
411 struct snd_soc_component
*component
;
412 struct wm8770_priv
*wm8770
;
418 component
= dai
->component
;
419 wm8770
= snd_soc_component_get_drvdata(component
);
422 switch (params_width(params
)) {
436 switch (substream
->stream
) {
437 case SNDRV_PCM_STREAM_PLAYBACK
:
441 case SNDRV_PCM_STREAM_CAPTURE
:
449 /* Only need to set MCLK/LRCLK ratio if we're master */
450 if (snd_soc_component_read32(component
, WM8770_MSTRCTRL
) & 0x100) {
451 for (; i
< ARRAY_SIZE(mclk_ratios
); ++i
) {
452 ratio
= wm8770
->sysclk
/ params_rate(params
);
453 if (ratio
== mclk_ratios
[i
])
457 if (i
== ARRAY_SIZE(mclk_ratios
)) {
458 dev_err(component
->dev
,
459 "Unable to configure MCLK ratio %d/%d\n",
460 wm8770
->sysclk
, params_rate(params
));
464 dev_dbg(component
->dev
, "MCLK is %dfs\n", mclk_ratios
[i
]);
466 snd_soc_component_update_bits(component
, WM8770_MSTRCTRL
, 0x7 << shift
,
470 snd_soc_component_update_bits(component
, WM8770_IFACECTRL
, 0x30, iface
);
475 static int wm8770_mute(struct snd_soc_dai
*dai
, int mute
)
477 struct snd_soc_component
*component
;
479 component
= dai
->component
;
480 return snd_soc_component_update_bits(component
, WM8770_DACMUTE
, 0x10,
484 static int wm8770_set_sysclk(struct snd_soc_dai
*dai
,
485 int clk_id
, unsigned int freq
, int dir
)
487 struct snd_soc_component
*component
;
488 struct wm8770_priv
*wm8770
;
490 component
= dai
->component
;
491 wm8770
= snd_soc_component_get_drvdata(component
);
492 wm8770
->sysclk
= freq
;
496 static int wm8770_set_bias_level(struct snd_soc_component
*component
,
497 enum snd_soc_bias_level level
)
500 struct wm8770_priv
*wm8770
;
502 wm8770
= snd_soc_component_get_drvdata(component
);
505 case SND_SOC_BIAS_ON
:
507 case SND_SOC_BIAS_PREPARE
:
509 case SND_SOC_BIAS_STANDBY
:
510 if (snd_soc_component_get_bias_level(component
) == SND_SOC_BIAS_OFF
) {
511 ret
= regulator_bulk_enable(ARRAY_SIZE(wm8770
->supplies
),
514 dev_err(component
->dev
,
515 "Failed to enable supplies: %d\n",
520 regcache_sync(wm8770
->regmap
);
523 snd_soc_component_write(component
, WM8770_PWDNCTRL
, 0);
526 case SND_SOC_BIAS_OFF
:
527 /* global powerdown */
528 snd_soc_component_write(component
, WM8770_PWDNCTRL
, 1);
529 regulator_bulk_disable(ARRAY_SIZE(wm8770
->supplies
),
537 #define WM8770_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
538 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
540 static const struct snd_soc_dai_ops wm8770_dai_ops
= {
541 .digital_mute
= wm8770_mute
,
542 .hw_params
= wm8770_hw_params
,
543 .set_fmt
= wm8770_set_fmt
,
544 .set_sysclk
= wm8770_set_sysclk
,
547 static struct snd_soc_dai_driver wm8770_dai
= {
548 .name
= "wm8770-hifi",
550 .stream_name
= "Playback",
553 .rates
= SNDRV_PCM_RATE_8000_192000
,
554 .formats
= WM8770_FORMATS
557 .stream_name
= "Capture",
560 .rates
= SNDRV_PCM_RATE_8000_96000
,
561 .formats
= WM8770_FORMATS
563 .ops
= &wm8770_dai_ops
,
567 static int wm8770_probe(struct snd_soc_component
*component
)
569 struct wm8770_priv
*wm8770
;
572 wm8770
= snd_soc_component_get_drvdata(component
);
573 wm8770
->component
= component
;
575 ret
= regulator_bulk_enable(ARRAY_SIZE(wm8770
->supplies
),
578 dev_err(component
->dev
, "Failed to enable supplies: %d\n", ret
);
582 ret
= wm8770_reset(component
);
584 dev_err(component
->dev
, "Failed to issue reset: %d\n", ret
);
588 /* latch the volume update bits */
589 snd_soc_component_update_bits(component
, WM8770_MSDIGVOL
, 0x100, 0x100);
590 snd_soc_component_update_bits(component
, WM8770_MSALGVOL
, 0x100, 0x100);
591 snd_soc_component_update_bits(component
, WM8770_VOUT1RVOL
, 0x100, 0x100);
592 snd_soc_component_update_bits(component
, WM8770_VOUT2RVOL
, 0x100, 0x100);
593 snd_soc_component_update_bits(component
, WM8770_VOUT3RVOL
, 0x100, 0x100);
594 snd_soc_component_update_bits(component
, WM8770_VOUT4RVOL
, 0x100, 0x100);
595 snd_soc_component_update_bits(component
, WM8770_DAC1RVOL
, 0x100, 0x100);
596 snd_soc_component_update_bits(component
, WM8770_DAC2RVOL
, 0x100, 0x100);
597 snd_soc_component_update_bits(component
, WM8770_DAC3RVOL
, 0x100, 0x100);
598 snd_soc_component_update_bits(component
, WM8770_DAC4RVOL
, 0x100, 0x100);
601 snd_soc_component_update_bits(component
, WM8770_DACMUTE
, 0x10, 0x10);
604 regulator_bulk_disable(ARRAY_SIZE(wm8770
->supplies
), wm8770
->supplies
);
608 static const struct snd_soc_component_driver soc_component_dev_wm8770
= {
609 .probe
= wm8770_probe
,
610 .set_bias_level
= wm8770_set_bias_level
,
611 .controls
= wm8770_snd_controls
,
612 .num_controls
= ARRAY_SIZE(wm8770_snd_controls
),
613 .dapm_widgets
= wm8770_dapm_widgets
,
614 .num_dapm_widgets
= ARRAY_SIZE(wm8770_dapm_widgets
),
615 .dapm_routes
= wm8770_intercon
,
616 .num_dapm_routes
= ARRAY_SIZE(wm8770_intercon
),
617 .use_pmdown_time
= 1,
619 .non_legacy_dai_naming
= 1,
622 static const struct of_device_id wm8770_of_match
[] = {
623 { .compatible
= "wlf,wm8770", },
626 MODULE_DEVICE_TABLE(of
, wm8770_of_match
);
628 static const struct regmap_config wm8770_regmap
= {
631 .max_register
= WM8770_RESET
,
633 .reg_defaults
= wm8770_reg_defaults
,
634 .num_reg_defaults
= ARRAY_SIZE(wm8770_reg_defaults
),
635 .cache_type
= REGCACHE_RBTREE
,
637 .volatile_reg
= wm8770_volatile_reg
,
640 static int wm8770_spi_probe(struct spi_device
*spi
)
642 struct wm8770_priv
*wm8770
;
645 wm8770
= devm_kzalloc(&spi
->dev
, sizeof(struct wm8770_priv
),
650 for (i
= 0; i
< ARRAY_SIZE(wm8770
->supplies
); i
++)
651 wm8770
->supplies
[i
].supply
= wm8770_supply_names
[i
];
653 ret
= devm_regulator_bulk_get(&spi
->dev
, ARRAY_SIZE(wm8770
->supplies
),
656 dev_err(&spi
->dev
, "Failed to request supplies: %d\n", ret
);
660 wm8770
->disable_nb
[0].notifier_call
= wm8770_regulator_event_0
;
661 wm8770
->disable_nb
[1].notifier_call
= wm8770_regulator_event_1
;
662 wm8770
->disable_nb
[2].notifier_call
= wm8770_regulator_event_2
;
664 /* This should really be moved into the regulator core */
665 for (i
= 0; i
< ARRAY_SIZE(wm8770
->supplies
); i
++) {
666 ret
= devm_regulator_register_notifier(
667 wm8770
->supplies
[i
].consumer
,
668 &wm8770
->disable_nb
[i
]);
671 "Failed to register regulator notifier: %d\n",
676 wm8770
->regmap
= devm_regmap_init_spi(spi
, &wm8770_regmap
);
677 if (IS_ERR(wm8770
->regmap
))
678 return PTR_ERR(wm8770
->regmap
);
680 spi_set_drvdata(spi
, wm8770
);
682 ret
= devm_snd_soc_register_component(&spi
->dev
,
683 &soc_component_dev_wm8770
, &wm8770_dai
, 1);
688 static struct spi_driver wm8770_spi_driver
= {
691 .of_match_table
= wm8770_of_match
,
693 .probe
= wm8770_spi_probe
,
696 module_spi_driver(wm8770_spi_driver
);
698 MODULE_DESCRIPTION("ASoC WM8770 driver");
699 MODULE_AUTHOR("Dimitris Papastamos <dp@opensource.wolfsonmicro.com>");
700 MODULE_LICENSE("GPL");