25
25
#define IMX415_PIXEL_ARRAY_WIDTH 3864
26
26
#define IMX415_PIXEL_ARRAY_HEIGHT 2192
27
27
#define IMX415_PIXEL_ARRAY_VBLANK 58
28
+ #define IMX415_EXPOSURE_OFFSET 8
28
29
29
30
#define IMX415_NUM_CLK_PARAM_REGS 11
30
31
56
57
#define IMX415_OUTSEL IMX415_REG_8BIT(0x30C0)
57
58
#define IMX415_DRV IMX415_REG_8BIT(0x30C1)
58
59
#define IMX415_VMAX IMX415_REG_24BIT(0x3024)
60
+ #define IMX415_VMAX_MAX 0xfffff
59
61
#define IMX415_HMAX IMX415_REG_16BIT(0x3028)
60
62
#define IMX415_SHR0 IMX415_REG_24BIT(0x3050)
61
63
#define IMX415_GAIN_PCG_0 IMX415_REG_16BIT(0x3090)
@@ -457,7 +459,6 @@ static const struct imx415_clk_params imx415_clk_params[] = {
457
459
458
460
/* all-pixel 2-lane 720 Mbps 15.74 Hz mode */
459
461
static const struct imx415_reg imx415_mode_2_720 [] = {
460
- { IMX415_VMAX , 0x08CA },
461
462
{ IMX415_HMAX , 0x07F0 },
462
463
{ IMX415_LANEMODE , IMX415_LANEMODE_2 },
463
464
{ IMX415_TCLKPOST , 0x006F },
@@ -473,7 +474,6 @@ static const struct imx415_reg imx415_mode_2_720[] = {
473
474
474
475
/* all-pixel 2-lane 1440 Mbps 30.01 Hz mode */
475
476
static const struct imx415_reg imx415_mode_2_1440 [] = {
476
- { IMX415_VMAX , 0x08CA },
477
477
{ IMX415_HMAX , 0x042A },
478
478
{ IMX415_LANEMODE , IMX415_LANEMODE_2 },
479
479
{ IMX415_TCLKPOST , 0x009F },
@@ -489,7 +489,6 @@ static const struct imx415_reg imx415_mode_2_1440[] = {
489
489
490
490
/* all-pixel 4-lane 891 Mbps 30 Hz mode */
491
491
static const struct imx415_reg imx415_mode_4_891 [] = {
492
- { IMX415_VMAX , 0x08CA },
493
492
{ IMX415_HMAX , 0x044C },
494
493
{ IMX415_LANEMODE , IMX415_LANEMODE_4 },
495
494
{ IMX415_TCLKPOST , 0x007F },
@@ -617,6 +616,7 @@ struct imx415 {
617
616
struct v4l2_ctrl * vblank ;
618
617
struct v4l2_ctrl * hflip ;
619
618
struct v4l2_ctrl * vflip ;
619
+ struct v4l2_ctrl * exposure ;
620
620
621
621
unsigned int cur_mode ;
622
622
unsigned int num_data_lanes ;
@@ -795,16 +795,37 @@ static int imx415_s_ctrl(struct v4l2_ctrl *ctrl)
795
795
ctrls );
796
796
const struct v4l2_mbus_framefmt * format ;
797
797
struct v4l2_subdev_state * state ;
798
+ u32 exposure_max ;
798
799
unsigned int vmax ;
799
800
unsigned int flip ;
800
-
801
- if (!sensor -> streaming )
802
- return 0 ;
801
+ int ret ;
803
802
804
803
state = v4l2_subdev_get_locked_active_state (& sensor -> subdev );
805
804
format = v4l2_subdev_get_pad_format (& sensor -> subdev , state , 0 );
806
805
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
+
807
818
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 ;
808
829
case V4L2_CID_EXPOSURE :
809
830
/* clamp the exposure value to VMAX. */
810
831
vmax = format -> height + sensor -> vblank -> cur .val ;
@@ -840,7 +861,8 @@ static int imx415_ctrls_init(struct imx415 *sensor)
840
861
u64 pixel_rate = supported_modes [sensor -> cur_mode ].pixel_rate ;
841
862
u64 lane_rate = supported_modes [sensor -> cur_mode ].lane_rate ;
842
863
u32 exposure_max = IMX415_PIXEL_ARRAY_HEIGHT +
843
- IMX415_PIXEL_ARRAY_VBLANK - 8 ;
864
+ IMX415_PIXEL_ARRAY_VBLANK -
865
+ IMX415_EXPOSURE_OFFSET ;
844
866
u32 hblank ;
845
867
unsigned int i ;
846
868
int ret ;
@@ -869,8 +891,9 @@ static int imx415_ctrls_init(struct imx415 *sensor)
869
891
if (ctrl )
870
892
ctrl -> flags |= V4L2_CTRL_FLAG_READ_ONLY ;
871
893
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 );
874
897
875
898
v4l2_ctrl_new_std (& sensor -> ctrls , & imx415_ctrl_ops ,
876
899
V4L2_CID_ANALOGUE_GAIN , IMX415_AGAIN_MIN ,
@@ -887,16 +910,9 @@ static int imx415_ctrls_init(struct imx415 *sensor)
887
910
sensor -> vblank = v4l2_ctrl_new_std (& sensor -> ctrls , & imx415_ctrl_ops ,
888
911
V4L2_CID_VBLANK ,
889
912
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 );
894
915
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
- */
900
916
v4l2_ctrl_new_std (& sensor -> ctrls , NULL , V4L2_CID_PIXEL_RATE , pixel_rate ,
901
917
pixel_rate , 1 , pixel_rate );
902
918
0 commit comments