diff options
Diffstat (limited to 'drivers/gpu/drm/drm_of.c')
| -rw-r--r-- | drivers/gpu/drm/drm_of.c | 63 | 
1 files changed, 63 insertions, 0 deletions
| diff --git a/drivers/gpu/drm/drm_of.c b/drivers/gpu/drm/drm_of.c index 9a2cfab3a177..7bbcb999bb75 100644 --- a/drivers/gpu/drm/drm_of.c +++ b/drivers/gpu/drm/drm_of.c @@ -2,6 +2,8 @@  #include <linux/component.h>  #include <linux/export.h>  #include <linux/list.h> +#include <linux/media-bus-format.h> +#include <linux/of.h>  #include <linux/of_graph.h>  #include <drm/drm_bridge.h> @@ -430,3 +432,64 @@ int drm_of_lvds_get_data_mapping(const struct device_node *port)  	return -EINVAL;  }  EXPORT_SYMBOL_GPL(drm_of_lvds_get_data_mapping); + +/** + * drm_of_get_data_lanes_count - Get DSI/(e)DP data lane count + * @endpoint: DT endpoint node of the DSI/(e)DP source or sink + * @min: minimum supported number of data lanes + * @max: maximum supported number of data lanes + * + * Count DT "data-lanes" property elements and check for validity. + * + * Return: + * * min..max - positive integer count of "data-lanes" elements + * * -ve - the "data-lanes" property is missing or invalid + * * -EINVAL - the "data-lanes" property is unsupported + */ +int drm_of_get_data_lanes_count(const struct device_node *endpoint, +				const unsigned int min, const unsigned int max) +{ +	int ret; + +	ret = of_property_count_u32_elems(endpoint, "data-lanes"); +	if (ret < 0) +		return ret; + +	if (ret < min || ret > max) +		return -EINVAL; + +	return ret; +} +EXPORT_SYMBOL_GPL(drm_of_get_data_lanes_count); + +/** + * drm_of_get_data_lanes_count_ep - Get DSI/(e)DP data lane count by endpoint + * @port: DT port node of the DSI/(e)DP source or sink + * @port_reg: identifier (value of reg property) of the parent port node + * @reg: identifier (value of reg property) of the endpoint node + * @min: minimum supported number of data lanes + * @max: maximum supported number of data lanes + * + * Count DT "data-lanes" property elements and check for validity. + * This variant uses endpoint specifier. + * + * Return: + * * min..max - positive integer count of "data-lanes" elements + * * -EINVAL - the "data-mapping" property is unsupported + * * -ENODEV - the "data-mapping" property is missing + */ +int drm_of_get_data_lanes_count_ep(const struct device_node *port, +				   int port_reg, int reg, +				   const unsigned int min, +				   const unsigned int max) +{ +	struct device_node *endpoint; +	int ret; + +	endpoint = of_graph_get_endpoint_by_regs(port, port_reg, reg); +	ret = drm_of_get_data_lanes_count(endpoint, min, max); +	of_node_put(endpoint); + +	return ret; +} +EXPORT_SYMBOL_GPL(drm_of_get_data_lanes_count_ep); | 
