13 #include <linux/module.h>
21 #include <linux/i2c.h>
24 #include <linux/slab.h>
45 #define WM8996_NUM_SUPPLIES 3
96 struct gpio_chip gpio_chip;
104 #define WM8996_REGULATOR_EVENT(n) \
105 static int wm8996_regulator_event_##n(struct notifier_block *nb, \
106 unsigned long event, void *data) \
108 struct wm8996_priv *wm8996 = container_of(nb, struct wm8996_priv, \
110 if (event & REGULATOR_EVENT_DISABLE) { \
111 regcache_mark_dirty(wm8996->regmap); \
310 static const char *sidetone_hpf_text[] = {
311 "2.9kHz",
"1.5kHz",
"735Hz",
"403Hz",
"196Hz",
"98Hz",
"49Hz"
314 static const struct soc_enum sidetone_hpf =
317 static const char *hpf_mode_text[] = {
318 "HiFi",
"Custom",
"Voice"
321 static const struct soc_enum dsp1tx_hpf_mode =
324 static const struct soc_enum dsp2tx_hpf_mode =
327 static const char *hpf_cutoff_text[] = {
328 "50Hz",
"75Hz",
"100Hz",
"150Hz",
"200Hz",
"300Hz",
"400Hz"
331 static const struct soc_enum dsp1tx_hpf_cutoff =
334 static const struct soc_enum dsp2tx_hpf_cutoff =
339 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
341 int base, best, best_val, save,
i,
cfg, iface;
376 - wm8996->
rx_rate[iface]) < best_val) {
383 dev_dbg(codec->
dev,
"ReTune Mobile %d %s/%dHz for %dHz sample rate\n",
403 static int wm8996_get_retune_mobile_block(
const char *
name)
405 if (
strcmp(name,
"DSP1 EQ Mode") == 0)
407 if (
strcmp(name,
"DSP2 EQ Mode") == 0)
412 static int wm8996_put_retune_mobile_enum(
struct snd_kcontrol *kcontrol,
416 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
418 int block = wm8996_get_retune_mobile_block(kcontrol->
id.name);
429 wm8996_set_retune_mobile(codec, block);
434 static int wm8996_get_retune_mobile_enum(
struct snd_kcontrol *kcontrol,
438 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
439 int block = wm8996_get_retune_mobile_block(kcontrol->
id.name);
453 0, 5, 24, 0, sidetone_tlv),
455 0, 5, 24, 0, sidetone_tlv),
457 SOC_ENUM(
"Sidetone HPF Cut-off", sidetone_hpf),
468 SOC_ENUM(
"DSP1 Capture HPF Mode", dsp1tx_hpf_mode),
469 SOC_ENUM(
"DSP1 Capture HPF Cutoff", dsp1tx_hpf_cutoff),
474 SOC_ENUM(
"DSP2 Capture HPF Mode", dsp2tx_hpf_mode),
475 SOC_ENUM(
"DSP2 Capture HPF Cutoff", dsp2tx_hpf_cutoff),
507 0, threedstereo_tlv),
509 0, threedstereo_tlv),
512 8, 0, out_digital_tlv),
514 8, 0, out_digital_tlv),
577 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
580 if (wm8996->
bg_ena == 1) {
589 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
605 wm8996_bg_enable(codec);
608 wm8996_bg_disable(codec);
659 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
679 dev_dbg(codec->
dev,
"DC servo state: %x\n", ret);
680 }
while (timeout && ret & mask);
683 dev_err(codec->
dev,
"DC servo timed out for %x\n", mask);
685 dev_dbg(codec->
dev,
"DC servo complete for %x\n", mask);
693 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
698 dev_dbg(codec->
dev,
"Starting DC servo for %x\n",
709 dev_dbg(codec->
dev,
"Applying RMV_SHORTs %x->%x\n",
777 static const char *sidetone_text[] = {
781 static const struct soc_enum left_sidetone_enum =
787 static const struct soc_enum right_sidetone_enum =
793 static const char *spk_text[] = {
794 "DAC1L",
"DAC1R",
"DAC2L",
"DAC2R"
797 static const struct soc_enum spkl_enum =
803 static const struct soc_enum spkr_enum =
809 static const char *dsp1rx_text[] = {
813 static const struct soc_enum dsp1rx_enum =
819 static const char *dsp2rx_text[] = {
823 static const struct soc_enum dsp2rx_enum =
829 static const char *aif2tx_text[] = {
830 "DSP2",
"DSP1",
"AIF1"
833 static const struct soc_enum aif2tx_enum =
839 static const char *inmux_text[] = {
840 "ADC",
"DMIC1",
"DMIC2"
843 static const struct soc_enum in1_enum =
849 static const struct soc_enum in2_enum =
1075 {
"AIFCLK",
NULL,
"SYSCLK" },
1076 {
"SYSDSPCLK",
NULL,
"SYSCLK" },
1077 {
"Charge Pump",
NULL,
"SYSCLK" },
1078 {
"Charge Pump",
NULL,
"CPVDD" },
1080 {
"MICB1",
NULL,
"LDO2" },
1081 {
"MICB1",
NULL,
"MICB1 Audio" },
1082 {
"MICB1",
NULL,
"Bandgap" },
1083 {
"MICB2",
NULL,
"LDO2" },
1084 {
"MICB2",
NULL,
"MICB2 Audio" },
1085 {
"MICB2",
NULL,
"Bandgap" },
1087 {
"AIF1RX0",
NULL,
"AIF1 Playback" },
1088 {
"AIF1RX1",
NULL,
"AIF1 Playback" },
1089 {
"AIF1RX2",
NULL,
"AIF1 Playback" },
1090 {
"AIF1RX3",
NULL,
"AIF1 Playback" },
1091 {
"AIF1RX4",
NULL,
"AIF1 Playback" },
1092 {
"AIF1RX5",
NULL,
"AIF1 Playback" },
1094 {
"AIF2RX0",
NULL,
"AIF2 Playback" },
1095 {
"AIF2RX1",
NULL,
"AIF2 Playback" },
1097 {
"AIF1 Capture",
NULL,
"AIF1TX0" },
1098 {
"AIF1 Capture",
NULL,
"AIF1TX1" },
1099 {
"AIF1 Capture",
NULL,
"AIF1TX2" },
1100 {
"AIF1 Capture",
NULL,
"AIF1TX3" },
1101 {
"AIF1 Capture",
NULL,
"AIF1TX4" },
1102 {
"AIF1 Capture",
NULL,
"AIF1TX5" },
1104 {
"AIF2 Capture",
NULL,
"AIF2TX0" },
1105 {
"AIF2 Capture",
NULL,
"AIF2TX1" },
1107 {
"IN1L PGA",
NULL,
"IN2LN" },
1108 {
"IN1L PGA",
NULL,
"IN2LP" },
1109 {
"IN1L PGA",
NULL,
"IN1LN" },
1110 {
"IN1L PGA",
NULL,
"IN1LP" },
1111 {
"IN1L PGA",
NULL,
"Bandgap" },
1113 {
"IN1R PGA",
NULL,
"IN2RN" },
1114 {
"IN1R PGA",
NULL,
"IN2RP" },
1115 {
"IN1R PGA",
NULL,
"IN1RN" },
1116 {
"IN1R PGA",
NULL,
"IN1RP" },
1117 {
"IN1R PGA",
NULL,
"Bandgap" },
1119 {
"ADCL",
NULL,
"IN1L PGA" },
1121 {
"ADCR",
NULL,
"IN1R PGA" },
1123 {
"DMIC1L",
NULL,
"DMIC1DAT" },
1124 {
"DMIC1R",
NULL,
"DMIC1DAT" },
1125 {
"DMIC2L",
NULL,
"DMIC2DAT" },
1126 {
"DMIC2R",
NULL,
"DMIC2DAT" },
1128 {
"DMIC2L",
NULL,
"DMIC2" },
1129 {
"DMIC2R",
NULL,
"DMIC2" },
1130 {
"DMIC1L",
NULL,
"DMIC1" },
1131 {
"DMIC1R",
NULL,
"DMIC1" },
1133 {
"IN1L Mux",
"ADC",
"ADCL" },
1134 {
"IN1L Mux",
"DMIC1",
"DMIC1L" },
1135 {
"IN1L Mux",
"DMIC2",
"DMIC2L" },
1137 {
"IN1R Mux",
"ADC",
"ADCR" },
1138 {
"IN1R Mux",
"DMIC1",
"DMIC1R" },
1139 {
"IN1R Mux",
"DMIC2",
"DMIC2R" },
1141 {
"IN2L Mux",
"ADC",
"ADCL" },
1142 {
"IN2L Mux",
"DMIC1",
"DMIC1L" },
1143 {
"IN2L Mux",
"DMIC2",
"DMIC2L" },
1145 {
"IN2R Mux",
"ADC",
"ADCR" },
1146 {
"IN2R Mux",
"DMIC1",
"DMIC1R" },
1147 {
"IN2R Mux",
"DMIC2",
"DMIC2R" },
1149 {
"Left Sidetone",
"IN1",
"IN1L Mux" },
1150 {
"Left Sidetone",
"IN2",
"IN2L Mux" },
1152 {
"Right Sidetone",
"IN1",
"IN1R Mux" },
1153 {
"Right Sidetone",
"IN2",
"IN2R Mux" },
1155 {
"DSP1TXL",
"IN1 Switch",
"IN1L Mux" },
1156 {
"DSP1TXR",
"IN1 Switch",
"IN1R Mux" },
1158 {
"DSP2TXL",
"IN1 Switch",
"IN2L Mux" },
1159 {
"DSP2TXR",
"IN1 Switch",
"IN2R Mux" },
1161 {
"AIF1TX0",
NULL,
"DSP1TXL" },
1162 {
"AIF1TX1",
NULL,
"DSP1TXR" },
1163 {
"AIF1TX2",
NULL,
"DSP2TXL" },
1164 {
"AIF1TX3",
NULL,
"DSP2TXR" },
1165 {
"AIF1TX4",
NULL,
"AIF2RX0" },
1166 {
"AIF1TX5",
NULL,
"AIF2RX1" },
1168 {
"AIF1RX0",
NULL,
"AIFCLK" },
1169 {
"AIF1RX1",
NULL,
"AIFCLK" },
1170 {
"AIF1RX2",
NULL,
"AIFCLK" },
1171 {
"AIF1RX3",
NULL,
"AIFCLK" },
1172 {
"AIF1RX4",
NULL,
"AIFCLK" },
1173 {
"AIF1RX5",
NULL,
"AIFCLK" },
1175 {
"AIF2RX0",
NULL,
"AIFCLK" },
1176 {
"AIF2RX1",
NULL,
"AIFCLK" },
1178 {
"AIF1TX0",
NULL,
"AIFCLK" },
1179 {
"AIF1TX1",
NULL,
"AIFCLK" },
1180 {
"AIF1TX2",
NULL,
"AIFCLK" },
1181 {
"AIF1TX3",
NULL,
"AIFCLK" },
1182 {
"AIF1TX4",
NULL,
"AIFCLK" },
1183 {
"AIF1TX5",
NULL,
"AIFCLK" },
1185 {
"AIF2TX0",
NULL,
"AIFCLK" },
1186 {
"AIF2TX1",
NULL,
"AIFCLK" },
1188 {
"DSP1RXL",
NULL,
"SYSDSPCLK" },
1189 {
"DSP1RXR",
NULL,
"SYSDSPCLK" },
1190 {
"DSP2RXL",
NULL,
"SYSDSPCLK" },
1191 {
"DSP2RXR",
NULL,
"SYSDSPCLK" },
1192 {
"DSP1TXL",
NULL,
"SYSDSPCLK" },
1193 {
"DSP1TXR",
NULL,
"SYSDSPCLK" },
1194 {
"DSP2TXL",
NULL,
"SYSDSPCLK" },
1195 {
"DSP2TXR",
NULL,
"SYSDSPCLK" },
1197 {
"AIF1RXA",
NULL,
"AIF1RX0" },
1198 {
"AIF1RXA",
NULL,
"AIF1RX1" },
1199 {
"AIF1RXB",
NULL,
"AIF1RX2" },
1200 {
"AIF1RXB",
NULL,
"AIF1RX3" },
1201 {
"AIF1RXC",
NULL,
"AIF1RX4" },
1202 {
"AIF1RXC",
NULL,
"AIF1RX5" },
1204 {
"AIF2RX",
NULL,
"AIF2RX0" },
1205 {
"AIF2RX",
NULL,
"AIF2RX1" },
1207 {
"AIF2TX",
"DSP2",
"DSP2TX" },
1208 {
"AIF2TX",
"DSP1",
"DSP1RX" },
1209 {
"AIF2TX",
"AIF1",
"AIF1RXC" },
1211 {
"DSP1RXL",
NULL,
"DSP1RX" },
1212 {
"DSP1RXR",
NULL,
"DSP1RX" },
1213 {
"DSP2RXL",
NULL,
"DSP2RX" },
1214 {
"DSP2RXR",
NULL,
"DSP2RX" },
1216 {
"DSP2TX",
NULL,
"DSP2TXL" },
1217 {
"DSP2TX",
NULL,
"DSP2TXR" },
1219 {
"DSP1RX",
"AIF1",
"AIF1RXA" },
1220 {
"DSP1RX",
"AIF2",
"AIF2RX" },
1222 {
"DSP2RX",
"AIF1",
"AIF1RXB" },
1223 {
"DSP2RX",
"AIF2",
"AIF2RX" },
1225 {
"DAC2L Mixer",
"DSP2 Switch",
"DSP2RXL" },
1226 {
"DAC2L Mixer",
"DSP1 Switch",
"DSP1RXL" },
1227 {
"DAC2L Mixer",
"Right Sidetone Switch",
"Right Sidetone" },
1228 {
"DAC2L Mixer",
"Left Sidetone Switch",
"Left Sidetone" },
1230 {
"DAC2R Mixer",
"DSP2 Switch",
"DSP2RXR" },
1231 {
"DAC2R Mixer",
"DSP1 Switch",
"DSP1RXR" },
1232 {
"DAC2R Mixer",
"Right Sidetone Switch",
"Right Sidetone" },
1233 {
"DAC2R Mixer",
"Left Sidetone Switch",
"Left Sidetone" },
1235 {
"DAC1L Mixer",
"DSP2 Switch",
"DSP2RXL" },
1236 {
"DAC1L Mixer",
"DSP1 Switch",
"DSP1RXL" },
1237 {
"DAC1L Mixer",
"Right Sidetone Switch",
"Right Sidetone" },
1238 {
"DAC1L Mixer",
"Left Sidetone Switch",
"Left Sidetone" },
1240 {
"DAC1R Mixer",
"DSP2 Switch",
"DSP2RXR" },
1241 {
"DAC1R Mixer",
"DSP1 Switch",
"DSP1RXR" },
1242 {
"DAC1R Mixer",
"Right Sidetone Switch",
"Right Sidetone" },
1243 {
"DAC1R Mixer",
"Left Sidetone Switch",
"Left Sidetone" },
1245 {
"DAC1L",
NULL,
"DAC1L Mixer" },
1246 {
"DAC1R",
NULL,
"DAC1R Mixer" },
1247 {
"DAC2L",
NULL,
"DAC2L Mixer" },
1248 {
"DAC2R",
NULL,
"DAC2R Mixer" },
1250 {
"HPOUT2L PGA",
NULL,
"Charge Pump" },
1251 {
"HPOUT2L PGA",
NULL,
"Bandgap" },
1252 {
"HPOUT2L PGA",
NULL,
"DAC2L" },
1253 {
"HPOUT2L_DLY",
NULL,
"HPOUT2L PGA" },
1254 {
"HPOUT2L_DCS",
NULL,
"HPOUT2L_DLY" },
1255 {
"HPOUT2L_RMV_SHORT",
NULL,
"HPOUT2L_DCS" },
1257 {
"HPOUT2R PGA",
NULL,
"Charge Pump" },
1258 {
"HPOUT2R PGA",
NULL,
"Bandgap" },
1259 {
"HPOUT2R PGA",
NULL,
"DAC2R" },
1260 {
"HPOUT2R_DLY",
NULL,
"HPOUT2R PGA" },
1261 {
"HPOUT2R_DCS",
NULL,
"HPOUT2R_DLY" },
1262 {
"HPOUT2R_RMV_SHORT",
NULL,
"HPOUT2R_DCS" },
1264 {
"HPOUT1L PGA",
NULL,
"Charge Pump" },
1265 {
"HPOUT1L PGA",
NULL,
"Bandgap" },
1266 {
"HPOUT1L PGA",
NULL,
"DAC1L" },
1267 {
"HPOUT1L_DLY",
NULL,
"HPOUT1L PGA" },
1268 {
"HPOUT1L_DCS",
NULL,
"HPOUT1L_DLY" },
1269 {
"HPOUT1L_RMV_SHORT",
NULL,
"HPOUT1L_DCS" },
1271 {
"HPOUT1R PGA",
NULL,
"Charge Pump" },
1272 {
"HPOUT1R PGA",
NULL,
"Bandgap" },
1273 {
"HPOUT1R PGA",
NULL,
"DAC1R" },
1274 {
"HPOUT1R_DLY",
NULL,
"HPOUT1R PGA" },
1275 {
"HPOUT1R_DCS",
NULL,
"HPOUT1R_DLY" },
1276 {
"HPOUT1R_RMV_SHORT",
NULL,
"HPOUT1R_DCS" },
1278 {
"HPOUT2L",
NULL,
"HPOUT2L_RMV_SHORT" },
1279 {
"HPOUT2R",
NULL,
"HPOUT2R_RMV_SHORT" },
1280 {
"HPOUT1L",
NULL,
"HPOUT1L_RMV_SHORT" },
1281 {
"HPOUT1R",
NULL,
"HPOUT1R_RMV_SHORT" },
1283 {
"SPKL",
"DAC1L",
"DAC1L" },
1284 {
"SPKL",
"DAC1R",
"DAC1R" },
1285 {
"SPKL",
"DAC2L",
"DAC2L" },
1286 {
"SPKL",
"DAC2R",
"DAC2R" },
1288 {
"SPKR",
"DAC1L",
"DAC1L" },
1289 {
"SPKR",
"DAC1R",
"DAC1R" },
1290 {
"SPKR",
"DAC2L",
"DAC2L" },
1291 {
"SPKR",
"DAC2R",
"DAC2R" },
1293 {
"SPKL PGA",
NULL,
"SPKL" },
1294 {
"SPKR PGA",
NULL,
"SPKR" },
1296 {
"SPKDAT",
NULL,
"SPKL PGA" },
1297 {
"SPKDAT",
NULL,
"SPKR PGA" },
1300 static bool wm8996_readable_register(
struct device *
dev,
unsigned int reg)
1507 static bool wm8996_volatile_register(
struct device *dev,
unsigned int reg)
1531 static const int bclk_divs[] = {
1532 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96
1537 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
1538 int aif, best, cur_val,
bclk_rate, bclk_reg,
i;
1543 if (wm8996->
sysclk < 64000)
1560 for (i = 0; i <
ARRAY_SIZE(bclk_divs); i++) {
1561 cur_val = (wm8996->
sysclk / bclk_divs[
i]) - bclk_rate;
1566 bclk_rate = wm8996->
sysclk / bclk_divs[best];
1567 dev_dbg(codec->
dev,
"Using BCLK_DIV %d for actual BCLK %dHz\n",
1568 bclk_divs[best], bclk_rate);
1575 static int wm8996_set_bias_level(
struct snd_soc_codec *codec,
1578 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
1598 "Failed to enable supplies: %d\n",
1603 if (wm8996->
pdata.ldo_ena >= 0) {
1622 if (wm8996->
pdata.ldo_ena >= 0) {
1643 int aifctrl_reg, bclk_reg, lrclk_tx_reg, lrclk_rx_reg;
1731 static const int dsp_divs[] = {
1732 48000, 32000, 16000, 8000
1740 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
1745 int aifdata_reg, lrclk_reg, dsp_shift;
1776 if (bclk_rate < 0) {
1777 dev_err(codec->
dev,
"Unsupported BCLK rate: %d\n", bclk_rate);
1796 dsp |= i << dsp_shift;
1798 wm8996_update_bclk(codec);
1801 dev_dbg(dai->
dev,
"Using LRCLK rate %d for actual LRCLK %dHz\n",
1802 lrclk, bclk_rate / lrclk);
1816 static int wm8996_set_sysclk(
struct snd_soc_dai *dai,
1817 int clk_id,
unsigned int freq,
int dir)
1820 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
1849 dev_err(codec->
dev,
"Unsupported clock source %d\n", clk_id);
1853 switch (wm8996->
sysclk) {
1874 dev_warn(codec->
dev,
"Unsupported clock rate %dHz\n",
1879 wm8996_update_bclk(codec);
1912 { 0, 64000, 4, 16 },
1913 { 64000, 128000, 3, 8 },
1914 { 128000, 256000, 2, 4 },
1915 { 256000, 1000000, 1, 2 },
1916 { 1000000, 13500000, 0, 1 },
1924 unsigned int fratio, gcd_fll;
1930 while ((Fref / div) > 13500000) {
1935 pr_err(
"Can't scale %dMHz input down to <=13.5MHz\n",
1941 pr_debug(
"FLL Fref=%u Fout=%u\n", Fref, Fout);
1946 if (Fref >= 3000000)
1958 while (Fout * div < 90000000) {
1961 pr_err(
"Unable to find FLL_OUTDIV for Fout=%uHz\n",
1966 target = Fout *
div;
1969 pr_debug(
"FLL Fvco=%dHz\n", target);
1972 for (i = 0; i <
ARRAY_SIZE(fll_fratios); i++) {
1973 if (fll_fratios[i].
min <= Fref && Fref <= fll_fratios[i].
max) {
1975 fratio = fll_fratios[
i].ratio;
1980 pr_err(
"Unable to find FLL_FRATIO for Fref=%uHz\n", Fref);
1984 fll_div->
n = target / (fratio * Fref);
1986 if (target % Fref == 0) {
1990 gcd_fll =
gcd(target, fratio * Fref);
1992 fll_div->
theta = (target - (fll_div->
n * fratio * Fref))
1994 fll_div->
lambda = (fratio * Fref) / gcd_fll;
1997 pr_debug(
"FLL N=%x THETA=%x LAMBDA=%x\n",
1999 pr_debug(
"FLL_FRATIO=%x FLL_OUTDIV=%x FLL_REFCLK_DIV=%x\n",
2007 unsigned int Fref,
unsigned int Fout)
2009 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
2012 unsigned long timeout;
2029 wm8996_bg_disable(codec);
2052 dev_err(codec->
dev,
"Unknown FLL source %d\n", ret);
2088 wm8996_bg_enable(codec);
2094 WM8996_FLL_ENA, WM8996_FLL_ENA);
2115 for (retry = 0; retry < 10; retry++) {
2128 dev_err(codec->
dev,
"Timed out waiting for FLL\n");
2132 dev_dbg(codec->
dev,
"FLL configured for %dHz->%dHz\n", Fref, Fout);
2141 #ifdef CONFIG_GPIOLIB
2142 static inline struct wm8996_priv *gpio_to_wm8996(
struct gpio_chip *
chip)
2147 static void wm8996_gpio_set(
struct gpio_chip *
chip,
unsigned offset,
int value)
2149 struct wm8996_priv *wm8996 = gpio_to_wm8996(chip);
2155 static int wm8996_gpio_direction_out(
struct gpio_chip *
chip,
2156 unsigned offset,
int value)
2158 struct wm8996_priv *wm8996 = gpio_to_wm8996(chip);
2168 static int wm8996_gpio_get(
struct gpio_chip *chip,
unsigned offset)
2170 struct wm8996_priv *wm8996 = gpio_to_wm8996(chip);
2181 static int wm8996_gpio_direction_in(
struct gpio_chip *chip,
unsigned offset)
2183 struct wm8996_priv *wm8996 = gpio_to_wm8996(chip);
2191 static struct gpio_chip wm8996_template_chip = {
2194 .direction_output = wm8996_gpio_direction_out,
2195 .set = wm8996_gpio_set,
2196 .direction_input = wm8996_gpio_direction_in,
2197 .get = wm8996_gpio_get,
2201 static void wm8996_init_gpio(
struct wm8996_priv *wm8996)
2205 wm8996->gpio_chip = wm8996_template_chip;
2206 wm8996->gpio_chip.ngpio = 5;
2207 wm8996->gpio_chip.
dev = wm8996->
dev;
2209 if (wm8996->
pdata.gpio_base)
2210 wm8996->gpio_chip.base = wm8996->
pdata.gpio_base;
2212 wm8996->gpio_chip.base = -1;
2216 dev_err(wm8996->
dev,
"Failed to add GPIOs: %d\n", ret);
2219 static void wm8996_free_gpio(
struct wm8996_priv *wm8996)
2225 dev_err(wm8996->
dev,
"Failed to remove GPIOs: %d\n", ret);
2228 static void wm8996_init_gpio(
struct wm8996_priv *wm8996)
2232 static void wm8996_free_gpio(
struct wm8996_priv *wm8996)
2251 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
2292 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
2302 dev_err(codec->
dev,
"Failed to read HPDET status\n");
2307 dev_err(codec->
dev,
"Got HPDET IRQ but HPDET is busy\n");
2313 dev_dbg(codec->
dev,
"HPDET measured %d ohms\n", val);
2372 static void wm8996_report_headphone(
struct snd_soc_codec *codec)
2375 wm8996_hpdet_start(codec);
2387 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
2392 dev_dbg(codec->
dev,
"Microphone event: %x\n", val);
2395 dev_warn(codec->
dev,
"Microphone detection state invalid\n");
2401 dev_dbg(codec->
dev,
"Jack removal detected\n");
2423 dev_dbg(codec->
dev,
"Microphone detected\n");
2425 wm8996_hpdet_start(codec);
2448 if (wm8996->
detecting && (val & 0x3f0)) {
2452 wm8996_report_headphone(codec);
2467 dev_dbg(codec->
dev,
"Set microphone polarity to %d\n",
2468 (reg & WM8996_MICD_SRC) != 0);
2478 dev_dbg(codec->
dev,
"Mic button detected\n");
2482 wm8996_report_headphone(codec);
2490 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
2495 dev_err(codec->
dev,
"Failed to read IRQ status: %d\n",
2512 dev_err(codec->
dev,
"Digital core FIFO error\n");
2523 wm8996_hpdet_irq(codec);
2528 static irqreturn_t wm8996_edge_irq(
int irq,
void *data)
2534 val = wm8996_irq(irq, data);
2542 static void wm8996_retune_mobile_pdata(
struct snd_soc_codec *codec)
2544 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
2550 wm8996_get_retune_mobile_enum,
2551 wm8996_put_retune_mobile_enum),
2554 wm8996_get_retune_mobile_enum,
2555 wm8996_put_retune_mobile_enum),
2593 dev_dbg(codec->
dev,
"Allocated %d unique ReTune Mobile names\n",
2602 "Failed to add ReTune Mobile controls: %d\n", ret);
2605 static const struct regmap_config wm8996_regmap = {
2610 .reg_defaults = wm8996_reg,
2612 .volatile_reg = wm8996_volatile_register,
2613 .readable_reg = wm8996_readable_register,
2620 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
2626 init_completion(&wm8996->
dcs_done);
2627 init_completion(&wm8996->
fll_lock);
2633 dev_err(codec->
dev,
"Failed to set cache I/O: %d\n", ret);
2637 if (wm8996->
pdata.num_retune_mobile_cfgs)
2638 wm8996_retune_mobile_pdata(codec);
2644 if (wm8996->
pdata.irq_flags)
2645 irq_flags = wm8996->
pdata.irq_flags;
2654 irq_flags,
"wm8996", codec);
2657 irq_flags,
"wm8996", codec);
2673 dev_err(codec->
dev,
"Failed to request IRQ: %d\n",
2698 .probe = wm8996_probe,
2699 .remove = wm8996_remove,
2700 .set_bias_level = wm8996_set_bias_level,
2701 .idle_bias_off =
true,
2702 .seq_notifier = wm8996_seq_notifier,
2703 .controls = wm8996_snd_controls,
2704 .num_controls =
ARRAY_SIZE(wm8996_snd_controls),
2705 .dapm_widgets = wm8996_dapm_widgets,
2706 .num_dapm_widgets =
ARRAY_SIZE(wm8996_dapm_widgets),
2707 .dapm_routes = wm8996_dapm_routes,
2708 .num_dapm_routes =
ARRAY_SIZE(wm8996_dapm_routes),
2709 .set_pll = wm8996_set_fll,
2712 #define WM8996_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
2713 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
2714 SNDRV_PCM_RATE_48000)
2715 #define WM8996_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\
2716 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE |\
2717 SNDRV_PCM_FMTBIT_S32_LE)
2720 .set_fmt = wm8996_set_fmt,
2721 .hw_params = wm8996_hw_params,
2722 .set_sysclk = wm8996_set_sysclk,
2727 .name =
"wm8996-aif1",
2729 .stream_name =
"AIF1 Playback",
2737 .stream_name =
"AIF1 Capture",
2744 .ops = &wm8996_dai_ops,
2747 .name =
"wm8996-aif2",
2749 .stream_name =
"AIF2 Playback",
2757 .stream_name =
"AIF2 Capture",
2764 .ops = &wm8996_dai_ops,
2780 i2c_set_clientdata(i2c, wm8996);
2783 if (dev_get_platdata(&i2c->
dev))
2785 sizeof(wm8996->
pdata));
2787 if (wm8996->
pdata.ldo_ena > 0) {
2791 dev_err(&i2c->
dev,
"Failed to request GPIO %d: %d\n",
2792 wm8996->
pdata.ldo_ena, ret);
2798 wm8996->
supplies[i].supply = wm8996_supply_names[i];
2803 dev_err(&i2c->
dev,
"Failed to request supplies: %d\n", ret);
2807 wm8996->
disable_nb[0].notifier_call = wm8996_regulator_event_0;
2808 wm8996->
disable_nb[1].notifier_call = wm8996_regulator_event_1;
2809 wm8996->
disable_nb[2].notifier_call = wm8996_regulator_event_2;
2817 "Failed to register regulator notifier: %d\n",
2825 dev_err(&i2c->
dev,
"Failed to enable supplies: %d\n", ret);
2829 if (wm8996->
pdata.ldo_ena > 0) {
2835 if (IS_ERR(wm8996->
regmap)) {
2836 ret = PTR_ERR(wm8996->
regmap);
2837 dev_err(&i2c->
dev,
"regmap_init() failed: %d\n", ret);
2843 dev_err(&i2c->
dev,
"Failed to read ID register: %d\n", ret);
2846 if (reg != 0x8915) {
2847 dev_err(&i2c->
dev,
"Device is not a WM8996, ID %x\n", reg);
2854 dev_err(&i2c->
dev,
"Failed to read device revision: %d\n",
2862 if (wm8996->
pdata.ldo_ena > 0) {
2869 dev_err(&i2c->
dev,
"Failed to issue reset: %d\n", ret);
2880 wm8996->
pdata.inr_mode);
2883 if (!wm8996->
pdata.gpio_default[i])
2887 wm8996->
pdata.gpio_default[i] & 0xffff);
2890 if (wm8996->
pdata.spkmute_seq)
2895 wm8996->
pdata.spkmute_seq);
3035 dev_err(&i2c->
dev,
"Failed to read GPIO1: %d\n", ret);
3039 if (reg & WM8996_GP1_FN_MASK)
3046 dev_err(&i2c->
dev,
"Failed to read GPIO2: %d\n", ret);
3055 wm8996_init_gpio(wm8996);
3058 &soc_codec_dev_wm8996, wm8996_dai,
3066 wm8996_free_gpio(wm8996);
3069 if (wm8996->
pdata.ldo_ena > 0)
3073 if (wm8996->
pdata.ldo_ena > 0)
3082 struct wm8996_priv *wm8996 = i2c_get_clientdata(client);
3086 wm8996_free_gpio(wm8996);
3087 if (wm8996->
pdata.ldo_ena > 0) {
3104 static struct i2c_driver wm8996_i2c_driver = {
3109 .probe = wm8996_i2c_probe,
3111 .id_table = wm8996_i2c_id,