[LEDE-DEV] Problem trying to add support for Comfast E312A

Bill Moffitt bmoffitt at ayrstone.com
Mon Nov 20 11:23:25 PST 2017


I have been trying to put together a patch to support this device (5 
GHz. directional - like UBNT NanoStation M5), but I have run into a bug 
I can't seem to figure out.

Using the changes below, I have been able to get the system up and 
running, the radio appears to be working properly and all but *one* of 
the LEDs appear to be working. Note: I have not checked the reset button 
and the power switch.

With this patch applied, the third signal strength light (GPIO 16) acts 
strangely. It is on when it boots, and it stays on - forever. It cannot 
be turned off. It appears to be controlled by something else - whatever 
I send to /sys/class/cf-e312a:white:signal3/brightness the light never 
changes:

[signal 3 light is on]

root at LEDE:/sys/class/leds# cat cf-e312a:white:signal3/brightness
0

[signal 3 light is on]

root at LEDE:/sys/class/leds# echo 1 >cf-e312a:white:signal3/brightness

[signal 3 light is on]

root at LEDE:/sys/class/leds# cat cf-e312a:white:signal3/brightness
1
root at LEDE:/sys/class/leds# echo 0 >cf-e312a:white:signal3/brightness

[signal 3 light is on]

root at LEDE:/sys/class/leds# cat cf-e312a:white:signal3/brightness
0

The other odd thing is that, despite the fact I am initializing all the 
LEDs as " .active_low     = 1," the other LEDs appear to be initializing 
"hi" with only GPIO 16 initializing as "lo" -

root at LEDE:/sys/kernel/debug# cat gpio
gpiochip0: GPIOs 0-31, parent: platform/ath79-gpio, ath79-gpio:
  gpio-0   (                    |cf-e312a:white:wlan ) out hi
  gpio-1   (                    |cf-e312a:sda        ) out lo
  gpio-2   (                    |cf-e312a:white:lan  ) out hi
  gpio-3   (                    |cf-e312a:white:wan  ) out lo
  gpio-11  (                    |suite button        ) in  hi
  gpio-12  (                    |cf-e312a:scl        ) out lo
  gpio-14  (                    |cf-e312a:white:signa) out hi
  gpio-15  (                    |cf-e312a:white:signa) out hi
  gpio-16  (                    |cf-e312a:white:signa) out lo
  gpio-17  (                    |cf-e312a:white:signa) out hi
  gpio-19  (                    |PT7A7514 watchdog   ) out hi
  gpio-22  (                    |reset               ) in  hi

gpiochip1: GPIOs 489-511, parent: platform/ar934x_wmac, ath9k-phy0:
  gpio-490 (                    |ath9k-phy0          ) in  hi

I asked the folks at Comfast, and they assured me this is the right gpio 
for that light. I also tried all the other GPIOs using the "blink" 
script at https://wiki.openwrt.org/doc/hardware/port.gpio and verified 
none of them caused the state of that LED to change.

It is ENTIRELY POSSIBLE I screwed something up... I just cannot find it. 
Any assistance will be greatly appreciated.

Here's the patch as it exists now:

diff --git a/target/linux/ar71xx/base-files/etc/board.d/01_leds 
b/target/linux/ar71xx/base-files/etc/board.d/01_leds
index e101d55..1c506d0 100755
--- a/target/linux/ar71xx/base-files/etc/board.d/01_leds
+++ b/target/linux/ar71xx/base-files/etc/board.d/01_leds
@@ -182,6 +182,11 @@ carambola2)
         ucidef_set_led_netdev "wan" "WAN" "$board:orange:eth1" "eth1"
         ucidef_set_led_wlan "wlan" "WLAN" "$board:green:wlan" "phy0tpt"
         ;;
+cf-e312a)
+       ucidef_set_led_netdev "lan" "LAN" "$board:white:lan" "eth0"
+       ucidef_set_led_netdev "wan" "WAN" "$board:white:wan" "eth1"
+       ucidef_set_led_wlan "wlan" "WLAN" "$board:white:wlan" "phy0tpt"
+       ;;
  cf-e316n-v2)
         ucidef_set_led_netdev "lan" "LAN" "$board:blue:lan" "eth0"
         ucidef_set_led_netdev "wan" "WAN" "$board:blue:wan" "eth1"
