1 // SPDX-License-Identifier: GPL-2.0
3 * arch/arm/mach-ixp4xx/fsg-setup.c
7 * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
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
14 * Author: Rod Whitby <rod@whitby.id.au>
15 * Maintainers: http://www.nslu2-linux.org/
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>
28 #include <asm/mach-types.h>
29 #include <asm/mach/arch.h>
30 #include <asm/mach/flash.h>
31 #include <mach/hardware.h>
35 #define FSG_SDA_PIN 12
36 #define FSG_SCL_PIN 13
38 #define FSG_SB_GPIO 4 /* sync button */
39 #define FSG_RB_GPIO 9 /* reset button */
40 #define FSG_UB_GPIO 10 /* usb button */
42 static struct flash_platform_data fsg_flash_data = {
43 .map_name = "cfi_probe",
47 static struct resource fsg_flash_resource = {
48 .flags = IORESOURCE_MEM,
51 static struct platform_device fsg_flash = {
52 .name = "IXP4XX-Flash",
55 .platform_data = &fsg_flash_data,
58 .resource = &fsg_flash_resource,
61 static struct gpiod_lookup_table fsg_i2c_gpiod_table = {
62 .dev_id = "i2c-gpio.0",
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),
71 static struct platform_device fsg_i2c_gpio = {
75 .platform_data = NULL,
79 static struct i2c_board_info __initdata fsg_i2c_board_info [] = {
81 I2C_BOARD_INFO("isl1208", 0x6f),
85 static struct resource fsg_uart_resources[] = {
87 .start = IXP4XX_UART1_BASE_PHYS,
88 .end = IXP4XX_UART1_BASE_PHYS + 0x0fff,
89 .flags = IORESOURCE_MEM,
92 .start = IXP4XX_UART2_BASE_PHYS,
93 .end = IXP4XX_UART2_BASE_PHYS + 0x0fff,
94 .flags = IORESOURCE_MEM,
98 static struct plat_serial8250_port fsg_uart_data[] = {
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,
106 .uartclk = IXP4XX_UART_XTAL,
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,
115 .uartclk = IXP4XX_UART_XTAL,
120 static struct platform_device fsg_uart = {
121 .name = "serial8250",
122 .id = PLAT8250_DEV_PLATFORM,
124 .platform_data = fsg_uart_data,
126 .num_resources = ARRAY_SIZE(fsg_uart_resources),
127 .resource = fsg_uart_resources,
130 static struct platform_device fsg_leds = {
135 /* Built-in 10/100 Ethernet MAC interfaces */
136 static struct resource fsg_eth_npeb_resources[] = {
138 .start = IXP4XX_EthB_BASE_PHYS,
139 .end = IXP4XX_EthB_BASE_PHYS + 0x0fff,
140 .flags = IORESOURCE_MEM,
144 static struct resource fsg_eth_npec_resources[] = {
146 .start = IXP4XX_EthC_BASE_PHYS,
147 .end = IXP4XX_EthC_BASE_PHYS + 0x0fff,
148 .flags = IORESOURCE_MEM,
152 static struct eth_plat_info fsg_plat_eth[] = {
164 static struct platform_device fsg_eth[] = {
166 .name = "ixp4xx_eth",
167 .id = IXP4XX_ETH_NPEB,
169 .platform_data = fsg_plat_eth,
171 .num_resources = ARRAY_SIZE(fsg_eth_npeb_resources),
172 .resource = fsg_eth_npeb_resources,
174 .name = "ixp4xx_eth",
175 .id = IXP4XX_ETH_NPEC,
177 .platform_data = fsg_plat_eth + 1,
179 .num_resources = ARRAY_SIZE(fsg_eth_npec_resources),
180 .resource = fsg_eth_npec_resources,
184 static struct platform_device *fsg_devices[] __initdata = {
192 static irqreturn_t fsg_power_handler(int irq, void *dev_id)
194 /* Signal init to do the ctrlaltdel action, this will bypass init if
195 * it hasn't started and do a kernel_restart.
202 static irqreturn_t fsg_reset_handler(int irq, void *dev_id)
204 /* This is the paper-clip reset which does an emergency reboot. */
205 printk(KERN_INFO "Restarting system.\n");
206 machine_restart(NULL);
208 /* This should never be reached. */
212 static void __init fsg_init(void)
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;
222 *IXP4XX_EXP_CS0 |= IXP4XX_FLASH_WRITABLE;
223 *IXP4XX_EXP_CS1 = *IXP4XX_EXP_CS0;
225 /* Configure CS2 for operation, 8bit and writable */
226 *IXP4XX_EXP_CS2 = 0xbfff0002;
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));
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!
236 (void)platform_device_register(&fsg_uart);
238 platform_add_devices(fsg_devices, ARRAY_SIZE(fsg_devices));
240 if (request_irq(gpio_to_irq(FSG_RB_GPIO), &fsg_reset_handler,
241 IRQF_TRIGGER_LOW, "FSG reset button", NULL) < 0) {
243 printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
244 gpio_to_irq(FSG_RB_GPIO));
247 if (request_irq(gpio_to_irq(FSG_SB_GPIO), &fsg_power_handler,
248 IRQF_TRIGGER_LOW, "FSG power button", NULL) < 0) {
250 printk(KERN_DEBUG "Power Button IRQ %d not available\n",
251 gpio_to_irq(FSG_SB_GPIO));
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.
259 f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x400000);
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);
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.
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);
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);
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);
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,
309 .restart = ixp4xx_restart,