[PATCH v3 2/6] reset: imx8mp-audiomix: Add AudioMix Block Control reset driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Audiomix block control can be a reset controller for
Enhanced Audio Return Channel (EARC), which is one of
modules in this audiomix subsystem.

The EARC PHY software reset and EARC controller software
reset need to be supported.

Signed-off-by: Shengjiu Wang <shengjiu.wang@xxxxxxx>
---
 drivers/reset/Kconfig                 |   8 ++
 drivers/reset/Makefile                |   1 +
 drivers/reset/reset-imx8mp-audiomix.c | 117 ++++++++++++++++++++++++++
 3 files changed, 126 insertions(+)
 create mode 100644 drivers/reset/reset-imx8mp-audiomix.c

diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig
index 7112f5932609..0e7da0bb0a21 100644
--- a/drivers/reset/Kconfig
+++ b/drivers/reset/Kconfig
@@ -91,6 +91,14 @@ config RESET_IMX7
 	help
 	  This enables the reset controller driver for i.MX7 SoCs.
 
+config RESET_IMX8MP_AUDIOMIX
+	tristate "i.MX8MP AudioMix Reset Driver"
+	depends on HAS_IOMEM
+	depends on (ARM64 && ARCH_MXC) || COMPILE_TEST
+	select MFD_SYSCON
+	help
+	  This enables the reset controller driver for i.MX8MP AudioMix.
+
 config RESET_INTEL_GW
 	bool "Intel Reset Controller Driver"
 	depends on X86 || COMPILE_TEST
diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile
index fd8b49fa46fc..a6796e83900b 100644
--- a/drivers/reset/Makefile
+++ b/drivers/reset/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_RESET_BRCMSTB_RESCAL) += reset-brcmstb-rescal.o
 obj-$(CONFIG_RESET_GPIO) += reset-gpio.o
 obj-$(CONFIG_RESET_HSDK) += reset-hsdk.o
 obj-$(CONFIG_RESET_IMX7) += reset-imx7.o
+obj-$(CONFIG_RESET_IMX8MP_AUDIOMIX) += reset-imx8mp-audiomix.o
 obj-$(CONFIG_RESET_INTEL_GW) += reset-intel-gw.o
 obj-$(CONFIG_RESET_K210) += reset-k210.o
 obj-$(CONFIG_RESET_LANTIQ) += reset-lantiq.o
diff --git a/drivers/reset/reset-imx8mp-audiomix.c b/drivers/reset/reset-imx8mp-audiomix.c
new file mode 100644
index 000000000000..8ba0d4406b36
--- /dev/null
+++ b/drivers/reset/reset-imx8mp-audiomix.c
@@ -0,0 +1,117 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2024 NXP
+ */
+
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/regmap.h>
+#include <linux/reset-controller.h>
+
+#define EARC			0x200
+#define EARC_RESET_MASK		0x3
+
+struct imx8mp_audiomix_rst_priv {
+	struct regmap *regmap;
+	struct reset_controller_dev rcdev;
+};
+
+static int imx8mp_audiomix_reset_set(struct reset_controller_dev *rcdev,
+				     unsigned long id, bool assert)
+{
+	struct imx8mp_audiomix_rst_priv *priv = container_of(rcdev,
+				struct imx8mp_audiomix_rst_priv, rcdev);
+	unsigned int mask = BIT(id);
+
+	/* bit = 0 reset, bit = 1 unreset */
+	if (assert)
+		regmap_update_bits(priv->regmap, EARC, mask, 0);
+	else
+		regmap_update_bits(priv->regmap, EARC, mask, mask);
+
+	return 0;
+}
+
+static int imx8mp_audiomix_reset_reset(struct reset_controller_dev *rcdev,
+				       unsigned long id)
+{
+	imx8mp_audiomix_reset_set(rcdev, id, true);
+
+	return imx8mp_audiomix_reset_set(rcdev, id, false);
+}
+
+static int imx8mp_audiomix_reset_assert(struct reset_controller_dev *rcdev,
+					unsigned long id)
+{
+	return imx8mp_audiomix_reset_set(rcdev, id, true);
+}
+
+static int imx8mp_audiomix_reset_deassert(struct reset_controller_dev *rcdev,
+					  unsigned long id)
+{
+	return imx8mp_audiomix_reset_set(rcdev, id, false);
+}
+
+static int imx8mp_audiomix_reset_xlate(struct reset_controller_dev *rcdev,
+				       const struct of_phandle_args *reset_spec)
+{
+	unsigned long id = reset_spec->args[0];
+
+	if (!(BIT(id) & EARC_RESET_MASK))
+		return -EINVAL;
+
+	return id;
+}
+
+static const struct reset_control_ops imx8mp_audiomix_reset_ops = {
+	.reset = imx8mp_audiomix_reset_reset,
+	.assert = imx8mp_audiomix_reset_assert,
+	.deassert = imx8mp_audiomix_reset_deassert,
+};
+
+static int imx8mp_audiomix_reset_probe(struct platform_device *pdev)
+{
+	struct device_node *parent_np = of_get_parent(pdev->dev.of_node);
+	struct imx8mp_audiomix_rst_priv *priv;
+
+	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->regmap = syscon_node_to_regmap(parent_np);
+	of_node_put(parent_np);
+	if (IS_ERR(priv->regmap))
+		return PTR_ERR(priv->regmap);
+
+	priv->rcdev.owner     = THIS_MODULE;
+	priv->rcdev.nr_resets = fls(EARC_RESET_MASK);
+	priv->rcdev.ops       = &imx8mp_audiomix_reset_ops;
+	priv->rcdev.of_node   = pdev->dev.of_node;
+	priv->rcdev.dev	      = &pdev->dev;
+	priv->rcdev.of_reset_n_cells = 1;
+	priv->rcdev.of_xlate  = imx8mp_audiomix_reset_xlate;
+
+	return devm_reset_controller_register(&pdev->dev, &priv->rcdev);
+}
+
+static const struct of_device_id imx8mp_audiomix_reset_dt_match[] = {
+	{ .compatible = "fsl,imx8mp-audiomix-reset" },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, imx8mp_audiomix_reset_dt_match);
+
+static struct platform_driver imx8mp_audiomix_reset_driver = {
+	.probe	= imx8mp_audiomix_reset_probe,
+	.driver	= {
+		.name = "imx8mp-audiomix-reset",
+		.of_match_table = imx8mp_audiomix_reset_dt_match,
+	},
+};
+module_platform_driver(imx8mp_audiomix_reset_driver);
+
+MODULE_AUTHOR("Shengjiu Wang <shengjiu.wang@xxxxxxx>");
+MODULE_DESCRIPTION("Freescale i.MX8MP Audio Block Controller reset driver");
+MODULE_LICENSE("GPL");
-- 
2.34.1





[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux