hiwifi_r33.patch 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. From 72f3df2ae3d841447cba8188d48b90d91325b284 Mon Sep 17 00:00:00 2001
  2. From: zfdx123 <[email protected]>
  3. Date: Thu, 26 Jan 2023 12:49:13 +0800
  4. Subject: [PATCH] ramips: MT7620 add Support HiWiFi R33(C312B B52)
  5. ---
  6. .../generic/files/drivers/net/phy/rtl8367b.c | 9 +
  7. .../linux/ramips/dts/mt7620a_hiwifi_r33.dts | 235 ++++++++++++++++++
  8. target/linux/ramips/image/mt7620.mk | 22 ++
  9. .../mt7620/base-files/etc/board.d/01_leds | 3 +
  10. .../mt7620/base-files/etc/board.d/02_network | 13 +
  11. .../etc/hotplug.d/ieee80211/10_fix_wifi_mac | 33 +++
  12. .../mt7620/base-files/lib/upgrade/platform.sh | 3 +
  13. 7 files changed, 318 insertions(+)
  14. create mode 100644 target/linux/ramips/dts/mt7620a_hiwifi_r33.dts
  15. create mode 100644 target/linux/ramips/mt7620/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
  16. diff --git a/target/linux/generic/files/drivers/net/phy/rtl8367b.c b/target/linux/generic/files/drivers/net/phy/rtl8367b.c
  17. index 3599791a517b..6297e07628ba 100644
  18. --- a/target/linux/generic/files/drivers/net/phy/rtl8367b.c
  19. +++ b/target/linux/generic/files/drivers/net/phy/rtl8367b.c
  20. @@ -263,6 +263,8 @@ struct rtl8367b_initval {
  21. u16 val;
  22. };
  23. +u32 rtl_device_id;
  24. +
  25. #define RTL8367B_MIB_RXB_ID 0 /* IfInOctets */
  26. #define RTL8367B_MIB_TXB_ID 28 /* IfOutOctets */
  27. @@ -612,6 +614,10 @@ static int rtl8367b_write_initvals(struct rtl8366_smi *smi,
  28. int err;
  29. int i;
  30. + if (rtl_device_id == 0x0020) {
  31. + return 0;
  32. + }
  33. +
  34. for (i = 0; i < count; i++)
  35. REG_WR(smi, initvals[i].reg, initvals[i].val);
  36. @@ -1540,7 +1546,10 @@ static int rtl8367b_detect(struct rtl8366_smi *smi)
  37. return ret;
  38. }
  39. + rtl_device_id = chip_ver;
  40. +
  41. switch (chip_ver) {
  42. + case 0x0020:
  43. case 0x1000:
  44. chip_name = "8367RB";
  45. break;
  46. diff --git a/target/linux/ramips/dts/mt7620a_hiwifi_r33.dts b/target/linux/ramips/dts/mt7620a_hiwifi_r33.dts
  47. new file mode 100644
  48. index 000000000000..6761b1b68a06
  49. --- /dev/null
  50. +++ b/target/linux/ramips/dts/mt7620a_hiwifi_r33.dts
  51. @@ -0,0 +1,234 @@
  52. +#include "mt7620a.dtsi"
  53. +
  54. +#include <dt-bindings/gpio/gpio.h>
  55. +#include <dt-bindings/input/input.h>
  56. +
  57. +/ {
  58. + compatible = "hiwifi,r33", "ralink,mt7620a-soc";
  59. + model = "HiWiFi R33";
  60. +
  61. + chosen {
  62. + bootargs = "console=ttyS0,115200";
  63. + };
  64. +
  65. + aliases {
  66. + led-boot = &led_system;
  67. + led-failsafe = &led_system;
  68. + led-running = &led_system;
  69. + led-upgrade = &led_system;
  70. + };
  71. +
  72. + nand {
  73. + status = "okay";
  74. + #address-cells = <1>;
  75. + #size-cells = <1>;
  76. + compatible = "mtk,mt7620-nand";
  77. +
  78. + partitions {
  79. + compatible = "fixed-partitions";
  80. + #address-cells = <1>;
  81. + #size-cells = <1>;
  82. +
  83. + partition@0 {
  84. + label = "u-boot";
  85. + reg = <0x0 0x80000>;
  86. + read-only;
  87. + };
  88. +
  89. + partition@80000 {
  90. + label = "debug";
  91. + reg = <0x80000 0x80000>;
  92. + read-only;
  93. + };
  94. +
  95. + factory: partition@100000 {
  96. + label = "factory";
  97. + reg = <0x100000 0x40000>;
  98. + read-only;
  99. + };
  100. +
  101. + partition@140000 {
  102. + label = "kernel";
  103. + reg = <0x140000 0x400000>;
  104. + };
  105. +
  106. + ubiconcat0: partition@540000 {
  107. + label = "ubiconcat0";
  108. + reg = <0x540000 0x1c80000>;
  109. + };
  110. +
  111. + bdinfo: partition@21c0000 {
  112. + label = "bdinfo";
  113. + reg = <0x21c0000 0x80000>;
  114. + read-only;
  115. + };
  116. +
  117. + ubiconcat1: partition@2240000 {
  118. + label = "ubiconcat1";
  119. + reg = <0x2240000 0x5dc0000>;
  120. + };
  121. + };
  122. + };
  123. +
  124. + ubi-concat {
  125. + compatible = "mtd-concat";
  126. + devices = <&ubiconcat0 &ubiconcat1>;
  127. +
  128. + partitions {
  129. + compatible = "fixed-partitions";
  130. + #address-cells = <1>;
  131. + #size-cells = <1>;
  132. +
  133. + partition@0 {
  134. + label = "ubi";
  135. + reg = <0x0 0x7a40000>;
  136. + };
  137. + };
  138. + };
  139. +
  140. + leds {
  141. + compatible = "gpio-leds";
  142. +
  143. + wlan5g {
  144. + label = "blue:wlan5g";
  145. + gpios = <&gpio0 7 GPIO_ACTIVE_LOW>;
  146. + linux,default-trigger = "phy0tpt";
  147. + };
  148. +
  149. + led_system: system {
  150. + label = "blue:system";
  151. + gpios = <&gpio0 9 GPIO_ACTIVE_LOW>;
  152. + };
  153. +
  154. + turbo {
  155. + label = "blue:turbo";
  156. + gpios = <&gpio0 10 GPIO_ACTIVE_LOW>;
  157. + linux,default-trigger = "none";
  158. + };
  159. +
  160. + wlan2g {
  161. + label = "blue:wlan2g";
  162. + gpios = <&gpio0 11 GPIO_ACTIVE_LOW>;
  163. + linux,default-trigger = "phy1tpt";
  164. + };
  165. +
  166. + internet {
  167. + label = "blue:internet";
  168. + gpios = <&gpio3 0 GPIO_ACTIVE_LOW>;
  169. + };
  170. + };
  171. +
  172. + keys {
  173. + compatible = "gpio-keys";
  174. +
  175. + reset {
  176. + label = "reset";
  177. + gpios = <&gpio0 12 GPIO_ACTIVE_HIGH>;
  178. + linux,code = <KEY_RESTART>;
  179. + };
  180. + };
  181. +
  182. + gpio_export {
  183. + compatible = "gpio-export";
  184. + #size-cells = <0>;
  185. +
  186. + usbpower {
  187. + gpio-export,name = "usbpower";
  188. + gpio-export,output = <0>;
  189. + gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
  190. + };
  191. + };
  192. +
  193. + rtl8367rb {
  194. + compatible = "realtek,rtl8367b", "rtl8367b";
  195. + cpu_port = <6>;
  196. + realtek,extif1 = <1 0 1 1 1 1 1 1 2>;
  197. + mii-bus = <&mdio0>;
  198. + };
  199. +};
  200. +
  201. +&gpio3 {
  202. + status = "okay";
  203. +};
  204. +
  205. +&ehci {
  206. + status = "okay";
  207. +};
  208. +
  209. +&ohci {
  210. + status = "okay";
  211. +};
  212. +
  213. +&pcie {
  214. + status = "okay";
  215. +};
  216. +
  217. +&gsw {
  218. + mediatek,port4-gmac;
  219. + mediatek,ephy-base = /bits/ 8 <12>;
  220. +};
  221. +
  222. +&ethernet {
  223. + pinctrl-names = "default";
  224. + pinctrl-0 = <&rgmii1_pins &rgmii2_pins &mdio_pins>;
  225. +
  226. + nvmem-cells = <&macaddr_bdinfo_18a>;
  227. + nvmem-cell-names = "mac-address-ascii";
  228. +
  229. + port@5 {
  230. + status = "okay";
  231. + mediatek,fixed-link = <1000 1 1 1>;
  232. + phy-handle = <&phy5>;
  233. + phy-mode = "rgmii";
  234. + };
  235. +
  236. + mdio0: mdio-bus {
  237. + status = "okay";
  238. +
  239. + phy5: ethernet-phy@5 {
  240. + reg = <5>;
  241. + phy-mode = "rgmii";
  242. + };
  243. + };
  244. +};
  245. +
  246. +&wmac {
  247. + pinctrl-names = "default", "pa_gpio";
  248. + pinctrl-0 = <&pa_pins>;
  249. + pinctrl-1 = <&pa_gpio_pins>;
  250. + ralink,mtd-eeprom = <&factory 0x0>;
  251. +
  252. + nvmem-cells = <&macaddr_bdinfo_18a>;
  253. + nvmem-cell-names = "mac-address-ascii";
  254. + mac-address-increment = <1>;
  255. +};
  256. +
  257. +&pcie0 {
  258. + wifi@0,0 {
  259. + compatible = "pci14c3,7662";
  260. + reg = <0x0000 0 0 0 0>;
  261. + mediatek,mtd-eeprom = <&factory 0x8000>;
  262. + ieee80211-freq-limit = <5000000 6000000>;
  263. +
  264. + nvmem-cells = <&macaddr_bdinfo_18a>;
  265. + nvmem-cell-names = "mac-address-ascii";
  266. + mac-address-increment = <2>;
  267. + };
  268. +};
  269. +
  270. +&state_default {
  271. + gpio {
  272. + groups = "uartf", "wled";
  273. + function = "gpio";
  274. + };
  275. +};
  276. +
  277. +&bdinfo {
  278. + compatible = "nvmem-cells";
  279. + #address-cells = <1>;
  280. + #size-cells = <1>;
  281. +
  282. + macaddr_bdinfo_18a: macaddr@18a {
  283. + reg = <0x18a 0x11>;
  284. + };
  285. +};
  286. diff --git a/target/linux/ramips/image/mt7620.mk b/target/linux/ramips/image/mt7620.mk
  287. index 631e5043f411..c68b9a69c60d 100644
  288. --- a/target/linux/ramips/image/mt7620.mk
  289. +++ b/target/linux/ramips/image/mt7620.mk
  290. @@ -1338,3 +1338,25 @@ define Device/zyxel_keenetic-viva
  291. SUPPORTED_DEVICES += kng_rc
  292. endef
  293. TARGET_DEVICES += zyxel_keenetic-viva
  294. +
  295. +
  296. +define Device/hiwifi_r33
  297. + SOC := mt7620a
  298. + DEVICE_VENDOR := HiWiFi
  299. + DEVICE_MODEL := R33
  300. + DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport \
  301. + kmod-switch-rtl8366-smi kmod-switch-rtl8367b kmod-mt76x2
  302. + BLOCKSIZE := 128k
  303. + PAGESIZE := 2048
  304. + KERNEL_SIZE := 4096k
  305. + UBINIZE_OPTS := -E 5
  306. + IMAGE_SIZE := 32768k
  307. + IMAGES += kernel.bin rootfs.bin factory.bin
  308. + IMAGE/kernel.bin := append-kernel | check-size $$$$(KERNEL_SIZE)
  309. + IMAGE/rootfs.bin := append-ubi | check-size $$$$(IMAGE_SIZE)
  310. + IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
  311. + IMAGE/factory.bin := append-kernel | pad-to $$(KERNEL_SIZE) | append-ubi | \
  312. + check-size
  313. + SUPPORTED_DEVICES += r33
  314. +endef
  315. +TARGET_DEVICES += hiwifi_r33
  316. \ No newline at end of file
  317. diff --git a/target/linux/ramips/mt7620/base-files/etc/board.d/01_leds b/target/linux/ramips/mt7620/base-files/etc/board.d/01_leds
  318. index 53487d752688..1240b0efdae4 100644
  319. --- a/target/linux/ramips/mt7620/base-files/etc/board.d/01_leds
  320. +++ b/target/linux/ramips/mt7620/base-files/etc/board.d/01_leds
  321. @@ -112,6 +112,9 @@ hiwifi,hc5761)
  322. hiwifi,hc5861)
  323. ucidef_set_led_switch "internet" "internet" "blue:internet" "switch0" "0x20"
  324. ;;
  325. +hiwifi,r33)
  326. + ucidef_set_led_switch "internet" "internet" "blue:internet" "switch1" "0x01"
  327. + ;;
  328. hnet,c108)
  329. ucidef_set_led_netdev "lan" "lan" "green:lan" "eth0"
  330. ucidef_set_led_netdev "modem" "modem" "green:modem" "wwan0"
  331. diff --git a/target/linux/ramips/mt7620/base-files/etc/board.d/02_network b/target/linux/ramips/mt7620/base-files/etc/board.d/02_network
  332. index 00ffb1b5420c..5f4e7268e8a9 100644
  333. --- a/target/linux/ramips/mt7620/base-files/etc/board.d/02_network
  334. +++ b/target/linux/ramips/mt7620/base-files/etc/board.d/02_network
  335. @@ -156,6 +156,13 @@ ramips_setup_interfaces()
  336. ucidef_add_switch "switch0" \
  337. "0:lan" "1:lan" "5:wan" "6@eth0"
  338. ;;
  339. + hiwifi,r33)
  340. + ucidef_add_switch "switch0" \
  341. + "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0"
  342. + ucidef_add_switch_attr "switch0" "enable" "false"
  343. + ucidef_add_switch "switch1" \
  344. + "1:lan" "2:lan" "0:wan" "6@eth0"
  345. + ;;
  346. iodata,wn-ac1167gr|\
  347. iodata,wn-ac733gr3|\
  348. iptime,a1004ns)
  349. @@ -336,6 +343,12 @@ ramips_setup_macs()
  350. [ -n "$lan_mac" ] || lan_mac=$(cat /sys/class/net/eth0/address)
  351. wan_mac=$(macaddr_add "$lan_mac" 1)
  352. ;;
  353. + hiwifi,r33)
  354. + lan_mac=$(mtd_get_mac_ascii bdinfo "Vfac_mac ")
  355. + label_mac=$lan_mac
  356. + [ -n "$lan_mac" ] || lan_mac=$(cat /sys/class/net/eth0/address)
  357. + wan_mac=$(macaddr_add "$lan_mac" 1)
  358. + ;;
  359. iodata,wn-ac1167gr|\
  360. iodata,wn-ac733gr3)
  361. wan_mac=$(mtd_get_mac_ascii u-boot-env wanaddr)
  362. diff --git a/target/linux/ramips/mt7620/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac b/target/linux/ramips/mt7620/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
  363. index aa0ad99158271..c7b818a0af7c0 100644
  364. --- a/target/linux/ramips/mt7620/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
  365. +++ b/target/linux/ramips/mt7620/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
  366. @@ -23,4 +23,11 @@ case "$board" in
  367. [ "$PHYNBR" = "0" ] && [ -n "$label_mac" ] && \
  368. macaddr_unsetbit "$label_mac" 6 > /sys${DEVPATH}/macaddress
  369. ;;
  370. + hiwifi,r33)
  371. + label_mac=$(mtd_get_mac_ascii bdinfo "Vfac_mac ")
  372. + [ "$PHYNBR" = "1" ] && [ -n "$label_mac" ] && \
  373. + echo -n "$label_mac" > /sys${DEVPATH}/macaddress
  374. + [ "$PHYNBR" = "0" ] && [ -n "$label_mac" ] && \
  375. + macaddr_unsetbit "$label_mac" 6 > /sys${DEVPATH}/macaddress
  376. + ;;
  377. esac
  378. diff --git a/target/linux/ramips/mt7620/base-files/lib/upgrade/platform.sh b/target/linux/ramips/mt7620/base-files/lib/upgrade/platform.sh
  379. index 40272d4a744d..e4f83fd8ccb5 100755
  380. --- a/target/linux/ramips/mt7620/base-files/lib/upgrade/platform.sh
  381. +++ b/target/linux/ramips/mt7620/base-files/lib/upgrade/platform.sh
  382. @@ -35,6 +35,9 @@ platform_do_upgrade() {
  383. dd if=/dev/mtd0 bs=64 count=1 2>/dev/null | grep -qi breed && CI_KERNPART_EXT="kernel_stock"
  384. nand_do_upgrade "$1"
  385. ;;
  386. + hiwifi,r33)
  387. + nand_do_upgrade "$1"
  388. + ;;
  389. *)
  390. default_do_upgrade "$1"
  391. ;;