digsy_mtc.c 11 KB

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