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