OSDN Git Service

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