hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/amba/bus.c
....@@ -1,11 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * linux/arch/arm/common/amba.c
34 *
45 * Copyright (C) 2003 Deep Blue Solutions Ltd, All Rights Reserved.
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License version 2 as
8
- * published by the Free Software Foundation.
96 */
107 #include <linux/module.h>
118 #include <linux/init.h>
....@@ -21,24 +18,42 @@
2118 #include <linux/limits.h>
2219 #include <linux/clk/clk-conf.h>
2320 #include <linux/platform_device.h>
21
+#include <linux/reset.h>
2422
2523 #include <asm/irq.h>
2624
2725 #define to_amba_driver(d) container_of(d, struct amba_driver, drv)
2826
27
+/* called on periphid match and class 0x9 coresight device. */
28
+static int
29
+amba_cs_uci_id_match(const struct amba_id *table, struct amba_device *dev)
30
+{
31
+ int ret = 0;
32
+ struct amba_cs_uci_id *uci;
33
+
34
+ uci = table->data;
35
+
36
+ /* no table data or zero mask - return match on periphid */
37
+ if (!uci || (uci->devarch_mask == 0))
38
+ return 1;
39
+
40
+ /* test against read devtype and masked devarch value */
41
+ ret = (dev->uci.devtype == uci->devtype) &&
42
+ ((dev->uci.devarch & uci->devarch_mask) == uci->devarch);
43
+ return ret;
44
+}
45
+
2946 static const struct amba_id *
3047 amba_lookup(const struct amba_id *table, struct amba_device *dev)
3148 {
32
- int ret = 0;
33
-
3449 while (table->mask) {
35
- ret = (dev->periphid & table->mask) == table->id;
36
- if (ret)
37
- break;
50
+ if (((dev->periphid & table->mask) == table->id) &&
51
+ ((dev->cid != CORESIGHT_CID) ||
52
+ (amba_cs_uci_id_match(table, dev))))
53
+ return table;
3854 table++;
3955 }
40
-
41
- return ret ? table : NULL;
56
+ return NULL;
4257 }
4358
4459 static int amba_match(struct device *dev, struct device_driver *drv)
....@@ -284,11 +299,10 @@
284299 {
285300 struct amba_device *pcdev = to_amba_device(dev);
286301 struct amba_driver *drv = to_amba_driver(dev->driver);
287
- int ret = 0;
288302
289303 pm_runtime_get_sync(dev);
290304 if (drv->remove)
291
- ret = drv->remove(pcdev);
305
+ drv->remove(pcdev);
292306 pm_runtime_put_noidle(dev);
293307
294308 /* Undo the runtime PM settings in amba_probe() */
....@@ -299,7 +313,7 @@
299313 amba_put_disable_pclk(pcdev);
300314 dev_pm_domain_detach(dev, true);
301315
302
- return ret;
316
+ return 0;
303317 }
304318
305319 static void amba_shutdown(struct device *dev)
....@@ -388,6 +402,21 @@
388402 ret = amba_get_enable_pclk(dev);
389403 if (ret == 0) {
390404 u32 pid, cid;
405
+ struct reset_control *rstc;
406
+
407
+ /*
408
+ * Find reset control(s) of the amba bus and de-assert them.
409
+ */
410
+ rstc = of_reset_control_array_get_optional_shared(dev->dev.of_node);
411
+ if (IS_ERR(rstc)) {
412
+ ret = PTR_ERR(rstc);
413
+ if (ret != -EPROBE_DEFER)
414
+ dev_err(&dev->dev, "can't get reset: %d\n",
415
+ ret);
416
+ goto err_reset;
417
+ }
418
+ reset_control_deassert(rstc);
419
+ reset_control_put(rstc);
391420
392421 /*
393422 * Read pid and cid based on size of resource
....@@ -400,10 +429,22 @@
400429 cid |= (readl(tmp + size - 0x10 + 4 * i) & 255) <<
401430 (i * 8);
402431
432
+ if (cid == CORESIGHT_CID) {
433
+ /* set the base to the start of the last 4k block */
434
+ void __iomem *csbase = tmp + size - 4096;
435
+
436
+ dev->uci.devarch =
437
+ readl(csbase + UCI_REG_DEVARCH_OFFSET);
438
+ dev->uci.devtype =
439
+ readl(csbase + UCI_REG_DEVTYPE_OFFSET) & 0xff;
440
+ }
441
+
403442 amba_put_disable_pclk(dev);
404443
405
- if (cid == AMBA_CID || cid == CORESIGHT_CID)
444
+ if (cid == AMBA_CID || cid == CORESIGHT_CID) {
406445 dev->periphid = pid;
446
+ dev->cid = cid;
447
+ }
407448
408449 if (!dev->periphid)
409450 ret = -ENODEV;
....@@ -433,6 +474,12 @@
433474 release_resource(&dev->res);
434475 err_out:
435476 return ret;
477
+
478
+ err_reset:
479
+ amba_put_disable_pclk(dev);
480
+ iounmap(tmp);
481
+ dev_pm_domain_detach(&dev->dev, true);
482
+ goto err_release;
436483 }
437484
438485 /*
....@@ -458,7 +505,7 @@
458505
459506 #define DEFERRED_DEVICE_TIMEOUT (msecs_to_jiffies(5 * 1000))
460507
461
-static void amba_deferred_retry_func(struct work_struct *dummy)
508
+static int amba_deferred_retry(void)
462509 {
463510 struct deferred_device *ddev, *tmp;
464511
....@@ -474,11 +521,19 @@
474521 kfree(ddev);
475522 }
476523
524
+ mutex_unlock(&deferred_devices_lock);
525
+
526
+ return 0;
527
+}
528
+late_initcall(amba_deferred_retry);
529
+
530
+static void amba_deferred_retry_func(struct work_struct *dummy)
531
+{
532
+ amba_deferred_retry();
533
+
477534 if (!list_empty(&deferred_devices))
478535 schedule_delayed_work(&deferred_retry_work,
479536 DEFERRED_DEVICE_TIMEOUT);
480
-
481
- mutex_unlock(&deferred_devices_lock);
482537 }
483538
484539 /**
....@@ -598,6 +653,7 @@
598653 dev->dev.release = amba_device_release;
599654 dev->dev.bus = &amba_bustype;
600655 dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
656
+ dev->dev.dma_parms = &dev->dma_parms;
601657 dev->res.name = dev_name(&dev->dev);
602658 }
603659