gfs2: Switch to may_setattr in gfs2_setattr
[linux-2.6-microblaze.git] / arch / arm / mach-ixp4xx / nslu2-setup.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * arch/arm/mach-ixp4xx/nslu2-setup.c
4  *
5  * NSLU2 board-setup
6  *
7  * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
8  *
9  * based on ixdp425-setup.c:
10  *      Copyright (C) 2003-2004 MontaVista Software, Inc.
11  * based on nslu2-power.c:
12  *      Copyright (C) 2005 Tower Technologies
13  *
14  * Author: Mark Rakes <mrakes at mac.com>
15  * Author: Rod Whitby <rod@whitby.id.au>
16  * Author: Alessandro Zummo <a.zummo@towertech.it>
17  * Maintainers: http://www.nslu2-linux.org/
18  *
19  */
20 #include <linux/gpio.h>
21 #include <linux/if_ether.h>
22 #include <linux/irq.h>
23 #include <linux/serial.h>
24 #include <linux/serial_8250.h>
25 #include <linux/leds.h>
26 #include <linux/reboot.h>
27 #include <linux/i2c.h>
28 #include <linux/gpio/machine.h>
29 #include <linux/io.h>
30 #include <asm/mach-types.h>
31 #include <asm/mach/arch.h>
32 #include <asm/mach/flash.h>
33 #include <asm/mach/time.h>
34 #include <mach/hardware.h>
35
36 #include "irqs.h"
37
38 #define NSLU2_SDA_PIN           7
39 #define NSLU2_SCL_PIN           6
40
41 /* NSLU2 Timer */
42 #define NSLU2_FREQ 66000000
43
44 /* Buttons */
45 #define NSLU2_PB_GPIO           5       /* power button */
46 #define NSLU2_PO_GPIO           8       /* power off */
47 #define NSLU2_RB_GPIO           12      /* reset button */
48
49 /* Buzzer */
50 #define NSLU2_GPIO_BUZZ         4
51
52 /* LEDs */
53 #define NSLU2_LED_RED_GPIO      0
54 #define NSLU2_LED_GRN_GPIO      1
55 #define NSLU2_LED_DISK1_GPIO    3
56 #define NSLU2_LED_DISK2_GPIO    2
57
58 static struct flash_platform_data nslu2_flash_data = {
59         .map_name               = "cfi_probe",
60         .width                  = 2,
61 };
62
63 static struct resource nslu2_flash_resource = {
64         .flags                  = IORESOURCE_MEM,
65 };
66
67 static struct platform_device nslu2_flash = {
68         .name                   = "IXP4XX-Flash",
69         .id                     = 0,
70         .dev.platform_data      = &nslu2_flash_data,
71         .num_resources          = 1,
72         .resource               = &nslu2_flash_resource,
73 };
74
75 static struct gpiod_lookup_table nslu2_i2c_gpiod_table = {
76         .dev_id         = "i2c-gpio.0",
77         .table          = {
78                 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NSLU2_SDA_PIN,
79                                 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
80                 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NSLU2_SCL_PIN,
81                                 NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
82         },
83 };
84
85 static struct i2c_board_info __initdata nslu2_i2c_board_info [] = {
86         {
87                 I2C_BOARD_INFO("x1205", 0x6f),
88         },
89 };
90
91 static struct gpio_led nslu2_led_pins[] = {
92         {
93                 .name           = "nslu2:green:ready",
94                 .gpio           = NSLU2_LED_GRN_GPIO,
95         },
96         {
97                 .name           = "nslu2:red:status",
98                 .gpio           = NSLU2_LED_RED_GPIO,
99         },
100         {
101                 .name           = "nslu2:green:disk-1",
102                 .gpio           = NSLU2_LED_DISK1_GPIO,
103                 .active_low     = true,
104         },
105         {
106                 .name           = "nslu2:green:disk-2",
107                 .gpio           = NSLU2_LED_DISK2_GPIO,
108                 .active_low     = true,
109         },
110 };
111
112 static struct gpio_led_platform_data nslu2_led_data = {
113         .num_leds               = ARRAY_SIZE(nslu2_led_pins),
114         .leds                   = nslu2_led_pins,
115 };
116
117 static struct platform_device nslu2_leds = {
118         .name                   = "leds-gpio",
119         .id                     = -1,
120         .dev.platform_data      = &nslu2_led_data,
121 };
122
123 static struct platform_device nslu2_i2c_gpio = {
124         .name                   = "i2c-gpio",
125         .id                     = 0,
126         .dev     = {
127                 .platform_data  = NULL,
128         },
129 };
130
131 static struct resource nslu2_beeper_resources[] = {
132         {
133                 .start  = IRQ_IXP4XX_TIMER2,
134                 .flags  = IORESOURCE_IRQ,
135         },
136 };
137
138 static struct platform_device nslu2_beeper = {
139         .name                   = "ixp4xx-beeper",
140         .id                     = NSLU2_GPIO_BUZZ,
141         .resource               = nslu2_beeper_resources,
142         .num_resources          = ARRAY_SIZE(nslu2_beeper_resources),
143 };
144
145 static struct resource nslu2_uart_resources[] = {
146         {
147                 .start          = IXP4XX_UART1_BASE_PHYS,
148                 .end            = IXP4XX_UART1_BASE_PHYS + 0x0fff,
149                 .flags          = IORESOURCE_MEM,
150         },
151         {
152                 .start          = IXP4XX_UART2_BASE_PHYS,
153                 .end            = IXP4XX_UART2_BASE_PHYS + 0x0fff,
154                 .flags          = IORESOURCE_MEM,
155         }
156 };
157
158 static struct plat_serial8250_port nslu2_uart_data[] = {
159         {
160                 .mapbase        = IXP4XX_UART1_BASE_PHYS,
161                 .membase        = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET,
162                 .irq            = IRQ_IXP4XX_UART1,
163                 .flags          = UPF_BOOT_AUTOCONF,
164                 .iotype         = UPIO_MEM,
165                 .regshift       = 2,
166                 .uartclk        = IXP4XX_UART_XTAL,
167         },
168         {
169                 .mapbase        = IXP4XX_UART2_BASE_PHYS,
170                 .membase        = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET,
171                 .irq            = IRQ_IXP4XX_UART2,
172                 .flags          = UPF_BOOT_AUTOCONF,
173                 .iotype         = UPIO_MEM,
174                 .regshift       = 2,
175                 .uartclk        = IXP4XX_UART_XTAL,
176         },
177         { }
178 };
179
180 static struct platform_device nslu2_uart = {
181         .name                   = "serial8250",
182         .id                     = PLAT8250_DEV_PLATFORM,
183         .dev.platform_data      = nslu2_uart_data,
184         .num_resources          = 2,
185         .resource               = nslu2_uart_resources,
186 };
187
188 /* Built-in 10/100 Ethernet MAC interfaces */
189 static struct resource nslu2_eth_resources[] = {
190         {
191                 .start          = IXP4XX_EthB_BASE_PHYS,
192                 .end            = IXP4XX_EthB_BASE_PHYS + 0x0fff,
193                 .flags          = IORESOURCE_MEM,
194         },
195 };
196
197 static struct eth_plat_info nslu2_plat_eth[] = {
198         {
199                 .phy            = 1,
200                 .rxq            = 3,
201                 .txreadyq       = 20,
202         }
203 };
204
205 static struct platform_device nslu2_eth[] = {
206         {
207                 .name                   = "ixp4xx_eth",
208                 .id                     = IXP4XX_ETH_NPEB,
209                 .dev.platform_data      = nslu2_plat_eth,
210                 .num_resources          = ARRAY_SIZE(nslu2_eth_resources),
211                 .resource               = nslu2_eth_resources,
212         }
213 };
214
215 static struct platform_device *nslu2_devices[] __initdata = {
216         &nslu2_i2c_gpio,
217         &nslu2_flash,
218         &nslu2_beeper,
219         &nslu2_leds,
220         &nslu2_eth[0],
221 };
222
223 static void nslu2_power_off(void)
224 {
225         /* This causes the box to drop the power and go dead. */
226
227         /* enable the pwr cntl gpio and assert power off */
228         gpio_direction_output(NSLU2_PO_GPIO, 1);
229 }
230
231 static irqreturn_t nslu2_power_handler(int irq, void *dev_id)
232 {
233         /* Signal init to do the ctrlaltdel action, this will bypass init if
234          * it hasn't started and do a kernel_restart.
235          */
236         ctrl_alt_del();
237
238         return IRQ_HANDLED;
239 }
240
241 static irqreturn_t nslu2_reset_handler(int irq, void *dev_id)
242 {
243         /* This is the paper-clip reset, it shuts the machine down directly.
244          */
245         machine_power_off();
246
247         return IRQ_HANDLED;
248 }
249
250 static int __init nslu2_gpio_init(void)
251 {
252         if (!machine_is_nslu2())
253                 return 0;
254
255         /* Request the power off GPIO */
256         return gpio_request(NSLU2_PO_GPIO, "power off");
257 }
258 device_initcall(nslu2_gpio_init);
259
260 static void __init nslu2_timer_init(void)
261 {
262     /* The xtal on this machine is non-standard. */
263     ixp4xx_timer_freq = NSLU2_FREQ;
264
265     /* Call standard timer_init function. */
266     ixp4xx_timer_init();
267 }
268
269 static void __init nslu2_init(void)
270 {
271         uint8_t __iomem *f;
272         int i;
273
274         ixp4xx_sys_init();
275
276         nslu2_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
277         nslu2_flash_resource.end =
278                 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
279
280         gpiod_add_lookup_table(&nslu2_i2c_gpiod_table);
281         i2c_register_board_info(0, nslu2_i2c_board_info,
282                                 ARRAY_SIZE(nslu2_i2c_board_info));
283
284         /*
285          * This is only useful on a modified machine, but it is valuable
286          * to have it first in order to see debug messages, and so that
287          * it does *not* get removed if platform_add_devices fails!
288          */
289         (void)platform_device_register(&nslu2_uart);
290
291         platform_add_devices(nslu2_devices, ARRAY_SIZE(nslu2_devices));
292
293         pm_power_off = nslu2_power_off;
294
295         if (request_irq(gpio_to_irq(NSLU2_RB_GPIO), &nslu2_reset_handler,
296                 IRQF_TRIGGER_LOW, "NSLU2 reset button", NULL) < 0) {
297
298                 printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
299                         gpio_to_irq(NSLU2_RB_GPIO));
300         }
301
302         if (request_irq(gpio_to_irq(NSLU2_PB_GPIO), &nslu2_power_handler,
303                 IRQF_TRIGGER_HIGH, "NSLU2 power button", NULL) < 0) {
304
305                 printk(KERN_DEBUG "Power Button IRQ %d not available\n",
306                         gpio_to_irq(NSLU2_PB_GPIO));
307         }
308
309         /*
310          * Map in a portion of the flash and read the MAC address.
311          * Since it is stored in BE in the flash itself, we need to
312          * byteswap it if we're in LE mode.
313          */
314         f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x40000);
315         if (f) {
316                 for (i = 0; i < 6; i++)
317 #ifdef __ARMEB__
318                         nslu2_plat_eth[0].hwaddr[i] = readb(f + 0x3FFB0 + i);
319 #else
320                         nslu2_plat_eth[0].hwaddr[i] = readb(f + 0x3FFB0 + (i^3));
321 #endif
322                 iounmap(f);
323         }
324         printk(KERN_INFO "NSLU2: Using MAC address %pM for port 0\n",
325                nslu2_plat_eth[0].hwaddr);
326
327 }
328
329 MACHINE_START(NSLU2, "Linksys NSLU2")
330         /* Maintainer: www.nslu2-linux.org */
331         .atag_offset    = 0x100,
332         .map_io         = ixp4xx_map_io,
333         .init_early     = ixp4xx_init_early,
334         .init_irq       = ixp4xx_init_irq,
335         .init_time      = nslu2_timer_init,
336         .init_machine   = nslu2_init,
337 #if defined(CONFIG_PCI)
338         .dma_zone_size  = SZ_64M,
339 #endif
340         .restart        = ixp4xx_restart,
341 MACHINE_END