Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4063042rdb; Thu, 14 Sep 2023 10:34:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHuLAVvHVNM7uJAYgMX4tAGYVDuTtiULdeinsyWnco9JAZGvICBKxWSqIp6Y8764NqjeV4B X-Received: by 2002:a05:6358:722:b0:13f:7e5:b397 with SMTP id e34-20020a056358072200b0013f07e5b397mr6267906rwj.7.1694712840801; Thu, 14 Sep 2023 10:34:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694712840; cv=none; d=google.com; s=arc-20160816; b=c5jvWFWJKydFTyfbCdPRpLmD+vSM4cbFCkpR8sJ8Wivyb3mBKAZayxLsA9bnxY1sY2 jouawmm32qnhnCXwcktHC8GnKuNPAFAyePjHWrasV1V2ENIiip+u3nEMQlO1vMRRwsK+ DsVSn8mqSkgj7EY+JruNzZSQslbkvTmYFJoL+sRxT/jkesU6no91O0eu37nijiXvqGwp oeMkvPgqck/2k6AmTinhvFXRElX8f0ewPGsVGT5AtQb7WniX2K8Ote/IzY/Rl5TdEiMi QsCql0WT/gA+EhVjxPBIOEL/zTpDagNayH7gHD3KvLj9r4Jp5DQsCHYoG6aWqvcbpzzd OTGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=w91AaSibQ2B9fGgOierSU9qFhPDlaKtKGncctMjLLGM=; fh=g6SNSbKWikwoCpcsPWztfCqlpI97qPh8qXzaJ8EGOt8=; b=ZNOsAuTtCuNJqpm2CcbGvLHHZP0rU1dn59FcjVhhhLjIQNmi0UH+/PwPEkw/oOT2t0 y/ntK4dMM7Vq8sRwt4sa45tWWX/xTvJltHsi2X/owwcZ2btbqm8HiAHdvn6fIh4MSlhz OOAWhwf+v+nTILREYFCrY07jdK12YRaeRgbzCHSAgN4ktewOc1RU2okxgffmIIMSfbTk Kaqx6HBvqeu/VlIzf2suE2CCTOebvhuqll7ieDftw/Lizh5iahLAmRRHAYc+z6Ezl/uT fay/lBu43FDgK8VGSjmcGvhGjbJ3dGmmONhaRDirRNP64UDptlx4qc4sGcFP/jGpj+QJ Y5jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=sRgWdbux; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id x14-20020a63170e000000b0055b79986063si1789278pgl.300.2023.09.14.10.34.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 10:34:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=sRgWdbux; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 762FB830D109; Thu, 14 Sep 2023 02:03:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236685AbjINJDI (ORCPT + 99 others); Thu, 14 Sep 2023 05:03:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236668AbjINJCy (ORCPT ); Thu, 14 Sep 2023 05:02:54 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E64C1BF1; Thu, 14 Sep 2023 02:02:29 -0700 (PDT) Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2DCF12CF; Thu, 14 Sep 2023 11:00:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1694682055; bh=ZSJzooOMl8o+UASvefvCSAyN9by/gcSLf34MmpDlkOA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=sRgWdbuxCqCfmaEXP0Wbi/MjJfDdjiaIJ6JrR+j3Fdan+E3YvXDF+1+7tdS6bbRSh jvuRtKEZsgVG8KQyyB36+OvBN5Vo0Xqs1SM6ao9T9HHSJ6xtlbVazYSW436gAE9A3E qIboFCnK8987DMfYzOQo9kHaVjNXETJ4J1oxcj+I= Date: Thu, 14 Sep 2023 12:02:41 +0300 From: Laurent Pinchart To: Jacopo Mondi Cc: Andrey Skvortsov , Sakari Ailus , Steve Longerbeam , Sakari Ailus , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Jarrah Gosbell , Arnaud Ferraris Subject: Re: [PATCH] media: ov5640: use pm_runtime_force_suspend/resume for system suspend Message-ID: <20230914090241.GA2504@pendragon.ideasonboard.com> References: <20230818173416.2467832-1-andrej.skvortzov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: 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 (groat.vger.email [0.0.0.0]); Thu, 14 Sep 2023 02:03:14 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email On Thu, Sep 14, 2023 at 10:54:40AM +0200, Jacopo Mondi wrote: > On Wed, Sep 13, 2023 at 11:48:13PM +0300, Andrey Skvortsov wrote: > > On 23-09-13 15:27, Sakari Ailus wrote: > > > On Fri, Aug 18, 2023 at 08:34:16PM +0300, Andrey Skvortsov wrote: > > > > If system was suspended while camera sensor was used, data and > > > > interrupts were still coming from sensor and that caused unstable > > > > system. Sometimes system hanged during a resume. Use > > > > pm_runtime_force_* helpers in order to support system suspend. > > > > > > > > Signed-off-by: Andrey Skvortsov > > > > > > Thanks for the patch. > > > > > > It's not been documented really how system suspend and resume should > > > work for complex cameras. But I don't think it can be done by drivers > > > separately as the CSI-2 bus initialisation requires actions from both > > > sender and receiver drivers, at particular points of time. > > > > Thanks for the review. > > > > I've tested this on PinePhone A64. It uses DVP, maybe because of that > > system suspend/resume worked good in my case. > > Originally I've implemented system suspend/resume similar to this [1] > > or [2] as I've seen this approach in other mainlined drivers. But some > > drivers reuse pm_runtime_force_* helpers, so I've went with this. > > > > Do you think it would be better to use something like [2] until there > > is better well defined way for system suspend/resume for complex cameras? > > > > please don't :) > https://patchwork.linuxtv.org/project/linux-media/patch/20230913135638.26277-16-laurent.pinchart@ideasonboard.com/ > > However... > > > > So I think we'll need to initiate this from the driver handling DMA, just > > > as starting and stopping streaming. Even then, there needs to be a > > > certainty that the sensor device has resumed before streaming is started. I > > > recall Laurent suggested device links for that purpose, but I don't think > > > any work has been done to implement it that way. > > .. as Sakari suggested, the driver handling the DMA should be in > charge of calling s_stream() on the sensor subdev in its > suspend/resume handlers. There's the risk the receiver resumes while > the sensor is still suspended, and at this time there's no solution in > mainline to handle this correctly. > > Laurent/Sakari, how should this be handled for the time being ? device_link() should handle this. See mxc_isi_async_notifier_bound() in drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c. It would be nice if this could be done in the V4L2 core. I haven't checked if that's possible. > Laurent's patch for imx219 (and his forthcoming patch to remove the > same pattern from all sensor drivers in mainline) might be opening th > door for unexpected bugs as long as we don't enforce a resume/suspend > ordering ? I'd argue that the bugs are there already, at least for CSI-2 sensors the use a continuous clock. If you resume streaming on the sensor first, the clock lane will switch to HS mode before the receiver gets resumed, and the receiver won't be able to synchronize. System suspend/resume tends to be badly tested in camera sensor drivers, so lots of bugs creep in :-( > > 1. https://salsa.debian.org/Mobian-team/devices/kernels/sunxi64-linux/-/blob/mobian-6.1/debian/patches/camera/0076-media-gc2145-implement-system-suspend.patch > > 2. https://elixir.bootlin.com/linux/latest/source/drivers/media/i2c/imx219.c#L1159 > > Can we get a link to the receiver driver you're using in your kernel ? -- Regards, Laurent Pinchart