Skip to content

Commit

Permalink
drm: convert drivers to use of_graph_get_remote_node
Browse files Browse the repository at this point in the history
Convert drivers to use the new of_graph_get_remote_node() helper
instead of parsing the endpoint node and then getting the remote device
node. Now drivers can just specify the device node and which
port/endpoint and get back the connected remote device node. The details
of the graph binding are nicely abstracted into the core OF graph code.

This changes some error messages to debug messages (in the graph core).
Graph connections are often "no connects" depending on the particular
board, so we want to avoid spurious messages. Plus the kernel is not a
DT validator.

Signed-off-by: Rob Herring <[email protected]>
Acked-by: Neil Armstrong <[email protected]>
Tested-by: Liviu Dudau <[email protected]>
Tested-by: Eric Anholt <[email protected]>
Tested-by: Jyri Sarha <[email protected]>
Tested by: Archit Taneja <[email protected]>
Signed-off-by: Sean Paul <[email protected]>
  • Loading branch information
robherring authored and atseanpaul committed Apr 6, 2017
1 parent 1f2db30 commit 86418f9
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 310 deletions.
22 changes: 3 additions & 19 deletions drivers/gpu/drm/arm/hdlcd_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,29 +392,13 @@ static int compare_dev(struct device *dev, void *data)

