dss-of.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (C) 2013 Texas Instruments
  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. EXPORT_SYMBOL_GPL(dss_of_port_get_parent_device);
  38. u32 dss_of_port_get_port_number(struct device_node *port)
  39. {
  40. int r;
  41. u32 reg;
  42. r = of_property_read_u32(port, "reg", &reg);
  43. if (r)
  44. reg = 0;
  45. return reg;
  46. }
  47. EXPORT_SYMBOL_GPL(dss_of_port_get_port_number);
  48. struct omap_dss_device *
  49. omapdss_of_find_source_for_first_ep(struct device_node *node)
  50. {
  51. struct device_node *ep;
  52. struct device_node *src_port;
  53. struct omap_dss_device *src;
  54. ep = of_graph_get_endpoint_by_regs(node, 0, 0);
  55. if (!ep)
  56. return ERR_PTR(-EINVAL);
  57. src_port = of_graph_get_remote_port(ep);
  58. if (!src_port) {
  59. of_node_put(ep);
  60. return ERR_PTR(-EINVAL);
  61. }
  62. of_node_put(ep);
  63. src = omap_dss_find_output_by_port_node(src_port);
  64. of_node_put(src_port);
  65. return src ? src : ERR_PTR(-EPROBE_DEFER);
  66. }
  67. EXPORT_SYMBOL_GPL(omapdss_of_find_source_for_first_ep);