OSDN Git Service

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