mpc85xx: use the generic board detect
[lede-git/.git] / target / linux / mpc85xx / base-files / etc / hotplug.d / firmware / 10-ath9k-eeprom
1 #!/bin/sh
2
3 FW_FILE="/lib/firmware/$FIRMWARE"
4
5 ath9k_eeprom_die() {
6         echo "ath9k eeprom: " "$*" >&2
7         exit 1
8 }
9
10 ath9k_eeprom_extract() {
11         local part=$1
12         local offset=$2
13         local count=$3
14         local mtd
15
16         mtd=$(find_mtd_chardev $part)
17         [ -n "$mtd" ] || \
18                 ath9k_eeprom_die "no mtd device found for partition $part"
19
20         dd if=$mtd bs=$offset skip=1 count=1 2>/dev/null | dd of=$FW_FILE bs=$count count=1 2>/dev/null || \
21                 ath9k_eeprom_die "failed to extract from $mtd"
22 }
23
24 tpl_set_wireless_mac()
25 {
26         local offset=$1
27         local mac
28
29         mac=$(mtd_get_mac_binary u-boot 326656)
30         mac=$(macaddr_add $mac $offset)
31
32         macaddr_2bin $mac | dd bs=1 count=6 seek=2 conv=notrunc of=$FW_FILE 2>/dev/null
33 }
34
35 [ -e $FW_FILE ] && exit 0
36
37 . /lib/functions.sh
38 . /lib/functions/system.sh
39
40 board=$(board_name)
41
42 case "$FIRMWARE" in
43 "pci_wmac0.eeprom")
44         case $board in
45         tplink,tl-wdr4900-v1)
46                 ath9k_eeprom_extract "caldata" 4096 2048
47                 tpl_set_wireless_mac 0
48                 ;;
49         *)
50                 ath9k_eeprom_die "board $board is not supported yet"
51                 ;;
52         esac
53         ;;
54
55 "pci_wmac1.eeprom")
56         case $board in
57         tplink,tl-wdr4900-v1)
58                 ath9k_eeprom_extract "caldata" 20480 2048
59                 tpl_set_wireless_mac -1
60                 ;;
61         *)
62                 ath9k_eeprom_die "board $board is not supported yet"
63                 ;;
64         esac
65         ;;
66 esac