forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-09-20 cf4ce59b3b70238352c7f1729f0f7223214828ad
kernel/sound/soc/codecs/ssm2602.c
....@@ -1,31 +1,17 @@
1
-/*
2
- * File: sound/soc/codecs/ssm2602.c
3
- * Author: Cliff Cai <Cliff.Cai@analog.com>
4
- *
5
- * Created: Tue June 06 2008
6
- * Description: Driver for ssm2602 sound chip
7
- *
8
- * Modified:
9
- * Copyright 2008 Analog Devices Inc.
10
- *
11
- * Bugs: Enter bugs at http://blackfin.uclinux.org/
12
- *
13
- * This program is free software; you can redistribute it and/or modify
14
- * it under the terms of the GNU General Public License as published by
15
- * the Free Software Foundation; either version 2 of the License, or
16
- * (at your option) any later version.
17
- *
18
- * This program is distributed in the hope that it will be useful,
19
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- * GNU General Public License for more details.
22
- *
23
- * You should have received a copy of the GNU General Public License
24
- * along with this program; if not, see the file COPYING, or write
25
- * to the Free Software Foundation, Inc.,
26
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
- */
1
+// SPDX-License-Identifier: GPL-2.0-or-later
2
+//
3
+// File: sound/soc/codecs/ssm2602.c
4
+// Author: Cliff Cai <Cliff.Cai@analog.com>
5
+//
6
+// Created: Tue June 06 2008
7
+// Description: Driver for ssm2602 sound chip
8
+//
9
+// Modified:
10
+// Copyright 2008 Analog Devices Inc.
11
+//
12
+// Bugs: Enter bugs at http://blackfin.uclinux.org/
2813
14
+#include <linux/delay.h>
2915 #include <linux/module.h>
3016 #include <linux/regmap.h>
3117 #include <linux/slab.h>
....@@ -65,6 +51,18 @@
6551 { .reg = 0x07, .def = 0x000a },
6652 { .reg = 0x08, .def = 0x0000 },
6753 { .reg = 0x09, .def = 0x0000 }
54
+};
55
+
56
+/*
57
+ * ssm2602 register patch
58
+ * Workaround for playback distortions after power up: activates digital
59
+ * core, and then powers on output, DAC, and whole chip at the same time
60
+ */
61
+
62
+static const struct reg_sequence ssm2602_patch[] = {
63
+ { SSM2602_ACTIVE, 0x01 },
64
+ { SSM2602_PWR, 0x07 },
65
+ { SSM2602_RESET, 0x00 },
6866 };
6967
7068
....@@ -111,7 +109,6 @@
111109
112110 SOC_SINGLE("Mic Boost (+20dB)", SSM2602_APANA, 0, 1, 0),
113111 SOC_SINGLE("Mic Boost2 (+20dB)", SSM2602_APANA, 8, 1, 0),
114
-SOC_SINGLE("Mic Switch", SSM2602_APANA, 1, 1, 1),
115112 };
116113
117114 /* Output Mixer */
....@@ -121,9 +118,30 @@
121118 SOC_DAPM_SINGLE("Mic Sidetone Switch", SSM2602_APANA, 5, 1, 0),
122119 };
123120
121
+static const struct snd_kcontrol_new mic_ctl =
122
+ SOC_DAPM_SINGLE("Switch", SSM2602_APANA, 1, 1, 1);
123
+
124124 /* Input mux */
125125 static const struct snd_kcontrol_new ssm2602_input_mux_controls =
126126 SOC_DAPM_ENUM("Input Select", ssm2602_enum[0]);
127
+
128
+static int ssm2602_mic_switch_event(struct snd_soc_dapm_widget *w,
129
+ struct snd_kcontrol *kcontrol, int event)
130
+{
131
+ /*
132
+ * According to the ssm2603 data sheet (control register sequencing),
133
+ * the digital core should be activated only after all necessary bits
134
+ * in the power register are enabled, and a delay determined by the
135
+ * decoupling capacitor on the VMID pin has passed. If the digital core
136
+ * is activated too early, or even before the ADC is powered up, audible
137
+ * artifacts appear at the beginning and end of the recorded signal.
138
+ *
139
+ * In practice, audible artifacts disappear well over 500 ms.
140
+ */
141
+ msleep(500);
142
+
143
+ return 0;
144
+}
127145
128146 static const struct snd_soc_dapm_widget ssm260x_dapm_widgets[] = {
129147 SND_SOC_DAPM_DAC("DAC", "HiFi Playback", SSM2602_PWR, 3, 1),
....@@ -145,6 +163,9 @@
145163
146164 SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0, &ssm2602_input_mux_controls),
147165 SND_SOC_DAPM_MICBIAS("Mic Bias", SSM2602_PWR, 1, 1),
166
+
167
+SND_SOC_DAPM_SWITCH_E("Mic Switch", SSM2602_APANA, 1, 1, &mic_ctl,
168
+ ssm2602_mic_switch_event, SND_SOC_DAPM_PRE_PMU),
148169
149170 SND_SOC_DAPM_OUTPUT("LHPOUT"),
150171 SND_SOC_DAPM_OUTPUT("RHPOUT"),
....@@ -178,8 +199,10 @@
178199 {"LHPOUT", NULL, "Output Mixer"},
179200
180201 {"Input Mux", "Line", "Line Input"},
181
- {"Input Mux", "Mic", "Mic Bias"},
202
+ {"Input Mux", "Mic", "Mic Switch"},
182203 {"ADC", NULL, "Input Mux"},
204
+
205
+ {"Mic Switch", NULL, "Mic Bias"},
183206
184207 {"Mic Bias", NULL, "MICIN"},
185208 };
....@@ -327,7 +350,7 @@
327350 return 0;
328351 }
329352
330
-static int ssm2602_mute(struct snd_soc_dai *dai, int mute)
353
+static int ssm2602_mute(struct snd_soc_dai *dai, int mute, int direction)
331354 {
332355 struct ssm2602_priv *ssm2602 = snd_soc_component_get_drvdata(dai->component);
333356
....@@ -494,9 +517,10 @@
494517 static const struct snd_soc_dai_ops ssm2602_dai_ops = {
495518 .startup = ssm2602_startup,
496519 .hw_params = ssm2602_hw_params,
497
- .digital_mute = ssm2602_mute,
520
+ .mute_stream = ssm2602_mute,
498521 .set_sysclk = ssm2602_set_dai_sysclk,
499522 .set_fmt = ssm2602_set_dai_fmt,
523
+ .no_capture_mute = 1,
500524 };
501525
502526 static struct snd_soc_dai_driver ssm2602_dai = {
....@@ -577,6 +601,9 @@
577601 return ret;
578602 }
579603
604
+ regmap_register_patch(ssm2602->regmap, ssm2602_patch,
605
+ ARRAY_SIZE(ssm2602_patch));
606
+
580607 /* set the update bits */
581608 regmap_update_bits(ssm2602->regmap, SSM2602_LINVOL,
582609 LINVOL_LRIN_BOTH, LINVOL_LRIN_BOTH);