16 #include <linux/module.h>
21 #include <linux/i2c.h>
22 #include <linux/slab.h>
36 #define WM8731_NUM_SUPPLIES 4
58 static const struct reg_default wm8731_reg_defaults[] = {
71 static bool wm8731_volatile(
struct device *
dev,
unsigned int reg)
76 static bool wm8731_writeable(
struct device *
dev,
unsigned int reg)
81 #define wm8731_reset(c) snd_soc_write(c, WM8731_RESET, 0)
83 static const char *wm8731_input_select[] = {
"Line In",
"Mic"};
85 static const struct soc_enum wm8731_insel_enum =
88 static int wm8731_deemph[] = { 0, 32000, 44100, 48000 };
92 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
100 for (i = 2; i <
ARRAY_SIZE(wm8731_deemph); i++) {
112 dev_dbg(codec->
dev,
"Set deemphasis %d (%dHz)\n",
113 best, wm8731_deemph[best]);
118 static int wm8731_get_deemph(
struct snd_kcontrol *kcontrol,
122 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
124 ucontrol->
value.enumerated.item[0] = wm8731->
deemph;
129 static int wm8731_put_deemph(
struct snd_kcontrol *kcontrol,
133 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
141 if (wm8731->
deemph != deemph) {
144 wm8731_set_deemph(codec);
179 wm8731_get_deemph, wm8731_put_deemph),
197 &wm8731_output_mixer_controls[0],
222 {
"DAC",
NULL,
"OSC", wm8731_check_osc},
223 {
"ADC",
NULL,
"OSC", wm8731_check_osc},
224 {
"DAC",
NULL,
"ACTIVE"},
225 {
"ADC",
NULL,
"ACTIVE"},
228 {
"Output Mixer",
"Line Bypass Switch",
"Line Input"},
229 {
"Output Mixer",
"HiFi Playback Switch",
"DAC"},
230 {
"Output Mixer",
"Mic Sidetone Switch",
"Mic Bias"},
233 {
"RHPOUT",
NULL,
"Output Mixer"},
234 {
"ROUT",
NULL,
"Output Mixer"},
235 {
"LHPOUT",
NULL,
"Output Mixer"},
236 {
"LOUT",
NULL,
"Output Mixer"},
239 {
"Input Mux",
"Line In",
"Line Input"},
240 {
"Input Mux",
"Mic",
"Mic Bias"},
241 {
"ADC",
NULL,
"Input Mux"},
244 {
"Line Input",
NULL,
"LLINEIN"},
245 {
"Line Input",
NULL,
"RLINEIN"},
246 {
"Mic Bias",
NULL,
"MICIN"},
259 static const struct _coeff_div coeff_div[] = {
261 {12288000, 48000, 256, 0x0, 0x0, 0x0},
262 {18432000, 48000, 384, 0x0, 0x1, 0x0},
263 {12000000, 48000, 250, 0x0, 0x0, 0x1},
266 {12288000, 32000, 384, 0x6, 0x0, 0x0},
267 {18432000, 32000, 576, 0x6, 0x1, 0x0},
268 {12000000, 32000, 375, 0x6, 0x0, 0x1},
271 {12288000, 8000, 1536, 0x3, 0x0, 0x0},
272 {18432000, 8000, 2304, 0x3, 0x1, 0x0},
273 {11289600, 8000, 1408, 0xb, 0x0, 0x0},
274 {16934400, 8000, 2112, 0xb, 0x1, 0x0},
275 {12000000, 8000, 1500, 0x3, 0x0, 0x1},
278 {12288000, 96000, 128, 0x7, 0x0, 0x0},
279 {18432000, 96000, 192, 0x7, 0x1, 0x0},
280 {12000000, 96000, 125, 0x7, 0x0, 0x1},
283 {11289600, 44100, 256, 0x8, 0x0, 0x0},
284 {16934400, 44100, 384, 0x8, 0x1, 0x0},
285 {12000000, 44100, 272, 0x8, 0x1, 0x1},
288 {11289600, 88200, 128, 0xf, 0x0, 0x0},
289 {16934400, 88200, 192, 0xf, 0x1, 0x0},
290 {12000000, 88200, 136, 0xf, 0x1, 0x1},
293 static inline int get_coeff(
int mclk,
int rate)
298 if (coeff_div[i].rate == rate && coeff_div[i].mclk == mclk)
309 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
312 u16 srate = (coeff_div[
i].
sr << 2) |
313 (coeff_div[i].bosr << 1) | coeff_div[
i].
usb;
331 wm8731_set_deemph(codec);
349 static int wm8731_set_dai_sysclk(
struct snd_soc_dai *codec_dai,
350 int clk_id,
unsigned int freq,
int dir)
353 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
382 static int wm8731_set_dai_fmt(
struct snd_soc_dai *codec_dai,
441 static int wm8731_set_bias_level(
struct snd_soc_codec *codec,
444 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
478 #define WM8731_RATES SNDRV_PCM_RATE_8000_96000
480 #define WM8731_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
481 SNDRV_PCM_FMTBIT_S24_LE)
484 .hw_params = wm8731_hw_params,
485 .digital_mute = wm8731_mute,
486 .set_sysclk = wm8731_set_dai_sysclk,
487 .set_fmt = wm8731_set_dai_fmt,
491 .name =
"wm8731-hifi",
493 .stream_name =
"Playback",
499 .stream_name =
"Capture",
504 .ops = &wm8731_dai_ops,
505 .symmetric_rates = 1,
523 #define wm8731_suspend NULL
524 #define wm8731_resume NULL
529 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
535 dev_err(codec->
dev,
"Failed to set cache I/O: %d\n", ret);
540 wm8731->
supplies[i].supply = wm8731_supply_names[i];
545 dev_err(codec->
dev,
"Failed to request supplies: %d\n", ret);
552 dev_err(codec->
dev,
"Failed to enable supplies: %d\n", ret);
553 goto err_regulator_get;
558 dev_err(codec->
dev,
"Failed to issue reset: %d\n", ret);
559 goto err_regulator_enable;
578 err_regulator_enable:
589 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
600 .probe = wm8731_probe,
601 .remove = wm8731_remove,
604 .set_bias_level = wm8731_set_bias_level,
605 .dapm_widgets = wm8731_dapm_widgets,
606 .num_dapm_widgets =
ARRAY_SIZE(wm8731_dapm_widgets),
607 .dapm_routes = wm8731_intercon,
608 .num_dapm_routes =
ARRAY_SIZE(wm8731_intercon),
609 .controls = wm8731_snd_controls,
610 .num_controls =
ARRAY_SIZE(wm8731_snd_controls),
614 { .compatible =
"wlf,wm8731", },
620 static const struct regmap_config wm8731_regmap = {
625 .volatile_reg = wm8731_volatile,
626 .writeable_reg = wm8731_writeable,
629 .reg_defaults = wm8731_reg_defaults,
630 .num_reg_defaults =
ARRAY_SIZE(wm8731_reg_defaults),
633 #if defined(CONFIG_SPI_MASTER)
645 if (IS_ERR(wm8731->
regmap)) {
646 ret = PTR_ERR(wm8731->
regmap);
647 dev_err(&spi->
dev,
"Failed to allocate register map: %d\n",
652 spi_set_drvdata(spi, wm8731);
655 &soc_codec_dev_wm8731, &wm8731_dai, 1);
657 dev_err(&spi->
dev,
"Failed to register CODEC: %d\n", ret);
670 static struct spi_driver wm8731_spi_driver = {
674 .of_match_table = wm8731_of_match,
676 .probe = wm8731_spi_probe,
681 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
694 if (IS_ERR(wm8731->
regmap)) {
695 ret = PTR_ERR(wm8731->
regmap);
696 dev_err(&i2c->
dev,
"Failed to allocate register map: %d\n",
701 i2c_set_clientdata(i2c, wm8731);
704 &soc_codec_dev_wm8731, &wm8731_dai, 1);
706 dev_err(&i2c->
dev,
"Failed to register CODEC: %d\n", ret);
725 static struct i2c_driver wm8731_i2c_driver = {
729 .of_match_table = wm8731_of_match,
731 .probe = wm8731_i2c_probe,
733 .id_table = wm8731_i2c_id,
737 static int __init wm8731_modinit(
void)
740 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
741 ret = i2c_add_driver(&wm8731_i2c_driver);
747 #if defined(CONFIG_SPI_MASTER)
758 static void __exit wm8731_exit(
void)
760 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
763 #if defined(CONFIG_SPI_MASTER)
764 spi_unregister_driver(&wm8731_spi_driver);