ARC: mm: vmalloc sync from kernel to user table to update PMD ...
[linux-2.6-microblaze.git] / arch / arm / mach-ixp4xx / fsg-setup.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * arch/arm/mach-ixp4xx/fsg-setup.c
4  *
5  * FSG 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: Rod Whitby <rod@whitby.id.au>
15  * Maintainers: http://www.nslu2-linux.org/
16  *
17  */
18 #include <linux/gpio.h>
19 #include <linux/if_ether.h>
20 #include <linux/irq.h>
21 #include <linux/serial.h>
22 #include <linux/serial_8250.h>
23 #include <linux/leds.h>
24 #include <linux/reboot.h>
25 #include <linux/i2c.h>
26 #include <linux/gpio/machine.h>
27 #include <linux/io.h>
28 #include <asm/mach-types.h>
29 #include <asm/mach/arch.h>
30 #include <asm/mach/flash.h>
31 #include <mach/hardware.h>
32
33 #include "irqs.h"
34
35 #define FSG_SDA_PIN             12
36 #define FSG_SCL_PIN             13
37
38 #define FSG_SB_GPIO             4       /* sync button */
39 #define FSG_RB_GPIO             9       /* reset button */
40 #define FSG_UB_GPIO             10      /* usb button */
41
42 static struct flash_platform_data fsg_flash_data = {
43         .map_name               = "cfi_probe",
44         .width                  = 2,
45 };
46
47 static struct resource fsg_flash_resource = {
48         .flags                  = IORESOURCE_MEM,
49 };
50
51 static struct platform_device fsg_flash = {
52         .name                   = "IXP4XX-Flash",
53         .id                     = 0,
54         .dev = {
55                 .platform_data  = &fsg_flash_data,
56         },
57         .num_resources          = 1,
58         .resource               = &fsg_flash_resource,
59 };
60
61 static struct gpiod_lookup_table fsg_i2c_gpiod_table = {
62         .dev_id         = "i2c-gpio.0",
63         .table          = {
64                 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", FSG_SDA_PIN,
65                                 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
66                 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", FSG_SCL_PIN,
67                                 NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
68         },
69 };
70
71 static struct platform_device fsg_i2c_gpio = {
72         .name                   = "i2c-gpio",
73         .id                     = 0,
74         .dev = {
75                 .platform_data  = NULL,
76         },
77 };
78
79 static struct i2c_board_info __initdata fsg_i2c_board_info [] = {
80         {
81                 I2C_BOARD_INFO("isl1208", 0x6f),
82         },
83 };
84
85 static struct resource fsg_uart_resources[] = {
86         {
87                 .start          = IXP4XX_UART1_BASE_PHYS,
88                 .end            = IXP4XX_UART1_BASE_PHYS + 0x0fff,
89                 .flags          = IORESOURCE_MEM,
90         },
91         {
92                 .start          = IXP4XX_UART2_BASE_PHYS,
93                 .end            = IXP4XX_UART2_BASE_PHYS + 0x0fff,
94                 .flags          = IORESOURCE_MEM,
95         }
96 };
97
98 static struct plat_serial8250_port fsg_uart_data[] = {
99         {
100                 .mapbase        = IXP4XX_UART1_BASE_PHYS,
101                 .membase        = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET,
102                 .irq            = IRQ_IXP4XX_UART1,
103                 .flags          = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
104                 .iotype         = UPIO_MEM,
105                 .regshift       = 2,
106                 .uartclk        = IXP4XX_UART_XTAL,
107         },
108         {
109                 .mapbase        = IXP4XX_UART2_BASE_PHYS,
110                 .membase        = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET,
111                 .irq            = IRQ_IXP4XX_UART2,
112                 .flags          = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
113                 .iotype         = UPIO_MEM,
114                 .regshift       = 2,
115                 .uartclk        = IXP4XX_UART_XTAL,
116         },
117         { }
118 };
119
120 static struct platform_device fsg_uart = {
121         .name                   = "serial8250",
122         .id                     = PLAT8250_DEV_PLATFORM,
123         .dev = {
124                 .platform_data  = fsg_uart_data,
125         },
126         .num_resources          = ARRAY_SIZE(fsg_uart_resources),
127         .resource               = fsg_uart_resources,
128 };
129
130 static struct platform_device fsg_leds = {
131         .name           = "fsg-led",
132         .id             = -1,
133 };
134
135 /* Built-in 10/100 Ethernet MAC interfaces */
136 static struct resource fsg_eth_npeb_resources[] = {
137         {
138                 .start          = IXP4XX_EthB_BASE_PHYS,
139                 .end            = IXP4XX_EthB_BASE_PHYS + 0x0fff,
140                 .flags          = IORESOURCE_MEM,
141         },
142 };
143
144 static struct resource fsg_eth_npec_resources[] = {
145         {
146                 .start          = IXP4XX_EthC_BASE_PHYS,
147                 .end            = IXP4XX_EthC_BASE_PHYS + 0x0fff,
148                 .flags          = IORESOURCE_MEM,
149         },
150 };
151
152 static struct eth_plat_info fsg_plat_eth[] = {
153         {
154                 .phy            = 5,
155                 .rxq            = 3,
156                 .txreadyq       = 20,
157         }, {
158                 .phy            = 4,
159                 .rxq            = 4,
160                 .txreadyq       = 21,
161         }
162 };
163
164 static struct platform_device fsg_eth[] = {
165         {
166                 .name                   = "ixp4xx_eth",
167                 .id                     = IXP4XX_ETH_NPEB,
168                 .dev = {
169                         .platform_data  = fsg_plat_eth,
170                 },
171                 .num_resources  = ARRAY_SIZE(fsg_eth_npeb_resources),
172                 .resource       = fsg_eth_npeb_resources,
173         }, {
174                 .name                   = "ixp4xx_eth",
175                 .id                     = IXP4XX_ETH_NPEC,
176                 .dev = {
177                         .platform_data  = fsg_plat_eth + 1,
178                 },
179                 .num_resources  = ARRAY_SIZE(fsg_eth_npec_resources),
180                 .resource       = fsg_eth_npec_resources,
181         }
182 };
183
184 static struct platform_device *fsg_devices[] __initdata = {
185         &fsg_i2c_gpio,
186         &fsg_flash,
187         &fsg_leds,
188         &fsg_eth[0],
189         &fsg_eth[1],
190 };
191
192 static irqreturn_t fsg_power_handler(int irq, void *dev_id)
193 {
194         /* Signal init to do the ctrlaltdel action, this will bypass init if
195          * it hasn't started and do a kernel_restart.
196          */
197         ctrl_alt_del();
198
199         return IRQ_HANDLED;
200 }
201
202 static irqreturn_t fsg_reset_handler(int irq, void *dev_id)
203 {
204         /* This is the paper-clip reset which does an emergency reboot. */
205         printk(KERN_INFO "Restarting system.\n");
206         machine_restart(NULL);
207
208         /* This should never be reached. */
209         return IRQ_HANDLED;
210 }
211
212 static void __init fsg_init(void)
213 {
214         uint8_t __iomem *f;
215
216         ixp4xx_sys_init();
217
218         fsg_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
219         fsg_flash_resource.end =
220                 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
221
222         *IXP4XX_EXP_CS0 |= IXP4XX_FLASH_WRITABLE;
223         *IXP4XX_EXP_CS1 = *IXP4XX_EXP_CS0;
224
225         /* Configure CS2 for operation, 8bit and writable */
226         *IXP4XX_EXP_CS2 = 0xbfff0002;
227
228         gpiod_add_lookup_table(&fsg_i2c_gpiod_table);
229         i2c_register_board_info(0, fsg_i2c_board_info,
230                                 ARRAY_SIZE(fsg_i2c_board_info));
231
232         /* This is only useful on a modified machine, but it is valuable
233          * to have it first in order to see debug messages, and so that
234          * it does *not* get removed if platform_add_devices fails!
235          */
236         (void)platform_device_register(&fsg_uart);
237
238         platform_add_devices(fsg_devices, ARRAY_SIZE(fsg_devices));
239
240         if (request_irq(gpio_to_irq(FSG_RB_GPIO), &fsg_reset_handler,
241                         IRQF_TRIGGER_LOW, "FSG reset button", NULL) < 0) {
242
243                 printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
244                         gpio_to_irq(FSG_RB_GPIO));
245         }
246
247         if (request_irq(gpio_to_irq(FSG_SB_GPIO), &fsg_power_handler,
248                         IRQF_TRIGGER_LOW, "FSG power button", NULL) < 0) {
249
250                 printk(KERN_DEBUG "Power Button IRQ %d not available\n",
251                         gpio_to_irq(FSG_SB_GPIO));
252         }
253
254         /*
255          * Map in a portion of the flash and read the MAC addresses.
256          * Since it is stored in BE in the flash itself, we need to
257          * byteswap it if we're in LE mode.
258          */
259         f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x400000);
260         if (f) {
261 #ifdef __ARMEB__
262                 int i;
263                 for (i = 0; i < 6; i++) {
264                         fsg_plat_eth[0].hwaddr[i] = readb(f + 0x3C0422 + i);
265                         fsg_plat_eth[1].hwaddr[i] = readb(f + 0x3C043B + i);
266                 }
267 #else
268
269                 /*
270                   Endian-swapped reads from unaligned addresses are
271                   required to extract the two MACs from the big-endian
272                   Redboot config area in flash.
273                 */
274
275                 fsg_plat_eth[0].hwaddr[0] = readb(f + 0x3C0421);
276                 fsg_plat_eth[0].hwaddr[1] = readb(f + 0x3C0420);
277                 fsg_plat_eth[0].hwaddr[2] = readb(f + 0x3C0427);
278                 fsg_plat_eth[0].hwaddr[3] = readb(f + 0x3C0426);
279                 fsg_plat_eth[0].hwaddr[4] = readb(f + 0x3C0425);
280                 fsg_plat_eth[0].hwaddr[5] = readb(f + 0x3C0424);
281
282                 fsg_plat_eth[1].hwaddr[0] = readb(f + 0x3C0439);
283                 fsg_plat_eth[1].hwaddr[1] = readb(f + 0x3C043F);
284                 fsg_plat_eth[1].hwaddr[2] = readb(f + 0x3C043E);
285                 fsg_plat_eth[1].hwaddr[3] = readb(f + 0x3C043D);
286                 fsg_plat_eth[1].hwaddr[4] = readb(f + 0x3C043C);
287                 fsg_plat_eth[1].hwaddr[5] = readb(f + 0x3C0443);
288 #endif
289                 iounmap(f);
290         }
291         printk(KERN_INFO "FSG: Using MAC address %pM for port 0\n",
292                fsg_plat_eth[0].hwaddr);
293         printk(KERN_INFO "FSG: Using MAC address %pM for port 1\n",
294                fsg_plat_eth[1].hwaddr);
295
296 }
297
298 MACHINE_START(FSG, "Freecom FSG-3")
299         /* Maintainer: www.nslu2-linux.org */
300         .map_io         = ixp4xx_map_io,
301         .init_early     = ixp4xx_init_early,
302         .init_irq       = ixp4xx_init_irq,
303         .init_time      = ixp4xx_timer_init,
304         .atag_offset    = 0x100,
305         .init_machine   = fsg_init,
306 #if defined(CONFIG_PCI)
307         .dma_zone_size  = SZ_64M,
308 #endif
309         .restart        = ixp4xx_restart,
310 MACHINE_END
311