OSDN Git Service

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