summaryrefslogtreecommitdiff
path: root/recipes-bsp/multitech/mts-io/mts-io.mtcap.init
blob: faebc6f3fd0d35e94a2eedf2c96adf2a213e75b5 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash

sysdir=/sys/devices/platform/mts-io
lora_init() {
  # reset lora chip
  mts-io-sysfs store lora/reset 1
  mts-io-sysfs store lora/reset 0
  usleep 100000
  mts-io-sysfs store lora/reset 1
}

eth_init() {
  # reset eth phy
  mts-io-sysfs store eth-reset 1
  mts-io-sysfs store eth-reset 0
  usleep 100000
  mts-io-sysfs store eth-reset 1
}

# Normal state when powered up
wifi_init1() {
  [[ -f ${sysdir}/capability/wifi ]] || return 0
  # reset wlan
  mts-io-sysfs store wlan-rst 0
  # disable wlan
  mts-io-sysfs store wlan-en 0
}
  
wifi_init2() {
  [[ -f ${sysdir}/capability/wifi ]] || return 0
  mts-io-sysfs store wlan-en 1
  usleep 30000  # 30mS according to WILC1000 spec.
  mts-io-sysfs store wlan-rst 1
}


cell_init() {
  # remove /dev/modem_at[0,1] symlinks
  rm -f /dev/modem_at[0,1]

  # power down the cellular chip gracefully
  mts-io-sysfs store radio-power 0

  # power up the cellular chip
  mts-io-sysfs store radio-power 1
}

start_lora_led_updater() {
  lora-led-updater &
}

case $1 in
  start)
    echo "Loading mts-io module"
    modprobe -r atmel_mci
    modprobe mts_io
    wifi_init1
    lora_init
    eth_init
    cell_init &
    start_lora_led_updater
    wifi_init2
    modprobe atmel_mci
    if [[ -f ${sysdir}/capability/wifi ]] ; then
        modprobe wilc1000
        modprobe wilc1000-sdio
    fi	
    ;;

  stop)
    echo "Unloading mts-io module"
    wifi_init1  # Power down wifi
    if [[ -f ${sysdir}/capability/wifi ]] ; then
        modprobe -r wilc1000-sdio >/dev/null 2>&1
        modprobe -r wilc1000 >/dev/null 2>&1
    fi
    modprobe -r mts_io >/dev/null 2>&1
    ;;

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