a1f6d468c8af21c9baa1350d26a01f23d05f11af
[openpandora.oe.git] / recipes / pandora-system / pandora-state / rc.pandora-state
1 #!/bin/sh
2
3 ### BEGIN INIT INFO
4 # Provides:          pandora-lcd-state
5 # Required-Start:    #adjust
6 # Required-Stop:     #adjust
7 # Default-Start:     S
8 # Default-Stop:      0 1 6
9 ### END INIT INFO
10  
11 DESC="OpenPandora Save and Restore LCD Settings"
12 NAME="pandora-state"
13
14 d_stop() {
15         echo "Saving Pandora specific settings"
16         bright=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness)
17         if [ $bright != "0" ]; then
18             cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness > /etc/pandora/conf/brightness.state
19         fi
20         touch /etc/pandora/shutdown
21         cat /sys/devices/platform/omap2_mcspi.1/spi1.1/gamma > /etc/pandora/conf/gamma.state
22         cat -v /proc/pandora/nub0/mode | sed -n '1p' > /etc/pandora/conf/nubs.state
23         cat -v /proc/pandora/nub0/mouse_sensitivity | sed -n '1p' >> /etc/pandora/conf/nubs.state
24         cat -v /proc/pandora/nub0/scrollx_sensitivity | sed -n '1p' >> /etc/pandora/conf/nubs.state
25         cat -v /proc/pandora/nub0/scrolly_sensitivity | sed -n '1p' >> /etc/pandora/conf/nubs.state
26         cat -v /proc/pandora/nub0/scroll_rate| sed -n '1p' >> /etc/pandora/conf/nubs.state
27         cat -v /proc/pandora/nub0/mbutton_threshold | sed -n '1p' >> /etc/pandora/conf/nubs.state
28         cat -v /proc/pandora/nub1/mode | sed -n '1p' >> /etc/pandora/conf/nubs.state
29         cat -v /proc/pandora/nub1/mouse_sensitivity | sed -n '1p' >> /etc/pandora/conf/nubs.state
30         cat -v /proc/pandora/nub1/scrollx_sensitivity | sed -n '1p' >> /etc/pandora/conf/nubs.state
31         cat -v /proc/pandora/nub1/scrolly_sensitivity | sed -n '1p' >> /etc/pandora/conf/nubs.state
32         cat -v /proc/pandora/nub1/scroll_rate | sed -n '1p' >> /etc/pandora/conf/nubs.state
33         cat -v /proc/pandora/nub1/mbutton_threshold | sed -n '1p' >> /etc/pandora/conf/nubs.state
34 }
35
36 d_start() {
37         echo "Restoring Pandora specific settings"
38         cat /etc/pandora/conf/dirty_expire_centisecs >  /proc/sys/vm/dirty_expire_centisecs
39         cat /etc/pandora/conf/brightness.state > /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness 
40         cat /etc/pandora/conf/gamma.state > /sys/devices/platform/omap2_mcspi.1/spi1.1/gamma
41         if [ -f /etc/pandora/conf/filter.state ]; then
42                 filter=$(cat /etc/pandora/conf/filter.state)
43                 /usr/pandora/scripts/op_videofir.sh $filter 
44         fi
45         cpuspeed="$(cat /etc/pandora/conf/cpu.conf | grep default | awk -F\: '{print $2}')"
46         oppmax="$(cat /etc/pandora/conf/cpu.conf | grep opp | awk -F\: '{print $2}')"
47         echo $oppmax > /proc/pandora/cpu_opp_max
48         if [ -f /etc/pandora/shutdown ]; then
49               rm /etc/pandora/shutdown
50               sync
51               echo $cpuspeed > /proc/pandora/cpu_mhz_max
52         else
53               echo "No clean shutdown - will not set CPU speed"
54               touch /tmp/nocleanwarn
55         fi
56         sed -n '1p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/mode
57         sed -n '2p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/mouse_sensitivity
58         sed -n '3p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/scrollx_sensitivity
59         sed -n '4p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/scrolly_sensitivity
60         sed -n '5p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/scroll_rate
61         sed -n '6p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/mbutton_threshold
62         sed -n '7p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/mode
63         sed -n '8p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/mouse_sensitivity
64         sed -n '9p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/scrollx_sensitivity
65         sed -n '10p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/scrolly_sensitivity
66         sed -n '11p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/scroll_rate
67         sed -n '12p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/mbutton_threshold
68 }
69
70 case "$1" in
71   start)
72         echo -n "Starting $DESC: $NAME - "
73         d_start
74         echo "."
75         ;;
76   stop)
77         echo -n "Stopping $DESC: $NAME - "
78         d_stop
79         echo "."
80         ;;
81   reload)
82         echo -n "Reloading $DESC: $NAME - "
83         d_start
84         echo "."
85         ;;      
86   restart|force-reload)
87         echo -n "Restarting $DESC: $NAME - "
88         d_stop
89         sleep 1
90         d_start
91         echo "."
92         ;;
93   *)
94         echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
95         exit 1
96         ;;
97 esac
98
99 exit 0