2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2002-10-27 22:25:25 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2002
|
|
|
|
* Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
|
|
|
* Marius Groeger <mgroeger@sysgo.de>
|
|
|
|
*
|
|
|
|
* (C) Copyright 2002
|
|
|
|
* Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
|
|
|
* Alex Zuepke <azu@sysgo.de>
|
|
|
|
*/
|
|
|
|
|
2015-08-16 02:16:26 +00:00
|
|
|
#include <common.h>
|
2019-11-14 19:57:37 +00:00
|
|
|
#include <cpu_func.h>
|
2020-05-10 17:40:02 +00:00
|
|
|
#include <init.h>
|
2019-11-14 19:57:42 +00:00
|
|
|
#include <irq_func.h>
|
2015-08-16 02:16:26 +00:00
|
|
|
#include <asm/arch/pxa-regs.h>
|
2020-05-10 17:39:56 +00:00
|
|
|
#include <asm/cache.h>
|
2010-09-09 07:50:39 +00:00
|
|
|
#include <asm/io.h>
|
2009-04-05 11:02:43 +00:00
|
|
|
#include <asm/system.h>
|
2010-09-09 07:50:39 +00:00
|
|
|
#include <command.h>
|
2002-10-27 22:25:25 +00:00
|
|
|
|
2011-11-26 06:32:24 +00:00
|
|
|
/* Flush I/D-cache */
|
|
|
|
static void cache_flush(void)
|
|
|
|
{
|
|
|
|
unsigned long i = 0;
|
|
|
|
|
|
|
|
asm ("mcr p15, 0, %0, c7, c5, 0" : : "r" (i));
|
|
|
|
}
|
2009-04-05 11:06:31 +00:00
|
|
|
|
2011-11-26 06:32:24 +00:00
|
|
|
int cleanup_before_linux(void)
|
2002-10-27 22:25:25 +00:00
|
|
|
{
|
|
|
|
/*
|
2011-11-26 06:32:24 +00:00
|
|
|
* This function is called just before we call Linux. It prepares
|
|
|
|
* the processor for Linux by just disabling everything that can
|
|
|
|
* disturb booting Linux.
|
2002-10-27 22:25:25 +00:00
|
|
|
*/
|
|
|
|
|
2011-11-26 06:32:24 +00:00
|
|
|
disable_interrupts();
|
2009-04-05 11:06:31 +00:00
|
|
|
icache_disable();
|
|
|
|
dcache_disable();
|
|
|
|
cache_flush();
|
2002-10-27 22:25:25 +00:00
|
|
|
|
2011-11-26 06:32:24 +00:00
|
|
|
return 0;
|
2003-06-15 22:40:42 +00:00
|
|
|
}
|
2010-09-28 13:44:10 +00:00
|
|
|
|
|
|
|
inline void writelrb(uint32_t val, uint32_t addr)
|
|
|
|
{
|
|
|
|
writel(val, addr);
|
2011-11-26 06:32:24 +00:00
|
|
|
asm volatile("" : : : "memory");
|
2010-09-28 13:44:10 +00:00
|
|
|
readl(addr);
|
2011-11-26 06:32:24 +00:00
|
|
|
asm volatile("" : : : "memory");
|
2010-09-28 13:44:10 +00:00
|
|
|
}
|
|
|
|
|
2011-11-26 10:18:57 +00:00
|
|
|
void pxa2xx_dram_init(void)
|
2010-09-28 13:44:10 +00:00
|
|
|
{
|
|
|
|
uint32_t tmp;
|
|
|
|
int i;
|
|
|
|
/*
|
|
|
|
* 1) Initialize Asynchronous static memory controller
|
|
|
|
*/
|
|
|
|
|
|
|
|
writelrb(CONFIG_SYS_MSC0_VAL, MSC0);
|
|
|
|
writelrb(CONFIG_SYS_MSC1_VAL, MSC1);
|
|
|
|
writelrb(CONFIG_SYS_MSC2_VAL, MSC2);
|
|
|
|
/*
|
|
|
|
* 2) Initialize Card Interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* MECR: Memory Expansion Card Register */
|
|
|
|
writelrb(CONFIG_SYS_MECR_VAL, MECR);
|
|
|
|
/* MCMEM0: Card Interface slot 0 timing */
|
|
|
|
writelrb(CONFIG_SYS_MCMEM0_VAL, MCMEM0);
|
|
|
|
/* MCMEM1: Card Interface slot 1 timing */
|
|
|
|
writelrb(CONFIG_SYS_MCMEM1_VAL, MCMEM1);
|
|
|
|
/* MCATT0: Card Interface Attribute Space Timing, slot 0 */
|
|
|
|
writelrb(CONFIG_SYS_MCATT0_VAL, MCATT0);
|
|
|
|
/* MCATT1: Card Interface Attribute Space Timing, slot 1 */
|
|
|
|
writelrb(CONFIG_SYS_MCATT1_VAL, MCATT1);
|
|
|
|
/* MCIO0: Card Interface I/O Space Timing, slot 0 */
|
|
|
|
writelrb(CONFIG_SYS_MCIO0_VAL, MCIO0);
|
|
|
|
/* MCIO1: Card Interface I/O Space Timing, slot 1 */
|
|
|
|
writelrb(CONFIG_SYS_MCIO1_VAL, MCIO1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 3) Configure Fly-By DMA register
|
|
|
|
*/
|
|
|
|
|
|
|
|
writelrb(CONFIG_SYS_FLYCNFG_VAL, FLYCNFG);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 4) Initialize Timing for Sync Memory (SDCLK0)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Before accessing MDREFR we need a valid DRI field, so we set
|
|
|
|
* this to power on defaults + DRI field.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Read current MDREFR config and zero out DRI */
|
|
|
|
tmp = readl(MDREFR) & ~0xfff;
|
|
|
|
/* Add user-specified DRI */
|
|
|
|
tmp |= CONFIG_SYS_MDREFR_VAL & 0xfff;
|
|
|
|
/* Configure important bits */
|
|
|
|
tmp |= MDREFR_K0RUN | MDREFR_SLFRSH;
|
|
|
|
tmp &= ~(MDREFR_APD | MDREFR_E1PIN);
|
|
|
|
|
|
|
|
/* Write MDREFR back */
|
|
|
|
writelrb(tmp, MDREFR);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 5) Initialize Synchronous Static Memory (Flash/Peripherals)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Initialize SXCNFG register. Assert the enable bits.
|
|
|
|
*
|
|
|
|
* Write SXMRS to cause an MRS command to all enabled banks of
|
|
|
|
* synchronous static memory. Note that SXLCR need not be written
|
|
|
|
* at this time.
|
|
|
|
*/
|
|
|
|
writelrb(CONFIG_SYS_SXCNFG_VAL, SXCNFG);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 6) Initialize SDRAM
|
|
|
|
*/
|
|
|
|
|
|
|
|
writelrb(CONFIG_SYS_MDREFR_VAL & ~MDREFR_SLFRSH, MDREFR);
|
|
|
|
writelrb(CONFIG_SYS_MDREFR_VAL | MDREFR_E1PIN, MDREFR);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 7) Write MDCNFG with MDCNFG:DEx deasserted (set to 0), to configure
|
|
|
|
* but not enable each SDRAM partition pair.
|
|
|
|
*/
|
|
|
|
|
|
|
|
writelrb(CONFIG_SYS_MDCNFG_VAL &
|
|
|
|
~(MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3), MDCNFG);
|
2019-11-14 19:57:28 +00:00
|
|
|
|
2010-09-28 13:44:10 +00:00
|
|
|
/* Wait for the clock to the SDRAMs to stabilize, 100..200 usec. */
|
2019-11-14 19:57:28 +00:00
|
|
|
writel(0, OSCR);
|
|
|
|
while (readl(OSCR) < 0x300)
|
|
|
|
asm volatile("" : : : "memory");
|
2010-09-28 13:44:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 8) Trigger a number (usually 8) refresh cycles by attempting
|
|
|
|
* non-burst read or write accesses to disabled SDRAM, as commonly
|
|
|
|
* specified in the power up sequence documented in SDRAM data
|
|
|
|
* sheets. The address(es) used for this purpose must not be
|
|
|
|
* cacheable.
|
|
|
|
*/
|
|
|
|
for (i = 9; i >= 0; i--) {
|
|
|
|
writel(i, 0xa0000000);
|
2011-11-26 06:32:24 +00:00
|
|
|
asm volatile("" : : : "memory");
|
2010-09-28 13:44:10 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* 9) Write MDCNFG with enable bits asserted (MDCNFG:DEx set to 1).
|
|
|
|
*/
|
|
|
|
|
|
|
|
tmp = CONFIG_SYS_MDCNFG_VAL &
|
|
|
|
(MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3);
|
|
|
|
tmp |= readl(MDCNFG);
|
|
|
|
writelrb(tmp, MDCNFG);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 10) Write MDMRS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
writelrb(CONFIG_SYS_MDMRS_VAL, MDMRS);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 11) Enable APD
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (CONFIG_SYS_MDREFR_VAL & MDREFR_APD) {
|
|
|
|
tmp = readl(MDREFR);
|
|
|
|
tmp |= MDREFR_APD;
|
|
|
|
writelrb(tmp, MDREFR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pxa_gpio_setup(void)
|
|
|
|
{
|
|
|
|
writel(CONFIG_SYS_GPSR0_VAL, GPSR0);
|
|
|
|
writel(CONFIG_SYS_GPSR1_VAL, GPSR1);
|
|
|
|
writel(CONFIG_SYS_GPSR2_VAL, GPSR2);
|
2011-11-26 06:32:24 +00:00
|
|
|
#if defined(CONFIG_CPU_PXA27X)
|
2010-09-28 13:44:10 +00:00
|
|
|
writel(CONFIG_SYS_GPSR3_VAL, GPSR3);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
writel(CONFIG_SYS_GPCR0_VAL, GPCR0);
|
|
|
|
writel(CONFIG_SYS_GPCR1_VAL, GPCR1);
|
|
|
|
writel(CONFIG_SYS_GPCR2_VAL, GPCR2);
|
2011-11-26 06:32:24 +00:00
|
|
|
#if defined(CONFIG_CPU_PXA27X)
|
2010-09-28 13:44:10 +00:00
|
|
|
writel(CONFIG_SYS_GPCR3_VAL, GPCR3);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
writel(CONFIG_SYS_GPDR0_VAL, GPDR0);
|
|
|
|
writel(CONFIG_SYS_GPDR1_VAL, GPDR1);
|
|
|
|
writel(CONFIG_SYS_GPDR2_VAL, GPDR2);
|
2011-11-26 06:32:24 +00:00
|
|
|
#if defined(CONFIG_CPU_PXA27X)
|
2010-09-28 13:44:10 +00:00
|
|
|
writel(CONFIG_SYS_GPDR3_VAL, GPDR3);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
writel(CONFIG_SYS_GAFR0_L_VAL, GAFR0_L);
|
|
|
|
writel(CONFIG_SYS_GAFR0_U_VAL, GAFR0_U);
|
|
|
|
writel(CONFIG_SYS_GAFR1_L_VAL, GAFR1_L);
|
|
|
|
writel(CONFIG_SYS_GAFR1_U_VAL, GAFR1_U);
|
|
|
|
writel(CONFIG_SYS_GAFR2_L_VAL, GAFR2_L);
|
|
|
|
writel(CONFIG_SYS_GAFR2_U_VAL, GAFR2_U);
|
2011-11-26 06:32:24 +00:00
|
|
|
#if defined(CONFIG_CPU_PXA27X)
|
2010-09-28 13:44:10 +00:00
|
|
|
writel(CONFIG_SYS_GAFR3_L_VAL, GAFR3_L);
|
|
|
|
writel(CONFIG_SYS_GAFR3_U_VAL, GAFR3_U);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
writel(CONFIG_SYS_PSSR_VAL, PSSR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pxa_interrupt_setup(void)
|
|
|
|
{
|
|
|
|
writel(0, ICLR);
|
|
|
|
writel(0, ICMR);
|
2011-11-26 06:32:24 +00:00
|
|
|
#if defined(CONFIG_CPU_PXA27X)
|
2010-09-28 13:44:10 +00:00
|
|
|
writel(0, ICLR2);
|
|
|
|
writel(0, ICMR2);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void pxa_clock_setup(void)
|
|
|
|
{
|
|
|
|
writel(CONFIG_SYS_CKEN, CKEN);
|
|
|
|
writel(CONFIG_SYS_CCCR, CCCR);
|
2013-05-21 19:49:41 +00:00
|
|
|
asm volatile("mcr p14, 0, %0, c6, c0, 0" : : "r"(0x0b));
|
2010-09-28 13:44:10 +00:00
|
|
|
|
|
|
|
/* enable the 32Khz oscillator for RTC and PowerManager */
|
|
|
|
writel(OSCC_OON, OSCC);
|
2011-11-26 06:32:24 +00:00
|
|
|
while (!(readl(OSCC) & OSCC_OOK))
|
|
|
|
asm volatile("" : : : "memory");
|
2010-09-28 13:44:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pxa_wakeup(void)
|
|
|
|
{
|
|
|
|
uint32_t rcsr;
|
|
|
|
|
|
|
|
rcsr = readl(RCSR);
|
|
|
|
writel(rcsr & (RCSR_GPR | RCSR_SMR | RCSR_WDR | RCSR_HWR), RCSR);
|
|
|
|
|
|
|
|
/* Wakeup */
|
|
|
|
if (rcsr & RCSR_SMR) {
|
|
|
|
writel(PSSR_PH, PSSR);
|
2011-11-26 10:18:57 +00:00
|
|
|
pxa2xx_dram_init();
|
2010-09-28 13:44:10 +00:00
|
|
|
icache_disable();
|
|
|
|
dcache_disable();
|
2011-11-26 06:32:24 +00:00
|
|
|
asm volatile("mov pc, %0" : : "r"(readl(PSPR)));
|
2010-09-28 13:44:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int arch_cpu_init(void)
|
|
|
|
{
|
|
|
|
pxa_gpio_setup();
|
|
|
|
pxa_wakeup();
|
|
|
|
pxa_interrupt_setup();
|
|
|
|
pxa_clock_setup();
|
|
|
|
return 0;
|
|
|
|
}
|
2011-04-13 18:18:31 +00:00
|
|
|
|
|
|
|
void i2c_clk_enable(void)
|
|
|
|
{
|
2011-11-26 06:32:24 +00:00
|
|
|
/* Set the global I2C clock on */
|
2011-04-13 18:18:31 +00:00
|
|
|
writel(readl(CKEN) | CKEN14_I2C, CKEN);
|
|
|
|
}
|
2011-10-31 13:12:39 +00:00
|
|
|
|
2020-12-15 15:47:52 +00:00
|
|
|
void __attribute__((weak)) reset_cpu(void) __attribute__((noreturn));
|
2011-10-31 13:12:39 +00:00
|
|
|
|
2020-12-15 15:47:52 +00:00
|
|
|
void reset_cpu(void)
|
2011-10-31 13:12:39 +00:00
|
|
|
{
|
|
|
|
uint32_t tmp;
|
|
|
|
|
|
|
|
setbits_le32(OWER, OWER_WME);
|
|
|
|
|
|
|
|
tmp = readl(OSCR);
|
|
|
|
tmp += 0x1000;
|
|
|
|
writel(tmp, OSMR3);
|
2013-12-17 01:03:40 +00:00
|
|
|
writel(MDREFR_SLFRSH, MDREFR);
|
2011-10-31 13:12:39 +00:00
|
|
|
|
|
|
|
for (;;)
|
|
|
|
;
|
|
|
|
}
|
2016-03-21 01:37:07 +00:00
|
|
|
|
|
|
|
void enable_caches(void)
|
|
|
|
{
|
2019-05-03 13:41:00 +00:00
|
|
|
#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
|
2016-03-21 01:37:07 +00:00
|
|
|
icache_enable();
|
|
|
|
#endif
|
2019-05-03 13:41:00 +00:00
|
|
|
#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
|
2016-03-21 01:37:07 +00:00
|
|
|
dcache_enable();
|
|
|
|
#endif
|
|
|
|
}
|