km82xx.c 14 KB

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