Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1239090pxb; Thu, 21 Oct 2021 19:11:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnq+CZsS5oD7PCS81u1hHn/YxbWKc4TTU0nu7UZZVcGKDSDrJj7KlHjgw0HByHHxm2Wonp X-Received: by 2002:a17:907:3f9c:: with SMTP id hr28mr11737534ejc.246.1634868681165; Thu, 21 Oct 2021 19:11:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634868681; cv=none; d=google.com; s=arc-20160816; b=W0VGiftgYL59nKnqaTnIgZ7U7k+mUjlmbNVkld+83ii0FdgjzDu+DVLbPBF4x9Q9US BbvS0DDdHmQCEcVDiqh84JMmd4ufIPVHZlQjQjVDdova2F7jB2YAZJI74lo0jGjq1Z7T Iq6d6yhFqzAa9ZQ34ZOzP8QiO0yDJfODaqVZj4uWVRIKznD/33ldueGFuzyFqBZxl/xk 0fTShd2cUQqO9Df8iMD/rHUUi2WEkIZrUPrWYFP0n02jM/nNfjKJai1LpadHYBZTtUXF nsyCVIkChF5S1soOjPRZm3spScV1TbnJcQbcWLAvAf1jo7I6P2MAafZUV8K/pJHOBhAY Yjzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ic/jkXaDMCMZefIM+INQtLKGqHBF+RCyVHH3h2YGrKw=; b=Nsedu3ZD90gkcZ23rlk0soD+em+b/0GFvfehRkYnsh7/3p6Wy6kxnulNIte4VHg2HX Q7LXnvZMhRAhdT9vN92NKGV1FJlGaoTDMuR4MB9UH/hjF+I/tQMuglWrMh8LmXR1qwyx lPm4qJa6qTozNeCqFQ8TwyyuUUvq3T+2yGVHI7WzW1Anwo5loN1sXuUHQP81a9IvzxvC p48mTMSMGX3+bKDpla1zrqo2pDzpOKpuFOjCuJ9tWyy/eV1WhmFlUPZqG3EE7urW5H07 OOPNmrXqHMyE0nlumcLZuUj30IwsHECpNI6vUkXxWlP+82jlC7HU6wkR3qzWMUd4MH06 plHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=lOYDkrAg; 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 gn41si13505534ejc.594.2021.10.21.19.10.56; Thu, 21 Oct 2021 19:11:21 -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; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=lOYDkrAg; 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 S232263AbhJVCIs (ORCPT + 99 others); Thu, 21 Oct 2021 22:08:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232179AbhJVCIr (ORCPT ); Thu, 21 Oct 2021 22:08:47 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED253C061348 for ; Thu, 21 Oct 2021 19:06:30 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id y1so1668260plk.10 for ; Thu, 21 Oct 2021 19:06:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ic/jkXaDMCMZefIM+INQtLKGqHBF+RCyVHH3h2YGrKw=; b=lOYDkrAgkjTYYjAVXORDOxu+X2oWJ4E99fQkCZASDeb6Bxv82OEj1GN5FK0PImm5Km 1ndDDD5m1+pbmgSn1SBOKkTkmI7jOGTmPdscGaAxvuyV0qv9zrNHSWWjIacTclp7IP8m blwJCsF1Eav/gdde5L8blmmtrqSfTEaSWkVhkGUJlXUKR5GLx7C9pNVdNuQpKo0hWD5q r1DrR3i3eTnq/y4cVofFTn7yizNn9/14ZJ233lM7YtM+F0dJDENsEyExx68GpuYIW9j3 V12+w1OEyyGSREogPhp1ezeuWIo0c7S25MveUfLpDoYgyADV8XIlq8q5tptjCMaone7i fdWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ic/jkXaDMCMZefIM+INQtLKGqHBF+RCyVHH3h2YGrKw=; b=T+rknxTXTHjLQcTJmpJMABgz97fVVDbtqhFsks6JhO9Z6w/1EO2S78n9FFZXFo9GvP 9S7fHOu9WpSfuNm/JGbo9Bb0EYPso1nX2c5oXQMbYywbg2hzAHleBLYL0TSzk2AnC/p0 rqmRR+9A7X9jZJABP+aHw9qJvVGnSZ7Wok2mezizVPDxHb1yEWPwEuH8s9PH6B/HBqt6 nf/q+Ws599lOShZsqx2LlmYCZ8psL3ICU2vFFR6ne3Vv+ka6ucT/+iXk7a1UEFaJfN8S 6lq8FevSp8OrOFM7kkGKAADw0HPxp82X43qJhu2Y/GohsbDqDhSn92gsN6RiTv5S91qj 7WCw== X-Gm-Message-State: AOAM5326LA7dSHYbq2AojC/jETXyczN4hb8RJE9IRwn4ycgpucJdkdyr BQRVYNBpwsQy+0Qw2K/ZR2on/w== X-Received: by 2002:a17:903:310c:b0:13f:f70e:6e8f with SMTP id w12-20020a170903310c00b0013ff70e6e8fmr7335147plc.82.1634868390409; Thu, 21 Oct 2021 19:06:30 -0700 (PDT) Received: from x1 ([2601:1c2:1080:1950:7c59:380a:adf8:4f49]) by smtp.gmail.com with ESMTPSA id p4sm6260957pgc.15.2021.10.21.19.06.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Oct 2021 19:06:29 -0700 (PDT) Date: Thu, 21 Oct 2021 19:06:27 -0700 From: Drew Fustini To: Emil Renner Berthing 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 Subject: Re: [PATCH v2 12/16] pinctrl: starfive: Add pinctrl driver for StarFive SoCs Message-ID: <20211022020627.GA1836770@x1> References: <20211021174223.43310-1-kernel@esmil.dk> <20211021174223.43310-13-kernel@esmil.dk> <20211021190118.GA1802180@x1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 21, 2021 at 09:50:42PM +0200, Emil Renner Berthing wrote: > 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. Ah, it seems I once knew this back in July [1] but never got the documentation changed: NOTE: Table 12-9 in the JH7100 datasheet is incorrect regarding fields GPIOIE_0 and GPIOIE_1. An interrupt is enabled (unmasked) when the bit is set to 1 and it is disabled (masked) when set to 0. The datasheet incorrectly states the opposite. I think this is due to the datasheet author thinking of it as mask field which it is not, it is an enable field. I will raise an issue on the documentation repo. > > Michael Zhu: Can you confirm if a 1 or 0 enables the interrupt in the > GPIOIE registers? > > /Emil [1] https://github.com/esmil/linux/pull/34/commits/e247a259e40312d0202cdbdd686dbba09afc7813