OSDN Git Service

Allow to add extra apps
[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                         modprobe ak8975
24                         ;;
25                 *)
26                         ;;
27         esac
28 }
29
30 function init_hal_audio()
31 {
32         case "$PRODUCT" in
33                 VirtualBox*|Bochs*)
34                         [ -d /proc/asound/card0 ] || modprobe snd-sb16 isapnp=0 irq=5
35                         ;;
36                 *)
37                         ;;
38         esac
39 }
40
41 function init_hal_bluetooth()
42 {
43         for r in /sys/class/rfkill/*; do
44                 type=$(cat $r/type)
45                 [ "$type" = "wlan" -o "$type" = "bluetooth" ] && echo 1 > $r/state
46         done
47
48         # these modules are incompatible with bluedroid
49         rmmod ath3k
50         rmmod btusb
51         rmmod bluetooth
52         set_property ro.rfkilldisabled 1
53 }
54
55 function init_hal_camera()
56 {
57         [ -c /dev/video0 ] || modprobe vivi
58 }
59
60 function init_hal_gps()
61 {
62         # TODO
63         return
64 }
65
66 function set_drm_mode()
67 {
68         case "$PRODUCT" in
69                 ET1602*)
70                         drm_mode=1366x768
71                         ;;
72                 *)
73                         ;;
74         esac
75
76         [ -n "$drm_mode" ] && set_property debug.drm.mode.force $drm_mode
77 }
78
79 function init_uvesafb()
80 {
81         case "$PRODUCT" in
82                 *Q550)
83                         UVESA_MODE=${UVESA_MODE:-1280x800}
84                         ;;
85                 ET2002*)
86                         UVESA_MODE=${UVESA_MODE:-1600x900}
87                         ;;
88                 T91*)
89                         UVESA_MODE=${UVESA_MODE:-1024x600}
90                         ;;
91                 VirtualBox*|Bochs*)
92                         UVESA_MODE=${UVESA_MODE:-1024x768}
93                         ;;
94                 *)
95                         ;;
96         esac
97
98         modprobe uvesafb mode_option=${UVESA_MODE:-800x600}-16 ${UVESA_OPTION:-mtrr=3 scroll=redraw}
99 }
100
101 function init_hal_gralloc()
102 {
103         case "$(cat /proc/fb | head -1)" in
104                 0*inteldrmfb|0*radeondrmfb)
105                         set_property ro.hardware.gralloc drm
106                         set_drm_mode
107                         ;;
108                 0*svgadrmfb)
109                         ;;
110                 "")
111                         init_uvesafb
112                         ;&
113                 0*)
114                         [ "$HWACCEL" = "1" ] || set_property debug.egl.hw 0
115                         ;;
116         esac
117 }
118
119 function init_hal_hwcomposer()
120 {
121         # TODO
122         return
123 }
124
125 function init_hal_lights()
126 {
127         chown 1000.1000 /sys/class/backlight/*/brightness
128 }
129
130 function init_hal_power()
131 {
132         for p in /sys/class/rtc/*; do
133                 echo disabled > $p/device/power/wakeup
134         done
135
136         # TODO
137         case "$PRODUCT" in
138                 *)
139                         ;;
140         esac
141 }
142
143 function init_hal_sensors()
144 {
145         local hal_sensors=kbd
146         case "$(cat $DMIPATH/uevent)" in
147                 *Lucid-MWE*)
148                         set_property ro.ignore_atkbd 1
149                         hal_sensors=hdaps
150                         ;;
151                 *ICONIA*W5*)
152                         hal_sensors=w500
153                         ;;
154                 *S10-3t*)
155                         hal_sensors=s103t
156                         ;;
157                 *Inagua*)
158                         #setkeycodes 0x62 29
159                         #setkeycodes 0x74 56
160                         set_property ro.ignore_atkbd 1
161                         set_property hal.sensors.kbd.type 2
162                         ;;
163                 *TEGA*|*2010:svnIntel:*)
164                         set_property ro.ignore_atkbd 1
165                         set_property hal.sensors.kbd.type 1
166                         io_switch 0x0 0x1
167                         setkeycodes 0x6d 125
168                         ;;
169                 *DLI*)
170                         set_property ro.ignore_atkbd 1
171                         set_property hal.sensors.kbd.type 1
172                         setkeycodes 0x64 1
173                         setkeycodes 0x65 172
174                         setkeycodes 0x66 120
175                         setkeycodes 0x67 116
176                         setkeycodes 0x68 114
177                         setkeycodes 0x69 115
178                         setkeycodes 0x6c 114
179                         setkeycodes 0x6d 115
180                         ;;
181                 *tx2*)
182                         setkeycodes 0xb1 138
183                         setkeycodes 0x8a 152
184                         set_property hal.sensors.kbd.type 6
185                         set_property poweroff.doubleclick 0
186                         set_property qemu.hw.mainkeys 1
187                         ;;
188                 *MS-N0E1*)
189                         set_property ro.ignore_atkbd 1
190                         set_property poweroff.doubleclick 0
191                         setkeycodes 0xa5 125
192                         setkeycodes 0xa7 1
193                         setkeycodes 0xe3 142
194                         ;;
195                 *Aspire1*25*)
196                         modprobe lis3lv02d_i2c
197                         hal_sensors=hdaps
198                         echo -n "enabled" > /sys/class/thermal/thermal_zone0/mode
199                         ;;
200                 *ThinkPad*Tablet*)
201                         modprobe hdaps
202                         hal_sensors=hdaps
203                         ;;
204                 *)
205                         ;;
206         esac
207
208         # has sensor-hub?
209         for i in /sys/bus/iio/devices/iio:device?; do
210                 busybox chown -R 1000.1000 /sys/bus/iio/devices/iio:device?/
211                 lsmod | grep -q hid_sensor_accel_3d && hal_sensors=hsb || hal_sensors=iio
212                 break
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