blob: 5c955da3346b2c1ff665060100b2f875a87cbe50 [file] [log] [blame]
Simon Glass599447c2014-10-04 11:29:37 -06001/*
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 Glass599447c2014-10-04 11:29:37 -06009
10DECLARE_GLOBAL_DATA_PTR;
11
Simon Glass59b61962015-07-07 20:53:44 -060012struct simple_bus_plat {
13 u32 base;
14 u32 size;
15 u32 target;
16};
17
18fdt_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 Glass599447c2014-10-04 11:29:37 -060028static int simple_bus_post_bind(struct udevice *dev)
29{
Simon Glass59b61962015-07-07 20:53:44 -060030 u32 cell[3];
31 int ret;
32
33 ret = fdtdec_get_int_array(gd->fdt_blob, dev->of_offset, "ranges",
34 cell, ARRAY_SIZE(cell));
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 Glass09128c52016-07-05 17:10:09 -060043 return dm_scan_fdt_dev(dev);
Simon Glass599447c2014-10-04 11:29:37 -060044}
45
46UCLASS_DRIVER(simple_bus) = {
47 .id = UCLASS_SIMPLE_BUS,
48 .name = "simple_bus",
49 .post_bind = simple_bus_post_bind,
Simon Glass59b61962015-07-07 20:53:44 -060050 .per_device_platdata_auto_alloc_size = sizeof(struct simple_bus_plat),
Simon Glass599447c2014-10-04 11:29:37 -060051};
52
53static const struct udevice_id generic_simple_bus_ids[] = {
54 { .compatible = "simple-bus" },
Masahiro Yamada4fe976c2016-03-01 11:51:48 +090055 { .compatible = "simple-mfd" },
Simon Glass599447c2014-10-04 11:29:37 -060056 { }
57};
58
59U_BOOT_DRIVER(simple_bus_drv) = {
60 .name = "generic_simple_bus",
61 .id = UCLASS_SIMPLE_BUS,
62 .of_match = generic_simple_bus_ids,
63};