xref: /openbmc/u-boot/board/renesas/lager/lager.c (revision da06f9a1850b074904966121b125c000ffc07b2f)
183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0
2f4ec4522SNobuhiro Iwamatsu /*
3f4ec4522SNobuhiro Iwamatsu  * board/renesas/lager/lager.c
4f4ec4522SNobuhiro Iwamatsu  *     This file is lager board support.
5f4ec4522SNobuhiro Iwamatsu  *
6f4ec4522SNobuhiro Iwamatsu  * Copyright (C) 2013 Renesas Electronics Corporation
7f4ec4522SNobuhiro Iwamatsu  * Copyright (C) 2013 Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
8f4ec4522SNobuhiro Iwamatsu  */
9f4ec4522SNobuhiro Iwamatsu 
10f4ec4522SNobuhiro Iwamatsu #include <common.h>
119925f1dbSAlex Kiernan #include <environment.h>
12f4ec4522SNobuhiro Iwamatsu #include <malloc.h>
13f4ec4522SNobuhiro Iwamatsu #include <netdev.h>
14cf839572SNobuhiro Iwamatsu #include <dm.h>
15cf839572SNobuhiro Iwamatsu #include <dm/platform_data/serial_sh.h>
16f4ec4522SNobuhiro Iwamatsu #include <asm/processor.h>
17f4ec4522SNobuhiro Iwamatsu #include <asm/mach-types.h>
18f4ec4522SNobuhiro Iwamatsu #include <asm/io.h>
191221ce45SMasahiro Yamada #include <linux/errno.h>
20f4ec4522SNobuhiro Iwamatsu #include <asm/arch/sys_proto.h>
21f4ec4522SNobuhiro Iwamatsu #include <asm/gpio.h>
22f4ec4522SNobuhiro Iwamatsu #include <asm/arch/rmobile.h>
2344e1eebfSNobuhiro Iwamatsu #include <asm/arch/rcar-mstp.h>
24d7916b1dSNobuhiro Iwamatsu #include <asm/arch/mmc.h>
25acdfecbbSNobuhiro Iwamatsu #include <asm/arch/sh_sdhi.h>
2623565c6bSNobuhiro Iwamatsu #include <miiphy.h>
27b9986be0SNobuhiro Iwamatsu #include <i2c.h>
28d7916b1dSNobuhiro Iwamatsu #include <mmc.h>
29f4ec4522SNobuhiro Iwamatsu #include "qos.h"
30f4ec4522SNobuhiro Iwamatsu 
31f4ec4522SNobuhiro Iwamatsu DECLARE_GLOBAL_DATA_PTR;
32f4ec4522SNobuhiro Iwamatsu 
332c2c6ba6SNobuhiro Iwamatsu #define CLK2MHZ(clk)	(clk / 1000 / 1000)
s_init(void)34f4ec4522SNobuhiro Iwamatsu void s_init(void)
35f4ec4522SNobuhiro Iwamatsu {
36dc535e10SNobuhiro Iwamatsu 	struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE;
37dc535e10SNobuhiro Iwamatsu 	struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE;
38f4ec4522SNobuhiro Iwamatsu 
39f4ec4522SNobuhiro Iwamatsu 	/* Watchdog init */
40f4ec4522SNobuhiro Iwamatsu 	writel(0xA5A5A500, &rwdt->rwtcsra);
41f4ec4522SNobuhiro Iwamatsu 	writel(0xA5A5A500, &swdt->swtcsra);
42f4ec4522SNobuhiro Iwamatsu 
432c2c6ba6SNobuhiro Iwamatsu 	/* CPU frequency setting. Set to 1.4GHz */
44f212a8abSNobuhiro Iwamatsu 	if (rmobile_get_cpu_rev_integer() >= R8A7790_CUT_ES2X) {
45d8659c6dSNobuhiro Iwamatsu 		u32 stat = 0;
46f212a8abSNobuhiro Iwamatsu 		u32 stc = ((1400 / CLK2MHZ(CONFIG_SYS_CLK_FREQ)) - 1)
47f212a8abSNobuhiro Iwamatsu 			<< PLL0_STC_BIT;
482c2c6ba6SNobuhiro Iwamatsu 		clrsetbits_le32(PLL0CR, PLL0_STC_MASK, stc);
49d8659c6dSNobuhiro Iwamatsu 
50d8659c6dSNobuhiro Iwamatsu 		do {
51d8659c6dSNobuhiro Iwamatsu 			stat = readl(PLLECR) & PLL0ST;
52d8659c6dSNobuhiro Iwamatsu 		} while (stat == 0x0);
53f212a8abSNobuhiro Iwamatsu 	}
542c2c6ba6SNobuhiro Iwamatsu 
55f4ec4522SNobuhiro Iwamatsu 	/* QoS(Quality-of-Service) Init */
56f4ec4522SNobuhiro Iwamatsu 	qos_init();
57f4ec4522SNobuhiro Iwamatsu }
58f4ec4522SNobuhiro Iwamatsu 
59e6027e6fSMarek Vasut #define TMU0_MSTP125	BIT(25)
6023565c6bSNobuhiro Iwamatsu 
61e6027e6fSMarek Vasut #define SD1CKCR		0xE6150078
62e6027e6fSMarek Vasut #define SD2CKCR		0xE615026C
63e6027e6fSMarek Vasut #define SD_97500KHZ	0x7
64acdfecbbSNobuhiro Iwamatsu 
board_early_init_f(void)65f4ec4522SNobuhiro Iwamatsu int board_early_init_f(void)
66f4ec4522SNobuhiro Iwamatsu {
67f4ec4522SNobuhiro Iwamatsu 	mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
68acdfecbbSNobuhiro Iwamatsu 
69acdfecbbSNobuhiro Iwamatsu 	/*
70acdfecbbSNobuhiro Iwamatsu 	 * SD0 clock is set to 97.5MHz by default.
71e6027e6fSMarek Vasut 	 * Set SD1 and SD2 to the 97.5MHz as well.
72acdfecbbSNobuhiro Iwamatsu 	 */
73e6027e6fSMarek Vasut 	writel(SD_97500KHZ, SD1CKCR);
74e6027e6fSMarek Vasut 	writel(SD_97500KHZ, SD2CKCR);
7523565c6bSNobuhiro Iwamatsu 
76f4ec4522SNobuhiro Iwamatsu 	return 0;
77f4ec4522SNobuhiro Iwamatsu }
78f4ec4522SNobuhiro Iwamatsu 
79e6027e6fSMarek Vasut #define ETHERNET_PHY_RESET	185	/* GPIO 5 31 */
80e6027e6fSMarek Vasut 
board_init(void)81f4ec4522SNobuhiro Iwamatsu int board_init(void)
82f4ec4522SNobuhiro Iwamatsu {
83f4ec4522SNobuhiro Iwamatsu 	/* adress of boot parameters */
84eeb266abSNobuhiro Iwamatsu 	gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
85f4ec4522SNobuhiro Iwamatsu 
86e6027e6fSMarek Vasut 	/* Force ethernet PHY out of reset */
87e6027e6fSMarek Vasut 	gpio_request(ETHERNET_PHY_RESET, "phy_reset");
88e6027e6fSMarek Vasut 	gpio_direction_output(ETHERNET_PHY_RESET, 0);
89e6027e6fSMarek Vasut 	mdelay(10);
90e6027e6fSMarek Vasut 	gpio_direction_output(ETHERNET_PHY_RESET, 1);
9123565c6bSNobuhiro Iwamatsu 
9223565c6bSNobuhiro Iwamatsu 	return 0;
9323565c6bSNobuhiro Iwamatsu }
9423565c6bSNobuhiro Iwamatsu 
dram_init(void)95e6027e6fSMarek Vasut int dram_init(void)
9623565c6bSNobuhiro Iwamatsu {
9712308b12SSiva Durga Prasad Paladugu 	if (fdtdec_setup_mem_size_base() != 0)
98e6027e6fSMarek Vasut 		return -EINVAL;
9923565c6bSNobuhiro Iwamatsu 
100e6027e6fSMarek Vasut 	return 0;
10123565c6bSNobuhiro Iwamatsu }
10223565c6bSNobuhiro Iwamatsu 
dram_init_banksize(void)103e6027e6fSMarek Vasut int dram_init_banksize(void)
104e6027e6fSMarek Vasut {
105e6027e6fSMarek Vasut 	fdtdec_setup_memory_banksize();
106e6027e6fSMarek Vasut 
107e6027e6fSMarek Vasut 	return 0;
108e6027e6fSMarek Vasut }
109e6027e6fSMarek Vasut 
110e6027e6fSMarek Vasut /* KSZ8041NL/RNL */
11123565c6bSNobuhiro Iwamatsu #define PHY_CONTROL1		0x1E
112*4bbd4642SMarek Vasut #define PHY_LED_MODE		0xC000
11323565c6bSNobuhiro Iwamatsu #define PHY_LED_MODE_ACK	0x4000
board_phy_config(struct phy_device * phydev)11423565c6bSNobuhiro Iwamatsu int board_phy_config(struct phy_device *phydev)
11523565c6bSNobuhiro Iwamatsu {
11623565c6bSNobuhiro Iwamatsu 	int ret = phy_read(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1);
11723565c6bSNobuhiro Iwamatsu 	ret &= ~PHY_LED_MODE;
11823565c6bSNobuhiro Iwamatsu 	ret |= PHY_LED_MODE_ACK;
11923565c6bSNobuhiro Iwamatsu 	ret = phy_write(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1, (u16)ret);
12023565c6bSNobuhiro Iwamatsu 
121f4ec4522SNobuhiro Iwamatsu 	return 0;
122f4ec4522SNobuhiro Iwamatsu }
123f4ec4522SNobuhiro Iwamatsu 
reset_cpu(ulong addr)124f4ec4522SNobuhiro Iwamatsu void reset_cpu(ulong addr)
125f4ec4522SNobuhiro Iwamatsu {
126e6027e6fSMarek Vasut 	struct udevice *dev;
127e6027e6fSMarek Vasut 	const u8 pmic_bus = 2;
128e6027e6fSMarek Vasut 	const u8 pmic_addr = 0x58;
129e6027e6fSMarek Vasut 	u8 data;
130e6027e6fSMarek Vasut 	int ret;
131b9986be0SNobuhiro Iwamatsu 
132e6027e6fSMarek Vasut 	ret = i2c_get_chip_for_busnum(pmic_bus, pmic_addr, 1, &dev);
133e6027e6fSMarek Vasut 	if (ret)
134e6027e6fSMarek Vasut 		hang();
135e6027e6fSMarek Vasut 
136e6027e6fSMarek Vasut 	ret = dm_i2c_read(dev, 0x13, &data, 1);
137e6027e6fSMarek Vasut 	if (ret)
138e6027e6fSMarek Vasut 		hang();
139e6027e6fSMarek Vasut 
140e6027e6fSMarek Vasut 	data |= BIT(1);
141e6027e6fSMarek Vasut 
142e6027e6fSMarek Vasut 	ret = dm_i2c_write(dev, 0x13, &data, 1);
143e6027e6fSMarek Vasut 	if (ret)
144e6027e6fSMarek Vasut 		hang();
145f4ec4522SNobuhiro Iwamatsu }
146cf839572SNobuhiro Iwamatsu 
env_get_location(enum env_operation op,int prio)147e6027e6fSMarek Vasut enum env_location env_get_location(enum env_operation op, int prio)
148e6027e6fSMarek Vasut {
149e6027e6fSMarek Vasut 	const u32 load_magic = 0xb33fc0de;
150cf839572SNobuhiro Iwamatsu 
151e6027e6fSMarek Vasut 	/* Block environment access if loaded using JTAG */
152e6027e6fSMarek Vasut 	if ((readl(CONFIG_SPL_TEXT_BASE + 0x24) == load_magic) &&
153e6027e6fSMarek Vasut 	    (op != ENVOP_INIT))
154e6027e6fSMarek Vasut 		return ENVL_UNKNOWN;
155e6027e6fSMarek Vasut 
156e6027e6fSMarek Vasut 	if (prio)
157e6027e6fSMarek Vasut 		return ENVL_UNKNOWN;
158e6027e6fSMarek Vasut 
159e6027e6fSMarek Vasut 	return ENVL_SPI_FLASH;
160e6027e6fSMarek Vasut }
161