OSDN Git Service

906f081096499b22a57f79bd0271efd5121ebf7a
[android-x86/device-generic-common.git] / init.sh
1 #
2 # Copyright (C) 2013 The Android-x86 Open Source Project
3 #
4 # License: GNU Public License v2 or later
5 #
6
7 function set_property()
8 {
9         # this must be run before post-fs stage
10         echo $1=$2 >> /x86.prop
11 }
12
13 function init_misc()
14 {
15         # a hack for USB modem
16         lsusb | grep 1a8d:1000 && eject
17
18         # in case no cpu governor driver autoloads
19         [ -d /sys/devices/system/cpu/cpu0/cpufreq ] || modprobe acpi-cpufreq
20
21         case "$PRODUCT" in
22                 T10*TA)
23                         ;;
24                 *)
25                         ;;
26         esac
27 }
28
29 function init_hal_audio()
30 {
31         case "$PRODUCT" in
32                 VirtualBox*|Bochs*)
33                         [ -d /proc/asound/card0 ] || modprobe snd-sb16 isapnp=0 irq=5
34                         ;;
35                 *)
36                         ;;
37         esac
38 }
39
40 function init_hal_bluetooth()
41 {
42         for r in /sys/class/rfkill/*; do
43                 type=$(cat $r/type)
44                 [ "$type" = "wlan" -o "$type" = "bluetooth" ] && echo 1 > $r/state
45         done
46
47         # these modules are incompatible with bluedroid
48         rmmod ath3k
49         rmmod btusb
50         rmmod bluetooth
51         set_property ro.rfkilldisabled 1
52 }
53
54 function init_hal_camera()
55 {
56         [ -c /dev/video0 ] || modprobe vivi
57 }
58
59 function init_hal_gps()
60 {
61         # TODO
62         return
63 }
64
65 function set_drm_mode()
66 {
67         case "$PRODUCT" in
68                 ET1602*)
69                         drm_mode=1366x768
70                         ;;
71                 *)
72                         ;;
73         esac
74
75         [ -n "$drm_mode" ] && set_property debug.drm.mode.force $drm_mode
76 }
77
78 function init_uvesafb()
79 {
80         case "$PRODUCT" in
81                 *Q550)
82                         UVESA_MODE=${UVESA_MODE:-1280x800}
83                         ;;
84                 ET2002*)
85                         UVESA_MODE=${UVESA_MODE:-1600x900}
86                         ;;
87                 T91*)
88                         UVESA_MODE=${UVESA_MODE:-1024x600}
89                         ;;
90                 VirtualBox*|Bochs*)
91                         UVESA_MODE=${UVESA_MODE:-1024x768}
92                         ;;
93                 *)
94                         ;;
95         esac
96
97         modprobe uvesafb mode_option=${UVESA_MODE:-800x600}-16 ${UVESA_OPTION:-mtrr=3 scroll=redraw}
98 }
99
100 function init_hal_gralloc()
101 {
102         case "$(cat /proc/fb | head -1)" in
103                 0*inteldrmfb|0*radeondrmfb)
104                         set_property ro.hardware.gralloc drm
105                         set_drm_mode
106                         ;;
107                 0*svgadrmfb)
108                         ;;
109                 "")
110                         init_uvesafb
111                         ;&
112                 0*)
113                         [ "$HWACCEL" = "1" ] || set_property debug.egl.hw 0
114                         ;;
115         esac
116 }
117
118 function init_hal_hwcomposer()
119 {
120         # TODO
121         return
122 }
123
124 function init_hal_lights()
125 {
126         chown 1000.1000 /sys/class/backlight/*/brightness
127 }
128
129 function init_hal_power()
130 {
131         for p in /sys/class/rtc/*; do
132                 echo disabled > $p/device/power/wakeup
133         done
134
135         # TODO
136         case "$PRODUCT" in
137                 *)
138                         ;;
139         esac
140 }
141
142 function init_hal_sensors()
143 {
144         local hal_sensors=kbd
145         case "$(cat $DMIPATH/uevent)" in
146                 *Lucid-MWE*)
147                         set_property ro.ignore_atkbd 1
148                         hal_sensors=hdaps
149                         ;;
150                 *ICONIA*W5*)
151                         hal_sensors=w500
152                         ;;
153                 *S10-3t*)
154                         hal_sensors=s103t
155                         ;;
156                 *Inagua*)
157                         #setkeycodes 0x62 29
158                         #setkeycodes 0x74 56
159                         set_property ro.ignore_atkbd 1
160                         set_property hal.sensors.kbd.type 2
161                         ;;
162                 *TEGA*|*2010:svnIntel:*)
163                         set_property ro.ignore_atkbd 1
164                         set_property hal.sensors.kbd.type 1
165                         io_switch 0x0 0x1
166                         setkeycodes 0x6d 125
167                         ;;
168                 *DLI*)
169                         set_property ro.ignore_atkbd 1
170                         set_property hal.sensors.kbd.type 1
171                         setkeycodes 0x64 1
172                         setkeycodes 0x65 172
173                         setkeycodes 0x66 120
174                         setkeycodes 0x67 116
175                         setkeycodes 0x68 114
176                         setkeycodes 0x69 115
177                         setkeycodes 0x6c 114
178                         setkeycodes 0x6d 115
179                         ;;
180                 *tx2*)
181                         setkeycodes 0xb1 138
182                         setkeycodes 0x8a 152
183                         set_property hal.sensors.kbd.type 6
184                         set_property poweroff.doubleclick 0
185                         set_property qemu.hw.mainkeys 1
186                         ;;
187                 *MS-N0E1*)
188                         set_property ro.ignore_atkbd 1
189                         set_property poweroff.doubleclick 0
190                         setkeycodes 0xa5 125
191                         setkeycodes 0xa7 1
192                         setkeycodes 0xe3 142
193                         ;;
194                 *Aspire1*25*)
195                         modprobe lis3lv02d_i2c
196                         hal_sensors=hdaps
197                         echo -n "enabled" > /sys/class/thermal/thermal_zone0/mode
198                         ;;
199                 *ThinkPad*Tablet*)
200                         modprobe hdaps
201                         hal_sensors=hdaps
202                         ;;
203                 *)
204                         ;;
205         esac
206
207         # has sensor-hub?
208         for i in /sys/bus/iio/devices/iio:device?; do
209                 if [ -e $i/in_accel_scale ]; then
210                         busybox chown -R 1000.1000 /sys/bus/iio/devices/iio:device?/
211                         hal_sensors=hsb
212                         break
213                 fi
214         done
215
216         set_property ro.hardware.sensors $hal_sensors
217 }
218
219 function create_pointercal()
220 {
221         if [ ! -e /data/misc/tscal/pointercal ]; then
222                 mkdir -p /data/misc/tscal
223                 touch /data/misc/tscal/pointercal
224                 chown 1000.1000 /data/misc/tscal /data/misc/tscal/*
225                 chmod 775 /data/misc/tscal
226                 chmod 664 /data/misc/tscal/pointercal
227         fi
228 }
229
230 function init_tscal()
231 {
232         case "$PRODUCT" in
233                 T91|T101|ET2002|74499FU|945GSE-ITE8712|CF-19[CDYFGKLP]*)
234                         create_pointercal
235                         return
236                         ;;
237                 *)
238                         ;;
239         esac
240
241         for usbts in $(lsusb | awk '{ print $6 }'); do
242                 case "$usbts" in
243                         0596:0001|0eef:0001)
244                                 create_pointercal
245                                 return
246                                 ;;
247                         *)
248                                 ;;
249                 esac
250         done
251 }
252
253 function init_ril()
254 {
255         case "$(cat $DMIPATH/uevent)" in
256                 *TEGA*|*2010:svnIntel:*|*Lucid-MWE*)
257                         set_property rild.libpath /system/lib/libhuaweigeneric-ril.so
258                         set_property rild.libargs "-d /dev/ttyUSB2 -v /dev/ttyUSB1"
259                         ;;
260                 *)
261                         set_property rild.libpath /system/lib/libreference-ril.so
262                         set_property rild.libargs "-d /dev/ttyUSB2"
263                         ;;
264         esac
265 }
266
267 function init_cpu_governor()
268 {
269         governor=$(getprop cpu.governor)
270
271         [ $governor ] && {
272                 for cpu in $(ls -d /sys/devices/system/cpu/cpu?); do
273                         echo $governor > $cpu/cpufreq/scaling_governor || return 1
274                 done
275         }
276 }
277
278 function do_init()
279 {
280         init_misc
281         init_hal_audio
282         init_hal_bluetooth
283         init_hal_camera
284         init_hal_gps
285         init_hal_gralloc
286         init_hal_hwcomposer
287         init_hal_lights
288         init_hal_power
289         init_hal_sensors
290         init_tscal
291         init_ril
292         chmod 640 /x86.prop
293         post_init
294 }
295
296 function do_netconsole()
297 {
298         modprobe netconsole netconsole="@/,@$(getprop dhcp.eth0.gateway)/"
299 }
300
301 function do_bootcomplete()
302 {
303         init_cpu_governor
304
305         [ -z "$(getprop persist.sys.root_access)" ] && setprop persist.sys.root_access 3
306
307         # FIXME: autosleep works better on i965?
308         [ "$(getprop debug.mesa.driver)" = "i965" ] && setprop debug.autosleep 1
309
310         lsmod | grep -e brcmfmac && setprop wlan.no-unload-driver 1
311
312         for bt in $(lsusb -v | awk ' /Class:.E0/ { print $9 } '); do
313                 chown 1002.1002 $bt && chmod 660 $bt
314         done
315
316         case "$PRODUCT" in
317                 1866???|1867???|1869???) # ThinkPad X41 Tablet
318                         start tablet-mode
319                         start wacom-input
320                         setkeycodes 0x6d 115
321                         setkeycodes 0x6e 114
322                         setkeycodes 0x69 28
323                         setkeycodes 0x6b 158
324                         setkeycodes 0x68 172
325                         setkeycodes 0x6c 127
326                         setkeycodes 0x67 217
327                         ;;
328                 6363???|6364???|6366???) # ThinkPad X60 Tablet
329                         ;&
330                 7762???|7763???|7767???) # ThinkPad X61 Tablet
331                         start tablet-mode
332                         start wacom-input
333                         setkeycodes 0x6d 115
334                         setkeycodes 0x6e 114
335                         setkeycodes 0x69 28
336                         setkeycodes 0x6b 158
337                         setkeycodes 0x68 172
338                         setkeycodes 0x6c 127
339                         setkeycodes 0x67 217
340                         ;;
341                 7448???|7449???|7450???|7453???) # ThinkPad X200 Tablet
342                         start tablet-mode
343                         start wacom-input
344                         setkeycodes 0xe012 158
345                         setkeycodes 0x66 172
346                         setkeycodes 0x6b 127
347                         ;;
348                 *)
349                         ;;
350         esac
351
352 #       [ -d /proc/asound/card0 ] || modprobe snd-dummy
353         for c in $(grep '\[.*\]' /proc/asound/cards | awk '{print $1}'); do
354                 f=/system/etc/alsa/$(cat /proc/asound/card$c/id).state
355                 if [ -e $f ]; then
356                         alsa_ctl -f $f restore $c
357                 else
358                         alsa_ctl init $c
359                         alsa_amixer -c $c set Master on
360                         alsa_amixer -c $c set Master 100%
361                         alsa_amixer -c $c set Headphone on
362                         alsa_amixer -c $c set Headphone 100%
363                         alsa_amixer -c $c set Speaker 100%
364                         alsa_amixer -c $c set Capture 100%
365                         alsa_amixer -c $c set Capture cap
366                         alsa_amixer -c $c set PCM 100 unmute
367                         alsa_amixer -c $c set 'Mic Boost' 3
368                         alsa_amixer -c $c set 'Internal Mic Boost' 3
369                 fi
370         done
371 }
372
373 PATH=/system/bin:/system/xbin
374
375 DMIPATH=/sys/class/dmi/id
376 BOARD=$(cat $DMIPATH/board_name)
377 PRODUCT=$(cat $DMIPATH/product_name)
378
379 # import cmdline variables
380 for c in `cat /proc/cmdline`; do
381         case $c in
382                 androidboot.hardware=*)
383                         ;;
384                 *=*)
385                         eval $c
386                         ;;
387         esac
388 done
389
390 [ -n "$DEBUG" ] && set -x || exec &> /dev/null
391
392 # import the vendor specific script
393 hw_sh=/vendor/etc/init.sh
394 [ -e $hw_sh ] && source $hw_sh
395
396 case "$1" in
397         netconsole)
398                 [ -n "$DEBUG" ] && do_netconsole
399                 ;;
400         bootcomplete)
401                 do_bootcomplete
402                 ;;
403         init|"")
404                 do_init
405                 ;;
406 esac
407
408 return 0