Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 45C5FC433F5 for ; Sun, 30 Jan 2022 01:18:44 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C94428129B; Sun, 30 Jan 2022 02:18:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 83C838169D; Sun, 30 Jan 2022 02:18:39 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 847FC80FD2 for ; Sun, 30 Jan 2022 02:18:36 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=andre.przywara@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 83222ED1; Sat, 29 Jan 2022 17:18:35 -0800 (PST) Received: from slackpad.fritz.box (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E47F23F73B; Sat, 29 Jan 2022 17:18:33 -0800 (PST) Date: Sun, 30 Jan 2022 01:18:23 +0000 From: Andre Przywara To: Samuel Holland Cc: Heinrich Schuchardt , Andy Shevchenko , Icenowy Zheng , Jaehoon Chung , Jernej Skrabec , Peng Fan , Simon Glass , u-boot@lists.denx.de, Jagan Teki Subject: Re: [PATCH 3/4] gpio: sunxi: Implement .set_flags Message-ID: <20220130011823.016777bc@slackpad.fritz.box> In-Reply-To: <8f46da6f-461c-a3ea-3486-5bc9fc6e13c6@sholland.org> References: <20211021045258.30757-1-samuel@sholland.org> <20211021045258.30757-4-samuel@sholland.org> <8f46da6f-461c-a3ea-3486-5bc9fc6e13c6@sholland.org> Organization: Arm Ltd. X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.31; x86_64-slackware-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean On Fri, 5 Nov 2021 16:46:07 -0500 Samuel Holland wrote: > On 11/5/21 9:43 AM, Heinrich Schuchardt wrote: > > On 10/21/21 06:52, Samuel Holland wrote: =20 > >> This, along with gpio_flags_xlate(), allows the GPIO driver to handle > >> pull-up/down flags provided by consumer drivers or in the device tree. > >> > >> Signed-off-by: Samuel Holland > >> Reviewed-by: Simon Glass > >> --- > >> > >> =C2=A0 drivers/gpio/sunxi_gpio.c | 62 +++++++++++++++++---------------= ------- > >> =C2=A0 1 file changed, 27 insertions(+), 35 deletions(-) > >> > >> diff --git a/drivers/gpio/sunxi_gpio.c b/drivers/gpio/sunxi_gpio.c > >> index cdbc40d48f..92fee0118d 100644 > >> --- a/drivers/gpio/sunxi_gpio.c > >> +++ b/drivers/gpio/sunxi_gpio.c > >> @@ -139,27 +139,6 @@ int sunxi_name_to_gpio(const char *name) > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return ret ? ret : gpio; > >> =C2=A0 } > >> =C2=A0 -static int sunxi_gpio_direction_input(struct udevice *dev, uns= igned > >> offset) > >> -{ > >> -=C2=A0=C2=A0=C2=A0 struct sunxi_gpio_plat *plat =3D dev_get_plat(dev); > >> - > >> -=C2=A0=C2=A0=C2=A0 sunxi_gpio_set_cfgbank(plat->regs, offset, SUNXI_G= PIO_INPUT); > >> - > >> -=C2=A0=C2=A0=C2=A0 return 0; > >> -} > >> - > >> -static int sunxi_gpio_direction_output(struct udevice *dev, unsigned > >> offset, > >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int value) > >> -{ > >> -=C2=A0=C2=A0=C2=A0 struct sunxi_gpio_plat *plat =3D dev_get_plat(dev); > >> -=C2=A0=C2=A0=C2=A0 u32 num =3D GPIO_NUM(offset); > >> - > >> -=C2=A0=C2=A0=C2=A0 sunxi_gpio_set_cfgbank(plat->regs, offset, SUNXI_G= PIO_OUTPUT); > >> -=C2=A0=C2=A0=C2=A0 clrsetbits_le32(&plat->regs->dat, 1 << num, value = ? (1 << num) : 0); > >> - > >> -=C2=A0=C2=A0=C2=A0 return 0; > >> -} > >> - > >> =C2=A0 static int sunxi_gpio_get_value(struct udevice *dev, unsigned o= ffset) > >> =C2=A0 { > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct sunxi_gpio_plat *plat =3D dev_ge= t_plat(dev); > >> @@ -172,16 +151,6 @@ static int sunxi_gpio_get_value(struct udevice > >> *dev, unsigned offset) > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return dat & 0x1; > >> =C2=A0 } > >> =C2=A0 -static int sunxi_gpio_set_value(struct udevice *dev, unsigned = offset, > >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 int value) > >> -{ > >> -=C2=A0=C2=A0=C2=A0 struct sunxi_gpio_plat *plat =3D dev_get_plat(dev); > >> -=C2=A0=C2=A0=C2=A0 u32 num =3D GPIO_NUM(offset); > >> - > >> -=C2=A0=C2=A0=C2=A0 clrsetbits_le32(&plat->regs->dat, 1 << num, value = ? (1 << num) : 0); > >> -=C2=A0=C2=A0=C2=A0 return 0; > >> -} > >> - > >> =C2=A0 static int sunxi_gpio_get_function(struct udevice *dev, unsigned > >> offset) > >> =C2=A0 { > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct sunxi_gpio_plat *plat =3D dev_ge= t_plat(dev); > >> @@ -205,18 +174,41 @@ static int sunxi_gpio_xlate(struct udevice *dev, > >> struct gpio_desc *desc, > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (ret) > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return ret; > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 desc->offset =3D args->args[1]; > >> -=C2=A0=C2=A0=C2=A0 desc->flags =3D args->args[2] & GPIO_ACTIVE_LOW ? = GPIOD_ACTIVE_LOW > >> : 0; > >> +=C2=A0=C2=A0=C2=A0 desc->flags =3D gpio_flags_xlate(args->args[2]); > >> + > >> +=C2=A0=C2=A0=C2=A0 return 0; > >> +} > >> + > >> +static int sunxi_gpio_set_flags(struct udevice *dev, unsigned int > >> offset, > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 ulong flags) > >> +{ > >> +=C2=A0=C2=A0=C2=A0 struct sunxi_gpio_plat *plat =3D dev_get_plat(dev); > >> + > >> +=C2=A0=C2=A0=C2=A0 if (flags & GPIOD_IS_OUT) { > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 u32 value =3D !!(flags & G= PIOD_IS_OUT_ACTIVE); > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 u32 num =3D GPIO_NUM(offse= t); > >> + > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 clrsetbits_le32(&plat->reg= s->dat, 1 << num, value << num); > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 sunxi_gpio_set_cfgbank(pla= t->regs, offset, SUNXI_GPIO_OUTPUT); > >> +=C2=A0=C2=A0=C2=A0 } else if (flags & GPIOD_IS_IN) { > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 u32 pull =3D 0; > >> + > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (flags & GPIOD_PULL_UP) > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pu= ll =3D 1; > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 else if (flags & GPIOD_PUL= L_DOWN) > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pu= ll =3D 2; > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 sunxi_gpio_set_pull_bank(p= lat->regs, offset, pull); > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 sunxi_gpio_set_cfgbank(pla= t->regs, offset, SUNXI_GPIO_INPUT); > >> +=C2=A0=C2=A0=C2=A0 } > >> =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return 0; > >> =C2=A0 } > >> =C2=A0 =C2=A0 static const struct dm_gpio_ops gpio_sunxi_ops =3D { > >> -=C2=A0=C2=A0=C2=A0 .direction_input=C2=A0=C2=A0=C2=A0 =3D sunxi_gpio_= direction_input, > >> -=C2=A0=C2=A0=C2=A0 .direction_output=C2=A0=C2=A0=C2=A0 =3D sunxi_gpio= _direction_output, =20 > >=20 > > Removing these operations is not related to your commit message. > >=20 > > dm_gpio_set_value() seems to be using them. =20 >=20 > It does not use any of these operations when set_flags is provided. The > same applies to _dm_gpio_set_flags(). >=20 > asm-generic/gpio.h says about set_flags: > > This method is required and should be implemented by new drivers. At > > some point, it will supersede direction_input() and > > direction_output(), which wil be removed. =20 >=20 > So I believe it is intended to replace the other three operations. That's what I get from the code and this header file comment as well. Reviewed-by: Andre Przywara Cheers, Andre >=20 > Regards, > Samuel >=20 > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .get_value=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 =3D sunxi_gpio_get_value, > >> -=C2=A0=C2=A0=C2=A0 .set_value=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 =3D sunxi_gpio_set_value, =20 > >=20 > > Same here. > >=20 > > Best regards > >=20 > > Heinrich > > =20 > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .get_function=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 =3D sunxi_gpio_get_function, > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .xlate=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =3D sunxi_gpio_xlate, > >> +=C2=A0=C2=A0=C2=A0 .set_flags=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 =3D sunxi_gpio_set_flags, > >> =C2=A0 }; > >> =C2=A0 =C2=A0 /** > >> =20 > > =20 >=20