forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/sound/soc/codecs/max98090.c
....@@ -1,11 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * max98090.c -- MAX98090 ALSA SoC Audio driver
34 *
45 * 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.
96 */
107
118 #include <linux/delay.h>
....@@ -314,9 +311,6 @@
314311 static const DECLARE_TLV_DB_SCALE(max98090_dvg_tlv, 0, 600, 0);
315312 static const DECLARE_TLV_DB_SCALE(max98090_dv_tlv, -1500, 100, 0);
316313
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);
320314 static const DECLARE_TLV_DB_SCALE(max98090_alcmakeup_tlv, 0, 100, 0);
321315 static const DECLARE_TLV_DB_SCALE(max98090_alccomp_tlv, -3100, 100, 0);
322316 static const DECLARE_TLV_DB_SCALE(max98090_drcexp_tlv, -6600, 100, 0);
....@@ -359,7 +353,7 @@
359353 struct soc_mixer_control *mc =
360354 (struct soc_mixer_control *)kcontrol->private_value;
361355 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);
363357 unsigned int *select;
364358
365359 switch (mc->reg) {
....@@ -399,8 +393,9 @@
399393 struct soc_mixer_control *mc =
400394 (struct soc_mixer_control *)kcontrol->private_value;
401395 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);
404399 unsigned int *select;
405400
406401 switch (mc->reg) {
....@@ -419,6 +414,10 @@
419414
420415 val = (val >> mc->shift) & mask;
421416
417
+ if (sel_unchecked < 0 || sel_unchecked > mc->max)
418
+ return -EINVAL;
419
+ sel = sel_unchecked;
420
+
422421 *select = sel;
423422
424423 /* Setting a volume is only valid if it is already On */
....@@ -433,7 +432,7 @@
433432 mask << mc->shift,
434433 sel << mc->shift);
435434
436
- return 0;
435
+ return *select != val;
437436 }
438437
439438 static const char *max98090_perf_pwr_text[] =
....@@ -736,7 +735,7 @@
736735 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
737736 struct max98090_priv *max98090 = snd_soc_component_get_drvdata(component);
738737
739
- unsigned int val = snd_soc_component_read32(component, w->reg);
738
+ unsigned int val = snd_soc_component_read(component, w->reg);
740739
741740 if (w->reg == M98090_REG_MIC1_INPUT_LEVEL)
742741 val = (val & M98090_MIC_PA1EN_MASK) >> M98090_MIC_PA1EN_SHIFT;
....@@ -816,18 +815,6 @@
816815
817816 static const struct snd_kcontrol_new max98090_dmic_mux =
818817 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);
831818
832819 /* LINEA mixer switch */
833820 static const struct snd_kcontrol_new max98090_linea_mixer_controls[] = {
....@@ -1514,7 +1501,7 @@
15141501 }
15151502
15161503 /* 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) &
15181505 M98090_MAS_MASK)) {
15191506 return;
15201507 }
....@@ -2035,7 +2022,8 @@
20352022 return 0;
20362023 }
20372024
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)
20392027 {
20402028 struct snd_soc_component *component = codec_dai->component;
20412029 int regval;
....@@ -2057,7 +2045,7 @@
20572045 case SNDRV_PCM_TRIGGER_START:
20582046 case SNDRV_PCM_TRIGGER_RESUME:
20592047 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
2060
- if (!max98090->master && dai->active == 1)
2048
+ if (!max98090->master && snd_soc_dai_active(dai) == 1)
20612049 queue_delayed_work(system_power_efficient_wq,
20622050 &max98090->pll_det_enable_work,
20632051 msecs_to_jiffies(10));
....@@ -2065,7 +2053,7 @@
20652053 case SNDRV_PCM_TRIGGER_STOP:
20662054 case SNDRV_PCM_TRIGGER_SUSPEND:
20672055 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
2068
- if (!max98090->master && dai->active == 1)
2056
+ if (!max98090->master && snd_soc_dai_active(dai) == 1)
20692057 schedule_work(&max98090->pll_det_disable_work);
20702058 break;
20712059 default:
....@@ -2124,8 +2112,10 @@
21242112 static void max98090_pll_work(struct max98090_priv *max98090)
21252113 {
21262114 struct snd_soc_component *component = max98090->component;
2115
+ unsigned int pll;
2116
+ int i;
21272117
2128
- if (!snd_soc_component_is_active(component))
2118
+ if (!snd_soc_component_active(component))
21292119 return;
21302120
21312121 dev_info_ratelimited(component->dev, "PLL unlocked\n");
....@@ -2143,8 +2133,16 @@
21432133 snd_soc_component_update_bits(component, M98090_REG_DEVICE_SHUTDOWN,
21442134 M98090_SHDNN_MASK, M98090_SHDNN_MASK);
21452135
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
+ }
21482146 }
21492147
21502148 static void max98090_jack_work(struct work_struct *work)
....@@ -2165,16 +2163,16 @@
21652163
21662164 msleep(50);
21672165
2168
- reg = snd_soc_component_read32(component, M98090_REG_JACK_STATUS);
2166
+ reg = snd_soc_component_read(component, M98090_REG_JACK_STATUS);
21692167
21702168 /* Weak pull up allows only insertion detection */
21712169 snd_soc_component_update_bits(component, M98090_REG_JACK_DETECT,
21722170 M98090_JDWK_MASK, M98090_JDWK_MASK);
21732171 } else {
2174
- reg = snd_soc_component_read32(component, M98090_REG_JACK_STATUS);
2172
+ reg = snd_soc_component_read(component, M98090_REG_JACK_STATUS);
21752173 }
21762174
2177
- reg = snd_soc_component_read32(component, M98090_REG_JACK_STATUS);
2175
+ reg = snd_soc_component_read(component, M98090_REG_JACK_STATUS);
21782176
21792177 switch (reg & (M98090_LSNS_MASK | M98090_JKSNS_MASK)) {
21802178 case M98090_LSNS_MASK | M98090_JKSNS_MASK:
....@@ -2355,8 +2353,9 @@
23552353 .set_fmt = max98090_dai_set_fmt,
23562354 .set_tdm_slot = max98090_set_tdm_slot,
23572355 .hw_params = max98090_dai_hw_params,
2358
- .digital_mute = max98090_dai_digital_mute,
2356
+ .mute_stream = max98090_dai_mute,
23592357 .trigger = max98090_dai_trigger,
2358
+ .no_capture_mute = 1,
23602359 };
23612360
23622361 static struct snd_soc_dai_driver max98090_dai[] = {
....@@ -2414,7 +2413,7 @@
24142413 max98090->pa1en = 0;
24152414 max98090->pa2en = 0;
24162415
2417
- ret = snd_soc_component_read32(component, M98090_REG_REVISION_ID);
2416
+ ret = snd_soc_component_read(component, M98090_REG_REVISION_ID);
24182417 if (ret < 0) {
24192418 dev_err(component->dev, "Failed to read device revision: %d\n",
24202419 ret);
....@@ -2454,7 +2453,7 @@
24542453 * An old interrupt ocurring prior to installing the ISR
24552454 * can keep a new interrupt from generating a trigger.
24562455 */
2457
- snd_soc_component_read32(component, M98090_REG_DEVICE_STATUS);
2456
+ snd_soc_component_read(component, M98090_REG_DEVICE_STATUS);
24582457
24592458 /* High Performance is default */
24602459 snd_soc_component_update_bits(component, M98090_REG_DAC_CONTROL,
....@@ -2659,17 +2658,12 @@
26592658
26602659 return 0;
26612660 }
2662
-
2663
-static int max98090_suspend(struct device *dev)
2664
-{
2665
- return 0;
2666
-}
26672661 #endif
26682662
26692663 static const struct dev_pm_ops max98090_pm = {
26702664 SET_RUNTIME_PM_OPS(max98090_runtime_suspend,
26712665 max98090_runtime_resume, NULL)
2672
- SET_SYSTEM_SLEEP_PM_OPS(max98090_suspend, max98090_resume)
2666
+ SET_SYSTEM_SLEEP_PM_OPS(NULL, max98090_resume)
26732667 };
26742668
26752669 static const struct i2c_device_id max98090_i2c_id[] = {