digsy_mtc.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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. * See file CREDITS for list of people who contributed to this
  17. * project.
  18. *
  19. * This program is free software; you can redistribute it and/or
  20. * modify it under the terms of the GNU General Public License as
  21. * published by the Free Software Foundation; either version 2 of
  22. * the License, or (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program; if not, write to the Free Software
  31. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  32. * MA 02111-1307 USA
  33. */
  34. #include <common.h>
  35. #include <mpc5xxx.h>
  36. #include <net.h>
  37. #include <pci.h>
  38. #include <asm/processor.h>
  39. #include <asm/io.h>
  40. #include "eeprom.h"
  41. #if defined(CONFIG_DIGSY_REV5)
  42. #include "is45s16800a2.h"
  43. #include <mtd/cfi_flash.h>
  44. #else
  45. #include "is42s16800a-7t.h"
  46. #endif
  47. #include <libfdt.h>
  48. #include <fdt_support.h>
  49. DECLARE_GLOBAL_DATA_PTR;
  50. extern int usb_cpu_init(void);
  51. #if defined(CONFIG_DIGSY_REV5)
  52. /*
  53. * The M29W128GH needs a specail reset command function,
  54. * details see the doc/README.cfi file
  55. */
  56. void flash_cmd_reset(flash_info_t *info)
  57. {
  58. flash_write_cmd(info, 0, 0, AMD_CMD_RESET);
  59. }
  60. #endif
  61. #ifndef CONFIG_SYS_RAMBOOT
  62. static void sdram_start(int hi_addr)
  63. {
  64. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  65. long control = SDRAM_CONTROL | hi_addr_bit;
  66. /* unlock mode register */
  67. out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000000);
  68. /* precharge all banks */
  69. out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000002);
  70. /* auto refresh */
  71. out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000004);
  72. /* set mode register */
  73. out_be32((void *)MPC5XXX_SDRAM_MODE, SDRAM_MODE);
  74. /* normal operation */
  75. out_be32((void *)MPC5XXX_SDRAM_CTRL, control);
  76. }
  77. #endif
  78. /*
  79. * ATTENTION: Although partially referenced initdram does NOT make real use
  80. * use of CONFIG_SYS_SDRAM_BASE. The code does not work if
  81. * CONFIG_SYS_SDRAM_BASE is something else than 0x00000000.
  82. */
  83. phys_size_t initdram(int board_type)
  84. {
  85. ulong dramsize = 0;
  86. ulong dramsize2 = 0;
  87. uint svr, pvr;
  88. #ifndef CONFIG_SYS_RAMBOOT
  89. ulong test1, test2;
  90. /* setup SDRAM chip selects */
  91. out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0x0000001C); /* 512MB at 0x0 */
  92. out_be32((void *)MPC5XXX_SDRAM_CS1CFG, 0x80000000); /* disabled */
  93. /* setup config registers */
  94. out_be32((void *)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1);
  95. out_be32((void *)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2);
  96. /* find RAM size using SDRAM CS0 only */
  97. sdram_start(0);
  98. test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x08000000);
  99. sdram_start(1);
  100. test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x08000000);
  101. if (test1 > test2) {
  102. sdram_start(0);
  103. dramsize = test1;
  104. } else {
  105. dramsize = test2;
  106. }
  107. /* memory smaller than 1MB is impossible */
  108. if (dramsize < (1 << 20))
  109. dramsize = 0;
  110. /* set SDRAM CS0 size according to the amount of RAM found */
  111. if (dramsize > 0) {
  112. out_be32((void *)MPC5XXX_SDRAM_CS0CFG,
  113. (0x13 + __builtin_ffs(dramsize >> 20) - 1));
  114. } else {
  115. out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0); /* disabled */
  116. }
  117. /* let SDRAM CS1 start right after CS0 */
  118. out_be32((void *)MPC5XXX_SDRAM_CS1CFG, dramsize + 0x0000001C);
  119. /* find RAM size using SDRAM CS1 only */
  120. test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize),
  121. 0x08000000);
  122. dramsize2 = test1;
  123. /* memory smaller than 1MB is impossible */
  124. if (dramsize2 < (1 << 20))
  125. dramsize2 = 0;
  126. /* set SDRAM CS1 size according to the amount of RAM found */
  127. if (dramsize2 > 0) {
  128. out_be32((void *)MPC5XXX_SDRAM_CS1CFG, (dramsize |
  129. (0x13 + __builtin_ffs(dramsize2 >> 20) - 1)));
  130. } else {
  131. out_be32((void *)MPC5XXX_SDRAM_CS1CFG, dramsize); /* disabled */
  132. }
  133. #else /* CONFIG_SYS_RAMBOOT */
  134. /* retrieve size of memory connected to SDRAM CS0 */
  135. dramsize = in_be32((void *)MPC5XXX_SDRAM_CS0CFG) & 0xFF;
  136. if (dramsize >= 0x13)
  137. dramsize = (1 << (dramsize - 0x13)) << 20;
  138. else
  139. dramsize = 0;
  140. /* retrieve size of memory connected to SDRAM CS1 */
  141. dramsize2 = in_be32((void *)MPC5XXX_SDRAM_CS1CFG) & 0xFF;
  142. if (dramsize2 >= 0x13)
  143. dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
  144. else
  145. dramsize2 = 0;
  146. #endif /* CONFIG_SYS_RAMBOOT */
  147. /*
  148. * On MPC5200B we need to set the special configuration delay in the
  149. * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
  150. * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
  151. *
  152. * "The SDelay should be written to a value of 0x00000004. It is
  153. * required to account for changes caused by normal wafer processing
  154. * parameters."
  155. */
  156. svr = get_svr();
  157. pvr = get_pvr();
  158. if ((SVR_MJREV(svr) >= 2) &&
  159. (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4))
  160. out_be32((void *)MPC5XXX_SDRAM_SDELAY, 0x04);
  161. return dramsize + dramsize2;
  162. }
  163. int checkboard(void)
  164. {
  165. char *s = getenv("serial#");
  166. puts ("Board: InterControl digsyMTC");
  167. #if defined(CONFIG_DIGSY_REV5)
  168. puts (" rev5");
  169. #endif
  170. if (s != NULL) {
  171. puts(", ");
  172. puts(s);
  173. }
  174. putc('\n');
  175. return 0;
  176. }
  177. int board_early_init_r(void)
  178. {
  179. #ifdef CONFIG_MPC52XX_SPI
  180. struct mpc5xxx_gpt *gpt = (struct mpc5xxx_gpt*)MPC5XXX_GPT;
  181. #endif
  182. /*
  183. * Now, when we are in RAM, enable flash write access for detection
  184. * process. Note that CS_BOOT cannot be cleared when executing in
  185. * flash.
  186. */
  187. /* disable CS_BOOT */
  188. clrbits_be32((void *)MPC5XXX_ADDECR, (1 << 25));
  189. /* enable CS1 */
  190. setbits_be32((void *)MPC5XXX_ADDECR, (1 << 17));
  191. /* enable CS0 */
  192. setbits_be32((void *)MPC5XXX_ADDECR, (1 << 16));
  193. #if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT)
  194. /* Low level USB init, required for proper kernel operation */
  195. usb_cpu_init();
  196. #endif
  197. #ifdef CONFIG_MPC52XX_SPI
  198. /* GPT 6 Output Enable */
  199. out_be32(&gpt[6].emsr, 0x00000034);
  200. /* GPT 7 Output Enable */
  201. out_be32(&gpt[7].emsr, 0x00000034);
  202. #endif
  203. return (0);
  204. }
  205. void board_get_enetaddr (uchar * enet)
  206. {
  207. ushort read = 0;
  208. ushort addr_of_eth_addr = 0;
  209. ushort len_sys = 0;
  210. ushort len_sys_cfg = 0;
  211. /* check identification word */
  212. eeprom_read(EEPROM_ADDR, EEPROM_ADDR_IDENT, (uchar *)&read, 2);
  213. if (read != EEPROM_IDENT)
  214. return;
  215. /* calculate offset of config area */
  216. eeprom_read(EEPROM_ADDR, EEPROM_ADDR_LEN_SYS, (uchar *)&len_sys, 2);
  217. eeprom_read(EEPROM_ADDR, EEPROM_ADDR_LEN_SYSCFG,
  218. (uchar *)&len_sys_cfg, 2);
  219. addr_of_eth_addr = (len_sys + len_sys_cfg + EEPROM_ADDR_ETHADDR) << 1;
  220. if (addr_of_eth_addr >= EEPROM_LEN)
  221. return;
  222. eeprom_read(EEPROM_ADDR, addr_of_eth_addr, enet, 6);
  223. }
  224. int misc_init_r(void)
  225. {
  226. uchar enetaddr[6];
  227. if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
  228. board_get_enetaddr(enetaddr);
  229. eth_setenv_enetaddr("ethaddr", enetaddr);
  230. }
  231. return 0;
  232. }
  233. #ifdef CONFIG_PCI
  234. static struct pci_controller hose;
  235. extern void pci_mpc5xxx_init(struct pci_controller *);
  236. void pci_init_board(void)
  237. {
  238. pci_mpc5xxx_init(&hose);
  239. }
  240. #endif
  241. #ifdef CONFIG_CMD_IDE
  242. #ifdef CONFIG_IDE_RESET
  243. void init_ide_reset(void)
  244. {
  245. debug ("init_ide_reset\n");
  246. /* set gpio output value to 1 */
  247. setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, (1 << 25));
  248. /* open drain output */
  249. setbits_be32((void *)MPC5XXX_WU_GPIO_ODE, (1 << 25));
  250. /* direction output */
  251. setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, (1 << 25));
  252. /* enable gpio */
  253. setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, (1 << 25));
  254. }
  255. void ide_set_reset(int idereset)
  256. {
  257. debug ("ide_reset(%d)\n", idereset);
  258. /* set gpio output value to 0 */
  259. clrbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, (1 << 25));
  260. /* open drain output */
  261. setbits_be32((void *)MPC5XXX_WU_GPIO_ODE, (1 << 25));
  262. /* direction output */
  263. setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, (1 << 25));
  264. /* enable gpio */
  265. setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, (1 << 25));
  266. udelay(10000);
  267. /* set gpio output value to 1 */
  268. setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, (1 << 25));
  269. /* open drain output */
  270. setbits_be32((void *)MPC5XXX_WU_GPIO_ODE, (1 << 25));
  271. /* direction output */
  272. setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, (1 << 25));
  273. /* enable gpio */
  274. setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, (1 << 25));
  275. }
  276. #endif /* CONFIG_IDE_RESET */
  277. #endif /* CONFIG_CMD_IDE */
  278. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  279. static void ft_delete_node(void *fdt, const char *compat)
  280. {
  281. int off = -1;
  282. int ret;
  283. off = fdt_node_offset_by_compatible(fdt, -1, compat);
  284. if (off < 0) {
  285. printf("Could not find %s node.\n", compat);
  286. return;
  287. }
  288. ret = fdt_del_node(fdt, off);
  289. if (ret < 0)
  290. printf("Could not delete %s node.\n", compat);
  291. }
  292. #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
  293. static void ft_adapt_flash_base(void *blob)
  294. {
  295. flash_info_t *dev = &flash_info[0];
  296. int off;
  297. struct fdt_property *prop;
  298. int len;
  299. u32 *reg, *reg2;
  300. off = fdt_node_offset_by_compatible(blob, -1, "fsl,mpc5200b-lpb");
  301. if (off < 0) {
  302. printf("Could not find fsl,mpc5200b-lpb node.\n");
  303. return;
  304. }
  305. /* found compatible property */
  306. prop = fdt_get_property_w(blob, off, "ranges", &len);
  307. if (prop) {
  308. reg = reg2 = (u32 *)&prop->data[0];
  309. reg[2] = dev->start[0];
  310. reg[3] = dev->size;
  311. fdt_setprop(blob, off, "ranges", reg2, len);
  312. } else
  313. printf("Could not find ranges\n");
  314. }
  315. extern ulong flash_get_size (phys_addr_t base, int banknum);
  316. /* Update the Flash Baseaddr settings */
  317. int update_flash_size (int flash_size)
  318. {
  319. volatile struct mpc5xxx_mmap_ctl *mm =
  320. (struct mpc5xxx_mmap_ctl *) CONFIG_SYS_MBAR;
  321. flash_info_t *dev;
  322. int i;
  323. int size = 0;
  324. unsigned long base = 0x0;
  325. u32 *cs_reg = (u32 *)&mm->cs0_start;
  326. for (i = 0; i < 2; i++) {
  327. dev = &flash_info[i];
  328. if (dev->size) {
  329. /* calculate new base addr for this chipselect */
  330. base -= dev->size;
  331. out_be32(cs_reg, START_REG(base));
  332. cs_reg++;
  333. out_be32(cs_reg, STOP_REG(base, dev->size));
  334. cs_reg++;
  335. /* recalculate the sectoraddr in the cfi driver */
  336. size += flash_get_size(base, i);
  337. }
  338. }
  339. gd->bd->bi_flashstart = base;
  340. return 0;
  341. }
  342. #endif /* defined(CONFIG_SYS_UPDATE_FLASH_SIZE) */
  343. void ft_board_setup(void *blob, bd_t *bd)
  344. {
  345. int phy_addr = CONFIG_PHY_ADDR;
  346. char eth_path[] = "/soc5200@f0000000/mdio@3000/ethernet-phy@0";
  347. ft_cpu_setup(blob, bd);
  348. /*
  349. * There are 2 RTC nodes in the DTS, so remove
  350. * the unneeded node here.
  351. */
  352. #if defined(CONFIG_DIGSY_REV5)
  353. ft_delete_node(blob, "dallas,ds1339");
  354. #else
  355. ft_delete_node(blob, "mc,rv3029c2");
  356. #endif
  357. #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
  358. #ifdef CONFIG_FDT_FIXUP_NOR_FLASH_SIZE
  359. /* Update reg property in all nor flash nodes too */
  360. fdt_fixup_nor_flash_size(blob);
  361. #endif
  362. ft_adapt_flash_base(blob);
  363. #endif
  364. /* fix up the phy address */
  365. do_fixup_by_path(blob, eth_path, "reg", &phy_addr, sizeof(int), 0);
  366. }
  367. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */