OSDN Git Service

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