Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp10595040rwl; Mon, 2 Jan 2023 05:19:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXsWgevOTx0dpPDNWau+CaEFlWTukE9hKetagArYq/xmJyO/xVWI9KU0LFmnZ5XGk9M8btdU X-Received: by 2002:a17:907:c71b:b0:7c1:67ca:56f5 with SMTP id ty27-20020a170907c71b00b007c167ca56f5mr40498665ejc.15.1672665598455; Mon, 02 Jan 2023 05:19:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672665598; cv=none; d=google.com; s=arc-20160816; b=ajXHQio+BIyck+VPHH9Ay8V9Zmt62r5gVYfsvW+HT744swlD8qiZ47gtkkS0o/DZBe P0JSnNFTfsRW7QjxCbq8fuOFkRBTfOrJFxglRbQ8BsGfYbQVIbHCiqdbWgOkyNjtW4KI YleqnhBMa7O7KWNFhW/UKbWJTpqFbeotQjQj4RRY79vPzXPUKCvCgk+NsVlHh8dTAAl2 PzaGleSANN3KEZfxaxMLvPHY/+dSu2c+JVYpIt/zMkU0NBzYJJ3VxS1WyqGAxER+NFL+ kYR4AoOrB8RJ4Fzp43yEJBGD3Ut8B2v7k80V2F9RG51py35B2454PIwRi0eOklAQN9pV wzOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=xMZx54Xj2ddNmH7CYT53GxPmLR4IA/SYVliSYQdrkpw=; b=PqxscmnirQKDk20WplilzdgPuyeZ2XJiFrTmtLosKwD6qr+u4KHFXny9GaJoTDJNwY P8NNbco5mnfESmHvDi0CAZwPv3jX129xH7/tlnPd2DxUXTYEhuZpdbqzXrMTY55Na35o /LBgT6re7Nzv0MhSzd/7LVUgejbN14NAKivNtTxyhhQspSDwqWjAAb8zMa84RdiTuc5+ uk5xHIPIU/NReXRGdopvbaQ9QxmztIap99djL3Vq8oCvit4HwVl3Y+QQOQPIQhIerD0U aPSsk54LjY9McJPHJIul+vE5blPqczRDFn919WdG8jmcYRGYiip+ADs2+PvIHw+q33FR QAWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20210112.gappssmtp.com header.s=20210112 header.b=PvM8eQTC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga28-20020a1709070c1c00b007a92b00c094si25359352ejc.421.2023.01.02.05.19.43; Mon, 02 Jan 2023 05:19:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20210112.gappssmtp.com header.s=20210112 header.b=PvM8eQTC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232976AbjABMup (ORCPT + 61 others); Mon, 2 Jan 2023 07:50:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232988AbjABMul (ORCPT ); Mon, 2 Jan 2023 07:50:41 -0500 Received: from mail-vs1-xe29.google.com (mail-vs1-xe29.google.com [IPv6:2607:f8b0:4864:20::e29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A79A9636E for ; Mon, 2 Jan 2023 04:50:39 -0800 (PST) Received: by mail-vs1-xe29.google.com with SMTP id i188so28849958vsi.8 for ; Mon, 02 Jan 2023 04:50:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=xMZx54Xj2ddNmH7CYT53GxPmLR4IA/SYVliSYQdrkpw=; b=PvM8eQTCd7btpRU4ZlTCF4FwTkgmzS/WWSkogViUT4SQitmOmeDGaqAImpqXDZ/bY8 dLHKKQiFQVLZNAG2Mmg9uEIIPxtGNiy97XDqBa/o3o2u0/HIfb0uqNsE6X/EXjDfj3u8 bk4BrFfCqpq173Y33Qph5m+UGqQy1aNVr3SywMseBY3Z1BdR8BMm3VowUdMBX6eK791A nubZzDTPaYiBJeKbyCkFpnZRqgp+TBnOSKpA0H1xBgtJsYshe4+kLQ/a92E1B5TdlR0C IXpoG1QNu5LzzygGiEdtNtkbw/qsPlJFlsVsk+ohSK5YTkiKAh2v2ZREkI3hAoZrmO+x STnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xMZx54Xj2ddNmH7CYT53GxPmLR4IA/SYVliSYQdrkpw=; b=hNcJhMHTC3l2aKP7bC+x8vFqtARX+MvL4N0I/Nak0P7wj6pOH3/gyldvAUapYam4Ed 60IPQ/pCHRqRTdVqZ9dN1PQXBoFtz8I0/XrpPE+lvFA6h8bNAM2fib6aMxbOboT+bBgY tG+xruuQn1QqTpm0UFi0+G6AiwXqUxa7KoamJpgMgavxMHC2BnmZI9J7QAGKV1bIEIrV bm1746Nawa8LQO9aV4R23F+zRfFRWCJzaTbpfppHW4T6dtgzHkM3PM8EJreiQJyqVNBi GZ35p8V5cZQEje/Zu37Hxty02eNIPtFnH0g7Sf5H6gQ7Ye7sLNTL/O0iXWsRqFzrS4c8 vyAw== X-Gm-Message-State: AFqh2kon/a4gOgdKY6MnOvK3WB1WRyhPd2fspRVpzQR/nwvzAtioAxYA GToqlJyJtpac8K/7pi1vcx2JvzvN83gAmPCQUuTFyg== X-Received: by 2002:a67:df8c:0:b0:3c5:1ac1:bf38 with SMTP id x12-20020a67df8c000000b003c51ac1bf38mr4030319vsk.78.1672663838685; Mon, 02 Jan 2023 04:50:38 -0800 (PST) MIME-Version: 1.0 References: <20221213224310.543243-1-fabrizio.castro.jz@renesas.com> <20221213224310.543243-5-fabrizio.castro.jz@renesas.com> In-Reply-To: <20221213224310.543243-5-fabrizio.castro.jz@renesas.com> From: Bartosz Golaszewski Date: Mon, 2 Jan 2023 13:50:27 +0100 Message-ID: Subject: Re: [PATCH 4/5] gpio: Add support for Renesas RZ/V2M PWC To: Fabrizio Castro Cc: Linus Walleij , Rob Herring , Krzysztof Kozlowski , Sebastian Reichel , Geert Uytterhoeven , Lee Jones , linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Chris Paterson , Biju Das , linux-renesas-soc@vger.kernel.org, Laurent Pinchart , Jacopo Mondi , Phil Edworthy Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 13, 2022 at 11:43 PM Fabrizio Castro wrote: > > The RZ/V2M SoC contains an External Power Sequence Controller (PWC) > module. This module provides an external power supply on/off sequence, > on/off signal for the LPDDR4 core power supply, control signals for > external I/O power supplies of the SD host interfaces, and key input > signals. > PWC is essentially a Multi-Function Device (MFD). > > The driver just implements the control signals for external I/O > power supplies of the SD host interfaces as gpios, and it relies on > syscon and simple-mfd. > > Signed-off-by: Phil Edworthy > Signed-off-by: Fabrizio Castro > --- > drivers/gpio/Kconfig | 8 +++ > drivers/gpio/Makefile | 1 + > drivers/gpio/gpio-rzv2m-pwc.c | 123 ++++++++++++++++++++++++++++++++++ > 3 files changed, 132 insertions(+) > create mode 100644 drivers/gpio/gpio-rzv2m-pwc.c > > diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig > index e6ebc4c90a5d..e016919b9643 100644 > --- a/drivers/gpio/Kconfig > +++ b/drivers/gpio/Kconfig > @@ -553,6 +553,14 @@ config GPIO_ROCKCHIP > help > Say yes here to support GPIO on Rockchip SoCs. > > +config GPIO_RZV2M_PWC > + tristate "Renesas RZ/V2M PWC GPIO support" > + depends on MFD_SYSCON > + depends on ARCH_R9A09G011 || COMPILE_TEST > + help > + Say yes here to support the External Power Sequence Controller (PWC) > + GPIO controller driver for RZ/V2M devices. > + > config GPIO_SAMA5D2_PIOBU > tristate "SAMA5D2 PIOBU GPIO support" > depends on MFD_SYSCON > diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile > index 3462a138764a..5f655684603f 100644 > --- a/drivers/gpio/Makefile > +++ b/drivers/gpio/Makefile > @@ -132,6 +132,7 @@ obj-$(CONFIG_GPIO_RDC321X) += gpio-rdc321x.o > obj-$(CONFIG_GPIO_REALTEK_OTTO) += gpio-realtek-otto.o > obj-$(CONFIG_GPIO_REG) += gpio-reg.o > obj-$(CONFIG_GPIO_ROCKCHIP) += gpio-rockchip.o > +obj-$(CONFIG_GPIO_RZV2M_PWC) += gpio-rzv2m-pwc.o > obj-$(CONFIG_ARCH_SA1100) += gpio-sa1100.o > obj-$(CONFIG_GPIO_SAMA5D2_PIOBU) += gpio-sama5d2-piobu.o > obj-$(CONFIG_GPIO_SCH311X) += gpio-sch311x.o > diff --git a/drivers/gpio/gpio-rzv2m-pwc.c b/drivers/gpio/gpio-rzv2m-pwc.c > new file mode 100644 > index 000000000000..672d868cb8c9 > --- /dev/null > +++ b/drivers/gpio/gpio-rzv2m-pwc.c > @@ -0,0 +1,123 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Copyright (C) 2022 Renesas Electronics Corporation > + * > + * GPIO driver for Renesas RZ/V2M External Power Sequence Controller (PWC) > + */ > + > +#include > +#include > +#include > +#include > +#include > + > +struct rzv2m_pwc_gpio_priv { > + struct gpio_chip gp; > + int offset; > + struct regmap *regmap; > + DECLARE_BITMAP(ch_en_bits, 2); > +}; > + > +static void rzv2m_pwc_gpio_set(struct gpio_chip *chip, unsigned int offset, > + int value) > +{ > + struct rzv2m_pwc_gpio_priv *priv = gpiochip_get_data(chip); > + u32 reg; > + > + /* BIT 16 enables write to BIT 0, and BIT 17 enables write to BIT 1 */ > + reg = BIT(offset + 16); > + if (value) > + reg |= BIT(offset); > + > + regmap_write(priv->regmap, priv->offset, reg); > + > + if (value) > + set_bit(offset, priv->ch_en_bits); > + else > + clear_bit(offset, priv->ch_en_bits); You can use assign_bit() here and pass value to it. > +} > + > +static int rzv2m_pwc_gpio_get(struct gpio_chip *chip, unsigned int offset) > +{ > + struct rzv2m_pwc_gpio_priv *priv = gpiochip_get_data(chip); > + > + return test_bit(offset, priv->ch_en_bits); > +} > + > +static int rzv2m_pwc_gpio_direction_output(struct gpio_chip *gc, > + unsigned int nr, int value) > +{ > + if (nr > 1) > + return -EINVAL; > + > + rzv2m_pwc_gpio_set(gc, nr, value); > + > + return 0; > +} > + > +static const struct gpio_chip rzv2m_pwc_gc = { > + .label = "rzv2m_pwc_gpio", > + .owner = THIS_MODULE, > + .get = rzv2m_pwc_gpio_get, > + .set = rzv2m_pwc_gpio_set, > + .direction_output = rzv2m_pwc_gpio_direction_output, > + .can_sleep = false, > + .ngpio = 2, > + .base = -1, > +}; > + > +static int rzv2m_pwc_gpio_probe(struct platform_device *pdev) > +{ > + struct rzv2m_pwc_gpio_priv *priv; > + int err; > + > + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); > + if (!priv) > + return -ENOMEM; > + > + priv->regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, > + "regmap"); > + > + if (IS_ERR(priv->regmap)) > + return dev_err_probe(&pdev->dev, PTR_ERR(priv->regmap), > + "Can't find regmap property"); > + > + err = of_property_read_u32(pdev->dev.of_node, "offset", &priv->offset); Please don't use OF APIs in drivers anymore, use device_property_read_u32() instead. Otherwise looks pretty good! Bart > + if (err) > + return dev_err_probe(&pdev->dev, -EINVAL, > + "Can't find offset property"); > + > + /* > + * The register used by this driver cannot be read, therefore set the > + * outputs to their default values and initialize priv->ch_en_bits accordingly. > + * BIT 16 enables write to BIT 0, BIT 17 enables write to BIT 1, and the > + * default value of both BIT 0 and BIT 1 is 0. > + */ > + regmap_write(priv->regmap, priv->offset, BIT(17) | BIT(16)); > + bitmap_zero(priv->ch_en_bits, 2); > + > + priv->gp = rzv2m_pwc_gc; > + priv->gp.parent = pdev->dev.parent; > + priv->gp.fwnode = dev_fwnode(&pdev->dev); > + > + return devm_gpiochip_add_data(&pdev->dev, &priv->gp, priv); > +} > + > +static const struct of_device_id rzv2m_pwc_gpio_of_match[] = { > + { .compatible = "renesas,rzv2m-pwc-gpio" }, > + { /* sentinel */ } > +}; > +MODULE_DEVICE_TABLE(of, rzv2m_pwc_gpio_of_match); > + > +static struct platform_driver rzv2m_pwc_gpio_driver = { > + .probe = rzv2m_pwc_gpio_probe, > + .driver = { > + .name = "rzv2m_pwc_gpio", > + .of_match_table = of_match_ptr(rzv2m_pwc_gpio_of_match), > + }, > +}; > +module_platform_driver(rzv2m_pwc_gpio_driver); > + > +MODULE_LICENSE("GPL"); > +MODULE_AUTHOR("Fabrizio Castro "); > +MODULE_DESCRIPTION("Renesas RZ/V2M PWC GPIO"); > -- > 2.34.1 >