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 <sound/core.h>
28 #include <sound/pcm.h>
29 #include <sound/pcm_params.h>
30 #include <sound/soc.h>
31 #include <sound/initval.h>
32 #include <sound/tlv.h>
36 #define WM8731_NUM_SUPPLIES 4
37 static const char *wm8731_supply_names
[WM8731_NUM_SUPPLIES
] = {
44 /* codec private data */
46 struct regmap
*regmap
;
47 struct regulator_bulk_data supplies
[WM8731_NUM_SUPPLIES
];
48 const struct snd_pcm_hw_constraint_list
*constraints
;
57 * wm8731 register cache
59 static const struct reg_default wm8731_reg_defaults
[] = {
72 static bool wm8731_volatile(struct device
*dev
, unsigned int reg
)
74 return reg
== WM8731_RESET
;
77 static bool wm8731_writeable(struct device
*dev
, unsigned int reg
)
79 return reg
<= WM8731_RESET
;
82 #define wm8731_reset(c) snd_soc_write(c, WM8731_RESET, 0)
84 static const char *wm8731_input_select
[] = {"Line In", "Mic"};
86 static const struct soc_enum wm8731_insel_enum
=
87 SOC_ENUM_SINGLE(WM8731_APANA
, 2, 2, wm8731_input_select
);
89 static int wm8731_deemph
[] = { 0, 32000, 44100, 48000 };
91 static int wm8731_set_deemph(struct snd_soc_codec
*codec
)
93 struct wm8731_priv
*wm8731
= snd_soc_codec_get_drvdata(codec
);
96 /* If we're using deemphasis select the nearest available sample
101 for (i
= 2; i
< ARRAY_SIZE(wm8731_deemph
); i
++) {
102 if (abs(wm8731_deemph
[i
] - wm8731
->playback_fs
) <
103 abs(wm8731_deemph
[best
] - wm8731
->playback_fs
))
113 dev_dbg(codec
->dev
, "Set deemphasis %d (%dHz)\n",
114 best
, wm8731_deemph
[best
]);
116 return snd_soc_update_bits(codec
, WM8731_APDIGI
, 0x6, val
);
119 static int wm8731_get_deemph(struct snd_kcontrol
*kcontrol
,
120 struct snd_ctl_elem_value
*ucontrol
)
122 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
123 struct wm8731_priv
*wm8731
= snd_soc_codec_get_drvdata(codec
);
125 ucontrol
->value
.integer
.value
[0] = wm8731
->deemph
;
130 static int wm8731_put_deemph(struct snd_kcontrol
*kcontrol
,
131 struct snd_ctl_elem_value
*ucontrol
)
133 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
134 struct wm8731_priv
*wm8731
= snd_soc_codec_get_drvdata(codec
);
135 int deemph
= ucontrol
->value
.integer
.value
[0];
141 mutex_lock(&codec
->mutex
);
142 if (wm8731
->deemph
!= deemph
) {
143 wm8731
->deemph
= deemph
;
145 wm8731_set_deemph(codec
);
149 mutex_unlock(&codec
->mutex
);
154 static const DECLARE_TLV_DB_SCALE(in_tlv
, -3450, 150, 0);
155 static const DECLARE_TLV_DB_SCALE(sidetone_tlv
, -1500, 300, 0);
156 static const DECLARE_TLV_DB_SCALE(out_tlv
, -12100, 100, 1);
157 static const DECLARE_TLV_DB_SCALE(mic_tlv
, 0, 2000, 0);
159 static const struct snd_kcontrol_new wm8731_snd_controls
[] = {
161 SOC_DOUBLE_R_TLV("Master Playback Volume", WM8731_LOUT1V
, WM8731_ROUT1V
,
163 SOC_DOUBLE_R("Master Playback ZC Switch", WM8731_LOUT1V
, WM8731_ROUT1V
,
166 SOC_DOUBLE_R_TLV("Capture Volume", WM8731_LINVOL
, WM8731_RINVOL
, 0, 31, 0,
168 SOC_DOUBLE_R("Line Capture Switch", WM8731_LINVOL
, WM8731_RINVOL
, 7, 1, 1),
170 SOC_SINGLE_TLV("Mic Boost Volume", WM8731_APANA
, 0, 1, 0, mic_tlv
),
171 SOC_SINGLE("Mic Capture Switch", WM8731_APANA
, 1, 1, 1),
173 SOC_SINGLE_TLV("Sidetone Playback Volume", WM8731_APANA
, 6, 3, 1,
176 SOC_SINGLE("ADC High Pass Filter Switch", WM8731_APDIGI
, 0, 1, 1),
177 SOC_SINGLE("Store DC Offset Switch", WM8731_APDIGI
, 4, 1, 0),
179 SOC_SINGLE_BOOL_EXT("Playback Deemphasis Switch", 0,
180 wm8731_get_deemph
, wm8731_put_deemph
),
184 static const struct snd_kcontrol_new wm8731_output_mixer_controls
[] = {
185 SOC_DAPM_SINGLE("Line Bypass Switch", WM8731_APANA
, 3, 1, 0),
186 SOC_DAPM_SINGLE("Mic Sidetone Switch", WM8731_APANA
, 5, 1, 0),
187 SOC_DAPM_SINGLE("HiFi Playback Switch", WM8731_APANA
, 4, 1, 0),
191 static const struct snd_kcontrol_new wm8731_input_mux_controls
=
192 SOC_DAPM_ENUM("Input Select", wm8731_insel_enum
);
194 static const struct snd_soc_dapm_widget wm8731_dapm_widgets
[] = {
195 SND_SOC_DAPM_SUPPLY("ACTIVE",WM8731_ACTIVE
, 0, 0, NULL
, 0),
196 SND_SOC_DAPM_SUPPLY("OSC", WM8731_PWR
, 5, 1, NULL
, 0),
197 SND_SOC_DAPM_MIXER("Output Mixer", WM8731_PWR
, 4, 1,
198 &wm8731_output_mixer_controls
[0],
199 ARRAY_SIZE(wm8731_output_mixer_controls
)),
200 SND_SOC_DAPM_DAC("DAC", "HiFi Playback", WM8731_PWR
, 3, 1),
201 SND_SOC_DAPM_OUTPUT("LOUT"),
202 SND_SOC_DAPM_OUTPUT("LHPOUT"),
203 SND_SOC_DAPM_OUTPUT("ROUT"),
204 SND_SOC_DAPM_OUTPUT("RHPOUT"),
205 SND_SOC_DAPM_ADC("ADC", "HiFi Capture", WM8731_PWR
, 2, 1),
206 SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM
, 0, 0, &wm8731_input_mux_controls
),
207 SND_SOC_DAPM_PGA("Line Input", WM8731_PWR
, 0, 1, NULL
, 0),
208 SND_SOC_DAPM_MICBIAS("Mic Bias", WM8731_PWR
, 1, 1),
209 SND_SOC_DAPM_INPUT("MICIN"),
210 SND_SOC_DAPM_INPUT("RLINEIN"),
211 SND_SOC_DAPM_INPUT("LLINEIN"),
214 static int wm8731_check_osc(struct snd_soc_dapm_widget
*source
,
215 struct snd_soc_dapm_widget
*sink
)
217 struct wm8731_priv
*wm8731
= snd_soc_codec_get_drvdata(source
->codec
);
219 return wm8731
->sysclk_type
== WM8731_SYSCLK_XTAL
;
222 static const struct snd_soc_dapm_route wm8731_intercon
[] = {
223 {"DAC", NULL
, "OSC", wm8731_check_osc
},
224 {"ADC", NULL
, "OSC", wm8731_check_osc
},
225 {"DAC", NULL
, "ACTIVE"},
226 {"ADC", NULL
, "ACTIVE"},
229 {"Output Mixer", "Line Bypass Switch", "Line Input"},
230 {"Output Mixer", "HiFi Playback Switch", "DAC"},
231 {"Output Mixer", "Mic Sidetone Switch", "Mic Bias"},
234 {"RHPOUT", NULL
, "Output Mixer"},
235 {"ROUT", NULL
, "Output Mixer"},
236 {"LHPOUT", NULL
, "Output Mixer"},
237 {"LOUT", NULL
, "Output Mixer"},
240 {"Input Mux", "Line In", "Line Input"},
241 {"Input Mux", "Mic", "Mic Bias"},
242 {"ADC", NULL
, "Input Mux"},
245 {"Line Input", NULL
, "LLINEIN"},
246 {"Line Input", NULL
, "RLINEIN"},
247 {"Mic Bias", NULL
, "MICIN"},
259 /* codec mclk clock divider coefficients */
260 static const struct _coeff_div coeff_div
[] = {
262 {12288000, 48000, 256, 0x0, 0x0, 0x0},
263 {18432000, 48000, 384, 0x0, 0x1, 0x0},
264 {12000000, 48000, 250, 0x0, 0x0, 0x1},
267 {12288000, 32000, 384, 0x6, 0x0, 0x0},
268 {18432000, 32000, 576, 0x6, 0x1, 0x0},
269 {12000000, 32000, 375, 0x6, 0x0, 0x1},
272 {12288000, 8000, 1536, 0x3, 0x0, 0x0},
273 {18432000, 8000, 2304, 0x3, 0x1, 0x0},
274 {11289600, 8000, 1408, 0xb, 0x0, 0x0},
275 {16934400, 8000, 2112, 0xb, 0x1, 0x0},
276 {12000000, 8000, 1500, 0x3, 0x0, 0x1},
279 {12288000, 96000, 128, 0x7, 0x0, 0x0},
280 {18432000, 96000, 192, 0x7, 0x1, 0x0},
281 {12000000, 96000, 125, 0x7, 0x0, 0x1},
284 {11289600, 44100, 256, 0x8, 0x0, 0x0},
285 {16934400, 44100, 384, 0x8, 0x1, 0x0},
286 {12000000, 44100, 272, 0x8, 0x1, 0x1},
289 {11289600, 88200, 128, 0xf, 0x0, 0x0},
290 {16934400, 88200, 192, 0xf, 0x1, 0x0},
291 {12000000, 88200, 136, 0xf, 0x1, 0x1},
294 /* rates constraints */
295 static const unsigned int wm8731_rates_12000000
[] = {
296 8000, 32000, 44100, 48000, 96000, 88200,
299 static const unsigned int wm8731_rates_12288000_18432000
[] = {
300 8000, 32000, 48000, 96000,
303 static const unsigned int wm8731_rates_11289600_16934400
[] = {
307 static const struct snd_pcm_hw_constraint_list wm8731_constraints_12000000
= {
308 .list
= wm8731_rates_12000000
,
309 .count
= ARRAY_SIZE(wm8731_rates_12000000
),
313 struct snd_pcm_hw_constraint_list wm8731_constraints_12288000_18432000
= {
314 .list
= wm8731_rates_12288000_18432000
,
315 .count
= ARRAY_SIZE(wm8731_rates_12288000_18432000
),
319 struct snd_pcm_hw_constraint_list wm8731_constraints_11289600_16934400
= {
320 .list
= wm8731_rates_11289600_16934400
,
321 .count
= ARRAY_SIZE(wm8731_rates_11289600_16934400
),
324 static inline int get_coeff(int mclk
, int rate
)
328 for (i
= 0; i
< ARRAY_SIZE(coeff_div
); i
++) {
329 if (coeff_div
[i
].rate
== rate
&& coeff_div
[i
].mclk
== mclk
)
335 static int wm8731_hw_params(struct snd_pcm_substream
*substream
,
336 struct snd_pcm_hw_params
*params
,
337 struct snd_soc_dai
*dai
)
339 struct snd_soc_codec
*codec
= dai
->codec
;
340 struct wm8731_priv
*wm8731
= snd_soc_codec_get_drvdata(codec
);
341 u16 iface
= snd_soc_read(codec
, WM8731_IFACE
) & 0xfff3;
342 int i
= get_coeff(wm8731
->sysclk
, params_rate(params
));
343 u16 srate
= (coeff_div
[i
].sr
<< 2) |
344 (coeff_div
[i
].bosr
<< 1) | coeff_div
[i
].usb
;
346 wm8731
->playback_fs
= params_rate(params
);
348 snd_soc_write(codec
, WM8731_SRATE
, srate
);
351 switch (params_format(params
)) {
352 case SNDRV_PCM_FORMAT_S16_LE
:
354 case SNDRV_PCM_FORMAT_S20_3LE
:
357 case SNDRV_PCM_FORMAT_S24_LE
:
362 wm8731_set_deemph(codec
);
364 snd_soc_write(codec
, WM8731_IFACE
, iface
);
368 static int wm8731_mute(struct snd_soc_dai
*dai
, int mute
)
370 struct snd_soc_codec
*codec
= dai
->codec
;
371 u16 mute_reg
= snd_soc_read(codec
, WM8731_APDIGI
) & 0xfff7;
374 snd_soc_write(codec
, WM8731_APDIGI
, mute_reg
| 0x8);
376 snd_soc_write(codec
, WM8731_APDIGI
, mute_reg
);
380 static int wm8731_set_dai_sysclk(struct snd_soc_dai
*codec_dai
,
381 int clk_id
, unsigned int freq
, int dir
)
383 struct snd_soc_codec
*codec
= codec_dai
->codec
;
384 struct wm8731_priv
*wm8731
= snd_soc_codec_get_drvdata(codec
);
387 case WM8731_SYSCLK_XTAL
:
388 case WM8731_SYSCLK_MCLK
:
389 wm8731
->sysclk_type
= clk_id
;
397 wm8731
->constraints
= NULL
;
400 wm8731
->constraints
= &wm8731_constraints_12000000
;
404 wm8731
->constraints
= &wm8731_constraints_12288000_18432000
;
408 wm8731
->constraints
= &wm8731_constraints_11289600_16934400
;
414 wm8731
->sysclk
= freq
;
416 snd_soc_dapm_sync(&codec
->dapm
);
422 static int wm8731_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
425 struct snd_soc_codec
*codec
= codec_dai
->codec
;
428 /* set master/slave audio interface */
429 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
430 case SND_SOC_DAIFMT_CBM_CFM
:
433 case SND_SOC_DAIFMT_CBS_CFS
:
439 /* interface format */
440 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
441 case SND_SOC_DAIFMT_I2S
:
444 case SND_SOC_DAIFMT_RIGHT_J
:
446 case SND_SOC_DAIFMT_LEFT_J
:
449 case SND_SOC_DAIFMT_DSP_A
:
452 case SND_SOC_DAIFMT_DSP_B
:
459 /* clock inversion */
460 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
461 case SND_SOC_DAIFMT_NB_NF
:
463 case SND_SOC_DAIFMT_IB_IF
:
466 case SND_SOC_DAIFMT_IB_NF
:
469 case SND_SOC_DAIFMT_NB_IF
:
477 snd_soc_write(codec
, WM8731_IFACE
, iface
);
481 static int wm8731_set_bias_level(struct snd_soc_codec
*codec
,
482 enum snd_soc_bias_level level
)
484 struct wm8731_priv
*wm8731
= snd_soc_codec_get_drvdata(codec
);
489 case SND_SOC_BIAS_ON
:
491 case SND_SOC_BIAS_PREPARE
:
493 case SND_SOC_BIAS_STANDBY
:
494 if (codec
->dapm
.bias_level
== SND_SOC_BIAS_OFF
) {
495 ret
= regulator_bulk_enable(ARRAY_SIZE(wm8731
->supplies
),
500 regcache_sync(wm8731
->regmap
);
503 /* Clear PWROFF, gate CLKOUT, everything else as-is */
504 reg
= snd_soc_read(codec
, WM8731_PWR
) & 0xff7f;
505 snd_soc_write(codec
, WM8731_PWR
, reg
| 0x0040);
507 case SND_SOC_BIAS_OFF
:
508 snd_soc_write(codec
, WM8731_PWR
, 0xffff);
509 regulator_bulk_disable(ARRAY_SIZE(wm8731
->supplies
),
511 regcache_mark_dirty(wm8731
->regmap
);
514 codec
->dapm
.bias_level
= level
;
518 static int wm8731_startup(struct snd_pcm_substream
*substream
,
519 struct snd_soc_dai
*dai
)
521 struct wm8731_priv
*wm8731
= snd_soc_codec_get_drvdata(dai
->codec
);
523 if (wm8731
->constraints
)
524 snd_pcm_hw_constraint_list(substream
->runtime
, 0,
525 SNDRV_PCM_HW_PARAM_RATE
,
526 wm8731
->constraints
);
531 #define WM8731_RATES SNDRV_PCM_RATE_8000_96000
533 #define WM8731_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
534 SNDRV_PCM_FMTBIT_S24_LE)
536 static const struct snd_soc_dai_ops wm8731_dai_ops
= {
537 .startup
= wm8731_startup
,
538 .hw_params
= wm8731_hw_params
,
539 .digital_mute
= wm8731_mute
,
540 .set_sysclk
= wm8731_set_dai_sysclk
,
541 .set_fmt
= wm8731_set_dai_fmt
,
544 static struct snd_soc_dai_driver wm8731_dai
= {
545 .name
= "wm8731-hifi",
547 .stream_name
= "Playback",
550 .rates
= WM8731_RATES
,
551 .formats
= WM8731_FORMATS
,},
553 .stream_name
= "Capture",
556 .rates
= WM8731_RATES
,
557 .formats
= WM8731_FORMATS
,},
558 .ops
= &wm8731_dai_ops
,
559 .symmetric_rates
= 1,
563 static int wm8731_suspend(struct snd_soc_codec
*codec
)
565 wm8731_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
570 static int wm8731_resume(struct snd_soc_codec
*codec
)
572 wm8731_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
577 #define wm8731_suspend NULL
578 #define wm8731_resume NULL
581 static int wm8731_probe(struct snd_soc_codec
*codec
)
583 struct wm8731_priv
*wm8731
= snd_soc_codec_get_drvdata(codec
);
586 codec
->control_data
= wm8731
->regmap
;
587 ret
= snd_soc_codec_set_cache_io(codec
, 7, 9, SND_SOC_REGMAP
);
589 dev_err(codec
->dev
, "Failed to set cache I/O: %d\n", ret
);
593 for (i
= 0; i
< ARRAY_SIZE(wm8731
->supplies
); i
++)
594 wm8731
->supplies
[i
].supply
= wm8731_supply_names
[i
];
596 ret
= regulator_bulk_get(codec
->dev
, ARRAY_SIZE(wm8731
->supplies
),
599 dev_err(codec
->dev
, "Failed to request supplies: %d\n", ret
);
603 ret
= regulator_bulk_enable(ARRAY_SIZE(wm8731
->supplies
),
606 dev_err(codec
->dev
, "Failed to enable supplies: %d\n", ret
);
607 goto err_regulator_get
;
610 ret
= wm8731_reset(codec
);
612 dev_err(codec
->dev
, "Failed to issue reset: %d\n", ret
);
613 goto err_regulator_enable
;
616 wm8731_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
618 /* Latch the update bits */
619 snd_soc_update_bits(codec
, WM8731_LOUT1V
, 0x100, 0);
620 snd_soc_update_bits(codec
, WM8731_ROUT1V
, 0x100, 0);
621 snd_soc_update_bits(codec
, WM8731_LINVOL
, 0x100, 0);
622 snd_soc_update_bits(codec
, WM8731_RINVOL
, 0x100, 0);
624 /* Disable bypass path by default */
625 snd_soc_update_bits(codec
, WM8731_APANA
, 0x8, 0);
627 /* Regulators will have been enabled by bias management */
628 regulator_bulk_disable(ARRAY_SIZE(wm8731
->supplies
), wm8731
->supplies
);
632 err_regulator_enable
:
633 regulator_bulk_disable(ARRAY_SIZE(wm8731
->supplies
), wm8731
->supplies
);
635 regulator_bulk_free(ARRAY_SIZE(wm8731
->supplies
), wm8731
->supplies
);
640 /* power down chip */
641 static int wm8731_remove(struct snd_soc_codec
*codec
)
643 struct wm8731_priv
*wm8731
= snd_soc_codec_get_drvdata(codec
);
645 wm8731_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
647 regulator_bulk_disable(ARRAY_SIZE(wm8731
->supplies
), wm8731
->supplies
);
648 regulator_bulk_free(ARRAY_SIZE(wm8731
->supplies
), wm8731
->supplies
);
653 static struct snd_soc_codec_driver soc_codec_dev_wm8731
= {
654 .probe
= wm8731_probe
,
655 .remove
= wm8731_remove
,
656 .suspend
= wm8731_suspend
,
657 .resume
= wm8731_resume
,
658 .set_bias_level
= wm8731_set_bias_level
,
659 .dapm_widgets
= wm8731_dapm_widgets
,
660 .num_dapm_widgets
= ARRAY_SIZE(wm8731_dapm_widgets
),
661 .dapm_routes
= wm8731_intercon
,
662 .num_dapm_routes
= ARRAY_SIZE(wm8731_intercon
),
663 .controls
= wm8731_snd_controls
,
664 .num_controls
= ARRAY_SIZE(wm8731_snd_controls
),
667 static const struct of_device_id wm8731_of_match
[] = {
668 { .compatible
= "wlf,wm8731", },
672 MODULE_DEVICE_TABLE(of
, wm8731_of_match
);
674 static const struct regmap_config wm8731_regmap
= {
678 .max_register
= WM8731_RESET
,
679 .volatile_reg
= wm8731_volatile
,
680 .writeable_reg
= wm8731_writeable
,
682 .cache_type
= REGCACHE_RBTREE
,
683 .reg_defaults
= wm8731_reg_defaults
,
684 .num_reg_defaults
= ARRAY_SIZE(wm8731_reg_defaults
),
687 #if defined(CONFIG_SPI_MASTER)
688 static int wm8731_spi_probe(struct spi_device
*spi
)
690 struct wm8731_priv
*wm8731
;
693 wm8731
= devm_kzalloc(&spi
->dev
, sizeof(struct wm8731_priv
),
698 wm8731
->regmap
= devm_regmap_init_spi(spi
, &wm8731_regmap
);
699 if (IS_ERR(wm8731
->regmap
)) {
700 ret
= PTR_ERR(wm8731
->regmap
);
701 dev_err(&spi
->dev
, "Failed to allocate register map: %d\n",
706 spi_set_drvdata(spi
, wm8731
);
708 ret
= snd_soc_register_codec(&spi
->dev
,
709 &soc_codec_dev_wm8731
, &wm8731_dai
, 1);
711 dev_err(&spi
->dev
, "Failed to register CODEC: %d\n", ret
);
718 static int wm8731_spi_remove(struct spi_device
*spi
)
720 snd_soc_unregister_codec(&spi
->dev
);
724 static struct spi_driver wm8731_spi_driver
= {
727 .owner
= THIS_MODULE
,
728 .of_match_table
= wm8731_of_match
,
730 .probe
= wm8731_spi_probe
,
731 .remove
= wm8731_spi_remove
,
733 #endif /* CONFIG_SPI_MASTER */
735 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
736 static int wm8731_i2c_probe(struct i2c_client
*i2c
,
737 const struct i2c_device_id
*id
)
739 struct wm8731_priv
*wm8731
;
742 wm8731
= devm_kzalloc(&i2c
->dev
, sizeof(struct wm8731_priv
),
747 wm8731
->regmap
= devm_regmap_init_i2c(i2c
, &wm8731_regmap
);
748 if (IS_ERR(wm8731
->regmap
)) {
749 ret
= PTR_ERR(wm8731
->regmap
);
750 dev_err(&i2c
->dev
, "Failed to allocate register map: %d\n",
755 i2c_set_clientdata(i2c
, wm8731
);
757 ret
= snd_soc_register_codec(&i2c
->dev
,
758 &soc_codec_dev_wm8731
, &wm8731_dai
, 1);
760 dev_err(&i2c
->dev
, "Failed to register CODEC: %d\n", ret
);
767 static int wm8731_i2c_remove(struct i2c_client
*client
)
769 snd_soc_unregister_codec(&client
->dev
);
773 static const struct i2c_device_id wm8731_i2c_id
[] = {
777 MODULE_DEVICE_TABLE(i2c
, wm8731_i2c_id
);
779 static struct i2c_driver wm8731_i2c_driver
= {
782 .owner
= THIS_MODULE
,
783 .of_match_table
= wm8731_of_match
,
785 .probe
= wm8731_i2c_probe
,
786 .remove
= wm8731_i2c_remove
,
787 .id_table
= wm8731_i2c_id
,
791 static int __init
wm8731_modinit(void)
794 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
795 ret
= i2c_add_driver(&wm8731_i2c_driver
);
797 printk(KERN_ERR
"Failed to register WM8731 I2C driver: %d\n",
801 #if defined(CONFIG_SPI_MASTER)
802 ret
= spi_register_driver(&wm8731_spi_driver
);
804 printk(KERN_ERR
"Failed to register WM8731 SPI driver: %d\n",
810 module_init(wm8731_modinit
);
812 static void __exit
wm8731_exit(void)
814 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
815 i2c_del_driver(&wm8731_i2c_driver
);
817 #if defined(CONFIG_SPI_MASTER)
818 spi_unregister_driver(&wm8731_spi_driver
);
821 module_exit(wm8731_exit
);
823 MODULE_DESCRIPTION("ASoC WM8731 driver");
824 MODULE_AUTHOR("Richard Purdie");
825 MODULE_LICENSE("GPL");