1 /* 2 * SPDX-License-Identifier: GPL-2.0+ 3 * 4 * (C) Copyright 2018 Rockchip Electronics Co., Ltd 5 * 6 */ 7 8 #include <asm/io.h> 9 #include <common.h> 10 #include <dm.h> 11 #include <fdtdec.h> 12 13 void iomem_show(const char *label, unsigned long base, size_t start, size_t end) 14 { 15 unsigned long val, offset = start, nr = 0; 16 17 if (label) 18 printf("%s:\n", label); 19 20 printf("%08lx: ", base + offset); 21 for (offset = start; offset <= end; offset += 0x04) { 22 if (nr >= 4) { 23 printf("\n%08lx: ", base + offset); 24 nr = 0; 25 } 26 val = readl((void __iomem *)base + offset); 27 printf("%08lx ", val); 28 nr++; 29 } 30 printf("\n"); 31 } 32 33 void iomem_show_by_compatible(const char *compat, size_t start, size_t end) 34 { 35 const void *fdt = gd->fdt_blob; 36 const char *compatible; 37 fdt_addr_t addr; 38 int offset; 39 40 if (!compat) 41 return; 42 43 for (offset = fdt_next_node(fdt, 0, NULL); 44 offset >= 0; 45 offset = fdt_next_node(fdt, offset, NULL)) { 46 compatible = fdt_getprop(fdt, offset, "compatible", NULL); 47 if (!compatible) 48 continue; 49 50 if (strstr(compatible, compat)) { 51 addr = fdtdec_get_addr_size_auto_noparent(fdt, offset, 52 "reg", 0, NULL, false); 53 compatible = fdt_getprop(fdt, offset, "compatible", 54 NULL); 55 iomem_show(compatible, addr, start, end); 56 break; 57 } 58 } 59 60 printf("\n"); 61 } 62 63 static int do_iomem_by_compatible(cmd_tbl_t *cmdtp, int flag, int argc, 64 char *const argv[]) 65 { 66 size_t start, end; 67 const char *compat; 68 69 if (argc != 4) 70 return CMD_RET_USAGE; 71 72 compat = argv[1]; 73 start = simple_strtoul(argv[2], NULL, 0); 74 end = simple_strtoul(argv[3], NULL, 0); 75 76 iomem_show_by_compatible(compat, start, end); 77 78 return 0; 79 } 80 81 U_BOOT_CMD( 82 iomem, 4, 1, do_iomem_by_compatible, 83 "Show iomem data by device compatible", 84 "iomem <compatible> <start offset> <end offset>\n" 85 " eg: iomem -grf 0x0 0x200" 86 ); 87