arm: rmobile: rcar: Move control macro of mstp to arch-rmobile/rcar-mstp.h
[platform/kernel/u-boot.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 <asm/arch/rcar-mstp.h>
22 #include <miiphy.h>
23 #include <i2c.h>
24 #include "qos.h"
25
26 DECLARE_GLOBAL_DATA_PTR;
27
28 #define CLK2MHZ(clk)    (clk / 1000 / 1000)
29 void s_init(void)
30 {
31         struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE;
32         struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE;
33
34         /* Watchdog init */
35         writel(0xA5A5A500, &rwdt->rwtcsra);
36         writel(0xA5A5A500, &swdt->swtcsra);
37
38         /* CPU frequency setting. Set to 1.4GHz */
39         if (rmobile_get_cpu_rev_integer() >= R8A7790_CUT_ES2X) {
40                 u32 stat = 0;
41                 u32 stc = ((1400 / CLK2MHZ(CONFIG_SYS_CLK_FREQ)) - 1)
42                         << PLL0_STC_BIT;
43                 clrsetbits_le32(PLL0CR, PLL0_STC_MASK, stc);
44
45                 do {
46                         stat = readl(PLLECR) & PLL0ST;
47                 } while (stat == 0x0);
48         }
49
50         /* QoS(Quality-of-Service) Init */
51         qos_init();
52 }
53
54 #define TMU0_MSTP125    (1 << 25)
55 #define SCIF0_MSTP721   (1 << 21)
56 #define ETHER_MSTP813   (1 << 13)
57
58 int board_early_init_f(void)
59 {
60         /* TMU0 */
61         mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
62         /* SCIF0 */
63         mstp_clrbits_le32(MSTPSR7, SMSTPCR7, SCIF0_MSTP721);
64         /* ETHER */
65         mstp_clrbits_le32(MSTPSR8, SMSTPCR8, ETHER_MSTP813);
66
67         return 0;
68 }
69
70 void arch_preboot_os(void)
71 {
72         /* Disable TMU0 */
73         mstp_setbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
74 }
75
76 DECLARE_GLOBAL_DATA_PTR;
77 int board_init(void)
78 {
79         /* adress of boot parameters */
80         gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
81
82         /* Init PFC controller */
83         r8a7790_pinmux_init();
84
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
147         return 0;
148 }
149
150 int dram_init(void)
151 {
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
161 void reset_cpu(ulong addr)
162 {
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);
170 }