1747503b1SLiam Girdwood // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) 2747503b1SLiam Girdwood // 3747503b1SLiam Girdwood // This file is provided under a dual BSD/GPLv2 license. When using or 4747503b1SLiam Girdwood // redistributing this file, you may do so under either license. 5747503b1SLiam Girdwood // 6747503b1SLiam Girdwood // Copyright(c) 2018 Intel Corporation. All rights reserved. 7747503b1SLiam Girdwood // 8747503b1SLiam Girdwood // Authors: Liam Girdwood <liam.r.girdwood@linux.intel.com> 9747503b1SLiam Girdwood // Ranjani Sridharan <ranjani.sridharan@linux.intel.com> 10747503b1SLiam Girdwood // Rander Wang <rander.wang@intel.com> 11747503b1SLiam Girdwood // Keyon Jie <yang.jie@linux.intel.com> 12747503b1SLiam Girdwood // 13747503b1SLiam Girdwood 14747503b1SLiam Girdwood /* 15747503b1SLiam Girdwood * Hardware interface for generic Intel audio DSP HDA IP 16747503b1SLiam Girdwood */ 17747503b1SLiam Girdwood 18747503b1SLiam Girdwood #include <sound/hdaudio_ext.h> 19747503b1SLiam Girdwood #include <sound/hda_register.h> 20747503b1SLiam Girdwood #include "../ops.h" 21747503b1SLiam Girdwood #include "hda.h" 22747503b1SLiam Girdwood 23747503b1SLiam Girdwood /* 24747503b1SLiam Girdwood * DSP Core control. 25747503b1SLiam Girdwood */ 26747503b1SLiam Girdwood 27747503b1SLiam Girdwood int hda_dsp_core_reset_enter(struct snd_sof_dev *sdev, unsigned int core_mask) 28747503b1SLiam Girdwood { 29747503b1SLiam Girdwood u32 adspcs; 30747503b1SLiam Girdwood u32 reset; 31747503b1SLiam Girdwood int ret; 32747503b1SLiam Girdwood 33747503b1SLiam Girdwood /* set reset bits for cores */ 34747503b1SLiam Girdwood reset = HDA_DSP_ADSPCS_CRST_MASK(core_mask); 35747503b1SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, HDA_DSP_BAR, 36747503b1SLiam Girdwood HDA_DSP_REG_ADSPCS, 37747503b1SLiam Girdwood reset, reset), 38747503b1SLiam Girdwood 39747503b1SLiam Girdwood /* poll with timeout to check if operation successful */ 40747503b1SLiam Girdwood ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR, 41747503b1SLiam Girdwood HDA_DSP_REG_ADSPCS, adspcs, 42747503b1SLiam Girdwood ((adspcs & reset) == reset), 43747503b1SLiam Girdwood HDA_DSP_REG_POLL_INTERVAL_US, 44747503b1SLiam Girdwood HDA_DSP_RESET_TIMEOUT_US); 45747503b1SLiam Girdwood 46747503b1SLiam Girdwood /* has core entered reset ? */ 47747503b1SLiam Girdwood adspcs = snd_sof_dsp_read(sdev, HDA_DSP_BAR, 48747503b1SLiam Girdwood HDA_DSP_REG_ADSPCS); 49747503b1SLiam Girdwood if ((adspcs & HDA_DSP_ADSPCS_CRST_MASK(core_mask)) != 50747503b1SLiam Girdwood HDA_DSP_ADSPCS_CRST_MASK(core_mask)) { 51747503b1SLiam Girdwood dev_err(sdev->dev, 52747503b1SLiam Girdwood "error: reset enter failed: core_mask %x adspcs 0x%x\n", 53747503b1SLiam Girdwood core_mask, adspcs); 54747503b1SLiam Girdwood ret = -EIO; 55747503b1SLiam Girdwood } 56747503b1SLiam Girdwood 57747503b1SLiam Girdwood return ret; 58747503b1SLiam Girdwood } 59747503b1SLiam Girdwood 60747503b1SLiam Girdwood int hda_dsp_core_reset_leave(struct snd_sof_dev *sdev, unsigned int core_mask) 61747503b1SLiam Girdwood { 62747503b1SLiam Girdwood unsigned int crst; 63747503b1SLiam Girdwood u32 adspcs; 64747503b1SLiam Girdwood int ret; 65747503b1SLiam Girdwood 66747503b1SLiam Girdwood /* clear reset bits for cores */ 67747503b1SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, HDA_DSP_BAR, 68747503b1SLiam Girdwood HDA_DSP_REG_ADSPCS, 69747503b1SLiam Girdwood HDA_DSP_ADSPCS_CRST_MASK(core_mask), 70747503b1SLiam Girdwood 0); 71747503b1SLiam Girdwood 72747503b1SLiam Girdwood /* poll with timeout to check if operation successful */ 73747503b1SLiam Girdwood crst = HDA_DSP_ADSPCS_CRST_MASK(core_mask); 74747503b1SLiam Girdwood ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR, 75747503b1SLiam Girdwood HDA_DSP_REG_ADSPCS, adspcs, 76747503b1SLiam Girdwood !(adspcs & crst), 77747503b1SLiam Girdwood HDA_DSP_REG_POLL_INTERVAL_US, 78747503b1SLiam Girdwood HDA_DSP_RESET_TIMEOUT_US); 79747503b1SLiam Girdwood 80747503b1SLiam Girdwood /* has core left reset ? */ 81747503b1SLiam Girdwood adspcs = snd_sof_dsp_read(sdev, HDA_DSP_BAR, 82747503b1SLiam Girdwood HDA_DSP_REG_ADSPCS); 83747503b1SLiam Girdwood if ((adspcs & HDA_DSP_ADSPCS_CRST_MASK(core_mask)) != 0) { 84747503b1SLiam Girdwood dev_err(sdev->dev, 85747503b1SLiam Girdwood "error: reset leave failed: core_mask %x adspcs 0x%x\n", 86747503b1SLiam Girdwood core_mask, adspcs); 87747503b1SLiam Girdwood ret = -EIO; 88747503b1SLiam Girdwood } 89747503b1SLiam Girdwood 90747503b1SLiam Girdwood return ret; 91747503b1SLiam Girdwood } 92747503b1SLiam Girdwood 93747503b1SLiam Girdwood int hda_dsp_core_stall_reset(struct snd_sof_dev *sdev, unsigned int core_mask) 94747503b1SLiam Girdwood { 95747503b1SLiam Girdwood /* stall core */ 96747503b1SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, HDA_DSP_BAR, 97747503b1SLiam Girdwood HDA_DSP_REG_ADSPCS, 98747503b1SLiam Girdwood HDA_DSP_ADSPCS_CSTALL_MASK(core_mask), 99747503b1SLiam Girdwood HDA_DSP_ADSPCS_CSTALL_MASK(core_mask)); 100747503b1SLiam Girdwood 101747503b1SLiam Girdwood /* set reset state */ 102747503b1SLiam Girdwood return hda_dsp_core_reset_enter(sdev, core_mask); 103747503b1SLiam Girdwood } 104747503b1SLiam Girdwood 105747503b1SLiam Girdwood int hda_dsp_core_run(struct snd_sof_dev *sdev, unsigned int core_mask) 106747503b1SLiam Girdwood { 107747503b1SLiam Girdwood int ret; 108747503b1SLiam Girdwood 109747503b1SLiam Girdwood /* leave reset state */ 110747503b1SLiam Girdwood ret = hda_dsp_core_reset_leave(sdev, core_mask); 111747503b1SLiam Girdwood if (ret < 0) 112747503b1SLiam Girdwood return ret; 113747503b1SLiam Girdwood 114747503b1SLiam Girdwood /* run core */ 115747503b1SLiam Girdwood dev_dbg(sdev->dev, "unstall/run core: core_mask = %x\n", core_mask); 116747503b1SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, HDA_DSP_BAR, 117747503b1SLiam Girdwood HDA_DSP_REG_ADSPCS, 118747503b1SLiam Girdwood HDA_DSP_ADSPCS_CSTALL_MASK(core_mask), 119747503b1SLiam Girdwood 0); 120747503b1SLiam Girdwood 121747503b1SLiam Girdwood /* is core now running ? */ 122747503b1SLiam Girdwood if (!hda_dsp_core_is_enabled(sdev, core_mask)) { 123747503b1SLiam Girdwood hda_dsp_core_stall_reset(sdev, core_mask); 124747503b1SLiam Girdwood dev_err(sdev->dev, "error: DSP start core failed: core_mask %x\n", 125747503b1SLiam Girdwood core_mask); 126747503b1SLiam Girdwood ret = -EIO; 127747503b1SLiam Girdwood } 128747503b1SLiam Girdwood 129747503b1SLiam Girdwood return ret; 130747503b1SLiam Girdwood } 131747503b1SLiam Girdwood 132747503b1SLiam Girdwood /* 133747503b1SLiam Girdwood * Power Management. 134747503b1SLiam Girdwood */ 135747503b1SLiam Girdwood 136747503b1SLiam Girdwood int hda_dsp_core_power_up(struct snd_sof_dev *sdev, unsigned int core_mask) 137747503b1SLiam Girdwood { 138747503b1SLiam Girdwood unsigned int cpa; 139747503b1SLiam Girdwood u32 adspcs; 140747503b1SLiam Girdwood int ret; 141747503b1SLiam Girdwood 142747503b1SLiam Girdwood /* update bits */ 143747503b1SLiam Girdwood snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPCS, 144747503b1SLiam Girdwood HDA_DSP_ADSPCS_SPA_MASK(core_mask), 145747503b1SLiam Girdwood HDA_DSP_ADSPCS_SPA_MASK(core_mask)); 146747503b1SLiam Girdwood 147747503b1SLiam Girdwood /* poll with timeout to check if operation successful */ 148747503b1SLiam Girdwood cpa = HDA_DSP_ADSPCS_CPA_MASK(core_mask); 149747503b1SLiam Girdwood ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR, 150747503b1SLiam Girdwood HDA_DSP_REG_ADSPCS, adspcs, 151747503b1SLiam Girdwood (adspcs & cpa) == cpa, 152747503b1SLiam Girdwood HDA_DSP_REG_POLL_INTERVAL_US, 153747503b1SLiam Girdwood HDA_DSP_RESET_TIMEOUT_US); 154747503b1SLiam Girdwood if (ret < 0) 155747503b1SLiam Girdwood dev_err(sdev->dev, "error: timeout on core powerup\n"); 156747503b1SLiam Girdwood 157747503b1SLiam Girdwood /* did core power up ? */ 158747503b1SLiam Girdwood adspcs = snd_sof_dsp_read(sdev, HDA_DSP_BAR, 159747503b1SLiam Girdwood HDA_DSP_REG_ADSPCS); 160747503b1SLiam Girdwood if ((adspcs & HDA_DSP_ADSPCS_CPA_MASK(core_mask)) != 161747503b1SLiam Girdwood HDA_DSP_ADSPCS_CPA_MASK(core_mask)) { 162747503b1SLiam Girdwood dev_err(sdev->dev, 163747503b1SLiam Girdwood "error: power up core failed core_mask %xadspcs 0x%x\n", 164747503b1SLiam Girdwood core_mask, adspcs); 165747503b1SLiam Girdwood ret = -EIO; 166747503b1SLiam Girdwood } 167747503b1SLiam Girdwood 168747503b1SLiam Girdwood return ret; 169747503b1SLiam Girdwood } 170747503b1SLiam Girdwood 171747503b1SLiam Girdwood int hda_dsp_core_power_down(struct snd_sof_dev *sdev, unsigned int core_mask) 172747503b1SLiam Girdwood { 173747503b1SLiam Girdwood u32 adspcs; 174747503b1SLiam Girdwood 175747503b1SLiam Girdwood /* update bits */ 176747503b1SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, HDA_DSP_BAR, 177747503b1SLiam Girdwood HDA_DSP_REG_ADSPCS, 178747503b1SLiam Girdwood HDA_DSP_ADSPCS_SPA_MASK(core_mask), 0); 179747503b1SLiam Girdwood 180747503b1SLiam Girdwood return snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR, 181747503b1SLiam Girdwood HDA_DSP_REG_ADSPCS, adspcs, 182747503b1SLiam Girdwood !(adspcs & HDA_DSP_ADSPCS_SPA_MASK(core_mask)), 183747503b1SLiam Girdwood HDA_DSP_REG_POLL_INTERVAL_US, 184747503b1SLiam Girdwood HDA_DSP_PD_TIMEOUT * USEC_PER_MSEC); 185747503b1SLiam Girdwood } 186747503b1SLiam Girdwood 187747503b1SLiam Girdwood bool hda_dsp_core_is_enabled(struct snd_sof_dev *sdev, 188747503b1SLiam Girdwood unsigned int core_mask) 189747503b1SLiam Girdwood { 190747503b1SLiam Girdwood int val; 191747503b1SLiam Girdwood bool is_enable; 192747503b1SLiam Girdwood 193747503b1SLiam Girdwood val = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPCS); 194747503b1SLiam Girdwood 195747503b1SLiam Girdwood is_enable = ((val & HDA_DSP_ADSPCS_CPA_MASK(core_mask)) && 196747503b1SLiam Girdwood (val & HDA_DSP_ADSPCS_SPA_MASK(core_mask)) && 197747503b1SLiam Girdwood !(val & HDA_DSP_ADSPCS_CRST_MASK(core_mask)) && 198747503b1SLiam Girdwood !(val & HDA_DSP_ADSPCS_CSTALL_MASK(core_mask))); 199747503b1SLiam Girdwood 200747503b1SLiam Girdwood dev_dbg(sdev->dev, "DSP core(s) enabled? %d : core_mask %x\n", 201747503b1SLiam Girdwood is_enable, core_mask); 202747503b1SLiam Girdwood 203747503b1SLiam Girdwood return is_enable; 204747503b1SLiam Girdwood } 205747503b1SLiam Girdwood 206747503b1SLiam Girdwood int hda_dsp_enable_core(struct snd_sof_dev *sdev, unsigned int core_mask) 207747503b1SLiam Girdwood { 208747503b1SLiam Girdwood int ret; 209747503b1SLiam Girdwood 210747503b1SLiam Girdwood /* return if core is already enabled */ 211747503b1SLiam Girdwood if (hda_dsp_core_is_enabled(sdev, core_mask)) 212747503b1SLiam Girdwood return 0; 213747503b1SLiam Girdwood 214747503b1SLiam Girdwood /* power up */ 215747503b1SLiam Girdwood ret = hda_dsp_core_power_up(sdev, core_mask); 216747503b1SLiam Girdwood if (ret < 0) { 217747503b1SLiam Girdwood dev_err(sdev->dev, "error: dsp core power up failed: core_mask %x\n", 218747503b1SLiam Girdwood core_mask); 219747503b1SLiam Girdwood return ret; 220747503b1SLiam Girdwood } 221747503b1SLiam Girdwood 222747503b1SLiam Girdwood return hda_dsp_core_run(sdev, core_mask); 223747503b1SLiam Girdwood } 224747503b1SLiam Girdwood 225747503b1SLiam Girdwood int hda_dsp_core_reset_power_down(struct snd_sof_dev *sdev, 226747503b1SLiam Girdwood unsigned int core_mask) 227747503b1SLiam Girdwood { 228747503b1SLiam Girdwood int ret; 229747503b1SLiam Girdwood 230747503b1SLiam Girdwood /* place core in reset prior to power down */ 231747503b1SLiam Girdwood ret = hda_dsp_core_stall_reset(sdev, core_mask); 232747503b1SLiam Girdwood if (ret < 0) { 233747503b1SLiam Girdwood dev_err(sdev->dev, "error: dsp core reset failed: core_mask %x\n", 234747503b1SLiam Girdwood core_mask); 235747503b1SLiam Girdwood return ret; 236747503b1SLiam Girdwood } 237747503b1SLiam Girdwood 238747503b1SLiam Girdwood /* power down core */ 239747503b1SLiam Girdwood ret = hda_dsp_core_power_down(sdev, core_mask); 240747503b1SLiam Girdwood if (ret < 0) { 241747503b1SLiam Girdwood dev_err(sdev->dev, "error: dsp core power down fail mask %x: %d\n", 242747503b1SLiam Girdwood core_mask, ret); 243747503b1SLiam Girdwood return ret; 244747503b1SLiam Girdwood } 245747503b1SLiam Girdwood 246747503b1SLiam Girdwood /* make sure we are in OFF state */ 247747503b1SLiam Girdwood if (hda_dsp_core_is_enabled(sdev, core_mask)) { 248747503b1SLiam Girdwood dev_err(sdev->dev, "error: dsp core disable fail mask %x: %d\n", 249747503b1SLiam Girdwood core_mask, ret); 250747503b1SLiam Girdwood ret = -EIO; 251747503b1SLiam Girdwood } 252747503b1SLiam Girdwood 253747503b1SLiam Girdwood return ret; 254747503b1SLiam Girdwood } 255747503b1SLiam Girdwood 256747503b1SLiam Girdwood void hda_dsp_ipc_int_enable(struct snd_sof_dev *sdev) 257747503b1SLiam Girdwood { 258747503b1SLiam Girdwood struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata; 259747503b1SLiam Girdwood const struct sof_intel_dsp_desc *chip = hda->desc; 260747503b1SLiam Girdwood 261747503b1SLiam Girdwood /* enable IPC DONE and BUSY interrupts */ 262747503b1SLiam Girdwood snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, chip->ipc_ctl, 263747503b1SLiam Girdwood HDA_DSP_REG_HIPCCTL_DONE | HDA_DSP_REG_HIPCCTL_BUSY, 264747503b1SLiam Girdwood HDA_DSP_REG_HIPCCTL_DONE | HDA_DSP_REG_HIPCCTL_BUSY); 265747503b1SLiam Girdwood 266747503b1SLiam Girdwood /* enable IPC interrupt */ 267747503b1SLiam Girdwood snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPIC, 268747503b1SLiam Girdwood HDA_DSP_ADSPIC_IPC, HDA_DSP_ADSPIC_IPC); 269747503b1SLiam Girdwood } 270747503b1SLiam Girdwood 271747503b1SLiam Girdwood void hda_dsp_ipc_int_disable(struct snd_sof_dev *sdev) 272747503b1SLiam Girdwood { 273747503b1SLiam Girdwood struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata; 274747503b1SLiam Girdwood const struct sof_intel_dsp_desc *chip = hda->desc; 275747503b1SLiam Girdwood 276747503b1SLiam Girdwood /* disable IPC interrupt */ 277747503b1SLiam Girdwood snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPIC, 278747503b1SLiam Girdwood HDA_DSP_ADSPIC_IPC, 0); 279747503b1SLiam Girdwood 280747503b1SLiam Girdwood /* disable IPC BUSY and DONE interrupt */ 281747503b1SLiam Girdwood snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, chip->ipc_ctl, 282747503b1SLiam Girdwood HDA_DSP_REG_HIPCCTL_BUSY | HDA_DSP_REG_HIPCCTL_DONE, 0); 283747503b1SLiam Girdwood } 284747503b1SLiam Girdwood 2851c38c922SFred Oh static int hda_suspend(struct snd_sof_dev *sdev, bool runtime_suspend) 286747503b1SLiam Girdwood { 287747503b1SLiam Girdwood struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata; 288747503b1SLiam Girdwood const struct sof_intel_dsp_desc *chip = hda->desc; 289747503b1SLiam Girdwood #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) 290747503b1SLiam Girdwood struct hdac_bus *bus = sof_to_bus(sdev); 291747503b1SLiam Girdwood #endif 292747503b1SLiam Girdwood int ret; 293747503b1SLiam Girdwood 294747503b1SLiam Girdwood /* disable IPC interrupts */ 295747503b1SLiam Girdwood hda_dsp_ipc_int_disable(sdev); 296747503b1SLiam Girdwood 297747503b1SLiam Girdwood #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) 298*fd15f2f5SRander Wang if (runtime_suspend) 299*fd15f2f5SRander Wang hda_codec_jack_wake_enable(sdev); 300*fd15f2f5SRander Wang 301747503b1SLiam Girdwood /* power down all hda link */ 302747503b1SLiam Girdwood snd_hdac_ext_bus_link_power_down_all(bus); 303747503b1SLiam Girdwood #endif 304747503b1SLiam Girdwood 305747503b1SLiam Girdwood /* power down DSP */ 306747503b1SLiam Girdwood ret = hda_dsp_core_reset_power_down(sdev, chip->cores_mask); 307747503b1SLiam Girdwood if (ret < 0) { 308747503b1SLiam Girdwood dev_err(sdev->dev, 309747503b1SLiam Girdwood "error: failed to power down core during suspend\n"); 310747503b1SLiam Girdwood return ret; 311747503b1SLiam Girdwood } 312747503b1SLiam Girdwood 313747503b1SLiam Girdwood /* disable ppcap interrupt */ 314747503b1SLiam Girdwood hda_dsp_ctrl_ppcap_enable(sdev, false); 315747503b1SLiam Girdwood hda_dsp_ctrl_ppcap_int_enable(sdev, false); 316747503b1SLiam Girdwood 3179a50ee58SZhu Yingjiang /* disable hda bus irq and streams */ 3189a50ee58SZhu Yingjiang hda_dsp_ctrl_stop_chip(sdev); 319747503b1SLiam Girdwood 320747503b1SLiam Girdwood /* disable LP retention mode */ 321747503b1SLiam Girdwood snd_sof_pci_update_bits(sdev, PCI_PGCTL, 322747503b1SLiam Girdwood PCI_PGCTL_LSRMD_MASK, PCI_PGCTL_LSRMD_MASK); 323747503b1SLiam Girdwood 324747503b1SLiam Girdwood /* reset controller */ 325747503b1SLiam Girdwood ret = hda_dsp_ctrl_link_reset(sdev, true); 326747503b1SLiam Girdwood if (ret < 0) { 327747503b1SLiam Girdwood dev_err(sdev->dev, 328747503b1SLiam Girdwood "error: failed to reset controller during suspend\n"); 329747503b1SLiam Girdwood return ret; 330747503b1SLiam Girdwood } 331747503b1SLiam Girdwood 332747503b1SLiam Girdwood return 0; 333747503b1SLiam Girdwood } 334747503b1SLiam Girdwood 335*fd15f2f5SRander Wang static int hda_resume(struct snd_sof_dev *sdev, bool runtime_resume) 336747503b1SLiam Girdwood { 337747503b1SLiam Girdwood #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) 338747503b1SLiam Girdwood struct hdac_bus *bus = sof_to_bus(sdev); 339747503b1SLiam Girdwood struct hdac_ext_link *hlink = NULL; 340747503b1SLiam Girdwood #endif 341747503b1SLiam Girdwood int ret; 342747503b1SLiam Girdwood 343747503b1SLiam Girdwood /* 344747503b1SLiam Girdwood * clear TCSEL to clear playback on some HD Audio 345747503b1SLiam Girdwood * codecs. PCI TCSEL is defined in the Intel manuals. 346747503b1SLiam Girdwood */ 347747503b1SLiam Girdwood snd_sof_pci_update_bits(sdev, PCI_TCSEL, 0x07, 0); 348747503b1SLiam Girdwood 349747503b1SLiam Girdwood /* reset and start hda controller */ 350747503b1SLiam Girdwood ret = hda_dsp_ctrl_init_chip(sdev, true); 351747503b1SLiam Girdwood if (ret < 0) { 352747503b1SLiam Girdwood dev_err(sdev->dev, 353747503b1SLiam Girdwood "error: failed to start controller after resume\n"); 354747503b1SLiam Girdwood return ret; 355747503b1SLiam Girdwood } 356747503b1SLiam Girdwood 357*fd15f2f5SRander Wang #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) 358*fd15f2f5SRander Wang /* check jack status */ 359*fd15f2f5SRander Wang if (runtime_resume) 360*fd15f2f5SRander Wang hda_codec_jack_check(sdev); 3616aa232e1SRander Wang 3626aa232e1SRander Wang /* turn off the links that were off before suspend */ 3636aa232e1SRander Wang list_for_each_entry(hlink, &bus->hlink_list, list) { 3646aa232e1SRander Wang if (!hlink->ref_count) 3656aa232e1SRander Wang snd_hdac_ext_bus_link_power_down(hlink); 3666aa232e1SRander Wang } 3676aa232e1SRander Wang 3686aa232e1SRander Wang /* check dma status and clean up CORB/RIRB buffers */ 3696aa232e1SRander Wang if (!bus->cmd_dma_state) 3706aa232e1SRander Wang snd_hdac_bus_stop_cmd_io(bus); 371747503b1SLiam Girdwood #else 372747503b1SLiam Girdwood 373747503b1SLiam Girdwood hda_dsp_ctrl_misc_clock_gating(sdev, false); 374747503b1SLiam Girdwood 375747503b1SLiam Girdwood /* reset controller */ 376747503b1SLiam Girdwood ret = hda_dsp_ctrl_link_reset(sdev, true); 377747503b1SLiam Girdwood if (ret < 0) { 378747503b1SLiam Girdwood dev_err(sdev->dev, 379747503b1SLiam Girdwood "error: failed to reset controller during resume\n"); 380747503b1SLiam Girdwood return ret; 381747503b1SLiam Girdwood } 382747503b1SLiam Girdwood 383747503b1SLiam Girdwood /* take controller out of reset */ 384747503b1SLiam Girdwood ret = hda_dsp_ctrl_link_reset(sdev, false); 385747503b1SLiam Girdwood if (ret < 0) { 386747503b1SLiam Girdwood dev_err(sdev->dev, 387747503b1SLiam Girdwood "error: failed to ready controller during resume\n"); 388747503b1SLiam Girdwood return ret; 389747503b1SLiam Girdwood } 390747503b1SLiam Girdwood 391747503b1SLiam Girdwood /* enable hda bus irq */ 392747503b1SLiam Girdwood snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTCTL, 393747503b1SLiam Girdwood SOF_HDA_INT_CTRL_EN | SOF_HDA_INT_GLOBAL_EN, 394747503b1SLiam Girdwood SOF_HDA_INT_CTRL_EN | SOF_HDA_INT_GLOBAL_EN); 395747503b1SLiam Girdwood 396747503b1SLiam Girdwood hda_dsp_ctrl_misc_clock_gating(sdev, true); 39724b6ff68SZhu Yingjiang #endif 398747503b1SLiam Girdwood 399747503b1SLiam Girdwood /* enable ppcap interrupt */ 400747503b1SLiam Girdwood hda_dsp_ctrl_ppcap_enable(sdev, true); 401747503b1SLiam Girdwood hda_dsp_ctrl_ppcap_int_enable(sdev, true); 402747503b1SLiam Girdwood 403747503b1SLiam Girdwood return 0; 404747503b1SLiam Girdwood } 405747503b1SLiam Girdwood 406747503b1SLiam Girdwood int hda_dsp_resume(struct snd_sof_dev *sdev) 407747503b1SLiam Girdwood { 408747503b1SLiam Girdwood /* init hda controller. DSP cores will be powered up during fw boot */ 409*fd15f2f5SRander Wang return hda_resume(sdev, false); 410747503b1SLiam Girdwood } 411747503b1SLiam Girdwood 412747503b1SLiam Girdwood int hda_dsp_runtime_resume(struct snd_sof_dev *sdev) 413747503b1SLiam Girdwood { 414747503b1SLiam Girdwood /* init hda controller. DSP cores will be powered up during fw boot */ 415*fd15f2f5SRander Wang return hda_resume(sdev, true); 416747503b1SLiam Girdwood } 417747503b1SLiam Girdwood 41887a6fe80SKai Vehmanen int hda_dsp_runtime_idle(struct snd_sof_dev *sdev) 41987a6fe80SKai Vehmanen { 42087a6fe80SKai Vehmanen struct hdac_bus *hbus = sof_to_bus(sdev); 42187a6fe80SKai Vehmanen 42287a6fe80SKai Vehmanen if (hbus->codec_powered) { 42387a6fe80SKai Vehmanen dev_dbg(sdev->dev, "some codecs still powered (%08X), not idle\n", 42487a6fe80SKai Vehmanen (unsigned int)hbus->codec_powered); 42587a6fe80SKai Vehmanen return -EBUSY; 42687a6fe80SKai Vehmanen } 42787a6fe80SKai Vehmanen 42887a6fe80SKai Vehmanen return 0; 42987a6fe80SKai Vehmanen } 43087a6fe80SKai Vehmanen 4311c38c922SFred Oh int hda_dsp_runtime_suspend(struct snd_sof_dev *sdev) 432747503b1SLiam Girdwood { 433747503b1SLiam Girdwood /* stop hda controller and power dsp off */ 4341c38c922SFred Oh return hda_suspend(sdev, true); 435747503b1SLiam Girdwood } 436747503b1SLiam Girdwood 4371c38c922SFred Oh int hda_dsp_suspend(struct snd_sof_dev *sdev) 438747503b1SLiam Girdwood { 439747503b1SLiam Girdwood struct hdac_bus *bus = sof_to_bus(sdev); 440747503b1SLiam Girdwood int ret; 441747503b1SLiam Girdwood 442747503b1SLiam Girdwood /* stop hda controller and power dsp off */ 4431c38c922SFred Oh ret = hda_suspend(sdev, false); 444747503b1SLiam Girdwood if (ret < 0) { 445747503b1SLiam Girdwood dev_err(bus->dev, "error: suspending dsp\n"); 446747503b1SLiam Girdwood return ret; 447747503b1SLiam Girdwood } 448747503b1SLiam Girdwood 449747503b1SLiam Girdwood return 0; 450747503b1SLiam Girdwood } 451ed3baacdSRanjani Sridharan 4527077a07aSRanjani Sridharan int hda_dsp_set_hw_params_upon_resume(struct snd_sof_dev *sdev) 453ed3baacdSRanjani Sridharan { 454ed3baacdSRanjani Sridharan struct hdac_bus *bus = sof_to_bus(sdev); 455ed3baacdSRanjani Sridharan struct sof_intel_hda_stream *hda_stream; 456ed3baacdSRanjani Sridharan struct hdac_ext_stream *stream; 457ed3baacdSRanjani Sridharan struct hdac_stream *s; 458ed3baacdSRanjani Sridharan 4597077a07aSRanjani Sridharan #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) 4607077a07aSRanjani Sridharan struct snd_soc_pcm_runtime *rtd; 4617077a07aSRanjani Sridharan struct hdac_ext_link *link; 4627077a07aSRanjani Sridharan const char *name; 4637077a07aSRanjani Sridharan int stream_tag; 4647077a07aSRanjani Sridharan #endif 4657077a07aSRanjani Sridharan 466ed3baacdSRanjani Sridharan /* set internal flag for BE */ 467ed3baacdSRanjani Sridharan list_for_each_entry(s, &bus->stream_list, list) { 468ed3baacdSRanjani Sridharan stream = stream_to_hdac_ext_stream(s); 469ed3baacdSRanjani Sridharan hda_stream = container_of(stream, struct sof_intel_hda_stream, 470ed3baacdSRanjani Sridharan hda_stream); 471ed3baacdSRanjani Sridharan hda_stream->hw_params_upon_resume = 1; 4727077a07aSRanjani Sridharan #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) 4737077a07aSRanjani Sridharan /* 4747077a07aSRanjani Sridharan * clear and release stream. This should already be taken care 4757077a07aSRanjani Sridharan * for running streams when the SUSPEND trigger is called. 4767077a07aSRanjani Sridharan * But paused streams do not get suspended, so this needs to be 4777077a07aSRanjani Sridharan * done explicitly during suspend. 4787077a07aSRanjani Sridharan */ 4797077a07aSRanjani Sridharan if (stream->link_substream) { 4807077a07aSRanjani Sridharan rtd = snd_pcm_substream_chip(stream->link_substream); 4817077a07aSRanjani Sridharan name = rtd->codec_dai->component->name; 4827077a07aSRanjani Sridharan link = snd_hdac_ext_bus_get_link(bus, name); 4837077a07aSRanjani Sridharan if (!link) 4847077a07aSRanjani Sridharan return -EINVAL; 4857077a07aSRanjani Sridharan stream_tag = hdac_stream(stream)->stream_tag; 4867077a07aSRanjani Sridharan snd_hdac_ext_link_clear_stream_id(link, stream_tag); 4877077a07aSRanjani Sridharan snd_hdac_ext_stream_release(stream, 4887077a07aSRanjani Sridharan HDAC_EXT_STREAM_TYPE_LINK); 489ed3baacdSRanjani Sridharan } 4907077a07aSRanjani Sridharan #endif 4917077a07aSRanjani Sridharan } 4927077a07aSRanjani Sridharan return 0; 493ed3baacdSRanjani Sridharan } 494