OSDN Git Service

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