| 1 | /* |
| 2 | * TP-LINK TL-WR841N/ND v8 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/platform_device.h> |
| 12 | |
| 13 | #include <asm/mach-ath79/ath79.h> |
| 14 | #include <asm/mach-ath79/ar71xx_regs.h> |
| 15 | |
| 16 | #include "common.h" |
| 17 | #include "dev-eth.h" |
| 18 | #include "dev-gpio-buttons.h" |
| 19 | #include "dev-leds-gpio.h" |
| 20 | #include "dev-m25p80.h" |
| 21 | #include "dev-wmac.h" |
| 22 | #include "machtypes.h" |
| 23 | |
| 24 | #define TL_WR841NV8_GPIO_LED_WLAN 13 |
| 25 | #define TL_WR841NV8_GPIO_LED_QSS 15 |
| 26 | #define TL_WR841NV8_GPIO_LED_WAN 18 |
| 27 | #define TL_WR841NV8_GPIO_LED_LAN1 19 |
| 28 | #define TL_WR841NV8_GPIO_LED_LAN2 20 |
| 29 | #define TL_WR841NV8_GPIO_LED_LAN3 21 |
| 30 | #define TL_WR841NV8_GPIO_LED_LAN4 12 |
| 31 | #define TL_WR841NV8_GPIO_LED_SYSTEM 14 |
| 32 | |
| 33 | #define TL_WR841NV8_GPIO_BTN_RESET 17 |
| 34 | #define TL_WR841NV8_GPIO_SW_RFKILL 16 |
| 35 | |
| 36 | #define TL_WR841NV8_KEYS_POLL_INTERVAL 20 /* msecs */ |
| 37 | #define TL_WR841NV8_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR841NV8_KEYS_POLL_INTERVAL) |
| 38 | |
| 39 | static const char *tl_wr841n_v8_part_probes[] = { |
| 40 | "tp-link", |
| 41 | NULL, |
| 42 | }; |
| 43 | |
| 44 | static struct flash_platform_data tl_wr841n_v8_flash_data = { |
| 45 | .part_probes = tl_wr841n_v8_part_probes, |
| 46 | }; |
| 47 | |
| 48 | static struct gpio_led tl_wr841n_v8_leds_gpio[] __initdata = { |
| 49 | { |
| 50 | .name = "tp-link:green:lan1", |
| 51 | .gpio = TL_WR841NV8_GPIO_LED_LAN1, |
| 52 | .active_low = 1, |
| 53 | }, { |
| 54 | .name = "tp-link:green:lan2", |
| 55 | .gpio = TL_WR841NV8_GPIO_LED_LAN2, |
| 56 | .active_low = 1, |
| 57 | }, { |
| 58 | .name = "tp-link:green:lan3", |
| 59 | .gpio = TL_WR841NV8_GPIO_LED_LAN3, |
| 60 | .active_low = 1, |
| 61 | }, { |
| 62 | .name = "tp-link:green:lan4", |
| 63 | .gpio = TL_WR841NV8_GPIO_LED_LAN4, |
| 64 | .active_low = 1, |
| 65 | }, { |
| 66 | .name = "tp-link:green:qss", |
| 67 | .gpio = TL_WR841NV8_GPIO_LED_QSS, |
| 68 | .active_low = 1, |
| 69 | }, { |
| 70 | .name = "tp-link:green:system", |
| 71 | .gpio = TL_WR841NV8_GPIO_LED_SYSTEM, |
| 72 | .active_low = 1, |
| 73 | }, { |
| 74 | .name = "tp-link:green:wan", |
| 75 | .gpio = TL_WR841NV8_GPIO_LED_WAN, |
| 76 | .active_low = 1, |
| 77 | }, { |
| 78 | .name = "tp-link:green:wlan", |
| 79 | .gpio = TL_WR841NV8_GPIO_LED_WLAN, |
| 80 | .active_low = 1, |
| 81 | }, |
| 82 | }; |
| 83 | |
| 84 | static struct gpio_keys_button tl_wr841n_v8_gpio_keys[] __initdata = { |
| 85 | { |
| 86 | .desc = "Reset button", |
| 87 | .type = EV_KEY, |
| 88 | .code = KEY_RESTART, |
| 89 | .debounce_interval = TL_WR841NV8_KEYS_DEBOUNCE_INTERVAL, |
| 90 | .gpio = TL_WR841NV8_GPIO_BTN_RESET, |
| 91 | .active_low = 1, |
| 92 | }, { |
| 93 | .desc = "RFKILL switch", |
| 94 | .type = EV_SW, |
| 95 | .code = KEY_RFKILL, |
| 96 | .debounce_interval = TL_WR841NV8_KEYS_DEBOUNCE_INTERVAL, |
| 97 | .gpio = TL_WR841NV8_GPIO_SW_RFKILL, |
| 98 | .active_low = 0, |
| 99 | } |
| 100 | }; |
| 101 | |
| 102 | static void __init tl_wr841n_v8_gmac_setup(void) |
| 103 | { |
| 104 | void __iomem *base; |
| 105 | u32 t; |
| 106 | |
| 107 | base = ioremap(AR934X_GMAC_BASE, AR934X_GMAC_SIZE); |
| 108 | |
| 109 | t = __raw_readl(base + AR934X_GMAC_REG_ETH_CFG); |
| 110 | |
| 111 | t &= ~(AR934X_ETH_CFG_RGMII_GMAC0 | AR934X_ETH_CFG_MII_GMAC0 | |
| 112 | AR934X_ETH_CFG_GMII_GMAC0 | AR934X_ETH_CFG_SW_ONLY_MODE | |
| 113 | AR934X_ETH_CFG_SW_PHY_SWAP); |
| 114 | |
| 115 | t |= AR934X_ETH_CFG_SW_PHY_SWAP; |
| 116 | __raw_writel(t, base + AR934X_GMAC_REG_ETH_CFG); |
| 117 | t = __raw_readl(base + AR934X_GMAC_REG_ETH_CFG); |
| 118 | |
| 119 | iounmap(base); |
| 120 | } |
| 121 | |
| 122 | static void __init tl_wr841n_v8_setup(void) |
| 123 | { |
| 124 | u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00); |
| 125 | u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000); |
| 126 | |
| 127 | ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr841n_v8_leds_gpio), |
| 128 | tl_wr841n_v8_leds_gpio); |
| 129 | |
| 130 | ath79_register_gpio_keys_polled(1, TL_WR841NV8_KEYS_POLL_INTERVAL, |
| 131 | ARRAY_SIZE(tl_wr841n_v8_gpio_keys), |
| 132 | tl_wr841n_v8_gpio_keys); |
| 133 | |
| 134 | ath79_register_m25p80(&tl_wr841n_v8_flash_data); |
| 135 | |
| 136 | tl_wr841n_v8_gmac_setup(); |
| 137 | |
| 138 | ath79_register_mdio(1, 0x0); |
| 139 | |
| 140 | ath79_init_mac(ath79_eth0_data.mac_addr, mac, -1); |
| 141 | ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0); |
| 142 | |
| 143 | /* GMAC0 is connected to the PHY0 of the internal switch */ |
| 144 | ath79_switch_data.phy4_mii_en = 1; |
| 145 | ath79_switch_data.phy_poll_mask = BIT(0); |
| 146 | ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII; |
| 147 | ath79_eth0_data.phy_mask = BIT(0); |
| 148 | ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev; |
| 149 | ath79_register_eth(0); |
| 150 | |
| 151 | /* GMAC1 is connected to the internal switch */ |
| 152 | ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII; |
| 153 | ath79_register_eth(1); |
| 154 | |
| 155 | ath79_register_wmac(ee, mac); |
| 156 | } |
| 157 | |
| 158 | MIPS_MACHINE(ATH79_MACH_TL_WR841N_V8, "TL-WR841N-v8", "TP-LINK TL-WR841N/ND v8", |
| 159 | tl_wr841n_v8_setup); |
| 160 | |