blob: fe3b0eb554fff5131cfd1954c809aed9755ffe65 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Walter Schweizerd2ac3262016-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 Schweizerd2ac3262016-10-06 23:29:56 +02006 */
7
8#include <common.h>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Walter Schweizerd2ac3262016-10-06 23:29:56 +020010#include <miiphy.h>
Simon Glass0c364412019-12-28 10:44:48 -070011#include <net.h>
Simon Glassd9a766f2017-05-17 08:23:00 -060012#include <asm/setup.h>
Walter Schweizerd2ac3262016-10-06 23:29:56 +020013#include <asm/arch/cpu.h>
14#include <asm/arch/soc.h>
15#include <asm/arch/mpp.h>
Simon Glassdbd79542020-05-10 11:40:11 -060016#include <linux/delay.h>
Walter Schweizerd2ac3262016-10-06 23:29:56 +020017#include "ds109.h"
18
19DECLARE_GLOBAL_DATA_PTR;
20
21int 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
90int 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
103void reset_misc(void)
104{
105 int b_d;
106 printf("Synology reset...");
107 udelay(50000);
108
Simon Glass119e7ef2020-12-22 19:30:18 -0700109 b_d = ns16550_calc_divisor((struct ns16550 *)CONFIG_SYS_NS16550_COM2,
110 CONFIG_SYS_NS16550_CLK, 9600);
Simon Glass2b923982020-12-22 19:30:19 -0700111 ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM2, b_d);
112 ns16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM2,
113 SOFTWARE_REBOOT);
Walter Schweizerd2ac3262016-10-06 23:29:56 +0200114}
115
116/* Support old kernels */
117void setup_board_tags(struct tag **in_params)
118{
119 unsigned int boardId;
120 struct tag *params;
121 struct tag_mv_uboot *t;
Walter Schweizer8eb2ce02016-10-06 23:30:00 +0200122 int i;
Walter Schweizerd2ac3262016-10-06 23:29:56 +0200123
124 printf("Synology board tags...");
125 params = *in_params;
126 t = (struct tag_mv_uboot *)&params->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 Schweizer8eb2ce02016-10-06 23:30:00 +0200136 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 Schweizerd2ac3262016-10-06 23:29:56 +0200142 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 */
150void 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, &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 */