2 * Copyright (C) 2016 Laurent Pinchart <laurent.pinchart@ideasonboard.com>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
11 #include <drm/drm_bridge.h>
12 #include <drm/drm_panel.h>
14 #include <linux/of_graph.h>
17 struct drm_bridge bridge
;
18 struct drm_bridge
*panel_bridge
;
21 static int lvds_encoder_attach(struct drm_bridge
*bridge
)
23 struct lvds_encoder
*lvds_encoder
= container_of(bridge
,
27 return drm_bridge_attach(bridge
->encoder
, lvds_encoder
->panel_bridge
,
31 static struct drm_bridge_funcs funcs
= {
32 .attach
= lvds_encoder_attach
,
35 static int lvds_encoder_probe(struct platform_device
*pdev
)
37 struct device_node
*port
;
38 struct device_node
*endpoint
;
39 struct device_node
*panel_node
;
40 struct drm_panel
*panel
;
41 struct lvds_encoder
*lvds_encoder
;
43 lvds_encoder
= devm_kzalloc(&pdev
->dev
, sizeof(*lvds_encoder
),
48 /* Locate the panel DT node. */
49 port
= of_graph_get_port_by_id(pdev
->dev
.of_node
, 1);
51 dev_dbg(&pdev
->dev
, "port 1 not found\n");
55 endpoint
= of_get_child_by_name(port
, "endpoint");
58 dev_dbg(&pdev
->dev
, "no endpoint for port 1\n");
62 panel_node
= of_graph_get_remote_port_parent(endpoint
);
63 of_node_put(endpoint
);
65 dev_dbg(&pdev
->dev
, "no remote endpoint for port 1\n");
69 panel
= of_drm_find_panel(panel_node
);
70 of_node_put(panel_node
);
72 dev_dbg(&pdev
->dev
, "panel not found, deferring probe\n");
76 lvds_encoder
->panel_bridge
=
77 devm_drm_panel_bridge_add(&pdev
->dev
,
78 panel
, DRM_MODE_CONNECTOR_LVDS
);
79 if (IS_ERR(lvds_encoder
->panel_bridge
))
80 return PTR_ERR(lvds_encoder
->panel_bridge
);
82 /* The panel_bridge bridge is attached to the panel's of_node,
83 * but we need a bridge attached to our of_node for our user
86 lvds_encoder
->bridge
.of_node
= pdev
->dev
.of_node
;
87 lvds_encoder
->bridge
.funcs
= &funcs
;
88 drm_bridge_add(&lvds_encoder
->bridge
);
90 platform_set_drvdata(pdev
, lvds_encoder
);
95 static int lvds_encoder_remove(struct platform_device
*pdev
)
97 struct lvds_encoder
*lvds_encoder
= platform_get_drvdata(pdev
);
99 drm_bridge_remove(&lvds_encoder
->bridge
);
104 static const struct of_device_id lvds_encoder_match
[] = {
105 { .compatible
= "lvds-encoder" },
106 { .compatible
= "thine,thc63lvdm83d" },
109 MODULE_DEVICE_TABLE(of
, lvds_encoder_match
);
111 static struct platform_driver lvds_encoder_driver
= {
112 .probe
= lvds_encoder_probe
,
113 .remove
= lvds_encoder_remove
,
115 .name
= "lvds-encoder",
116 .of_match_table
= lvds_encoder_match
,
119 module_platform_driver(lvds_encoder_driver
);
121 MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
122 MODULE_DESCRIPTION("Transparent parallel to LVDS encoder");
123 MODULE_LICENSE("GPL");