All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: alsa-devel@alsa-project.org
Cc: Dragos Tarcatu <dragos_tarcatu@mentor.com>,
	Daniel Baluta <daniel.baluta@gmail.com>,
	Alan Cox <alan@linux.intel.com>,
	tiwai@suse.de, Keyon Jie <yang.jie@linux.intel.com>,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
	liam.r.girdwood@linux.intel.com, vkoul@kernel.org,
	broonie@kernel.org, andriy.shevchenko@linux.intel.com,
	sound-open-firmware@alsa-project.org
Subject: [PATCH v5 05/21] ASoC: SOF: Intel: Add HDA controller for Intel DSP
Date: Fri, 12 Apr 2019 11:08:48 -0500	[thread overview]
Message-ID: <20190412160904.30418-6-pierre-louis.bossart@linux.intel.com> (raw)
In-Reply-To: <20190412160904.30418-1-pierre-louis.bossart@linux.intel.com>

From: Liam Girdwood <liam.r.girdwood@linux.intel.com>

Support HDA controller operations for DSP and provide space for future
DSP HDA FW integration.

Signed-off-by: Keyon Jie <yang.jie@linux.intel.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
---
 sound/soc/sof/intel/hda-ctrl.c | 181 +++++++++++++++++++++++++++++++++
 1 file changed, 181 insertions(+)
 create mode 100644 sound/soc/sof/intel/hda-ctrl.c

