mgsuvd.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * (C) Copyright 2007
  3. * Heiko Schocher, DENX Software Engineering, hs@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 <mpc8xx.h>
  25. #include <asm/io.h>
  26. #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
  27. #include <libfdt.h>
  28. #endif
  29. extern int ivm_read_eeprom (void);
  30. DECLARE_GLOBAL_DATA_PTR;
  31. const uint sdram_table[] =
  32. {
  33. 0x0f07fc04, 0x0ffffc04, 0x00bdfc04, 0x0ff77c00,
  34. 0x1ffffc05, 0xfffffc04, 0xfffffc04, 0xfffffc04,
  35. /* 0x08 Burst Read */
  36. 0x0f07fc04, 0x0ffffc04, 0x00bdfc04, 0x00fffc00,
  37. 0x00fffc00, 0x00fffc00, 0x0ff77c00, 0x1ffffc05,
  38. /* 0x10 Load mode register */
  39. 0x0ffffc34, 0x0ff57c04, 0x0ffffc04, 0x1ffffc05,
  40. 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04,
  41. /* 0x18 Single Write */
  42. 0x0f07fc04, 0x0ffffc00, 0x00bd7c04, 0x0ffffc04,
  43. 0x0ff77c04, 0x1ffffc05, 0xfffffc04, 0xfffffc04,
  44. /* 0x20 Burst Write */
  45. 0x0f07fc04, 0x0ffffc00, 0x00bd7c00, 0x00fffc00,
  46. 0x00fffc00, 0x00fffc04, 0x0ffffc04, 0x0ff77c04,
  47. 0x1ffffc05, 0xfffffc04, 0xfffffc04, 0xfffffc04,
  48. 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04,
  49. /* 0x30 Precharge all and Refresh */
  50. 0x0ff77c04, 0x0ffffc04, 0x0ff5fc84, 0x0ffffc04,
  51. 0x0ffffc04, 0x0ffffc84, 0x1ffffc05, 0xfffffc04,
  52. 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04,
  53. /* 0x3C Exception */
  54. 0x7ffffc04, 0xfffffc07, 0xfffffc04, 0xfffffc04,
  55. };
  56. int checkboard (void)
  57. {
  58. puts ("Board: Keymile mgsuvd\n");
  59. return (0);
  60. }
  61. phys_size_t initdram (int board_type)
  62. {
  63. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  64. volatile memctl8xx_t *memctl = &immap->im_memctl;
  65. long int size;
  66. upmconfig (UPMB, (uint *) sdram_table,
  67. sizeof (sdram_table) / sizeof (uint));
  68. /*
  69. * Preliminary prescaler for refresh (depends on number of
  70. * banks): This value is selected for four cycles every 62.4 us
  71. * with two SDRAM banks or four cycles every 31.2 us with one
  72. * bank. It will be adjusted after memory sizing.
  73. */
  74. memctl->memc_mptpr = CONFIG_SYS_MPTPR;
  75. /*
  76. * The following value is used as an address (i.e. opcode) for
  77. * the LOAD MODE REGISTER COMMAND during SDRAM initialisation. If
  78. * the port size is 32bit the SDRAM does NOT "see" the lower two
  79. * address lines, i.e. mar=0x00000088 -> opcode=0x00000022 for
  80. * MICRON SDRAMs:
  81. * -> 0 00 010 0 010
  82. * | | | | +- Burst Length = 4
  83. * | | | +----- Burst Type = Sequential
  84. * | | +------- CAS Latency = 2
  85. * | +----------- Operating Mode = Standard
  86. * +-------------- Write Burst Mode = Programmed Burst Length
  87. */
  88. memctl->memc_mar = CONFIG_SYS_MAR;
  89. /*
  90. * Map controller banks 1 to the SDRAM banks 1 at
  91. * preliminary addresses - these have to be modified after the
  92. * SDRAM size has been determined.
  93. */
  94. memctl->memc_or1 = CONFIG_SYS_OR1_PRELIM;
  95. memctl->memc_br1 = CONFIG_SYS_BR1_PRELIM;
  96. memctl->memc_mbmr = CONFIG_SYS_MBMR & (~(MBMR_PTBE)); /* no refresh yet */
  97. udelay (200);
  98. /* perform SDRAM initializsation sequence */
  99. memctl->memc_mcr = 0x80802830; /* SDRAM bank 0 */
  100. udelay (1);
  101. memctl->memc_mcr = 0x80802110; /* SDRAM bank 0 - execute twice */
  102. udelay (1);
  103. memctl->memc_mbmr |= MBMR_PTBE; /* enable refresh */
  104. udelay (1000);
  105. /*
  106. * Check Bank 0 Memory Size for re-configuration
  107. *
  108. */
  109. size = get_ram_size(SDRAM_BASE1_PRELIM, SDRAM_MAX_SIZE);
  110. udelay (1000);
  111. debug ("SDRAM Bank 0: %ld MB\n", size >> 20);
  112. return (size);
  113. }
  114. /*
  115. * Early board initalization.
  116. */
  117. int board_early_init_r(void)
  118. {
  119. /* setup the UPIOx */
  120. out_8((u8 *)(CONFIG_SYS_PIGGY_BASE + 0x02), 0xc0);
  121. out_8((u8 *)(CONFIG_SYS_PIGGY_BASE + 0x03), 0x35);
  122. return 0;
  123. }
  124. int hush_init_var (void)
  125. {
  126. ivm_read_eeprom ();
  127. return 0;
  128. }
  129. #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
  130. /*
  131. * update "memory" property in the blob
  132. */
  133. void ft_blob_update (void *blob, bd_t *bd)
  134. {
  135. int ret, nodeoffset = 0;
  136. ulong brg_data[1] = {0};
  137. ulong memory_data[2] = {0};
  138. ulong flash_data[4] = {0};
  139. memory_data[0] = cpu_to_be32 (bd->bi_memstart);
  140. memory_data[1] = cpu_to_be32 (bd->bi_memsize);
  141. nodeoffset = fdt_path_offset (blob, "/memory");
  142. if (nodeoffset >= 0) {
  143. ret = fdt_setprop (blob, nodeoffset, "reg", memory_data,
  144. sizeof (memory_data));
  145. if (ret < 0)
  146. printf("ft_blob_update(): cannot set /memory/reg "
  147. "property err:%s\n", fdt_strerror (ret));
  148. } else {
  149. /* memory node is required in dts */
  150. printf("ft_blob_update(): cannot find /memory node "
  151. "err:%s\n", fdt_strerror (nodeoffset));
  152. }
  153. flash_data[2] = cpu_to_be32 (bd->bi_flashstart);
  154. flash_data[3] = cpu_to_be32 (bd->bi_flashsize);
  155. nodeoffset = fdt_path_offset (blob, "/localbus");
  156. if (nodeoffset >= 0) {
  157. ret = fdt_setprop (blob, nodeoffset, "ranges", flash_data,
  158. sizeof (flash_data));
  159. if (ret < 0)
  160. printf("ft_blob_update(): cannot set /localbus/ranges "
  161. "property err:%s\n", fdt_strerror (ret));
  162. } else {
  163. /* memory node is required in dts */
  164. printf("ft_blob_update(): cannot find /localbus node "
  165. "err:%s\n", fdt_strerror (nodeoffset));
  166. }
  167. /* BRG */
  168. brg_data[0] = cpu_to_be32 (bd->bi_busfreq);
  169. nodeoffset = fdt_path_offset (blob, "/soc/cpm");
  170. if (nodeoffset >= 0) {
  171. ret = fdt_setprop (blob, nodeoffset, "brg-frequency", brg_data,
  172. sizeof (brg_data));
  173. if (ret < 0)
  174. printf("ft_blob_update(): cannot set /soc/cpm/brg-frequency "
  175. "property err:%s\n", fdt_strerror(ret));
  176. } else {
  177. /* memory node is required in dts */
  178. printf("ft_blob_update(): cannot find /soc/cpm node "
  179. "err:%s\n", fdt_strerror (nodeoffset));
  180. }
  181. /* MAC Adresse */
  182. nodeoffset = fdt_path_offset (blob, "/soc/cpm/ethernet");
  183. if (nodeoffset >= 0) {
  184. ret = fdt_setprop (blob, nodeoffset, "mac-address", bd->bi_enetaddr,
  185. sizeof (uchar) * 6);
  186. if (ret < 0)
  187. printf("ft_blob_update(): cannot set /soc/cpm/scc/mac-address "
  188. "property err:%s\n", fdt_strerror (ret));
  189. } else {
  190. /* memory node is required in dts */
  191. printf("ft_blob_update(): cannot find /soc/cpm/ethernet node "
  192. "err:%s\n", fdt_strerror (nodeoffset));
  193. }
  194. }
  195. void ft_board_setup(void *blob, bd_t *bd)
  196. {
  197. ft_cpu_setup (blob, bd);
  198. ft_blob_update (blob, bd);
  199. }
  200. #endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */
  201. int i2c_soft_read_pin (void)
  202. {
  203. int val;
  204. *(unsigned short *)(I2C_BASE_DIR) &= ~SDA_CONF;
  205. udelay(1);
  206. val = *(unsigned char *)(I2C_BASE_PORT);
  207. return ((val & SDA_BIT) == SDA_BIT);
  208. }