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 static 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 static const struct pinmux_config enbw_pins[] = {
100 { pinmux(13), 8, 4 },
101 { pinmux(13), 8, 5 },
102 { pinmux(13), 8, 6 },
103 { pinmux(13), 8, 7 },
104 { pinmux(14), 8, 0 },
105 { pinmux(14), 8, 1 },
106 { pinmux(16), 8, 1 },
107 { pinmux(16), 8, 2 },
108 { pinmux(16), 8, 3 },
109 { pinmux(16), 8, 4 },
110 { pinmux(16), 8, 5 },
111 { pinmux(16), 8, 6 },
112 { pinmux(16), 8, 7 },
113 { pinmux(17), 1, 0 },
114 { pinmux(17), 1, 1 },
115 { pinmux(17), 1, 2 },
116 { pinmux(17), 8, 3 },
117 { pinmux(17), 8, 4 },
118 { pinmux(17), 8, 5 },
119 { pinmux(17), 8, 6 },
120 { pinmux(17), 8, 7 },
121 { pinmux(18), 8, 0 },
122 { pinmux(18), 8, 1 },
123 { pinmux(18), 2, 2 },
124 { pinmux(18), 2, 3 },
125 { pinmux(18), 2, 4 },
126 { pinmux(18), 8, 6 },
127 { pinmux(18), 8, 7 },
128 { pinmux(19), 8, 0 },
129 { pinmux(19), 2, 1 },
130 { pinmux(19), 2, 2 },
131 { pinmux(19), 2, 3 },
132 { pinmux(19), 2, 4 },
133 { pinmux(19), 8, 5 },
134 { pinmux(19), 8, 6 },
137 const struct pinmux_resource pinmuxes[] = {
138 PINMUX_ITEM(emac_pins_mii),
139 PINMUX_ITEM(emac_pins_mdio),
140 PINMUX_ITEM(i2c0_pins),
141 PINMUX_ITEM(emifa_pins_cs2),
142 PINMUX_ITEM(emifa_pins_cs3),
143 PINMUX_ITEM(emifa_pins_cs4),
144 PINMUX_ITEM(emifa_pins_nand),
145 PINMUX_ITEM(emifa_pins_nor),
146 PINMUX_ITEM(spi1_pins_base),
147 PINMUX_ITEM(spi1_pins_scs0),
148 PINMUX_ITEM(uart1_pins_txrx),
149 PINMUX_ITEM(uart2_pins_txrx),
150 PINMUX_ITEM(uart2_pins_rtscts),
151 PINMUX_ITEM(enbw_pins),
154 const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
157 char name[GPIO_NAME_SIZE];
164 static const struct gpio_config enbw_gpio_config[] = {
165 { "RS485 enable", 8, 11, 1, 0 },
166 { "RS485 iso", 8, 10, 1, 0 },
167 { "W2HUT RS485 Rx ena", 8, 9, 1, 0 },
168 { "W2HUT RS485 iso", 8, 8, 1, 0 },
169 { "LAN reset", 7, 15, 1, 1 },
170 { "ena 11V PLC", 7, 14, 1, 0 },
171 { "ena 1.5V PLC", 7, 13, 1, 0 },
172 { "disable VBUS", 7, 12, 1, 1 },
173 { "PLC reset", 6, 13, 1, 1 },
174 { "LCM RS", 6, 12, 1, 0 },
175 { "LCM R/W", 6, 11, 1, 0 },
176 { "PLC pairing", 6, 10, 1, 1 },
177 { "PLC MDIO CLK", 6, 9, 1, 0 },
178 { "HK218", 6, 8, 1, 0 },
179 { "HK218 Rx", 6, 1, 1, 1 },
180 { "TPM reset", 6, 0, 1, 1 },
181 { "LCM E", 2, 2, 1, 1 },
182 { "PV-IF RxD ena", 0, 15, 1, 1 },
183 { "LED1", 1, 15, 1, 1 },
184 { "LED2", 0, 1, 1, 1 },
185 { "LED3", 0, 2, 1, 1 },
186 { "LED4", 0, 3, 1, 1 },
187 { "LED5", 0, 4, 1, 1 },
188 { "LED6", 0, 5, 1, 0 },
189 { "LED7", 0, 6, 1, 0 },
190 { "LED8", 0, 14, 1, 0 },
191 { "USER1", 0, 12, 0, 0 },
192 { "USER2", 0, 13, 0, 0 },
195 #define PHY_POWER 0x0800
197 static void enbw_cmc_switch(int port, int on)
200 unsigned char phyaddr = 3;
201 unsigned char reg = 0;
207 devname = miiphy_get_current_dev();
209 printf("Error: no mii device\n");
212 if (miiphy_read(devname, phyaddr, reg, &data) != 0) {
213 printf("Error reading from the PHY addr=%02x reg=%02x\n",
223 if (miiphy_write(devname, phyaddr, reg, data) != 0) {
224 printf("Error writing to the PHY addr=%02x reg=%02x\n",
234 #ifndef CONFIG_USE_IRQ
237 /* address of boot parameters, not used as booting with DTT */
238 gd->bd->bi_boot_params = 0;
240 for (i = 0; i < ARRAY_SIZE(enbw_gpio_config); i++) {
241 int gpio = enbw_gpio_config[i].bank * 16 +
242 enbw_gpio_config[i].gpio;
244 ret = gpio_request(gpio, enbw_gpio_config[i].name);
246 printf("%s: Could not get %s gpio\n", __func__,
247 enbw_gpio_config[i].name);
251 if (enbw_gpio_config[i].out)
252 gpio_direction_output(gpio,
253 enbw_gpio_config[i].value);
255 gpio_direction_input(gpio);
258 /* setup the SUSPSRC for ARM to control emulation suspend */
259 clrbits_le32(&davinci_syscfg_regs->suspsrc,
260 (DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
261 DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
262 DAVINCI_SYSCFG_SUSPSRC_UART2));
267 #ifdef CONFIG_DRIVER_TI_EMAC
269 * Initializes on-board ethernet controllers.
271 int board_eth_init(bd_t *bis)
273 #ifdef CONFIG_DRIVER_TI_EMAC
274 davinci_emac_mii_mode_sel(0);
275 #endif /* CONFIG_DRIVER_TI_EMAC */
277 if (!davinci_emac_initialize()) {
278 printf("Error: Ethernet init failed!\n");
282 if (hwconfig_subarg_cmp("switch", "lan", "on"))
283 /* Switch port lan on */
284 enbw_cmc_switch(1, 1);
286 enbw_cmc_switch(1, 0);
288 if (hwconfig_subarg_cmp("switch", "pwl", "on"))
289 /* Switch port pwl on */
290 enbw_cmc_switch(2, 1);
292 enbw_cmc_switch(2, 0);
296 #endif /* CONFIG_DRIVER_TI_EMAC */
298 #ifdef CONFIG_PREBOOT
299 static uchar kbd_magic_prefix[] = "key_magic_";
300 static uchar kbd_command_prefix[] = "key_cmd_";
306 struct kbd_data_t *get_keys(struct kbd_data_t *kbd_data)
309 kbd_data->s1 = gpio_get_value(12) +
310 (gpio_get_value(13) << 1);
314 static int compare_magic(const struct kbd_data_t *kbd_data, char *str)
318 if (s1 >= '0' && s1 <= '9')
320 else if (s1 >= 'a' && s1 <= 'f')
322 else if (s1 >= 'A' && s1 <= 'F')
327 if (s1 != kbd_data->s1)
333 static char *key_match(const struct kbd_data_t *kbd_data)
335 char magic[sizeof(kbd_magic_prefix) + 1];
337 char *kbd_magic_keys;
340 * The following string defines the characters that can be appended
341 * to "key_magic" to form the names of environment variables that
342 * hold "magic" key codes, i. e. such key codes that can cause
343 * pre-boot actions. If the string is empty (""), then only
344 * "key_magic" is checked (old behaviour); the string "125" causes
345 * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
347 kbd_magic_keys = getenv("magic_keys");
348 if (kbd_magic_keys == NULL)
352 * loop over all magic keys;
353 * use '\0' suffix in case of empty string
355 for (suffix = kbd_magic_keys; *suffix ||
356 suffix == kbd_magic_keys; ++suffix) {
357 sprintf(magic, "%s%c", kbd_magic_prefix, *suffix);
359 if (compare_magic(kbd_data, getenv(magic)) == 0) {
360 char cmd_name[sizeof(kbd_command_prefix) + 1];
363 sprintf(cmd_name, "%s%c", kbd_command_prefix, *suffix);
364 cmd = getenv(cmd_name);
372 #endif /* CONFIG_PREBOOT */
374 int misc_init_r(void)
377 #ifdef CONFIG_PREBOOT
378 struct kbd_data_t kbd_data;
380 char *str = strdup(key_match(get_keys(&kbd_data)));
381 /* Set or delete definition */
382 setenv("preboot", str);
384 #endif /* CONFIG_PREBOOT */
386 /* count all restarts, and save this in an environment var */
387 s = getenv("restartcount");
390 sprintf(buf, "%ld", simple_strtoul(s, NULL, 10) + 1);
394 setenv("restartcount", buf);
397 #ifdef CONFIG_HW_WATCHDOG
398 davinci_hw_watchdog_enable();
410 struct cmc_led led_table[] = {
421 static int cmc_get_led_state(struct cmc_led *led)
424 int gpio = led->bank * 16 + led->gpio;
426 value = gpio_get_value(gpio);
431 static int cmc_set_led_state(struct cmc_led *led, int state)
433 int gpio = led->bank * 16 + led->gpio;
435 gpio_set_value(gpio, state);
439 static int do_led(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
445 int len = ARRAY_SIZE(led_table);
448 return cmd_usage(cmdtp);
454 while ((!found) && (i < len)) {
455 if (strcmp(argv[1], led->name) == 0) {
463 return cmd_usage(cmdtp);
466 if (cmc_get_led_state(led))
473 if (strcmp(argv[2], "on") == 0)
474 cmc_set_led_state(led, 1);
476 cmc_set_led_state(led, 0);
481 U_BOOT_CMD(led, 3, 1, do_led,
482 "switch on/off board led",
486 #ifdef CONFIG_HW_WATCHDOG
487 void hw_watchdog_reset(void)
489 davinci_hw_watchdog_reset();
493 #if defined(CONFIG_POST)
494 void arch_memory_failure_handle(void)
496 struct davinci_gpio *gpio = davinci_gpio_bank01;
500 * if memor< failure blink with the LED 1,2 and 3
501 * as we running from flash, we cannot use the gpio
502 * api here, so access the gpio pin direct through
507 clrbits_le32(&gpio->out_data, 0x80000006);
510 setbits_le32(&gpio->out_data, 0x80000006);
518 #if defined(CONFIG_BOOTCOUNT_LIMIT)
519 void bootcount_store(ulong a)
521 struct davinci_rtc *reg =
522 (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
525 * write RTC kick register to enable write
526 * for RTC Scratch registers. Cratch0 and 1 are
527 * used for bootcount values.
529 writel(RTC_KICK0R_WE, ®->kick0r);
530 writel(RTC_KICK1R_WE, ®->kick1r);
531 out_be32(®->scratch0, a);
532 out_be32(®->scratch1, BOOTCOUNT_MAGIC);
535 ulong bootcount_load(void)
537 struct davinci_rtc *reg =
538 (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
540 if (in_be32(®->scratch1) != BOOTCOUNT_MAGIC)
543 return in_be32(®->scratch0);
547 void board_gpio_init(void)
549 struct davinci_gpio *gpio = davinci_gpio_bank01;
552 * Power on required peripherals
553 * ARM does not have access by default to PSC0 and PSC1
554 * assuming here that the DSP bootloader has set the IOPU
555 * such that PSC access is available to ARM
557 if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
561 * set LED (gpio Interface not usable here)
562 * set LED pins to output and state 0
564 clrbits_le32(&gpio->dir, 0x8000407e);
565 clrbits_le32(&gpio->out_data, 0x8000407e);
566 /* set LED 1 - 5 to state on */
567 setbits_le32(&gpio->out_data, 0x8000001e);
570 int board_late_init(void)
572 cmc_set_led_state(&led_table[4], 0);
577 void show_boot_progress(int val)
581 cmc_set_led_state(&led_table[4], 1);
584 cmc_set_led_state(&led_table[4], 0);
587 cmc_set_led_state(&led_table[4], 1);
592 #ifdef CONFIG_DAVINCI_MMC
593 static struct davinci_mmc mmc_sd1 = {
594 .reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD1_BASE,
595 .input_clk = 228000000,
596 .host_caps = MMC_MODE_4BIT,
597 .voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
598 .version = MMC_CTLR_VERSION_2,
601 int board_mmc_init(bd_t *bis)
603 mmc_sd1.input_clk = clk_get(DAVINCI_MMC_CLKID);
604 /* Add slot-0 to mmc subsystem */
605 return davinci_mmc_init(bis, &mmc_sd1);