Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014 Google, Inc |
Simon Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
Simon Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 8 | |
Simon Glass | 59b6196 | 2015-07-07 20:53:44 -0600 | [diff] [blame] | 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 | |
Simon Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 25 | static int simple_bus_post_bind(struct udevice *dev) |
| 26 | { |
Kever Yang | 22d088c | 2017-01-18 20:25:44 +0800 | [diff] [blame] | 27 | #if CONFIG_IS_ENABLED(OF_PLATDATA) |
| 28 | return 0; |
| 29 | #else |
Simon Glass | 59b6196 | 2015-07-07 20:53:44 -0600 | [diff] [blame] | 30 | u32 cell[3]; |
| 31 | int ret; |
| 32 | |
Simon Glass | b3cf4fa | 2017-05-18 20:09:11 -0600 | [diff] [blame] | 33 | ret = dev_read_u32_array(dev, "ranges", cell, ARRAY_SIZE(cell)); |
Simon Glass | 59b6196 | 2015-07-07 20:53:44 -0600 | [diff] [blame] | 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 | |
Simon Glass | 09128c5 | 2016-07-05 17:10:09 -0600 | [diff] [blame] | 42 | return dm_scan_fdt_dev(dev); |
Kever Yang | 22d088c | 2017-01-18 20:25:44 +0800 | [diff] [blame] | 43 | #endif |
Simon Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | UCLASS_DRIVER(simple_bus) = { |
| 47 | .id = UCLASS_SIMPLE_BUS, |
| 48 | .name = "simple_bus", |
| 49 | .post_bind = simple_bus_post_bind, |
Simon Glass | 59b6196 | 2015-07-07 20:53:44 -0600 | [diff] [blame] | 50 | .per_device_platdata_auto_alloc_size = sizeof(struct simple_bus_plat), |
Simon Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | static const struct udevice_id generic_simple_bus_ids[] = { |
| 54 | { .compatible = "simple-bus" }, |
Masahiro Yamada | 4fe976c | 2016-03-01 11:51:48 +0900 | [diff] [blame] | 55 | { .compatible = "simple-mfd" }, |
Simon Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 56 | { } |
| 57 | }; |
| 58 | |
Walter Lozano | 2901ac6 | 2020-06-25 01:10:04 -0300 | [diff] [blame] | 59 | U_BOOT_DRIVER(simple_bus) = { |
| 60 | .name = "simple_bus", |
Simon Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 61 | .id = UCLASS_SIMPLE_BUS, |
| 62 | .of_match = generic_simple_bus_ids, |
Lukas Auer | 54310eb | 2019-04-10 14:46:07 +0200 | [diff] [blame] | 63 | .flags = DM_FLAG_PRE_RELOC, |
Simon Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 64 | }; |