dss-of.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
  3. * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. */
  14. #include <linux/device.h>
  15. #include <linux/err.h>
  16. #include <linux/module.h>
  17. #include <linux/of.h>
  18. #include <linux/of_graph.h>
  19. #include <linux/seq_file.h>
  20. #include "omapdss.h"
  21. static struct device_node *
  22. dss_of_port_get_parent_device(struct device_node *port)
  23. {
  24. struct device_node *np;
  25. int i;
  26. if (!port)
  27. return NULL;
  28. np = of_get_parent(port);
  29. for (i = 0; i < 2 && np; ++i) {
  30. struct property *prop;
  31. prop = of_find_property(np, "compatible", NULL);
  32. if (prop)
  33. return np;
  34. np = of_get_next_parent(np);
  35. }
  36. return NULL;
  37. }
  38. struct omap_dss_device *
  39. omapdss_of_find_connected_device(struct device_node *node, unsigned int port)
  40. {
  41. struct device_node *src_node;
  42. struct device_node *src_port;
  43. struct device_node *ep;
  44. struct omap_dss_device *src;
  45. u32 port_number = 0;
  46. /* Get the endpoint... */
  47. ep = of_graph_get_endpoint_by_regs(node, port, 0);
  48. if (!ep)
  49. return NULL;
  50. /* ... and its remote port... */
  51. src_port = of_graph_get_remote_port(ep);
  52. of_node_put(ep);
  53. if (!src_port)
  54. return NULL;
  55. /* ... and the remote port's number and parent... */
  56. of_property_read_u32(src_port, "reg", &port_number);
  57. src_node = dss_of_port_get_parent_device(src_port);
  58. of_node_put(src_port);
  59. if (!src_node)
  60. return ERR_PTR(-EINVAL);
  61. /* ... and finally the connected device. */
  62. src = omapdss_find_device_by_port(src_node, port_number);
  63. of_node_put(src_node);
  64. return src ? src : ERR_PTR(-EPROBE_DEFER);
  65. }
  66. EXPORT_SYMBOL_GPL(omapdss_of_find_connected_device);