blob: b0c2c20958718bec7e6ba6decfbdd02fd99fa622 [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 Glass7db06832020-12-19 10:40:03 -07008#include <dm/simple_bus.h>
Simon Glass59b61962015-07-07 20:53:44 -06009
10fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr)
11{
Simon Glass71fa5b42020-12-03 16:55:18 -070012 struct simple_bus_plat *plat = dev_get_uclass_plat(dev);
Simon Glass59b61962015-07-07 20:53:44 -060013
14 if (addr >= plat->base && addr < plat->base + plat->size)
15 addr = (addr - plat->base) + plat->target;
16
17 return addr;
18}
19
Simon Glass599447c2014-10-04 11:29:37 -060020static int simple_bus_post_bind(struct udevice *dev)
21{
Kever Yang22d088c2017-01-18 20:25:44 +080022#if CONFIG_IS_ENABLED(OF_PLATDATA)
23 return 0;
24#else
Simon Glass59b61962015-07-07 20:53:44 -060025 u32 cell[3];
26 int ret;
27
Simon Glassb3cf4fa2017-05-18 20:09:11 -060028 ret = dev_read_u32_array(dev, "ranges", cell, ARRAY_SIZE(cell));
Simon Glass59b61962015-07-07 20:53:44 -060029 if (!ret) {
Simon Glass71fa5b42020-12-03 16:55:18 -070030 struct simple_bus_plat *plat = dev_get_uclass_plat(dev);
Simon Glass59b61962015-07-07 20:53:44 -060031
32 plat->base = cell[0];
33 plat->target = cell[1];
34 plat->size = cell[2];
35 }
36
Simon Glass09128c52016-07-05 17:10:09 -060037 return dm_scan_fdt_dev(dev);
Kever Yang22d088c2017-01-18 20:25:44 +080038#endif
Simon Glass599447c2014-10-04 11:29:37 -060039}
40
41UCLASS_DRIVER(simple_bus) = {
42 .id = UCLASS_SIMPLE_BUS,
43 .name = "simple_bus",
44 .post_bind = simple_bus_post_bind,
Simon Glass71fa5b42020-12-03 16:55:18 -070045 .per_device_plat_auto = sizeof(struct simple_bus_plat),
Simon Glass599447c2014-10-04 11:29:37 -060046};
47
Simon Glass76404d82020-12-22 19:30:24 -070048#if !CONFIG_IS_ENABLED(OF_PLATDATA)
Simon Glass599447c2014-10-04 11:29:37 -060049static const struct udevice_id generic_simple_bus_ids[] = {
50 { .compatible = "simple-bus" },
Masahiro Yamada4fe976c2016-03-01 11:51:48 +090051 { .compatible = "simple-mfd" },
Simon Glass599447c2014-10-04 11:29:37 -060052 { }
53};
Simon Glass76404d82020-12-22 19:30:24 -070054#endif
Simon Glass599447c2014-10-04 11:29:37 -060055
Walter Lozano2901ac62020-06-25 01:10:04 -030056U_BOOT_DRIVER(simple_bus) = {
57 .name = "simple_bus",
Simon Glass599447c2014-10-04 11:29:37 -060058 .id = UCLASS_SIMPLE_BUS,
Simon Glass76404d82020-12-22 19:30:24 -070059 .of_match = of_match_ptr(generic_simple_bus_ids),
Lukas Auer54310eb2019-04-10 14:46:07 +020060 .flags = DM_FLAG_PRE_RELOC,
Simon Glass599447c2014-10-04 11:29:37 -060061};