gose.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. * board/renesas/gose/gose.c
  3. *
  4. * Copyright (C) 2014 Renesas Electronics Corporation
  5. *
  6. * SPDX-License-Identifier: GPL-2.0
  7. */
  8. #include <common.h>
  9. #include <malloc.h>
  10. #include <dm.h>
  11. #include <dm/platform_data/serial_sh.h>
  12. #include <environment.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 "qos.h"
  26. DECLARE_GLOBAL_DATA_PTR;
  27. #define CLK2MHZ(clk) (clk / 1000 / 1000)
  28. void s_init(void)
  29. {
  30. struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE;
  31. struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE;
  32. u32 stc;
  33. /* Watchdog init */
  34. writel(0xA5A5A500, &rwdt->rwtcsra);
  35. writel(0xA5A5A500, &swdt->swtcsra);
  36. /* CPU frequency setting. Set to 1.5GHz */
  37. stc = ((1500 / CLK2MHZ(CONFIG_SYS_CLK_FREQ)) - 1) << PLL0_STC_BIT;
  38. clrsetbits_le32(PLL0CR, PLL0_STC_MASK, stc);
  39. /* QoS */
  40. qos_init();
  41. }
  42. #define TMU0_MSTP125 (1 << 25)
  43. #define SCIF0_MSTP721 (1 << 21)
  44. #define ETHER_MSTP813 (1 << 13)
  45. #define SDHI0_MSTP314 (1 << 14)
  46. #define SDHI1_MSTP312 (1 << 12)
  47. #define SDHI2_MSTP311 (1 << 11)
  48. #define SD1CKCR 0xE6150078
  49. #define SD2CKCR 0xE615026C
  50. #define SD_97500KHZ 0x7
  51. int board_early_init_f(void)
  52. {
  53. /* TMU0 */
  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. writel(SD_97500KHZ, SD1CKCR);
  63. writel(SD_97500KHZ, SD2CKCR);
  64. return 0;
  65. }
  66. #define PUPR5 0xE6060114
  67. #define PUPR5_ETH 0x3FFC0000
  68. #define PUPR5_ETH_MAGIC (1 << 27)
  69. int board_init(void)
  70. {
  71. /* adress of boot parameters */
  72. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  73. /* Init PFC controller */
  74. r8a7793_pinmux_init();
  75. /* ETHER Enable */
  76. gpio_request(GPIO_FN_ETH_CRS_DV, NULL);
  77. gpio_request(GPIO_FN_ETH_RX_ER, NULL);
  78. gpio_request(GPIO_FN_ETH_RXD0, NULL);
  79. gpio_request(GPIO_FN_ETH_RXD1, NULL);
  80. gpio_request(GPIO_FN_ETH_LINK, NULL);
  81. gpio_request(GPIO_FN_ETH_REFCLK, NULL);
  82. gpio_request(GPIO_FN_ETH_MDIO, NULL);
  83. gpio_request(GPIO_FN_ETH_TXD1, NULL);
  84. gpio_request(GPIO_FN_ETH_TX_EN, NULL);
  85. gpio_request(GPIO_FN_ETH_TXD0, NULL);
  86. gpio_request(GPIO_FN_ETH_MDC, NULL);
  87. gpio_request(GPIO_FN_IRQ0, NULL);
  88. mstp_clrbits_le32(PUPR5, PUPR5, PUPR5_ETH & ~PUPR5_ETH_MAGIC);
  89. gpio_request(GPIO_GP_5_22, NULL); /* PHY_RST */
  90. mstp_clrbits_le32(PUPR5, PUPR5, PUPR5_ETH_MAGIC);
  91. gpio_direction_output(GPIO_GP_5_22, 0);
  92. mdelay(20);
  93. gpio_set_value(GPIO_GP_5_22, 1);
  94. udelay(1);
  95. return 0;
  96. }
  97. #define CXR24 0xEE7003C0 /* MAC address high register */
  98. #define CXR25 0xEE7003C8 /* MAC address low register */
  99. int board_eth_init(bd_t *bis)
  100. {
  101. int ret = -ENODEV;
  102. u32 val;
  103. unsigned char enetaddr[6];
  104. #ifdef CONFIG_SH_ETHER
  105. ret = sh_eth_initialize(bis);
  106. if (!eth_env_get_enetaddr("ethaddr", enetaddr))
  107. return ret;
  108. /* Set Mac address */
  109. val = enetaddr[0] << 24 | enetaddr[1] << 16 |
  110. enetaddr[2] << 8 | enetaddr[3];
  111. writel(val, CXR24);
  112. val = enetaddr[4] << 8 | enetaddr[5];
  113. writel(val, CXR25);
  114. #endif
  115. return ret;
  116. }
  117. int board_mmc_init(bd_t *bis)
  118. {
  119. int ret = -ENODEV;
  120. #ifdef CONFIG_SH_SDHI
  121. gpio_request(GPIO_FN_SD0_DATA0, NULL);
  122. gpio_request(GPIO_FN_SD0_DATA1, NULL);
  123. gpio_request(GPIO_FN_SD0_DATA2, NULL);
  124. gpio_request(GPIO_FN_SD0_DATA3, NULL);
  125. gpio_request(GPIO_FN_SD0_CLK, NULL);
  126. gpio_request(GPIO_FN_SD0_CMD, NULL);
  127. gpio_request(GPIO_FN_SD0_CD, NULL);
  128. gpio_request(GPIO_FN_SD2_DATA0, NULL);
  129. gpio_request(GPIO_FN_SD2_DATA1, NULL);
  130. gpio_request(GPIO_FN_SD2_DATA2, NULL);
  131. gpio_request(GPIO_FN_SD2_DATA3, NULL);
  132. gpio_request(GPIO_FN_SD2_CLK, NULL);
  133. gpio_request(GPIO_FN_SD2_CMD, NULL);
  134. gpio_request(GPIO_FN_SD2_CD, NULL);
  135. /* SDHI 0 */
  136. gpio_request(GPIO_GP_7_17, NULL);
  137. gpio_request(GPIO_GP_2_12, NULL);
  138. gpio_direction_output(GPIO_GP_7_17, 1); /* power on */
  139. gpio_direction_output(GPIO_GP_2_12, 1); /* 1: 3.3V, 0: 1.8V */
  140. ret = sh_sdhi_init(CONFIG_SYS_SH_SDHI0_BASE, 0,
  141. SH_SDHI_QUIRK_16BIT_BUF);
  142. if (ret)
  143. return ret;
  144. /* SDHI 1 */
  145. gpio_request(GPIO_GP_7_18, NULL);
  146. gpio_request(GPIO_GP_2_13, NULL);
  147. gpio_direction_output(GPIO_GP_7_18, 1); /* power on */
  148. gpio_direction_output(GPIO_GP_2_13, 1); /* 1: 3.3V, 0: 1.8V */
  149. ret = sh_sdhi_init(CONFIG_SYS_SH_SDHI1_BASE, 1, 0);
  150. if (ret)
  151. return ret;
  152. /* SDHI 2 */
  153. gpio_request(GPIO_GP_7_19, NULL);
  154. gpio_request(GPIO_GP_2_26, NULL);
  155. gpio_direction_output(GPIO_GP_7_19, 1); /* power on */
  156. gpio_direction_output(GPIO_GP_2_26, 1); /* 1: 3.3V, 0: 1.8V */
  157. ret = sh_sdhi_init(CONFIG_SYS_SH_SDHI2_BASE, 2, 0);
  158. #endif
  159. return ret;
  160. }
  161. int dram_init(void)
  162. {
  163. gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
  164. return 0;
  165. }
  166. const struct rmobile_sysinfo sysinfo = {
  167. CONFIG_ARCH_RMOBILE_BOARD_STRING
  168. };
  169. void reset_cpu(ulong addr)
  170. {
  171. u8 val;
  172. i2c_set_bus_num(2); /* PowerIC connected to ch2 */
  173. i2c_read(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1);
  174. val |= 0x02;
  175. i2c_write(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1);
  176. }
  177. static const struct sh_serial_platdata serial_platdata = {
  178. .base = SCIF0_BASE,
  179. .type = PORT_SCIF,
  180. .clk = 14745600,
  181. .clk_mode = EXT_CLK,
  182. };
  183. U_BOOT_DEVICE(gose_serials) = {
  184. .name = "serial_sh",
  185. .platdata = &serial_platdata,
  186. };