Skip to content

Commit 4e8d73c

Browse files
6by9pelwell
authored andcommitted
media: i2c: imx415: Add read/write control of VBLANK
This also requires that the ranges for the exposure control are updated. Signed-off-by: Dave Stevenson <[email protected]>
1 parent 384e58f commit 4e8d73c

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

drivers/media/i2c/imx415.c

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define IMX415_PIXEL_ARRAY_WIDTH 3864
2626
#define IMX415_PIXEL_ARRAY_HEIGHT 2192
2727
#define IMX415_PIXEL_ARRAY_VBLANK 58
28+
#define IMX415_EXPOSURE_OFFSET 8
2829

2930
#define IMX415_NUM_CLK_PARAM_REGS 11
3031

@@ -56,6 +57,7 @@
5657
#define IMX415_OUTSEL IMX415_REG_8BIT(0x30C0)
5758
#define IMX415_DRV IMX415_REG_8BIT(0x30C1)
5859
#define IMX415_VMAX IMX415_REG_24BIT(0x3024)
60+
#define IMX415_VMAX_MAX 0xfffff
5961
#define IMX415_HMAX IMX415_REG_16BIT(0x3028)
6062
#define IMX415_SHR0 IMX415_REG_24BIT(0x3050)
6163
#define IMX415_GAIN_PCG_0 IMX415_REG_16BIT(0x3090)
@@ -457,7 +459,6 @@ static const struct imx415_clk_params imx415_clk_params[] = {
457459

458460
/* all-pixel 2-lane 720 Mbps 15.74 Hz mode */
459461
static const struct imx415_reg imx415_mode_2_720[] = {
460-
{ IMX415_VMAX, 0x08CA },
461462
{ IMX415_HMAX, 0x07F0 },
462463
{ IMX415_LANEMODE, IMX415_LANEMODE_2 },
463464
{ IMX415_TCLKPOST, 0x006F },
@@ -473,7 +474,6 @@ static const struct imx415_reg imx415_mode_2_720[] = {
473474

474475
/* all-pixel 2-lane 1440 Mbps 30.01 Hz mode */
475476
static const struct imx415_reg imx415_mode_2_1440[] = {
476-
{ IMX415_VMAX, 0x08CA },
477477
{ IMX415_HMAX, 0x042A },
478478
{ IMX415_LANEMODE, IMX415_LANEMODE_2 },
479479
{ IMX415_TCLKPOST, 0x009F },
@@ -489,7 +489,6 @@ static const struct imx415_reg imx415_mode_2_1440[] = {
489489

490490
/* all-pixel 4-lane 891 Mbps 30 Hz mode */
491491
static const struct imx415_reg imx415_mode_4_891[] = {
492-
{ IMX415_VMAX, 0x08CA },
493492
{ IMX415_HMAX, 0x044C },
494493
{ IMX415_LANEMODE, IMX415_LANEMODE_4 },
495494
{ IMX415_TCLKPOST, 0x007F },
@@ -617,6 +616,7 @@ struct imx415 {
617616
struct v4l2_ctrl *vblank;
618617
struct v4l2_ctrl *hflip;
619618
struct v4l2_ctrl *vflip;
619+
struct v4l2_ctrl *exposure;
620620

621621
unsigned int cur_mode;
622622
unsigned int num_data_lanes;
@@ -795,16 +795,37 @@ static int imx415_s_ctrl(struct v4l2_ctrl *ctrl)
795795
ctrls);
796796
const struct v4l2_mbus_framefmt *format;
797797
struct v4l2_subdev_state *state;
798+
u32 exposure_max;
798799
unsigned int vmax;
799800
unsigned int flip;
800-
801-
if (!sensor->streaming)
802-
return 0;
801+
int ret;
803802

804803
state = v4l2_subdev_get_locked_active_state(&sensor->subdev);
805804
format = v4l2_subdev_get_pad_format(&sensor->subdev, state, 0);
806805

806+
if (ctrl->id == V4L2_CID_VBLANK) {
807+
exposure_max = format->height + ctrl->val -
808+
IMX415_EXPOSURE_OFFSET;
809+
__v4l2_ctrl_modify_range(sensor->exposure,
810+
sensor->exposure->minimum,
811+
exposure_max, sensor->exposure->step,
812+
sensor->exposure->default_value);
813+
}
814+
815+
if (!sensor->streaming)
816+
return 0;
817+
807818
switch (ctrl->id) {
819+
case V4L2_CID_VBLANK:
820+
ret = imx415_write(sensor, IMX415_VMAX,
821+
format->height + ctrl->val);
822+
if (ret)
823+
return ret;
824+
/*
825+
* Deliberately fall through as exposure is set based on VMAX
826+
* which has just changed.
827+
*/
828+
fallthrough;
808829
case V4L2_CID_EXPOSURE:
809830
/* clamp the exposure value to VMAX. */
810831
vmax = format->height + sensor->vblank->cur.val;
@@ -840,7 +861,8 @@ static int imx415_ctrls_init(struct imx415 *sensor)
840861
u64 pixel_rate = supported_modes[sensor->cur_mode].pixel_rate;
841862
u64 lane_rate = supported_modes[sensor->cur_mode].lane_rate;
842863
u32 exposure_max = IMX415_PIXEL_ARRAY_HEIGHT +
843-
IMX415_PIXEL_ARRAY_VBLANK - 8;
864+
IMX415_PIXEL_ARRAY_VBLANK -
865+
IMX415_EXPOSURE_OFFSET;
844866
u32 hblank;
845867
unsigned int i;
846868
int ret;
@@ -869,8 +891,9 @@ static int imx415_ctrls_init(struct imx415 *sensor)
869891
if (ctrl)
870892
ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
871893

872-
v4l2_ctrl_new_std(&sensor->ctrls, &imx415_ctrl_ops, V4L2_CID_EXPOSURE,
873-
4, exposure_max, 1, exposure_max);
894+
sensor->exposure = v4l2_ctrl_new_std(&sensor->ctrls, &imx415_ctrl_ops,
895+
V4L2_CID_EXPOSURE, 4,
896+
exposure_max, 1, exposure_max);
874897

875898
v4l2_ctrl_new_std(&sensor->ctrls, &imx415_ctrl_ops,
876899
V4L2_CID_ANALOGUE_GAIN, IMX415_AGAIN_MIN,
@@ -887,16 +910,9 @@ static int imx415_ctrls_init(struct imx415 *sensor)
887910
sensor->vblank = v4l2_ctrl_new_std(&sensor->ctrls, &imx415_ctrl_ops,
888911
V4L2_CID_VBLANK,
889912
IMX415_PIXEL_ARRAY_VBLANK,
890-
IMX415_PIXEL_ARRAY_VBLANK, 1,
891-
IMX415_PIXEL_ARRAY_VBLANK);
892-
if (sensor->vblank)
893-
sensor->vblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
913+
IMX415_VMAX_MAX - IMX415_PIXEL_ARRAY_HEIGHT,
914+
1, IMX415_PIXEL_ARRAY_VBLANK);
894915

895-
/*
896-
* The pixel rate used here is a virtual value and can be used for
897-
* calculating the frame rate together with hblank. It may not
898-
* necessarily be the physically correct pixel clock.
899-
*/
900916
v4l2_ctrl_new_std(&sensor->ctrls, NULL, V4L2_CID_PIXEL_RATE, pixel_rate,
901917
pixel_rate, 1, pixel_rate);
902918

0 commit comments

Comments
 (0)