media: i2c: Add OmniVision OG0VA1B camera sensor driver
Subsystems (4)
v2 cover media: i2c: Add OmniVision OG0VA1B camera sensor driver
Add OmniVision OG0VA1B driver support. The OmniVision OG0VA1B is a 1/10-inch monochrome CMOS VGA image sensor. It outputs 10-bit raw (Y10) frames at up to 640x480 resolution over a single-lane MIPI CSI-2 interface and is controlled via an I2C-compatible SCCB bus.
This driver has been verified on the Purwa EVK.
---
Changes in v2:
- Integrate OG0VA1B into the existing og0ve1b driver and binding
instead. -- Vladimir
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Wenmeng Liu (3):
dt-bindings: media: i2c: og0ve1b: Add OmniVision OG0VA1B camera sensor
media: i2c: og0ve1b: Introduce per-sensor data structure
media: i2c: og0ve1b: Add support for OmniVision OG0VA1B
.../bindings/media/i2c/ovti,og0ve1b.yaml | 4 +- drivers/media/i2c/og0ve1b.c | 333 ++++++++++++++++++--- 2 files changed, 299 insertions(+), 38 deletions(-)
---
base-commit: 4f441960e691d37c880d2cc004de06bb5b6bd5e4
change-id: 20260618-og0va1b-55bbf3cabb0e
Best regards,
Signature · 1 line
Wenmeng Liu <[email protected]>
PATCH v2 1/3 dt-bindings: media: i2c: og0ve1b: Add OmniVision OG0VA1B camera sensor
The OmniVision OG0VA1B is a monochrome image sensor closely related to the already supported OG0VE1B. It shares the same SCCB control interface, power supplies, clock and MIPI D-PHY description, but differs in its chip ID, register programming and output format.
--- Documentation/devicetree/bindings/media/i2c/ovti,og0ve1b.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/media/i2c/ovti,og0ve1b.yaml +3 -1
@@ -21,7 +21,9 @@ allOf: properties: compatible: - const: ovti,og0ve1b + enum: + - ovti,og0va1b + - ovti,og0ve1b reg: maxItems: 1
Signature · 1 line
2.34.1
Re: [PATCH v2 1/3] dt-bindings: media: i2c: og0ve1b: Add OmniVision OG0VA1B camera sensor
Hi Wenmeng,
thank you for the updates!
Quoted 16 lines · Wenmeng Liu
The OmniVision OG0VA1B is a monochrome image sensor closely related to the already supported OG0VE1B. It shares the same SCCB control interface, power supplies, clock and MIPI D-PHY description, but differs in its chip ID, register programming and output format.
Signed-off-by Wenmeng Liu <[email protected]>--- Documentation/devicetree/bindings/media/i2c/ovti,og0ve1b.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/media/i2c/ovti,og0ve1b.yaml +0
-0
Documentation/devicetree/bindings/media/i2c/ovti,og0ve1b.yaml allOf: · line 29
Quoted 10 lines
Documentation/devicetree/bindings/media/i2c/ovti,og0ve1b.yaml +3
-1@@ -21,7 +21,9 @@ allOf: properties: compatible: - const: ovti,og0ve1b + enum: + - ovti,og0va1b + - ovti,og0ve1b reg: maxItems: 1
Since it becomes a shared dt documentation, it will be accepted to get a generalised description section also, in any case:
Signature · 2 lines
Best wishes, Vladimir
Re: [PATCH v2 1/3] dt-bindings: media: i2c: og0ve1b: Add OmniVision OG0VA1B camera sensor
Hi Vladimir,
Quoted 33 lines · Vladimir Zapolskiy
Hi Wenmeng,
thank you for the updates!
Quoted 15 lines · Wenmeng Liu
The OmniVision OG0VA1B is a monochrome image sensor closely related to the already supported OG0VE1B. It shares the same SCCB control interface, power supplies, clock and MIPI D-PHY description, but differs in its chip ID, register programming and output format.
Signed-off-by Wenmeng Liu <[email protected]>---
Documentation/devicetree/bindings/media/i2c/ovti,og0ve1b.yaml| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/media/i2c/ovti,og0ve1b.yaml +0
-0@@ -21,7 +21,9 @@ allOf:Quoted 9 lines
properties:
compatible:
- const: ovti,og0ve1b
+ enum:
+ - ovti,og0va1b
+ - ovti,og0ve1b
reg:
maxItems: 1Since it becomes a shared dt documentation, it will be accepted to get a generalised description section also, in any case:
Quoted 2 lines
Reviewed-by Vladimir Zapolskiy <[email protected]>
Thanks for your review, will change description in next version.
Best regards,
Wenmeng
Re: [PATCH v2 1/3] dt-bindings: media: i2c: og0ve1b: Add OmniVision OG0VA1B camera sensor
In reply to Wenmeng Liupw-bot: not-applicable
PATCH v2 2/3 media: i2c: og0ve1b: Introduce per-sensor data structure
In reply to Wenmeng LiuIn preparation for supporting further OmniVision sensors that share most of this driver, move the sensor-specific parameters (chip id, MCLK frequency, test pattern register, link frequency menu and the list of supported modes) into a new struct og0ve1b_sensor_data, selected through i2c_get_match_data() at probe time.
--- drivers/media/i2c/og0ve1b.c | 101 +++++++++++++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 34 deletions(-)
drivers/media/i2c/og0ve1b.c +67 -34
@@ -66,10 +66,21 @@ struct og0ve1b_mode {u32 hts;/* Horizontal timing size */ u32 vts;/* Default vertical timing size */ u32 bpp;/* Bits per pixel */ +u32 code;/* MEDIA_BUS_FMT code */ const struct og0ve1b_reg_list reg_list;/* Sensor register setting */ }; +struct og0ve1b_sensor_data { +u64 chip_id; +unsigned long mclk_freq; +u32 test_pattern_reg; +const s64 *link_freq_menu; +int num_link_freqs; +const struct og0ve1b_mode *modes; +int num_modes; +}; +static const char *const og0ve1b_test_pattern_menu[] = {"Disabled" ,"Vertical Colour Bars" ,
@@ -97,8 +108,7 @@ struct og0ve1b {struct v4l2_ctrl *exposure;struct v4l2_ctrl_handler ctrl_handler; -/* Saved register value */ -u64 pre_isp; +const struct og0ve1b_sensor_data *sensor; };static const struct cci_reg_sequence og0ve1b_640x480_120fps_mode[] = {
@@ -254,6 +264,7 @@ static const struct og0ve1b_mode supported_modes[] = { .hts = 792, .vts = 568, .bpp = 8, + .code = MEDIA_BUS_FMT_Y8_1X8, .reg_list = { .regs = og0ve1b_640x480_120fps_mode, .num_regs = ARRAY_SIZE(og0ve1b_640x480_120fps_mode),
@@ -261,23 +272,39 @@ static const struct og0ve1b_mode supported_modes[] = { }, }; +static const struct og0ve1b_sensor_data og0ve1b_data = { + .chip_id =OG0VE1B_CHIP_ID , + .mclk_freq =OG0VE1B_MCLK_FREQ_24MHZ , + .test_pattern_reg =OG0VE1B_REG_PRE_ISP , + .link_freq_menu = og0ve1b_link_freq_menu, + .num_link_freqs =ARRAY_SIZE (og0ve1b_link_freq_menu), + .modes = supported_modes, + .num_modes =ARRAY_SIZE (supported_modes), +}; +static int og0ve1b_enable_test_pattern (struct og0ve1b *og0ve1b,u32 pattern) { -u64 val = og0ve1b->pre_isp; +u32 reg = og0ve1b->sensor->test_pattern_reg; +u64 val; +int ret; + + ret =cci_read (og0ve1b->regmap, reg, &val,NULL ); +if (ret) +return ret;if (pattern) val |=OG0VE1B_TEST_PATTERN_ENABLE ;else val &= ~OG0VE1B_TEST_PATTERN_ENABLE ; -return cci_write (og0ve1b->regmap,OG0VE1B_REG_PRE_ISP , val,NULL ); +return cci_write (og0ve1b->regmap, reg, val,NULL ); }static int og0ve1b_set_ctrl (struct v4l2_ctrl *ctrl) { struct og0ve1b *og0ve1b = container_of(ctrl->handler, struct og0ve1b, ctrl_handler); -const struct og0ve1b_mode *mode = &supported_modes[0 ]; +const struct og0ve1b_mode *mode = &og0ve1b->sensor->modes[0 ];s64 exposure_max;int ret;
@@ -333,7 +360,8 @@ static const struct v4l2_ctrl_ops og0ve1b_ctrl_ops = {static int og0ve1b_init_controls (struct og0ve1b *og0ve1b) {struct v4l2_ctrl_handler *ctrl_hdlr = &og0ve1b->ctrl_handler; -const struct og0ve1b_mode *mode = &supported_modes[0 ]; +const struct og0ve1b_mode *mode = &og0ve1b->sensor->modes[0 ]; +const struct og0ve1b_sensor_data *sensor = og0ve1b->sensor;s64 exposure_max, pixel_rate, h_blank, v_blank;struct v4l2_fwnode_device_properties props;struct v4l2_ctrl *ctrl;
@@ -343,12 +371,12 @@ static int og0ve1b_init_controls(struct og0ve1b *og0ve1b) ctrl =v4l2_ctrl_new_int_menu (ctrl_hdlr, &og0ve1b_ctrl_ops,V4L2_CID_LINK_FREQ , -ARRAY_SIZE (og0ve1b_link_freq_menu) -1 , -0 , og0ve1b_link_freq_menu); + sensor->num_link_freqs -1 , +0 , sensor->link_freq_menu);if (ctrl) ctrl->flags |=V4L2_CTRL_FLAG_READ_ONLY ; - pixel_rate = og0ve1b_link_freq_menu[0 ] / mode->bpp; + pixel_rate = sensor->link_freq_menu[0 ] / mode->bpp;v4l2_ctrl_new_std (ctrl_hdlr, &og0ve1b_ctrl_ops,V4L2_CID_PIXEL_RATE ,0 , pixel_rate,1 , pixel_rate);
@@ -407,7 +435,7 @@ static int og0ve1b_init_controls(struct og0ve1b *og0ve1b)static void og0ve1b_update_pad_format (const struct og0ve1b_mode *mode,struct v4l2_mbus_framefmt *fmt) { - fmt->code =MEDIA_BUS_FMT_Y8_1X8 ; + fmt->code = mode->code; fmt->width = mode->width; fmt->height = mode->height; fmt->field =V4L2_FIELD_NONE ;
@@ -421,8 +449,8 @@ static int og0ve1b_enable_streams(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, u32 pad, u64 streams_mask) { -const struct og0ve1b_reg_list *reg_list = &supported_modes[0 ].reg_list; struct og0ve1b *og0ve1b = to_og0ve1b(sd); +const struct og0ve1b_reg_list *reg_list = &og0ve1b->sensor->modes[0 ].reg_list;int ret; ret =pm_runtime_resume_and_get (og0ve1b->dev);
@@ -484,13 +512,14 @@ static int og0ve1b_set_pad_format(struct v4l2_subdev *sd,struct v4l2_subdev_state *state, struct v4l2_subdev_format *fmt) { + struct og0ve1b *og0ve1b = to_og0ve1b(sd);struct v4l2_mbus_framefmt *format;const struct og0ve1b_mode *mode; format =v4l2_subdev_state_get_format (state,0 ); - mode =v4l2_find_nearest_size (supported_modes, -ARRAY_SIZE (supported_modes), + mode =v4l2_find_nearest_size (og0ve1b->sensor->modes, + og0ve1b->sensor->num_modes, width, height, fmt->format.width, fmt->format.height);
@@ -505,10 +534,12 @@ static int og0ve1b_enum_mbus_code(struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state, struct v4l2_subdev_mbus_code_enum *code) { + struct og0ve1b *og0ve1b = to_og0ve1b(sd); +if (code->index >0 )return -EINVAL ; - code->code =MEDIA_BUS_FMT_Y8_1X8 ; + code->code = og0ve1b->sensor->modes[0 ].code;return 0 ; }
@@ -517,15 +548,18 @@ static int og0ve1b_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)) + struct og0ve1b *og0ve1b = to_og0ve1b(sd); +const struct og0ve1b_sensor_data *sensor = og0ve1b->sensor; + +if (fse->index >= sensor->num_modes)return -EINVAL ; -if (fse->code !=MEDIA_BUS_FMT_Y8_1X8 ) +if (fse->code != sensor->modes[fse->index].code)return -EINVAL ; - fse->min_width = supported_modes[fse->index].width; + fse->min_width = sensor->modes[fse->index].width; fse->max_width = fse->min_width; - fse->min_height = supported_modes[fse->index].height; + fse->min_height = sensor->modes[fse->index].height; fse->max_height = fse->min_height;return 0 ;
@@ -534,13 +568,14 @@ static int og0ve1b_enum_frame_size(struct v4l2_subdev *sd,static int og0ve1b_init_state (struct v4l2_subdev *sd,struct v4l2_subdev_state *state) { +struct og0ve1b *og0ve1b =to_og0ve1b (sd);struct v4l2_subdev_format fmt = { .which =V4L2_SUBDEV_FORMAT_TRY , .pad =0 , .format = { - .code =MEDIA_BUS_FMT_Y8_1X8 , - .width = supported_modes[0 ].width, - .height = supported_modes[0 ].height, + .code = og0ve1b->sensor->modes[0 ].code, + .width = og0ve1b->sensor->modes[0 ].width, + .height = og0ve1b->sensor->modes[0 ].height, }, };
@@ -586,18 +621,13 @@ static int og0ve1b_identify_sensor(struct og0ve1b *og0ve1b)return ret; } -if (val !=OG0VE1B_CHIP_ID ) { -dev_err (og0ve1b->dev,"chip id mismatch: %x!=%llx\n" , -OG0VE1B_CHIP_ID , val); +if (val != og0ve1b->sensor->chip_id) { +dev_err (og0ve1b->dev,"chip id mismatch: %llx!=%llx\n" , + og0ve1b->sensor->chip_id, val);return -ENODEV ; } - ret =cci_read (og0ve1b->regmap,OG0VE1B_REG_PRE_ISP , - &og0ve1b->pre_isp,NULL ); -if (ret) -dev_err (og0ve1b->dev,"failed to read pre_isp: %d\n" , ret); - -return ret; +return 0 ; }static int og0ve1b_check_hwcfg (struct og0ve1b *og0ve1b)
@@ -624,8 +654,8 @@ static int og0ve1b_check_hwcfg(struct og0ve1b *og0ve1b) ret =v4l2_link_freq_to_bitmap (og0ve1b->dev, bus_cfg.link_frequencies, bus_cfg.nr_of_link_frequencies, - og0ve1b_link_freq_menu, -ARRAY_SIZE (og0ve1b_link_freq_menu), + og0ve1b->sensor->link_freq_menu, + og0ve1b->sensor->num_link_freqs, &freq_bitmap);v4l2_fwnode_endpoint_free (&bus_cfg);
@@ -686,6 +716,9 @@ static int og0ve1b_probe(struct i2c_client *client)return -ENOMEM ; og0ve1b->dev = &client->dev; + og0ve1b->sensor =i2c_get_match_data (client); +if (!og0ve1b->sensor) +return -ENODEV ;v4l2_i2c_subdev_init (&og0ve1b->sd, client, &og0ve1b_subdev_ops);
@@ -700,7 +733,7 @@ static int og0ve1b_probe(struct i2c_client *client) "failed to get XVCLK clock\n"); freq =clk_get_rate (og0ve1b->xvclk); -if (freq && freq !=OG0VE1B_MCLK_FREQ_24MHZ ) +if (freq && freq != og0ve1b->sensor->mclk_freq)return dev_err_probe (og0ve1b->dev, -EINVAL ,"XVCLK clock frequency %lu is not supported\n" , freq);
@@ -819,7 +852,7 @@ static const struct dev_pm_ops og0ve1b_pm_ops = { };static const struct of_device_id og0ve1b_of_match[] = { - { .compatible ="ovti,og0ve1b" }, + { .compatible ="ovti,og0ve1b" , .data = &og0ve1b_data }, {/* sentinel */ } };MODULE_DEVICE_TABLE (of, og0ve1b_of_match);
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v2 2/3] media: i2c: og0ve1b: Introduce per-sensor data structure
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Incorrect return value check of pm_runtime_get_if_active() leads to unbalanced PM usage count and potential log-spam. --
commit 77fd9b09419f467242cfd9a487b0ac45ff5344ef
Author: Wenmeng Liu <[email protected]>
media: i2c: og0ve1b: Introduce per-sensor data structure
This patch moves sensor-specific parameters into a new struct og0ve1b_sensor_data to prepare for supporting additional OmniVision sensors. The sensor data is selected at probe time using i2c_get_match_data().
Quoted 4 lines
drivers/media/i2c/og0ve1b.c +0
-0
[ ... ]
Quoted 1 line
drivers/media/i2c/og0ve1b.c +0
-0@@ -261,23 +272,39 @@ static const struct og0ve1b_mode supported_modes[] = {
[ ... ]
drivers/media/i2c/og0ve1b.c static const struct og0ve1b_mode supported_modes[] = { · line 309
Quoted 8 lines
static int
og0ve1b_set_ctrl(struct v4l2_ctrl *ctrl){drivers/media/i2c/og0ve1b.c +1
-1struct og0ve1b *og0ve1b = container_of(ctrl->handler, struct og0ve1b, ctrl_handler); -const struct og0ve1b_mode *mode = &supported_modes[0 ]; +const struct og0ve1b_mode *mode = &og0ve1b->sensor->modes[0 ];s64 exposure_max;int ret;
[Severity: High]
This isn't a bug introduced by this patch, but I noticed a pre-existing issue in this function regarding the return value check of pm_runtime_get_if_active().
Later in og0ve1b_set_ctrl(), the code does:
if (!pm_runtime_get_if_active(og0ve1b->dev))
return 0;Because pm_runtime_get_if_active() can return a negative error code (like -EINVAL when PM is disabled), the logical NOT operator will evaluate the negative error as false. This bypasses the error condition entirely, allowing execution to proceed to I2C hardware register writes and unconditionally calling pm_runtime_put().
Since the initial 'get' call did not increment the usage counter on error, the subsequent 'put' call decrements it improperly. Could this cause an unbalanced PM usage count underflow and trigger kernel warnings?
Should this condition be updated to explicitly check if the return value is less than or equal to zero?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Vladimir Zapolskiy
maintainerRe: [PATCH v2 2/3] media: i2c: og0ve1b: Introduce per-sensor data structure
In reply to Wenmeng LiuHi Wenmeng.
Quoted 16 lines · Wenmeng Liu
In preparation for supporting further OmniVision sensors that share most of this driver, move the sensor-specific parameters (chip id, MCLK frequency, test pattern register, link frequency menu and the list of supported modes) into a new struct
og0ve1b_sensor_data, selected throughi2c_get_match_data()at probe time.Signed-off-by Wenmeng Liu <[email protected]>--- drivers/media/i2c/og0ve1b.c | 101 +++++++++++++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 34 deletions(-)drivers/media/i2c/og0ve1b.c +0
-0
drivers/media/i2c/og0ve1b.c struct og0ve1b_mode { · line 69
Quoted 4 lines
drivers/media/i2c/og0ve1b.c +1
-0@@ -66,10 +66,21 @@ struct og0ve1b_mode {u32 hts;/* Horizontal timing size */ u32 vts;/* Default vertical timing size */ u32 bpp;/* Bits per pixel */ +u32 code;/* MEDIA_BUS_FMT code */
In this particular case of grayscale only sensors there is no need for both bpp and media bus format code, since there is a natural one-to-one mapping.
I'm fine with "code" just replacing "bpp", and in og0ve1b_init_controls() simply replace "bpp" with "(code == MEDIA_BUS_FMT_Y8_1X8 ? 8 : 10)".
Quoted 18 lines
drivers/media/i2c/og0ve1b.c +10
-0const struct og0ve1b_reg_list reg_list;/* Sensor register setting */ }; +struct og0ve1b_sensor_data { +u64 chip_id; +unsigned long mclk_freq; +u32 test_pattern_reg; +const s64 *link_freq_menu; +int num_link_freqs; +const struct og0ve1b_mode *modes; +int num_modes; +}; +static const char *const og0ve1b_test_pattern_menu[] = {"Disabled" ,"Vertical Colour Bars" ,
drivers/media/i2c/og0ve1b.c struct og0ve1b { · line 101
Quoted 5 lines
drivers/media/i2c/og0ve1b.c +0
-2@@ -97,8 +108,7 @@ struct og0ve1b {struct v4l2_ctrl *exposure;struct v4l2_ctrl_handler ctrl_handler; -/* Saved register value */ -u64 pre_isp;
I'm afraid this will break test pattern on og0ve1b, unfortunately it should be kept as is for now.
The register is used for something else, and IIRC even cci_update_bits() API does not work expectedly, it certainly should be read once and written later.
Hence it leaves an option to keep og0ve1b_enable_test_pattern() and then introduce in 3/3 a new og0va1b_enable_test_pattern() function, the selection will be done in runtime similarly to other og0ve/og0va branches.
drivers/media/i2c/og0ve1b.c struct og0ve1b { · line 111
Quoted 1 line
drivers/media/i2c/og0ve1b.c +1
-0+const struct og0ve1b_sensor_data *sensor;
Well, the identifier name is confusing to me, it is not "sensor", it's "sensor data" or just "data", no?
Quoted 13 lines
drivers/media/i2c/og0ve1b.c +1
-0};static const struct cci_reg_sequence og0ve1b_640x480_120fps_mode[] = {@@ -254,6 +264,7 @@ static const struct og0ve1b_mode supported_modes[] = { .hts = 792, .vts = 568, .bpp = 8, + .code = MEDIA_BUS_FMT_Y8_1X8, .reg_list = { .regs = og0ve1b_640x480_120fps_mode, .num_regs = ARRAY_SIZE(og0ve1b_640x480_120fps_mode),@@ -261,23 +272,39 @@ static const struct og0ve1b_mode supported_modes[] = { },
drivers/media/i2c/og0ve1b.c static const struct og0ve1b_mode supported_modes[] = { · line 282
Quoted 10 lines
drivers/media/i2c/og0ve1b.c +8
-0}; +static const struct og0ve1b_sensor_data og0ve1b_data = { + .chip_id =OG0VE1B_CHIP_ID , + .mclk_freq =OG0VE1B_MCLK_FREQ_24MHZ , + .test_pattern_reg =OG0VE1B_REG_PRE_ISP , + .link_freq_menu = og0ve1b_link_freq_menu, + .num_link_freqs =ARRAY_SIZE (og0ve1b_link_freq_menu), + .modes = supported_modes, + .num_modes =ARRAY_SIZE (supported_modes),
Please use tab symbols or spaces before '=' sign consistently on all lines.
Quoted 11 lines
drivers/media/i2c/og0ve1b.c +8
-1+}; +static int og0ve1b_enable_test_pattern (struct og0ve1b *og0ve1b,u32 pattern) { -u64 val = og0ve1b->pre_isp; +u32 reg = og0ve1b->sensor->test_pattern_reg; +u64 val; +int ret; + + ret =cci_read (og0ve1b->regmap, reg, &val,NULL ); +if (ret)
drivers/media/i2c/og0ve1b.c static const struct og0ve1b_mode supported_modes[] = { · line 301
Quoted 10 lines
drivers/media/i2c/og0ve1b.c +2
-1+return ret;if (pattern) val |=OG0VE1B_TEST_PATTERN_ENABLE ;else val &= ~OG0VE1B_TEST_PATTERN_ENABLE ; -return cci_write (og0ve1b->regmap,OG0VE1B_REG_PRE_ISP , val,NULL ); +return cci_write (og0ve1b->regmap, reg, val,NULL ); }
So far let's keep the function above unmodified, but call it by pointer stored in the new struct.
Does OG0VA have also just one "Vertical Colour Bars" test pattern mode?
Let me test this v2 for test pattern regression to formally confirm it shortly.
Quoted 23 lines
drivers/media/i2c/og0ve1b.c +3
-2static int og0ve1b_set_ctrl (struct v4l2_ctrl *ctrl) { struct og0ve1b *og0ve1b = container_of(ctrl->handler, struct og0ve1b, ctrl_handler); -const struct og0ve1b_mode *mode = &supported_modes[0 ]; +const struct og0ve1b_mode *mode = &og0ve1b->sensor->modes[0 ];s64 exposure_max;int ret;@@ -333,7 +360,8 @@ static const struct v4l2_ctrl_ops og0ve1b_ctrl_ops = {static int og0ve1b_init_controls (struct og0ve1b *og0ve1b) {struct v4l2_ctrl_handler *ctrl_hdlr = &og0ve1b->ctrl_handler; -const struct og0ve1b_mode *mode = &supported_modes[0 ]; +const struct og0ve1b_mode *mode = &og0ve1b->sensor->modes[0 ]; +const struct og0ve1b_sensor_data *sensor = og0ve1b->sensor;s64 exposure_max, pixel_rate, h_blank, v_blank;struct v4l2_fwnode_device_properties props;struct v4l2_ctrl *ctrl;@@ -343,12 +371,12 @@ static int og0ve1b_init_controls(struct og0ve1b *og0ve1b) ctrl = v4l2_ctrl_new_int_menu(ctrl_hdlr, &og0ve1b_ctrl_ops,
drivers/media/i2c/og0ve1b.c static int og0ve1b_init_controls(struct og0ve1b *og0ve1b) · line 379
Quoted 10 lines
drivers/media/i2c/og0ve1b.c +3
-3V4L2_CID_LINK_FREQ , -ARRAY_SIZE (og0ve1b_link_freq_menu) -1 , - 0, og0ve1b_link_freq_menu); + sensor->num_link_freqs -1 , + 0, sensor->link_freq_menu);if (ctrl) ctrl->flags |=V4L2_CTRL_FLAG_READ_ONLY ; - pixel_rate = og0ve1b_link_freq_menu[0 ] / mode->bpp; + pixel_rate = sensor->link_freq_menu[0 ] / mode->bpp;
Since it becomes more complex, can you please move the calculation to a new inline function, like os05b10_pixel_rate()?
Quoted 77 lines
drivers/media/i2c/og0ve1b.c +15
-9v4l2_ctrl_new_std (ctrl_hdlr, &og0ve1b_ctrl_ops,V4L2_CID_PIXEL_RATE ,0 , pixel_rate,1 , pixel_rate);@@ -407,7 +435,7 @@ static int og0ve1b_init_controls(struct og0ve1b *og0ve1b)static void og0ve1b_update_pad_format (const struct og0ve1b_mode *mode,struct v4l2_mbus_framefmt *fmt) { - fmt->code =MEDIA_BUS_FMT_Y8_1X8 ; + fmt->code = mode->code; fmt->width = mode->width; fmt->height = mode->height; fmt->field =V4L2_FIELD_NONE ;@@ -421,8 +449,8 @@ static int og0ve1b_enable_streams(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, u32 pad, u64 streams_mask) { -const struct og0ve1b_reg_list *reg_list = &supported_modes[0 ].reg_list; struct og0ve1b *og0ve1b = to_og0ve1b(sd); +const struct og0ve1b_reg_list *reg_list = &og0ve1b->sensor->modes[0 ].reg_list;int ret; ret =pm_runtime_resume_and_get (og0ve1b->dev);@@ -484,13 +512,14 @@ static int og0ve1b_set_pad_format(struct v4l2_subdev *sd,struct v4l2_subdev_state *state, struct v4l2_subdev_format *fmt) { + struct og0ve1b *og0ve1b = to_og0ve1b(sd);struct v4l2_mbus_framefmt *format;const struct og0ve1b_mode *mode; format =v4l2_subdev_state_get_format (state,0 ); - mode =v4l2_find_nearest_size (supported_modes, -ARRAY_SIZE (supported_modes), + mode =v4l2_find_nearest_size (og0ve1b->sensor->modes, + og0ve1b->sensor->num_modes, width, height, fmt->format.width, fmt->format.height);@@ -505,10 +534,12 @@ static int og0ve1b_enum_mbus_code(struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state, struct v4l2_subdev_mbus_code_enum *code) { + struct og0ve1b *og0ve1b = to_og0ve1b(sd); +if (code->index >0 )return -EINVAL ; - code->code =MEDIA_BUS_FMT_Y8_1X8 ; + code->code = og0ve1b->sensor->modes[0 ].code;return 0 ; }@@ -517,15 +548,18 @@ static int og0ve1b_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)) + struct og0ve1b *og0ve1b = to_og0ve1b(sd); +const struct og0ve1b_sensor_data *sensor = og0ve1b->sensor; + +if (fse->index >= sensor->num_modes)return -EINVAL ; -if (fse->code !=MEDIA_BUS_FMT_Y8_1X8 ) +if (fse->code != sensor->modes[fse->index].code)return -EINVAL ; - fse->min_width = supported_modes[fse->index].width; + fse->min_width = sensor->modes[fse->index].width; fse->max_width = fse->min_width; - fse->min_height = supported_modes[fse->index].height; + fse->min_height = sensor->modes[fse->index].height; fse->max_height = fse->min_height;return 0 ;
drivers/media/i2c/og0ve1b.c static int og0ve1b_enum_frame_size(struct v4l2_subdev *sd, · line 571
Quoted 4 lines
drivers/media/i2c/og0ve1b.c +1
-0@@ -534,13 +568,14 @@ static int og0ve1b_enum_frame_size(struct v4l2_subdev *sd,static int og0ve1b_init_state (struct v4l2_subdev *sd,struct v4l2_subdev_state *state) { +struct og0ve1b *og0ve1b =to_og0ve1b (sd);
struct og0ve1b_sensor_data *data = to_og0ve1b(sd)->sensor; // ->data anticipated
Quoted 68 lines
drivers/media/i2c/og0ve1b.c +13
-15struct v4l2_subdev_format fmt = { .which =V4L2_SUBDEV_FORMAT_TRY , .pad =0 , .format = { - .code =MEDIA_BUS_FMT_Y8_1X8 , - .width = supported_modes[0 ].width, - .height = supported_modes[0 ].height, + .code = og0ve1b->sensor->modes[0 ].code, + .width = og0ve1b->sensor->modes[0 ].width, + .height = og0ve1b->sensor->modes[0 ].height, }, };@@ -586,18 +621,13 @@ static int og0ve1b_identify_sensor(struct og0ve1b *og0ve1b)return ret; } -if (val !=OG0VE1B_CHIP_ID ) { -dev_err (og0ve1b->dev,"chip id mismatch: %x!=%llx\n" , -OG0VE1B_CHIP_ID , val); +if (val != og0ve1b->sensor->chip_id) { +dev_err (og0ve1b->dev,"chip id mismatch: %llx!=%llx\n" , + og0ve1b->sensor->chip_id, val);return -ENODEV ; } - ret =cci_read (og0ve1b->regmap,OG0VE1B_REG_PRE_ISP , - &og0ve1b->pre_isp,NULL ); -if (ret) -dev_err (og0ve1b->dev,"failed to read pre_isp: %d\n" , ret); - -return ret; +return 0 ; }static int og0ve1b_check_hwcfg (struct og0ve1b *og0ve1b)@@ -624,8 +654,8 @@ static int og0ve1b_check_hwcfg(struct og0ve1b *og0ve1b) ret =v4l2_link_freq_to_bitmap (og0ve1b->dev, bus_cfg.link_frequencies, bus_cfg.nr_of_link_frequencies, - og0ve1b_link_freq_menu, -ARRAY_SIZE (og0ve1b_link_freq_menu), + og0ve1b->sensor->link_freq_menu, + og0ve1b->sensor->num_link_freqs, &freq_bitmap);v4l2_fwnode_endpoint_free (&bus_cfg);@@ -686,6 +716,9 @@ static int og0ve1b_probe(struct i2c_client *client)return -ENOMEM ; og0ve1b->dev = &client->dev; + og0ve1b->sensor =i2c_get_match_data (client); +if (!og0ve1b->sensor) +return -ENODEV ;v4l2_i2c_subdev_init (&og0ve1b->sd, client, &og0ve1b_subdev_ops);@@ -700,7 +733,7 @@ static int og0ve1b_probe(struct i2c_client *client) "failed to get XVCLK clock\n"); freq =clk_get_rate (og0ve1b->xvclk); -if (freq && freq !=OG0VE1B_MCLK_FREQ_24MHZ ) +if (freq && freq != og0ve1b->sensor->mclk_freq)return dev_err_probe (og0ve1b->dev, -EINVAL ,"XVCLK clock frequency %lu is not supported\n" , freq);
drivers/media/i2c/og0ve1b.c static const struct dev_pm_ops og0ve1b_pm_ops = { · line 858
Quoted 8 lines
drivers/media/i2c/og0ve1b.c +1
-1@@ -819,7 +852,7 @@ static const struct dev_pm_ops og0ve1b_pm_ops = { };static const struct of_device_id og0ve1b_of_match[] = { - { .compatible ="ovti,og0ve1b" }, + { .compatible ="ovti,og0ve1b" , .data = &og0ve1b_data }, {/* sentinel */ } };MODULE_DEVICE_TABLE (of, og0ve1b_of_match);
Looks good overall, thank you.
Signature · 2 lines
Best wishes, Vladimir
Re: [PATCH v2 2/3] media: i2c: og0ve1b: Introduce per-sensor data structure
Hi Vladimir,
Quoted 28 lines · Vladimir Zapolskiy
Hi Wenmeng.
Quoted 17 lines · Wenmeng Liu
In preparation for supporting further OmniVision sensors that share most of this driver, move the sensor-specific parameters (chip id, MCLK frequency, test pattern register, link frequency menu and the list of supported modes) into a new struct
og0ve1b_sensor_data, selected throughi2c_get_match_data()at probe time.Signed-off-by Wenmeng Liu <[email protected]>---
drivers/media/i2c/og0ve1b.c| 101 ++++++++++++++++++++++++++++
+---------------1 file changed, 67 insertions(+), 34 deletions(-)drivers/media/i2c/og0ve1b.c +0
-0@@ -66,10 +66,21 @@ struct og0ve1b_mode {Quoted 4 lines
u32 hts; /* Horizontal timing size */ u32 vts; /* Default vertical timing size */ u32 bpp; /* Bits per pixel */
+ u32 code; /*MEDIA_BUS_FMTcode */In this particular case of grayscale only sensors there is no need for both bpp and media bus format code, since there is a natural one-to-one mapping.
Quoted 3 lines
I'm fine with "code" just replacing "bpp", and in
og0ve1b_init_controls()simply replace "bpp" with "(code ==MEDIA_BUS_FMT_Y8_1X8? 8 : 10)".
ACK.
Quoted 24 lines
Quoted 16 lines
const struct
og0ve1b_reg_listreg_list; /* Sensor register setting */ };drivers/media/i2c/og0ve1b.c +10
-0+struct og0ve1b_sensor_data { + u64 chip_id; + unsigned long mclk_freq; + u32 test_pattern_reg; + const s64 *link_freq_menu; + int num_link_freqs; + const struct og0ve1b_mode *modes; + int num_modes; +}; +static const char * const og0ve1b_test_pattern_menu[] = { "Disabled",
"Vertical Colour Bars",drivers/media/i2c/og0ve1b.c struct og0ve1b { · line 100
Quoted 4 lines
drivers/media/i2c/og0ve1b.c +0
-2@@ -97,8 +108,7 @@ struct og0ve1b { struct v4l2_ctrl *exposure; struct v4l2_ctrl_handler ctrl_handler; - /* Saved register value */ - u64 pre_isp;I'm afraid this will break test pattern on og0ve1b, unfortunately it should be kept as is for now.
Quoted 3 lines
The register is used for something else, and IIRC even
cci_update_bits()API does not work expectedly, it certainly should be read once and written later.
Will keep pre_isp code for og0ve1b.
Quoted 9 lines
Hence it leaves an option to keep
og0ve1b_enable_test_pattern()and then introduce in 3/3 a newog0va1b_enable_test_pattern()function, the selection will be done in runtime similarly to other og0ve/og0va branches.drivers/media/i2c/og0ve1b.c struct og0ve1b { · line 111
Quoted 1 line
drivers/media/i2c/og0ve1b.c +1
-0+ const struct og0ve1b_sensor_data *sensor;Well, the identifier name is confusing to me, it is not "sensor", it's "sensor data" or just "data", no?
ACK.
Quoted 17 lines
Quoted 17 lines
drivers/media/i2c/og0ve1b.c +1
-0}; static const struct cci_reg_sequence og0ve1b_640x480_120fps_mode[] = {@@ -254,6 +264,7 @@ static const struct og0ve1b_mode supported_modes[] = { .hts = 792, .vts = 568, .bpp = 8, + .code = MEDIA_BUS_FMT_Y8_1X8, .reg_list = { .regs = og0ve1b_640x480_120fps_mode,.num_regs =
ARRAY_SIZE(og0ve1b_640x480_120fps_mode),drivers/media/i2c/og0ve1b.c +2
-0@@ -261,23 +272,39 @@ static const struct og0ve1b_mode supported_modes[] = { }, }; +static const struct og0ve1b_sensor_data og0ve1b_data = { + .chip_id = OG0VE1B_CHIP_ID,
Quoted 9 lines
drivers/media/i2c/og0ve1b.c static const struct og0ve1b_mode supported_modes[] = { · line 282
Quoted 6 lines
drivers/media/i2c/og0ve1b.c +6
-0+ .mclk_freq = OG0VE1B_MCLK_FREQ_24MHZ, + .test_pattern_reg = OG0VE1B_REG_PRE_ISP, + .link_freq_menu = og0ve1b_link_freq_menu, + .num_link_freqs = ARRAY_SIZE(og0ve1b_link_freq_menu), + .modes = supported_modes, + .num_modes = ARRAY_SIZE(supported_modes),Please use tab symbols or spaces before '=' sign consistently on all lines.
ACK.
Quoted 23 lines
Quoted 14 lines
drivers/media/i2c/og0ve1b.c +9
-1+}; + static int og0ve1b_enable_test_pattern(struct og0ve1b *og0ve1b, u32 pattern) { - u64 val = og0ve1b->pre_isp; + u32 reg = og0ve1b->sensor->test_pattern_reg; + u64 val; + int ret; + + ret = cci_read(og0ve1b->regmap, reg, &val, NULL); + if (ret) + return ret; if (pattern) val |= OG0VE1B_TEST_PATTERN_ENABLE;Quoted 5 lines
else
val &= ~OG0VE1B_TEST_PATTERN_ENABLE;
- returncci_write(og0ve1b->regmap, OG0VE1B_REG_PRE_ISP, val, NULL); + returncci_write(og0ve1b->regmap, reg, val, NULL);
}So far let's keep the function above unmodified, but call it by pointer stored in the new struct.
Quoted 4 lines
Does OG0VA have also just one "Vertical Colour Bars" test pattern mode?
Let me test this v2 for test pattern regression to formally confirm it shortly.
For og0va1b, tpg has 4 types:
"Standard Color Bar",
"Top-Bottom Darker Color Bar",
"Right-Left Darker Color Bar",
"Bottom-Top Darker Color Bar",
will fix it in next version.
Quoted 26 lines
Quoted 26 lines
static int
og0ve1b_set_ctrl(struct v4l2_ctrl *ctrl)
{
struct og0ve1b *og0ve1b =container_of(ctrl->handler, struct og0ve1b, ctrl_handler);
- const structog0ve1b_mode*mode = &supported_modes[0];
+ const structog0ve1b_mode*mode = &og0ve1b->sensor->modes[0]; s64exposure_max;
int ret;drivers/media/i2c/og0ve1b.c +2
-1@@ -333,7 +360,8 @@ static const struct v4l2_ctrl_ops og0ve1b_ctrl_ops = { static int og0ve1b_init_controls(struct og0ve1b *og0ve1b) { struct v4l2_ctrl_handler *ctrl_hdlr = &og0ve1b->ctrl_handler; - const struct og0ve1b_mode *mode = &supported_modes[0]; + const struct og0ve1b_mode *mode = &og0ve1b->sensor->modes[0]; + const struct og0ve1b_sensor_data *sensor = og0ve1b->sensor; s64 exposure_max, pixel_rate, h_blank, v_blank; struct v4l2_fwnode_device_properties props;struct
v4l2_ctrl*ctrl;drivers/media/i2c/og0ve1b.c +1
-2@@ -343,12 +371,12 @@ static int og0ve1b_init_controls(struct og0ve1b *og0ve1b) ctrl = v4l2_ctrl_new_int_menu(ctrl_hdlr, &og0ve1b_ctrl_ops, V4L2_CID_LINK_FREQ, - ARRAY_SIZE(og0ve1b_link_freq_menu) - 1, - 0, og0ve1b_link_freq_menu); + sensor->num_link_freqs - 1,
Quoted 9 lines
drivers/media/i2c/og0ve1b.c static int og0ve1b_init_controls(struct og0ve1b *og0ve1b) · line 379
Quoted 5 lines
drivers/media/i2c/og0ve1b.c +2
-1+ 0, sensor->link_freq_menu); if (ctrl) ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; - pixel_rate = og0ve1b_link_freq_menu[0] / mode->bpp; + pixel_rate = sensor->link_freq_menu[0] / mode->bpp;Since it becomes more complex, can you please move the calculation to a new inline function, like
os05b10_pixel_rate()?
ACK.
Quoted 74 lines
Quoted 74 lines
drivers/media/i2c/og0ve1b.c +1
-1v4l2_ctrl_new_std(ctrl_hdlr, &og0ve1b_ctrl_ops, V4L2_CID_PIXEL_RATE, 0, pixel_rate, 1, pixel_rate);@@ -407,7 +435,7 @@ static int og0ve1b_init_controls(struct og0ve1b *og0ve1b) static void og0ve1b_update_pad_format(const struct og0ve1b_mode *mode, struct v4l2_mbus_framefmt *fmt) { - fmt->code = MEDIA_BUS_FMT_Y8_1X8; + fmt->code = mode->code; fmt->width = mode->width; fmt->height = mode->height;
fmt->field=V4L2_FIELD_NONE;drivers/media/i2c/og0ve1b.c +1
-1@@ -421,8 +449,8 @@ static int og0ve1b_enable_streams(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, u32 pad, u64 streams_mask) { - const struct og0ve1b_reg_list *reg_list = &supported_modes[0 ].reg_list; struct og0ve1b *og0ve1b = to_og0ve1b(sd); + const struct og0ve1b_reg_list *reg_list = &og0ve1b->sensor- >modes[0].reg_list;int ret;
ret =pm_runtime_resume_and_get(og0ve1b->dev);drivers/media/i2c/og0ve1b.c +13
-7@@ -484,13 +512,14 @@ static int og0ve1b_set_pad_format(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, struct v4l2_subdev_format *fmt) { + struct og0ve1b *og0ve1b = to_og0ve1b(sd); struct v4l2_mbus_framefmt *format; const struct og0ve1b_mode *mode; format = v4l2_subdev_state_get_format(state, 0); - mode = v4l2_find_nearest_size(supported_modes, - ARRAY_SIZE(supported_modes), + mode = v4l2_find_nearest_size(og0ve1b->sensor->modes, + og0ve1b->sensor->num_modes, width, height, fmt->format.width, fmt->format.height);@@ -505,10 +534,12 @@ static int og0ve1b_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_mbus_code_enum *code) { + struct og0ve1b *og0ve1b = to_og0ve1b(sd); + if (code->index > 0) return -EINVAL; - code->code = MEDIA_BUS_FMT_Y8_1X8; + code->code = og0ve1b->sensor->modes[0].code; return 0; }@@ -517,15 +548,18 @@ static int og0ve1b_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)) + struct og0ve1b *og0ve1b = to_og0ve1b(sd); + const struct og0ve1b_sensor_data *sensor = og0ve1b->sensor; + + if (fse->index >= sensor->num_modes) return -EINVAL; - if (fse->code != MEDIA_BUS_FMT_Y8_1X8) + if (fse->code != sensor->modes[fse->index].code) return -EINVAL; - fse->min_width = supported_modes[fse->index].width; + fse->min_width = sensor->modes[fse->index].width; fse->max_width = fse->min_width; - fse->min_height = supported_modes[fse->index].height; + fse->min_height = sensor->modes[fse->index].height; fse->max_height = fse->min_height; return 0;
Quoted 9 lines
drivers/media/i2c/og0ve1b.c static int og0ve1b_enum_frame_size(struct · line 572
Quoted 6 lines
drivers/media/i2c/og0ve1b.c +1
-0@@ -534,13 +568,14 @@ static int og0ve1b_enum_frame_size(structv4l2_subdev *sd, static int og0ve1b_init_state(struct v4l2_subdev *sd, struct v4l2_subdev_state *state) { + struct og0ve1b *og0ve1b = to_og0ve1b(sd);struct
og0ve1b_sensor_data*data = to_og0ve1b(sd)->sensor; // ->data anticipated
ACK.
Quoted 62 lines
Quoted 62 lines
drivers/media/i2c/og0ve1b.c +13
-15struct v4l2_subdev_format fmt = { .which = V4L2_SUBDEV_FORMAT_TRY, .pad = 0, .format = { - .code = MEDIA_BUS_FMT_Y8_1X8, - .width = supported_modes[0].width, - .height = supported_modes[0].height, + .code = og0ve1b->sensor->modes[0].code, + .width = og0ve1b->sensor->modes[0].width, + .height = og0ve1b->sensor->modes[0].height, }, };@@ -586,18 +621,13 @@ static int og0ve1b_identify_sensor(struct og0ve1b *og0ve1b) return ret; } - if (val != OG0VE1B_CHIP_ID) { - dev_err(og0ve1b->dev, "chip id mismatch: %x!=%llx\n", - OG0VE1B_CHIP_ID, val); + if (val != og0ve1b->sensor->chip_id) { + dev_err(og0ve1b->dev, "chip id mismatch: %llx!=%llx\n", + og0ve1b->sensor->chip_id, val); return -ENODEV; } - ret = cci_read(og0ve1b->regmap, OG0VE1B_REG_PRE_ISP, - &og0ve1b->pre_isp, NULL); - if (ret) - dev_err(og0ve1b->dev, "failed to read pre_isp: %d\n", ret); - - return ret; + return 0; } static int og0ve1b_check_hwcfg(struct og0ve1b *og0ve1b)@@ -624,8 +654,8 @@ static int og0ve1b_check_hwcfg(struct og0ve1b *og0ve1b) ret = v4l2_link_freq_to_bitmap(og0ve1b->dev, bus_cfg.link_frequencies, bus_cfg.nr_of_link_frequencies, - og0ve1b_link_freq_menu, - ARRAY_SIZE(og0ve1b_link_freq_menu), + og0ve1b->sensor->link_freq_menu, + og0ve1b->sensor->num_link_freqs, &freq_bitmap); v4l2_fwnode_endpoint_free(&bus_cfg);@@ -686,6 +716,9 @@ static int og0ve1b_probe(struct i2c_client *client) return -ENOMEM; og0ve1b->dev = &client->dev; + og0ve1b->sensor = i2c_get_match_data(client); + if (!og0ve1b->sensor) + return -ENODEV; v4l2_i2c_subdev_init(&og0ve1b->sd, client, &og0ve1b_subdev_ops);@@ -700,7 +733,7 @@ static int og0ve1b_probe(struct i2c_client *client) "failed to get XVCLK clock\n"); freq = clk_get_rate(og0ve1b->xvclk); - if (freq && freq != OG0VE1B_MCLK_FREQ_24MHZ) + if (freq && freq != og0ve1b->sensor->mclk_freq) return dev_err_probe(og0ve1b->dev, -EINVAL, "XVCLK clock frequency %lu is not supported\n", freq);@@ -819,7 +852,7 @@ static const struct dev_pm_ops og0ve1b_pm_ops = { }; static const struct of_device_id og0ve1b_of_match[] = {
Quoted 9 lines
drivers/media/i2c/og0ve1b.c static const struct dev_pm_ops og0ve1b_pm_ops = {
Quoted 6 lines
drivers/media/i2c/og0ve1b.c +1
-1- { .compatible = "ovti,og0ve1b" }, + { .compatible = "ovti,og0ve1b", .data = &og0ve1b_data }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, og0ve1b_of_match);Looks good overall, thank you.
Thanks,
Wenmeng
Re: [PATCH v2 2/3] media: i2c: og0ve1b: Introduce per-sensor data structure
In reply to Wenmeng LiuQuoted 225 lines · Wenmeng Liu
In preparation for supporting further OmniVision sensors that share most of this driver, move the sensor-specific parameters (chip id, MCLK frequency, test pattern register, link frequency menu and the list of supported modes) into a new struct
og0ve1b_sensor_data, selected throughi2c_get_match_data()at probe time.Signed-off-by Wenmeng Liu <[email protected]>--- drivers/media/i2c/og0ve1b.c | 101 +++++++++++++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 34 deletions(-)drivers/media/i2c/og0ve1b.c +59
-24@@ -66,10 +66,21 @@ struct og0ve1b_mode {u32 hts;/* Horizontal timing size */ u32 vts;/* Default vertical timing size */ u32 bpp;/* Bits per pixel */ +u32 code;/* MEDIA_BUS_FMT code */ const struct og0ve1b_reg_list reg_list;/* Sensor register setting */ }; +struct og0ve1b_sensor_data { +u64 chip_id; +unsigned long mclk_freq; +u32 test_pattern_reg; +const s64 *link_freq_menu; +int num_link_freqs; +const struct og0ve1b_mode *modes; +int num_modes; +}; +static const char *const og0ve1b_test_pattern_menu[] = {"Disabled" ,"Vertical Colour Bars" ,@@ -97,8 +108,7 @@ struct og0ve1b {struct v4l2_ctrl *exposure;struct v4l2_ctrl_handler ctrl_handler; -/* Saved register value */ -u64 pre_isp; +const struct og0ve1b_sensor_data *sensor; };static const struct cci_reg_sequence og0ve1b_640x480_120fps_mode[] = {@@ -254,6 +264,7 @@ static const struct og0ve1b_mode supported_modes[] = { .hts = 792, .vts = 568, .bpp = 8, + .code = MEDIA_BUS_FMT_Y8_1X8, .reg_list = { .regs = og0ve1b_640x480_120fps_mode, .num_regs = ARRAY_SIZE(og0ve1b_640x480_120fps_mode),@@ -261,23 +272,39 @@ static const struct og0ve1b_mode supported_modes[] = { }, }; +static const struct og0ve1b_sensor_data og0ve1b_data = { + .chip_id =OG0VE1B_CHIP_ID , + .mclk_freq =OG0VE1B_MCLK_FREQ_24MHZ , + .test_pattern_reg =OG0VE1B_REG_PRE_ISP , + .link_freq_menu = og0ve1b_link_freq_menu, + .num_link_freqs =ARRAY_SIZE (og0ve1b_link_freq_menu), + .modes = supported_modes, + .num_modes =ARRAY_SIZE (supported_modes), +}; +static int og0ve1b_enable_test_pattern (struct og0ve1b *og0ve1b,u32 pattern) { -u64 val = og0ve1b->pre_isp; +u32 reg = og0ve1b->sensor->test_pattern_reg; +u64 val; +int ret; + + ret =cci_read (og0ve1b->regmap, reg, &val,NULL ); +if (ret) +return ret;if (pattern) val |=OG0VE1B_TEST_PATTERN_ENABLE ;else val &= ~OG0VE1B_TEST_PATTERN_ENABLE ; -return cci_write (og0ve1b->regmap,OG0VE1B_REG_PRE_ISP , val,NULL ); +return cci_write (og0ve1b->regmap, reg, val,NULL ); }static int og0ve1b_set_ctrl (struct v4l2_ctrl *ctrl) { struct og0ve1b *og0ve1b = container_of(ctrl->handler, struct og0ve1b, ctrl_handler); -const struct og0ve1b_mode *mode = &supported_modes[0 ]; +const struct og0ve1b_mode *mode = &og0ve1b->sensor->modes[0 ];s64 exposure_max;int ret;@@ -333,7 +360,8 @@ static const struct v4l2_ctrl_ops og0ve1b_ctrl_ops = {static int og0ve1b_init_controls (struct og0ve1b *og0ve1b) {struct v4l2_ctrl_handler *ctrl_hdlr = &og0ve1b->ctrl_handler; -const struct og0ve1b_mode *mode = &supported_modes[0 ]; +const struct og0ve1b_mode *mode = &og0ve1b->sensor->modes[0 ]; +const struct og0ve1b_sensor_data *sensor = og0ve1b->sensor;s64 exposure_max, pixel_rate, h_blank, v_blank;struct v4l2_fwnode_device_properties props;struct v4l2_ctrl *ctrl;@@ -343,12 +371,12 @@ static int og0ve1b_init_controls(struct og0ve1b *og0ve1b) ctrl =v4l2_ctrl_new_int_menu (ctrl_hdlr, &og0ve1b_ctrl_ops,V4L2_CID_LINK_FREQ , -ARRAY_SIZE (og0ve1b_link_freq_menu) -1 , -0 , og0ve1b_link_freq_menu); + sensor->num_link_freqs -1 , +0 , sensor->link_freq_menu);if (ctrl) ctrl->flags |=V4L2_CTRL_FLAG_READ_ONLY ; - pixel_rate = og0ve1b_link_freq_menu[0 ] / mode->bpp; + pixel_rate = sensor->link_freq_menu[0 ] / mode->bpp;v4l2_ctrl_new_std (ctrl_hdlr, &og0ve1b_ctrl_ops,V4L2_CID_PIXEL_RATE ,0 , pixel_rate,1 , pixel_rate);@@ -407,7 +435,7 @@ static int og0ve1b_init_controls(struct og0ve1b *og0ve1b)static void og0ve1b_update_pad_format (const struct og0ve1b_mode *mode,struct v4l2_mbus_framefmt *fmt) { - fmt->code =MEDIA_BUS_FMT_Y8_1X8 ; + fmt->code = mode->code; fmt->width = mode->width; fmt->height = mode->height; fmt->field =V4L2_FIELD_NONE ;@@ -421,8 +449,8 @@ static int og0ve1b_enable_streams(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, u32 pad, u64 streams_mask) { -const struct og0ve1b_reg_list *reg_list = &supported_modes[0 ].reg_list; struct og0ve1b *og0ve1b = to_og0ve1b(sd); +const struct og0ve1b_reg_list *reg_list = &og0ve1b->sensor->modes[0 ].reg_list;int ret; ret =pm_runtime_resume_and_get (og0ve1b->dev);@@ -484,13 +512,14 @@ static int og0ve1b_set_pad_format(struct v4l2_subdev *sd,struct v4l2_subdev_state *state, struct v4l2_subdev_format *fmt) { + struct og0ve1b *og0ve1b = to_og0ve1b(sd);struct v4l2_mbus_framefmt *format;const struct og0ve1b_mode *mode; format =v4l2_subdev_state_get_format (state,0 ); - mode =v4l2_find_nearest_size (supported_modes, -ARRAY_SIZE (supported_modes), + mode =v4l2_find_nearest_size (og0ve1b->sensor->modes, + og0ve1b->sensor->num_modes, width, height, fmt->format.width, fmt->format.height);@@ -505,10 +534,12 @@ static int og0ve1b_enum_mbus_code(struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state, struct v4l2_subdev_mbus_code_enum *code) { + struct og0ve1b *og0ve1b = to_og0ve1b(sd); +if (code->index >0 )return -EINVAL ; - code->code =MEDIA_BUS_FMT_Y8_1X8 ; + code->code = og0ve1b->sensor->modes[0 ].code;return 0 ; }@@ -517,15 +548,18 @@ static int og0ve1b_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)) + struct og0ve1b *og0ve1b = to_og0ve1b(sd); +const struct og0ve1b_sensor_data *sensor = og0ve1b->sensor; + +if (fse->index >= sensor->num_modes)return -EINVAL ; -if (fse->code !=MEDIA_BUS_FMT_Y8_1X8 ) +if (fse->code != sensor->modes[fse->index].code)return -EINVAL ; - fse->min_width = supported_modes[fse->index].width; + fse->min_width = sensor->modes[fse->index].width; fse->max_width = fse->min_width; - fse->min_height = supported_modes[fse->index].height; + fse->min_height = sensor->modes[fse->index].height; fse->max_height = fse->min_height;return 0 ;@@ -534,13 +568,14 @@ static int og0ve1b_enum_frame_size(struct v4l2_subdev *sd,static int og0ve1b_init_state (struct v4l2_subdev *sd,struct v4l2_subdev_state *state) { +struct og0ve1b *og0ve1b =to_og0ve1b (sd);struct v4l2_subdev_format fmt = { .which =V4L2_SUBDEV_FORMAT_TRY , .pad =0 , .format = { - .code =MEDIA_BUS_FMT_Y8_1X8 , - .width = supported_modes[0 ].width, - .height = supported_modes[0 ].height, + .code = og0ve1b->sensor->modes[0 ].code, + .width = og0ve1b->sensor->modes[0 ].width, + .height = og0ve1b->sensor->modes[0 ].height, }, };@@ -586,18 +621,13 @@ static int og0ve1b_identify_sensor(struct og0ve1b *og0ve1b)return ret; } -if (val !=OG0VE1B_CHIP_ID ) { -dev_err (og0ve1b->dev,"chip id mismatch: %x!=%llx\n" , -OG0VE1B_CHIP_ID , val); +if (val != og0ve1b->sensor->chip_id) { +dev_err (og0ve1b->dev,"chip id mismatch: %llx!=%llx\n" , + og0ve1b->sensor->chip_id, val);
drivers/media/i2c/og0ve1b.c static int og0ve1b_identify_sensor(struct og0ve1b *og0ve1b) · line 630
Quoted 10 lines
drivers/media/i2c/og0ve1b.c +1
-6return -ENODEV ; } - ret =cci_read (og0ve1b->regmap,OG0VE1B_REG_PRE_ISP , - &og0ve1b->pre_isp,NULL ); -if (ret) -dev_err (og0ve1b->dev,"failed to read pre_isp: %d\n" , ret); - -return ret; +return 0 ;
The one thing that is not immediately clear to me is if we get equivalent logic WRT OG0VE1B_REG_PRE_ISP after this change.
Quoted 44 lines
drivers/media/i2c/og0ve1b.c +7
-5}static int og0ve1b_check_hwcfg (struct og0ve1b *og0ve1b)@@ -624,8 +654,8 @@ static int og0ve1b_check_hwcfg(struct og0ve1b *og0ve1b) ret =v4l2_link_freq_to_bitmap (og0ve1b->dev, bus_cfg.link_frequencies, bus_cfg.nr_of_link_frequencies, - og0ve1b_link_freq_menu, -ARRAY_SIZE (og0ve1b_link_freq_menu), + og0ve1b->sensor->link_freq_menu, + og0ve1b->sensor->num_link_freqs, &freq_bitmap);v4l2_fwnode_endpoint_free (&bus_cfg);@@ -686,6 +716,9 @@ static int og0ve1b_probe(struct i2c_client *client)return -ENOMEM ; og0ve1b->dev = &client->dev; + og0ve1b->sensor =i2c_get_match_data (client); +if (!og0ve1b->sensor) +return -ENODEV ;v4l2_i2c_subdev_init (&og0ve1b->sd, client, &og0ve1b_subdev_ops);@@ -700,7 +733,7 @@ static int og0ve1b_probe(struct i2c_client *client) "failed to get XVCLK clock\n"); freq =clk_get_rate (og0ve1b->xvclk); -if (freq && freq !=OG0VE1B_MCLK_FREQ_24MHZ ) +if (freq && freq != og0ve1b->sensor->mclk_freq)return dev_err_probe (og0ve1b->dev, -EINVAL ,"XVCLK clock frequency %lu is not supported\n" , freq);@@ -819,7 +852,7 @@ static const struct dev_pm_ops og0ve1b_pm_ops = { };static const struct of_device_id og0ve1b_of_match[] = { - { .compatible ="ovti,og0ve1b" }, + { .compatible ="ovti,og0ve1b" , .data = &og0ve1b_data }, {/* sentinel */ } };MODULE_DEVICE_TABLE (of, og0ve1b_of_match); --
Quoted 3 lines
2.34.1
Other than that LTGM.
---
bod
Re: [PATCH v2 2/3] media: i2c: og0ve1b: Introduce per-sensor data structure
Hi Bryan,
Quoted 243 lines · Bryan O'Donoghue
Quoted 242 lines · Wenmeng Liu
In preparation for supporting further OmniVision sensors that share most of this driver, move the sensor-specific parameters (chip id, MCLK frequency, test pattern register, link frequency menu and the list of supported modes) into a new struct
og0ve1b_sensor_data, selected throughi2c_get_match_data()at probe time.Signed-off-by Wenmeng Liu <[email protected]>---
drivers/media/i2c/og0ve1b.c| 101 ++++++++++++++++++++++++++++
+---------------1 file changed, 67 insertions(+), 34 deletions(-)drivers/media/i2c/og0ve1b.c +0
-0@@ -66,10 +66,21 @@ struct og0ve1b_mode {u32 hts; /* Horizontal timing size */ u32 vts; /* Default vertical timing size */ u32 bpp; /* Bits per pixel */
+ u32 code; /*MEDIA_BUS_FMTcode */const struct
og0ve1b_reg_listreg_list; /* Sensor register setting */ };drivers/media/i2c/og0ve1b.c +10
-0+struct og0ve1b_sensor_data { + u64 chip_id; + unsigned long mclk_freq; + u32 test_pattern_reg; + const s64 *link_freq_menu; + int num_link_freqs; + const struct og0ve1b_mode *modes; + int num_modes; +}; +static const char * const og0ve1b_test_pattern_menu[] = { "Disabled",
"Vertical Colour Bars",drivers/media/i2c/og0ve1b.c +2
-2@@ -97,8 +108,7 @@ struct og0ve1b { struct v4l2_ctrl *exposure; struct v4l2_ctrl_handler ctrl_handler; - /* Saved register value */ - u64 pre_isp; + const struct og0ve1b_sensor_data *sensor; }; static const struct cci_reg_sequence og0ve1b_640x480_120fps_mode[] = {@@ -254,6 +264,7 @@ static const struct og0ve1b_mode supported_modes[] = { .hts = 792, .vts = 568, .bpp = 8, + .code = MEDIA_BUS_FMT_Y8_1X8, .reg_list = { .regs = og0ve1b_640x480_120fps_mode,.num_regs =
ARRAY_SIZE(og0ve1b_640x480_120fps_mode),drivers/media/i2c/og0ve1b.c +17
-1@@ -261,23 +272,39 @@ static const struct og0ve1b_mode supported_modes[] = { }, }; +static const struct og0ve1b_sensor_data og0ve1b_data = { + .chip_id = OG0VE1B_CHIP_ID, + .mclk_freq = OG0VE1B_MCLK_FREQ_24MHZ, + .test_pattern_reg = OG0VE1B_REG_PRE_ISP, + .link_freq_menu = og0ve1b_link_freq_menu, + .num_link_freqs = ARRAY_SIZE(og0ve1b_link_freq_menu), + .modes = supported_modes, + .num_modes = ARRAY_SIZE(supported_modes), +}; + static int og0ve1b_enable_test_pattern(struct og0ve1b *og0ve1b, u32 pattern) { - u64 val = og0ve1b->pre_isp; + u32 reg = og0ve1b->sensor->test_pattern_reg; + u64 val; + int ret; + + ret = cci_read(og0ve1b->regmap, reg, &val, NULL); + if (ret) + return ret; if (pattern) val |= OG0VE1B_TEST_PATTERN_ENABLE;else
val &= ~OG0VE1B_TEST_PATTERN_ENABLE;- return
cci_write(og0ve1b->regmap, OG0VE1B_REG_PRE_ISP, val, NULL); + returncci_write(og0ve1b->regmap, reg, val, NULL);
}static int
og0ve1b_set_ctrl(struct v4l2_ctrl *ctrl)
{
struct og0ve1b *og0ve1b =container_of(ctrl->handler, struct og0ve1b, ctrl_handler);
- const structog0ve1b_mode*mode = &supported_modes[0];
+ const structog0ve1b_mode*mode = &og0ve1b->sensor->modes[0]; s64exposure_max;
int ret;drivers/media/i2c/og0ve1b.c +2
-1@@ -333,7 +360,8 @@ static const struct v4l2_ctrl_ops og0ve1b_ctrl_ops = { static int og0ve1b_init_controls(struct og0ve1b *og0ve1b) { struct v4l2_ctrl_handler *ctrl_hdlr = &og0ve1b->ctrl_handler; - const struct og0ve1b_mode *mode = &supported_modes[0]; + const struct og0ve1b_mode *mode = &og0ve1b->sensor->modes[0]; + const struct og0ve1b_sensor_data *sensor = og0ve1b->sensor; s64 exposure_max, pixel_rate, h_blank, v_blank; struct v4l2_fwnode_device_properties props;struct
v4l2_ctrl*ctrl;drivers/media/i2c/og0ve1b.c +4
-4@@ -343,12 +371,12 @@ static int og0ve1b_init_controls(struct og0ve1b *og0ve1b) ctrl = v4l2_ctrl_new_int_menu(ctrl_hdlr, &og0ve1b_ctrl_ops, V4L2_CID_LINK_FREQ, - ARRAY_SIZE(og0ve1b_link_freq_menu) - 1, - 0, og0ve1b_link_freq_menu); + sensor->num_link_freqs - 1, + 0, sensor->link_freq_menu); if (ctrl) ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; - pixel_rate = og0ve1b_link_freq_menu[0] / mode->bpp; + pixel_rate = sensor->link_freq_menu[0] / mode->bpp; v4l2_ctrl_new_std(ctrl_hdlr, &og0ve1b_ctrl_ops, V4L2_CID_PIXEL_RATE, 0, pixel_rate, 1, pixel_rate);@@ -407,7 +435,7 @@ static int og0ve1b_init_controls(struct og0ve1b *og0ve1b) static void og0ve1b_update_pad_format(const struct og0ve1b_mode *mode, struct v4l2_mbus_framefmt *fmt) { - fmt->code = MEDIA_BUS_FMT_Y8_1X8; + fmt->code = mode->code; fmt->width = mode->width; fmt->height = mode->height;
fmt->field=V4L2_FIELD_NONE;drivers/media/i2c/og0ve1b.c +1
-1@@ -421,8 +449,8 @@ static int og0ve1b_enable_streams(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, u32 pad, u64 streams_mask) { - const struct og0ve1b_reg_list *reg_list = &supported_modes[0 ].reg_list; struct og0ve1b *og0ve1b = to_og0ve1b(sd); + const struct og0ve1b_reg_list *reg_list = &og0ve1b->sensor- >modes[0].reg_list;int ret;
ret =
pm_runtime_resume_and_get(og0ve1b->dev);drivers/media/i2c/og0ve1b.c +3
-2@@ -484,13 +512,14 @@ static int og0ve1b_set_pad_format(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, struct v4l2_subdev_format *fmt) { + struct og0ve1b *og0ve1b = to_og0ve1b(sd); struct v4l2_mbus_framefmt *format; const struct og0ve1b_mode *mode; format = v4l2_subdev_state_get_format(state, 0); - mode = v4l2_find_nearest_size(supported_modes, - ARRAY_SIZE(supported_modes), + mode = v4l2_find_nearest_size(og0ve1b->sensor->modes, + og0ve1b->sensor->num_modes, width, height, fmt->format.width,
fmt->format.height);drivers/media/i2c/og0ve1b.c +3
-1@@ -505,10 +534,12 @@ static int og0ve1b_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_mbus_code_enum *code) { + struct og0ve1b *og0ve1b = to_og0ve1b(sd); + if (code->index > 0) return -EINVAL; - code->code = MEDIA_BUS_FMT_Y8_1X8; + code->code = og0ve1b->sensor->modes[0].code; return 0;}
drivers/media/i2c/og0ve1b.c +7
-4@@ -517,15 +548,18 @@ static int og0ve1b_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)) + struct og0ve1b *og0ve1b = to_og0ve1b(sd); + const struct og0ve1b_sensor_data *sensor = og0ve1b->sensor; + + if (fse->index >= sensor->num_modes) return -EINVAL; - if (fse->code != MEDIA_BUS_FMT_Y8_1X8) + if (fse->code != sensor->modes[fse->index].code) return -EINVAL; - fse->min_width = supported_modes[fse->index].width; + fse->min_width = sensor->modes[fse->index].width; fse->max_width = fse->min_width; - fse->min_height = supported_modes[fse->index].height; + fse->min_height = sensor->modes[fse->index].height; fse->max_height = fse->min_height;return 0;
drivers/media/i2c/og0ve1b.c +7
-6@@ -534,13 +568,14 @@ static int og0ve1b_enum_frame_size(structv4l2_subdev *sd, static int og0ve1b_init_state(struct v4l2_subdev *sd, struct v4l2_subdev_state *state) { + struct og0ve1b *og0ve1b = to_og0ve1b(sd); struct v4l2_subdev_format fmt = { .which = V4L2_SUBDEV_FORMAT_TRY, .pad = 0, .format = { - .code = MEDIA_BUS_FMT_Y8_1X8, - .width = supported_modes[0].width, - .height = supported_modes[0].height, + .code = og0ve1b->sensor->modes[0].code, + .width = og0ve1b->sensor->modes[0].width, + .height = og0ve1b->sensor->modes[0].height, }, };@@ -586,18 +621,13 @@ static int og0ve1b_identify_sensor(struct og0ve1b *og0ve1b) return ret; } - if (val != OG0VE1B_CHIP_ID) { - dev_err(og0ve1b->dev, "chip id mismatch: %x!=%llx\n", - OG0VE1B_CHIP_ID, val); + if (val != og0ve1b->sensor->chip_id) { + dev_err(og0ve1b->dev, "chip id mismatch: %llx!=%llx\n", + og0ve1b->sensor->chip_id, val); return -ENODEV; }
Quoted 10 lines
drivers/media/i2c/og0ve1b.c static int og0ve1b_identify_sensor(struct og0ve1b *og0ve1b) · line 630
Quoted 7 lines
drivers/media/i2c/og0ve1b.c +1
-6- ret = cci_read(og0ve1b->regmap, OG0VE1B_REG_PRE_ISP, - &og0ve1b->pre_isp, NULL); - if (ret) - dev_err(og0ve1b->dev, "failed to read pre_isp: %d\n", ret); - - return ret; + return 0;The one thing that is not immediately clear to me is if we get equivalent logic WRT
OG0VE1B_REG_PRE_ISPafter this change.
I will kill OG0VE1B_REG_PRE_ISP logic in next version.
Quoted 52 lines
Quoted 49 lines
drivers/media/i2c/og0ve1b.c +0
-0}static int
og0ve1b_check_hwcfg(struct og0ve1b *og0ve1b)drivers/media/i2c/og0ve1b.c +2
-2@@ -624,8 +654,8 @@ static int og0ve1b_check_hwcfg(struct og0ve1b *og0ve1b) ret = v4l2_link_freq_to_bitmap(og0ve1b->dev, bus_cfg.link_frequencies, bus_cfg.nr_of_link_frequencies, - og0ve1b_link_freq_menu, - ARRAY_SIZE(og0ve1b_link_freq_menu), + og0ve1b->sensor->link_freq_menu, + og0ve1b->sensor->num_link_freqs, &freq_bitmap);
v4l2_fwnode_endpoint_free(&bus_cfg);drivers/media/i2c/og0ve1b.c +5
-2@@ -686,6 +716,9 @@ static int og0ve1b_probe(struct i2c_client *client) return -ENOMEM; og0ve1b->dev = &client->dev; + og0ve1b->sensor = i2c_get_match_data(client); + if (!og0ve1b->sensor) + return -ENODEV; v4l2_i2c_subdev_init(&og0ve1b->sd, client, &og0ve1b_subdev_ops);@@ -700,7 +733,7 @@ static int og0ve1b_probe(struct i2c_client *client) "failed to get XVCLK clock\n"); freq = clk_get_rate(og0ve1b->xvclk); - if (freq && freq != OG0VE1B_MCLK_FREQ_24MHZ) + if (freq && freq != og0ve1b->sensor->mclk_freq) return dev_err_probe(og0ve1b->dev, -EINVAL, "XVCLK clock frequency %lu is not supported\n", freq);@@ -819,7 +852,7 @@ static const struct dev_pm_ops og0ve1b_pm_ops = { }; static const struct of_device_id og0ve1b_of_match[] = { - { .compatible = "ovti,og0ve1b" }, + { .compatible = "ovti,og0ve1b", .data = &og0ve1b_data }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, og0ve1b_of_match);Signature · 2 lines
-- 2.34.1Other than that LTGM.
Quoted 2 lines
---
bod
Thanks,
Wenmeng
Re: [PATCH v2 2/3] media: i2c: og0ve1b: Introduce per-sensor data structure
Quoted 5 lines · Wenmeng Liu
Quoted 4 lines
Quoted 1 line
+ return 0;
The one thing that is not immediately clear to me is if we get equivalent logic WRT
OG0VE1B_REG_PRE_ISPafter this change.I will kill
OG0VE1B_REG_PRE_ISPlogic in next version.
Kill, steady on.
Just double check and be sure about it, is all I mean.
---
bod
PATCH v2 3/3 media: i2c: og0ve1b: Add support for OmniVision OG0VA1B
In reply to Wenmeng LiuThe OmniVision OG0VA1B is a monochrome image sensor closely related to the OG0VE1B. It shares the SCCB control interface, power supplies and the single-lane MIPI D-PHY description, and differs in its chip id, the test pattern register, the register programming and the output format (10-bit RAW instead of 8-bit).
Add an og0ve1b_sensor_data entry describing the OG0VA1B together with its 640x480 60fps register sequence.
--- drivers/media/i2c/og0ve1b.c | 234 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 230 insertions(+), 4 deletions(-)
drivers/media/i2c/og0ve1b.c +230 -4
@@ -17,8 +17,12 @@#define OG0VE1B_LINK_FREQ_500MHZ (500 * HZ_PER_MHZ)#define OG0VE1B_MCLK_FREQ_24MHZ (24 * HZ_PER_MHZ) +#define OG0VA1B_LINK_FREQ_480MHZ (480 * HZ_PER_MHZ) +#define OG0VA1B_MCLK_FREQ_19_2MHZ (19200 * HZ_PER_KHZ) +#define OG0VE1B_REG_CHIP_ID CCI_REG24(0x300a)#define OG0VE1B_CHIP_ID 0xc75645 +#define OG0VA1B_CHIP_ID 0xc75641#define OG0VE1B_REG_MODE_SELECT CCI_REG8(0x0100)#define OG0VE1B_MODE_STANDBY 0x00
@@ -45,8 +49,9 @@#define OG0VE1B_REG_VTS CCI_REG16(0x380e)#define OG0VE1B_VTS_MAX 0xffff -/* Test pattern */ +/* Test pattern - OG0VE1B uses 0x5e00, OG0VA1B uses 0x5100 */ #define OG0VE1B_REG_PRE_ISP CCI_REG8(0x5e00) +#define OG0VA1B_REG_TEST_PATTERN CCI_REG8(0x5100)#define OG0VE1B_TEST_PATTERN_ENABLE BIT(7)#define to_og0ve1b (_sd) container_of(_sd, struct og0ve1b, sd)
@@ -55,6 +60,10 @@ static const s64 og0ve1b_link_freq_menu[] = { OG0VE1B_LINK_FREQ_500MHZ, }; +static const s64 og0va1b_link_freq_menu[] = { +OG0VA1B_LINK_FREQ_480MHZ , +}; +struct og0ve1b_reg_list {const struct cci_reg_sequence *regs;unsigned int num_regs;
@@ -72,9 +81,14 @@ struct og0ve1b_mode { };struct og0ve1b_sensor_data { +const char *name;u64 chip_id;unsigned long mclk_freq;u32 test_pattern_reg; +/* Exposure register unit: OG0VE1B 1/16 line (4), OG0VA1B whole lines (0). */ +unsigned int exposure_shift; +/* Pixel rate multiplier: OG0VA1B uses CSI-2 DDR (2), OG0VE1B keeps 1. */ +unsigned int pixel_rate_mul;const s64 *link_freq_menu;int num_link_freqs;const struct og0ve1b_mode *modes;
@@ -272,16 +286,223 @@ static const struct og0ve1b_mode supported_modes[] = { }, }; +static const struct cci_reg_sequence og0va1b_640x480_60fps_mode[] = { + {CCI_REG8 (0x0302 ),0x31 }, + {CCI_REG8 (0x0303 ),0x02 }, + {CCI_REG8 (0x0304 ),0x01 }, + {CCI_REG8 (0x0305 ),0x90 }, + {CCI_REG8 (0x0306 ),0x00 }, + {CCI_REG8 (0x0323 ),0x02 }, + {CCI_REG8 (0x0325 ),0x68 }, + {CCI_REG8 (0x0326 ),0xd8 }, + {CCI_REG8 (0x3006 ),0x0e }, + {CCI_REG8 (0x300d ),0x08 }, + {CCI_REG8 (0x3018 ),0xf0 }, + {CCI_REG8 (0x301c ),0xf0 }, + {CCI_REG8 (0x3020 ),0x20 }, + {CCI_REG8 (0x3040 ),0x0f }, + {CCI_REG8 (0x3022 ),0x01 }, + {CCI_REG8 (0x3107 ),0x40 }, + {CCI_REG8 (0x3216 ),0x01 }, + {CCI_REG8 (0x3217 ),0x00 }, + {CCI_REG8 (0x3218 ),0xc0 }, + {CCI_REG8 (0x3219 ),0x55 }, + {CCI_REG8 (0x3506 ),0x01 }, + {CCI_REG8 (0x3507 ),0x50 }, + {CCI_REG8 (0x3508 ),0x01 }, + {CCI_REG8 (0x3509 ),0x00 }, + {CCI_REG8 (0x350a ),0x01 }, + {CCI_REG8 (0x350b ),0x00 }, + {CCI_REG8 (0x350c ),0x00 }, + {CCI_REG8 (0x3541 ),0x00 }, + {CCI_REG8 (0x3542 ),0x40 }, + {CCI_REG8 (0x3605 ),0x90 }, + {CCI_REG8 (0x3606 ),0x41 }, + {CCI_REG8 (0x3612 ),0x00 }, + {CCI_REG8 (0x3620 ),0x08 }, + {CCI_REG8 (0x3630 ),0x17 }, + {CCI_REG8 (0x3631 ),0x99 }, + {CCI_REG8 (0x3639 ),0x88 }, + {CCI_REG8 (0x3668 ),0x00 }, + {CCI_REG8 (0x3674 ),0x00 }, + {CCI_REG8 (0x3677 ),0x3f }, + {CCI_REG8 (0x368f ),0x06 }, + {CCI_REG8 (0x36a2 ),0x19 }, + {CCI_REG8 (0x36a4 ),0xf1 }, + {CCI_REG8 (0x36a5 ),0x2d }, + {CCI_REG8 (0x3706 ),0x30 }, + {CCI_REG8 (0x370d ),0x72 }, + {CCI_REG8 (0x3713 ),0x86 }, + {CCI_REG8 (0x3715 ),0x03 }, + {CCI_REG8 (0x3716 ),0x00 }, + {CCI_REG8 (0x376d ),0x24 }, + {CCI_REG8 (0x3770 ),0x3a }, + {CCI_REG8 (0x3778 ),0x00 }, + {CCI_REG8 (0x37a8 ),0x03 }, + {CCI_REG8 (0x37a9 ),0x00 }, + {CCI_REG8 (0x37df ),0x7d }, + {CCI_REG8 (0x3800 ),0x00 }, + {CCI_REG8 (0x3801 ),0x00 }, + {CCI_REG8 (0x3802 ),0x00 }, + {CCI_REG8 (0x3803 ),0x00 }, + {CCI_REG8 (0x3804 ),0x02 }, + {CCI_REG8 (0x3805 ),0x8f }, + {CCI_REG8 (0x3806 ),0x01 }, + {CCI_REG8 (0x3807 ),0xef }, + {CCI_REG8 (0x3808 ),0x02 }, + {CCI_REG8 (0x3809 ),0x80 }, + {CCI_REG8 (0x380a ),0x01 }, + {CCI_REG8 (0x380b ),0xe0 }, + {CCI_REG8 (0x380c ),0x01 }, + {CCI_REG8 (0x380d ),0x78 }, + {CCI_REG8 (0x380e ),0x08 }, + {CCI_REG8 (0x380f ),0x30 }, + {CCI_REG8 (0x3810 ),0x00 }, + {CCI_REG8 (0x3811 ),0x08 }, + {CCI_REG8 (0x3812 ),0x00 }, + {CCI_REG8 (0x3813 ),0x08 }, + {CCI_REG8 (0x3814 ),0x11 }, + {CCI_REG8 (0x3815 ),0x11 }, + {CCI_REG8 (0x3816 ),0x00 }, + {CCI_REG8 (0x3817 ),0x01 }, + {CCI_REG8 (0x3818 ),0x00 }, + {CCI_REG8 (0x3819 ),0x05 }, + {CCI_REG8 (0x3820 ),0x40 }, + {CCI_REG8 (0x3821 ),0x04 }, + {CCI_REG8 (0x3823 ),0x00 }, + {CCI_REG8 (0x3826 ),0x00 }, + {CCI_REG8 (0x3827 ),0x00 }, + {CCI_REG8 (0x382b ),0x52 }, + {CCI_REG8 (0x384a ),0xa2 }, + {CCI_REG8 (0x3858 ),0x00 }, + {CCI_REG8 (0x3859 ),0x00 }, + {CCI_REG8 (0x3860 ),0x00 }, + {CCI_REG8 (0x3861 ),0x00 }, + {CCI_REG8 (0x3866 ),0x0c }, + {CCI_REG8 (0x3867 ),0x07 }, + {CCI_REG8 (0x3884 ),0x00 }, + {CCI_REG8 (0x3885 ),0x08 }, + {CCI_REG8 (0x3888 ),0x50 }, + {CCI_REG8 (0x3893 ),0x6c }, + {CCI_REG8 (0x3898 ),0x00 }, + {CCI_REG8 (0x389a ),0x04 }, + {CCI_REG8 (0x389b ),0x01 }, + {CCI_REG8 (0x389c ),0x0b }, + {CCI_REG8 (0x389d ),0xdc }, + {CCI_REG8 (0x38b1 ),0x04 }, + {CCI_REG8 (0x38b2 ),0x00 }, + {CCI_REG8 (0x38b3 ),0x08 }, + {CCI_REG8 (0x38c1 ),0x46 }, + {CCI_REG8 (0x38c9 ),0x02 }, + {CCI_REG8 (0x38d4 ),0x06 }, + {CCI_REG8 (0x38d5 ),0x5a }, + {CCI_REG8 (0x38d6 ),0x08 }, + {CCI_REG8 (0x38d7 ),0x3a }, + {CCI_REG8 (0x391f ),0x00 }, + {CCI_REG8 (0x3920 ),0xaa }, + {CCI_REG8 (0x3921 ),0x00 }, + {CCI_REG8 (0x3922 ),0x00 }, + {CCI_REG8 (0x3923 ),0x00 }, + {CCI_REG8 (0x3924 ),0x00 }, + {CCI_REG8 (0x3925 ),0x00 }, + {CCI_REG8 (0x3926 ),0x00 }, + {CCI_REG8 (0x3927 ),0x00 }, + {CCI_REG8 (0x3928 ),0x10 }, + {CCI_REG8 (0x3929 ),0x01 }, + {CCI_REG8 (0x392a ),0xb4 }, + {CCI_REG8 (0x392b ),0x00 }, + {CCI_REG8 (0x392c ),0x10 }, + {CCI_REG8 (0x392d ),0x01 }, + {CCI_REG8 (0x392e ),0x78 }, + {CCI_REG8 (0x392f ),0x4a }, + {CCI_REG8 (0x391e ),0x01 }, + {CCI_REG8 (0x389f ),0x08 }, + {CCI_REG8 (0x38a0 ),0x00 }, + {CCI_REG8 (0x38a1 ),0x00 }, + {CCI_REG8 (0x3a06 ),0x06 }, + {CCI_REG8 (0x3a07 ),0x78 }, + {CCI_REG8 (0x3a08 ),0x08 }, + {CCI_REG8 (0x3a09 ),0x80 }, + {CCI_REG8 (0x3a52 ),0x00 }, + {CCI_REG8 (0x3a53 ),0x01 }, + {CCI_REG8 (0x3a54 ),0x0c }, + {CCI_REG8 (0x3a55 ),0x04 }, + {CCI_REG8 (0x3a58 ),0x0c }, + {CCI_REG8 (0x3a59 ),0x04 }, + {CCI_REG8 (0x4000 ),0xcf }, + {CCI_REG8 (0x4003 ),0x40 }, + {CCI_REG8 (0x4008 ),0x04 }, + {CCI_REG8 (0x4009 ),0x13 }, + {CCI_REG8 (0x400a ),0x02 }, + {CCI_REG8 (0x400b ),0x34 }, + {CCI_REG8 (0x4010 ),0x71 }, + {CCI_REG8 (0x4042 ),0xc3 }, + {CCI_REG8 (0x4306 ),0x04 }, + {CCI_REG8 (0x4307 ),0x12 }, + {CCI_REG8 (0x4500 ),0x70 }, + {CCI_REG8 (0x4509 ),0x00 }, + {CCI_REG8 (0x450b ),0x83 }, + {CCI_REG8 (0x4604 ),0x68 }, + {CCI_REG8 (0x481b ),0x44 }, + {CCI_REG8 (0x481f ),0x30 }, + {CCI_REG8 (0x4823 ),0x44 }, + {CCI_REG8 (0x4825 ),0x35 }, + {CCI_REG8 (0x4837 ),0x11 }, + {CCI_REG8 (0x4f00 ),0x04 }, + {CCI_REG8 (0x4f10 ),0x04 }, + {CCI_REG8 (0x4f21 ),0x01 }, + {CCI_REG8 (0x4f22 ),0x00 }, + {CCI_REG8 (0x4f23 ),0x54 }, + {CCI_REG8 (0x4f24 ),0x51 }, + {CCI_REG8 (0x4f25 ),0x41 }, + {CCI_REG8 (0x5000 ),0x3f }, + {CCI_REG8 (0x5001 ),0x80 }, + {CCI_REG8 (0x500a ),0x00 }, + {CCI_REG8 (0x5100 ),0x00 }, + {CCI_REG8 (0x5111 ),0x20 }, +}; + +static const struct og0ve1b_mode og0va1b_supported_modes[] = { + { + .width =640 , + .height =480 , + .hts =752 , + .vts =2096 , + .bpp =10 , + .code =MEDIA_BUS_FMT_Y10_1X10 , + .reg_list = { + .regs = og0va1b_640x480_60fps_mode, + .num_regs =ARRAY_SIZE (og0va1b_640x480_60fps_mode), + }, + }, +}; +static const struct og0ve1b_sensor_data og0ve1b_data = { + .name ="og0ve1b" , .chip_id =OG0VE1B_CHIP_ID , .mclk_freq =OG0VE1B_MCLK_FREQ_24MHZ , .test_pattern_reg =OG0VE1B_REG_PRE_ISP , + .exposure_shift =4 , + .pixel_rate_mul =1 , .link_freq_menu = og0ve1b_link_freq_menu, .num_link_freqs =ARRAY_SIZE (og0ve1b_link_freq_menu), .modes = supported_modes, .num_modes =ARRAY_SIZE (supported_modes), }; +static const struct og0ve1b_sensor_data og0va1b_data = { + .name ="og0va1b" , + .chip_id =OG0VA1B_CHIP_ID , + .mclk_freq =OG0VA1B_MCLK_FREQ_19_2MHZ , + .test_pattern_reg =OG0VA1B_REG_TEST_PATTERN , + .exposure_shift =0 , + .pixel_rate_mul =2 , + .link_freq_menu = og0va1b_link_freq_menu, + .num_link_freqs =ARRAY_SIZE (og0va1b_link_freq_menu), + .modes = og0va1b_supported_modes, + .num_modes =ARRAY_SIZE (og0va1b_supported_modes), +}; +static int og0ve1b_enable_test_pattern (struct og0ve1b *og0ve1b,u32 pattern) {u32 reg = og0ve1b->sensor->test_pattern_reg;
@@ -334,7 +555,8 @@ static int og0ve1b_set_ctrl(struct v4l2_ctrl *ctrl)break ;case V4L2_CID_EXPOSURE : ret =cci_write (og0ve1b->regmap,OG0VE1B_REG_EXPOSURE , - ctrl->val <<4 ,NULL ); + ctrl->val << og0ve1b->sensor->exposure_shift, +NULL );break ;case V4L2_CID_VBLANK : ret = cci_write(og0ve1b->regmap, OG0VE1B_REG_VTS,
@@ -376,7 +598,8 @@ static int og0ve1b_init_controls(struct og0ve1b *og0ve1b)if (ctrl) ctrl->flags |=V4L2_CTRL_FLAG_READ_ONLY ; - pixel_rate = sensor->link_freq_menu[0 ] / mode->bpp; + pixel_rate = sensor->link_freq_menu[0 ] * sensor->pixel_rate_mul / + mode->bpp;v4l2_ctrl_new_std (ctrl_hdlr, &og0ve1b_ctrl_ops,V4L2_CID_PIXEL_RATE ,0 , pixel_rate,1 , pixel_rate);
@@ -721,6 +944,8 @@ static int og0ve1b_probe(struct i2c_client *client)return -ENODEV ;v4l2_i2c_subdev_init (&og0ve1b->sd, client, &og0ve1b_subdev_ops); +v4l2_i2c_subdev_set_name (&og0ve1b->sd, client, + og0ve1b->sensor->name,NULL ); og0ve1b->regmap =devm_cci_regmap_init_i2c (client,16 );if (IS_ERR (og0ve1b->regmap))
@@ -853,6 +1078,7 @@ static const struct dev_pm_ops og0ve1b_pm_ops = {static const struct of_device_id og0ve1b_of_match[] = { { .compatible ="ovti,og0ve1b" , .data = &og0ve1b_data }, + { .compatible ="ovti,og0va1b" , .data = &og0va1b_data }, {/* sentinel */ } };MODULE_DEVICE_TABLE (of, og0ve1b_of_match);
@@ -870,5 +1096,5 @@ static struct i2c_driver og0ve1b_i2c_driver = {module_i2c_driver (og0ve1b_i2c_driver);MODULE_AUTHOR ("Vladimir Zapolskiy <[email protected]>" ); -MODULE_DESCRIPTION ("OmniVision OG0VE1B sensor driver" ); +MODULE_DESCRIPTION ("OmniVision OG0VE1B/OG0VA1B sensor driver" );MODULE_LICENSE ("GPL" );
Signature · 1 line
2.34.1
Vladimir Zapolskiy
maintainerRe: [PATCH v2 3/3] media: i2c: og0ve1b: Add support for OmniVision OG0VA1B
Quoted 19 lines · Wenmeng Liu
The OmniVision OG0VA1B is a monochrome image sensor closely related to the OG0VE1B. It shares the SCCB control interface, power supplies and the single-lane MIPI D-PHY description, and differs in its chip id, the test pattern register, the register programming and the output format (10-bit RAW instead of 8-bit).
Add an
og0ve1b_sensor_dataentry describing the OG0VA1B together with its 640x480 60fps register sequence.Signed-off-by Wenmeng Liu <[email protected]>--- drivers/media/i2c/og0ve1b.c | 234 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 230 insertions(+), 4 deletions(-)drivers/media/i2c/og0ve1b.c +0
-0
drivers/media/i2c/og0ve1b.c line 25
Quoted 9 lines
drivers/media/i2c/og0ve1b.c +4
-0@@ -17,8 +17,12 @@#define OG0VE1B_LINK_FREQ_500MHZ (500 * HZ_PER_MHZ)#define OG0VE1B_MCLK_FREQ_24MHZ (24 * HZ_PER_MHZ) +#define OG0VA1B_LINK_FREQ_480MHZ (480 * HZ_PER_MHZ) +#define OG0VA1B_MCLK_FREQ_19_2MHZ (19200 * HZ_PER_KHZ) +#define OG0VE1B_REG_CHIP_ID CCI_REG24(0x300a)#define OG0VE1B_CHIP_ID 0xc75645 +#define OG0VA1B_CHIP_ID 0xc75641
Please keep the list alphabetically sorted, also it's fine if "OG0VE1B_REG_CHIP_ID" is reduced to "OG0V_REG_CHIP_ID".
Quoted 236 lines
drivers/media/i2c/og0ve1b.c +202
-1#define OG0VE1B_REG_MODE_SELECT CCI_REG8(0x0100)#define OG0VE1B_MODE_STANDBY 0x00@@ -45,8 +49,9 @@#define OG0VE1B_REG_VTS CCI_REG16(0x380e)#define OG0VE1B_VTS_MAX 0xffff -/* Test pattern */ +/* Test pattern - OG0VE1B uses 0x5e00, OG0VA1B uses 0x5100 */ #define OG0VE1B_REG_PRE_ISP CCI_REG8(0x5e00) +#define OG0VA1B_REG_TEST_PATTERN CCI_REG8(0x5100)#define OG0VE1B_TEST_PATTERN_ENABLE BIT(7)#define to_og0ve1b (_sd) container_of(_sd, struct og0ve1b, sd)@@ -55,6 +60,10 @@ static const s64 og0ve1b_link_freq_menu[] = { OG0VE1B_LINK_FREQ_500MHZ, }; +static const s64 og0va1b_link_freq_menu[] = { +OG0VA1B_LINK_FREQ_480MHZ , +}; +struct og0ve1b_reg_list {const struct cci_reg_sequence *regs;unsigned int num_regs;@@ -72,9 +81,14 @@ struct og0ve1b_mode { };struct og0ve1b_sensor_data { +const char *name;u64 chip_id;unsigned long mclk_freq;u32 test_pattern_reg; +/* Exposure register unit: OG0VE1B 1/16 line (4), OG0VA1B whole lines (0). */ +unsigned int exposure_shift; +/* Pixel rate multiplier: OG0VA1B uses CSI-2 DDR (2), OG0VE1B keeps 1. */ +unsigned int pixel_rate_mul;const s64 *link_freq_menu;int num_link_freqs;const struct og0ve1b_mode *modes;@@ -272,16 +286,223 @@ static const struct og0ve1b_mode supported_modes[] = { }, }; +static const struct cci_reg_sequence og0va1b_640x480_60fps_mode[] = { + {CCI_REG8 (0x0302 ),0x31 }, + {CCI_REG8 (0x0303 ),0x02 }, + {CCI_REG8 (0x0304 ),0x01 }, + {CCI_REG8 (0x0305 ),0x90 }, + {CCI_REG8 (0x0306 ),0x00 }, + {CCI_REG8 (0x0323 ),0x02 }, + {CCI_REG8 (0x0325 ),0x68 }, + {CCI_REG8 (0x0326 ),0xd8 }, + {CCI_REG8 (0x3006 ),0x0e }, + {CCI_REG8 (0x300d ),0x08 }, + {CCI_REG8 (0x3018 ),0xf0 }, + {CCI_REG8 (0x301c ),0xf0 }, + {CCI_REG8 (0x3020 ),0x20 }, + {CCI_REG8 (0x3040 ),0x0f }, + {CCI_REG8 (0x3022 ),0x01 }, + {CCI_REG8 (0x3107 ),0x40 }, + {CCI_REG8 (0x3216 ),0x01 }, + {CCI_REG8 (0x3217 ),0x00 }, + {CCI_REG8 (0x3218 ),0xc0 }, + {CCI_REG8 (0x3219 ),0x55 }, + {CCI_REG8 (0x3506 ),0x01 }, + {CCI_REG8 (0x3507 ),0x50 }, + {CCI_REG8 (0x3508 ),0x01 }, + {CCI_REG8 (0x3509 ),0x00 }, + {CCI_REG8 (0x350a ),0x01 }, + {CCI_REG8 (0x350b ),0x00 }, + {CCI_REG8 (0x350c ),0x00 }, + {CCI_REG8 (0x3541 ),0x00 }, + {CCI_REG8 (0x3542 ),0x40 }, + {CCI_REG8 (0x3605 ),0x90 }, + {CCI_REG8 (0x3606 ),0x41 }, + {CCI_REG8 (0x3612 ),0x00 }, + {CCI_REG8 (0x3620 ),0x08 }, + {CCI_REG8 (0x3630 ),0x17 }, + {CCI_REG8 (0x3631 ),0x99 }, + {CCI_REG8 (0x3639 ),0x88 }, + {CCI_REG8 (0x3668 ),0x00 }, + {CCI_REG8 (0x3674 ),0x00 }, + {CCI_REG8 (0x3677 ),0x3f }, + {CCI_REG8 (0x368f ),0x06 }, + {CCI_REG8 (0x36a2 ),0x19 }, + {CCI_REG8 (0x36a4 ),0xf1 }, + {CCI_REG8 (0x36a5 ),0x2d }, + {CCI_REG8 (0x3706 ),0x30 }, + {CCI_REG8 (0x370d ),0x72 }, + {CCI_REG8 (0x3713 ),0x86 }, + {CCI_REG8 (0x3715 ),0x03 }, + {CCI_REG8 (0x3716 ),0x00 }, + {CCI_REG8 (0x376d ),0x24 }, + {CCI_REG8 (0x3770 ),0x3a }, + {CCI_REG8 (0x3778 ),0x00 }, + {CCI_REG8 (0x37a8 ),0x03 }, + {CCI_REG8 (0x37a9 ),0x00 }, + {CCI_REG8 (0x37df ),0x7d }, + {CCI_REG8 (0x3800 ),0x00 }, + {CCI_REG8 (0x3801 ),0x00 }, + {CCI_REG8 (0x3802 ),0x00 }, + {CCI_REG8 (0x3803 ),0x00 }, + {CCI_REG8 (0x3804 ),0x02 }, + {CCI_REG8 (0x3805 ),0x8f }, + {CCI_REG8 (0x3806 ),0x01 }, + {CCI_REG8 (0x3807 ),0xef }, + {CCI_REG8 (0x3808 ),0x02 }, + {CCI_REG8 (0x3809 ),0x80 }, + {CCI_REG8 (0x380a ),0x01 }, + {CCI_REG8 (0x380b ),0xe0 }, + {CCI_REG8 (0x380c ),0x01 }, + {CCI_REG8 (0x380d ),0x78 }, + {CCI_REG8 (0x380e ),0x08 }, + {CCI_REG8 (0x380f ),0x30 }, + {CCI_REG8 (0x3810 ),0x00 }, + {CCI_REG8 (0x3811 ),0x08 }, + {CCI_REG8 (0x3812 ),0x00 }, + {CCI_REG8 (0x3813 ),0x08 }, + {CCI_REG8 (0x3814 ),0x11 }, + {CCI_REG8 (0x3815 ),0x11 }, + {CCI_REG8 (0x3816 ),0x00 }, + {CCI_REG8 (0x3817 ),0x01 }, + {CCI_REG8 (0x3818 ),0x00 }, + {CCI_REG8 (0x3819 ),0x05 }, + {CCI_REG8 (0x3820 ),0x40 }, + {CCI_REG8 (0x3821 ),0x04 }, + {CCI_REG8 (0x3823 ),0x00 }, + {CCI_REG8 (0x3826 ),0x00 }, + {CCI_REG8 (0x3827 ),0x00 }, + {CCI_REG8 (0x382b ),0x52 }, + {CCI_REG8 (0x384a ),0xa2 }, + {CCI_REG8 (0x3858 ),0x00 }, + {CCI_REG8 (0x3859 ),0x00 }, + {CCI_REG8 (0x3860 ),0x00 }, + {CCI_REG8 (0x3861 ),0x00 }, + {CCI_REG8 (0x3866 ),0x0c }, + {CCI_REG8 (0x3867 ),0x07 }, + {CCI_REG8 (0x3884 ),0x00 }, + {CCI_REG8 (0x3885 ),0x08 }, + {CCI_REG8 (0x3888 ),0x50 }, + {CCI_REG8 (0x3893 ),0x6c }, + {CCI_REG8 (0x3898 ),0x00 }, + {CCI_REG8 (0x389a ),0x04 }, + {CCI_REG8 (0x389b ),0x01 }, + {CCI_REG8 (0x389c ),0x0b }, + {CCI_REG8 (0x389d ),0xdc }, + {CCI_REG8 (0x38b1 ),0x04 }, + {CCI_REG8 (0x38b2 ),0x00 }, + {CCI_REG8 (0x38b3 ),0x08 }, + {CCI_REG8 (0x38c1 ),0x46 }, + {CCI_REG8 (0x38c9 ),0x02 }, + {CCI_REG8 (0x38d4 ),0x06 }, + {CCI_REG8 (0x38d5 ),0x5a }, + {CCI_REG8 (0x38d6 ),0x08 }, + {CCI_REG8 (0x38d7 ),0x3a }, + {CCI_REG8 (0x391f ),0x00 }, + {CCI_REG8 (0x3920 ),0xaa }, + {CCI_REG8 (0x3921 ),0x00 }, + {CCI_REG8 (0x3922 ),0x00 }, + {CCI_REG8 (0x3923 ),0x00 }, + {CCI_REG8 (0x3924 ),0x00 }, + {CCI_REG8 (0x3925 ),0x00 }, + {CCI_REG8 (0x3926 ),0x00 }, + {CCI_REG8 (0x3927 ),0x00 }, + {CCI_REG8 (0x3928 ),0x10 }, + {CCI_REG8 (0x3929 ),0x01 }, + {CCI_REG8 (0x392a ),0xb4 }, + {CCI_REG8 (0x392b ),0x00 }, + {CCI_REG8 (0x392c ),0x10 }, + {CCI_REG8 (0x392d ),0x01 }, + {CCI_REG8 (0x392e ),0x78 }, + {CCI_REG8 (0x392f ),0x4a }, + {CCI_REG8 (0x391e ),0x01 }, + {CCI_REG8 (0x389f ),0x08 }, + {CCI_REG8 (0x38a0 ),0x00 }, + {CCI_REG8 (0x38a1 ),0x00 }, + {CCI_REG8 (0x3a06 ),0x06 }, + {CCI_REG8 (0x3a07 ),0x78 }, + {CCI_REG8 (0x3a08 ),0x08 }, + {CCI_REG8 (0x3a09 ),0x80 }, + {CCI_REG8 (0x3a52 ),0x00 }, + {CCI_REG8 (0x3a53 ),0x01 }, + {CCI_REG8 (0x3a54 ),0x0c }, + {CCI_REG8 (0x3a55 ),0x04 }, + {CCI_REG8 (0x3a58 ),0x0c }, + {CCI_REG8 (0x3a59 ),0x04 }, + {CCI_REG8 (0x4000 ),0xcf }, + {CCI_REG8 (0x4003 ),0x40 }, + {CCI_REG8 (0x4008 ),0x04 }, + {CCI_REG8 (0x4009 ),0x13 }, + {CCI_REG8 (0x400a ),0x02 }, + {CCI_REG8 (0x400b ),0x34 }, + {CCI_REG8 (0x4010 ),0x71 }, + {CCI_REG8 (0x4042 ),0xc3 }, + {CCI_REG8 (0x4306 ),0x04 }, + {CCI_REG8 (0x4307 ),0x12 }, + {CCI_REG8 (0x4500 ),0x70 }, + {CCI_REG8 (0x4509 ),0x00 }, + {CCI_REG8 (0x450b ),0x83 }, + {CCI_REG8 (0x4604 ),0x68 }, + {CCI_REG8 (0x481b ),0x44 }, + {CCI_REG8 (0x481f ),0x30 }, + {CCI_REG8 (0x4823 ),0x44 }, + {CCI_REG8 (0x4825 ),0x35 }, + {CCI_REG8 (0x4837 ),0x11 }, + {CCI_REG8 (0x4f00 ),0x04 }, + {CCI_REG8 (0x4f10 ),0x04 }, + {CCI_REG8 (0x4f21 ),0x01 }, + {CCI_REG8 (0x4f22 ),0x00 }, + {CCI_REG8 (0x4f23 ),0x54 }, + {CCI_REG8 (0x4f24 ),0x51 }, + {CCI_REG8 (0x4f25 ),0x41 }, + {CCI_REG8 (0x5000 ),0x3f }, + {CCI_REG8 (0x5001 ),0x80 }, + {CCI_REG8 (0x500a ),0x00 }, + {CCI_REG8 (0x5100 ),0x00 }, + {CCI_REG8 (0x5111 ),0x20 }, +}; + +static const struct og0ve1b_mode og0va1b_supported_modes[] = { + { + .width =640 , + .height =480 , + .hts =752 , + .vts =2096 , + .bpp =10 , + .code =MEDIA_BUS_FMT_Y10_1X10 , + .reg_list = { + .regs = og0va1b_640x480_60fps_mode, + .num_regs =ARRAY_SIZE (og0va1b_640x480_60fps_mode), + }, + }, +}; +static const struct og0ve1b_sensor_data og0ve1b_data = {
drivers/media/i2c/og0ve1b.c static const struct og0ve1b_mode supported_modes[] = { · line 490
Quoted 10 lines
drivers/media/i2c/og0ve1b.c +3
-0+ .name = "og0ve1b", .chip_id = OG0VE1B_CHIP_ID, .mclk_freq = OG0VE1B_MCLK_FREQ_24MHZ, .test_pattern_reg = OG0VE1B_REG_PRE_ISP, + .exposure_shift = 4, + .pixel_rate_mul = 1, .link_freq_menu = og0ve1b_link_freq_menu, .num_link_freqs = ARRAY_SIZE(og0ve1b_link_freq_menu), .modes = supported_modes, .num_modes = ARRAY_SIZE(supported_modes),
Can you please rename "supported_modes" to "og0ve1b_supported_modes"? Likely it should be done in 2/3 change, but it's up to you.
Quoted 4 lines
drivers/media/i2c/og0ve1b.c +2
-0}; +static const struct og0ve1b_sensor_data og0va1b_data = { + .name ="og0va1b" ,
drivers/media/i2c/og0ve1b.c static const struct og0ve1b_mode supported_modes[] = { · line 504
Quoted 10 lines
drivers/media/i2c/og0ve1b.c +10
-0+ .chip_id = OG0VA1B_CHIP_ID, + .mclk_freq = OG0VA1B_MCLK_FREQ_19_2MHZ, + .test_pattern_reg = OG0VA1B_REG_TEST_PATTERN, + .exposure_shift = 0, + .pixel_rate_mul = 2, + .link_freq_menu = og0va1b_link_freq_menu, + .num_link_freqs = ARRAY_SIZE(og0va1b_link_freq_menu), + .modes = og0va1b_supported_modes, + .num_modes = ARRAY_SIZE(og0va1b_supported_modes), +};
First og0va1b_data, then og0ve1b_data declaration to keep the natural order.
Quoted 43 lines
drivers/media/i2c/og0ve1b.c +8
-2+static int og0ve1b_enable_test_pattern (struct og0ve1b *og0ve1b,u32 pattern) {u32 reg = og0ve1b->sensor->test_pattern_reg;@@ -334,7 +555,8 @@ static int og0ve1b_set_ctrl(struct v4l2_ctrl *ctrl)break ;case V4L2_CID_EXPOSURE : ret =cci_write (og0ve1b->regmap,OG0VE1B_REG_EXPOSURE , - ctrl->val <<4 ,NULL ); + ctrl->val << og0ve1b->sensor->exposure_shift, +NULL );break ;case V4L2_CID_VBLANK : ret = cci_write(og0ve1b->regmap, OG0VE1B_REG_VTS,@@ -376,7 +598,8 @@ static int og0ve1b_init_controls(struct og0ve1b *og0ve1b)if (ctrl) ctrl->flags |=V4L2_CTRL_FLAG_READ_ONLY ; - pixel_rate = sensor->link_freq_menu[0 ] / mode->bpp; + pixel_rate = sensor->link_freq_menu[0 ] * sensor->pixel_rate_mul / + mode->bpp;v4l2_ctrl_new_std (ctrl_hdlr, &og0ve1b_ctrl_ops,V4L2_CID_PIXEL_RATE ,0 , pixel_rate,1 , pixel_rate);@@ -721,6 +944,8 @@ static int og0ve1b_probe(struct i2c_client *client)return -ENODEV ;v4l2_i2c_subdev_init (&og0ve1b->sd, client, &og0ve1b_subdev_ops); +v4l2_i2c_subdev_set_name (&og0ve1b->sd, client, + og0ve1b->sensor->name,NULL ); og0ve1b->regmap =devm_cci_regmap_init_i2c (client,16 );if (IS_ERR (og0ve1b->regmap))@@ -853,6 +1078,7 @@ static const struct dev_pm_ops og0ve1b_pm_ops = {static const struct of_device_id og0ve1b_of_match[] = { { .compatible ="ovti,og0ve1b" , .data = &og0ve1b_data }, + { .compatible ="ovti,og0va1b" , .data = &og0va1b_data }, {/* sentinel */ } };MODULE_DEVICE_TABLE (of, og0ve1b_of_match);
drivers/media/i2c/og0ve1b.c static struct i2c_driver og0ve1b_i2c_driver = { · line 1100
Quoted 6 lines
drivers/media/i2c/og0ve1b.c +1
-1@@ -870,5 +1096,5 @@ static struct i2c_driver og0ve1b_i2c_driver = {module_i2c_driver (og0ve1b_i2c_driver);MODULE_AUTHOR ("Vladimir Zapolskiy <[email protected]>" ); -MODULE_DESCRIPTION ("OmniVision OG0VE1B sensor driver" ); +MODULE_DESCRIPTION ("OmniVision OG0VE1B/OG0VA1B sensor driver" );MODULE_LICENSE ("GPL" );
Looks good, thank you!
Signature · 2 lines
Best wishes, Vladimir
Re: [PATCH v2 3/3] media: i2c: og0ve1b: Add support for OmniVision OG0VA1B
Hi Vladimir,
Quoted 16 lines · Vladimir Zapolskiy
Quoted 15 lines · Wenmeng Liu
The OmniVision OG0VA1B is a monochrome image sensor closely related to the OG0VE1B. It shares the SCCB control interface, power supplies and the single-lane MIPI D-PHY description, and differs in its chip id, the test pattern register, the register programming and the output format (10-bit RAW instead of 8-bit).
Add an
og0ve1b_sensor_dataentry describing the OG0VA1B together with its 640x480 60fps register sequence.Signed-off-by Wenmeng Liu <[email protected]>---
drivers/media/i2c/og0ve1b.c| 234 ++++++++++++++++++++++++++++++++++
+++++++++-1 file changed, 230 insertions(+), 4 deletions(-)
Quoted 17 lines
drivers/media/i2c/og0ve1b.c line 24
Quoted 13 lines
drivers/media/i2c/og0ve1b.c +4
-0@@ -17,8 +17,12 @@ #define OG0VE1B_LINK_FREQ_500MHZ (500 * HZ_PER_MHZ) #define OG0VE1B_MCLK_FREQ_24MHZ (24 * HZ_PER_MHZ) +#define OG0VA1B_LINK_FREQ_480MHZ (480 * HZ_PER_MHZ) +#define OG0VA1B_MCLK_FREQ_19_2MHZ (19200 * HZ_PER_KHZ) + #define OG0VE1B_REG_CHIP_ID CCI_REG24(0x300a) #define OG0VE1B_CHIP_ID 0xc75645 +#define OG0VA1B_CHIP_ID 0xc75641Please keep the list alphabetically sorted, also it's fine if "
OG0VE1B_REG_CHIP_ID" is reduced to "OG0V_REG_CHIP_ID".
ACK.
Quoted 238 lines
Quoted 238 lines
drivers/media/i2c/og0ve1b.c +8
-1#define OG0VE1B_REG_MODE_SELECT CCI_REG8(0x0100) #define OG0VE1B_MODE_STANDBY 0x00@@ -45,8 +49,9 @@ #define OG0VE1B_REG_VTS CCI_REG16(0x380e) #define OG0VE1B_VTS_MAX 0xffff -/* Test pattern */ +/* Test pattern - OG0VE1B uses 0x5e00, OG0VA1B uses 0x5100 */ #define OG0VE1B_REG_PRE_ISP CCI_REG8(0x5e00) +#define OG0VA1B_REG_TEST_PATTERN CCI_REG8(0x5100) #define OG0VE1B_TEST_PATTERN_ENABLE BIT(7) #define to_og0ve1b(_sd) container_of(_sd, struct og0ve1b, sd)@@ -55,6 +60,10 @@ static const s64 og0ve1b_link_freq_menu[] = { OG0VE1B_LINK_FREQ_500MHZ, }; +static const s64 og0va1b_link_freq_menu[] = { + OG0VA1B_LINK_FREQ_480MHZ, +}; + struct og0ve1b_reg_list { const struct cci_reg_sequence *regs; unsigned int num_regs;@@ -72,9 +81,14 @@ struct og0ve1b_mode { }; struct og0ve1b_sensor_data { + const char *name; u64 chip_id; unsigned long mclk_freq; u32 test_pattern_reg; + /* Exposure register unit: OG0VE1B 1/16 line (4), OG0VA1B wholelines (0). */
+ unsigned intexposure_shift;
+ /* Pixel rate multiplier: OG0VA1B uses CSI-2 DDR (2), OG0VE1B keeps 1. */
+ unsigned intpixel_rate_mul;
const s64*link_freq_menu;
intnum_link_freqs;
const structog0ve1b_mode*modes;drivers/media/i2c/og0ve1b.c +193
-0@@ -272,16 +286,223 @@ static const struct og0ve1b_mode supported_modes[] = { }, }; +static const struct cci_reg_sequence og0va1b_640x480_60fps_mode[] = { + { CCI_REG8(0x0302), 0x31 }, + { CCI_REG8(0x0303), 0x02 }, + { CCI_REG8(0x0304), 0x01 }, + { CCI_REG8(0x0305), 0x90 }, + { CCI_REG8(0x0306), 0x00 }, + { CCI_REG8(0x0323), 0x02 }, + { CCI_REG8(0x0325), 0x68 }, + { CCI_REG8(0x0326), 0xd8 }, + { CCI_REG8(0x3006), 0x0e }, + { CCI_REG8(0x300d), 0x08 }, + { CCI_REG8(0x3018), 0xf0 }, + { CCI_REG8(0x301c), 0xf0 }, + { CCI_REG8(0x3020), 0x20 }, + { CCI_REG8(0x3040), 0x0f }, + { CCI_REG8(0x3022), 0x01 }, + { CCI_REG8(0x3107), 0x40 }, + { CCI_REG8(0x3216), 0x01 }, + { CCI_REG8(0x3217), 0x00 }, + { CCI_REG8(0x3218), 0xc0 }, + { CCI_REG8(0x3219), 0x55 }, + { CCI_REG8(0x3506), 0x01 }, + { CCI_REG8(0x3507), 0x50 }, + { CCI_REG8(0x3508), 0x01 }, + { CCI_REG8(0x3509), 0x00 }, + { CCI_REG8(0x350a), 0x01 }, + { CCI_REG8(0x350b), 0x00 }, + { CCI_REG8(0x350c), 0x00 }, + { CCI_REG8(0x3541), 0x00 }, + { CCI_REG8(0x3542), 0x40 }, + { CCI_REG8(0x3605), 0x90 }, + { CCI_REG8(0x3606), 0x41 }, + { CCI_REG8(0x3612), 0x00 }, + { CCI_REG8(0x3620), 0x08 }, + { CCI_REG8(0x3630), 0x17 }, + { CCI_REG8(0x3631), 0x99 }, + { CCI_REG8(0x3639), 0x88 }, + { CCI_REG8(0x3668), 0x00 }, + { CCI_REG8(0x3674), 0x00 }, + { CCI_REG8(0x3677), 0x3f }, + { CCI_REG8(0x368f), 0x06 }, + { CCI_REG8(0x36a2), 0x19 }, + { CCI_REG8(0x36a4), 0xf1 }, + { CCI_REG8(0x36a5), 0x2d }, + { CCI_REG8(0x3706), 0x30 }, + { CCI_REG8(0x370d), 0x72 }, + { CCI_REG8(0x3713), 0x86 }, + { CCI_REG8(0x3715), 0x03 }, + { CCI_REG8(0x3716), 0x00 }, + { CCI_REG8(0x376d), 0x24 }, + { CCI_REG8(0x3770), 0x3a }, + { CCI_REG8(0x3778), 0x00 }, + { CCI_REG8(0x37a8), 0x03 }, + { CCI_REG8(0x37a9), 0x00 }, + { CCI_REG8(0x37df), 0x7d }, + { CCI_REG8(0x3800), 0x00 }, + { CCI_REG8(0x3801), 0x00 }, + { CCI_REG8(0x3802), 0x00 }, + { CCI_REG8(0x3803), 0x00 }, + { CCI_REG8(0x3804), 0x02 }, + { CCI_REG8(0x3805), 0x8f }, + { CCI_REG8(0x3806), 0x01 }, + { CCI_REG8(0x3807), 0xef }, + { CCI_REG8(0x3808), 0x02 }, + { CCI_REG8(0x3809), 0x80 }, + { CCI_REG8(0x380a), 0x01 }, + { CCI_REG8(0x380b), 0xe0 }, + { CCI_REG8(0x380c), 0x01 }, + { CCI_REG8(0x380d), 0x78 }, + { CCI_REG8(0x380e), 0x08 }, + { CCI_REG8(0x380f), 0x30 }, + { CCI_REG8(0x3810), 0x00 }, + { CCI_REG8(0x3811), 0x08 }, + { CCI_REG8(0x3812), 0x00 }, + { CCI_REG8(0x3813), 0x08 }, + { CCI_REG8(0x3814), 0x11 }, + { CCI_REG8(0x3815), 0x11 }, + { CCI_REG8(0x3816), 0x00 }, + { CCI_REG8(0x3817), 0x01 }, + { CCI_REG8(0x3818), 0x00 }, + { CCI_REG8(0x3819), 0x05 }, + { CCI_REG8(0x3820), 0x40 }, + { CCI_REG8(0x3821), 0x04 }, + { CCI_REG8(0x3823), 0x00 }, + { CCI_REG8(0x3826), 0x00 }, + { CCI_REG8(0x3827), 0x00 }, + { CCI_REG8(0x382b), 0x52 }, + { CCI_REG8(0x384a), 0xa2 }, + { CCI_REG8(0x3858), 0x00 }, + { CCI_REG8(0x3859), 0x00 }, + { CCI_REG8(0x3860), 0x00 }, + { CCI_REG8(0x3861), 0x00 }, + { CCI_REG8(0x3866), 0x0c }, + { CCI_REG8(0x3867), 0x07 }, + { CCI_REG8(0x3884), 0x00 }, + { CCI_REG8(0x3885), 0x08 }, + { CCI_REG8(0x3888), 0x50 }, + { CCI_REG8(0x3893), 0x6c }, + { CCI_REG8(0x3898), 0x00 }, + { CCI_REG8(0x389a), 0x04 }, + { CCI_REG8(0x389b), 0x01 }, + { CCI_REG8(0x389c), 0x0b }, + { CCI_REG8(0x389d), 0xdc }, + { CCI_REG8(0x38b1), 0x04 }, + { CCI_REG8(0x38b2), 0x00 }, + { CCI_REG8(0x38b3), 0x08 }, + { CCI_REG8(0x38c1), 0x46 }, + { CCI_REG8(0x38c9), 0x02 }, + { CCI_REG8(0x38d4), 0x06 }, + { CCI_REG8(0x38d5), 0x5a }, + { CCI_REG8(0x38d6), 0x08 }, + { CCI_REG8(0x38d7), 0x3a }, + { CCI_REG8(0x391f), 0x00 }, + { CCI_REG8(0x3920), 0xaa }, + { CCI_REG8(0x3921), 0x00 }, + { CCI_REG8(0x3922), 0x00 }, + { CCI_REG8(0x3923), 0x00 }, + { CCI_REG8(0x3924), 0x00 }, + { CCI_REG8(0x3925), 0x00 }, + { CCI_REG8(0x3926), 0x00 }, + { CCI_REG8(0x3927), 0x00 }, + { CCI_REG8(0x3928), 0x10 }, + { CCI_REG8(0x3929), 0x01 }, + { CCI_REG8(0x392a), 0xb4 }, + { CCI_REG8(0x392b), 0x00 }, + { CCI_REG8(0x392c), 0x10 }, + { CCI_REG8(0x392d), 0x01 }, + { CCI_REG8(0x392e), 0x78 }, + { CCI_REG8(0x392f), 0x4a }, + { CCI_REG8(0x391e), 0x01 }, + { CCI_REG8(0x389f), 0x08 }, + { CCI_REG8(0x38a0), 0x00 }, + { CCI_REG8(0x38a1), 0x00 }, + { CCI_REG8(0x3a06), 0x06 }, + { CCI_REG8(0x3a07), 0x78 }, + { CCI_REG8(0x3a08), 0x08 }, + { CCI_REG8(0x3a09), 0x80 }, + { CCI_REG8(0x3a52), 0x00 }, + { CCI_REG8(0x3a53), 0x01 }, + { CCI_REG8(0x3a54), 0x0c }, + { CCI_REG8(0x3a55), 0x04 }, + { CCI_REG8(0x3a58), 0x0c }, + { CCI_REG8(0x3a59), 0x04 }, + { CCI_REG8(0x4000), 0xcf }, + { CCI_REG8(0x4003), 0x40 }, + { CCI_REG8(0x4008), 0x04 }, + { CCI_REG8(0x4009), 0x13 }, + { CCI_REG8(0x400a), 0x02 }, + { CCI_REG8(0x400b), 0x34 }, + { CCI_REG8(0x4010), 0x71 }, + { CCI_REG8(0x4042), 0xc3 }, + { CCI_REG8(0x4306), 0x04 }, + { CCI_REG8(0x4307), 0x12 }, + { CCI_REG8(0x4500), 0x70 }, + { CCI_REG8(0x4509), 0x00 }, + { CCI_REG8(0x450b), 0x83 }, + { CCI_REG8(0x4604), 0x68 }, + { CCI_REG8(0x481b), 0x44 }, + { CCI_REG8(0x481f), 0x30 }, + { CCI_REG8(0x4823), 0x44 }, + { CCI_REG8(0x4825), 0x35 }, + { CCI_REG8(0x4837), 0x11 }, + { CCI_REG8(0x4f00), 0x04 }, + { CCI_REG8(0x4f10), 0x04 }, + { CCI_REG8(0x4f21), 0x01 }, + { CCI_REG8(0x4f22), 0x00 }, + { CCI_REG8(0x4f23), 0x54 }, + { CCI_REG8(0x4f24), 0x51 }, + { CCI_REG8(0x4f25), 0x41 }, + { CCI_REG8(0x5000), 0x3f }, + { CCI_REG8(0x5001), 0x80 }, + { CCI_REG8(0x500a), 0x00 }, + { CCI_REG8(0x5100), 0x00 }, + { CCI_REG8(0x5111), 0x20 }, +}; + +static const struct og0ve1b_mode og0va1b_supported_modes[] = { + { + .width = 640, + .height = 480, + .hts = 752, + .vts = 2096, + .bpp = 10, + .code = MEDIA_BUS_FMT_Y10_1X10, + .reg_list = { + .regs = og0va1b_640x480_60fps_mode, + .num_regs = ARRAY_SIZE(og0va1b_640x480_60fps_mode), + }, + }, +}; + static const struct og0ve1b_sensor_data og0ve1b_data = { + .name = "og0ve1b", .chip_id = OG0VE1B_CHIP_ID, .mclk_freq = OG0VE1B_MCLK_FREQ_24MHZ, .test_pattern_reg = OG0VE1B_REG_PRE_ISP, + .exposure_shift = 4,
Quoted 9 lines
drivers/media/i2c/og0ve1b.c static const struct og0ve1b_mode supported_modes[] = { · line 490
Quoted 5 lines
drivers/media/i2c/og0ve1b.c +1
-0+ .pixel_rate_mul = 1, .link_freq_menu = og0ve1b_link_freq_menu, .num_link_freqs = ARRAY_SIZE(og0ve1b_link_freq_menu), .modes = supported_modes, .num_modes = ARRAY_SIZE(supported_modes),Can you please rename "
supported_modes" to "og0ve1b_supported_modes"? Likely it should be done in 2/3 change, but it's up to you.
ACK.
Quoted 7 lines
Quoted 7 lines
drivers/media/i2c/og0ve1b.c +6
-0}; +static const struct og0ve1b_sensor_data og0va1b_data = { + .name = "og0va1b", + .chip_id = OG0VA1B_CHIP_ID, + .mclk_freq = OG0VA1B_MCLK_FREQ_19_2MHZ, + .test_pattern_reg = OG0VA1B_REG_TEST_PATTERN, + .exposure_shift = 0,
Quoted 9 lines
drivers/media/i2c/og0ve1b.c static const struct og0ve1b_mode supported_modes[] = { · line 504
Quoted 6 lines
drivers/media/i2c/og0ve1b.c +6
-0+ .pixel_rate_mul = 2, + .link_freq_menu = og0va1b_link_freq_menu, + .num_link_freqs = ARRAY_SIZE(og0va1b_link_freq_menu), + .modes = og0va1b_supported_modes, + .num_modes = ARRAY_SIZE(og0va1b_supported_modes), +};First
og0va1b_data, thenog0ve1b_datadeclaration to keep the natural order.
ACK.
Quoted 38 lines
Quoted 38 lines
drivers/media/i2c/og0ve1b.c +1
-0+ static int og0ve1b_enable_test_pattern(struct og0ve1b *og0ve1b, u32 pattern) { u32 reg = og0ve1b->sensor->test_pattern_reg;@@ -334,7 +555,8 @@ static int og0ve1b_set_ctrl(struct v4l2_ctrl *ctrl) break;case
V4L2_CID_EXPOSURE:
ret =cci_write(og0ve1b->regmap, OG0VE1B_REG_EXPOSURE, - ctrl->val << 4, NULL);
+ctrl->val<<og0ve1b->sensor->exposure_shift, + NULL);
break;
caseV4L2_CID_VBLANK:
ret = cci_write(og0ve1b->regmap,OG0VE1B_REG_VTS,drivers/media/i2c/og0ve1b.c +5
-1@@ -376,7 +598,8 @@ static int og0ve1b_init_controls(struct og0ve1b *og0ve1b) if (ctrl) ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; - pixel_rate = sensor->link_freq_menu[0] / mode->bpp; + pixel_rate = sensor->link_freq_menu[0] * sensor->pixel_rate_mul / + mode->bpp; v4l2_ctrl_new_std(ctrl_hdlr, &og0ve1b_ctrl_ops, V4L2_CID_PIXEL_RATE, 0, pixel_rate, 1, pixel_rate);@@ -721,6 +944,8 @@ static int og0ve1b_probe(struct i2c_client *client) return -ENODEV; v4l2_i2c_subdev_init(&og0ve1b->sd, client, &og0ve1b_subdev_ops); + v4l2_i2c_subdev_set_name(&og0ve1b->sd, client, + og0ve1b->sensor->name, NULL); og0ve1b->regmap = devm_cci_regmap_init_i2c(client, 16); if (IS_ERR(og0ve1b->regmap))@@ -853,6 +1078,7 @@ static const struct dev_pm_ops og0ve1b_pm_ops = { static const struct of_device_id og0ve1b_of_match[] = { { .compatible = "ovti,og0ve1b", .data = &og0ve1b_data }, + { .compatible = "ovti,og0va1b", .data = &og0va1b_data }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, og0ve1b_of_match);@@ -870,5 +1096,5 @@ static struct i2c_driver og0ve1b_i2c_driver = {
Quoted 9 lines
drivers/media/i2c/og0ve1b.c static struct i2c_driver og0ve1b_i2c_driver = {
Quoted 6 lines
drivers/media/i2c/og0ve1b.c +1
-1module_i2c_driver(og0ve1b_i2c_driver); MODULE_AUTHOR("Vladimir Zapolskiy <[email protected]>"); -MODULE_DESCRIPTION ("OmniVision OG0VE1B sensor driver" ); +MODULE_DESCRIPTION ("OmniVision OG0VE1B/OG0VA1B sensor driver" ); MODULE_LICENSE("GPL");Looks good, thank you!
Will fix it all in next version.
Thanks,
Wenmeng