OSDN Git Service

init.sh: set sensor hal to hdaps if lis3lv02d_i2c is loaded
[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
26 function init_hal_audio()
27 {
28         case "$PRODUCT" in
29                 VirtualBox*|Bochs*)
30                         [ -d /proc/asound/card0 ] || modprobe snd-sb16 isapnp=0 irq=5
31                         ;;
32                 *)
33                         ;;
34         esac
35 }
36
37 function init_hal_bluetooth()
38 {
39         for r in /sys/class/rfkill/*; do
40                 type=$(cat $r/type)
41                 [ "$type" = "wlan" -o "$type" = "bluetooth" ] && echo 1 > $r/state
42         done
43
44         case "$PRODUCT" in
45                 T10*TA|HP*Omni*)
46                         BTUART_PORT=/dev/ttyS1
47                         ;;
48                 MacBookPro8*)
49                         rmmod b43
50                         modprobe b43 btcoex=0
51                         modprobe btusb
52                         ;;
53                 # FIXME
54                 # Fix MacBook 2013-2015 (Air6/7&Pro11/12) BCM4360 ssb&wl conflict.
55                 MacBookPro11* | MacBookPro12* | MacBookAir6* | MacBookAir7*)
56                         rmmod b43
57                         rmmod ssb
58                         rmmod bcma
59                         rmmod wl
60                         modprobe wl
61                         modprobe btusb
62                         ;;
63                 *)
64                         for bt in $(lsusb -v | awk ' /Class:.E0/ { print $9 } '); do
65                                 chown 1002.1002 $bt && chmod 660 $bt
66                         done
67                         modprobe btusb
68                         ;;
69         esac
70
71         if [ -n "$BTUART_PORT" ]; then
72                 set_property hal.bluetooth.uart $BTUART_PORT
73                 chown bluetooth.bluetooth $BTUART_PORT
74                 start btattach:-B$BTUART_PORT
75                 log -t hciconfig -p i "`hciconfig`"
76         fi
77 }
78
79 function init_hal_camera()
80 {
81         return
82 }
83
84 function init_hal_gps()
85 {
86         # TODO
87         return
88 }
89
90 function set_drm_mode()
91 {
92         case "$PRODUCT" in
93                 ET1602*)
94                         drm_mode=1366x768
95                         ;;
96                 *)
97                         ;;
98         esac
99
100         [ -n "$drm_mode" ] && set_property debug.drm.mode.force $drm_mode
101 }
102
103 function init_uvesafb()
104 {
105         case "$PRODUCT" in
106                 *Q550)
107                         UVESA_MODE=${UVESA_MODE:-1280x800}
108                         ;;
109                 ET2002*)
110                         UVESA_MODE=${UVESA_MODE:-1600x900}
111                         ;;
112                 T91*)
113                         UVESA_MODE=${UVESA_MODE:-1024x600}
114                         ;;
115                 VirtualBox*|Bochs*)
116                         UVESA_MODE=${UVESA_MODE:-1024x768}
117                         ;;
118                 *)
119                         ;;
120         esac
121
122         [ "$HWACCEL" = "0" ] && bpp=16 || bpp=32
123         modprobe uvesafb mode_option=${UVESA_MODE:-800x600}-$bpp ${UVESA_OPTION:-mtrr=3 scroll=redraw}
124 }
125
126 function init_hal_gralloc()
127 {
128         case "$(cat /proc/fb | head -1)" in
129                 *virtiodrmfb)
130 #                       set_property ro.hardware.hwcomposer drm
131                         ;&
132                 0*inteldrmfb|0*radeondrmfb|0*nouveaufb|0*svgadrmfb)
133                         set_property ro.hardware.gralloc drm
134                         set_drm_mode
135                         ;;
136                 "")
137                         init_uvesafb
138                         ;&
139                 0*)
140                         # FIXME: software rendering failed to pass the SetupWizard
141                         set_property ro.setupwizard.mode DISABLED
142                         ;;
143         esac
144
145         [ -n "$DEBUG" ] && set_property debug.egl.trace error
146 }
147
148 function init_hal_hwcomposer()
149 {
150         # TODO
151         return
152 }
153
154 function init_hal_lights()
155 {
156         chown 1000.1000 /sys/class/backlight/*/brightness
157 }
158
159 function init_hal_power()
160 {
161         for p in /sys/class/rtc/*; do
162                 echo disabled > $p/device/power/wakeup
163         done
164
165         # TODO
166         case "$PRODUCT" in
167                 *)
168                         ;;
169         esac
170 }
171
172 function init_hal_sensors()
173 {
174         local hal_sensors=kbd
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                 *)
236                         ;;
237         esac
238
239         # has iio sensor-hub?
240         if [ -n "`ls /sys/bus/iio/devices/iio:device* 2> /dev/null`" ]; then
241                 busybox chown -R 1000.1000 /sys/bus/iio/devices/iio:device*/
242                 lsmod | grep -q hid_sensor_accel_3d && hal_sensors=hsb || hal_sensors=iio
243         elif lsmod | grep -q lis3lv02d_i2c; then
244                 hal_sensors=hdaps
245         fi
246
247         set_property ro.hardware.sensors $hal_sensors
248 }
249
250 function create_pointercal()
251 {
252         if [ ! -e /data/misc/tscal/pointercal ]; then
253                 mkdir -p /data/misc/tscal
254                 touch /data/misc/tscal/pointercal
255                 chown 1000.1000 /data/misc/tscal /data/misc/tscal/*
256                 chmod 775 /data/misc/tscal
257                 chmod 664 /data/misc/tscal/pointercal
258         fi
259 }
260
261 function init_tscal()
262 {
263         case "$PRODUCT" in
264                 ST70416-6*)
265                         modprobe gslx680_ts_acpi
266                         ;&
267                 T91|T101|ET2002|74499FU|945GSE-ITE8712|CF-19[CDYFGKLP]*)
268                         create_pointercal
269                         return
270                         ;;
271                 *)
272                         ;;
273         esac
274
275         for usbts in $(lsusb | awk '{ print $6 }'); do
276                 case "$usbts" in
277                         0596:0001|0eef:0001)
278                                 create_pointercal
279                                 return
280                                 ;;
281                         *)
282                                 ;;
283                 esac
284         done
285 }
286
287 function init_ril()
288 {
289         case "$(cat $DMIPATH/uevent)" in
290                 *TEGA*|*2010:svnIntel:*|*Lucid-MWE*)
291                         set_property rild.libpath /system/lib/libhuaweigeneric-ril.so
292                         set_property rild.libargs "-d /dev/ttyUSB2 -v /dev/ttyUSB1"
293                         ;;
294                 *)
295                         ;;
296         esac
297 }
298
299 function init_cpu_governor()
300 {
301         governor=$(getprop cpu.governor)
302
303         [ $governor ] && {
304                 for cpu in $(ls -d /sys/devices/system/cpu/cpu?); do
305                         echo $governor > $cpu/cpufreq/scaling_governor || return 1
306                 done
307         }
308 }
309
310 function do_init()
311 {
312         init_misc
313         init_hal_audio
314         init_hal_bluetooth
315         init_hal_camera
316         init_hal_gps
317         init_hal_gralloc
318         init_hal_hwcomposer
319         init_hal_lights
320         init_hal_power
321         init_hal_sensors
322         init_tscal
323         init_ril
324         post_init
325 }
326
327 function do_netconsole()
328 {
329         modprobe netconsole netconsole="@/,@$(getprop dhcp.eth0.gateway)/"
330 }
331
332 function do_bootcomplete()
333 {
334         init_cpu_governor
335
336         [ -z "$(getprop persist.sys.root_access)" ] && setprop persist.sys.root_access 3
337
338         # FIXME: autosleep works better on i965?
339         [ "$(getprop debug.mesa.driver)" = "i965" ] && setprop debug.autosleep 1
340
341         lsmod | grep -e brcmfmac && setprop wlan.no-unload-driver 1
342
343         case "$PRODUCT" in
344                 1866???|1867???|1869???) # ThinkPad X41 Tablet
345                         start tablet-mode
346                         start wacom-input
347                         setkeycodes 0x6d 115
348                         setkeycodes 0x6e 114
349                         setkeycodes 0x69 28
350                         setkeycodes 0x6b 158
351                         setkeycodes 0x68 172
352                         setkeycodes 0x6c 127
353                         setkeycodes 0x67 217
354                         ;;
355                 6363???|6364???|6366???) # ThinkPad X60 Tablet
356                         ;&
357                 7762???|7763???|7767???) # ThinkPad X61 Tablet
358                         start tablet-mode
359                         start wacom-input
360                         setkeycodes 0x6d 115
361                         setkeycodes 0x6e 114
362                         setkeycodes 0x69 28
363                         setkeycodes 0x6b 158
364                         setkeycodes 0x68 172
365                         setkeycodes 0x6c 127
366                         setkeycodes 0x67 217
367                         ;;
368                 7448???|7449???|7450???|7453???) # ThinkPad X200 Tablet
369                         start tablet-mode
370                         start wacom-input
371                         setkeycodes 0xe012 158
372                         setkeycodes 0x66 172
373                         setkeycodes 0x6b 127
374                         ;;
375                 *)
376                         ;;
377         esac
378
379 #       [ -d /proc/asound/card0 ] || modprobe snd-dummy
380         for c in $(grep '\[.*\]' /proc/asound/cards | awk '{print $1}'); do
381                 f=/system/etc/alsa/$(cat /proc/asound/card$c/id).state
382                 if [ -e $f ]; then
383                         alsa_ctl -f $f restore $c
384                 else
385                         alsa_ctl init $c
386                         alsa_amixer -c $c set Master on
387                         alsa_amixer -c $c set Master 100%
388                         alsa_amixer -c $c set Headphone on
389                         alsa_amixer -c $c set Headphone 100%
390                         alsa_amixer -c $c set Speaker 100%
391                         alsa_amixer -c $c set Capture 100%
392                         alsa_amixer -c $c set Capture cap
393                         alsa_amixer -c $c set PCM 100 unmute
394                         alsa_amixer -c $c set SPO unmute
395                         alsa_amixer -c $c set 'Mic Boost' 3
396                         alsa_amixer -c $c set 'Internal Mic Boost' 3
397                 fi
398         done
399 }
400
401 function do_hci()
402 {
403         local hci=`hciconfig | grep ^hci | cut -d: -f1`
404         local btd="`getprop init.svc.bluetoothd`"
405         log -t bluetoothd -p i "$btd ($hci)"
406         if [ -n "`getprop hal.bluetooth.uart`" ]; then
407                 [ "`getprop init.svc.bluetoothd`" = "running" ] && hciconfig $hci up
408         fi
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                 *.*=*)
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         hci)
452                 do_hci
453                 ;;
454         init|"")
455                 do_init
456                 ;;
457 esac
458
459 return 0