#!/bin/sh # B23 (720 mA) board-side observer, from b10b3-mon.sh (env VMAX = ALERT VBAT uV, EVDD = expected VDD_MAX hex): every P s append one line to /tmp/b23-mon.log (survives NCM/USB loss). Reads only. P=${1:-30} grep -q " /sys/kernel/debug " /proc/mounts || mount -t debugfs debugfs /sys/kernel/debug R=/sys/kernel/debug/regmap/0-00/registers; S=/sys/kernel/debug/pm8916_lbc/state rd() { dd if=$R bs=9 skip=$(($1)) count=$2 2>/dev/null | cut -d' ' -f2 | tr '\n' ' '; } D=/sys/bus/iio/devices/iio:device0; C=/sys/class/power_supply/pm8916-lbc-chgr trap '' HUP i=0 while [ ! -e /tmp/b23-mon.stop ]; do i=$((i + 1)); vb=$(cat $D/in_voltage6_input); pt=$(cat $D/in_temp8_input) a=""; [ "$vb" -gt ${VMAX:-4220000} ] && a="$a ALERT-VBAT"; [ "$pt" -gt ${TMAX:-60000} ] && a="$a ALERT-TEMP"; [ "$(rd 0x1060 1)" != "80 " ] && a="$a ALERT-TIMER"; case "$(rd 0x1040 1)" in ${EVDD:-08}" "|${EVDD2:-xx}" ") ;; *) a="$a ALERT-VDDMAX";; esac; [ "$(rd 0x1044 1)" != "07 " ] && a="$a ALERT-IBAT" st=$(head -1 $S | tr ' ' '='); cv=$(sed -n 2p $S | sed 's/.*cv_s \([-0-9]*\) nocv \([0-9]*\).*/cv_s=\1 nocv=\2/'); cnt=$(sed -n 3p $S | tr ' ' '='); vdd=$(rd 0x1040 1) ld=$(pgrep -c yes 2>/dev/null || ps | grep -c "[y]es$") echo "M $i $(date -u +%T) up=$(cut -d' ' -f1 /proc/uptime) $st $cv $cnt vbat6=$vb vph=$(cat $D/in_voltage7_input) usbin=$(cat $D/in_voltage0_input) fifo=$(rd 0x40c0 4) chgst=$(rd 0x1009 1) crt=$(rd 0x1010 1) brt=$(rd 0x1210 1) urt=$(rd 0x1310 1) usbp=$(rd 0x1308 2) ctrl=$(rd 0x1049 1) vdd=$vdd ibat=$(rd 0x1044 1) tchg=$(rd 0x1060 2) failed=$(rd 0x104a 1) bd=$(rd 0x1642 1) online=$(cat $C/online) psy=$(cat $C/status) pmt=$pt cpu=$(cat /sys/class/thermal/thermal_zone4/temp) load=$ld$a" >> /tmp/b23-mon.log sleep $P done echo "MON-END $(date -u +%T)" >> /tmp/b23-mon.log