Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 // arch/arm/mach-orion5x/wrt350n-v2-setup.c
0003 #include <linux/gpio.h>
0004 #include <linux/kernel.h>
0005 #include <linux/init.h>
0006 #include <linux/platform_device.h>
0007 #include <linux/pci.h>
0008 #include <linux/irq.h>
0009 #include <linux/delay.h>
0010 #include <linux/mtd/physmap.h>
0011 #include <linux/mv643xx_eth.h>
0012 #include <linux/ethtool.h>
0013 #include <linux/leds.h>
0014 #include <linux/gpio_keys.h>
0015 #include <linux/input.h>
0016 #include <linux/platform_data/dsa.h>
0017 #include <asm/mach-types.h>
0018 #include <asm/mach/arch.h>
0019 #include <asm/mach/pci.h>
0020 #include "orion5x.h"
0021 #include "common.h"
0022 #include "mpp.h"
0023 
0024 /*
0025  * LEDs attached to GPIO
0026  */
0027 static struct gpio_led wrt350n_v2_led_pins[] = {
0028     {
0029         .name       = "wrt350nv2:green:power",
0030         .gpio       = 0,
0031         .active_low = 1,
0032     }, {
0033         .name       = "wrt350nv2:green:security",
0034         .gpio       = 1,
0035         .active_low = 1,
0036     }, {
0037         .name       = "wrt350nv2:orange:power",
0038         .gpio       = 5,
0039         .active_low = 1,
0040     }, {
0041         .name       = "wrt350nv2:green:usb",
0042         .gpio       = 6,
0043         .active_low = 1,
0044     }, {
0045         .name       = "wrt350nv2:green:wireless",
0046         .gpio       = 7,
0047         .active_low = 1,
0048     },
0049 };
0050 
0051 static struct gpio_led_platform_data wrt350n_v2_led_data = {
0052     .leds       = wrt350n_v2_led_pins,
0053     .num_leds   = ARRAY_SIZE(wrt350n_v2_led_pins),
0054 };
0055 
0056 static struct platform_device wrt350n_v2_leds = {
0057     .name   = "leds-gpio",
0058     .id = -1,
0059     .dev    = {
0060         .platform_data  = &wrt350n_v2_led_data,
0061     },
0062 };
0063 
0064 /*
0065  * Buttons attached to GPIO
0066  */
0067 static struct gpio_keys_button wrt350n_v2_buttons[] = {
0068     {
0069         .code       = KEY_RESTART,
0070         .gpio       = 3,
0071         .desc       = "Reset Button",
0072         .active_low = 1,
0073     }, {
0074         .code       = KEY_WPS_BUTTON,
0075         .gpio       = 2,
0076         .desc       = "WPS Button",
0077         .active_low = 1,
0078     },
0079 };
0080 
0081 static struct gpio_keys_platform_data wrt350n_v2_button_data = {
0082     .buttons    = wrt350n_v2_buttons,
0083     .nbuttons   = ARRAY_SIZE(wrt350n_v2_buttons),
0084 };
0085 
0086 static struct platform_device wrt350n_v2_button_device = {
0087     .name       = "gpio-keys",
0088     .id     = -1,
0089     .num_resources  = 0,
0090     .dev        = {
0091         .platform_data  = &wrt350n_v2_button_data,
0092     },
0093 };
0094 
0095 /*
0096  * General setup
0097  */
0098 static unsigned int wrt350n_v2_mpp_modes[] __initdata = {
0099     MPP0_GPIO,      /* Power LED green (0=on) */
0100     MPP1_GPIO,      /* Security LED (0=on) */
0101     MPP2_GPIO,      /* Internal Button (0=on) */
0102     MPP3_GPIO,      /* Reset Button (0=on) */
0103     MPP4_GPIO,      /* PCI int */
0104     MPP5_GPIO,      /* Power LED orange (0=on) */
0105     MPP6_GPIO,      /* USB LED (0=on) */
0106     MPP7_GPIO,      /* Wireless LED (0=on) */
0107     MPP8_UNUSED,        /* ??? */
0108     MPP9_GIGE,      /* GE_RXERR */
0109     MPP10_UNUSED,       /* ??? */
0110     MPP11_UNUSED,       /* ??? */
0111     MPP12_GIGE,     /* GE_TXD[4] */
0112     MPP13_GIGE,     /* GE_TXD[5] */
0113     MPP14_GIGE,     /* GE_TXD[6] */
0114     MPP15_GIGE,     /* GE_TXD[7] */
0115     MPP16_GIGE,     /* GE_RXD[4] */
0116     MPP17_GIGE,     /* GE_RXD[5] */
0117     MPP18_GIGE,     /* GE_RXD[6] */
0118     MPP19_GIGE,     /* GE_RXD[7] */
0119     0,
0120 };
0121 
0122 /*
0123  * 8M NOR flash Device bus boot chip select
0124  */
0125 #define WRT350N_V2_NOR_BOOT_BASE    0xf4000000
0126 #define WRT350N_V2_NOR_BOOT_SIZE    SZ_8M
0127 
0128 static struct mtd_partition wrt350n_v2_nor_flash_partitions[] = {
0129     {
0130         .name       = "kernel",
0131         .offset     = 0x00000000,
0132         .size       = 0x00760000,
0133     }, {
0134         .name       = "rootfs",
0135         .offset     = 0x001a0000,
0136         .size       = 0x005c0000,
0137     }, {
0138         .name       = "lang",
0139         .offset     = 0x00760000,
0140         .size       = 0x00040000,
0141     }, {
0142         .name       = "nvram",
0143         .offset     = 0x007a0000,
0144         .size       = 0x00020000,
0145     }, {
0146         .name       = "u-boot",
0147         .offset     = 0x007c0000,
0148         .size       = 0x00040000,
0149     },
0150 };
0151 
0152 static struct physmap_flash_data wrt350n_v2_nor_flash_data = {
0153     .width      = 1,
0154     .parts      = wrt350n_v2_nor_flash_partitions,
0155     .nr_parts   = ARRAY_SIZE(wrt350n_v2_nor_flash_partitions),
0156 };
0157 
0158 static struct resource wrt350n_v2_nor_flash_resource = {
0159     .flags      = IORESOURCE_MEM,
0160     .start      = WRT350N_V2_NOR_BOOT_BASE,
0161     .end        = WRT350N_V2_NOR_BOOT_BASE + WRT350N_V2_NOR_BOOT_SIZE - 1,
0162 };
0163 
0164 static struct platform_device wrt350n_v2_nor_flash = {
0165     .name           = "physmap-flash",
0166     .id         = 0,
0167     .dev        = {
0168         .platform_data  = &wrt350n_v2_nor_flash_data,
0169     },
0170     .num_resources      = 1,
0171     .resource       = &wrt350n_v2_nor_flash_resource,
0172 };
0173 
0174 static struct mv643xx_eth_platform_data wrt350n_v2_eth_data = {
0175     .phy_addr   = MV643XX_ETH_PHY_NONE,
0176     .speed      = SPEED_1000,
0177     .duplex     = DUPLEX_FULL,
0178 };
0179 
0180 static struct dsa_chip_data wrt350n_v2_switch_chip_data = {
0181     .port_names[0]  = "lan2",
0182     .port_names[1]  = "lan1",
0183     .port_names[2]  = "wan",
0184     .port_names[3]  = "cpu",
0185     .port_names[5]  = "lan3",
0186     .port_names[7]  = "lan4",
0187 };
0188 
0189 static void __init wrt350n_v2_init(void)
0190 {
0191     /*
0192      * Setup basic Orion functions. Need to be called early.
0193      */
0194     orion5x_init();
0195 
0196     orion5x_mpp_conf(wrt350n_v2_mpp_modes);
0197 
0198     /*
0199      * Configure peripherals.
0200      */
0201     orion5x_ehci0_init();
0202     orion5x_eth_init(&wrt350n_v2_eth_data);
0203     orion5x_eth_switch_init(&wrt350n_v2_switch_chip_data);
0204     orion5x_uart0_init();
0205 
0206     mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET,
0207                     ORION_MBUS_DEVBUS_BOOT_ATTR,
0208                     WRT350N_V2_NOR_BOOT_BASE,
0209                     WRT350N_V2_NOR_BOOT_SIZE);
0210     platform_device_register(&wrt350n_v2_nor_flash);
0211     platform_device_register(&wrt350n_v2_leds);
0212     platform_device_register(&wrt350n_v2_button_device);
0213 }
0214 
0215 static int __init wrt350n_v2_pci_map_irq(const struct pci_dev *dev, u8 slot,
0216     u8 pin)
0217 {
0218     int irq;
0219 
0220     /*
0221      * Check for devices with hard-wired IRQs.
0222      */
0223     irq = orion5x_pci_map_irq(dev, slot, pin);
0224     if (irq != -1)
0225         return irq;
0226 
0227     /*
0228      * Mini-PCI slot.
0229      */
0230     if (slot == 7)
0231         return gpio_to_irq(4);
0232 
0233     return -1;
0234 }
0235 
0236 static struct hw_pci wrt350n_v2_pci __initdata = {
0237     .nr_controllers = 2,
0238     .setup      = orion5x_pci_sys_setup,
0239     .scan       = orion5x_pci_sys_scan_bus,
0240     .map_irq    = wrt350n_v2_pci_map_irq,
0241 };
0242 
0243 static int __init wrt350n_v2_pci_init(void)
0244 {
0245     if (machine_is_wrt350n_v2())
0246         pci_common_init(&wrt350n_v2_pci);
0247 
0248     return 0;
0249 }
0250 subsys_initcall(wrt350n_v2_pci_init);
0251 
0252 MACHINE_START(WRT350N_V2, "Linksys WRT350N v2")
0253     /* Maintainer: Lennert Buytenhek <buytenh@marvell.com> */
0254     .atag_offset    = 0x100,
0255     .nr_irqs    = ORION5X_NR_IRQS,
0256     .init_machine   = wrt350n_v2_init,
0257     .map_io     = orion5x_map_io,
0258     .init_early = orion5x_init_early,
0259     .init_irq   = orion5x_init_irq,
0260     .init_time  = orion5x_timer_init,
0261     .fixup      = tag_fixup_mem32,
0262     .restart    = orion5x_restart,
0263 MACHINE_END