Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2650573imm; Thu, 16 Aug 2018 13:09:21 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyib2bqb80SCaSadOiUzH2lwySeA63eF8fA0hgys5Dpn/NPcf4XKnCUyS1VX4Ct6nIJomSc X-Received: by 2002:a63:c608:: with SMTP id w8-v6mr30210412pgg.16.1534450161831; Thu, 16 Aug 2018 13:09:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534450161; cv=none; d=google.com; s=arc-20160816; b=q/3TxRhA9giRBRAm769OvnFNOotqbXQmxhTqellefM6zjQvEMdwfkVOjUrteNLWGAQ 5zuSU1e5JfFInWBVXxkc/agF7N6nWdYXjP/4f42BxxzfD3vtkdmFAC0O/0QyNW9/WRMs qZb84zpIhhHXK9gMvV3WDnAZnarQsm/hUbBn0b4x2uIh+lheL9I7aUWIot/2RChqhpx8 AQa0jyKAVD3TtQjI2rlBa2hC5Xn1GU06NHoQQhIP/6+foJfZHSrNoM8jwBzxqNXY1Yak ttBB3dFP2FY4ZhhE1P3wTdSibm6toQ/whZz63SqL3/342hw59lo3rYLqdwL8Tjoai4Du nUcA== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=YbEgU6NoCTKY3cxZJBhRAPLasbYsKrPISCc9HR3/AbY=; b=EpUIvsHCaYU8+k6QdKWZq6N31rWeVWBWuOJqDpCCq61IpUtuTUKqvlNWtdkD14wqQ2 Yhu60kNyZa1VkoDfj+EnXHLkjf8X9g4eFn5KcwNtkHsuUZPiV6YkGaqXWQPJgCGHoOby YM8MPzYyAuyIuWC93cTMCigyzySe5OyvuFgKOhcTaHMd0Bm511xhSCZzNvAu3ocpsce8 lF9izJ/a/k9sP9x5MonnPEhCKzPCA2sy4bEfJdMUrF1WPcPTxOijgeY43c1bYxgR4Fbx 5UEmXAdcO5MkJYk/9LCIekUm1Ngo88E4fUxXpvkI3QF4ifdpkRPeww5oxaEOAgnSE8NL XMCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=h+Vhk2tE; 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=REJECT sp=REJECT 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 t16-v6si194395pga.442.2018.08.16.13.09.07; Thu, 16 Aug 2018 13:09:21 -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=h+Vhk2tE; 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=REJECT sp=REJECT dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726133AbeHPXHT (ORCPT + 99 others); Thu, 16 Aug 2018 19:07:19 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:32930 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725783AbeHPXHT (ORCPT ); Thu, 16 Aug 2018 19:07:19 -0400 Received: by mail-pg1-f196.google.com with SMTP id r64-v6so1369802pgr.0 for ; Thu, 16 Aug 2018 13:06:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YbEgU6NoCTKY3cxZJBhRAPLasbYsKrPISCc9HR3/AbY=; b=h+Vhk2tEsYo3goR0+igWXENVwiGtm4Gs/UC2MQQBjDLZyCUWBgPNgkASxwrbXFN2iX JrRSYFqywZn9pXx1eMMDn87XJPC1tYb9NsxSep0bBOXuyICT20/lwzPcVh3op3UtzBUd giXD35ZtPGlyxvF+fqzwlWus+V2kJ1chErYkE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YbEgU6NoCTKY3cxZJBhRAPLasbYsKrPISCc9HR3/AbY=; b=mYmGCC4JPgZzdA7xJn+1OtCfRDpyYPXGFrlHaX5BEcDDwT+06hyiFX7qvDSBf42zjc qb0yZAXjLawF/B+KhGDe8nAT+xbzsU/mKV9EsiXenqqlvbZ0MKNMx76VfQ8BCWskVmVy 06czatH2NWz8jEYUht/pZUUGz6Zf7tLG66Ho2RpD3f8MUKOZcsweDHALdIiRxgojhmma vCFVSUtIGvvxTQCsSHhSkZyjl9cCJJoNZpqF2YcEWZHq748pddHeR+Wo2078V8LKGK9k 19MidV6eRsOVCrVcOe5fYF6FT1TzcdYvjRHT/h5vsZ8E/HoRzxtE2t1lrTqguyjFfvKV GHMg== X-Gm-Message-State: AOUpUlEecqJP6kI+nhmQdOFGUx2FBQzHFjdMVEOaUaZXsyMA0BnekOh6 +5mBW0roRXysHTyf3XaXhKrJ3g== X-Received: by 2002:a65:6455:: with SMTP id s21-v6mr184200pgv.25.1534450010878; Thu, 16 Aug 2018 13:06:50 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:201:7e28:b9f3:6afc:5326]) by smtp.gmail.com with ESMTPSA id v6-v6sm234958pfa.28.2018.08.16.13.06.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Aug 2018 13:06:50 -0700 (PDT) From: Stephen Boyd To: Linus Walleij Cc: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linux-arm-msm@vger.kernel.org, Bjorn Andersson , Doug Anderson Subject: [PATCH v3 1/3] pinctrl: msm: Really mask level interrupts to prevent latching Date: Thu, 16 Aug 2018 13:06:46 -0700 Message-Id: <20180816200648.90458-2-swboyd@chromium.org> X-Mailer: git-send-email 2.18.0.865.gffc8e1a3cd6-goog In-Reply-To: <20180816200648.90458-1-swboyd@chromium.org> References: <20180816200648.90458-1-swboyd@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The interrupt controller hardware in this pin controller has two status enable bits. The first "normal" status enable bit enables or disables the summary interrupt line being raised when a gpio interrupt triggers and the "raw" status enable bit allows or prevents the hardware from latching an interrupt into the status register for a gpio interrupt. Currently we just toggle the "normal" status enable bit in the mask and unmask ops so that the summary irq interrupt going to the CPU's interrupt controller doesn't trigger for the masked gpio interrupt. For a level triggered interrupt, the flow would be as follows: the pin controller sees the interrupt, latches the status into the status register, raises the summary irq to the CPU, summary irq handler runs and calls handle_level_irq(), handle_level_irq() masks and acks the gpio interrupt, the interrupt handler runs, and finally unmask the interrupt. When the interrupt handler completes, we expect that the interrupt line level will go back to the deasserted state so the genirq code can unmask the interrupt without it triggering again. If we only mask the interrupt by clearing the "normal" status enable bit then we'll ack the interrupt but it will continue to show up as pending in the status register because the raw status bit is enabled, the hardware hasn't deasserted the line, and thus the asserted state latches into the status register again. When the hardware deasserts the interrupt the pin controller still thinks there is a pending unserviced level interrupt because it latched it earlier. This behavior causes software to see an extra interrupt for level type interrupts each time the interrupt is handled. Let's fix this by clearing the raw status enable bit for level type interrupts so that the hardware stops latching the status of the interrupt after we ack it. We don't do this for edge type interrupts because it seems that toggling the raw status enable bit for edge type interrupts causes spurious edge interrupts. Cc: Bjorn Andersson Cc: Doug Anderson Signed-off-by: Stephen Boyd --- drivers/pinctrl/qcom/pinctrl-msm.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/pinctrl/qcom/pinctrl-msm.c b/drivers/pinctrl/qcom/pinctrl-msm.c index 2155a30c282b..5d72ffad32c2 100644 --- a/drivers/pinctrl/qcom/pinctrl-msm.c +++ b/drivers/pinctrl/qcom/pinctrl-msm.c @@ -634,6 +634,29 @@ static void msm_gpio_irq_mask(struct irq_data *d) raw_spin_lock_irqsave(&pctrl->lock, flags); val = readl(pctrl->regs + g->intr_cfg_reg); + /* + * There are two bits that control interrupt forwarding to the CPU. The + * RAW_STATUS_EN bit causes the level or edge sensed on the line to be + * latched into the interrupt status register when the hardware detects + * an irq that it's configured for (either edge for edge type or level + * for level type irq). The 'non-raw' status enable bit causes the + * hardware to assert the summary interrupt to the CPU if the latched + * status bit is set. There's a bug though, the edge detection logic + * seems to have a problem where toggling the RAW_STATUS_EN bit may + * cause the status bit to latch spuriously when there isn't any edge + * so we can't touch that bit for edge type irqs and we have to keep + * the bit set anyway so that edges are latched while the line is masked. + * + * To make matters more complicated, leaving the RAW_STATUS_EN bit + * enabled all the time causes level interrupts to re-latch into the + * status register because the level is still present on the line after + * we ack it. We clear the raw status enable bit during mask here and + * set the bit on unmask so the interrupt can't latch into the hardware + * while it's masked. + */ + if (irqd_get_trigger_type(d) & IRQ_TYPE_LEVEL_MASK) + val &= ~BIT(g->intr_raw_status_bit); + val &= ~BIT(g->intr_enable_bit); writel(val, pctrl->regs + g->intr_cfg_reg); @@ -655,6 +678,7 @@ static void msm_gpio_irq_unmask(struct irq_data *d) raw_spin_lock_irqsave(&pctrl->lock, flags); val = readl(pctrl->regs + g->intr_cfg_reg); + val |= BIT(g->intr_raw_status_bit); val |= BIT(g->intr_enable_bit); writel(val, pctrl->regs + g->intr_cfg_reg); -- Sent by a computer through tubes