OSDN Git Service

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