OSDN Git Service

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