Skip to content

Commit 8a805df

Browse files
committed
ppc4xx/fdt/flash: Change fdt_fixup_nor_flash_node() to not rely on cs size
This patch changes the behaviour of the fdt_fixup_nor_flash_node() function. Now it doesn't patch the size of the "reg" property with the chip-select size, but with the size returned from the new function flash_get_bank_size(). This function will return per weak default the flash size of the bank (bank = chip-select numer) detected by the flash driver. If this does not fit your needs, this function may be overridden by a board specific one. For this the parameters needed to be changed. So I intentionally squashed the PPC4xx stuff using this routine into this patch. Otherwise it would not be git-bisectable anymore. The board specific function for the AMCC/APM Ebony eval board is now included in this patch version. Signed-off-by: Stefan Roese <sr@denx.de> Tested-by: Detlev Zundel <dzu@denx.de> Cc: Gerald Van Baren <vanbaren@cideas.com> Cc: Wolfgang Denk <wd@denx.de>
1 parent ab25e88 commit 8a805df

File tree

5 files changed

+85
-17
lines changed

5 files changed

+85
-17
lines changed

arch/powerpc/cpu/ppc4xx/fdt.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ void __ft_board_setup(void *blob, bd_t *bd)
5959
*p++ = 0;
6060
*p++ = bxcr & EBC_BXCR_BAS_MASK;
6161
*p++ = EBC_BXCR_BANK_SIZE(bxcr);
62+
}
63+
}
64+
6265

6366
#ifdef CONFIG_FDT_FIXUP_NOR_FLASH_SIZE
64-
/* Try to update reg property in nor flash node too */
65-
fdt_fixup_nor_flash_size(blob, i,
66-
EBC_BXCR_BANK_SIZE(bxcr));
67+
/* Update reg property in all nor flash nodes too */
68+
fdt_fixup_nor_flash_size(blob);
6769
#endif
68-
}
69-
}
7070

7171
/* Some 405 PPC's have EBC as direct PLB child in the dts */
7272
if (fdt_path_offset(blob, ebc_path) < 0)

board/amcc/ebony/flash.c

+31
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <common.h>
3535
#include <ppc4xx.h>
3636
#include <asm/processor.h>
37+
#include <asm/io.h>
3738

