mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/4] media: i2c: ds90ub960: VC mapping improvements and TX1 support
@ 2026-06-08 14:28 Rishikesh Donadkar
  2026-06-08 14:28 ` [PATCH 1/4] media: i2c: ds90ub960: Enable CSI TX1 port Rishikesh Donadkar
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Rishikesh Donadkar @ 2026-06-08 14:28 UTC (permalink / raw)
  To: jai.luthra
  Cc: r-donadkar, y-abhilashchandra, devarsht, vigneshr, mchehab,
	tomi.valkeinen, jai.luthra, linux-kernel, linux-media

This series improves virtual channel (VC) handling and adds TX1 port
support to the DS90UB960/UB9702 deserializer driver.

PATCH 01:    Enable CSI TX1 port by parsing active RX/TX ports from
             device tree and configuring RX_PORT_CTL BCC mapping
PATCH 02:    Replace hardcoded VC-to-port-number assignment with a
             proper per-port VC map built from source frame descriptors,
             allowing multi-channel sensors to work correctly
PATCH 03:    Fix loop termination bug in ub960_get_vc_maps() that caused
             ports after the first unconnected RX port to be skipped
PATCH 04:    Add UB9702-specific VC mapping (4 bits/VC, 2 VCs per port)
             instead of incorrectly reusing the UB960 layout

Tested streaming with the following configurations:
1. IMX219 + v3link on AM62A
2. ov2312 + v3link on AM62A
3. ov2312 + fusion2 on AM62A

Overlay and defconfig changes for the same can be found below:
https://github.com/RISHI27-dot/linux/commits/u/ds90ub960_mcs/

v4l2-compliance results:
https://gist.github.com/Rishikesh-D/0f5464617849f228699c525c47b4c785

Jai Luthra (2):
  media: i2c: ds90ub960: Support multi-channel sensors
  media: i2c: ds90ub960: Fix VC mapping when ports skipped

Rishikesh Donadkar (1):
  media: i2c: ds90ub960: Use VC mapping specific to ub9702

Yemike Abhilash Chandra (1):
  media: i2c: ds90ub960: Enable CSI TX1 port

 drivers/media/i2c/ds90ub960.c | 240 ++++++++++++++++++++++------------
 1 file changed, 154 insertions(+), 86 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/4] media: i2c: ds90ub960: Enable CSI TX1 port
  2026-06-08 14:28 [PATCH 0/4] media: i2c: ds90ub960: VC mapping improvements and TX1 support Rishikesh Donadkar
@ 2026-06-08 14:28 ` Rishikesh Donadkar
  2026-06-08 14:28 ` [PATCH 2/4] media: i2c: ds90ub960: Support multi-channel sensors Rishikesh Donadkar
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Rishikesh Donadkar @ 2026-06-08 14:28 UTC (permalink / raw)
  To: jai.luthra
  Cc: r-donadkar, y-abhilashchandra, devarsht, vigneshr, mchehab,
	tomi.valkeinen, jai.luthra, linux-kernel, linux-media

From: Yemike Abhilash Chandra <y-abhilashchandra@ti.com>

The DS90UB960 chip has two CSI-2 transmit ports (TX0 and TX1), but the
current driver implementation only utilizes TX0. To enable TX1 as the
active output port, the I2C Bidirectional Control Channel (BCC) mapping in
the RX_PORT_CTL register must be configured to use I2C Slave Port 1.

This patch adds a new function, ub960_parse_active_ports(), which is
called during driver initialization to scan the device tree and identify
which RX and TX ports are enabled. The function creates bitmasks
representing the active ports and uses these masks to correctly configure
the RX_PORT_CTL register, ensuring proper port routing for whichever TX
port is in use.

DS90UB960 data sheet: https://www.ti.com/lit/ds/symlink/ds90ub960-q1.pdf
Signed-off-by: Yemike Abhilash Chandra <y-abhilashchandra@ti.com>
Co-developed-by: Rishikesh Donadkar <r-donadkar@ti.com>
Signed-off-by: Rishikesh Donadkar <r-donadkar@ti.com>
---
 drivers/media/i2c/ds90ub960.c | 46 ++++++++++++++++++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/ds90ub960.c b/drivers/media/i2c/ds90ub960.c
index 15a9797b47ac..653dc7a4eee5 100644
--- a/drivers/media/i2c/ds90ub960.c
+++ b/drivers/media/i2c/ds90ub960.c
@@ -26,6 +26,7 @@
  * - i2c-atr could be made embeddable instead of allocatable.
  */
 
+#include <linux/bitfield.h>
 #include <linux/bitops.h>
 #include <linux/cleanup.h>
 #include <linux/clk.h>
@@ -76,6 +77,8 @@
 
 #define UB960_NUM_BC_GPIOS		4
 
+#define UB960_CSI_TX0			BIT(4)
+
 /*
  * Register map
  *
@@ -114,6 +117,7 @@
 #define UB960_SR_SCL_HIGH_TIME			0x0a
 #define UB960_SR_SCL_LOW_TIME			0x0b
 #define UB960_SR_RX_PORT_CTL			0x0c
+#define UB960_SR_RX_PORT_CTL_BCC_MAP		GENMASK(7, 4)
 #define UB960_SR_IO_CTL				0x0d
 #define UB960_SR_GPIO_PIN_STS			0x0e
 #define UB960_SR_GPIO_INPUT_CTL			0x0f
@@ -589,6 +593,9 @@ struct ub960_data {
 	u32 tx_data_rate;		/* Nominal data rate (Gb/s) */
 	s64 tx_link_freq[1];
 
+	u8 rx_mask;
+	u8 tx_mask;
+
 	struct i2c_atr *atr;
 
 	struct {
@@ -2538,7 +2545,18 @@ static int ub960_init_rx_ports_ub960(struct ub960_data *priv)
 	struct device *dev = &priv->client->dev;
 	unsigned int port_lock_mask;
 	unsigned int port_mask;
-	int ret;
+	u8 enabled_rxports_mask;
+	u8 enabled_rxports;
+	int ret = 0;
+
+	/* Configure I2C interface for RX ports */
+	enabled_rxports_mask = FIELD_PREP(UB960_SR_RX_PORT_CTL_BCC_MAP, priv->rx_mask);
+	enabled_rxports = (priv->tx_mask & UB960_CSI_TX0)  ? 0x00 : enabled_rxports_mask;
+
+	ret = ub960_update_bits(priv, UB960_SR_RX_PORT_CTL, enabled_rxports_mask,
+				enabled_rxports, &ret);
+	if (ret)
+		return ret;
 
 	for_each_active_rxport(priv, it) {
 		ret = ub960_init_rx_port_ub960(priv, it.rxport);
@@ -4789,6 +4807,30 @@ static int ub960_parse_dt_txports(struct ub960_data *priv)
 	return 0;
 }
 
+static void ub960_parse_active_ports(struct ub960_data *priv)
+{
+	struct device *dev = &priv->client->dev;
+	int nport;
+
+	priv->rx_mask = 0;
+	priv->tx_mask = 0;
+
+	for (nport = 0; nport < priv->hw_data->num_rxports + priv->hw_data->num_txports; nport++) {
+		struct fwnode_handle *ep_fwnode;
+
+		ep_fwnode = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev), nport, 0, 0);
+		if (!ep_fwnode)
+			continue;
+
+		if (nport < priv->hw_data->num_rxports)
+			priv->rx_mask |= BIT(nport);
+		else
+			priv->tx_mask |= BIT(nport);
+
+		fwnode_handle_put(ep_fwnode);
+	}
+}
+
 static int ub960_parse_dt(struct ub960_data *priv)
 {
 	int ret;
@@ -5162,6 +5204,8 @@ static int ub960_probe(struct i2c_client *client)
 	if (ret)
 		goto err_mutex_destroy;
 
+	ub960_parse_active_ports(priv);
+
 	ret = ub960_parse_dt(priv);
 	if (ret)
 		goto err_disable_core_hw;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/4] media: i2c: ds90ub960: Support multi-channel sensors
  2026-06-08 14:28 [PATCH 0/4] media: i2c: ds90ub960: VC mapping improvements and TX1 support Rishikesh Donadkar
  2026-06-08 14:28 ` [PATCH 1/4] media: i2c: ds90ub960: Enable CSI TX1 port Rishikesh Donadkar
