gdc.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * (C) Copyright 2008 Dmitry Rakhchev, EmCraft Systems, rda@emcraft.com
  3. *
  4. * Developed for DENX Software Engineering GmbH
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #ifdef CONFIG_POST
  26. /* This test attempts to verify board GDC. A scratch register tested, then
  27. * simple memory test (get_ram_size()) run over GDC memory.
  28. */
  29. #include <post.h>
  30. #include <asm/io.h>
  31. DECLARE_GLOBAL_DATA_PTR;
  32. #define GDC_SCRATCH_REG 0xC1FF8044
  33. #define GDC_VERSION_REG 0xC1FF8084
  34. #define GDC_RAM_START 0xC0000000
  35. #define GDC_RAM_END 0xC2000000
  36. #if CONFIG_POST & CFG_POST_BSPEC4
  37. static int gdc_test_reg_one(uint value)
  38. {
  39. int ret = 0;
  40. uint read_value;
  41. /* write test pattern */
  42. out_be32((void *)GDC_SCRATCH_REG, value);
  43. /* read other location (protect against data lines capacity) */
  44. ret = in_be32((void *)GDC_RAM_START);
  45. /* verify test pattern */
  46. read_value = in_be32((void *)GDC_SCRATCH_REG);
  47. if (read_value != value) {
  48. post_log("GDC SCRATCH test failed write %08X, read %08X\n",
  49. value, read_value);
  50. ret = 1;
  51. }
  52. return ret;
  53. }
  54. /* Verify GDC, get memory size */
  55. int gdc_post_test(int flags)
  56. {
  57. uint old_value;
  58. int ret = 0;
  59. post_log("\n");
  60. old_value = in_be32((void *)GDC_SCRATCH_REG);
  61. if (gdc_test_reg_one(0x55555555))
  62. ret = 1;
  63. if (gdc_test_reg_one(0xAAAAAAAA))
  64. ret = 1;
  65. out_be32((void *)GDC_SCRATCH_REG, old_value);
  66. old_value = in_be32((void *)GDC_VERSION_REG);
  67. post_log("GDC chip version %u.%u, year %04X\n",
  68. (old_value >> 8) & 0xFF, old_value & 0xFF,
  69. (old_value >> 16) & 0xFFFF);
  70. old_value = get_ram_size((void *)GDC_RAM_START,
  71. GDC_RAM_END - GDC_RAM_START);
  72. post_log("GDC RAM size: %d bytes\n", old_value);
  73. return ret;
  74. }
  75. #endif /* CONFIG_POST & CFG_POST_BSPEC4 */
  76. #endif /* CONFIG_POST */