]> git.sur5r.net Git - u-boot/blob - board/renesas/koelsch/koelsch.c
arm: rmobile: koelsch: Migrate serial driver to drivers model
[u-boot] / board / renesas / koelsch / koelsch.c
1 /*
2  * board/renesas/koelsch/koelsch.c
3  *
4  * Copyright (C) 2013 Renesas Electronics Corporation
5  *
6  * SPDX-License-Identifier: GPL-2.0
7  *
8  */
9
10 #include <common.h>
11 #include <malloc.h>
12 #include <dm.h>
13 #include <dm/platform_data/serial_sh.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 <netdev.h>
23 #include <miiphy.h>
24 #include <i2c.h>
25 #include <div64.h>
26 #include "qos.h"
27
28 DECLARE_GLOBAL_DATA_PTR;
29
30 #define CLK2MHZ(clk)    (clk / 1000 / 1000)
31 void s_init(void)
32 {
33         struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE;
34         struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE;
35         u32 stc;
36
37         /* Watchdog init */
38         writel(0xA5A5A500, &rwdt->rwtcsra);
39         writel(0xA5A5A500, &swdt->swtcsra);
40
41         /* CPU frequency setting. Set to 1.5GHz */
42         stc = ((1500 / CLK2MHZ(CONFIG_SYS_CLK_FREQ)) - 1) << PLL0_STC_BIT;
43         clrsetbits_le32(PLL0CR, PLL0_STC_MASK, stc);
44
45         /* QoS */
46         qos_init();
47 }
48
49 #define TMU0_MSTP125    (1 << 25)
50 #define SCIF0_MSTP721   (1 << 21)
51 #define ETHER_MSTP813   (1 << 13)
52
53 int board_early_init_f(void)
54 {
55         mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
56
57         /* SCIF0 */
58         mstp_clrbits_le32(MSTPSR7, SMSTPCR7, SCIF0_MSTP721);
59
60         /* ETHER */
61         mstp_clrbits_le32(MSTPSR8, SMSTPCR8, ETHER_MSTP813);
62
63         return 0;
64 }
65
66 /* LSI pin pull-up control */
67 #define PUPR5 0xe6060114
68 #define PUPR5_ETH 0x3FFC0000
69 #define PUPR5_ETH_MAGIC (1 << 27)
70 int board_init(void)
71 {
72         /* adress of boot parameters */
73         gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
74
75         /* Init PFC controller */
76         r8a7791_pinmux_init();
77
78         /* ETHER Enable */
79         gpio_request(GPIO_FN_ETH_CRS_DV, NULL);
80         gpio_request(GPIO_FN_ETH_RX_ER, NULL);
81         gpio_request(GPIO_FN_ETH_RXD0, NULL);
82         gpio_request(GPIO_FN_ETH_RXD1, NULL);
83         gpio_request(GPIO_FN_ETH_LINK, NULL);
84         gpio_request(GPIO_FN_ETH_REFCLK, NULL);
85         gpio_request(GPIO_FN_ETH_MDIO, NULL);
86         gpio_request(GPIO_FN_ETH_TXD1, NULL);
87         gpio_request(GPIO_FN_ETH_TX_EN, NULL);
88         gpio_request(GPIO_FN_ETH_TXD0, NULL);
89         gpio_request(GPIO_FN_ETH_MDC, NULL);
90         gpio_request(GPIO_FN_IRQ0, NULL);
91
92         mstp_clrbits_le32(PUPR5, PUPR5, PUPR5_ETH & ~PUPR5_ETH_MAGIC);
93         gpio_request(GPIO_GP_5_22, NULL); /* PHY_RST */
94         mstp_clrbits_le32(PUPR5, PUPR5, PUPR5_ETH_MAGIC);
95
96         gpio_direction_output(GPIO_GP_5_22, 0);
97         mdelay(20);
98         gpio_set_value(GPIO_GP_5_22, 1);
99         udelay(1);
100
101         return 0;
102 }
103
104 #define CXR24 0xEE7003C0 /* MAC address high register */
105 #define CXR25 0xEE7003C8 /* MAC address low register */
106 int board_eth_init(bd_t *bis)
107 {
108 #ifdef CONFIG_SH_ETHER
109         int ret = -ENODEV;
110         u32 val;
111         unsigned char enetaddr[6];
112
113         ret = sh_eth_initialize(bis);
114         if (!eth_getenv_enetaddr("ethaddr", enetaddr))
115                 return ret;
116
117         /* Set Mac address */
118         val = enetaddr[0] << 24 | enetaddr[1] << 16 |
119                 enetaddr[2] << 8 | enetaddr[3];
120         writel(val, CXR24);
121
122         val = enetaddr[4] << 8 | enetaddr[5];
123         writel(val, CXR25);
124
125         return ret;
126 #else
127         return 0;
128 #endif
129 }
130
131 int dram_init(void)
132 {
133         gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
134
135         return 0;
136 }
137
138 /* koelsch has KSZ8041NL/RNL */
139 #define PHY_CONTROL1    0x1E
140 #define PHY_LED_MODE    0xC0000
141 #define PHY_LED_MODE_ACK        0x4000
142 int board_phy_config(struct phy_device *phydev)
143 {
144         int ret = phy_read(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1);
145         ret &= ~PHY_LED_MODE;
146         ret |= PHY_LED_MODE_ACK;
147         ret = phy_write(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1, (u16)ret);
148
149         return 0;
150 }
151
152 const struct rmobile_sysinfo sysinfo = {
153         CONFIG_RMOBILE_BOARD_STRING
154 };
155
156 void reset_cpu(ulong addr)
157 {
158         u8 val;
159
160         i2c_set_bus_num(2); /* PowerIC connected to ch2 */
161         i2c_read(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1);
162         val |= 0x02;
163         i2c_write(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1);
164 }
165
166 static const struct sh_serial_platdata serial_platdata = {
167         .base = SCIF0_BASE,
168         .type = PORT_SCIF,
169         .clk = 14745600,
170         .clk_mode = EXT_CLK,
171 };
172
173 U_BOOT_DEVICE(koelsch_serials) = {
174         .name = "serial_sh",
175         .platdata = &serial_platdata,
176 };