ar71xx: add support for TP-Link TL-WR902AC v1
[openwrt/openwrt.git] / target / linux / ar71xx / base-files / etc / hotplug.d / firmware / 11-ath10k-caldata
1 #!/bin/sh
2
3 ath10kcal_die() {
4 echo "ath10cal: " "$*"
5 exit 1
6 }
7
8 ath10kcal_from_file() {
9 local source=$1
10 local offset=$2
11 local count=$3
12
13 dd if=$source of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
14 ath10kcal_die "failed to extract calibration data from $source"
15 }
16
17 ath10kcal_extract() {
18 local part=$1
19 local offset=$2
20 local count=$3
21 local mtd
22
23 mtd=$(find_mtd_chardev $part)
24 [ -n "$mtd" ] || \
25 ath10kcal_die "no mtd device found for partition $part"
26
27 dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
28 ath10kcal_die "failed to extract calibration data from $mtd"
29 }
30
31 ath10kcal_patch_mac() {
32 local mac=$1
33
34 [ -z "$mac" ] && return
35
36 macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=6 count=6
37 }
38
39 [ -e /lib/firmware/$FIRMWARE ] && exit 0
40
41 . /lib/ar71xx.sh
42 . /lib/functions.sh
43 . /lib/functions/system.sh
44
45 board=$(ar71xx_board_name)
46
47 case "$FIRMWARE" in
48 "ath10k/cal-pci-0000:00:00.0.bin")
49 case $board in
50 a40|\
51 a60|\
52 mr1750|\
53 mr1750v2|\
54 om5p-acv2)
55 ath10kcal_extract "ART" 20480 2116
56 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +16)
57 ;;
58 archer-c25-v1|\
59 archer-c59-v1|\
60 archer-c60-v1|\
61 tl-wdr6500-v2)
62 ath10kcal_extract "art" 20480 2116
63 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -2)
64 ;;
65 cf-e380ac-v1|\
66 cf-e380ac-v2|\
67 dlan-pro-1200-ac|\
68 sr3200|\
69 xd3200)
70 ath10kcal_extract "art" 20480 2116
71 ;;
72 dap-2695-a1)
73 ath10kcal_extract "radiocfg" 20480 2116
74 ath10kcal_patch_mac $(mtd_get_mac_ascii bdcfg wlanmac_a)
75 ;;
76 dir-869-a1|\
77 qihoo-c301)
78 ath10kcal_extract "radiocfg" 20480 2116
79 ath10kcal_patch_mac $(mtd_get_mac_ascii devdata wlan5mac)
80 ;;
81 dw33d)
82 ath10kcal_extract "art" 20480 2116
83 ath10kcal_patch_mac $(mtd_get_mac_binary art 18)
84 ;;
85 epg5000|\
86 esr1750)
87 ath10kcal_extract "caldata" 20480 2116
88 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +1)
89 ;;
90 mc-mac1200r)
91 ath10kcal_extract "art" 20480 2116
92 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -1)
93 ;;
94 r6100)
95 ath10kcal_extract "caldata" 20480 2116
96 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) +2)
97 ;;
98 rb-952ui-5ac2nd)
99 ath10kcal_from_file "/sys/firmware/routerboot/ext_wlan_data" 20480 2116
100 ;;
101 re450|\
102 tl-wr902ac-v1)
103 ath10kcal_extract "art" 20480 2116
104 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) -2)
105 ;;
106 tl-wpa8630)
107 ath10kcal_extract "art" 20480 2116
108 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +1)
109 ;;
110 unifiac-lite|\
111 unifiac-pro)
112 ath10kcal_extract "EEPROM" 20480 2116
113 ;;
114 esac
115 ;;
116 "ath10k/cal-pci-0000:01:00.0.bin")
117 case $board in
118 archer-c5|\
119 archer-c7)
120 ath10kcal_extract "art" 20480 2116
121 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -2)
122 ;;
123 nbg6616|\
124 nbg6716)
125 ath10kcal_extract "RFdata" 20480 2116
126 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -2)
127 ;;
128 om5p-ac)
129 ath10kcal_extract "ART" 20480 2116
130 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +16)
131 ;;
132 rb-911g-5hpacd|\
133 rb-962uigs-5hact2hnt)
134 ath10kcal_from_file "/sys/firmware/routerboot/ext_wlan_data" 20480 2116
135 ;;
136 esac
137 ;;
138 "ath10k/pre-cal-pci-0000:00:00.0.bin")
139 case $board in
140 archer-c58-v1)
141 ath10kcal_extract "art" 20480 12064
142 ;;
143 esac
144 ;;
145 *)
146 exit 1
147 ;;
148 esac