xref: /openbmc/u-boot/board/renesas/alt/alt.c (revision da06f9a1850b074904966121b125c000ffc07b2f)
183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0
2cff2f5f0SNobuhiro Iwamatsu /*
3cff2f5f0SNobuhiro Iwamatsu  * board/renesas/alt/alt.c
4cff2f5f0SNobuhiro Iwamatsu  *
5cae72042SMitsuhiro Kimura  * Copyright (C) 2014, 2015 Renesas Electronics Corporation
6cff2f5f0SNobuhiro Iwamatsu  */
7cff2f5f0SNobuhiro Iwamatsu 
8cff2f5f0SNobuhiro Iwamatsu #include <common.h>
9cff2f5f0SNobuhiro Iwamatsu #include <malloc.h>
109e116f64SNobuhiro Iwamatsu #include <dm.h>
119e116f64SNobuhiro Iwamatsu #include <dm/platform_data/serial_sh.h>
129925f1dbSAlex Kiernan #include <environment.h>
13cff2f5f0SNobuhiro Iwamatsu #include <asm/processor.h>
14cff2f5f0SNobuhiro Iwamatsu #include <asm/mach-types.h>
15cff2f5f0SNobuhiro Iwamatsu #include <asm/io.h>
161221ce45SMasahiro Yamada #include <linux/errno.h>
17cff2f5f0SNobuhiro Iwamatsu #include <asm/arch/sys_proto.h>
18cff2f5f0SNobuhiro Iwamatsu #include <asm/gpio.h>
19cff2f5f0SNobuhiro Iwamatsu #include <asm/arch/rmobile.h>
2044e1eebfSNobuhiro Iwamatsu #include <asm/arch/rcar-mstp.h>
212b8c0814SNobuhiro Iwamatsu #include <asm/arch/mmc.h>
2225f9613fSNobuhiro Iwamatsu #include <asm/arch/sh_sdhi.h>
23cff2f5f0SNobuhiro Iwamatsu #include <netdev.h>
24cff2f5f0SNobuhiro Iwamatsu #include <miiphy.h>
25cff2f5f0SNobuhiro Iwamatsu #include <i2c.h>
26cff2f5f0SNobuhiro Iwamatsu #include <div64.h>
27cff2f5f0SNobuhiro Iwamatsu #include "qos.h"
28cff2f5f0SNobuhiro Iwamatsu 
29cff2f5f0SNobuhiro Iwamatsu DECLARE_GLOBAL_DATA_PTR;
30cff2f5f0SNobuhiro Iwamatsu 
s_init(void)31cff2f5f0SNobuhiro Iwamatsu void s_init(void)
32cff2f5f0SNobuhiro Iwamatsu {
33cff2f5f0SNobuhiro Iwamatsu 	struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE;
34cff2f5f0SNobuhiro Iwamatsu 	struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE;
35cff2f5f0SNobuhiro Iwamatsu 
36cff2f5f0SNobuhiro Iwamatsu 	/* Watchdog init */
37cff2f5f0SNobuhiro Iwamatsu 	writel(0xA5A5A500, &rwdt->rwtcsra);
38cff2f5f0SNobuhiro Iwamatsu 	writel(0xA5A5A500, &swdt->swtcsra);
39cff2f5f0SNobuhiro Iwamatsu 
40cff2f5f0SNobuhiro Iwamatsu 	/* QoS */
41cff2f5f0SNobuhiro Iwamatsu 	qos_init();
42cff2f5f0SNobuhiro Iwamatsu }
43cff2f5f0SNobuhiro Iwamatsu 
44bb6d2ff2SMarek Vasut #define TMU0_MSTP125	BIT(25)
45bb6d2ff2SMarek Vasut #define MMC0_MSTP315	BIT(15)
4625f9613fSNobuhiro Iwamatsu 
4725f9613fSNobuhiro Iwamatsu #define SD1CKCR		0xE6150078
48bb6d2ff2SMarek Vasut #define SD_97500KHZ	0x7
4992ef38eeSNobuhiro Iwamatsu 
board_early_init_f(void)50cff2f5f0SNobuhiro Iwamatsu int board_early_init_f(void)
51cff2f5f0SNobuhiro Iwamatsu {
52cff2f5f0SNobuhiro Iwamatsu 	/* TMU */
53cff2f5f0SNobuhiro Iwamatsu 	mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
54cff2f5f0SNobuhiro Iwamatsu 
55bb6d2ff2SMarek Vasut 	/* Set SD1 to the 97.5MHz */
56bb6d2ff2SMarek Vasut 	writel(SD_97500KHZ, SD1CKCR);
57cff2f5f0SNobuhiro Iwamatsu 
58cff2f5f0SNobuhiro Iwamatsu 	return 0;
59cff2f5f0SNobuhiro Iwamatsu }
60cff2f5f0SNobuhiro Iwamatsu 
61bb6d2ff2SMarek Vasut #define ETHERNET_PHY_RESET	56	/* GPIO 1 24 */
62bb6d2ff2SMarek Vasut 
board_init(void)63cff2f5f0SNobuhiro Iwamatsu int board_init(void)
64cff2f5f0SNobuhiro Iwamatsu {
65cff2f5f0SNobuhiro Iwamatsu 	/* adress of boot parameters */
664772684cSNobuhiro Iwamatsu 	gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
67cff2f5f0SNobuhiro Iwamatsu 
68bb6d2ff2SMarek Vasut 	/* Force ethernet PHY out of reset */
69bb6d2ff2SMarek Vasut 	gpio_request(ETHERNET_PHY_RESET, "phy_reset");
70bb6d2ff2SMarek Vasut 	gpio_direction_output(ETHERNET_PHY_RESET, 0);
71cff2f5f0SNobuhiro Iwamatsu 	mdelay(20);
72bb6d2ff2SMarek Vasut 	gpio_direction_output(ETHERNET_PHY_RESET, 1);
73cff2f5f0SNobuhiro Iwamatsu 	udelay(1);
74cff2f5f0SNobuhiro Iwamatsu 
75cff2f5f0SNobuhiro Iwamatsu 	return 0;
76cff2f5f0SNobuhiro Iwamatsu }
77cff2f5f0SNobuhiro Iwamatsu 
dram_init(void)78cff2f5f0SNobuhiro Iwamatsu int dram_init(void)
79cff2f5f0SNobuhiro Iwamatsu {
8012308b12SSiva Durga Prasad Paladugu 	if (fdtdec_setup_mem_size_base() != 0)
81bb6d2ff2SMarek Vasut 		return -EINVAL;
82bb6d2ff2SMarek Vasut 
83bb6d2ff2SMarek Vasut 	return 0;
84bb6d2ff2SMarek Vasut }
85bb6d2ff2SMarek Vasut 
dram_init_banksize(void)86bb6d2ff2SMarek Vasut int dram_init_banksize(void)
87bb6d2ff2SMarek Vasut {
88bb6d2ff2SMarek Vasut 	fdtdec_setup_memory_banksize();
89bb6d2ff2SMarek Vasut 
90bb6d2ff2SMarek Vasut 	return 0;
91bb6d2ff2SMarek Vasut }
92bb6d2ff2SMarek Vasut 
93bb6d2ff2SMarek Vasut /* KSZ8041RNLI */
94bb6d2ff2SMarek Vasut #define PHY_CONTROL1		0x1E
954bbd4642SMarek Vasut #define PHY_LED_MODE		0xC000
96bb6d2ff2SMarek Vasut #define PHY_LED_MODE_ACK	0x4000
board_phy_config(struct phy_device * phydev)97bb6d2ff2SMarek Vasut int board_phy_config(struct phy_device *phydev)
98bb6d2ff2SMarek Vasut {
99bb6d2ff2SMarek Vasut 	int ret = phy_read(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1);
100bb6d2ff2SMarek Vasut 	ret &= ~PHY_LED_MODE;
101bb6d2ff2SMarek Vasut 	ret |= PHY_LED_MODE_ACK;
102bb6d2ff2SMarek Vasut 	ret = phy_write(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1, (u16)ret);
103cff2f5f0SNobuhiro Iwamatsu 
104cff2f5f0SNobuhiro Iwamatsu 	return 0;
105cff2f5f0SNobuhiro Iwamatsu }
106cff2f5f0SNobuhiro Iwamatsu 
reset_cpu(ulong addr)107cff2f5f0SNobuhiro Iwamatsu void reset_cpu(ulong addr)
108cff2f5f0SNobuhiro Iwamatsu {
109bb6d2ff2SMarek Vasut 	struct udevice *dev;
110*0c78ec64SMarek Vasut 	const u8 pmic_bus = 7;
111bb6d2ff2SMarek Vasut 	const u8 pmic_addr = 0x58;
112bb6d2ff2SMarek Vasut 	u8 data;
113bb6d2ff2SMarek Vasut 	int ret;
114cff2f5f0SNobuhiro Iwamatsu 
115bb6d2ff2SMarek Vasut 	ret = i2c_get_chip_for_busnum(pmic_bus, pmic_addr, 1, &dev);
116bb6d2ff2SMarek Vasut 	if (ret)
117bb6d2ff2SMarek Vasut 		hang();
118bb6d2ff2SMarek Vasut 
119bb6d2ff2SMarek Vasut 	ret = dm_i2c_read(dev, 0x13, &data, 1);
120bb6d2ff2SMarek Vasut 	if (ret)
121bb6d2ff2SMarek Vasut 		hang();
122bb6d2ff2SMarek Vasut 
123bb6d2ff2SMarek Vasut 	data |= BIT(1);
124bb6d2ff2SMarek Vasut 
125bb6d2ff2SMarek Vasut 	ret = dm_i2c_write(dev, 0x13, &data, 1);
126bb6d2ff2SMarek Vasut 	if (ret)
127bb6d2ff2SMarek Vasut 		hang();
128cff2f5f0SNobuhiro Iwamatsu }
1299e116f64SNobuhiro Iwamatsu 
env_get_location(enum env_operation op,int prio)130bb6d2ff2SMarek Vasut enum env_location env_get_location(enum env_operation op, int prio)
131bb6d2ff2SMarek Vasut {
132bb6d2ff2SMarek Vasut 	const u32 load_magic = 0xb33fc0de;
1339e116f64SNobuhiro Iwamatsu 
134bb6d2ff2SMarek Vasut 	/* Block environment access if loaded using JTAG */
135bb6d2ff2SMarek Vasut 	if ((readl(CONFIG_SPL_TEXT_BASE + 0x24) == load_magic) &&
136bb6d2ff2SMarek Vasut 	    (op != ENVOP_INIT))
137bb6d2ff2SMarek Vasut 		return ENVL_UNKNOWN;
138bb6d2ff2SMarek Vasut 
139bb6d2ff2SMarek Vasut 	if (prio)
140bb6d2ff2SMarek Vasut 		return ENVL_UNKNOWN;
141bb6d2ff2SMarek Vasut 
142bb6d2ff2SMarek Vasut 	return ENVL_SPI_FLASH;
143bb6d2ff2SMarek Vasut }
144