vme8349.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * vme8349.c -- esd VME8349 board support
  3. *
  4. * Copyright (c) 2008-2009 esd gmbh.
  5. *
  6. * (C) Copyright 2006
  7. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  8. *
  9. * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
  10. * Based on board/mpc8349emds/mpc8349emds.c (and previous 834x releases.)
  11. *
  12. * See file CREDITS for list of people who contributed to this
  13. * project.
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License as
  17. * published by the Free Software Foundation; either version 2 of
  18. * the License, or (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  28. * MA 02111-1307 USA
  29. *
  30. */
  31. #include <common.h>
  32. #include <ioports.h>
  33. #include <mpc83xx.h>
  34. #include <asm/mpc8349_pci.h>
  35. #if defined(CONFIG_OF_LIBFDT)
  36. #include <libfdt.h>
  37. #endif
  38. #include <asm/io.h>
  39. #include <asm/mmu.h>
  40. #include <spd.h>
  41. #include <spd_sdram.h>
  42. #include <i2c.h>
  43. #include <netdev.h>
  44. void ddr_enable_ecc(unsigned int dram_size);
  45. phys_size_t initdram(int board_type)
  46. {
  47. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  48. u32 msize = 0;
  49. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
  50. return -1;
  51. /* DDR SDRAM - Main memory */
  52. im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_BASE & LAWBAR_BAR;
  53. msize = spd_sdram();
  54. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  55. /*
  56. * Initialize and enable DDR ECC.
  57. */
  58. ddr_enable_ecc(msize * 1024 * 1024);
  59. #endif
  60. /* Now check memory size (after ECC is initialized) */
  61. msize = get_ram_size(0, msize);
  62. /* return total bus SDRAM size(bytes) -- DDR */
  63. return msize * 1024 * 1024;
  64. }
  65. int checkboard(void)
  66. {
  67. #ifdef VME_CADDY2
  68. puts("Board: esd VME-CADDY/2\n");
  69. #else
  70. puts("Board: esd VME-CPU/8349\n");
  71. #endif
  72. return 0;
  73. }
  74. #ifdef VME_CADDY2
  75. int board_eth_init(bd_t *bis)
  76. {
  77. return pci_eth_init(bis);
  78. }
  79. #endif
  80. #if defined(CONFIG_OF_BOARD_SETUP)
  81. void ft_board_setup(void *blob, bd_t *bd)
  82. {
  83. ft_cpu_setup(blob, bd);
  84. #ifdef CONFIG_PCI
  85. ft_pci_setup(blob, bd);
  86. #endif
  87. }
  88. #endif
  89. int misc_init_r()
  90. {
  91. immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  92. clrsetbits_be32(&im->im_lbc.lcrr, LBCR_LDIS, 0);
  93. return 0;
  94. }
  95. /*
  96. * Provide SPD values for spd_sdram(). Both boards (VME-CADDY/2
  97. * and VME-CADDY/2) have different SDRAM configurations.
  98. */
  99. #ifdef VME_CADDY2
  100. #define SMALL_RAM 0xff
  101. #define LARGE_RAM 0x00
  102. #else
  103. #define SMALL_RAM 0x00
  104. #define LARGE_RAM 0xff
  105. #endif
  106. #define SPD_VAL(a, b) (((a) & SMALL_RAM) | ((b) & LARGE_RAM))
  107. static spd_eeprom_t default_spd_eeprom = {
  108. SPD_VAL(0x80, 0x80), /* 00 use 128 Bytes */
  109. SPD_VAL(0x07, 0x07), /* 01 use 128 Bytes */
  110. SPD_MEMTYPE_DDR2, /* 02 type is DDR2 */
  111. SPD_VAL(0x0d, 0x0d), /* 03 rows: 13 */
  112. SPD_VAL(0x09, 0x0a), /* 04 cols: 9 / 10 */
  113. SPD_VAL(0x00, 0x00), /* 05 */
  114. SPD_VAL(0x40, 0x40), /* 06 */
  115. SPD_VAL(0x00, 0x00), /* 07 */
  116. SPD_VAL(0x05, 0x05), /* 08 */
  117. SPD_VAL(0x30, 0x30), /* 09 */
  118. SPD_VAL(0x45, 0x45), /* 10 */
  119. SPD_VAL(0x02, 0x02), /* 11 ecc used */
  120. SPD_VAL(0x82, 0x82), /* 12 */
  121. SPD_VAL(0x10, 0x10), /* 13 */
  122. SPD_VAL(0x08, 0x08), /* 14 */
  123. SPD_VAL(0x00, 0x00), /* 15 */
  124. SPD_VAL(0x0c, 0x0c), /* 16 */
  125. SPD_VAL(0x04, 0x08), /* 17 banks: 4 / 8 */
  126. SPD_VAL(0x38, 0x38), /* 18 */
  127. SPD_VAL(0x00, 0x00), /* 19 */
  128. SPD_VAL(0x02, 0x02), /* 20 */
  129. SPD_VAL(0x00, 0x00), /* 21 */
  130. SPD_VAL(0x03, 0x03), /* 22 */
  131. SPD_VAL(0x3d, 0x3d), /* 23 */
  132. SPD_VAL(0x45, 0x45), /* 24 */
  133. SPD_VAL(0x50, 0x50), /* 25 */
  134. SPD_VAL(0x45, 0x45), /* 26 */
  135. SPD_VAL(0x3c, 0x3c), /* 27 */
  136. SPD_VAL(0x28, 0x28), /* 28 */
  137. SPD_VAL(0x3c, 0x3c), /* 29 */
  138. SPD_VAL(0x2d, 0x2d), /* 30 */
  139. SPD_VAL(0x20, 0x80), /* 31 */
  140. SPD_VAL(0x20, 0x20), /* 32 */
  141. SPD_VAL(0x27, 0x27), /* 33 */
  142. SPD_VAL(0x10, 0x10), /* 34 */
  143. SPD_VAL(0x17, 0x17), /* 35 */
  144. SPD_VAL(0x3c, 0x3c), /* 36 */
  145. SPD_VAL(0x1e, 0x1e), /* 37 */
  146. SPD_VAL(0x1e, 0x1e), /* 38 */
  147. SPD_VAL(0x00, 0x00), /* 39 */
  148. SPD_VAL(0x00, 0x06), /* 40 */
  149. SPD_VAL(0x37, 0x37), /* 41 */
  150. SPD_VAL(0x4b, 0x7f), /* 42 */
  151. SPD_VAL(0x80, 0x80), /* 43 */
  152. SPD_VAL(0x18, 0x18), /* 44 */
  153. SPD_VAL(0x22, 0x22), /* 45 */
  154. SPD_VAL(0x00, 0x00), /* 46 */
  155. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  156. SPD_VAL(0x10, 0x10), /* 62 */
  157. SPD_VAL(0x7e, 0x1d), /* 63 */
  158. { 'e', 's', 'd', '-', 'g', 'm', 'b', 'h' },
  159. SPD_VAL(0x00, 0x00), /* 72 */
  160. #ifdef VME_CADDY2
  161. { "vme-caddy/2 ram " }
  162. #else
  163. { "vme-cpu/2 ram " }
  164. #endif
  165. };
  166. int vme8349_read_spd(uchar chip, uint addr, int alen, uchar *buffer, int len)
  167. {
  168. int old_bus = I2C_GET_BUS();
  169. unsigned int l, sum;
  170. int valid = 0;
  171. I2C_SET_BUS(0);
  172. if (i2c_read(chip, addr, alen, buffer, len) == 0)
  173. if (memcmp(&buffer[64], &default_spd_eeprom.mid[0], 8) == 0) {
  174. sum = 0;
  175. for (l = 0; l < 63; l++)
  176. sum = (sum + buffer[l]) & 0xff;
  177. if (sum == buffer[63])
  178. valid = 1;
  179. else
  180. printf("Invalid checksum in EEPROM %02x %02x\n",
  181. sum, buffer[63]);
  182. }
  183. if (valid == 0) {
  184. memcpy(buffer, (void *)&default_spd_eeprom, len);
  185. sum = 0;
  186. for (l = 0; l < 63; l++)
  187. sum = (sum + buffer[l]) & 0xff;
  188. if (sum != buffer[63])
  189. printf("Invalid checksum in FLASH %02x %02x\n",
  190. sum, buffer[63]);
  191. buffer[63] = sum;
  192. }
  193. I2C_SET_BUS(old_bus);
  194. return 0;
  195. }