2008-01-16 07:13:58 +00:00
|
|
|
/*
|
2010-03-31 04:06:53 +00:00
|
|
|
* Copyright 2008-2010 Freescale Semiconductor, Inc.
|
2008-01-16 07:13:58 +00:00
|
|
|
*
|
|
|
|
* (C) Copyright 2000
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <asm/fsl_law.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
|
2008-06-11 05:44:10 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
/* number of LAWs in the hw implementation */
|
|
|
|
#if defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \
|
|
|
|
defined(CONFIG_MPC8560) || defined(CONFIG_MPC8555)
|
|
|
|
#define FSL_HW_NUM_LAWS 8
|
|
|
|
#elif defined(CONFIG_MPC8548) || defined(CONFIG_MPC8544) || \
|
2009-03-27 21:02:44 +00:00
|
|
|
defined(CONFIG_MPC8568) || defined(CONFIG_MPC8569) || \
|
2008-06-11 05:44:10 +00:00
|
|
|
defined(CONFIG_MPC8641) || defined(CONFIG_MPC8610)
|
|
|
|
#define FSL_HW_NUM_LAWS 10
|
2009-01-21 23:17:33 +00:00
|
|
|
#elif defined(CONFIG_MPC8536) || defined(CONFIG_MPC8572) || \
|
2009-08-20 13:27:45 +00:00
|
|
|
defined(CONFIG_P1011) || defined(CONFIG_P1020) || \
|
2010-03-31 04:06:53 +00:00
|
|
|
defined(CONFIG_P1012) || defined(CONFIG_P1021) || \
|
|
|
|
defined(CONFIG_P1013) || defined(CONFIG_P1022) || \
|
2009-08-20 13:27:45 +00:00
|
|
|
defined(CONFIG_P2010) || defined(CONFIG_P2020)
|
2008-06-11 05:44:10 +00:00
|
|
|
#define FSL_HW_NUM_LAWS 12
|
2010-01-27 16:26:46 +00:00
|
|
|
#elif defined(CONFIG_PPC_P3041) || defined(CONFIG_PPC_P4080) || \
|
|
|
|
defined(CONFIG_PPC_P5020)
|
2009-03-19 07:39:17 +00:00
|
|
|
#define FSL_HW_NUM_LAWS 32
|
2008-06-11 05:44:10 +00:00
|
|
|
#else
|
|
|
|
#error FSL_HW_NUM_LAWS not defined for this platform
|
|
|
|
#endif
|
2008-01-16 07:13:58 +00:00
|
|
|
|
2009-03-19 07:32:23 +00:00
|
|
|
#ifdef CONFIG_FSL_CORENET
|
2010-06-17 16:37:23 +00:00
|
|
|
#define LAW_BASE (CONFIG_SYS_FSL_CORENET_CCM_ADDR)
|
|
|
|
#define LAWAR_ADDR(x) (&((ccsr_local_t *)LAW_BASE)->law[x].lawar)
|
|
|
|
#define LAWBARH_ADDR(x) (&((ccsr_local_t *)LAW_BASE)->law[x].lawbarh)
|
|
|
|
#define LAWBARL_ADDR(x) (&((ccsr_local_t *)LAW_BASE)->law[x].lawbarl)
|
|
|
|
#define LAWBAR_SHIFT 0
|
|
|
|
#else
|
|
|
|
#define LAW_BASE (CONFIG_SYS_IMMR + 0xc08)
|
|
|
|
#define LAWAR_ADDR(x) ((u32 *)LAW_BASE + 8 * x + 2)
|
|
|
|
#define LAWBAR_ADDR(x) ((u32 *)LAW_BASE + 8 * x)
|
|
|
|
#define LAWBAR_SHIFT 12
|
|
|
|
#endif
|
2009-03-19 07:32:23 +00:00
|
|
|
|
|
|
|
|
2010-06-17 16:37:23 +00:00
|
|
|
static inline phys_addr_t get_law_base_addr(int idx)
|
2009-03-19 07:32:23 +00:00
|
|
|
{
|
2010-06-17 16:37:23 +00:00
|
|
|
#ifdef CONFIG_FSL_CORENET
|
|
|
|
return (phys_addr_t)
|
|
|
|
((u64)in_be32(LAWBARH_ADDR(idx)) << 32) |
|
|
|
|
in_be32(LAWBARL_ADDR(idx));
|
|
|
|
#else
|
|
|
|
return (phys_addr_t)in_be32(LAWBAR_ADDR(idx)) << LAWBAR_SHIFT;
|
|
|
|
#endif
|
2009-03-19 07:32:23 +00:00
|
|
|
}
|
|
|
|
|
2010-06-17 16:37:23 +00:00
|
|
|
static inline void set_law_base_addr(int idx, phys_addr_t addr)
|
2009-03-19 07:32:23 +00:00
|
|
|
{
|
2010-06-17 16:37:23 +00:00
|
|
|
#ifdef CONFIG_FSL_CORENET
|
|
|
|
out_be32(LAWBARL_ADDR(idx), addr & 0xffffffff);
|
|
|
|
out_be32(LAWBARH_ADDR(idx), (u64)addr >> 32);
|
2009-03-19 07:32:23 +00:00
|
|
|
#else
|
2010-06-17 16:37:23 +00:00
|
|
|
out_be32(LAWBAR_ADDR(idx), addr >> LAWBAR_SHIFT);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-01-16 07:13:58 +00:00
|
|
|
void set_law(u8 idx, phys_addr_t addr, enum law_size sz, enum law_trgt_if id)
|
|
|
|
{
|
2008-06-11 05:44:10 +00:00
|
|
|
gd->used_laws |= (1 << idx);
|
|
|
|
|
2010-06-17 16:37:23 +00:00
|
|
|
out_be32(LAWAR_ADDR(idx), 0);
|
|
|
|
set_law_base_addr(idx, addr);
|
|
|
|
out_be32(LAWAR_ADDR(idx), LAW_EN | ((u32)id << 20) | (u32)sz);
|
2008-01-16 07:13:58 +00:00
|
|
|
|
2009-09-04 22:05:24 +00:00
|
|
|
/* Read back so that we sync the writes */
|
2010-06-17 16:37:23 +00:00
|
|
|
in_be32(LAWAR_ADDR(idx));
|
2008-01-16 07:13:58 +00:00
|
|
|
}
|
|
|
|
|
2009-03-19 07:32:23 +00:00
|
|
|
void disable_law(u8 idx)
|
|
|
|
{
|
|
|
|
gd->used_laws &= ~(1 << idx);
|
|
|
|
|
2010-06-17 16:37:23 +00:00
|
|
|
out_be32(LAWAR_ADDR(idx), 0);
|
|
|
|
set_law_base_addr(idx, 0);
|
2009-03-19 07:32:23 +00:00
|
|
|
|
|
|
|
/* Read back so that we sync the writes */
|
2010-06-17 16:37:23 +00:00
|
|
|
in_be32(LAWAR_ADDR(idx));
|
2009-03-19 07:32:23 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-30 13:39:44 +00:00
|
|
|
#ifndef CONFIG_NAND_SPL
|
2009-03-19 07:32:23 +00:00
|
|
|
static int get_law_entry(u8 i, struct law_entry *e)
|
|
|
|
{
|
2010-06-17 16:37:23 +00:00
|
|
|
u32 lawar;
|
2009-03-19 07:32:23 +00:00
|
|
|
|
2010-06-17 16:37:23 +00:00
|
|
|
lawar = in_be32(LAWAR_ADDR(i));
|
2009-03-19 07:32:23 +00:00
|
|
|
|
2010-06-17 16:37:23 +00:00
|
|
|
if (!(lawar & LAW_EN))
|
2009-03-19 07:32:23 +00:00
|
|
|
return 0;
|
|
|
|
|
2010-06-17 16:37:23 +00:00
|
|
|
e->addr = get_law_base_addr(i);
|
|
|
|
e->size = lawar & 0x3f;
|
|
|
|
e->trgt_id = (lawar >> 20) & 0xff;
|
2009-03-19 07:32:23 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-06-11 05:44:10 +00:00
|
|
|
int set_next_law(phys_addr_t addr, enum law_size sz, enum law_trgt_if id)
|
|
|
|
{
|
|
|
|
u32 idx = ffz(gd->used_laws);
|
|
|
|
|
|
|
|
if (idx >= FSL_HW_NUM_LAWS)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
set_law(idx, addr, sz, id);
|
2008-06-10 21:16:02 +00:00
|
|
|
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
ppc/85xx: add boot from NAND/eSDHC/eSPI support
The MPC8536E is capable of booting form NAND/eSDHC/eSPI, this patch
implements these three bootup methods in a unified way - all of these
use the general cpu/mpc85xx/start.S, and load the main image to L2SRAM
which lets us use the SPD to initialize the SDRAM.
For all three bootup methods, the bootup process can be divided into two
stages: the first stage will initialize the corresponding controller,
configure the L2SRAM, then copy the second stage image to L2SRAM and
jump to it. The second stage image is just like the general U-Boot image
to configure all the hardware and boot up to U-Boot command line.
When boot from NAND, the eLBC controller will first load the first stage
image to internal 4K RAM buffer because it's also stored on the NAND
flash. The first stage image, also call 4K NAND loader, will initialize
the L2SRAM, load the second stage image to L2SRAM and jump to it. The 4K
NAND loader's code comes from the corresponding nand_spl directory, along
with the code twisted by CONFIG_NAND_SPL.
When boot from eSDHC/eSPI, there's no such a first stage image because
the CPU ROM code does the same work. It will initialize the L2SRAM
according to the config addr/word pairs on the fixed address and
initialize the eSDHC/eSPI controller, then load the second stage image
to L2SRAM and jump to it.
The macro CONFIG_SYS_RAMBOOT is used to control the code to produce the
second stage image for all different bootup methods. It's set in the
board config file when one of the bootup methods above is selected.
Signed-off-by: Mingkai Hu <Mingkai.hu@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2009-09-11 06:19:10 +00:00
|
|
|
#ifndef CONFIG_NAND_SPL
|
2008-06-10 21:16:02 +00:00
|
|
|
int set_last_law(phys_addr_t addr, enum law_size sz, enum law_trgt_if id)
|
|
|
|
{
|
|
|
|
u32 idx;
|
|
|
|
|
|
|
|
/* we have no LAWs free */
|
|
|
|
if (gd->used_laws == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* grab the last free law */
|
|
|
|
idx = __ilog2(~(gd->used_laws));
|
|
|
|
|
|
|
|
if (idx >= FSL_HW_NUM_LAWS)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
set_law(idx, addr, sz, id);
|
2008-06-11 05:44:10 +00:00
|
|
|
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
2009-03-19 07:32:23 +00:00
|
|
|
struct law_entry find_law(phys_addr_t addr)
|
2008-01-16 07:13:58 +00:00
|
|
|
{
|
2009-03-19 07:32:23 +00:00
|
|
|
struct law_entry entry;
|
|
|
|
int i;
|
2008-01-16 07:13:58 +00:00
|
|
|
|
2009-03-19 07:32:23 +00:00
|
|
|
entry.index = -1;
|
|
|
|
entry.addr = 0;
|
|
|
|
entry.size = 0;
|
|
|
|
entry.trgt_id = 0;
|
2008-06-11 05:44:10 +00:00
|
|
|
|
2009-03-19 07:32:23 +00:00
|
|
|
for (i = 0; i < FSL_HW_NUM_LAWS; i++) {
|
|
|
|
u64 upper;
|
2008-01-16 07:13:58 +00:00
|
|
|
|
2009-03-19 07:32:23 +00:00
|
|
|
if (!get_law_entry(i, &entry))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
upper = entry.addr + (2ull << entry.size);
|
|
|
|
if ((addr >= entry.addr) && (addr < upper)) {
|
|
|
|
entry.index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return entry;
|
2008-01-16 07:13:58 +00:00
|
|
|
}
|
|
|
|
|
2008-01-23 22:31:05 +00:00
|
|
|
void print_laws(void)
|
|
|
|
{
|
|
|
|
int i;
|
2010-06-17 16:37:23 +00:00
|
|
|
u32 lawar;
|
2008-01-23 22:31:05 +00:00
|
|
|
|
|
|
|
printf("\nLocal Access Window Configuration\n");
|
2010-06-17 16:37:23 +00:00
|
|
|
for (i = 0; i < FSL_HW_NUM_LAWS; i++) {
|
|
|
|
lawar = in_be32(LAWAR_ADDR(i));
|
2010-06-17 16:37:24 +00:00
|
|
|
#ifdef CONFIG_FSL_CORENET
|
|
|
|
printf("LAWBARH%02d: 0x%08x LAWBARL%02d: 0x%08x",
|
|
|
|
i, in_be32(LAWBARH_ADDR(i)),
|
|
|
|
i, in_be32(LAWBARL_ADDR(i)));
|
|
|
|
#else
|
2010-06-17 16:37:23 +00:00
|
|
|
printf("LAWBAR%02d: 0x%08x", i, in_be32(LAWBAR_ADDR(i)));
|
2010-06-17 16:37:24 +00:00
|
|
|
#endif
|
2010-06-17 16:37:23 +00:00
|
|
|
printf(" LAWAR0x%02d: 0x%08x\n", i, lawar);
|
|
|
|
printf("\t(EN: %d TGT: 0x%02x SIZE: ",
|
|
|
|
(lawar & LAW_EN) ? 1 : 0, (lawar >> 20) & 0xff);
|
|
|
|
print_size(lawar_size(lawar), ")\n");
|
2008-01-23 22:31:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-08-26 20:01:28 +00:00
|
|
|
/* use up to 2 LAWs for DDR, used the last available LAWs */
|
|
|
|
int set_ddr_laws(u64 start, u64 sz, enum law_trgt_if id)
|
|
|
|
{
|
|
|
|
u64 start_align, law_sz;
|
|
|
|
int law_sz_enc;
|
|
|
|
|
|
|
|
if (start == 0)
|
|
|
|
start_align = 1ull << (LAW_SIZE_32G + 1);
|
|
|
|
else
|
|
|
|
start_align = 1ull << (ffs64(start) - 1);
|
|
|
|
law_sz = min(start_align, sz);
|
|
|
|
law_sz_enc = __ilog2_u64(law_sz) - 1;
|
|
|
|
|
|
|
|
if (set_last_law(start, law_sz_enc, id) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2009-04-04 15:21:02 +00:00
|
|
|
/* recalculate size based on what was actually covered by the law */
|
|
|
|
law_sz = 1ull << __ilog2_u64(law_sz);
|
|
|
|
|
2008-08-26 20:01:28 +00:00
|
|
|
/* do we still have anything to map */
|
|
|
|
sz = sz - law_sz;
|
|
|
|
if (sz) {
|
|
|
|
start += law_sz;
|
|
|
|
|
|
|
|
start_align = 1ull << (ffs64(start) - 1);
|
|
|
|
law_sz = min(start_align, sz);
|
|
|
|
law_sz_enc = __ilog2_u64(law_sz) - 1;
|
|
|
|
|
|
|
|
if (set_last_law(start, law_sz_enc, id) < 0)
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do we still have anything to map */
|
|
|
|
sz = sz - law_sz;
|
|
|
|
if (sz)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
ppc/85xx: add boot from NAND/eSDHC/eSPI support
The MPC8536E is capable of booting form NAND/eSDHC/eSPI, this patch
implements these three bootup methods in a unified way - all of these
use the general cpu/mpc85xx/start.S, and load the main image to L2SRAM
which lets us use the SPD to initialize the SDRAM.
For all three bootup methods, the bootup process can be divided into two
stages: the first stage will initialize the corresponding controller,
configure the L2SRAM, then copy the second stage image to L2SRAM and
jump to it. The second stage image is just like the general U-Boot image
to configure all the hardware and boot up to U-Boot command line.
When boot from NAND, the eLBC controller will first load the first stage
image to internal 4K RAM buffer because it's also stored on the NAND
flash. The first stage image, also call 4K NAND loader, will initialize
the L2SRAM, load the second stage image to L2SRAM and jump to it. The 4K
NAND loader's code comes from the corresponding nand_spl directory, along
with the code twisted by CONFIG_NAND_SPL.
When boot from eSDHC/eSPI, there's no such a first stage image because
the CPU ROM code does the same work. It will initialize the L2SRAM
according to the config addr/word pairs on the fixed address and
initialize the eSDHC/eSPI controller, then load the second stage image
to L2SRAM and jump to it.
The macro CONFIG_SYS_RAMBOOT is used to control the code to produce the
second stage image for all different bootup methods. It's set in the
board config file when one of the bootup methods above is selected.
Signed-off-by: Mingkai Hu <Mingkai.hu@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2009-09-11 06:19:10 +00:00
|
|
|
#endif
|
2008-08-26 20:01:28 +00:00
|
|
|
|
2008-01-16 07:13:58 +00:00
|
|
|
void init_laws(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2009-03-19 07:32:23 +00:00
|
|
|
#if FSL_HW_NUM_LAWS < 32
|
2008-06-11 05:44:10 +00:00
|
|
|
gd->used_laws = ~((1 << FSL_HW_NUM_LAWS) - 1);
|
2009-03-19 07:32:23 +00:00
|
|
|
#elif FSL_HW_NUM_LAWS == 32
|
|
|
|
gd->used_laws = 0;
|
|
|
|
#else
|
|
|
|
#error FSL_HW_NUM_LAWS can not be greater than 32 w/o code changes
|
|
|
|
#endif
|
2008-01-16 07:13:58 +00:00
|
|
|
|
2008-06-11 05:44:10 +00:00
|
|
|
for (i = 0; i < num_law_entries; i++) {
|
|
|
|
if (law_table[i].index == -1)
|
|
|
|
set_next_law(law_table[i].addr, law_table[i].size,
|
|
|
|
law_table[i].trgt_id);
|
|
|
|
else
|
|
|
|
set_law(law_table[i].index, law_table[i].addr,
|
|
|
|
law_table[i].size, law_table[i].trgt_id);
|
2008-01-16 07:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ;
|
|
|
|
}
|