a7e9ee13555b35211937ff8678a3128be2d4eeb1
[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:     5 3
8 # Default-Stop:      0 1 6
9 ### END INIT INFO
10  
11 DESC="OpenPandora Save and Restore various settings"
12 NAME="pandora-state"
13
14 . /usr/pandora/scripts/op_paths.sh
15
16 d_stop() {
17         echo "Saving Pandora specific settings"
18         bright=$(cat $SYSFS_BACKLIGHT_BRIGHTNESS)
19         if [ $bright != "0" ]; then
20             echo $bright > /etc/pandora/conf/brightness.state
21         fi
22         touch /etc/pandora/shutdown
23         cat $SYSFS_GAMMA > /etc/pandora/conf/gamma.state
24         cat -v /proc/pandora/nub0/mode | sed -n '1p' > /etc/pandora/conf/nubs.state
25         cat -v /proc/pandora/nub0/mouse_sensitivity | sed -n '1p' >> /etc/pandora/conf/nubs.state
26         cat -v /proc/pandora/nub0/scrollx_sensitivity | sed -n '1p' >> /etc/pandora/conf/nubs.state
27         cat -v /proc/pandora/nub0/scrolly_sensitivity | sed -n '1p' >> /etc/pandora/conf/nubs.state
28         cat -v /proc/pandora/nub0/scroll_rate| sed -n '1p' >> /etc/pandora/conf/nubs.state
29         cat -v /proc/pandora/nub0/mbutton_threshold | sed -n '1p' >> /etc/pandora/conf/nubs.state
30         cat -v /proc/pandora/nub1/mode | sed -n '1p' >> /etc/pandora/conf/nubs.state
31         cat -v /proc/pandora/nub1/mouse_sensitivity | sed -n '1p' >> /etc/pandora/conf/nubs.state
32         cat -v /proc/pandora/nub1/scrollx_sensitivity | sed -n '1p' >> /etc/pandora/conf/nubs.state
33         cat -v /proc/pandora/nub1/scrolly_sensitivity | sed -n '1p' >> /etc/pandora/conf/nubs.state
34         cat -v /proc/pandora/nub1/scroll_rate | sed -n '1p' >> /etc/pandora/conf/nubs.state
35         cat -v /proc/pandora/nub1/mbutton_threshold | sed -n '1p' >> /etc/pandora/conf/nubs.state
36         cat -v /proc/pandora/nub0/mbutton_delay | sed -n '1p' >> /etc/pandora/conf/nubs.state
37         cat -v /proc/pandora/nub1/mbutton_delay | sed -n '1p' >> /etc/pandora/conf/nubs.state
38 }
39
40 d_start() {
41         # Determine Pandora type
42         pnd_version=$(dmesg | grep OMAP3 | grep ES | awk '{print $3}')
43         echo $pnd_version > /tmp/pnd_version
44         
45         echo "Restoring Pandora specific settings"
46         
47         # Enable TV Out
48         if [ -f /etc/pandora/conf/tvout.state ]; then
49                 /usr/pandora/scripts/op_tvout.sh
50         fi
51         
52         # Set LEDs
53         highpow="$(cat /etc/pandora/conf/led.conf | grep HighPowerLED: | awk -F\: '{print $2}')"
54         echo $highpow > /sys/class/leds/pandora\:\:power/brightness #power LED bright
55         bright=$(cat /etc/pandora/conf/brightness.state)
56         if [ "$bright" -gt "0" ]; then
57                 echo $bright > $SYSFS_BACKLIGHT_BRIGHTNESS
58         fi
59         
60         # Set Gamma
61         cat /etc/pandora/conf/dirty_expire_centisecs >  /proc/sys/vm/dirty_expire_centisecs
62         cat /etc/pandora/conf/gamma.state > $SYSFS_GAMMA
63         if [ -f /etc/pandora/conf/dssgamma.state ]; then
64                 dssgamma=$(cat /etc/pandora/conf/dssgamma.state)
65                 dssgamma2=$(echo "scale=2;$dssgamma / 100" | bc)
66                 /usr/pandora/scripts/op_gamma.sh $dssgamma2
67         fi
68         
69         # Set Filter
70         if [ -f /etc/pandora/conf/filter.state ]; then
71                 filter=$(cat /etc/pandora/conf/filter.state)
72                 /usr/pandora/scripts/op_videofir.sh $filter 
73         fi
74         
75         # Check for unclean shutdown and set CPU Speed
76         cpuspeed="$(cat /etc/pandora/conf/cpu.conf | grep default | awk -F\: '{print $2}')"
77         oppmax="$(cat /etc/pandora/conf/cpu.conf | grep opp | awk -F\: '{print $2}')"
78         echo $oppmax > /proc/pandora/cpu_opp_max
79         if [ -f /etc/pandora/shutdown ]; then
80               rm /etc/pandora/shutdown
81               sync      
82         else
83               echo "No clean shutdown - will CPU Speed will be set to safe value."
84               echo "Yes" > /tmp/nocleanwarn
85               chmod 777 /tmp/nocleanwarn
86                 if [ "$pnd_version" == "OMAP3630" ]; then
87                   cpuspeed="1000"
88                 else
89                   cpuspeed="600"
90                 fi
91         fi
92         /usr/pandora/scripts/op_cpuspeed.sh -n $cpuspeed
93         
94         # Set nubs
95         sed -n '1p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/mode
96         sed -n '2p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/mouse_sensitivity
97         sed -n '3p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/scrollx_sensitivity
98         sed -n '4p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/scrolly_sensitivity
99         sed -n '5p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/scroll_rate
100         sed -n '6p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/mbutton_threshold
101         sed -n '7p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/mode
102         sed -n '8p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/mouse_sensitivity
103         sed -n '9p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/scrollx_sensitivity
104         sed -n '10p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/scrolly_sensitivity
105         sed -n '11p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/scroll_rate
106         sed -n '12p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/mbutton_threshold
107         sed -n '13p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/mbutton_delay
108         sed -n '14p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/mbutton_delay
109         
110         # Enable ZRAM Swap
111         echo "Enabling ZRAM Swap"
112         mkswap /dev/zram0
113         swapon -p 5 /dev/zram0
114
115         # set audio powerdown delay (ms)
116         if [ -e /sys/devices/platform/soc-audio/PCM1773/pmdown_time ]; then
117                 echo 60000 > /sys/devices/platform/soc-audio/PCM1773/pmdown_time
118         fi
119 }
120
121 case "$1" in
122   start)
123         echo -n "Starting $DESC: $NAME - "
124         d_start
125         echo "."
126         ;;
127   stop)
128         echo -n "Stopping $DESC: $NAME - "
129         d_stop
130         echo "."
131         ;;
132   reload)
133         echo -n "Reloading $DESC: $NAME - "
134         d_start
135         echo "."
136         ;;      
137   restart|force-reload)
138         echo -n "Restarting $DESC: $NAME - "
139         d_stop
140         sleep 1
141         d_start
142         echo "."
143         ;;
144   *)
145         echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
146         exit 1
147         ;;
148 esac
149
150 exit 0