From patchwork Tue Nov 6 19:19:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabrizio Castro X-Patchwork-Id: 10671325 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2BE0E13A4 for ; Tue, 6 Nov 2018 19:19:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1AC902AF64 for ; Tue, 6 Nov 2018 19:19:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E9652B11E; Tue, 6 Nov 2018 19:19:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C3E32AF64 for ; Tue, 6 Nov 2018 19:19:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388674AbeKGEqJ (ORCPT ); Tue, 6 Nov 2018 23:46:09 -0500 Received: from relmlor3.renesas.com ([210.160.252.173]:3220 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387804AbeKGEqJ (ORCPT ); Tue, 6 Nov 2018 23:46:09 -0500 Received: from unknown (HELO relmlir4.idc.renesas.com) ([10.200.68.154]) by relmlie2.idc.renesas.com with ESMTP; 07 Nov 2018 04:19:23 +0900 Received: from relmlii1.idc.renesas.com (relmlii1.idc.renesas.com [10.200.68.65]) by relmlir4.idc.renesas.com (Postfix) with ESMTP id 9AD30673E6; Wed, 7 Nov 2018 04:19:23 +0900 (JST) X-IronPort-AV: E=Sophos;i="5.54,472,1534777200"; d="scan'208";a="295321012" Received: from unknown (HELO fabrizio-dev.ree.adwin.renesas.com) ([10.226.36.250]) by relmlii1.idc.renesas.com with ESMTP; 07 Nov 2018 04:19:21 +0900 From: Fabrizio Castro To: Linus Walleij , Geert Uytterhoeven , Simon Horman Cc: Fabrizio Castro , linux-gpio@vger.kernel.org, Chris Paterson , Biju Das , linux-renesas-soc@vger.kernel.org Subject: [PATCH v2] gpio: rcar: Request GPIO while enabling interrupt Date: Tue, 6 Nov 2018 19:19:09 +0000 Message-Id: <1541531949-23407-1-git-send-email-fabrizio.castro@bp.renesas.com> X-Mailer: git-send-email 2.7.4 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are cases when the bootloader configures a pin to work as a function rather than GPIO, and other cases when the pin is configured as a function at POR. This commit makes sure the pin is configured as a GPIO the moment we need it to work as an interrupt. Signed-off-by: Fabrizio Castro --- v1->v2: * Moved gpio_rcar_request call from gpio_rcar_irq_set_type to rcar_gpio_irq_request_resources * Added rcar_gpio_irq_release_resources for calling gpio_rcar_free Comments very welcome! drivers/gpio/gpio-rcar.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c index 3c82bb3..c16598b 100644 --- a/drivers/gpio/gpio-rcar.c +++ b/drivers/gpio/gpio-rcar.c @@ -344,6 +344,29 @@ static int gpio_rcar_direction_output(struct gpio_chip *chip, unsigned offset, return 0; } +static int rcar_gpio_irq_request_resources(struct irq_data *d) +{ + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); + struct gpio_rcar_priv *p = gpiochip_get_data(gc); + unsigned int hwirq = irqd_to_hwirq(d); + int err; + + gpio_rcar_direction_input(gc, hwirq); + err = gpio_rcar_request(gc, hwirq); + if (err) + dev_err(&p->pdev->dev, "Can't request GPIO %u from %s\n", hwirq, + gc->label); + return err; +} + +static void rcar_gpio_irq_release_resources(struct irq_data *d) +{ + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); + unsigned int hwirq = irqd_to_hwirq(d); + + gpio_rcar_free(gc, hwirq); +} + struct gpio_rcar_info { bool has_both_edge_trigger; }; @@ -491,6 +514,8 @@ static int gpio_rcar_probe(struct platform_device *pdev) irq_chip->irq_set_type = gpio_rcar_irq_set_type; irq_chip->irq_set_wake = gpio_rcar_irq_set_wake; irq_chip->flags = IRQCHIP_SET_TYPE_MASKED | IRQCHIP_MASK_ON_SUSPEND; + irq_chip->irq_request_resources = rcar_gpio_irq_request_resources; + irq_chip->irq_release_resources = rcar_gpio_irq_release_resources; ret = gpiochip_add_data(gpio_chip, p); if (ret) {