Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1274365pxu; Mon, 23 Nov 2020 16:44:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJwiHMOrBwtMW5kJUhqilGLMh4rZhRLO+YuAc6NOQ3uFtV29H/CEyQcer4gTklLF/H7dElNW X-Received: by 2002:a05:6402:1284:: with SMTP id w4mr1756517edv.324.1606178664629; Mon, 23 Nov 2020 16:44:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606178664; cv=none; d=google.com; s=arc-20160816; b=Wb7HaD3Yo3g/8P8qUx1QQotQ4pFfMnJBTWTmGdFHjsP5II5QPYCjoIG/W1p76X3+w7 vE9nbucNBM++n1qxNwOIbCpSU/IadvdaBPf658ysNOGV9Lz7dV8iO+d4CAyocHq8GMxn 9b21gLhqatrnTmdI0ukbrjowRK+02QqRf+uvPTRuL3saPWxW5feyuuDP12ouXsNcq/ie GJVX8I7fcw8hurCuJML+w8dqISeuFqpmITWBf4C5tTSJgOuUgRrsW3zXU+g1eNEduiUm ORdJKSnojcpsfB7UYc3qhAlCe4oC7sQs7ZzuvELREuKEZJK2h6sYahaJyJBXfyOvITz2 Je5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=dVZAZuhnHNDw7eBlpqaNTuLy1qB5NlqAynArFyBMzdU=; b=WtLbdTrrZJMjLxtSaPKTxvKfzixDpBUE1iXrMsuyRuG7QOKbJofgxWrPsE6k/aCnvd j528EvqbUECtfMXl1vX5KCboST7Em/LYbPWfxoSx5KNPIbQYxT0Tp25y3aUlrmWfNvUj UmmO/gERaICUD879etHv9MJgkq0BNBf7zWtR/D3i9ElV2q5QMNeaHEj+YG5hJr75c0vl 4/bxxCyWQ9mvHDKLcmpXYGP5qhR1a5vxJYPBWkR2CTbjWtAnFUrujRYkXupL9G45UzLe Yd3wH4fGVoNz+AaSw+O5T7IAMjcDUSiVnx/oRBHw4llnR8MOqAlShG3d6aos7J+eF22r E7lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=oMy+quRS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id u4si7362727eja.497.2020.11.23.16.44.01; Mon, 23 Nov 2020 16:44:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=oMy+quRS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728594AbgKXACU (ORCPT + 99 others); Mon, 23 Nov 2020 19:02:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728567AbgKXACT (ORCPT ); Mon, 23 Nov 2020 19:02:19 -0500 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3819CC061A4D for ; Mon, 23 Nov 2020 16:02:19 -0800 (PST) Received: by mail-pg1-x543.google.com with SMTP id v21so15805436pgi.2 for ; Mon, 23 Nov 2020 16:02:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=dVZAZuhnHNDw7eBlpqaNTuLy1qB5NlqAynArFyBMzdU=; b=oMy+quRSFEMEHuIZhuSvFxsJnohoLaGB1uP5Yc2aYTkic1+FuPSrNECJ/ysK1f6gWT ers6BO0+t5vhO1N1mWWI/Weilyqpvb2RNRGU8ocpD7IWHTijus14RXUthJJlRX5ZiOt8 0wb18gTlJlXBwbt2oaLqZ9kgPv/QZWZlenQfM= 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:mime-version :content-transfer-encoding; bh=dVZAZuhnHNDw7eBlpqaNTuLy1qB5NlqAynArFyBMzdU=; b=QKWTjNwleboHSfWCtGLomjfZxdxLiAyCNw/bqY2QSuayeyByIS6poC6m8BoOq4XIgC yDSua9Si0K+tll7/DXdSQDy7nWJ19SxM+fYxbpYSULAAUdHNFAWji1cxwOW9eVnFBjyd 5avcgRqu+rwvInKmgAfd0kYDBE8Y6yIkdfGqLWIvU9FalXVPzo+lOOe584jAN4123vND k+WdwoNJbJJ7POwicIGU6VbHJDQO7/BWxEoL51CFdOFsbZCbdOPx+zA5y4eVnrTNtevQ 9qU2f2ewOijAwrLMjRfzrtFnbsNyGeqPqhtJpkeXbQEg/orTfSta/iNI4lvGE9cZjKn5 UiFw== X-Gm-Message-State: AOAM533IU+ASPPQCf0wUfypYcTDfsK9/2F+fTgAiGyM6q3ycv5dX9XW4 rzgU9P4hr2dMI9cZB1+cx0PdPQ== X-Received: by 2002:a63:215f:: with SMTP id s31mr1567453pgm.258.1606176138623; Mon, 23 Nov 2020 16:02:18 -0800 (PST) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:42b0:34ff:fe3d:58e6]) by smtp.gmail.com with ESMTPSA id l133sm13091945pfd.112.2020.11.23.16.02.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 16:02:18 -0800 (PST) From: Douglas Anderson To: Marc Zyngier , Thomas Gleixner , Jason Cooper , Linus Walleij Cc: Maulik Shah , Srinivas Ramana , Neeraj Upadhyay , Rajendra Nayak , linux-gpio@vger.kernel.org, linux-arm-msm@vger.kernel.org, Bjorn Andersson , Stephen Boyd , Douglas Anderson , Andy Gross , linux-kernel@vger.kernel.org Subject: [PATCH 1/3] irqchip: qcom-pdc: Fix phantom irq when changing between rising/falling Date: Mon, 23 Nov 2020 16:01:51 -0800 Message-Id: <20201123160139.1.I2702919afc253e2a451bebc3b701b462b2d22344@changeid> X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We have a problem if we use gpio-keys and configure wakeups such that we only want one edge to wake us up. AKA: wakeup-event-action = ; wakeup-source; Specifically we end up with a phantom interrupt that blocks suspend if the line was already high and we want wakeups on rising edges (AKA we want the GPIO to go low and then high again before we wake up). The opposite is also problematic. Specifically, here's what's happening today: 1. Normally, gpio-keys configures to look for both edges. Due to the current workaround introduced in commit c3c0c2e18d94 ("pinctrl: qcom: Handle broken/missing PDC dual edge IRQs on sc7180"), if the line was high we'd configure for falling edges. 2. At suspend time, we change to look for rising edges. 3. After qcom_pdc_gic_set_type() runs, we get a phantom interrupt. We can solve this by just clearing the phantom interrupt. NOTE: it is possible that this could cause problems for a client with very specific needs, but there's not much we can do with this hardware. As an example, let's say the interrupt signal is currently high and the client is looking for falling edges. The client now changes to look for rising edges. The client could possibly expect that if the line has a short pulse low (and back high) that it would always be detected. Specifically no matter when the pulse happened, it should either have tripped the (old) falling edge trigger or the (new) rising edge trigger. We will simply not trip it. We could narrow down the race a bit by polling our parent before changing types, but no matter what we do there will still be a period of time where we can't tell the difference between a real transition (or more than one transition) and the phantom. Signed-off-by: Douglas Anderson --- drivers/irqchip/qcom-pdc.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/irqchip/qcom-pdc.c b/drivers/irqchip/qcom-pdc.c index bd39e9de6ecf..7d097164aadc 100644 --- a/drivers/irqchip/qcom-pdc.c +++ b/drivers/irqchip/qcom-pdc.c @@ -159,6 +159,8 @@ static int qcom_pdc_gic_set_type(struct irq_data *d, unsigned int type) { int pin_out = d->hwirq; enum pdc_irq_config_bits pdc_type; + enum pdc_irq_config_bits old_pdc_type; + int ret; if (pin_out == GPIO_NO_WAKE_IRQ) return 0; @@ -187,9 +189,24 @@ static int qcom_pdc_gic_set_type(struct irq_data *d, unsigned int type) return -EINVAL; } + old_pdc_type = pdc_reg_read(IRQ_i_CFG, pin_out); pdc_reg_write(IRQ_i_CFG, pin_out, pdc_type); - return irq_chip_set_type_parent(d, type); + ret = irq_chip_set_type_parent(d, type); + + /* + * When we change types the PDC can give a phantom interrupt. + * Clear it. Specifically the phantom shows up if a line is already + * high and we change to rising or if a line is already low and we + * change to falling but let's be consistent and clear it always. + * + * Doing this works because we have IRQCHIP_SET_TYPE_MASKED so the + * interrupt will be cleared before the rest of the system sees it. + */ + if (old_pdc_type != pdc_type) + irq_chip_set_parent_state(d, IRQCHIP_STATE_PENDING, 0); + + return ret; } static struct irq_chip qcom_pdc_gic_chip = { -- 2.29.2.454.gaff20da3a2-goog