blob: 14237443fa52446d097fa93e16a3977643c94320 [file] [log] [blame]
stroesea65cb682003-09-12 08:41:39 +00001/*
2 * (C) Copyright 2001-2003
3 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
stroesea65cb682003-09-12 08:41:39 +00006 */
7
8#include <common.h>
9#include <asm/processor.h>
Matthias Fuchsbb57ad42009-02-20 10:19:19 +010010#include <asm/io.h>
stroesea65cb682003-09-12 08:41:39 +000011#include <command.h>
12#include <malloc.h>
13
Wolfgang Denkd87080b2006-03-31 18:32:53 +020014DECLARE_GLOBAL_DATA_PTR;
stroese31193c22004-12-16 18:37:08 +000015
16extern void lxt971_no_sleep(void);
stroesea65cb682003-09-12 08:41:39 +000017
stroese47b1e3d2005-03-01 17:26:39 +000018int board_revision(void)
19{
20 unsigned long osrl_reg;
21 unsigned long isr1l_reg;
22 unsigned long tcr_reg;
23 unsigned long value;
24
25 /*
26 * Get version of HUB405 board from GPIO's
27 */
28
29 /*
30 * Setup GPIO pin(s) (IRQ6/GPIO23)
31 */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +010032 osrl_reg = in_be32((void *)GPIO0_OSRH);
33 isr1l_reg = in_be32((void *)GPIO0_ISR1H);
34 tcr_reg = in_be32((void *)GPIO0_TCR);
35 out_be32((void *)GPIO0_OSRH, osrl_reg & ~0x00030000); /* output select */
36 out_be32((void *)GPIO0_ISR1H, isr1l_reg | 0x00030000); /* input select */
37 out_be32((void *)GPIO0_TCR, tcr_reg & ~0x00000100); /* select input */
stroese47b1e3d2005-03-01 17:26:39 +000038
39 udelay(1000); /* wait some time before reading input */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +010040 value = in_be32((void *)GPIO0_IR) & 0x00000100; /* get config bits */
stroese47b1e3d2005-03-01 17:26:39 +000041
42 /*
43 * Restore GPIO settings
44 */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +010045 out_be32((void *)GPIO0_OSRH, osrl_reg); /* output select */
46 out_be32((void *)GPIO0_ISR1H, isr1l_reg); /* input select */
47 out_be32((void *)GPIO0_TCR, tcr_reg); /* enable output driver for outputs */
stroese47b1e3d2005-03-01 17:26:39 +000048
49 if (value & 0x00000100) {
50 /* Revision 1.1 or 1.2 detected */
51 return 1;
52 }
53
54 /* Revision 1.0 */
55 return 0;
56}
57
58
wdenkc837dcb2004-01-20 23:12:12 +000059int board_early_init_f (void)
stroesea65cb682003-09-12 08:41:39 +000060{
61 /*
62 * IRQ 0-15 405GP internally generated; active high; level sensitive
63 * IRQ 16 405GP internally generated; active low; level sensitive
64 * IRQ 17-24 RESERVED
65 * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
66 * IRQ 26 (EXT IRQ 1) SER0 ; active low; level sensitive
67 * IRQ 27 (EXT IRQ 2) SER1; active low; level sensitive
68 * IRQ 28 (EXT IRQ 3) FPGA 0; active low; level sensitive
69 * IRQ 29 (EXT IRQ 4) FPGA 1; active low; level sensitive
70 * IRQ 30 (EXT IRQ 5) PCI INTA; active low; level sensitive
71 * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
72 */
Stefan Roese952e7762009-09-24 09:55:50 +020073 mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
74 mtdcr(UIC0ER, 0x00000000); /* disable all ints */
75 mtdcr(UIC0CR, 0x00000000); /* set all to be non-critical*/
76 mtdcr(UIC0PR, 0xFFFFFF9F); /* set int polarities */
77 mtdcr(UIC0TR, 0x10000000); /* set int trigger levels */
78 mtdcr(UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest priority*/
79 mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
stroesea65cb682003-09-12 08:41:39 +000080
81 /*
82 * EBC Configuration Register: set ready timeout to 512 ebc-clks -> ca. 15 us
83 */
Stefan Roesed1c3b272009-09-09 16:25:29 +020084 mtebc (EBC0_CFG, 0xa8400000); /* ebc always driven */
stroesea65cb682003-09-12 08:41:39 +000085
86 return 0;
87}
88
Matthias Fuchsbb57ad42009-02-20 10:19:19 +010089#define LED_REG (DUART0_BA + 0x20)
stroesea65cb682003-09-12 08:41:39 +000090int misc_init_r (void)
91{
stroese31193c22004-12-16 18:37:08 +000092 unsigned long val;
93 int delay, flashcnt;
94 char *str;
stroese47b1e3d2005-03-01 17:26:39 +000095 char hw_rev[4];
stroesea65cb682003-09-12 08:41:39 +000096
97 /*
98 * Enable interrupts in exar duart mcr[3]
99 */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100100 out_8((void *)(DUART0_BA + 4), 0x08);
101 out_8((void *)(DUART1_BA + 4), 0x08);
102 out_8((void *)(DUART2_BA + 4), 0x08);
103 out_8((void *)(DUART3_BA + 4), 0x08);
stroesea65cb682003-09-12 08:41:39 +0000104
wdenkefe2a4d2004-12-16 21:44:03 +0000105 /*
stroese31193c22004-12-16 18:37:08 +0000106 * Set RS232/RS422 control (RS232 = high on GPIO)
107 */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100108 val = in_be32((void *)GPIO0_OR);
109 val &= ~(CONFIG_SYS_UART2_RS232 | CONFIG_SYS_UART3_RS232 |
110 CONFIG_SYS_UART4_RS232 | CONFIG_SYS_UART5_RS232);
stroese31193c22004-12-16 18:37:08 +0000111
112 str = getenv("phys0");
113 if (!str || (str && (str[0] == '0')))
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200114 val |= CONFIG_SYS_UART2_RS232;
stroese31193c22004-12-16 18:37:08 +0000115
116 str = getenv("phys1");
117 if (!str || (str && (str[0] == '0')))
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200118 val |= CONFIG_SYS_UART3_RS232;
stroese31193c22004-12-16 18:37:08 +0000119
120 str = getenv("phys2");
121 if (!str || (str && (str[0] == '0')))
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200122 val |= CONFIG_SYS_UART4_RS232;
stroese31193c22004-12-16 18:37:08 +0000123
124 str = getenv("phys3");
125 if (!str || (str && (str[0] == '0')))
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200126 val |= CONFIG_SYS_UART5_RS232;
stroese31193c22004-12-16 18:37:08 +0000127
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100128 out_be32((void *)GPIO0_OR, val);
stroese31193c22004-12-16 18:37:08 +0000129
stroesea65cb682003-09-12 08:41:39 +0000130 /*
stroese31193c22004-12-16 18:37:08 +0000131 * check board type and setup AP power
132 */
133 str = getenv("bd_type"); /* this is only set on non prototype hardware */
134 if (str != NULL) {
stroese47b1e3d2005-03-01 17:26:39 +0000135 if ((strcmp(str, "swch405") == 0) || ((!strcmp(str, "hub405") && (gd->board_type >= 1)))) {
stroese31193c22004-12-16 18:37:08 +0000136 unsigned char led_reg_default = 0;
137 str = getenv("ap_pwr");
138 if (!str || (str && (str[0] == '1')))
139 led_reg_default = 0x04 | 0x02 ; /* U2_LED | AP_PWR */
140
141 /*
stroese47b1e3d2005-03-01 17:26:39 +0000142 * Flash LEDs
stroese31193c22004-12-16 18:37:08 +0000143 */
144 for (flashcnt = 0; flashcnt < 3; flashcnt++) {
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100145 /* LED_A..D off */
146 out_8((void *)LED_REG, led_reg_default);
stroese31193c22004-12-16 18:37:08 +0000147 for (delay = 0; delay < 100; delay++)
148 udelay(1000);
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100149 /* LED_A..D on */
150 out_8((void *)LED_REG, led_reg_default | 0xf0);
stroese31193c22004-12-16 18:37:08 +0000151 for (delay = 0; delay < 50; delay++)
152 udelay(1000);
153 }
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100154 out_8((void *)LED_REG, led_reg_default);
stroese31193c22004-12-16 18:37:08 +0000155 }
156 }
157
158 /*
159 * Reset external DUARTs
160 */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100161 out_be32((void *)GPIO0_OR,
162 in_be32((void *)GPIO0_OR) | CONFIG_SYS_DUART_RST); /* set reset to high */
stroese31193c22004-12-16 18:37:08 +0000163 udelay(10); /* wait 10us */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100164 out_be32((void *)GPIO0_OR,
165 in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_DUART_RST); /* set reset to low */
stroese31193c22004-12-16 18:37:08 +0000166 udelay(1000); /* wait 1ms */
167
stroese47b1e3d2005-03-01 17:26:39 +0000168 /*
169 * Store hardware revision in environment for further processing
170 */
171 sprintf(hw_rev, "1.%ld", gd->board_type);
172 setenv("hw_rev", hw_rev);
stroesea65cb682003-09-12 08:41:39 +0000173 return (0);
174}
175
176
177/*
178 * Check Board Identity:
179 */
stroesea65cb682003-09-12 08:41:39 +0000180int checkboard (void)
181{
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200182 char str[64];
Wolfgang Denkcdb74972010-07-24 21:55:43 +0200183 int i = getenv_f("serial#", str, sizeof(str));
stroesea65cb682003-09-12 08:41:39 +0000184
185 puts ("Board: ");
186
187 if (i == -1) {
188 puts ("### No HW ID - assuming HUB405");
189 } else {
190 puts(str);
191 }
192
Wolfgang Denkcdb74972010-07-24 21:55:43 +0200193 if (getenv_f("bd_type", str, sizeof(str)) != -1) {
stroese47b1e3d2005-03-01 17:26:39 +0000194 printf(" (%s", str);
195 } else {
196 puts(" (Missing bd_type!");
197 }
198
199 gd->board_type = board_revision();
200 printf(", Rev 1.%ld)\n", gd->board_type);
stroesea65cb682003-09-12 08:41:39 +0000201
stroese31193c22004-12-16 18:37:08 +0000202 /*
203 * Disable sleep mode in LXT971
204 */
205 lxt971_no_sleep();
206
stroesea65cb682003-09-12 08:41:39 +0000207 return 0;
208}