.. | .. |
---|
25 | 25 | struct rsnd_mod *dma; |
---|
26 | 26 | struct rsnd_kctrl_cfg_s sen; /* sync convert enable */ |
---|
27 | 27 | struct rsnd_kctrl_cfg_s sync; /* sync convert */ |
---|
28 | | - u32 convert_rate; /* sampling rate convert */ |
---|
29 | 28 | int irq; |
---|
30 | 29 | }; |
---|
31 | 30 | |
---|
.. | .. |
---|
89 | 88 | return 0; |
---|
90 | 89 | |
---|
91 | 90 | if (!rsnd_src_sync_is_enabled(mod)) |
---|
92 | | - return src->convert_rate; |
---|
| 91 | + return rsnd_io_converted_rate(io); |
---|
93 | 92 | |
---|
94 | 93 | convert_rate = src->sync.val; |
---|
95 | 94 | |
---|
96 | 95 | if (!convert_rate) |
---|
97 | | - convert_rate = src->convert_rate; |
---|
| 96 | + convert_rate = rsnd_io_converted_rate(io); |
---|
98 | 97 | |
---|
99 | 98 | if (!convert_rate) |
---|
100 | 99 | convert_rate = runtime->rate; |
---|
.. | .. |
---|
135 | 134 | return rate; |
---|
136 | 135 | } |
---|
137 | 136 | |
---|
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 | +}; |
---|
145 | 145 | |
---|
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 | +}; |
---|
160 | 154 | |
---|
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 | +}; |
---|
163 | 163 | |
---|
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 | +}; |
---|
168 | 172 | |
---|
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 | +}; |
---|
171 | 190 | |
---|
172 | 191 | static void rsnd_src_set_convert_rate(struct rsnd_dai_stream *io, |
---|
173 | 192 | struct rsnd_mod *mod) |
---|
.. | .. |
---|
180 | 199 | u32 fin, fout; |
---|
181 | 200 | u32 ifscr, fsrate, adinr; |
---|
182 | 201 | u32 cr, route; |
---|
183 | | - u32 bsdsr, bsisr; |
---|
184 | 202 | u32 i_busif, o_busif, tmp; |
---|
| 203 | + const u32 *bsdsr_table; |
---|
| 204 | + const u32 *chptn; |
---|
185 | 205 | uint ratio; |
---|
| 206 | + int chan; |
---|
| 207 | + int idx; |
---|
186 | 208 | |
---|
187 | 209 | if (!runtime) |
---|
188 | 210 | return; |
---|
189 | 211 | |
---|
190 | 212 | fin = rsnd_src_get_in_rate(priv, io); |
---|
191 | 213 | fout = rsnd_src_get_out_rate(priv, io); |
---|
| 214 | + |
---|
| 215 | + chan = rsnd_runtime_channel_original(io); |
---|
192 | 216 | |
---|
193 | 217 | /* 6 - 1/6 are very enough ratio for SRC_BSDSR */ |
---|
194 | 218 | if (fin == fout) |
---|
.. | .. |
---|
208 | 232 | /* |
---|
209 | 233 | * SRC_ADINR |
---|
210 | 234 | */ |
---|
211 | | - adinr = rsnd_get_adinr_bit(mod, io) | |
---|
212 | | - rsnd_runtime_channel_original(io); |
---|
| 235 | + adinr = rsnd_get_adinr_bit(mod, io) | chan; |
---|
213 | 236 | |
---|
214 | 237 | /* |
---|
215 | 238 | * SRC_IFSCR / SRC_IFSVR |
---|
.. | .. |
---|
242 | 265 | |
---|
243 | 266 | /* |
---|
244 | 267 | * SRC_BSDSR / SRC_BSISR |
---|
| 268 | + * |
---|
| 269 | + * see |
---|
| 270 | + * Combination of Register Setting Related to |
---|
| 271 | + * FSO/FSI Ratio and Channel, Latency |
---|
245 | 272 | */ |
---|
246 | 273 | 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; |
---|
247 | 289 | case 5: |
---|
248 | 290 | case 6: |
---|
249 | 291 | case 7: |
---|
250 | 292 | case 8: |
---|
251 | | - bsdsr = 0x02400000; /* 6 - 1/6 */ |
---|
252 | | - bsisr = 0x00100060; /* 6 - 1/6 */ |
---|
| 293 | + chptn = chan222222; |
---|
| 294 | + bsdsr_table = bsdsr_table_pattern2; |
---|
253 | 295 | break; |
---|
254 | 296 | default: |
---|
255 | | - bsdsr = 0x01800000; /* 6 - 1/6 */ |
---|
256 | | - bsisr = 0x00100060 ;/* 6 - 1/6 */ |
---|
257 | | - break; |
---|
| 297 | + goto convert_rate_err; |
---|
258 | 298 | } |
---|
| 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; |
---|
259 | 317 | |
---|
260 | 318 | /* BUSIF_MODE */ |
---|
261 | 319 | tmp = rsnd_get_busif_shift(io, mod); |
---|
.. | .. |
---|
269 | 327 | rsnd_mod_write(mod, SRC_IFSCR, ifscr); |
---|
270 | 328 | rsnd_mod_write(mod, SRC_IFSVR, fsrate); |
---|
271 | 329 | 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]); |
---|
274 | 332 | rsnd_mod_write(mod, SRC_SRCIR, 0); /* cancel initialize */ |
---|
275 | 333 | |
---|
276 | 334 | rsnd_mod_write(mod, SRC_I_BUSIF_MODE, i_busif); |
---|
.. | .. |
---|
279 | 337 | rsnd_mod_write(mod, SRC_BUSIF_DALIGN, rsnd_get_dalign(mod, io)); |
---|
280 | 338 | |
---|
281 | 339 | 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"); |
---|
282 | 345 | } |
---|
283 | 346 | |
---|
284 | 347 | static int rsnd_src_irq(struct rsnd_mod *mod, |
---|
.. | .. |
---|
349 | 412 | status0 = rsnd_mod_read(mod, SCU_SYS_STATUS0); |
---|
350 | 413 | status1 = rsnd_mod_read(mod, SCU_SYS_STATUS1); |
---|
351 | 414 | 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); |
---|
355 | 417 | |
---|
356 | 418 | ret = true; |
---|
357 | 419 | } |
---|
.. | .. |
---|
392 | 454 | struct rsnd_priv *priv) |
---|
393 | 455 | { |
---|
394 | 456 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
---|
| 457 | + int ret; |
---|
395 | 458 | |
---|
396 | 459 | /* reset sync convert_rate */ |
---|
397 | 460 | src->sync.val = 0; |
---|
398 | 461 | |
---|
399 | | - rsnd_mod_power_on(mod); |
---|
| 462 | + ret = rsnd_mod_power_on(mod); |
---|
| 463 | + if (ret < 0) |
---|
| 464 | + return ret; |
---|
400 | 465 | |
---|
401 | 466 | rsnd_src_activation(mod); |
---|
402 | 467 | |
---|
.. | .. |
---|
527 | 592 | } |
---|
528 | 593 | |
---|
529 | 594 | 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, |
---|
540 | 605 | }; |
---|
541 | 606 | |
---|
542 | 607 | struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id) |
---|
.. | .. |
---|
605 | 670 | } |
---|
606 | 671 | |
---|
607 | 672 | 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); |
---|
610 | 674 | if (ret) { |
---|
611 | 675 | of_node_put(np); |
---|
612 | 676 | goto rsnd_src_probe_done; |
---|