]> Git Repo - J-u-boot.git/blob - drivers/core/simple-bus.c
dm: core: Show device sequence instead in dm_dump_tree()
[J-u-boot.git] / drivers / core / simple-bus.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2014 Google, Inc
4  */
5
6 #define LOG_CATEGORY UCLASS_SIMPLE_BUS
7
8 #include <asm/global_data.h>
9 #include <dm.h>
10 #include <dm/simple_bus.h>
11 #include <fdt_support.h>
12
13 DECLARE_GLOBAL_DATA_PTR;
14
15 fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr)
16 {
17         struct simple_bus_plat *plat = dev_get_uclass_plat(dev);
18
19         if (addr >= plat->base && addr < plat->base + plat->size)
20                 addr = (addr - plat->base) + plat->target;
21
22         return addr;
23 }
24
25 static int simple_bus_post_bind(struct udevice *dev)
26 {
27 #if CONFIG_IS_ENABLED(OF_PLATDATA)
28         return 0;
29 #else
30         struct simple_bus_plat *plat = dev_get_uclass_plat(dev);
31         int ret;
32
33         if (CONFIG_IS_ENABLED(SIMPLE_BUS_CORRECT_RANGE)) {
34                 uint64_t caddr, paddr, len;
35
36                 /* only read range index 0 */
37                 ret = fdt_read_range((void *)gd->fdt_blob, dev_of_offset(dev),
38                                      0, &caddr, &paddr, &len);
39                 if (!ret) {
40                         plat->base = caddr;
41                         plat->target = paddr;
42                         plat->size = len;
43                 }
44         } else {
45                 u32 cell[3];
46
47                 ret = dev_read_u32_array(dev, "ranges", cell,
48                                          ARRAY_SIZE(cell));
49                 if (!ret) {
50                         plat->base = cell[0];
51                         plat->target = cell[1];
52                         plat->size = cell[2];
53                 }
54         }
55
56         return dm_scan_fdt_dev(dev);
57 #endif
58 }
59
60 UCLASS_DRIVER(simple_bus) = {
61         .id             = UCLASS_SIMPLE_BUS,
62         .name           = "simple_bus",
63         .post_bind      = simple_bus_post_bind,
64         .per_device_plat_auto   = sizeof(struct simple_bus_plat),
65 };
66
67 #if CONFIG_IS_ENABLED(OF_REAL)
68 static const struct udevice_id generic_simple_bus_ids[] = {
69         { .compatible = "simple-bus" },
70         { .compatible = "simple-mfd" },
71         { }
72 };
73 #endif
74
75 U_BOOT_DRIVER(simple_bus) = {
76         .name   = "simple_bus",
77         .id     = UCLASS_SIMPLE_BUS,
78         .of_match = of_match_ptr(generic_simple_bus_ids),
79         .flags  = DM_FLAG_PRE_RELOC,
80 };
This page took 0.030523 seconds and 4 git commands to generate.