km82xx.c 14 KB

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