ci20.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * CI20 setup code
  4. *
  5. * Copyright (c) 2013 Imagination Technologies
  6. * Author: Paul Burton <paul.burton@imgtec.com>
  7. */
  8. #include <common.h>
  9. #include <env.h>
  10. #include <init.h>
  11. #include <net.h>
  12. #include <netdev.h>
  13. #include <asm/global_data.h>
  14. #include <asm/io.h>
  15. #include <asm/gpio.h>
  16. #include <linux/bitops.h>
  17. #include <linux/delay.h>
  18. #include <mach/jz4780.h>
  19. #include <mach/jz4780_dram.h>
  20. #include <mach/jz4780_gpio.h>
  21. struct ci20_otp {
  22. u32 serial_number;
  23. u32 date;
  24. u8 manufacturer[2];
  25. u8 mac[6];
  26. } __packed;
  27. static void ci20_mux_mmc(void)
  28. {
  29. void __iomem *gpio_regs = (void __iomem *)GPIO_BASE;
  30. /* setup MSC1 pins */
  31. writel(0x30f00000, gpio_regs + GPIO_PXINTC(4));
  32. writel(0x30f00000, gpio_regs + GPIO_PXMASKC(4));
  33. writel(0x30f00000, gpio_regs + GPIO_PXPAT1C(4));
  34. writel(0x30f00000, gpio_regs + GPIO_PXPAT0C(4));
  35. writel(0x30f00000, gpio_regs + GPIO_PXPENC(4));
  36. jz4780_clk_ungate_mmc();
  37. }
  38. #ifndef CONFIG_SPL_BUILD
  39. static void ci20_mux_eth(void)
  40. {
  41. void __iomem *gpio_regs = (void __iomem *)GPIO_BASE;
  42. #ifdef CONFIG_MTD_RAW_NAND
  43. /* setup pins (some already setup for NAND) */
  44. writel(0x04030000, gpio_regs + GPIO_PXINTC(0));
  45. writel(0x04030000, gpio_regs + GPIO_PXMASKC(0));
  46. writel(0x04030000, gpio_regs + GPIO_PXPAT1C(0));
  47. writel(0x04030000, gpio_regs + GPIO_PXPAT0C(0));
  48. writel(0x04030000, gpio_regs + GPIO_PXPENS(0));
  49. #else
  50. /* setup pins (as above +NAND CS +RD/WE +SDx +SAx) */
  51. writel(0x0dff00ff, gpio_regs + GPIO_PXINTC(0));
  52. writel(0x0dff00ff, gpio_regs + GPIO_PXMASKC(0));
  53. writel(0x0dff00ff, gpio_regs + GPIO_PXPAT1C(0));
  54. writel(0x0dff00ff, gpio_regs + GPIO_PXPAT0C(0));
  55. writel(0x0dff00ff, gpio_regs + GPIO_PXPENS(0));
  56. writel(0x00000003, gpio_regs + GPIO_PXINTC(1));
  57. writel(0x00000003, gpio_regs + GPIO_PXMASKC(1));
  58. writel(0x00000003, gpio_regs + GPIO_PXPAT1C(1));
  59. writel(0x00000003, gpio_regs + GPIO_PXPAT0C(1));
  60. writel(0x00000003, gpio_regs + GPIO_PXPENS(1));
  61. #endif
  62. }
  63. static void ci20_mux_jtag(void)
  64. {
  65. #ifdef CONFIG_JTAG
  66. void __iomem *gpio_regs = (void __iomem *)GPIO_BASE;
  67. /* enable JTAG */
  68. writel(3 << 30, gpio_regs + GPIO_PXINTC(0));
  69. writel(3 << 30, gpio_regs + GPIO_PXMASKC(0));
  70. writel(3 << 30, gpio_regs + GPIO_PXPAT1C(0));
  71. writel(3 << 30, gpio_regs + GPIO_PXPAT0C(0));
  72. #endif
  73. }
  74. static void ci20_mux_nand(void)
  75. {
  76. void __iomem *gpio_regs = (void __iomem *)GPIO_BASE;
  77. /* setup pins */
  78. writel(0x002c00ff, gpio_regs + GPIO_PXINTC(0));
  79. writel(0x002c00ff, gpio_regs + GPIO_PXMASKC(0));
  80. writel(0x002c00ff, gpio_regs + GPIO_PXPAT1C(0));
  81. writel(0x002c00ff, gpio_regs + GPIO_PXPAT0C(0));
  82. writel(0x002c00ff, gpio_regs + GPIO_PXPENS(0));
  83. writel(0x00000003, gpio_regs + GPIO_PXINTC(1));
  84. writel(0x00000003, gpio_regs + GPIO_PXMASKC(1));
  85. writel(0x00000003, gpio_regs + GPIO_PXPAT1C(1));
  86. writel(0x00000003, gpio_regs + GPIO_PXPAT0C(1));
  87. writel(0x00000003, gpio_regs + GPIO_PXPENS(1));
  88. /* FRB0_N */
  89. jz47xx_gpio_direction_input(JZ_GPIO(0, 20));
  90. writel(20, gpio_regs + GPIO_PXPENS(0));
  91. /* disable write protect */
  92. jz47xx_gpio_direction_output(JZ_GPIO(5, 22), 1);
  93. }
  94. static void ci20_mux_uart(void)
  95. {
  96. void __iomem *gpio_regs = (void __iomem *)GPIO_BASE;
  97. /* UART0 */
  98. writel(0x9, gpio_regs + GPIO_PXINTC(5));
  99. writel(0x9, gpio_regs + GPIO_PXMASKC(5));
  100. writel(0x9, gpio_regs + GPIO_PXPAT1C(5));
  101. writel(0x9, gpio_regs + GPIO_PXPAT0C(5));
  102. writel(0x9, gpio_regs + GPIO_PXPENC(5));
  103. jz4780_clk_ungate_uart(0);
  104. /* UART 1 and 2 */
  105. jz4780_clk_ungate_uart(1);
  106. jz4780_clk_ungate_uart(2);
  107. #ifndef CONFIG_JTAG
  108. /* UART3 */
  109. writel(1 << 12, gpio_regs + GPIO_PXINTC(3));
  110. writel(1 << 12, gpio_regs + GPIO_PXMASKS(3));
  111. writel(1 << 12, gpio_regs + GPIO_PXPAT1S(3));
  112. writel(1 << 12, gpio_regs + GPIO_PXPAT0C(3));
  113. writel(3 << 30, gpio_regs + GPIO_PXINTC(0));
  114. writel(3 << 30, gpio_regs + GPIO_PXMASKC(0));
  115. writel(3 << 30, gpio_regs + GPIO_PXPAT1C(0));
  116. writel(1 << 30, gpio_regs + GPIO_PXPAT0C(0));
  117. writel(1 << 31, gpio_regs + GPIO_PXPAT0S(0));
  118. jz4780_clk_ungate_uart(3);
  119. #endif
  120. /* UART4 */
  121. writel(0x100400, gpio_regs + GPIO_PXINTC(2));
  122. writel(0x100400, gpio_regs + GPIO_PXMASKC(2));
  123. writel(0x100400, gpio_regs + GPIO_PXPAT1S(2));
  124. writel(0x100400, gpio_regs + GPIO_PXPAT0C(2));
  125. writel(0x100400, gpio_regs + GPIO_PXPENC(2));
  126. jz4780_clk_ungate_uart(4);
  127. }
  128. int board_early_init_f(void)
  129. {
  130. ci20_mux_jtag();
  131. ci20_mux_uart();
  132. ci20_mux_eth();
  133. ci20_mux_mmc();
  134. ci20_mux_nand();
  135. /* SYS_POWER_IND high (LED blue, VBUS off) */
  136. jz47xx_gpio_direction_output(JZ_GPIO(5, 15), 0);
  137. /* LEDs off */
  138. jz47xx_gpio_direction_output(JZ_GPIO(2, 0), 0);
  139. jz47xx_gpio_direction_output(JZ_GPIO(2, 1), 0);
  140. jz47xx_gpio_direction_output(JZ_GPIO(2, 2), 0);
  141. jz47xx_gpio_direction_output(JZ_GPIO(2, 3), 0);
  142. return 0;
  143. }
  144. int misc_init_r(void)
  145. {
  146. const u32 efuse_clk = jz4780_clk_get_efuse_clk();
  147. struct ci20_otp otp;
  148. char manufacturer[3];
  149. /* Read the board OTP data */
  150. jz4780_efuse_init(efuse_clk);
  151. jz4780_efuse_read(0x18, 16, (u8 *)&otp);
  152. /* Set MAC address */
  153. if (!is_valid_ethaddr(otp.mac)) {
  154. /* no MAC assigned, generate one from the unique chip ID */
  155. jz4780_efuse_read(0x8, 4, &otp.mac[0]);
  156. jz4780_efuse_read(0x12, 2, &otp.mac[4]);
  157. otp.mac[0] = (otp.mac[0] | 0x02) & ~0x01;
  158. }
  159. eth_env_set_enetaddr("ethaddr", otp.mac);
  160. /* Put other board information into the environment */
  161. env_set_ulong("serial#", otp.serial_number);
  162. env_set_ulong("board_date", otp.date);
  163. manufacturer[0] = otp.manufacturer[0];
  164. manufacturer[1] = otp.manufacturer[1];
  165. manufacturer[2] = 0;
  166. env_set("board_mfr", manufacturer);
  167. return 0;
  168. }
  169. #ifdef CONFIG_DRIVER_DM9000
  170. int board_eth_init(struct bd_info *bis)
  171. {
  172. /* Enable clock */
  173. jz4780_clk_ungate_ethernet();
  174. /* Enable power (PB25) */
  175. jz47xx_gpio_direction_output(JZ_GPIO(1, 25), 1);
  176. /* Reset (PF12) */
  177. mdelay(10);
  178. jz47xx_gpio_direction_output(JZ_GPIO(5, 12), 0);
  179. mdelay(10);
  180. jz47xx_gpio_direction_output(JZ_GPIO(5, 12), 1);
  181. mdelay(10);
  182. return dm9000_initialize(bis);
  183. }
  184. #endif /* CONFIG_DRIVER_DM9000 */
  185. #endif
  186. static u8 ci20_revision(void)
  187. {
  188. void __iomem *gpio_regs = (void __iomem *)GPIO_BASE;
  189. int val;
  190. jz47xx_gpio_direction_input(JZ_GPIO(2, 18));
  191. jz47xx_gpio_direction_input(JZ_GPIO(2, 19));
  192. /* Enable pullups */
  193. writel(BIT(18) | BIT(19), gpio_regs + GPIO_PXPENC(2));
  194. /* Read PC18/19 for version */
  195. val = (!!jz47xx_gpio_get_value(JZ_GPIO(2, 18))) |
  196. ((!!jz47xx_gpio_get_value(JZ_GPIO(2, 19))) << 1);
  197. if (val == 3) /* Rev 1 boards had no pulldowns - giving 3 */
  198. return 1;
  199. if (val == 1) /* Rev 2 boards pulldown port C bit 18 giving 1 */
  200. return 2;
  201. return 0;
  202. }
  203. int dram_init(void)
  204. {
  205. gd->ram_size = sdram_size(0) + sdram_size(1);
  206. return 0;
  207. }
  208. /* U-Boot common routines */
  209. int checkboard(void)
  210. {
  211. printf("Board: Creator CI20 (rev.%d)\n", ci20_revision());
  212. return 0;
  213. }
  214. #ifdef CONFIG_SPL_BUILD
  215. #if defined(CONFIG_SPL_MMC_SUPPORT)
  216. int board_mmc_init(struct bd_info *bd)
  217. {
  218. ci20_mux_mmc();
  219. return jz_mmc_init((void __iomem *)MSC0_BASE);
  220. }
  221. #endif
  222. static const struct jz4780_ddr_config K4B2G0846Q_48_config = {
  223. .timing = {
  224. (4 << DDRC_TIMING1_TRTP_BIT) | (13 << DDRC_TIMING1_TWTR_BIT) |
  225. (6 << DDRC_TIMING1_TWR_BIT) | (5 << DDRC_TIMING1_TWL_BIT),
  226. (4 << DDRC_TIMING2_TCCD_BIT) | (15 << DDRC_TIMING2_TRAS_BIT) |
  227. (6 << DDRC_TIMING2_TRCD_BIT) | (6 << DDRC_TIMING2_TRL_BIT),
  228. (4 << DDRC_TIMING3_ONUM) | (7 << DDRC_TIMING3_TCKSRE_BIT) |
  229. (6 << DDRC_TIMING3_TRP_BIT) | (4 << DDRC_TIMING3_TRRD_BIT) |
  230. (21 << DDRC_TIMING3_TRC_BIT),
  231. (31 << DDRC_TIMING4_TRFC_BIT) | (1 << DDRC_TIMING4_TRWCOV_BIT) |
  232. (4 << DDRC_TIMING4_TCKE_BIT) | (9 << DDRC_TIMING4_TMINSR_BIT) |
  233. (8 << DDRC_TIMING4_TXP_BIT) | (3 << DDRC_TIMING4_TMRD_BIT),
  234. (8 << DDRC_TIMING5_TRTW_BIT) | (4 << DDRC_TIMING5_TRDLAT_BIT) |
  235. (4 << DDRC_TIMING5_TWDLAT_BIT),
  236. (25 << DDRC_TIMING6_TXSRD_BIT) | (12 << DDRC_TIMING6_TFAW_BIT) |
  237. (2 << DDRC_TIMING6_TCFGW_BIT) | (2 << DDRC_TIMING6_TCFGR_BIT),
  238. },
  239. /* PHY */
  240. /* Mode Register 0 */
  241. .mr0 = 0x420,
  242. #ifdef SDRAM_DISABLE_DLL
  243. .mr1 = (DDR3_MR1_DIC_7 | DDR3_MR1_RTT_DIS | DDR3_MR1_DLL_DISABLE),
  244. #else
  245. .mr1 = (DDR3_MR1_DIC_7 | DDR3_MR1_RTT_DIS),
  246. #endif
  247. .ptr0 = 0x002000d4,
  248. .ptr1 = 0x02230d40,
  249. .ptr2 = 0x04013880,
  250. .dtpr0 = 0x2a8f6690,
  251. .dtpr1 = 0x00400860,
  252. .dtpr2 = 0x10042a00,
  253. .pullup = 0x0b,
  254. .pulldn = 0x0b,
  255. };
  256. static const struct jz4780_ddr_config H5TQ2G83CFR_48_config = {
  257. .timing = {
  258. (4 << DDRC_TIMING1_TRTP_BIT) | (13 << DDRC_TIMING1_TWTR_BIT) |
  259. (6 << DDRC_TIMING1_TWR_BIT) | (5 << DDRC_TIMING1_TWL_BIT),
  260. (4 << DDRC_TIMING2_TCCD_BIT) | (16 << DDRC_TIMING2_TRAS_BIT) |
  261. (6 << DDRC_TIMING2_TRCD_BIT) | (6 << DDRC_TIMING2_TRL_BIT),
  262. (4 << DDRC_TIMING3_ONUM) | (7 << DDRC_TIMING3_TCKSRE_BIT) |
  263. (6 << DDRC_TIMING3_TRP_BIT) | (4 << DDRC_TIMING3_TRRD_BIT) |
  264. (22 << DDRC_TIMING3_TRC_BIT),
  265. (42 << DDRC_TIMING4_TRFC_BIT) | (1 << DDRC_TIMING4_TRWCOV_BIT) |
  266. (4 << DDRC_TIMING4_TCKE_BIT) | (7 << DDRC_TIMING4_TMINSR_BIT) |
  267. (3 << DDRC_TIMING4_TXP_BIT) | (3 << DDRC_TIMING4_TMRD_BIT),
  268. (8 << DDRC_TIMING5_TRTW_BIT) | (4 << DDRC_TIMING5_TRDLAT_BIT) |
  269. (4 << DDRC_TIMING5_TWDLAT_BIT),
  270. (25 << DDRC_TIMING6_TXSRD_BIT) | (20 << DDRC_TIMING6_TFAW_BIT) |
  271. (2 << DDRC_TIMING6_TCFGW_BIT) | (2 << DDRC_TIMING6_TCFGR_BIT),
  272. },
  273. /* PHY */
  274. /* Mode Register 0 */
  275. .mr0 = 0x420,
  276. #ifdef SDRAM_DISABLE_DLL
  277. .mr1 = (DDR3_MR1_DIC_7 | DDR3_MR1_RTT_DIS | DDR3_MR1_DLL_DISABLE),
  278. #else
  279. .mr1 = (DDR3_MR1_DIC_7 | DDR3_MR1_RTT_DIS),
  280. #endif
  281. .ptr0 = 0x002000d4,
  282. .ptr1 = 0x02d30d40,
  283. .ptr2 = 0x04013880,
  284. .dtpr0 = 0x2c906690,
  285. .dtpr1 = 0x005608a0,
  286. .dtpr2 = 0x10042a00,
  287. .pullup = 0x0e,
  288. .pulldn = 0x0e,
  289. };
  290. #if (CONFIG_SYS_MHZ != 1200)
  291. #error No DDR configuration for CPU speed
  292. #endif
  293. const struct jz4780_ddr_config *jz4780_get_ddr_config(void)
  294. {
  295. const int board_revision = ci20_revision();
  296. if (board_revision == 2)
  297. return &K4B2G0846Q_48_config;
  298. else /* Fall back to H5TQ2G83CFR RAM */
  299. return &H5TQ2G83CFR_48_config;
  300. }
  301. #endif