Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp6111266imm; Mon, 27 Aug 2018 09:52:36 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYO4UJ3IYyfShR0G1lxq4bx3YYp8sYhoCbt6IMrce+73Q0UlHzaQ6RDavY2fPhb3GAIdopO X-Received: by 2002:a62:fc5:: with SMTP id 66-v6mr15097342pfp.237.1535388756703; Mon, 27 Aug 2018 09:52:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535388756; cv=none; d=google.com; s=arc-20160816; b=jAAVrxZmJgkNg4B/hK3LmRDPWfdw4w0iVMhnQcZW20WjE5rulCFs2hbC+O/xNyrx4D B3dcc5441mMxlaT/YQrlvXKagQgmhrEQzopruzoKM2RAddJOwg2AQepvmPwvdxmKVspE L95rLohxhVL2LZN/3cjJCNfGvv5d0qnQP7MPh0WUX785ZNwjUHilEqsT9zRFiIzbxcqn 9FhTJockSc3wjrG/5lLTOiPenr8uvWJyFKJLnQTJCRncUFizBurjbzbSUq2hOljO904Z j+G/lvPYdWpuEAQ27nhrbhP0BH45ri92gkNGW4YsbSskvyki26YV4BOCm6NkiElAip8q 2Meg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=Yvyf9B0xNl7XZMYZ+sxMVyVMJ94V74dDx+qydqVdOyA=; b=qu0py4kaT4h8+ikaIB2+XH2wGtcAM/Xow3cM+6A6ggKo7ifw/8oRZeZwVCxOMZdqTf 2IY8py1iiY+PqzfTj4U9JxAW2NYCjh7gw5l79oWW7qKxJ5iQap4W9or8e8bo+WTTbpG7 vxrbVZIh/HMxPwXPqfs4NJnynmw7angiqw27pZjat+iLVxXjplwwWS/RjSi/PmL63zuR tg4GC0xYDzAKyjFYHM5mdP2J3nYv/fn+E7ZhrM2pBWaEmk+5z6EUvgwQ30d8XVS0n0tX +kiF22ubXxyFU3tSxUabuM6e8z1adksekDjfktWHye63BkGXttgSkyhUgZt5W7PMt1QE 8Y6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=aixJQRhg; dkim=pass header.i=@codeaurora.org header.s=default header.b=b7pCNZhT; 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 1-v6si14172501plv.28.2018.08.27.09.52.21; Mon, 27 Aug 2018 09:52:36 -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; dkim=pass header.i=@codeaurora.org header.s=default header.b=aixJQRhg; dkim=pass header.i=@codeaurora.org header.s=default header.b=b7pCNZhT; 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 S1727390AbeH0Ui2 (ORCPT + 99 others); Mon, 27 Aug 2018 16:38:28 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:37630 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726995AbeH0Ui2 (ORCPT ); Mon, 27 Aug 2018 16:38:28 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 45A9A60600; Mon, 27 Aug 2018 16:51:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1535388665; bh=Whbt4fBIqSqQ7WtLjW3p/q2rj00GYt0D+RU50P4eZok=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=aixJQRhg/I3INmt0cDgeqFVWYDFKgxFPulKR7LoDZywylhl1QxbbT4SpdfJltfIfX 9dCSIDy7BWbwWa5tNXOp2xb3K///Hm9prMKVlvevg316UfmGBcF9SpOksAUX9lhzH1 bnN4FiZ68Mc1MVJd9PWgOqWgUUwSYM8qLMOwpILM= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from localhost (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: ilina@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 24BD460117; Mon, 27 Aug 2018 16:51:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1535388664; bh=Whbt4fBIqSqQ7WtLjW3p/q2rj00GYt0D+RU50P4eZok=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=b7pCNZhTUAC47uLIdtsRYgPJAczn+VzwHLm86gTlD04gT9w/+V8Qzx7on2EK/QsFP KUWjS/7J6ExHwJVLb4t05ZJudMh1JtTa+kQcvobKo90Ttm5sR8adxv6vHMe8WzznsL S4OgBtjX2eGLuE2GjxXY1nsa1r2dcaKlcGkhNDr0= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 24BD460117 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=ilina@codeaurora.org Date: Mon, 27 Aug 2018 10:51:03 -0600 From: Lina Iyer To: Bjorn Andersson Cc: marc.zyngier@arm.com, 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 v2 1/5] drivers: pinctrl: qcom: add wakeup capability to GPIO Message-ID: <20180827165103.GQ5081@codeaurora.org> References: <20180817163849.30750-1-ilina@codeaurora.org> <20180817163849.30750-2-ilina@codeaurora.org> <20180821060844.GB5603@tuxbook-pro> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20180821060844.GB5603@tuxbook-pro> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 20 2018 at 00:05 -0600, Bjorn Andersson wrote: >On Fri 17 Aug 09:38 PDT 2018, Lina Iyer wrote: > >Thanks Lina, I think this looks like a very reasonable approach! > >> 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 the >> 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. >> > >Afaict we can model a driver for the MPM hardware - for previous >platforms - after your PDC driver and all of this logic will be reused. > >As such I think it would be better to use the word "wake" instead of >"pdc" in the implementation. I don't see a problem with the commit >message being specific and talking about the PDC though, so keep that. > >> Signed-off-by: Lina Iyer >> --- >> 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 | 97 ++++++++++++++++++++++++++++++ >> 1 file changed, 97 insertions(+) >> >> diff --git a/drivers/pinctrl/qcom/pinctrl-msm.c b/drivers/pinctrl/qcom/pinctrl-msm.c >> index 0e22f52b2a19..03ef1d29d078 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); > >Given that the TLMM summary logic isn't powered during a collapse, is >there really a point in toggling the wake of the summary irq? (I wrote >this, not sure it is correct) > >Also, we're not modifying any tlmm state here, so we shouldn't need that >spinlock. > Okay. >> >> raw_spin_unlock_irqrestore(&pctrl->lock, flags); >> @@ -863,6 +871,93 @@ 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)) { > >This deserves a comment in the code as well. > Will add. >> + 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); >> + raw_spin_unlock_irqrestore(&pctrl->lock, flags); >> + } >> + >> + 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); >> + unsigned irq; >> + unsigned long trigger; >> + const char *pin_name; >> + int ret; >> + >> + pin_name = kasprintf(GFP_KERNEL, "gpio%lu", d->hwirq); > >pin_name needs to be released in msm_gpio_pdc_pin_release() as well. > >> + if (!pin_name) >> + return -ENOMEM; >> + >> + irq = platform_get_irq_byname(pdev, pin_name); >> + if (irq < 0) { >> + kfree(pin_name); >> + return 0; >> + } >> + >> + trigger = irqd_get_trigger_type(d) | IRQF_ONESHOT | IRQF_NO_SUSPEND; >> + ret = request_irq(irq, wake_irq_gpio_handler, trigger, pin_name, d); >> + if (ret) { >> + pr_warn("GPIO-%lu could not be set up as wakeup", d->hwirq); >> + kfree(pin_name); >> + return ret; >> + } >> + >> + irq_set_handler_data(d->irq, irq_get_irq_data(irq)); >> + disable_irq(irq); >> + >> + return 0; >> +} >> + >> +static int msm_gpio_pdc_pin_release(struct irq_data *d) >> +{ >> + struct irq_data *pdc_irqd = irq_get_handler_data(d->irq); >> + >> + if (pdc_irqd) { >> + irq_set_handler_data(d->irq, NULL); >> + free_irq(pdc_irqd->irq, d); > >free_irq() returns what was "pin_name" in msm_gpio_pdc_pin_request(), so >you should be able to free that. > Just realized the return value. Will fix. Thanks, Lina