118d81c7f29676fdfd2b4e8de786ce7b75c6cc09
[oweals/u-boot.git] / board / pcs440ep / pcs440ep.c
1 /*
2  * (C) Copyright 2006
3  * Stefan Roese, DENX Software Engineering, sr@denx.de.
4  *
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>
25 #include <asm/ppc4xx.h>
26 #include <malloc.h>
27 #include <command.h>
28 #include <crc.h>
29 #include <asm/processor.h>
30 #include <spd_sdram.h>
31 #include <status_led.h>
32 #include <sha1.h>
33 #include <asm/io.h>
34 #include <net.h>
35
36 DECLARE_GLOBAL_DATA_PTR;
37
38 extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips     */
39
40 unsigned char   sha1_checksum[SHA1_SUM_LEN];
41
42 /* swap 4 Bits (Bit0 = Bit3, Bit1 = Bit2, Bit2 = Bit1 and Bit3 = Bit0) */
43 unsigned char swapbits[16] = {0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe,
44                               0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf};
45
46 static void set_leds (int val)
47 {
48         out32(GPIO0_OR, (in32 (GPIO0_OR) & ~0x78000000) | (val << 27));
49 }
50
51 #define GET_LEDS ((in32 (GPIO0_OR) & 0x78000000) >> 27)
52
53 void __led_init (led_id_t mask, int state)
54 {
55         int     val = GET_LEDS;
56
57         if (state == STATUS_LED_ON)
58                 val |= mask;
59         else
60                 val &= ~mask;
61         set_leds (val);
62 }
63
64 void __led_set (led_id_t mask, int state)
65 {
66         int     val = GET_LEDS;
67
68         if (state == STATUS_LED_ON)
69                 val |= mask;
70         else if (state == STATUS_LED_OFF)
71                 val &= ~mask;
72         set_leds (val);
73 }
74
75 void __led_toggle (led_id_t mask)
76 {
77         int     val = GET_LEDS;
78
79         val ^= mask;
80         set_leds (val);
81 }
82
83 static void status_led_blink (void)
84 {
85         int     i;
86         int     val = GET_LEDS;
87
88         /* set all LED which are on, to state BLINKING */
89         for (i = 0; i < 4; i++) {
90                 if (val & 0x01) status_led_set (3 - i, STATUS_LED_BLINKING);
91                 else status_led_set (3 - i, STATUS_LED_OFF);
92                 val = val >> 1;
93         }
94 }
95
96 #if defined(CONFIG_SHOW_BOOT_PROGRESS)
97 void show_boot_progress (int val)
98 {
99         /* find all valid Codes for val in README */
100         if (val == -30) return;
101         if (val < 0) {
102                 /* smthing goes wrong */
103                 status_led_blink ();
104                 return;
105         }
106         switch (val) {
107         case BOOTSTAGE_ID_CHECK_MAGIC:
108                 /* validating Image */
109                 status_led_set(0, STATUS_LED_OFF);
110                 status_led_set(1, STATUS_LED_ON);
111                 status_led_set(2, STATUS_LED_ON);
112                 break;
113         case BOOTSTAGE_ID_RUN_OS:
114                 status_led_set(0, STATUS_LED_ON);
115                 status_led_set(1, STATUS_LED_ON);
116                 status_led_set(2, STATUS_LED_ON);
117                 break;
118 #if 0
119                 case 64:
120                         /* starting Ethernet configuration */
121                         status_led_set (0, STATUS_LED_OFF);
122                         status_led_set (1, STATUS_LED_OFF);
123                         status_led_set (2, STATUS_LED_ON);
124                         break;
125 #endif
126                 case 80:
127                         /* loading Image */
128                         status_led_set (0, STATUS_LED_ON);
129                         status_led_set (1, STATUS_LED_OFF);
130                         status_led_set (2, STATUS_LED_ON);
131                         break;
132         }
133 }
134 #endif
135
136 int board_early_init_f(void)
137 {
138         register uint reg;
139
140         set_leds(0);                    /* display boot info counter */
141
142         /*--------------------------------------------------------------------
143          * Setup the external bus controller/chip selects
144          *-------------------------------------------------------------------*/
145         mtdcr(EBC0_CFGADDR, EBC0_CFG);
146         reg = mfdcr(EBC0_CFGDATA);
147         mtdcr(EBC0_CFGDATA, reg | 0x04000000);  /* Set ATC */
148
149         /*--------------------------------------------------------------------
150          * GPIO's are alreay setup in arch/powerpc/cpu/ppc4xx/cpu_init.c
151          * via define from board config file.
152          *-------------------------------------------------------------------*/
153
154         /*--------------------------------------------------------------------
155          * Setup the interrupt controller polarities, triggers, etc.
156          *-------------------------------------------------------------------*/
157         mtdcr(UIC0SR, 0xffffffff);      /* clear all */
158         mtdcr(UIC0ER, 0x00000000);      /* disable all */
159         mtdcr(UIC0CR, 0x00000001);      /* UIC1 crit is critical */
160         mtdcr(UIC0PR, 0xfffffe1f);      /* per ref-board manual */
161         mtdcr(UIC0TR, 0x01c00000);      /* per ref-board manual */
162         mtdcr(UIC0VR, 0x00000001);      /* int31 highest, base=0x000 */
163         mtdcr(UIC0SR, 0xffffffff);      /* clear all */
164
165         mtdcr(UIC1SR, 0xffffffff);      /* clear all */
166         mtdcr(UIC1ER, 0x00000000);      /* disable all */
167         mtdcr(UIC1CR, 0x00000000);      /* all non-critical */
168         mtdcr(UIC1PR, 0xffffe0ff);      /* per ref-board manual */
169         mtdcr(UIC1TR, 0x00ffc000);      /* per ref-board manual */
170         mtdcr(UIC1VR, 0x00000001);      /* int31 highest, base=0x000 */
171         mtdcr(UIC1SR, 0xffffffff);      /* clear all */
172
173         /*--------------------------------------------------------------------
174          * Setup other serial configuration
175          *-------------------------------------------------------------------*/
176         mfsdr(SDR0_PCI0, reg);
177         mtsdr(SDR0_PCI0, 0x80000000 | reg);     /* PCI arbiter enabled */
178         mtsdr(SDR0_PFC0, 0x00000000);   /* Pin function: enable GPIO49-63 */
179         mtsdr(SDR0_PFC1, 0x00048000);   /* Pin function: UART0 has 4 pins, select IRQ5 */
180
181         return 0;
182 }
183
184 #define EEPROM_LEN      256
185 static void load_ethaddr(void)
186 {
187         int     ok_ethaddr, ok_eth1addr;
188         int     ret;
189         uchar   buf[EEPROM_LEN];
190         char    *use_eeprom;
191         u16     checksumcrc16 = 0;
192
193         /* If the env is sane, then nothing for us to do */
194         ok_ethaddr = eth_getenv_enetaddr("ethaddr", buf);
195         ok_eth1addr = eth_getenv_enetaddr("eth1addr", buf);
196         if (ok_ethaddr && ok_eth1addr)
197                 return;
198
199         /* read the MACs from EEprom */
200         status_led_set (0, STATUS_LED_ON);
201         status_led_set (1, STATUS_LED_ON);
202         ret = eeprom_read (CONFIG_SYS_I2C_EEPROM_ADDR, 0, buf, EEPROM_LEN);
203         if (ret == 0) {
204                 checksumcrc16 = cyg_crc16 (buf, EEPROM_LEN - 2);
205                 /* check, if the EEprom is programmed:
206                  * - The Prefix(Byte 0,1,2) is equal to "ATR"
207                  * - The checksum, stored in the last 2 Bytes, is correct
208                  */
209                 if ((strncmp ((char *)buf,"ATR",3) != 0) ||
210                     ((checksumcrc16 >> 8) != buf[EEPROM_LEN - 2]) ||
211                     ((checksumcrc16 & 0xff) != buf[EEPROM_LEN - 1])) {
212                         /* EEprom is not programmed */
213                         printf("%s: EEPROM Checksum not OK\n", __FUNCTION__);
214                 } else {
215                         /* get the MACs */
216                         if (!ok_ethaddr)
217                                 eth_setenv_enetaddr("ethaddr", &buf[3]);
218                         if (!ok_eth1addr)
219                                 eth_setenv_enetaddr("eth1addr", &buf[9]);
220                         return;
221                 }
222         }
223
224         /* some error reading the EEprom */
225         if ((use_eeprom = getenv ("use_eeprom_ethaddr")) == NULL) {
226                 /* dont use bootcmd */
227                 setenv("bootdelay", "-1");
228                 return;
229         }
230         /* == default ? use standard */
231         if (strncmp (use_eeprom, "default", 7) == 0) {
232                 return;
233         }
234         /* Env doesnt exist -> hang */
235         status_led_blink ();
236         /* here we do this "handy" because we have no interrupts
237            at this time */
238         puts ("### EEPROM ERROR ### Please RESET the board ###\n");
239         for (;;) {
240                 __led_toggle (12);
241                 udelay (100000);
242         }
243         return;
244 }
245
246 #ifdef CONFIG_PREBOOT
247
248 static uchar kbd_magic_prefix[]         = "key_magic";
249 static uchar kbd_command_prefix[]       = "key_cmd";
250
251 struct kbd_data_t {
252         char s1;
253         char s2;
254 };
255
256 struct kbd_data_t* get_keys (struct kbd_data_t *kbd_data)
257 {
258         char *val;
259         unsigned long tmp;
260
261         /* use the DIPs for some bootoptions */
262         val = getenv (ENV_NAME_DIP);
263         tmp = simple_strtoul (val, NULL, 16);
264
265         kbd_data->s2 = (tmp & 0x0f);
266         kbd_data->s1 = (tmp & 0xf0) >> 4;
267         return kbd_data;
268 }
269
270 static int compare_magic (const struct kbd_data_t *kbd_data, char *str)
271 {
272         char s1 = str[0];
273
274         if (s1 >= '0' && s1 <= '9')
275                 s1 -= '0';
276         else if (s1 >= 'a' && s1 <= 'f')
277                 s1 = s1 - 'a' + 10;
278         else if (s1 >= 'A' && s1 <= 'F')
279                 s1 = s1 - 'A' + 10;
280         else
281                 return -1;
282
283         if (s1 != kbd_data->s1) return -1;
284
285         s1 = str[1];
286         if (s1 >= '0' && s1 <= '9')
287                 s1 -= '0';
288         else if (s1 >= 'a' && s1 <= 'f')
289                 s1 = s1 - 'a' + 10;
290         else if (s1 >= 'A' && s1 <= 'F')
291                 s1 = s1 - 'A' + 10;
292         else
293                 return -1;
294
295         if (s1 != kbd_data->s2) return -1;
296         return 0;
297 }
298
299 static char *key_match (const struct kbd_data_t *kbd_data)
300 {
301         char magic[sizeof (kbd_magic_prefix) + 1];
302         char *suffix;
303         char *kbd_magic_keys;
304
305         /*
306          * The following string defines the characters that can be appended
307          * to "key_magic" to form the names of environment variables that
308          * hold "magic" key codes, i. e. such key codes that can cause
309          * pre-boot actions. If the string is empty (""), then only
310          * "key_magic" is checked (old behaviour); the string "125" causes
311          * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
312          */
313         if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
314                 kbd_magic_keys = "";
315
316         /* loop over all magic keys;
317          * use '\0' suffix in case of empty string
318          */
319         for (suffix = kbd_magic_keys; *suffix ||
320                      suffix == kbd_magic_keys; ++suffix) {
321                 sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
322                 if (compare_magic (kbd_data, getenv (magic)) == 0) {
323                         char cmd_name[sizeof (kbd_command_prefix) + 1];
324                         char *cmd;
325
326                         sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
327                         cmd = getenv (cmd_name);
328
329                         return (cmd);
330                 }
331         }
332         return (NULL);
333 }
334
335 #endif /* CONFIG_PREBOOT */
336
337 static int pcs440ep_readinputs (void)
338 {
339         int     i;
340         char    value[20];
341
342         /* read the inputs and set the Envvars */
343         /* Revision Level Bit 26 - 29 */
344         i = ((in32 (GPIO0_IR) & 0x0000003c) >> 2);
345         i = swapbits[i];
346         sprintf (value, "%02x", i);
347         setenv (ENV_NAME_REVLEV, value);
348         /* Solder Switch Bit 30 - 33 */
349         i = (in32 (GPIO0_IR) & 0x00000003) << 2;
350         i += (in32 (GPIO1_IR) & 0xc0000000) >> 30;
351         i = swapbits[i];
352         sprintf (value, "%02x", i);
353         setenv (ENV_NAME_SOLDER, value);
354         /* DIP Switch Bit 49 - 56 */
355         i = ((in32 (GPIO1_IR) & 0x00007f80) >> 7);
356         i = (swapbits[i & 0x0f] << 4) + swapbits[(i & 0xf0) >> 4];
357         sprintf (value, "%02x", i);
358         setenv (ENV_NAME_DIP, value);
359         return 0;
360 }
361
362
363 #if defined(CONFIG_SHA1_CHECK_UB_IMG)
364 /*************************************************************************
365  * calculate a SHA1 sum for the U-Boot image in Flash.
366  *
367  ************************************************************************/
368 static int pcs440ep_sha1 (int docheck)
369 {
370         unsigned char *data;
371         unsigned char *ptroff;
372         unsigned char output[20];
373         unsigned char org[20];
374         int     i, len = CONFIG_SHA1_LEN;
375
376         memcpy ((char *)CONFIG_SYS_LOAD_ADDR, (char *)CONFIG_SHA1_START, len);
377         data = (unsigned char *)CONFIG_SYS_LOAD_ADDR;
378         ptroff = &data[len + SHA1_SUM_POS];
379
380         for (i = 0; i < SHA1_SUM_LEN; i++) {
381                 org[i] = ptroff[i];
382                 ptroff[i] = 0;
383         }
384
385         sha1_csum ((unsigned char *) data, len, (unsigned char *)output);
386
387         if (docheck == 2) {
388                 for (i = 0; i < 20 ; i++) {
389                         printf("%02X ", output[i]);
390                 }
391                 printf("\n");
392         }
393         if (docheck == 1) {
394                 for (i = 0; i < 20 ; i++) {
395                         if (org[i] != output[i]) return 1;
396                 }
397         }
398         return 0;
399 }
400
401 /*************************************************************************
402  * do some checks after the SHA1 checksum from the U-Boot Image was
403  * calculated.
404  *
405  ************************************************************************/
406 static void pcs440ep_checksha1 (void)
407 {
408         int     ret;
409         char    *cs_test;
410
411         status_led_set (0, STATUS_LED_OFF);
412         status_led_set (1, STATUS_LED_OFF);
413         status_led_set (2, STATUS_LED_ON);
414         ret = pcs440ep_sha1 (1);
415         if (ret == 0) return;
416
417         if ((cs_test = getenv ("cs_test")) == NULL) {
418                 /* Env doesnt exist -> hang */
419                 status_led_blink ();
420                 /* here we do this "handy" because we have no interrupts
421                    at this time */
422                 puts ("### SHA1 ERROR ### Please RESET the board ###\n");
423                 for (;;) {
424                         __led_toggle (2);
425                         udelay (100000);
426                 }
427         }
428
429         if (strncmp (cs_test, "off", 3) == 0) {
430                 printf ("SHA1 U-Boot sum NOT ok!\n");
431                 setenv ("bootdelay", "-1");
432         }
433 }
434 #else
435 static __inline__ void pcs440ep_checksha1 (void) { do {} while (0);}
436 #endif
437
438 int misc_init_r (void)
439 {
440         uint pbcr;
441         int size_val = 0;
442
443         load_ethaddr();
444
445         /* Re-do sizing to get full correct info */
446         mtdcr(EBC0_CFGADDR, PB0CR);
447         pbcr = mfdcr(EBC0_CFGDATA);
448         switch (gd->bd->bi_flashsize) {
449         case 1 << 20:
450                 size_val = 0;
451                 break;
452         case 2 << 20:
453                 size_val = 1;
454                 break;
455         case 4 << 20:
456                 size_val = 2;
457                 break;
458         case 8 << 20:
459                 size_val = 3;
460                 break;
461         case 16 << 20:
462                 size_val = 4;
463                 break;
464         case 32 << 20:
465                 size_val = 5;
466                 break;
467         case 64 << 20:
468                 size_val = 6;
469                 break;
470         case 128 << 20:
471                 size_val = 7;
472                 break;
473         }
474         pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
475         mtdcr(EBC0_CFGADDR, PB0CR);
476         mtdcr(EBC0_CFGDATA, pbcr);
477
478         /* adjust flash start and offset */
479         gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
480         gd->bd->bi_flashoffset = 0;
481
482         /* Monitor protection ON by default */
483         (void)flash_protect(FLAG_PROTECT_SET,
484                             -CONFIG_SYS_MONITOR_LEN,
485                             0xffffffff,
486                             &flash_info[1]);
487
488         /* Env protection ON by default */
489         (void)flash_protect(FLAG_PROTECT_SET,
490                             CONFIG_ENV_ADDR_REDUND,
491                             CONFIG_ENV_ADDR_REDUND + 2*CONFIG_ENV_SECT_SIZE - 1,
492                             &flash_info[1]);
493
494         pcs440ep_readinputs ();
495         pcs440ep_checksha1 ();
496 #ifdef CONFIG_PREBOOT
497         {
498                 struct kbd_data_t kbd_data;
499                 /* Decode keys */
500                 char *str = strdup (key_match (get_keys (&kbd_data)));
501                 /* Set or delete definition */
502                 setenv ("preboot", str);
503                 free (str);
504         }
505 #endif /* CONFIG_PREBOOT */
506         return 0;
507 }
508
509 int checkboard(void)
510 {
511         char buf[64];
512         int i = getenv_f("serial#", buf, sizeof(buf));
513
514         printf("Board: PCS440EP");
515         if (i > 0) {
516                 puts(", serial# ");
517                 puts(buf);
518         }
519         putc('\n');
520
521         return (0);
522 }
523
524 void spd_ddr_init_hang (void)
525 {
526         status_led_set (0, STATUS_LED_OFF);
527         status_led_set (1, STATUS_LED_ON);
528         /* we cannot use hang() because we are still running from
529            Flash, and so the status_led driver is not initialized */
530         puts ("### SDRAM ERROR ### Please RESET the board ###\n");
531         for (;;) {
532                 __led_toggle (4);
533                 udelay (100000);
534         }
535 }
536
537 phys_size_t initdram (int board_type)
538 {
539         long dram_size = 0;
540
541         status_led_set (0, STATUS_LED_ON);
542         status_led_set (1, STATUS_LED_OFF);
543         dram_size = spd_sdram();
544         status_led_set (0, STATUS_LED_OFF);
545         status_led_set (1, STATUS_LED_ON);
546         if (dram_size == 0) {
547                 hang();
548         }
549
550         return dram_size;
551 }
552
553 /*************************************************************************
554  *  hw_watchdog_reset
555  *
556  *      This routine is called to reset (keep alive) the watchdog timer
557  *
558  ************************************************************************/
559 #if defined(CONFIG_HW_WATCHDOG)
560 void hw_watchdog_reset(void)
561 {
562
563 }
564 #endif
565
566 /*************************************************************************
567  * "led" Commando for the U-Boot shell
568  *
569  ************************************************************************/
570 int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
571 {
572         int     rcode = 0, i;
573         ulong   pattern = 0;
574
575         pattern = simple_strtoul (argv[1], NULL, 16);
576         if (pattern > 0x400) {
577                 int     val = GET_LEDS;
578                 printf ("led: %x\n", val);
579                 return rcode;
580         }
581         if (pattern > 0x200) {
582                 status_led_blink ();
583                 hang ();
584                 return rcode;
585         }
586         if (pattern > 0x100) {
587                 status_led_blink ();
588                 return rcode;
589         }
590         pattern &= 0x0f;
591         for (i = 0; i < 4; i++) {
592                 if (pattern & 0x01) status_led_set (i, STATUS_LED_ON);
593                 else status_led_set (i, STATUS_LED_OFF);
594                 pattern = pattern >> 1;
595         }
596         return rcode;
597 }
598
599 U_BOOT_CMD(
600         led,    2,      1,      do_led,
601         "set the DIAG-LED",
602         "[bitmask] 0x01 = DIAG 1 on\n"
603         "              0x02 = DIAG 2 on\n"
604         "              0x04 = DIAG 3 on\n"
605         "              0x08 = DIAG 4 on\n"
606         "              > 0x100 set the LED, who are on, to state blinking"
607 );
608
609 #if defined(CONFIG_SHA1_CHECK_UB_IMG)
610 /*************************************************************************
611  * "sha1" Commando for the U-Boot shell
612  *
613  ************************************************************************/
614 int do_sha1 (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
615 {
616         int     rcode = -1;
617
618         if (argc < 2) {
619 usage:
620                 return cmd_usage(cmdtp);
621         }
622
623         if (argc >= 3) {
624                 unsigned char *data;
625                 unsigned char output[20];
626                 int     len;
627                 int     i;
628
629                 data = (unsigned char *)simple_strtoul (argv[1], NULL, 16);
630                 len = simple_strtoul (argv[2], NULL, 16);
631                 sha1_csum (data, len, (unsigned char *)output);
632                 printf ("U-Boot sum:\n");
633                 for (i = 0; i < 20 ; i++) {
634                         printf ("%02X ", output[i]);
635                 }
636                 printf ("\n");
637                 if (argc == 4) {
638                         data = (unsigned char *)simple_strtoul (argv[3], NULL, 16);
639                         memcpy (data, output, 20);
640                 }
641                 return 0;
642         }
643         if (argc == 2) {
644                 char *ptr = argv[1];
645                 if (*ptr != '-') goto usage;
646                 ptr++;
647                 if ((*ptr == 'c') || (*ptr == 'C')) {
648                         rcode = pcs440ep_sha1 (1);
649                         printf ("SHA1 U-Boot sum %sok!\n", (rcode != 0) ? "not " : "");
650                 } else if ((*ptr == 'p') || (*ptr == 'P')) {
651                         rcode = pcs440ep_sha1 (2);
652                 } else {
653                         rcode = pcs440ep_sha1 (0);
654                 }
655                 return rcode;
656         }
657         return rcode;
658 }
659
660 U_BOOT_CMD(
661         sha1,   4,      1,      do_sha1,
662         "calculate the SHA1 Sum",
663         "address len [addr]  calculate the SHA1 sum [save at addr]\n"
664         "     -p calculate the SHA1 sum from the U-Boot image in flash and print\n"
665         "     -c check the U-Boot image in flash"
666 );
667 #endif
668
669 #if defined (CONFIG_CMD_IDE)
670 /* These addresses need to be shifted one place to the left
671  * ( bus per_addr 20 -30 is connectsd on CF bus A10-A0)
672  * These values are shifted
673  */
674 extern ulong *ide_bus_offset;
675 void inline ide_outb(int dev, int port, unsigned char val)
676 {
677         debug ("ide_outb (dev= %d, port= 0x%x, val= 0x%02x) : @ 0x%08lx\n",
678                 dev, port, val, (ATA_CURR_BASE(dev)+port));
679
680         out_be16((u16 *)(ATA_CURR_BASE(dev)+(port << 1)), val);
681 }
682 unsigned char inline ide_inb(int dev, int port)
683 {
684         uchar val;
685         val = in_be16((u16 *)(ATA_CURR_BASE(dev)+(port << 1)));
686         debug ("ide_inb (dev= %d, port= 0x%x) : @ 0x%08lx -> 0x%02x\n",
687                 dev, port, (ATA_CURR_BASE(dev)+port), val);
688         return (val);
689 }
690 #endif
691
692 #ifdef CONFIG_IDE_PREINIT
693 int ide_preinit (void)
694 {
695         /* Set True IDE Mode */
696         out32 (GPIO0_OR, (in32 (GPIO0_OR) | 0x00100000));
697         out32 (GPIO0_OR, (in32 (GPIO0_OR) | 0x00200000));
698         out32 (GPIO1_OR, (in32 (GPIO1_OR) & ~0x00008040));
699         udelay (100000);
700         return 0;
701 }
702 #endif
703
704 #if defined (CONFIG_CMD_IDE) && defined (CONFIG_IDE_RESET)
705 void ide_set_reset (int idereset)
706 {
707         debug ("ide_reset(%d)\n", idereset);
708         if (idereset == 0) {
709                 out32 (GPIO0_OR, (in32 (GPIO0_OR) | 0x00200000));
710         } else {
711                 out32 (GPIO0_OR, (in32 (GPIO0_OR) & ~0x00200000));
712         }
713         udelay (10000);
714 }
715 #endif /* defined (CONFIG_CMD_IDE) && defined (CONFIG_IDE_RESET) */