ARM: uniphier: detect register base addresses run-time
Until the last SoC, the register addresses have been hard-coded because
they are always constant. For a planned new SoC, the register bases
will be completely changed. I insist on supporting multiple SoCs/boards
by a single defconfig (uniphier_v8_defconfig) since duplicating similar
defconfig files is a maintenance burden. The base addresses must be
fixed-up at run-time somehow.
Previously, the board init code identified the SoC by reading out the
SG_REVISION register. This is much easier than parsing DT.
You cannot do it any more because the base address of SG will be
changed. The SG_REVISION register exists to read out the SoC ID, but
you never know its address before identifying the SoC. Oh well.
So, the possible solution is to parse the DT, and find out the node
with "*-soc-glue" compatible string. Then, sg_base is set to the value
of the "reg" property. The sc_base is set up likewise.
It is worth noting a pit-fall. Having sc_base and sg_base in the global
scope will make the life easier, but the global variables are poorly
supported before the relocation. In fact, the .bss section overwraps
with DT. Allocating them in the .bss section would break DT. So, I gave
dummy initializers to assign them in the .data section.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2019-07-10 11:07:42 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
//
|
|
|
|
// Copyright (C) 2019 Socionext Inc.
|
|
|
|
// Author: Masahiro Yamada <yamada.masahiro@socionext.com>
|
|
|
|
|
|
|
|
#include <dm/of.h>
|
|
|
|
#include <fdt_support.h>
|
2020-05-20 03:31:27 +00:00
|
|
|
#include <linux/errno.h>
|
ARM: uniphier: detect register base addresses run-time
Until the last SoC, the register addresses have been hard-coded because
they are always constant. For a planned new SoC, the register bases
will be completely changed. I insist on supporting multiple SoCs/boards
by a single defconfig (uniphier_v8_defconfig) since duplicating similar
defconfig files is a maintenance burden. The base addresses must be
fixed-up at run-time somehow.
Previously, the board init code identified the SoC by reading out the
SG_REVISION register. This is much easier than parsing DT.
You cannot do it any more because the base address of SG will be
changed. The SG_REVISION register exists to read out the SoC ID, but
you never know its address before identifying the SoC. Oh well.
So, the possible solution is to parse the DT, and find out the node
with "*-soc-glue" compatible string. Then, sg_base is set to the value
of the "reg" property. The sc_base is set up likewise.
It is worth noting a pit-fall. Having sc_base and sg_base in the global
scope will make the life easier, but the global variables are poorly
supported before the relocation. In fact, the .bss section overwraps
with DT. Allocating them in the .bss section would break DT. So, I gave
dummy initializers to assign them in the .data section.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2019-07-10 11:07:42 +00:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/libfdt.h>
|
|
|
|
#include <linux/sizes.h>
|
|
|
|
#include <asm/global_data.h>
|
|
|
|
|
|
|
|
#include "base-address.h"
|
|
|
|
#include "sc64-regs.h"
|
|
|
|
#include "sg-regs.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dummy initializers are needed to allocate these to .data section instead of
|
|
|
|
* .bss section. The .bss section is unusable before relocation because the
|
|
|
|
* .bss section and DT share the same address. Without the initializers,
|
|
|
|
* DT would be broken.
|
|
|
|
*/
|
|
|
|
void __iomem *sc_base = (void *)0xdeadbeef;
|
|
|
|
void __iomem *sg_base = (void *)0xdeadbeef;
|
|
|
|
|
|
|
|
static u64 uniphier_base_address_get(const char *compat_tail)
|
|
|
|
{
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
const void *fdt = gd->fdt_blob;
|
|
|
|
int offset, len, i;
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
for (offset = fdt_next_node(fdt, 0, NULL);
|
|
|
|
offset >= 0;
|
|
|
|
offset = fdt_next_node(fdt, offset, NULL)) {
|
|
|
|
for (i = 0;
|
|
|
|
(str = fdt_stringlist_get(fdt, offset, "compatible", i, &len));
|
|
|
|
i++) {
|
|
|
|
if (!memcmp(compat_tail,
|
|
|
|
str + len - strlen(compat_tail),
|
|
|
|
strlen(compat_tail)))
|
|
|
|
return fdt_get_base_address(fdt, offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OF_BAD_ADDR;
|
|
|
|
}
|
|
|
|
|
|
|
|
int uniphier_base_address_init(void)
|
|
|
|
{
|
|
|
|
u64 base;
|
|
|
|
|
|
|
|
base = uniphier_base_address_get("-soc-glue");
|
|
|
|
if (base == OF_BAD_ADDR)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
sg_base = ioremap(base, SZ_8K);
|
|
|
|
|
|
|
|
base = uniphier_base_address_get("-sysctrl");
|
|
|
|
if (base == OF_BAD_ADDR)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
sc_base = ioremap(base, SZ_64K);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|