| 1 | /* |
| 2 | * D-Link DIR-300 rev B board support |
| 3 | * |
| 4 | * Copyright (C) 2009-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/init.h> |
| 12 | #include <linux/platform_device.h> |
| 13 | |
| 14 | #include <asm/mach-ralink/machine.h> |
| 15 | #include <asm/mach-ralink/dev-gpio-buttons.h> |
| 16 | #include <asm/mach-ralink/dev-gpio-leds.h> |
| 17 | #include <asm/mach-ralink/rt305x.h> |
| 18 | #include <asm/mach-ralink/rt305x_regs.h> |
| 19 | |
| 20 | #include "devices.h" |
| 21 | |
| 22 | #define DIR_300B_GPIO_LED_STATUS_AMBER 8 |
| 23 | #define DIR_300B_GPIO_LED_STATUS_GREEN 9 |
| 24 | #define DIR_300B_GPIO_LED_WPS 13 |
| 25 | /* |
| 26 | * NOTE: The wan led is also connected to the switch, both |
| 27 | * switch and gpio must be active to make it light up |
| 28 | */ |
| 29 | #define DIR_300B_GPIO_LED_WAN_GREEN 12 |
| 30 | #define DIR_300B_GPIO_LED_WAN_AMBER 14 |
| 31 | |
| 32 | /* |
| 33 | * NOTE: the WPS led in DIR-620 consists of two antiparallel leds, |
| 34 | * so they can't be lit simultaneously |
| 35 | */ |
| 36 | #define DIR_620_GPIO_LED_WPS_AMBER 11 |
| 37 | |
| 38 | #define DIR_300B_GPIO_BUTTON_WPS 0 /* active low */ |
| 39 | #define DIR_300B_GPIO_BUTTON_RESET 10 /* active low */ |
| 40 | |
| 41 | #define DIR_300B_KEYS_POLL_INTERVAL 20 |
| 42 | #define DIR_300B_KEYS_DEBOUNCE_INTERVAL (3 * DIR_300B_KEYS_POLL_INTERVAL) |
| 43 | |
| 44 | static struct gpio_led dir_300b_leds_gpio[] __initdata = { |
| 45 | { |
| 46 | .name = "d-link:amber:status", |
| 47 | .gpio = DIR_300B_GPIO_LED_STATUS_AMBER, |
| 48 | .active_low = 1, |
| 49 | }, { |
| 50 | .name = "d-link:green:status", |
| 51 | .gpio = DIR_300B_GPIO_LED_STATUS_GREEN, |
| 52 | .active_low = 1, |
| 53 | }, { |
| 54 | .name = "d-link:amber:wan", |
| 55 | .gpio = DIR_300B_GPIO_LED_WAN_AMBER, |
| 56 | .active_low = 1, |
| 57 | }, { |
| 58 | .name = "d-link:green:wan", |
| 59 | .gpio = DIR_300B_GPIO_LED_WAN_GREEN, |
| 60 | .active_low = 1, |
| 61 | }, { |
| 62 | .name = "d-link:blue:wps", |
| 63 | .gpio = DIR_300B_GPIO_LED_WPS, |
| 64 | .active_low = 1, |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | static struct gpio_keys_button dir_300b_gpio_buttons[] __initdata = { |
| 69 | { |
| 70 | .desc = "reset", |
| 71 | .type = EV_KEY, |
| 72 | .code = KEY_RESTART, |
| 73 | .debounce_interval = DIR_300B_KEYS_DEBOUNCE_INTERVAL, |
| 74 | .gpio = DIR_300B_GPIO_BUTTON_RESET, |
| 75 | .active_low = 1, |
| 76 | }, { |
| 77 | .desc = "wps", |
| 78 | .type = EV_KEY, |
| 79 | .code = KEY_WPS_BUTTON, |
| 80 | .debounce_interval = DIR_300B_KEYS_DEBOUNCE_INTERVAL, |
| 81 | .gpio = DIR_300B_GPIO_BUTTON_WPS, |
| 82 | .active_low = 1, |
| 83 | } |
| 84 | }; |
| 85 | |
| 86 | static struct gpio_led dir_620_leds_gpio[] __initdata = { |
| 87 | { |
| 88 | .name = "d-link:amber:status", |
| 89 | .gpio = DIR_300B_GPIO_LED_STATUS_AMBER, |
| 90 | .active_low = 1, |
| 91 | }, { |
| 92 | .name = "d-link:green:status", |
| 93 | .gpio = DIR_300B_GPIO_LED_STATUS_GREEN, |
| 94 | .active_low = 1, |
| 95 | }, { |
| 96 | .name = "d-link:amber:wan", |
| 97 | .gpio = DIR_300B_GPIO_LED_WAN_AMBER, |
| 98 | .active_low = 1, |
| 99 | }, { |
| 100 | .name = "d-link:green:wan", |
| 101 | .gpio = DIR_300B_GPIO_LED_WAN_GREEN, |
| 102 | .active_low = 1, |
| 103 | }, { |
| 104 | .name = "d-link:blue:wps", |
| 105 | .gpio = DIR_300B_GPIO_LED_WPS, |
| 106 | }, { |
| 107 | .name = "d-link:amber:wps", |
| 108 | .gpio = DIR_620_GPIO_LED_WPS_AMBER, |
| 109 | } |
| 110 | }; |
| 111 | |
| 112 | static void __init dir_common_init(void) |
| 113 | { |
| 114 | rt305x_gpio_init(RT305X_GPIO_MODE_GPIO << RT305X_GPIO_MODE_UART0_SHIFT); |
| 115 | |
| 116 | rt305x_register_flash(0); |
| 117 | |
| 118 | rt305x_esw_data.vlan_config = RT305X_ESW_VLAN_CONFIG_LLLLW; |
| 119 | rt305x_register_ethernet(); |
| 120 | ramips_register_gpio_buttons(-1, DIR_300B_KEYS_POLL_INTERVAL, |
| 121 | ARRAY_SIZE(dir_300b_gpio_buttons), |
| 122 | dir_300b_gpio_buttons); |
| 123 | rt305x_register_wifi(); |
| 124 | rt305x_register_wdt(); |
| 125 | } |
| 126 | |
| 127 | static void __init dir_300b_init(void) |
| 128 | { |
| 129 | dir_common_init(); |
| 130 | ramips_register_gpio_leds(-1, ARRAY_SIZE(dir_300b_leds_gpio), |
| 131 | dir_300b_leds_gpio); |
| 132 | } |
| 133 | |
| 134 | static void __init dir_620a1_init(void) |
| 135 | { |
| 136 | dir_common_init(); |
| 137 | ramips_register_gpio_leds(-1, ARRAY_SIZE(dir_620_leds_gpio), |
| 138 | dir_620_leds_gpio); |
| 139 | rt305x_register_usb(); |
| 140 | } |
| 141 | |
| 142 | MIPS_MACHINE(RAMIPS_MACH_DIR_300_B1, "DIR-300-B1", "D-Link DIR-300 B1", |
| 143 | dir_300b_init); |
| 144 | |
| 145 | MIPS_MACHINE(RAMIPS_MACH_DIR_600_B1, "DIR-600-B1", "D-Link DIR-600 B1", |
| 146 | dir_300b_init); |
| 147 | |
| 148 | MIPS_MACHINE(RAMIPS_MACH_DIR_600_B2, "DIR-600-B2", "D-Link DIR-600 B2", |
| 149 | dir_300b_init); |
| 150 | |
| 151 | MIPS_MACHINE(RAMIPS_MACH_DIR_615_D, "DIR-615-D", "D-Link DIR-615 D", |
| 152 | dir_300b_init); |
| 153 | |
| 154 | MIPS_MACHINE(RAMIPS_MACH_DIR_620_A1, "DIR-620-A1", "D-Link DIR-620 A1", |
| 155 | dir_620a1_init); |
| 156 | |