blob: 43a3d47d2b038ebf42ce966bc4b699df54fb8930 [file] [log] [blame]
wdenk1cb8e982003-03-06 21:55:29 +00001/*
2 * (C) Copyright 2002
3 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4 * Marius Groeger <mgroeger@sysgo.de>
5 *
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +00006 * (C) Copyright 2002, 2010
wdenk1cb8e982003-03-06 21:55:29 +00007 * David Mueller, ELSOFT AG, <d.mueller@elsoft.ch>
8 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
wdenk1cb8e982003-03-06 21:55:29 +000010 */
11
12#include <common.h>
Ben Warrenb1c0eaa2009-08-25 13:09:37 -070013#include <netdev.h>
wdenk1cb8e982003-03-06 21:55:29 +000014#include <i2c.h>
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +000015#include <asm/io.h>
16#include <asm/arch/s3c24x0_cpu.h>
wdenk1cb8e982003-03-06 21:55:29 +000017
18#include "vcma9.h"
19#include "../common/common_util.h"
20
Wolfgang Denkd87080b2006-03-31 18:32:53 +020021DECLARE_GLOBAL_DATA_PTR;
wdenk1cb8e982003-03-06 21:55:29 +000022
wdenk1cb8e982003-03-06 21:55:29 +000023/*
24 * Miscellaneous platform dependent initialisations
25 */
26
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +000027int board_early_init_f(void)
wdenk1cb8e982003-03-06 21:55:29 +000028{
kevin.morfitt@fearnside-systems.co.ukeb0ae7f2009-10-10 13:33:11 +090029 struct s3c24x0_gpio * const gpio = s3c24x0_get_base_gpio();
wdenk1cb8e982003-03-06 21:55:29 +000030
wdenk1cb8e982003-03-06 21:55:29 +000031 /* set up the I/O ports */
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +000032 writel(0x007FFFFF, &gpio->gpacon);
33 writel(0x002AAAAA, &gpio->gpbcon);
34 writel(0x000002BF, &gpio->gpbup);
35 writel(0xAAAAAAAA, &gpio->gpccon);
36 writel(0x0000FFFF, &gpio->gpcup);
37 writel(0xAAAAAAAA, &gpio->gpdcon);
38 writel(0x0000FFFF, &gpio->gpdup);
39 writel(0xAAAAAAAA, &gpio->gpecon);
40 writel(0x000037F7, &gpio->gpeup);
41 writel(0x00000000, &gpio->gpfcon);
42 writel(0x00000000, &gpio->gpfup);
43 writel(0xFFEAFF5A, &gpio->gpgcon);
44 writel(0x0000F0DC, &gpio->gpgup);
45 writel(0x0028AAAA, &gpio->gphcon);
46 writel(0x00000656, &gpio->gphup);
wdenk1cb8e982003-03-06 21:55:29 +000047
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +000048 /* setup correct IRQ modes for NIC (rising edge mode) */
49 writel((readl(&gpio->extint2) & ~(7<<8)) | (4<<8), &gpio->extint2);
wdenk48b42612003-06-19 23:01:32 +000050
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +000051 /* select USB port 2 to be host or device (setup as host for now) */
52 writel(readl(&gpio->misccr) | 0x08, &gpio->misccr);
wdenk1cb8e982003-03-06 21:55:29 +000053
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +000054 return 0;
55}
wdenk1cb8e982003-03-06 21:55:29 +000056
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +000057int board_init(void)
58{
wdenk1cb8e982003-03-06 21:55:29 +000059 /* adress of boot parameters */
60 gd->bd->bi_boot_params = 0x30000100;
61
62 icache_enable();
63 dcache_enable();
64
65 return 0;
66}
67
wdenk1cb8e982003-03-06 21:55:29 +000068/*
69 * Get some Board/PLD Info
70 */
71
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +000072static u8 get_pld_reg(enum vcma9_pld_regs reg)
wdenk1cb8e982003-03-06 21:55:29 +000073{
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +000074 return readb(VCMA9_PLD_BASE + reg);
wdenk1cb8e982003-03-06 21:55:29 +000075}
76
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +000077static u8 get_pld_version(void)
wdenk1cb8e982003-03-06 21:55:29 +000078{
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +000079 return (get_pld_reg(VCMA9_PLD_ID) >> 4) & 0x0F;
wdenk1cb8e982003-03-06 21:55:29 +000080}
81
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +000082static u8 get_pld_revision(void)
wdenk531716e2003-09-13 19:01:12 +000083{
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +000084 return get_pld_reg(VCMA9_PLD_ID) & 0x0F;
wdenk531716e2003-09-13 19:01:12 +000085}
86
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +000087static uchar get_board_pcb(void)
wdenk1cb8e982003-03-06 21:55:29 +000088{
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +000089 return ((get_pld_reg(VCMA9_PLD_BOARD) >> 4) & 0x03) + 'A';
wdenk1cb8e982003-03-06 21:55:29 +000090}
91
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +000092static u8 get_nr_chips(void)
wdenk1cb8e982003-03-06 21:55:29 +000093{
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +000094 switch ((get_pld_reg(VCMA9_PLD_SDRAM) >> 4) & 0x0F) {
wdenk531716e2003-09-13 19:01:12 +000095 case 0: return 4;
96 case 1: return 1;
97 case 2: return 2;
98 default: return 0;
99 }
100}
101
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +0000102static ulong get_chip_size(void)
wdenk531716e2003-09-13 19:01:12 +0000103{
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +0000104 switch (get_pld_reg(VCMA9_PLD_SDRAM) & 0x0F) {
wdenk531716e2003-09-13 19:01:12 +0000105 case 0: return 16 * (1024*1024);
106 case 1: return 32 * (1024*1024);
107 case 2: return 8 * (1024*1024);
108 case 3: return 8 * (1024*1024);
109 default: return 0;
wdenk42d1f032003-10-15 23:53:47 +0000110 }
wdenk531716e2003-09-13 19:01:12 +0000111}
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +0000112
113static const char *get_chip_geom(void)
wdenk531716e2003-09-13 19:01:12 +0000114{
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +0000115 switch (get_pld_reg(VCMA9_PLD_SDRAM) & 0x0F) {
wdenk531716e2003-09-13 19:01:12 +0000116 case 0: return "4Mx8x4";
117 case 1: return "8Mx8x4";
118 case 2: return "2Mx8x4";
119 case 3: return "4Mx8x2";
120 default: return "unknown";
121 }
122}
123
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +0000124static void vcma9_show_info(char *board_name, char *serial)
wdenk531716e2003-09-13 19:01:12 +0000125{
126 printf("Board: %s SN: %s PCB Rev: %c PLD(%d,%d)\n",
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +0000127 board_name, serial,
128 get_board_pcb(), get_pld_version(), get_pld_revision());
129 printf("SDRAM: %d chips %s\n", get_nr_chips(), get_chip_geom());
wdenk531716e2003-09-13 19:01:12 +0000130}
131
132int dram_init(void)
133{
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +0000134 /* dram_init must store complete ramsize in gd->ram_size */
135 gd->ram_size = get_chip_size() * get_nr_chips();
wdenk531716e2003-09-13 19:01:12 +0000136 return 0;
137}
138
wdenk1cb8e982003-03-06 21:55:29 +0000139/*
140 * Check Board Identity:
141 */
142
143int checkboard(void)
144{
Wolfgang Denkfc19e362007-10-13 23:51:14 +0200145 char s[50];
wdenk1cb8e982003-03-06 21:55:29 +0000146 int i;
147 backup_t *b = (backup_t *) s;
148
Wolfgang Denkcdb74972010-07-24 21:55:43 +0200149 i = getenv_f("serial#", s, 32);
wdenk1cb8e982003-03-06 21:55:29 +0000150 if ((i < 0) || strncmp (s, "VCMA9", 5)) {
151 get_backup_values (b);
152 if (strncmp (b->signature, "MPL\0", 4) != 0) {
153 puts ("### No HW ID - assuming VCMA9");
154 } else {
155 b->serial_name[5] = 0;
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +0000156 vcma9_show_info(b->serial_name, &b->serial_name[6]);
wdenk1cb8e982003-03-06 21:55:29 +0000157 }
158 } else {
159 s[5] = 0;
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +0000160 vcma9_show_info(s, &s[6]);
wdenk1cb8e982003-03-06 21:55:29 +0000161 }
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +0000162
163 return 0;
wdenk1cb8e982003-03-06 21:55:29 +0000164}
165
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +0000166int board_late_init(void)
wdenk1cb8e982003-03-06 21:55:29 +0000167{
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +0000168 /*
169 * check if environment is healthy, otherwise restore values
170 * from shadow copy
171 */
wdenk1cb8e982003-03-06 21:55:29 +0000172 check_env();
173 return 0;
174}
175
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +0000176void vcma9_print_info(void)
wdenk1cb8e982003-03-06 21:55:29 +0000177{
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +0000178 char *s = getenv("serial#");
wdenk1cb8e982003-03-06 21:55:29 +0000179
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +0000180 if (!s) {
wdenk531716e2003-09-13 19:01:12 +0000181 puts ("### No HW ID - assuming VCMA9");
wdenk531716e2003-09-13 19:01:12 +0000182 } else {
183 s[5] = 0;
David Müller (ELSOFT AG)f3108302011-05-01 21:52:51 +0000184 vcma9_show_info(s, &s[6]);
wdenk531716e2003-09-13 19:01:12 +0000185 }
wdenk1cb8e982003-03-06 21:55:29 +0000186}
Ben Warrenb1c0eaa2009-08-25 13:09:37 -0700187
188#ifdef CONFIG_CMD_NET
189int board_eth_init(bd_t *bis)
190{
191 int rc = 0;
192#ifdef CONFIG_CS8900
193 rc = cs8900_initialize(0, CONFIG_CS8900_BASE);
194#endif
195 return rc;
196}
197#endif
David Müller (ELSOFT AG)6d754842011-05-01 21:52:50 +0000198
199/*
200 * Hardcoded flash setup:
201 * Flash 0 is a non-CFI AMD AM29F400BB flash.
202 */
203ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
204{
205 info->portwidth = FLASH_CFI_16BIT;
206 info->chipwidth = FLASH_CFI_BY16;
207 info->interface = FLASH_CFI_X16;
208 return 1;
209}