]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/renesas/lager/lager.c
arm: rmobile: lager: Remove NOR-Flash support
[karo-tx-uboot.git] / board / renesas / lager / lager.c
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>
21 #include <miiphy.h>
22 #include <i2c.h>
23 #include "qos.h"
24
25 DECLARE_GLOBAL_DATA_PTR;
26
27 void s_init(void)
28 {
29         struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE;
30         struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE;
31
32         /* Watchdog init */
33         writel(0xA5A5A500, &rwdt->rwtcsra);
34         writel(0xA5A5A500, &swdt->swtcsra);
35
36         /* QoS(Quality-of-Service) Init */
37         qos_init();
38 }
39
40 #define MSTPSR1 0xE6150038
41 #define SMSTPCR1        0xE6150134
42 #define TMU0_MSTP125    (1 << 25)
43
44 #define MSTPSR7 0xE61501C4
45 #define SMSTPCR7        0xE615014C
46 #define SCIF0_MSTP721   (1 << 21)
47
48 #define MSTPSR8 0xE61509A0
49 #define SMSTPCR8        0xE6150990
50 #define ETHER_MSTP813   (1 << 13)
51
52 #define mstp_setbits(type, addr, saddr, set) \
53         out_##type((saddr), in_##type(addr) | (set))
54 #define mstp_clrbits(type, addr, saddr, clear) \
55         out_##type((saddr), in_##type(addr) & ~(clear))
56 #define mstp_setbits_le32(addr, saddr, set)     \
57                 mstp_setbits(le32, addr, saddr, set)
58 #define mstp_clrbits_le32(addr, saddr, clear)   \
59                 mstp_clrbits(le32, addr, saddr, clear)
60
61 int board_early_init_f(void)
62 {
63         /* TMU0 */
64         mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
65         /* SCIF0 */
66         mstp_clrbits_le32(MSTPSR7, SMSTPCR7, SCIF0_MSTP721);
67         /* ETHER */
68         mstp_clrbits_le32(MSTPSR8, SMSTPCR8, ETHER_MSTP813);
69
70         return 0;
71 }
72
73 void arch_preboot_os(void)
74 {
75         /* Disable TMU0 */
76         mstp_setbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
77 }
78
79 DECLARE_GLOBAL_DATA_PTR;
80 int board_init(void)
81 {
82         /* board id for linux */
83         gd->bd->bi_arch_number = MACH_TYPE_LAGER;
84         /* adress of boot parameters */
85         gd->bd->bi_boot_params = LAGER_SDRAM_BASE + 0x100;
86
87         /* Init PFC controller */
88         r8a7790_pinmux_init();
89
90         /* ETHER Enable */
91         gpio_request(GPIO_FN_ETH_CRS_DV, NULL);
92         gpio_request(GPIO_FN_ETH_RX_ER, NULL);
93         gpio_request(GPIO_FN_ETH_RXD0, NULL);
94         gpio_request(GPIO_FN_ETH_RXD1, NULL);
95         gpio_request(GPIO_FN_ETH_LINK, NULL);
96         gpio_request(GPIO_FN_ETH_REF_CLK, NULL);
97         gpio_request(GPIO_FN_ETH_MDIO, NULL);
98         gpio_request(GPIO_FN_ETH_TXD1, NULL);
99         gpio_request(GPIO_FN_ETH_TX_EN, NULL);
100         gpio_request(GPIO_FN_ETH_MAGIC, NULL);
101         gpio_request(GPIO_FN_ETH_TXD0, NULL);
102         gpio_request(GPIO_FN_ETH_MDC, NULL);
103         gpio_request(GPIO_FN_IRQ0, NULL);
104
105         gpio_request(GPIO_GP_5_31, NULL);       /* PHY_RST */
106         gpio_direction_output(GPIO_GP_5_31, 0);
107         mdelay(20);
108         gpio_set_value(GPIO_GP_5_31, 1);
109         udelay(1);
110
111         return 0;
112 }
113
114 #define CXR24 0xEE7003C0 /* MAC address high register */
115 #define CXR25 0xEE7003C8 /* MAC address low register */
116 int board_eth_init(bd_t *bis)
117 {
118         int ret = -ENODEV;
119
120 #ifdef CONFIG_SH_ETHER
121         u32 val;
122         unsigned char enetaddr[6];
123
124         ret = sh_eth_initialize(bis);
125         if (!eth_getenv_enetaddr("ethaddr", enetaddr))
126                 return ret;
127
128         /* Set Mac address */
129         val = enetaddr[0] << 24 | enetaddr[1] << 16 |
130             enetaddr[2] << 8 | enetaddr[3];
131         writel(val, CXR24);
132
133         val = enetaddr[4] << 8 | enetaddr[5];
134         writel(val, CXR25);
135
136 #endif
137
138         return ret;
139 }
140
141 /* lager has KSZ8041NL/RNL */
142 #define PHY_CONTROL1    0x1E
143 #define PHY_LED_MODE    0xC0000
144 #define PHY_LED_MODE_ACK        0x4000
145 int board_phy_config(struct phy_device *phydev)
146 {
147         int ret = phy_read(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1);
148         ret &= ~PHY_LED_MODE;
149         ret |= PHY_LED_MODE_ACK;
150         ret = phy_write(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1, (u16)ret);
151
152         return 0;
153 }
154
155 int dram_init(void)
156 {
157         gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
158         gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
159
160         return 0;
161 }
162
163 const struct rmobile_sysinfo sysinfo = {
164         CONFIG_RMOBILE_BOARD_STRING
165 };
166
167 void dram_init_banksize(void)
168 {
169         gd->bd->bi_dram[0].start = LAGER_SDRAM_BASE;
170         gd->bd->bi_dram[0].size = LAGER_SDRAM_SIZE;
171 }
172
173 int board_late_init(void)
174 {
175         return 0;
176 }
177
178 void reset_cpu(ulong addr)
179 {
180         u8 val;
181
182         i2c_set_bus_num(3); /* PowerIC connected to ch3 */
183         i2c_init(400000, 0);
184         i2c_read(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1);
185         val |= 0x02;
186         i2c_write(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1);
187 }