Skip to content

Commit 61e285c

Browse files
ranj063broonie
authored andcommitted
ASoC: SOF: Move DSP power state transitions to platform-specific ops
The DSP device substates such as D0I0/D0I3 are platform-specific. Therefore, the d0_substate field of struct snd_sof_dev is replaced with the dsp_power_state field which represents the current state of the DSP. This field holds both the device state and the platform-specific substate values. With the DSP device substates being platform-specific, the DSP power state transitions need to be performed in the platform-specific suspend/resume ops as well. In order to achieve this, the ops signature has to be modified to pass the target device state as an argument. The target substate will be determined by the platform-specific ops before performing the transition. For example, in the case of the system suspending to S0IX, the top-level SOF device suspend callback needs to only determine if the DSP will be entering D3 or remain in D0. The target substate in case the device needs to remain in D0 (D0I0 or D0I3) will be determined by the platform-specific suspend op. With the addition of the extended set of power states for the DSP, the set_power_state op for HDA platforms has to be extended to handle only the appropriate state transitions. So, the implementation for the Intel HDA platforms is also modified. Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Link: https://lore.kernel.org/r/20200129220726.31792-6-pierre-louis.bossart@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 700d167 commit 61e285c

6 files changed

Lines changed: 242 additions & 121 deletions

File tree

‎sound/soc/sof/core.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data)
286286
/* initialize sof device */
287287
sdev->dev = dev;
288288

289-
/* initialize default D0 sub-state */
290-
sdev->d0_substate = SOF_DSP_D0I0;
289+
/* initialize default DSP power state */
290+
sdev->dsp_power_state.state = SOF_DSP_PM_D0;
291291

292292
sdev->pdata = plat_data;
293293
sdev->first_boot = true;

‎sound/soc/sof/intel/hda-dsp.c‎

Lines changed: 205 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,10 @@ static int hda_dsp_send_pm_gate_ipc(struct snd_sof_dev *sdev, u32 flags)
338338
sizeof(pm_gate), &reply, sizeof(reply));
339339
}
340340

