13 #include <linux/module.h>
20 #include <linux/i2c.h>
24 #include <linux/slab.h>
36 #define WM5100_NUM_CORE_SUPPLIES 2
43 #define WM5100_SYNC_SRS 3
82 struct gpio_chip gpio_chip;
86 static int wm5100_sr_code[] = {
121 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
122 int sr_code, sr_free,
i;
124 for (i = 0; i <
ARRAY_SIZE(wm5100_sr_code); i++)
125 if (wm5100_sr_code[i] == rate)
128 dev_err(codec->
dev,
"Unsupported sample rate: %dHz\n", rate);
133 if ((wm5100->
sysclk % rate) == 0) {
136 for (i = 0; i <
ARRAY_SIZE(wm5100_sr_regs); i++) {
137 if (!wm5100->
sr_ref[i] && sr_free == -1) {
148 dev_dbg(codec->
dev,
"SR %dHz, slot %d, ref %d\n",
149 rate, i, wm5100->
sr_ref[i]);
154 dev_err(codec->
dev,
"All SR slots already in use\n");
158 dev_dbg(codec->
dev,
"Allocating SR slot %d for %dHz\n",
160 wm5100->
sr_ref[sr_free]++;
169 "SR %dHz incompatible with %dHz SYSCLK and %dHz ASYNCCLK\n",
175 static void wm5100_free_sr(
struct snd_soc_codec *codec,
int rate)
177 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
180 for (i = 0; i <
ARRAY_SIZE(wm5100_sr_code); i++)
181 if (wm5100_sr_code[i] == rate)
184 dev_err(codec->
dev,
"Unsupported sample rate: %dHz\n", rate);
187 sr_code = wm5100_sr_code[
i];
189 for (i = 0; i <
ARRAY_SIZE(wm5100_sr_regs); i++) {
199 dev_dbg(codec->
dev,
"Dereference SR %dHz, count now %d\n",
202 dev_warn(codec->
dev,
"Freeing unreferenced sample rate %dHz\n",
207 static int wm5100_reset(
struct wm5100_priv *wm5100)
209 if (wm5100->
pdata.reset) {
225 static const char *wm5100_mixer_texts[] = {
300 static int wm5100_mixer_values[] = {
376 #define WM5100_MIXER_CONTROLS(name, base) \
377 SOC_SINGLE_TLV(name " Input 1 Volume", base + 1 , \
378 WM5100_MIXER_VOL_SHIFT, 80, 0, mixer_tlv), \
379 SOC_SINGLE_TLV(name " Input 2 Volume", base + 3 , \
380 WM5100_MIXER_VOL_SHIFT, 80, 0, mixer_tlv), \
381 SOC_SINGLE_TLV(name " Input 3 Volume", base + 5 , \
382 WM5100_MIXER_VOL_SHIFT, 80, 0, mixer_tlv), \
383 SOC_SINGLE_TLV(name " Input 4 Volume", base + 7 , \
384 WM5100_MIXER_VOL_SHIFT, 80, 0, mixer_tlv)
386 #define WM5100_MUX_ENUM_DECL(name, reg) \
387 SOC_VALUE_ENUM_SINGLE_DECL(name, reg, 0, 0xff, \
388 wm5100_mixer_texts, wm5100_mixer_values)
390 #define WM5100_MUX_CTL_DECL(name) \
391 const struct snd_kcontrol_new name##_mux = \
392 SOC_DAPM_VALUE_ENUM("Route", name##_enum)
394 #define WM5100_MIXER_ENUMS(name, base_reg) \
395 static WM5100_MUX_ENUM_DECL(name##_in1_enum, base_reg); \
396 static WM5100_MUX_ENUM_DECL(name##_in2_enum, base_reg + 2); \
397 static WM5100_MUX_ENUM_DECL(name##_in3_enum, base_reg + 4); \
398 static WM5100_MUX_ENUM_DECL(name##_in4_enum, base_reg + 6); \
399 static WM5100_MUX_CTL_DECL(name##_in1); \
400 static WM5100_MUX_CTL_DECL(name##_in2); \
401 static WM5100_MUX_CTL_DECL(name##_in3); \
402 static WM5100_MUX_CTL_DECL(name##_in4)
449 #define WM5100_MUX(name, ctrl) \
450 SND_SOC_DAPM_VALUE_MUX(name, SND_SOC_NOPM, 0, 0, ctrl)
452 #define WM5100_MIXER_WIDGETS(name, name_str) \
453 WM5100_MUX(name_str " Input 1", &name##_in1_mux), \
454 WM5100_MUX(name_str " Input 2", &name##_in2_mux), \
455 WM5100_MUX(name_str " Input 3", &name##_in3_mux), \
456 WM5100_MUX(name_str " Input 4", &name##_in4_mux), \
457 SND_SOC_DAPM_MIXER(name_str " Mixer", SND_SOC_NOPM, 0, 0, NULL, 0)
459 #define WM5100_MIXER_INPUT_ROUTES(name) \
460 { name, "Tone Generator 1", "Tone Generator 1" }, \
461 { name, "Tone Generator 2", "Tone Generator 2" }, \
462 { name, "IN1L", "IN1L PGA" }, \
463 { name, "IN1R", "IN1R PGA" }, \
464 { name, "IN2L", "IN2L PGA" }, \
465 { name, "IN2R", "IN2R PGA" }, \
466 { name, "IN3L", "IN3L PGA" }, \
467 { name, "IN3R", "IN3R PGA" }, \
468 { name, "IN4L", "IN4L PGA" }, \
469 { name, "IN4R", "IN4R PGA" }, \
470 { name, "AIF1RX1", "AIF1RX1" }, \
471 { name, "AIF1RX2", "AIF1RX2" }, \
472 { name, "AIF1RX3", "AIF1RX3" }, \
473 { name, "AIF1RX4", "AIF1RX4" }, \
474 { name, "AIF1RX5", "AIF1RX5" }, \
475 { name, "AIF1RX6", "AIF1RX6" }, \
476 { name, "AIF1RX7", "AIF1RX7" }, \
477 { name, "AIF1RX8", "AIF1RX8" }, \
478 { name, "AIF2RX1", "AIF2RX1" }, \
479 { name, "AIF2RX2", "AIF2RX2" }, \
480 { name, "AIF3RX1", "AIF3RX1" }, \
481 { name, "AIF3RX2", "AIF3RX2" }, \
482 { name, "EQ1", "EQ1" }, \
483 { name, "EQ2", "EQ2" }, \
484 { name, "EQ3", "EQ3" }, \
485 { name, "EQ4", "EQ4" }, \
486 { name, "DRC1L", "DRC1L" }, \
487 { name, "DRC1R", "DRC1R" }, \
488 { name, "LHPF1", "LHPF1" }, \
489 { name, "LHPF2", "LHPF2" }, \
490 { name, "LHPF3", "LHPF3" }, \
491 { name, "LHPF4", "LHPF4" }
493 #define WM5100_MIXER_ROUTES(widget, name) \
494 { widget, NULL, name " Mixer" }, \
495 { name " Mixer", NULL, name " Input 1" }, \
496 { name " Mixer", NULL, name " Input 2" }, \
497 { name " Mixer", NULL, name " Input 3" }, \
498 { name " Mixer", NULL, name " Input 4" }, \
499 WM5100_MIXER_INPUT_ROUTES(name " Input 1"), \
500 WM5100_MIXER_INPUT_ROUTES(name " Input 2"), \
501 WM5100_MIXER_INPUT_ROUTES(name " Input 3"), \
502 WM5100_MIXER_INPUT_ROUTES(name " Input 4")
504 static const char *wm5100_lhpf_mode_text[] = {
505 "Low-pass",
"High-pass"
508 static const struct soc_enum wm5100_lhpf1_mode =
510 wm5100_lhpf_mode_text);
512 static const struct soc_enum wm5100_lhpf2_mode =
514 wm5100_lhpf_mode_text);
516 static const struct soc_enum wm5100_lhpf3_mode =
518 wm5100_lhpf_mode_text);
520 static const struct soc_enum wm5100_lhpf4_mode =
522 wm5100_lhpf_mode_text);
668 SOC_ENUM(
"LHPF1 Mode", wm5100_lhpf1_mode),
669 SOC_ENUM(
"LHPF2 Mode", wm5100_lhpf2_mode),
670 SOC_ENUM(
"LHPF3 Mode", wm5100_lhpf3_mode),
671 SOC_ENUM(
"LHPF4 Mode", wm5100_lhpf4_mode),
726 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
732 for (i = 0; i < 200; i++) {
740 dev_err(codec->
dev,
"Timeout waiting for OUTPUT1 %x\n",
747 for (i = 0; i < 200; i++) {
755 dev_err(codec->
dev,
"Timeout waiting for OUTPUT2 %x\n",
781 static void wm5100_log_status3(
struct wm5100_priv *wm5100,
int val)
784 dev_crit(wm5100->
dev,
"Speaker shutdown warning\n");
786 dev_crit(wm5100->
dev,
"Speaker shutdown\n");
788 dev_crit(wm5100->
dev,
"SYSCLK underclocked\n");
790 dev_crit(wm5100->
dev,
"ASYNCCLK underclocked\n");
793 static void wm5100_log_status4(
struct wm5100_priv *wm5100,
int val)
796 dev_err(wm5100->
dev,
"AIF3 configuration error\n");
798 dev_err(wm5100->
dev,
"AIF2 configuration error\n");
800 dev_err(wm5100->
dev,
"AIF1 configuration error\n");
802 dev_err(wm5100->
dev,
"Control interface error\n");
830 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
837 wm5100_log_status3(wm5100, ret);
840 wm5100_log_status4(wm5100, ret);
1071 {
"CP1",
NULL,
"CPVDD" },
1072 {
"CP2 Active",
NULL,
"CPVDD" },
1074 {
"IN1L",
NULL,
"SYSCLK" },
1075 {
"IN1R",
NULL,
"SYSCLK" },
1076 {
"IN2L",
NULL,
"SYSCLK" },
1077 {
"IN2R",
NULL,
"SYSCLK" },
1078 {
"IN3L",
NULL,
"SYSCLK" },
1079 {
"IN3R",
NULL,
"SYSCLK" },
1080 {
"IN4L",
NULL,
"SYSCLK" },
1081 {
"IN4R",
NULL,
"SYSCLK" },
1083 {
"OUT1L",
NULL,
"SYSCLK" },
1084 {
"OUT1R",
NULL,
"SYSCLK" },
1085 {
"OUT2L",
NULL,
"SYSCLK" },
1086 {
"OUT2R",
NULL,
"SYSCLK" },
1087 {
"OUT3L",
NULL,
"SYSCLK" },
1088 {
"OUT3R",
NULL,
"SYSCLK" },
1089 {
"OUT4L",
NULL,
"SYSCLK" },
1090 {
"OUT4R",
NULL,
"SYSCLK" },
1091 {
"OUT5L",
NULL,
"SYSCLK" },
1092 {
"OUT5R",
NULL,
"SYSCLK" },
1093 {
"OUT6L",
NULL,
"SYSCLK" },
1094 {
"OUT6R",
NULL,
"SYSCLK" },
1096 {
"AIF1RX1",
NULL,
"SYSCLK" },
1097 {
"AIF1RX2",
NULL,
"SYSCLK" },
1098 {
"AIF1RX3",
NULL,
"SYSCLK" },
1099 {
"AIF1RX4",
NULL,
"SYSCLK" },
1100 {
"AIF1RX5",
NULL,
"SYSCLK" },
1101 {
"AIF1RX6",
NULL,
"SYSCLK" },
1102 {
"AIF1RX7",
NULL,
"SYSCLK" },
1103 {
"AIF1RX8",
NULL,
"SYSCLK" },
1105 {
"AIF2RX1",
NULL,
"SYSCLK" },
1106 {
"AIF2RX1",
NULL,
"DBVDD2" },
1107 {
"AIF2RX2",
NULL,
"SYSCLK" },
1108 {
"AIF2RX2",
NULL,
"DBVDD2" },
1110 {
"AIF3RX1",
NULL,
"SYSCLK" },
1111 {
"AIF3RX1",
NULL,
"DBVDD3" },
1112 {
"AIF3RX2",
NULL,
"SYSCLK" },
1113 {
"AIF3RX2",
NULL,
"DBVDD3" },
1115 {
"AIF1TX1",
NULL,
"SYSCLK" },
1116 {
"AIF1TX2",
NULL,
"SYSCLK" },
1117 {
"AIF1TX3",
NULL,
"SYSCLK" },
1118 {
"AIF1TX4",
NULL,
"SYSCLK" },
1119 {
"AIF1TX5",
NULL,
"SYSCLK" },
1120 {
"AIF1TX6",
NULL,
"SYSCLK" },
1121 {
"AIF1TX7",
NULL,
"SYSCLK" },
1122 {
"AIF1TX8",
NULL,
"SYSCLK" },
1124 {
"AIF2TX1",
NULL,
"SYSCLK" },
1125 {
"AIF2TX1",
NULL,
"DBVDD2" },
1126 {
"AIF2TX2",
NULL,
"SYSCLK" },
1127 {
"AIF2TX2",
NULL,
"DBVDD2" },
1129 {
"AIF3TX1",
NULL,
"SYSCLK" },
1130 {
"AIF3TX1",
NULL,
"DBVDD3" },
1131 {
"AIF3TX2",
NULL,
"SYSCLK" },
1132 {
"AIF3TX2",
NULL,
"DBVDD3" },
1134 {
"MICBIAS1",
NULL,
"CP2" },
1135 {
"MICBIAS2",
NULL,
"CP2" },
1136 {
"MICBIAS3",
NULL,
"CP2" },
1138 {
"IN1L PGA",
NULL,
"CP2" },
1139 {
"IN1R PGA",
NULL,
"CP2" },
1140 {
"IN2L PGA",
NULL,
"CP2" },
1141 {
"IN2R PGA",
NULL,
"CP2" },
1142 {
"IN3L PGA",
NULL,
"CP2" },
1143 {
"IN3R PGA",
NULL,
"CP2" },
1144 {
"IN4L PGA",
NULL,
"CP2" },
1145 {
"IN4R PGA",
NULL,
"CP2" },
1147 {
"IN1L PGA",
NULL,
"CP2 Active" },
1148 {
"IN1R PGA",
NULL,
"CP2 Active" },
1149 {
"IN2L PGA",
NULL,
"CP2 Active" },
1150 {
"IN2R PGA",
NULL,
"CP2 Active" },
1151 {
"IN3L PGA",
NULL,
"CP2 Active" },
1152 {
"IN3R PGA",
NULL,
"CP2 Active" },
1153 {
"IN4L PGA",
NULL,
"CP2 Active" },
1154 {
"IN4R PGA",
NULL,
"CP2 Active" },
1156 {
"OUT1L",
NULL,
"CP1" },
1157 {
"OUT1R",
NULL,
"CP1" },
1158 {
"OUT2L",
NULL,
"CP1" },
1159 {
"OUT2R",
NULL,
"CP1" },
1160 {
"OUT3L",
NULL,
"CP1" },
1161 {
"OUT3R",
NULL,
"CP1" },
1163 {
"Tone Generator 1",
NULL,
"TONE" },
1164 {
"Tone Generator 2",
NULL,
"TONE" },
1166 {
"IN1L PGA",
NULL,
"IN1L" },
1167 {
"IN1R PGA",
NULL,
"IN1R" },
1168 {
"IN2L PGA",
NULL,
"IN2L" },
1169 {
"IN2R PGA",
NULL,
"IN2R" },
1170 {
"IN3L PGA",
NULL,
"IN3L" },
1171 {
"IN3R PGA",
NULL,
"IN3R" },
1172 {
"IN4L PGA",
NULL,
"IN4L" },
1173 {
"IN4R PGA",
NULL,
"IN4R" },
1220 {
"HPOUT1L",
NULL,
"OUT1L" },
1221 {
"HPOUT1R",
NULL,
"OUT1R" },
1222 {
"HPOUT2L",
NULL,
"OUT2L" },
1223 {
"HPOUT2R",
NULL,
"OUT2R" },
1224 {
"HPOUT3L",
NULL,
"OUT3L" },
1225 {
"HPOUT3R",
NULL,
"OUT3R" },
1226 {
"SPKOUTL",
NULL,
"OUT4L" },
1227 {
"SPKOUTR",
NULL,
"OUT4R" },
1228 {
"SPKDAT1",
NULL,
"OUT5L" },
1229 {
"SPKDAT1",
NULL,
"OUT5R" },
1230 {
"SPKDAT2",
NULL,
"OUT6L" },
1231 {
"SPKDAT2",
NULL,
"OUT6R" },
1232 {
"PWM1",
NULL,
"PWM1 Driver" },
1233 {
"PWM2",
NULL,
"PWM2 Driver" },
1273 base = dai->
driver->base;
1292 dev_err(codec->
dev,
"Unsupported DAI format %d\n",
1293 fmt & SND_SOC_DAIFMT_FORMAT_MASK);
1311 dev_err(codec->
dev,
"Unsupported master mode %d\n",
1312 fmt & SND_SOC_DAIFMT_MASTER_MASK);
1344 #define WM5100_NUM_BCLK_RATES 19
1395 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
1397 int i, base,
bclk, aif_rate, lrclk, wl,
fl,
sr;
1400 base = dai->
driver->base;
1410 dev_dbg(codec->
dev,
"Word length %d bits, frame length %d bits\n",
1420 aif_rate = wm5100->
sysclk;
1429 for (i = 0; i <
ARRAY_SIZE(wm5100_sr_code); i++)
1445 async ?
"ASYNCCLK" :
"SYSCLK");
1449 dev_dbg(codec->
dev,
"Target BCLK is %dHz, using %dHz %s\n",
1450 bclk, aif_rate, async ?
"ASYNCCLK" :
"SYSCLK");
1452 if (aif_rate % 4000)
1453 bclk_rates = wm5100_bclk_rates_cd;
1455 bclk_rates = wm5100_bclk_rates_dat;
1458 if (bclk_rates[i] >= bclk && (bclk_rates[i] % bclk == 0))
1460 if (i == WM5100_NUM_BCLK_RATES) {
1462 "No valid BCLK for %dHz found from %dHz %s\n",
1463 bclk, aif_rate, async ?
"ASYNCCLK" :
"SYSCLK");
1468 dev_dbg(codec->
dev,
"Setting %dHz BCLK\n", bclk_rates[bclk]);
1472 dev_dbg(codec->
dev,
"Setting %dHz LRCLK\n", bclk_rates[bclk] / lrclk);
1497 .set_fmt = wm5100_set_fmt,
1498 .hw_params = wm5100_hw_params,
1501 static int wm5100_set_sysclk(
struct snd_soc_codec *codec,
int clk_id,
1504 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
1506 int fval, audio_rate,
ret,
reg;
1511 rate_store = &wm5100->
sysclk;
1544 dev_err(codec->
dev,
"Invalid source %d\n", source);
1567 dev_err(codec->
dev,
"Unsupported OPCLK %dHz\n",
1574 dev_err(codec->
dev,
"Unknown clock %d\n", clk_id);
1581 dev_err(codec->
dev,
"Invalid source %d\n", source);
1599 dev_err(codec->
dev,
"Invalid clock rate: %d\n", freq);
1635 dev_dbg(codec->
dev,
"Setting primary audio rate to %dHz",
1637 if (0 && *rate_store)
1638 wm5100_free_sr(codec, audio_rate);
1639 ret = wm5100_alloc_sr(codec, audio_rate);
1641 dev_warn(codec->
dev,
"Primary audio slot is %d\n",
1665 { 0, 64000, 4, 16 },
1666 { 64000, 128000, 3, 8 },
1667 { 128000, 256000, 2, 4 },
1668 { 256000, 1000000, 1, 2 },
1669 { 1000000, 13500000, 0, 1 },
1677 unsigned int fratio, gcd_fll;
1683 while ((Fref / div) > 13500000) {
1688 pr_err(
"Can't scale %dMHz input down to <=13.5MHz\n",
1694 pr_debug(
"FLL Fref=%u Fout=%u\n", Fref, Fout);
1701 while (Fout * div < 90000000) {
1704 pr_err(
"Unable to find FLL_OUTDIV for Fout=%uHz\n",
1709 target = Fout *
div;
1712 pr_debug(
"FLL Fvco=%dHz\n", target);
1715 for (i = 0; i <
ARRAY_SIZE(fll_fratios); i++) {
1716 if (fll_fratios[i].
min <= Fref && Fref <= fll_fratios[i].
max) {
1718 fratio = fll_fratios[
i].ratio;
1723 pr_err(
"Unable to find FLL_FRATIO for Fref=%uHz\n", Fref);
1727 fll_div->
n = target / (fratio * Fref);
1729 if (target % Fref == 0) {
1733 gcd_fll =
gcd(target, fratio * Fref);
1735 fll_div->
theta = (target - (fll_div->
n * fratio * Fref))
1737 fll_div->
lambda = (fratio * Fref) / gcd_fll;
1740 pr_debug(
"FLL N=%x THETA=%x LAMBDA=%x\n",
1742 pr_debug(
"FLL_FRATIO=%x(%d) FLL_OUTDIV=%x FLL_REFCLK_DIV=%x\n",
1749 static int wm5100_set_fll(
struct snd_soc_codec *codec,
int fll_id,
int source,
1750 unsigned int Fref,
unsigned int Fout)
1753 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
1760 fll = &wm5100->
fll[0];
1765 fll = &wm5100->
fll[1];
1770 dev_err(codec->
dev,
"Unknown FLL %d\n",fll_id);
1775 dev_dbg(codec->
dev,
"FLL%d disabled", fll_id);
1777 pm_runtime_put(codec->
dev);
1793 dev_err(codec->
dev,
"Invalid FLL source %d\n", source);
1807 factors.fll_fratio);
1814 (factors.fll_refclk_div
1822 pm_runtime_get_sync(codec->
dev);
1835 for (i = 0; i < timeout; i++) {
1849 "Failed to read FLL status: %d\n",
1857 dev_err(codec->
dev,
"FLL%d lock timed out\n", fll_id);
1858 pm_runtime_put(codec->
dev);
1866 dev_dbg(codec->
dev,
"FLL%d running %dHz->%dHz\n", fll_id,
1873 #define WM5100_RATES SNDRV_PCM_RATE_8000_192000
1875 #define WM5100_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
1876 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
1880 .name =
"wm5100-aif1",
1883 .stream_name =
"AIF1 Playback",
1890 .stream_name =
"AIF1 Capture",
1896 .ops = &wm5100_dai_ops,
1899 .name =
"wm5100-aif2",
1903 .stream_name =
"AIF2 Playback",
1910 .stream_name =
"AIF2 Capture",
1916 .ops = &wm5100_dai_ops,
1919 .name =
"wm5100-aif3",
1923 .stream_name =
"AIF3 Playback",
1930 .stream_name =
"AIF3 Capture",
1936 .ops = &wm5100_dai_ops,
1940 static int wm5100_dig_vu[] = {
1964 static void wm5100_set_detect_mode(
struct wm5100_priv *wm5100,
int the_mode)
1982 dev_dbg(wm5100->
dev,
"Set microphone polarity to %d\n",
1986 static void wm5100_report_headphone(
struct wm5100_priv *wm5100)
1988 dev_dbg(wm5100->
dev,
"Headphone detected\n");
1999 static void wm5100_micd_irq(
struct wm5100_priv *wm5100)
2006 dev_err(wm5100->
dev,
"Failed to read micropone status: %d\n",
2011 dev_dbg(wm5100->
dev,
"Microphone event: %x\n", val);
2014 dev_warn(wm5100->
dev,
"Microphone detection state invalid\n");
2020 dev_dbg(wm5100->
dev,
"Jack removal detected\n");
2040 dev_dbg(wm5100->
dev,
"Microphone detected\n");
2070 wm5100_report_headphone(wm5100);
2072 wm5100_set_detect_mode(wm5100, !wm5100->
jack_mode);
2082 dev_dbg(wm5100->
dev,
"Mic button detected\n");
2086 wm5100_report_headphone(wm5100);
2093 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
2100 wm5100_set_detect_mode(wm5100, 0);
2141 unsigned int irq_val, mask_val;
2146 dev_err(wm5100->
dev,
"Failed to read IRQ status 3: %d\n",
2154 dev_err(wm5100->
dev,
"Failed to read IRQ mask 3: %d\n",
2159 irq_val &= ~mask_val;
2166 wm5100_log_status3(wm5100, irq_val);
2178 wm5100_micd_irq(wm5100);
2182 dev_err(wm5100->
dev,
"Failed to read IRQ status 4: %d\n",
2190 dev_err(wm5100->
dev,
"Failed to read IRQ mask 4: %d\n",
2195 irq_val &= ~mask_val;
2202 wm5100_log_status4(wm5100, irq_val);
2207 static irqreturn_t wm5100_edge_irq(
int irq,
void *data)
2213 val = wm5100_irq(irq, data);
2221 #ifdef CONFIG_GPIOLIB
2222 static inline struct wm5100_priv *gpio_to_wm5100(
struct gpio_chip *
chip)
2227 static void wm5100_gpio_set(
struct gpio_chip *
chip,
unsigned offset,
int value)
2229 struct wm5100_priv *wm5100 = gpio_to_wm5100(chip);
2235 static int wm5100_gpio_direction_out(
struct gpio_chip *
chip,
2238 struct wm5100_priv *wm5100 = gpio_to_wm5100(chip);
2252 static int wm5100_gpio_get(
struct gpio_chip *chip,
unsigned offset)
2254 struct wm5100_priv *wm5100 = gpio_to_wm5100(chip);
2265 static int wm5100_gpio_direction_in(
struct gpio_chip *chip,
unsigned offset)
2267 struct wm5100_priv *wm5100 = gpio_to_wm5100(chip);
2275 static struct gpio_chip wm5100_template_chip = {
2278 .direction_output = wm5100_gpio_direction_out,
2279 .set = wm5100_gpio_set,
2280 .direction_input = wm5100_gpio_direction_in,
2281 .get = wm5100_gpio_get,
2285 static void wm5100_init_gpio(
struct i2c_client *i2c)
2287 struct wm5100_priv *wm5100 = i2c_get_clientdata(i2c);
2290 wm5100->gpio_chip = wm5100_template_chip;
2291 wm5100->gpio_chip.ngpio = 6;
2292 wm5100->gpio_chip.
dev = &i2c->
dev;
2294 if (wm5100->
pdata.gpio_base)
2295 wm5100->gpio_chip.base = wm5100->
pdata.gpio_base;
2297 wm5100->gpio_chip.base = -1;
2301 dev_err(&i2c->
dev,
"Failed to add GPIOs: %d\n", ret);
2304 static void wm5100_free_gpio(
struct i2c_client *i2c)
2306 struct wm5100_priv *wm5100 = i2c_get_clientdata(i2c);
2311 dev_err(&i2c->
dev,
"Failed to remove GPIOs: %d\n", ret);
2314 static void wm5100_init_gpio(
struct i2c_client *i2c)
2318 static void wm5100_free_gpio(
struct i2c_client *i2c)
2326 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
2334 dev_err(codec->
dev,
"Failed to set cache I/O: %d\n", ret);
2338 for (i = 0; i <
ARRAY_SIZE(wm5100_dig_vu); i++)
2350 wm5100_dapm_widgets_noirq,
2353 if (wm5100->
pdata.hp_pol) {
2357 dev_err(&i2c->
dev,
"Failed to request HP_POL %d: %d\n",
2358 wm5100->
pdata.hp_pol, ret);
2372 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
2374 if (wm5100->
pdata.hp_pol) {
2382 .probe = wm5100_probe,
2383 .remove = wm5100_remove,
2385 .set_sysclk = wm5100_set_sysclk,
2386 .set_pll = wm5100_set_fll,
2389 .seq_notifier = wm5100_seq_notifier,
2390 .controls = wm5100_snd_controls,
2391 .num_controls =
ARRAY_SIZE(wm5100_snd_controls),
2392 .dapm_widgets = wm5100_dapm_widgets,
2393 .num_dapm_widgets =
ARRAY_SIZE(wm5100_dapm_widgets),
2394 .dapm_routes = wm5100_dapm_routes,
2395 .num_dapm_routes =
ARRAY_SIZE(wm5100_dapm_routes),
2398 static const struct regmap_config wm5100_regmap = {
2410 static const unsigned int wm5100_mic_ctrl_reg[] = {
2423 int ret,
i, irq_flags;
2433 if (IS_ERR(wm5100->
regmap)) {
2434 ret = PTR_ERR(wm5100->
regmap);
2435 dev_err(&i2c->
dev,
"Failed to allocate register map: %d\n",
2441 init_completion(&wm5100->
fll[i].lock);
2446 i2c_set_clientdata(i2c, wm5100);
2449 wm5100->
core_supplies[i].supply = wm5100_core_supply_names[i];
2455 dev_err(&i2c->
dev,
"Failed to request core supplies: %d\n",
2463 dev_err(&i2c->
dev,
"Failed to enable core supplies: %d\n",
2468 if (wm5100->
pdata.ldo_ena) {
2472 dev_err(&i2c->
dev,
"Failed to request LDOENA %d: %d\n",
2473 wm5100->
pdata.ldo_ena, ret);
2479 if (wm5100->
pdata.reset) {
2483 dev_err(&i2c->
dev,
"Failed to request /RESET %d: %d\n",
2484 wm5100->
pdata.reset, ret);
2491 dev_err(&i2c->
dev,
"Failed to read ID register: %d\n", ret);
2500 dev_err(&i2c->
dev,
"Device is not a WM5100, ID is %x\n", reg);
2507 dev_err(&i2c->
dev,
"Failed to read revision register\n");
2514 ret = wm5100_reset(wm5100);
2516 dev_err(&i2c->
dev,
"Failed to issue reset\n");
2520 switch (wm5100->
rev) {
2523 wm5100_reva_patches,
2526 dev_err(&i2c->
dev,
"Failed to register patches: %d\n",
2536 wm5100_init_gpio(i2c);
2539 if (!wm5100->
pdata.gpio_defaults[i])
2543 wm5100->
pdata.gpio_defaults[i]);
2550 (wm5100->
pdata.in_mode[i] <<
2552 (wm5100->
pdata.dmic_sup[i] <<
2557 if (wm5100->
pdata.irq_flags)
2558 irq_flags = wm5100->
pdata.irq_flags;
2566 wm5100_edge_irq, irq_flags,
2570 irq_flags,
"wm5100",
2574 dev_err(&i2c->
dev,
"Failed to request IRQ %d: %d\n",
2586 WM5100_CLKGEN_ERR_EINT |
2591 WM5100_AIF3_ERR_EINT |
2592 WM5100_AIF2_ERR_EINT |
2593 WM5100_AIF1_ERR_EINT |
2594 WM5100_CTRLIF_ERR_EINT |
2595 WM5100_ISRC2_UNDERCLOCKED_EINT |
2596 WM5100_ISRC1_UNDERCLOCKED_EINT |
2597 WM5100_FX_UNDERCLOCKED_EINT |
2598 WM5100_AIF3_UNDERCLOCKED_EINT |
2599 WM5100_AIF2_UNDERCLOCKED_EINT |
2600 WM5100_AIF1_UNDERCLOCKED_EINT |
2601 WM5100_ASRC_UNDERCLOCKED_EINT |
2602 WM5100_DAC_UNDERCLOCKED_EINT |
2603 WM5100_ADC_UNDERCLOCKED_EINT |
2608 pm_runtime_set_active(&i2c->
dev);
2610 pm_request_idle(&i2c->
dev);
2613 &soc_codec_dev_wm5100, wm5100_dai,
2616 dev_err(&i2c->
dev,
"Failed to register WM5100: %d\n", ret);
2625 wm5100_free_gpio(i2c);
2626 if (wm5100->
pdata.reset) {
2631 if (wm5100->
pdata.ldo_ena) {
2644 struct wm5100_priv *wm5100 = i2c_get_clientdata(i2c);
2649 wm5100_free_gpio(i2c);
2650 if (wm5100->
pdata.reset) {
2654 if (wm5100->
pdata.ldo_ena) {
2662 #ifdef CONFIG_PM_RUNTIME
2663 static int wm5100_runtime_suspend(
struct device *
dev)
2669 if (wm5100->
pdata.ldo_ena)
2677 static int wm5100_runtime_resume(
struct device *dev)
2685 dev_err(dev,
"Failed to enable supplies: %d\n",
2690 if (wm5100->
pdata.ldo_ena) {
2713 static struct i2c_driver wm5100_i2c_driver = {
2719 .probe = wm5100_i2c_probe,
2721 .id_table = wm5100_i2c_id,