2014-10-04 17:29:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 Google, Inc
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2015-07-08 02:53:44 +00:00
|
|
|
struct simple_bus_plat {
|
|
|
|
u32 base;
|
|
|
|
u32 size;
|
|
|
|
u32 target;
|
|
|
|
};
|
|
|
|
|
|
|
|
fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr)
|
|
|
|
{
|
|
|
|
struct simple_bus_plat *plat = dev_get_uclass_platdata(dev);
|
|
|
|
|
|
|
|
if (addr >= plat->base && addr < plat->base + plat->size)
|
|
|
|
addr = (addr - plat->base) + plat->target;
|
|
|
|
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
2014-10-04 17:29:37 +00:00
|
|
|
static int simple_bus_post_bind(struct udevice *dev)
|
|
|
|
{
|
2017-01-18 12:25:44 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OF_PLATDATA)
|
|
|
|
return 0;
|
|
|
|
#else
|
2015-07-08 02:53:44 +00:00
|
|
|
u32 cell[3];
|
|
|
|
int ret;
|
|
|
|
|
2017-01-17 23:52:55 +00:00
|
|
|
ret = fdtdec_get_int_array(gd->fdt_blob, dev_of_offset(dev), "ranges",
|
2015-07-08 02:53:44 +00:00
|
|
|
cell, ARRAY_SIZE(cell));
|
|
|
|
if (!ret) {
|
|
|
|
struct simple_bus_plat *plat = dev_get_uclass_platdata(dev);
|
|
|
|
|
|
|
|
plat->base = cell[0];
|
|
|
|
plat->target = cell[1];
|
|
|
|
plat->size = cell[2];
|
|
|
|
}
|
|
|
|
|
2016-07-05 23:10:09 +00:00
|
|
|
return dm_scan_fdt_dev(dev);
|
2017-01-18 12:25:44 +00:00
|
|
|
#endif
|
2014-10-04 17:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UCLASS_DRIVER(simple_bus) = {
|
|
|
|
.id = UCLASS_SIMPLE_BUS,
|
|
|
|
.name = "simple_bus",
|
|
|
|
.post_bind = simple_bus_post_bind,
|
2015-07-08 02:53:44 +00:00
|
|
|
.per_device_platdata_auto_alloc_size = sizeof(struct simple_bus_plat),
|
2014-10-04 17:29:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id generic_simple_bus_ids[] = {
|
|
|
|
{ .compatible = "simple-bus" },
|
2016-03-01 02:51:48 +00:00
|
|
|
{ .compatible = "simple-mfd" },
|
2014-10-04 17:29:37 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(simple_bus_drv) = {
|
|
|
|
.name = "generic_simple_bus",
|
|
|
|
.id = UCLASS_SIMPLE_BUS,
|
|
|
|
.of_match = generic_simple_bus_ids,
|
|
|
|
};
|