405ep.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 "405ep.h"
  30. #include <gdsys_fpga.h>
  31. #define REFLECTION_TESTPATTERN 0xdede
  32. #define REFLECTION_TESTPATTERN_INV (~REFLECTION_TESTPATTERN & 0xffff)
  33. DECLARE_GLOBAL_DATA_PTR;
  34. int get_fpga_state(unsigned dev)
  35. {
  36. return gd->fpga_state[dev];
  37. }
  38. void print_fpga_state(unsigned dev)
  39. {
  40. if (gd->fpga_state[dev] & FPGA_STATE_DONE_FAILED)
  41. puts(" Waiting for FPGA-DONE timed out.\n");
  42. if (gd->fpga_state[dev] & FPGA_STATE_REFLECTION_FAILED)
  43. puts(" FPGA reflection test failed.\n");
  44. }
  45. int board_early_init_f(void)
  46. {
  47. unsigned k;
  48. for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k)
  49. gd->fpga_state[k] = 0;
  50. mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
  51. mtdcr(UIC0ER, 0x00000000); /* disable all ints */
  52. mtdcr(UIC0CR, 0x00000000); /* set all to be non-critical */
  53. mtdcr(UIC0PR, 0xFFFFFF80); /* set int polarities */
  54. mtdcr(UIC0TR, 0x10000000); /* set int trigger levels */
  55. mtdcr(UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest prio */
  56. mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
  57. /*
  58. * EBC Configuration Register: set ready timeout to 512 ebc-clks
  59. * -> ca. 15 us
  60. */
  61. mtebc(EBC0_CFG, 0xa8400000); /* ebc always driven */
  62. return 0;
  63. }
  64. int board_early_init_r(void)
  65. {
  66. unsigned k;
  67. unsigned ctr;
  68. for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k)
  69. gd->fpga_state[k] = 0;
  70. /*
  71. * reset FPGA
  72. */
  73. gd405ep_init();
  74. gd405ep_set_fpga_reset(1);
  75. gd405ep_setup_hw();
  76. for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) {
  77. ctr = 0;
  78. while (!gd405ep_get_fpga_done(k)) {
  79. udelay(100000);
  80. if (ctr++ > 5) {
  81. gd->fpga_state[k] |= FPGA_STATE_DONE_FAILED;
  82. break;
  83. }
  84. }
  85. }
  86. udelay(10);
  87. gd405ep_set_fpga_reset(0);
  88. for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) {
  89. struct ihs_fpga *fpga =
  90. (struct ihs_fpga *)CONFIG_SYS_FPGA_BASE(k);
  91. #ifdef CONFIG_SYS_FPGA_NO_RFL_HI
  92. u16 *reflection_target = &fpga->reflection_low;
  93. #else
  94. u16 *reflection_target = &fpga->reflection_high;
  95. #endif
  96. /*
  97. * wait for fpga out of reset
  98. */
  99. ctr = 0;
  100. while (1) {
  101. out_le16(&fpga->reflection_low,
  102. REFLECTION_TESTPATTERN);
  103. if (in_le16(reflection_target) ==
  104. REFLECTION_TESTPATTERN_INV)
  105. break;
  106. udelay(100000);
  107. if (ctr++ > 5) {
  108. gd->fpga_state[k] |=
  109. FPGA_STATE_REFLECTION_FAILED;
  110. break;
  111. }
  112. }
  113. }
  114. return 0;
  115. }