From patchwork Tue May 30 17:29:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 687045 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 63E61C77B7A for ; Tue, 30 May 2023 17:30:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233364AbjE3Raw (ORCPT ); Tue, 30 May 2023 13:30:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232651AbjE3Rau (ORCPT ); Tue, 30 May 2023 13:30:50 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6C43126 for ; Tue, 30 May 2023 10:30:36 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-30af159b433so1792127f8f.3 for ; Tue, 30 May 2023 10:30:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1685467835; x=1688059835; 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=R06QgnOIc6JgKZENg1I2OL1jwi9EcZ87JyuvJDeto3A=; b=tKP76imLLXQxdtAPEEPtgsdO21bq7Uds91Wzv55c7j6SJfO/so/hWcXV1qEkR9ugmD dP94pJ0TlxvXrsPahmIGXp6nmlpOBJdtrCjuEWkoh/eXzepGBZDjmVJRjQ5HBaxE5YCc AtkfX1vj8TSlXL6imQe9J09v0rDHPTzxt/FEecRhZ3SqcRJ+ph8y3la5VDm+h75m5Bfy hkDQcND9qWb8Yw/PvJktP45b1rVgGoY4UOu3op3FI7O8kCSzGx0SvBrSjlLcEI7WJWda qGR8KJyRlKZrTDvN+Uia8hlWvvwiXUAP84FDKk4y0h9Mk91/NmJYsmBu1sdY+6QJGk5f rUrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685467835; x=1688059835; 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=R06QgnOIc6JgKZENg1I2OL1jwi9EcZ87JyuvJDeto3A=; b=cEp7MepJ8NS9enVOeajvZg1l+3enUS3tJDvFT584GU1UzCqHU0fIhg1gx/7n7Euk4i rysTHjnIjZCWHO+j2I6SjkBDtLN3xXKOza5+acKh+lkMvmLK9Oho6u+/Kk84IZO3xglJ cS3j3Kk21VjmreSPNYfXuW9t2fcDEspAJDGm0hLvnV2D3jo0jPdGsFVzUp1qkPHfMNAa Dl7ZFhCQkjmLMhz58lutPHh3nwhc4Sc6ORiYM2z0mbUdIuSeusrrTI8Rul787S3iezGk irpsrxkX+6svIkouqOrcmCG+5XcEOAB4hzgpIYTyfeIY7vkIJ6fOJfy4aayct7oM3iki 0wzA== X-Gm-Message-State: AC+VfDzn7/SBMI7DwAsh1EsoPvw5QDp84DDUEUHxDcAkiSJRvFFqrusZ rJgge03FtxSX7LCMNSFGdWU40g== X-Google-Smtp-Source: ACHHUZ67Dhm4m4Vx7L3nMLJoFcwqPEG2bGGs7sMNRgY5Xw3DtQEr8fgODkkxHZKnXX4ZW/xbM7PVhw== X-Received: by 2002:adf:e591:0:b0:2f9:61b5:7796 with SMTP id l17-20020adfe591000000b002f961b57796mr2180627wrm.29.1685467835399; Tue, 30 May 2023 10:30:35 -0700 (PDT) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id h14-20020a056000000e00b0030ae901bc54sm3964823wrx.62.2023.05.30.10.30.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 10:30:34 -0700 (PDT) From: Dave Stevenson To: Sakari Ailus , linux-media@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org Cc: Dave Stevenson Subject: [PATCH 01/21] media: i2c: imx258: Remove unused defines Date: Tue, 30 May 2023 18:29:40 +0100 Message-Id: <20230530173000.3060865-2-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230530173000.3060865-1-dave.stevenson@raspberrypi.com> References: <20230530173000.3060865-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The IMX258_FLL_* defines are unused. Remove them. Signed-off-by: Dave Stevenson --- drivers/media/i2c/imx258.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index 85d73b186111..6028579393b5 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -29,12 +29,6 @@ #define IMX258_VTS_30FPS_VGA 0x034c #define IMX258_VTS_MAX 0xffff -/*Frame Length Line*/ -#define IMX258_FLL_MIN 0x08a6 -#define IMX258_FLL_MAX 0xffff -#define IMX258_FLL_STEP 1 -#define IMX258_FLL_DEFAULT 0x0c98 - /* HBLANK control - read only */ #define IMX258_PPL_DEFAULT 5352 From patchwork Tue May 30 17:29:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 687044 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 32A33C7EE23 for ; Tue, 30 May 2023 17:30:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233367AbjE3Ray (ORCPT ); Tue, 30 May 2023 13:30:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232372AbjE3Rax (ORCPT ); Tue, 30 May 2023 13:30:53 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4B7712B for ; Tue, 30 May 2023 10:30:37 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-30ac4e7f37bso3151967f8f.2 for ; Tue, 30 May 2023 10:30:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1685467836; x=1688059836; 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=pJY/Ey8RP2gZGhO8YHfuicP99D/efDE5/sepTgp3T+s=; b=oLGt38khPIrktP5C1Oz3mDt5pOyJlDFbTfyn9cpEjo68EoLJ8ixv2KV+ieWpVWx14g w+AgEhbqWiWjQT5uu+88qDVWyrZfTuGA82qgvVa38Xh9UU1prMB8VnjsgI5GRYhrPUNw OIQ0h6nRi+U7fmkWpd3fA+osIjI8CPhBD4P1iLuWsOmd4W7NfUKAs2srLlwWK7BfC3rd hCqEfPppivva6sxpjFLXo1KoaAjy+WMOUWLozGZSfii0ObK0dipkgwqRDoVAA+Qn8/vU oHdD/wX+WPn3Nv1Qf2qF4VKE59npx8uEOPgSgVHm4hM2WxYNEBcQucqfEATOIUMo/XEt 1Hqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685467836; x=1688059836; 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=pJY/Ey8RP2gZGhO8YHfuicP99D/efDE5/sepTgp3T+s=; b=NO+k+TVp7IxiiyRIMZgjeLG0ynya0zgq3DD0QHCvdxdKKvGgSPwVWjJIDIZNJMyOTN qLcIRVouuL3n50XqfeW5ikAI7s0YIqJEKoL5P2YEjba/ffFU/zbjNBpGrilj3jUbPVeu icSFio840dMlLf0MAWeasH+KtVFAzIiKAsdDlwM/vw7gE+sQgNP34/e0uhRE/fc/ssgQ Pduv6pOurpQC+7a4QI+8pMXfDEkMOe8Hf6fuCRLIGtwoRqdAEPTmLEB/JYWrn3ICflSS Oox7IT4egKhoQZnr1R9TrCixTNKEHHeTLkuHTRB6TkYY7kKTRw+toxfymwTd27yQdMHp +lnQ== X-Gm-Message-State: AC+VfDyrPeWAL1s88LI0FiMuzwjO9P+d8X26BnabpwX/yLMHJU6tEUtf AZoqN5UxvilZWjzWcH8VYhEv5w== X-Google-Smtp-Source: ACHHUZ5b1Ts+5DMzxAO4Zfo/nayI+BkE/tCNvJAhaHwXv6MgWqqCUyyVlhVLm0fohjq6MR2JavSwzg== X-Received: by 2002:adf:cd82:0:b0:2f4:4e1a:bea2 with SMTP id q2-20020adfcd82000000b002f44e1abea2mr1948308wrj.59.1685467836100; Tue, 30 May 2023 10:30:36 -0700 (PDT) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id h14-20020a056000000e00b0030ae901bc54sm3964823wrx.62.2023.05.30.10.30.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 10:30:35 -0700 (PDT) From: Dave Stevenson To: Sakari Ailus , linux-media@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org Cc: Dave Stevenson Subject: [PATCH 02/21] media: i2c: imx258: Make image geometry meet sensor requirements Date: Tue, 30 May 2023 18:29:41 +0100 Message-Id: <20230530173000.3060865-3-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230530173000.3060865-1-dave.stevenson@raspberrypi.com> References: <20230530173000.3060865-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The output image is defined as being 4208x3118 pixels in size. Y_ADD_STA register was set to 0, and Y_ADD_END to 3118, giving 3119 lines total. The datasheet lists a requirement for Y_ADD_STA to be a multiple of a power of 2 depending on binning/scaling mode (2 for full pixel, 4 for x2-bin/scale, 8 for (x2-bin)+(x2-subsample) or x4-bin, or 16 for (x4-bin)+(x2-subsample)). (Y_ADD_END – Y_ADD_STA + 1) also has to be a similar power of 2. The current configuration for the full res modes breaks that second requirement, and we can't increase Y_ADD_STA to 1 to retain exactly the same field of view as that then breaks the first requirement. For the binned modes, they are worse off as 3118 is not a multiple of 4. Increase the main mode to 4208x3120 so that it is the same FOV as the binned modes, with Y_ADD_STA at 0. Fix Y_ADD_STA and Y_ADD_END for the binned modes so that they meet the sensor requirements. This does change the Bayer order as the default configuration is for H&V flips to be enabled, so readout is from Y_STA_END to Y_ADD_STA, and this patch has changed Y_STA_END. Signed-off-by: Dave Stevenson Reviewed-by: Jacopo Mondi --- drivers/media/i2c/imx258.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index 6028579393b5..946b1a12971d 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -111,7 +111,7 @@ struct imx258_mode { struct imx258_reg_list reg_list; }; -/* 4208x3118 needs 1267Mbps/lane, 4 lanes */ +/* 4208x3120 needs 1267Mbps/lane, 4 lanes */ static const struct imx258_reg mipi_data_rate_1267mbps[] = { { 0x0301, 0x05 }, { 0x0303, 0x02 }, @@ -148,7 +148,7 @@ static const struct imx258_reg mipi_data_rate_640mbps[] = { { 0x0823, 0x00 }, }; -static const struct imx258_reg mode_4208x3118_regs[] = { +static const struct imx258_reg mode_4208x3120_regs[] = { { 0x0136, 0x13 }, { 0x0137, 0x33 }, { 0x3051, 0x00 }, @@ -210,7 +210,7 @@ static const struct imx258_reg mode_4208x3118_regs[] = { { 0x0348, 0x10 }, { 0x0349, 0x6F }, { 0x034A, 0x0C }, - { 0x034B, 0x2E }, + { 0x034B, 0x2F }, { 0x0381, 0x01 }, { 0x0383, 0x01 }, { 0x0385, 0x01 }, @@ -329,7 +329,7 @@ static const struct imx258_reg mode_2104_1560_regs[] = { { 0x0348, 0x10 }, { 0x0349, 0x6F }, { 0x034A, 0x0C }, - { 0x034B, 0x2E }, + { 0x034B, 0x2F }, { 0x0381, 0x01 }, { 0x0383, 0x01 }, { 0x0385, 0x01 }, @@ -448,7 +448,7 @@ static const struct imx258_reg mode_1048_780_regs[] = { { 0x0348, 0x10 }, { 0x0349, 0x6F }, { 0x034A, 0x0C }, - { 0x034B, 0x2E }, + { 0x034B, 0x2F }, { 0x0381, 0x01 }, { 0x0383, 0x01 }, { 0x0385, 0x01 }, @@ -562,12 +562,12 @@ static const struct imx258_link_freq_config link_freq_configs[] = { static const struct imx258_mode supported_modes[] = { { .width = 4208, - .height = 3118, + .height = 3120, .vts_def = IMX258_VTS_30FPS, .vts_min = IMX258_VTS_30FPS, .reg_list = { - .num_of_regs = ARRAY_SIZE(mode_4208x3118_regs), - .regs = mode_4208x3118_regs, + .num_of_regs = ARRAY_SIZE(mode_4208x3120_regs), + .regs = mode_4208x3120_regs, }, .link_freq_index = IMX258_LINK_FREQ_1267MBPS, }, @@ -710,7 +710,7 @@ static int imx258_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) /* Initialize try_fmt */ try_fmt->width = supported_modes[0].width; try_fmt->height = supported_modes[0].height; - try_fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10; + try_fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10; try_fmt->field = V4L2_FIELD_NONE; return 0; @@ -822,7 +822,7 @@ static int imx258_enum_mbus_code(struct v4l2_subdev *sd, if (code->index > 0) return -EINVAL; - code->code = MEDIA_BUS_FMT_SGRBG10_1X10; + code->code = MEDIA_BUS_FMT_SBGGR10_1X10; return 0; } @@ -834,7 +834,7 @@ static int imx258_enum_frame_size(struct v4l2_subdev *sd, if (fse->index >= ARRAY_SIZE(supported_modes)) return -EINVAL; - if (fse->code != MEDIA_BUS_FMT_SGRBG10_1X10) + if (fse->code != MEDIA_BUS_FMT_SBGGR10_1X10) return -EINVAL; fse->min_width = supported_modes[fse->index].width; @@ -850,7 +850,7 @@ static void imx258_update_pad_format(const struct imx258_mode *mode, { fmt->format.width = mode->width; fmt->format.height = mode->height; - fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10; + fmt->format.code = MEDIA_BUS_FMT_SBGGR10_1X10; fmt->format.field = V4L2_FIELD_NONE; } @@ -898,7 +898,7 @@ static int imx258_set_pad_format(struct v4l2_subdev *sd, mutex_lock(&imx258->mutex); /* Only one raw bayer(GBRG) order is supported */ - fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10; + fmt->format.code = MEDIA_BUS_FMT_SBGGR10_1X10; mode = v4l2_find_nearest_size(supported_modes, ARRAY_SIZE(supported_modes), width, height, From patchwork Tue May 30 17:29:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 687043 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 33F9FC7EE23 for ; Tue, 30 May 2023 17:30:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233448AbjE3Ra5 (ORCPT ); Tue, 30 May 2023 13:30:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232372AbjE3Raz (ORCPT ); Tue, 30 May 2023 13:30:55 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADED3BE for ; Tue, 30 May 2023 10:30:39 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-30aa76048fbso3234789f8f.2 for ; Tue, 30 May 2023 10:30:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1685467838; x=1688059838; 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=u7/FcO1U+j1nYafNALuQBE2oIBBveZJ8k9FM+1r+mLQ=; b=PSCTZ0VOFIA3mpQiEXJUivFW8R2a6tk7L5ikbNoZvsr9W2gYRZwLzi/ud/rQmuiBiB ct+GrXvxJc9Pab+fK9zXGhuBp09GxNOZezt+SmURMAUlu/Onnq2y7EW2ui2FCqKZNm50 hAjaI6g1lpTbcyz8rhg5JE8XomTEYzrjRnJPp7+SFgjrra94OigGndnXPwZ1EgJuJ2nC BDVdbVEnIVC0S3LJPBdY2YcirvtZbxb+6vTZi3GIeFYMF6w7YPOV5ijtvSwttWufWG3w 1wHUkvDUp0bCbTq64fes1T8btiDzs57aruc5mZyzNYGt10MN7MqLGhLYIhA0Tsr3uO3C fRjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685467838; x=1688059838; 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=u7/FcO1U+j1nYafNALuQBE2oIBBveZJ8k9FM+1r+mLQ=; b=JelYma0lvvHNZ3F+zqqYaVc0l0M1fjzzYb2N+pe77VgIUozDYZ5nGj5STBEMoKQzKW pP28i5Yy2obp0gu/KIS0m5jAQlzl+lSCmVR5DwnLaMj5YG5jFH8NrNd6b2nowQDj4U0U JKv69wPP8wRgLXxQm+/0UnmTaOZSn6DShHbh5ND7vMWD97EkVc0wm9uwIWRuAxnH8R/H SAgQtHlX0M6/0bAh43feG22eEBeHaBLr17W9yyn512933gFutmwbpubkG4ZzjBq5rkbH FXBQFoYE3o05+dOaHDKAfjFMEZnRQx80DcxG0GT/kaZE1wm6f+01JcKG13bx0QxZqqXa GfYQ== X-Gm-Message-State: AC+VfDyJXKeVlnKUe8vRcvmBe51tmtkreEMjNnlGl4s6H4jG6/yYuurc l+fJJPD3qtPYaFZ5Hvq1ZSmB0A== X-Google-Smtp-Source: ACHHUZ5F5xRqIVyM6Ii8wAbGuU8dMOv2X8P1gGJ3+JcLOVS1ZYMlWofiOpOjlu5hbw/a4T/kF8DKcw== X-Received: by 2002:a5d:5551:0:b0:306:3731:f73b with SMTP id g17-20020a5d5551000000b003063731f73bmr2197212wrw.43.1685467838228; Tue, 30 May 2023 10:30:38 -0700 (PDT) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id h14-20020a056000000e00b0030ae901bc54sm3964823wrx.62.2023.05.30.10.30.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 10:30:37 -0700 (PDT) From: Dave Stevenson To: Sakari Ailus , linux-media@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org Cc: Dave Stevenson Subject: [PATCH 05/21] media: i2c: imx258: Add regulator control Date: Tue, 30 May 2023 18:29:44 +0100 Message-Id: <20230530173000.3060865-6-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230530173000.3060865-1-dave.stevenson@raspberrypi.com> References: <20230530173000.3060865-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The device tree bindings define the relevant regulators for the sensor, so update the driver to request the regulators and control them at the appropriate times. Signed-off-by: Dave Stevenson --- drivers/media/i2c/imx258.c | 42 +++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index b695fd987b71..30bae7388c3a 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -507,6 +508,16 @@ static const char * const imx258_test_pattern_menu[] = { "Pseudorandom Sequence (PN9)", }; +/* regulator supplies */ +static const char * const imx258_supply_name[] = { + /* Supplies can be enabled in any order */ + "vana", /* Analog (2.8V) supply */ + "vdig", /* Digital Core (1.2V) supply */ + "vif", /* IF (1.8V) supply */ +}; + +#define IMX258_NUM_SUPPLIES ARRAY_SIZE(imx258_supply_name) + /* Configurations for supported link frequencies */ #define IMX258_LINK_FREQ_634MHZ 633600000ULL #define IMX258_LINK_FREQ_320MHZ 320000000ULL @@ -614,6 +625,7 @@ struct imx258 { bool streaming; struct clk *clk; + struct regulator_bulk_data supplies[IMX258_NUM_SUPPLIES]; }; static inline struct imx258 *to_imx258(struct v4l2_subdev *_sd) @@ -999,9 +1011,19 @@ static int imx258_power_on(struct device *dev) struct imx258 *imx258 = to_imx258(sd); int ret; + ret = regulator_bulk_enable(IMX258_NUM_SUPPLIES, + imx258->supplies); + if (ret) { + dev_err(dev, "%s: failed to enable regulators\n", + __func__); + return ret; + } + ret = clk_prepare_enable(imx258->clk); - if (ret) + if (ret) { dev_err(dev, "failed to enable clock\n"); + regulator_bulk_disable(IMX258_NUM_SUPPLIES, imx258->supplies); + } return ret; } @@ -1012,6 +1034,7 @@ static int imx258_power_off(struct device *dev) struct imx258 *imx258 = to_imx258(sd); clk_disable_unprepare(imx258->clk); + regulator_bulk_disable(IMX258_NUM_SUPPLIES, imx258->supplies); return 0; } @@ -1260,6 +1283,19 @@ static void imx258_free_controls(struct imx258 *imx258) mutex_destroy(&imx258->mutex); } +static int imx258_get_regulators(struct imx258 *imx258, + struct i2c_client *client) +{ + unsigned int i; + + for (i = 0; i < IMX258_NUM_SUPPLIES; i++) + imx258->supplies[i].supply = imx258_supply_name[i]; + + return devm_regulator_bulk_get(&client->dev, + IMX258_NUM_SUPPLIES, + imx258->supplies); +} + static int imx258_probe(struct i2c_client *client) { struct imx258 *imx258; @@ -1270,6 +1306,10 @@ static int imx258_probe(struct i2c_client *client) if (!imx258) return -ENOMEM; + ret = imx258_get_regulators(imx258, client); + if (ret) + return ret; + imx258->clk = devm_clk_get_optional(&client->dev, NULL); if (IS_ERR(imx258->clk)) return dev_err_probe(&client->dev, PTR_ERR(imx258->clk), From patchwork Tue May 30 17:29:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 687042 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 5542CC7EE23 for ; Tue, 30 May 2023 17:31:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233418AbjE3Ra7 (ORCPT ); Tue, 30 May 2023 13:30:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233429AbjE3Ra4 (ORCPT ); Tue, 30 May 2023 13:30:56 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB439EA for ; Tue, 30 May 2023 10:30:41 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-30aebe2602fso1792749f8f.3 for ; Tue, 30 May 2023 10:30:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1685467840; x=1688059840; 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=wc3ytaiyab5qcNXXV08KfBLcECyWOvHwoS6EBmpUcn4=; b=Yv2tt9qAl3AF04PSVbTldrI2Lyt/9iXkbs0AC5pSN6eXYx2sI9r9DOtLf9erG2MzUo 6BNDSb9hSXDnyt2ttzWBfe4v6sMB+4G0YpXBtmsBOnr8obBItMH6vhHxfLb1DuF1E0n7 E3TG3Hhis4IKOEXN4jeLL+j1oRbBnqLlb8MRDtalzddRfIdKNmiGH1k0IMiedemX2es+ huAo03fUzUfO35AoDBKWV2EHVjhJa8Q2FdnrhXH+PD/soU0BrHFvVcYiHpqrHMSkS7Vm M3dMJGDdIFKdVS+RlOU2IAxgUw5vet6Re7LoSgT3hphi9y2HedoeRgr/k6Ax14fbkQUO 6lXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685467840; x=1688059840; 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=wc3ytaiyab5qcNXXV08KfBLcECyWOvHwoS6EBmpUcn4=; b=fSfTaZgOUVthYZmc0ArK81jTfFyf/bG28HZE2JDXI3zvjQp6hfuAaKT3HRyPDAo6Zo hqYiHq4s632gH8J2YK0iCNwNEQYrvxRkp8VcXqPZpQqzlxt6ce23v2L/ss/kJ3iC5Krt PhHfHDXkz/i60zXJfpwAY+lFtrF1Yy24kuHaYpgdWESZMgI2fv4wc9E0EvSXJGtofyim UGc51LRpTXrI41oKx8b+wEs3wrgUv5C8sodZFyCW5H54l3wQFxD/7rdTv2IjHe3A21nF GhCIjITalDi7l0+lZffDlZ9eKqSt9VD+MZAdg5Vl+DXNac63oMbxRMczodnuUQ4c8guv 8LXQ== X-Gm-Message-State: AC+VfDzka80Ft2p22zm0FGs6LHAIs8wTR5OmF2DwNqKoY3oyX3DJetBK JyVVYDjSUwutRtQs0NxJ3NBYU/z2sLdjRMBKGgU= X-Google-Smtp-Source: ACHHUZ6X3KwAeXAuK7do058CkuaiW9UJD6s9hSg7Q9v7TT64DVpSFPQIOKNIMq5ugQPFBuz1RGEZmA== X-Received: by 2002:adf:e44d:0:b0:30a:b030:9cdd with SMTP id t13-20020adfe44d000000b0030ab0309cddmr2099995wrm.25.1685467840417; Tue, 30 May 2023 10:30:40 -0700 (PDT) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id h14-20020a056000000e00b0030ae901bc54sm3964823wrx.62.2023.05.30.10.30.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 10:30:39 -0700 (PDT) From: Dave Stevenson To: Sakari Ailus , linux-media@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org Cc: Dave Stevenson Subject: [PATCH 08/21] media: i2c: imx258: Add support for 24MHz clock Date: Tue, 30 May 2023 18:29:47 +0100 Message-Id: <20230530173000.3060865-9-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230530173000.3060865-1-dave.stevenson@raspberrypi.com> References: <20230530173000.3060865-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org There's no reason why only a clock of 19.2MHz is supported. Indeed this isn't even a frequency listed in the datasheet. Add support for 24MHz as well. The PLL settings result in slightly different link frequencies, so parameterise those. Signed-off-by: Dave Stevenson --- drivers/media/i2c/imx258.c | 137 ++++++++++++++++++++++++++++++------- 1 file changed, 111 insertions(+), 26 deletions(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index 5a57d0b5fcd8..d40521f9a3c6 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -76,9 +76,6 @@ #define REG_CONFIG_MIRROR_FLIP 0x03 #define REG_CONFIG_FLIP_TEST_PATTERN 0x02 -/* Input clock frequency in Hz */ -#define IMX258_INPUT_CLOCK_FREQ 19200000 - struct imx258_reg { u16 address; u8 val; @@ -91,6 +88,7 @@ struct imx258_reg_list { /* Link frequency config */ struct imx258_link_freq_config { + u64 link_frequency; u32 pixels_per_line; /* PLL registers for this link frequency */ @@ -115,7 +113,9 @@ struct imx258_mode { }; /* 4208x3120 needs 1267Mbps/lane, 4 lanes */ -static const struct imx258_reg mipi_data_rate_1267mbps[] = { +static const struct imx258_reg mipi_1267mbps_19_2mhz[] = { + { 0x0136, 0x13 }, + { 0x0137, 0x33 }, { 0x0301, 0x05 }, { 0x0303, 0x02 }, { 0x0305, 0x03 }, @@ -133,7 +133,29 @@ static const struct imx258_reg mipi_data_rate_1267mbps[] = { { 0x0823, 0xCC }, }; -static const struct imx258_reg mipi_data_rate_640mbps[] = { +static const struct imx258_reg mipi_1272mbps_24mhz[] = { + { 0x0136, 0x18 }, + { 0x0137, 0x00 }, + { 0x0301, 0x05 }, + { 0x0303, 0x02 }, + { 0x0305, 0x04 }, + { 0x0306, 0x00 }, + { 0x0307, 0xD4 }, + { 0x0309, 0x0A }, + { 0x030B, 0x01 }, + { 0x030D, 0x02 }, + { 0x030E, 0x00 }, + { 0x030F, 0xD8 }, + { 0x0310, 0x00 }, + { 0x0820, 0x13 }, + { 0x0821, 0x4C }, + { 0x0822, 0xCC }, + { 0x0823, 0xCC }, +}; + +static const struct imx258_reg mipi_640mbps_19_2mhz[] = { + { 0x0136, 0x13 }, + { 0x0137, 0x33 }, { 0x0301, 0x05 }, { 0x0303, 0x02 }, { 0x0305, 0x03 }, @@ -151,9 +173,27 @@ static const struct imx258_reg mipi_data_rate_640mbps[] = { { 0x0823, 0x00 }, }; +static const struct imx258_reg mipi_642mbps_24mhz[] = { + { 0x0136, 0x18 }, + { 0x0137, 0x00 }, + { 0x0301, 0x05 }, + { 0x0303, 0x02 }, + { 0x0305, 0x04 }, + { 0x0306, 0x00 }, + { 0x0307, 0x6B }, + { 0x0309, 0x0A }, + { 0x030B, 0x01 }, + { 0x030D, 0x02 }, + { 0x030E, 0x00 }, + { 0x030F, 0xD8 }, + { 0x0310, 0x00 }, + { 0x0820, 0x0A }, + { 0x0821, 0x00 }, + { 0x0822, 0x00 }, + { 0x0823, 0x00 }, +}; + static const struct imx258_reg mode_common_regs[] = { - { 0x0136, 0x13 }, - { 0x0137, 0x33 }, { 0x3051, 0x00 }, { 0x3052, 0x00 }, { 0x4E21, 0x14 }, @@ -313,10 +353,6 @@ static const char * const imx258_supply_name[] = { #define IMX258_NUM_SUPPLIES ARRAY_SIZE(imx258_supply_name) -/* Configurations for supported link frequencies */ -#define IMX258_LINK_FREQ_634MHZ 633600000ULL -#define IMX258_LINK_FREQ_320MHZ 320000000ULL - enum { IMX258_LINK_FREQ_1267MBPS, IMX258_LINK_FREQ_640MBPS, @@ -335,25 +371,55 @@ static u64 link_freq_to_pixel_rate(u64 f) } /* Menu items for LINK_FREQ V4L2 control */ -static const s64 link_freq_menu_items[] = { +/* Configurations for supported link frequencies */ +#define IMX258_LINK_FREQ_634MHZ 633600000ULL +#define IMX258_LINK_FREQ_320MHZ 320000000ULL + +static const s64 link_freq_menu_items_19_2[] = { IMX258_LINK_FREQ_634MHZ, IMX258_LINK_FREQ_320MHZ, }; +/* Configurations for supported link frequencies */ +#define IMX258_LINK_FREQ_636MHZ 636000000ULL +#define IMX258_LINK_FREQ_321MHZ 321000000ULL + +static const s64 link_freq_menu_items_24[] = { + IMX258_LINK_FREQ_636MHZ, + IMX258_LINK_FREQ_321MHZ, +}; + /* Link frequency configs */ -static const struct imx258_link_freq_config link_freq_configs[] = { +static const struct imx258_link_freq_config link_freq_configs_19_2[] = { + [IMX258_LINK_FREQ_1267MBPS] = { + .pixels_per_line = IMX258_PPL_DEFAULT, + .reg_list = { + .num_of_regs = ARRAY_SIZE(mipi_1267mbps_19_2mhz), + .regs = mipi_1267mbps_19_2mhz, + } + }, + [IMX258_LINK_FREQ_640MBPS] = { + .pixels_per_line = IMX258_PPL_DEFAULT, + .reg_list = { + .num_of_regs = ARRAY_SIZE(mipi_640mbps_19_2mhz), + .regs = mipi_640mbps_19_2mhz, + } + }, +}; + +static const struct imx258_link_freq_config link_freq_configs_24[] = { [IMX258_LINK_FREQ_1267MBPS] = { .pixels_per_line = IMX258_PPL_DEFAULT, .reg_list = { - .num_of_regs = ARRAY_SIZE(mipi_data_rate_1267mbps), - .regs = mipi_data_rate_1267mbps, + .num_of_regs = ARRAY_SIZE(mipi_1272mbps_24mhz), + .regs = mipi_1272mbps_24mhz, } }, [IMX258_LINK_FREQ_640MBPS] = { .pixels_per_line = IMX258_PPL_DEFAULT, .reg_list = { - .num_of_regs = ARRAY_SIZE(mipi_data_rate_640mbps), - .regs = mipi_data_rate_640mbps, + .num_of_regs = ARRAY_SIZE(mipi_642mbps_24mhz), + .regs = mipi_642mbps_24mhz, } }, }; @@ -410,6 +476,9 @@ struct imx258 { /* Current mode */ const struct imx258_mode *cur_mode; + const struct imx258_link_freq_config *link_freq_configs; + const s64 *link_freq_menu_items; + /* * Mutex for serialized access: * Protect sensor module set pad format and start/stop streaming safely. @@ -717,7 +786,7 @@ static int imx258_set_pad_format(struct v4l2_subdev *sd, imx258->cur_mode = mode; __v4l2_ctrl_s_ctrl(imx258->link_freq, mode->link_freq_index); - link_freq = link_freq_menu_items[mode->link_freq_index]; + link_freq = imx258->link_freq_menu_items[mode->link_freq_index]; pixel_rate = link_freq_to_pixel_rate(link_freq); __v4l2_ctrl_s_ctrl_int64(imx258->pixel_rate, pixel_rate); /* Update limits and set FPS to default */ @@ -731,7 +800,7 @@ static int imx258_set_pad_format(struct v4l2_subdev *sd, vblank_def); __v4l2_ctrl_s_ctrl(imx258->vblank, vblank_def); h_blank = - link_freq_configs[mode->link_freq_index].pixels_per_line + imx258->link_freq_configs[mode->link_freq_index].pixels_per_line - imx258->cur_mode->width; __v4l2_ctrl_modify_range(imx258->hblank, h_blank, h_blank, 1, h_blank); @@ -751,7 +820,7 @@ static int imx258_start_streaming(struct imx258 *imx258) /* Setup PLL */ link_freq_index = imx258->cur_mode->link_freq_index; - reg_list = &link_freq_configs[link_freq_index].reg_list; + reg_list = &imx258->link_freq_configs[link_freq_index].reg_list; ret = imx258_write_regs(imx258, reg_list->regs, reg_list->num_of_regs); if (ret) { dev_err(&client->dev, "%s failed to set plls\n", __func__); @@ -986,9 +1055,9 @@ static int imx258_init_controls(struct imx258 *imx258) imx258->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, &imx258_ctrl_ops, V4L2_CID_LINK_FREQ, - ARRAY_SIZE(link_freq_menu_items) - 1, + ARRAY_SIZE(link_freq_menu_items_19_2) - 1, 0, - link_freq_menu_items); + imx258->link_freq_menu_items); if (imx258->link_freq) imx258->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; @@ -1004,8 +1073,10 @@ static int imx258_init_controls(struct imx258 *imx258) if (vflip) vflip->flags |= V4L2_CTRL_FLAG_READ_ONLY; - pixel_rate_max = link_freq_to_pixel_rate(link_freq_menu_items[0]); - pixel_rate_min = link_freq_to_pixel_rate(link_freq_menu_items[1]); + pixel_rate_max = + link_freq_to_pixel_rate(imx258->link_freq_menu_items[0]); + pixel_rate_min = + link_freq_to_pixel_rate(imx258->link_freq_menu_items[1]); /* By default, PIXEL_RATE is read only */ imx258->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops, V4L2_CID_PIXEL_RATE, @@ -1123,11 +1194,25 @@ static int imx258_probe(struct i2c_client *client) "no clock provided, using clock-frequency property\n"); device_property_read_u32(&client->dev, "clock-frequency", &val); + } else if (IS_ERR(imx258->clk)) { + return dev_err_probe(&client->dev, PTR_ERR(imx258->clk), + "error getting clock\n"); } else { val = clk_get_rate(imx258->clk); } - if (val != IMX258_INPUT_CLOCK_FREQ) { - dev_err(&client->dev, "input clock frequency not supported\n"); + + switch (val) { + case 19200000: + imx258->link_freq_configs = link_freq_configs_19_2; + imx258->link_freq_menu_items = link_freq_menu_items_19_2; + break; + case 24000000: + imx258->link_freq_configs = link_freq_configs_24; + imx258->link_freq_menu_items = link_freq_menu_items_24; + break; + default: + dev_err(&client->dev, "input clock frequency of %u not supported\n", + val); return -EINVAL; } From patchwork Tue May 30 17:29:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 687041 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 11D67C7EE32 for ; Tue, 30 May 2023 17:31:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233484AbjE3RbB (ORCPT ); Tue, 30 May 2023 13:31:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233411AbjE3Ra5 (ORCPT ); Tue, 30 May 2023 13:30:57 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2198F133 for ; Tue, 30 May 2023 10:30:43 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-30af86a96b4so506178f8f.3 for ; Tue, 30 May 2023 10:30:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1685467841; x=1688059841; 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=7ZSyDMKbn7895XHyKFyQxSeXVFo2FOQ8DM2PUTA4yfA=; b=oQiBQGeEz7NaiYO6TxKMla9Q/9kAAjBklvopZ4r8D138guGbFy7dxocYIJbWr31AGA 2vxk0d4aw6E4xPbNJRIcrIU3xOS+W3sTNVzbCWuPMFqPSJgCUUzNf06f05DcOO7bd/q+ UYH3wLg4/nm8M3SBP5Y3ZE4c5paLPIkY2MyiI+6ocA3zrp8GmZhMTQwpVcjjsHADk3vg YpJLNohpjS+dbcmmUD19DrG1ZEe3WhmI1KfCrHhHMgqT32W5TF/VfCiwhhX45CCLSTtp 9iHzHbAGcTdraLanhFN9pTb3ni8A0PPV7Ag3P7E6CKR+t9C/ysnzlwWXxRmpdnMaBLTi v6Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685467841; x=1688059841; 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=7ZSyDMKbn7895XHyKFyQxSeXVFo2FOQ8DM2PUTA4yfA=; b=ixFNfqkeIIM//HNjlMbDEM2dBPg9KC/YRI6W0fhFRiPqP/OLS0ANMgJSfO2HvDppab X3yXFd7JZciV/pg4FDjEw1jDwWkOeEfu0uP+p/+wOxIvaV6vnogvP0HiH2WRLAlYxiJu K5mag7YXIXlJ2C7zkRgtv8aY7jefIWUkobbvpZiJ5wsOQvxlshCHIGtW1nI0Rg86jocs tESddsvvVDrciS/W6dNjJxVoR+lWM0LgU8Ku7tro/LrIQnNGxQJwxDNex2kFHjoOpbrQ wr0UlIZc4mXTJZhz5o6xkL6y6VULl+PvrnuxduXWhBZ2u1wfy9/ZopdwpaqWDc+SyDQz PXoQ== X-Gm-Message-State: AC+VfDw4uV5p/Y8cJ/e9Gyc9fTJ09hBkqmEUYF9iwBnfkjjaolEE4XJ3 g31NBp1wbkgUORnuboUQ7iqaWw== X-Google-Smtp-Source: ACHHUZ7+Fxn6Adgaa/yNZ6eLBb/jzjH0VNbcLe8swDCYEwt7d/vm0UaQ44rTFvbYvpDSeovgUWrD7A== X-Received: by 2002:a5d:408e:0:b0:2ef:ba4f:c821 with SMTP id o14-20020a5d408e000000b002efba4fc821mr2034857wrp.36.1685467841154; Tue, 30 May 2023 10:30:41 -0700 (PDT) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id h14-20020a056000000e00b0030ae901bc54sm3964823wrx.62.2023.05.30.10.30.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 10:30:40 -0700 (PDT) From: Dave Stevenson To: Sakari Ailus , linux-media@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org Cc: Dave Stevenson Subject: [PATCH 09/21] media: i2c: imx258: Add support for running on 2 CSI data lanes Date: Tue, 30 May 2023 18:29:48 +0100 Message-Id: <20230530173000.3060865-10-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230530173000.3060865-1-dave.stevenson@raspberrypi.com> References: <20230530173000.3060865-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Extends the driver to also support 2 data lanes. Frame rates are obviously more restricted on 2 lanes, but some hardware simply hasn't wired more up. Signed-off-by: Dave Stevenson --- drivers/media/i2c/imx258.c | 211 ++++++++++++++++++++++++++++++++----- 1 file changed, 187 insertions(+), 24 deletions(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index d40521f9a3c6..433dff7f1fa0 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -86,13 +86,17 @@ struct imx258_reg_list { const struct imx258_reg *regs; }; +#define IMX258_LANE_CONFIGS 2 +#define IMX258_2_LANE_MODE 0 +#define IMX258_4_LANE_MODE 1 + /* Link frequency config */ struct imx258_link_freq_config { u64 link_frequency; u32 pixels_per_line; /* PLL registers for this link frequency */ - struct imx258_reg_list reg_list; + struct imx258_reg_list reg_list[IMX258_LANE_CONFIGS]; }; /* Mode : resolution and related config&values */ @@ -112,8 +116,30 @@ struct imx258_mode { struct imx258_reg_list reg_list; }; -/* 4208x3120 needs 1267Mbps/lane, 4 lanes */ -static const struct imx258_reg mipi_1267mbps_19_2mhz[] = { +/* 4208x3120 needs 1267Mbps/lane, 4 lanes. Use that rate on 2 lanes as well */ +static const struct imx258_reg mipi_1267mbps_19_2mhz_2l[] = { + { 0x0136, 0x13 }, + { 0x0137, 0x33 }, + { 0x0301, 0x0A }, + { 0x0303, 0x02 }, + { 0x0305, 0x03 }, + { 0x0306, 0x00 }, + { 0x0307, 0xC6 }, + { 0x0309, 0x0A }, + { 0x030B, 0x01 }, + { 0x030D, 0x02 }, + { 0x030E, 0x00 }, + { 0x030F, 0xD8 }, + { 0x0310, 0x00 }, + + { 0x0114, 0x01 }, + { 0x0820, 0x09 }, + { 0x0821, 0xa6 }, + { 0x0822, 0x66 }, + { 0x0823, 0x66 }, +}; + +static const struct imx258_reg mipi_1267mbps_19_2mhz_4l[] = { { 0x0136, 0x13 }, { 0x0137, 0x33 }, { 0x0301, 0x05 }, @@ -127,16 +153,18 @@ static const struct imx258_reg mipi_1267mbps_19_2mhz[] = { { 0x030E, 0x00 }, { 0x030F, 0xD8 }, { 0x0310, 0x00 }, + + { 0x0114, 0x03 }, { 0x0820, 0x13 }, { 0x0821, 0x4C }, { 0x0822, 0xCC }, { 0x0823, 0xCC }, }; -static const struct imx258_reg mipi_1272mbps_24mhz[] = { +static const struct imx258_reg mipi_1272mbps_24mhz_2l[] = { { 0x0136, 0x18 }, { 0x0137, 0x00 }, - { 0x0301, 0x05 }, + { 0x0301, 0x0a }, { 0x0303, 0x02 }, { 0x0305, 0x04 }, { 0x0306, 0x00 }, @@ -147,13 +175,59 @@ static const struct imx258_reg mipi_1272mbps_24mhz[] = { { 0x030E, 0x00 }, { 0x030F, 0xD8 }, { 0x0310, 0x00 }, + + { 0x0114, 0x01 }, { 0x0820, 0x13 }, { 0x0821, 0x4C }, { 0x0822, 0xCC }, { 0x0823, 0xCC }, }; -static const struct imx258_reg mipi_640mbps_19_2mhz[] = { +static const struct imx258_reg mipi_1272mbps_24mhz_4l[] = { + { 0x0136, 0x18 }, + { 0x0137, 0x00 }, + { 0x0301, 0x05 }, + { 0x0303, 0x02 }, + { 0x0305, 0x04 }, + { 0x0306, 0x00 }, + { 0x0307, 0xD4 }, + { 0x0309, 0x0A }, + { 0x030B, 0x01 }, + { 0x030D, 0x02 }, + { 0x030E, 0x00 }, + { 0x030F, 0xD8 }, + { 0x0310, 0x00 }, + + { 0x0114, 0x03 }, + { 0x0820, 0x13 }, + { 0x0821, 0xE0 }, + { 0x0822, 0x00 }, + { 0x0823, 0x00 }, +}; + +static const struct imx258_reg mipi_640mbps_19_2mhz_2l[] = { + { 0x0136, 0x13 }, + { 0x0137, 0x33 }, + { 0x0301, 0x05 }, + { 0x0303, 0x02 }, + { 0x0305, 0x03 }, + { 0x0306, 0x00 }, + { 0x0307, 0x64 }, + { 0x0309, 0x0A }, + { 0x030B, 0x01 }, + { 0x030D, 0x02 }, + { 0x030E, 0x00 }, + { 0x030F, 0xD8 }, + { 0x0310, 0x00 }, + + { 0x0114, 0x01 }, + { 0x0820, 0x05 }, + { 0x0821, 0x00 }, + { 0x0822, 0x00 }, + { 0x0823, 0x00 }, +}; + +static const struct imx258_reg mipi_640mbps_19_2mhz_4l[] = { { 0x0136, 0x13 }, { 0x0137, 0x33 }, { 0x0301, 0x05 }, @@ -167,13 +241,37 @@ static const struct imx258_reg mipi_640mbps_19_2mhz[] = { { 0x030E, 0x00 }, { 0x030F, 0xD8 }, { 0x0310, 0x00 }, + + { 0x0114, 0x03 }, { 0x0820, 0x0A }, { 0x0821, 0x00 }, { 0x0822, 0x00 }, { 0x0823, 0x00 }, }; -static const struct imx258_reg mipi_642mbps_24mhz[] = { +static const struct imx258_reg mipi_642mbps_24mhz_2l[] = { + { 0x0136, 0x18 }, + { 0x0137, 0x00 }, + { 0x0301, 0x0A }, + { 0x0303, 0x02 }, + { 0x0305, 0x04 }, + { 0x0306, 0x00 }, + { 0x0307, 0x6B }, + { 0x0309, 0x0A }, + { 0x030B, 0x01 }, + { 0x030D, 0x02 }, + { 0x030E, 0x00 }, + { 0x030F, 0xD8 }, + { 0x0310, 0x00 }, + + { 0x0114, 0x01 }, + { 0x0820, 0x0A }, + { 0x0821, 0x00 }, + { 0x0822, 0x00 }, + { 0x0823, 0x00 }, +}; + +static const struct imx258_reg mipi_642mbps_24mhz_4l[] = { { 0x0136, 0x18 }, { 0x0137, 0x00 }, { 0x0301, 0x05 }, @@ -187,6 +285,8 @@ static const struct imx258_reg mipi_642mbps_24mhz[] = { { 0x030E, 0x00 }, { 0x030F, 0xD8 }, { 0x0310, 0x00 }, + + { 0x0114, 0x03 }, { 0x0820, 0x0A }, { 0x0821, 0x00 }, { 0x0822, 0x00 }, @@ -241,7 +341,6 @@ static const struct imx258_reg mode_common_regs[] = { { 0x5F05, 0xED }, { 0x0112, 0x0A }, { 0x0113, 0x0A }, - { 0x0114, 0x03 }, { 0x0342, 0x14 }, { 0x0343, 0xE8 }, { 0x0344, 0x00 }, @@ -360,11 +459,13 @@ enum { /* * pixel_rate = link_freq * data-rate * nr_of_lanes / bits_per_sample - * data rate => double data rate; number of lanes => 4; bits per pixel => 10 + * data rate => double data rate; + * number of lanes => (configurable 2 or 4); + * bits per pixel => 10 */ -static u64 link_freq_to_pixel_rate(u64 f) +static u64 link_freq_to_pixel_rate(u64 f, unsigned int nlanes) { - f *= 2 * 4; + f *= 2 * nlanes; do_div(f, 10); return f; @@ -394,15 +495,27 @@ static const struct imx258_link_freq_config link_freq_configs_19_2[] = { [IMX258_LINK_FREQ_1267MBPS] = { .pixels_per_line = IMX258_PPL_DEFAULT, .reg_list = { - .num_of_regs = ARRAY_SIZE(mipi_1267mbps_19_2mhz), - .regs = mipi_1267mbps_19_2mhz, + [IMX258_2_LANE_MODE] = { + .num_of_regs = ARRAY_SIZE(mipi_1267mbps_19_2mhz_2l), + .regs = mipi_1267mbps_19_2mhz_2l, + }, + [IMX258_4_LANE_MODE] = { + .num_of_regs = ARRAY_SIZE(mipi_1267mbps_19_2mhz_4l), + .regs = mipi_1267mbps_19_2mhz_4l, + }, } }, [IMX258_LINK_FREQ_640MBPS] = { .pixels_per_line = IMX258_PPL_DEFAULT, .reg_list = { - .num_of_regs = ARRAY_SIZE(mipi_640mbps_19_2mhz), - .regs = mipi_640mbps_19_2mhz, + [IMX258_2_LANE_MODE] = { + .num_of_regs = ARRAY_SIZE(mipi_640mbps_19_2mhz_2l), + .regs = mipi_640mbps_19_2mhz_2l, + }, + [IMX258_4_LANE_MODE] = { + .num_of_regs = ARRAY_SIZE(mipi_640mbps_19_2mhz_4l), + .regs = mipi_640mbps_19_2mhz_4l, + }, } }, }; @@ -411,15 +524,27 @@ static const struct imx258_link_freq_config link_freq_configs_24[] = { [IMX258_LINK_FREQ_1267MBPS] = { .pixels_per_line = IMX258_PPL_DEFAULT, .reg_list = { - .num_of_regs = ARRAY_SIZE(mipi_1272mbps_24mhz), - .regs = mipi_1272mbps_24mhz, + [IMX258_2_LANE_MODE] = { + .num_of_regs = ARRAY_SIZE(mipi_1272mbps_24mhz_2l), + .regs = mipi_1272mbps_24mhz_2l, + }, + [IMX258_4_LANE_MODE] = { + .num_of_regs = ARRAY_SIZE(mipi_1272mbps_24mhz_4l), + .regs = mipi_1272mbps_24mhz_4l, + }, } }, [IMX258_LINK_FREQ_640MBPS] = { .pixels_per_line = IMX258_PPL_DEFAULT, .reg_list = { - .num_of_regs = ARRAY_SIZE(mipi_642mbps_24mhz), - .regs = mipi_642mbps_24mhz, + [IMX258_2_LANE_MODE] = { + .num_of_regs = ARRAY_SIZE(mipi_642mbps_24mhz_2l), + .regs = mipi_642mbps_24mhz_2l, + }, + [IMX258_4_LANE_MODE] = { + .num_of_regs = ARRAY_SIZE(mipi_642mbps_24mhz_4l), + .regs = mipi_642mbps_24mhz_4l, + }, } }, }; @@ -478,6 +603,7 @@ struct imx258 { const struct imx258_link_freq_config *link_freq_configs; const s64 *link_freq_menu_items; + unsigned int nlanes; /* * Mutex for serialized access: @@ -787,7 +913,7 @@ static int imx258_set_pad_format(struct v4l2_subdev *sd, __v4l2_ctrl_s_ctrl(imx258->link_freq, mode->link_freq_index); link_freq = imx258->link_freq_menu_items[mode->link_freq_index]; - pixel_rate = link_freq_to_pixel_rate(link_freq); + pixel_rate = link_freq_to_pixel_rate(link_freq, imx258->nlanes); __v4l2_ctrl_s_ctrl_int64(imx258->pixel_rate, pixel_rate); /* Update limits and set FPS to default */ vblank_def = imx258->cur_mode->vts_def - @@ -816,11 +942,13 @@ static int imx258_start_streaming(struct imx258 *imx258) { struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); const struct imx258_reg_list *reg_list; + const struct imx258_link_freq_config *link_freq_cfg; int ret, link_freq_index; /* Setup PLL */ link_freq_index = imx258->cur_mode->link_freq_index; - reg_list = &imx258->link_freq_configs[link_freq_index].reg_list; + link_freq_cfg = &imx258->link_freq_configs[link_freq_index]; + reg_list = &link_freq_cfg->reg_list[imx258->nlanes == 2 ? 0 : 1]; ret = imx258_write_regs(imx258, reg_list->regs, reg_list->num_of_regs); if (ret) { dev_err(&client->dev, "%s failed to set plls\n", __func__); @@ -1074,9 +1202,11 @@ static int imx258_init_controls(struct imx258 *imx258) vflip->flags |= V4L2_CTRL_FLAG_READ_ONLY; pixel_rate_max = - link_freq_to_pixel_rate(imx258->link_freq_menu_items[0]); + link_freq_to_pixel_rate(imx258->link_freq_menu_items[0], + imx258->nlanes); pixel_rate_min = - link_freq_to_pixel_rate(imx258->link_freq_menu_items[1]); + link_freq_to_pixel_rate(imx258->link_freq_menu_items[1], + imx258->nlanes); /* By default, PIXEL_RATE is read only */ imx258->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops, V4L2_CID_PIXEL_RATE, @@ -1174,6 +1304,10 @@ static int imx258_get_regulators(struct imx258 *imx258, static int imx258_probe(struct i2c_client *client) { struct imx258 *imx258; + struct fwnode_handle *endpoint; + struct v4l2_fwnode_endpoint ep = { + .bus_type = V4L2_MBUS_CSI2_DPHY + }; int ret; u32 val = 0; @@ -1216,13 +1350,38 @@ static int imx258_probe(struct i2c_client *client) return -EINVAL; } + endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(&client->dev), NULL); + if (!endpoint) { + dev_err(&client->dev, "Endpoint node not found\n"); + return -EINVAL; + } + + ret = v4l2_fwnode_endpoint_alloc_parse(endpoint, &ep); + fwnode_handle_put(endpoint); + if (ret == -ENXIO) { + dev_err(&client->dev, "Unsupported bus type, should be CSI2\n"); + goto error_endpoint_poweron; + } else if (ret) { + dev_err(&client->dev, "Parsing endpoint node failed\n"); + goto error_endpoint_poweron; + } + + /* Get number of data lanes */ + imx258->nlanes = ep.bus.mipi_csi2.num_data_lanes; + if (imx258->nlanes != 2 && imx258->nlanes != 4) { + dev_err(&client->dev, "Invalid data lanes: %u\n", + imx258->nlanes); + ret = -EINVAL; + goto error_endpoint_poweron; + } + /* Initialize subdev */ v4l2_i2c_subdev_init(&imx258->sd, client, &imx258_subdev_ops); /* Will be powered off via pm_runtime_idle */ ret = imx258_power_on(&client->dev); if (ret) - return ret; + goto error_endpoint_poweron; /* Check module identity */ ret = imx258_identify_module(imx258); @@ -1255,6 +1414,7 @@ static int imx258_probe(struct i2c_client *client) pm_runtime_set_active(&client->dev); pm_runtime_enable(&client->dev); pm_runtime_idle(&client->dev); + v4l2_fwnode_endpoint_free(&endpoint); return 0; @@ -1267,6 +1427,9 @@ static int imx258_probe(struct i2c_client *client) error_identify: imx258_power_off(&client->dev); +error_endpoint_poweron: + v4l2_fwnode_endpoint_free(&ep); + return ret; } From patchwork Tue May 30 17:29:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 687040 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 A7F39C7EE23 for ; Tue, 30 May 2023 17:31:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233469AbjE3RbD (ORCPT ); Tue, 30 May 2023 13:31:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233476AbjE3Ra7 (ORCPT ); Tue, 30 May 2023 13:30:59 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDB9F137 for ; Tue, 30 May 2023 10:30:44 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3f6ffc2b314so540825e9.0 for ; Tue, 30 May 2023 10:30:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1685467843; x=1688059843; 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=jbrlyIIVWtljdw9WJ85IvtoCQCr75FYCyMVLGQO5Tmc=; b=CA0VBEoc9iIBzHXJRv4T+k/OL6i3wBgopcXzil+L2P8VpB3s0QjWHoj3gJlUnn2zfY MRABR0lKl6stLocFEZ+aneDF+hR2zlE4wnZx/9/0EXijhvm8zTAfVrGJjSercDkQurmk 8zXW9mJjx6wEKMQBNsVwzedFlbFY0vEePWLDJR09RYvS/JnaqYw58x8vQ8JAlySRrpqi aBKWB5S7h7yXLGF9bI7mnvg76dFzq5ELcr3RbyunOAOcZEEuxj8awsxjcEZvCA9jUaHs sE5gfT/tIBldNYSqJ+w/Mbcv1ZyI5lYjLGJFoGYnCAO6g6Ha9/vL3KPkD7mgNflHAVpy /8VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685467843; x=1688059843; 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=jbrlyIIVWtljdw9WJ85IvtoCQCr75FYCyMVLGQO5Tmc=; b=YNIVVPgSNAn3ajWEt+lxTfiHtvh5vK9nDfD5PXYxZD9uXxBInhD5xZ1sipC7aTLem4 aQvppketlx0wzfQRx3b4KEWHfzrim4nxSKttT2qJwDAUCzVmDgWPNu1je8IMGyQy6Vzp YcNwXY8ch3fJ3RPaltZit73eTAZl6NHyHh/hH790Ksk7AYvh3S4dX7t771ALrfzzjrEp LIIlWNqHqia9dLISiHVD501zKdvIIHFZxFkOOytI9/4jdkGc4NG3VkJSuJStyx9cesQg 6t1obGJacMWKssx8PgIEE9c1hXiyM0knYPk3rzM2y7YtpYJ/KsZWSvYPsp4OFXNRntKb ZMog== X-Gm-Message-State: AC+VfDyO8cXvx1iEhim4j/KCnniJGy7h16bTApYLy+zg1iL9DnD/WuJw tF/5xmU7t6wy/S00s0dEAdVEJpHqVfFnjMpLJLg= X-Google-Smtp-Source: ACHHUZ58ZZhVsCHcRerb4diHY/iL0doRdlIylB7Zl7T38eUt87QIs7tYNUSOBmSCHZnVQyQOthf1YQ== X-Received: by 2002:a5d:5957:0:b0:30a:ed4c:e17d with SMTP id e23-20020a5d5957000000b0030aed4ce17dmr4276888wri.5.1685467843361; Tue, 30 May 2023 10:30:43 -0700 (PDT) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id h14-20020a056000000e00b0030ae901bc54sm3964823wrx.62.2023.05.30.10.30.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 10:30:43 -0700 (PDT) From: Dave Stevenson To: Sakari Ailus , linux-media@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org Cc: Dave Stevenson Subject: [PATCH 12/21] media: i2c: imx258: Allow configuration of clock lane behaviour Date: Tue, 30 May 2023 18:29:51 +0100 Message-Id: <20230530173000.3060865-13-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230530173000.3060865-1-dave.stevenson@raspberrypi.com> References: <20230530173000.3060865-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The sensor supports the clock lane either remaining in HS mode during frame blanking, or dropping to LP11. Add configuration of the mode via V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK. Signed-off-by: Dave Stevenson Reviewed-by: Jacopo Mondi --- drivers/media/i2c/imx258.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index 1fa83fe82f27..b5c2dcb7c9e6 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -72,6 +72,8 @@ /* Test Pattern Control */ #define IMX258_REG_TEST_PATTERN 0x0600 +#define IMX258_CLK_BLANK_STOP 0x4040 + /* Orientation */ #define REG_MIRROR_FLIP_CONTROL 0x0101 #define REG_CONFIG_MIRROR_FLIP 0x03 @@ -634,6 +636,7 @@ struct imx258 { const struct imx258_link_freq_config *link_freq_configs; const s64 *link_freq_menu_items; unsigned int nlanes; + unsigned int csi2_flags; /* * Mutex for serialized access: @@ -1072,6 +1075,15 @@ static int imx258_start_streaming(struct imx258 *imx258) return ret; } + ret = imx258_write_reg(imx258, IMX258_CLK_BLANK_STOP, + IMX258_REG_VALUE_08BIT, + imx258->csi2_flags & V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK ? + 1 : 0); + if (ret) { + dev_err(&client->dev, "%s failed to set clock lane mode\n", __func__); + return ret; + } + /* Apply default values of current mode */ reg_list = &imx258->cur_mode->reg_list; ret = imx258_write_regs(imx258, reg_list->regs, reg_list->num_of_regs); @@ -1486,6 +1498,8 @@ static int imx258_probe(struct i2c_client *client) goto error_endpoint_poweron; } + imx258->csi2_flags = ep.bus.mipi_csi2.flags; + /* Initialize subdev */ v4l2_i2c_subdev_init(&imx258->sd, client, &imx258_subdev_ops); From patchwork Tue May 30 17:29:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 687039 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 ED5A3C7EE24 for ; Tue, 30 May 2023 17:31:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233477AbjE3RbF (ORCPT ); Tue, 30 May 2023 13:31:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233407AbjE3RbB (ORCPT ); Tue, 30 May 2023 13:31:01 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE517C5 for ; Tue, 30 May 2023 10:30:45 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-30ad99fa586so4549881f8f.2 for ; Tue, 30 May 2023 10:30:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1685467844; x=1688059844; 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=s0RVCChZrw1HM9gOYT9R7Dq9M2JqYnSrsD9fDiYXZqw=; b=Mk9j0A28T6ZsD/yDUdYTaasqk+2b7wKUk8E2DlztWHh0RyXRVFPSZD7ZFthFUpAdrG XT7y0PraqOExWZyDr3DW/zW5kv1lZduZS/yWQTcwt4cQuXGneoQCTc5EYZUPD/C9N3MI rQ8qLEbk0YZ/DQcWp9mrTnjHQRAHU6P3f5EFCQQCBownaSvGlzmSc7WxBvb0m9Wh6sO6 /t5/namP+ryoxiOM8VAIZ0qSOS4TG0d9zYoR29nca3R18m/pVoB2tu6337r41oo8hlst rhZa4vvN6M6hD1tiHrFC059RUIwDNRsz8a6AidKnYjJkrWTsOPfCyC9nkmK2y6Lj8AT6 GuyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685467844; x=1688059844; 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=s0RVCChZrw1HM9gOYT9R7Dq9M2JqYnSrsD9fDiYXZqw=; b=DdHXLKgsu8efWfGMFYmEseesGsnURgeFO6ukcE+K90pDvgetrwu+giuwyNPDStg41C +cLILOrMU5gQu9M6wKGK9etN4jS0BSXo0e9kyDIoetgMpLGHqlioJ/sH3LjQ0gW5Kyrm hLFaY61bF2zWyMisNAs1TX2hU52TqQIf5jVMtgivcCgsI2PpJtxysB2+5ZeAYX0g+s0e YEttpPxtkXNEqMMyNHtFeHm9jn3qkXL2S12KB9LchrP7Okmqbtr2VwLujfSWPyxWZcnY YDAR4z4SZDCyQ9w+LMIGnudsUS4xFQ9xA8f2uiNxlJALm4eLsplToUAD49oREZr+t7V2 6lqw== X-Gm-Message-State: AC+VfDzyeIIUWuuUZglicB0Q6tixAnzWsLTYdouilNa1IkxJvr4+O1q5 shZJReWPMH+fmrvac/hCCk/4iw== X-Google-Smtp-Source: ACHHUZ5Y27ra5AaDsbjy8uc6KnHxbqSIL9rvP8ykCeiZTJYKsmQpxOYMh5RFpxYgewnchbx9vZqxow== X-Received: by 2002:adf:d851:0:b0:304:8147:f0ba with SMTP id k17-20020adfd851000000b003048147f0bamr2494403wrl.3.1685467844357; Tue, 30 May 2023 10:30:44 -0700 (PDT) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id h14-20020a056000000e00b0030ae901bc54sm3964823wrx.62.2023.05.30.10.30.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 10:30:44 -0700 (PDT) From: Dave Stevenson To: Sakari Ailus , linux-media@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org Cc: Dave Stevenson Subject: [PATCH 13/21] media: i2c: imx258: Correct max FRM_LENGTH_LINES value Date: Tue, 30 May 2023 18:29:52 +0100 Message-Id: <20230530173000.3060865-14-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230530173000.3060865-1-dave.stevenson@raspberrypi.com> References: <20230530173000.3060865-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The data sheet states that the maximum value for registers 0x0340/0x0341 FRM_LENGTH_LINES is 65525(decimal), not the 0xFFFF defined in this driver. Correct this limit. Signed-off-by: Dave Stevenson Reviewed-by: Jacopo Mondi --- drivers/media/i2c/imx258.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index b5c2dcb7c9e6..f5199e3243e8 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -28,7 +28,7 @@ #define IMX258_VTS_30FPS 0x0c50 #define IMX258_VTS_30FPS_2K 0x0638 #define IMX258_VTS_30FPS_VGA 0x034c -#define IMX258_VTS_MAX 0xffff +#define IMX258_VTS_MAX 65525 #define IMX258_REG_VTS 0x0340 From patchwork Tue May 30 17:29:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 687038 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 B63AFC7EE2F for ; Tue, 30 May 2023 17:31:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233505AbjE3RbH (ORCPT ); Tue, 30 May 2023 13:31:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233411AbjE3RbC (ORCPT ); Tue, 30 May 2023 13:31:02 -0400 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 39922FE for ; Tue, 30 May 2023 10:30:47 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-30af56f5f52so807543f8f.1 for ; Tue, 30 May 2023 10:30:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1685467845; x=1688059845; 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=cUThpILL4T/V94u7S3e1f/FLWPY1UKbhVsXY3sBoTvM=; b=kWNH+y9ZyNFRMDrxP2j1B18xVkLWKSxcZKOjaNbDjk2esJUXYVQcVxqohNPsZvADOA 85Uwsytw94xHTbUolGqPZx9+JYlDbSSSlBwpf7C6KmP0mTfXWV7Ylsm+mZ2GA6rET3BF Y10+/cUWAclIzasjZ8+Tb4l7OE4cu40FvqJYSjiwTZZIRStQr+/5WxZrxZY5D4LhvTTx rLgJ8YYQk8Afdr4GJvegeZNGz77Og+4JvLQhIG6fmwMjgmApRdc1jMx5u22EzKw3hY4R JgUmCnlRPOXJo0cLUaf6bFJri+3lsqwFGAQGepupX4aJI6xWgLn3WpTcWNeNdR+ZX+SI jriQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685467845; x=1688059845; 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=cUThpILL4T/V94u7S3e1f/FLWPY1UKbhVsXY3sBoTvM=; b=K1lSHAPkUyf6tNHdVM0th+TVWhESj14rxuXC5kwYXeMDLr6YUR7hvAQY7AZYSFGL9k RpJb2Dk+75kkIV2xmxiV1ttj3K60VhIrL5z+ktT0YmN/S7ksVOhmztjZjvzbr61gvmYj i862ZpR2GxBPw2WyyjzWMGplFM+vgZi1VH7jjAIBC5kK7crtLQA8ny7y7+WDXAXc9oGH u4US16s0Q6KKcyAnpM04Ka6MqPZzg/FUDbkWfX7o4w3VjDXtP4PvY94JsXgoiYk7ddbD B0C8hBxOzE8y8hgAdI77sA+82g8tzZI4OQxsDHki/GTSkjxEOUkIGbqSNMyEjETPWIf+ 96JQ== X-Gm-Message-State: AC+VfDzM18rrPd5V1r51kxmqtzAfmy5hybEfUBNBDfkBzjT3FCIkZtLo o+d12npXbPlB/cckUlbmtW4AHg== X-Google-Smtp-Source: ACHHUZ4TvCLpRAjzLTHS5+42Go0XWDRlGJeuCvwmbQjSgRmgAodQ7zs/FN7Q3ItjXwdoY+XOM3O+KQ== X-Received: by 2002:a5d:55cc:0:b0:30a:ebf6:b061 with SMTP id i12-20020a5d55cc000000b0030aebf6b061mr2332611wrw.60.1685467845780; Tue, 30 May 2023 10:30:45 -0700 (PDT) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id h14-20020a056000000e00b0030ae901bc54sm3964823wrx.62.2023.05.30.10.30.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 10:30:45 -0700 (PDT) From: Dave Stevenson To: Sakari Ailus , linux-media@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org Cc: Dave Stevenson Subject: [PATCH 15/21] media: i2c: imx258: Issue reset before starting streaming Date: Tue, 30 May 2023 18:29:54 +0100 Message-Id: <20230530173000.3060865-16-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230530173000.3060865-1-dave.stevenson@raspberrypi.com> References: <20230530173000.3060865-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Whilst not documented, register 0x0103 bit 0 is the soft reset for the sensor, so send it before trying to configure the sensor. Signed-off-by: Dave Stevenson --- drivers/media/i2c/imx258.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index 1e424058fcb9..7d6528f9ca4d 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -20,6 +20,8 @@ #define IMX258_MODE_STANDBY 0x00 #define IMX258_MODE_STREAMING 0x01 +#define IMX258_REG_RESET 0x0103 + /* Chip ID */ #define IMX258_REG_CHIP_ID 0x0016 #define IMX258_CHIP_ID 0x0258 @@ -1084,6 +1086,14 @@ static int imx258_start_streaming(struct imx258 *imx258) const struct imx258_link_freq_config *link_freq_cfg; int ret, link_freq_index; + ret = imx258_write_reg(imx258, IMX258_REG_RESET, IMX258_REG_VALUE_08BIT, + 0x01); + if (ret) { + dev_err(&client->dev, "%s failed to reset sensor\n", __func__); + return ret; + } + usleep_range(10000, 15000); + /* Setup PLL */ link_freq_index = imx258->cur_mode->link_freq_index; link_freq_cfg = &imx258->link_freq_configs[link_freq_index]; From patchwork Tue May 30 17:29:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 687037 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 47BE5C7EE33 for ; Tue, 30 May 2023 17:31:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233504AbjE3RbJ (ORCPT ); Tue, 30 May 2023 13:31:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233215AbjE3RbD (ORCPT ); Tue, 30 May 2023 13:31:03 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD27D188 for ; Tue, 30 May 2023 10:30:48 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-30aa76048fbso3235178f8f.2 for ; Tue, 30 May 2023 10:30:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1685467847; x=1688059847; 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=cnWY7OTC78+bqFCEFt1iBTNvVK0nkspVbxS6HHLxTBw=; b=jVGfs046dCFefrTKca4lLHASiUFjo83tZ9XRKITF1Pzv20fgvULT8BKQL3ygFC/tY6 PklFwZrB9LAzkY7QkYgbOTf/pRDmglOSoXXsLELgBlcNshkPh0MsPopE3Ux8TQtaCNgn n8ttUmiJ7Gvhk5eheTZsdAl0JjKjSnZAY2BbEXXvKUPBlXKg29oy5XNqbi46eDAogxxR f9ZrjBu3k9kiRmT4A8kI6cPUNBTyiqC550GX8HOSesP9iYWU5xBNUiD0hXSpIzGEDMHB Yb0FxeKpDKwtYZ33ESeQGern5AfEGyAOArq6UCfH9+2jnH9A4k1ZpXdqZkaBsg+Pf0r+ 61pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685467847; x=1688059847; 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=cnWY7OTC78+bqFCEFt1iBTNvVK0nkspVbxS6HHLxTBw=; b=gqAgcJtIs5G4nROty588DJTojZFET4sqpIrOUs1alpaK6NAqZU/TpnXaG/KFvyuBad pNos/H3girUWUoAzA3Zc9CpKUfGxMCOfQWGPGcZZQLG8HPkn2WH07XlPIgzGDA9w0Tid oTVZNs4ACoEeEkX/wN7gkqPDYrfwx1RzptYbqyKdGCgXwUZiTWXjWasU7akZYf80IMTm iNnb8jGqdPrIIc9Vod8TWmtJcyrKo/w4z1K2Lx/iQIjh0I2A2pjAFkV9El9guoIGyMyL cACBXZwY0mSwIKStDJOEuppNr2qTIWT1sX8M3WaHj/UY/MymLwYgyZ9duAmLfbYG+HY7 wjVg== X-Gm-Message-State: AC+VfDy/8sduvh43OUUNPnRcjDM3otynTS7BFgkdQG7BAZ/TXxC+nI/v GG5gWXGZV1jg5tF0ZpT4NFy71A== X-Google-Smtp-Source: ACHHUZ40lW60nbY8Y/M4PKGKr3nMy/UnHyiZSUEW0ViFeGk/4T8j3O3pNZ0BY8Tv/ZTuYxO+O3Krkg== X-Received: by 2002:a05:6000:12c8:b0:309:48eb:cdf9 with SMTP id l8-20020a05600012c800b0030948ebcdf9mr2215743wrx.38.1685467847261; Tue, 30 May 2023 10:30:47 -0700 (PDT) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id h14-20020a056000000e00b0030ae901bc54sm3964823wrx.62.2023.05.30.10.30.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 10:30:46 -0700 (PDT) From: Dave Stevenson To: Sakari Ailus , linux-media@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org Cc: Dave Stevenson Subject: [PATCH 17/21] media: i2c: imx258: Support faster pixel rate on binned modes Date: Tue, 30 May 2023 18:29:56 +0100 Message-Id: <20230530173000.3060865-18-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230530173000.3060865-1-dave.stevenson@raspberrypi.com> References: <20230530173000.3060865-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org With the binned modes, there is little point in faithfully reproducing the horizontal line length of 5352 pixels on the CSI2 bus, and the FIFO between the pixel array and MIPI serialiser allows us to remove that dependency. Allow the pixel array to run with the normal settings, with the MIPI serialiser at half the rate. This requires some additional information for the link frequency to pixel rate function that needs to be added to the configuration tables. Signed-off-by: Dave Stevenson --- drivers/media/i2c/imx258.c | 109 ++++++++++++++++++++++++------------- 1 file changed, 71 insertions(+), 38 deletions(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index b9b650d40365..986757650378 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -103,6 +103,11 @@ struct imx258_reg_list { const struct imx258_reg *regs; }; +struct imx258_link_cfg { + unsigned int lf_to_pix_rate_factor; + struct imx258_reg_list reg_list; +}; + #define IMX258_LANE_CONFIGS 2 #define IMX258_2_LANE_MODE 0 #define IMX258_4_LANE_MODE 1 @@ -112,8 +117,8 @@ struct imx258_link_freq_config { u64 link_frequency; u32 pixels_per_line; - /* PLL registers for this link frequency */ - struct imx258_reg_list reg_list[IMX258_LANE_CONFIGS]; + /* Configuration for this link frequency / num lanes selection */ + struct imx258_link_cfg link_cfg[IMX258_LANE_CONFIGS]; }; /* Mode : resolution and related config&values */ @@ -272,7 +277,7 @@ static const struct imx258_reg mipi_640mbps_19_2mhz_4l[] = { static const struct imx258_reg mipi_642mbps_24mhz_2l[] = { { 0x0136, 0x18 }, { 0x0137, 0x00 }, - { 0x0301, 0x0A }, + { 0x0301, 0x05 }, { 0x0303, 0x02 }, { 0x0305, 0x04 }, { 0x0306, 0x00 }, @@ -478,14 +483,22 @@ enum { }; /* - * pixel_rate = link_freq * data-rate * nr_of_lanes / bits_per_sample - * data rate => double data rate; - * number of lanes => (configurable 2 or 4); - * bits per pixel => 10 + * Pixel rate does not necessarily relate to link frequency on this sensor as + * there is a FIFO between the pixel array pipeline and the MIPI serializer. + * The recommendation from Sony is that the pixel array is always run with a + * line length of 5352 pixels, which means that there is a large amount of + * blanking time for the 1048x780 mode. There is no need to replicate this + * blanking on the CSI2 bus, and the configuration of register 0x0301 allows the + * divider to be altered. + * + * The actual factor between link frequency and pixel rate is in the + * imx258_link_cfg, so use this to convert between the two. + * bits per pixel being 10, and D-PHY being DDR is assumed by this function, so + * the value is only the combination of number of lanes and pixel clock divider. */ -static u64 link_freq_to_pixel_rate(u64 f, unsigned int nlanes) +static u64 link_freq_to_pixel_rate(u64 f, const struct imx258_link_cfg *link_cfg) { - f *= 2 * nlanes; + f *= 2 * link_cfg->lf_to_pix_rate_factor; do_div(f, 10); return f; @@ -510,31 +523,33 @@ static const s64 link_freq_menu_items_24[] = { IMX258_LINK_FREQ_321MHZ, }; +#define REGS(_list) { .num_of_regs = ARRAY_SIZE(_list), .regs = _list, } + /* Link frequency configs */ static const struct imx258_link_freq_config link_freq_configs_19_2[] = { [IMX258_LINK_FREQ_1267MBPS] = { .pixels_per_line = IMX258_PPL_DEFAULT, - .reg_list = { + .link_cfg = { [IMX258_2_LANE_MODE] = { - .num_of_regs = ARRAY_SIZE(mipi_1267mbps_19_2mhz_2l), - .regs = mipi_1267mbps_19_2mhz_2l, + .lf_to_pix_rate_factor = 2 * 2, + .reg_list = REGS(mipi_1267mbps_19_2mhz_2l), }, [IMX258_4_LANE_MODE] = { - .num_of_regs = ARRAY_SIZE(mipi_1267mbps_19_2mhz_4l), - .regs = mipi_1267mbps_19_2mhz_4l, + .lf_to_pix_rate_factor = 4, + .reg_list = REGS(mipi_1267mbps_19_2mhz_4l), }, } }, [IMX258_LINK_FREQ_640MBPS] = { .pixels_per_line = IMX258_PPL_DEFAULT, - .reg_list = { + .link_cfg = { [IMX258_2_LANE_MODE] = { - .num_of_regs = ARRAY_SIZE(mipi_640mbps_19_2mhz_2l), - .regs = mipi_640mbps_19_2mhz_2l, + .lf_to_pix_rate_factor = 2, + .reg_list = REGS(mipi_640mbps_19_2mhz_2l), }, [IMX258_4_LANE_MODE] = { - .num_of_regs = ARRAY_SIZE(mipi_640mbps_19_2mhz_4l), - .regs = mipi_640mbps_19_2mhz_4l, + .lf_to_pix_rate_factor = 4, + .reg_list = REGS(mipi_640mbps_19_2mhz_4l), }, } }, @@ -543,27 +558,27 @@ static const struct imx258_link_freq_config link_freq_configs_19_2[] = { static const struct imx258_link_freq_config link_freq_configs_24[] = { [IMX258_LINK_FREQ_1267MBPS] = { .pixels_per_line = IMX258_PPL_DEFAULT, - .reg_list = { + .link_cfg = { [IMX258_2_LANE_MODE] = { - .num_of_regs = ARRAY_SIZE(mipi_1272mbps_24mhz_2l), - .regs = mipi_1272mbps_24mhz_2l, + .lf_to_pix_rate_factor = 2, + .reg_list = REGS(mipi_1272mbps_24mhz_2l), }, [IMX258_4_LANE_MODE] = { - .num_of_regs = ARRAY_SIZE(mipi_1272mbps_24mhz_4l), - .regs = mipi_1272mbps_24mhz_4l, + .lf_to_pix_rate_factor = 4, + .reg_list = REGS(mipi_1272mbps_24mhz_4l), }, } }, [IMX258_LINK_FREQ_640MBPS] = { .pixels_per_line = IMX258_PPL_DEFAULT, - .reg_list = { + .link_cfg = { [IMX258_2_LANE_MODE] = { - .num_of_regs = ARRAY_SIZE(mipi_642mbps_24mhz_2l), - .regs = mipi_642mbps_24mhz_2l, + .lf_to_pix_rate_factor = 2 * 2, + .reg_list = REGS(mipi_642mbps_24mhz_2l), }, [IMX258_4_LANE_MODE] = { - .num_of_regs = ARRAY_SIZE(mipi_642mbps_24mhz_4l), - .regs = mipi_642mbps_24mhz_4l, + .lf_to_pix_rate_factor = 4, + .reg_list = REGS(mipi_642mbps_24mhz_4l), }, } }, @@ -643,7 +658,7 @@ struct imx258 { const struct imx258_link_freq_config *link_freq_configs; const s64 *link_freq_menu_items; - unsigned int nlanes; + unsigned int lane_mode_idx; unsigned int csi2_flags; /* @@ -976,8 +991,10 @@ static int imx258_set_pad_format(struct v4l2_subdev *sd, struct v4l2_subdev_format *fmt) { struct imx258 *imx258 = to_imx258(sd); - const struct imx258_mode *mode; + const struct imx258_link_freq_config *link_freq_cfgs; + const struct imx258_link_cfg *link_cfg; struct v4l2_mbus_framefmt *framefmt; + const struct imx258_mode *mode; s32 vblank_def; s32 vblank_min; s64 h_blank; @@ -1001,7 +1018,11 @@ static int imx258_set_pad_format(struct v4l2_subdev *sd, __v4l2_ctrl_s_ctrl(imx258->link_freq, mode->link_freq_index); link_freq = imx258->link_freq_menu_items[mode->link_freq_index]; - pixel_rate = link_freq_to_pixel_rate(link_freq, imx258->nlanes); + link_freq_cfgs = + &imx258->link_freq_configs[mode->link_freq_index]; + + link_cfg = &link_freq_cfgs->link_cfg[imx258->lane_mode_idx]; + pixel_rate = link_freq_to_pixel_rate(link_freq, link_cfg); __v4l2_ctrl_modify_range(imx258->pixel_rate, pixel_rate, pixel_rate, 1, pixel_rate); /* Update limits and set FPS to default */ @@ -1098,7 +1119,8 @@ static int imx258_start_streaming(struct imx258 *imx258) /* Setup PLL */ link_freq_index = imx258->cur_mode->link_freq_index; link_freq_cfg = &imx258->link_freq_configs[link_freq_index]; - reg_list = &link_freq_cfg->reg_list[imx258->nlanes == 2 ? 0 : 1]; + + reg_list = &link_freq_cfg->link_cfg[imx258->lane_mode_idx].reg_list; ret = imx258_write_regs(imx258, reg_list->regs, reg_list->num_of_regs); if (ret) { dev_err(&client->dev, "%s failed to set plls\n", __func__); @@ -1324,9 +1346,11 @@ static const struct v4l2_subdev_internal_ops imx258_internal_ops = { static int imx258_init_controls(struct imx258 *imx258) { struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); + const struct imx258_link_freq_config *link_freq_cfgs; struct v4l2_fwnode_device_properties props; - struct v4l2_ctrl_handler *ctrl_hdlr; struct v4l2_ctrl *vflip, *hflip; + struct v4l2_ctrl_handler *ctrl_hdlr; + const struct imx258_link_cfg *link_cfg; s64 vblank_def; s64 vblank_min; s64 pixel_rate; @@ -1360,8 +1384,11 @@ static int imx258_init_controls(struct imx258 *imx258) if (vflip) vflip->flags |= V4L2_CTRL_FLAG_READ_ONLY; + link_freq_cfgs = &imx258->link_freq_configs[0]; + link_cfg = link_freq_cfgs[imx258->lane_mode_idx].link_cfg; pixel_rate = link_freq_to_pixel_rate(imx258->link_freq_menu_items[0], - imx258->nlanes); + link_cfg); + /* By default, PIXEL_RATE is read only */ imx258->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops, V4L2_CID_PIXEL_RATE, @@ -1522,10 +1549,16 @@ static int imx258_probe(struct i2c_client *client) } /* Get number of data lanes */ - imx258->nlanes = ep.bus.mipi_csi2.num_data_lanes; - if (imx258->nlanes != 2 && imx258->nlanes != 4) { + switch (ep.bus.mipi_csi2.num_data_lanes) { + case 2: + imx258->lane_mode_idx = IMX258_2_LANE_MODE; + break; + case 4: + imx258->lane_mode_idx = IMX258_4_LANE_MODE; + break; + default: dev_err(&client->dev, "Invalid data lanes: %u\n", - imx258->nlanes); + ep.bus.mipi_csi2.num_data_lanes); ret = -EINVAL; goto error_endpoint_poweron; } From patchwork Tue May 30 17:29:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 687036 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 D1773C7EE32 for ; Tue, 30 May 2023 17:31:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233482AbjE3RbK (ORCPT ); Tue, 30 May 2023 13:31:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233468AbjE3RbF (ORCPT ); Tue, 30 May 2023 13:31:05 -0400 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 5EE0D10C for ; Tue, 30 May 2023 10:30:50 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3f6d01d390bso49262785e9.2 for ; Tue, 30 May 2023 10:30:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1685467849; x=1688059849; 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=ur+XfWhDDUp4MmWin+/GXdhhvV3YzjyhUErQF6DqfuM=; b=T6GTerzQDiqp2ipMpYi+DNT9+tMaABR4+bpRh7d3p6DNcSASkEkQJbr0ZNxfDzNXuw a+D+AH7QUCXVeKxeB2IRpKq6gJrnfYWXlWTZu4ZfZYhZFN6p0yyPQrFKekA7eNb7KGvl D3bC+Jxa7RDQsGPfNu/eK8XPJMSEsIke7zdZkrkHCmV+CN9HMtOFvSHMGmhS2XKiD/5M aMOwPVU6uYOBYtAWHTn8TeIFVKeXrdr/DpW5Mh0LJFMTqOqxPIM7WcT7/SOLEz41bglT 52IFSFtDHY8NcWsfIRudLH+cAfHB/4sq79+4RRhq5f6YOi36A6QArECp0sNiiGuBt08E tPAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685467849; x=1688059849; 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=ur+XfWhDDUp4MmWin+/GXdhhvV3YzjyhUErQF6DqfuM=; b=fqSEhzaPI/X7uQ//Cnp4+fMusvsLn2WJIitgG4rBNkPe+Gvu22UIhriYdHOjQ95Fs/ xArUIJaXsVTTbLVPfvd6cALtFb2121cidNwLg1V+svNvmd+/8ty+lmrmxZ/e4vzdK1cm 0mjVK+aGZnciprNKN1QrepehyAfffRK+4w0CaKEN4rTZ4qfLLyCEKhMxOGm4I1z4gW+b 34jhO8ex+syFcChG/RV0RrmpJyFtFHEqMn9A20sts/4377H9JNQQP4F8Cs9i7wV6sQJj nWfEV/YKn8xxS7nKoif/BJg/ThYQYcQ59Rouu0870hcuCdPGXwBjctENXd4dAo6Br414 4jyg== X-Gm-Message-State: AC+VfDyXMhXf4FyGdrGgGlcqLGiGA5H9YHZl+00b+O/QOKYtwWr0f+2v cr6ePwq+2KzkMH2LtC4LMpcz4w== X-Google-Smtp-Source: ACHHUZ4qyXdoRL+mf9Zz6fea/PbwDq0CxE2fYdhxfVSOSi3ooTC7nXbcExNV5oNL89a/jSeLFCdPVw== X-Received: by 2002:a5d:54c2:0:b0:306:343a:aede with SMTP id x2-20020a5d54c2000000b00306343aaedemr2618269wrv.65.1685467848905; Tue, 30 May 2023 10:30:48 -0700 (PDT) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id h14-20020a056000000e00b0030ae901bc54sm3964823wrx.62.2023.05.30.10.30.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 10:30:48 -0700 (PDT) From: Dave Stevenson To: Sakari Ailus , linux-media@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org Cc: Dave Stevenson Subject: [PATCH 19/21] dt-bindings: media: imx258: Add alternate compatible strings Date: Tue, 30 May 2023 18:29:58 +0100 Message-Id: <20230530173000.3060865-20-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230530173000.3060865-1-dave.stevenson@raspberrypi.com> References: <20230530173000.3060865-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org There are a number of variants of the imx258 modules that can not be differentiated at runtime, so add compatible strings for them. Signed-off-by: Dave Stevenson --- .../devicetree/bindings/media/i2c/sony,imx258.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/media/i2c/sony,imx258.yaml b/Documentation/devicetree/bindings/media/i2c/sony,imx258.yaml index bee61a443b23..3415b26b5991 100644 --- a/Documentation/devicetree/bindings/media/i2c/sony,imx258.yaml +++ b/Documentation/devicetree/bindings/media/i2c/sony,imx258.yaml @@ -14,10 +14,15 @@ description: |- type stacked image sensor with a square pixel array of size 4208 x 3120. It is programmable through I2C interface. Image data is sent through MIPI CSI-2. + There are a number of variants of the sensor which cannot be detected at + runtime, so multiple compatible strings are required to differentiate these. properties: compatible: - const: sony,imx258 + oneOf: + - enum: + - sony,imx258 + - sony,imx258-pdaf assigned-clocks: true assigned-clock-parents: true From patchwork Tue May 30 17:30:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 687035 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 44BECC7EE33 for ; Tue, 30 May 2023 17:31:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233468AbjE3RbM (ORCPT ); Tue, 30 May 2023 13:31:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233472AbjE3RbI (ORCPT ); Tue, 30 May 2023 13:31:08 -0400 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 6464D10D for ; Tue, 30 May 2023 10:30:52 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3f623adec61so50012875e9.0 for ; Tue, 30 May 2023 10:30:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1685467850; x=1688059850; 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=RVFzCe7HAl1iD+IOebocyxw66+4T7VjgBBQtFfp3oF4=; b=bEh0QQp07tcRFODEe+lFMfLA/s2rK7PdzPke/SRTtCVAlpjpJB+4/ry7X5Bnv9V7KB uKCaElJCQSEzRuck27U6HNC2S557AmK9PGkUSgfAPU/+N+kAVS1YnbSH2czG7TQRfyV5 t0AJYmchYZVbGiW1+7soC3LLTUoEk99XjOLxTSvjakty3US0irfnBlLSD4TQ5/FOWNe9 btCxW1+Z6Djgro/+CZ60k9rNQ/kYzf+aJt9f2xMeMqiM0dieiXFkRwlkFaWgbEKcVZ7v DOxrp84LVd2VB6KsASRDbcgRohLXZLoDiWU+dPek/9+M+OQC1GzBWvGuHQL+W6KlUMbC EEaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685467850; x=1688059850; 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=RVFzCe7HAl1iD+IOebocyxw66+4T7VjgBBQtFfp3oF4=; b=aCjQPjP8x4dkZ8t0jxbBOVx54PFB+eH3ynZFkYGkq2JMK/utdhCWmr6ZhcDOrPvVpf +gboo6h2zEhlDEPxPiQLnxl7a0IuJTqIkR0RiWQmAnlJXc7FAFqr8HqUpQCj56HIwGXa 7wIR8Gb4T5U40NnyjMBtsdS/0myyBSGVBBSK8plb0GGq7dc4P0dGsMpgyXgAlI4Khj7N axRkcizDtvowmO0ZTVo/xxKzF5euz/fgD1Lb2Ero5dt/ZBmAy0XyBejSJcCkrKI/6mea V1DX8RuBfNZKJFnPbXggVC5oBkCwa2v2yEIyUZWqedrsia7UXPIjPjxf2kCUvLdWAaKB A5bQ== X-Gm-Message-State: AC+VfDwep9onW4CYx8JLWOH6w7rhTB0XXdYJIRQ1//WEbVUaIj5mr4GR SLP8AcAHHjMz6pmUVRhddf/yAA== X-Google-Smtp-Source: ACHHUZ4fbgyo0xN72vW1oD3n0FwSFH2ci5yZuBq6JESTgA+XgHMxNZJl0XksbOG89ORjF3LobTUiOw== X-Received: by 2002:a7b:c846:0:b0:3f4:20bd:ba46 with SMTP id c6-20020a7bc846000000b003f420bdba46mr2066456wml.5.1685467850429; Tue, 30 May 2023 10:30:50 -0700 (PDT) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id h14-20020a056000000e00b0030ae901bc54sm3964823wrx.62.2023.05.30.10.30.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 10:30:49 -0700 (PDT) From: Dave Stevenson To: Sakari Ailus , linux-media@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org Cc: Dave Stevenson Subject: [PATCH 21/21] media: i2c: imx258: Make HFLIP and VFLIP controls writable Date: Tue, 30 May 2023 18:30:00 +0100 Message-Id: <20230530173000.3060865-22-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230530173000.3060865-1-dave.stevenson@raspberrypi.com> References: <20230530173000.3060865-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The sensor supports H & V flips, but the controls were READ_ONLY. Note that the Bayer order changes with these flips, therefore they set the V4L2_CTRL_FLAG_MODIFY_LAYOUT property. Signed-off-by: Dave Stevenson --- drivers/media/i2c/imx258.c | 99 ++++++++++++++++++++++++-------------- 1 file changed, 64 insertions(+), 35 deletions(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index 98b5c1e3abff..cf90ac66e14c 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -83,8 +83,8 @@ /* Orientation */ #define REG_MIRROR_FLIP_CONTROL 0x0101 -#define REG_CONFIG_MIRROR_FLIP 0x03 -#define REG_CONFIG_FLIP_TEST_PATTERN 0x02 +#define REG_CONFIG_MIRROR_HFLIP 0x01 +#define REG_CONFIG_MIRROR_VFLIP 0x02 /* IMX258 native and active pixel array size. */ #define IMX258_NATIVE_WIDTH 4224U @@ -484,6 +484,23 @@ static const struct imx258_variant_cfg imx258_pdaf_cfg = { .num_regs = ARRAY_SIZE(imx258_pdaf_cfg_regs), }; +/* + * The supported formats. + * This table MUST contain 4 entries per format, to cover the various flip + * combinations in the order + * - no flip + * - h flip + * - v flip + * - h&v flips + */ +static const u32 codes[] = { + /* 10-bit modes. */ + MEDIA_BUS_FMT_SRGGB10_1X10, + MEDIA_BUS_FMT_SGRBG10_1X10, + MEDIA_BUS_FMT_SGBRG10_1X10, + MEDIA_BUS_FMT_SBGGR10_1X10 +}; + static const char * const imx258_test_pattern_menu[] = { "Disabled", "Solid Colour", @@ -677,6 +694,8 @@ struct imx258 { struct v4l2_ctrl *vblank; struct v4l2_ctrl *hblank; struct v4l2_ctrl *exposure; + struct v4l2_ctrl *hflip; + struct v4l2_ctrl *vflip; /* Current long exposure factor in use. Set through V4L2_CID_VBLANK */ unsigned int long_exp_shift; @@ -780,9 +799,22 @@ static int imx258_write_regs(struct imx258 *imx258, return 0; } +/* Get bayer order based on flip setting. */ +static u32 imx258_get_format_code(struct imx258 *imx258) +{ + unsigned int i; + + lockdep_assert_held(&imx258->mutex); + + i = (imx258->vflip->val ? 2 : 0) | + (imx258->hflip->val ? 1 : 0); + + return codes[i]; +} /* Open sub-device */ static int imx258_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) { + struct imx258 *imx258 = to_imx258(sd); struct v4l2_mbus_framefmt *try_fmt = v4l2_subdev_get_try_format(sd, fh->state, 0); struct v4l2_rect *try_crop; @@ -790,7 +822,7 @@ static int imx258_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) /* Initialize try_fmt */ try_fmt->width = supported_modes[0].width; try_fmt->height = supported_modes[0].height; - try_fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10; + try_fmt->code = imx258_get_format_code(imx258); try_fmt->field = V4L2_FIELD_NONE; /* Initialize try_crop */ @@ -903,10 +935,6 @@ static int imx258_set_ctrl(struct v4l2_ctrl *ctrl) ret = imx258_write_reg(imx258, IMX258_REG_TEST_PATTERN, IMX258_REG_VALUE_16BIT, ctrl->val); - ret = imx258_write_reg(imx258, REG_MIRROR_FLIP_CONTROL, - IMX258_REG_VALUE_08BIT, - !ctrl->val ? REG_CONFIG_MIRROR_FLIP : - REG_CONFIG_FLIP_TEST_PATTERN); break; case V4L2_CID_WIDE_DYNAMIC_RANGE: if (!ctrl->val) { @@ -928,6 +956,15 @@ static int imx258_set_ctrl(struct v4l2_ctrl *ctrl) ret = imx258_set_frame_length(imx258, imx258->cur_mode->height + ctrl->val); break; + case V4L2_CID_VFLIP: + case V4L2_CID_HFLIP: + ret = imx258_write_reg(imx258, REG_MIRROR_FLIP_CONTROL, + IMX258_REG_VALUE_08BIT, + (imx258->hflip->val ? + REG_CONFIG_MIRROR_HFLIP : 0) | + (imx258->vflip->val ? + REG_CONFIG_MIRROR_VFLIP : 0)); + break; default: dev_info(&client->dev, "ctrl(id:0x%x,val:0x%x) is not handled\n", @@ -949,11 +986,13 @@ static int imx258_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_mbus_code_enum *code) { - /* Only one bayer order(GRBG) is supported */ + struct imx258 *imx258 = to_imx258(sd); + + /* Only one bayer format (10 bit) is supported */ if (code->index > 0) return -EINVAL; - code->code = MEDIA_BUS_FMT_SBGGR10_1X10; + code->code = imx258_get_format_code(imx258); return 0; } @@ -962,10 +1001,11 @@ static int imx258_enum_frame_size(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_frame_size_enum *fse) { + struct imx258 *imx258 = to_imx258(sd); if (fse->index >= ARRAY_SIZE(supported_modes)) return -EINVAL; - if (fse->code != MEDIA_BUS_FMT_SBGGR10_1X10) + if (fse->code != imx258_get_format_code(imx258)) return -EINVAL; fse->min_width = supported_modes[fse->index].width; @@ -976,12 +1016,13 @@ static int imx258_enum_frame_size(struct v4l2_subdev *sd, return 0; } -static void imx258_update_pad_format(const struct imx258_mode *mode, +static void imx258_update_pad_format(struct imx258 *imx258, + const struct imx258_mode *mode, struct v4l2_subdev_format *fmt) { fmt->format.width = mode->width; fmt->format.height = mode->height; - fmt->format.code = MEDIA_BUS_FMT_SBGGR10_1X10; + fmt->format.code = imx258_get_format_code(imx258); fmt->format.field = V4L2_FIELD_NONE; } @@ -994,7 +1035,7 @@ static int __imx258_get_pad_format(struct imx258 *imx258, sd_state, fmt->pad); else - imx258_update_pad_format(imx258->cur_mode, fmt); + imx258_update_pad_format(imx258, imx258->cur_mode, fmt); return 0; } @@ -1030,13 +1071,12 @@ static int imx258_set_pad_format(struct v4l2_subdev *sd, mutex_lock(&imx258->mutex); - /* Only one raw bayer(GBRG) order is supported */ - fmt->format.code = MEDIA_BUS_FMT_SBGGR10_1X10; + fmt->format.code = imx258_get_format_code(imx258); mode = v4l2_find_nearest_size(supported_modes, ARRAY_SIZE(supported_modes), width, height, fmt->format.width, fmt->format.height); - imx258_update_pad_format(mode, fmt); + imx258_update_pad_format(imx258, mode, fmt); if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { framefmt = v4l2_subdev_get_try_format(sd, sd_state, fmt->pad); *framefmt = fmt->format; @@ -1186,15 +1226,6 @@ static int imx258_start_streaming(struct imx258 *imx258) return ret; } - /* Set Orientation be 180 degree */ - ret = imx258_write_reg(imx258, REG_MIRROR_FLIP_CONTROL, - IMX258_REG_VALUE_08BIT, REG_CONFIG_MIRROR_FLIP); - if (ret) { - dev_err(&client->dev, "%s failed to set orientation\n", - __func__); - return ret; - } - /* Apply customized values from user */ ret = __v4l2_ctrl_handler_setup(imx258->sd.ctrl_handler); if (ret) @@ -1383,7 +1414,6 @@ static int imx258_init_controls(struct imx258 *imx258) struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); const struct imx258_link_freq_config *link_freq_cfgs; struct v4l2_fwnode_device_properties props; - struct v4l2_ctrl *vflip, *hflip; struct v4l2_ctrl_handler *ctrl_hdlr; const struct imx258_link_cfg *link_cfg; s64 vblank_def; @@ -1408,16 +1438,15 @@ static int imx258_init_controls(struct imx258 *imx258) if (imx258->link_freq) imx258->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; - /* The driver only supports one bayer order and flips by default. */ - hflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops, - V4L2_CID_HFLIP, 1, 1, 1, 1); - if (hflip) - hflip->flags |= V4L2_CTRL_FLAG_READ_ONLY; + imx258->hflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops, + V4L2_CID_HFLIP, 0, 1, 1, 1); + if (imx258->hflip) + imx258->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; - vflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops, - V4L2_CID_VFLIP, 1, 1, 1, 1); - if (vflip) - vflip->flags |= V4L2_CTRL_FLAG_READ_ONLY; + imx258->vflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops, + V4L2_CID_VFLIP, 0, 1, 1, 1); + if (imx258->vflip) + imx258->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; link_freq_cfgs = &imx258->link_freq_configs[0]; link_cfg = link_freq_cfgs[imx258->lane_mode_idx].link_cfg;