@ 2026-06-08 14:28 ` Rishikesh Donadkar
  2026-06-08 17:09   ` Jai Luthra
  2026-06-08 14:29 ` [PATCH 3/4] media: i2c: ds90ub960: Fix VC mapping when ports skipped Rishikesh Donadkar
  2026-06-08 14:29 ` [PATCH 4/4] media: i2c: ds90ub960: Use VC mapping specific to ub9702 Rishikesh Donadkar
  3 siblings, 1 reply; 8+ messages in thread
From: Rishikesh Donadkar @ 2026-06-08 14:28 UTC (permalink / raw)
  To: jai.luthra
  Cc: r-donadkar, y-abhilashchandra, devarsht, vigneshr, mchehab,
	tomi.valkeinen, jai.luthra, linux-kernel, linux-media

From: Jai Luthra <me@jailuthra.in>

Before this, the deserializer would ignore the virtual channel (VC) ID
set in the incoming CSI packets, and set the ID to the RX port number in
the outgoing packets. This was done to support multiple single-channel
cameras, all sending packets with the same default VC ID = 0.

Now we check which (and how many) channels are under use on any incoming
FPDLink port, and map it to available channels on the outgoing CSI port.

Signed-off-by: Jai Luthra <me@jailuthra.in>
Signed-off-by: Rishikesh Donadkar <r-donadkar@ti.com>
---
 drivers/media/i2c/ds90ub960.c | 165 +++++++++++++++++-----------------
 1 file changed, 81 insertions(+), 84 deletions(-)