diff --git a/sound/soc/sof/intel/hda-ctrl.c b/sound/soc/sof/intel/hda-ctrl.c
new file mode 100644
index 000000000000..2c3645736e1f
--- /dev/null
+++ b/sound/soc/sof/intel/hda-ctrl.c
@@ -0,0 +1,181 @@
+// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
+//
+// This file is provided under a dual BSD/GPLv2 license.  When using or
+// redistributing this file, you may do so under either license.
+//
+// Copyright(c) 2018 Intel Corporation. All rights reserved.
+//
+// Authors: Liam Girdwood <liam.r.girdwood@linux.intel.com>
+//	    Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
+//	    Rander Wang <rander.wang@intel.com>
+//          Keyon Jie <yang.jie@linux.intel.com>
+//
+
+/*
+ * Hardware interface for generic Intel audio DSP HDA IP
+ */
+
+#include <sound/hdaudio_ext.h>
+#include <sound/hda_register.h>
+#include "../ops.h"
+#include "hda.h"
+
+/*
+ * HDA Operations.
+ */
+
+int hda_dsp_ctrl_link_reset(struct snd_sof_dev *sdev, bool reset)
+{
+	unsigned long timeout;
+	u32 gctl = 0;
+	u32 val;
+
+	/* 0 to enter reset and 1 to exit reset */
+	val = reset ? 0 : SOF_HDA_GCTL_RESET;
+
+	/* enter/exit HDA controller reset */
+	snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, SOF_HDA_GCTL,
+				SOF_HDA_GCTL_RESET, val);
+
+	/* wait to enter/exit reset */
+	timeout = jiffies + msecs_to_jiffies(HDA_DSP_CTRL_RESET_TIMEOUT);
+	while (time_before(jiffies, timeout)) {
+		gctl = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_GCTL);
+		if ((gctl & SOF_HDA_GCTL_RESET) == val)
+			return 0;
+		usleep_range(500, 1000);
+	}
+
+	/* enter/exit reset failed */
+	dev_err(sdev->dev, "error: failed to %s HDA controller gctl 0x%x\n",
+		reset ? "reset" : "ready", gctl);
+	return -EIO;
+}
+
+int hda_dsp_ctrl_get_caps(struct snd_sof_dev *sdev)
+{
+	struct hdac_bus *bus = sof_to_bus(sdev);
+	u32 cap, offset, feature;
+	int count = 0;
+
+	offset = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_LLCH);
+
+	do {
+		cap = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, offset);
+
+		dev_dbg(sdev->dev, "checking for capabilities at offset 0x%x\n",
+			offset & SOF_HDA_CAP_NEXT_MASK);
+
+		feature = (cap & SOF_HDA_CAP_ID_MASK) >> SOF_HDA_CAP_ID_OFF;
+
+		switch (feature) {
+		case SOF_HDA_PP_CAP_ID:
+			dev_dbg(sdev->dev, "found DSP capability at 0x%x\n",
+				offset);
+			bus->ppcap = bus->remap_addr + offset;
+			sdev->bar[HDA_DSP_PP_BAR] = bus->ppcap;
+			break;
+		case SOF_HDA_SPIB_CAP_ID:
+			dev_dbg(sdev->dev, "found SPIB capability at 0x%x\n",
+				offset);
+			bus->spbcap = bus->remap_addr + offset;
+			sdev->bar[HDA_DSP_SPIB_BAR] = bus->spbcap;
+			break;
+		case SOF_HDA_DRSM_CAP_ID:
+			dev_dbg(sdev->dev, "found DRSM capability at 0x%x\n",
+				offset);
+			bus->drsmcap = bus->remap_addr + offset;
+			sdev->bar[HDA_DSP_DRSM_BAR] = bus->drsmcap;
+			break;
+		case SOF_HDA_GTS_CAP_ID:
+			dev_dbg(sdev->dev, "found GTS capability at 0x%x\n",
+				offset);
+			bus->gtscap = bus->remap_addr + offset;
+			break;
+		case SOF_HDA_ML_CAP_ID:
+			dev_dbg(sdev->dev, "found ML capability at 0x%x\n",
+				offset);
+			bus->mlcap = bus->remap_addr + offset;
+			break;
+		default:
+			dev_vdbg(sdev->dev, "found capability %d at 0x%x\n",
+				 feature, offset);
+			break;
+		}
+
+		offset = cap & SOF_HDA_CAP_NEXT_MASK;
+	} while (count++ <= SOF_HDA_MAX_CAPS && offset);
+
+	return 0;
+}
+
+void hda_dsp_ctrl_ppcap_enable(struct snd_sof_dev *sdev, bool enable)
+{
+	u32 val = enable ? SOF_HDA_PPCTL_GPROCEN : 0;
+
+	snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL,
+				SOF_HDA_PPCTL_GPROCEN, val);
+}
+
+void hda_dsp_ctrl_ppcap_int_enable(struct snd_sof_dev *sdev, bool enable)
+{
+	u32 val	= enable ? SOF_HDA_PPCTL_PIE : 0;
+
+	snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL,
+				SOF_HDA_PPCTL_PIE, val);
+}
+
+void hda_dsp_ctrl_misc_clock_gating(struct snd_sof_dev *sdev, bool enable)
+{
+	u32 val = enable ? PCI_CGCTL_MISCBDCGE_MASK : 0;
+
+	snd_sof_pci_update_bits(sdev, PCI_CGCTL, PCI_CGCTL_MISCBDCGE_MASK, val);
+}
+
+/*
+ * enable/disable audio dsp clock gating and power gating bits.
+ * This allows the HW to opportunistically power and clock gate
+ * the audio dsp when it is idle
+ */
+int hda_dsp_ctrl_clock_power_gating(struct snd_sof_dev *sdev, bool enable)
+{
+#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
+	struct hdac_bus *bus = sof_to_bus(sdev);
+#endif
+	u32 val;
+
+	/* enable/disable audio dsp clock gating */
+	val = enable ? PCI_CGCTL_ADSPDCGE : 0;
+	snd_sof_pci_update_bits(sdev, PCI_CGCTL, PCI_CGCTL_ADSPDCGE, val);
+
+#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
+	/* enable/disable L1 support */
+	val = enable ? SOF_HDA_VS_EM2_L1SEN : 0;
+	snd_hdac_chip_updatel(bus, VS_EM2, SOF_HDA_VS_EM2_L1SEN, val);
+#endif
+
+	/* enable/disable audio dsp power gating */
+	val = enable ? 0 : PCI_PGCTL_ADSPPGD;
+	snd_sof_pci_update_bits(sdev, PCI_PGCTL, PCI_PGCTL_ADSPPGD, val);
+
+	return 0;
+}
+
+#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
+/*
+ * While performing reset, controller may not come back properly and causing
+ * issues, so recommendation is to set CGCTL.MISCBDCGE to 0 then do reset
+ * (init chip) and then again set CGCTL.MISCBDCGE to 1
+ */
+int hda_dsp_ctrl_init_chip(struct snd_sof_dev *sdev, bool full_reset)
+{
+	struct hdac_bus *bus = sof_to_bus(sdev);
+	int ret;
+
+	hda_dsp_ctrl_misc_clock_gating(sdev, false);
+	ret = snd_hdac_bus_init_chip(bus, full_reset);
+	hda_dsp_ctrl_misc_clock_gating(sdev, true);
+
+	return ret;
+}
+#endif
-- 
2.17.1

  parent reply	other threads:[~2019-04-12 16:08 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-12 16:08 [PATCH v5 00/21] ASoC: Sound Open Firmware (SOF) - Intel support Pierre-Louis Bossart
2019-04-12 16:08 ` [PATCH v5 01/21] ASoC: SOF: Intel: Add BYT, CHT and BSW DSP HW support Pierre-Louis Bossart
2019-04-27 17:52   ` Applied "ASoC: SOF: Intel: Add BYT, CHT and BSW DSP HW support." to the asoc tree Mark Brown
2019-04-12 16:08 ` [PATCH v5 02/21] ASoC: SOF: Intel: Add BDW HW DSP support Pierre-Louis Bossart
2019-04-27 17:52   ` Applied "ASoC: SOF: Intel: Add BDW HW DSP support" to the asoc tree Mark Brown
2019-04-12 16:08 ` [PATCH v5 03/21] ASoC: SOF: Intel: Add legacy IPC support Pierre-Louis Bossart
2019-04-27 17:52   ` Applied "ASoC: SOF: Intel: Add legacy IPC support" to the asoc tree Mark Brown
2019-04-12 16:08 ` [PATCH v5 04/21] ASoC: SOF: Intel: Add APL/CNL HW DSP support Pierre-Louis Bossart
2019-04-27 17:52   ` Applied "ASoC: SOF: Intel: Add APL/CNL HW DSP support" to the asoc tree Mark Brown
2019-04-12 16:08 ` Pierre-Louis Bossart [this message]
2019-04-27 17:52   ` Applied "ASoC: SOF: Intel: Add HDA controller for Intel DSP" " Mark Brown
2019-04-12 16:08 ` [PATCH v5 06/21] ASoC: SOF: Intel: Add Intel specific HDA DSP HW operations Pierre-Louis Bossart
2019-04-27 17:52   ` Applied "ASoC: SOF: Intel: Add Intel specific HDA DSP HW operations" to the asoc tree Mark Brown
2019-04-12 16:08 ` [PATCH v5 07/21] ASoC: SOF: Intel: Add Intel specific HDA IPC mechanisms Pierre-Louis Bossart
2019-04-27 17:52   ` Applied "ASoC: SOF: Intel: Add Intel specific HDA IPC mechanisms." to the asoc tree Mark Brown
2019-04-12 16:08 ` [PATCH v5 08/21] ASoC: SOF: Intel: Add Intel specific HDA firmware loader Pierre-Louis Bossart
2019-04-27 17:52   ` Applied "ASoC: SOF: Intel: Add Intel specific HDA firmware loader" to the asoc tree Mark Brown
2019-04-12 16:08 ` [PATCH v5 09/21] ASoC: SOF: Intel: Add Intel specific HDA PCM operations Pierre-Louis Bossart
2019-04-27 17:52   ` Applied "ASoC: SOF: Intel: Add Intel specific HDA PCM operations" to the asoc tree Mark Brown
2019-04-12 16:08 ` [PATCH v5 10/21] ASoC: SOF: Intel: Add hda-bus support and initialization Pierre-Louis Bossart
2019-04-27 17:52   ` Applied "ASoC: SOF: Intel: Add hda-bus support and initialization" to the asoc tree Mark Brown
2019-04-12 16:08 ` [PATCH v5 11/21] ASoC: SOF: Intel: Add Intel specific HDA stream operations Pierre-Louis Bossart
2019-04-27 17:52   ` Applied "ASoC: SOF: Intel: Add Intel specific HDA stream operations" to the asoc tree Mark Brown
2019-04-12 16:08 ` [PATCH v5 12/21] ASoC: SOF: Intel: Add Intel specific HDA trace operations Pierre-Louis Bossart
2019-04-27 17:52   ` Applied "ASoC: SOF: Intel: Add Intel specific HDA trace operations" to the asoc tree Mark Brown
2019-04-12 16:08 ` [PATCH v5 13/21] ASoC: SOF: Intel: Add support for HDAudio codecs Pierre-Louis Bossart
2019-04-27 17:52   ` Applied "ASoC: SOF: Intel: Add support for HDAudio codecs" to the asoc tree Mark Brown
2019-04-12 16:08 ` [PATCH v5 14/21] ASoC: SOF: Intel: add SKL+ platform DAIs Pierre-Louis Bossart
2019-04-27 17:52   ` Applied "ASoC: SOF: Intel: add SKL+ platform DAIs" to the asoc tree Mark Brown
2019-04-12 16:08 ` [PATCH v5 15/21] ASoC: SOF: Intel: Add platform differentiation for APL and CNL Pierre-Louis Bossart
2019-04-27 17:52   ` Applied "ASoC: SOF: Intel: Add platform differentiation for APL and CNL" to the asoc tree Mark Brown
2019-04-12 16:08 ` [PATCH v5 16/21] ASoC: SOF: Add ACPI device support Pierre-Louis Bossart
2019-04-27 17:52   ` Applied "ASoC: SOF: Add ACPI device support" to the asoc tree Mark Brown
2019-04-12 16:09 ` [PATCH v5 17/21] ASoC: SOF: Add PCI device support Pierre-Louis Bossart
2019-04-27 17:52   ` Applied "ASoC: SOF: Add PCI device support" to the asoc tree Mark Brown
2019-04-12 16:09 ` [PATCH v5 18/21] ASoC: Intel: Kconfig: expose common option between SST and SOF drivers Pierre-Louis Bossart
2019-04-27 17:52   ` Applied "ASoC: Intel: Kconfig: expose common option between SST and SOF drivers" to the asoc tree Mark Brown
2019-04-12 16:09 ` [PATCH v5 19/21] ASoC: SOF: Add Build support for SOF core and Intel drivers Pierre-Louis Bossart
2019-04-27 17:52   ` Applied "ASoC: SOF: Add Build support for SOF core and Intel drivers" to the asoc tree Mark Brown
2019-04-12 16:09 ` [PATCH v5 20/21] ASoC: Intel: Make sure BDW based machine drivers build for SOF Pierre-Louis Bossart
2019-04-27 17:52   ` Applied "ASoC: Intel: Make sure BDW based machine drivers build for SOF" to the asoc tree Mark Brown
2019-04-12 16:09 ` [PATCH v5 21/21] ASoC: Intel: select relevant machine drivers for SOF Pierre-Louis Bossart
2019-04-27 17:52   ` Applied "ASoC: Intel: select relevant machine drivers for SOF" to the asoc tree Mark Brown
2019-04-23 15:42 ` [PATCH v5 00/21] ASoC: Sound Open Firmware (SOF) - Intel support Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190412160904.30418-6-pierre-louis.bossart@linux.intel.com \
    --to=pierre-louis.bossart@linux.intel.com \
    --cc=alan@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=broonie@kernel.org \
    --cc=daniel.baluta@gmail.com \
    --cc=dragos_tarcatu@mentor.com \
    --cc=liam.r.girdwood@linux.intel.com \
    --cc=sound-open-firmware@alsa-project.org \
    --cc=tiwai@suse.de \
    --cc=vkoul@kernel.org \
    --cc=yang.jie@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.