OSDN Git Service

init.sh: fix sensors support for LINX1010B
[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                 *)
42                         ;;
43         esac
44
45         if grep -qi "IntelHDMI" /proc/asound/card0/id; then
46                 [ -d /proc/asound/card1 ] || set_property ro.hardware.audio.primary hdmi
47         fi
48 }
49
50 function init_hal_bluetooth()
51 {
52         for r in /sys/class/rfkill/*; do
53                 type=$(cat $r/type)
54                 [ "$type" = "wlan" -o "$type" = "bluetooth" ] && echo 1 > $r/state
55         done
56
57         case "$PRODUCT" in
58                 T100TAF)
59                         set_property bluetooth.interface hci1
60                         ;;
61                 T10*TA|M80TA|HP*Omni*)
62                         BTUART_PORT=/dev/ttyS1
63                         set_property hal.bluetooth.uart.proto bcm
64                         ;;
65                 MacBookPro8*)
66                         rmmod b43
67                         modprobe b43 btcoex=0
68                         modprobe btusb
69                         ;;
70                 # FIXME
71                 # Fix MacBook 2013-2015 (Air6/7&Pro11/12) BCM4360 ssb&wl conflict.
72                 MacBookPro11* | MacBookPro12* | MacBookAir6* | MacBookAir7*)
73                         rmmod b43
74                         rmmod ssb
75                         rmmod bcma
76                         rmmod wl
77                         modprobe wl
78                         modprobe btusb
79                         ;;
80                 *)
81                         for bt in $(busybox lsusb -v | awk ' /Class:.E0/ { print $9 } '); do
82                                 chown 1002.1002 $bt && chmod 660 $bt
83                         done
84                         ;;
85         esac
86
87         if [ -n "$BTUART_PORT" ]; then
88                 set_property hal.bluetooth.uart $BTUART_PORT
89                 chown bluetooth.bluetooth $BTUART_PORT
90                 start btattach
91         fi
92
93         # rtl8723bs bluetooth
94         if dmesg -t | grep -qE '8723bs.*BT'; then
95                 TTYSTRING=`dmesg -t | grep -E 'tty.*MMIO' | awk '{print $2}' | head -1`
96                 if [ -n "$TTYSTRING" ]; then
97                         echo "RTL8723BS BT uses $TTYSTRING for Bluetooth."
98                         ln -sf $TTYSTRING /dev/rtk_h5
99                         start rtk_hciattach
100                 fi
101         fi
102 }
103
104 function init_hal_camera()
105 {
106         case "$PRODUCT" in
107                 e-tab*Pro)
108                         set_prop_if_empty hal.camera.0 0,270
109                         set_prop_if_empty hal.camera.2 1,90
110                         ;;
111                 *)
112                         ;;
113         esac
114 }
115
116 function init_hal_gps()
117 {
118         # TODO
119         return
120 }
121
122 function set_drm_mode()
123 {
124         case "$PRODUCT" in
125                 ET1602*)
126                         drm_mode=1366x768
127                         ;;
128                 *)
129                         [ -n "$video" ] && drm_mode=$video
130                         ;;
131         esac
132
133         [ -n "$drm_mode" ] && set_property debug.drm.mode.force $drm_mode
134 }
135
136 function init_uvesafb()
137 {
138         UVESA_MODE=${UVESA_MODE:-${video%@*}}
139
140         case "$PRODUCT" in
141                 ET2002*)
142                         UVESA_MODE=${UVESA_MODE:-1600x900}
143                         ;;
144                 *)
145                         ;;
146         esac
147
148         modprobe uvesafb mode_option=${UVESA_MODE:-1024x768}-32 ${UVESA_OPTION:-mtrr=3 scroll=redraw}
149 }
150
151 function init_hal_gralloc()
152 {
153         case "$(cat /proc/fb | head -1)" in
154                 *virtiodrmfb)
155                         if [ "$HWACCEL" != "0" ]; then
156                                 set_property ro.hardware.hwcomposer drm
157                                 set_property ro.hardware.gralloc gbm
158                                 set_property debug.drm.mode.force ${video:-1280x800}
159                         fi
160                         set_prop_if_empty sleep.state none
161                         ;;
162                 0*inteldrmfb|0*radeondrmfb|0*nouveaufb|0*svgadrmfb|0*amdgpudrmfb)
163                         if [ "$HWACCEL" != "0" ]; then
164                                 set_property ro.hardware.gralloc drm
165                                 set_drm_mode
166                         fi
167                         ;;
168                 "")
169                         init_uvesafb
170                         ;&
171                 0*)
172                         ;;
173         esac
174
175         [ -n "$DEBUG" ] && set_property debug.egl.trace error
176 }
177
178 function init_hal_hwcomposer()
179 {
180         # TODO
181         return
182 }
183
184 function init_hal_lights()
185 {
186         chown 1000.1000 /sys/class/backlight/*/brightness
187 }
188
189 function init_hal_power()
190 {
191         for p in /sys/class/rtc/*; do
192                 echo disabled > $p/device/power/wakeup
193         done
194
195         # TODO
196         case "$PRODUCT" in
197                 HP*Omni*|OEMB|Surface*3|T10*TA)
198                         set_prop_if_empty sleep.state none
199                         ;;
200                 e-tab*Pro)
201                         set_prop_if_empty sleep.state force
202                         ;;
203                 *)
204                         ;;
205         esac
206 }
207
208 function init_hal_sensors()
209 {
210         # if we have sensor module for our hardware, use it
211         ro_hardware=$(getprop ro.hardware)
212         [ -f /system/lib/hw/sensors.${ro_hardware}.so ] && return 0
213
214         local hal_sensors=kbd
215         local has_sensors=true
216         case "$(cat $DMIPATH/uevent)" in
217                 *Lucid-MWE*)
218                         set_property ro.ignore_atkbd 1
219                         hal_sensors=hdaps
220                         ;;
221                 *ICONIA*W5*)
222                         hal_sensors=w500
223                         ;;
224                 *S10-3t*)
225                         hal_sensors=s103t
226                         ;;
227                 *Inagua*)
228                         #setkeycodes 0x62 29
229                         #setkeycodes 0x74 56
230                         set_property ro.ignore_atkbd 1
231                         set_property hal.sensors.kbd.type 2
232                         ;;
233                 *TEGA*|*2010:svnIntel:*)
234                         set_property ro.ignore_atkbd 1
235                         set_property hal.sensors.kbd.type 1
236                         io_switch 0x0 0x1
237                         setkeycodes 0x6d 125
238                         ;;
239                 *DLI*)
240                         set_property ro.ignore_atkbd 1
241                         set_property hal.sensors.kbd.type 1
242                         setkeycodes 0x64 1
243                         setkeycodes 0x65 172
244                         setkeycodes 0x66 120
245                         setkeycodes 0x67 116
246                         setkeycodes 0x68 114
247                         setkeycodes 0x69 115
248                         setkeycodes 0x6c 114
249                         setkeycodes 0x6d 115
250                         ;;
251                 *tx2*)
252                         setkeycodes 0xb1 138
253                         setkeycodes 0x8a 152
254                         set_property hal.sensors.kbd.type 6
255                         set_property poweroff.doubleclick 0
256                         set_property qemu.hw.mainkeys 1
257                         ;;
258                 *MS-N0E1*)
259                         set_property ro.ignore_atkbd 1
260                         set_property poweroff.doubleclick 0
261                         setkeycodes 0xa5 125
262                         setkeycodes 0xa7 1
263                         setkeycodes 0xe3 142
264                         ;;
265                 *Aspire1*25*)
266                         modprobe lis3lv02d_i2c
267                         echo -n "enabled" > /sys/class/thermal/thermal_zone0/mode
268                         ;;
269                 *ThinkPad*Tablet*)
270                         modprobe hdaps
271                         hal_sensors=hdaps
272                         ;;
273                 *LINX1010B*)
274                         set_property ro.iio.accel.z.opt_scale -1
275                         ;&
276                 *i7Stylus*|*M80TA*)
277                         set_property ro.iio.accel.x.opt_scale -1
278                         ;;
279                 *ONDATablet*)
280                         set_property ro.iio.accel.order 102
281                         set_property ro.iio.accel.x.opt_scale -1
282                         set_property ro.iio.accel.y.opt_scale -1
283                         ;;
284                 *ST70416-6*)
285                         set_property ro.iio.accel.order 102
286                         ;;
287                 *e-tabPro*|*pnEZpad*)
288                         set_property ro.iio.accel.quirks no-trig
289                         ;&
290                 *T*0*TA*)
291                         set_property ro.iio.accel.y.opt_scale -1
292                         ;;
293                 *)
294                         has_sensors=false
295                         ;;
296         esac
297
298         # has iio sensor-hub?
299         if [ -n "`ls /sys/bus/iio/devices/iio:device* 2> /dev/null`" ]; then
300                 busybox chown -R 1000.1000 /sys/bus/iio/devices/iio:device*/
301                 [ -n "`ls /sys/bus/iio/devices/iio:device*/in_accel_x_raw 2> /dev/null`" ] && has_sensors=true
302                 hal_sensors=iio
303         elif lsmod | grep -q lis3lv02d_i2c; then
304                 hal_sensors=hdaps
305                 has_sensors=true
306         elif [ "$hal_sensors" != "kbd" ]; then
307                 has_sensors=true
308         fi
309
310         set_property ro.hardware.sensors $hal_sensors
311         set_property config.override_forced_orient ${HAS_SENSORS:-$has_sensors}
312 }
313
314 function create_pointercal()
315 {
316         if [ ! -e /data/misc/tscal/pointercal ]; then
317                 mkdir -p /data/misc/tscal
318                 touch /data/misc/tscal/pointercal
319                 chown 1000.1000 /data/misc/tscal /data/misc/tscal/*
320                 chmod 775 /data/misc/tscal
321                 chmod 664 /data/misc/tscal/pointercal
322         fi
323 }
324
325 function init_tscal()
326 {
327         case "$PRODUCT" in
328                 ST70416-6*)
329                         modprobe gslx680_ts_acpi
330                         ;&
331                 T91|T101|ET2002|74499FU|945GSE-ITE8712|CF-19[CDYFGKLP]*)
332                         create_pointercal
333                         return
334                         ;;
335                 *)
336                         ;;
337         esac
338
339         for usbts in $(lsusb | awk '{ print $6 }'); do
340                 case "$usbts" in
341                         0596:0001|0eef:0001)
342                                 create_pointercal
343                                 return
344                                 ;;
345                         *)
346                                 ;;
347                 esac
348         done
349 }
350
351 function init_ril()
352 {
353         case "$(cat $DMIPATH/uevent)" in
354                 *TEGA*|*2010:svnIntel:*|*Lucid-MWE*)
355                         set_property rild.libpath /system/lib/libhuaweigeneric-ril.so
356                         set_property rild.libargs "-d /dev/ttyUSB2 -v /dev/ttyUSB1"
357                         set_property ro.radio.noril no
358                         ;;
359                 *)
360                         set_property ro.radio.noril yes
361                         ;;
362         esac
363 }
364
365 function init_cpu_governor()
366 {
367         governor=$(getprop cpu.governor)
368
369         [ $governor ] && {
370                 for cpu in $(ls -d /sys/devices/system/cpu/cpu?); do
371                         echo $governor > $cpu/cpufreq/scaling_governor || return 1
372                 done
373         }
374 }
375
376 function do_init()
377 {
378         init_misc
379         init_hal_audio
380         init_hal_bluetooth
381         init_hal_camera
382         init_hal_gps
383         init_hal_gralloc
384         init_hal_hwcomposer
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                 *)
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