Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp862372imm; Wed, 10 Oct 2018 05:36:19 -0700 (PDT) X-Google-Smtp-Source: ACcGV61S8fvXze1CaiCL6X9nx/IJdhy2k7wyVIczYJhTd4PVkZVqidaoB0AIeHMWDo5tBz+Oe63h X-Received: by 2002:a63:c112:: with SMTP id w18-v6mr30050459pgf.429.1539174979576; Wed, 10 Oct 2018 05:36:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539174979; cv=none; d=google.com; s=arc-20160816; b=U/ezxGYHToahN8LkPgLnL5m2MuaTp9u0lMFPCdVLuclfJgs0vWkTzH4QjUnvQldym1 Li3gCQjmLiJL/2cgr2EPWFv88YrFKIFL97CFV933y0cyOeyhUQvLO45cqwkzaLQEywsG QJsvKdc4+H3B8Xzr4rJVPk+D7ypX+DpITwhoPt1s7VT9LtAo/IS8WZJG04nw/LGjvvgQ XxC8fQZFeZyCkSuT1/Hpo138stVi/9sSZoU2CYRYt06RS68/gprXLbJjdav+gMoPtGNZ Z/fhK06yMmWSbTxu6NyKG7Y9kWpsMNCcFEPslT9IWjlQYiVqO+j6QSCfv6uZ73JJx1AR n7MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=LK9+G6KymxKlkyxnkqpHkZFSykVTIPaNiAUqgugUA9Q=; b=NfbnkWu9RDohlQKsFueUhQIzh+R1xaRQZm/2VlcTjqirs1jYNsBbykrHM44R3sXWHk Y68BlrK/+zqXhpiYH4Kh4bBripJdRlFfOVg86qNU8xG/SALS5lOQsaGEKzCJHkACdPLe DoQvKXz+yRzHEffl+2ojL9P0pr3KSvUqhA8Ind2LJ6dSnNU2N+a2Y9zqhh5E1Z8KuibV UbNmGo5GI6laMt8RK5C18mrfSvjPciZyM53Rw/EYTQRK9GjeCNuuajr0GcVihbaAF4F9 zwjGLlua56t3mivyHzJ9dK4lLvSqJC/LIlC7mCFA7cZo+6SbcyU/iD1eByVPcdEjcqfK +Bcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GFUBM7+f; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u13-v6si25351924pfl.129.2018.10.10.05.36.04; Wed, 10 Oct 2018 05:36:19 -0700 (PDT) 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=@linaro.org header.s=google header.b=GFUBM7+f; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726786AbeJJT5b (ORCPT + 99 others); Wed, 10 Oct 2018 15:57:31 -0400 Received: from mail-it1-f195.google.com ([209.85.166.195]:39661 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726562AbeJJT5a (ORCPT ); Wed, 10 Oct 2018 15:57:30 -0400 Received: by mail-it1-f195.google.com with SMTP id w200-v6so7661951itc.4 for ; Wed, 10 Oct 2018 05:35:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LK9+G6KymxKlkyxnkqpHkZFSykVTIPaNiAUqgugUA9Q=; b=GFUBM7+fUw2M70npY32WActEysjzu9z/LR6Fe27VNBC769C1UHnZCXXMtEfC5tKOOp /eOV+FPRWAJ7gqpL57o2yjEEysIsnkP49siSfeuJuPRWThJE20pVQZbi3r7IrRC3bMfZ RGTpZSmCZs3NWNhOHqhwJINCX1Be/WoDoIOZU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LK9+G6KymxKlkyxnkqpHkZFSykVTIPaNiAUqgugUA9Q=; b=LFPNMEX3WHc/GqJBXRHHQBWKN43Syc1Di8UW3l/91w0fZQCJqha/2gSFeFKPlxRWLj 6x2kLh13aCQ5RpBkQL+svaTAZqTuIRX5GD4DvG0btxiBbUo/RS8igIMgrSLx12duXGDU qC7zTwPHLsjHlfD784JVROhn+B2tZsXsguGTNqrQNA0GqzWgPESAjRl8JXPALpgEHYip ZkBGgW3590atE8rRaw6UKOEIlzJwJ8xjjAYkQb23BCP1CzS0fOf1aFrTd03Z0qYOLnSV 3ggMTH2FbL3AVj4f/8nHVPUIWPOtab2j0N/ou+yrmIv2paab5zGRjxz5uteyuUvPmKtn sHaQ== X-Gm-Message-State: ABuFfoikXCMBGq2ZdTc8uBvujSe9sPfBIxMQRfvRXD+VxMIMop5BvUO1 KNrUTWIQxH+GnFpLxm1zsfbd7aJPux0cwobD+5uK+A== X-Received: by 2002:a02:7789:: with SMTP id g131-v6mr25519247jac.66.1539174931405; Wed, 10 Oct 2018 05:35:31 -0700 (PDT) MIME-Version: 1.0 References: <1539111085-25502-1-git-send-email-atish.patra@wdc.com> <1539111085-25502-5-git-send-email-atish.patra@wdc.com> In-Reply-To: <1539111085-25502-5-git-send-email-atish.patra@wdc.com> From: Linus Walleij Date: Wed, 10 Oct 2018 14:35:19 +0200 Message-ID: Subject: Re: [RFC 4/4] gpio: sifive: Add GPIO driver for SiFive SoCs To: atish.patra@wdc.com, "thierry.reding@gmail.com" Cc: Palmer Dabbelt , linux-riscv@lists.infradead.org, linux-pwm@vger.kernel.org, "open list:GPIO SUBSYSTEM" , Rob Herring , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , "linux-kernel@vger.kernel.org" , Mark Rutland , Christoph Hellwig Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Atish, thanks for your patch! On Tue, Oct 9, 2018 at 8:51 PM Atish Patra wrote: > From: "Wesley W. Terpstra" > > Adds the GPIO driver for SiFive RISC-V SoCs. > > Signed-off-by: Wesley W. Terpstra > [Atish: Various fixes and code cleanup] > Signed-off-by: Atish Patra (...) > +config GPIO_SIFIVE > + bool "SiFive GPIO support" > + depends on OF_GPIO > + select GPIOLIB_IRQCHIP I suggest to add select GPIO_GENERIC as per below. Maybe select REGMAP_MMIO as well. > + help > + Say yes here to support the GPIO device on SiFive SoCs. > + > +#include > +#include Do you need these two? I think will bring them in for you. > +#include Are you using this? > +struct sifive_gpio { > + raw_spinlock_t lock; > + void __iomem *base; > + struct gpio_chip gc; > + unsigned long enabled; Since max GPIO is 32 why not use an u32 for this? > + unsigned int trigger[MAX_GPIO]; > + unsigned int irq_parent[MAX_GPIO]; > + struct sifive_gpio *self_ptr[MAX_GPIO]; > +}; > + > +static void sifive_assign_bit(void __iomem *ptr, unsigned int offset, int value) > +{ > + /* > + * It's frustrating that we are not allowed to use the device atomics > + * which are GUARANTEED to be supported by this device on RISC-V > + */ > + u32 bit = BIT(offset), old = ioread32(ptr); > + > + if (value) > + iowrite32(old | bit, ptr); > + else > + iowrite32(old & ~bit, ptr); > +} This looks like a mask and set implementation, you are essentially reinventing regmap MMIO and the regmap_update_bits() call. Could you look into just using regmap MMIO in that case? If you need examples, look at gpio-mvebu.c that calls devm_regmap_init_mmio() for example. > +static int sifive_direction_input(struct gpio_chip *gc, unsigned int offset) > +static int sifive_direction_output(struct gpio_chip *gc, unsigned int offset, > +static int sifive_get_direction(struct gpio_chip *gc, unsigned int offset) > +static int sifive_get_value(struct gpio_chip *gc, unsigned int offset) > +static void sifive_set_value(struct gpio_chip *gc, unsigned int offset, These functions look like a typical hardware that can use GPIOLIB_GENERIC and bgpio_init() to set up the accessors. See gpio-ftgpio010.c for an example. As a bonus you will get .get/.set_multiple implemented by the generic GPIO. > +static void sifive_irq_enable(struct irq_data *d) > +static void sifive_irq_disable(struct irq_data *d) (...) > +static struct irq_chip sifive_irqchip = { > + .name = "sifive-gpio", > + .irq_set_type = sifive_irq_set_type, > + .irq_mask = sifive_irq_mask, > + .irq_unmask = sifive_irq_unmask, > + .irq_enable = sifive_irq_enable, > + .irq_disable = sifive_irq_disable, The handling of .irq_enable and .irq_disable has changed upstream. Please align with the new codebase as changed by Hans Verkuil: commit 461c1a7d4733d1dfd5c47b040cf32a5e7eefbc6c "gpiolib: override irq_enable/disable" commit 4e9439ddacea06f35acce4d374bf6bd0acf99bc8 "gpiolib: add flag to indicate if the irq is disabled" You will need to rebase your work on the v4.20-rc1 once it is out. Right now the changes are on linux-next or my devel branch. > + ngpio = of_irq_count(node); > + if (ngpio >= MAX_GPIO) { > + dev_err(dev, "Too many GPIO interrupts (max=%d)\n", MAX_GPIO); > + return -ENXIO; > + } (...) > + for (gpio = 0; gpio < ngpio; ++gpio) { > + irq = platform_get_irq(pdev, gpio); > + if (irq < 0) { > + dev_err(dev, "invalid IRQ\n"); > + gpiochip_remove(&chip->gc); > + return -ENODEV; > + } This is an hierarchical IRQ so it should use an hierarchical irqdomain. I am discussing with Thierry to make more generic irq domains for hierarchical IRQ GPIOs, until then you have to look at gpio-thunderx.c, gpio-uniphier.c or gpio-xgene-sb.c that all use hierarchical IRQs. Yours, Linus Walleij