hub405.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. * (C) Copyright 2001-2003
  3. * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
  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. #include <common.h>
  24. #include <asm/processor.h>
  25. #include <command.h>
  26. #include <malloc.h>
  27. extern void lxt971_no_sleep(void);
  28. int board_revision(void)
  29. {
  30. unsigned long osrl_reg;
  31. unsigned long isr1l_reg;
  32. unsigned long tcr_reg;
  33. unsigned long value;
  34. /*
  35. * Get version of HUB405 board from GPIO's
  36. */
  37. /*
  38. * Setup GPIO pin(s) (IRQ6/GPIO23)
  39. */
  40. osrl_reg = in32(GPIO0_OSRH);
  41. isr1l_reg = in32(GPIO0_ISR1H);
  42. tcr_reg = in32(GPIO0_TCR);
  43. out32(GPIO0_OSRH, osrl_reg & ~0x00030000); /* output select */
  44. out32(GPIO0_ISR1H, isr1l_reg | 0x00030000); /* input select */
  45. out32(GPIO0_TCR, tcr_reg & ~0x00000100); /* select input */
  46. udelay(1000); /* wait some time before reading input */
  47. value = in32(GPIO0_IR) & 0x00000100; /* get config bits */
  48. /*
  49. * Restore GPIO settings
  50. */
  51. out32(GPIO0_OSRH, osrl_reg); /* output select */
  52. out32(GPIO0_ISR1H, isr1l_reg); /* input select */
  53. out32(GPIO0_TCR, tcr_reg); /* enable output driver for outputs */
  54. if (value & 0x00000100) {
  55. /* Revision 1.1 or 1.2 detected */
  56. return 1;
  57. }
  58. /* Revision 1.0 */
  59. return 0;
  60. }
  61. int board_early_init_f (void)
  62. {
  63. /*
  64. * IRQ 0-15 405GP internally generated; active high; level sensitive
  65. * IRQ 16 405GP internally generated; active low; level sensitive
  66. * IRQ 17-24 RESERVED
  67. * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
  68. * IRQ 26 (EXT IRQ 1) SER0 ; active low; level sensitive
  69. * IRQ 27 (EXT IRQ 2) SER1; active low; level sensitive
  70. * IRQ 28 (EXT IRQ 3) FPGA 0; active low; level sensitive
  71. * IRQ 29 (EXT IRQ 4) FPGA 1; active low; level sensitive
  72. * IRQ 30 (EXT IRQ 5) PCI INTA; active low; level sensitive
  73. * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
  74. */
  75. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  76. mtdcr(uicer, 0x00000000); /* disable all ints */
  77. mtdcr(uiccr, 0x00000000); /* set all to be non-critical*/
  78. mtdcr(uicpr, 0xFFFFFF9F); /* set int polarities */
  79. mtdcr(uictr, 0x10000000); /* set int trigger levels */
  80. mtdcr(uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority*/
  81. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  82. /*
  83. * EBC Configuration Register: set ready timeout to 512 ebc-clks -> ca. 15 us
  84. */
  85. mtebc (epcr, 0xa8400000); /* ebc always driven */
  86. return 0;
  87. }
  88. int misc_init_f (void)
  89. {
  90. return 0; /* dummy implementation */
  91. }
  92. int misc_init_r (void)
  93. {
  94. DECLARE_GLOBAL_DATA_PTR;
  95. volatile unsigned char *duart0_mcr = (unsigned char *)((ulong)DUART0_BA + 4);
  96. volatile unsigned char *duart1_mcr = (unsigned char *)((ulong)DUART1_BA + 4);
  97. volatile unsigned char *duart2_mcr = (unsigned char *)((ulong)DUART2_BA + 4);
  98. volatile unsigned char *duart3_mcr = (unsigned char *)((ulong)DUART3_BA + 4);
  99. volatile unsigned char *led_reg = (unsigned char *)((ulong)DUART0_BA + 0x20);
  100. unsigned long val;
  101. int delay, flashcnt;
  102. char *str;
  103. char hw_rev[4];
  104. /*
  105. * Enable interrupts in exar duart mcr[3]
  106. */
  107. *duart0_mcr = 0x08;
  108. *duart1_mcr = 0x08;
  109. *duart2_mcr = 0x08;
  110. *duart3_mcr = 0x08;
  111. /*
  112. * Set RS232/RS422 control (RS232 = high on GPIO)
  113. */
  114. val = in32(GPIO0_OR);
  115. val &= ~(CFG_UART2_RS232 | CFG_UART3_RS232 | CFG_UART4_RS232 | CFG_UART5_RS232);
  116. str = getenv("phys0");
  117. if (!str || (str && (str[0] == '0')))
  118. val |= CFG_UART2_RS232;
  119. str = getenv("phys1");
  120. if (!str || (str && (str[0] == '0')))
  121. val |= CFG_UART3_RS232;
  122. str = getenv("phys2");
  123. if (!str || (str && (str[0] == '0')))
  124. val |= CFG_UART4_RS232;
  125. str = getenv("phys3");
  126. if (!str || (str && (str[0] == '0')))
  127. val |= CFG_UART5_RS232;
  128. out32(GPIO0_OR, val);
  129. /*
  130. * Set NAND-FLASH GPIO signals to default
  131. */
  132. out32(GPIO0_OR, in32(GPIO0_OR) & ~(CFG_NAND_CLE | CFG_NAND_ALE));
  133. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_NAND_CE);
  134. /*
  135. * check board type and setup AP power
  136. */
  137. str = getenv("bd_type"); /* this is only set on non prototype hardware */
  138. if (str != NULL) {
  139. if ((strcmp(str, "swch405") == 0) || ((!strcmp(str, "hub405") && (gd->board_type >= 1)))) {
  140. unsigned char led_reg_default = 0;
  141. str = getenv("ap_pwr");
  142. if (!str || (str && (str[0] == '1')))
  143. led_reg_default = 0x04 | 0x02 ; /* U2_LED | AP_PWR */
  144. /*
  145. * Flash LEDs
  146. */
  147. for (flashcnt = 0; flashcnt < 3; flashcnt++) {
  148. *led_reg = led_reg_default; /* LED_A..D off */
  149. for (delay = 0; delay < 100; delay++)
  150. udelay(1000);
  151. *led_reg = led_reg_default | 0xf0; /* LED_A..D on */
  152. for (delay = 0; delay < 50; delay++)
  153. udelay(1000);
  154. }
  155. *led_reg = led_reg_default;
  156. }
  157. }
  158. /*
  159. * Reset external DUARTs
  160. */
  161. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_DUART_RST); /* set reset to high */
  162. udelay(10); /* wait 10us */
  163. out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_DUART_RST); /* set reset to low */
  164. udelay(1000); /* wait 1ms */
  165. /*
  166. * Store hardware revision in environment for further processing
  167. */
  168. sprintf(hw_rev, "1.%ld", gd->board_type);
  169. setenv("hw_rev", hw_rev);
  170. return (0);
  171. }
  172. /*
  173. * Check Board Identity:
  174. */
  175. int checkboard (void)
  176. {
  177. DECLARE_GLOBAL_DATA_PTR;
  178. char str[64];
  179. int i = getenv_r ("serial#", str, sizeof(str));
  180. puts ("Board: ");
  181. if (i == -1) {
  182. puts ("### No HW ID - assuming HUB405");
  183. } else {
  184. puts(str);
  185. }
  186. if (getenv_r("bd_type", str, sizeof(str)) != -1) {
  187. printf(" (%s", str);
  188. } else {
  189. puts(" (Missing bd_type!");
  190. }
  191. gd->board_type = board_revision();
  192. printf(", Rev 1.%ld)\n", gd->board_type);
  193. /*
  194. * Disable sleep mode in LXT971
  195. */
  196. lxt971_no_sleep();
  197. return 0;
  198. }
  199. long int initdram (int board_type)
  200. {
  201. unsigned long val;
  202. mtdcr(memcfga, mem_mb0cf);
  203. val = mfdcr(memcfgd);
  204. #if 0
  205. printf("\nmb0cf=%x\n", val); /* test-only */
  206. printf("strap=%x\n", mfdcr(strap)); /* test-only */
  207. #endif
  208. return (4*1024*1024 << ((val & 0x000e0000) >> 17));
  209. }
  210. int testdram (void)
  211. {
  212. /* TODO: XXX XXX XXX */
  213. printf ("test: 16 MB - ok\n");
  214. return (0);
  215. }
  216. #if (CONFIG_COMMANDS & CFG_CMD_NAND)
  217. #include <linux/mtd/nand.h>
  218. extern struct nand_chip nand_dev_desc[CFG_MAX_NAND_DEVICE];
  219. void nand_init(void)
  220. {
  221. nand_probe(CFG_NAND_BASE);
  222. if (nand_dev_desc[0].ChipID != NAND_ChipID_UNKNOWN) {
  223. print_size(nand_dev_desc[0].totlen, "\n");
  224. }
  225. }
  226. #endif