blob: eaac95460c6e1ee74473bfc4730eb60eb9dc8dae [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Walter Schweizera0a868b2016-10-06 23:29:56 +02002/*
3 * Copyright (C) 2009-2012
4 * Wojciech Dubowik <wojciech.dubowik@neratec.com>
5 * Luka Perkov <luka@openwrt.org>
Walter Schweizera0a868b2016-10-06 23:29:56 +02006 */
7
8#include <common.h>
Simon Glass691d7192020-05-10 11:40:02 -06009#include <init.h>
Walter Schweizera0a868b2016-10-06 23:29:56 +020010#include <miiphy.h>
Simon Glass5e6267a2019-12-28 10:44:48 -070011#include <net.h>
Simon Glass401d1c42020-10-30 21:38:53 -060012#include <asm/global_data.h>
Simon Glass5d982852017-05-17 08:23:00 -060013#include <asm/setup.h>
Walter Schweizera0a868b2016-10-06 23:29:56 +020014#include <asm/arch/cpu.h>
15#include <asm/arch/soc.h>
16#include <asm/arch/mpp.h>
Simon Glassc05ed002020-05-10 11:40:11 -060017#include <linux/delay.h>
Walter Schweizera0a868b2016-10-06 23:29:56 +020018#include "ds109.h"
19
20DECLARE_GLOBAL_DATA_PTR;
21
22int 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
91int 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
104void reset_misc(void)
105{
106 int b_d;
107 printf("Synology reset...");
108 udelay(50000);
109
Simon Glassd30c7202020-12-22 19:30:18 -0700110 b_d = ns16550_calc_divisor((struct ns16550 *)CONFIG_SYS_NS16550_COM2,
111 CONFIG_SYS_NS16550_CLK, 9600);
Simon Glass2d6bf752020-12-22 19:30:19 -0700112 ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM2, b_d);
113 ns16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM2,
114 SOFTWARE_REBOOT);
Walter Schweizera0a868b2016-10-06 23:29:56 +0200115}
116
117/* Support old kernels */
118void setup_board_tags(struct tag **in_params)
119{
120 unsigned int boardId;
121 struct tag *params;
122 struct tag_mv_uboot *t;
Walter Schweizer1c653202016-10-06 23:30:00 +0200123 int i;
Walter Schweizera0a868b2016-10-06 23:29:56 +0200124
125 printf("Synology board tags...");
126 params = *in_params;
127 t = (struct tag_mv_uboot *)&params->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 Schweizer1c653202016-10-06 23:30:00 +0200137 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 Schweizera0a868b2016-10-06 23:29:56 +0200143 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 */
151void 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, &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 */