Laurent Pinchart | 67cc3e2 | 2017-03-02 12:47:26 +0200 | [diff] [blame] | 1 | /* |
| 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 Anholt | 13dfc05 | 2017-06-02 13:25:14 -0700 | [diff] [blame] | 11 | #include <drm/drm_bridge.h> |
Laurent Pinchart | 67cc3e2 | 2017-03-02 12:47:26 +0200 | [diff] [blame] | 12 | #include <drm/drm_panel.h> |
| 13 | |
| 14 | #include <linux/of_graph.h> |
| 15 | |
Laurent Pinchart | 67cc3e2 | 2017-03-02 12:47:26 +0200 | [diff] [blame] | 16 | static int lvds_encoder_probe(struct platform_device *pdev) |
| 17 | { |
Laurent Pinchart | 67cc3e2 | 2017-03-02 12:47:26 +0200 | [diff] [blame] | 18 | struct device_node *port; |
| 19 | struct device_node *endpoint; |
Eric Anholt | 13dfc05 | 2017-06-02 13:25:14 -0700 | [diff] [blame] | 20 | struct device_node *panel_node; |
| 21 | struct drm_panel *panel; |
| 22 | struct drm_bridge *bridge; |
Laurent Pinchart | 67cc3e2 | 2017-03-02 12:47:26 +0200 | [diff] [blame] | 23 | |
| 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 Anholt | 13dfc05 | 2017-06-02 13:25:14 -0700 | [diff] [blame] | 38 | panel_node = of_graph_get_remote_port_parent(endpoint); |
Laurent Pinchart | 67cc3e2 | 2017-03-02 12:47:26 +0200 | [diff] [blame] | 39 | of_node_put(endpoint); |
Eric Anholt | 13dfc05 | 2017-06-02 13:25:14 -0700 | [diff] [blame] | 40 | if (!panel_node) { |
Laurent Pinchart | 67cc3e2 | 2017-03-02 12:47:26 +0200 | [diff] [blame] | 41 | dev_dbg(&pdev->dev, "no remote endpoint for port 1\n"); |
| 42 | return -ENXIO; |
| 43 | } |
| 44 | |
Eric Anholt | 13dfc05 | 2017-06-02 13:25:14 -0700 | [diff] [blame] | 45 | panel = of_drm_find_panel(panel_node); |
| 46 | of_node_put(panel_node); |
| 47 | if (!panel) { |
Laurent Pinchart | 67cc3e2 | 2017-03-02 12:47:26 +0200 | [diff] [blame] | 48 | dev_dbg(&pdev->dev, "panel not found, deferring probe\n"); |
| 49 | return -EPROBE_DEFER; |
| 50 | } |
| 51 | |
Eric Anholt | 13dfc05 | 2017-06-02 13:25:14 -0700 | [diff] [blame] | 52 | 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 Pinchart | 67cc3e2 | 2017-03-02 12:47:26 +0200 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | static int lvds_encoder_remove(struct platform_device *pdev) |
| 62 | { |
Eric Anholt | 13dfc05 | 2017-06-02 13:25:14 -0700 | [diff] [blame] | 63 | struct drm_bridge *bridge = platform_get_drvdata(pdev); |
Laurent Pinchart | 67cc3e2 | 2017-03-02 12:47:26 +0200 | [diff] [blame] | 64 | |
Eric Anholt | 13dfc05 | 2017-06-02 13:25:14 -0700 | [diff] [blame] | 65 | drm_bridge_remove(bridge); |
Laurent Pinchart | 67cc3e2 | 2017-03-02 12:47:26 +0200 | [diff] [blame] | 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | static const struct of_device_id lvds_encoder_match[] = { |
| 71 | { .compatible = "lvds-encoder" }, |
Laurent Pinchart | 7160d57 | 2017-03-02 12:47:28 +0200 | [diff] [blame] | 72 | { .compatible = "thine,thc63lvdm83d" }, |
Laurent Pinchart | 67cc3e2 | 2017-03-02 12:47:26 +0200 | [diff] [blame] | 73 | {}, |
| 74 | }; |
| 75 | MODULE_DEVICE_TABLE(of, lvds_encoder_match); |
| 76 | |
| 77 | static 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 | }; |
| 85 | module_platform_driver(lvds_encoder_driver); |
| 86 | |
| 87 | MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>"); |
| 88 | MODULE_DESCRIPTION("Transparent parallel to LVDS encoder"); |
| 89 | MODULE_LICENSE("GPL"); |