]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/hmi1001/hmi1001.c
Add keyboard and dot matrix display support for HMI1001 board.
[karo-tx-uboot.git] / board / hmi1001 / hmi1001.c
1 /*
2  * (C) Copyright 2003-2004
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * (C) Copyright 2004
6  * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
7  *
8  * (C) Copyright 2004
9  * Martin Krause, TQ-Systems GmbH, martin.krause@tqs.de
10  *
11  * See file CREDITS for list of people who contributed to this
12  * project.
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License as
16  * published by the Free Software Foundation; either version 2 of
17  * the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27  * MA 02111-1307 USA
28  */
29
30 #include <common.h>
31 #include <mpc5xxx.h>
32 #include <pci.h>
33
34 #ifndef CFG_RAMBOOT
35 static void sdram_start (int hi_addr)
36 {
37         long hi_addr_bit = hi_addr ? 0x01000000 : 0;
38
39         /* unlock mode register */
40         *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
41         __asm__ volatile ("sync");
42
43         /* precharge all banks */
44         *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
45         __asm__ volatile ("sync");
46
47 #if SDRAM_DDR
48         /* set mode register: extended mode */
49         *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
50         __asm__ volatile ("sync");
51
52         /* set mode register: reset DLL */
53         *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
54         __asm__ volatile ("sync");
55 #endif
56
57         /* precharge all banks */
58         *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
59         __asm__ volatile ("sync");
60
61         /* auto refresh */
62         *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
63         __asm__ volatile ("sync");
64
65         /* set mode register */
66         *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
67         __asm__ volatile ("sync");
68
69         /* normal operation */
70         *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
71         __asm__ volatile ("sync");
72 }
73 #endif
74
75 /*
76  * ATTENTION: Although partially referenced initdram does NOT make real use
77  *            use of CFG_SDRAM_BASE. The code does not work if CFG_SDRAM_BASE
78  *            is something else than 0x00000000.
79  */
80
81 long int initdram (int board_type)
82 {
83         ulong dramsize = 0;
84 #ifndef CFG_RAMBOOT
85         ulong test1, test2;
86
87         /* setup SDRAM chip selects */
88         *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001c; /* 512MB at 0x0 */
89         *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x40000000; /* disabled */
90         __asm__ volatile ("sync");
91
92         /* setup config registers */
93         *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
94         *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
95         __asm__ volatile ("sync");
96
97 #if SDRAM_DDR
98         /* set tap delay */
99         *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
100         __asm__ volatile ("sync");
101 #endif
102
103         /* find RAM size using SDRAM CS0 only */
104         sdram_start(0);
105         test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x20000000);
106         sdram_start(1);
107         test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x20000000);
108         if (test1 > test2) {
109                 sdram_start(0);
110                 dramsize = test1;
111         } else {
112                 dramsize = test2;
113         }
114
115         /* memory smaller than 1MB is impossible */
116         if (dramsize < (1 << 20)) {
117                 dramsize = 0;
118         }
119
120         /* set SDRAM CS0 size according to the amount of RAM found */
121         if (dramsize > 0) {
122                 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 +
123                         __builtin_ffs(dramsize >> 20) - 1;
124         } else {
125                 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
126         }
127
128         *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
129 #else /* CFG_RAMBOOT */
130
131         /* retrieve size of memory connected to SDRAM CS0 */
132         dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
133         if (dramsize >= 0x13) {
134                 dramsize = (1 << (dramsize - 0x13)) << 20;
135         } else {
136                 dramsize = 0;
137         }
138
139         /* retrieve size of memory connected to SDRAM CS1 */
140         dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
141         if (dramsize2 >= 0x13) {
142                 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
143         } else {
144                 dramsize2 = 0;
145         }
146
147 #endif /* CFG_RAMBOOT */
148
149 /*      return dramsize + dramsize2; */
150         return dramsize;
151 }
152
153 int checkboard (void)
154 {
155         puts ("Board: HMI1001\n");
156         return 0;
157 }
158
159 #ifdef CONFIG_PREBOOT
160
161 static uchar kbd_magic_prefix[]         = "key_magic";
162 static uchar kbd_command_prefix[]       = "key_cmd";
163
164 #define S1_ROT  0xf0
165 #define S2_Q    0x40
166 #define S2_M    0x20
167
168 struct kbd_data_t {
169         char s1;
170         char s2;
171 };
172
173 struct kbd_data_t* get_keys (struct kbd_data_t *kbd_data)
174 {
175         kbd_data->s1 = *((volatile uchar*)(CFG_STATUS1_BASE));
176         kbd_data->s2 = *((volatile uchar*)(CFG_STATUS2_BASE));
177
178         return kbd_data;
179 }
180
181 static int compare_magic (struct kbd_data_t *kbd_data, uchar *str)
182 {
183         char s1 = str[0];
184         char s2;
185
186         if (s1 >= '0' && s1 <= '9')
187                 s1 -= '0';
188         else if (s1 >= 'a' && s1 <= 'f')
189                 s1 = s1 - 'a' + 10;
190         else if (s1 >= 'A' && s1 <= 'F')
191                 s1 = s1 - 'A' + 10;
192         else
193                 return -1;
194
195         if (((S1_ROT & kbd_data->s1) >> 4) != s1)
196                 return -1;
197
198         s2 = (S2_Q | S2_M) & kbd_data->s2;
199
200         switch (str[1]) {
201         case 'q':
202         case 'Q':
203                 if (s2 == S2_Q)
204                         return -1;
205                 break;
206         case 'm':
207         case 'M':
208                 if (s2 == S2_M)
209                         return -1;
210                 break;
211         case '\0':
212                 if (s2 == (S2_Q | S2_M))
213                         return 0;
214         default:
215                 return -1;
216         }
217
218         if (str[2])
219                 return -1;
220
221         return 0;
222 }
223
224 static uchar *key_match (const struct kbd_data_t *kbd_data)
225 {
226         uchar magic[sizeof (kbd_magic_prefix) + 1];
227         uchar *suffix;
228         uchar *kbd_magic_keys;
229
230         /*
231          * The following string defines the characters that can be appended
232          * to "key_magic" to form the names of environment variables that
233          * hold "magic" key codes, i. e. such key codes that can cause
234          * pre-boot actions. If the string is empty (""), then only
235          * "key_magic" is checked (old behaviour); the string "125" causes
236          * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
237          */
238         if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
239                 kbd_magic_keys = "";
240
241         /* loop over all magic keys;
242          * use '\0' suffix in case of empty string
243          */
244         for (suffix = kbd_magic_keys; *suffix ||
245                      suffix == kbd_magic_keys; ++suffix) {
246                 sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
247
248                 if (compare_magic(kbd_data, getenv(magic)) == 0) {
249                         uchar cmd_name[sizeof (kbd_command_prefix) + 1];
250                         char *cmd;
251
252                         sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
253                         cmd = getenv (cmd_name);
254
255                         return (cmd);
256                 }
257         }
258
259         return (NULL);
260 }
261
262 #endif /* CONFIG_PREBOOT */
263
264 int misc_init_f (void)
265 {
266 }
267
268 int misc_init_r (void)
269 {
270 #ifdef CONFIG_PREBOOT
271         struct kbd_data_t kbd_data;
272         /* Decode keys */
273         uchar *str = strdup (key_match (get_keys (&kbd_data)));
274         /* Set or delete definition */
275         setenv ("preboot", str);
276         free (str);
277 #endif /* CONFIG_PREBOOT */
278
279         return 0;
280 }
281
282 int board_early_init_r (void)
283 {
284         *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
285         *(vu_long *)MPC5XXX_BOOTCS_START =
286         *(vu_long *)MPC5XXX_CS0_START = START_REG(CFG_FLASH_BASE);
287         *(vu_long *)MPC5XXX_BOOTCS_STOP =
288         *(vu_long *)MPC5XXX_CS0_STOP = STOP_REG(CFG_FLASH_BASE, CFG_FLASH_SIZE);
289         return 0;
290 }
291 #ifdef  CONFIG_PCI
292 static struct pci_controller hose;
293
294 extern void pci_mpc5xxx_init(struct pci_controller *);
295
296 void pci_init_board(void)
297 {
298         pci_mpc5xxx_init(&hose);
299 }
300 #endif