digsy_mtc.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. /*
  2. * (C) Copyright 2003
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * (C) Copyright 2004
  6. * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
  7. *
  8. * (C) Copyright 2005-2009
  9. * Modified for InterControl digsyMTC MPC5200 board by
  10. * Frank Bodammer, GCD Hard- & Software GmbH,
  11. * frank.bodammer@gcd-solutions.de
  12. *
  13. * (C) Copyright 2009
  14. * Grzegorz Bernacki, Semihalf, gjb@semihalf.com
  15. *
  16. * SPDX-License-Identifier: GPL-2.0+
  17. */
  18. #include <common.h>
  19. #include <mpc5xxx.h>
  20. #include <net.h>
  21. #include <pci.h>
  22. #include <asm/processor.h>
  23. #include <asm/io.h>
  24. #include "eeprom.h"
  25. #if defined(CONFIG_DIGSY_REV5)
  26. #include "is45s16800a2.h"
  27. #include <mtd/cfi_flash.h>
  28. #include <flash.h>
  29. #else
  30. #include "is42s16800a-7t.h"
  31. #endif
  32. #include <libfdt.h>
  33. #include <fdt_support.h>
  34. #include <i2c.h>
  35. #include <mb862xx.h>
  36. DECLARE_GLOBAL_DATA_PTR;
  37. extern int usb_cpu_init(void);
  38. #if defined(CONFIG_DIGSY_REV5)
  39. /*
  40. * The M29W128GH needs a specail reset command function,
  41. * details see the doc/README.cfi file
  42. */
  43. void flash_cmd_reset(flash_info_t *info)
  44. {
  45. flash_write_cmd(info, 0, 0, AMD_CMD_RESET);
  46. }
  47. #endif
  48. #ifndef CONFIG_SYS_RAMBOOT
  49. static void sdram_start(int hi_addr)
  50. {
  51. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  52. long control = SDRAM_CONTROL | hi_addr_bit;
  53. /* unlock mode register */
  54. out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000000);
  55. /* precharge all banks */
  56. out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000002);
  57. /* auto refresh */
  58. out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000004);
  59. /* set mode register */
  60. out_be32((void *)MPC5XXX_SDRAM_MODE, SDRAM_MODE);
  61. /* normal operation */
  62. out_be32((void *)MPC5XXX_SDRAM_CTRL, control);
  63. }
  64. #endif
  65. /*
  66. * ATTENTION: Although partially referenced initdram does NOT make real use
  67. * use of CONFIG_SYS_SDRAM_BASE. The code does not work if
  68. * CONFIG_SYS_SDRAM_BASE is something else than 0x00000000.
  69. */
  70. phys_size_t initdram(int board_type)
  71. {
  72. ulong dramsize = 0;
  73. ulong dramsize2 = 0;
  74. uint svr, pvr;
  75. #ifndef CONFIG_SYS_RAMBOOT
  76. ulong test1, test2;
  77. /* setup SDRAM chip selects */
  78. out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0x0000001C); /* 512MB at 0x0 */
  79. out_be32((void *)MPC5XXX_SDRAM_CS1CFG, 0x80000000); /* disabled */
  80. /* setup config registers */
  81. out_be32((void *)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1);
  82. out_be32((void *)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2);
  83. /* find RAM size using SDRAM CS0 only */
  84. sdram_start(0);
  85. test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x08000000);
  86. sdram_start(1);
  87. test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x08000000);
  88. if (test1 > test2) {
  89. sdram_start(0);
  90. dramsize = test1;
  91. } else {
  92. dramsize = test2;
  93. }
  94. /* memory smaller than 1MB is impossible */
  95. if (dramsize < (1 << 20))
  96. dramsize = 0;
  97. /* set SDRAM CS0 size according to the amount of RAM found */
  98. if (dramsize > 0) {
  99. out_be32((void *)MPC5XXX_SDRAM_CS0CFG,
  100. (0x13 + __builtin_ffs(dramsize >> 20) - 1));
  101. } else {
  102. out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0); /* disabled */
  103. }
  104. /* let SDRAM CS1 start right after CS0 */
  105. out_be32((void *)MPC5XXX_SDRAM_CS1CFG, dramsize + 0x0000001C);
  106. /* find RAM size using SDRAM CS1 only */
  107. test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize),
  108. 0x08000000);
  109. dramsize2 = test1;
  110. /* memory smaller than 1MB is impossible */
  111. if (dramsize2 < (1 << 20))
  112. dramsize2 = 0;
  113. /* set SDRAM CS1 size according to the amount of RAM found */
  114. if (dramsize2 > 0) {
  115. out_be32((void *)MPC5XXX_SDRAM_CS1CFG, (dramsize |
  116. (0x13 + __builtin_ffs(dramsize2 >> 20) - 1)));
  117. } else {
  118. out_be32((void *)MPC5XXX_SDRAM_CS1CFG, dramsize); /* disabled */
  119. }
  120. #else /* CONFIG_SYS_RAMBOOT */
  121. /* retrieve size of memory connected to SDRAM CS0 */
  122. dramsize = in_be32((void *)MPC5XXX_SDRAM_CS0CFG) & 0xFF;
  123. if (dramsize >= 0x13)
  124. dramsize = (1 << (dramsize - 0x13)) << 20;
  125. else
  126. dramsize = 0;
  127. /* retrieve size of memory connected to SDRAM CS1 */
  128. dramsize2 = in_be32((void *)MPC5XXX_SDRAM_CS1CFG) & 0xFF;
  129. if (dramsize2 >= 0x13)
  130. dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
  131. else
  132. dramsize2 = 0;
  133. #endif /* CONFIG_SYS_RAMBOOT */
  134. /*
  135. * On MPC5200B we need to set the special configuration delay in the
  136. * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
  137. * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
  138. *
  139. * "The SDelay should be written to a value of 0x00000004. It is
  140. * required to account for changes caused by normal wafer processing
  141. * parameters."
  142. */
  143. svr = get_svr();
  144. pvr = get_pvr();
  145. if ((SVR_MJREV(svr) >= 2) &&
  146. (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4))
  147. out_be32((void *)MPC5XXX_SDRAM_SDELAY, 0x04);
  148. return dramsize + dramsize2;
  149. }
  150. int checkboard(void)
  151. {
  152. char buf[64];
  153. int i = getenv_f("serial#", buf, sizeof(buf));
  154. puts ("Board: InterControl digsyMTC");
  155. #if defined(CONFIG_DIGSY_REV5)
  156. puts (" rev5");
  157. #endif
  158. if (i > 0) {
  159. puts(", ");
  160. puts(buf);
  161. }
  162. putc('\n');
  163. return 0;
  164. }
  165. #if defined(CONFIG_VIDEO)
  166. #define GPIO_USB1_0 0x00010000 /* Power-On pin */
  167. #define GPIO_USB1_9 0x08 /* PX_~EN pin */
  168. #define GPIO_EE_DO 0x10 /* PSC6_0 (DO) pin */
  169. #define GPIO_EE_CTS 0x20 /* PSC6_1 (CTS) pin */
  170. #define GPIO_EE_DI 0x10000000 /* PSC6_2 (DI) pin */
  171. #define GPIO_EE_CLK 0x20000000 /* PSC6_3 (CLK) pin */
  172. #define GPT_GPIO_ON 0x00000034 /* GPT as simple GPIO, high */
  173. static void exbo_hw_init(void)
  174. {
  175. struct mpc5xxx_gpt *gpt = (struct mpc5xxx_gpt *)MPC5XXX_GPT;
  176. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO;
  177. struct mpc5xxx_wu_gpio *wu_gpio =
  178. (struct mpc5xxx_wu_gpio *)MPC5XXX_WU_GPIO;
  179. /* configure IrDA pins (PSC6 port) as gpios */
  180. gpio->port_config &= 0xFF8FFFFF;
  181. /* Init for USB1_0, EE_CLK and EE_DI - Low */
  182. setbits_be32(&gpio->simple_ddr,
  183. GPIO_USB1_0 | GPIO_EE_CLK | GPIO_EE_DI);
  184. clrbits_be32(&gpio->simple_ode,
  185. GPIO_USB1_0 | GPIO_EE_CLK | GPIO_EE_DI);
  186. clrbits_be32(&gpio->simple_dvo,
  187. GPIO_USB1_0 | GPIO_EE_CLK | GPIO_EE_DI);
  188. setbits_be32(&gpio->simple_gpioe,
  189. GPIO_USB1_0 | GPIO_EE_CLK | GPIO_EE_DI);
  190. /* Init for EE_DO, EE_CTS - Input */
  191. clrbits_8(&wu_gpio->ddr, GPIO_EE_DO | GPIO_EE_CTS);
  192. setbits_8(&wu_gpio->enable, GPIO_EE_DO | GPIO_EE_CTS);
  193. /* Init for PX_~EN (USB1_9) - High */
  194. clrbits_8(&gpio->sint_ode, GPIO_USB1_9);
  195. setbits_8(&gpio->sint_ddr, GPIO_USB1_9);
  196. clrbits_8(&gpio->sint_inten, GPIO_USB1_9);
  197. setbits_8(&gpio->sint_dvo, GPIO_USB1_9);
  198. setbits_8(&gpio->sint_gpioe, GPIO_USB1_9);
  199. /* Init for ~OE Switch (GPIO3) - Timer_0 GPIO High */
  200. out_be32(&gpt[0].emsr, GPT_GPIO_ON);
  201. /* Init for S Switch (GPIO4) - Timer_1 GPIO High */
  202. out_be32(&gpt[1].emsr, GPT_GPIO_ON);
  203. /* Power-On camera supply */
  204. setbits_be32(&gpio->simple_dvo, GPIO_USB1_0);
  205. }
  206. #else
  207. static inline void exbo_hw_init(void) {}
  208. #endif /* CONFIG_VIDEO */
  209. int board_early_init_r(void)
  210. {
  211. #ifdef CONFIG_MPC52XX_SPI
  212. struct mpc5xxx_gpt *gpt = (struct mpc5xxx_gpt*)MPC5XXX_GPT;
  213. #endif
  214. /*
  215. * Now, when we are in RAM, enable flash write access for detection
  216. * process. Note that CS_BOOT cannot be cleared when executing in
  217. * flash.
  218. */
  219. /* disable CS_BOOT */
  220. clrbits_be32((void *)MPC5XXX_ADDECR, (1 << 25));
  221. /* enable CS1 */
  222. setbits_be32((void *)MPC5XXX_ADDECR, (1 << 17));
  223. /* enable CS0 */
  224. setbits_be32((void *)MPC5XXX_ADDECR, (1 << 16));
  225. #if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT)
  226. /* Low level USB init, required for proper kernel operation */
  227. usb_cpu_init();
  228. #endif
  229. #ifdef CONFIG_MPC52XX_SPI
  230. /* GPT 6 Output Enable */
  231. out_be32(&gpt[6].emsr, 0x00000034);
  232. /* GPT 7 Output Enable */
  233. out_be32(&gpt[7].emsr, 0x00000034);
  234. #endif
  235. return (0);
  236. }
  237. void board_get_enetaddr (uchar * enet)
  238. {
  239. ushort read = 0;
  240. ushort addr_of_eth_addr = 0;
  241. ushort len_sys = 0;
  242. ushort len_sys_cfg = 0;
  243. /* check identification word */
  244. eeprom_read(EEPROM_ADDR, EEPROM_ADDR_IDENT, (uchar *)&read, 2);
  245. if (read != EEPROM_IDENT)
  246. return;
  247. /* calculate offset of config area */
  248. eeprom_read(EEPROM_ADDR, EEPROM_ADDR_LEN_SYS, (uchar *)&len_sys, 2);
  249. eeprom_read(EEPROM_ADDR, EEPROM_ADDR_LEN_SYSCFG,
  250. (uchar *)&len_sys_cfg, 2);
  251. addr_of_eth_addr = (len_sys + len_sys_cfg + EEPROM_ADDR_ETHADDR) << 1;
  252. if (addr_of_eth_addr >= EEPROM_LEN)
  253. return;
  254. eeprom_read(EEPROM_ADDR, addr_of_eth_addr, enet, 6);
  255. }
  256. int misc_init_r(void)
  257. {
  258. pci_dev_t devbusfn;
  259. uchar enetaddr[6];
  260. /* check if graphic extension board is present */
  261. devbusfn = pci_find_device(PCI_VENDOR_ID_FUJITSU,
  262. PCI_DEVICE_ID_CORAL_PA, 0);
  263. if (devbusfn != -1)
  264. exbo_hw_init();
  265. if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
  266. board_get_enetaddr(enetaddr);
  267. eth_setenv_enetaddr("ethaddr", enetaddr);
  268. }
  269. return 0;
  270. }
  271. #ifdef CONFIG_PCI
  272. static struct pci_controller hose;
  273. extern void pci_mpc5xxx_init(struct pci_controller *);
  274. void pci_init_board(void)
  275. {
  276. pci_mpc5xxx_init(&hose);
  277. }
  278. #endif
  279. #ifdef CONFIG_CMD_IDE
  280. #ifdef CONFIG_IDE_RESET
  281. void init_ide_reset(void)
  282. {
  283. debug ("init_ide_reset\n");
  284. /* set gpio output value to 1 */
  285. setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, (1 << 25));
  286. /* open drain output */
  287. setbits_be32((void *)MPC5XXX_WU_GPIO_ODE, (1 << 25));
  288. /* direction output */
  289. setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, (1 << 25));
  290. /* enable gpio */
  291. setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, (1 << 25));
  292. }
  293. void ide_set_reset(int idereset)
  294. {
  295. debug ("ide_reset(%d)\n", idereset);
  296. /* set gpio output value to 0 */
  297. clrbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, (1 << 25));
  298. /* open drain output */
  299. setbits_be32((void *)MPC5XXX_WU_GPIO_ODE, (1 << 25));
  300. /* direction output */
  301. setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, (1 << 25));
  302. /* enable gpio */
  303. setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, (1 << 25));
  304. udelay(10000);
  305. /* set gpio output value to 1 */
  306. setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, (1 << 25));
  307. /* open drain output */
  308. setbits_be32((void *)MPC5XXX_WU_GPIO_ODE, (1 << 25));
  309. /* direction output */
  310. setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, (1 << 25));
  311. /* enable gpio */
  312. setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, (1 << 25));
  313. }
  314. #endif /* CONFIG_IDE_RESET */
  315. #endif /* CONFIG_CMD_IDE */
  316. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  317. static void ft_delete_node(void *fdt, const char *compat)
  318. {
  319. int off = -1;
  320. int ret;
  321. off = fdt_node_offset_by_compatible(fdt, -1, compat);
  322. if (off < 0) {
  323. printf("Could not find %s node.\n", compat);
  324. return;
  325. }
  326. ret = fdt_del_node(fdt, off);
  327. if (ret < 0)
  328. printf("Could not delete %s node.\n", compat);
  329. }
  330. #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
  331. static void ft_adapt_flash_base(void *blob)
  332. {
  333. flash_info_t *dev = &flash_info[0];
  334. int off;
  335. struct fdt_property *prop;
  336. int len;
  337. u32 *reg, *reg2;
  338. off = fdt_node_offset_by_compatible(blob, -1, "fsl,mpc5200b-lpb");
  339. if (off < 0) {
  340. printf("Could not find fsl,mpc5200b-lpb node.\n");
  341. return;
  342. }
  343. /* found compatible property */
  344. prop = fdt_get_property_w(blob, off, "ranges", &len);
  345. if (prop) {
  346. reg = reg2 = (u32 *)&prop->data[0];
  347. reg[2] = dev->start[0];
  348. reg[3] = dev->size;
  349. fdt_setprop(blob, off, "ranges", reg2, len);
  350. } else
  351. printf("Could not find ranges\n");
  352. }
  353. extern ulong flash_get_size (phys_addr_t base, int banknum);
  354. /* Update the Flash Baseaddr settings */
  355. int update_flash_size (int flash_size)
  356. {
  357. volatile struct mpc5xxx_mmap_ctl *mm =
  358. (struct mpc5xxx_mmap_ctl *) CONFIG_SYS_MBAR;
  359. flash_info_t *dev;
  360. int i;
  361. int size = 0;
  362. unsigned long base = 0x0;
  363. u32 *cs_reg = (u32 *)&mm->cs0_start;
  364. for (i = 0; i < 2; i++) {
  365. dev = &flash_info[i];
  366. if (dev->size) {
  367. /* calculate new base addr for this chipselect */
  368. base -= dev->size;
  369. out_be32(cs_reg, START_REG(base));
  370. cs_reg++;
  371. out_be32(cs_reg, STOP_REG(base, dev->size));
  372. cs_reg++;
  373. /* recalculate the sectoraddr in the cfi driver */
  374. size += flash_get_size(base, i);
  375. }
  376. }
  377. flash_protect_default();
  378. gd->bd->bi_flashstart = base;
  379. return 0;
  380. }
  381. #endif /* defined(CONFIG_SYS_UPDATE_FLASH_SIZE) */
  382. int ft_board_setup(void *blob, bd_t *bd)
  383. {
  384. int phy_addr = CONFIG_PHY_ADDR;
  385. char eth_path[] = "/soc5200@f0000000/mdio@3000/ethernet-phy@0";
  386. ft_cpu_setup(blob, bd);
  387. /*
  388. * There are 2 RTC nodes in the DTS, so remove
  389. * the unneeded node here.
  390. */
  391. #if defined(CONFIG_DIGSY_REV5)
  392. ft_delete_node(blob, "dallas,ds1339");
  393. #else
  394. ft_delete_node(blob, "mc,rv3029c2");
  395. #endif
  396. #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
  397. #ifdef CONFIG_FDT_FIXUP_NOR_FLASH_SIZE
  398. /* Update reg property in all nor flash nodes too */
  399. fdt_fixup_nor_flash_size(blob);
  400. #endif
  401. ft_adapt_flash_base(blob);
  402. #endif
  403. /* fix up the phy address */
  404. do_fixup_by_path(blob, eth_path, "reg", &phy_addr, sizeof(int), 0);
  405. return 0;
  406. }
  407. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */