Lines Matching refs:sdev

39 static int hda_dsp_core_reset_enter(struct snd_sof_dev *sdev, unsigned int core_mask)  in hda_dsp_core_reset_enter()  argument
47 snd_sof_dsp_update_bits_unlocked(sdev, HDA_DSP_BAR, in hda_dsp_core_reset_enter()
52 ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR, in hda_dsp_core_reset_enter()
58 dev_err(sdev->dev, in hda_dsp_core_reset_enter()
65 adspcs = snd_sof_dsp_read(sdev, HDA_DSP_BAR, in hda_dsp_core_reset_enter()
69 dev_err(sdev->dev, in hda_dsp_core_reset_enter()
78 static int hda_dsp_core_reset_leave(struct snd_sof_dev *sdev, unsigned int core_mask) in hda_dsp_core_reset_leave() argument
85 snd_sof_dsp_update_bits_unlocked(sdev, HDA_DSP_BAR, in hda_dsp_core_reset_leave()
92 ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR, in hda_dsp_core_reset_leave()
99 dev_err(sdev->dev, in hda_dsp_core_reset_leave()
106 adspcs = snd_sof_dsp_read(sdev, HDA_DSP_BAR, in hda_dsp_core_reset_leave()
109 dev_err(sdev->dev, in hda_dsp_core_reset_leave()
118 int hda_dsp_core_stall_reset(struct snd_sof_dev *sdev, unsigned int core_mask) in hda_dsp_core_stall_reset() argument
121 snd_sof_dsp_update_bits_unlocked(sdev, HDA_DSP_BAR, in hda_dsp_core_stall_reset()
127 return hda_dsp_core_reset_enter(sdev, core_mask); in hda_dsp_core_stall_reset()
130 bool hda_dsp_core_is_enabled(struct snd_sof_dev *sdev, unsigned int core_mask) in hda_dsp_core_is_enabled() argument
135 val = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPCS); in hda_dsp_core_is_enabled()
149 dev_dbg(sdev->dev, "DSP core(s) enabled? %d : core_mask %x\n", in hda_dsp_core_is_enabled()
155 int hda_dsp_core_run(struct snd_sof_dev *sdev, unsigned int core_mask) in hda_dsp_core_run() argument
160 ret = hda_dsp_core_reset_leave(sdev, core_mask); in hda_dsp_core_run()
165 dev_dbg(sdev->dev, "unstall/run core: core_mask = %x\n", core_mask); in hda_dsp_core_run()
166 snd_sof_dsp_update_bits_unlocked(sdev, HDA_DSP_BAR, in hda_dsp_core_run()
172 if (!hda_dsp_core_is_enabled(sdev, core_mask)) { in hda_dsp_core_run()
173 hda_dsp_core_stall_reset(sdev, core_mask); in hda_dsp_core_run()
174 dev_err(sdev->dev, "error: DSP start core failed: core_mask %x\n", in hda_dsp_core_run()
186 int hda_dsp_core_power_up(struct snd_sof_dev *sdev, unsigned int core_mask) in hda_dsp_core_power_up() argument
188 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata; in hda_dsp_core_power_up()
201 snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPCS, in hda_dsp_core_power_up()
207 ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR, in hda_dsp_core_power_up()
213 dev_err(sdev->dev, in hda_dsp_core_power_up()
220 adspcs = snd_sof_dsp_read(sdev, HDA_DSP_BAR, in hda_dsp_core_power_up()
224 dev_err(sdev->dev, in hda_dsp_core_power_up()
233 static int hda_dsp_core_power_down(struct snd_sof_dev *sdev, unsigned int core_mask) in hda_dsp_core_power_down() argument
239 snd_sof_dsp_update_bits_unlocked(sdev, HDA_DSP_BAR, in hda_dsp_core_power_down()
243 ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR, in hda_dsp_core_power_down()
249 dev_err(sdev->dev, in hda_dsp_core_power_down()
256 int hda_dsp_enable_core(struct snd_sof_dev *sdev, unsigned int core_mask) in hda_dsp_enable_core() argument
258 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata; in hda_dsp_enable_core()
266 if (!core_mask || hda_dsp_core_is_enabled(sdev, core_mask)) in hda_dsp_enable_core()
270 ret = hda_dsp_core_power_up(sdev, core_mask); in hda_dsp_enable_core()
272 dev_err(sdev->dev, "error: dsp core power up failed: core_mask %x\n", in hda_dsp_enable_core()
277 return hda_dsp_core_run(sdev, core_mask); in hda_dsp_enable_core()
280 int hda_dsp_core_reset_power_down(struct snd_sof_dev *sdev, in hda_dsp_core_reset_power_down() argument
283 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata; in hda_dsp_core_reset_power_down()
295 ret = hda_dsp_core_stall_reset(sdev, core_mask); in hda_dsp_core_reset_power_down()
297 dev_err(sdev->dev, "error: dsp core reset failed: core_mask %x\n", in hda_dsp_core_reset_power_down()
303 ret = hda_dsp_core_power_down(sdev, core_mask); in hda_dsp_core_reset_power_down()
305 dev_err(sdev->dev, "error: dsp core power down fail mask %x: %d\n", in hda_dsp_core_reset_power_down()
311 if (hda_dsp_core_is_enabled(sdev, core_mask)) { in hda_dsp_core_reset_power_down()
312 dev_err(sdev->dev, "error: dsp core disable fail mask %x: %d\n", in hda_dsp_core_reset_power_down()
320 void hda_dsp_ipc_int_enable(struct snd_sof_dev *sdev) in hda_dsp_ipc_int_enable() argument
322 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata; in hda_dsp_ipc_int_enable()
325 if (sdev->dspless_mode_selected) in hda_dsp_ipc_int_enable()
329 snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, chip->ipc_ctl, in hda_dsp_ipc_int_enable()
334 snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPIC, in hda_dsp_ipc_int_enable()
338 void hda_dsp_ipc_int_disable(struct snd_sof_dev *sdev) in hda_dsp_ipc_int_disable() argument
340 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata; in hda_dsp_ipc_int_disable()
343 if (sdev->dspless_mode_selected) in hda_dsp_ipc_int_disable()
347 snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPIC, in hda_dsp_ipc_int_disable()
351 snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, chip->ipc_ctl, in hda_dsp_ipc_int_disable()
355 static int hda_dsp_wait_d0i3c_done(struct snd_sof_dev *sdev) in hda_dsp_wait_d0i3c_done() argument
358 struct snd_sof_pdata *pdata = sdev->pdata; in hda_dsp_wait_d0i3c_done()
362 while (snd_sof_dsp_read8(sdev, HDA_DSP_HDA_BAR, chip->d0i3_offset) & in hda_dsp_wait_d0i3c_done()
372 static int hda_dsp_send_pm_gate_ipc(struct snd_sof_dev *sdev, u32 flags) in hda_dsp_send_pm_gate_ipc() argument
374 const struct sof_ipc_pm_ops *pm_ops = sof_ipc_get_ops(sdev, pm); in hda_dsp_send_pm_gate_ipc()
377 return pm_ops->set_pm_gate(sdev, flags); in hda_dsp_send_pm_gate_ipc()
382 static int hda_dsp_update_d0i3c_register(struct snd_sof_dev *sdev, u8 value) in hda_dsp_update_d0i3c_register() argument
384 struct snd_sof_pdata *pdata = sdev->pdata; in hda_dsp_update_d0i3c_register()
392 ret = hda_dsp_wait_d0i3c_done(sdev); in hda_dsp_update_d0i3c_register()
394 dev_err(sdev->dev, "CIP timeout before D0I3C update!\n"); in hda_dsp_update_d0i3c_register()
399 snd_sof_dsp_update8(sdev, HDA_DSP_HDA_BAR, chip->d0i3_offset, in hda_dsp_update_d0i3c_register()
409 ret = hda_dsp_wait_d0i3c_done(sdev); in hda_dsp_update_d0i3c_register()
411 dev_err(sdev->dev, "CIP timeout after D0I3C update!\n"); in hda_dsp_update_d0i3c_register()
415 reg = snd_sof_dsp_read8(sdev, HDA_DSP_HDA_BAR, chip->d0i3_offset); in hda_dsp_update_d0i3c_register()
418 dev_err(sdev->dev, "failed to update D0I3C!\n"); in hda_dsp_update_d0i3c_register()
422 trace_sof_intel_D0I3C_updated(sdev, reg); in hda_dsp_update_d0i3c_register()
431 static bool hda_dsp_d0i3_streaming_applicable(struct snd_sof_dev *sdev) in hda_dsp_d0i3_streaming_applicable() argument
438 list_for_each_entry(spcm, &sdev->pcm_list, list) { in hda_dsp_d0i3_streaming_applicable()
455 static int hda_dsp_set_D0_state(struct snd_sof_dev *sdev, in hda_dsp_set_D0_state() argument
469 switch (sdev->dsp_power_state.state) { in hda_dsp_set_D0_state()
477 dev_err(sdev->dev, "error: transition from %d to %d not allowed\n", in hda_dsp_set_D0_state()
478 sdev->dsp_power_state.state, target_state->state); in hda_dsp_set_D0_state()
492 if (!sdev->fw_trace_is_supported || in hda_dsp_set_D0_state()
494 sdev->system_suspend_target != SOF_SUSPEND_NONE) in hda_dsp_set_D0_state()
497 if (hda_dsp_d0i3_streaming_applicable(sdev)) in hda_dsp_set_D0_state()
505 ret = hda_dsp_update_d0i3c_register(sdev, value); in hda_dsp_set_D0_state()
514 ret = hda_dsp_send_pm_gate_ipc(sdev, flags); in hda_dsp_set_D0_state()
516 dev_err(sdev->dev, in hda_dsp_set_D0_state()
531 hda_dsp_update_d0i3c_register(sdev, value); in hda_dsp_set_D0_state()
537 static void hda_dsp_state_log(struct snd_sof_dev *sdev) in hda_dsp_state_log() argument
539 switch (sdev->dsp_power_state.state) { in hda_dsp_state_log()
541 switch (sdev->dsp_power_state.substate) { in hda_dsp_state_log()
543 dev_dbg(sdev->dev, "Current DSP power state: D0I0\n"); in hda_dsp_state_log()
546 dev_dbg(sdev->dev, "Current DSP power state: D0I3\n"); in hda_dsp_state_log()
549 dev_dbg(sdev->dev, "Unknown DSP D0 substate: %d\n", in hda_dsp_state_log()
550 sdev->dsp_power_state.substate); in hda_dsp_state_log()
555 dev_dbg(sdev->dev, "Current DSP power state: D1\n"); in hda_dsp_state_log()
558 dev_dbg(sdev->dev, "Current DSP power state: D2\n"); in hda_dsp_state_log()
561 dev_dbg(sdev->dev, "Current DSP power state: D3\n"); in hda_dsp_state_log()
564 dev_dbg(sdev->dev, "Unknown DSP power state: %d\n", in hda_dsp_state_log()
565 sdev->dsp_power_state.state); in hda_dsp_state_log()
577 static int hda_dsp_set_power_state(struct snd_sof_dev *sdev, in hda_dsp_set_power_state() argument
584 ret = hda_dsp_set_D0_state(sdev, target_state); in hda_dsp_set_power_state()
588 if (sdev->dsp_power_state.state == SOF_DSP_PM_D0 && in hda_dsp_set_power_state()
589 sdev->dsp_power_state.substate == SOF_HDA_DSP_PM_D0I0) in hda_dsp_set_power_state()
592 dev_err(sdev->dev, in hda_dsp_set_power_state()
594 sdev->dsp_power_state.state, target_state->state); in hda_dsp_set_power_state()
597 dev_err(sdev->dev, "error: target state unsupported %d\n", in hda_dsp_set_power_state()
602 dev_err(sdev->dev, in hda_dsp_set_power_state()
608 sdev->dsp_power_state = *target_state; in hda_dsp_set_power_state()
609 hda_dsp_state_log(sdev); in hda_dsp_set_power_state()
613 int hda_dsp_set_power_state_ipc3(struct snd_sof_dev *sdev, in hda_dsp_set_power_state_ipc3() argument
624 sdev->system_suspend_target == SOF_SUSPEND_S0IX) in hda_dsp_set_power_state_ipc3()
625 return hda_dsp_set_power_state(sdev, target_state); in hda_dsp_set_power_state_ipc3()
631 if (target_state->state == sdev->dsp_power_state.state && in hda_dsp_set_power_state_ipc3()
632 target_state->substate == sdev->dsp_power_state.substate) in hda_dsp_set_power_state_ipc3()
635 return hda_dsp_set_power_state(sdev, target_state); in hda_dsp_set_power_state_ipc3()
638 int hda_dsp_set_power_state_ipc4(struct snd_sof_dev *sdev, in hda_dsp_set_power_state_ipc4() argument
642 if (target_state->state == sdev->dsp_power_state.state && in hda_dsp_set_power_state_ipc4()
643 target_state->substate == sdev->dsp_power_state.substate) in hda_dsp_set_power_state_ipc4()
646 return hda_dsp_set_power_state(sdev, target_state); in hda_dsp_set_power_state_ipc4()
679 static int hda_suspend(struct snd_sof_dev *sdev, bool runtime_suspend) in hda_suspend() argument
681 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata; in hda_suspend()
683 struct hdac_bus *bus = sof_to_bus(sdev); in hda_suspend()
693 if (sdev->system_suspend_target > SOF_SUSPEND_S3 || in hda_suspend()
694 sdev->fw_state == SOF_FW_CRASHED || in hda_suspend()
695 sdev->fw_state == SOF_FW_BOOT_FAILED) in hda_suspend()
698 ret = chip->disable_interrupts(sdev); in hda_suspend()
702 hda_codec_jack_wake_enable(sdev, runtime_suspend); in hda_suspend()
707 if (sdev->dspless_mode_selected) in hda_suspend()
710 ret = chip->power_down_dsp(sdev); in hda_suspend()
712 dev_err(sdev->dev, "failed to power down DSP during suspend\n"); in hda_suspend()
718 sdev->dsp_core_ref_count[j] = 0; in hda_suspend()
721 hda_dsp_ctrl_ppcap_enable(sdev, false); in hda_suspend()
722 hda_dsp_ctrl_ppcap_int_enable(sdev, false); in hda_suspend()
726 hda_dsp_ctrl_stop_chip(sdev); in hda_suspend()
729 snd_sof_pci_update_bits(sdev, PCI_PGCTL, in hda_suspend()
733 ret = hda_dsp_ctrl_link_reset(sdev, true); in hda_suspend()
735 dev_err(sdev->dev, in hda_suspend()
741 hda_codec_i915_display_power(sdev, false); in hda_suspend()
746 static int hda_resume(struct snd_sof_dev *sdev, bool runtime_resume) in hda_resume() argument
751 hda_codec_i915_display_power(sdev, true); in hda_resume()
757 snd_sof_pci_update_bits(sdev, PCI_TCSEL, 0x07, 0); in hda_resume()
760 ret = hda_dsp_ctrl_init_chip(sdev); in hda_resume()
762 dev_err(sdev->dev, in hda_resume()
769 hda_codec_jack_wake_enable(sdev, false); in hda_resume()
770 if (sdev->system_suspend_target == SOF_SUSPEND_NONE) in hda_resume()
771 hda_codec_jack_check(sdev); in hda_resume()
774 if (!sdev->dspless_mode_selected) { in hda_resume()
776 hda_dsp_ctrl_ppcap_enable(sdev, true); in hda_resume()
777 hda_dsp_ctrl_ppcap_int_enable(sdev, true); in hda_resume()
782 hda_codec_i915_display_power(sdev, false); in hda_resume()
787 int hda_dsp_resume(struct snd_sof_dev *sdev) in hda_dsp_resume() argument
789 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata; in hda_dsp_resume()
790 struct hdac_bus *bus = sof_to_bus(sdev); in hda_dsp_resume()
791 struct pci_dev *pci = to_pci_dev(sdev->dev); in hda_dsp_resume()
799 if (sdev->dsp_power_state.state == SOF_DSP_PM_D0) { in hda_dsp_resume()
802 dev_err(sdev->dev, in hda_dsp_resume()
809 hda_codec_resume_cmd_io(sdev); in hda_dsp_resume()
812 ret = snd_sof_dsp_set_power_state(sdev, &target_state); in hda_dsp_resume()
814 dev_err(sdev->dev, "error: setting dsp state %d substate %d\n", in hda_dsp_resume()
821 snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, in hda_dsp_resume()
832 ret = hda_resume(sdev, false); in hda_dsp_resume()
836 return snd_sof_dsp_set_power_state(sdev, &target_state); in hda_dsp_resume()
839 int hda_dsp_runtime_resume(struct snd_sof_dev *sdev) in hda_dsp_runtime_resume() argument
847 ret = hda_resume(sdev, true); in hda_dsp_runtime_resume()
851 return snd_sof_dsp_set_power_state(sdev, &target_state); in hda_dsp_runtime_resume()
854 int hda_dsp_runtime_idle(struct snd_sof_dev *sdev) in hda_dsp_runtime_idle() argument
856 struct hdac_bus *hbus = sof_to_bus(sdev); in hda_dsp_runtime_idle()
859 dev_dbg(sdev->dev, "some codecs still powered (%08X), not idle\n", in hda_dsp_runtime_idle()
867 int hda_dsp_runtime_suspend(struct snd_sof_dev *sdev) in hda_dsp_runtime_suspend() argument
869 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata; in hda_dsp_runtime_suspend()
875 if (!sdev->dspless_mode_selected) { in hda_dsp_runtime_suspend()
881 ret = hda_suspend(sdev, true); in hda_dsp_runtime_suspend()
885 return snd_sof_dsp_set_power_state(sdev, &target_state); in hda_dsp_runtime_suspend()
888 int hda_dsp_suspend(struct snd_sof_dev *sdev, u32 target_state) in hda_dsp_suspend() argument
890 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata; in hda_dsp_suspend()
891 struct hdac_bus *bus = sof_to_bus(sdev); in hda_dsp_suspend()
892 struct pci_dev *pci = to_pci_dev(sdev->dev); in hda_dsp_suspend()
900 if (!sdev->dspless_mode_selected) { in hda_dsp_suspend()
907 ret = snd_sof_dsp_set_power_state(sdev, &target_dsp_state); in hda_dsp_suspend()
909 dev_err(sdev->dev, "error: setting dsp state %d substate %d\n", in hda_dsp_suspend()
917 snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, HDA_VS_INTEL_EM2, in hda_dsp_suspend()
921 hda_codec_suspend_cmd_io(sdev); in hda_dsp_suspend()
926 dev_err(sdev->dev, in hda_dsp_suspend()
939 ret = hda_suspend(sdev, false); in hda_dsp_suspend()
945 return snd_sof_dsp_set_power_state(sdev, &target_dsp_state); in hda_dsp_suspend()
948 static unsigned int hda_dsp_check_for_dma_streams(struct snd_sof_dev *sdev) in hda_dsp_check_for_dma_streams() argument
950 struct hdac_bus *bus = sof_to_bus(sdev); in hda_dsp_check_for_dma_streams()
958 val = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, in hda_dsp_check_for_dma_streams()
967 static int hda_dsp_s5_quirk(struct snd_sof_dev *sdev) in hda_dsp_s5_quirk() argument
983 ret = hda_dsp_ctrl_link_reset(sdev, false); in hda_dsp_s5_quirk()
990 ret = hda_dsp_ctrl_link_reset(sdev, true); in hda_dsp_s5_quirk()
997 int hda_dsp_shutdown_dma_flush(struct snd_sof_dev *sdev) in hda_dsp_shutdown_dma_flush() argument
1003 active_streams = hda_dsp_check_for_dma_streams(sdev); in hda_dsp_shutdown_dma_flush()
1005 sdev->system_suspend_target = SOF_SUSPEND_S3; in hda_dsp_shutdown_dma_flush()
1006 ret = snd_sof_suspend(sdev->dev); in hda_dsp_shutdown_dma_flush()
1009 dev_warn(sdev->dev, in hda_dsp_shutdown_dma_flush()
1012 ret2 = hda_dsp_s5_quirk(sdev); in hda_dsp_shutdown_dma_flush()
1014 dev_err(sdev->dev, "shutdown recovery failed (%d)\n", ret2); in hda_dsp_shutdown_dma_flush()
1020 int hda_dsp_shutdown(struct snd_sof_dev *sdev) in hda_dsp_shutdown() argument
1022 sdev->system_suspend_target = SOF_SUSPEND_S3; in hda_dsp_shutdown()
1023 return snd_sof_suspend(sdev->dev); in hda_dsp_shutdown()
1026 int hda_dsp_set_hw_params_upon_resume(struct snd_sof_dev *sdev) in hda_dsp_set_hw_params_upon_resume() argument
1031 ret = hda_dsp_dais_suspend(sdev); in hda_dsp_set_hw_params_upon_resume()
1033 dev_warn(sdev->dev, "%s: failure in hda_dsp_dais_suspend\n", __func__); in hda_dsp_set_hw_params_upon_resume()
1044 struct snd_sof_dev *sdev = dev_get_drvdata(bus->dev); in hda_dsp_d0i3_work() local
1052 if (!snd_sof_dsp_only_d0i3_compatible_stream_active(sdev)) in hda_dsp_d0i3_work()
1057 ret = snd_sof_dsp_set_power_state(sdev, &target_state); in hda_dsp_d0i3_work()
1059 dev_err_ratelimited(sdev->dev, in hda_dsp_d0i3_work()
1064 int hda_dsp_core_get(struct snd_sof_dev *sdev, int core) in hda_dsp_core_get() argument
1066 const struct sof_ipc_pm_ops *pm_ops = sdev->ipc->ops->pm; in hda_dsp_core_get()
1070 ret = hda_dsp_enable_core(sdev, BIT(core)); in hda_dsp_core_get()
1072 dev_err(sdev->dev, "failed to power up core %d with err: %d\n", in hda_dsp_core_get()
1078 if (sdev->fw_state != SOF_FW_BOOT_COMPLETE || core == SOF_DSP_PRIMARY_CORE) in hda_dsp_core_get()
1086 ret = pm_ops->set_core_state(sdev, core, true); in hda_dsp_core_get()
1088 dev_err(sdev->dev, "failed to enable secondary core '%d' failed with %d\n", in hda_dsp_core_get()
1097 ret1 = hda_dsp_core_reset_power_down(sdev, BIT(core)); in hda_dsp_core_get()
1099 dev_err(sdev->dev, "failed to power down core: %d with err: %d\n", core, ret1); in hda_dsp_core_get()
1104 int hda_dsp_disable_interrupts(struct snd_sof_dev *sdev) in hda_dsp_disable_interrupts() argument
1106 hda_sdw_int_enable(sdev, false); in hda_dsp_disable_interrupts()
1107 hda_dsp_ipc_int_disable(sdev); in hda_dsp_disable_interrupts()