H A D | wm5100.c | 2 * wm5100.c -- WM5100 ALSA SoC Audio driver 33 #include <sound/wm5100.h> 35 #include "wm5100.h" 122 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec); wm5100_alloc_sr() local 134 if ((wm5100->sysclk % rate) == 0) { wm5100_alloc_sr() 138 if (!wm5100->sr_ref[i] && sr_free == -1) { wm5100_alloc_sr() 148 wm5100->sr_ref[i]++; wm5100_alloc_sr() 150 rate, i, wm5100->sr_ref[i]); wm5100_alloc_sr() 161 wm5100->sr_ref[sr_free]++; wm5100_alloc_sr() 171 rate, wm5100->sysclk, wm5100->asyncclk); wm5100_alloc_sr() 178 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec); wm5100_free_sr() local 191 if (!wm5100->sr_ref[i]) wm5100_free_sr() 199 wm5100->sr_ref[i]--; wm5100_free_sr() 201 rate, wm5100->sr_ref[i]); wm5100_free_sr() 208 static int wm5100_reset(struct wm5100_priv *wm5100) wm5100_reset() argument 210 if (wm5100->pdata.reset) { wm5100_reset() 211 gpio_set_value_cansleep(wm5100->pdata.reset, 0); wm5100_reset() 212 gpio_set_value_cansleep(wm5100->pdata.reset, 1); wm5100_reset() 216 return regmap_write(wm5100->regmap, WM5100_SOFTWARE_RESET, 0); wm5100_reset() 739 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec); wm5100_seq_notifier() local 743 if (wm5100->out_ena[0]) { wm5100_seq_notifier() 748 wm5100->out_ena[0] = false; wm5100_seq_notifier() 758 if (wm5100->out_ena[1]) { wm5100_seq_notifier() 763 wm5100->out_ena[1] = false; wm5100_seq_notifier() 779 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec); wm5100_out_ev() local 783 wm5100->out_ena[0] = true; wm5100_out_ev() 786 wm5100->out_ena[0] = true; wm5100_out_ev() 795 static void wm5100_log_status3(struct wm5100_priv *wm5100, int val) wm5100_log_status3() argument 798 dev_crit(wm5100->dev, "Speaker shutdown warning\n"); wm5100_log_status3() 800 dev_crit(wm5100->dev, "Speaker shutdown\n"); wm5100_log_status3() 802 dev_crit(wm5100->dev, "SYSCLK underclocked\n"); wm5100_log_status3() 804 dev_crit(wm5100->dev, "ASYNCCLK underclocked\n"); wm5100_log_status3() 807 static void wm5100_log_status4(struct wm5100_priv *wm5100, int val) wm5100_log_status4() argument 810 dev_err(wm5100->dev, "AIF3 configuration error\n"); wm5100_log_status4() 812 dev_err(wm5100->dev, "AIF2 configuration error\n"); wm5100_log_status4() 814 dev_err(wm5100->dev, "AIF1 configuration error\n"); wm5100_log_status4() 816 dev_err(wm5100->dev, "Control interface error\n"); wm5100_log_status4() 818 dev_err(wm5100->dev, "ISRC2 underclocked\n"); wm5100_log_status4() 820 dev_err(wm5100->dev, "ISRC1 underclocked\n"); wm5100_log_status4() 822 dev_err(wm5100->dev, "FX underclocked\n"); wm5100_log_status4() 824 dev_err(wm5100->dev, "AIF3 underclocked\n"); wm5100_log_status4() 826 dev_err(wm5100->dev, "AIF2 underclocked\n"); wm5100_log_status4() 828 dev_err(wm5100->dev, "AIF1 underclocked\n"); wm5100_log_status4() 830 dev_err(wm5100->dev, "ASRC underclocked\n"); wm5100_log_status4() 832 dev_err(wm5100->dev, "DAC underclocked\n"); wm5100_log_status4() 834 dev_err(wm5100->dev, "ADC underclocked\n"); wm5100_log_status4() 836 dev_err(wm5100->dev, "Mixer underclocked\n"); wm5100_log_status4() 844 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec); wm5100_post_ev() local 851 wm5100_log_status3(wm5100, ret); wm5100_post_ev() 854 wm5100_log_status4(wm5100, ret); wm5100_post_ev() 1403 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec); wm5100_hw_params() local 1404 bool async = wm5100->aif_async[dai->id]; wm5100_hw_params() 1428 aif_rate = wm5100->sysclk; wm5100_hw_params() 1434 aif_rate = wm5100->asyncclk; wm5100_hw_params() 1482 wm5100->aif_symmetric[dai->id]) wm5100_hw_params() 1512 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec); wm5100_set_sysclk() local 1519 rate_store = &wm5100->sysclk; wm5100_set_sysclk() 1523 rate_store = &wm5100->asyncclk; wm5100_set_sysclk() 1546 wm5100->aif_async[clk_id - 1] = false; wm5100_set_sysclk() 1549 wm5100->aif_async[clk_id - 1] = true; wm5100_set_sysclk() 1761 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec); wm5100_set_fll() local 1769 fll = &wm5100->fll[0]; wm5100_set_fll() 1774 fll = &wm5100->fll[1]; wm5100_set_fll() 1889 .name = "wm5100-aif1", 1908 .name = "wm5100-aif2", 1928 .name = "wm5100-aif3", 1973 static void wm5100_set_detect_mode(struct wm5100_priv *wm5100, int the_mode) wm5100_set_detect_mode() argument 1975 struct wm5100_jack_mode *mode = &wm5100->pdata.jack_modes[the_mode]; wm5100_set_detect_mode() 1977 if (WARN_ON(the_mode >= ARRAY_SIZE(wm5100->pdata.jack_modes))) wm5100_set_detect_mode() 1980 gpio_set_value_cansleep(wm5100->pdata.hp_pol, mode->hp_pol); wm5100_set_detect_mode() 1981 regmap_update_bits(wm5100->regmap, WM5100_ACCESSORY_DETECT_MODE_1, wm5100_set_detect_mode() 1986 regmap_update_bits(wm5100->regmap, WM5100_MISC_CONTROL, wm5100_set_detect_mode() 1990 wm5100->jack_mode = the_mode; wm5100_set_detect_mode() 1992 dev_dbg(wm5100->dev, "Set microphone polarity to %d\n", wm5100_set_detect_mode() 1993 wm5100->jack_mode); wm5100_set_detect_mode() 1996 static void wm5100_report_headphone(struct wm5100_priv *wm5100) wm5100_report_headphone() argument 1998 dev_dbg(wm5100->dev, "Headphone detected\n"); wm5100_report_headphone() 1999 wm5100->jack_detecting = false; wm5100_report_headphone() 2000 snd_soc_jack_report(wm5100->jack, SND_JACK_HEADPHONE, wm5100_report_headphone() 2004 regmap_update_bits(wm5100->regmap, WM5100_MIC_DETECT_1, wm5100_report_headphone() 2009 static void wm5100_micd_irq(struct wm5100_priv *wm5100) wm5100_micd_irq() argument 2014 ret = regmap_read(wm5100->regmap, WM5100_MIC_DETECT_3, &val); wm5100_micd_irq() 2016 dev_err(wm5100->dev, "Failed to read micropone status: %d\n", wm5100_micd_irq() 2021 dev_dbg(wm5100->dev, "Microphone event: %x\n", val); wm5100_micd_irq() 2024 dev_warn(wm5100->dev, "Microphone detection state invalid\n"); wm5100_micd_irq() 2030 dev_dbg(wm5100->dev, "Jack removal detected\n"); wm5100_micd_irq() 2031 wm5100->jack_mic = false; wm5100_micd_irq() 2032 wm5100->jack_detecting = true; wm5100_micd_irq() 2033 wm5100->jack_flips = 0; wm5100_micd_irq() 2034 snd_soc_jack_report(wm5100->jack, 0, wm5100_micd_irq() 2038 regmap_update_bits(wm5100->regmap, WM5100_MIC_DETECT_1, wm5100_micd_irq() 2049 if (wm5100->jack_detecting) { wm5100_micd_irq() 2050 dev_dbg(wm5100->dev, "Microphone detected\n"); wm5100_micd_irq() 2051 wm5100->jack_mic = true; wm5100_micd_irq() 2052 wm5100->jack_detecting = false; wm5100_micd_irq() 2053 snd_soc_jack_report(wm5100->jack, wm5100_micd_irq() 2059 regmap_update_bits(wm5100->regmap, WM5100_MIC_DETECT_1, wm5100_micd_irq() 2063 dev_dbg(wm5100->dev, "Mic button up\n"); wm5100_micd_irq() 2064 snd_soc_jack_report(wm5100->jack, 0, SND_JACK_BTN_0); wm5100_micd_irq() 2076 if (wm5100->jack_detecting && (val & 0x3f8)) { wm5100_micd_irq() 2077 wm5100->jack_flips++; wm5100_micd_irq() 2079 if (wm5100->jack_flips > 1) wm5100_micd_irq() 2080 wm5100_report_headphone(wm5100); wm5100_micd_irq() 2082 wm5100_set_detect_mode(wm5100, !wm5100->jack_mode); wm5100_micd_irq() 2091 if (wm5100->jack_mic) { wm5100_micd_irq() 2092 dev_dbg(wm5100->dev, "Mic button detected\n"); wm5100_micd_irq() 2093 snd_soc_jack_report(wm5100->jack, SND_JACK_BTN_0, wm5100_micd_irq() 2095 } else if (wm5100->jack_detecting) { wm5100_micd_irq() 2096 wm5100_report_headphone(wm5100); wm5100_micd_irq() 2103 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec); wm5100_detect() local 2107 wm5100->jack = jack; wm5100_detect() 2108 wm5100->jack_detecting = true; wm5100_detect() 2109 wm5100->jack_flips = 0; wm5100_detect() 2111 wm5100_set_detect_mode(wm5100, 0); wm5100_detect() 2147 wm5100->jack = NULL; wm5100_detect() 2156 struct wm5100_priv *wm5100 = data; wm5100_irq() local 2161 ret = regmap_read(wm5100->regmap, WM5100_INTERRUPT_STATUS_3, &irq_val); wm5100_irq() 2163 dev_err(wm5100->dev, "Failed to read IRQ status 3: %d\n", wm5100_irq() 2168 ret = regmap_read(wm5100->regmap, WM5100_INTERRUPT_STATUS_3_MASK, wm5100_irq() 2171 dev_err(wm5100->dev, "Failed to read IRQ mask 3: %d\n", wm5100_irq() 2178 regmap_write(wm5100->regmap, WM5100_INTERRUPT_STATUS_3, irq_val); wm5100_irq() 2183 wm5100_log_status3(wm5100, irq_val); wm5100_irq() 2186 dev_dbg(wm5100->dev, "FLL1 locked\n"); wm5100_irq() 2187 complete(&wm5100->fll[0].lock); wm5100_irq() 2190 dev_dbg(wm5100->dev, "FLL2 locked\n"); wm5100_irq() 2191 complete(&wm5100->fll[1].lock); wm5100_irq() 2195 wm5100_micd_irq(wm5100); wm5100_irq() 2197 ret = regmap_read(wm5100->regmap, WM5100_INTERRUPT_STATUS_4, &irq_val); wm5100_irq() 2199 dev_err(wm5100->dev, "Failed to read IRQ status 4: %d\n", wm5100_irq() 2204 ret = regmap_read(wm5100->regmap, WM5100_INTERRUPT_STATUS_4_MASK, wm5100_irq() 2207 dev_err(wm5100->dev, "Failed to read IRQ mask 4: %d\n", wm5100_irq() 2217 regmap_write(wm5100->regmap, WM5100_INTERRUPT_STATUS_4, irq_val); wm5100_irq() 2219 wm5100_log_status4(wm5100, irq_val); wm5100_irq() 2246 struct wm5100_priv *wm5100 = gpio_to_wm5100(chip); wm5100_gpio_set() local 2248 regmap_update_bits(wm5100->regmap, WM5100_GPIO_CTRL_1 + offset, wm5100_gpio_set() 2255 struct wm5100_priv *wm5100 = gpio_to_wm5100(chip); wm5100_gpio_direction_out() local 2260 ret = regmap_update_bits(wm5100->regmap, WM5100_GPIO_CTRL_1 + offset, wm5100_gpio_direction_out() 2271 struct wm5100_priv *wm5100 = gpio_to_wm5100(chip); wm5100_gpio_get() local 2275 ret = regmap_read(wm5100->regmap, WM5100_GPIO_CTRL_1 + offset, ®); wm5100_gpio_get() 2284 struct wm5100_priv *wm5100 = gpio_to_wm5100(chip); wm5100_gpio_direction_in() local 2286 return regmap_update_bits(wm5100->regmap, WM5100_GPIO_CTRL_1 + offset, wm5100_gpio_direction_in() 2293 .label = "wm5100", 2304 struct wm5100_priv *wm5100 = i2c_get_clientdata(i2c); wm5100_init_gpio() local 2307 wm5100->gpio_chip = wm5100_template_chip; wm5100_init_gpio() 2308 wm5100->gpio_chip.ngpio = 6; wm5100_init_gpio() 2309 wm5100->gpio_chip.dev = &i2c->dev; wm5100_init_gpio() 2311 if (wm5100->pdata.gpio_base) wm5100_init_gpio() 2312 wm5100->gpio_chip.base = wm5100->pdata.gpio_base; wm5100_init_gpio() 2314 wm5100->gpio_chip.base = -1; wm5100_init_gpio() 2316 ret = gpiochip_add(&wm5100->gpio_chip); wm5100_init_gpio() 2323 struct wm5100_priv *wm5100 = i2c_get_clientdata(i2c); wm5100_free_gpio() local 2325 gpiochip_remove(&wm5100->gpio_chip); wm5100_free_gpio() 2341 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec); wm5100_probe() local 2344 wm5100->codec = codec; wm5100_probe() 2360 if (wm5100->pdata.hp_pol) { wm5100_probe() 2361 ret = gpio_request_one(wm5100->pdata.hp_pol, wm5100_probe() 2365 wm5100->pdata.hp_pol, ret); wm5100_probe() 2379 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec); wm5100_remove() local 2381 if (wm5100->pdata.hp_pol) { wm5100_remove() 2382 gpio_free(wm5100->pdata.hp_pol); wm5100_remove() 2428 struct wm5100_priv *wm5100; wm5100_i2c_probe() local 2432 wm5100 = devm_kzalloc(&i2c->dev, sizeof(struct wm5100_priv), wm5100_i2c_probe() 2434 if (wm5100 == NULL) wm5100_i2c_probe() 2437 wm5100->dev = &i2c->dev; wm5100_i2c_probe() 2439 wm5100->regmap = devm_regmap_init_i2c(i2c, &wm5100_regmap); wm5100_i2c_probe() 2440 if (IS_ERR(wm5100->regmap)) { wm5100_i2c_probe() 2441 ret = PTR_ERR(wm5100->regmap); wm5100_i2c_probe() 2447 for (i = 0; i < ARRAY_SIZE(wm5100->fll); i++) wm5100_i2c_probe() 2448 init_completion(&wm5100->fll[i].lock); wm5100_i2c_probe() 2451 wm5100->pdata = *pdata; wm5100_i2c_probe() 2453 i2c_set_clientdata(i2c, wm5100); wm5100_i2c_probe() 2455 for (i = 0; i < ARRAY_SIZE(wm5100->core_supplies); i++) wm5100_i2c_probe() 2456 wm5100->core_supplies[i].supply = wm5100_core_supply_names[i]; wm5100_i2c_probe() 2459 ARRAY_SIZE(wm5100->core_supplies), wm5100_i2c_probe() 2460 wm5100->core_supplies); wm5100_i2c_probe() 2467 ret = regulator_bulk_enable(ARRAY_SIZE(wm5100->core_supplies), wm5100_i2c_probe() 2468 wm5100->core_supplies); wm5100_i2c_probe() 2475 if (wm5100->pdata.ldo_ena) { wm5100_i2c_probe() 2476 ret = gpio_request_one(wm5100->pdata.ldo_ena, wm5100_i2c_probe() 2480 wm5100->pdata.ldo_ena, ret); wm5100_i2c_probe() 2486 if (wm5100->pdata.reset) { wm5100_i2c_probe() 2487 ret = gpio_request_one(wm5100->pdata.reset, wm5100_i2c_probe() 2491 wm5100->pdata.reset, ret); wm5100_i2c_probe() 2496 ret = regmap_read(wm5100->regmap, WM5100_SOFTWARE_RESET, ®); wm5100_i2c_probe() 2512 ret = regmap_read(wm5100->regmap, WM5100_DEVICE_REVISION, ®); wm5100_i2c_probe() 2517 wm5100->rev = reg & WM5100_DEVICE_REVISION_MASK; wm5100_i2c_probe() 2519 dev_info(&i2c->dev, "revision %c\n", wm5100->rev + 'A'); wm5100_i2c_probe() 2521 ret = wm5100_reset(wm5100); wm5100_i2c_probe() 2527 switch (wm5100->rev) { wm5100_i2c_probe() 2529 ret = regmap_register_patch(wm5100->regmap, wm5100_i2c_probe() 2545 for (i = 0; i < ARRAY_SIZE(wm5100->pdata.gpio_defaults); i++) { wm5100_i2c_probe() 2546 if (!wm5100->pdata.gpio_defaults[i]) wm5100_i2c_probe() 2549 regmap_write(wm5100->regmap, WM5100_GPIO_CTRL_1 + i, wm5100_i2c_probe() 2550 wm5100->pdata.gpio_defaults[i]); wm5100_i2c_probe() 2553 for (i = 0; i < ARRAY_SIZE(wm5100->pdata.in_mode); i++) { wm5100_i2c_probe() 2554 regmap_update_bits(wm5100->regmap, wm5100_mic_ctrl_reg[i], wm5100_i2c_probe() 2557 (wm5100->pdata.in_mode[i] << wm5100_i2c_probe() 2559 (wm5100->pdata.dmic_sup[i] << wm5100_i2c_probe() 2564 if (wm5100->pdata.irq_flags) wm5100_i2c_probe() 2565 irq_flags = wm5100->pdata.irq_flags; wm5100_i2c_probe() 2574 "wm5100", wm5100); wm5100_i2c_probe() 2577 irq_flags, "wm5100", wm5100_i2c_probe() 2578 wm5100); wm5100_i2c_probe() 2585 regmap_update_bits(wm5100->regmap, wm5100_i2c_probe() 2596 regmap_update_bits(wm5100->regmap, wm5100_i2c_probe() 2631 free_irq(i2c->irq, wm5100); wm5100_i2c_probe() 2633 if (wm5100->pdata.reset) { wm5100_i2c_probe() 2634 gpio_set_value_cansleep(wm5100->pdata.reset, 0); wm5100_i2c_probe() 2635 gpio_free(wm5100->pdata.reset); wm5100_i2c_probe() 2638 if (wm5100->pdata.ldo_ena) { wm5100_i2c_probe() 2639 gpio_set_value_cansleep(wm5100->pdata.ldo_ena, 0); wm5100_i2c_probe() 2640 gpio_free(wm5100->pdata.ldo_ena); wm5100_i2c_probe() 2643 regulator_bulk_disable(ARRAY_SIZE(wm5100->core_supplies), wm5100_i2c_probe() 2644 wm5100->core_supplies); wm5100_i2c_probe() 2651 struct wm5100_priv *wm5100 = i2c_get_clientdata(i2c); wm5100_i2c_remove() local 2655 free_irq(i2c->irq, wm5100); wm5100_i2c_remove() 2657 if (wm5100->pdata.reset) { wm5100_i2c_remove() 2658 gpio_set_value_cansleep(wm5100->pdata.reset, 0); wm5100_i2c_remove() 2659 gpio_free(wm5100->pdata.reset); wm5100_i2c_remove() 2661 if (wm5100->pdata.ldo_ena) { wm5100_i2c_remove() 2662 gpio_set_value_cansleep(wm5100->pdata.ldo_ena, 0); wm5100_i2c_remove() 2663 gpio_free(wm5100->pdata.ldo_ena); wm5100_i2c_remove() 2672 struct wm5100_priv *wm5100 = dev_get_drvdata(dev); wm5100_runtime_suspend() local 2674 regcache_cache_only(wm5100->regmap, true); wm5100_runtime_suspend() 2675 regcache_mark_dirty(wm5100->regmap); wm5100_runtime_suspend() 2676 if (wm5100->pdata.ldo_ena) wm5100_runtime_suspend() 2677 gpio_set_value_cansleep(wm5100->pdata.ldo_ena, 0); wm5100_runtime_suspend() 2678 regulator_bulk_disable(ARRAY_SIZE(wm5100->core_supplies), wm5100_runtime_suspend() 2679 wm5100->core_supplies); wm5100_runtime_suspend() 2686 struct wm5100_priv *wm5100 = dev_get_drvdata(dev); wm5100_runtime_resume() local 2689 ret = regulator_bulk_enable(ARRAY_SIZE(wm5100->core_supplies), wm5100_runtime_resume() 2690 wm5100->core_supplies); wm5100_runtime_resume() 2697 if (wm5100->pdata.ldo_ena) { wm5100_runtime_resume() 2698 gpio_set_value_cansleep(wm5100->pdata.ldo_ena, 1); wm5100_runtime_resume() 2702 regcache_cache_only(wm5100->regmap, false); wm5100_runtime_resume() 2703 regcache_sync(wm5100->regmap); wm5100_runtime_resume() 2715 { "wm5100", 0 }, 2722 .name = "wm5100",
|