Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp59546pxb; Wed, 13 Jan 2021 23:17:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJx3A21+9ciJYc+XyxY2CrFN04mutekrur3TD6a37Va/do+yy1Ev+NzD2f3g/c7GUM6mDwyc X-Received: by 2002:a17:906:cd06:: with SMTP id oz6mr4323072ejb.25.1610608627617; Wed, 13 Jan 2021 23:17:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610608627; cv=none; d=google.com; s=arc-20160816; b=UYpd0slphtvIlhJQna4QjO8zVHzQ0/cnTodBZpcKPvqoOz1fA+hQCmwdHAiG14gL+L tW7lWJOx7yMEsXMO4Jb/sj5Ml0yUXIVqqgBW4OmTbAh/7jN8JYWQMRK7gkdM8SSJ6zML uV1cwiD6W7g3/b5dCf+IB0a9hJ9PjEZJ7+wXhujkzMuaFT2644qMsU2xUU9i6KCN5FDE Et1KgbVPzl5rhRmTqgoao2DzkqBWgIajPSfDvX1Vylu1no/jAvrI4JKwhhQP+9gv5Jbd nK0t4dNKaFFj6fc6Vcv5R7cQFwaePlbpA1vnWt9BHv4UMnFPppqHC/+HKQl8LQwXnnO3 ouiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:message-id:date:to:cc:from:subject :references:in-reply-to:content-transfer-encoding:mime-version :dkim-signature; bh=OwRfqD0YnqmsUnmWg+j8CrMA8g6zFsMROmDWudFkMws=; b=xfRan9oqTqjMXFObmO7uRov/js68NmaKqpYo6A+hq1M+emjCwPGFSkxCGNVY2qPzBO Z8fgVKSZq27LpRHCPyf6KyUbrxspzRLhHrPDIhnPcB2KXl5rohFmjPHpXG+ki3qYEUv4 L9F7hrEK6rk4uk1ubx88izkLXwmH3Z+4kPfazHXpABfbVz4Swgn3H10dHZyxgJPojPz1 QF/qwBc0G/z+7/YaQGYTVyB0tRQs+yrurHyxbajqxSX8OLoILgV0EoAdOO5cG6MJ4szf cbNkxEXLNzhZKLW0n+uMJZl79i0vfhw2qMlOhslgiOCAD4Av/BFwrZZE3SNV1tS6nc7k 9KEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="D40JTh/W"; 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 f19si2089438ejf.221.2021.01.13.23.16.44; Wed, 13 Jan 2021 23:17:07 -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="D40JTh/W"; 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 S1726952AbhANHP2 (ORCPT + 99 others); Thu, 14 Jan 2021 02:15:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726131AbhANHP1 (ORCPT ); Thu, 14 Jan 2021 02:15:27 -0500 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17357C061786 for ; Wed, 13 Jan 2021 23:14:47 -0800 (PST) Received: by mail-pf1-x42d.google.com with SMTP id c13so2804023pfi.12 for ; Wed, 13 Jan 2021 23:14:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:content-transfer-encoding:in-reply-to:references :subject:from:cc:to:date:message-id:user-agent; bh=OwRfqD0YnqmsUnmWg+j8CrMA8g6zFsMROmDWudFkMws=; b=D40JTh/WlJbBPmXf9TRmQxsAF37NVHwxgW6GQmhs2RZcMJQE7JMCeP6QlcbZwhSKrn lUBu8F/G0ajDoxVKkovPBbyYKAwdkW/s17EGwF3Li+iho+0WWlBwURfGrCBPnDOeSuWB aPR7+sWByCv3HqqoAqbVlMAgNZGWW08RiQ9mo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:content-transfer-encoding :in-reply-to:references:subject:from:cc:to:date:message-id :user-agent; bh=OwRfqD0YnqmsUnmWg+j8CrMA8g6zFsMROmDWudFkMws=; b=qa9q/hpBV0kISShgfrv2gSKbm88O13hMhE8YnuUMv3pAghM4Sy0KL8uyzpeMHb8qUm sdFBn28hutkASS5+cSzaTHvWIy/NuXzv1btKer1IeiYzEkNbgt3UmVM3BE2z0/Ppi0IX ZA2dt4+qe9oXhGmwRHM1tVhLMyVTAtwHtJRKRCHH8p+HwkwPDI3WE6aef3OxiuI3djFu ocLPHKetaj0cz+V3yhTNA47vCoU3UevMmylPA9FwS1m3gu5aSICSk5f0ftcfmeSh/EMA XnRvYVIO4uMZmCp0GfSxrLpRCpTQd9OHkSJwm6U+l7JyN/Ael+LFfxeEzke5K+m5P/hc ad7Q== X-Gm-Message-State: AOAM533gTPPdDy2Zh0u0DfZGVB0zb0OT9WG7JBpiX+0EyhUC6ZeuBUh9 PI6HJwTqrLc5ePgZhYQ+1sbFYA== X-Received: by 2002:aa7:979d:0:b029:1a4:3b76:a559 with SMTP id o29-20020aa7979d0000b02901a43b76a559mr6122076pfp.49.1610608486387; Wed, 13 Jan 2021 23:14:46 -0800 (PST) Received: from chromium.org ([2620:15c:202:201:3e52:82ff:fe6c:83ab]) by smtp.gmail.com with ESMTPSA id n1sm4329919pfu.28.2021.01.13.23.14.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jan 2021 23:14:45 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <20210108093339.v5.4.I7cf3019783720feb57b958c95c2b684940264cd1@changeid> References: <20210108093339.v5.1.I3ad184e3423d8e479bc3e86f5b393abb1704a1d1@changeid> <20210108093339.v5.4.I7cf3019783720feb57b958c95c2b684940264cd1@changeid> Subject: Re: [PATCH v5 4/4] pinctrl: qcom: Don't clear pending interrupts when enabling From: Stephen Boyd Cc: Bjorn Andersson , Neeraj Upadhyay , Rajendra Nayak , Maulik Shah , linux-gpio@vger.kernel.org, Srinivas Ramana , linux-arm-msm@vger.kernel.org, Douglas Anderson , Andy Gross , linux-kernel@vger.kernel.org To: Douglas Anderson , Jason Cooper , Linus Walleij , Marc Zyngier , Thomas Gleixner Date: Wed, 13 Jan 2021 23:14:44 -0800 Message-ID: <161060848425.3661239.17417977666663714149@swboyd.mtv.corp.google.com> User-Agent: alot/0.9.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Douglas Anderson (2021-01-08 09:35:16) > Let's deal with the problem like this: > * When we mux away, we'll mask our interrupt. This isn't necessary in > the above case since the client already masked us, but it's a good > idea in general. > * When we mux back will clear any interrupts and unmask. I'm on board! >=20 > Fixes: 4b7618fdc7e6 ("pinctrl: qcom: Add irq_enable callback for msm gpio= ") > Fixes: 71266d9d3936 ("pinctrl: qcom: Move clearing pending IRQ to .irq_re= quest_resources callback") > Signed-off-by: Douglas Anderson > --- > diff --git a/drivers/pinctrl/qcom/pinctrl-msm.c b/drivers/pinctrl/qcom/pi= nctrl-msm.c > index a6b0c17e2f78..d5d1f3430c6c 100644 > --- a/drivers/pinctrl/qcom/pinctrl-msm.c > +++ b/drivers/pinctrl/qcom/pinctrl-msm.c > @@ -51,6 +51,7 @@ > * @dual_edge_irqs: Bitmap of irqs that need sw emulated dual edge > * detection. > * @skip_wake_irqs: Skip IRQs that are handled by wakeup interrupt contr= oller > + * @disabled_for_mux: These IRQs were disabled because we muxed away. > * @soc: Reference to soc_data of platform specific data. > * @regs: Base addresses for the TLMM tiles. > * @phys_base: Physical base address > @@ -72,6 +73,7 @@ struct msm_pinctrl { > DECLARE_BITMAP(dual_edge_irqs, MAX_NR_GPIO); > DECLARE_BITMAP(enabled_irqs, MAX_NR_GPIO); > DECLARE_BITMAP(skip_wake_irqs, MAX_NR_GPIO); > + DECLARE_BITMAP(disabled_for_mux, MAX_NR_GPIO); > =20 > const struct msm_pinctrl_soc_data *soc; > void __iomem *regs[MAX_NR_TILES]; > @@ -179,6 +181,10 @@ static int msm_pinmux_set_mux(struct pinctrl_dev *pc= tldev, > unsigned group) > { > struct msm_pinctrl *pctrl =3D pinctrl_dev_get_drvdata(pctldev); > + struct gpio_chip *gc =3D &pctrl->chip; > + unsigned int irq =3D irq_find_mapping(gc->irq.domain, group); > + struct irq_data *d =3D irq_get_irq_data(irq); > + unsigned int gpio_func =3D pctrl->soc->gpio_func; > const struct msm_pingroup *g; > unsigned long flags; > u32 val, mask; > @@ -195,6 +201,20 @@ static int msm_pinmux_set_mux(struct pinctrl_dev *pc= tldev, > if (WARN_ON(i =3D=3D g->nfuncs)) > return -EINVAL; > =20 > + /* > + * If an GPIO interrupt is setup on this pin then we need special > + * handling. Specifically interrupt detection logic will still s= ee > + * the pin twiddle even when we're muxed away. > + * > + * When we see a pin with an interrupt setup on it then we'll dis= able > + * (mask) interrupts on it when we mux away until we mux back. N= ote > + * that disable_irq() refcounts and interrupts are disabled as lo= ng as > + * at least one disable_irq() has been called. > + */ > + if (d && i !=3D gpio_func && > + !test_and_set_bit(d->hwirq, pctrl->disabled_for_mux)) > + disable_irq(irq); Does it need to be forced non-lazy so that it is actually disabled at the GIC? I'm trying to understand how the lazy irq disabling plays into this. I think it's a don't care situation because if the line twiddles and triggers an irq then we'll actually disable it at the GIC in the genirq core and mark it pending for resend. I wonder if we wouldn't have to undo the pending state if we actually ignored it at the GIC forcefully. And I also worry that it may cause a random wakeup if the line twiddles, becomes pending at GIC and thus blocks the CPU from running a WFI but it isn't an irq that Linux cares about because it's muxed to UART, and then lazy handling runs and shuts it down. Is that possible? > + > raw_spin_lock_irqsave(&pctrl->lock, flags); > =20 > val =3D msm_readl_ctl(pctrl, g); > @@ -204,6 +224,20 @@ static int msm_pinmux_set_mux(struct pinctrl_dev *pc= tldev, > =20 > raw_spin_unlock_irqrestore(&pctrl->lock, flags); > =20 > + if (d && i =3D=3D gpio_func && > + test_and_clear_bit(d->hwirq, pctrl->disabled_for_mux)) { > + /* > + * Clear interrupts detected while not GPIO since we only > + * masked things. > + */ > + if (d->parent_data && test_bit(d->hwirq, pctrl->skip_wake= _irqs)) > + irq_chip_set_parent_state(d, IRQCHIP_STATE_PENDIN= G, false); So if not lazy this could go away? Although I think this is to clear out the pending state in the GIC and not the PDC which is the parent. > + else > + msm_ack_intr_status(pctrl, g); > + > + enable_irq(irq); > + } > +