18 #include <linux/module.h>
25 #include <linux/i2c.h>
27 #include <linux/slab.h>
42 static const struct reg_default wm8903_reg_defaults[] = {
141 #ifdef CONFIG_GPIOLIB
142 struct gpio_chip gpio_chip;
146 static bool wm8903_readable_register(
struct device *
dev,
unsigned int reg)
232 static bool wm8903_volatile_register(
struct device *dev,
unsigned int reg)
263 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
278 #define WM8903_DCS_MODE_WRITE_STOP 0
279 #define WM8903_DCS_MODE_START_STOP 2
286 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
292 dev_dbg(codec->
dev,
"Starting DC servo for %x\n",
302 "Restore DC servo %d value %x\n",
309 "Calibrate DC servo %d\n", 3 - i);
348 pr_warn(
"DCS mode %d delay not set\n", dcs_mode);
364 static int wm8903_class_w_put(
struct snd_kcontrol *kcontrol,
370 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
377 if (ucontrol->
value.integer.value[0]) {
390 if (!ucontrol->
value.integer.value[0]) {
399 dev_dbg(codec->
dev,
"Bypass use count now %d\n",
405 #define SOC_DAPM_SINGLE_W(xname, reg, shift, max, invert) \
406 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
407 .info = snd_soc_info_volsw, \
408 .get = snd_soc_dapm_get_volsw, .put = wm8903_class_w_put, \
409 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
412 static int wm8903_deemph[] = { 0, 32000, 44100, 48000 };
416 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
424 for (i = 2; i <
ARRAY_SIZE(wm8903_deemph); i++) {
425 if (
abs(wm8903_deemph[i] - wm8903->
fs) <
426 abs(wm8903_deemph[best] - wm8903->
fs))
436 dev_dbg(codec->
dev,
"Set deemphasis %d (%dHz)\n",
437 best, wm8903_deemph[best]);
443 static int wm8903_get_deemph(
struct snd_kcontrol *kcontrol,
447 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
449 ucontrol->
value.enumerated.item[0] = wm8903->
deemph;
454 static int wm8903_put_deemph(
struct snd_kcontrol *kcontrol,
458 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
466 if (wm8903->
deemph != deemph) {
469 wm8903_set_deemph(codec);
490 static const char *hpf_mode_text[] = {
491 "Hi-fi",
"Voice 1",
"Voice 2",
"Voice 3"
494 static const struct soc_enum hpf_mode =
497 static const char *osr_text[] = {
498 "Low power",
"High performance"
501 static const struct soc_enum adc_osr =
504 static const struct soc_enum dac_osr =
507 static const char *drc_slope_text[] = {
508 "1",
"1/2",
"1/4",
"1/8",
"1/16",
"0"
511 static const struct soc_enum drc_slope_r0 =
514 static const struct soc_enum drc_slope_r1 =
517 static const char *drc_attack_text[] = {
519 "363us",
"762us",
"1.45ms",
"2.9ms",
"5.8ms",
"11.6ms",
"23.2ms",
520 "46.4ms",
"92.8ms",
"185.6ms"
523 static const struct soc_enum drc_attack =
526 static const char *drc_decay_text[] = {
527 "186ms",
"372ms",
"743ms",
"1.49s",
"2.97s",
"5.94s",
"11.89s",
531 static const struct soc_enum drc_decay =
534 static const char *drc_ff_delay_text[] = {
535 "5 samples",
"9 samples"
538 static const struct soc_enum drc_ff_delay =
541 static const char *drc_qr_decay_text[] = {
542 "0.725ms",
"1.45ms",
"5.8ms"
545 static const struct soc_enum drc_qr_decay =
548 static const char *drc_smoothing_text[] = {
549 "Low",
"Medium",
"High"
552 static const struct soc_enum drc_smoothing =
555 static const char *soft_mute_text[] = {
556 "Fast (fs/2)",
"Slow (fs/32)"
559 static const struct soc_enum soft_mute =
562 static const char *mute_mode_text[] = {
566 static const struct soc_enum mute_mode =
569 static const char *companding_text[] = {
573 static const struct soc_enum dac_companding =
576 static const struct soc_enum adc_companding =
579 static const char *input_mode_text[] = {
580 "Single-Ended",
"Differential Line",
"Differential Mic"
583 static const struct soc_enum linput_mode_enum =
586 static const struct soc_enum rinput_mode_enum =
589 static const char *linput_mux_text[] = {
590 "IN1L",
"IN2L",
"IN3L"
593 static const struct soc_enum linput_enum =
596 static const struct soc_enum linput_inv_enum =
599 static const char *rinput_mux_text[] = {
600 "IN1R",
"IN2R",
"IN3R"
603 static const struct soc_enum rinput_enum =
606 static const struct soc_enum rinput_inv_enum =
610 static const char *sidetone_text[] = {
611 "None",
"Left",
"Right"
614 static const struct soc_enum lsidetone_enum =
617 static const struct soc_enum rsidetone_enum =
620 static const char *adcinput_text[] = {
624 static const struct soc_enum adcinput_enum =
627 static const char *aif_text[] = {
631 static const struct soc_enum lcapture_enum =
634 static const struct soc_enum rcapture_enum =
637 static const struct soc_enum lplay_enum =
640 static const struct soc_enum rplay_enum =
665 SOC_ENUM(
"DRC Compressor Slope R0", drc_slope_r0),
666 SOC_ENUM(
"DRC Compressor Slope R1", drc_slope_r1),
672 SOC_ENUM(
"DRC Attack Rate", drc_attack),
673 SOC_ENUM(
"DRC Decay Rate", drc_decay),
674 SOC_ENUM(
"DRC FF Delay", drc_ff_delay),
678 SOC_ENUM(
"DRC QR Decay Rate", drc_qr_decay),
681 SOC_ENUM(
"DRC Smoothing Threshold", drc_smoothing),
686 SOC_ENUM(
"ADC Companding Mode", adc_companding),
690 12, 0, digital_sidetone_tlv),
696 SOC_ENUM(
"DAC Soft Mute Rate", soft_mute),
697 SOC_ENUM(
"DAC Mute Mode", mute_mode),
699 SOC_ENUM(
"DAC Companding Mode", dac_companding),
702 wm8903_get_deemph, wm8903_put_deemph),
864 left_output_mixer,
ARRAY_SIZE(left_output_mixer)),
866 right_output_mixer,
ARRAY_SIZE(right_output_mixer)),
869 left_speaker_mixer,
ARRAY_SIZE(left_speaker_mixer)),
871 right_speaker_mixer,
ARRAY_SIZE(right_speaker_mixer)),
932 {
"CLK_DSP",
NULL,
"CLK_SYS" },
933 {
"MICBIAS",
NULL,
"CLK_SYS" },
934 {
"HPL_DCS",
NULL,
"CLK_SYS" },
935 {
"HPR_DCS",
NULL,
"CLK_SYS" },
936 {
"LINEOUTL_DCS",
NULL,
"CLK_SYS" },
937 {
"LINEOUTR_DCS",
NULL,
"CLK_SYS" },
939 {
"Left Input Mux",
"IN1L",
"IN1L" },
940 {
"Left Input Mux",
"IN2L",
"IN2L" },
941 {
"Left Input Mux",
"IN3L",
"IN3L" },
943 {
"Left Input Inverting Mux",
"IN1L",
"IN1L" },
944 {
"Left Input Inverting Mux",
"IN2L",
"IN2L" },
945 {
"Left Input Inverting Mux",
"IN3L",
"IN3L" },
947 {
"Right Input Mux",
"IN1R",
"IN1R" },
948 {
"Right Input Mux",
"IN2R",
"IN2R" },
949 {
"Right Input Mux",
"IN3R",
"IN3R" },
951 {
"Right Input Inverting Mux",
"IN1R",
"IN1R" },
952 {
"Right Input Inverting Mux",
"IN2R",
"IN2R" },
953 {
"Right Input Inverting Mux",
"IN3R",
"IN3R" },
955 {
"Left Input Mode Mux",
"Single-Ended",
"Left Input Inverting Mux" },
956 {
"Left Input Mode Mux",
"Differential Line",
958 {
"Left Input Mode Mux",
"Differential Line",
959 "Left Input Inverting Mux" },
960 {
"Left Input Mode Mux",
"Differential Mic",
962 {
"Left Input Mode Mux",
"Differential Mic",
963 "Left Input Inverting Mux" },
965 {
"Right Input Mode Mux",
"Single-Ended",
966 "Right Input Inverting Mux" },
967 {
"Right Input Mode Mux",
"Differential Line",
969 {
"Right Input Mode Mux",
"Differential Line",
970 "Right Input Inverting Mux" },
971 {
"Right Input Mode Mux",
"Differential Mic",
973 {
"Right Input Mode Mux",
"Differential Mic",
974 "Right Input Inverting Mux" },
976 {
"Left Input PGA",
NULL,
"Left Input Mode Mux" },
977 {
"Right Input PGA",
NULL,
"Right Input Mode Mux" },
979 {
"Left ADC Input",
"ADC",
"Left Input PGA" },
980 {
"Left ADC Input",
"DMIC",
"DMICDAT" },
981 {
"Right ADC Input",
"ADC",
"Right Input PGA" },
982 {
"Right ADC Input",
"DMIC",
"DMICDAT" },
984 {
"Left Capture Mux",
"Left",
"ADCL" },
985 {
"Left Capture Mux",
"Right",
"ADCR" },
987 {
"Right Capture Mux",
"Left",
"ADCL" },
988 {
"Right Capture Mux",
"Right",
"ADCR" },
990 {
"AIFTXL",
NULL,
"Left Capture Mux" },
991 {
"AIFTXR",
NULL,
"Right Capture Mux" },
993 {
"ADCL",
NULL,
"Left ADC Input" },
994 {
"ADCL",
NULL,
"CLK_DSP" },
995 {
"ADCR",
NULL,
"Right ADC Input" },
996 {
"ADCR",
NULL,
"CLK_DSP" },
998 {
"Left Playback Mux",
"Left",
"AIFRXL" },
999 {
"Left Playback Mux",
"Right",
"AIFRXR" },
1001 {
"Right Playback Mux",
"Left",
"AIFRXL" },
1002 {
"Right Playback Mux",
"Right",
"AIFRXR" },
1004 {
"DACL Sidetone",
"Left",
"ADCL" },
1005 {
"DACL Sidetone",
"Right",
"ADCR" },
1006 {
"DACR Sidetone",
"Left",
"ADCL" },
1007 {
"DACR Sidetone",
"Right",
"ADCR" },
1009 {
"DACL",
NULL,
"Left Playback Mux" },
1010 {
"DACL",
NULL,
"DACL Sidetone" },
1011 {
"DACL",
NULL,
"CLK_DSP" },
1013 {
"DACR",
NULL,
"Right Playback Mux" },
1014 {
"DACR",
NULL,
"DACR Sidetone" },
1015 {
"DACR",
NULL,
"CLK_DSP" },
1017 {
"Left Output Mixer",
"Left Bypass Switch",
"Left Input PGA" },
1018 {
"Left Output Mixer",
"Right Bypass Switch",
"Right Input PGA" },
1019 {
"Left Output Mixer",
"DACL Switch",
"DACL" },
1020 {
"Left Output Mixer",
"DACR Switch",
"DACR" },
1022 {
"Right Output Mixer",
"Left Bypass Switch",
"Left Input PGA" },
1023 {
"Right Output Mixer",
"Right Bypass Switch",
"Right Input PGA" },
1024 {
"Right Output Mixer",
"DACL Switch",
"DACL" },
1025 {
"Right Output Mixer",
"DACR Switch",
"DACR" },
1027 {
"Left Speaker Mixer",
"Left Bypass Switch",
"Left Input PGA" },
1028 {
"Left Speaker Mixer",
"Right Bypass Switch",
"Right Input PGA" },
1029 {
"Left Speaker Mixer",
"DACL Switch",
"DACL" },
1030 {
"Left Speaker Mixer",
"DACR Switch",
"DACR" },
1032 {
"Right Speaker Mixer",
"Left Bypass Switch",
"Left Input PGA" },
1033 {
"Right Speaker Mixer",
"Right Bypass Switch",
"Right Input PGA" },
1034 {
"Right Speaker Mixer",
"DACL Switch",
"DACL" },
1035 {
"Right Speaker Mixer",
"DACR Switch",
"DACR" },
1037 {
"Left Line Output PGA",
NULL,
"Left Output Mixer" },
1038 {
"Right Line Output PGA",
NULL,
"Right Output Mixer" },
1040 {
"Left Headphone Output PGA",
NULL,
"Left Output Mixer" },
1041 {
"Right Headphone Output PGA",
NULL,
"Right Output Mixer" },
1043 {
"Left Speaker PGA",
NULL,
"Left Speaker Mixer" },
1044 {
"Right Speaker PGA",
NULL,
"Right Speaker Mixer" },
1046 {
"HPL_ENA",
NULL,
"Left Headphone Output PGA" },
1047 {
"HPR_ENA",
NULL,
"Right Headphone Output PGA" },
1048 {
"HPL_ENA_DLY",
NULL,
"HPL_ENA" },
1049 {
"HPR_ENA_DLY",
NULL,
"HPR_ENA" },
1050 {
"LINEOUTL_ENA",
NULL,
"Left Line Output PGA" },
1051 {
"LINEOUTR_ENA",
NULL,
"Right Line Output PGA" },
1052 {
"LINEOUTL_ENA_DLY",
NULL,
"LINEOUTL_ENA" },
1053 {
"LINEOUTR_ENA_DLY",
NULL,
"LINEOUTR_ENA" },
1055 {
"HPL_DCS",
NULL,
"DCS Master" },
1056 {
"HPR_DCS",
NULL,
"DCS Master" },
1057 {
"LINEOUTL_DCS",
NULL,
"DCS Master" },
1058 {
"LINEOUTR_DCS",
NULL,
"DCS Master" },
1060 {
"HPL_DCS",
NULL,
"HPL_ENA_DLY" },
1061 {
"HPR_DCS",
NULL,
"HPR_ENA_DLY" },
1062 {
"LINEOUTL_DCS",
NULL,
"LINEOUTL_ENA_DLY" },
1063 {
"LINEOUTR_DCS",
NULL,
"LINEOUTR_ENA_DLY" },
1065 {
"HPL_ENA_OUTP",
NULL,
"HPL_DCS" },
1066 {
"HPR_ENA_OUTP",
NULL,
"HPR_DCS" },
1067 {
"LINEOUTL_ENA_OUTP",
NULL,
"LINEOUTL_DCS" },
1068 {
"LINEOUTR_ENA_OUTP",
NULL,
"LINEOUTR_DCS" },
1070 {
"HPL_RMV_SHORT",
NULL,
"HPL_ENA_OUTP" },
1071 {
"HPR_RMV_SHORT",
NULL,
"HPR_ENA_OUTP" },
1072 {
"LINEOUTL_RMV_SHORT",
NULL,
"LINEOUTL_ENA_OUTP" },
1073 {
"LINEOUTR_RMV_SHORT",
NULL,
"LINEOUTR_ENA_OUTP" },
1075 {
"HPOUTL",
NULL,
"HPL_RMV_SHORT" },
1076 {
"HPOUTR",
NULL,
"HPR_RMV_SHORT" },
1077 {
"LINEOUTL",
NULL,
"LINEOUTL_RMV_SHORT" },
1078 {
"LINEOUTR",
NULL,
"LINEOUTR_RMV_SHORT" },
1080 {
"LOP",
NULL,
"Left Speaker PGA" },
1081 {
"LON",
NULL,
"Left Speaker PGA" },
1083 {
"ROP",
NULL,
"Right Speaker PGA" },
1084 {
"RON",
NULL,
"Right Speaker PGA" },
1086 {
"Left Headphone Output PGA",
NULL,
"Charge Pump" },
1087 {
"Right Headphone Output PGA",
NULL,
"Charge Pump" },
1088 {
"Left Line Output PGA",
NULL,
"Charge Pump" },
1089 {
"Right Line Output PGA",
NULL,
"Charge Pump" },
1092 static int wm8903_set_bias_level(
struct snd_soc_codec *codec,
1206 static int wm8903_set_dai_sysclk(
struct snd_soc_dai *codec_dai,
1207 int clk_id,
unsigned int freq,
int dir)
1210 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
1217 static int wm8903_set_dai_fmt(
struct snd_soc_dai *codec_dai,
1262 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1279 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
1304 static int wm8903_digital_mute(
struct snd_soc_dai *codec_dai,
int mute)
1329 } clk_sys_ratios[] = {
1330 { 64, 0x0, 0x0, 1 },
1331 { 68, 0x0, 0x1, 1 },
1332 { 125, 0x0, 0x2, 1 },
1333 { 128, 0x1, 0x0, 1 },
1334 { 136, 0x1, 0x1, 1 },
1335 { 192, 0x2, 0x0, 1 },
1336 { 204, 0x2, 0x1, 1 },
1338 { 64, 0x0, 0x0, 2 },
1339 { 68, 0x0, 0x1, 2 },
1340 { 125, 0x0, 0x2, 2 },
1341 { 128, 0x1, 0x0, 2 },
1342 { 136, 0x1, 0x1, 2 },
1343 { 192, 0x2, 0x0, 2 },
1344 { 204, 0x2, 0x1, 2 },
1346 { 250, 0x2, 0x2, 1 },
1347 { 256, 0x3, 0x0, 1 },
1348 { 272, 0x3, 0x1, 1 },
1349 { 384, 0x4, 0x0, 1 },
1350 { 408, 0x4, 0x1, 1 },
1351 { 375, 0x4, 0x2, 1 },
1352 { 512, 0x5, 0x0, 1 },
1353 { 544, 0x5, 0x1, 1 },
1354 { 500, 0x5, 0x2, 1 },
1355 { 768, 0x6, 0x0, 1 },
1356 { 816, 0x6, 0x1, 1 },
1357 { 750, 0x6, 0x2, 1 },
1358 { 1024, 0x7, 0x0, 1 },
1359 { 1088, 0x7, 0x1, 1 },
1360 { 1000, 0x7, 0x2, 1 },
1361 { 1408, 0x8, 0x0, 1 },
1362 { 1496, 0x8, 0x1, 1 },
1363 { 1536, 0x9, 0x0, 1 },
1364 { 1632, 0x9, 0x1, 1 },
1365 { 1500, 0x9, 0x2, 1 },
1367 { 250, 0x2, 0x2, 2 },
1368 { 256, 0x3, 0x0, 2 },
1369 { 272, 0x3, 0x1, 2 },
1370 { 384, 0x4, 0x0, 2 },
1371 { 408, 0x4, 0x1, 2 },
1372 { 375, 0x4, 0x2, 2 },
1373 { 512, 0x5, 0x0, 2 },
1374 { 544, 0x5, 0x1, 2 },
1375 { 500, 0x5, 0x2, 2 },
1376 { 768, 0x6, 0x0, 2 },
1377 { 816, 0x6, 0x1, 2 },
1378 { 750, 0x6, 0x2, 2 },
1379 { 1024, 0x7, 0x0, 2 },
1380 { 1088, 0x7, 0x1, 2 },
1381 { 1000, 0x7, 0x2, 2 },
1382 { 1408, 0x8, 0x0, 2 },
1383 { 1496, 0x8, 0x1, 2 },
1384 { 1536, 0x9, 0x0, 2 },
1385 { 1632, 0x9, 0x1, 2 },
1386 { 1500, 0x9, 0x2, 2 },
1417 } sample_rates[] = {
1437 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
1463 best_val =
abs(sample_rates[dsp_config].
rate - fs);
1464 for (i = 1; i <
ARRAY_SIZE(sample_rates); i++) {
1465 cur_val =
abs(sample_rates[i].
rate - fs);
1466 if (cur_val <= best_val) {
1472 dev_dbg(codec->
dev,
"DSP fs = %dHz\n", sample_rates[dsp_config].rate);
1474 clock1 |= sample_rates[dsp_config].value;
1498 dev_dbg(codec->
dev,
"MCLK = %dHz, target sample rate = %dHz\n",
1507 (clk_sys_ratios[0].mclk_div *
1508 clk_sys_ratios[0].div)) - fs);
1509 for (i = 1; i <
ARRAY_SIZE(clk_sys_ratios); i++) {
1511 (clk_sys_ratios[i].mclk_div *
1512 clk_sys_ratios[i].div)) - fs);
1514 if (cur_val <= best_val) {
1520 if (clk_sys_ratios[clk_config].
mclk_div == 2) {
1522 clk_sys = wm8903->
sysclk / 2;
1525 clk_sys = wm8903->
sysclk;
1533 dev_dbg(codec->
dev,
"CLK_SYS_RATE=%x, CLK_SYS_MODE=%x div=%d\n",
1534 clk_sys_ratios[clk_config].rate,
1535 clk_sys_ratios[clk_config].mode,
1536 clk_sys_ratios[clk_config].div);
1538 dev_dbg(codec->
dev,
"Actual CLK_SYS = %dHz\n", clk_sys);
1546 best_val = ((clk_sys * 10) / bclk_divs[0].
ratio) -
bclk;
1549 cur_val = ((clk_sys * 10) / bclk_divs[i].ratio) -
bclk;
1560 dev_dbg(codec->
dev,
"BCLK ratio %d for %dHz - actual BCLK = %dHz\n",
1561 bclk_divs[bclk_div].ratio / 10, bclk,
1562 (clk_sys * 10) / bclk_divs[bclk_div].ratio);
1568 wm8903_set_deemph(codec);
1600 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
1603 dev_dbg(codec->
dev,
"Enabling microphone detection: %x %x\n",
1640 int mic_report,
ret;
1641 unsigned int int_val,
mask, int_pol;
1646 dev_err(wm8903->
dev,
"Failed to read IRQ mask: %d\n", ret);
1652 dev_err(wm8903->
dev,
"Failed to read IRQ status: %d\n", ret);
1673 dev_err(wm8903->
dev,
"Failed to read interrupt polarity: %d\n",
1678 #ifndef CONFIG_SND_SOC_WM8903_MODULE
1680 trace_snd_soc_jack_irq(dev_name(wm8903->
dev));
1684 dev_dbg(wm8903->
dev,
"Microphone short (pol=%x)\n", int_pol);
1691 dev_dbg(wm8903->
dev,
"Microphone detect (pol=%x)\n", int_pol);
1693 mic_report ^= wm8903->
mic_det;
1710 #define WM8903_PLAYBACK_RATES (SNDRV_PCM_RATE_8000 |\
1711 SNDRV_PCM_RATE_11025 | \
1712 SNDRV_PCM_RATE_16000 | \
1713 SNDRV_PCM_RATE_22050 | \
1714 SNDRV_PCM_RATE_32000 | \
1715 SNDRV_PCM_RATE_44100 | \
1716 SNDRV_PCM_RATE_48000 | \
1717 SNDRV_PCM_RATE_88200 | \
1718 SNDRV_PCM_RATE_96000)
1720 #define WM8903_CAPTURE_RATES (SNDRV_PCM_RATE_8000 |\
1721 SNDRV_PCM_RATE_11025 | \
1722 SNDRV_PCM_RATE_16000 | \
1723 SNDRV_PCM_RATE_22050 | \
1724 SNDRV_PCM_RATE_32000 | \
1725 SNDRV_PCM_RATE_44100 | \
1726 SNDRV_PCM_RATE_48000)
1728 #define WM8903_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
1729 SNDRV_PCM_FMTBIT_S20_3LE |\
1730 SNDRV_PCM_FMTBIT_S24_LE)
1733 .hw_params = wm8903_hw_params,
1734 .digital_mute = wm8903_digital_mute,
1735 .set_fmt = wm8903_set_dai_fmt,
1736 .set_sysclk = wm8903_set_dai_sysclk,
1740 .name =
"wm8903-hifi",
1742 .stream_name =
"Playback",
1749 .stream_name =
"Capture",
1755 .ops = &wm8903_dai_ops,
1756 .symmetric_rates = 1,
1768 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
1777 #ifdef CONFIG_GPIOLIB
1778 static inline struct wm8903_priv *gpio_to_wm8903(
struct gpio_chip *
chip)
1783 static int wm8903_gpio_request(
struct gpio_chip *
chip,
unsigned offset)
1791 static int wm8903_gpio_direction_in(
struct gpio_chip *chip,
unsigned offset)
1793 struct wm8903_priv *wm8903 = gpio_to_wm8903(chip);
1809 static int wm8903_gpio_get(
struct gpio_chip *chip,
unsigned offset)
1811 struct wm8903_priv *wm8903 = gpio_to_wm8903(chip);
1819 static int wm8903_gpio_direction_out(
struct gpio_chip *chip,
1820 unsigned offset,
int value)
1822 struct wm8903_priv *wm8903 = gpio_to_wm8903(chip);
1838 static void wm8903_gpio_set(
struct gpio_chip *chip,
unsigned offset,
int value)
1840 struct wm8903_priv *wm8903 = gpio_to_wm8903(chip);
1847 static struct gpio_chip wm8903_template_chip = {
1850 .request = wm8903_gpio_request,
1851 .direction_input = wm8903_gpio_direction_in,
1852 .get = wm8903_gpio_get,
1853 .direction_output = wm8903_gpio_direction_out,
1854 .set = wm8903_gpio_set,
1858 static void wm8903_init_gpio(
struct wm8903_priv *wm8903)
1863 wm8903->gpio_chip = wm8903_template_chip;
1865 wm8903->gpio_chip.
dev = wm8903->
dev;
1868 wm8903->gpio_chip.base = pdata->
gpio_base;
1870 wm8903->gpio_chip.base = -1;
1874 dev_err(wm8903->
dev,
"Failed to add GPIOs: %d\n", ret);
1877 static void wm8903_free_gpio(
struct wm8903_priv *wm8903)
1883 dev_err(wm8903->
dev,
"Failed to remove GPIOs: %d\n", ret);
1886 static void wm8903_init_gpio(
struct wm8903_priv *wm8903)
1890 static void wm8903_free_gpio(
struct wm8903_priv *wm8903)
1897 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
1905 dev_err(codec->
dev,
"Failed to set cache I/O: %d\n", ret);
1924 .probe = wm8903_probe,
1925 .remove = wm8903_remove,
1926 .suspend = wm8903_suspend,
1927 .resume = wm8903_resume,
1928 .set_bias_level = wm8903_set_bias_level,
1929 .seq_notifier = wm8903_seq_notifier,
1930 .controls = wm8903_snd_controls,
1931 .num_controls =
ARRAY_SIZE(wm8903_snd_controls),
1932 .dapm_widgets = wm8903_dapm_widgets,
1933 .num_dapm_widgets =
ARRAY_SIZE(wm8903_dapm_widgets),
1934 .dapm_routes = wm8903_intercon,
1935 .num_dapm_routes =
ARRAY_SIZE(wm8903_intercon),
1938 static const struct regmap_config wm8903_regmap = {
1943 .volatile_reg = wm8903_volatile_register,
1944 .readable_reg = wm8903_readable_register,
1947 .reg_defaults = wm8903_reg_defaults,
1948 .num_reg_defaults =
ARRAY_SIZE(wm8903_reg_defaults),
1951 static int wm8903_set_pdata_irq_trigger(
struct i2c_client *i2c,
1961 switch (irqd_get_trigger_type(irq_data)) {
1980 static int wm8903_set_pdata_from_of(
struct i2c_client *i2c,
1987 if (of_property_read_u32(np,
"micdet-cfg", &val32) >= 0)
1990 if (of_property_read_u32(np,
"micdet-delay", &val32) >= 0)
2010 }
else if (pdata->
gpio_cfg[i] == 0xffffffff) {
2012 }
else if (pdata->
gpio_cfg[i] > 0x7fff) {
2013 dev_err(&i2c->
dev,
"Invalid gpio-cfg[%d] %x\n",
2029 bool mic_gpio =
false;
2030 unsigned int val, irq_pol;
2040 if (IS_ERR(wm8903->
regmap)) {
2041 ret = PTR_ERR(wm8903->
regmap);
2042 dev_err(&i2c->
dev,
"Failed to allocate register map: %d\n",
2047 i2c_set_clientdata(i2c, wm8903);
2057 dev_err(&i2c->
dev,
"Failed to allocate pdata\n");
2062 ret = wm8903_set_pdata_irq_trigger(i2c, wm8903->
pdata);
2067 if (i2c->
dev.of_node) {
2068 ret = wm8903_set_pdata_from_of(i2c, wm8903->
pdata);
2074 pdata = wm8903->
pdata;
2078 dev_err(&i2c->
dev,
"Failed to read chip ID: %d\n", ret);
2081 if (val != 0x8903) {
2082 dev_err(&i2c->
dev,
"Device with ID %x is not a WM8903\n", val);
2089 dev_err(&i2c->
dev,
"Failed to read chip revision: %d\n", ret);
2098 wm8903_init_gpio(wm8903);
2157 dev_err(wm8903->
dev,
"Failed to request IRQ: %d\n",
2200 &soc_codec_dev_wm8903, &wm8903_dai, 1);
2211 struct wm8903_priv *wm8903 = i2c_get_clientdata(client);
2215 wm8903_free_gpio(wm8903);
2222 { .compatible =
"wlf,wm8903", },
2233 static struct i2c_driver wm8903_i2c_driver = {
2237 .of_match_table = wm8903_of_match,
2239 .probe = wm8903_i2c_probe,
2241 .id_table = wm8903_i2c_id,