Nobuhiro Iwamatsu | cff2f5f | 2014-06-26 10:23:30 +0900 | [diff] [blame] | 1 | /* |
| 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 Iwamatsu | 44e1eeb | 2014-12-02 16:52:19 +0900 | [diff] [blame] | 18 | #include <asm/arch/rcar-mstp.h> |
Nobuhiro Iwamatsu | cff2f5f | 2014-06-26 10:23:30 +0900 | [diff] [blame] | 19 | #include <netdev.h> |
| 20 | #include <miiphy.h> |
| 21 | #include <i2c.h> |
| 22 | #include <div64.h> |
| 23 | #include "qos.h" |
| 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
| 27 | #define CLK2MHZ(clk) (clk / 1000 / 1000) |
| 28 | void 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 Iwamatsu | cff2f5f | 2014-06-26 10:23:30 +0900 | [diff] [blame] | 41 | #define TMU0_MSTP125 (1 << 25) |
Nobuhiro Iwamatsu | 0e429bd | 2014-10-31 16:30:25 +0900 | [diff] [blame] | 42 | #define SCIF2_MSTP719 (1 << 19) |
Nobuhiro Iwamatsu | cff2f5f | 2014-06-26 10:23:30 +0900 | [diff] [blame] | 43 | #define ETHER_MSTP813 (1 << 13) |
Nobuhiro Iwamatsu | 92ef38e | 2014-11-10 09:16:43 +0900 | [diff] [blame] | 44 | #define IIC1_MSTP323 (1 << 23) |
| 45 | |
Nobuhiro Iwamatsu | cff2f5f | 2014-06-26 10:23:30 +0900 | [diff] [blame] | 46 | int board_early_init_f(void) |
| 47 | { |
| 48 | /* TMU */ |
| 49 | mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125); |
| 50 | |
Nobuhiro Iwamatsu | 0e429bd | 2014-10-31 16:30:25 +0900 | [diff] [blame] | 51 | /* SCIF2 */ |
| 52 | mstp_clrbits_le32(MSTPSR7, SMSTPCR7, SCIF2_MSTP719); |
Nobuhiro Iwamatsu | cff2f5f | 2014-06-26 10:23:30 +0900 | [diff] [blame] | 53 | |
| 54 | /* ETHER */ |
| 55 | mstp_clrbits_le32(MSTPSR8, SMSTPCR8, ETHER_MSTP813); |
| 56 | |
Nobuhiro Iwamatsu | 92ef38e | 2014-11-10 09:16:43 +0900 | [diff] [blame] | 57 | /* IIC1 / sh-i2c ch1 */ |
| 58 | mstp_clrbits_le32(MSTPSR3, SMSTPCR3, IIC1_MSTP323); |
| 59 | |
Nobuhiro Iwamatsu | cff2f5f | 2014-06-26 10:23:30 +0900 | [diff] [blame] | 60 | return 0; |
| 61 | } |
| 62 | |
Nobuhiro Iwamatsu | cff2f5f | 2014-06-26 10:23:30 +0900 | [diff] [blame] | 63 | int board_init(void) |
| 64 | { |
| 65 | /* adress of boot parameters */ |
Nobuhiro Iwamatsu | 4772684 | 2014-11-10 13:58:50 +0900 | [diff] [blame] | 66 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
Nobuhiro Iwamatsu | cff2f5f | 2014-06-26 10:23:30 +0900 | [diff] [blame] | 67 | |
| 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 */ |
| 98 | int 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 | |
| 123 | int dram_init(void) |
| 124 | { |
Nobuhiro Iwamatsu | cff2f5f | 2014-06-26 10:23:30 +0900 | [diff] [blame] | 125 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE; |
| 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | const struct rmobile_sysinfo sysinfo = { |
| 131 | CONFIG_RMOBILE_BOARD_STRING |
| 132 | }; |
| 133 | |
Nobuhiro Iwamatsu | cff2f5f | 2014-06-26 10:23:30 +0900 | [diff] [blame] | 134 | void reset_cpu(ulong addr) |
| 135 | { |
| 136 | u8 val; |
| 137 | |
Nobuhiro Iwamatsu | f063b32 | 2014-11-10 09:16:44 +0900 | [diff] [blame] | 138 | i2c_set_bus_num(1); /* PowerIC connected to ch1 */ |
Nobuhiro Iwamatsu | cff2f5f | 2014-06-26 10:23:30 +0900 | [diff] [blame] | 139 | 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 | } |