blob: 7cc1d46009ffc9f94533f1f1350cd89319588b0a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass599447c2014-10-04 11:29:37 -06002/*
3 * Copyright (c) 2014 Google, Inc
Simon Glass599447c2014-10-04 11:29:37 -06004 */
5
6#include <common.h>
7#include <dm.h>
Simon Glass599447c2014-10-04 11:29:37 -06008
Simon Glass59b61962015-07-07 20:53:44 -06009struct simple_bus_plat {
10 u32 base;
11 u32 size;
12 u32 target;
13};
14
15fdt_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
Simon Glass599447c2014-10-04 11:29:37 -060025static int simple_bus_post_bind(struct udevice *dev)
26{
Kever Yang22d088c2017-01-18 20:25:44 +080027#if CONFIG_IS_ENABLED(OF_PLATDATA)
28 return 0;
29#else
Simon Glass59b61962015-07-07 20:53:44 -060030 u32 cell[3];
31 int ret;
32
Simon Glassb3cf4fa2017-05-18 20:09:11 -060033 ret = dev_read_u32_array(dev, "ranges", cell, ARRAY_SIZE(cell));
Simon Glass59b61962015-07-07 20:53:44 -060034 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
Simon Glass09128c52016-07-05 17:10:09 -060042 return dm_scan_fdt_dev(dev);
Kever Yang22d088c2017-01-18 20:25:44 +080043#endif
Simon Glass599447c2014-10-04 11:29:37 -060044}
45
46UCLASS_DRIVER(simple_bus) = {
47 .id = UCLASS_SIMPLE_BUS,
48 .name = "simple_bus",
49 .post_bind = simple_bus_post_bind,
Simon Glass59b61962015-07-07 20:53:44 -060050 .per_device_platdata_auto_alloc_size = sizeof(struct simple_bus_plat),
Simon Glass599447c2014-10-04 11:29:37 -060051};
52
53static const struct udevice_id generic_simple_bus_ids[] = {
54 { .compatible = "simple-bus" },
Masahiro Yamada4fe976c2016-03-01 11:51:48 +090055 { .compatible = "simple-mfd" },
Simon Glass599447c2014-10-04 11:29:37 -060056 { }
57};
58
Walter Lozano2901ac62020-06-25 01:10:04 -030059U_BOOT_DRIVER(simple_bus) = {
60 .name = "simple_bus",
Simon Glass599447c2014-10-04 11:29:37 -060061 .id = UCLASS_SIMPLE_BUS,
62 .of_match = generic_simple_bus_ids,
Lukas Auer54310eb2019-04-10 14:46:07 +020063 .flags = DM_FLAG_PRE_RELOC,
Simon Glass599447c2014-10-04 11:29:37 -060064};