lvds-encoder.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #include <drm/drmP.h>
  10. #include <drm/drm_bridge.h>
  11. #include <drm/drm_panel.h>
  12. #include <linux/of_graph.h>
  13. static int lvds_encoder_probe(struct platform_device *pdev)
  14. {
  15. struct device_node *port;
  16. struct device_node *endpoint;
  17. struct device_node *panel_node;
  18. struct drm_panel *panel;
  19. struct drm_bridge *bridge;
  20. /* Locate the panel DT node. */
  21. port = of_graph_get_port_by_id(pdev->dev.of_node, 1);
  22. if (!port) {
  23. dev_dbg(&pdev->dev, "port 1 not found\n");
  24. return -ENXIO;
  25. }
  26. endpoint = of_get_child_by_name(port, "endpoint");
  27. of_node_put(port);
  28. if (!endpoint) {
  29. dev_dbg(&pdev->dev, "no endpoint for port 1\n");
  30. return -ENXIO;
  31. }
  32. panel_node = of_graph_get_remote_port_parent(endpoint);
  33. of_node_put(endpoint);
  34. if (!panel_node) {
  35. dev_dbg(&pdev->dev, "no remote endpoint for port 1\n");
  36. return -ENXIO;
  37. }
  38. panel = of_drm_find_panel(panel_node);
  39. of_node_put(panel_node);
  40. if (!panel) {
  41. dev_dbg(&pdev->dev, "panel not found, deferring probe\n");
  42. return -EPROBE_DEFER;
  43. }
  44. bridge = drm_panel_bridge_add(panel, DRM_MODE_CONNECTOR_LVDS);
  45. if (IS_ERR(bridge))
  46. return PTR_ERR(bridge);
  47. platform_set_drvdata(pdev, bridge);
  48. return 0;
  49. }
  50. static int lvds_encoder_remove(struct platform_device *pdev)
  51. {
  52. struct drm_bridge *bridge = platform_get_drvdata(pdev);
  53. drm_bridge_remove(bridge);
  54. return 0;
  55. }
  56. static const struct of_device_id lvds_encoder_match[] = {
  57. { .compatible = "lvds-encoder" },
  58. { .compatible = "thine,thc63lvdm83d" },
  59. {},
  60. };
  61. MODULE_DEVICE_TABLE(of, lvds_encoder_match);
  62. static struct platform_driver lvds_encoder_driver = {
  63. .probe = lvds_encoder_probe,
  64. .remove = lvds_encoder_remove,
  65. .driver = {
  66. .name = "lvds-encoder",
  67. .of_match_table = lvds_encoder_match,
  68. },
  69. };
  70. module_platform_driver(lvds_encoder_driver);
  71. MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
  72. MODULE_DESCRIPTION("Transparent parallel to LVDS encoder");
  73. MODULE_LICENSE("GPL");