Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp4422921ybf; Wed, 4 Mar 2020 03:42:21 -0800 (PST) X-Google-Smtp-Source: ADFU+vvd8qpCxEu+lJC/EYvPGOA805+xZ949hPwf447m5Cd8SnIda1erzJH0JBA8FMgR2rVWXf6u X-Received: by 2002:a05:6830:11d4:: with SMTP id v20mr1878306otq.372.1583322141212; Wed, 04 Mar 2020 03:42:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583322141; cv=none; d=google.com; s=arc-20160816; b=Sxlx/OyhgrdcXZIIzIBYg39dK/4Y/JwRkqmAELjSpsUzHMu6pOavZmlgbgOaiO4XcB 6tSZh5QDT5d6u+G8/TEPXKvg9L8xnpRdgR433NOqT57VjUeXLoE2/e7FUhbwrC8ZTUTM oA7os1qtZYTmb+jBC3ffTgqBqWfVGNySJc3uPuCIyle2HQTCBK5hJ5cXlSyjKtTd0TIr blWzqnEOuN11LsSynGDwgZBXF5VLkL9imxNkF4UnWjIW/AtcBpL0Y0Lzdd/I6T5OxyuT DW0qalqRMoGXQI6gVMHAANKgo+s8BMZR3VfyITGQgpITYEDAYIzaC6cCaE8CYZcBjOfq fdfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id; bh=w4lVeO4rQOD6J6wZOaVl254xjOT5uoBFiFQBPQdNZ2k=; b=vZYaHSgraTElqj5LGwKBW9pDJkCVpyM0Wzl7LkyeHKPADj17Kkizk8rRVhg0BtOtZ6 FoG8ZQVeQtdbntPH4UYBxrgGA1iWheZ+NgsqamAMbjEdZ9fPMEPVIUvQikXbeLEIiLlj iW6rCq/ZEgV0Qkq6SVQU4Oyna8HCt+01bljfT67f3S2WMzzobaFV5sXp4v4Ye5T3uC/w T76FiJt8dRPpoSGw5LXIThe91ATh2/uZpWNsOgzqJvAc5bxCYoFTSOvQWU0hfVZI+W9y K/iFW0qdCrPj395Kyl/QjzPfmoUbYdY6yVEInzhulMPHOJ7zu5BjuR72Luo/me7G8ROC 6Vfg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e26si960793otk.251.2020.03.04.03.42.09; Wed, 04 Mar 2020 03:42:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729397AbgCDLlo convert rfc822-to-8bit (ORCPT + 99 others); Wed, 4 Mar 2020 06:41:44 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:40913 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729377AbgCDLlo (ORCPT ); Wed, 4 Mar 2020 06:41:44 -0500 Received: from lupine.hi.pengutronix.de ([2001:67c:670:100:3ad5:47ff:feaf:1a17] helo=lupine) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j9SP7-0001eR-T3; Wed, 04 Mar 2020 12:41:33 +0100 Received: from pza by lupine with local (Exim 4.92) (envelope-from ) id 1j9SP7-0005kZ-6Z; Wed, 04 Mar 2020 12:41:33 +0100 Message-ID: Subject: Re: [RFC 10/11] reset: imx: Add audiomix reset controller support From: Philipp Zabel To: Abel Vesa , Rob Herring , Shawn Guo , Sascha Hauer , Fabio Estevam , Mike Turquette , Stephen Boyd , Lee Jones , Anson Huang , Leonard Crestez , Peng Fan , Jacky Bai Cc: devicetree@vger.kernel.org, Linux Kernel Mailing List , NXP Linux Team , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org Date: Wed, 04 Mar 2020 12:41:33 +0100 In-Reply-To: <1583226206-19758-11-git-send-email-abel.vesa@nxp.com> References: <1583226206-19758-1-git-send-email-abel.vesa@nxp.com> <1583226206-19758-11-git-send-email-abel.vesa@nxp.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.30.5-1.1 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:3ad5:47ff:feaf:1a17 X-SA-Exim-Mail-From: p.zabel@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Abel, On Tue, 2020-03-03 at 11:03 +0200, Abel Vesa wrote: > The imx-mix MFD driver registers some devices, one of which, in case of > audiomix, maps correctly to a reset controller type. This driver registers > a reset controller for that. For now, only the EARC specific resets are added. > > Signed-off-by: Abel Vesa > Reviewed-by: Leonard Crestez > --- > drivers/reset/Kconfig | 7 ++ > drivers/reset/Makefile | 1 + > drivers/reset/reset-imx-audiomix.c | 122 +++++++++++++++++++++++++ > include/dt-bindings/reset/imx-audiomix-reset.h | 15 +++ > 4 files changed, 145 insertions(+) > create mode 100644 drivers/reset/reset-imx-audiomix.c > create mode 100644 include/dt-bindings/reset/imx-audiomix-reset.h > > diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig > index d9efbfd..2f8d9b3 100644 > --- a/drivers/reset/Kconfig > +++ b/drivers/reset/Kconfig > @@ -81,6 +81,13 @@ config RESET_INTEL_GW > Say Y to control the reset signals provided by reset controller. > Otherwise, say N. > > +config RESET_IMX_AUDIOMIX > + bool "i.MX Audiomix Reset Driver" if COMPILE_TEST > + depends on HAS_IOMEM > + default ARCH_MXC > + help > + This enables the audiomix reset controller driver for i.MX SoCs. > + > config RESET_LANTIQ > bool "Lantiq XWAY Reset Driver" if COMPILE_TEST > default SOC_TYPE_XWAY > diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile > index 249ed35..cf23d38 100644 > --- a/drivers/reset/Makefile > +++ b/drivers/reset/Makefile > @@ -12,6 +12,7 @@ obj-$(CONFIG_RESET_BRCMSTB_RESCAL) += reset-brcmstb-rescal.o > obj-$(CONFIG_RESET_HSDK) += reset-hsdk.o > obj-$(CONFIG_RESET_IMX7) += reset-imx7.o > obj-$(CONFIG_RESET_INTEL_GW) += reset-intel-gw.o > +obj-$(CONFIG_RESET_IMX_AUDIOMIX) += reset-imx-audiomix.o > obj-$(CONFIG_RESET_LANTIQ) += reset-lantiq.o > obj-$(CONFIG_RESET_LPC18XX) += reset-lpc18xx.o > obj-$(CONFIG_RESET_MESON) += reset-meson.o > diff --git a/drivers/reset/reset-imx-audiomix.c b/drivers/reset/reset-imx-audiomix.c > new file mode 100644 > index 00000000..d1c62ef > --- /dev/null > +++ b/drivers/reset/reset-imx-audiomix.c > @@ -0,0 +1,122 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright 2019 NXP. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define IMX_AUDIOMIX_EARC_CTRL_REG 0x200 > + > +#define IMX_AUDIOMIX_EARC_RESET_BIT 0x0 > +#define IMX_AUDIOMIX_EARC_PHY_RESET_BIT 0x1 > + > +struct imx_audiomix_reset_data { > + void __iomem *base; > + struct reset_controller_dev rcdev; > + spinlock_t lock; > +}; > + > +static int imx_audiomix_reset_set(struct reset_controller_dev *rcdev, > + unsigned long id, bool assert) > +{ > + struct imx_audiomix_reset_data *drvdata = container_of(rcdev, > + struct imx_audiomix_reset_data, rcdev); > + void __iomem *reg_addr = drvdata->base; > + unsigned long flags; > + unsigned int offset; > + u32 reg; > + > + switch (id) { > + case IMX_AUDIOMIX_EARC_PHY_RESET: > + reg_addr += IMX_AUDIOMIX_EARC_CTRL_REG; > + offset = IMX_AUDIOMIX_EARC_PHY_RESET_BIT; > + break; > + case IMX_AUDIOMIX_EARC_RESET: > + reg_addr += IMX_AUDIOMIX_EARC_CTRL_REG; > + offset = IMX_AUDIOMIX_EARC_RESET_BIT; > + break; > + default: > + return -EINVAL; > + } > + > + if (assert) { > + pm_runtime_get_sync(rcdev->dev); This seems wrong. Why is the runtime PM reference count incremented when a reset is asserted ... > + spin_lock_irqsave(&drvdata->lock, flags); > + reg = readl(reg_addr); > + writel(reg & ~BIT(offset), reg_addr); > + spin_unlock_irqrestore(&drvdata->lock, flags); > + } else { > + spin_lock_irqsave(&drvdata->lock, flags); > + reg = readl(reg_addr); > + writel(reg | BIT(offset), reg_addr); > + spin_unlock_irqrestore(&drvdata->lock, flags); > + pm_runtime_put(rcdev->dev); ... and decremented when a reset is deasserted? Apart from the runtime PM handling this looks like it could reuse reset- simple. > + } > + > + return 0; > +} > + > +static int imx_audiomix_reset_assert(struct reset_controller_dev *rcdev, > + unsigned long id) > +{ > + return imx_audiomix_reset_set(rcdev, id, true); > +} > + > +static int imx_audiomix_reset_deassert(struct reset_controller_dev *rcdev, > + unsigned long id) > +{ > + return imx_audiomix_reset_set(rcdev, id, false); > +} > + > +static const struct reset_control_ops imx_audiomix_reset_ops = { > + .assert = imx_audiomix_reset_assert, > + .deassert = imx_audiomix_reset_deassert, > +}; > + > +static int imx_audiomix_reset_probe(struct platform_device *pdev) > +{ > + struct imx_audiomix_reset_data *drvdata; > + struct device *dev = &pdev->dev; > + > + drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL); > + if (drvdata == NULL) > + return -ENOMEM; > + > + drvdata->base = dev_get_drvdata(dev->parent); > + > + platform_set_drvdata(pdev, drvdata); > + > + pm_runtime_enable(dev); > + > + spin_lock_init(&drvdata->lock); > + > + drvdata->rcdev.owner = THIS_MODULE; > + drvdata->rcdev.nr_resets = IMX_AUDIOMIX_RESET_NUM; > + drvdata->rcdev.ops = &imx_audiomix_reset_ops; > + drvdata->rcdev.of_node = dev->of_node; > + drvdata->rcdev.dev = dev; > + > + return devm_reset_controller_register(dev, &drvdata->rcdev); > +} > + > +static const struct of_device_id imx_audiomix_reset_dt_ids[] = { > + { .compatible = "fsl,imx8mp-audiomix-reset", }, > + { /* sentinel */ }, > +}; > + > +static struct platform_driver imx_audiomix_reset_driver = { > + .probe = imx_audiomix_reset_probe, > + .driver = { > + .name = KBUILD_MODNAME, > + .of_match_table = imx_audiomix_reset_dt_ids, > + }, > +}; > +module_platform_driver(imx_audiomix_reset_driver); > diff --git a/include/dt-bindings/reset/imx-audiomix-reset.h b/include/dt-bindings/reset/imx-audiomix-reset.h > new file mode 100644 > index 00000000..2e26878 > --- /dev/null > +++ b/include/dt-bindings/reset/imx-audiomix-reset.h > @@ -0,0 +1,15 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright 2019 NXP. > + */ > + > +#ifndef DT_BINDING_RESET_IMX_AUDIOMIX_H > +#define DT_BINDING_RESET_IMX_AUDIOMIX_H > + > +#define IMX_AUDIOMIX_EARC_RESET 0x0 > +#define IMX_AUDIOMIX_EARC_PHY_RESET 0x1 > + > +#define IMX_AUDIOMIX_RESET_NUM 2 > + > +#endif > + The imx-audiomix-reset.h change should go into a separate patch, together with the binding docs for fsl,imx8mp-audiomix-reset. regards Philipp