blob: 84ff47e53c7af9b5cdb906e51dd411d75bd0d3f2 [file] [log] [blame]
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +01001/*
Markus Klotzbuecher24e37642006-05-23 10:33:11 +02002 * (C) Copyright 2006
3 * DENX Software Engineering
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +01004 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
Markus Klotzbuecherba70d6a2006-03-24 12:23:27 +010025#include <i2c.h>
26#include <da9030.h>
Markus Klotzbuecher71ae4112006-04-25 10:03:01 +020027#include <malloc.h>
28#include <command.h>
Markus Klotzbuecherba70d6a2006-03-24 12:23:27 +010029#include <asm/arch/pxa-regs.h>
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +010030
Wolfgang Denkd87080b2006-03-31 18:32:53 +020031DECLARE_GLOBAL_DATA_PTR;
32
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +010033/* ------------------------------------------------------------------------- */
34
Markus Klotzbuecherba70d6a2006-03-24 12:23:27 +010035static void init_DA9030(void);
Markus Klotzbuecher71ae4112006-04-25 10:03:01 +020036static void keys_init(void);
37static void get_pressed_keys(uchar *s);
38static uchar *key_match(uchar *kbd_data);
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +010039
40/*
41 * Miscelaneous platform dependent initialisations
42 */
43
44int board_init (void)
45{
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +010046 /* memory and cpu-speed are setup before relocation */
47 /* so we do _nothing_ here */
48
Markus Klotzbücher69493282006-02-28 18:05:25 +010049 /* arch number of Lubbock-Board mk@tbd: fix this! */
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +010050 gd->bd->bi_arch_number = MACH_TYPE_LUBBOCK;
51
52 /* adress of boot parameters */
53 gd->bd->bi_boot_params = 0xa0000100;
54
55 return 0;
56}
57
58int board_late_init(void)
59{
Markus Klotzbuecher71ae4112006-04-25 10:03:01 +020060#ifdef DELTA_CHECK_KEYBD
61 uchar kbd_data[KEYBD_DATALEN];
62 char keybd_env[2 * KEYBD_DATALEN + 1];
63 char *str;
64 int i;
65#endif /* DELTA_CHECK_KEYBD */
66
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +010067 setenv("stdout", "serial");
68 setenv("stderr", "serial");
Markus Klotzbuecher71ae4112006-04-25 10:03:01 +020069
70#ifdef DELTA_CHECK_KEYBD
71 keys_init();
72
73 memset(kbd_data, '\0', KEYBD_DATALEN);
74
75 /* check for pressed keys and setup keybd_env */
76 get_pressed_keys(kbd_data);
77
78 for (i = 0; i < KEYBD_DATALEN; ++i) {
79 sprintf (keybd_env + i + i, "%02X", kbd_data[i]);
80 }
81 setenv ("keybd", keybd_env);
82
83 str = strdup ((char *)key_match (kbd_data)); /* decode keys */
84
85# ifdef CONFIG_PREBOOT /* automatically configure "preboot" command on key match */
86 setenv ("preboot", str); /* set or delete definition */
87# endif /* CONFIG_PREBOOT */
88 if (str != NULL) {
89 free (str);
90 }
91#endif /* DELTA_CHECK_KEYBD */
92
Markus Klotzbuecherba70d6a2006-03-24 12:23:27 +010093 init_DA9030();
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +010094 return 0;
95}
96
Markus Klotzbuecher71ae4112006-04-25 10:03:01 +020097/*
98 * Magic Key Handling, mainly copied from board/lwmon/lwmon.c
99 */
100#ifdef DELTA_CHECK_KEYBD
101
102static uchar kbd_magic_prefix[] = "key_magic";
103static uchar kbd_command_prefix[] = "key_cmd";
104
105/*
106 * Get pressed keys
107 * s is a buffer of size KEYBD_DATALEN-1
108 */
109static void get_pressed_keys(uchar *s)
110{
111 unsigned long val;
112 val = GPLR3;
113
114 if(val & (1<<31))
115 *s++ = KEYBD_KP_DKIN0;
116 if(val & (1<<18))
117 *s++ = KEYBD_KP_DKIN1;
118 if(val & (1<<29))
119 *s++ = KEYBD_KP_DKIN2;
120 if(val & (1<<22))
121 *s++ = KEYBD_KP_DKIN5;
122}
123
124static void keys_init()
125{
126 CKENB |= CKENB_7_GPIO;
127 udelay(100);
128
129 /* Configure GPIOs */
130 GPIO127 = 0xa840; /* KP_DKIN0 */
131 GPIO114 = 0xa840; /* KP_DKIN1 */
132 GPIO125 = 0xa840; /* KP_DKIN2 */
133 GPIO118 = 0xa840; /* KP_DKIN5 */
134
135 /* Configure GPIOs as inputs */
136 GPDR3 &= ~(1<<31 | 1<<18 | 1<<29 | 1<<22);
137 GCDR3 = (1<<31 | 1<<18 | 1<<29 | 1<<22);
138
139 udelay(100);
140}
141
142static int compare_magic (uchar *kbd_data, uchar *str)
143{
144 /* uchar compare[KEYBD_DATALEN-1]; */
145 uchar compare[KEYBD_DATALEN];
146 char *nxt;
147 int i;
148
149 /* Don't include modifier byte */
150 /* memcpy (compare, kbd_data+1, KEYBD_DATALEN-1); */
151 memcpy (compare, kbd_data, KEYBD_DATALEN);
152
153 for (; str != NULL; str = (*nxt) ? (uchar *)(nxt+1) : (uchar *)nxt) {
154 uchar c;
155 int k;
156
157 c = (uchar) simple_strtoul ((char *)str, (char **) (&nxt), 16);
158
159 if (str == (uchar *)nxt) { /* invalid character */
160 break;
161 }
162
163 /*
164 * Check if this key matches the input.
165 * Set matches to zero, so they match only once
166 * and we can find duplicates or extra keys
167 */
168 for (k = 0; k < sizeof(compare); ++k) {
169 if (compare[k] == '\0') /* only non-zero entries */
170 continue;
171 if (c == compare[k]) { /* found matching key */
172 compare[k] = '\0';
173 break;
174 }
175 }
176 if (k == sizeof(compare)) {
177 return -1; /* unmatched key */
178 }
179 }
180
181 /*
182 * A full match leaves no keys in the `compare' array,
183 */
184 for (i = 0; i < sizeof(compare); ++i) {
185 if (compare[i])
186 {
187 return -1;
188 }
189 }
190
191 return 0;
192}
193
194
195static uchar *key_match (uchar *kbd_data)
196{
197 char magic[sizeof (kbd_magic_prefix) + 1];
198 uchar *suffix;
199 char *kbd_magic_keys;
200
201 /*
202 * The following string defines the characters that can pe appended
203 * to "key_magic" to form the names of environment variables that
204 * hold "magic" key codes, i. e. such key codes that can cause
205 * pre-boot actions. If the string is empty (""), then only
206 * "key_magic" is checked (old behaviour); the string "125" causes
207 * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
208 */
209 if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
210 kbd_magic_keys = "";
211
212 /* loop over all magic keys;
213 * use '\0' suffix in case of empty string
214 */
215 for (suffix=(uchar *)kbd_magic_keys; *suffix || suffix==(uchar *)kbd_magic_keys; ++suffix) {
216 sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
217#if 0
218 printf ("### Check magic \"%s\"\n", magic);
219#endif
220 if (compare_magic(kbd_data, (uchar *)getenv(magic)) == 0) {
221 char cmd_name[sizeof (kbd_command_prefix) + 1];
222 char *cmd;
223
224 sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
225
226 cmd = getenv (cmd_name);
227#if 0
228 printf ("### Set PREBOOT to $(%s): \"%s\"\n",
229 cmd_name, cmd ? cmd : "<<NULL>>");
230#endif
231 *kbd_data = *suffix;
232 return ((uchar *)cmd);
233 }
234 }
235#if 0
236 printf ("### Delete PREBOOT\n");
237#endif
238 *kbd_data = '\0';
239 return (NULL);
240}
241
242int do_kbd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
243{
244 uchar kbd_data[KEYBD_DATALEN];
245 char keybd_env[2 * KEYBD_DATALEN + 1];
246 int i;
247
248 /* Read keys */
249 get_pressed_keys(kbd_data);
250 puts ("Keys:");
251 for (i = 0; i < KEYBD_DATALEN; ++i) {
252 sprintf (keybd_env + i + i, "%02X", kbd_data[i]);
253 printf (" %02x", kbd_data[i]);
254 }
255 putc ('\n');
256 setenv ("keybd", keybd_env);
257 return 0;
258}
259
260U_BOOT_CMD(
261 kbd, 1, 1, do_kbd,
Peter Tyser2fb26042009-01-27 18:03:12 -0600262 "read keyboard status",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200263 ""
Markus Klotzbuecher71ae4112006-04-25 10:03:01 +0200264);
265
266#endif /* DELTA_CHECK_KEYBD */
267
268
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100269int dram_init (void)
270{
Markus Klotzbücher4f7a0e32006-02-20 16:37:37 +0100271 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
272 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
273 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
274 gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
275 gd->bd->bi_dram[2].start = PHYS_SDRAM_3;
276 gd->bd->bi_dram[2].size = PHYS_SDRAM_3_SIZE;
277 gd->bd->bi_dram[3].start = PHYS_SDRAM_4;
278 gd->bd->bi_dram[3].size = PHYS_SDRAM_4_SIZE;
279
280 return 0;
281}
Markus Klotzbuecherba70d6a2006-03-24 12:23:27 +0100282
Markus Klotzbuecher9e7b5ce2006-03-30 17:00:39 +0200283void i2c_init_board()
284{
285 CKENB |= (CKENB_4_I2C);
286
287 /* setup I2C GPIO's */
288 GPIO32 = 0x801; /* SCL = Alt. Fkt. 1 */
289 GPIO33 = 0x801; /* SDA = Alt. Fkt. 1 */
290}
291
Markus Klotzbuecherba70d6a2006-03-24 12:23:27 +0100292/* initialize the DA9030 Power Controller */
293static void init_DA9030()
294{
295 uchar addr = (uchar) DA9030_I2C_ADDR, val = 0;
296
Markus Klotzbuecher9e7b5ce2006-03-30 17:00:39 +0200297 CKENB |= CKENB_7_GPIO;
298 udelay(100);
Markus Klotzbuecherba70d6a2006-03-24 12:23:27 +0100299
Markus Klotzbuecher9e7b5ce2006-03-30 17:00:39 +0200300 /* Rising Edge on EXTON to reset DA9030 */
301 GPIO17 = 0x8800; /* configure GPIO17, no pullup, -down */
Markus Klotzbuecherc855ef62006-03-27 16:01:03 +0200302 GPDR0 |= (1<<17); /* GPIO17 is output */
303 GSDR0 = (1<<17);
304 GPCR0 = (1<<17); /* drive GPIO17 low */
Markus Klotzbuecherc855ef62006-03-27 16:01:03 +0200305 GPSR0 = (1<<17); /* drive GPIO17 high */
Markus Klotzbuecher9e7b5ce2006-03-30 17:00:39 +0200306
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200307#if CONFIG_SYS_DA9030_EXTON_DELAY
308 udelay((unsigned long) CONFIG_SYS_DA9030_EXTON_DELAY); /* wait for DA9030 */
Markus Klotzbuecherc855ef62006-03-27 16:01:03 +0200309#endif
310 GPCR0 = (1<<17); /* drive GPIO17 low */
Markus Klotzbuecherba70d6a2006-03-24 12:23:27 +0100311
312 /* reset the watchdog and go active (0xec) */
313 val = (SYS_CONTROL_A_HWRES_ENABLE |
314 (0x6<<4) |
315 SYS_CONTROL_A_WDOG_ACTION |
316 SYS_CONTROL_A_WATCHDOG);
Markus Klotzbuecher89f2dfa2006-03-29 17:49:27 +0200317 if(i2c_write(addr, SYS_CONTROL_A, 1, &val, 1)) {
318 printf("Error accessing DA9030 via i2c.\n");
319 return;
320 }
Markus Klotzbuecherba70d6a2006-03-24 12:23:27 +0100321
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +0200322 val = 0x80;
323 if(i2c_write(addr, IRQ_MASK_B, 1, &val, 1)) {
324 printf("Error accessing DA9030 via i2c.\n");
325 return;
326 }
327
Markus Klotzbuecherba70d6a2006-03-24 12:23:27 +0100328 i2c_reg_write(addr, REG_CONTROL_1_97, 0xfd); /* disable LDO1, enable LDO6 */
329 i2c_reg_write(addr, LDO2_3, 0xd1); /* LDO2 =1,9V, LDO3=3,1V */
330 i2c_reg_write(addr, LDO4_5, 0xcc); /* LDO2 =1,9V, LDO3=3,1V */
Markus Klotzbuecher9e7b5ce2006-03-30 17:00:39 +0200331 i2c_reg_write(addr, LDO6_SIMCP, 0x3e); /* LDO6=3,2V, SIMCP = 5V support */
Markus Klotzbuecherba70d6a2006-03-24 12:23:27 +0100332 i2c_reg_write(addr, LDO7_8, 0xc9); /* LDO7=2,7V, LDO8=3,0V */
333 i2c_reg_write(addr, LDO9_12, 0xec); /* LDO9=3,0V, LDO12=3,2V */
Markus Klotzbuecher9e7b5ce2006-03-30 17:00:39 +0200334 i2c_reg_write(addr, BUCK, 0x0c); /* Buck=1.2V */
Markus Klotzbuecherba70d6a2006-03-24 12:23:27 +0100335 i2c_reg_write(addr, REG_CONTROL_2_98, 0x7f); /* All LDO'S on 8,9,10,11,12,14 */
Markus Klotzbuecher9e7b5ce2006-03-30 17:00:39 +0200336 i2c_reg_write(addr, LDO_10_11, 0xcc); /* LDO10=3.0V LDO11=3.0V */
Markus Klotzbuecherba70d6a2006-03-24 12:23:27 +0100337 i2c_reg_write(addr, LDO_15, 0xae); /* LDO15=1.8V, dislock first 3bit */
Markus Klotzbuecher9e7b5ce2006-03-30 17:00:39 +0200338 i2c_reg_write(addr, LDO_14_16, 0x05); /* LDO14=2.8V, LDO16=NB */
Markus Klotzbuecherba70d6a2006-03-24 12:23:27 +0100339 i2c_reg_write(addr, LDO_18_19, 0x9c); /* LDO18=3.0V, LDO19=2.7V */
340 i2c_reg_write(addr, LDO_17_SIMCP0, 0x2c); /* LDO17=3.0V, SIMCP=3V support */
341 i2c_reg_write(addr, BUCK2_DVC1, 0x9a); /* Buck2=1.5V plus Update support of 520 MHz */
342 i2c_reg_write(addr, REG_CONTROL_2_18, 0x43); /* Ball on */
343 i2c_reg_write(addr, MISC_CONTROLB, 0x08); /* session valid enable */
344 i2c_reg_write(addr, USBPUMP, 0xc1); /* start pump, ignore HW signals */
345
346 val = i2c_reg_read(addr, STATUS);
347 if(val & STATUS_CHDET)
348 printf("Charger detected, turning on LED.\n");
349 else {
350 printf("No charger detetected.\n");
351 /* undervoltage? print error and power down */
352 }
353}
354
355
356#if 0
357/* reset the DA9030 watchdog */
358void hw_watchdog_reset(void)
359{
360 uchar addr = (uchar) DA9030_I2C_ADDR, val = 0;
361 val = i2c_reg_read(addr, SYS_CONTROL_A);
362 val |= SYS_CONTROL_A_WATCHDOG;
363 i2c_reg_write(addr, SYS_CONTROL_A, val);
364}
365#endif