Skip to content

Instantly share code, notes, and snippets.

@routevegetable
Last active May 14, 2016 22:56
Show Gist options
  • Save routevegetable/c8ec9bce0143e24edb10 to your computer and use it in GitHub Desktop.
Save routevegetable/c8ec9bce0143e24edb10 to your computer and use it in GitHub Desktop.
Allwinner A20 CEC control script
#!/bin/bash
# Nasty script to poke the CEC control memory locations in Allwinner A20
# Find the STANDBY_VALUE we want
case $1 in
on)
STANDBY_VALUE=0
;;
off)
STANDBY_VALUE=1
;;
*)
echo Usage: $0 "[on|off]"
exit 1
;;
esac
# Find the offset of cec_count
CEC_COUNT_OFFSET=$((16#`grep cec_count /proc/kallsyms | cut -d ' ' -f 1`))
[ $CEC_COUNT_OFFSET == 0 ] && {
echo Cannot find cec_count kernel symbol
exit 2
}
# Find the offset of cec_standby
CEC_STANDBY_OFFSET=$((16#`grep cec_standby /proc/kallsyms | cut -d ' ' -f 1`))
[ $CEC_STANDBY_OFFSET == 0 ] && {
echo Cannot find cec_standby kernel symbol
exit 3
}
write_cec_count() {
echo -ne "\x$1" | dd of=/dev/kmem seek=$CEC_COUNT_OFFSET count=1 bs=1 2>/dev/null
}
write_cec_standby() {
echo -ne "\x$1" | dd of=/dev/kmem seek=$CEC_STANDBY_OFFSET count=1 bs=1 2>/dev/null
}
read_cec_count() {
dd if=/dev/kmem skip=$CEC_COUNT_OFFSET bs=1 count=1 2>/dev/null | hexdump -e '1/1 "%d"'
}
# Write the standby value and a count of 30
write_cec_standby $STANDBY_VALUE
write_cec_count 1e
echo -n Setting...
# Wait for the driver to decrement cec_count to 1
CEC_COUNT=30
while [ $CEC_COUNT -gt 1 ]; do
CEC_COUNT=`read_cec_count`
sleep 1
done
echo Done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment