media: v4l: add support for Virtual Channel IDs
Subsystems (6)
cover media: v4l: add support for Virtual Channel IDs
Multi-camera systems often have issues with receiving video streams from multiple cameras at the same time because the cameras use the same Virtual Channel IDs.
CSI bridges might not support remapping the Virtual Channel IDs, making it impossible to receive the separate video streams at the same time, while the CSI receiver is able to de-mux streams based on VC IDs.
Cameras sometimes have support for changing the VC IDs they output themselves.
For a practical example, GMSL2 deserializer chips do not support VC ID remapping in tunnel mode, and neither do the serializers. Allowing the cameras to have their VC IDs configured would allow multi-camera setups to use tunnel mode.
Add support for specifying these Virtual Channel IDs in Video Interface Endpoints.
Add support for parsing VC IDs in v4l2_fwnode_endpoint_parse(). This allows us to retrieve the specified VC IDs in camera drivers and configure the hardware to use them.
The supported values are 0 to 3, with a maximum of 4 values. Although the CSI-2 specification allows for up to 32 virtual channels, most hardware doesn't support more than 4. This can be extended later if need be.
The driver must validate the number of VC IDs and the VC IDs themselves.
Add an example implementation for IMX219.
Cosmin Tanislav (5):
dt-bindings: media: video-interfaces: add support for Virtual Channel
IDs
media: v4l: fwnode: parse Virtual Channel IDs for CSI2 buses
dt-bindings: media: imx219: add support for Virtual Channel IDs
media: i2c: imx219: pass format's code to imx219_get_format_bpp()
media: i2c: imx219: implement configurable VC ID
Laurent Pinchart (1):
media: i2c: imx219: Report streams using frame descriptors
.../devicetree/bindings/media/i2c/imx219.yaml | 2 + .../bindings/media/video-interfaces.yaml | 11 ++++ drivers/media/i2c/imx219.c | 54 +++++++++++++++++-- drivers/media/v4l2-core/v4l2-fwnode.c | 15 ++++++ include/media/v4l2-mediabus.h | 5 ++ 5 files changed, 84 insertions(+), 3 deletions(-)
Signature · 1 line
2.48.1
PATCH 1/6 dt-bindings: media: video-interfaces: add support for Virtual Channel IDs
Multi-camera systems often have issues with receiving video streams from multiple cameras at the same time because the cameras use the same Virtual Channel IDs.
CSI bridges might not support remapping the Virtual Channel IDs, making it impossible to receive the separate video streams at the same time, while the CSI receiver is able to de-mux streams based on VC IDs.
Cameras sometimes have support for changing the VC IDs they output themselves.
For a practical example, GMSL2 deserializer chips do not support VC ID remapping in tunnel mode, and neither do the serializers. Allowing the cameras to have their VC IDs configured would allow multi-camera setups to use tunnel mode.
Add support for specifying these Virtual Channel IDs in Video Interface Endpoints. The supported values are 0 to 3, with a maximum of 4 values. Although the CSI-2 specification allows for up to 32 virtual channels, most hardware doesn't support more than 4. This can be extended later if need be.
--- .../devicetree/bindings/media/video-interfaces.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+)
Documentation/devicetree/bindings/media/video-interfaces.yaml +11 -0
@@ -231,6 +231,17 @@ properties: shall be interpreted as 0 (ABC). This property is valid for CSI-2 C-PHY busses only. + vc-ids: + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 1 + maxItems: 4 + items: + maximum: 3 + description: + An array of Virtual Channel IDs. These are unsigned integers that specify + the VC IDs used by the device for its data streams. This property is valid + for MIPI CSI-2 only. + strobe: $ref: /schemas/types.yaml#/definitions/uint32 enum: [ 0, 1 ]
Signature · 1 line
2.48.1
PATCH 2/6 media: v4l: fwnode: parse Virtual Channel IDs for CSI2 buses
In reply to Cosmin TanislavMulti-camera systems often have issues with receiving video streams from multiple cameras at the same time because the cameras use the same Virtual Channel IDs.
CSI bridges might not support remapping the Virtual Channel IDs, making it impossible to receive the separate video streams at the same time, while the CSI receiver is able to de-mux streams based on VC IDs.
Cameras sometimes have support for changing the VC IDs they output themselves.
For a practical example, GMSL2 deserializer chips do not support VC ID remapping in tunnel mode, and neither do the serializers. Allowing the cameras to have their VC IDs configured would allow multi-camera setups to use tunnel mode.
Add support for parsing VC IDs in v4l2_fwnode_endpoint_parse(). This allows us to retrieve the specified VC IDs in camera drivers and configure the hardware to use them.
The supported values are 0 to 3, with a maximum of 4 values. Although the CSI-2 specification allows for up to 32 virtual channels, most hardware doesn't support more than 4. This can be extended later if need be.
The driver must validate the number of VC IDs and the VC IDs themselves.
--- drivers/media/v4l2-core/v4l2-fwnode.c | 15 +++++++++++++++ include/media/v4l2-mediabus.h | 5 +++++ 2 files changed, 20 insertions(+)
drivers/media/v4l2-core/v4l2-fwnode.c +15 -0
@@ -129,8 +129,10 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,bool have_clk_lane = false, have_data_lanes = false, have_lane_polarities = false, have_line_orders = false;unsigned int flags =0 , lanes_used =0 ; +u32 vc_ids_array[V4L2_MBUS_CSI2_MAX_VC_IDS ];u32 array[1 +V4L2_MBUS_CSI2_MAX_DATA_LANES ];u32 clock_lane =0 ; +unsigned int num_vc_ids =0 ;unsigned int num_data_lanes =0 ;bool use_default_lane_mapping = false;unsigned int i;
@@ -208,6 +210,15 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode, have_line_orders = true; } + rval =fwnode_property_count_u32 (fwnode,"vc-ids" ); +if (rval >0 ) { + num_vc_ids = + min_t(unsigned int, V4L2_MBUS_CSI2_MAX_VC_IDS, rval); + +fwnode_property_read_u32_array (fwnode,"vc-ids" , vc_ids_array, + num_vc_ids); + } +if (!fwnode_property_read_u32 (fwnode,"clock-lanes" , &v)) { clock_lane = v;pr_debug ("clock lane position %u\n" , v);
@@ -248,6 +259,10 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode, bus->data_lanes[i] = array[i]; } + bus->num_vc_ids = num_vc_ids; +for (i =0 ; i < num_vc_ids; i++) + bus->vc_ids[i] = vc_ids_array[i]; +if (have_lane_polarities) { fwnode_property_read_u32_array(fwnode, "lane-polarities", array,
include/media/v4l2-mediabus.h +5 -0
@@ -72,6 +72,7 @@#define V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK BIT(0)#define V4L2_MBUS_CSI2_MAX_DATA_LANES 8 +#define V4L2_MBUS_CSI2_MAX_VC_IDS 4/** * enum v4l2_mbus_csi2_cphy_line_orders_type - CSI-2 C-PHY line order
@@ -94,8 +95,10 @@ enum v4l2_mbus_csi2_cphy_line_orders_type {/** * struct v4l2_mbus_config_mipi_csi2 - MIPI CSI-2 data bus configuration * @flags: media bus (V4L2_MBUS_*) flags +* @vc_ids: an array of Virtual Channel IDs * @data_lanes: an array of physical data lane indexes * @clock_lane: physical lane index of the clock lane +* @num_vc_ids: number of Virtual Channel IDs * @num_data_lanes: number of data lanes * @lane_polarities: polarity of the lanes. The order is the same of * the physical lanes.
@@ -104,8 +107,10 @@ enum v4l2_mbus_csi2_cphy_line_orders_type {*/ struct v4l2_mbus_config_mipi_csi2 {unsigned int flags; +unsigned char vc_ids[V4L2_MBUS_CSI2_MAX_VC_IDS ];unsigned char data_lanes[V4L2_MBUS_CSI2_MAX_DATA_LANES ];unsigned char clock_lane; +unsigned char num_vc_ids;unsigned char num_data_lanes;bool lane_polarities[1 +V4L2_MBUS_CSI2_MAX_DATA_LANES ];enum v4l2_mbus_csi2_cphy_line_orders_type line_orders[V4L2_MBUS_CSI2_MAX_DATA_LANES ];
Signature · 1 line
2.48.1
PATCH 3/6 dt-bindings: media: imx219: add support for Virtual Channel IDs
In reply to Cosmin TanislavIMX219 supports configuring the Virtual Channel ID used for image and embedded data streams.
--- Documentation/devicetree/bindings/media/i2c/imx219.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/media/i2c/imx219.yaml +2 -0
@@ -66,6 +66,8 @@ properties: clock-noncontinuous: true link-frequencies: true + vc-ids: + maxItems: 1 required: - link-frequencies
Signature · 1 line
2.48.1
PATCH 4/6 media: i2c: imx219: pass format's code to imx219_get_format_bpp()
In reply to Cosmin Tanislavimx219_get_format_bpp() only uses the code of the format, pass it instead of the whole format to allow usage when the whole format is not available.
--- drivers/media/i2c/imx219.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/i2c/imx219.c +3 -3
@@ -387,9 +387,9 @@ static u32 imx219_get_format_code(struct imx219 *imx219, u32 code)return imx219_mbus_formats[i]; } -static u32 imx219_get_format_bpp (const struct v4l2_mbus_framefmt *format) +static u32 imx219_get_format_bpp (u32 code) { -switch (format->code) { +switch (code) {case MEDIA_BUS_FMT_SRGGB8_1X8 :case MEDIA_BUS_FMT_SGRBG8_1X8 :case MEDIA_BUS_FMT_SGBRG8_1X8 :
@@ -680,7 +680,7 @@ static int imx219_set_framefmt(struct imx219 *imx219, format =v4l2_subdev_state_get_format (state,0 ); crop =v4l2_subdev_state_get_crop (state,0 ); - bpp =imx219_get_format_bpp (format); + bpp =imx219_get_format_bpp (format->code);cci_write (imx219->regmap,IMX219_REG_X_ADD_STA_A , crop->left -IMX219_PIXEL_ARRAY_LEFT , &ret);
Signature · 1 line
2.48.1
PATCH 5/6 media: i2c: imx219: Report streams using frame descriptors
In reply to Cosmin TanislavFrom: Laurent Pinchart <[email protected]>
Implement the .get_frame_desc() subdev operation to report information about streams to the connected CSI-2 receiver. This is required to let the CSI-2 receiver driver know about virtual channels and data types for each stream.
--- drivers/media/i2c/imx219.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/media/i2c/imx219.c +24 -0
@@ -23,6 +23,7 @@#include <linux/pm_runtime.h> #include <linux/regulator/consumer.h> +#include <media/mipi-csi2.h> #include <media/v4l2-cci.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-device.h>
@@ -990,6 +991,28 @@ static int imx219_init_state(struct v4l2_subdev *sd,return 0 ; } +static int imx219_get_frame_desc (struct v4l2_subdev *sd,unsigned int pad, +struct v4l2_mbus_frame_desc *fd) +{ +struct v4l2_subdev_state *state; +u32 code; + + state =v4l2_subdev_lock_and_get_active_state (sd); + code =v4l2_subdev_state_get_format (state,0 )->code; +v4l2_subdev_unlock_state (state); + + fd->type =V4L2_MBUS_FRAME_DESC_TYPE_CSI2 ; + fd->num_entries =1 ; + + fd->entry[0 ].pixelcode = code; + fd->entry[0 ].stream =0 ; + fd->entry[0 ].bus.csi2.vc =0 ; + fd->entry[0 ].bus.csi2.dt =imx219_get_format_bpp (code) ==8 + ?MIPI_CSI2_DT_RAW8 :MIPI_CSI2_DT_RAW10 ; + +return 0 ; +} +static const struct v4l2_subdev_video_ops imx219_video_ops = { .s_stream = imx219_set_stream, };
@@ -1000,6 +1023,7 @@ static const struct v4l2_subdev_pad_ops imx219_pad_ops = { .set_fmt = imx219_set_pad_format, .get_selection = imx219_get_selection, .enum_frame_size = imx219_enum_frame_size, + .get_frame_desc = imx219_get_frame_desc, };static const struct v4l2_subdev_ops imx219_subdev_ops = {
Signature · 1 line
2.48.1
PATCH 6/6 media: i2c: imx219: implement configurable VC ID
In reply to Cosmin TanislavIMX219 supports configuring the Virtual Channel ID used for image and embedded data streams.
--- drivers/media/i2c/imx219.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)
drivers/media/i2c/imx219.c +25 -1
@@ -38,6 +38,8 @@#define IMX219_MODE_STANDBY 0x00#define IMX219_MODE_STREAMING 0x01 +#define IMX219_REG_CSI_CH_ID CCI_REG8(0x0110) +#define IMX219_REG_CSI_LANE_MODE CCI_REG8(0x0114)#define IMX219_CSI_2_LANE_MODE 0x01#define IMX219_CSI_4_LANE_MODE 0x03
@@ -363,6 +365,9 @@ struct imx219 {/* Two or Four lanes */ u8 lanes; + +/* Virtual channel ID */ +u8 vc_id; };static inline struct imx219 *to_imx219 (struct v4l2_subdev *_sd)
@@ -724,6 +729,12 @@ static int imx219_configure_lanes(struct imx219 *imx219) ARRAY_SIZE(imx219_4lane_regs), NULL); }; +static int imx219_configure_vc (struct imx219 *imx219) +{ +return cci_write (imx219->regmap,IMX219_REG_CSI_CH_ID , + imx219->vc_id,NULL ); +} +static int imx219_start_streaming (struct imx219 *imx219,struct v4l2_subdev_state *state) {
@@ -749,6 +760,11 @@ static int imx219_start_streaming(struct imx219 *imx219, goto err_rpm_put; } +/* Configure Virtual Channel ID */ + ret =imx219_configure_vc (imx219); +if (ret) +return ret; +/* Apply format and crop settings. */ ret =imx219_set_framefmt (imx219, state);if (ret) {
@@ -994,6 +1010,7 @@ static int imx219_init_state(struct v4l2_subdev *sd,static int imx219_get_frame_desc (struct v4l2_subdev *sd,unsigned int pad,struct v4l2_mbus_frame_desc *fd) { +struct imx219 *imx219 =to_imx219 (sd);struct v4l2_subdev_state *state;u32 code;
@@ -1006,7 +1023,7 @@ static int imx219_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad, fd->entry[0 ].pixelcode = code; fd->entry[0 ].stream =0 ; - fd->entry[0 ].bus.csi2.vc =0 ; + fd->entry[0 ].bus.csi2.vc = imx219->vc_id; fd->entry[0 ].bus.csi2.dt =imx219_get_format_bpp (code) ==8 ?MIPI_CSI2_DT_RAW8 :MIPI_CSI2_DT_RAW10 ;
@@ -1149,6 +1166,13 @@ static int imx219_check_hwcfg(struct device *dev, struct imx219 *imx219) } imx219->lanes = ep_cfg.bus.mipi_csi2.num_data_lanes; +if (ep_cfg.bus.mipi_csi2.num_vc_ids >1 ) { +dev_err_probe (dev, -EINVAL , +"only 1 virtual channel id is supported\n" ); + goto error_out; + } + imx219->vc_id = ep_cfg.bus.mipi_csi2.vc_ids[0 ]; +/* Check the link frequency set in device tree */ switch (imx219->lanes) {case 2 :
Signature · 1 line
2.48.1