.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * linux/arch/arm/common/amba.c |
---|
3 | 4 | * |
---|
4 | 5 | * 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. |
---|
9 | 6 | */ |
---|
10 | 7 | #include <linux/module.h> |
---|
11 | 8 | #include <linux/init.h> |
---|
.. | .. |
---|
21 | 18 | #include <linux/limits.h> |
---|
22 | 19 | #include <linux/clk/clk-conf.h> |
---|
23 | 20 | #include <linux/platform_device.h> |
---|
| 21 | +#include <linux/reset.h> |
---|
24 | 22 | |
---|
25 | 23 | #include <asm/irq.h> |
---|
26 | 24 | |
---|
27 | 25 | #define to_amba_driver(d) container_of(d, struct amba_driver, drv) |
---|
28 | 26 | |
---|
| 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 | + |
---|
29 | 46 | static const struct amba_id * |
---|
30 | 47 | amba_lookup(const struct amba_id *table, struct amba_device *dev) |
---|
31 | 48 | { |
---|
32 | | - int ret = 0; |
---|
33 | | - |
---|
34 | 49 | 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; |
---|
38 | 54 | table++; |
---|
39 | 55 | } |
---|
40 | | - |
---|
41 | | - return ret ? table : NULL; |
---|
| 56 | + return NULL; |
---|
42 | 57 | } |
---|
43 | 58 | |
---|
44 | 59 | static int amba_match(struct device *dev, struct device_driver *drv) |
---|
.. | .. |
---|
284 | 299 | { |
---|
285 | 300 | struct amba_device *pcdev = to_amba_device(dev); |
---|
286 | 301 | struct amba_driver *drv = to_amba_driver(dev->driver); |
---|
287 | | - int ret = 0; |
---|
288 | 302 | |
---|
289 | 303 | pm_runtime_get_sync(dev); |
---|
290 | 304 | if (drv->remove) |
---|
291 | | - ret = drv->remove(pcdev); |
---|
| 305 | + drv->remove(pcdev); |
---|
292 | 306 | pm_runtime_put_noidle(dev); |
---|
293 | 307 | |
---|
294 | 308 | /* Undo the runtime PM settings in amba_probe() */ |
---|
.. | .. |
---|
299 | 313 | amba_put_disable_pclk(pcdev); |
---|
300 | 314 | dev_pm_domain_detach(dev, true); |
---|
301 | 315 | |
---|
302 | | - return ret; |
---|
| 316 | + return 0; |
---|
303 | 317 | } |
---|
304 | 318 | |
---|
305 | 319 | static void amba_shutdown(struct device *dev) |
---|
.. | .. |
---|
349 | 363 | { |
---|
350 | 364 | struct amba_device *d = to_amba_device(dev); |
---|
351 | 365 | |
---|
| 366 | + of_node_put(d->dev.of_node); |
---|
352 | 367 | if (d->res.parent) |
---|
353 | 368 | release_resource(&d->res); |
---|
354 | 369 | kfree(d); |
---|
.. | .. |
---|
388 | 403 | ret = amba_get_enable_pclk(dev); |
---|
389 | 404 | if (ret == 0) { |
---|
390 | 405 | u32 pid, cid; |
---|
| 406 | + struct reset_control *rstc; |
---|
| 407 | + |
---|
| 408 | + /* |
---|
| 409 | + * Find reset control(s) of the amba bus and de-assert them. |
---|
| 410 | + */ |
---|
| 411 | + rstc = of_reset_control_array_get_optional_shared(dev->dev.of_node); |
---|
| 412 | + if (IS_ERR(rstc)) { |
---|
| 413 | + ret = PTR_ERR(rstc); |
---|
| 414 | + if (ret != -EPROBE_DEFER) |
---|
| 415 | + dev_err(&dev->dev, "can't get reset: %d\n", |
---|
| 416 | + ret); |
---|
| 417 | + goto err_reset; |
---|
| 418 | + } |
---|
| 419 | + reset_control_deassert(rstc); |
---|
| 420 | + reset_control_put(rstc); |
---|
391 | 421 | |
---|
392 | 422 | /* |
---|
393 | 423 | * Read pid and cid based on size of resource |
---|
.. | .. |
---|
400 | 430 | cid |= (readl(tmp + size - 0x10 + 4 * i) & 255) << |
---|
401 | 431 | (i * 8); |
---|
402 | 432 | |
---|
| 433 | + if (cid == CORESIGHT_CID) { |
---|
| 434 | + /* set the base to the start of the last 4k block */ |
---|
| 435 | + void __iomem *csbase = tmp + size - 4096; |
---|
| 436 | + |
---|
| 437 | + dev->uci.devarch = |
---|
| 438 | + readl(csbase + UCI_REG_DEVARCH_OFFSET); |
---|
| 439 | + dev->uci.devtype = |
---|
| 440 | + readl(csbase + UCI_REG_DEVTYPE_OFFSET) & 0xff; |
---|
| 441 | + } |
---|
| 442 | + |
---|
403 | 443 | amba_put_disable_pclk(dev); |
---|
404 | 444 | |
---|
405 | | - if (cid == AMBA_CID || cid == CORESIGHT_CID) |
---|
| 445 | + if (cid == AMBA_CID || cid == CORESIGHT_CID) { |
---|
406 | 446 | dev->periphid = pid; |
---|
| 447 | + dev->cid = cid; |
---|
| 448 | + } |
---|
407 | 449 | |
---|
408 | 450 | if (!dev->periphid) |
---|
409 | 451 | ret = -ENODEV; |
---|
.. | .. |
---|
433 | 475 | release_resource(&dev->res); |
---|
434 | 476 | err_out: |
---|
435 | 477 | return ret; |
---|
| 478 | + |
---|
| 479 | + err_reset: |
---|
| 480 | + amba_put_disable_pclk(dev); |
---|
| 481 | + iounmap(tmp); |
---|
| 482 | + dev_pm_domain_detach(&dev->dev, true); |
---|
| 483 | + goto err_release; |
---|
436 | 484 | } |
---|
437 | 485 | |
---|
438 | 486 | /* |
---|
.. | .. |
---|
458 | 506 | |
---|
459 | 507 | #define DEFERRED_DEVICE_TIMEOUT (msecs_to_jiffies(5 * 1000)) |
---|
460 | 508 | |
---|
461 | | -static void amba_deferred_retry_func(struct work_struct *dummy) |
---|
| 509 | +static int amba_deferred_retry(void) |
---|
462 | 510 | { |
---|
463 | 511 | struct deferred_device *ddev, *tmp; |
---|
464 | 512 | |
---|
.. | .. |
---|
474 | 522 | kfree(ddev); |
---|
475 | 523 | } |
---|
476 | 524 | |
---|
| 525 | + mutex_unlock(&deferred_devices_lock); |
---|
| 526 | + |
---|
| 527 | + return 0; |
---|
| 528 | +} |
---|
| 529 | +late_initcall(amba_deferred_retry); |
---|
| 530 | + |
---|
| 531 | +static void amba_deferred_retry_func(struct work_struct *dummy) |
---|
| 532 | +{ |
---|
| 533 | + amba_deferred_retry(); |
---|
| 534 | + |
---|
477 | 535 | if (!list_empty(&deferred_devices)) |
---|
478 | 536 | schedule_delayed_work(&deferred_retry_work, |
---|
479 | 537 | DEFERRED_DEVICE_TIMEOUT); |
---|
480 | | - |
---|
481 | | - mutex_unlock(&deferred_devices_lock); |
---|
482 | 538 | } |
---|
483 | 539 | |
---|
484 | 540 | /** |
---|
.. | .. |
---|
598 | 654 | dev->dev.release = amba_device_release; |
---|
599 | 655 | dev->dev.bus = &amba_bustype; |
---|
600 | 656 | dev->dev.dma_mask = &dev->dev.coherent_dma_mask; |
---|
| 657 | + dev->dev.dma_parms = &dev->dma_parms; |
---|
601 | 658 | dev->res.name = dev_name(&dev->dev); |
---|
602 | 659 | } |
---|
603 | 660 | |
---|