OSDN Git Service

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