lager.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*
  2. * board/renesas/lager/lager.c
  3. * This file is lager board support.
  4. *
  5. * Copyright (C) 2013 Renesas Electronics Corporation
  6. * Copyright (C) 2013 Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
  7. *
  8. * SPDX-License-Identifier: GPL-2.0
  9. */
  10. #include <common.h>
  11. #include <malloc.h>
  12. #include <netdev.h>
  13. #include <dm.h>
  14. #include <dm/platform_data/serial_sh.h>
  15. #include <asm/processor.h>
  16. #include <asm/mach-types.h>
  17. #include <asm/io.h>
  18. #include <linux/errno.h>
  19. #include <asm/arch/sys_proto.h>
  20. #include <asm/gpio.h>
  21. #include <asm/arch/rmobile.h>
  22. #include <asm/arch/rcar-mstp.h>
  23. #include <asm/arch/mmc.h>
  24. #include <asm/arch/sh_sdhi.h>
  25. #include <miiphy.h>
  26. #include <i2c.h>
  27. #include <mmc.h>
  28. #include "qos.h"
  29. DECLARE_GLOBAL_DATA_PTR;
  30. #define CLK2MHZ(clk) (clk / 1000 / 1000)
  31. void s_init(void)
  32. {
  33. struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE;
  34. struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE;
  35. /* Watchdog init */
  36. writel(0xA5A5A500, &rwdt->rwtcsra);
  37. writel(0xA5A5A500, &swdt->swtcsra);
  38. /* CPU frequency setting. Set to 1.4GHz */
  39. if (rmobile_get_cpu_rev_integer() >= R8A7790_CUT_ES2X) {
  40. u32 stat = 0;
  41. u32 stc = ((1400 / CLK2MHZ(CONFIG_SYS_CLK_FREQ)) - 1)
  42. << PLL0_STC_BIT;
  43. clrsetbits_le32(PLL0CR, PLL0_STC_MASK, stc);
  44. do {
  45. stat = readl(PLLECR) & PLL0ST;
  46. } while (stat == 0x0);
  47. }
  48. /* QoS(Quality-of-Service) Init */
  49. qos_init();
  50. }
  51. #define TMU0_MSTP125 (1 << 25)
  52. #define SCIF0_MSTP721 (1 << 21)
  53. #define ETHER_MSTP813 (1 << 13)
  54. #define MMC1_MSTP305 (1 << 5)
  55. #define MSTPSR3 0xE6150048
  56. #define SMSTPCR3 0xE615013C
  57. #define SDHI0_MSTP314 (1 << 14)
  58. #define SDHI1_MSTP313 (1 << 13)
  59. #define SDHI2_MSTP312 (1 << 12)
  60. #define SD2CKCR 0xE6150078
  61. #define SD2_97500KHZ 0x7
  62. int board_early_init_f(void)
  63. {
  64. /* TMU0 */
  65. mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
  66. /* SCIF0 */
  67. mstp_clrbits_le32(MSTPSR7, SMSTPCR7, SCIF0_MSTP721);
  68. /* ETHER */
  69. mstp_clrbits_le32(MSTPSR8, SMSTPCR8, ETHER_MSTP813);
  70. /* eMMC */
  71. mstp_clrbits_le32(MSTPSR3, SMSTPCR3, MMC1_MSTP305);
  72. /* SDHI0, 2 */
  73. mstp_clrbits_le32(MSTPSR3, SMSTPCR3, SDHI0_MSTP314 | SDHI2_MSTP312);
  74. /*
  75. * SD0 clock is set to 97.5MHz by default.
  76. * Set SD2 to the 97.5MHz as well.
  77. */
  78. writel(SD2_97500KHZ, SD2CKCR);
  79. return 0;
  80. }
  81. DECLARE_GLOBAL_DATA_PTR;
  82. int board_init(void)
  83. {
  84. /* adress of boot parameters */
  85. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  86. /* Init PFC controller */
  87. r8a7790_pinmux_init();
  88. /* ETHER Enable */
  89. gpio_request(GPIO_FN_ETH_CRS_DV, NULL);
  90. gpio_request(GPIO_FN_ETH_RX_ER, NULL);
  91. gpio_request(GPIO_FN_ETH_RXD0, NULL);
  92. gpio_request(GPIO_FN_ETH_RXD1, NULL);
  93. gpio_request(GPIO_FN_ETH_LINK, NULL);
  94. gpio_request(GPIO_FN_ETH_REF_CLK, NULL);
  95. gpio_request(GPIO_FN_ETH_MDIO, NULL);
  96. gpio_request(GPIO_FN_ETH_TXD1, NULL);
  97. gpio_request(GPIO_FN_ETH_TX_EN, NULL);
  98. gpio_request(GPIO_FN_ETH_MAGIC, NULL);
  99. gpio_request(GPIO_FN_ETH_TXD0, NULL);
  100. gpio_request(GPIO_FN_ETH_MDC, NULL);
  101. gpio_request(GPIO_FN_IRQ0, NULL);
  102. gpio_request(GPIO_GP_5_31, NULL); /* PHY_RST */
  103. gpio_direction_output(GPIO_GP_5_31, 0);
  104. mdelay(20);
  105. gpio_set_value(GPIO_GP_5_31, 1);
  106. udelay(1);
  107. return 0;
  108. }
  109. #define CXR24 0xEE7003C0 /* MAC address high register */
  110. #define CXR25 0xEE7003C8 /* MAC address low register */
  111. int board_eth_init(bd_t *bis)
  112. {
  113. int ret = -ENODEV;
  114. #ifdef CONFIG_SH_ETHER
  115. u32 val;
  116. unsigned char enetaddr[6];
  117. ret = sh_eth_initialize(bis);
  118. if (!eth_getenv_enetaddr("ethaddr", enetaddr))
  119. return ret;
  120. /* Set Mac address */
  121. val = enetaddr[0] << 24 | enetaddr[1] << 16 |
  122. enetaddr[2] << 8 | enetaddr[3];
  123. writel(val, CXR24);
  124. val = enetaddr[4] << 8 | enetaddr[5];
  125. writel(val, CXR25);
  126. #endif
  127. return ret;
  128. }
  129. /* lager has KSZ8041NL/RNL */
  130. #define PHY_CONTROL1 0x1E
  131. #define PHY_LED_MODE 0xC0000
  132. #define PHY_LED_MODE_ACK 0x4000
  133. int board_phy_config(struct phy_device *phydev)
  134. {
  135. int ret = phy_read(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1);
  136. ret &= ~PHY_LED_MODE;
  137. ret |= PHY_LED_MODE_ACK;
  138. ret = phy_write(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1, (u16)ret);
  139. return 0;
  140. }
  141. int board_mmc_init(bd_t *bis)
  142. {
  143. int ret = -ENODEV;
  144. #ifdef CONFIG_SH_MMCIF
  145. gpio_request(GPIO_FN_MMC1_D0, NULL);
  146. gpio_request(GPIO_FN_MMC1_D1, NULL);
  147. gpio_request(GPIO_FN_MMC1_D2, NULL);
  148. gpio_request(GPIO_FN_MMC1_D3, NULL);
  149. gpio_request(GPIO_FN_MMC1_D4, NULL);
  150. gpio_request(GPIO_FN_MMC1_D5, NULL);
  151. gpio_request(GPIO_FN_MMC1_D6, NULL);
  152. gpio_request(GPIO_FN_MMC1_D7, NULL);
  153. gpio_request(GPIO_FN_MMC1_CLK, NULL);
  154. gpio_request(GPIO_FN_MMC1_CMD, NULL);
  155. ret = mmcif_mmc_init();
  156. #endif
  157. #ifdef CONFIG_SH_SDHI
  158. gpio_request(GPIO_FN_SD0_DAT0, NULL);
  159. gpio_request(GPIO_FN_SD0_DAT1, NULL);
  160. gpio_request(GPIO_FN_SD0_DAT2, NULL);
  161. gpio_request(GPIO_FN_SD0_DAT3, NULL);
  162. gpio_request(GPIO_FN_SD0_CLK, NULL);
  163. gpio_request(GPIO_FN_SD0_CMD, NULL);
  164. gpio_request(GPIO_FN_SD0_CD, NULL);
  165. gpio_request(GPIO_FN_SD2_DAT0, NULL);
  166. gpio_request(GPIO_FN_SD2_DAT1, NULL);
  167. gpio_request(GPIO_FN_SD2_DAT2, NULL);
  168. gpio_request(GPIO_FN_SD2_DAT3, NULL);
  169. gpio_request(GPIO_FN_SD2_CLK, NULL);
  170. gpio_request(GPIO_FN_SD2_CMD, NULL);
  171. gpio_request(GPIO_FN_SD2_CD, NULL);
  172. /*
  173. * SDHI 0
  174. * need JP3 set to pin-1 side on board.
  175. */
  176. gpio_request(GPIO_GP_5_24, NULL);
  177. gpio_request(GPIO_GP_5_29, NULL);
  178. gpio_direction_output(GPIO_GP_5_24, 1); /* power on */
  179. gpio_direction_output(GPIO_GP_5_29, 1); /* 1: 3.3V, 0: 1.8V */
  180. ret = sh_sdhi_init(CONFIG_SYS_SH_SDHI0_BASE, 0,
  181. SH_SDHI_QUIRK_16BIT_BUF);
  182. if (ret)
  183. return ret;
  184. /* SDHI 2 */
  185. gpio_request(GPIO_GP_5_25, NULL);
  186. gpio_request(GPIO_GP_5_30, NULL);
  187. gpio_direction_output(GPIO_GP_5_25, 1); /* power on */
  188. gpio_direction_output(GPIO_GP_5_30, 1); /* 1: 3.3V, 0: 1.8V */
  189. ret = sh_sdhi_init(CONFIG_SYS_SH_SDHI2_BASE, 2, 0);
  190. #endif
  191. return ret;
  192. }
  193. int dram_init(void)
  194. {
  195. gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
  196. return 0;
  197. }
  198. const struct rmobile_sysinfo sysinfo = {
  199. CONFIG_ARCH_RMOBILE_BOARD_STRING
  200. };
  201. void reset_cpu(ulong addr)
  202. {
  203. u8 val;
  204. i2c_set_bus_num(3); /* PowerIC connected to ch3 */
  205. i2c_init(400000, 0);
  206. i2c_read(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1);
  207. val |= 0x02;
  208. i2c_write(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1);
  209. }
  210. static const struct sh_serial_platdata serial_platdata = {
  211. .base = SCIF0_BASE,
  212. .type = PORT_SCIF,
  213. .clk = 14745600,
  214. .clk_mode = EXT_CLK,
  215. };
  216. U_BOOT_DEVICE(lager_serials) = {
  217. .name = "serial_sh",
  218. .platdata = &serial_platdata,
  219. };