| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * max98090.c -- MAX98090 ALSA SoC Audio driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright 2011-2012 Maxim Integrated Products |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 8 | | - * published by the Free Software Foundation. |
|---|
| 9 | 6 | */ |
|---|
| 10 | 7 | |
|---|
| 11 | 8 | #include <linux/delay.h> |
|---|
| .. | .. |
|---|
| 314 | 311 | static const DECLARE_TLV_DB_SCALE(max98090_dvg_tlv, 0, 600, 0); |
|---|
| 315 | 312 | static const DECLARE_TLV_DB_SCALE(max98090_dv_tlv, -1500, 100, 0); |
|---|
| 316 | 313 | |
|---|
| 317 | | -static const DECLARE_TLV_DB_SCALE(max98090_sidetone_tlv, -6050, 200, 0); |
|---|
| 318 | | - |
|---|
| 319 | | -static const DECLARE_TLV_DB_SCALE(max98090_alc_tlv, -1500, 100, 0); |
|---|
| 320 | 314 | static const DECLARE_TLV_DB_SCALE(max98090_alcmakeup_tlv, 0, 100, 0); |
|---|
| 321 | 315 | static const DECLARE_TLV_DB_SCALE(max98090_alccomp_tlv, -3100, 100, 0); |
|---|
| 322 | 316 | static const DECLARE_TLV_DB_SCALE(max98090_drcexp_tlv, -6600, 100, 0); |
|---|
| .. | .. |
|---|
| 359 | 353 | struct soc_mixer_control *mc = |
|---|
| 360 | 354 | (struct soc_mixer_control *)kcontrol->private_value; |
|---|
| 361 | 355 | unsigned int mask = (1 << fls(mc->max)) - 1; |
|---|
| 362 | | - unsigned int val = snd_soc_component_read32(component, mc->reg); |
|---|
| 356 | + unsigned int val = snd_soc_component_read(component, mc->reg); |
|---|
| 363 | 357 | unsigned int *select; |
|---|
| 364 | 358 | |
|---|
| 365 | 359 | switch (mc->reg) { |
|---|
| .. | .. |
|---|
| 399 | 393 | struct soc_mixer_control *mc = |
|---|
| 400 | 394 | (struct soc_mixer_control *)kcontrol->private_value; |
|---|
| 401 | 395 | unsigned int mask = (1 << fls(mc->max)) - 1; |
|---|
| 402 | | - unsigned int sel = ucontrol->value.integer.value[0]; |
|---|
| 403 | | - unsigned int val = snd_soc_component_read32(component, mc->reg); |
|---|
| 396 | + int sel_unchecked = ucontrol->value.integer.value[0]; |
|---|
| 397 | + unsigned int sel; |
|---|
| 398 | + unsigned int val = snd_soc_component_read(component, mc->reg); |
|---|
| 404 | 399 | unsigned int *select; |
|---|
| 405 | 400 | |
|---|
| 406 | 401 | switch (mc->reg) { |
|---|
| .. | .. |
|---|
| 419 | 414 | |
|---|
| 420 | 415 | val = (val >> mc->shift) & mask; |
|---|
| 421 | 416 | |
|---|
| 417 | + if (sel_unchecked < 0 || sel_unchecked > mc->max) |
|---|
| 418 | + return -EINVAL; |
|---|
| 419 | + sel = sel_unchecked; |
|---|
| 420 | + |
|---|
| 422 | 421 | *select = sel; |
|---|
| 423 | 422 | |
|---|
| 424 | 423 | /* Setting a volume is only valid if it is already On */ |
|---|
| .. | .. |
|---|
| 433 | 432 | mask << mc->shift, |
|---|
| 434 | 433 | sel << mc->shift); |
|---|
| 435 | 434 | |
|---|
| 436 | | - return 0; |
|---|
| 435 | + return *select != val; |
|---|
| 437 | 436 | } |
|---|
| 438 | 437 | |
|---|
| 439 | 438 | static const char *max98090_perf_pwr_text[] = |
|---|
| .. | .. |
|---|
| 736 | 735 | struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
|---|
| 737 | 736 | struct max98090_priv *max98090 = snd_soc_component_get_drvdata(component); |
|---|
| 738 | 737 | |
|---|
| 739 | | - unsigned int val = snd_soc_component_read32(component, w->reg); |
|---|
| 738 | + unsigned int val = snd_soc_component_read(component, w->reg); |
|---|
| 740 | 739 | |
|---|
| 741 | 740 | if (w->reg == M98090_REG_MIC1_INPUT_LEVEL) |
|---|
| 742 | 741 | val = (val & M98090_MIC_PA1EN_MASK) >> M98090_MIC_PA1EN_SHIFT; |
|---|
| .. | .. |
|---|
| 816 | 815 | |
|---|
| 817 | 816 | static const struct snd_kcontrol_new max98090_dmic_mux = |
|---|
| 818 | 817 | SOC_DAPM_ENUM("DMIC Mux", dmic_mux_enum); |
|---|
| 819 | | - |
|---|
| 820 | | -static const char *max98090_micpre_text[] = { "Off", "On" }; |
|---|
| 821 | | - |
|---|
| 822 | | -static SOC_ENUM_SINGLE_DECL(max98090_pa1en_enum, |
|---|
| 823 | | - M98090_REG_MIC1_INPUT_LEVEL, |
|---|
| 824 | | - M98090_MIC_PA1EN_SHIFT, |
|---|
| 825 | | - max98090_micpre_text); |
|---|
| 826 | | - |
|---|
| 827 | | -static SOC_ENUM_SINGLE_DECL(max98090_pa2en_enum, |
|---|
| 828 | | - M98090_REG_MIC2_INPUT_LEVEL, |
|---|
| 829 | | - M98090_MIC_PA2EN_SHIFT, |
|---|
| 830 | | - max98090_micpre_text); |
|---|
| 831 | 818 | |
|---|
| 832 | 819 | /* LINEA mixer switch */ |
|---|
| 833 | 820 | static const struct snd_kcontrol_new max98090_linea_mixer_controls[] = { |
|---|
| .. | .. |
|---|
| 1514 | 1501 | } |
|---|
| 1515 | 1502 | |
|---|
| 1516 | 1503 | /* Skip configuration when operating as slave */ |
|---|
| 1517 | | - if (!(snd_soc_component_read32(component, M98090_REG_MASTER_MODE) & |
|---|
| 1504 | + if (!(snd_soc_component_read(component, M98090_REG_MASTER_MODE) & |
|---|
| 1518 | 1505 | M98090_MAS_MASK)) { |
|---|
| 1519 | 1506 | return; |
|---|
| 1520 | 1507 | } |
|---|
| .. | .. |
|---|
| 2035 | 2022 | return 0; |
|---|
| 2036 | 2023 | } |
|---|
| 2037 | 2024 | |
|---|
| 2038 | | -static int max98090_dai_digital_mute(struct snd_soc_dai *codec_dai, int mute) |
|---|
| 2025 | +static int max98090_dai_mute(struct snd_soc_dai *codec_dai, int mute, |
|---|
| 2026 | + int direction) |
|---|
| 2039 | 2027 | { |
|---|
| 2040 | 2028 | struct snd_soc_component *component = codec_dai->component; |
|---|
| 2041 | 2029 | int regval; |
|---|
| .. | .. |
|---|
| 2057 | 2045 | case SNDRV_PCM_TRIGGER_START: |
|---|
| 2058 | 2046 | case SNDRV_PCM_TRIGGER_RESUME: |
|---|
| 2059 | 2047 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
|---|
| 2060 | | - if (!max98090->master && dai->active == 1) |
|---|
| 2048 | + if (!max98090->master && snd_soc_dai_active(dai) == 1) |
|---|
| 2061 | 2049 | queue_delayed_work(system_power_efficient_wq, |
|---|
| 2062 | 2050 | &max98090->pll_det_enable_work, |
|---|
| 2063 | 2051 | msecs_to_jiffies(10)); |
|---|
| .. | .. |
|---|
| 2065 | 2053 | case SNDRV_PCM_TRIGGER_STOP: |
|---|
| 2066 | 2054 | case SNDRV_PCM_TRIGGER_SUSPEND: |
|---|
| 2067 | 2055 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
|---|
| 2068 | | - if (!max98090->master && dai->active == 1) |
|---|
| 2056 | + if (!max98090->master && snd_soc_dai_active(dai) == 1) |
|---|
| 2069 | 2057 | schedule_work(&max98090->pll_det_disable_work); |
|---|
| 2070 | 2058 | break; |
|---|
| 2071 | 2059 | default: |
|---|
| .. | .. |
|---|
| 2124 | 2112 | static void max98090_pll_work(struct max98090_priv *max98090) |
|---|
| 2125 | 2113 | { |
|---|
| 2126 | 2114 | struct snd_soc_component *component = max98090->component; |
|---|
| 2115 | + unsigned int pll; |
|---|
| 2116 | + int i; |
|---|
| 2127 | 2117 | |
|---|
| 2128 | | - if (!snd_soc_component_is_active(component)) |
|---|
| 2118 | + if (!snd_soc_component_active(component)) |
|---|
| 2129 | 2119 | return; |
|---|
| 2130 | 2120 | |
|---|
| 2131 | 2121 | dev_info_ratelimited(component->dev, "PLL unlocked\n"); |
|---|
| .. | .. |
|---|
| 2143 | 2133 | snd_soc_component_update_bits(component, M98090_REG_DEVICE_SHUTDOWN, |
|---|
| 2144 | 2134 | M98090_SHDNN_MASK, M98090_SHDNN_MASK); |
|---|
| 2145 | 2135 | |
|---|
| 2146 | | - /* Give PLL time to lock */ |
|---|
| 2147 | | - msleep(10); |
|---|
| 2136 | + for (i = 0; i < 10; ++i) { |
|---|
| 2137 | + /* Give PLL time to lock */ |
|---|
| 2138 | + usleep_range(1000, 1200); |
|---|
| 2139 | + |
|---|
| 2140 | + /* Check lock status */ |
|---|
| 2141 | + pll = snd_soc_component_read( |
|---|
| 2142 | + component, M98090_REG_DEVICE_STATUS); |
|---|
| 2143 | + if (!(pll & M98090_ULK_MASK)) |
|---|
| 2144 | + break; |
|---|
| 2145 | + } |
|---|
| 2148 | 2146 | } |
|---|
| 2149 | 2147 | |
|---|
| 2150 | 2148 | static void max98090_jack_work(struct work_struct *work) |
|---|
| .. | .. |
|---|
| 2165 | 2163 | |
|---|
| 2166 | 2164 | msleep(50); |
|---|
| 2167 | 2165 | |
|---|
| 2168 | | - reg = snd_soc_component_read32(component, M98090_REG_JACK_STATUS); |
|---|
| 2166 | + reg = snd_soc_component_read(component, M98090_REG_JACK_STATUS); |
|---|
| 2169 | 2167 | |
|---|
| 2170 | 2168 | /* Weak pull up allows only insertion detection */ |
|---|
| 2171 | 2169 | snd_soc_component_update_bits(component, M98090_REG_JACK_DETECT, |
|---|
| 2172 | 2170 | M98090_JDWK_MASK, M98090_JDWK_MASK); |
|---|
| 2173 | 2171 | } else { |
|---|
| 2174 | | - reg = snd_soc_component_read32(component, M98090_REG_JACK_STATUS); |
|---|
| 2172 | + reg = snd_soc_component_read(component, M98090_REG_JACK_STATUS); |
|---|
| 2175 | 2173 | } |
|---|
| 2176 | 2174 | |
|---|
| 2177 | | - reg = snd_soc_component_read32(component, M98090_REG_JACK_STATUS); |
|---|
| 2175 | + reg = snd_soc_component_read(component, M98090_REG_JACK_STATUS); |
|---|
| 2178 | 2176 | |
|---|
| 2179 | 2177 | switch (reg & (M98090_LSNS_MASK | M98090_JKSNS_MASK)) { |
|---|
| 2180 | 2178 | case M98090_LSNS_MASK | M98090_JKSNS_MASK: |
|---|
| .. | .. |
|---|
| 2355 | 2353 | .set_fmt = max98090_dai_set_fmt, |
|---|
| 2356 | 2354 | .set_tdm_slot = max98090_set_tdm_slot, |
|---|
| 2357 | 2355 | .hw_params = max98090_dai_hw_params, |
|---|
| 2358 | | - .digital_mute = max98090_dai_digital_mute, |
|---|
| 2356 | + .mute_stream = max98090_dai_mute, |
|---|
| 2359 | 2357 | .trigger = max98090_dai_trigger, |
|---|
| 2358 | + .no_capture_mute = 1, |
|---|
| 2360 | 2359 | }; |
|---|
| 2361 | 2360 | |
|---|
| 2362 | 2361 | static struct snd_soc_dai_driver max98090_dai[] = { |
|---|
| .. | .. |
|---|
| 2414 | 2413 | max98090->pa1en = 0; |
|---|
| 2415 | 2414 | max98090->pa2en = 0; |
|---|
| 2416 | 2415 | |
|---|
| 2417 | | - ret = snd_soc_component_read32(component, M98090_REG_REVISION_ID); |
|---|
| 2416 | + ret = snd_soc_component_read(component, M98090_REG_REVISION_ID); |
|---|
| 2418 | 2417 | if (ret < 0) { |
|---|
| 2419 | 2418 | dev_err(component->dev, "Failed to read device revision: %d\n", |
|---|
| 2420 | 2419 | ret); |
|---|
| .. | .. |
|---|
| 2454 | 2453 | * An old interrupt ocurring prior to installing the ISR |
|---|
| 2455 | 2454 | * can keep a new interrupt from generating a trigger. |
|---|
| 2456 | 2455 | */ |
|---|
| 2457 | | - snd_soc_component_read32(component, M98090_REG_DEVICE_STATUS); |
|---|
| 2456 | + snd_soc_component_read(component, M98090_REG_DEVICE_STATUS); |
|---|
| 2458 | 2457 | |
|---|
| 2459 | 2458 | /* High Performance is default */ |
|---|
| 2460 | 2459 | snd_soc_component_update_bits(component, M98090_REG_DAC_CONTROL, |
|---|
| .. | .. |
|---|
| 2659 | 2658 | |
|---|
| 2660 | 2659 | return 0; |
|---|
| 2661 | 2660 | } |
|---|
| 2662 | | - |
|---|
| 2663 | | -static int max98090_suspend(struct device *dev) |
|---|
| 2664 | | -{ |
|---|
| 2665 | | - return 0; |
|---|
| 2666 | | -} |
|---|
| 2667 | 2661 | #endif |
|---|
| 2668 | 2662 | |
|---|
| 2669 | 2663 | static const struct dev_pm_ops max98090_pm = { |
|---|
| 2670 | 2664 | SET_RUNTIME_PM_OPS(max98090_runtime_suspend, |
|---|
| 2671 | 2665 | max98090_runtime_resume, NULL) |
|---|
| 2672 | | - SET_SYSTEM_SLEEP_PM_OPS(max98090_suspend, max98090_resume) |
|---|
| 2666 | + SET_SYSTEM_SLEEP_PM_OPS(NULL, max98090_resume) |
|---|
| 2673 | 2667 | }; |
|---|
| 2674 | 2668 | |
|---|
| 2675 | 2669 | static const struct i2c_device_id max98090_i2c_id[] = { |
|---|