GNU Linux-libre 6.1.90-gnu
[releases.git] / arch / arm / mach-orion5x / ls_hgl-setup.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * arch/arm/mach-orion5x/ls_hgl-setup.c
4  *
5  * Maintainer: Zhu Qingsen <zhuqs@cn.fujitsu.com>
6  */
7
8 #include <linux/kernel.h>
9 #include <linux/init.h>
10 #include <linux/platform_device.h>
11 #include <linux/mtd/physmap.h>
12 #include <linux/mv643xx_eth.h>
13 #include <linux/leds.h>
14 #include <linux/gpio_keys.h>
15 #include <linux/input.h>
16 #include <linux/i2c.h>
17 #include <linux/ata_platform.h>
18 #include <linux/gpio.h>
19 #include <asm/mach-types.h>
20 #include <asm/mach/arch.h>
21 #include "common.h"
22 #include "mpp.h"
23 #include "orion5x.h"
24
25 /*****************************************************************************
26  * Linkstation LS-HGL Info
27  ****************************************************************************/
28
29 /*
30  * 256K NOR flash Device bus boot chip select
31  */
32
33 #define LS_HGL_NOR_BOOT_BASE    0xf4000000
34 #define LS_HGL_NOR_BOOT_SIZE    SZ_256K
35
36 /*****************************************************************************
37  * 256KB NOR Flash on BOOT Device
38  ****************************************************************************/
39
40 static struct physmap_flash_data ls_hgl_nor_flash_data = {
41         .width          = 1,
42 };
43
44 static struct resource ls_hgl_nor_flash_resource = {
45         .flags  = IORESOURCE_MEM,
46         .start  = LS_HGL_NOR_BOOT_BASE,
47         .end    = LS_HGL_NOR_BOOT_BASE + LS_HGL_NOR_BOOT_SIZE - 1,
48 };
49
50 static struct platform_device ls_hgl_nor_flash = {
51         .name                   = "physmap-flash",
52         .id                     = 0,
53         .dev            = {
54                 .platform_data  = &ls_hgl_nor_flash_data,
55         },
56         .num_resources          = 1,
57         .resource               = &ls_hgl_nor_flash_resource,
58 };
59
60 /*****************************************************************************
61  * Ethernet
62  ****************************************************************************/
63
64 static struct mv643xx_eth_platform_data ls_hgl_eth_data = {
65         .phy_addr       = 8,
66 };
67
68 /*****************************************************************************
69  * RTC 5C372a on I2C bus
70  ****************************************************************************/
71
72 static struct i2c_board_info __initdata ls_hgl_i2c_rtc = {
73         I2C_BOARD_INFO("rs5c372a", 0x32),
74 };
75
76 /*****************************************************************************
77  * LEDs attached to GPIO
78  ****************************************************************************/
79
80 #define LS_HGL_GPIO_LED_ALARM   2
81 #define LS_HGL_GPIO_LED_INFO    3
82 #define LS_HGL_GPIO_LED_FUNC    17
83 #define LS_HGL_GPIO_LED_PWR     0
84
85
86 static struct gpio_led ls_hgl_led_pins[] = {
87         {
88                 .name      = "alarm:red",
89                 .gpio      = LS_HGL_GPIO_LED_ALARM,
90                 .active_low     = 1,
91         }, {
92                 .name      = "info:amber",
93                 .gpio      = LS_HGL_GPIO_LED_INFO,
94                 .active_low     = 1,
95         }, {
96                 .name      = "func:blue:top",
97                 .gpio      = LS_HGL_GPIO_LED_FUNC,
98                 .active_low     = 1,
99         }, {
100                 .name      = "power:blue:bottom",
101                 .gpio      = LS_HGL_GPIO_LED_PWR,
102         },
103 };
104
105 static struct gpio_led_platform_data ls_hgl_led_data = {
106         .leds      = ls_hgl_led_pins,
107         .num_leds       = ARRAY_SIZE(ls_hgl_led_pins),
108 };
109
110 static struct platform_device ls_hgl_leds = {
111         .name   = "leds-gpio",
112         .id     = -1,
113         .dev    = {
114                 .platform_data  = &ls_hgl_led_data,
115         },
116 };
117
118 /****************************************************************************
119  * GPIO Attached Keys
120  ****************************************************************************/
121 #define LS_HGL_GPIO_KEY_FUNC       15
122 #define LS_HGL_GPIO_KEY_POWER      8
123 #define LS_HGL_GPIO_KEY_AUTOPOWER  10
124
125 #define LS_HGL_SW_POWER     0x00
126 #define LS_HGL_SW_AUTOPOWER 0x01
127
128 static struct gpio_keys_button ls_hgl_buttons[] = {
129         {
130                 .code      = KEY_OPTION,
131                 .gpio      = LS_HGL_GPIO_KEY_FUNC,
132                 .desc      = "Function Button",
133                 .active_low     = 1,
134         }, {
135                 .type           = EV_SW,
136                 .code      = LS_HGL_SW_POWER,
137                 .gpio      = LS_HGL_GPIO_KEY_POWER,
138                 .desc      = "Power-on Switch",
139                 .active_low     = 1,
140         }, {
141                 .type           = EV_SW,
142                 .code      = LS_HGL_SW_AUTOPOWER,
143                 .gpio      = LS_HGL_GPIO_KEY_AUTOPOWER,
144                 .desc      = "Power-auto Switch",
145                 .active_low     = 1,
146         },
147 };
148
149 static struct gpio_keys_platform_data ls_hgl_button_data = {
150         .buttons        = ls_hgl_buttons,
151         .nbuttons       = ARRAY_SIZE(ls_hgl_buttons),
152 };
153
154 static struct platform_device ls_hgl_button_device = {
155         .name      = "gpio-keys",
156         .id          = -1,
157         .num_resources  = 0,
158         .dev        = {
159                 .platform_data  = &ls_hgl_button_data,
160         },
161 };
162
163
164 /*****************************************************************************
165  * SATA
166  ****************************************************************************/
167 static struct mv_sata_platform_data ls_hgl_sata_data = {
168         .n_ports        = 2,
169 };
170
171
172 /*****************************************************************************
173  * Linkstation LS-HGL specific power off method: reboot
174  ****************************************************************************/
175 /*
176  * On the Linkstation LS-HGL, the shutdown process is following:
177  * - Userland monitors key events until the power switch goes to off position
178  * - The board reboots
179  * - U-boot starts and goes into an idle mode waiting for the user
180  *   to move the switch to ON position
181  */
182
183 static void ls_hgl_power_off(void)
184 {
185         orion5x_restart(REBOOT_HARD, NULL);
186 }
187
188
189 /*****************************************************************************
190  * General Setup
191  ****************************************************************************/
192
193 #define LS_HGL_GPIO_USB_POWER   9
194 #define LS_HGL_GPIO_AUTO_POWER  10
195 #define LS_HGL_GPIO_POWER           8
196
197 #define LS_HGL_GPIO_HDD_POWER   1
198
199 static unsigned int ls_hgl_mpp_modes[] __initdata = {
200         MPP0_GPIO, /* LED_PWR */
201         MPP1_GPIO, /* HDD_PWR */
202         MPP2_GPIO, /* LED_ALARM */
203         MPP3_GPIO, /* LED_INFO */
204         MPP4_UNUSED,
205         MPP5_UNUSED,
206         MPP6_GPIO, /* FAN_LCK */
207         MPP7_GPIO, /* INIT */
208         MPP8_GPIO, /* POWER */
209         MPP9_GPIO, /* USB_PWR */
210         MPP10_GPIO, /* AUTO_POWER */
211         MPP11_UNUSED, /* LED_ETH (dummy) */
212         MPP12_UNUSED,
213         MPP13_UNUSED,
214         MPP14_UNUSED,
215         MPP15_GPIO, /* FUNC */
216         MPP16_UNUSED,
217         MPP17_GPIO, /* LED_FUNC */
218         MPP18_UNUSED,
219         MPP19_UNUSED,
220         0,
221 };
222
223 static void __init ls_hgl_init(void)
224 {
225         /*
226          * Setup basic Orion functions. Need to be called early.
227          */
228         orion5x_init();
229
230         orion5x_mpp_conf(ls_hgl_mpp_modes);
231
232         /*
233          * Configure peripherals.
234          */
235         orion5x_ehci0_init();
236         orion5x_ehci1_init();
237         orion5x_eth_init(&ls_hgl_eth_data);
238         orion5x_i2c_init();
239         orion5x_sata_init(&ls_hgl_sata_data);
240         orion5x_uart0_init();
241         orion5x_xor_init();
242
243         mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET,
244                                     ORION_MBUS_DEVBUS_BOOT_ATTR,
245                                     LS_HGL_NOR_BOOT_BASE,
246                                     LS_HGL_NOR_BOOT_SIZE);
247         platform_device_register(&ls_hgl_nor_flash);
248
249         platform_device_register(&ls_hgl_button_device);
250
251         platform_device_register(&ls_hgl_leds);
252
253         i2c_register_board_info(0, &ls_hgl_i2c_rtc, 1);
254
255         /* enable USB power */
256         gpio_set_value(LS_HGL_GPIO_USB_POWER, 1);
257
258         /* register power-off method */
259         pm_power_off = ls_hgl_power_off;
260
261         pr_info("%s: finished\n", __func__);
262 }
263
264 MACHINE_START(LINKSTATION_LS_HGL, "Buffalo Linkstation LS-HGL")
265         /* Maintainer: Zhu Qingsen <zhuqs@cn.fujistu.com> */
266         .atag_offset    = 0x100,
267         .nr_irqs        = ORION5X_NR_IRQS,
268         .init_machine   = ls_hgl_init,
269         .map_io         = orion5x_map_io,
270         .init_early     = orion5x_init_early,
271         .init_irq       = orion5x_init_irq,
272         .init_time      = orion5x_timer_init,
273         .fixup          = tag_fixup_mem32,
274         .restart        = orion5x_restart,
275 MACHINE_END