From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Use the newly added internal pad API to expose the internal
configuration of the sensor to userspace in a standard manner.
Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
---
drivers/media/i2c/ov5645.c | 115 +++++++++++++++++++++++++++----------
1 file changed, 84 insertions(+), 31 deletions(-)
diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
index e3706b6b5621..a3353992594b 100644
--- a/drivers/media/i2c/ov5645.c
+++ b/drivers/media/i2c/ov5645.c
@@ -61,6 +61,10 @@
#define OV5645_SDE_SAT_U 0x5583
#define OV5645_SDE_SAT_V 0x5584
+#define OV5645_NATIVE_FORMAT MEDIA_BUS_FMT_SBGGR8_1X8
+#define OV5645_NATIVE_WIDTH 2592
+#define OV5645_NATIVE_HEIGHT 1944
+
/* regulator supplies */
static const char * const ov5645_supply_name[] = {
"vdddo", /* Digital I/O (1.8V) supply */
@@ -70,6 +74,12 @@ static const char * const ov5645_supply_name[] = {
#define OV5645_NUM_SUPPLIES ARRAY_SIZE(ov5645_supply_name)
+enum ov5645_pad_ids {
+ OV5645_PAD_SOURCE,
+ OV5645_PAD_IMAGE,
+ OV5645_NUM_PADS,
+};
+
struct reg_value {
u16 reg;
u8 val;
@@ -88,7 +98,7 @@ struct ov5645 {
struct i2c_client *i2c_client;
struct device *dev;
struct v4l2_subdev sd;
- struct media_pad pad;
+ struct media_pad pads[OV5645_NUM_PADS];
struct v4l2_fwnode_endpoint ep;
struct v4l2_rect crop;
struct clk *xclk;
@@ -850,7 +860,10 @@ static int ov5645_enum_mbus_code(struct v4l2_subdev *sd,
if (code->index > 0)
return -EINVAL;
- code->code = MEDIA_BUS_FMT_UYVY8_1X16;
+ if (code->pad == OV5645_PAD_IMAGE)
+ code->code = OV5645_NATIVE_FORMAT;
+ else
+ code->code = MEDIA_BUS_FMT_UYVY8_1X16;
return 0;
}
@@ -859,16 +872,24 @@ static int ov5645_enum_frame_size(struct v4l2_subdev *subdev,
struct v4l2_subdev_state *sd_state,
struct v4l2_subdev_frame_size_enum *fse)
{
- if (fse->code != MEDIA_BUS_FMT_UYVY8_1X16)
- return -EINVAL;
-
- if (fse->index >= ARRAY_SIZE(ov5645_mode_info_data))
- return -EINVAL;
-
- fse->min_width = ov5645_mode_info_data[fse->index].width;
- fse->max_width = ov5645_mode_info_data[fse->index].width;
- fse->min_height = ov5645_mode_info_data[fse->index].height;
- fse->max_height = ov5645_mode_info_data[fse->index].height;
+ if (fse->pad == OV5645_PAD_IMAGE) {
+ if (fse->code != OV5645_NATIVE_FORMAT || fse->index > 0)
+ return -EINVAL;
+
+ fse->min_width = OV5645_NATIVE_WIDTH;
+ fse->max_width = OV5645_NATIVE_WIDTH;
+ fse->min_height = OV5645_NATIVE_HEIGHT;
+ fse->max_height = OV5645_NATIVE_HEIGHT;
+ } else {
+ if (fse->code != MEDIA_BUS_FMT_UYVY8_1X16 ||
+ fse->index >= ARRAY_SIZE(ov5645_mode_info_data))
+ return -EINVAL;
+
+ fse->min_width = ov5645_mode_info_data[fse->index].width;
+ fse->max_width = ov5645_mode_info_data[fse->index].width;
+ fse->min_height = ov5645_mode_info_data[fse->index].height;
+ fse->max_height = ov5645_mode_info_data[fse->index].height;
+ }
return 0;
}
@@ -877,20 +898,57 @@ static int ov5645_set_format(struct v4l2_subdev *sd,
struct v4l2_subdev_state *sd_state,
struct v4l2_subdev_format *format)
{
- struct ov5645 *ov5645 = to_ov5645(sd);
- struct v4l2_mbus_framefmt *__format;
- struct v4l2_rect *__crop;
const struct ov5645_mode_info *new_mode;
+ struct ov5645 *ov5645 = to_ov5645(sd);
+ struct v4l2_mbus_framefmt *fmt;
+ struct v4l2_rect *compose;
+ struct v4l2_rect *crop;
int ret;
- __crop = v4l2_subdev_state_get_crop(sd_state, 0);
+ if (format->pad != OV5645_PAD_SOURCE)
+ return v4l2_subdev_get_fmt(sd, sd_state, format);
+
new_mode = v4l2_find_nearest_size(ov5645_mode_info_data,
ARRAY_SIZE(ov5645_mode_info_data),
width, height, format->format.width,
format->format.height);
-
- __crop->width = new_mode->width;
- __crop->height = new_mode->height;
+ format->format.code = MEDIA_BUS_FMT_UYVY8_1X16;
+ format->format.width = new_mode->width;
+ format->format.height = new_mode->height;
+ format->format.field = V4L2_FIELD_NONE;
+ format->format.colorspace = V4L2_COLORSPACE_SRGB;
+ format->format.ycbcr_enc = V4L2_YCBCR_ENC_601;
+ format->format.quantization = V4L2_QUANTIZATION_LIM_RANGE;
+ format->format.xfer_func = V4L2_XFER_FUNC_SRGB;
+
+ fmt = v4l2_subdev_state_get_format(sd_state, OV5645_PAD_IMAGE);
+ *fmt = format->format;
+ fmt->code = OV5645_NATIVE_FORMAT;
+ fmt->width = OV5645_NATIVE_WIDTH;
+ fmt->height = OV5645_NATIVE_HEIGHT;
+
+ crop = v4l2_subdev_state_get_crop(sd_state, OV5645_PAD_IMAGE);
+ crop->width = format->format.width;
+ crop->height = format->format.height;
+
+ /*
+ * The compose rectangle models binning, its size is the sensor output
+ * size.
+ */
+ compose = v4l2_subdev_state_get_compose(sd_state, OV5645_PAD_IMAGE);
+ compose->left = 0;
+ compose->top = 0;
+ compose->width = format->format.width;
+ compose->height = format->format.height;
+
+ crop = v4l2_subdev_state_get_crop(sd_state, OV5645_PAD_SOURCE);
+ crop->left = 0;
+ crop->top = 0;
+ crop->width = format->format.width;
+ crop->height = format->format.height;
+
+ fmt = v4l2_subdev_state_get_format(sd_state, OV5645_PAD_SOURCE);
+ *fmt = format->format;
if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
ret = __v4l2_ctrl_s_ctrl_int64(ov5645->pixel_clock,
@@ -906,14 +964,6 @@ static int ov5645_set_format(struct v4l2_subdev *sd,
ov5645->current_mode = new_mode;
}
- __format = v4l2_subdev_state_get_format(sd_state, 0);
- __format->width = __crop->width;
- __format->height = __crop->height;
- __format->code = MEDIA_BUS_FMT_UYVY8_1X16;
- __format->field = V4L2_FIELD_NONE;
- __format->colorspace = V4L2_COLORSPACE_SRGB;
-
- format->format = *__format;
return 0;
}
@@ -923,7 +973,7 @@ static int ov5645_init_state(struct v4l2_subdev *subdev,
{
struct v4l2_subdev_format fmt = {
.which = V4L2_SUBDEV_FORMAT_TRY,
- .pad = 0,
+ .pad = OV5645_PAD_SOURCE,
.format = {
.code = MEDIA_BUS_FMT_UYVY8_1X16,
.width = ov5645_mode_info_data[1].width,
@@ -943,7 +993,7 @@ static int ov5645_get_selection(struct v4l2_subdev *sd,
if (sel->target != V4L2_SEL_TGT_CROP)
return -EINVAL;
- sel->r = *v4l2_subdev_state_get_crop(sd_state, 0);
+ sel->r = *v4l2_subdev_state_get_crop(sd_state, sel->pad);
return 0;
}
@@ -1157,11 +1207,14 @@ static int ov5645_probe(struct i2c_client *client)
ov5645->sd.internal_ops = &ov5645_internal_ops;
ov5645->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
V4L2_SUBDEV_FL_HAS_EVENTS;
- ov5645->pad.flags = MEDIA_PAD_FL_SOURCE;
+ ov5645->pads[OV5645_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
+ ov5645->pads[OV5645_PAD_IMAGE].flags = MEDIA_PAD_FL_SINK |
+ MEDIA_PAD_FL_INTERNAL;
ov5645->sd.dev = dev;
ov5645->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
- ret = media_entity_pads_init(&ov5645->sd.entity, 1, &ov5645->pad);
+ ret = media_entity_pads_init(&ov5645->sd.entity,
+ ARRAY_SIZE(ov5645->pads), ov5645->pads);
if (ret < 0) {
dev_err_probe(dev, ret, "could not register media entity\n");
goto free_ctrl;
--
2.43.0