OSDN Git Service

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