blob: 1a9c864ef377e65334f0cf50a1e83e49be8675a2 [file] [log] [blame]
Simon Glassda802b92014-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>
9#include <dm/root.h>
10
11DECLARE_GLOBAL_DATA_PTR;
12
Simon Glassf3301772015-07-07 20:53:44 -060013struct simple_bus_plat {
14 u32 base;
15 u32 size;
16 u32 target;
17};
18
19fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr)
20{
21 struct simple_bus_plat *plat = dev_get_uclass_platdata(dev);
22
23 if (addr >= plat->base && addr < plat->base + plat->size)
24 addr = (addr - plat->base) + plat->target;
25
26 return addr;
27}
28
Simon Glassda802b92014-10-04 11:29:37 -060029static int simple_bus_post_bind(struct udevice *dev)
30{
Simon Glassf3301772015-07-07 20:53:44 -060031 u32 cell[3];
32 int ret;
33
34 ret = fdtdec_get_int_array(gd->fdt_blob, dev->of_offset, "ranges",
35 cell, ARRAY_SIZE(cell));
36 if (!ret) {
37 struct simple_bus_plat *plat = dev_get_uclass_platdata(dev);
38
39 plat->base = cell[0];
40 plat->target = cell[1];
41 plat->size = cell[2];
42 }
43
Simon Glassda802b92014-10-04 11:29:37 -060044 return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
45}
46
47UCLASS_DRIVER(simple_bus) = {
48 .id = UCLASS_SIMPLE_BUS,
49 .name = "simple_bus",
50 .post_bind = simple_bus_post_bind,
Simon Glassf3301772015-07-07 20:53:44 -060051 .per_device_platdata_auto_alloc_size = sizeof(struct simple_bus_plat),
Simon Glassda802b92014-10-04 11:29:37 -060052};
53
54static const struct udevice_id generic_simple_bus_ids[] = {
55 { .compatible = "simple-bus" },
Masahiro Yamada9f569172016-03-01 11:51:48 +090056 { .compatible = "simple-mfd" },
Simon Glassda802b92014-10-04 11:29:37 -060057 { }
58};
59
60U_BOOT_DRIVER(simple_bus_drv) = {
61 .name = "generic_simple_bus",
62 .id = UCLASS_SIMPLE_BUS,
63 .of_match = generic_simple_bus_ids,
64};