gose.c 5.3 KB

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