|
29 | 29 | #define SDnFMT_BITS(x) ((x) << 4) |
30 | 30 | #define SDnFMT_CHAN(x) ((x) << 0) |
31 | 31 |
|
| 32 | +#define HDA_MAX_PERIOD_TIME_HEADROOM 10 |
| 33 | + |
32 | 34 | static bool hda_always_enable_dmi_l1; |
33 | 35 | module_param_named(always_enable_dmi_l1, hda_always_enable_dmi_l1, bool, 0444); |
34 | 36 | MODULE_PARM_DESC(always_enable_dmi_l1, "SOF HDA always enable DMI l1"); |
@@ -295,19 +297,35 @@ int hda_dsp_pcm_open(struct snd_sof_dev *sdev, |
295 | 297 | SNDRV_PCM_FMTBIT_S16 | SNDRV_PCM_FMTBIT_S32); |
296 | 298 |
|
297 | 299 | /* |
298 | | - * The dsp_min_burst_size_in_ms is the length of the minimum burst size |
| 300 | + * The dsp_max_burst_size_in_ms is the length of the maximum burst size |
299 | 301 | * of the host DMA in the ALSA buffer. |
300 | 302 | * |
301 | | - * Set a constraint to period time min to be at least twice as long as |
302 | | - * the minimum burst size to avoid DMA overruns |
| 303 | + * On playback start the DMA will transfer dsp_max_burst_size_in_ms |
| 304 | + * amount of data in one initial burst to fill up the host DMA buffer. |
| 305 | + * Consequent DMA burst sizes are shorter and their length can vary. |
| 306 | + * To avoid immediate xrun by the initial burst we need to place |
| 307 | + * constraint on the period size (via PERIOD_TIME) to cover the size of |
| 308 | + * the host buffer. |
| 309 | + * We need to add headroom of max 10ms as the firmware needs time to |
| 310 | + * settle to the 1ms pacing and initially it can run faster for few |
| 311 | + * internal periods. |
| 312 | + * |
| 313 | + * On capture the DMA will transfer 1ms chunks. |
303 | 314 | */ |
304 | | - if (spcm->stream[direction].dsp_min_burst_size_in_ms) { |
305 | | - unsigned int burst_time = spcm->stream[direction].dsp_min_burst_size_in_ms; |
| 315 | + if (spcm->stream[direction].dsp_max_burst_size_in_ms) { |
| 316 | + unsigned int period_time = spcm->stream[direction].dsp_max_burst_size_in_ms; |
| 317 | + |
| 318 | + /* |
| 319 | + * add headroom over the maximum burst size to cover the time |
| 320 | + * needed for the DMA pace to settle. |
| 321 | + * Limit the headroom time to HDA_MAX_PERIOD_TIME_HEADROOM |
| 322 | + */ |
| 323 | + period_time += min(period_time, HDA_MAX_PERIOD_TIME_HEADROOM); |
306 | 324 |
|
307 | 325 | snd_pcm_hw_constraint_minmax(substream->runtime, |
308 | | - SNDRV_PCM_HW_PARAM_PERIOD_TIME, |
309 | | - burst_time * USEC_PER_MSEC * 2, |
310 | | - UINT_MAX); |
| 326 | + SNDRV_PCM_HW_PARAM_PERIOD_TIME, |
| 327 | + period_time * USEC_PER_MSEC, |
| 328 | + UINT_MAX); |
311 | 329 | } |
312 | 330 |
|
313 | 331 | /* binding pcm substream to hda stream */ |
|
0 commit comments