27
27
#define IMX415_PIXEL_ARRAY_VBLANK 58
28
28
#define IMX415_EXPOSURE_OFFSET 8
29
29
30
+ #define IMX415_PIXEL_RATE_74_25MHZ 891000000
31
+ #define IMX415_PIXEL_RATE_72MHZ 864000000
32
+
30
33
#define IMX415_NUM_CLK_PARAM_REGS 11
31
34
32
35
#define IMX415_REG_8BIT (n ) ((1 << 16) | (n))
59
62
#define IMX415_VMAX IMX415_REG_24BIT(0x3024)
60
63
#define IMX415_VMAX_MAX 0xfffff
61
64
#define IMX415_HMAX IMX415_REG_16BIT(0x3028)
65
+ #define IMX415_HMAX_MAX 0xffff
66
+ #define IMX415_HMAX_MULTIPLIER 12
62
67
#define IMX415_SHR0 IMX415_REG_24BIT(0x3050)
63
68
#define IMX415_GAIN_PCG_0 IMX415_REG_16BIT(0x3090)
64
69
#define IMX415_AGAIN_MIN 0
@@ -459,7 +464,6 @@ static const struct imx415_clk_params imx415_clk_params[] = {
459
464
460
465
/* all-pixel 2-lane 720 Mbps 15.74 Hz mode */
461
466
static const struct imx415_reg imx415_mode_2_720 [] = {
462
- { IMX415_HMAX , 0x07F0 },
463
467
{ IMX415_LANEMODE , IMX415_LANEMODE_2 },
464
468
{ IMX415_TCLKPOST , 0x006F },
465
469
{ IMX415_TCLKPREPARE , 0x002F },
@@ -474,7 +478,6 @@ static const struct imx415_reg imx415_mode_2_720[] = {
474
478
475
479
/* all-pixel 2-lane 1440 Mbps 30.01 Hz mode */
476
480
static const struct imx415_reg imx415_mode_2_1440 [] = {
477
- { IMX415_HMAX , 0x042A },
478
481
{ IMX415_LANEMODE , IMX415_LANEMODE_2 },
479
482
{ IMX415_TCLKPOST , 0x009F },
480
483
{ IMX415_TCLKPREPARE , 0x0057 },
@@ -489,7 +492,6 @@ static const struct imx415_reg imx415_mode_2_1440[] = {
489
492
490
493
/* all-pixel 4-lane 891 Mbps 30 Hz mode */
491
494
static const struct imx415_reg imx415_mode_4_891 [] = {
492
- { IMX415_HMAX , 0x044C },
493
495
{ IMX415_LANEMODE , IMX415_LANEMODE_4 },
494
496
{ IMX415_TCLKPOST , 0x007F },
495
497
{ IMX415_TCLKPREPARE , 0x0037 },
@@ -507,39 +509,10 @@ struct imx415_mode_reg_list {
507
509
const struct imx415_reg * regs ;
508
510
};
509
511
510
- /*
511
- * Mode : number of lanes, lane rate and frame rate dependent settings
512
- *
513
- * pixel_rate and hmax_pix are needed to calculate hblank for the v4l2 ctrl
514
- * interface. These values can not be found in the data sheet and should be
515
- * treated as virtual values. Use following table when adding new modes.
516
- *
517
- * lane_rate lanes fps hmax_pix pixel_rate
518
- *
519
- * 594 2 10.000 4400 99000000
520
- * 891 2 15.000 4400 148500000
521
- * 720 2 15.748 4064 144000000
522
- * 1782 2 30.000 4400 297000000
523
- * 2079 2 30.000 4400 297000000
524
- * 1440 2 30.019 4510 304615385
525
- *
526
- * 594 4 20.000 5500 247500000
527
- * 594 4 25.000 4400 247500000
528
- * 720 4 25.000 4400 247500000
529
- * 720 4 30.019 4510 304615385
530
- * 891 4 30.000 4400 297000000
531
- * 1440 4 30.019 4510 304615385
532
- * 1440 4 60.038 4510 609230769
533
- * 1485 4 60.000 4400 594000000
534
- * 1782 4 60.000 4400 594000000
535
- * 2079 4 60.000 4400 594000000
536
- * 2376 4 90.164 4392 891000000
537
- */
538
512
struct imx415_mode {
539
513
u64 lane_rate ;
540
514
u32 lanes ;
541
- u32 hmax_pix ;
542
- u64 pixel_rate ;
515
+ u32 hmax_min ;
543
516
struct imx415_mode_reg_list reg_list ;
544
517
};
545
518
@@ -548,8 +521,7 @@ static const struct imx415_mode supported_modes[] = {
548
521
{
549
522
.lane_rate = 720000000 ,
550
523
.lanes = 2 ,
551
- .hmax_pix = 4064 ,
552
- .pixel_rate = 144000000 ,
524
+ .hmax_min = 2032 ,
553
525
.reg_list = {
554
526
.num_of_regs = ARRAY_SIZE (imx415_mode_2_720 ),
555
527
.regs = imx415_mode_2_720 ,
@@ -558,8 +530,7 @@ static const struct imx415_mode supported_modes[] = {
558
530
{
559
531
.lane_rate = 1440000000 ,
560
532
.lanes = 2 ,
561
- .hmax_pix = 4510 ,
562
- .pixel_rate = 304615385 ,
533
+ .hmax_min = 1066 ,
563
534
.reg_list = {
564
535
.num_of_regs = ARRAY_SIZE (imx415_mode_2_1440 ),
565
536
.regs = imx415_mode_2_1440 ,
@@ -568,8 +539,7 @@ static const struct imx415_mode supported_modes[] = {
568
539
{
569
540
.lane_rate = 891000000 ,
570
541
.lanes = 4 ,
571
- .hmax_pix = 4400 ,
572
- .pixel_rate = 297000000 ,
542
+ .hmax_min = 1100 ,
573
543
.reg_list = {
574
544
.num_of_regs = ARRAY_SIZE (imx415_mode_4_891 ),
575
545
.regs = imx415_mode_4_891 ,
@@ -601,6 +571,7 @@ static const char *const imx415_test_pattern_menu[] = {
601
571
struct imx415 {
602
572
struct device * dev ;
603
573
struct clk * clk ;
574
+ unsigned long pixel_rate ;
604
575
struct regulator_bulk_data supplies [ARRAY_SIZE (imx415_supply_names )];
605
576
struct gpio_desc * reset ;
606
577
struct regmap * regmap ;
@@ -614,6 +585,7 @@ struct imx415 {
614
585
615
586
struct v4l2_ctrl_handler ctrls ;
616
587
struct v4l2_ctrl * vblank ;
588
+ struct v4l2_ctrl * hblank ;
617
589
struct v4l2_ctrl * hflip ;
618
590
struct v4l2_ctrl * vflip ;
619
591
struct v4l2_ctrl * exposure ;
@@ -845,6 +817,11 @@ static int imx415_s_ctrl(struct v4l2_ctrl *ctrl)
845
817
case V4L2_CID_TEST_PATTERN :
846
818
return imx415_set_testpattern (sensor , ctrl -> val );
847
819
820
+ case V4L2_CID_HBLANK :
821
+ return imx415_write (sensor , IMX415_HMAX ,
822
+ (format -> width + ctrl -> val ) /
823
+ IMX415_HMAX_MULTIPLIER );
824
+
848
825
default :
849
826
return - EINVAL ;
850
827
}
@@ -858,12 +835,11 @@ static int imx415_ctrls_init(struct imx415 *sensor)
858
835
{
859
836
struct v4l2_fwnode_device_properties props ;
860
837
struct v4l2_ctrl * ctrl ;
861
- u64 pixel_rate = supported_modes [sensor -> cur_mode ].pixel_rate ;
862
838
u64 lane_rate = supported_modes [sensor -> cur_mode ].lane_rate ;
863
839
u32 exposure_max = IMX415_PIXEL_ARRAY_HEIGHT +
864
840
IMX415_PIXEL_ARRAY_VBLANK -
865
841
IMX415_EXPOSURE_OFFSET ;
866
- u32 hblank ;
842
+ u32 hblank_min , hblank_max ;
867
843
unsigned int i ;
868
844
int ret ;
869
845
@@ -900,21 +876,24 @@ static int imx415_ctrls_init(struct imx415 *sensor)
900
876
IMX415_AGAIN_MAX , IMX415_AGAIN_STEP ,
901
877
IMX415_AGAIN_MIN );
902
878
903
- hblank = supported_modes [sensor -> cur_mode ].hmax_pix -
904
- IMX415_PIXEL_ARRAY_WIDTH ;
879
+ hblank_min = (supported_modes [sensor -> cur_mode ].hmax_min *
880
+ IMX415_HMAX_MULTIPLIER ) - IMX415_PIXEL_ARRAY_WIDTH ;
881
+ hblank_max = (IMX415_HMAX_MAX * IMX415_HMAX_MULTIPLIER ) -
882
+ IMX415_PIXEL_ARRAY_WIDTH ;
905
883
ctrl = v4l2_ctrl_new_std (& sensor -> ctrls , & imx415_ctrl_ops ,
906
- V4L2_CID_HBLANK , hblank , hblank , 1 , hblank );
907
- if ( ctrl )
908
- ctrl -> flags |= V4L2_CTRL_FLAG_READ_ONLY ;
884
+ V4L2_CID_HBLANK , hblank_min ,
885
+ hblank_max , IMX415_HMAX_MULTIPLIER ,
886
+ hblank_min ) ;
909
887
910
888
sensor -> vblank = v4l2_ctrl_new_std (& sensor -> ctrls , & imx415_ctrl_ops ,
911
889
V4L2_CID_VBLANK ,
912
890
IMX415_PIXEL_ARRAY_VBLANK ,
913
891
IMX415_VMAX_MAX - IMX415_PIXEL_ARRAY_HEIGHT ,
914
892
1 , IMX415_PIXEL_ARRAY_VBLANK );
915
893
916
- v4l2_ctrl_new_std (& sensor -> ctrls , NULL , V4L2_CID_PIXEL_RATE , pixel_rate ,
917
- pixel_rate , 1 , pixel_rate );
894
+ v4l2_ctrl_new_std (& sensor -> ctrls , NULL , V4L2_CID_PIXEL_RATE ,
895
+ sensor -> pixel_rate , sensor -> pixel_rate , 1 ,
896
+ sensor -> pixel_rate );
918
897
919
898
sensor -> hflip = v4l2_ctrl_new_std (& sensor -> ctrls , & imx415_ctrl_ops ,
920
899
V4L2_CID_HFLIP , 0 , 1 , 1 , 0 );
@@ -1410,6 +1389,17 @@ static int imx415_parse_hw_config(struct imx415 *sensor)
1410
1389
"no valid sensor mode defined\n" );
1411
1390
goto done_endpoint_free ;
1412
1391
}
1392
+ switch (inck ) {
1393
+ case 27000000 :
1394
+ case 37125000 :
1395
+ case 74250000 :
1396
+ sensor -> pixel_rate = IMX415_PIXEL_RATE_74_25MHZ ;
1397
+ break ;
1398
+ case 24000000 :
1399
+ case 72000000 :
1400
+ sensor -> pixel_rate = IMX415_PIXEL_RATE_72MHZ ;
1401
+ break ;
1402
+ }
1413
1403
1414
1404
lane_rate = supported_modes [sensor -> cur_mode ].lane_rate ;
1415
1405
for (i = 0 ; i < ARRAY_SIZE (imx415_clk_params ); ++ i ) {
0 commit comments