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