From patchwork Mon Mar 13 18:38:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Keeping X-Patchwork-Id: 9621823 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6D3BA604CC for ; Mon, 13 Mar 2017 18:41:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62A43284EF for ; Mon, 13 Mar 2017 18:41:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 575E828502; Mon, 13 Mar 2017 18:41:54 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0881A284EF for ; Mon, 13 Mar 2017 18:41:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=1JNwnZMGWdX5EgoxpfPHJf4MzBOxUpdGZAKmaP/b9gs=; b=T/6h7273Z2JXmmkCwhni5wqBDz //TvwHWy8/xQAjw3byDoajVG4wLTsuqhTr8G38sj8NRe/Hl0Cys9Z/VHH6HyPSLtyVHa8nYqAzFyd poo9hJHxMgIDTP7/vvBPX1XPsF6jTY4EYFQTNGrjGpCxTkeSPFi3c4oKHjepGa4JOuNBBDGvg066G YywRFmjoB0KlOGvoWsQn5y+teEnxzNEBJlLz683IItc1uFyz879mTY+csj1mjwQmH2csf26OP/hOC FVBEzfHXK9eQwEx3opgJEL4HHQEIcOomdcpi2JhVGx9rKqn6Q7OaoAf8lgXA+DPHGIfvIqYt/Ec8N nmvFzixA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cnUun-0004cN-G0; Mon, 13 Mar 2017 18:41:53 +0000 Received: from dougal.metanate.com ([90.155.101.14] helo=metanate.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cnUs3-0001j6-Pe; Mon, 13 Mar 2017 18:39:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=simple/simple; d=metanate.com; s=stronger; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=hEFt0GnUZiI5DBtOt4ZleGlnipv62KJZ5isHtiVwxV4=; b=EpAwHwvShhS/9M8ZuBxhIsvPlLKkzDDzM4K4j7wOg/0j41Dbl/53Gwfzk6dSCWsu+Ej2z3Er6/vW4/5Eg03E5nGkSYdkAPNVLFM2OlNOaND9fRnSa23gP5+X2oNQsIwnGIGWwAG6IYmp1DUxIOBEoJrl94gIST6GXHP82Ec1A10GKC58CdfL4dQfQMxxIcmC4zqbVS4HywpX1yPdMxZSX6ZPoj3ESD3OV2QQXcl0lZJVnkYJqg80EHlT+6k+fAyKAsfPzb0pRXoJBedExSmpCBqdWAgKLh9nSTI4xxrA2kPW1QVx5j4SIZ+jBVzbUisG+TAHyZbHqjm49ZHZqEoE+g==; Received: from brian ([192.168.88.1] helo=leela.metanate.com) by shrek.metanate.com with esmtpsa (TLSv1.2:DHE-RSA-AES128-GCM-SHA256:128) (Exim 4.83_RC2) (envelope-from ) id 1cnUrR-00060b-9o; Mon, 13 Mar 2017 18:38:25 +0000 From: John Keeping To: Heiko Stuebner Subject: [RFC PATCH 4/4] pinctrl: rockchip: avoid hardirq-unsafe functions in irq_chip Date: Mon, 13 Mar 2017 18:38:13 +0000 Message-Id: <20170313183813.3582-5-john@metanate.com> X-Mailer: git-send-email 2.12.0.377.gf910686b23.dirty In-Reply-To: <20170313183813.3582-1-john@metanate.com> References: <20170313183813.3582-1-john@metanate.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170313_113904_087017_D2530849 X-CRM114-Status: GOOD ( 10.47 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-rockchip@lists.infradead.org, Linus Walleij , linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, John Keeping , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP With real-time preemption, regmap functions cannot be used in the implementation of irq_chip since they use spinlocks which may sleep. Move the setting of the mux for IRQs to an irq_bus_sync_unlock handler where we are allowed to sleep. Signed-off-by: John Keeping Reviewed-by: Heiko Stuebner --- drivers/pinctrl/pinctrl-rockchip.c | 44 ++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c index 52e70c4aef7c..80f7c23d12d4 100644 --- a/drivers/pinctrl/pinctrl-rockchip.c +++ b/drivers/pinctrl/pinctrl-rockchip.c @@ -143,6 +143,9 @@ struct rockchip_drv { * @gpio_chip: gpiolib chip * @grange: gpio range * @slock: spinlock for the gpio bank + * @irq_lock: bus lock for irq chip + * @new_irqs: newly configured irqs which must be muxed as GPIOs in + * irq_bus_sync_unlock() */ struct rockchip_pin_bank { void __iomem *reg_base; @@ -165,6 +168,8 @@ struct rockchip_pin_bank { struct pinctrl_gpio_range grange; raw_spinlock_t slock; u32 toggle_edge_mode; + struct mutex irq_lock; + u32 new_irqs; }; #define PIN_BANK(id, pins, label) \ @@ -2045,11 +2050,12 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type) int ret; /* make sure the pin is configured as gpio input */ - ret = rockchip_set_mux(bank, d->hwirq, RK_FUNC_GPIO); + ret = rockchip_verify_mux(bank, d->hwirq, RK_FUNC_GPIO); if (ret < 0) return ret; - clk_enable(bank->clk); + bank->new_irqs |= mask; + raw_spin_lock_irqsave(&bank->slock, flags); data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR); @@ -2107,7 +2113,6 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type) default: irq_gc_unlock(gc); raw_spin_unlock_irqrestore(&bank->slock, flags); - clk_disable(bank->clk); return -EINVAL; } @@ -2116,7 +2121,6 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type) irq_gc_unlock(gc); raw_spin_unlock_irqrestore(&bank->slock, flags); - clk_disable(bank->clk); return 0; } @@ -2160,6 +2164,34 @@ static void rockchip_irq_gc_mask_set_bit(struct irq_data *d) clk_disable(bank->clk); } +static void rockchip_irq_bus_lock(struct irq_data *d) +{ + struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); + struct rockchip_pin_bank *bank = gc->private; + + clk_enable(bank->clk); + mutex_lock(&bank->irq_lock); +} + +static void rockchip_irq_bus_sync_unlock(struct irq_data *d) +{ + struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); + struct rockchip_pin_bank *bank = gc->private; + + while (bank->new_irqs) { + unsigned int irq = __ffs(bank->new_irqs); + int ret; + + ret = rockchip_set_mux(bank, irq, RK_FUNC_GPIO); + WARN_ON(ret < 0); + + bank->new_irqs &= ~BIT(irq); + } + + mutex_unlock(&bank->irq_lock); + clk_disable(bank->clk); +} + static int rockchip_interrupts_register(struct platform_device *pdev, struct rockchip_pinctrl *info) { @@ -2225,6 +2257,9 @@ static int rockchip_interrupts_register(struct platform_device *pdev, gc->chip_types[0].chip.irq_suspend = rockchip_irq_suspend; gc->chip_types[0].chip.irq_resume = rockchip_irq_resume; gc->chip_types[0].chip.irq_set_type = rockchip_irq_set_type; + gc->chip_types[0].chip.irq_bus_lock = rockchip_irq_bus_lock; + gc->chip_types[0].chip.irq_bus_sync_unlock = + rockchip_irq_bus_sync_unlock; gc->wake_enabled = IRQ_MSK(bank->nr_pins); irq_set_chained_handler_and_data(bank->irq, @@ -2398,6 +2433,7 @@ static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data( int bank_pins = 0; raw_spin_lock_init(&bank->slock); + mutex_init(&bank->irq_lock); bank->drvdata = d; bank->pin_base = ctrl->nr_pins; ctrl->nr_pins += bank->nr_pins;