summaryrefslogtreecommitdiff
path: root/recipes-bsp/multitech/mt-dt-overlay/init-mtcpmhs-sdmfg
blob: 2a0e03d885c1a3afc1a02fa8e5ae3b59974b9300 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# This script must be run only to set up device tree on new devices
# as part of manufacturing process when EEPROMs are empty


DEVTREE="/sys/kernel/config/device-tree/overlays/"

install_all_dtbo() {
  for f in *.dtbo ; do
    if ! [[ -f $f ]] ; then
        continue
    fi
    # f2 is the extracted device name
    base=$(basename $f .dtbo)
    /bin/mkdir ${DEVTREE}/$base || true
    /bin/cat $f >${DEVTREE}/$base/dtbo
  done
}

load_overlay() {
  if ! pushd /lib/dtoverlays ; then
    echo "Can't find device tree overlays"
    return 1
  fi
  
  # Detect PCA9557 I2C GPIO at 0x19 on I2C bus 1
  RES_="$(/usr/sbin/i2cdetect -r -y 1 0x19 0x19)"
  if [[ "$RES_" =~ .*(^10:[[:blank:]]+19).* ]]; then
    if ! pushd MTCDT3/0.2 ; then
      echo "Can't find MTCDT3/0.2 direcotry"
      popd
      return 1
    fi
    echo "Loading device tree overlay for MTCDT3 v 0.2"
    install_all_dtbo
    popd
  fi

  # Detect MCP23008 I2C GPIO at 0x21 on I2C bus 1
  RES_="$(/usr/sbin/i2cdetect -r -y 1 0x21 0x21)"
  if [[ "$RES_" =~ .*(^20:[[:blank:]]+21).* ]]; then
    if ! pushd MTCDT3/0.0 ; then
      echo "Can't find MTCDT3/0.0 direcotry"
      popd
      return 1
    fi
    echo "Loading device tree overlay for MTCDT3 v 0.0"
    install_all_dtbo
    popd
  fi

  popd
}

case $1 in
  start)
    echo "Loading device tree overlay"
    load_overlay
    ;;

  stop)
    echo "Not implemented"
    ;;

  *)
    echo "Usage: $0 {start|stop}"
    exit 2
    ;;
esac