2 * (C) Copyright 2009 Wolfgang Denk <wd@denx.de>
3 * (C) Copyright 2009 Dave Srl www.dave.eu
4 * (C) Copyright 2010 ifm ecomatic GmbH
6 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/bitops.h>
13 #include <asm/processor.h>
14 #include <asm/mpc512x.h>
15 #include <fdt_support.h>
16 #ifdef CONFIG_MISC_INIT_R
23 DECLARE_GLOBAL_DATA_PTR;
25 static void gpio_configure(void)
30 im = (immap_t *) CONFIG_SYS_IMMR;
32 out_be32(&gpioregs->gpodr, 0x00290000); /* open drain */
33 out_be32(&gpioregs->gpdat, 0x80001040); /* data (when output) */
36 * out_be32(&gpioregs->gpdir, 0xC2293020);
37 * workaround for a hardware effect: configure direction in pieces,
38 * setting all outputs at once drops the reset line too low and
39 * makes us lose the MII connection (breaks ethernet for us)
41 out_be32(&gpioregs->gpdir, 0x02003060); /* direction */
42 setbits_be32(&gpioregs->gpdir, 0x00200000); /* += reset asi */
44 setbits_be32(&gpioregs->gpdir, 0x00080000); /* += reset safety */
46 setbits_be32(&gpioregs->gpdir, 0x00010000); /* += reset comm */
48 setbits_be32(&gpioregs->gpdir, 0xC0000000); /* += backlight, KB sel */
50 /* to turn from red to yellow when U-Boot runs */
51 setbits_be32(&gpioregs->gpdat, 0x00002020);
52 out_be32(&gpioregs->gpimr, 0x00000000); /* interrupt mask */
53 out_be32(&gpioregs->gpicr1, 0x00000004); /* interrupt sense part 1 */
54 out_be32(&gpioregs->gpicr2, 0x00A80000); /* interrupt sense part 2 */
55 out_be32(&gpioregs->gpier, 0xFFFFFFFF); /* interrupt events, clear */
58 /* the physical location of the pins */
59 #define GPIOKEY_ROW_BITMASK 0x40000000
60 #define GPIOKEY_ROW_UPPER 0
61 #define GPIOKEY_ROW_LOWER 1
63 #define GPIOKEY_COL0_BITMASK 0x20000000
64 #define GPIOKEY_COL1_BITMASK 0x10000000
65 #define GPIOKEY_COL2_BITMASK 0x08000000
67 /* the logical presentation of pressed keys */
68 #define GPIOKEY_BIT_FNLEFT (1 << 5)
69 #define GPIOKEY_BIT_FNRIGHT (1 << 4)
70 #define GPIOKEY_BIT_DIRUP (1 << 3)
71 #define GPIOKEY_BIT_DIRLEFT (1 << 2)
72 #define GPIOKEY_BIT_DIRRIGHT (1 << 1)
73 #define GPIOKEY_BIT_DIRDOWN (1 << 0)
75 /* the hotkey combination which starts recovery */
76 #define GPIOKEY_BITS_RECOVERY (GPIOKEY_BIT_FNLEFT | GPIOKEY_BIT_DIRUP | \
79 static void gpio_selectrow(gpio512x_t *gpioregs, u32 row)
83 setbits_be32(&gpioregs->gpdat, GPIOKEY_ROW_BITMASK);
85 clrbits_be32(&gpioregs->gpdat, GPIOKEY_ROW_BITMASK);
89 static u32 gpio_querykbd(void)
96 im = (immap_t *)CONFIG_SYS_IMMR;
100 /* query upper row */
101 gpio_selectrow(gpioregs, GPIOKEY_ROW_UPPER);
102 input = in_be32(&gpioregs->gpdat);
103 if ((input & GPIOKEY_COL0_BITMASK) == 0)
104 keybits |= GPIOKEY_BIT_FNLEFT;
105 if ((input & GPIOKEY_COL1_BITMASK) == 0)
106 keybits |= GPIOKEY_BIT_DIRUP;
107 if ((input & GPIOKEY_COL2_BITMASK) == 0)
108 keybits |= GPIOKEY_BIT_FNRIGHT;
110 /* query lower row */
111 gpio_selectrow(gpioregs, GPIOKEY_ROW_LOWER);
112 input = in_be32(&gpioregs->gpdat);
113 if ((input & GPIOKEY_COL0_BITMASK) == 0)
114 keybits |= GPIOKEY_BIT_DIRLEFT;
115 if ((input & GPIOKEY_COL1_BITMASK) == 0)
116 keybits |= GPIOKEY_BIT_DIRRIGHT;
117 if ((input & GPIOKEY_COL2_BITMASK) == 0)
118 keybits |= GPIOKEY_BIT_DIRDOWN;
120 /* return bit pattern for keys */
124 /* excerpt from the recovery's hw_info.h */
126 struct __attribute__ ((__packed__)) eeprom_layout {
127 char magic[3]; /** 'ifm' */
128 u8 len[2]; /** content length without magic/len fields */
129 u8 version[3]; /** structure version */
130 u8 type; /** type of PCB */
131 u8 reserved[0x37]; /** padding up to offset 0x40 */
132 u8 macaddress[6]; /** ethernet MAC (for the mainboard) @0x40 */
135 #define HW_COMP_MAINCPU 2
137 static struct eeprom_layout eeprom_content;
138 static int eeprom_is_valid;
139 static int eeprom_version;
141 #define get_eeprom_field_int(name) ({ \
145 for (idx = 0; idx < sizeof(name); idx++) { \
147 value |= name[idx]; \
152 static int read_eeprom(void)
157 int mac_read_from_eeprom(void)
163 printf("I2C EEPROM read failed.\n");
167 if (!eeprom_is_valid) {
168 printf("I2C EEPROM content not valid\n");
173 switch (eeprom_version) {
176 mac = (const u8 *)&eeprom_content.macaddress;
180 if (mac && is_valid_ethaddr(mac)) {
181 eth_setenv_enetaddr("ethaddr", mac);
183 mac_txt = getenv("ethaddr");
185 printf("DIAG: MAC value [%s]\n", mac_txt);
187 printf("DIAG: failed to setup MAC env\n");
196 * this board uses DDR1(!) Micron SDRAM, *NOT* the DDR2
197 * which the ADS, Aria or PDM360NG boards are using
198 * (the steps outlined here refer to the Micron datasheet)
200 u32 sdram_init_seq[] = {
201 /* item 6, at least one NOP after CKE went high */
202 CONFIG_SYS_DDRCMD_NOP,
203 CONFIG_SYS_DDRCMD_NOP,
204 CONFIG_SYS_DDRCMD_NOP,
205 CONFIG_SYS_DDRCMD_NOP,
206 CONFIG_SYS_DDRCMD_NOP,
207 CONFIG_SYS_DDRCMD_NOP,
208 CONFIG_SYS_DDRCMD_NOP,
209 CONFIG_SYS_DDRCMD_NOP,
210 CONFIG_SYS_DDRCMD_NOP,
211 CONFIG_SYS_DDRCMD_NOP,
212 /* item 7, precharge all; item 8, tRP (20ns) */
213 CONFIG_SYS_DDRCMD_PCHG_ALL,
214 CONFIG_SYS_DDRCMD_NOP,
215 /* item 9, extended mode register; item 10, tMRD 10ns) */
216 CONFIG_SYS_MICRON_EMODE | CONFIG_SYS_MICRON_EMODE_PARAM,
217 CONFIG_SYS_DDRCMD_NOP,
219 * item 11, (base) mode register _with_ reset DLL;
220 * item 12, tMRD (10ns)
222 CONFIG_SYS_MICRON_BMODE | CONFIG_SYS_MICRON_BMODE_RSTDLL |
223 CONFIG_SYS_MICRON_BMODE_PARAM,
224 CONFIG_SYS_DDRCMD_NOP,
225 /* item 13, precharge all; item 14, tRP (20ns) */
226 CONFIG_SYS_DDRCMD_PCHG_ALL,
227 CONFIG_SYS_DDRCMD_NOP,
229 * item 15, auto refresh (i.e. refresh with CKE held high);
230 * item 16, tRFC (70ns)
232 CONFIG_SYS_DDRCMD_RFSH,
233 CONFIG_SYS_DDRCMD_NOP,
234 CONFIG_SYS_DDRCMD_NOP,
235 CONFIG_SYS_DDRCMD_NOP,
236 CONFIG_SYS_DDRCMD_NOP,
237 CONFIG_SYS_DDRCMD_NOP,
238 CONFIG_SYS_DDRCMD_NOP,
239 CONFIG_SYS_DDRCMD_NOP,
240 CONFIG_SYS_DDRCMD_NOP,
242 * item 17, auto refresh (i.e. refresh with CKE held high);
243 * item 18, tRFC (70ns)
245 CONFIG_SYS_DDRCMD_RFSH,
246 CONFIG_SYS_DDRCMD_NOP,
247 CONFIG_SYS_DDRCMD_NOP,
248 CONFIG_SYS_DDRCMD_NOP,
249 CONFIG_SYS_DDRCMD_NOP,
250 CONFIG_SYS_DDRCMD_NOP,
251 CONFIG_SYS_DDRCMD_NOP,
252 CONFIG_SYS_DDRCMD_NOP,
253 CONFIG_SYS_DDRCMD_NOP,
254 /* item 19, optional, unassert DLL reset; item 20, tMRD (20ns) */
255 CONFIG_SYS_MICRON_BMODE | CONFIG_SYS_MICRON_BMODE_PARAM,
256 CONFIG_SYS_DDRCMD_NOP,
258 * item 21, "actually done", but make sure 200 DRAM clock cycles
259 * have passed after DLL reset before READ requests are issued
260 * (200 cycles at 160MHz -> 1.25 usec)
262 /* EMPTY, optional, we don't do it */
267 gd->ram_size = fixed_sdram(NULL, sdram_init_seq,
268 ARRAY_SIZE(sdram_init_seq));
273 int misc_init_r(void)
279 /* setup GPIO directions and initial values */
283 * enforce the start of the recovery system when
284 * - the appropriate keys were pressed
285 * - "some" external software told us to
286 * - a previous installation was aborted or has failed
289 keys = gpio_querykbd();
291 printf("GPIO keyboard status [0x%02X]\n", keys);
292 if ((keys & GPIOKEY_BITS_RECOVERY) == GPIOKEY_BITS_RECOVERY) {
293 printf("detected recovery request (keyboard)\n");
296 s = getenv("want_recovery");
297 if ((s != NULL) && (*s != '\0')) {
298 printf("detected recovery request (environment)\n");
301 s = getenv("install_in_progress");
302 if ((s != NULL) && (*s != '\0')) {
303 printf("previous installation has not completed\n");
306 s = getenv("install_failed");
307 if ((s != NULL) && (*s != '\0')) {
308 printf("previous installation has failed\n");
312 printf("enforced start of the recovery system\n");
313 setenv("bootcmd", "run recovery");
317 * boot the recovery system without waiting; boot the
318 * production system without waiting by default, only
319 * insert a pause (to provide a chance to get a prompt)
320 * when GPIO keys were pressed during power on
323 setenv("bootdelay", "0");
325 setenv("bootdelay", "0");
327 setenv("bootdelay", "2");
329 /* get the ethernet MAC from I2C EEPROM */
330 mac_read_from_eeprom();
335 /* setup specific IO pad configuration */
336 static iopin_t ioregs_init[] = {
338 offsetof(struct ioctrl512x, io_control_nfc_ce0), 1,
339 IO_PIN_OVER_FMUX | IO_PIN_OVER_DRVSTR,
340 IO_PIN_FMUX(1) | IO_PIN_DS(2),
343 offsetof(struct ioctrl512x, io_control_lpc_cs1), 1,
348 offsetof(struct ioctrl512x, io_control_lpc_cs2), 1,
353 offsetof(struct ioctrl512x, io_control_pata_ce1), 2,
354 IO_PIN_OVER_FMUX | IO_PIN_OVER_DRVSTR,
355 IO_PIN_FMUX(1) | IO_PIN_DS(2),
357 { /* SDHC CLK, CMD, D0, D1, D2, D3 */
358 offsetof(struct ioctrl512x, io_control_pata_ior), 6,
359 IO_PIN_OVER_FMUX | IO_PIN_OVER_DRVSTR,
360 IO_PIN_FMUX(1) | IO_PIN_DS(2),
362 { /* GPIO keyboard */
363 offsetof(struct ioctrl512x, io_control_pci_ad30), 4,
367 { /* GPIO DN1 PF, LCD power, DN2 PF */
368 offsetof(struct ioctrl512x, io_control_pci_ad26), 3,
372 { /* GPIO reset AS-i */
373 offsetof(struct ioctrl512x, io_control_pci_ad21), 1,
377 { /* GPIO reset safety */
378 offsetof(struct ioctrl512x, io_control_pci_ad19), 1,
382 { /* GPIO reset netX */
383 offsetof(struct ioctrl512x, io_control_pci_ad16), 1,
388 offsetof(struct ioctrl512x, io_control_pci_ad15), 1,
392 { /* GPIO SD CD, SD WP */
393 offsetof(struct ioctrl512x, io_control_pci_ad08), 2,
398 offsetof(struct ioctrl512x, io_control_pci_ad06), 1,
399 IO_PIN_OVER_FMUX | IO_PIN_OVER_DRVSTR,
400 IO_PIN_FMUX(2) | IO_PIN_DS(2),
402 { /* GPIO AS-i prog, AS-i done, LCD backlight */
403 offsetof(struct ioctrl512x, io_control_pci_ad05), 3,
407 { /* GPIO AS-i wdg */
408 offsetof(struct ioctrl512x, io_control_pci_req2), 1,
412 { /* GPIO safety wdg */
413 offsetof(struct ioctrl512x, io_control_pci_req1), 1,
417 { /* GPIO netX wdg */
418 offsetof(struct ioctrl512x, io_control_pci_req0), 1,
422 { /* GPIO IRQ powerfail */
423 offsetof(struct ioctrl512x, io_control_pci_inta), 1,
427 { /* GPIO AS-i PWRD */
428 offsetof(struct ioctrl512x, io_control_pci_frame), 1,
432 { /* GPIO LED0, LED1 */
433 offsetof(struct ioctrl512x, io_control_pci_idsel), 2,
437 { /* GPIO IRQ AS-i 1, IRQ AS-i 2, IRQ safety */
438 offsetof(struct ioctrl512x, io_control_pci_irdy), 3,
443 offsetof(struct ioctrl512x, io_control_spdif_txclk), 1,
444 IO_PIN_OVER_FMUX | IO_PIN_OVER_DRVSTR,
445 IO_PIN_FMUX(2) | IO_PIN_DS(2),
447 { /* FEC TX ER, CRS */
448 offsetof(struct ioctrl512x, io_control_spdif_tx), 2,
449 IO_PIN_OVER_FMUX | IO_PIN_OVER_DRVSTR,
450 IO_PIN_FMUX(1) | IO_PIN_DS(2),
452 { /* GPIO/GPT */ /* to *NOT* have the EXT IRQ0 float */
453 offsetof(struct ioctrl512x, io_control_irq0), 1,
458 * FEC col, tx en, tx clk, txd 0-3, mdc, rx er,
459 * rdx 3-0, mdio, rx clk
461 offsetof(struct ioctrl512x, io_control_psc0_0), 15,
462 IO_PIN_OVER_FMUX | IO_PIN_OVER_DRVSTR,
463 IO_PIN_FMUX(1) | IO_PIN_DS(2),
465 /* optional: make sure PSC3 remains the serial console */
467 offsetof(struct ioctrl512x, io_control_psc3_4), 1,
468 IO_PIN_OVER_FMUX | IO_PIN_OVER_DRVSTR,
469 IO_PIN_FMUX(1) | IO_PIN_DS(2),
471 /* make sure PSC4 remains available for SPI,
472 *BUT* PSC4_1 is a GPIO kind of SS! */
473 { /* enforce drive strength on the SPI pin */
474 offsetof(struct ioctrl512x, io_control_psc4_0), 5,
479 offsetof(struct ioctrl512x, io_control_psc4_1), 1,
483 /* optional: make sure PSC5 remains available for SPI */
484 { /* enforce drive strength on the SPI pin */
485 offsetof(struct ioctrl512x, io_control_psc5_0), 5,
490 offsetof(struct ioctrl512x, io_control_psc6_0), 1,
491 IO_PIN_OVER_FMUX | IO_PIN_OVER_DRVSTR,
492 IO_PIN_FMUX(1) | IO_PIN_DS(2),
495 offsetof(struct ioctrl512x, io_control_psc6_1), 1,
496 IO_PIN_OVER_FMUX | IO_PIN_OVER_DRVSTR,
497 IO_PIN_FMUX(2) | IO_PIN_DS(1),
500 offsetof(struct ioctrl512x, io_control_psc6_4), 1,
501 IO_PIN_OVER_FMUX | IO_PIN_OVER_DRVSTR,
502 IO_PIN_FMUX(2) | IO_PIN_DS(1),
504 { /* PSC7, part of DIU RGB */
505 offsetof(struct ioctrl512x, io_control_psc7_0), 2,
506 IO_PIN_OVER_FMUX | IO_PIN_OVER_DRVSTR,
507 IO_PIN_FMUX(2) | IO_PIN_DS(1),
509 { /* PSC7, safety UART */
510 offsetof(struct ioctrl512x, io_control_psc7_2), 2,
511 IO_PIN_OVER_FMUX | IO_PIN_OVER_DRVSTR,
512 IO_PIN_FMUX(0) | IO_PIN_DS(1),
514 { /* DIU (part of) RGB[] */
515 offsetof(struct ioctrl512x, io_control_psc8_3), 16,
516 IO_PIN_OVER_FMUX | IO_PIN_OVER_DRVSTR,
517 IO_PIN_FMUX(2) | IO_PIN_DS(1),
519 { /* DIU data enable */
520 offsetof(struct ioctrl512x, io_control_psc11_4), 1,
521 IO_PIN_OVER_FMUX | IO_PIN_OVER_DRVSTR,
522 IO_PIN_FMUX(2) | IO_PIN_DS(1),
524 /* reduce LPB drive strength for improved EMI */
525 { /* LPC OE, LPC RW */
526 offsetof(struct ioctrl512x, io_control_lpc_oe), 2,
530 { /* LPC AX03 through LPC AD00 */
531 offsetof(struct ioctrl512x, io_control_lpc_ax03), 36,
536 offsetof(struct ioctrl512x, io_control_pata_ce2), 1,
541 offsetof(struct ioctrl512x, io_control_nfc_wp), 1,
546 offsetof(struct ioctrl512x, io_control_nfc_ale), 4,
554 puts("Board: ifm AC14xx\n");
556 /* initialize function mux & slew rate IO inter alia on IO Pins */
557 iopin_initialize_bits(ioregs_init, ARRAY_SIZE(ioregs_init));
562 #ifdef CONFIG_OF_BOARD_SETUP
563 int ft_board_setup(void *blob, bd_t *bd)
565 ft_cpu_setup(blob, bd);
569 #endif /* CONFIG_OF_BOARD_SETUP */