OSDN Git Service

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