OSDN Git Service

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