From patchwork Tue Jan 31 19:20:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 650786 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 DDF7AC636CC for ; Tue, 31 Jan 2023 19:21:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230255AbjAaTVA (ORCPT ); Tue, 31 Jan 2023 14:21:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231431AbjAaTUz (ORCPT ); Tue, 31 Jan 2023 14:20:55 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34A1B5977F for ; Tue, 31 Jan 2023 11:20:51 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id j32-20020a05600c1c2000b003dc4fd6e61dso6398499wms.5 for ; Tue, 31 Jan 2023 11:20:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NLNhf5APnhwJhTJUEBocYb42Q20VcIzYBY0/ED9ON98=; b=KN/2WCK+J1NkgTzN8gTGMBcQwmty4Xh+CBioXZaduJOPXXILuDWwQMdBSway5LAiKU FnMe0GIm4c/RxBdcmzuzF/qtGyv5r1bblwhShFqO9WhDDuIphXd4hxo6R0tDVuU4jBfi 5fKfdNW/+uQFaHJXWb1qGuxxgD9dt2Uwi78IDeZ/2xq/77aqvqXG5enCtjVrTDpJmx84 5UTHkbercpCNj09OIG/Aia8tgsqN9ZZiLGsKgk5obYmosjxPPPIVYT/UxFOF3XvwSK/R L2MRukVfq0R4iPBkuXGfGcILirK8RVPTPT06gDxKgVImS/FC++DZzaMsqWgbk/KeHx6E wrpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NLNhf5APnhwJhTJUEBocYb42Q20VcIzYBY0/ED9ON98=; b=XTpNQ0pNtaqXS794hMR+1x/77CxeTaoLo8bD5rDOFEOe4Qq4I1kqEjStuOK6zRgbeB rYCRAkOhAspN5f1nCT+dKQgkfBRq4uN0qNLZJd+WF5EEQs+1AgAJlEsdYCxQc1simgI1 iH4lAHB9jOPWFSGl7qkuroGwUCmyBRLSTt5JXccX+TRrCvwyDY2I/sRR/p7Azftch0xb lBd0uTNDxKmQYVnpazKin/BQG7f1JNtBxZM0NQ+NldWCUNCHH+fMf/nHkdsS5oPIeTof IqWQm9AmDh2aek+VBimqXvgB4Dw0AF+0ViS82Xv6O8I46QruLz0+k583w8zvtYHLREXn CuJA== X-Gm-Message-State: AO0yUKUsGNCYyMpV9TO78l2sv9oHgY7BHTesodq7VEgicb47hWytGUqz cnH43pSt9cRx14/K2sM8oX0LBg== X-Google-Smtp-Source: AK7set9N+y2qABTbja5ZTw44ju26/j0hTSK/frm55MyXJDq0OqkEg6txqMGSm/InsdkqwoEP9TuYpw== X-Received: by 2002:a05:600c:44d4:b0:3dc:405b:99b4 with SMTP id f20-20020a05600c44d400b003dc405b99b4mr19835196wmo.25.1675192849793; Tue, 31 Jan 2023 11:20:49 -0800 (PST) Received: from dave-Ubuntu2204.. (194.15.169.217.in-addr.arpa. [217.169.15.194]) by smtp.googlemail.com with ESMTPSA id x9-20020a05600c21c900b003dc434b39c7sm3527512wmj.0.2023.01.31.11.20.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 11:20:49 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org Cc: Dave Stevenson Subject: [PATCH 01/11] media: i2c: imx290: Match kernel coding style on whitespace Date: Tue, 31 Jan 2023 19:20:06 +0000 Message-Id: <20230131192016.3476937-2-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230131192016.3476937-1-dave.stevenson@raspberrypi.com> References: <20230131192016.3476937-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Fix up a couple of coding style issues regarding missing blank lines after declarations, double blank lines, and incorrect indentation. Signed-off-by: Dave Stevenson --- drivers/media/i2c/imx290.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index a370f1102334..88c7201510a2 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -106,7 +106,6 @@ #define IMX290_VMAX_DEFAULT 1125 - /* * The IMX290 pixel array is organized as follows: * @@ -335,6 +334,7 @@ static const s64 imx290_link_freq_2lanes[] = { [FREQ_INDEX_1080P] = 445500000, [FREQ_INDEX_720P] = 297000000, }; + static const s64 imx290_link_freq_4lanes[] = { [FREQ_INDEX_1080P] = 222750000, [FREQ_INDEX_720P] = 148500000, @@ -465,7 +465,7 @@ static int __always_unused imx290_read(struct imx290 *imx290, u32 addr, u32 *val data, (addr >> IMX290_REG_SIZE_SHIFT) & 3); if (ret < 0) { dev_err(imx290->dev, "%u-bit read from 0x%04x failed: %d\n", - ((addr >> IMX290_REG_SIZE_SHIFT) & 3) * 8, + ((addr >> IMX290_REG_SIZE_SHIFT) & 3) * 8, addr & IMX290_REG_ADDR_MASK, ret); return ret; } @@ -486,7 +486,7 @@ static int imx290_write(struct imx290 *imx290, u32 addr, u32 value, int *err) data, (addr >> IMX290_REG_SIZE_SHIFT) & 3); if (ret < 0) { dev_err(imx290->dev, "%u-bit write to 0x%04x failed: %d\n", - ((addr >> IMX290_REG_SIZE_SHIFT) & 3) * 8, + ((addr >> IMX290_REG_SIZE_SHIFT) & 3) * 8, addr & IMX290_REG_ADDR_MASK, ret); if (err) *err = ret; @@ -752,8 +752,7 @@ static int imx290_start_streaming(struct imx290 *imx290, /* Set init register settings */ ret = imx290_set_register_array(imx290, imx290_global_init_settings, - ARRAY_SIZE( - imx290_global_init_settings)); + ARRAY_SIZE(imx290_global_init_settings)); if (ret < 0) { dev_err(imx290->dev, "Could not set init registers\n"); return ret; From patchwork Tue Jan 31 19:20:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 650785 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 2F2F8C38142 for ; Tue, 31 Jan 2023 19:21:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230372AbjAaTVG (ORCPT ); Tue, 31 Jan 2023 14:21:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231482AbjAaTU4 (ORCPT ); Tue, 31 Jan 2023 14:20:56 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0B45589A6 for ; Tue, 31 Jan 2023 11:20:52 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id k8-20020a05600c1c8800b003dc57ea0dfeso5271643wms.0 for ; Tue, 31 Jan 2023 11:20:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FFJWbZbE2PPVfA3ICvzj1Enxs9hPxy1DhzpkcqIlUJE=; b=i0SO1MwfH4e8osruv9YP2+/BvlSSP9K9t4aQx2AyPESiOz/N+cE6tXjUX9IgpPzPKA beSIS+BqJt5eKh4KABqCyHkKR0oKCe8/PA9ys+zbwm5jhUdxeXZkg7p2wl/RdWmkyeIR EDZZuFSeqs+F8QlHGVayw7Aq7N6X05imAtVD7uxJ/XV30GQqm8KkWlZIlUT+nlkaITfR e95nKFzz6ft9e1aR3Qe5eLy//pSBp8faPn/XPiUzQVX2n30sZv2XTizZt+Kth12ValNf MXQsq9U24QB9rr/KTNWWtrq/e1FmKrIN5dD6zXgNXP51MO+d095O0oYe8CnYB+ZVpm+O Ca/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FFJWbZbE2PPVfA3ICvzj1Enxs9hPxy1DhzpkcqIlUJE=; b=O+GGievjFQ9UWzTcIjbuEjTd6JAz2XYi9rLMUgthyXbXMNIHpRNB7k2BwIS6sUeo4Y W9wzFVNXMqEClqjuAHExERBhxbcF8+zcMSXDEGQI+aJr0gYqtxgpEea+CzWqtc8ZYtZE cWpHU9A7lORLjYLsdWSelagCsHI2tJiGHohS2LnY+cJpaghumLwI8ZLKcYiaVtWbxMwm yFrEvjOl246+Euk/HcWAqV7KOI2nFsqaKBUknjUbNuu4hVwZ1Bl9DCbOW+1Bl9tUb0Aq yuEjfamlse2H1J+tVv9ns3FyqcGeSOkwvg9l/97QHFGeHMJk2JahQ+G5TLYYAFrbpUhC wCQA== X-Gm-Message-State: AO0yUKU3zQlgNUQM1XZJOkrCCZCAj1m1dvMFxUYNLzKQT3qY3weIfQc0 03v+7pRZ3i/7uXDdDXl4UyEEwg== X-Google-Smtp-Source: AK7set/Ryp0Euz247gW8j9Dx3LCwvsvJnLSQ2lVfABqva/9+WquKABmLJfm4nS5nP27jiAcUkgrSWA== X-Received: by 2002:a05:600c:3b0f:b0:3dc:5e21:8aa2 with SMTP id m15-20020a05600c3b0f00b003dc5e218aa2mr7086964wms.34.1675192851382; Tue, 31 Jan 2023 11:20:51 -0800 (PST) Received: from dave-Ubuntu2204.. (194.15.169.217.in-addr.arpa. [217.169.15.194]) by smtp.googlemail.com with ESMTPSA id x9-20020a05600c21c900b003dc434b39c7sm3527512wmj.0.2023.01.31.11.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 11:20:50 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org Cc: Dave Stevenson Subject: [PATCH 02/11] media: i2c: imx290: Set the colorspace fields in the format Date: Tue, 31 Jan 2023 19:20:07 +0000 Message-Id: <20230131192016.3476937-3-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230131192016.3476937-1-dave.stevenson@raspberrypi.com> References: <20230131192016.3476937-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The colorspace fields were left untouched in imx290_set_fmt which lead to a v4l2-compliance failure. Signed-off-by: Dave Stevenson --- drivers/media/i2c/imx290.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index 88c7201510a2..bf96fd914303 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -897,6 +897,14 @@ static int imx290_set_fmt(struct v4l2_subdev *sd, fmt->format.code = imx290_formats[0].code[imx290->mono]; fmt->format.field = V4L2_FIELD_NONE; + fmt->format.colorspace = V4L2_COLORSPACE_RAW; + fmt->format.ycbcr_enc = + V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->format.colorspace); + fmt->format.quantization = + V4L2_MAP_QUANTIZATION_DEFAULT(true, fmt->format.colorspace, + fmt->format.ycbcr_enc); + fmt->format.xfer_func = + V4L2_MAP_XFER_FUNC_DEFAULT(fmt->format.colorspace); format = v4l2_subdev_get_pad_format(sd, sd_state, 0); From patchwork Tue Jan 31 19:20:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 649078 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 821BFC636CC for ; Tue, 31 Jan 2023 19:21:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230204AbjAaTVI (ORCPT ); Tue, 31 Jan 2023 14:21:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230520AbjAaTU5 (ORCPT ); Tue, 31 Jan 2023 14:20:57 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71557CA06 for ; Tue, 31 Jan 2023 11:20:54 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id r2so15206595wrv.7 for ; Tue, 31 Jan 2023 11:20:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QwvmcpgfyBG0Ign+mwoPJyQbUloHHhl8dlCljhw7ZAs=; b=JF1paWrIDc3DXJmrcybMwQyNMg/jsxkjLSSwXtEmGLXQUIPNs4nvRjA7KiU4g7xdbO nYhSt6PYt73PeGOI1T2e34sU8RRmdxt5i/XANUPsF5ImZ2Zp51dnm398Siq0cBofQqdw GNOSdSgDwVmm5wpwA7jh90wAaXn0sFRKH2TTniSyUgaVIMZDOGxogTkA+K9uFqoVJ135 i+N0HxWuC/SmE2yGoeUTgb43nwIwYp375S/kD5Nd8n9C0Pot+fZccorkyqgZwuja/GNe HhE1xspaz0O+kx2FO1ocvVq5mXxYAmcbIKlWut4FqZ5D+KBpVq9mO3jCBR4bsw3xaNUk BrFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QwvmcpgfyBG0Ign+mwoPJyQbUloHHhl8dlCljhw7ZAs=; b=nF56x3GmapJb3EWnD9e27vwKByobAInJHOETE0QUvMt3/dBXcIRwQXFMdCXFiSGX6j 2LJqSfh40jZTb04qSSDRjwpRbRuF8rxirlNOHLWgc/74l3AmOjYeVlosSGdgLQME4ST8 Bp+1SBijTm4akwYyLDdF9a9JxiaG1x+S/LiizsLzt34J7rgEa0xAD4XCRcWgeUPZ5D4x XaMZvFaUCXQxJTCHk7DYXv1ht26WvNP/PQ0VuE3JGqVFyilBO7e4UMe6P+FPZhDs8n3b hfnZ6TKRRpt2GJqR8vBmAtwCQWazGmOhe4/lIdJuwOf4f2m5L73mzL/H8f7WKzcbPol0 Fvyw== X-Gm-Message-State: AO0yUKXg7dC2+ctKOf9t/ChvbEXY7VMrAStQe4q7CAS4GgrMcuFo5mBc HRgq3msi/gn5LBRknvmSFDpubw== X-Google-Smtp-Source: AK7set/ObbtUvqhRs/9VRjiOm/XjJyVmURj0erY6aU0O6UBWKan2FcbgL36jbrB9jgeQLfGvwRh3TQ== X-Received: by 2002:a5d:5958:0:b0:2bf:ee58:72ae with SMTP id e24-20020a5d5958000000b002bfee5872aemr91504wri.50.1675192852960; Tue, 31 Jan 2023 11:20:52 -0800 (PST) Received: from dave-Ubuntu2204.. (194.15.169.217.in-addr.arpa. [217.169.15.194]) by smtp.googlemail.com with ESMTPSA id x9-20020a05600c21c900b003dc434b39c7sm3527512wmj.0.2023.01.31.11.20.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 11:20:52 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org Cc: Dave Stevenson Subject: [PATCH 03/11] media: i2c: imx290: Add V4L2_SUBDEV_FL_HAS_EVENTS and subscribe hooks Date: Tue, 31 Jan 2023 19:20:08 +0000 Message-Id: <20230131192016.3476937-4-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230131192016.3476937-1-dave.stevenson@raspberrypi.com> References: <20230131192016.3476937-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Any V4L2 subdevice that implements controls and declares V4L2_SUBDEV_FL_HAS_DEVNODE should also declare V4L2_SUBDEV_FL_HAS_EVENTS and implement subscribe_event and unsubscribe_event hooks. This driver didn't and would therefore fail v4l2-compliance testing. Add the relevant hooks. Signed-off-by: Dave Stevenson Reviewed-by: Laurent Pinchart Reviewed-by: Alexander Stein --- drivers/media/i2c/imx290.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index bf96fd914303..12946ca9d8d2 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -977,6 +978,11 @@ static int imx290_entity_init_cfg(struct v4l2_subdev *subdev, return 0; } +static const struct v4l2_subdev_core_ops imx290_core_ops = { + .subscribe_event = v4l2_ctrl_subdev_subscribe_event, + .unsubscribe_event = v4l2_event_subdev_unsubscribe, +}; + static const struct v4l2_subdev_video_ops imx290_video_ops = { .s_stream = imx290_set_stream, }; @@ -991,6 +997,7 @@ static const struct v4l2_subdev_pad_ops imx290_pad_ops = { }; static const struct v4l2_subdev_ops imx290_subdev_ops = { + .core = &imx290_core_ops, .video = &imx290_video_ops, .pad = &imx290_pad_ops, }; @@ -1009,7 +1016,8 @@ static int imx290_subdev_init(struct imx290 *imx290) imx290->current_mode = &imx290_modes_ptr(imx290)[0]; v4l2_i2c_subdev_init(&imx290->sd, client, &imx290_subdev_ops); - imx290->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; + imx290->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | + V4L2_SUBDEV_FL_HAS_EVENTS; imx290->sd.dev = imx290->dev; imx290->sd.entity.ops = &imx290_subdev_entity_ops; imx290->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; From patchwork Tue Jan 31 19:20:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 650784 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 3624CC636CD for ; Tue, 31 Jan 2023 19:21:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231634AbjAaTVK (ORCPT ); Tue, 31 Jan 2023 14:21:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230273AbjAaTU6 (ORCPT ); Tue, 31 Jan 2023 14:20:58 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1497115557 for ; Tue, 31 Jan 2023 11:20:55 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id bg13-20020a05600c3c8d00b003d9712b29d2so13257278wmb.2 for ; Tue, 31 Jan 2023 11:20:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YlBo0kZk8/xb90kgdTCjwFuYGgW4+Yg6DmE0UD6DHvk=; b=Rj3UqTy0hi43Lj3fLMMJ8+tfMeHCtk8rx+3qAkSYAgsD4c+W/h/AwD4EBEHHOle04o pIqVimw+VCNMvWKw9r7hp8Ua5oojvrpC72Do+lT9RuF5icxYZuo8LJhYEmwTChpk9W9A cg2mxPpCkx4fRMbYGrvhr4flKZwxb12R5/7J+J7ZXJ/3DT+ypVAE6UhXcLSemPYaHqrw puYiaNBzhuprH2jeWaA0g/xL32J9gaT2HfJPKwyGGgtCPmGQMGDW7AqbBYNlXIHIbSoV HFK/nxeg5nSSC9V3VwV8FXMRPSoycE0l5kr8WWOf+sW1r4lQ2BhElyROx80uirNd0Zm5 btKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YlBo0kZk8/xb90kgdTCjwFuYGgW4+Yg6DmE0UD6DHvk=; b=qgrvd5Tx1AZWsBFiXgbg1KQY2r+Q/kFJ9jDGZe9iD0U4fCO8j3BBG4Ijv1uSOcaKSK WL9VXAu7g/Hb6yAKQSOQX1Xim/sHn6DEmg49NIgqyNzck7xTlYm1vqVQG+UDbMbLsmSC X+htKjf2w42U2LjAbhJ4Y39xuLew2DREMGjjumer/1N5O/IGPhnwN+6EqasQKrSuiuF0 MeiCcpEUs/AF+Y/ccFMH2JAe2ywmnOQLnz9PNqYlUv+uSkt83wNdtbaZ7xw8iNaW60UL a5CfvtjzQcve2KU9HJiX87WFnMGXjQ6/QaVtm4I7lXCdESZA596vxSYphukU3ks95JGJ 9tFw== X-Gm-Message-State: AO0yUKXjic/Q0L0Q3bDVv9WzlI3jtwrhzOJyODXSLFCumcSchl+ZD+y3 pEsCK4PHTxeHPk8EN4xQVaUrm5dNti35wsHE X-Google-Smtp-Source: AK7set/8y502DxetLX+LkXnM+cXrunj4RXFSXB72ksApSM1rwUhnxhVc7SJslQCvhj6qwyERXLUo6w== X-Received: by 2002:a05:600c:35d6:b0:3dc:443e:3a8b with SMTP id r22-20020a05600c35d600b003dc443e3a8bmr14862613wmq.16.1675192854713; Tue, 31 Jan 2023 11:20:54 -0800 (PST) Received: from dave-Ubuntu2204.. (194.15.169.217.in-addr.arpa. [217.169.15.194]) by smtp.googlemail.com with ESMTPSA id x9-20020a05600c21c900b003dc434b39c7sm3527512wmj.0.2023.01.31.11.20.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 11:20:53 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org Cc: Dave Stevenson Subject: [PATCH 04/11] media: i2c: imx290: Fix the pixel rate at 148.5Mpix/s Date: Tue, 31 Jan 2023 19:20:09 +0000 Message-Id: <20230131192016.3476937-5-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230131192016.3476937-1-dave.stevenson@raspberrypi.com> References: <20230131192016.3476937-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The datasheet lists the link frequency changes between 1080p and 720p modes. This is correct that the link frequency changes as measured on an oscilloscope. Link frequency is not necessarily the same as pixel rate. The datasheet gives standard configurations for 1080p and 720p modes at a number of frame rates. Looking at the 1080p mode it gives: HMAX = 0x898 = 2200 VMAX = 0x465 = 1125 2200 * 1125 * 60fps = 148.5MPix/s Looking at the 720p mode it gives: HMAX = 0xce4 = 3300 VMAX = 0x2ee = 750 3300 * 750 * 60fps = 148.5Mpix/s This driver currently scales the pixel rate proportionally to the link frequency, however the above shows that this is not the correct thing to do, and currently all frame rate and exposure calculations give incorrect results. Correctly report the pixel rate as being 148.5MPix/s under any mode. Signed-off-by: Dave Stevenson --- drivers/media/i2c/imx290.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index 12946ca9d8d2..bd8729aed43c 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -107,6 +107,7 @@ #define IMX290_VMAX_DEFAULT 1125 +#define IMX290_PIXEL_RATE 148500000 /* * The IMX290 pixel array is organized as follows: * @@ -190,7 +191,6 @@ struct imx290 { struct v4l2_ctrl_handler ctrls; struct v4l2_ctrl *link_freq; - struct v4l2_ctrl *pixel_rate; struct v4l2_ctrl *hblank; struct v4l2_ctrl *vblank; }; @@ -649,15 +649,8 @@ static void imx290_ctrl_update(struct imx290 *imx290, { unsigned int hblank = mode->hmax - mode->width; unsigned int vblank = IMX290_VMAX_DEFAULT - mode->height; - s64 link_freq = imx290_link_freqs_ptr(imx290)[mode->link_freq_index]; - u64 pixel_rate; - - /* pixel rate = link_freq * 2 * nr_of_lanes / bits_per_sample */ - pixel_rate = link_freq * 2 * imx290->nlanes; - do_div(pixel_rate, imx290_format_info(format->code)->bpp); __v4l2_ctrl_s_ctrl(imx290->link_freq, mode->link_freq_index); - __v4l2_ctrl_s_ctrl_int64(imx290->pixel_rate, pixel_rate); __v4l2_ctrl_modify_range(imx290->hblank, hblank, hblank, 1, hblank); __v4l2_ctrl_modify_range(imx290->vblank, vblank, vblank, 1, vblank); @@ -707,9 +700,9 @@ static int imx290_ctrl_init(struct imx290 *imx290) if (imx290->link_freq) imx290->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; - imx290->pixel_rate = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, - V4L2_CID_PIXEL_RATE, - 1, INT_MAX, 1, 1); + v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, V4L2_CID_PIXEL_RATE, + IMX290_PIXEL_RATE, IMX290_PIXEL_RATE, 1, + IMX290_PIXEL_RATE); v4l2_ctrl_new_std_menu_items(&imx290->ctrls, &imx290_ctrl_ops, V4L2_CID_TEST_PATTERN, From patchwork Tue Jan 31 19:20:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 649077 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 4C5B5C38142 for ; Tue, 31 Jan 2023 19:21:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231300AbjAaTVQ (ORCPT ); Tue, 31 Jan 2023 14:21:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231444AbjAaTVD (ORCPT ); Tue, 31 Jan 2023 14:21:03 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C566C599B7 for ; Tue, 31 Jan 2023 11:20:57 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id o36so5088891wms.1 for ; Tue, 31 Jan 2023 11:20:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eG4gjnujP2JmOKKu7SEk7EkBV7JyvS8Ps6UkgPfOjtQ=; b=IC9CprXpxGPpui3XdU/D8moKfztaS+te74bCJ0jj/zxDGAq4AfFqwamj6TBk47gNkV pgnNyke/ZygCSwvG/xudS9RCpFDksSOPXdNmeYLXtcvvtP1+YDrg4GjMuW/xl46PFUKa 9JLZDaWzkfB0IP2qOYztdQIWUNVaK6D8oFgpSNGUzdhw5hqvV/X+2cxzsW8SPzzlDQY/ yZWR+/0ikUhVDdmrJeldmQBbUWOihryLACx1i4XPev8FfNhr/oS6jXUlolcacyJ3uQpd gC/c4MZBy1NFYwLfuj4nAyFohsXKxSGPOEXH+t75X6Iphdo6CmotoNzp7+CTre2biHkd tOJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eG4gjnujP2JmOKKu7SEk7EkBV7JyvS8Ps6UkgPfOjtQ=; b=uwnsAi+etGQJoHW0JhrfGeNPnLBFX4c75yvZlWANcPQHqI0+whTsyO9zl10jqHJWmX hcztvx2fLGKWlKG2ckdIH5WWRlRLasqnGX57VAObag7tejDipcq1m6ocJVmiqN/HxchG J7BhBvPPX79QZ5ZMW3GraAMlxORSWSxj9n7uOBJYN1Kdm77NItR9KHe2tUTctW8fN3yf irX0eZ+U6Mk2XL9jw6h44tnXAwxnkMg+q2TNDJqtJu7BO981JwTUAcxnxtEGRrHB4MWN /Gv0mySmP4xHDDMChpq1lojlHSsP39sXfNPaxJxv5A3hbCnJ8olmUp/eM4IBSSfanEy1 5rXw== X-Gm-Message-State: AFqh2kr9PVD30OYPenIHgsUMEHcQ1e1+73vMy09ethTGB7h921RAy9MG vosLiZhndFOraP7k5bnawGoK6Q== X-Google-Smtp-Source: AMrXdXvADqAZ2mjC/VnbRNVYN9z73CrZqkCaCx+p6iaU4Q4lIrvPhzKMcyU9roLselJc5CXnpJ/2Xw== X-Received: by 2002:a05:600c:4687:b0:3db:2e06:4091 with SMTP id p7-20020a05600c468700b003db2e064091mr46256047wmo.37.1675192856321; Tue, 31 Jan 2023 11:20:56 -0800 (PST) Received: from dave-Ubuntu2204.. (194.15.169.217.in-addr.arpa. [217.169.15.194]) by smtp.googlemail.com with ESMTPSA id x9-20020a05600c21c900b003dc434b39c7sm3527512wmj.0.2023.01.31.11.20.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 11:20:55 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org Cc: Dave Stevenson Subject: [PATCH 05/11] media: i2c: imx290: Support 60fps in 2 lane operation Date: Tue, 31 Jan 2023 19:20:10 +0000 Message-Id: <20230131192016.3476937-6-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230131192016.3476937-1-dave.stevenson@raspberrypi.com> References: <20230131192016.3476937-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Commit "97589ad61c73 media: i2c: imx290: Add support for 2 data lanes" added support for running in two lane mode (instead of 4), but without changing the link frequency that resulted in a max of 30fps. Commit "98e0500eadb7 media: i2c: imx290: Add configurable link frequency and pixel rate" then doubled the link frequency when in 2 lane mode, but didn't undo the correction for running at only 30fps, just extending horizontal blanking instead. Remove the 30fps limit on 2 lane by correcting the register config in accordance with the datasheet for 60fps operation over 2 lanes. Signed-off-by: Dave Stevenson Reviewed-by: Laurent Pinchart Reviewed-by: Alexander Stein --- drivers/media/i2c/imx290.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index bd8729aed43c..6bcfa535872f 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -366,7 +366,7 @@ static const struct imx290_mode imx290_modes_2lanes[] = { { .width = 1920, .height = 1080, - .hmax = 4400, + .hmax = 2200, .link_freq_index = FREQ_INDEX_1080P, .data = imx290_1080p_settings, .data_size = ARRAY_SIZE(imx290_1080p_settings), @@ -374,7 +374,7 @@ static const struct imx290_mode imx290_modes_2lanes[] = { { .width = 1280, .height = 720, - .hmax = 6600, + .hmax = 3300, .link_freq_index = FREQ_INDEX_720P, .data = imx290_720p_settings, .data_size = ARRAY_SIZE(imx290_720p_settings), @@ -518,21 +518,10 @@ static int imx290_set_register_array(struct imx290 *imx290, static int imx290_set_data_lanes(struct imx290 *imx290) { int ret = 0; - u32 frsel; - - switch (imx290->nlanes) { - case 2: - default: - frsel = 0x02; - break; - case 4: - frsel = 0x01; - break; - } imx290_write(imx290, IMX290_PHY_LANE_NUM, imx290->nlanes - 1, &ret); imx290_write(imx290, IMX290_CSI_LANE_MODE, imx290->nlanes - 1, &ret); - imx290_write(imx290, IMX290_FR_FDG_SEL, frsel, &ret); + imx290_write(imx290, IMX290_FR_FDG_SEL, 0x01, &ret); return ret; } From patchwork Tue Jan 31 19:20:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 649076 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 40475C636CD for ; Tue, 31 Jan 2023 19:21:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231264AbjAaTVV (ORCPT ); Tue, 31 Jan 2023 14:21:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229985AbjAaTVG (ORCPT ); Tue, 31 Jan 2023 14:21:06 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89A44599AF for ; Tue, 31 Jan 2023 11:20:58 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id q10so15219661wrm.4 for ; Tue, 31 Jan 2023 11:20:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=W5McuJ2hRZrWx+uYtLO8QBzTJ9fuESjuMdU73e0TzLA=; b=s6sgjx2jimyUaoKyGGZXhTNlC4TcrIfwNDF1wpvcBNLh1IaOYAAhsK7LXT45TB3R0D eyAk523tRxkVx3w00erIRhkjhUWGsa5RM56UzC1wfsy7OE9LsUgNRVFYd45gBPTd3b1S /LSBZpR0DotPJTNPQk+YTmzEmlN2qFy90/W3d439E4SG1W7yv4rpqBjhbGm6ntu+HWWZ KKnMA3d6+02Zqk65duVThhkCtDGsBPYaTJOKWoTsORO7iMKpHbWdIe5zRz4CbZJ5I88Q b7MVKxJabV28zZr637rrFvA+7Ib69QZwfIszLGq2lQ9EtjummTCbIboypRtfJPBehTPn AVGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W5McuJ2hRZrWx+uYtLO8QBzTJ9fuESjuMdU73e0TzLA=; b=AoPCJwSXqtM7gL9Bc1KU5MCj7f+F8ON3ImOew7Mt4HwrMs4prbVuInH5wj+zRoyCSi pMtiLxuoKWE/ys8oCh2yMOY0w/IzHuxSOqiFpqNWCyOKjSQTgniA7PtmnfhooWKJyyLJ IlI3cGIe+ouolMIFCB3nmG81piluDuh+oidlgyX3d/BPKRLNQE6UUe+Knc831cKO5XYA aDe0z1I6Eub26f6zB5XZiqYCwFrjx0FKHWDzyHnOmieYMpCez3oDfAn3sleHPOlgo9v3 b8QCoYpTo2h2Lmnwd3zW2Hx2kSgdI1WheqxzGTj2ln6P59mbAKNFiEkQRP/sga7+Lv69 RtLw== X-Gm-Message-State: AO0yUKUpP1iHb91RBhydRkZKPRVXbg89i4d3VOF40WgmYuyCxaJK1la3 p8Gjnksqbd7oqdC8T+3Rz7lQ86n1jOP5BFWS X-Google-Smtp-Source: AK7set/JPjn9n9VoNB2/5M4o5xd5uwP8v8rDeJDJvAFuOglgmYRV1aGJXAaZNaQv9qJKRIMAcWawCA== X-Received: by 2002:adf:c754:0:b0:2ba:dce5:ee28 with SMTP id b20-20020adfc754000000b002badce5ee28mr164864wrh.18.1675192858175; Tue, 31 Jan 2023 11:20:58 -0800 (PST) Received: from dave-Ubuntu2204.. (194.15.169.217.in-addr.arpa. [217.169.15.194]) by smtp.googlemail.com with ESMTPSA id x9-20020a05600c21c900b003dc434b39c7sm3527512wmj.0.2023.01.31.11.20.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 11:20:57 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org Cc: Dave Stevenson Subject: [PATCH 06/11] media: i2c: imx290: Use CSI timings as per datasheet Date: Tue, 31 Jan 2023 19:20:11 +0000 Message-Id: <20230131192016.3476937-7-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230131192016.3476937-1-dave.stevenson@raspberrypi.com> References: <20230131192016.3476937-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Commit "98e0500eadb7 media: i2c: imx290: Add configurable link frequency and pixel rate" added support for the increased link frequencies on 2 data lanes, but didn't update the CSI timing registers in accordance with the datasheet. Use the specified settings. Signed-off-by: Dave Stevenson Reviewed-by: Laurent Pinchart --- drivers/media/i2c/imx290.c | 126 +++++++++++++++++++++++++++++++------ 1 file changed, 106 insertions(+), 20 deletions(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index 6bcfa535872f..9ddd6382b127 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -174,6 +174,18 @@ struct imx290_mode { u32 data_size; }; +struct imx290_csi_cfg { + u16 repitition; + u16 tclkpost; + u16 thszero; + u16 thsprepare; + u16 tclktrail; + u16 thstrail; + u16 tclkzero; + u16 tclkprepare; + u16 tlpx; +}; + struct imx290 { struct device *dev; struct clk *xclk; @@ -273,16 +285,6 @@ static const struct imx290_regval imx290_1080p_settings[] = { { IMX290_INCKSEL4, 0x01 }, { IMX290_INCKSEL5, 0x1a }, { IMX290_INCKSEL6, 0x1a }, - /* data rate settings */ - { IMX290_REPETITION, 0x10 }, - { IMX290_TCLKPOST, 87 }, - { IMX290_THSZERO, 55 }, - { IMX290_THSPREPARE, 31 }, - { IMX290_TCLKTRAIL, 31 }, - { IMX290_THSTRAIL, 31 }, - { IMX290_TCLKZERO, 119 }, - { IMX290_TCLKPREPARE, 31 }, - { IMX290_TLPX, 23 }, }; static const struct imx290_regval imx290_720p_settings[] = { @@ -298,16 +300,6 @@ static const struct imx290_regval imx290_720p_settings[] = { { IMX290_INCKSEL4, 0x01 }, { IMX290_INCKSEL5, 0x1a }, { IMX290_INCKSEL6, 0x1a }, - /* data rate settings */ - { IMX290_REPETITION, 0x10 }, - { IMX290_TCLKPOST, 79 }, - { IMX290_THSZERO, 47 }, - { IMX290_THSPREPARE, 23 }, - { IMX290_TCLKTRAIL, 23 }, - { IMX290_THSTRAIL, 23 }, - { IMX290_TCLKZERO, 87 }, - { IMX290_TCLKPREPARE, 23 }, - { IMX290_TLPX, 23 }, }; static const struct imx290_regval imx290_10bit_settings[] = { @@ -328,6 +320,58 @@ static const struct imx290_regval imx290_12bit_settings[] = { { IMX290_CSI_DT_FMT, IMX290_CSI_DT_FMT_RAW12 }, }; +static const struct imx290_csi_cfg imx290_csi_222_75mhz = { + /* 222.25MHz or 445.5Mbit/s per lane */ + .repitition = 0x10, + .tclkpost = 87, + .thszero = 55, + .thsprepare = 31, + .tclktrail = 31, + .thstrail = 31, + .tclkzero = 119, + .tclkprepare = 31, + .tlpx = 23, +}; + +static const struct imx290_csi_cfg imx290_csi_445_5mhz = { + /* 445.5MHz or 891Mbit/s per lane */ + .repitition = 0x00, + .tclkpost = 119, + .thszero = 103, + .thsprepare = 71, + .tclktrail = 55, + .thstrail = 63, + .tclkzero = 255, + .tclkprepare = 63, + .tlpx = 55, +}; + +static const struct imx290_csi_cfg imx290_csi_148_5mhz = { + /* 148.5MHz or 297Mbit/s per lane */ + .repitition = 0x10, + .tclkpost = 79, + .thszero = 47, + .thsprepare = 23, + .tclktrail = 23, + .thstrail = 23, + .tclkzero = 87, + .tclkprepare = 23, + .tlpx = 23, +}; + +static const struct imx290_csi_cfg imx290_csi_297mhz = { + /* 297MHz or 594Mbit/s per lane */ + .repitition = 0x00, + .tclkpost = 103, + .thszero = 87, + .thsprepare = 47, + .tclktrail = 39, + .thstrail = 47, + .tclkzero = 191, + .tclkprepare = 47, + .tlpx = 39, +}; + /* supported link frequencies */ #define FREQ_INDEX_1080P 0 #define FREQ_INDEX_720P 1 @@ -536,6 +580,42 @@ static int imx290_set_black_level(struct imx290 *imx290, black_level >> (16 - bpp), err); } +static int imx290_set_csi_config(struct imx290 *imx290) +{ + const s64 *link_freqs = imx290_link_freqs_ptr(imx290); + const struct imx290_csi_cfg *csi_cfg; + int ret = 0; + + switch (link_freqs[imx290->current_mode->link_freq_index]) { + case 445500000: + csi_cfg = &imx290_csi_445_5mhz; + break; + case 297000000: + csi_cfg = &imx290_csi_297mhz; + break; + case 222750000: + csi_cfg = &imx290_csi_222_75mhz; + break; + case 148500000: + csi_cfg = &imx290_csi_148_5mhz; + break; + default: + return -EINVAL; + } + + imx290_write(imx290, IMX290_REPETITION, csi_cfg->repitition, &ret); + imx290_write(imx290, IMX290_TCLKPOST, csi_cfg->tclkpost, &ret); + imx290_write(imx290, IMX290_THSZERO, csi_cfg->thszero, &ret); + imx290_write(imx290, IMX290_THSPREPARE, csi_cfg->thsprepare, &ret); + imx290_write(imx290, IMX290_TCLKTRAIL, csi_cfg->tclktrail, &ret); + imx290_write(imx290, IMX290_THSTRAIL, csi_cfg->thstrail, &ret); + imx290_write(imx290, IMX290_TCLKZERO, csi_cfg->tclkzero, &ret); + imx290_write(imx290, IMX290_TCLKPREPARE, csi_cfg->tclkprepare, &ret); + imx290_write(imx290, IMX290_TLPX, csi_cfg->tlpx, &ret); + + return ret; +} + static int imx290_setup_format(struct imx290 *imx290, const struct v4l2_mbus_framefmt *format) { @@ -748,6 +828,12 @@ static int imx290_start_streaming(struct imx290 *imx290, return ret; } + ret = imx290_set_csi_config(imx290); + if (ret < 0) { + dev_err(imx290->dev, "Could not set csi cfg\n"); + return ret; + } + /* Apply the register values related to current frame format */ format = v4l2_subdev_get_pad_format(&imx290->sd, state, 0); ret = imx290_setup_format(imx290, format); From patchwork Tue Jan 31 19:20:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 650783 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 437ACC38142 for ; Tue, 31 Jan 2023 19:21:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231454AbjAaTVU (ORCPT ); Tue, 31 Jan 2023 14:21:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230519AbjAaTVK (ORCPT ); Tue, 31 Jan 2023 14:21:10 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E4D459E59 for ; Tue, 31 Jan 2023 11:21:01 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id j29-20020a05600c1c1d00b003dc52fed235so5888021wms.1 for ; Tue, 31 Jan 2023 11:21:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WH2m6BhNR1uDXlk7bsxUU9DHWcuEsawDHjnKOH5ul0Q=; b=pzyU8Gc+Cr1YndkNKnbwJBp7PInVg9cNURZvI+svHboxz6aOAUih7YT1xIQlCnWIYJ 9HJg5347CqK787gl8UjVrjh4hTFgMXYw95nE1wO36eF05pYoxCHKPaTIxN8bfJiqKJm5 9F/Ejbg4Q5GbcCrx73vqXr2hDY/K9ELH0j9cveb8F19qfOAkXbwNv7UNmVosLuhMmo6U 3fjjssQv2JwaoL0FJevzQ8WW2IrXy1+YUU6pIdV9K6p5TXwpEtaObogqTh23AF53kqEc 94hILru1e+RaZDPxmWMo1clo0XWnXlWPQ5ib/L5li8AkTsBHhvM6UiePeK3Vtw4p6Xlx yx6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WH2m6BhNR1uDXlk7bsxUU9DHWcuEsawDHjnKOH5ul0Q=; b=YfHjzdj84Gzlfyx3tnm12NNYiaDoKEIRue66OBs84K59ccrxhwevDiaVqzaxWON1CF Xv0sl8yJSaASKtsx032U+oG0//3+WP9Nr8AVfKcVl0bd4vVbskwExZBKgsWnch3Nn0OT l6lXUxvtFkSNcXpmoHgA9wR1J1/ygM6yT+Gp/4TJ3Xx39qOcaLJjntz9Dxf8pNUSROVE gvnXuEixyx2vAI2cFF7IEhgRbS3rcpQERcSwXhkTB3f2R3XuOY2gdakRn7y7jqP/NJxO DFjy3ZadqETsQzm6rOwwIGsKoJqP6soGE1mH4u5ZAEdR+beDt8g93TV6q/uUdvQy9fy0 Z7cA== X-Gm-Message-State: AO0yUKViDFBupH9DLS/PZrjMPqAJwjKrHeJk07gNpgX5rP0EqyloFaeN tLo2CQbB88PcT5X6oV2thdbogsZ6AZ8IhZJF X-Google-Smtp-Source: AK7set9q5zpQFp5aZC9veoh9czoaoB24cRbCPPmlXpJGCnH8ur6+I4XwGFTbHLY0TSmLDaHLnh7rXA== X-Received: by 2002:a05:600c:705:b0:3cf:85f7:bbc4 with SMTP id i5-20020a05600c070500b003cf85f7bbc4mr720561wmn.2.1675192859715; Tue, 31 Jan 2023 11:20:59 -0800 (PST) Received: from dave-Ubuntu2204.. (194.15.169.217.in-addr.arpa. [217.169.15.194]) by smtp.googlemail.com with ESMTPSA id x9-20020a05600c21c900b003dc434b39c7sm3527512wmj.0.2023.01.31.11.20.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 11:20:58 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org Cc: Dave Stevenson Subject: [PATCH 07/11] media: i2c: imx290: Convert V4L2_CID_HBLANK to read/write Date: Tue, 31 Jan 2023 19:20:12 +0000 Message-Id: <20230131192016.3476937-8-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230131192016.3476937-1-dave.stevenson@raspberrypi.com> References: <20230131192016.3476937-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The driver exposed V4L2_CID_HBLANK as a read only control to allow for exposure calculations and determination of the frame rate. Convert to a read/write control so that the frame rate can be controlled. Signed-off-by: Dave Stevenson --- drivers/media/i2c/imx290.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index 9ddd6382b127..9006be6e5e7c 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -47,6 +47,7 @@ #define IMX290_GAIN IMX290_REG_8BIT(0x3014) #define IMX290_VMAX IMX290_REG_24BIT(0x3018) #define IMX290_HMAX IMX290_REG_16BIT(0x301c) +#define IMX290_HMAX_MAX 0xffff #define IMX290_SHS1 IMX290_REG_24BIT(0x3020) #define IMX290_WINWV_OB IMX290_REG_8BIT(0x303a) #define IMX290_WINPV IMX290_REG_16BIT(0x303c) @@ -167,7 +168,7 @@ struct imx290_regval { struct imx290_mode { u32 width; u32 height; - u32 hmax; + u32 hmax_min; u8 link_freq_index; const struct imx290_regval *data; @@ -410,7 +411,7 @@ static const struct imx290_mode imx290_modes_2lanes[] = { { .width = 1920, .height = 1080, - .hmax = 2200, + .hmax_min = 2200, .link_freq_index = FREQ_INDEX_1080P, .data = imx290_1080p_settings, .data_size = ARRAY_SIZE(imx290_1080p_settings), @@ -418,7 +419,7 @@ static const struct imx290_mode imx290_modes_2lanes[] = { { .width = 1280, .height = 720, - .hmax = 3300, + .hmax_min = 3300, .link_freq_index = FREQ_INDEX_720P, .data = imx290_720p_settings, .data_size = ARRAY_SIZE(imx290_720p_settings), @@ -429,7 +430,7 @@ static const struct imx290_mode imx290_modes_4lanes[] = { { .width = 1920, .height = 1080, - .hmax = 2200, + .hmax_min = 2200, .link_freq_index = FREQ_INDEX_1080P, .data = imx290_1080p_settings, .data_size = ARRAY_SIZE(imx290_1080p_settings), @@ -437,7 +438,7 @@ static const struct imx290_mode imx290_modes_4lanes[] = { { .width = 1280, .height = 720, - .hmax = 3300, + .hmax_min = 3300, .link_freq_index = FREQ_INDEX_720P, .data = imx290_720p_settings, .data_size = ARRAY_SIZE(imx290_720p_settings), @@ -686,6 +687,12 @@ static int imx290_set_ctrl(struct v4l2_ctrl *ctrl) } break; + case V4L2_CID_HBLANK: + ret = imx290_write(imx290, IMX290_HMAX, + ctrl->val + imx290->current_mode->width, + NULL); + break; + default: ret = -EINVAL; break; @@ -716,12 +723,14 @@ static void imx290_ctrl_update(struct imx290 *imx290, const struct v4l2_mbus_framefmt *format, const struct imx290_mode *mode) { - unsigned int hblank = mode->hmax - mode->width; + unsigned int hblank_min = mode->hmax_min - mode->width; + unsigned int hblank_max = IMX290_HMAX_MAX - mode->width; unsigned int vblank = IMX290_VMAX_DEFAULT - mode->height; __v4l2_ctrl_s_ctrl(imx290->link_freq, mode->link_freq_index); - __v4l2_ctrl_modify_range(imx290->hblank, hblank, hblank, 1, hblank); + __v4l2_ctrl_modify_range(imx290->hblank, hblank_min, hblank_max, 1, + hblank_min); __v4l2_ctrl_modify_range(imx290->vblank, vblank, vblank, 1, vblank); } @@ -778,10 +787,11 @@ static int imx290_ctrl_init(struct imx290 *imx290) ARRAY_SIZE(imx290_test_pattern_menu) - 1, 0, 0, imx290_test_pattern_menu); + /* + * Actual range will be set from imx290_ctrl_update later in the probe. + */ imx290->hblank = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, V4L2_CID_HBLANK, 1, 1, 1, 1); - if (imx290->hblank) - imx290->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; imx290->vblank = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, V4L2_CID_VBLANK, 1, 1, 1, 1); @@ -850,11 +860,6 @@ static int imx290_start_streaming(struct imx290 *imx290, return ret; } - ret = imx290_write(imx290, IMX290_HMAX, imx290->current_mode->hmax, - NULL); - if (ret) - return ret; - /* Apply customized values from user */ ret = __v4l2_ctrl_handler_setup(imx290->sd.ctrl_handler); if (ret) { From patchwork Tue Jan 31 19:20:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 649075 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 0F737C636D4 for ; Tue, 31 Jan 2023 19:21:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231180AbjAaTVW (ORCPT ); Tue, 31 Jan 2023 14:21:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231671AbjAaTVK (ORCPT ); Tue, 31 Jan 2023 14:21:10 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE70C59B6B for ; Tue, 31 Jan 2023 11:21:01 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id bg13-20020a05600c3c8d00b003d9712b29d2so13257480wmb.2 for ; Tue, 31 Jan 2023 11:21:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PjJEsG45mLeURzUgdM3mVE0Cbt3Vk1VNsiHoyn2V0po=; b=LhiHpu/Xxe2cXMWELkR0k8wPd4/a1iJMw5Lo5G4WXskT6rP0AjdGaBGHuPdu5f5NhZ w4sNr6IwTApF1nNeCkfQKv/dlMWPENrjnEDDZu4u3JwDMq5QX6wCm4ri32IPCEZYTP9S 3u6RaLrvXmJHnsZzAIEyAs+G6TvyfREnBg3iA1cNijxWwpfn26FY0L8cmawkptqGAeAV m+ODfv9jEPVNCgJIvQH0Xl79nFqMypp0vAZ27OBjjkWnCWNs5At+LzmPqAnpEn01MTBN ITkLjTB8pK1Sfa2qfzFkxWE8NCaI/s+89jFM1WRjaolQdafBrOuMfSBRMqdltAGQeFze t4WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PjJEsG45mLeURzUgdM3mVE0Cbt3Vk1VNsiHoyn2V0po=; b=HsqF9kpJv+80aFH9h1ZduvCWO9RycIffI/vDC0bgZuOGUSjdUGLr98afTWNvdeJOFT 6Yf5x2LDaGoPttcysUzPN/HJoh5+Q6r702jiYvuyEU8VaPQJ9SnzU5RbqOZMYMlf1ux2 +U4vaikc7WAhImOioQTK6rCeEzsNzfI7R7X4+yOBliClFCJ+Nx0arAesWhPju/AwFw/C Ss3EGUIs/d3yQyc/b096IgUGluvDhAepPjkGW1vg3wBg5LpcuXc5Z0JS1GfojOD0nc9i OA1VUQpNMdFDtNCiCCRHa6x38pRw+rTOomOuzeeeknkXjIbvQDKpSopB9ZoobVLawE8P lPDA== X-Gm-Message-State: AFqh2krDKvNmySZsEg3oTtGPSy97GmzinsnsTkLSUPkg52Tqp4t67qK4 8LD1qH4oNCtXN3cE4HNM7Yu8Kc01be7Lkmm7 X-Google-Smtp-Source: AMrXdXvrisYkELLUBE+tC5UKwZz6TOE/OH86R8JVDdxGgbVmknQ0jNYoRrd1kozq+QFBqxKohAREtQ== X-Received: by 2002:a05:600c:35c1:b0:3db:1424:e781 with SMTP id r1-20020a05600c35c100b003db1424e781mr49509908wmq.23.1675192861270; Tue, 31 Jan 2023 11:21:01 -0800 (PST) Received: from dave-Ubuntu2204.. (194.15.169.217.in-addr.arpa. [217.169.15.194]) by smtp.googlemail.com with ESMTPSA id x9-20020a05600c21c900b003dc434b39c7sm3527512wmj.0.2023.01.31.11.20.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 11:21:00 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org Cc: Dave Stevenson Subject: [PATCH 08/11] media: i2c: imx290: Convert V4L2_CID_VBLANK to read/write Date: Tue, 31 Jan 2023 19:20:13 +0000 Message-Id: <20230131192016.3476937-9-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230131192016.3476937-1-dave.stevenson@raspberrypi.com> References: <20230131192016.3476937-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The driver exposed V4L2_CID_HBLANK as a read only control to allow for exposure calculations and determination of the frame rate. Convert to a read/write control so that the frame rate can be controlled. V4L2_CID_VBLANK also sets the limits for the exposure control, therefore exposure ranges have to be updated when vblank changes. This also updates the default VMAX in 720p mode from 1125 to 750 to achieve 60fps and follow the datasheet. Signed-off-by: Dave Stevenson Reviewed-by: Laurent Pinchart --- drivers/media/i2c/imx290.c | 57 ++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index 9006be6e5e7c..3413d83369ba 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -46,6 +46,7 @@ #define IMX290_BLKLEVEL IMX290_REG_16BIT(0x300a) #define IMX290_GAIN IMX290_REG_8BIT(0x3014) #define IMX290_VMAX IMX290_REG_24BIT(0x3018) +#define IMX290_VMAX_MAX 0x3ffff #define IMX290_HMAX IMX290_REG_16BIT(0x301c) #define IMX290_HMAX_MAX 0xffff #define IMX290_SHS1 IMX290_REG_24BIT(0x3020) @@ -106,8 +107,6 @@ #define IMX290_PGCTRL_THRU BIT(1) #define IMX290_PGCTRL_MODE(n) ((n) << 4) -#define IMX290_VMAX_DEFAULT 1125 - #define IMX290_PIXEL_RATE 148500000 /* * The IMX290 pixel array is organized as follows: @@ -169,6 +168,7 @@ struct imx290_mode { u32 width; u32 height; u32 hmax_min; + u32 vmax_min; u8 link_freq_index; const struct imx290_regval *data; @@ -206,6 +206,7 @@ struct imx290 { struct v4l2_ctrl *link_freq; struct v4l2_ctrl *hblank; struct v4l2_ctrl *vblank; + struct v4l2_ctrl *exposure; }; static inline struct imx290 *to_imx290(struct v4l2_subdev *_sd) @@ -219,7 +220,6 @@ static inline struct imx290 *to_imx290(struct v4l2_subdev *_sd) static const struct imx290_regval imx290_global_init_settings[] = { { IMX290_CTRL_07, IMX290_WINMODE_1080P }, - { IMX290_VMAX, IMX290_VMAX_DEFAULT }, { IMX290_EXTCK_FREQ, 0x2520 }, { IMX290_WINWV_OB, 12 }, { IMX290_WINPH, 0 }, @@ -412,6 +412,7 @@ static const struct imx290_mode imx290_modes_2lanes[] = { .width = 1920, .height = 1080, .hmax_min = 2200, + .vmax_min = 1125, .link_freq_index = FREQ_INDEX_1080P, .data = imx290_1080p_settings, .data_size = ARRAY_SIZE(imx290_1080p_settings), @@ -420,6 +421,7 @@ static const struct imx290_mode imx290_modes_2lanes[] = { .width = 1280, .height = 720, .hmax_min = 3300, + .vmax_min = 750, .link_freq_index = FREQ_INDEX_720P, .data = imx290_720p_settings, .data_size = ARRAY_SIZE(imx290_720p_settings), @@ -431,6 +433,7 @@ static const struct imx290_mode imx290_modes_4lanes[] = { .width = 1920, .height = 1080, .hmax_min = 2200, + .vmax_min = 1125, .link_freq_index = FREQ_INDEX_1080P, .data = imx290_1080p_settings, .data_size = ARRAY_SIZE(imx290_1080p_settings), @@ -439,6 +442,7 @@ static const struct imx290_mode imx290_modes_4lanes[] = { .width = 1280, .height = 720, .hmax_min = 3300, + .vmax_min = 750, .link_freq_index = FREQ_INDEX_720P, .data = imx290_720p_settings, .data_size = ARRAY_SIZE(imx290_720p_settings), @@ -645,7 +649,7 @@ static int imx290_set_ctrl(struct v4l2_ctrl *ctrl) struct imx290, ctrls); const struct v4l2_mbus_framefmt *format; struct v4l2_subdev_state *state; - int ret = 0; + int ret = 0, vmax; /* * Return immediately for controls that don't need to be applied to the @@ -654,6 +658,18 @@ static int imx290_set_ctrl(struct v4l2_ctrl *ctrl) if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) return 0; + if (ctrl->id == V4L2_CID_VBLANK) { + u32 vmax = ctrl->val + imx290->current_mode->height; + + /* + * Changing vblank changes the allowed range for exposure. + * We don't supply the current exposure as default here as it + * may lie outside the new range. We will reset it just below. + */ + __v4l2_ctrl_modify_range(imx290->exposure, + 1, vmax - 2, 1, vmax - 2); + } + /* V4L2 controls values will be applied only when power is already up */ if (!pm_runtime_get_if_in_use(imx290->dev)) return 0; @@ -666,9 +682,23 @@ static int imx290_set_ctrl(struct v4l2_ctrl *ctrl) ret = imx290_write(imx290, IMX290_GAIN, ctrl->val, NULL); break; + case V4L2_CID_VBLANK: + ret = imx290_write(imx290, IMX290_VMAX, + ctrl->val + imx290->current_mode->height, + NULL); + /* + * Due to the way that exposure is programmed in this sensor in + * relation to VMAX, we have to reprogramme it whenever VMAX is + * changed. + * Update ctrl so that the V4L2_CID_EXPOSURE case can refer to + * it. + */ + ctrl = imx290->exposure; + fallthrough; case V4L2_CID_EXPOSURE: + vmax = imx290->vblank->val + imx290->current_mode->height; ret = imx290_write(imx290, IMX290_SHS1, - IMX290_VMAX_DEFAULT - ctrl->val - 1, NULL); + vmax - ctrl->val - 1, NULL); break; case V4L2_CID_TEST_PATTERN: @@ -725,13 +755,15 @@ static void imx290_ctrl_update(struct imx290 *imx290, { unsigned int hblank_min = mode->hmax_min - mode->width; unsigned int hblank_max = IMX290_HMAX_MAX - mode->width; - unsigned int vblank = IMX290_VMAX_DEFAULT - mode->height; + unsigned int vblank_min = mode->vmax_min - mode->height; + unsigned int vblank_max = IMX290_VMAX_MAX - mode->height; __v4l2_ctrl_s_ctrl(imx290->link_freq, mode->link_freq_index); __v4l2_ctrl_modify_range(imx290->hblank, hblank_min, hblank_max, 1, hblank_min); - __v4l2_ctrl_modify_range(imx290->vblank, vblank, vblank, 1, vblank); + __v4l2_ctrl_modify_range(imx290->vblank, vblank_min, vblank_max, 1, + vblank_min); } static int imx290_ctrl_init(struct imx290 *imx290) @@ -761,9 +793,12 @@ static int imx290_ctrl_init(struct imx290 *imx290) v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, V4L2_CID_ANALOGUE_GAIN, 0, 100, 1, 0); - v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, - V4L2_CID_EXPOSURE, 1, IMX290_VMAX_DEFAULT - 2, 1, - IMX290_VMAX_DEFAULT - 2); + /* + * Correct range will be determined through imx290_ctrl_update setting + * V4L2_CID_VBLANK. + */ + imx290->exposure = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, + V4L2_CID_EXPOSURE, 1, 1, 1, 1); /* * Set the link frequency, pixel rate, horizontal blanking and vertical @@ -795,8 +830,6 @@ static int imx290_ctrl_init(struct imx290 *imx290) imx290->vblank = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, V4L2_CID_VBLANK, 1, 1, 1, 1); - if (imx290->vblank) - imx290->vblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; v4l2_ctrl_new_fwnode_properties(&imx290->ctrls, &imx290_ctrl_ops, &props); From patchwork Tue Jan 31 19:20:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 650782 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 B36E3C636CC for ; Tue, 31 Jan 2023 19:21:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231676AbjAaTVW (ORCPT ); Tue, 31 Jan 2023 14:21:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231142AbjAaTVM (ORCPT ); Tue, 31 Jan 2023 14:21:12 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18EFF59B4C for ; Tue, 31 Jan 2023 11:21:04 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id bg13-20020a05600c3c8d00b003d9712b29d2so13257517wmb.2 for ; Tue, 31 Jan 2023 11:21:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9iqMwjkZPhZJ3cGG7p2ATQbb1Iz8vPEA/Svjw84DMf8=; b=T0l7WtiHYwPy9jMqOnQzIz7GdDoXkLt1eZMkX8cxkp1OoefmCtMeHwzymfUF0FkfFx SKvdg/1xTvh69NCpC156rBZW/n5yS+PIm/KfIIJ7kozPqv6JOBGgYy4PpX1OrDy9xf7/ u8eYphYEvwa2mw0ypyb5yYjouiIcFUDRLm02O2oQzHcrejS6riAH0r+XJZ/5eO94irAj R2GXe0nNkikQBWSS86Tpc2Oyt7sYUHiC96eUOX54b9jv49fgIBC5BezWRwZf3sh0yTCY Mn7lsgmyrh4saOpC2+0j1ArT4ILP3kd1MuJOvfVg+w8+qzQote2yoNOEYB8emYTD500g b7HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9iqMwjkZPhZJ3cGG7p2ATQbb1Iz8vPEA/Svjw84DMf8=; b=zTscYsrzVcP6L/PzmIrsmzbqu+MPkqKvsXgF+38j/qjMtixa0tuap+KC9Ax0lEEJfi uedWU3dMWghPbnpvRa0qoREE87ah4EA8gAE51y1yY7C5h7Tv2otxG24l/jrsPVBfekOI PCm/boVyaaAqF1N3Pblv18JfOj3oI+mWodeh3wIV+HFU09w39VgTWObgTyuZD7N9H7UK uEzX3/xERNy0xBtVUjxarfp7Edt7Kz0fSJOHbxxCXymH36icHXe6B7mFslJfeQwbjZwo aIWC8RCQiODveiQk0+RlDXX/NVnMcflxEZhnQj8GZF04MkAnwwr2MGnCQZGdOFwfqzum shDQ== X-Gm-Message-State: AO0yUKUNalSiJnKJMStJpesBNVDiRhMMUueIR+1rG94SFspH/3a1ulKW f7yUqNKvxIsFIh8eDPhRXI1sLQ== X-Google-Smtp-Source: AK7set8Cg5DRumtVJEsvTwN8HIWFiGyugNdx8HFgOxfLP5KNV2a79LDC93so9I6tArlGohLuN7yZdA== X-Received: by 2002:a05:600c:2057:b0:3dd:1b3c:1ca2 with SMTP id p23-20020a05600c205700b003dd1b3c1ca2mr5882381wmg.22.1675192862669; Tue, 31 Jan 2023 11:21:02 -0800 (PST) Received: from dave-Ubuntu2204.. (194.15.169.217.in-addr.arpa. [217.169.15.194]) by smtp.googlemail.com with ESMTPSA id x9-20020a05600c21c900b003dc434b39c7sm3527512wmj.0.2023.01.31.11.21.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 11:21:02 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org Cc: Dave Stevenson Subject: [PATCH 09/11] media: i2c: imx290: Remove duplicated write to IMX290_CTRL_07 Date: Tue, 31 Jan 2023 19:20:14 +0000 Message-Id: <20230131192016.3476937-10-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230131192016.3476937-1-dave.stevenson@raspberrypi.com> References: <20230131192016.3476937-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org IMX290_CTRL_07 was written from both imx290_global_init_settings and imx290_1080p_settings and imx290_720p_settings. Remove it from imx290_global_init_settings as the setting varies based on the mode. Signed-off-by: Dave Stevenson --- drivers/media/i2c/imx290.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index 3413d83369ba..5202ef3cc3e6 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -219,7 +219,6 @@ static inline struct imx290 *to_imx290(struct v4l2_subdev *_sd) */ static const struct imx290_regval imx290_global_init_settings[] = { - { IMX290_CTRL_07, IMX290_WINMODE_1080P }, { IMX290_EXTCK_FREQ, 0x2520 }, { IMX290_WINWV_OB, 12 }, { IMX290_WINPH, 0 }, From patchwork Tue Jan 31 19:20:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 650781 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 980A5C38142 for ; Tue, 31 Jan 2023 19:21:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231297AbjAaTVX (ORCPT ); Tue, 31 Jan 2023 14:21:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231789AbjAaTVP (ORCPT ); Tue, 31 Jan 2023 14:21:15 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 979A8589A6 for ; Tue, 31 Jan 2023 11:21:05 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id o18so5740593wrj.3 for ; Tue, 31 Jan 2023 11:21:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LmLsXD5N2VDr1p+YGeciMrKRrG4q8uLP5itzXU5xuBQ=; b=D0nUoP7nGU/qfQRqaky69JGzpST8Q/zfsZsQcNWVc95sTyuB9RPYNkzjQPjX+sh+Bo 0aS8+6o1muPhhRAol2AGKT1JRlnJZyfMbnN+eXZnwHikTSCMzEQtVHJgtxPIrS6/9oTQ 9ODplCwG7Ig5K1+PxLW4kmqQD4eq/s2BUjPUQiTsWdQSRX1dofFEDie+4JRxRHxFHTx5 fA1IkYu94KPLJR8ZzkJ3tYTTX8uAErA0QJ23UvihoNfNEcnlTFZXkH9I/OfRizR88fYh vRFGkQBBLEfZBcVZHvioEpEijasMP9cMmgapgDC0pYgRu2cQWYR+W/TMec7KvWzmnUz/ oczw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LmLsXD5N2VDr1p+YGeciMrKRrG4q8uLP5itzXU5xuBQ=; b=iE2bNCJ94wBGY0yO51c+vBpIwnA8cEnSV7N/y/Orq2NQUX7YBQq47jSnCuAGpksj1q IUCEEZsKrhEdm6xSlirhSysNOr0MCA6nKywHC5XyEK4SCyR2a6xYICY1KimzXYrVwTeG K8vETRjt9bn/+ozb0ETl83/pvZ/+HLBf5nrJ/uOkZoM/Zz841/wPDDmHpOxn2YIvFyUh cwcrlBqD8IUa2jeaaGinc/y1v0/HAwnPJGT8prVbHM1vgVUY2K1M4aaS0i9bZ+JrAgEG 6rR6/bEL8dhyax+/imzIl7kC30kMWKwLQgAtWUt82ASwcS3LKtkyinoyKZW/s8WdvQMD o71Q== X-Gm-Message-State: AO0yUKWyzXOhLJ1bEkgkuql9ICKGQU9oRdQgbSo8WZ+fMWsteIKTZ1NJ EuFKFSj+/JuSR+qJT+upSmDxJA== X-Google-Smtp-Source: AK7set+uIJJ+7/+aeAvoU8mxo0eKFi9pqg2ptdHLMBtGKodzXMdWoXPKvxkGM0A2p3btjj48zYxBrw== X-Received: by 2002:a5d:634b:0:b0:2bf:b0ff:737b with SMTP id b11-20020a5d634b000000b002bfb0ff737bmr3537255wrw.36.1675192864141; Tue, 31 Jan 2023 11:21:04 -0800 (PST) Received: from dave-Ubuntu2204.. (194.15.169.217.in-addr.arpa. [217.169.15.194]) by smtp.googlemail.com with ESMTPSA id x9-20020a05600c21c900b003dc434b39c7sm3527512wmj.0.2023.01.31.11.21.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 11:21:03 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org Cc: Dave Stevenson Subject: [PATCH 10/11] media: i2c: imx290: Add support for 74.25MHz external clock Date: Tue, 31 Jan 2023 19:20:15 +0000 Message-Id: <20230131192016.3476937-11-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230131192016.3476937-1-dave.stevenson@raspberrypi.com> References: <20230131192016.3476937-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The sensor supports either a 37.125 or 74.25MHz external, but the driver only supported 37.125MHz. Add the relevant register configuration for either clock frequency option. Signed-off-by: Dave Stevenson --- drivers/media/i2c/imx290.c | 120 +++++++++++++++++++++++++++++++------ 1 file changed, 103 insertions(+), 17 deletions(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index 5202ef3cc3e6..7f6746f74040 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -102,6 +102,7 @@ #define IMX290_TCLKPREPARE IMX290_REG_16BIT(0x3452) #define IMX290_TLPX IMX290_REG_16BIT(0x3454) #define IMX290_X_OUT_SIZE IMX290_REG_16BIT(0x3472) +#define IMX290_INCKSEL7 IMX290_REG_8BIT(0x3480) #define IMX290_PGCTRL_REGEN BIT(0) #define IMX290_PGCTRL_THRU BIT(1) @@ -159,11 +160,27 @@ #define IMX290_NUM_SUPPLIES 3 +#define CLK_37_125 0 +#define CLK_74_25 1 +#define NUM_CLK 2 + struct imx290_regval { u32 reg; u32 val; }; +/* + * Clock configuration for registers INCKSEL1 to INCKSEL6. + */ +struct imx290_clk_cfg { + u8 incksel1; + u8 incksel2; + u8 incksel3; + u8 incksel4; + u8 incksel5; + u8 incksel6; +}; + struct imx290_mode { u32 width; u32 height; @@ -173,6 +190,8 @@ struct imx290_mode { const struct imx290_regval *data; u32 data_size; + + const struct imx290_clk_cfg *clk_cfg; }; struct imx290_csi_cfg { @@ -191,6 +210,7 @@ struct imx290 { struct device *dev; struct clk *xclk; struct regmap *regmap; + u32 xclk_freq; u8 nlanes; u8 mono; @@ -219,7 +239,6 @@ static inline struct imx290 *to_imx290(struct v4l2_subdev *_sd) */ static const struct imx290_regval imx290_global_init_settings[] = { - { IMX290_EXTCK_FREQ, 0x2520 }, { IMX290_WINWV_OB, 12 }, { IMX290_WINPH, 0 }, { IMX290_WINPV, 0 }, @@ -269,7 +288,16 @@ static const struct imx290_regval imx290_global_init_settings[] = { { IMX290_REG_8BIT(0x33b0), 0x50 }, { IMX290_REG_8BIT(0x33b2), 0x1a }, { IMX290_REG_8BIT(0x33b3), 0x04 }, - { IMX290_REG_8BIT(0x3480), 0x49 }, +}; + +static const struct imx290_regval imx290_37_125mhz_clock[] = { + { IMX290_EXTCK_FREQ, 0x2520 }, + { IMX290_INCKSEL7, 0x49 }, +}; + +static const struct imx290_regval imx290_74_25mhz_clock[] = { + { IMX290_EXTCK_FREQ, 0x4a40 }, + { IMX290_INCKSEL7, 0x92 }, }; static const struct imx290_regval imx290_1080p_settings[] = { @@ -279,12 +307,6 @@ static const struct imx290_regval imx290_1080p_settings[] = { { IMX290_OPB_SIZE_V, 10 }, { IMX290_X_OUT_SIZE, 1920 }, { IMX290_Y_OUT_SIZE, 1080 }, - { IMX290_INCKSEL1, 0x18 }, - { IMX290_INCKSEL2, 0x03 }, - { IMX290_INCKSEL3, 0x20 }, - { IMX290_INCKSEL4, 0x01 }, - { IMX290_INCKSEL5, 0x1a }, - { IMX290_INCKSEL6, 0x1a }, }; static const struct imx290_regval imx290_720p_settings[] = { @@ -294,12 +316,6 @@ static const struct imx290_regval imx290_720p_settings[] = { { IMX290_OPB_SIZE_V, 4 }, { IMX290_X_OUT_SIZE, 1280 }, { IMX290_Y_OUT_SIZE, 720 }, - { IMX290_INCKSEL1, 0x20 }, - { IMX290_INCKSEL2, 0x00 }, - { IMX290_INCKSEL3, 0x20 }, - { IMX290_INCKSEL4, 0x01 }, - { IMX290_INCKSEL5, 0x1a }, - { IMX290_INCKSEL6, 0x1a }, }; static const struct imx290_regval imx290_10bit_settings[] = { @@ -405,6 +421,48 @@ static inline int imx290_link_freqs_num(const struct imx290 *imx290) return ARRAY_SIZE(imx290_link_freq_4lanes); } +static const struct imx290_clk_cfg imx290_1080p_clock_config[NUM_CLK] = { + [CLK_37_125] = { + /* 37.125MHz clock config */ + .incksel1 = 0x18, + .incksel2 = 0x03, + .incksel3 = 0x20, + .incksel4 = 0x01, + .incksel5 = 0x1a, + .incksel6 = 0x1a, + }, + [CLK_74_25] = { + /* 74.25MHz clock config */ + .incksel1 = 0x0c, + .incksel2 = 0x03, + .incksel3 = 0x10, + .incksel4 = 0x01, + .incksel5 = 0x1b, + .incksel6 = 0x1b, + }, +}; + +static const struct imx290_clk_cfg imx290_720p_clock_config[NUM_CLK] = { + [CLK_37_125] = { + /* 37.125MHz clock config */ + .incksel1 = 0x20, + .incksel2 = 0x00, + .incksel3 = 0x20, + .incksel4 = 0x01, + .incksel5 = 0x1a, + .incksel6 = 0x1a, + }, + [CLK_74_25] = { + /* 74.25MHz clock config */ + .incksel1 = 0x10, + .incksel2 = 0x00, + .incksel3 = 0x10, + .incksel4 = 0x01, + .incksel5 = 0x1b, + .incksel6 = 0x1b, + }, +}; + /* Mode configs */ static const struct imx290_mode imx290_modes_2lanes[] = { { @@ -415,6 +473,7 @@ static const struct imx290_mode imx290_modes_2lanes[] = { .link_freq_index = FREQ_INDEX_1080P, .data = imx290_1080p_settings, .data_size = ARRAY_SIZE(imx290_1080p_settings), + .clk_cfg = imx290_1080p_clock_config, }, { .width = 1280, @@ -424,6 +483,7 @@ static const struct imx290_mode imx290_modes_2lanes[] = { .link_freq_index = FREQ_INDEX_720P, .data = imx290_720p_settings, .data_size = ARRAY_SIZE(imx290_720p_settings), + .clk_cfg = imx290_720p_clock_config, }, }; @@ -436,6 +496,7 @@ static const struct imx290_mode imx290_modes_4lanes[] = { .link_freq_index = FREQ_INDEX_1080P, .data = imx290_1080p_settings, .data_size = ARRAY_SIZE(imx290_1080p_settings), + .clk_cfg = imx290_1080p_clock_config, }, { .width = 1280, @@ -445,6 +506,7 @@ static const struct imx290_mode imx290_modes_4lanes[] = { .link_freq_index = FREQ_INDEX_720P, .data = imx290_720p_settings, .data_size = ARRAY_SIZE(imx290_720p_settings), + .clk_cfg = imx290_720p_clock_config, }, }; @@ -563,6 +625,23 @@ static int imx290_set_register_array(struct imx290 *imx290, return 0; } +static int imx290_set_clock(struct imx290 *imx290) +{ + int clk_idx = (imx290->xclk_freq == 37125000) ? 0 : 1; + const struct imx290_mode *mode = imx290->current_mode; + const struct imx290_clk_cfg *clk_cfg = &mode->clk_cfg[clk_idx]; + int ret = 0; + + imx290_write(imx290, IMX290_INCKSEL1, clk_cfg->incksel1, &ret); + imx290_write(imx290, IMX290_INCKSEL2, clk_cfg->incksel2, &ret); + imx290_write(imx290, IMX290_INCKSEL3, clk_cfg->incksel3, &ret); + imx290_write(imx290, IMX290_INCKSEL4, clk_cfg->incksel4, &ret); + imx290_write(imx290, IMX290_INCKSEL5, clk_cfg->incksel5, &ret); + imx290_write(imx290, IMX290_INCKSEL6, clk_cfg->incksel6, &ret); + + return ret; +} + static int imx290_set_data_lanes(struct imx290 *imx290) { int ret = 0; @@ -863,6 +942,13 @@ static int imx290_start_streaming(struct imx290 *imx290, return ret; } + /* Set clock parameters based on mode and xclk */ + ret = imx290_set_clock(imx290); + if (ret < 0) { + dev_err(imx290->dev, "Could not set clocks\n"); + return ret; + } + /* Set data lane count */ ret = imx290_set_data_lanes(imx290); if (ret < 0) { @@ -1259,14 +1345,14 @@ static int imx290_init_clk(struct imx290 *imx290) int ret; ret = fwnode_property_read_u32(dev_fwnode(imx290->dev), - "clock-frequency", &xclk_freq); + "clock-frequency", &imx290->xclk_freq); if (ret) { dev_err(imx290->dev, "Could not get xclk frequency\n"); return ret; } - /* external clock must be 37.125 MHz */ - if (xclk_freq != 37125000) { + /* external clock must be 37.125 MHz or 74.25MHz */ + if (imx290->xclk_freq != 37125000 && imx290->xclk_freq != 74250000) { dev_err(imx290->dev, "External clock frequency %u is not supported\n", xclk_freq); return -EINVAL; From patchwork Tue Jan 31 19:20:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 649074 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 8CC86C636D7 for ; Tue, 31 Jan 2023 19:21:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229680AbjAaTVY (ORCPT ); Tue, 31 Jan 2023 14:21:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229972AbjAaTVS (ORCPT ); Tue, 31 Jan 2023 14:21:18 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54DD859E44 for ; Tue, 31 Jan 2023 11:21:07 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id c10-20020a05600c0a4a00b003db0636ff84so11474497wmq.0 for ; Tue, 31 Jan 2023 11:21:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bXag4SScz1IWoq6CjWg2NhccWObAjwUcn/IapGcRwP8=; b=E0njOo/egkeNjKFlL4b6ek6ARSF8TKUj5qbzX+TdIMtXMcHWsODy8zOrEJ8/c567VK lDOxM/nFhcEFaVe+WKXrC1PRmE8GtOQNlc82osKtpA8B0N3G+7EQwySRru9tkEsIgYrS NLhqGt1cMw1RVk2Zwe4bJa/TLuCFIsIbigy02CnnUBD/cgosCWJsFTDqsYb+CZ+cM4Yt LPBWQHFmuVdCkLoR7GqVase3A7klqv11P+gCVMSgPCrz0Q47ca+RMkRw1IJgHu8oP60X vJZxWQLBUUAIJnjV+TvL5n5vfOi7/XbGdgkWEXT2ydsVo3ytsDvaEdsXDGbm4sRrIiJK 1jcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bXag4SScz1IWoq6CjWg2NhccWObAjwUcn/IapGcRwP8=; b=ZyFHds/MAPSk+BLTVuInUu5ol00g1MPmyBcGtVQ6vPrXKcuN1VLP+5OKeyAfpos96U BEKVT+RZkb2qH6qEocFu57o3wenU/dyTrEllxo2ndYAfReNU33C8UPWx8Vo1tzuWoCHJ pSolgQVzaDfAG6HRAxgf69Y6U2w9hOnVGUKgiQ5rMa8hMPHLe6+DprhwkhUcLXndi1/R Ylw1UVqtWckY0/4txU+DXTEtodldtjBfLRGRkvC1Y5GuFK9M4u4jFU1GckENRnpYiQ0b qPo7YAfS0INJflxnxKP7EENP+RjTYv6RqpCnihx+gKTV3bx16nng01HkjhZBASX3Y6DV +cuw== X-Gm-Message-State: AO0yUKV5czhgHrRPJ3Bfdj19rIchx3IU2PUIsZnpR7BYrDZtQN/rVxio oJMIQ8JSfkwO/3oGBHDYArwy5A== X-Google-Smtp-Source: AK7set+W34BOhdUBH/EuggPZEsldVXz2DrgK54z6obFviOZh8umUJdtdMP5UYgq1cs8UegFupeaP9g== X-Received: by 2002:a05:600c:3492:b0:3dc:5984:a16c with SMTP id a18-20020a05600c349200b003dc5984a16cmr8795936wmq.31.1675192865840; Tue, 31 Jan 2023 11:21:05 -0800 (PST) Received: from dave-Ubuntu2204.. (194.15.169.217.in-addr.arpa. [217.169.15.194]) by smtp.googlemail.com with ESMTPSA id x9-20020a05600c21c900b003dc434b39c7sm3527512wmj.0.2023.01.31.11.21.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 11:21:05 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org Cc: Dave Stevenson Subject: [PATCH 11/11] media: i2c: imx290: Add support for H & V Flips Date: Tue, 31 Jan 2023 19:20:16 +0000 Message-Id: <20230131192016.3476937-12-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230131192016.3476937-1-dave.stevenson@raspberrypi.com> References: <20230131192016.3476937-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The sensor supports H & V flips, so add the relevant hooks for V4L2_CID_HFLIP and V4L2_CID_VFLIP to configure them. Note that the Bayer order is maintained as the readout area shifts by 1 pixel in the appropriate direction (note the comment about the top margin being 8 pixels whilst the bottom margin is 9). The V4L2_SEL_TGT_CROP region is therefore adjusted appropriately. Signed-off-by: Dave Stevenson --- drivers/media/i2c/imx290.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index 7f6746f74040..d2b7534f2c51 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -227,6 +227,8 @@ struct imx290 { struct v4l2_ctrl *hblank; struct v4l2_ctrl *vblank; struct v4l2_ctrl *exposure; + struct v4l2_ctrl *hflip; + struct v4l2_ctrl *vflip; }; static inline struct imx290 *to_imx290(struct v4l2_subdev *_sd) @@ -801,6 +803,24 @@ static int imx290_set_ctrl(struct v4l2_ctrl *ctrl) NULL); break; + case V4L2_CID_HFLIP: + case V4L2_CID_VFLIP: + { + u32 reg; + + /* WINMODE is in bits [6:4], so need to read-modify-write */ + ret = imx290_read(imx290, IMX290_CTRL_07, ®); + if (ret) + break; + reg &= ~(IMX290_HREVERSE | IMX290_VREVERSE); + if (imx290->hflip->val) + reg |= IMX290_HREVERSE; + if (imx290->vflip->val) + reg |= IMX290_VREVERSE; + ret = imx290_write(imx290, IMX290_CTRL_07, reg, NULL); + break; + } + default: ret = -EINVAL; break; @@ -853,7 +873,7 @@ static int imx290_ctrl_init(struct imx290 *imx290) if (ret < 0) return ret; - v4l2_ctrl_handler_init(&imx290->ctrls, 9); + v4l2_ctrl_handler_init(&imx290->ctrls, 11); /* * The sensor has an analog gain and a digital gain, both controlled @@ -909,6 +929,11 @@ static int imx290_ctrl_init(struct imx290 *imx290) imx290->vblank = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, V4L2_CID_VBLANK, 1, 1, 1, 1); + imx290->hflip = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, + V4L2_CID_HFLIP, 0, 1, 1, 0); + imx290->vflip = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, + V4L2_CID_VFLIP, 0, 1, 1, 0); + v4l2_ctrl_new_fwnode_properties(&imx290->ctrls, &imx290_ctrl_ops, &props); @@ -1030,6 +1055,9 @@ static int imx290_set_stream(struct v4l2_subdev *sd, int enable) pm_runtime_put_autosuspend(imx290->dev); } + /* vflip and hflip cannot change during streaming */ + __v4l2_ctrl_grab(imx290->vflip, enable); + __v4l2_ctrl_grab(imx290->hflip, enable); unlock: v4l2_subdev_unlock_state(state); return ret; @@ -1115,6 +1143,7 @@ static int imx290_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_selection *sel) { + struct imx290 *imx290 = to_imx290(sd); struct v4l2_mbus_framefmt *format; switch (sel->target) { @@ -1122,9 +1151,11 @@ static int imx290_get_selection(struct v4l2_subdev *sd, format = v4l2_subdev_get_pad_format(sd, sd_state, 0); sel->r.top = IMX920_PIXEL_ARRAY_MARGIN_TOP - + (IMX290_PIXEL_ARRAY_RECORDING_HEIGHT - format->height) / 2; + + (IMX290_PIXEL_ARRAY_RECORDING_HEIGHT - format->height) / 2 + + imx290->vflip->val; sel->r.left = IMX920_PIXEL_ARRAY_MARGIN_LEFT - + (IMX290_PIXEL_ARRAY_RECORDING_WIDTH - format->width) / 2; + + (IMX290_PIXEL_ARRAY_RECORDING_WIDTH - format->width) / 2 + + imx290->hflip->val; sel->r.width = format->width; sel->r.height = format->height;