2 * wm8737.c -- WM8737 ALSA SoC Audio driver
4 * Copyright 2010 Wolfson Microelectronics plc
6 * Author: Mark Brown <broonie@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>
18 #include <linux/i2c.h>
19 #include <linux/regmap.h>
20 #include <linux/regulator/consumer.h>
21 #include <linux/spi/spi.h>
22 #include <linux/slab.h>
23 #include <linux/of_device.h>
24 #include <sound/core.h>
25 #include <sound/pcm.h>
26 #include <sound/pcm_params.h>
27 #include <sound/soc.h>
28 #include <sound/soc-dapm.h>
29 #include <sound/initval.h>
30 #include <sound/tlv.h>
34 #define WM8737_NUM_SUPPLIES 4
35 static const char *wm8737_supply_names
[WM8737_NUM_SUPPLIES
] = {
42 /* codec private data */
44 struct regmap
*regmap
;
45 struct regulator_bulk_data supplies
[WM8737_NUM_SUPPLIES
];
49 static const struct reg_default wm8737_reg_defaults
[] = {
50 { 0, 0x00C3 }, /* R0 - Left PGA volume */
51 { 1, 0x00C3 }, /* R1 - Right PGA volume */
52 { 2, 0x0007 }, /* R2 - AUDIO path L */
53 { 3, 0x0007 }, /* R3 - AUDIO path R */
54 { 4, 0x0000 }, /* R4 - 3D Enhance */
55 { 5, 0x0000 }, /* R5 - ADC Control */
56 { 6, 0x0000 }, /* R6 - Power Management */
57 { 7, 0x000A }, /* R7 - Audio Format */
58 { 8, 0x0000 }, /* R8 - Clocking */
59 { 9, 0x000F }, /* R9 - MIC Preamp Control */
60 { 10, 0x0003 }, /* R10 - Misc Bias Control */
61 { 11, 0x0000 }, /* R11 - Noise Gate */
62 { 12, 0x007C }, /* R12 - ALC1 */
63 { 13, 0x0000 }, /* R13 - ALC2 */
64 { 14, 0x0032 }, /* R14 - ALC3 */
67 static bool wm8737_volatile(struct device
*dev
, unsigned int reg
)
77 static int wm8737_reset(struct snd_soc_codec
*codec
)
79 return snd_soc_write(codec
, WM8737_RESET
, 0);
82 static const unsigned int micboost_tlv
[] = {
84 0, 0, TLV_DB_SCALE_ITEM(1300, 0, 0),
85 1, 1, TLV_DB_SCALE_ITEM(1800, 0, 0),
86 2, 2, TLV_DB_SCALE_ITEM(2800, 0, 0),
87 3, 3, TLV_DB_SCALE_ITEM(3300, 0, 0),
89 static const DECLARE_TLV_DB_SCALE(pga_tlv
, -9750, 50, 1);
90 static const DECLARE_TLV_DB_SCALE(adc_tlv
, -600, 600, 0);
91 static const DECLARE_TLV_DB_SCALE(ng_tlv
, -7800, 600, 0);
92 static const DECLARE_TLV_DB_SCALE(alc_max_tlv
, -1200, 600, 0);
93 static const DECLARE_TLV_DB_SCALE(alc_target_tlv
, -1800, 100, 0);
95 static const char *micbias_enum_text
[] = {
102 static const struct soc_enum micbias_enum
=
103 SOC_ENUM_SINGLE(WM8737_MIC_PREAMP_CONTROL
, 0, 4, micbias_enum_text
);
105 static const char *low_cutoff_text
[] = {
109 static const struct soc_enum low_3d
=
110 SOC_ENUM_SINGLE(WM8737_3D_ENHANCE
, 6, 2, low_cutoff_text
);
112 static const char *high_cutoff_text
[] = {
116 static const struct soc_enum high_3d
=
117 SOC_ENUM_SINGLE(WM8737_3D_ENHANCE
, 5, 2, high_cutoff_text
);
119 static const char *alc_fn_text
[] = {
120 "Disabled", "Right", "Left", "Stereo"
123 static const struct soc_enum alc_fn
=
124 SOC_ENUM_SINGLE(WM8737_ALC1
, 7, 4, alc_fn_text
);
126 static const char *alc_hold_text
[] = {
127 "0", "2.67ms", "5.33ms", "10.66ms", "21.32ms", "42.64ms", "85.28ms",
128 "170.56ms", "341.12ms", "682.24ms", "1.364s", "2.728s", "5.458s",
129 "10.916s", "21.832s", "43.691s"
132 static const struct soc_enum alc_hold
=
133 SOC_ENUM_SINGLE(WM8737_ALC2
, 0, 16, alc_hold_text
);
135 static const char *alc_atk_text
[] = {
136 "8.4ms", "16.8ms", "33.6ms", "67.2ms", "134.4ms", "268.8ms", "537.6ms",
137 "1.075s", "2.15s", "4.3s", "8.6s"
140 static const struct soc_enum alc_atk
=
141 SOC_ENUM_SINGLE(WM8737_ALC3
, 0, 11, alc_atk_text
);
143 static const char *alc_dcy_text
[] = {
144 "33.6ms", "67.2ms", "134.4ms", "268.8ms", "537.6ms", "1.075s", "2.15s",
145 "4.3s", "8.6s", "17.2s", "34.41s"
148 static const struct soc_enum alc_dcy
=
149 SOC_ENUM_SINGLE(WM8737_ALC3
, 4, 11, alc_dcy_text
);
151 static const struct snd_kcontrol_new wm8737_snd_controls
[] = {
152 SOC_DOUBLE_R_TLV("Mic Boost Volume", WM8737_AUDIO_PATH_L
, WM8737_AUDIO_PATH_R
,
153 6, 3, 0, micboost_tlv
),
154 SOC_DOUBLE_R("Mic Boost Switch", WM8737_AUDIO_PATH_L
, WM8737_AUDIO_PATH_R
,
156 SOC_DOUBLE("Mic ZC Switch", WM8737_AUDIO_PATH_L
, WM8737_AUDIO_PATH_R
,
159 SOC_DOUBLE_R_TLV("Capture Volume", WM8737_LEFT_PGA_VOLUME
,
160 WM8737_RIGHT_PGA_VOLUME
, 0, 255, 0, pga_tlv
),
161 SOC_DOUBLE("Capture ZC Switch", WM8737_AUDIO_PATH_L
, WM8737_AUDIO_PATH_R
,
164 SOC_DOUBLE("INPUT1 DC Bias Switch", WM8737_MISC_BIAS_CONTROL
, 0, 1, 1, 0),
166 SOC_ENUM("Mic PGA Bias", micbias_enum
),
167 SOC_SINGLE("ADC Low Power Switch", WM8737_ADC_CONTROL
, 2, 1, 0),
168 SOC_SINGLE("High Pass Filter Switch", WM8737_ADC_CONTROL
, 0, 1, 1),
169 SOC_DOUBLE("Polarity Invert Switch", WM8737_ADC_CONTROL
, 5, 6, 1, 0),
171 SOC_SINGLE("3D Switch", WM8737_3D_ENHANCE
, 0, 1, 0),
172 SOC_SINGLE("3D Depth", WM8737_3D_ENHANCE
, 1, 15, 0),
173 SOC_ENUM("3D Low Cut-off", low_3d
),
174 SOC_ENUM("3D High Cut-off", low_3d
),
175 SOC_SINGLE_TLV("3D ADC Volume", WM8737_3D_ENHANCE
, 7, 1, 1, adc_tlv
),
177 SOC_SINGLE("Noise Gate Switch", WM8737_NOISE_GATE
, 0, 1, 0),
178 SOC_SINGLE_TLV("Noise Gate Threshold Volume", WM8737_NOISE_GATE
, 2, 7, 0,
181 SOC_ENUM("ALC", alc_fn
),
182 SOC_SINGLE_TLV("ALC Max Gain Volume", WM8737_ALC1
, 4, 7, 0, alc_max_tlv
),
183 SOC_SINGLE_TLV("ALC Target Volume", WM8737_ALC1
, 0, 15, 0, alc_target_tlv
),
184 SOC_ENUM("ALC Hold Time", alc_hold
),
185 SOC_SINGLE("ALC ZC Switch", WM8737_ALC2
, 4, 1, 0),
186 SOC_ENUM("ALC Attack Time", alc_atk
),
187 SOC_ENUM("ALC Decay Time", alc_dcy
),
190 static const char *linsel_text
[] = {
191 "LINPUT1", "LINPUT2", "LINPUT3", "LINPUT1 DC",
194 static const struct soc_enum linsel_enum
=
195 SOC_ENUM_SINGLE(WM8737_AUDIO_PATH_L
, 7, 4, linsel_text
);
197 static const struct snd_kcontrol_new linsel_mux
=
198 SOC_DAPM_ENUM("LINSEL", linsel_enum
);
201 static const char *rinsel_text
[] = {
202 "RINPUT1", "RINPUT2", "RINPUT3", "RINPUT1 DC",
205 static const struct soc_enum rinsel_enum
=
206 SOC_ENUM_SINGLE(WM8737_AUDIO_PATH_R
, 7, 4, rinsel_text
);
208 static const struct snd_kcontrol_new rinsel_mux
=
209 SOC_DAPM_ENUM("RINSEL", rinsel_enum
);
211 static const char *bypass_text
[] = {
215 static const struct soc_enum lbypass_enum
=
216 SOC_ENUM_SINGLE(WM8737_MIC_PREAMP_CONTROL
, 2, 2, bypass_text
);
218 static const struct snd_kcontrol_new lbypass_mux
=
219 SOC_DAPM_ENUM("Left Bypass", lbypass_enum
);
222 static const struct soc_enum rbypass_enum
=
223 SOC_ENUM_SINGLE(WM8737_MIC_PREAMP_CONTROL
, 3, 2, bypass_text
);
225 static const struct snd_kcontrol_new rbypass_mux
=
226 SOC_DAPM_ENUM("Left Bypass", rbypass_enum
);
228 static const struct snd_soc_dapm_widget wm8737_dapm_widgets
[] = {
229 SND_SOC_DAPM_INPUT("LINPUT1"),
230 SND_SOC_DAPM_INPUT("LINPUT2"),
231 SND_SOC_DAPM_INPUT("LINPUT3"),
232 SND_SOC_DAPM_INPUT("RINPUT1"),
233 SND_SOC_DAPM_INPUT("RINPUT2"),
234 SND_SOC_DAPM_INPUT("RINPUT3"),
235 SND_SOC_DAPM_INPUT("LACIN"),
236 SND_SOC_DAPM_INPUT("RACIN"),
238 SND_SOC_DAPM_MUX("LINSEL", SND_SOC_NOPM
, 0, 0, &linsel_mux
),
239 SND_SOC_DAPM_MUX("RINSEL", SND_SOC_NOPM
, 0, 0, &rinsel_mux
),
241 SND_SOC_DAPM_MUX("Left Preamp Mux", SND_SOC_NOPM
, 0, 0, &lbypass_mux
),
242 SND_SOC_DAPM_MUX("Right Preamp Mux", SND_SOC_NOPM
, 0, 0, &rbypass_mux
),
244 SND_SOC_DAPM_PGA("PGAL", WM8737_POWER_MANAGEMENT
, 5, 0, NULL
, 0),
245 SND_SOC_DAPM_PGA("PGAR", WM8737_POWER_MANAGEMENT
, 4, 0, NULL
, 0),
247 SND_SOC_DAPM_DAC("ADCL", NULL
, WM8737_POWER_MANAGEMENT
, 3, 0),
248 SND_SOC_DAPM_DAC("ADCR", NULL
, WM8737_POWER_MANAGEMENT
, 2, 0),
250 SND_SOC_DAPM_AIF_OUT("AIF", "Capture", 0, WM8737_POWER_MANAGEMENT
, 6, 0),
253 static const struct snd_soc_dapm_route intercon
[] = {
254 { "LINSEL", "LINPUT1", "LINPUT1" },
255 { "LINSEL", "LINPUT2", "LINPUT2" },
256 { "LINSEL", "LINPUT3", "LINPUT3" },
257 { "LINSEL", "LINPUT1 DC", "LINPUT1" },
259 { "RINSEL", "RINPUT1", "RINPUT1" },
260 { "RINSEL", "RINPUT2", "RINPUT2" },
261 { "RINSEL", "RINPUT3", "RINPUT3" },
262 { "RINSEL", "RINPUT1 DC", "RINPUT1" },
264 { "Left Preamp Mux", "Preamp", "LINSEL" },
265 { "Left Preamp Mux", "Direct", "LACIN" },
267 { "Right Preamp Mux", "Preamp", "RINSEL" },
268 { "Right Preamp Mux", "Direct", "RACIN" },
270 { "PGAL", NULL
, "Left Preamp Mux" },
271 { "PGAR", NULL
, "Right Preamp Mux" },
273 { "ADCL", NULL
, "PGAL" },
274 { "ADCR", NULL
, "PGAR" },
276 { "AIF", NULL
, "ADCL" },
277 { "AIF", NULL
, "ADCR" },
280 static int wm8737_add_widgets(struct snd_soc_codec
*codec
)
282 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
284 snd_soc_dapm_new_controls(dapm
, wm8737_dapm_widgets
,
285 ARRAY_SIZE(wm8737_dapm_widgets
));
286 snd_soc_dapm_add_routes(dapm
, intercon
, ARRAY_SIZE(intercon
));
291 /* codec mclk clock divider coefficients */
292 static const struct {
298 { 12288000, 8000, 0, 0x4 },
299 { 12288000, 12000, 0, 0x8 },
300 { 12288000, 16000, 0, 0xa },
301 { 12288000, 24000, 0, 0x1c },
302 { 12288000, 32000, 0, 0xc },
303 { 12288000, 48000, 0, 0 },
304 { 12288000, 96000, 0, 0xe },
306 { 11289600, 8000, 0, 0x14 },
307 { 11289600, 11025, 0, 0x18 },
308 { 11289600, 22050, 0, 0x1a },
309 { 11289600, 44100, 0, 0x10 },
310 { 11289600, 88200, 0, 0x1e },
312 { 18432000, 8000, 0, 0x5 },
313 { 18432000, 12000, 0, 0x9 },
314 { 18432000, 16000, 0, 0xb },
315 { 18432000, 24000, 0, 0x1b },
316 { 18432000, 32000, 0, 0xd },
317 { 18432000, 48000, 0, 0x1 },
318 { 18432000, 96000, 0, 0x1f },
320 { 16934400, 8000, 0, 0x15 },
321 { 16934400, 11025, 0, 0x19 },
322 { 16934400, 22050, 0, 0x1b },
323 { 16934400, 44100, 0, 0x11 },
324 { 16934400, 88200, 0, 0x1f },
326 { 12000000, 8000, 1, 0x4 },
327 { 12000000, 11025, 1, 0x19 },
328 { 12000000, 12000, 1, 0x8 },
329 { 12000000, 16000, 1, 0xa },
330 { 12000000, 22050, 1, 0x1b },
331 { 12000000, 24000, 1, 0x1c },
332 { 12000000, 32000, 1, 0xc },
333 { 12000000, 44100, 1, 0x11 },
334 { 12000000, 48000, 1, 0x0 },
335 { 12000000, 88200, 1, 0x1f },
336 { 12000000, 96000, 1, 0xe },
339 static int wm8737_hw_params(struct snd_pcm_substream
*substream
,
340 struct snd_pcm_hw_params
*params
,
341 struct snd_soc_dai
*dai
)
343 struct snd_soc_codec
*codec
= dai
->codec
;
344 struct wm8737_priv
*wm8737
= snd_soc_codec_get_drvdata(codec
);
349 for (i
= 0; i
< ARRAY_SIZE(coeff_div
); i
++) {
350 if (coeff_div
[i
].rate
!= params_rate(params
))
353 if (coeff_div
[i
].mclk
== wm8737
->mclk
)
356 if (coeff_div
[i
].mclk
== wm8737
->mclk
* 2) {
357 clocking
|= WM8737_CLKDIV2
;
362 if (i
== ARRAY_SIZE(coeff_div
)) {
363 dev_err(codec
->dev
, "%dHz MCLK can't support %dHz\n",
364 wm8737
->mclk
, params_rate(params
));
368 clocking
|= coeff_div
[i
].usb
| (coeff_div
[i
].sr
<< WM8737_SR_SHIFT
);
370 switch (params_format(params
)) {
371 case SNDRV_PCM_FORMAT_S16_LE
:
373 case SNDRV_PCM_FORMAT_S20_3LE
:
376 case SNDRV_PCM_FORMAT_S24_LE
:
379 case SNDRV_PCM_FORMAT_S32_LE
:
386 snd_soc_update_bits(codec
, WM8737_AUDIO_FORMAT
, WM8737_WL_MASK
, af
);
387 snd_soc_update_bits(codec
, WM8737_CLOCKING
,
388 WM8737_USB_MODE
| WM8737_CLKDIV2
| WM8737_SR_MASK
,
394 static int wm8737_set_dai_sysclk(struct snd_soc_dai
*codec_dai
,
395 int clk_id
, unsigned int freq
, int dir
)
397 struct snd_soc_codec
*codec
= codec_dai
->codec
;
398 struct wm8737_priv
*wm8737
= snd_soc_codec_get_drvdata(codec
);
401 for (i
= 0; i
< ARRAY_SIZE(coeff_div
); i
++) {
402 if (freq
== coeff_div
[i
].mclk
||
403 freq
== coeff_div
[i
].mclk
* 2) {
409 dev_err(codec
->dev
, "MCLK rate %dHz not supported\n", freq
);
415 static int wm8737_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
418 struct snd_soc_codec
*codec
= codec_dai
->codec
;
421 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
422 case SND_SOC_DAIFMT_CBM_CFM
:
425 case SND_SOC_DAIFMT_CBS_CFS
:
431 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
432 case SND_SOC_DAIFMT_I2S
:
435 case SND_SOC_DAIFMT_RIGHT_J
:
437 case SND_SOC_DAIFMT_LEFT_J
:
440 case SND_SOC_DAIFMT_DSP_A
:
443 case SND_SOC_DAIFMT_DSP_B
:
450 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
451 case SND_SOC_DAIFMT_NB_NF
:
453 case SND_SOC_DAIFMT_NB_IF
:
460 snd_soc_update_bits(codec
, WM8737_AUDIO_FORMAT
,
461 WM8737_FORMAT_MASK
| WM8737_LRP
| WM8737_MS
, af
);
466 static int wm8737_set_bias_level(struct snd_soc_codec
*codec
,
467 enum snd_soc_bias_level level
)
469 struct wm8737_priv
*wm8737
= snd_soc_codec_get_drvdata(codec
);
473 case SND_SOC_BIAS_ON
:
476 case SND_SOC_BIAS_PREPARE
:
478 snd_soc_update_bits(codec
, WM8737_MISC_BIAS_CONTROL
,
479 WM8737_VMIDSEL_MASK
, 0);
482 case SND_SOC_BIAS_STANDBY
:
483 if (codec
->dapm
.bias_level
== SND_SOC_BIAS_OFF
) {
484 ret
= regulator_bulk_enable(ARRAY_SIZE(wm8737
->supplies
),
488 "Failed to enable supplies: %d\n",
493 regcache_sync(wm8737
->regmap
);
495 /* Fast VMID ramp at 2*2.5k */
496 snd_soc_update_bits(codec
, WM8737_MISC_BIAS_CONTROL
,
497 WM8737_VMIDSEL_MASK
, 0x4);
500 snd_soc_update_bits(codec
, WM8737_POWER_MANAGEMENT
,
510 snd_soc_update_bits(codec
, WM8737_MISC_BIAS_CONTROL
,
511 WM8737_VMIDSEL_MASK
, 2);
515 case SND_SOC_BIAS_OFF
:
516 snd_soc_update_bits(codec
, WM8737_POWER_MANAGEMENT
,
517 WM8737_VMID_MASK
| WM8737_VREF_MASK
, 0);
519 regulator_bulk_disable(ARRAY_SIZE(wm8737
->supplies
),
524 codec
->dapm
.bias_level
= level
;
528 #define WM8737_RATES SNDRV_PCM_RATE_8000_96000
530 #define WM8737_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
531 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
533 static const struct snd_soc_dai_ops wm8737_dai_ops
= {
534 .hw_params
= wm8737_hw_params
,
535 .set_sysclk
= wm8737_set_dai_sysclk
,
536 .set_fmt
= wm8737_set_dai_fmt
,
539 static struct snd_soc_dai_driver wm8737_dai
= {
542 .stream_name
= "Capture",
543 .channels_min
= 2, /* Mono modes not yet supported */
545 .rates
= WM8737_RATES
,
546 .formats
= WM8737_FORMATS
,
548 .ops
= &wm8737_dai_ops
,
552 static int wm8737_suspend(struct snd_soc_codec
*codec
)
554 wm8737_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
558 static int wm8737_resume(struct snd_soc_codec
*codec
)
560 wm8737_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
564 #define wm8737_suspend NULL
565 #define wm8737_resume NULL
568 static int wm8737_probe(struct snd_soc_codec
*codec
)
570 struct wm8737_priv
*wm8737
= snd_soc_codec_get_drvdata(codec
);
573 ret
= snd_soc_codec_set_cache_io(codec
, 7, 9, SND_SOC_REGMAP
);
575 dev_err(codec
->dev
, "Failed to set cache I/O: %d\n", ret
);
579 ret
= regulator_bulk_enable(ARRAY_SIZE(wm8737
->supplies
),
582 dev_err(codec
->dev
, "Failed to enable supplies: %d\n", ret
);
586 ret
= wm8737_reset(codec
);
588 dev_err(codec
->dev
, "Failed to issue reset\n");
592 snd_soc_update_bits(codec
, WM8737_LEFT_PGA_VOLUME
, WM8737_LVU
,
594 snd_soc_update_bits(codec
, WM8737_RIGHT_PGA_VOLUME
, WM8737_RVU
,
597 wm8737_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
599 /* Bias level configuration will have done an extra enable */
600 regulator_bulk_disable(ARRAY_SIZE(wm8737
->supplies
), wm8737
->supplies
);
602 snd_soc_add_codec_controls(codec
, wm8737_snd_controls
,
603 ARRAY_SIZE(wm8737_snd_controls
));
604 wm8737_add_widgets(codec
);
609 regulator_bulk_disable(ARRAY_SIZE(wm8737
->supplies
), wm8737
->supplies
);
614 static int wm8737_remove(struct snd_soc_codec
*codec
)
616 wm8737_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
620 static struct snd_soc_codec_driver soc_codec_dev_wm8737
= {
621 .probe
= wm8737_probe
,
622 .remove
= wm8737_remove
,
623 .suspend
= wm8737_suspend
,
624 .resume
= wm8737_resume
,
625 .set_bias_level
= wm8737_set_bias_level
,
628 static const struct of_device_id wm8737_of_match
[] = {
629 { .compatible
= "wlf,wm8737", },
633 MODULE_DEVICE_TABLE(of
, wm8737_of_match
);
635 static const struct regmap_config wm8737_regmap
= {
638 .max_register
= WM8737_MAX_REGISTER
,
640 .reg_defaults
= wm8737_reg_defaults
,
641 .num_reg_defaults
= ARRAY_SIZE(wm8737_reg_defaults
),
642 .cache_type
= REGCACHE_RBTREE
,
644 .volatile_reg
= wm8737_volatile
,
647 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
648 static int wm8737_i2c_probe(struct i2c_client
*i2c
,
649 const struct i2c_device_id
*id
)
651 struct wm8737_priv
*wm8737
;
654 wm8737
= devm_kzalloc(&i2c
->dev
, sizeof(struct wm8737_priv
),
659 for (i
= 0; i
< ARRAY_SIZE(wm8737
->supplies
); i
++)
660 wm8737
->supplies
[i
].supply
= wm8737_supply_names
[i
];
662 ret
= devm_regulator_bulk_get(&i2c
->dev
, ARRAY_SIZE(wm8737
->supplies
),
665 dev_err(&i2c
->dev
, "Failed to request supplies: %d\n", ret
);
669 wm8737
->regmap
= devm_regmap_init_i2c(i2c
, &wm8737_regmap
);
670 if (IS_ERR(wm8737
->regmap
))
671 return PTR_ERR(wm8737
->regmap
);
673 i2c_set_clientdata(i2c
, wm8737
);
675 ret
= snd_soc_register_codec(&i2c
->dev
,
676 &soc_codec_dev_wm8737
, &wm8737_dai
, 1);
682 static int wm8737_i2c_remove(struct i2c_client
*client
)
684 snd_soc_unregister_codec(&client
->dev
);
689 static const struct i2c_device_id wm8737_i2c_id
[] = {
693 MODULE_DEVICE_TABLE(i2c
, wm8737_i2c_id
);
695 static struct i2c_driver wm8737_i2c_driver
= {
698 .owner
= THIS_MODULE
,
699 .of_match_table
= wm8737_of_match
,
701 .probe
= wm8737_i2c_probe
,
702 .remove
= wm8737_i2c_remove
,
703 .id_table
= wm8737_i2c_id
,
707 #if defined(CONFIG_SPI_MASTER)
708 static int wm8737_spi_probe(struct spi_device
*spi
)
710 struct wm8737_priv
*wm8737
;
713 wm8737
= devm_kzalloc(&spi
->dev
, sizeof(struct wm8737_priv
),
718 for (i
= 0; i
< ARRAY_SIZE(wm8737
->supplies
); i
++)
719 wm8737
->supplies
[i
].supply
= wm8737_supply_names
[i
];
721 ret
= devm_regulator_bulk_get(&spi
->dev
, ARRAY_SIZE(wm8737
->supplies
),
724 dev_err(&spi
->dev
, "Failed to request supplies: %d\n", ret
);
728 wm8737
->regmap
= devm_regmap_init_spi(spi
, &wm8737_regmap
);
729 if (IS_ERR(wm8737
->regmap
))
730 return PTR_ERR(wm8737
->regmap
);
732 spi_set_drvdata(spi
, wm8737
);
734 ret
= snd_soc_register_codec(&spi
->dev
,
735 &soc_codec_dev_wm8737
, &wm8737_dai
, 1);
740 static int wm8737_spi_remove(struct spi_device
*spi
)
742 snd_soc_unregister_codec(&spi
->dev
);
747 static struct spi_driver wm8737_spi_driver
= {
750 .owner
= THIS_MODULE
,
751 .of_match_table
= wm8737_of_match
,
753 .probe
= wm8737_spi_probe
,
754 .remove
= wm8737_spi_remove
,
756 #endif /* CONFIG_SPI_MASTER */
758 static int __init
wm8737_modinit(void)
761 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
762 ret
= i2c_add_driver(&wm8737_i2c_driver
);
764 printk(KERN_ERR
"Failed to register WM8737 I2C driver: %d\n",
768 #if defined(CONFIG_SPI_MASTER)
769 ret
= spi_register_driver(&wm8737_spi_driver
);
771 printk(KERN_ERR
"Failed to register WM8737 SPI driver: %d\n",
777 module_init(wm8737_modinit
);
779 static void __exit
wm8737_exit(void)
781 #if defined(CONFIG_SPI_MASTER)
782 spi_unregister_driver(&wm8737_spi_driver
);
784 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
785 i2c_del_driver(&wm8737_i2c_driver
);
788 module_exit(wm8737_exit
);
790 MODULE_DESCRIPTION("ASoC WM8737 driver");
791 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
792 MODULE_LICENSE("GPL");