Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp135719rdb; Tue, 5 Dec 2023 00:27:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IH8wSd11n8mUsYOOtXUeMfzn4hWPGZ0y79D5gz3XS80JAl1Hshi6cZ8E+ty/gxUF1SPn8mA X-Received: by 2002:a05:6358:2626:b0:170:7cd:4c5f with SMTP id l38-20020a056358262600b0017007cd4c5fmr8960533rwc.10.1701764868411; Tue, 05 Dec 2023 00:27:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701764868; cv=none; d=google.com; s=arc-20160816; b=KCmq7X3LWFSQjam6zzvI+puOcIKMeyze8QqULvIM8KgA9iNE/m5XhSaVuDPPBmTMPO T1rcpxP8lzZhlwuAAVyl5VfXUCHzBjelSyqLa59jNybUiTb5OgAqMxo4mTVV+DmuhmvM rtk2TImvTyurPRg2//KHtDd7Y8UniZB7livjVQL17FsyKX5uP985RPO99WDajh0krEn/ MorbDyFA8dzR1HLEHa+C7Ro2Rpy24hmuYwcNH72RvobRKIyEXFZU6hxi0l1jAl1P2A2N VUEC9GBXbSm0YXMi12y7qE2g2eDA+SN32Z/wXbmfFDeJivNq04WX+lnqOPKvQJobcZot 0TOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:autocrypt :from:references:cc:to:content-language:subject:user-agent :mime-version:date:message-id:dkim-signature; bh=MYg+lTR8n/7sj1v4Q/nV6m6NpN2Aj3jm6xqbggIr50o=; fh=tme7j8kxe+bl8/nZ+qVhPWeazCvcSJ8NfR7yBtPaJyw=; b=VCccRTD4vtgmjsQX2nfsrxuAItIpexhqzYyyYf/FBgnD2GpcCoKOtHr1xHCQx1sljM m/NIWOM/Q2LrK2L7t3wDNp8mThBpytolZzbPVO2d9Bri7Vm4/oRpX4smXh05m3/Hv7RP 6nV7ShIJW9J8ZZFiH6dod6xRXgT7jQhtWZRKEbF/RYJcFsxD/waAue4GNxiGjca3gxl6 hMvl4HI6kHOqQ2CMOLEWWIpXpIrTVTsWF4FiF0OJpXVC5p/Aezp89H7xl7n+KC7SIawp kNbLM0Ek1Y/QUhUoS0dI/ZEu/8lhzCktVweuDxY5nJ0XpkE1/gOwe1P9RBeiMUAL9253 KSMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=GLdhIJbF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id n5-20020a635c45000000b005c5fe7661c7si4587028pgm.359.2023.12.05.00.27.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 00:27:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=GLdhIJbF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 2F2CB8040EA6; Tue, 5 Dec 2023 00:27:47 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231714AbjLEI1f (ORCPT + 99 others); Tue, 5 Dec 2023 03:27:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229712AbjLEI1e (ORCPT ); Tue, 5 Dec 2023 03:27:34 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C52A4FA; Tue, 5 Dec 2023 00:27:40 -0800 (PST) Received: from [192.168.88.20] (91-158-149-209.elisa-laajakaista.fi [91.158.149.209]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4ABA64DB; Tue, 5 Dec 2023 09:26:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1701764819; bh=2bWSQJ91KzxSVZZxT/S36qXml+6Tqw1sYUSNGxv6iGw=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=GLdhIJbFPt4zgN4FTYoadYmU7ouvQUXJvq3ThTc4rY3HAmTmAfAUp9LRkTUWgm2if 0vQpGOTGw34wB/8TU7u2xlV8G8MOgSdKgJB5uN9pZuSKnlrHjjuwB3yUbFWn1/5IkF D3dsnS/fpJgAQADa8dAJ1+D1wo2LfqLzv8hBw0Nw= Message-ID: <9b28dcf7-c9a0-4d68-9197-cdcdd9f0393b@ideasonboard.com> Date: Tue, 5 Dec 2023 10:27:34 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 3/4] media: rkisp1: Fix IRQ handling due to shared interrupts Content-Language: en-US To: Laurent Pinchart Cc: Dafna Hirschfeld , Mauro Carvalho Chehab , Heiko Stuebner , Paul Elder , Alexander Stein , kieran.bingham@ideasonboard.com, umang.jain@ideasonboard.com, aford173@gmail.com, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20231205-rkisp-irq-fix-v1-0-f4045c74ba45@ideasonboard.com> <20231205-rkisp-irq-fix-v1-3-f4045c74ba45@ideasonboard.com> <20231205082016.GA17394@pendragon.ideasonboard.com> From: Tomi Valkeinen Autocrypt: addr=tomi.valkeinen@ideasonboard.com; keydata= xsFNBE6ms0cBEACyizowecZqX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EXpZcIOQjQ71fqlpiXkXSIaQ6YMEs8WjBbpP81h7QxWIfWtp+VnwNGc6nq5IQDESH mvQcsFS7d3eGVI6eyjCFdcAO8eMAEQEAAcLBXwQYAQIACQUCTqazRwIbDAAKCRD6PaqMvJYe 9fA7EACS6exUedsBKmt4pT7nqXBcRsqm6YzT6DeCM8PWMTeaVGHiR4TnNFiT3otD5UpYQI7S suYxoTdHrrrBzdlKe5rUWpzoZkVK6p0s9OIvGzLT0lrb0HC9iNDWT3JgpYDnk4Z2mFi6tTbq xKMtpVFRA6FjviGDRsfkfoURZI51nf2RSAk/A8BEDDZ7lgJHskYoklSpwyrXhkp9FHGMaYII m9EKuUTX9JPDG2FTthCBrdsgWYPdJQvM+zscq09vFMQ9Fykbx5N8z/oFEUy3ACyPqW2oyfvU CH5WDpWBG0s5BALp1gBJPytIAd/pY/5ZdNoi0Cx3+Z7jaBFEyYJdWy1hGddpkgnMjyOfLI7B CFrdecTZbR5upjNSDvQ7RG85SnpYJTIin+SAUazAeA2nS6gTZzumgtdw8XmVXZwdBfF+ICof 92UkbYcYNbzWO/GHgsNT1WnM4sa9lwCSWH8Fw1o/3bX1VVPEsnESOfxkNdu+gAF5S6+I6n3a ueeIlwJl5CpT5l8RpoZXEOVtXYn8zzOJ7oGZYINRV9Pf8qKGLf3Dft7zKBP832I3PQjeok7F yjt+9S+KgSFSHP3Pa4E7lsSdWhSlHYNdG/czhoUkSCN09C0rEK93wxACx3vtxPLjXu6RptBw 3dRq7n+mQChEB1am0BueV1JZaBboIL0AGlSJkm23kw== In-Reply-To: <20231205082016.GA17394@pendragon.ideasonboard.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 05 Dec 2023 00:27:47 -0800 (PST) On 05/12/2023 10:20, Laurent Pinchart wrote: > Hi Tomi, > > Thank you for the patch. > > On Tue, Dec 05, 2023 at 10:09:34AM +0200, Tomi Valkeinen wrote: >> 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. > > Is IRQF_SHARED actually needed ? I don't have any answer to that, but it seems to have always been there. Dropping it would simplify the code, but we can only do that if we are sure all the platforms the ISP is used on or will be used on won't share the interrupt. Tomi >> 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 >> --- >> .../media/platform/rockchip/rkisp1/rkisp1-capture.c | 3 +++ >> .../media/platform/rockchip/rkisp1/rkisp1-common.h | 2 ++ >> drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c | 3 +++ >> drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c | 21 +++++++++++++++++++++ >> drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c | 3 +++ >> 5 files changed, 32 insertions(+) >> >> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c >> index b50b044d22af..e92067897f28 100644 >> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c >> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c >> @@ -779,6 +779,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 ec28907d978e..7f97fdf6e24c 100644 >> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h >> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h >> @@ -465,6 +465,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; >> @@ -488,6 +489,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 47f4353a1784..f6b54654b435 100644 >> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c >> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-csi.c >> @@ -184,6 +184,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 1d60f4b8bd09..fbe03f7864e3 100644 >> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c >> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c >> @@ -306,6 +306,23 @@ 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 i = 0; i < RKISP1_NUM_IRQS; ++i) { >> + if (rkisp1->irqs[i] == -1) >> + continue; >> + >> + if (i == 0 || rkisp1->irqs[i - 1] != rkisp1->irqs[i]) >> + synchronize_irq(rkisp1->irqs[i]); >> + } >> + >> clk_bulk_disable_unprepare(rkisp1->clk_size, rkisp1->clks); >> return pinctrl_pm_select_sleep_state(dev); >> } >> @@ -322,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 dafbfd230542..d6b8786661ad 100644 >> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c >> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c >> @@ -1082,6 +1082,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; >