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