Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Nobuhiro Iwamatsu | 7fbb92b | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 2 | /* |
| 3 | * board/renesas/koelsch/koelsch.c |
| 4 | * |
| 5 | * Copyright (C) 2013 Renesas Electronics Corporation |
| 6 | * |
Nobuhiro Iwamatsu | 7fbb92b | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Tom Rini | 8c70baa | 2021-12-14 13:36:40 -0500 | [diff] [blame] | 10 | #include <clock_legacy.h> |
Simon Glass | afb0215 | 2019-12-28 10:45:01 -0700 | [diff] [blame] | 11 | #include <cpu_func.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 12 | #include <env.h> |
Simon Glass | f11478f | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 13 | #include <hang.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 14 | #include <init.h> |
Nobuhiro Iwamatsu | 7fbb92b | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 15 | #include <malloc.h> |
Nobuhiro Iwamatsu | 6288fb4 | 2014-12-09 11:24:01 +0900 | [diff] [blame] | 16 | #include <dm.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 17 | #include <asm/global_data.h> |
Nobuhiro Iwamatsu | 6288fb4 | 2014-12-09 11:24:01 +0900 | [diff] [blame] | 18 | #include <dm/platform_data/serial_sh.h> |
Simon Glass | 9d1f619 | 2019-08-02 09:44:25 -0600 | [diff] [blame] | 19 | #include <env_internal.h> |
Nobuhiro Iwamatsu | 7fbb92b | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 20 | #include <asm/processor.h> |
| 21 | #include <asm/mach-types.h> |
| 22 | #include <asm/io.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 23 | #include <linux/bitops.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 24 | #include <linux/delay.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 25 | #include <linux/errno.h> |
Nobuhiro Iwamatsu | 7fbb92b | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 26 | #include <asm/arch/sys_proto.h> |
| 27 | #include <asm/gpio.h> |
| 28 | #include <asm/arch/rmobile.h> |
Nobuhiro Iwamatsu | ade3c94 | 2014-12-02 16:52:19 +0900 | [diff] [blame] | 29 | #include <asm/arch/rcar-mstp.h> |
Nobuhiro Iwamatsu | af33ae7 | 2014-11-12 13:03:54 +0900 | [diff] [blame] | 30 | #include <asm/arch/sh_sdhi.h> |
Nobuhiro Iwamatsu | 157585e | 2013-10-20 20:37:17 +0900 | [diff] [blame] | 31 | #include <netdev.h> |
| 32 | #include <miiphy.h> |
Nobuhiro Iwamatsu | 7fbb92b | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 33 | #include <i2c.h> |
Nobuhiro Iwamatsu | cb5c69a | 2014-03-31 11:52:51 +0900 | [diff] [blame] | 34 | #include <div64.h> |
Nobuhiro Iwamatsu | 7fbb92b | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 35 | #include "qos.h" |
| 36 | |
| 37 | DECLARE_GLOBAL_DATA_PTR; |
| 38 | |
Nobuhiro Iwamatsu | cb5c69a | 2014-03-31 11:52:51 +0900 | [diff] [blame] | 39 | #define CLK2MHZ(clk) (clk / 1000 / 1000) |
Nobuhiro Iwamatsu | 7fbb92b | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 40 | void s_init(void) |
| 41 | { |
Nobuhiro Iwamatsu | 0a6c510 | 2014-03-27 16:18:08 +0900 | [diff] [blame] | 42 | struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE; |
| 43 | struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE; |
Nobuhiro Iwamatsu | cb5c69a | 2014-03-31 11:52:51 +0900 | [diff] [blame] | 44 | u32 stc; |
Nobuhiro Iwamatsu | 7fbb92b | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 45 | |
| 46 | /* Watchdog init */ |
| 47 | writel(0xA5A5A500, &rwdt->rwtcsra); |
| 48 | writel(0xA5A5A500, &swdt->swtcsra); |
| 49 | |
Nobuhiro Iwamatsu | cb5c69a | 2014-03-31 11:52:51 +0900 | [diff] [blame] | 50 | /* CPU frequency setting. Set to 1.5GHz */ |
Tom Rini | 8c70baa | 2021-12-14 13:36:40 -0500 | [diff] [blame] | 51 | stc = ((1500 / CLK2MHZ(get_board_sys_clk())) - 1) << PLL0_STC_BIT; |
Nobuhiro Iwamatsu | cb5c69a | 2014-03-31 11:52:51 +0900 | [diff] [blame] | 52 | clrsetbits_le32(PLL0CR, PLL0_STC_MASK, stc); |
| 53 | |
Nobuhiro Iwamatsu | 7fbb92b | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 54 | /* QoS */ |
| 55 | qos_init(); |
Nobuhiro Iwamatsu | 7fbb92b | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 56 | } |
| 57 | |
Marek Vasut | b0fd6e2 | 2018-04-17 14:13:11 +0200 | [diff] [blame] | 58 | #define TMU0_MSTP125 BIT(25) |
Nobuhiro Iwamatsu | af33ae7 | 2014-11-12 13:03:54 +0900 | [diff] [blame] | 59 | |
| 60 | #define SD1CKCR 0xE6150078 |
| 61 | #define SD2CKCR 0xE615026C |
| 62 | #define SD_97500KHZ 0x7 |
| 63 | |
Nobuhiro Iwamatsu | 7fbb92b | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 64 | int board_early_init_f(void) |
| 65 | { |
| 66 | mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125); |
| 67 | |
Nobuhiro Iwamatsu | af33ae7 | 2014-11-12 13:03:54 +0900 | [diff] [blame] | 68 | /* |
| 69 | * SD0 clock is set to 97.5MHz by default. |
| 70 | * Set SD1 and SD2 to the 97.5MHz as well. |
| 71 | */ |
| 72 | writel(SD_97500KHZ, SD1CKCR); |
| 73 | writel(SD_97500KHZ, SD2CKCR); |
| 74 | |
Nobuhiro Iwamatsu | 7fbb92b | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 75 | return 0; |
| 76 | } |
| 77 | |
Marek Vasut | b0fd6e2 | 2018-04-17 14:13:11 +0200 | [diff] [blame] | 78 | #define ETHERNET_PHY_RESET 176 /* GPIO 5 22 */ |
| 79 | |
Nobuhiro Iwamatsu | 7fbb92b | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 80 | int board_init(void) |
| 81 | { |
| 82 | /* adress of boot parameters */ |
Nobuhiro Iwamatsu | 692912b | 2014-11-10 13:58:50 +0900 | [diff] [blame] | 83 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
Nobuhiro Iwamatsu | 7fbb92b | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 84 | |
Marek Vasut | b0fd6e2 | 2018-04-17 14:13:11 +0200 | [diff] [blame] | 85 | /* Force ethernet PHY out of reset */ |
| 86 | gpio_request(ETHERNET_PHY_RESET, "phy_reset"); |
| 87 | gpio_direction_output(ETHERNET_PHY_RESET, 0); |
| 88 | mdelay(10); |
| 89 | gpio_direction_output(ETHERNET_PHY_RESET, 1); |
Nobuhiro Iwamatsu | 157585e | 2013-10-20 20:37:17 +0900 | [diff] [blame] | 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
Marek Vasut | b0fd6e2 | 2018-04-17 14:13:11 +0200 | [diff] [blame] | 94 | int dram_init(void) |
Nobuhiro Iwamatsu | 157585e | 2013-10-20 20:37:17 +0900 | [diff] [blame] | 95 | { |
Siva Durga Prasad Paladugu | b3d55ea | 2018-07-16 15:56:11 +0530 | [diff] [blame] | 96 | if (fdtdec_setup_mem_size_base() != 0) |
Marek Vasut | b0fd6e2 | 2018-04-17 14:13:11 +0200 | [diff] [blame] | 97 | return -EINVAL; |
Nobuhiro Iwamatsu | 157585e | 2013-10-20 20:37:17 +0900 | [diff] [blame] | 98 | |
Nobuhiro Iwamatsu | 7fbb92b | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 99 | return 0; |
| 100 | } |
| 101 | |
Marek Vasut | b0fd6e2 | 2018-04-17 14:13:11 +0200 | [diff] [blame] | 102 | int dram_init_banksize(void) |
Nobuhiro Iwamatsu | af33ae7 | 2014-11-12 13:03:54 +0900 | [diff] [blame] | 103 | { |
Marek Vasut | b0fd6e2 | 2018-04-17 14:13:11 +0200 | [diff] [blame] | 104 | fdtdec_setup_memory_banksize(); |
Nobuhiro Iwamatsu | 7fbb92b | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | |
Marek Vasut | b0fd6e2 | 2018-04-17 14:13:11 +0200 | [diff] [blame] | 109 | /* Koelsch has KSZ8041NL/RNL */ |
| 110 | #define PHY_CONTROL1 0x1E |
Marek Vasut | 9580a45 | 2019-03-30 07:05:09 +0100 | [diff] [blame] | 111 | #define PHY_LED_MODE 0xC000 |
Nobuhiro Iwamatsu | 157585e | 2013-10-20 20:37:17 +0900 | [diff] [blame] | 112 | #define PHY_LED_MODE_ACK 0x4000 |
| 113 | int board_phy_config(struct phy_device *phydev) |
| 114 | { |
| 115 | int ret = phy_read(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1); |
| 116 | ret &= ~PHY_LED_MODE; |
| 117 | ret |= PHY_LED_MODE_ACK; |
| 118 | ret = phy_write(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1, (u16)ret); |
| 119 | |
| 120 | return 0; |
| 121 | } |
| 122 | |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 123 | void reset_cpu(void) |
Nobuhiro Iwamatsu | 7fbb92b | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 124 | { |
Marek Vasut | b0fd6e2 | 2018-04-17 14:13:11 +0200 | [diff] [blame] | 125 | struct udevice *dev; |
| 126 | const u8 pmic_bus = 6; |
| 127 | const u8 pmic_addr = 0x58; |
| 128 | u8 data; |
| 129 | int ret; |
| 130 | |
| 131 | ret = i2c_get_chip_for_busnum(pmic_bus, pmic_addr, 1, &dev); |
| 132 | if (ret) |
| 133 | hang(); |
| 134 | |
| 135 | ret = dm_i2c_read(dev, 0x13, &data, 1); |
| 136 | if (ret) |
| 137 | hang(); |
| 138 | |
| 139 | data |= BIT(1); |
Nobuhiro Iwamatsu | 6c57c16 | 2013-10-10 10:48:20 +0900 | [diff] [blame] | 140 | |
Marek Vasut | b0fd6e2 | 2018-04-17 14:13:11 +0200 | [diff] [blame] | 141 | ret = dm_i2c_write(dev, 0x13, &data, 1); |
| 142 | if (ret) |
| 143 | hang(); |
Nobuhiro Iwamatsu | 7fbb92b | 2013-11-21 17:07:46 +0900 | [diff] [blame] | 144 | } |
Nobuhiro Iwamatsu | 6288fb4 | 2014-12-09 11:24:01 +0900 | [diff] [blame] | 145 | |
Marek Vasut | b0fd6e2 | 2018-04-17 14:13:11 +0200 | [diff] [blame] | 146 | enum env_location env_get_location(enum env_operation op, int prio) |
| 147 | { |
| 148 | const u32 load_magic = 0xb33fc0de; |
Nobuhiro Iwamatsu | 6288fb4 | 2014-12-09 11:24:01 +0900 | [diff] [blame] | 149 | |
Marek Vasut | b0fd6e2 | 2018-04-17 14:13:11 +0200 | [diff] [blame] | 150 | /* Block environment access if loaded using JTAG */ |
| 151 | if ((readl(CONFIG_SPL_TEXT_BASE + 0x24) == load_magic) && |
| 152 | (op != ENVOP_INIT)) |
| 153 | return ENVL_UNKNOWN; |
| 154 | |
| 155 | if (prio) |
| 156 | return ENVL_UNKNOWN; |
| 157 | |
| 158 | return ENVL_SPI_FLASH; |
| 159 | } |