diff --git a/target/linux/ar71xx/base-files/etc/diag.sh 
b/target/linux/ar71xx/base-files/etc/diag.sh
index 5ef620b..6274841 100644
--- a/target/linux/ar71xx/base-files/etc/diag.sh
+++ b/target/linux/ar71xx/base-files/etc/diag.sh
@@ -118,6 +118,7 @@ get_status_led() {
         cap4200ag)
                 status_led="senao:green:pwr"
                 ;;
+       cf-e312a|\
         cf-e316n-v2|\
         cf-e520n|\
         cf-e530n)
diff --git a/target/linux/ar71xx/base-files/lib/ar71xx.sh 
b/target/linux/ar71xx/base-files/lib/ar71xx.sh
index 9903563..98ed277 100755
--- a/target/linux/ar71xx/base-files/lib/ar71xx.sh
+++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh
@@ -504,6 +504,9 @@ ar71xx_board_detect() {
         *"Carambola2"*)
                 name="carambola2"
                 ;;
+       *"CF-E312A")
+               name="cf-e312a"
+               ;;
         *"CF-E316N v2")
                 name="cf-e316n-v2"
                 ;;
diff --git a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh 
b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
index 18e5e41..1b13230 100755
--- a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
@@ -215,6 +215,7 @@ platform_check_image() {
         bullet-m|\
         c-55|\
         carambola2|\
+       cf-e312a|\
         cf-e316n-v2|\
         cf-e320n-v2|\
         cf-e355ac|\
diff --git a/target/linux/ar71xx/config-4.4 b/target/linux/ar71xx/config-4.4
index 4793bf4..e86837f 100644
--- a/target/linux/ar71xx/config-4.4
+++ b/target/linux/ar71xx/config-4.4
@@ -67,6 +67,7 @@ CONFIG_ATH79_MACH_C55=y
  CONFIG_ATH79_MACH_CAP324=y
  CONFIG_ATH79_MACH_CAP4200AG=y
  CONFIG_ATH79_MACH_CARAMBOLA2=y
+CONFIG_ATH79_MACH_CF_E312A=y
  CONFIG_ATH79_MACH_CF_E316N_V2=y
  CONFIG_ATH79_MACH_CF_E320N_V2=y
  CONFIG_ATH79_MACH_CF_E355AC=y
diff --git a/target/linux/ar71xx/config-4.9 b/target/linux/ar71xx/config-4.9
index 84b2a0b..231e78e 100644
--- a/target/linux/ar71xx/config-4.9
+++ b/target/linux/ar71xx/config-4.9
@@ -65,6 +65,7 @@ CONFIG_ATH79_MACH_C55=y
  CONFIG_ATH79_MACH_CAP324=y
  CONFIG_ATH79_MACH_CAP4200AG=y
  CONFIG_ATH79_MACH_CARAMBOLA2=y
+CONFIG_ATH79_MACH_CF_E312A=y
  CONFIG_ATH79_MACH_CF_E316N_V2=y
  CONFIG_ATH79_MACH_CF_E320N_V2=y
  CONFIG_ATH79_MACH_CF_E355AC=y
diff --git a/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt 
b/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt
index 5cb4f7e..e0484f2 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt
+++ b/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt
@@ -2021,6 +2021,16 @@ config ATH79_MACH_RAMBUTAN
         select ATH79_DEV_USB
         select ATH79_DEV_WMAC

+config ATH79_MACH_CF_E312A
+       bool "COMFAST CF-E312A support"
+       select SOC_AR934X
+       select ATH79_DEV_ETH
+       select ATH79_DEV_GPIO_BUTTONS
+       select ATH79_DEV_LEDS_GPIO
+       select ATH79_DEV_M25P80
+       select ATH79_DEV_USB
+       select ATH79_DEV_WMAC
+
  config ATH79_MACH_CF_E316N_V2
         bool "COMFAST CF-E316N v2 support"
         select SOC_AR934X
diff --git a/target/linux/ar71xx/files/arch/mips/ath79/Makefile 
b/target/linux/ar71xx/files/arch/mips/ath79/Makefile
index 7d12282..3cf8e69 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/Makefile
+++ b/target/linux/ar71xx/files/arch/mips/ath79/Makefile
@@ -74,6 +74,7 @@ obj-$(CONFIG_ATH79_MACH_C60)                  += 
mach-c60.o
  obj-$(CONFIG_ATH79_MACH_CAP324)                        += mach-cap324.o
  obj-$(CONFIG_ATH79_MACH_CAP4200AG)             += mach-cap4200ag.o
  obj-$(CONFIG_ATH79_MACH_CARAMBOLA2)            += mach-carambola2.o
+obj-$(CONFIG_ATH79_MACH_CF_E312A)              += mach-cf-e316n-v2.o
  obj-$(CONFIG_ATH79_MACH_CF_E316N_V2)           += mach-cf-e316n-v2.o
  obj-$(CONFIG_ATH79_MACH_CF_E320N_V2)           += mach-cf-e316n-v2.o
  obj-$(CONFIG_ATH79_MACH_CF_E355AC)             += mach-cf-e316n-v2.o
diff --git 
a/target/linux/ar71xx/files/arch/mips/ath79/mach-cf-e316n-v2.c 
b/target/linux/ar71xx/files/arch/mips/ath79/mach-cf-e316n-v2.c
index 82fe83f..42b6a6e 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/mach-cf-e316n-v2.c
+++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-cf-e316n-v2.c
@@ -1,5 +1,6 @@
  /*
   *  Support for COMFAST boards:
+ *  - CF-E312A (AR9341)
   *  - CF-E316N v2 (AR9341)
   *  - CF-E320N v2 (QCA9531)
   *  - CF-E355AC (QCA9531)
@@ -36,6 +37,80 @@
  #define CF_EXXXN_KEYS_POLL_INTERVAL    20
  #define CF_EXXXN_KEYS_DEBOUNCE_INTERVAL        (3 * 
CF_EXXXN_KEYS_POLL_INTERVAL)

+/* CF-E312A */
+#define CF_E312A_GPIO_LED_LAN           2
+#define CF_E312A_GPIO_LED_WAN           3
+#define CF_E312A_GPIO_LED_WLAN          0
+#define CF_E312A_GPIO_LED_SIGNAL1       14
+#define CF_E312A_GPIO_LED_SIGNAL2       15
+#define CF_E312A_GPIO_LED_SIGNAL3       16
+#define CF_E312A_GPIO_LED_SIGNAL4       17
+#define CF_E312A_GPIO_BTN_SUITE         11
+#define CF_E312A_GPIO_BTN_RESET         22
+#define CF_E312A_GPIO_SDA               1
+#define CF_E312A_GPIO_SCL               12
+
+#define CF_E312A_GPIO_XWDT_TRIGGER      19
+
+static struct gpio_led cf_e312a_leds_gpio[] __initdata = {
+       {
+               .name           = "cf-e312a:white:lan",
+               .gpio           = CF_E312A_GPIO_LED_LAN,
+               .active_low     = 0,
+       }, {
+               .name           = "cf-e312a:white:wan",
+               .gpio           = CF_E312A_GPIO_LED_WAN,
+               .active_low     = 0,
+       }, {
+               .name           = "cf-e312a:white:wlan",
+               .gpio           = CF_E312A_GPIO_LED_WLAN,
+               .active_low     = 1,
+       }, {
+               .name           = "cf-e312a:white:signal1",
+               .gpio           = CF_E312A_GPIO_LED_SIGNAL1,
+               .active_low     = 1,
+       }, {
+               .name           = "cf-e312a:white:signal2",
+               .gpio           = CF_E312A_GPIO_LED_SIGNAL2,
+               .active_low     = 1,
+    }, {
+               .name           = "cf-e312a:white:signal3",
+               .gpio           = CF_E312A_GPIO_LED_SIGNAL3,
+               .active_low     = 1,
+       }, {
+               .name           = "cf-e312a:white:signal4",
+               .gpio           = CF_E312A_GPIO_LED_SIGNAL4,
+               .active_low     = 1,
+
+       }, {
+               .name           = "cf-e312a:sda",
+               .gpio           = CF_E312A_GPIO_SDA,
+               .active_low     = 0,
+    }, {
+               .name           = "cf-e312a:scl",
+               .gpio           = CF_E312A_GPIO_SCL,
+               .active_low     = 0,
+       },
+};
+
+static struct gpio_keys_button cf_e312a_gpio_keys[] __initdata = {
+       {
+               .desc           = "reset",
+               .type           = EV_KEY,
+               .code           = KEY_RESTART,
+               .debounce_interval = CF_EXXXN_KEYS_DEBOUNCE_INTERVAL,
+               .gpio           = CF_E312A_GPIO_BTN_RESET,
+               .active_low     = 0,
+       }, {
+               .desc           = "suite button",
+               .type           = EV_KEY,
+               .code           = KEY_POWER,
+               .debounce_interval = CF_EXXXN_KEYS_DEBOUNCE_INTERVAL,
+               .gpio           = CF_E312A_GPIO_BTN_SUITE,
+               .active_low     = 1,
+    },
+};
+
  /* CF-E316N v2 */
  #define CF_E316N_V2_GPIO_LED_DIAG_B    0
  #define CF_E316N_V2_GPIO_LED_DIAG_R    2
@@ -290,6 +365,47 @@ static void __init cf_exxxn_common_setup(unsigned 
long art_ofs, int gpio_wdt)
         ath79_register_usb();
  }

