11
11
#include <linux/pm_runtime.h>
12
12
13
13
#include "coresight-priv.h"
14
+ #include "coresight-trace-id.h"
14
15
15
16
struct dummy_drvdata {
16
17
struct device * dev ;
17
18
struct coresight_device * csdev ;
19
+ u8 traceid ;
18
20
};
19
21
20
22
DEFINE_CORESIGHT_DEVLIST (source_devs , "dummy_source" );
@@ -72,13 +74,44 @@ static const struct coresight_ops dummy_sink_cs_ops = {
72
74
.sink_ops = & dummy_sink_ops ,
73
75
};
74
76
77
+ /* User can get the trace id of dummy source from this node. */
78
+ static ssize_t traceid_show (struct device * dev ,
79
+ struct device_attribute * attr , char * buf )
80
+ {
81
+ unsigned long val ;
82
+ struct dummy_drvdata * drvdata = dev_get_drvdata (dev -> parent );
83
+
84
+ val = drvdata -> traceid ;
85
+ return sysfs_emit (buf , "%#lx\n" , val );
86
+ }
87
+ static DEVICE_ATTR_RO (traceid );
88
+
89
+ static struct attribute * coresight_dummy_attrs [] = {
90
+ & dev_attr_traceid .attr ,
91
+ NULL ,
92
+ };
93
+
94
+ static const struct attribute_group coresight_dummy_group = {
95
+ .attrs = coresight_dummy_attrs ,
96
+ };
97
+
98
+ static const struct attribute_group * coresight_dummy_groups [] = {
99
+ & coresight_dummy_group ,
100
+ NULL ,
101
+ };
102
+
75
103
static int dummy_probe (struct platform_device * pdev )
76
104
{
77
105
struct device * dev = & pdev -> dev ;
78
106
struct device_node * node = dev -> of_node ;
79
107
struct coresight_platform_data * pdata ;
80
108
struct dummy_drvdata * drvdata ;
81
109
struct coresight_desc desc = { 0 };
110
+ int ret = 0 , trace_id = 0 ;
111
+
112
+ drvdata = devm_kzalloc (dev , sizeof (* drvdata ), GFP_KERNEL );
113
+ if (!drvdata )
114
+ return - ENOMEM ;
82
115
83
116
if (of_device_is_compatible (node , "arm,coresight-dummy-source" )) {
84
117
@@ -90,6 +123,26 @@ static int dummy_probe(struct platform_device *pdev)
90
123
desc .subtype .source_subtype =
91
124
CORESIGHT_DEV_SUBTYPE_SOURCE_OTHERS ;
92
125
desc .ops = & dummy_source_cs_ops ;
126
+ desc .groups = coresight_dummy_groups ;
127
+
128
+ ret = coresight_get_static_trace_id (dev , & trace_id );
129
+ if (!ret ) {
130
+ /* Get the static id if id is set in device tree. */
131
+ ret = coresight_trace_id_get_static_system_id (trace_id );
132
+ if (ret < 0 ) {
133
+ dev_err (dev , "Fail to get static id.\n" );
134
+ return ret ;
135
+ }
136
+ } else {
137
+ /* Get next available id if id is not set in device tree. */
138
+ trace_id = coresight_trace_id_get_system_id ();
139
+ if (trace_id < 0 ) {
140
+ ret = trace_id ;
141
+ return ret ;
142
+ }
143
+ }
144
+ drvdata -> traceid = (u8 )trace_id ;
145
+
93
146
} else if (of_device_is_compatible (node , "arm,coresight-dummy-sink" )) {
94
147
desc .name = coresight_alloc_device_name (& sink_devs , dev );
95
148
if (!desc .name )
@@ -104,34 +157,44 @@ static int dummy_probe(struct platform_device *pdev)
104
157
}
105
158
106
159
pdata = coresight_get_platform_data (dev );
107
- if (IS_ERR (pdata ))
108
- return PTR_ERR (pdata );
160
+ if (IS_ERR (pdata )) {
161
+ ret = PTR_ERR (pdata );
162
+ goto free_id ;
163
+ }
109
164
pdev -> dev .platform_data = pdata ;
110
165
111
- drvdata = devm_kzalloc (dev , sizeof (* drvdata ), GFP_KERNEL );
112
- if (!drvdata )
113
- return - ENOMEM ;
114
-
115
166
drvdata -> dev = & pdev -> dev ;
116
167
platform_set_drvdata (pdev , drvdata );
117
168
118
169
desc .pdata = pdev -> dev .platform_data ;
119
170
desc .dev = & pdev -> dev ;
120
171
drvdata -> csdev = coresight_register (& desc );
121
- if (IS_ERR (drvdata -> csdev ))
122
- return PTR_ERR (drvdata -> csdev );
172
+ if (IS_ERR (drvdata -> csdev )) {
173
+ ret = PTR_ERR (drvdata -> csdev );
174
+ goto free_id ;
175
+ }
123
176
124
177
pm_runtime_enable (dev );
125
178
dev_dbg (dev , "Dummy device initialized\n" );
126
179
127
- return 0 ;
180
+ ret = 0 ;
181
+ goto out ;
182
+
183
+ free_id :
184
+ if (IS_VALID_CS_TRACE_ID (drvdata -> traceid ))
185
+ coresight_trace_id_put_system_id (drvdata -> traceid );
186
+
187
+ out :
188
+ return ret ;
128
189
}
129
190
130
191
static void dummy_remove (struct platform_device * pdev )
131
192
{
132
193
struct dummy_drvdata * drvdata = platform_get_drvdata (pdev );
133
194
struct device * dev = & pdev -> dev ;
134
195
196
+ if (IS_VALID_CS_TRACE_ID (drvdata -> traceid ))
197
+ coresight_trace_id_put_system_id (drvdata -> traceid );
135
198
pm_runtime_disable (dev );
136
199
coresight_unregister (drvdata -> csdev );
137
200
}
0 commit comments