Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp960005pxb; Thu, 21 Oct 2021 12:52:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0BjyMIr5dj1hd+C9Y8eDiuyQMXjpXrEDLNRLHVDIjflFwJ91wWo4endBBWm76SBC9/7hC X-Received: by 2002:a63:3e84:: with SMTP id l126mr5996858pga.341.1634845970514; Thu, 21 Oct 2021 12:52:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634845970; cv=none; d=google.com; s=arc-20160816; b=fNwOnqRPsoK/bjnr0AVAu/AGhyHieeWuUwrBgudgemyVvAlJb/R6Ka4gibhOeppL0I v204SyhpAyCCuSJYBecO0XPwk6qiYddmsqDdNF4HPxY/5jXIWp0nmJrddsQBySYUbNzn 4V8ZesdcVQBjur+Irl4sylaGbtVIa55LUYvlFz5H9Yvk5l8y7Ve5Ou6VRjUDlqvXYBnh aRCrHGSSdclCBCTqiZjbnZjCQFfDi20weMbWO9QF/Iqgvuo22jcri+hUNjfJYqB/fZNu g3LGGu2Tx1tutjI7A7WuEd+OGvtShzr/+ij7KT8OY/DToGvGNxOrfYWb6+gizUVRb3yy V+LQ== 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; bh=5qcBk3DeZv7+MBr+DGak5KmAIKq22H5/grJVeSCeLaw=; b=EWWv4D1Hu4Ca7zJGcTCMKIPKlpehx5NuNn/g9jvheg01+8OzipqxxAprE5TNCJQuux 2Cnoct5ExzOPeAUPuFupHkd6XJHrFWaxt1WJ/fXeXXoVR0LMDoAZsucJC1wP5IOlGINi GypJb4A+vTw+ADqKmSjXdslGei++WsxF8E6UbRrgqYUPDebG4+GH+0uWqloi8kJwrJ6l Dh/IAwRPY/X7/flxPK0s/3hbjNydoGu6T4SFlwqOAHJepN3CqDWHBlBO8hNibgpPSqxQ UCPfYVnGaJTOA2MySZ/4WnaDb0vMGz9HNsX61bCZBkv6GxvXR8Ugyh5F+LaLIG7YHnsb Clkw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h6si8546384plf.222.2021.10.21.12.52.32; Thu, 21 Oct 2021 12:52:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231853AbhJUTxL (ORCPT + 99 others); Thu, 21 Oct 2021 15:53:11 -0400 Received: from mail-pg1-f177.google.com ([209.85.215.177]:35651 "EHLO mail-pg1-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231728AbhJUTxJ (ORCPT ); Thu, 21 Oct 2021 15:53:09 -0400 Received: by mail-pg1-f177.google.com with SMTP id q187so1274761pgq.2; Thu, 21 Oct 2021 12:50:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5qcBk3DeZv7+MBr+DGak5KmAIKq22H5/grJVeSCeLaw=; b=ZjItPisPSDEL6cgmvUPYFaAZEy0N46bIWUjLpg8oJfA6tpA3SbC9C4EPghn/wGs4JD cII7/2xC3dnbGAMmhklBB7JA4bZ2psdJXPmFoOFLR4ujbiiUb7l4VhAawaMEELxMYJ42 5Us60xzpB/f9V+wFNyPUoFur/ONjDcXD0xXb9wCy33GBIv3EQeTHDb4G/EYiWEK0ULtb /v1yXWtKMZF8753QsYsm5LMlABi592MQcK3lgHqL6uaMPyfWy1Te4HeWGtEaylxBejpx 2q5fzejSLFYreio2lxOZ+shyweg+0PbM9ZWykT+W/wHWXxzCs4jKBjtNEODE+OO8J4xU B9Bw== X-Gm-Message-State: AOAM533iLrDX8+dmEY3xez1WN3h0tALAHOWZuRq63VZ4EUPafgbABuR1 ODeaC6W3dj3IGudUs0K97/8sPTTHRAZ3HjwUuB4= X-Received: by 2002:a63:2d46:: with SMTP id t67mr5876914pgt.15.1634845853245; Thu, 21 Oct 2021 12:50:53 -0700 (PDT) MIME-Version: 1.0 References: <20211021174223.43310-1-kernel@esmil.dk> <20211021174223.43310-13-kernel@esmil.dk> <20211021190118.GA1802180@x1> In-Reply-To: <20211021190118.GA1802180@x1> From: Emil Renner Berthing Date: Thu, 21 Oct 2021 21:50:42 +0200 Message-ID: Subject: Re: [PATCH v2 12/16] pinctrl: starfive: Add pinctrl driver for StarFive SoCs To: Drew Fustini Cc: linux-riscv , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , linux-clk , "open list:GPIO SUBSYSTEM" , "open list:SERIAL DRIVERS" , Palmer Dabbelt , Paul Walmsley , Rob Herring , Michael Turquette , Stephen Boyd , Thomas Gleixner , Marc Zyngier , Philipp Zabel , Linus Walleij , Greg Kroah-Hartman , Daniel Lezcano , Andy Shevchenko , Jiri Slaby , Maximilian Luz , Sagar Kadam , Drew Fustini , Geert Uytterhoeven , Michael Zhu , Fu Wei , Anup Patel , Atish Patra , Matteo Croce , Linux Kernel Mailing List , Huan Feng Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 21 Oct 2021 at 21:01, Drew Fustini wrote: > On Thu, Oct 21, 2021 at 07:42:19PM +0200, Emil Renner Berthing wrote: > > +/* > > + * Interrupt Trigger Polarity. If set to 1 the interrupt is triggered on a > > + * rising edge (edge-triggered) or high level (level-triggered). If set to 0 the > > + * interrupt is triggered on a falling edge (edge-triggered) or low level > > + * (level-triggered). > > + */ > > +#define GPIOIEV 0x020 > > + > > +/* > > + * Interrupt Mask. If set to 1 the interrupt is disabled (masked). If set to 0 > > + * the interrupt is enabled (unmasked). > > + */ > > +#define GPIOIE 0x028 > > It bothered me that the datasheet used the term GPIOIE for the interrupt > mask register. I had used a more verbose #define name because I worried > someone reading GPIOIE in functions might mistake it for an interrupt > enable register. This happened to me when I was originally working with > the gpio driver. > > However I suppose the best solution would have been to get the datasheet > updated as I can see how it is best to have #define names in the driver > match the datasheet. > > > +static void starfive_irq_mask(struct irq_data *d) > > +{ > > + struct starfive_pinctrl *sfp = starfive_from_irq_data(d); > > + irq_hw_number_t gpio = irqd_to_hwirq(d); > > + void __iomem *ie = sfp->base + GPIOIE + 4 * (gpio / 32); > > + u32 mask = BIT(gpio % 32); > > + unsigned long flags; > > + u32 value; > > + > > + raw_spin_lock_irqsave(&sfp->lock, flags); > > + value = readl_relaxed(ie) & ~mask; > > + writel_relaxed(value, ie); > > + raw_spin_unlock_irqrestore(&sfp->lock, flags); > > +} > > + > > +static void starfive_irq_mask_ack(struct irq_data *d) > > +{ > > + struct starfive_pinctrl *sfp = starfive_from_irq_data(d); > > + irq_hw_number_t gpio = irqd_to_hwirq(d); > > + void __iomem *ie = sfp->base + GPIOIE + 4 * (gpio / 32); > > + void __iomem *ic = sfp->base + GPIOIC + 4 * (gpio / 32); > > + u32 mask = BIT(gpio % 32); > > + unsigned long flags; > > + u32 value; > > + > > + raw_spin_lock_irqsave(&sfp->lock, flags); > > + value = readl_relaxed(ie) & ~mask; > > + writel_relaxed(value, ie); > > + writel_relaxed(mask, ic); > > + raw_spin_unlock_irqrestore(&sfp->lock, flags); > > +} > > + > > +static void starfive_irq_unmask(struct irq_data *d) > > +{ > > + struct starfive_pinctrl *sfp = starfive_from_irq_data(d); > > + irq_hw_number_t gpio = irqd_to_hwirq(d); > > + void __iomem *ie = sfp->base + GPIOIE + 4 * (gpio / 32); > > + u32 mask = BIT(gpio % 32); > > + unsigned long flags; > > + u32 value; > > + > > + raw_spin_lock_irqsave(&sfp->lock, flags); > > + value = readl_relaxed(ie) | mask; > > + writel_relaxed(value, ie); > > + raw_spin_unlock_irqrestore(&sfp->lock, flags); > > +} > > + ... > > +static int starfive_gpio_init_hw(struct gpio_chip *gc) > > +{ > > + struct starfive_pinctrl *sfp = starfive_from_gc(gc); > > + > > + /* mask all GPIO interrupts */ > > + writel(0, sfp->base + GPIOIE + 0); > > + writel(0, sfp->base + GPIOIE + 4); > > Woudln't 0 in GPIOIE mean mask is disabled for all interrupts? > > In other words, wouldn't this enable all the interrupts? Heh, you're right. The code does the exact opposite of what the documentation says it should be doing. However I just tried and with the code as it is now GPIO interrupts work fine, but with the logic flipped the kernel fails to boot. I'm guessing because an interrupt storm. So it seems to me the documentation might be wrong and GPIOIE is actually a good name. Michael Zhu: Can you confirm if a 1 or 0 enables the interrupt in the GPIOIE registers? /Emil