917357ec12fed6bbc81a39ceecd6270462b2a039
[librecmc/librecmc.git] / target / linux / ramips / files / arch / mips / ralink / rt305x / mach-nw718.c
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 static struct mtd_partition nw718_partitions[] = {
38         {
39                 .name   = "u-boot",
40                 .offset = 0,
41                 .size   = 0x030000,
42                 .mask_flags = MTD_WRITEABLE,
43         }, {
44                 .name   = "config",
45                 .offset = 0x030000,
46                 .size   = 0x020000,
47                 .mask_flags = MTD_WRITEABLE,
48         }, {
49                 .name   = "factory",
50                 .offset = 0x050000,
51                 .size   = 0x010000,
52                 .mask_flags = MTD_WRITEABLE,
53         }, {
54                 .name   = "kernel",
55                 .offset = 0x060000,
56                 .size   = 0x090000,
57         }, {
58                 .name   = "rootfs",
59                 .offset = 0x150000,
60                 .size   = 0x2b0000,
61         }, {
62                 .name   = "firmware",
63                 .offset = 0x060000,
64                 .size   = 0x3a0000,
65         }
66 };
67
68 static struct flash_platform_data nw718_flash_data = {
69         .nr_parts       = ARRAY_SIZE(nw718_partitions),
70         .parts          = nw718_partitions,
71 };
72
73 static struct gpio_led nw718_leds_gpio[] __initdata = {
74         {
75                 .name           = "nw718:amber:cpu",
76                 .gpio           = NW718_GPIO_LED_CPU,
77                 .active_low     = 1,
78         }, {
79                 .name           = "nw718:amber:usb",
80                 .gpio           = NW718_GPIO_LED_USB,
81                 .active_low     = 1,
82         }, {
83                 .name           = "nw718:amber:wps",
84                 .gpio           = NW718_GPIO_LED_WPS,
85                 .active_low     = 1,
86         }
87 };
88
89 static struct gpio_button nw718_gpio_buttons[] __initdata = {
90         {
91                 .desc           = "reset",
92                 .type           = EV_KEY,
93                 .code           = KEY_RESTART,
94                 .threshold      = 3,
95                 .gpio           = NW718_GPIO_BUTTON_RESET,
96                 .active_low     = 1,
97         }, {
98                 .desc           = "wps",
99                 .type           = EV_KEY,
100                 .code           = KEY_WPS_BUTTON,
101                 .threshold      = 3,
102                 .gpio           = NW718_GPIO_BUTTON_WPS,
103                 .active_low     = 1,
104         }
105 };
106
107 static struct spi_board_info nw718_spi_info[] = {
108         {
109                 .bus_num        = 0,
110                 .chip_select    = 0,
111                 .max_speed_hz   = 25000000,
112                 .modalias       = "m25p80",
113                 .platform_data  = &nw718_flash_data,
114                 .controller_data = (void *) NW718_GPIO_SPI_CS0,
115         }
116 };
117
118 static void __init nw718_init(void)
119 {
120         rt305x_gpio_init(RT305X_GPIO_MODE_I2C |
121                          RT305X_GPIO_MODE_GPIO << RT305X_GPIO_MODE_UART0_SHIFT);
122
123         rt305x_esw_data.vlan_config = RT305X_ESW_VLAN_CONFIG_LLLLW;
124         rt305x_register_ethernet();
125         ramips_register_gpio_leds(-1, ARRAY_SIZE(nw718_leds_gpio),
126                                   nw718_leds_gpio);
127         ramips_register_gpio_buttons(-1, NW718_BUTTONS_POLL_INTERVAL,
128                                      ARRAY_SIZE(nw718_gpio_buttons),
129                                      nw718_gpio_buttons);
130         rt305x_register_wifi();
131         rt305x_register_wdt();
132         rt305x_register_spi(nw718_spi_info, ARRAY_SIZE(nw718_spi_info));
133         rt305x_register_usb();
134 }
135
136 MIPS_MACHINE(RAMIPS_MACH_WHR_G300N, "NW718", "Netcore NW718", nw718_init);