Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Walter Schweizer | d2ac326 | 2016-10-06 23:29:56 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2009-2012 |
| 4 | * Wojciech Dubowik <wojciech.dubowik@neratec.com> |
| 5 | * Luka Perkov <luka@openwrt.org> |
Walter Schweizer | d2ac326 | 2016-10-06 23:29:56 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 9 | #include <init.h> |
Walter Schweizer | d2ac326 | 2016-10-06 23:29:56 +0200 | [diff] [blame] | 10 | #include <miiphy.h> |
Simon Glass | 0c36441 | 2019-12-28 10:44:48 -0700 | [diff] [blame] | 11 | #include <net.h> |
Simon Glass | d9a766f | 2017-05-17 08:23:00 -0600 | [diff] [blame] | 12 | #include <asm/setup.h> |
Walter Schweizer | d2ac326 | 2016-10-06 23:29:56 +0200 | [diff] [blame] | 13 | #include <asm/arch/cpu.h> |
| 14 | #include <asm/arch/soc.h> |
| 15 | #include <asm/arch/mpp.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 16 | #include <linux/delay.h> |
Walter Schweizer | d2ac326 | 2016-10-06 23:29:56 +0200 | [diff] [blame] | 17 | #include "ds109.h" |
| 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
| 21 | int board_early_init_f(void) |
| 22 | { |
| 23 | /* |
| 24 | * default gpio configuration |
| 25 | * There are maximum 64 gpios controlled through 2 sets of registers |
| 26 | * the below configuration configures mainly initial LED status |
| 27 | */ |
| 28 | mvebu_config_gpio(DS109_OE_VAL_LOW, |
| 29 | DS109_OE_VAL_HIGH, |
| 30 | DS109_OE_LOW, DS109_OE_HIGH); |
| 31 | |
| 32 | /* Multi-Purpose Pins Functionality configuration */ |
| 33 | static const u32 kwmpp_config[] = { |
| 34 | MPP0_SPI_SCn, /* SPI Flash */ |
| 35 | MPP1_SPI_MOSI, |
| 36 | MPP2_SPI_SCK, |
| 37 | MPP3_SPI_MISO, |
| 38 | MPP4_GPIO, |
| 39 | MPP5_GPO, |
| 40 | MPP6_SYSRST_OUTn, /* Reset signal */ |
| 41 | MPP7_GPO, |
| 42 | MPP8_TW_SDA, /* I2C */ |
| 43 | MPP9_TW_SCK, /* I2C */ |
| 44 | MPP10_UART0_TXD, |
| 45 | MPP11_UART0_RXD, |
| 46 | MPP12_GPO, |
| 47 | MPP13_UART1_TXD, |
| 48 | MPP14_UART1_RXD, |
| 49 | MPP15_GPIO, |
| 50 | MPP16_GPIO, |
| 51 | MPP17_GPIO, |
| 52 | MPP18_GPO, |
| 53 | MPP19_GPO, |
| 54 | MPP20_SATA1_ACTn, |
| 55 | MPP21_SATA0_ACTn, |
| 56 | MPP22_GPIO, /* HDD2 FAIL LED */ |
| 57 | MPP23_GPIO, /* HDD1 FAIL LED */ |
| 58 | MPP24_GPIO, |
| 59 | MPP25_GPIO, |
| 60 | MPP26_GPIO, |
| 61 | MPP27_GPIO, |
| 62 | MPP28_GPIO, |
| 63 | MPP29_GPIO, |
| 64 | MPP30_GPIO, |
| 65 | MPP31_GPIO, /* HDD2 */ |
| 66 | MPP32_GPIO, /* FAN A */ |
| 67 | MPP33_GPIO, /* FAN B */ |
| 68 | MPP34_GPIO, /* FAN C */ |
| 69 | MPP35_GPIO, /* FAN SENSE */ |
| 70 | MPP36_GPIO, |
| 71 | MPP37_GPIO, |
| 72 | MPP38_GPIO, |
| 73 | MPP39_GPIO, |
| 74 | MPP40_GPIO, |
| 75 | MPP41_GPIO, |
| 76 | MPP42_GPIO, |
| 77 | MPP43_GPIO, |
| 78 | MPP44_GPIO, |
| 79 | MPP45_GPIO, |
| 80 | MPP46_GPIO, |
| 81 | MPP47_GPIO, |
| 82 | MPP48_GPIO, |
| 83 | MPP49_GPIO, |
| 84 | 0 |
| 85 | }; |
| 86 | kirkwood_mpp_conf(kwmpp_config, NULL); |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | int board_init(void) |
| 91 | { |
| 92 | /* address of boot parameters */ |
| 93 | gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100; |
| 94 | |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | /* Synology reset uses UART */ |
| 99 | #include <ns16550.h> |
| 100 | #define SOFTWARE_SHUTDOWN 0x31 |
| 101 | #define SOFTWARE_REBOOT 0x43 |
| 102 | #define CONFIG_SYS_NS16550_COM2 KW_UART1_BASE |
| 103 | void reset_misc(void) |
| 104 | { |
| 105 | int b_d; |
| 106 | printf("Synology reset..."); |
| 107 | udelay(50000); |
| 108 | |
Simon Glass | 119e7ef | 2020-12-22 19:30:18 -0700 | [diff] [blame] | 109 | b_d = ns16550_calc_divisor((struct ns16550 *)CONFIG_SYS_NS16550_COM2, |
| 110 | CONFIG_SYS_NS16550_CLK, 9600); |
Simon Glass | 2b92398 | 2020-12-22 19:30:19 -0700 | [diff] [blame] | 111 | ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM2, b_d); |
| 112 | ns16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM2, |
| 113 | SOFTWARE_REBOOT); |
Walter Schweizer | d2ac326 | 2016-10-06 23:29:56 +0200 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /* Support old kernels */ |
| 117 | void setup_board_tags(struct tag **in_params) |
| 118 | { |
| 119 | unsigned int boardId; |
| 120 | struct tag *params; |
| 121 | struct tag_mv_uboot *t; |
Walter Schweizer | 8eb2ce0 | 2016-10-06 23:30:00 +0200 | [diff] [blame] | 122 | int i; |
Walter Schweizer | d2ac326 | 2016-10-06 23:29:56 +0200 | [diff] [blame] | 123 | |
| 124 | printf("Synology board tags..."); |
| 125 | params = *in_params; |
| 126 | t = (struct tag_mv_uboot *)¶ms->u; |
| 127 | |
| 128 | t->uboot_version = VER_NUM; |
| 129 | |
| 130 | boardId = SYNO_DS109_ID; |
| 131 | t->uboot_version |= boardId; |
| 132 | |
| 133 | t->tclk = CONFIG_SYS_TCLK; |
| 134 | t->sysclk = CONFIG_SYS_TCLK*2; |
| 135 | |
Walter Schweizer | 8eb2ce0 | 2016-10-06 23:30:00 +0200 | [diff] [blame] | 136 | t->isusbhost = 1; |
| 137 | for (i = 0; i < 4; i++) { |
| 138 | memset(t->macaddr[i], 0, sizeof(t->macaddr[i])); |
| 139 | t->mtu[i] = 0; |
| 140 | } |
| 141 | |
Walter Schweizer | d2ac326 | 2016-10-06 23:29:56 +0200 | [diff] [blame] | 142 | params->hdr.tag = ATAG_MV_UBOOT; |
| 143 | params->hdr.size = tag_size(tag_mv_uboot); |
| 144 | params = tag_next(params); |
| 145 | *in_params = params; |
| 146 | } |
| 147 | |
| 148 | #ifdef CONFIG_RESET_PHY_R |
| 149 | /* Configure and enable MV88E1116 PHY */ |
| 150 | void reset_phy(void) |
| 151 | { |
| 152 | u16 reg; |
| 153 | u16 devadr; |
| 154 | char *name = "egiga0"; |
| 155 | |
| 156 | if (miiphy_set_current_dev(name)) |
| 157 | return; |
| 158 | |
| 159 | /* command to read PHY dev address */ |
| 160 | if (miiphy_read(name, 0xEE, 0xEE, (u16 *)&devadr)) { |
| 161 | printf("Error: 88E1116 could not read PHY dev address\n"); |
| 162 | return; |
| 163 | } |
| 164 | |
| 165 | /* |
| 166 | * Enable RGMII delay on Tx and Rx for CPU port |
| 167 | * Ref: sec 4.7.2 of chip datasheet |
| 168 | */ |
| 169 | miiphy_write(name, devadr, MV88E1116_PGADR_REG, 2); |
| 170 | miiphy_read(name, devadr, MV88E1116_MAC_CTRL_REG, ®); |
| 171 | reg |= (MV88E1116_RGMII_RXTM_CTRL | MV88E1116_RGMII_TXTM_CTRL); |
| 172 | miiphy_write(name, devadr, MV88E1116_MAC_CTRL_REG, reg); |
| 173 | miiphy_write(name, devadr, MV88E1116_PGADR_REG, 0); |
| 174 | |
| 175 | /* reset the phy */ |
| 176 | miiphy_reset(name, devadr); |
| 177 | |
| 178 | printf("88E1116 Initialized on %s\n", name); |
| 179 | } |
| 180 | #endif /* CONFIG_RESET_PHY_R */ |