Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3938019imm; Mon, 8 Oct 2018 12:00:35 -0700 (PDT) X-Google-Smtp-Source: ACcGV63NHcQnHawQP5V2800mgxyU4mUCKLvEla1QLbM1MOqlpTeqKO+41XZJ72znGSWgcsk53kRr X-Received: by 2002:a63:2587:: with SMTP id l129-v6mr13159128pgl.382.1539025235798; Mon, 08 Oct 2018 12:00:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539025235; cv=none; d=google.com; s=arc-20160816; b=yTzUMd3SZPpSp9oYDuzTGQi2JwSeVSd/O/WOQvTQQj4VLLfs+MFejqH2Isp8sNcorw fUlWOCjjxO8+cq2LG7eh6WLJfeOS4UZuyW154o8MDN/bNsdZC5iV4Rb/pkJ8u6xkN8Ec D6ZkejwdrI2NeeXIJu8+GiAWgc4vFa75bY6mp+V61Y/4ogcvE5FXzWcPB/+o4i21dII4 ceRF4GsDodLoWiI7Bnbf20bvQmRqrwKCpFj58cefHdmdfJxvPTbjiMo0LgJNjdeUnQKh 37tFs/9HkJ4RLl8Q3u/7u52v3gMyMuACAGnCwH/ZyI0RvLRi3EsXzt6gSv7dRBs6tL6q J3eQ== 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=OFK9qhe7F4Zx+H+9jFk0YTfMiw+uLazRDpn/FLZgwKE=; b=RwGr6apHLC1COpWHhWvgn4fHAot79u3QUFohv1FhptFk4yghk3DoUXVv5qvsCJztGd OTBEhe4kPI/xmUAjqDUSfUuDWCr2Vp/rcKJA3XJw117w5EFiRZCaFu3UbOvqXRP7sgEX Vd44WShb5PtKGUlVLhoUGHvaAul2+wRfUOkuydQVvU+LbtEh2OMuKq+7fWl07XkqGEIw tBR27RCYM6CWwqxo7Mrgdqnpsli3YxKmnIxb+1A4MC+bfZ3thiFKvkLf3HZXRnrXhn6H 9ZgD4R1U+EBFnJ1SWPKt/O2K3ZfHKeBTuLW8GvXGK1sxf4tLEpd7WVLAy0jQM/7FuG2I l1qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1k9qcpnq; 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 k20-v6si17985851pgm.574.2018.10.08.12.00.20; Mon, 08 Oct 2018 12:00:35 -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=1k9qcpnq; 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 S1731901AbeJICCm (ORCPT + 99 others); Mon, 8 Oct 2018 22:02:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:52014 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730559AbeJICCl (ORCPT ); Mon, 8 Oct 2018 22:02:41 -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 F30D4204FD; Mon, 8 Oct 2018 18:49:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539024573; bh=0EmPAyTQQfZfXNW4SHgv98Rgq0zPtoZZfvU8fIf0egY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1k9qcpnqlgyEYT0Swf4yME+KGzbPfW6LOKBQaTATM1MuYoHKtBUtgRDV8j3b/xrAu dES0j6omXfXcvyi68OrHvPEtBal95Z2hhWhpbM1NkUWrACm0n2RhHEh3DYSwPQicfv WWOFZuqUerDhFdgRVU9xdIDDWCzGhHjlvQGhiC4w= 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.18 084/168] pinctrl: msm: Really mask level interrupts to prevent latching Date: Mon, 8 Oct 2018 20:31:04 +0200 Message-Id: <20181008175623.254740657@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008175620.043587728@linuxfoundation.org> References: <20181008175620.043587728@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.18-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 @@ -634,6 +634,29 @@ static void msm_gpio_irq_mask(struct irq 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 i 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);