From 737e12167da416aeda5e7b6cb6972531f8508490 Mon Sep 17 00:00:00 2001 From: Joseph Chen Date: Fri, 13 Jul 2018 11:53:55 +0800 Subject: [PATCH] rockchip: add iomem show interface this is mainly for debug. Change-Id: Ied842841f09780c11092624fb602a3f3723469c3 Signed-off-by: Joseph Chen --- arch/arm/mach-rockchip/Makefile | 1 + arch/arm/mach-rockchip/iomem.c | 86 +++++++++++++++++++++++++++++++++ include/iomem.h | 35 ++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 arch/arm/mach-rockchip/iomem.c create mode 100644 include/iomem.h diff --git a/arch/arm/mach-rockchip/Makefile b/arch/arm/mach-rockchip/Makefile index 1cc2cc35e7..6d0fd25d51 100644 --- a/arch/arm/mach-rockchip/Makefile +++ b/arch/arm/mach-rockchip/Makefile @@ -23,6 +23,7 @@ ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),) obj-y += boot_mode.o obj-y += board.o obj-y += chip_info.o +obj-y += iomem.o obj-$(CONFIG_ROCKCHIP_CRC) += rockchip_crc.o obj-$(CONFIG_ROCKCHIP_SMCCC) += rockchip_smccc.o diff --git a/arch/arm/mach-rockchip/iomem.c b/arch/arm/mach-rockchip/iomem.c new file mode 100644 index 0000000000..75b8bb3b75 --- /dev/null +++ b/arch/arm/mach-rockchip/iomem.c @@ -0,0 +1,86 @@ +/* + * SPDX-License-Identifier: GPL-2.0+ + * + * (C) Copyright 2018 Rockchip Electronics Co., Ltd + * + */ + +#include +#include +#include +#include + +void iomem_show(const char *label, unsigned long base, size_t start, size_t end) +{ + unsigned long val, offset = start, nr = 0; + + if (label) + printf("%s:\n", label); + + printf("%08lx: ", base + offset); + for (offset = start; offset <= end; offset += 0x04) { + if (nr >= 4) { + printf("\n%08lx: ", base + offset); + nr = 0; + } + val = readl((void __iomem *)base + offset); + printf("%08lx ", val); + nr++; + } + printf("\n"); +} + +void iomem_show_by_compatible(const char *compat, size_t start, size_t end) +{ + const void *fdt = gd->fdt_blob; + const char *compatible; + fdt_addr_t addr; + int offset; + + if (!compat) + return; + + for (offset = fdt_next_node(fdt, 0, NULL); + offset >= 0; + offset = fdt_next_node(fdt, offset, NULL)) { + compatible = fdt_getprop(fdt, offset, "compatible", NULL); + if (!compatible) + continue; + + if (strstr(compatible, compat)) { + addr = fdtdec_get_addr_size_auto_noparent(fdt, offset, + "reg", 0, NULL, false); + compatible = fdt_getprop(fdt, offset, "compatible", + NULL); + iomem_show(compatible, addr, start, end); + break; + } + } + + printf("\n"); +} + +static int do_iomem_by_compatible(cmd_tbl_t *cmdtp, int flag, int argc, + char *const argv[]) +{ + size_t start, end; + const char *compat; + + if (argc != 4) + return CMD_RET_USAGE; + + compat = argv[1]; + start = simple_strtoul(argv[2], NULL, 0); + end = simple_strtoul(argv[3], NULL, 0); + + iomem_show_by_compatible(compat, start, end); + + return 0; +} + +U_BOOT_CMD( + iomem, 4, 1, do_iomem_by_compatible, + "Show iomem data by device compatible", + "iomem \n" + " eg: iomem -grf 0x0 0x200" +); diff --git a/include/iomem.h b/include/iomem.h new file mode 100644 index 0000000000..55ef1573c3 --- /dev/null +++ b/include/iomem.h @@ -0,0 +1,35 @@ +/* + * SPDX-License-Identifier: GPL-2.0+ + * + * (C) Copyright 2018 Rockchip Electronics Co., Ltd + * + */ + +#ifndef _ROCKCHIP_IOMEM_H_ +#define _ROCKCHIP_IOMEM_H_ + +/** + * iomem_show() - Show iomem data. Usually for peripheral registers. + * + * @lable: Title to show + * @base: Base address of iomem + * @start: Start offset + * @end: End offset + */ +void iomem_show(const char *label, unsigned long base, size_t start, size_t end); + +/** + * iomem_show_by_compatible() - Show iomem data and auto find base address by + * compabile(sub string match). + * + * @compat: Compatible name, sub string match. + * @start: Start offset + * @end: End offset + * + * eg: iomem_show_by_compatible("-grf", 0x0, 0x200); + * first node that contains "-grf" will be dump. + * + */ +void iomem_show_by_compatible(const char *compat, size_t start, size_t end); + +#endif