forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
kernel/drivers/hwtracing/coresight/coresight-funnel.c
....@@ -5,6 +5,7 @@
55 * Description: CoreSight Funnel driver
66 */
77
8
+#include <linux/acpi.h>
89 #include <linux/kernel.h>
910 #include <linux/init.h>
1011 #include <linux/types.h>
....@@ -29,10 +30,11 @@
2930 #define FUNNEL_HOLDTIME (0x7 << FUNNEL_HOLDTIME_SHFT)
3031 #define FUNNEL_ENSx_MASK 0xff
3132
33
+DEFINE_CORESIGHT_DEVLIST(funnel_devs, "funnel");
34
+
3235 /**
3336 * struct funnel_drvdata - specifics associated to a funnel component
3437 * @base: memory mapped base address for this component.
35
- * @dev: the device entity associated to this component.
3638 * @atclk: optional clock for the core parts of the funnel.
3739 * @csdev: component vitals needed by the framework.
3840 * @priority: port selection order.
....@@ -40,7 +42,6 @@
4042 */
4143 struct funnel_drvdata {
4244 void __iomem *base;
43
- struct device *dev;
4445 struct clk *atclk;
4546 struct coresight_device *csdev;
4647 unsigned long priority;
....@@ -51,13 +52,14 @@
5152 {
5253 u32 functl;
5354 int rc = 0;
55
+ struct coresight_device *csdev = drvdata->csdev;
5456
5557 CS_UNLOCK(drvdata->base);
5658
5759 functl = readl_relaxed(drvdata->base + FUNNEL_FUNCTL);
5860 /* Claim the device only when we enable the first slave */
5961 if (!(functl & FUNNEL_ENSx_MASK)) {
60
- rc = coresight_claim_device_unlocked(drvdata->base);
62
+ rc = coresight_claim_device_unlocked(csdev);
6163 if (rc)
6264 goto done;
6365 }
....@@ -92,7 +94,7 @@
9294 spin_unlock_irqrestore(&drvdata->spinlock, flags);
9395
9496 if (first_enable)
95
- dev_dbg(drvdata->dev, "FUNNEL inport %d enabled\n", inport);
97
+ dev_dbg(&csdev->dev, "FUNNEL inport %d enabled\n", inport);
9698 return rc;
9799 }
98100
....@@ -100,6 +102,7 @@
100102 int inport)
101103 {
102104 u32 functl;
105
+ struct coresight_device *csdev = drvdata->csdev;
103106
104107 CS_UNLOCK(drvdata->base);
105108
....@@ -109,7 +112,7 @@
109112
110113 /* Disclaim the device if none of the slaves are now active */
111114 if (!(functl & FUNNEL_ENSx_MASK))
112
- coresight_disclaim_device_unlocked(drvdata->base);
115
+ coresight_disclaim_device_unlocked(csdev);
113116
114117 CS_LOCK(drvdata->base);
115118 }
....@@ -130,7 +133,7 @@
130133 spin_unlock_irqrestore(&drvdata->spinlock, flags);
131134
132135 if (last_disable)
133
- dev_dbg(drvdata->dev, "FUNNEL inport %d disabled\n", inport);
136
+ dev_dbg(&csdev->dev, "FUNNEL inport %d disabled\n", inport);
134137 }
135138
136139 static const struct coresight_ops_link funnel_link_ops = {
....@@ -185,11 +188,11 @@
185188 u32 val;
186189 struct funnel_drvdata *drvdata = dev_get_drvdata(dev->parent);
187190
188
- pm_runtime_get_sync(drvdata->dev);
191
+ pm_runtime_get_sync(dev->parent);
189192
190193 val = get_funnel_ctrl_hw(drvdata);
191194
192
- pm_runtime_put(drvdata->dev);
195
+ pm_runtime_put(dev->parent);
193196
194197 return sprintf(buf, "%#x\n", val);
195198 }
....@@ -209,23 +212,19 @@
209212 struct coresight_platform_data *pdata = NULL;
210213 struct funnel_drvdata *drvdata;
211214 struct coresight_desc desc = { 0 };
212
- struct device_node *np = dev->of_node;
213215
214
- if (np) {
215
- pdata = of_get_coresight_platform_data(dev, np);
216
- if (IS_ERR(pdata))
217
- return PTR_ERR(pdata);
218
- dev->platform_data = pdata;
219
- }
216
+ if (is_of_node(dev_fwnode(dev)) &&
217
+ of_device_is_compatible(dev->of_node, "arm,coresight-funnel"))
218
+ dev_warn_once(dev, "Uses OBSOLETE CoreSight funnel binding\n");
220219
221
- if (of_device_is_compatible(np, "arm,coresight-funnel"))
222
- pr_warn_once("Uses OBSOLETE CoreSight funnel binding\n");
220
+ desc.name = coresight_alloc_device_name(&funnel_devs, dev);
221
+ if (!desc.name)
222
+ return -ENOMEM;
223223
224224 drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
225225 if (!drvdata)
226226 return -ENOMEM;
227227
228
- drvdata->dev = dev;
229228 drvdata->atclk = devm_clk_get(dev, "atclk"); /* optional */
230229 if (!IS_ERR(drvdata->atclk)) {
231230 ret = clk_prepare_enable(drvdata->atclk);
....@@ -245,9 +244,17 @@
245244 }
246245 drvdata->base = base;
247246 desc.groups = coresight_funnel_groups;
247
+ desc.access = CSDEV_ACCESS_IOMEM(base);
248248 }
249249
250250 dev_set_drvdata(dev, drvdata);
251
+
252
+ pdata = coresight_get_platform_data(dev);
253
+ if (IS_ERR(pdata)) {
254
+ ret = PTR_ERR(pdata);
255
+ goto out_disable_clk;
256
+ }
257
+ dev->platform_data = pdata;
251258
252259 spin_lock_init(&drvdata->spinlock);
253260 desc.type = CORESIGHT_DEV_TYPE_LINK;
....@@ -268,6 +275,15 @@
268275 if (ret && !IS_ERR_OR_NULL(drvdata->atclk))
269276 clk_disable_unprepare(drvdata->atclk);
270277 return ret;
278
+}
279
+
280
+static int funnel_remove(struct device *dev)
281
+{
282
+ struct funnel_drvdata *drvdata = dev_get_drvdata(dev);
283
+
284
+ coresight_unregister(drvdata->csdev);
285
+
286
+ return 0;
271287 }
272288
273289 #ifdef CONFIG_PM
....@@ -315,26 +331,51 @@
315331 return ret;
316332 }
317333
334
+static int static_funnel_remove(struct platform_device *pdev)
335
+{
336
+ funnel_remove(&pdev->dev);
337
+ pm_runtime_disable(&pdev->dev);
338
+ return 0;
339
+}
340
+
318341 static const struct of_device_id static_funnel_match[] = {
319342 {.compatible = "arm,coresight-static-funnel"},
320343 {}
321344 };
322345
346
+MODULE_DEVICE_TABLE(of, static_funnel_match);
347
+
348
+#ifdef CONFIG_ACPI
349
+static const struct acpi_device_id static_funnel_ids[] = {
350
+ {"ARMHC9FE", 0},
351
+ {},
352
+};
353
+
354
+MODULE_DEVICE_TABLE(acpi, static_funnel_ids);
355
+#endif
356
+
323357 static struct platform_driver static_funnel_driver = {
324358 .probe = static_funnel_probe,
359
+ .remove = static_funnel_remove,
325360 .driver = {
326361 .name = "coresight-static-funnel",
362
+ .owner = THIS_MODULE,
327363 .of_match_table = static_funnel_match,
364
+ .acpi_match_table = ACPI_PTR(static_funnel_ids),
328365 .pm = &funnel_dev_pm_ops,
329366 .suppress_bind_attrs = true,
330367 },
331368 };
332
-builtin_platform_driver(static_funnel_driver);
333369
334370 static int dynamic_funnel_probe(struct amba_device *adev,
335371 const struct amba_id *id)
336372 {
337373 return funnel_probe(&adev->dev, &adev->res);
374
+}
375
+
376
+static void dynamic_funnel_remove(struct amba_device *adev)
377
+{
378
+ funnel_remove(&adev->dev);
338379 }
339380
340381 static const struct amba_id dynamic_funnel_ids[] = {
....@@ -350,6 +391,8 @@
350391 { 0, 0},
351392 };
352393
394
+MODULE_DEVICE_TABLE(amba, dynamic_funnel_ids);
395
+
353396 static struct amba_driver dynamic_funnel_driver = {
354397 .drv = {
355398 .name = "coresight-dynamic-funnel",
....@@ -358,6 +401,39 @@
358401 .suppress_bind_attrs = true,
359402 },
360403 .probe = dynamic_funnel_probe,
404
+ .remove = dynamic_funnel_remove,
361405 .id_table = dynamic_funnel_ids,
362406 };
363
-builtin_amba_driver(dynamic_funnel_driver);
407
+
408
+static int __init funnel_init(void)
409
+{
410
+ int ret;
411
+
412
+ ret = platform_driver_register(&static_funnel_driver);
413
+ if (ret) {
414
+ pr_info("Error registering platform driver\n");
415
+ return ret;
416
+ }
417
+
418
+ ret = amba_driver_register(&dynamic_funnel_driver);
419
+ if (ret) {
420
+ pr_info("Error registering amba driver\n");
421
+ platform_driver_unregister(&static_funnel_driver);
422
+ }
423
+
424
+ return ret;
425
+}
426
+
427
+static void __exit funnel_exit(void)
428
+{
429
+ platform_driver_unregister(&static_funnel_driver);
430
+ amba_driver_unregister(&dynamic_funnel_driver);
431
+}
432
+
433
+module_init(funnel_init);
434
+module_exit(funnel_exit);
435
+
436
+MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
437
+MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
438
+MODULE_DESCRIPTION("Arm CoreSight Funnel Driver");
439
+MODULE_LICENSE("GPL v2");