OSDN Git Service

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