3 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
6 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
8 * Based on da830evm.c. Original Copyrights follow:
10 * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com>
11 * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #include <environment.h>
40 #include <asm/arch/da850_lowlevel.h>
41 #include <asm/arch/davinci_misc.h>
42 #include <asm/arch/emif_defs.h>
43 #include <asm/arch/emac_defs.h>
44 #include <asm/arch/gpio.h>
45 #include <asm/arch/pinmux_defs.h>
46 #include <asm/arch/hardware.h>
47 #include <asm/arch/sdmmc_defs.h>
48 #include <asm/arch/timer_defs.h>
50 DECLARE_GLOBAL_DATA_PTR;
52 const struct lpsc_resource lpsc[] = {
53 { DAVINCI_LPSC_AEMIF },
54 { DAVINCI_LPSC_SPI1 },
55 { DAVINCI_LPSC_ARM_RAM_ROM },
56 { DAVINCI_LPSC_UART0 },
57 { DAVINCI_LPSC_EMAC },
58 { DAVINCI_LPSC_UART0 },
59 { DAVINCI_LPSC_GPIO },
60 { DAVINCI_LPSC_DDR_EMIF },
61 { DAVINCI_LPSC_UART1 },
62 { DAVINCI_LPSC_UART2 },
63 { DAVINCI_LPSC_MMC_SD1 },
64 { DAVINCI_LPSC_USB20 },
65 { DAVINCI_LPSC_USB11 },
68 const int lpsc_size = ARRAY_SIZE(lpsc);
70 static const struct pinmux_config enbw_pins[] = {
100 { pinmux(13), 8, 2 },
101 { pinmux(13), 8, 3 },
102 { pinmux(13), 8, 4 },
103 { pinmux(13), 8, 5 },
104 { pinmux(13), 8, 6 },
105 { pinmux(13), 8, 7 },
106 { pinmux(14), 8, 0 },
107 { pinmux(14), 8, 1 },
108 { pinmux(16), 8, 1 },
109 { pinmux(16), 8, 2 },
110 { pinmux(16), 8, 3 },
111 { pinmux(16), 8, 4 },
112 { pinmux(16), 8, 5 },
113 { pinmux(16), 8, 6 },
114 { pinmux(16), 8, 7 },
115 { pinmux(17), 1, 0 },
116 { pinmux(17), 1, 1 },
117 { pinmux(17), 1, 2 },
118 { pinmux(17), 8, 3 },
119 { pinmux(17), 8, 4 },
120 { pinmux(17), 8, 5 },
121 { pinmux(17), 8, 6 },
122 { pinmux(17), 8, 7 },
123 { pinmux(18), 8, 0 },
124 { pinmux(18), 8, 1 },
125 { pinmux(18), 2, 2 },
126 { pinmux(18), 2, 3 },
127 { pinmux(18), 2, 4 },
128 { pinmux(18), 8, 6 },
129 { pinmux(18), 8, 7 },
130 { pinmux(19), 8, 0 },
131 { pinmux(19), 2, 1 },
132 { pinmux(19), 2, 2 },
133 { pinmux(19), 2, 3 },
134 { pinmux(19), 2, 4 },
135 { pinmux(19), 8, 5 },
136 { pinmux(19), 8, 6 },
139 const struct pinmux_resource pinmuxes[] = {
140 PINMUX_ITEM(emac_pins_mii),
141 PINMUX_ITEM(emac_pins_mdio),
142 PINMUX_ITEM(i2c0_pins),
143 PINMUX_ITEM(emifa_pins_cs2),
144 PINMUX_ITEM(emifa_pins_cs3),
145 PINMUX_ITEM(emifa_pins_cs4),
146 PINMUX_ITEM(emifa_pins_nand),
147 PINMUX_ITEM(emifa_pins_nor),
148 PINMUX_ITEM(spi1_pins_base),
149 PINMUX_ITEM(spi1_pins_scs0),
150 PINMUX_ITEM(uart1_pins_txrx),
151 PINMUX_ITEM(uart2_pins_txrx),
152 PINMUX_ITEM(uart2_pins_rtscts),
153 PINMUX_ITEM(enbw_pins),
156 const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
159 char name[GPIO_NAME_SIZE];
166 static const struct gpio_config enbw_gpio_config[] = {
167 { "RS485 enable", 8, 11, 1, 0 },
168 { "RS485 iso", 8, 10, 1, 0 },
169 { "W2HUT RS485 Rx ena", 8, 9, 1, 0 },
170 { "W2HUT RS485 iso", 8, 8, 1, 0 },
171 { "LAN reset", 7, 15, 1, 1 },
172 { "ena 11V PLC", 7, 14, 1, 0 },
173 { "ena 1.5V PLC", 7, 13, 1, 0 },
174 { "disable VBUS", 7, 12, 1, 1 },
175 { "PLC reset", 6, 13, 1, 1 },
176 { "LCM RS", 6, 12, 1, 0 },
177 { "LCM R/W", 6, 11, 1, 0 },
178 { "PLC pairing", 6, 10, 1, 1 },
179 { "PLC MDIO CLK", 6, 9, 1, 0 },
180 { "HK218", 6, 8, 1, 0 },
181 { "HK218 Rx", 6, 1, 1, 1 },
182 { "TPM reset", 6, 0, 1, 1 },
183 { "LCM E", 2, 2, 1, 1 },
184 { "PV-IF RxD ena", 0, 15, 1, 1 },
185 { "LED1", 1, 15, 1, 1 },
186 { "LED2", 0, 1, 1, 1 },
187 { "LED3", 0, 2, 1, 1 },
188 { "LED4", 0, 3, 1, 1 },
189 { "LED5", 0, 4, 1, 1 },
190 { "LED6", 0, 5, 1, 0 },
191 { "LED7", 0, 6, 1, 0 },
192 { "LED8", 0, 14, 1, 0 },
193 { "USER1", 0, 12, 0, 0 },
194 { "USER2", 0, 13, 0, 0 },
197 #define PHY_POWER 0x0800
199 static void enbw_cmc_switch(int port, int on)
202 unsigned char phyaddr = 3;
203 unsigned char reg = 0;
209 devname = miiphy_get_current_dev();
211 printf("Error: no mii device\n");
214 if (miiphy_read(devname, phyaddr, reg, &data) != 0) {
215 printf("Error reading from the PHY addr=%02x reg=%02x\n",
225 if (miiphy_write(devname, phyaddr, reg, data) != 0) {
226 printf("Error writing to the PHY addr=%02x reg=%02x\n",
236 #ifndef CONFIG_USE_IRQ
239 /* address of boot parameters, not used as booting with DTT */
240 gd->bd->bi_boot_params = 0;
242 for (i = 0; i < ARRAY_SIZE(enbw_gpio_config); i++) {
243 int gpio = enbw_gpio_config[i].bank * 16 +
244 enbw_gpio_config[i].gpio;
246 ret = gpio_request(gpio, enbw_gpio_config[i].name);
248 printf("%s: Could not get %s gpio\n", __func__,
249 enbw_gpio_config[i].name);
253 if (enbw_gpio_config[i].out)
254 gpio_direction_output(gpio,
255 enbw_gpio_config[i].value);
257 gpio_direction_input(gpio);
260 /* setup the SUSPSRC for ARM to control emulation suspend */
261 clrbits_le32(&davinci_syscfg_regs->suspsrc,
262 (DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
263 DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
264 DAVINCI_SYSCFG_SUSPSRC_UART2));
269 #ifdef CONFIG_DRIVER_TI_EMAC
271 * Initializes on-board ethernet controllers.
273 int board_eth_init(bd_t *bis)
275 #ifdef CONFIG_DRIVER_TI_EMAC
276 davinci_emac_mii_mode_sel(0);
277 #endif /* CONFIG_DRIVER_TI_EMAC */
279 if (!davinci_emac_initialize()) {
280 printf("Error: Ethernet init failed!\n");
284 if (hwconfig_subarg_cmp("switch", "lan", "on"))
285 /* Switch port lan on */
286 enbw_cmc_switch(1, 1);
288 enbw_cmc_switch(1, 0);
290 if (hwconfig_subarg_cmp("switch", "pwl", "on"))
291 /* Switch port pwl on */
292 enbw_cmc_switch(2, 1);
294 enbw_cmc_switch(2, 0);
298 #endif /* CONFIG_DRIVER_TI_EMAC */
300 #ifdef CONFIG_PREBOOT
301 static uchar kbd_magic_prefix[] = "key_magic_";
302 static uchar kbd_command_prefix[] = "key_cmd_";
308 struct kbd_data_t *get_keys(struct kbd_data_t *kbd_data)
311 kbd_data->s1 = gpio_get_value(12) +
312 (gpio_get_value(13) << 1);
316 static int compare_magic(const struct kbd_data_t *kbd_data, char *str)
320 if (s1 >= '0' && s1 <= '9')
322 else if (s1 >= 'a' && s1 <= 'f')
324 else if (s1 >= 'A' && s1 <= 'F')
329 if (s1 != kbd_data->s1)
335 static char *key_match(const struct kbd_data_t *kbd_data)
337 char magic[sizeof(kbd_magic_prefix) + 1];
339 char *kbd_magic_keys;
342 * The following string defines the characters that can be appended
343 * to "key_magic" to form the names of environment variables that
344 * hold "magic" key codes, i. e. such key codes that can cause
345 * pre-boot actions. If the string is empty (""), then only
346 * "key_magic" is checked (old behaviour); the string "125" causes
347 * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
349 kbd_magic_keys = getenv("magic_keys");
350 if (kbd_magic_keys == NULL)
354 * loop over all magic keys;
355 * use '\0' suffix in case of empty string
357 for (suffix = kbd_magic_keys; *suffix ||
358 suffix == kbd_magic_keys; ++suffix) {
359 sprintf(magic, "%s%c", kbd_magic_prefix, *suffix);
361 if (compare_magic(kbd_data, getenv(magic)) == 0) {
362 char cmd_name[sizeof(kbd_command_prefix) + 1];
365 sprintf(cmd_name, "%s%c", kbd_command_prefix, *suffix);
366 cmd = getenv(cmd_name);
374 #endif /* CONFIG_PREBOOT */
376 int misc_init_r(void)
379 #ifdef CONFIG_PREBOOT
380 struct kbd_data_t kbd_data;
382 char *str = strdup(key_match(get_keys(&kbd_data)));
383 /* Set or delete definition */
384 setenv("preboot", str);
386 #endif /* CONFIG_PREBOOT */
388 /* count all restarts, and save this in an environment var */
389 s = getenv("restartcount");
392 sprintf(buf, "%ld", simple_strtoul(s, NULL, 10) + 1);
396 setenv("restartcount", buf);
399 #ifdef CONFIG_HW_WATCHDOG
400 davinci_hw_watchdog_enable();
412 struct cmc_led led_table[] = {
423 static int cmc_get_led_state(struct cmc_led *led)
426 int gpio = led->bank * 16 + led->gpio;
428 value = gpio_get_value(gpio);
433 static int cmc_set_led_state(struct cmc_led *led, int state)
435 int gpio = led->bank * 16 + led->gpio;
437 gpio_set_value(gpio, state);
441 static int do_led(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
447 int len = ARRAY_SIZE(led_table);
450 return cmd_usage(cmdtp);
456 while ((!found) && (i < len)) {
457 if (strcmp(argv[1], led->name) == 0) {
465 return cmd_usage(cmdtp);
468 if (cmc_get_led_state(led))
475 if (strcmp(argv[2], "on") == 0)
476 cmc_set_led_state(led, 1);
478 cmc_set_led_state(led, 0);
483 U_BOOT_CMD(led, 3, 1, do_led,
484 "switch on/off board led",
488 #ifdef CONFIG_HW_WATCHDOG
489 void hw_watchdog_reset(void)
491 davinci_hw_watchdog_reset();
495 #if defined(CONFIG_POST)
496 void arch_memory_failure_handle(void)
498 struct davinci_gpio *gpio = davinci_gpio_bank01;
502 * if memor< failure blink with the LED 1,2 and 3
503 * as we running from flash, we cannot use the gpio
504 * api here, so access the gpio pin direct through
509 clrbits_le32(&gpio->out_data, 0x80000006);
512 setbits_le32(&gpio->out_data, 0x80000006);
520 #if defined(CONFIG_BOOTCOUNT_LIMIT)
521 void bootcount_store(ulong a)
523 struct davinci_rtc *reg =
524 (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
527 * write RTC kick register to enable write
528 * for RTC Scratch registers. Cratch0 and 1 are
529 * used for bootcount values.
531 writel(RTC_KICK0R_WE, ®->kick0r);
532 writel(RTC_KICK1R_WE, ®->kick1r);
533 out_be32(®->scratch0, a);
534 out_be32(®->scratch1, BOOTCOUNT_MAGIC);
537 ulong bootcount_load(void)
539 struct davinci_rtc *reg =
540 (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
542 if (in_be32(®->scratch1) != BOOTCOUNT_MAGIC)
545 return in_be32(®->scratch0);
549 void board_gpio_init(void)
551 struct davinci_gpio *gpio = davinci_gpio_bank01;
554 * set LED (gpio Interface not usable here)
555 * set LED pins to output and state 0
557 clrbits_le32(&gpio->dir, 0x8000407e);
558 clrbits_le32(&gpio->out_data, 0x8000407e);
559 /* set LED 1 - 5 to state on */
560 setbits_le32(&gpio->out_data, 0x8000001e);
563 int board_late_init(void)
565 cmc_set_led_state(&led_table[4], 0);
570 void show_boot_progress(int val)
574 cmc_set_led_state(&led_table[4], 1);
577 cmc_set_led_state(&led_table[4], 0);
580 cmc_set_led_state(&led_table[4], 1);
585 #ifdef CONFIG_DAVINCI_MMC
586 static struct davinci_mmc mmc_sd1 = {
587 .reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD1_BASE,
588 .input_clk = 228000000,
589 .host_caps = MMC_MODE_4BIT,
590 .voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
591 .version = MMC_CTLR_VERSION_2,
594 int board_mmc_init(bd_t *bis)
596 mmc_sd1.input_clk = clk_get(DAVINCI_MMC_CLKID);
597 /* Add slot-0 to mmc subsystem */
598 return davinci_mmc_init(bis, &mmc_sd1);