1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (c) 2014 Google, Inc
4 */
5
6 #include <common.h>
7 #include <dm.h>
8 #include <dm/simple_bus.h>
9
simple_bus_translate(struct udevice * dev,fdt_addr_t addr)10 fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr)
11 {
12 struct simple_bus_plat *plat = dev_get_uclass_plat(dev);
13
14 if (addr >= plat->base && addr < plat->base + plat->size)
15 addr = (addr - plat->base) + plat->target;
16
17 return addr;
18 }
19
simple_bus_post_bind(struct udevice * dev)20 static int simple_bus_post_bind(struct udevice *dev)
21 {
22 #if CONFIG_IS_ENABLED(OF_PLATDATA)
23 return 0;
24 #else
25 u32 cell[3];
26 int ret;
27
28 ret = dev_read_u32_array(dev, "ranges", cell, ARRAY_SIZE(cell));
29 if (!ret) {
30 struct simple_bus_plat *plat = dev_get_uclass_plat(dev);
31
32 plat->base = cell[0];
33 plat->target = cell[1];
34 plat->size = cell[2];
35 }
36
37 return dm_scan_fdt_dev(dev);
38 #endif
39 }
40
41 UCLASS_DRIVER(simple_bus) = {
42 .id = UCLASS_SIMPLE_BUS,
43 .name = "simple_bus",
44 .post_bind = simple_bus_post_bind,
45 .per_device_plat_auto = sizeof(struct simple_bus_plat),
46 };
47
48 #if !CONFIG_IS_ENABLED(OF_PLATDATA)
49 static const struct udevice_id generic_simple_bus_ids[] = {
50 { .compatible = "simple-bus" },
51 { .compatible = "simple-mfd" },
52 { }
53 };
54 #endif
55
56 U_BOOT_DRIVER(simple_bus) = {
57 .name = "simple_bus",
58 .id = UCLASS_SIMPLE_BUS,
59 .of_match = of_match_ptr(generic_simple_bus_ids),
60 .flags = DM_FLAG_PRE_RELOC,
61 };
62