From patchwork Tue Jun 27 13:18:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 697099 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 333EBEB64DC for ; Tue, 27 Jun 2023 13:19:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229887AbjF0NT1 (ORCPT ); Tue, 27 Jun 2023 09:19:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229763AbjF0NTZ (ORCPT ); Tue, 27 Jun 2023 09:19:25 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B3BD1701 for ; Tue, 27 Jun 2023 06:18:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687871920; 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=UJ2gFGtWlOdwugdxEjiWdEJqjFXAlC6uot0bf3Xingw=; b=EeZapeH1j2NNr5uWfyLFnwXkF/P2D95Cq/GKzHs5ULa60ibPU2Ca1o7oqcpAhiZIH76Tjf cwJVxGoP3vJ0ZxZygbHtL23LzU2r2/VxfGeMgtL4dB4DsDONRNI2HmI5aNSsQvHeByq4J/ BozbmBGEsSKDD+wqzOrfDD6Xd3HD+wM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-65-bs5u4FnUP-y4_kVsNyBgxw-1; Tue, 27 Jun 2023 09:18:37 -0400 X-MC-Unique: bs5u4FnUP-y4_kVsNyBgxw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3D1B88C80EF; Tue, 27 Jun 2023 13:18:36 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.194.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 60E20401061; Tue, 27 Jun 2023 13:18:34 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Laurent Pinchart , Rui Miguel Silva , Daniel Scally Cc: Hans de Goede , Mauro Carvalho Chehab , Andy Shevchenko , Kate Hsuan , Tommaso Merciai , linux-media@vger.kernel.org Subject: [PATCH v3 02/29] media: ov2680: Fix ov2680_bayer_order() Date: Tue, 27 Jun 2023 15:18:03 +0200 Message-ID: <20230627131830.54601-3-hdegoede@redhat.com> In-Reply-To: <20230627131830.54601-1-hdegoede@redhat.com> References: <20230627131830.54601-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The index into ov2680_hv_flip_bayer_order[] should be 0-3, but ov2680_bayer_order() was using 0 + BIT(2) + (BIT(2) << 1) as max index, while the intention was to use: 0 + 1 + 2 as max index. Fix the index calculation in ov2680_bayer_order(), while at it also just use the ctrl values rather then reading them back using a slow i2c-read transaction. This also allows making the function void, since there now are no more i2c-reads to error check. Note the check for the ctrls being NULL is there to allow adding an ov2680_fill_format() helper later, which will call ov2680_set_bayer_order() during probe() before the ctrls are created. Fixes: 3ee47cad3e69 ("media: ov2680: Add Omnivision OV2680 sensor driver") Reviewed-by: Daniel Scally Acked-by: Rui Miguel Silva Signed-off-by: Hans de Goede --- drivers/media/i2c/ov2680.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c index 049ca28b9663..2001e08253ef 100644 --- a/drivers/media/i2c/ov2680.c +++ b/drivers/media/i2c/ov2680.c @@ -315,26 +315,17 @@ static void ov2680_power_down(struct ov2680_dev *sensor) usleep_range(5000, 10000); } -static int ov2680_bayer_order(struct ov2680_dev *sensor) +static void ov2680_set_bayer_order(struct ov2680_dev *sensor) { - u32 format1; - u32 format2; - u32 hv_flip; - int ret; + int hv_flip = 0; - ret = ov2680_read_reg(sensor, OV2680_REG_FORMAT1, &format1); - if (ret < 0) - return ret; + if (sensor->ctrls.vflip && sensor->ctrls.vflip->val) + hv_flip += 1; - ret = ov2680_read_reg(sensor, OV2680_REG_FORMAT2, &format2); - if (ret < 0) - return ret; - - hv_flip = (format2 & BIT(2) << 1) | (format1 & BIT(2)); + if (sensor->ctrls.hflip && sensor->ctrls.hflip->val) + hv_flip += 2; sensor->fmt.code = ov2680_hv_flip_bayer_order[hv_flip]; - - return 0; } static int ov2680_vflip_enable(struct ov2680_dev *sensor) @@ -345,7 +336,8 @@ static int ov2680_vflip_enable(struct ov2680_dev *sensor) if (ret < 0) return ret; - return ov2680_bayer_order(sensor); + ov2680_set_bayer_order(sensor); + return 0; } static int ov2680_vflip_disable(struct ov2680_dev *sensor) @@ -378,7 +370,8 @@ static int ov2680_hflip_disable(struct ov2680_dev *sensor) if (ret < 0) return ret; - return ov2680_bayer_order(sensor); + ov2680_set_bayer_order(sensor); + return 0; } static int ov2680_test_pattern_set(struct ov2680_dev *sensor, int value) From patchwork Tue Jun 27 13:18:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 697097 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3992DEB64DC for ; Tue, 27 Jun 2023 13:19:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230113AbjF0NTh (ORCPT ); Tue, 27 Jun 2023 09:19:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230106AbjF0NTd (ORCPT ); Tue, 27 Jun 2023 09:19:33 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87C3310FF for ; Tue, 27 Jun 2023 06:18:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687871924; 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=Ld2LYg+1aqo15l266uY3r9vrBXDa0Q2jWLha1B9tsSw=; b=UT2tA4EtdXYe6euBWLNsBxjTesRDndyFzViMbf0rCcRsk9RM0k6MBNQvye4J5szrnfts3w c3EuQQSJe/7UUyinEKyUryLwlPeY5sciyaL58ij6/Qjocd5GFfMcSjqy+Ld6Gazmb1KnD1 sQ/mb30nvDS7ZtcxUjnvz/AKJZUP6Q8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-563-Yg-2-klEMeavC2VspWO1aA-1; Tue, 27 Jun 2023 09:18:38 -0400 X-MC-Unique: Yg-2-klEMeavC2VspWO1aA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BCF538C80F9; Tue, 27 Jun 2023 13:18:37 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.194.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7058240F169; Tue, 27 Jun 2023 13:18:36 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Laurent Pinchart , Rui Miguel Silva , Daniel Scally Cc: Hans de Goede , Mauro Carvalho Chehab , Andy Shevchenko , Kate Hsuan , Tommaso Merciai , linux-media@vger.kernel.org Subject: [PATCH v3 03/29] media: ov2680: Fix vflip / hflip set functions Date: Tue, 27 Jun 2023 15:18:04 +0200 Message-ID: <20230627131830.54601-4-hdegoede@redhat.com> In-Reply-To: <20230627131830.54601-1-hdegoede@redhat.com> References: <20230627131830.54601-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org ov2680_vflip_disable() / ov2680_hflip_disable() pass BIT(0) instead of 0 as value to ov2680_mod_reg(). While fixing this also: 1. Stop having separate enable/disable functions for hflip / vflip 2. Move the is_streaming check, which is unique to hflip / vflip into the ov2680_set_?flip() functions. for a nice code cleanup. Fixes: 3ee47cad3e69 ("media: ov2680: Add Omnivision OV2680 sensor driver") Reviewed-by: Daniel Scally Acked-by: Rui Miguel Silva Signed-off-by: Hans de Goede --- drivers/media/i2c/ov2680.c | 50 ++++++++++---------------------------- 1 file changed, 13 insertions(+), 37 deletions(-) diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c index 2001e08253ef..c93810f84ed7 100644 --- a/drivers/media/i2c/ov2680.c +++ b/drivers/media/i2c/ov2680.c @@ -328,11 +328,15 @@ static void ov2680_set_bayer_order(struct ov2680_dev *sensor) sensor->fmt.code = ov2680_hv_flip_bayer_order[hv_flip]; } -static int ov2680_vflip_enable(struct ov2680_dev *sensor) +static int ov2680_set_vflip(struct ov2680_dev *sensor, s32 val) { int ret; - ret = ov2680_mod_reg(sensor, OV2680_REG_FORMAT1, BIT(2), BIT(2)); + if (sensor->is_streaming) + return -EBUSY; + + ret = ov2680_mod_reg(sensor, OV2680_REG_FORMAT1, + BIT(2), val ? BIT(2) : 0); if (ret < 0) return ret; @@ -340,33 +344,15 @@ static int ov2680_vflip_enable(struct ov2680_dev *sensor) return 0; } -static int ov2680_vflip_disable(struct ov2680_dev *sensor) +static int ov2680_set_hflip(struct ov2680_dev *sensor, s32 val) { int ret; - ret = ov2680_mod_reg(sensor, OV2680_REG_FORMAT1, BIT(2), BIT(0)); - if (ret < 0) - return ret; + if (sensor->is_streaming) + return -EBUSY; - return ov2680_bayer_order(sensor); -} - -static int ov2680_hflip_enable(struct ov2680_dev *sensor) -{ - int ret; - - ret = ov2680_mod_reg(sensor, OV2680_REG_FORMAT2, BIT(2), BIT(2)); - if (ret < 0) - return ret; - - return ov2680_bayer_order(sensor); -} - -static int ov2680_hflip_disable(struct ov2680_dev *sensor) -{ - int ret; - - ret = ov2680_mod_reg(sensor, OV2680_REG_FORMAT2, BIT(2), BIT(0)); + ret = ov2680_mod_reg(sensor, OV2680_REG_FORMAT2, + BIT(2), val ? BIT(2) : 0); if (ret < 0) return ret; @@ -720,19 +706,9 @@ static int ov2680_s_ctrl(struct v4l2_ctrl *ctrl) case V4L2_CID_EXPOSURE: return ov2680_exposure_set(sensor, ctrl->val); case V4L2_CID_VFLIP: - if (sensor->is_streaming) - return -EBUSY; - if (ctrl->val) - return ov2680_vflip_enable(sensor); - else - return ov2680_vflip_disable(sensor); + return ov2680_set_vflip(sensor, ctrl->val); case V4L2_CID_HFLIP: - if (sensor->is_streaming) - return -EBUSY; - if (ctrl->val) - return ov2680_hflip_enable(sensor); - else - return ov2680_hflip_disable(sensor); + return ov2680_set_hflip(sensor, ctrl->val); case V4L2_CID_TEST_PATTERN: return ov2680_test_pattern_set(sensor, ctrl->val); default: From patchwork Tue Jun 27 13:18:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 697098 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12F9BEB64DC for ; Tue, 27 Jun 2023 13:19:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230070AbjF0NTb (ORCPT ); Tue, 27 Jun 2023 09:19:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229567AbjF0NTZ (ORCPT ); Tue, 27 Jun 2023 09:19:25 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F35DD1712 for ; Tue, 27 Jun 2023 06:18:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687871927; 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=XXDZMJiE6MrDYHyPuXPqIDejJizXioiJ8sueQT8WryU=; b=XFpKMYTPkMLQNQwlmX8emyZ3SaQC4H3MPwDwzhMolv/Zsn3QPNhypZct2qErcyW7aLTgVM l5a3EmeNacgEXtcjNwvkAQAutKvE5AI2tTSFY0YOK8svyas0qKWLgGxOUlvnbCDbh326j0 AJmpzr6hbsBEaF4vew9sXhUUCiRKia0= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-592-hoJvNA06M4Ov91nUIk7k9Q-1; Tue, 27 Jun 2023 09:18:42 -0400 X-MC-Unique: hoJvNA06M4Ov91nUIk7k9Q-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D2AA22815E3C; Tue, 27 Jun 2023 13:18:40 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.194.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 802E1401061; Tue, 27 Jun 2023 13:18:39 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Laurent Pinchart , Rui Miguel Silva , Daniel Scally Cc: Hans de Goede , Mauro Carvalho Chehab , Andy Shevchenko , Kate Hsuan , Tommaso Merciai , linux-media@vger.kernel.org Subject: [PATCH v3 05/29] media: ov2680: Don't take the lock for try_fmt calls Date: Tue, 27 Jun 2023 15:18:06 +0200 Message-ID: <20230627131830.54601-6-hdegoede@redhat.com> In-Reply-To: <20230627131830.54601-1-hdegoede@redhat.com> References: <20230627131830.54601-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org On ov2680_set_fmt() calls with format->which == V4L2_SUBDEV_FORMAT_TRY, ov2680_set_fmt() does not talk to the sensor. So in this case there is no need to lock the sensor->lock mutex or to check that the sensor is streaming. Fixes: 3ee47cad3e69 ("media: ov2680: Add Omnivision OV2680 sensor driver") Acked-by: Rui Miguel Silva Signed-off-by: Hans de Goede --- drivers/media/i2c/ov2680.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c index f6297874af3b..2b20990f4cf5 100644 --- a/drivers/media/i2c/ov2680.c +++ b/drivers/media/i2c/ov2680.c @@ -595,24 +595,22 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd, if (format->pad != 0) return -EINVAL; - mutex_lock(&sensor->lock); - - if (sensor->is_streaming) { - ret = -EBUSY; - goto unlock; - } - mode = v4l2_find_nearest_size(ov2680_mode_data, ARRAY_SIZE(ov2680_mode_data), width, height, fmt->width, fmt->height); - if (!mode) { - ret = -EINVAL; - goto unlock; - } + if (!mode) + return -EINVAL; if (format->which == V4L2_SUBDEV_FORMAT_TRY) { try_fmt = v4l2_subdev_get_try_format(sd, sd_state, 0); format->format = *try_fmt; + return 0; + } + + mutex_lock(&sensor->lock); + + if (sensor->is_streaming) { + ret = -EBUSY; goto unlock; } From patchwork Tue Jun 27 13:18:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 697095 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBACEEB64DC for ; Tue, 27 Jun 2023 13:20:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229881AbjF0NUO (ORCPT ); Tue, 27 Jun 2023 09:20:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230106AbjF0NUI (ORCPT ); Tue, 27 Jun 2023 09:20:08 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11565171A for ; Tue, 27 Jun 2023 06:18:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687871927; 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=VwO1a1IjoFoGQprf//V47HWez7maIaOWf7otJqJ9XUM=; b=Sd6MXr4TldIe10ZPFi2qpagfIE3lZO/rnRDchFv+QVqsaj3YdqJz17xTLaj7nBsRf73IhC OXi4Kb+65cUY9SG2I1I3WBvTxC1+59Zpy/8ACEm6Gok9E5O4auOdPYl0BqPqoJpxk6iohq dqujvIWdFGprhrlns5/vYefZD6LS41c= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-546-c0Ad4pAKM_q31cQeZ5tp4w-1; Tue, 27 Jun 2023 09:18:43 -0400 X-MC-Unique: c0Ad4pAKM_q31cQeZ5tp4w-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6394B185A794; Tue, 27 Jun 2023 13:18:42 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.194.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1319A400F5A; Tue, 27 Jun 2023 13:18:40 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Laurent Pinchart , Rui Miguel Silva , Daniel Scally Cc: Hans de Goede , Mauro Carvalho Chehab , Andy Shevchenko , Kate Hsuan , Tommaso Merciai , linux-media@vger.kernel.org Subject: [PATCH v3 06/29] media: ov2680: Add ov2680_fill_format() helper function Date: Tue, 27 Jun 2023 15:18:07 +0200 Message-ID: <20230627131830.54601-7-hdegoede@redhat.com> In-Reply-To: <20230627131830.54601-1-hdegoede@redhat.com> References: <20230627131830.54601-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add a ov2680_fill_format() helper function and use this everywhere were a v4l2_mbus_framefmt struct needs to be filled in so that the driver always fills it consistently. This is a preparation patch for fixing ov2680_set_fmt() which == V4L2_SUBDEV_FORMAT_TRY calls not properly filling in the passed in v4l2_mbus_framefmt struct. Note that for ov2680_init_cfg() this now simply always fills the try_fmt struct of the passed in sd_state. This is correct because ov2680_init_cfg() is never called with a NULL sd_state so the old sd_state check is not necessary. Fixes: 3ee47cad3e69 ("media: ov2680: Add Omnivision OV2680 sensor driver") Acked-by: Rui Miguel Silva Signed-off-by: Hans de Goede --- drivers/media/i2c/ov2680.c | 49 +++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c index 2b20990f4cf5..c4a46c734d82 100644 --- a/drivers/media/i2c/ov2680.c +++ b/drivers/media/i2c/ov2680.c @@ -54,6 +54,9 @@ #define OV2680_WIDTH_MAX 1600 #define OV2680_HEIGHT_MAX 1200 +#define OV2680_DEFAULT_WIDTH 800 +#define OV2680_DEFAULT_HEIGHT 600 + enum ov2680_mode_id { OV2680_MODE_QUXGA_800_600, OV2680_MODE_720P_1280_720, @@ -315,7 +318,8 @@ static void ov2680_power_down(struct ov2680_dev *sensor) usleep_range(5000, 10000); } -static void ov2680_set_bayer_order(struct ov2680_dev *sensor) +static void ov2680_set_bayer_order(struct ov2680_dev *sensor, + struct v4l2_mbus_framefmt *fmt) { int hv_flip = 0; @@ -325,7 +329,19 @@ static void ov2680_set_bayer_order(struct ov2680_dev *sensor) if (sensor->ctrls.hflip && sensor->ctrls.hflip->val) hv_flip += 2; - sensor->fmt.code = ov2680_hv_flip_bayer_order[hv_flip]; + fmt->code = ov2680_hv_flip_bayer_order[hv_flip]; +} + +static void ov2680_fill_format(struct ov2680_dev *sensor, + struct v4l2_mbus_framefmt *fmt, + unsigned int width, unsigned int height) +{ + memset(fmt, 0, sizeof(*fmt)); + fmt->width = width; + fmt->height = height; + fmt->field = V4L2_FIELD_NONE; + fmt->colorspace = V4L2_COLORSPACE_SRGB; + ov2680_set_bayer_order(sensor, fmt); } static int ov2680_set_vflip(struct ov2680_dev *sensor, s32 val) @@ -340,7 +356,7 @@ static int ov2680_set_vflip(struct ov2680_dev *sensor, s32 val) if (ret < 0) return ret; - ov2680_set_bayer_order(sensor); + ov2680_set_bayer_order(sensor, &sensor->fmt); return 0; } @@ -356,7 +372,7 @@ static int ov2680_set_hflip(struct ov2680_dev *sensor, s32 val) if (ret < 0) return ret; - ov2680_set_bayer_order(sensor); + ov2680_set_bayer_order(sensor, &sensor->fmt); return 0; } @@ -614,10 +630,7 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd, goto unlock; } - fmt->width = mode->width; - fmt->height = mode->height; - fmt->code = sensor->fmt.code; - fmt->colorspace = sensor->fmt.colorspace; + ov2680_fill_format(sensor, fmt, mode->width, mode->height); sensor->current_mode = mode; sensor->fmt = format->format; @@ -632,16 +645,11 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd, static int ov2680_init_cfg(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state) { - struct v4l2_subdev_format fmt = { - .which = sd_state ? V4L2_SUBDEV_FORMAT_TRY - : V4L2_SUBDEV_FORMAT_ACTIVE, - .format = { - .width = 800, - .height = 600, - } - }; + struct ov2680_dev *sensor = to_ov2680_dev(sd); - return ov2680_set_fmt(sd, sd_state, &fmt); + ov2680_fill_format(sensor, &sd_state->pads[0].try_fmt, + OV2680_DEFAULT_WIDTH, OV2680_DEFAULT_HEIGHT); + return 0; } static int ov2680_enum_frame_size(struct v4l2_subdev *sd, @@ -740,11 +748,8 @@ static int ov2680_mode_init(struct ov2680_dev *sensor) const struct ov2680_mode_info *init_mode; /* set initial mode */ - sensor->fmt.code = MEDIA_BUS_FMT_SBGGR10_1X10; - sensor->fmt.width = 800; - sensor->fmt.height = 600; - sensor->fmt.field = V4L2_FIELD_NONE; - sensor->fmt.colorspace = V4L2_COLORSPACE_SRGB; + ov2680_fill_format(sensor, &sensor->fmt, + OV2680_DEFAULT_WIDTH, OV2680_DEFAULT_HEIGHT); sensor->frame_interval.denominator = OV2680_FRAME_RATE; sensor->frame_interval.numerator = 1; From patchwork Tue Jun 27 13:18:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 697096 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C5CEEB64DD for ; Tue, 27 Jun 2023 13:20:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230385AbjF0NUK (ORCPT ); Tue, 27 Jun 2023 09:20:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229667AbjF0NUH (ORCPT ); Tue, 27 Jun 2023 09:20:07 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32C722728 for ; Tue, 27 Jun 2023 06:18:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687871938; 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=494+hYCkSRWouwu3cdry5hPSn6fPQTx2zVU0xTwSDZg=; b=fe5grEeeRmxeCq8Bnh6kP1lDuHml98AdURK208xB7gmJfGjGtGXd4EoAHFhRf4hb7yoUKL Lfr31UO91BBjwfvJyH92sKF0uiJGeAQqX0Sx+9DT81tuhllI107ZshnI0W+SsxjPk1vBfI dljfifO14WRLGxZxZvxAsuNRKz01hm4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-456-MdP8EmkdNmG7-JqFIhqKXg-1; Tue, 27 Jun 2023 09:18:52 -0400 X-MC-Unique: MdP8EmkdNmG7-JqFIhqKXg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 826458C8118; Tue, 27 Jun 2023 13:18:48 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.194.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 364AB401061; Tue, 27 Jun 2023 13:18:47 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Laurent Pinchart , Rui Miguel Silva , Daniel Scally Cc: Hans de Goede , Mauro Carvalho Chehab , Andy Shevchenko , Kate Hsuan , Tommaso Merciai , linux-media@vger.kernel.org Subject: [PATCH v3 10/29] media: ov2680: Store dev instead of i2c_client in ov2680_dev Date: Tue, 27 Jun 2023 15:18:11 +0200 Message-ID: <20230627131830.54601-11-hdegoede@redhat.com> In-Reply-To: <20230627131830.54601-1-hdegoede@redhat.com> References: <20230627131830.54601-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Now that the cci_* register access helpers are used access to the i2c_client after probe() is no longer necessary. Directly store a struct device *dev pointing to &client->dev inside ov2680_dev to make the code simpler. Acked-by: Rui Miguel Silva Signed-off-by: Hans de Goede --- Changes in v2: - Use to_i2c_client(sensor->dev) in ov2680_v4l2_register() --- drivers/media/i2c/ov2680.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c index fb25ba446d52..824e2962e7d5 100644 --- a/drivers/media/i2c/ov2680.c +++ b/drivers/media/i2c/ov2680.c @@ -87,7 +87,7 @@ struct ov2680_ctrls { }; struct ov2680_dev { - struct i2c_client *i2c_client; + struct device *dev; struct regmap *regmap; struct v4l2_subdev sd; @@ -172,11 +172,6 @@ static struct ov2680_dev *to_ov2680_dev(struct v4l2_subdev *sd) return container_of(sd, struct ov2680_dev, sd); } -static struct device *ov2680_to_dev(struct ov2680_dev *sensor) -{ - return &sensor->i2c_client->dev; -} - static inline struct v4l2_subdev *ctrl_to_sd(struct v4l2_ctrl *ctrl) { return &container_of(ctrl->handler, struct ov2680_dev, @@ -344,7 +339,6 @@ static int ov2680_power_off(struct ov2680_dev *sensor) static int ov2680_power_on(struct ov2680_dev *sensor) { - struct device *dev = ov2680_to_dev(sensor); int ret; if (sensor->is_enabled) @@ -352,7 +346,7 @@ static int ov2680_power_on(struct ov2680_dev *sensor) ret = regulator_bulk_enable(OV2680_NUM_SUPPLIES, sensor->supplies); if (ret < 0) { - dev_err(dev, "failed to enable regulators: %d\n", ret); + dev_err(sensor->dev, "failed to enable regulators: %d\n", ret); return ret; } @@ -360,7 +354,7 @@ static int ov2680_power_on(struct ov2680_dev *sensor) ret = cci_write(sensor->regmap, OV2680_REG_SOFT_RESET, 0x01, NULL); if (ret != 0) { - dev_err(dev, "sensor soft reset failed\n"); + dev_err(sensor->dev, "sensor soft reset failed\n"); goto err_disable_regulators; } usleep_range(1000, 2000); @@ -656,13 +650,13 @@ static int ov2680_mode_init(struct ov2680_dev *sensor) static int ov2680_v4l2_register(struct ov2680_dev *sensor) { + struct i2c_client *client = to_i2c_client(sensor->dev); const struct v4l2_ctrl_ops *ops = &ov2680_ctrl_ops; struct ov2680_ctrls *ctrls = &sensor->ctrls; struct v4l2_ctrl_handler *hdl = &ctrls->handler; int ret = 0; - v4l2_i2c_subdev_init(&sensor->sd, sensor->i2c_client, - &ov2680_subdev_ops); + v4l2_i2c_subdev_init(&sensor->sd, client, &ov2680_subdev_ops); sensor->sd.flags = V4L2_SUBDEV_FL_HAS_DEVNODE; sensor->pad.flags = MEDIA_PAD_FL_SOURCE; @@ -719,14 +713,12 @@ static int ov2680_get_regulators(struct ov2680_dev *sensor) for (i = 0; i < OV2680_NUM_SUPPLIES; i++) sensor->supplies[i].supply = ov2680_supply_name[i]; - return devm_regulator_bulk_get(&sensor->i2c_client->dev, - OV2680_NUM_SUPPLIES, - sensor->supplies); + return devm_regulator_bulk_get(sensor->dev, + OV2680_NUM_SUPPLIES, sensor->supplies); } static int ov2680_check_id(struct ov2680_dev *sensor) { - struct device *dev = ov2680_to_dev(sensor); u64 chip_id; int ret; @@ -734,12 +726,12 @@ static int ov2680_check_id(struct ov2680_dev *sensor) ret = cci_read(sensor->regmap, OV2680_REG_CHIP_ID, &chip_id, NULL); if (ret < 0) { - dev_err(dev, "failed to read chip id\n"); + dev_err(sensor->dev, "failed to read chip id\n"); return -ENODEV; } if (chip_id != OV2680_CHIP_ID) { - dev_err(dev, "chip id: 0x%04llx does not match expected 0x%04x\n", + dev_err(sensor->dev, "chip id: 0x%04llx does not match expected 0x%04x\n", chip_id, OV2680_CHIP_ID); return -ENODEV; } @@ -749,7 +741,7 @@ static int ov2680_check_id(struct ov2680_dev *sensor) static int ov2680_parse_dt(struct ov2680_dev *sensor) { - struct device *dev = ov2680_to_dev(sensor); + struct device *dev = sensor->dev; int ret; sensor->reset_gpio = devm_gpiod_get_optional(dev, "reset", @@ -786,7 +778,7 @@ static int ov2680_probe(struct i2c_client *client) if (!sensor) return -ENOMEM; - sensor->i2c_client = client; + sensor->dev = &client->dev; sensor->regmap = devm_cci_regmap_init_i2c(client, 16); if (IS_ERR(sensor->regmap)) From patchwork Tue Jun 27 13:18:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 697093 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31956EB64DD for ; Tue, 27 Jun 2023 13:20:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230345AbjF0NUU (ORCPT ); Tue, 27 Jun 2023 09:20:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230409AbjF0NUN (ORCPT ); Tue, 27 Jun 2023 09:20:13 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1BA41726 for ; Tue, 27 Jun 2023 06:18:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687871934; 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=Uw7ZRZepyM+wSz/SFtpNPZLSQO1/3ghsFKFgBxAyjB0=; b=CH35yYKXxbsMjT5HSrYGG+6royCZt5Z7/w+AeRkw5/TE7D5dJaqMoTdTOcfRNJ3C2R9A26 IheUZ4tmTxSMnOPis5ZHg0fDip+tpeQ0+bJcCCbY9IHWWFt8gxiYtSbHao7CLBETVJ020U m+FOZZLayjmHSQfpmnJ+l6Mws3pStGc= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-452-PvdLBIghO1ydI0ZkCGQfFg-1; Tue, 27 Jun 2023 09:18:50 -0400 X-MC-Unique: PvdLBIghO1ydI0ZkCGQfFg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0F8D63815EE8; Tue, 27 Jun 2023 13:18:50 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.194.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id B625240BB4D; Tue, 27 Jun 2023 13:18:48 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Laurent Pinchart , Rui Miguel Silva , Daniel Scally Cc: Hans de Goede , Mauro Carvalho Chehab , Andy Shevchenko , Kate Hsuan , Tommaso Merciai , linux-media@vger.kernel.org Subject: [PATCH v3 11/29] media: ov2680: Check for "powerdown" GPIO con-id before checking for "reset" GPIO con-id Date: Tue, 27 Jun 2023 15:18:12 +0200 Message-ID: <20230627131830.54601-12-hdegoede@redhat.com> In-Reply-To: <20230627131830.54601-1-hdegoede@redhat.com> References: <20230627131830.54601-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The datasheet of the OV2680 labels the single GPIO to put the sensor in powersaving mode as XSHUTDN aka shutdown, _not_ reset. This is important because some boards have standardized sensor connectors which allow connecting various sensor modules. These connectors have both reset and powerdown signals and the powerdown signal is routed to the OV2680's XSHUTDN pin. On x86/ACPI multiple Bay Trail, Cherry Trail, Sky Lake and Kaby Lake models have an OV2680 connected to the ISP2 / IPU3. On these devices the GPIOS are not described in DT instead the GPIOs are described with an Intel specific DSM which labels them as either powerdown or reset. Often this DSM returns both reset and powerdown pins even though the OV2680 has only 1 such pin. For the ov2680 driver to work on these devices it must use the GPIO with "powerdown" as con-id, matching the XSHUTDN name from the datasheet. As for why "powerdown" vs say "shutdown" the ACPI DSM -> con-id mapping code is shared, so we must use standardized names and currently all of the following sensor drivers already use "powerdown": adv7180, gc0310, isl7998x, ov02a10, ov2659, ov5640, ov5648, ov5670, ov5693, ov7670, ov772x, ov7740, ov8858, ov8865 and ov9650 . Where as the hi846 driver is the lonely standout using "shutdown". Try the "powerdown" con-id first to make things work, falling back to "reset" to keep existing DT setups working. Acked-by: Rui Miguel Silva Signed-off-by: Hans de Goede --- drivers/media/i2c/ov2680.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c index 824e2962e7d5..0de047c49c31 100644 --- a/drivers/media/i2c/ov2680.c +++ b/drivers/media/i2c/ov2680.c @@ -96,7 +96,7 @@ struct ov2680_dev { u32 xvclk_freq; struct regulator_bulk_data supplies[OV2680_NUM_SUPPLIES]; - struct gpio_desc *reset_gpio; + struct gpio_desc *pwdn_gpio; struct mutex lock; /* protect members */ bool mode_pending_changes; @@ -180,19 +180,19 @@ static inline struct v4l2_subdev *ctrl_to_sd(struct v4l2_ctrl *ctrl) static void ov2680_power_up(struct ov2680_dev *sensor) { - if (!sensor->reset_gpio) + if (!sensor->pwdn_gpio) return; - gpiod_set_value(sensor->reset_gpio, 0); + gpiod_set_value(sensor->pwdn_gpio, 0); usleep_range(5000, 10000); } static void ov2680_power_down(struct ov2680_dev *sensor) { - if (!sensor->reset_gpio) + if (!sensor->pwdn_gpio) return; - gpiod_set_value(sensor->reset_gpio, 1); + gpiod_set_value(sensor->pwdn_gpio, 1); usleep_range(5000, 10000); } @@ -350,7 +350,7 @@ static int ov2680_power_on(struct ov2680_dev *sensor) return ret; } - if (!sensor->reset_gpio) { + if (!sensor->pwdn_gpio) { ret = cci_write(sensor->regmap, OV2680_REG_SOFT_RESET, 0x01, NULL); if (ret != 0) { @@ -742,16 +742,27 @@ static int ov2680_check_id(struct ov2680_dev *sensor) static int ov2680_parse_dt(struct ov2680_dev *sensor) { struct device *dev = sensor->dev; + struct gpio_desc *gpio; int ret; - sensor->reset_gpio = devm_gpiod_get_optional(dev, "reset", - GPIOD_OUT_HIGH); - ret = PTR_ERR_OR_ZERO(sensor->reset_gpio); + /* + * The pin we want is named XSHUTDN in the datasheet. Linux sensor + * drivers have standardized on using "powerdown" as con-id name + * for powerdown or shutdown pins. Older DTB files use "reset", + * so fallback to that if there is no "powerdown" pin. + */ + gpio = devm_gpiod_get_optional(dev, "powerdown", GPIOD_OUT_HIGH); + if (!gpio) + gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + + ret = PTR_ERR_OR_ZERO(gpio); if (ret < 0) { dev_dbg(dev, "error while getting reset gpio: %d\n", ret); return ret; } + sensor->pwdn_gpio = gpio; + sensor->xvclk = devm_clk_get(dev, "xvclk"); if (IS_ERR(sensor->xvclk)) { dev_err(dev, "xvclk clock missing or invalid\n"); From patchwork Tue Jun 27 13:18:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 697083 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 569B8EB64D9 for ; Tue, 27 Jun 2023 15:00:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231345AbjF0PA6 (ORCPT ); Tue, 27 Jun 2023 11:00:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230195AbjF0PA5 (ORCPT ); Tue, 27 Jun 2023 11:00:57 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 449C3FA for ; Tue, 27 Jun 2023 08:00:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687878012; 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=ShseNxfXXxfnIb148XD8n6NmouB69TgdS0NPQ2fWsXQ=; b=MfReiWwDwx7lylWZPNow8sPa0JBBqYI6SZc0GPoZ+pZaSqqoGS2Idm2LhUlTvah1/jsAcE ysuIrK6duPCQc9J1Cca05WEZN/RpcHtAwUyL7vhI1BgK7SY0iLHiRb/86+x+JLuaIzjKpR ktNHgcX1ergxFbWKCtiWL3rrFn7yf/E= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-251-S7R3W0ISMq-uQWavta-zOw-1; Tue, 27 Jun 2023 09:18:52 -0400 X-MC-Unique: S7R3W0ISMq-uQWavta-zOw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 916113815EEA; Tue, 27 Jun 2023 13:18:51 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.194.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 42E38401061; Tue, 27 Jun 2023 13:18:50 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Laurent Pinchart , Rui Miguel Silva , Daniel Scally Cc: Hans de Goede , Mauro Carvalho Chehab , Andy Shevchenko , Kate Hsuan , Tommaso Merciai , linux-media@vger.kernel.org Subject: [PATCH v3 12/29] media: ov2680: Add runtime-pm support Date: Tue, 27 Jun 2023 15:18:13 +0200 Message-ID: <20230627131830.54601-13-hdegoede@redhat.com> In-Reply-To: <20230627131830.54601-1-hdegoede@redhat.com> References: <20230627131830.54601-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Remove the obsolete s_power() callback and instead use runtime-pm + autosuspend, powering-on the sensor on s_stream(1) and releasing the runtime-pm reference on s_stream(0). This also removes the need for ov2680_mode_restore() instead ov2680_stream_enable() now takes care of all sensor initalization after power-on. This is a preparation patch for adding ACPI support. Note this also removes putting the clock lane into LP-11 state from ov2680_power_on() since now streaming will start immediately after powering on the sensor there is no need to put the clock lane in a low power state. Acked-by: Rui Miguel Silva Signed-off-by: Hans de Goede --- drivers/media/i2c/ov2680.c | 134 +++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 73 deletions(-) diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c index 0de047c49c31..56aaf67c1d82 100644 --- a/drivers/media/i2c/ov2680.c +++ b/drivers/media/i2c/ov2680.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -99,7 +100,6 @@ struct ov2680_dev { struct gpio_desc *pwdn_gpio; struct mutex lock; /* protect members */ - bool mode_pending_changes; bool is_enabled; bool is_streaming; @@ -282,19 +282,15 @@ static int ov2680_exposure_set(struct ov2680_dev *sensor, u32 exp) } static int ov2680_stream_enable(struct ov2680_dev *sensor) -{ - return cci_write(sensor->regmap, OV2680_REG_STREAM_CTRL, 1, NULL); -} - -static int ov2680_stream_disable(struct ov2680_dev *sensor) -{ - return cci_write(sensor->regmap, OV2680_REG_STREAM_CTRL, 0, NULL); -} - -static int ov2680_mode_set(struct ov2680_dev *sensor) { int ret; + ret = regmap_multi_reg_write(sensor->regmap, + ov2680_mode_init_data.reg_data, + ov2680_mode_init_data.reg_data_size); + if (ret < 0) + return ret; + ret = regmap_multi_reg_write(sensor->regmap, sensor->current_mode->reg_data, sensor->current_mode->reg_data_size); @@ -306,22 +302,12 @@ static int ov2680_mode_set(struct ov2680_dev *sensor) if (ret < 0) return ret; - sensor->mode_pending_changes = false; - - return 0; + return cci_write(sensor->regmap, OV2680_REG_STREAM_CTRL, 1, NULL); } -static int ov2680_mode_restore(struct ov2680_dev *sensor) +static int ov2680_stream_disable(struct ov2680_dev *sensor) { - int ret; - - ret = regmap_multi_reg_write(sensor->regmap, - ov2680_mode_init_data.reg_data, - ov2680_mode_init_data.reg_data_size); - if (ret < 0) - return ret; - - return ov2680_mode_set(sensor); + return cci_write(sensor->regmap, OV2680_REG_STREAM_CTRL, 0, NULL); } static int ov2680_power_off(struct ov2680_dev *sensor) @@ -369,11 +355,6 @@ static int ov2680_power_on(struct ov2680_dev *sensor) sensor->is_enabled = true; - /* Set clock lane into LP-11 state */ - ov2680_stream_enable(sensor); - usleep_range(1000, 2000); - ov2680_stream_disable(sensor); - return 0; err_disable_regulators: @@ -381,26 +362,6 @@ static int ov2680_power_on(struct ov2680_dev *sensor) return ret; } -static int ov2680_s_power(struct v4l2_subdev *sd, int on) -{ - struct ov2680_dev *sensor = to_ov2680_dev(sd); - int ret = 0; - - mutex_lock(&sensor->lock); - - if (on) - ret = ov2680_power_on(sensor); - else - ret = ov2680_power_off(sensor); - - if (on && ret == 0) - ret = ov2680_mode_restore(sensor); - - mutex_unlock(&sensor->lock); - - return ret; -} - static int ov2680_s_g_frame_interval(struct v4l2_subdev *sd, struct v4l2_subdev_frame_interval *fi) { @@ -423,16 +384,20 @@ static int ov2680_s_stream(struct v4l2_subdev *sd, int enable) if (sensor->is_streaming == !!enable) goto unlock; - if (enable && sensor->mode_pending_changes) { - ret = ov2680_mode_set(sensor); + if (enable) { + ret = pm_runtime_resume_and_get(sensor->sd.dev); if (ret < 0) goto unlock; - } - if (enable) ret = ov2680_stream_enable(sensor); - else + if (ret < 0) { + pm_runtime_put(sensor->sd.dev); + goto unlock; + } + } else { ret = ov2680_stream_disable(sensor); + pm_runtime_put(sensor->sd.dev); + } sensor->is_streaming = !!enable; @@ -519,7 +484,6 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd, sensor->current_mode = mode; sensor->fmt = format->format; - sensor->mode_pending_changes = true; unlock: mutex_unlock(&sensor->lock); @@ -603,10 +567,6 @@ static const struct v4l2_ctrl_ops ov2680_ctrl_ops = { .s_ctrl = ov2680_s_ctrl, }; -static const struct v4l2_subdev_core_ops ov2680_core_ops = { - .s_power = ov2680_s_power, -}; - static const struct v4l2_subdev_video_ops ov2680_video_ops = { .g_frame_interval = ov2680_s_g_frame_interval, .s_frame_interval = ov2680_s_g_frame_interval, @@ -623,7 +583,6 @@ static const struct v4l2_subdev_pad_ops ov2680_pad_ops = { }; static const struct v4l2_subdev_ops ov2680_subdev_ops = { - .core = &ov2680_core_ops, .video = &ov2680_video_ops, .pad = &ov2680_pad_ops, }; @@ -643,8 +602,6 @@ static int ov2680_mode_init(struct ov2680_dev *sensor) sensor->current_mode = init_mode; - sensor->mode_pending_changes = true; - return 0; } @@ -722,8 +679,6 @@ static int ov2680_check_id(struct ov2680_dev *sensor) u64 chip_id; int ret; - ov2680_power_on(sensor); - ret = cci_read(sensor->regmap, OV2680_REG_CHIP_ID, &chip_id, NULL); if (ret < 0) { dev_err(sensor->dev, "failed to read chip id\n"); @@ -811,18 +766,39 @@ static int ov2680_probe(struct i2c_client *client) mutex_init(&sensor->lock); - ret = ov2680_check_id(sensor); + /* + * Power up and verify the chip now, so that if runtime pm is + * disabled the chip is left on and streaming will work. + */ + ret = ov2680_power_on(sensor); if (ret < 0) goto lock_destroy; + ret = ov2680_check_id(sensor); + if (ret < 0) + goto err_powerdown; + + pm_runtime_set_active(&client->dev); + pm_runtime_get_noresume(&client->dev); + pm_runtime_enable(&client->dev); + ret = ov2680_v4l2_register(sensor); if (ret < 0) - goto lock_destroy; + goto err_pm_runtime; + + pm_runtime_set_autosuspend_delay(&client->dev, 1000); + pm_runtime_use_autosuspend(&client->dev); + pm_runtime_put_autosuspend(&client->dev); dev_info(dev, "ov2680 init correctly\n"); return 0; +err_pm_runtime: + pm_runtime_disable(&client->dev); + pm_runtime_put_noidle(&client->dev); +err_powerdown: + ov2680_power_off(sensor); lock_destroy: dev_err(dev, "ov2680 init fail: %d\n", ret); mutex_destroy(&sensor->lock); @@ -839,9 +815,18 @@ static void ov2680_remove(struct i2c_client *client) mutex_destroy(&sensor->lock); media_entity_cleanup(&sensor->sd.entity); v4l2_ctrl_handler_free(&sensor->ctrls.handler); + + /* + * Disable runtime PM. In case runtime PM is disabled in the kernel, + * make sure to turn power off manually. + */ + pm_runtime_disable(&client->dev); + if (!pm_runtime_status_suspended(&client->dev)) + ov2680_power_off(sensor); + pm_runtime_set_suspended(&client->dev); } -static int __maybe_unused ov2680_suspend(struct device *dev) +static int ov2680_suspend(struct device *dev) { struct v4l2_subdev *sd = dev_get_drvdata(dev); struct ov2680_dev *sensor = to_ov2680_dev(sd); @@ -849,15 +834,19 @@ static int __maybe_unused ov2680_suspend(struct device *dev) if (sensor->is_streaming) ov2680_stream_disable(sensor); - return 0; + return ov2680_power_off(sensor); } -static int __maybe_unused ov2680_resume(struct device *dev) +static int ov2680_resume(struct device *dev) { struct v4l2_subdev *sd = dev_get_drvdata(dev); struct ov2680_dev *sensor = to_ov2680_dev(sd); int ret; + ret = ov2680_power_on(sensor); + if (ret < 0) + goto stream_disable; + if (sensor->is_streaming) { ret = ov2680_stream_enable(sensor); if (ret < 0) @@ -873,9 +862,8 @@ static int __maybe_unused ov2680_resume(struct device *dev) return ret; } -static const struct dev_pm_ops ov2680_pm_ops = { - SET_SYSTEM_SLEEP_PM_OPS(ov2680_suspend, ov2680_resume) -}; +static DEFINE_RUNTIME_DEV_PM_OPS(ov2680_pm_ops, ov2680_suspend, ov2680_resume, + NULL); static const struct of_device_id ov2680_dt_ids[] = { { .compatible = "ovti,ov2680" }, @@ -886,7 +874,7 @@ MODULE_DEVICE_TABLE(of, ov2680_dt_ids); static struct i2c_driver ov2680_i2c_driver = { .driver = { .name = "ov2680", - .pm = &ov2680_pm_ops, + .pm = pm_sleep_ptr(&ov2680_pm_ops), .of_match_table = of_match_ptr(ov2680_dt_ids), }, .probe = ov2680_probe, From patchwork Tue Jun 27 13:18:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 697094 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 292A5EB64D9 for ; Tue, 27 Jun 2023 13:20:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230331AbjF0NUS (ORCPT ); Tue, 27 Jun 2023 09:20:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230345AbjF0NUK (ORCPT ); Tue, 27 Jun 2023 09:20:10 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AC172738 for ; Tue, 27 Jun 2023 06:18:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687871939; 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=FYTsBRuELW2Xht+bwDTCkN0JA6WOd0epNkc4o+meax8=; b=h58VMUCO2BViU2BWtvyFfHWrQk8bqBdizTPYf/qjMS2jJHXcBYhIB0w41CEPFki7ZLfiRQ NiYzt6yTGIejWrrasyU8VUMMm8rg8bRz0G59kkZsiEpN1ojAjxYjtJqcmQRmW8b4SbpfoK 6KQeZRiFoVVuzMLVKvvdcm3Q97Cv0Qc= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-36-w0o4xUxBMESuJSifNB7urA-1; Tue, 27 Jun 2023 09:18:53 -0400 X-MC-Unique: w0o4xUxBMESuJSifNB7urA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1EFF63C01E05; Tue, 27 Jun 2023 13:18:53 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.194.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id C55DA400F5A; Tue, 27 Jun 2023 13:18:51 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Laurent Pinchart , Rui Miguel Silva , Daniel Scally Cc: Hans de Goede , Mauro Carvalho Chehab , Andy Shevchenko , Kate Hsuan , Tommaso Merciai , linux-media@vger.kernel.org Subject: [PATCH v3 13/29] media: ov2680: Drop is_enabled flag Date: Tue, 27 Jun 2023 15:18:14 +0200 Message-ID: <20230627131830.54601-14-hdegoede@redhat.com> In-Reply-To: <20230627131830.54601-1-hdegoede@redhat.com> References: <20230627131830.54601-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org With runtime-pm it is guaranteed that ov2680_power_on() and ov2680_power_off() will always be called in a balanced way; and the is_enabled check in ov2680_s_ctrl() can be replaced by checking the runtime-suspend state. So there is no more need for the is_enabled flag, remove it. While at it also make sure that flip control changes while suspended still lead to the bayer-order getting updated so that get_fmt returns the correct bayer-order. Acked-by: Rui Miguel Silva Signed-off-by: Hans de Goede --- drivers/media/i2c/ov2680.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c index 56aaf67c1d82..b7c23286700e 100644 --- a/drivers/media/i2c/ov2680.c +++ b/drivers/media/i2c/ov2680.c @@ -100,7 +100,6 @@ struct ov2680_dev { struct gpio_desc *pwdn_gpio; struct mutex lock; /* protect members */ - bool is_enabled; bool is_streaming; struct ov2680_ctrls ctrls; @@ -312,14 +311,9 @@ static int ov2680_stream_disable(struct ov2680_dev *sensor) static int ov2680_power_off(struct ov2680_dev *sensor) { - if (!sensor->is_enabled) - return 0; - clk_disable_unprepare(sensor->xvclk); ov2680_power_down(sensor); regulator_bulk_disable(OV2680_NUM_SUPPLIES, sensor->supplies); - sensor->is_enabled = false; - return 0; } @@ -327,9 +321,6 @@ static int ov2680_power_on(struct ov2680_dev *sensor) { int ret; - if (sensor->is_enabled) - return 0; - ret = regulator_bulk_enable(OV2680_NUM_SUPPLIES, sensor->supplies); if (ret < 0) { dev_err(sensor->dev, "failed to enable regulators: %d\n", ret); @@ -353,8 +344,6 @@ static int ov2680_power_on(struct ov2680_dev *sensor) if (ret < 0) goto err_disable_regulators; - sensor->is_enabled = true; - return 0; err_disable_regulators: @@ -541,26 +530,37 @@ static int ov2680_s_ctrl(struct v4l2_ctrl *ctrl) { struct v4l2_subdev *sd = ctrl_to_sd(ctrl); struct ov2680_dev *sensor = to_ov2680_dev(sd); + int ret; - if (!sensor->is_enabled) + /* Only apply changes to the controls if the device is powered up */ + if (!pm_runtime_get_if_in_use(sensor->sd.dev)) { + ov2680_set_bayer_order(sensor, &sensor->fmt); return 0; + } switch (ctrl->id) { case V4L2_CID_GAIN: - return ov2680_gain_set(sensor, ctrl->val); + ret = ov2680_gain_set(sensor, ctrl->val); + break; case V4L2_CID_EXPOSURE: - return ov2680_exposure_set(sensor, ctrl->val); + ret = ov2680_exposure_set(sensor, ctrl->val); + break; case V4L2_CID_VFLIP: - return ov2680_set_vflip(sensor, ctrl->val); + ret = ov2680_set_vflip(sensor, ctrl->val); + break; case V4L2_CID_HFLIP: - return ov2680_set_hflip(sensor, ctrl->val); + ret = ov2680_set_hflip(sensor, ctrl->val); + break; case V4L2_CID_TEST_PATTERN: - return ov2680_test_pattern_set(sensor, ctrl->val); + ret = ov2680_test_pattern_set(sensor, ctrl->val); + break; default: + ret = -EINVAL; break; } - return -EINVAL; + pm_runtime_put(sensor->sd.dev); + return ret; } static const struct v4l2_ctrl_ops ov2680_ctrl_ops = { From patchwork Tue Jun 27 13:18:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 697092 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AEFDEB64DD for ; Tue, 27 Jun 2023 13:20:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230249AbjF0NUY (ORCPT ); Tue, 27 Jun 2023 09:20:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230290AbjF0NUO (ORCPT ); Tue, 27 Jun 2023 09:20:14 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71CB72944 for ; Tue, 27 Jun 2023 06:19:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687871942; 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=7YNytIuxe7Hkg0i+r88hLt7EshkDkEBeD1PDIZ6xVK8=; b=U+nMGjx76vKEf51SFl2zZxpbggPpQCK2m5E0JzlR9w4J0bVxj2pTkSw//Z8ZnY1qtO+qej eVW6DK6leetPrBdZLINOzeyhg3GrT7hYsr3K1u5n459T5jg5A6Aqbueqn2gh1BPp8eHU0V mStyOC0jqqPC40dcc+zEo4Qe5KhMg30= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-26-o1hT5_-APiud8ZDyBCMArQ-1; Tue, 27 Jun 2023 09:18:59 -0400 X-MC-Unique: o1hT5_-APiud8ZDyBCMArQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 436483815EFD; Tue, 27 Jun 2023 13:18:59 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.194.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB833400F5A; Tue, 27 Jun 2023 13:18:57 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Laurent Pinchart , Rui Miguel Silva , Daniel Scally Cc: Hans de Goede , Mauro Carvalho Chehab , Andy Shevchenko , Kate Hsuan , Tommaso Merciai , linux-media@vger.kernel.org Subject: [PATCH v3 17/29] media: ov2680: Add support for ACPI enumeration Date: Tue, 27 Jun 2023 15:18:18 +0200 Message-ID: <20230627131830.54601-18-hdegoede@redhat.com> In-Reply-To: <20230627131830.54601-1-hdegoede@redhat.com> References: <20230627131830.54601-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add an acpi_match_table now that all the other bits necessary for ACPI support are in place. Acked-by: Rui Miguel Silva Signed-off-by: Hans de Goede --- drivers/media/i2c/ov2680.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c index 52ae265612fa..b011dadbb98a 100644 --- a/drivers/media/i2c/ov2680.c +++ b/drivers/media/i2c/ov2680.c @@ -934,11 +934,18 @@ static const struct of_device_id ov2680_dt_ids[] = { }; MODULE_DEVICE_TABLE(of, ov2680_dt_ids); +static const struct acpi_device_id ov2680_acpi_ids[] = { + { "OVTI2680" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(acpi, ov2680_acpi_ids); + static struct i2c_driver ov2680_i2c_driver = { .driver = { .name = "ov2680", .pm = pm_sleep_ptr(&ov2680_pm_ops), .of_match_table = of_match_ptr(ov2680_dt_ids), + .acpi_match_table = ov2680_acpi_ids, }, .probe = ov2680_probe, .remove = ov2680_remove, From patchwork Tue Jun 27 13:18:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 697090 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F7DDEB64DD for ; Tue, 27 Jun 2023 13:20:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229599AbjF0NU4 (ORCPT ); Tue, 27 Jun 2023 09:20:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230025AbjF0NUY (ORCPT ); Tue, 27 Jun 2023 09:20:24 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08F022949 for ; Tue, 27 Jun 2023 06:19:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687871949; 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=mkf3I5gdk7XEjn8bCuQ+aD3I35PlbZkEB2r+HGOtCrw=; b=TLPfX1ykaAEv7LEF47GIWsgo7CUsp8sZrN9VlLSjbGYfdc2hVC3eLg8TMu5Gp+KdP/CmWi Pv1Eezz7+qkq89k4F8p9B+5/tDE+6GzcgOQzHeYwnj5hhTVadrVivQaAedLcOx31xerQ7P 3cAd8hFmGri0CIN/uSatrvOfsSd8NkM= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-527-zXIBBQPdPKC1zA8aqA_bAA-1; Tue, 27 Jun 2023 09:19:05 -0400 X-MC-Unique: zXIBBQPdPKC1zA8aqA_bAA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5839D3C0CD50; Tue, 27 Jun 2023 13:19:02 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.194.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08CF8400F5A; Tue, 27 Jun 2023 13:19:00 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Laurent Pinchart , Rui Miguel Silva , Daniel Scally Cc: Hans de Goede , Mauro Carvalho Chehab , Andy Shevchenko , Kate Hsuan , Tommaso Merciai , linux-media@vger.kernel.org Subject: [PATCH v3 19/29] media: ov2680: Annotate the per mode register setting lists Date: Tue, 27 Jun 2023 15:18:20 +0200 Message-ID: <20230627131830.54601-20-hdegoede@redhat.com> In-Reply-To: <20230627131830.54601-1-hdegoede@redhat.com> References: <20230627131830.54601-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Annotate the per mode register setting lists. This is a preparation patch for moving to calculating the per mode settings, allowing to set any mode through cropping. The annotations make it easier to see which registers are mode dependent and which are fixed. Acked-by: Rui Miguel Silva Signed-off-by: Hans de Goede --- drivers/media/i2c/ov2680.c | 118 ++++++++++++++++++++++++++++++++----- 1 file changed, 104 insertions(+), 14 deletions(-) diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c index 7ca70877abf1..09b74c15220b 100644 --- a/drivers/media/i2c/ov2680.c +++ b/drivers/media/i2c/ov2680.c @@ -141,27 +141,117 @@ static const int ov2680_hv_flip_bayer_order[] = { }; static const struct reg_sequence ov2680_setting_30fps_QUXGA_800_600[] = { - {0x3086, 0x01}, {0x370a, 0x23}, {0x3808, 0x03}, {0x3809, 0x20}, - {0x380a, 0x02}, {0x380b, 0x58}, {0x380c, 0x06}, {0x380d, 0xac}, - {0x380e, 0x02}, {0x380f, 0x84}, {0x3811, 0x04}, {0x3813, 0x04}, - {0x3814, 0x31}, {0x3815, 0x31}, {0x3820, 0xc0}, {0x4008, 0x00}, - {0x4009, 0x03}, {0x4837, 0x1e}, {0x3501, 0x4e}, {0x3502, 0xe0}, + /* Set PLL SP DIV to 1 for binning mode */ + {0x3086, 0x01}, + + /* Sensor control register 0x0a to 0x23 for binning mode */ + {0x370a, 0x23}, + + /* Set X and Y output size to 800x600 */ + {0x3808, 0x03}, + {0x3809, 0x20}, + {0x380a, 0x02}, + {0x380b, 0x58}, + + /* Set HTS + VTS to 1708x644 */ + {0x380c, 0x06}, + {0x380d, 0xac}, + {0x380e, 0x02}, + {0x380f, 0x84}, + + /* Set ISP WIN X and Y start to 4x4 */ + {0x3811, 0x04}, + {0x3813, 0x04}, + + /* Set X INC and Y INC for binning */ + {0x3814, 0x31}, + {0x3815, 0x31}, + + /* Initialize FORMAT1 to default/reset value (vflip disabled) */ + {0x3820, 0xc0}, + + /* Set black level compensation range to 0 - 3 (default 0 - 11) */ + {0x4008, 0x00}, + {0x4009, 0x03}, + + /* Set MIPI pclk period to 0x1e (default/reset is 0x18) */ + {0x4837, 0x1e}, + + /* Initialize exposure to 0x4ee (overridden by the ctrl, drop this */ + {0x3501, 0x4e}, + {0x3502, 0xe0}, + + /* R MANUAL set exposure and gain to manual (hw does not do auto) */ {0x3503, 0x03}, }; static const struct reg_sequence ov2680_setting_30fps_720P_1280_720[] = { - {0x3086, 0x00}, {0x3808, 0x05}, {0x3809, 0x00}, {0x380a, 0x02}, - {0x380b, 0xd0}, {0x380c, 0x06}, {0x380d, 0xa8}, {0x380e, 0x05}, - {0x380f, 0x0e}, {0x3811, 0x08}, {0x3813, 0x06}, {0x3814, 0x11}, - {0x3815, 0x11}, {0x3820, 0xc0}, {0x4008, 0x00}, + /* Set PLL SP DIV to 0 for not binning mode */ + {0x3086, 0x00}, + + /* Set X and Y output size to 1280x720 */ + {0x3808, 0x05}, + {0x3809, 0x00}, + {0x380a, 0x02}, + {0x380b, 0xd0}, + + /* Set HTS + VTS to 1704x1294 */ + {0x380c, 0x06}, + {0x380d, 0xa8}, + {0x380e, 0x05}, + {0x380f, 0x0e}, + + /* Set ISP WIN X and Y start to 8x6 */ + {0x3811, 0x08}, + {0x3813, 0x06}, + + /* Set X INC and Y INC for non binning */ + {0x3814, 0x11}, + {0x3815, 0x11}, + + /* Initialize FORMAT1 to default/reset value (vflip disabled) */ + {0x3820, 0xc0}, + + /* Set backlight compensation range start to 0 */ + {0x4008, 0x00}, }; static const struct reg_sequence ov2680_setting_30fps_UXGA_1600_1200[] = { - {0x3086, 0x00}, {0x3501, 0x4e}, {0x3502, 0xe0}, {0x3808, 0x06}, - {0x3809, 0x40}, {0x380a, 0x04}, {0x380b, 0xb0}, {0x380c, 0x06}, - {0x380d, 0xa8}, {0x380e, 0x05}, {0x380f, 0x0e}, {0x3811, 0x00}, - {0x3813, 0x00}, {0x3814, 0x11}, {0x3815, 0x11}, {0x3820, 0xc0}, - {0x4008, 0x00}, {0x4837, 0x18} + /* Set PLL SP DIV to 0 for not binning mode */ + {0x3086, 0x00}, + + /* Initialize exposure to 0x4ee (overridden by the ctrl, drop this */ + {0x3501, 0x4e}, + {0x3502, 0xe0}, + + /* Set X and Y output size to 1600x1200 */ + {0x3808, 0x06}, + {0x3809, 0x40}, + {0x380a, 0x04}, + {0x380b, 0xb0}, + + /* Set HTS + VTS to 1704x1294 */ + {0x380c, 0x06}, + {0x380d, 0xa8}, + {0x380e, 0x05}, + {0x380f, 0x0e}, + + /* Set ISP WIN X and Y start to 0x0 */ + {0x3811, 0x00}, + {0x3813, 0x00}, + + /* Set X INC and Y INC for non binning */ + {0x3814, 0x11}, + {0x3815, 0x11}, + + /* Initialize FORMAT1 to default/reset value (vflip disabled) */ + {0x3820, 0xc0}, + + /* Set backlight compensation range start to 0 */ + {0x4008, 0x00}, + + /* Set MIPI pclk period to default/reset value of 0x18 */ + {0x4837, 0x18} }; static const struct ov2680_mode_info ov2680_mode_init_data = { From patchwork Tue Jun 27 13:18:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 697091 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 827E3EB64DC for ; Tue, 27 Jun 2023 13:20:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230423AbjF0NU2 (ORCPT ); Tue, 27 Jun 2023 09:20:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229841AbjF0NUT (ORCPT ); Tue, 27 Jun 2023 09:20:19 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26EF22948 for ; Tue, 27 Jun 2023 06:19:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687871948; 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=hzpDyCrOo2UnaL2MBj0ouL36Sug3PGNPxzhNMfM03go=; b=AwR3u0pDxpzceE/1WHVhwFu1DRcZzXA9L5SZWurPY1MQdiehEhcnTbl/8Go4kVc2SYfTwX 2OhKBUGniUjoh/4MCoK5em4YLMu9j6fyDxRXKzVeqSKNib39kpuJXA4n+Wh+c3fRS74MwX vBZx/3A2JLUGQ+Yr5jKy5p6lclMIZCQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-255-i8_xjltePIOzciQ67K27uQ-1; Tue, 27 Jun 2023 09:19:05 -0400 X-MC-Unique: i8_xjltePIOzciQ67K27uQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DD5F48C7C30; Tue, 27 Jun 2023 13:19:03 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.194.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BCDF40F169; Tue, 27 Jun 2023 13:19:02 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Laurent Pinchart , Rui Miguel Silva , Daniel Scally Cc: Hans de Goede , Mauro Carvalho Chehab , Andy Shevchenko , Kate Hsuan , Tommaso Merciai , linux-media@vger.kernel.org Subject: [PATCH v3 20/29] media: ov2680: Add ov2680_mode struct Date: Tue, 27 Jun 2023 15:18:21 +0200 Message-ID: <20230627131830.54601-21-hdegoede@redhat.com> In-Reply-To: <20230627131830.54601-1-hdegoede@redhat.com> References: <20230627131830.54601-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add an ov2680_mode struct to group together mode related state. For now this only containst the v4l2_mbus_framefmt and the frame_interval. This is a preparation patch for moving to calculating the per mode settings, which will store more info in the new ov2680_mode struct. Acked-by: Rui Miguel Silva Signed-off-by: Hans de Goede --- drivers/media/i2c/ov2680.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c index 09b74c15220b..79789b9efadf 100644 --- a/drivers/media/i2c/ov2680.c +++ b/drivers/media/i2c/ov2680.c @@ -101,6 +101,11 @@ struct ov2680_ctrls { struct v4l2_ctrl *test_pattern; }; +struct ov2680_mode { + struct v4l2_mbus_framefmt fmt; + struct v4l2_fract frame_interval; +}; + struct ov2680_dev { struct device *dev; struct fwnode_handle *ep_fwnode; @@ -119,8 +124,7 @@ struct ov2680_dev { bool is_streaming; struct ov2680_ctrls ctrls; - struct v4l2_mbus_framefmt fmt; - struct v4l2_fract frame_interval; + struct ov2680_mode mode; const struct ov2680_mode_info *current_mode; }; @@ -339,7 +343,7 @@ static int ov2680_set_vflip(struct ov2680_dev *sensor, s32 val) if (ret < 0) return ret; - ov2680_set_bayer_order(sensor, &sensor->fmt); + ov2680_set_bayer_order(sensor, &sensor->mode.fmt); return 0; } @@ -355,7 +359,7 @@ static int ov2680_set_hflip(struct ov2680_dev *sensor, s32 val) if (ret < 0) return ret; - ov2680_set_bayer_order(sensor, &sensor->fmt); + ov2680_set_bayer_order(sensor, &sensor->mode.fmt); return 0; } @@ -468,7 +472,7 @@ static int ov2680_s_g_frame_interval(struct v4l2_subdev *sd, struct ov2680_dev *sensor = to_ov2680_dev(sd); mutex_lock(&sensor->lock); - fi->interval = sensor->frame_interval; + fi->interval = sensor->mode.frame_interval; mutex_unlock(&sensor->lock); return 0; @@ -516,7 +520,7 @@ static int ov2680_enum_mbus_code(struct v4l2_subdev *sd, if (code->pad != 0 || code->index != 0) return -EINVAL; - code->code = sensor->fmt.code; + code->code = sensor->mode.fmt.code; return 0; } @@ -537,7 +541,7 @@ static int ov2680_get_fmt(struct v4l2_subdev *sd, fmt = v4l2_subdev_get_try_format(&sensor->sd, sd_state, format->pad); } else { - fmt = &sensor->fmt; + fmt = &sensor->mode.fmt; } format->format = *fmt; @@ -583,7 +587,7 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd, } sensor->current_mode = mode; - sensor->fmt = format->format; + sensor->mode.fmt = format->format; unlock: mutex_unlock(&sensor->lock); @@ -628,7 +632,7 @@ static int ov2680_enum_frame_interval(struct v4l2_subdev *sd, if (fie->index) return -EINVAL; - fie->interval = sensor->frame_interval; + fie->interval = sensor->mode.frame_interval; return 0; } @@ -641,7 +645,7 @@ static int ov2680_s_ctrl(struct v4l2_ctrl *ctrl) /* Only apply changes to the controls if the device is powered up */ if (!pm_runtime_get_if_in_use(sensor->sd.dev)) { - ov2680_set_bayer_order(sensor, &sensor->fmt); + ov2680_set_bayer_order(sensor, &sensor->mode.fmt); return 0; } @@ -699,11 +703,11 @@ static int ov2680_mode_init(struct ov2680_dev *sensor) const struct ov2680_mode_info *init_mode; /* set initial mode */ - ov2680_fill_format(sensor, &sensor->fmt, + ov2680_fill_format(sensor, &sensor->mode.fmt, OV2680_DEFAULT_WIDTH, OV2680_DEFAULT_HEIGHT); - sensor->frame_interval.denominator = OV2680_FRAME_RATE; - sensor->frame_interval.numerator = 1; + sensor->mode.frame_interval.denominator = OV2680_FRAME_RATE; + sensor->mode.frame_interval.numerator = 1; init_mode = &ov2680_mode_init_data; From patchwork Tue Jun 27 13:18:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 697089 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74B6FEB64D9 for ; Tue, 27 Jun 2023 13:21:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230023AbjF0NU6 (ORCPT ); Tue, 27 Jun 2023 09:20:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230195AbjF0NUY (ORCPT ); Tue, 27 Jun 2023 09:20:24 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AD1B2951 for ; Tue, 27 Jun 2023 06:19:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687871954; 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=Py3m8gLUNPEn+UP9knJ5Khore2RWIznc21UGom5cOdY=; b=KX0rYwcKgyWQLmCJlj2WtSt2O5TPbHg1QnTOYVATvns7l7InpsfGvaNucXgv/8zFEG80ea ju79ERYwmoMj/GfQ4zPemb808UEXbXqI6q58ntZb17/TN1Es06SQAmhgSCzoayXY/STQvT D9N6byDkHsahBS7ZOtmKhD81nqTFDsE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-260-Ws-QWrDAOLmWdjyMvyzYpg-1; Tue, 27 Jun 2023 09:19:07 -0400 X-MC-Unique: Ws-QWrDAOLmWdjyMvyzYpg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EE8118631DF; Tue, 27 Jun 2023 13:19:06 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.194.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2311400F5A; Tue, 27 Jun 2023 13:19:05 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Laurent Pinchart , Rui Miguel Silva , Daniel Scally Cc: Hans de Goede , Mauro Carvalho Chehab , Andy Shevchenko , Kate Hsuan , Tommaso Merciai , linux-media@vger.kernel.org Subject: [PATCH v3 22/29] media: ov2680: Add an __ov2680_get_pad_format() helper function Date: Tue, 27 Jun 2023 15:18:23 +0200 Message-ID: <20230627131830.54601-23-hdegoede@redhat.com> In-Reply-To: <20230627131830.54601-1-hdegoede@redhat.com> References: <20230627131830.54601-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add an __ov2680_get_pad_format() helper function. This is a preparation patch for adding selections support. Acked-by: Rui Miguel Silva Signed-off-by: Hans de Goede --- drivers/media/i2c/ov2680.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c index 15e0b0ef5e8f..c692e0457770 100644 --- a/drivers/media/i2c/ov2680.c +++ b/drivers/media/i2c/ov2680.c @@ -216,6 +216,18 @@ static void ov2680_set_bayer_order(struct ov2680_dev *sensor, fmt->code = ov2680_hv_flip_bayer_order[hv_flip]; } +static struct v4l2_mbus_framefmt * +__ov2680_get_pad_format(struct ov2680_dev *sensor, + struct v4l2_subdev_state *state, + unsigned int pad, + enum v4l2_subdev_format_whence which) +{ + if (which == V4L2_SUBDEV_FORMAT_TRY) + return v4l2_subdev_get_try_format(&sensor->sd, state, pad); + + return &sensor->mode.fmt; +} + static void ov2680_fill_format(struct ov2680_dev *sensor, struct v4l2_mbus_framefmt *fmt, unsigned int width, unsigned int height) @@ -504,22 +516,16 @@ static int ov2680_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_format *format) { struct ov2680_dev *sensor = to_ov2680_dev(sd); - struct v4l2_mbus_framefmt *fmt = NULL; + struct v4l2_mbus_framefmt *fmt; if (format->pad != 0) return -EINVAL; + fmt = __ov2680_get_pad_format(sensor, sd_state, format->pad, + format->which); + mutex_lock(&sensor->lock); - - if (format->which == V4L2_SUBDEV_FORMAT_TRY) { - fmt = v4l2_subdev_get_try_format(&sensor->sd, sd_state, - format->pad); - } else { - fmt = &sensor->mode.fmt; - } - format->format = *fmt; - mutex_unlock(&sensor->lock); return 0; From patchwork Tue Jun 27 13:18:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 697087 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91EC9C001DB for ; Tue, 27 Jun 2023 13:21:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229655AbjF0NV1 (ORCPT ); Tue, 27 Jun 2023 09:21:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231154AbjF0NUt (ORCPT ); Tue, 27 Jun 2023 09:20:49 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 612142952 for ; Tue, 27 Jun 2023 06:19:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687871955; 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=vsjh68AwaiI9uZdM+NLzoO73sUn0GRzvtvlVHANlkGI=; b=IgQHc2p/tzP6PjU3aMd6vBoB5MQmq9Gv8wW45njWW8cORnOYSCUffTrvFRTY89eaF9wYfb qgHo29jZ0Cmn9bBlyJ3dMK3NfobRFUZRtgJlt2g3qgEgo+/O9aptzfSYIX99ykG7Mf6zCL TvOhxMVHHc4OudREGjscbp6wkPomK/A= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-240-8zx-Uht8PHSRKng8RnWRmw-1; Tue, 27 Jun 2023 09:19:12 -0400 X-MC-Unique: 8zx-Uht8PHSRKng8RnWRmw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8FC7A800969; Tue, 27 Jun 2023 13:19:11 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.194.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4179A401061; Tue, 27 Jun 2023 13:19:10 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Laurent Pinchart , Rui Miguel Silva , Daniel Scally Cc: Hans de Goede , Mauro Carvalho Chehab , Andy Shevchenko , Kate Hsuan , Tommaso Merciai , linux-media@vger.kernel.org Subject: [PATCH v3 25/29] media: ov2680: Add a bunch of register tweaks Date: Tue, 27 Jun 2023 15:18:26 +0200 Message-ID: <20230627131830.54601-26-hdegoede@redhat.com> In-Reply-To: <20230627131830.54601-1-hdegoede@redhat.com> References: <20230627131830.54601-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Usually when developing a sensor driver with help from the vendor the vendor will provide a bunch of register tweaks for optimal performance of the sensor. The atomisp-ov2680.c driver was (presumably) developed by Intel with help from OmniVision and indeed contains a bunch of register tweaks. Add these register tweaks to the "main" ov2680.c driver. Acked-by: Rui Miguel Silva Signed-off-by: Hans de Goede --- drivers/media/i2c/ov2680.c | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c index e26a6487d421..6c9f038c4631 100644 --- a/drivers/media/i2c/ov2680.c +++ b/drivers/media/i2c/ov2680.c @@ -178,18 +178,71 @@ static const int ov2680_hv_flip_bayer_order[] = { }; static const struct reg_sequence ov2680_global_setting[] = { + /* MIPI PHY, 0x10 -> 0x1c enable bp_c_hs_en_lat and bp_d_hs_en_lat */ + {0x3016, 0x1c}, + /* R MANUAL set exposure and gain to manual (hw does not do auto) */ {0x3503, 0x03}, + /* Analog control register tweaks */ + {0x3603, 0x39}, /* Reset value 0x99 */ + {0x3604, 0x24}, /* Reset value 0x74 */ + {0x3621, 0x37}, /* Reset value 0x44 */ + + /* Sensor control register tweaks */ + {0x3701, 0x64}, /* Reset value 0x61 */ + {0x3705, 0x3c}, /* Reset value 0x21 */ + {0x370c, 0x50}, /* Reset value 0x10 */ + {0x370d, 0xc0}, /* Reset value 0x00 */ + {0x3718, 0x88}, /* Reset value 0x80 */ + + /* PSRAM tweaks */ + {0x3781, 0x80}, /* Reset value 0x00 */ + {0x3784, 0x0c}, /* Reset value 0x00, based on OV2680_R1A_AM10.ovt */ + {0x3789, 0x60}, /* Reset value 0x50 */ + + /* BLC CTRL00 0x01 -> 0x81 set avg_weight to 8 */ + {0x4000, 0x81}, + /* Set black level compensation range to 0 - 3 (default 0 - 11) */ {0x4008, 0x00}, {0x4009, 0x03}, + /* VFIFO R2 0x00 -> 0x02 set Frame reset enable */ + {0x4602, 0x02}, + + /* MIPI ctrl CLK PREPARE MIN change from 0x26 (38) -> 0x36 (54) */ + {0x481f, 0x36}, + + /* MIPI ctrl CLK LPX P MIN change from 0x32 (50) -> 0x36 (54) */ + {0x4825, 0x36}, + + /* R ISP CTRL2 0x20 -> 0x30, set sof_sel bit */ + {0x5002, 0x30}, + /* * Window CONTROL 0x00 -> 0x01, enable manual window control, * this is necessary for full size flip and mirror support. */ {0x5708, 0x01}, + + /* + * DPC CTRL0 0x14 -> 0x3e, set enable_tail, enable_3x3_cluster + * and enable_general_tail bits based OV2680_R1A_AM10.ovt. + */ + {0x5780, 0x3e}, + + /* DPC MORE CONNECTION CASE THRE 0x0c (12) -> 0x02 (2) */ + {0x5788, 0x02}, + + /* DPC GAIN LIST1 0x0f (15) -> 0x08 (8) */ + {0x578e, 0x08}, + + /* DPC GAIN LIST2 0x3f (63) -> 0x0c (12) */ + {0x578f, 0x0c}, + + /* DPC THRE RATIO 0x04 (4) -> 0x00 (0) */ + {0x5792, 0x00}, }; static struct ov2680_dev *to_ov2680_dev(struct v4l2_subdev *sd) From patchwork Tue Jun 27 13:18:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 697088 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93512C0015E for ; Tue, 27 Jun 2023 13:21:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230109AbjF0NU6 (ORCPT ); Tue, 27 Jun 2023 09:20:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231134AbjF0NUr (ORCPT ); Tue, 27 Jun 2023 09:20:47 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBB722955 for ; Tue, 27 Jun 2023 06:19:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687871957; 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=HL+9qW2GOntrfz7uUONccp/geKxLZdPL1bY5UK7EiCY=; b=VBNk6aq6nrKdH777+6fn2HWDVfDtfVxlOT74xUf0nc/S9gZMkzwlsMRWGPXAr1JrNmo0Ao KqMpiTd0DO5gYWAZGpFNEEgc3mBMUqRjXW+9JlGrdW4dkfmaIJRHmMW7qLwQDlkP4sDn/6 jscY7kso9JiOUr0yUxZ0mW/6owAbb1U= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-536-gOgg61nAPuSXE8iEMWbm-A-1; Tue, 27 Jun 2023 09:19:13 -0400 X-MC-Unique: gOgg61nAPuSXE8iEMWbm-A-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1F28C10504AA; Tue, 27 Jun 2023 13:19:13 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.194.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id C334C400F5A; Tue, 27 Jun 2023 13:19:11 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Laurent Pinchart , Rui Miguel Silva , Daniel Scally Cc: Hans de Goede , Mauro Carvalho Chehab , Andy Shevchenko , Kate Hsuan , Tommaso Merciai , linux-media@vger.kernel.org Subject: [PATCH v3 26/29] media: ov2680: Drop unnecessary pad checks Date: Tue, 27 Jun 2023 15:18:27 +0200 Message-ID: <20230627131830.54601-27-hdegoede@redhat.com> In-Reply-To: <20230627131830.54601-1-hdegoede@redhat.com> References: <20230627131830.54601-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Drop unnecessary pad checks in enum_mbus_code, get_fmt, set_fmt this is already checked by check_pad() from drivers/media/v4l2-core/v4l2-subdev.c. Acked-by: Rui Miguel Silva Signed-off-by: Hans de Goede --- drivers/media/i2c/ov2680.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c index 6c9f038c4631..d1de2fc50f4e 100644 --- a/drivers/media/i2c/ov2680.c +++ b/drivers/media/i2c/ov2680.c @@ -589,7 +589,7 @@ static int ov2680_enum_mbus_code(struct v4l2_subdev *sd, { struct ov2680_dev *sensor = to_ov2680_dev(sd); - if (code->pad != 0 || code->index != 0) + if (code->index != 0) return -EINVAL; code->code = sensor->mode.fmt.code; @@ -604,9 +604,6 @@ static int ov2680_get_fmt(struct v4l2_subdev *sd, struct ov2680_dev *sensor = to_ov2680_dev(sd); struct v4l2_mbus_framefmt *fmt; - if (format->pad != 0) - return -EINVAL; - fmt = __ov2680_get_pad_format(sensor, sd_state, format->pad, format->which); @@ -627,9 +624,6 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd, unsigned int width, height; int ret = 0; - if (format->pad != 0) - return -EINVAL; - crop = __ov2680_get_pad_crop(sensor, sd_state, format->pad, format->which); From patchwork Tue Jun 27 13:18:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 697086 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67C32EB64DD for ; Tue, 27 Jun 2023 13:22:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230158AbjF0NV2 (ORCPT ); Tue, 27 Jun 2023 09:21:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231152AbjF0NUt (ORCPT ); Tue, 27 Jun 2023 09:20:49 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D423710FC for ; Tue, 27 Jun 2023 06:19:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687871963; 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=jXyuPG3nVUsOxq8Ri0oMCx9yYwZq/YYp3TT4e/nljwk=; b=i9MmyBraLknNelIWxvU80J/mE/WC9IjA4co9mbQ9swPhfRVPKZ/lIhqVc9/ql6KhnQ0bP+ CbGcU2JFwDTp0zmffGYh2nL7lqs/kgRkudTUdwH2UoovTZyDtzqXUg8d+Hgecsf9QI5TUg WvPENEunoqjEwbhnV6fafwRw2LNQSAs= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-628-eJ_b4G9BP42-Mv3rXqgeHA-1; Tue, 27 Jun 2023 09:19:19 -0400 X-MC-Unique: eJ_b4G9BP42-Mv3rXqgeHA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 04FF33815EFC; Tue, 27 Jun 2023 13:19:19 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.194.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id ACB7F401061; Tue, 27 Jun 2023 13:19:17 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Laurent Pinchart , Rui Miguel Silva , Daniel Scally Cc: Hans de Goede , Mauro Carvalho Chehab , Andy Shevchenko , Kate Hsuan , Tommaso Merciai , linux-media@vger.kernel.org Subject: [PATCH v3 29/29] MAINTAINERS: Add Hans de Goede as OV2680 sensor driver maintainer Date: Tue, 27 Jun 2023 15:18:30 +0200 Message-ID: <20230627131830.54601-30-hdegoede@redhat.com> In-Reply-To: <20230627131830.54601-1-hdegoede@redhat.com> References: <20230627131830.54601-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add myself as OV2680 sensor driver maintainer. Signed-off-by: Hans de Goede Reviewed-by: Rui Miguel Silva Reviewed-by: Daniel Scally --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index c6a7b43321d9..2ec35c3569dd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -15518,6 +15518,7 @@ F: drivers/media/i2c/ov13b10.c OMNIVISION OV2680 SENSOR DRIVER M: Rui Miguel Silva +M: Hans de Goede L: linux-media@vger.kernel.org S: Maintained T: git git://linuxtv.org/media_tree.git