OSDN Git Service

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