Lines Matching +full:digital +full:- +full:input +full:- +full:short +full:- +full:circuit +full:- +full:detection
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * wm8996.c - WM8996 audio codec interface
5 * Copyright 2011-2 Wolfson Microelectronics PLC.
108 regcache_mark_dirty(wm8996->regmap); \
299 static const DECLARE_TLV_DB_SCALE(sidetone_tlv, -3600, 150, 0);
300 static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1);
301 static const DECLARE_TLV_DB_SCALE(out_digital_tlv, -1200, 150, 0);
302 static const DECLARE_TLV_DB_SCALE(out_tlv, -900, 75, 0);
303 static const DECLARE_TLV_DB_SCALE(spk_tlv, -900, 150, 0);
304 static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
305 static const DECLARE_TLV_DB_SCALE(threedstereo_tlv, -1600, 183, 1);
337 struct wm8996_pdata *pdata = &wm8996->pdata; in wm8996_set_retune_mobile()
340 if (!wm8996->num_retune_mobile_texts) in wm8996_set_retune_mobile()
366 cfg = wm8996->retune_mobile_cfg[block]; in wm8996_set_retune_mobile()
369 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) { in wm8996_set_retune_mobile()
370 if (strcmp(pdata->retune_mobile_cfgs[i].name, in wm8996_set_retune_mobile()
371 wm8996->retune_mobile_texts[cfg]) == 0 && in wm8996_set_retune_mobile()
372 abs(pdata->retune_mobile_cfgs[i].rate in wm8996_set_retune_mobile()
373 - wm8996->rx_rate[iface]) < best_val) { in wm8996_set_retune_mobile()
375 best_val = abs(pdata->retune_mobile_cfgs[i].rate in wm8996_set_retune_mobile()
376 - wm8996->rx_rate[iface]); in wm8996_set_retune_mobile()
380 dev_dbg(component->dev, "ReTune Mobile %d %s/%dHz for %dHz sample rate\n", in wm8996_set_retune_mobile()
382 pdata->retune_mobile_cfgs[best].name, in wm8996_set_retune_mobile()
383 pdata->retune_mobile_cfgs[best].rate, in wm8996_set_retune_mobile()
384 wm8996->rx_rate[iface]); in wm8996_set_retune_mobile()
392 for (i = 0; i < ARRAY_SIZE(pdata->retune_mobile_cfgs[best].regs); i++) in wm8996_set_retune_mobile()
394 pdata->retune_mobile_cfgs[best].regs[i]); in wm8996_set_retune_mobile()
406 return -EINVAL; in wm8996_get_retune_mobile_block()
414 struct wm8996_pdata *pdata = &wm8996->pdata; in wm8996_put_retune_mobile_enum()
415 int block = wm8996_get_retune_mobile_block(kcontrol->id.name); in wm8996_put_retune_mobile_enum()
416 int value = ucontrol->value.enumerated.item[0]; in wm8996_put_retune_mobile_enum()
421 if (value >= pdata->num_retune_mobile_cfgs) in wm8996_put_retune_mobile_enum()
422 return -EINVAL; in wm8996_put_retune_mobile_enum()
424 wm8996->retune_mobile_cfg[block] = value; in wm8996_put_retune_mobile_enum()
436 int block = wm8996_get_retune_mobile_block(kcontrol->id.name); in wm8996_get_retune_mobile_enum()
440 ucontrol->value.enumerated.item[0] = wm8996->retune_mobile_cfg[block]; in wm8996_get_retune_mobile_enum()
456 SOC_ENUM("Sidetone HPF Cut-off", sidetone_hpf),
510 SOC_DOUBLE_TLV("Digital Output 1 Volume", WM8996_DAC1_HPOUT1_VOLUME, 0, 4,
512 SOC_DOUBLE_TLV("Digital Output 2 Volume", WM8996_DAC2_HPOUT2_VOLUME, 0, 4,
578 wm8996->bg_ena++; in wm8996_bg_enable()
579 if (wm8996->bg_ena == 1) { in wm8996_bg_enable()
590 wm8996->bg_ena--; in wm8996_bg_disable()
591 if (!wm8996->bg_ena) in wm8996_bg_disable()
599 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in bg_event()
611 ret = -EINVAL; in bg_event()
634 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in rmv_short_event()
640 wm8996->hpout_pending &= ~w->shift; in rmv_short_event()
643 wm8996->hpout_pending |= w->shift; in rmv_short_event()
647 return -EINVAL; in rmv_short_event()
655 struct i2c_client *i2c = to_i2c_client(component->dev); in wait_for_dc_servo()
664 if (i2c->irq) { in wait_for_dc_servo()
665 timeout = wait_for_completion_timeout(&wm8996->dcs_done, in wait_for_dc_servo()
668 dev_err(component->dev, "DC servo timed out\n"); in wait_for_dc_servo()
672 timeout--; in wait_for_dc_servo()
676 dev_dbg(component->dev, "DC servo state: %x\n", ret); in wait_for_dc_servo()
680 dev_err(component->dev, "DC servo timed out for %x\n", mask); in wait_for_dc_servo()
682 dev_dbg(component->dev, "DC servo complete for %x\n", mask); in wait_for_dc_servo()
692 if (wm8996->dcs_pending) { in wm8996_seq_notifier()
693 dev_dbg(component->dev, "Starting DC servo for %x\n", in wm8996_seq_notifier()
694 wm8996->dcs_pending); in wm8996_seq_notifier()
697 wait_for_dc_servo(component, wm8996->dcs_pending in wm8996_seq_notifier()
700 wm8996->dcs_pending = 0; in wm8996_seq_notifier()
703 if (wm8996->hpout_pending != wm8996->hpout_ena) { in wm8996_seq_notifier()
704 dev_dbg(component->dev, "Applying RMV_SHORTs %x->%x\n", in wm8996_seq_notifier()
705 wm8996->hpout_ena, wm8996->hpout_pending); in wm8996_seq_notifier()
709 if (wm8996->hpout_pending & HPOUT1L) { in wm8996_seq_notifier()
718 if (wm8996->hpout_pending & HPOUT1R) { in wm8996_seq_notifier()
731 if (wm8996->hpout_pending & HPOUT2L) { in wm8996_seq_notifier()
740 if (wm8996->hpout_pending & HPOUT2R) { in wm8996_seq_notifier()
751 wm8996->hpout_ena = wm8996->hpout_pending; in wm8996_seq_notifier()
758 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in dcs_start()
763 wm8996->dcs_pending |= 1 << w->shift; in dcs_start()
767 return -EINVAL; in dcs_start()
1539 if (wm8996->sysclk < 64000) in wm8996_update_bclk()
1552 bclk_rate = wm8996->bclk_rate[aif]; in wm8996_update_bclk()
1557 cur_val = (wm8996->sysclk / bclk_divs[i]) - bclk_rate; in wm8996_update_bclk()
1562 bclk_rate = wm8996->sysclk / bclk_divs[best]; in wm8996_update_bclk()
1563 dev_dbg(component->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n", in wm8996_update_bclk()
1590 ret = regulator_bulk_enable(ARRAY_SIZE(wm8996->supplies), in wm8996_set_bias_level()
1591 wm8996->supplies); in wm8996_set_bias_level()
1593 dev_err(component->dev, in wm8996_set_bias_level()
1599 if (wm8996->pdata.ldo_ena >= 0) { in wm8996_set_bias_level()
1600 gpio_set_value_cansleep(wm8996->pdata.ldo_ena, in wm8996_set_bias_level()
1605 regcache_cache_only(wm8996->regmap, false); in wm8996_set_bias_level()
1606 regcache_sync(wm8996->regmap); in wm8996_set_bias_level()
1617 regcache_cache_only(wm8996->regmap, true); in wm8996_set_bias_level()
1618 if (wm8996->pdata.ldo_ena >= 0) { in wm8996_set_bias_level()
1619 gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 0); in wm8996_set_bias_level()
1620 regcache_cache_only(wm8996->regmap, true); in wm8996_set_bias_level()
1622 regulator_bulk_disable(ARRAY_SIZE(wm8996->supplies), in wm8996_set_bias_level()
1623 wm8996->supplies); in wm8996_set_bias_level()
1632 struct snd_soc_component *component = dai->component; in wm8996_set_fmt()
1639 switch (dai->id) { in wm8996_set_fmt()
1653 WARN(1, "Invalid dai id %d\n", dai->id); in wm8996_set_fmt()
1654 return -EINVAL; in wm8996_set_fmt()
1690 return -EINVAL; in wm8996_set_fmt()
1706 return -EINVAL; in wm8996_set_fmt()
1733 struct snd_soc_component *component = dai->component; in wm8996_hw_params()
1741 switch (dai->id) { in wm8996_hw_params()
1743 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK || in wm8996_hw_params()
1754 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK || in wm8996_hw_params()
1765 WARN(1, "Invalid dai id %d\n", dai->id); in wm8996_hw_params()
1766 return -EINVAL; in wm8996_hw_params()
1771 dev_err(component->dev, "Unsupported BCLK rate: %d\n", bclk_rate); in wm8996_hw_params()
1775 wm8996->bclk_rate[dai->id] = bclk_rate; in wm8996_hw_params()
1776 wm8996->rx_rate[dai->id] = params_rate(params); in wm8996_hw_params()
1786 if (abs(dsp_divs[i] - params_rate(params)) < in wm8996_hw_params()
1787 abs(dsp_divs[best] - params_rate(params))) in wm8996_hw_params()
1795 dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n", in wm8996_hw_params()
1813 struct snd_soc_component *component = dai->component; in wm8996_set_sysclk()
1821 if (freq == wm8996->sysclk && clk_id == wm8996->sysclk_src) in wm8996_set_sysclk()
1831 wm8996->sysclk = freq; in wm8996_set_sysclk()
1835 wm8996->sysclk = freq; in wm8996_set_sysclk()
1839 wm8996->sysclk = freq; in wm8996_set_sysclk()
1843 dev_err(component->dev, "Unsupported clock source %d\n", clk_id); in wm8996_set_sysclk()
1844 return -EINVAL; in wm8996_set_sysclk()
1847 switch (wm8996->sysclk) { in wm8996_set_sysclk()
1856 wm8996->sysclk /= 2; in wm8996_set_sysclk()
1869 dev_warn(component->dev, "Unsupported clock rate %dHz\n", in wm8996_set_sysclk()
1870 wm8996->sysclk); in wm8996_set_sysclk()
1871 return -EINVAL; in wm8996_set_sysclk()
1885 wm8996->sysclk_src = clk_id; in wm8996_set_sysclk()
1924 fll_div->fll_refclk_div = 0; in fll_factors()
1927 fll_div->fll_refclk_div++; in fll_factors()
1930 pr_err("Can't scale %dMHz input down to <=13.5MHz\n", in fll_factors()
1932 return -EINVAL; in fll_factors()
1942 fll_div->fll_loop_gain = 5; in fll_factors()
1944 fll_div->fll_loop_gain = 0; in fll_factors()
1947 fll_div->fll_ref_freq = 0; in fll_factors()
1949 fll_div->fll_ref_freq = 1; in fll_factors()
1951 /* Fvco should be 90-100MHz; don't check the upper bound */ in fll_factors()
1958 return -EINVAL; in fll_factors()
1962 fll_div->fll_outdiv = div - 1; in fll_factors()
1969 fll_div->fll_fratio = fll_fratios[i].fll_fratio; in fll_factors()
1976 return -EINVAL; in fll_factors()
1979 fll_div->n = target / (fratio * Fref); in fll_factors()
1982 fll_div->theta = 0; in fll_factors()
1983 fll_div->lambda = 0; in fll_factors()
1987 fll_div->theta = (target - (fll_div->n * fratio * Fref)) in fll_factors()
1989 fll_div->lambda = (fratio * Fref) / gcd_fll; in fll_factors()
1993 fll_div->n, fll_div->theta, fll_div->lambda); in fll_factors()
1995 fll_div->fll_fratio, fll_div->fll_outdiv, in fll_factors()
1996 fll_div->fll_refclk_div); in fll_factors()
2005 struct i2c_client *i2c = to_i2c_client(component->dev); in wm8996_set_fll()
2011 if (source == wm8996->fll_src && Fref == wm8996->fll_fref && in wm8996_set_fll()
2012 Fout == wm8996->fll_fout) in wm8996_set_fll()
2016 dev_dbg(component->dev, "FLL disabled\n"); in wm8996_set_fll()
2018 wm8996->fll_fref = 0; in wm8996_set_fll()
2019 wm8996->fll_fout = 0; in wm8996_set_fll()
2047 dev_err(component->dev, "Unknown FLL source %d\n", ret); in wm8996_set_fll()
2048 return -EINVAL; in wm8996_set_fll()
2086 try_wait_for_completion(&wm8996->fll_lock); in wm8996_set_fll()
2091 /* The FLL supports live reconfiguration - kick that in case we were in wm8996_set_fll()
2105 if (i2c->irq) in wm8996_set_fll()
2112 time_left = wait_for_completion_timeout(&wm8996->fll_lock, in wm8996_set_fll()
2115 WARN_ON(!i2c->irq); in wm8996_set_fll()
2125 dev_err(component->dev, "Timed out waiting for FLL\n"); in wm8996_set_fll()
2126 ret = -ETIMEDOUT; in wm8996_set_fll()
2129 dev_dbg(component->dev, "FLL configured for %dHz->%dHz\n", Fref, Fout); in wm8996_set_fll()
2131 wm8996->fll_fref = Fref; in wm8996_set_fll()
2132 wm8996->fll_fout = Fout; in wm8996_set_fll()
2133 wm8996->fll_src = source; in wm8996_set_fll()
2143 regmap_update_bits(wm8996->regmap, WM8996_GPIO_1 + offset, in wm8996_gpio_set()
2155 return regmap_update_bits(wm8996->regmap, WM8996_GPIO_1 + offset, in wm8996_gpio_direction_out()
2166 ret = regmap_read(wm8996->regmap, WM8996_GPIO_1 + offset, ®); in wm8996_gpio_get()
2177 return regmap_update_bits(wm8996->regmap, WM8996_GPIO_1 + offset, in wm8996_gpio_direction_in()
2197 wm8996->gpio_chip = wm8996_template_chip; in wm8996_init_gpio()
2198 wm8996->gpio_chip.ngpio = 5; in wm8996_init_gpio()
2199 wm8996->gpio_chip.parent = wm8996->dev; in wm8996_init_gpio()
2201 if (wm8996->pdata.gpio_base) in wm8996_init_gpio()
2202 wm8996->gpio_chip.base = wm8996->pdata.gpio_base; in wm8996_init_gpio()
2204 wm8996->gpio_chip.base = -1; in wm8996_init_gpio()
2206 ret = gpiochip_add_data(&wm8996->gpio_chip, wm8996); in wm8996_init_gpio()
2208 dev_err(wm8996->dev, "Failed to add GPIOs: %d\n", ret); in wm8996_init_gpio()
2213 gpiochip_remove(&wm8996->gpio_chip); in wm8996_free_gpio()
2226 * wm8996_detect - Enable default WM8996 jack detection
2231 * The WM8996 has advanced accessory detection support for headsets.
2235 * This will detect headset, headphone and short circuit button and
2245 wm8996->jack = jack; in wm8996_detect()
2246 wm8996->detecting = true; in wm8996_detect()
2247 wm8996->polarity_cb = polarity_cb; in wm8996_detect()
2248 wm8996->jack_flips = 0; in wm8996_detect()
2250 if (wm8996->polarity_cb) in wm8996_detect()
2251 wm8996->polarity_cb(component, 0); in wm8996_detect()
2253 /* Clear discarge to avoid noise during detection */ in wm8996_detect()
2259 /* LDO2 powers the microphones, SYSCLK clocks detection */ in wm8996_detect()
2267 /* We start off just enabling microphone detection - even a in wm8996_detect()
2268 * plain headphone will trigger detection. in wm8996_detect()
2273 /* Slowest detection rate, gives debounce for initial detection */ in wm8996_detect()
2299 dev_err(component->dev, "Failed to read HPDET status\n"); in wm8996_hpdet_irq()
2304 dev_err(component->dev, "Got HPDET IRQ but HPDET is busy\n"); in wm8996_hpdet_irq()
2310 dev_dbg(component->dev, "HPDET measured %d ohms\n", val); in wm8996_hpdet_irq()
2321 if (wm8996->jack_mic) in wm8996_hpdet_irq()
2324 snd_soc_jack_report(wm8996->jack, report, in wm8996_hpdet_irq()
2327 wm8996->detecting = false; in wm8996_hpdet_irq()
2329 /* If the output isn't running re-clamp it */ in wm8996_hpdet_irq()
2373 dev_dbg(component->dev, "Headphone detected\n"); in wm8996_report_headphone()
2376 /* Increase the detection rate a bit for responsiveness. */ in wm8996_report_headphone()
2391 dev_dbg(component->dev, "Microphone event: %x\n", val); in wm8996_micd()
2394 dev_warn(component->dev, "Microphone detection state invalid\n"); in wm8996_micd()
2400 dev_dbg(component->dev, "Jack removal detected\n"); in wm8996_micd()
2401 wm8996->jack_mic = false; in wm8996_micd()
2402 wm8996->detecting = true; in wm8996_micd()
2403 wm8996->jack_flips = 0; in wm8996_micd()
2404 snd_soc_jack_report(wm8996->jack, 0, in wm8996_micd()
2421 if (wm8996->detecting) { in wm8996_micd()
2422 dev_dbg(component->dev, "Microphone detected\n"); in wm8996_micd()
2423 wm8996->jack_mic = true; in wm8996_micd()
2434 dev_dbg(component->dev, "Mic button up\n"); in wm8996_micd()
2435 snd_soc_jack_report(wm8996->jack, 0, SND_JACK_BTN_0); in wm8996_micd()
2443 * do this for the lowest impedences to speed up detection of in wm8996_micd()
2447 if (wm8996->detecting && (val & 0x3f0)) { in wm8996_micd()
2448 wm8996->jack_flips++; in wm8996_micd()
2450 if (wm8996->jack_flips > 1) { in wm8996_micd()
2462 if (wm8996->polarity_cb) in wm8996_micd()
2463 wm8996->polarity_cb(component, in wm8996_micd()
2466 dev_dbg(component->dev, "Set microphone polarity to %d\n", in wm8996_micd()
2476 if (wm8996->jack_mic) { in wm8996_micd()
2477 dev_dbg(component->dev, "Mic button detected\n"); in wm8996_micd()
2478 snd_soc_jack_report(wm8996->jack, SND_JACK_BTN_0, in wm8996_micd()
2480 } else if (wm8996->detecting) { in wm8996_micd()
2494 dev_err(component->dev, "Failed to read IRQ status: %d\n", in wm8996_irq()
2506 dev_dbg(component->dev, "DC servo IRQ\n"); in wm8996_irq()
2507 complete(&wm8996->dcs_done); in wm8996_irq()
2511 dev_err(component->dev, "Digital core FIFO error\n"); in wm8996_irq()
2514 dev_dbg(component->dev, "FLL locked\n"); in wm8996_irq()
2515 complete(&wm8996->fll_lock); in wm8996_irq()
2544 struct wm8996_pdata *pdata = &wm8996->pdata; in wm8996_retune_mobile_pdata()
2548 wm8996->retune_mobile_enum, in wm8996_retune_mobile_pdata()
2552 wm8996->retune_mobile_enum, in wm8996_retune_mobile_pdata()
2563 wm8996->num_retune_mobile_texts = 0; in wm8996_retune_mobile_pdata()
2564 wm8996->retune_mobile_texts = NULL; in wm8996_retune_mobile_pdata()
2565 for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) { in wm8996_retune_mobile_pdata()
2566 for (j = 0; j < wm8996->num_retune_mobile_texts; j++) { in wm8996_retune_mobile_pdata()
2567 if (strcmp(pdata->retune_mobile_cfgs[i].name, in wm8996_retune_mobile_pdata()
2568 wm8996->retune_mobile_texts[j]) == 0) in wm8996_retune_mobile_pdata()
2572 if (j != wm8996->num_retune_mobile_texts) in wm8996_retune_mobile_pdata()
2576 t = krealloc(wm8996->retune_mobile_texts, in wm8996_retune_mobile_pdata()
2578 (wm8996->num_retune_mobile_texts + 1), in wm8996_retune_mobile_pdata()
2584 t[wm8996->num_retune_mobile_texts] = in wm8996_retune_mobile_pdata()
2585 pdata->retune_mobile_cfgs[i].name; in wm8996_retune_mobile_pdata()
2588 wm8996->num_retune_mobile_texts++; in wm8996_retune_mobile_pdata()
2589 wm8996->retune_mobile_texts = t; in wm8996_retune_mobile_pdata()
2592 dev_dbg(component->dev, "Allocated %d unique ReTune Mobile names\n", in wm8996_retune_mobile_pdata()
2593 wm8996->num_retune_mobile_texts); in wm8996_retune_mobile_pdata()
2595 wm8996->retune_mobile_enum.items = wm8996->num_retune_mobile_texts; in wm8996_retune_mobile_pdata()
2596 wm8996->retune_mobile_enum.texts = wm8996->retune_mobile_texts; in wm8996_retune_mobile_pdata()
2600 dev_err(component->dev, in wm8996_retune_mobile_pdata()
2620 struct i2c_client *i2c = to_i2c_client(component->dev); in wm8996_probe()
2623 wm8996->component = component; in wm8996_probe()
2625 init_completion(&wm8996->dcs_done); in wm8996_probe()
2626 init_completion(&wm8996->fll_lock); in wm8996_probe()
2628 if (wm8996->pdata.num_retune_mobile_cfgs) in wm8996_probe()
2634 if (i2c->irq) { in wm8996_probe()
2635 if (wm8996->pdata.irq_flags) in wm8996_probe()
2636 irq_flags = wm8996->pdata.irq_flags; in wm8996_probe()
2643 ret = request_threaded_irq(i2c->irq, NULL, in wm8996_probe()
2647 ret = request_threaded_irq(i2c->irq, NULL, wm8996_irq, in wm8996_probe()
2664 dev_err(component->dev, "Failed to request IRQ: %d\n", in wm8996_probe()
2675 struct i2c_client *i2c = to_i2c_client(component->dev); in wm8996_remove()
2680 if (i2c->irq) in wm8996_remove()
2681 free_irq(i2c->irq, component); in wm8996_remove()
2715 .name = "wm8996-aif1",
2735 .name = "wm8996-aif2",
2762 wm8996 = devm_kzalloc(&i2c->dev, sizeof(struct wm8996_priv), in wm8996_i2c_probe()
2765 return -ENOMEM; in wm8996_i2c_probe()
2768 wm8996->dev = &i2c->dev; in wm8996_i2c_probe()
2770 if (dev_get_platdata(&i2c->dev)) in wm8996_i2c_probe()
2771 memcpy(&wm8996->pdata, dev_get_platdata(&i2c->dev), in wm8996_i2c_probe()
2772 sizeof(wm8996->pdata)); in wm8996_i2c_probe()
2774 if (wm8996->pdata.ldo_ena > 0) { in wm8996_i2c_probe()
2775 ret = gpio_request_one(wm8996->pdata.ldo_ena, in wm8996_i2c_probe()
2778 dev_err(&i2c->dev, "Failed to request GPIO %d: %d\n", in wm8996_i2c_probe()
2779 wm8996->pdata.ldo_ena, ret); in wm8996_i2c_probe()
2784 for (i = 0; i < ARRAY_SIZE(wm8996->supplies); i++) in wm8996_i2c_probe()
2785 wm8996->supplies[i].supply = wm8996_supply_names[i]; in wm8996_i2c_probe()
2787 ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(wm8996->supplies), in wm8996_i2c_probe()
2788 wm8996->supplies); in wm8996_i2c_probe()
2790 dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); in wm8996_i2c_probe()
2794 wm8996->disable_nb[0].notifier_call = wm8996_regulator_event_0; in wm8996_i2c_probe()
2795 wm8996->disable_nb[1].notifier_call = wm8996_regulator_event_1; in wm8996_i2c_probe()
2796 wm8996->disable_nb[2].notifier_call = wm8996_regulator_event_2; in wm8996_i2c_probe()
2799 for (i = 0; i < ARRAY_SIZE(wm8996->supplies); i++) { in wm8996_i2c_probe()
2801 wm8996->supplies[i].consumer, in wm8996_i2c_probe()
2802 &wm8996->disable_nb[i]); in wm8996_i2c_probe()
2804 dev_err(&i2c->dev, in wm8996_i2c_probe()
2810 ret = regulator_bulk_enable(ARRAY_SIZE(wm8996->supplies), in wm8996_i2c_probe()
2811 wm8996->supplies); in wm8996_i2c_probe()
2813 dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret); in wm8996_i2c_probe()
2817 if (wm8996->pdata.ldo_ena > 0) { in wm8996_i2c_probe()
2818 gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 1); in wm8996_i2c_probe()
2822 wm8996->regmap = devm_regmap_init_i2c(i2c, &wm8996_regmap); in wm8996_i2c_probe()
2823 if (IS_ERR(wm8996->regmap)) { in wm8996_i2c_probe()
2824 ret = PTR_ERR(wm8996->regmap); in wm8996_i2c_probe()
2825 dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret); in wm8996_i2c_probe()
2829 ret = regmap_read(wm8996->regmap, WM8996_SOFTWARE_RESET, ®); in wm8996_i2c_probe()
2831 dev_err(&i2c->dev, "Failed to read ID register: %d\n", ret); in wm8996_i2c_probe()
2835 dev_err(&i2c->dev, "Device is not a WM8996, ID %x\n", reg); in wm8996_i2c_probe()
2836 ret = -EINVAL; in wm8996_i2c_probe()
2840 ret = regmap_read(wm8996->regmap, WM8996_CHIP_REVISION, ®); in wm8996_i2c_probe()
2842 dev_err(&i2c->dev, "Failed to read device revision: %d\n", in wm8996_i2c_probe()
2847 dev_info(&i2c->dev, "revision %c\n", in wm8996_i2c_probe()
2850 if (wm8996->pdata.ldo_ena > 0) { in wm8996_i2c_probe()
2851 gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 0); in wm8996_i2c_probe()
2852 regcache_cache_only(wm8996->regmap, true); in wm8996_i2c_probe()
2854 ret = regmap_write(wm8996->regmap, WM8996_SOFTWARE_RESET, in wm8996_i2c_probe()
2857 dev_err(&i2c->dev, "Failed to issue reset: %d\n", ret); in wm8996_i2c_probe()
2862 regulator_bulk_disable(ARRAY_SIZE(wm8996->supplies), wm8996->supplies); in wm8996_i2c_probe()
2865 regmap_update_bits(wm8996->regmap, WM8996_LINE_INPUT_CONTROL, in wm8996_i2c_probe()
2867 wm8996->pdata.inl_mode << WM8996_INL_MODE_SHIFT | in wm8996_i2c_probe()
2868 wm8996->pdata.inr_mode); in wm8996_i2c_probe()
2870 for (i = 0; i < ARRAY_SIZE(wm8996->pdata.gpio_default); i++) { in wm8996_i2c_probe()
2871 if (!wm8996->pdata.gpio_default[i]) in wm8996_i2c_probe()
2874 regmap_write(wm8996->regmap, WM8996_GPIO_1 + i, in wm8996_i2c_probe()
2875 wm8996->pdata.gpio_default[i] & 0xffff); in wm8996_i2c_probe()
2878 if (wm8996->pdata.spkmute_seq) in wm8996_i2c_probe()
2879 regmap_update_bits(wm8996->regmap, in wm8996_i2c_probe()
2883 wm8996->pdata.spkmute_seq); in wm8996_i2c_probe()
2885 regmap_update_bits(wm8996->regmap, WM8996_ACCESSORY_DETECT_MODE_2, in wm8996_i2c_probe()
2887 WM8996_MICD_SRC, wm8996->pdata.micdet_def); in wm8996_i2c_probe()
2890 regmap_update_bits(wm8996->regmap, WM8996_LEFT_LINE_INPUT_VOLUME, in wm8996_i2c_probe()
2892 regmap_update_bits(wm8996->regmap, WM8996_RIGHT_LINE_INPUT_VOLUME, in wm8996_i2c_probe()
2895 regmap_update_bits(wm8996->regmap, WM8996_DAC1_LEFT_VOLUME, in wm8996_i2c_probe()
2897 regmap_update_bits(wm8996->regmap, WM8996_DAC1_RIGHT_VOLUME, in wm8996_i2c_probe()
2899 regmap_update_bits(wm8996->regmap, WM8996_DAC2_LEFT_VOLUME, in wm8996_i2c_probe()
2901 regmap_update_bits(wm8996->regmap, WM8996_DAC2_RIGHT_VOLUME, in wm8996_i2c_probe()
2904 regmap_update_bits(wm8996->regmap, WM8996_OUTPUT1_LEFT_VOLUME, in wm8996_i2c_probe()
2906 regmap_update_bits(wm8996->regmap, WM8996_OUTPUT1_RIGHT_VOLUME, in wm8996_i2c_probe()
2908 regmap_update_bits(wm8996->regmap, WM8996_OUTPUT2_LEFT_VOLUME, in wm8996_i2c_probe()
2910 regmap_update_bits(wm8996->regmap, WM8996_OUTPUT2_RIGHT_VOLUME, in wm8996_i2c_probe()
2913 regmap_update_bits(wm8996->regmap, WM8996_DSP1_TX_LEFT_VOLUME, in wm8996_i2c_probe()
2915 regmap_update_bits(wm8996->regmap, WM8996_DSP1_TX_RIGHT_VOLUME, in wm8996_i2c_probe()
2917 regmap_update_bits(wm8996->regmap, WM8996_DSP2_TX_LEFT_VOLUME, in wm8996_i2c_probe()
2919 regmap_update_bits(wm8996->regmap, WM8996_DSP2_TX_RIGHT_VOLUME, in wm8996_i2c_probe()
2922 regmap_update_bits(wm8996->regmap, WM8996_DSP1_RX_LEFT_VOLUME, in wm8996_i2c_probe()
2924 regmap_update_bits(wm8996->regmap, WM8996_DSP1_RX_RIGHT_VOLUME, in wm8996_i2c_probe()
2926 regmap_update_bits(wm8996->regmap, WM8996_DSP2_RX_LEFT_VOLUME, in wm8996_i2c_probe()
2928 regmap_update_bits(wm8996->regmap, WM8996_DSP2_RX_RIGHT_VOLUME, in wm8996_i2c_probe()
2934 regmap_update_bits(wm8996->regmap, in wm8996_i2c_probe()
2939 regmap_update_bits(wm8996->regmap, in wm8996_i2c_probe()
2944 regmap_update_bits(wm8996->regmap, in wm8996_i2c_probe()
2949 regmap_update_bits(wm8996->regmap, in wm8996_i2c_probe()
2954 regmap_update_bits(wm8996->regmap, in wm8996_i2c_probe()
2959 regmap_update_bits(wm8996->regmap, in wm8996_i2c_probe()
2965 regmap_update_bits(wm8996->regmap, in wm8996_i2c_probe()
2970 regmap_update_bits(wm8996->regmap, in wm8996_i2c_probe()
2976 regmap_update_bits(wm8996->regmap, in wm8996_i2c_probe()
2981 regmap_update_bits(wm8996->regmap, in wm8996_i2c_probe()
2986 regmap_update_bits(wm8996->regmap, in wm8996_i2c_probe()
2991 regmap_update_bits(wm8996->regmap, in wm8996_i2c_probe()
2996 regmap_update_bits(wm8996->regmap, in wm8996_i2c_probe()
3001 regmap_update_bits(wm8996->regmap, in wm8996_i2c_probe()
3007 regmap_update_bits(wm8996->regmap, in wm8996_i2c_probe()
3012 regmap_update_bits(wm8996->regmap, in wm8996_i2c_probe()
3021 ret = regmap_read(wm8996->regmap, WM8996_GPIO_1, ®); in wm8996_i2c_probe()
3023 dev_err(&i2c->dev, "Failed to read GPIO1: %d\n", ret); in wm8996_i2c_probe()
3028 regmap_update_bits(wm8996->regmap, WM8996_AIF1_TX_LRCLK_2, in wm8996_i2c_probe()
3032 ret = regmap_read(wm8996->regmap, WM8996_GPIO_2, ®); in wm8996_i2c_probe()
3034 dev_err(&i2c->dev, "Failed to read GPIO2: %d\n", ret); in wm8996_i2c_probe()
3039 regmap_update_bits(wm8996->regmap, WM8996_AIF2_TX_LRCLK_2, in wm8996_i2c_probe()
3045 ret = devm_snd_soc_register_component(&i2c->dev, in wm8996_i2c_probe()
3057 if (wm8996->pdata.ldo_ena > 0) in wm8996_i2c_probe()
3058 gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 0); in wm8996_i2c_probe()
3059 regulator_bulk_disable(ARRAY_SIZE(wm8996->supplies), wm8996->supplies); in wm8996_i2c_probe()
3061 if (wm8996->pdata.ldo_ena > 0) in wm8996_i2c_probe()
3062 gpio_free(wm8996->pdata.ldo_ena); in wm8996_i2c_probe()
3073 if (wm8996->pdata.ldo_ena > 0) { in wm8996_i2c_remove()
3074 gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 0); in wm8996_i2c_remove()
3075 gpio_free(wm8996->pdata.ldo_ena); in wm8996_i2c_remove()