Lines Matching +full:gpio +full:- +full:out +full:- +full:pol
1 // SPDX-License-Identifier: GPL-2.0-only
3 * wm5100.c -- WM5100 ALSA SoC Audio driver
5 * Copyright 2011-2 Wolfson Microelectronics plc
17 #include <linux/gpio/driver.h>
18 #include <linux/gpio/consumer.h>
130 dev_err(component->dev, "Unsupported sample rate: %dHz\n", rate); in wm5100_alloc_sr()
131 return -EINVAL; in wm5100_alloc_sr()
135 if ((wm5100->sysclk % rate) == 0) { in wm5100_alloc_sr()
137 sr_free = -1; in wm5100_alloc_sr()
139 if (!wm5100->sr_ref[i] && sr_free == -1) { in wm5100_alloc_sr()
149 wm5100->sr_ref[i]++; in wm5100_alloc_sr()
150 dev_dbg(component->dev, "SR %dHz, slot %d, ref %d\n", in wm5100_alloc_sr()
151 rate, i, wm5100->sr_ref[i]); in wm5100_alloc_sr()
155 if (sr_free == -1) { in wm5100_alloc_sr()
156 dev_err(component->dev, "All SR slots already in use\n"); in wm5100_alloc_sr()
157 return -EBUSY; in wm5100_alloc_sr()
160 dev_dbg(component->dev, "Allocating SR slot %d for %dHz\n", in wm5100_alloc_sr()
162 wm5100->sr_ref[sr_free]++; in wm5100_alloc_sr()
170 dev_err(component->dev, in wm5100_alloc_sr()
172 rate, wm5100->sysclk, wm5100->asyncclk); in wm5100_alloc_sr()
173 return -EINVAL; in wm5100_alloc_sr()
186 dev_err(component->dev, "Unsupported sample rate: %dHz\n", rate); in wm5100_free_sr()
192 if (!wm5100->sr_ref[i]) in wm5100_free_sr()
200 wm5100->sr_ref[i]--; in wm5100_free_sr()
201 dev_dbg(component->dev, "Dereference SR %dHz, count now %d\n", in wm5100_free_sr()
202 rate, wm5100->sr_ref[i]); in wm5100_free_sr()
204 dev_warn(component->dev, "Freeing unreferenced sample rate %dHz\n", in wm5100_free_sr()
211 if (wm5100->reset) { in wm5100_reset()
212 gpiod_set_value_cansleep(wm5100->reset, 1); in wm5100_reset()
213 gpiod_set_value_cansleep(wm5100->reset, 0); in wm5100_reset()
217 return regmap_write(wm5100->regmap, WM5100_SOFTWARE_RESET, 0); in wm5100_reset()
221 static DECLARE_TLV_DB_SCALE(in_tlv, -6300, 100, 0);
222 static DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
223 static DECLARE_TLV_DB_SCALE(mixer_tlv, -3200, 100, 0);
224 static DECLARE_TLV_DB_SCALE(out_tlv, -6400, 100, 0);
225 static DECLARE_TLV_DB_SCALE(digital_tlv, -6400, 50, 0);
325 0x30, /* AIF3 - check */
507 "Low-pass", "High-pass"
626 /* FIXME: Only valid from -12dB to 0dB (52-64) */
743 if (wm5100->out_ena[0]) { in wm5100_seq_notifier()
748 wm5100->out_ena[0] = false; in wm5100_seq_notifier()
753 dev_err(component->dev, "Timeout waiting for OUTPUT1 %x\n", in wm5100_seq_notifier()
758 if (wm5100->out_ena[1]) { in wm5100_seq_notifier()
763 wm5100->out_ena[1] = false; in wm5100_seq_notifier()
768 dev_err(component->dev, "Timeout waiting for OUTPUT2 %x\n", in wm5100_seq_notifier()
778 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wm5100_out_ev()
781 switch (w->reg) { in wm5100_out_ev()
783 wm5100->out_ena[0] = true; in wm5100_out_ev()
786 wm5100->out_ena[0] = true; in wm5100_out_ev()
798 dev_crit(wm5100->dev, "Speaker shutdown warning\n"); in wm5100_log_status3()
800 dev_crit(wm5100->dev, "Speaker shutdown\n"); in wm5100_log_status3()
802 dev_crit(wm5100->dev, "SYSCLK underclocked\n"); in wm5100_log_status3()
804 dev_crit(wm5100->dev, "ASYNCCLK underclocked\n"); in wm5100_log_status3()
810 dev_err(wm5100->dev, "AIF3 configuration error\n"); in wm5100_log_status4()
812 dev_err(wm5100->dev, "AIF2 configuration error\n"); in wm5100_log_status4()
814 dev_err(wm5100->dev, "AIF1 configuration error\n"); in wm5100_log_status4()
816 dev_err(wm5100->dev, "Control interface error\n"); in wm5100_log_status4()
818 dev_err(wm5100->dev, "ISRC2 underclocked\n"); in wm5100_log_status4()
820 dev_err(wm5100->dev, "ISRC1 underclocked\n"); in wm5100_log_status4()
822 dev_err(wm5100->dev, "FX underclocked\n"); in wm5100_log_status4()
824 dev_err(wm5100->dev, "AIF3 underclocked\n"); in wm5100_log_status4()
826 dev_err(wm5100->dev, "AIF2 underclocked\n"); in wm5100_log_status4()
828 dev_err(wm5100->dev, "AIF1 underclocked\n"); in wm5100_log_status4()
830 dev_err(wm5100->dev, "ASRC underclocked\n"); in wm5100_log_status4()
832 dev_err(wm5100->dev, "DAC underclocked\n"); in wm5100_log_status4()
834 dev_err(wm5100->dev, "ADC underclocked\n"); in wm5100_log_status4()
836 dev_err(wm5100->dev, "Mixer underclocked\n"); in wm5100_log_status4()
843 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wm5100_post_ev()
1077 * look at the error status from the CODEC - if we've got the IRQ
1284 struct snd_soc_component *component = dai->component; in wm5100_set_fmt()
1287 base = dai->driver->base; in wm5100_set_fmt()
1300 dev_err(component->dev, "Unsupported DAI format %d\n", in wm5100_set_fmt()
1302 return -EINVAL; in wm5100_set_fmt()
1319 dev_err(component->dev, "Unsupported master mode %d\n", in wm5100_set_fmt()
1321 return -EINVAL; in wm5100_set_fmt()
1338 return -EINVAL; in wm5100_set_fmt()
1402 struct snd_soc_component *component = dai->component; in wm5100_hw_params()
1404 bool async = wm5100->aif_async[dai->id]; in wm5100_hw_params()
1408 base = dai->driver->base; in wm5100_hw_params()
1418 dev_dbg(component->dev, "Word length %d bits, frame length %d bits\n", in wm5100_hw_params()
1428 aif_rate = wm5100->sysclk; in wm5100_hw_params()
1434 aif_rate = wm5100->asyncclk; in wm5100_hw_params()
1441 dev_err(component->dev, "Invalid rate %dHzn", in wm5100_hw_params()
1443 return -EINVAL; in wm5100_hw_params()
1452 dev_err(component->dev, "%s has no rate set\n", in wm5100_hw_params()
1454 return -EINVAL; in wm5100_hw_params()
1457 dev_dbg(component->dev, "Target BCLK is %dHz, using %dHz %s\n", in wm5100_hw_params()
1469 dev_err(component->dev, in wm5100_hw_params()
1472 return -EINVAL; in wm5100_hw_params()
1476 dev_dbg(component->dev, "Setting %dHz BCLK\n", bclk_rates[bclk]); in wm5100_hw_params()
1480 dev_dbg(component->dev, "Setting %dHz LRCLK\n", bclk_rates[bclk] / lrclk); in wm5100_hw_params()
1481 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK || in wm5100_hw_params()
1482 wm5100->aif_symmetric[dai->id]) in wm5100_hw_params()
1490 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in wm5100_hw_params()
1519 rate_store = &wm5100->sysclk; in wm5100_set_sysclk()
1523 rate_store = &wm5100->asyncclk; in wm5100_set_sysclk()
1536 return -EINVAL; in wm5100_set_sysclk()
1546 wm5100->aif_async[clk_id - 1] = false; in wm5100_set_sysclk()
1549 wm5100->aif_async[clk_id - 1] = true; in wm5100_set_sysclk()
1552 dev_err(component->dev, "Invalid source %d\n", source); in wm5100_set_sysclk()
1553 return -EINVAL; in wm5100_set_sysclk()
1575 dev_err(component->dev, "Unsupported OPCLK %dHz\n", in wm5100_set_sysclk()
1577 return -EINVAL; in wm5100_set_sysclk()
1582 dev_err(component->dev, "Unknown clock %d\n", clk_id); in wm5100_set_sysclk()
1583 return -EINVAL; in wm5100_set_sysclk()
1589 dev_err(component->dev, "Invalid source %d\n", source); in wm5100_set_sysclk()
1590 return -EINVAL; in wm5100_set_sysclk()
1607 dev_err(component->dev, "Invalid clock rate: %d\n", freq); in wm5100_set_sysclk()
1608 return -EINVAL; in wm5100_set_sysclk()
1643 dev_dbg(component->dev, "Setting primary audio rate to %dHz", in wm5100_set_sysclk()
1649 dev_warn(component->dev, "Primary audio slot is %d\n", in wm5100_set_sysclk()
1690 fll_div->fll_refclk_div = 0; in fll_factors()
1693 fll_div->fll_refclk_div++; in fll_factors()
1698 return -EINVAL; in fll_factors()
1707 /* Fvco should be 90-100MHz; don't check the upper bound */ in fll_factors()
1714 return -EINVAL; in fll_factors()
1718 fll_div->fll_outdiv = div - 1; in fll_factors()
1722 /* Find an appropraite FLL_FRATIO and factor it out of the target */ in fll_factors()
1725 fll_div->fll_fratio = fll_fratios[i].fll_fratio; in fll_factors()
1732 return -EINVAL; in fll_factors()
1735 fll_div->n = target / (fratio * Fref); in fll_factors()
1738 fll_div->theta = 0; in fll_factors()
1739 fll_div->lambda = 0; in fll_factors()
1743 fll_div->theta = (target - (fll_div->n * fratio * Fref)) in fll_factors()
1745 fll_div->lambda = (fratio * Fref) / gcd_fll; in fll_factors()
1749 fll_div->n, fll_div->theta, fll_div->lambda); in fll_factors()
1751 fll_div->fll_fratio, fratio, fll_div->fll_outdiv, in fll_factors()
1752 fll_div->fll_refclk_div); in fll_factors()
1760 struct i2c_client *i2c = to_i2c_client(component->dev); in wm5100_set_fll()
1769 fll = &wm5100->fll[0]; in wm5100_set_fll()
1770 base = WM5100_FLL1_CONTROL_1 - 1; in wm5100_set_fll()
1774 fll = &wm5100->fll[1]; in wm5100_set_fll()
1775 base = WM5100_FLL2_CONTROL_2 - 1; in wm5100_set_fll()
1779 dev_err(component->dev, "Unknown FLL %d\n",fll_id); in wm5100_set_fll()
1780 return -EINVAL; in wm5100_set_fll()
1784 dev_dbg(component->dev, "FLL%d disabled", fll_id); in wm5100_set_fll()
1785 if (fll->fout) in wm5100_set_fll()
1786 pm_runtime_put(component->dev); in wm5100_set_fll()
1787 fll->fout = 0; in wm5100_set_fll()
1802 dev_err(component->dev, "Invalid FLL source %d\n", source); in wm5100_set_fll()
1803 return -EINVAL; in wm5100_set_fll()
1829 try_wait_for_completion(&fll->lock); in wm5100_set_fll()
1831 pm_runtime_get_sync(component->dev); in wm5100_set_fll()
1835 if (i2c->irq) in wm5100_set_fll()
1845 if (i2c->irq) { in wm5100_set_fll()
1846 time_left = wait_for_completion_timeout(&fll->lock, in wm5100_set_fll()
1857 dev_err(component->dev, in wm5100_set_fll()
1866 dev_err(component->dev, "FLL%d lock timed out\n", fll_id); in wm5100_set_fll()
1867 pm_runtime_put(component->dev); in wm5100_set_fll()
1868 return -ETIMEDOUT; in wm5100_set_fll()
1871 fll->src = source; in wm5100_set_fll()
1872 fll->fref = Fref; in wm5100_set_fll()
1873 fll->fout = Fout; in wm5100_set_fll()
1875 dev_dbg(component->dev, "FLL%d running %dHz->%dHz\n", fll_id, in wm5100_set_fll()
1889 .name = "wm5100-aif1",
1890 .base = WM5100_AUDIO_IF_1_1 - 1,
1908 .name = "wm5100-aif2",
1910 .base = WM5100_AUDIO_IF_2_1 - 1,
1928 .name = "wm5100-aif3",
1930 .base = WM5100_AUDIO_IF_3_1 - 1,
1975 struct wm5100_jack_mode *mode = &wm5100->pdata.jack_modes[the_mode]; in wm5100_set_detect_mode()
1977 if (WARN_ON(the_mode >= ARRAY_SIZE(wm5100->pdata.jack_modes))) in wm5100_set_detect_mode()
1980 gpiod_set_value_cansleep(wm5100->hp_pol, mode->hp_pol); in wm5100_set_detect_mode()
1981 regmap_update_bits(wm5100->regmap, WM5100_ACCESSORY_DETECT_MODE_1, in wm5100_set_detect_mode()
1984 (mode->bias << WM5100_ACCDET_BIAS_SRC_SHIFT) | in wm5100_set_detect_mode()
1985 mode->micd_src << WM5100_ACCDET_SRC_SHIFT); in wm5100_set_detect_mode()
1986 regmap_update_bits(wm5100->regmap, WM5100_MISC_CONTROL, in wm5100_set_detect_mode()
1988 mode->micd_src << WM5100_HPCOM_SRC_SHIFT); in wm5100_set_detect_mode()
1990 wm5100->jack_mode = the_mode; in wm5100_set_detect_mode()
1992 dev_dbg(wm5100->dev, "Set microphone polarity to %d\n", in wm5100_set_detect_mode()
1993 wm5100->jack_mode); in wm5100_set_detect_mode()
1998 dev_dbg(wm5100->dev, "Headphone detected\n"); in wm5100_report_headphone()
1999 wm5100->jack_detecting = false; in wm5100_report_headphone()
2000 snd_soc_jack_report(wm5100->jack, SND_JACK_HEADPHONE, in wm5100_report_headphone()
2004 regmap_update_bits(wm5100->regmap, WM5100_MIC_DETECT_1, in wm5100_report_headphone()
2014 ret = regmap_read(wm5100->regmap, WM5100_MIC_DETECT_3, &val); in wm5100_micd_irq()
2016 dev_err(wm5100->dev, "Failed to read microphone status: %d\n", in wm5100_micd_irq()
2021 dev_dbg(wm5100->dev, "Microphone event: %x\n", val); in wm5100_micd_irq()
2024 dev_warn(wm5100->dev, "Microphone detection state invalid\n"); in wm5100_micd_irq()
2030 dev_dbg(wm5100->dev, "Jack removal detected\n"); in wm5100_micd_irq()
2031 wm5100->jack_mic = false; in wm5100_micd_irq()
2032 wm5100->jack_detecting = true; in wm5100_micd_irq()
2033 wm5100->jack_flips = 0; in wm5100_micd_irq()
2034 snd_soc_jack_report(wm5100->jack, 0, in wm5100_micd_irq()
2038 regmap_update_bits(wm5100->regmap, WM5100_MIC_DETECT_1, in wm5100_micd_irq()
2049 if (wm5100->jack_detecting) { in wm5100_micd_irq()
2050 dev_dbg(wm5100->dev, "Microphone detected\n"); in wm5100_micd_irq()
2051 wm5100->jack_mic = true; in wm5100_micd_irq()
2052 wm5100->jack_detecting = false; in wm5100_micd_irq()
2053 snd_soc_jack_report(wm5100->jack, in wm5100_micd_irq()
2059 regmap_update_bits(wm5100->regmap, WM5100_MIC_DETECT_1, in wm5100_micd_irq()
2063 dev_dbg(wm5100->dev, "Mic button up\n"); in wm5100_micd_irq()
2064 snd_soc_jack_report(wm5100->jack, 0, SND_JACK_BTN_0); in wm5100_micd_irq()
2076 if (wm5100->jack_detecting && (val & 0x3f8)) { in wm5100_micd_irq()
2077 wm5100->jack_flips++; in wm5100_micd_irq()
2079 if (wm5100->jack_flips > 1) in wm5100_micd_irq()
2082 wm5100_set_detect_mode(wm5100, !wm5100->jack_mode); in wm5100_micd_irq()
2091 if (wm5100->jack_mic) { in wm5100_micd_irq()
2092 dev_dbg(wm5100->dev, "Mic button detected\n"); in wm5100_micd_irq()
2093 snd_soc_jack_report(wm5100->jack, SND_JACK_BTN_0, in wm5100_micd_irq()
2095 } else if (wm5100->jack_detecting) { in wm5100_micd_irq()
2107 wm5100->jack = jack; in wm5100_detect()
2108 wm5100->jack_detecting = true; in wm5100_detect()
2109 wm5100->jack_flips = 0; in wm5100_detect()
2131 /* We start off just enabling microphone detection - even a in wm5100_detect()
2147 wm5100->jack = NULL; in wm5100_detect()
2161 ret = regmap_read(wm5100->regmap, WM5100_INTERRUPT_STATUS_3, &irq_val); in wm5100_irq()
2163 dev_err(wm5100->dev, "Failed to read IRQ status 3: %d\n", in wm5100_irq()
2168 ret = regmap_read(wm5100->regmap, WM5100_INTERRUPT_STATUS_3_MASK, in wm5100_irq()
2171 dev_err(wm5100->dev, "Failed to read IRQ mask 3: %d\n", in wm5100_irq()
2178 regmap_write(wm5100->regmap, WM5100_INTERRUPT_STATUS_3, irq_val); in wm5100_irq()
2186 dev_dbg(wm5100->dev, "FLL1 locked\n"); in wm5100_irq()
2187 complete(&wm5100->fll[0].lock); in wm5100_irq()
2190 dev_dbg(wm5100->dev, "FLL2 locked\n"); in wm5100_irq()
2191 complete(&wm5100->fll[1].lock); in wm5100_irq()
2197 ret = regmap_read(wm5100->regmap, WM5100_INTERRUPT_STATUS_4, &irq_val); in wm5100_irq()
2199 dev_err(wm5100->dev, "Failed to read IRQ status 4: %d\n", in wm5100_irq()
2204 ret = regmap_read(wm5100->regmap, WM5100_INTERRUPT_STATUS_4_MASK, in wm5100_irq()
2207 dev_err(wm5100->dev, "Failed to read IRQ mask 4: %d\n", in wm5100_irq()
2217 regmap_write(wm5100->regmap, WM5100_INTERRUPT_STATUS_4, irq_val); in wm5100_irq()
2243 regmap_update_bits(wm5100->regmap, WM5100_GPIO_CTRL_1 + offset, in wm5100_gpio_set()
2255 ret = regmap_update_bits(wm5100->regmap, WM5100_GPIO_CTRL_1 + offset, in wm5100_gpio_direction_out()
2270 ret = regmap_read(wm5100->regmap, WM5100_GPIO_CTRL_1 + offset, ®); in wm5100_gpio_get()
2281 return regmap_update_bits(wm5100->regmap, WM5100_GPIO_CTRL_1 + offset, in wm5100_gpio_direction_in()
2302 wm5100->gpio_chip = wm5100_template_chip; in wm5100_init_gpio()
2303 wm5100->gpio_chip.ngpio = 6; in wm5100_init_gpio()
2304 wm5100->gpio_chip.parent = &i2c->dev; in wm5100_init_gpio()
2305 wm5100->gpio_chip.base = -1; in wm5100_init_gpio()
2307 ret = gpiochip_add_data(&wm5100->gpio_chip, wm5100); in wm5100_init_gpio()
2309 dev_err(&i2c->dev, "Failed to add GPIOs: %d\n", ret); in wm5100_init_gpio()
2316 gpiochip_remove(&wm5100->gpio_chip); in wm5100_free_gpio()
2331 struct i2c_client *i2c = to_i2c_client(component->dev); in wm5100_probe()
2335 wm5100->component = component; in wm5100_probe()
2347 if (i2c->irq) in wm5100_probe()
2351 wm5100->hp_pol = devm_gpiod_get_optional(&i2c->dev, "hp-pol", in wm5100_probe()
2353 if (IS_ERR(wm5100->hp_pol)) { in wm5100_probe()
2354 ret = PTR_ERR(wm5100->hp_pol); in wm5100_probe()
2355 dev_err(&i2c->dev, "Failed to request HP_POL GPIO: %d\n", in wm5100_probe()
2399 struct wm5100_pdata *pdata = dev_get_platdata(&i2c->dev); in wm5100_i2c_probe()
2404 wm5100 = devm_kzalloc(&i2c->dev, sizeof(struct wm5100_priv), in wm5100_i2c_probe()
2407 return -ENOMEM; in wm5100_i2c_probe()
2409 wm5100->dev = &i2c->dev; in wm5100_i2c_probe()
2411 wm5100->regmap = devm_regmap_init_i2c(i2c, &wm5100_regmap); in wm5100_i2c_probe()
2412 if (IS_ERR(wm5100->regmap)) { in wm5100_i2c_probe()
2413 ret = PTR_ERR(wm5100->regmap); in wm5100_i2c_probe()
2414 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", in wm5100_i2c_probe()
2419 for (i = 0; i < ARRAY_SIZE(wm5100->fll); i++) in wm5100_i2c_probe()
2420 init_completion(&wm5100->fll[i].lock); in wm5100_i2c_probe()
2423 wm5100->pdata = *pdata; in wm5100_i2c_probe()
2427 for (i = 0; i < ARRAY_SIZE(wm5100->core_supplies); i++) in wm5100_i2c_probe()
2428 wm5100->core_supplies[i].supply = wm5100_core_supply_names[i]; in wm5100_i2c_probe()
2430 ret = devm_regulator_bulk_get(&i2c->dev, in wm5100_i2c_probe()
2431 ARRAY_SIZE(wm5100->core_supplies), in wm5100_i2c_probe()
2432 wm5100->core_supplies); in wm5100_i2c_probe()
2434 dev_err(&i2c->dev, "Failed to request core supplies: %d\n", in wm5100_i2c_probe()
2439 ret = regulator_bulk_enable(ARRAY_SIZE(wm5100->core_supplies), in wm5100_i2c_probe()
2440 wm5100->core_supplies); in wm5100_i2c_probe()
2442 dev_err(&i2c->dev, "Failed to enable core supplies: %d\n", in wm5100_i2c_probe()
2447 wm5100->ldo_ena = devm_gpiod_get_optional(&i2c->dev, "wlf,ldo1ena", in wm5100_i2c_probe()
2449 if (IS_ERR(wm5100->ldo_ena)) { in wm5100_i2c_probe()
2450 ret = PTR_ERR(wm5100->ldo_ena); in wm5100_i2c_probe()
2451 dev_err(&i2c->dev, "Failed to request LDOENA GPIO: %d\n", ret); in wm5100_i2c_probe()
2454 if (wm5100->ldo_ena) { in wm5100_i2c_probe()
2455 gpiod_set_consumer_name(wm5100->ldo_ena, "WM5100 LDOENA"); in wm5100_i2c_probe()
2459 wm5100->reset = devm_gpiod_get_optional(&i2c->dev, "reset", in wm5100_i2c_probe()
2461 if (IS_ERR(wm5100->reset)) { in wm5100_i2c_probe()
2462 ret = PTR_ERR(wm5100->reset); in wm5100_i2c_probe()
2463 dev_err(&i2c->dev, "Failed to request /RESET GPIO: %d\n", ret); in wm5100_i2c_probe()
2466 gpiod_set_consumer_name(wm5100->reset, "WM5100 /RESET"); in wm5100_i2c_probe()
2468 ret = regmap_read(wm5100->regmap, WM5100_SOFTWARE_RESET, ®); in wm5100_i2c_probe()
2470 dev_err(&i2c->dev, "Failed to read ID register: %d\n", ret); in wm5100_i2c_probe()
2479 dev_err(&i2c->dev, "Device is not a WM5100, ID is %x\n", reg); in wm5100_i2c_probe()
2480 ret = -EINVAL; in wm5100_i2c_probe()
2484 ret = regmap_read(wm5100->regmap, WM5100_DEVICE_REVISION, ®); in wm5100_i2c_probe()
2486 dev_err(&i2c->dev, "Failed to read revision register\n"); in wm5100_i2c_probe()
2489 wm5100->rev = reg & WM5100_DEVICE_REVISION_MASK; in wm5100_i2c_probe()
2491 dev_info(&i2c->dev, "revision %c\n", wm5100->rev + 'A'); in wm5100_i2c_probe()
2495 dev_err(&i2c->dev, "Failed to issue reset\n"); in wm5100_i2c_probe()
2499 switch (wm5100->rev) { in wm5100_i2c_probe()
2501 ret = regmap_register_patch(wm5100->regmap, in wm5100_i2c_probe()
2505 dev_err(&i2c->dev, "Failed to register patches: %d\n", in wm5100_i2c_probe()
2517 for (i = 0; i < ARRAY_SIZE(wm5100->pdata.gpio_defaults); i++) { in wm5100_i2c_probe()
2518 if (!wm5100->pdata.gpio_defaults[i]) in wm5100_i2c_probe()
2521 regmap_write(wm5100->regmap, WM5100_GPIO_CTRL_1 + i, in wm5100_i2c_probe()
2522 wm5100->pdata.gpio_defaults[i]); in wm5100_i2c_probe()
2525 for (i = 0; i < ARRAY_SIZE(wm5100->pdata.in_mode); i++) { in wm5100_i2c_probe()
2526 regmap_update_bits(wm5100->regmap, wm5100_mic_ctrl_reg[i], in wm5100_i2c_probe()
2529 (wm5100->pdata.in_mode[i] << in wm5100_i2c_probe()
2531 (wm5100->pdata.dmic_sup[i] << in wm5100_i2c_probe()
2535 if (i2c->irq) { in wm5100_i2c_probe()
2536 if (wm5100->pdata.irq_flags) in wm5100_i2c_probe()
2537 irq_flags = wm5100->pdata.irq_flags; in wm5100_i2c_probe()
2544 ret = request_threaded_irq(i2c->irq, NULL, in wm5100_i2c_probe()
2548 ret = request_threaded_irq(i2c->irq, NULL, wm5100_irq, in wm5100_i2c_probe()
2553 dev_err(&i2c->dev, "Failed to request IRQ %d: %d\n", in wm5100_i2c_probe()
2554 i2c->irq, ret); in wm5100_i2c_probe()
2557 regmap_update_bits(wm5100->regmap, in wm5100_i2c_probe()
2568 regmap_update_bits(wm5100->regmap, in wm5100_i2c_probe()
2587 pm_runtime_set_active(&i2c->dev); in wm5100_i2c_probe()
2588 pm_runtime_enable(&i2c->dev); in wm5100_i2c_probe()
2589 pm_request_idle(&i2c->dev); in wm5100_i2c_probe()
2591 ret = devm_snd_soc_register_component(&i2c->dev, in wm5100_i2c_probe()
2595 dev_err(&i2c->dev, "Failed to register WM5100: %d\n", ret); in wm5100_i2c_probe()
2602 pm_runtime_disable(&i2c->dev); in wm5100_i2c_probe()
2603 if (i2c->irq) in wm5100_i2c_probe()
2604 free_irq(i2c->irq, wm5100); in wm5100_i2c_probe()
2606 gpiod_set_value_cansleep(wm5100->reset, 1); in wm5100_i2c_probe()
2608 gpiod_set_value_cansleep(wm5100->ldo_ena, 0); in wm5100_i2c_probe()
2610 regulator_bulk_disable(ARRAY_SIZE(wm5100->core_supplies), in wm5100_i2c_probe()
2611 wm5100->core_supplies); in wm5100_i2c_probe()
2620 pm_runtime_disable(&i2c->dev); in wm5100_i2c_remove()
2621 if (i2c->irq) in wm5100_i2c_remove()
2622 free_irq(i2c->irq, wm5100); in wm5100_i2c_remove()
2624 gpiod_set_value_cansleep(wm5100->reset, 1); in wm5100_i2c_remove()
2625 gpiod_set_value_cansleep(wm5100->ldo_ena, 0); in wm5100_i2c_remove()
2633 regcache_cache_only(wm5100->regmap, true); in wm5100_runtime_suspend()
2634 regcache_mark_dirty(wm5100->regmap); in wm5100_runtime_suspend()
2635 gpiod_set_value_cansleep(wm5100->ldo_ena, 0); in wm5100_runtime_suspend()
2636 regulator_bulk_disable(ARRAY_SIZE(wm5100->core_supplies), in wm5100_runtime_suspend()
2637 wm5100->core_supplies); in wm5100_runtime_suspend()
2647 ret = regulator_bulk_enable(ARRAY_SIZE(wm5100->core_supplies), in wm5100_runtime_resume()
2648 wm5100->core_supplies); in wm5100_runtime_resume()
2655 if (wm5100->ldo_ena) { in wm5100_runtime_resume()
2656 gpiod_set_value_cansleep(wm5100->ldo_ena, 1); in wm5100_runtime_resume()
2660 regcache_cache_only(wm5100->regmap, false); in wm5100_runtime_resume()
2661 regcache_sync(wm5100->regmap); in wm5100_runtime_resume()