xref: /openbmc/u-boot/drivers/core/simple-bus.c (revision cbd2fba1)
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 
9 struct simple_bus_plat {
10 	u32 base;
11 	u32 size;
12 	u32 target;
13 };
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_platdata(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 	u32 cell[3];
31 	int ret;
32 
33 	ret = dev_read_u32_array(dev, "ranges", cell, ARRAY_SIZE(cell));
34 	if (!ret) {
35 		struct simple_bus_plat *plat = dev_get_uclass_platdata(dev);
36 
37 		plat->base = cell[0];
38 		plat->target = cell[1];
39 		plat->size = cell[2];
40 	}
41 
42 	return dm_scan_fdt_dev(dev);
43 #endif
44 }
45 
46 UCLASS_DRIVER(simple_bus) = {
47 	.id		= UCLASS_SIMPLE_BUS,
48 	.name		= "simple_bus",
49 	.post_bind	= simple_bus_post_bind,
50 	.per_device_platdata_auto_alloc_size = sizeof(struct simple_bus_plat),
51 };
52 
53 static const struct udevice_id generic_simple_bus_ids[] = {
54 	{ .compatible = "simple-bus" },
55 	{ .compatible = "simple-mfd" },
56 	{ }
57 };
58 
59 U_BOOT_DRIVER(simple_bus_drv) = {
60 	.name	= "generic_simple_bus",
61 	.id	= UCLASS_SIMPLE_BUS,
62 	.of_match = generic_simple_bus_ids,
63 };
64