Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp111407imm; Thu, 20 Sep 2018 16:11:55 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYGRUw3QtO7xTTNsGVQ/N6y3O2XpbovwICHyCjSh4ElClWfnn1yTuLWnSRbNxKrN2Bffo0G X-Received: by 2002:aa7:818f:: with SMTP id g15-v6mr43180325pfi.71.1537485115362; Thu, 20 Sep 2018 16:11:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537485115; cv=none; d=google.com; s=arc-20160816; b=Kof+a0msEFBql+vfDYUuL1rG9tBVx0UzN6rkMdzRYVog/AYkmGAXxR3QCfIC1nyMkT 8oiTvvQFjgUaeesbzKvuXlVjToke+1FMYD1UBX0/QOiOfPBiXkG780zi/QFWjk6z3E7R 7p09Mw40xjEdBMTI/aveA9RFMOHiw/nMG2LnA/h2lDOMR00pAPPM4/m72u5uU6BSvL7x lKCRI+eahzcTl9k7Sf3CEEtBuBI9FRhntuy/faUaPan3jaTd+9GMiQYQ3yW3+iEwbdse A0biA5KbvyvfKccPOTOQghYTCSj+CPh12FsPb1XU+okM5CMlhyn7QdXBHUSSjpxoIslg PdaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:organization:user-agent :references:in-reply-to:subject:cc:to:from:message-id:date; bh=MOjPSAY8h7ZbXSRH41MF8g+WRb6T79Lmds/Xryf4+FQ=; b=Nh0mGHaKdNhr3edJWyeSoWvGS3jmvSnPkkc70IFnAweasoPg7EUDNn7thZsi04N16y XODLIEQ3X1NY0HowSXX4KVx5/CqwPq+zfchCaqP5LukWJej3J+0p7NK0hRwg3Hw5d4eI fOJ78xMYDefdRYrFBSq9T4WmFWBAaH6qNnjdncsHv2OUyqAGvjo0Qqpjii3wKXe1yosr eOH8LwaeoYpzowWnQWXPLzN6RYLoDK6eOXUvQyGLS6XqcnFgHjE2yq0rj83chNSPOY6g xwMCEQhRAQm1waNJWjW1s5sttnADFPXBMzQx/6f08tx0qvQ5Sxw3LuNZEW5xt4KtebqC mQug== ARC-Authentication-Results: i=1; mx.google.com; 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 e17-v6si22566666pgv.615.2018.09.20.16.11.34; Thu, 20 Sep 2018 16:11:55 -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; 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 S1725915AbeIUE5W (ORCPT + 99 others); Fri, 21 Sep 2018 00:57:22 -0400 Received: from foss.arm.com ([217.140.101.70]:54200 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725808AbeIUE5W (ORCPT ); Fri, 21 Sep 2018 00:57:22 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9683C80D; Thu, 20 Sep 2018 16:11:29 -0700 (PDT) Received: from big-swifty.misterjones.org (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 246EC3F5C0; Thu, 20 Sep 2018 16:11:29 -0700 (PDT) Date: Fri, 21 Sep 2018 00:11:28 +0100 Message-ID: <86k1nfwyqn.wl-marc.zyngier@arm.com> From: Marc Zyngier To: Lina Iyer Cc: bjorn.andersson@linaro.org, sboyd@kernel.org, evgreen@chromium.org, linus.walleij@linaro.org, rplsssn@codeaurora.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, rnayak@codeaurora.org, devicetree@vger.kernel.org, andy.gross@linaro.org, dianders@chromium.org Subject: Re: [PATCH v3 1/5] drivers: pinctrl: qcom: add wakeup capability to GPIO In-Reply-To: <20180904211810.5506-2-ilina@codeaurora.org> References: <20180904211810.5506-1-ilina@codeaurora.org> <20180904211810.5506-2-ilina@codeaurora.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 EasyPG/1.0.0 Emacs/25.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Organization: ARM Ltd MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Lina, On Tue, 04 Sep 2018 22:18:06 +0100, Lina Iyer wrote: > > QCOM SoC's that have Power Domain Controller (PDC) chip in the always-on > domain can wakeup the SoC, when interrupts and GPIOs are routed to its > interrupt controller. Only select GPIOs that are deemed wakeup capable > are routed to specific PDC pins. During low power state, the pinmux > interrupt controller may be non-functional but the PDC would be. The PDC > can detect the wakeup GPIO is triggered and bring the TLMM to an > operational state. > > Interrupts that are level triggered will be detected at the TLMM when > the controller becomes operational. Edge interrupts however need to be > replayed again. > > Request the corresponding PDC IRQ, when the GPIO is requested as an IRQ, > but keep it disabled. During suspend, we can enable the PDC IRQ instead > of the GPIO IRQ, which may or not be detected. > > Signed-off-by: Lina Iyer > --- > Changes in v3: > - free action->name > Changes in v2: > - Remove IRQF_NO_SUSPEND and IRQF_ONE_SHOT from PDC IRQ > Changes in v1: > - Trigger GPIO in h/w from PDC IRQ handler > - Avoid big tables for GPIO-PDC map, pick from DT instead > - Use handler_data > --- > drivers/pinctrl/qcom/pinctrl-msm.c | 98 ++++++++++++++++++++++++++++++ > 1 file changed, 98 insertions(+) > > diff --git a/drivers/pinctrl/qcom/pinctrl-msm.c b/drivers/pinctrl/qcom/pinctrl-msm.c > index 0e22f52b2a19..6527a0a9edd1 100644 > --- a/drivers/pinctrl/qcom/pinctrl-msm.c > +++ b/drivers/pinctrl/qcom/pinctrl-msm.c > @@ -687,11 +687,15 @@ static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type) > const struct msm_pingroup *g; > unsigned long flags; > u32 val; > + struct irq_data *pdc_irqd = irq_get_handler_data(d->irq); > > g = &pctrl->soc->groups[d->hwirq]; > > raw_spin_lock_irqsave(&pctrl->lock, flags); > > + if (pdc_irqd) > + irq_set_irq_type(pdc_irqd->irq, type); > + > /* > * For hw without possibility of detecting both edges > */ > @@ -779,9 +783,13 @@ static int msm_gpio_irq_set_wake(struct irq_data *d, unsigned int on) > struct gpio_chip *gc = irq_data_get_irq_chip_data(d); > struct msm_pinctrl *pctrl = gpiochip_get_data(gc); > unsigned long flags; > + struct irq_data *pdc_irqd = irq_get_handler_data(d->irq); > > raw_spin_lock_irqsave(&pctrl->lock, flags); > > + if (pdc_irqd) > + irq_set_irq_wake(pdc_irqd->irq, on); > + > irq_set_irq_wake(pctrl->irq, on); > > raw_spin_unlock_irqrestore(&pctrl->lock, flags); > @@ -863,6 +871,94 @@ static bool msm_gpio_needs_valid_mask(struct msm_pinctrl *pctrl) > return device_property_read_u16_array(pctrl->dev, "gpios", NULL, 0) > 0; > } > > +static irqreturn_t wake_irq_gpio_handler(int irq, void *data) > +{ > + struct irq_data *irqd = data; > + struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); > + struct msm_pinctrl *pctrl = gpiochip_get_data(gc); > + const struct msm_pingroup *g; > + unsigned long flags; > + u32 val; > + > + if (!irqd_is_level_type(irqd)) { > + g = &pctrl->soc->groups[irqd->hwirq]; > + raw_spin_lock_irqsave(&pctrl->lock, flags); > + val = BIT(g->intr_status_bit); > + writel(val, pctrl->regs + g->intr_status_reg); write_relaxed, please. > + raw_spin_unlock_irqrestore(&pctrl->lock, flags); > + } Overall, this requires some form of documentation (I'll have forgotten about the whole thing quickly enough). > + > + return IRQ_HANDLED; > +} > + > +static int msm_gpio_pdc_pin_request(struct irq_data *d) > +{ > + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); > + struct msm_pinctrl *pctrl = gpiochip_get_data(gc); > + struct platform_device *pdev = to_platform_device(pctrl->dev); > + const char *pin_name; > + int irq; > + int ret; > + > + pin_name = kasprintf(GFP_KERNEL, "gpio%lu", d->hwirq); > + if (!pin_name) > + return -ENOMEM; > + > + irq = platform_get_irq_byname(pdev, pin_name); > + if (irq < 0) { > + kfree(pin_name); > + return 0; > + } > + > + ret = request_irq(irq, wake_irq_gpio_handler, irqd_get_trigger_type(d), > + pin_name, d); > + if (ret) { > + pr_warn("GPIO-%lu could not be set up as wakeup", d->hwirq); This message doesn't correspond to what you're doing here. > + kfree(pin_name); > + return ret; > + } > + > + irq_set_handler_data(d->irq, irq_get_irq_data(irq)); > + disable_irq(irq); Who enables this interrupt? There is a gap between request_irq and disable_irq, where you can take the interrupt, and not having set the handler data. Horrible things will happen in this situation. A slightly better way of doing that would be: // Prevent the interrupt from being enabled on request irq_set_status_flags(d->irq, IRQ_NOAUTOEN); ret = request_irq(...); irq_set_handler(...); and let the enable_irq() do its thing when it happens (where?). > + > + return 0; > +} > + > +static int msm_gpio_pdc_pin_release(struct irq_data *d) > +{ > + struct irq_data *pdc_irqd = irq_get_handler_data(d->irq); > + const void *name; > + > + if (pdc_irqd) { > + irq_set_handler_data(d->irq, NULL); > + name = free_irq(pdc_irqd->irq, d); > + kfree(name); > + } > + > + return 0; > +} > + > +static int msm_gpio_irq_reqres(struct irq_data *d) > +{ > + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); > + > + if (gpiochip_lock_as_irq(gc, irqd_to_hwirq(d))) { > + dev_err(gc->parent, "unable to lock HW IRQ %lu for IRQ\n", > + irqd_to_hwirq(d)); > + return -EINVAL; > + } > + > + return msm_gpio_pdc_pin_request(d); > +} > + > +static void msm_gpio_irq_relres(struct irq_data *d) > +{ > + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); > + > + msm_gpio_pdc_pin_release(d); > + gpiochip_unlock_as_irq(gc, irqd_to_hwirq(d)); > +} > + > static int msm_gpio_init(struct msm_pinctrl *pctrl) > { > struct gpio_chip *chip; > @@ -887,6 +983,8 @@ static int msm_gpio_init(struct msm_pinctrl *pctrl) > pctrl->irq_chip.irq_ack = msm_gpio_irq_ack; > pctrl->irq_chip.irq_set_type = msm_gpio_irq_set_type; > pctrl->irq_chip.irq_set_wake = msm_gpio_irq_set_wake; > + pctrl->irq_chip.irq_request_resources = msm_gpio_irq_reqres; > + pctrl->irq_chip.irq_release_resources = msm_gpio_irq_relres; > > ret = gpiochip_add_data(&pctrl->chip, pctrl); > if (ret) { > -- > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, > a Linux Foundation Collaborative Project > Thanks, M. -- Jazz is not dead, it just smell funny.