2 * wm8731.c -- WM8731 ALSA SoC Audio driver
4 * Copyright 2005 Openedhand Ltd.
5 * Copyright 2006-12 Wolfson Microelectronics, plc
7 * Author: Richard Purdie <richard@openedhand.com>
9 * Based on wm8753.c by Liam Girdwood
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #include <linux/module.h>
17 #include <linux/moduleparam.h>
18 #include <linux/init.h>
19 #include <linux/delay.h>
21 #include <linux/i2c.h>
22 #include <linux/slab.h>
23 #include <linux/regmap.h>
24 #include <linux/regulator/consumer.h>
25 #include <linux/spi/spi.h>
26 #include <linux/of_device.h>
27 #include <linux/mutex.h>
28 #include <linux/clk.h>
29 #include <sound/core.h>
30 #include <sound/pcm.h>
31 #include <sound/pcm_params.h>
32 #include <sound/soc.h>
33 #include <sound/initval.h>
34 #include <sound/tlv.h>
38 #define WM8731_NUM_SUPPLIES 4
39 static const char *wm8731_supply_names
[WM8731_NUM_SUPPLIES
] = {
46 /* codec private data */
48 struct regmap
*regmap
;
50 struct regulator_bulk_data supplies
[WM8731_NUM_SUPPLIES
];
51 const struct snd_pcm_hw_constraint_list
*constraints
;
62 * wm8731 register cache
64 static const struct reg_default wm8731_reg_defaults
[] = {
77 static bool wm8731_volatile(struct device
*dev
, unsigned int reg
)
79 return reg
== WM8731_RESET
;
82 static bool wm8731_writeable(struct device
*dev
, unsigned int reg
)
84 return reg
<= WM8731_RESET
;
87 #define wm8731_reset(c) snd_soc_write(c, WM8731_RESET, 0)
89 static const char *wm8731_input_select
[] = {"Line In", "Mic"};
91 static SOC_ENUM_SINGLE_DECL(wm8731_insel_enum
,
92 WM8731_APANA
, 2, wm8731_input_select
);
94 static int wm8731_deemph
[] = { 0, 32000, 44100, 48000 };
96 static int wm8731_set_deemph(struct snd_soc_codec
*codec
)
98 struct wm8731_priv
*wm8731
= snd_soc_codec_get_drvdata(codec
);
101 /* If we're using deemphasis select the nearest available sample
104 if (wm8731
->deemph
) {
106 for (i
= 2; i
< ARRAY_SIZE(wm8731_deemph
); i
++) {
107 if (abs(wm8731_deemph
[i
] - wm8731
->playback_fs
) <
108 abs(wm8731_deemph
[best
] - wm8731
->playback_fs
))
118 dev_dbg(codec
->dev
, "Set deemphasis %d (%dHz)\n",
119 best
, wm8731_deemph
[best
]);
121 return snd_soc_update_bits(codec
, WM8731_APDIGI
, 0x6, val
);
124 static int wm8731_get_deemph(struct snd_kcontrol
*kcontrol
,
125 struct snd_ctl_elem_value
*ucontrol
)
127 struct snd_soc_codec
*codec
= snd_soc_kcontrol_codec(kcontrol
);
128 struct wm8731_priv
*wm8731
= snd_soc_codec_get_drvdata(codec
);
130 ucontrol
->value
.integer
.value
[0] = wm8731
->deemph
;
135 static int wm8731_put_deemph(struct snd_kcontrol
*kcontrol
,
136 struct snd_ctl_elem_value
*ucontrol
)
138 struct snd_soc_codec
*codec
= snd_soc_kcontrol_codec(kcontrol
);
139 struct wm8731_priv
*wm8731
= snd_soc_codec_get_drvdata(codec
);
140 int deemph
= ucontrol
->value
.integer
.value
[0];
146 mutex_lock(&wm8731
->lock
);
147 if (wm8731
->deemph
!= deemph
) {
148 wm8731
->deemph
= deemph
;
150 wm8731_set_deemph(codec
);
154 mutex_unlock(&wm8731
->lock
);
159 static const DECLARE_TLV_DB_SCALE(in_tlv
, -3450, 150, 0);
160 static const DECLARE_TLV_DB_SCALE(sidetone_tlv
, -1500, 300, 0);
161 static const DECLARE_TLV_DB_SCALE(out_tlv
, -12100, 100, 1);
162 static const DECLARE_TLV_DB_SCALE(mic_tlv
, 0, 2000, 0);
164 static const struct snd_kcontrol_new wm8731_snd_controls
[] = {
166 SOC_DOUBLE_R_TLV("Master Playback Volume", WM8731_LOUT1V
, WM8731_ROUT1V
,
168 SOC_DOUBLE_R("Master Playback ZC Switch", WM8731_LOUT1V
, WM8731_ROUT1V
,
171 SOC_DOUBLE_R_TLV("Capture Volume", WM8731_LINVOL
, WM8731_RINVOL
, 0, 31, 0,
173 SOC_DOUBLE_R("Line Capture Switch", WM8731_LINVOL
, WM8731_RINVOL
, 7, 1, 1),
175 SOC_SINGLE_TLV("Mic Boost Volume", WM8731_APANA
, 0, 1, 0, mic_tlv
),
176 SOC_SINGLE("Mic Capture Switch", WM8731_APANA
, 1, 1, 1),
178 SOC_SINGLE_TLV("Sidetone Playback Volume", WM8731_APANA
, 6, 3, 1,
181 SOC_SINGLE("ADC High Pass Filter Switch", WM8731_APDIGI
, 0, 1, 1),
182 SOC_SINGLE("Store DC Offset Switch", WM8731_APDIGI
, 4, 1, 0),
184 SOC_SINGLE_BOOL_EXT("Playback Deemphasis Switch", 0,
185 wm8731_get_deemph
, wm8731_put_deemph
),
189 static const struct snd_kcontrol_new wm8731_output_mixer_controls
[] = {
190 SOC_DAPM_SINGLE("Line Bypass Switch", WM8731_APANA
, 3, 1, 0),
191 SOC_DAPM_SINGLE("Mic Sidetone Switch", WM8731_APANA
, 5, 1, 0),
192 SOC_DAPM_SINGLE("HiFi Playback Switch", WM8731_APANA
, 4, 1, 0),
196 static const struct snd_kcontrol_new wm8731_input_mux_controls
=
197 SOC_DAPM_ENUM("Input Select", wm8731_insel_enum
);
199 static const struct snd_soc_dapm_widget wm8731_dapm_widgets
[] = {
200 SND_SOC_DAPM_SUPPLY("ACTIVE",WM8731_ACTIVE
, 0, 0, NULL
, 0),
201 SND_SOC_DAPM_SUPPLY("OSC", WM8731_PWR
, 5, 1, NULL
, 0),
202 SND_SOC_DAPM_MIXER("Output Mixer", WM8731_PWR
, 4, 1,
203 &wm8731_output_mixer_controls
[0],
204 ARRAY_SIZE(wm8731_output_mixer_controls
)),
205 SND_SOC_DAPM_DAC("DAC", "HiFi Playback", WM8731_PWR
, 3, 1),
206 SND_SOC_DAPM_OUTPUT("LOUT"),
207 SND_SOC_DAPM_OUTPUT("LHPOUT"),
208 SND_SOC_DAPM_OUTPUT("ROUT"),
209 SND_SOC_DAPM_OUTPUT("RHPOUT"),
210 SND_SOC_DAPM_ADC("ADC", "HiFi Capture", WM8731_PWR
, 2, 1),
211 SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM
, 0, 0, &wm8731_input_mux_controls
),
212 SND_SOC_DAPM_PGA("Line Input", WM8731_PWR
, 0, 1, NULL
, 0),
213 SND_SOC_DAPM_MICBIAS("Mic Bias", WM8731_PWR
, 1, 1),
214 SND_SOC_DAPM_INPUT("MICIN"),
215 SND_SOC_DAPM_INPUT("RLINEIN"),
216 SND_SOC_DAPM_INPUT("LLINEIN"),
219 static int wm8731_check_osc(struct snd_soc_dapm_widget
*source
,
220 struct snd_soc_dapm_widget
*sink
)
222 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(source
->dapm
);
223 struct wm8731_priv
*wm8731
= snd_soc_codec_get_drvdata(codec
);
225 return wm8731
->sysclk_type
== WM8731_SYSCLK_XTAL
;
228 static const struct snd_soc_dapm_route wm8731_intercon
[] = {
229 {"DAC", NULL
, "OSC", wm8731_check_osc
},
230 {"ADC", NULL
, "OSC", wm8731_check_osc
},
231 {"DAC", NULL
, "ACTIVE"},
232 {"ADC", NULL
, "ACTIVE"},
235 {"Output Mixer", "Line Bypass Switch", "Line Input"},
236 {"Output Mixer", "HiFi Playback Switch", "DAC"},
237 {"Output Mixer", "Mic Sidetone Switch", "Mic Bias"},
240 {"RHPOUT", NULL
, "Output Mixer"},
241 {"ROUT", NULL
, "Output Mixer"},
242 {"LHPOUT", NULL
, "Output Mixer"},
243 {"LOUT", NULL
, "Output Mixer"},
246 {"Input Mux", "Line In", "Line Input"},
247 {"Input Mux", "Mic", "Mic Bias"},
248 {"ADC", NULL
, "Input Mux"},
251 {"Line Input", NULL
, "LLINEIN"},
252 {"Line Input", NULL
, "RLINEIN"},
253 {"Mic Bias", NULL
, "MICIN"},
265 /* codec mclk clock divider coefficients */
266 static const struct _coeff_div coeff_div
[] = {
268 {12288000, 48000, 256, 0x0, 0x0, 0x0},
269 {18432000, 48000, 384, 0x0, 0x1, 0x0},
270 {12000000, 48000, 250, 0x0, 0x0, 0x1},
273 {12288000, 32000, 384, 0x6, 0x0, 0x0},
274 {18432000, 32000, 576, 0x6, 0x1, 0x0},
275 {12000000, 32000, 375, 0x6, 0x0, 0x1},
278 {12288000, 8000, 1536, 0x3, 0x0, 0x0},
279 {18432000, 8000, 2304, 0x3, 0x1, 0x0},
280 {11289600, 8000, 1408, 0xb, 0x0, 0x0},
281 {16934400, 8000, 2112, 0xb, 0x1, 0x0},
282 {12000000, 8000, 1500, 0x3, 0x0, 0x1},
285 {12288000, 96000, 128, 0x7, 0x0, 0x0},
286 {18432000, 96000, 192, 0x7, 0x1, 0x0},
287 {12000000, 96000, 125, 0x7, 0x0, 0x1},
290 {11289600, 44100, 256, 0x8, 0x0, 0x0},
291 {16934400, 44100, 384, 0x8, 0x1, 0x0},
292 {12000000, 44100, 272, 0x8, 0x1, 0x1},
295 {11289600, 88200, 128, 0xf, 0x0, 0x0},
296 {16934400, 88200, 192, 0xf, 0x1, 0x0},
297 {12000000, 88200, 136, 0xf, 0x1, 0x1},
300 /* rates constraints */
301 static const unsigned int wm8731_rates_12000000
[] = {
302 8000, 32000, 44100, 48000, 96000, 88200,
305 static const unsigned int wm8731_rates_12288000_18432000
[] = {
306 8000, 32000, 48000, 96000,
309 static const unsigned int wm8731_rates_11289600_16934400
[] = {
313 static const struct snd_pcm_hw_constraint_list wm8731_constraints_12000000
= {
314 .list
= wm8731_rates_12000000
,
315 .count
= ARRAY_SIZE(wm8731_rates_12000000
),
319 struct snd_pcm_hw_constraint_list wm8731_constraints_12288000_18432000
= {
320 .list
= wm8731_rates_12288000_18432000
,
321 .count
= ARRAY_SIZE(wm8731_rates_12288000_18432000
),
325 struct snd_pcm_hw_constraint_list wm8731_constraints_11289600_16934400
= {
326 .list
= wm8731_rates_11289600_16934400
,
327 .count
= ARRAY_SIZE(wm8731_rates_11289600_16934400
),
330 static inline int get_coeff(int mclk
, int rate
)
334 for (i
= 0; i
< ARRAY_SIZE(coeff_div
); i
++) {
335 if (coeff_div
[i
].rate
== rate
&& coeff_div
[i
].mclk
== mclk
)
341 static int wm8731_hw_params(struct snd_pcm_substream
*substream
,
342 struct snd_pcm_hw_params
*params
,
343 struct snd_soc_dai
*dai
)
345 struct snd_soc_codec
*codec
= dai
->codec
;
346 struct wm8731_priv
*wm8731
= snd_soc_codec_get_drvdata(codec
);
347 u16 iface
= snd_soc_read(codec
, WM8731_IFACE
) & 0xfff3;
348 int i
= get_coeff(wm8731
->sysclk
, params_rate(params
));
349 u16 srate
= (coeff_div
[i
].sr
<< 2) |
350 (coeff_div
[i
].bosr
<< 1) | coeff_div
[i
].usb
;
352 wm8731
->playback_fs
= params_rate(params
);
354 snd_soc_write(codec
, WM8731_SRATE
, srate
);
357 switch (params_width(params
)) {
368 wm8731_set_deemph(codec
);
370 snd_soc_write(codec
, WM8731_IFACE
, iface
);
374 static int wm8731_mute(struct snd_soc_dai
*dai
, int mute
)
376 struct snd_soc_codec
*codec
= dai
->codec
;
377 u16 mute_reg
= snd_soc_read(codec
, WM8731_APDIGI
) & 0xfff7;
380 snd_soc_write(codec
, WM8731_APDIGI
, mute_reg
| 0x8);
382 snd_soc_write(codec
, WM8731_APDIGI
, mute_reg
);
386 static int wm8731_set_dai_sysclk(struct snd_soc_dai
*codec_dai
,
387 int clk_id
, unsigned int freq
, int dir
)
389 struct snd_soc_codec
*codec
= codec_dai
->codec
;
390 struct snd_soc_dapm_context
*dapm
= snd_soc_codec_get_dapm(codec
);
391 struct wm8731_priv
*wm8731
= snd_soc_codec_get_drvdata(codec
);
394 case WM8731_SYSCLK_XTAL
:
395 case WM8731_SYSCLK_MCLK
:
396 if (wm8731
->mclk
&& clk_set_rate(wm8731
->mclk
, freq
))
398 wm8731
->sysclk_type
= clk_id
;
406 wm8731
->constraints
= NULL
;
409 wm8731
->constraints
= &wm8731_constraints_12000000
;
413 wm8731
->constraints
= &wm8731_constraints_12288000_18432000
;
417 wm8731
->constraints
= &wm8731_constraints_11289600_16934400
;
423 wm8731
->sysclk
= freq
;
425 snd_soc_dapm_sync(dapm
);
431 static int wm8731_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
434 struct snd_soc_codec
*codec
= codec_dai
->codec
;
437 /* set master/slave audio interface */
438 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
439 case SND_SOC_DAIFMT_CBM_CFM
:
442 case SND_SOC_DAIFMT_CBS_CFS
:
448 /* interface format */
449 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
450 case SND_SOC_DAIFMT_I2S
:
453 case SND_SOC_DAIFMT_RIGHT_J
:
455 case SND_SOC_DAIFMT_LEFT_J
:
458 case SND_SOC_DAIFMT_DSP_A
:
461 case SND_SOC_DAIFMT_DSP_B
:
468 /* clock inversion */
469 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
470 case SND_SOC_DAIFMT_NB_NF
:
472 case SND_SOC_DAIFMT_IB_IF
:
475 case SND_SOC_DAIFMT_IB_NF
:
478 case SND_SOC_DAIFMT_NB_IF
:
486 snd_soc_write(codec
, WM8731_IFACE
, iface
);
490 static int wm8731_set_bias_level(struct snd_soc_codec
*codec
,
491 enum snd_soc_bias_level level
)
493 struct wm8731_priv
*wm8731
= snd_soc_codec_get_drvdata(codec
);
498 case SND_SOC_BIAS_ON
:
500 clk_prepare_enable(wm8731
->mclk
);
502 case SND_SOC_BIAS_PREPARE
:
504 case SND_SOC_BIAS_STANDBY
:
505 if (snd_soc_codec_get_bias_level(codec
) == SND_SOC_BIAS_OFF
) {
506 ret
= regulator_bulk_enable(ARRAY_SIZE(wm8731
->supplies
),
511 regcache_sync(wm8731
->regmap
);
514 /* Clear PWROFF, gate CLKOUT, everything else as-is */
515 reg
= snd_soc_read(codec
, WM8731_PWR
) & 0xff7f;
516 snd_soc_write(codec
, WM8731_PWR
, reg
| 0x0040);
518 case SND_SOC_BIAS_OFF
:
520 clk_disable_unprepare(wm8731
->mclk
);
521 snd_soc_write(codec
, WM8731_PWR
, 0xffff);
522 regulator_bulk_disable(ARRAY_SIZE(wm8731
->supplies
),
524 regcache_mark_dirty(wm8731
->regmap
);
530 static int wm8731_startup(struct snd_pcm_substream
*substream
,
531 struct snd_soc_dai
*dai
)
533 struct wm8731_priv
*wm8731
= snd_soc_codec_get_drvdata(dai
->codec
);
535 if (wm8731
->constraints
)
536 snd_pcm_hw_constraint_list(substream
->runtime
, 0,
537 SNDRV_PCM_HW_PARAM_RATE
,
538 wm8731
->constraints
);
543 #define WM8731_RATES SNDRV_PCM_RATE_8000_96000
545 #define WM8731_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
546 SNDRV_PCM_FMTBIT_S24_LE)
548 static const struct snd_soc_dai_ops wm8731_dai_ops
= {
549 .startup
= wm8731_startup
,
550 .hw_params
= wm8731_hw_params
,
551 .digital_mute
= wm8731_mute
,
552 .set_sysclk
= wm8731_set_dai_sysclk
,
553 .set_fmt
= wm8731_set_dai_fmt
,
556 static struct snd_soc_dai_driver wm8731_dai
= {
557 .name
= "wm8731-hifi",
559 .stream_name
= "Playback",
562 .rates
= WM8731_RATES
,
563 .formats
= WM8731_FORMATS
,},
565 .stream_name
= "Capture",
568 .rates
= WM8731_RATES
,
569 .formats
= WM8731_FORMATS
,},
570 .ops
= &wm8731_dai_ops
,
571 .symmetric_rates
= 1,
574 static int wm8731_probe(struct snd_soc_codec
*codec
)
576 struct wm8731_priv
*wm8731
= snd_soc_codec_get_drvdata(codec
);
579 for (i
= 0; i
< ARRAY_SIZE(wm8731
->supplies
); i
++)
580 wm8731
->supplies
[i
].supply
= wm8731_supply_names
[i
];
582 ret
= devm_regulator_bulk_get(codec
->dev
, ARRAY_SIZE(wm8731
->supplies
),
585 dev_err(codec
->dev
, "Failed to request supplies: %d\n", ret
);
589 ret
= regulator_bulk_enable(ARRAY_SIZE(wm8731
->supplies
),
592 dev_err(codec
->dev
, "Failed to enable supplies: %d\n", ret
);
596 ret
= wm8731_reset(codec
);
598 dev_err(codec
->dev
, "Failed to issue reset: %d\n", ret
);
599 goto err_regulator_enable
;
602 snd_soc_codec_force_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
604 /* Latch the update bits */
605 snd_soc_update_bits(codec
, WM8731_LOUT1V
, 0x100, 0);
606 snd_soc_update_bits(codec
, WM8731_ROUT1V
, 0x100, 0);
607 snd_soc_update_bits(codec
, WM8731_LINVOL
, 0x100, 0);
608 snd_soc_update_bits(codec
, WM8731_RINVOL
, 0x100, 0);
610 /* Disable bypass path by default */
611 snd_soc_update_bits(codec
, WM8731_APANA
, 0x8, 0);
613 /* Regulators will have been enabled by bias management */
614 regulator_bulk_disable(ARRAY_SIZE(wm8731
->supplies
), wm8731
->supplies
);
618 err_regulator_enable
:
619 regulator_bulk_disable(ARRAY_SIZE(wm8731
->supplies
), wm8731
->supplies
);
624 /* power down chip */
625 static int wm8731_remove(struct snd_soc_codec
*codec
)
627 struct wm8731_priv
*wm8731
= snd_soc_codec_get_drvdata(codec
);
629 regulator_bulk_disable(ARRAY_SIZE(wm8731
->supplies
), wm8731
->supplies
);
634 static struct snd_soc_codec_driver soc_codec_dev_wm8731
= {
635 .probe
= wm8731_probe
,
636 .remove
= wm8731_remove
,
637 .set_bias_level
= wm8731_set_bias_level
,
638 .suspend_bias_off
= true,
640 .dapm_widgets
= wm8731_dapm_widgets
,
641 .num_dapm_widgets
= ARRAY_SIZE(wm8731_dapm_widgets
),
642 .dapm_routes
= wm8731_intercon
,
643 .num_dapm_routes
= ARRAY_SIZE(wm8731_intercon
),
644 .controls
= wm8731_snd_controls
,
645 .num_controls
= ARRAY_SIZE(wm8731_snd_controls
),
648 static const struct of_device_id wm8731_of_match
[] = {
649 { .compatible
= "wlf,wm8731", },
653 MODULE_DEVICE_TABLE(of
, wm8731_of_match
);
655 static const struct regmap_config wm8731_regmap
= {
659 .max_register
= WM8731_RESET
,
660 .volatile_reg
= wm8731_volatile
,
661 .writeable_reg
= wm8731_writeable
,
663 .cache_type
= REGCACHE_RBTREE
,
664 .reg_defaults
= wm8731_reg_defaults
,
665 .num_reg_defaults
= ARRAY_SIZE(wm8731_reg_defaults
),
668 #if defined(CONFIG_SPI_MASTER)
669 static int wm8731_spi_probe(struct spi_device
*spi
)
671 struct wm8731_priv
*wm8731
;
674 wm8731
= devm_kzalloc(&spi
->dev
, sizeof(*wm8731
), GFP_KERNEL
);
678 wm8731
->mclk
= devm_clk_get(&spi
->dev
, "mclk");
679 if (IS_ERR(wm8731
->mclk
)) {
680 ret
= PTR_ERR(wm8731
->mclk
);
681 if (ret
== -ENOENT
) {
683 dev_warn(&spi
->dev
, "Assuming static MCLK\n");
685 dev_err(&spi
->dev
, "Failed to get MCLK: %d\n",
691 mutex_init(&wm8731
->lock
);
693 wm8731
->regmap
= devm_regmap_init_spi(spi
, &wm8731_regmap
);
694 if (IS_ERR(wm8731
->regmap
)) {
695 ret
= PTR_ERR(wm8731
->regmap
);
696 dev_err(&spi
->dev
, "Failed to allocate register map: %d\n",
701 spi_set_drvdata(spi
, wm8731
);
703 ret
= snd_soc_register_codec(&spi
->dev
,
704 &soc_codec_dev_wm8731
, &wm8731_dai
, 1);
706 dev_err(&spi
->dev
, "Failed to register CODEC: %d\n", ret
);
713 static int wm8731_spi_remove(struct spi_device
*spi
)
715 snd_soc_unregister_codec(&spi
->dev
);
719 static struct spi_driver wm8731_spi_driver
= {
722 .owner
= THIS_MODULE
,
723 .of_match_table
= wm8731_of_match
,
725 .probe
= wm8731_spi_probe
,
726 .remove
= wm8731_spi_remove
,
728 #endif /* CONFIG_SPI_MASTER */
730 #if IS_ENABLED(CONFIG_I2C)
731 static int wm8731_i2c_probe(struct i2c_client
*i2c
,
732 const struct i2c_device_id
*id
)
734 struct wm8731_priv
*wm8731
;
737 wm8731
= devm_kzalloc(&i2c
->dev
, sizeof(struct wm8731_priv
),
742 wm8731
->mclk
= devm_clk_get(&i2c
->dev
, "mclk");
743 if (IS_ERR(wm8731
->mclk
)) {
744 ret
= PTR_ERR(wm8731
->mclk
);
745 if (ret
== -ENOENT
) {
747 dev_warn(&i2c
->dev
, "Assuming static MCLK\n");
749 dev_err(&i2c
->dev
, "Failed to get MCLK: %d\n",
755 mutex_init(&wm8731
->lock
);
757 wm8731
->regmap
= devm_regmap_init_i2c(i2c
, &wm8731_regmap
);
758 if (IS_ERR(wm8731
->regmap
)) {
759 ret
= PTR_ERR(wm8731
->regmap
);
760 dev_err(&i2c
->dev
, "Failed to allocate register map: %d\n",
765 i2c_set_clientdata(i2c
, wm8731
);
767 ret
= snd_soc_register_codec(&i2c
->dev
,
768 &soc_codec_dev_wm8731
, &wm8731_dai
, 1);
770 dev_err(&i2c
->dev
, "Failed to register CODEC: %d\n", ret
);
777 static int wm8731_i2c_remove(struct i2c_client
*client
)
779 snd_soc_unregister_codec(&client
->dev
);
783 static const struct i2c_device_id wm8731_i2c_id
[] = {
787 MODULE_DEVICE_TABLE(i2c
, wm8731_i2c_id
);
789 static struct i2c_driver wm8731_i2c_driver
= {
792 .owner
= THIS_MODULE
,
793 .of_match_table
= wm8731_of_match
,
795 .probe
= wm8731_i2c_probe
,
796 .remove
= wm8731_i2c_remove
,
797 .id_table
= wm8731_i2c_id
,
801 static int __init
wm8731_modinit(void)
804 #if IS_ENABLED(CONFIG_I2C)
805 ret
= i2c_add_driver(&wm8731_i2c_driver
);
807 printk(KERN_ERR
"Failed to register WM8731 I2C driver: %d\n",
811 #if defined(CONFIG_SPI_MASTER)
812 ret
= spi_register_driver(&wm8731_spi_driver
);
814 printk(KERN_ERR
"Failed to register WM8731 SPI driver: %d\n",
820 module_init(wm8731_modinit
);
822 static void __exit
wm8731_exit(void)
824 #if IS_ENABLED(CONFIG_I2C)
825 i2c_del_driver(&wm8731_i2c_driver
);
827 #if defined(CONFIG_SPI_MASTER)
828 spi_unregister_driver(&wm8731_spi_driver
);
831 module_exit(wm8731_exit
);
833 MODULE_DESCRIPTION("ASoC WM8731 driver");
834 MODULE_AUTHOR("Richard Purdie");
835 MODULE_LICENSE("GPL");