From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05BCCC433F5 for ; Fri, 1 Oct 2021 11:38:19 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 6D5D161A63 for ; Fri, 1 Oct 2021 11:38:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6D5D161A63 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=br-automation.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5874F83257; Fri, 1 Oct 2021 13:38:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=br-automation.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 EDCDB831DB; Fri, 1 Oct 2021 13:38:09 +0200 (CEST) Received: from mail2.br-automation.com (mail2.br-automation.com [213.33.116.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 42C3682D13 for ; Fri, 1 Oct 2021 13:38:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=br-automation.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=hannes.schmelzer@br-automation.com X-AuditID: c0a80110-bd3bf70000001ea8-6f-6156f3189418 Received: from brsmtp01.br-automation.co.at (Unknown_Domain [192.168.1.60]) by mail2.br-automation.com () with SMTP id A1.49.07848.813F6516; Fri, 1 Oct 2021 13:38:00 +0200 (CEST) From: "Hannes Schmelzer" To: "U-Boot Mailing List" Cc: "Hannes Schmelzer" ,"Harm Berntsen" ,"Heiko Schocher" ,"Linus Walleij" ,"Michal Simek" ,"Sebastian Reichel" ,"Simon Glass" ,"Stefan Roese" ,"Stephan Gerhold" ,"Weijie Gao" Subject: [PATCH v1] drivers/gpio: add support for MAX7320 i2c i/o expander Date: Fri, 1 Oct 2021 13:37:57 +0200 Message-Id: <1633088277-24976-1-git-send-email-hannes.schmelzer@br-automation.com> Content-Transfer-Encoding: quoted-printable X-Mailer: git-send-email 2.7.4 X-MIMETrack: Itemize by SMTP Server on BRSMTPINTERN2/InternSMTP(Release 10.0.1FP3|August 09, 2019) at 01/10/2021 13:37:59, Serialize by Router on BRSMTPINTERN2/InternSMTP(Release 10.0.1FP3|August 09, 2019) at 01/10/2021 13:37:59, Serialize complete at 01/10/2021 13:37:59, Itemize by SMTP Server on BRSMTP01/Eggelsberg/AT/B&R(Release 10.0.1FP3|August 09, 2019) at 10/01/2021 01:38:00 PM X-TNEFEvaluated: 1 MIME-Version: 1.0 X-Disclaimed: 16187 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrNLMWRmVeSWpSXmKPExsVyYAWjja7E57BEg60rNS0WLXe32HHnPrPF lD/LmSzevYywuPvaz+Lblm2MFifXfWCyuDHXxOLt3k52i4YXp5kduDxmN1xk8dhxdwmjx7xZ J1g82hbYe9y5tofN4+ydHYweLSf3s3h0rpzK7LH382+WAM4oLpuU1JzMstQifbsErozd8yaz FVwxrDg4/wdLA+MRjS5GTg4JAROJvvYZ7F2MXBxCAlsZJTZN6WYHSbAJ2Eqcmn6CBcQWETCQ uL/6ClicWWAps8SC1c4gtrCAl8Tk1tNgNSwCKhI/3k1nBrF5BYIkfr+4zwRRry2xbOFrZohl chI3z3UygyyTEGhlluh8vp8JIiEkcXrxWahmQYmTM5+wQMSFJW7dmsk0gZFvFpJZs5CULWBk WsUonpuYmWOkl1Skm1hakp+bWJKZn6eXnJ+7iRES4AI7GHe/0T7EyMTBeIhRgoNZSYT3h3hw ohBvSmJlVWpRfnxRaU5q8SFGaQ4WJXHe1q23EoQE0hNLUrNTUwtSi2CyTBycUg2MVn7Hffe4 7zq5yU57lzxrjkVzvFms+wGrgszHTM4uvO53zqod+7qorb/srv+0xXqTWxO1ZBdXL4rdL7tg 3rdJM23t4xUcEr6/Sbw6v/BX6+KPgnEpJ5ZecK65plPjq+e+OeDCtNqf7VE/BfV5uRaenHrx lMSnmD/8VvuL9C/o+51g+3qY6ZqeEktxRqKhFnNRcSIAzH87lF4CAAA= X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean This commit adds support for the MAX7320 (and clones) gpio expander. Signed-off-by: Hannes Schmelzer --- doc/device-tree-bindings/gpio/gpio-max7320.txt | 36 ++++++++ drivers/gpio/Kconfig | 8 ++ drivers/gpio/Makefile | 1 + drivers/gpio/max7320=5Fgpio.c | 113 +++++++++++++++++++= ++++++ 4 files changed, 158 insertions(+) create mode 100644 doc/device-tree-bindings/gpio/gpio-max7320.txt create mode 100644 drivers/gpio/max7320=5Fgpio.c diff --git a/doc/device-tree-bindings/gpio/gpio-max7320.txt b/doc/device-tr= ee-bindings/gpio/gpio-max7320.txt new file mode 100644 index 0000000..87b703b --- /dev/null +++ b/doc/device-tree-bindings/gpio/gpio-max7320.txt @@ -0,0 +1,36 @@ +* MAX7320 I/O expanders + +The original maxim 7320 i/o expander offers 8 bit push/pull outputs. +There exists some clones which offers 16 bit. + +Required Properties: + + - compatible: should be one of the following. + - "maxim,max7320" + + - reg: I2C slave address. + + - gpio-controller: Marks the device node as a gpio controller. + - #gpio-cells: Should be 2. The first cell is the GPIO number and the se= cond + cell specifies GPIO flags, as defined in . On= ly the + GPIO=5FACTIVE=5FHIGH and GPIO=5FACTIVE=5FLOW flags are supported. + +Optional Properties: + + - ngpios: tell the driver how many gpios the device offers. + if the property is omitted, 8bit (original maxim) is assumed. + +Please refer to gpio.txt in this directory for details of the common GPIO +bindings used by client devices. + +Example: MAX7320 I/O expander node + + ledgpio: max7320@5d { + status =3D "okay"; + compatible =3D "maxim,max7320"; + reg =3D <0x5d>; + #gpio-cells =3D <2>; + gpio-controller; + ngpios =3D <16>; + }; + diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index e37ac9f..3aafbe3 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -513,4 +513,12 @@ config NOMADIK=5FGPIO into a number of banks each with 32 GPIOs. The GPIOs for a device are defined in the device tree with one node for each bank. =20 +config MAX7320=5FGPIO + bool "MAX7320 I2C GPIO Expander driver" + depends on DM=5FGPIO && DM=5FI2C + help + Support for MAX7320 I2C 8/16-bit GPIO expander. + original maxim device has 8 push/pull outputs, + some clones offers 16bit. + endmenu diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 58f4704..f59ea4a 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -69,3 +69,4 @@ obj-$(CONFIG=5FMSCC=5FSGPIO) +=3D mscc=5Fsgpio.o obj-$(CONFIG=5FNX=5FGPIO) +=3D nx=5Fgpio.o obj-$(CONFIG=5FSIFIVE=5FGPIO) +=3D sifive-gpio.o obj-$(CONFIG=5FNOMADIK=5FGPIO) +=3D nmk=5Fgpio.o +obj-$(CONFIG=5FMAX7320=5FGPIO) +=3D max7320=5Fgpio.o diff --git a/drivers/gpio/max7320=5Fgpio.c b/drivers/gpio/max7320=5Fgpio.c new file mode 100644 index 0000000..647aed9 --- /dev/null +++ b/drivers/gpio/max7320=5Fgpio.c @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * max7320 I2C GPIO EXPANDER DRIVER + * + * Copyright (C) 2021 Hannes Schmelzer + * B&R Industrial Automation GmbH - http://www.br-automation.com + * + */ + +#include +#include +#include +#include +#include + +struct max7320=5Fchip { + u32 outreg; +}; + +static int max7320=5Fdirection=5Foutput(struct udevice *dev, + unsigned int offset, int value) +{ + struct max7320=5Fchip *plat =3D dev=5Fget=5Fplat(dev); + struct gpio=5Fdev=5Fpriv *uc=5Fpriv =3D dev=5Fget=5Fuclass=5Fpriv(dev); + struct dm=5Fi2c=5Fchip *chip =3D dev=5Fget=5Fparent=5Fplat(dev); + + int ret; + + if (value) + plat->outreg |=3D BIT(offset); + else + plat->outreg &=3D ~BIT(offset); + + ret =3D dm=5Fi2c=5Fwrite(dev, + plat->outreg & 0xff, + (uint8=5Ft *)&plat->outreg + 1, + uc=5Fpriv->gpio=5Fcount > 8 ? 1 : 0); + if (ret) + printf("%s i2c write failed to addr %x\n", =5F=5Ffunc=5F=5F, + chip->chip=5Faddr); + + return ret; +} + +static int max7320=5Fget=5Fvalue(struct udevice *dev, unsigned int offset) +{ + struct max7320=5Fchip *plat =3D dev=5Fget=5Fplat(dev); + + return (plat->outreg >> offset) & 0x1; +} + +static int max7320=5Fset=5Fvalue(struct udevice *dev, unsigned int offset, + int value) +{ + return max7320=5Fdirection=5Foutput(dev, offset, value); +} + +static int max7320=5Fget=5Ffunction(struct udevice *dev, unsigned int offs= et) +{ + return GPIOF=5FOUTPUT; +} + +static int max7320=5Fofdata=5Fplat(struct udevice *dev) +{ + struct gpio=5Fdev=5Fpriv *uc=5Fpriv =3D dev=5Fget=5Fuclass=5Fpriv(dev); + + uc=5Fpriv->gpio=5Fcount =3D dev=5Fread=5Fu32=5Fdefault(dev, "ngpios", 8); + if (uc=5Fpriv->gpio=5Fcount > 16) { + printf("%s: max7320 doesn't support more than 16 gpios!", + =5F=5Ffunc=5F=5F); + return -EINVAL; + } + + uc=5Fpriv->bank=5Fname =3D fdt=5Fgetprop(gd->fdt=5Fblob, dev=5Fof=5Foffse= t(dev), + "gpio-bank-name", NULL); + if (!uc=5Fpriv->bank=5Fname) + uc=5Fpriv->bank=5Fname =3D fdt=5Fget=5Fname(gd->fdt=5Fblob, + dev=5Fof=5Foffset(dev), NULL); + + return 0; +} + +static int max7320=5Fgpio=5Fprobe(struct udevice *dev) +{ + struct gpio=5Fdev=5Fpriv *uc=5Fpriv =3D dev=5Fget=5Fuclass=5Fpriv(dev); + + debug("%s GPIO controller with %d gpios probed\n", + uc=5Fpriv->bank=5Fname, uc=5Fpriv->gpio=5Fcount); + + return 0; +} + +static const struct dm=5Fgpio=5Fops max7320=5Fgpio=5Fops =3D { + .direction=5Foutput =3D max7320=5Fdirection=5Foutput, + .set=5Fvalue =3D max7320=5Fset=5Fvalue, + .get=5Fvalue =3D max7320=5Fget=5Fvalue, + .get=5Ffunction =3D max7320=5Fget=5Ffunction, +}; + +static const struct udevice=5Fid max7320=5Fgpio=5Fids[] =3D { + { .compatible =3D "maxim,max7320" }, + { } +}; + +U=5FBOOT=5FDRIVER(gpio=5Fmax7320) =3D { + .name =3D "gpio=5Fmax7320", + .id =3D UCLASS=5FGPIO, + .ops =3D &max7320=5Fgpio=5Fops, + .of=5Fmatch =3D max7320=5Fgpio=5Fids, + .of=5Fto=5Fplat =3D max7320=5Fofdata=5Fplat, + .probe =3D max7320=5Fgpio=5Fprobe, + .plat=5Fauto =3D sizeof(struct max7320=5Fchip), +}; --=20 2.7.4