Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: v4l: Add helper to get number of active lanes via a pad

Sometimes, users will not use all of the MIPI CSI 2 lanes available when
connecting to the MIPI CSI receiver of their device. Add a helper
function that checks the mbus_config for the device driver to allow
users to define the number of active data lanes through the
get_mbus_config op.

If the driver does not implement this op, fall back to using the maximum
number of lanes available.

Reviewed-by: Frank Li <Frank.Li@nxp.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Isaac Scott <isaac.scott@ideasonboard.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>

authored by

Isaac Scott and committed by
Hans Verkuil
fd3f646e ca042de6

+49
+29
drivers/media/v4l2-core/v4l2-common.c
··· 573 573 return v4l2_get_link_freq_ctrl(sd->ctrl_handler, mul, div); 574 574 } 575 575 EXPORT_SYMBOL_GPL(v4l2_get_link_freq); 576 + 577 + int v4l2_get_active_data_lanes(const struct media_pad *pad, 578 + unsigned int max_data_lanes) 579 + { 580 + struct v4l2_mbus_config mbus_config = {}; 581 + struct v4l2_subdev *sd; 582 + unsigned int lanes; 583 + int ret; 584 + 585 + sd = media_entity_to_v4l2_subdev(pad->entity); 586 + ret = v4l2_subdev_call(sd, pad, get_mbus_config, pad->index, 587 + &mbus_config); 588 + if (ret < 0 && ret != -ENOIOCTLCMD) 589 + return ret; 590 + 591 + /* This relies on the mbus_config being zeroed at init time */ 592 + lanes = mbus_config.bus.mipi_csi2.num_data_lanes; 593 + if (!lanes) 594 + return max_data_lanes; 595 + 596 + if (lanes > max_data_lanes) { 597 + dev_dbg(sd->dev, "Active data lanes (%u) exceeds max (%u)\n", 598 + lanes, max_data_lanes); 599 + return -EINVAL; 600 + } 601 + 602 + return lanes; 603 + } 604 + EXPORT_SYMBOL_GPL(v4l2_get_active_data_lanes); 576 605 #endif 577 606 578 607 /*
+20
include/media/v4l2-common.h
··· 581 581 #ifdef CONFIG_MEDIA_CONTROLLER 582 582 s64 v4l2_get_link_freq(const struct media_pad *pad, unsigned int mul, 583 583 unsigned int div); 584 + 585 + /** 586 + * v4l2_get_active_data_lanes - Get number of active data lanes from driver 587 + * 588 + * @pad: The transmitter's media pad. 589 + * @max_data_lanes: The maximum number of active data lanes supported by 590 + * the MIPI CSI link in hardware. 591 + * 592 + * This function is intended for obtaining the number of data lanes that are 593 + * actively being used by the driver for a MIPI CSI-2 device on a given media pad. 594 + * This information is derived from a mbus_config fetched from a device driver 595 + * using the get_mbus_config v4l2_subdev pad op. 596 + * 597 + * Return: 598 + * * >0: Number of active data lanes 599 + * * %-EINVAL: Number of active data lanes is invalid, as it exceeds the maximum 600 + * supported data lanes. 601 + */ 602 + int v4l2_get_active_data_lanes(const struct media_pad *pad, 603 + unsigned int max_data_lanes); 584 604 #endif 585 605 586 606 void v4l2_simplify_fraction(u32 *numerator, u32 *denominator,