OSDN Git Service

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