Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp240303imu; Wed, 2 Jan 2019 05:55:35 -0800 (PST) X-Google-Smtp-Source: ALg8bN57wFa16zAjE2Zbt/IjSjEaruJhIMlybdpuRMaZzGGKMqRpcmHpAPCz2zX7plQj2wVa8tDK X-Received: by 2002:a63:4c5:: with SMTP id 188mr13709710pge.391.1546437335072; Wed, 02 Jan 2019 05:55:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546437335; cv=none; d=google.com; s=arc-20160816; b=SdsnUG9QsOZgQR2HHaVhD3E3ZL1lI6ArDmcs/Ew7IUCAOzLrSZrvU/yxAOlzqzIG4g WckIT0QO+ihtZU51+XshOHRP2PsEONsg6HhYbmT9/tcJ/d1qAKHek9BAM/TuKoUmfTwy ES7AXmrHATKiDV3WmG0qj5/Xi6WpiLGifRmGSFxRVKwG+Aj8mKlRMa6Jy2bYqKJB5d/K 2xUDsiPstT3VaxgbnvVb96AFDguoh+SbS6D/yNl8n1Bzc3KgGaOU/lW0v3pJmJ8BNu+P xQ3rBDwMPe289j4xsxyRDzhvoGvjFJbGR8jBnCsxL5RTxC/piXXMBaA4vl6x2KCY5KlG GVdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id; bh=AWkw7AthqswlcRDFaxTUTheTwUjXrmrEmc4D53UdHCI=; b=fVQRy9ST+awwkEW1jybuYhdSAsy/GrA8t0NMyXIn2vp4ILZ86GJJqkcPU2bCkmHWs/ RbRb0kL4FeGTd2NjNaON6+RRN1HudRAjMCe5eMgT2Sh4jUnbh3FsqGj3thRqFkWimKrd MGjjSjTsjNnuS2Z6f3wnO2Loc9le4u5BYUsQCw4qH52xO2W2xiwNkY7yenjnbt3jeWhd d6aHHtm98rc6s1dBVWS/zNDwe0f8hSLQ1oW+E9TwQK33OuTxChpgTMHuYZ3WH135b2n9 h5G+GKi0MjWkut1G4WvkPV0rIcZnkpsqUDXRn7m36sa0Tb5AncWdfunDawp/sWTOp/tS Tq0g== 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 d17si6433562pgl.484.2019.01.02.05.55.03; Wed, 02 Jan 2019 05:55:35 -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 S1729066AbfABKo6 (ORCPT + 99 others); Wed, 2 Jan 2019 05:44:58 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:57637 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728677AbfABKo6 (ORCPT ); Wed, 2 Jan 2019 05:44:58 -0500 Received: from lupine.hi.pengutronix.de ([2001:67c:670:100:3ad5:47ff:feaf:1a17] helo=lupine) by metis.ext.pengutronix.de with esmtp (Exim 4.89) (envelope-from ) id 1gee1A-0001lh-R5; Wed, 02 Jan 2019 11:44:56 +0100 Message-ID: <1546425895.3457.1.camel@pengutronix.de> Subject: Re: [PATCH 2/2] reset: Add Broadcom STB SW_INIT reset controller driver From: Philipp Zabel To: Florian Fainelli , linux-kernel@vger.kernel.org Cc: Rob Herring , Mark Rutland , Brian Norris , Gregory Fong , "maintainer:BROADCOM BCM7XXX ARM ARCHITECTURE" , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , "moderated list:BROADCOM BCM7XXX ARM ARCHITECTURE" Date: Wed, 02 Jan 2019 11:44:55 +0100 In-Reply-To: <20181221013409.14324-3-f.fainelli@gmail.com> References: <20181221013409.14324-1-f.fainelli@gmail.com> <20181221013409.14324-3-f.fainelli@gmail.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6-1+deb9u1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Florian, On Thu, 2018-12-20 at 17:34 -0800, Florian Fainelli wrote: > Add support for resetting blocks through the Linux reset controller > subsystem when reset lines are provided through a SW_INIT-style reset > controller on Broadcom STB SoCs. > > Signed-off-by: Florian Fainelli Thank you, this looks mostly good to me. I just have a few small nitpicks and I'm curious about the mdelays, see below. > --- > drivers/reset/Kconfig | 7 ++ > drivers/reset/Makefile | 1 + > drivers/reset/reset-brcmstb.c | 121 ++++++++++++++++++++++++++++++++++ > 3 files changed, 129 insertions(+) > create mode 100644 drivers/reset/reset-brcmstb.c > > diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig > index 2e01bd833ffd..1ca03c57e049 100644 > --- a/drivers/reset/Kconfig > +++ b/drivers/reset/Kconfig > @@ -40,6 +40,13 @@ config RESET_BERLIN > help > This enables the reset controller driver for Marvell Berlin SoCs. > > +config RESET_BRCMSTB > + bool "Broadcom STB reset controller" if COMPILE_TEST > + default ARCH_BRCMSTB > + help > + This enables the reset controller driver for Broadcom STB SoCs using > + a SUN_TOP_CTRL_SW_INIT style controller. > + > config RESET_HSDK > bool "Synopsys HSDK Reset Driver" > depends on HAS_IOMEM > diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile > index dc7874df78d9..7395db2cb1dd 100644 > --- a/drivers/reset/Makefile > +++ b/drivers/reset/Makefile > @@ -7,6 +7,7 @@ obj-$(CONFIG_RESET_A10SR) += reset-a10sr.o > obj-$(CONFIG_RESET_ATH79) += reset-ath79.o > obj-$(CONFIG_RESET_AXS10X) += reset-axs10x.o > obj-$(CONFIG_RESET_BERLIN) += reset-berlin.o > +obj-$(CONFIG_RESET_BRCMSTB) += reset-brcmstb.o > obj-$(CONFIG_RESET_HSDK) += reset-hsdk.o > obj-$(CONFIG_RESET_IMX7) += reset-imx7.o > obj-$(CONFIG_RESET_LANTIQ) += reset-lantiq.o > diff --git a/drivers/reset/reset-brcmstb.c b/drivers/reset/reset-brcmstb.c > new file mode 100644 > index 000000000000..17a0bcdd6c9a > --- /dev/null > +++ b/drivers/reset/reset-brcmstb.c > @@ -0,0 +1,121 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Broadcom STB generic reset controller for SW_INIT style reset controller > + * > + * Copyright (C) 2018 Broadcom > + * > + */ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +struct brcmstb_reset { > + void __iomem *base; > + unsigned int n_words; > + struct device *dev; These two variables are not used anywhere. > + struct reset_controller_dev rcdev; > +}; > + > +#define SW_INIT_SET 0x00 > +#define SW_INIT_CLEAR 0x04 > +#define SW_INIT_STATUS 0x08 > + > +#define SW_INIT_BIT(id) BIT((id) & 0x1f) > +#define SW_INIT_BANK(id) (id >> 5) Checkpatch suggests to use ((id) >> 5) here. > + > +#define SW_INIT_BANK_SIZE 0x18 > + > +static inline > +struct brcmstb_reset *to_brcmstb(struct reset_controller_dev *rcdev) > +{ > + return container_of(rcdev, struct brcmstb_reset, rcdev); > +} > + > +static int brcmstb_reset_assert(struct reset_controller_dev *rcdev, > + unsigned long id) > +{ > + unsigned int off = SW_INIT_BANK(id) * SW_INIT_BANK_SIZE; > + struct brcmstb_reset *priv = to_brcmstb(rcdev); > + > + writel_relaxed(SW_INIT_BIT(id), priv->base + off + SW_INIT_SET); > + msleep(10); What is the purpose of the msleep(10)? Is it guaranteed that the writel takes effect before the msleep, or could it be lingering in some store buffer for (a part of) the duration? Also, checkpatch warns about this being < 20 ms. You could increase the delay or use usleep_range. > + return 0; > +} > + > +static int brcmstb_reset_deassert(struct reset_controller_dev *rcdev, > + unsigned long id) > +{ > + unsigned int off = SW_INIT_BANK(id) * SW_INIT_BANK_SIZE; > + struct brcmstb_reset *priv = to_brcmstb(rcdev); > + > + writel_relaxed(SW_INIT_BIT(id), priv->base + off + SW_INIT_CLEAR); > + msleep(10); Same as above, what has to be delayed for 10 ms after deasserting the reset? Is this the same for all reset lines handled by this controller? > + > + return 0; > +} > + > +static int brcmstb_reset_status(struct reset_controller_dev *rcdev, > + unsigned long id) > +{ > + unsigned int off = SW_INIT_BANK(id) * SW_INIT_BANK_SIZE; > + struct brcmstb_reset *priv = to_brcmstb(rcdev); > + > + return readl_relaxed(priv->base + off + SW_INIT_STATUS); Should this be + return readl_relaxed(priv->base + off + SW_INIT_STATUS) & + SW_INIT_BANK(id); i.e. do the SW_INIT_STATUS registers contain 32 status bits, one for each reset line? > +} > + > +static const struct reset_control_ops brcmstb_reset_ops = { > + .assert = brcmstb_reset_assert, > + .deassert = brcmstb_reset_deassert, > + .status = brcmstb_reset_status, > +}; > + > +static int brcmstb_reset_probe(struct platform_device *pdev) > +{ > + struct device *kdev = &pdev->dev; > + struct brcmstb_reset *priv; > + struct resource *res; > + > + priv = devm_kzalloc(kdev, sizeof(*priv), GFP_KERNEL); > + if (!priv) > + return -ENOMEM; > + > + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > + priv->base = devm_ioremap_resource(kdev, res); > + if (IS_ERR(priv->base)) > + return PTR_ERR(priv->base); > + > + dev_set_drvdata(kdev, priv); > + > + priv->rcdev.owner = THIS_MODULE; > + priv->rcdev.nr_resets = (resource_size(res) / SW_INIT_BANK_SIZE) * 32; > + priv->rcdev.ops = &brcmstb_reset_ops; > + priv->rcdev.of_node = kdev->of_node; > + /* Use defaults: 1 cell and simple xlate function */ > + priv->dev = kdev; priv->dev could be removed. > + > + return devm_reset_controller_register(kdev, &priv->rcdev); > +} > + > +static const struct of_device_id brcmstb_reset_of_match[] = { > + { .compatible = "brcm,brcmstb-reset" }, > + { /* sentinel */ } > +}; > + > +static struct platform_driver brcmstb_reset_driver = { > + .probe = brcmstb_reset_probe, > + .driver = { > + .name = "brcmstb-reset", > + .of_match_table = brcmstb_reset_of_match, > + }, > +}; > +module_platform_driver(brcmstb_reset_driver); > + > +MODULE_AUTHOR("Broadcom"); > +MODULE_DESCRIPTION("Broadcom STB reset controller"); > +MODULE_LICENSE("GPL"); regards Philipp