blob: 5acfa5f0e492b558bcc77f4cd9c0ca30d27e5f55 [file] [log] [blame]
Simon Glass599447c2014-10-04 11:29:37 -06001/*
2 * Copyright (c) 2014 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <dm.h>
Simon Glass599447c2014-10-04 11:29:37 -06009
Simon Glass59b61962015-07-07 20:53:44 -060010struct simple_bus_plat {
11 u32 base;
12 u32 size;
13 u32 target;
14};
15
16fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr)
17{
18 struct simple_bus_plat *plat = dev_get_uclass_platdata(dev);
19
20 if (addr >= plat->base && addr < plat->base + plat->size)
21 addr = (addr - plat->base) + plat->target;
22
23 return addr;
24}
25
Simon Glass599447c2014-10-04 11:29:37 -060026static int simple_bus_post_bind(struct udevice *dev)
27{
Kever Yang22d088c2017-01-18 20:25:44 +080028#if CONFIG_IS_ENABLED(OF_PLATDATA)
29 return 0;
30#else
Simon Glass59b61962015-07-07 20:53:44 -060031 u32 cell[3];
32 int ret;
33
Simon Glassb3cf4fa2017-05-18 20:09:11 -060034 ret = dev_read_u32_array(dev, "ranges", cell, ARRAY_SIZE(cell));
Simon Glass59b61962015-07-07 20:53:44 -060035 if (!ret) {
36 struct simple_bus_plat *plat = dev_get_uclass_platdata(dev);
37
38 plat->base = cell[0];
39 plat->target = cell[1];
40 plat->size = cell[2];
41 }
42
Simon Glass09128c52016-07-05 17:10:09 -060043 return dm_scan_fdt_dev(dev);
Kever Yang22d088c2017-01-18 20:25:44 +080044#endif
Simon Glass599447c2014-10-04 11:29:37 -060045}
46
47UCLASS_DRIVER(simple_bus) = {
48 .id = UCLASS_SIMPLE_BUS,
49 .name = "simple_bus",
50 .post_bind = simple_bus_post_bind,
Simon Glass59b61962015-07-07 20:53:44 -060051 .per_device_platdata_auto_alloc_size = sizeof(struct simple_bus_plat),
Simon Glass599447c2014-10-04 11:29:37 -060052};
53
54static const struct udevice_id generic_simple_bus_ids[] = {
55 { .compatible = "simple-bus" },
Masahiro Yamada4fe976c2016-03-01 11:51:48 +090056 { .compatible = "simple-mfd" },
Simon Glass599447c2014-10-04 11:29:37 -060057 { }
58};
59
60U_BOOT_DRIVER(simple_bus_drv) = {
61 .name = "generic_simple_bus",
62 .id = UCLASS_SIMPLE_BUS,
63 .of_match = generic_simple_bus_ids,
64};