]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/renesas/gose/gose.c
arm: rmobile: gose: Migrate serial driver to drivers model
[karo-tx-uboot.git] / board / renesas / gose / gose.c
1 /*
2  * board/renesas/gose/gose.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 <dm.h>
12 #include <dm/platform_data/serial_sh.h>
13 #include <asm/processor.h>
14 #include <asm/mach-types.h>
15 #include <asm/io.h>
16 #include <asm/errno.h>
17 #include <asm/arch/sys_proto.h>
18 #include <asm/gpio.h>
19 #include <asm/arch/rmobile.h>
20 #include <asm/arch/rcar-mstp.h>
21 #include <netdev.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         u32 stc;
34
35         /* Watchdog init */
36         writel(0xA5A5A500, &rwdt->rwtcsra);
37         writel(0xA5A5A500, &swdt->swtcsra);
38
39         /* CPU frequency setting. Set to 1.5GHz */
40         stc = ((1500 / CLK2MHZ(CONFIG_SYS_CLK_FREQ)) - 1) << PLL0_STC_BIT;
41         clrsetbits_le32(PLL0CR, PLL0_STC_MASK, stc);
42
43         /* QoS */
44         qos_init();
45 }
46
47 #define TMU0_MSTP125    (1 << 25)
48 #define SCIF0_MSTP721   (1 << 21)
49 #define ETHER_MSTP813   (1 << 13)
50
51 int board_early_init_f(void)
52 {
53         /* TMU0 */
54         mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
55
56         /* SCIF0 */
57         mstp_clrbits_le32(MSTPSR7, SMSTPCR7, SCIF0_MSTP721);
58
59         /* ETHER */
60         mstp_clrbits_le32(MSTPSR8, SMSTPCR8, ETHER_MSTP813);
61
62         return 0;
63 }
64
65 #define PUPR5           0xE6060114
66 #define PUPR5_ETH       0x3FFC0000
67 #define PUPR5_ETH_MAGIC (1 << 27)
68
69 int board_init(void)
70 {
71         /* adress of boot parameters */
72         gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
73
74         /* Init PFC controller */
75         r8a7793_pinmux_init();
76
77         /* ETHER Enable */
78         gpio_request(GPIO_FN_ETH_CRS_DV, NULL);
79         gpio_request(GPIO_FN_ETH_RX_ER, NULL);
80         gpio_request(GPIO_FN_ETH_RXD0, NULL);
81         gpio_request(GPIO_FN_ETH_RXD1, NULL);
82         gpio_request(GPIO_FN_ETH_LINK, NULL);
83         gpio_request(GPIO_FN_ETH_REFCLK, NULL);
84         gpio_request(GPIO_FN_ETH_MDIO, NULL);
85         gpio_request(GPIO_FN_ETH_TXD1, NULL);
86         gpio_request(GPIO_FN_ETH_TX_EN, NULL);
87         gpio_request(GPIO_FN_ETH_TXD0, NULL);
88         gpio_request(GPIO_FN_ETH_MDC, NULL);
89         gpio_request(GPIO_FN_IRQ0, NULL);
90
91         mstp_clrbits_le32(PUPR5, PUPR5, PUPR5_ETH & ~PUPR5_ETH_MAGIC);
92         gpio_request(GPIO_GP_5_22, NULL); /* PHY_RST */
93         mstp_clrbits_le32(PUPR5, PUPR5, PUPR5_ETH_MAGIC);
94
95         gpio_direction_output(GPIO_GP_5_22, 0);
96         mdelay(20);
97         gpio_set_value(GPIO_GP_5_22, 1);
98         udelay(1);
99
100         return 0;
101 }
102
103 #define CXR24 0xEE7003C0 /* MAC address high register */
104 #define CXR25 0xEE7003C8 /* MAC address low register */
105
106 int board_eth_init(bd_t *bis)
107 {
108         int ret = -ENODEV;
109         u32 val;
110         unsigned char enetaddr[6];
111
112 #ifdef CONFIG_SH_ETHER
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 #endif
125
126         return ret;
127 }
128
129 int dram_init(void)
130 {
131         gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
132
133         return 0;
134 }
135
136 const struct rmobile_sysinfo sysinfo = {
137         CONFIG_RMOBILE_BOARD_STRING
138 };
139
140 void reset_cpu(ulong addr)
141 {
142         u8 val;
143
144         i2c_set_bus_num(2); /* PowerIC connected to ch2 */
145         i2c_read(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1);
146         val |= 0x02;
147         i2c_write(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1);
148 }
149
150 static const struct sh_serial_platdata serial_platdata = {
151         .base = SCIF0_BASE,
152         .type = PORT_SCIF,
153         .clk = 14745600,
154         .clk_mode = EXT_CLK,
155 };
156
157 U_BOOT_DEVICE(gose_serials) = {
158         .name = "serial_sh",
159         .platdata = &serial_platdata,
160 };