drm: of: Add drm_of_get_data_lanes_count and drm_of_get_data_lanes_ep
Subsystems (8)
PATCH v2 1/11 drm: of: Add drm_of_get_data_lanes_count and drm_of_get_data_lanes_ep
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.
To: [email protected]
---
V2: - Rename drm_of_get_data_lanes{,_ep} to drm_of_get_data_lanes_count{,_ep}
- Add RB from Andrzej
--- drivers/gpu/drm/drm_of.c | 61 ++++++++++++++++++++++++++++++++++++++++ include/drm/drm_of.h | 20 +++++++++++++ 2 files changed, 81 insertions(+)
drivers/gpu/drm/drm_of.c +61 -0
@@ -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_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);
include/drm/drm_of.h +20 -0
@@ -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_count (const struct device_node *endpoint, +const unsigned int min,const unsigned int max); +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);#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_count (const struct device_node *endpoint, +const unsigned int min,const unsigned int max) +{ +return -EINVAL ; +} + +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) +{ +return -EINVAL ; +}#endif /*
Signature · 1 line
2.35.1
PATCH v2 2/11 drm/bridge: anx7625: Convert to drm_of_get_data_lanes_count
Convert driver to use this new helper to standardize OF "data-lanes" parsing.
To: [email protected]
---
V2: - Rename drm_of_get_data_lanes{,_ep} to drm_of_get_data_lanes_count{,_ep}
- Add RB from Andrzej
--- drivers/gpu/drm/bridge/analogix/anx7625.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/bridge/analogix/anx7625.c +4 -4
@@ -1637,16 +1637,16 @@ static int anx7625_parse_dt(struct device *dev,if (of_property_read_u32 (ep0,"bus-type" , &bus_type)) bus_type =0 ; - mipi_lanes =of_property_count_u32_elems (ep0,"data-lanes" ); + mipi_lanes =drm_of_get_data_lanes_count (ep0,1 ,MAX_LANES_SUPPORT );of_node_put (ep0); }if (bus_type ==V4L2_FWNODE_BUS_TYPE_PARALLEL )/* bus type is Parallel(DSI) */ pdata->is_dpi =0 ; - pdata->mipi_lanes = mipi_lanes; -if (pdata->mipi_lanes >MAX_LANES_SUPPORT || pdata->mipi_lanes <=0 ) - pdata->mipi_lanes =MAX_LANES_SUPPORT ; + pdata->mipi_lanes =MAX_LANES_SUPPORT ; +if (mipi_lanes >0 ) + pdata->mipi_lanes = mipi_lanes;if (pdata->is_dpi)DRM_DEV_DEBUG_DRIVER (dev,"found MIPI DPI host node.\n" );
Signature · 1 line
2.35.1
PATCH v2 3/11 drm/bridge: icn6211: Convert to drm_of_get_data_lanes_count_ep
In reply to Marek VasutConvert driver to use this new helper to standardize OF "data-lanes" parsing.
To: [email protected]
---
V2: - Rename drm_of_get_data_lanes{,_ep} to drm_of_get_data_lanes_count{,_ep}
- Add RB from Andrzej
--- drivers/gpu/drm/bridge/chipone-icn6211.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/gpu/drm/bridge/chipone-icn6211.c +4 -7
@@ -496,21 +496,18 @@ static int chipone_dsi_attach(struct chipone *icn) {struct mipi_dsi_device *dsi = icn->dsi;struct device *dev = icn->dev; -struct device_node *endpoint;int dsi_lanes, ret; - endpoint =of_graph_get_endpoint_by_regs (dev->of_node,0 ,0 ); - dsi_lanes =of_property_count_u32_elems (endpoint,"data-lanes" ); -of_node_put (endpoint); + dsi_lanes =drm_of_get_data_lanes_count_ep (dev->of_node,0 ,0 ,1 ,4 );/* * If the 'data-lanes' property does not exist in DT or is invalid, * default to previously hard-coded behavior, which was 4 data lanes. */ -if (dsi_lanes >=1 && dsi_lanes <=4 ) - icn->dsi->lanes = dsi_lanes; -else +if (dsi_lanes <0 ) icn->dsi->lanes =4 ; +else + icn->dsi->lanes = dsi_lanes; dsi->format =MIPI_DSI_FMT_RGB888 ; dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST |
Signature · 1 line
2.35.1
PATCH v2 4/11 drm/bridge: lt8912: Convert to drm_of_get_data_lanes_count_ep
In reply to Marek VasutConvert driver to use this new helper to standardize OF "data-lanes" parsing.
To: [email protected]
---
V2: - Rename drm_of_get_data_lanes{,_ep} to drm_of_get_data_lanes_count{,_ep}
- Add RB from Andrzej
--- drivers/gpu/drm/bridge/lontium-lt8912b.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/gpu/drm/bridge/lontium-lt8912b.c +2 -7
@@ -607,7 +607,6 @@ static int lt8912_parse_dt(struct lt8912 *lt)int ret;int data_lanes;struct device_node *port_node; -struct device_node *endpoint; gp_reset =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_HIGH );if (IS_ERR (gp_reset)) {
@@ -618,16 +617,12 @@ static int lt8912_parse_dt(struct lt8912 *lt) } lt->gp_reset = gp_reset; - endpoint =of_graph_get_endpoint_by_regs (dev->of_node,0 ,-1 ); -if (!endpoint) -return -ENODEV ; - - data_lanes =of_property_count_u32_elems (endpoint,"data-lanes" ); -of_node_put (endpoint); + data_lanes =drm_of_get_data_lanes_count_ep (dev->of_node,0 ,-1 ,1 ,4 );if (data_lanes <0 ) {dev_err (lt->dev,"%s: Bad data-lanes property\n" , __func__);return data_lanes; } + lt->data_lanes = data_lanes; lt->host_node =of_graph_get_remote_node (dev->of_node,0 ,-1 );
Signature · 1 line
2.35.1
PATCH v2 5/11 drm/bridge: lt9211: Convert to drm_of_get_data_lanes_count
In reply to Marek VasutConvert driver to use this new helper to standardize OF "data-lanes" parsing.
To: [email protected]
---
V2: - Rename drm_of_get_data_lanes{,_ep} to drm_of_get_data_lanes_count{,_ep}
- Add RB from Andrzej
--- drivers/gpu/drm/bridge/lontium-lt9211.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/bridge/lontium-lt9211.c +3 -3
@@ -686,7 +686,7 @@ static int lt9211_host_attach(struct lt9211 *ctx)int ret; endpoint =of_graph_get_endpoint_by_regs (dev->of_node,0 ,-1 ); - dsi_lanes =of_property_count_u32_elems (endpoint,"data-lanes" ); + dsi_lanes =drm_of_get_data_lanes_count (endpoint,1 ,4 ); host_node =of_graph_get_remote_port_parent (endpoint); host =of_find_mipi_dsi_host_by_node (host_node);of_node_put (host_node);
@@ -695,8 +695,8 @@ static int lt9211_host_attach(struct lt9211 *ctx)if (!host)return -EPROBE_DEFER ; -if (dsi_lanes <0 || dsi_lanes >4 ) -return -EINVAL ; +if (dsi_lanes <0 ) +return dsi_lanes; dsi =devm_mipi_dsi_device_register_full (dev, host, &info);if (IS_ERR (dsi))
Signature · 1 line
2.35.1
PATCH v2 6/11 drm/bridge: tc358767: Convert to drm_of_get_data_lanes_count
In reply to Marek VasutConvert driver to use this new helper to standardize OF "data-lanes" parsing.
To: [email protected]
---
V2: - Rename drm_of_get_data_lanes{,_ep} to drm_of_get_data_lanes_count{,_ep}
- Add RB from Andrzej
--- drivers/gpu/drm/bridge/tc358767.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/bridge/tc358767.c +4 -4
@@ -1889,18 +1889,18 @@ static int tc_mipi_dsi_host_attach(struct tc_data *tc)int dsi_lanes, ret; endpoint =of_graph_get_endpoint_by_regs (dev->of_node,0 ,-1 ); - dsi_lanes =of_property_count_u32_elems (endpoint,"data-lanes" ); + dsi_lanes =drm_of_get_data_lanes_count (endpoint,1 ,4 ); host_node =of_graph_get_remote_port_parent (endpoint); host =of_find_mipi_dsi_host_by_node (host_node);of_node_put (host_node);of_node_put (endpoint); -if (dsi_lanes <=0 || dsi_lanes >4 ) -return -EINVAL ; -if (!host)return -EPROBE_DEFER ; +if (dsi_lanes <0 ) +return dsi_lanes; + dsi =mipi_dsi_device_register_full (host, &info);if (IS_ERR (dsi)) return dev_err_probe(dev, PTR_ERR(dsi),
Signature · 1 line
2.35.1
PATCH v2 7/11 drm/bridge: tc358775: Convert to drm_of_get_data_lanes_count_ep
In reply to Marek VasutConvert driver to use this new helper to standardize OF "data-lanes" parsing.
To: [email protected]
---
V2: - Rename drm_of_get_data_lanes{,_ep} to drm_of_get_data_lanes_count{,_ep}
- Drop now unused prop and len local variables
- Add RB from Andrzej
--- drivers/gpu/drm/bridge/tc358775.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-)
drivers/gpu/drm/bridge/tc358775.c +5 -16
@@ -529,8 +529,7 @@ static int tc358775_parse_dt(struct device_node *np, struct tc_data *tc)struct device_node *endpoint;struct device_node *parent;struct device_node *remote; -struct property *prop; -int len =0 ; +int dsi_lanes;/* * To get the data-lanes of dsi, we need to access the dsi0_out of port1
@@ -544,25 +543,15 @@ static int tc358775_parse_dt(struct device_node *np, struct tc_data *tc)of_node_put (endpoint);if (parent) {/* dsi0 port 1 */ - endpoint =of_graph_get_endpoint_by_regs (parent,1 ,-1 ); + dsi_lanes =drm_of_get_data_lanes_count_ep (parent,1 ,-1 ,1 ,4 );of_node_put (parent); -if (endpoint) { - prop =of_find_property (endpoint,"data-lanes" , - &len); -of_node_put (endpoint); -if (!prop) { -dev_err (tc->dev, -"failed to find data lane\n" ); -return -EPROBE_DEFER ; - } - } } } - tc->num_dsi_lanes = len /sizeof (u32); +if (dsi_lanes <0 ) +return dsi_lanes; -if (tc->num_dsi_lanes <1 || tc->num_dsi_lanes >4 ) -return -EINVAL ; + tc->num_dsi_lanes = dsi_lanes; tc->host_node =of_graph_get_remote_node (np,0 ,0 );if (!tc->host_node)
Signature · 1 line
2.35.1
PATCH v2 8/11 drm/bridge: ti-sn65dsi83: Convert to drm_of_get_data_lanes_count
In reply to Marek VasutConvert driver to use this new helper to standardize OF "data-lanes" parsing.
To: [email protected]
---
V2: - Rename drm_of_get_data_lanes{,_ep} to drm_of_get_data_lanes_count{,_ep}
- Add RB from Andrzej
--- drivers/gpu/drm/bridge/ti-sn65dsi83.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/ti-sn65dsi83.c +1 -1
@@ -628,7 +628,7 @@ static int sn65dsi83_host_attach(struct sn65dsi83 *ctx)int dsi_lanes, ret; endpoint =of_graph_get_endpoint_by_regs (dev->of_node,0 ,-1 ); - dsi_lanes =of_property_count_u32_elems (endpoint,"data-lanes" ); + dsi_lanes =drm_of_get_data_lanes_count (endpoint,1 ,4 ); host_node =of_graph_get_remote_port_parent (endpoint); host =of_find_mipi_dsi_host_by_node (host_node);of_node_put (host_node);
Signature · 1 line
2.35.1
Marek Vasut
AppliedRe: [PATCH v2 08/11] drm/bridge: ti-sn65dsi83: Convert to drm_of_get_data_lanes_count
Quoted 2 lines · Marek Vasut
Convert driver to use this new helper to standardize OF "data-lanes" parsing.
Applied all to drm-misc-next except for this particular patch, which depends on yet unreviewed deduplication patch. Both remaining patches are resubmitted:
https://patchwork.freedesktop.org/patch/489197/
https://patchwork.freedesktop.org/patch/489198/
PATCH v2 9/11 drm/bridge: ti-sn65dsi86: Convert to drm_of_get_data_lanes_count
In reply to Marek VasutConvert driver to use this new helper to standardize OF "data-lanes" parsing.
To: [email protected]
---
V2: - Rename drm_of_get_data_lanes{,_ep} to drm_of_get_data_lanes_count{,_ep}
- Add RB from Andrzej
--- drivers/gpu/drm/bridge/ti-sn65dsi86.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/bridge/ti-sn65dsi86.c +2 -2
@@ -1142,8 +1142,8 @@ static void ti_sn_bridge_parse_lanes(struct ti_sn65dsi86 *pdata,* mappings that the hardware supports. */ endpoint =of_graph_get_endpoint_by_regs (np,1 ,-1 ); - dp_lanes =of_property_count_u32_elems (endpoint,"data-lanes" ); -if (dp_lanes >0 && dp_lanes <=SN_MAX_DP_LANES ) { + dp_lanes =drm_of_get_data_lanes_count (endpoint,1 ,SN_MAX_DP_LANES ); +if (dp_lanes >0 ) {of_property_read_u32_array (endpoint,"data-lanes" , lane_assignments, dp_lanes); of_property_read_u32_array(endpoint, "lane-polarities",
Signature · 1 line
2.35.1
PATCH v2 10/11 drm/msm: Convert to drm_of_get_data_lanes_count
In reply to Marek VasutConvert driver to use this new helper to standardize OF "data-lanes" parsing.
To: [email protected]
---
V2: - Use drm/msm prefix
- Rename drm_of_get_data_lanes{,_ep} to drm_of_get_data_lanes_count{,_ep}
- Add RB from Andrzej and Dmitry
--- drivers/gpu/drm/msm/dp/dp_parser.c | 6 ++---- drivers/gpu/drm/msm/dsi/dsi_host.c | 7 +++---- 2 files changed, 5 insertions(+), 8 deletions(-)
drivers/gpu/drm/msm/dp/dp_parser.c +2 -4
@@ -102,11 +102,9 @@ static int dp_parser_ctrl_res(struct dp_parser *parser)static int dp_parser_misc (struct dp_parser *parser) {struct device_node *of_node = parser->pdev->dev.of_node; -int len =0 ; -const char *data_lane_property ="data-lanes" ; +int len; - len =of_property_count_elems_of_size (of_node, - data_lane_property,sizeof (u32)); + len =drm_of_get_data_lanes_count (of_node,1 ,DP_MAX_NUM_DP_LANES );if (len <0 ) {DRM_WARN ("Invalid property %s, default max DP lanes = %d\n" , data_lane_property,DP_MAX_NUM_DP_LANES );
drivers/gpu/drm/msm/dsi/dsi_host.c +3 -4
@@ -1779,11 +1779,10 @@ static int dsi_host_parse_lane_data(struct msm_dsi_host *msm_host,return 0 ; } - num_lanes = len /sizeof (u32); - -if (num_lanes <1 || num_lanes >4 ) { + num_lanes =drm_of_get_data_lanes_count (ep,1 ,4 ); +if (num_lanes <0 ) {DRM_DEV_ERROR (dev,"bad number of data lanes\n" ); -return -EINVAL ; +return num_lanes; } msm_host->num_data_lanes = num_lanes;
Signature · 1 line
2.35.1
Re: [PATCH v2 10/11] drm/msm: Convert to drm_of_get_data_lanes_count
Quoted 6 lines · Marek Vasut
Convert driver to use this new helper to standardize OF "data-lanes" parsing.
Reviewed-by Andrzej Hajda <[email protected]>Reviewed-by Dmitry Baryshkov <[email protected]>Signed-off-by Marek Vasut <[email protected]>
Quoted 57 lines
Cc: Abhinav Kumar <[email protected]>
Cc: Andrzej Hajda <[email protected]>
Cc: Dmitry Baryshkov <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Lucas Stach <[email protected]>
Cc: Maxime Ripard <[email protected]>
Cc: Rob Clark <[email protected]>
Cc: Robert Foss <[email protected]>
Cc: Sam Ravnborg <[email protected]>
Cc: Sean Paul <[email protected]>
To: [email protected]
---
V2: - Use drm/msm prefix
- Rename drm_of_get_data_lanes{,_ep} to drm_of_get_data_lanes_count{,_ep}
- Add RB from Andrzej and Dmitry--- drivers/gpu/drm/msm/dp/dp_parser.c | 6 ++---- drivers/gpu/drm/msm/dsi/dsi_host.c | 7 +++---- 2 files changed, 5 insertions(+), 8 deletions(-)drivers/gpu/drm/msm/dp/dp_parser.c +2
-4@@ -102,11 +102,9 @@ static int dp_parser_ctrl_res(struct dp_parser *parser)static int dp_parser_misc (struct dp_parser *parser) {struct device_node *of_node = parser->pdev->dev.of_node; -int len =0 ; -const char *data_lane_property ="data-lanes" ; +int len; - len =of_property_count_elems_of_size (of_node, - data_lane_property,sizeof (u32)); + len =drm_of_get_data_lanes_count (of_node,1 ,DP_MAX_NUM_DP_LANES );if (len <0 ) {DRM_WARN ("Invalid property %s, default max DP lanes = %d\n" , data_lane_property,DP_MAX_NUM_DP_LANES );drivers/gpu/drm/msm/dsi/dsi_host.c +3
-4@@ -1779,11 +1779,10 @@ static int dsi_host_parse_lane_data(struct msm_dsi_host *msm_host,return 0 ; } - num_lanes = len /sizeof (u32); - -if (num_lanes <1 || num_lanes >4 ) { + num_lanes =drm_of_get_data_lanes_count (ep,1 ,4 ); +if (num_lanes <0 ) {DRM_DEV_ERROR (dev,"bad number of data lanes\n" ); -return -EINVAL ; +return num_lanes; } msm_host->num_data_lanes = num_lanes;
PATCH v2 11/11 drm/bridge: rcar: Convert to drm_of_get_data_lanes_count_ep
In reply to Marek VasutConvert driver to use this new helper to standardize OF "data-lanes" parsing.
To: [email protected]
---
V2: - Rename drm_of_get_data_lanes{,_ep} to drm_of_get_data_lanes_count{,_ep}
- Add RB from Andrzej
--- drivers/gpu/drm/rcar-du/rcar_mipi_dsi.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
drivers/gpu/drm/rcar-du/rcar_mipi_dsi.c +2 -11
@@ -683,19 +683,10 @@ static int rcar_mipi_dsi_parse_dt(struct rcar_mipi_dsi *dsi)u32 data_lanes[4 ];int ret; - ep =of_graph_get_endpoint_by_regs (dsi->dev->of_node,1 ,0 ); -if (!ep) { -dev_dbg (dsi->dev,"unconnected port@1\n" ); -return -ENODEV ; - } - - ret =of_property_read_variable_u32_array (ep,"data-lanes" , data_lanes, -1 ,4 ); -of_node_put (ep); - + ret =drm_of_get_data_lanes_count_ep (dsi->dev->of_node,1 ,0 ,1 ,4 );if (ret <0 ) {dev_err (dsi->dev,"missing or invalid data-lanes property\n" ); -return -ENODEV ; +return ret; } dsi->num_data_lanes = ret;
Signature · 1 line
2.35.1