Nobuhiro Iwamatsu | 1251e49 | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 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 | |
| 10 | #include <common.h> |
| 11 | #include <malloc.h> |
| 12 | #include <asm/processor.h> |
| 13 | #include <asm/mach-types.h> |
| 14 | #include <asm/io.h> |
| 15 | #include <asm/errno.h> |
| 16 | #include <asm/arch/sys_proto.h> |
| 17 | #include <asm/gpio.h> |
| 18 | #include <asm/arch/rmobile.h> |
Nobuhiro Iwamatsu | 44e1eeb | 2014-12-02 16:52:19 +0900 | [diff] [blame^] | 19 | #include <asm/arch/rcar-mstp.h> |
Nobuhiro Iwamatsu | 90362c0 | 2013-10-20 20:37:17 +0900 | [diff] [blame] | 20 | #include <netdev.h> |
| 21 | #include <miiphy.h> |
Nobuhiro Iwamatsu | 1251e49 | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 22 | #include <i2c.h> |
Nobuhiro Iwamatsu | ccde677 | 2014-03-31 11:52:51 +0900 | [diff] [blame] | 23 | #include <div64.h> |
Nobuhiro Iwamatsu | 1251e49 | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 24 | #include "qos.h" |
| 25 | |
| 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
Nobuhiro Iwamatsu | ccde677 | 2014-03-31 11:52:51 +0900 | [diff] [blame] | 28 | #define CLK2MHZ(clk) (clk / 1000 / 1000) |
Nobuhiro Iwamatsu | 1251e49 | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 29 | void s_init(void) |
| 30 | { |
Nobuhiro Iwamatsu | ec9b386 | 2014-03-27 16:18:08 +0900 | [diff] [blame] | 31 | struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE; |
| 32 | struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE; |
Nobuhiro Iwamatsu | ccde677 | 2014-03-31 11:52:51 +0900 | [diff] [blame] | 33 | u32 stc; |
Nobuhiro Iwamatsu | 1251e49 | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 34 | |
| 35 | /* Watchdog init */ |
| 36 | writel(0xA5A5A500, &rwdt->rwtcsra); |
| 37 | writel(0xA5A5A500, &swdt->swtcsra); |
| 38 | |
Nobuhiro Iwamatsu | ccde677 | 2014-03-31 11:52:51 +0900 | [diff] [blame] | 39 | /* CPU frequency setting. Set to 1.5GHz */ |
| 40 | stc = ((1500 / CLK2MHZ(CONFIG_SYS_CLK_FREQ)) - 1) << PLL0_STC_BIT; |
| 41 | clrsetbits_le32(PLL0CR, PLL0_STC_MASK, stc); |
| 42 | |
Nobuhiro Iwamatsu | 1251e49 | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 43 | /* QoS */ |
| 44 | qos_init(); |
Nobuhiro Iwamatsu | 1251e49 | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 45 | } |
| 46 | |
Nobuhiro Iwamatsu | 1251e49 | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 47 | #define TMU0_MSTP125 (1 << 25) |
Nobuhiro Iwamatsu | 1251e49 | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 48 | #define SCIF0_MSTP721 (1 << 21) |
Nobuhiro Iwamatsu | 90362c0 | 2013-10-20 20:37:17 +0900 | [diff] [blame] | 49 | #define ETHER_MSTP813 (1 << 13) |
| 50 | |
Nobuhiro Iwamatsu | 1251e49 | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 51 | int board_early_init_f(void) |
| 52 | { |
| 53 | mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125); |
| 54 | |
Nobuhiro Iwamatsu | 1251e49 | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 55 | /* SCIF0 */ |
Nobuhiro Iwamatsu | 1251e49 | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 56 | mstp_clrbits_le32(MSTPSR7, SMSTPCR7, SCIF0_MSTP721); |
| 57 | |
Nobuhiro Iwamatsu | 90362c0 | 2013-10-20 20:37:17 +0900 | [diff] [blame] | 58 | /* ETHER */ |
| 59 | mstp_clrbits_le32(MSTPSR8, SMSTPCR8, ETHER_MSTP813); |
| 60 | |
Nobuhiro Iwamatsu | 1251e49 | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 61 | return 0; |
| 62 | } |
| 63 | |
Nobuhiro Iwamatsu | 9f861f0 | 2013-10-11 14:49:04 +0900 | [diff] [blame] | 64 | void arch_preboot_os(void) |
| 65 | { |
| 66 | /* Disable TMU0 */ |
| 67 | mstp_setbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125); |
| 68 | } |
| 69 | |
Nobuhiro Iwamatsu | 90362c0 | 2013-10-20 20:37:17 +0900 | [diff] [blame] | 70 | /* LSI pin pull-up control */ |
| 71 | #define PUPR5 0xe6060114 |
| 72 | #define PUPR5_ETH 0x3FFC0000 |
| 73 | #define PUPR5_ETH_MAGIC (1 << 27) |
Nobuhiro Iwamatsu | 1251e49 | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 74 | int board_init(void) |
| 75 | { |
| 76 | /* adress of boot parameters */ |
Nobuhiro Iwamatsu | 956556f | 2014-11-10 13:58:50 +0900 | [diff] [blame] | 77 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
Nobuhiro Iwamatsu | 1251e49 | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 78 | |
| 79 | /* Init PFC controller */ |
| 80 | r8a7791_pinmux_init(); |
| 81 | |
Nobuhiro Iwamatsu | 90362c0 | 2013-10-20 20:37:17 +0900 | [diff] [blame] | 82 | /* ETHER Enable */ |
| 83 | gpio_request(GPIO_FN_ETH_CRS_DV, NULL); |
| 84 | gpio_request(GPIO_FN_ETH_RX_ER, NULL); |
| 85 | gpio_request(GPIO_FN_ETH_RXD0, NULL); |
| 86 | gpio_request(GPIO_FN_ETH_RXD1, NULL); |
| 87 | gpio_request(GPIO_FN_ETH_LINK, NULL); |
| 88 | gpio_request(GPIO_FN_ETH_REFCLK, NULL); |
| 89 | gpio_request(GPIO_FN_ETH_MDIO, NULL); |
| 90 | gpio_request(GPIO_FN_ETH_TXD1, NULL); |
| 91 | gpio_request(GPIO_FN_ETH_TX_EN, NULL); |
| 92 | gpio_request(GPIO_FN_ETH_TXD0, NULL); |
| 93 | gpio_request(GPIO_FN_ETH_MDC, NULL); |
| 94 | gpio_request(GPIO_FN_IRQ0, NULL); |
| 95 | |
| 96 | mstp_clrbits_le32(PUPR5, PUPR5, PUPR5_ETH & ~PUPR5_ETH_MAGIC); |
| 97 | gpio_request(GPIO_GP_5_22, NULL); /* PHY_RST */ |
| 98 | mstp_clrbits_le32(PUPR5, PUPR5, PUPR5_ETH_MAGIC); |
| 99 | |
| 100 | gpio_direction_output(GPIO_GP_5_22, 0); |
| 101 | mdelay(20); |
| 102 | gpio_set_value(GPIO_GP_5_22, 1); |
| 103 | udelay(1); |
| 104 | |
Nobuhiro Iwamatsu | 1251e49 | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 105 | return 0; |
| 106 | } |
| 107 | |
Nobuhiro Iwamatsu | 90362c0 | 2013-10-20 20:37:17 +0900 | [diff] [blame] | 108 | #define CXR24 0xEE7003C0 /* MAC address high register */ |
| 109 | #define CXR25 0xEE7003C8 /* MAC address low register */ |
| 110 | int board_eth_init(bd_t *bis) |
| 111 | { |
| 112 | #ifdef CONFIG_SH_ETHER |
| 113 | int ret = -ENODEV; |
| 114 | u32 val; |
| 115 | unsigned char enetaddr[6]; |
| 116 | |
| 117 | ret = sh_eth_initialize(bis); |
| 118 | if (!eth_getenv_enetaddr("ethaddr", enetaddr)) |
| 119 | return ret; |
| 120 | |
| 121 | /* Set Mac address */ |
| 122 | val = enetaddr[0] << 24 | enetaddr[1] << 16 | |
| 123 | enetaddr[2] << 8 | enetaddr[3]; |
| 124 | writel(val, CXR24); |
| 125 | |
| 126 | val = enetaddr[4] << 8 | enetaddr[5]; |
| 127 | writel(val, CXR25); |
| 128 | |
| 129 | return ret; |
| 130 | #else |
| 131 | return 0; |
| 132 | #endif |
| 133 | } |
| 134 | |
Nobuhiro Iwamatsu | 1251e49 | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 135 | int dram_init(void) |
| 136 | { |
Nobuhiro Iwamatsu | 1251e49 | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 137 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE; |
| 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
Nobuhiro Iwamatsu | 90362c0 | 2013-10-20 20:37:17 +0900 | [diff] [blame] | 142 | /* koelsch has KSZ8041NL/RNL */ |
| 143 | #define PHY_CONTROL1 0x1E |
| 144 | #define PHY_LED_MODE 0xC0000 |
| 145 | #define PHY_LED_MODE_ACK 0x4000 |
| 146 | int board_phy_config(struct phy_device *phydev) |
| 147 | { |
| 148 | int ret = phy_read(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1); |
| 149 | ret &= ~PHY_LED_MODE; |
| 150 | ret |= PHY_LED_MODE_ACK; |
| 151 | ret = phy_write(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1, (u16)ret); |
| 152 | |
| 153 | return 0; |
| 154 | } |
| 155 | |
Nobuhiro Iwamatsu | 1251e49 | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 156 | const struct rmobile_sysinfo sysinfo = { |
| 157 | CONFIG_RMOBILE_BOARD_STRING |
| 158 | }; |
| 159 | |
Nobuhiro Iwamatsu | 1251e49 | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 160 | void reset_cpu(ulong addr) |
| 161 | { |
Nobuhiro Iwamatsu | b8f383b | 2013-10-10 10:48:20 +0900 | [diff] [blame] | 162 | u8 val; |
| 163 | |
| 164 | i2c_set_bus_num(2); /* PowerIC connected to ch2 */ |
| 165 | i2c_read(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1); |
| 166 | val |= 0x02; |
| 167 | i2c_write(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1); |
Nobuhiro Iwamatsu | 1251e49 | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 168 | } |