silk.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * board/renesas/silk/silk.c
  3. *
  4. * Copyright (C) 2015 Renesas Electronics Corporation
  5. * Copyright (C) 2015 Cogent Embedded, Inc.
  6. *
  7. * SPDX-License-Identifier: GPL-2.0
  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/mmc.h>
  22. #include <asm/arch/sh_sdhi.h>
  23. #include <netdev.h>
  24. #include <miiphy.h>
  25. #include <i2c.h>
  26. #include <div64.h>
  27. #include "qos.h"
  28. DECLARE_GLOBAL_DATA_PTR;
  29. #define CLK2MHZ(clk) (clk / 1000 / 1000)
  30. void s_init(void)
  31. {
  32. struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE;
  33. struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE;
  34. /* Watchdog init */
  35. writel(0xA5A5A500, &rwdt->rwtcsra);
  36. writel(0xA5A5A500, &swdt->swtcsra);
  37. /* QoS */
  38. qos_init();
  39. }
  40. #define TMU0_MSTP125 (1 << 25)
  41. #define SCIF2_MSTP719 (1 << 19)
  42. #define ETHER_MSTP813 (1 << 13)
  43. #define IIC1_MSTP323 (1 << 23)
  44. #define MMC0_MSTP315 (1 << 15)
  45. #define SDHI1_MSTP312 (1 << 12)
  46. #define SD1CKCR 0xE6150078
  47. #define SD1_97500KHZ 0x7
  48. int board_early_init_f(void)
  49. {
  50. /* TMU */
  51. mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
  52. /* SCIF2 */
  53. mstp_clrbits_le32(MSTPSR7, SMSTPCR7, SCIF2_MSTP719);
  54. /* ETHER */
  55. mstp_clrbits_le32(MSTPSR8, SMSTPCR8, ETHER_MSTP813);
  56. /* IIC1 / sh-i2c ch1 */
  57. mstp_clrbits_le32(MSTPSR3, SMSTPCR3, IIC1_MSTP323);
  58. #ifdef CONFIG_SH_MMCIF
  59. /* MMC */
  60. mstp_clrbits_le32(MSTPSR3, SMSTPCR3, MMC0_MSTP315);
  61. #endif
  62. #ifdef CONFIG_SH_SDHI
  63. /* SDHI1 */
  64. mstp_clrbits_le32(MSTPSR3, SMSTPCR3, SDHI1_MSTP312);
  65. /*
  66. * Set SD1 to the 97.5MHz
  67. */
  68. writel(SD1_97500KHZ, SD1CKCR);
  69. #endif
  70. return 0;
  71. }
  72. /* LSI pin pull-up control */
  73. #define PUPR3 0xe606010C
  74. #define PUPR3_ETH 0x006FF800
  75. #define PUPR1 0xe6060104
  76. #define PUPR1_DREQ0_N (1 << 20)
  77. int board_init(void)
  78. {
  79. /* adress of boot parameters */
  80. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  81. /* Init PFC controller */
  82. r8a7794_pinmux_init();
  83. /* Ether Enable */
  84. gpio_request(GPIO_FN_ETH_CRS_DV, NULL);
  85. gpio_request(GPIO_FN_ETH_RX_ER, NULL);
  86. gpio_request(GPIO_FN_ETH_RXD0, NULL);
  87. gpio_request(GPIO_FN_ETH_RXD1, NULL);
  88. gpio_request(GPIO_FN_ETH_LINK, NULL);
  89. gpio_request(GPIO_FN_ETH_REFCLK, NULL);
  90. gpio_request(GPIO_FN_ETH_MDIO, NULL);
  91. gpio_request(GPIO_FN_ETH_TXD1, NULL);
  92. gpio_request(GPIO_FN_ETH_TX_EN, NULL);
  93. gpio_request(GPIO_FN_ETH_MAGIC, NULL);
  94. gpio_request(GPIO_FN_ETH_TXD0, NULL);
  95. gpio_request(GPIO_FN_ETH_MDC, NULL);
  96. gpio_request(GPIO_FN_IRQ8, NULL);
  97. /* PHY reset */
  98. mstp_clrbits_le32(PUPR3, PUPR3, PUPR3_ETH);
  99. gpio_request(GPIO_GP_1_24, NULL);
  100. mstp_clrbits_le32(PUPR1, PUPR1, PUPR1_DREQ0_N);
  101. gpio_direction_output(GPIO_GP_1_24, 0);
  102. mdelay(20);
  103. gpio_set_value(GPIO_GP_1_24, 1);
  104. udelay(1);
  105. return 0;
  106. }
  107. #define CXR24 0xEE7003C0 /* MAC address high register */
  108. #define CXR25 0xEE7003C8 /* MAC address low register */
  109. int board_eth_init(bd_t *bis)
  110. {
  111. #ifdef CONFIG_SH_ETHER
  112. int ret = -ENODEV;
  113. u32 val;
  114. unsigned char enetaddr[6];
  115. ret = sh_eth_initialize(bis);
  116. if (!eth_getenv_enetaddr("ethaddr", enetaddr))
  117. return ret;
  118. /* Set Mac address */
  119. val = enetaddr[0] << 24 | enetaddr[1] << 16 |
  120. enetaddr[2] << 8 | enetaddr[3];
  121. writel(val, CXR24);
  122. val = enetaddr[4] << 8 | enetaddr[5];
  123. writel(val, CXR25);
  124. return ret;
  125. #else
  126. return 0;
  127. #endif
  128. }
  129. int board_mmc_init(bd_t *bis)
  130. {
  131. int ret = -ENODEV;
  132. #ifdef CONFIG_SH_MMCIF
  133. /* MMC0 */
  134. gpio_request(GPIO_GP_4_31, NULL);
  135. gpio_direction_output(GPIO_GP_4_31, 1);
  136. ret = mmcif_mmc_init();
  137. #endif
  138. #ifdef CONFIG_SH_SDHI
  139. gpio_request(GPIO_FN_SD1_DATA0, NULL);
  140. gpio_request(GPIO_FN_SD1_DATA1, NULL);
  141. gpio_request(GPIO_FN_SD1_DATA2, NULL);
  142. gpio_request(GPIO_FN_SD1_DATA3, NULL);
  143. gpio_request(GPIO_FN_SD1_CLK, NULL);
  144. gpio_request(GPIO_FN_SD1_CMD, NULL);
  145. gpio_request(GPIO_FN_SD1_CD, NULL);
  146. /* SDHI 1 */
  147. gpio_request(GPIO_GP_4_26, NULL);
  148. gpio_request(GPIO_GP_4_29, NULL);
  149. gpio_direction_output(GPIO_GP_4_26, 1);
  150. gpio_direction_output(GPIO_GP_4_29, 1);
  151. ret = sh_sdhi_init(CONFIG_SYS_SH_SDHI1_BASE, 1, 0);
  152. #endif
  153. return ret;
  154. }
  155. int dram_init(void)
  156. {
  157. gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
  158. return 0;
  159. }
  160. const struct rmobile_sysinfo sysinfo = {
  161. CONFIG_ARCH_RMOBILE_BOARD_STRING
  162. };
  163. void reset_cpu(ulong addr)
  164. {
  165. u8 val;
  166. i2c_set_bus_num(1); /* PowerIC connected to ch1 */
  167. i2c_read(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1);
  168. val |= 0x02;
  169. i2c_write(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1);
  170. }
  171. static const struct sh_serial_platdata serial_platdata = {
  172. .base = SCIF2_BASE,
  173. .type = PORT_SCIF,
  174. .clk = 14745600,
  175. .clk_mode = EXT_CLK,
  176. };
  177. U_BOOT_DEVICE(silk_serials) = {
  178. .name = "serial_sh",
  179. .platdata = &serial_platdata,
  180. };