blob: 47cf51bdcd2f2785a8a4c5380d39a2f56f1cd7b4 [file] [log] [blame]
Nobuhiro Iwamatsud74c8cf2013-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 Iwamatsuade3c942014-12-02 16:52:19 +090021#include <asm/arch/rcar-mstp.h>
Nobuhiro Iwamatsu0929b742013-10-20 20:28:24 +090022#include <miiphy.h>
Nobuhiro Iwamatsua99b6b52013-10-10 09:13:41 +090023#include <i2c.h>
Nobuhiro Iwamatsud74c8cf2013-11-21 17:06:46 +090024#include "qos.h"
25
26DECLARE_GLOBAL_DATA_PTR;
27
Nobuhiro Iwamatsu0751cbf2014-03-31 14:14:25 +090028#define CLK2MHZ(clk) (clk / 1000 / 1000)
Nobuhiro Iwamatsud74c8cf2013-11-21 17:06:46 +090029void s_init(void)
30{
Nobuhiro Iwamatsufa3e41b2014-03-27 16:18:19 +090031 struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE;
32 struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE;
Nobuhiro Iwamatsud74c8cf2013-11-21 17:06:46 +090033
34 /* Watchdog init */
35 writel(0xA5A5A500, &rwdt->rwtcsra);
36 writel(0xA5A5A500, &swdt->swtcsra);
37
Nobuhiro Iwamatsu0751cbf2014-03-31 14:14:25 +090038 /* CPU frequency setting. Set to 1.4GHz */
Nobuhiro Iwamatsu70ad4f62014-07-30 12:28:00 +090039 if (rmobile_get_cpu_rev_integer() >= R8A7790_CUT_ES2X) {
Nobuhiro Iwamatsu67fd59b2014-10-31 16:08:11 +090040 u32 stat = 0;
Nobuhiro Iwamatsu70ad4f62014-07-30 12:28:00 +090041 u32 stc = ((1400 / CLK2MHZ(CONFIG_SYS_CLK_FREQ)) - 1)
42 << PLL0_STC_BIT;
43 clrsetbits_le32(PLL0CR, PLL0_STC_MASK, stc);
Nobuhiro Iwamatsu67fd59b2014-10-31 16:08:11 +090044
45 do {
46 stat = readl(PLLECR) & PLL0ST;
47 } while (stat == 0x0);
Nobuhiro Iwamatsu70ad4f62014-07-30 12:28:00 +090048 }
Nobuhiro Iwamatsu0751cbf2014-03-31 14:14:25 +090049
Nobuhiro Iwamatsud74c8cf2013-11-21 17:06:46 +090050 /* QoS(Quality-of-Service) Init */
51 qos_init();
Nobuhiro Iwamatsud74c8cf2013-11-21 17:06:46 +090052}
53
Nobuhiro Iwamatsud74c8cf2013-11-21 17:06:46 +090054#define TMU0_MSTP125 (1 << 25)
Nobuhiro Iwamatsud74c8cf2013-11-21 17:06:46 +090055#define SCIF0_MSTP721 (1 << 21)
Nobuhiro Iwamatsu0929b742013-10-20 20:28:24 +090056#define ETHER_MSTP813 (1 << 13)
57
Nobuhiro Iwamatsud74c8cf2013-11-21 17:06:46 +090058int board_early_init_f(void)
59{
60 /* TMU0 */
61 mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
Nobuhiro Iwamatsud74c8cf2013-11-21 17:06:46 +090062 /* SCIF0 */
Nobuhiro Iwamatsud74c8cf2013-11-21 17:06:46 +090063 mstp_clrbits_le32(MSTPSR7, SMSTPCR7, SCIF0_MSTP721);
Nobuhiro Iwamatsu0929b742013-10-20 20:28:24 +090064 /* ETHER */
65 mstp_clrbits_le32(MSTPSR8, SMSTPCR8, ETHER_MSTP813);
66
Nobuhiro Iwamatsud74c8cf2013-11-21 17:06:46 +090067 return 0;
68}
69
Nobuhiro Iwamatsue5e91de2013-10-11 15:00:37 +090070void arch_preboot_os(void)
71{
72 /* Disable TMU0 */
73 mstp_setbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
74}
75
Nobuhiro Iwamatsud74c8cf2013-11-21 17:06:46 +090076DECLARE_GLOBAL_DATA_PTR;
77int board_init(void)
78{
Nobuhiro Iwamatsud74c8cf2013-11-21 17:06:46 +090079 /* adress of boot parameters */
Nobuhiro Iwamatsu9c87f992014-11-10 13:58:50 +090080 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Nobuhiro Iwamatsud74c8cf2013-11-21 17:06:46 +090081
82 /* Init PFC controller */
83 r8a7790_pinmux_init();
84
Nobuhiro Iwamatsu0929b742013-10-20 20:28:24 +090085 /* 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 */
111int 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
140int 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 Iwamatsud74c8cf2013-11-21 17:06:46 +0900147 return 0;
148}
149
150int dram_init(void)
151{
Nobuhiro Iwamatsud74c8cf2013-11-21 17:06:46 +0900152 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
153
154 return 0;
155}
156
157const struct rmobile_sysinfo sysinfo = {
158 CONFIG_RMOBILE_BOARD_STRING
159};
160
Nobuhiro Iwamatsud74c8cf2013-11-21 17:06:46 +0900161void reset_cpu(ulong addr)
162{
Nobuhiro Iwamatsua99b6b52013-10-10 09:13:41 +0900163 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 Iwamatsud74c8cf2013-11-21 17:06:46 +0900170}