blob: 0903ba574f61c4d1ab40a0e18d77d852bd282c0a [file] [log] [blame]
Laurent Pinchart67cc3e22017-03-02 12:47:26 +02001/*
2 * Copyright (C) 2016 Laurent Pinchart <laurent.pinchart@ideasonboard.com>
3 *
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.
8 */
9
10#include <drm/drmP.h>
Eric Anholt13dfc052017-06-02 13:25:14 -070011#include <drm/drm_bridge.h>
Laurent Pinchart67cc3e22017-03-02 12:47:26 +020012#include <drm/drm_panel.h>
13
14#include <linux/of_graph.h>
15
Laurent Pinchart67cc3e22017-03-02 12:47:26 +020016static int lvds_encoder_probe(struct platform_device *pdev)
17{
Laurent Pinchart67cc3e22017-03-02 12:47:26 +020018 struct device_node *port;
19 struct device_node *endpoint;
Eric Anholt13dfc052017-06-02 13:25:14 -070020 struct device_node *panel_node;
21 struct drm_panel *panel;
22 struct drm_bridge *bridge;
Laurent Pinchart67cc3e22017-03-02 12:47:26 +020023
24 /* Locate the panel DT node. */
25 port = of_graph_get_port_by_id(pdev->dev.of_node, 1);
26 if (!port) {
27 dev_dbg(&pdev->dev, "port 1 not found\n");
28 return -ENXIO;
29 }
30
31 endpoint = of_get_child_by_name(port, "endpoint");
32 of_node_put(port);
33 if (!endpoint) {
34 dev_dbg(&pdev->dev, "no endpoint for port 1\n");
35 return -ENXIO;
36 }
37
Eric Anholt13dfc052017-06-02 13:25:14 -070038 panel_node = of_graph_get_remote_port_parent(endpoint);
Laurent Pinchart67cc3e22017-03-02 12:47:26 +020039 of_node_put(endpoint);
Eric Anholt13dfc052017-06-02 13:25:14 -070040 if (!panel_node) {
Laurent Pinchart67cc3e22017-03-02 12:47:26 +020041 dev_dbg(&pdev->dev, "no remote endpoint for port 1\n");
42 return -ENXIO;
43 }
44
Eric Anholt13dfc052017-06-02 13:25:14 -070045 panel = of_drm_find_panel(panel_node);
46 of_node_put(panel_node);
47 if (!panel) {
Laurent Pinchart67cc3e22017-03-02 12:47:26 +020048 dev_dbg(&pdev->dev, "panel not found, deferring probe\n");
49 return -EPROBE_DEFER;
50 }
51
Eric Anholt13dfc052017-06-02 13:25:14 -070052 bridge = drm_panel_bridge_add(panel, DRM_MODE_CONNECTOR_LVDS);
53 if (IS_ERR(bridge))
54 return PTR_ERR(bridge);
55
56 platform_set_drvdata(pdev, bridge);
57
58 return 0;
Laurent Pinchart67cc3e22017-03-02 12:47:26 +020059}
60
61static int lvds_encoder_remove(struct platform_device *pdev)
62{
Eric Anholt13dfc052017-06-02 13:25:14 -070063 struct drm_bridge *bridge = platform_get_drvdata(pdev);
Laurent Pinchart67cc3e22017-03-02 12:47:26 +020064
Eric Anholt13dfc052017-06-02 13:25:14 -070065 drm_bridge_remove(bridge);
Laurent Pinchart67cc3e22017-03-02 12:47:26 +020066
67 return 0;
68}
69
70static const struct of_device_id lvds_encoder_match[] = {
71 { .compatible = "lvds-encoder" },
Laurent Pinchart7160d572017-03-02 12:47:28 +020072 { .compatible = "thine,thc63lvdm83d" },
Laurent Pinchart67cc3e22017-03-02 12:47:26 +020073 {},
74};
75MODULE_DEVICE_TABLE(of, lvds_encoder_match);
76
77static struct platform_driver lvds_encoder_driver = {
78 .probe = lvds_encoder_probe,
79 .remove = lvds_encoder_remove,
80 .driver = {
81 .name = "lvds-encoder",
82 .of_match_table = lvds_encoder_match,
83 },
84};
85module_platform_driver(lvds_encoder_driver);
86
87MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
88MODULE_DESCRIPTION("Transparent parallel to LVDS encoder");
89MODULE_LICENSE("GPL");