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                 *)
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         return
107 }
108
109 function init_hal_gps()
110 {
111         # TODO
112         return
113 }
114
115 function set_drm_mode()
116 {
117         case "$PRODUCT" in
118                 ET1602*)
119                         drm_mode=1366x768
120                         ;;
121                 *)
122                         [ -n "$video" ] && drm_mode=$video
123                         ;;
124         esac
125
126         [ -n "$drm_mode" ] && set_property debug.drm.mode.force $drm_mode
127 }
128
129 function init_uvesafb()
130 {
131         case "$PRODUCT" in
132                 ET2002*)
133                         UVESA_MODE=${UVESA_MODE:-1600x900}
134                         ;;
135                 *)
136                         ;;
137         esac
138
139         modprobe uvesafb mode_option=${UVESA_MODE:-1024x768}-32 ${UVESA_OPTION:-mtrr=3 scroll=redraw}
140 }
141
142 function init_hal_gralloc()
143 {
144         case "$(cat /proc/fb | head -1)" in
145                 *virtiodrmfb)
146                         if [ "$HWACCEL" != "0" ]; then
147                                 set_property ro.hardware.hwcomposer drm
148                                 set_property ro.hardware.gralloc gbm
149                                 set_property debug.drm.mode.force ${video:-1280x800}
150                         fi
151                         set_prop_if_empty sleep.state none
152                         ;;
153                 0*inteldrmfb|0*radeondrmfb|0*nouveaufb|0*svgadrmfb|0*amdgpudrmfb)
154                         if [ "$HWACCEL" != "0" ]; then
155                                 set_property ro.hardware.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_lights()
176 {
177         chown 1000.1000 /sys/class/backlight/*/brightness
178 }
179
180 function init_hal_power()
181 {
182         for p in /sys/class/rtc/*; do
183                 echo disabled > $p/device/power/wakeup
184         done
185
186         # TODO
187         case "$PRODUCT" in
188                 HP*Omni*|OEMB|Surface*3|T10*TA)
189                         set_prop_if_empty sleep.state none
190                         ;;
191                 *)
192                         ;;
193         esac
194 }
195
196 function init_hal_sensors()
197 {
198         # if we have sensor module for our hardware, use it
199         ro_hardware=$(getprop ro.hardware)
200         [ -f /system/lib/hw/sensors.${ro_hardware}.so ] && return 0
201
202         local hal_sensors=kbd
203         local has_sensors=true
204         case "$(cat $DMIPATH/uevent)" in
205                 *Lucid-MWE*)
206                         set_property ro.ignore_atkbd 1
207                         hal_sensors=hdaps
208                         ;;
209                 *ICONIA*W5*)
210                         hal_sensors=w500
211                         ;;
212                 *S10-3t*)
213                         hal_sensors=s103t
214                         ;;
215                 *Inagua*)
216                         #setkeycodes 0x62 29
217                         #setkeycodes 0x74 56
218                         set_property ro.ignore_atkbd 1
219                         set_property hal.sensors.kbd.type 2
220                         ;;
221                 *TEGA*|*2010:svnIntel:*)
222                         set_property ro.ignore_atkbd 1
223                         set_property hal.sensors.kbd.type 1
224                         io_switch 0x0 0x1
225                         setkeycodes 0x6d 125
226                         ;;
227                 *DLI*)
228                         set_property ro.ignore_atkbd 1
229                         set_property hal.sensors.kbd.type 1
230                         setkeycodes 0x64 1
231                         setkeycodes 0x65 172
232                         setkeycodes 0x66 120
233                         setkeycodes 0x67 116
234                         setkeycodes 0x68 114
235                         setkeycodes 0x69 115
236                         setkeycodes 0x6c 114
237                         setkeycodes 0x6d 115
238                         ;;
239                 *tx2*)
240                         setkeycodes 0xb1 138
241                         setkeycodes 0x8a 152
242                         set_property hal.sensors.kbd.type 6
243                         set_property poweroff.doubleclick 0
244                         set_property qemu.hw.mainkeys 1
245                         ;;
246                 *MS-N0E1*)
247                         set_property ro.ignore_atkbd 1
248                         set_property poweroff.doubleclick 0
249                         setkeycodes 0xa5 125
250                         setkeycodes 0xa7 1
251                         setkeycodes 0xe3 142
252                         ;;
253                 *Aspire1*25*)
254                         modprobe lis3lv02d_i2c
255                         echo -n "enabled" > /sys/class/thermal/thermal_zone0/mode
256                         ;;
257                 *ThinkPad*Tablet*)
258                         modprobe hdaps
259                         hal_sensors=hdaps
260                         ;;
261                 *i7Stylus*|*M80TA*)
262                         set_property ro.iio.accel.x.opt_scale -1
263                         ;;
264                 *ONDATablet*)
265                         set_property ro.iio.accel.order 102
266                         set_property ro.iio.accel.x.opt_scale -1
267                         set_property ro.iio.accel.y.opt_scale -1
268                         ;;
269                 *ST70416-6*)
270                         set_property ro.iio.accel.order 102
271                         ;;
272                 *T*0*TA*|*pnEZpad*)
273                         set_property ro.iio.accel.y.opt_scale -1
274                         ;;
275                 *)
276                         has_sensors=false
277                         ;;
278         esac
279
280         # has iio sensor-hub?
281         if [ -n "`ls /sys/bus/iio/devices/iio:device* 2> /dev/null`" ]; then
282                 busybox chown -R 1000.1000 /sys/bus/iio/devices/iio:device*/
283                 [ -n "`ls /sys/bus/iio/devices/iio:device*/in_accel_x_raw 2> /dev/null`" ] && has_sensors=true
284                 hal_sensors=iio
285         elif lsmod | grep -q lis3lv02d_i2c; then
286                 hal_sensors=hdaps
287                 has_sensors=true
288         elif [ "$hal_sensors" != "kbd" ]; then
289                 has_sensors=true
290         fi
291
292         set_property ro.hardware.sensors $hal_sensors
293         set_property config.override_forced_orient ${HAS_SENSORS:-$has_sensors}
294 }
295
296 function create_pointercal()
297 {
298         if [ ! -e /data/misc/tscal/pointercal ]; then
299                 mkdir -p /data/misc/tscal
300                 touch /data/misc/tscal/pointercal
301                 chown 1000.1000 /data/misc/tscal /data/misc/tscal/*
302                 chmod 775 /data/misc/tscal
303                 chmod 664 /data/misc/tscal/pointercal
304         fi
305 }
306
307 function init_tscal()
308 {
309         case "$PRODUCT" in
310                 ST70416-6*)
311                         modprobe gslx680_ts_acpi
312                         ;&
313                 T91|T101|ET2002|74499FU|945GSE-ITE8712|CF-19[CDYFGKLP]*)
314                         create_pointercal
315                         return
316                         ;;
317                 *)
318                         ;;
319         esac
320
321         for usbts in $(lsusb | awk '{ print $6 }'); do
322                 case "$usbts" in
323                         0596:0001|0eef:0001)
324                                 create_pointercal
325                                 return
326                                 ;;
327                         *)
328                                 ;;
329                 esac
330         done
331 }
332
333 function init_ril()
334 {
335         case "$(cat $DMIPATH/uevent)" in
336                 *TEGA*|*2010:svnIntel:*|*Lucid-MWE*)
337                         set_property rild.libpath /system/lib/libhuaweigeneric-ril.so
338                         set_property rild.libargs "-d /dev/ttyUSB2 -v /dev/ttyUSB1"
339                         set_property ro.radio.noril no
340                         ;;
341                 *)
342                         set_property ro.radio.noril yes
343                         ;;
344         esac
345 }
346
347 function init_cpu_governor()
348 {
349         governor=$(getprop cpu.governor)
350
351         [ $governor ] && {
352                 for cpu in $(ls -d /sys/devices/system/cpu/cpu?); do
353                         echo $governor > $cpu/cpufreq/scaling_governor || return 1
354                 done
355         }
356 }
357
358 function do_init()
359 {
360         init_misc
361         init_hal_audio
362         init_hal_bluetooth
363         init_hal_camera
364         init_hal_gps
365         init_hal_gralloc
366         init_hal_hwcomposer
367         init_hal_lights
368         init_hal_power
369         init_hal_sensors
370         init_tscal
371         init_ril
372         post_init
373 }
374
375 function do_netconsole()
376 {
377         modprobe netconsole netconsole="@/,@$(getprop dhcp.eth0.gateway)/"
378 }
379
380 function do_bootcomplete()
381 {
382         hciconfig | grep -q hci || pm disable com.android.bluetooth
383
384         init_cpu_governor
385
386         [ -z "$(getprop persist.sys.root_access)" ] && setprop persist.sys.root_access 3
387
388         lsmod | grep -Ehq "brcmfmac|rtl8723be" && setprop wlan.no-unload-driver 1
389
390         case "$PRODUCT" in
391                 1866???|1867???|1869???) # ThinkPad X41 Tablet
392                         start tablet-mode
393                         start wacom-input
394                         setkeycodes 0x6d 115
395                         setkeycodes 0x6e 114
396                         setkeycodes 0x69 28
397                         setkeycodes 0x6b 158
398                         setkeycodes 0x68 172
399                         setkeycodes 0x6c 127
400                         setkeycodes 0x67 217
401                         ;;
402                 6363???|6364???|6366???) # ThinkPad X60 Tablet
403                         ;&
404                 7762???|7763???|7767???) # ThinkPad X61 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                 7448???|7449???|7450???|7453???) # ThinkPad X200 Tablet
416                         start tablet-mode
417                         start wacom-input
418                         setkeycodes 0xe012 158
419                         setkeycodes 0x66 172
420                         setkeycodes 0x6b 127
421                         ;;
422                 VMware*)
423                         pm disable com.android.bluetooth
424                         ;;
425                 *)
426                         ;;
427         esac
428
429 #       [ -d /proc/asound/card0 ] || modprobe snd-dummy
430         for c in $(grep '\[.*\]' /proc/asound/cards | awk '{print $1}'); do
431                 f=/system/etc/alsa/$(cat /proc/asound/card$c/id).state
432                 if [ -e $f ]; then
433                         alsa_ctl -f $f restore $c
434                 else
435                         alsa_ctl init $c
436                         alsa_amixer -c $c set Master on
437                         alsa_amixer -c $c set Master 100%
438                         alsa_amixer -c $c set Headphone on
439                         alsa_amixer -c $c set Headphone 100%
440                         alsa_amixer -c $c set Speaker 100%
441                         alsa_amixer -c $c set Capture 80%
442                         alsa_amixer -c $c set Capture cap
443                         alsa_amixer -c $c set PCM 100 unmute
444                         alsa_amixer -c $c set SPO unmute
445                         alsa_amixer -c $c set IEC958 on
446                         alsa_amixer -c $c set 'Mic Boost' 1
447                         alsa_amixer -c $c set 'Internal Mic Boost' 1
448                 fi
449         done
450
451         post_bootcomplete
452 }
453
454 PATH=/sbin:/system/bin:/system/xbin
455
456 DMIPATH=/sys/class/dmi/id
457 BOARD=$(cat $DMIPATH/board_name)
458 PRODUCT=$(cat $DMIPATH/product_name)
459
460 # import cmdline variables
461 for c in `cat /proc/cmdline`; do
462         case $c in
463                 BOOT_IMAGE=*|iso-scan/*|*.*=*)
464                         ;;
465                 *=*)
466                         eval $c
467                         if [ -z "$1" ]; then
468                                 case $c in
469                                         DEBUG=*)
470                                                 [ -n "$DEBUG" ] && set_property debug.logcat 1
471                                                 ;;
472                                 esac
473                         fi
474                         ;;
475         esac
476 done
477
478 [ -n "$DEBUG" ] && set -x || exec &> /dev/null
479
480 # import the vendor specific script
481 hw_sh=/vendor/etc/init.sh
482 [ -e $hw_sh ] && source $hw_sh
483
484 case "$1" in
485         netconsole)
486                 [ -n "$DEBUG" ] && do_netconsole
487                 ;;
488         bootcomplete)
489                 do_bootcomplete
490                 ;;
491         init|"")
492                 do_init
493                 ;;
494 esac
495
496 return 0