Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3915950imm; Mon, 8 Oct 2018 11:37:58 -0700 (PDT) X-Google-Smtp-Source: ACcGV60jDroPQTNypL7URIqhpQXQozSMa8gVBkpGhJJaz5y93JclkYkCEhUjWTzGYnShsSo2DXnC X-Received: by 2002:a63:2c8a:: with SMTP id s132-v6mr21648001pgs.73.1539023878627; Mon, 08 Oct 2018 11:37:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539023878; cv=none; d=google.com; s=arc-20160816; b=BT3U0o3hvs7dO/yVRsY62w05rwy1Ws8eLn7s+sXq6jTUATdM+pS8gtZJ7EKwCtB498 jYKClV7ByMDiThw0tMxi0Xp79UvA1qhQ9uyoevraUnMrAvJhVEUwvF8wH9ideFbFpqIq Y8MOejuSI2Yw307jxPx6GMl3Hzq6jRNQUo9GbC/AUtQe13ExKx29ms1/UvaVKMW66xhW y6IbyOsR99wtJt0WJRh356cpOFmpJ8tnsDq4zJY2M48TAwP4l1sTdIAaytQw3ipaCnaN uZIQL6RXkIImqpoCTF1CXTQwfMotuGh3umM/EuGSXUDUbovkdYHvD5U8eg6NGvH6yHYJ Uigg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2zYrdmtlHe0TZoFc7KKxKgF72mOEMfc8+SqjtAVs9/A=; b=vEFVJ/Lg8+v8i/VR/Nln6yanHkUeGMn0wAXdX3om11vg8/KhfFNrVTHQyelP8965EE Ex9XfBCcI7D3ZJgsTG+ORSfRBt39ovvgo0O37FXplzp4oD/Iod71tRxtknxJStTWsnlu rhv2Kk1+MOQkMCVkEm3YUyq2IqWtimMcUyGE/BzMRJCM5Yfwb+bjC3RQph2JrEYuyWtt ObtOnuiePKU3cUKhBI8fXVT1mEsQeIwVtSVaY3AAs4GDDvf6aUACKEp6uAymk7nHmn4E 9TcEi6LBXVW/7cFu1/CFacdPTu0f4oiIGaGC3oF5OluZ0Nv7+BD+ItIikXG4y79aKhjX 33ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Hp0/otqJ"; 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 64-v6si19706732pft.177.2018.10.08.11.37.43; Mon, 08 Oct 2018 11:37:58 -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=@kernel.org header.s=default header.b="Hp0/otqJ"; 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 S1728736AbeJIBt4 (ORCPT + 99 others); Mon, 8 Oct 2018 21:49:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:35502 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726958AbeJIBt4 (ORCPT ); Mon, 8 Oct 2018 21:49:56 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3BD712064A; Mon, 8 Oct 2018 18:36:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539023812; bh=OqqoSVfa8gdx3SKyGl79WrQNR8YrG8WBk0rrx98J6FM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hp0/otqJIgactjRfdziTE0+eaJryYZ8rHFoZreA/JkFZ8vqqkFRhpDwV3O0TJF+ys hYunWsxhgy+VXN1UTkKKorpNNivZYnfDeBIv6FNGS/fmqNnXzCVQpJKk0qviD3k8VQ WNQJzzqEYBt/wD4Xgv2mnDWUd/XcyUqkwwzZZSeI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephen Boyd , Douglas Anderson , Bjorn Andersson , Linus Walleij , Sasha Levin Subject: [PATCH 4.4 093/113] pinctrl: msm: Really mask level interrupts to prevent latching Date: Mon, 8 Oct 2018 20:31:34 +0200 Message-Id: <20181008175536.405502473@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008175530.864641368@linuxfoundation.org> References: <20181008175530.864641368@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Stephen Boyd [ Upstream commit b55326dc969ea2d704a008d9a97583b128f54f4f ] 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. Signed-off-by: Stephen Boyd Reviewed-by: Douglas Anderson Reviewed-by: Bjorn Andersson Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/pinctrl/qcom/pinctrl-msm.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) --- a/drivers/pinctrl/qcom/pinctrl-msm.c +++ b/drivers/pinctrl/qcom/pinctrl-msm.c @@ -577,6 +577,29 @@ static void msm_gpio_irq_mask(struct irq 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); @@ -598,6 +621,7 @@ static void msm_gpio_irq_unmask(struct i 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);