diff --git a/drivers/media/i2c/maxim/local/maxim2c/maxim2c_drv.h b/drivers/media/i2c/maxim/local/maxim2c/maxim2c_drv.h index 2376c3126d37..9711cb08d443 100644 --- a/drivers/media/i2c/maxim/local/maxim2c/maxim2c_drv.h +++ b/drivers/media/i2c/maxim/local/maxim2c/maxim2c_drv.h @@ -55,6 +55,7 @@ struct maxim2c_mode { u32 bpp; const struct regval *reg_list; u32 vc[PAD_MAX]; + struct v4l2_rect crop_rect; }; typedef struct maxim2c { diff --git a/drivers/media/i2c/maxim/local/maxim2c/maxim2c_pattern.c b/drivers/media/i2c/maxim/local/maxim2c/maxim2c_pattern.c index 8bbf1ae8cee6..a0c4d02eac23 100644 --- a/drivers/media/i2c/maxim/local/maxim2c/maxim2c_pattern.c +++ b/drivers/media/i2c/maxim/local/maxim2c/maxim2c_pattern.c @@ -41,6 +41,13 @@ static const struct maxim2c_mode maxim2c_pattern_mode = { #else .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_0, #endif + /* crop rect */ + .crop_rect = { + .left = 0, + .width = PATTERN_WIDTH, + .top = 0, + .height = PATTERN_HEIGHT, + }, }; int maxim2c_pattern_enable(maxim2c_t *maxim2c, bool enable) diff --git a/drivers/media/i2c/maxim/local/maxim2c/maxim2c_v4l2.c b/drivers/media/i2c/maxim/local/maxim2c/maxim2c_v4l2.c index 49c499453eaf..766c21ab9d6a 100644 --- a/drivers/media/i2c/maxim/local/maxim2c/maxim2c_v4l2.c +++ b/drivers/media/i2c/maxim/local/maxim2c/maxim2c_v4l2.c @@ -77,6 +77,13 @@ static const struct maxim2c_mode maxim2c_def_mode = { .vc[PAD2] = V4L2_MBUS_CSI2_CHANNEL_2, .vc[PAD3] = V4L2_MBUS_CSI2_CHANNEL_3, #endif /* LINUX_VERSION_CODE */ + /* crop rect */ + .crop_rect = { + .left = 0, + .width = 1920, + .top = 0, + .height = 1080, + }, }; static struct rkmodule_csi_dphy_param rk3588_dcphy_param = { @@ -95,7 +102,7 @@ static int maxim2c_support_mode_init(maxim2c_t *maxim2c) struct device *dev = &maxim2c->client->dev; struct device_node *node = NULL; struct maxim2c_mode *mode = NULL; - u32 value = 0, vc_array[PAD_MAX]; + u32 value = 0, vc_array[PAD_MAX], crop_array[4]; int ret = 0, i = 0, array_size = 0; dev_info(dev, "=== maxim2c support mode init ===\n"); @@ -210,6 +217,28 @@ static int maxim2c_support_mode_init(maxim2c_t *maxim2c) for (i = 0; i < PAD_MAX; i++) dev_info(dev, "support mode: vc[%d] = 0x%x\n", i, mode->vc[i]); + /* crop rect */ + array_size = of_property_read_variable_u32_array(node, + "crop-rect", crop_array, 1, 4); + if (array_size == 4) { + /* [left, top, width, height] */ + for (i = 0; i < array_size; i++) + dev_info(dev, "crop-rect[%d] property: %d\n", i, crop_array[i]); + + mode->crop_rect.left = crop_array[0]; + mode->crop_rect.top = crop_array[1]; + mode->crop_rect.width = crop_array[2]; + mode->crop_rect.height = crop_array[3]; + } else { + mode->crop_rect.left = 0; + mode->crop_rect.width = mode->width; + mode->crop_rect.top = 0; + mode->crop_rect.height = mode->height; + } + dev_info(dev, "support mode crop rect: [ left = %d, top = %d, width = %d, height = %d ]\n", + mode->crop_rect.left, mode->crop_rect.top, + mode->crop_rect.width, mode->crop_rect.height); + of_node_put(node); return 0; @@ -835,10 +864,10 @@ static int maxim2c_get_selection(struct v4l2_subdev *sd, maxim2c_t *maxim2c = v4l2_get_subdevdata(sd); if (sel->target == V4L2_SEL_TGT_CROP_BOUNDS) { - sel->r.left = 0; - sel->r.width = maxim2c->cur_mode->width; - sel->r.top = 0; - sel->r.height = maxim2c->cur_mode->height; + sel->r.left = maxim2c->cur_mode->crop_rect.left; + sel->r.width = maxim2c->cur_mode->crop_rect.width; + sel->r.top = maxim2c->cur_mode->crop_rect.top; + sel->r.height = maxim2c->cur_mode->crop_rect.height; return 0; } diff --git a/drivers/media/i2c/maxim/local/maxim4c/maxim4c_drv.h b/drivers/media/i2c/maxim/local/maxim4c/maxim4c_drv.h index 8fb35d491d79..d4485fea0bbb 100644 --- a/drivers/media/i2c/maxim/local/maxim4c/maxim4c_drv.h +++ b/drivers/media/i2c/maxim/local/maxim4c/maxim4c_drv.h @@ -55,6 +55,7 @@ struct maxim4c_mode { u32 bpp; const struct regval *reg_list; u32 vc[PAD_MAX]; + struct v4l2_rect crop_rect; }; typedef struct maxim4c { diff --git a/drivers/media/i2c/maxim/local/maxim4c/maxim4c_pattern.c b/drivers/media/i2c/maxim/local/maxim4c/maxim4c_pattern.c index 25400b074245..1ea4e2eeecf1 100644 --- a/drivers/media/i2c/maxim/local/maxim4c/maxim4c_pattern.c +++ b/drivers/media/i2c/maxim/local/maxim4c/maxim4c_pattern.c @@ -47,6 +47,13 @@ static const struct maxim4c_mode maxim4c_pattern_mode = { #else .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_0, #endif + /* crop rect */ + .crop_rect = { + .left = 0, + .width = PATTERN_WIDTH, + .top = 0, + .height = PATTERN_HEIGHT, + }, }; /* VPG0 or VPG1 register */ diff --git a/drivers/media/i2c/maxim/local/maxim4c/maxim4c_v4l2.c b/drivers/media/i2c/maxim/local/maxim4c/maxim4c_v4l2.c index 20f755e0e241..9498c265d634 100644 --- a/drivers/media/i2c/maxim/local/maxim4c/maxim4c_v4l2.c +++ b/drivers/media/i2c/maxim/local/maxim4c/maxim4c_v4l2.c @@ -77,6 +77,13 @@ static const struct maxim4c_mode maxim4c_def_mode = { .vc[PAD2] = V4L2_MBUS_CSI2_CHANNEL_2, .vc[PAD3] = V4L2_MBUS_CSI2_CHANNEL_3, #endif /* LINUX_VERSION_CODE */ + /* crop rect */ + .crop_rect = { + .left = 0, + .width = 1920, + .top = 0, + .height = 1080, + }, }; static struct rkmodule_csi_dphy_param rk3588_dcphy_param = { @@ -95,7 +102,7 @@ static int maxim4c_support_mode_init(maxim4c_t *maxim4c) struct device *dev = &maxim4c->client->dev; struct device_node *node = NULL; struct maxim4c_mode *mode = NULL; - u32 value = 0, vc_array[PAD_MAX]; + u32 value = 0, vc_array[PAD_MAX], crop_array[4]; int ret = 0, i = 0, array_size = 0; dev_info(dev, "=== maxim4c support mode init ===\n"); @@ -210,6 +217,28 @@ static int maxim4c_support_mode_init(maxim4c_t *maxim4c) for (i = 0; i < PAD_MAX; i++) dev_info(dev, "support mode: vc[%d] = 0x%x\n", i, mode->vc[i]); + /* crop rect */ + array_size = of_property_read_variable_u32_array(node, + "crop-rect", crop_array, 1, 4); + if (array_size == 4) { + /* [left, top, width, height] */ + for (i = 0; i < array_size; i++) + dev_info(dev, "crop-rect[%d] property: %d\n", i, crop_array[i]); + + mode->crop_rect.left = crop_array[0]; + mode->crop_rect.top = crop_array[1]; + mode->crop_rect.width = crop_array[2]; + mode->crop_rect.height = crop_array[3]; + } else { + mode->crop_rect.left = 0; + mode->crop_rect.width = mode->width; + mode->crop_rect.top = 0; + mode->crop_rect.height = mode->height; + } + dev_info(dev, "support mode crop rect: [ left = %d, top = %d, width = %d, height = %d ]\n", + mode->crop_rect.left, mode->crop_rect.top, + mode->crop_rect.width, mode->crop_rect.height); + of_node_put(node); return 0; @@ -835,10 +864,10 @@ static int maxim4c_get_selection(struct v4l2_subdev *sd, maxim4c_t *maxim4c = v4l2_get_subdevdata(sd); if (sel->target == V4L2_SEL_TGT_CROP_BOUNDS) { - sel->r.left = 0; - sel->r.width = maxim4c->cur_mode->width; - sel->r.top = 0; - sel->r.height = maxim4c->cur_mode->height; + sel->r.left = maxim4c->cur_mode->crop_rect.left; + sel->r.width = maxim4c->cur_mode->crop_rect.width; + sel->r.top = maxim4c->cur_mode->crop_rect.top; + sel->r.height = maxim4c->cur_mode->crop_rect.height; return 0; }