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