18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * arch/arm/mach-ixp4xx/fsg-setup.c 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * FSG board-setup 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au> 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * based on ixdp425-setup.c: 108c2ecf20Sopenharmony_ci * Copyright (C) 2003-2004 MontaVista Software, Inc. 118c2ecf20Sopenharmony_ci * based on nslu2-power.c 128c2ecf20Sopenharmony_ci * Copyright (C) 2005 Tower Technologies 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * Author: Rod Whitby <rod@whitby.id.au> 158c2ecf20Sopenharmony_ci * Maintainers: http://www.nslu2-linux.org/ 168c2ecf20Sopenharmony_ci * 178c2ecf20Sopenharmony_ci */ 188c2ecf20Sopenharmony_ci#include <linux/gpio.h> 198c2ecf20Sopenharmony_ci#include <linux/if_ether.h> 208c2ecf20Sopenharmony_ci#include <linux/irq.h> 218c2ecf20Sopenharmony_ci#include <linux/serial.h> 228c2ecf20Sopenharmony_ci#include <linux/serial_8250.h> 238c2ecf20Sopenharmony_ci#include <linux/leds.h> 248c2ecf20Sopenharmony_ci#include <linux/reboot.h> 258c2ecf20Sopenharmony_ci#include <linux/i2c.h> 268c2ecf20Sopenharmony_ci#include <linux/gpio/machine.h> 278c2ecf20Sopenharmony_ci#include <linux/io.h> 288c2ecf20Sopenharmony_ci#include <asm/mach-types.h> 298c2ecf20Sopenharmony_ci#include <asm/mach/arch.h> 308c2ecf20Sopenharmony_ci#include <asm/mach/flash.h> 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#include "irqs.h" 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#define FSG_SDA_PIN 12 358c2ecf20Sopenharmony_ci#define FSG_SCL_PIN 13 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#define FSG_SB_GPIO 4 /* sync button */ 388c2ecf20Sopenharmony_ci#define FSG_RB_GPIO 9 /* reset button */ 398c2ecf20Sopenharmony_ci#define FSG_UB_GPIO 10 /* usb button */ 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_cistatic struct flash_platform_data fsg_flash_data = { 428c2ecf20Sopenharmony_ci .map_name = "cfi_probe", 438c2ecf20Sopenharmony_ci .width = 2, 448c2ecf20Sopenharmony_ci}; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cistatic struct resource fsg_flash_resource = { 478c2ecf20Sopenharmony_ci .flags = IORESOURCE_MEM, 488c2ecf20Sopenharmony_ci}; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cistatic struct platform_device fsg_flash = { 518c2ecf20Sopenharmony_ci .name = "IXP4XX-Flash", 528c2ecf20Sopenharmony_ci .id = 0, 538c2ecf20Sopenharmony_ci .dev = { 548c2ecf20Sopenharmony_ci .platform_data = &fsg_flash_data, 558c2ecf20Sopenharmony_ci }, 568c2ecf20Sopenharmony_ci .num_resources = 1, 578c2ecf20Sopenharmony_ci .resource = &fsg_flash_resource, 588c2ecf20Sopenharmony_ci}; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_cistatic struct gpiod_lookup_table fsg_i2c_gpiod_table = { 618c2ecf20Sopenharmony_ci .dev_id = "i2c-gpio.0", 628c2ecf20Sopenharmony_ci .table = { 638c2ecf20Sopenharmony_ci GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", FSG_SDA_PIN, 648c2ecf20Sopenharmony_ci NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 658c2ecf20Sopenharmony_ci GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", FSG_SCL_PIN, 668c2ecf20Sopenharmony_ci NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 678c2ecf20Sopenharmony_ci }, 688c2ecf20Sopenharmony_ci}; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_cistatic struct platform_device fsg_i2c_gpio = { 718c2ecf20Sopenharmony_ci .name = "i2c-gpio", 728c2ecf20Sopenharmony_ci .id = 0, 738c2ecf20Sopenharmony_ci .dev = { 748c2ecf20Sopenharmony_ci .platform_data = NULL, 758c2ecf20Sopenharmony_ci }, 768c2ecf20Sopenharmony_ci}; 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_cistatic struct i2c_board_info __initdata fsg_i2c_board_info [] = { 798c2ecf20Sopenharmony_ci { 808c2ecf20Sopenharmony_ci I2C_BOARD_INFO("isl1208", 0x6f), 818c2ecf20Sopenharmony_ci }, 828c2ecf20Sopenharmony_ci}; 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_cistatic struct resource fsg_uart_resources[] = { 858c2ecf20Sopenharmony_ci { 868c2ecf20Sopenharmony_ci .start = IXP4XX_UART1_BASE_PHYS, 878c2ecf20Sopenharmony_ci .end = IXP4XX_UART1_BASE_PHYS + 0x0fff, 888c2ecf20Sopenharmony_ci .flags = IORESOURCE_MEM, 898c2ecf20Sopenharmony_ci }, 908c2ecf20Sopenharmony_ci { 918c2ecf20Sopenharmony_ci .start = IXP4XX_UART2_BASE_PHYS, 928c2ecf20Sopenharmony_ci .end = IXP4XX_UART2_BASE_PHYS + 0x0fff, 938c2ecf20Sopenharmony_ci .flags = IORESOURCE_MEM, 948c2ecf20Sopenharmony_ci } 958c2ecf20Sopenharmony_ci}; 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_cistatic struct plat_serial8250_port fsg_uart_data[] = { 988c2ecf20Sopenharmony_ci { 998c2ecf20Sopenharmony_ci .mapbase = IXP4XX_UART1_BASE_PHYS, 1008c2ecf20Sopenharmony_ci .membase = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET, 1018c2ecf20Sopenharmony_ci .irq = IRQ_IXP4XX_UART1, 1028c2ecf20Sopenharmony_ci .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST, 1038c2ecf20Sopenharmony_ci .iotype = UPIO_MEM, 1048c2ecf20Sopenharmony_ci .regshift = 2, 1058c2ecf20Sopenharmony_ci .uartclk = IXP4XX_UART_XTAL, 1068c2ecf20Sopenharmony_ci }, 1078c2ecf20Sopenharmony_ci { 1088c2ecf20Sopenharmony_ci .mapbase = IXP4XX_UART2_BASE_PHYS, 1098c2ecf20Sopenharmony_ci .membase = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET, 1108c2ecf20Sopenharmony_ci .irq = IRQ_IXP4XX_UART2, 1118c2ecf20Sopenharmony_ci .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST, 1128c2ecf20Sopenharmony_ci .iotype = UPIO_MEM, 1138c2ecf20Sopenharmony_ci .regshift = 2, 1148c2ecf20Sopenharmony_ci .uartclk = IXP4XX_UART_XTAL, 1158c2ecf20Sopenharmony_ci }, 1168c2ecf20Sopenharmony_ci { } 1178c2ecf20Sopenharmony_ci}; 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_cistatic struct platform_device fsg_uart = { 1208c2ecf20Sopenharmony_ci .name = "serial8250", 1218c2ecf20Sopenharmony_ci .id = PLAT8250_DEV_PLATFORM, 1228c2ecf20Sopenharmony_ci .dev = { 1238c2ecf20Sopenharmony_ci .platform_data = fsg_uart_data, 1248c2ecf20Sopenharmony_ci }, 1258c2ecf20Sopenharmony_ci .num_resources = ARRAY_SIZE(fsg_uart_resources), 1268c2ecf20Sopenharmony_ci .resource = fsg_uart_resources, 1278c2ecf20Sopenharmony_ci}; 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_cistatic struct platform_device fsg_leds = { 1308c2ecf20Sopenharmony_ci .name = "fsg-led", 1318c2ecf20Sopenharmony_ci .id = -1, 1328c2ecf20Sopenharmony_ci}; 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci/* Built-in 10/100 Ethernet MAC interfaces */ 1358c2ecf20Sopenharmony_cistatic struct resource fsg_eth_npeb_resources[] = { 1368c2ecf20Sopenharmony_ci { 1378c2ecf20Sopenharmony_ci .start = IXP4XX_EthB_BASE_PHYS, 1388c2ecf20Sopenharmony_ci .end = IXP4XX_EthB_BASE_PHYS + 0x0fff, 1398c2ecf20Sopenharmony_ci .flags = IORESOURCE_MEM, 1408c2ecf20Sopenharmony_ci }, 1418c2ecf20Sopenharmony_ci}; 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_cistatic struct resource fsg_eth_npec_resources[] = { 1448c2ecf20Sopenharmony_ci { 1458c2ecf20Sopenharmony_ci .start = IXP4XX_EthC_BASE_PHYS, 1468c2ecf20Sopenharmony_ci .end = IXP4XX_EthC_BASE_PHYS + 0x0fff, 1478c2ecf20Sopenharmony_ci .flags = IORESOURCE_MEM, 1488c2ecf20Sopenharmony_ci }, 1498c2ecf20Sopenharmony_ci}; 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_cistatic struct eth_plat_info fsg_plat_eth[] = { 1528c2ecf20Sopenharmony_ci { 1538c2ecf20Sopenharmony_ci .phy = 5, 1548c2ecf20Sopenharmony_ci .rxq = 3, 1558c2ecf20Sopenharmony_ci .txreadyq = 20, 1568c2ecf20Sopenharmony_ci }, { 1578c2ecf20Sopenharmony_ci .phy = 4, 1588c2ecf20Sopenharmony_ci .rxq = 4, 1598c2ecf20Sopenharmony_ci .txreadyq = 21, 1608c2ecf20Sopenharmony_ci } 1618c2ecf20Sopenharmony_ci}; 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_cistatic struct platform_device fsg_eth[] = { 1648c2ecf20Sopenharmony_ci { 1658c2ecf20Sopenharmony_ci .name = "ixp4xx_eth", 1668c2ecf20Sopenharmony_ci .id = IXP4XX_ETH_NPEB, 1678c2ecf20Sopenharmony_ci .dev = { 1688c2ecf20Sopenharmony_ci .platform_data = fsg_plat_eth, 1698c2ecf20Sopenharmony_ci }, 1708c2ecf20Sopenharmony_ci .num_resources = ARRAY_SIZE(fsg_eth_npeb_resources), 1718c2ecf20Sopenharmony_ci .resource = fsg_eth_npeb_resources, 1728c2ecf20Sopenharmony_ci }, { 1738c2ecf20Sopenharmony_ci .name = "ixp4xx_eth", 1748c2ecf20Sopenharmony_ci .id = IXP4XX_ETH_NPEC, 1758c2ecf20Sopenharmony_ci .dev = { 1768c2ecf20Sopenharmony_ci .platform_data = fsg_plat_eth + 1, 1778c2ecf20Sopenharmony_ci }, 1788c2ecf20Sopenharmony_ci .num_resources = ARRAY_SIZE(fsg_eth_npec_resources), 1798c2ecf20Sopenharmony_ci .resource = fsg_eth_npec_resources, 1808c2ecf20Sopenharmony_ci } 1818c2ecf20Sopenharmony_ci}; 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_cistatic struct platform_device *fsg_devices[] __initdata = { 1848c2ecf20Sopenharmony_ci &fsg_i2c_gpio, 1858c2ecf20Sopenharmony_ci &fsg_flash, 1868c2ecf20Sopenharmony_ci &fsg_leds, 1878c2ecf20Sopenharmony_ci &fsg_eth[0], 1888c2ecf20Sopenharmony_ci &fsg_eth[1], 1898c2ecf20Sopenharmony_ci}; 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_cistatic irqreturn_t fsg_power_handler(int irq, void *dev_id) 1928c2ecf20Sopenharmony_ci{ 1938c2ecf20Sopenharmony_ci /* Signal init to do the ctrlaltdel action, this will bypass init if 1948c2ecf20Sopenharmony_ci * it hasn't started and do a kernel_restart. 1958c2ecf20Sopenharmony_ci */ 1968c2ecf20Sopenharmony_ci ctrl_alt_del(); 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci return IRQ_HANDLED; 1998c2ecf20Sopenharmony_ci} 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_cistatic irqreturn_t fsg_reset_handler(int irq, void *dev_id) 2028c2ecf20Sopenharmony_ci{ 2038c2ecf20Sopenharmony_ci /* This is the paper-clip reset which does an emergency reboot. */ 2048c2ecf20Sopenharmony_ci printk(KERN_INFO "Restarting system.\n"); 2058c2ecf20Sopenharmony_ci machine_restart(NULL); 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci /* This should never be reached. */ 2088c2ecf20Sopenharmony_ci return IRQ_HANDLED; 2098c2ecf20Sopenharmony_ci} 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_cistatic void __init fsg_init(void) 2128c2ecf20Sopenharmony_ci{ 2138c2ecf20Sopenharmony_ci uint8_t __iomem *f; 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci ixp4xx_sys_init(); 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci fsg_flash_resource.start = IXP4XX_EXP_BUS_BASE(0); 2188c2ecf20Sopenharmony_ci fsg_flash_resource.end = 2198c2ecf20Sopenharmony_ci IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci *IXP4XX_EXP_CS0 |= IXP4XX_FLASH_WRITABLE; 2228c2ecf20Sopenharmony_ci *IXP4XX_EXP_CS1 = *IXP4XX_EXP_CS0; 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ci /* Configure CS2 for operation, 8bit and writable */ 2258c2ecf20Sopenharmony_ci *IXP4XX_EXP_CS2 = 0xbfff0002; 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci gpiod_add_lookup_table(&fsg_i2c_gpiod_table); 2288c2ecf20Sopenharmony_ci i2c_register_board_info(0, fsg_i2c_board_info, 2298c2ecf20Sopenharmony_ci ARRAY_SIZE(fsg_i2c_board_info)); 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci /* This is only useful on a modified machine, but it is valuable 2328c2ecf20Sopenharmony_ci * to have it first in order to see debug messages, and so that 2338c2ecf20Sopenharmony_ci * it does *not* get removed if platform_add_devices fails! 2348c2ecf20Sopenharmony_ci */ 2358c2ecf20Sopenharmony_ci (void)platform_device_register(&fsg_uart); 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci platform_add_devices(fsg_devices, ARRAY_SIZE(fsg_devices)); 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci if (request_irq(gpio_to_irq(FSG_RB_GPIO), &fsg_reset_handler, 2408c2ecf20Sopenharmony_ci IRQF_TRIGGER_LOW, "FSG reset button", NULL) < 0) { 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_ci printk(KERN_DEBUG "Reset Button IRQ %d not available\n", 2438c2ecf20Sopenharmony_ci gpio_to_irq(FSG_RB_GPIO)); 2448c2ecf20Sopenharmony_ci } 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_ci if (request_irq(gpio_to_irq(FSG_SB_GPIO), &fsg_power_handler, 2478c2ecf20Sopenharmony_ci IRQF_TRIGGER_LOW, "FSG power button", NULL) < 0) { 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci printk(KERN_DEBUG "Power Button IRQ %d not available\n", 2508c2ecf20Sopenharmony_ci gpio_to_irq(FSG_SB_GPIO)); 2518c2ecf20Sopenharmony_ci } 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci /* 2548c2ecf20Sopenharmony_ci * Map in a portion of the flash and read the MAC addresses. 2558c2ecf20Sopenharmony_ci * Since it is stored in BE in the flash itself, we need to 2568c2ecf20Sopenharmony_ci * byteswap it if we're in LE mode. 2578c2ecf20Sopenharmony_ci */ 2588c2ecf20Sopenharmony_ci f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x400000); 2598c2ecf20Sopenharmony_ci if (f) { 2608c2ecf20Sopenharmony_ci#ifdef __ARMEB__ 2618c2ecf20Sopenharmony_ci int i; 2628c2ecf20Sopenharmony_ci for (i = 0; i < 6; i++) { 2638c2ecf20Sopenharmony_ci fsg_plat_eth[0].hwaddr[i] = readb(f + 0x3C0422 + i); 2648c2ecf20Sopenharmony_ci fsg_plat_eth[1].hwaddr[i] = readb(f + 0x3C043B + i); 2658c2ecf20Sopenharmony_ci } 2668c2ecf20Sopenharmony_ci#else 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci /* 2698c2ecf20Sopenharmony_ci Endian-swapped reads from unaligned addresses are 2708c2ecf20Sopenharmony_ci required to extract the two MACs from the big-endian 2718c2ecf20Sopenharmony_ci Redboot config area in flash. 2728c2ecf20Sopenharmony_ci */ 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci fsg_plat_eth[0].hwaddr[0] = readb(f + 0x3C0421); 2758c2ecf20Sopenharmony_ci fsg_plat_eth[0].hwaddr[1] = readb(f + 0x3C0420); 2768c2ecf20Sopenharmony_ci fsg_plat_eth[0].hwaddr[2] = readb(f + 0x3C0427); 2778c2ecf20Sopenharmony_ci fsg_plat_eth[0].hwaddr[3] = readb(f + 0x3C0426); 2788c2ecf20Sopenharmony_ci fsg_plat_eth[0].hwaddr[4] = readb(f + 0x3C0425); 2798c2ecf20Sopenharmony_ci fsg_plat_eth[0].hwaddr[5] = readb(f + 0x3C0424); 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci fsg_plat_eth[1].hwaddr[0] = readb(f + 0x3C0439); 2828c2ecf20Sopenharmony_ci fsg_plat_eth[1].hwaddr[1] = readb(f + 0x3C043F); 2838c2ecf20Sopenharmony_ci fsg_plat_eth[1].hwaddr[2] = readb(f + 0x3C043E); 2848c2ecf20Sopenharmony_ci fsg_plat_eth[1].hwaddr[3] = readb(f + 0x3C043D); 2858c2ecf20Sopenharmony_ci fsg_plat_eth[1].hwaddr[4] = readb(f + 0x3C043C); 2868c2ecf20Sopenharmony_ci fsg_plat_eth[1].hwaddr[5] = readb(f + 0x3C0443); 2878c2ecf20Sopenharmony_ci#endif 2888c2ecf20Sopenharmony_ci iounmap(f); 2898c2ecf20Sopenharmony_ci } 2908c2ecf20Sopenharmony_ci printk(KERN_INFO "FSG: Using MAC address %pM for port 0\n", 2918c2ecf20Sopenharmony_ci fsg_plat_eth[0].hwaddr); 2928c2ecf20Sopenharmony_ci printk(KERN_INFO "FSG: Using MAC address %pM for port 1\n", 2938c2ecf20Sopenharmony_ci fsg_plat_eth[1].hwaddr); 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci} 2968c2ecf20Sopenharmony_ci 2978c2ecf20Sopenharmony_ciMACHINE_START(FSG, "Freecom FSG-3") 2988c2ecf20Sopenharmony_ci /* Maintainer: www.nslu2-linux.org */ 2998c2ecf20Sopenharmony_ci .map_io = ixp4xx_map_io, 3008c2ecf20Sopenharmony_ci .init_early = ixp4xx_init_early, 3018c2ecf20Sopenharmony_ci .init_irq = ixp4xx_init_irq, 3028c2ecf20Sopenharmony_ci .init_time = ixp4xx_timer_init, 3038c2ecf20Sopenharmony_ci .atag_offset = 0x100, 3048c2ecf20Sopenharmony_ci .init_machine = fsg_init, 3058c2ecf20Sopenharmony_ci#if defined(CONFIG_PCI) 3068c2ecf20Sopenharmony_ci .dma_zone_size = SZ_64M, 3078c2ecf20Sopenharmony_ci#endif 3088c2ecf20Sopenharmony_ci .restart = ixp4xx_restart, 3098c2ecf20Sopenharmony_ciMACHINE_END 3108c2ecf20Sopenharmony_ci 311