blob: 13b9d51dd181be9e3250384bc15a38be8517f916 [file] [log] [blame]
Magnus Lilja6eeb6f72009-07-01 01:07:55 +02001/*
2 *
3 * (C) Copyright 2009 Magnus Lilja <lilja.magnus@gmail.com>
4 *
5 * (c) 2007 Pengutronix, Sascha Hauer <s.hauer@pengutronix.de>
6 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Magnus Lilja6eeb6f72009-07-01 01:07:55 +02008 */
9
10
11#include <common.h>
Ben Warrenfbfdd3a2009-07-20 22:01:11 -070012#include <netdev.h>
Stefano Babic78129d92011-03-14 15:43:56 +010013#include <asm/arch/clock.h>
14#include <asm/arch/imx-regs.h>
Helmut Raiger035929c2011-09-29 05:45:03 +000015#include <asm/arch/sys_proto.h>
Fabio Estevam5e4f3802011-04-10 08:17:50 +000016#include <watchdog.h>
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000017#include <power/pmic.h>
Fabio Estevam578bac02011-10-24 05:32:28 +000018#include <fsl_pmic.h>
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000019#include <errno.h>
Magnus Lilja6eeb6f72009-07-01 01:07:55 +020020
21DECLARE_GLOBAL_DATA_PTR;
22
Benoît Thébaudeauefb7c002013-04-11 09:35:51 +000023#ifdef CONFIG_SPL_BUILD
24void board_init_f(ulong bootflag)
25{
Albert ARIBAUDfb9445a2013-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ébaudeauefb7c002013-04-11 09:35:51 +000041 asm volatile("ldr pc, =nand_boot");
42}
43#endif
44
Magnus Lilja6eeb6f72009-07-01 01:07:55 +020045int dram_init(void)
46{
Fabio Estevam66a8b4d2011-02-09 01:17:55 +000047 /* dram_init must store complete ramsize in gd->ram_size */
Albert ARIBAUDa9606732011-07-03 05:55:33 +000048 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
Fabio Estevam66a8b4d2011-02-09 01:17:55 +000049 PHYS_SDRAM_1_SIZE);
50 return 0;
51}
52
Fabio Estevam1af83e32011-02-09 01:17:56 +000053int board_early_init_f(void)
Magnus Lilja6eeb6f72009-07-01 01:07:55 +020054{
55 /* CS5: CPLD incl. network controller */
Helmut Raiger035929c2011-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 Lilja6eeb6f72009-07-01 01:07:55 +020066
67 /* Setup UART1 and SPI2 pins */
68 mx31_uart1_hw_init();
69 mx31_spi2_hw_init();
70
Fabio Estevam1af83e32011-02-09 01:17:56 +000071 return 0;
72}
73
74int board_init(void)
75{
Magnus Lilja6eeb6f72009-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 Estevam5e4f3802011-04-10 08:17:50 +000082int board_late_init(void)
83{
Fabio Estevam578bac02011-10-24 05:32:28 +000084 u32 val;
85 struct pmic *p;
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000086 int ret;
Fabio Estevam578bac02011-10-24 05:32:28 +000087
Fabio Estevam3b48b4f2013-11-20 20:26:04 -020088 ret = pmic_init(CONFIG_FSL_PMIC_BUS);
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000089 if (ret)
90 return ret;
Fabio Estevam578bac02011-10-24 05:32:28 +000091
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000092 p = pmic_get("FSL_PMIC");
93 if (!p)
94 return -ENODEV;
Fabio Estevam578bac02011-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 Estevam5e4f3802011-04-10 08:17:50 +000099#ifdef CONFIG_HW_WATCHDOG
Troy Kisky4b7c6022012-10-22 15:19:01 +0000100 hw_watchdog_init();
Fabio Estevam5e4f3802011-04-10 08:17:50 +0000101#endif
102 return 0;
103}
104
Magnus Lilja6eeb6f72009-07-01 01:07:55 +0200105int checkboard(void)
106{
Fabio Estevam7450e2a2011-04-18 07:38:12 +0000107 printf("Board: MX31PDK\n");
Magnus Lilja6eeb6f72009-07-01 01:07:55 +0200108 return 0;
109}
Ben Warrenfbfdd3a2009-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}