+static void __init cf_e312a_setup(void)
+{
+       u8 *mac = (u8 *) KSEG1ADDR(0x1f010000);
+
+       cf_exxxn_common_setup(0x10000, CF_E312A_GPIO_XWDT_TRIGGER);
+
+       ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_PHY_SWAP);
+
+       ath79_register_mdio(1, 0x0);
+
+       /* GMAC0 is connected to the PHY0 of the internal switch */
+       ath79_switch_data.phy4_mii_en = 1;
+       ath79_switch_data.phy_poll_mask = BIT(0);
+       ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
+       ath79_eth0_data.phy_mask = BIT(0);
+       ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
+       ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
+       ath79_register_eth(0);
+
+       /* GMAC1 is connected to the internal switch */
+       ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
+       ath79_init_mac(ath79_eth1_data.mac_addr, mac, 2);
+       ath79_register_eth(1);
+
+       /* Don't Enable 2x Skyworks SE2576L WLAN power amplifiers
+       gpio_request_one(CF_E316N_V2_GPIO_EXTERNAL_PA0, GPIOF_OUT_INIT_HIGH,
+                        "WLAN PA0");
+       gpio_request_one(CF_E316N_V2_GPIO_EXTERNAL_PA1, GPIOF_OUT_INIT_HIGH,
+                        "WLAN PA1"); */
+
+       ath79_register_leds_gpio(-1, ARRAY_SIZE(cf_e312a_leds_gpio),
+                                cf_e312a_leds_gpio);
+
+       ath79_register_gpio_keys_polled(1, CF_EXXXN_KEYS_POLL_INTERVAL,
+ ARRAY_SIZE(cf_e312a_gpio_keys),
+                                       cf_e312a_gpio_keys);
+}
+
+MIPS_MACHINE(ATH79_MACH_CF_E312A, "CF-E312A", "COMFAST CF-E312A",
+            cf_e312a_setup);
+
  static void __init cf_e316n_v2_setup(void)
  {
         u8 *mac = (u8 *) KSEG1ADDR(0x1f010000);
diff --git a/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h 
b/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h
index 01472b6..949c5fd 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h
+++ b/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h
@@ -60,6 +60,7 @@ enum ath79_mach_type {
         ATH79_MACH_CAP324,                      /* PowerCloud CAP324 */
         ATH79_MACH_CAP4200AG,                   /* Senao CAP4200AG */
         ATH79_MACH_CARAMBOLA2,                  /* 8devices Carambola2 */
+       ATH79_MACH_CF_E312A,                    /* COMFAST CF-E312A */
         ATH79_MACH_CF_E316N_V2,                 /* COMFAST CF-E316N v2 */
         ATH79_MACH_CF_E320N_V2,                 /* COMFAST CF-E320N v2 */
         ATH79_MACH_CF_E355AC,                   /* COMFAST CF-E355AC */
diff --git a/target/linux/ar71xx/image/generic.mk 
b/target/linux/ar71xx/image/generic.mk
index 3c5fcc3..134360a 100644
--- a/target/linux/ar71xx/image/generic.mk
+++ b/target/linux/ar71xx/image/generic.mk
@@ -135,6 +135,14 @@ define Device/carambola2
  endef
  TARGET_DEVICES += carambola2

+define Device/cf-e312a
+  DEVICE_TITLE := COMFAST CF-E312A
+  BOARDNAME := CF-E312A
+  IMAGE_SIZE := 16192k
+  MTDPARTS := 
spi0.0:64k(u-boot)ro,64k(art)ro,16192k(firmware),64k(art-backup)ro
+endef
+TARGET_DEVICES += cf-e312a
+
  define Device/cf-e316n-v2
    DEVICE_TITLE := COMFAST CF-E316N v2
    BOARDNAME := CF-E316N-V2


Thanks,

Bill




More information about the Lede-dev mailing list