Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1778521ybh; Fri, 13 Mar 2020 07:16:44 -0700 (PDT) X-Google-Smtp-Source: ADFU+vv7xOslSseIe5KQsQ+WzCnLoYT/HnQzEUbB0wPEm0zWAjbhoRR5H5f8z5OGu2osjQsMYsKy X-Received: by 2002:a9d:2226:: with SMTP id o35mr8067540ota.261.1584109004806; Fri, 13 Mar 2020 07:16:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584109004; cv=none; d=google.com; s=arc-20160816; b=cj66wFeZxHiXJwthg+u2d75TFCs6uua9jNd5rFAau7hzGN9knFC1ZWhjsWKdDY0Y7A R/2Gm84EI9CTnXswQb7Uuhz40oEKbCl2NSjN8fGQEJz06NyRZh4porwv2VC8YfDD96+N pLep8VBCMMgrUwnnrP/AVYaysCabMUp4OoTzpwHfNt3bnPtdUfbAUwpFrcAj+wxmQIcS ihZB5OBrjjbKgWqaS5gjrLixKTIsxskIJPL7BetMRiYNmTMJHftfnmSQ99egMSY4YLCk NjpKiHUemVKRmkAjmB+YDIKaQBlwTRtig7ZYriCwFxFoqohQ7ejdFTBS8K4mS3fPHbRz pBHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=mCl7S7kyx+hS88zfyrKTKLCsCkxpbcCEZBFKYYigt1Y=; b=BbSbTruDrryDkAWsI92AwAnZcHyeYOkMcmqx8z6f23x3x2GQ2SuHQvrmSuQgtYmBXo lQQ6/SV7jecJfox8aZXSgxzke7671eh08cotGKSncYbE4VBpY08y4P6RSu9Yqf6F6Aoz MKk+WaBQpK+bykGEJ+syQTb3Fo1Tpfz1DDCdvxbWKOj2Y6CeEQDsIB1TkJTBeNW0KPCo wKI2nEdl8EeuUJk6pFhkp+zJu1f68hm2fzg5B5SgO3SGgjwYYhGwUHPm79ruo67aonQC nYKns9wCm7hgJizlaCcMdV6UC/hCYC/lKRXIufUZnOs3d3/Ihs12CMdGLJyvk00ZjCwb PBcw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k3si4692323oib.82.2020.03.13.07.16.29; Fri, 13 Mar 2020 07:16:44 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726779AbgCMOQL (ORCPT + 99 others); Fri, 13 Mar 2020 10:16:11 -0400 Received: from inva020.nxp.com ([92.121.34.13]:38688 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726526AbgCMOQL (ORCPT ); Fri, 13 Mar 2020 10:16:11 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id A0AE61A1497; Fri, 13 Mar 2020 15:16:06 +0100 (CET) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 92DA41A146B; Fri, 13 Mar 2020 15:16:06 +0100 (CET) Received: from localhost (fsr-ub1664-175.ea.freescale.net [10.171.82.40]) by inva024.eu-rdc02.nxp.com (Postfix) with ESMTP id 7BEC1203CE; Fri, 13 Mar 2020 15:16:06 +0100 (CET) Date: Fri, 13 Mar 2020 16:16:06 +0200 From: Abel Vesa To: Philipp Zabel Cc: Rob Herring , Shawn Guo , Sascha Hauer , Fabio Estevam , Mike Turquette , Stephen Boyd , Lee Jones , Anson Huang , Leonard Crestez , Peng Fan , Jacky Bai , devicetree@vger.kernel.org, Linux Kernel Mailing List , NXP Linux Team , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [RFC 10/11] reset: imx: Add audiomix reset controller support Message-ID: <20200313141606.euumtuizm562zghv@fsr-ub1664-175> References: <1583226206-19758-1-git-send-email-abel.vesa@nxp.com> <1583226206-19758-11-git-send-email-abel.vesa@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180622 X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 20-03-04 12:41:33, Philipp Zabel wrote: > 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 ... The audiomix IP has its own power domain. The way I see it, when the last deassert is done, there is no point in keeping the audiomix on. So, unless the clock controller part of it does it, the audiomix will be powered down. > > > + 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