3839
#undef DEBUG
3940
#ifdef DEBUG
@@ -71,6 +72,36 @@ static unsigned long flash_addr_table[8][CONFIG_SYS_MAX_FLASH_BANKS] = {
7172
*/
7273
static ulong flash_get_size(vu_long * addr, flash_info_t * info);
7374

75+
/*
76+
* Override the weak default mapping function with a board specific one
77+
*/
78+
u32 flash_get_bank_size(int cs, int idx)
79+
{
80+
u8 reg = in_8((void *)CONFIG_SYS_FPGA_BASE);
81+
82+
if ((reg & BOOT_SMALL_FLASH) && !(reg & FLASH_ONBD_N)) {
83+
/*
84+
* cs0: small flash (512KiB)
85+
* cs2: 2 * big flash (2 * 2MiB)
86+
*/
87+
if (cs == 0)
88+
return flash_info[2].size;
89+
if (cs == 2)
90+
return flash_info[0].size + flash_info[1].size;
91+
} else {
92+
/*
93+
* cs0: 2 * big flash (2 * 2MiB)
94+
* cs2: small flash (512KiB)
95+
*/
96+
if (cs == 0)
97+
return flash_info[0].size + flash_info[1].size;
98+
if (cs == 2)
99+
return flash_info[2].size;
100+
}
101+
102+
return 0;
103+
}
104+
74105
unsigned long flash_init(void)
75106
{
76107
unsigned long total_b = 0;

common/fdt_support.c

+41-10
Original file line numberDiff line numberDiff line change
@@ -590,12 +590,31 @@ int fdt_pci_dma_ranges(void *blob, int phb_off, struct pci_controller *hose) {
590590
#endif
591591

592592
#ifdef CONFIG_FDT_FIXUP_NOR_FLASH_SIZE
593+
/*
594+
* Provide a weak default function to return the flash bank size.
595+
* There might be multiple non-identical flash chips connected to one
596+
* chip-select, so we need to pass an index as well.
597+
*/
598+
u32 __flash_get_bank_size(int cs, int idx)
599+
{
600+
extern flash_info_t flash_info[];
601+
602+
/*
603+
* As default, a simple 1:1 mapping is provided. Boards with
604+
* a different mapping need to supply a board specific mapping
605+
* routine.
606+
*/
607+
return flash_info[cs].size;
608+
}
609+
u32 flash_get_bank_size(int cs, int idx)
610+
__attribute__((weak, alias("__flash_get_bank_size")));
611+
593612
/*
594613
* This function can be used to update the size in the "reg" property
595-
* of the NOR FLASH device nodes. This is necessary for boards with
614+
* of all NOR FLASH device nodes. This is necessary for boards with
596615
* non-fixed NOR FLASH sizes.
597616
*/
598-
int fdt_fixup_nor_flash_size(void *blob, int cs, u32 size)
617+
int fdt_fixup_nor_flash_size(void *blob)
599618
{
600619
char compat[][16] = { "cfi-flash", "jedec-flash" };
601620
int off;
@@ -607,19 +626,31 @@ int fdt_fixup_nor_flash_size(void *blob, int cs, u32 size)
607626
for (i = 0; i < 2; i++) {
608627
off = fdt_node_offset_by_compatible(blob, -1, compat[i]);
609628
while (off != -FDT_ERR_NOTFOUND) {
629+
int idx;
630+
610631
/*
611-
* Found one compatible node, now check if this one
612-
* has the correct CS
632+
* Found one compatible node, so fixup the size
633+
* int its reg properties
613634
*/
614635
prop = fdt_get_property_w(blob, off, "reg", &len);
615636
if (prop) {
637+
int tuple_size = 3 * sizeof(reg);
638+
639+
/*
640+
* There might be multiple reg-tuples,
641+
* so loop through them all
642+
*/
643+
len /= tuple_size;
616644
reg = (u32 *)&prop->data[0];
617-
if (reg[0] == cs) {
618-
reg[2] = size;
645+
for (idx = 0; idx < len; idx++) {
646+
/*
647+
* Update size in reg property
648+
*/
649+
reg[2] = flash_get_bank_size(reg[0],
650+
idx);
619651
fdt_setprop(blob, off, "reg", reg,
620-
3 * sizeof(u32));
621-
622-
return 0;
652+
tuple_size);
653+
reg += tuple_size;
623654
}
624655
}
625656

@@ -629,7 +660,7 @@ int fdt_fixup_nor_flash_size(void *blob, int cs, u32 size)
629660
}
630661
}
631662

632-
return -1;
663+
return 0;
633664
}
634665
#endif
635666

include/configs/acadia.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,13 @@
120120
#define CONFIG_SYS_FLASH_EMPTY_INFO /* print 'E' for empty sector on flinfo */
121121

122122
#else
123-
#define CONFIG_SYS_NO_FLASH 1 /* No NOR on Acadia when NAND-booting */
123+
/*
124+
* No NOR-flash on Acadia when NAND-booting. We need to undef the
125+
* NOR device-tree fixup code as well, since flash_info is not defined
126+
* in this case.
127+
*/
128+
#define CONFIG_SYS_NO_FLASH 1
129+
#undef CONFIG_FDT_FIXUP_NOR_FLASH_SIZE
124130
#endif
125131

126132
#ifdef CONFIG_ENV_IS_IN_FLASH

include/fdt_support.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void ft_pci_setup(void *blob, bd_t *bd);
7979
void set_working_fdt_addr(void *addr);
8080
int fdt_resize(void *blob);
8181

82-
int fdt_fixup_nor_flash_size(void *blob, int cs, u32 size);
82+
int fdt_fixup_nor_flash_size(void *blob);
8383

8484
void fdt_fixup_mtdparts(void *fdt, void *node_info, int node_info_size);
8585
void fdt_del_node_and_alias(void *blob, const char *alias);

0 commit comments

Comments
 (0)