From patchwork Sat Oct 28 07:17:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Apitzsch?= X-Patchwork-Id: 739177 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 DEA39C27C4B for ; Sat, 28 Oct 2023 07:19:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232134AbjJ1HS5 (ORCPT ); Sat, 28 Oct 2023 03:18:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229584AbjJ1HSt (ORCPT ); Sat, 28 Oct 2023 03:18:49 -0400 Received: from smtprelay08.ispgateway.de (smtprelay08.ispgateway.de [134.119.228.110]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C95C11B; Sat, 28 Oct 2023 00:18:45 -0700 (PDT) Received: from [92.206.139.21] (helo=note-book.lan) by smtprelay08.ispgateway.de with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.1) (envelope-from ) id 1qwdak-0002T7-1M; Sat, 28 Oct 2023 09:18:42 +0200 From: =?utf-8?q?Andr=C3=A9_Apitzsch?= Date: Sat, 28 Oct 2023 09:17:44 +0200 Subject: [PATCH v2 1/5] media: i2c: imx214: Explain some magic numbers MIME-Version: 1.0 Message-Id: <20231028-imx214-v2-1-69a8fb730d6e@apitzsch.eu> References: <20231028-imx214-v2-0-69a8fb730d6e@apitzsch.eu> In-Reply-To: <20231028-imx214-v2-0-69a8fb730d6e@apitzsch.eu> To: Ricardo Ribalda , Sakari Ailus , Mauro Carvalho Chehab Cc: Kieran Bingham , Jacopo Mondi , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, =?utf-8?q?Andr=C3=A9_Apitzsch?= , Ricardo Ribalda X-Mailer: b4 0.12.3 X-Df-Sender: YW5kcmVAYXBpdHpzY2guZXU= Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Code refinement, no functional changes. Reviewed-by: Ricardo Ribalda Signed-off-by: André Apitzsch --- drivers/media/i2c/imx214.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/media/i2c/imx214.c b/drivers/media/i2c/imx214.c index 4f77ea02cc27..1c30f6666d35 100644 --- a/drivers/media/i2c/imx214.c +++ b/drivers/media/i2c/imx214.c @@ -19,12 +19,23 @@ #include #include +#define IMX214_REG_MODE_SELECT 0x0100 +#define IMX214_MODE_STANDBY 0x00 +#define IMX214_MODE_STREAMING 0x01 + #define IMX214_DEFAULT_CLK_FREQ 24000000 #define IMX214_DEFAULT_LINK_FREQ 480000000 #define IMX214_DEFAULT_PIXEL_RATE ((IMX214_DEFAULT_LINK_FREQ * 8LL) / 10) #define IMX214_FPS 30 #define IMX214_MBUS_CODE MEDIA_BUS_FMT_SRGGB10_1X10 +/* Exposure control */ +#define IMX214_REG_EXPOSURE 0x0202 +#define IMX214_EXPOSURE_MIN 0 +#define IMX214_EXPOSURE_MAX 3184 +#define IMX214_EXPOSURE_STEP 1 +#define IMX214_EXPOSURE_DEFAULT 3184 + static const char * const imx214_supply_name[] = { "vdda", "vddd", @@ -665,7 +676,7 @@ static int imx214_set_ctrl(struct v4l2_ctrl *ctrl) case V4L2_CID_EXPOSURE: vals[1] = ctrl->val; vals[0] = ctrl->val >> 8; - ret = regmap_bulk_write(imx214->regmap, 0x202, vals, 2); + ret = regmap_bulk_write(imx214->regmap, IMX214_REG_EXPOSURE, vals, 2); if (ret < 0) dev_err(imx214->dev, "Error %d\n", ret); ret = 0; @@ -743,7 +754,7 @@ static int imx214_start_streaming(struct imx214 *imx214) dev_err(imx214->dev, "could not sync v4l2 controls\n"); goto error; } - ret = regmap_write(imx214->regmap, 0x100, 1); + ret = regmap_write(imx214->regmap, IMX214_REG_MODE_SELECT, IMX214_MODE_STREAMING); if (ret < 0) { dev_err(imx214->dev, "could not sent start table %d\n", ret); goto error; @@ -761,7 +772,7 @@ static int imx214_stop_streaming(struct imx214 *imx214) { int ret; - ret = regmap_write(imx214->regmap, 0x100, 0); + ret = regmap_write(imx214->regmap, IMX214_REG_MODE_SELECT, IMX214_MODE_STANDBY); if (ret < 0) dev_err(imx214->dev, "could not sent stop table %d\n", ret); @@ -991,9 +1002,12 @@ static int imx214_probe(struct i2c_client *client) * * Yours sincerely, Ricardo. */ - imx214->exposure = v4l2_ctrl_new_std(&imx214->ctrls, &imx214_ctrl_ops, + imx214->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &imx214_ctrl_ops, V4L2_CID_EXPOSURE, - 0, 3184, 1, 0x0c70); + IMX214_EXPOSURE_MIN, + IMX214_EXPOSURE_MAX, + IMX214_EXPOSURE_STEP, + IMX214_EXPOSURE_DEFAULT); imx214->unit_size = v4l2_ctrl_new_std_compound(&imx214->ctrls, NULL, From patchwork Sat Oct 28 07:17:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Apitzsch?= X-Patchwork-Id: 739178 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 67012C25B67 for ; Sat, 28 Oct 2023 07:19:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232912AbjJ1HS7 (ORCPT ); Sat, 28 Oct 2023 03:18:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229712AbjJ1HSy (ORCPT ); Sat, 28 Oct 2023 03:18:54 -0400 Received: from smtprelay08.ispgateway.de (smtprelay08.ispgateway.de [134.119.228.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6950B126; Sat, 28 Oct 2023 00:18:46 -0700 (PDT) Received: from [92.206.139.21] (helo=note-book.lan) by smtprelay08.ispgateway.de with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.1) (envelope-from ) id 1qwdal-0002T7-1R; Sat, 28 Oct 2023 09:18:43 +0200 From: =?utf-8?q?Andr=C3=A9_Apitzsch?= Date: Sat, 28 Oct 2023 09:17:47 +0200 Subject: [PATCH v2 4/5] media: i2c: imx214: Add sensor's pixel matrix size MIME-Version: 1.0 Message-Id: <20231028-imx214-v2-4-69a8fb730d6e@apitzsch.eu> References: <20231028-imx214-v2-0-69a8fb730d6e@apitzsch.eu> In-Reply-To: <20231028-imx214-v2-0-69a8fb730d6e@apitzsch.eu> To: Ricardo Ribalda , Sakari Ailus , Mauro Carvalho Chehab Cc: Kieran Bingham , Jacopo Mondi , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, =?utf-8?q?Andr=C3=A9_Apitzsch?= X-Mailer: b4 0.12.3 X-Df-Sender: YW5kcmVAYXBpdHpzY2guZXU= Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Set effective and active sensor pixel sizes as shown in product brief[1]. [1]: https://www.mouser.com/datasheet/2/897/ProductBrief_IMX214_20150428-1289331.pdf Reviewed-by: Jacopo Mondi Signed-off-by: André Apitzsch --- drivers/media/i2c/imx214.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/drivers/media/i2c/imx214.c b/drivers/media/i2c/imx214.c index 574878e8c97d..e0d9624a9d3f 100644 --- a/drivers/media/i2c/imx214.c +++ b/drivers/media/i2c/imx214.c @@ -36,6 +36,14 @@ #define IMX214_EXPOSURE_STEP 1 #define IMX214_EXPOSURE_DEFAULT 3184 +/* IMX214 native and active pixel array size */ +#define IMX214_NATIVE_WIDTH 4224U +#define IMX214_NATIVE_HEIGHT 3136U +#define IMX214_PIXEL_ARRAY_LEFT 8U +#define IMX214_PIXEL_ARRAY_TOP 8U +#define IMX214_PIXEL_ARRAY_WIDTH 4208U +#define IMX214_PIXEL_ARRAY_HEIGHT 3120U + static const char * const imx214_supply_name[] = { "vdda", "vddd", @@ -634,14 +642,31 @@ static int imx214_get_selection(struct v4l2_subdev *sd, { struct imx214 *imx214 = to_imx214(sd); - if (sel->target != V4L2_SEL_TGT_CROP) - return -EINVAL; + switch (sel->target) { + case V4L2_SEL_TGT_CROP: + mutex_lock(&imx214->mutex); + sel->r = *__imx214_get_pad_crop(imx214, sd_state, sel->pad, + sel->which); + mutex_unlock(&imx214->mutex); + return 0; - mutex_lock(&imx214->mutex); - sel->r = *__imx214_get_pad_crop(imx214, sd_state, sel->pad, - sel->which); - mutex_unlock(&imx214->mutex); - return 0; + case V4L2_SEL_TGT_NATIVE_SIZE: + sel->r.top = 0; + sel->r.left = 0; + sel->r.width = IMX214_NATIVE_WIDTH; + sel->r.height = IMX214_NATIVE_HEIGHT; + return 0; + + case V4L2_SEL_TGT_CROP_DEFAULT: + case V4L2_SEL_TGT_CROP_BOUNDS: + sel->r.top = IMX214_PIXEL_ARRAY_TOP; + sel->r.left = IMX214_PIXEL_ARRAY_LEFT; + sel->r.width = IMX214_PIXEL_ARRAY_WIDTH; + sel->r.height = IMX214_PIXEL_ARRAY_HEIGHT; + return 0; + } + + return -EINVAL; } static int imx214_entity_init_cfg(struct v4l2_subdev *subdev,