dss-of.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. struct device_node *dss_of_port_get_parent_device(struct device_node *port)
  22. {
  23. struct device_node *np;
  24. int i;
  25. if (!port)
  26. return NULL;
  27. np = of_get_parent(port);
  28. for (i = 0; i < 2 && np; ++i) {
  29. struct property *prop;
  30. prop = of_find_property(np, "compatible", NULL);
  31. if (prop)
  32. return np;
  33. np = of_get_next_parent(np);
  34. }
  35. return NULL;
  36. }
  37. u32 dss_of_port_get_port_number(struct device_node *port)
  38. {
  39. int r;
  40. u32 reg;
  41. r = of_property_read_u32(port, "reg", &reg);
  42. if (r)
  43. reg = 0;
  44. return reg;
  45. }
  46. struct omap_dss_device *
  47. omapdss_of_find_source_for_first_ep(struct device_node *node)
  48. {
  49. struct device_node *ep;
  50. struct device_node *src_port;
  51. struct omap_dss_device *src;
  52. ep = of_graph_get_endpoint_by_regs(node, 0, 0);
  53. if (!ep)
  54. return ERR_PTR(-EINVAL);
  55. src_port = of_graph_get_remote_port(ep);
  56. if (!src_port) {
  57. of_node_put(ep);
  58. return ERR_PTR(-EINVAL);
  59. }
  60. of_node_put(ep);
  61. src = omap_dss_find_output_by_port_node(src_port);
  62. of_node_put(src_port);
  63. return src ? src : ERR_PTR(-EPROBE_DEFER);
  64. }
  65. EXPORT_SYMBOL_GPL(omapdss_of_find_source_for_first_ep);