of_coresight.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/types.h>
  14. #include <linux/err.h>
  15. #include <linux/slab.h>
  16. #include <linux/of.h>
  17. #include <linux/coresight.h>
  18. #include <linux/coresight-cti.h>
  19. struct coresight_platform_data *of_get_coresight_platform_data(
  20. struct device *dev, struct device_node *node)
  21. {
  22. int i, ret = 0;
  23. uint32_t outports_len = 0;
  24. struct device_node *child_node;
  25. struct coresight_platform_data *pdata;
  26. pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  27. if (!pdata)
  28. return ERR_PTR(-ENOMEM);
  29. ret = of_property_read_u32(node, "coresight-id", &pdata->id);
  30. if (ret)
  31. return ERR_PTR(ret);
  32. ret = of_property_read_string(node, "coresight-name", &pdata->name);
  33. if (ret)
  34. return ERR_PTR(ret);
  35. ret = of_property_read_u32(node, "coresight-nr-inports",
  36. &pdata->nr_inports);
  37. if (ret)
  38. return ERR_PTR(ret);
  39. pdata->nr_outports = 0;
  40. if (of_get_property(node, "coresight-outports", &outports_len))
  41. pdata->nr_outports = outports_len/sizeof(uint32_t);
  42. if (pdata->nr_outports) {
  43. pdata->outports = devm_kzalloc(dev, pdata->nr_outports *
  44. sizeof(*pdata->outports),
  45. GFP_KERNEL);
  46. if (!pdata->outports)
  47. return ERR_PTR(-ENOMEM);
  48. ret = of_property_read_u32_array(node, "coresight-outports",
  49. (u32 *)pdata->outports,
  50. pdata->nr_outports);
  51. if (ret)
  52. return ERR_PTR(ret);
  53. pdata->child_ids = devm_kzalloc(dev, pdata->nr_outports *
  54. sizeof(*pdata->child_ids),
  55. GFP_KERNEL);
  56. if (!pdata->child_ids)
  57. return ERR_PTR(-ENOMEM);
  58. for (i = 0; i < pdata->nr_outports; i++) {
  59. child_node = of_parse_phandle(node,
  60. "coresight-child-list",
  61. i);
  62. if (!child_node)
  63. return ERR_PTR(-EINVAL);
  64. ret = of_property_read_u32(child_node, "coresight-id",
  65. (u32 *)&pdata->child_ids[i]);
  66. of_node_put(child_node);
  67. if (ret)
  68. return ERR_PTR(ret);
  69. }
  70. pdata->child_ports = devm_kzalloc(dev, pdata->nr_outports *
  71. sizeof(*pdata->child_ports),
  72. GFP_KERNEL);
  73. if (!pdata->child_ports)
  74. return ERR_PTR(-ENOMEM);
  75. ret = of_property_read_u32_array(node, "coresight-child-ports",
  76. (u32 *)pdata->child_ports,
  77. pdata->nr_outports);
  78. if (ret)
  79. return ERR_PTR(ret);
  80. }
  81. pdata->default_sink = of_property_read_bool(node,
  82. "coresight-default-sink");
  83. return pdata;
  84. }
  85. EXPORT_SYMBOL(of_get_coresight_platform_data);
  86. struct coresight_cti_data *of_get_coresight_cti_data(
  87. struct device *dev, struct device_node *node)
  88. {
  89. int i, ret;
  90. uint32_t ctis_len;
  91. struct device_node *child_node;
  92. struct coresight_cti_data *ctidata;
  93. ctidata = devm_kzalloc(dev, sizeof(*ctidata), GFP_KERNEL);
  94. if (!ctidata)
  95. return ERR_PTR(-ENOMEM);
  96. if (of_get_property(node, "coresight-ctis", &ctis_len))
  97. ctidata->nr_ctis = ctis_len/sizeof(uint32_t);
  98. else
  99. return ERR_PTR(-EINVAL);
  100. if (ctidata->nr_ctis) {
  101. ctidata->names = devm_kzalloc(dev, ctidata->nr_ctis *
  102. sizeof(*ctidata->names),
  103. GFP_KERNEL);
  104. if (!ctidata->names)
  105. return ERR_PTR(-ENOMEM);
  106. for (i = 0; i < ctidata->nr_ctis; i++) {
  107. child_node = of_parse_phandle(node, "coresight-ctis",
  108. i);
  109. if (!child_node)
  110. return ERR_PTR(-EINVAL);
  111. ret = of_property_read_string(child_node,
  112. "coresight-name",
  113. &ctidata->names[i]);
  114. of_node_put(child_node);
  115. if (ret)
  116. return ERR_PTR(ret);
  117. }
  118. }
  119. return ctidata;
  120. }
  121. EXPORT_SYMBOL(of_get_coresight_cti_data);