3 * Marvell Semiconductor <www.marvell.com>
4 * Prafulla Wadaskar <prafulla@marvell.com>
7 * Stefan Roese, DENX Software Engineering, sr@denx.de.
10 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
12 * See file CREDITS for list of people who contributed to this
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
37 #include <asm/arch/kirkwood.h>
38 #include <asm/arch/mpp.h>
40 #include "../common/common.h"
42 DECLARE_GLOBAL_DATA_PTR;
44 /* Multi-Purpose Pins Functionality configuration */
45 u32 kwmpp_config[] = {
54 #if defined(CONFIG_SOFT_I2C)
58 #if defined(CONFIG_HARD_I2C)
64 MPP12_GPO, /* Reserved */
67 MPP15_GPIO, /* Not used */
68 MPP16_GPIO, /* Not used */
69 MPP17_GPIO, /* Reserved */
86 MPP34_GPIO, /* CDL1 (input) */
87 MPP35_GPIO, /* CDL2 (input) */
88 MPP36_GPIO, /* MAIN_IRQ (input) */
89 MPP37_GPIO, /* BOARD_LED */
90 MPP38_GPIO, /* Piggy3 LED[1] */
91 MPP39_GPIO, /* Piggy3 LED[2] */
92 MPP40_GPIO, /* Piggy3 LED[3] */
93 MPP41_GPIO, /* Piggy3 LED[4] */
94 MPP42_GPIO, /* Piggy3 LED[5] */
95 MPP43_GPIO, /* Piggy3 LED[6] */
96 MPP44_GPIO, /* Piggy3 LED[7], BIST_EN_L */
97 MPP45_GPIO, /* Piggy3 LED[8] */
98 MPP46_GPIO, /* Reserved */
99 MPP47_GPIO, /* Reserved */
100 MPP48_GPIO, /* Reserved */
101 MPP49_GPIO, /* SW_INTOUTn */
105 int ethernet_present(void)
110 if (i2c_read(0x10, 2, 1, &buf, 1) != 0) {
111 printf("%s: Error reading Boco\n", __func__);
114 if ((buf & 0x40) == 0x40)
120 int initialize_unit_leds(void)
124 * per default they all are
125 * ok apart from bootstat
126 * LED connected through BOCO
127 * BOCO lies at the address 0x10
128 * LEDs are in the block CTRL_H (addr 0x02)
129 * BOOTSTAT LED is the first 0x01
133 #define APPLEDMASK 0x01
136 if (i2c_read(BOCO, CTRL_H, 1, &buf, 1) != 0) {
137 printf("%s: Error reading Boco\n", __func__);
141 if (i2c_write(BOCO, CTRL_H, 1, &buf, 1) != 0) {
142 printf("%s: Error writing Boco\n", __func__);
148 int misc_init_r(void)
154 if (ethernet_present() == 0)
158 str = getenv("mach_type");
160 mach_type = simple_strtoul(str, NULL, 10);
161 printf("Overwriting MACH_TYPE with %d!!!\n", mach_type);
162 gd->bd->bi_arch_number = mach_type;
165 initialize_unit_leds();
170 int board_early_init_f(void)
174 kirkwood_mpp_conf(kwmpp_config);
177 * The FLASH_GPIO_PIN switches between using a
178 * NAND or a SPI FLASH. Set this pin on start
181 tmp = readl(KW_GPIO0_BASE);
182 writel(tmp | FLASH_GPIO_PIN , KW_GPIO0_BASE);
183 tmp = readl(KW_GPIO0_BASE + 4);
184 writel(tmp & (~FLASH_GPIO_PIN) , KW_GPIO0_BASE + 4);
185 printf("KM: setting NAND mode\n");
187 #if defined(CONFIG_SOFT_I2C)
188 /* init the GPIO for I2C Bitbang driver */
189 kw_gpio_set_valid(KM_KIRKWOOD_SDA_PIN, 1);
190 kw_gpio_set_valid(KM_KIRKWOOD_SCL_PIN, 1);
191 kw_gpio_direction_output(KM_KIRKWOOD_SDA_PIN, 0);
192 kw_gpio_direction_output(KM_KIRKWOOD_SCL_PIN, 0);
194 #if defined(CONFIG_SYS_EEPROM_WREN)
195 kw_gpio_set_valid(KM_KIRKWOOD_ENV_WP, 38);
196 kw_gpio_direction_output(KM_KIRKWOOD_ENV_WP, 1);
205 * arch number of board
207 gd->bd->bi_arch_number = MACH_TYPE_KM_KIRKWOOD;
209 /* address of boot parameters */
210 gd->bd->bi_boot_params = kw_sdram_bar(0) + 0x100;
215 int last_stage_init(void)
221 #if defined(CONFIG_CMD_SF)
222 int do_spi_toggle(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
226 return cmd_usage(cmdtp);
228 if ((strcmp(argv[1], "off") == 0)) {
229 printf("SPI FLASH disabled, NAND enabled\n");
230 /* Multi-Purpose Pins Functionality configuration */
231 kwmpp_config[0] = MPP0_NF_IO2;
232 kwmpp_config[1] = MPP1_NF_IO3;
233 kwmpp_config[2] = MPP2_NF_IO4;
234 kwmpp_config[3] = MPP3_NF_IO5;
236 kirkwood_mpp_conf(kwmpp_config);
237 tmp = readl(KW_GPIO0_BASE);
238 writel(tmp | FLASH_GPIO_PIN , KW_GPIO0_BASE);
239 } else if ((strcmp(argv[1], "on") == 0)) {
240 printf("SPI FLASH enabled, NAND disabled\n");
241 /* Multi-Purpose Pins Functionality configuration */
242 kwmpp_config[0] = MPP0_SPI_SCn;
243 kwmpp_config[1] = MPP1_SPI_MOSI;
244 kwmpp_config[2] = MPP2_SPI_SCK;
245 kwmpp_config[3] = MPP3_SPI_MISO;
247 kirkwood_mpp_conf(kwmpp_config);
248 tmp = readl(KW_GPIO0_BASE);
249 writel(tmp & (~FLASH_GPIO_PIN) , KW_GPIO0_BASE);
251 return cmd_usage(cmdtp);
258 spitoggle, 2, 0, do_spi_toggle,
259 "En-/disable SPI FLASH access",
260 "<on|off> - Enable (on) or disable (off) SPI FLASH access\n"
266 /* dram_init must store complete ramsize in gd->ram_size */
268 gd->ram_size = get_ram_size((volatile void *)kw_sdram_bar(0),
273 void dram_init_banksize(void)
277 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
278 gd->bd->bi_dram[i].start = kw_sdram_bar(i);
279 gd->bd->bi_dram[i].size = get_ram_size((long *)kw_sdram_bar(i),
284 /* Configure and enable MV88E1118 PHY */
287 char *name = "egiga0";
289 if (miiphy_set_current_dev(name))
293 miiphy_reset(name, CONFIG_PHY_BASE_ADR);
296 #if defined(CONFIG_HUSH_INIT_VAR)
297 int hush_init_var(void)
304 #if defined(CONFIG_BOOTCOUNT_LIMIT)
305 void bootcount_store(ulong a)
307 volatile ulong *save_addr;
308 volatile ulong size = 0;
310 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
311 size += gd->bd->bi_dram[i].size;
313 save_addr = (ulong*)(size - BOOTCOUNT_ADDR);
314 writel(a, save_addr);
315 writel(BOOTCOUNT_MAGIC, &save_addr[1]);
318 ulong bootcount_load(void)
320 volatile ulong *save_addr;
321 volatile ulong size = 0;
323 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
324 size += gd->bd->bi_dram[i].size;
326 save_addr = (ulong*)(size - BOOTCOUNT_ADDR);
327 if (readl(&save_addr[1]) != BOOTCOUNT_MAGIC)
330 return readl(save_addr);
334 #if defined(CONFIG_SOFT_I2C)
335 void set_sda(int state)
341 void set_scl(int state)
354 return kw_gpio_get_value(KM_KIRKWOOD_SCL_PIN) ? 1 : 0;
358 #if defined(CONFIG_SYS_EEPROM_WREN)
359 int eeprom_write_enable(unsigned dev_addr, int state)
361 kw_gpio_set_value(KM_KIRKWOOD_ENV_WP, !state);
363 return !kw_gpio_get_value(KM_KIRKWOOD_ENV_WP);