OSDN Git Service

init.sh: honor sensors.${ro_hardware}.so first
[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         # if we have sensor module for our hardware, use it
175         ro_hardware=$(getprop ro.hardware)
176         [ -f /system/lib/hw/sensors.${ro_hardware}.so ] && return 0
177
178         local hal_sensors=kbd
179         case "$(cat $DMIPATH/uevent)" in
180                 *Lucid-MWE*)
181                         set_property ro.ignore_atkbd 1
182                         hal_sensors=hdaps
183                         ;;
184                 *ICONIA*W5*)
185                         hal_sensors=w500
186                         ;;
187                 *S10-3t*)
188                         hal_sensors=s103t
189                         ;;
190                 *Inagua*)
191                         #setkeycodes 0x62 29
192                         #setkeycodes 0x74 56
193                         set_property ro.ignore_atkbd 1
194                         set_property hal.sensors.kbd.type 2
195                         ;;
196                 *TEGA*|*2010:svnIntel:*)
197                         set_property ro.ignore_atkbd 1
198                         set_property hal.sensors.kbd.type 1
199                         io_switch 0x0 0x1
200                         setkeycodes 0x6d 125
201                         ;;
202                 *DLI*)
203                         set_property ro.ignore_atkbd 1
204                         set_property hal.sensors.kbd.type 1
205                         setkeycodes 0x64 1
206                         setkeycodes 0x65 172
207                         setkeycodes 0x66 120
208                         setkeycodes 0x67 116
209                         setkeycodes 0x68 114
210                         setkeycodes 0x69 115
211                         setkeycodes 0x6c 114
212                         setkeycodes 0x6d 115
213                         ;;
214                 *tx2*)
215                         setkeycodes 0xb1 138
216                         setkeycodes 0x8a 152
217                         set_property hal.sensors.kbd.type 6
218                         set_property poweroff.doubleclick 0
219                         set_property qemu.hw.mainkeys 1
220                         ;;
221                 *MS-N0E1*)
222                         set_property ro.ignore_atkbd 1
223                         set_property poweroff.doubleclick 0
224                         setkeycodes 0xa5 125
225                         setkeycodes 0xa7 1
226                         setkeycodes 0xe3 142
227                         ;;
228                 *Aspire1*25*)
229                         modprobe lis3lv02d_i2c
230                         echo -n "enabled" > /sys/class/thermal/thermal_zone0/mode
231                         ;;
232                 *ThinkPad*Tablet*)
233                         modprobe hdaps
234                         hal_sensors=hdaps
235                         ;;
236                 *i7Stylus*)
237                         set_property hal.sensors.iio.accel.matrix 1,0,0,0,-1,0,0,0,-1
238                         ;;
239                 *)
240                         ;;
241         esac
242
243         # has iio sensor-hub?
244         if [ -n "`ls /sys/bus/iio/devices/iio:device* 2> /dev/null`" ]; then
245                 busybox chown -R 1000.1000 /sys/bus/iio/devices/iio:device*/
246                 lsmod | grep -q hid_sensor_accel_3d && hal_sensors=hsb || hal_sensors=iio
247         elif lsmod | grep -q lis3lv02d_i2c; then
248                 hal_sensors=hdaps
249         fi
250
251         set_property ro.hardware.sensors $hal_sensors
252 }
253
254 function create_pointercal()
255 {
256         if [ ! -e /data/misc/tscal/pointercal ]; then
257                 mkdir -p /data/misc/tscal
258                 touch /data/misc/tscal/pointercal
259                 chown 1000.1000 /data/misc/tscal /data/misc/tscal/*
260                 chmod 775 /data/misc/tscal
261                 chmod 664 /data/misc/tscal/pointercal
262         fi
263 }
264
265 function init_tscal()
266 {
267         case "$PRODUCT" in
268                 ST70416-6*)
269                         modprobe gslx680_ts_acpi
270                         ;&
271                 T91|T101|ET2002|74499FU|945GSE-ITE8712|CF-19[CDYFGKLP]*)
272                         create_pointercal
273                         return
274                         ;;
275                 *)
276                         ;;
277         esac
278
279         for usbts in $(lsusb | awk '{ print $6 }'); do
280                 case "$usbts" in
281                         0596:0001|0eef:0001)
282                                 create_pointercal
283                                 return
284                                 ;;
285                         *)
286                                 ;;
287                 esac
288         done
289 }
290
291 function init_ril()
292 {
293         case "$(cat $DMIPATH/uevent)" in
294                 *TEGA*|*2010:svnIntel:*|*Lucid-MWE*)
295                         set_property rild.libpath /system/lib/libhuaweigeneric-ril.so
296                         set_property rild.libargs "-d /dev/ttyUSB2 -v /dev/ttyUSB1"
297                         ;;
298                 *)
299                         ;;
300         esac
301 }
302
303 function init_cpu_governor()
304 {
305         governor=$(getprop cpu.governor)
306
307         [ $governor ] && {
308                 for cpu in $(ls -d /sys/devices/system/cpu/cpu?); do
309                         echo $governor > $cpu/cpufreq/scaling_governor || return 1
310                 done
311         }
312 }
313
314 function do_init()
315 {
316         init_misc
317         init_hal_audio
318         init_hal_bluetooth
319         init_hal_camera
320         init_hal_gps
321         init_hal_gralloc
322         init_hal_hwcomposer
323         init_hal_lights
324         init_hal_power
325         init_hal_sensors
326         init_tscal
327         init_ril
328         post_init
329 }
330
331 function do_netconsole()
332 {
333         modprobe netconsole netconsole="@/,@$(getprop dhcp.eth0.gateway)/"
334 }
335
336 function do_bootcomplete()
337 {
338         init_cpu_governor
339
340         [ -z "$(getprop persist.sys.root_access)" ] && setprop persist.sys.root_access 3
341
342         # FIXME: autosleep works better on i965?
343         [ "$(getprop debug.mesa.driver)" = "i965" ] && setprop debug.autosleep 1
344
345         lsmod | grep -e brcmfmac && setprop wlan.no-unload-driver 1
346
347         case "$PRODUCT" in
348                 1866???|1867???|1869???) # ThinkPad X41 Tablet
349                         start tablet-mode
350                         start wacom-input
351                         setkeycodes 0x6d 115
352                         setkeycodes 0x6e 114
353                         setkeycodes 0x69 28
354                         setkeycodes 0x6b 158
355                         setkeycodes 0x68 172
356                         setkeycodes 0x6c 127
357                         setkeycodes 0x67 217
358                         ;;
359                 6363???|6364???|6366???) # ThinkPad X60 Tablet
360                         ;&
361                 7762???|7763???|7767???) # ThinkPad X61 Tablet
362                         start tablet-mode
363                         start wacom-input
364                         setkeycodes 0x6d 115
365                         setkeycodes 0x6e 114
366                         setkeycodes 0x69 28
367                         setkeycodes 0x6b 158
368                         setkeycodes 0x68 172
369                         setkeycodes 0x6c 127
370                         setkeycodes 0x67 217
371                         ;;
372                 7448???|7449???|7450???|7453???) # ThinkPad X200 Tablet
373                         start tablet-mode
374                         start wacom-input
375                         setkeycodes 0xe012 158
376                         setkeycodes 0x66 172
377                         setkeycodes 0x6b 127
378                         ;;
379                 *)
380                         ;;
381         esac
382
383 #       [ -d /proc/asound/card0 ] || modprobe snd-dummy
384         for c in $(grep '\[.*\]' /proc/asound/cards | awk '{print $1}'); do
385                 f=/system/etc/alsa/$(cat /proc/asound/card$c/id).state
386                 if [ -e $f ]; then
387                         alsa_ctl -f $f restore $c
388                 else
389                         alsa_ctl init $c
390                         alsa_amixer -c $c set Master on
391                         alsa_amixer -c $c set Master 100%
392                         alsa_amixer -c $c set Headphone on
393                         alsa_amixer -c $c set Headphone 100%
394                         alsa_amixer -c $c set Speaker 100%
395                         alsa_amixer -c $c set Capture 100%
396                         alsa_amixer -c $c set Capture cap
397                         alsa_amixer -c $c set PCM 100 unmute
398                         alsa_amixer -c $c set SPO unmute
399                         alsa_amixer -c $c set 'Mic Boost' 3
400                         alsa_amixer -c $c set 'Internal Mic Boost' 3
401                 fi
402         done
403 }
404
405 function do_hci()
406 {
407         local hci=`hciconfig | grep ^hci | cut -d: -f1`
408         local btd="`getprop init.svc.bluetoothd`"
409         log -t bluetoothd -p i "$btd ($hci)"
410         if [ -n "`getprop hal.bluetooth.uart`" ]; then
411                 [ "`getprop init.svc.bluetoothd`" = "running" ] && hciconfig $hci up
412         fi
413 }
414
415 PATH=/sbin:/system/bin:/system/xbin
416
417 DMIPATH=/sys/class/dmi/id
418 BOARD=$(cat $DMIPATH/board_name)
419 PRODUCT=$(cat $DMIPATH/product_name)
420
421 # import cmdline variables
422 for c in `cat /proc/cmdline`; do
423         case $c in
424                 *.*=*)
425                         ;;
426                 *=*)
427                         eval $c
428                         if [ -z "$1" ]; then
429                                 case $c in
430                                         HWACCEL=*)
431                                                 set_property debug.egl.hw $HWACCEL
432                                                 ;;
433                                         DEBUG=*)
434                                                 [ -n "$DEBUG" ] && set_property debug.logcat 1
435                                                 ;;
436                                 esac
437                         fi
438                         ;;
439         esac
440 done
441
442 [ -n "$DEBUG" ] && set -x || exec &> /dev/null
443
444 # import the vendor specific script
445 hw_sh=/vendor/etc/init.sh
446 [ -e $hw_sh ] && source $hw_sh
447
448 case "$1" in
449         netconsole)
450                 [ -n "$DEBUG" ] && do_netconsole
451                 ;;
452         bootcomplete)
453                 do_bootcomplete
454                 ;;
455         hci)
456                 do_hci
457                 ;;
458         init|"")
459                 do_init
460                 ;;
461 esac
462
463 return 0