From patchwork Sat Apr 18 16:02:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chuanhong Guo X-Patchwork-Id: 462375 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A013B140308 for ; Sun, 19 Apr 2015 02:03:17 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="verification failed; unprotected key" header.d=gmail.com header.i=@gmail.com header.b=T9RzY5Mh; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 793E7280342; Sat, 18 Apr 2015 18:02:11 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, T_DKIM_INVALID autolearn=no version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 7D8CD280091 for ; Sat, 18 Apr 2015 18:02:05 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 CL_IP_EQ_HELO_IP=-2 (check from: .gmail. - helo: .mail-pa0-f44.google. - helo-domain: .google.) FROM/MX_MATCHES_HELO(DOMAIN)=-2; rate: -8.5 Received: from mail-pa0-f44.google.com (mail-pa0-f44.google.com [209.85.220.44]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Sat, 18 Apr 2015 18:02:04 +0200 (CEST) Received: by pacyx8 with SMTP id yx8so157976928pac.1 for ; Sat, 18 Apr 2015 09:02:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=He/AXB9NLzcUvxHWycRaoxu54vN4ZC4YzDkw156NwW0=; b=T9RzY5Mhz1aqF1ebdEvmW++jskP/9/mV5DF9u28l4s4T1IsezfVLRdYsGDwC9qOnqh R2SF1Ffkcokk7/eAB12XIoSOcHSS0PGqcZRzpEmdluZ01180Igf3jU2tanj8dHfpeIGB rcG3WGXGuMypeUFvYYyHMTcr1yq/t8tJGaMCYIPWOoYwjO9eNP4fiUZY46zSthCr/aNT /FT3W9ifBeRby9A4TTGAqXLYaXViPuzcCDkcw2J632m43fjXlU04RraWyz5uuBMwsO/p 8oYG4zoGZxVgltevbryqmcZmVDK+5WmtyOLdV5QXh4yztWaFyPyuXDFhNLgdykfbuDlu C7Lg== X-Received: by 10.68.88.196 with SMTP id bi4mr14678715pbb.130.1429372977771; Sat, 18 Apr 2015 09:02:57 -0700 (PDT) Received: from guoguopc-lan.lan ([23.244.64.204]) by mx.google.com with ESMTPSA id w6sm13280102pbt.60.2015.04.18.09.02.55 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Apr 2015 09:02:56 -0700 (PDT) From: =?UTF-8?q?=E9=83=AD=E4=BC=A0=E9=88=9C?= To: openwrt-devel@lists.openwrt.org Date: Sun, 19 Apr 2015 00:02:45 +0800 Message-Id: <1429372965-21327-1-git-send-email-gch981213@gmail.com> X-Mailer: git-send-email 2.1.0 MIME-Version: 1.0 Subject: [OpenWrt-Devel] [PATCH][RFC] ramips:Add support for HiWiFi HC5761. X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" Hi,all! I'm trying to add support for HiWiFi HC5761 router,This patch works fine.Because the mac address is not saved in factory partition and I think my way to deal with this problem is not so good,I hope I could get some suggestions for this patch. HiWiFi HC5761 is a dual band router with mt7620a SoC.It has 3 network interface,SD card and USB. There is an MT7610E for 5G wireless but there is no open-source driver to support this.I enabled the PCI-E interface so that I could use the proprietary driver from MTK. MAC address is not in factory partition.It is defined in bdinfo partition in ascii format. With 'strings' command we could see such a line:Vfac_mac = XX:XX:XX:XX:XX:XX There is a space between 'Vfac_mac' and '=' so 'mtd_get_mac_ascii' function in /lib/functions/system.sh doesn't work.I copied the function and added a space in the sed command. Because of the mac address,the calibration data for wireless should't be read from mtd partition directly.I used the hotplug script to generate the calibration data for the wireless driver. I think I added too much code for the MAC address:-( I wonder if there is a better way to do this. Best regards. Guo Chuanhong Signed-off-by: 郭传鈜 --- target/linux/ramips/base-files/etc/board.d/01_leds | 5 + .../linux/ramips/base-files/etc/board.d/02_network | 20 +++ target/linux/ramips/base-files/etc/diag.sh | 3 + .../etc/hotplug.d/firmware/10-rt2x00-eeprom | 39 +++++- target/linux/ramips/base-files/lib/ramips.sh | 3 + .../ramips/base-files/lib/upgrade/platform.sh | 1 + target/linux/ramips/dts/HiWiFi-HC5761.dts | 155 +++++++++++++++++++++ target/linux/ramips/image/Makefile | 3 + 8 files changed, 228 insertions(+), 1 deletion(-) create mode 100644 target/linux/ramips/dts/HiWiFi-HC5761.dts diff --git a/target/linux/ramips/base-files/etc/board.d/01_leds b/target/linux/ramips/base-files/etc/board.d/01_leds index 56ba3b7..e20732d 100755 --- a/target/linux/ramips/base-files/etc/board.d/01_leds +++ b/target/linux/ramips/base-files/etc/board.d/01_leds @@ -222,6 +222,11 @@ case $board in set_usb_led "wr8305rt:usb" set_wifi_led "wr8305rt:wifi" ;; + hiwifi-hc5761) + ucidef_set_led_default "system" "system" "hiwifi:blue:system" "1" + ucidef_set_led_netdev "internet" "internet" "hiwifi:blue:internet" "eth0.2" + set_wifi_led "hiwifi:blue:wlan-2p4" + ;; wt1520) set_wifi_led "rt2800pci-phy0::radio" ;; diff --git a/target/linux/ramips/base-files/etc/board.d/02_network b/target/linux/ramips/base-files/etc/board.d/02_network index 24e1ba8..615baa4 100755 --- a/target/linux/ramips/base-files/etc/board.d/02_network +++ b/target/linux/ramips/base-files/etc/board.d/02_network @@ -223,6 +223,7 @@ ramips_setup_interfaces() ucidef_add_switch_vlan "switch0" "2" "4 6t" ;; + hiwifi-hc5761 | \ y1s) ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2" ucidef_add_switch "switch0" "1" "1" @@ -288,6 +289,25 @@ ramips_setup_macs() wan_mac=$(macaddr_add "$lan_mac" 4) ;; + hiwifi-hc5761) + local part + local mac_dirty + + part=$(find_mtd_part "bdinfo") + if [ -z "$part" ]; then + echo "hiwifi_get_mac: partition bdinfo not found!" >&2 + return + fi + + mac_dirty=$(strings "$part" | sed -n 's/^'"Vfac_mac "'=//p') + + # "canonicalize" mac + [ -n "$mac_dirty" ] && { + lan_mac=$(macaddr_canonicalize "$mac_dirty") + } + wan_mac=$(macaddr_add "$lan_mac" 1) + ;; + m3 |\ m4 |\ x5 |\ diff --git a/target/linux/ramips/base-files/etc/diag.sh b/target/linux/ramips/base-files/etc/diag.sh index 5301593..e66336f 100644 --- a/target/linux/ramips/base-files/etc/diag.sh +++ b/target/linux/ramips/base-files/etc/diag.sh @@ -220,6 +220,9 @@ get_status_led() { na930) status_led="na930:blue:power" ;; + hiwifi-hc5761) + status_led="hiwifi:blue:system" + ;; y1 | \ y1s) status_led="lenovo:blue:power" diff --git a/target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom b/target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom index 0cd95a5..ce7171c 100644 --- a/target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom +++ b/target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom @@ -21,6 +21,37 @@ rt2x00_eeprom_extract() { rt2x00_eeprom_die "failed to extract from $mtd" } +hiwifi_eeprom_extract() { + local part=$1 + local offset=$2 + local mac_addr=$3 + local mtd + + . /lib/functions.sh + . /lib/functions/system.sh + mtd=$(find_mtd_part $part) + [ -n "$mtd" ] || exit 1 + dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=4 + macaddr_2bin $mac_addr >> /lib/firmware/$FIRMWARE + dd if=$mtd bs=1 skip=$(echo $offset | awk '{print $1+10}') count=502 >> /lib/firmware/$FIRMWARE +} + +hiwifi_get_mac() +{ + local part + local mac_dirty + part=$(find_mtd_part "bdinfo") + if [ -z "$part" ]; then + echo "hiwifi_get_mac: partition bdinfo not found!" >&2 + return + fi + mac_dirty=$(strings "$part" | sed -n 's/^'"Vfac_mac "'=//p') + # "canonicalize" mac + [ -n "$mac_dirty" ] && { + macaddr_canonicalize "$mac_dirty" + } +} + FW="/lib/firmware/$FIRMWARE" [ -e "$FW" ] && exit 0 @@ -36,7 +67,13 @@ case "$FIRMWARE" in ;; esac ;; - +"hiwifi_wlan24_caldata.eeprom") + case $board in + hiwifi-hc5761) + hiwifi_eeprom_extract "factory" 0 $(hiwifi_get_mac) + ;; + esac + ;; "rt2x00pci_1_0.eeprom") case $board in cy-swr1100) diff --git a/target/linux/ramips/base-files/lib/ramips.sh b/target/linux/ramips/base-files/lib/ramips.sh index 616f4a1..0509678 100755 --- a/target/linux/ramips/base-files/lib/ramips.sh +++ b/target/linux/ramips/base-files/lib/ramips.sh @@ -385,6 +385,9 @@ ramips_board_detect() { *"ZTE Q7") name="zte-q7" ;; + *"HiWiFi HC5761") + name="hiwifi-hc5761" + ;; *"Lenovo Y1") name="y1" ;; diff --git a/target/linux/ramips/base-files/lib/upgrade/platform.sh b/target/linux/ramips/base-files/lib/upgrade/platform.sh index 17b456b..463ed94 100755 --- a/target/linux/ramips/base-files/lib/upgrade/platform.sh +++ b/target/linux/ramips/base-files/lib/upgrade/platform.sh @@ -53,6 +53,7 @@ platform_check_image() { freestation5 | \ firewrt |\ hg255d | \ + hiwifi-hc5761 |\ hlk-rm04 | \ ht-tm02 | \ hw550-3g | \ diff --git a/target/linux/ramips/dts/HiWiFi-HC5761.dts b/target/linux/ramips/dts/HiWiFi-HC5761.dts new file mode 100644 index 0000000..2c6c4d7 --- /dev/null +++ b/target/linux/ramips/dts/HiWiFi-HC5761.dts @@ -0,0 +1,155 @@ +/dts-v1/; + +/include/ "mt7620a.dtsi" + +/ { + compatible = "HiWiFi-HC5761", "ralink,mt7620a-soc"; + model = "HiWiFi HC5761"; + + chosen { + bootargs = "console=ttyS0,115200"; + }; + + palmbus@10000000 { + sysc@0 { + ralink,gpiomux = "i2c", "jtag"; + ralink,uartmux = "gpio"; + ralink,wdtmux = <1>; + }; + gpio0: gpio@600 { + status = "okay"; + }; + gpio3: gpio@688 { + status = "okay"; + }; + + spi@b00 { + status = "okay"; + + m25p80@0 { + #address-cells = <1>; + #size-cells = <1>; + compatible = "w25q128"; + reg = <0 0>; + linux,modalias = "m25p80", "w25q128"; + spi-max-frequency = <10000000>; + + partition@0 { + label = "u-boot"; + reg = <0x0 0x30000>; + read-only; + }; + + partition@30000 { + label = "u-boot-env"; + reg = <0x30000 0x10000>; + read-only; + }; + + factory: partition@40000 { + label = "factory"; + reg = <0x40000 0x10000>; + read-only; + }; + + partition@50000 { + label = "firmware"; + reg = <0x50000 0xf80000>; + }; + + partition@fd0000 { + label = "hwf_config"; + reg = <0xfd0000 0x10000>; + }; + + partition@fe0000 { + label = "bdinfo"; + reg = <0xfe0000 0x10000>; + }; + + partition@ff0000 { + label = "backup"; + reg = <0xff0000 0x10000>; + }; + }; + }; + }; + + ehci@101c0000 { + status = "okay"; + }; + + ohci@101c1000 { + status = "okay"; + }; + + sdhci@10130000 { + status = "okay"; + }; + + pcie@10140000 { + status = "okay"; + }; + + wmac@10180000 { + ralink,eeprom = "hiwifi_wlan24_caldata.eeprom"; + }; + + pinctrl { + state_default: pinctrl0 { + gpio { + ralink,group = "uartf", "wled", "nd_sd"; + ralink,function = "gpio"; + }; + }; + }; + + ethernet@10100000 { + pinctrl-names = "default"; + pinctrl-0 = <&ephy_pins>; + ralink,port-map = "llllw"; + }; + + gpio-keys-polled { + compatible = "gpio-keys-polled"; + #address-cells = <1>; + #size-cells = <0>; + poll-interval = <20>; + reset { + label = "reset"; + gpios = <&gpio0 12 1>; + linux,code = <0x198>; + }; + }; + + gpio-leds { + compatible = "gpio-leds"; + system { + label = "hiwifi:blue:system"; + gpios = <&gpio0 9 1>; + }; + internet { + label = "hiwifi:blue:internet"; + gpios = <&gpio0 11 1>; + }; + wlan2p4 { + label = "hiwifi:blue:wlan-2p4"; + gpios = <&gpio3 0 1>; + }; + wlan5p { + label = "hiwifi:blue:wlan-5p"; + gpios = <&gpio0 7 1>; + }; + }; + + gpio_export { + compatible = "gpio-export"; + #size-cells = <0>; + usbpower { + gpio-export,name = "usbpower"; + gpio-export,output = <1>; + gpios = <&gpio0 13 0>; + }; + }; + +}; diff --git a/target/linux/ramips/image/Makefile b/target/linux/ramips/image/Makefile index e6b5112..5a29447 100644 --- a/target/linux/ramips/image/Makefile +++ b/target/linux/ramips/image/Makefile @@ -852,6 +852,8 @@ Image/Build/Profile/DIR-810L=$(call BuildFirmware/CustomFlash/$(1),$(1),dir-810l na930_mtd_size=20971520 Image/Build/Profile/NA930=$(call BuildFirmware/CustomFlash/$(1),$(1),na930,NA930,$(na930_mtd_size)) Image/Build/Profile/MZK-750DHP=$(call BuildFirmware/Default8M/$(1),$(1),mzk-750dhp,MZK-750DHP) +hiwifi_16m_mtd_size=16252928 +Image/Build/Profile/HiWiFi-HC5761=$(call BuildFirmware/CustomFlash/$(1),$(1),hiwifi-hc5761,HiWiFi-HC5761,$(hiwifi_16m_mtd_size)) Image/Build/Profile/Y1=$(call BuildFirmware/Default16M/$(1),$(1),Lenovo-y1,Y1) Image/Build/Profile/Y1S=$(call BuildFirmware/Default16M/$(1),$(1),Lenovo-y1s,Y1S) Image/Build/Profile/MLW221=$(call BuildFirmware/Default16M/$(1),$(1),mlw221,MLW221) @@ -884,6 +886,7 @@ define Image/Build/Profile/Default $(call Image/Build/Profile/WHR1166D,$(1)) $(call Image/Build/Profile/MZK-750DHP,$(1)) $(call Image/Build/Profile/NA930,$(1)) + $(call Image/Build/Profile/HiWiFi-HC5761,$(1)) $(call Image/Build/Profile/Y1,$(1)) $(call Image/Build/Profile/Y1S,$(1)) $(call Image/Build/Profile/MLW221,$(1))