blob: fb57f2635730af3e209acea1bcfe40ad78c0e6e0 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Magnus Lilja8449f282009-07-01 01:07:55 +02002/*
3 *
4 * (C) Copyright 2009 Magnus Lilja <lilja.magnus@gmail.com>
5 *
6 * (c) 2007 Pengutronix, Sascha Hauer <s.hauer@pengutronix.de>
Magnus Lilja8449f282009-07-01 01:07:55 +02007 */
8
9
10#include <common.h>
Simon Glass52559322019-11-14 12:57:46 -070011#include <init.h>
Ben Warren736fead2009-07-20 22:01:11 -070012#include <netdev.h>
Stefano Babic86271112011-03-14 15:43:56 +010013#include <asm/arch/clock.h>
14#include <asm/arch/imx-regs.h>
Helmut Raiger47c54552011-09-29 05:45:03 +000015#include <asm/arch/sys_proto.h>
Fabio Estevamb73850f2011-04-10 08:17:50 +000016#include <watchdog.h>
Łukasz Majewskic7336812012-11-13 03:21:55 +000017#include <power/pmic.h>
Fabio Estevam1f83d002011-10-24 05:32:28 +000018#include <fsl_pmic.h>
Łukasz Majewskic7336812012-11-13 03:21:55 +000019#include <errno.h>
Magnus Lilja8449f282009-07-01 01:07:55 +020020
21DECLARE_GLOBAL_DATA_PTR;
22
Benoît Thébaudeauda962b72013-04-11 09:35:51 +000023#ifdef CONFIG_SPL_BUILD
24void board_init_f(ulong bootflag)
25{
Albert ARIBAUD3acb3242013-05-19 01:48:12 +000026 /*
27 * copy ourselves from where we are running to where we were
28 * linked at. Use ulong pointers as all addresses involved
29 * are 4-byte-aligned.
30 */
31 ulong *start_ptr, *end_ptr, *link_ptr, *run_ptr, *dst;
32 asm volatile ("ldr %0, =_start" : "=r"(start_ptr));
33 asm volatile ("ldr %0, =_end" : "=r"(end_ptr));
34 asm volatile ("ldr %0, =board_init_f" : "=r"(link_ptr));
35 asm volatile ("adr %0, board_init_f" : "=r"(run_ptr));
36 for (dst = start_ptr; dst < end_ptr; dst++)
37 *dst = *(dst+(run_ptr-link_ptr));
38 /*
39 * branch to nand_boot's link-time address.
40 */
Benoît Thébaudeauda962b72013-04-11 09:35:51 +000041 asm volatile("ldr pc, =nand_boot");
42}
43#endif
44
Magnus Lilja8449f282009-07-01 01:07:55 +020045int dram_init(void)
46{
Fabio Estevamed3df722011-02-09 01:17:55 +000047 /* dram_init must store complete ramsize in gd->ram_size */
Albert ARIBAUDa55d23c2011-07-03 05:55:33 +000048 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
Fabio Estevamed3df722011-02-09 01:17:55 +000049 PHYS_SDRAM_1_SIZE);
50 return 0;
51}
52
Fabio Estevam9b6442f2011-02-09 01:17:56 +000053int board_early_init_f(void)
Magnus Lilja8449f282009-07-01 01:07:55 +020054{
55 /* CS5: CPLD incl. network controller */
Helmut Raiger47c54552011-09-29 05:45:03 +000056 static const struct mxc_weimcs cs5 = {
57 /* sp wp bcd bcs psz pme sync dol cnc wsc ew wws edc */
58 CSCR_U(0, 0, 0, 0, 0, 0, 0, 0, 3, 24, 0, 4, 3),
59 /* oea oen ebwa ebwn csa ebc dsz csn psr cre wrap csen */
60 CSCR_L(2, 2, 2, 5, 2, 0, 5, 2, 0, 0, 0, 1),
61 /* ebra ebrn rwa rwn mum lah lbn lba dww dct wwu age cnc2 fce*/
62 CSCR_A(2, 2, 2, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0)
63 };
64
65 mxc_setup_weimcs(5, &cs5);
Magnus Lilja8449f282009-07-01 01:07:55 +020066
67 /* Setup UART1 and SPI2 pins */
68 mx31_uart1_hw_init();
69 mx31_spi2_hw_init();
70
Fabio Estevam9b6442f2011-02-09 01:17:56 +000071 return 0;
72}
73
74int board_init(void)
75{
Magnus Lilja8449f282009-07-01 01:07:55 +020076 /* adress of boot parameters */
77 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
78
79 return 0;
80}
81
Fabio Estevamb73850f2011-04-10 08:17:50 +000082int board_late_init(void)
83{
Fabio Estevam1f83d002011-10-24 05:32:28 +000084 u32 val;
85 struct pmic *p;
Łukasz Majewskic7336812012-11-13 03:21:55 +000086 int ret;
Fabio Estevam1f83d002011-10-24 05:32:28 +000087
Fabio Estevam4e785c62013-11-20 20:26:04 -020088 ret = pmic_init(CONFIG_FSL_PMIC_BUS);
Łukasz Majewskic7336812012-11-13 03:21:55 +000089 if (ret)
90 return ret;
Fabio Estevam1f83d002011-10-24 05:32:28 +000091
Łukasz Majewskic7336812012-11-13 03:21:55 +000092 p = pmic_get("FSL_PMIC");
93 if (!p)
94 return -ENODEV;
Fabio Estevam1f83d002011-10-24 05:32:28 +000095 /* Enable RTC battery */
96 pmic_reg_read(p, REG_POWER_CTL0, &val);
97 pmic_reg_write(p, REG_POWER_CTL0, val | COINCHEN);
98 pmic_reg_write(p, REG_INT_STATUS1, RTCRSTI);
Fabio Estevamb73850f2011-04-10 08:17:50 +000099#ifdef CONFIG_HW_WATCHDOG
Troy Kiskyabbab702012-10-22 15:19:01 +0000100 hw_watchdog_init();
Fabio Estevamb73850f2011-04-10 08:17:50 +0000101#endif
102 return 0;
103}
104
Magnus Lilja8449f282009-07-01 01:07:55 +0200105int checkboard(void)
106{
Fabio Estevame9e07902011-04-18 07:38:12 +0000107 printf("Board: MX31PDK\n");
Magnus Lilja8449f282009-07-01 01:07:55 +0200108 return 0;
109}
Ben Warren736fead2009-07-20 22:01:11 -0700110
111int board_eth_init(bd_t *bis)
112{
113 int rc = 0;
114#ifdef CONFIG_SMC911X
115 rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
116#endif
117 return rc;
118}