incaip.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * (C) Copyright 2003
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.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/addrspace.h>
  26. #include <asm/inca-ip.h>
  27. extern uint incaip_get_cpuclk(void);
  28. static ulong max_sdram_size(void)
  29. {
  30. /* The only supported SDRAM data width is 16bit.
  31. */
  32. #define CFG_DW 2
  33. /* The only supported number of SDRAM banks is 4.
  34. */
  35. #define CFG_NB 4
  36. ulong cfgpb0 = *INCA_IP_SDRAM_MC_CFGPB0;
  37. int cols = cfgpb0 & 0xF;
  38. int rows = (cfgpb0 & 0xF0) >> 4;
  39. ulong size = (1 << (rows + cols)) * CFG_DW * CFG_NB;
  40. return size;
  41. }
  42. /*
  43. * Check memory range for valid RAM. A simple memory test determines
  44. * the actually available RAM size between addresses `base' and
  45. * `base + maxsize'. Some (not all) hardware errors are detected:
  46. * - short between address lines
  47. * - short between data lines
  48. */
  49. static long int dram_size(long int *base, long int maxsize)
  50. {
  51. volatile long int *addr;
  52. ulong cnt, val;
  53. ulong save[32]; /* to make test non-destructive */
  54. unsigned char i = 0;
  55. for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
  56. addr = base + cnt; /* pointer arith! */
  57. save[i++] = *addr;
  58. *addr = ~cnt;
  59. }
  60. /* write 0 to base address */
  61. addr = base;
  62. save[i] = *addr;
  63. *addr = 0;
  64. /* check at base address */
  65. if ((val = *addr) != 0) {
  66. *addr = save[i];
  67. return (0);
  68. }
  69. for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
  70. addr = base + cnt; /* pointer arith! */
  71. val = *addr;
  72. *addr = save[--i];
  73. if (val != (~cnt)) {
  74. return (cnt * sizeof (long));
  75. }
  76. }
  77. return (maxsize);
  78. }
  79. long int initdram(int board_type)
  80. {
  81. int rows, cols, best_val = *INCA_IP_SDRAM_MC_CFGPB0;
  82. ulong size, max_size = 0;
  83. ulong our_address;
  84. asm volatile ("move %0, $25" : "=r" (our_address) :);
  85. /* Can't probe for RAM size unless we are running from Flash.
  86. */
  87. if (PHYSADDR(our_address) < PHYSADDR(PHYS_FLASH_1))
  88. {
  89. return max_sdram_size();
  90. }
  91. for (cols = 0x8; cols <= 0xC; cols++)
  92. {
  93. for (rows = 0xB; rows <= 0xD; rows++)
  94. {
  95. *INCA_IP_SDRAM_MC_CFGPB0 = (0x14 << 8) |
  96. (rows << 4) | cols;
  97. size = dram_size((ulong *)CFG_SDRAM_BASE,
  98. max_sdram_size());
  99. if (size > max_size)
  100. {
  101. best_val = *INCA_IP_SDRAM_MC_CFGPB0;
  102. max_size = size;
  103. }
  104. }
  105. }
  106. *INCA_IP_SDRAM_MC_CFGPB0 = best_val;
  107. return max_size;
  108. }
  109. int checkboard (void)
  110. {
  111. unsigned long chipid = *INCA_IP_WDT_CHIPID;
  112. int part_num;
  113. puts ("Board: INCA-IP ");
  114. part_num = (chipid >> 12) & 0xffff;
  115. switch (part_num) {
  116. case 0xc0:
  117. printf ("Standard Version, ");
  118. break;
  119. case 0xc1:
  120. printf ("Basic Version, ");
  121. break;
  122. default:
  123. printf ("Unknown Part Number 0x%x ", part_num);
  124. break;
  125. }
  126. printf ("Chip V1.%ld, ", (chipid >> 28));
  127. printf("CPU Speed %d MHz\n", incaip_get_cpuclk()/1000000);
  128. return 0;
  129. }