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