[PATCH v12 50/86] media: ov2740: Add support for generic raw formats

Sakari Ailus
2026-04-09T20:15:38Z

Add RAW_10 media bus code and V4L2_CID_CFA_PATTERN as well as
V4L2_CID_CFA_PATTERN_FLIP control support.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
drivers/media/i2c/ov2740.c | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/ov2740.c b/drivers/media/i2c/ov2740.c
index b3d0c7e81585..cc9cd7ccbf1f 100644
--- a/drivers/media/i2c/ov2740.c
+++ b/drivers/media/i2c/ov2740.c
@@ -807,7 +807,7 @@ static int ov2740_init_controls(struct ov2740 *ov2740)
int ret;

ctrl_hdlr = &ov2740->ctrl_handler;
- ret = v4l2_ctrl_handler_init(ctrl_hdlr, 10);
+ ret = v4l2_ctrl_handler_init(ctrl_hdlr, 12);
if (ret)
return ret;

@@ -855,6 +855,13 @@ static int ov2740_init_controls(struct ov2740 *ov2740)
V4L2_CID_TEST_PATTERN,
ARRAY_SIZE(ov2740_test_pattern_menu) - 1,
0, 0, ov2740_test_pattern_menu);
+ v4l2_ctrl_new_std(ctrl_hdlr, NULL, V4L2_CID_CFA_PATTERN,
+ V4L2_CFA_PATTERN_GRBG, V4L2_CFA_PATTERN_GRBG,
+ 1, V4L2_CFA_PATTERN_GRBG);
+ v4l2_ctrl_new_std(ctrl_hdlr, NULL,
+ V4L2_CID_CFA_PATTERN_FLIP,
+ 0, V4L2_CFA_PATTERN_FLIP_BOTH,
+ 0, V4L2_CFA_PATTERN_FLIP_BOTH);

ret = v4l2_fwnode_device_parse(ov2740->dev, &props);
if (ret) {
@@ -1090,6 +1097,9 @@ static int __ov2740_set_format(struct v4l2_subdev *sd,
width, height,
format->width, format->height);

+ if (format->code != MEDIA_BUS_FMT_RAW_10)
+ format->code = MEDIA_BUS_FMT_SGRBG10_1X10;
+
src_pix_fmt->code = format->code;
src_pix_fmt->width = mode->width;
src_pix_fmt->height = mode->height;
@@ -1130,10 +1140,14 @@ static int ov2740_enum_mbus_code(struct v4l2_subdev *sd,
struct v4l2_subdev_state *sd_state,
struct v4l2_subdev_mbus_code_enum *code)
{
- if (code->index > 0)
+ const u32 codes[] = {
+ MEDIA_BUS_FMT_SGRBG10_1X10,
+ MEDIA_BUS_FMT_RAW_10,
+ };
+ if (code->index >= ARRAY_SIZE(codes))
return -EINVAL;

- code->code = MEDIA_BUS_FMT_SGRBG10_1X10;
+ code->code = codes[code->index];

return 0;
}
@@ -1148,7 +1162,8 @@ static int ov2740_enum_frame_size(struct v4l2_subdev *sd,
if (fse->index >= ov2740->supported_modes_count)
return -EINVAL;

- if (fse->code != MEDIA_BUS_FMT_SGRBG10_1X10)
+ if (fse->code != MEDIA_BUS_FMT_SGRBG10_1X10 &&
+ fse->code != MEDIA_BUS_FMT_RAW_10)
return -EINVAL;

fse->min_width = supported_modes[fse->index].width;
--
2.47.3