2 * wm8770.c -- WM8770 ALSA SoC Audio driver
4 * Copyright 2010 Wolfson Microelectronics plc
6 * Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/module.h>
14 #include <linux/moduleparam.h>
15 #include <linux/init.h>
16 #include <linux/delay.h>
17 #include <linux/of_device.h>
19 #include <linux/spi/spi.h>
20 #include <linux/regmap.h>
21 #include <linux/regulator/consumer.h>
22 #include <linux/slab.h>
23 #include <sound/core.h>
24 #include <sound/pcm.h>
25 #include <sound/pcm_params.h>
26 #include <sound/soc.h>
27 #include <sound/initval.h>
28 #include <sound/tlv.h>
32 #define WM8770_NUM_SUPPLIES 3
33 static const char *wm8770_supply_names
[WM8770_NUM_SUPPLIES
] = {
39 static const struct reg_default wm8770_reg_defaults
[] = {
73 static bool wm8770_volatile_reg(struct device
*dev
, unsigned int reg
)
84 struct regmap
*regmap
;
85 struct regulator_bulk_data supplies
[WM8770_NUM_SUPPLIES
];
86 struct notifier_block disable_nb
[WM8770_NUM_SUPPLIES
];
87 struct snd_soc_codec
*codec
;
91 static int vout12supply_event(struct snd_soc_dapm_widget
*w
,
92 struct snd_kcontrol
*kcontrol
, int event
);
93 static int vout34supply_event(struct snd_soc_dapm_widget
*w
,
94 struct snd_kcontrol
*kcontrol
, int event
);
97 * We can't use the same notifier block for more than one supply and
98 * there's no way I can see to get from a callback to the caller
99 * except container_of().
101 #define WM8770_REGULATOR_EVENT(n) \
102 static int wm8770_regulator_event_##n(struct notifier_block *nb, \
103 unsigned long event, void *data) \
105 struct wm8770_priv *wm8770 = container_of(nb, struct wm8770_priv, \
107 if (event & REGULATOR_EVENT_DISABLE) { \
108 regcache_mark_dirty(wm8770->regmap); \
113 WM8770_REGULATOR_EVENT(0)
114 WM8770_REGULATOR_EVENT(1)
115 WM8770_REGULATOR_EVENT(2)
117 static const DECLARE_TLV_DB_SCALE(adc_tlv
, -1200, 100, 0);
118 static const DECLARE_TLV_DB_SCALE(dac_dig_tlv
, -12750, 50, 1);
119 static const DECLARE_TLV_DB_SCALE(dac_alg_tlv
, -12700, 100, 1);
121 static const char *dac_phase_text
[][2] = {
122 { "DAC1 Normal", "DAC1 Inverted" },
123 { "DAC2 Normal", "DAC2 Inverted" },
124 { "DAC3 Normal", "DAC3 Inverted" },
125 { "DAC4 Normal", "DAC4 Inverted" },
128 static const struct soc_enum dac_phase
[] = {
129 SOC_ENUM_DOUBLE(WM8770_DACPHASE
, 0, 1, 2, dac_phase_text
[0]),
130 SOC_ENUM_DOUBLE(WM8770_DACPHASE
, 2, 3, 2, dac_phase_text
[1]),
131 SOC_ENUM_DOUBLE(WM8770_DACPHASE
, 4, 5, 2, dac_phase_text
[2]),
132 SOC_ENUM_DOUBLE(WM8770_DACPHASE
, 6, 7, 2, dac_phase_text
[3]),
135 static const struct snd_kcontrol_new wm8770_snd_controls
[] = {
136 /* global DAC playback controls */
137 SOC_SINGLE_TLV("DAC Playback Volume", WM8770_MSDIGVOL
, 0, 255, 0,
139 SOC_SINGLE("DAC Playback Switch", WM8770_DACMUTE
, 4, 1, 1),
140 SOC_SINGLE("DAC Playback ZC Switch", WM8770_DACCTRL1
, 0, 1, 0),
142 /* global VOUT playback controls */
143 SOC_SINGLE_TLV("VOUT Playback Volume", WM8770_MSALGVOL
, 0, 127, 0,
145 SOC_SINGLE("VOUT Playback ZC Switch", WM8770_MSALGVOL
, 7, 1, 0),
147 /* VOUT1/2/3/4 specific controls */
148 SOC_DOUBLE_R_TLV("VOUT1 Playback Volume", WM8770_VOUT1LVOL
,
149 WM8770_VOUT1RVOL
, 0, 127, 0, dac_alg_tlv
),
150 SOC_DOUBLE_R("VOUT1 Playback ZC Switch", WM8770_VOUT1LVOL
,
151 WM8770_VOUT1RVOL
, 7, 1, 0),
152 SOC_DOUBLE_R_TLV("VOUT2 Playback Volume", WM8770_VOUT2LVOL
,
153 WM8770_VOUT2RVOL
, 0, 127, 0, dac_alg_tlv
),
154 SOC_DOUBLE_R("VOUT2 Playback ZC Switch", WM8770_VOUT2LVOL
,
155 WM8770_VOUT2RVOL
, 7, 1, 0),
156 SOC_DOUBLE_R_TLV("VOUT3 Playback Volume", WM8770_VOUT3LVOL
,
157 WM8770_VOUT3RVOL
, 0, 127, 0, dac_alg_tlv
),
158 SOC_DOUBLE_R("VOUT3 Playback ZC Switch", WM8770_VOUT3LVOL
,
159 WM8770_VOUT3RVOL
, 7, 1, 0),
160 SOC_DOUBLE_R_TLV("VOUT4 Playback Volume", WM8770_VOUT4LVOL
,
161 WM8770_VOUT4RVOL
, 0, 127, 0, dac_alg_tlv
),
162 SOC_DOUBLE_R("VOUT4 Playback ZC Switch", WM8770_VOUT4LVOL
,
163 WM8770_VOUT4RVOL
, 7, 1, 0),
165 /* DAC1/2/3/4 specific controls */
166 SOC_DOUBLE_R_TLV("DAC1 Playback Volume", WM8770_DAC1LVOL
,
167 WM8770_DAC1RVOL
, 0, 255, 0, dac_dig_tlv
),
168 SOC_SINGLE("DAC1 Deemphasis Switch", WM8770_DACCTRL2
, 0, 1, 0),
169 SOC_ENUM("DAC1 Phase", dac_phase
[0]),
170 SOC_DOUBLE_R_TLV("DAC2 Playback Volume", WM8770_DAC2LVOL
,
171 WM8770_DAC2RVOL
, 0, 255, 0, dac_dig_tlv
),
172 SOC_SINGLE("DAC2 Deemphasis Switch", WM8770_DACCTRL2
, 1, 1, 0),
173 SOC_ENUM("DAC2 Phase", dac_phase
[1]),
174 SOC_DOUBLE_R_TLV("DAC3 Playback Volume", WM8770_DAC3LVOL
,
175 WM8770_DAC3RVOL
, 0, 255, 0, dac_dig_tlv
),
176 SOC_SINGLE("DAC3 Deemphasis Switch", WM8770_DACCTRL2
, 2, 1, 0),
177 SOC_ENUM("DAC3 Phase", dac_phase
[2]),
178 SOC_DOUBLE_R_TLV("DAC4 Playback Volume", WM8770_DAC4LVOL
,
179 WM8770_DAC4RVOL
, 0, 255, 0, dac_dig_tlv
),
180 SOC_SINGLE("DAC4 Deemphasis Switch", WM8770_DACCTRL2
, 3, 1, 0),
181 SOC_ENUM("DAC4 Phase", dac_phase
[3]),
183 /* ADC specific controls */
184 SOC_DOUBLE_R_TLV("Capture Volume", WM8770_ADCLCTRL
, WM8770_ADCRCTRL
,
186 SOC_DOUBLE_R("Capture Switch", WM8770_ADCLCTRL
, WM8770_ADCRCTRL
,
190 SOC_SINGLE("ADC 128x Oversampling Switch", WM8770_MSTRCTRL
, 3, 1, 0),
191 SOC_SINGLE("ADC Highpass Filter Switch", WM8770_IFACECTRL
, 8, 1, 1)
194 static const char *ain_text
[] = {
195 "AIN1", "AIN2", "AIN3", "AIN4",
196 "AIN5", "AIN6", "AIN7", "AIN8"
199 static SOC_ENUM_DOUBLE_DECL(ain_enum
,
200 WM8770_ADCMUX
, 0, 4, ain_text
);
202 static const struct snd_kcontrol_new ain_mux
=
203 SOC_DAPM_ENUM("Capture Mux", ain_enum
);
205 static const struct snd_kcontrol_new vout1_mix_controls
[] = {
206 SOC_DAPM_SINGLE("DAC1 Switch", WM8770_OUTMUX1
, 0, 1, 0),
207 SOC_DAPM_SINGLE("AUX1 Switch", WM8770_OUTMUX1
, 1, 1, 0),
208 SOC_DAPM_SINGLE("Bypass Switch", WM8770_OUTMUX1
, 2, 1, 0)
211 static const struct snd_kcontrol_new vout2_mix_controls
[] = {
212 SOC_DAPM_SINGLE("DAC2 Switch", WM8770_OUTMUX1
, 3, 1, 0),
213 SOC_DAPM_SINGLE("AUX2 Switch", WM8770_OUTMUX1
, 4, 1, 0),
214 SOC_DAPM_SINGLE("Bypass Switch", WM8770_OUTMUX1
, 5, 1, 0)
217 static const struct snd_kcontrol_new vout3_mix_controls
[] = {
218 SOC_DAPM_SINGLE("DAC3 Switch", WM8770_OUTMUX2
, 0, 1, 0),
219 SOC_DAPM_SINGLE("AUX3 Switch", WM8770_OUTMUX2
, 1, 1, 0),
220 SOC_DAPM_SINGLE("Bypass Switch", WM8770_OUTMUX2
, 2, 1, 0)
223 static const struct snd_kcontrol_new vout4_mix_controls
[] = {
224 SOC_DAPM_SINGLE("DAC4 Switch", WM8770_OUTMUX2
, 3, 1, 0),
225 SOC_DAPM_SINGLE("Bypass Switch", WM8770_OUTMUX2
, 4, 1, 0)
228 static const struct snd_soc_dapm_widget wm8770_dapm_widgets
[] = {
229 SND_SOC_DAPM_INPUT("AUX1"),
230 SND_SOC_DAPM_INPUT("AUX2"),
231 SND_SOC_DAPM_INPUT("AUX3"),
233 SND_SOC_DAPM_INPUT("AIN1"),
234 SND_SOC_DAPM_INPUT("AIN2"),
235 SND_SOC_DAPM_INPUT("AIN3"),
236 SND_SOC_DAPM_INPUT("AIN4"),
237 SND_SOC_DAPM_INPUT("AIN5"),
238 SND_SOC_DAPM_INPUT("AIN6"),
239 SND_SOC_DAPM_INPUT("AIN7"),
240 SND_SOC_DAPM_INPUT("AIN8"),
242 SND_SOC_DAPM_MUX("Capture Mux", WM8770_ADCMUX
, 8, 1, &ain_mux
),
244 SND_SOC_DAPM_ADC("ADC", "Capture", WM8770_PWDNCTRL
, 1, 1),
246 SND_SOC_DAPM_DAC("DAC1", "Playback", WM8770_PWDNCTRL
, 2, 1),
247 SND_SOC_DAPM_DAC("DAC2", "Playback", WM8770_PWDNCTRL
, 3, 1),
248 SND_SOC_DAPM_DAC("DAC3", "Playback", WM8770_PWDNCTRL
, 4, 1),
249 SND_SOC_DAPM_DAC("DAC4", "Playback", WM8770_PWDNCTRL
, 5, 1),
251 SND_SOC_DAPM_SUPPLY("VOUT12 Supply", SND_SOC_NOPM
, 0, 0,
252 vout12supply_event
, SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
253 SND_SOC_DAPM_SUPPLY("VOUT34 Supply", SND_SOC_NOPM
, 0, 0,
254 vout34supply_event
, SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
256 SND_SOC_DAPM_MIXER("VOUT1 Mixer", SND_SOC_NOPM
, 0, 0,
257 vout1_mix_controls
, ARRAY_SIZE(vout1_mix_controls
)),
258 SND_SOC_DAPM_MIXER("VOUT2 Mixer", SND_SOC_NOPM
, 0, 0,
259 vout2_mix_controls
, ARRAY_SIZE(vout2_mix_controls
)),
260 SND_SOC_DAPM_MIXER("VOUT3 Mixer", SND_SOC_NOPM
, 0, 0,
261 vout3_mix_controls
, ARRAY_SIZE(vout3_mix_controls
)),
262 SND_SOC_DAPM_MIXER("VOUT4 Mixer", SND_SOC_NOPM
, 0, 0,
263 vout4_mix_controls
, ARRAY_SIZE(vout4_mix_controls
)),
265 SND_SOC_DAPM_OUTPUT("VOUT1"),
266 SND_SOC_DAPM_OUTPUT("VOUT2"),
267 SND_SOC_DAPM_OUTPUT("VOUT3"),
268 SND_SOC_DAPM_OUTPUT("VOUT4")
271 static const struct snd_soc_dapm_route wm8770_intercon
[] = {
272 { "Capture Mux", "AIN1", "AIN1" },
273 { "Capture Mux", "AIN2", "AIN2" },
274 { "Capture Mux", "AIN3", "AIN3" },
275 { "Capture Mux", "AIN4", "AIN4" },
276 { "Capture Mux", "AIN5", "AIN5" },
277 { "Capture Mux", "AIN6", "AIN6" },
278 { "Capture Mux", "AIN7", "AIN7" },
279 { "Capture Mux", "AIN8", "AIN8" },
281 { "ADC", NULL
, "Capture Mux" },
283 { "VOUT1 Mixer", NULL
, "VOUT12 Supply" },
284 { "VOUT1 Mixer", "DAC1 Switch", "DAC1" },
285 { "VOUT1 Mixer", "AUX1 Switch", "AUX1" },
286 { "VOUT1 Mixer", "Bypass Switch", "Capture Mux" },
288 { "VOUT2 Mixer", NULL
, "VOUT12 Supply" },
289 { "VOUT2 Mixer", "DAC2 Switch", "DAC2" },
290 { "VOUT2 Mixer", "AUX2 Switch", "AUX2" },
291 { "VOUT2 Mixer", "Bypass Switch", "Capture Mux" },
293 { "VOUT3 Mixer", NULL
, "VOUT34 Supply" },
294 { "VOUT3 Mixer", "DAC3 Switch", "DAC3" },
295 { "VOUT3 Mixer", "AUX3 Switch", "AUX3" },
296 { "VOUT3 Mixer", "Bypass Switch", "Capture Mux" },
298 { "VOUT4 Mixer", NULL
, "VOUT34 Supply" },
299 { "VOUT4 Mixer", "DAC4 Switch", "DAC4" },
300 { "VOUT4 Mixer", "Bypass Switch", "Capture Mux" },
302 { "VOUT1", NULL
, "VOUT1 Mixer" },
303 { "VOUT2", NULL
, "VOUT2 Mixer" },
304 { "VOUT3", NULL
, "VOUT3 Mixer" },
305 { "VOUT4", NULL
, "VOUT4 Mixer" }
308 static int vout12supply_event(struct snd_soc_dapm_widget
*w
,
309 struct snd_kcontrol
*kcontrol
, int event
)
311 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
314 case SND_SOC_DAPM_PRE_PMU
:
315 snd_soc_update_bits(codec
, WM8770_OUTMUX1
, 0x180, 0);
317 case SND_SOC_DAPM_POST_PMD
:
318 snd_soc_update_bits(codec
, WM8770_OUTMUX1
, 0x180, 0x180);
325 static int vout34supply_event(struct snd_soc_dapm_widget
*w
,
326 struct snd_kcontrol
*kcontrol
, int event
)
328 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
331 case SND_SOC_DAPM_PRE_PMU
:
332 snd_soc_update_bits(codec
, WM8770_OUTMUX2
, 0x180, 0);
334 case SND_SOC_DAPM_POST_PMD
:
335 snd_soc_update_bits(codec
, WM8770_OUTMUX2
, 0x180, 0x180);
342 static int wm8770_reset(struct snd_soc_codec
*codec
)
344 return snd_soc_write(codec
, WM8770_RESET
, 0);
347 static int wm8770_set_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
349 struct snd_soc_codec
*codec
;
354 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
355 case SND_SOC_DAIFMT_CBM_CFM
:
358 case SND_SOC_DAIFMT_CBS_CFS
:
366 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
367 case SND_SOC_DAIFMT_I2S
:
370 case SND_SOC_DAIFMT_RIGHT_J
:
372 case SND_SOC_DAIFMT_LEFT_J
:
379 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
380 case SND_SOC_DAIFMT_NB_NF
:
382 case SND_SOC_DAIFMT_IB_IF
:
385 case SND_SOC_DAIFMT_IB_NF
:
388 case SND_SOC_DAIFMT_NB_IF
:
395 snd_soc_update_bits(codec
, WM8770_IFACECTRL
, 0xf, iface
);
396 snd_soc_update_bits(codec
, WM8770_MSTRCTRL
, 0x100, master
);
401 static const int mclk_ratios
[] = {
410 static int wm8770_hw_params(struct snd_pcm_substream
*substream
,
411 struct snd_pcm_hw_params
*params
,
412 struct snd_soc_dai
*dai
)
414 struct snd_soc_codec
*codec
;
415 struct wm8770_priv
*wm8770
;
422 wm8770
= snd_soc_codec_get_drvdata(codec
);
425 switch (params_width(params
)) {
439 switch (substream
->stream
) {
440 case SNDRV_PCM_STREAM_PLAYBACK
:
444 case SNDRV_PCM_STREAM_CAPTURE
:
452 /* Only need to set MCLK/LRCLK ratio if we're master */
453 if (snd_soc_read(codec
, WM8770_MSTRCTRL
) & 0x100) {
454 for (; i
< ARRAY_SIZE(mclk_ratios
); ++i
) {
455 ratio
= wm8770
->sysclk
/ params_rate(params
);
456 if (ratio
== mclk_ratios
[i
])
460 if (i
== ARRAY_SIZE(mclk_ratios
)) {
462 "Unable to configure MCLK ratio %d/%d\n",
463 wm8770
->sysclk
, params_rate(params
));
467 dev_dbg(codec
->dev
, "MCLK is %dfs\n", mclk_ratios
[i
]);
469 snd_soc_update_bits(codec
, WM8770_MSTRCTRL
, 0x7 << shift
,
473 snd_soc_update_bits(codec
, WM8770_IFACECTRL
, 0x30, iface
);
478 static int wm8770_mute(struct snd_soc_dai
*dai
, int mute
)
480 struct snd_soc_codec
*codec
;
483 return snd_soc_update_bits(codec
, WM8770_DACMUTE
, 0x10,
487 static int wm8770_set_sysclk(struct snd_soc_dai
*dai
,
488 int clk_id
, unsigned int freq
, int dir
)
490 struct snd_soc_codec
*codec
;
491 struct wm8770_priv
*wm8770
;
494 wm8770
= snd_soc_codec_get_drvdata(codec
);
495 wm8770
->sysclk
= freq
;
499 static int wm8770_set_bias_level(struct snd_soc_codec
*codec
,
500 enum snd_soc_bias_level level
)
503 struct wm8770_priv
*wm8770
;
505 wm8770
= snd_soc_codec_get_drvdata(codec
);
508 case SND_SOC_BIAS_ON
:
510 case SND_SOC_BIAS_PREPARE
:
512 case SND_SOC_BIAS_STANDBY
:
513 if (snd_soc_codec_get_bias_level(codec
) == SND_SOC_BIAS_OFF
) {
514 ret
= regulator_bulk_enable(ARRAY_SIZE(wm8770
->supplies
),
518 "Failed to enable supplies: %d\n",
523 regcache_sync(wm8770
->regmap
);
526 snd_soc_write(codec
, WM8770_PWDNCTRL
, 0);
529 case SND_SOC_BIAS_OFF
:
530 /* global powerdown */
531 snd_soc_write(codec
, WM8770_PWDNCTRL
, 1);
532 regulator_bulk_disable(ARRAY_SIZE(wm8770
->supplies
),
540 #define WM8770_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
541 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
543 static const struct snd_soc_dai_ops wm8770_dai_ops
= {
544 .digital_mute
= wm8770_mute
,
545 .hw_params
= wm8770_hw_params
,
546 .set_fmt
= wm8770_set_fmt
,
547 .set_sysclk
= wm8770_set_sysclk
,
550 static struct snd_soc_dai_driver wm8770_dai
= {
551 .name
= "wm8770-hifi",
553 .stream_name
= "Playback",
556 .rates
= SNDRV_PCM_RATE_8000_192000
,
557 .formats
= WM8770_FORMATS
560 .stream_name
= "Capture",
563 .rates
= SNDRV_PCM_RATE_8000_96000
,
564 .formats
= WM8770_FORMATS
566 .ops
= &wm8770_dai_ops
,
570 static int wm8770_probe(struct snd_soc_codec
*codec
)
572 struct wm8770_priv
*wm8770
;
575 wm8770
= snd_soc_codec_get_drvdata(codec
);
576 wm8770
->codec
= codec
;
578 ret
= regulator_bulk_enable(ARRAY_SIZE(wm8770
->supplies
),
581 dev_err(codec
->dev
, "Failed to enable supplies: %d\n", ret
);
585 ret
= wm8770_reset(codec
);
587 dev_err(codec
->dev
, "Failed to issue reset: %d\n", ret
);
591 /* latch the volume update bits */
592 snd_soc_update_bits(codec
, WM8770_MSDIGVOL
, 0x100, 0x100);
593 snd_soc_update_bits(codec
, WM8770_MSALGVOL
, 0x100, 0x100);
594 snd_soc_update_bits(codec
, WM8770_VOUT1RVOL
, 0x100, 0x100);
595 snd_soc_update_bits(codec
, WM8770_VOUT2RVOL
, 0x100, 0x100);
596 snd_soc_update_bits(codec
, WM8770_VOUT3RVOL
, 0x100, 0x100);
597 snd_soc_update_bits(codec
, WM8770_VOUT4RVOL
, 0x100, 0x100);
598 snd_soc_update_bits(codec
, WM8770_DAC1RVOL
, 0x100, 0x100);
599 snd_soc_update_bits(codec
, WM8770_DAC2RVOL
, 0x100, 0x100);
600 snd_soc_update_bits(codec
, WM8770_DAC3RVOL
, 0x100, 0x100);
601 snd_soc_update_bits(codec
, WM8770_DAC4RVOL
, 0x100, 0x100);
604 snd_soc_update_bits(codec
, WM8770_DACMUTE
, 0x10, 0x10);
607 regulator_bulk_disable(ARRAY_SIZE(wm8770
->supplies
), wm8770
->supplies
);
611 static const struct snd_soc_codec_driver soc_codec_dev_wm8770
= {
612 .probe
= wm8770_probe
,
613 .set_bias_level
= wm8770_set_bias_level
,
614 .idle_bias_off
= true,
616 .component_driver
= {
617 .controls
= wm8770_snd_controls
,
618 .num_controls
= ARRAY_SIZE(wm8770_snd_controls
),
619 .dapm_widgets
= wm8770_dapm_widgets
,
620 .num_dapm_widgets
= ARRAY_SIZE(wm8770_dapm_widgets
),
621 .dapm_routes
= wm8770_intercon
,
622 .num_dapm_routes
= ARRAY_SIZE(wm8770_intercon
),
626 static const struct of_device_id wm8770_of_match
[] = {
627 { .compatible
= "wlf,wm8770", },
630 MODULE_DEVICE_TABLE(of
, wm8770_of_match
);
632 static const struct regmap_config wm8770_regmap
= {
635 .max_register
= WM8770_RESET
,
637 .reg_defaults
= wm8770_reg_defaults
,
638 .num_reg_defaults
= ARRAY_SIZE(wm8770_reg_defaults
),
639 .cache_type
= REGCACHE_RBTREE
,
641 .volatile_reg
= wm8770_volatile_reg
,
644 static int wm8770_spi_probe(struct spi_device
*spi
)
646 struct wm8770_priv
*wm8770
;
649 wm8770
= devm_kzalloc(&spi
->dev
, sizeof(struct wm8770_priv
),
654 for (i
= 0; i
< ARRAY_SIZE(wm8770
->supplies
); i
++)
655 wm8770
->supplies
[i
].supply
= wm8770_supply_names
[i
];
657 ret
= devm_regulator_bulk_get(&spi
->dev
, ARRAY_SIZE(wm8770
->supplies
),
660 dev_err(&spi
->dev
, "Failed to request supplies: %d\n", ret
);
664 wm8770
->disable_nb
[0].notifier_call
= wm8770_regulator_event_0
;
665 wm8770
->disable_nb
[1].notifier_call
= wm8770_regulator_event_1
;
666 wm8770
->disable_nb
[2].notifier_call
= wm8770_regulator_event_2
;
668 /* This should really be moved into the regulator core */
669 for (i
= 0; i
< ARRAY_SIZE(wm8770
->supplies
); i
++) {
670 ret
= regulator_register_notifier(wm8770
->supplies
[i
].consumer
,
671 &wm8770
->disable_nb
[i
]);
674 "Failed to register regulator notifier: %d\n",
679 wm8770
->regmap
= devm_regmap_init_spi(spi
, &wm8770_regmap
);
680 if (IS_ERR(wm8770
->regmap
))
681 return PTR_ERR(wm8770
->regmap
);
683 spi_set_drvdata(spi
, wm8770
);
685 ret
= snd_soc_register_codec(&spi
->dev
,
686 &soc_codec_dev_wm8770
, &wm8770_dai
, 1);
691 static int wm8770_spi_remove(struct spi_device
*spi
)
693 struct wm8770_priv
*wm8770
= spi_get_drvdata(spi
);
696 for (i
= 0; i
< ARRAY_SIZE(wm8770
->supplies
); ++i
)
697 regulator_unregister_notifier(wm8770
->supplies
[i
].consumer
,
698 &wm8770
->disable_nb
[i
]);
700 snd_soc_unregister_codec(&spi
->dev
);
705 static struct spi_driver wm8770_spi_driver
= {
708 .of_match_table
= wm8770_of_match
,
710 .probe
= wm8770_spi_probe
,
711 .remove
= wm8770_spi_remove
714 module_spi_driver(wm8770_spi_driver
);
716 MODULE_DESCRIPTION("ASoC WM8770 driver");
717 MODULE_AUTHOR("Dimitris Papastamos <dp@opensource.wolfsonmicro.com>");
718 MODULE_LICENSE("GPL");