hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/sound/soc/sh/rcar/src.c
....@@ -25,7 +25,6 @@
2525 struct rsnd_mod *dma;
2626 struct rsnd_kctrl_cfg_s sen; /* sync convert enable */
2727 struct rsnd_kctrl_cfg_s sync; /* sync convert */
28
- u32 convert_rate; /* sampling rate convert */
2928 int irq;
3029 };
3130
....@@ -89,12 +88,12 @@
8988 return 0;
9089
9190 if (!rsnd_src_sync_is_enabled(mod))
92
- return src->convert_rate;
91
+ return rsnd_io_converted_rate(io);
9392
9493 convert_rate = src->sync.val;
9594
9695 if (!convert_rate)
97
- convert_rate = src->convert_rate;
96
+ convert_rate = rsnd_io_converted_rate(io);
9897
9998 if (!convert_rate)
10099 convert_rate = runtime->rate;
....@@ -135,39 +134,59 @@
135134 return rate;
136135 }
137136
138
-static int rsnd_src_hw_params(struct rsnd_mod *mod,
139
- struct rsnd_dai_stream *io,
140
- struct snd_pcm_substream *substream,
141
- struct snd_pcm_hw_params *fe_params)
142
-{
143
- struct rsnd_src *src = rsnd_mod_to_src(mod);
144
- struct snd_soc_pcm_runtime *fe = substream->private_data;
137
+static const u32 bsdsr_table_pattern1[] = {
138
+ 0x01800000, /* 6 - 1/6 */
139
+ 0x01000000, /* 6 - 1/4 */
140
+ 0x00c00000, /* 6 - 1/3 */
141
+ 0x00800000, /* 6 - 1/2 */
142
+ 0x00600000, /* 6 - 2/3 */
143
+ 0x00400000, /* 6 - 1 */
144
+};
145145
146
- /*
147
- * SRC assumes that it is used under DPCM if user want to use
148
- * sampling rate convert. Then, SRC should be FE.
149
- * And then, this function will be called *after* BE settings.
150
- * this means, each BE already has fixuped hw_params.
151
- * see
152
- * dpcm_fe_dai_hw_params()
153
- * dpcm_be_dai_hw_params()
154
- */
155
- src->convert_rate = 0;
156
- if (fe->dai_link->dynamic) {
157
- int stream = substream->stream;
158
- struct snd_soc_dpcm *dpcm;
159
- struct snd_pcm_hw_params *be_params;
146
+static const u32 bsdsr_table_pattern2[] = {
147
+ 0x02400000, /* 6 - 1/6 */
148
+ 0x01800000, /* 6 - 1/4 */
149
+ 0x01200000, /* 6 - 1/3 */
150
+ 0x00c00000, /* 6 - 1/2 */
151
+ 0x00900000, /* 6 - 2/3 */
152
+ 0x00600000, /* 6 - 1 */
153
+};
160154
161
- list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
162
- be_params = &dpcm->hw_params;
155
+static const u32 bsisr_table[] = {
156
+ 0x00100060, /* 6 - 1/6 */
157
+ 0x00100040, /* 6 - 1/4 */
158
+ 0x00100030, /* 6 - 1/3 */
159
+ 0x00100020, /* 6 - 1/2 */
160
+ 0x00100020, /* 6 - 2/3 */
161
+ 0x00100020, /* 6 - 1 */
162
+};
163163
164
- if (params_rate(fe_params) != params_rate(be_params))
165
- src->convert_rate = params_rate(be_params);
166
- }
167
- }
164
+static const u32 chan288888[] = {
165
+ 0x00000006, /* 1 to 2 */
166
+ 0x000001fe, /* 1 to 8 */
167
+ 0x000001fe, /* 1 to 8 */
168
+ 0x000001fe, /* 1 to 8 */
169
+ 0x000001fe, /* 1 to 8 */
170
+ 0x000001fe, /* 1 to 8 */
171
+};
168172
169
- return 0;
170
-}
173
+static const u32 chan244888[] = {
174
+ 0x00000006, /* 1 to 2 */
175
+ 0x0000001e, /* 1 to 4 */
176
+ 0x0000001e, /* 1 to 4 */
177
+ 0x000001fe, /* 1 to 8 */
178
+ 0x000001fe, /* 1 to 8 */
179
+ 0x000001fe, /* 1 to 8 */
180
+};
181
+
182
+static const u32 chan222222[] = {
183
+ 0x00000006, /* 1 to 2 */
184
+ 0x00000006, /* 1 to 2 */
185
+ 0x00000006, /* 1 to 2 */
186
+ 0x00000006, /* 1 to 2 */
187
+ 0x00000006, /* 1 to 2 */
188
+ 0x00000006, /* 1 to 2 */
189
+};
171190
172191 static void rsnd_src_set_convert_rate(struct rsnd_dai_stream *io,
173192 struct rsnd_mod *mod)
....@@ -180,15 +199,20 @@
180199 u32 fin, fout;
181200 u32 ifscr, fsrate, adinr;
182201 u32 cr, route;
183
- u32 bsdsr, bsisr;
184202 u32 i_busif, o_busif, tmp;
203
+ const u32 *bsdsr_table;
204
+ const u32 *chptn;
185205 uint ratio;
206
+ int chan;
207
+ int idx;
186208
187209 if (!runtime)
188210 return;
189211
190212 fin = rsnd_src_get_in_rate(priv, io);
191213 fout = rsnd_src_get_out_rate(priv, io);
214
+
215
+ chan = rsnd_runtime_channel_original(io);
192216
193217 /* 6 - 1/6 are very enough ratio for SRC_BSDSR */
194218 if (fin == fout)
....@@ -208,8 +232,7 @@
208232 /*
209233 * SRC_ADINR
210234 */
211
- adinr = rsnd_get_adinr_bit(mod, io) |
212
- rsnd_runtime_channel_original(io);
235
+ adinr = rsnd_get_adinr_bit(mod, io) | chan;
213236
214237 /*
215238 * SRC_IFSCR / SRC_IFSVR
....@@ -242,20 +265,55 @@
242265
243266 /*
244267 * SRC_BSDSR / SRC_BSISR
268
+ *
269
+ * see
270
+ * Combination of Register Setting Related to
271
+ * FSO/FSI Ratio and Channel, Latency
245272 */
246273 switch (rsnd_mod_id(mod)) {
274
+ case 0:
275
+ chptn = chan288888;
276
+ bsdsr_table = bsdsr_table_pattern1;
277
+ break;
278
+ case 1:
279
+ case 3:
280
+ case 4:
281
+ chptn = chan244888;
282
+ bsdsr_table = bsdsr_table_pattern1;
283
+ break;
284
+ case 2:
285
+ case 9:
286
+ chptn = chan222222;
287
+ bsdsr_table = bsdsr_table_pattern1;
288
+ break;
247289 case 5:
248290 case 6:
249291 case 7:
250292 case 8:
251
- bsdsr = 0x02400000; /* 6 - 1/6 */
252
- bsisr = 0x00100060; /* 6 - 1/6 */
293
+ chptn = chan222222;
294
+ bsdsr_table = bsdsr_table_pattern2;
253295 break;
254296 default:
255
- bsdsr = 0x01800000; /* 6 - 1/6 */
256
- bsisr = 0x00100060 ;/* 6 - 1/6 */
257
- break;
297
+ goto convert_rate_err;
258298 }
299
+
300
+ /*
301
+ * E3 need to overwrite
302
+ */
303
+ if (rsnd_is_e3(priv))
304
+ switch (rsnd_mod_id(mod)) {
305
+ case 0:
306
+ case 4:
307
+ chptn = chan222222;
308
+ }
309
+
310
+ for (idx = 0; idx < ARRAY_SIZE(chan222222); idx++)
311
+ if (chptn[idx] & (1 << chan))
312
+ break;
313
+
314
+ if (chan > 8 ||
315
+ idx >= ARRAY_SIZE(chan222222))
316
+ goto convert_rate_err;
259317
260318 /* BUSIF_MODE */
261319 tmp = rsnd_get_busif_shift(io, mod);
....@@ -269,8 +327,8 @@
269327 rsnd_mod_write(mod, SRC_IFSCR, ifscr);
270328 rsnd_mod_write(mod, SRC_IFSVR, fsrate);
271329 rsnd_mod_write(mod, SRC_SRCCR, cr);
272
- rsnd_mod_write(mod, SRC_BSDSR, bsdsr);
273
- rsnd_mod_write(mod, SRC_BSISR, bsisr);
330
+ rsnd_mod_write(mod, SRC_BSDSR, bsdsr_table[idx]);
331
+ rsnd_mod_write(mod, SRC_BSISR, bsisr_table[idx]);
274332 rsnd_mod_write(mod, SRC_SRCIR, 0); /* cancel initialize */
275333
276334 rsnd_mod_write(mod, SRC_I_BUSIF_MODE, i_busif);
....@@ -279,6 +337,11 @@
279337 rsnd_mod_write(mod, SRC_BUSIF_DALIGN, rsnd_get_dalign(mod, io));
280338
281339 rsnd_adg_set_src_timesel_gen2(mod, io, fin, fout);
340
+
341
+ return;
342
+
343
+convert_rate_err:
344
+ dev_err(dev, "unknown BSDSR/BSDIR settings\n");
282345 }
283346
284347 static int rsnd_src_irq(struct rsnd_mod *mod,
....@@ -349,9 +412,8 @@
349412 status0 = rsnd_mod_read(mod, SCU_SYS_STATUS0);
350413 status1 = rsnd_mod_read(mod, SCU_SYS_STATUS1);
351414 if ((status0 & val0) || (status1 & val1)) {
352
- rsnd_dbg_irq_status(dev, "%s[%d] err status : 0x%08x, 0x%08x\n",
353
- rsnd_mod_name(mod), rsnd_mod_id(mod),
354
- status0, status1);
415
+ rsnd_dbg_irq_status(dev, "%s err status : 0x%08x, 0x%08x\n",
416
+ rsnd_mod_name(mod), status0, status1);
355417
356418 ret = true;
357419 }
....@@ -392,11 +454,14 @@
392454 struct rsnd_priv *priv)
393455 {
394456 struct rsnd_src *src = rsnd_mod_to_src(mod);
457
+ int ret;
395458
396459 /* reset sync convert_rate */
397460 src->sync.val = 0;
398461
399
- rsnd_mod_power_on(mod);
462
+ ret = rsnd_mod_power_on(mod);
463
+ if (ret < 0)
464
+ return ret;
400465
401466 rsnd_src_activation(mod);
402467
....@@ -527,16 +592,16 @@
527592 }
528593
529594 static struct rsnd_mod_ops rsnd_src_ops = {
530
- .name = SRC_NAME,
531
- .dma_req = rsnd_src_dma_req,
532
- .probe = rsnd_src_probe_,
533
- .init = rsnd_src_init,
534
- .quit = rsnd_src_quit,
535
- .start = rsnd_src_start,
536
- .stop = rsnd_src_stop,
537
- .irq = rsnd_src_irq,
538
- .hw_params = rsnd_src_hw_params,
539
- .pcm_new = rsnd_src_pcm_new,
595
+ .name = SRC_NAME,
596
+ .dma_req = rsnd_src_dma_req,
597
+ .probe = rsnd_src_probe_,
598
+ .init = rsnd_src_init,
599
+ .quit = rsnd_src_quit,
600
+ .start = rsnd_src_start,
601
+ .stop = rsnd_src_stop,
602
+ .irq = rsnd_src_irq,
603
+ .pcm_new = rsnd_src_pcm_new,
604
+ .get_status = rsnd_mod_get_status,
540605 };
541606
542607 struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id)
....@@ -605,8 +670,7 @@
605670 }
606671
607672 ret = rsnd_mod_init(priv, rsnd_mod_get(src),
608
- &rsnd_src_ops, clk, rsnd_mod_get_status,
609
- RSND_MOD_SRC, i);
673
+ &rsnd_src_ops, clk, RSND_MOD_SRC, i);
610674 if (ret) {
611675 of_node_put(np);
612676 goto rsnd_src_probe_done;