Received: by 10.192.165.148 with SMTP id m20csp3738567imm; Mon, 7 May 2018 18:38:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZogyEc1QVBmlSvf4BYQjw2bkOEsm0Nv6zL93FjzSHsfLVOIMcahgtv7AnTA3krirbCvFA6G X-Received: by 2002:a65:6395:: with SMTP id h21-v6mr4809100pgv.267.1525743537955; Mon, 07 May 2018 18:38:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525743537; cv=none; d=google.com; s=arc-20160816; b=f2p61ucHLOrqCWt+qhoc11q/m520gETLrU/Pku+F9mSDlCesA5bqlflaYeB/OwtWx+ C6WkoXEJ7S67h7931L/2F3w8L4CzE6RwTi9VKWf/94+UAsyMgDZznUm3en4rx6A5zO3D VtCWHEosAMJN9RiPvY5tzYUFLxaFExnYisTUsCtV9oU0X029sPesLddEwXYWHBMrey2U eIVMakgILHf5fckW3NPVqdmnf7xbRyhPLnhw4GNVzqCkRZ49OuVFW4TEo106H0Fx1/Fy gsmO5gjSg36KY1u6DGCMr/F752UqON1qpBHSZiU03pyp0UGFfpSBfhG+8VQqfkUvpQkH Y1fw== 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:in-reply-to :references:subject:cc:to:mime-version:user-agent:from:date :message-id:arc-authentication-results; bh=+6h6BzuQNX98b+BQOyDqYCs1wll/Hh57wmiq5BEK2jI=; b=VbKtXuDqgn1u1gylmON8zgelALZKwmgYfEeaJ4khc+3upLvEdPsTaDFWqoxO/1K/m5 pgDrcJAQfk4c1ZjOR3tXIk/MSP9OiycwP+Mq9At4hbfZQfT5cOQxZ7eMWpvt9Yl3hAAV 7cfKNG4mnvqcvQGe55fPE4Gu7tftRdQzxPGXwmjW3MDRCTjC2OzdDaSOvV1uOd+qtv9/ O/XjEQBHm47bR1HDpzBuBr6mYuz4i91WiOM75nW0hHjVZiOrtn3EUzZs6zMMOCQ/Ak+v xx9ZFpUdZUBSXX5ffIpgrYs0d2ql1ueKJBhi4Z7IlFrRRRT+sEasbQI+3mVDmzN2m0Tw HIwQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u6si11886804pfm.183.2018.05.07.18.38.43; Mon, 07 May 2018 18:38:57 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753833AbeEHBgu (ORCPT + 99 others); Mon, 7 May 2018 21:36:50 -0400 Received: from regular1.263xmail.com ([211.150.99.134]:59802 "EHLO regular1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753442AbeEHBgd (ORCPT ); Mon, 7 May 2018 21:36:33 -0400 Received: from jeffy.chen?rock-chips.com (unknown [192.168.167.11]) by regular1.263xmail.com (Postfix) with ESMTP id 07C2E9162; Tue, 8 May 2018 09:36:29 +0800 (CST) X-263anti-spam: KSV:0;BIG:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ADDR-CHECKED4: 1 X-ABS-CHECKED: 1 X-SKE-CHECKED: 1 X-ANTISPAM-LEVEL: 2 Received: from [172.16.22.179] (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTPA id E9BED3AF; Tue, 8 May 2018 09:36:26 +0800 (CST) X-IP-DOMAINF: 1 X-RL-SENDER: jeffy.chen@rock-chips.com X-FST-TO: briannorris@chromium.org X-SENDER-IP: 103.29.142.67 X-LOGIN-NAME: jeffy.chen@rock-chips.com X-UNIQUE-TAG: <9214384948890b49698780a307ec475f> X-ATTACHMENT-NUM: 0 X-SENDER: cjf@rock-chips.com X-DNS-TYPE: 0 Received: from [172.16.22.179] (unknown [103.29.142.67]) by smtp.263.net (Postfix) whith ESMTP id 15819AJLH6K; Tue, 08 May 2018 09:36:29 +0800 (CST) Message-ID: <5AF0FF18.1050905@rock-chips.com> Date: Tue, 08 May 2018 09:36:24 +0800 From: JeffyChen User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:19.0) Gecko/20130126 Thunderbird/19.0 MIME-Version: 1.0 To: Brian Norris 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 References: <20180503065553.7762-1-jeffy.chen@rock-chips.com> <20180507221511.GA6448@rodete-desktop-imager.corp.google.com> In-Reply-To: <20180507221511.GA6448@rodete-desktop-imager.corp.google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Brian, On 05/08/2018 06:15 AM, Brian Norris wrote: > + 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. ok, will fix it. > >> + * 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. just from my testing, the spurious irq only happen when set EDGE_RISING to a gpio which is already high level, or set EDGE_FALLING to a gpio which is already low level.so the demux / EDGE_BOTH seem ok. but adding comments as your suggested is a good idea, will do that. > > 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. if let me guess, the unexpected irq we saw is the hardware trying to avoid losing irq? for example, we set a EDGE_RISING, and the hardware saw the gpio is already high, then though it might lost an irq, so fake one for safe? i'll try to confirm it with IC guys. > > 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. right, i noticed that too, will add a patch for that in v2. > > 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 >> >> > > >