OSDN Git Service

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