16 #include <linux/module.h>
21 #include <linux/i2c.h>
25 #include <linux/slab.h>
35 #define WM8985_NUM_SUPPLIES 4
43 static const struct reg_default wm8985_reg_defaults[] = {
100 static bool wm8985_writeable(
struct device *
dev,
unsigned int reg)
168 static const int volume_update_regs[] = {
188 static const struct {
202 static const int srates[] = { 48000, 32000, 24000, 16000, 12000, 8000 };
204 static const int bclk_divs[] = {
228 static const char *alc_sel_text[] = {
"Off",
"Right",
"Left",
"Stereo" };
232 static const char *alc_mode_text[] = {
"ALC",
"Limiter" };
236 static const char *filter_mode_text[] = {
"Audio",
"Application" };
240 static const char *eq_bw_text[] = {
"Narrow",
"Wide" };
241 static const char *eqmode_text[] = {
"Capture",
"Playback" };
244 static const char *eq1_cutoff_text[] = {
245 "80Hz",
"105Hz",
"135Hz",
"175Hz"
249 static const char *eq2_cutoff_text[] = {
250 "230Hz",
"300Hz",
"385Hz",
"500Hz"
255 static const char *eq3_cutoff_text[] = {
256 "650Hz",
"850Hz",
"1.1kHz",
"1.4kHz"
261 static const char *eq4_cutoff_text[] = {
262 "1.8kHz",
"2.4kHz",
"3.2kHz",
"4.1kHz"
267 static const char *eq5_cutoff_text[] = {
268 "5.3kHz",
"6.9kHz",
"9kHz",
"11.7kHz"
273 static const char *speaker_mode_text[] = {
"Class A/B",
"Class D" };
276 static const char *depth_3d_text[] = {
301 SOC_ENUM(
"ALC Capture Function", alc_sel),
303 3, 7, 0, alc_max_tlv),
305 0, 7, 0, alc_min_tlv),
307 0, 15, 0, alc_tar_tlv),
326 8, 1, 0, pga_boost_tlv),
338 4, 7, 1, lim_thresh_tlv),
340 0, 12, 0, lim_boost_tlv),
360 SOC_ENUM(
"High Pass Filter Mode", filter_mode),
371 SOC_ENUM_EXT(
"Equalizer Function", eqmode, eqmode_get, eqmode_put),
388 SOC_ENUM(
"Speaker Mode", speaker_mode)
440 2, 0, left_out_mixer,
ARRAY_SIZE(left_out_mixer)),
442 3, 0, right_out_mixer,
ARRAY_SIZE(right_out_mixer)),
445 2, 0, left_input_mixer,
ARRAY_SIZE(left_input_mixer)),
447 3, 0, right_input_mixer,
ARRAY_SIZE(right_input_mixer)),
450 4, 0, left_boost_mixer,
ARRAY_SIZE(left_boost_mixer)),
452 5, 0, right_boost_mixer,
ARRAY_SIZE(right_boost_mixer)),
487 {
"Right Output Mixer",
"PCM Switch",
"Right DAC" },
488 {
"Right Output Mixer",
"Aux Switch",
"AUXR" },
489 {
"Right Output Mixer",
"Line Switch",
"Right Boost Mixer" },
491 {
"Left Output Mixer",
"PCM Switch",
"Left DAC" },
492 {
"Left Output Mixer",
"Aux Switch",
"AUXL" },
493 {
"Left Output Mixer",
"Line Switch",
"Left Boost Mixer" },
495 {
"Right Headphone Out",
NULL,
"Right Output Mixer" },
496 {
"HPR",
NULL,
"Right Headphone Out" },
498 {
"Left Headphone Out",
NULL,
"Left Output Mixer" },
499 {
"HPL",
NULL,
"Left Headphone Out" },
501 {
"Right Speaker Out",
NULL,
"Right Output Mixer" },
502 {
"SPKR",
NULL,
"Right Speaker Out" },
504 {
"Left Speaker Out",
NULL,
"Left Output Mixer" },
505 {
"SPKL",
NULL,
"Left Speaker Out" },
507 {
"Right ADC",
NULL,
"Right Boost Mixer" },
509 {
"Right Boost Mixer",
"AUXR Volume",
"AUXR" },
510 {
"Right Boost Mixer",
NULL,
"Right Capture PGA" },
511 {
"Right Boost Mixer",
"R2 Volume",
"R2" },
513 {
"Left ADC",
NULL,
"Left Boost Mixer" },
515 {
"Left Boost Mixer",
"AUXL Volume",
"AUXL" },
516 {
"Left Boost Mixer",
NULL,
"Left Capture PGA" },
517 {
"Left Boost Mixer",
"L2 Volume",
"L2" },
519 {
"Right Capture PGA",
NULL,
"Right Input Mixer" },
520 {
"Left Capture PGA",
NULL,
"Left Input Mixer" },
522 {
"Right Input Mixer",
"R2 Switch",
"R2" },
523 {
"Right Input Mixer",
"MicN Switch",
"RIN" },
524 {
"Right Input Mixer",
"MicP Switch",
"RIP" },
526 {
"Left Input Mixer",
"L2 Switch",
"L2" },
527 {
"Left Input Mixer",
"MicN Switch",
"LIN" },
528 {
"Left Input Mixer",
"MicP Switch",
"LIP" },
539 ucontrol->
value.integer.value[0] = 1;
541 ucontrol->
value.integer.value[0] = 0;
550 unsigned int regpwr2, regpwr3;
553 if (ucontrol->
value.integer.value[0] != 0
554 && ucontrol->
value.integer.value[0] != 1)
560 if (!ucontrol->
value.integer.value[0])
564 if (ucontrol->
value.integer.value[0])
581 ucontrol->
value.integer.value[0]
640 dev_err(dai->
dev,
"Unknown master/slave configuration\n");
648 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
677 dev_err(dai->
dev,
"Unknown polarity configuration\n");
700 wm8985 = snd_soc_codec_get_drvdata(codec);
703 if ((
int)wm8985->
bclk < 0)
720 dev_err(dai->
dev,
"Unsupported word length %u\n",
741 dev_dbg(dai->
dev,
"Selected SRATE = %d\n", srates[srate_idx]);
750 == fs_ratios[
i].ratio)
755 dev_err(dai->
dev,
"Unable to configure MCLK ratio %u/%u\n",
760 dev_dbg(dai->
dev,
"MCLK ratio = %dfs\n", fs_ratios[i].ratio);
765 tmp = (wm8985->
sysclk / fs_ratios[
i].div) * 10;
767 if (wm8985->
bclk == tmp / bclk_divs[i])
772 dev_err(dai->
dev,
"No matching BCLK divider found\n");
788 #define FIXED_PLL_SIZE ((1ULL << 24) * 10)
793 unsigned long int K, Ndiv, Nmod;
803 if (Ndiv < 6 || Ndiv > 12) {
805 " the recommended range: %lu\n", __func__, Ndiv);
815 K = Kpart & 0xffffffff;
824 static int wm8985_set_pll(
struct snd_soc_dai *dai,
int pll_id,
825 int source,
unsigned int freq_in,
826 unsigned int freq_out)
833 if (freq_in && freq_out) {
843 if (!freq_in || !freq_out)
863 static int wm8985_set_sysclk(
struct snd_soc_dai *dai,
864 int clk_id,
unsigned int freq,
int dir)
870 wm8985 = snd_soc_codec_get_drvdata(codec);
884 dev_err(dai->
dev,
"Unknown clock source %d\n", clk_id);
892 static int wm8985_set_bias_level(
struct snd_soc_codec *codec,
898 wm8985 = snd_soc_codec_get_drvdata(codec);
913 "Failed to enable supplies: %d\n",
985 #define wm8985_suspend NULL
986 #define wm8985_resume NULL
993 wm8985 = snd_soc_codec_get_drvdata(codec);
1005 wm8985 = snd_soc_codec_get_drvdata(codec);
1010 dev_err(codec->
dev,
"Failed to set cache i/o: %d\n", ret);
1015 wm8985->
supplies[i].supply = wm8985_supply_names[i];
1020 dev_err(codec->
dev,
"Failed to request supplies: %d\n", ret);
1027 dev_err(codec->
dev,
"Failed to enable supplies: %d\n", ret);
1031 ret = wm8985_reset(codec);
1033 dev_err(codec->
dev,
"Failed to issue reset: %d\n", ret);
1034 goto err_reg_enable;
1038 for (i = 0; i <
ARRAY_SIZE(volume_update_regs); ++
i)
1056 .digital_mute = wm8985_dac_mute,
1057 .hw_params = wm8985_hw_params,
1058 .set_fmt = wm8985_set_fmt,
1059 .set_sysclk = wm8985_set_sysclk,
1060 .set_pll = wm8985_set_pll
1063 #define WM8985_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
1064 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
1067 .name =
"wm8985-hifi",
1069 .stream_name =
"Playback",
1076 .stream_name =
"Capture",
1082 .ops = &wm8985_dai_ops,
1083 .symmetric_rates = 1
1087 .probe = wm8985_probe,
1088 .remove = wm8985_remove,
1091 .set_bias_level = wm8985_set_bias_level,
1093 .controls = wm8985_snd_controls,
1094 .num_controls =
ARRAY_SIZE(wm8985_snd_controls),
1095 .dapm_widgets = wm8985_dapm_widgets,
1096 .num_dapm_widgets =
ARRAY_SIZE(wm8985_dapm_widgets),
1097 .dapm_routes = wm8985_dapm_routes,
1098 .num_dapm_routes =
ARRAY_SIZE(wm8985_dapm_routes),
1101 static const struct regmap_config wm8985_regmap = {
1106 .writeable_reg = wm8985_writeable,
1109 .reg_defaults = wm8985_reg_defaults,
1110 .num_reg_defaults =
ARRAY_SIZE(wm8985_reg_defaults),
1113 #if defined(CONFIG_SPI_MASTER)
1123 spi_set_drvdata(spi, wm8985);
1126 if (IS_ERR(wm8985->
regmap)) {
1127 ret = PTR_ERR(wm8985->
regmap);
1128 dev_err(&spi->
dev,
"Failed to allocate register map: %d\n",
1134 &soc_codec_dev_wm8985, &wm8985_dai, 1);
1147 struct wm8985_priv *wm8985 = spi_get_drvdata(spi);
1155 static struct spi_driver wm8985_spi_driver = {
1160 .probe = wm8985_spi_probe,
1165 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1176 i2c_set_clientdata(i2c, wm8985);
1179 if (IS_ERR(wm8985->
regmap)) {
1180 ret = PTR_ERR(wm8985->
regmap);
1181 dev_err(&i2c->
dev,
"Failed to allocate register map: %d\n",
1187 &soc_codec_dev_wm8985, &wm8985_dai, 1);
1200 struct wm8985_priv *wm8985 = i2c_get_clientdata(i2c);
1214 static struct i2c_driver wm8985_i2c_driver = {
1219 .probe = wm8985_i2c_probe,
1221 .id_table = wm8985_i2c_id
1225 static int __init wm8985_modinit(
void)
1229 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1230 ret = i2c_add_driver(&wm8985_i2c_driver);
1236 #if defined(CONFIG_SPI_MASTER)
1247 static void __exit wm8985_exit(
void)
1249 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1252 #if defined(CONFIG_SPI_MASTER)
1253 spi_unregister_driver(&wm8985_spi_driver);