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