From 43fd4ab5346ee3be3a88ed6d0112ea5012aedf7d Mon Sep 17 00:00:00 2001 From: Piotr Dymacz Date: Mon, 16 Nov 2015 12:16:40 +0100 Subject: [PATCH] Add support for LED and button in TL-WR820N --- u-boot/Makefile | 4 ++ u-boot/board/ar7240/ap143/ap143.c | 51 ++++++++++++++++++++++++-- u-boot/cpu/mips/ar7240/qca_gpio_init.S | 48 ++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 3 deletions(-) diff --git a/u-boot/Makefile b/u-boot/Makefile index 92d4ec8..14e0653 100644 --- a/u-boot/Makefile +++ b/u-boot/Makefile @@ -762,6 +762,10 @@ tplink_wr820n_CH_config : unconfig ap143_common_config @echo "#define CFG_ATHRS27_PHY 1" >> include/config.h @echo "#define CFG_ATH_GMAC_NMACS 2" >> include/config.h @echo "#define DEFAULT_FLASH_SIZE_IN_MB 4" >> include/config.h + @echo "#define GPIO_SYS_LED_BIT 13" >> include/config.h + @echo "#define GPIO_SYS_LED_ON 0" >> include/config.h + @echo "#define GPIO_RST_BUTTON_BIT 12" >> include/config.h + @echo "#define GPIO_RST_BUTTON_IS_ACTIVE_LOW 1" >> include/config.h @echo "#define BOARD_CUSTOM_STRING \"TP-Link TL-WR820N CH\"" >> include/config.h @echo "#define CFG_PLL_FREQ CFG_PLL_400_400_200" >> include/config.h diff --git a/u-boot/board/ar7240/ap143/ap143.c b/u-boot/board/ar7240/ap143/ap143.c index 43af583..9d06613 100644 --- a/u-boot/board/ar7240/ap143/ap143.c +++ b/u-boot/board/ar7240/ap143/ap143.c @@ -5,28 +5,73 @@ #include #include #include +#include extern int ath_ddr_initial_config(uint32_t refresh); extern int ath_ddr_find_size(void); +#define SETBITVAL(val, pos, bit) do {ulong bitval = (bit) ? 0x1 : 0x0; (val) = ((val) & ~(0x1 << (pos))) | ( (bitval) << (pos));} while(0) + void led_toggle(void) { - return; + u32 gpio = qca_soc_reg_read(QCA_GPIO_OUT_REG); + +#if defined(CONFIG_FOR_TPLINK_WR820N_CH) + gpio ^= 1 << GPIO_SYS_LED_BIT; +#else + #error "Custom GPIO in leg_toggle() not defined!" +#endif + + qca_soc_reg_write(QCA_GPIO_OUT_REG, gpio); } void all_led_on(void) { - return; + u32 gpio = qca_soc_reg_read(QCA_GPIO_OUT_REG); + +#if defined(CONFIG_FOR_TPLINK_WR820N_CH) + SETBITVAL(gpio, GPIO_SYS_LED_BIT, GPIO_SYS_LED_ON); +#else + #error "Custom GPIO in all_led_on() not defined!" +#endif + + qca_soc_reg_write(QCA_GPIO_OUT_REG, gpio); } void all_led_off(void) { - return; + u32 gpio = qca_soc_reg_read(QCA_GPIO_OUT_REG); + +#if defined(CONFIG_FOR_TPLINK_WR820N_CH) + SETBITVAL(gpio, GPIO_SYS_LED_BIT, !GPIO_SYS_LED_ON); +#else + #error "Custom GPIO in all_led_on() not defined!" +#endif + + qca_soc_reg_write(QCA_GPIO_OUT_REG, gpio); } int reset_button_status(void) { +#ifndef GPIO_RST_BUTTON_BIT return 0; +#else + u32 gpio = qca_soc_reg_read(QCA_GPIO_IN_REG); + + if(gpio & (1 << GPIO_RST_BUTTON_BIT)){ + #if defined(GPIO_RST_BUTTON_IS_ACTIVE_LOW) + return 0 ; + #else + return 1 ; + #endif + } else { + #if defined(GPIO_RST_BUTTON_IS_ACTIVE_LOW) + return 1; + #else + return 0; + #endif + } +#endif } int gpio_init(void) diff --git a/u-boot/cpu/mips/ar7240/qca_gpio_init.S b/u-boot/cpu/mips/ar7240/qca_gpio_init.S index 96ea76b..3959f79 100644 --- a/u-boot/cpu/mips/ar7240/qca_gpio_init.S +++ b/u-boot/cpu/mips/ar7240/qca_gpio_init.S @@ -338,6 +338,54 @@ lowlevel_gpio_init: li t8, QCA_GPIO_SET_REG li t9, (GPIO13 | GPIO14 | GPIO15 | GPIO18) sw t9, 0(t8) + +#elif defined(CONFIG_FOR_TPLINK_WR820N_CH) + /* + * LEDs and buttons GPIOs on WR820N CH: + * + * 11 => USB Power (active high) + * 13 => SYS + * + * 0 => SWITCH + * 1 => SWITCH + * 12 => Reset button + * + * All OUT GPIOs are active LOW if not stated otherwise + */ + + /* GPIOs init */ + li t8, QCA_GPIO_OE_REG + lw t9, 0(t8) + /* Set GPIOs 11 and 13 outputs */ + and t9, t9, ~(GPIO11 | GPIO13) + /* Set GPIOs 0, 1 and 12 as inputs */ + or t9, t9, (GPIO0 | GPIO1 | GPIO12) + sw t9, 0(t8) + + /* Set GPIO function for GPIOs 0 and 1 */ + li t8, QCA_GPIO_OUT_FUNC0_REG + lw t9, 0(t8) + and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO0_EN_MASK | \ + QCA_GPIO_OUT_FUNCX_GPIO1_EN_MASK) + sw t9, 0(t8) + + /* Set GPIO function for GPIO 11 */ + li t8, QCA_GPIO_OUT_FUNC2_REG + lw t9, 0(t8) + and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO11_EN_MASK) + sw t9, 0(t8) + + /* Set gpio function for GPIOs 12 and 13 */ + li t8, QCA_GPIO_OUT_FUNC3_REG + lw t9, 0(t8) + and t9, t9, ~(QCA_GPIO_OUT_FUNCX_GPIO12_EN_MASK | \ + QCA_GPIO_OUT_FUNCX_GPIO13_EN_MASK) + sw t9, 0(t8) + + /* Turn off LED, turn on power on USB */ + li t8, QCA_GPIO_SET_REG + li t9, (GPIO11 | GPIO13) + sw t9, 0(t8) #endif j ra -- 2.25.1