@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
#include <config.h>
#include <version.h>
#include <atheros.h>
+#include <soc/qca_soc_common.h>
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)
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