14 #include <linux/module.h>
19 #include <linux/i2c.h>
22 #include <linux/slab.h>
33 #define WM8523_NUM_SUPPLIES 2
39 #define WM8523_NUM_RATES 7
50 static const struct reg_default wm8523_reg_defaults[] = {
60 static bool wm8523_volatile_register(
struct device *
dev,
unsigned int reg)
73 static const char *wm8523_zd_count_text[] = {
78 static const struct soc_enum wm8523_zc_count =
89 SOC_ENUM(
"Zero Detect Count", wm8523_zc_count),
99 {
"LINEVOUTL",
NULL,
"DAC" },
100 {
"LINEVOUTR",
NULL,
"DAC" },
120 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
127 "No MCLK configured, call set_sysclk() on init\n");
143 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
149 for (i = 0; i <
ARRAY_SIZE(lrclk_ratios); i++) {
151 lrclk_ratios[
i].ratio)
157 dev_err(codec->
dev,
"MCLK/fs ratio %d unsupported\n",
163 aifctrl2 |= lrclk_ratios[
i].value;
186 static int wm8523_set_dai_sysclk(
struct snd_soc_dai *codec_dai,
187 int clk_id,
unsigned int freq,
int dir)
190 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
197 for (i = 0; i <
ARRAY_SIZE(lrclk_ratios); i++) {
198 val = freq / lrclk_ratios[
i].ratio;
216 dev_dbg(codec->
dev,
"Supported sample rate: %dHz\n",
222 dev_dbg(codec->
dev,
"Skipping sample rate: %dHz\n",
235 static int wm8523_set_dai_fmt(
struct snd_soc_dai *codec_dai,
294 static int wm8523_set_bias_level(
struct snd_soc_codec *codec,
297 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
316 "Failed to enable supplies: %d\n",
351 #define WM8523_RATES SNDRV_PCM_RATE_8000_192000
353 #define WM8523_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
354 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
357 .startup = wm8523_startup,
358 .hw_params = wm8523_hw_params,
359 .set_sysclk = wm8523_set_dai_sysclk,
360 .set_fmt = wm8523_set_dai_fmt,
364 .name =
"wm8523-hifi",
366 .stream_name =
"Playback",
372 .ops = &wm8523_dai_ops,
388 #define wm8523_suspend NULL
389 #define wm8523_resume NULL
394 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
403 dev_err(codec->
dev,
"Failed to set cache I/O: %d\n", ret);
424 .probe = wm8523_probe,
425 .remove = wm8523_remove,
428 .set_bias_level = wm8523_set_bias_level,
430 .controls = wm8523_controls,
432 .dapm_widgets = wm8523_dapm_widgets,
433 .num_dapm_widgets =
ARRAY_SIZE(wm8523_dapm_widgets),
434 .dapm_routes = wm8523_dapm_routes,
435 .num_dapm_routes =
ARRAY_SIZE(wm8523_dapm_routes),
439 { .compatible =
"wlf,wm8523" },
443 static const struct regmap_config wm8523_regmap = {
448 .reg_defaults = wm8523_reg_defaults,
449 .num_reg_defaults =
ARRAY_SIZE(wm8523_reg_defaults),
452 .volatile_reg = wm8523_volatile_register,
455 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
469 if (IS_ERR(wm8523->
regmap)) {
470 ret = PTR_ERR(wm8523->
regmap);
471 dev_err(&i2c->
dev,
"Failed to create regmap: %d\n", ret);
476 wm8523->
supplies[i].supply = wm8523_supply_names[i];
481 dev_err(&i2c->
dev,
"Failed to request supplies: %d\n", ret);
488 dev_err(&i2c->
dev,
"Failed to enable supplies: %d\n", ret);
494 dev_err(&i2c->
dev,
"Failed to read ID register\n");
498 dev_err(&i2c->
dev,
"Device is not a WM8523, ID is %x\n", ret);
505 dev_err(&i2c->
dev,
"Failed to read revision register\n");
513 dev_err(&i2c->
dev,
"Failed to reset device: %d\n", ret);
519 i2c_set_clientdata(i2c, wm8523);
522 &soc_codec_dev_wm8523, &wm8523_dai, 1);
543 static struct i2c_driver wm8523_i2c_driver = {
547 .of_match_table = wm8523_of_match,
549 .probe = wm8523_i2c_probe,
551 .id_table = wm8523_i2c_id,
555 static int __init wm8523_modinit(
void)
558 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
559 ret = i2c_add_driver(&wm8523_i2c_driver);
569 static void __exit wm8523_exit(
void)
571 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)