405ep.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * (C) Copyright 2010
  3. * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.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. #include <common.h>
  24. #include <command.h>
  25. #include <asm/processor.h>
  26. #include <asm/io.h>
  27. #include <asm/ppc4xx-gpio.h>
  28. #include <asm/global_data.h>
  29. #include <gdsys_fpga.h>
  30. #define LATCH0_BASE (CONFIG_SYS_LATCH_BASE)
  31. #define LATCH1_BASE (CONFIG_SYS_LATCH_BASE + 0x100)
  32. #define LATCH2_BASE (CONFIG_SYS_LATCH_BASE + 0x200)
  33. #define REFLECTION_TESTPATTERN 0xdede
  34. #define REFLECTION_TESTPATTERN_INV (~REFLECTION_TESTPATTERN & 0xffff)
  35. DECLARE_GLOBAL_DATA_PTR;
  36. int get_fpga_state(unsigned dev)
  37. {
  38. return gd->fpga_state[dev];
  39. }
  40. void print_fpga_state(unsigned dev)
  41. {
  42. if (gd->fpga_state[dev] & FPGA_STATE_DONE_FAILED)
  43. puts(" Waiting for FPGA-DONE timed out.\n");
  44. if (gd->fpga_state[dev] & FPGA_STATE_REFLECTION_FAILED)
  45. puts(" FPGA reflection test failed.\n");
  46. }
  47. int board_early_init_f(void)
  48. {
  49. unsigned k;
  50. unsigned ctr;
  51. for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k)
  52. gd->fpga_state[k] = 0;
  53. mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
  54. mtdcr(UIC0ER, 0x00000000); /* disable all ints */
  55. mtdcr(UIC0CR, 0x00000000); /* set all to be non-critical */
  56. mtdcr(UIC0PR, 0xFFFFFF80); /* set int polarities */
  57. mtdcr(UIC0TR, 0x10000000); /* set int trigger levels */
  58. mtdcr(UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest prio */
  59. mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
  60. /*
  61. * EBC Configuration Register: set ready timeout to 512 ebc-clks
  62. * -> ca. 15 us
  63. */
  64. mtebc(EBC0_CFG, 0xa8400000); /* ebc always driven */
  65. /*
  66. * setup io-latches for reset
  67. */
  68. out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_RESET);
  69. out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_RESET);
  70. /*
  71. * set "startup-finished"-gpios
  72. */
  73. gpio_write_bit(21, 0);
  74. gpio_write_bit(22, 1);
  75. /*
  76. * wait for fpga-done
  77. */
  78. for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) {
  79. ctr = 0;
  80. while (!(in_le16((void *)LATCH2_BASE)
  81. & CONFIG_SYS_FPGA_DONE(k))) {
  82. udelay(100000);
  83. if (ctr++ > 5) {
  84. gd->fpga_state[k] |= FPGA_STATE_DONE_FAILED;
  85. break;
  86. }
  87. }
  88. }
  89. /*
  90. * setup io-latches for boot (stop reset)
  91. */
  92. udelay(10);
  93. out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_BOOT);
  94. out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_BOOT);
  95. for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) {
  96. ihs_fpga_t *fpga = (ihs_fpga_t *) CONFIG_SYS_FPGA_BASE(k);
  97. #ifdef CONFIG_SYS_FPGA_NO_RFL_HI
  98. u16 *reflection_target = &fpga->reflection_low;
  99. #else
  100. u16 *reflection_target = &fpga->reflection_high;
  101. #endif
  102. /*
  103. * wait for fpga out of reset
  104. */
  105. ctr = 0;
  106. while (1) {
  107. out_le16(&fpga->reflection_low,
  108. REFLECTION_TESTPATTERN);
  109. if (in_le16(reflection_target) ==
  110. REFLECTION_TESTPATTERN_INV)
  111. break;
  112. udelay(100000);
  113. if (ctr++ > 5) {
  114. gd->fpga_state[k] |=
  115. FPGA_STATE_REFLECTION_FAILED;
  116. break;
  117. }
  118. }
  119. }
  120. return 0;
  121. }