Commit 4123c8ee authored by aTc's avatar aTc
Browse files

added letux scripts

parent 3843ec2a
#!/bin/sh
# if not in software-controlled charging mode, Vbus (and only that)
# has to be applied before running the script
#MUSB_MODE=/sys/bus/platform/devices/musb-hdrc/mode
#MUSB_MODE=/sys/bus/platform/devices/musb-hdrc.0/mode
MUSB_MODE=/sys/bus/platform/devices/musb-hdrc.1.auto/mode
MUSB_M=`cat $MUSB_MODE`
echo "$MUSB_M"
if [ "$MUSB_M" != b_idle ] ; then
echo Invalid mode at start
exit
fi
# trigger a transition from b_idle to b_peripheral by simulating
# a connection to a host (enable pull-down resistors)
echo on > /sys/bus/platform/devices/twl4030_usb/fake_host
sleep 0.2
cat $MUSB_MODE
# trigger a transition from b_peripheral to b_hnp_enable
echo host >$MUSB_MODE
cat $MUSB_MODE
sleep 0.2
# simulate a disconnection from host
echo off > /sys/bus/platform/devices/twl4030_usb/fake_host
sleep 0.2
cat $MUSB_MODE
# be a host by ourselfs (if we wouldn't mess with this bit,
# it would be already set here)
echo on > /sys/bus/platform/devices/twl4030_usb/fake_host
MUSB_M=`cat $MUSB_MODE`
echo "$MUSB_M"
if [ "$MUSB_M" = b_wait_acon ] ; then
echo "Prepared for being usb host, time to attach your device"
fi
DURATION="$1"
[ "$DURATION" ] || DURATION=60
## check DT model
# GTA04
TWL4030_MADC=/sys/devices/platform/68000000.ocp/48070000.i2c/i2c-0/0-0048/48070000.i2c:twl@48:madc/iio:device0
CHARGER=/sys/class/power_supply/twl4030_usb
BQ27000=/sys/class/power_supply/bq27000-battery
# Pyra
[ -r "$CHARGER" ] || CHARGER=/sys/class/power_supply/bq24297
[ -r "$BQ27000" ] || BQ27000=/sys/class/power_supply/bq27425-0
while true
do
VBUS=$(cat $TWL4030_MADC/in_voltage8_input 2>/dev/null)
VCHG=$(cat $TWL4030_MADC/in_voltage11_input 2>/dev/null)
CHGVOLT=$(cat $CHARGER/voltage_now 2>/dev/null)
[ "$CHGVOLT" ] && CHGVOLT=$(expr "$CHGVOLT" / 1000)
VBAT=$(cat $TWL4030_MADC/in_voltage12_input 2>/dev/null)
BQVBAT=$(cat $BQ27000/voltage_now 2>/dev/null)
[ "$BQVBAT" ] && BQVBAT=$(expr "$BQVBAT" / 1000)
[ "$VBAT" ] && CHG=$(expr \( "$VBAT" - 3200 \) \* 100 / 1050)
BQCHG=$(cat $BQ27000/capacity 2>/dev/null)
TEMP=$(cat $TWL4030_MADC/int_temp1_input 2>/dev/null)
BQTEMP=$(cat $BQ27000/temp 2>/dev/null)
IDPIN=$(cat /dev/usb_id 2>/dev/null)
[ "$BQTEMP" ] && BQTEMP=$(expr "$BQTEMP" / 10)
ICHG=$(cat $TWL4030_MADC/in_current10_input 2>/dev/null)
BQCICHG=$(cat $BQ27000/current_now 2>/dev/null)
[ "$BQCICHG" ] && BQCICHG=$(expr "$BQCICHG" / 1000)
echo "$(date) - ${VBUS}/${CHGVOLT}/${VBAT}/${BQVBAT}/${VCHG}mV - ${CHG}/${BQCHG}% - ${TEMP}/${BQTEMP}C - ${ICHG}/${BQCICHG}mA - ${IDPIN}" | tee -a battlog
sync
sleep $DURATION
done
#
# turn on/off backlight
#
BL=/sys/class/backlight/$(cd /sys/class/backlight/ && ls -1 | head -1)
if [ "$1" = 1 ]
then
echo 0 >$BL/bl_power
else
echo 1 >$BL/bl_power
fi
/*
* blanviewd.c
*
* daemon to read the ambient light sensor and control
* backlight intensity for Ortustech Blanview display
*
* (c) H. N. Schaller, Golden Delicious Comp. GmbH&Co. KG, 2013
* Lukas Märdian <lukas@goldelico.com>
* Licence: GNU GPL2
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
int main(int argc, char *argv[])
{
char debug=0;
int prev_bl=-1;
char *file;
FILE *in, *out;
if(argv[1] != NULL && strcmp(argv[1], "-d") == 0)
{
fprintf(stderr, "debug mode\n");
debug=1;
}
else if(argv[1])
{
fprintf(stderr, "usage: blanviewd [-d]\n");
return 1;
}
#if 1
file="/sys/devices/platform/pwm-backlight/backlight/pwm-backlight/brightness";
#else
file="/sys/devices/platform/pwm-backlight/backlight/pwm-backlight/max_brightness";
#endif
out=fopen(file, "w");
if(!out)
{
fprintf(stderr, "%s: %s\n", file, strerror(errno));
return 1;
}
while(1)
{
int i, n;
unsigned short x, y, pressure_raw, pressure, pendown;
unsigned short temperature, temp0, temp1;
unsigned short z1, z2;
unsigned short aux;
unsigned short ambient_light;
unsigned short bl;
file="/sys/bus/i2c/drivers/tsc2007/2-0048/values";
in=fopen(file, "r");
if(!in)
{
fprintf(stderr, "%s: %s\n", file, strerror(errno));
return 1;
}
n=fscanf(in, "%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu",
&x,
&y,
&pressure_raw,
&pendown,
&temperature,
&z1,
&z2,
&temp0,
&temp1,
&aux,
&pressure);
fclose(in);
if(n == 11)
{
if(debug)
fprintf(stderr, "aux=%d", aux);
if(aux <= 4096 && aux > 2048) // max ambient light
ambient_light = 1;
else if(aux <= 2048 && aux > 1024)
ambient_light = 2;
else if(aux <= 1024 && aux > 512)
ambient_light = 3;
else if(aux <= 512 && aux > 256)
ambient_light = 4;
else if(aux <= 256 && aux > 0) // min ambient light
ambient_light = 5;
else // something went wrong, go max
ambient_light = 5;
bl = ambient_light*20;
if(debug)
fprintf(stderr, " ->");
while(prev_bl != bl)
{
if(prev_bl < 0)
prev_bl=bl; // first
else if(prev_bl < bl)
prev_bl+=1;
else
prev_bl-=1;
fprintf(out, "%d\n", prev_bl); // fade backlight level
fflush(out);
if(debug)
fprintf(stderr, " %d", prev_bl);
usleep(10000);
}
prev_bl = bl;
if(debug)
fprintf(stderr, "\n");
}
else if(debug)
fprintf(stderr, "n=%d\n", n); // driver mismatch...
sleep(5); // next sample in 5 sec
}
}
#
# initialize BOE panel directly connected to OMAP5
# using the panel-mipi-debug driver
#
# controller: OTM1283A
#
# -n: don't try to program panel
# -s: experiments for address shift register and enable command2
# -t: test if we can write single bytes through MIPI (yes we can - if command2 and address shift is already enabled)
if ! [ "$(cat /proc/device-tree/ocp/dss@58000000/encoder@58004000/lcd/compatible)" = "omapdss,mipi,debug" ]
then
echo this script needs the mipi-debug driver!
echo use panelselect to choose the '-n' driver
exit 1
fi
./bl 1
if [ ! -L dcs ]
then
rm -rf dcs
ln -s /sys/devices/platform/44000000.ocp/58000000.dss/58004000.encoder/58004000.encoder:lcd/dcs dcs
fi
# make sure the panel is active before trying to send commands
echo nostream >dcs # if it was on before
echo stop >dcs # stop if it was already running
echo nopower >dcs # enable is unused
echo reset >dcs # reset panel
# reset panel
echo reset >dcs # reset panel
sleep .1
echo noreset >dcs # take panel out of reset before starting the clocks
sleep .2
echo start >dcs # start MIPI interface
sleep .2
# show some DCS status
echo status >dcs
# for i in 05 0a 0b 0c 0d 0e 0f 13 20 52 54 5f 68 a1rrrr da db dc; do echo $i r >dcs; done
# program panel here
if [ "$1" != "-n" ]
then
# enable command2 and address shift
if [ "$1" = "-s" ]
then
echo g0000 >dcs # write address shift register
echo gff12 >dcs # write FF00h
echo g0001 >dcs # write address shift register
echo gff83 >dcs # write FF01h
echo g0002 >dcs # write address shift register
echo gff01 >dcs # write FF02h
else
echo g0000 >dcs # write address shift register
echo gff128301 >dcs # write FF00h
shift
fi
# use address shift to specify lower 8 address bits
echo g0080 >dcs # write address shift register
# enable orise command 2
echo gff1283 >dcs # write FF80h
if [ "$1" = "-t" ]
then # special test if we can write single bytes through MIPI
# try to read MIPISET1 for debugging of interface
echo g0080 >dcs
echo gb0rrrrr >dcs # read 5 bytes from B080h
echo g00b3 >dcs
echo gc0 rr >dcs
cat dcs # expected: 00 01 00 30 04
echo g00b3 >dcs
echo gc0aa >dcs # try to write first byte
echo g00b3 >dcs
echo gc0 rr >dcs
cat dcs # should read aa??
echo g00b4 >dcs
echo gc0bb >dcs # try to write second byte
echo g00b3 >dcs
echo gc0 rr >dcs
cat dcs # should read aabb
echo g00b3 >dcs # Interval Scan Frame: 0 framecolumn inversion
echo gc00050 >dcs
echo g00b3 >dcs
echo gc0 rr >dcs
cat dcs # should read 0050
shift
fi
## now really program the panel according to manufacturer's command list
# -------------------- panel setting --------------------
echo g0080 >dcs # TCON Setting
echo gc00064000f1100640f11 >dcs
echo g0090 >dcs # Panel Timing Setting
echo gc0005c00010004 >dcs
echo g0087 >dcs
echo gc418 >dcs
echo g00b3 >dcs # Interval Scan Frame: 0 framecolumn inversion
echo gc00050 >dcs
echo g0081 >dcs # frame rate:60Hz
echo gc166 >dcs
echo g0081 >dcs
echo gc48202 >dcs
echo g0090 >dcs
echo gc449 >dcs
echo g00c6 >dcs
echo gb003 >dcs
echo g0090 >dcs # Mode-3
echo gf502110211 >dcs
echo g0090 >dcs # 2xVPNL1.5*=002*=503*=a0
echo gc550 >dcs
echo g0094 >dcs # Frequency
echo gc566 >dcs
echo g00b2 >dcs # VGLO1 setting
echo gf50000 >dcs
echo g00b4 >dcs # VGLO1_S setting
echo gf50000 >dcs
echo g00b6 >dcs # VGLO2 setting
echo gf50000 >dcs
echo g00b8 >dcs # VGLO2_S setting
echo gf50000 >dcs
echo g0094 >dcs # VCL ON
echo gf502 >dcs
echo g00BA >dcs # VSP ON
echo gf503 >dcs
echo g00b2 >dcs # VGHO Option
echo gc540 >dcs
echo g00b4 >dcs # VGLO Option
echo gc5C0 >dcs
# -------------------- power setting --------------------
echo g00a0 >dcs # dcdc setting
echo gc40510060205151005100702051510 >dcs
echo g00b0 >dcs # clamp voltage setting
echo gc40000 >dcs
echo g0091 >dcs # VGH=13VVGL=-12Vpump ratio:VGH=6xVGL=-5x
echo gc51950 >dcs
echo g0000 >dcs # GVDD=4.87VNGVDD=-4.87V
echo gd8bcbc >dcs
echo g0000 >dcs # VCOMDC=-1.1
echo gd95a >dcs # 5d 6f
echo g0000 >dcs
echo gE101070b0d060d0b0a040710080f110a01 >dcs
echo g0000 >dcs
echo gE201070b0d060d0b0a040710080f110a01 >dcs
echo g00b0 >dcs # VDD_18V=1.7VLVDSVDD=1.55V
echo gc504B8 >dcs
echo g00bb >dcs # LVD voltage level setting
echo gc580 >dcs
# echo g00c3 >dcs # Sample / Hold All on
# echo gf581 >dcs
# -------------------- panel timing state control --------------------
echo g0080 >dcs # panel timing state control
echo gcb0000000000000000000000 >dcs
echo g0090 >dcs # panel timing state control
echo gcb000000000000000000000000000000 >dcs
echo g00a0 >dcs # panel timing state control
echo gcb000000000000000000000000000000 >dcs
echo g00b0 >dcs # panel timing state control
echo gcb000000000000000000000000000000 >dcs
echo g00c0 >dcs # panel timing state control
echo gcb050505050505000000000000000000 >dcs
echo g00d0 >dcs # panel timing state control
echo gcb000000000005050505050505050000 >dcs
echo g00e0 >dcs # panel timing state control
echo gcb0000000000000000000000000505 >dcs
echo g00f0 >dcs # panel timing state control
echo gcbffffffffffffffffffffff >dcs
# -------------------- panel pad mapping control --------------------
echo g0080 >dcs # panel pad mapping control
echo gcc0a0c0e100204000000000000000000 >dcs
echo g0090 >dcs # panel pad mapping control
echo gcc00000000002e2d090b0d0f01030000 >dcs
echo g00a0 >dcs # panel pad mapping control
echo gcc0000000000000000000000002e2d >dcs
echo g00b0 >dcs # panel pad mapping control
echo gcc0F0D0B090301000000000000000000 >dcs
echo g00c0 >dcs # panel pad mapping control
echo gcc00000000002d2e100E0C0A04020000 >dcs
echo g00d0 >dcs # panel pad mapping control
echo gcc0000000000000000000000002d2e >dcs
# -------------------- panel timing setting --------------------
echo g0080 >dcs # panel VST setting
echo gce8D03008C03008B03008A0300 >dcs
echo g0090 >dcs # panel VEND setting
echo gce0000000000000000000000000000 >dcs
echo g00a0 >dcs # panel CLKA1/2 setting
echo gce380B04FC000000380A04FD000000 >dcs
echo g00b0 >dcs # panel CLKA3/4 setting
echo gce380904FE000000380804FF000000 >dcs
echo g00c0 >dcs # panel CLKb1/2 setting
echo gce3807050000000038060501000000 >dcs
echo g00d0 >dcs # panel CLKb3/4 setting
echo gce3805050200000038040503000000 >dcs
echo g0080 >dcs # panel CLKc1/2 setting
echo gcf0000000000000000000000000000 >dcs
echo g0090 >dcs # panel CLKc3/4 setting
echo gcf0000000000000000000000000000 >dcs
echo g00a0 >dcs # panel CLKd1/2 setting
echo gcf0000000000000000000000000000 >dcs
echo g00b0 >dcs # panel CLKd3/4 setting
echo gcf0000000000000000000000000000 >dcs
echo g00c0 >dcs # panel ECLK setting
echo gcf0101202000000102000008 >dcs
echo g00b5 >dcs # TCON_GOA_OUT Setting
echo gc533f1ff33f1ff >dcs # normal output with VGH/VGL
echo g00a0 >dcs
echo gc102 >dcs
echo g00b1 >dcs
echo gc604 >dcs
echo g0080 >dcs
echo gb0rrrrr >dcs # read 5 bytes from B080h
# expected: 00 01 00 30 04
echo g0000 >dcs # Orise mode disable
# note: we probably can't send that through the SSD2858
echo gffffffff >dcs
# should now be locked again
echo g0080 >dcs
echo gb0rrrrr >dcs # read 5 bytes from B080h
# expected: 00 00 00 00 00
fi
# DCS sleep out
echo 11 >dcs
sleep 0.120
# enable stream and turn display on
echo stream >dcs
sleep 0.020
echo 29 >dcs
exit
# randomly fill framebuffer
for i in 1 2 3 4 5
do
cat /dev/urandom > /dev/fb0 2>/dev/null
done
### WARNING ###
#
# this variant is only for programming a panel with OTM1283A and not for experimentation!
# it needs special hardware for the OTP programming voltage
#
if ! [ "$(cat /proc/device-tree/ocp/dss@58000000/encoder@58004000/lcd/compatible)" = "omapdss,mipi,debug" ]
then
echo this script needs the mipi-debug driver!
echo use ./panelselect and choose the 'n' driver
exit 1
fi
./bl 1
if [ ! -L dcs ]
then
rm -rf dcs
ln -s /sys/devices/platform/44000000.ocp/58000000.dss/58004000.encoder/58004000.encoder:lcd/dcs dcs
fi
# make sure to turn off programming power!
echo nopower >dcs
sleep .2
echo nopower >dcs
sleep .2
# now set up the panel as we want to have it programmed
./boe-w677l
read -p "Panel ok (y/n)? " yn
if [ "$yn" != "y" ]
then exit
fi
# prepare for programming
echo nostream >dcs
echo 28 >dcs
echo 10 >dcs
sleep 0.080
# enable command2 and address shift
echo gff128301 >dcs # write FF00h
# use address shift to specify lower 8 address bits
echo g0080 >dcs # write address shift register
# enable orise command 2
echo gff1283 >dcs # write FF80h
# try to read MIPISET1 for debugging of interface
echo g0080 >dcs
echo gb0rrrrr >dcs # read 5 bytes from B080h
# expected: 00 01 00 30 04
# do the programming
echo power >dcs # >enable 7.5V
echo g0000 >dcs # NVMIN
echo geb01 >dcs # NVMIN
sleep 0.8 # programming impulse
echo g0000 >dcs # NVMIN
echo geb00 >dcs # NVMIN
echo nopower >dcs # turn off 7.5V
sleep 0.2
# now the panel should have been programmed and come up without special programming sequence
./mipi-test
#
# start camera demo
# see also http://projects.goldelico.com/p/gta04-kernel/page/Camera/
#
# some background information what happens here:
#
# http://processors.wiki.ti.com/index.php/UserGuideOmap35xCaptureDriver_PSP_04.02.00.07#Software_Design_Interfaces_2
# http://labs.isee.biz/index.php/How_to_setup_tvp5151_video_decoder#Steps_to_configure_the_ISP_and_TVP5151
# http://wiki.buglabs.net/index.php/Software:Camera_Module_V4L2_Usage
# http://git.ideasonboard.org/media-ctl.git/tree
# http://www.mail-archive.com/linux-media@vger.kernel.org/msg20004.html
#
# Unfortunately there is no good documentation. Except the kernel and media-ctl sources.
# So be prepared for a lot of trial-and-error if you want to improve anything.
#
[ "$(which media-ctl)" ] || apt-get install -y media-ctl
[ "$(which mplayer)" ] || apt-get install -y mplayer
MODE=$1; [ "$MODE" ] || MODE=sxga
export XAUTHORITY=/.Xauthority
echo "### starting mplayer in $MODE mode ###"
case "$MODE" in
sxga ) # bypassing OMAP ISP (almost)
media-ctl -r -l '"ov9655 2-0030":0->"OMAP3 ISP CCDC":0[1], "OMAP3 ISP CCDC":1->"OMAP3 ISP CCDC output":0[1]'
media-ctl -V '"ov9655 2-0030":0 [UYVY2X8 1280x1024]'
# media-ctl -V '"OMAP3 ISP CCDC":0 [UYVY2X8 1280x1024]' # is set automatically
media-ctl -V '"OMAP3 ISP CCDC":1 [UYVY 1280x1024]'
mplayer tv:// -vf rotate=2 -tv driver=v4l2:device=$(media-ctl -e "OMAP3 ISP CCDC output"):outfmt=uyvy:width=1280:height=1024:fps=15 -vo x11
;;
sxga-old )
media-ctl -r -l '"ov9655 2-0030":0->"OMAP3 ISP CCDC":0[1], "OMAP3 ISP CCDC":2->"OMAP3 ISP preview":0[1], "OMAP3 ISP preview":1->"OMAP3 ISP resizer":0[1], "OMAP3 ISP resizer":1->"OMAP3 ISP resizer output":0[1]'
export DEVICE=$(media-ctl -e "OMAP3 ISP resizer output")
media-ctl -V '"ov9655 2-0030":0 [SGRBG10 1280x1024], "OMAP3 ISP CCDC":2 [SGRBG10 1280x1024], "OMAP3 ISP preview":1 [UYVY 1280x1024], "OMAP3 ISP resizer":1 [UYVY 1280x1024]'
mplayer tv:// -vf rotate=2 -tv driver=v4l2:device=$(media-ctl -e "OMAP3 ISP resizer output"):outfmt=uyvy:width=1280:height=1024:fps=15 -vo x11
;;
qvga-old )
media-ctl -r -l '"ov9655 2-0030":0->"OMAP3 ISP CCDC":0[1], "OMAP3 ISP CCDC":2->"OMAP3 ISP preview":0[1], "OMAP3 ISP preview":1->"OMAP3 ISP resizer":0[1], "OMAP3 ISP resizer":1->"OMAP3 ISP resizer output":0[1]'
export DEVICE=$(media-ctl -e "OMAP3 ISP resizer output")
media-ctl -V '"ov9655 2-0030":0 [SGRBG10 320x240], "OMAP3 ISP CCDC":2 [SGRBG10 320x240], "OMAP3 ISP preview":1 [UYVY 320x240], "OMAP3 ISP resizer":1 [UYVY 320x240]'
mplayer tv:// -vf rotate=2 -tv driver=v4l2:device=$(media-ctl -e "OMAP3 ISP resizer output"):outfmt=uyvy:width=320:height=240:fps=30 -vo x11
;;
cif-old )
media-ctl -r -l '"ov9655 2-0030":0->"OMAP3 ISP CCDC":0[1], "OMAP3 ISP CCDC":2->"OMAP3 ISP preview":0[1], "OMAP3 ISP preview":1->"OMAP3 ISP resizer":0[1], "OMAP3 ISP resizer":1->"OMAP3 ISP resizer output":0[1]'
export DEVICE=$(media-ctl -e "OMAP3 ISP resizer output")
media-ctl -V '"ov9655 2-0030":0 [SGRBG10 352x288], "OMAP3 ISP CCDC":2 [SGRBG10 352x288], "OMAP3 ISP preview":1 [UYVY 352x288], "OMAP3 ISP resizer":1 [UYVY 352x288]'
mplayer tv:// -vf rotate=2 -tv driver=v4l2:device=$(media-ctl -e "OMAP3 ISP resizer output"):outfmt=uyvy:width=352:height=288:fps=30 -vo x11
;;
vga-old )
media-ctl -r -l '"ov9655 2-0030":0->"OMAP3 ISP CCDC":0[1], "OMAP3 ISP CCDC":2->"OMAP3 ISP preview":0[1], "OMAP3 ISP preview":1->"OMAP3 ISP resizer":0[1], "OMAP3 ISP resizer":1->"OMAP3 ISP resizer output":0[1]'
media-ctl -V '"ov9655 2-0030":0 [SGRBG10 640x480], "OMAP3 ISP CCDC":2 [SGRBG10 640x480], "OMAP3 ISP preview":1 [UYVY 640x480], "OMAP3 ISP resizer":1 [UYVY 640x480]'
mplayer tv:// -vf rotate=2 -tv driver=v4l2:device=$(media-ctl -e "OMAP3 ISP resizer output"):outfmt=uyvy:width=640:height=480:fps=30 -vo x11
;;
vga-resizer | vga-r* )
media-ctl -r -l '"ov9655 2-0030":0->"OMAP3 ISP CCDC":0[1], "OMAP3 ISP CCDC":1->"OMAP3 ISP resizer":0[1], "OMAP3 ISP resizer":1->"OMAP3 ISP resizer output":0[1]'
export DEVICE=$(media-ctl -e "OMAP3 ISP resizer output")