vme8349.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. * SPDX-License-Identifier: GPL-2.0+
  13. */
  14. #include <common.h>
  15. #include <ioports.h>
  16. #include <mpc83xx.h>
  17. #include <asm/mpc8349_pci.h>
  18. #if defined(CONFIG_OF_LIBFDT)
  19. #include <libfdt.h>
  20. #endif
  21. #include <asm/io.h>
  22. #include <asm/mmu.h>
  23. #include <spd.h>
  24. #include <spd_sdram.h>
  25. #include <i2c.h>
  26. #include <netdev.h>
  27. void ddr_enable_ecc(unsigned int dram_size);
  28. phys_size_t initdram(int board_type)
  29. {
  30. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  31. u32 msize = 0;
  32. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
  33. return -1;
  34. /* DDR SDRAM - Main memory */
  35. im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_BASE & LAWBAR_BAR;
  36. msize = spd_sdram();
  37. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  38. /*
  39. * Initialize and enable DDR ECC.
  40. */
  41. ddr_enable_ecc(msize * 1024 * 1024);
  42. #endif
  43. /* Now check memory size (after ECC is initialized) */
  44. msize = get_ram_size(0, msize);
  45. /* return total bus SDRAM size(bytes) -- DDR */
  46. return msize * 1024 * 1024;
  47. }
  48. int checkboard(void)
  49. {
  50. #ifdef VME_CADDY2
  51. puts("Board: esd VME-CADDY/2\n");
  52. #else
  53. puts("Board: esd VME-CPU/8349\n");
  54. #endif
  55. return 0;
  56. }
  57. #ifdef VME_CADDY2
  58. int board_eth_init(bd_t *bis)
  59. {
  60. return pci_eth_init(bis);
  61. }
  62. #endif
  63. #if defined(CONFIG_OF_BOARD_SETUP)
  64. int ft_board_setup(void *blob, bd_t *bd)
  65. {
  66. ft_cpu_setup(blob, bd);
  67. #ifdef CONFIG_PCI
  68. ft_pci_setup(blob, bd);
  69. #endif
  70. return 0;
  71. }
  72. #endif
  73. int misc_init_r()
  74. {
  75. immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  76. clrsetbits_be32(&im->im_lbc.lcrr, LBCR_LDIS, 0);
  77. return 0;
  78. }
  79. /*
  80. * Provide SPD values for spd_sdram(). Both boards (VME-CADDY/2
  81. * and VME-CADDY/2) have different SDRAM configurations.
  82. */
  83. #ifdef VME_CADDY2
  84. #define SMALL_RAM 0xff
  85. #define LARGE_RAM 0x00
  86. #else
  87. #define SMALL_RAM 0x00
  88. #define LARGE_RAM 0xff
  89. #endif
  90. #define SPD_VAL(a, b) (((a) & SMALL_RAM) | ((b) & LARGE_RAM))
  91. static spd_eeprom_t default_spd_eeprom = {
  92. SPD_VAL(0x80, 0x80), /* 00 use 128 Bytes */
  93. SPD_VAL(0x07, 0x07), /* 01 use 128 Bytes */
  94. SPD_MEMTYPE_DDR2, /* 02 type is DDR2 */
  95. SPD_VAL(0x0d, 0x0d), /* 03 rows: 13 */
  96. SPD_VAL(0x09, 0x0a), /* 04 cols: 9 / 10 */
  97. SPD_VAL(0x00, 0x00), /* 05 */
  98. SPD_VAL(0x40, 0x40), /* 06 */
  99. SPD_VAL(0x00, 0x00), /* 07 */
  100. SPD_VAL(0x05, 0x05), /* 08 */
  101. SPD_VAL(0x30, 0x30), /* 09 */
  102. SPD_VAL(0x45, 0x45), /* 10 */
  103. SPD_VAL(0x02, 0x02), /* 11 ecc used */
  104. SPD_VAL(0x82, 0x82), /* 12 */
  105. SPD_VAL(0x10, 0x10), /* 13 */
  106. SPD_VAL(0x08, 0x08), /* 14 */
  107. SPD_VAL(0x00, 0x00), /* 15 */
  108. SPD_VAL(0x0c, 0x0c), /* 16 */
  109. SPD_VAL(0x04, 0x08), /* 17 banks: 4 / 8 */
  110. SPD_VAL(0x38, 0x38), /* 18 */
  111. SPD_VAL(0x00, 0x00), /* 19 */
  112. SPD_VAL(0x02, 0x02), /* 20 */
  113. SPD_VAL(0x00, 0x00), /* 21 */
  114. SPD_VAL(0x03, 0x03), /* 22 */
  115. SPD_VAL(0x3d, 0x3d), /* 23 */
  116. SPD_VAL(0x45, 0x45), /* 24 */
  117. SPD_VAL(0x50, 0x50), /* 25 */
  118. SPD_VAL(0x45, 0x45), /* 26 */
  119. SPD_VAL(0x3c, 0x3c), /* 27 */
  120. SPD_VAL(0x28, 0x28), /* 28 */
  121. SPD_VAL(0x3c, 0x3c), /* 29 */
  122. SPD_VAL(0x2d, 0x2d), /* 30 */
  123. SPD_VAL(0x20, 0x80), /* 31 */
  124. SPD_VAL(0x20, 0x20), /* 32 */
  125. SPD_VAL(0x27, 0x27), /* 33 */
  126. SPD_VAL(0x10, 0x10), /* 34 */
  127. SPD_VAL(0x17, 0x17), /* 35 */
  128. SPD_VAL(0x3c, 0x3c), /* 36 */
  129. SPD_VAL(0x1e, 0x1e), /* 37 */
  130. SPD_VAL(0x1e, 0x1e), /* 38 */
  131. SPD_VAL(0x00, 0x00), /* 39 */
  132. SPD_VAL(0x00, 0x06), /* 40 */
  133. SPD_VAL(0x37, 0x37), /* 41 */
  134. SPD_VAL(0x4b, 0x7f), /* 42 */
  135. SPD_VAL(0x80, 0x80), /* 43 */
  136. SPD_VAL(0x18, 0x18), /* 44 */
  137. SPD_VAL(0x22, 0x22), /* 45 */
  138. SPD_VAL(0x00, 0x00), /* 46 */
  139. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  140. SPD_VAL(0x10, 0x10), /* 62 */
  141. SPD_VAL(0x7e, 0x1d), /* 63 */
  142. { 'e', 's', 'd', '-', 'g', 'm', 'b', 'h' },
  143. SPD_VAL(0x00, 0x00), /* 72 */
  144. #ifdef VME_CADDY2
  145. { "vme-caddy/2 ram " }
  146. #else
  147. { "vme-cpu/2 ram " }
  148. #endif
  149. };
  150. int vme8349_read_spd(uchar chip, uint addr, int alen, uchar *buffer, int len)
  151. {
  152. int old_bus = i2c_get_bus_num();
  153. unsigned int l, sum;
  154. int valid = 0;
  155. i2c_set_bus_num(0);
  156. if (i2c_read(chip, addr, alen, buffer, len) == 0)
  157. if (memcmp(&buffer[64], &default_spd_eeprom.mid[0], 8) == 0) {
  158. sum = 0;
  159. for (l = 0; l < 63; l++)
  160. sum = (sum + buffer[l]) & 0xff;
  161. if (sum == buffer[63])
  162. valid = 1;
  163. else
  164. printf("Invalid checksum in EEPROM %02x %02x\n",
  165. sum, buffer[63]);
  166. }
  167. if (valid == 0) {
  168. memcpy(buffer, (void *)&default_spd_eeprom, len);
  169. sum = 0;
  170. for (l = 0; l < 63; l++)
  171. sum = (sum + buffer[l]) & 0xff;
  172. if (sum != buffer[63])
  173. printf("Invalid checksum in FLASH %02x %02x\n",
  174. sum, buffer[63]);
  175. buffer[63] = sum;
  176. }
  177. i2c_set_bus_num(old_bus);
  178. return 0;
  179. }