| 1 | /* |
| 2 | * Buffalo WZR-HP-G300NH board support |
| 3 | * |
| 4 | * Copyright (C) 2010 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/platform_device.h> |
| 12 | #include <linux/mtd/mtd.h> |
| 13 | #include <linux/mtd/partitions.h> |
| 14 | #include <linux/nxp_74hc153.h> |
| 15 | #include <linux/rtl8366s.h> |
| 16 | #include <linux/rtl8366rb.h> |
| 17 | |
| 18 | #include <asm/mips_machine.h> |
| 19 | #include <asm/mach-ar71xx/ar71xx.h> |
| 20 | #include <asm/mach-ar71xx/ar91xx_flash.h> |
| 21 | |
| 22 | #include "machtype.h" |
| 23 | #include "devices.h" |
| 24 | #include "dev-ar9xxx-wmac.h" |
| 25 | #include "dev-gpio-buttons.h" |
| 26 | #include "dev-leds-gpio.h" |
| 27 | #include "dev-usb.h" |
| 28 | |
| 29 | #define WZRHPG300NH_GPIO_LED_USB 0 |
| 30 | #define WZRHPG300NH_GPIO_LED_DIAG 1 |
| 31 | #define WZRHPG300NH_GPIO_LED_WIRELESS 6 |
| 32 | #define WZRHPG300NH_GPIO_LED_SECURITY 17 |
| 33 | #define WZRHPG300NH_GPIO_LED_ROUTER 18 |
| 34 | |
| 35 | #define WZRHPG300NH_GPIO_RTL8366_SDA 19 |
| 36 | #define WZRHPG300NH_GPIO_RTL8366_SCK 20 |
| 37 | |
| 38 | #define WZRHPG300NH_GPIO_74HC153_S0 9 |
| 39 | #define WZRHPG300NH_GPIO_74HC153_S1 11 |
| 40 | #define WZRHPG300NH_GPIO_74HC153_1Y 12 |
| 41 | #define WZRHPG300NH_GPIO_74HC153_2Y 14 |
| 42 | |
| 43 | #define WZRHPG300NH_GPIO_EXP_BASE 32 |
| 44 | #define WZRHPG300NH_GPIO_BTN_AOSS (WZRHPG300NH_GPIO_EXP_BASE + 0) |
| 45 | #define WZRHPG300NH_GPIO_BTN_RESET (WZRHPG300NH_GPIO_EXP_BASE + 1) |
| 46 | #define WZRHPG300NH_GPIO_BTN_ROUTER_ON (WZRHPG300NH_GPIO_EXP_BASE + 2) |
| 47 | #define WZRHPG300NH_GPIO_BTN_QOS_ON (WZRHPG300NH_GPIO_EXP_BASE + 3) |
| 48 | #define WZRHPG300NH_GPIO_BTN_USB (WZRHPG300NH_GPIO_EXP_BASE + 5) |
| 49 | #define WZRHPG300NH_GPIO_BTN_ROUTER_AUTO (WZRHPG300NH_GPIO_EXP_BASE + 6) |
| 50 | #define WZRHPG300NH_GPIO_BTN_QOS_OFF (WZRHPG300NH_GPIO_EXP_BASE + 7) |
| 51 | |
| 52 | #define WZRHPG300NH_KEYS_POLL_INTERVAL 20 /* msecs */ |
| 53 | #define WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL (3 * WZRHPG300NH_KEYS_POLL_INTERVAL) |
| 54 | |
| 55 | #define WZRHPG300NH_MAC_OFFSET 0x20c |
| 56 | |
| 57 | #ifdef CONFIG_MTD_PARTITIONS |
| 58 | static struct mtd_partition wzrhpg300nh_flash_partitions[] = { |
| 59 | { |
| 60 | .name = "u-boot", |
| 61 | .offset = 0, |
| 62 | .size = 0x0040000, |
| 63 | .mask_flags = MTD_WRITEABLE, |
| 64 | }, { |
| 65 | .name = "u-boot-env", |
| 66 | .offset = 0x0040000, |
| 67 | .size = 0x0020000, |
| 68 | .mask_flags = MTD_WRITEABLE, |
| 69 | }, { |
| 70 | .name = "kernel", |
| 71 | .offset = 0x0060000, |
| 72 | .size = 0x0100000, |
| 73 | }, { |
| 74 | .name = "rootfs", |
| 75 | .offset = 0x0160000, |
| 76 | .size = 0x1e60000, |
| 77 | }, { |
| 78 | .name = "user_property", |
| 79 | .offset = 0x1fc0000, |
| 80 | .size = 0x0020000, |
| 81 | .mask_flags = MTD_WRITEABLE, |
| 82 | }, { |
| 83 | .name = "art", |
| 84 | .offset = 0x1fe0000, |
| 85 | .size = 0x0020000, |
| 86 | .mask_flags = MTD_WRITEABLE, |
| 87 | }, { |
| 88 | .name = "firmware", |
| 89 | .offset = 0x0060000, |
| 90 | .size = 0x1f60000, |
| 91 | } |
| 92 | }; |
| 93 | #endif /* CONFIG_MTD_PARTITIONS */ |
| 94 | |
| 95 | static struct ar91xx_flash_platform_data wzrhpg300nh_flash_data = { |
| 96 | .width = 2, |
| 97 | #ifdef CONFIG_MTD_PARTITIONS |
| 98 | .parts = wzrhpg300nh_flash_partitions, |
| 99 | .nr_parts = ARRAY_SIZE(wzrhpg300nh_flash_partitions), |
| 100 | #endif |
| 101 | }; |
| 102 | |
| 103 | #define WZRHPG300NH_FLASH_BASE 0x1e000000 |
| 104 | #define WZRHPG300NH_FLASH_SIZE (32 * 1024 * 1024) |
| 105 | |
| 106 | static struct resource wzrhpg300nh_flash_resources[] = { |
| 107 | [0] = { |
| 108 | .start = WZRHPG300NH_FLASH_BASE, |
| 109 | .end = WZRHPG300NH_FLASH_BASE + WZRHPG300NH_FLASH_SIZE - 1, |
| 110 | .flags = IORESOURCE_MEM, |
| 111 | }, |
| 112 | }; |
| 113 | |
| 114 | static struct platform_device wzrhpg300nh_flash_device = { |
| 115 | .name = "ar91xx-flash", |
| 116 | .id = -1, |
| 117 | .resource = wzrhpg300nh_flash_resources, |
| 118 | .num_resources = ARRAY_SIZE(wzrhpg300nh_flash_resources), |
| 119 | .dev = { |
| 120 | .platform_data = &wzrhpg300nh_flash_data, |
| 121 | } |
| 122 | }; |
| 123 | |
| 124 | static struct gpio_led wzrhpg300nh_leds_gpio[] __initdata = { |
| 125 | { |
| 126 | .name = "wzr-hp-g300nh:orange:security", |
| 127 | .gpio = WZRHPG300NH_GPIO_LED_SECURITY, |
| 128 | .active_low = 1, |
| 129 | }, { |
| 130 | .name = "wzr-hp-g300nh:green:wireless", |
| 131 | .gpio = WZRHPG300NH_GPIO_LED_WIRELESS, |
| 132 | .active_low = 1, |
| 133 | }, { |
| 134 | .name = "wzr-hp-g300nh:green:router", |
| 135 | .gpio = WZRHPG300NH_GPIO_LED_ROUTER, |
| 136 | .active_low = 1, |
| 137 | }, { |
| 138 | .name = "wzr-hp-g300nh:red:diag", |
| 139 | .gpio = WZRHPG300NH_GPIO_LED_DIAG, |
| 140 | .active_low = 1, |
| 141 | }, { |
| 142 | .name = "wzr-hp-g300nh:blue:usb", |
| 143 | .gpio = WZRHPG300NH_GPIO_LED_USB, |
| 144 | .active_low = 1, |
| 145 | } |
| 146 | }; |
| 147 | |
| 148 | static struct gpio_keys_button wzrhpg300nh_gpio_keys[] __initdata = { |
| 149 | { |
| 150 | .desc = "reset", |
| 151 | .type = EV_KEY, |
| 152 | .code = KEY_RESTART, |
| 153 | .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL, |
| 154 | .gpio = WZRHPG300NH_GPIO_BTN_RESET, |
| 155 | .active_low = 1, |
| 156 | }, { |
| 157 | .desc = "aoss", |
| 158 | .type = EV_KEY, |
| 159 | .code = KEY_WPS_BUTTON, |
| 160 | .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL, |
| 161 | .gpio = WZRHPG300NH_GPIO_BTN_AOSS, |
| 162 | .active_low = 1, |
| 163 | }, { |
| 164 | .desc = "usb", |
| 165 | .type = EV_KEY, |
| 166 | .code = BTN_2, |
| 167 | .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL, |
| 168 | .gpio = WZRHPG300NH_GPIO_BTN_USB, |
| 169 | .active_low = 1, |
| 170 | }, { |
| 171 | .desc = "qos_on", |
| 172 | .type = EV_KEY, |
| 173 | .code = BTN_3, |
| 174 | .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL, |
| 175 | .gpio = WZRHPG300NH_GPIO_BTN_QOS_ON, |
| 176 | .active_low = 0, |
| 177 | }, { |
| 178 | .desc = "qos_off", |
| 179 | .type = EV_KEY, |
| 180 | .code = BTN_4, |
| 181 | .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL, |
| 182 | .gpio = WZRHPG300NH_GPIO_BTN_QOS_OFF, |
| 183 | .active_low = 0, |
| 184 | }, { |
| 185 | .desc = "router_on", |
| 186 | .type = EV_KEY, |
| 187 | .code = BTN_5, |
| 188 | .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL, |
| 189 | .gpio = WZRHPG300NH_GPIO_BTN_ROUTER_ON, |
| 190 | .active_low = 0, |
| 191 | }, { |
| 192 | .desc = "router_auto", |
| 193 | .type = EV_KEY, |
| 194 | .code = BTN_6, |
| 195 | .debounce_interval = WZRHPG300NH_KEYS_DEBOUNCE_INTERVAL, |
| 196 | .gpio = WZRHPG300NH_GPIO_BTN_ROUTER_AUTO, |
| 197 | .active_low = 0, |
| 198 | } |
| 199 | }; |
| 200 | |
| 201 | static struct nxp_74hc153_platform_data wzrhpg300nh_74hc153_data = { |
| 202 | .gpio_base = WZRHPG300NH_GPIO_EXP_BASE, |
| 203 | .gpio_pin_s0 = WZRHPG300NH_GPIO_74HC153_S0, |
| 204 | .gpio_pin_s1 = WZRHPG300NH_GPIO_74HC153_S1, |
| 205 | .gpio_pin_1y = WZRHPG300NH_GPIO_74HC153_1Y, |
| 206 | .gpio_pin_2y = WZRHPG300NH_GPIO_74HC153_2Y, |
| 207 | }; |
| 208 | |
| 209 | static struct platform_device wzrhpg300nh_74hc153_device = { |
| 210 | .name = NXP_74HC153_DRIVER_NAME, |
| 211 | .id = -1, |
| 212 | .dev = { |
| 213 | .platform_data = &wzrhpg300nh_74hc153_data, |
| 214 | } |
| 215 | }; |
| 216 | |
| 217 | static struct rtl8366s_platform_data wzrhpg300nh_rtl8366s_data = { |
| 218 | .gpio_sda = WZRHPG300NH_GPIO_RTL8366_SDA, |
| 219 | .gpio_sck = WZRHPG300NH_GPIO_RTL8366_SCK, |
| 220 | }; |
| 221 | |
| 222 | static struct platform_device wzrhpg300nh_rtl8366s_device = { |
| 223 | .name = RTL8366S_DRIVER_NAME, |
| 224 | .id = -1, |
| 225 | .dev = { |
| 226 | .platform_data = &wzrhpg300nh_rtl8366s_data, |
| 227 | } |
| 228 | }; |
| 229 | |
| 230 | static struct rtl8366rb_platform_data wzrhpg301nh_rtl8366rb_data = { |
| 231 | .gpio_sda = WZRHPG300NH_GPIO_RTL8366_SDA, |
| 232 | .gpio_sck = WZRHPG300NH_GPIO_RTL8366_SCK, |
| 233 | }; |
| 234 | |
| 235 | static struct platform_device wzrhpg301nh_rtl8366rb_device = { |
| 236 | .name = RTL8366RB_DRIVER_NAME, |
| 237 | .id = -1, |
| 238 | .dev = { |
| 239 | .platform_data = &wzrhpg301nh_rtl8366rb_data, |
| 240 | } |
| 241 | }; |
| 242 | |
| 243 | static void __init wzrhpg30xnh_setup(bool hasrtl8366rb) |
| 244 | { |
| 245 | u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000); |
| 246 | u8 *mac = eeprom + WZRHPG300NH_MAC_OFFSET; |
| 247 | |
| 248 | ar71xx_init_mac(ar71xx_eth0_data.mac_addr, mac, 0); |
| 249 | ar71xx_init_mac(ar71xx_eth1_data.mac_addr, mac, 1); |
| 250 | |
| 251 | if (hasrtl8366rb) { |
| 252 | ar71xx_eth0_pll_data.pll_1000 = 0x1f000000; |
| 253 | ar71xx_eth0_data.mii_bus_dev = &wzrhpg301nh_rtl8366rb_device.dev; |
| 254 | ar71xx_eth1_pll_data.pll_1000 = 0x100; |
| 255 | ar71xx_eth1_data.mii_bus_dev = &wzrhpg301nh_rtl8366rb_device.dev; |
| 256 | } else { |
| 257 | ar71xx_eth0_pll_data.pll_1000 = 0x1e000100; |
| 258 | ar71xx_eth0_data.mii_bus_dev = &wzrhpg300nh_rtl8366s_device.dev; |
| 259 | ar71xx_eth1_pll_data.pll_1000 = 0x1e000100; |
| 260 | ar71xx_eth1_data.mii_bus_dev = &wzrhpg300nh_rtl8366s_device.dev; |
| 261 | } |
| 262 | |
| 263 | ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII; |
| 264 | ar71xx_eth0_data.speed = SPEED_1000; |
| 265 | ar71xx_eth0_data.duplex = DUPLEX_FULL; |
| 266 | |
| 267 | ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII; |
| 268 | ar71xx_eth1_data.phy_mask = 0x10; |
| 269 | |
| 270 | ar71xx_add_device_eth(0); |
| 271 | ar71xx_add_device_eth(1); |
| 272 | |
| 273 | ar71xx_add_device_usb(); |
| 274 | ar9xxx_add_device_wmac(eeprom, NULL); |
| 275 | |
| 276 | platform_device_register(&wzrhpg300nh_74hc153_device); |
| 277 | platform_device_register(&wzrhpg300nh_flash_device); |
| 278 | |
| 279 | if (hasrtl8366rb) |
| 280 | platform_device_register(&wzrhpg301nh_rtl8366rb_device); |
| 281 | else |
| 282 | platform_device_register(&wzrhpg300nh_rtl8366s_device); |
| 283 | |
| 284 | ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wzrhpg300nh_leds_gpio), |
| 285 | wzrhpg300nh_leds_gpio); |
| 286 | |
| 287 | ar71xx_register_gpio_keys_polled(-1, WZRHPG300NH_KEYS_POLL_INTERVAL, |
| 288 | ARRAY_SIZE(wzrhpg300nh_gpio_keys), |
| 289 | wzrhpg300nh_gpio_keys); |
| 290 | |
| 291 | } |
| 292 | |
| 293 | static void __init wzrhpg300nh_setup(void) |
| 294 | { |
| 295 | wzrhpg30xnh_setup(false); |
| 296 | } |
| 297 | |
| 298 | static void __init wzrhpg301nh_setup(void) |
| 299 | { |
| 300 | wzrhpg30xnh_setup(true); |
| 301 | } |
| 302 | |
| 303 | MIPS_MACHINE(AR71XX_MACH_WZR_HP_G300NH, "WZR-HP-G300NH", |
| 304 | "Buffalo WZR-HP-G300NH", wzrhpg300nh_setup); |
| 305 | |
| 306 | MIPS_MACHINE(AR71XX_MACH_WZR_HP_G301NH, "WZR-HP-G301NH", |
| 307 | "Buffalo WZR-HP-G301NH", wzrhpg301nh_setup); |
| 308 | |