Message ID | 20220519112657.62283-1-marex@denx.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [01/11] drm: of: Add drm_of_get_data_lanes and drm_of_get_data_lanes_ep | expand |
On 19.05.2022 13:26, Marek Vasut wrote: > Add helper function to count and sanitize DT "data-lanes" property > and return either error or the data-lanes count. This is useful for > both DSI and (e)DP "data-lanes" property. The later version of the > function is an extra wrapper which handles the endpoint look up by > regs, that's what majority of the drivers duplicate too, but not all > of them. > > Signed-off-by: Marek Vasut <marex@denx.de> > Cc: Andrzej Hajda <andrzej.hajda@intel.com> > Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > Cc: Lucas Stach <l.stach@pengutronix.de> > Cc: Maxime Ripard <maxime@cerno.tech> > Cc: Robert Foss <robert.foss@linaro.org> > Cc: Sam Ravnborg <sam@ravnborg.org> > To: dri-devel@lists.freedesktop.org > --- > drivers/gpu/drm/drm_of.c | 61 ++++++++++++++++++++++++++++++++++++++++ > include/drm/drm_of.h | 20 +++++++++++++ > 2 files changed, 81 insertions(+) > > diff --git a/drivers/gpu/drm/drm_of.c b/drivers/gpu/drm/drm_of.c > index 9a2cfab3a177f..2186f966d2820 100644 > --- a/drivers/gpu/drm/drm_of.c > +++ b/drivers/gpu/drm/drm_of.c > @@ -430,3 +430,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 - 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(const struct device_node *endpoint, > + const unsigned int min, const unsigned int max) Adding count to the name would be more accurate, for example drm_of_get_data_lanes_count ? Up to you. Reviewed-by: Andrzej Hajda <andrzej.hajda@intel.com> Regards Andrzej > +{ > + 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); > + > +/** > + * drm_of_get_data_lanes_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_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(endpoint, min, max); > + of_node_put(endpoint); > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(drm_of_get_data_lanes_ep); > diff --git a/include/drm/drm_of.h b/include/drm/drm_of.h > index 99f79ac8b4cd7..b559c53756196 100644 > --- a/include/drm/drm_of.h > +++ b/include/drm/drm_of.h > @@ -50,6 +50,12 @@ int drm_of_find_panel_or_bridge(const struct device_node *np, > int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1, > const struct device_node *port2); > int drm_of_lvds_get_data_mapping(const struct device_node *port); > +int drm_of_get_data_lanes(const struct device_node *endpoint, > + const unsigned int min, const unsigned int max); > +int drm_of_get_data_lanes_ep(const struct device_node *port, > + int port_reg, int reg, > + const unsigned int min, > + const unsigned int max); > #else > static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev, > struct device_node *port) > @@ -105,6 +111,20 @@ drm_of_lvds_get_data_mapping(const struct device_node *port) > { > return -EINVAL; > } > + > +int drm_of_get_data_lanes(const struct device_node *endpoint, > + const unsigned int min, const unsigned int max) > +{ > + return -EINVAL; > +} > + > +int drm_of_get_data_lanes_ep(const struct device_node *port, > + int port_reg, int reg > + const unsigned int min, > + const unsigned int max) > +{ > + return -EINVAL; > +} > #endif > > /*
diff --git a/drivers/gpu/drm/drm_of.c b/drivers/gpu/drm/drm_of.c index 9a2cfab3a177f..2186f966d2820 100644 --- a/drivers/gpu/drm/drm_of.c +++ b/drivers/gpu/drm/drm_of.c @@ -430,3 +430,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 - 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(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); + +/** + * drm_of_get_data_lanes_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_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(endpoint, min, max); + of_node_put(endpoint); + + return ret; +} +EXPORT_SYMBOL_GPL(drm_of_get_data_lanes_ep); diff --git a/include/drm/drm_of.h b/include/drm/drm_of.h index 99f79ac8b4cd7..b559c53756196 100644 --- a/include/drm/drm_of.h +++ b/include/drm/drm_of.h @@ -50,6 +50,12 @@ int drm_of_find_panel_or_bridge(const struct device_node *np, int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1, const struct device_node *port2); int drm_of_lvds_get_data_mapping(const struct device_node *port); +int drm_of_get_data_lanes(const struct device_node *endpoint, + const unsigned int min, const unsigned int max); +int drm_of_get_data_lanes_ep(const struct device_node *port, + int port_reg, int reg, + const unsigned int min, + const unsigned int max); #else static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev, struct device_node *port) @@ -105,6 +111,20 @@ drm_of_lvds_get_data_mapping(const struct device_node *port) { return -EINVAL; } + +int drm_of_get_data_lanes(const struct device_node *endpoint, + const unsigned int min, const unsigned int max) +{ + return -EINVAL; +} + +int drm_of_get_data_lanes_ep(const struct device_node *port, + int port_reg, int reg + const unsigned int min, + const unsigned int max) +{ + return -EINVAL; +} #endif /*
Add helper function to count and sanitize DT "data-lanes" property and return either error or the data-lanes count. This is useful for both DSI and (e)DP "data-lanes" property. The later version of the function is an extra wrapper which handles the endpoint look up by regs, that's what majority of the drivers duplicate too, but not all of them. Signed-off-by: Marek Vasut <marex@denx.de> Cc: Andrzej Hajda <andrzej.hajda@intel.com> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Cc: Lucas Stach <l.stach@pengutronix.de> Cc: Maxime Ripard <maxime@cerno.tech> Cc: Robert Foss <robert.foss@linaro.org> Cc: Sam Ravnborg <sam@ravnborg.org> To: dri-devel@lists.freedesktop.org --- drivers/gpu/drm/drm_of.c | 61 ++++++++++++++++++++++++++++++++++++++++ include/drm/drm_of.h | 20 +++++++++++++ 2 files changed, 81 insertions(+)