OSDN Git Service

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