| 1 | /* |
| 2 | * NETGEAR WNDR4300 board support |
| 3 | * |
| 4 | * Copyright (C) 2012 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/pci.h> |
| 12 | #include <linux/phy.h> |
| 13 | #include <linux/gpio.h> |
| 14 | #include <linux/platform_device.h> |
| 15 | #include <linux/ath9k_platform.h> |
| 16 | #include <linux/ar8216_platform.h> |
| 17 | |
| 18 | #include <asm/mach-ath79/ar71xx_regs.h> |
| 19 | |
| 20 | #include "common.h" |
| 21 | #include "dev-ap9x-pci.h" |
| 22 | #include "dev-eth.h" |
| 23 | #include "dev-gpio-buttons.h" |
| 24 | #include "dev-leds-gpio.h" |
| 25 | #include "dev-nfc.h" |
| 26 | #include "dev-usb.h" |
| 27 | #include "dev-wmac.h" |
| 28 | #include "machtypes.h" |
| 29 | |
| 30 | #define WNDR4300_GPIO_LED_POWER_GREEN 0 |
| 31 | #define WNDR4300_GPIO_LED_POWER_ORANGE 2 |
| 32 | #define WNDR4300_GPIO_LED_USB 13 |
| 33 | #define WNDR4300_GPIO_LED_WAN_GREEN 1 |
| 34 | #define WNDR4300_GPIO_LED_WAN_ORANGE 3 |
| 35 | #define WNDR4300_GPIO_LED_WLAN5G 14 |
| 36 | #define WNDR4300_GPIO_LED_WPS_GREEN 16 |
| 37 | #define WNDR4300_GPIO_LED_WPS_ORANGE 17 |
| 38 | |
| 39 | #define WNDR4300_GPIO_BTN_RESET 21 |
| 40 | #define WNDR4300_GPIO_BTN_WIRELESS 15 |
| 41 | #define WNDR4300_GPIO_BTN_WPS 12 |
| 42 | |
| 43 | #define WNDR4300_KEYS_POLL_INTERVAL 20 /* msecs */ |
| 44 | #define WNDR4300_KEYS_DEBOUNCE_INTERVAL (3 * WNDR4300_KEYS_POLL_INTERVAL) |
| 45 | |
| 46 | static struct gpio_led wndr4300_leds_gpio[] __initdata = { |
| 47 | { |
| 48 | .name = "netgear:green:power", |
| 49 | .gpio = WNDR4300_GPIO_LED_POWER_GREEN, |
| 50 | .active_low = 1, |
| 51 | }, |
| 52 | { |
| 53 | .name = "netgear:orange:power", |
| 54 | .gpio = WNDR4300_GPIO_LED_POWER_ORANGE, |
| 55 | .active_low = 1, |
| 56 | }, |
| 57 | { |
| 58 | .name = "netgear:green:wan", |
| 59 | .gpio = WNDR4300_GPIO_LED_WAN_GREEN, |
| 60 | .active_low = 1, |
| 61 | }, |
| 62 | { |
| 63 | .name = "netgear:orange:wan", |
| 64 | .gpio = WNDR4300_GPIO_LED_WAN_ORANGE, |
| 65 | .active_low = 1, |
| 66 | }, |
| 67 | { |
| 68 | .name = "netgear:green:usb", |
| 69 | .gpio = WNDR4300_GPIO_LED_USB, |
| 70 | .active_low = 1, |
| 71 | }, |
| 72 | { |
| 73 | .name = "netgear:green:wps", |
| 74 | .gpio = WNDR4300_GPIO_LED_WPS_GREEN, |
| 75 | .active_low = 1, |
| 76 | }, |
| 77 | { |
| 78 | .name = "netgear:orange:wps", |
| 79 | .gpio = WNDR4300_GPIO_LED_WPS_ORANGE, |
| 80 | .active_low = 1, |
| 81 | }, |
| 82 | { |
| 83 | .name = "netgear:blue:wlan5g", |
| 84 | .gpio = WNDR4300_GPIO_LED_WLAN5G, |
| 85 | .active_low = 1, |
| 86 | }, |
| 87 | }; |
| 88 | |
| 89 | static struct gpio_keys_button wndr4300_gpio_keys[] __initdata = { |
| 90 | { |
| 91 | .desc = "Reset button", |
| 92 | .type = EV_KEY, |
| 93 | .code = KEY_RESTART, |
| 94 | .debounce_interval = WNDR4300_KEYS_DEBOUNCE_INTERVAL, |
| 95 | .gpio = WNDR4300_GPIO_BTN_RESET, |
| 96 | .active_low = 1, |
| 97 | }, |
| 98 | { |
| 99 | .desc = "WPS button", |
| 100 | .type = EV_KEY, |
| 101 | .code = KEY_WPS_BUTTON, |
| 102 | .debounce_interval = WNDR4300_KEYS_DEBOUNCE_INTERVAL, |
| 103 | .gpio = WNDR4300_GPIO_BTN_WPS, |
| 104 | .active_low = 1, |
| 105 | }, |
| 106 | { |
| 107 | .desc = "Wireless button", |
| 108 | .type = EV_KEY, |
| 109 | .code = BTN_0, |
| 110 | .debounce_interval = WNDR4300_KEYS_DEBOUNCE_INTERVAL, |
| 111 | .gpio = WNDR4300_GPIO_BTN_WIRELESS, |
| 112 | .active_low = 1, |
| 113 | }, |
| 114 | }; |
| 115 | |
| 116 | static struct ar8327_pad_cfg wndr4300_ar8327_pad0_cfg = { |
| 117 | .mode = AR8327_PAD_MAC_RGMII, |
| 118 | .txclk_delay_en = true, |
| 119 | .rxclk_delay_en = true, |
| 120 | .txclk_delay_sel = AR8327_CLK_DELAY_SEL1, |
| 121 | .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2, |
| 122 | }; |
| 123 | |
| 124 | static struct ar8327_led_cfg wndr4300_ar8327_led_cfg = { |
| 125 | .led_ctrl0 = 0xc737c737, |
| 126 | .led_ctrl1 = 0x00000000, |
| 127 | .led_ctrl2 = 0x00000000, |
| 128 | .led_ctrl3 = 0x0030c300, |
| 129 | .open_drain = false, |
| 130 | }; |
| 131 | |
| 132 | static struct ar8327_platform_data wndr4300_ar8327_data = { |
| 133 | .pad0_cfg = &wndr4300_ar8327_pad0_cfg, |
| 134 | .port0_cfg = { |
| 135 | .force_link = 1, |
| 136 | .speed = AR8327_PORT_SPEED_1000, |
| 137 | .duplex = 1, |
| 138 | .txpause = 1, |
| 139 | .rxpause = 1, |
| 140 | }, |
| 141 | .led_cfg = &wndr4300_ar8327_led_cfg, |
| 142 | }; |
| 143 | |
| 144 | static struct mdio_board_info wndr4300_mdio0_info[] = { |
| 145 | { |
| 146 | .bus_id = "ag71xx-mdio.0", |
| 147 | .phy_addr = 0, |
| 148 | .platform_data = &wndr4300_ar8327_data, |
| 149 | }, |
| 150 | }; |
| 151 | |
| 152 | static void __init wndr4300_setup(void) |
| 153 | { |
| 154 | ath79_register_leds_gpio(-1, ARRAY_SIZE(wndr4300_leds_gpio), |
| 155 | wndr4300_leds_gpio); |
| 156 | ath79_register_gpio_keys_polled(-1, WNDR4300_KEYS_POLL_INTERVAL, |
| 157 | ARRAY_SIZE(wndr4300_gpio_keys), |
| 158 | wndr4300_gpio_keys); |
| 159 | |
| 160 | ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0); |
| 161 | |
| 162 | mdiobus_register_board_info(wndr4300_mdio0_info, |
| 163 | ARRAY_SIZE(wndr4300_mdio0_info)); |
| 164 | |
| 165 | ath79_register_mdio(0, 0x0); |
| 166 | |
| 167 | /* GMAC0 is connected to an AR8327N switch */ |
| 168 | ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII; |
| 169 | ath79_eth0_data.phy_mask = BIT(0); |
| 170 | ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev; |
| 171 | ath79_eth0_pll_data.pll_1000 = 0x06000000; |
| 172 | ath79_register_eth(0); |
| 173 | |
| 174 | ath79_register_nfc(); |
| 175 | ath79_register_usb(); |
| 176 | |
| 177 | ath79_register_wmac_simple(); |
| 178 | ap91_pci_init_simple(); |
| 179 | } |
| 180 | |
| 181 | MIPS_MACHINE(ATH79_MACH_WNDR4300, "WNDR4300", "NETGEAR WNDR4300", |
| 182 | wndr4300_setup); |
| 183 | |