14 #include <linux/module.h>
19 #include <linux/i2c.h>
23 #include <linux/slab.h>
34 #define WM8741_NUM_SUPPLIES 2
40 #define WM8741_NUM_RATES 6
50 static const struct reg_default wm8741_reg_defaults[] = {
63 static bool wm8741_readable(
struct device *
dev,
unsigned int reg)
107 {
"VOUTLP",
NULL,
"DACL" },
108 {
"VOUTLN",
NULL,
"DACL" },
109 {
"VOUTRP",
NULL,
"DACR" },
110 {
"VOUTRN",
NULL,
"DACR" },
125 static unsigned int rates_11289[] = {
134 static unsigned int rates_12288[] = {
143 static unsigned int rates_16384[] = {
152 static unsigned int rates_16934[] = {
161 static unsigned int rates_18432[] = {
170 static unsigned int rates_22579[] = {
171 44100, 88235, 1764000
179 static unsigned int rates_24576[] = {
180 32000, 48000, 96000, 192000
188 static unsigned int rates_36864[] = {
202 struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec);
209 "No MCLK configured, call set_sysclk() on init\n");
225 struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec);
230 for (i = 0; i <
ARRAY_SIZE(lrclk_ratios); i++) {
232 lrclk_ratios[
i].ratio)
238 dev_err(codec->
dev,
"MCLK/fs ratio %d unsupported\n",
257 dev_dbg(codec->
dev,
"wm8741_hw_params: Unsupported bit size param = %d",
262 dev_dbg(codec->
dev,
"wm8741_hw_params: bit size param = %d",
269 static int wm8741_set_dai_sysclk(
struct snd_soc_dai *codec_dai,
270 int clk_id,
unsigned int freq,
int dir)
273 struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec);
275 dev_dbg(codec->
dev,
"wm8741_set_dai_sysclk info: freq=%dHz\n", freq);
322 static int wm8741_set_dai_fmt(
struct snd_soc_dai *codec_dai,
374 dev_dbg(codec->
dev,
"wm8741_set_dai_fmt: Format=%x, Clock Inv=%x\n",
375 fmt & SND_SOC_DAIFMT_FORMAT_MASK,
376 ((fmt & SND_SOC_DAIFMT_INV_MASK)));
382 #define WM8741_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
383 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | \
384 SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 | \
385 SNDRV_PCM_RATE_192000)
387 #define WM8741_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
388 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
391 .startup = wm8741_startup,
392 .hw_params = wm8741_hw_params,
393 .set_sysclk = wm8741_set_dai_sysclk,
394 .set_fmt = wm8741_set_dai_fmt,
400 .stream_name =
"Playback",
406 .ops = &wm8741_dai_ops,
416 #define wm8741_suspend NULL
417 #define wm8741_resume NULL
422 struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec);
428 dev_err(codec->
dev,
"Failed to enable supplies: %d\n", ret);
434 dev_err(codec->
dev,
"Failed to set cache I/O: %d\n", ret);
438 ret = wm8741_reset(codec);
440 dev_err(codec->
dev,
"Failed to issue reset\n");
454 dev_dbg(codec->
dev,
"Successful registration\n");
465 struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec);
473 .probe = wm8741_probe,
474 .remove = wm8741_remove,
477 .controls = wm8741_snd_controls,
478 .num_controls =
ARRAY_SIZE(wm8741_snd_controls),
479 .dapm_widgets = wm8741_dapm_widgets,
480 .num_dapm_widgets =
ARRAY_SIZE(wm8741_dapm_widgets),
481 .dapm_routes = wm8741_dapm_routes,
482 .num_dapm_routes =
ARRAY_SIZE(wm8741_dapm_routes),
486 { .compatible =
"wlf,wm8741", },
491 static const struct regmap_config wm8741_regmap = {
496 .reg_defaults = wm8741_reg_defaults,
497 .num_reg_defaults =
ARRAY_SIZE(wm8741_reg_defaults),
500 .readable_reg = wm8741_readable,
503 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
504 static int wm8741_i2c_probe(
struct i2c_client *i2c,
516 wm8741->
supplies[i].supply = wm8741_supply_names[i];
521 dev_err(&i2c->
dev,
"Failed to request supplies: %d\n", ret);
526 if (IS_ERR(wm8741->
regmap)) {
527 ret = PTR_ERR(wm8741->
regmap);
528 dev_err(&i2c->
dev,
"Failed to init regmap: %d\n", ret);
532 i2c_set_clientdata(i2c, wm8741);
535 &soc_codec_dev_wm8741, &wm8741_dai, 1);
552 static struct i2c_driver wm8741_i2c_driver = {
556 .of_match_table = wm8741_of_match,
558 .probe = wm8741_i2c_probe,
559 .remove = wm8741_i2c_remove,
560 .id_table = wm8741_i2c_id,
564 #if defined(CONFIG_SPI_MASTER)
576 wm8741->
supplies[i].supply = wm8741_supply_names[i];
581 dev_err(&spi->
dev,
"Failed to request supplies: %d\n", ret);
586 if (IS_ERR(wm8741->
regmap)) {
587 ret = PTR_ERR(wm8741->
regmap);
588 dev_err(&spi->
dev,
"Failed to init regmap: %d\n", ret);
592 spi_set_drvdata(spi, wm8741);
595 &soc_codec_dev_wm8741, &wm8741_dai, 1);
605 static struct spi_driver wm8741_spi_driver = {
609 .of_match_table = wm8741_of_match,
611 .probe = wm8741_spi_probe,
616 static int __init wm8741_modinit(
void)
620 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
621 ret = i2c_add_driver(&wm8741_i2c_driver);
623 pr_err(
"Failed to register WM8741 I2C driver: %d\n", ret);
625 #if defined(CONFIG_SPI_MASTER)
637 static void __exit wm8741_exit(
void)
639 #if defined(CONFIG_SPI_MASTER)
640 spi_unregister_driver(&wm8741_spi_driver);
642 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)