summaryrefslogtreecommitdiff
path: root/recipes-bsp/multitech/mts-io/mts-io.init
blob: f27415cdd4f5f3c24dbb2cef590a248ac5b5a243 (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
#!/bin/bash

sysdir=/sys/devices/platform/mts-io

read_card_info() {
  ap1_product_id=""
  ap2_product_id=""

  if [ -d $sysdir/ap1 ]; then
    ap1_product_id=$(cat $sysdir/ap1/product-id)
  fi
  if [ -d $sysdir/ap2 ]; then
    ap2_product_id=$(cat $sysdir/ap2/product-id)
  fi
}

mfser_init() {
  found_ap1=0

  if [[ "$ap1_product_id" =~ ^MTAC-MFSER- ]]; then
    echo "mts-io: Linking /dev/mfser to /dev/ttyAP1"
    ln -sf /dev/ttyAP1 /dev/mfser
    found_ap1=1
  fi

  if [[ "$ap2_product_id" =~ ^MTAC-MFSER- ]]; then
    if [[ $found_ap1 = 1 ]]; then
      echo "mts-io: Linking /dev/mfser-2 to /dev/ttyAP2"
      ln -sf /dev/ttyAP2 /dev/mfser-2
    else
      echo "mts-io: Linking /dev/mfser to /dev/ttyAP2"
      ln -sf /dev/ttyAP2 /dev/mfser
    fi
  fi

}

case $1 in
  start)
    echo "Loading mts-io module"
    modprobe mts_io
    read_card_info
    mfser_init
    ;;

  stop)
    echo "Unloading mts-io module"
    modprobe -r mts_io
    ;;

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