3 * DENX Software Engineering
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
29 #include <asm/arch/pxa-regs.h>
31 DECLARE_GLOBAL_DATA_PTR
;
33 /* ------------------------------------------------------------------------- */
35 static void init_DA9030(void);
36 static void keys_init(void);
37 static void get_pressed_keys(uchar
*s
);
38 static uchar
*key_match(uchar
*kbd_data
);
41 * Miscelaneous platform dependent initialisations
46 /* memory and cpu-speed are setup before relocation */
47 /* so we do _nothing_ here */
49 /* arch number of Lubbock-Board mk@tbd: fix this! */
50 gd
->bd
->bi_arch_number
= MACH_TYPE_LUBBOCK
;
52 /* adress of boot parameters */
53 gd
->bd
->bi_boot_params
= 0xa0000100;
58 int board_late_init(void)
60 #ifdef DELTA_CHECK_KEYBD
61 uchar kbd_data
[KEYBD_DATALEN
];
62 char keybd_env
[2 * KEYBD_DATALEN
+ 1];
65 #endif /* DELTA_CHECK_KEYBD */
67 setenv("stdout", "serial");
68 setenv("stderr", "serial");
70 #ifdef DELTA_CHECK_KEYBD
73 memset(kbd_data
, '\0', KEYBD_DATALEN
);
75 /* check for pressed keys and setup keybd_env */
76 get_pressed_keys(kbd_data
);
78 for (i
= 0; i
< KEYBD_DATALEN
; ++i
) {
79 sprintf (keybd_env
+ i
+ i
, "%02X", kbd_data
[i
]);
81 setenv ("keybd", keybd_env
);
83 str
= strdup ((char *)key_match (kbd_data
)); /* decode keys */
85 # ifdef CONFIG_PREBOOT /* automatically configure "preboot" command on key match */
86 setenv ("preboot", str
); /* set or delete definition */
87 # endif /* CONFIG_PREBOOT */
91 #endif /* DELTA_CHECK_KEYBD */
98 * Magic Key Handling, mainly copied from board/lwmon/lwmon.c
100 #ifdef DELTA_CHECK_KEYBD
102 static uchar kbd_magic_prefix
[] = "key_magic";
103 static uchar kbd_command_prefix
[] = "key_cmd";
107 * s is a buffer of size KEYBD_DATALEN-1
109 static void get_pressed_keys(uchar
*s
)
115 *s
++ = KEYBD_KP_DKIN0
;
117 *s
++ = KEYBD_KP_DKIN1
;
119 *s
++ = KEYBD_KP_DKIN2
;
121 *s
++ = KEYBD_KP_DKIN5
;
124 static void keys_init()
126 CKENB
|= CKENB_7_GPIO
;
129 /* Configure GPIOs */
130 GPIO127
= 0xa840; /* KP_DKIN0 */
131 GPIO114
= 0xa840; /* KP_DKIN1 */
132 GPIO125
= 0xa840; /* KP_DKIN2 */
133 GPIO118
= 0xa840; /* KP_DKIN5 */
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);
142 static int compare_magic (uchar
*kbd_data
, uchar
*str
)
144 /* uchar compare[KEYBD_DATALEN-1]; */
145 uchar compare
[KEYBD_DATALEN
];
149 /* Don't include modifier byte */
150 /* memcpy (compare, kbd_data+1, KEYBD_DATALEN-1); */
151 memcpy (compare
, kbd_data
, KEYBD_DATALEN
);
153 for (; str
!= NULL
; str
= (*nxt
) ? (uchar
*)(nxt
+1) : (uchar
*)nxt
) {
157 c
= (uchar
) simple_strtoul ((char *)str
, (char **) (&nxt
), 16);
159 if (str
== (uchar
*)nxt
) { /* invalid character */
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
168 for (k
= 0; k
< sizeof(compare
); ++k
) {
169 if (compare
[k
] == '\0') /* only non-zero entries */
171 if (c
== compare
[k
]) { /* found matching key */
176 if (k
== sizeof(compare
)) {
177 return -1; /* unmatched key */
182 * A full match leaves no keys in the `compare' array,
184 for (i
= 0; i
< sizeof(compare
); ++i
) {
195 static uchar
*key_match (uchar
*kbd_data
)
197 char magic
[sizeof (kbd_magic_prefix
) + 1];
199 char *kbd_magic_keys
;
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.
209 if ((kbd_magic_keys
= getenv ("magic_keys")) == NULL
)
212 /* loop over all magic keys;
213 * use '\0' suffix in case of empty string
215 for (suffix
=(uchar
*)kbd_magic_keys
; *suffix
|| suffix
==(uchar
*)kbd_magic_keys
; ++suffix
) {
216 sprintf (magic
, "%s%c", kbd_magic_prefix
, *suffix
);
218 printf ("### Check magic \"%s\"\n", magic
);
220 if (compare_magic(kbd_data
, (uchar
*)getenv(magic
)) == 0) {
221 char cmd_name
[sizeof (kbd_command_prefix
) + 1];
224 sprintf (cmd_name
, "%s%c", kbd_command_prefix
, *suffix
);
226 cmd
= getenv (cmd_name
);
228 printf ("### Set PREBOOT to $(%s): \"%s\"\n",
229 cmd_name
, cmd
? cmd
: "<<NULL>>");
232 return ((uchar
*)cmd
);
236 printf ("### Delete PREBOOT\n");
242 int do_kbd (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
244 uchar kbd_data
[KEYBD_DATALEN
];
245 char keybd_env
[2 * KEYBD_DATALEN
+ 1];
249 get_pressed_keys(kbd_data
);
251 for (i
= 0; i
< KEYBD_DATALEN
; ++i
) {
252 sprintf (keybd_env
+ i
+ i
, "%02X", kbd_data
[i
]);
253 printf (" %02x", kbd_data
[i
]);
256 setenv ("keybd", keybd_env
);
262 "kbd - read keyboard status\n",
266 #endif /* DELTA_CHECK_KEYBD */
271 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
;
283 void i2c_init_board()
285 CKENB
|= (CKENB_4_I2C
);
287 /* setup I2C GPIO's */
288 GPIO32
= 0x801; /* SCL = Alt. Fkt. 1 */
289 GPIO33
= 0x801; /* SDA = Alt. Fkt. 1 */
292 /* initialize the DA9030 Power Controller */
293 static void init_DA9030()
295 uchar addr
= (uchar
) DA9030_I2C_ADDR
, val
= 0;
297 CKENB
|= CKENB_7_GPIO
;
300 /* Rising Edge on EXTON to reset DA9030 */
301 GPIO17
= 0x8800; /* configure GPIO17, no pullup, -down */
302 GPDR0
|= (1<<17); /* GPIO17 is output */
304 GPCR0
= (1<<17); /* drive GPIO17 low */
305 GPSR0
= (1<<17); /* drive GPIO17 high */
307 #if CFG_DA9030_EXTON_DELAY
308 udelay((unsigned long) CFG_DA9030_EXTON_DELAY
); /* wait for DA9030 */
310 GPCR0
= (1<<17); /* drive GPIO17 low */
312 /* reset the watchdog and go active (0xec) */
313 val
= (SYS_CONTROL_A_HWRES_ENABLE
|
315 SYS_CONTROL_A_WDOG_ACTION
|
316 SYS_CONTROL_A_WATCHDOG
);
317 if(i2c_write(addr
, SYS_CONTROL_A
, 1, &val
, 1)) {
318 printf("Error accessing DA9030 via i2c.\n");
323 if(i2c_write(addr
, IRQ_MASK_B
, 1, &val
, 1)) {
324 printf("Error accessing DA9030 via i2c.\n");
328 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 */
331 i2c_reg_write(addr
, LDO6_SIMCP
, 0x3e); /* LDO6=3,2V, SIMCP = 5V support */
332 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 */
334 i2c_reg_write(addr
, BUCK
, 0x0c); /* Buck=1.2V */
335 i2c_reg_write(addr
, REG_CONTROL_2_98
, 0x7f); /* All LDO'S on 8,9,10,11,12,14 */
336 i2c_reg_write(addr
, LDO_10_11
, 0xcc); /* LDO10=3.0V LDO11=3.0V */
337 i2c_reg_write(addr
, LDO_15
, 0xae); /* LDO15=1.8V, dislock first 3bit */
338 i2c_reg_write(addr
, LDO_14_16
, 0x05); /* LDO14=2.8V, LDO16=NB */
339 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 */
346 val
= i2c_reg_read(addr
, STATUS
);
347 if(val
& STATUS_CHDET
)
348 printf("Charger detected, turning on LED.\n");
350 printf("No charger detetected.\n");
351 /* undervoltage? print error and power down */
357 /* reset the DA9030 watchdog */
358 void hw_watchdog_reset(void)
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
);