hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/sound/soc/codecs/rl6231.c
....@@ -1,13 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * rl6231.c - RL6231 class device shared support
34 *
45 * Copyright 2014 Realtek Semiconductor Corp.
56 *
67 * Author: Oder Chiou <oder_chiou@realtek.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License version 2 as
10
- * published by the Free Software Foundation.
118 */
129
1310 #include <linux/module.h>
....@@ -83,8 +80,8 @@
8380 for (i = 0; i < ARRAY_SIZE(div); i++) {
8481 if ((div[i] % 3) == 0)
8582 continue;
86
- /* find divider that gives DMIC frequency below 3.072MHz */
87
- if (3072000 * div[i] >= rate)
83
+ /* find divider that gives DMIC frequency below 1.536MHz */
84
+ if (1536000 * div[i] >= rate)
8885 return i;
8986 }
9087
....@@ -100,11 +97,15 @@
10097 int n;
10198 int m;
10299 bool m_bp;
100
+ bool k_bp;
103101 };
104102
105103 static const struct pll_calc_map pll_preset_table[] = {
106
- {19200000, 4096000, 23, 14, 1, false},
107
- {19200000, 24576000, 3, 30, 3, false},
104
+ {19200000, 4096000, 23, 14, 1, false, false},
105
+ {19200000, 24576000, 3, 30, 3, false, false},
106
+ {48000000, 3840000, 23, 2, 0, false, false},
107
+ {3840000, 24576000, 3, 30, 0, true, false},
108
+ {3840000, 22579200, 3, 5, 0, true, false},
108109 };
109110
110111 static unsigned int find_best_div(unsigned int in,
....@@ -130,7 +131,7 @@
130131 * rl6231_pll_calc - Calcualte PLL M/N/K code.
131132 * @freq_in: external clock provided to codec.
132133 * @freq_out: target clock which codec works on.
133
- * @pll_code: Pointer to structure with M, N, K and bypass flag.
134
+ * @pll_code: Pointer to structure with M, N, K, m_bypass and k_bypass flag.
134135 *
135136 * Calcualte M/N/K code to configure PLL for codec.
136137 *
....@@ -145,7 +146,7 @@
145146 unsigned int red, pll_out, in_t, out_t, div, div_t;
146147 unsigned int red_t = abs(freq_out - freq_in);
147148 unsigned int f_in, f_out, f_max;
148
- bool bypass = false;
149
+ bool m_bypass = false, k_bypass = false;
149150
150151 if (RL6231_PLL_INP_MAX < freq_in || RL6231_PLL_INP_MIN > freq_in)
151152 return -EINVAL;
....@@ -156,7 +157,8 @@
156157 k = pll_preset_table[i].k;
157158 m = pll_preset_table[i].m;
158159 n = pll_preset_table[i].n;
159
- bypass = pll_preset_table[i].m_bp;
160
+ m_bypass = pll_preset_table[i].m_bp;
161
+ k_bypass = pll_preset_table[i].k_bp;
160162 pr_debug("Use preset PLL parameter table\n");
161163 goto code_find;
162164 }
....@@ -174,12 +176,14 @@
174176 f_in = freq_in / div;
175177 f_out = freq_out / div;
176178 k = min_k;
179
+ if (min_k < -1)
180
+ min_k = -1;
177181 for (k_t = min_k; k_t <= max_k; k_t++) {
178182 for (n_t = 0; n_t <= max_n; n_t++) {
179183 in_t = f_in * (n_t + 2);
180184 pll_out = f_out * (k_t + 2);
181185 if (in_t == pll_out) {
182
- bypass = true;
186
+ m_bypass = true;
183187 n = n_t;
184188 k = k_t;
185189 goto code_find;
....@@ -187,7 +191,7 @@
187191 out_t = in_t / (k_t + 2);
188192 red = abs(f_out - out_t);
189193 if (red < red_t) {
190
- bypass = true;
194
+ m_bypass = true;
191195 n = n_t;
192196 m = 0;
193197 k = k_t;
....@@ -199,7 +203,7 @@
199203 out_t = in_t / ((m_t + 2) * (k_t + 2));
200204 red = abs(f_out - out_t);
201205 if (red < red_t) {
202
- bypass = false;
206
+ m_bypass = false;
203207 n = n_t;
204208 m = m_t;
205209 k = k_t;
....@@ -213,8 +217,13 @@
213217 pr_debug("Only get approximation about PLL\n");
214218
215219 code_find:
220
+ if (k == -1) {
221
+ k_bypass = true;
222
+ k = 0;
223
+ }
216224
217
- pll_code->m_bp = bypass;
225
+ pll_code->m_bp = m_bypass;
226
+ pll_code->k_bp = k_bypass;
218227 pll_code->m_code = m;
219228 pll_code->n_code = n;
220229 pll_code->k_code = k;