rc.pandora-state: Find out Pandora Type and set it into /tmp/pnd_version
[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         echo "Restoring Pandora specific settings"
45         highpow="$(cat /etc/pandora/conf/led.conf | grep HighPowerLED: | awk -F\: '{print $2}')"
46         echo $highpow > /sys/class/leds/pandora\:\:power/brightness #power LED bright
47         bright=$(cat /etc/pandora/conf/brightness.state)
48         if [ "$bright" -gt "0" ]; then
49                 echo $bright > $SYSFS_BACKLIGHT_BRIGHTNESS
50         fi
51         cat /etc/pandora/conf/dirty_expire_centisecs >  /proc/sys/vm/dirty_expire_centisecs
52         cat /etc/pandora/conf/gamma.state > $SYSFS_GAMMA
53         if [ -f /etc/pandora/conf/dssgamma.state ]; then
54                 dssgamma=$(cat /etc/pandora/conf/dssgamma.state)
55                 dssgamma2=$(echo "scale=2;$dssgamma / 100" | bc)
56                 /usr/pandora/scripts/op_gamma.sh $dssgamma2
57         fi
58         if [ -f /etc/pandora/conf/filter.state ]; then
59                 filter=$(cat /etc/pandora/conf/filter.state)
60                 /usr/pandora/scripts/op_videofir.sh $filter 
61         fi
62         cpuspeed="$(cat /etc/pandora/conf/cpu.conf | grep default | awk -F\: '{print $2}')"
63         oppmax="$(cat /etc/pandora/conf/cpu.conf | grep opp | awk -F\: '{print $2}')"
64         echo $oppmax > /proc/pandora/cpu_opp_max
65         if [ -f /etc/pandora/shutdown ]; then
66               rm /etc/pandora/shutdown
67               sync      
68         else
69               echo "No clean shutdown - will CPU Speed will be set to safe value."
70               echo "Yes" > /tmp/nocleanwarn
71               chmod 777 /tmp/nocleanwarn
72                 if [ "$pnd_version" == "OMAP3630" ]; then
73                   cpuspeed="1000"
74                 else
75                   cpuspeed="600"
76                 fi
77         fi
78         /usr/pandora/scripts/op_cpuspeed.sh -n $cpuspeed
79         sed -n '1p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/mode
80         sed -n '2p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/mouse_sensitivity
81         sed -n '3p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/scrollx_sensitivity
82         sed -n '4p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/scrolly_sensitivity
83         sed -n '5p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/scroll_rate
84         sed -n '6p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/mbutton_threshold
85         sed -n '7p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/mode
86         sed -n '8p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/mouse_sensitivity
87         sed -n '9p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/scrollx_sensitivity
88         sed -n '10p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/scrolly_sensitivity
89         sed -n '11p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/scroll_rate
90         sed -n '12p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/mbutton_threshold
91         sed -n '13p' /etc/pandora/conf/nubs.state > /proc/pandora/nub0/mbutton_delay
92         sed -n '14p' /etc/pandora/conf/nubs.state > /proc/pandora/nub1/mbutton_delay
93         echo "Enabling ZRAM Swap"
94         mkswap /dev/zram0
95         swapon -p 5 /dev/zram0
96
97         # set audio powerdown delay (ms)
98         if [ -e /sys/devices/platform/soc-audio/PCM1773/pmdown_time ]; then
99                 echo 60000 > /sys/devices/platform/soc-audio/PCM1773/pmdown_time
100         fi
101 }
102
103 case "$1" in
104   start)
105         echo -n "Starting $DESC: $NAME - "
106         d_start
107         echo "."
108         ;;
109   stop)
110         echo -n "Stopping $DESC: $NAME - "
111         d_stop
112         echo "."
113         ;;
114   reload)
115         echo -n "Reloading $DESC: $NAME - "
116         d_start
117         echo "."
118         ;;      
119   restart|force-reload)
120         echo -n "Restarting $DESC: $NAME - "
121         d_stop
122         sleep 1
123         d_start
124         echo "."
125         ;;
126   *)
127         echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
128         exit 1
129         ;;
130 esac
131
132 exit 0