]>
git.ipfire.org Git - people/ms/u-boot.git/blob - board/keymile/km_arm/km_arm.c
5da856fabc4fd9e32eb90abe565315c52ee69287
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
;
45 * BOCO FPGA definitions
48 #define REG_CTRL_H 0x02
49 #define MASK_WRL_UNITRUN 0x01
50 #define MASK_RBX_PGY_PRESENT 0x40
51 #define REG_IRQ_CIRQ2 0x2d
52 #define MASK_RBI_DEFECT_16 0x01
54 /* Multi-Purpose Pins Functionality configuration */
55 u32 kwmpp_config
[] = {
64 #if defined(CONFIG_SOFT_I2C)
68 #if defined(CONFIG_HARD_I2C)
74 MPP12_GPO
, /* Reserved */
77 MPP15_GPIO
, /* Not used */
78 MPP16_GPIO
, /* Not used */
79 MPP17_GPIO
, /* Reserved */
96 MPP34_GPIO
, /* CDL1 (input) */
97 MPP35_GPIO
, /* CDL2 (input) */
98 MPP36_GPIO
, /* MAIN_IRQ (input) */
99 MPP37_GPIO
, /* BOARD_LED */
100 MPP38_GPIO
, /* Piggy3 LED[1] */
101 MPP39_GPIO
, /* Piggy3 LED[2] */
102 MPP40_GPIO
, /* Piggy3 LED[3] */
103 MPP41_GPIO
, /* Piggy3 LED[4] */
104 MPP42_GPIO
, /* Piggy3 LED[5] */
105 MPP43_GPIO
, /* Piggy3 LED[6] */
106 MPP44_GPIO
, /* Piggy3 LED[7], BIST_EN_L */
107 MPP45_GPIO
, /* Piggy3 LED[8] */
108 MPP46_GPIO
, /* Reserved */
109 MPP47_GPIO
, /* Reserved */
110 MPP48_GPIO
, /* Reserved */
111 MPP49_GPIO
, /* SW_INTOUTn */
115 #if defined(CONFIG_MGCOGE3UN)
117 * Wait for startup OK from mgcoge3ne
119 int startup_allowed(void)
124 * Read CIRQ16 bit (bit 0)
126 if (i2c_read(BOCO
, REG_IRQ_CIRQ2
, 1, &buf
, 1) != 0)
127 printf("%s: Error reading Boco\n", __func__
);
129 if ((buf
& MASK_RBI_DEFECT_16
) == MASK_RBI_DEFECT_16
)
135 #if (defined(CONFIG_MGCOGE3UN)|defined(CONFIG_PORTL2))
137 * These two boards have always ethernet present. Its connected to the mv
140 int ethernet_present(void)
145 int ethernet_present(void)
150 if (i2c_read(BOCO
, REG_CTRL_H
, 1, &buf
, 1) != 0) {
151 printf("%s: Error reading Boco\n", __func__
);
154 if ((buf
& MASK_RBX_PGY_PRESENT
) == MASK_RBX_PGY_PRESENT
)
161 int initialize_unit_leds(void)
164 * Init the unit LEDs per default they all are
165 * ok apart from bootstat
169 if (i2c_read(BOCO
, REG_CTRL_H
, 1, &buf
, 1) != 0) {
170 printf("%s: Error reading Boco\n", __func__
);
173 buf
|= MASK_WRL_UNITRUN
;
174 if (i2c_write(BOCO
, REG_CTRL_H
, 1, &buf
, 1) != 0) {
175 printf("%s: Error writing Boco\n", __func__
);
181 #if defined(CONFIG_BOOTCOUNT_LIMIT)
182 void set_bootcount_addr(void)
185 unsigned int bootcountaddr
;
186 bootcountaddr
= gd
->ram_size
- BOOTCOUNT_ADDR
;
187 sprintf((char *)buf
, "0x%x", bootcountaddr
);
188 setenv("bootcountaddr", (char *)buf
);
192 int misc_init_r(void)
197 str
= getenv("mach_type");
199 mach_type
= simple_strtoul(str
, NULL
, 10);
200 printf("Overwriting MACH_TYPE with %d!!!\n", mach_type
);
201 gd
->bd
->bi_arch_number
= mach_type
;
203 #if defined(CONFIG_MGCOGE3UN)
205 wait_for_ne
= getenv("waitforne");
206 if (wait_for_ne
!= NULL
) {
207 if (strcmp(wait_for_ne
, "true") == 0) {
210 while (startup_allowed() == 0) {
214 puts("wait\b\b\b\b");
225 initialize_unit_leds();
227 #if defined(CONFIG_BOOTCOUNT_LIMIT)
228 set_bootcount_addr();
233 int board_early_init_f(void)
237 kirkwood_mpp_conf(kwmpp_config
);
240 * The FLASH_GPIO_PIN switches between using a
241 * NAND or a SPI FLASH. Set this pin on start
244 tmp
= readl(KW_GPIO0_BASE
);
245 writel(tmp
| FLASH_GPIO_PIN
, KW_GPIO0_BASE
);
246 tmp
= readl(KW_GPIO0_BASE
+ 4);
247 writel(tmp
& (~FLASH_GPIO_PIN
) , KW_GPIO0_BASE
+ 4);
249 #if defined(CONFIG_SOFT_I2C)
250 /* init the GPIO for I2C Bitbang driver */
251 kw_gpio_set_valid(KM_KIRKWOOD_SDA_PIN
, 1);
252 kw_gpio_set_valid(KM_KIRKWOOD_SCL_PIN
, 1);
253 kw_gpio_direction_output(KM_KIRKWOOD_SDA_PIN
, 0);
254 kw_gpio_direction_output(KM_KIRKWOOD_SCL_PIN
, 0);
256 #if defined(CONFIG_SYS_EEPROM_WREN)
257 kw_gpio_set_valid(KM_KIRKWOOD_ENV_WP
, 38);
258 kw_gpio_direction_output(KM_KIRKWOOD_ENV_WP
, 1);
267 * arch number of board
269 gd
->bd
->bi_arch_number
= MACH_TYPE_KM_KIRKWOOD
;
271 /* address of boot parameters */
272 gd
->bd
->bi_boot_params
= kw_sdram_bar(0) + 0x100;
277 #if defined(CONFIG_CMD_SF)
278 int do_spi_toggle(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
282 return cmd_usage(cmdtp
);
284 if ((strcmp(argv
[1], "off") == 0)) {
285 printf("SPI FLASH disabled, NAND enabled\n");
286 /* Multi-Purpose Pins Functionality configuration */
287 kwmpp_config
[0] = MPP0_NF_IO2
;
288 kwmpp_config
[1] = MPP1_NF_IO3
;
289 kwmpp_config
[2] = MPP2_NF_IO4
;
290 kwmpp_config
[3] = MPP3_NF_IO5
;
292 kirkwood_mpp_conf(kwmpp_config
);
293 tmp
= readl(KW_GPIO0_BASE
);
294 writel(tmp
| FLASH_GPIO_PIN
, KW_GPIO0_BASE
);
295 } else if ((strcmp(argv
[1], "on") == 0)) {
296 printf("SPI FLASH enabled, NAND disabled\n");
297 /* Multi-Purpose Pins Functionality configuration */
298 kwmpp_config
[0] = MPP0_SPI_SCn
;
299 kwmpp_config
[1] = MPP1_SPI_MOSI
;
300 kwmpp_config
[2] = MPP2_SPI_SCK
;
301 kwmpp_config
[3] = MPP3_SPI_MISO
;
303 kirkwood_mpp_conf(kwmpp_config
);
304 tmp
= readl(KW_GPIO0_BASE
);
305 writel(tmp
& (~FLASH_GPIO_PIN
) , KW_GPIO0_BASE
);
307 return cmd_usage(cmdtp
);
314 spitoggle
, 2, 0, do_spi_toggle
,
315 "En-/disable SPI FLASH access",
316 "<on|off> - Enable (on) or disable (off) SPI FLASH access\n"
322 /* dram_init must store complete ramsize in gd->ram_size */
324 gd
->ram_size
= get_ram_size((volatile void *)kw_sdram_bar(0),
329 void dram_init_banksize(void)
333 for (i
= 0; i
< CONFIG_NR_DRAM_BANKS
; i
++) {
334 gd
->bd
->bi_dram
[i
].start
= kw_sdram_bar(i
);
335 gd
->bd
->bi_dram
[i
].size
= get_ram_size((long *)kw_sdram_bar(i
),
340 #if (defined(CONFIG_MGCOGE3UN)|defined(CONFIG_PORTL2))
342 #define PHY_LED_SEL 0x18
343 #define PHY_LED0_LINK (0x5)
344 #define PHY_LED1_ACT (0x8<<4)
345 #define PHY_LED2_INT (0xe<<8)
346 #define PHY_SPEC_CTRL 0x1c
347 #define PHY_RGMII_CLK_STABLE (0x1<<10)
348 #define PHY_CLSA (0x1<<1)
350 /* Configure and enable MV88E3018 PHY */
353 char *name
= "egiga0";
356 if (miiphy_set_current_dev(name
))
359 /* RGMII clk transition on data stable */
360 if (miiphy_read(name
, CONFIG_PHY_BASE_ADR
, PHY_SPEC_CTRL
, ®
) != 0)
361 printf("Error reading PHY spec ctrl reg\n");
362 if (miiphy_write(name
, CONFIG_PHY_BASE_ADR
, PHY_SPEC_CTRL
,
363 reg
| PHY_RGMII_CLK_STABLE
| PHY_CLSA
) != 0)
364 printf("Error writing PHY spec ctrl reg\n");
367 if (miiphy_write(name
, CONFIG_PHY_BASE_ADR
, PHY_LED_SEL
,
368 PHY_LED0_LINK
| PHY_LED1_ACT
| PHY_LED2_INT
) != 0)
369 printf("Error writing PHY LED reg\n");
372 miiphy_reset(name
, CONFIG_PHY_BASE_ADR
);
375 /* Configure and enable MV88E1118 PHY on the piggy*/
378 char *name
= "egiga0";
380 if (miiphy_set_current_dev(name
))
384 miiphy_reset(name
, CONFIG_PHY_BASE_ADR
);
389 #if defined(CONFIG_HUSH_INIT_VAR)
390 int hush_init_var(void)
397 #if defined(CONFIG_BOOTCOUNT_LIMIT)
398 void bootcount_store(ulong a
)
400 volatile ulong
*save_addr
;
401 volatile ulong size
= 0;
403 for (i
= 0; i
< CONFIG_NR_DRAM_BANKS
; i
++) {
404 size
+= gd
->bd
->bi_dram
[i
].size
;
406 save_addr
= (ulong
*)(size
- BOOTCOUNT_ADDR
);
407 writel(a
, save_addr
);
408 writel(BOOTCOUNT_MAGIC
, &save_addr
[1]);
411 ulong
bootcount_load(void)
413 volatile ulong
*save_addr
;
414 volatile ulong size
= 0;
416 for (i
= 0; i
< CONFIG_NR_DRAM_BANKS
; i
++) {
417 size
+= gd
->bd
->bi_dram
[i
].size
;
419 save_addr
= (ulong
*)(size
- BOOTCOUNT_ADDR
);
420 if (readl(&save_addr
[1]) != BOOTCOUNT_MAGIC
)
423 return readl(save_addr
);
427 #if defined(CONFIG_SOFT_I2C)
428 void set_sda(int state
)
434 void set_scl(int state
)
447 return kw_gpio_get_value(KM_KIRKWOOD_SCL_PIN
) ? 1 : 0;
451 #if defined(CONFIG_SYS_EEPROM_WREN)
452 int eeprom_write_enable(unsigned dev_addr
, int state
)
454 kw_gpio_set_value(KM_KIRKWOOD_ENV_WP
, !state
);
456 return !kw_gpio_get_value(KM_KIRKWOOD_ENV_WP
);