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 | 7db0683 | 2020-12-19 10:40:03 -0700 | [diff] [blame] | 8 | #include <dm/simple_bus.h> |
Simon Glass | 59b6196 | 2015-07-07 20:53:44 -0600 | [diff] [blame] | 9 | |
| 10 | fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr) |
| 11 | { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 12 | struct simple_bus_plat *plat = dev_get_uclass_plat(dev); |
Simon Glass | 59b6196 | 2015-07-07 20:53:44 -0600 | [diff] [blame] | 13 | |
| 14 | if (addr >= plat->base && addr < plat->base + plat->size) |
| 15 | addr = (addr - plat->base) + plat->target; |
| 16 | |
| 17 | return addr; |
| 18 | } |
| 19 | |
Simon Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 20 | static int simple_bus_post_bind(struct udevice *dev) |
| 21 | { |
Kever Yang | 22d088c | 2017-01-18 20:25:44 +0800 | [diff] [blame] | 22 | #if CONFIG_IS_ENABLED(OF_PLATDATA) |
| 23 | return 0; |
| 24 | #else |
Simon Glass | 59b6196 | 2015-07-07 20:53:44 -0600 | [diff] [blame] | 25 | u32 cell[3]; |
| 26 | int ret; |
| 27 | |
Simon Glass | b3cf4fa | 2017-05-18 20:09:11 -0600 | [diff] [blame] | 28 | ret = dev_read_u32_array(dev, "ranges", cell, ARRAY_SIZE(cell)); |
Simon Glass | 59b6196 | 2015-07-07 20:53:44 -0600 | [diff] [blame] | 29 | if (!ret) { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 30 | struct simple_bus_plat *plat = dev_get_uclass_plat(dev); |
Simon Glass | 59b6196 | 2015-07-07 20:53:44 -0600 | [diff] [blame] | 31 | |
| 32 | plat->base = cell[0]; |
| 33 | plat->target = cell[1]; |
| 34 | plat->size = cell[2]; |
| 35 | } |
| 36 | |
Simon Glass | 09128c5 | 2016-07-05 17:10:09 -0600 | [diff] [blame] | 37 | return dm_scan_fdt_dev(dev); |
Kever Yang | 22d088c | 2017-01-18 20:25:44 +0800 | [diff] [blame] | 38 | #endif |
Simon Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | UCLASS_DRIVER(simple_bus) = { |
| 42 | .id = UCLASS_SIMPLE_BUS, |
| 43 | .name = "simple_bus", |
| 44 | .post_bind = simple_bus_post_bind, |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 45 | .per_device_plat_auto = sizeof(struct simple_bus_plat), |
Simon Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 46 | }; |
| 47 | |
Simon Glass | 76404d8 | 2020-12-22 19:30:24 -0700 | [diff] [blame] | 48 | #if !CONFIG_IS_ENABLED(OF_PLATDATA) |
Simon Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 49 | static const struct udevice_id generic_simple_bus_ids[] = { |
| 50 | { .compatible = "simple-bus" }, |
Masahiro Yamada | 4fe976c | 2016-03-01 11:51:48 +0900 | [diff] [blame] | 51 | { .compatible = "simple-mfd" }, |
Simon Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 52 | { } |
| 53 | }; |
Simon Glass | 76404d8 | 2020-12-22 19:30:24 -0700 | [diff] [blame] | 54 | #endif |
Simon Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 55 | |
Walter Lozano | 2901ac6 | 2020-06-25 01:10:04 -0300 | [diff] [blame] | 56 | U_BOOT_DRIVER(simple_bus) = { |
| 57 | .name = "simple_bus", |
Simon Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 58 | .id = UCLASS_SIMPLE_BUS, |
Simon Glass | 76404d8 | 2020-12-22 19:30:24 -0700 | [diff] [blame] | 59 | .of_match = of_match_ptr(generic_simple_bus_ids), |
Lukas Auer | 54310eb | 2019-04-10 14:46:07 +0200 | [diff] [blame] | 60 | .flags = DM_FLAG_PRE_RELOC, |
Simon Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 61 | }; |