From patchwork Mon Dec 18 07:54:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 13496338 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6F407C35274 for ; Mon, 18 Dec 2023 07:54:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=t2UoZn8FKfXNtosKrxi6zXviz/2MO/WrEDAb01hLmYw=; b=Y5c7yQOZwd0vK1 mMJfHK6SCgiU0eJCS/sKFB99xh1SHCxuprMuPpSTMp1N1z7jML0STB3b16ZwPfK/0M82NyBs6+bPS 4c4p2iICLB8wnL+HY5Sbijc6VCKv4dR3Y6vuCu9AQWFExYeIuPSZZ4825pzzINp/ALr5259ZkPWiD Cf8mh8P/DXSX9Wz2JuNCIWYKPVqUpUZd/MvKpvQL/I6l+aeVLwFbInnNGkEk7lw8w7hc94TE4Z8zk eOO8EOq1PUuEP6qzfsC/LIns5S4OFS9UswzzekeJ/8tEF3t2DK3rvD2RFmDQ/mKeExyOneRB3OHXa PdK7Vidrg/PYVDV+u7VA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rF8Sc-009PUM-29; Mon, 18 Dec 2023 07:54:46 +0000 Received: from perceval.ideasonboard.com ([213.167.242.64]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rF8SS-009PP6-07; Mon, 18 Dec 2023 07:54:38 +0000 Received: from [127.0.1.1] (91-158-149-209.elisa-laajakaista.fi [91.158.149.209]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9FE2B15B5; Mon, 18 Dec 2023 08:53:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1702886022; bh=zKagm460JpwxYXaiONH9XZnoH9bqVXdR1WvL7VlcgPg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=UZ0HkyAXp0K6m61+0qI4QyfcUIVUvcqLclmfDU67REsE8ZfqfcLgZ8gaVBBlg5M4e RAHZwBKl7WoShNtHrcPaGP3Kaf+q1lLe2m3MEyJFlqKsUySXb4zDSugt44hAeiT7CN h6oK/GfCuD7ajijxHZkrzIBzuQaCQ0XVq63a1A+g= From: Tomi Valkeinen Date: Mon, 18 Dec 2023 09:54:00 +0200 Subject: [PATCH 1/2] Revert "media: rkisp1: Drop IRQF_SHARED" MIME-Version: 1.0 Message-Id: <20231218-rkisp-shirq-fix-v1-1-173007628248@ideasonboard.com> References: <20231218-rkisp-shirq-fix-v1-0-173007628248@ideasonboard.com> In-Reply-To: <20231218-rkisp-shirq-fix-v1-0-173007628248@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Mauro Carvalho Chehab , Heiko Stuebner , Mikhail Rudenko Cc: Kieran Bingham , Paul Elder , linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Tomi Valkeinen X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=1189; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=zKagm460JpwxYXaiONH9XZnoH9bqVXdR1WvL7VlcgPg=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBlf/q0m1ZIhyfN/VQk1p4R2SkQxrKhz3E9a2wPW 6hvqYULuVaJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZX/6tAAKCRD6PaqMvJYe 9bLNEACOty+4zxtY9WKiAGyTNrH8gGUraTQv7Lo+htgeNcqEo95ymQx18BlRQMdP1TtPRnentdv mzFgEFveizwSX3bnVOY5lcNQtxyKkW1B1p3np9srUTq6yiFZ97KMqBQbiieN230zTLZUB4dwM3o wl/QoUKqXtCG4ocCoNzeF+gN9TmY+qLZ+phCq+L4ARxS/60hDUAqGBC8d+cA2bPIqWHORLuc0qP v/QQvjd0ymziGbtraMevbf9EqR8PEi6silm42AorU4zKruoOsFdtxkmbmfFYV3bAAhlNc//J51T K2P6WhPAIfrI8sMa0Zg8zRYjuD1meRXk4P8BRFbDH48rCFvqXm0eTMorOdxeaSiY9A3z6graMtF GFX+baqtbsipwjCMRJcckdj02U7CQHBraMY221RcC0eFcQ/a6JrX+fNubr5LdcfIZTP5gO+B2Ry c2+xSKnYhJ+VGaap4sDz7gD3+N7d5+uH1oTVaNGwsfo1iH2LPs6lU7EusuQhD0bnBXgl27IsJCr /gymAeYlkfRAGFdBuv7WIrjTdvktUZvFOeCTPp55FoN9a1ZjF3GD5ABmspPd+7MlNfjb5MgnnfY 9LNN3uspWtvTF8swjdCfgRJfPCAGP8piVIxyKd4jENI0abQiC7qJnrDeihBfSJAnrmcPIXKPxs9 Ne7T6oN1g+q8z3Q== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231217_235436_298124_CA906E2B X-CRM114-Status: GOOD ( 11.34 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org This reverts commit 85d2a31fe4d9be1555f621ead7a520d8791e0f74. The rkisp1 does share interrupt lines on some platforms, after all. Thus we need to revert this, and implement a fix for the rkisp1 shared irq handling in a follow-up patch. Reported-by: Mikhail Rudenko Closes: https://lore.kernel.org/all/87o7eo8vym.fsf@gmail.com/ Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart --- drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c index f96f821a7b50..acc559652d6e 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c @@ -559,7 +559,7 @@ static int rkisp1_probe(struct platform_device *pdev) rkisp1->irqs[il] = irq; } - ret = devm_request_irq(dev, irq, info->isrs[i].isr, 0, + ret = devm_request_irq(dev, irq, info->isrs[i].isr, IRQF_SHARED, dev_driver_string(dev), dev); if (ret) { dev_err(dev, "request irq failed: %d\n", ret); From patchwork Mon Dec 18 07:54:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 13496337 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C05C6C46CD2 for ; Mon, 18 Dec 2023 07:54:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/MdlKUzurFN+c/NiFL3C7KFB3gP+ORvLXA+e1J1USEs=; b=awzsL6UmUYAd1n 843+kVqbLTMxNul8lr2+BN+id+5XwA0u0FjN34/FDc5Clth2JF3OmL6BaaFQffwlv22LojZ2StTD7 5dbKzbuVV5CdhD6Gawi81jcv2R9KfcrUZaWpgH8ozXWZ1gwY7tHVU8SETQeOg9U1OvDNrqwZihAR6 0UeJ+9ntmMNb4xcC9YQ37eQbnXj0nVaB79DHtK3AgB7fdivB5mAcDVUi05Nlglv2opSjMvHVqnIOc l8Ls9YV+gUOKrPaxtdhJy17XlYX7JigDCiOidkG9+VXTisfirxmXK+bPfFGEeMdZWrhXF/7Ws2VoU roflRGR2Gn767uAwUrOw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rF8SW-009PRL-2t; Mon, 18 Dec 2023 07:54:40 +0000 Received: from perceval.ideasonboard.com ([213.167.242.64]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rF8SR-009PP7-31; Mon, 18 Dec 2023 07:54:37 +0000 Received: from [127.0.1.1] (91-158-149-209.elisa-laajakaista.fi [91.158.149.209]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6C61C17E1; Mon, 18 Dec 2023 08:53:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1702886023; bh=VDN1suJaU5z+jG7P1v66MdGb21xQzNSju14tW5jmG7o=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=foXNIT6oCI3FbtDsp/JLvb8jXGr4NkF0SUp2AmuPmd+bthhLkmrrfeODZBeabQfoQ PGFjQt0RqS0nZlQFTSnWpgNhfnLX50q5FK7X9ClZk4/BUEjDWOiREQylaZALyS+7/e YViUDSwLvu2L0x0eidHR/5lTW79T8B/OP0vHlW9M= From: Tomi Valkeinen Date: Mon, 18 Dec 2023 09:54:01 +0200 Subject: [PATCH 2/2] media: rkisp1: Fix IRQ handling due to shared interrupts MIME-Version: 1.0 Message-Id: <20231218-rkisp-shirq-fix-v1-2-173007628248@ideasonboard.com> References: <20231218-rkisp-shirq-fix-v1-0-173007628248@ideasonboard.com> In-Reply-To: <20231218-rkisp-shirq-fix-v1-0-173007628248@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Mauro Carvalho Chehab , Heiko Stuebner , Mikhail Rudenko Cc: Kieran Bingham , Paul Elder , linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Tomi Valkeinen X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=4836; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=VDN1suJaU5z+jG7P1v66MdGb21xQzNSju14tW5jmG7o=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBlf/q0hIJva5BYwMg2k1BnwgKKL0b0LTvAfpzZI uM6u3QAj9eJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZX/6tAAKCRD6PaqMvJYe 9R8MD/4+BFDmq2y0WAYJccdpaV/7jBxDo1utw3M8tpuTNA5b6aN4Ta+v7ASUp3hdefBtnyNweEq Sr7GjqXxDmTXyivRGDHamXT+WEyYauQTcy2q6O4uM6n8KMVE+0d0zleQ13KIuhsa2CQhdrLcISc FkMvtbv6OY7Q94eYFUMXv3XYkpqfLAcXOziuelsl0lCMDKYZCIUWNiSQM15lIYddpsIlsCu0/L3 XFaaYXwmT4Een1UpMMwW9qSMJrwfGxsv4p9oJj28yfIxoxR8OqEmk5rz8nyNPRieZmpGi/DIpK1 2D+95EIlXs5LUfjqNXYvhHP8NBrjSFzfQLLSUqVDyw4IdeVxR5EDEdWHQ2klCjDBUWc1P8QcJlw O85F2lIGlOm231lWmIKglJA0stleqUKATzcsw7ixEAOxweh5cpfbdb57RVX1iIh2X0iTfM1IoR/ 8Up9CPFIuRJRB5Tfd8qb0wZrYXyblEej75WN05r5u8N8qvkHhTr+Hk62kPvm+pnvfn4Hd+g2Hu1 YytCOvFsLg4xBSy6lenERjN2jZxw6OfPTcTm0kuNG7MHK9hrxKksO0evUKceoQ8xPllVMx5bL7A 1fwTAUDLwJ+sVv33FmTAsBYWRMMrWpMDRTSqBgoI58ugNdel1WWcMEJuDdTM/4gme9/HJkxYtNK ZGwkT9NuHv3P72Q== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231217_235436_149416_EF2F8152 X-CRM114-Status: GOOD ( 18.97 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org The driver requests the interrupts as IRQF_SHARED, so the interrupt handlers can be called at any time. If such a call happens while the ISP is powered down, the SoC will hang as the driver tries to access the ISP registers. This can be reproduced even without the platform sharing the IRQ line: Enable CONFIG_DEBUG_SHIRQ and unload the driver, and the board will hang. Fix this by adding a new field, 'irqs_enabled', which is used to bail out from the interrupt handler when the ISP is not operational. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart --- .../platform/rockchip/rkisp1/rkisp1-capture.c | 3 +++ .../media/platform/rockchip/rkisp1/rkisp1-common.h | 2 ++ .../media/platform/rockchip/rkisp1/rkisp1-csi.c | 3 +++ .../media/platform/rockchip/rkisp1/rkisp1-dev.c | 22 ++++++++++++++++++++++ .../media/platform/rockchip/rkisp1/rkisp1-isp.c | 3 +++ 5 files changed, 33 insertions(+) diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c index aebd3c12020b..c381c22135a2 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c @@ -725,6 +725,9 @@ irqreturn_t rkisp1_capture_isr(int irq, void *ctx) unsigned int i; u32 status; + if (!rkisp1->irqs_enabled) + return IRQ_NONE; + status = rkisp1_read(rkisp1, RKISP1_CIF_MI_MIS); if (!status) return IRQ_NONE; diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h index 4b6b28c05b89..b757f75edecf 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h @@ -450,6 +450,7 @@ struct rkisp1_debug { * @debug: debug params to be exposed on debugfs * @info: version-specific ISP information * @irqs: IRQ line numbers + * @irqs_enabled: the hardware is enabled and can cause interrupts */ struct rkisp1_device { void __iomem *base_addr; @@ -471,6 +472,7 @@ struct rkisp1_device { struct rkisp1_debug debug; const struct rkisp1_info *info; int irqs[RKISP1_NUM_IRQS]; + bool irqs_enabled; }; /* diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c index b6e47e2f1b94..4202642e0523 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c @@ -196,6 +196,9 @@ irqreturn_t rkisp1_csi_isr(int irq, void *ctx) struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); u32 val, status; + if (!rkisp1->irqs_enabled) + return IRQ_NONE; + status = rkisp1_read(rkisp1, RKISP1_CIF_MIPI_MIS); if (!status) return IRQ_NONE; diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c index acc559652d6e..73cf08a74011 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c @@ -305,6 +305,24 @@ static int __maybe_unused rkisp1_runtime_suspend(struct device *dev) { struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); + rkisp1->irqs_enabled = false; + /* Make sure the IRQ handler will see the above */ + mb(); + + /* + * Wait until any running IRQ handler has returned. The IRQ handler + * may get called even after this (as it's a shared interrupt line) + * but the 'irqs_enabled' flag will make the handler return immediately. + */ + for (unsigned int il = 0; il < ARRAY_SIZE(rkisp1->irqs); ++il) { + if (rkisp1->irqs[il] == -1) + continue; + + /* Skip if the irq line is the same as previous */ + if (il == 0 || rkisp1->irqs[il - 1] != rkisp1->irqs[il]) + synchronize_irq(rkisp1->irqs[il]); + } + clk_bulk_disable_unprepare(rkisp1->clk_size, rkisp1->clks); return pinctrl_pm_select_sleep_state(dev); } @@ -321,6 +339,10 @@ static int __maybe_unused rkisp1_runtime_resume(struct device *dev) if (ret) return ret; + rkisp1->irqs_enabled = true; + /* Make sure the IRQ handler will see the above */ + mb(); + return 0; } diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c index f00873d31c42..78a1f7a1499b 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c @@ -976,6 +976,9 @@ irqreturn_t rkisp1_isp_isr(int irq, void *ctx) struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); u32 status, isp_err; + if (!rkisp1->irqs_enabled) + return IRQ_NONE; + status = rkisp1_read(rkisp1, RKISP1_CIF_ISP_MIS); if (!status) return IRQ_NONE;