13 #include <linux/module.h>
18 #include <linux/i2c.h>
22 #include <linux/slab.h>
34 #define WM8737_NUM_SUPPLIES 4
49 static const struct reg_default wm8737_reg_defaults[] = {
67 static bool wm8737_volatile(
struct device *
dev,
unsigned int reg)
82 static const unsigned int micboost_tlv[] = {
95 static const char *micbias_enum_text[] = {
102 static const struct soc_enum micbias_enum =
105 static const char *low_cutoff_text[] = {
109 static const struct soc_enum low_3d =
112 static const char *high_cutoff_text[] = {
116 static const struct soc_enum high_3d =
119 static const char *alc_fn_text[] = {
120 "Disabled",
"Right",
"Left",
"Stereo"
123 static const struct soc_enum alc_fn =
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 =
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 =
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 =
153 6, 3, 0, micboost_tlv),
166 SOC_ENUM(
"Mic PGA Bias", micbias_enum),
174 SOC_ENUM(
"3D High Cut-off", low_3d),
184 SOC_ENUM(
"ALC Hold Time", alc_hold),
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 =
201 static const char *rinsel_text[] = {
202 "RINPUT1",
"RINPUT2",
"RINPUT3",
"RINPUT1 DC",
205 static const struct soc_enum rinsel_enum =
211 static const char *bypass_text[] = {
215 static const struct soc_enum lbypass_enum =
222 static const struct soc_enum rbypass_enum =
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" },
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 },
344 struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec);
353 if (coeff_div[i].
mclk == wm8737->
mclk)
356 if (coeff_div[i].
mclk == wm8737->
mclk * 2) {
363 dev_err(codec->
dev,
"%dHz MCLK can't support %dHz\n",
394 static int wm8737_set_dai_sysclk(
struct snd_soc_dai *codec_dai,
395 int clk_id,
unsigned int freq,
int dir)
398 struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec);
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,
466 static int wm8737_set_bias_level(
struct snd_soc_codec *codec,
469 struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec);
488 "Failed to enable supplies: %d\n",
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)
534 .hw_params = wm8737_hw_params,
535 .set_sysclk = wm8737_set_dai_sysclk,
536 .set_fmt = wm8737_set_dai_fmt,
542 .stream_name =
"Capture",
548 .ops = &wm8737_dai_ops,
564 #define wm8737_suspend NULL
565 #define wm8737_resume NULL
570 struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec);
575 dev_err(codec->
dev,
"Failed to set cache I/O: %d\n", ret);
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");
604 wm8737_add_widgets(codec);
621 .probe = wm8737_probe,
622 .remove = wm8737_remove,
625 .set_bias_level = wm8737_set_bias_level,
629 { .compatible =
"wlf,wm8737", },
635 static const struct regmap_config wm8737_regmap = {
640 .reg_defaults = wm8737_reg_defaults,
641 .num_reg_defaults =
ARRAY_SIZE(wm8737_reg_defaults),
644 .volatile_reg = wm8737_volatile,
647 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
660 wm8737->
supplies[i].supply = wm8737_supply_names[i];
665 dev_err(&i2c->
dev,
"Failed to request supplies: %d\n", ret);
670 if (IS_ERR(wm8737->
regmap))
671 return PTR_ERR(wm8737->
regmap);
673 i2c_set_clientdata(i2c, wm8737);
676 &soc_codec_dev_wm8737, &wm8737_dai, 1);
695 static struct i2c_driver wm8737_i2c_driver = {
699 .of_match_table = wm8737_of_match,
701 .probe = wm8737_i2c_probe,
703 .id_table = wm8737_i2c_id,
707 #if defined(CONFIG_SPI_MASTER)
719 wm8737->
supplies[i].supply = wm8737_supply_names[i];
724 dev_err(&spi->
dev,
"Failed to request supplies: %d\n", ret);
729 if (IS_ERR(wm8737->
regmap))
730 return PTR_ERR(wm8737->
regmap);
732 spi_set_drvdata(spi, wm8737);
735 &soc_codec_dev_wm8737, &wm8737_dai, 1);
747 static struct spi_driver wm8737_spi_driver = {
751 .of_match_table = wm8737_of_match,
753 .probe = wm8737_spi_probe,
758 static int __init wm8737_modinit(
void)
761 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
762 ret = i2c_add_driver(&wm8737_i2c_driver);
768 #if defined(CONFIG_SPI_MASTER)
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)