km82xx.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. /*
  2. * (C) Copyright 2007 - 2008
  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 <mpc8260.h>
  25. #include <ioports.h>
  26. #include <malloc.h>
  27. #include <asm/io.h>
  28. #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
  29. #include <libfdt.h>
  30. #endif
  31. #include <i2c.h>
  32. #include "../common/common.h"
  33. /*
  34. * I/O Port configuration table
  35. *
  36. * if conf is 1, then that port pin will be configured at boot time
  37. * according to the five values podr/pdir/ppar/psor/pdat for that entry
  38. */
  39. const iop_conf_t iop_conf_tab[4][32] = {
  40. /* Port A */
  41. { /* conf ppar psor pdir podr pdat */
  42. { 0, 0, 0, 0, 0, 0 }, /* PA31 */
  43. { 0, 0, 0, 0, 0, 0 }, /* PA30 */
  44. { 0, 0, 0, 0, 0, 0 }, /* PA29 */
  45. { 0, 0, 0, 0, 0, 0 }, /* PA28 */
  46. { 0, 0, 0, 0, 0, 0 }, /* PA27 */
  47. { 0, 0, 0, 0, 0, 0 }, /* PA26 */
  48. { 0, 0, 0, 0, 0, 0 }, /* PA25 */
  49. { 0, 0, 0, 0, 0, 0 }, /* PA24 */
  50. { 0, 0, 0, 0, 0, 0 }, /* PA23 */
  51. { 0, 0, 0, 0, 0, 0 }, /* PA22 */
  52. { 0, 0, 0, 0, 0, 0 }, /* PA21 */
  53. { 0, 0, 0, 0, 0, 0 }, /* PA20 */
  54. { 0, 0, 0, 0, 0, 0 }, /* PA19 */
  55. { 0, 0, 0, 0, 0, 0 }, /* PA18 */
  56. { 0, 0, 0, 0, 0, 0 }, /* PA17 */
  57. { 0, 0, 0, 0, 0, 0 }, /* PA16 */
  58. { 0, 0, 0, 0, 0, 0 }, /* PA15 */
  59. { 0, 0, 0, 0, 0, 0 }, /* PA14 */
  60. { 0, 0, 0, 0, 0, 0 }, /* PA13 */
  61. { 0, 0, 0, 0, 0, 0 }, /* PA12 */
  62. { 0, 0, 0, 0, 0, 0 }, /* PA11 */
  63. { 0, 0, 0, 0, 0, 0 }, /* PA10 */
  64. { 1, 1, 0, 1, 0, 0 }, /* PA9 SMC2 TxD */
  65. { 1, 1, 0, 0, 0, 0 }, /* PA8 SMC2 RxD */
  66. { 0, 0, 0, 0, 0, 0 }, /* PA7 */
  67. { 0, 0, 0, 0, 0, 0 }, /* PA6 */
  68. { 0, 0, 0, 0, 0, 0 }, /* PA5 */
  69. { 0, 0, 0, 0, 0, 0 }, /* PA4 */
  70. { 0, 0, 0, 0, 0, 0 }, /* PA3 */
  71. { 0, 0, 0, 0, 0, 0 }, /* PA2 */
  72. { 0, 0, 0, 0, 0, 0 }, /* PA1 */
  73. { 0, 0, 0, 0, 0, 0 } /* PA0 */
  74. },
  75. /* Port B */
  76. { /* conf ppar psor pdir podr pdat */
  77. { 0, 0, 0, 0, 0, 0 }, /* PB31 */
  78. { 0, 0, 0, 0, 0, 0 }, /* PB30 */
  79. { 0, 0, 0, 0, 0, 0 }, /* PB29 */
  80. { 0, 0, 0, 0, 0, 0 }, /* PB28 */
  81. { 0, 0, 0, 0, 0, 0 }, /* PB27 */
  82. { 0, 0, 0, 0, 0, 0 }, /* PB26 */
  83. { 0, 0, 0, 0, 0, 0 }, /* PB25 */
  84. { 0, 0, 0, 0, 0, 0 }, /* PB24 */
  85. { 0, 0, 0, 0, 0, 0 }, /* PB23 */
  86. { 0, 0, 0, 0, 0, 0 }, /* PB22 */
  87. { 0, 0, 0, 0, 0, 0 }, /* PB21 */
  88. { 0, 0, 0, 0, 0, 0 }, /* PB20 */
  89. { 0, 0, 0, 0, 0, 0 }, /* PB19 */
  90. { 0, 0, 0, 0, 0, 0 }, /* PB18 */
  91. { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  92. { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  93. { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  94. { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  95. { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  96. { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  97. { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  98. { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  99. { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  100. { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  101. { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  102. { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  103. { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  104. { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  105. { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  106. { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  107. { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  108. { 0, 0, 0, 0, 0, 0 } /* non-existent */
  109. },
  110. /* Port C */
  111. { /* conf ppar psor pdir podr pdat */
  112. { 0, 0, 0, 0, 0, 0 }, /* PC31 */
  113. { 0, 0, 0, 0, 0, 0 }, /* PC30 */
  114. { 0, 0, 0, 0, 0, 0 }, /* PC29 */
  115. { 0, 0, 0, 0, 0, 0 }, /* PC28 */
  116. { 0, 0, 0, 0, 0, 0 }, /* PC27 */
  117. { 0, 0, 0, 0, 0, 0 }, /* PC26 */
  118. { 1, 1, 0, 0, 0, 0 }, /* PC25 RxClk */
  119. { 1, 1, 0, 0, 0, 0 }, /* PC24 TxClk */
  120. { 0, 0, 0, 0, 0, 0 }, /* PC23 */
  121. { 0, 0, 0, 0, 0, 0 }, /* PC22 */
  122. { 0, 0, 0, 0, 0, 0 }, /* PC21 */
  123. { 0, 0, 0, 0, 0, 0 }, /* PC20 */
  124. { 0, 0, 0, 0, 0, 0 }, /* PC19 */
  125. { 0, 0, 0, 0, 0, 0 }, /* PC18 */
  126. { 0, 0, 0, 0, 0, 0 }, /* PC17 */
  127. { 0, 0, 0, 0, 0, 0 }, /* PC16 */
  128. { 0, 0, 0, 0, 0, 0 }, /* PC15 */
  129. { 0, 0, 0, 0, 0, 0 }, /* PC14 */
  130. { 0, 0, 0, 0, 0, 0 }, /* PC13 */
  131. { 0, 0, 0, 0, 0, 0 }, /* PC12 */
  132. { 0, 0, 0, 0, 0, 0 }, /* PC11 */
  133. { 0, 0, 0, 0, 0, 0 }, /* PC10 */
  134. { 1, 1, 0, 0, 0, 0 }, /* PC9 SCC4: CTS */
  135. { 1, 1, 0, 0, 0, 0 }, /* PC8 SCC4: CD */
  136. { 0, 0, 0, 0, 0, 0 }, /* PC7 */
  137. { 0, 0, 0, 0, 0, 0 }, /* PC6 */
  138. { 0, 0, 0, 0, 0, 0 }, /* PC5 */
  139. { 0, 0, 0, 0, 0, 0 }, /* PC4 */
  140. { 0, 0, 0, 0, 0, 0 }, /* PC3 */
  141. { 0, 0, 0, 0, 0, 0 }, /* PC2 */
  142. { 0, 0, 0, 0, 0, 0 }, /* PC1 */
  143. { 0, 0, 0, 0, 0, 0 }, /* PC0 */
  144. },
  145. /* Port D */
  146. { /* conf ppar psor pdir podr pdat */
  147. { 0, 0, 0, 0, 0, 0 }, /* PD31 */
  148. { 0, 0, 0, 0, 0, 0 }, /* PD30 */
  149. { 0, 0, 0, 0, 0, 0 }, /* PD29 */
  150. { 0, 0, 0, 0, 0, 0 }, /* PD28 */
  151. { 0, 0, 0, 0, 0, 0 }, /* PD27 */
  152. { 0, 0, 0, 0, 0, 0 }, /* PD26 */
  153. { 0, 0, 0, 0, 0, 0 }, /* PD25 */
  154. { 0, 0, 0, 0, 0, 0 }, /* PD24 */
  155. { 0, 0, 0, 0, 0, 0 }, /* PD23 */
  156. { 1, 1, 0, 0, 0, 0 }, /* PD22 SCC4: RXD */
  157. { 1, 1, 0, 1, 0, 0 }, /* PD21 SCC4: TXD */
  158. { 1, 1, 0, 1, 0, 0 }, /* PD20 SCC4: RTS */
  159. { 0, 0, 0, 0, 0, 0 }, /* PD19 */
  160. { 0, 0, 0, 0, 0, 0 }, /* PD18 */
  161. { 0, 0, 0, 0, 0, 0 }, /* PD17 */
  162. { 0, 0, 0, 0, 0, 0 }, /* PD16 */
  163. #if defined(CONFIG_HARD_I2C)
  164. { 1, 1, 1, 0, 1, 0 }, /* PD15 I2C SDA */
  165. { 1, 1, 1, 0, 1, 0 }, /* PD14 I2C SCL */
  166. #else
  167. { 1, 0, 0, 0, 1, 1 }, /* PD15 */
  168. { 1, 0, 0, 1, 1, 1 }, /* PD14 */
  169. #endif
  170. { 0, 0, 0, 0, 0, 0 }, /* PD13 */
  171. { 0, 0, 0, 0, 0, 0 }, /* PD12 */
  172. { 0, 0, 0, 0, 0, 0 }, /* PD11 */
  173. { 0, 0, 0, 0, 0, 0 }, /* PD10 */
  174. { 0, 0, 0, 0, 0, 0 }, /* PD9 */
  175. { 0, 0, 0, 0, 0, 0 }, /* PD8 */
  176. { 0, 0, 0, 0, 0, 0 }, /* PD7 */
  177. { 0, 0, 0, 0, 0, 0 }, /* PD6 */
  178. { 0, 0, 0, 0, 0, 0 }, /* PD5 */
  179. { 0, 0, 0, 0, 0, 0 }, /* PD4 */
  180. { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  181. { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  182. { 0, 0, 0, 0, 0, 0 }, /* non-existent */
  183. { 0, 0, 0, 0, 0, 0 } /* non-existent */
  184. }
  185. };
  186. /*
  187. * Try SDRAM initialization with P/LSDMR=sdmr and ORx=orx
  188. *
  189. * This routine performs standard 8260 initialization sequence
  190. * and calculates the available memory size. It may be called
  191. * several times to try different SDRAM configurations on both
  192. * 60x and local buses.
  193. */
  194. static long int try_init(memctl8260_t *memctl, ulong sdmr,
  195. ulong orx, uchar *base)
  196. {
  197. uchar c = 0xff;
  198. ulong maxsize, size;
  199. int i;
  200. /*
  201. * We must be able to test a location outsize the maximum legal size
  202. * to find out THAT we are outside; but this address still has to be
  203. * mapped by the controller. That means, that the initial mapping has
  204. * to be (at least) twice as large as the maximum expected size.
  205. */
  206. maxsize = (1 + (~orx | 0x7fff))/* / 2*/;
  207. out_be32(&memctl->memc_or1, orx);
  208. /*
  209. * Quote from 8260 UM (10.4.2 SDRAM Power-On Initialization, 10-35):
  210. *
  211. * "At system reset, initialization software must set up the
  212. * programmable parameters in the memory controller banks registers
  213. * (ORx, BRx, P/LSDMR). After all memory parameters are configured,
  214. * system software should execute the following initialization sequence
  215. * for each SDRAM device.
  216. *
  217. * 1. Issue a PRECHARGE-ALL-BANKS command
  218. * 2. Issue eight CBR REFRESH commands
  219. * 3. Issue a MODE-SET command to initialize the mode register
  220. *
  221. * The initial commands are executed by setting P/LSDMR[OP] and
  222. * accessing the SDRAM with a single-byte transaction."
  223. *
  224. * The appropriate BRx/ORx registers have already been set when we
  225. * get here. The SDRAM can be accessed at the address
  226. * CONFIG_SYS_SDRAM_BASE.
  227. */
  228. out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_PREA);
  229. out_8(base, c);
  230. out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_CBRR);
  231. for (i = 0; i < 8; i++)
  232. out_8(base, c);
  233. out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_MRW);
  234. /* setting MR on address lines */
  235. out_8((uchar *)(base + CONFIG_SYS_MRS_OFFS), c);
  236. out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_NORM | PSDMR_RFEN);
  237. out_8(base, c);
  238. size = get_ram_size((long *)base, maxsize);
  239. out_be32(&memctl->memc_or1, orx | ~(size - 1));
  240. return size;
  241. }
  242. #ifdef CONFIG_SYS_SDRAM_LIST
  243. /*
  244. * If CONFIG_SYS_SDRAM_LIST is defined, we cycle through all SDRAM
  245. * configurations therein (should be from high to lower) to find the
  246. * one actually matching the current configuration.
  247. * CONFIG_SYS_PSDMR and CONFIG_SYS_OR1 will contain the base values which are
  248. * common among all possible configurations; values in CONFIG_SYS_SDRAM_LIST
  249. * (defined as the initialization value for the array of struct sdram_conf_s)
  250. * will then be ORed with such base values.
  251. */
  252. struct sdram_conf_s {
  253. ulong size;
  254. int or1;
  255. int psdmr;
  256. };
  257. static struct sdram_conf_s sdram_conf[] = CONFIG_SYS_SDRAM_LIST;
  258. static long probe_sdram(memctl8260_t *memctl)
  259. {
  260. int n = 0;
  261. long psize = 0;
  262. for (n = 0; n < ARRAY_SIZE(sdram_conf); psize = 0, n++) {
  263. psize = try_init(memctl,
  264. CONFIG_SYS_PSDMR | sdram_conf[n].psdmr,
  265. CONFIG_SYS_OR1 | sdram_conf[n].or1,
  266. (uchar *) CONFIG_SYS_SDRAM_BASE);
  267. debug("Probing %ld bytes returned %ld\n",
  268. sdram_conf[n].size, psize);
  269. if (psize == sdram_conf[n].size)
  270. break;
  271. }
  272. return psize;
  273. }
  274. #else /* CONFIG_SYS_SDRAM_LIST */
  275. static long probe_sdram(memctl8260_t *memctl)
  276. {
  277. return try_init(memctl, CONFIG_SYS_PSDMR, CONFIG_SYS_OR1,
  278. (uchar *) CONFIG_SYS_SDRAM_BASE);
  279. }
  280. #endif /* CONFIG_SYS_SDRAM_LIST */
  281. phys_size_t initdram(int board_type)
  282. {
  283. immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  284. memctl8260_t *memctl = &immap->im_memctl;
  285. long psize;
  286. out_8(&memctl->memc_psrt, CONFIG_SYS_PSRT);
  287. out_be16(&memctl->memc_mptpr, CONFIG_SYS_MPTPR);
  288. #ifndef CONFIG_SYS_RAMBOOT
  289. /* 60x SDRAM setup:
  290. */
  291. psize = probe_sdram(memctl);
  292. #endif /* CONFIG_SYS_RAMBOOT */
  293. icache_enable();
  294. return psize;
  295. }
  296. int checkboard(void)
  297. {
  298. #if defined(CONFIG_MGCOGE)
  299. puts("Board: Keymile mgcoge");
  300. #else
  301. puts("Board: Keymile mgcoge3ne");
  302. #endif
  303. if (ethernet_present())
  304. puts(" with PIGGY.");
  305. puts("\n");
  306. return 0;
  307. }
  308. int last_stage_init(void)
  309. {
  310. struct bfticu_iomap *base =
  311. (struct bfticu_iomap *)CONFIG_SYS_FPGA_BASE;
  312. u8 dip_switch;
  313. dip_switch = in_8(&base->mswitch);
  314. dip_switch &= BFTICU_DIPSWITCH_MASK;
  315. /* dip switch 'full reset' or 'db erase' */
  316. if (dip_switch & 0x1 || dip_switch & 0x2) {
  317. /* start bootloader */
  318. puts("DIP: Enabled\n");
  319. setenv("actual_bank", "0");
  320. }
  321. set_km_env();
  322. return 0;
  323. }
  324. #ifdef CONFIG_MGCOGE3NE
  325. static void set_pin(int state, unsigned long mask);
  326. /*
  327. * For mgcoge3ne boards, the mgcoge3un control is controlled from
  328. * a GPIO line on the PPC CPU. If bobcatreset is set the line
  329. * will toggle once what forces the mgocge3un part to restart
  330. * immediately.
  331. */
  332. static void handle_mgcoge3un_reset(void)
  333. {
  334. char *bobcatreset = getenv("bobcatreset");
  335. if (bobcatreset) {
  336. if (strcmp(bobcatreset, "true") == 0) {
  337. puts("Forcing bobcat reset\n");
  338. set_pin(0, 0x00000004); /* clear PD29 to reset arm */
  339. udelay(1000);
  340. set_pin(1, 0x00000004);
  341. } else
  342. set_pin(1, 0x00000004); /* set PD29 to not reset arm */
  343. }
  344. }
  345. #endif
  346. int ethernet_present(void)
  347. {
  348. struct km_bec_fpga *base =
  349. (struct km_bec_fpga *)CONFIG_SYS_KMBEC_FPGA_BASE;
  350. return in_8(&base->bprth) & PIGGY_PRESENT;
  351. }
  352. /*
  353. * Early board initalization.
  354. */
  355. int board_early_init_r(void)
  356. {
  357. struct km_bec_fpga *base =
  358. (struct km_bec_fpga *)CONFIG_SYS_KMBEC_FPGA_BASE;
  359. /* setup the UPIOx */
  360. /* General Unit Reset disabled, Flash Bank enabled, UnitLed on */
  361. out_8(&base->oprth, (WRG_RESET | H_OPORTS_14 | WRG_LED));
  362. /* SCC4 enable, halfduplex, FCC1 powerdown */
  363. out_8(&base->oprtl, (H_OPORTS_SCC4_ENA | H_OPORTS_SCC4_FD_ENA |
  364. H_OPORTS_FCC1_PW_DWN));
  365. #ifdef CONFIG_MGCOGE3NE
  366. handle_mgcoge3un_reset();
  367. #endif
  368. return 0;
  369. }
  370. int hush_init_var(void)
  371. {
  372. ivm_read_eeprom();
  373. return 0;
  374. }
  375. #define SDA_MASK 0x00010000
  376. #define SCL_MASK 0x00020000
  377. static void set_pin(int state, unsigned long mask)
  378. {
  379. ioport_t *iop = ioport_addr((immap_t *)CONFIG_SYS_IMMR, 3);
  380. if (state)
  381. setbits_be32(&iop->pdat, mask);
  382. else
  383. clrbits_be32(&iop->pdat, mask);
  384. setbits_be32(&iop->pdir, mask);
  385. }
  386. static int get_pin(unsigned long mask)
  387. {
  388. ioport_t *iop = ioport_addr((immap_t *)CONFIG_SYS_IMMR, 3);
  389. clrbits_be32(&iop->pdir, mask);
  390. return 0 != (in_be32(&iop->pdat) & mask);
  391. }
  392. void set_sda(int state)
  393. {
  394. set_pin(state, SDA_MASK);
  395. }
  396. void set_scl(int state)
  397. {
  398. set_pin(state, SCL_MASK);
  399. }
  400. int get_sda(void)
  401. {
  402. return get_pin(SDA_MASK);
  403. }
  404. int get_scl(void)
  405. {
  406. return get_pin(SCL_MASK);
  407. }
  408. #if defined(CONFIG_HARD_I2C)
  409. static void setports(int gpio)
  410. {
  411. ioport_t *iop = ioport_addr((immap_t *)CONFIG_SYS_IMMR, 3);
  412. if (gpio) {
  413. clrbits_be32(&iop->ppar, (SDA_MASK | SCL_MASK));
  414. clrbits_be32(&iop->podr, (SDA_MASK | SCL_MASK));
  415. } else {
  416. setbits_be32(&iop->ppar, (SDA_MASK | SCL_MASK));
  417. clrbits_be32(&iop->pdir, (SDA_MASK | SCL_MASK));
  418. setbits_be32(&iop->podr, (SDA_MASK | SCL_MASK));
  419. }
  420. }
  421. #endif
  422. #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
  423. void ft_board_setup(void *blob, bd_t *bd)
  424. {
  425. ft_cpu_setup(blob, bd);
  426. }
  427. #endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */