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 const struct soc_enum ain_enum
=
200 SOC_ENUM_DOUBLE(WM8770_ADCMUX
, 0, 4, 8, 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
;
316 case SND_SOC_DAPM_PRE_PMU
:
317 snd_soc_update_bits(codec
, WM8770_OUTMUX1
, 0x180, 0);
319 case SND_SOC_DAPM_POST_PMD
:
320 snd_soc_update_bits(codec
, WM8770_OUTMUX1
, 0x180, 0x180);
327 static int vout34supply_event(struct snd_soc_dapm_widget
*w
,
328 struct snd_kcontrol
*kcontrol
, int event
)
330 struct snd_soc_codec
*codec
;
335 case SND_SOC_DAPM_PRE_PMU
:
336 snd_soc_update_bits(codec
, WM8770_OUTMUX2
, 0x180, 0);
338 case SND_SOC_DAPM_POST_PMD
:
339 snd_soc_update_bits(codec
, WM8770_OUTMUX2
, 0x180, 0x180);
346 static int wm8770_reset(struct snd_soc_codec
*codec
)
348 return snd_soc_write(codec
, WM8770_RESET
, 0);
351 static int wm8770_set_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
353 struct snd_soc_codec
*codec
;
358 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
359 case SND_SOC_DAIFMT_CBM_CFM
:
362 case SND_SOC_DAIFMT_CBS_CFS
:
370 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
371 case SND_SOC_DAIFMT_I2S
:
374 case SND_SOC_DAIFMT_RIGHT_J
:
376 case SND_SOC_DAIFMT_LEFT_J
:
383 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
384 case SND_SOC_DAIFMT_NB_NF
:
386 case SND_SOC_DAIFMT_IB_IF
:
389 case SND_SOC_DAIFMT_IB_NF
:
392 case SND_SOC_DAIFMT_NB_IF
:
399 snd_soc_update_bits(codec
, WM8770_IFACECTRL
, 0xf, iface
);
400 snd_soc_update_bits(codec
, WM8770_MSTRCTRL
, 0x100, master
);
405 static const int mclk_ratios
[] = {
414 static int wm8770_hw_params(struct snd_pcm_substream
*substream
,
415 struct snd_pcm_hw_params
*params
,
416 struct snd_soc_dai
*dai
)
418 struct snd_soc_codec
*codec
;
419 struct wm8770_priv
*wm8770
;
426 wm8770
= snd_soc_codec_get_drvdata(codec
);
429 switch (params_format(params
)) {
430 case SNDRV_PCM_FORMAT_S16_LE
:
432 case SNDRV_PCM_FORMAT_S20_3LE
:
435 case SNDRV_PCM_FORMAT_S24_LE
:
438 case SNDRV_PCM_FORMAT_S32_LE
:
443 switch (substream
->stream
) {
444 case SNDRV_PCM_STREAM_PLAYBACK
:
448 case SNDRV_PCM_STREAM_CAPTURE
:
456 /* Only need to set MCLK/LRCLK ratio if we're master */
457 if (snd_soc_read(codec
, WM8770_MSTRCTRL
) & 0x100) {
458 for (; i
< ARRAY_SIZE(mclk_ratios
); ++i
) {
459 ratio
= wm8770
->sysclk
/ params_rate(params
);
460 if (ratio
== mclk_ratios
[i
])
464 if (i
== ARRAY_SIZE(mclk_ratios
)) {
466 "Unable to configure MCLK ratio %d/%d\n",
467 wm8770
->sysclk
, params_rate(params
));
471 dev_dbg(codec
->dev
, "MCLK is %dfs\n", mclk_ratios
[i
]);
473 snd_soc_update_bits(codec
, WM8770_MSTRCTRL
, 0x7 << shift
,
477 snd_soc_update_bits(codec
, WM8770_IFACECTRL
, 0x30, iface
);
482 static int wm8770_mute(struct snd_soc_dai
*dai
, int mute
)
484 struct snd_soc_codec
*codec
;
487 return snd_soc_update_bits(codec
, WM8770_DACMUTE
, 0x10,
491 static int wm8770_set_sysclk(struct snd_soc_dai
*dai
,
492 int clk_id
, unsigned int freq
, int dir
)
494 struct snd_soc_codec
*codec
;
495 struct wm8770_priv
*wm8770
;
498 wm8770
= snd_soc_codec_get_drvdata(codec
);
499 wm8770
->sysclk
= freq
;
503 static int wm8770_set_bias_level(struct snd_soc_codec
*codec
,
504 enum snd_soc_bias_level level
)
507 struct wm8770_priv
*wm8770
;
509 wm8770
= snd_soc_codec_get_drvdata(codec
);
512 case SND_SOC_BIAS_ON
:
514 case SND_SOC_BIAS_PREPARE
:
516 case SND_SOC_BIAS_STANDBY
:
517 if (codec
->dapm
.bias_level
== SND_SOC_BIAS_OFF
) {
518 ret
= regulator_bulk_enable(ARRAY_SIZE(wm8770
->supplies
),
522 "Failed to enable supplies: %d\n",
527 regcache_sync(wm8770
->regmap
);
530 snd_soc_write(codec
, WM8770_PWDNCTRL
, 0);
533 case SND_SOC_BIAS_OFF
:
534 /* global powerdown */
535 snd_soc_write(codec
, WM8770_PWDNCTRL
, 1);
536 regulator_bulk_disable(ARRAY_SIZE(wm8770
->supplies
),
541 codec
->dapm
.bias_level
= level
;
545 #define WM8770_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
546 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
548 static const struct snd_soc_dai_ops wm8770_dai_ops
= {
549 .digital_mute
= wm8770_mute
,
550 .hw_params
= wm8770_hw_params
,
551 .set_fmt
= wm8770_set_fmt
,
552 .set_sysclk
= wm8770_set_sysclk
,
555 static struct snd_soc_dai_driver wm8770_dai
= {
556 .name
= "wm8770-hifi",
558 .stream_name
= "Playback",
561 .rates
= SNDRV_PCM_RATE_8000_192000
,
562 .formats
= WM8770_FORMATS
565 .stream_name
= "Capture",
568 .rates
= SNDRV_PCM_RATE_8000_96000
,
569 .formats
= WM8770_FORMATS
571 .ops
= &wm8770_dai_ops
,
575 static int wm8770_probe(struct snd_soc_codec
*codec
)
577 struct wm8770_priv
*wm8770
;
580 wm8770
= snd_soc_codec_get_drvdata(codec
);
581 wm8770
->codec
= codec
;
583 ret
= snd_soc_codec_set_cache_io(codec
, 7, 9, SND_SOC_REGMAP
);
585 dev_err(codec
->dev
, "Failed to set cache I/O: %d\n", ret
);
589 ret
= regulator_bulk_enable(ARRAY_SIZE(wm8770
->supplies
),
592 dev_err(codec
->dev
, "Failed to enable supplies: %d\n", ret
);
596 ret
= wm8770_reset(codec
);
598 dev_err(codec
->dev
, "Failed to issue reset: %d\n", ret
);
602 /* latch the volume update bits */
603 snd_soc_update_bits(codec
, WM8770_MSDIGVOL
, 0x100, 0x100);
604 snd_soc_update_bits(codec
, WM8770_MSALGVOL
, 0x100, 0x100);
605 snd_soc_update_bits(codec
, WM8770_VOUT1RVOL
, 0x100, 0x100);
606 snd_soc_update_bits(codec
, WM8770_VOUT2RVOL
, 0x100, 0x100);
607 snd_soc_update_bits(codec
, WM8770_VOUT3RVOL
, 0x100, 0x100);
608 snd_soc_update_bits(codec
, WM8770_VOUT4RVOL
, 0x100, 0x100);
609 snd_soc_update_bits(codec
, WM8770_DAC1RVOL
, 0x100, 0x100);
610 snd_soc_update_bits(codec
, WM8770_DAC2RVOL
, 0x100, 0x100);
611 snd_soc_update_bits(codec
, WM8770_DAC3RVOL
, 0x100, 0x100);
612 snd_soc_update_bits(codec
, WM8770_DAC4RVOL
, 0x100, 0x100);
615 snd_soc_update_bits(codec
, WM8770_DACMUTE
, 0x10, 0x10);
618 regulator_bulk_disable(ARRAY_SIZE(wm8770
->supplies
), wm8770
->supplies
);
622 static struct snd_soc_codec_driver soc_codec_dev_wm8770
= {
623 .probe
= wm8770_probe
,
624 .set_bias_level
= wm8770_set_bias_level
,
625 .idle_bias_off
= true,
627 .controls
= wm8770_snd_controls
,
628 .num_controls
= ARRAY_SIZE(wm8770_snd_controls
),
629 .dapm_widgets
= wm8770_dapm_widgets
,
630 .num_dapm_widgets
= ARRAY_SIZE(wm8770_dapm_widgets
),
631 .dapm_routes
= wm8770_intercon
,
632 .num_dapm_routes
= ARRAY_SIZE(wm8770_intercon
),
635 static const struct of_device_id wm8770_of_match
[] = {
636 { .compatible
= "wlf,wm8770", },
639 MODULE_DEVICE_TABLE(of
, wm8770_of_match
);
641 static const struct regmap_config wm8770_regmap
= {
644 .max_register
= WM8770_RESET
,
646 .reg_defaults
= wm8770_reg_defaults
,
647 .num_reg_defaults
= ARRAY_SIZE(wm8770_reg_defaults
),
648 .cache_type
= REGCACHE_RBTREE
,
650 .volatile_reg
= wm8770_volatile_reg
,
653 static int wm8770_spi_probe(struct spi_device
*spi
)
655 struct wm8770_priv
*wm8770
;
658 wm8770
= devm_kzalloc(&spi
->dev
, sizeof(struct wm8770_priv
),
663 for (i
= 0; i
< ARRAY_SIZE(wm8770
->supplies
); i
++)
664 wm8770
->supplies
[i
].supply
= wm8770_supply_names
[i
];
666 ret
= devm_regulator_bulk_get(&spi
->dev
, ARRAY_SIZE(wm8770
->supplies
),
669 dev_err(&spi
->dev
, "Failed to request supplies: %d\n", ret
);
673 wm8770
->disable_nb
[0].notifier_call
= wm8770_regulator_event_0
;
674 wm8770
->disable_nb
[1].notifier_call
= wm8770_regulator_event_1
;
675 wm8770
->disable_nb
[2].notifier_call
= wm8770_regulator_event_2
;
677 /* This should really be moved into the regulator core */
678 for (i
= 0; i
< ARRAY_SIZE(wm8770
->supplies
); i
++) {
679 ret
= regulator_register_notifier(wm8770
->supplies
[i
].consumer
,
680 &wm8770
->disable_nb
[i
]);
683 "Failed to register regulator notifier: %d\n",
688 wm8770
->regmap
= devm_regmap_init_spi(spi
, &wm8770_regmap
);
689 if (IS_ERR(wm8770
->regmap
))
690 return PTR_ERR(wm8770
->regmap
);
692 spi_set_drvdata(spi
, wm8770
);
694 ret
= snd_soc_register_codec(&spi
->dev
,
695 &soc_codec_dev_wm8770
, &wm8770_dai
, 1);
700 static int wm8770_spi_remove(struct spi_device
*spi
)
702 struct wm8770_priv
*wm8770
= spi_get_drvdata(spi
);
705 for (i
= 0; i
< ARRAY_SIZE(wm8770
->supplies
); ++i
)
706 regulator_unregister_notifier(wm8770
->supplies
[i
].consumer
,
707 &wm8770
->disable_nb
[i
]);
709 snd_soc_unregister_codec(&spi
->dev
);
714 static struct spi_driver wm8770_spi_driver
= {
717 .owner
= THIS_MODULE
,
718 .of_match_table
= wm8770_of_match
,
720 .probe
= wm8770_spi_probe
,
721 .remove
= wm8770_spi_remove
724 module_spi_driver(wm8770_spi_driver
);
726 MODULE_DESCRIPTION("ASoC WM8770 driver");
727 MODULE_AUTHOR("Dimitris Papastamos <dp@opensource.wolfsonmicro.com>");
728 MODULE_LICENSE("GPL");