OSDN Git Service

init.sh: refine the rule of has_sensors
[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 ro.iio.accel.y.opt_scale -1
253                         set_property ro.iio.accel.z.opt_scale -1
254                         ;;
255                 *ONDATablet*)
256                         set_property ro.iio.accel.order 102
257                         ;;
258                 *ST70416-6*)
259                         set_property ro.iio.accel.order 102
260                         ;&
261                 *Surface.3*|*svnOEMB*|*T305CA*)
262                         set_property ro.iio.accel.y.opt_scale -1
263                         ;&
264                 *T10*TA*)
265                         set_property ro.iio.accel.x.opt_scale -1
266                         set_property ro.iio.accel.z.opt_scale -1
267                         ;;
268                 *)
269                         has_sensors=false
270                         ;;
271         esac
272
273         # has iio sensor-hub?
274         if [ -n "`ls /sys/bus/iio/devices/iio:device* 2> /dev/null`" ]; then
275                 busybox chown -R 1000.1000 /sys/bus/iio/devices/iio:device*/
276                 [ -n "`ls /sys/bus/iio/devices/iio:device*/in_accel_x_raw 2> /dev/null`" ] && has_sensors=true
277                 hal_sensors=iio
278         elif lsmod | grep -q lis3lv02d_i2c; then
279                 hal_sensors=hdaps
280                 has_sensors=true
281         elif [ "$hal_sensors" != "kbd" ]; then
282                 has_sensors=${HAS_SENSORS:-true}
283         fi
284
285         set_property ro.hardware.sensors $hal_sensors
286         set_property config.override_forced_orient $has_sensors
287 }
288
289 function create_pointercal()
290 {
291         if [ ! -e /data/misc/tscal/pointercal ]; then
292                 mkdir -p /data/misc/tscal
293                 touch /data/misc/tscal/pointercal
294                 chown 1000.1000 /data/misc/tscal /data/misc/tscal/*
295                 chmod 775 /data/misc/tscal
296                 chmod 664 /data/misc/tscal/pointercal
297         fi
298 }
299
300 function init_tscal()
301 {
302         case "$PRODUCT" in
303                 ST70416-6*)
304                         modprobe gslx680_ts_acpi
305                         ;&
306                 T91|T101|ET2002|74499FU|945GSE-ITE8712|CF-19[CDYFGKLP]*)
307                         create_pointercal
308                         return
309                         ;;
310                 *)
311                         ;;
312         esac
313
314         for usbts in $(lsusb | awk '{ print $6 }'); do
315                 case "$usbts" in
316                         0596:0001|0eef:0001)
317                                 create_pointercal
318                                 return
319                                 ;;
320                         *)
321                                 ;;
322                 esac
323         done
324 }
325
326 function init_ril()
327 {
328         case "$(cat $DMIPATH/uevent)" in
329                 *TEGA*|*2010:svnIntel:*|*Lucid-MWE*)
330                         set_property rild.libpath /system/lib/libhuaweigeneric-ril.so
331                         set_property rild.libargs "-d /dev/ttyUSB2 -v /dev/ttyUSB1"
332                         set_property ro.radio.noril no
333                         ;;
334                 *)
335                         set_property ro.radio.noril yes
336                         ;;
337         esac
338 }
339
340 function init_cpu_governor()
341 {
342         governor=$(getprop cpu.governor)
343
344         [ $governor ] && {
345                 for cpu in $(ls -d /sys/devices/system/cpu/cpu?); do
346                         echo $governor > $cpu/cpufreq/scaling_governor || return 1
347                 done
348         }
349 }
350
351 function do_init()
352 {
353         init_misc
354         init_hal_audio
355         init_hal_bluetooth
356         init_hal_camera
357         init_hal_gps
358         init_hal_gralloc
359         init_hal_hwcomposer
360         init_hal_lights
361         init_hal_power
362         init_hal_sensors
363         init_tscal
364         init_ril
365         post_init
366 }
367
368 function do_netconsole()
369 {
370         modprobe netconsole netconsole="@/,@$(getprop dhcp.eth0.gateway)/"
371 }
372
373 function do_bootcomplete()
374 {
375         init_cpu_governor
376
377         [ -z "$(getprop persist.sys.root_access)" ] && setprop persist.sys.root_access 3
378
379         lsmod | grep -Ehq "brcmfmac|rtl8723be" && setprop wlan.no-unload-driver 1
380
381         case "$PRODUCT" in
382                 1866???|1867???|1869???) # ThinkPad X41 Tablet
383                         start tablet-mode
384                         start wacom-input
385                         setkeycodes 0x6d 115
386                         setkeycodes 0x6e 114
387                         setkeycodes 0x69 28
388                         setkeycodes 0x6b 158
389                         setkeycodes 0x68 172
390                         setkeycodes 0x6c 127
391                         setkeycodes 0x67 217
392                         ;;
393                 6363???|6364???|6366???) # ThinkPad X60 Tablet
394                         ;&
395                 7762???|7763???|7767???) # ThinkPad X61 Tablet
396                         start tablet-mode
397                         start wacom-input
398                         setkeycodes 0x6d 115
399                         setkeycodes 0x6e 114
400                         setkeycodes 0x69 28
401                         setkeycodes 0x6b 158
402                         setkeycodes 0x68 172
403                         setkeycodes 0x6c 127
404                         setkeycodes 0x67 217
405                         ;;
406                 7448???|7449???|7450???|7453???) # ThinkPad X200 Tablet
407                         start tablet-mode
408                         start wacom-input
409                         setkeycodes 0xe012 158
410                         setkeycodes 0x66 172
411                         setkeycodes 0x6b 127
412                         ;;
413                 *)
414                         ;;
415         esac
416
417 #       [ -d /proc/asound/card0 ] || modprobe snd-dummy
418         for c in $(grep '\[.*\]' /proc/asound/cards | awk '{print $1}'); do
419                 f=/system/etc/alsa/$(cat /proc/asound/card$c/id).state
420                 if [ -e $f ]; then
421                         alsa_ctl -f $f restore $c
422                 else
423                         alsa_ctl init $c
424                         alsa_amixer -c $c set Master on
425                         alsa_amixer -c $c set Master 100%
426                         alsa_amixer -c $c set Headphone on
427                         alsa_amixer -c $c set Headphone 100%
428                         alsa_amixer -c $c set Speaker 100%
429                         alsa_amixer -c $c set Capture 100%
430                         alsa_amixer -c $c set Capture cap
431                         alsa_amixer -c $c set PCM 100 unmute
432                         alsa_amixer -c $c set SPO unmute
433                         alsa_amixer -c $c set IEC958 on
434                         alsa_amixer -c $c set 'Mic Boost' 3
435                         alsa_amixer -c $c set 'Internal Mic Boost' 3
436                 fi
437         done
438
439         post_bootcomplete
440 }
441
442 PATH=/sbin:/system/bin:/system/xbin
443
444 DMIPATH=/sys/class/dmi/id
445 BOARD=$(cat $DMIPATH/board_name)
446 PRODUCT=$(cat $DMIPATH/product_name)
447
448 # import cmdline variables
449 for c in `cat /proc/cmdline`; do
450         case $c in
451                 BOOT_IMAGE=*|iso-scan/*|*.*=*)
452                         ;;
453                 *=*)
454                         eval $c
455                         if [ -z "$1" ]; then
456                                 case $c in
457                                         DEBUG=*)
458                                                 [ -n "$DEBUG" ] && set_property debug.logcat 1
459                                                 ;;
460                                 esac
461                         fi
462                         ;;
463         esac
464 done
465
466 [ -n "$DEBUG" ] && set -x || exec &> /dev/null
467
468 # import the vendor specific script
469 hw_sh=/vendor/etc/init.sh
470 [ -e $hw_sh ] && source $hw_sh
471
472 case "$1" in
473         netconsole)
474                 [ -n "$DEBUG" ] && do_netconsole
475                 ;;
476         bootcomplete)
477                 do_bootcomplete
478                 ;;
479         init|"")
480                 do_init
481                 ;;
482 esac
483
484 return 0