o2dnt2.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. /*
  2. * Partially derived from board code for digsyMTC,
  3. * (C) Copyright 2009
  4. * Grzegorz Bernacki, Semihalf, gjb@semihalf.com
  5. *
  6. * (C) Copyright 2012
  7. * DENX Software Engineering, Anatolij Gustschin <agust@denx.de>
  8. *
  9. * SPDX-License-Identifier: GPL-2.0+
  10. */
  11. #include <common.h>
  12. #include <mpc5xxx.h>
  13. #include <asm/processor.h>
  14. #include <asm/io.h>
  15. #include <libfdt.h>
  16. #include <fdt_support.h>
  17. #include <i2c.h>
  18. #include <miiphy.h>
  19. #include <net.h>
  20. #include <pci.h>
  21. DECLARE_GLOBAL_DATA_PTR;
  22. #define SDRAM_MODE 0x00CD0000
  23. #define SDRAM_CONTROL 0x504F0000
  24. #define SDRAM_CONFIG1 0xD2322800
  25. #define SDRAM_CONFIG2 0x8AD70000
  26. enum ifm_sensor_type {
  27. O2DNT = 0x00, /* !< O2DNT 32MB */
  28. O2DNT2 = 0x01, /* !< O2DNT2 64MB */
  29. O3DNT = 0x02, /* !< O3DNT 32MB */
  30. O3DNT_MIN = 0x40, /* !< O3DNT Minerva 32MB */
  31. UNKNOWN = 0xff, /* !< Unknow sensor */
  32. };
  33. static enum ifm_sensor_type gt_ifm_sensor_type;
  34. #ifndef CONFIG_SYS_RAMBOOT
  35. static void sdram_start(int hi_addr)
  36. {
  37. struct mpc5xxx_sdram *sdram = (struct mpc5xxx_sdram *)MPC5XXX_SDRAM;
  38. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  39. long control = SDRAM_CONTROL | hi_addr_bit;
  40. /* unlock mode register */
  41. out_be32(&sdram->ctrl, control | 0x80000000);
  42. /* precharge all banks */
  43. out_be32(&sdram->ctrl, control | 0x80000002);
  44. /* auto refresh */
  45. out_be32(&sdram->ctrl, control | 0x80000004);
  46. /* set mode register */
  47. out_be32(&sdram->mode, SDRAM_MODE);
  48. /* normal operation */
  49. out_be32(&sdram->ctrl, control);
  50. }
  51. #endif
  52. /*
  53. * ATTENTION: Although partially referenced initdram does NOT make real use
  54. * use of CONFIG_SYS_SDRAM_BASE. The code does not work if
  55. * CONFIG_SYS_SDRAM_BASE is something else than 0x00000000.
  56. */
  57. phys_size_t initdram(int board_type)
  58. {
  59. struct mpc5xxx_mmap_ctl *mmap_ctl =
  60. (struct mpc5xxx_mmap_ctl *)CONFIG_SYS_MBAR;
  61. struct mpc5xxx_sdram *sdram = (struct mpc5xxx_sdram *)MPC5XXX_SDRAM;
  62. ulong dramsize = 0;
  63. ulong dramsize2 = 0;
  64. uint svr, pvr;
  65. if (gt_ifm_sensor_type == O2DNT2) {
  66. /* activate SDRAM CS1 */
  67. setbits_be32((void *)MPC5XXX_GPS_PORT_CONFIG, 0x80000000);
  68. }
  69. #ifndef CONFIG_SYS_RAMBOOT
  70. ulong test1, test2;
  71. /* setup SDRAM chip selects */
  72. out_be32(&mmap_ctl->sdram0, 0x0000001E); /* 2 GB at 0x0 */
  73. out_be32(&mmap_ctl->sdram1, 0x00000000); /* disabled */
  74. /* setup config registers */
  75. out_be32(&sdram->config1, SDRAM_CONFIG1);
  76. out_be32(&sdram->config2, SDRAM_CONFIG2);
  77. /* find RAM size using SDRAM CS0 only */
  78. sdram_start(0);
  79. test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x08000000);
  80. sdram_start(1);
  81. test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x08000000);
  82. if (test1 > test2) {
  83. sdram_start(0);
  84. dramsize = test1;
  85. } else {
  86. dramsize = test2;
  87. }
  88. /* memory smaller than 1MB is impossible */
  89. if (dramsize < (1 << 20))
  90. dramsize = 0;
  91. /* set SDRAM CS0 size according to the amount of RAM found */
  92. if (dramsize > 0) {
  93. out_be32(&mmap_ctl->sdram0,
  94. (0x13 + __builtin_ffs(dramsize >> 20) - 1));
  95. } else {
  96. out_be32(&mmap_ctl->sdram0, 0); /* disabled */
  97. }
  98. /* let SDRAM CS1 start right after CS0 */
  99. out_be32(&mmap_ctl->sdram1, dramsize + 0x0000001E); /* 2G */
  100. /* find RAM size using SDRAM CS1 only */
  101. if (!dramsize)
  102. sdram_start(0);
  103. test2 = test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize),
  104. 0x80000000);
  105. if (!dramsize) {
  106. sdram_start(1);
  107. test2 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize),
  108. 0x80000000);
  109. }
  110. if (test1 > test2) {
  111. sdram_start(0);
  112. dramsize2 = test1;
  113. } else {
  114. dramsize2 = test2;
  115. }
  116. /* memory smaller than 1MB is impossible */
  117. if (dramsize2 < (1 << 20))
  118. dramsize2 = 0;
  119. /* set SDRAM CS1 size according to the amount of RAM found */
  120. if (dramsize2 > 0) {
  121. out_be32(&mmap_ctl->sdram1, (dramsize |
  122. (0x13 + __builtin_ffs(dramsize2 >> 20) - 1)));
  123. } else {
  124. out_be32(&mmap_ctl->sdram1, dramsize); /* disabled */
  125. }
  126. #else /* CONFIG_SYS_RAMBOOT */
  127. /* retrieve size of memory connected to SDRAM CS0 */
  128. dramsize = in_be32(&mmap_ctl->sdram0) & 0xFF;
  129. if (dramsize >= 0x13)
  130. dramsize = (1 << (dramsize - 0x13)) << 20;
  131. else
  132. dramsize = 0;
  133. /* retrieve size of memory connected to SDRAM CS1 */
  134. dramsize2 = in_be32(&mmap_ctl->sdram1) & 0xFF;
  135. if (dramsize2 >= 0x13)
  136. dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
  137. else
  138. dramsize2 = 0;
  139. #endif /* CONFIG_SYS_RAMBOOT */
  140. /*
  141. * On MPC5200B we need to set the special configuration delay in the
  142. * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
  143. * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
  144. *
  145. * "The SDelay should be written to a value of 0x00000004. It is
  146. * required to account for changes caused by normal wafer processing
  147. * parameters."
  148. */
  149. svr = get_svr();
  150. pvr = get_pvr();
  151. if ((SVR_MJREV(svr) >= 2) &&
  152. (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4))
  153. out_be32(&sdram->sdelay, 0x04);
  154. return dramsize + dramsize2;
  155. }
  156. #define GPT_GPIO_IN 0x4
  157. int checkboard(void)
  158. {
  159. struct mpc5xxx_gpt *gpt = (struct mpc5xxx_gpt *)MPC5XXX_GPT;
  160. unsigned char board_config = 0;
  161. int i;
  162. /* switch gpt0 - gpt7 to input */
  163. for (i = 0; i < 7; i++)
  164. out_be32(&gpt[i].emsr, GPT_GPIO_IN);
  165. /* get configuration byte on timer-port */
  166. for (i = 0; i < 7; i++)
  167. board_config |= (in_be32(&gpt[i].sr) & 0x100) >> (8 - i);
  168. puts("Board: ");
  169. switch (board_config) {
  170. case 0:
  171. puts("O2DNT\n");
  172. gt_ifm_sensor_type = O2DNT;
  173. break;
  174. case 1:
  175. puts("O3DNT\n");
  176. gt_ifm_sensor_type = O3DNT;
  177. break;
  178. case 2:
  179. puts("O2DNT2\n");
  180. gt_ifm_sensor_type = O2DNT2;
  181. break;
  182. case 64:
  183. puts("O3DNT Minerva\n");
  184. gt_ifm_sensor_type = O3DNT_MIN;
  185. break;
  186. default:
  187. puts("Unknown\n");
  188. gt_ifm_sensor_type = UNKNOWN;
  189. break;
  190. }
  191. return 0;
  192. }
  193. int board_early_init_r(void)
  194. {
  195. struct mpc5xxx_lpb *lpb_regs = (struct mpc5xxx_lpb *)MPC5XXX_LPB;
  196. /*
  197. * Now, when we are in RAM, enable flash write access for detection
  198. * process. Note that CS_BOOT cannot be cleared when executing in flash.
  199. */
  200. clrbits_be32(&lpb_regs->cs0_cfg, 1); /* clear RO */
  201. /* disable CS_BOOT */
  202. clrbits_be32((void *)MPC5XXX_ADDECR, (1 << 25));
  203. /* enable CS0 */
  204. setbits_be32((void *)MPC5XXX_ADDECR, (1 << 16));
  205. return 0;
  206. }
  207. #define MIIM_LXT971_LED_CFG_REG 0x14
  208. #define LXT971_LED_CFG_LINK_STATUS 0x4000
  209. #define LXT971_LED_CFG_RX_TX_ACTIVITY 0x0700
  210. #define LXT971_LED_CFG_LINK_ACTIVITY 0x00D0
  211. #define LXT971_LED_CFG_PULSE_STRETCH 0x0002
  212. /*
  213. * Additional PHY intialization after reset in mpc5xxx_fec_init_phy()
  214. */
  215. void reset_phy(void)
  216. {
  217. /*
  218. * Set LED configuration bits.
  219. * It can't be done in misc_init_r() since FEC is not
  220. * initialized at this time. Therefore we do it here.
  221. */
  222. miiphy_write("FEC", CONFIG_PHY_ADDR, MIIM_LXT971_LED_CFG_REG,
  223. LXT971_LED_CFG_LINK_STATUS |
  224. LXT971_LED_CFG_RX_TX_ACTIVITY |
  225. LXT971_LED_CFG_LINK_ACTIVITY |
  226. LXT971_LED_CFG_PULSE_STRETCH);
  227. }
  228. #if defined(CONFIG_POST)
  229. /*
  230. * Reads GPIO pin PSC6_3. A keypress is reported, if PSC6_3 is low. If PSC6_3
  231. * is left open, no keypress is detected.
  232. */
  233. int post_hotkeys_pressed(void)
  234. {
  235. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *) MPC5XXX_GPIO;
  236. /*
  237. * Configure PSC6_1 and PSC6_3 as GPIO. PSC6 then couldn't be used in
  238. * CODEC or UART mode. Consumer IrDA should still be possible.
  239. */
  240. clrbits_be32(&gpio->port_config, 0x07000000);
  241. setbits_be32(&gpio->port_config, 0x03000000);
  242. /* Enable GPIO for GPIO_IRDA_1 (IR_USB_CLK pin) = PSC6_3 */
  243. setbits_be32(&gpio->simple_gpioe, 0x20000000);
  244. /* Configure GPIO_IRDA_1 as input */
  245. clrbits_be32(&gpio->simple_ddr, 0x20000000);
  246. return (in_be32(&gpio->simple_ival) & 0x20000000) ? 0 : 1;
  247. }
  248. #endif
  249. #ifdef CONFIG_PCI
  250. static struct pci_controller hose;
  251. void pci_init_board(void)
  252. {
  253. pci_mpc5xxx_init(&hose);
  254. }
  255. #endif
  256. #ifdef CONFIG_OF_BOARD_SETUP
  257. #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
  258. static void ft_adapt_flash_base(void *blob)
  259. {
  260. flash_info_t *dev = &flash_info[0];
  261. int off;
  262. struct fdt_property *prop;
  263. int len;
  264. u32 *reg, *reg2;
  265. off = fdt_node_offset_by_compatible(blob, -1, "fsl,mpc5200b-lpb");
  266. if (off < 0) {
  267. printf("Could not find fsl,mpc5200b-lpb node.\n");
  268. return;
  269. }
  270. /* found compatible property */
  271. prop = fdt_get_property_w(blob, off, "ranges", &len);
  272. if (prop) {
  273. reg = reg2 = (u32 *)&prop->data[0];
  274. reg[2] = dev->start[0];
  275. reg[3] = dev->size;
  276. fdt_setprop(blob, off, "ranges", reg2, len);
  277. } else
  278. printf("Could not find ranges\n");
  279. }
  280. extern ulong flash_get_size(phys_addr_t base, int banknum);
  281. /* Update the flash baseaddr settings */
  282. int update_flash_size(int flash_size)
  283. {
  284. struct mpc5xxx_mmap_ctl *mm =
  285. (struct mpc5xxx_mmap_ctl *) CONFIG_SYS_MBAR;
  286. flash_info_t *dev;
  287. int i;
  288. int size = 0;
  289. unsigned long base = 0x0;
  290. u32 *cs_reg = (u32 *)&mm->cs0_start;
  291. for (i = 0; i < 2; i++) {
  292. dev = &flash_info[i];
  293. if (dev->size) {
  294. /* calculate new base addr for this chipselect */
  295. base -= dev->size;
  296. out_be32(cs_reg, START_REG(base));
  297. cs_reg++;
  298. out_be32(cs_reg, STOP_REG(base, dev->size));
  299. cs_reg++;
  300. /* recalculate the sectoraddr in the cfi driver */
  301. size += flash_get_size(base, i);
  302. }
  303. }
  304. flash_protect_default();
  305. gd->bd->bi_flashstart = base;
  306. return 0;
  307. }
  308. #endif /* defined(CONFIG_SYS_UPDATE_FLASH_SIZE) */
  309. int ft_board_setup(void *blob, bd_t *bd)
  310. {
  311. int phy_addr = CONFIG_PHY_ADDR;
  312. char eth_path[] = "/soc5200@f0000000/mdio@3000/ethernet-phy@0";
  313. ft_cpu_setup(blob, bd);
  314. #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
  315. #ifdef CONFIG_FDT_FIXUP_NOR_FLASH_SIZE
  316. /* Update reg property in all nor flash nodes too */
  317. fdt_fixup_nor_flash_size(blob);
  318. #endif
  319. ft_adapt_flash_base(blob);
  320. #endif
  321. /* fix up the phy address */
  322. do_fixup_by_path(blob, eth_path, "reg", &phy_addr, sizeof(int), 0);
  323. return 0;
  324. }
  325. #endif /* CONFIG_OF_BOARD_SETUP */