From b4cc242d8ee7cc6d481139d52c9091841e1af74a Mon Sep 17 00:00:00 2001 From: Zoltan HERPAI Date: Tue, 5 May 2020 17:09:35 +0200 Subject: [PATCH] ar71xx: bring back Atheros AP83 support I still have a (working!) AP83-040 board, so let's bring back support for it. Changes since it was dropped: - WLAN LED isn't working, "fixme" - hardcoded flash layout was added back into the mach file - sysupgrade is "fixme" - the flash mechanism and the custom SPI driver was not modernized, but they compile and work. Other than these notes, the board is working as expected. Signed-off-by: Zoltan HERPAI --- .../ar71xx/base-files/etc/board.d/01_leds | 3 + .../ar71xx/base-files/etc/board.d/02_network | 1 + target/linux/ar71xx/base-files/etc/diag.sh | 1 + target/linux/ar71xx/base-files/lib/ar71xx.sh | 3 + .../ar71xx/base-files/lib/upgrade/platform.sh | 1 + target/linux/ar71xx/config-4.14 | 2 + .../files/arch/mips/ath79/Kconfig.openwrt | 8 + .../ar71xx/files/arch/mips/ath79/Makefile | 1 + .../ar71xx/files/arch/mips/ath79/mach-ap83.c | 277 ++++++++++++++++++ .../ar71xx/files/arch/mips/ath79/machtypes.h | 1 + target/linux/ar71xx/generic/config-default | 1 + .../ar71xx/image/generic-legacy-devices.mk | 7 + target/linux/ar71xx/image/legacy.mk | 2 + 13 files changed, 308 insertions(+) create mode 100644 target/linux/ar71xx/files/arch/mips/ath79/mach-ap83.c 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 54727a6e52..2c6cbc74f5 100755 --- a/target/linux/ar71xx/base-files/etc/board.d/01_leds +++ b/target/linux/ar71xx/base-files/etc/board.d/01_leds @@ -18,6 +18,9 @@ a60) ucidef_set_led_default "status-red" "Status (red)" "a60:red:status" "0" ucidef_set_led_default "status-blue" "Status (blue)" "a60:blue:status" "0" ;; +ap83) + ucidef_set_led_wlan "wlan" "WLAN" "$board:green:wlan" "phy0tpt" + ;; airgateway|\ airgatewaypro) ucidef_set_led_wlan "wlan" "WLAN" "ubnt:blue:wlan" "phy0tpt" diff --git a/target/linux/ar71xx/base-files/etc/board.d/02_network b/target/linux/ar71xx/base-files/etc/board.d/02_network index 1487ff58de..8c0f5b4e9b 100755 --- a/target/linux/ar71xx/base-files/etc/board.d/02_network +++ b/target/linux/ar71xx/base-files/etc/board.d/02_network @@ -161,6 +161,7 @@ ar71xx_setup_interfaces() a60|\ alfa-ap96|\ alfa-nx|\ + ap83|\ dr344|\ gl-ar150|\ gl-ar300m|\ diff --git a/target/linux/ar71xx/base-files/etc/diag.sh b/target/linux/ar71xx/base-files/etc/diag.sh index 1a92ad927d..35216e3f1e 100644 --- a/target/linux/ar71xx/base-files/etc/diag.sh +++ b/target/linux/ar71xx/base-files/etc/diag.sh @@ -64,6 +64,7 @@ get_status_led() { ap135-020) status_led="ap135:green:status" ;; + ap83|\ archer-c25-v1|\ archer-c58-v1|\ archer-c59-v1|\ diff --git a/target/linux/ar71xx/base-files/lib/ar71xx.sh b/target/linux/ar71xx/base-files/lib/ar71xx.sh index 044ef4eae5..5e33ba6ba2 100755 --- a/target/linux/ar71xx/base-files/lib/ar71xx.sh +++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh @@ -682,6 +682,9 @@ ar71xx_board_detect() { *"Atheros AP96") name="ap96" ;; + *"Atheros AP83") + name="ap83" + ;; *"AW-NR580") name="aw-nr580" ;; diff --git a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh index eb812865db..d7aa40a118 100755 --- a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh +++ b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh @@ -344,6 +344,7 @@ platform_check_image() { ap136-020|\ ap147-010|\ ap152|\ + ap83|\ ap91-5g|\ ap96|\ arduino-yun|\ diff --git a/target/linux/ar71xx/config-4.14 b/target/linux/ar71xx/config-4.14 index 9a524fae43..4f3703cfc2 100644 --- a/target/linux/ar71xx/config-4.14 +++ b/target/linux/ar71xx/config-4.14 @@ -46,6 +46,7 @@ CONFIG_ATH79=y # CONFIG_ATH79_MACH_AP152 is not set # CONFIG_ATH79_MACH_AP531B0 is not set # CONFIG_ATH79_MACH_AP81 is not set +# CONFIG_ATH79_MACH_AP83 is not set # CONFIG_ATH79_MACH_AP90Q is not set # CONFIG_ATH79_MACH_AP91_5G is not set # CONFIG_ATH79_MACH_AP96 is not set @@ -463,6 +464,7 @@ CONFIG_SERIAL_8250_RUNTIME_UARTS=1 # CONFIG_SOC_QCA955X is not set # CONFIG_SOC_QCA956X is not set CONFIG_SPI=y +CONFIG_SPI_AP83=y CONFIG_SPI_ATH79=y CONFIG_SPI_BITBANG=y CONFIG_SPI_GPIO=y diff --git a/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt b/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt index 6fd78c46a0..de59b001ce 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt +++ b/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt @@ -216,6 +216,14 @@ config ATH79_MACH_AP531B0 select ATH79_DEV_USB select ATH79_DEV_WMAC +config ATH79_MACH_AP83 + bool "Atheros AP83 board support" + select SOC_AR913X + select ATH79_DEV_GPIO_BUTTONS + select ATH79_DEV_LEDS_GPIO + select ATH79_DEV_USB + select ATH79_DEV_WMAC + config ATH79_MACH_AP90Q bool "YunCore AP80Q/AP90Q support" select SOC_QCA953X diff --git a/target/linux/ar71xx/files/arch/mips/ath79/Makefile b/target/linux/ar71xx/files/arch/mips/ath79/Makefile index 0265b3d818..1ff6a5f893 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/Makefile +++ b/target/linux/ar71xx/files/arch/mips/ath79/Makefile @@ -56,6 +56,7 @@ obj-$(CONFIG_ATH79_MACH_AP143) += mach-ap143.o obj-$(CONFIG_ATH79_MACH_AP147) += mach-ap147.o obj-$(CONFIG_ATH79_MACH_AP152) += mach-ap152.o obj-$(CONFIG_ATH79_MACH_AP531B0) += mach-ap531b0.o +obj-$(CONFIG_ATH79_MACH_AP83) += mach-ap83.o obj-$(CONFIG_ATH79_MACH_AP90Q) += mach-ap90q.o obj-$(CONFIG_ATH79_MACH_AP91_5G) += mach-ap91-5g.o obj-$(CONFIG_ATH79_MACH_AP96) += mach-ap96.o diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-ap83.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-ap83.c new file mode 100644 index 0000000000..053d17d661 --- /dev/null +++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-ap83.c @@ -0,0 +1,277 @@ +/* + * Atheros AP83 board support + * + * Copyright (C) 2008-2012 Gabor Juhos + * Copyright (C) 2008 Imre Kaloz + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "dev-eth.h" +#include "dev-gpio-buttons.h" +#include "dev-leds-gpio.h" +#include "dev-usb.h" +#include "dev-wmac.h" +#include "machtypes.h" + +#define AP83_GPIO_LED_WLAN 6 +#define AP83_GPIO_LED_POWER 14 +#define AP83_GPIO_LED_JUMPSTART 15 +#define AP83_GPIO_BTN_JUMPSTART 12 +#define AP83_GPIO_BTN_RESET 21 + +#define AP83_050_GPIO_VSC7385_CS 1 +#define AP83_050_GPIO_VSC7385_MISO 3 +#define AP83_050_GPIO_VSC7385_MOSI 16 +#define AP83_050_GPIO_VSC7385_SCK 17 + +#define AP83_KEYS_POLL_INTERVAL 20 /* msecs */ +#define AP83_KEYS_DEBOUNCE_INTERVAL (3 * AP83_KEYS_POLL_INTERVAL) + +static struct mtd_partition ap83_flash_partitions[] = { + { + .name = "u-boot", + .offset = 0, + .size = 0x040000, + .mask_flags = MTD_WRITEABLE, + }, { + .name = "u-boot-env", + .offset = 0x040000, + .size = 0x020000, + .mask_flags = MTD_WRITEABLE, + }, { + .name = "rootfs", + .offset = 0x060000, + .size = 0x400000, + }, { + .name = "kernel", + .offset = 0x460000, + .size = 0x390000, + }, { + .name = "art", + .offset = 0x7f0000, + .size = 0x010000, + .mask_flags = MTD_WRITEABLE, + }, { + .name = "firmware", + .offset = 0x060000, + .size = 0x790000, + } +}; + +static struct physmap_flash_data ap83_flash_data = { + .width = 2, + .parts = ap83_flash_partitions, + .nr_parts = ARRAY_SIZE(ap83_flash_partitions), +}; + +static struct resource ap83_flash_resources[] = { + [0] = { + .start = AR71XX_SPI_BASE, + .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1, + .flags = IORESOURCE_MEM, + }, +}; + +static struct platform_device ap83_flash_device = { + .name = "physmap-flash", + .id = -1, + .resource = ap83_flash_resources, + .num_resources = ARRAY_SIZE(ap83_flash_resources), + .dev = { + .platform_data = &ap83_flash_data, + } +}; + +static struct gpio_led ap83_leds_gpio[] __initdata = { + { + .name = "ap83:green:jumpstart", + .gpio = AP83_GPIO_LED_JUMPSTART, + .active_low = 0, + }, { + .name = "ap83:green:power", + .gpio = AP83_GPIO_LED_POWER, + .active_low = 0, + }, { + .name = "ap83:green:wlan", + .gpio = AP83_GPIO_LED_WLAN, + .active_low = 0, + }, +}; + +static struct gpio_keys_button ap83_gpio_keys[] __initdata = { + { + .desc = "soft_reset", + .type = EV_KEY, + .code = KEY_RESTART, + .debounce_interval = AP83_KEYS_DEBOUNCE_INTERVAL, + .gpio = AP83_GPIO_BTN_RESET, + .active_low = 1, + }, { + .desc = "jumpstart", + .type = EV_KEY, + .code = KEY_WPS_BUTTON, + .debounce_interval = AP83_KEYS_DEBOUNCE_INTERVAL, + .gpio = AP83_GPIO_BTN_JUMPSTART, + .active_low = 1, + } +}; + +static struct resource ap83_040_spi_resources[] = { + [0] = { + .start = AR71XX_SPI_BASE, + .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1, + .flags = IORESOURCE_MEM, + }, +}; + +static struct platform_device ap83_040_spi_device = { + .name = "ap83-spi", + .id = 0, + .resource = ap83_040_spi_resources, + .num_resources = ARRAY_SIZE(ap83_040_spi_resources), +}; + +static struct spi_gpio_platform_data ap83_050_spi_data = { + .miso = AP83_050_GPIO_VSC7385_MISO, + .mosi = AP83_050_GPIO_VSC7385_MOSI, + .sck = AP83_050_GPIO_VSC7385_SCK, + .num_chipselect = 1, +}; + +static struct platform_device ap83_050_spi_device = { + .name = "spi_gpio", + .id = 0, + .dev = { + .platform_data = &ap83_050_spi_data, + } +}; + +static void ap83_vsc7385_reset(void) +{ + ath79_device_reset_set(AR71XX_RESET_GE1_PHY); + udelay(10); + ath79_device_reset_clear(AR71XX_RESET_GE1_PHY); + mdelay(50); +} + +static struct vsc7385_platform_data ap83_vsc7385_data = { + .reset = ap83_vsc7385_reset, + .ucode_name = "vsc7385_ucode_ap83.bin", + .mac_cfg = { + .tx_ipg = 6, + .bit2 = 0, + .clk_sel = 3, + }, +}; + +static struct spi_board_info ap83_spi_info[] = { + { + .bus_num = 0, + .chip_select = 0, + .max_speed_hz = 25000000, + .modalias = "spi-vsc7385", + .platform_data = &ap83_vsc7385_data, + .controller_data = (void *) AP83_050_GPIO_VSC7385_CS, + } +}; + +static void __init ap83_generic_setup(void) +{ + u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000); + + ath79_register_mdio(0, 0xfffffffe); + + ath79_init_mac(ath79_eth0_data.mac_addr, eeprom, 0); + ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII; + ath79_eth0_data.phy_mask = 0x1; + + ath79_register_eth(0); + + ath79_init_mac(ath79_eth1_data.mac_addr, eeprom, 1); + ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII; + ath79_eth1_data.speed = SPEED_1000; + ath79_eth1_data.duplex = DUPLEX_FULL; + + ath79_eth1_pll_data.pll_1000 = 0x1f000000; + + ath79_register_eth(1); + + ath79_register_leds_gpio(-1, ARRAY_SIZE(ap83_leds_gpio), + ap83_leds_gpio); + + ath79_register_gpio_keys_polled(-1, AP83_KEYS_POLL_INTERVAL, + ARRAY_SIZE(ap83_gpio_keys), + ap83_gpio_keys); + + ath79_register_usb(); + + ath79_register_wmac(eeprom, NULL); + + platform_device_register(&ap83_flash_device); + + spi_register_board_info(ap83_spi_info, ARRAY_SIZE(ap83_spi_info)); +} + +static void ap83_040_flash_lock(struct platform_device *pdev) +{ + ath79_flash_acquire(); +} + +static void ap83_040_flash_unlock(struct platform_device *pdev) +{ + ath79_flash_release(); +} + +static void __init ap83_040_setup(void) +{ + ap83_flash_data.lock = ap83_040_flash_lock; + ap83_flash_data.unlock = ap83_040_flash_unlock; + ap83_generic_setup(); + platform_device_register(&ap83_040_spi_device); +} + +static void __init ap83_050_setup(void) +{ + ap83_generic_setup(); + platform_device_register(&ap83_050_spi_device); +} + +static void __init ap83_setup(void) +{ + u8 *board_id = (u8 *) KSEG1ADDR(0x1fff1244); + unsigned int board_version; + + board_version = (unsigned int)(board_id[0] - '0'); + board_version += ((unsigned int)(board_id[1] - '0')) * 10; + + printk(KERN_WARNING "Board is AP83-%03u\n", board_version); + + switch (board_version) { + case 40: + ap83_040_setup(); + break; + case 50: + ap83_050_setup(); + break; + default: + printk(KERN_WARNING "AP83-%03u board is not yet supported\n", + board_version); + } +} + +MIPS_MACHINE(ATH79_MACH_AP83, "AP83", "Atheros AP83", ap83_setup); diff --git a/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h b/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h index 900b4ec87b..ee4afad19f 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h +++ b/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h @@ -40,6 +40,7 @@ enum ath79_mach_type { ATH79_MACH_AP147_010, /* Atheros AP147-010 reference board */ ATH79_MACH_AP152, /* Atheros AP152 reference board */ ATH79_MACH_AP531B0, /* Rockeetech AP531B0 */ + ATH79_MACH_AP83, /* Atheros AP83 */ ATH79_MACH_AP90Q, /* YunCore AP80Q/AP90Q */ ATH79_MACH_AP91_5G, /* ALFA Network AP91-5G */ ATH79_MACH_AP96, /* Atheros AP96 */ diff --git a/target/linux/ar71xx/generic/config-default b/target/linux/ar71xx/generic/config-default index 25b58ae91e..85b58db3ff 100644 --- a/target/linux/ar71xx/generic/config-default +++ b/target/linux/ar71xx/generic/config-default @@ -24,6 +24,7 @@ CONFIG_ATH79_MACH_AP143=y CONFIG_ATH79_MACH_AP147=y CONFIG_ATH79_MACH_AP152=y CONFIG_ATH79_MACH_AP531B0=y +CONFIG_ATH79_MACH_AP83=y CONFIG_ATH79_MACH_AP90Q=y CONFIG_ATH79_MACH_AP91_5G=y CONFIG_ATH79_MACH_AP96=y diff --git a/target/linux/ar71xx/image/generic-legacy-devices.mk b/target/linux/ar71xx/image/generic-legacy-devices.mk index cbe039cd29..7fdd30d248 100644 --- a/target/linux/ar71xx/image/generic-legacy-devices.mk +++ b/target/linux/ar71xx/image/generic-legacy-devices.mk @@ -21,6 +21,13 @@ define LegacyDevice/TUBE2H8M endef LEGACY_DEVICES += TUBE2H8M +define LegacyDevice/AP83 + DEVICE_TITLE := Atheros AP83 reference board + DEVICE_PACKAGES := kmod-usb-core kmod-usb2 \ + vsc7385-ucode-ap83 vsc7395-ucode-ap83 +endef +LEGACY_DEVICES += AP83 + define LegacyDevice/AP96 DEVICE_TITLE := Atheros AP96 reference board DEVICE_PACKAGES := kmod-usb2 diff --git a/target/linux/ar71xx/image/legacy.mk b/target/linux/ar71xx/image/legacy.mk index 926ce780b4..83ba046840 100644 --- a/target/linux/ar71xx/image/legacy.mk +++ b/target/linux/ar71xx/image/legacy.mk @@ -227,6 +227,7 @@ alfa_mtdlayout_8M=mtdparts=spi0.0:256k(u-boot)ro,64k(u-boot-env)ro,6144k(rootfs) alfa_mtdlayout_16M=mtdparts=spi0.0:256k(u-boot)ro,64k(u-boot-env)ro,15936k(firmware),64k(nvram),64k(art)ro all0258n_mtdlayout=mtdparts=spi0.0:256k(u-boot)ro,64k(u-boot-env),6272k(firmware),1536k(failsafe),64k(art)ro all0315n_mtdlayout=mtdparts=spi0.0:256k(u-boot)ro,256k(u-boot-env),13568k(firmware),2048k(failsafe),256k(art)ro +ap83_mtdlayout=mtdparts=spi0.0:256k(u-boot)ro,128k(u-boot-env)ro,4096k(rootfs),3648k(kernel),64k(art)ro,7744k@0x60000(firmware) ap96_mtdlayout=mtdparts=spi0.0:192k(u-boot)ro,64k(u-boot-env)ro,6144k(rootfs),1728k(kernel),64k(art)ro,7872k@0x40000(firmware) ap121_mtdlayout_8M=mtdparts=spi0.0:256k(u-boot)ro,64k(u-boot-env)ro,6144k(rootfs),1600k(kernel),64k(nvram),64k(art)ro,7744k@0x50000(firmware) ap121_mtdlayout_16M=mtdparts=spi0.0:256k(u-boot)ro,64k(u-boot-env)ro,10944k(rootfs),4992k(kernel),64k(nvram),64k(art)ro,15936k@0x50000(firmware) @@ -882,6 +883,7 @@ $(eval $(call SingleProfile,AthLzma,64k,ALFAAP120C,alfa-ap120c,ALFA-AP120C,ttyS0 $(eval $(call SingleProfile,AthLzma,64k,ALFAAP96,alfa-ap96,ALFA-AP96,ttyS0,115200,$$(alfa_ap96_mtdlayout),RKuImage)) $(eval $(call SingleProfile,AthLzma,64k,ALL0258N,all0258n,ALL0258N,ttyS0,115200,$$(all0258n_mtdlayout),KRuImage,65536)) $(eval $(call SingleProfile,AthLzma,256k,ALL0315N,all0315n,ALL0315N,ttyS0,115200,$$(all0315n_mtdlayout),KRuImage,262144)) +$(eval $(call SingleProfile,AthGzip,64k,AP83,ap83,AP83,ttyS0,115200,$$(ap83_mtdlayout),RKuImage)) $(eval $(call SingleProfile,AthLzma,64k,AP121_8M,ap121-8M,AP121,ttyATH0,115200,$$(ap121_mtdlayout_8M),RKuImage)) $(eval $(call SingleProfile,AthLzma,64k,AP121_16M,ap121-16M,AP121,ttyATH0,115200,$$(ap121_mtdlayout_16M),RKuImage)) $(eval $(call SingleProfile,AthLzma,64k,AP132,ap132,AP132,ttyS0,115200,$$(ap132_mtdlayout),KRuImage)) -- 2.30.2