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()
695 if (sdev->system_suspend_target > SOF_SUSPEND_S3 || in hda_suspend()
697 sdev->system_suspend_target == SOF_SUSPEND_S3)) in hda_suspend()
704 if (imr_lost || sdev->fw_state == SOF_FW_CRASHED || in hda_suspend()
705 sdev->fw_state == SOF_FW_BOOT_FAILED) in hda_suspend()
708 ret = chip->disable_interrupts(sdev); in hda_suspend()
713 synchronize_irq(sdev->ipc_irq); in hda_suspend()
715 hda_codec_jack_wake_enable(sdev, runtime_suspend); in hda_suspend()
720 if (sdev->dspless_mode_selected) in hda_suspend()
723 ret = chip->power_down_dsp(sdev); in hda_suspend()
725 dev_err(sdev->dev, "failed to power down DSP during suspend\n"); in hda_suspend()
731 sdev->dsp_core_ref_count[j] = 0; in hda_suspend()
734 hda_dsp_ctrl_ppcap_enable(sdev, false); in hda_suspend()
735 hda_dsp_ctrl_ppcap_int_enable(sdev, false); in hda_suspend()
739 hda_dsp_ctrl_stop_chip(sdev); in hda_suspend()
742 snd_sof_pci_update_bits(sdev, PCI_PGCTL, in hda_suspend()
746 ret = hda_dsp_ctrl_link_reset(sdev, true); in hda_suspend()
748 dev_err(sdev->dev, in hda_suspend()
754 hda_codec_i915_display_power(sdev, false); in hda_suspend()
759 static int hda_resume(struct snd_sof_dev *sdev, bool runtime_resume) in hda_resume() argument
764 hda_codec_i915_display_power(sdev, true); in hda_resume()
770 snd_sof_pci_update_bits(sdev, PCI_TCSEL, 0x07, 0); in hda_resume()
773 ret = hda_dsp_ctrl_init_chip(sdev); in hda_resume()
775 dev_err(sdev->dev, in hda_resume()
782 hda_codec_jack_wake_enable(sdev, false); in hda_resume()
783 if (sdev->system_suspend_target == SOF_SUSPEND_NONE) in hda_resume()
784 hda_codec_jack_check(sdev); in hda_resume()
787 if (!sdev->dspless_mode_selected) { in hda_resume()
789 hda_dsp_ctrl_ppcap_enable(sdev, true); in hda_resume()
790 hda_dsp_ctrl_ppcap_int_enable(sdev, true); in hda_resume()
795 hda_codec_i915_display_power(sdev, false); in hda_resume()
800 int hda_dsp_resume(struct snd_sof_dev *sdev) in hda_dsp_resume() argument
802 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata; in hda_dsp_resume()
803 struct hdac_bus *bus = sof_to_bus(sdev); in hda_dsp_resume()
804 struct pci_dev *pci = to_pci_dev(sdev->dev); in hda_dsp_resume()
812 if (sdev->dsp_power_state.state == SOF_DSP_PM_D0) { in hda_dsp_resume()
815 dev_err(sdev->dev, in hda_dsp_resume()
822 hda_codec_resume_cmd_io(sdev); in hda_dsp_resume()
825 ret = snd_sof_dsp_set_power_state(sdev, &target_state); in hda_dsp_resume()
827 dev_err(sdev->dev, "error: setting dsp state %d substate %d\n", in hda_dsp_resume()
834 snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, in hda_dsp_resume()
845 ret = hda_resume(sdev, false); in hda_dsp_resume()
849 return snd_sof_dsp_set_power_state(sdev, &target_state); in hda_dsp_resume()
852 int hda_dsp_runtime_resume(struct snd_sof_dev *sdev) in hda_dsp_runtime_resume() argument
860 ret = hda_resume(sdev, true); in hda_dsp_runtime_resume()
864 return snd_sof_dsp_set_power_state(sdev, &target_state); in hda_dsp_runtime_resume()
867 int hda_dsp_runtime_idle(struct snd_sof_dev *sdev) in hda_dsp_runtime_idle() argument
869 struct hdac_bus *hbus = sof_to_bus(sdev); in hda_dsp_runtime_idle()
872 dev_dbg(sdev->dev, "some codecs still powered (%08X), not idle\n", in hda_dsp_runtime_idle()
880 int hda_dsp_runtime_suspend(struct snd_sof_dev *sdev) in hda_dsp_runtime_suspend() argument
882 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata; in hda_dsp_runtime_suspend()
888 if (!sdev->dspless_mode_selected) { in hda_dsp_runtime_suspend()
894 ret = hda_suspend(sdev, true); in hda_dsp_runtime_suspend()
898 return snd_sof_dsp_set_power_state(sdev, &target_state); in hda_dsp_runtime_suspend()
901 int hda_dsp_suspend(struct snd_sof_dev *sdev, u32 target_state) in hda_dsp_suspend() argument
903 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata; in hda_dsp_suspend()
904 struct hdac_bus *bus = sof_to_bus(sdev); in hda_dsp_suspend()
905 struct pci_dev *pci = to_pci_dev(sdev->dev); in hda_dsp_suspend()
913 if (!sdev->dspless_mode_selected) { in hda_dsp_suspend()
920 ret = snd_sof_dsp_set_power_state(sdev, &target_dsp_state); in hda_dsp_suspend()
922 dev_err(sdev->dev, "error: setting dsp state %d substate %d\n", in hda_dsp_suspend()
930 snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, HDA_VS_INTEL_EM2, in hda_dsp_suspend()
934 hda_codec_suspend_cmd_io(sdev); in hda_dsp_suspend()
939 dev_err(sdev->dev, in hda_dsp_suspend()
952 ret = hda_suspend(sdev, false); in hda_dsp_suspend()
958 return snd_sof_dsp_set_power_state(sdev, &target_dsp_state); in hda_dsp_suspend()
961 static unsigned int hda_dsp_check_for_dma_streams(struct snd_sof_dev *sdev) in hda_dsp_check_for_dma_streams() argument
963 struct hdac_bus *bus = sof_to_bus(sdev); in hda_dsp_check_for_dma_streams()
971 val = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, in hda_dsp_check_for_dma_streams()
980 static int hda_dsp_s5_quirk(struct snd_sof_dev *sdev) in hda_dsp_s5_quirk() argument
996 ret = hda_dsp_ctrl_link_reset(sdev, false); in hda_dsp_s5_quirk()
1003 ret = hda_dsp_ctrl_link_reset(sdev, true); in hda_dsp_s5_quirk()
1010 int hda_dsp_shutdown_dma_flush(struct snd_sof_dev *sdev) in hda_dsp_shutdown_dma_flush() argument
1016 active_streams = hda_dsp_check_for_dma_streams(sdev); in hda_dsp_shutdown_dma_flush()
1018 sdev->system_suspend_target = SOF_SUSPEND_S3; in hda_dsp_shutdown_dma_flush()
1019 ret = snd_sof_suspend(sdev->dev); in hda_dsp_shutdown_dma_flush()
1022 dev_warn(sdev->dev, in hda_dsp_shutdown_dma_flush()
1025 ret2 = hda_dsp_s5_quirk(sdev); in hda_dsp_shutdown_dma_flush()
1027 dev_err(sdev->dev, "shutdown recovery failed (%d)\n", ret2); in hda_dsp_shutdown_dma_flush()
1033 int hda_dsp_shutdown(struct snd_sof_dev *sdev) in hda_dsp_shutdown() argument
1035 sdev->system_suspend_target = SOF_SUSPEND_S3; in hda_dsp_shutdown()
1036 return snd_sof_suspend(sdev->dev); in hda_dsp_shutdown()
1039 int hda_dsp_set_hw_params_upon_resume(struct snd_sof_dev *sdev) in hda_dsp_set_hw_params_upon_resume() argument
1044 ret = hda_dsp_dais_suspend(sdev); in hda_dsp_set_hw_params_upon_resume()
1046 dev_warn(sdev->dev, "%s: failure in hda_dsp_dais_suspend\n", __func__); in hda_dsp_set_hw_params_upon_resume()
1057 struct snd_sof_dev *sdev = dev_get_drvdata(bus->dev); in hda_dsp_d0i3_work() local
1065 if (!snd_sof_dsp_only_d0i3_compatible_stream_active(sdev)) in hda_dsp_d0i3_work()
1070 ret = snd_sof_dsp_set_power_state(sdev, &target_state); in hda_dsp_d0i3_work()
1072 dev_err_ratelimited(sdev->dev, in hda_dsp_d0i3_work()
1077 int hda_dsp_core_get(struct snd_sof_dev *sdev, int core) in hda_dsp_core_get() argument
1079 const struct sof_ipc_pm_ops *pm_ops = sdev->ipc->ops->pm; in hda_dsp_core_get()
1083 ret = hda_dsp_enable_core(sdev, BIT(core)); in hda_dsp_core_get()
1085 dev_err(sdev->dev, "failed to power up core %d with err: %d\n", in hda_dsp_core_get()
1091 if (sdev->fw_state != SOF_FW_BOOT_COMPLETE || core == SOF_DSP_PRIMARY_CORE) in hda_dsp_core_get()
1099 ret = pm_ops->set_core_state(sdev, core, true); in hda_dsp_core_get()
1101 dev_err(sdev->dev, "failed to enable secondary core '%d' failed with %d\n", in hda_dsp_core_get()
1110 ret1 = hda_dsp_core_reset_power_down(sdev, BIT(core)); in hda_dsp_core_get()
1112 dev_err(sdev->dev, "failed to power down core: %d with err: %d\n", core, ret1); in hda_dsp_core_get()
1117 int hda_dsp_disable_interrupts(struct snd_sof_dev *sdev) in hda_dsp_disable_interrupts() argument
1119 hda_sdw_int_enable(sdev, false); in hda_dsp_disable_interrupts()
1120 hda_dsp_ipc_int_disable(sdev); in hda_dsp_disable_interrupts()