diff --git a/drivers/media/i2c/ds90ub960.c b/drivers/media/i2c/ds90ub960.c
index 653dc7a4eee5..506b436fe50c 100644
--- a/drivers/media/i2c/ds90ub960.c
+++ b/drivers/media/i2c/ds90ub960.c
@@ -72,6 +72,7 @@
 #define UB960_MAX_RX_NPORTS	4
 #define UB960_MAX_TX_NPORTS	2
 #define UB960_MAX_NPORTS	(UB960_MAX_RX_NPORTS + UB960_MAX_TX_NPORTS)
+#define UB960_MAX_VC		4
 
 #define UB960_MAX_PORT_ALIASES	8
 
@@ -3471,40 +3472,76 @@ static int ub960_rxport_handle_events(struct ub960_data *priv, u8 nport)
  */
 
 /*
- * The current implementation only supports a simple VC mapping, where all VCs
- * from a one RX port will be mapped to the same VC. Also, the hardware
- * dictates that all streams from an RX port must go to a single TX port.
+ * Map incoming streams with different virtual channels from 1-4 sensors to
+ * unique VCs on CSI TX0. Sensors using multiple VCs will work, but due to
+ * limited total channels (4) this will reduce the total number of sensors that
+ * can work simultaneously.
  *
- * This function decides the target VC numbers for each RX port with a simple
- * algorithm, so that for each TX port, we get VC numbers starting from 0,
- * and counting up.
+ * The current implementation is limited to using a single CSI TX port
+ * at a time (either TX0 or TX1 and not both simultaneously),
+ * as that is the most common HW configuration found on boards with DS90UB960.
+ * For using both CSI TX0 & TX1 the below method will need significant changes.
  *
- * E.g. if all four RX ports are in use, of which the first two go to the
- * first TX port and the secont two go to the second TX port, we would get
- * the following VCs for the four RX ports: 0, 1, 0, 1.
- *
- * TODO: implement a more sophisticated VC mapping. As the driver cannot know
- * what VCs the sinks expect (say, an FPGA with hardcoded VC routing), this
- * probably needs to be somehow configurable. Device tree?
  */
-static void ub960_get_vc_maps(struct ub960_data *priv,
-			      struct v4l2_subdev_state *state, u8 *vc)
+static void ub960_get_vc_maps(struct ub960_data *priv, u8 *vc_map)
 {
-	u8 cur_vc[UB960_MAX_TX_NPORTS] = {};
-	struct v4l2_subdev_route *route;
-	u8 handled_mask = 0;
+	struct device *dev = &priv->client->dev;
+	u8 nport, available_vc = 0;
 
-	for_each_active_route(&state->routing, route) {
-		unsigned int rx, tx;
+	for (nport = 0;
+	     nport < priv->hw_data->num_rxports && priv->rxports[nport];
+	     ++nport) {
+		struct v4l2_mbus_frame_desc source_fd;
+		bool used_vc[UB960_MAX_VC] = {false};
+		u8 vc, cur_vc = available_vc;
+		int j, ret;
+		u8 map;
 
-		rx = ub960_pad_to_port(priv, route->sink_pad);
-		if (BIT(rx) & handled_mask)
+		ret = v4l2_subdev_call(priv->rxports[nport]->source.sd, pad,
+				       get_frame_desc,
+				       priv->rxports[nport]->source.pad,
+				       &source_fd);
+		/* Mark channels used in source in used_vc[] */
+		if (!ret) {
+			for (j = 0; j < source_fd.num_entries; ++j) {
+				u8 source_vc = source_fd.entry[j].bus.csi2.vc;
+
+				if (source_vc < UB960_MAX_VC)
+					used_vc[source_vc] = true;
+			}
+		} else if (ret == -ENOIOCTLCMD) {
+			/* assume VC=0 is used if sensor driver doesn't provide info */
+			used_vc[0] = true;
+		} else {
 			continue;
+		}
 
-		tx = ub960_pad_to_port(priv, route->source_pad);
+		/* Start with all channels mapped to first free output */
+		map = (cur_vc << 6) | (cur_vc << 4) | (cur_vc << 2) |
+			(cur_vc << 0);
 
-		vc[rx] = cur_vc[tx]++;
-		handled_mask |= BIT(rx);
+		/* Map actually used to channels to distinct free outputs */
+		for (vc = 0; vc < UB960_MAX_VC; ++vc) {
+			if (used_vc[vc]) {
+				map &= ~(0x03 << (2 * vc));
+				map |= (cur_vc << (2 * vc));
+				++cur_vc;
+			}
+		}
+
+		/* Don't enable port if we ran out of available channels */
+		if (cur_vc > UB960_MAX_VC) {
+			dev_err(dev,
+				"No VCs available for RX port %d\n",
+				nport);
+			continue;
+		}
+
+		/* Enable port and update map */
+		vc_map[nport] = map;
+		available_vc = cur_vc;
+		dev_dbg(dev, "%s: VC map for port %d is 0x%02x",
+			__func__, nport, map);
 	}
 }
 
@@ -3552,45 +3589,6 @@ static int ub960_disable_rx_port(struct ub960_data *priv, unsigned int nport)
 				 UB960_SR_FWD_CTL1_PORT_DIS(nport), NULL);
 }
 
