Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp899513ybh; Mon, 13 Jul 2020 04:22:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxB728zmjXOo8Qf6893mTZuBns50YSe37F7n/t+NH5JzyAqG8hN1itM4qB3xO+PR8ja9lG8 X-Received: by 2002:a17:906:b0d:: with SMTP id u13mr70053220ejg.342.1594639352989; Mon, 13 Jul 2020 04:22:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594639352; cv=none; d=google.com; s=arc-20160816; b=cYN+O6UPR6mznKbQmP5jsL3VDZSFATeegluBz/pZiql3hg4S2bn0VjCK0BRDnQPTrH rd2mKc4OLWAG1U/ckULDSpEe+/brpUtCHWZvqBeXbUcFn7cgrXDQOoIgoVEg8WUqrR5s DLBZRFbqjhDUUGgLNcLo0OEbmWfS6XKyUE9konXqEghmN1v27T+vq0+tvq46PAcP+1Kz xDyYehpy4kAUcNS9Pc+vHUHZQMeE0EajrjRzkt4aauHoxXzY/WYhb1CcCVykPSRQzgVN rq1POv+OYuXqwEMn2qcjh2OakMZJdglKj/kICeF4fxmVsQAq377PK0fIKX8NOP7bQoOb tA5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=lGfMlzw7lL+DLnAZAtVs4q1y+3Quxodyv6jz/gCh0U8=; b=DzO+R4DYWckUMCa1+quLSgmkokczUGWpAaUOpxJj9XPeDxz8a7QVaU58J9OhiJ/2TN R3xfZtQOqCLimBB0FzF8qYbjHd85hhEVVGARSdJu33O4aDxpjUctqsCAmlzaxT0fKld2 q8Dv6PNLpKIFpnXBON9Pu666bFBNDM5juGpSMocq29z5f2Ltik2FZ0jGl4TrEfFm8loA ImWEZp0jg77Xk3odp6yu1A1Qp54jfI6KzKBGdP47PUrHJwXKPHeE5u8FCujvy0p4HKtI iTD4XQLwFa8kVGDSDuytmqs3SDyIXSxU63/BxqVoOpCmSb9ZnhdsRIfmjJqPEgAoVdVS +0Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gMJzYmkZ; 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 d4si8392277ejb.349.2020.07.13.04.22.09; Mon, 13 Jul 2020 04:22:32 -0700 (PDT) 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=gMJzYmkZ; 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 S1729457AbgGMLTa (ORCPT + 99 others); Mon, 13 Jul 2020 07:19:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728950AbgGMLT3 (ORCPT ); Mon, 13 Jul 2020 07:19:29 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E437C08C5DB for ; Mon, 13 Jul 2020 04:19:29 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id j18so12926202wmi.3 for ; Mon, 13 Jul 2020 04:19:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=lGfMlzw7lL+DLnAZAtVs4q1y+3Quxodyv6jz/gCh0U8=; b=gMJzYmkZL6sWzY0Gun2l8Qm0qVvA7eviIR7WnbXqCQ+6oFJ2xMUy6/dVfjkmPhcZ94 zMoSdhycU75jusbCXkICBbO3YB19YOkXgbh0LiTHZddXq1SViHdIlpH+Q36mObsqBUXI smr0FxW0Nun1Z3vY2XSiHUMitCgANXAP/chPw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=lGfMlzw7lL+DLnAZAtVs4q1y+3Quxodyv6jz/gCh0U8=; b=qHpa2LY23IAuDuIHzE/V50NGU0M1fbRsufXbNl+6OF8xRAARBdNr3cLmE6KfYNtqKK tVPP4YmLL39ENJ2582aPMJofgtCaax62dikNyYeeFdzCtC2NuBz/hqCreDEBLaz9IF5s JJa9UMNCnlG73WEOCq07ajcRQ0lep2JXmPAu0L5MT2ieoSHZVVkODfmTPG9m/g97/5T5 5YTh24A0wItXPm0z7GFC/sMIldYncl9TV2Aja8zmXR2DCn6Z0XPRgWYeJcnHLsoTWQD1 SXq2eViGR6+Bp3hRir3RMcI1IVxU1QzjHzvREnuzycut7Zb+0cGc+uiI33lMt6oFPLZG 8pNA== X-Gm-Message-State: AOAM531toC3iI7UjJlOGXvhQLfjwuOMI1VWUzbV2/a+ydjOxz7VG9WBW DhT4aebVp85QmGK9aFCzcm51rS8+dbbQ3RoGwbrZHQ== X-Received: by 2002:a1c:4d04:: with SMTP id o4mr17837113wmh.132.1594639167627; Mon, 13 Jul 2020 04:19:27 -0700 (PDT) MIME-Version: 1.0 References: <20200708141610.1.Ie0d730120b232a86a4eac1e2909bcbec844d1766@changeid> In-Reply-To: <20200708141610.1.Ie0d730120b232a86a4eac1e2909bcbec844d1766@changeid> From: Cheng-yi Chiang Date: Mon, 13 Jul 2020 19:19:01 +0800 Message-ID: Subject: Re: [PATCH] pinctrl: qcom: Handle broken PDC dual edge case on sc7180 To: Douglas Anderson Cc: linus.walleij@linaro.org, Stephen Boyd , linux-arm-msm@vger.kernel.org, ilina@codeaurora.org, agross@kernel.org, rnayak@codeaurora.org, mkshah@codeaurora.org, bjorn.andersson@linaro.org, Marc Zyngier , linux-gpio@vger.kernel.org, linux-kernel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 9, 2020 at 5:16 AM Douglas Anderson wrote: > > As per Qualcomm, there is a PDC hardware issue (with the specific IP > rev that exists on sc7180) that causes the PDC not to work properly > when configured to handle dual edges. > > Let's work around this by emulating only ever letting our parent see > requests for single edge interrupts on affected hardware. > > Fixes: e35a6ae0eb3a ("pinctrl/msm: Setup GPIO chip in hierarchy") > Signed-off-by: Douglas Anderson Tested-by: Cheng-Yi Chiang > > --- > As far as I can tell everything here should work and the limited > testing I'm able to give it shows that, in fact, I can detect both > edges. > > Please give this an extra thorough review since it's trying to find > the exact right place to insert this code and I'm not massively > familiar with all the frameworks. > > If someone has hardware where it's easy to stress test this that'd be > wonderful too. The board I happen to have in front of me doesn't have > any easy-to-toggle GPIOs where I can just poke a button or a switch to > generate edges. My testing was done by hacking the "write protect" > GPIO on my board into gpio-keys as a dual-edge interrupt and then > sending commands to our security chip to toggle it--not exactly great > for testing to make sure there are no race conditions if the interrupt > bounces a lot. > > drivers/pinctrl/qcom/pinctrl-msm.c | 80 +++++++++++++++++++++++++++ > drivers/pinctrl/qcom/pinctrl-msm.h | 4 ++ > drivers/pinctrl/qcom/pinctrl-sc7180.c | 1 + > 3 files changed, 85 insertions(+) > > diff --git a/drivers/pinctrl/qcom/pinctrl-msm.c b/drivers/pinctrl/qcom/pinctrl-msm.c > index 83b7d64bc4c1..45ca09ebb7b3 100644 > --- a/drivers/pinctrl/qcom/pinctrl-msm.c > +++ b/drivers/pinctrl/qcom/pinctrl-msm.c > @@ -860,6 +860,79 @@ static void msm_gpio_irq_ack(struct irq_data *d) > raw_spin_unlock_irqrestore(&pctrl->lock, flags); > } > > +/** > + * msm_gpio_update_dual_edge_parent() - Prime next edge for IRQs handled by parent. > + * @d: The irq dta. > + * > + * This is much like msm_gpio_update_dual_edge_pos() but for IRQs that are > + * normally handled by the parent irqchip. The logic here is slightly > + * different due to what's easy to do with our parent, but in principle it's > + * the same. > + */ > +static void msm_gpio_update_dual_edge_parent(struct irq_data *d) > +{ > + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); > + struct msm_pinctrl *pctrl = gpiochip_get_data(gc); > + const struct msm_pingroup *g = &pctrl->soc->groups[d->hwirq]; > + unsigned long flags; > + int loop_limit = 100; > + unsigned int val; > + unsigned int type; > + > + /* Read the value and make a guess about what edge we need to catch */ > + val = msm_readl_io(pctrl, g) & BIT(g->in_bit); > + type = val ? IRQ_TYPE_EDGE_FALLING : IRQ_TYPE_EDGE_RISING; > + > + raw_spin_lock_irqsave(&pctrl->lock, flags); > + do { > + /* Set the parent to catch the next edge */ > + irq_chip_set_type_parent(d, type); > + > + /* > + * Possibly the line changed between when we last read "val" > + * (and decided what edge we needed) and when set the edge. > + * If the value didn't change (or changed and then changed > + * back) then we're done. > + */ > + val = msm_readl_io(pctrl, g) & BIT(g->in_bit); > + if (type == IRQ_TYPE_EDGE_RISING) { > + if (!val) > + break; > + type = IRQ_TYPE_EDGE_FALLING; > + } else if (type == IRQ_TYPE_EDGE_FALLING) { > + if (val) > + break; > + type = IRQ_TYPE_EDGE_RISING; > + } > + } while (loop_limit-- > 0); > + raw_spin_unlock_irqrestore(&pctrl->lock, flags); > + > + if (!loop_limit) > + dev_err(pctrl->dev, "dual-edge irq failed to stabilize\n"); > +} > + > +void msm_gpio_handle_dual_edge_parent_irq(struct irq_desc *desc) > +{ > + struct irq_data *d = &desc->irq_data; > + > + /* Make sure we're primed for the next edge */ > + msm_gpio_update_dual_edge_parent(d); > + > + /* Pass on to the normal interrupt handler */ > + handle_fasteoi_irq(desc); > +} > + > +static bool msm_gpio_needs_dual_edge_parent_workaround(struct irq_data *d, > + unsigned int type) > +{ > + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); > + struct msm_pinctrl *pctrl = gpiochip_get_data(gc); > + > + return type == IRQ_TYPE_EDGE_BOTH && > + pctrl->soc->wakeirq_dual_edge_errata && d->parent_data && > + test_bit(d->hwirq, pctrl->skip_wake_irqs); > +} > + > static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type) > { > struct gpio_chip *gc = irq_data_get_irq_chip_data(d); > @@ -868,6 +941,13 @@ static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type) > unsigned long flags; > u32 val; > > + if (msm_gpio_needs_dual_edge_parent_workaround(d, type)) { > + irq_set_handler_locked(d, msm_gpio_handle_dual_edge_parent_irq); > + msm_gpio_update_dual_edge_parent(d); > + > + return 0; > + } > + > if (d->parent_data) > irq_chip_set_type_parent(d, type); > > diff --git a/drivers/pinctrl/qcom/pinctrl-msm.h b/drivers/pinctrl/qcom/pinctrl-msm.h > index 9452da18a78b..7486fe08eb9b 100644 > --- a/drivers/pinctrl/qcom/pinctrl-msm.h > +++ b/drivers/pinctrl/qcom/pinctrl-msm.h > @@ -113,6 +113,9 @@ struct msm_gpio_wakeirq_map { > * @pull_no_keeper: The SoC does not support keeper bias. > * @wakeirq_map: The map of wakeup capable GPIOs and the pin at PDC/MPM > * @nwakeirq_map: The number of entries in @wakeirq_map > + * @wakeirq_dual_edge_errata: If true then GPIOs using the wakeirq_map need > + * to be aware that their parent can't handle dual > + * edge interrupts. > */ > struct msm_pinctrl_soc_data { > const struct pinctrl_pin_desc *pins; > @@ -128,6 +131,7 @@ struct msm_pinctrl_soc_data { > const int *reserved_gpios; > const struct msm_gpio_wakeirq_map *wakeirq_map; > unsigned int nwakeirq_map; > + bool wakeirq_dual_edge_errata; > }; > > extern const struct dev_pm_ops msm_pinctrl_dev_pm_ops; > diff --git a/drivers/pinctrl/qcom/pinctrl-sc7180.c b/drivers/pinctrl/qcom/pinctrl-sc7180.c > index 1b6465a882f2..1d9acad3c1ce 100644 > --- a/drivers/pinctrl/qcom/pinctrl-sc7180.c > +++ b/drivers/pinctrl/qcom/pinctrl-sc7180.c > @@ -1147,6 +1147,7 @@ static const struct msm_pinctrl_soc_data sc7180_pinctrl = { > .ntiles = ARRAY_SIZE(sc7180_tiles), > .wakeirq_map = sc7180_pdc_map, > .nwakeirq_map = ARRAY_SIZE(sc7180_pdc_map), > + .wakeirq_dual_edge_errata = true, > }; > > static int sc7180_pinctrl_probe(struct platform_device *pdev) > -- > 2.27.0.383.g050319c2ae-goog >