koelsch.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * board/renesas/koelsch/koelsch.c
  3. *
  4. * Copyright (C) 2013 Renesas Electronics Corporation
  5. *
  6. * SPDX-License-Identifier: GPL-2.0
  7. *
  8. */
  9. #include <common.h>
  10. #include <malloc.h>
  11. #include <dm.h>
  12. #include <dm/platform_data/serial_sh.h>
  13. #include <asm/processor.h>
  14. #include <asm/mach-types.h>
  15. #include <asm/io.h>
  16. #include <linux/errno.h>
  17. #include <asm/arch/sys_proto.h>
  18. #include <asm/gpio.h>
  19. #include <asm/arch/rmobile.h>
  20. #include <asm/arch/rcar-mstp.h>
  21. #include <asm/arch/sh_sdhi.h>
  22. #include <netdev.h>
  23. #include <miiphy.h>
  24. #include <i2c.h>
  25. #include <div64.h>
  26. #include "qos.h"
  27. DECLARE_GLOBAL_DATA_PTR;
  28. #define CLK2MHZ(clk) (clk / 1000 / 1000)
  29. void s_init(void)
  30. {
  31. struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE;
  32. struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE;
  33. u32 stc;
  34. /* Watchdog init */
  35. writel(0xA5A5A500, &rwdt->rwtcsra);
  36. writel(0xA5A5A500, &swdt->swtcsra);
  37. /* CPU frequency setting. Set to 1.5GHz */
  38. stc = ((1500 / CLK2MHZ(CONFIG_SYS_CLK_FREQ)) - 1) << PLL0_STC_BIT;
  39. clrsetbits_le32(PLL0CR, PLL0_STC_MASK, stc);
  40. /* QoS */
  41. qos_init();
  42. }
  43. #define TMU0_MSTP125 (1 << 25)
  44. #define SCIF0_MSTP721 (1 << 21)
  45. #define ETHER_MSTP813 (1 << 13)
  46. #define SDHI0_MSTP314 (1 << 14)
  47. #define SDHI1_MSTP312 (1 << 12)
  48. #define SDHI2_MSTP311 (1 << 11)
  49. #define SD1CKCR 0xE6150078
  50. #define SD2CKCR 0xE615026C
  51. #define SD_97500KHZ 0x7
  52. int board_early_init_f(void)
  53. {
  54. mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
  55. /* SCIF0 */
  56. mstp_clrbits_le32(MSTPSR7, SMSTPCR7, SCIF0_MSTP721);
  57. /* ETHER */
  58. mstp_clrbits_le32(MSTPSR8, SMSTPCR8, ETHER_MSTP813);
  59. /* SDHI */
  60. mstp_clrbits_le32(MSTPSR3, SMSTPCR3,
  61. SDHI0_MSTP314 | SDHI1_MSTP312 | SDHI2_MSTP311);
  62. /*
  63. * SD0 clock is set to 97.5MHz by default.
  64. * Set SD1 and SD2 to the 97.5MHz as well.
  65. */
  66. writel(SD_97500KHZ, SD1CKCR);
  67. writel(SD_97500KHZ, SD2CKCR);
  68. return 0;
  69. }
  70. /* LSI pin pull-up control */
  71. #define PUPR5 0xe6060114
  72. #define PUPR5_ETH 0x3FFC0000
  73. #define PUPR5_ETH_MAGIC (1 << 27)
  74. int board_init(void)
  75. {
  76. /* adress of boot parameters */
  77. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  78. /* Init PFC controller */
  79. r8a7791_pinmux_init();
  80. /* ETHER Enable */
  81. gpio_request(GPIO_FN_ETH_CRS_DV, NULL);
  82. gpio_request(GPIO_FN_ETH_RX_ER, NULL);
  83. gpio_request(GPIO_FN_ETH_RXD0, NULL);
  84. gpio_request(GPIO_FN_ETH_RXD1, NULL);
  85. gpio_request(GPIO_FN_ETH_LINK, NULL);
  86. gpio_request(GPIO_FN_ETH_REFCLK, NULL);
  87. gpio_request(GPIO_FN_ETH_MDIO, NULL);
  88. gpio_request(GPIO_FN_ETH_TXD1, NULL);
  89. gpio_request(GPIO_FN_ETH_TX_EN, NULL);
  90. gpio_request(GPIO_FN_ETH_TXD0, NULL);
  91. gpio_request(GPIO_FN_ETH_MDC, NULL);
  92. gpio_request(GPIO_FN_IRQ0, NULL);
  93. mstp_clrbits_le32(PUPR5, PUPR5, PUPR5_ETH & ~PUPR5_ETH_MAGIC);
  94. gpio_request(GPIO_GP_5_22, NULL); /* PHY_RST */
  95. mstp_clrbits_le32(PUPR5, PUPR5, PUPR5_ETH_MAGIC);
  96. gpio_direction_output(GPIO_GP_5_22, 0);
  97. mdelay(20);
  98. gpio_set_value(GPIO_GP_5_22, 1);
  99. udelay(1);
  100. return 0;
  101. }
  102. #define CXR24 0xEE7003C0 /* MAC address high register */
  103. #define CXR25 0xEE7003C8 /* MAC address low register */
  104. int board_eth_init(bd_t *bis)
  105. {
  106. #ifdef CONFIG_SH_ETHER
  107. int ret = -ENODEV;
  108. u32 val;
  109. unsigned char enetaddr[6];
  110. ret = sh_eth_initialize(bis);
  111. if (!eth_getenv_enetaddr("ethaddr", enetaddr))
  112. return ret;
  113. /* Set Mac address */
  114. val = enetaddr[0] << 24 | enetaddr[1] << 16 |
  115. enetaddr[2] << 8 | enetaddr[3];
  116. writel(val, CXR24);
  117. val = enetaddr[4] << 8 | enetaddr[5];
  118. writel(val, CXR25);
  119. return ret;
  120. #else
  121. return 0;
  122. #endif
  123. }
  124. int board_mmc_init(bd_t *bis)
  125. {
  126. int ret = -ENODEV;
  127. #ifdef CONFIG_SH_SDHI
  128. gpio_request(GPIO_FN_SD0_DATA0, NULL);
  129. gpio_request(GPIO_FN_SD0_DATA1, NULL);
  130. gpio_request(GPIO_FN_SD0_DATA2, NULL);
  131. gpio_request(GPIO_FN_SD0_DATA3, NULL);
  132. gpio_request(GPIO_FN_SD0_CLK, NULL);
  133. gpio_request(GPIO_FN_SD0_CMD, NULL);
  134. gpio_request(GPIO_FN_SD0_CD, NULL);
  135. gpio_request(GPIO_FN_SD2_DATA0, NULL);
  136. gpio_request(GPIO_FN_SD2_DATA1, NULL);
  137. gpio_request(GPIO_FN_SD2_DATA2, NULL);
  138. gpio_request(GPIO_FN_SD2_DATA3, NULL);
  139. gpio_request(GPIO_FN_SD2_CLK, NULL);
  140. gpio_request(GPIO_FN_SD2_CMD, NULL);
  141. gpio_request(GPIO_FN_SD2_CD, NULL);
  142. /* SDHI 0 */
  143. gpio_request(GPIO_GP_7_17, NULL);
  144. gpio_request(GPIO_GP_2_12, NULL);
  145. gpio_direction_output(GPIO_GP_7_17, 1); /* power on */
  146. gpio_direction_output(GPIO_GP_2_12, 1); /* 1: 3.3V, 0: 1.8V */
  147. ret = sh_sdhi_init(CONFIG_SYS_SH_SDHI0_BASE, 0,
  148. SH_SDHI_QUIRK_16BIT_BUF);
  149. if (ret)
  150. return ret;
  151. /* SDHI 1 */
  152. gpio_request(GPIO_GP_7_18, NULL);
  153. gpio_request(GPIO_GP_2_13, NULL);
  154. gpio_direction_output(GPIO_GP_7_18, 1); /* power on */
  155. gpio_direction_output(GPIO_GP_2_13, 1); /* 1: 3.3V, 0: 1.8V */
  156. ret = sh_sdhi_init(CONFIG_SYS_SH_SDHI1_BASE, 1, 0);
  157. if (ret)
  158. return ret;
  159. /* SDHI 2 */
  160. gpio_request(GPIO_GP_7_19, NULL);
  161. gpio_request(GPIO_GP_2_26, NULL);
  162. gpio_direction_output(GPIO_GP_7_19, 1); /* power on */
  163. gpio_direction_output(GPIO_GP_2_26, 1); /* 1: 3.3V, 0: 1.8V */
  164. ret = sh_sdhi_init(CONFIG_SYS_SH_SDHI2_BASE, 2, 0);
  165. #endif
  166. return ret;
  167. }
  168. int dram_init(void)
  169. {
  170. gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
  171. return 0;
  172. }
  173. /* koelsch has KSZ8041NL/RNL */
  174. #define PHY_CONTROL1 0x1E
  175. #define PHY_LED_MODE 0xC0000
  176. #define PHY_LED_MODE_ACK 0x4000
  177. int board_phy_config(struct phy_device *phydev)
  178. {
  179. int ret = phy_read(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1);
  180. ret &= ~PHY_LED_MODE;
  181. ret |= PHY_LED_MODE_ACK;
  182. ret = phy_write(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1, (u16)ret);
  183. return 0;
  184. }
  185. const struct rmobile_sysinfo sysinfo = {
  186. CONFIG_ARCH_RMOBILE_BOARD_STRING
  187. };
  188. void reset_cpu(ulong addr)
  189. {
  190. u8 val;
  191. i2c_set_bus_num(2); /* PowerIC connected to ch2 */
  192. i2c_read(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1);
  193. val |= 0x02;
  194. i2c_write(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1);
  195. }
  196. static const struct sh_serial_platdata serial_platdata = {
  197. .base = SCIF0_BASE,
  198. .type = PORT_SCIF,
  199. .clk = 14745600,
  200. .clk_mode = EXT_CLK,
  201. };
  202. U_BOOT_DEVICE(koelsch_serials) = {
  203. .name = "serial_sh",
  204. .platdata = &serial_platdata,
  205. };