o2dnt2.c 10 KB

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