blob: 8b8c0d62b5a3ec898204e0b62238d44d819f0558 [file] [log] [blame]
Pratik Pateld944cc72013-02-08 11:52:12 -08001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Pratik Patel5f6d1af2012-06-13 15:48:13 -07002 *
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
13#include <linux/module.h>
14#include <linux/types.h>
15#include <linux/err.h>
16#include <linux/slab.h>
17#include <linux/of.h>
18#include <linux/coresight.h>
Pratik Pateld944cc72013-02-08 11:52:12 -080019#include <linux/coresight-cti.h>
Pratik Patel5f6d1af2012-06-13 15:48:13 -070020
Pratik Patel5f6d1af2012-06-13 15:48:13 -070021struct coresight_platform_data *of_get_coresight_platform_data(
22 struct device *dev, struct device_node *node)
23{
24 int i, ret = 0;
25 uint32_t outports_len = 0;
26 struct device_node *child_node;
27 struct coresight_platform_data *pdata;
28
29 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
30 if (!pdata)
31 return ERR_PTR(-ENOMEM);
32
33 ret = of_property_read_u32(node, "coresight-id", &pdata->id);
34 if (ret)
35 return ERR_PTR(ret);
36
37 ret = of_property_read_string(node, "coresight-name", &pdata->name);
38 if (ret)
39 return ERR_PTR(ret);
40
41 ret = of_property_read_u32(node, "coresight-nr-inports",
42 &pdata->nr_inports);
43 if (ret)
44 return ERR_PTR(ret);
45
46 pdata->nr_outports = 0;
47 if (of_get_property(node, "coresight-outports", &outports_len))
48 pdata->nr_outports = outports_len/sizeof(uint32_t);
49
50 if (pdata->nr_outports) {
51 pdata->outports = devm_kzalloc(dev, pdata->nr_outports *
52 sizeof(*pdata->outports),
53 GFP_KERNEL);
54 if (!pdata->outports)
55 return ERR_PTR(-ENOMEM);
56
57 ret = of_property_read_u32_array(node, "coresight-outports",
58 (u32 *)pdata->outports,
59 pdata->nr_outports);
60 if (ret)
61 return ERR_PTR(ret);
62
63 pdata->child_ids = devm_kzalloc(dev, pdata->nr_outports *
64 sizeof(*pdata->child_ids),
65 GFP_KERNEL);
66 if (!pdata->child_ids)
67 return ERR_PTR(-ENOMEM);
68
69 for (i = 0; i < pdata->nr_outports; i++) {
70 child_node = of_parse_phandle(node,
71 "coresight-child-list",
72 i);
73 if (!child_node)
74 return ERR_PTR(-EINVAL);
75
76 ret = of_property_read_u32(child_node, "coresight-id",
77 (u32 *)&pdata->child_ids[i]);
78 of_node_put(child_node);
79 if (ret)
80 return ERR_PTR(ret);
81 }
82
83 pdata->child_ports = devm_kzalloc(dev, pdata->nr_outports *
84 sizeof(*pdata->child_ports),
85 GFP_KERNEL);
86 if (!pdata->child_ports)
87 return ERR_PTR(-ENOMEM);
88
89 ret = of_property_read_u32_array(node, "coresight-child-ports",
90 (u32 *)pdata->child_ports,
91 pdata->nr_outports);
92 if (ret)
93 return ERR_PTR(ret);
94 }
95
96 pdata->default_sink = of_property_read_bool(node,
97 "coresight-default-sink");
98 return pdata;
99}
Pratik Patel394783a2013-04-22 11:12:14 -0700100EXPORT_SYMBOL(of_get_coresight_platform_data);
Pratik Pateld944cc72013-02-08 11:52:12 -0800101
102struct coresight_cti_data *of_get_coresight_cti_data(
103 struct device *dev, struct device_node *node)
104{
105 int i, ret;
106 uint32_t ctis_len;
107 struct device_node *child_node;
108 struct coresight_cti_data *ctidata;
109
110 ctidata = devm_kzalloc(dev, sizeof(*ctidata), GFP_KERNEL);
111 if (!ctidata)
112 return ERR_PTR(-ENOMEM);
113
114 if (of_get_property(node, "coresight-ctis", &ctis_len))
115 ctidata->nr_ctis = ctis_len/sizeof(uint32_t);
116 else
117 return ERR_PTR(-EINVAL);
118
119 if (ctidata->nr_ctis) {
120 ctidata->names = devm_kzalloc(dev, ctidata->nr_ctis *
121 sizeof(*ctidata->names),
122 GFP_KERNEL);
123 if (!ctidata->names)
124 return ERR_PTR(-ENOMEM);
125
126 for (i = 0; i < ctidata->nr_ctis; i++) {
127 child_node = of_parse_phandle(node, "coresight-ctis",
128 i);
129 if (!child_node)
130 return ERR_PTR(-EINVAL);
131
132 ret = of_property_read_string(child_node,
133 "coresight-name",
134 &ctidata->names[i]);
135 of_node_put(child_node);
136 if (ret)
137 return ERR_PTR(ret);
138 }
139 }
140 return ctidata;
141}
142EXPORT_SYMBOL(of_get_coresight_cti_data);