Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp432487pxb; Thu, 14 Jan 2021 09:17:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJxOL2+VspuhCLz49UkVpa2uQIWcFXnHr/6vn/PQ/dhEUg9d7keyfCEDaUsmh10al8OknVjs X-Received: by 2002:a17:906:f0d0:: with SMTP id dk16mr5952079ejb.144.1610644655171; Thu, 14 Jan 2021 09:17:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610644655; cv=none; d=google.com; s=arc-20160816; b=i0rIYF2u9Etw2KIpGxa7Lvp7buO+J6tT3Ns/5mNHBbi+q7eAoGKcNBCG/ekQqJdqQe MqvAjXbXXgT19sj0QWqPbszBuMian2u9jDrIwq/1ussxdk+U2chZefK5V3kJ7K2tt4IU xRbqj6LLcPMyw3YZefI78RDe8NMsK3F8jpw0ZmWbjtkqd14JYufzxfGsP8MF8FOKtA/J 97NLKLnHODydtpyUHrRs7z3E96Q5lxKDWYf4vDjPnFOAZDpOPM2OmsSWpSU3/H0Wfa3c 7ZfebJl2kCW8IeZfAAv/JMKwEj8Jlmaz/CV9RBKYE/4N5AdMklqTk2snCSR2OtANerS2 4ZJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=qaFSjFq15gJ5kL5BciOwoue8YB8M48nAYhLQvOFNNhY=; b=v6QiUlTn+/ZcD9FgysIwJlV4rRK1V2vmMsLJTLoRg3tARciKiczCoXvK+5JCTkq6sa uE8obHgL2YFH9dwDmk1RMWebaHIsPxmmWRmO9aSz1huwwrRr3S0+n3924T4L80O/yEeE 88oEDLXn+fbH2QoMBgMOSfDrnjdV2VBKD/DKQZqBYGqC62Wo/OS+ZVzG5AaBMKE28GS4 R4EfeiaEGBtBjoDCcBKmLjCGsTEDIWbpZL6jPdSwjOXQtKab7ZIGRRuOrhycwl5k3BH1 cc+TEKDot/8UpRiDaSqKF1FINhBTFADIupt4w9C/ciAtJQ46d1ec3XwsuTyK9hoqlPh1 r2Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h1gf3Ri9; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t21si2628526ejf.648.2021.01.14.09.17.10; Thu, 14 Jan 2021 09:17:35 -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=@linaro.org header.s=google header.b=h1gf3Ri9; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728935AbhANRPw (ORCPT + 99 others); Thu, 14 Jan 2021 12:15:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728926AbhANRPv (ORCPT ); Thu, 14 Jan 2021 12:15:51 -0500 Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B74DAC0613D3 for ; Thu, 14 Jan 2021 09:15:10 -0800 (PST) Received: by mail-ot1-x334.google.com with SMTP id a109so5883099otc.1 for ; Thu, 14 Jan 2021 09:15:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=qaFSjFq15gJ5kL5BciOwoue8YB8M48nAYhLQvOFNNhY=; b=h1gf3Ri9zlYKv1/Pt/v3LUg3++8O2s/1Owo9/GL5iV43s6JCbl8Eu56f0hAJ2/mtE2 K8wSgsL1ZHfGgsp7zJV+74crDethx3ZUxCU39jxneEI2O5ZN+t6FwbwmeDtL9jGw1GpZ 2YxuM1mOAlpEgYbzcQhZ8RsYW2WkF1GyqXweLV4jnDt0xX/OChXm34qAavAz11EbOtxN XbAJzG1sICY3TmuIH7hooetViHHwkS8yj7DHGxwUbRJ/xS1im5VjeD5EufJOaC8YE2Nd ifpiyQTkPWd8A8OhQ0AO7GpdnL+Dx9jJmvPuBv/bHU2xkTN7qosp16mFaoCHsxJ3cVm8 QDmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=qaFSjFq15gJ5kL5BciOwoue8YB8M48nAYhLQvOFNNhY=; b=jg4pedjAFd+cOfgE47Yrn07FGzqyaucowAENkE61JSr/sdcPcnDpqFPOBTaJCURh9v nPChbcrixXHXjA6uljqNOIExt2CA8CwWFgs+EjDbUqcUvOWsbCFO+3HZq0+RSw5oXap3 IOVU33NGc9vspDT4wWJs0ErtRm1YF0zsN8mgsKrv17xdWdXN+IZnqHTYJAhLz/jd3Yt1 ThA8bawXQHeAkM/ODupGEDManYWvy3pDBtKl+76yECSl9kw+S3KjFf5+Reov/3m59InA GXfTs830P2qY2iyyOwFWNzySKPfbE05bDdiP4gfWGDlk93DCzi/GsbqZMbJ/gMzQzyIV 8oNQ== X-Gm-Message-State: AOAM532KpEEPuFGBWSwVSZAEUXZxVFhV+FJzfALGiHa4eN1seOKYDckC H9z2pRknj/F7G42W2FkY+e8cyg== X-Received: by 2002:a05:6830:1e41:: with SMTP id e1mr5233569otj.143.1610644510091; Thu, 14 Jan 2021 09:15:10 -0800 (PST) Received: from builder.lan (104-57-184-186.lightspeed.austtx.sbcglobal.net. [104.57.184.186]) by smtp.gmail.com with ESMTPSA id s26sm1175595otd.8.2021.01.14.09.15.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jan 2021 09:15:09 -0800 (PST) Date: Thu, 14 Jan 2021 11:15:07 -0600 From: Bjorn Andersson To: Stephen Boyd Cc: Douglas Anderson , Jason Cooper , Linus Walleij , Marc Zyngier , Thomas Gleixner , Neeraj Upadhyay , Rajendra Nayak , Maulik Shah , linux-gpio@vger.kernel.org, Srinivas Ramana , linux-arm-msm@vger.kernel.org, Andy Gross , linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 4/4] pinctrl: qcom: Don't clear pending interrupts when enabling Message-ID: References: <20210108093339.v5.1.I3ad184e3423d8e479bc3e86f5b393abb1704a1d1@changeid> <20210108093339.v5.4.I7cf3019783720feb57b958c95c2b684940264cd1@changeid> <161060848425.3661239.17417977666663714149@swboyd.mtv.corp.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <161060848425.3661239.17417977666663714149@swboyd.mtv.corp.google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 14 Jan 01:14 CST 2021, Stephen Boyd wrote: > 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! > > > > > Fixes: 4b7618fdc7e6 ("pinctrl: qcom: Add irq_enable callback for msm gpio") > > Fixes: 71266d9d3936 ("pinctrl: qcom: Move clearing pending IRQ to .irq_request_resources callback") > > Signed-off-by: Douglas Anderson > > --- > > diff --git a/drivers/pinctrl/qcom/pinctrl-msm.c b/drivers/pinctrl/qcom/pinctrl-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 controller > > + * @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); > > > > 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 *pctldev, > > unsigned group) > > { > > struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); > > + struct gpio_chip *gc = &pctrl->chip; > > + unsigned int irq = irq_find_mapping(gc->irq.domain, group); > > + struct irq_data *d = irq_get_irq_data(irq); > > + unsigned int gpio_func = 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 *pctldev, > > if (WARN_ON(i == g->nfuncs)) > > return -EINVAL; > > > > + /* > > + * If an GPIO interrupt is setup on this pin then we need special > > + * handling. Specifically interrupt detection logic will still see > > + * the pin twiddle even when we're muxed away. > > + * > > + * When we see a pin with an interrupt setup on it then we'll disable > > + * (mask) interrupts on it when we mux away until we mux back. Note > > + * that disable_irq() refcounts and interrupts are disabled as long as > > + * at least one disable_irq() has been called. > > + */ > > + if (d && i != 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? > I was about to write a question about why we should disable the IRQ through the irqchip framework, rather than just do it in the hardware directly. Which I think means that I came to the same conclusion as you, that if we have a pin masked to non-gpio, it will still wake the system up, just to actually disable the IRQ lazily. Is there a problem with leaving the irq framework to believe the IRQ is enabled while we disable the delivery in hardware? Regards, Bjorn > > + > > raw_spin_lock_irqsave(&pctrl->lock, flags); > > > > val = msm_readl_ctl(pctrl, g); > > @@ -204,6 +224,20 @@ static int msm_pinmux_set_mux(struct pinctrl_dev *pctldev, > > > > raw_spin_unlock_irqrestore(&pctrl->lock, flags); > > > > + if (d && i == 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_PENDING, 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); > > + } > > +