OSDN Git Service

Merge remote-tracking branch 'x86/nougat-x86' into oreo-x86
[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                 TS10*)
42                         set_prop_if_empty hal.audio.out pcmC0D2p
43                         ;;
44         esac
45 }
46
47 function init_hal_bluetooth()
48 {
49         for r in /sys/class/rfkill/*; do
50                 type=$(cat $r/type)
51                 [ "$type" = "wlan" -o "$type" = "bluetooth" ] && echo 1 > $r/state
52         done
53
54         case "$PRODUCT" in
55                 T100TAF)
56                         set_property bluetooth.interface hci1
57                         ;;
58                 T10*TA|M80TA|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                 *)
119                         [ -n "$video" ] && drm_mode=$video
120                         ;;
121         esac
122
123         [ -n "$drm_mode" ] && set_property debug.drm.mode.force $drm_mode
124 }
125
126 function init_uvesafb()
127 {
128         UVESA_MODE=${UVESA_MODE:-${video%@*}}
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         [ "$VULKAN" = "1" ] && GRALLOC=gbm
144
145         case "$(cat /proc/fb | head -1)" in
146                 *virtiodrmfb)
147                         if [ "$HWACCEL" != "0" ]; then
148                                 set_property ro.hardware.hwcomposer ${HWC:-drm}
149                                 set_property ro.hardware.gralloc ${GRALLOC:-gbm}
150                                 set_property debug.drm.mode.force ${video:-1280x800}
151                         fi
152                         ;;
153                 0*inteldrmfb|0*radeondrmfb|0*nouveaufb|0*svgadrmfb|0*amdgpudrmfb)
154                         if [ "$HWACCEL" != "0" ]; then
155                                 set_property ro.hardware.gralloc ${GRALLOC:-drm}
156                                 set_drm_mode
157                         fi
158                         ;;
159                 "")
160                         init_uvesafb
161                         ;&
162                 0*)
163                         ;;
164         esac
165
166         [ -n "$DEBUG" ] && set_property debug.egl.trace error
167 }
168
169 function init_hal_hwcomposer()
170 {
171         # TODO
172         return
173 }
174
175 function init_hal_vulkan()
176 {
177         case "$(cat /proc/fb | head -1)" in
178                 0*inteldrmfb)
179                         set_property ro.hardware.vulkan android-x86
180                         ;;
181                 0*amdgpudrmfb)
182                         set_property ro.hardware.vulkan radv
183                         ;;
184                 *)
185                         ;;
186         esac
187 }
188
189 function init_hal_lights()
190 {
191         chown 1000.1000 /sys/class/backlight/*/brightness
192 }
193
194 function init_hal_power()
195 {
196         for p in /sys/class/rtc/*; do
197                 echo disabled > $p/device/power/wakeup
198         done
199
200         # TODO
201         case "$PRODUCT" in
202                 HP*Omni*|OEMB|Standard*PC*|Surface*3|T10*TA|VMware*)
203                         set_prop_if_empty sleep.state none
204                         ;;
205                 e-tab*Pro)
206                         set_prop_if_empty sleep.state force
207                         ;;
208                 *)
209                         ;;
210         esac
211 }
212
213 function init_hal_sensors()
214 {
215         # if we have sensor module for our hardware, use it
216         ro_hardware=$(getprop ro.hardware)
217         [ -f /system/lib/hw/sensors.${ro_hardware}.so ] && return 0
218
219         local hal_sensors=kbd
220         local has_sensors=true
221         case "$(cat $DMIPATH/uevent)" in
222                 *Lucid-MWE*)
223                         set_property ro.ignore_atkbd 1
224                         hal_sensors=hdaps
225                         ;;
226                 *ICONIA*W5*)
227                         hal_sensors=w500
228                         ;;
229                 *S10-3t*)
230                         hal_sensors=s103t
231                         ;;
232                 *Inagua*)
233                         #setkeycodes 0x62 29
234                         #setkeycodes 0x74 56
235                         set_property ro.ignore_atkbd 1
236                         set_property hal.sensors.kbd.type 2
237                         ;;
238                 *TEGA*|*2010:svnIntel:*)
239                         set_property ro.ignore_atkbd 1
240                         set_property hal.sensors.kbd.type 1
241                         io_switch 0x0 0x1
242                         setkeycodes 0x6d 125
243                         ;;
244                 *DLI*)
245                         set_property ro.ignore_atkbd 1
246                         set_property hal.sensors.kbd.type 1
247                         setkeycodes 0x64 1
248                         setkeycodes 0x65 172
249                         setkeycodes 0x66 120
250                         setkeycodes 0x67 116
251                         setkeycodes 0x68 114
252                         setkeycodes 0x69 115
253                         setkeycodes 0x6c 114
254                         setkeycodes 0x6d 115
255                         ;;
256                 *tx2*)
257                         setkeycodes 0xb1 138
258                         setkeycodes 0x8a 152
259                         set_property hal.sensors.kbd.type 6
260                         set_property poweroff.doubleclick 0
261                         set_property qemu.hw.mainkeys 1
262                         ;;
263                 *MS-N0E1*)
264                         set_property ro.ignore_atkbd 1
265                         set_property poweroff.doubleclick 0
266                         setkeycodes 0xa5 125
267                         setkeycodes 0xa7 1
268                         setkeycodes 0xe3 142
269                         ;;
270                 *Aspire1*25*)
271                         modprobe lis3lv02d_i2c
272                         echo -n "enabled" > /sys/class/thermal/thermal_zone0/mode
273                         ;;
274                 *ThinkPad*Tablet*)
275                         modprobe hdaps
276                         hal_sensors=hdaps
277                         ;;
278                 *e-tabPro*)
279                         set_property ro.iio.accel.quirks no-trig
280                         ;&
281                 *i7Stylus*|*M80TA*)
282                         set_property ro.iio.accel.x.opt_scale -1
283                         ;;
284                 *ONDATablet*)
285                         set_property ro.iio.accel.order 102
286                         set_property ro.iio.accel.x.opt_scale -1
287                         set_property ro.iio.accel.y.opt_scale -1
288                         ;;
289                 *ST70416-6*)
290                         set_property ro.iio.accel.order 102
291                         ;;
292                 *pnEZpad*)
293                         set_property ro.iio.accel.quirks no-trig
294                         ;&
295                 *T*0*TA*)
296                         set_property ro.iio.accel.y.opt_scale -1
297                         ;;
298                 *)
299                         has_sensors=false
300                         ;;
301         esac
302
303         # has iio sensor-hub?
304         if [ -n "`ls /sys/bus/iio/devices/iio:device* 2> /dev/null`" ]; then
305                 busybox chown -R 1000.1000 /sys/bus/iio/devices/iio:device*/
306                 [ -n "`ls /sys/bus/iio/devices/iio:device*/in_accel_x_raw 2> /dev/null`" ] && has_sensors=true
307                 hal_sensors=iio
308         elif lsmod | grep -q lis3lv02d_i2c; then
309                 hal_sensors=hdaps
310                 has_sensors=true
311         elif [ "$hal_sensors" != "kbd" ]; then
312                 has_sensors=true
313         fi
314
315         set_property ro.hardware.sensors $hal_sensors
316         set_property config.override_forced_orient ${HAS_SENSORS:-$has_sensors}
317 }
318
319 function create_pointercal()
320 {
321         if [ ! -e /data/misc/tscal/pointercal ]; then
322                 mkdir -p /data/misc/tscal
323                 touch /data/misc/tscal/pointercal
324                 chown 1000.1000 /data/misc/tscal /data/misc/tscal/*
325                 chmod 775 /data/misc/tscal
326                 chmod 664 /data/misc/tscal/pointercal
327         fi
328 }
329
330 function init_tscal()
331 {
332         case "$PRODUCT" in
333                 ST70416-6*)
334                         modprobe gslx680_ts_acpi
335                         ;&
336                 T91|T101|ET2002|74499FU|945GSE-ITE8712|CF-19[CDYFGKLP]*)
337                         create_pointercal
338                         return
339                         ;;
340                 *)
341                         ;;
342         esac
343
344         for usbts in $(lsusb | awk '{ print $6 }'); do
345                 case "$usbts" in
346                         0596:0001|0eef:0001)
347                                 create_pointercal
348                                 return
349                                 ;;
350                         *)
351                                 ;;
352                 esac
353         done
354 }
355
356 function init_ril()
357 {
358         case "$(cat $DMIPATH/uevent)" in
359                 *TEGA*|*2010:svnIntel:*|*Lucid-MWE*)
360                         set_property rild.libpath /system/lib/libhuaweigeneric-ril.so
361                         set_property rild.libargs "-d /dev/ttyUSB2 -v /dev/ttyUSB1"
362                         set_property ro.radio.noril no
363                         ;;
364                 *)
365                         set_property ro.radio.noril yes
366                         ;;
367         esac
368 }
369
370 function init_cpu_governor()
371 {
372         governor=$(getprop cpu.governor)
373
374         [ $governor ] && {
375                 for cpu in $(ls -d /sys/devices/system/cpu/cpu?); do
376                         echo $governor > $cpu/cpufreq/scaling_governor || return 1
377                 done
378         }
379 }
380
381 function do_init()
382 {
383         init_misc
384         init_hal_audio
385         init_hal_bluetooth
386         init_hal_camera
387         init_hal_gps
388         init_hal_gralloc
389         init_hal_hwcomposer
390         init_hal_vulkan
391         init_hal_lights
392         init_hal_power
393         init_hal_sensors
394         init_tscal
395         init_ril
396         post_init
397 }
398
399 function do_netconsole()
400 {
401         modprobe netconsole netconsole="@/,@$(getprop dhcp.eth0.gateway)/"
402 }
403
404 function do_bootcomplete()
405 {
406         hciconfig | grep -q hci || pm disable com.android.bluetooth
407
408         init_cpu_governor
409
410         [ -z "$(getprop persist.sys.root_access)" ] && setprop persist.sys.root_access 3
411
412         lsmod | grep -Ehq "brcmfmac|rtl8723be" && setprop wlan.no-unload-driver 1
413
414         case "$PRODUCT" in
415                 1866???|1867???|1869???) # ThinkPad X41 Tablet
416                         start tablet-mode
417                         start wacom-input
418                         setkeycodes 0x6d 115
419                         setkeycodes 0x6e 114
420                         setkeycodes 0x69 28
421                         setkeycodes 0x6b 158
422                         setkeycodes 0x68 172
423                         setkeycodes 0x6c 127
424                         setkeycodes 0x67 217
425                         ;;
426                 6363???|6364???|6366???) # ThinkPad X60 Tablet
427                         ;&
428                 7762???|7763???|7767???) # ThinkPad X61 Tablet
429                         start tablet-mode
430                         start wacom-input
431                         setkeycodes 0x6d 115
432                         setkeycodes 0x6e 114
433                         setkeycodes 0x69 28
434                         setkeycodes 0x6b 158
435                         setkeycodes 0x68 172
436                         setkeycodes 0x6c 127
437                         setkeycodes 0x67 217
438                         ;;
439                 7448???|7449???|7450???|7453???) # ThinkPad X200 Tablet
440                         start tablet-mode
441                         start wacom-input
442                         setkeycodes 0xe012 158
443                         setkeycodes 0x66 172
444                         setkeycodes 0x6b 127
445                         ;;
446                 Surface*Go)
447                         echo on > /sys/devices/pci0000:00/0000:00:15.1/i2c_designware.1/power/control
448                         ;;
449                 VMware*)
450                         pm disable com.android.bluetooth
451                         ;;
452                 *)
453                         ;;
454         esac
455
456 #       [ -d /proc/asound/card0 ] || modprobe snd-dummy
457         for c in $(grep '\[.*\]' /proc/asound/cards | awk '{print $1}'); do
458                 f=/system/etc/alsa/$(cat /proc/asound/card$c/id).state
459                 if [ -e $f ]; then
460                         alsa_ctl -f $f restore $c
461                 else
462                         alsa_ctl init $c
463                         alsa_amixer -c $c set Master on
464                         alsa_amixer -c $c set Master 100%
465                         alsa_amixer -c $c set Headphone on
466                         alsa_amixer -c $c set Headphone 100%
467                         alsa_amixer -c $c set Speaker 100%
468                         alsa_amixer -c $c set Capture 80%
469                         alsa_amixer -c $c set Capture cap
470                         alsa_amixer -c $c set PCM 100 unmute
471                         alsa_amixer -c $c set SPO unmute
472                         alsa_amixer -c $c set IEC958 on
473                         alsa_amixer -c $c set 'Mic Boost' 1
474                         alsa_amixer -c $c set 'Internal Mic Boost' 1
475                 fi
476         done
477
478         post_bootcomplete
479 }
480
481 PATH=/sbin:/system/bin:/system/xbin
482
483 DMIPATH=/sys/class/dmi/id
484 BOARD=$(cat $DMIPATH/board_name)
485 PRODUCT=$(cat $DMIPATH/product_name)
486
487 # import cmdline variables
488 for c in `cat /proc/cmdline`; do
489         case $c in
490                 BOOT_IMAGE=*|iso-scan/*|*.*=*)
491                         ;;
492                 *=*)
493                         eval $c
494                         if [ -z "$1" ]; then
495                                 case $c in
496                                         DEBUG=*)
497                                                 [ -n "$DEBUG" ] && set_property debug.logcat 1
498                                                 ;;
499                                 esac
500                         fi
501                         ;;
502         esac
503 done
504
505 [ -n "$DEBUG" ] && set -x || exec &> /dev/null
506
507 # import the vendor specific script
508 hw_sh=/vendor/etc/init.sh
509 [ -e $hw_sh ] && source $hw_sh
510
511 case "$1" in
512         netconsole)
513                 [ -n "$DEBUG" ] && do_netconsole
514                 ;;
515         bootcomplete)
516                 do_bootcomplete
517                 ;;
518         init|"")
519                 do_init
520                 ;;
521 esac
522
523 return 0