From patchwork Fri May 29 02:14:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Fong X-Patchwork-Id: 6504131 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id ED2CF9F38D for ; Fri, 29 May 2015 02:20:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1030B2070D for ; Fri, 29 May 2015 02:20:08 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2BC2C20708 for ; Fri, 29 May 2015 02:20:07 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Yy9s1-0003R1-2g; Fri, 29 May 2015 02:18:01 +0000 Received: from mail-pa0-x230.google.com ([2607:f8b0:400e:c03::230]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Yy9pV-0000Cu-Ci for linux-arm-kernel@lists.infradead.org; Fri, 29 May 2015 02:15:29 +0000 Received: by padbw4 with SMTP id bw4so37000445pad.0 for ; Thu, 28 May 2015 19:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FxROuNGutELBgGetRR+ZOb34xyq5urVOhwho20Xc0xE=; b=QNEqlzrpvUN95FeyW1SVh5mraCmOdzJ8JLaZ/6CGigwZ8FVIe0RdPYquMEp7BAegQ1 LHFztYzhgzNMy/+7BCJVP3kyUOJ2xi3ryQMFMpG4pIk6hu67IxvifxS9iSqLJ0V+MbC+ 5363c7f/v1yWAHh+R2x0tnEeCdZcydOioUh0/b5TuYXRVaH1bGk9eoYVuKzthQ6avFTK TVJ5PJEASrRKhIr1AmukcjnYChj7gynaIrYxfGUeX4GHs/Rpa62c3TlI0rsFipEmAn4W M3vBDvPgCuUZWRrVSntNVKsmI4bPKXOurU2rB15oUAe/PBF9ksU9n6Xk2AVP+UhLjIl0 Ms1Q== X-Received: by 10.66.119.174 with SMTP id kv14mr10672340pab.5.1432865702915; Thu, 28 May 2015 19:15:02 -0700 (PDT) Received: from gregory-irv-00.irv.broadcom.com (5520-maca-inet1-outside.broadcom.com. [216.31.211.11]) by mx.google.com with ESMTPSA id ph4sm3722456pdb.43.2015.05.28.19.15.00 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 May 2015 19:15:01 -0700 (PDT) From: Gregory Fong To: linux-gpio@vger.kernel.org Subject: [PATCH v2 4/6] gpio: brcmstb: Allow GPIOs to be wakeup sources Date: Thu, 28 May 2015 19:14:08 -0700 Message-Id: <1432865650-4062-5-git-send-email-gregory.0xf0@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1432865650-4062-1-git-send-email-gregory.0xf0@gmail.com> References: <1432865650-4062-1-git-send-email-gregory.0xf0@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150528_191525_532336_0366540E X-CRM114-Status: GOOD ( 16.31 ) X-Spam-Score: -0.6 (/) Cc: Mark Rutland , Alexandre Courbot , Florian Fainelli , Russell King , Pawel Moll , devicetree@vger.kernel.org, Linus Walleij , Ian Campbell , linux-kernel@vger.kernel.org, Rob Herring , bcm-kernel-feedback-list@broadcom.com, Gregory Fong , Kumar Gala , Brian Norris , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Several drivers (e.g. gpio-keys) allow for GPIOs to be configured as wakeup sources, and this GPIO controller supports that through a separate interrupt path. The de-facto standard DT property "wakeup-source" is checked, since that indicates whether the GPIO controller hardware can wake. Uses the IRQCHIP_MASK_ON_SUSPEND irq_chip flag because UPG GIO doesn't have any of its own wakeup source configuration. Signed-off-by: Gregory Fong Reviewed-by: Brian Norris --- New in v2. drivers/gpio/gpio-brcmstb.c | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/drivers/gpio/gpio-brcmstb.c b/drivers/gpio/gpio-brcmstb.c index b9962ff..2598c1e 100644 --- a/drivers/gpio/gpio-brcmstb.c +++ b/drivers/gpio/gpio-brcmstb.c @@ -19,6 +19,7 @@ #include #include #include +#include #define GIO_BANK_SIZE 0x20 #define GIO_ODEN(bank) (((bank) * GIO_BANK_SIZE) + 0x00) @@ -48,6 +49,7 @@ struct brcmstb_gpio_priv { struct irq_domain *irq_domain; int parent_irq; int gpio_base; + int parent_wake_irq; }; #define MAX_GPIO_PER_BANK 32 @@ -183,6 +185,31 @@ static int brcmstb_gpio_irq_set_type(struct irq_data *d, unsigned int type) return 0; } +static int brcmstb_gpio_irq_set_wake(struct irq_data *d, unsigned int enable) +{ + struct brcmstb_gpio_bank *bank = irq_data_get_irq_chip_data(d); + struct brcmstb_gpio_priv *priv = bank->parent_priv; + + /* + * Only enable wake IRQ once for however many hwirqs can wake + * since they all use the same wake IRQ. Mask will be set + * up appropriately thanks to IRQCHIP_MASK_ON_SUSPEND flag. + */ + if (enable) + enable_irq_wake(priv->parent_wake_irq); + else + disable_irq_wake(priv->parent_wake_irq); + return 0; +} + +static irqreturn_t brcmstb_gpio_wake_irq_handler(int irq, void *data) +{ + struct brcmstb_gpio_priv *priv = data; + + pm_wakeup_event(&priv->pdev->dev, 0); + return IRQ_HANDLED; +} + static void brcmstb_gpio_irq_bank_handler(int irq, struct brcmstb_gpio_bank *bank) { @@ -369,6 +396,32 @@ static int brcmstb_gpio_irq_setup(struct platform_device *pdev, priv->irq_chip.irq_mask = brcmstb_gpio_irq_mask; priv->irq_chip.irq_unmask = brcmstb_gpio_irq_unmask; priv->irq_chip.irq_set_type = brcmstb_gpio_irq_set_type; + + /* Ensures that all non-wakeup IRQs are disabled at suspend */ + priv->irq_chip.flags = IRQCHIP_MASK_ON_SUSPEND; + + if (IS_ENABLED(CONFIG_PM_SLEEP) && + of_get_property(np, "wakeup-source", NULL)) { + priv->parent_wake_irq = platform_get_irq(pdev, 1); + if (priv->parent_wake_irq < 0) { + dev_warn(dev, + "Couldn't get wake IRQ - GPIOs will not be able to wake from sleep"); + } else { + int err = devm_request_irq(dev, priv->parent_wake_irq, + brcmstb_gpio_wake_irq_handler, 0, + "brcmstb-gpio-wake", priv); + + if (err < 0) { + dev_err(dev, "Couldn't request wake IRQ"); + return err; + } + + device_set_wakeup_capable(dev, true); + device_wakeup_enable(dev); + priv->irq_chip.irq_set_wake = brcmstb_gpio_irq_set_wake; + } + } + priv->irq_domain = irq_domain_add_linear(np, priv->num_gpios, &brcmstb_gpio_irq_domain_ops,