1 From 0292614f8cd061f71f975dae7d74fe5324545321 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Thu, 2 Jan 2025 12:43:01 +0000
4 Subject: [PATCH] media: i2c: imx415: Link frequencies are not exclusive to num
7 The link frequencies are equally valid in 2 or 4 lane modes, but
8 they change the hmax_min value for the mode as the MIPI block
9 has to have sufficient time to send the pixel data for each line.
11 Remove the association with number of lanes, and add hmax_min
12 configuration for both lane options.
14 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
16 drivers/media/i2c/imx415.c | 49 +++++++++++++++++---------------------
17 1 file changed, 22 insertions(+), 27 deletions(-)
19 --- a/drivers/media/i2c/imx415.c
20 +++ b/drivers/media/i2c/imx415.c
21 @@ -462,9 +462,8 @@ static const struct imx415_clk_params im
25 -/* all-pixel 2-lane 720 Mbps 15.74 Hz mode */
26 -static const struct imx415_reg imx415_mode_2_720[] = {
27 - { IMX415_LANEMODE, IMX415_LANEMODE_2 },
28 +/* 720 Mbps CSI configuration */
29 +static const struct imx415_reg imx415_linkrate_720mbps[] = {
30 { IMX415_TCLKPOST, 0x006F },
31 { IMX415_TCLKPREPARE, 0x002F },
32 { IMX415_TCLKTRAIL, 0x002F },
33 @@ -476,9 +475,8 @@ static const struct imx415_reg imx415_mo
34 { IMX415_TLPX, 0x0027 },
37 -/* all-pixel 2-lane 1440 Mbps 30.01 Hz mode */
38 -static const struct imx415_reg imx415_mode_2_1440[] = {
39 - { IMX415_LANEMODE, IMX415_LANEMODE_2 },
40 +/* 1440 Mbps CSI configuration */
41 +static const struct imx415_reg imx415_linkrate_1440mbps[] = {
42 { IMX415_TCLKPOST, 0x009F },
43 { IMX415_TCLKPREPARE, 0x0057 },
44 { IMX415_TCLKTRAIL, 0x0057 },
45 @@ -490,9 +488,8 @@ static const struct imx415_reg imx415_mo
46 { IMX415_TLPX, 0x004F },
49 -/* all-pixel 4-lane 891 Mbps 30 Hz mode */
50 -static const struct imx415_reg imx415_mode_4_891[] = {
51 - { IMX415_LANEMODE, IMX415_LANEMODE_4 },
53 +static const struct imx415_reg imx415_linkrate_891mbps[] = {
54 { IMX415_TCLKPOST, 0x007F },
55 { IMX415_TCLKPREPARE, 0x0037 },
56 { IMX415_TCLKTRAIL, 0x0037 },
57 @@ -511,8 +508,7 @@ struct imx415_mode_reg_list {
64 struct imx415_mode_reg_list reg_list;
67 @@ -520,29 +516,26 @@ struct imx415_mode {
68 static const struct imx415_mode supported_modes[] = {
70 .lane_rate = 720000000,
73 + .hmax_min = { 2032, 1066 },
75 - .num_of_regs = ARRAY_SIZE(imx415_mode_2_720),
76 - .regs = imx415_mode_2_720,
77 + .num_of_regs = ARRAY_SIZE(imx415_linkrate_720mbps),
78 + .regs = imx415_linkrate_720mbps,
82 .lane_rate = 1440000000,
85 + .hmax_min = { 1066, 533 },
87 - .num_of_regs = ARRAY_SIZE(imx415_mode_2_1440),
88 - .regs = imx415_mode_2_1440,
89 + .num_of_regs = ARRAY_SIZE(imx415_linkrate_1440mbps),
90 + .regs = imx415_linkrate_1440mbps,
94 .lane_rate = 891000000,
97 + .hmax_min = { 1100, 550 },
99 - .num_of_regs = ARRAY_SIZE(imx415_mode_4_891),
100 - .regs = imx415_mode_4_891,
101 + .num_of_regs = ARRAY_SIZE(imx415_linkrate_891mbps),
102 + .regs = imx415_linkrate_891mbps,
106 @@ -876,7 +869,7 @@ static int imx415_ctrls_init(struct imx4
107 IMX415_AGAIN_MAX, IMX415_AGAIN_STEP,
110 - hblank_min = (supported_modes[sensor->cur_mode].hmax_min *
111 + hblank_min = (supported_modes[sensor->cur_mode].hmax_min[sensor->num_data_lanes == 2 ? 0 : 1] *
112 IMX415_HMAX_MULTIPLIER) - IMX415_PIXEL_ARRAY_WIDTH;
113 hblank_max = (IMX415_HMAX_MAX * IMX415_HMAX_MULTIPLIER) -
114 IMX415_PIXEL_ARRAY_WIDTH;
115 @@ -944,7 +937,11 @@ static int imx415_set_mode(struct imx415
120 + ret = imx415_write(sensor, IMX415_LANEMODE,
121 + sensor->num_data_lanes == 2 ? IMX415_LANEMODE_2 :
122 + IMX415_LANEMODE_4);
127 static int imx415_setup(struct imx415 *sensor, struct v4l2_subdev_state *state)
128 @@ -1373,8 +1370,6 @@ static int imx415_parse_hw_config(struct
131 for (j = 0; j < ARRAY_SIZE(supported_modes); ++j) {
132 - if (sensor->num_data_lanes != supported_modes[j].lanes)
134 if (bus_cfg.link_frequencies[i] * 2 !=
135 supported_modes[j].lane_rate)