341-
int hda_dsp_set_power_state(struct snd_sof_dev *sdev,
342-
enum sof_d0_substate d0_substate)
341+
static int hda_dsp_update_d0i3c_register(struct snd_sof_dev *sdev, u8 value)
343342
{
344343
struct hdac_bus *bus = sof_to_bus(sdev);
345-
u32 flags;
346344
int ret;
347-
u8 value;
348345

349346
/* Write to D0I3C after Command-In-Progress bit is cleared */
350347
ret = hda_dsp_wait_d0i3c_done(sdev);
@@ -354,7 +351,6 @@ int hda_dsp_set_power_state(struct snd_sof_dev *sdev,
354351
}
355352

356353
/* Update D0I3C register */
357-
value = d0_substate == SOF_DSP_D0I3 ? SOF_HDA_VS_D0I3C_I3 : 0;
358354
snd_hdac_chip_updateb(bus, VS_D0I3C, SOF_HDA_VS_D0I3C_I3, value);
359355

360356
/* Wait for cmd in progress to be cleared before exiting the function */
@@ -367,20 +363,160 @@ int hda_dsp_set_power_state(struct snd_sof_dev *sdev,
367363
dev_vdbg(bus->dev, "D0I3C updated, register = 0x%x\n",
368364
snd_hdac_chip_readb(bus, VS_D0I3C));
369365

370-
if (d0_substate == SOF_DSP_D0I0)
371-
flags = HDA_PM_PPG;/* prevent power gating in D0 */
372-
else
373-
flags = HDA_PM_NO_DMA_TRACE;/* disable DMA trace in D0I3*/
366+
return 0;
367+
}
374368

375-
/* sending pm_gate IPC */
376-
ret = hda_dsp_send_pm_gate_ipc(sdev, flags);
369+
static int hda_dsp_set_D0_state(struct snd_sof_dev *sdev,
370+
const struct sof_dsp_power_state *target_state)
371+
{
372+
u32 flags = 0;
373+
int ret;
374+
u8 value = 0;
375+
376+
/*
377+
* Sanity check for illegal state transitions
378+
* The only allowed transitions are:
379+
* 1. D3 -> D0I0
380+
* 2. D0I0 -> D0I3
381+
* 3. D0I3 -> D0I0
382+
*/
383+
switch (sdev->dsp_power_state.state) {
384+
case SOF_DSP_PM_D0:
385+
/* Follow the sequence below for D0 substate transitions */
386+
break;
387+
case SOF_DSP_PM_D3:
388+
/* Follow regular flow for D3 -> D0 transition */
389+
return 0;
390+
default:
391+
dev_err(sdev->dev, "error: transition from %d to %d not allowed\n",
392+
sdev->dsp_power_state.state, target_state->state);
393+
return -EINVAL;
394+
}
395+
396+
/* Set flags and register value for D0 target substate */
397+
if (target_state->substate == SOF_HDA_DSP_PM_D0I3) {
398+
value = SOF_HDA_VS_D0I3C_I3;
399+
400+
/* disable DMA trace in D0I3 */
401+
flags = HDA_PM_NO_DMA_TRACE;
402+
} else {
403+
/* prevent power gating in D0I0 */
404+
flags = HDA_PM_PPG;
405+
}
406+
407+
/* update D0I3C register */
408+
ret = hda_dsp_update_d0i3c_register(sdev, value);
377409
if (ret < 0)
410+
return ret;
411+
412+
/*
413+
* Notify the DSP of the state change.
414+
* If this IPC fails, revert the D0I3C register update in order
415+
* to prevent partial state change.
416+
*/
417+
ret = hda_dsp_send_pm_gate_ipc(sdev, flags);
418+
if (ret < 0) {
378419
dev_err(sdev->dev,
379420
"error: PM_GATE ipc error %d\n", ret);
421+
goto revert;
422+
}
423+
424+
return ret;
425+
426+
revert:
427+
/* fallback to the previous register value */
428+
value = value ? 0 : SOF_HDA_VS_D0I3C_I3;
429+
430+
/*
431+
* This can fail but return the IPC error to signal that
432+
* the state change failed.
433+
*/
434+
hda_dsp_update_d0i3c_register(sdev, value);
380435

381436
return ret;
382437
}
383438

439+
/*
440+
* All DSP power state transitions are initiated by the driver.
441+
* If the requested state change fails, the error is simply returned.
442+
* Further state transitions are attempted only when the set_power_save() op
443+
* is called again either because of a new IPC sent to the DSP or
444+
* during system suspend/resume.
445+
*/
446+
int hda_dsp_set_power_state(struct snd_sof_dev *sdev,
447+
const struct sof_dsp_power_state *target_state)
448+
{
449+
int ret = 0;
450+
451+
/* Nothing to do if the DSP is already in the requested state */
452+
if (target_state->state == sdev->dsp_power_state.state &&
453+
target_state->substate == sdev->dsp_power_state.substate)
454+
return 0;
455+
456+
switch (target_state->state) {
457+
case SOF_DSP_PM_D0:
458+
ret = hda_dsp_set_D0_state(sdev, target_state);
459+
break;
460+
case SOF_DSP_PM_D3:
461+
/* The only allowed transition is: D0I0 -> D3 */
462+
if (sdev->dsp_power_state.state == SOF_DSP_PM_D0 &&
463+
sdev->dsp_power_state.substate == SOF_HDA_DSP_PM_D0I0)
464+
break;
465+
466+
dev_err(sdev->dev,
467+
"error: transition from %d to %d not allowed\n",
468+
sdev->dsp_power_state.state, target_state->state);
469+
return -EINVAL;
470+
default:
471+
dev_err(sdev->dev, "error: target state unsupported %d\n",
472+
target_state->state);
473+
return -EINVAL;
474+
}
475+
if (ret < 0) {
476+
dev_err(sdev->dev,
477+
"failed to set requested target DSP state %d substate %d\n",
478+
target_state->state, target_state->substate);
479+
return ret;
480+
}
481+
482+
sdev->dsp_power_state = *target_state;
483+
dev_dbg(sdev->dev, "New DSP state %d substate %d\n",
484+
target_state->state, target_state->substate);
485+
return ret;
486+
}
487+
488+
/*
489+
* Audio DSP states may transform as below:-
490+
*
491+
* D0I3 compatible stream
492+
* Runtime +---------------------+ opened only, timeout
493+
* suspend | +--------------------+
494+
* +------------+ D0(active) | |
495+
* | | <---------------+ |
496+
* | +--------> | | |
497+
* | |Runtime +--^--+---------^--+--+ The last | |
498+
* | |resume | | | | opened D0I3 | |
499+
* | | | | | | compatible | |
500+
* | | resume| | | | stream closed | |
501+
* | | from | | D3 | | | |
502+
* | | D3 | |suspend | | d0i3 | |
503+
* | | | | | |suspend | |
504+
* | | | | | | | |
505+
* | | | | | | | |
506+
* +-v---+-----------+--v-------+ | | +------+----v----+
507+
* | | | +-----------> |
508+
* | D3 (suspended) | | | D0I3 +-----+
509+
* | | +--------------+ | |
510+
* | | resume from | | |
511+
* +-------------------^--------+ d0i3 suspend +----------------+ |
512+
* | |
513+
* | D3 suspend |
514+
* +------------------------------------------------+
515+
*
516+
* d0i3_suspend = s0_suspend && D0I3 stream opened,
517+
* D3 suspend = !d0i3_suspend,
518+
*/
519+
384520
static int hda_suspend(struct snd_sof_dev *sdev, bool runtime_suspend)
385521
{
386522
struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
@@ -480,8 +616,22 @@ int hda_dsp_resume(struct snd_sof_dev *sdev)
480616
{
481617
struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
482618
struct pci_dev *pci = to_pci_dev(sdev->dev);
619+
const struct sof_dsp_power_state target_state = {
620+
.state = SOF_DSP_PM_D0,
621+
.substate = SOF_HDA_DSP_PM_D0I0,
622+
};
623+
int ret;
624+
625+
/* resume from D0I3 */
626+
if (sdev->dsp_power_state.state == SOF_DSP_PM_D0) {
627+
/* Set DSP power state */
628+
ret = hda_dsp_set_power_state(sdev, &target_state);
629+
if (ret < 0) {
630+
dev_err(sdev->dev, "error: setting dsp state %d substate %d\n",
631+
target_state.state, target_state.substate);
632+
return ret;
633+
}
483634

484-
if (sdev->system_suspend_target == SOF_SUSPEND_S0IX) {
485635
/* restore L1SEN bit */
486636
if (hda->l1_support_changed)
487637
snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR,
@@ -495,13 +645,27 @@ int hda_dsp_resume(struct snd_sof_dev *sdev)
495645
}
496646

497647
/* init hda controller. DSP cores will be powered up during fw boot */
498-
return hda_resume(sdev, false);
648+
ret = hda_resume(sdev, false);
649+
if (ret < 0)
650+
return ret;
651+
652+
hda_dsp_set_power_state(sdev, &target_state);
653+
return ret;
499654
}
500655

501656
int hda_dsp_runtime_resume(struct snd_sof_dev *sdev)
502657
{
658+
const struct sof_dsp_power_state target_state = {
659+
.state = SOF_DSP_PM_D0,
660+
};
661+
int ret;
662+
503663
/* init hda controller. DSP cores will be powered up during fw boot */
504-
return hda_resume(sdev, true);
664+
ret = hda_resume(sdev, true);
665+
if (ret < 0)
666+
return ret;
667+
668+
return hda_dsp_set_power_state(sdev, &target_state);
505669
}
506670

507671
int hda_dsp_runtime_idle(struct snd_sof_dev *sdev)
@@ -519,18 +683,41 @@ int hda_dsp_runtime_idle(struct snd_sof_dev *sdev)
519683

520684
int hda_dsp_runtime_suspend(struct snd_sof_dev *sdev)
521685
{
686+
const struct sof_dsp_power_state target_state = {
687+
.state = SOF_DSP_PM_D3,
688+
};
689+
int ret;
690+
522691
/* stop hda controller and power dsp off */
523-
return hda_suspend(sdev, true);
692+
ret = hda_suspend(sdev, true);
693+
if (ret < 0)
694+
return ret;
695+
696+
return hda_dsp_set_power_state(sdev, &target_state);
524697
}
525698

526-
int hda_dsp_suspend(struct snd_sof_dev *sdev)
699+
int hda_dsp_suspend(struct snd_sof_dev *sdev, u32 target_state)
527700
{
528701
struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
529702
struct hdac_bus *bus = sof_to_bus(sdev);
530703
struct pci_dev *pci = to_pci_dev(sdev->dev);
704+
const struct sof_dsp_power_state target_dsp_state = {
705+
.state = target_state,
706+
.substate = target_state == SOF_DSP_PM_D0 ?
707+
SOF_HDA_DSP_PM_D0I3 : 0,
708+
};
531709
int ret;
532710

533-
if (sdev->system_suspend_target == SOF_SUSPEND_S0IX) {
711+
if (target_state == SOF_DSP_PM_D0) {
712+
/* Set DSP power state */
713+
ret = hda_dsp_set_power_state(sdev, &target_dsp_state);
714+
if (ret < 0) {
715+
dev_err(sdev->dev, "error: setting dsp state %d substate %d\n",
716+
target_dsp_state.state,
717+
target_dsp_state.substate);
718+
return ret;
719+
}
720+
534721
/* enable L1SEN to make sure the system can enter S0Ix */
535722
hda->l1_support_changed =
536723
snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR,
@@ -551,7 +738,7 @@ int hda_dsp_suspend(struct snd_sof_dev *sdev)
551738
return ret;
552739
}
553740

554-
return 0;
741+
return hda_dsp_set_power_state(sdev, &target_dsp_state);
555742
}
556743

557744
int hda_dsp_set_hw_params_upon_resume(struct snd_sof_dev *sdev)

‎sound/soc/sof/intel/hda.h‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,12 @@ struct sof_intel_dsp_bdl {
392392
#define SOF_HDA_PLAYBACK 0
393393
#define SOF_HDA_CAPTURE 1
394394

395+
/* HDA DSP D0 substate */
396+
enum sof_hda_D0_substate {
397+
SOF_HDA_DSP_PM_D0I0, /* default D0 substate */
398+
SOF_HDA_DSP_PM_D0I3, /* low power D0 substate */
399+
};
400+
395401
/* represents DSP HDA controller frontend - i.e. host facing control */
396402
struct sof_intel_hda_dev {
397403

@@ -469,9 +475,9 @@ void hda_dsp_ipc_int_enable(struct snd_sof_dev *sdev);
469475
void hda_dsp_ipc_int_disable(struct snd_sof_dev *sdev);
470476

471477
int hda_dsp_set_power_state(struct snd_sof_dev *sdev,
472-
enum sof_d0_substate d0_substate);
478+
const struct sof_dsp_power_state *target_state);
473479

474-
int hda_dsp_suspend(struct snd_sof_dev *sdev);
480+
int hda_dsp_suspend(struct snd_sof_dev *sdev, u32 target_state);
475481
int hda_dsp_resume(struct snd_sof_dev *sdev);
476482
int hda_dsp_runtime_suspend(struct snd_sof_dev *sdev);
477483
int hda_dsp_runtime_resume(struct snd_sof_dev *sdev);

‎sound/soc/sof/ops.h‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,11 @@ static inline int snd_sof_dsp_resume(struct snd_sof_dev *sdev)
146146
return 0;
147147
}
148148

149-
static inline int snd_sof_dsp_suspend(struct snd_sof_dev *sdev)
149+
static inline int snd_sof_dsp_suspend(struct snd_sof_dev *sdev,
150+
u32 target_state)
150151
{
151152
if (sof_ops(sdev)->suspend)
152-
return sof_ops(sdev)->suspend(sdev);
153+
return sof_ops(sdev)->suspend(sdev, target_state);
153154

154155
return 0;
155156
}
@@ -193,14 +194,15 @@ static inline int snd_sof_dsp_set_clk(struct snd_sof_dev *sdev, u32 freq)
193194
return 0;
194195
}
195196

196-
static inline int snd_sof_dsp_set_power_state(struct snd_sof_dev *sdev,
197-
enum sof_d0_substate substate)
197+
static inline int
198+
snd_sof_dsp_set_power_state(struct snd_sof_dev *sdev,
199+
const struct sof_dsp_power_state *target_state)
198200
{
199201
if (sof_ops(sdev)->set_power_state)
200-
return sof_ops(sdev)->set_power_state(sdev, substate);
202+
return sof_ops(sdev)->set_power_state(sdev, target_state);
201203

202-
/* D0 substate is not supported */
203-
return -ENOTSUPP;
204+
/* D0 substate is not supported, do nothing here. */
205+
return 0;
204206
}
205207

206208
/* debug */

0 commit comments

Comments
 (0)