media: i2c: Add OV05C camera sensor driver
Subsystems (2)
PATCH 1/1 media: i2c: Add OV05C camera sensor driver
Add driver for OmniVision 5.2M OV05C10 sensor. This driver supports only the full size normal 2888x1808@30fps 2-lane sensor profile.
--- drivers/media/i2c/Kconfig | 10 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/ov05c.c | 1031 ++++++++++++++++++++++++++++++++++++ 3 files changed, 1042 insertions(+) create mode 100644 drivers/media/i2c/ov05c.c
drivers/media/i2c/Kconfig +10 -0
@@ -337,6 +337,16 @@ config VIDEO_OG01A1B To compile this driver as a module, choose M here: the module will be called og01a1b. +config VIDEO_OV05C + tristate "OmniVision OV05 sensor support" + select V4L2_CCI_I2C + help + This is a Video4Linux2 sensor driver for the OmniVision + OV05C camera. + + To compile this driver as a module, choose M here: the + module will be called OV05C. + config VIDEO_OV01A10 tristate "OmniVision OV01A10 sensor support" help
drivers/media/i2c/Makefile +1 -0
@@ -80,6 +80,7 @@ obj-$(CONFIG_VIDEO_MT9V011) += mt9v011.o obj-$(CONFIG_VIDEO_MT9V032) += mt9v032.o obj-$(CONFIG_VIDEO_MT9V111) += mt9v111.o obj-$(CONFIG_VIDEO_OG01A1B) += og01a1b.o +obj-$(CONFIG_VIDEO_OV05C) += ov05c.o obj-$(CONFIG_VIDEO_OV01A10) += ov01a10.o obj-$(CONFIG_VIDEO_OV02A10) += ov02a10.o obj-$(CONFIG_VIDEO_OV08D10) += ov08d10.o
drivers/media/i2c/ov05c.c new file +1031 -0
1,031 lines not on this page · raw message
Signature · 1 line
2.43.0
Hi Pratap,
Thank you for the patch.
A few assorted comments to start with, I'll try to do a more in-depth review later.
Quoted 3 lines · Pratap Nirujogi
Add driver for OmniVision 5.2M OV05C10 sensor. This driver supports only the full size normal 2888x1808@30fps 2-lane sensor profile.
What have you tested this driver with ? I see no OF device ID or ACPI device ID.
Please provide a v4l2-compliance report.
Quoted 5 lines
Signed-off-by Pratap Nirujogi <[email protected]>--- drivers/media/i2c/Kconfig | 10 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/ov05c.c | 1031 ++++++++++++++++++++++++++++++++++++
Please add an entry in the MAINTAINERS file.
drivers/media/i2c/Kconfig config VIDEO_OG01A1B · line 340
Quoted 12 lines
3 files changed, 1042 insertions(+) create mode 100644 drivers/media/i2c/ov05c.cdrivers/media/i2c/Kconfig +1
-0@@ -337,6 +337,16 @@ config VIDEO_OG01A1B To compile this driver as a module, choose M here: the module will be called og01a1b. +config VIDEO_OV05C
Please sort entries alphabetically.
Quoted 17 lines
drivers/media/i2c/Kconfig +9
-0+ tristate "OmniVision OV05 sensor support" + select V4L2_CCI_I2C + help + This is a Video4Linux2 sensor driver for the OmniVision + OV05C camera. + + To compile this driver as a module, choose M here: the + module will be called OV05C. + config VIDEO_OV01A10 tristate "OmniVision OV01A10 sensor support" helpdrivers/media/i2c/Makefile +0
-0
drivers/media/i2c/Makefile obj-$(CONFIG_VIDEO_MT9V011) += mt9v011.o · line 83
Quoted 4 lines
drivers/media/i2c/Makefile +1
-0@@ -80,6 +80,7 @@ obj-$(CONFIG_VIDEO_MT9V011) += mt9v011.o obj-$(CONFIG_VIDEO_MT9V032) += mt9v032.o obj-$(CONFIG_VIDEO_MT9V111) += mt9v111.o obj-$(CONFIG_VIDEO_OG01A1B) += og01a1b.o +obj-$(CONFIG_VIDEO_OV05C) += ov05c.o
Here too.
drivers/media/i2c/ov05c.c line 1
Quoted 10 lines
drivers/media/i2c/Makefile +0
-0obj-$(CONFIG_VIDEO_OV01A10) += ov01a10.o obj-$(CONFIG_VIDEO_OV02A10) += ov02a10.o obj-$(CONFIG_VIDEO_OV08D10) += ov08d10.odrivers/media/i2c/ov05c.c new file +1
-0@@ -0,0 +1,1031 @@ +/* SPDX-License-Identifier: MIT */
Why not GPL-2.0 ?
Quoted 13 lines
drivers/media/i2c/ov05c.c new file +13
-0+/* +* Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. +* All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sub license, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice (including the
drivers/media/i2c/ov05c.c line 24
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+* next paragraph) shall be included in all copies or substantial portions +* of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +* USE OR OTHER DEALINGS IN THE SOFTWARE.
Drop all this (except the copyright line), it's conveyed by the SPDX tag.
drivers/media/i2c/ov05c.c line 28
Quoted 4 lines
drivers/media/i2c/ov05c.c new file +4
-0+* +*/ + +#include <linux/acpi.h>
This doesn't seem to be used.
drivers/media/i2c/ov05c.c line 31
Quoted 3 lines
drivers/media/i2c/ov05c.c new file +3
-0+#include <linux/i2c.h> +#include <linux/module.h> +#include <linux/delay.h>
Alphabetical order please.
drivers/media/i2c/ov05c.c line 38
Quoted 7 lines
drivers/media/i2c/ov05c.c new file +7
-0+#include <linux/units.h> +#include <linux/pm_runtime.h> +#include <linux/gpio.h> +#include <media/v4l2-ctrls.h> +#include <media/v4l2-device.h> +#include <media/v4l2-fwnode.h> +#include <media/v4l2-cci.h>
Thanks for using the CCI helpers :-)
drivers/media/i2c/ov05c.c line 47
Quoted 9 lines
drivers/media/i2c/ov05c.c new file +9
-0+ +#define DRV_NAME "ov05c" + +/* Chip ID */ +#define OV05C_REG_CHIP_ID CCI_REG24(0x00) +#define OV05C_CHIP_ID 0x430556 + +/* Control registers */ +#define OV05C_REG_PAGE_CTL CCI_REG8(0xFD)
V4L2 spells hex constants in lower case.
Quoted 32 lines
drivers/media/i2c/ov05c.c new file +32
-0+#define OV05C_REG_TRIGGER CCI_REG8(0x01) + +/* V_TIMING internal */ +#define OV05C_REG_VTS CCI_REG16(0x05) +#define OV05C_VTS_30FPS 1860 +#define OV05C_VTS_MAX 0x7fff + +/* H TIMING internal */ +#define OV05C_REG_HTS CCI_REG16(0x37) +#define OV05C_HTS_30FPS 0x0280 + +/* Exposure control */ +#define OV05C_REG_EXPOSURE CCI_REG24(0x02) +#define OV05C_EXPOSURE_MAX_MARGIN 33 +#define OV05C_EXPOSURE_MIN 4 +#define OV05C_EXPOSURE_STEP 1 +#define OV05C_EXPOSURE_DEFAULT 0x40 + +/* Analog gain control */ +#define OV05C_REG_ANALOG_GAIN CCI_REG8(0x24) +#define OV05C_ANA_GAIN_MIN 0x80 +#define OV05C_ANA_GAIN_MAX 0x07c0 +#define OV05C_ANA_GAIN_STEP 1 +#define OV05C_ANA_GAIN_DEFAULT 0x80 + +/* Digital gain control */ +#define OV05C_REG_DGTL_GAIN_H CCI_REG8(0x21) +#define OV05C_REG_DGTL_GAIN_L CCI_REG8(0x22) + +#define OV05C_DGTL_GAIN_MIN 64/* Min = 1 X */ +#define OV05C_DGTL_GAIN_MAX (256 - 1)/* Max = 4 X */ +#define OV05C_DGTL_GAIN_DEFAULT 0x80/* Default gain = 2x */
drivers/media/i2c/ov05c.c line 89
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+#define OV05C_DGTL_GAIN_STEP 1/* Each step = 1/64 */ + +#define OV05C_DGTL_GAIN_L_MASK 0xFF +#define OV05C_DGTL_GAIN_H_SHIFT 8 +#define OV05C_DGTL_GAIN_H_MASK 0xFF00 + +/* Test Pattern Control */ +#define OV05C_REG_TEST_PATTERN_CTL CCI_REG8(0xF3) +#define OV05C_REG_TEST_PATTERN CCI_REG8(0x12) +#define OV05C_TEST_PATTERN_ENABLE BIT(0)
Could you please sort registers by their numerical address ?
drivers/media/i2c/ov05c.c line 91
Quoted 2 lines
drivers/media/i2c/ov05c.c new file +2
-0+ +#define NUM_OF_PADS 3
Why three pads ? The driver doesn't seem to make a distinction between them.
Quoted 216 lines
drivers/media/i2c/ov05c.c new file +216
-0+ +enum { +OV05C_LINK_FREQ_900MHZ_INDEX , +}; + +struct ov05c_reg_list { +u32 num_of_regs; +const struct cci_reg_sequence *regs; +}; + +/* Link frequency config */ +struct ov05c_link_freq_config { +/* registers for this link frequency */ +struct ov05c_reg_list reg_list; +}; + +/* Mode : resolution and related config&values */ +struct ov05c_mode { +/* Frame width */ +u32 width; +/* Frame height */ +u32 height; +/* number of lanes */ +u32 lanes; + +/* V-timing */ +u32 vts_def; +u32 vts_min; + +/* HTS */ +u32 hts; + +/* Index of Link frequency config to be used */ +u32 link_freq_index; + +/* Default register values */ +struct ov05c_reg_list reg_list; +}; + +static const struct cci_reg_sequence + mode_2888_1808_30fps_1800mbps_2lane_24mhz_regs[] = { + {CCI_REG8 (0xfd ),0x00 }, + {CCI_REG8 (0x20 ),0x00 }, + {CCI_REG8 (0xfd ),0x00 }, + {CCI_REG8 (0x20 ),0x0b }, + {CCI_REG8 (0xc1 ),0x09 }, + {CCI_REG8 (0x21 ),0x06 }, + {CCI_REG8 (0x14 ),0x78 }, + {CCI_REG8 (0xe7 ),0x03 }, + {CCI_REG8 (0xe7 ),0x00 }, + {CCI_REG8 (0x21 ),0x00 }, + {CCI_REG8 (0xfd ),0x01 }, + {CCI_REG8 (0x03 ),0x00 }, + {CCI_REG8 (0x04 ),0x06 }, + {CCI_REG8 (0x05 ),0x07 }, + {CCI_REG8 (0x06 ),0x44 }, + {CCI_REG8 (0x07 ),0x08 }, + {CCI_REG8 (0x1b ),0x01 }, + {CCI_REG8 (0x24 ),0xff }, + {CCI_REG8 (0x32 ),0x03 }, + {CCI_REG8 (0x42 ),0x5d }, + {CCI_REG8 (0x43 ),0x08 }, + {CCI_REG8 (0x44 ),0x81 }, + {CCI_REG8 (0x46 ),0x5f }, + {CCI_REG8 (0x48 ),0x18 }, + {CCI_REG8 (0x49 ),0x04 }, + {CCI_REG8 (0x5c ),0x18 }, + {CCI_REG8 (0x5e ),0x13 }, + {CCI_REG8 (0x70 ),0x15 }, + {CCI_REG8 (0x77 ),0x35 }, + {CCI_REG8 (0x79 ),0x00 }, + {CCI_REG8 (0x7b ),0x08 }, + {CCI_REG8 (0x7d ),0x08 }, + {CCI_REG8 (0x7e ),0x08 }, + {CCI_REG8 (0x7f ),0x08 }, + {CCI_REG8 (0x90 ),0x37 }, + {CCI_REG8 (0x91 ),0x05 }, + {CCI_REG8 (0x92 ),0x18 }, + {CCI_REG8 (0x93 ),0x27 }, + {CCI_REG8 (0x94 ),0x05 }, + {CCI_REG8 (0x95 ),0x38 }, + {CCI_REG8 (0x9b ),0x00 }, + {CCI_REG8 (0x9c ),0x06 }, + {CCI_REG8 (0x9d ),0x28 }, + {CCI_REG8 (0x9e ),0x06 }, + {CCI_REG8 (0xb2 ),0x0f }, + {CCI_REG8 (0xb3 ),0x29 }, + {CCI_REG8 (0xbf ),0x3c }, + {CCI_REG8 (0xc2 ),0x04 }, + {CCI_REG8 (0xc4 ),0x00 }, + {CCI_REG8 (0xca ),0x20 }, + {CCI_REG8 (0xcb ),0x20 }, + {CCI_REG8 (0xcc ),0x28 }, + {CCI_REG8 (0xcd ),0x28 }, + {CCI_REG8 (0xce ),0x20 }, + {CCI_REG8 (0xcf ),0x20 }, + {CCI_REG8 (0xd0 ),0x2a }, + {CCI_REG8 (0xd1 ),0x2a }, + {CCI_REG8 (0xfd ),0x0f }, + {CCI_REG8 (0x00 ),0x00 }, + {CCI_REG8 (0x01 ),0xa0 }, + {CCI_REG8 (0x02 ),0x48 }, + {CCI_REG8 (0x07 ),0x8f }, + {CCI_REG8 (0x08 ),0x70 }, + {CCI_REG8 (0x09 ),0x01 }, + {CCI_REG8 (0x0b ),0x40 }, + {CCI_REG8 (0x0d ),0x07 }, + {CCI_REG8 (0x11 ),0x33 }, + {CCI_REG8 (0x12 ),0x77 }, + {CCI_REG8 (0x13 ),0x66 }, + {CCI_REG8 (0x14 ),0x65 }, + {CCI_REG8 (0x15 ),0x37 }, + {CCI_REG8 (0x16 ),0xbf }, + {CCI_REG8 (0x17 ),0xff }, + {CCI_REG8 (0x18 ),0xff }, + {CCI_REG8 (0x19 ),0x12 }, + {CCI_REG8 (0x1a ),0x10 }, + {CCI_REG8 (0x1c ),0x77 }, + {CCI_REG8 (0x1d ),0x77 }, + {CCI_REG8 (0x20 ),0x0f }, + {CCI_REG8 (0x21 ),0x0f }, + {CCI_REG8 (0x22 ),0x0f }, + {CCI_REG8 (0x23 ),0x0f }, + {CCI_REG8 (0x2b ),0x20 }, + {CCI_REG8 (0x2c ),0x20 }, + {CCI_REG8 (0x2d ),0x04 }, + {CCI_REG8 (0xfd ),0x03 }, + {CCI_REG8 (0x9d ),0x0f }, + {CCI_REG8 (0x9f ),0x40 }, + {CCI_REG8 (0xfd ),0x00 }, + {CCI_REG8 (0x20 ),0x1b }, + {CCI_REG8 (0xfd ),0x04 }, + {CCI_REG8 (0x19 ),0x60 }, + {CCI_REG8 (0xfd ),0x02 }, + {CCI_REG8 (0x75 ),0x05 }, + {CCI_REG8 (0x7f ),0x06 }, + {CCI_REG8 (0x9a ),0x03 }, + {CCI_REG8 (0xa2 ),0x07 }, + {CCI_REG8 (0xa3 ),0x10 }, + {CCI_REG8 (0xa5 ),0x02 }, + {CCI_REG8 (0xa6 ),0x0b }, + {CCI_REG8 (0xa7 ),0x48 }, + {CCI_REG8 (0xfd ),0x07 }, + {CCI_REG8 (0x42 ),0x00 }, + {CCI_REG8 (0x43 ),0x80 }, + {CCI_REG8 (0x44 ),0x00 }, + {CCI_REG8 (0x45 ),0x80 }, + {CCI_REG8 (0x46 ),0x00 }, + {CCI_REG8 (0x47 ),0x80 }, + {CCI_REG8 (0x48 ),0x00 }, + {CCI_REG8 (0x49 ),0x80 }, + {CCI_REG8 (0x00 ),0xf7 }, + {CCI_REG8 (0xfd ),0x00 }, + {CCI_REG8 (0xe7 ),0x03 }, + {CCI_REG8 (0xe7 ),0x00 }, + {CCI_REG8 (0xfd ),0x00 }, + {CCI_REG8 (0x93 ),0x18 }, + {CCI_REG8 (0x94 ),0xff }, + {CCI_REG8 (0x95 ),0xbd }, + {CCI_REG8 (0x96 ),0x1a }, + {CCI_REG8 (0x98 ),0x04 }, + {CCI_REG8 (0x99 ),0x08 }, + {CCI_REG8 (0x9b ),0x10 }, + {CCI_REG8 (0x9c ),0x3f }, + {CCI_REG8 (0xa1 ),0x05 }, + {CCI_REG8 (0xa4 ),0x2f }, + {CCI_REG8 (0xc0 ),0x0c }, + {CCI_REG8 (0xc1 ),0x08 }, + {CCI_REG8 (0xc2 ),0x00 }, + {CCI_REG8 (0xb6 ),0x20 }, + {CCI_REG8 (0xbb ),0x80 }, + {CCI_REG8 (0xfd ),0x00 }, + {CCI_REG8 (0xa0 ),0x01 }, + {CCI_REG8 (0xfd ),0x01 }, +}; + +static const struct cci_reg_sequence mode_OV05C_stream_on_regs[] = { + {CCI_REG8 (0xfd ),0x01 }, + {CCI_REG8 (0x33 ),0x03 }, + {CCI_REG8 (0x01 ),0x02 }, + {CCI_REG8 (0xfd ),0x00 }, + {CCI_REG8 (0x20 ),0x1f }, + {CCI_REG8 (0xfd ),0x01 }, +}; + +static const struct cci_reg_sequence mode_OV05C_stream_off_regs[] = { + {CCI_REG8 (0xfd ),0x00 }, + {CCI_REG8 (0x20 ),0x5b }, + {CCI_REG8 (0xfd ),0x01 }, + {CCI_REG8 (0x33 ),0x02 }, + {CCI_REG8 (0x01 ),0x02 }, +}; + +static const char *const ov05c_test_pattern_menu[] = { +"Disabled" , +"Vertical Color Bar Type 1" , +"Vertical Color Bar Type 2" , +"Vertical Color Bar Type 3" , +"Vertical Color Bar Type 4" +}; + +/* Configurations for supported link frequencies */ +#define OV05C_LINK_FREQ_900MHZ (900 * HZ_PER_MHZ) + +/* Number of lanes supported */ +#define OV05C_DATA_LANES 2 + +/* Bits per sample of sensor output */ +#define OV05C_BITS_PER_SAMPLE 10 + +/* +* pixel_rate = link_freq * data-rate * nr_of_lanes / bits_per_sample +* data rate => double data rate; number of lanes => 2; bits per pixel => 10 +*/ +static u64 link_freq_to_pixel_rate (u64 f) +{
drivers/media/i2c/ov05c.c line 317
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+ f *=2 *OV05C_DATA_LANES ; +do_div (f,OV05C_BITS_PER_SAMPLE ); + +return f; +} + +/* Menu items for LINK_FREQ V4L2 control */ +static const s64 ov05c_link_freq_menu_items[] = { +OV05C_LINK_FREQ_900MHZ , +};
The link frequencies should be parsed from device properties (DT or ACPI), not be hardcoded in the driver. PLL parameters should be computed dynamically accordingly.
drivers/media/i2c/ov05c.c line 323
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+ +/* Mode configs */ +static const struct ov05c_mode supported_modes[] = { + { + .width =2888 , + .height =1808 ,
Can the sensor registers related to the image size be set based on the format set by userspace, instead of hardcoding modes ?
Quoted 22 lines
drivers/media/i2c/ov05c.c new file +22
-0+ .vts_def = OV05C_VTS_30FPS, + .vts_min = OV05C_VTS_30FPS, + .hts = 640, + .lanes = 2, + .reg_list = { + .num_of_regs = ARRAY_SIZE(mode_2888_1808_30fps_1800mbps_2lane_24mhz_regs), + .regs = mode_2888_1808_30fps_1800mbps_2lane_24mhz_regs, + }, + .link_freq_index = OV05C_LINK_FREQ_900MHZ_INDEX, + }, +}; + +struct ov05c { +struct v4l2_subdev sd; +struct media_pad pads[NUM_OF_PADS ]; + +/* V4L2 control handler */ +struct v4l2_ctrl_handler ctrl_handler; + +/* V4L2 Controls */ +struct v4l2_ctrl *link_freq; +struct v4l2_ctrl *pixel_rate;
drivers/media/i2c/ov05c.c line 355
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+struct v4l2_ctrl *vblank; +struct v4l2_ctrl *hblank; +struct v4l2_ctrl *exposure; + +/* Current mode */ +const struct ov05c_mode *cur_mode; + +struct regmap *regmap; + +/* Mutex for serialized access */
You need to document which fields the mutex protects.
drivers/media/i2c/ov05c.c line 364
Quoted 9 lines
drivers/media/i2c/ov05c.c new file +9
-0+struct mutex mutex; + +/* gpio descriptor */ +struct gpio_desc *enable_gpio; +}; + +#define to_ov05c (_sd) container_of(_sd, struct ov05c, sd) + +static int ov05c_open (struct v4l2_subdev *sd,struct v4l2_subdev_fh *fh)
.open() is normally not used for sensor drivers. You should use .init_state() instead.
Quoted 15 lines
drivers/media/i2c/ov05c.c new file +15
-0+{ +const struct ov05c_mode *default_mode = &supported_modes[0 ]; +struct ov05c *ov05c =to_ov05c (sd); +struct v4l2_mbus_framefmt *try_fmt = +v4l2_subdev_state_get_format (fh->state,0 ); + +mutex_lock (&ov05c->mutex); + +/* Initialize try_fmt */ + try_fmt->width = default_mode->width; + try_fmt->height = default_mode->height; + try_fmt->code =MEDIA_BUS_FMT_SGRBG10_1X10 ; + try_fmt->field =V4L2_FIELD_NONE ; + +/* No crop or compose */
drivers/media/i2c/ov05c.c line 389
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+mutex_unlock (&ov05c->mutex); + +return 0 ; +} + +static int ov05c_update_cid_vblank (struct ov05c *ov05c,u32 vblank) +{ +int ret =0 ; + + cci_write(ov05c->regmap, OV05C_REG_PAGE_CTL,
Controlling the page manually is error-prone. Could you encode the page number in the register address, and implement read/write wrapper functions that will set the page and call cci_read() and cci_write() ? You can then cache the active page, and avoid writing OV05C_REG_PAGE_CTL unnecessarily?
drivers/media/i2c/ov05c.c line 392
Quoted 3 lines
drivers/media/i2c/ov05c.c new file +3
-0+ BIT(0), &ret); +if (ret) +return ret;
Drop this, and ...
drivers/media/i2c/ov05c.c line 398
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+ +cci_write (ov05c->regmap,OV05C_REG_VTS , + ov05c->cur_mode->height + + vblank, &ret); +if (ret) +return ret;
drop this too ...
drivers/media/i2c/ov05c.c line 401
Quoted 3 lines
drivers/media/i2c/ov05c.c new file +3
-0+ +cci_write (ov05c->regmap,OV05C_REG_TRIGGER , +BIT (0 ), &ret);
Please create macros for register bits.
drivers/media/i2c/ov05c.c line 403
Quoted 2 lines
drivers/media/i2c/ov05c.c new file +2
-0+ +return ret;
and the function will behave as you expect. If ret is not zero, cci_write() returns immediately, so you can have multiple cci_write() calls without intermediate error handling. The same applies everywhere in the driver.
Quoted 372 lines
drivers/media/i2c/ov05c.c new file +372
-0+} + +static int ov05c_update_cid_exposure (struct ov05c *ov05c,u32 exposure) +{ +int ret =0 ; + +cci_write (ov05c->regmap,OV05C_REG_PAGE_CTL , +BIT (0 ), &ret); +if (ret) +return ret; + +cci_write (ov05c->regmap,OV05C_REG_EXPOSURE , + exposure, &ret); +if (ret) +return ret; + +cci_write (ov05c->regmap,OV05C_REG_TRIGGER , +BIT (0 ), &ret); + +return ret; +} + +static int ov05c_update_analog_gain (struct ov05c *ov05c,u32 a_gain) +{ +int ret; + + ret =cci_write (ov05c->regmap,OV05C_REG_PAGE_CTL ,BIT (0 ),NULL ); +if (ret) +return ret; + + ret =cci_write (ov05c->regmap,OV05C_REG_ANALOG_GAIN , a_gain,NULL ); +if (ret) +return ret; + +return cci_write (ov05c->regmap,OV05C_REG_TRIGGER ,BIT (0 ),NULL ); +} + +static int ov05_update_digital_gain (struct ov05c *ov05c,u32 d_gain) +{ +int ret; +u64 val; + + ret =cci_write (ov05c->regmap,OV05C_REG_PAGE_CTL ,BIT (0 ),NULL ); +if (ret) +return ret; + + val = d_gain &OV05C_DGTL_GAIN_L_MASK ; + ret =cci_write (ov05c->regmap,OV05C_REG_DGTL_GAIN_L , val,NULL ); +if (ret) +return ret; + + val = (d_gain &OV05C_DGTL_GAIN_H_MASK ) >>OV05C_DGTL_GAIN_H_SHIFT ; + + ret =cci_write (ov05c->regmap,OV05C_REG_DGTL_GAIN_H , val,NULL ); +if (ret) +return ret; + +return cci_write (ov05c->regmap,OV05C_REG_TRIGGER ,BIT (0 ),NULL ); +} + +static int ov05c_enable_test_pattern (struct ov05c *ov05c,u32 pattern) +{ +int ret; +u64 val; + + ret =cci_write (ov05c->regmap,OV05C_REG_PAGE_CTL ,BIT (2 ),NULL ); +if (ret) +return ret; + +if (pattern) { + ret =cci_read (ov05c->regmap,OV05C_REG_TEST_PATTERN_CTL , &val,NULL ); +if (ret) +return ret; + + ret =cci_write (ov05c->regmap,OV05C_REG_TEST_PATTERN_CTL , val |BIT (1 ),NULL ); +if (ret) +return ret; + + ret =cci_read (ov05c->regmap,OV05C_REG_TEST_PATTERN , &val,NULL ); +if (ret) +return ret; + + val &=OV05C_TEST_PATTERN_ENABLE ; + }else { + ret =cci_read (ov05c->regmap,OV05C_REG_TEST_PATTERN , &val,NULL ); +if (ret) +return ret; + + val &= ~OV05C_TEST_PATTERN_ENABLE ; + } + + ret =cci_write (ov05c->regmap,OV05C_REG_TEST_PATTERN , val,NULL ); +if (ret) +return ret; + +return cci_write (ov05c->regmap,OV05C_REG_TRIGGER ,BIT (0 ),NULL ); +} + +static int ov05c_set_ctrl (struct v4l2_ctrl *ctrl) +{ +struct ov05c *ov05c =container_of (ctrl->handler, + struct ov05c, ctrl_handler); +struct i2c_client *client =v4l2_get_subdevdata (&ov05c->sd); +s64 max; +int ret =0 ; + +/* Propagate change of current control to all related controls */ +switch (ctrl->id) { +case V4L2_CID_VBLANK : +/* Update max exposure while meeting expected vblanking */ + max = ov05c->cur_mode->height + ctrl->val -OV05C_EXPOSURE_MAX_MARGIN ; +__v4l2_ctrl_modify_range (ov05c->exposure, + ov05c->exposure->minimum, + max, ov05c->exposure->step, max); +break ; + } + +/* +* Applying V4L2 control value only happens +* when power is up for streaming +*/ +if (!pm_runtime_get_if_in_use (&client->dev)) +return 0 ; + +switch (ctrl->id) { +case V4L2_CID_ANALOGUE_GAIN : + ret =ov05c_update_analog_gain (ov05c, ctrl->val); +break ; +case V4L2_CID_DIGITAL_GAIN : + ret =ov05_update_digital_gain (ov05c, ctrl->val); +break ; +case V4L2_CID_EXPOSURE : + ret =ov05c_update_cid_exposure (ov05c, ctrl->val); +break ; +case V4L2_CID_VBLANK : + ret =ov05c_update_cid_vblank (ov05c, ctrl->val); +break ; +case V4L2_CID_TEST_PATTERN : + ret =ov05c_enable_test_pattern (ov05c, ctrl->val); +break ; +default : +dev_info (&client->dev, +"ctrl(id:0x%x,val:0x%x) is not handled\n" , + ctrl->id, ctrl->val); +break ; + } + +pm_runtime_put (&client->dev); + +return ret; +} + +static const struct v4l2_ctrl_ops ov05c_ctrl_ops = { + .s_ctrl = ov05c_set_ctrl, +}; + +static int ov05c_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 */ +if (code->index >0 ) +return -EINVAL ; + + code->code =MEDIA_BUS_FMT_SGRBG10_1X10 ; + +return 0 ; +} + +static int ov05c_enum_frame_size (struct v4l2_subdev *sd, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_frame_size_enum *fse) +{ +if (fse->index >=ARRAY_SIZE (supported_modes)) +return -EINVAL ; + +if (fse->code !=MEDIA_BUS_FMT_SGRBG10_1X10 ) +return -EINVAL ; + + fse->min_width = supported_modes[fse->index].width; + fse->max_width = fse->min_width; + fse->min_height = supported_modes[fse->index].height; + fse->max_height = fse->min_height; + +return 0 ; +} + +static void ov05c_update_pad_format (const struct ov05c_mode *mode, +struct v4l2_subdev_format *fmt) +{ + fmt->format.width = mode->width; + fmt->format.height = mode->height; + fmt->format.code =MEDIA_BUS_FMT_SGRBG10_1X10 ; + fmt->format.field =V4L2_FIELD_NONE ; +} + +static int ov05c_do_get_pad_format (struct ov05c *ov05c, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_format *fmt) +{ +struct v4l2_mbus_framefmt *framefmt; + +if (fmt->which ==V4L2_SUBDEV_FORMAT_TRY ) { + framefmt =v4l2_subdev_state_get_format (sd_state, fmt->pad); + fmt->format = *framefmt; + }else { +ov05c_update_pad_format (ov05c->cur_mode, fmt); + } + +return 0 ; +} + +static int ov05c_get_pad_format (struct v4l2_subdev *sd, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_format *fmt) +{ +struct ov05c *ov05c =to_ov05c (sd); +int ret; + +mutex_lock (&ov05c->mutex); + ret =ov05c_do_get_pad_format (ov05c, sd_state, fmt); +mutex_unlock (&ov05c->mutex); + +return ret; +} + +static int ov05c_set_pad_format (struct v4l2_subdev *sd, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_format *fmt) +{ +struct ov05c *ov05c =to_ov05c (sd); +const struct ov05c_mode *mode; +struct v4l2_mbus_framefmt *framefmt; +s32 vblank_def; +s32 vblank_min; +s64 h_blank; +s64 pixel_rate; +s64 link_freq; + +mutex_lock (&ov05c->mutex); + +/* Only one raw bayer(GRBG) order is supported */ +if (fmt->format.code !=MEDIA_BUS_FMT_SGRBG10_1X10 ) + fmt->format.code =MEDIA_BUS_FMT_SGRBG10_1X10 ; + + mode =v4l2_find_nearest_size (supported_modes, +ARRAY_SIZE (supported_modes), + width, height, + fmt->format.width, fmt->format.height); +ov05c_update_pad_format (mode, fmt); +if (fmt->which ==V4L2_SUBDEV_FORMAT_TRY ) { + framefmt =v4l2_subdev_state_get_format (sd_state, fmt->pad); + *framefmt = fmt->format; + }else { + ov05c->cur_mode = mode; +__v4l2_ctrl_s_ctrl (ov05c->link_freq, mode->link_freq_index); + link_freq = ov05c_link_freq_menu_items[mode->link_freq_index]; + pixel_rate =link_freq_to_pixel_rate (link_freq); +__v4l2_ctrl_s_ctrl_int64 (ov05c->pixel_rate, pixel_rate); + +/* Update limits and set FPS to default */ + vblank_def = ov05c->cur_mode->vts_def - + ov05c->cur_mode->height; + vblank_min = ov05c->cur_mode->vts_min - + ov05c->cur_mode->height; +__v4l2_ctrl_modify_range (ov05c->vblank, vblank_min, +OV05C_VTS_MAX + - ov05c->cur_mode->height, +1 , + vblank_def); +__v4l2_ctrl_s_ctrl (ov05c->vblank, vblank_def); + h_blank = ov05c->cur_mode->hts; +__v4l2_ctrl_modify_range (ov05c->hblank, h_blank, + h_blank,1 , h_blank); + } + +mutex_unlock (&ov05c->mutex); + +return 0 ; +} + +static int ov05c_start_streaming (struct ov05c *ov05c) +{ +struct i2c_client *client =v4l2_get_subdevdata (&ov05c->sd); +const struct ov05c_reg_list *reg_list; +int ret =0 ; + +/* Apply default values of current mode */ + reg_list = &ov05c->cur_mode->reg_list; +cci_multi_reg_write (ov05c->regmap, reg_list->regs, reg_list->num_of_regs, + &ret); +if (ret) { +dev_err (&client->dev,"%s failed to set mode, ret: %d\n" , __func__, ret); +return ret; + } + +/* Apply customized values from user */ + ret =__v4l2_ctrl_handler_setup (ov05c->sd.ctrl_handler); +if (ret) { +dev_err (&client->dev,"__v4l2_ctrl_handler_setup err:%d" , ret); +return ret; + } + +cci_multi_reg_write (ov05c->regmap, mode_OV05C_stream_on_regs, +ARRAY_SIZE (mode_OV05C_stream_on_regs), &ret); +if (ret) +dev_err (&client->dev,"%s failed to start the streaming\n" , __func__); + +return ret; +} + +static int ov05c_stop_streaming (struct ov05c *ov05c) +{ +int ret =0 ; +struct i2c_client *client =v4l2_get_subdevdata (&ov05c->sd); + +cci_multi_reg_write (ov05c->regmap, mode_OV05C_stream_off_regs, +ARRAY_SIZE (mode_OV05C_stream_off_regs), &ret); +if (ret) +dev_err (&client->dev,"%s failed to stop the streaming\n" , __func__); + +return ret; +} + +static void ov05c_sensor_enable (struct ov05c *ov05c,bool enable) +{ +if (enable) { +gpiod_set_value (ov05c->enable_gpio,0 ); +usleep_range (10 ,20 ); + +gpiod_set_value (ov05c->enable_gpio,1 ); +/* The delay is to make sure the sensor is completely turned on */ +usleep_range (1000 ,2000 ); + }else { +gpiod_set_value (ov05c->enable_gpio,0 ); +usleep_range (10 ,20 ); + } +} + +static int ov05c_set_stream (struct v4l2_subdev *sd,int enable) +{ +struct ov05c *ov05c =to_ov05c (sd); +struct i2c_client *client =v4l2_get_subdevdata (sd); +int ret =0 ; + +mutex_lock (&ov05c->mutex); + +if (enable) { +ov05c_sensor_enable (ov05c, true); + + ret =pm_runtime_resume_and_get (&client->dev); +if (ret <0 ) + goto err_unlock; + +/* +* Apply default & customized values +* and then start streaming. +*/ + ret =ov05c_start_streaming (ov05c); +if (ret) + goto err_rpm_put; + }else { +ov05c_stop_streaming (ov05c); +pm_runtime_put (&client->dev); + +ov05c_sensor_enable (ov05c, false); + } + +mutex_unlock (&ov05c->mutex); + +return ret; +
drivers/media/i2c/ov05c.c line 785
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+err_rpm_put: +pm_runtime_put (&client->dev); +err_unlock: +mutex_unlock (&ov05c->mutex); + +return ret; +} + +static const struct v4l2_subdev_video_ops ov05c_video_ops = { + .s_stream = ov05c_set_stream,
Please implement the .enable_streams() and .disable_streams() operations instead.
drivers/media/i2c/ov05c.c line 790
Quoted 5 lines
drivers/media/i2c/ov05c.c new file +5
-0+}; + +static const struct v4l2_subdev_pad_ops ov05c_pad_ops = { + .enum_mbus_code = ov05c_enum_mbus_code, + .get_fmt = ov05c_get_pad_format,
Use v4l2_subdev_get_fmt() here and drop the manual implementation of ov05c_get_pad_format(). You will need to call v4l2_subdev_init_finalize() at probe time. You should then be able to drop the mutex in the ov05c structure, as the active state lock will be used to serialize everything. The imx219 driver is a possible example of how to do so.
Quoted 131 lines
drivers/media/i2c/ov05c.c new file +131
-0+ .set_fmt = ov05c_set_pad_format, + .enum_frame_size = ov05c_enum_frame_size, +}; + +static const struct v4l2_subdev_ops ov05c_subdev_ops = { + .video = &ov05c_video_ops, + .pad = &ov05c_pad_ops, +}; + +static const struct media_entity_operations ov05c_subdev_entity_ops = { + .link_validate = v4l2_subdev_link_validate, +}; + +static const struct v4l2_subdev_internal_ops ov05c_internal_ops = { + .open = ov05c_open, +}; + +static int ov05c_init_controls (struct ov05c *ov05c) +{ +struct i2c_client *client =v4l2_get_subdevdata (&ov05c->sd); +struct v4l2_fwnode_device_properties props; +struct v4l2_ctrl_handler *ctrl_hdlr; +const struct ov05c_mode *mode; +s64 exposure_max; +s64 vblank_def; +s64 vblank_min; +s64 hblank; +s64 pixel_rate_max; +u32 max_items; +int ret; + +/* Initialize V4L2 control handler with 10 items */ + ret =v4l2_ctrl_handler_init (&ov05c->ctrl_handler,10 ); +if (ret) +return ret; + ctrl_hdlr = &ov05c->ctrl_handler; + +/* Initialize mutex for serialization */ +mutex_init (&ov05c->mutex); + ctrl_hdlr->lock = &ov05c->mutex; + +/* Initialize Link frequency control item */ + max_items =ARRAY_SIZE (ov05c_link_freq_menu_items) -1 ; + ov05c->link_freq =v4l2_ctrl_new_int_menu (ctrl_hdlr, +NULL , +V4L2_CID_LINK_FREQ , + max_items, +0 , + ov05c_link_freq_menu_items); +if (ov05c->link_freq) + ov05c->link_freq->flags |=V4L2_CTRL_FLAG_READ_ONLY ; + +/* Initialize Pixel rate control item */ + pixel_rate_max =link_freq_to_pixel_rate (ov05c_link_freq_menu_items[0 ]); + ov05c->pixel_rate =v4l2_ctrl_new_std (ctrl_hdlr,NULL , +V4L2_CID_PIXEL_RATE , +0 , pixel_rate_max, +1 , pixel_rate_max); + +/* Initialize VBLANK control item */ + mode = ov05c->cur_mode; + vblank_def = mode->vts_def - mode->height; + vblank_min = mode->vts_min - mode->height; + ov05c->vblank =v4l2_ctrl_new_std (ctrl_hdlr, &ov05c_ctrl_ops, +V4L2_CID_VBLANK , + vblank_min,OV05C_VTS_MAX - mode->height, +1 , vblank_def); + +/* Initialize HBLANK control item */ + hblank =max (0 , ov05c->cur_mode->hts - ov05c->cur_mode->width); + ov05c->hblank =v4l2_ctrl_new_std (ctrl_hdlr,NULL , +V4L2_CID_HBLANK , + hblank, hblank,1 , hblank); +if (ov05c->hblank) + ov05c->hblank->flags |=V4L2_CTRL_FLAG_READ_ONLY ; + +/* Initialize EXPOSURE control item */ + exposure_max = mode->vts_def -OV05C_EXPOSURE_MAX_MARGIN ; + ov05c->exposure =v4l2_ctrl_new_std (ctrl_hdlr, &ov05c_ctrl_ops, +V4L2_CID_EXPOSURE , +OV05C_EXPOSURE_MIN , exposure_max, +OV05C_EXPOSURE_STEP , exposure_max); + +/* Initialize Analog gain control item */ +v4l2_ctrl_new_std (ctrl_hdlr, &ov05c_ctrl_ops,V4L2_CID_ANALOGUE_GAIN , +OV05C_ANA_GAIN_MIN ,OV05C_ANA_GAIN_MAX , +OV05C_ANA_GAIN_STEP ,OV05C_ANA_GAIN_DEFAULT ); + +/* Initialize Digital gain control item */ +v4l2_ctrl_new_std (ctrl_hdlr, &ov05c_ctrl_ops,V4L2_CID_DIGITAL_GAIN , +OV05C_DGTL_GAIN_MIN ,OV05C_DGTL_GAIN_MAX , +OV05C_DGTL_GAIN_STEP ,OV05C_DGTL_GAIN_DEFAULT ); + + +/* Initialize Test pattern control item */ +v4l2_ctrl_new_std_menu_items (ctrl_hdlr, &ov05c_ctrl_ops, +V4L2_CID_TEST_PATTERN , +ARRAY_SIZE (ov05c_test_pattern_menu) -1 ,0 , +0 , ov05c_test_pattern_menu); + +if (ctrl_hdlr->error) { + ret = ctrl_hdlr->error; +dev_err (&client->dev,"%s V4L2 control init failed (%d)" , __func__, ret); + goto error; + } + + ret =v4l2_fwnode_device_parse (&client->dev, &props); +if (ret) + goto error; + + ret =v4l2_ctrl_new_fwnode_properties (ctrl_hdlr, &ov05c_ctrl_ops, &props); +if (ret) + goto error; + + ov05c->sd.ctrl_handler = ctrl_hdlr; + +return 0 ; + +error: +v4l2_ctrl_handler_free (ctrl_hdlr); +mutex_destroy (&ov05c->mutex); + +return ret; +} + +static void ov05c_free_controls (struct ov05c *ov05c) +{ +v4l2_ctrl_handler_free (ov05c->sd.ctrl_handler); +mutex_destroy (&ov05c->mutex); +} +
drivers/media/i2c/ov05c.c line 931
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+static int ov05c_probe (struct i2c_client *client) +{ +struct ov05c *ov05c; +int i, ret; + + ov05c =devm_kzalloc (&client->dev,sizeof (*ov05c),GFP_KERNEL ); +if (!ov05c) +return -ENOMEM ; + + client->dev.init_name =DRV_NAME ;
That's unusual, why is it needed ?
Quoted 40 lines
drivers/media/i2c/ov05c.c new file +40
-0+ +/* create sensor enable gpio control */ + ov05c->enable_gpio =devm_gpiod_get (&client->dev,"sensor0_enable" ,GPIOD_OUT_LOW ); +if (IS_ERR_OR_NULL (ov05c->enable_gpio)) +return PTR_ERR (ov05c->enable_gpio); + +/* Initialize subdev */ +v4l2_i2c_subdev_init (&ov05c->sd, client, &ov05c_subdev_ops); + +/* Initialize CCI */ + ov05c->regmap =devm_cci_regmap_init_i2c (client,8 ); +if (IS_ERR (ov05c->regmap)) { +dev_err (&client->dev,"Failed to initialize CCI\n" ); +return PTR_ERR (ov05c->regmap); + } + +/* Set default mode to max resolution */ + ov05c->cur_mode = &supported_modes[0 ]; + +/* Initialize V4L2 controls */ + ret =ov05c_init_controls (ov05c); +if (ret) +return ret; + +/* Initialize V4L2 subdev */ + ov05c->sd.internal_ops = &ov05c_internal_ops; + ov05c->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; + ov05c->sd.entity.ops = &ov05c_subdev_entity_ops; + ov05c->sd.entity.function =MEDIA_ENT_F_CAM_SENSOR ; + ov05c->sd.entity.name ="OV05C" ; + +/* Initialize source pad */ +for (i =0 ; i <NUM_OF_PADS ; i++) + ov05c->pads[i].flags =MEDIA_PAD_FL_SOURCE ; + + ret =media_entity_pads_init (&ov05c->sd.entity,NUM_OF_PADS , ov05c->pads); +if (ret) + goto error_handler_free; + + ret =v4l2_async_register_subdev_sensor (&ov05c->sd);
drivers/media/i2c/ov05c.c line 981
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+if (ret) + goto error_media_entity; + +/* +* Device is already turned on by i2c-core with ACPI domain PM. +* Enable runtime PM and turn off the device. +*/ +pm_runtime_set_active (&client->dev); +pm_runtime_enable (&client->dev); +pm_runtime_idle (&client->dev);
Please enable auto-suspend.
drivers/media/i2c/ov05c.c line 983
Quoted 2 lines
drivers/media/i2c/ov05c.c new file +2
-0+ +dev_info (&client->dev,"%s success" , __func__);
This can be dropped.
Quoted 35 lines
drivers/media/i2c/ov05c.c new file +35
-0+ +return 0 ; + +error_media_entity: +media_entity_cleanup (&ov05c->sd.entity); + +error_handler_free: +ov05c_free_controls (ov05c); + +return ret; +} + +static void ov05c_remove (struct i2c_client *client) +{ +struct v4l2_subdev *sd =i2c_get_clientdata (client); +struct ov05c *ov05c =to_ov05c (sd); + +v4l2_async_unregister_subdev (sd); +media_entity_cleanup (&sd->entity); +ov05c_free_controls (ov05c); + +pm_runtime_disable (&client->dev); +pm_runtime_set_suspended (&client->dev); +} + +static const struct i2c_device_id ov05c_id[] = { + {"ov05c" ,0 }, + { } +}; + +MODULE_DEVICE_TABLE (i2c, ov05c_id); + +static struct i2c_driver ov05c_i2c_driver = { + .driver = { + .name =DRV_NAME ,
drivers/media/i2c/ov05c.c line 1028
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+ }, + .id_table = ov05c_id, + .probe = ov05c_probe, + .remove = ov05c_remove, +}; + +module_i2c_driver (ov05c_i2c_driver); + +MODULE_AUTHOR ("Venkata Narendra Kumar Gutta <[email protected]>" ); +MODULE_AUTHOR ("Pratap Nirujogi <[email protected]>" );
Should the patch have a SoB line for Venkata too ?
drivers/media/i2c/ov05c.c line 1031
Quoted 3 lines
drivers/media/i2c/ov05c.c new file +3
-0+MODULE_DESCRIPTION ("OmniVision OV05C sensor driver" ); +MODULE_ALIAS ("ov05c" ); +MODULE_LICENSE ("GPL and additional rights" );
Mismatch with the SPDX tag.
Signature · 3 lines
Regards, Laurent Pinchart
Hi Laurent,
Thanks for reviewing and extremely sorry for the delayed response. We have submitted V2 patch based on your review feedback.
Can you please help to review latest V2 patch and let us know your feedback.
Thanks,
Pratap
Quoted 10 lines · Laurent Pinchart
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Hi Pratap,
Thank you for the patch.
A few assorted comments to start with, I'll try to do a more in-depth review later.
Quoted 8 lines
Quoted 3 lines · Pratap Nirujogi
Add driver for OmniVision 5.2M OV05C10 sensor. This driver supports only the full size normal 2888x1808@30fps 2-lane sensor profile.
What have you tested this driver with ? I see no OF device ID or ACPI device ID.
We have tested this driver on the "AMD RYZEN AI MAX PRO 385 w/ Radeon 8050S" target supporting ISP HW v4.1. OMNI5C10 is ACPI HID for this sensor on the target.
Quoted 1 line
Please provide a v4l2-compliance report.
Please refer the attached screenshot for the v4l2-compliance test report. This test is ran with V2 patch. Fixed some of the compliance test failures on V1 and ensured it is 100% compliant for the supported IOCTLS.
Quoted 9 lines
Quoted 6 lines
Signed-off-by Pratap Nirujogi <[email protected]>--- drivers/media/i2c/Kconfig | 10 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/ov05c.c | 1031 ++++++++++++++++++++++++++++++++++++Please add an entry in the
MAINTAINERSfile.
Sure, its updated in V2 patch.
Quoted 11 lines
Quoted 11 lines
3 files changed, 1042 insertions(+)create mode 100644
drivers/media/i2c/ov05c.cdrivers/media/i2c/Kconfig +0
-0@@ -337,6 +337,16 @@ config VIDEO_OG01A1B To compile this driver as a module, choose M here: the module will be called og01a1b.
Quoted 4 lines
drivers/media/i2c/Kconfig config VIDEO_OG01A1B · line 340
Quoted 1 line
drivers/media/i2c/Kconfig +1
-0+config VIDEO_OV05CPlease sort entries alphabetically.
Done. Updated in V2 patch.
Quoted 15 lines
Quoted 15 lines
drivers/media/i2c/Kconfig +9
-0+ tristate "OmniVision OV05 sensor support" + select V4L2_CCI_I2C + help + This is a Video4Linux2 sensor driver for the OmniVision + OV05C camera. + + To compile this driver as a module, choose M here: the + module will be called OV05C. + config VIDEO_OV01A10 tristate "OmniVision OV01A10 sensor support" helpdrivers/media/i2c/Makefile +0
-1--- a/drivers/media/i2c/Makefile
Quoted 9 lines
drivers/media/i2c/Makefile obj-$(CONFIG_VIDEO_MT9V011) += mt9v011.o · line 83
Quoted 6 lines
+++ b/drivers/media/i2c/Makefile
drivers/media/i2c/Makefile +1
-0@@ -80,6 +80,7 @@ obj-$(CONFIG_VIDEO_MT9V011) += mt9v011.o obj-$(CONFIG_VIDEO_MT9V032) += mt9v032.o obj-$(CONFIG_VIDEO_MT9V111) += mt9v111.o obj-$(CONFIG_VIDEO_OG01A1B) += og01a1b.o +obj-$(CONFIG_VIDEO_OV05C) += ov05c.oHere too.
Done. Updated in V2 patch.
Quoted 4 lines
Quoted 4 lines
drivers/media/i2c/Makefile +0
-0obj-$(CONFIG_VIDEO_OV01A10) += ov01a10.o obj-$(CONFIG_VIDEO_OV02A10) += ov02a10.o obj-$(CONFIG_VIDEO_OV08D10) += ov08d10.odrivers/media/i2c/ov05c.c +0
-0
Quoted 9 lines
drivers/media/i2c/ov05c.c line 1
Quoted 6 lines
new file mode 100644
index 000000000000..96c4f74af4a9drivers/media/i2c/ov05c.c new file +1
-0@@ -0,0 +1,1031 @@ +/* SPDX-License-Identifier: MIT */ Why not GPL-2.0 ?
Done. Updated license to GPL in V2.
Quoted 24 lines
Quoted 13 lines
drivers/media/i2c/ov05c.c new file +13
-0+/* +* Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. +* All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sub license, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice (including the drivers/media/i2c/ov05c.c line 24
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+* next paragraph) shall be included in all copies or substantial portions +* of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +* USE OR OTHER DEALINGS IN THE SOFTWARE.
Quoted 3 lines
Drop all this (except the copyright line), it's conveyed by the SPDX tag.
Done. Copyright header updated as suggested.
Quoted 7 lines
drivers/media/i2c/ov05c.c line 28
Quoted 4 lines
drivers/media/i2c/ov05c.c new file +4
-0+* +*/ + +#include <linux/acpi.h> This doesn't seem to be used.
Yes, its not used. Removed in V2.
Quoted 6 lines
drivers/media/i2c/ov05c.c line 31
Quoted 3 lines
drivers/media/i2c/ov05c.c new file +3
-0+#include <linux/i2c.h> +#include <linux/module.h> +#include <linux/delay.h> Alphabetical order please.
Done. Fixed the order in V2.
Quoted 10 lines
drivers/media/i2c/ov05c.c line 38
Quoted 7 lines
drivers/media/i2c/ov05c.c new file +7
-0+#include <linux/units.h> +#include <linux/pm_runtime.h> +#include <linux/gpio.h> +#include <media/v4l2-ctrls.h> +#include <media/v4l2-device.h> +#include <media/v4l2-fwnode.h> +#include <media/v4l2-cci.h> Thanks for using the CCI helpers :-)
Those are really helpful, thank you :)
Quoted 12 lines
drivers/media/i2c/ov05c.c line 47
Quoted 9 lines
drivers/media/i2c/ov05c.c new file +9
-0+ +#define DRV_NAME "ov05c" + +/* Chip ID */ +#define OV05C_REG_CHIP_ID CCI_REG24(0x00) +#define OV05C_CHIP_ID 0x430556 + +/* Control registers */ +#define OV05C_REG_PAGE_CTL CCI_REG8(0xFD)V4L2 spells hex constants in lower case.
thank you, updated in V2.
Quoted 36 lines
Quoted 36 lines
drivers/media/i2c/ov05c.c new file +36
-0+#define OV05C_REG_TRIGGER CCI_REG8(0x01) + +/* V_TIMING internal */ +#define OV05C_REG_VTS CCI_REG16(0x05) +#define OV05C_VTS_30FPS 1860 +#define OV05C_VTS_MAX 0x7fff + +/* H TIMING internal */ +#define OV05C_REG_HTS CCI_REG16(0x37) +#define OV05C_HTS_30FPS 0x0280 + +/* Exposure control */ +#define OV05C_REG_EXPOSURE CCI_REG24(0x02) +#define OV05C_EXPOSURE_MAX_MARGIN 33 +#define OV05C_EXPOSURE_MIN 4 +#define OV05C_EXPOSURE_STEP 1 +#define OV05C_EXPOSURE_DEFAULT 0x40 + +/* Analog gain control */ +#define OV05C_REG_ANALOG_GAIN CCI_REG8(0x24) +#define OV05C_ANA_GAIN_MIN 0x80 +#define OV05C_ANA_GAIN_MAX 0x07c0 +#define OV05C_ANA_GAIN_STEP 1 +#define OV05C_ANA_GAIN_DEFAULT 0x80 + +/* Digital gain control */ +#define OV05C_REG_DGTL_GAIN_H CCI_REG8(0x21) +#define OV05C_REG_DGTL_GAIN_L CCI_REG8(0x22) + +#define OV05C_DGTL_GAIN_MIN 64/* Min = 1 X */ +#define OV05C_DGTL_GAIN_MAX (256 - 1)/* Max = 4 X */ +#define OV05C_DGTL_GAIN_DEFAULT 0x80/* Default gain = 2x */ +#define OV05C_DGTL_GAIN_STEP 1/* Each step = 1/64 */ + +#define OV05C_DGTL_GAIN_L_MASK 0xFF +#define OV05C_DGTL_GAIN_H_SHIFT 8
Quoted 9 lines
drivers/media/i2c/ov05c.c line 89
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+#define OV05C_DGTL_GAIN_H_MASK 0xFF00 + +/* Test Pattern Control */ +#define OV05C_REG_TEST_PATTERN_CTL CCI_REG8(0xF3) +#define OV05C_REG_TEST_PATTERN CCI_REG8(0x12) +#define OV05C_TEST_PATTERN_ENABLE BIT(0)Could you please sort registers by their numerical address ?
Sure, its taken care in V2.
Quoted 6 lines
drivers/media/i2c/ov05c.c line 91
Quoted 2 lines
drivers/media/i2c/ov05c.c new file +2
-0+ +#define NUM_OF_PADS 3Why three pads ? The driver doesn't seem to make a distinction between them.
Thanks, only 1 pad is needed. Updated in V2.
Quoted 222 lines
Quoted 222 lines
drivers/media/i2c/ov05c.c new file +222
-0+ +enum { +OV05C_LINK_FREQ_900MHZ_INDEX , +}; + +struct ov05c_reg_list { +u32 num_of_regs; +const struct cci_reg_sequence *regs; +}; + +/* Link frequency config */ +struct ov05c_link_freq_config { +/* registers for this link frequency */ +struct ov05c_reg_list reg_list; +}; + +/* Mode : resolution and related config&values */ +struct ov05c_mode { +/* Frame width */ +u32 width; +/* Frame height */ +u32 height; +/* number of lanes */ +u32 lanes; + +/* V-timing */ +u32 vts_def; +u32 vts_min; + +/* HTS */ +u32 hts; + +/* Index of Link frequency config to be used */ +u32 link_freq_index; + +/* Default register values */ +struct ov05c_reg_list reg_list; +}; + +static const struct cci_reg_sequence + mode_2888_1808_30fps_1800mbps_2lane_24mhz_regs[] = { + {CCI_REG8 (0xfd ),0x00 }, + {CCI_REG8 (0x20 ),0x00 }, + {CCI_REG8 (0xfd ),0x00 }, + {CCI_REG8 (0x20 ),0x0b }, + {CCI_REG8 (0xc1 ),0x09 }, + {CCI_REG8 (0x21 ),0x06 }, + {CCI_REG8 (0x14 ),0x78 }, + {CCI_REG8 (0xe7 ),0x03 }, + {CCI_REG8 (0xe7 ),0x00 }, + {CCI_REG8 (0x21 ),0x00 }, + {CCI_REG8 (0xfd ),0x01 }, + {CCI_REG8 (0x03 ),0x00 }, + {CCI_REG8 (0x04 ),0x06 }, + {CCI_REG8 (0x05 ),0x07 }, + {CCI_REG8 (0x06 ),0x44 }, + {CCI_REG8 (0x07 ),0x08 }, + {CCI_REG8 (0x1b ),0x01 }, + {CCI_REG8 (0x24 ),0xff }, + {CCI_REG8 (0x32 ),0x03 }, + {CCI_REG8 (0x42 ),0x5d }, + {CCI_REG8 (0x43 ),0x08 }, + {CCI_REG8 (0x44 ),0x81 }, + {CCI_REG8 (0x46 ),0x5f }, + {CCI_REG8 (0x48 ),0x18 }, + {CCI_REG8 (0x49 ),0x04 }, + {CCI_REG8 (0x5c ),0x18 }, + {CCI_REG8 (0x5e ),0x13 }, + {CCI_REG8 (0x70 ),0x15 }, + {CCI_REG8 (0x77 ),0x35 }, + {CCI_REG8 (0x79 ),0x00 }, + {CCI_REG8 (0x7b ),0x08 }, + {CCI_REG8 (0x7d ),0x08 }, + {CCI_REG8 (0x7e ),0x08 }, + {CCI_REG8 (0x7f ),0x08 }, + {CCI_REG8 (0x90 ),0x37 }, + {CCI_REG8 (0x91 ),0x05 }, + {CCI_REG8 (0x92 ),0x18 }, + {CCI_REG8 (0x93 ),0x27 }, + {CCI_REG8 (0x94 ),0x05 }, + {CCI_REG8 (0x95 ),0x38 }, + {CCI_REG8 (0x9b ),0x00 }, + {CCI_REG8 (0x9c ),0x06 }, + {CCI_REG8 (0x9d ),0x28 }, + {CCI_REG8 (0x9e ),0x06 }, + {CCI_REG8 (0xb2 ),0x0f }, + {CCI_REG8 (0xb3 ),0x29 }, + {CCI_REG8 (0xbf ),0x3c }, + {CCI_REG8 (0xc2 ),0x04 }, + {CCI_REG8 (0xc4 ),0x00 }, + {CCI_REG8 (0xca ),0x20 }, + {CCI_REG8 (0xcb ),0x20 }, + {CCI_REG8 (0xcc ),0x28 }, + {CCI_REG8 (0xcd ),0x28 }, + {CCI_REG8 (0xce ),0x20 }, + {CCI_REG8 (0xcf ),0x20 }, + {CCI_REG8 (0xd0 ),0x2a }, + {CCI_REG8 (0xd1 ),0x2a }, + {CCI_REG8 (0xfd ),0x0f }, + {CCI_REG8 (0x00 ),0x00 }, + {CCI_REG8 (0x01 ),0xa0 }, + {CCI_REG8 (0x02 ),0x48 }, + {CCI_REG8 (0x07 ),0x8f }, + {CCI_REG8 (0x08 ),0x70 }, + {CCI_REG8 (0x09 ),0x01 }, + {CCI_REG8 (0x0b ),0x40 }, + {CCI_REG8 (0x0d ),0x07 }, + {CCI_REG8 (0x11 ),0x33 }, + {CCI_REG8 (0x12 ),0x77 }, + {CCI_REG8 (0x13 ),0x66 }, + {CCI_REG8 (0x14 ),0x65 }, + {CCI_REG8 (0x15 ),0x37 }, + {CCI_REG8 (0x16 ),0xbf }, + {CCI_REG8 (0x17 ),0xff }, + {CCI_REG8 (0x18 ),0xff }, + {CCI_REG8 (0x19 ),0x12 }, + {CCI_REG8 (0x1a ),0x10 }, + {CCI_REG8 (0x1c ),0x77 }, + {CCI_REG8 (0x1d ),0x77 }, + {CCI_REG8 (0x20 ),0x0f }, + {CCI_REG8 (0x21 ),0x0f }, + {CCI_REG8 (0x22 ),0x0f }, + {CCI_REG8 (0x23 ),0x0f }, + {CCI_REG8 (0x2b ),0x20 }, + {CCI_REG8 (0x2c ),0x20 }, + {CCI_REG8 (0x2d ),0x04 }, + {CCI_REG8 (0xfd ),0x03 }, + {CCI_REG8 (0x9d ),0x0f }, + {CCI_REG8 (0x9f ),0x40 }, + {CCI_REG8 (0xfd ),0x00 }, + {CCI_REG8 (0x20 ),0x1b }, + {CCI_REG8 (0xfd ),0x04 }, + {CCI_REG8 (0x19 ),0x60 }, + {CCI_REG8 (0xfd ),0x02 }, + {CCI_REG8 (0x75 ),0x05 }, + {CCI_REG8 (0x7f ),0x06 }, + {CCI_REG8 (0x9a ),0x03 }, + {CCI_REG8 (0xa2 ),0x07 }, + {CCI_REG8 (0xa3 ),0x10 }, + {CCI_REG8 (0xa5 ),0x02 }, + {CCI_REG8 (0xa6 ),0x0b }, + {CCI_REG8 (0xa7 ),0x48 }, + {CCI_REG8 (0xfd ),0x07 }, + {CCI_REG8 (0x42 ),0x00 }, + {CCI_REG8 (0x43 ),0x80 }, + {CCI_REG8 (0x44 ),0x00 }, + {CCI_REG8 (0x45 ),0x80 }, + {CCI_REG8 (0x46 ),0x00 }, + {CCI_REG8 (0x47 ),0x80 }, + {CCI_REG8 (0x48 ),0x00 }, + {CCI_REG8 (0x49 ),0x80 }, + {CCI_REG8 (0x00 ),0xf7 }, + {CCI_REG8 (0xfd ),0x00 }, + {CCI_REG8 (0xe7 ),0x03 }, + {CCI_REG8 (0xe7 ),0x00 }, + {CCI_REG8 (0xfd ),0x00 }, + {CCI_REG8 (0x93 ),0x18 }, + {CCI_REG8 (0x94 ),0xff }, + {CCI_REG8 (0x95 ),0xbd }, + {CCI_REG8 (0x96 ),0x1a }, + {CCI_REG8 (0x98 ),0x04 }, + {CCI_REG8 (0x99 ),0x08 }, + {CCI_REG8 (0x9b ),0x10 }, + {CCI_REG8 (0x9c ),0x3f }, + {CCI_REG8 (0xa1 ),0x05 }, + {CCI_REG8 (0xa4 ),0x2f }, + {CCI_REG8 (0xc0 ),0x0c }, + {CCI_REG8 (0xc1 ),0x08 }, + {CCI_REG8 (0xc2 ),0x00 }, + {CCI_REG8 (0xb6 ),0x20 }, + {CCI_REG8 (0xbb ),0x80 }, + {CCI_REG8 (0xfd ),0x00 }, + {CCI_REG8 (0xa0 ),0x01 }, + {CCI_REG8 (0xfd ),0x01 }, +}; + +static const struct cci_reg_sequence mode_OV05C_stream_on_regs[] = { + {CCI_REG8 (0xfd ),0x01 }, + {CCI_REG8 (0x33 ),0x03 }, + {CCI_REG8 (0x01 ),0x02 }, + {CCI_REG8 (0xfd ),0x00 }, + {CCI_REG8 (0x20 ),0x1f }, + {CCI_REG8 (0xfd ),0x01 }, +}; + +static const struct cci_reg_sequence mode_OV05C_stream_off_regs[] = { + {CCI_REG8 (0xfd ),0x00 }, + {CCI_REG8 (0x20 ),0x5b }, + {CCI_REG8 (0xfd ),0x01 }, + {CCI_REG8 (0x33 ),0x02 }, + {CCI_REG8 (0x01 ),0x02 }, +}; + +static const char *const ov05c_test_pattern_menu[] = { +"Disabled" , +"Vertical Color Bar Type 1" , +"Vertical Color Bar Type 2" , +"Vertical Color Bar Type 3" , +"Vertical Color Bar Type 4" +}; + +/* Configurations for supported link frequencies */ +#define OV05C_LINK_FREQ_900MHZ (900 * HZ_PER_MHZ) + +/* Number of lanes supported */ +#define OV05C_DATA_LANES 2 + +/* Bits per sample of sensor output */ +#define OV05C_BITS_PER_SAMPLE 10 + +/* +* pixel_rate = link_freq * data-rate * nr_of_lanes / bits_per_sample +* data rate => double data rate; number of lanes => 2; bits per pixel => 10 +*/ +static u64 link_freq_to_pixel_rate (u64 f) +{ + f *=2 *OV05C_DATA_LANES ; +do_div (f,OV05C_BITS_PER_SAMPLE ); + +return f; +} +
Quoted 9 lines
drivers/media/i2c/ov05c.c line 317
Quoted 4 lines
drivers/media/i2c/ov05c.c new file +4
-0+/* Menu items for LINK_FREQ V4L2 control */ +static const s64 ov05c_link_freq_menu_items[] = { +OV05C_LINK_FREQ_900MHZ , +};The link frequencies should be parsed from device properties (DT or ACPI), not be hardcoded in the driver. PLL parameters should be computed dynamically accordingly.
Yes, its taken care in V2. We have taken care of reading the link frequency from the swnodes recently added in the latest V3 x86/platform driver patch submitted for review. The swnodes are added for this platform as the camera device specific properties in ACPI are missing.
The link frequency actually is related to the sensor profile, here we support only one profile, so the link frequency is fixed, no dynamic calculation is needed, just like other upstream sensor driver like ov02a10.
Quoted 10 lines
drivers/media/i2c/ov05c.c line 323
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+ +/* Mode configs */ +static const struct ov05c_mode supported_modes[] = { + { + .width =2888 , + .height =1808 ,Can the sensor registers related to the image size be set based on the format set by userspace, instead of hardcoding modes ?
Ideally its possible, but for this particular sensor we have register settings only for this mode from the vendor.
Quoted 26 lines
Quoted 26 lines
drivers/media/i2c/ov05c.c new file +26
-0+ .vts_def = OV05C_VTS_30FPS, + .vts_min = OV05C_VTS_30FPS, + .hts = 640, + .lanes = 2, + .reg_list = { + .num_of_regs = ARRAY_SIZE(mode_2888_1808_30fps_1800mbps_2lane_24mhz_regs), + .regs = mode_2888_1808_30fps_1800mbps_2lane_24mhz_regs, + }, + .link_freq_index = OV05C_LINK_FREQ_900MHZ_INDEX, + }, +}; + +struct ov05c { +struct v4l2_subdev sd; +struct media_pad pads[NUM_OF_PADS ]; + +/* V4L2 control handler */ +struct v4l2_ctrl_handler ctrl_handler; + +/* V4L2 Controls */ +struct v4l2_ctrl *link_freq; +struct v4l2_ctrl *pixel_rate; +struct v4l2_ctrl *vblank; +struct v4l2_ctrl *hblank; +struct v4l2_ctrl *exposure; +
Quoted 9 lines
drivers/media/i2c/ov05c.c line 355
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+/* Current mode */ +const struct ov05c_mode *cur_mode; + +struct regmap *regmap; + +/* Mutex for serialized access */ You need to document which fields the mutex protects.
We found this mutex is not required and removed it in V2.
Quoted 4 lines
Quoted 4 lines
drivers/media/i2c/ov05c.c new file +4
-0+struct mutex mutex; + +/* gpio descriptor */ +struct gpio_desc *enable_gpio;
Quoted 9 lines
drivers/media/i2c/ov05c.c line 364
Quoted 5 lines
drivers/media/i2c/ov05c.c new file +5
-0+}; + +#define to_ov05c (_sd) container_of(_sd, struct ov05c, sd) + +static int ov05c_open (struct v4l2_subdev *sd,struct v4l2_subdev_fh *fh).open() is normally not used for sensor drivers. You should use .init_state() instead.
Done. Removed open() and added init_state() in V2.
Quoted 23 lines
Quoted 23 lines
drivers/media/i2c/ov05c.c new file +23
-0+{ +const struct ov05c_mode *default_mode = &supported_modes[0 ]; +struct ov05c *ov05c =to_ov05c (sd); +struct v4l2_mbus_framefmt *try_fmt = +v4l2_subdev_state_get_format (fh->state,0 ); + +mutex_lock (&ov05c->mutex); + +/* Initialize try_fmt */ + try_fmt->width = default_mode->width; + try_fmt->height = default_mode->height; + try_fmt->code =MEDIA_BUS_FMT_SGRBG10_1X10 ; + try_fmt->field =V4L2_FIELD_NONE ; + +/* No crop or compose */ +mutex_unlock (&ov05c->mutex); + +return 0 ; +} + +static int ov05c_update_cid_vblank (struct ov05c *ov05c,u32 vblank) +{ +int ret =0 ;
Quoted 9 lines
drivers/media/i2c/ov05c.c line 389
Quoted 2 lines
drivers/media/i2c/ov05c.c new file +2
-0+ + cci_write(ov05c->regmap, OV05C_REG_PAGE_CTL,Controlling the page manually is error-prone. Could you encode the page number in the register address, and implement read/write wrapper functions that will set the page and call
cci_read()andcci_write()? You can then cache the active page, and avoid writingOV05C_REG_PAGE_CTLunnecessarily?
thanks for this suggestion. We have taken care of it in V2.
Quoted 6 lines
drivers/media/i2c/ov05c.c line 392
Quoted 3 lines
drivers/media/i2c/ov05c.c new file +3
-0+ BIT(0), &ret); +if (ret) +return ret;Drop this, and ...
Quoted 9 lines
drivers/media/i2c/ov05c.c line 398
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+ +cci_write (ov05c->regmap,OV05C_REG_VTS , + ov05c->cur_mode->height + + vblank, &ret); +if (ret) +return ret;drop this too ...
Done. Removed in V2.
Quoted 6 lines
drivers/media/i2c/ov05c.c line 401
Quoted 3 lines
drivers/media/i2c/ov05c.c new file +3
-0+ +cci_write (ov05c->regmap,OV05C_REG_TRIGGER , +BIT (0 ), &ret);Please create macros for register bits.
sure, added macro OV05C_REG_TRIGGER_START in V2.
Quoted 8 lines
drivers/media/i2c/ov05c.c line 403
Quoted 2 lines
drivers/media/i2c/ov05c.c new file +2
-0+ +return ret;and the function will behave as you expect. If ret is not zero,
cci_write()returns immediately, so you can have multiplecci_write()calls without intermediate error handling. The same applies everywhere in the driver.
Refactored ov05c10_update control funcs. Please see V2 and let us know your opinion.
Quoted 377 lines
Quoted 377 lines
drivers/media/i2c/ov05c.c new file +377
-0+} + +static int ov05c_update_cid_exposure (struct ov05c *ov05c,u32 exposure) +{ +int ret =0 ; + +cci_write (ov05c->regmap,OV05C_REG_PAGE_CTL , +BIT (0 ), &ret); +if (ret) +return ret; + +cci_write (ov05c->regmap,OV05C_REG_EXPOSURE , + exposure, &ret); +if (ret) +return ret; + +cci_write (ov05c->regmap,OV05C_REG_TRIGGER , +BIT (0 ), &ret); + +return ret; +} + +static int ov05c_update_analog_gain (struct ov05c *ov05c,u32 a_gain) +{ +int ret; + + ret =cci_write (ov05c->regmap,OV05C_REG_PAGE_CTL ,BIT (0 ),NULL ); +if (ret) +return ret; + + ret =cci_write (ov05c->regmap,OV05C_REG_ANALOG_GAIN , a_gain,NULL ); +if (ret) +return ret; + +return cci_write (ov05c->regmap,OV05C_REG_TRIGGER ,BIT (0 ),NULL ); +} + +static int ov05_update_digital_gain (struct ov05c *ov05c,u32 d_gain) +{ +int ret; +u64 val; + + ret =cci_write (ov05c->regmap,OV05C_REG_PAGE_CTL ,BIT (0 ),NULL ); +if (ret) +return ret; + + val = d_gain &OV05C_DGTL_GAIN_L_MASK ; + ret =cci_write (ov05c->regmap,OV05C_REG_DGTL_GAIN_L , val,NULL ); +if (ret) +return ret; + + val = (d_gain &OV05C_DGTL_GAIN_H_MASK ) >>OV05C_DGTL_GAIN_H_SHIFT ; + + ret =cci_write (ov05c->regmap,OV05C_REG_DGTL_GAIN_H , val,NULL ); +if (ret) +return ret; + +return cci_write (ov05c->regmap,OV05C_REG_TRIGGER ,BIT (0 ),NULL ); +} + +static int ov05c_enable_test_pattern (struct ov05c *ov05c,u32 pattern) +{ +int ret; +u64 val; + + ret =cci_write (ov05c->regmap,OV05C_REG_PAGE_CTL ,BIT (2 ),NULL ); +if (ret) +return ret; + +if (pattern) { + ret =cci_read (ov05c->regmap,OV05C_REG_TEST_PATTERN_CTL , &val,NULL ); +if (ret) +return ret; + + ret =cci_write (ov05c->regmap,OV05C_REG_TEST_PATTERN_CTL , val |BIT (1 ),NULL ); +if (ret) +return ret; + + ret =cci_read (ov05c->regmap,OV05C_REG_TEST_PATTERN , &val,NULL ); +if (ret) +return ret; + + val &=OV05C_TEST_PATTERN_ENABLE ; + }else { + ret =cci_read (ov05c->regmap,OV05C_REG_TEST_PATTERN , &val,NULL ); +if (ret) +return ret; + + val &= ~OV05C_TEST_PATTERN_ENABLE ; + } + + ret =cci_write (ov05c->regmap,OV05C_REG_TEST_PATTERN , val,NULL ); +if (ret) +return ret; + +return cci_write (ov05c->regmap,OV05C_REG_TRIGGER ,BIT (0 ),NULL ); +} + +static int ov05c_set_ctrl (struct v4l2_ctrl *ctrl) +{ +struct ov05c *ov05c =container_of (ctrl->handler, + struct ov05c, ctrl_handler); +struct i2c_client *client =v4l2_get_subdevdata (&ov05c->sd); +s64 max; +int ret =0 ; + +/* Propagate change of current control to all related controls */ +switch (ctrl->id) { +case V4L2_CID_VBLANK : +/* Update max exposure while meeting expected vblanking */ + max = ov05c->cur_mode->height + ctrl->val -OV05C_EXPOSURE_MAX_MARGIN ; +__v4l2_ctrl_modify_range (ov05c->exposure, + ov05c->exposure->minimum, + max, ov05c->exposure->step, max); +break ; + } + +/* +* Applying V4L2 control value only happens +* when power is up for streaming +*/ +if (!pm_runtime_get_if_in_use (&client->dev)) +return 0 ; + +switch (ctrl->id) { +case V4L2_CID_ANALOGUE_GAIN : + ret =ov05c_update_analog_gain (ov05c, ctrl->val); +break ; +case V4L2_CID_DIGITAL_GAIN : + ret =ov05_update_digital_gain (ov05c, ctrl->val); +break ; +case V4L2_CID_EXPOSURE : + ret =ov05c_update_cid_exposure (ov05c, ctrl->val); +break ; +case V4L2_CID_VBLANK : + ret =ov05c_update_cid_vblank (ov05c, ctrl->val); +break ; +case V4L2_CID_TEST_PATTERN : + ret =ov05c_enable_test_pattern (ov05c, ctrl->val); +break ; +default : +dev_info (&client->dev, +"ctrl(id:0x%x,val:0x%x) is not handled\n" , + ctrl->id, ctrl->val); +break ; + } + +pm_runtime_put (&client->dev); + +return ret; +} + +static const struct v4l2_ctrl_ops ov05c_ctrl_ops = { + .s_ctrl = ov05c_set_ctrl, +}; + +static int ov05c_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 */ +if (code->index >0 ) +return -EINVAL ; + + code->code =MEDIA_BUS_FMT_SGRBG10_1X10 ; + +return 0 ; +} + +static int ov05c_enum_frame_size (struct v4l2_subdev *sd, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_frame_size_enum *fse) +{ +if (fse->index >=ARRAY_SIZE (supported_modes)) +return -EINVAL ; + +if (fse->code !=MEDIA_BUS_FMT_SGRBG10_1X10 ) +return -EINVAL ; + + fse->min_width = supported_modes[fse->index].width; + fse->max_width = fse->min_width; + fse->min_height = supported_modes[fse->index].height; + fse->max_height = fse->min_height; + +return 0 ; +} + +static void ov05c_update_pad_format (const struct ov05c_mode *mode, +struct v4l2_subdev_format *fmt) +{ + fmt->format.width = mode->width; + fmt->format.height = mode->height; + fmt->format.code =MEDIA_BUS_FMT_SGRBG10_1X10 ; + fmt->format.field =V4L2_FIELD_NONE ; +} + +static int ov05c_do_get_pad_format (struct ov05c *ov05c, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_format *fmt) +{ +struct v4l2_mbus_framefmt *framefmt; + +if (fmt->which ==V4L2_SUBDEV_FORMAT_TRY ) { + framefmt =v4l2_subdev_state_get_format (sd_state, fmt->pad); + fmt->format = *framefmt; + }else { +ov05c_update_pad_format (ov05c->cur_mode, fmt); + } + +return 0 ; +} + +static int ov05c_get_pad_format (struct v4l2_subdev *sd, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_format *fmt) +{ +struct ov05c *ov05c =to_ov05c (sd); +int ret; + +mutex_lock (&ov05c->mutex); + ret =ov05c_do_get_pad_format (ov05c, sd_state, fmt); +mutex_unlock (&ov05c->mutex); + +return ret; +} + +static int ov05c_set_pad_format (struct v4l2_subdev *sd, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_format *fmt) +{ +struct ov05c *ov05c =to_ov05c (sd); +const struct ov05c_mode *mode; +struct v4l2_mbus_framefmt *framefmt; +s32 vblank_def; +s32 vblank_min; +s64 h_blank; +s64 pixel_rate; +s64 link_freq; + +mutex_lock (&ov05c->mutex); + +/* Only one raw bayer(GRBG) order is supported */ +if (fmt->format.code !=MEDIA_BUS_FMT_SGRBG10_1X10 ) + fmt->format.code =MEDIA_BUS_FMT_SGRBG10_1X10 ; + + mode =v4l2_find_nearest_size (supported_modes, +ARRAY_SIZE (supported_modes), + width, height, + fmt->format.width, fmt->format.height); +ov05c_update_pad_format (mode, fmt); +if (fmt->which ==V4L2_SUBDEV_FORMAT_TRY ) { + framefmt =v4l2_subdev_state_get_format (sd_state, fmt->pad); + *framefmt = fmt->format; + }else { + ov05c->cur_mode = mode; +__v4l2_ctrl_s_ctrl (ov05c->link_freq, mode->link_freq_index); + link_freq = ov05c_link_freq_menu_items[mode->link_freq_index]; + pixel_rate =link_freq_to_pixel_rate (link_freq); +__v4l2_ctrl_s_ctrl_int64 (ov05c->pixel_rate, pixel_rate); + +/* Update limits and set FPS to default */ + vblank_def = ov05c->cur_mode->vts_def - + ov05c->cur_mode->height; + vblank_min = ov05c->cur_mode->vts_min - + ov05c->cur_mode->height; +__v4l2_ctrl_modify_range (ov05c->vblank, vblank_min, +OV05C_VTS_MAX + - ov05c->cur_mode->height, +1 , + vblank_def); +__v4l2_ctrl_s_ctrl (ov05c->vblank, vblank_def); + h_blank = ov05c->cur_mode->hts; +__v4l2_ctrl_modify_range (ov05c->hblank, h_blank, + h_blank,1 , h_blank); + } + +mutex_unlock (&ov05c->mutex); + +return 0 ; +} + +static int ov05c_start_streaming (struct ov05c *ov05c) +{ +struct i2c_client *client =v4l2_get_subdevdata (&ov05c->sd); +const struct ov05c_reg_list *reg_list; +int ret =0 ; + +/* Apply default values of current mode */ + reg_list = &ov05c->cur_mode->reg_list; +cci_multi_reg_write (ov05c->regmap, reg_list->regs, reg_list->num_of_regs, + &ret); +if (ret) { +dev_err (&client->dev,"%s failed to set mode, ret: %d\n" , __func__, ret); +return ret; + } + +/* Apply customized values from user */ + ret =__v4l2_ctrl_handler_setup (ov05c->sd.ctrl_handler); +if (ret) { +dev_err (&client->dev,"__v4l2_ctrl_handler_setup err:%d" , ret); +return ret; + } + +cci_multi_reg_write (ov05c->regmap, mode_OV05C_stream_on_regs, +ARRAY_SIZE (mode_OV05C_stream_on_regs), &ret); +if (ret) +dev_err (&client->dev,"%s failed to start the streaming\n" , __func__); + +return ret; +} + +static int ov05c_stop_streaming (struct ov05c *ov05c) +{ +int ret =0 ; +struct i2c_client *client =v4l2_get_subdevdata (&ov05c->sd); + +cci_multi_reg_write (ov05c->regmap, mode_OV05C_stream_off_regs, +ARRAY_SIZE (mode_OV05C_stream_off_regs), &ret); +if (ret) +dev_err (&client->dev,"%s failed to stop the streaming\n" , __func__); + +return ret; +} + +static void ov05c_sensor_enable (struct ov05c *ov05c,bool enable) +{ +if (enable) { +gpiod_set_value (ov05c->enable_gpio,0 ); +usleep_range (10 ,20 ); + +gpiod_set_value (ov05c->enable_gpio,1 ); +/* The delay is to make sure the sensor is completely turned on */ +usleep_range (1000 ,2000 ); + }else { +gpiod_set_value (ov05c->enable_gpio,0 ); +usleep_range (10 ,20 ); + } +} + +static int ov05c_set_stream (struct v4l2_subdev *sd,int enable) +{ +struct ov05c *ov05c =to_ov05c (sd); +struct i2c_client *client =v4l2_get_subdevdata (sd); +int ret =0 ; + +mutex_lock (&ov05c->mutex); + +if (enable) { +ov05c_sensor_enable (ov05c, true); + + ret =pm_runtime_resume_and_get (&client->dev); +if (ret <0 ) + goto err_unlock; + +/* +* Apply default & customized values +* and then start streaming. +*/ + ret =ov05c_start_streaming (ov05c); +if (ret) + goto err_rpm_put; + }else { +ov05c_stop_streaming (ov05c); +pm_runtime_put (&client->dev); + +ov05c_sensor_enable (ov05c, false); + } + +mutex_unlock (&ov05c->mutex); + +return ret; + +err_rpm_put: +pm_runtime_put (&client->dev); +err_unlock: +mutex_unlock (&ov05c->mutex); +
Quoted 9 lines
drivers/media/i2c/ov05c.c line 785
Quoted 5 lines
drivers/media/i2c/ov05c.c new file +5
-0+return ret; +} + +static const struct v4l2_subdev_video_ops ov05c_video_ops = { + .s_stream = ov05c_set_stream,Please implement the .enable_streams() and .disable_streams() operations instead.
thanks, implemented in V2.
Quoted 4 lines
Quoted 4 lines
drivers/media/i2c/ov05c.c new file +4
-0+}; + +static const struct v4l2_subdev_pad_ops ov05c_pad_ops = { + .enum_mbus_code = ov05c_enum_mbus_code,
Quoted 9 lines
drivers/media/i2c/ov05c.c line 790
Quoted 1 line
drivers/media/i2c/ov05c.c new file +1
-0+ .get_fmt = ov05c_get_pad_format,Use
v4l2_subdev_get_fmt()here and drop the manual implementation ofov05c_get_pad_format(). You will need to callv4l2_subdev_init_finalize()at probe time. You should then be able to drop the mutex in the ov05c structure, as the active state lock will be used to serialize everything. The imx219 driver is a possible example of how to do so.
thanks, replaced ov05c_get_pad_format() with v4l2_subdev_get_fmt() in V2.
Quoted 135 lines
Quoted 135 lines
drivers/media/i2c/ov05c.c new file +135
-0+ .set_fmt = ov05c_set_pad_format, + .enum_frame_size = ov05c_enum_frame_size, +}; + +static const struct v4l2_subdev_ops ov05c_subdev_ops = { + .video = &ov05c_video_ops, + .pad = &ov05c_pad_ops, +}; + +static const struct media_entity_operations ov05c_subdev_entity_ops = { + .link_validate = v4l2_subdev_link_validate, +}; + +static const struct v4l2_subdev_internal_ops ov05c_internal_ops = { + .open = ov05c_open, +}; + +static int ov05c_init_controls (struct ov05c *ov05c) +{ +struct i2c_client *client =v4l2_get_subdevdata (&ov05c->sd); +struct v4l2_fwnode_device_properties props; +struct v4l2_ctrl_handler *ctrl_hdlr; +const struct ov05c_mode *mode; +s64 exposure_max; +s64 vblank_def; +s64 vblank_min; +s64 hblank; +s64 pixel_rate_max; +u32 max_items; +int ret; + +/* Initialize V4L2 control handler with 10 items */ + ret =v4l2_ctrl_handler_init (&ov05c->ctrl_handler,10 ); +if (ret) +return ret; + ctrl_hdlr = &ov05c->ctrl_handler; + +/* Initialize mutex for serialization */ +mutex_init (&ov05c->mutex); + ctrl_hdlr->lock = &ov05c->mutex; + +/* Initialize Link frequency control item */ + max_items =ARRAY_SIZE (ov05c_link_freq_menu_items) -1 ; + ov05c->link_freq =v4l2_ctrl_new_int_menu (ctrl_hdlr, +NULL , +V4L2_CID_LINK_FREQ , + max_items, +0 , + ov05c_link_freq_menu_items); +if (ov05c->link_freq) + ov05c->link_freq->flags |=V4L2_CTRL_FLAG_READ_ONLY ; + +/* Initialize Pixel rate control item */ + pixel_rate_max =link_freq_to_pixel_rate (ov05c_link_freq_menu_items[0 ]); + ov05c->pixel_rate =v4l2_ctrl_new_std (ctrl_hdlr,NULL , +V4L2_CID_PIXEL_RATE , +0 , pixel_rate_max, +1 , pixel_rate_max); + +/* Initialize VBLANK control item */ + mode = ov05c->cur_mode; + vblank_def = mode->vts_def - mode->height; + vblank_min = mode->vts_min - mode->height; + ov05c->vblank =v4l2_ctrl_new_std (ctrl_hdlr, &ov05c_ctrl_ops, +V4L2_CID_VBLANK , + vblank_min,OV05C_VTS_MAX - mode->height, +1 , vblank_def); + +/* Initialize HBLANK control item */ + hblank =max (0 , ov05c->cur_mode->hts - ov05c->cur_mode->width); + ov05c->hblank =v4l2_ctrl_new_std (ctrl_hdlr,NULL , +V4L2_CID_HBLANK , + hblank, hblank,1 , hblank); +if (ov05c->hblank) + ov05c->hblank->flags |=V4L2_CTRL_FLAG_READ_ONLY ; + +/* Initialize EXPOSURE control item */ + exposure_max = mode->vts_def -OV05C_EXPOSURE_MAX_MARGIN ; + ov05c->exposure =v4l2_ctrl_new_std (ctrl_hdlr, &ov05c_ctrl_ops, +V4L2_CID_EXPOSURE , +OV05C_EXPOSURE_MIN , exposure_max, +OV05C_EXPOSURE_STEP , exposure_max); + +/* Initialize Analog gain control item */ +v4l2_ctrl_new_std (ctrl_hdlr, &ov05c_ctrl_ops,V4L2_CID_ANALOGUE_GAIN , +OV05C_ANA_GAIN_MIN ,OV05C_ANA_GAIN_MAX , +OV05C_ANA_GAIN_STEP ,OV05C_ANA_GAIN_DEFAULT ); + +/* Initialize Digital gain control item */ +v4l2_ctrl_new_std (ctrl_hdlr, &ov05c_ctrl_ops,V4L2_CID_DIGITAL_GAIN , +OV05C_DGTL_GAIN_MIN ,OV05C_DGTL_GAIN_MAX , +OV05C_DGTL_GAIN_STEP ,OV05C_DGTL_GAIN_DEFAULT ); + + +/* Initialize Test pattern control item */ +v4l2_ctrl_new_std_menu_items (ctrl_hdlr, &ov05c_ctrl_ops, +V4L2_CID_TEST_PATTERN , +ARRAY_SIZE (ov05c_test_pattern_menu) -1 ,0 , +0 , ov05c_test_pattern_menu); + +if (ctrl_hdlr->error) { + ret = ctrl_hdlr->error; +dev_err (&client->dev,"%s V4L2 control init failed (%d)" , __func__, ret); + goto error; + } + + ret =v4l2_fwnode_device_parse (&client->dev, &props); +if (ret) + goto error; + + ret =v4l2_ctrl_new_fwnode_properties (ctrl_hdlr, &ov05c_ctrl_ops, &props); +if (ret) + goto error; + + ov05c->sd.ctrl_handler = ctrl_hdlr; + +return 0 ; + +error: +v4l2_ctrl_handler_free (ctrl_hdlr); +mutex_destroy (&ov05c->mutex); + +return ret; +} + +static void ov05c_free_controls (struct ov05c *ov05c) +{ +v4l2_ctrl_handler_free (ov05c->sd.ctrl_handler); +mutex_destroy (&ov05c->mutex); +} + +static int ov05c_probe (struct i2c_client *client) +{ +struct ov05c *ov05c; +int i, ret;
Quoted 9 lines
drivers/media/i2c/ov05c.c line 931
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+ + ov05c =devm_kzalloc (&client->dev,sizeof (*ov05c),GFP_KERNEL ); +if (!ov05c) +return -ENOMEM ; + + client->dev.init_name =DRV_NAME ;That's unusual, why is it needed ?
yes, its not needed, removed it in V2.
Quoted 44 lines
Quoted 44 lines
drivers/media/i2c/ov05c.c new file +44
-0+ +/* create sensor enable gpio control */ + ov05c->enable_gpio =devm_gpiod_get (&client->dev,"sensor0_enable" ,GPIOD_OUT_LOW ); +if (IS_ERR_OR_NULL (ov05c->enable_gpio)) +return PTR_ERR (ov05c->enable_gpio); + +/* Initialize subdev */ +v4l2_i2c_subdev_init (&ov05c->sd, client, &ov05c_subdev_ops); + +/* Initialize CCI */ + ov05c->regmap =devm_cci_regmap_init_i2c (client,8 ); +if (IS_ERR (ov05c->regmap)) { +dev_err (&client->dev,"Failed to initialize CCI\n" ); +return PTR_ERR (ov05c->regmap); + } + +/* Set default mode to max resolution */ + ov05c->cur_mode = &supported_modes[0 ]; + +/* Initialize V4L2 controls */ + ret =ov05c_init_controls (ov05c); +if (ret) +return ret; + +/* Initialize V4L2 subdev */ + ov05c->sd.internal_ops = &ov05c_internal_ops; + ov05c->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; + ov05c->sd.entity.ops = &ov05c_subdev_entity_ops; + ov05c->sd.entity.function =MEDIA_ENT_F_CAM_SENSOR ; + ov05c->sd.entity.name ="OV05C" ; + +/* Initialize source pad */ +for (i =0 ; i <NUM_OF_PADS ; i++) + ov05c->pads[i].flags =MEDIA_PAD_FL_SOURCE ; + + ret =media_entity_pads_init (&ov05c->sd.entity,NUM_OF_PADS , ov05c->pads); +if (ret) + goto error_handler_free; + + ret =v4l2_async_register_subdev_sensor (&ov05c->sd); +if (ret) + goto error_media_entity; + +/*
Quoted 9 lines
drivers/media/i2c/ov05c.c line 981
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+* Device is already turned on by i2c-core with ACPI domain PM. +* Enable runtime PM and turn off the device. +*/ +pm_runtime_set_active (&client->dev); +pm_runtime_enable (&client->dev); +pm_runtime_idle (&client->dev);Please enable auto-suspend.
sure, enabled auto-suspend/resume in V2.
Quoted 5 lines
drivers/media/i2c/ov05c.c line 983
Quoted 2 lines
drivers/media/i2c/ov05c.c new file +2
-0+ +dev_info (&client->dev,"%s success" , __func__);This can be dropped.
Done. Removed in V2.
Quoted 39 lines
Quoted 39 lines
drivers/media/i2c/ov05c.c new file +39
-0+ +return 0 ; + +error_media_entity: +media_entity_cleanup (&ov05c->sd.entity); + +error_handler_free: +ov05c_free_controls (ov05c); + +return ret; +} + +static void ov05c_remove (struct i2c_client *client) +{ +struct v4l2_subdev *sd =i2c_get_clientdata (client); +struct ov05c *ov05c =to_ov05c (sd); + +v4l2_async_unregister_subdev (sd); +media_entity_cleanup (&sd->entity); +ov05c_free_controls (ov05c); + +pm_runtime_disable (&client->dev); +pm_runtime_set_suspended (&client->dev); +} + +static const struct i2c_device_id ov05c_id[] = { + {"ov05c" ,0 }, + { } +}; + +MODULE_DEVICE_TABLE (i2c, ov05c_id); + +static struct i2c_driver ov05c_i2c_driver = { + .driver = { + .name =DRV_NAME , + }, + .id_table = ov05c_id, + .probe = ov05c_probe, + .remove = ov05c_remove,
Quoted 9 lines
drivers/media/i2c/ov05c.c line 1028
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+}; + +module_i2c_driver (ov05c_i2c_driver); + +MODULE_AUTHOR ("Venkata Narendra Kumar Gutta <[email protected]>" ); +MODULE_AUTHOR ("Pratap Nirujogi <[email protected]>" );Should the patch have a SoB line for Venkata too ?
yes, its needed, added both Venkat's and Bin's SoB and CoB tags in V2.
Quoted 6 lines
drivers/media/i2c/ov05c.c line 1031
Quoted 3 lines
drivers/media/i2c/ov05c.c new file +3
-0+MODULE_DESCRIPTION ("OmniVision OV05C sensor driver" ); +MODULE_ALIAS ("ov05c" ); +MODULE_LICENSE ("GPL and additional rights" );Mismatch with the SPDX tag.
Done. Fixed in V2.
Quoted 4 lines
--
Regards,Laurent Pinchart
Hello Pratap,
Quoted 6 lines · Pratap
Hi Laurent,
Thanks for reviewing and extremely sorry for the delayed response. We have submitted V2 patch based on your review feedback.
Can you please help to review latest V2 patch and let us know your feedback.
Sure. It will take a bit of time though, as my review backlog is big. Please see below for additional comments.
Quoted 14 lines · Laurent Pinchart
Quoted 13 lines
Hi Pratap,
Thank you for the patch.
A few assorted comments to start with, I'll try to do a more in-depth review later.
Quoted 3 lines · Pratap Nirujogi
Add driver for OmniVision 5.2M OV05C10 sensor. This driver supports only the full size normal 2888x1808@30fps 2-lane sensor profile.
Quoted 6 lines
Quoted 2 lines
What have you tested this driver with ? I see no OF device ID or ACPI device ID.
We have tested this driver on the "AMD RYZEN AI MAX PRO 385 w/ Radeon 8050S" target supporting ISP HW v4.1. OMNI5C10 is ACPI HID for this sensor on the target.
That's interesting. Do you have plans to post a driver for the ISP ?
Quoted 6 lines
Quoted 1 line
Please provide a v4l2-compliance report.
Please refer the attached screenshot for the v4l2-compliance test report. This test is ran with V2 patch. Fixed some of the compliance test failures on V1 and ensured it is 100% compliant for the supported IOCTLS.
Could you please post the v4l2-compliance report in a reply to v2, in text format instead of a screenshot ?
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Signed-off-by Pratap Nirujogi <[email protected]>--- drivers/media/i2c/Kconfig | 10 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/ov05c.c | 1031 ++++++++++++++++++++++++++++++++++++
[snip]
Signature · 3 lines
Regards, Laurent Pinchart
Hi Laurent,
Thanks for your response.
Thanks,
Pratap
Quoted 6 lines · Laurent Pinchart
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Hello Pratap,
On Fri, Mar 28, 2025 at 06:10:41PM -0400, Nirujogi, Pratap wrote:
Quoted 8 lines
Quoted 6 lines
Hi Laurent,
Thanks for reviewing and extremely sorry for the delayed response. We have submitted V2 patch based on your review feedback.
Can you please help to review latest V2 patch and let us know your feedback.
Sure. It will take a bit of time though, as my review backlog is big.
Thanks for notifying us.
Quoted 16 lines
Please see below for additional comments.
Quoted 14 lines · Laurent Pinchart
Quoted 13 lines
Hi Pratap,
Thank you for the patch.
A few assorted comments to start with, I'll try to do a more in-depth review later.
Quoted 3 lines · Pratap Nirujogi
Add driver for OmniVision 5.2M OV05C10 sensor. This driver supports only the full size normal 2888x1808@30fps 2-lane sensor profile.
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
What have you tested this driver with ? I see no OF device ID or ACPI device ID.
We have tested this driver on the "AMD RYZEN AI MAX PRO 385 w/ Radeon 8050S" target supporting ISP HW v4.1. OMNI5C10 is ACPI HID for this sensor on the target.
That's interesting. Do you have plans to post a driver for the ISP ?
yes, we are planning to post the ISP driver patches once the dependent platform / sensor / i2c patches gets finalized after review.
Quoted 10 lines
Quoted 6 lines
Quoted 1 line
Please provide a v4l2-compliance report.
Please refer the attached screenshot for the v4l2-compliance test report. This test is ran with V2 patch. Fixed some of the compliance test failures on V1 and ensured it is 100% compliant for the supported IOCTLS.
Could you please post the v4l2-compliance report in a reply to v2, in text format instead of a screenshot ?
Sure, will share the report in text format in response to V2.
Quoted 12 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Signed-off-by Pratap Nirujogi <[email protected]>--- drivers/media/i2c/Kconfig | 10 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/ov05c.c | 1031 ++++++++++++++++++++++++++++++++++++[snip]
--
Regards,Laurent Pinchart
Quoted 65 lines · Pratap Nirujogi
Add driver for OmniVision 5.2M OV05C10 sensor. This driver supports only the full size normal 2888x1808@30fps 2-lane sensor profile.
Signed-off-by Pratap Nirujogi <[email protected]>--- drivers/media/i2c/Kconfig | 10 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/ov05c.c | 1031 ++++++++++++++++++++++++++++++++++++ 3 files changed, 1042 insertions(+) create mode 100644 drivers/media/i2c/ov05c.cdrivers/media/i2c/Kconfig +10
-0@@ -337,6 +337,16 @@ config VIDEO_OG01A1B To compile this driver as a module, choose M here: the module will be called og01a1b. +config VIDEO_OV05C + tristate "OmniVision OV05 sensor support" + select V4L2_CCI_I2C + help + This is a Video4Linux2 sensor driver for the OmniVision + OV05C camera. + + To compile this driver as a module, choose M here: the + module will be called OV05C. + config VIDEO_OV01A10 tristate "OmniVision OV01A10 sensor support" helpdrivers/media/i2c/Makefile +1
-0@@ -80,6 +80,7 @@ obj-$(CONFIG_VIDEO_MT9V011) += mt9v011.o obj-$(CONFIG_VIDEO_MT9V032) += mt9v032.o obj-$(CONFIG_VIDEO_MT9V111) += mt9v111.o obj-$(CONFIG_VIDEO_OG01A1B) += og01a1b.o +obj-$(CONFIG_VIDEO_OV05C) += ov05c.o obj-$(CONFIG_VIDEO_OV01A10) += ov01a10.o obj-$(CONFIG_VIDEO_OV02A10) += ov02a10.o obj-$(CONFIG_VIDEO_OV08D10) += ov08d10.odrivers/media/i2c/ov05c.c new file +14
-0@@ -0,0 +1,1031 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. +* All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sub license, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice (including the
drivers/media/i2c/ov05c.c line 24
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+* next paragraph) shall be included in all copies or substantial portions +* of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +* USE OR OTHER DEALINGS IN THE SOFTWARE.
What's with AMD? Second patch that day, same issues.
Drop license boilerplate.
Quoted 14 lines
drivers/media/i2c/ov05c.c new file +14
-0+* +*/ + +#include <linux/acpi.h> +#include <linux/i2c.h> +#include <linux/module.h> +#include <linux/delay.h> +#include <linux/units.h> +#include <linux/pm_runtime.h> +#include <linux/gpio.h> +#include <media/v4l2-ctrls.h> +#include <media/v4l2-device.h> +#include <media/v4l2-fwnode.h> +#include <media/v4l2-cci.h>
...
Quoted 4 lines
drivers/media/i2c/ov05c.c new file +4
-0+ +static int ov05c_probe (struct i2c_client *client) +{ +struct ov05c *ov05c;
drivers/media/i2c/ov05c.c line 934
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+int i, ret; + + ov05c =devm_kzalloc (&client->dev,sizeof (*ov05c),GFP_KERNEL ); +if (!ov05c) +return -ENOMEM ; + + client->dev.init_name =DRV_NAME ; + +/* create sensor enable gpio control */ + ov05c->enable_gpio =devm_gpiod_get (&client->dev,"sensor0_enable" ,GPIOD_OUT_LOW );
s/sensor0_enable/enable/
drivers/media/i2c/ov05c.c line 944
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+if (IS_ERR_OR_NULL (ov05c->enable_gpio)) +return PTR_ERR (ov05c->enable_gpio); + +/* Initialize subdev */ +v4l2_i2c_subdev_init (&ov05c->sd, client, &ov05c_subdev_ops); + +/* Initialize CCI */ + ov05c->regmap =devm_cci_regmap_init_i2c (client,8 ); +if (IS_ERR (ov05c->regmap)) { +dev_err (&client->dev,"Failed to initialize CCI\n" );
Syntax is: return dev_err_probe
Quoted 29 lines
drivers/media/i2c/ov05c.c new file +29
-0+return PTR_ERR (ov05c->regmap); + } + +/* Set default mode to max resolution */ + ov05c->cur_mode = &supported_modes[0 ]; + +/* Initialize V4L2 controls */ + ret =ov05c_init_controls (ov05c); +if (ret) +return ret; + +/* Initialize V4L2 subdev */ + ov05c->sd.internal_ops = &ov05c_internal_ops; + ov05c->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; + ov05c->sd.entity.ops = &ov05c_subdev_entity_ops; + ov05c->sd.entity.function =MEDIA_ENT_F_CAM_SENSOR ; + ov05c->sd.entity.name ="OV05C" ; + +/* Initialize source pad */ +for (i =0 ; i <NUM_OF_PADS ; i++) + ov05c->pads[i].flags =MEDIA_PAD_FL_SOURCE ; + + ret =media_entity_pads_init (&ov05c->sd.entity,NUM_OF_PADS , ov05c->pads); +if (ret) + goto error_handler_free; + + ret =v4l2_async_register_subdev_sensor (&ov05c->sd); +if (ret) + goto error_media_entity;
drivers/media/i2c/ov05c.c line 983
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+ +/* +* Device is already turned on by i2c-core with ACPI domain PM. +* Enable runtime PM and turn off the device. +*/ +pm_runtime_set_active (&client->dev); +pm_runtime_enable (&client->dev); +pm_runtime_idle (&client->dev); + +dev_info (&client->dev,"%s success" , __func__);
Drop, useless. Kernel has infrastructure for simple function exit debugging. For probing as well.
Quoted 37 lines
drivers/media/i2c/ov05c.c new file +37
-0+ +return 0 ; + +error_media_entity: +media_entity_cleanup (&ov05c->sd.entity); + +error_handler_free: +ov05c_free_controls (ov05c); + +return ret; +} + +static void ov05c_remove (struct i2c_client *client) +{ +struct v4l2_subdev *sd =i2c_get_clientdata (client); +struct ov05c *ov05c =to_ov05c (sd); + +v4l2_async_unregister_subdev (sd); +media_entity_cleanup (&sd->entity); +ov05c_free_controls (ov05c); + +pm_runtime_disable (&client->dev); +pm_runtime_set_suspended (&client->dev); +} + +static const struct i2c_device_id ov05c_id[] = { + {"ov05c" ,0 }, + { } +}; + +MODULE_DEVICE_TABLE (i2c, ov05c_id); + +static struct i2c_driver ov05c_i2c_driver = { + .driver = { + .name =DRV_NAME , + }, + .id_table = ov05c_id,
drivers/media/i2c/ov05c.c line 1030
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+ .probe = ov05c_probe, + .remove = ov05c_remove, +}; + +module_i2c_driver (ov05c_i2c_driver); + +MODULE_AUTHOR ("Venkata Narendra Kumar Gutta <[email protected]>" ); +MODULE_AUTHOR ("Pratap Nirujogi <[email protected]>" ); +MODULE_DESCRIPTION ("OmniVision OV05C sensor driver" ); +MODULE_ALIAS ("ov05c" );
Drop, not correct alias.
Quoted 1 line
+MODULE_LICENSE("GPL and additional rights");
No, use proper license and matching tag. Your top said this is not GPL!
Best regards,
Krzysztof
Hi Krzysztof,
Thanks for reviewing and extremely sorry for the delayed response.
We have submitted V2 patch based on the review feedback. Can you please help to review latest V2 patch and let us know your feedback.
Thanks,
Pratap
Quoted 82 lines · Krzysztof Kozlowski
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Quoted 65 lines · Pratap Nirujogi
Add driver for OmniVision 5.2M OV05C10 sensor. This driver supports only the full size normal 2888x1808@30fps 2-lane sensor profile.
Signed-off-by Pratap Nirujogi <[email protected]>--- drivers/media/i2c/Kconfig | 10 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/ov05c.c | 1031 ++++++++++++++++++++++++++++++++++++ 3 files changed, 1042 insertions(+)create mode 100644
drivers/media/i2c/ov05c.cdrivers/media/i2c/Kconfig +10
-0@@ -337,6 +337,16 @@ config VIDEO_OG01A1B To compile this driver as a module, choose M here: the module will be called og01a1b. +config VIDEO_OV05C + tristate "OmniVision OV05 sensor support" + select V4L2_CCI_I2C + help + This is a Video4Linux2 sensor driver for the OmniVision + OV05C camera. + + To compile this driver as a module, choose M here: the + module will be called OV05C. + config VIDEO_OV01A10 tristate "OmniVision OV01A10 sensor support" helpdrivers/media/i2c/Makefile +1
-0@@ -80,6 +80,7 @@ obj-$(CONFIG_VIDEO_MT9V011) += mt9v011.o obj-$(CONFIG_VIDEO_MT9V032) += mt9v032.o obj-$(CONFIG_VIDEO_MT9V111) += mt9v111.o obj-$(CONFIG_VIDEO_OG01A1B) += og01a1b.o +obj-$(CONFIG_VIDEO_OV05C) += ov05c.o obj-$(CONFIG_VIDEO_OV01A10) += ov01a10.o obj-$(CONFIG_VIDEO_OV02A10) += ov02a10.o obj-$(CONFIG_VIDEO_OV08D10) += ov08d10.odrivers/media/i2c/ov05c.c new file +14
-0@@ -0,0 +1,1031 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. +* All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sub license, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice (including the drivers/media/i2c/ov05c.c line 24
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+* next paragraph) shall be included in all copies or substantial portions +* of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +* USE OR OTHER DEALINGS IN THE SOFTWARE. What's with AMD? Second patch that day, same issues.
Quoted 2 lines
Drop license boilerplate.
Done. Updated copyright header and license in V2.
Quoted 27 lines
Quoted 14 lines
drivers/media/i2c/ov05c.c new file +14
-0+* +*/ + +#include <linux/acpi.h> +#include <linux/i2c.h> +#include <linux/module.h> +#include <linux/delay.h> +#include <linux/units.h> +#include <linux/pm_runtime.h> +#include <linux/gpio.h> +#include <media/v4l2-ctrls.h> +#include <media/v4l2-device.h> +#include <media/v4l2-fwnode.h> +#include <media/v4l2-cci.h> ...
Quoted 9 lines
drivers/media/i2c/ov05c.c new file +9
-0+ +static int ov05c_probe (struct i2c_client *client) +{ +struct ov05c *ov05c; +int i, ret; + + ov05c =devm_kzalloc (&client->dev,sizeof (*ov05c),GFP_KERNEL ); +if (!ov05c) +return -ENOMEM ;
Quoted 9 lines
drivers/media/i2c/ov05c.c line 934
Quoted 5 lines
drivers/media/i2c/ov05c.c new file +5
-0+ + client->dev.init_name =DRV_NAME ; + +/* create sensor enable gpio control */ + ov05c->enable_gpio =devm_gpiod_get (&client->dev,"sensor0_enable" ,GPIOD_OUT_LOW );s/sensor0_enable/enable/
Is it okay to use "sensor0_enabled" as connection id? We used this name to differentiate the two GPIO PINs that has to be programmed for RGB streaming to work with this sensor.
Quoted 4 lines
Quoted 4 lines
drivers/media/i2c/ov05c.c new file +4
-0+if (IS_ERR_OR_NULL (ov05c->enable_gpio)) +return PTR_ERR (ov05c->enable_gpio); + +/* Initialize subdev */
Quoted 9 lines
drivers/media/i2c/ov05c.c line 944
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+v4l2_i2c_subdev_init (&ov05c->sd, client, &ov05c_subdev_ops); + +/* Initialize CCI */ + ov05c->regmap =devm_cci_regmap_init_i2c (client,8 ); +if (IS_ERR (ov05c->regmap)) { +dev_err (&client->dev,"Failed to initialize CCI\n" );Syntax is: return
dev_err_probe
Done. Updated in V2.
Quoted 34 lines
Quoted 34 lines
drivers/media/i2c/ov05c.c new file +34
-0+return PTR_ERR (ov05c->regmap); + } + +/* Set default mode to max resolution */ + ov05c->cur_mode = &supported_modes[0 ]; + +/* Initialize V4L2 controls */ + ret =ov05c_init_controls (ov05c); +if (ret) +return ret; + +/* Initialize V4L2 subdev */ + ov05c->sd.internal_ops = &ov05c_internal_ops; + ov05c->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; + ov05c->sd.entity.ops = &ov05c_subdev_entity_ops; + ov05c->sd.entity.function =MEDIA_ENT_F_CAM_SENSOR ; + ov05c->sd.entity.name ="OV05C" ; + +/* Initialize source pad */ +for (i =0 ; i <NUM_OF_PADS ; i++) + ov05c->pads[i].flags =MEDIA_PAD_FL_SOURCE ; + + ret =media_entity_pads_init (&ov05c->sd.entity,NUM_OF_PADS , ov05c->pads); +if (ret) + goto error_handler_free; + + ret =v4l2_async_register_subdev_sensor (&ov05c->sd); +if (ret) + goto error_media_entity; + +/* +* Device is already turned on by i2c-core with ACPI domain PM. +* Enable runtime PM and turn off the device. +*/
Quoted 9 lines
drivers/media/i2c/ov05c.c line 983
Quoted 5 lines
drivers/media/i2c/ov05c.c new file +5
-0+pm_runtime_set_active (&client->dev); +pm_runtime_enable (&client->dev); +pm_runtime_idle (&client->dev); + +dev_info (&client->dev,"%s success" , __func__);Drop, useless. Kernel has infrastructure for simple function exit debugging. For probing as well.
Done. Removed in V2.
Quoted 41 lines
Quoted 41 lines
drivers/media/i2c/ov05c.c new file +41
-0+ +return 0 ; + +error_media_entity: +media_entity_cleanup (&ov05c->sd.entity); + +error_handler_free: +ov05c_free_controls (ov05c); + +return ret; +} + +static void ov05c_remove (struct i2c_client *client) +{ +struct v4l2_subdev *sd =i2c_get_clientdata (client); +struct ov05c *ov05c =to_ov05c (sd); + +v4l2_async_unregister_subdev (sd); +media_entity_cleanup (&sd->entity); +ov05c_free_controls (ov05c); + +pm_runtime_disable (&client->dev); +pm_runtime_set_suspended (&client->dev); +} + +static const struct i2c_device_id ov05c_id[] = { + {"ov05c" ,0 }, + { } +}; + +MODULE_DEVICE_TABLE (i2c, ov05c_id); + +static struct i2c_driver ov05c_i2c_driver = { + .driver = { + .name =DRV_NAME , + }, + .id_table = ov05c_id, + .probe = ov05c_probe, + .remove = ov05c_remove, +}; +
Quoted 9 lines
drivers/media/i2c/ov05c.c line 1030
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+module_i2c_driver (ov05c_i2c_driver); + +MODULE_AUTHOR ("Venkata Narendra Kumar Gutta <[email protected]>" ); +MODULE_AUTHOR ("Pratap Nirujogi <[email protected]>" ); +MODULE_DESCRIPTION ("OmniVision OV05C sensor driver" ); +MODULE_ALIAS ("ov05c" );Drop, not correct alias.
Done. Removed in V2.
Quoted 4 lines
Quoted 1 line
+MODULE_LICENSE("GPL and additional rights");
No, use proper license and matching tag. Your top said this is not GPL!
Done. Updated to "GPL v2" in V2.
Quoted 3 lines
Best regards,
Krzysztof
Quoted 133 lines · Pratap
Hi Krzysztof,
Thanks for reviewing and extremely sorry for the delayed response.
We have submitted V2 patch based on the review feedback. Can you please help to review latest V2 patch and let us know your feedback.
Thanks,
PratapQuoted 82 lines · Krzysztof Kozlowski
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Quoted 65 lines · Pratap Nirujogi
Add driver for OmniVision 5.2M OV05C10 sensor. This driver supports only the full size normal 2888x1808@30fps 2-lane sensor profile.
Signed-off-by Pratap Nirujogi <[email protected]>--- drivers/media/i2c/Kconfig | 10 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/ov05c.c | 1031 ++++++++++++++++++++++++++++++++++++ 3 files changed, 1042 insertions(+)create mode 100644
drivers/media/i2c/ov05c.cdrivers/media/i2c/Kconfig +10
-0@@ -337,6 +337,16 @@ config VIDEO_OG01A1B To compile this driver as a module, choose M here: the module will be called og01a1b. +config VIDEO_OV05C + tristate "OmniVision OV05 sensor support" + select V4L2_CCI_I2C + help + This is a Video4Linux2 sensor driver for the OmniVision + OV05C camera. + + To compile this driver as a module, choose M here: the + module will be called OV05C. + config VIDEO_OV01A10 tristate "OmniVision OV01A10 sensor support" helpdrivers/media/i2c/Makefile +1
-0@@ -80,6 +80,7 @@ obj-$(CONFIG_VIDEO_MT9V011) += mt9v011.o obj-$(CONFIG_VIDEO_MT9V032) += mt9v032.o obj-$(CONFIG_VIDEO_MT9V111) += mt9v111.o obj-$(CONFIG_VIDEO_OG01A1B) += og01a1b.o +obj-$(CONFIG_VIDEO_OV05C) += ov05c.o obj-$(CONFIG_VIDEO_OV01A10) += ov01a10.o obj-$(CONFIG_VIDEO_OV02A10) += ov02a10.o obj-$(CONFIG_VIDEO_OV08D10) += ov08d10.odrivers/media/i2c/ov05c.c new file +14
-0@@ -0,0 +1,1031 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. +* All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sub license, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice (including the drivers/media/i2c/ov05c.c line 24
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+* next paragraph) shall be included in all copies or substantial portions +* of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +* USE OR OTHER DEALINGS IN THE SOFTWARE. What's with AMD? Second patch that day, same issues.
Quoted 2 lines
Drop license boilerplate.
Done. Updated copyright header and license in V2.
Quoted 27 lines
Quoted 14 lines
drivers/media/i2c/ov05c.c new file +14
-0+* +*/ + +#include <linux/acpi.h> +#include <linux/i2c.h> +#include <linux/module.h> +#include <linux/delay.h> +#include <linux/units.h> +#include <linux/pm_runtime.h> +#include <linux/gpio.h> +#include <media/v4l2-ctrls.h> +#include <media/v4l2-device.h> +#include <media/v4l2-fwnode.h> +#include <media/v4l2-cci.h> ...
Quoted 9 lines
drivers/media/i2c/ov05c.c new file +9
-0+ +static int ov05c_probe (struct i2c_client *client) +{ +struct ov05c *ov05c; +int i, ret; + + ov05c =devm_kzalloc (&client->dev,sizeof (*ov05c),GFP_KERNEL ); +if (!ov05c) +return -ENOMEM ;Quoted 9 lines
drivers/media/i2c/ov05c.c line 934
Quoted 5 lines
drivers/media/i2c/ov05c.c new file +5
-0+ + client->dev.init_name =DRV_NAME ; + +/* create sensor enable gpio control */ + ov05c->enable_gpio =devm_gpiod_get (&client->dev,"sensor0_enable" ,GPIOD_OUT_LOW );s/sensor0_enable/enable/
Quoted 3 lines
Is it okay to use "
sensor0_enabled" as connection id? We used this name to differentiate the two GPIO PINs that has to be programmed for RGB streaming to work with this sensor.
How much time did you give me to respond here? 20 minutes. In the middle of my night. And then you send v2, without waiting for my answer.
That's not acceptable for me.
Best regards,
Krzysztof
Quoted 137 lines · Krzysztof Kozlowski
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Quoted 133 lines · Pratap
Hi Krzysztof,
Thanks for reviewing and extremely sorry for the delayed response.
We have submitted V2 patch based on the review feedback. Can you please help to review latest V2 patch and let us know your feedback.
Thanks,
PratapQuoted 82 lines · Krzysztof Kozlowski
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Quoted 65 lines · Pratap Nirujogi
Add driver for OmniVision 5.2M OV05C10 sensor. This driver supports only the full size normal 2888x1808@30fps 2-lane sensor profile.
Signed-off-by Pratap Nirujogi <[email protected]>--- drivers/media/i2c/Kconfig | 10 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/ov05c.c | 1031 ++++++++++++++++++++++++++++++++++++ 3 files changed, 1042 insertions(+)create mode 100644
drivers/media/i2c/ov05c.cdrivers/media/i2c/Kconfig +10
-0@@ -337,6 +337,16 @@ config VIDEO_OG01A1B To compile this driver as a module, choose M here: the module will be called og01a1b. +config VIDEO_OV05C + tristate "OmniVision OV05 sensor support" + select V4L2_CCI_I2C + help + This is a Video4Linux2 sensor driver for the OmniVision + OV05C camera. + + To compile this driver as a module, choose M here: the + module will be called OV05C. + config VIDEO_OV01A10 tristate "OmniVision OV01A10 sensor support" helpdrivers/media/i2c/Makefile +1
-0@@ -80,6 +80,7 @@ obj-$(CONFIG_VIDEO_MT9V011) += mt9v011.o obj-$(CONFIG_VIDEO_MT9V032) += mt9v032.o obj-$(CONFIG_VIDEO_MT9V111) += mt9v111.o obj-$(CONFIG_VIDEO_OG01A1B) += og01a1b.o +obj-$(CONFIG_VIDEO_OV05C) += ov05c.o obj-$(CONFIG_VIDEO_OV01A10) += ov01a10.o obj-$(CONFIG_VIDEO_OV02A10) += ov02a10.o obj-$(CONFIG_VIDEO_OV08D10) += ov08d10.odrivers/media/i2c/ov05c.c new file +14
-0@@ -0,0 +1,1031 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. +* All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sub license, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice (including the drivers/media/i2c/ov05c.c line 24
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+* next paragraph) shall be included in all copies or substantial portions +* of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +* USE OR OTHER DEALINGS IN THE SOFTWARE. What's with AMD? Second patch that day, same issues.
Quoted 2 lines
Drop license boilerplate.
Done. Updated copyright header and license in V2.
Quoted 36 lines
Quoted 14 lines
drivers/media/i2c/ov05c.c new file +14
-0+* +*/ + +#include <linux/acpi.h> +#include <linux/i2c.h> +#include <linux/module.h> +#include <linux/delay.h> +#include <linux/units.h> +#include <linux/pm_runtime.h> +#include <linux/gpio.h> +#include <media/v4l2-ctrls.h> +#include <media/v4l2-device.h> +#include <media/v4l2-fwnode.h> +#include <media/v4l2-cci.h> ...
Quoted 4 lines
drivers/media/i2c/ov05c.c new file +4
-0+ +static int ov05c_probe (struct i2c_client *client) +{ +struct ov05c *ov05c;drivers/media/i2c/ov05c.c line 934
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+int i, ret; + + ov05c =devm_kzalloc (&client->dev,sizeof (*ov05c),GFP_KERNEL ); +if (!ov05c) +return -ENOMEM ; + + client->dev.init_name =DRV_NAME ; + +/* create sensor enable gpio control */ + ov05c->enable_gpio =devm_gpiod_get (&client->dev,"sensor0_enable" ,GPIOD_OUT_LOW );s/sensor0_enable/enable/
Quoted 9 lines
Quoted 3 lines
Is it okay to use "
sensor0_enabled" as connection id? We used this name to differentiate the two GPIO PINs that has to be programmed for RGB streaming to work with this sensor.How much time did you give me to respond here? 20 minutes. In the middle of my night. And then you send v2, without waiting for my answer.
That's not acceptable for me.
My apologies for the inconvenience caused.
Quoted 2 lines
Best regards,
Krzysztof
Sakari Ailus
maintainerHi Pratap,
Thanks for the patch.
Quoted 19 lines · Pratap Nirujogi
Add driver for OmniVision 5.2M OV05C10 sensor. This driver supports only the full size normal 2888x1808@30fps 2-lane sensor profile.
Signed-off-by Pratap Nirujogi <[email protected]>--- drivers/media/i2c/Kconfig | 10 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/ov05c.c | 1031 ++++++++++++++++++++++++++++++++++++ 3 files changed, 1042 insertions(+) create mode 100644 drivers/media/i2c/ov05c.cdrivers/media/i2c/Kconfig +0
-0@@ -337,6 +337,16 @@ config VIDEO_OG01A1B To compile this driver as a module, choose M here: the module will be called og01a1b.
drivers/media/i2c/Kconfig config VIDEO_OG01A1B · line 348
Quoted 10 lines
drivers/media/i2c/Kconfig +9
-0+config VIDEO_OV05C + tristate "OmniVision OV05 sensor support" + select V4L2_CCI_I2C + help + This is a Video4Linux2 sensor driver for the OmniVision + OV05C camera. + + To compile this driver as a module, choose M here: the + module will be called OV05C.
Omnivision has typically named their sensors as /ov[0-9]{2}.[0-9]{2}/ and this does not follow that pattern. Is ov05c the full name of the chip?
Quoted 22 lines
drivers/media/i2c/Kconfig +1
-0+ config VIDEO_OV01A10 tristate "OmniVision OV01A10 sensor support" helpdrivers/media/i2c/Makefile +1
-0@@ -80,6 +80,7 @@ obj-$(CONFIG_VIDEO_MT9V011) += mt9v011.o obj-$(CONFIG_VIDEO_MT9V032) += mt9v032.o obj-$(CONFIG_VIDEO_MT9V111) += mt9v111.o obj-$(CONFIG_VIDEO_OG01A1B) += og01a1b.o +obj-$(CONFIG_VIDEO_OV05C) += ov05c.o obj-$(CONFIG_VIDEO_OV01A10) += ov01a10.o obj-$(CONFIG_VIDEO_OV02A10) += ov02a10.o obj-$(CONFIG_VIDEO_OV08D10) += ov08d10.odrivers/media/i2c/ov05c.c new file +0
-0
drivers/media/i2c/ov05c.c line 1
Quoted 1 line
drivers/media/i2c/ov05c.c new file +1
-0@@ -0,0 +1,1031 @@ +/* SPDX-License-Identifier: MIT */
No GPL? Huh?
Quoted 17 lines
drivers/media/i2c/ov05c.c new file +17
-0+/* +* Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. +* All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sub license, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice (including the +* next paragraph) shall be included in all copies or substantial portions +* of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
drivers/media/i2c/ov05c.c line 28
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +* USE OR OTHER DEALINGS IN THE SOFTWARE. +* +*/ + +#include <linux/acpi.h>
I don't think you need this for anything right now.
drivers/media/i2c/ov05c.c line 38
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+#include <linux/i2c.h> +#include <linux/module.h> +#include <linux/delay.h> +#include <linux/units.h> +#include <linux/pm_runtime.h> +#include <linux/gpio.h> +#include <media/v4l2-ctrls.h> +#include <media/v4l2-device.h> +#include <media/v4l2-fwnode.h> +#include <media/v4l2-cci.h>
Alphabetical order, please.
drivers/media/i2c/ov05c.c line 44
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+ +#define DRV_NAME "ov05c" + +/* Chip ID */ +#define OV05C_REG_CHIP_ID CCI_REG24(0x00) +#define OV05C_CHIP_ID 0x430556
What about the fourth chip ID register?
Quoted 25 lines
drivers/media/i2c/ov05c.c new file +25
-0+ +/* Control registers */ +#define OV05C_REG_PAGE_CTL CCI_REG8(0xFD) +#define OV05C_REG_TRIGGER CCI_REG8(0x01) + +/* V_TIMING internal */ +#define OV05C_REG_VTS CCI_REG16(0x05) +#define OV05C_VTS_30FPS 1860 +#define OV05C_VTS_MAX 0x7fff + +/* H TIMING internal */ +#define OV05C_REG_HTS CCI_REG16(0x37) +#define OV05C_HTS_30FPS 0x0280 + +/* Exposure control */ +#define OV05C_REG_EXPOSURE CCI_REG24(0x02) +#define OV05C_EXPOSURE_MAX_MARGIN 33 +#define OV05C_EXPOSURE_MIN 4 +#define OV05C_EXPOSURE_STEP 1 +#define OV05C_EXPOSURE_DEFAULT 0x40 + +/* Analog gain control */ +#define OV05C_REG_ANALOG_GAIN CCI_REG8(0x24) +#define OV05C_ANA_GAIN_MIN 0x80 +#define OV05C_ANA_GAIN_MAX 0x07c0
drivers/media/i2c/ov05c.c line 79
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+#define OV05C_ANA_GAIN_STEP 1 +#define OV05C_ANA_GAIN_DEFAULT 0x80 + +/* Digital gain control */ +#define OV05C_REG_DGTL_GAIN_H CCI_REG8(0x21) +#define OV05C_REG_DGTL_GAIN_L CCI_REG8(0x22) + +#define OV05C_DGTL_GAIN_MIN 64/* Min = 1 X */ +#define OV05C_DGTL_GAIN_MAX (256 - 1)/* Max = 4 X */ +#define OV05C_DGTL_GAIN_DEFAULT 0x80/* Default gain = 2x */
It seems the default digital gain is 2x. Why not 1x?
Quoted 43 lines
drivers/media/i2c/ov05c.c new file +43
-0+#define OV05C_DGTL_GAIN_STEP 1/* Each step = 1/64 */ + +#define OV05C_DGTL_GAIN_L_MASK 0xFF +#define OV05C_DGTL_GAIN_H_SHIFT 8 +#define OV05C_DGTL_GAIN_H_MASK 0xFF00 + +/* Test Pattern Control */ +#define OV05C_REG_TEST_PATTERN_CTL CCI_REG8(0xF3) +#define OV05C_REG_TEST_PATTERN CCI_REG8(0x12) +#define OV05C_TEST_PATTERN_ENABLE BIT(0) + +#define NUM_OF_PADS 3 + +enum { +OV05C_LINK_FREQ_900MHZ_INDEX , +}; + +struct ov05c_reg_list { +u32 num_of_regs; +const struct cci_reg_sequence *regs; +}; + +/* Link frequency config */ +struct ov05c_link_freq_config { +/* registers for this link frequency */ +struct ov05c_reg_list reg_list; +}; + +/* Mode : resolution and related config&values */ +struct ov05c_mode { +/* Frame width */ +u32 width; +/* Frame height */ +u32 height; +/* number of lanes */ +u32 lanes; + +/* V-timing */ +u32 vts_def; +u32 vts_min; + +/* HTS */ +u32 hts;
drivers/media/i2c/ov05c.c line 132
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+ +/* Index of Link frequency config to be used */ +u32 link_freq_index; + +/* Default register values */ +struct ov05c_reg_list reg_list; +}; + +static const struct cci_reg_sequence + mode_2888_1808_30fps_1800mbps_2lane_24mhz_regs[] = {
I'm not sure what checkpatch.pl says about this but I'd wrap before "struct".
Do you think you could separate mode specific registers from the link frequency/lane configuration and common settings?
Quoted 235 lines
drivers/media/i2c/ov05c.c new file +235
-0+ { CCI_REG8(0xfd), 0x00 }, + { CCI_REG8(0x20), 0x00 }, + { CCI_REG8(0xfd), 0x00 }, + { CCI_REG8(0x20), 0x0b }, + { CCI_REG8(0xc1), 0x09 }, + { CCI_REG8(0x21), 0x06 }, + { CCI_REG8(0x14), 0x78 }, + { CCI_REG8(0xe7), 0x03 }, + { CCI_REG8(0xe7), 0x00 }, + { CCI_REG8(0x21), 0x00 }, + { CCI_REG8(0xfd), 0x01 }, + { CCI_REG8(0x03), 0x00 }, + { CCI_REG8(0x04), 0x06 }, + { CCI_REG8(0x05), 0x07 }, + { CCI_REG8(0x06), 0x44 }, + { CCI_REG8(0x07), 0x08 }, + { CCI_REG8(0x1b), 0x01 }, + { CCI_REG8(0x24), 0xff }, + { CCI_REG8(0x32), 0x03 }, + { CCI_REG8(0x42), 0x5d }, + { CCI_REG8(0x43), 0x08 }, + { CCI_REG8(0x44), 0x81 }, + { CCI_REG8(0x46), 0x5f }, + { CCI_REG8(0x48), 0x18 }, + { CCI_REG8(0x49), 0x04 }, + { CCI_REG8(0x5c), 0x18 }, + { CCI_REG8(0x5e), 0x13 }, + { CCI_REG8(0x70), 0x15 }, + { CCI_REG8(0x77), 0x35 }, + { CCI_REG8(0x79), 0x00 }, + { CCI_REG8(0x7b), 0x08 }, + { CCI_REG8(0x7d), 0x08 }, + { CCI_REG8(0x7e), 0x08 }, + { CCI_REG8(0x7f), 0x08 }, + { CCI_REG8(0x90), 0x37 }, + { CCI_REG8(0x91), 0x05 }, + { CCI_REG8(0x92), 0x18 }, + { CCI_REG8(0x93), 0x27 }, + { CCI_REG8(0x94), 0x05 }, + { CCI_REG8(0x95), 0x38 }, + { CCI_REG8(0x9b), 0x00 }, + { CCI_REG8(0x9c), 0x06 }, + { CCI_REG8(0x9d), 0x28 }, + { CCI_REG8(0x9e), 0x06 }, + { CCI_REG8(0xb2), 0x0f }, + { CCI_REG8(0xb3), 0x29 }, + { CCI_REG8(0xbf), 0x3c }, + { CCI_REG8(0xc2), 0x04 }, + { CCI_REG8(0xc4), 0x00 }, + { CCI_REG8(0xca), 0x20 }, + { CCI_REG8(0xcb), 0x20 }, + { CCI_REG8(0xcc), 0x28 }, + { CCI_REG8(0xcd), 0x28 }, + { CCI_REG8(0xce), 0x20 }, + { CCI_REG8(0xcf), 0x20 }, + { CCI_REG8(0xd0), 0x2a }, + { CCI_REG8(0xd1), 0x2a }, + { CCI_REG8(0xfd), 0x0f }, + { CCI_REG8(0x00), 0x00 }, + { CCI_REG8(0x01), 0xa0 }, + { CCI_REG8(0x02), 0x48 }, + { CCI_REG8(0x07), 0x8f }, + { CCI_REG8(0x08), 0x70 }, + { CCI_REG8(0x09), 0x01 }, + { CCI_REG8(0x0b), 0x40 }, + { CCI_REG8(0x0d), 0x07 }, + { CCI_REG8(0x11), 0x33 }, + { CCI_REG8(0x12), 0x77 }, + { CCI_REG8(0x13), 0x66 }, + { CCI_REG8(0x14), 0x65 }, + { CCI_REG8(0x15), 0x37 }, + { CCI_REG8(0x16), 0xbf }, + { CCI_REG8(0x17), 0xff }, + { CCI_REG8(0x18), 0xff }, + { CCI_REG8(0x19), 0x12 }, + { CCI_REG8(0x1a), 0x10 }, + { CCI_REG8(0x1c), 0x77 }, + { CCI_REG8(0x1d), 0x77 }, + { CCI_REG8(0x20), 0x0f }, + { CCI_REG8(0x21), 0x0f }, + { CCI_REG8(0x22), 0x0f }, + { CCI_REG8(0x23), 0x0f }, + { CCI_REG8(0x2b), 0x20 }, + { CCI_REG8(0x2c), 0x20 }, + { CCI_REG8(0x2d), 0x04 }, + { CCI_REG8(0xfd), 0x03 }, + { CCI_REG8(0x9d), 0x0f }, + { CCI_REG8(0x9f), 0x40 }, + { CCI_REG8(0xfd), 0x00 }, + { CCI_REG8(0x20), 0x1b }, + { CCI_REG8(0xfd), 0x04 }, + { CCI_REG8(0x19), 0x60 }, + { CCI_REG8(0xfd), 0x02 }, + { CCI_REG8(0x75), 0x05 }, + { CCI_REG8(0x7f), 0x06 }, + { CCI_REG8(0x9a), 0x03 }, + { CCI_REG8(0xa2), 0x07 }, + { CCI_REG8(0xa3), 0x10 }, + { CCI_REG8(0xa5), 0x02 }, + { CCI_REG8(0xa6), 0x0b }, + { CCI_REG8(0xa7), 0x48 }, + { CCI_REG8(0xfd), 0x07 }, + { CCI_REG8(0x42), 0x00 }, + { CCI_REG8(0x43), 0x80 }, + { CCI_REG8(0x44), 0x00 }, + { CCI_REG8(0x45), 0x80 }, + { CCI_REG8(0x46), 0x00 }, + { CCI_REG8(0x47), 0x80 }, + { CCI_REG8(0x48), 0x00 }, + { CCI_REG8(0x49), 0x80 }, + { CCI_REG8(0x00), 0xf7 }, + { CCI_REG8(0xfd), 0x00 }, + { CCI_REG8(0xe7), 0x03 }, + { CCI_REG8(0xe7), 0x00 }, + { CCI_REG8(0xfd), 0x00 }, + { CCI_REG8(0x93), 0x18 }, + { CCI_REG8(0x94), 0xff }, + { CCI_REG8(0x95), 0xbd }, + { CCI_REG8(0x96), 0x1a }, + { CCI_REG8(0x98), 0x04 }, + { CCI_REG8(0x99), 0x08 }, + { CCI_REG8(0x9b), 0x10 }, + { CCI_REG8(0x9c), 0x3f }, + { CCI_REG8(0xa1), 0x05 }, + { CCI_REG8(0xa4), 0x2f }, + { CCI_REG8(0xc0), 0x0c }, + { CCI_REG8(0xc1), 0x08 }, + { CCI_REG8(0xc2), 0x00 }, + { CCI_REG8(0xb6), 0x20 }, + { CCI_REG8(0xbb), 0x80 }, + { CCI_REG8(0xfd), 0x00 }, + { CCI_REG8(0xa0), 0x01 }, + { CCI_REG8(0xfd), 0x01 }, +}; + +static const struct cci_reg_sequence mode_OV05C_stream_on_regs[] = { + {CCI_REG8 (0xfd ),0x01 }, + {CCI_REG8 (0x33 ),0x03 }, + {CCI_REG8 (0x01 ),0x02 }, + {CCI_REG8 (0xfd ),0x00 }, + {CCI_REG8 (0x20 ),0x1f }, + {CCI_REG8 (0xfd ),0x01 }, +}; + +static const struct cci_reg_sequence mode_OV05C_stream_off_regs[] = { + {CCI_REG8 (0xfd ),0x00 }, + {CCI_REG8 (0x20 ),0x5b }, + {CCI_REG8 (0xfd ),0x01 }, + {CCI_REG8 (0x33 ),0x02 }, + {CCI_REG8 (0x01 ),0x02 }, +}; + +static const char *const ov05c_test_pattern_menu[] = { +"Disabled" , +"Vertical Color Bar Type 1" , +"Vertical Color Bar Type 2" , +"Vertical Color Bar Type 3" , +"Vertical Color Bar Type 4" +}; + +/* Configurations for supported link frequencies */ +#define OV05C_LINK_FREQ_900MHZ (900 * HZ_PER_MHZ) + +/* Number of lanes supported */ +#define OV05C_DATA_LANES 2 + +/* Bits per sample of sensor output */ +#define OV05C_BITS_PER_SAMPLE 10 + +/* +* pixel_rate = link_freq * data-rate * nr_of_lanes / bits_per_sample +* data rate => double data rate; number of lanes => 2; bits per pixel => 10 +*/ +static u64 link_freq_to_pixel_rate (u64 f) +{ + f *=2 *OV05C_DATA_LANES ; +do_div (f,OV05C_BITS_PER_SAMPLE ); + +return f; +} + +/* Menu items for LINK_FREQ V4L2 control */ +static const s64 ov05c_link_freq_menu_items[] = { +OV05C_LINK_FREQ_900MHZ , +}; + +/* Mode configs */ +static const struct ov05c_mode supported_modes[] = { + { + .width =2888 , + .height =1808 , + .vts_def =OV05C_VTS_30FPS , + .vts_min =OV05C_VTS_30FPS , + .hts =640 , + .lanes =2 , + .reg_list = { + .num_of_regs =ARRAY_SIZE (mode_2888_1808_30fps_1800mbps_2lane_24mhz_regs), + .regs = mode_2888_1808_30fps_1800mbps_2lane_24mhz_regs, + }, + .link_freq_index =OV05C_LINK_FREQ_900MHZ_INDEX , + }, +}; + +struct ov05c { +struct v4l2_subdev sd; +struct media_pad pads[NUM_OF_PADS ]; + +/* V4L2 control handler */ +struct v4l2_ctrl_handler ctrl_handler; + +/* V4L2 Controls */ +struct v4l2_ctrl *link_freq; +struct v4l2_ctrl *pixel_rate; +struct v4l2_ctrl *vblank; +struct v4l2_ctrl *hblank; +struct v4l2_ctrl *exposure; + +/* Current mode */ +const struct ov05c_mode *cur_mode; + +struct regmap *regmap; + +/* Mutex for serialized access */ +struct mutex mutex; + +/* gpio descriptor */ +struct gpio_desc *enable_gpio; +}; + +#define to_ov05c (_sd) container_of(_sd, struct ov05c, sd) + +static int ov05c_open (struct v4l2_subdev *sd,struct v4l2_subdev_fh *fh) +{ +const struct ov05c_mode *default_mode = &supported_modes[0 ]; +struct ov05c *ov05c =to_ov05c (sd);
drivers/media/i2c/ov05c.c line 377
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+struct v4l2_mbus_framefmt *try_fmt = +v4l2_subdev_state_get_format (fh->state,0 ); + +mutex_lock (&ov05c->mutex); + +/* Initialize try_fmt */ + try_fmt->width = default_mode->width; + try_fmt->height = default_mode->height; + try_fmt->code =MEDIA_BUS_FMT_SGRBG10_1X10 ; + try_fmt->field =V4L2_FIELD_NONE ;
Please implement init_state callback instead.
Quoted 24 lines
drivers/media/i2c/ov05c.c new file +24
-0+ +/* No crop or compose */ +mutex_unlock (&ov05c->mutex); + +return 0 ; +} + +static int ov05c_update_cid_vblank (struct ov05c *ov05c,u32 vblank) +{ +int ret =0 ; + +cci_write (ov05c->regmap,OV05C_REG_PAGE_CTL , +BIT (0 ), &ret); +if (ret) +return ret; + +cci_write (ov05c->regmap,OV05C_REG_VTS , + ov05c->cur_mode->height + + vblank, &ret); +if (ret) +return ret; + +cci_write (ov05c->regmap,OV05C_REG_TRIGGER , +BIT (0 ), &ret);
drivers/media/i2c/ov05c.c line 411
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+ +return ret; +} + +static int ov05c_update_cid_exposure (struct ov05c *ov05c,u32 exposure) +{ +int ret =0 ; + +cci_write (ov05c->regmap,OV05C_REG_PAGE_CTL , +BIT (0 ), &ret);
Fits on the same line. Same in the function above this one and below in this function.
Quoted 27 lines
drivers/media/i2c/ov05c.c new file +27
-0+if (ret) +return ret; + +cci_write (ov05c->regmap,OV05C_REG_EXPOSURE , + exposure, &ret); +if (ret) +return ret; + +cci_write (ov05c->regmap,OV05C_REG_TRIGGER , +BIT (0 ), &ret); + +return ret; +} + +static int ov05c_update_analog_gain (struct ov05c *ov05c,u32 a_gain) +{ +int ret; + + ret =cci_write (ov05c->regmap,OV05C_REG_PAGE_CTL ,BIT (0 ),NULL ); +if (ret) +return ret; + + ret =cci_write (ov05c->regmap,OV05C_REG_ANALOG_GAIN , a_gain,NULL ); +if (ret) +return ret; + +return cci_write (ov05c->regmap,OV05C_REG_TRIGGER ,BIT (0 ),NULL );
drivers/media/i2c/ov05c.c line 448
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+} + +static int ov05_update_digital_gain (struct ov05c *ov05c,u32 d_gain) +{ +int ret; +u64 val; + + ret =cci_write (ov05c->regmap,OV05C_REG_PAGE_CTL ,BIT (0 ),NULL ); +if (ret) +return ret;
You can remove the check...
drivers/media/i2c/ov05c.c line 451
Quoted 3 lines
drivers/media/i2c/ov05c.c new file +3
-0+ + val = d_gain &OV05C_DGTL_GAIN_L_MASK ; + ret =cci_write (ov05c->regmap,OV05C_REG_DGTL_GAIN_L , val,NULL );
if you pass &ret to cci_write().
drivers/media/i2c/ov05c.c line 453
Quoted 2 lines
drivers/media/i2c/ov05c.c new file +2
-0+if (ret) +return ret;
Ditto.
drivers/media/i2c/ov05c.c line 459
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+ + val = (d_gain &OV05C_DGTL_GAIN_H_MASK ) >>OV05C_DGTL_GAIN_H_SHIFT ; + + ret =cci_write (ov05c->regmap,OV05C_REG_DGTL_GAIN_H , val,NULL ); +if (ret) +return ret;
Ditto. And similarly elsewhere.
Quoted 36 lines
drivers/media/i2c/ov05c.c new file +36
-0+ +return cci_write (ov05c->regmap,OV05C_REG_TRIGGER ,BIT (0 ),NULL ); +} + +static int ov05c_enable_test_pattern (struct ov05c *ov05c,u32 pattern) +{ +int ret; +u64 val; + + ret =cci_write (ov05c->regmap,OV05C_REG_PAGE_CTL ,BIT (2 ),NULL ); +if (ret) +return ret; + +if (pattern) { + ret =cci_read (ov05c->regmap,OV05C_REG_TEST_PATTERN_CTL , &val,NULL ); +if (ret) +return ret; + + ret =cci_write (ov05c->regmap,OV05C_REG_TEST_PATTERN_CTL , val |BIT (1 ),NULL ); +if (ret) +return ret; + + ret =cci_read (ov05c->regmap,OV05C_REG_TEST_PATTERN , &val,NULL ); +if (ret) +return ret; + + val &=OV05C_TEST_PATTERN_ENABLE ; + }else { + ret =cci_read (ov05c->regmap,OV05C_REG_TEST_PATTERN , &val,NULL ); +if (ret) +return ret; + + val &= ~OV05C_TEST_PATTERN_ENABLE ; + } + + ret =cci_write (ov05c->regmap,OV05C_REG_TEST_PATTERN , val,NULL );
drivers/media/i2c/ov05c.c line 505
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+if (ret) +return ret; + +return cci_write (ov05c->regmap,OV05C_REG_TRIGGER ,BIT (0 ),NULL ); +} + +static int ov05c_set_ctrl (struct v4l2_ctrl *ctrl) +{ +struct ov05c *ov05c =container_of (ctrl->handler, + struct ov05c, ctrl_handler);
Alignment.
drivers/media/i2c/ov05c.c line 517
Quoted 12 lines
drivers/media/i2c/ov05c.c new file +12
-0+struct i2c_client *client =v4l2_get_subdevdata (&ov05c->sd); +s64 max; +int ret =0 ; + +/* Propagate change of current control to all related controls */ +switch (ctrl->id) { +case V4L2_CID_VBLANK : +/* Update max exposure while meeting expected vblanking */ + max = ov05c->cur_mode->height + ctrl->val -OV05C_EXPOSURE_MAX_MARGIN ; +__v4l2_ctrl_modify_range (ov05c->exposure, + ov05c->exposure->minimum, + max, ov05c->exposure->step, max);
Can this fail?
Quoted 98 lines
drivers/media/i2c/ov05c.c new file +98
-0+break ; + } + +/* +* Applying V4L2 control value only happens +* when power is up for streaming +*/ +if (!pm_runtime_get_if_in_use (&client->dev)) +return 0 ; + +switch (ctrl->id) { +case V4L2_CID_ANALOGUE_GAIN : + ret =ov05c_update_analog_gain (ov05c, ctrl->val); +break ; +case V4L2_CID_DIGITAL_GAIN : + ret =ov05_update_digital_gain (ov05c, ctrl->val); +break ; +case V4L2_CID_EXPOSURE : + ret =ov05c_update_cid_exposure (ov05c, ctrl->val); +break ; +case V4L2_CID_VBLANK : + ret =ov05c_update_cid_vblank (ov05c, ctrl->val); +break ; +case V4L2_CID_TEST_PATTERN : + ret =ov05c_enable_test_pattern (ov05c, ctrl->val); +break ; +default : +dev_info (&client->dev, +"ctrl(id:0x%x,val:0x%x) is not handled\n" , + ctrl->id, ctrl->val); +break ; + } + +pm_runtime_put (&client->dev); + +return ret; +} + +static const struct v4l2_ctrl_ops ov05c_ctrl_ops = { + .s_ctrl = ov05c_set_ctrl, +}; + +static int ov05c_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 */ +if (code->index >0 ) +return -EINVAL ; + + code->code =MEDIA_BUS_FMT_SGRBG10_1X10 ; + +return 0 ; +} + +static int ov05c_enum_frame_size (struct v4l2_subdev *sd, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_frame_size_enum *fse) +{ +if (fse->index >=ARRAY_SIZE (supported_modes)) +return -EINVAL ; + +if (fse->code !=MEDIA_BUS_FMT_SGRBG10_1X10 ) +return -EINVAL ; + + fse->min_width = supported_modes[fse->index].width; + fse->max_width = fse->min_width; + fse->min_height = supported_modes[fse->index].height; + fse->max_height = fse->min_height; + +return 0 ; +} + +static void ov05c_update_pad_format (const struct ov05c_mode *mode, +struct v4l2_subdev_format *fmt) +{ + fmt->format.width = mode->width; + fmt->format.height = mode->height; + fmt->format.code =MEDIA_BUS_FMT_SGRBG10_1X10 ; + fmt->format.field =V4L2_FIELD_NONE ; +} + +static int ov05c_do_get_pad_format (struct ov05c *ov05c, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_format *fmt) +{ +struct v4l2_mbus_framefmt *framefmt; + +if (fmt->which ==V4L2_SUBDEV_FORMAT_TRY ) { + framefmt =v4l2_subdev_state_get_format (sd_state, fmt->pad); + fmt->format = *framefmt; + }else { +ov05c_update_pad_format (ov05c->cur_mode, fmt); + } + +return 0 ; +} +
drivers/media/i2c/ov05c.c line 625
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+static int ov05c_get_pad_format (struct v4l2_subdev *sd, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_format *fmt) +{ +struct ov05c *ov05c =to_ov05c (sd); +int ret; + +mutex_lock (&ov05c->mutex); + ret =ov05c_do_get_pad_format (ov05c, sd_state, fmt); +mutex_unlock (&ov05c->mutex);
Please use sub-device state instead (see e.g. imx219 driver for an example).
Quoted 82 lines
drivers/media/i2c/ov05c.c new file +82
-0+ +return ret; +} + +static int ov05c_set_pad_format (struct v4l2_subdev *sd, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_format *fmt) +{ +struct ov05c *ov05c =to_ov05c (sd); +const struct ov05c_mode *mode; +struct v4l2_mbus_framefmt *framefmt; +s32 vblank_def; +s32 vblank_min; +s64 h_blank; +s64 pixel_rate; +s64 link_freq; + +mutex_lock (&ov05c->mutex); + +/* Only one raw bayer(GRBG) order is supported */ +if (fmt->format.code !=MEDIA_BUS_FMT_SGRBG10_1X10 ) + fmt->format.code =MEDIA_BUS_FMT_SGRBG10_1X10 ; + + mode =v4l2_find_nearest_size (supported_modes, +ARRAY_SIZE (supported_modes), + width, height, + fmt->format.width, fmt->format.height); +ov05c_update_pad_format (mode, fmt); +if (fmt->which ==V4L2_SUBDEV_FORMAT_TRY ) { + framefmt =v4l2_subdev_state_get_format (sd_state, fmt->pad); + *framefmt = fmt->format; + }else { + ov05c->cur_mode = mode; +__v4l2_ctrl_s_ctrl (ov05c->link_freq, mode->link_freq_index); + link_freq = ov05c_link_freq_menu_items[mode->link_freq_index]; + pixel_rate =link_freq_to_pixel_rate (link_freq); +__v4l2_ctrl_s_ctrl_int64 (ov05c->pixel_rate, pixel_rate); + +/* Update limits and set FPS to default */ + vblank_def = ov05c->cur_mode->vts_def - + ov05c->cur_mode->height; + vblank_min = ov05c->cur_mode->vts_min - + ov05c->cur_mode->height; +__v4l2_ctrl_modify_range (ov05c->vblank, vblank_min, +OV05C_VTS_MAX + - ov05c->cur_mode->height, +1 , + vblank_def); +__v4l2_ctrl_s_ctrl (ov05c->vblank, vblank_def); + h_blank = ov05c->cur_mode->hts; +__v4l2_ctrl_modify_range (ov05c->hblank, h_blank, + h_blank,1 , h_blank); + } + +mutex_unlock (&ov05c->mutex); + +return 0 ; +} + +static int ov05c_start_streaming (struct ov05c *ov05c) +{ +struct i2c_client *client =v4l2_get_subdevdata (&ov05c->sd); +const struct ov05c_reg_list *reg_list; +int ret =0 ; + +/* Apply default values of current mode */ + reg_list = &ov05c->cur_mode->reg_list; +cci_multi_reg_write (ov05c->regmap, reg_list->regs, reg_list->num_of_regs, + &ret); +if (ret) { +dev_err (&client->dev,"%s failed to set mode, ret: %d\n" , __func__, ret); +return ret; + } + +/* Apply customized values from user */ + ret =__v4l2_ctrl_handler_setup (ov05c->sd.ctrl_handler); +if (ret) { +dev_err (&client->dev,"__v4l2_ctrl_handler_setup err:%d" , ret); +return ret; + } + + cci_multi_reg_write(ov05c->regmap, mode_OV05C_stream_on_regs,
drivers/media/i2c/ov05c.c line 717
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+ ARRAY_SIZE(mode_OV05C_stream_on_regs), &ret); +if (ret) +dev_err (&client->dev,"%s failed to start the streaming\n" , __func__); + +return ret; +} + +static int ov05c_stop_streaming (struct ov05c *ov05c) +{ +int ret =0 ;
Please declare temporary and return value variables as last.
Quoted 13 lines
drivers/media/i2c/ov05c.c new file +13
-0+struct i2c_client *client =v4l2_get_subdevdata (&ov05c->sd); + +cci_multi_reg_write (ov05c->regmap, mode_OV05C_stream_off_regs, +ARRAY_SIZE (mode_OV05C_stream_off_regs), &ret); +if (ret) +dev_err (&client->dev,"%s failed to stop the streaming\n" , __func__); + +return ret; +} + +static void ov05c_sensor_enable (struct ov05c *ov05c,bool enable) +{ +if (enable) {
drivers/media/i2c/ov05c.c line 740
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+gpiod_set_value (ov05c->enable_gpio,0 ); +usleep_range (10 ,20 ); + +gpiod_set_value (ov05c->enable_gpio,1 ); +/* The delay is to make sure the sensor is completely turned on */ +usleep_range (1000 ,2000 ); + }else { +gpiod_set_value (ov05c->enable_gpio,0 ); +usleep_range (10 ,20 ); + }
These belong to their respective runtime PM callbacks. At least in the enable case the order seems to be wrong, too.
drivers/media/i2c/ov05c.c line 743
Quoted 3 lines
drivers/media/i2c/ov05c.c new file +3
-0+} + +static int ov05c_set_stream (struct v4l2_subdev *sd,int enable)
Please switch to enable_streams/disable_streams pad ops instead.
Quoted 77 lines
drivers/media/i2c/ov05c.c new file +77
-0+{ +struct ov05c *ov05c =to_ov05c (sd); +struct i2c_client *client =v4l2_get_subdevdata (sd); +int ret =0 ; + +mutex_lock (&ov05c->mutex); + +if (enable) { +ov05c_sensor_enable (ov05c, true); + + ret =pm_runtime_resume_and_get (&client->dev); +if (ret <0 ) + goto err_unlock; + +/* +* Apply default & customized values +* and then start streaming. +*/ + ret =ov05c_start_streaming (ov05c); +if (ret) + goto err_rpm_put; + }else { +ov05c_stop_streaming (ov05c); +pm_runtime_put (&client->dev); + +ov05c_sensor_enable (ov05c, false); + } + +mutex_unlock (&ov05c->mutex); + +return ret; + +err_rpm_put: +pm_runtime_put (&client->dev); +err_unlock: +mutex_unlock (&ov05c->mutex); + +return ret; +} + +static const struct v4l2_subdev_video_ops ov05c_video_ops = { + .s_stream = ov05c_set_stream, +}; + +static const struct v4l2_subdev_pad_ops ov05c_pad_ops = { + .enum_mbus_code = ov05c_enum_mbus_code, + .get_fmt = ov05c_get_pad_format, + .set_fmt = ov05c_set_pad_format, + .enum_frame_size = ov05c_enum_frame_size, +}; + +static const struct v4l2_subdev_ops ov05c_subdev_ops = { + .video = &ov05c_video_ops, + .pad = &ov05c_pad_ops, +}; + +static const struct media_entity_operations ov05c_subdev_entity_ops = { + .link_validate = v4l2_subdev_link_validate, +}; + +static const struct v4l2_subdev_internal_ops ov05c_internal_ops = { + .open = ov05c_open, +}; + +static int ov05c_init_controls (struct ov05c *ov05c) +{ +struct i2c_client *client =v4l2_get_subdevdata (&ov05c->sd); +struct v4l2_fwnode_device_properties props; +struct v4l2_ctrl_handler *ctrl_hdlr; +const struct ov05c_mode *mode; +s64 exposure_max; +s64 vblank_def; +s64 vblank_min; +s64 hblank; +s64 pixel_rate_max; +u32 max_items; +int ret;
drivers/media/i2c/ov05c.c line 830
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+ +/* Initialize V4L2 control handler with 10 items */ + ret =v4l2_ctrl_handler_init (&ov05c->ctrl_handler,10 ); +if (ret) +return ret; + ctrl_hdlr = &ov05c->ctrl_handler; + +/* Initialize mutex for serialization */ +mutex_init (&ov05c->mutex); + ctrl_hdlr->lock = &ov05c->mutex;
I'd use the control lock for sub-device state, too. Again, see the imx219 driver.
Quoted 91 lines
drivers/media/i2c/ov05c.c new file +91
-0+ +/* Initialize Link frequency control item */ + max_items =ARRAY_SIZE (ov05c_link_freq_menu_items) -1 ; + ov05c->link_freq =v4l2_ctrl_new_int_menu (ctrl_hdlr, +NULL , +V4L2_CID_LINK_FREQ , + max_items, +0 , + ov05c_link_freq_menu_items); +if (ov05c->link_freq) + ov05c->link_freq->flags |=V4L2_CTRL_FLAG_READ_ONLY ; + +/* Initialize Pixel rate control item */ + pixel_rate_max =link_freq_to_pixel_rate (ov05c_link_freq_menu_items[0 ]); + ov05c->pixel_rate =v4l2_ctrl_new_std (ctrl_hdlr,NULL , +V4L2_CID_PIXEL_RATE , +0 , pixel_rate_max, +1 , pixel_rate_max); + +/* Initialize VBLANK control item */ + mode = ov05c->cur_mode; + vblank_def = mode->vts_def - mode->height; + vblank_min = mode->vts_min - mode->height; + ov05c->vblank =v4l2_ctrl_new_std (ctrl_hdlr, &ov05c_ctrl_ops, +V4L2_CID_VBLANK , + vblank_min,OV05C_VTS_MAX - mode->height, +1 , vblank_def); + +/* Initialize HBLANK control item */ + hblank =max (0 , ov05c->cur_mode->hts - ov05c->cur_mode->width); + ov05c->hblank =v4l2_ctrl_new_std (ctrl_hdlr,NULL , +V4L2_CID_HBLANK , + hblank, hblank,1 , hblank); +if (ov05c->hblank) + ov05c->hblank->flags |=V4L2_CTRL_FLAG_READ_ONLY ; + +/* Initialize EXPOSURE control item */ + exposure_max = mode->vts_def -OV05C_EXPOSURE_MAX_MARGIN ; + ov05c->exposure =v4l2_ctrl_new_std (ctrl_hdlr, &ov05c_ctrl_ops, +V4L2_CID_EXPOSURE , +OV05C_EXPOSURE_MIN , exposure_max, +OV05C_EXPOSURE_STEP , exposure_max); + +/* Initialize Analog gain control item */ +v4l2_ctrl_new_std (ctrl_hdlr, &ov05c_ctrl_ops,V4L2_CID_ANALOGUE_GAIN , +OV05C_ANA_GAIN_MIN ,OV05C_ANA_GAIN_MAX , +OV05C_ANA_GAIN_STEP ,OV05C_ANA_GAIN_DEFAULT ); + +/* Initialize Digital gain control item */ +v4l2_ctrl_new_std (ctrl_hdlr, &ov05c_ctrl_ops,V4L2_CID_DIGITAL_GAIN , +OV05C_DGTL_GAIN_MIN ,OV05C_DGTL_GAIN_MAX , +OV05C_DGTL_GAIN_STEP ,OV05C_DGTL_GAIN_DEFAULT ); + + +/* Initialize Test pattern control item */ +v4l2_ctrl_new_std_menu_items (ctrl_hdlr, &ov05c_ctrl_ops, +V4L2_CID_TEST_PATTERN , +ARRAY_SIZE (ov05c_test_pattern_menu) -1 ,0 , +0 , ov05c_test_pattern_menu); + +if (ctrl_hdlr->error) { + ret = ctrl_hdlr->error; +dev_err (&client->dev,"%s V4L2 control init failed (%d)" , __func__, ret); + goto error; + } + + ret =v4l2_fwnode_device_parse (&client->dev, &props); +if (ret) + goto error; + + ret =v4l2_ctrl_new_fwnode_properties (ctrl_hdlr, &ov05c_ctrl_ops, &props); +if (ret) + goto error; + + ov05c->sd.ctrl_handler = ctrl_hdlr; + +return 0 ; + +error: +v4l2_ctrl_handler_free (ctrl_hdlr); +mutex_destroy (&ov05c->mutex); + +return ret; +} + +static void ov05c_free_controls (struct ov05c *ov05c) +{ +v4l2_ctrl_handler_free (ov05c->sd.ctrl_handler); +mutex_destroy (&ov05c->mutex); +} +
drivers/media/i2c/ov05c.c line 931
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+static int ov05c_probe (struct i2c_client *client) +{ +struct ov05c *ov05c; +int i, ret; + + ov05c =devm_kzalloc (&client->dev,sizeof (*ov05c),GFP_KERNEL ); +if (!ov05c) +return -ENOMEM ; + + client->dev.init_name =DRV_NAME ;
This is hardly needed.
Please also check the V4L2 fwnode endpoint and validate it. See how other drivers do this.
drivers/media/i2c/ov05c.c line 933
Quoted 2 lines
drivers/media/i2c/ov05c.c new file +2
-0+ +/* create sensor enable gpio control */
The comment is redundant, please remove it. I'd say that goes for the rest of the comments in the function, too.
drivers/media/i2c/ov05c.c line 934
Quoted 1 line
drivers/media/i2c/ov05c.c new file +1
-0+ ov05c->enable_gpio =devm_gpiod_get (&client->dev,"sensor0_enable" ,GPIOD_OUT_LOW );
Please run
$ ./scripts/checkpatch.pl --strict --max-line-length=80
on this.
Regarding the GPIO name, where does it come from? I'd instead use "enable" or "reset" (in which case the polarity would be differente).
Which external clock frequency the driver assumes? You should also check for it.
Quoted 5 lines
drivers/media/i2c/ov05c.c new file +5
-0+if (IS_ERR_OR_NULL (ov05c->enable_gpio)) +return PTR_ERR (ov05c->enable_gpio); + +/* Initialize subdev */ +v4l2_i2c_subdev_init (&ov05c->sd, client, &ov05c_subdev_ops);
drivers/media/i2c/ov05c.c line 949
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+ +/* Initialize CCI */ + ov05c->regmap =devm_cci_regmap_init_i2c (client,8 ); +if (IS_ERR (ov05c->regmap)) { +dev_err (&client->dev,"Failed to initialize CCI\n" ); +return PTR_ERR (ov05c->regmap); + } + +/* Set default mode to max resolution */ + ov05c->cur_mode = &supported_modes[0 ];
Please avoid having state information in device context struct whenever possible.
drivers/media/i2c/ov05c.c line 961
Quoted 12 lines
drivers/media/i2c/ov05c.c new file +12
-0+ +/* Initialize V4L2 controls */ + ret =ov05c_init_controls (ov05c); +if (ret) +return ret; + +/* Initialize V4L2 subdev */ + ov05c->sd.internal_ops = &ov05c_internal_ops; + ov05c->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; + ov05c->sd.entity.ops = &ov05c_subdev_entity_ops; + ov05c->sd.entity.function =MEDIA_ENT_F_CAM_SENSOR ; + ov05c->sd.entity.name ="OV05C" ;
The entity name has been set by v4l2_i2c_subdev_init() already.
drivers/media/i2c/ov05c.c line 965
Quoted 4 lines
drivers/media/i2c/ov05c.c new file +4
-0+ +/* Initialize source pad */ +for (i =0 ; i <NUM_OF_PADS ; i++) + ov05c->pads[i].flags =MEDIA_PAD_FL_SOURCE ;
Three source pads? What are they for?
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+ + ret =media_entity_pads_init (&ov05c->sd.entity,NUM_OF_PADS , ov05c->pads); +if (ret) + goto error_handler_free; + + ret =v4l2_async_register_subdev_sensor (&ov05c->sd);
drivers/media/i2c/ov05c.c line 981
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+if (ret) + goto error_media_entity; + +/* +* Device is already turned on by i2c-core with ACPI domain PM. +* Enable runtime PM and turn off the device. +*/ +pm_runtime_set_active (&client->dev); +pm_runtime_enable (&client->dev); +pm_runtime_idle (&client->dev);
Please read <URL:https://hverkuil.home.xs4all.nl/spec/driver-api/v4l2-subdev.html#media-registering-async-subdevs>.
drivers/media/i2c/ov05c.c line 983
Quoted 2 lines
drivers/media/i2c/ov05c.c new file +2
-0+ +dev_info (&client->dev,"%s success" , __func__);
This looks like a development time leftover. Please remove this and other similar cases.
Quoted 17 lines
drivers/media/i2c/ov05c.c new file +17
-0+ +return 0 ; + +error_media_entity: +media_entity_cleanup (&ov05c->sd.entity); + +error_handler_free: +ov05c_free_controls (ov05c); + +return ret; +} + +static void ov05c_remove (struct i2c_client *client) +{ +struct v4l2_subdev *sd =i2c_get_clientdata (client); +struct ov05c *ov05c =to_ov05c (sd); +
drivers/media/i2c/ov05c.c line 1010
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+v4l2_async_unregister_subdev (sd); +media_entity_cleanup (&sd->entity); +ov05c_free_controls (ov05c); + +pm_runtime_disable (&client->dev); +pm_runtime_set_suspended (&client->dev); +} + +static const struct i2c_device_id ov05c_id[] = { + {"ov05c" ,0 },
You probably don't need this.
Which brings us to a question: is the platform you're using this DT or ACPI based? You'll need appropriate compatible / _HID and in DT case bindings, too.
Quoted 21 lines
drivers/media/i2c/ov05c.c new file +21
-0+ { } +}; + +MODULE_DEVICE_TABLE (i2c, ov05c_id); + +static struct i2c_driver ov05c_i2c_driver = { + .driver = { + .name =DRV_NAME , + }, + .id_table = ov05c_id, + .probe = ov05c_probe, + .remove = ov05c_remove, +}; + +module_i2c_driver (ov05c_i2c_driver); + +MODULE_AUTHOR ("Venkata Narendra Kumar Gutta <[email protected]>" ); +MODULE_AUTHOR ("Pratap Nirujogi <[email protected]>" ); +MODULE_DESCRIPTION ("OmniVision OV05C sensor driver" ); +MODULE_ALIAS ("ov05c" ); +MODULE_LICENSE ("GPL and additional rights" );
Signature · 3 lines
Kind regards, Sakari Ailus
Hi Sakari,
Thanks for reviewing the patch and extremely sorry for the delayed response.
We have submitted V2 patch based on the review feedback. Can you please help to review latest V2 patch and let us know your feedback.
Thanks,
Pratap
Quoted 28 lines · Sakari Ailus
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Hi Pratap,
Thanks for the patch.
Quoted 20 lines · Pratap Nirujogi
Add driver for OmniVision 5.2M OV05C10 sensor. This driver supports only the full size normal 2888x1808@30fps 2-lane sensor profile.
Signed-off-by Pratap Nirujogi <[email protected]>--- drivers/media/i2c/Kconfig | 10 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/ov05c.c | 1031 ++++++++++++++++++++++++++++++++++++ 3 files changed, 1042 insertions(+)create mode 100644
drivers/media/i2c/ov05c.cdrivers/media/i2c/Kconfig +0
-0@@ -337,6 +337,16 @@ config VIDEO_OG01A1B To compile this driver as a module, choose M here: the module will be called og01a1b.
Quoted 13 lines
drivers/media/i2c/Kconfig config VIDEO_OG01A1B · line 348
Quoted 9 lines
drivers/media/i2c/Kconfig +9
-0+config VIDEO_OV05C + tristate "OmniVision OV05 sensor support" + select V4L2_CCI_I2C + help + This is a Video4Linux2 sensor driver for the OmniVision + OV05C camera. + + To compile this driver as a module, choose M here: the + module will be called OV05C.Omnivision has typically named their sensors as /ov[0-9]{2}.[0-9]{2}/ and this does not follow that pattern. Is ov05c the full name of the chip?
Full name is OV05C10. Replaced OV05C with OV05C10; and also the driver name as OV05C10 in V2.
Quoted 17 lines
Quoted 17 lines
drivers/media/i2c/Kconfig +1
-0+ config VIDEO_OV01A10 tristate "OmniVision OV01A10 sensor support" helpdrivers/media/i2c/Makefile +1
-0@@ -80,6 +80,7 @@ obj-$(CONFIG_VIDEO_MT9V011) += mt9v011.o obj-$(CONFIG_VIDEO_MT9V032) += mt9v032.o obj-$(CONFIG_VIDEO_MT9V111) += mt9v111.o obj-$(CONFIG_VIDEO_OG01A1B) += og01a1b.o +obj-$(CONFIG_VIDEO_OV05C) += ov05c.o obj-$(CONFIG_VIDEO_OV01A10) += ov01a10.o obj-$(CONFIG_VIDEO_OV02A10) += ov02a10.o obj-$(CONFIG_VIDEO_OV08D10) += ov08d10.odrivers/media/i2c/ov05c.c +0
-0
Quoted 9 lines
drivers/media/i2c/ov05c.c line 1
Quoted 6 lines
new file mode 100644
index 000000000000..96c4f74af4a9drivers/media/i2c/ov05c.c new file +1
-0@@ -0,0 +1,1031 @@ +/* SPDX-License-Identifier: MIT */ No GPL? Huh?
yes, it is GPL. Updated copyright header and license in V2.
Quoted 21 lines
Quoted 21 lines
drivers/media/i2c/ov05c.c new file +21
-0+/* +* Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. +* All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sub license, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice (including the +* next paragraph) shall be included in all copies or substantial portions +* of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
Quoted 9 lines
drivers/media/i2c/ov05c.c line 28
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +* USE OR OTHER DEALINGS IN THE SOFTWARE. +* +*/ + +#include <linux/acpi.h> I don't think you need this for anything right now.
yes, its removed in V2.
Quoted 4 lines
Quoted 4 lines
drivers/media/i2c/ov05c.c new file +4
-0+#include <linux/i2c.h> +#include <linux/module.h> +#include <linux/delay.h> +#include <linux/units.h>
Quoted 9 lines
drivers/media/i2c/ov05c.c line 38
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+#include <linux/pm_runtime.h> +#include <linux/gpio.h> +#include <media/v4l2-ctrls.h> +#include <media/v4l2-device.h> +#include <media/v4l2-fwnode.h> +#include <media/v4l2-cci.h> Alphabetical order, please.
yes, order is fixed in V2.
Quoted 38 lines
drivers/media/i2c/ov05c.c line 44
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+ +#define DRV_NAME "ov05c" + +/* Chip ID */ +#define OV05C_REG_CHIP_ID CCI_REG24(0x00) +#define OV05C_CHIP_ID 0x430556What about the fourth chip ID register?
Quoted 29 lines
drivers/media/i2c/ov05c.c new file +29
-0+ +/* Control registers */ +#define OV05C_REG_PAGE_CTL CCI_REG8(0xFD) +#define OV05C_REG_TRIGGER CCI_REG8(0x01) + +/* V_TIMING internal */ +#define OV05C_REG_VTS CCI_REG16(0x05) +#define OV05C_VTS_30FPS 1860 +#define OV05C_VTS_MAX 0x7fff + +/* H TIMING internal */ +#define OV05C_REG_HTS CCI_REG16(0x37) +#define OV05C_HTS_30FPS 0x0280 + +/* Exposure control */ +#define OV05C_REG_EXPOSURE CCI_REG24(0x02) +#define OV05C_EXPOSURE_MAX_MARGIN 33 +#define OV05C_EXPOSURE_MIN 4 +#define OV05C_EXPOSURE_STEP 1 +#define OV05C_EXPOSURE_DEFAULT 0x40 + +/* Analog gain control */ +#define OV05C_REG_ANALOG_GAIN CCI_REG8(0x24) +#define OV05C_ANA_GAIN_MIN 0x80 +#define OV05C_ANA_GAIN_MAX 0x07c0 +#define OV05C_ANA_GAIN_STEP 1 +#define OV05C_ANA_GAIN_DEFAULT 0x80 + +/* Digital gain control */
Quoted 9 lines
drivers/media/i2c/ov05c.c line 79
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+#define OV05C_REG_DGTL_GAIN_H CCI_REG8(0x21) +#define OV05C_REG_DGTL_GAIN_L CCI_REG8(0x22) + +#define OV05C_DGTL_GAIN_MIN 64/* Min = 1 X */ +#define OV05C_DGTL_GAIN_MAX (256 - 1)/* Max = 4 X */ +#define OV05C_DGTL_GAIN_DEFAULT 0x80/* Default gain = 2x */ It seems the default digital gain is 2x. Why not 1x?
Done. Updated to 1x in V2.
Quoted 48 lines
Quoted 48 lines
drivers/media/i2c/ov05c.c new file +48
-0+#define OV05C_DGTL_GAIN_STEP 1/* Each step = 1/64 */ + +#define OV05C_DGTL_GAIN_L_MASK 0xFF +#define OV05C_DGTL_GAIN_H_SHIFT 8 +#define OV05C_DGTL_GAIN_H_MASK 0xFF00 + +/* Test Pattern Control */ +#define OV05C_REG_TEST_PATTERN_CTL CCI_REG8(0xF3) +#define OV05C_REG_TEST_PATTERN CCI_REG8(0x12) +#define OV05C_TEST_PATTERN_ENABLE BIT(0) + +#define NUM_OF_PADS 3 + +enum { +OV05C_LINK_FREQ_900MHZ_INDEX , +}; + +struct ov05c_reg_list { +u32 num_of_regs; +const struct cci_reg_sequence *regs; +}; + +/* Link frequency config */ +struct ov05c_link_freq_config { +/* registers for this link frequency */ +struct ov05c_reg_list reg_list; +}; + +/* Mode : resolution and related config&values */ +struct ov05c_mode { +/* Frame width */ +u32 width; +/* Frame height */ +u32 height; +/* number of lanes */ +u32 lanes; + +/* V-timing */ +u32 vts_def; +u32 vts_min; + +/* HTS */ +u32 hts; + +/* Index of Link frequency config to be used */ +u32 link_freq_index; + +/* Default register values */
Quoted 9 lines
drivers/media/i2c/ov05c.c line 132
Quoted 5 lines
drivers/media/i2c/ov05c.c new file +5
-0+struct ov05c_reg_list reg_list; +}; + +static const struct cci_reg_sequence + mode_2888_1808_30fps_1800mbps_2lane_24mhz_regs[] = {I'm not sure what checkpatch.pl says about this but I'd wrap before "struct".
Done. Simplified the name to fit in one line in V2.
Quoted 3 lines
Do you think you could separate mode specific registers from the link frequency/lane configuration and common settings?
We received this programming sequence from the vendor. Need to check if such a split would be possible with the vendor. Is it okay to use this sequence for now?
Quoted 239 lines
Quoted 239 lines
drivers/media/i2c/ov05c.c new file +239
-0+ { CCI_REG8(0xfd), 0x00 }, + { CCI_REG8(0x20), 0x00 }, + { CCI_REG8(0xfd), 0x00 }, + { CCI_REG8(0x20), 0x0b }, + { CCI_REG8(0xc1), 0x09 }, + { CCI_REG8(0x21), 0x06 }, + { CCI_REG8(0x14), 0x78 }, + { CCI_REG8(0xe7), 0x03 }, + { CCI_REG8(0xe7), 0x00 }, + { CCI_REG8(0x21), 0x00 }, + { CCI_REG8(0xfd), 0x01 }, + { CCI_REG8(0x03), 0x00 }, + { CCI_REG8(0x04), 0x06 }, + { CCI_REG8(0x05), 0x07 }, + { CCI_REG8(0x06), 0x44 }, + { CCI_REG8(0x07), 0x08 }, + { CCI_REG8(0x1b), 0x01 }, + { CCI_REG8(0x24), 0xff }, + { CCI_REG8(0x32), 0x03 }, + { CCI_REG8(0x42), 0x5d }, + { CCI_REG8(0x43), 0x08 }, + { CCI_REG8(0x44), 0x81 }, + { CCI_REG8(0x46), 0x5f }, + { CCI_REG8(0x48), 0x18 }, + { CCI_REG8(0x49), 0x04 }, + { CCI_REG8(0x5c), 0x18 }, + { CCI_REG8(0x5e), 0x13 }, + { CCI_REG8(0x70), 0x15 }, + { CCI_REG8(0x77), 0x35 }, + { CCI_REG8(0x79), 0x00 }, + { CCI_REG8(0x7b), 0x08 }, + { CCI_REG8(0x7d), 0x08 }, + { CCI_REG8(0x7e), 0x08 }, + { CCI_REG8(0x7f), 0x08 }, + { CCI_REG8(0x90), 0x37 }, + { CCI_REG8(0x91), 0x05 }, + { CCI_REG8(0x92), 0x18 }, + { CCI_REG8(0x93), 0x27 }, + { CCI_REG8(0x94), 0x05 }, + { CCI_REG8(0x95), 0x38 }, + { CCI_REG8(0x9b), 0x00 }, + { CCI_REG8(0x9c), 0x06 }, + { CCI_REG8(0x9d), 0x28 }, + { CCI_REG8(0x9e), 0x06 }, + { CCI_REG8(0xb2), 0x0f }, + { CCI_REG8(0xb3), 0x29 }, + { CCI_REG8(0xbf), 0x3c }, + { CCI_REG8(0xc2), 0x04 }, + { CCI_REG8(0xc4), 0x00 }, + { CCI_REG8(0xca), 0x20 }, + { CCI_REG8(0xcb), 0x20 }, + { CCI_REG8(0xcc), 0x28 }, + { CCI_REG8(0xcd), 0x28 }, + { CCI_REG8(0xce), 0x20 }, + { CCI_REG8(0xcf), 0x20 }, + { CCI_REG8(0xd0), 0x2a }, + { CCI_REG8(0xd1), 0x2a }, + { CCI_REG8(0xfd), 0x0f }, + { CCI_REG8(0x00), 0x00 }, + { CCI_REG8(0x01), 0xa0 }, + { CCI_REG8(0x02), 0x48 }, + { CCI_REG8(0x07), 0x8f }, + { CCI_REG8(0x08), 0x70 }, + { CCI_REG8(0x09), 0x01 }, + { CCI_REG8(0x0b), 0x40 }, + { CCI_REG8(0x0d), 0x07 }, + { CCI_REG8(0x11), 0x33 }, + { CCI_REG8(0x12), 0x77 }, + { CCI_REG8(0x13), 0x66 }, + { CCI_REG8(0x14), 0x65 }, + { CCI_REG8(0x15), 0x37 }, + { CCI_REG8(0x16), 0xbf }, + { CCI_REG8(0x17), 0xff }, + { CCI_REG8(0x18), 0xff }, + { CCI_REG8(0x19), 0x12 }, + { CCI_REG8(0x1a), 0x10 }, + { CCI_REG8(0x1c), 0x77 }, + { CCI_REG8(0x1d), 0x77 }, + { CCI_REG8(0x20), 0x0f }, + { CCI_REG8(0x21), 0x0f }, + { CCI_REG8(0x22), 0x0f }, + { CCI_REG8(0x23), 0x0f }, + { CCI_REG8(0x2b), 0x20 }, + { CCI_REG8(0x2c), 0x20 }, + { CCI_REG8(0x2d), 0x04 }, + { CCI_REG8(0xfd), 0x03 }, + { CCI_REG8(0x9d), 0x0f }, + { CCI_REG8(0x9f), 0x40 }, + { CCI_REG8(0xfd), 0x00 }, + { CCI_REG8(0x20), 0x1b }, + { CCI_REG8(0xfd), 0x04 }, + { CCI_REG8(0x19), 0x60 }, + { CCI_REG8(0xfd), 0x02 }, + { CCI_REG8(0x75), 0x05 }, + { CCI_REG8(0x7f), 0x06 }, + { CCI_REG8(0x9a), 0x03 }, + { CCI_REG8(0xa2), 0x07 }, + { CCI_REG8(0xa3), 0x10 }, + { CCI_REG8(0xa5), 0x02 }, + { CCI_REG8(0xa6), 0x0b }, + { CCI_REG8(0xa7), 0x48 }, + { CCI_REG8(0xfd), 0x07 }, + { CCI_REG8(0x42), 0x00 }, + { CCI_REG8(0x43), 0x80 }, + { CCI_REG8(0x44), 0x00 }, + { CCI_REG8(0x45), 0x80 }, + { CCI_REG8(0x46), 0x00 }, + { CCI_REG8(0x47), 0x80 }, + { CCI_REG8(0x48), 0x00 }, + { CCI_REG8(0x49), 0x80 }, + { CCI_REG8(0x00), 0xf7 }, + { CCI_REG8(0xfd), 0x00 }, + { CCI_REG8(0xe7), 0x03 }, + { CCI_REG8(0xe7), 0x00 }, + { CCI_REG8(0xfd), 0x00 }, + { CCI_REG8(0x93), 0x18 }, + { CCI_REG8(0x94), 0xff }, + { CCI_REG8(0x95), 0xbd }, + { CCI_REG8(0x96), 0x1a }, + { CCI_REG8(0x98), 0x04 }, + { CCI_REG8(0x99), 0x08 }, + { CCI_REG8(0x9b), 0x10 }, + { CCI_REG8(0x9c), 0x3f }, + { CCI_REG8(0xa1), 0x05 }, + { CCI_REG8(0xa4), 0x2f }, + { CCI_REG8(0xc0), 0x0c }, + { CCI_REG8(0xc1), 0x08 }, + { CCI_REG8(0xc2), 0x00 }, + { CCI_REG8(0xb6), 0x20 }, + { CCI_REG8(0xbb), 0x80 }, + { CCI_REG8(0xfd), 0x00 }, + { CCI_REG8(0xa0), 0x01 }, + { CCI_REG8(0xfd), 0x01 }, +}; + +static const struct cci_reg_sequence mode_OV05C_stream_on_regs[] = { + {CCI_REG8 (0xfd ),0x01 }, + {CCI_REG8 (0x33 ),0x03 }, + {CCI_REG8 (0x01 ),0x02 }, + {CCI_REG8 (0xfd ),0x00 }, + {CCI_REG8 (0x20 ),0x1f }, + {CCI_REG8 (0xfd ),0x01 }, +}; + +static const struct cci_reg_sequence mode_OV05C_stream_off_regs[] = { + {CCI_REG8 (0xfd ),0x00 }, + {CCI_REG8 (0x20 ),0x5b }, + {CCI_REG8 (0xfd ),0x01 }, + {CCI_REG8 (0x33 ),0x02 }, + {CCI_REG8 (0x01 ),0x02 }, +}; + +static const char *const ov05c_test_pattern_menu[] = { +"Disabled" , +"Vertical Color Bar Type 1" , +"Vertical Color Bar Type 2" , +"Vertical Color Bar Type 3" , +"Vertical Color Bar Type 4" +}; + +/* Configurations for supported link frequencies */ +#define OV05C_LINK_FREQ_900MHZ (900 * HZ_PER_MHZ) + +/* Number of lanes supported */ +#define OV05C_DATA_LANES 2 + +/* Bits per sample of sensor output */ +#define OV05C_BITS_PER_SAMPLE 10 + +/* +* pixel_rate = link_freq * data-rate * nr_of_lanes / bits_per_sample +* data rate => double data rate; number of lanes => 2; bits per pixel => 10 +*/ +static u64 link_freq_to_pixel_rate (u64 f) +{ + f *=2 *OV05C_DATA_LANES ; +do_div (f,OV05C_BITS_PER_SAMPLE ); + +return f; +} + +/* Menu items for LINK_FREQ V4L2 control */ +static const s64 ov05c_link_freq_menu_items[] = { +OV05C_LINK_FREQ_900MHZ , +}; + +/* Mode configs */ +static const struct ov05c_mode supported_modes[] = { + { + .width =2888 , + .height =1808 , + .vts_def =OV05C_VTS_30FPS , + .vts_min =OV05C_VTS_30FPS , + .hts =640 , + .lanes =2 , + .reg_list = { + .num_of_regs =ARRAY_SIZE (mode_2888_1808_30fps_1800mbps_2lane_24mhz_regs), + .regs = mode_2888_1808_30fps_1800mbps_2lane_24mhz_regs, + }, + .link_freq_index =OV05C_LINK_FREQ_900MHZ_INDEX , + }, +}; + +struct ov05c { +struct v4l2_subdev sd; +struct media_pad pads[NUM_OF_PADS ]; + +/* V4L2 control handler */ +struct v4l2_ctrl_handler ctrl_handler; + +/* V4L2 Controls */ +struct v4l2_ctrl *link_freq; +struct v4l2_ctrl *pixel_rate; +struct v4l2_ctrl *vblank; +struct v4l2_ctrl *hblank; +struct v4l2_ctrl *exposure; + +/* Current mode */ +const struct ov05c_mode *cur_mode; + +struct regmap *regmap; + +/* Mutex for serialized access */ +struct mutex mutex; + +/* gpio descriptor */ +struct gpio_desc *enable_gpio; +}; + +#define to_ov05c (_sd) container_of(_sd, struct ov05c, sd) + +static int ov05c_open (struct v4l2_subdev *sd,struct v4l2_subdev_fh *fh) +{ +const struct ov05c_mode *default_mode = &supported_modes[0 ]; +struct ov05c *ov05c =to_ov05c (sd); +struct v4l2_mbus_framefmt *try_fmt = +v4l2_subdev_state_get_format (fh->state,0 ); + +mutex_lock (&ov05c->mutex);
Quoted 9 lines
drivers/media/i2c/ov05c.c line 377
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+ +/* Initialize try_fmt */ + try_fmt->width = default_mode->width; + try_fmt->height = default_mode->height; + try_fmt->code =MEDIA_BUS_FMT_SGRBG10_1X10 ; + try_fmt->field =V4L2_FIELD_NONE ;Please implement
init_statecallback instead.
sure, implemented init_state in V2.
Quoted 89 lines
Quoted 24 lines
drivers/media/i2c/ov05c.c new file +24
-0+ +/* No crop or compose */ +mutex_unlock (&ov05c->mutex); + +return 0 ; +} + +static int ov05c_update_cid_vblank (struct ov05c *ov05c,u32 vblank) +{ +int ret =0 ; + +cci_write (ov05c->regmap,OV05C_REG_PAGE_CTL , +BIT (0 ), &ret); +if (ret) +return ret; + +cci_write (ov05c->regmap,OV05C_REG_VTS , + ov05c->cur_mode->height + + vblank, &ret); +if (ret) +return ret; + +cci_write (ov05c->regmap,OV05C_REG_TRIGGER , +BIT (0 ), &ret);drivers/media/i2c/ov05c.c line 411
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+ +return ret; +} + +static int ov05c_update_cid_exposure (struct ov05c *ov05c,u32 exposure) +{ +int ret =0 ; + +cci_write (ov05c->regmap,OV05C_REG_PAGE_CTL , +BIT (0 ), &ret);Fits on the same line. Same in the function above this one and below in this function.
Quoted 27 lines
drivers/media/i2c/ov05c.c new file +27
-0+if (ret) +return ret; + +cci_write (ov05c->regmap,OV05C_REG_EXPOSURE , + exposure, &ret); +if (ret) +return ret; + +cci_write (ov05c->regmap,OV05C_REG_TRIGGER , +BIT (0 ), &ret); + +return ret; +} + +static int ov05c_update_analog_gain (struct ov05c *ov05c,u32 a_gain) +{ +int ret; + + ret =cci_write (ov05c->regmap,OV05C_REG_PAGE_CTL ,BIT (0 ),NULL ); +if (ret) +return ret; + + ret =cci_write (ov05c->regmap,OV05C_REG_ANALOG_GAIN , a_gain,NULL ); +if (ret) +return ret; + +return cci_write (ov05c->regmap,OV05C_REG_TRIGGER ,BIT (0 ),NULL );drivers/media/i2c/ov05c.c line 448
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+} + +static int ov05_update_digital_gain (struct ov05c *ov05c,u32 d_gain) +{ +int ret; +u64 val; + + ret =cci_write (ov05c->regmap,OV05C_REG_PAGE_CTL ,BIT (0 ),NULL ); +if (ret) +return ret;You can remove the check...
drivers/media/i2c/ov05c.c line 451
Quoted 3 lines
drivers/media/i2c/ov05c.c new file +3
-0+ + val = d_gain &OV05C_DGTL_GAIN_L_MASK ; + ret =cci_write (ov05c->regmap,OV05C_REG_DGTL_GAIN_L , val,NULL );if you pass &ret to
cci_write().drivers/media/i2c/ov05c.c line 453
Quoted 2 lines
drivers/media/i2c/ov05c.c new file +2
-0+if (ret) +return ret;Ditto.
Quoted 9 lines
drivers/media/i2c/ov05c.c line 459
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+ + val = (d_gain &OV05C_DGTL_GAIN_H_MASK ) >>OV05C_DGTL_GAIN_H_SHIFT ; + + ret =cci_write (ov05c->regmap,OV05C_REG_DGTL_GAIN_H , val,NULL ); +if (ret) +return ret;Ditto. And similarly elsewhere.
Refactored ov05c10_update control funcs based on your feedback and also from other reviewers. Please see V2 and let us know your opinion.
Quoted 40 lines
Quoted 40 lines
drivers/media/i2c/ov05c.c new file +40
-0+ +return cci_write (ov05c->regmap,OV05C_REG_TRIGGER ,BIT (0 ),NULL ); +} + +static int ov05c_enable_test_pattern (struct ov05c *ov05c,u32 pattern) +{ +int ret; +u64 val; + + ret =cci_write (ov05c->regmap,OV05C_REG_PAGE_CTL ,BIT (2 ),NULL ); +if (ret) +return ret; + +if (pattern) { + ret =cci_read (ov05c->regmap,OV05C_REG_TEST_PATTERN_CTL , &val,NULL ); +if (ret) +return ret; + + ret =cci_write (ov05c->regmap,OV05C_REG_TEST_PATTERN_CTL , val |BIT (1 ),NULL ); +if (ret) +return ret; + + ret =cci_read (ov05c->regmap,OV05C_REG_TEST_PATTERN , &val,NULL ); +if (ret) +return ret; + + val &=OV05C_TEST_PATTERN_ENABLE ; + }else { + ret =cci_read (ov05c->regmap,OV05C_REG_TEST_PATTERN , &val,NULL ); +if (ret) +return ret; + + val &= ~OV05C_TEST_PATTERN_ENABLE ; + } + + ret =cci_write (ov05c->regmap,OV05C_REG_TEST_PATTERN , val,NULL ); +if (ret) +return ret; + +return cci_write (ov05c->regmap,OV05C_REG_TRIGGER ,BIT (0 ),NULL );
Quoted 9 lines
drivers/media/i2c/ov05c.c line 505
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+} + +static int ov05c_set_ctrl (struct v4l2_ctrl *ctrl) +{ +struct ov05c *ov05c =container_of (ctrl->handler, + struct ov05c, ctrl_handler);Alignment.
Done. Fixed it in V2.
Quoted 13 lines
drivers/media/i2c/ov05c.c line 517
Quoted 12 lines
drivers/media/i2c/ov05c.c new file +12
-0+struct i2c_client *client =v4l2_get_subdevdata (&ov05c->sd); +s64 max; +int ret =0 ; + +/* Propagate change of current control to all related controls */ +switch (ctrl->id) { +case V4L2_CID_VBLANK : +/* Update max exposure while meeting expected vblanking */ + max = ov05c->cur_mode->height + ctrl->val -OV05C_EXPOSURE_MAX_MARGIN ; +__v4l2_ctrl_modify_range (ov05c->exposure, + ov05c->exposure->minimum, + max, ov05c->exposure->step, max);
Quoted 2 lines
Can this fail?
yes, added failure check in V2, thank you.
Quoted 103 lines
Quoted 103 lines
drivers/media/i2c/ov05c.c new file +103
-0+break ; + } + +/* +* Applying V4L2 control value only happens +* when power is up for streaming +*/ +if (!pm_runtime_get_if_in_use (&client->dev)) +return 0 ; + +switch (ctrl->id) { +case V4L2_CID_ANALOGUE_GAIN : + ret =ov05c_update_analog_gain (ov05c, ctrl->val); +break ; +case V4L2_CID_DIGITAL_GAIN : + ret =ov05_update_digital_gain (ov05c, ctrl->val); +break ; +case V4L2_CID_EXPOSURE : + ret =ov05c_update_cid_exposure (ov05c, ctrl->val); +break ; +case V4L2_CID_VBLANK : + ret =ov05c_update_cid_vblank (ov05c, ctrl->val); +break ; +case V4L2_CID_TEST_PATTERN : + ret =ov05c_enable_test_pattern (ov05c, ctrl->val); +break ; +default : +dev_info (&client->dev, +"ctrl(id:0x%x,val:0x%x) is not handled\n" , + ctrl->id, ctrl->val); +break ; + } + +pm_runtime_put (&client->dev); + +return ret; +} + +static const struct v4l2_ctrl_ops ov05c_ctrl_ops = { + .s_ctrl = ov05c_set_ctrl, +}; + +static int ov05c_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 */ +if (code->index >0 ) +return -EINVAL ; + + code->code =MEDIA_BUS_FMT_SGRBG10_1X10 ; + +return 0 ; +} + +static int ov05c_enum_frame_size (struct v4l2_subdev *sd, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_frame_size_enum *fse) +{ +if (fse->index >=ARRAY_SIZE (supported_modes)) +return -EINVAL ; + +if (fse->code !=MEDIA_BUS_FMT_SGRBG10_1X10 ) +return -EINVAL ; + + fse->min_width = supported_modes[fse->index].width; + fse->max_width = fse->min_width; + fse->min_height = supported_modes[fse->index].height; + fse->max_height = fse->min_height; + +return 0 ; +} + +static void ov05c_update_pad_format (const struct ov05c_mode *mode, +struct v4l2_subdev_format *fmt) +{ + fmt->format.width = mode->width; + fmt->format.height = mode->height; + fmt->format.code =MEDIA_BUS_FMT_SGRBG10_1X10 ; + fmt->format.field =V4L2_FIELD_NONE ; +} + +static int ov05c_do_get_pad_format (struct ov05c *ov05c, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_format *fmt) +{ +struct v4l2_mbus_framefmt *framefmt; + +if (fmt->which ==V4L2_SUBDEV_FORMAT_TRY ) { + framefmt =v4l2_subdev_state_get_format (sd_state, fmt->pad); + fmt->format = *framefmt; + }else { +ov05c_update_pad_format (ov05c->cur_mode, fmt); + } + +return 0 ; +} + +static int ov05c_get_pad_format (struct v4l2_subdev *sd, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_format *fmt) +{ +struct ov05c *ov05c =to_ov05c (sd);
Quoted 9 lines
drivers/media/i2c/ov05c.c line 625
Quoted 5 lines
drivers/media/i2c/ov05c.c new file +5
-0+int ret; + +mutex_lock (&ov05c->mutex); + ret =ov05c_do_get_pad_format (ov05c, sd_state, fmt); +mutex_unlock (&ov05c->mutex);Please use sub-device state instead (see e.g. imx219 driver for an example).
We removed ov05c_get_pad_format() altogether and used v4l2_subdev_get_fmt() in V2. Please see V2 and let us know your opinion.
Quoted 86 lines
Quoted 86 lines
drivers/media/i2c/ov05c.c new file +86
-0+ +return ret; +} + +static int ov05c_set_pad_format (struct v4l2_subdev *sd, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_format *fmt) +{ +struct ov05c *ov05c =to_ov05c (sd); +const struct ov05c_mode *mode; +struct v4l2_mbus_framefmt *framefmt; +s32 vblank_def; +s32 vblank_min; +s64 h_blank; +s64 pixel_rate; +s64 link_freq; + +mutex_lock (&ov05c->mutex); + +/* Only one raw bayer(GRBG) order is supported */ +if (fmt->format.code !=MEDIA_BUS_FMT_SGRBG10_1X10 ) + fmt->format.code =MEDIA_BUS_FMT_SGRBG10_1X10 ; + + mode =v4l2_find_nearest_size (supported_modes, +ARRAY_SIZE (supported_modes), + width, height, + fmt->format.width, fmt->format.height); +ov05c_update_pad_format (mode, fmt); +if (fmt->which ==V4L2_SUBDEV_FORMAT_TRY ) { + framefmt =v4l2_subdev_state_get_format (sd_state, fmt->pad); + *framefmt = fmt->format; + }else { + ov05c->cur_mode = mode; +__v4l2_ctrl_s_ctrl (ov05c->link_freq, mode->link_freq_index); + link_freq = ov05c_link_freq_menu_items[mode->link_freq_index]; + pixel_rate =link_freq_to_pixel_rate (link_freq); +__v4l2_ctrl_s_ctrl_int64 (ov05c->pixel_rate, pixel_rate); + +/* Update limits and set FPS to default */ + vblank_def = ov05c->cur_mode->vts_def - + ov05c->cur_mode->height; + vblank_min = ov05c->cur_mode->vts_min - + ov05c->cur_mode->height; +__v4l2_ctrl_modify_range (ov05c->vblank, vblank_min, +OV05C_VTS_MAX + - ov05c->cur_mode->height, +1 , + vblank_def); +__v4l2_ctrl_s_ctrl (ov05c->vblank, vblank_def); + h_blank = ov05c->cur_mode->hts; +__v4l2_ctrl_modify_range (ov05c->hblank, h_blank, + h_blank,1 , h_blank); + } + +mutex_unlock (&ov05c->mutex); + +return 0 ; +} + +static int ov05c_start_streaming (struct ov05c *ov05c) +{ +struct i2c_client *client =v4l2_get_subdevdata (&ov05c->sd); +const struct ov05c_reg_list *reg_list; +int ret =0 ; + +/* Apply default values of current mode */ + reg_list = &ov05c->cur_mode->reg_list; +cci_multi_reg_write (ov05c->regmap, reg_list->regs, reg_list->num_of_regs, + &ret); +if (ret) { +dev_err (&client->dev,"%s failed to set mode, ret: %d\n" , __func__, ret); +return ret; + } + +/* Apply customized values from user */ + ret =__v4l2_ctrl_handler_setup (ov05c->sd.ctrl_handler); +if (ret) { +dev_err (&client->dev,"__v4l2_ctrl_handler_setup err:%d" , ret); +return ret; + } + +cci_multi_reg_write (ov05c->regmap, mode_OV05C_stream_on_regs, +ARRAY_SIZE (mode_OV05C_stream_on_regs), &ret); +if (ret) +dev_err (&client->dev,"%s failed to start the streaming\n" , __func__); +
Quoted 9 lines
drivers/media/i2c/ov05c.c line 717
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+return ret; +} + +static int ov05c_stop_streaming (struct ov05c *ov05c) +{ +int ret =0 ;Please declare temporary and return value variables as last.
Done. Updated in V2.
Quoted 27 lines
Quoted 13 lines
drivers/media/i2c/ov05c.c new file +13
-0+struct i2c_client *client =v4l2_get_subdevdata (&ov05c->sd); + +cci_multi_reg_write (ov05c->regmap, mode_OV05C_stream_off_regs, +ARRAY_SIZE (mode_OV05C_stream_off_regs), &ret); +if (ret) +dev_err (&client->dev,"%s failed to stop the streaming\n" , __func__); + +return ret; +} + +static void ov05c_sensor_enable (struct ov05c *ov05c,bool enable) +{ +if (enable) {drivers/media/i2c/ov05c.c line 740
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+gpiod_set_value (ov05c->enable_gpio,0 ); +usleep_range (10 ,20 ); + +gpiod_set_value (ov05c->enable_gpio,1 ); +/* The delay is to make sure the sensor is completely turned on */ +usleep_range (1000 ,2000 ); + }else { +gpiod_set_value (ov05c->enable_gpio,0 ); +usleep_range (10 ,20 ); + }These belong to their respective runtime PM callbacks. At least in the enable case the order seems to be wrong, too.
Quoted 6 lines
drivers/media/i2c/ov05c.c line 743
Quoted 3 lines
drivers/media/i2c/ov05c.c new file +3
-0+} + +static int ov05c_set_stream (struct v4l2_subdev *sd,int enable)Please switch to enable_streams/disable_streams pad ops instead.
sure, implemented enable_streams/disable_streams in V2.
Quoted 82 lines
Quoted 82 lines
drivers/media/i2c/ov05c.c new file +82
-0+{ +struct ov05c *ov05c =to_ov05c (sd); +struct i2c_client *client =v4l2_get_subdevdata (sd); +int ret =0 ; + +mutex_lock (&ov05c->mutex); + +if (enable) { +ov05c_sensor_enable (ov05c, true); + + ret =pm_runtime_resume_and_get (&client->dev); +if (ret <0 ) + goto err_unlock; + +/* +* Apply default & customized values +* and then start streaming. +*/ + ret =ov05c_start_streaming (ov05c); +if (ret) + goto err_rpm_put; + }else { +ov05c_stop_streaming (ov05c); +pm_runtime_put (&client->dev); + +ov05c_sensor_enable (ov05c, false); + } + +mutex_unlock (&ov05c->mutex); + +return ret; + +err_rpm_put: +pm_runtime_put (&client->dev); +err_unlock: +mutex_unlock (&ov05c->mutex); + +return ret; +} + +static const struct v4l2_subdev_video_ops ov05c_video_ops = { + .s_stream = ov05c_set_stream, +}; + +static const struct v4l2_subdev_pad_ops ov05c_pad_ops = { + .enum_mbus_code = ov05c_enum_mbus_code, + .get_fmt = ov05c_get_pad_format, + .set_fmt = ov05c_set_pad_format, + .enum_frame_size = ov05c_enum_frame_size, +}; + +static const struct v4l2_subdev_ops ov05c_subdev_ops = { + .video = &ov05c_video_ops, + .pad = &ov05c_pad_ops, +}; + +static const struct media_entity_operations ov05c_subdev_entity_ops = { + .link_validate = v4l2_subdev_link_validate, +}; + +static const struct v4l2_subdev_internal_ops ov05c_internal_ops = { + .open = ov05c_open, +}; + +static int ov05c_init_controls (struct ov05c *ov05c) +{ +struct i2c_client *client =v4l2_get_subdevdata (&ov05c->sd); +struct v4l2_fwnode_device_properties props; +struct v4l2_ctrl_handler *ctrl_hdlr; +const struct ov05c_mode *mode; +s64 exposure_max; +s64 vblank_def; +s64 vblank_min; +s64 hblank; +s64 pixel_rate_max; +u32 max_items; +int ret; + +/* Initialize V4L2 control handler with 10 items */ + ret =v4l2_ctrl_handler_init (&ov05c->ctrl_handler,10 ); +if (ret) +return ret;
Quoted 9 lines
drivers/media/i2c/ov05c.c line 830
Quoted 5 lines
drivers/media/i2c/ov05c.c new file +5
-0+ ctrl_hdlr = &ov05c->ctrl_handler; + +/* Initialize mutex for serialization */ +mutex_init (&ov05c->mutex); + ctrl_hdlr->lock = &ov05c->mutex;I'd use the control lock for sub-device state, too. Again, see the imx219 driver.
We removed the mutex variables in V2, please see V2 and let us know your feedback.
Quoted 95 lines
Quoted 95 lines
drivers/media/i2c/ov05c.c new file +95
-0+ +/* Initialize Link frequency control item */ + max_items =ARRAY_SIZE (ov05c_link_freq_menu_items) -1 ; + ov05c->link_freq =v4l2_ctrl_new_int_menu (ctrl_hdlr, +NULL , +V4L2_CID_LINK_FREQ , + max_items, +0 , + ov05c_link_freq_menu_items); +if (ov05c->link_freq) + ov05c->link_freq->flags |=V4L2_CTRL_FLAG_READ_ONLY ; + +/* Initialize Pixel rate control item */ + pixel_rate_max =link_freq_to_pixel_rate (ov05c_link_freq_menu_items[0 ]); + ov05c->pixel_rate =v4l2_ctrl_new_std (ctrl_hdlr,NULL , +V4L2_CID_PIXEL_RATE , +0 , pixel_rate_max, +1 , pixel_rate_max); + +/* Initialize VBLANK control item */ + mode = ov05c->cur_mode; + vblank_def = mode->vts_def - mode->height; + vblank_min = mode->vts_min - mode->height; + ov05c->vblank =v4l2_ctrl_new_std (ctrl_hdlr, &ov05c_ctrl_ops, +V4L2_CID_VBLANK , + vblank_min,OV05C_VTS_MAX - mode->height, +1 , vblank_def); + +/* Initialize HBLANK control item */ + hblank =max (0 , ov05c->cur_mode->hts - ov05c->cur_mode->width); + ov05c->hblank =v4l2_ctrl_new_std (ctrl_hdlr,NULL , +V4L2_CID_HBLANK , + hblank, hblank,1 , hblank); +if (ov05c->hblank) + ov05c->hblank->flags |=V4L2_CTRL_FLAG_READ_ONLY ; + +/* Initialize EXPOSURE control item */ + exposure_max = mode->vts_def -OV05C_EXPOSURE_MAX_MARGIN ; + ov05c->exposure =v4l2_ctrl_new_std (ctrl_hdlr, &ov05c_ctrl_ops, +V4L2_CID_EXPOSURE , +OV05C_EXPOSURE_MIN , exposure_max, +OV05C_EXPOSURE_STEP , exposure_max); + +/* Initialize Analog gain control item */ +v4l2_ctrl_new_std (ctrl_hdlr, &ov05c_ctrl_ops,V4L2_CID_ANALOGUE_GAIN , +OV05C_ANA_GAIN_MIN ,OV05C_ANA_GAIN_MAX , +OV05C_ANA_GAIN_STEP ,OV05C_ANA_GAIN_DEFAULT ); + +/* Initialize Digital gain control item */ +v4l2_ctrl_new_std (ctrl_hdlr, &ov05c_ctrl_ops,V4L2_CID_DIGITAL_GAIN , +OV05C_DGTL_GAIN_MIN ,OV05C_DGTL_GAIN_MAX , +OV05C_DGTL_GAIN_STEP ,OV05C_DGTL_GAIN_DEFAULT ); + + +/* Initialize Test pattern control item */ +v4l2_ctrl_new_std_menu_items (ctrl_hdlr, &ov05c_ctrl_ops, +V4L2_CID_TEST_PATTERN , +ARRAY_SIZE (ov05c_test_pattern_menu) -1 ,0 , +0 , ov05c_test_pattern_menu); + +if (ctrl_hdlr->error) { + ret = ctrl_hdlr->error; +dev_err (&client->dev,"%s V4L2 control init failed (%d)" , __func__, ret); + goto error; + } + + ret =v4l2_fwnode_device_parse (&client->dev, &props); +if (ret) + goto error; + + ret =v4l2_ctrl_new_fwnode_properties (ctrl_hdlr, &ov05c_ctrl_ops, &props); +if (ret) + goto error; + + ov05c->sd.ctrl_handler = ctrl_hdlr; + +return 0 ; + +error: +v4l2_ctrl_handler_free (ctrl_hdlr); +mutex_destroy (&ov05c->mutex); + +return ret; +} + +static void ov05c_free_controls (struct ov05c *ov05c) +{ +v4l2_ctrl_handler_free (ov05c->sd.ctrl_handler); +mutex_destroy (&ov05c->mutex); +} + +static int ov05c_probe (struct i2c_client *client) +{ +struct ov05c *ov05c; +int i, ret;
Quoted 9 lines
drivers/media/i2c/ov05c.c line 931
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+ + ov05c =devm_kzalloc (&client->dev,sizeof (*ov05c),GFP_KERNEL ); +if (!ov05c) +return -ENOMEM ; + + client->dev.init_name =DRV_NAME ;This is hardly needed.
yes, agreed, its removed in V2.
Quoted 3 lines
Please also check the V4L2 fwnode endpoint and validate it. See how other drivers do this.
thank you, we added support to parse v4l2 endpoint fwnode in V2.
Quoted 6 lines
drivers/media/i2c/ov05c.c line 933
Quoted 2 lines
drivers/media/i2c/ov05c.c new file +2
-0+ +/* create sensor enable gpio control */ The comment is redundant, please remove it. I'd say that goes for the rest of the comments in the function, too.
Done. Removed in V2.
Quoted 8 lines
drivers/media/i2c/ov05c.c line 934
Quoted 1 line
drivers/media/i2c/ov05c.c new file +1
-0+ ov05c->enable_gpio =devm_gpiod_get (&client->dev,"sensor0_enable" ,GPIOD_OUT_LOW );Please run
$ ./scripts/checkpatch.pl --strict --max-line-length=80on this.
sure, we have taken care of it in V2, all lines are within 80 characters.
Quoted 3 lines
Regarding the GPIO name, where does it come from? I'd instead use "enable" or "reset" (in which case the polarity would be differente).
We used this name to differentiate the two GPIO PINs that has to be programmed for RGB streaming to work with this sensor. Is it okay to use the same name?
Quoted 3 lines
Which external clock frequency the driver assumes? You should also check for it.
Done. Added the check for ref clock in V2.
Quoted 19 lines
Quoted 5 lines
drivers/media/i2c/ov05c.c new file +5
-0+if (IS_ERR_OR_NULL (ov05c->enable_gpio)) +return PTR_ERR (ov05c->enable_gpio); + +/* Initialize subdev */ +v4l2_i2c_subdev_init (&ov05c->sd, client, &ov05c_subdev_ops);drivers/media/i2c/ov05c.c line 949
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+ +/* Initialize CCI */ + ov05c->regmap =devm_cci_regmap_init_i2c (client,8 ); +if (IS_ERR (ov05c->regmap)) { +dev_err (&client->dev,"Failed to initialize CCI\n" ); +return PTR_ERR (ov05c->regmap); + } + +/* Set default mode to max resolution */ + ov05c->cur_mode = &supported_modes[0 ];Please avoid having state information in device context struct whenever possible.
Quoted 15 lines
drivers/media/i2c/ov05c.c line 961
Quoted 12 lines
drivers/media/i2c/ov05c.c new file +12
-0+ +/* Initialize V4L2 controls */ + ret =ov05c_init_controls (ov05c); +if (ret) +return ret; + +/* Initialize V4L2 subdev */ + ov05c->sd.internal_ops = &ov05c_internal_ops; + ov05c->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; + ov05c->sd.entity.ops = &ov05c_subdev_entity_ops; + ov05c->sd.entity.function =MEDIA_ENT_F_CAM_SENSOR ; + ov05c->sd.entity.name ="OV05C" ;The entity name has been set by
v4l2_i2c_subdev_init()already.
Done. Removed in V2.
Quoted 7 lines
drivers/media/i2c/ov05c.c line 965
Quoted 4 lines
drivers/media/i2c/ov05c.c new file +4
-0+ +/* Initialize source pad */ +for (i =0 ; i <NUM_OF_PADS ; i++) + ov05c->pads[i].flags =MEDIA_PAD_FL_SOURCE ;Three source pads? What are they for?
Updated to 1 pad in V2.
Quoted 20 lines
Quoted 6 lines
drivers/media/i2c/ov05c.c new file +6
-0+ + ret =media_entity_pads_init (&ov05c->sd.entity,NUM_OF_PADS , ov05c->pads); +if (ret) + goto error_handler_free; + + ret =v4l2_async_register_subdev_sensor (&ov05c->sd);drivers/media/i2c/ov05c.c line 981
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+if (ret) + goto error_media_entity; + +/* +* Device is already turned on by i2c-core with ACPI domain PM. +* Enable runtime PM and turn off the device. +*/ +pm_runtime_set_active (&client->dev); +pm_runtime_enable (&client->dev); +pm_runtime_idle (&client->dev);Please read <URL:https://hverkuil.home.xs4all.nl/spec/driver-api/v4l2-subdev.html#media-registering-async-subdevs>.
Quoted 6 lines
drivers/media/i2c/ov05c.c line 983
Quoted 2 lines
drivers/media/i2c/ov05c.c new file +2
-0+ +dev_info (&client->dev,"%s success" , __func__);This looks like a development time leftover. Please remove this and other similar cases.
Done. Removed in V2. Thank you.
Quoted 60 lines
Quoted 17 lines
drivers/media/i2c/ov05c.c new file +17
-0+ +return 0 ; + +error_media_entity: +media_entity_cleanup (&ov05c->sd.entity); + +error_handler_free: +ov05c_free_controls (ov05c); + +return ret; +} + +static void ov05c_remove (struct i2c_client *client) +{ +struct v4l2_subdev *sd =i2c_get_clientdata (client); +struct ov05c *ov05c =to_ov05c (sd); +drivers/media/i2c/ov05c.c line 1010
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+v4l2_async_unregister_subdev (sd); +media_entity_cleanup (&sd->entity); +ov05c_free_controls (ov05c); + +pm_runtime_disable (&client->dev); +pm_runtime_set_suspended (&client->dev); +} + +static const struct i2c_device_id ov05c_id[] = { + {"ov05c" ,0 },You probably don't need this.
Which brings us to a question: is the platform you're using this DT or ACPI based? You'll need appropriate compatible /
_HIDand in DT case bindings, too.Quoted 11 lines
drivers/media/i2c/ov05c.c new file +11
-0+ { } +}; + +MODULE_DEVICE_TABLE (i2c, ov05c_id); + +static struct i2c_driver ov05c_i2c_driver = { + .driver = { + .name =DRV_NAME , + }, + .id_table = ov05c_id, + .probe = ov05c_probe,drivers/media/i2c/ov05c.c line 1031
Quoted 10 lines
drivers/media/i2c/ov05c.c new file +10
-0+ .remove = ov05c_remove, +}; + +module_i2c_driver (ov05c_i2c_driver); + +MODULE_AUTHOR ("Venkata Narendra Kumar Gutta <[email protected]>" ); +MODULE_AUTHOR ("Pratap Nirujogi <[email protected]>" ); +MODULE_DESCRIPTION ("OmniVision OV05C sensor driver" ); +MODULE_ALIAS ("ov05c" ); +MODULE_LICENSE ("GPL and additional rights" );--
Kind regards,Sakari Ailus
Hi Pratap,
kernel test robot noticed the following build warnings:
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Pratap-Nirujogi/media-i2c-Add-OV05C-camera-sensor-driver/20250301-005638 base: https://git.linuxtv.org/media-ci/media-pending.git master patch link: https://lore.kernel.org/r/20250228165317.3468075-1-pratap.nirujogi%40amd.com patch subject: [PATCH] media: i2c: Add OV05C camera sensor driver config: arm64-randconfig-r071-20250312 (https://download.01.org/0day-ci/archive/20250314/[email protected]/config) compiler: aarch64-linux-gcc (GCC) 14.2.0
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]> | Reported-by: Dan Carpenter <[email protected]> | Closes: https://lore.kernel.org/r/[email protected]/
smatch warnings:drivers/media/i2c/ov05c.c:936 ov05c_probe() warn: passing zero to 'PTR_ERR'
vim +/PTR_ERR +936 drivers/media/i2c/ov05c.c
6da03431f4f1e18 Pratap Nirujogi 2025-02-28 922 static int ov05c_probe(struct i2c_client *client)
6da03431f4f1e18 Pratap Nirujogi 2025-02-28 923 {
6da03431f4f1e18 Pratap Nirujogi 2025-02-28 924 struct ov05c *ov05c;
6da03431f4f1e18 Pratap Nirujogi 2025-02-28 925 int i, ret;
6da03431f4f1e18 Pratap Nirujogi 2025-02-28 926
6da03431f4f1e18 Pratap Nirujogi 2025-02-28 927 ov05c = devm_kzalloc(&client->dev, sizeof(*ov05c), GFP_KERNEL);
6da03431f4f1e18 Pratap Nirujogi 2025-02-28 928 if (!ov05c)
6da03431f4f1e18 Pratap Nirujogi 2025-02-28 929 return -ENOMEM;
6da03431f4f1e18 Pratap Nirujogi 2025-02-28 930
6da03431f4f1e18 Pratap Nirujogi 2025-02-28 931 client->dev.init_name = DRV_NAME;
6da03431f4f1e18 Pratap Nirujogi 2025-02-28 932
6da03431f4f1e18 Pratap Nirujogi 2025-02-28 933 /* create sensor enable gpio control */
6da03431f4f1e18 Pratap Nirujogi 2025-02-28 934 ov05c->enable_gpio = devm_gpiod_get(&client->dev, "sensor0_enable", GPIOD_OUT_LOW);
6da03431f4f1e18 Pratap Nirujogi 2025-02-28 935 if (IS_ERR_OR_NULL(ov05c->enable_gpio))6da03431f4f1e18 Pratap Nirujogi 2025-02-28 @936 return PTR_ERR(ov05c->enable_gpio);
If devm_gpiod_get() returns NULL then we'd return success, but actually devm_gpiod_get() can't return NULL. Only error pointers.
6da03431f4f1e18 Pratap Nirujogi 2025-02-28 937
6da03431f4f1e18 Pratap Nirujogi 2025-02-28 938 /* Initialize subdev */
6da03431f4f1e18 Pratap Nirujogi 2025-02-28 939 v4l2_i2c_subdev_init(&ov05c->sd, client, &ov05c_subdev_ops);
6da03431f4f1e18 Pratap Nirujogi 2025-02-28 940
6da03431f4f1e18 Pratap Nirujogi 2025-02-28 941 /* Initialize CCI */
6da03431f4f1e18 Pratap Nirujogi 2025-02-28 942 ov05c->regmap = devm_cci_regmap_init_i2c(client, 8);
6da03431f4f1e18 Pratap Nirujogi 2025-02-28 943 if (IS_ERR(ov05c->regmap)) {Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Hi Dan,
Thanks for reporting this issue.
Thanks,
Pratap
Quoted 41 lines · Dan Carpenter
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Hi Pratap,
kernel test robot noticed the following build warnings:
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Pratap-Nirujogi/media-i2c-Add-OV05C-camera-sensor-driver/20250301-005638 base: https://git.linuxtv.org/media-ci/media-pending.git master patch link: https://lore.kernel.org/r/20250228165317.3468075-1-pratap.nirujogi%40amd.com patch subject: [PATCH] media: i2c: Add OV05C camera sensor driver config: arm64-randconfig-r071-20250312 (https://download.01.org/0day-ci/archive/20250314/[email protected]/config) compiler: aarch64-linux-gcc (GCC) 14.2.0If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]> | Reported-by: Dan Carpenter <[email protected]> | Closes: https://lore.kernel.org/r/[email protected]/smatch warnings:
drivers/media/i2c/ov05c.c:936ov05c_probe()warn: passing zero to 'PTR_ERR'vim +/PTR_ERR +936
drivers/media/i2c/ov05c.c6da03431f4f1e18 Pratap Nirujogi 2025-02-28 922 static int ov05c_probe(struct i2c_client *client) 6da03431f4f1e18 Pratap Nirujogi 2025-02-28 923 { 6da03431f4f1e18 Pratap Nirujogi 2025-02-28 924 struct ov05c *ov05c; 6da03431f4f1e18 Pratap Nirujogi 2025-02-28 925 int i, ret; 6da03431f4f1e18 Pratap Nirujogi 2025-02-28 926 6da03431f4f1e18 Pratap Nirujogi 2025-02-28 927 ov05c = devm_kzalloc(&client->dev, sizeof(*ov05c), GFP_KERNEL); 6da03431f4f1e18 Pratap Nirujogi 2025-02-28 928 if (!ov05c) 6da03431f4f1e18 Pratap Nirujogi 2025-02-28 929 return -ENOMEM; 6da03431f4f1e18 Pratap Nirujogi 2025-02-28 930 6da03431f4f1e18 Pratap Nirujogi 2025-02-28 931 client->dev.init_name = DRV_NAME; 6da03431f4f1e18 Pratap Nirujogi 2025-02-28 932 6da03431f4f1e18 Pratap Nirujogi 2025-02-28 933 /* create sensor enable gpio control */ 6da03431f4f1e18 Pratap Nirujogi 2025-02-28 934 ov05c->enable_gpio = devm_gpiod_get(&client->dev, "sensor0_enable", GPIOD_OUT_LOW); 6da03431f4f1e18 Pratap Nirujogi 2025-02-28 935 if (IS_ERR_OR_NULL(ov05c->enable_gpio))
Quoted 5 lines
6da03431f4f1e18Pratap Nirujogi 2025-02-28 @936 returnPTR_ERR(ov05c->enable_gpio);If
devm_gpiod_get()returns NULL then we'd return success, but actuallydevm_gpiod_get()can't return NULL. Only error pointers.
We are working on the feedback provided by reviewers on v1, we will take care of this issue too replacing IS_ERR_OR_NULL() with IS_ERR() while submitting the v2. Thank you!
Quoted 12 lines
6da03431f4f1e18 Pratap Nirujogi 2025-02-28 937 6da03431f4f1e18 Pratap Nirujogi 2025-02-28 938 /* Initialize subdev */ 6da03431f4f1e18 Pratap Nirujogi 2025-02-28 939 v4l2_i2c_subdev_init(&ov05c->sd, client, &ov05c_subdev_ops); 6da03431f4f1e18 Pratap Nirujogi 2025-02-28 940 6da03431f4f1e18 Pratap Nirujogi 2025-02-28 941 /* Initialize CCI */ 6da03431f4f1e18 Pratap Nirujogi 2025-02-28 942 ov05c->regmap = devm_cci_regmap_init_i2c(client, 8); 6da03431f4f1e18 Pratap Nirujogi 2025-02-28 943 if (IS_ERR(ov05c->regmap)) {--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki