2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-10-04 17:29:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 Google, Inc
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
|
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)
|
|
|
|
{
|
2020-12-03 23:55:18 +00:00
|
|
|
struct simple_bus_plat *plat = dev_get_uclass_plat(dev);
|
2015-07-08 02:53:44 +00:00
|
|
|
|
|
|
|
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-05-19 02:09:11 +00:00
|
|
|
ret = dev_read_u32_array(dev, "ranges", cell, ARRAY_SIZE(cell));
|
2015-07-08 02:53:44 +00:00
|
|
|
if (!ret) {
|
2020-12-03 23:55:18 +00:00
|
|
|
struct simple_bus_plat *plat = dev_get_uclass_plat(dev);
|
2015-07-08 02:53:44 +00:00
|
|
|
|
|
|
|
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,
|
2020-12-03 23:55:18 +00:00
|
|
|
.per_device_plat_auto = 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
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2020-06-25 04:10:04 +00:00
|
|
|
U_BOOT_DRIVER(simple_bus) = {
|
|
|
|
.name = "simple_bus",
|
2014-10-04 17:29:37 +00:00
|
|
|
.id = UCLASS_SIMPLE_BUS,
|
|
|
|
.of_match = generic_simple_bus_ids,
|
2019-04-10 12:46:07 +00:00
|
|
|
.flags = DM_FLAG_PRE_RELOC,
|
2014-10-04 17:29:37 +00:00
|
|
|
};
|