OSDN Git Service

Add nouveau to blacklist
[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 rmmod_if_exist()
19 {
20         for m in $*; do
21                 [ -d /sys/module/$m ] && rmmod $m
22         done
23 }
24
25 function init_misc()
26 {
27         # device information
28         setprop ro.product.manufacturer "$(cat $DMIPATH/sys_vendor)"
29         setprop ro.product.model "$PRODUCT"
30
31         # a hack for USB modem
32         lsusb | grep 1a8d:1000 && eject
33
34         # in case no cpu governor driver autoloads
35         [ -d /sys/devices/system/cpu/cpu0/cpufreq ] || modprobe acpi-cpufreq
36
37         # enable sdcardfs if /data is not mounted on tmpfs or 9p
38         mount | grep /data\ | grep -qE 'tmpfs|9p'
39         [ $? -eq 0 ] && set_prop_if_empty ro.sys.sdcardfs false
40
41         # remove wl if it's not used
42         local wifi
43         if [ -d /sys/class/net/wlan0 ]; then
44                 wifi=$(basename `readlink /sys/class/net/wlan0/device/driver`)
45                 [ "$wifi" != "wl" ] && rmmod_if_exist wl
46         fi
47
48         # enable virt_wifi if needed
49         local eth=`getprop net.virt_wifi eth0`
50         if [ -d /sys/class/net/$eth -a "$VIRT_WIFI" != "0" ]; then
51                 if [ -n "$wifi" -a "$VIRT_WIFI" = "1" ]; then
52                         rmmod_if_exist iwlmvm $wifi
53                 fi
54                 if [ ! -d /sys/class/net/wlan0 ]; then
55                         ifconfig $eth down
56                         ip link set $eth name wifi_eth
57                         ifconfig wifi_eth up
58                         ip link add link wifi_eth name wlan0 type virt_wifi
59                 fi
60         fi
61 }
62
63 function init_hal_audio()
64 {
65         case "$PRODUCT" in
66                 VirtualBox*|Bochs*)
67                         [ -d /proc/asound/card0 ] || modprobe snd-sb16 isapnp=0 irq=5
68                         ;;
69                 *)
70                         ;;
71         esac
72
73         if grep -qi "IntelHDMI" /proc/asound/card0/id; then
74                 [ -d /proc/asound/card1 ] || set_property ro.hardware.audio.primary hdmi
75         fi
76 }
77
78 function init_hal_bluetooth()
79 {
80         for r in /sys/class/rfkill/*; do
81                 type=$(cat $r/type)
82                 [ "$type" = "wlan" -o "$type" = "bluetooth" ] && echo 1 > $r/state
83         done
84
85         case "$PRODUCT" in
86                 T100TAF)
87                         set_property bluetooth.interface hci1
88                         ;;
89                 T10*TA|M80TA|HP*Omni*)
90                         BTUART_PORT=/dev/ttyS1
91                         set_property hal.bluetooth.uart.proto bcm
92                         ;;
93                 MacBookPro8*)
94                         rmmod b43
95                         modprobe b43 btcoex=0
96                         modprobe btusb
97                         ;;
98                 # FIXME
99                 # Fix MacBook 2013-2015 (Air6/7&Pro11/12) BCM4360 ssb&wl conflict.
100                 MacBookPro11* | MacBookPro12* | MacBookAir6* | MacBookAir7*)
101                         rmmod b43
102                         rmmod ssb
103                         rmmod bcma
104                         rmmod wl
105                         modprobe wl
106                         modprobe btusb
107                         ;;
108                 *)
109                         for bt in $(busybox lsusb -v | awk ' /Class:.E0/ { print $9 } '); do
110                                 chown 1002.1002 $bt && chmod 660 $bt
111                         done
112                         ;;
113         esac
114
115         if [ -n "$BTUART_PORT" ]; then
116                 set_property hal.bluetooth.uart $BTUART_PORT
117                 chown bluetooth.bluetooth $BTUART_PORT
118                 start btattach
119         fi
120
121         # rtl8723bs bluetooth
122         if dmesg -t | grep -qE '8723bs.*BT'; then
123                 TTYSTRING=`dmesg -t | grep -E 'tty.*MMIO' | awk '{print $2}' | head -1`
124                 if [ -n "$TTYSTRING" ]; then
125                         echo "RTL8723BS BT uses $TTYSTRING for Bluetooth."
126                         ln -sf $TTYSTRING /dev/rtk_h5
127                         start rtk_hciattach
128                 fi
129         fi
130 }
131
132 function init_hal_camera()
133 {
134         case "$UEVENT" in
135                 *e-tabPro*)
136                         set_prop_if_empty hal.camera.0 0,270
137                         set_prop_if_empty hal.camera.2 1,90
138                         ;;
139                 *LenovoideapadD330*)
140                         set_prop_if_empty hal.camera.0 0,90
141                         set_prop_if_empty hal.camera.2 1,90
142                         ;;
143                 *)
144                         ;;
145         esac
146 }
147
148 function init_hal_gps()
149 {
150         # TODO
151         return
152 }
153
154 function set_drm_mode()
155 {
156         case "$PRODUCT" in
157                 ET1602*)
158                         drm_mode=1366x768
159                         ;;
160                 *)
161                         [ -n "$video" ] && drm_mode=$video
162                         ;;
163         esac
164
165         [ -n "$drm_mode" ] && set_property debug.drm.mode.force $drm_mode
166 }
167
168 function init_uvesafb()
169 {
170         UVESA_MODE=${UVESA_MODE:-${video%@*}}
171
172         case "$PRODUCT" in
173                 ET2002*)
174                         UVESA_MODE=${UVESA_MODE:-1600x900}
175                         ;;
176                 *)
177                         ;;
178         esac
179
180         modprobe uvesafb mode_option=${UVESA_MODE:-1024x768}-32 ${UVESA_OPTION:-mtrr=3 scroll=redraw}
181 }
182
183 function init_hal_gralloc()
184 {
185         case "$(cat /proc/fb | head -1)" in
186                 *virtiodrmfb)
187                         if [ "$HWACCEL" != "0" ]; then
188                                 set_property ro.hardware.hwcomposer drm
189                                 set_property ro.hardware.gralloc gbm
190                                 set_property debug.drm.mode.force ${video:-1280x800}
191                         fi
192                         set_prop_if_empty sleep.state none
193                         ;;
194                 0*inteldrmfb|0*radeondrmfb|0*nouveaufb|0*svgadrmfb|0*amdgpudrmfb)
195                         if [ "$HWACCEL" != "0" ]; then
196                                 set_property ro.hardware.gralloc drm
197                                 set_drm_mode
198                         fi
199                         ;;
200                 "")
201                         init_uvesafb
202                         ;&
203                 0*)
204                         ;;
205         esac
206
207         [ -n "$DEBUG" ] && set_property debug.egl.trace error
208 }
209
210 function init_hal_hwcomposer()
211 {
212         # TODO
213         return
214 }
215
216 function init_hal_lights()
217 {
218         chown 1000.1000 /sys/class/backlight/*/brightness
219 }
220
221 function init_hal_power()
222 {
223         for p in /sys/class/rtc/*; do
224                 echo disabled > $p/device/power/wakeup
225         done
226
227         # TODO
228         case "$PRODUCT" in
229                 HP*Omni*|OEMB|Surface*3|T10*TA)
230                         set_prop_if_empty sleep.state none
231                         ;;
232                 e-tab*Pro)
233                         set_prop_if_empty sleep.state force
234                         ;;
235                 *)
236                         ;;
237         esac
238 }
239
240 function init_hal_sensors()
241 {
242         # if we have sensor module for our hardware, use it
243         ro_hardware=$(getprop ro.hardware)
244         [ -f /system/lib/hw/sensors.${ro_hardware}.so ] && return 0
245
246         local hal_sensors=kbd
247         local has_sensors=true
248         case "$UEVENT" in
249                 *Lucid-MWE*)
250                         set_property ro.ignore_atkbd 1
251                         hal_sensors=hdaps
252                         ;;
253                 *ICONIA*W5*)
254                         hal_sensors=w500
255                         ;;
256                 *S10-3t*)
257                         hal_sensors=s103t
258                         ;;
259                 *Inagua*)
260                         #setkeycodes 0x62 29
261                         #setkeycodes 0x74 56
262                         set_property ro.ignore_atkbd 1
263                         set_property hal.sensors.kbd.type 2
264                         ;;
265                 *TEGA*|*2010:svnIntel:*)
266                         set_property ro.ignore_atkbd 1
267                         set_property hal.sensors.kbd.type 1
268                         io_switch 0x0 0x1
269                         setkeycodes 0x6d 125
270                         ;;
271                 *DLI*)
272                         set_property ro.ignore_atkbd 1
273                         set_property hal.sensors.kbd.type 1
274                         setkeycodes 0x64 1
275                         setkeycodes 0x65 172
276                         setkeycodes 0x66 120
277                         setkeycodes 0x67 116
278                         setkeycodes 0x68 114
279                         setkeycodes 0x69 115
280                         setkeycodes 0x6c 114
281                         setkeycodes 0x6d 115
282                         ;;
283                 *tx2*)
284                         setkeycodes 0xb1 138
285                         setkeycodes 0x8a 152
286                         set_property hal.sensors.kbd.type 6
287                         set_property poweroff.doubleclick 0
288                         set_property qemu.hw.mainkeys 1
289                         ;;
290                 *MS-N0E1*)
291                         set_property ro.ignore_atkbd 1
292                         set_property poweroff.doubleclick 0
293                         setkeycodes 0xa5 125
294                         setkeycodes 0xa7 1
295                         setkeycodes 0xe3 142
296                         ;;
297                 *Aspire1*25*)
298                         modprobe lis3lv02d_i2c
299                         echo -n "enabled" > /sys/class/thermal/thermal_zone0/mode
300                         ;;
301                 *ThinkPad*Tablet*)
302                         modprobe hdaps
303                         hal_sensors=hdaps
304                         ;;
305                 *LenovoideapadD330*)
306                         set_property ro.iio.accel.quirks no-trig
307                         set_property ro.iio.accel.order 102
308                         ;&
309                 *LINX1010B*)
310                         set_property ro.iio.accel.x.opt_scale -1
311                         set_property ro.iio.accel.z.opt_scale -1
312                         ;;
313                 *i7-WN*)
314                         set_property ro.iio.accel.quirks no-trig
315                         ;&
316                 *i7Stylus*)
317                         set_property ro.iio.accel.x.opt_scale -1
318                         ;;
319                 *LenovoMIIX320*|*ONDATablet*)
320                         set_property ro.iio.accel.order 102
321                         set_property ro.iio.accel.x.opt_scale -1
322                         set_property ro.iio.accel.y.opt_scale -1
323                         ;;
324                 *SP111-33*)
325                         set_property ro.iio.accel.quirks no-trig
326                         ;&
327                 *ST70416-6*)
328                         set_property ro.iio.accel.order 102
329                         ;;
330                 *e-tabPro*|*pnEZpad*|*TECLAST:rntPAD*)
331                         set_property ro.iio.accel.quirks no-trig
332                         ;&
333                 *T*0*TA*|*M80TA*)
334                         set_property ro.iio.accel.y.opt_scale -1
335                         ;;
336                 *)
337                         has_sensors=false
338                         ;;
339         esac
340
341         # has iio sensor-hub?
342         if [ -n "`ls /sys/bus/iio/devices/iio:device* 2> /dev/null`" ]; then
343                 busybox chown -R 1000.1000 /sys/bus/iio/devices/iio:device*/
344                 [ -n "`ls /sys/bus/iio/devices/iio:device*/in_accel_x_raw 2> /dev/null`" ] && has_sensors=true
345                 hal_sensors=iio
346         elif lsmod | grep -q lis3lv02d_i2c; then
347                 hal_sensors=hdaps
348                 has_sensors=true
349         elif [ "$hal_sensors" != "kbd" ]; then
350                 has_sensors=true
351         fi
352
353         set_property ro.hardware.sensors $hal_sensors
354         set_property config.override_forced_orient ${HAS_SENSORS:-$has_sensors}
355 }
356
357 function create_pointercal()
358 {
359         if [ ! -e /data/misc/tscal/pointercal ]; then
360                 mkdir -p /data/misc/tscal
361                 touch /data/misc/tscal/pointercal
362                 chown 1000.1000 /data/misc/tscal /data/misc/tscal/*
363                 chmod 775 /data/misc/tscal
364                 chmod 664 /data/misc/tscal/pointercal
365         fi
366 }
367
368 function init_tscal()
369 {
370         case "$UEVENT" in
371                 *ST70416-6*)
372                         modprobe gslx680_ts_acpi
373                         ;&
374                 *T91*|*T101*|*ET2002*|*74499FU*|*945GSE-ITE8712*|*CF-19[CDYFGKLP]*|*TECLAST:rntPAD*)
375                         create_pointercal
376                         return
377                         ;;
378                 *)
379                         ;;
380         esac
381
382         for usbts in $(lsusb | awk '{ print $6 }'); do
383                 case "$usbts" in
384                         0596:0001|0eef:0001)
385                                 create_pointercal
386                                 return
387                                 ;;
388                         *)
389                                 ;;
390                 esac
391         done
392 }
393
394 function init_ril()
395 {
396         case "$UEVENT" in
397                 *TEGA*|*2010:svnIntel:*|*Lucid-MWE*)
398                         set_property rild.libpath /system/lib/libhuaweigeneric-ril.so
399                         set_property rild.libargs "-d /dev/ttyUSB2 -v /dev/ttyUSB1"
400                         set_property ro.radio.noril no
401                         ;;
402                 *)
403                         set_property ro.radio.noril yes
404                         ;;
405         esac
406 }
407
408 function init_cpu_governor()
409 {
410         governor=$(getprop cpu.governor)
411
412         [ $governor ] && {
413                 for cpu in $(ls -d /sys/devices/system/cpu/cpu?); do
414                         echo $governor > $cpu/cpufreq/scaling_governor || return 1
415                 done
416         }
417 }
418
419 function do_init()
420 {
421         init_misc
422         init_hal_audio
423         init_hal_bluetooth
424         init_hal_camera
425         init_hal_gps
426         init_hal_gralloc
427         init_hal_hwcomposer
428         init_hal_lights
429         init_hal_power
430         init_hal_sensors
431         init_tscal
432         init_ril
433         post_init
434 }
435
436 function do_netconsole()
437 {
438         modprobe netconsole netconsole="@/,@$(getprop dhcp.eth0.gateway)/"
439 }
440
441 function do_bootcomplete()
442 {
443         hciconfig | grep -q hci || pm disable com.android.bluetooth
444
445         init_cpu_governor
446
447         [ -z "$(getprop persist.sys.root_access)" ] && setprop persist.sys.root_access 3
448
449         lsmod | grep -Ehq "brcmfmac|rtl8723be" && setprop wlan.no-unload-driver 1
450
451         case "$PRODUCT" in
452                 1866???|1867???|1869???) # ThinkPad X41 Tablet
453                         start tablet-mode
454                         start wacom-input
455                         setkeycodes 0x6d 115
456                         setkeycodes 0x6e 114
457                         setkeycodes 0x69 28
458                         setkeycodes 0x6b 158
459                         setkeycodes 0x68 172
460                         setkeycodes 0x6c 127
461                         setkeycodes 0x67 217
462                         ;;
463                 6363???|6364???|6366???) # ThinkPad X60 Tablet
464                         ;&
465                 7762???|7763???|7767???) # ThinkPad X61 Tablet
466                         start tablet-mode
467                         start wacom-input
468                         setkeycodes 0x6d 115
469                         setkeycodes 0x6e 114
470                         setkeycodes 0x69 28
471                         setkeycodes 0x6b 158
472                         setkeycodes 0x68 172
473                         setkeycodes 0x6c 127
474                         setkeycodes 0x67 217
475                         ;;
476                 7448???|7449???|7450???|7453???) # ThinkPad X200 Tablet
477                         start tablet-mode
478                         start wacom-input
479                         setkeycodes 0xe012 158
480                         setkeycodes 0x66 172
481                         setkeycodes 0x6b 127
482                         ;;
483                 Surface*Go)
484                         echo on > /sys/devices/pci0000:00/0000:00:15.1/i2c_designware.1/power/control
485                         ;;
486                 X80*Power)
487                         set_property power.nonboot-cpu-off 1
488                         ;;
489                 *)
490                         ;;
491         esac
492
493 #       [ -d /proc/asound/card0 ] || modprobe snd-dummy
494         for c in $(grep '\[.*\]' /proc/asound/cards | awk '{print $1}'); do
495                 f=/system/etc/alsa/$(cat /proc/asound/card$c/id).state
496                 if [ -e $f ]; then
497                         alsa_ctl -f $f restore $c
498                 else
499                         alsa_ctl init $c
500                         alsa_amixer -c $c set Master on
501                         alsa_amixer -c $c set Master 100%
502                         alsa_amixer -c $c set Headphone on
503                         alsa_amixer -c $c set Headphone 100%
504                         alsa_amixer -c $c set Speaker 100%
505                         alsa_amixer -c $c set Capture 80%
506                         alsa_amixer -c $c set Capture cap
507                         alsa_amixer -c $c set PCM 100% unmute
508                         alsa_amixer -c $c set SPO unmute
509                         alsa_amixer -c $c set IEC958 on
510                         alsa_amixer -c $c set 'Mic Boost' 1
511                         alsa_amixer -c $c set 'Internal Mic Boost' 1
512                 fi
513         done
514
515         post_bootcomplete
516 }
517
518 PATH=/sbin:/system/bin:/system/xbin
519
520 DMIPATH=/sys/class/dmi/id
521 BOARD=$(cat $DMIPATH/board_name)
522 PRODUCT=$(cat $DMIPATH/product_name)
523 UEVENT=$(cat $DMIPATH/uevent)
524
525 # import cmdline variables
526 for c in `cat /proc/cmdline`; do
527         case $c in
528                 BOOT_IMAGE=*|iso-scan/*|*.*=*)
529                         ;;
530                 *=*)
531                         eval $c
532                         if [ -z "$1" ]; then
533                                 case $c in
534                                         DEBUG=*)
535                                                 [ -n "$DEBUG" ] && set_property debug.logcat 1
536                                                 ;;
537                                 esac
538                         fi
539                         ;;
540         esac
541 done
542
543 [ -n "$DEBUG" ] && set -x || exec &> /dev/null
544
545 # import the vendor specific script
546 hw_sh=/vendor/etc/init.sh
547 [ -e $hw_sh ] && source $hw_sh
548
549 case "$1" in
550         netconsole)
551                 [ -n "$DEBUG" ] && do_netconsole
552                 ;;
553         bootcomplete)
554                 do_bootcomplete
555                 ;;
556         init|"")
557                 do_init
558                 ;;
559 esac
560
561 return 0