121871138SVladimir Barinov /* 221871138SVladimir Barinov * board/renesas/stout/stout.c 321871138SVladimir Barinov * This file is Stout board support. 421871138SVladimir Barinov * 521871138SVladimir Barinov * Copyright (C) 2015 Renesas Electronics Europe GmbH 621871138SVladimir Barinov * Copyright (C) 2015 Renesas Electronics Corporation 721871138SVladimir Barinov * Copyright (C) 2015 Cogent Embedded, Inc. 821871138SVladimir Barinov * 921871138SVladimir Barinov * SPDX-License-Identifier: GPL-2.0 1021871138SVladimir Barinov */ 1121871138SVladimir Barinov 1221871138SVladimir Barinov #include <common.h> 1321871138SVladimir Barinov #include <malloc.h> 1421871138SVladimir Barinov #include <netdev.h> 1521871138SVladimir Barinov #include <dm.h> 1621871138SVladimir Barinov #include <dm/platform_data/serial_sh.h> 1721871138SVladimir Barinov #include <asm/processor.h> 1821871138SVladimir Barinov #include <asm/mach-types.h> 1921871138SVladimir Barinov #include <asm/io.h> 2021871138SVladimir Barinov #include <asm/errno.h> 2121871138SVladimir Barinov #include <asm/arch/sys_proto.h> 2221871138SVladimir Barinov #include <asm/gpio.h> 2321871138SVladimir Barinov #include <asm/arch/rmobile.h> 2421871138SVladimir Barinov #include <asm/arch/rcar-mstp.h> 2521871138SVladimir Barinov #include <asm/arch/mmc.h> 2621871138SVladimir Barinov #include <asm/arch/sh_sdhi.h> 2721871138SVladimir Barinov #include <miiphy.h> 2821871138SVladimir Barinov #include <i2c.h> 2921871138SVladimir Barinov #include <mmc.h> 3021871138SVladimir Barinov #include "qos.h" 3121871138SVladimir Barinov #include "cpld.h" 3221871138SVladimir Barinov 3321871138SVladimir Barinov DECLARE_GLOBAL_DATA_PTR; 3421871138SVladimir Barinov 3521871138SVladimir Barinov #define CLK2MHZ(clk) (clk / 1000 / 1000) 3621871138SVladimir Barinov void s_init(void) 3721871138SVladimir Barinov { 3821871138SVladimir Barinov struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE; 3921871138SVladimir Barinov struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE; 4021871138SVladimir Barinov 4121871138SVladimir Barinov /* Watchdog init */ 4221871138SVladimir Barinov writel(0xA5A5A500, &rwdt->rwtcsra); 4321871138SVladimir Barinov writel(0xA5A5A500, &swdt->swtcsra); 4421871138SVladimir Barinov 4521871138SVladimir Barinov /* CPU frequency setting. Set to 1.4GHz */ 4621871138SVladimir Barinov if (rmobile_get_cpu_rev_integer() >= R8A7790_CUT_ES2X) { 4721871138SVladimir Barinov u32 stat = 0; 4821871138SVladimir Barinov u32 stc = ((1400 / CLK2MHZ(CONFIG_SYS_CLK_FREQ)) - 1) 4921871138SVladimir Barinov << PLL0_STC_BIT; 5021871138SVladimir Barinov clrsetbits_le32(PLL0CR, PLL0_STC_MASK, stc); 5121871138SVladimir Barinov 5221871138SVladimir Barinov do { 5321871138SVladimir Barinov stat = readl(PLLECR) & PLL0ST; 5421871138SVladimir Barinov } while (stat == 0x0); 5521871138SVladimir Barinov } 5621871138SVladimir Barinov 5721871138SVladimir Barinov /* QoS(Quality-of-Service) Init */ 5821871138SVladimir Barinov qos_init(); 5921871138SVladimir Barinov } 6021871138SVladimir Barinov 6121871138SVladimir Barinov #define TMU0_MSTP125 (1 << 25) 6221871138SVladimir Barinov #define SCIFA0_MSTP204 (1 << 4) 6321871138SVladimir Barinov #define SDHI0_MSTP314 (1 << 14) 6421871138SVladimir Barinov #define SDHI2_MSTP312 (1 << 12) 6521871138SVladimir Barinov #define ETHER_MSTP813 (1 << 13) 6621871138SVladimir Barinov 6721871138SVladimir Barinov #define MSTPSR3 0xE6150048 6821871138SVladimir Barinov #define SMSTPCR3 0xE615013C 6921871138SVladimir Barinov 7021871138SVladimir Barinov #define SD2CKCR 0xE6150078 7121871138SVladimir Barinov #define SD2_97500KHZ 0x7 7221871138SVladimir Barinov 7321871138SVladimir Barinov int board_early_init_f(void) 7421871138SVladimir Barinov { 7521871138SVladimir Barinov /* TMU0 */ 7621871138SVladimir Barinov mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125); 7721871138SVladimir Barinov /* SCIFA0 */ 7821871138SVladimir Barinov mstp_clrbits_le32(MSTPSR2, SMSTPCR2, SCIFA0_MSTP204); 7921871138SVladimir Barinov /* ETHER */ 8021871138SVladimir Barinov mstp_clrbits_le32(MSTPSR8, SMSTPCR8, ETHER_MSTP813); 8121871138SVladimir Barinov /* SDHI0,2 */ 8221871138SVladimir Barinov mstp_clrbits_le32(MSTPSR3, SMSTPCR3, SDHI0_MSTP314 | SDHI2_MSTP312); 8321871138SVladimir Barinov 8421871138SVladimir Barinov /* 8521871138SVladimir Barinov * SD0 clock is set to 97.5MHz by default. 8621871138SVladimir Barinov * Set SD2 to the 97.5MHz as well. 8721871138SVladimir Barinov */ 8821871138SVladimir Barinov writel(SD2_97500KHZ, SD2CKCR); 8921871138SVladimir Barinov 9021871138SVladimir Barinov return 0; 9121871138SVladimir Barinov } 9221871138SVladimir Barinov 9321871138SVladimir Barinov int board_init(void) 9421871138SVladimir Barinov { 9521871138SVladimir Barinov /* adress of boot parameters */ 9621871138SVladimir Barinov gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; 9721871138SVladimir Barinov 9821871138SVladimir Barinov /* Init PFC controller */ 9921871138SVladimir Barinov r8a7790_pinmux_init(); 10021871138SVladimir Barinov 10121871138SVladimir Barinov cpld_init(); 10221871138SVladimir Barinov 10321871138SVladimir Barinov #ifdef CONFIG_SH_ETHER 10421871138SVladimir Barinov /* ETHER Enable */ 10521871138SVladimir Barinov gpio_request(GPIO_FN_ETH_CRS_DV, NULL); 10621871138SVladimir Barinov gpio_request(GPIO_FN_ETH_RX_ER, NULL); 10721871138SVladimir Barinov gpio_request(GPIO_FN_ETH_RXD0, NULL); 10821871138SVladimir Barinov gpio_request(GPIO_FN_ETH_RXD1, NULL); 10921871138SVladimir Barinov gpio_request(GPIO_FN_ETH_LINK, NULL); 11021871138SVladimir Barinov gpio_request(GPIO_FN_ETH_REF_CLK, NULL); 11121871138SVladimir Barinov gpio_request(GPIO_FN_ETH_MDIO, NULL); 11221871138SVladimir Barinov gpio_request(GPIO_FN_ETH_TXD1, NULL); 11321871138SVladimir Barinov gpio_request(GPIO_FN_ETH_TX_EN, NULL); 11421871138SVladimir Barinov gpio_request(GPIO_FN_ETH_MAGIC, NULL); 11521871138SVladimir Barinov gpio_request(GPIO_FN_ETH_TXD0, NULL); 11621871138SVladimir Barinov gpio_request(GPIO_FN_ETH_MDC, NULL); 11721871138SVladimir Barinov gpio_request(GPIO_FN_IRQ1, NULL); 11821871138SVladimir Barinov 11921871138SVladimir Barinov gpio_request(GPIO_GP_3_31, NULL); /* PHY_RST */ 12021871138SVladimir Barinov gpio_direction_output(GPIO_GP_3_31, 0); 12121871138SVladimir Barinov mdelay(20); 12221871138SVladimir Barinov gpio_set_value(GPIO_GP_3_31, 1); 12321871138SVladimir Barinov udelay(1); 12421871138SVladimir Barinov #endif 12521871138SVladimir Barinov 12621871138SVladimir Barinov return 0; 12721871138SVladimir Barinov } 12821871138SVladimir Barinov 12921871138SVladimir Barinov #define CXR24 0xEE7003C0 /* MAC address high register */ 13021871138SVladimir Barinov #define CXR25 0xEE7003C8 /* MAC address low register */ 13121871138SVladimir Barinov int board_eth_init(bd_t *bis) 13221871138SVladimir Barinov { 13321871138SVladimir Barinov int ret = -ENODEV; 13421871138SVladimir Barinov 13521871138SVladimir Barinov #ifdef CONFIG_SH_ETHER 13621871138SVladimir Barinov u32 val; 13721871138SVladimir Barinov unsigned char enetaddr[6]; 13821871138SVladimir Barinov 13921871138SVladimir Barinov ret = sh_eth_initialize(bis); 14021871138SVladimir Barinov if (!eth_getenv_enetaddr("ethaddr", enetaddr)) 14121871138SVladimir Barinov return ret; 14221871138SVladimir Barinov 14321871138SVladimir Barinov /* Set Mac address */ 14421871138SVladimir Barinov val = enetaddr[0] << 24 | enetaddr[1] << 16 | 14521871138SVladimir Barinov enetaddr[2] << 8 | enetaddr[3]; 14621871138SVladimir Barinov writel(val, CXR24); 14721871138SVladimir Barinov 14821871138SVladimir Barinov val = enetaddr[4] << 8 | enetaddr[5]; 14921871138SVladimir Barinov writel(val, CXR25); 15021871138SVladimir Barinov #endif 15121871138SVladimir Barinov 15221871138SVladimir Barinov return ret; 15321871138SVladimir Barinov } 15421871138SVladimir Barinov 15521871138SVladimir Barinov /* Stout has KSZ8041NL/RNL */ 15621871138SVladimir Barinov #define PHY_CONTROL1 0x1E 15721871138SVladimir Barinov #define PHY_LED_MODE 0xC0000 15821871138SVladimir Barinov #define PHY_LED_MODE_ACK 0x4000 15921871138SVladimir Barinov int board_phy_config(struct phy_device *phydev) 16021871138SVladimir Barinov { 16121871138SVladimir Barinov int ret = phy_read(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1); 16221871138SVladimir Barinov ret &= ~PHY_LED_MODE; 16321871138SVladimir Barinov ret |= PHY_LED_MODE_ACK; 16421871138SVladimir Barinov ret = phy_write(phydev, MDIO_DEVAD_NONE, PHY_CONTROL1, (u16)ret); 16521871138SVladimir Barinov 16621871138SVladimir Barinov return 0; 16721871138SVladimir Barinov } 16821871138SVladimir Barinov 16921871138SVladimir Barinov int board_mmc_init(bd_t *bis) 17021871138SVladimir Barinov { 17121871138SVladimir Barinov int ret = -ENODEV; 17221871138SVladimir Barinov 17321871138SVladimir Barinov #ifdef CONFIG_SH_SDHI 17421871138SVladimir Barinov gpio_request(GPIO_FN_SD0_DAT0, NULL); 17521871138SVladimir Barinov gpio_request(GPIO_FN_SD0_DAT1, NULL); 17621871138SVladimir Barinov gpio_request(GPIO_FN_SD0_DAT2, NULL); 17721871138SVladimir Barinov gpio_request(GPIO_FN_SD0_DAT3, NULL); 17821871138SVladimir Barinov gpio_request(GPIO_FN_SD0_CLK, NULL); 17921871138SVladimir Barinov gpio_request(GPIO_FN_SD0_CMD, NULL); 18021871138SVladimir Barinov gpio_request(GPIO_FN_SD0_CD, NULL); 18121871138SVladimir Barinov gpio_request(GPIO_FN_SD2_DAT0, NULL); 18221871138SVladimir Barinov gpio_request(GPIO_FN_SD2_DAT1, NULL); 18321871138SVladimir Barinov gpio_request(GPIO_FN_SD2_DAT2, NULL); 18421871138SVladimir Barinov gpio_request(GPIO_FN_SD2_DAT3, NULL); 18521871138SVladimir Barinov gpio_request(GPIO_FN_SD2_CLK, NULL); 18621871138SVladimir Barinov gpio_request(GPIO_FN_SD2_CMD, NULL); 18721871138SVladimir Barinov gpio_request(GPIO_FN_SD2_CD, NULL); 18821871138SVladimir Barinov 18921871138SVladimir Barinov /* SDHI0 - needs CPLD mux setup */ 19021871138SVladimir Barinov gpio_request(GPIO_GP_3_30, NULL); 19121871138SVladimir Barinov gpio_direction_output(GPIO_GP_3_30, 1); /* VLDO3=3.3V */ 19221871138SVladimir Barinov gpio_request(GPIO_GP_5_24, NULL); 19321871138SVladimir Barinov gpio_direction_output(GPIO_GP_5_24, 1); /* power on */ 19421871138SVladimir Barinov 19521871138SVladimir Barinov ret = sh_sdhi_init(CONFIG_SYS_SH_SDHI0_BASE, 0, 19621871138SVladimir Barinov SH_SDHI_QUIRK_16BIT_BUF); 19721871138SVladimir Barinov if (ret) 19821871138SVladimir Barinov return ret; 19921871138SVladimir Barinov 20021871138SVladimir Barinov /* SDHI2 - needs CPLD mux setup */ 20121871138SVladimir Barinov gpio_request(GPIO_GP_3_29, NULL); 20221871138SVladimir Barinov gpio_direction_output(GPIO_GP_3_29, 1); /* VLDO4=3.3V */ 20321871138SVladimir Barinov gpio_request(GPIO_GP_5_25, NULL); 20421871138SVladimir Barinov gpio_direction_output(GPIO_GP_5_25, 1); /* power on */ 20521871138SVladimir Barinov 20621871138SVladimir Barinov ret = sh_sdhi_init(CONFIG_SYS_SH_SDHI2_BASE, 2, 0); 20721871138SVladimir Barinov #endif 20821871138SVladimir Barinov return ret; 20921871138SVladimir Barinov } 21021871138SVladimir Barinov 21121871138SVladimir Barinov 21221871138SVladimir Barinov int dram_init(void) 21321871138SVladimir Barinov { 21421871138SVladimir Barinov gd->ram_size = CONFIG_SYS_SDRAM_SIZE; 21521871138SVladimir Barinov 21621871138SVladimir Barinov return 0; 21721871138SVladimir Barinov } 21821871138SVladimir Barinov 21921871138SVladimir Barinov const struct rmobile_sysinfo sysinfo = { 220*1cc95f6eSNobuhiro Iwamatsu CONFIG_ARCH_RMOBILE_BOARD_STRING 22121871138SVladimir Barinov }; 22221871138SVladimir Barinov 22321871138SVladimir Barinov static const struct sh_serial_platdata serial_platdata = { 22421871138SVladimir Barinov .base = SCIFA0_BASE, 22521871138SVladimir Barinov .type = PORT_SCIFA, 22621871138SVladimir Barinov .clk = CONFIG_MP_CLK_FREQ, 22721871138SVladimir Barinov }; 22821871138SVladimir Barinov 22921871138SVladimir Barinov U_BOOT_DEVICE(stout_serials) = { 23021871138SVladimir Barinov .name = "serial_sh", 23121871138SVladimir Barinov .platdata = &serial_platdata, 23221871138SVladimir Barinov }; 233