Received: by 10.223.176.5 with SMTP id f5csp807549wra; Fri, 9 Feb 2018 07:31:53 -0800 (PST) X-Google-Smtp-Source: AH8x226GTcMC67i77m8LoNxOP1EYXqq1wAAifPHvvTn3acfTQDaDJGRf7c2wqN4khBhEZEkQ9qbQ X-Received: by 2002:a17:902:261:: with SMTP id 88-v6mr1317173plc.384.1518190313035; Fri, 09 Feb 2018 07:31:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518190313; cv=none; d=google.com; s=arc-20160816; b=KwvfkJ/mrx8pkb5C+pQkuyr8Wgu4tdLbfv2CZSPaSMX5se3WCWFZtOPJ7D6gH/HT6g goWcWcUIykOR0nZDxRAMXT2G2hrCyac/IscwfgG/piy3VsrO6GTbIqdyrMLA/z9NPywC aux2IuCQjXN838gCwOYf2oKqeVZ3qBNLjZs/UfEza+LJPvwIQ1+aWI1kqk7vNQhqaN83 ZtEaHZxVUgPskXFtF8a2c52A234678IL01xA6GobpmykyGwM6FTrzJ7NLnbcDM8Ppg1m eXCjvMAdtmXaRUdCOWD+FOAva/7uPD3zq0aZ56VRaWwZWSOP2od+G2jFR4xI8d3FDIPg Zdqg== 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:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=gryUFluoRGbNloQNEQWtND0aUGPlY48faQsVcyHRgNQ=; b=sKN9I4XB5QC+4aIX6JnO6hwY1ugG2MLaTjh1WsGrao/dmT1x8sjJL3QlKdEfT6e+Dj 7fN+PoPVM8xU44ABKnLLaBQwTcBhGXnpJ+cDYuTEskD4bARStfHk5mfy54a0A3Q1VNVh 4eXzG0RVb1gnseWcetzHIKtVe+HiTVOhBFAQPF4r/kOGScbZDQIDpADfFM7+olqUplVF 1aDKc8wI0Fq4KWwguerVSYeZLDtKRcw7NuWZWmcQcfmXfxAkpHUo0cs+XrWQc/eAtr3a uf9uetzUL9RvKR4cYqEq4VqwouIzGljYIu6Jb8KnqntVWL6wJqyz5a9bruxRa768mETF 96qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=s8VowdJ6; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o25si1489610pgv.520.2018.02.09.07.31.38; Fri, 09 Feb 2018 07:31:53 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=s8VowdJ6; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751097AbeBIPa7 (ORCPT + 99 others); Fri, 9 Feb 2018 10:30:59 -0500 Received: from mail-qk0-f194.google.com ([209.85.220.194]:41384 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750981AbeBIPa5 (ORCPT ); Fri, 9 Feb 2018 10:30:57 -0500 Received: by mail-qk0-f194.google.com with SMTP id p23so10414196qke.8; Fri, 09 Feb 2018 07:30:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=gryUFluoRGbNloQNEQWtND0aUGPlY48faQsVcyHRgNQ=; b=s8VowdJ6H4RNakYdE1tboGhyb+yHKaMEk1X/kTiuQY+1CBK8f28E+7fMgB8Em2LOR9 yKq5y1mKqFQ+PDD0VMMMCpumbiDB7wJL7g3RPqMoFZI26s5HKkgN9Rbz6WtAX7dr+Db8 E+Jo3vuv/762mk/AFqDgOdQCAdiGqDCuLtMM639vraGoRyGp9y+3TbDHLBVrv8bRYLOT 4nRRSvQ5ECHyZ01sMj5sek3/5cD6mherdSqT8zjc6UcZ0z/JG2Xk+SPAN7UqEvOFReIg kFvpG7tbYygRN4OeLjpIfoOE0kc/oUp4lhqk+ps2sLngObGwRo8Z7kHqcKVSTwC5HvY+ QO/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=gryUFluoRGbNloQNEQWtND0aUGPlY48faQsVcyHRgNQ=; b=sjrWoaJLDJ2fpSSn87BijF+mvqwdWAuEZrtx4tSGkGjcrnXQOZTuNwTj5lTULZQ7Ms eO23k9Wcp88VlnSwpkJ28QyU289vI4dqlUjJUJlxHC3iGzWOlYZeVvn8QvGekNvkrHkT AxS/HVOmO07ekJvHoSGUWPCAAhs+1bB7I3NkVDIN+uDYDZNh1rv2DTIBAL3EFmB7asO2 Sro2+F9ocmmyOXK+ARV0WnINDS/Z4jOyt91bpkrOPMBmZ8V4kc82X0xeIKpwdkrouHIL whmu94Giq6OqHH1I3LJ1JadGcrmpdLFDHG5Byj26yv/A+XG0N1duVo8xbrqAtbWjkJCa L8uQ== X-Gm-Message-State: APf1xPB+yc8CmY7JOuadGek2pLo92ejYTxS7j6adsFxP23MRupGaE00i 60tRCGqU317OgQrPx3WJVratSrJX+1q9eNmZBnFL5Nsc X-Received: by 10.55.120.66 with SMTP id t63mr4328212qkc.345.1518190256533; Fri, 09 Feb 2018 07:30:56 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.175.35 with HTTP; Fri, 9 Feb 2018 07:30:55 -0800 (PST) In-Reply-To: <20180209120732.17863-3-j.neuschaefer@gmx.net> References: <20180209120732.17863-1-j.neuschaefer@gmx.net> <20180209120732.17863-3-j.neuschaefer@gmx.net> From: Andy Shevchenko Date: Fri, 9 Feb 2018 17:30:55 +0200 Message-ID: Subject: Re: [PATCH v3 2/4] gpio: Add GPIO driver for Nintendo Wii To: =?UTF-8?Q?Jonathan_Neusch=C3=A4fer?= Cc: Linux Kernel Mailing List , Joel Stanley , "open list:LINUX FOR POWERPC PA SEMI PWRFICIENT" , "open list:GPIO SUBSYSTEM" , devicetree , Albert Herranz , Segher Boessenkool , Linus Walleij Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 9, 2018 at 2:07 PM, Jonathan Neusch=C3=A4fer wrote: > The Nintendo Wii's chipset (called "Hollywood") has a GPIO controller > that supports a configurable number of pins (up to 32), interrupts, and > some special mechanisms to share the controller between the system's > security processor (an ARM926) and the PowerPC CPU. Pin multiplexing is > not supported. > > This patch adds a basic driver for this GPIO controller. Interrupt > support will come in a later patch. > > This patch is based on code developed by Albert Herranz and the GameCube > Linux Team, file arch/powerpc/platforms/embedded6xx/hlwd-gpio.c, > available at https://github.com/DeltaResero/GC-Wii-Linux-Kernels, but > has grown quite dissimilar. > Fine to me, though one comment below. In any case, Reviewed-by: Andy Shevchenko > Signed-off-by: Jonathan Neusch=C3=A4fer > Cc: Albert Herranz > Cc: Segher Boessenkool > <--- > > v3: > - Do some style cleanups, as suggest by Andy Shevchenko > > v2: > - Change hlwd_gpio_driver.driver.name to "gpio-hlwd" to match the > filename (was "hlwd_gpio") > - Remove unnecessary include of linux/of_gpio.h, as suggested by Linus > Walleij. > - Add struct device pointer to context struct to make it possible to use > dev_info(hlwd->dev, "..."), as suggested by Linus Walleij > - Use the GPIO_GENERIC library to reduce code size, as suggested by > Linus Walleij > - Use iowrite32be instead of __raw_writel for big-endian MMIO access, as > suggested by Linus Walleij > - Remove commit message paragraph suggesting to diff against the > original driver, because it's so different now > --- > drivers/gpio/Kconfig | 9 ++++ > drivers/gpio/Makefile | 1 + > drivers/gpio/gpio-hlwd.c | 115 +++++++++++++++++++++++++++++++++++++++++= ++++++ > 3 files changed, 125 insertions(+) > create mode 100644 drivers/gpio/gpio-hlwd.c > > diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig > index d6a8e851ad13..47606dfe06cc 100644 > --- a/drivers/gpio/Kconfig > +++ b/drivers/gpio/Kconfig > @@ -229,6 +229,15 @@ config GPIO_GRGPIO > Select this to support Aeroflex Gaisler GRGPIO cores from the G= RLIB > VHDL IP core library. > > +config GPIO_HLWD > + tristate "Nintendo Wii (Hollywood) GPIO" > + depends on OF_GPIO You may get rid of it if... > + select GPIO_GENERIC > + help > + Select this to support the GPIO controller of the Nintendo Wii. > + > + If unsure, say N. > + > config GPIO_ICH > tristate "Intel ICH GPIO" > depends on PCI && X86 > diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile > index 4bc24febb889..492f62d0eb59 100644 > --- a/drivers/gpio/Makefile > +++ b/drivers/gpio/Makefile > @@ -54,6 +54,7 @@ obj-$(CONFIG_GPIO_FTGPIO010) +=3D gpio-ftgpio010.o > obj-$(CONFIG_GPIO_GE_FPGA) +=3D gpio-ge.o > obj-$(CONFIG_GPIO_GPIO_MM) +=3D gpio-gpio-mm.o > obj-$(CONFIG_GPIO_GRGPIO) +=3D gpio-grgpio.o > +obj-$(CONFIG_GPIO_HLWD) +=3D gpio-hlwd.o > obj-$(CONFIG_HTC_EGPIO) +=3D gpio-htc-egpio.o > obj-$(CONFIG_GPIO_ICH) +=3D gpio-ich.o > obj-$(CONFIG_GPIO_INGENIC) +=3D gpio-ingenic.o > diff --git a/drivers/gpio/gpio-hlwd.c b/drivers/gpio/gpio-hlwd.c > new file mode 100644 > index 000000000000..a63136a68ba3 > --- /dev/null > +++ b/drivers/gpio/gpio-hlwd.c > @@ -0,0 +1,115 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +// Copyright (C) 2008-2009 The GameCube Linux Team > +// Copyright (C) 2008,2009 Albert Herranz > +// Copyright (C) 2017-2018 Jonathan Neusch=C3=A4fer > +// > +// Nintendo Wii (Hollywood) GPIO driver > + > +#include > +#include > +#include > +#include > +#include > +#include ...(and using platform device header I suppose)... > +#include > + > +/* > + * Register names and offsets courtesy of WiiBrew: > + * https://wiibrew.org/wiki/Hardware/Hollywood_GPIOs > + * > + * Note that for most registers, there are two versions: > + * - HW_GPIOB_* Is always accessible by the Broadway PowerPC core, but d= oes > + * always give access to all GPIO lines > + * - HW_GPIO_* Is only accessible by the Broadway PowerPC code if the me= mory > + * firewall (AHBPROT) in the Hollywood chipset has been configured to = allow > + * such access. > + * > + * The ownership of each GPIO line can be configured in the HW_GPIO_OWNE= R > + * register: A one bit configures the line for access via the HW_GPIOB_* > + * registers, a zero bit indicates access via HW_GPIO_*. This driver use= s > + * HW_GPIOB_*. > + */ > +#define HW_GPIOB_OUT 0x00 > +#define HW_GPIOB_DIR 0x04 > +#define HW_GPIOB_IN 0x08 > +#define HW_GPIOB_INTLVL 0x0c > +#define HW_GPIOB_INTFLAG 0x10 > +#define HW_GPIOB_INTMASK 0x14 > +#define HW_GPIOB_INMIR 0x18 > +#define HW_GPIO_ENABLE 0x1c > +#define HW_GPIO_OUT 0x20 > +#define HW_GPIO_DIR 0x24 > +#define HW_GPIO_IN 0x28 > +#define HW_GPIO_INTLVL 0x2c > +#define HW_GPIO_INTFLAG 0x30 > +#define HW_GPIO_INTMASK 0x34 > +#define HW_GPIO_INMIR 0x38 > +#define HW_GPIO_OWNER 0x3c > + > +struct hlwd_gpio { > + struct gpio_chip gpioc; > + void __iomem *regs; > +}; > + > +static int hlwd_gpio_probe(struct platform_device *pdev) > +{ > + struct hlwd_gpio *hlwd; > + struct resource *regs_resource; > + u32 ngpios; > + int res; > + > + hlwd =3D devm_kzalloc(&pdev->dev, sizeof(*hlwd), GFP_KERNEL); > + if (!hlwd) > + return -ENOMEM; > + > + regs_resource =3D platform_get_resource(pdev, IORESOURCE_MEM, 0); > + hlwd->regs =3D devm_ioremap_resource(&pdev->dev, regs_resource); > + if (IS_ERR(hlwd->regs)) > + return PTR_ERR(hlwd->regs); > + > + /* > + * Claim all GPIOs using the OWNER register. This will not work o= n > + * systems where the AHBPROT memory firewall hasn't been configur= ed to > + * permit PPC access to HW_GPIO_*. > + * > + * Note that this has to happen before bgpio_init reads the > + * HW_GPIOB_OUT and HW_GPIOB_DIR, because otherwise it reads the = wrong > + * values. > + */ > + iowrite32be(0xffffffff, hlwd->regs + HW_GPIO_OWNER); > + > + res =3D bgpio_init(&hlwd->gpioc, &pdev->dev, 4, > + hlwd->regs + HW_GPIOB_IN, hlwd->regs + HW_GPIOB_O= UT, > + NULL, hlwd->regs + HW_GPIOB_DIR, NULL, > + BGPIOF_BIG_ENDIAN_BYTE_ORDER); > + if (res < 0) { > + dev_warn(&pdev->dev, "bgpio_init failed: %d\n", res); > + return res; > + } > + > + res =3D of_property_read_u32(pdev->dev.of_node, "ngpios", &ngpios= ); ...if you switch to unified device property API. > + if (res) > + ngpios =3D 32; > + hlwd->gpioc.ngpio =3D ngpios; > + > + return devm_gpiochip_add_data(&pdev->dev, &hlwd->gpioc, hlwd); > +} > + > +static const struct of_device_id hlwd_gpio_match[] =3D { > + { .compatible =3D "nintendo,hollywood-gpio", }, > + {}, > +}; > +MODULE_DEVICE_TABLE(of, hlwd_gpio_match); > + > +static struct platform_driver hlwd_gpio_driver =3D { > + .driver =3D { > + .name =3D "gpio-hlwd", > + .of_match_table =3D hlwd_gpio_match, > + }, > + .probe =3D hlwd_gpio_probe, > +}; > +module_platform_driver(hlwd_gpio_driver); > + > +MODULE_AUTHOR("Jonathan Neusch=C3=A4fer "); > +MODULE_DESCRIPTION("Nintendo Wii GPIO driver"); > +MODULE_LICENSE("GPL"); > -- > 2.15.1 > --=20 With Best Regards, Andy Shevchenko