omap3-pandora-kernel2: update
[openpandora.oe.git] / recipes / pandora-system / pandora-scripts / op_tvout.sh
1 #!/bin/bash
2
3 # defaults
4 profiles=/etc/pandora/conf/tvout-profiles.conf
5 tv_type="pal"
6 conn_type="svideo"
7 layer=0
8 pal_size="658,520"
9 pal_pos="35,35"
10 ntsc_size="655,455"
11 ntsc_pos="40,15"
12
13 usage()
14 {
15   echo "usage: $0 [-d] [-t pal|ntsc] [-c composite|svideo] [-l 0|1|o] [-{p|n}s w,h] [-{p|n}p x,y]"
16   exit 1
17 }
18
19 setup_scaler()
20 {
21   # we must preallocate enough memory for the scaler layer
22   # since the app won't be able to change this
23   # the whole time TV-out is running..
24   ofbset -fb /dev/fb1 -mem $[3*1024*1024] -size 512 256 -en 0
25 }
26
27 enable_it()
28 {
29   size=$pal_size
30   pos=$pal_pos
31   if [ "$tv_type" = "ntsc" ]; then
32     size=$ntsc_size
33     pos=$ntsc_pos
34   fi
35   echo "${tv_type}, ${conn_type}, layer $layer, $pos $size"
36
37   cd /sys/devices/platform/omapdss
38   ovl0=`cat overlay0/enabled`
39   ovl1=`cat overlay1/enabled`
40   echo 0 > display1/enabled
41   echo 0 > overlay0/enabled
42   echo 0 > overlay1/enabled
43   echo 0 > overlay2/enabled
44   echo "" > /sys/class/graphics/fb2/overlays
45   echo "" > /sys/class/graphics/fb1/overlays
46   if [ $layer -eq 1 ]; then
47     setup_scaler
48     echo "0" > /sys/class/graphics/fb0/overlays
49     echo "1,2" > /sys/class/graphics/fb1/overlays
50   else
51     # assume layer 0 for now
52     echo "0,2" > /sys/class/graphics/fb0/overlays
53     echo "1" > /sys/class/graphics/fb1/overlays
54   fi
55   echo $conn_type > display1/venc_type
56   echo "tv" > overlay2/manager
57   echo $tv_type > display1/timings
58   echo $size > overlay2/output_size
59   echo $pos > overlay2/position 
60   echo $ovl0 > overlay0/enabled
61   echo $ovl1 > overlay1/enabled
62   echo 1 > overlay2/enabled
63   echo 1 > display1/enabled
64 }
65
66 disable_it()
67 {
68   cd /sys/devices/platform/omapdss
69   echo 0 > overlay0/enabled
70   echo 0 > overlay1/enabled
71   echo 0 > overlay2/enabled
72   echo 0 > display1/enabled
73   echo "" > /sys/class/graphics/fb2/overlays
74   echo "" > /sys/class/graphics/fb1/overlays
75   echo 0 > /sys/class/graphics/fb0/overlays
76   echo 1 > /sys/class/graphics/fb1/overlays
77   # for system menu, etc
78   echo 2 > /sys/class/graphics/fb2/overlays
79   echo "lcd" > overlay2/manager
80   echo 1 > overlay0/enabled
81 }
82
83 layer_toggle()
84 {
85   tv_on=`cat /sys/devices/platform/omapdss/display1/enabled`
86   if [ "$tv_on" != "1" ]; then
87     echo "tv-out is off, not changing layers"
88     exit 1
89   fi
90   ovl1_on=`cat /sys/devices/platform/omapdss/overlay1/enabled`
91   if [ "$ovl1_on" != "1" ]; then
92     layer=0
93     return
94   fi
95
96   tmp=`cat /sys/class/graphics/fb0/overlays`
97   if [ "$tmp" == "0" ]; then
98     # tv was on overlay
99     layer=0
100   else
101     layer=1
102   fi
103 }
104
105 is_good_tv_type()
106 {
107   if [ "$1" == "pal" -o "$1" == "ntsc" ]; then
108     return 0
109   fi
110   echo "bad tv_type: $1"
111   false
112 }
113
114 is_good_conn_type()
115 {
116   if [ "$1" == "svideo" -o "$1" == "composite" ]; then
117     return 0
118   fi
119   echo "bad conn_type: $1"
120   false
121 }
122
123 is_good_layer()
124 {
125   if [ "$1" == "0" -o "$1" == "1" ]; then
126     return 0
127   fi
128   echo "bad layer: $1"
129   false
130 }
131
132 # read defaults from user profile
133 if test -f "$profiles"; then
134   defprofile=`grep -A1 '^Last written' "$profiles" | tail -n 1`
135   if test -n "$defprofile"; then
136     parse_profile()
137     {
138       # enabled
139       # encoding
140       is_good_tv_type $2 && tv_type=$2
141       # connection
142       is_good_conn_type $3 && conn_type=$3
143       # layer
144       is_good_layer $4 && layer=$4
145       # x,y
146       test -n "$5" -a -n "$6" && eval ${tv_type}_pos=$5,$6
147       # w,h
148       test -n "$7" -a -n "$8" && eval ${tv_type}_size=$7,$8
149     }
150
151     parse_profile $defprofile
152     echo "loaded defaults from last used profile"
153   fi
154 fi
155
156 # parse args
157 while true; do
158   case $1 in
159     "-d")
160       disable_it
161       exit 0
162       ;;
163     "-t")
164       shift
165       tv_type=$1
166       ;;
167     "-c")
168       shift
169       conn_type=$1
170       ;;
171     "-l")
172       shift
173       if [ "$1" == "o" ]; then
174         # "other layer" - switch to different layer
175         layer_toggle
176       else
177         layer=$1
178       fi
179       ;;
180     "-ps")
181       shift
182       if [ "$1" != "0,0" ]; then
183         pal_size=$1
184       else
185         echo "warning: ignored pal_size: $1"
186       fi
187       ;;
188     "-pp")
189       shift
190       pal_pos=$1
191       ;;
192     "-ns")
193       shift
194       if [ "$1" != "0,0" ]; then
195         ntsc_size=$1
196       else
197         echo "warning: ignored ntsc_size: $1"
198       fi
199       ;;
200     "-np")
201       shift
202       ntsc_pos=$1
203       ;;
204     "")
205       ;;
206     *)
207       usage
208       ;;
209   esac
210
211   if ! shift; then break; fi
212 done
213
214 if ! is_good_tv_type $tv_type; then
215   usage
216 fi
217
218 if ! is_good_conn_type $conn_type; then
219   usage
220 fi
221
222 if ! is_good_layer $layer; then
223   usage
224 fi
225
226 enable_it