Simon Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 1 | /* |
| 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 Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 9 | |
| 10 | DECLARE_GLOBAL_DATA_PTR; |
| 11 | |
Simon Glass | 59b6196 | 2015-07-07 20:53:44 -0600 | [diff] [blame] | 12 | struct simple_bus_plat { |
| 13 | u32 base; |
| 14 | u32 size; |
| 15 | u32 target; |
| 16 | }; |
| 17 | |
| 18 | fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr) |
| 19 | { |
| 20 | struct simple_bus_plat *plat = dev_get_uclass_platdata(dev); |
| 21 | |
| 22 | if (addr >= plat->base && addr < plat->base + plat->size) |
| 23 | addr = (addr - plat->base) + plat->target; |
| 24 | |
| 25 | return addr; |
| 26 | } |
| 27 | |
Simon Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 28 | static int simple_bus_post_bind(struct udevice *dev) |
| 29 | { |
Kever Yang | 22d088c | 2017-01-18 20:25:44 +0800 | [diff] [blame] | 30 | #if CONFIG_IS_ENABLED(OF_PLATDATA) |
| 31 | return 0; |
| 32 | #else |
Simon Glass | 59b6196 | 2015-07-07 20:53:44 -0600 | [diff] [blame] | 33 | u32 cell[3]; |
| 34 | int ret; |
| 35 | |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 36 | ret = fdtdec_get_int_array(gd->fdt_blob, dev_of_offset(dev), "ranges", |
Simon Glass | 59b6196 | 2015-07-07 20:53:44 -0600 | [diff] [blame] | 37 | cell, ARRAY_SIZE(cell)); |
| 38 | if (!ret) { |
| 39 | struct simple_bus_plat *plat = dev_get_uclass_platdata(dev); |
| 40 | |
| 41 | plat->base = cell[0]; |
| 42 | plat->target = cell[1]; |
| 43 | plat->size = cell[2]; |
| 44 | } |
| 45 | |
Simon Glass | 09128c5 | 2016-07-05 17:10:09 -0600 | [diff] [blame] | 46 | return dm_scan_fdt_dev(dev); |
Kever Yang | 22d088c | 2017-01-18 20:25:44 +0800 | [diff] [blame] | 47 | #endif |
Simon Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | UCLASS_DRIVER(simple_bus) = { |
| 51 | .id = UCLASS_SIMPLE_BUS, |
| 52 | .name = "simple_bus", |
| 53 | .post_bind = simple_bus_post_bind, |
Simon Glass | 59b6196 | 2015-07-07 20:53:44 -0600 | [diff] [blame] | 54 | .per_device_platdata_auto_alloc_size = sizeof(struct simple_bus_plat), |
Simon Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | static const struct udevice_id generic_simple_bus_ids[] = { |
| 58 | { .compatible = "simple-bus" }, |
Masahiro Yamada | 4fe976c | 2016-03-01 11:51:48 +0900 | [diff] [blame] | 59 | { .compatible = "simple-mfd" }, |
Simon Glass | 599447c | 2014-10-04 11:29:37 -0600 | [diff] [blame] | 60 | { } |
| 61 | }; |
| 62 | |
| 63 | U_BOOT_DRIVER(simple_bus_drv) = { |
| 64 | .name = "generic_simple_bus", |
| 65 | .id = UCLASS_SIMPLE_BUS, |
| 66 | .of_match = generic_simple_bus_ids, |
| 67 | }; |