From: Piotr Dymacz Date: Wed, 18 Dec 2013 16:31:46 +0000 (+0100) Subject: GPIO configuration for AR934x (in asm is, however, better) X-Git-Tag: 2014-11-19~49^2~3 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=8875f1640bfdde1533aa7ab8c12d71df3f4e435c;p=oweals%2Fu-boot_mod.git GPIO configuration for AR934x (in asm is, however, better) --- diff --git a/u-boot/Makefile b/u-boot/Makefile index b067643..ac2a4bf 100755 --- a/u-boot/Makefile +++ b/u-boot/Makefile @@ -482,6 +482,18 @@ wdr3600_43x0_config : unconfig wasp_common_config @echo "#define CFG_ATHRS17_PHY 1" >> include/config.h @echo "#define CFG_AG7240_NMACS 1" >> include/config.h @echo "#define CFG_DUAL_PHY_SUPPORT 1" >> include/config.h + @echo "#define GPIO_SYS_LED_BIT 14" >> include/config.h + @echo "#define GPIO_SYS_LED_ON 0" >> include/config.h + @echo "#define GPIO_WLAN_2G_LED_BIT 13" >> include/config.h + @echo "#define GPIO_WLAN_2G_LED_ON 0" >> include/config.h + @echo "#define GPIO_USB1_LED_BIT 11" >> include/config.h + @echo "#define GPIO_USB1_LED_ON 0" >> include/config.h + @echo "#define GPIO_USB2_LED_BIT 12" >> include/config.h + @echo "#define GPIO_USB2_LED_ON 0" >> include/config.h + @echo "#define GPIO_QSS_LED_BIT 15" >> include/config.h + @echo "#define GPIO_QSS_LED_ON 0" >> include/config.h + @echo "#define GPIO_RST_BUTTON_BIT 16" >> include/config.h + @echo "#define GPIO_RST_BUTTON_IS_ACTIVE_LOW 1" >> include/config.h @echo "#define DEFAULT_FLASH_SIZE_IN_MB 8" >> include/config.h @echo "#define BOARD_CUSTOM_STRING \"DB120 (AR9344) U-Boot for TL-WDR3600/43x0\"" >> include/config.h @@ -494,6 +506,24 @@ wr841n_v8_config : unconfig wasp_common_config @echo "#define DDR2_32BIT_SUPPORT 1" >> include/config.h @echo "#define CFG_ATHRS27_PHY 1" >> include/config.h @echo "#define CFG_AG7240_NMACS 2" >> include/config.h + @echo "#define GPIO_SYS_LED_BIT 14" >> include/config.h + @echo "#define GPIO_SYS_LED_ON 0" >> include/config.h + @echo "#define GPIO_WLAN_LED_BIT 13" >> include/config.h + @echo "#define GPIO_WLAN_LED_ON 0" >> include/config.h + @echo "#define GPIO_INTERNET_LED_BIT 18" >> include/config.h + @echo "#define GPIO_INTERNET_LED_ON 0" >> include/config.h + @echo "#define GPIO_LAN1_LED_BIT 19" >> include/config.h + @echo "#define GPIO_LAN1_LED_ON 0" >> include/config.h + @echo "#define GPIO_LAN2_LED_BIT 20" >> include/config.h + @echo "#define GPIO_LAN2_LED_ON 0" >> include/config.h + @echo "#define GPIO_LAN3_LED_BIT 21" >> include/config.h + @echo "#define GPIO_LAN3_LED_ON 0" >> include/config.h + @echo "#define GPIO_LAN4_LED_BIT 12" >> include/config.h + @echo "#define GPIO_LAN4_LED_ON 0" >> include/config.h + @echo "#define GPIO_QSS_LED_BIT 15" >> include/config.h + @echo "#define GPIO_QSS_LED_ON 0" >> include/config.h + @echo "#define GPIO_RST_BUTTON_BIT 17" >> include/config.h + @echo "#define GPIO_RST_BUTTON_IS_ACTIVE_LOW 1" >> include/config.h @echo "#define DEFAULT_FLASH_SIZE_IN_MB 4" >> include/config.h @echo "#define BOARD_CUSTOM_STRING \"AP123 (AR9341) U-Boot for TL-WR841N/D v8\"" >> include/config.h diff --git a/u-boot/board/ar7240/db12x/db12x.c b/u-boot/board/ar7240/db12x/db12x.c index 26fe6d9..b1a362a 100755 --- a/u-boot/board/ar7240/db12x/db12x.c +++ b/u-boot/board/ar7240/db12x/db12x.c @@ -14,56 +14,97 @@ extern int ar7240_ddr_find_size(void); void led_toggle(void){ unsigned int gpio; - gpio = ar7240_reg_rd(AR7240_GPIO_OUT); + gpio = ar7240_reg_rd(AR934X_GPIO_OUT); - // SYS LED is connected to GPIO 14 - gpio ^= 1 << 14; +#if defined(CONFIG_FOR_TPLINK_WDR3600_WDR43X0_V1) + gpio ^= 1 << GPIO_SYS_LED_BIT; +#elif defined(CONFIG_FOR_TPLINK_WR841N_V8) + gpio ^= 1 << GPIO_SYS_LED_BIT; +#else + #error "Custom GPIO in leg_toggle() not defined!" +#endif - ar7240_reg_wr(AR7240_GPIO_OUT, gpio); + ar7240_reg_wr(AR934X_GPIO_OUT, gpio); } void all_led_on(void){ unsigned int gpio; - gpio = ar7240_reg_rd(AR7240_GPIO_OUT); - - // SYS LED (GPIO 14) and WLAN24 (GPIO 13) - SETBITVAL(gpio, 14, 0); - SETBITVAL(gpio, 13, 0); - - ar7240_reg_wr(AR7240_GPIO_OUT, gpio); + gpio = ar7240_reg_rd(AR934X_GPIO_OUT); + +#if defined(CONFIG_FOR_TPLINK_WDR3600_WDR43X0_V1) + SETBITVAL(gpio, GPIO_SYS_LED_BIT, GPIO_SYS_LED_ON); + SETBITVAL(gpio, GPIO_WLAN_2G_LED_BIT, GPIO_WLAN_2G_LED_ON); + SETBITVAL(gpio, GPIO_USB1_LED_BIT, GPIO_USB1_LED_ON); + SETBITVAL(gpio, GPIO_USB2_LED_BIT, GPIO_USB2_LED_ON); + //SETBITVAL(gpio, GPIO_QSS_LED_BIT, GPIO_QSS_LED_ON); +#elif defined(CONFIG_FOR_TPLINK_WR841N_V8) + SETBITVAL(gpio, GPIO_SYS_LED_BIT, GPIO_SYS_LED_ON); + SETBITVAL(gpio, GPIO_WLAN_LED_BIT, GPIO_WLAN_LED_ON); + SETBITVAL(gpio, GPIO_INTERNET_LED_BIT, GPIO_INTERNET_LED_ON); + SETBITVAL(gpio, GPIO_LAN1_LED_BIT, GPIO_LAN1_LED_ON); + SETBITVAL(gpio, GPIO_LAN2_LED_BIT, GPIO_LAN2_LED_ON); + SETBITVAL(gpio, GPIO_LAN3_LED_BIT, GPIO_LAN3_LED_ON); + SETBITVAL(gpio, GPIO_LAN4_LED_BIT, GPIO_LAN4_LED_ON); + SETBITVAL(gpio, GPIO_QSS_LED_BIT, GPIO_QSS_LED_ON); +#else + #error "Custom GPIO in all_led_on() not defined!" +#endif + + ar7240_reg_wr(AR934X_GPIO_OUT, gpio); } void all_led_off(void){ unsigned int gpio; - gpio = ar7240_reg_rd(AR7240_GPIO_OUT); - - // SYS LED (GPIO 14) and WLAN24 (GPIO 13) - SETBITVAL(gpio, 14, 1); - SETBITVAL(gpio, 13, 1); - - ar7240_reg_wr(AR7240_GPIO_OUT, gpio); + gpio = ar7240_reg_rd(AR934X_GPIO_OUT); + +#if defined(CONFIG_FOR_TPLINK_WDR3600_WDR43X0_V1) + SETBITVAL(gpio, GPIO_SYS_LED_BIT, !GPIO_SYS_LED_ON); + SETBITVAL(gpio, GPIO_WLAN_2G_LED_BIT, !GPIO_WLAN_2G_LED_ON); + SETBITVAL(gpio, GPIO_USB1_LED_BIT, !GPIO_USB1_LED_ON); + SETBITVAL(gpio, GPIO_USB2_LED_BIT, !GPIO_USB2_LED_ON); + //SETBITVAL(gpio, GPIO_QSS_LED_BIT, !GPIO_QSS_LED_ON); +#elif defined(CONFIG_FOR_TPLINK_WR841N_V8) + SETBITVAL(gpio, GPIO_SYS_LED_BIT, !GPIO_SYS_LED_ON); + SETBITVAL(gpio, GPIO_WLAN_LED_BIT, !GPIO_WLAN_LED_ON); + SETBITVAL(gpio, GPIO_INTERNET_LED_BIT, !GPIO_INTERNET_LED_ON); + SETBITVAL(gpio, GPIO_LAN1_LED_BIT, !GPIO_LAN1_LED_ON); + SETBITVAL(gpio, GPIO_LAN2_LED_BIT, !GPIO_LAN2_LED_ON); + SETBITVAL(gpio, GPIO_LAN3_LED_BIT, !GPIO_LAN3_LED_ON); + SETBITVAL(gpio, GPIO_LAN4_LED_BIT, !GPIO_LAN4_LED_ON); + SETBITVAL(gpio, GPIO_QSS_LED_BIT, !GPIO_QSS_LED_ON); +#else + #error "Custom GPIO in all_led_off() not defined!" +#endif + + ar7240_reg_wr(AR934X_GPIO_OUT, gpio); } // get button status +#ifndef GPIO_RST_BUTTON_BIT + #error "GPIO_RST_BUTTON_BIT not defined!" +#endif int reset_button_status(void){ - // RESET BUTTON is connected to GPIO 16 - if(ar7240_reg_rd(AR7240_GPIO_IN) & (1 << 16)){ - return 0; + unsigned int gpio; + + gpio = ar7240_reg_rd(AR934X_GPIO_IN); + + if(gpio & (1 << GPIO_RST_BUTTON_BIT)){ +#if defined(GPIO_RST_BUTTON_IS_ACTIVE_LOW) + return(0); +#else + return(1); +#endif } else { - return 1; +#if defined(GPIO_RST_BUTTON_IS_ACTIVE_LOW) + return(1); +#else + return(0); +#endif } } -void gpio_config(void){ - /* disable the CLK_OBS on GPIO_4 and set GPIO4 as input */ - ar7240_reg_rmw_clear(GPIO_OE_ADDRESS, (1 << 4)); - ar7240_reg_rmw_clear(GPIO_OUT_FUNCTION1_ADDRESS, GPIO_OUT_FUNCTION1_ENABLE_GPIO_4_MASK); - ar7240_reg_rmw_set(GPIO_OUT_FUNCTION1_ADDRESS, GPIO_OUT_FUNCTION1_ENABLE_GPIO_4_SET(0x80)); - ar7240_reg_rmw_set(GPIO_OE_ADDRESS, (1 << 4)); -} - void ath_set_tuning_caps(void){ typedef struct { u_int8_t pad[0x28]; @@ -113,8 +154,6 @@ int wasp_mem_config(void){ //wasp_usb_initial_config(); - gpio_config(); - /* Needed here not to mess with Ethernet clocks */ ath_set_tuning_caps(); diff --git a/u-boot/cpu/mips/start_bootstrap.S b/u-boot/cpu/mips/start_bootstrap.S index 9f5ebaa..0188535 100755 --- a/u-boot/cpu/mips/start_bootstrap.S +++ b/u-boot/cpu/mips/start_bootstrap.S @@ -32,20 +32,6 @@ #define AR7100_SPI_CLOCK 0x1F000004 -#ifdef CONFIG_WASP_SUPPORT - #define ATH_APB_BASE 0xB8000000 /* KSEG1ADDR(0x18000000) */ - #define ATH_GPIO_BASE ATH_APB_BASE+0x00040000 - #define ATH_GPIO_OE ATH_GPIO_BASE+0x0 - #define ATH_GPIO_OUT ATH_GPIO_BASE+0x8 - #define ATH_GPIO_OUT_FUNCTION0 ATH_GPIO_BASE+0x2c - #define ATH_GPIO_OUT_FUNCTION1 ATH_GPIO_BASE+0x30 - #define ATH_GPIO_OUT_FUNCTION2 ATH_GPIO_BASE+0x34 - #define ATH_GPIO_OUT_FUNCTION3 ATH_GPIO_BASE+0x38 - #define ATH_GPIO_OUT_FUNCTION4 ATH_GPIO_BASE+0x3c - #define ATH_GPIO_OUT_FUNCTION5 ATH_GPIO_BASE+0x40 -#endif - - #define RVECENT(f,n) \ b f; nop @@ -194,43 +180,63 @@ _start_bootstrap: .align 4 reset: -#ifdef CONFIG_WASP_SUPPORT -#ifndef CONFIG_AP123 - /* GPIO Init */ - li a1, ATH_GPIO_OE +#if defined(CONFIG_WASP_SUPPORT) + + /* + * Disable JTAG + */ + + // Set BIT 1 to 1 in AR934X_GPIO_FUNCTION + li a1, AR934X_GPIO_FUNCTION lw v1, 0(a1) - /* GPIO 11-15 as output */ - li v0, ~((1 << 15) | (1 << 14) | (1 << 13) | (1 << 12) | (1 << 11)) + li v0, 0x2 + or v1, v1, v0 + sw v1, 0(a1) + +#if defined(CONFIG_FOR_TPLINK_WDR3600_WDR43X0_V1) + /* + * LED's/Reset GPIOs on WDR3600/WDR43x0 v1: + * + * 11 => USB1 + * 12 => USB2 + * 13 => WLAN2G + * 14 => SYS + * 15 => QSS + * + * 16 => Reset button + * + * All used GPIOs are active LOW! + */ + + // GPIO Init + li a1, AR934X_GPIO_OE + lw v1, 0(a1) + li v0, 0xFFFF07FF and v1, v1, v0 - /* save GPIO Config Value */ sw v1, 0(a1) - lw v0, 0(a1) - /* set gpio funtion for gpio11 */ - li a1, ATH_GPIO_OUT_FUNCTION2 + // Set gpio function for GPIO 11 + li a1, AR934X_GPIO_OUT_FUNCTION2 lw v1, 0(a1) - li v0, 0x00ffffff + li v0, 0x00FFFFFF and v1, v1, v0 - /* set v1 value to ATH_GPIO_OUT_FUNCTION2 */ sw v1, 0(a1) - /* set gpio funtion for gpio12~15 */ - li a1, ATH_GPIO_OUT_FUNCTION3 + // Set gpio function for GPIOs 12~15 + li a1, AR934X_GPIO_OUT_FUNCTION3 lw v1, 0(a1) li v0, 0x0 and v1, v1, v0 - /* set v1 value to ATH_GPIO_OUT_FUNCTION3 */ sw v1, 0(a1) - /* turn on gpio11-15 */ - li a1, ATH_GPIO_OUT + // Turn on GPIOs 11~15 + li a1, AR934X_GPIO_OUT lw v1, 0(a1) - li v0, ~((1 << 15) | (1 << 14) | (1 << 13) | (1 << 12) | (1 << 11)) + li v0, 0xFFFF07FF and v1, v1, v0 - /* set v1 value to ATH_GPIO_OUT */ sw v1, 0(a1) - /* wait for a while, for leds' bootup blink*/ + // wait for a while, for leds' bootup blink li a1, 0 li v1, 0x70000 @@ -239,15 +245,61 @@ reset: bne a1, v1, 1b nop - /* turn off gpio11-15 */ - li a1, ATH_GPIO_OUT + // Turn off GPIOs 11~15 + li a1, AR934X_GPIO_OUT lw v1, 0(a1) - li v0, ((1 << 15) | (1 << 14) | (1 << 13) | (1 << 12) | (1 << 11)) + li v0, ~(0xFFFF07FF) + or v1, v1, v0 + sw v1, 0(a1) + +#elif defined(CONFIG_FOR_TPLINK_WR841N_V8) + /* + * LED's/Reset GPIOs on WR841N/D v8: + * + * 12 => LAN4 + * 13 => WLAN + * 14 => SYS + * 15 => QSS + * 18 => WAN + * 19 => LAN1 + * 20 => LAN2 + * 21 => LAN3 + * + * 17 => Reset button (already set as input) + * + * All used GPIOs are active LOW! + */ + + // GPIOs init + li a1, AR934X_GPIO_OE + lw v1, 0(a1) + li v0, 0xFFC30FFF + and v1, v1, v0 + sw v1, 0(a1) + + // Set gpio function for GPIO 11 + li a1, AR934X_GPIO_OUT_FUNCTION2 + lw v1, 0(a1) + li v0, 0x00ffffff + and v1, v1, v0 + sw v1, 0(a1) + + // Set gpio function for GPIOs 12~15 + li a1, AR934X_GPIO_OUT_FUNCTION3 + lw v1, 0(a1) + li v0, 0x0 + and v1, v1, v0 + sw v1, 0(a1) + + // Turn off GPIOs + li a1, AR934X_GPIO_OUT + lw v1, 0(a1) + li v0, ~(0xFFC30FFF) or v1, v1, v0 - /* set v1 value to ATH_GPIO_OUT */ sw v1, 0(a1) #endif -#endif + +#endif /* #if defined(CONFIG_WASP_SUPPORT) */ /* * Clearing CP0 registers - This is generally required for the MIPS-24k diff --git a/u-boot/include/ar934x_soc.h b/u-boot/include/ar934x_soc.h index b412cfc..1d05bf3 100755 --- a/u-boot/include/ar934x_soc.h +++ b/u-boot/include/ar934x_soc.h @@ -1609,9 +1609,6 @@ #define XTAL_ADDRESS 0x18116290 -#define GPIO_OE_ADDRESS 0x18040000 - - #define PCIE_PHY_REG_1_SERDES_DIS_RXIMP_MSB 31 #define PCIE_PHY_REG_1_SERDES_DIS_RXIMP_LSB 31 #define PCIE_PHY_REG_1_SERDES_DIS_RXIMP_MASK 0x80000000 @@ -1752,6 +1749,30 @@ #define PCIE_PHY_REG_1_S_RESET 0xe // 14 #define PCIE_PHY_REG_1_ADDRESS 0x18116cc0 +#define AR934X_GPIO_BASE 0x18040000 +#define AR934X_GPIO_OE AR934X_GPIO_BASE + 0x0 +#define AR934X_GPIO_IN AR934X_GPIO_BASE + 0x4 +#define AR934X_GPIO_OUT AR934X_GPIO_BASE + 0x8 +#define AR934X_GPIO_SET AR934X_GPIO_BASE + 0xC +#define AR934X_GPIO_CLEAR AR934X_GPIO_BASE + 0x10 +#define AR934X_GPIO_INT AR934X_GPIO_BASE + 0x14 +#define AR934X_GPIO_INT_TYPE AR934X_GPIO_BASE + 0x18 +#define AR934X_GPIO_INT_POLARITY AR934X_GPIO_BASE + 0x1C +#define AR934X_GPIO_INT_PENDING AR934X_GPIO_BASE + 0x20 +#define AR934X_GPIO_INT_MASK AR934X_GPIO_BASE + 0x24 +#define AR934X_GPIO_IN_ETH_SWITCH_LED AR934X_GPIO_BASE + 0x28 +#define AR934X_GPIO_OUT_FUNCTION0 AR934X_GPIO_BASE + 0x2C +#define AR934X_GPIO_OUT_FUNCTION1 AR934X_GPIO_BASE + 0x30 +#define AR934X_GPIO_OUT_FUNCTION2 AR934X_GPIO_BASE + 0x34 +#define AR934X_GPIO_OUT_FUNCTION3 AR934X_GPIO_BASE + 0x38 +#define AR934X_GPIO_OUT_FUNCTION4 AR934X_GPIO_BASE + 0x3C +#define AR934X_GPIO_IN_ENABLE0 AR934X_GPIO_BASE + 0x44 +#define AR934X_GPIO_IN_ENABLE1 AR934X_GPIO_BASE + 0x48 +#define AR934X_GPIO_IN_ENABLE2 AR934X_GPIO_BASE + 0x4C +#define AR934X_GPIO_IN_ENABLE3 AR934X_GPIO_BASE + 0x50 +#define AR934X_GPIO_IN_ENABLE4 AR934X_GPIO_BASE + 0x54 +#define AR934X_GPIO_IN_ENABLE9 AR934X_GPIO_BASE + 0x68 +#define AR934X_GPIO_FUNCTION AR934X_GPIO_BASE + 0x6C #define GPIO_OUT_FUNCTION1_ENABLE_GPIO_7_MSB 31 #define GPIO_OUT_FUNCTION1_ENABLE_GPIO_7_LSB 24