blob: 23ef19494901df05c2f011cb14b0da3d80a79311 [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>
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 Iwamatsu23565c62013-10-20 20:28:24 +090021#include <miiphy.h>
Nobuhiro Iwamatsub9986be2013-10-10 09:13:41 +090022#include <i2c.h>
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090023#include "qos.h"
24
25DECLARE_GLOBAL_DATA_PTR;
26
Nobuhiro Iwamatsu2c2c6ba2014-03-31 14:14:25 +090027#define CLK2MHZ(clk) (clk / 1000 / 1000)
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090028void s_init(void)
29{
Nobuhiro Iwamatsudc535e12014-03-27 16:18:19 +090030 struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE;
31 struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE;
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090032
33 /* Watchdog init */
34 writel(0xA5A5A500, &rwdt->rwtcsra);
35 writel(0xA5A5A500, &swdt->swtcsra);
36
Nobuhiro Iwamatsu2c2c6ba2014-03-31 14:14:25 +090037 /* CPU frequency setting. Set to 1.4GHz */
Nobuhiro Iwamatsuf212a8a2014-07-30 12:28:00 +090038 if (rmobile_get_cpu_rev_integer() >= R8A7790_CUT_ES2X) {
Nobuhiro Iwamatsud8659c62014-10-31 16:08:11 +090039 u32 stat = 0;
Nobuhiro Iwamatsuf212a8a2014-07-30 12:28:00 +090040 u32 stc = ((1400 / CLK2MHZ(CONFIG_SYS_CLK_FREQ)) - 1)
41 << PLL0_STC_BIT;
42 clrsetbits_le32(PLL0CR, PLL0_STC_MASK, stc);
Nobuhiro Iwamatsud8659c62014-10-31 16:08:11 +090043
44 do {
45 stat = readl(PLLECR) & PLL0ST;
46 } while (stat == 0x0);
Nobuhiro Iwamatsuf212a8a2014-07-30 12:28:00 +090047 }
Nobuhiro Iwamatsu2c2c6ba2014-03-31 14:14:25 +090048
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090049 /* QoS(Quality-of-Service) Init */
50 qos_init();
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090051}
52
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090053#define TMU0_MSTP125 (1 << 25)
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090054#define SCIF0_MSTP721 (1 << 21)
Nobuhiro Iwamatsu23565c62013-10-20 20:28:24 +090055#define ETHER_MSTP813 (1 << 13)
56
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090057#define mstp_setbits(type, addr, saddr, set) \
58 out_##type((saddr), in_##type(addr) | (set))
59#define mstp_clrbits(type, addr, saddr, clear) \
60 out_##type((saddr), in_##type(addr) & ~(clear))
61#define mstp_setbits_le32(addr, saddr, set) \
62 mstp_setbits(le32, addr, saddr, set)
63#define mstp_clrbits_le32(addr, saddr, clear) \
64 mstp_clrbits(le32, addr, saddr, clear)
65
66int board_early_init_f(void)
67{
68 /* TMU0 */
69 mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090070 /* SCIF0 */
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090071 mstp_clrbits_le32(MSTPSR7, SMSTPCR7, SCIF0_MSTP721);
Nobuhiro Iwamatsu23565c62013-10-20 20:28:24 +090072 /* ETHER */
73 mstp_clrbits_le32(MSTPSR8, SMSTPCR8, ETHER_MSTP813);
74
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090075 return 0;
76}
77
Nobuhiro Iwamatsu16bf36f2013-10-11 15:00:37 +090078void arch_preboot_os(void)
79{
80 /* Disable TMU0 */
81 mstp_setbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
82}
83
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090084DECLARE_GLOBAL_DATA_PTR;
85int board_init(void)
86{
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090087 /* adress of boot parameters */
Nobuhiro Iwamatsueeb266a2014-11-10 13:58:50 +090088 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +090089
90 /* Init PFC controller */
91 r8a7790_pinmux_init();
92
Nobuhiro Iwamatsu23565c62013-10-20 20:28:24 +090093 /* ETHER Enable */
94 gpio_request(GPIO_FN_ETH_CRS_DV, NULL);
95 gpio_request(GPIO_FN_ETH_RX_ER, NULL);
96 gpio_request(GPIO_FN_ETH_RXD0, NULL);
97 gpio_request(GPIO_FN_ETH_RXD1, NULL);
98 gpio_request(GPIO_FN_ETH_LINK, NULL);
99 gpio_request(GPIO_FN_ETH_REF_CLK, NULL);
100 gpio_request(GPIO_FN_ETH_MDIO, NULL);
101 gpio_request(GPIO_FN_ETH_TXD1, NULL);
102 gpio_request(GPIO_FN_ETH_TX_EN, NULL);
103 gpio_request(GPIO_FN_ETH_MAGIC, NULL);
104 gpio_request(GPIO_FN_ETH_TXD0, NULL);
105 gpio_request(GPIO_FN_ETH_MDC, NULL);
106 gpio_request(GPIO_FN_IRQ0, NULL);
107
108 gpio_request(GPIO_GP_5_31, NULL); /* PHY_RST */
109 gpio_direction_output(GPIO_GP_5_31, 0);
110 mdelay(20);
111 gpio_set_value(GPIO_GP_5_31, 1);
112 udelay(1);
113
114 return 0;
115}
116
117#define CXR24 0xEE7003C0 /* MAC address high register */
118#define CXR25 0xEE7003C8 /* MAC address low register */
119int board_eth_init(bd_t *bis)
120{
121 int ret = -ENODEV;
122
123#ifdef CONFIG_SH_ETHER
124 u32 val;
125 unsigned char enetaddr[6];
126
127 ret = sh_eth_initialize(bis);
128 if (!eth_getenv_enetaddr("ethaddr", enetaddr))
129 return ret;
130
131 /* Set Mac address */
132 val = enetaddr[0] << 24 | enetaddr[1] << 16 |
133 enetaddr[2] << 8 | enetaddr[3];
134 writel(val, CXR24);
135
136 val = enetaddr[4] << 8 | enetaddr[5];
137 writel(val, CXR25);
138
139#endif
140
141 return ret;
142}
143
144/* lager has KSZ8041NL/RNL */
145#define PHY_CONTROL1 0x1E
146#define PHY_LED_MODE 0xC0000
147#define PHY_LED_MODE_ACK 0x4000
148int board_phy_config(struct phy_device *phydev)
149{
150 int ret = phy_read(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1);
151 ret &= ~PHY_LED_MODE;
152 ret |= PHY_LED_MODE_ACK;
153 ret = phy_write(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1, (u16)ret);
154
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +0900155 return 0;
156}
157
158int dram_init(void)
159{
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +0900160 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
161
162 return 0;
163}
164
165const struct rmobile_sysinfo sysinfo = {
166 CONFIG_RMOBILE_BOARD_STRING
167};
168
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +0900169void reset_cpu(ulong addr)
170{
Nobuhiro Iwamatsub9986be2013-10-10 09:13:41 +0900171 u8 val;
172
173 i2c_set_bus_num(3); /* PowerIC connected to ch3 */
174 i2c_init(400000, 0);
175 i2c_read(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1);
176 val |= 0x02;
177 i2c_write(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1);
Nobuhiro Iwamatsuf4ec4522013-11-21 17:06:46 +0900178}