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
|
|
|
|
*/
|
|
|
|
|
2021-04-27 09:02:19 +00:00
|
|
|
#define LOG_CATEGORY UCLASS_SIMPLE_BUS
|
|
|
|
|
2014-10-04 17:29:37 +00:00
|
|
|
#include <common.h>
|
2021-03-14 12:15:02 +00:00
|
|
|
#include <asm/global_data.h>
|
2014-10-04 17:29:37 +00:00
|
|
|
#include <dm.h>
|
2020-12-19 17:40:03 +00:00
|
|
|
#include <dm/simple_bus.h>
|
2021-03-14 12:15:02 +00:00
|
|
|
#include <fdt_support.h>
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
2015-07-08 02:53:44 +00:00
|
|
|
|
|
|
|
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
|
2021-03-14 12:15:02 +00:00
|
|
|
struct simple_bus_plat *plat = dev_get_uclass_plat(dev);
|
2015-07-08 02:53:44 +00:00
|
|
|
int ret;
|
|
|
|
|
2021-03-14 12:15:02 +00:00
|
|
|
if (CONFIG_IS_ENABLED(SIMPLE_BUS_CORRECT_RANGE)) {
|
|
|
|
uint64_t caddr, paddr, len;
|
|
|
|
|
|
|
|
/* only read range index 0 */
|
|
|
|
ret = fdt_read_range((void *)gd->fdt_blob, dev_of_offset(dev),
|
|
|
|
0, &caddr, &paddr, &len);
|
|
|
|
if (!ret) {
|
|
|
|
plat->base = caddr;
|
|
|
|
plat->target = paddr;
|
|
|
|
plat->size = len;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
u32 cell[3];
|
2015-07-08 02:53:44 +00:00
|
|
|
|
2021-03-14 12:15:02 +00:00
|
|
|
ret = dev_read_u32_array(dev, "ranges", cell,
|
|
|
|
ARRAY_SIZE(cell));
|
|
|
|
if (!ret) {
|
|
|
|
plat->base = cell[0];
|
|
|
|
plat->target = cell[1];
|
|
|
|
plat->size = cell[2];
|
|
|
|
}
|
2015-07-08 02:53:44 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2020-12-23 02:30:24 +00:00
|
|
|
#if !CONFIG_IS_ENABLED(OF_PLATDATA)
|
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-12-23 02:30:24 +00:00
|
|
|
#endif
|
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,
|
2020-12-23 02:30:24 +00:00
|
|
|
.of_match = of_match_ptr(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
|
|
|
};
|