ipq806x/nbg6817: add support for ZyXEL NBG6817
[openwrt/openwrt.git] / target / linux / ipq806x / base-files / lib / ipq806x.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2014 The Linux Foundation. All rights reserved.
4 # Copyright (C) 2011 OpenWrt.org
5 #
6
7 IPQ806X_BOARD_NAME=
8 IPQ806X_MODEL=
9
10 ipq806x_board_detect() {
11 local machine
12 local name
13
14 machine=$(cat /proc/device-tree/model)
15
16 case "$machine" in
17 *"AP148")
18 name="ap148"
19 ;;
20 *"C2600")
21 name="c2600"
22 ;;
23 *"D7800")
24 name="d7800"
25 ;;
26 *"DB149")
27 name="db149"
28 ;;
29 *"NBG6817")
30 name="nbg6817"
31 ;;
32 *"R7500")
33 name="r7500"
34 ;;
35 *"R7500v2")
36 name="r7500v2"
37 ;;
38 *"Linksys EA8500"*)
39 name="ea8500"
40 ;;
41 *"R7800")
42 name="r7800"
43 ;;
44 esac
45
46 [ -z "$name" ] && name="unknown"
47
48 [ -z "$IPQ806X_BOARD_NAME" ] && IPQ806X_BOARD_NAME="$name"
49 [ -z "$IPQ806X_MODEL" ] && IPQ806X_MODEL="$machine"
50
51 [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
52
53 echo "$IPQ806X_BOARD_NAME" > /tmp/sysinfo/board_name
54 echo "$IPQ806X_MODEL" > /tmp/sysinfo/model
55 }
56
57 ipq806x_board_name() {
58 local name
59
60 [ -f /tmp/sysinfo/board_name ] && name=$(cat /tmp/sysinfo/board_name)
61 [ -z "$name" ] && name="unknown"
62
63 echo "$name"
64 }
65
66 ipq806x_get_dt_led() {
67 local label
68 local ledpath
69 local basepath="/sys/firmware/devicetree/base"
70 local nodepath="$basepath/aliases/led-$1"
71
72 [ -f "$nodepath" ] && ledpath=$(cat "$nodepath")
73 [ -n "$ledpath" ] && label=$(cat "$basepath$ledpath/label")
74
75 echo "$label"
76 }