18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * arch/arm/mach-orion5x/wrt350n-v2-setup.c
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This file is licensed under the terms of the GNU General Public
58c2ecf20Sopenharmony_ci * License version 2.  This program is licensed "as is" without any
68c2ecf20Sopenharmony_ci * warranty of any kind, whether express or implied.
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci#include <linux/gpio.h>
98c2ecf20Sopenharmony_ci#include <linux/kernel.h>
108c2ecf20Sopenharmony_ci#include <linux/init.h>
118c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
128c2ecf20Sopenharmony_ci#include <linux/pci.h>
138c2ecf20Sopenharmony_ci#include <linux/irq.h>
148c2ecf20Sopenharmony_ci#include <linux/delay.h>
158c2ecf20Sopenharmony_ci#include <linux/mtd/physmap.h>
168c2ecf20Sopenharmony_ci#include <linux/mv643xx_eth.h>
178c2ecf20Sopenharmony_ci#include <linux/ethtool.h>
188c2ecf20Sopenharmony_ci#include <linux/leds.h>
198c2ecf20Sopenharmony_ci#include <linux/gpio_keys.h>
208c2ecf20Sopenharmony_ci#include <linux/input.h>
218c2ecf20Sopenharmony_ci#include <linux/platform_data/dsa.h>
228c2ecf20Sopenharmony_ci#include <asm/mach-types.h>
238c2ecf20Sopenharmony_ci#include <asm/mach/arch.h>
248c2ecf20Sopenharmony_ci#include <asm/mach/pci.h>
258c2ecf20Sopenharmony_ci#include "orion5x.h"
268c2ecf20Sopenharmony_ci#include "common.h"
278c2ecf20Sopenharmony_ci#include "mpp.h"
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci/*
308c2ecf20Sopenharmony_ci * LEDs attached to GPIO
318c2ecf20Sopenharmony_ci */
328c2ecf20Sopenharmony_cistatic struct gpio_led wrt350n_v2_led_pins[] = {
338c2ecf20Sopenharmony_ci	{
348c2ecf20Sopenharmony_ci		.name		= "wrt350nv2:green:power",
358c2ecf20Sopenharmony_ci		.gpio		= 0,
368c2ecf20Sopenharmony_ci		.active_low	= 1,
378c2ecf20Sopenharmony_ci	}, {
388c2ecf20Sopenharmony_ci		.name		= "wrt350nv2:green:security",
398c2ecf20Sopenharmony_ci		.gpio		= 1,
408c2ecf20Sopenharmony_ci		.active_low	= 1,
418c2ecf20Sopenharmony_ci	}, {
428c2ecf20Sopenharmony_ci		.name		= "wrt350nv2:orange:power",
438c2ecf20Sopenharmony_ci		.gpio		= 5,
448c2ecf20Sopenharmony_ci		.active_low	= 1,
458c2ecf20Sopenharmony_ci	}, {
468c2ecf20Sopenharmony_ci		.name		= "wrt350nv2:green:usb",
478c2ecf20Sopenharmony_ci		.gpio		= 6,
488c2ecf20Sopenharmony_ci		.active_low	= 1,
498c2ecf20Sopenharmony_ci	}, {
508c2ecf20Sopenharmony_ci		.name		= "wrt350nv2:green:wireless",
518c2ecf20Sopenharmony_ci		.gpio		= 7,
528c2ecf20Sopenharmony_ci		.active_low	= 1,
538c2ecf20Sopenharmony_ci	},
548c2ecf20Sopenharmony_ci};
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistatic struct gpio_led_platform_data wrt350n_v2_led_data = {
578c2ecf20Sopenharmony_ci	.leds		= wrt350n_v2_led_pins,
588c2ecf20Sopenharmony_ci	.num_leds	= ARRAY_SIZE(wrt350n_v2_led_pins),
598c2ecf20Sopenharmony_ci};
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_cistatic struct platform_device wrt350n_v2_leds = {
628c2ecf20Sopenharmony_ci	.name	= "leds-gpio",
638c2ecf20Sopenharmony_ci	.id	= -1,
648c2ecf20Sopenharmony_ci	.dev	= {
658c2ecf20Sopenharmony_ci		.platform_data	= &wrt350n_v2_led_data,
668c2ecf20Sopenharmony_ci	},
678c2ecf20Sopenharmony_ci};
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/*
708c2ecf20Sopenharmony_ci * Buttons attached to GPIO
718c2ecf20Sopenharmony_ci */
728c2ecf20Sopenharmony_cistatic struct gpio_keys_button wrt350n_v2_buttons[] = {
738c2ecf20Sopenharmony_ci	{
748c2ecf20Sopenharmony_ci		.code		= KEY_RESTART,
758c2ecf20Sopenharmony_ci		.gpio		= 3,
768c2ecf20Sopenharmony_ci		.desc		= "Reset Button",
778c2ecf20Sopenharmony_ci		.active_low	= 1,
788c2ecf20Sopenharmony_ci	}, {
798c2ecf20Sopenharmony_ci		.code		= KEY_WPS_BUTTON,
808c2ecf20Sopenharmony_ci		.gpio		= 2,
818c2ecf20Sopenharmony_ci		.desc		= "WPS Button",
828c2ecf20Sopenharmony_ci		.active_low	= 1,
838c2ecf20Sopenharmony_ci	},
848c2ecf20Sopenharmony_ci};
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_cistatic struct gpio_keys_platform_data wrt350n_v2_button_data = {
878c2ecf20Sopenharmony_ci	.buttons	= wrt350n_v2_buttons,
888c2ecf20Sopenharmony_ci	.nbuttons	= ARRAY_SIZE(wrt350n_v2_buttons),
898c2ecf20Sopenharmony_ci};
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_cistatic struct platform_device wrt350n_v2_button_device = {
928c2ecf20Sopenharmony_ci	.name		= "gpio-keys",
938c2ecf20Sopenharmony_ci	.id		= -1,
948c2ecf20Sopenharmony_ci	.num_resources	= 0,
958c2ecf20Sopenharmony_ci	.dev		= {
968c2ecf20Sopenharmony_ci		.platform_data	= &wrt350n_v2_button_data,
978c2ecf20Sopenharmony_ci	},
988c2ecf20Sopenharmony_ci};
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci/*
1018c2ecf20Sopenharmony_ci * General setup
1028c2ecf20Sopenharmony_ci */
1038c2ecf20Sopenharmony_cistatic unsigned int wrt350n_v2_mpp_modes[] __initdata = {
1048c2ecf20Sopenharmony_ci	MPP0_GPIO,		/* Power LED green (0=on) */
1058c2ecf20Sopenharmony_ci	MPP1_GPIO,		/* Security LED (0=on) */
1068c2ecf20Sopenharmony_ci	MPP2_GPIO,		/* Internal Button (0=on) */
1078c2ecf20Sopenharmony_ci	MPP3_GPIO,		/* Reset Button (0=on) */
1088c2ecf20Sopenharmony_ci	MPP4_GPIO,		/* PCI int */
1098c2ecf20Sopenharmony_ci	MPP5_GPIO,		/* Power LED orange (0=on) */
1108c2ecf20Sopenharmony_ci	MPP6_GPIO,		/* USB LED (0=on) */
1118c2ecf20Sopenharmony_ci	MPP7_GPIO,		/* Wireless LED (0=on) */
1128c2ecf20Sopenharmony_ci	MPP8_UNUSED,		/* ??? */
1138c2ecf20Sopenharmony_ci	MPP9_GIGE,		/* GE_RXERR */
1148c2ecf20Sopenharmony_ci	MPP10_UNUSED,		/* ??? */
1158c2ecf20Sopenharmony_ci	MPP11_UNUSED,		/* ??? */
1168c2ecf20Sopenharmony_ci	MPP12_GIGE,		/* GE_TXD[4] */
1178c2ecf20Sopenharmony_ci	MPP13_GIGE,		/* GE_TXD[5] */
1188c2ecf20Sopenharmony_ci	MPP14_GIGE,		/* GE_TXD[6] */
1198c2ecf20Sopenharmony_ci	MPP15_GIGE,		/* GE_TXD[7] */
1208c2ecf20Sopenharmony_ci	MPP16_GIGE,		/* GE_RXD[4] */
1218c2ecf20Sopenharmony_ci	MPP17_GIGE,		/* GE_RXD[5] */
1228c2ecf20Sopenharmony_ci	MPP18_GIGE,		/* GE_RXD[6] */
1238c2ecf20Sopenharmony_ci	MPP19_GIGE,		/* GE_RXD[7] */
1248c2ecf20Sopenharmony_ci	0,
1258c2ecf20Sopenharmony_ci};
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci/*
1288c2ecf20Sopenharmony_ci * 8M NOR flash Device bus boot chip select
1298c2ecf20Sopenharmony_ci */
1308c2ecf20Sopenharmony_ci#define WRT350N_V2_NOR_BOOT_BASE	0xf4000000
1318c2ecf20Sopenharmony_ci#define WRT350N_V2_NOR_BOOT_SIZE	SZ_8M
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_cistatic struct mtd_partition wrt350n_v2_nor_flash_partitions[] = {
1348c2ecf20Sopenharmony_ci	{
1358c2ecf20Sopenharmony_ci		.name		= "kernel",
1368c2ecf20Sopenharmony_ci		.offset		= 0x00000000,
1378c2ecf20Sopenharmony_ci		.size		= 0x00760000,
1388c2ecf20Sopenharmony_ci	}, {
1398c2ecf20Sopenharmony_ci		.name		= "rootfs",
1408c2ecf20Sopenharmony_ci		.offset		= 0x001a0000,
1418c2ecf20Sopenharmony_ci		.size		= 0x005c0000,
1428c2ecf20Sopenharmony_ci	}, {
1438c2ecf20Sopenharmony_ci		.name		= "lang",
1448c2ecf20Sopenharmony_ci		.offset		= 0x00760000,
1458c2ecf20Sopenharmony_ci		.size		= 0x00040000,
1468c2ecf20Sopenharmony_ci	}, {
1478c2ecf20Sopenharmony_ci		.name		= "nvram",
1488c2ecf20Sopenharmony_ci		.offset		= 0x007a0000,
1498c2ecf20Sopenharmony_ci		.size		= 0x00020000,
1508c2ecf20Sopenharmony_ci	}, {
1518c2ecf20Sopenharmony_ci		.name		= "u-boot",
1528c2ecf20Sopenharmony_ci		.offset		= 0x007c0000,
1538c2ecf20Sopenharmony_ci		.size		= 0x00040000,
1548c2ecf20Sopenharmony_ci	},
1558c2ecf20Sopenharmony_ci};
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_cistatic struct physmap_flash_data wrt350n_v2_nor_flash_data = {
1588c2ecf20Sopenharmony_ci	.width		= 1,
1598c2ecf20Sopenharmony_ci	.parts		= wrt350n_v2_nor_flash_partitions,
1608c2ecf20Sopenharmony_ci	.nr_parts	= ARRAY_SIZE(wrt350n_v2_nor_flash_partitions),
1618c2ecf20Sopenharmony_ci};
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_cistatic struct resource wrt350n_v2_nor_flash_resource = {
1648c2ecf20Sopenharmony_ci	.flags		= IORESOURCE_MEM,
1658c2ecf20Sopenharmony_ci	.start		= WRT350N_V2_NOR_BOOT_BASE,
1668c2ecf20Sopenharmony_ci	.end		= WRT350N_V2_NOR_BOOT_BASE + WRT350N_V2_NOR_BOOT_SIZE - 1,
1678c2ecf20Sopenharmony_ci};
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_cistatic struct platform_device wrt350n_v2_nor_flash = {
1708c2ecf20Sopenharmony_ci	.name			= "physmap-flash",
1718c2ecf20Sopenharmony_ci	.id			= 0,
1728c2ecf20Sopenharmony_ci	.dev		= {
1738c2ecf20Sopenharmony_ci		.platform_data	= &wrt350n_v2_nor_flash_data,
1748c2ecf20Sopenharmony_ci	},
1758c2ecf20Sopenharmony_ci	.num_resources		= 1,
1768c2ecf20Sopenharmony_ci	.resource		= &wrt350n_v2_nor_flash_resource,
1778c2ecf20Sopenharmony_ci};
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_cistatic struct mv643xx_eth_platform_data wrt350n_v2_eth_data = {
1808c2ecf20Sopenharmony_ci	.phy_addr	= MV643XX_ETH_PHY_NONE,
1818c2ecf20Sopenharmony_ci	.speed		= SPEED_1000,
1828c2ecf20Sopenharmony_ci	.duplex		= DUPLEX_FULL,
1838c2ecf20Sopenharmony_ci};
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_cistatic struct dsa_chip_data wrt350n_v2_switch_chip_data = {
1868c2ecf20Sopenharmony_ci	.port_names[0]	= "lan2",
1878c2ecf20Sopenharmony_ci	.port_names[1]	= "lan1",
1888c2ecf20Sopenharmony_ci	.port_names[2]	= "wan",
1898c2ecf20Sopenharmony_ci	.port_names[3]	= "cpu",
1908c2ecf20Sopenharmony_ci	.port_names[5]	= "lan3",
1918c2ecf20Sopenharmony_ci	.port_names[7]	= "lan4",
1928c2ecf20Sopenharmony_ci};
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_cistatic void __init wrt350n_v2_init(void)
1958c2ecf20Sopenharmony_ci{
1968c2ecf20Sopenharmony_ci	/*
1978c2ecf20Sopenharmony_ci	 * Setup basic Orion functions. Need to be called early.
1988c2ecf20Sopenharmony_ci	 */
1998c2ecf20Sopenharmony_ci	orion5x_init();
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci	orion5x_mpp_conf(wrt350n_v2_mpp_modes);
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci	/*
2048c2ecf20Sopenharmony_ci	 * Configure peripherals.
2058c2ecf20Sopenharmony_ci	 */
2068c2ecf20Sopenharmony_ci	orion5x_ehci0_init();
2078c2ecf20Sopenharmony_ci	orion5x_eth_init(&wrt350n_v2_eth_data);
2088c2ecf20Sopenharmony_ci	orion5x_eth_switch_init(&wrt350n_v2_switch_chip_data);
2098c2ecf20Sopenharmony_ci	orion5x_uart0_init();
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci	mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET,
2128c2ecf20Sopenharmony_ci				    ORION_MBUS_DEVBUS_BOOT_ATTR,
2138c2ecf20Sopenharmony_ci				    WRT350N_V2_NOR_BOOT_BASE,
2148c2ecf20Sopenharmony_ci				    WRT350N_V2_NOR_BOOT_SIZE);
2158c2ecf20Sopenharmony_ci	platform_device_register(&wrt350n_v2_nor_flash);
2168c2ecf20Sopenharmony_ci	platform_device_register(&wrt350n_v2_leds);
2178c2ecf20Sopenharmony_ci	platform_device_register(&wrt350n_v2_button_device);
2188c2ecf20Sopenharmony_ci}
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_cistatic int __init wrt350n_v2_pci_map_irq(const struct pci_dev *dev, u8 slot,
2218c2ecf20Sopenharmony_ci	u8 pin)
2228c2ecf20Sopenharmony_ci{
2238c2ecf20Sopenharmony_ci	int irq;
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci	/*
2268c2ecf20Sopenharmony_ci	 * Check for devices with hard-wired IRQs.
2278c2ecf20Sopenharmony_ci	 */
2288c2ecf20Sopenharmony_ci	irq = orion5x_pci_map_irq(dev, slot, pin);
2298c2ecf20Sopenharmony_ci	if (irq != -1)
2308c2ecf20Sopenharmony_ci		return irq;
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci	/*
2338c2ecf20Sopenharmony_ci	 * Mini-PCI slot.
2348c2ecf20Sopenharmony_ci	 */
2358c2ecf20Sopenharmony_ci	if (slot == 7)
2368c2ecf20Sopenharmony_ci		return gpio_to_irq(4);
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci	return -1;
2398c2ecf20Sopenharmony_ci}
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_cistatic struct hw_pci wrt350n_v2_pci __initdata = {
2428c2ecf20Sopenharmony_ci	.nr_controllers	= 2,
2438c2ecf20Sopenharmony_ci	.setup		= orion5x_pci_sys_setup,
2448c2ecf20Sopenharmony_ci	.scan		= orion5x_pci_sys_scan_bus,
2458c2ecf20Sopenharmony_ci	.map_irq	= wrt350n_v2_pci_map_irq,
2468c2ecf20Sopenharmony_ci};
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_cistatic int __init wrt350n_v2_pci_init(void)
2498c2ecf20Sopenharmony_ci{
2508c2ecf20Sopenharmony_ci	if (machine_is_wrt350n_v2())
2518c2ecf20Sopenharmony_ci		pci_common_init(&wrt350n_v2_pci);
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci	return 0;
2548c2ecf20Sopenharmony_ci}
2558c2ecf20Sopenharmony_cisubsys_initcall(wrt350n_v2_pci_init);
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ciMACHINE_START(WRT350N_V2, "Linksys WRT350N v2")
2588c2ecf20Sopenharmony_ci	/* Maintainer: Lennert Buytenhek <buytenh@marvell.com> */
2598c2ecf20Sopenharmony_ci	.atag_offset	= 0x100,
2608c2ecf20Sopenharmony_ci	.nr_irqs	= ORION5X_NR_IRQS,
2618c2ecf20Sopenharmony_ci	.init_machine	= wrt350n_v2_init,
2628c2ecf20Sopenharmony_ci	.map_io		= orion5x_map_io,
2638c2ecf20Sopenharmony_ci	.init_early	= orion5x_init_early,
2648c2ecf20Sopenharmony_ci	.init_irq	= orion5x_init_irq,
2658c2ecf20Sopenharmony_ci	.init_time	= orion5x_timer_init,
2668c2ecf20Sopenharmony_ci	.fixup		= tag_fixup_mem32,
2678c2ecf20Sopenharmony_ci	.restart	= orion5x_restart,
2688c2ecf20Sopenharmony_ciMACHINE_END
269