arm: rmobile: rcar: Move module control register to header file of SoC
[platform/kernel/u-boot.git] / board / renesas / alt / alt.c
1 /*
2  * board/renesas/alt/alt.c
3  *
4  * Copyright (C) 2014 Renesas Electronics Corporation
5  *
6  * SPDX-License-Identifier: GPL-2.0
7  */
8
9 #include <common.h>
10 #include <malloc.h>
11 #include <asm/processor.h>
12 #include <asm/mach-types.h>
13 #include <asm/io.h>
14 #include <asm/errno.h>
15 #include <asm/arch/sys_proto.h>
16 #include <asm/gpio.h>
17 #include <asm/arch/rmobile.h>
18 #include <netdev.h>
19 #include <miiphy.h>
20 #include <i2c.h>
21 #include <div64.h>
22 #include "qos.h"
23
24 DECLARE_GLOBAL_DATA_PTR;
25
26 #define CLK2MHZ(clk)    (clk / 1000 / 1000)
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 */
37         qos_init();
38 }
39
40 #define TMU0_MSTP125    (1 << 25)
41 #define SCIF2_MSTP719   (1 << 19)
42 #define ETHER_MSTP813   (1 << 13)
43 #define IIC1_MSTP323    (1 << 23)
44
45 #define mstp_setbits(type, addr, saddr, set) \
46         out_##type((saddr), in_##type(addr) | (set))
47 #define mstp_clrbits(type, addr, saddr, clear) \
48         out_##type((saddr), in_##type(addr) & ~(clear))
49 #define mstp_setbits_le32(addr, saddr, set) \
50         mstp_setbits(le32, addr, saddr, set)
51 #define mstp_clrbits_le32(addr, saddr, clear)   \
52         mstp_clrbits(le32, addr, saddr, clear)
53
54 int board_early_init_f(void)
55 {
56         /* TMU */
57         mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
58
59         /* SCIF2 */
60         mstp_clrbits_le32(MSTPSR7, SMSTPCR7, SCIF2_MSTP719);
61
62         /* ETHER */
63         mstp_clrbits_le32(MSTPSR8, SMSTPCR8, ETHER_MSTP813);
64
65         /* IIC1 / sh-i2c ch1 */
66         mstp_clrbits_le32(MSTPSR3, SMSTPCR3, IIC1_MSTP323);
67
68         return 0;
69 }
70
71 void arch_preboot_os(void)
72 {
73         /* Disable TMU0 */
74         mstp_setbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
75 }
76
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         r8a7794_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_REFCLK, 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_IRQ8, NULL);
99
100         /* PHY reset */
101         gpio_request(GPIO_GP_1_24, NULL);
102         gpio_direction_output(GPIO_GP_1_24, 0);
103         mdelay(20);
104         gpio_set_value(GPIO_GP_1_24, 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 */
112 int board_eth_init(bd_t *bis)
113 {
114 #ifdef CONFIG_SH_ETHER
115         int ret = -ENODEV;
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         return ret;
132 #else
133         return 0;
134 #endif
135 }
136
137 int dram_init(void)
138 {
139         gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
140
141         return 0;
142 }
143
144 const struct rmobile_sysinfo sysinfo = {
145         CONFIG_RMOBILE_BOARD_STRING
146 };
147
148 void reset_cpu(ulong addr)
149 {
150         u8 val;
151
152         i2c_set_bus_num(1); /* PowerIC connected to ch1 */
153         i2c_read(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1);
154         val |= 0x02;
155         i2c_write(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1);
156 }