koelsch.c 3.0 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0
2 3 4 5 6 7 8 9
/*
 * board/renesas/koelsch/koelsch.c
 *
 * Copyright (C) 2013 Renesas Electronics Corporation
 *
 */

#include <common.h>
10
#include <cpu_func.h>
S
Simon Glass 已提交
11
#include <env.h>
12
#include <malloc.h>
13 14
#include <dm.h>
#include <dm/platform_data/serial_sh.h>
15
#include <env_internal.h>
16 17 18
#include <asm/processor.h>
#include <asm/mach-types.h>
#include <asm/io.h>
19
#include <linux/errno.h>
20 21 22
#include <asm/arch/sys_proto.h>
#include <asm/gpio.h>
#include <asm/arch/rmobile.h>
23
#include <asm/arch/rcar-mstp.h>
24
#include <asm/arch/sh_sdhi.h>
25 26
#include <netdev.h>
#include <miiphy.h>
27
#include <i2c.h>
28
#include <div64.h>
29 30 31 32
#include "qos.h"

DECLARE_GLOBAL_DATA_PTR;

33
#define CLK2MHZ(clk)	(clk / 1000 / 1000)
34 35
void s_init(void)
{
36 37
	struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE;
	struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE;
38
	u32 stc;
39 40 41 42 43

	/* Watchdog init */
	writel(0xA5A5A500, &rwdt->rwtcsra);
	writel(0xA5A5A500, &swdt->swtcsra);

44 45 46 47
	/* CPU frequency setting. Set to 1.5GHz */
	stc = ((1500 / CLK2MHZ(CONFIG_SYS_CLK_FREQ)) - 1) << PLL0_STC_BIT;
	clrsetbits_le32(PLL0CR, PLL0_STC_MASK, stc);

48 49 50 51
	/* QoS */
	qos_init();
}

M
Marek Vasut 已提交
52
#define TMU0_MSTP125	BIT(25)
53 54 55 56 57

#define SD1CKCR		0xE6150078
#define SD2CKCR		0xE615026C
#define SD_97500KHZ	0x7

58 59 60 61
int board_early_init_f(void)
{
	mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);

62 63 64 65 66 67 68
	/*
	 * SD0 clock is set to 97.5MHz by default.
	 * Set SD1 and SD2 to the 97.5MHz as well.
	 */
	writel(SD_97500KHZ, SD1CKCR);
	writel(SD_97500KHZ, SD2CKCR);

69 70 71
	return 0;
}

M
Marek Vasut 已提交
72 73
#define ETHERNET_PHY_RESET	176	/* GPIO 5 22 */

74 75 76
int board_init(void)
{
	/* adress of boot parameters */
77
	gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
78

M
Marek Vasut 已提交
79 80 81 82 83
	/* Force ethernet PHY out of reset */
	gpio_request(ETHERNET_PHY_RESET, "phy_reset");
	gpio_direction_output(ETHERNET_PHY_RESET, 0);
	mdelay(10);
	gpio_direction_output(ETHERNET_PHY_RESET, 1);
84 85 86 87

	return 0;
}

M
Marek Vasut 已提交
88
int dram_init(void)
89
{
90
	if (fdtdec_setup_mem_size_base() != 0)
M
Marek Vasut 已提交
91
		return -EINVAL;
92

93 94 95
	return 0;
}

M
Marek Vasut 已提交
96
int dram_init_banksize(void)
97
{
M
Marek Vasut 已提交
98
	fdtdec_setup_memory_banksize();
99 100 101 102

	return 0;
}

M
Marek Vasut 已提交
103 104
/* Koelsch has KSZ8041NL/RNL */
#define PHY_CONTROL1		0x1E
105
#define PHY_LED_MODE		0xC000
106 107 108 109 110 111 112 113 114 115 116
#define PHY_LED_MODE_ACK	0x4000
int board_phy_config(struct phy_device *phydev)
{
	int ret = phy_read(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1);
	ret &= ~PHY_LED_MODE;
	ret |= PHY_LED_MODE_ACK;
	ret = phy_write(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1, (u16)ret);

	return 0;
}

117 118
void reset_cpu(ulong addr)
{
M
Marek Vasut 已提交
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
	struct udevice *dev;
	const u8 pmic_bus = 6;
	const u8 pmic_addr = 0x58;
	u8 data;
	int ret;

	ret = i2c_get_chip_for_busnum(pmic_bus, pmic_addr, 1, &dev);
	if (ret)
		hang();

	ret = dm_i2c_read(dev, 0x13, &data, 1);
	if (ret)
		hang();

	data |= BIT(1);
134

M
Marek Vasut 已提交
135 136 137
	ret = dm_i2c_write(dev, 0x13, &data, 1);
	if (ret)
		hang();
138
}
139

M
Marek Vasut 已提交
140 141 142
enum env_location env_get_location(enum env_operation op, int prio)
{
	const u32 load_magic = 0xb33fc0de;
143

M
Marek Vasut 已提交
144 145 146 147 148 149 150 151 152 153
	/* Block environment access if loaded using JTAG */
	if ((readl(CONFIG_SPL_TEXT_BASE + 0x24) == load_magic) &&
	    (op != ENVOP_INIT))
		return ENVL_UNKNOWN;

	if (prio)
		return ENVL_UNKNOWN;

	return ENVL_SPI_FLASH;
}