Nobuhiro Iwamatsu | d74c8cf | 2013-11-21 17:06:46 +0900 | [diff] [blame] | 1 | /* |
| 2 | * board/renesas/lager/lager.c |
| 3 | * This file is lager board support. |
| 4 | * |
| 5 | * Copyright (C) 2013 Renesas Electronics Corporation |
| 6 | * Copyright (C) 2013 Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com> |
| 7 | * |
| 8 | * SPDX-License-Identifier: GPL-2.0 |
| 9 | */ |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <malloc.h> |
| 13 | #include <netdev.h> |
| 14 | #include <asm/processor.h> |
| 15 | #include <asm/mach-types.h> |
| 16 | #include <asm/io.h> |
| 17 | #include <asm/errno.h> |
| 18 | #include <asm/arch/sys_proto.h> |
| 19 | #include <asm/gpio.h> |
| 20 | #include <asm/arch/rmobile.h> |
Nobuhiro Iwamatsu | ade3c94 | 2014-12-02 16:52:19 +0900 | [diff] [blame^] | 21 | #include <asm/arch/rcar-mstp.h> |
Nobuhiro Iwamatsu | 0929b74 | 2013-10-20 20:28:24 +0900 | [diff] [blame] | 22 | #include <miiphy.h> |
Nobuhiro Iwamatsu | a99b6b5 | 2013-10-10 09:13:41 +0900 | [diff] [blame] | 23 | #include <i2c.h> |
Nobuhiro Iwamatsu | d74c8cf | 2013-11-21 17:06:46 +0900 | [diff] [blame] | 24 | #include "qos.h" |
| 25 | |
| 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
Nobuhiro Iwamatsu | 0751cbf | 2014-03-31 14:14:25 +0900 | [diff] [blame] | 28 | #define CLK2MHZ(clk) (clk / 1000 / 1000) |
Nobuhiro Iwamatsu | d74c8cf | 2013-11-21 17:06:46 +0900 | [diff] [blame] | 29 | void s_init(void) |
| 30 | { |
Nobuhiro Iwamatsu | fa3e41b | 2014-03-27 16:18:19 +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 | d74c8cf | 2013-11-21 17:06:46 +0900 | [diff] [blame] | 33 | |
| 34 | /* Watchdog init */ |
| 35 | writel(0xA5A5A500, &rwdt->rwtcsra); |
| 36 | writel(0xA5A5A500, &swdt->swtcsra); |
| 37 | |
Nobuhiro Iwamatsu | 0751cbf | 2014-03-31 14:14:25 +0900 | [diff] [blame] | 38 | /* CPU frequency setting. Set to 1.4GHz */ |
Nobuhiro Iwamatsu | 70ad4f6 | 2014-07-30 12:28:00 +0900 | [diff] [blame] | 39 | if (rmobile_get_cpu_rev_integer() >= R8A7790_CUT_ES2X) { |
Nobuhiro Iwamatsu | 67fd59b | 2014-10-31 16:08:11 +0900 | [diff] [blame] | 40 | u32 stat = 0; |
Nobuhiro Iwamatsu | 70ad4f6 | 2014-07-30 12:28:00 +0900 | [diff] [blame] | 41 | u32 stc = ((1400 / CLK2MHZ(CONFIG_SYS_CLK_FREQ)) - 1) |
| 42 | << PLL0_STC_BIT; |
| 43 | clrsetbits_le32(PLL0CR, PLL0_STC_MASK, stc); |
Nobuhiro Iwamatsu | 67fd59b | 2014-10-31 16:08:11 +0900 | [diff] [blame] | 44 | |
| 45 | do { |
| 46 | stat = readl(PLLECR) & PLL0ST; |
| 47 | } while (stat == 0x0); |
Nobuhiro Iwamatsu | 70ad4f6 | 2014-07-30 12:28:00 +0900 | [diff] [blame] | 48 | } |
Nobuhiro Iwamatsu | 0751cbf | 2014-03-31 14:14:25 +0900 | [diff] [blame] | 49 | |
Nobuhiro Iwamatsu | d74c8cf | 2013-11-21 17:06:46 +0900 | [diff] [blame] | 50 | /* QoS(Quality-of-Service) Init */ |
| 51 | qos_init(); |
Nobuhiro Iwamatsu | d74c8cf | 2013-11-21 17:06:46 +0900 | [diff] [blame] | 52 | } |
| 53 | |
Nobuhiro Iwamatsu | d74c8cf | 2013-11-21 17:06:46 +0900 | [diff] [blame] | 54 | #define TMU0_MSTP125 (1 << 25) |
Nobuhiro Iwamatsu | d74c8cf | 2013-11-21 17:06:46 +0900 | [diff] [blame] | 55 | #define SCIF0_MSTP721 (1 << 21) |
Nobuhiro Iwamatsu | 0929b74 | 2013-10-20 20:28:24 +0900 | [diff] [blame] | 56 | #define ETHER_MSTP813 (1 << 13) |
| 57 | |
Nobuhiro Iwamatsu | d74c8cf | 2013-11-21 17:06:46 +0900 | [diff] [blame] | 58 | int board_early_init_f(void) |
| 59 | { |
| 60 | /* TMU0 */ |
| 61 | mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125); |
Nobuhiro Iwamatsu | d74c8cf | 2013-11-21 17:06:46 +0900 | [diff] [blame] | 62 | /* SCIF0 */ |
Nobuhiro Iwamatsu | d74c8cf | 2013-11-21 17:06:46 +0900 | [diff] [blame] | 63 | mstp_clrbits_le32(MSTPSR7, SMSTPCR7, SCIF0_MSTP721); |
Nobuhiro Iwamatsu | 0929b74 | 2013-10-20 20:28:24 +0900 | [diff] [blame] | 64 | /* ETHER */ |
| 65 | mstp_clrbits_le32(MSTPSR8, SMSTPCR8, ETHER_MSTP813); |
| 66 | |
Nobuhiro Iwamatsu | d74c8cf | 2013-11-21 17:06:46 +0900 | [diff] [blame] | 67 | return 0; |
| 68 | } |
| 69 | |
Nobuhiro Iwamatsu | e5e91de | 2013-10-11 15:00:37 +0900 | [diff] [blame] | 70 | void arch_preboot_os(void) |
| 71 | { |
| 72 | /* Disable TMU0 */ |
| 73 | mstp_setbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125); |
| 74 | } |
| 75 | |
Nobuhiro Iwamatsu | d74c8cf | 2013-11-21 17:06:46 +0900 | [diff] [blame] | 76 | DECLARE_GLOBAL_DATA_PTR; |
| 77 | int board_init(void) |
| 78 | { |
Nobuhiro Iwamatsu | d74c8cf | 2013-11-21 17:06:46 +0900 | [diff] [blame] | 79 | /* adress of boot parameters */ |
Nobuhiro Iwamatsu | 9c87f99 | 2014-11-10 13:58:50 +0900 | [diff] [blame] | 80 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
Nobuhiro Iwamatsu | d74c8cf | 2013-11-21 17:06:46 +0900 | [diff] [blame] | 81 | |
| 82 | /* Init PFC controller */ |
| 83 | r8a7790_pinmux_init(); |
| 84 | |
Nobuhiro Iwamatsu | 0929b74 | 2013-10-20 20:28:24 +0900 | [diff] [blame] | 85 | /* ETHER Enable */ |
| 86 | gpio_request(GPIO_FN_ETH_CRS_DV, NULL); |
| 87 | gpio_request(GPIO_FN_ETH_RX_ER, NULL); |
| 88 | gpio_request(GPIO_FN_ETH_RXD0, NULL); |
| 89 | gpio_request(GPIO_FN_ETH_RXD1, NULL); |
| 90 | gpio_request(GPIO_FN_ETH_LINK, NULL); |
| 91 | gpio_request(GPIO_FN_ETH_REF_CLK, NULL); |
| 92 | gpio_request(GPIO_FN_ETH_MDIO, NULL); |
| 93 | gpio_request(GPIO_FN_ETH_TXD1, NULL); |
| 94 | gpio_request(GPIO_FN_ETH_TX_EN, NULL); |
| 95 | gpio_request(GPIO_FN_ETH_MAGIC, NULL); |
| 96 | gpio_request(GPIO_FN_ETH_TXD0, NULL); |
| 97 | gpio_request(GPIO_FN_ETH_MDC, NULL); |
| 98 | gpio_request(GPIO_FN_IRQ0, NULL); |
| 99 | |
| 100 | gpio_request(GPIO_GP_5_31, NULL); /* PHY_RST */ |
| 101 | gpio_direction_output(GPIO_GP_5_31, 0); |
| 102 | mdelay(20); |
| 103 | gpio_set_value(GPIO_GP_5_31, 1); |
| 104 | udelay(1); |
| 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | #define CXR24 0xEE7003C0 /* MAC address high register */ |
| 110 | #define CXR25 0xEE7003C8 /* MAC address low register */ |
| 111 | int board_eth_init(bd_t *bis) |
| 112 | { |
| 113 | int ret = -ENODEV; |
| 114 | |
| 115 | #ifdef CONFIG_SH_ETHER |
| 116 | u32 val; |
| 117 | unsigned char enetaddr[6]; |
| 118 | |
| 119 | ret = sh_eth_initialize(bis); |
| 120 | if (!eth_getenv_enetaddr("ethaddr", enetaddr)) |
| 121 | return ret; |
| 122 | |
| 123 | /* Set Mac address */ |
| 124 | val = enetaddr[0] << 24 | enetaddr[1] << 16 | |
| 125 | enetaddr[2] << 8 | enetaddr[3]; |
| 126 | writel(val, CXR24); |
| 127 | |
| 128 | val = enetaddr[4] << 8 | enetaddr[5]; |
| 129 | writel(val, CXR25); |
| 130 | |
| 131 | #endif |
| 132 | |
| 133 | return ret; |
| 134 | } |
| 135 | |
| 136 | /* lager has KSZ8041NL/RNL */ |
| 137 | #define PHY_CONTROL1 0x1E |
| 138 | #define PHY_LED_MODE 0xC0000 |
| 139 | #define PHY_LED_MODE_ACK 0x4000 |
| 140 | int board_phy_config(struct phy_device *phydev) |
| 141 | { |
| 142 | int ret = phy_read(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1); |
| 143 | ret &= ~PHY_LED_MODE; |
| 144 | ret |= PHY_LED_MODE_ACK; |
| 145 | ret = phy_write(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1, (u16)ret); |
| 146 | |
Nobuhiro Iwamatsu | d74c8cf | 2013-11-21 17:06:46 +0900 | [diff] [blame] | 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | int dram_init(void) |
| 151 | { |
Nobuhiro Iwamatsu | d74c8cf | 2013-11-21 17:06:46 +0900 | [diff] [blame] | 152 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE; |
| 153 | |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | const struct rmobile_sysinfo sysinfo = { |
| 158 | CONFIG_RMOBILE_BOARD_STRING |
| 159 | }; |
| 160 | |
Nobuhiro Iwamatsu | d74c8cf | 2013-11-21 17:06:46 +0900 | [diff] [blame] | 161 | void reset_cpu(ulong addr) |
| 162 | { |
Nobuhiro Iwamatsu | a99b6b5 | 2013-10-10 09:13:41 +0900 | [diff] [blame] | 163 | u8 val; |
| 164 | |
| 165 | i2c_set_bus_num(3); /* PowerIC connected to ch3 */ |
| 166 | i2c_init(400000, 0); |
| 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); |
Nobuhiro Iwamatsu | d74c8cf | 2013-11-21 17:06:46 +0900 | [diff] [blame] | 170 | } |