Nobuhiro Iwamatsu | fdf7c65 | 2016-04-01 03:51:36 +0900 | [diff] [blame] | 1 | /* |
| 2 | * board/renesas/salvator-x/salvator-x.c |
Marek Vasut | 237dadd | 2017-05-13 15:57:53 +0200 | [diff] [blame] | 3 | * This file is Salvator-X/Salvator-XS board support. |
Nobuhiro Iwamatsu | fdf7c65 | 2016-04-01 03:51:36 +0900 | [diff] [blame] | 4 | * |
Marek Vasut | 5abb39b | 2017-05-13 15:57:46 +0200 | [diff] [blame] | 5 | * Copyright (C) 2015-2017 Renesas Electronics Corporation |
Nobuhiro Iwamatsu | fdf7c65 | 2016-04-01 03:51:36 +0900 | [diff] [blame] | 6 | * Copyright (C) 2015 Nobuhiro Iwamatsu <iwamatsu@nigauri.org> |
| 7 | * |
| 8 | * SPDX-License-Identifier: GPL-2.0+ |
| 9 | */ |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <malloc.h> |
| 13 | #include <netdev.h> |
| 14 | #include <dm.h> |
| 15 | #include <dm/platform_data/serial_sh.h> |
| 16 | #include <asm/processor.h> |
| 17 | #include <asm/mach-types.h> |
| 18 | #include <asm/io.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 19 | #include <linux/errno.h> |
Nobuhiro Iwamatsu | fdf7c65 | 2016-04-01 03:51:36 +0900 | [diff] [blame] | 20 | #include <asm/arch/sys_proto.h> |
| 21 | #include <asm/gpio.h> |
| 22 | #include <asm/arch/gpio.h> |
| 23 | #include <asm/arch/rmobile.h> |
| 24 | #include <asm/arch/rcar-mstp.h> |
Marek Vasut | 5abb39b | 2017-05-13 15:57:46 +0200 | [diff] [blame] | 25 | #include <asm/arch/sh_sdhi.h> |
Nobuhiro Iwamatsu | fdf7c65 | 2016-04-01 03:51:36 +0900 | [diff] [blame] | 26 | #include <i2c.h> |
| 27 | #include <mmc.h> |
| 28 | |
| 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
| 31 | #define CPGWPCR 0xE6150904 |
| 32 | #define CPGWPR 0xE615090C |
| 33 | |
| 34 | #define CLK2MHZ(clk) (clk / 1000 / 1000) |
| 35 | void s_init(void) |
| 36 | { |
| 37 | struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE; |
| 38 | struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE; |
| 39 | |
| 40 | /* Watchdog init */ |
| 41 | writel(0xA5A5A500, &rwdt->rwtcsra); |
| 42 | writel(0xA5A5A500, &swdt->swtcsra); |
| 43 | |
| 44 | writel(0xA5A50000, CPGWPCR); |
| 45 | writel(0xFFFFFFFF, CPGWPR); |
| 46 | } |
| 47 | |
Marek Vasut | 3614d30 | 2017-05-13 15:57:41 +0200 | [diff] [blame] | 48 | #define GSX_MSTP112 BIT(12) /* 3DG */ |
| 49 | #define TMU0_MSTP125 BIT(25) /* secure */ |
| 50 | #define TMU1_MSTP124 BIT(24) /* non-secure */ |
| 51 | #define SCIF2_MSTP310 BIT(10) /* SCIF2 */ |
Marek Vasut | 51e8006 | 2017-05-13 15:57:47 +0200 | [diff] [blame] | 52 | #define ETHERAVB_MSTP812 BIT(12) |
Marek Vasut | c16ed0b | 2017-05-13 15:57:48 +0200 | [diff] [blame] | 53 | #define DVFS_MSTP926 BIT(26) |
Marek Vasut | 5abb39b | 2017-05-13 15:57:46 +0200 | [diff] [blame] | 54 | #define SD0_MSTP314 BIT(14) |
| 55 | #define SD1_MSTP313 BIT(13) |
| 56 | #define SD2_MSTP312 BIT(12) /* either MMC0 */ |
| 57 | #define SD3_MSTP311 BIT(11) /* either MMC1 */ |
| 58 | |
| 59 | #define SD0CKCR 0xE6150074 |
| 60 | #define SD1CKCR 0xE6150078 |
| 61 | #define SD2CKCR 0xE6150268 |
| 62 | #define SD3CKCR 0xE615026C |
Nobuhiro Iwamatsu | fdf7c65 | 2016-04-01 03:51:36 +0900 | [diff] [blame] | 63 | |
| 64 | int board_early_init_f(void) |
| 65 | { |
| 66 | /* TMU0,1 */ /* which use ? */ |
| 67 | mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125 | TMU1_MSTP124); |
| 68 | /* SCIF2 */ |
| 69 | mstp_clrbits_le32(MSTPSR3, SMSTPCR3, SCIF2_MSTP310); |
Marek Vasut | 51e8006 | 2017-05-13 15:57:47 +0200 | [diff] [blame] | 70 | /* EHTERAVB */ |
| 71 | mstp_clrbits_le32(MSTPSR8, SMSTPCR8, ETHERAVB_MSTP812); |
Marek Vasut | 5abb39b | 2017-05-13 15:57:46 +0200 | [diff] [blame] | 72 | /* eMMC */ |
| 73 | mstp_clrbits_le32(MSTPSR3, SMSTPCR3, SD1_MSTP313 | SD2_MSTP312); |
| 74 | /* SDHI0, 3 */ |
| 75 | mstp_clrbits_le32(MSTPSR3, SMSTPCR3, SD0_MSTP314 | SD3_MSTP311); |
| 76 | |
Marek Vasut | bea0274 | 2017-09-05 15:11:14 +0200 | [diff] [blame] | 77 | writel(1, SD0CKCR); |
| 78 | writel(1, SD1CKCR); |
| 79 | writel(1, SD2CKCR); |
| 80 | writel(1, SD3CKCR); |
Nobuhiro Iwamatsu | fdf7c65 | 2016-04-01 03:51:36 +0900 | [diff] [blame] | 81 | |
Marek Vasut | c16ed0b | 2017-05-13 15:57:48 +0200 | [diff] [blame] | 82 | #if defined(CONFIG_SYS_I2C) && defined(CONFIG_SYS_I2C_SH) |
| 83 | /* DVFS for reset */ |
| 84 | mstp_clrbits_le32(MSTPSR9, SMSTPCR9, DVFS_MSTP926); |
| 85 | #endif |
Nobuhiro Iwamatsu | fdf7c65 | 2016-04-01 03:51:36 +0900 | [diff] [blame] | 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | /* SYSC */ |
| 90 | /* R/- 32 Power status register 2(3DG) */ |
| 91 | #define SYSC_PWRSR2 0xE6180100 |
| 92 | /* -/W 32 Power resume control register 2 (3DG) */ |
| 93 | #define SYSC_PWRONCR2 0xE618010C |
| 94 | |
Nobuhiro Iwamatsu | fdf7c65 | 2016-04-01 03:51:36 +0900 | [diff] [blame] | 95 | int board_init(void) |
| 96 | { |
| 97 | /* adress of boot parameters */ |
| 98 | gd->bd->bi_boot_params = CONFIG_SYS_TEXT_BASE + 0x50000; |
| 99 | |
| 100 | /* Init PFC controller */ |
Marek Vasut | 237dadd | 2017-05-13 15:57:53 +0200 | [diff] [blame] | 101 | #if defined(CONFIG_R8A7795) |
Nobuhiro Iwamatsu | fdf7c65 | 2016-04-01 03:51:36 +0900 | [diff] [blame] | 102 | r8a7795_pinmux_init(); |
Marek Vasut | 237dadd | 2017-05-13 15:57:53 +0200 | [diff] [blame] | 103 | #elif defined(CONFIG_R8A7796) |
| 104 | r8a7796_pinmux_init(); |
| 105 | #endif |
Nobuhiro Iwamatsu | fdf7c65 | 2016-04-01 03:51:36 +0900 | [diff] [blame] | 106 | |
Marek Vasut | 237dadd | 2017-05-13 15:57:53 +0200 | [diff] [blame] | 107 | #if defined(CONFIG_R8A7795) |
Nobuhiro Iwamatsu | fdf7c65 | 2016-04-01 03:51:36 +0900 | [diff] [blame] | 108 | /* GSX: force power and clock supply */ |
| 109 | writel(0x0000001F, SYSC_PWRONCR2); |
| 110 | while (readl(SYSC_PWRSR2) != 0x000003E0) |
| 111 | mdelay(20); |
| 112 | |
| 113 | mstp_clrbits_le32(MSTPSR1, SMSTPCR1, GSX_MSTP112); |
Marek Vasut | 237dadd | 2017-05-13 15:57:53 +0200 | [diff] [blame] | 114 | #endif |
Nobuhiro Iwamatsu | fdf7c65 | 2016-04-01 03:51:36 +0900 | [diff] [blame] | 115 | |
Marek Vasut | 4659a62 | 2017-05-13 15:57:49 +0200 | [diff] [blame] | 116 | /* USB1 pull-up */ |
| 117 | setbits_le32(PFC_PUEN6, PUEN_USB1_OVC | PUEN_USB1_PWEN); |
| 118 | |
Marek Vasut | 6b1bcd1 | 2017-08-28 14:12:34 +0200 | [diff] [blame] | 119 | #ifdef CONFIG_RENESAS_RAVB |
Marek Vasut | 51e8006 | 2017-05-13 15:57:47 +0200 | [diff] [blame] | 120 | /* EtherAVB Enable */ |
| 121 | /* GPSR2 */ |
| 122 | gpio_request(GPIO_GFN_AVB_AVTP_CAPTURE_A, NULL); |
| 123 | gpio_request(GPIO_GFN_AVB_AVTP_MATCH_A, NULL); |
| 124 | gpio_request(GPIO_GFN_AVB_LINK, NULL); |
| 125 | gpio_request(GPIO_GFN_AVB_PHY_INT, NULL); |
| 126 | gpio_request(GPIO_GFN_AVB_MAGIC, NULL); |
| 127 | gpio_request(GPIO_GFN_AVB_MDC, NULL); |
| 128 | |
| 129 | /* IPSR0 */ |
| 130 | gpio_request(GPIO_IFN_AVB_MDC, NULL); |
| 131 | gpio_request(GPIO_IFN_AVB_MAGIC, NULL); |
| 132 | gpio_request(GPIO_IFN_AVB_PHY_INT, NULL); |
| 133 | gpio_request(GPIO_IFN_AVB_LINK, NULL); |
| 134 | gpio_request(GPIO_IFN_AVB_AVTP_MATCH_A, NULL); |
| 135 | gpio_request(GPIO_IFN_AVB_AVTP_CAPTURE_A, NULL); |
| 136 | /* IPSR1 */ |
| 137 | gpio_request(GPIO_FN_AVB_AVTP_PPS, NULL); |
| 138 | /* IPSR2 */ |
| 139 | gpio_request(GPIO_FN_AVB_AVTP_MATCH_B, NULL); |
| 140 | /* IPSR3 */ |
| 141 | gpio_request(GPIO_FN_AVB_AVTP_CAPTURE_B, NULL); |
| 142 | |
Marek Vasut | 237dadd | 2017-05-13 15:57:53 +0200 | [diff] [blame] | 143 | #if defined(CONFIG_R8A7795) |
Marek Vasut | 4659a62 | 2017-05-13 15:57:49 +0200 | [diff] [blame] | 144 | /* USB2_OVC */ |
| 145 | gpio_request(GPIO_GP_6_15, NULL); |
| 146 | gpio_direction_input(GPIO_GP_6_15); |
| 147 | |
| 148 | /* USB2_PWEN */ |
| 149 | gpio_request(GPIO_GP_6_14, NULL); |
| 150 | gpio_direction_output(GPIO_GP_6_14, 1); |
| 151 | gpio_set_value(GPIO_GP_6_14, 1); |
Marek Vasut | 237dadd | 2017-05-13 15:57:53 +0200 | [diff] [blame] | 152 | #endif |
Marek Vasut | 51e8006 | 2017-05-13 15:57:47 +0200 | [diff] [blame] | 153 | /* AVB_PHY_RST */ |
| 154 | gpio_request(GPIO_GP_2_10, NULL); |
| 155 | gpio_direction_output(GPIO_GP_2_10, 0); |
| 156 | mdelay(20); |
| 157 | gpio_set_value(GPIO_GP_2_10, 1); |
| 158 | udelay(1); |
| 159 | #endif |
| 160 | |
Marek Vasut | 22eb59d | 2017-08-28 14:12:54 +0200 | [diff] [blame] | 161 | #ifdef CONFIG_MMC |
Marek Vasut | 5abb39b | 2017-05-13 15:57:46 +0200 | [diff] [blame] | 162 | /* SDHI0 */ |
| 163 | gpio_request(GPIO_GFN_SD0_DAT0, NULL); |
| 164 | gpio_request(GPIO_GFN_SD0_DAT1, NULL); |
| 165 | gpio_request(GPIO_GFN_SD0_DAT2, NULL); |
| 166 | gpio_request(GPIO_GFN_SD0_DAT3, NULL); |
| 167 | gpio_request(GPIO_GFN_SD0_CLK, NULL); |
| 168 | gpio_request(GPIO_GFN_SD0_CMD, NULL); |
| 169 | gpio_request(GPIO_GFN_SD0_CD, NULL); |
| 170 | gpio_request(GPIO_GFN_SD0_WP, NULL); |
| 171 | |
| 172 | gpio_request(GPIO_GP_5_2, NULL); |
| 173 | gpio_request(GPIO_GP_5_1, NULL); |
| 174 | gpio_direction_output(GPIO_GP_5_2, 1); /* power on */ |
| 175 | gpio_direction_output(GPIO_GP_5_1, 1); /* 1: 3.3V, 0: 1.8V */ |
| 176 | |
Marek Vasut | 5abb39b | 2017-05-13 15:57:46 +0200 | [diff] [blame] | 177 | /* SDHI1/SDHI2 eMMC */ |
| 178 | gpio_request(GPIO_GFN_SD1_DAT0, NULL); |
| 179 | gpio_request(GPIO_GFN_SD1_DAT1, NULL); |
| 180 | gpio_request(GPIO_GFN_SD1_DAT2, NULL); |
| 181 | gpio_request(GPIO_GFN_SD1_DAT3, NULL); |
| 182 | gpio_request(GPIO_GFN_SD2_DAT0, NULL); |
| 183 | gpio_request(GPIO_GFN_SD2_DAT1, NULL); |
| 184 | gpio_request(GPIO_GFN_SD2_DAT2, NULL); |
| 185 | gpio_request(GPIO_GFN_SD2_DAT3, NULL); |
| 186 | gpio_request(GPIO_GFN_SD2_CLK, NULL); |
Marek Vasut | 237dadd | 2017-05-13 15:57:53 +0200 | [diff] [blame] | 187 | #if defined(CONFIG_R8A7795) |
Marek Vasut | 5abb39b | 2017-05-13 15:57:46 +0200 | [diff] [blame] | 188 | gpio_request(GPIO_GFN_SD2_CMD, NULL); |
Marek Vasut | 237dadd | 2017-05-13 15:57:53 +0200 | [diff] [blame] | 189 | #elif defined(CONFIG_R8A7796) |
| 190 | gpio_request(GPIO_FN_SD2_CMD, NULL); |
| 191 | #else |
| 192 | #error Only R8A7795 and R87796 is supported |
| 193 | #endif |
Marek Vasut | 5abb39b | 2017-05-13 15:57:46 +0200 | [diff] [blame] | 194 | gpio_request(GPIO_GP_5_3, NULL); |
| 195 | gpio_request(GPIO_GP_5_9, NULL); |
| 196 | gpio_direction_output(GPIO_GP_5_3, 0); /* 1: 3.3V, 0: 1.8V */ |
| 197 | gpio_direction_output(GPIO_GP_5_9, 0); /* 1: 3.3V, 0: 1.8V */ |
| 198 | |
Marek Vasut | 237dadd | 2017-05-13 15:57:53 +0200 | [diff] [blame] | 199 | #if defined(CONFIG_R8A7795) |
Marek Vasut | 5abb39b | 2017-05-13 15:57:46 +0200 | [diff] [blame] | 200 | /* SDHI3 */ |
| 201 | gpio_request(GPIO_GFN_SD3_DAT0, NULL); /* GP_4_9 */ |
| 202 | gpio_request(GPIO_GFN_SD3_DAT1, NULL); /* GP_4_10 */ |
| 203 | gpio_request(GPIO_GFN_SD3_DAT2, NULL); /* GP_4_11 */ |
| 204 | gpio_request(GPIO_GFN_SD3_DAT3, NULL); /* GP_4_12 */ |
| 205 | gpio_request(GPIO_GFN_SD3_CLK, NULL); /* GP_4_7 */ |
| 206 | gpio_request(GPIO_GFN_SD3_CMD, NULL); /* GP_4_8 */ |
Marek Vasut | 237dadd | 2017-05-13 15:57:53 +0200 | [diff] [blame] | 207 | #elif defined(CONFIG_R8A7796) |
| 208 | gpio_request(GPIO_FN_SD3_DAT0, NULL); /* GP_4_9 */ |
| 209 | gpio_request(GPIO_FN_SD3_DAT1, NULL); /* GP_4_10 */ |
| 210 | gpio_request(GPIO_FN_SD3_DAT2, NULL); /* GP_4_11 */ |
| 211 | gpio_request(GPIO_FN_SD3_DAT3, NULL); /* GP_4_12 */ |
| 212 | gpio_request(GPIO_FN_SD3_CLK, NULL); /* GP_4_7 */ |
| 213 | gpio_request(GPIO_FN_SD3_CMD, NULL); /* GP_4_8 */ |
| 214 | #else |
| 215 | #error Only R8A7795 and R87796 is supported |
| 216 | #endif |
Marek Vasut | 5abb39b | 2017-05-13 15:57:46 +0200 | [diff] [blame] | 217 | /* IPSR10 */ |
| 218 | gpio_request(GPIO_FN_SD3_CD, NULL); |
| 219 | gpio_request(GPIO_FN_SD3_WP, NULL); |
| 220 | |
| 221 | gpio_request(GPIO_GP_3_15, NULL); |
| 222 | gpio_request(GPIO_GP_3_14, NULL); |
| 223 | gpio_direction_output(GPIO_GP_3_15, 1); /* power on */ |
| 224 | gpio_direction_output(GPIO_GP_3_14, 1); /* 1: 3.3V, 0: 1.8V */ |
Marek Vasut | 22eb59d | 2017-08-28 14:12:54 +0200 | [diff] [blame] | 225 | #endif |
Marek Vasut | 5abb39b | 2017-05-13 15:57:46 +0200 | [diff] [blame] | 226 | |
Marek Vasut | c9afcf6 | 2017-08-20 17:13:47 +0200 | [diff] [blame] | 227 | return 0; |
Marek Vasut | 5abb39b | 2017-05-13 15:57:46 +0200 | [diff] [blame] | 228 | } |
Nobuhiro Iwamatsu | fdf7c65 | 2016-04-01 03:51:36 +0900 | [diff] [blame] | 229 | |
| 230 | int dram_init(void) |
| 231 | { |
Marek Vasut | 3fca9d2 | 2017-05-13 15:57:50 +0200 | [diff] [blame] | 232 | gd->ram_size = PHYS_SDRAM_1_SIZE; |
| 233 | #if (CONFIG_NR_DRAM_BANKS >= 2) |
| 234 | gd->ram_size += PHYS_SDRAM_2_SIZE; |
| 235 | #endif |
| 236 | #if (CONFIG_NR_DRAM_BANKS >= 3) |
| 237 | gd->ram_size += PHYS_SDRAM_3_SIZE; |
| 238 | #endif |
| 239 | #if (CONFIG_NR_DRAM_BANKS >= 4) |
| 240 | gd->ram_size += PHYS_SDRAM_4_SIZE; |
| 241 | #endif |
| 242 | |
| 243 | return 0; |
| 244 | } |
Nobuhiro Iwamatsu | fdf7c65 | 2016-04-01 03:51:36 +0900 | [diff] [blame] | 245 | |
Marek Vasut | 3fca9d2 | 2017-05-13 15:57:50 +0200 | [diff] [blame] | 246 | int dram_init_banksize(void) |
| 247 | { |
| 248 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; |
| 249 | gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE; |
| 250 | #if (CONFIG_NR_DRAM_BANKS >= 2) |
| 251 | gd->bd->bi_dram[1].start = PHYS_SDRAM_2; |
| 252 | gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE; |
| 253 | #endif |
| 254 | #if (CONFIG_NR_DRAM_BANKS >= 3) |
| 255 | gd->bd->bi_dram[2].start = PHYS_SDRAM_3; |
| 256 | gd->bd->bi_dram[2].size = PHYS_SDRAM_3_SIZE; |
| 257 | #endif |
| 258 | #if (CONFIG_NR_DRAM_BANKS >= 4) |
| 259 | gd->bd->bi_dram[3].start = PHYS_SDRAM_4; |
| 260 | gd->bd->bi_dram[3].size = PHYS_SDRAM_4_SIZE; |
| 261 | #endif |
Nobuhiro Iwamatsu | fdf7c65 | 2016-04-01 03:51:36 +0900 | [diff] [blame] | 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | const struct rmobile_sysinfo sysinfo = { |
| 266 | CONFIG_RCAR_BOARD_STRING |
| 267 | }; |
| 268 | |
| 269 | #define RST_BASE 0xE6160000 |
| 270 | #define RST_CA57RESCNT (RST_BASE + 0x40) |
| 271 | #define RST_CA53RESCNT (RST_BASE + 0x44) |
| 272 | #define RST_RSTOUTCR (RST_BASE + 0x58) |
| 273 | #define RST_CODE 0xA5A5000F |
| 274 | |
| 275 | void reset_cpu(ulong addr) |
| 276 | { |
Marek Vasut | c16ed0b | 2017-05-13 15:57:48 +0200 | [diff] [blame] | 277 | #if defined(CONFIG_SYS_I2C) && defined(CONFIG_SYS_I2C_SH) |
| 278 | i2c_reg_write(CONFIG_SYS_I2C_POWERIC_ADDR, 0x20, 0x80); |
| 279 | #else |
Nobuhiro Iwamatsu | fdf7c65 | 2016-04-01 03:51:36 +0900 | [diff] [blame] | 280 | /* only CA57 ? */ |
| 281 | writel(RST_CODE, RST_CA57RESCNT); |
Marek Vasut | c16ed0b | 2017-05-13 15:57:48 +0200 | [diff] [blame] | 282 | #endif |
Nobuhiro Iwamatsu | fdf7c65 | 2016-04-01 03:51:36 +0900 | [diff] [blame] | 283 | } |