From patchwork Thu Jan 26 12:46:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 647886 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 C167AC54E94 for ; Thu, 26 Jan 2023 12:47:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235633AbjAZMrC (ORCPT ); Thu, 26 Jan 2023 07:47:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235500AbjAZMrB (ORCPT ); Thu, 26 Jan 2023 07:47:01 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B482D3C29E for ; Thu, 26 Jan 2023 04:46:59 -0800 (PST) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 40484D77; Thu, 26 Jan 2023 13:46:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1674737214; bh=lsOhnBsueJT5+Vnq0iApg4VIEcToEChO3dFh+KQmPoQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HUDuTHbo5Cnpuym3GRLH9QKuvh9RuWaGh5fFu8fhqr+eRO57DmtbwTH0CGpBuJ16a Ggm2E1BncyXNDjxT7Vsj+Q8+OEgBXQOVHhX8lZAqXAm1XVkKqFc4ksukbgq7xCLf2j h8E9HXH7nwBIQN+9ALNgNFCXzMXd/z4h7HO5q5GY= From: Jacopo Mondi To: Chiranjeevi Rapolu , Luca Weiss Cc: Jacopo Mondi , laurent.pinchart@ideasonboard.com, sakari.ailus@iki.fi, Mauro Carvalho Chehab , linux-media@vger.kernel.org Subject: [PATCH v5 2/9] media: i2c: ov5670: Allow probing with OF Date: Thu, 26 Jan 2023 13:46:25 +0100 Message-Id: <20230126124632.45842-3-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230126124632.45842-1-jacopo.mondi@ideasonboard.com> References: <20230126124632.45842-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The ov5670 driver currently only supports probing using ACPI matching. Add support for OF and add a missing header inclusion. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- drivers/media/i2c/ov5670.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/media/i2c/ov5670.c b/drivers/media/i2c/ov5670.c index bc9fc3bc90c2..07a396c8ab68 100644 --- a/drivers/media/i2c/ov5670.c +++ b/drivers/media/i2c/ov5670.c @@ -3,7 +3,9 @@ #include #include +#include #include +#include #include #include #include @@ -2583,11 +2585,18 @@ static const struct acpi_device_id ov5670_acpi_ids[] = { MODULE_DEVICE_TABLE(acpi, ov5670_acpi_ids); #endif +static const struct of_device_id ov5670_of_ids[] = { + { .compatible = "ovti,ov5670" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, ov5670_of_ids); + static struct i2c_driver ov5670_i2c_driver = { .driver = { .name = "ov5670", .pm = &ov5670_pm_ops, .acpi_match_table = ACPI_PTR(ov5670_acpi_ids), + .of_match_table = ov5670_of_ids, }, .probe_new = ov5670_probe, .remove = ov5670_remove, From patchwork Thu Jan 26 12:46:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 647885 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 9866AC61DA3 for ; Thu, 26 Jan 2023 12:47:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236266AbjAZMrH (ORCPT ); Thu, 26 Jan 2023 07:47:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236013AbjAZMrE (ORCPT ); Thu, 26 Jan 2023 07:47:04 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3BB56226D for ; Thu, 26 Jan 2023 04:47:02 -0800 (PST) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 09E781280; Thu, 26 Jan 2023 13:46:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1674737216; bh=BycciKnCJJNO55QmqQMo4O3x4cDe5k+KPzmD9tgvbvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b9bYes9tT8WTBueo3DsGxbbCZ5YSeyLy2elWEb4ZMa3nhrRPC+giYEJWL/NZPlIQQ 8V3ee/4ML+WzD8Dau7WCSZQmcfeBiHIuJrT5uMK6s6IasQczv87BUvPRDn+U3C/+OE +/Wk6jtpsLs2ewQIiQF+5vZG69Nykjt0RhXnwg98= From: Jacopo Mondi To: Chiranjeevi Rapolu , Luca Weiss Cc: Jacopo Mondi , laurent.pinchart@ideasonboard.com, sakari.ailus@iki.fi, Mauro Carvalho Chehab , linux-media@vger.kernel.org Subject: [PATCH v5 5/9] media: i2c: ov5670: Probe GPIOs Date: Thu, 26 Jan 2023 13:46:28 +0100 Message-Id: <20230126124632.45842-6-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230126124632.45842-1-jacopo.mondi@ideasonboard.com> References: <20230126124632.45842-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The OV5670 has a powerdown and reset pin, named respectively "PWDN" and "XSHUTDOWN". Optionally probe the gpios connected to the pins during the driver probe routine. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- drivers/media/i2c/ov5670.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/media/i2c/ov5670.c b/drivers/media/i2c/ov5670.c index 95bdbf628556..6843b2d9a2d4 100644 --- a/drivers/media/i2c/ov5670.c +++ b/drivers/media/i2c/ov5670.c @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -1843,6 +1844,10 @@ struct ov5670 { /* Regulators */ struct regulator_bulk_data supplies[OV5670_NUM_SUPPLIES]; + /* Power-down and reset gpios. */ + struct gpio_desc *pwdn_gpio; /* PWDNB pin. */ + struct gpio_desc *reset_gpio; /* XSHUTDOWN pin. */ + /* To serialize asynchronus callbacks */ struct mutex mutex; @@ -2495,6 +2500,23 @@ static int ov5670_regulators_probe(struct ov5670 *ov5670) ov5670->supplies); } +static int ov5670_gpio_probe(struct ov5670 *ov5670) +{ + struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); + + ov5670->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "powerdown", + GPIOD_OUT_LOW); + if (IS_ERR(ov5670->pwdn_gpio)) + return PTR_ERR(ov5670->pwdn_gpio); + + ov5670->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", + GPIOD_OUT_LOW); + if (IS_ERR(ov5670->reset_gpio)) + return PTR_ERR(ov5670->reset_gpio); + + return 0; +} + static int ov5670_probe(struct i2c_client *client) { struct ov5670 *ov5670; @@ -2539,6 +2561,12 @@ static int ov5670_probe(struct i2c_client *client) goto error_print; } + ret = ov5670_gpio_probe(ov5670); + if (ret) { + err_msg = "GPIO probe failed"; + goto error_print; + } + full_power = acpi_dev_state_d0(&client->dev); if (full_power) { /* Check module identity */ From patchwork Thu Jan 26 12:46:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 647884 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 8051EC61DA2 for ; Thu, 26 Jan 2023 12:47:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236609AbjAZMrU (ORCPT ); Thu, 26 Jan 2023 07:47:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232925AbjAZMrQ (ORCPT ); Thu, 26 Jan 2023 07:47:16 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 158F76C100 for ; Thu, 26 Jan 2023 04:47:06 -0800 (PST) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 32FC612EF; Thu, 26 Jan 2023 13:46:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1674737217; bh=lrr6L5YLONkNwE9d9XUrOKsFugVnbmXQItS0mH4vxtc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vla/DuaqPEN9KdxZOUMeS6gzbBJ6GJnoc+AfMBWN0t0vgj+LJWzHK+mOyNkQb5WZS IlmrMFxVHbovuGZzKzbCmRBzvgIO/0gnD2JaTKe61lO9zOZd4cnspGMjuc9le9HpVC AgOfPVuzyhVlFvBIrC3LvERs7O0H4dXz7uqrHo7I= From: Jacopo Mondi To: Chiranjeevi Rapolu , Luca Weiss Cc: Jacopo Mondi , laurent.pinchart@ideasonboard.com, sakari.ailus@iki.fi, Mauro Carvalho Chehab , linux-media@vger.kernel.org Subject: [PATCH v5 7/9] media: i2c: ov5670: Implement init_cfg Date: Thu, 26 Jan 2023 13:46:30 +0100 Message-Id: <20230126124632.45842-8-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230126124632.45842-1-jacopo.mondi@ideasonboard.com> References: <20230126124632.45842-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Implement the .init_cfg() pad operation and initialize the default format with the default full resolution mode 2592x1944. With .init_cfg() pad operation implemented the deprecated .open() internal operation can now be dropped. Signed-off-by: Jacopo Mondi --- drivers/media/i2c/ov5670.c | 46 +++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/drivers/media/i2c/ov5670.c b/drivers/media/i2c/ov5670.c index 12091a5c992e..8f4350898b36 100644 --- a/drivers/media/i2c/ov5670.c +++ b/drivers/media/i2c/ov5670.c @@ -1962,27 +1962,6 @@ static int ov5670_write_reg_list(struct ov5670 *ov5670, return ov5670_write_regs(ov5670, r_list->regs, r_list->num_of_regs); } -/* Open sub-device */ -static int ov5670_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) -{ - struct ov5670 *ov5670 = to_ov5670(sd); - struct v4l2_mbus_framefmt *try_fmt = - v4l2_subdev_get_try_format(sd, fh->state, 0); - - mutex_lock(&ov5670->mutex); - - /* Initialize try_fmt */ - try_fmt->width = ov5670->cur_mode->width; - try_fmt->height = ov5670->cur_mode->height; - try_fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10; - try_fmt->field = V4L2_FIELD_NONE; - - /* No crop or compose */ - mutex_unlock(&ov5670->mutex); - - return 0; -} - static int ov5670_update_digital_gain(struct ov5670 *ov5670, u32 d_gain) { int ret; @@ -2182,6 +2161,25 @@ static int ov5670_init_controls(struct ov5670 *ov5670) return ret; } +static int ov5670_init_cfg(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state) +{ + struct v4l2_mbus_framefmt *fmt = + v4l2_subdev_get_try_format(sd, state, 0); + const struct ov5670_mode *default_mode = &supported_modes[0]; + + fmt->width = default_mode->width; + fmt->height = default_mode->height; + fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10; + fmt->field = V4L2_FIELD_NONE; + fmt->colorspace = V4L2_COLORSPACE_SRGB; + fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(V4L2_COLORSPACE_SRGB); + fmt->quantization = V4L2_QUANTIZATION_FULL_RANGE; + fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(V4L2_COLORSPACE_SRGB); + + return 0; +} + static int ov5670_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_mbus_code_enum *code) @@ -2512,6 +2510,7 @@ static const struct v4l2_subdev_video_ops ov5670_video_ops = { }; static const struct v4l2_subdev_pad_ops ov5670_pad_ops = { + .init_cfg = ov5670_init_cfg, .enum_mbus_code = ov5670_enum_mbus_code, .get_fmt = ov5670_get_pad_format, .set_fmt = ov5670_set_pad_format, @@ -2533,10 +2532,6 @@ static const struct media_entity_operations ov5670_subdev_entity_ops = { .link_validate = v4l2_subdev_link_validate, }; -static const struct v4l2_subdev_internal_ops ov5670_internal_ops = { - .open = ov5670_open, -}; - static int ov5670_regulators_probe(struct ov5670 *ov5670) { struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); @@ -2645,7 +2640,6 @@ static int ov5670_probe(struct i2c_client *client) goto error_mutex_destroy; } - ov5670->sd.internal_ops = &ov5670_internal_ops; ov5670->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; ov5670->sd.entity.ops = &ov5670_subdev_entity_ops; From patchwork Thu Jan 26 12:46:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 647883 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 EC273C61DA7 for ; Thu, 26 Jan 2023 12:47:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236807AbjAZMre (ORCPT ); Thu, 26 Jan 2023 07:47:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236591AbjAZMrT (ORCPT ); Thu, 26 Jan 2023 07:47:19 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 990986E412 for ; Thu, 26 Jan 2023 04:47:10 -0800 (PST) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6D0FA1817; Thu, 26 Jan 2023 13:46:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1674737218; bh=MAQqT4UAk1AKtvkJYkZrjFjo5/jBx2Y9heJD2iSy4/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DF+Z6YFdz8o0u0AFbH3pfyivS00ulvW9Mv2kxWIdtwwCobXH2lZBZhPllTDxDvrHf LEdC5eLa9K65/8bzo3xHmmy7QYdBYCXzRRTX4XcHsETljRmgO+cNq+2lwK2OrOL5ZB ACfetklyhFfwvhib4wJ7qAw/zh72cABLHGR3xp8Q= From: Jacopo Mondi To: Chiranjeevi Rapolu , Luca Weiss Cc: Jacopo Mondi , laurent.pinchart@ideasonboard.com, sakari.ailus@iki.fi, Mauro Carvalho Chehab , linux-media@vger.kernel.org Subject: [PATCH v5 9/9] media: i2c: ov5670: Handle RO controls in set_ctrl Date: Thu, 26 Jan 2023 13:46:32 +0100 Message-Id: <20230126124632.45842-10-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230126124632.45842-1-jacopo.mondi@ideasonboard.com> References: <20230126124632.45842-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The ov5670 driver registers three controls as read-only: - V4L2_CID_PIXEL_RATE - V4L2_CID_LINK_FREQ - V4L2_CID_HBLANK The driver updates the range of HBLANK with __v4l2_ctrl_modify_range() and updates the values of PIXEL_RATE and LINK_FREQ with an explicit call to __v4l2_ctrl_s_ctrl() in ov5670_set_pad_format() time. This causes the .set_ctrl handler to be called on these controls causing a non-fatal warning to be emitted: ov5670_set_ctrl Unhandled id:0x9e0902, val:0x824 This is currently only critical for HBLANK, as LINK_FREQ and PIXEL_RATE currently only support a single value, and the v4l2-ctrl framework skips calling .set_ctrl() if the current control value is not changed. Expand the ov5670_set_ctrl() callback to handle the above controls to remove the above warning and defend against future expansions of the supported pixel rates and link frequencies. Also be stricter and return an error value if a control is actually not handled. Reported-by: Luca Weiss Signed-off-by: Jacopo Mondi --- drivers/media/i2c/ov5670.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/ov5670.c b/drivers/media/i2c/ov5670.c index 8655993ee9b0..a8116ad2cdc3 100644 --- a/drivers/media/i2c/ov5670.c +++ b/drivers/media/i2c/ov5670.c @@ -2038,7 +2038,7 @@ static int ov5670_set_ctrl(struct v4l2_ctrl *ctrl) struct ov5670, ctrl_handler); struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); s64 max; - int ret = 0; + int ret; /* Propagate change of current control to all related controls */ switch (ctrl->id) { @@ -2077,7 +2077,13 @@ static int ov5670_set_ctrl(struct v4l2_ctrl *ctrl) case V4L2_CID_TEST_PATTERN: ret = ov5670_enable_test_pattern(ov5670, ctrl->val); break; + case V4L2_CID_HBLANK: + case V4L2_CID_LINK_FREQ: + case V4L2_CID_PIXEL_RATE: + ret = 0; + break; default: + ret = -EINVAL; dev_info(&client->dev, "%s Unhandled id:0x%x, val:0x%x\n", __func__, ctrl->id, ctrl->val); break;