OSDN Git Service

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