Received: by 10.192.165.148 with SMTP id m20csp3594944imm; Mon, 7 May 2018 15:15:59 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoWjcDg5lyv68NyuS5/1LlPam0CctA7iZ1GXdwPRv2MFPWvO8MFA0oEingl57LtyzjF9QdQ X-Received: by 10.98.11.210 with SMTP id 79mr37519902pfl.4.1525731359608; Mon, 07 May 2018 15:15:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525731359; cv=none; d=google.com; s=arc-20160816; b=EX8r+9SNoRv416sdJu3LDdfukOg9rS5z+k7JauzMvgDFZtarHtMLbdl9dvBDxPjY3L ewQNKGOQvJPXUWHjjA/rjpzTuqohPxMmFfAHqqsCP1xu6efG910aUlYrO7uKLYHzk35s V+QNcdujk7y3yLJcChFbFLMB2NJhk9JbQZlzwlK86/UZOuul50vdE2ClYYgHe/hEevSq 88KgXvBPpGbmTnR8etawczxt+qFoOar3ikp0KbIDL852m0ijK6IWP69b/I6M0F1Qmxy0 sMSyAGRFztonTiqcAppokV5au/BKaLBRDj+33WukqzNiT6N9oYo3zzYEvJZzGZ/+46sM +G6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=iHTRzQEKa2zN1B57egZZ82+3K/6rN/6KeouGlr0k+Gg=; b=aIkURbFs2LemePF8NhXHEGI0dpneWVj2FSbIbnQETTGJKmDAi3BdezKVY0wu5O+7lP Tr7ZBZ51eHSkIkYX0LR2hrGyGKnk/2VjsErS0QcukWBFh+6ht+Qw1A1+lp6p7P1v+Ys3 4Ju4XnuBbXnHrnw7ioAKkecPvFbeU+XPxh1ReNZQF1wU1rUSRXuJZmjm6CMBG6/53GJe /yPNc+BINW+qmUAYDDEVuAUe0IMwlhcYcGCN3CfTNx2kBpwHJKMinFt0dhAipTpfAYmG GhN8qQtFnnvlAakrnqbtFiyPl85R3m6hCmMqbiOuyG8xKVh/pS3J/UgpPOI7OSmizoKM v5Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KWjZwWQW; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u13-v6si11714388plq.161.2018.05.07.15.15.45; Mon, 07 May 2018 15:15:59 -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=@chromium.org header.s=google header.b=KWjZwWQW; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753065AbeEGWPR (ORCPT + 99 others); Mon, 7 May 2018 18:15:17 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:40241 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752726AbeEGWPP (ORCPT ); Mon, 7 May 2018 18:15:15 -0400 Received: by mail-pl0-f66.google.com with SMTP id t22-v6so953559plo.7 for ; Mon, 07 May 2018 15:15:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=iHTRzQEKa2zN1B57egZZ82+3K/6rN/6KeouGlr0k+Gg=; b=KWjZwWQWcwJLPWgxpWw9/1A5/T3LnCeqD8NvLc0zIkSwnv37KY3g++OIuoxQVbM5qM Hv1qsm3XAXPbMbulPeZiSPZu164/Wqc8JqLjWkQygjZkzuwkyJC0k9g6kFl5ocQhuBe8 uZdjQgMuiAYnz8Jre8AlvIeiVsneWv/dufV7w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=iHTRzQEKa2zN1B57egZZ82+3K/6rN/6KeouGlr0k+Gg=; b=iHTz2Ua9ytdsNyg6OQlcmNRyOoVJgqxzH7WRhWoA75/y5IPUlIBrLDJ+e8MpAlytQ/ dw7BT+kmpKA4DzrqLdtw34YiHmohRXHRXhE0BRRTE8UXNUTyaHeJbx8s87etu1V2pJW0 vVFbnIB2g9GMLuop7YDGV2Ti0c/LDrs5cOmhbuS2rJA7Awba7d6HroUaZpnDLYgQLA7I QKD8M3EFWUkQAgIjhp7jLLwnlUv3ZhM+O+SLLzB3RtH9r5zHXCXG5fWrRIxyNHEvX803 1C2ooF6R8jKQ5FK99Zhbe0N1tiNjA525jvsffn+hu7YPTPIridD8jt8ijJTd8EkvLSvi oyXw== X-Gm-Message-State: ALQs6tBjLv4JBjWdSmw5pz3tzSaPnDnTwt9skJPOEflKFxQ/GkwckS48 B/whVaJL7WhzaX0mISFhz2K+3g== X-Received: by 2002:a17:902:362:: with SMTP id 89-v6mr39661465pld.270.1525731314867; Mon, 07 May 2018 15:15:14 -0700 (PDT) Received: from rodete-desktop-imager.corp.google.com ([2620:0:1000:1501:bc2f:3082:9938:5d41]) by smtp.gmail.com with ESMTPSA id k186sm55984533pfc.142.2018.05.07.15.15.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 May 2018 15:15:14 -0700 (PDT) Date: Mon, 7 May 2018 15:15:12 -0700 From: Brian Norris To: Jeffy Chen Cc: linux-kernel@vger.kernel.org, heiko@sntech.de, linux-rockchip@lists.infradead.org, Linus Walleij , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Doug Anderson Subject: Re: [RESEND PATCH] pinctrl: rockchip: Disable interrupt when changing it's capability Message-ID: <20180507221511.GA6448@rodete-desktop-imager.corp.google.com> References: <20180503065553.7762-1-jeffy.chen@rock-chips.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180503065553.7762-1-jeffy.chen@rock-chips.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org + Doug Hi Jeffy, On Thu, May 03, 2018 at 02:55:53PM +0800, Jeffy Chen wrote: > We saw spurious irq when changing irq's trigger type, for example > setting gpio-keys's wakeup irq trigger type. > > And according to the TRM: > "Programming the GPIO registers for interrupt capability, edge-sensitive > or level-sensitive interrupts, and interrupt polarity should be > completed prior to enabling the interrupts on Port A in order to prevent > spurious glitches on the interrupt lines to the interrupt controller." > > Reported-by: Brian Norris > Signed-off-by: Jeffy Chen > --- > > drivers/pinctrl/pinctrl-rockchip.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c > index 3924779f55785..7ff45ec8330d1 100644 > --- a/drivers/pinctrl/pinctrl-rockchip.c > +++ b/drivers/pinctrl/pinctrl-rockchip.c > @@ -2727,9 +2727,19 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type) > return -EINVAL; > } > > + /** The typical multiline comment style is to use only 1 asterisk -- 2 asterisks usually denote something more formal, like kerneldoc. > + * According to the TRM, we should keep irq disabled during programming > + * interrupt capability to prevent spurious glitches on the interrupt > + * lines to the interrupt controller. > + */ It's also worth noting that this case may come up in rockchip_irq_demux() for EDGE_BOTH triggers: /* * Triggering IRQ on both rising and falling edge * needs manual intervention. */ if (bank->toggle_edge_mode & BIT(irq)) { ... polarity = readl_relaxed(bank->reg_base + GPIO_INT_POLARITY); if (data & BIT(irq)) polarity &= ~BIT(irq); else polarity |= BIT(irq); writel(polarity, bank->reg_base + GPIO_INT_POLARITY); AIUI, this case is not actually a problem, because this polarity reconfiguration happens before we call generic_handle_irq(), so the extra spurious interrupt is handled and cleared after this point. But it seems like this should be noted somewhere in either the commit message, the code comments, or both. On the other hand...this also implies there may be a race condition there, where we might lose an interrupt if there is an edge between the re-configuration of the polarity in rockchip_irq_demux() and the clearing/handling of the interrupt (handle_edge_irq() -> chip->irq_ack()). If we have an edge between there, then we might ack it, but leave the polarity such that we aren't ready for the next (inverted) edge. I'm not 100% sure about the above, so it might be good to verify it. But I also expect this means there's really no way to 100% reliably implement both-edge trigger types on hardware like this that doesn't directly implement it. So I'm not sure what we'd do with that knowledge. > + data = readl(bank->reg_base + GPIO_INTEN); > + writel_relaxed(data & ~mask, gc->reg_base + GPIO_INTEN); Not sure if this is a needless optimization: but couldn't you only disable the interrupt (and make the level and polarity changes) only if the level or polarity are actually changing? For example, it's possible to end up here when changing from EDGE_BOTH to EDGE_RISING, but we might not actually program a new value. Brian > + > writel_relaxed(level, gc->reg_base + GPIO_INTTYPE_LEVEL); > writel_relaxed(polarity, gc->reg_base + GPIO_INT_POLARITY); > > + writel_relaxed(data, gc->reg_base + GPIO_INTEN); > + > irq_gc_unlock(gc); > raw_spin_unlock_irqrestore(&bank->slock, flags); > clk_disable(bank->clk); > -- > 2.11.0 > >