Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752021AbdHNNxt (ORCPT ); Mon, 14 Aug 2017 09:53:49 -0400 Received: from mail-oi0-f46.google.com ([209.85.218.46]:33518 "EHLO mail-oi0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751098AbdHNNxr (ORCPT ); Mon, 14 Aug 2017 09:53:47 -0400 MIME-Version: 1.0 In-Reply-To: <72d3cd83bed792a23ab60cf9b6d51b618f5aa084.1502103715.git.michal.simek@xilinx.com> References: <72d3cd83bed792a23ab60cf9b6d51b618f5aa084.1502103715.git.michal.simek@xilinx.com> From: Linus Walleij Date: Mon, 14 Aug 2017 15:53:46 +0200 Message-ID: Subject: Re: [PATCH 2/8] gpio: zynq: Wakeup gpio controller when it is used as IRQ controller To: Michal Simek Cc: "linux-kernel@vger.kernel.org" , "monstr@monstr.eu" , Borsodi Petr , =?UTF-8?Q?S=C3=B6ren_Brinkmann?= , Steffen Trumtrar , Peter Crosthwaite , "linux-gpio@vger.kernel.org" , Rob Herring , Josh Cartwright , "linux-arm-kernel@lists.infradead.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3097 Lines: 94 On Mon, Aug 7, 2017 at 1:01 PM, Michal Simek wrote: > From: Borsodi Petr > > There is a problem with GPIO driver when used as IRQ controller. > It is not working because the module is sleeping (clock is disabled). > The patch enables clocks when IP is used as IRQ controller. > > Signed-off-by: Borsodi Petr > Signed-off-by: Michal Simek I'm a bit worried about this patch. > +static int zynq_gpio_irq_request_resources(struct irq_data *d) > +{ > + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); > + int ret; > + > + if (!try_module_get(chip->gpiodev->owner)) > + return -ENODEV; You are poking around in gpiolib internals, I don't really like that. I prefer that you use accessors and try to make the core deal with this instead of fixing it up with a local hack in the driver. > + ret = pm_runtime_get_sync(chip->parent); > + if (ret < 0) { > + module_put(chip->gpiodev->owner); > + return ret; > + } What you essentially do is disable runtime PM while IRQs are in use, the patch commit log should say this. > + if (gpiochip_lock_as_irq(chip, d->hwirq)) { > + chip_err(chip, "unable to lock HW IRQ %lu for IRQ\n", d->hwirq); > + pm_runtime_put(chip->parent); > + module_put(chip->gpiodev->owner); > + return -EINVAL; > + } This is essentially a separate patch that should be done orthogonally. (I don't care super-much about that though.) > +static void zynq_gpio_irq_release_resources(struct irq_data *d) > +{ > + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); > + > + gpiochip_unlock_as_irq(chip, d->hwirq); > + pm_runtime_put(chip->parent); > + module_put(chip->gpiodev->owner); > +} (...) > + .irq_request_resources = zynq_gpio_irq_request_resources, > + .irq_release_resources = zynq_gpio_irq_release_resources, Look at this from gpiolib.c: static int gpiochip_irq_reqres(struct irq_data *d) { struct gpio_chip *chip = irq_data_get_irq_chip_data(d); if (!try_module_get(chip->gpiodev->owner)) return -ENODEV; if (gpiochip_lock_as_irq(chip, d->hwirq)) { chip_err(chip, "unable to lock HW IRQ %lu for IRQ\n", d->hwirq); module_put(chip->gpiodev->owner); return -EINVAL; } return 0; } static void gpiochip_irq_relres(struct irq_data *d) { struct gpio_chip *chip = irq_data_get_irq_chip_data(d); gpiochip_unlock_as_irq(chip, d->hwirq); module_put(chip->gpiodev->owner); } If you add pm_runtime_get_sync()/put to this and export the functions you have the same thing and you can just reuse this code instead of copying it. Arguably the above should indeed have that runtime PM code (unless we know a better way to deal with IRQs). So can we fix this in the core and reuse it from there? Yours, Linus Walleij