blob: d35d20f130a64e616767c6763c35fa406623ee08 [file] [log] [blame]
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +09001/*
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>
Nobuhiro Iwamatsucf839572014-12-09 16:20:04 +090014#include <dm.h>
15#include <dm/platform_data/serial_sh.h>
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090016#include <asm/processor.h>
17#include <asm/mach-types.h>
18#include <asm/io.h>
19#include <asm/errno.h>
20#include <asm/arch/sys_proto.h>
21#include <asm/gpio.h>
22#include <asm/arch/rmobile.h>
Nobuhiro Iwamatsu44e1eeb2014-12-02 16:52:19 +090023#include <asm/arch/rcar-mstp.h>
Nobuhiro Iwamatsud7916b12014-12-03 15:30:30 +090024#include <asm/arch/mmc.h>
Nobuhiro Iwamatsu23565c62013-10-20 20:28:24 +090025#include <miiphy.h>
Nobuhiro Iwamatsub9986be2013-10-10 09:13:41 +090026#include <i2c.h>
Nobuhiro Iwamatsud7916b12014-12-03 15:30:30 +090027#include <mmc.h>
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090028#include "qos.h"
29
30DECLARE_GLOBAL_DATA_PTR;
31
Nobuhiro Iwamatsu2c2c6ba2014-03-31 14:14:25 +090032#define CLK2MHZ(clk) (clk / 1000 / 1000)
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090033void s_init(void)
34{
Nobuhiro Iwamatsudc535e12014-03-27 16:18:19 +090035 struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE;
36 struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE;
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090037
38 /* Watchdog init */
39 writel(0xA5A5A500, &rwdt->rwtcsra);
40 writel(0xA5A5A500, &swdt->swtcsra);
41
Nobuhiro Iwamatsu2c2c6ba2014-03-31 14:14:25 +090042 /* CPU frequency setting. Set to 1.4GHz */
Nobuhiro Iwamatsuf212a8a2014-07-30 12:28:00 +090043 if (rmobile_get_cpu_rev_integer() >= R8A7790_CUT_ES2X) {
Nobuhiro Iwamatsud8659c62014-10-31 16:08:11 +090044 u32 stat = 0;
Nobuhiro Iwamatsuf212a8a2014-07-30 12:28:00 +090045 u32 stc = ((1400 / CLK2MHZ(CONFIG_SYS_CLK_FREQ)) - 1)
46 << PLL0_STC_BIT;
47 clrsetbits_le32(PLL0CR, PLL0_STC_MASK, stc);
Nobuhiro Iwamatsud8659c62014-10-31 16:08:11 +090048
49 do {
50 stat = readl(PLLECR) & PLL0ST;
51 } while (stat == 0x0);
Nobuhiro Iwamatsuf212a8a2014-07-30 12:28:00 +090052 }
Nobuhiro Iwamatsu2c2c6ba2014-03-31 14:14:25 +090053
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090054 /* QoS(Quality-of-Service) Init */
55 qos_init();
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090056}
57
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090058#define TMU0_MSTP125 (1 << 25)
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090059#define SCIF0_MSTP721 (1 << 21)
Nobuhiro Iwamatsu23565c62013-10-20 20:28:24 +090060#define ETHER_MSTP813 (1 << 13)
Nobuhiro Iwamatsud7916b12014-12-03 15:30:30 +090061#define MMC1_MSTP305 (1 << 5)
Nobuhiro Iwamatsu23565c62013-10-20 20:28:24 +090062
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090063int board_early_init_f(void)
64{
65 /* TMU0 */
66 mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090067 /* SCIF0 */
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090068 mstp_clrbits_le32(MSTPSR7, SMSTPCR7, SCIF0_MSTP721);
Nobuhiro Iwamatsu23565c62013-10-20 20:28:24 +090069 /* ETHER */
70 mstp_clrbits_le32(MSTPSR8, SMSTPCR8, ETHER_MSTP813);
Nobuhiro Iwamatsud7916b12014-12-03 15:30:30 +090071 /* eMMC */
72 mstp_clrbits_le32(MSTPSR3, SMSTPCR3, MMC1_MSTP305);
Nobuhiro Iwamatsu23565c62013-10-20 20:28:24 +090073
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090074 return 0;
75}
76
77DECLARE_GLOBAL_DATA_PTR;
78int board_init(void)
79{
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090080 /* adress of boot parameters */
Nobuhiro Iwamatsueeb266a2014-11-10 13:58:50 +090081 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090082
83 /* Init PFC controller */
84 r8a7790_pinmux_init();
85
Nobuhiro Iwamatsu23565c62013-10-20 20:28:24 +090086 /* ETHER Enable */
87 gpio_request(GPIO_FN_ETH_CRS_DV, NULL);
88 gpio_request(GPIO_FN_ETH_RX_ER, NULL);
89 gpio_request(GPIO_FN_ETH_RXD0, NULL);
90 gpio_request(GPIO_FN_ETH_RXD1, NULL);
91 gpio_request(GPIO_FN_ETH_LINK, NULL);
92 gpio_request(GPIO_FN_ETH_REF_CLK, NULL);
93 gpio_request(GPIO_FN_ETH_MDIO, NULL);
94 gpio_request(GPIO_FN_ETH_TXD1, NULL);
95 gpio_request(GPIO_FN_ETH_TX_EN, NULL);
96 gpio_request(GPIO_FN_ETH_MAGIC, NULL);
97 gpio_request(GPIO_FN_ETH_TXD0, NULL);
98 gpio_request(GPIO_FN_ETH_MDC, NULL);
99 gpio_request(GPIO_FN_IRQ0, NULL);
100
101 gpio_request(GPIO_GP_5_31, NULL); /* PHY_RST */
102 gpio_direction_output(GPIO_GP_5_31, 0);
103 mdelay(20);
104 gpio_set_value(GPIO_GP_5_31, 1);
105 udelay(1);
106
107 return 0;
108}
109
110#define CXR24 0xEE7003C0 /* MAC address high register */
111#define CXR25 0xEE7003C8 /* MAC address low register */
112int board_eth_init(bd_t *bis)
113{
114 int ret = -ENODEV;
115
116#ifdef CONFIG_SH_ETHER
117 u32 val;
118 unsigned char enetaddr[6];
119
120 ret = sh_eth_initialize(bis);
121 if (!eth_getenv_enetaddr("ethaddr", enetaddr))
122 return ret;
123
124 /* Set Mac address */
125 val = enetaddr[0] << 24 | enetaddr[1] << 16 |
126 enetaddr[2] << 8 | enetaddr[3];
127 writel(val, CXR24);
128
129 val = enetaddr[4] << 8 | enetaddr[5];
130 writel(val, CXR25);
131
132#endif
133
134 return ret;
135}
136
137/* lager has KSZ8041NL/RNL */
138#define PHY_CONTROL1 0x1E
139#define PHY_LED_MODE 0xC0000
140#define PHY_LED_MODE_ACK 0x4000
141int board_phy_config(struct phy_device *phydev)
142{
143 int ret = phy_read(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1);
144 ret &= ~PHY_LED_MODE;
145 ret |= PHY_LED_MODE_ACK;
146 ret = phy_write(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1, (u16)ret);
147
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +0900148 return 0;
149}
150
Nobuhiro Iwamatsud7916b12014-12-03 15:30:30 +0900151int board_mmc_init(bd_t *bis)
152{
153 int ret = 0;
154
155#ifdef CONFIG_SH_MMCIF
156 gpio_request(GPIO_FN_MMC1_D0, NULL);
157 gpio_request(GPIO_FN_MMC1_D1, NULL);
158 gpio_request(GPIO_FN_MMC1_D2, NULL);
159 gpio_request(GPIO_FN_MMC1_D3, NULL);
160 gpio_request(GPIO_FN_MMC1_D4, NULL);
161 gpio_request(GPIO_FN_MMC1_D5, NULL);
162 gpio_request(GPIO_FN_MMC1_D6, NULL);
163 gpio_request(GPIO_FN_MMC1_D7, NULL);
164 gpio_request(GPIO_FN_MMC1_CLK, NULL);
165 gpio_request(GPIO_FN_MMC1_CMD, NULL);
166
167 ret = mmcif_mmc_init();
168#endif
169 return ret;
170}
171
172
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +0900173int dram_init(void)
174{
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +0900175 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
176
177 return 0;
178}
179
180const struct rmobile_sysinfo sysinfo = {
181 CONFIG_RMOBILE_BOARD_STRING
182};
183
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +0900184void reset_cpu(ulong addr)
185{
Nobuhiro Iwamatsub9986be2013-10-10 09:13:41 +0900186 u8 val;
187
188 i2c_set_bus_num(3); /* PowerIC connected to ch3 */
189 i2c_init(400000, 0);
190 i2c_read(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1);
191 val |= 0x02;
192 i2c_write(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1);
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +0900193}
Nobuhiro Iwamatsucf839572014-12-09 16:20:04 +0900194
195static const struct sh_serial_platdata serial_platdata = {
196 .base = SCIF0_BASE,
197 .type = PORT_SCIF,
198 .clk = 14745600,
199 .clk_mode = EXT_CLK,
200};
201
202U_BOOT_DEVICE(lager_serials) = {
203 .name = "serial_sh",
204 .platdata = &serial_platdata,
205};