From 5561770f80b11786602726bf1fa172c8009e542b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Pouiller?= Date: Tue, 5 May 2020 14:37:47 +0200 Subject: [PATCH] staging: wfx: repair external IRQ for SDIO MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit When used over SDIO bus, device is able to use an external line to signal IRQs (also called Out-Of-Band IRQ). The current code have several problems: 1. The ISR cannot directly acknowledge IRQ since access to the bus is not atomic. This patch use a threaded IRQ to solve that issue. 2. On certain platforms, it is necessary to keep SDIO interruption enabled (with register SDIO_CCCR_IENx) (this part has inspired from the brcmfmac driver). Signed-off-by: Jérôme Pouiller Link: https://lore.kernel.org/r/20200505123757.39506-6-Jerome.Pouiller@silabs.com Signed-off-by: Greg Kroah-Hartman --- drivers/staging/wfx/bus_sdio.c | 38 ++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/drivers/staging/wfx/bus_sdio.c b/drivers/staging/wfx/bus_sdio.c index 0a63e76d3271..43a6b10c772a 100644 --- a/drivers/staging/wfx/bus_sdio.c +++ b/drivers/staging/wfx/bus_sdio.c @@ -6,10 +6,12 @@ * Copyright (c) 2010, ST-Ericsson */ #include +#include #include #include #include #include +#include #include "bus.h" #include "wfx.h" @@ -106,31 +108,41 @@ static irqreturn_t wfx_sdio_irq_handler_ext(int irq, void *priv) static int wfx_sdio_irq_subscribe(struct wfx_sdio_priv *bus) { + u32 flags; int ret; + u8 cccr; - if (bus->of_irq) { - ret = request_irq(bus->of_irq, wfx_sdio_irq_handler_ext, - IRQF_TRIGGER_RISING, "wfx", bus); - } else { + if (!bus->of_irq) { sdio_claim_host(bus->func); ret = sdio_claim_irq(bus->func, wfx_sdio_irq_handler); sdio_release_host(bus->func); + return ret; } - return ret; + + sdio_claim_host(bus->func); + cccr = sdio_f0_readb(bus->func, SDIO_CCCR_IENx, NULL); + cccr |= BIT(0); + cccr |= BIT(bus->func->num); + sdio_f0_writeb(bus->func, cccr, SDIO_CCCR_IENx, NULL); + sdio_release_host(bus->func); + flags = irq_get_trigger_type(bus->of_irq); + if (!flags) + flags = IRQF_TRIGGER_HIGH; + flags |= IRQF_ONESHOT; + return devm_request_threaded_irq(&bus->func->dev, bus->of_irq, NULL, + wfx_sdio_irq_handler_ext, flags, + "wfx", bus); } static int wfx_sdio_irq_unsubscribe(struct wfx_sdio_priv *bus) { int ret; - if (bus->of_irq) { - free_irq(bus->of_irq, bus); - ret = 0; - } else { - sdio_claim_host(bus->func); - ret = sdio_release_irq(bus->func); - sdio_release_host(bus->func); - } + if (bus->of_irq) + devm_free_irq(&bus->func->dev, bus->of_irq, bus); + sdio_claim_host(bus->func); + ret = sdio_release_irq(bus->func); + sdio_release_host(bus->func); return ret; } -- 2.25.1