From patchwork Wed Mar 15 17:46:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Keeping X-Patchwork-Id: 9626305 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 BC71F6048C for ; Wed, 15 Mar 2017 17:48:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B29B628665 for ; Wed, 15 Mar 2017 17:48:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A728528669; Wed, 15 Mar 2017 17:48:32 +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 30A8728665 for ; Wed, 15 Mar 2017 17:48:32 +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=rb83Moxx3JeGC3w8en87amq21CXT9drAR+s1Ny5hd20=; b=ZsQI4FZWK1H03H+PzI8hN2eFd3 bIrRmCb3nUGzbM8y1EAUbSG8FI0Fk4p0hmj3KlIn5vTLmbPqZo9bqwOoIkA8CIz9hmQpvr0YVxtzV oZ/z3BqmIh/JFv0AYGquJz4J3BYRq0CbnhzRpV7CfY11gg8UqJD8uqYY2D+xrGFg/9oFaFob8C3yK aj5ea6/iUgNGCDSEQ8V0QaUSfwPFQHOMTSlP1Iw6W5QirYVtWKKHw+4sNtAUsdk57hZIsMJqIEGWy lW1IVPisH0hDgIpIeJ48kZSl6VRIou7nuDsNvN1JJLcgqqy6NnAcXsDtbHoxMJ84oMaBM9dCpqIH9 9Bo39ZpA==; 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 1coD2F-0003z2-5e; Wed, 15 Mar 2017 17:48:31 +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 1coD1K-0002oN-LF; Wed, 15 Mar 2017 17:47:37 +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=z5p8a8g3dzmbWeCXsbo8rXAuTcMF+mWyYmzRJE90C58=; b=e47+p2Ig1w3wjUXZ4AzYLqHhklFbK7+cYZg0kccK37NVb8d1pK/LlRQZ4ikI1ANWaJ9tLLpvkWV6ozX1c05MIHZydCaFg2AbHroYsJNHJZpWQrWJChi4t3M042SPuuBZKs/urqMexl6D0iOSGoVjlkTdbIt6//jaMoxj1hAOGCZe6/8qfks/5fDCPOpR1ZH6HHlH4KHEd5xuaYj55f8fATdiUOhzGp5QZ9/Zhs2kr84jri338Iq3EIbm/CFYWCY14pt/uTTl/MjkMV3BdUIbfiL5VdH2GESaYreVeg6gMOpnefvVGv+sRI9UocIeX65om2j7fVpnexHNYOtNOLuYFw==; 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 1coD0t-00055n-9x; Wed, 15 Mar 2017 17:47:07 +0000 From: John Keeping To: Heiko Stuebner Subject: [PATCH v2 4/4] pinctrl: rockchip: avoid hardirq-unsafe functions in irq_chip Date: Wed, 15 Mar 2017 17:46:54 +0000 Message-Id: <20170315174654.15128-5-john@metanate.com> X-Mailer: git-send-email 2.12.0.377.gf910686b23.dirty In-Reply-To: <20170315174654.15128-1-john@metanate.com> References: <20170315174654.15128-1-john@metanate.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170315_104734_971296_62D72D56 X-CRM114-Status: GOOD ( 10.64 ) 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-gpio@vger.kernel.org, Linus Walleij , Julia Cartwright , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.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 Tested-by: Heiko Stuebner --- v2: unchanged --- 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 426f5ea57b16..5796b3c7cdd8 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) \ @@ -2134,11 +2139,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); @@ -2196,7 +2202,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; } @@ -2205,7 +2210,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; } @@ -2249,6 +2253,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) { @@ -2314,6 +2346,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, @@ -2487,6 +2522,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;