digsy_mtc.c 11 KB

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