forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/hwtracing/coresight/coresight-tpiu.c
....@@ -47,64 +47,60 @@
4747 #define FFCR_FON_MAN BIT(6)
4848 #define FFCR_STOP_FI BIT(12)
4949
50
+DEFINE_CORESIGHT_DEVLIST(tpiu_devs, "tpiu");
51
+
5052 /**
5153 * @base: memory mapped base address for this component.
52
- * @dev: the device entity associated to this component.
5354 * @atclk: optional clock for the core parts of the TPIU.
5455 * @csdev: component vitals needed by the framework.
5556 */
5657 struct tpiu_drvdata {
5758 void __iomem *base;
58
- struct device *dev;
5959 struct clk *atclk;
6060 struct coresight_device *csdev;
6161 };
6262
63
-static void tpiu_enable_hw(struct tpiu_drvdata *drvdata)
63
+static void tpiu_enable_hw(struct csdev_access *csa)
6464 {
65
- CS_UNLOCK(drvdata->base);
65
+ CS_UNLOCK(csa->base);
6666
6767 /* TODO: fill this up */
6868
69
- CS_LOCK(drvdata->base);
69
+ CS_LOCK(csa->base);
7070 }
7171
7272 static int tpiu_enable(struct coresight_device *csdev, u32 mode, void *__unused)
7373 {
74
- struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
75
-
76
- tpiu_enable_hw(drvdata);
74
+ tpiu_enable_hw(&csdev->access);
7775 atomic_inc(csdev->refcnt);
78
- dev_dbg(drvdata->dev, "TPIU enabled\n");
76
+ dev_dbg(&csdev->dev, "TPIU enabled\n");
7977 return 0;
8078 }
8179
82
-static void tpiu_disable_hw(struct tpiu_drvdata *drvdata)
80
+static void tpiu_disable_hw(struct csdev_access *csa)
8381 {
84
- CS_UNLOCK(drvdata->base);
82
+ CS_UNLOCK(csa->base);
8583
8684 /* Clear formatter and stop on flush */
87
- writel_relaxed(FFCR_STOP_FI, drvdata->base + TPIU_FFCR);
85
+ csdev_access_relaxed_write32(csa, FFCR_STOP_FI, TPIU_FFCR);
8886 /* Generate manual flush */
89
- writel_relaxed(FFCR_STOP_FI | FFCR_FON_MAN, drvdata->base + TPIU_FFCR);
87
+ csdev_access_relaxed_write32(csa, FFCR_STOP_FI | FFCR_FON_MAN, TPIU_FFCR);
9088 /* Wait for flush to complete */
91
- coresight_timeout(drvdata->base, TPIU_FFCR, FFCR_FON_MAN_BIT, 0);
89
+ coresight_timeout(csa, TPIU_FFCR, FFCR_FON_MAN_BIT, 0);
9290 /* Wait for formatter to stop */
93
- coresight_timeout(drvdata->base, TPIU_FFSR, FFSR_FT_STOPPED_BIT, 1);
91
+ coresight_timeout(csa, TPIU_FFSR, FFSR_FT_STOPPED_BIT, 1);
9492
95
- CS_LOCK(drvdata->base);
93
+ CS_LOCK(csa->base);
9694 }
9795
9896 static int tpiu_disable(struct coresight_device *csdev)
9997 {
100
- struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
101
-
10298 if (atomic_dec_return(csdev->refcnt))
10399 return -EBUSY;
104100
105
- tpiu_disable_hw(drvdata);
101
+ tpiu_disable_hw(&csdev->access);
106102
107
- dev_dbg(drvdata->dev, "TPIU disabled\n");
103
+ dev_dbg(&csdev->dev, "TPIU disabled\n");
108104 return 0;
109105 }
110106
....@@ -126,20 +122,15 @@
126122 struct tpiu_drvdata *drvdata;
127123 struct resource *res = &adev->res;
128124 struct coresight_desc desc = { 0 };
129
- struct device_node *np = adev->dev.of_node;
130125
131
- if (np) {
132
- pdata = of_get_coresight_platform_data(dev, np);
133
- if (IS_ERR(pdata))
134
- return PTR_ERR(pdata);
135
- adev->dev.platform_data = pdata;
136
- }
126
+ desc.name = coresight_alloc_device_name(&tpiu_devs, dev);
127
+ if (!desc.name)
128
+ return -ENOMEM;
137129
138130 drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
139131 if (!drvdata)
140132 return -ENOMEM;
141133
142
- drvdata->dev = &adev->dev;
143134 drvdata->atclk = devm_clk_get(&adev->dev, "atclk"); /* optional */
144135 if (!IS_ERR(drvdata->atclk)) {
145136 ret = clk_prepare_enable(drvdata->atclk);
....@@ -154,11 +145,15 @@
154145 return PTR_ERR(base);
155146
156147 drvdata->base = base;
148
+ desc.access = CSDEV_ACCESS_IOMEM(base);
157149
158150 /* Disable tpiu to support older devices */
159
- tpiu_disable_hw(drvdata);
151
+ tpiu_disable_hw(&desc.access);
160152
161
- pm_runtime_put(&adev->dev);
153
+ pdata = coresight_get_platform_data(dev);
154
+ if (IS_ERR(pdata))
155
+ return PTR_ERR(pdata);
156
+ dev->platform_data = pdata;
162157
163158 desc.type = CORESIGHT_DEV_TYPE_SINK;
164159 desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_PORT;
....@@ -167,7 +162,19 @@
167162 desc.dev = dev;
168163 drvdata->csdev = coresight_register(&desc);
169164
170
- return PTR_ERR_OR_ZERO(drvdata->csdev);
165
+ if (!IS_ERR(drvdata->csdev)) {
166
+ pm_runtime_put(&adev->dev);
167
+ return 0;
168
+ }
169
+
170
+ return PTR_ERR(drvdata->csdev);
171
+}
172
+
173
+static void tpiu_remove(struct amba_device *adev)
174
+{
175
+ struct tpiu_drvdata *drvdata = dev_get_drvdata(&adev->dev);
176
+
177
+ coresight_unregister(drvdata->csdev);
171178 }
172179
173180 #ifdef CONFIG_PM
....@@ -213,6 +220,8 @@
213220 { 0, 0},
214221 };
215222
223
+MODULE_DEVICE_TABLE(amba, tpiu_ids);
224
+
216225 static struct amba_driver tpiu_driver = {
217226 .drv = {
218227 .name = "coresight-tpiu",
....@@ -221,6 +230,13 @@
221230 .suppress_bind_attrs = true,
222231 },
223232 .probe = tpiu_probe,
233
+ .remove = tpiu_remove,
224234 .id_table = tpiu_ids,
225235 };
226
-builtin_amba_driver(tpiu_driver);
236
+
237
+module_amba_driver(tpiu_driver);
238
+
239
+MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
240
+MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
241
+MODULE_DESCRIPTION("Arm CoreSight TPIU (Trace Port Interface Unit) driver");
242
+MODULE_LICENSE("GPL v2");