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)
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                 *T*0*TA*|*pnEZpad*)
287                         set_property ro.iio.accel.y.opt_scale -1
288                         ;;
289                 *)
290                         has_sensors=false
291                         ;;
292         esac
293
294         # has iio sensor-hub?
295         if [ -n "`ls /sys/bus/iio/devices/iio:device* 2> /dev/null`" ]; then
296                 busybox chown -R 1000.1000 /sys/bus/iio/devices/iio:device*/
297                 [ -n "`ls /sys/bus/iio/devices/iio:device*/in_accel_x_raw 2> /dev/null`" ] && has_sensors=true
298                 hal_sensors=iio
299         elif lsmod | grep -q lis3lv02d_i2c; then
300                 hal_sensors=hdaps
301                 has_sensors=true
302         elif [ "$hal_sensors" != "kbd" ]; then
303                 has_sensors=true
304         fi
305
306         set_property ro.hardware.sensors $hal_sensors
307         set_property config.override_forced_orient ${HAS_SENSORS:-$has_sensors}
308 }
309
310 function create_pointercal()
311 {
312         if [ ! -e /data/misc/tscal/pointercal ]; then
313                 mkdir -p /data/misc/tscal
314                 touch /data/misc/tscal/pointercal
315                 chown 1000.1000 /data/misc/tscal /data/misc/tscal/*
316                 chmod 775 /data/misc/tscal
317                 chmod 664 /data/misc/tscal/pointercal
318         fi
319 }
320
321 function init_tscal()
322 {
323         case "$PRODUCT" in
324                 ST70416-6*)
325                         modprobe gslx680_ts_acpi
326                         ;&
327                 T91|T101|ET2002|74499FU|945GSE-ITE8712|CF-19[CDYFGKLP]*)
328                         create_pointercal
329                         return
330                         ;;
331                 *)
332                         ;;
333         esac
334
335         for usbts in $(lsusb | awk '{ print $6 }'); do
336                 case "$usbts" in
337                         0596:0001|0eef:0001)
338                                 create_pointercal
339                                 return
340                                 ;;
341                         *)
342                                 ;;
343                 esac
344         done
345 }
346
347 function init_ril()
348 {
349         case "$(cat $DMIPATH/uevent)" in
350                 *TEGA*|*2010:svnIntel:*|*Lucid-MWE*)
351                         set_property rild.libpath /system/lib/libhuaweigeneric-ril.so
352                         set_property rild.libargs "-d /dev/ttyUSB2 -v /dev/ttyUSB1"
353                         set_property ro.radio.noril no
354                         ;;
355                 *)
356                         set_property ro.radio.noril yes
357                         ;;
358         esac
359 }
360
361 function init_cpu_governor()
362 {
363         governor=$(getprop cpu.governor)
364
365         [ $governor ] && {
366                 for cpu in $(ls -d /sys/devices/system/cpu/cpu?); do
367                         echo $governor > $cpu/cpufreq/scaling_governor || return 1
368                 done
369         }
370 }
371
372 function do_init()
373 {
374         init_misc
375         init_hal_audio
376         init_hal_bluetooth
377         init_hal_camera
378         init_hal_gps
379         init_hal_gralloc
380         init_hal_hwcomposer
381         init_hal_vulkan
382         init_hal_lights
383         init_hal_power
384         init_hal_sensors
385         init_tscal
386         init_ril
387         post_init
388 }
389
390 function do_netconsole()
391 {
392         modprobe netconsole netconsole="@/,@$(getprop dhcp.eth0.gateway)/"
393 }
394
395 function do_bootcomplete()
396 {
397         hciconfig | grep -q hci || pm disable com.android.bluetooth
398
399         init_cpu_governor
400
401         [ -z "$(getprop persist.sys.root_access)" ] && setprop persist.sys.root_access 3
402
403         lsmod | grep -Ehq "brcmfmac|rtl8723be" && setprop wlan.no-unload-driver 1
404
405         case "$PRODUCT" in
406                 1866???|1867???|1869???) # ThinkPad X41 Tablet
407                         start tablet-mode
408                         start wacom-input
409                         setkeycodes 0x6d 115
410                         setkeycodes 0x6e 114
411                         setkeycodes 0x69 28
412                         setkeycodes 0x6b 158
413                         setkeycodes 0x68 172
414                         setkeycodes 0x6c 127
415                         setkeycodes 0x67 217
416                         ;;
417                 6363???|6364???|6366???) # ThinkPad X60 Tablet
418                         ;&
419                 7762???|7763???|7767???) # ThinkPad X61 Tablet
420                         start tablet-mode
421                         start wacom-input
422                         setkeycodes 0x6d 115
423                         setkeycodes 0x6e 114
424                         setkeycodes 0x69 28
425                         setkeycodes 0x6b 158
426                         setkeycodes 0x68 172
427                         setkeycodes 0x6c 127
428                         setkeycodes 0x67 217
429                         ;;
430                 7448???|7449???|7450???|7453???) # ThinkPad X200 Tablet
431                         start tablet-mode
432                         start wacom-input
433                         setkeycodes 0xe012 158
434                         setkeycodes 0x66 172
435                         setkeycodes 0x6b 127
436                         ;;
437                 Surface*Go)
438                         echo on > /sys/devices/pci0000:00/0000:00:15.1/i2c_designware.1/power/control
439                         ;;
440                 VMware*)
441                         pm disable com.android.bluetooth
442                         ;;
443                 *)
444                         ;;
445         esac
446
447 #       [ -d /proc/asound/card0 ] || modprobe snd-dummy
448         for c in $(grep '\[.*\]' /proc/asound/cards | awk '{print $1}'); do
449                 f=/system/etc/alsa/$(cat /proc/asound/card$c/id).state
450                 if [ -e $f ]; then
451                         alsa_ctl -f $f restore $c
452                 else
453                         alsa_ctl init $c
454                         alsa_amixer -c $c set Master on
455                         alsa_amixer -c $c set Master 100%
456                         alsa_amixer -c $c set Headphone on
457                         alsa_amixer -c $c set Headphone 100%
458                         alsa_amixer -c $c set Speaker 100%
459                         alsa_amixer -c $c set Capture 80%
460                         alsa_amixer -c $c set Capture cap
461                         alsa_amixer -c $c set PCM 100 unmute
462                         alsa_amixer -c $c set SPO unmute
463                         alsa_amixer -c $c set IEC958 on
464                         alsa_amixer -c $c set 'Mic Boost' 1
465                         alsa_amixer -c $c set 'Internal Mic Boost' 1
466                 fi
467         done
468
469         post_bootcomplete
470 }
471
472 PATH=/sbin:/system/bin:/system/xbin
473
474 DMIPATH=/sys/class/dmi/id
475 BOARD=$(cat $DMIPATH/board_name)
476 PRODUCT=$(cat $DMIPATH/product_name)
477
478 # import cmdline variables
479 for c in `cat /proc/cmdline`; do
480         case $c in
481                 BOOT_IMAGE=*|iso-scan/*|*.*=*)
482                         ;;
483                 *=*)
484                         eval $c
485                         if [ -z "$1" ]; then
486                                 case $c in
487                                         DEBUG=*)
488                                                 [ -n "$DEBUG" ] && set_property debug.logcat 1
489                                                 ;;
490                                 esac
491                         fi
492                         ;;
493         esac
494 done
495
496 [ -n "$DEBUG" ] && set -x || exec &> /dev/null
497
498 # import the vendor specific script
499 hw_sh=/vendor/etc/init.sh
500 [ -e $hw_sh ] && source $hw_sh
501
502 case "$1" in
503         netconsole)
504                 [ -n "$DEBUG" ] && do_netconsole
505                 ;;
506         bootcomplete)
507                 do_bootcomplete
508                 ;;
509         init|"")
510                 do_init
511                 ;;
512 esac
513
514 return 0