apf27.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * Copyright (C) 2008-2013 Eric Jarrige <eric.jarrige@armadeus.org>
  3. *
  4. * based on the files by
  5. * Sascha Hauer, Pengutronix
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <environment.h>
  11. #include <jffs2/jffs2.h>
  12. #include <nand.h>
  13. #include <netdev.h>
  14. #include <asm/io.h>
  15. #include <asm/arch/imx-regs.h>
  16. #include <asm/arch/gpio.h>
  17. #include <asm/gpio.h>
  18. #include <linux/errno.h>
  19. #include "apf27.h"
  20. #include "crc.h"
  21. #include "fpga.h"
  22. DECLARE_GLOBAL_DATA_PTR;
  23. /*
  24. * Fuse bank 1 row 8 is "reserved for future use" and therefore available for
  25. * customer use. The APF27 board uses this fuse to store the board revision:
  26. * 0: initial board revision
  27. * 1: first revision - Presence of the second RAM chip on the board is blown in
  28. * fuse bank 1 row 9 bit 0 - No hardware change
  29. * N: to be defined
  30. */
  31. static u32 get_board_rev(void)
  32. {
  33. struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
  34. return readl(&iim->bank[1].fuse_regs[8]);
  35. }
  36. /*
  37. * Fuse bank 1 row 9 is "reserved for future use" and therefore available for
  38. * customer use. The APF27 board revision 1 uses the bit 0 to permanently store
  39. * the presence of the second RAM chip
  40. * 0: AFP27 with 1 RAM of 64 MiB
  41. * 1: AFP27 with 2 RAM chips of 64 MiB each (128MB)
  42. */
  43. static int get_num_ram_bank(void)
  44. {
  45. struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
  46. int nr_dram_banks = 1;
  47. if ((get_board_rev() > 0) && (CONFIG_NR_DRAM_BANKS > 1))
  48. nr_dram_banks += readl(&iim->bank[1].fuse_regs[9]) & 0x01;
  49. else
  50. nr_dram_banks = CONFIG_NR_DRAM_POPULATED;
  51. return nr_dram_banks;
  52. }
  53. static void apf27_port_init(int port, u32 gpio_dr, u32 ocr1, u32 ocr2,
  54. u32 iconfa1, u32 iconfa2, u32 iconfb1, u32 iconfb2,
  55. u32 icr1, u32 icr2, u32 imr, u32 gpio_dir, u32 gpr,
  56. u32 puen, u32 gius)
  57. {
  58. struct gpio_port_regs *regs = (struct gpio_port_regs *)IMX_GPIO_BASE;
  59. writel(gpio_dr, &regs->port[port].gpio_dr);
  60. writel(ocr1, &regs->port[port].ocr1);
  61. writel(ocr2, &regs->port[port].ocr2);
  62. writel(iconfa1, &regs->port[port].iconfa1);
  63. writel(iconfa2, &regs->port[port].iconfa2);
  64. writel(iconfb1, &regs->port[port].iconfb1);
  65. writel(iconfb2, &regs->port[port].iconfb2);
  66. writel(icr1, &regs->port[port].icr1);
  67. writel(icr2, &regs->port[port].icr2);
  68. writel(imr, &regs->port[port].imr);
  69. writel(gpio_dir, &regs->port[port].gpio_dir);
  70. writel(gpr, &regs->port[port].gpr);
  71. writel(puen, &regs->port[port].puen);
  72. writel(gius, &regs->port[port].gius);
  73. }
  74. #define APF27_PORT_INIT(n) apf27_port_init(PORT##n, ACFG_DR_##n##_VAL, \
  75. ACFG_OCR1_##n##_VAL, ACFG_OCR2_##n##_VAL, ACFG_ICFA1_##n##_VAL, \
  76. ACFG_ICFA2_##n##_VAL, ACFG_ICFB1_##n##_VAL, ACFG_ICFB2_##n##_VAL, \
  77. ACFG_ICR1_##n##_VAL, ACFG_ICR2_##n##_VAL, ACFG_IMR_##n##_VAL, \
  78. ACFG_DDIR_##n##_VAL, ACFG_GPR_##n##_VAL, ACFG_PUEN_##n##_VAL, \
  79. ACFG_GIUS_##n##_VAL)
  80. static void apf27_iomux_init(void)
  81. {
  82. APF27_PORT_INIT(A);
  83. APF27_PORT_INIT(B);
  84. APF27_PORT_INIT(C);
  85. APF27_PORT_INIT(D);
  86. APF27_PORT_INIT(E);
  87. APF27_PORT_INIT(F);
  88. }
  89. static int apf27_devices_init(void)
  90. {
  91. int i;
  92. unsigned int mode[] = {
  93. PC5_PF_I2C2_DATA,
  94. PC6_PF_I2C2_CLK,
  95. PD17_PF_I2C_DATA,
  96. PD18_PF_I2C_CLK,
  97. };
  98. for (i = 0; i < ARRAY_SIZE(mode); i++)
  99. imx_gpio_mode(mode[i]);
  100. #ifdef CONFIG_MXC_UART
  101. mx27_uart1_init_pins();
  102. #endif
  103. #ifdef CONFIG_FEC_MXC
  104. mx27_fec_init_pins();
  105. #endif
  106. #ifdef CONFIG_MXC_MMC
  107. mx27_sd2_init_pins();
  108. imx_gpio_mode((GPIO_PORTF | GPIO_OUT | GPIO_PUEN | GPIO_GPIO | 16));
  109. gpio_request(PC_PWRON, "pc_pwron");
  110. gpio_set_value(PC_PWRON, 1);
  111. #endif
  112. return 0;
  113. }
  114. static void apf27_setup_csx(void)
  115. {
  116. struct weim_regs *weim = (struct weim_regs *)IMX_WEIM_BASE;
  117. writel(ACFG_CS0U_VAL, &weim->cs0u);
  118. writel(ACFG_CS0L_VAL, &weim->cs0l);
  119. writel(ACFG_CS0A_VAL, &weim->cs0a);
  120. writel(ACFG_CS1U_VAL, &weim->cs1u);
  121. writel(ACFG_CS1L_VAL, &weim->cs1l);
  122. writel(ACFG_CS1A_VAL, &weim->cs1a);
  123. writel(ACFG_CS2U_VAL, &weim->cs2u);
  124. writel(ACFG_CS2L_VAL, &weim->cs2l);
  125. writel(ACFG_CS2A_VAL, &weim->cs2a);
  126. writel(ACFG_CS3U_VAL, &weim->cs3u);
  127. writel(ACFG_CS3L_VAL, &weim->cs3l);
  128. writel(ACFG_CS3A_VAL, &weim->cs3a);
  129. writel(ACFG_CS4U_VAL, &weim->cs4u);
  130. writel(ACFG_CS4L_VAL, &weim->cs4l);
  131. writel(ACFG_CS4A_VAL, &weim->cs4a);
  132. writel(ACFG_CS5U_VAL, &weim->cs5u);
  133. writel(ACFG_CS5L_VAL, &weim->cs5l);
  134. writel(ACFG_CS5A_VAL, &weim->cs5a);
  135. writel(ACFG_EIM_VAL, &weim->eim);
  136. }
  137. static void apf27_setup_port(void)
  138. {
  139. struct system_control_regs *system =
  140. (struct system_control_regs *)IMX_SYSTEM_CTL_BASE;
  141. writel(ACFG_FMCR_VAL, &system->fmcr);
  142. }
  143. int board_init(void)
  144. {
  145. gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
  146. apf27_setup_csx();
  147. apf27_setup_port();
  148. apf27_iomux_init();
  149. apf27_devices_init();
  150. #if defined(CONFIG_FPGA)
  151. APF27_init_fpga();
  152. #endif
  153. return 0;
  154. }
  155. int dram_init(void)
  156. {
  157. gd->ram_size = get_ram_size((void *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
  158. if (get_num_ram_bank() > 1)
  159. gd->ram_size += get_ram_size((void *)PHYS_SDRAM_2,
  160. PHYS_SDRAM_2_SIZE);
  161. return 0;
  162. }
  163. void dram_init_banksize(void)
  164. {
  165. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  166. gd->bd->bi_dram[0].size = get_ram_size((void *)PHYS_SDRAM_1,
  167. PHYS_SDRAM_1_SIZE);
  168. gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
  169. if (get_num_ram_bank() > 1)
  170. gd->bd->bi_dram[1].size = get_ram_size((void *)PHYS_SDRAM_2,
  171. PHYS_SDRAM_2_SIZE);
  172. else
  173. gd->bd->bi_dram[1].size = 0;
  174. }
  175. ulong board_get_usable_ram_top(ulong total_size)
  176. {
  177. ulong ramtop;
  178. if (get_num_ram_bank() > 1)
  179. ramtop = PHYS_SDRAM_2 + get_ram_size((void *)PHYS_SDRAM_2,
  180. PHYS_SDRAM_2_SIZE);
  181. else
  182. ramtop = PHYS_SDRAM_1 + get_ram_size((void *)PHYS_SDRAM_1,
  183. PHYS_SDRAM_1_SIZE);
  184. return ramtop;
  185. }
  186. int checkboard(void)
  187. {
  188. printf("Board: Armadeus APF27 revision %d\n", get_board_rev());
  189. return 0;
  190. }
  191. #ifdef CONFIG_SPL_BUILD
  192. inline void hang(void)
  193. {
  194. for (;;)
  195. ;
  196. }
  197. void board_init_f(ulong bootflag)
  198. {
  199. /*
  200. * copy ourselves from where we are running to where we were
  201. * linked at. Use ulong pointers as all addresses involved
  202. * are 4-byte-aligned.
  203. */
  204. ulong *start_ptr, *end_ptr, *link_ptr, *run_ptr, *dst;
  205. asm volatile ("ldr %0, =_start" : "=r"(start_ptr));
  206. asm volatile ("ldr %0, =_end" : "=r"(end_ptr));
  207. asm volatile ("ldr %0, =board_init_f" : "=r"(link_ptr));
  208. asm volatile ("adr %0, board_init_f" : "=r"(run_ptr));
  209. for (dst = start_ptr; dst < end_ptr; dst++)
  210. *dst = *(dst+(run_ptr-link_ptr));
  211. /*
  212. * branch to nand_boot's link-time address.
  213. */
  214. asm volatile("ldr pc, =nand_boot");
  215. }
  216. #endif /* CONFIG_SPL_BUILD */