static int hdlcd_probe(struct platform_device *pdev)
{
struct device_node *port, *ep;
struct device_node *port;
struct component_match *match = NULL;

if (!pdev->dev.of_node)
return -ENODEV;

/* there is only one output port inside each device, find it */
ep = of_graph_get_next_endpoint(pdev->dev.of_node, NULL);
if (!ep)
return -ENODEV;

if (!of_device_is_available(ep)) {
of_node_put(ep);
port = of_graph_get_remote_node(pdev->dev.of_node, 0, 0);
if (!port)
return -ENODEV;
}

/* add the remote encoder port as component */
port = of_graph_get_remote_port_parent(ep);
of_node_put(ep);
if (!port || !of_device_is_available(port)) {
of_node_put(port);
return -EAGAIN;
}

drm_of_component_match_add(&pdev->dev, &match, compare_dev, port);
of_node_put(port);
Expand Down
28 changes: 4 additions & 24 deletions drivers/gpu/drm/arm/malidp_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ static int malidp_bind(struct device *dev)
{
struct resource *res;
struct drm_device *drm;
struct device_node *ep;
struct malidp_drm *malidp;
struct malidp_hw_device *hwdev;
struct platform_device *pdev = to_platform_device(dev);
Expand Down Expand Up @@ -398,12 +397,7 @@ static int malidp_bind(struct device *dev)
goto init_fail;

/* Set the CRTC's port so that the encoder component can find it */
ep = of_graph_get_next_endpoint(dev->of_node, NULL);
if (!ep) {
ret = -EINVAL;
goto port_fail;
}
malidp->crtc.port = of_get_next_parent(ep);
malidp->crtc.port = of_graph_get_port_by_id(dev->of_node, 0);

ret = component_bind_all(dev, drm);
if (ret) {
Expand Down Expand Up @@ -458,7 +452,6 @@ static int malidp_bind(struct device *dev)
bind_fail:
of_node_put(malidp->crtc.port);
malidp->crtc.port = NULL;
port_fail:
malidp_fini(drm);
init_fail:
drm->dev_private = NULL;
Expand Down Expand Up @@ -516,29 +509,16 @@ static int malidp_compare_dev(struct device *dev, void *data)

static int malidp_platform_probe(struct platform_device *pdev)
{
struct device_node *port, *ep;
struct device_node *port;
struct component_match *match = NULL;

if (!pdev->dev.of_node)
return -ENODEV;

/* there is only one output port inside each device, find it */
ep = of_graph_get_next_endpoint(pdev->dev.of_node, NULL);
if (!ep)
return -ENODEV;

if (!of_device_is_available(ep)) {
of_node_put(ep);
port = of_graph_get_remote_node(pdev->dev.of_node, 0, 0);
if (!port)
return -ENODEV;
}

/* add the remote encoder port as component */
port = of_graph_get_remote_port_parent(ep);
of_node_put(ep);
if (!port || !of_device_is_available(port)) {
of_node_put(port);
return -EAGAIN;
}

drm_of_component_match_add(&pdev->dev, &match, malidp_compare_dev,
port);
Expand Down
12 changes: 2 additions & 10 deletions drivers/gpu/drm/bridge/adv7511/adv7533.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ void adv7533_detach_dsi(struct adv7511 *adv)
int adv7533_parse_dt(struct device_node *np, struct adv7511 *adv)
{
u32 num_lanes;
struct device_node *endpoint;

of_property_read_u32(np, "adi,dsi-lanes", &num_lanes);

Expand All @@ -241,17 +240,10 @@ int adv7533_parse_dt(struct device_node *np, struct adv7511 *adv)

adv->num_dsi_lanes = num_lanes;

endpoint = of_graph_get_next_endpoint(np, NULL);
if (!endpoint)
adv->host_node = of_graph_get_remote_node(np, 0, 0);
if (!adv->host_node)
return -ENODEV;

adv->host_node = of_graph_get_remote_port_parent(endpoint);
if (!adv->host_node) {
of_node_put(endpoint);
return -ENODEV;
}

of_node_put(endpoint);
of_node_put(adv->host_node);

adv->use_timing_gen = !of_property_read_bool(np,
Expand Down
15 changes: 3 additions & 12 deletions drivers/gpu/drm/bridge/dumb-vga-dac.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,12 @@ static const struct drm_bridge_funcs dumb_vga_bridge_funcs = {

static struct i2c_adapter *dumb_vga_retrieve_ddc(struct device *dev)
{
struct device_node *end_node, *phandle, *remote;
struct device_node *phandle, *remote;
struct i2c_adapter *ddc;

end_node = of_graph_get_endpoint_by_regs(dev->of_node, 1, -1);
if (!end_node) {
dev_err(dev, "Missing connector endpoint\n");
return ERR_PTR(-ENODEV);
}

remote = of_graph_get_remote_port_parent(end_node);
of_node_put(end_node);
if (!remote) {
dev_err(dev, "Enable to parse remote node\n");
remote = of_graph_get_remote_node(dev->of_node, 1, -1);
if (!remote)
return ERR_PTR(-EINVAL);
}

phandle = of_parse_phandle(remote, "ddc-i2c-bus", 0);
of_node_put(remote);
Expand Down
15 changes: 5 additions & 10 deletions drivers/gpu/drm/bridge/ti-tfp410.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,13 @@ static irqreturn_t tfp410_hpd_irq_thread(int irq, void *arg)

static int tfp410_get_connector_properties(struct tfp410 *dvi)
{
struct device_node *ep = NULL, *connector_node = NULL;
struct device_node *ddc_phandle = NULL;
struct device_node *connector_node, *ddc_phandle;
int ret = 0;

/* port@1 is the connector node */
ep = of_graph_get_endpoint_by_regs(dvi->dev->of_node, 1, -1);
if (!ep)
goto fail;

connector_node = of_graph_get_remote_port_parent(ep);
connector_node = of_graph_get_remote_node(dvi->dev->of_node, 1, -1);
if (!connector_node)
goto fail;
return -ENODEV;

dvi->hpd = fwnode_get_named_gpiod(&connector_node->fwnode,
"hpd-gpios", 0, GPIOD_IN, "hpd");
Expand All @@ -199,10 +194,10 @@ static int tfp410_get_connector_properties(struct tfp410 *dvi)
else
ret = -EPROBE_DEFER;

of_node_put(ddc_phandle);

fail:
of_node_put(ep);
of_node_put(connector_node);
of_node_put(ddc_phandle);
return ret;
}

Expand Down
16 changes: 1 addition & 15 deletions drivers/gpu/drm/exynos/exynos_drm_dpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,27 +163,13 @@ enum {
FIMD_PORT_WRB,
};

static struct device_node *exynos_dpi_of_find_panel_node(struct device *dev)
{
struct device_node *np, *ep;

ep = of_graph_get_endpoint_by_regs(dev->of_node, FIMD_PORT_RGB, 0);
if (!ep)
return NULL;

np = of_graph_get_remote_port_parent(ep);
of_node_put(ep);

return np;
}

static int exynos_dpi_parse_dt(struct exynos_dpi *ctx)
{
struct device *dev = ctx->dev;
struct device_node *dn = dev->of_node;
struct device_node *np;

ctx->panel_node = exynos_dpi_of_find_panel_node(dev);
ctx->panel_node = of_graph_get_remote_node(dn, FIMD_PORT_RGB, 0);

np = of_get_child_by_name(dn, "display-timings");
if (np) {
Expand Down
13 changes: 3 additions & 10 deletions drivers/gpu/drm/exynos/exynos_drm_dsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1659,17 +1659,10 @@ static int exynos_dsi_parse_dt(struct exynos_dsi *dsi)

of_node_put(ep);

ep = of_graph_get_next_endpoint(node, NULL);
if (!ep) {
ret = -EINVAL;
goto end;
}
dsi->bridge_node = of_graph_get_remote_node(node, DSI_PORT_OUT, 0);
if (!dsi->bridge_node)
return -EINVAL;

dsi->bridge_node = of_graph_get_remote_port_parent(ep);
if (!dsi->bridge_node) {
ret = -EINVAL;
goto end;
}
end:
of_node_put(ep);

Expand Down
25 changes: 1 addition & 24 deletions drivers/gpu/drm/exynos/exynos_drm_mic.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,29 +229,6 @@ static void mic_set_reg_on(struct exynos_mic *mic, bool enable)
writel(reg, mic->reg + MIC_OP);
}

static struct device_node *get_remote_node(struct device_node *from, int reg)
{
struct device_node *endpoint = NULL, *remote_node = NULL;

endpoint = of_graph_get_endpoint_by_regs(from, reg, -1);
if (!endpoint) {
DRM_ERROR("mic: Failed to find remote port from %s",
from->full_name);
goto exit;
}

remote_node = of_graph_get_remote_port_parent(endpoint);
if (!remote_node) {
DRM_ERROR("mic: Failed to find remote port parent from %s",
from->full_name);
goto exit;
}

exit:
of_node_put(endpoint);
return remote_node;
}

static int parse_dt(struct exynos_mic *mic)
{
int ret = 0, i, j;
Expand All @@ -263,7 +240,7 @@ static int parse_dt(struct exynos_mic *mic)
* The first node must be for decon and the second one must be for dsi.
*/
for (i = 0, j = 0; i < NUM_ENDPOINTS; i++) {
remote_node = get_remote_node(mic->dev->of_node, i);
remote_node = of_graph_get_remote_node(mic->dev->of_node, i, 0);
if (!remote_node) {
ret = -EPIPE;
goto exit;
Expand Down
30 changes: 1 addition & 29 deletions drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,34 +230,6 @@ static const struct component_master_ops kirin_drm_ops = {
.unbind = kirin_drm_unbind,
};

static struct device_node *kirin_get_remote_node(struct device_node *np)
{
struct device_node *endpoint, *remote;

/* get the first endpoint, in our case only one remote node
* is connected to display controller.
*/
endpoint = of_graph_get_next_endpoint(np, NULL);
if (!endpoint) {
DRM_ERROR("no valid endpoint node\n");
return ERR_PTR(-ENODEV);
}

remote = of_graph_get_remote_port_parent(endpoint);
of_node_put(endpoint);
if (!remote) {
DRM_ERROR("no valid remote node\n");
return ERR_PTR(-ENODEV);
}

if (!of_device_is_available(remote)) {
DRM_ERROR("not available for remote node\n");
return ERR_PTR(-ENODEV);
}

return remote;
}

static int kirin_drm_platform_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
Expand All @@ -271,7 +243,7 @@ static int kirin_drm_platform_probe(struct platform_device *pdev)
return -EINVAL;
}

remote = kirin_get_remote_node(np);
remote = of_graph_get_remote_node(np, 0, 0);
if (IS_ERR(remote))
return PTR_ERR(remote);

Expand Down
12 changes: 3 additions & 9 deletions drivers/gpu/drm/mediatek/mtk_dpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ static int mtk_dpi_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
struct mtk_dpi *dpi;
struct resource *mem;
struct device_node *ep, *bridge_node = NULL;
struct device_node *bridge_node;
int comp_id;
int ret;

Expand Down Expand Up @@ -706,15 +706,9 @@ static int mtk_dpi_probe(struct platform_device *pdev)
return -EINVAL;
}

ep = of_graph_get_next_endpoint(dev->of_node, NULL);
if (ep) {
bridge_node = of_graph_get_remote_port_parent(ep);
of_node_put(ep);
}
if (!bridge_node) {
dev_err(dev, "Failed to find bridge node\n");
bridge_node = of_graph_get_remote_node(dev->of_node, 0, 0);
if (!bridge_node)
return -ENODEV;
}

dev_info(dev, "Found bridge node: %s\n", bridge_node->full_name);

Expand Down
26 changes: 3 additions & 23 deletions drivers/gpu/drm/mediatek/mtk_hdmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ static int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi *hdmi,
{
struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
struct device_node *cec_np, *port, *ep, *remote, *i2c_np;
struct device_node *cec_np, *remote, *i2c_np;
struct platform_device *cec_pdev;
struct regmap *regmap;
struct resource *mem;
Expand Down Expand Up @@ -1486,29 +1486,9 @@ static int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi *hdmi,
if (IS_ERR(hdmi->regs))
return PTR_ERR(hdmi->regs);

port = of_graph_get_port_by_id(np, 1);
if (!port) {
dev_err(dev, "Missing output port node\n");
remote = of_graph_get_remote_node(np, 1, 0);
if (!remote)
return -EINVAL;
}

ep = of_get_child_by_name(port, "endpoint");
if (!ep) {
dev_err(dev, "Missing endpoint node in port %s\n",
port->full_name);
of_node_put(port);
return -EINVAL;
}
of_node_put(port);

remote = of_graph_get_remote_port_parent(ep);
if (!remote) {
dev_err(dev, "Missing connector/bridge node for endpoint %s\n",
ep->full_name);
of_node_put(ep);
return -EINVAL;
}
of_node_put(ep);

if (!of_device_is_compatible(remote, "hdmi-connector")) {
hdmi->next_bridge = of_drm_find_bridge(remote);
Expand Down
Loading

0 comments on commit 86418f9

Please sign in to comment.