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