Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1509164imj; Fri, 8 Feb 2019 02:41:32 -0800 (PST) X-Google-Smtp-Source: AHgI3IbntS0nuIneeonLOSFznkOQ1S91NZXsexUZ4nUkKPBMmhzwbp6+U4Hifj2sYPDskX8+clxR X-Received: by 2002:a17:902:ba8b:: with SMTP id k11mr21948699pls.177.1549622492443; Fri, 08 Feb 2019 02:41:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549622492; cv=none; d=google.com; s=arc-20160816; b=N++SYjfOBQ5C83CxKsX2qIAYjJ4aBS9JPoSDtJzbw4eakvcPkM2iSFHEn9/VDoYh0h xzv/0qB3bge20S0AQsbm5xfGs/rGiSWOshSVWuwDMSWl2mAKu52oeEpBKH2moNPa37fw GbXstDqAaTb4BxjOljM2kjJMpVL3I8fOWor4NadZYwLzdDvj7UIRX1aty7NHGrWz0R8m x5oHAy42Q/abjihxNbKKFYdBsLoRjm+I+jv/agBf4iUkWfdqmqSrMoBfMz0xp1r4rd2S 0zaax85iyPka9FgL3tKVZk+botIvb5ftTwerjeJJYGbFNCFFr5EGjYYBpptTxFz36OVr S9XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=Nr3ElIXWj+82VHO9m2HDvKCAbSOc0GkppJb17YQ60kw=; b=Zl8ZDz1z59mzrvrI3LVoDhnC6C5kN7hztVRv4l8YMdOOLqmqUM5HAkwAKKV+KEiX/r /1B3UBNdsApjWydGLqWP5vjeJVgSbPhpxg3lDK/H8fqHOtn343maNmav5JK98Goc0YRX Ic7NcaZRfg+3xCKHNRPHI0vftUc9dsMfVT+aQZifGbWTlLjywCJCVeCqPKcNm9wuNg2c L3rA42WiTeOVH4eKsBX0vZyCVRI+3CvePSPba07FdUFatUUzTyWqWs22mum/M/InUdQA bc6UCG8WPTIts/HCu8uOHOKMtcoL4F9EIgpfbZzb1K0EK8/P70lWTMMM/yD2tfArguqP Qduw== 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 s7si1773908plq.237.2019.02.08.02.41.16; Fri, 08 Feb 2019 02:41:32 -0800 (PST) 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 S1726869AbfBHKkv (ORCPT + 99 others); Fri, 8 Feb 2019 05:40:51 -0500 Received: from relay5-d.mail.gandi.net ([217.70.183.197]:48119 "EHLO relay5-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726081AbfBHKku (ORCPT ); Fri, 8 Feb 2019 05:40:50 -0500 X-Originating-IP: 90.88.22.177 Received: from localhost (aaubervilliers-681-1-80-177.w90-88.abo.wanadoo.fr [90.88.22.177]) (Authenticated sender: thomas.petazzoni@bootlin.com) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 3AFE31C0008; Fri, 8 Feb 2019 10:40:47 +0000 (UTC) From: Thomas Petazzoni To: Linus Walleij , Bartosz Golaszewski , Michal Simek Cc: linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Thomas Petazzoni Subject: [PATCH] gpio: zynq: properly support runtime PM for GPIO used as interrupts Date: Fri, 8 Feb 2019 11:40:46 +0100 Message-Id: <20190208104046.21817-1-thomas.petazzoni@bootlin.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The Zynq GPIO driver currently implements runtime PM by: - Enabling runtime PM support in ->probe() and letting the runtime PM reference counter drop to zero at the end of ->probe(). - Increasing the runtime PM reference counter in ->request() and decreasing it in ->free(). However, the latter is not sufficient: when a GPIO is used as an interrupt, ->request() and ->free() are not called. Due to this, the runtime PM counter remains to zero when the only GPIOs in use are used as interrupts, causing them to simply not work. To address this problem, this commit implement the ->irq_request_resources() and ->irq_release_resources() hooks, ensuring that the runtime PM counter is properly incremented/decremented. Since we override the default hooks, we keep the existing behavior by making sure they call gpiochip_reqres_irq() / gpiochip_relres_irq() respectively. Signed-off-by: Thomas Petazzoni --- drivers/gpio/gpio-zynq.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/gpio/gpio-zynq.c b/drivers/gpio/gpio-zynq.c index 3f5fcdd5a429..65c0c29ce851 100644 --- a/drivers/gpio/gpio-zynq.c +++ b/drivers/gpio/gpio-zynq.c @@ -533,6 +533,26 @@ static int zynq_gpio_set_wake(struct irq_data *data, unsigned int on) return 0; } +static int zynq_gpio_irq_reqres(struct irq_data *d) +{ + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); + int ret; + + ret = pm_runtime_get_sync(chip->parent); + if (ret < 0) + return ret; + + return gpiochip_reqres_irq(chip, d->hwirq); +} + +static void zynq_gpio_irq_relres(struct irq_data *d) +{ + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); + + gpiochip_relres_irq(chip, d->hwirq); + pm_runtime_put(chip->parent); +} + /* irq chip descriptor */ static struct irq_chip zynq_gpio_level_irqchip = { .name = DRIVER_NAME, @@ -542,6 +562,8 @@ static struct irq_chip zynq_gpio_level_irqchip = { .irq_unmask = zynq_gpio_irq_unmask, .irq_set_type = zynq_gpio_set_irq_type, .irq_set_wake = zynq_gpio_set_wake, + .irq_request_resources = zynq_gpio_irq_reqres, + .irq_release_resources = zynq_gpio_irq_relres, .flags = IRQCHIP_EOI_THREADED | IRQCHIP_EOI_IF_HANDLED | IRQCHIP_MASK_ON_SUSPEND, }; @@ -554,6 +576,8 @@ static struct irq_chip zynq_gpio_edge_irqchip = { .irq_unmask = zynq_gpio_irq_unmask, .irq_set_type = zynq_gpio_set_irq_type, .irq_set_wake = zynq_gpio_set_wake, + .irq_request_resources = zynq_gpio_irq_reqres, + .irq_release_resources = zynq_gpio_irq_relres, .flags = IRQCHIP_MASK_ON_SUSPEND, }; -- 2.20.1