blob: c794d43ee4fc587d11cb1eda497ffb3afbdf448d [file] [log] [blame]
Nobuhiro Iwamatsuddbf3032014-06-26 10:23:30 +09001/*
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>
Nobuhiro Iwamatsuade3c942014-12-02 16:52:19 +090018#include <asm/arch/rcar-mstp.h>
Nobuhiro Iwamatsuddbf3032014-06-26 10:23:30 +090019#include <netdev.h>
20#include <miiphy.h>
21#include <i2c.h>
22#include <div64.h>
23#include "qos.h"
24
25DECLARE_GLOBAL_DATA_PTR;
26
27#define CLK2MHZ(clk) (clk / 1000 / 1000)
28void s_init(void)
29{
30 struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE;
31 struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE;
32
33 /* Watchdog init */
34 writel(0xA5A5A500, &rwdt->rwtcsra);
35 writel(0xA5A5A500, &swdt->swtcsra);
36
37 /* QoS */
38 qos_init();
39}
40
Nobuhiro Iwamatsuddbf3032014-06-26 10:23:30 +090041#define TMU0_MSTP125 (1 << 25)
Nobuhiro Iwamatsu45d00452014-10-31 16:30:25 +090042#define SCIF2_MSTP719 (1 << 19)
Nobuhiro Iwamatsuddbf3032014-06-26 10:23:30 +090043#define ETHER_MSTP813 (1 << 13)
Nobuhiro Iwamatsu10e8bde2014-11-10 09:16:43 +090044#define IIC1_MSTP323 (1 << 23)
45
Nobuhiro Iwamatsuddbf3032014-06-26 10:23:30 +090046int board_early_init_f(void)
47{
48 /* TMU */
49 mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
50
Nobuhiro Iwamatsu45d00452014-10-31 16:30:25 +090051 /* SCIF2 */
52 mstp_clrbits_le32(MSTPSR7, SMSTPCR7, SCIF2_MSTP719);
Nobuhiro Iwamatsuddbf3032014-06-26 10:23:30 +090053
54 /* ETHER */
55 mstp_clrbits_le32(MSTPSR8, SMSTPCR8, ETHER_MSTP813);
56
Nobuhiro Iwamatsu10e8bde2014-11-10 09:16:43 +090057 /* IIC1 / sh-i2c ch1 */
58 mstp_clrbits_le32(MSTPSR3, SMSTPCR3, IIC1_MSTP323);
59
Nobuhiro Iwamatsuddbf3032014-06-26 10:23:30 +090060 return 0;
61}
62
Nobuhiro Iwamatsuddbf3032014-06-26 10:23:30 +090063int board_init(void)
64{
65 /* adress of boot parameters */
Nobuhiro Iwamatsu18f0c6c2014-11-10 13:58:50 +090066 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Nobuhiro Iwamatsuddbf3032014-06-26 10:23:30 +090067
68 /* Init PFC controller */
69 r8a7794_pinmux_init();
70
71 /* Ether Enable */
72 gpio_request(GPIO_FN_ETH_CRS_DV, NULL);
73 gpio_request(GPIO_FN_ETH_RX_ER, NULL);
74 gpio_request(GPIO_FN_ETH_RXD0, NULL);
75 gpio_request(GPIO_FN_ETH_RXD1, NULL);
76 gpio_request(GPIO_FN_ETH_LINK, NULL);
77 gpio_request(GPIO_FN_ETH_REFCLK, NULL);
78 gpio_request(GPIO_FN_ETH_MDIO, NULL);
79 gpio_request(GPIO_FN_ETH_TXD1, NULL);
80 gpio_request(GPIO_FN_ETH_TX_EN, NULL);
81 gpio_request(GPIO_FN_ETH_MAGIC, NULL);
82 gpio_request(GPIO_FN_ETH_TXD0, NULL);
83 gpio_request(GPIO_FN_ETH_MDC, NULL);
84 gpio_request(GPIO_FN_IRQ8, NULL);
85
86 /* PHY reset */
87 gpio_request(GPIO_GP_1_24, NULL);
88 gpio_direction_output(GPIO_GP_1_24, 0);
89 mdelay(20);
90 gpio_set_value(GPIO_GP_1_24, 1);
91 udelay(1);
92
93 return 0;
94}
95
96#define CXR24 0xEE7003C0 /* MAC address high register */
97#define CXR25 0xEE7003C8 /* MAC address low register */
98int board_eth_init(bd_t *bis)
99{
100#ifdef CONFIG_SH_ETHER
101 int ret = -ENODEV;
102 u32 val;
103 unsigned char enetaddr[6];
104
105 ret = sh_eth_initialize(bis);
106 if (!eth_getenv_enetaddr("ethaddr", enetaddr))
107 return ret;
108
109 /* Set Mac address */
110 val = enetaddr[0] << 24 | enetaddr[1] << 16 |
111 enetaddr[2] << 8 | enetaddr[3];
112 writel(val, CXR24);
113
114 val = enetaddr[4] << 8 | enetaddr[5];
115 writel(val, CXR25);
116
117 return ret;
118#else
119 return 0;
120#endif
121}
122
123int dram_init(void)
124{
Nobuhiro Iwamatsuddbf3032014-06-26 10:23:30 +0900125 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
126
127 return 0;
128}
129
130const struct rmobile_sysinfo sysinfo = {
131 CONFIG_RMOBILE_BOARD_STRING
132};
133
Nobuhiro Iwamatsuddbf3032014-06-26 10:23:30 +0900134void reset_cpu(ulong addr)
135{
136 u8 val;
137
Nobuhiro Iwamatsu83ee4b52014-11-10 09:16:44 +0900138 i2c_set_bus_num(1); /* PowerIC connected to ch1 */
Nobuhiro Iwamatsuddbf3032014-06-26 10:23:30 +0900139 i2c_read(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1);
140 val |= 0x02;
141 i2c_write(CONFIG_SYS_I2C_POWERIC_ADDR, 0x13, 1, &val, 1);
142}