From patchwork Fri Apr 15 15:27:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Kocialkowski X-Patchwork-Id: 12815107 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 51EEAC433F5 for ; Fri, 15 Apr 2022 15:42:16 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xKdrGjHyGbl8hhx44WJeEfYIkFrKWQku5RmtGrNwk+E=; b=UfNwvAONQPSHTK Ss8STeOOn+mmeu0wqWfyBIeC34OFtsz9yqGl/rUOeUxWqtxTTJ1APR40BkNfBSY7FUY4YKzlwLPly +BV13eyfZWX5oukwAO216PvsOxVYEEVki+sKVbsDBCdSvlY1LEdpipzn+9wwOMs6lzhJlCXcTUXaM 4RK+7ySr4NojAY2m+0ekk84NiKuLZYD7hSLlegyueJrFPs6OiuPvAwMPKB4A8IHCTrkinbk0VS1Yb cPFIX3NkH1IvGCqI1K0iNYGkelHvGMJ/X5YJGGzKhFjuSfqM4GZspFTa2GRwOiHrDkLNwG75QY5iA 5sS86v1mbT/ZPuONBVZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nfO4D-00AdCT-I8; Fri, 15 Apr 2022 15:41:02 +0000 Received: from desiato.infradead.org ([90.155.92.199]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nfNsS-00AXSk-CZ for linux-arm-kernel@bombadil.infradead.org; Fri, 15 Apr 2022 15:28:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=2fzMXFp7GnA/U7fJH8F1ljdEdR1zvqkYmKc5yUNRwl4=; b=N6HwPpnDnApTOD5CmxbIaIS7NW YTVaSWJr85TBqb1YaEBPnmQtHDYSWWEprFbJ9CoyQyWiX39M6NlL6NQCy7M9dO9iY5Mjsm7Kx+tU6 nHZ/IQuncTs1Isjuxexy3s8FQ6Orr9rrkI3wNK6CRQlOIJPfc829HsGsKBcECOFj16qDmtmawILvc X0W56vyxM9EGx+BH3EyNOr37ZHjXssuD8AUuWEr4iQWxGHSf2kt7xeR+1hAVzmTDaaYLm+rT8qfcc PlLtE/OSc1m1c1hJD59/gbeIiY8f6NNdn7EMMpUKw+zru6ePR+WfzIP9a9n6VWvm24r/HiynS/5Xy PQSztE5w==; Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nfNsN-005QQ1-7r for linux-arm-kernel@lists.infradead.org; Fri, 15 Apr 2022 15:28:49 +0000 Received: (Authenticated sender: paul.kocialkowski@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 4682BE0015; Fri, 15 Apr 2022 15:28:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1650036526; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2fzMXFp7GnA/U7fJH8F1ljdEdR1zvqkYmKc5yUNRwl4=; b=fpB1K5LTTcVbPKdCHve3eIu0vkvgvWZeB3hOjMqWe1HHGUmBeR0XYc0f7MVKk+lzTEMRve h/VGQeA2SltQJhx5Zfi87uBAbP3PqidNBNXc6ZUPns4U8ghf4tR1ET/ivGsfXBtdzSuoue zhqunrOLpRS+4/3IeEDl1o5FXRVjo2IMMVfrJZb7W+0Rm4axQSnN2xc+iq9AVspBIBZSJ/ BWZvB9RkuVqxTE341RWCVfEnTgtpRrZm9B9lya3CckThejGzFodtsP+YBTxDwyx/ZpPDiz T7TZwxEfQ7x9Cty88rgnMDJ98qDvFNRcMXh7TWhY9pU0XieKI00fjO6o8kuJTQ== From: Paul Kocialkowski To: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Cc: Yong Deng , Paul Kocialkowski , Mauro Carvalho Chehab , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Laurent Pinchart , Maxime Ripard , Thomas Petazzoni Subject: [PATCH v4 23/45] media: sun6i-csi: Move power management to runtime pm in capture Date: Fri, 15 Apr 2022 17:27:49 +0200 Message-Id: <20220415152811.636419-24-paul.kocialkowski@bootlin.com> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220415152811.636419-1-paul.kocialkowski@bootlin.com> References: <20220415152811.636419-1-paul.kocialkowski@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220415_162847_558568_DDCA46C3 X-CRM114-Status: GOOD ( 18.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Let's just enable the module when we start using it (at stream on) and benefit from runtime pm instead of enabling it at first open. Also reorder the call to v4l2_pipeline_pm_get. Signed-off-by: Paul Kocialkowski Acked-by: Jernej Skrabec --- .../platform/sunxi/sun6i-csi/sun6i_csi.c | 24 ----------- .../platform/sunxi/sun6i-csi/sun6i_csi.h | 7 ---- .../sunxi/sun6i-csi/sun6i_csi_capture.c | 41 ++++++++++--------- 3 files changed, 22 insertions(+), 50 deletions(-) diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c index 29892e8c2b9d..7801f5abe47e 100644 --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c @@ -148,30 +148,6 @@ bool sun6i_csi_is_format_supported(struct sun6i_csi_device *csi_dev, return false; } -int sun6i_csi_set_power(struct sun6i_csi_device *csi_dev, bool enable) -{ - struct device *dev = csi_dev->dev; - struct regmap *regmap = csi_dev->regmap; - int ret; - - if (!enable) { - regmap_update_bits(regmap, SUN6I_CSI_EN_REG, - SUN6I_CSI_EN_CSI_EN, 0); - pm_runtime_put(dev); - - return 0; - } - - ret = pm_runtime_resume_and_get(dev); - if (ret < 0) - return ret; - - regmap_update_bits(regmap, SUN6I_CSI_EN_REG, SUN6I_CSI_EN_CSI_EN, - SUN6I_CSI_EN_CSI_EN); - - return 0; -} - static enum csi_input_fmt get_csi_input_format(struct sun6i_csi_device *csi_dev, u32 mbus_code, u32 pixformat) { diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h index 155527961280..3a4f2b45d267 100644 --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h @@ -77,13 +77,6 @@ struct sun6i_csi_variant { bool sun6i_csi_is_format_supported(struct sun6i_csi_device *csi_dev, u32 pixformat, u32 mbus_code); -/** - * sun6i_csi_set_power() - power on/off the csi - * @csi: pointer to the csi - * @enable: on/off - */ -int sun6i_csi_set_power(struct sun6i_csi_device *csi_dev, bool enable); - /** * sun6i_csi_update_config() - update the csi register settings * @csi: pointer to the csi diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c index 72fcc60d2695..3e5c4f7df48d 100644 --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c @@ -6,6 +6,7 @@ */ #include +#include #include #include @@ -141,6 +142,9 @@ static void sun6i_csi_capture_enable(struct sun6i_csi_device *csi_dev) { struct regmap *regmap = csi_dev->regmap; + regmap_update_bits(regmap, SUN6I_CSI_EN_REG, SUN6I_CSI_EN_CSI_EN, + SUN6I_CSI_EN_CSI_EN); + regmap_update_bits(regmap, SUN6I_CSI_CAP_REG, SUN6I_CSI_CAP_VCAP_ON, SUN6I_CSI_CAP_VCAP_ON); } @@ -150,6 +154,7 @@ static void sun6i_csi_capture_disable(struct sun6i_csi_device *csi_dev) struct regmap *regmap = csi_dev->regmap; regmap_update_bits(regmap, SUN6I_CSI_CAP_REG, SUN6I_CSI_CAP_VCAP_ON, 0); + regmap_update_bits(regmap, SUN6I_CSI_EN_REG, SUN6I_CSI_EN_CSI_EN, 0); } static void @@ -382,6 +387,7 @@ static int sun6i_csi_capture_start_streaming(struct vb2_queue *queue, struct sun6i_csi_capture *capture = &csi_dev->capture; struct sun6i_csi_capture_state *state = &capture->state; struct video_device *video_dev = &capture->video_dev; + struct device *dev = csi_dev->dev; struct v4l2_subdev *subdev; int ret; @@ -402,6 +408,12 @@ static int sun6i_csi_capture_start_streaming(struct vb2_queue *queue, goto error_media_pipeline; } + /* PM */ + + ret = pm_runtime_resume_and_get(dev); + if (ret < 0) + goto error_media_pipeline; + /* Clear */ sun6i_csi_capture_irq_clear(csi_dev); @@ -429,6 +441,8 @@ static int sun6i_csi_capture_start_streaming(struct vb2_queue *queue, sun6i_csi_capture_disable(csi_dev); sun6i_csi_capture_irq_disable(csi_dev); + pm_runtime_put(dev); + error_media_pipeline: media_pipeline_stop(&video_dev->entity); @@ -442,6 +456,7 @@ static void sun6i_csi_capture_stop_streaming(struct vb2_queue *queue) { struct sun6i_csi_device *csi_dev = vb2_get_drv_priv(queue); struct sun6i_csi_capture *capture = &csi_dev->capture; + struct device *dev = csi_dev->dev; struct v4l2_subdev *subdev; subdev = sun6i_csi_capture_remote_subdev(capture, NULL); @@ -451,6 +466,8 @@ static void sun6i_csi_capture_stop_streaming(struct vb2_queue *queue) sun6i_csi_capture_disable(csi_dev); sun6i_csi_capture_irq_disable(csi_dev); + pm_runtime_put(dev); + media_pipeline_stop(&capture->video_dev.entity); sun6i_csi_capture_state_cleanup(csi_dev, true); @@ -639,27 +656,20 @@ static int sun6i_csi_capture_open(struct file *file) if (mutex_lock_interruptible(&capture->lock)) return -ERESTARTSYS; - ret = v4l2_fh_open(file); + ret = v4l2_pipeline_pm_get(&capture->video_dev.entity); if (ret < 0) goto error_lock; - ret = v4l2_pipeline_pm_get(&capture->video_dev.entity); + ret = v4l2_fh_open(file); if (ret < 0) - goto error_v4l2_fh; - - /* Power on at first open. */ - if (v4l2_fh_is_singular_file(file)) { - ret = sun6i_csi_set_power(csi_dev, true); - if (ret < 0) - goto error_v4l2_fh; - } + goto error_pipeline; mutex_unlock(&capture->lock); return 0; -error_v4l2_fh: - v4l2_fh_release(file); +error_pipeline: + v4l2_pipeline_pm_put(&capture->video_dev.entity); error_lock: mutex_unlock(&capture->lock); @@ -671,19 +681,12 @@ static int sun6i_csi_capture_close(struct file *file) { struct sun6i_csi_device *csi_dev = video_drvdata(file); struct sun6i_csi_capture *capture = &csi_dev->capture; - bool last_close; mutex_lock(&capture->lock); - last_close = v4l2_fh_is_singular_file(file); - _vb2_fop_release(file, NULL); v4l2_pipeline_pm_put(&capture->video_dev.entity); - /* Power off at last close. */ - if (last_close) - sun6i_csi_set_power(csi_dev, false); - mutex_unlock(&capture->lock); return 0;