OSDN Git Service

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