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