From patchwork Mon Feb 20 12:40:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 655897 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 A6BC0C05027 for ; Mon, 20 Feb 2023 12:41:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231685AbjBTMlB (ORCPT ); Mon, 20 Feb 2023 07:41:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231618AbjBTMk7 (ORCPT ); Mon, 20 Feb 2023 07:40:59 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E501E166D5 for ; Mon, 20 Feb 2023 04:40:57 -0800 (PST) Received: from uno.homenet.telecomitalia.it (host-95-252-227-22.retail.telecomitalia.it [95.252.227.22]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 05D68A49; Mon, 20 Feb 2023 13:40:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1676896855; bh=/kCfs/Pr2oFXj4liOan4pGUL+3WJnLULGz8/u1dP9Zk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C9OV0FblYbOqYhGsrIUQqEIt9CMT1Cvi+kHoAgM0qqiSkd0S2wOuUbeRal0/6Gbbq RcAn6DIvnxoTUz/k8zJWnI6QRgV4ggeAEESGLt+0KQBBBPsp1xObnRoxGQCDPq8vBM 8z/jduwRlb4VXa8X9bWH2V+yaPLj6cIEoyUiskGk= From: Jacopo Mondi To: Mikhail Rudenko , Dave Stevenson , Laurent Pinchart , Sakari Ailus Cc: Valentine Barshak , linux-media@vger.kernel.org, Jacopo Mondi Subject: [PATCH 1/2] media: i2c: ov5647: Add test pattern control Date: Mon, 20 Feb 2023 13:40:41 +0100 Message-Id: <20230220124041.1010289-1-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230219180334.980950-1-jacopo.mondi@ideasonboard.com> References: <20230219180334.980950-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Valentine Barshak This adds V4L2_CID_TEST_PATTERN control support. Signed-off-by: Valentine Barshak Signed-off-by: Jacopo Mondi --- drivers/media/i2c/ov5647.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) -- 2.39.0 diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c index 847a7bbb69c5..0b88ac6dee41 100644 --- a/drivers/media/i2c/ov5647.c +++ b/drivers/media/i2c/ov5647.c @@ -58,6 +58,7 @@ #define OV5647_REG_MIPI_CTRL00 0x4800 #define OV5647_REG_MIPI_CTRL14 0x4814 #define OV5647_REG_AWB 0x5001 +#define OV5647_REG_ISPCTRL3D 0x503d #define REG_TERM 0xfffe #define VAL_TERM 0xfe @@ -116,6 +117,22 @@ static inline struct ov5647 *to_sensor(struct v4l2_subdev *sd) return container_of(sd, struct ov5647, sd); } +static const char * const ov5647_test_pattern_menu[] = { + "Disabled", + "Color Bars", + "Color Squares", + "Random Data", + "Input Data" +}; + +static u8 ov5647_test_pattern_val[] = { + 0x00, /* Disabled */ + 0x80, /* Color Bars */ + 0x82, /* Color Squares */ + 0x81, /* Random Data */ + 0x83, /* Input Data */ +}; + static const struct regval_list sensor_oe_disable_regs[] = { {0x3000, 0x00}, {0x3001, 0x00}, @@ -1242,6 +1259,10 @@ static int ov5647_s_ctrl(struct v4l2_ctrl *ctrl) ret = ov5647_write16(sd, OV5647_REG_VTS_HI, sensor->mode->format.height + ctrl->val); break; + case V4L2_CID_TEST_PATTERN: + ret = ov5647_write(sd, OV5647_REG_ISPCTRL3D, + ov5647_test_pattern_val[ctrl->val]); + break; /* Read-only, but we adjust it based on mode. */ case V4L2_CID_PIXEL_RATE: @@ -1270,7 +1291,7 @@ static int ov5647_init_controls(struct ov5647 *sensor) struct i2c_client *client = v4l2_get_subdevdata(&sensor->sd); int hblank, exposure_max, exposure_def; - v4l2_ctrl_handler_init(&sensor->ctrls, 8); + v4l2_ctrl_handler_init(&sensor->ctrls, 9); v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops, V4L2_CID_AUTOGAIN, 0, 1, 1, 0); @@ -1314,6 +1335,11 @@ static int ov5647_init_controls(struct ov5647 *sensor) sensor->mode->vts - sensor->mode->format.height); + v4l2_ctrl_new_std_menu_items(&sensor->ctrls, &ov5647_ctrl_ops, + V4L2_CID_TEST_PATTERN, + ARRAY_SIZE(ov5647_test_pattern_menu) - 1, + 0, 0, ov5647_test_pattern_menu); + if (sensor->ctrls.error) goto handler_free; From patchwork Mon Feb 20 12:41:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 655276 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 AE741C05027 for ; Mon, 20 Feb 2023 12:41:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231817AbjBTMlJ (ORCPT ); Mon, 20 Feb 2023 07:41:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231857AbjBTMlI (ORCPT ); Mon, 20 Feb 2023 07:41:08 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EEDC1B561 for ; Mon, 20 Feb 2023 04:41:07 -0800 (PST) Received: from uno.homenet.telecomitalia.it (host-95-252-227-22.retail.telecomitalia.it [95.252.227.22]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8653AA49; Mon, 20 Feb 2023 13:41:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1676896866; bh=rujmqGnJ/oR37BjpbMq5yAQrfqhHliE+cxkopZk4rrk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OIvDQhJVXSdT8rp1OF6Zf8A0IKyYrUwvKQ/Y4rCYbcx2+tEA22Oy14zuAvoe/k2hz 1j5SBf7NRoldrDRC87tbVRmPC+FK6gmSH8OCDQXRkJ994jWgFwL5Hhk3+UdG6CmExo FzCxeVEZWsBwUjQCre3bmbymDLX4jUzuI2OyZzMk= From: Jacopo Mondi To: Mikhail Rudenko , Dave Stevenson , Laurent Pinchart , Sakari Ailus Cc: Jacopo Mondi , linux-media@vger.kernel.org Subject: [PATCH 2/2] media: i2c: ov5647: Use bus-locked i2c_transfer() Date: Mon, 20 Feb 2023 13:41:01 +0100 Message-Id: <20230220124101.1010317-1-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230219180334.980950-1-jacopo.mondi@ideasonboard.com> References: <20230219180334.980950-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The ov5647_read() functions calls i2c_master_send() and i2c_master_read() in sequence. However this leaves space for other clients to contend the bus and insert a unrelated transaction in between the two calls. Replace the two calls with a single i2c_transfer() one, that locks the bus in between the transactions. Signed-off-by: Jacopo Mondi Reviewed-by: Tommaso Merciai Reviewed-by: Dave Stevenson --- drivers/media/i2c/ov5647.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) -- 2.39.0 diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c index 0b88ac6dee41..a423ee8fe20c 100644 --- a/drivers/media/i2c/ov5647.c +++ b/drivers/media/i2c/ov5647.c @@ -631,23 +631,29 @@ static int ov5647_write(struct v4l2_subdev *sd, u16 reg, u8 val) static int ov5647_read(struct v4l2_subdev *sd, u16 reg, u8 *val) { - unsigned char data_w[2] = { reg >> 8, reg & 0xff }; struct i2c_client *client = v4l2_get_subdevdata(sd); + u8 buf[2] = { reg >> 8, reg & 0xff }; + struct i2c_msg msg[2]; int ret; - ret = i2c_master_send(client, data_w, 2); + msg[0].addr = client->addr; + msg[0].flags = client->flags; + msg[0].buf = buf; + msg[0].len = sizeof(buf); + + msg[1].addr = client->addr; + msg[1].flags = client->flags | I2C_M_RD; + msg[1].buf = buf; + msg[1].len = 1; + + ret = i2c_transfer(client->adapter, msg, 2); if (ret < 0) { - dev_dbg(&client->dev, "%s: i2c write error, reg: %x\n", + dev_err(&client->dev, "%s: i2c read error, reg: %x\n", __func__, reg); return ret; } - ret = i2c_master_recv(client, val, 1); - if (ret < 0) { - dev_dbg(&client->dev, "%s: i2c read error, reg: %x\n", - __func__, reg); - return ret; - } + *val = buf[0]; return 0; }