ar71xx: image: simplify Embedded Wireless definitions
[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/functions.sh
42 . /lib/functions/system.sh
43
44 board=$(board_name)
45
46 case "$FIRMWARE" in
47 "ath10k/cal-pci-0000:00:00.0.bin")
48 case $board in
49 a40|\
50 a60|\
51 mr1750|\
52 mr1750v2|\
53 om5p-acv2)
54 ath10kcal_extract "ART" 20480 2116
55 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +16)
56 ;;
57 archer-c25-v1|\
58 tl-wdr6500-v2)
59 ath10kcal_extract "art" 20480 2116
60 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -2)
61 ;;
62 archer-c7-v4)
63 ath10kcal_extract "art" 20480 2116
64 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) -1)
65 ;;
66 cf-e355ac|\
67 cf-e380ac-v1|\
68 cf-e380ac-v2|\
69 dlan-pro-1200-ac|\
70 e1700ac-v2|\
71 e600gac-v2|\
72 sr3200|\
73 xd3200)
74 ath10kcal_extract "art" 20480 2116
75 ;;
76 dap-2695-a1)
77 ath10kcal_extract "radiocfg" 20480 2116
78 ath10kcal_patch_mac $(mtd_get_mac_ascii bdcfg wlanmac_a)
79 ;;
80 dir-869-a1|\
81 qihoo-c301)
82 ath10kcal_extract "radiocfg" 20480 2116
83 ath10kcal_patch_mac $(mtd_get_mac_ascii devdata wlan5mac)
84 ;;
85 dw33d)
86 ath10kcal_extract "art" 20480 2116
87 ath10kcal_patch_mac $(mtd_get_mac_binary art 18)
88 ;;
89 epg5000|\
90 esr1750)
91 ath10kcal_extract "caldata" 20480 2116
92 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +1)
93 ;;
94 gl-ar750|\
95 tl-wpa8630)
96 ath10kcal_extract "art" 20480 2116
97 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +1)
98 ;;
99 mc-mac1200r)
100 ath10kcal_extract "art" 20480 2116
101 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -1)
102 ;;
103 r6100)
104 ath10kcal_extract "caldata" 20480 2116
105 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) +2)
106 ;;
107 rb-952ui-5ac2nd|\
108 rb-wapg-5hact2hnd)
109 ath10kcal_from_file "/sys/firmware/routerboot/ext_wlan_data" 20480 2116
110 ;;
111 re355|\
112 re450|\
113 tl-wr902ac-v1)
114 ath10kcal_extract "art" 20480 2116
115 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) -2)
116 ;;
117 unifiac-lite|\
118 unifiac-pro)
119 ath10kcal_extract "EEPROM" 20480 2116
120 ;;
121 wi2a-ac200i)
122 ath10kcal_extract "ART" 20480 2116
123 ;;
124 esac
125 ;;
126 "ath10k/cal-pci-0000:01:00.0.bin")
127 case $board in
128 archer-c5|\
129 archer-c7)
130 ath10kcal_extract "art" 20480 2116
131 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -2)
132 ;;
133 nbg6616|\
134 nbg6716)
135 ath10kcal_extract "RFdata" 20480 2116
136 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -2)
137 ;;
138 om5p-ac)
139 ath10kcal_extract "ART" 20480 2116
140 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +16)
141 ;;
142 rb-911g-5hpacd|\
143 rb-921gs-5hpacd-r2|\
144 rb-962uigs-5hact2hnt)
145 ath10kcal_from_file "/sys/firmware/routerboot/ext_wlan_data" 20480 2116
146 ;;
147 wlr8100)
148 ath10kcal_extract "art" 20480 2116
149 ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_ascii u-boot-env ethaddr) +1)
150 ;;
151 esac
152 ;;
153 "ath10k/pre-cal-pci-0000:00:00.0.bin")
154 case $board in
155 archer-c58-v1|\
156 archer-c59-v1|\
157 archer-c60-v1|\
158 cf-e355ac-v2|\
159 cf-e375ac)
160 ath10kcal_extract "art" 20480 12064
161 ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \
162 /lib/firmware/ath10k/QCA9888/hw2.0/board.bin
163 ;;
164 esac
165 ;;
166 *)
167 exit 1
168 ;;
169 esac