OSDN Git Service

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