| 1 | /* |
| 2 | * Netcore NW718 board support |
| 3 | * |
| 4 | * Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License version 2 as published |
| 8 | * by the Free Software Foundation. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/platform_device.h> |
| 13 | #include <linux/mtd/mtd.h> |
| 14 | #include <linux/mtd/partitions.h> |
| 15 | #include <linux/spi/spi.h> |
| 16 | #include <linux/spi/flash.h> |
| 17 | |
| 18 | #include <asm/mach-ralink/machine.h> |
| 19 | #include <asm/mach-ralink/dev-gpio-buttons.h> |
| 20 | #include <asm/mach-ralink/dev-gpio-leds.h> |
| 21 | #include <asm/mach-ralink/rt305x.h> |
| 22 | #include <asm/mach-ralink/rt305x_regs.h> |
| 23 | |
| 24 | #include "devices.h" |
| 25 | |
| 26 | #define NW718_GPIO_LED_USB 8 |
| 27 | #define NW718_GPIO_LED_CPU 13 |
| 28 | #define NW718_GPIO_LED_WPS 14 |
| 29 | |
| 30 | #define NW718_GPIO_BUTTON_WPS 0 |
| 31 | #define NW718_GPIO_BUTTON_RESET 10 |
| 32 | |
| 33 | #define NW718_GPIO_SPI_CS0 3 |
| 34 | |
| 35 | #define NW718_BUTTONS_POLL_INTERVAL 20 |
| 36 | |
| 37 | #ifdef CONFIG_MTD_PARTITIONS |
| 38 | static struct mtd_partition nw718_partitions[] = { |
| 39 | { |
| 40 | .name = "u-boot", |
| 41 | .offset = 0, |
| 42 | .size = 0x030000, |
| 43 | .mask_flags = MTD_WRITEABLE, |
| 44 | }, { |
| 45 | .name = "config", |
| 46 | .offset = 0x030000, |
| 47 | .size = 0x020000, |
| 48 | .mask_flags = MTD_WRITEABLE, |
| 49 | }, { |
| 50 | .name = "factory", |
| 51 | .offset = 0x050000, |
| 52 | .size = 0x010000, |
| 53 | .mask_flags = MTD_WRITEABLE, |
| 54 | }, { |
| 55 | .name = "kernel", |
| 56 | .offset = 0x060000, |
| 57 | .size = 0x090000, |
| 58 | }, { |
| 59 | .name = "rootfs", |
| 60 | .offset = 0x150000, |
| 61 | .size = 0x2b0000, |
| 62 | }, { |
| 63 | .name = "firmware", |
| 64 | .offset = 0x060000, |
| 65 | .size = 0x3a0000, |
| 66 | } |
| 67 | }; |
| 68 | #define nw718_nr_parts ARRAY_SIZE(nw718_partitions) |
| 69 | #else |
| 70 | #define nw718_nr_parts 0 |
| 71 | #define nw718_partitions NULL |
| 72 | #endif /* CONFIG_MTD_PARTITIONS */ |
| 73 | |
| 74 | static struct flash_platform_data nw718_flash_data = { |
| 75 | .nr_parts = nw718_nr_parts, |
| 76 | .parts = nw718_partitions, |
| 77 | }; |
| 78 | |
| 79 | static struct gpio_led nw718_leds_gpio[] __initdata = { |
| 80 | { |
| 81 | .name = "nw718:amber:cpu", |
| 82 | .gpio = NW718_GPIO_LED_CPU, |
| 83 | .active_low = 1, |
| 84 | }, { |
| 85 | .name = "nw718:amber:usb", |
| 86 | .gpio = NW718_GPIO_LED_USB, |
| 87 | .active_low = 1, |
| 88 | }, { |
| 89 | .name = "nw718:amber:wps", |
| 90 | .gpio = NW718_GPIO_LED_WPS, |
| 91 | .active_low = 1, |
| 92 | } |
| 93 | }; |
| 94 | |
| 95 | static struct gpio_button nw718_gpio_buttons[] __initdata = { |
| 96 | { |
| 97 | .desc = "reset", |
| 98 | .type = EV_KEY, |
| 99 | .code = KEY_RESTART, |
| 100 | .threshold = 3, |
| 101 | .gpio = NW718_GPIO_BUTTON_RESET, |
| 102 | .active_low = 1, |
| 103 | }, { |
| 104 | .desc = "wps", |
| 105 | .type = EV_KEY, |
| 106 | .code = KEY_WPS_BUTTON, |
| 107 | .threshold = 3, |
| 108 | .gpio = NW718_GPIO_BUTTON_WPS, |
| 109 | .active_low = 1, |
| 110 | } |
| 111 | }; |
| 112 | |
| 113 | static struct spi_board_info nw718_spi_info[] = { |
| 114 | { |
| 115 | .bus_num = 0, |
| 116 | .chip_select = 0, |
| 117 | .max_speed_hz = 25000000, |
| 118 | .modalias = "m25p80", |
| 119 | .platform_data = &nw718_flash_data, |
| 120 | .controller_data = (void *) NW718_GPIO_SPI_CS0, |
| 121 | } |
| 122 | }; |
| 123 | |
| 124 | static void __init nw718_init(void) |
| 125 | { |
| 126 | rt305x_gpio_init(RT305X_GPIO_MODE_I2C | |
| 127 | RT305X_GPIO_MODE_GPIO << RT305X_GPIO_MODE_UART0_SHIFT); |
| 128 | |
| 129 | rt305x_esw_data.vlan_config = RT305X_ESW_VLAN_CONFIG_LLLLW; |
| 130 | rt305x_register_ethernet(); |
| 131 | ramips_register_gpio_leds(-1, ARRAY_SIZE(nw718_leds_gpio), |
| 132 | nw718_leds_gpio); |
| 133 | ramips_register_gpio_buttons(-1, NW718_BUTTONS_POLL_INTERVAL, |
| 134 | ARRAY_SIZE(nw718_gpio_buttons), |
| 135 | nw718_gpio_buttons); |
| 136 | rt305x_register_wifi(); |
| 137 | rt305x_register_wdt(); |
| 138 | rt305x_register_spi(nw718_spi_info, ARRAY_SIZE(nw718_spi_info)); |
| 139 | rt305x_register_usb(); |
| 140 | } |
| 141 | |
| 142 | MIPS_MACHINE(RAMIPS_MACH_WHR_G300N, "NW718", "Netcore NW718", nw718_init); |
| 143 | |