kup4k.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /*
  2. * (C) Copyright 2000-2004
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. * Klaus Heydeck, Kieback & Peter GmbH & Co KG, heydeck@kieback-peter.de
  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. #include <command.h>
  26. #include <libfdt.h>
  27. #include <mpc8xx.h>
  28. #include <hwconfig.h>
  29. #include <i2c.h>
  30. #include "../common/kup.h"
  31. #include <asm/io.h>
  32. static unsigned char swapbyte(unsigned char c);
  33. static int read_diag(void);
  34. DECLARE_GLOBAL_DATA_PTR;
  35. /* ----------------------------------------------------------------------- */
  36. #define _NOT_USED_ 0xFFFFFFFF
  37. const uint sdram_table[] = {
  38. /*
  39. * Single Read. (Offset 0 in UPMA RAM)
  40. */
  41. 0x1F07FC04, 0xEEAEFC04, 0x11ADFC04, 0xEFBBBC00,
  42. 0x1FF77C47, /* last */
  43. /*
  44. * SDRAM Initialization (offset 5 in UPMA RAM)
  45. *
  46. * This is no UPM entry point. The following definition uses
  47. * the remaining space to establish an initialization
  48. * sequence, which is executed by a RUN command.
  49. *
  50. */
  51. 0x1FF77C35, 0xEFEABC34, 0x1FB57C35, /* last */
  52. /*
  53. * Burst Read. (Offset 8 in UPMA RAM)
  54. */
  55. 0x1F07FC04, 0xEEAEFC04, 0x10ADFC04, 0xF0AFFC00,
  56. 0xF0AFFC00, 0xF1AFFC00, 0xEFBBBC00, 0x1FF77C47, /* last */
  57. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  58. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  59. /*
  60. * Single Write. (Offset 18 in UPMA RAM)
  61. */
  62. 0x1F27FC04, 0xEEAEBC00, 0x01B93C04, 0x1FF77C47, /* last */
  63. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  64. /*
  65. * Burst Write. (Offset 20 in UPMA RAM)
  66. */
  67. 0x1F07FC04, 0xEEAEBC00, 0x10AD7C00, 0xF0AFFC00,
  68. 0xF0AFFC00, 0xE1BBBC04, 0x1FF77C47, /* last */
  69. _NOT_USED_,
  70. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  71. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  72. /*
  73. * Refresh (Offset 30 in UPMA RAM)
  74. */
  75. 0x1FF5FC84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
  76. 0xFFFFFC84, 0xFFFFFC07, /* last */
  77. _NOT_USED_, _NOT_USED_,
  78. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  79. /*
  80. * Exception. (Offset 3c in UPMA RAM)
  81. */
  82. 0x7FFFFC07, /* last */
  83. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  84. };
  85. /* ----------------------------------------------------------------------- */
  86. /*
  87. * Check Board Identity:
  88. */
  89. int checkboard(void)
  90. {
  91. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  92. uchar rev,mod,tmp,pcf,ak_rev,ak_mod;
  93. /*
  94. * Init ChipSelect #4 (CAN + HW-Latch)
  95. */
  96. out_be32(&immap->im_memctl.memc_or4, CONFIG_SYS_OR4);
  97. out_be32(&immap->im_memctl.memc_br4, CONFIG_SYS_BR4);
  98. /*
  99. * Init ChipSelect #5 (S1D13768)
  100. */
  101. out_be32(&immap->im_memctl.memc_or5, CONFIG_SYS_OR5);
  102. out_be32(&immap->im_memctl.memc_br5, CONFIG_SYS_BR5);
  103. tmp = swapbyte(in_8((unsigned char*) LATCH_ADDR));
  104. rev = (tmp & 0xF8) >> 3;
  105. mod = (tmp & 0x07);
  106. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  107. if (read_diag())
  108. gd->flags &= ~GD_FLG_SILENT;
  109. printf("Board: KUP4K Rev %d.%d AK:",rev,mod);
  110. /*
  111. * TI Application report: Before using the IO as an input,
  112. * a high must be written to the IO first
  113. */
  114. pcf = 0xFF;
  115. i2c_write(0x21, 0, 0 , &pcf, 1);
  116. if (i2c_read(0x21, 0, 0, &pcf, 1)) {
  117. puts("n/a\n");
  118. } else {
  119. ak_rev = (pcf & 0xF8) >> 3;
  120. ak_mod = (pcf & 0x07);
  121. printf("%d.%d\n", ak_rev, ak_mod);
  122. }
  123. return 0;
  124. }
  125. /* ----------------------------------------------------------------------- */
  126. phys_size_t initdram(int board_type)
  127. {
  128. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  129. volatile memctl8xx_t *memctl = &immap->im_memctl;
  130. long int size = 0;
  131. uchar *latch,rev,mod,tmp;
  132. /*
  133. * Init ChipSelect #4 (CAN + HW-Latch) to determine Hardware Revision
  134. * Rev 1..6 -> 48 MB RAM; Rev >= 7 -> 96 MB
  135. */
  136. out_be32(&immap->im_memctl.memc_or4, CONFIG_SYS_OR4);
  137. out_be32(&immap->im_memctl.memc_br4, CONFIG_SYS_BR4);
  138. latch = (uchar *)0x90000200;
  139. tmp = swapbyte(*latch);
  140. rev = (tmp & 0xF8) >> 3;
  141. mod = (tmp & 0x07);
  142. upmconfig(UPMA, (uint *) sdram_table,
  143. sizeof (sdram_table) / sizeof (uint));
  144. out_be16(&memctl->memc_mptpr, CONFIG_SYS_MPTPR);
  145. out_be32(&memctl->memc_mar, 0x00000088);
  146. /* no refresh yet */
  147. if(rev >= 7) {
  148. out_be32(&memctl->memc_mamr,
  149. CONFIG_SYS_MAMR_9COL & (~(MAMR_PTAE)));
  150. } else {
  151. out_be32(&memctl->memc_mamr,
  152. CONFIG_SYS_MAMR_8COL & (~(MAMR_PTAE)));
  153. }
  154. udelay(200);
  155. /* perform SDRAM initializsation sequence */
  156. /* SDRAM bank 0 */
  157. out_be32(&memctl->memc_mcr, 0x80002105);
  158. udelay(1);
  159. out_be32(&memctl->memc_mcr, 0x80002830); /* execute twice */
  160. udelay(1);
  161. out_be32(&memctl->memc_mcr, 0x80002106); /* RUN MRS Pattern from loc 6 */
  162. udelay(1);
  163. /* SDRAM bank 1 */
  164. out_be32(&memctl->memc_mcr, 0x80004105);
  165. udelay(1);
  166. out_be32(&memctl->memc_mcr, 0x80004830); /* execute twice */
  167. udelay(1);
  168. out_be32(&memctl->memc_mcr, 0x80004106); /* RUN MRS Pattern from loc 6 */
  169. udelay(1);
  170. /* SDRAM bank 2 */
  171. out_be32(&memctl->memc_mcr, 0x80006105);
  172. udelay(1);
  173. out_be32(&memctl->memc_mcr, 0x80006830); /* execute twice */
  174. udelay(1);
  175. out_be32(&memctl->memc_mcr, 0x80006106); /* RUN MRS Pattern from loc 6 */
  176. udelay(1);
  177. setbits_be32(&memctl->memc_mamr, MAMR_PTAE); /* enable refresh */
  178. udelay(1000);
  179. out_be16(&memctl->memc_mptpr, CONFIG_SYS_MPTPR);
  180. udelay(1000);
  181. if(rev >= 7) {
  182. size = 32 * 3 * 1024 * 1024;
  183. out_be32(&memctl->memc_or1, CONFIG_SYS_OR1_9COL);
  184. out_be32(&memctl->memc_br1, CONFIG_SYS_BR1_9COL);
  185. out_be32(&memctl->memc_or2, CONFIG_SYS_OR2_9COL);
  186. out_be32(&memctl->memc_br2, CONFIG_SYS_BR2_9COL);
  187. out_be32(&memctl->memc_or3, CONFIG_SYS_OR3_9COL);
  188. out_be32(&memctl->memc_br3, CONFIG_SYS_BR3_9COL);
  189. } else {
  190. size = 16 * 3 * 1024 * 1024;
  191. out_be32(&memctl->memc_or1, CONFIG_SYS_OR1_8COL);
  192. out_be32(&memctl->memc_br1, CONFIG_SYS_BR1_8COL);
  193. out_be32(&memctl->memc_or2, CONFIG_SYS_OR2_8COL);
  194. out_be32(&memctl->memc_br2, CONFIG_SYS_BR2_8COL);
  195. out_be32(&memctl->memc_or3, CONFIG_SYS_OR3_8COL);
  196. out_be32(&memctl->memc_br3, CONFIG_SYS_BR3_8COL);
  197. }
  198. return (size);
  199. }
  200. /* ----------------------------------------------------------------------- */
  201. int misc_init_r(void)
  202. {
  203. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  204. #ifdef CONFIG_IDE_LED
  205. /* Configure PA8 as output port */
  206. setbits_be16(&immap->im_ioport.iop_padir, PA_8);
  207. setbits_be16(&immap->im_ioport.iop_paodr, PA_8);
  208. clrbits_be16(&immap->im_ioport.iop_papar, PA_8);
  209. setbits_be16(&immap->im_ioport.iop_padat, PA_8); /* turn it off */
  210. #endif
  211. load_sernum_ethaddr();
  212. setenv("hw","4k");
  213. poweron_key();
  214. return (0);
  215. }
  216. static int read_diag(void)
  217. {
  218. int diag;
  219. immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
  220. clrbits_be16(&immr->im_ioport.iop_pcdir, PC_4); /* input */
  221. clrbits_be16(&immr->im_ioport.iop_pcpar, PC_4); /* gpio */
  222. setbits_be16(&immr->im_ioport.iop_pcdir, PC_5); /* output */
  223. clrbits_be16(&immr->im_ioport.iop_pcpar, PC_4); /* gpio */
  224. setbits_be16(&immr->im_ioport.iop_pcdat, PC_5); /* 1 */
  225. udelay(500);
  226. if (in_be16(&immr->im_ioport.iop_pcdat) & PC_4) {
  227. clrbits_be16(&immr->im_ioport.iop_pcdat, PC_5);/* 0 */
  228. udelay(500);
  229. if(in_be16(&immr->im_ioport.iop_pcdat) & PC_4)
  230. diag = 0;
  231. else
  232. diag = 1;
  233. } else {
  234. diag = 0;
  235. }
  236. clrbits_be16(&immr->im_ioport.iop_pcdir, PC_5); /* input */
  237. return (diag);
  238. }
  239. static unsigned char swapbyte(unsigned char c)
  240. {
  241. unsigned char result = 0;
  242. int i = 0;
  243. for(i = 0; i < 8; ++i) {
  244. result = result << 1;
  245. result |= (c & 1);
  246. c = c >> 1;
  247. }
  248. return result;
  249. }
  250. /*
  251. * Device Tree Support
  252. */
  253. #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
  254. void ft_board_setup(void *blob, bd_t *bd)
  255. {
  256. ft_cpu_setup(blob, bd);
  257. }
  258. #endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */