blob: 668484b71b6a2c13ffceece4495682756de9a451 [file] [log] [blame]
Chris Packham87a62bc2018-05-30 20:14:35 +12001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2010, 2018
4 * Allied Telesis <www.alliedtelesis.com>
5 */
6
7#include <common.h>
Simon Glass691d7192020-05-10 11:40:02 -06008#include <init.h>
Simon Glass5e6267a2019-12-28 10:44:48 -07009#include <net.h>
Simon Glasscd93d622020-05-10 11:40:13 -060010#include <linux/bitops.h>
Simon Glassc05ed002020-05-10 11:40:11 -060011#include <linux/delay.h>
Chris Packham87a62bc2018-05-30 20:14:35 +120012#include <linux/io.h>
13#include <miiphy.h>
14#include <netdev.h>
Simon Glassc3e44302019-11-14 12:57:11 -070015#include <status_led.h>
Chris Packham87a62bc2018-05-30 20:14:35 +120016#include <asm/arch/cpu.h>
17#include <asm/arch/soc.h>
18#include <asm/arch/mpp.h>
19#include <asm/arch/gpio.h>
20
21/* Note: GPIO differences between specific boards
22 *
23 * We're trying to avoid having multiple build targets for all the Kirkwood
24 * based boards one area where things tend to differ is GPIO usage. For the
25 * most part the GPIOs driven by the bootloader are similar enough in function
26 * that there is no harm in driving them.
27 *
28 * XZ4 XS6 XS16 GS24A GT40 GP24A GT24A
29 * GPIO39 - INT(<) NC MUX_RST_N(>) NC POE_DIS_N(>) NC
30 */
31
32#define SBX81LIFKW_OE_LOW ~(BIT(31) | BIT(30) | BIT(28) | BIT(27) | \
33 BIT(18) | BIT(17) | BIT(13) | BIT(12) | \
34 BIT(10))
35#define SBX81LIFKW_OE_HIGH ~(BIT(0) | BIT(1) | BIT(7))
36#define SBX81LIFKW_OE_VAL_LOW (BIT(31) | BIT(30) | BIT(28) | BIT(27))
37#define SBX81LIFKW_OE_VAL_HIGH (BIT(0) | BIT(1))
38
39#define MV88E6097_RESET 27
40
41DECLARE_GLOBAL_DATA_PTR;
42
43struct led {
44 u32 reg;
45 u32 value;
46 u32 mask;
47};
48
49struct led amber_solid = {
50 MVEBU_GPIO0_BASE,
51 BIT(10),
52 BIT(18) | BIT(10)
53};
54
55struct led green_solid = {
56 MVEBU_GPIO0_BASE,
57 BIT(18) | BIT(10),
58 BIT(18) | BIT(10)
59};
60
61struct led amber_flash = {
62 MVEBU_GPIO0_BASE,
63 0,
64 BIT(18) | BIT(10)
65};
66
67struct led green_flash = {
68 MVEBU_GPIO0_BASE,
69 BIT(18),
70 BIT(18) | BIT(10)
71};
72
73static void status_led_set(struct led *led)
74{
75 clrsetbits_le32(led->reg, led->mask, led->value);
76}
77
78int board_early_init_f(void)
79{
80 /*
81 * default gpio configuration
82 * There are maximum 64 gpios controlled through 2 sets of registers
83 * the below configuration configures mainly initial LED status
84 */
85 mvebu_config_gpio(SBX81LIFKW_OE_VAL_LOW,
86 SBX81LIFKW_OE_VAL_HIGH,
87 SBX81LIFKW_OE_LOW, SBX81LIFKW_OE_HIGH);
88
89 /* Multi-Purpose Pins Functionality configuration */
90 static const u32 kwmpp_config[] = {
91 MPP0_SPI_SCn,
92 MPP1_SPI_MOSI,
93 MPP2_SPI_SCK,
94 MPP3_SPI_MISO,
95 MPP4_UART0_RXD,
96 MPP5_UART0_TXD,
97 MPP6_SYSRST_OUTn,
98 MPP7_PEX_RST_OUTn,
99 MPP8_TW_SDA,
100 MPP9_TW_SCK,
101 MPP10_GPO,
102 MPP11_GPIO,
103 MPP12_GPO,
104 MPP13_GPIO,
105 MPP14_GPIO,
106 MPP15_UART0_RTS,
107 MPP16_UART0_CTS,
108 MPP17_GPIO,
109 MPP18_GPO,
110 MPP19_GPO,
111 MPP20_GPIO,
112 MPP21_GPIO,
113 MPP22_GPIO,
114 MPP23_GPIO,
115 MPP24_GPIO,
116 MPP25_GPIO,
117 MPP26_GPIO,
118 MPP27_GPIO,
119 MPP28_GPIO,
120 MPP29_GPIO,
121 MPP30_GPIO,
122 MPP31_GPIO,
123 MPP32_GPIO,
124 MPP33_GPIO,
125 MPP34_GPIO,
126 MPP35_GPIO,
127 MPP36_GPIO,
128 MPP37_GPIO,
129 MPP38_GPIO,
130 MPP39_GPIO,
131 MPP40_GPIO,
132 MPP41_GPIO,
133 MPP42_GPIO,
134 MPP43_GPIO,
135 MPP44_GPIO,
136 MPP45_GPIO,
137 MPP46_GPIO,
138 MPP47_GPIO,
139 MPP48_GPIO,
140 MPP49_GPIO,
141 0
142 };
143
144 kirkwood_mpp_conf(kwmpp_config, NULL);
145 return 0;
146}
147
148int board_init(void)
149{
150 /* Power-down unused subsystems. The required
151 * subsystems are:
152 *
153 * GE0 b0
154 * PEX0 PHY b1
155 * PEX0.0 b2
156 * TSU b5
157 * SDRAM b6
158 * RUNIT b7
159 */
160 writel((BIT(0) | BIT(1) | BIT(2) |
161 BIT(5) | BIT(6) | BIT(7)),
162 KW_CPU_REG_BASE + 0x1c);
163
164 /* address of boot parameters */
165 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
166
167 status_led_set(&amber_solid);
168
169 return 0;
170}
171
Chris Packham54e33162018-06-03 16:21:27 +1200172#ifdef CONFIG_RESET_PHY_R
173/* automatically defined by kirkwood config.h */
Chris Packham87a62bc2018-05-30 20:14:35 +1200174void reset_phy(void)
175{
Chris Packham54e33162018-06-03 16:21:27 +1200176}
177#endif
178
179#ifdef CONFIG_MV88E61XX_SWITCH
180int mv88e61xx_hw_reset(struct phy_device *phydev)
181{
Chris Packham87a62bc2018-05-30 20:14:35 +1200182 /* Ensure the 88e6097 gets at least 10ms Reset
183 */
184 kw_gpio_set_value(MV88E6097_RESET, 0);
185 mdelay(20);
186 kw_gpio_set_value(MV88E6097_RESET, 1);
187 mdelay(20);
Chris Packham54e33162018-06-03 16:21:27 +1200188
189 phydev->advertising = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full;
190
191 return 0;
Chris Packham87a62bc2018-05-30 20:14:35 +1200192}
193#endif
194
195#ifdef CONFIG_MISC_INIT_R
196int misc_init_r(void)
197{
198 status_led_set(&green_flash);
199
200 return 0;
201}
202#endif