Skip to contentSkip to conversation

media: i2c: imx415: Add get_mbus_config() pad operation support

PATCH In review Alexander Shiyan 4 participants 13 messages Feb 19, 2025 – Feb 25, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 media: i2c: imx415: Add get_mbus_config() pad operation support

Allow the driver to report static media bus configuration using pad get_mbus_config() operation.

---
 drivers/media/i2c/imx415.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/media/i2c/imx415.c +13 -0
index 9f37779bd611..16a52900c61c 100644
@@ -1076,6 +1076,18 @@ static int imx415_init_state(struct v4l2_subdev *sd,
 	return 0;
 }
 
+static int imx415_get_mbus_config(struct v4l2_subdev *sd, unsigned int pad_id,
+				  struct v4l2_mbus_config *config)
+{
+	struct imx415 *sensor = to_imx415(sd);
+
+	config->type = V4L2_MBUS_CSI2_DPHY;
+	config->bus.mipi_csi2.flags = 0;
+	config->bus.mipi_csi2.num_data_lanes = sensor->num_data_lanes;
+
+	return 0;
+}
+
 static const struct v4l2_subdev_video_ops imx415_subdev_video_ops = {
 	.s_stream = imx415_s_stream,
 };
@@ -1086,6 +1098,7 @@ static const struct v4l2_subdev_pad_ops imx415_subdev_pad_ops = {
 	.get_fmt = v4l2_subdev_get_fmt,
 	.set_fmt = imx415_set_format,
 	.get_selection = imx415_get_selection,
+	.get_mbus_config = imx415_get_mbus_config,
 };
 
 static const struct v4l2_subdev_ops imx415_subdev_ops = {
Signature · 1 line
2.39.1
#1 lore raw

PATCH 2/4 media: i2c: imx415: Add missing ADBIT1 register for setup output format

The imx415 sensor has one more register for setting the output format (10/12 bit), which is currently not in the driver. The patch adds it.

---
 drivers/media/i2c/imx415.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/i2c/imx415.c +2 -0
index 16a52900c61c..c5beba4da18b 100644
@@ -77,6 +77,7 @@
 #define IMX415_INCKSEL5		  CCI_REG8(0x311e)
 #define IMX415_DIG_CLP_MODE	  CCI_REG8(0x32c8)
 #define IMX415_WRJ_OPEN		  CCI_REG8(0x3390)
+#define IMX415_ADBIT1		  CCI_REG8(0x3701)
 #define IMX415_SENSOR_INFO	  CCI_REG16_LE(0x3f12)
 #define IMX415_SENSOR_INFO_MASK	  0xfff
 #define IMX415_CHIP_ID		  0x514
@@ -581,6 +582,7 @@ static const struct cci_reg_sequence imx415_init_table[] = {
 	{ IMX415_REVERSE, 0x00 },
 	/* use RAW 10-bit mode */
 	{ IMX415_ADBIT, 0x00 },
+	{ IMX415_ADBIT1, 0x00 },
 	{ IMX415_MDBIT, 0x00 },
 	/* output VSYNC on XVS and low on XHS */
 	{ IMX415_OUTSEL, 0x22 },
Signature · 1 line
2.39.1
#2 lore raw

Re: [PATCH 2/4] media: i2c: imx415: Add missing ADBIT1 register for setup output format

Hi Alexander

Quoted 3 lines · Alexander Shiyan

The imx415 sensor has one more register for setting the output format (10/12 bit), which is currently not in the driver.

The datasheet states it is the "internal A/D conversion bits" setting, not output format.
Output format is set via MDBIT (reg 0x3032).

The sensor may well happily truncate 12bit A/D readout to RAW10 output, or left shift 10bit A/D values to RAW12 output.

I'll defer to Wolfvision on this one as I would expect them as the original authors to have been given a register list by Sony for the readout modes that they were interested in. Sony may therefore have recommended this apparent mismatch in A/D depth vs output format.

Dave

Quoted 31 lines

The patch adds it.

---
 drivers/media/i2c/imx415.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/i2c/imx415.c +2 -1
index 16a52900c61c..c5beba4da18b 100644
@@ -77,6 +77,7 @@
 #define IMX415_INCKSEL5                  CCI_REG8(0x311e)
 #define IMX415_DIG_CLP_MODE      CCI_REG8(0x32c8)
 #define IMX415_WRJ_OPEN                  CCI_REG8(0x3390)
+#define IMX415_ADBIT1            CCI_REG8(0x3701)
 #define IMX415_SENSOR_INFO       CCI_REG16_LE(0x3f12)
 #define IMX415_SENSOR_INFO_MASK          0xfff
 #define IMX415_CHIP_ID           0x514
@@ -581,6 +582,7 @@ static const struct cci_reg_sequence imx415_init_table[] = {
        { IMX415_REVERSE, 0x00 },
        /* use RAW 10-bit mode */
        { IMX415_ADBIT, 0x00 },
+       { IMX415_ADBIT1, 0x00 },
        { IMX415_MDBIT, 0x00 },
        /* output VSYNC on XVS and low on XHS */
        { IMX415_OUTSEL, 0x22 },
--

2.39.1

#3 lore raw

Re: [PATCH 2/4] media: i2c: imx415: Add missing ADBIT1 register for setup output format

Hello Dave.

Quoted 7 lines
Quoted 2 lines

The imx415 sensor has one more register for setting the output format (10/12 bit), which is currently not in the driver.

The datasheet states it is the "internal A/D conversion bits" setting, not output format.
Output format is set via MDBIT (reg 0x3032).

Quoted 7 lines

The sensor may well happily truncate 12bit A/D readout to RAW10 output, or left shift 10bit A/D values to RAW12 output.

I'll defer to Wolfvision on this one as I would expect them as the original authors to have been given a register list by Sony for the readout modes that they were interested in. Sony may therefore have recommended this apparent mismatch in A/D depth vs output format.

As far as I can see from the datasheet, the "Operating mode" table (page 48) clearly states that the AS-conversion and output bit width values are equal.

Thanks!

#4 lore raw

Re: [PATCH 2/4] media: i2c: imx415: Add missing ADBIT1 register for setup output format

Hi Alexander, Dave,

Quoted 16 lines · Alexander Shiyan

Hello Dave.

Quoted 14 lines
Quoted 2 lines

The imx415 sensor has one more register for setting the output format (10/12 bit), which is currently not in the driver.

The datasheet states it is the "internal A/D conversion bits" setting, not output format.
Output format is set via MDBIT (reg 0x3032).

The sensor may well happily truncate 12bit A/D readout to RAW10 output, or left shift 10bit A/D values to RAW12 output.

I'll defer to Wolfvision on this one as I would expect them as the original authors to have been given a register list by Sony for the readout modes that they were interested in. Sony may therefore have recommended this apparent mismatch in A/D depth vs output format.

Cc Gerald who is already looking into this

As far as I can gather, the register is not crucial for the correct operation. The chip works fine for us with the current driver and ADBIT1 is not mentioned in the register lists for the different modes.

However, we have successfully set the register in a different project (MCU + IMX415).

The patch may not be essential, but it is clearly correct IMHO.

Best regards,
Michael

Quoted 5 lines

As far as I can see from the datasheet, the "Operating mode" table (page 48) clearly states that the AS-conversion and output bit width values are equal.

Thanks!

Reviewed-by Tested-by
#5 lore raw

Re: [PATCH 2/4] media: i2c: imx415: Add missing ADBIT1 register for setup output format

Hi Alexander,

Quoted 33 lines

-----Ursprüngliche Nachricht-----
Von: Michael Riesch <[email protected]>
Gesendet: Dienstag, 25. Februar 2025 09:44
An: Alexander Shiyan <[email protected]>; Dave Stevenson <[email protected]>
Cc: [email protected]; Sakari Ailus <[email protected]>; Mauro Carvalho Chehab <[email protected]>; Gerald Loacker <[email protected]>
Betreff: Re: [PATCH 2/4] media: i2c: imx415: Add missing ADBIT1 register for setup output format

Hi Alexander, Dave,

Quoted 16 lines · Alexander Shiyan

Hello Dave.

Quoted 14 lines
Quoted 2 lines

The imx415 sensor has one more register for setting the output format (10/12 bit), which is currently not in the driver.

The datasheet states it is the "internal A/D conversion bits" setting, not output format.
Output format is set via MDBIT (reg 0x3032).

The sensor may well happily truncate 12bit A/D readout to RAW10 output, or left shift 10bit A/D values to RAW12 output.

I'll defer to Wolfvision on this one as I would expect them as the original authors to have been given a register list by Sony for the readout modes that they were interested in. Sony may therefore have recommended this apparent mismatch in A/D depth vs output format.

Cc Gerald who is already looking into this
Quoted 9 lines

As far as I can gather, the register is not crucial for the correct operation. The chip works fine for us with the current driver and ADBIT1 is not mentioned in the register lists for the different modes.

However, we have successfully set the register in a different project (MCU + IMX415).

The patch may not be essential, but it is clearly correct IMHO.

It's correct that this register needs to be set to zero for 10-bit operation according to the datasheet, although there are no visible differences.

Best regards,
Gerald

Quoted 8 lines

Best regards,
Michael

Quoted 5 lines

As far as I can see from the datasheet, the "Operating mode" table (page 48) clearly states that the AS-conversion and output bit width values are equal.

Thanks!

Reviewed-by on v1 2/4
#6 lore raw

Re: [PATCH 2/4] media: i2c: imx415: Add missing ADBIT1 register for setup output format

In reply to Alexander Shiyan

Hi Alexander,

Quoted 3 lines · Alexander Shiyan

The imx415 sensor has one more register for setting the output format (10/12 bit), which is currently not in the driver. The patch adds it.

the Fixes: tag may be justified here.

Quoted 1 line

Thanks and best regards,
Michael

Quoted 24 lines
---
 drivers/media/i2c/imx415.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/i2c/imx415.c +2 -0
index 16a52900c61c..c5beba4da18b 100644
@@ -77,6 +77,7 @@
 #define IMX415_INCKSEL5		  CCI_REG8(0x311e)
 #define IMX415_DIG_CLP_MODE	  CCI_REG8(0x32c8)
 #define IMX415_WRJ_OPEN		  CCI_REG8(0x3390)
+#define IMX415_ADBIT1		  CCI_REG8(0x3701)
 #define IMX415_SENSOR_INFO	  CCI_REG16_LE(0x3f12)
 #define IMX415_SENSOR_INFO_MASK	  0xfff
 #define IMX415_CHIP_ID		  0x514
@@ -581,6 +582,7 @@ static const struct cci_reg_sequence imx415_init_table[] = {
 	{ IMX415_REVERSE, 0x00 },
 	/* use RAW 10-bit mode */
 	{ IMX415_ADBIT, 0x00 },
+	{ IMX415_ADBIT1, 0x00 },
 	{ IMX415_MDBIT, 0x00 },
 	/* output VSYNC on XVS and low on XHS */
 	{ IMX415_OUTSEL, 0x22 },
#7 lore raw

PATCH 3/4 media: i2c: imx415: Add missing CSI configurations

In reply to Alexander Shiyan

Currently, not all variants for different lane rates are handled in the driver. This patch fills in the remaining possible CSI configurations for 2-lane mode.

---
 drivers/media/i2c/imx415.c | 97 +++++++++++++++++++++++++++++++-------
 1 file changed, 80 insertions(+), 17 deletions(-)
drivers/media/i2c/imx415.c +80 -17
index c5beba4da18b..83b7929455b2 100644
@@ -109,8 +109,8 @@ static const char *const imx415_supply_names[] = {
  * and converts them to link frequencies by a factor of two when needed.
  */
 static const s64 link_freq_menu_items[] = {
-	594000000 / 2,	720000000 / 2,	891000000 / 2,
-	1440000000 / 2, 1485000000 / 2,
+	594000000 / 2,	720000000 / 2,	891000000 / 2,	1440000000 / 2,
+	1485000000 / 2,	1782000000 / 2,	2079000000 / 2,	2376000000 / 2,
 };
 
 struct imx415_clk_params {
@@ -453,6 +453,19 @@ static const struct imx415_clk_params imx415_clk_params[] = {
 	},
 };
 
+/* 594 Mbps CSI configuration */
+static const struct cci_reg_sequence imx415_linkrate_594mbps[] = {
+	{ IMX415_TCLKPOST, 0x0067 },
+	{ IMX415_TCLKPREPARE, 0x0027 },
+	{ IMX415_TCLKTRAIL, 0x0027 },
+	{ IMX415_TCLKZERO, 0x00B7 },
+	{ IMX415_THSPREPARE, 0x002F },
+	{ IMX415_THSZERO, 0x004F },
+	{ IMX415_THSTRAIL, 0x002F },
+	{ IMX415_THSEXIT, 0x0047 },
+	{ IMX415_TLPX, 0x0027 },
+};
+
 /* 720 Mbps CSI configuration */
 static const struct cci_reg_sequence imx415_linkrate_720mbps[] = {
 	{ IMX415_TCLKPOST, 0x006F },
@@ -466,6 +479,19 @@ static const struct cci_reg_sequence imx415_linkrate_720mbps[] = {
 	{ IMX415_TLPX, 0x0027 },
 };
 
+/* 891 Mbps CSI configuration */
+static const struct cci_reg_sequence imx415_linkrate_891mbps[] = {
+	{ IMX415_TCLKPOST, 0x007F },
+	{ IMX415_TCLKPREPARE, 0x0037 },
+	{ IMX415_TCLKTRAIL, 0x0037 },
+	{ IMX415_TCLKZERO, 0x00F7 },
+	{ IMX415_THSPREPARE, 0x003F },
+	{ IMX415_THSZERO, 0x006F },
+	{ IMX415_THSTRAIL, 0x003F },
+	{ IMX415_THSEXIT, 0x005F },
+	{ IMX415_TLPX, 0x002F },
+};
+
 /* 1440 Mbps CSI configuration */
 static const struct cci_reg_sequence imx415_linkrate_1440mbps[] = {
 	{ IMX415_TCLKPOST, 0x009F },
@@ -479,17 +505,30 @@ static const struct cci_reg_sequence imx415_linkrate_1440mbps[] = {
 	{ IMX415_TLPX, 0x004F },
 };
 
-/* 891 Mbps CSI configuration */
-static const struct cci_reg_sequence imx415_linkrate_891mbps[] = {
-	{ IMX415_TCLKPOST, 0x007F },
-	{ IMX415_TCLKPREPARE, 0x0037 },
-	{ IMX415_TCLKTRAIL, 0x0037 },
-	{ IMX415_TCLKZERO, 0x00F7 },
-	{ IMX415_THSPREPARE, 0x003F },
-	{ IMX415_THSZERO, 0x006F },
-	{ IMX415_THSTRAIL, 0x003F },
-	{ IMX415_THSEXIT, 0x005F },
-	{ IMX415_TLPX, 0x002F },
+/* 1782 Mbps CSI configuration */
+static const struct cci_reg_sequence imx415_linkrate_1782mbps[] = {
+	{ IMX415_TCLKPOST, 0x00B7 },
+	{ IMX415_TCLKPREPARE, 0x0067 },
+	{ IMX415_TCLKTRAIL, 0x006F },
+	{ IMX415_TCLKZERO, 0x01DF },
+	{ IMX415_THSPREPARE, 0x006F },
+	{ IMX415_THSZERO, 0x00CF },
+	{ IMX415_THSTRAIL, 0x006F },
+	{ IMX415_THSEXIT, 0x00B7 },
+	{ IMX415_TLPX, 0x005F },
+};
+
+/* 2079 Mbps CSI configuration */
+static const struct cci_reg_sequence imx415_linkrate_2079mbps[] = {
+	{ IMX415_TCLKPOST, 0x00D7 },
+	{ IMX415_TCLKPREPARE, 0x007F },
+	{ IMX415_TCLKTRAIL, 0x007F },
+	{ IMX415_TCLKZERO, 0x0237 },
+	{ IMX415_THSPREPARE, 0x0087 },
+	{ IMX415_THSZERO, 0x00EF },
+	{ IMX415_THSTRAIL, 0x0087 },
+	{ IMX415_THSEXIT, 0x00DF },
+	{ IMX415_TLPX, 0x006F },
 };
 
 struct imx415_mode_reg_list {
@@ -505,6 +544,14 @@ struct imx415_mode {
 
 /* mode configs */
 static const struct imx415_mode supported_modes[] = {
+	{
+		.lane_rate = 594000000,
+		.hmax_min = { 3300, 1320 },
+		.reg_list = {
+			.num_of_regs = ARRAY_SIZE(imx415_linkrate_594mbps),
+			.regs = imx415_linkrate_594mbps,
+		},
+	},
 	{
 		.lane_rate = 720000000,
 		.hmax_min = { 2032, 1066 },
@@ -513,6 +560,14 @@ static const struct imx415_mode supported_modes[] = {
 			.regs = imx415_linkrate_720mbps,
 		},
 	},
+	{
+		.lane_rate = 891000000,
+		.hmax_min = { 2200, 1100 },
+		.reg_list = {
+			.num_of_regs = ARRAY_SIZE(imx415_linkrate_891mbps),
+			.regs = imx415_linkrate_891mbps,
+		},
+	},
 	{
 		.lane_rate = 1440000000,
 		.hmax_min = { 1066, 533 },
@@ -522,11 +577,19 @@ static const struct imx415_mode supported_modes[] = {
 		},
 	},
 	{
-		.lane_rate = 891000000,
-		.hmax_min = { 2200, 1100 },
+		.lane_rate = 1782000000,
+		.hmax_min = { 1100, 550 },
 		.reg_list = {
-			.num_of_regs = ARRAY_SIZE(imx415_linkrate_891mbps),
-			.regs = imx415_linkrate_891mbps,
+			.num_of_regs = ARRAY_SIZE(imx415_linkrate_1782mbps),
+			.regs = imx415_linkrate_1782mbps,
+		},
+	},
+	{
+		.lane_rate = 2079000000,
+		.hmax_min = { 1100, 550 },
+		.reg_list = {
+			.num_of_regs = ARRAY_SIZE(imx415_linkrate_2079mbps),
+			.regs = imx415_linkrate_2079mbps,
 		},
 	},
 };
Signature · 1 line
2.39.1
Reviewed-by on v1 3/4
#8 lore raw

Re: [PATCH 3/4] media: i2c: imx415: Add missing CSI configurations

Hi Alexander

Quoted 3 lines · Alexander Shiyan

Currently, not all variants for different lane rates are handled in the driver. This patch fills in the remaining possible CSI configurations for 2-lane mode.

This patch fills in the remaining CSI configurations supported in both 2 and 4 lane modes.

Otherwise I've checked the register settings against the datasheet I have, and they all appear to match.

Quoted 161 lines
---
 drivers/media/i2c/imx415.c | 97 +++++++++++++++++++++++++++++++-------
 1 file changed, 80 insertions(+), 17 deletions(-)
drivers/media/i2c/imx415.c +80 -18
index c5beba4da18b..83b7929455b2 100644
@@ -109,8 +109,8 @@ static const char *const imx415_supply_names[] = {
  * and converts them to link frequencies by a factor of two when needed.
  */
 static const s64 link_freq_menu_items[] = {
-       594000000 / 2,  720000000 / 2,  891000000 / 2,
-       1440000000 / 2, 1485000000 / 2,
+       594000000 / 2,  720000000 / 2,  891000000 / 2,  1440000000 / 2,
+       1485000000 / 2, 1782000000 / 2, 2079000000 / 2, 2376000000 / 2,
 };
 
 struct imx415_clk_params {
@@ -453,6 +453,19 @@ static const struct imx415_clk_params imx415_clk_params[] = {
        },
 };
 
+/* 594 Mbps CSI configuration */
+static const struct cci_reg_sequence imx415_linkrate_594mbps[] = {
+       { IMX415_TCLKPOST, 0x0067 },
+       { IMX415_TCLKPREPARE, 0x0027 },
+       { IMX415_TCLKTRAIL, 0x0027 },
+       { IMX415_TCLKZERO, 0x00B7 },
+       { IMX415_THSPREPARE, 0x002F },
+       { IMX415_THSZERO, 0x004F },
+       { IMX415_THSTRAIL, 0x002F },
+       { IMX415_THSEXIT, 0x0047 },
+       { IMX415_TLPX, 0x0027 },
+};
+
 /* 720 Mbps CSI configuration */
 static const struct cci_reg_sequence imx415_linkrate_720mbps[] = {
        { IMX415_TCLKPOST, 0x006F },
@@ -466,6 +479,19 @@ static const struct cci_reg_sequence imx415_linkrate_720mbps[] = {
        { IMX415_TLPX, 0x0027 },
 };
 
+/* 891 Mbps CSI configuration */
+static const struct cci_reg_sequence imx415_linkrate_891mbps[] = {
+       { IMX415_TCLKPOST, 0x007F },
+       { IMX415_TCLKPREPARE, 0x0037 },
+       { IMX415_TCLKTRAIL, 0x0037 },
+       { IMX415_TCLKZERO, 0x00F7 },
+       { IMX415_THSPREPARE, 0x003F },
+       { IMX415_THSZERO, 0x006F },
+       { IMX415_THSTRAIL, 0x003F },
+       { IMX415_THSEXIT, 0x005F },
+       { IMX415_TLPX, 0x002F },
+};
+
 /* 1440 Mbps CSI configuration */
 static const struct cci_reg_sequence imx415_linkrate_1440mbps[] = {
        { IMX415_TCLKPOST, 0x009F },
@@ -479,17 +505,30 @@ static const struct cci_reg_sequence imx415_linkrate_1440mbps[] = {
        { IMX415_TLPX, 0x004F },
 };
 
-/* 891 Mbps CSI configuration */
-static const struct cci_reg_sequence imx415_linkrate_891mbps[] = {
-       { IMX415_TCLKPOST, 0x007F },
-       { IMX415_TCLKPREPARE, 0x0037 },
-       { IMX415_TCLKTRAIL, 0x0037 },
-       { IMX415_TCLKZERO, 0x00F7 },
-       { IMX415_THSPREPARE, 0x003F },
-       { IMX415_THSZERO, 0x006F },
-       { IMX415_THSTRAIL, 0x003F },
-       { IMX415_THSEXIT, 0x005F },
-       { IMX415_TLPX, 0x002F },
+/* 1782 Mbps CSI configuration */
+static const struct cci_reg_sequence imx415_linkrate_1782mbps[] = {
+       { IMX415_TCLKPOST, 0x00B7 },
+       { IMX415_TCLKPREPARE, 0x0067 },
+       { IMX415_TCLKTRAIL, 0x006F },
+       { IMX415_TCLKZERO, 0x01DF },
+       { IMX415_THSPREPARE, 0x006F },
+       { IMX415_THSZERO, 0x00CF },
+       { IMX415_THSTRAIL, 0x006F },
+       { IMX415_THSEXIT, 0x00B7 },
+       { IMX415_TLPX, 0x005F },
+};
+
+/* 2079 Mbps CSI configuration */
+static const struct cci_reg_sequence imx415_linkrate_2079mbps[] = {
+       { IMX415_TCLKPOST, 0x00D7 },
+       { IMX415_TCLKPREPARE, 0x007F },
+       { IMX415_TCLKTRAIL, 0x007F },
+       { IMX415_TCLKZERO, 0x0237 },
+       { IMX415_THSPREPARE, 0x0087 },
+       { IMX415_THSZERO, 0x00EF },
+       { IMX415_THSTRAIL, 0x0087 },
+       { IMX415_THSEXIT, 0x00DF },
+       { IMX415_TLPX, 0x006F },
 };
 
 struct imx415_mode_reg_list {
@@ -505,6 +544,14 @@ struct imx415_mode {
 
 /* mode configs */
 static const struct imx415_mode supported_modes[] = {
+       {
+               .lane_rate = 594000000,
+               .hmax_min = { 3300, 1320 },
+               .reg_list = {
+                       .num_of_regs = ARRAY_SIZE(imx415_linkrate_594mbps),
+                       .regs = imx415_linkrate_594mbps,
+               },
+       },
        {
                .lane_rate = 720000000,
                .hmax_min = { 2032, 1066 },
@@ -513,6 +560,14 @@ static const struct imx415_mode supported_modes[] = {
                        .regs = imx415_linkrate_720mbps,
                },
        },
+       {
+               .lane_rate = 891000000,
+               .hmax_min = { 2200, 1100 },
+               .reg_list = {
+                       .num_of_regs = ARRAY_SIZE(imx415_linkrate_891mbps),
+                       .regs = imx415_linkrate_891mbps,
+               },
+       },
        {
                .lane_rate = 1440000000,
                .hmax_min = { 1066, 533 },
@@ -522,11 +577,19 @@ static const struct imx415_mode supported_modes[] = {
                },
        },
        {
-               .lane_rate = 891000000,
-               .hmax_min = { 2200, 1100 },
+               .lane_rate = 1782000000,
+               .hmax_min = { 1100, 550 },
                .reg_list = {
-                       .num_of_regs = ARRAY_SIZE(imx415_linkrate_891mbps),
-                       .regs = imx415_linkrate_891mbps,
+                       .num_of_regs = ARRAY_SIZE(imx415_linkrate_1782mbps),
+                       .regs = imx415_linkrate_1782mbps,
+               },
+       },
+       {
+               .lane_rate = 2079000000,
+               .hmax_min = { 1100, 550 },
+               .reg_list = {
+                       .num_of_regs = ARRAY_SIZE(imx415_linkrate_2079mbps),
+                       .regs = imx415_linkrate_2079mbps,
                },
        },
 };
--

2.39.1

#9 lore raw

PATCH 4/4 media: i2c: imx415: Add missing 4-lane CSI configurations

In reply to Alexander Shiyan

Not all CSI configurations are suitable for both 2-lane and 4-lane mode. To solve this, let's use a zero value in the hmax_min[] field of the supported_modes[] structure to indicate which CSI configuration can not be used for 2-lane or 4-lane mode.
Now that we have done that, let's add the remaining CSI configurations that can be used for 4-lane mode.

---
 drivers/media/i2c/imx415.c | 46 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
drivers/media/i2c/imx415.c +46 -0
index 83b7929455b2..5f18d3f38ded 100644
@@ -505,6 +505,19 @@ static const struct cci_reg_sequence imx415_linkrate_1440mbps[] = {
 	{ IMX415_TLPX, 0x004F },
 };
 
+/* 1485 Mbps CSI configuration */
+static const struct cci_reg_sequence imx415_linkrate_1485mbps[] = {
+	{ IMX415_TCLKPOST, 0x00A7 },
+	{ IMX415_TCLKPREPARE, 0x0057 },
+	{ IMX415_TCLKTRAIL, 0x005F },
+	{ IMX415_TCLKZERO, 0x0197 },
+	{ IMX415_THSPREPARE, 0x005F },
+	{ IMX415_THSZERO, 0x00AF },
+	{ IMX415_THSTRAIL, 0x005F },
+	{ IMX415_THSEXIT, 0x009F },
+	{ IMX415_TLPX, 0x004F },
+};
+
 /* 1782 Mbps CSI configuration */
 static const struct cci_reg_sequence imx415_linkrate_1782mbps[] = {
 	{ IMX415_TCLKPOST, 0x00B7 },
@@ -531,6 +544,19 @@ static const struct cci_reg_sequence imx415_linkrate_2079mbps[] = {
 	{ IMX415_TLPX, 0x006F },
 };
 
+/* 2376 Mbps CSI configuration */
+static const struct cci_reg_sequence imx415_linkrate_2376mbps[] = {
+	{ IMX415_TCLKPOST, 0x00E7 },
+	{ IMX415_TCLKPREPARE, 0x008F },
+	{ IMX415_TCLKTRAIL, 0x008F },
+	{ IMX415_TCLKZERO, 0x027F },
+	{ IMX415_THSPREPARE, 0x0097 },
+	{ IMX415_THSZERO, 0x010F },
+	{ IMX415_THSTRAIL, 0x0097 },
+	{ IMX415_THSEXIT, 0x00F7 },
+	{ IMX415_TLPX, 0x007F },
+};
+
 struct imx415_mode_reg_list {
 	u32 num_of_regs;
 	const struct cci_reg_sequence *regs;
@@ -576,6 +602,14 @@ static const struct imx415_mode supported_modes[] = {
 			.regs = imx415_linkrate_1440mbps,
 		},
 	},
+	{
+		.lane_rate = 1485000000,
+		.hmax_min = { 0, 550 },
+		.reg_list = {
+			.num_of_regs = ARRAY_SIZE(imx415_linkrate_1485mbps),
+			.regs = imx415_linkrate_1485mbps,
+		},
+	},
 	{
 		.lane_rate = 1782000000,
 		.hmax_min = { 1100, 550 },
@@ -592,6 +626,14 @@ static const struct imx415_mode supported_modes[] = {
 			.regs = imx415_linkrate_2079mbps,
 		},
 	},
+	{
+		.lane_rate = 2376000000,
+		.hmax_min = { 0, 366 },
+		.reg_list = {
+			.num_of_regs = ARRAY_SIZE(imx415_linkrate_2376mbps),
+			.regs = imx415_linkrate_2376mbps,
+		},
+	},
 };
 
 static const char *const imx415_test_pattern_menu[] = {
@@ -1375,9 +1417,13 @@ static int imx415_parse_hw_config(struct imx415 *sensor)
 		}
 
 		for (j = 0; j < ARRAY_SIZE(supported_modes); ++j) {
+			int lanes_idx = sensor->num_data_lanes == 2 ? 0 : 1;
+
 			if (bus_cfg.link_frequencies[i] * 2 !=
 			    supported_modes[j].lane_rate)
 				continue;
+			if (!supported_modes[j].hmax_min[lanes_idx])
+				continue;
 			sensor->cur_mode = j;
 			break;
 		}
Signature · 1 line
2.39.1
Reviewed-by on v1 4/4
#10 lore raw

Re: [PATCH 4/4] media: i2c: imx415: Add missing 4-lane CSI configurations

Hi Alexander

Quoted 88 lines · Alexander Shiyan

Not all CSI configurations are suitable for both 2-lane and 4-lane mode. To solve this, let's use a zero value in the hmax_min[] field of the supported_modes[] structure to indicate which CSI configuration can not be used for 2-lane or 4-lane mode.
Now that we have done that, let's add the remaining CSI configurations that can be used for 4-lane mode.

---
 drivers/media/i2c/imx415.c | 46 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
drivers/media/i2c/imx415.c +42 -0
index 83b7929455b2..5f18d3f38ded 100644
@@ -505,6 +505,19 @@ static const struct cci_reg_sequence imx415_linkrate_1440mbps[] = {
        { IMX415_TLPX, 0x004F },
 };
 
+/* 1485 Mbps CSI configuration */
+static const struct cci_reg_sequence imx415_linkrate_1485mbps[] = {
+       { IMX415_TCLKPOST, 0x00A7 },
+       { IMX415_TCLKPREPARE, 0x0057 },
+       { IMX415_TCLKTRAIL, 0x005F },
+       { IMX415_TCLKZERO, 0x0197 },
+       { IMX415_THSPREPARE, 0x005F },
+       { IMX415_THSZERO, 0x00AF },
+       { IMX415_THSTRAIL, 0x005F },
+       { IMX415_THSEXIT, 0x009F },
+       { IMX415_TLPX, 0x004F },
+};
+
 /* 1782 Mbps CSI configuration */
 static const struct cci_reg_sequence imx415_linkrate_1782mbps[] = {
        { IMX415_TCLKPOST, 0x00B7 },
@@ -531,6 +544,19 @@ static const struct cci_reg_sequence imx415_linkrate_2079mbps[] = {
        { IMX415_TLPX, 0x006F },
 };
 
+/* 2376 Mbps CSI configuration */
+static const struct cci_reg_sequence imx415_linkrate_2376mbps[] = {
+       { IMX415_TCLKPOST, 0x00E7 },
+       { IMX415_TCLKPREPARE, 0x008F },
+       { IMX415_TCLKTRAIL, 0x008F },
+       { IMX415_TCLKZERO, 0x027F },
+       { IMX415_THSPREPARE, 0x0097 },
+       { IMX415_THSZERO, 0x010F },
+       { IMX415_THSTRAIL, 0x0097 },
+       { IMX415_THSEXIT, 0x00F7 },
+       { IMX415_TLPX, 0x007F },
+};
+
 struct imx415_mode_reg_list {
        u32 num_of_regs;
        const struct cci_reg_sequence *regs;
@@ -576,6 +602,14 @@ static const struct imx415_mode supported_modes[] = {
                        .regs = imx415_linkrate_1440mbps,
                },
        },
+       {
+               .lane_rate = 1485000000,
+               .hmax_min = { 0, 550 },
+               .reg_list = {
+                       .num_of_regs = ARRAY_SIZE(imx415_linkrate_1485mbps),
+                       .regs = imx415_linkrate_1485mbps,
+               },
+       },
        {
                .lane_rate = 1782000000,
                .hmax_min = { 1100, 550 },
@@ -592,6 +626,14 @@ static const struct imx415_mode supported_modes[] = {
                        .regs = imx415_linkrate_2079mbps,
                },
        },
+       {
+               .lane_rate = 2376000000,
+               .hmax_min = { 0, 366 },
+               .reg_list = {
+                       .num_of_regs = ARRAY_SIZE(imx415_linkrate_2376mbps),
+                       .regs = imx415_linkrate_2376mbps,
+               },
+       },
 };
 
 static const char *const imx415_test_pattern_menu[] = {

drivers/media/i2c/imx415.c static int imx415_parse_hw_config(struct imx415 *sensor) · line 1426

Quoted 10 lines
drivers/media/i2c/imx415.c +4 -0
@@ -1375,9 +1417,13 @@ static int imx415_parse_hw_config(struct imx415 *sensor)
                }
 
                for (j = 0; j < ARRAY_SIZE(supported_modes); ++j) {
+                       int lanes_idx = sensor->num_data_lanes == 2 ? 0 : 1;
+
                        if (bus_cfg.link_frequencies[i] * 2 !=
                            supported_modes[j].lane_rate)
                                continue;
+                       if (!supported_modes[j].hmax_min[lanes_idx])
+                               continue;

You could lose the local variable by checking
if (!supported_modes[j].hmax_min[0] && sensor->num_data_lanes == 2)

Either way:

I've checked the register settings against the datasheet, and they all appear to match.

Quoted 7 lines
drivers/media/i2c/imx415.c +0 -1
                        sensor->cur_mode = j;
                        break;
                }
--

2.39.1

#11 lore raw
In reply to Alexander Shiyan

Hi Alexander

Quoted 15 lines · Alexander Shiyan

Allow the driver to report static media bus configuration using pad get_mbus_config() operation.

---
 drivers/media/i2c/imx415.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/media/i2c/imx415.c +0 -0
index 9f37779bd611..16a52900c61c 100644
@@ -1076,6 +1076,18 @@ static int imx415_init_state(struct v4l2_subdev *sd,
        return 0;

drivers/media/i2c/imx415.c static int imx415_init_state(struct v4l2_subdev *sd, · line 1086

Quoted 10 lines
drivers/media/i2c/imx415.c +8 -0
 }
 
+static int imx415_get_mbus_config(struct v4l2_subdev *sd, unsigned int pad_id,
+                                 struct v4l2_mbus_config *config)
+{
+       struct imx415 *sensor = to_imx415(sd);
+
+       config->type = V4L2_MBUS_CSI2_DPHY;
+       config->bus.mipi_csi2.flags = 0;
+       config->bus.mipi_csi2.num_data_lanes = sensor->num_data_lanes;

I'll let others confirm, but I believe the expectation is that the platform configuration would set this for both sensor and CSI2 receiver.
get_mbus_config is only used where the number of lanes can dynamically change.

I'm also trying to find confirmation in the IMX415 datasheet of whether it drops to LP for the clock lane or not. If it does, then you want to set V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK in the flags field. It's not obviously mentioned, so I may resort to getting an oscilloscope out on it.

Dave

Quoted 19 lines
drivers/media/i2c/imx415.c +5 -1
+
+       return 0;
+}
+
 static const struct v4l2_subdev_video_ops imx415_subdev_video_ops = {
        .s_stream = imx415_s_stream,
 };
@@ -1086,6 +1098,7 @@ static const struct v4l2_subdev_pad_ops imx415_subdev_pad_ops = {
        .get_fmt = v4l2_subdev_get_fmt,
        .set_fmt = imx415_set_format,
        .get_selection = imx415_get_selection,
+       .get_mbus_config = imx415_get_mbus_config,
 };
 
 static const struct v4l2_subdev_ops imx415_subdev_ops = {
--

2.39.1

Reviewed-by on v1 1/4
#12 lore raw
In reply to Alexander Shiyan

Hi Alexander,

Thanks for the patches. Next time, a cover letter that describes the overall goal of the changes would be nice for a series like this.

Quoted 4 lines · Alexander Shiyan

Allow the driver to report static media bus configuration using pad get_mbus_config() operation.

Best regards,
Michael

Quoted 35 lines
---
 drivers/media/i2c/imx415.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/media/i2c/imx415.c +13 -0
index 9f37779bd611..16a52900c61c 100644
@@ -1076,6 +1076,18 @@ static int imx415_init_state(struct v4l2_subdev *sd,
 	return 0;
 }
 
+static int imx415_get_mbus_config(struct v4l2_subdev *sd, unsigned int pad_id,
+				  struct v4l2_mbus_config *config)
+{
+	struct imx415 *sensor = to_imx415(sd);
+
+	config->type = V4L2_MBUS_CSI2_DPHY;
+	config->bus.mipi_csi2.flags = 0;
+	config->bus.mipi_csi2.num_data_lanes = sensor->num_data_lanes;
+
+	return 0;
+}
+
 static const struct v4l2_subdev_video_ops imx415_subdev_video_ops = {
 	.s_stream = imx415_s_stream,
 };
@@ -1086,6 +1098,7 @@ static const struct v4l2_subdev_pad_ops imx415_subdev_pad_ops = {
 	.get_fmt = v4l2_subdev_get_fmt,
 	.set_fmt = imx415_set_format,
 	.get_selection = imx415_get_selection,
+	.get_mbus_config = imx415_get_mbus_config,
 };
 
 static const struct v4l2_subdev_ops imx415_subdev_ops = {