2020-02-20 16:44:45 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-07-21 18:04:51 +00:00
|
|
|
log() {
|
|
|
|
echo "$@" | logger -t "postmarketOS:modem-setup"
|
|
|
|
}
|
|
|
|
|
2020-02-21 13:47:07 +00:00
|
|
|
# Current modem routing
|
|
|
|
#
|
|
|
|
# 1 - Digital PCM
|
2020-09-30 19:26:49 +00:00
|
|
|
# 1 - I2S slave
|
2020-02-21 13:47:07 +00:00
|
|
|
# 0 - Primary mode (short sync)
|
2020-09-30 19:26:49 +00:00
|
|
|
# 1 - 256kHz clock (256kHz / 16bit = 16k samples/s)
|
2020-02-21 13:47:07 +00:00
|
|
|
# 0 - 16bit linear format
|
2020-09-30 19:26:49 +00:00
|
|
|
# 0 - 8k sample/s
|
2020-02-21 13:47:07 +00:00
|
|
|
# 1 - 1 slot
|
|
|
|
# 1 - map to first slot (the only slot)
|
|
|
|
#
|
2020-09-30 19:26:49 +00:00
|
|
|
QDAI_CONFIG="1,1,0,1,0,0,1,1"
|
2020-07-21 18:04:51 +00:00
|
|
|
QCFG_RISIGNALTYPE_CONFIG="physical"
|
|
|
|
QMBNCFG_CONFIG="1"
|
|
|
|
QCFG_IMS_CONFIG="1"
|
|
|
|
|
|
|
|
if [ -z "$1" ]
|
|
|
|
then
|
|
|
|
DEV="/dev/EG25.AT"
|
|
|
|
else
|
|
|
|
DEV="$1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# When running this script from udev the modem might not be fully initialized
|
|
|
|
# yet, so give it some time to initialize
|
|
|
|
#
|
|
|
|
# We'll try to query for the firmware version for 15 seconds after which we'll
|
|
|
|
# consider the initialization failed
|
2020-02-20 16:44:45 +00:00
|
|
|
|
2020-07-21 18:04:51 +00:00
|
|
|
log "Waiting for the modem to initialize"
|
|
|
|
INITIALIZED=false
|
|
|
|
for second in $(seq 1 15)
|
|
|
|
do
|
|
|
|
if echo "AT+QDAI?" | atinout - $DEV - | grep -q OK
|
|
|
|
then
|
|
|
|
INITIALIZED=true
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
|
|
|
log "Waited for $second seconds..."
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
|
|
|
if $INITIALIZED
|
|
|
|
then
|
|
|
|
log "Modem initialized"
|
|
|
|
else
|
|
|
|
log "Modem failed to initialize"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-02-21 13:47:07 +00:00
|
|
|
|
|
|
|
# Read current config
|
2020-06-25 12:29:04 +00:00
|
|
|
QDAI_ACTUAL_CONFIG=$(echo "AT+QDAI?" | atinout - $DEV -)
|
2020-07-21 18:04:51 +00:00
|
|
|
QCFG_RISIGNALTYPE_ACTUAL_CONFIG=$(echo 'AT+QCFG="risignaltype"' | atinout - $DEV -)
|
|
|
|
QMBNCFG_ACTUAL_CONFIG=$(echo 'AT+QMBNCFG="AutoSel"' | atinout - $DEV -)
|
|
|
|
QCFG_IMS_ACTUAL_CONFIG=$(echo 'AT+QCFG="ims"' | atinout - $DEV -)
|
2020-02-21 13:47:07 +00:00
|
|
|
|
2020-07-21 18:04:51 +00:00
|
|
|
if echo $QDAI_ACTUAL_CONFIG | grep -q $QDAI_CONFIG && \
|
|
|
|
echo $QCFG_RISIGNALTYPE_ACTUAL_CONFIG | grep -q $QCFG_RISIGNALTYPE_CONFIG && \
|
|
|
|
echo $QMBNCFG_ACTUAL_CONFIG | grep -q $QMBNCFG_CONFIG && \
|
|
|
|
echo $QCFG_IMS_ACTUAL_CONFIG | grep -q $QCFG_IMS_CONFIG
|
2020-02-21 13:47:07 +00:00
|
|
|
then
|
2020-07-21 18:04:51 +00:00
|
|
|
log "Modem already configured"
|
2020-02-21 13:47:07 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Modem not configured, we need to send it the digital interface configuration,
|
|
|
|
# then reboot it
|
2020-06-25 12:29:04 +00:00
|
|
|
|
|
|
|
# Configure audio
|
2020-02-21 13:47:07 +00:00
|
|
|
RET=$(echo "AT+QDAI=$QDAI_CONFIG" | atinout - $DEV -)
|
|
|
|
|
2020-07-21 18:04:51 +00:00
|
|
|
if ! echo $RET | grep -q OK
|
2020-02-21 13:47:07 +00:00
|
|
|
then
|
2020-07-21 18:04:51 +00:00
|
|
|
log "Failed to configure audio: $RET"
|
2020-02-20 16:44:45 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2020-02-21 13:47:07 +00:00
|
|
|
|
2020-06-25 12:29:04 +00:00
|
|
|
# Configure ring device
|
2020-07-21 18:04:51 +00:00
|
|
|
RET=$(echo "AT+QCFG=\"risignaltype\",\"$QCFG_RISIGNALTYPE_CONFIG\"" | atinout - $DEV -)
|
2020-06-25 12:29:04 +00:00
|
|
|
|
2020-07-21 18:04:51 +00:00
|
|
|
if ! echo $RET | grep -q OK
|
2020-06-25 12:29:04 +00:00
|
|
|
then
|
2020-07-21 18:04:51 +00:00
|
|
|
log "Failed to configure modem ring wakeup: $RET"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Configure VoLTE auto selecting profile
|
|
|
|
RET=$(echo "AT+QMBNCFG=\"AutoSel\",$QMBNCFG_CONFIG" | atinout - $DEV -)
|
|
|
|
|
|
|
|
if ! echo $RET | grep -q OK
|
|
|
|
then
|
|
|
|
log "Failed to enable VoLTE profile auto selecting: $RET"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Enable VoLTE
|
|
|
|
RET=$(echo "AT+QCFG=\"ims\",$QCFG_IMS_CONFIG" | atinout - $DEV -)
|
|
|
|
|
|
|
|
if ! echo $RET | grep -q OK
|
|
|
|
then
|
|
|
|
log "Failed to enable VoLTE: $RET"
|
|
|
|
exit 1
|
2020-06-25 12:29:04 +00:00
|
|
|
fi
|
|
|
|
|
2020-02-21 13:47:07 +00:00
|
|
|
# Reset module
|
|
|
|
# 1 Set the mode to full functionality (vs 4: no RF, and 1: min functionality)
|
|
|
|
# 1 Reset the modem before changing mode (only available with 1 above)
|
|
|
|
#
|
|
|
|
RET=$(echo "AT+CFUN=1,1" | atinout - $DEV -)
|
|
|
|
|
2020-07-21 18:04:51 +00:00
|
|
|
if ! echo $RET | grep -q OK
|
2020-02-21 13:47:07 +00:00
|
|
|
then
|
2020-07-21 18:04:51 +00:00
|
|
|
log "Failed to reset the module: $RET"
|
|
|
|
exit 1
|
2020-02-21 13:47:07 +00:00
|
|
|
fi
|