-/*
- * The driver only supports using a single VC for each source. This function
- * checks that each source only provides streams using a single VC.
- */
-static int ub960_validate_stream_vcs(struct ub960_data *priv)
-{
-	for_each_active_rxport(priv, it) {
-		struct v4l2_mbus_frame_desc desc;
-		int ret;
-		u8 vc;
-
-		ret = v4l2_subdev_call(it.rxport->source.sd, pad,
-				       get_frame_desc, it.rxport->source.pad,
-				       &desc);
-		if (ret)
-			return ret;
-
-		if (desc.type != V4L2_MBUS_FRAME_DESC_TYPE_CSI2)
-			continue;
-
-		if (desc.num_entries == 0)
-			continue;
-
-		vc = desc.entry[0].bus.csi2.vc;
-
-		for (unsigned int i = 1; i < desc.num_entries; i++) {
-			if (vc == desc.entry[i].bus.csi2.vc)
-				continue;
-
-			dev_err(&priv->client->dev,
-				"rx%u: source with multiple virtual-channels is not supported\n",
-				it.nport);
-			return -ENODEV;
-		}
-	}
-
-	return 0;
-}
-
 static int ub960_configure_ports_for_streaming(struct ub960_data *priv,
 					       struct v4l2_subdev_state *state)
 {
@@ -3606,11 +3604,7 @@ static int ub960_configure_ports_for_streaming(struct ub960_data *priv,
 	struct v4l2_subdev_route *route;
 	int ret;
 
-	ret = ub960_validate_stream_vcs(priv);
-	if (ret)
-		return ret;
-
-	ub960_get_vc_maps(priv, state, vc_map);
+	ub960_get_vc_maps(priv, vc_map);
 
 	for_each_active_route(&state->routing, route) {
 		struct ub960_rxport *rxport;
@@ -3676,16 +3670,14 @@ static int ub960_configure_ports_for_streaming(struct ub960_data *priv,
 	for_each_active_rxport(priv, it) {
 		unsigned long nport = it.nport;
 
-		u8 vc = vc_map[nport];
-
 		if (rx_data[nport].num_streams == 0)
 			continue;
 
 		switch (it.rxport->rx_mode) {
 		case RXPORT_MODE_RAW10:
 			ub960_rxport_write(priv, nport, UB960_RR_RAW10_ID,
-				rx_data[nport].pixel_dt | (vc << UB960_RR_RAW10_ID_VC_SHIFT),
-				&ret);
+				rx_data[nport].pixel_dt | (nport << UB960_RR_RAW10_ID_VC_SHIFT),
+					&ret);
 
 			ub960_rxport_write(priv, nport,
 				UB960_RR_RAW_EMBED_DTYPE,
@@ -3701,15 +3693,10 @@ static int ub960_configure_ports_for_streaming(struct ub960_data *priv,
 
 		case RXPORT_MODE_CSI2_SYNC:
 		case RXPORT_MODE_CSI2_NONSYNC:
-			if (priv->hw_data->chip_type == UB960 ||
-			    priv->hw_data->chip_type == UB954) {
-				/* Map all VCs from this port to the same VC */
-				ub960_rxport_write(priv, nport, UB960_RR_CSI_VC_MAP,
-						   (vc << UB960_RR_CSI_VC_MAP_SHIFT(3)) |
-						   (vc << UB960_RR_CSI_VC_MAP_SHIFT(2)) |
-						   (vc << UB960_RR_CSI_VC_MAP_SHIFT(1)) |
-						   (vc << UB960_RR_CSI_VC_MAP_SHIFT(0)),
-						   &ret);
+			if (priv->hw_data->chip_type == UB960) {
+				ub960_rxport_write(priv, nport,
+						   UB960_RR_CSI_VC_MAP,
+						   vc_map[nport], &ret);
 			} else {
 				unsigned int i;
 
@@ -3965,6 +3952,11 @@ static int ub960_set_routing(struct v4l2_subdev *sd,
 	return _ub960_set_routing(sd, state, routing);
 }
 
+static inline u8 ub960_get_output_vc(u8 map, u8 input_vc)
+{
+	return (map >> (2 * input_vc)) & 0x03;
+}
+
 static int ub960_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,
 				struct v4l2_mbus_frame_desc *fd)
 {
@@ -3982,7 +3974,7 @@ static int ub960_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,
 
 	state = v4l2_subdev_lock_and_get_active_state(&priv->sd);
 
-	ub960_get_vc_maps(priv, state, vc_map);
+	ub960_get_vc_maps(priv, vc_map);
 
 	for_each_active_route(&state->routing, route) {
 		struct v4l2_mbus_frame_desc_entry *source_entry = NULL;
@@ -4025,7 +4017,12 @@ static int ub960_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,
 		fd->entry[fd->num_entries].length = source_entry->length;
 		fd->entry[fd->num_entries].pixelcode = source_entry->pixelcode;
 
-		fd->entry[fd->num_entries].bus.csi2.vc = vc_map[nport];
+		fd->entry[fd->num_entries].bus.csi2.vc =
+			ub960_get_output_vc(vc_map[nport],
+					    source_entry->bus.csi2.vc);
+		dev_dbg(dev, "Mapping sink %d/%d to output VC %d",
+			route->sink_pad, route->sink_stream,
+			fd->entry[fd->num_entries].bus.csi2.vc);
 
 		if (source_fd.type == V4L2_MBUS_FRAME_DESC_TYPE_CSI2) {
 			fd->entry[fd->num_entries].bus.csi2.dt =
-- 
2.34.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 3/4] media: i2c: ds90ub960: Fix VC mapping when ports skipped
  2026-06-08 14:28 [PATCH 0/4] media: i2c: ds90ub960: VC mapping improvements and TX1 support Rishikesh Donadkar
  2026-06-08 14:28 ` [PATCH 1/4] media: i2c: ds90ub960: Enable CSI TX1 port Rishikesh Donadkar
  2026-06-08 14:28 ` [PATCH 2/4] media: i2c: ds90ub960: Support multi-channel sensors Rishikesh Donadkar
@ 2026-06-08 14:29 ` Rishikesh Donadkar
  2026-06-08 17:11   ` Jai Luthra
  2026-06-08 14:29 ` [PATCH 4/4] media: i2c: ds90ub960: Use VC mapping specific to ub9702 Rishikesh Donadkar
  3 siblings, 1 reply; 8+ messages in thread
From: Rishikesh Donadkar @ 2026-06-08 14:29 UTC (permalink / raw)
  To: jai.luthra
  Cc: r-donadkar, y-abhilashchandra, devarsht, vigneshr, mchehab,
	tomi.valkeinen, jai.luthra, linux-kernel, linux-media

From: Jai Luthra <j-luthra@ti.com>

Currently the for loop that maps virtual channels from RX to TX ports
terminates at the first unconnected RX port.

Fix that by instead continuing to scan the remaining ports.

Signed-off-by: Jai Luthra <j-luthra@ti.com>
Signed-off-by: Rishikesh Donadkar <r-donadkar@ti.com>
---
 drivers/media/i2c/ds90ub960.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/media/i2c/ds90ub960.c b/drivers/media/i2c/ds90ub960.c
index 506b436fe50c..d1597659639f 100644
--- a/drivers/media/i2c/ds90ub960.c
+++ b/drivers/media/i2c/ds90ub960.c
@@ -3488,15 +3488,16 @@ static void ub960_get_vc_maps(struct ub960_data *priv, u8 *vc_map)
 	struct device *dev = &priv->client->dev;
 	u8 nport, available_vc = 0;
 
-	for (nport = 0;
-	     nport < priv->hw_data->num_rxports && priv->rxports[nport];
-	     ++nport) {
+	for (nport = 0; nport < priv->hw_data->num_rxports; ++nport) {
 		struct v4l2_mbus_frame_desc source_fd;
 		bool used_vc[UB960_MAX_VC] = {false};
 		u8 vc, cur_vc = available_vc;
 		int j, ret;
 		u8 map;
 
+		if (!priv->rxports[nport])
+			continue;
+
 		ret = v4l2_subdev_call(priv->rxports[nport]->source.sd, pad,
 				       get_frame_desc,
 				       priv->rxports[nport]->source.pad,
-- 
2.34.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 4/4] media: i2c: ds90ub960: Use VC mapping specific to ub9702
  2026-06-08 14:28 [PATCH 0/4] media: i2c: ds90ub960: VC mapping improvements and TX1 support Rishikesh Donadkar
                   ` (2 preceding siblings ...)
  2026-06-08 14:29 ` [PATCH 3/4] media: i2c: ds90ub960: Fix VC mapping when ports skipped Rishikesh Donadkar
@ 2026-06-08 14:29 ` Rishikesh Donadkar
  2026-06-08 17:16   ` Jai Luthra
  3 siblings, 1 reply; 8+ messages in thread
From: Rishikesh Donadkar @ 2026-06-08 14:29 UTC (permalink / raw)
  To: jai.luthra
  Cc: r-donadkar, y-abhilashchandra, devarsht, vigneshr, mchehab,
	tomi.valkeinen, jai.luthra, linux-kernel, linux-media

Add a dedicated virtual channel mapping for ub9702 deserializers which
require different VC configuration compared to ub960. Update the
configuration logic to select the appropriate map based on the
deserializer type.

Signed-off-by: Rishikesh Donadkar <r-donadkar@ti.com>
---
 drivers/media/i2c/ds90ub960.c | 44 ++++++++++++++++++++++++++++-------
 1 file changed, 35 insertions(+), 9 deletions(-)

diff --git a/drivers/media/i2c/ds90ub960.c b/drivers/media/i2c/ds90ub960.c
index d1597659639f..9ce6d9e6e3e8 100644
--- a/drivers/media/i2c/ds90ub960.c
+++ b/drivers/media/i2c/ds90ub960.c
@@ -3482,7 +3482,18 @@ static int ub960_rxport_handle_events(struct ub960_data *priv, u8 nport)
  * as that is the most common HW configuration found on boards with DS90UB960.
  * For using both CSI TX0 & TX1 the below method will need significant changes.
  *
+ * VC mapping differs between ub960 and ub9702 deserializers:
+ * For ub960:
+ *		- Each VC uses 2 bits in the mapping register
+ *		- Supports up to 4 virtual channels (VC0-VC3)
+ * For ub9702:
+ *		- Each VC uses 4 bits in the mapping register
+ *		- Currently uses only 2 virtual channels (VC0, VC1)
+ *
+ * The mapping registers determine which output VC a given input VC
+ * will be mapped to when forwarding data from the deserializer.
  */
+
 static void ub960_get_vc_maps(struct ub960_data *priv, u8 *vc_map)
 {
 	struct device *dev = &priv->client->dev;
@@ -3518,14 +3529,26 @@ static void ub960_get_vc_maps(struct ub960_data *priv, u8 *vc_map)
 		}
 
 		/* Start with all channels mapped to first free output */
-		map = (cur_vc << 6) | (cur_vc << 4) | (cur_vc << 2) |
-			(cur_vc << 0);
+
+		if (priv->hw_data->chip_type == UB960) {
+			map = (cur_vc << 6) | (cur_vc << 4) | (cur_vc << 2) |
+				(cur_vc << 0);
+		} else {
+			map = (cur_vc << 4) | (cur_vc << 0);
+		}
 
 		/* Map actually used to channels to distinct free outputs */
 		for (vc = 0; vc < UB960_MAX_VC; ++vc) {
 			if (used_vc[vc]) {
-				map &= ~(0x03 << (2 * vc));
-				map |= (cur_vc << (2 * vc));
+				if (priv->hw_data->chip_type == UB960) {
+					/* For ub960: 2 bits per VC */
+					map &= ~(0x03 << (2 * vc));
+					map |= (cur_vc << (2 * vc));
+				} else {
+					/* For ub9702: 4 bits per VC */
+					map &= ~(0x0f << (4 * vc));
+					map |= (cur_vc << (4 * vc));
+				}
 				++cur_vc;
 			}
 		}
@@ -3705,8 +3728,7 @@ static int ub960_configure_ports_for_streaming(struct ub960_data *priv,
 				for (i = 0; i < 8; i++)
 					ub960_rxport_write(priv, nport,
 							   UB9702_RR_VC_ID_MAP(i),
-							   (nport << 4) | nport,
-							   &ret);
+							   vc_map[nport], &ret);
 			}
 
 			break;
@@ -4018,9 +4040,13 @@ static int ub960_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,
 		fd->entry[fd->num_entries].length = source_entry->length;
 		fd->entry[fd->num_entries].pixelcode = source_entry->pixelcode;
 
-		fd->entry[fd->num_entries].bus.csi2.vc =
-			ub960_get_output_vc(vc_map[nport],
-					    source_entry->bus.csi2.vc);
+		if (priv->hw_data->chip_type == UB960)
+			fd->entry[fd->num_entries].bus.csi2.vc =
+				(vc_map[nport] >> (2 * source_entry->bus.csi2.vc)) & 0x03;
+		else
+			fd->entry[fd->num_entries].bus.csi2.vc =
+				(vc_map[nport] >> (4 * source_entry->bus.csi2.vc)) & 0x0f;
+
 		dev_dbg(dev, "Mapping sink %d/%d to output VC %d",
 			route->sink_pad, route->sink_stream,
 			fd->entry[fd->num_entries].bus.csi2.vc);
-- 
2.34.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/4] media: i2c: ds90ub960: Support multi-channel sensors
  2026-06-08 14:28 ` [PATCH 2/4] media: i2c: ds90ub960: Support multi-channel sensors Rishikesh Donadkar
@ 2026-06-08 17:09   ` Jai Luthra
  0 siblings, 0 replies; 8+ messages in thread
From: Jai Luthra @ 2026-06-08 17:09 UTC (permalink / raw)
  To: Rishikesh Donadkar, jai.luthra
  Cc: r-donadkar, y-abhilashchandra, devarsht, vigneshr, mchehab,
	tomi.valkeinen, linux-kernel, linux-media

Quoting Rishikesh Donadkar (2026-06-08 19:58:59)
> From: Jai Luthra <me@jailuthra.in>
> 

It's been many years since I wrote this, so I have no idea how that email
ended up here.

Please fix it in next revision to j-luthra@ti.com like the other patch, as
.mailmap should handle redirections from it.

Thanks,
    Jai

> Before this, the deserializer would ignore the virtual channel (VC) ID
> set in the incoming CSI packets, and set the ID to the RX port number in
> the outgoing packets. This was done to support multiple single-channel
> cameras, all sending packets with the same default VC ID = 0.
> 
> Now we check which (and how many) channels are under use on any incoming
> FPDLink port, and map it to available channels on the outgoing CSI port.
> 
> Signed-off-by: Jai Luthra <me@jailuthra.in>
> Signed-off-by: Rishikesh Donadkar <r-donadkar@ti.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/4] media: i2c: ds90ub960: Fix VC mapping when ports skipped
  2026-06-08 14:29 ` [PATCH 3/4] media: i2c: ds90ub960: Fix VC mapping when ports skipped Rishikesh Donadkar
@ 2026-06-08 17:11   ` Jai Luthra
  0 siblings, 0 replies; 8+ messages in thread
From: Jai Luthra @ 2026-06-08 17:11 UTC (permalink / raw)
  To: Rishikesh Donadkar, jai.luthra
  Cc: r-donadkar, y-abhilashchandra, devarsht, vigneshr, mchehab,
	tomi.valkeinen, linux-kernel, linux-media

Hi Rishikesh,

Quoting Rishikesh Donadkar (2026-06-08 19:59:00)
> From: Jai Luthra <j-luthra@ti.com>
> 
> Currently the for loop that maps virtual channels from RX to TX ports
> terminates at the first unconnected RX port.
> 
> Fix that by instead continuing to scan the remaining ports.
> 

It's never a good idea to introduce a bug in one patch and fix it in the
next. Please squash it in next revision.

Thanks,
    Jai

> Signed-off-by: Jai Luthra <j-luthra@ti.com>
> Signed-off-by: Rishikesh Donadkar <r-donadkar@ti.com>
> ---
>  drivers/media/i2c/ds90ub960.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/i2c/ds90ub960.c b/drivers/media/i2c/ds90ub960.c
> index 506b436fe50c..d1597659639f 100644
> --- a/drivers/media/i2c/ds90ub960.c
> +++ b/drivers/media/i2c/ds90ub960.c
> @@ -3488,15 +3488,16 @@ static void ub960_get_vc_maps(struct ub960_data *priv, u8 *vc_map)
>         struct device *dev = &priv->client->dev;
>         u8 nport, available_vc = 0;
>  
> -       for (nport = 0;
> -            nport < priv->hw_data->num_rxports && priv->rxports[nport];
> -            ++nport) {
> +       for (nport = 0; nport < priv->hw_data->num_rxports; ++nport) {
>                 struct v4l2_mbus_frame_desc source_fd;
>                 bool used_vc[UB960_MAX_VC] = {false};
>                 u8 vc, cur_vc = available_vc;
>                 int j, ret;
>                 u8 map;
>  
> +               if (!priv->rxports[nport])
> +                       continue;
> +
>                 ret = v4l2_subdev_call(priv->rxports[nport]->source.sd, pad,
>                                        get_frame_desc,
>                                        priv->rxports[nport]->source.pad,
> -- 
> 2.34.1
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 4/4] media: i2c: ds90ub960: Use VC mapping specific to ub9702
  2026-06-08 14:29 ` [PATCH 4/4] media: i2c: ds90ub960: Use VC mapping specific to ub9702 Rishikesh Donadkar
@ 2026-06-08 17:16   ` Jai Luthra
  0 siblings, 0 replies; 8+ messages in thread
From: Jai Luthra @ 2026-06-08 17:16 UTC (permalink / raw)
  To: Rishikesh Donadkar, jai.luthra
  Cc: r-donadkar, y-abhilashchandra, devarsht, vigneshr, mchehab,
	tomi.valkeinen, linux-kernel, linux-media

Quoting Rishikesh Donadkar (2026-06-08 19:59:01)
> Add a dedicated virtual channel mapping for ub9702 deserializers which
> require different VC configuration compared to ub960. Update the
> configuration logic to select the appropriate map based on the
> deserializer type.
> 
> Signed-off-by: Rishikesh Donadkar <r-donadkar@ti.com>
> ---
>  drivers/media/i2c/ds90ub960.c | 44 ++++++++++++++++++++++++++++-------
>  1 file changed, 35 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/media/i2c/ds90ub960.c b/drivers/media/i2c/ds90ub960.c
> index d1597659639f..9ce6d9e6e3e8 100644
> --- a/drivers/media/i2c/ds90ub960.c
> +++ b/drivers/media/i2c/ds90ub960.c
> @@ -3482,7 +3482,18 @@ static int ub960_rxport_handle_events(struct ub960_data *priv, u8 nport)
>   * as that is the most common HW configuration found on boards with DS90UB960.
>   * For using both CSI TX0 & TX1 the below method will need significant changes.
>   *
> + * VC mapping differs between ub960 and ub9702 deserializers:
> + * For ub960:
> + *             - Each VC uses 2 bits in the mapping register
> + *             - Supports up to 4 virtual channels (VC0-VC3)
> + * For ub9702:
> + *             - Each VC uses 4 bits in the mapping register
> + *             - Currently uses only 2 virtual channels (VC0, VC1)
> + *
> + * The mapping registers determine which output VC a given input VC
> + * will be mapped to when forwarding data from the deserializer.
>   */
> +
>  static void ub960_get_vc_maps(struct ub960_data *priv, u8 *vc_map)
>  {
>         struct device *dev = &priv->client->dev;
> @@ -3518,14 +3529,26 @@ static void ub960_get_vc_maps(struct ub960_data *priv, u8 *vc_map)
>                 }
>  
>                 /* Start with all channels mapped to first free output */
> -               map = (cur_vc << 6) | (cur_vc << 4) | (cur_vc << 2) |
> -                       (cur_vc << 0);
> +
> +               if (priv->hw_data->chip_type == UB960) {
> +                       map = (cur_vc << 6) | (cur_vc << 4) | (cur_vc << 2) |
> +                               (cur_vc << 0);
> +               } else {
> +                       map = (cur_vc << 4) | (cur_vc << 0);
> +               }
>  

Same comment as last patch, I think this means that UB9702 would be broken
without this patch, which is never a good idea in mainline.

Please squash together patches so that each patch is an independent change
that doesn't break any device.

I'm fine with a Co-developed-by tag in the final single patch as it's been
quite a while since I looked at this :-)

Thanks,
    Jai

>                 /* Map actually used to channels to distinct free outputs */
>                 for (vc = 0; vc < UB960_MAX_VC; ++vc) {
>                         if (used_vc[vc]) {
> -                               map &= ~(0x03 << (2 * vc));
> -                               map |= (cur_vc << (2 * vc));
> +                               if (priv->hw_data->chip_type == UB960) {
> +                                       /* For ub960: 2 bits per VC */
> +                                       map &= ~(0x03 << (2 * vc));
> +                                       map |= (cur_vc << (2 * vc));
> +                               } else {
> +                                       /* For ub9702: 4 bits per VC */
> +                                       map &= ~(0x0f << (4 * vc));
> +                                       map |= (cur_vc << (4 * vc));
> +                               }
>                                 ++cur_vc;
>                         }
>                 }
> @@ -3705,8 +3728,7 @@ static int ub960_configure_ports_for_streaming(struct ub960_data *priv,
>                                 for (i = 0; i < 8; i++)
>                                         ub960_rxport_write(priv, nport,
>                                                            UB9702_RR_VC_ID_MAP(i),
> -                                                          (nport << 4) | nport,
> -                                                          &ret);
> +                                                          vc_map[nport], &ret);
>                         }
>  
>                         break;
> @@ -4018,9 +4040,13 @@ static int ub960_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,
>                 fd->entry[fd->num_entries].length = source_entry->length;
>                 fd->entry[fd->num_entries].pixelcode = source_entry->pixelcode;
>  
> -               fd->entry[fd->num_entries].bus.csi2.vc =
> -                       ub960_get_output_vc(vc_map[nport],
> -                                           source_entry->bus.csi2.vc);
> +               if (priv->hw_data->chip_type == UB960)
> +                       fd->entry[fd->num_entries].bus.csi2.vc =
> +                               (vc_map[nport] >> (2 * source_entry->bus.csi2.vc)) & 0x03;
> +               else
> +                       fd->entry[fd->num_entries].bus.csi2.vc =
> +                               (vc_map[nport] >> (4 * source_entry->bus.csi2.vc)) & 0x0f;
> +
>                 dev_dbg(dev, "Mapping sink %d/%d to output VC %d",
>                         route->sink_pad, route->sink_stream,
>                         fd->entry[fd->num_entries].bus.csi2.vc);
> -- 
> 2.34.1
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-06-08 17:16 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-08 14:28 [PATCH 0/4] media: i2c: ds90ub960: VC mapping improvements and TX1 support Rishikesh Donadkar
2026-06-08 14:28 ` [PATCH 1/4] media: i2c: ds90ub960: Enable CSI TX1 port Rishikesh Donadkar
2026-06-08 14:28 ` [PATCH 2/4] media: i2c: ds90ub960: Support multi-channel sensors Rishikesh Donadkar
2026-06-08 17:09   ` Jai Luthra
2026-06-08 14:29 ` [PATCH 3/4] media: i2c: ds90ub960: Fix VC mapping when ports skipped Rishikesh Donadkar
2026-06-08 17:11   ` Jai Luthra
2026-06-08 14:29 ` [PATCH 4/4] media: i2c: ds90ub960: Use VC mapping specific to ub9702 Rishikesh Donadkar
2026-06-08 17:16   ` Jai Luthra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®