hub405.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 <asm/io.h>
  26. #include <command.h>
  27. #include <malloc.h>
  28. DECLARE_GLOBAL_DATA_PTR;
  29. extern void lxt971_no_sleep(void);
  30. int board_revision(void)
  31. {
  32. unsigned long osrl_reg;
  33. unsigned long isr1l_reg;
  34. unsigned long tcr_reg;
  35. unsigned long value;
  36. /*
  37. * Get version of HUB405 board from GPIO's
  38. */
  39. /*
  40. * Setup GPIO pin(s) (IRQ6/GPIO23)
  41. */
  42. osrl_reg = in_be32((void *)GPIO0_OSRH);
  43. isr1l_reg = in_be32((void *)GPIO0_ISR1H);
  44. tcr_reg = in_be32((void *)GPIO0_TCR);
  45. out_be32((void *)GPIO0_OSRH, osrl_reg & ~0x00030000); /* output select */
  46. out_be32((void *)GPIO0_ISR1H, isr1l_reg | 0x00030000); /* input select */
  47. out_be32((void *)GPIO0_TCR, tcr_reg & ~0x00000100); /* select input */
  48. udelay(1000); /* wait some time before reading input */
  49. value = in_be32((void *)GPIO0_IR) & 0x00000100; /* get config bits */
  50. /*
  51. * Restore GPIO settings
  52. */
  53. out_be32((void *)GPIO0_OSRH, osrl_reg); /* output select */
  54. out_be32((void *)GPIO0_ISR1H, isr1l_reg); /* input select */
  55. out_be32((void *)GPIO0_TCR, tcr_reg); /* enable output driver for outputs */
  56. if (value & 0x00000100) {
  57. /* Revision 1.1 or 1.2 detected */
  58. return 1;
  59. }
  60. /* Revision 1.0 */
  61. return 0;
  62. }
  63. int board_early_init_f (void)
  64. {
  65. /*
  66. * IRQ 0-15 405GP internally generated; active high; level sensitive
  67. * IRQ 16 405GP internally generated; active low; level sensitive
  68. * IRQ 17-24 RESERVED
  69. * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
  70. * IRQ 26 (EXT IRQ 1) SER0 ; active low; level sensitive
  71. * IRQ 27 (EXT IRQ 2) SER1; active low; level sensitive
  72. * IRQ 28 (EXT IRQ 3) FPGA 0; active low; level sensitive
  73. * IRQ 29 (EXT IRQ 4) FPGA 1; active low; level sensitive
  74. * IRQ 30 (EXT IRQ 5) PCI INTA; active low; level sensitive
  75. * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
  76. */
  77. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  78. mtdcr(uicer, 0x00000000); /* disable all ints */
  79. mtdcr(uiccr, 0x00000000); /* set all to be non-critical*/
  80. mtdcr(uicpr, 0xFFFFFF9F); /* set int polarities */
  81. mtdcr(uictr, 0x10000000); /* set int trigger levels */
  82. mtdcr(uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority*/
  83. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  84. /*
  85. * EBC Configuration Register: set ready timeout to 512 ebc-clks -> ca. 15 us
  86. */
  87. mtebc (epcr, 0xa8400000); /* ebc always driven */
  88. return 0;
  89. }
  90. #define LED_REG (DUART0_BA + 0x20)
  91. int misc_init_r (void)
  92. {
  93. unsigned long val;
  94. int delay, flashcnt;
  95. char *str;
  96. char hw_rev[4];
  97. /*
  98. * Enable interrupts in exar duart mcr[3]
  99. */
  100. out_8((void *)(DUART0_BA + 4), 0x08);
  101. out_8((void *)(DUART1_BA + 4), 0x08);
  102. out_8((void *)(DUART2_BA + 4), 0x08);
  103. out_8((void *)(DUART3_BA + 4), 0x08);
  104. /*
  105. * Set RS232/RS422 control (RS232 = high on GPIO)
  106. */
  107. val = in_be32((void *)GPIO0_OR);
  108. val &= ~(CONFIG_SYS_UART2_RS232 | CONFIG_SYS_UART3_RS232 |
  109. CONFIG_SYS_UART4_RS232 | CONFIG_SYS_UART5_RS232);
  110. str = getenv("phys0");
  111. if (!str || (str && (str[0] == '0')))
  112. val |= CONFIG_SYS_UART2_RS232;
  113. str = getenv("phys1");
  114. if (!str || (str && (str[0] == '0')))
  115. val |= CONFIG_SYS_UART3_RS232;
  116. str = getenv("phys2");
  117. if (!str || (str && (str[0] == '0')))
  118. val |= CONFIG_SYS_UART4_RS232;
  119. str = getenv("phys3");
  120. if (!str || (str && (str[0] == '0')))
  121. val |= CONFIG_SYS_UART5_RS232;
  122. out_be32((void *)GPIO0_OR, val);
  123. /*
  124. * check board type and setup AP power
  125. */
  126. str = getenv("bd_type"); /* this is only set on non prototype hardware */
  127. if (str != NULL) {
  128. if ((strcmp(str, "swch405") == 0) || ((!strcmp(str, "hub405") && (gd->board_type >= 1)))) {
  129. unsigned char led_reg_default = 0;
  130. str = getenv("ap_pwr");
  131. if (!str || (str && (str[0] == '1')))
  132. led_reg_default = 0x04 | 0x02 ; /* U2_LED | AP_PWR */
  133. /*
  134. * Flash LEDs
  135. */
  136. for (flashcnt = 0; flashcnt < 3; flashcnt++) {
  137. /* LED_A..D off */
  138. out_8((void *)LED_REG, led_reg_default);
  139. for (delay = 0; delay < 100; delay++)
  140. udelay(1000);
  141. /* LED_A..D on */
  142. out_8((void *)LED_REG, led_reg_default | 0xf0);
  143. for (delay = 0; delay < 50; delay++)
  144. udelay(1000);
  145. }
  146. out_8((void *)LED_REG, led_reg_default);
  147. }
  148. }
  149. /*
  150. * Reset external DUARTs
  151. */
  152. out_be32((void *)GPIO0_OR,
  153. in_be32((void *)GPIO0_OR) | CONFIG_SYS_DUART_RST); /* set reset to high */
  154. udelay(10); /* wait 10us */
  155. out_be32((void *)GPIO0_OR,
  156. in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_DUART_RST); /* set reset to low */
  157. udelay(1000); /* wait 1ms */
  158. /*
  159. * Store hardware revision in environment for further processing
  160. */
  161. sprintf(hw_rev, "1.%ld", gd->board_type);
  162. setenv("hw_rev", hw_rev);
  163. return (0);
  164. }
  165. /*
  166. * Check Board Identity:
  167. */
  168. int checkboard (void)
  169. {
  170. char str[64];
  171. int i = getenv_r ("serial#", str, sizeof(str));
  172. puts ("Board: ");
  173. if (i == -1) {
  174. puts ("### No HW ID - assuming HUB405");
  175. } else {
  176. puts(str);
  177. }
  178. if (getenv_r("bd_type", str, sizeof(str)) != -1) {
  179. printf(" (%s", str);
  180. } else {
  181. puts(" (Missing bd_type!");
  182. }
  183. gd->board_type = board_revision();
  184. printf(", Rev 1.%ld)\n", gd->board_type);
  185. /*
  186. * Disable sleep mode in LXT971
  187. */
  188. lxt971_no_sleep();
  189. return 0;
  190. }