16 #include <linux/module.h>
21 #include <linux/i2c.h>
23 #include <linux/slab.h>
33 #define WM8961_MAX_REGISTER 0xFC
35 static const struct reg_default wm8961_reg_defaults[] = {
113 static bool wm8961_volatile(
struct device *
dev,
unsigned int reg)
126 static bool wm8961_readable(
struct device *
dev,
unsigned int reg)
236 }
while (--timeout &&
243 dev_dbg(codec->
dev,
"DC servo startup complete\n");
278 dev_dbg(codec->
dev,
"Disabling charge pump\n");
293 if (event & SND_SOC_DAPM_POST_PMU) {
316 static const char *adc_hpf_text[] = {
317 "Hi-fi",
"Voice 1",
"Voice 2",
"Voice 3",
320 static const struct soc_enum adc_hpf =
323 static const char *dac_deemph_text[] = {
324 "None",
"32kHz",
"44.1kHz",
"48kHz",
327 static const struct soc_enum dac_deemph =
334 static unsigned int boost_tlv[] = {
347 6, 3, 7, 0, hp_sec_tlv),
358 SOC_ENUM(
"DAC Deemphasis", dac_deemph),
365 SOC_ENUM(
"ADC High Pass Filter Mode", adc_hpf),
384 static const char *sidetone_text[] = {
385 "None",
"Left",
"Right"
388 static const struct soc_enum dacl_sidetone =
391 static const struct soc_enum dacr_sidetone =
422 4, 0,
NULL, 0, wm8961_hp_event,
425 4, 0,
NULL, 0, wm8961_spk_event,
438 {
"DACL",
NULL,
"CLK_DSP" },
439 {
"DACL",
NULL,
"DACL Sidetone" },
440 {
"DACR",
NULL,
"CLK_DSP" },
441 {
"DACR",
NULL,
"DACR Sidetone" },
443 {
"DACL Sidetone",
"Left",
"ADCL" },
444 {
"DACL Sidetone",
"Right",
"ADCR" },
446 {
"DACR Sidetone",
"Left",
"ADCL" },
447 {
"DACR Sidetone",
"Right",
"ADCR" },
449 {
"HP_L",
NULL,
"Headphone Output" },
450 {
"HP_R",
NULL,
"Headphone Output" },
451 {
"Headphone Output",
NULL,
"DACL" },
452 {
"Headphone Output",
NULL,
"DACR" },
454 {
"SPK_LN",
NULL,
"Speaker Output" },
455 {
"SPK_LP",
NULL,
"Speaker Output" },
456 {
"SPK_RN",
NULL,
"Speaker Output" },
457 {
"SPK_RP",
NULL,
"Speaker Output" },
459 {
"Speaker Output",
NULL,
"DACL" },
460 {
"Speaker Output",
NULL,
"DACR" },
462 {
"ADCL",
NULL,
"Left Input" },
463 {
"ADCL",
NULL,
"CLK_DSP" },
464 {
"ADCR",
NULL,
"Right Input" },
465 {
"ADCR",
NULL,
"CLK_DSP" },
467 {
"Left Input",
NULL,
"LINPUT" },
468 {
"Right Input",
NULL,
"RINPUT" },
476 } wm8961_clk_sys_ratio[] = {
510 struct wm8961_priv *wm8961 = snd_soc_codec_get_drvdata(codec);
517 dev_err(codec->
dev,
"MCLK has not been specified\n");
523 for (i = 0; i <
ARRAY_SIZE(wm8961_srate); i++) {
524 if (
abs(wm8961_srate[i].
rate - fs) <
525 abs(wm8961_srate[best].
rate - fs))
530 reg |= wm8961_srate[best].val;
532 dev_dbg(codec->
dev,
"Selected SRATE %dHz for %dHz\n",
533 wm8961_srate[best].rate, fs);
540 "SYSCLK must be at least 64*fs for DAC\n");
545 "SYSCLK must be at least 256*fs for ADC\n");
549 for (i = 0; i <
ARRAY_SIZE(wm8961_clk_sys_ratio); i++) {
550 if (wm8961_clk_sys_ratio[i].
ratio >= target)
554 dev_err(codec->
dev,
"Unable to generate CLK_SYS_RATE\n");
557 dev_dbg(codec->
dev,
"Selected CLK_SYS_RATE of %d for %d/%d=%d\n",
558 wm8961_clk_sys_ratio[i].ratio, wm8961->
sysclk, fs,
596 static int wm8961_set_sysclk(
struct snd_soc_dai *dai,
int clk_id,
601 struct wm8961_priv *wm8961 = snd_soc_codec_get_drvdata(codec);
604 if (freq > 33000000) {
609 if (freq > 16500000) {
610 dev_dbg(codec->
dev,
"Using MCLK/2 for %dHz MCLK\n", freq);
614 dev_dbg(codec->
dev,
"Using MCLK/1 for %dHz MCLK\n", freq);
625 static int wm8961_set_fmt(
struct snd_soc_dai *dai,
unsigned int fmt)
719 static int wm8961_set_clkdiv(
struct snd_soc_dai *dai,
int div_id,
int div)
746 static int wm8961_set_bias_level(
struct snd_soc_codec *codec,
804 #define WM8961_RATES SNDRV_PCM_RATE_8000_48000
806 #define WM8961_FORMATS \
807 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
808 SNDRV_PCM_FMTBIT_S24_LE)
811 .hw_params = wm8961_hw_params,
812 .set_sysclk = wm8961_set_sysclk,
813 .set_fmt = wm8961_set_fmt,
814 .digital_mute = wm8961_digital_mute,
815 .set_tristate = wm8961_set_tristate,
816 .set_clkdiv = wm8961_set_clkdiv,
820 .name =
"wm8961-hifi",
822 .stream_name =
"HiFi Playback",
828 .stream_name =
"HiFi Capture",
833 .ops = &wm8961_dai_ops,
844 dev_err(codec->
dev,
"Failed to set cache I/O: %d\n", ret);
915 #define wm8961_suspend NULL
916 #define wm8961_resume NULL
920 .probe = wm8961_probe,
921 .remove = wm8961_remove,
924 .set_bias_level = wm8961_set_bias_level,
927 static const struct regmap_config wm8961_regmap = {
932 .reg_defaults = wm8961_reg_defaults,
933 .num_reg_defaults =
ARRAY_SIZE(wm8961_reg_defaults),
936 .volatile_reg = wm8961_volatile,
937 .readable_reg = wm8961_readable,
953 if (IS_ERR(wm8961->
regmap))
954 return PTR_ERR(wm8961->
regmap);
958 dev_err(&i2c->
dev,
"Failed to read chip ID: %d\n", ret);
963 dev_err(&i2c->
dev,
"Device is not a WM8961: ID=0x%x\n", val);
973 dev_err(&i2c->
dev,
"Failed to read chip revision: %d\n", ret);
977 dev_info(&i2c->
dev,
"WM8961 family %d revision %c\n",
984 dev_err(&i2c->
dev,
"Failed to issue reset: %d\n", ret);
988 i2c_set_clientdata(i2c, wm8961);
991 &soc_codec_dev_wm8961, &wm8961_dai, 1);
1009 static struct i2c_driver wm8961_i2c_driver = {
1014 .probe = wm8961_i2c_probe,
1016 .id_table = wm8961_i2c_id,