OSDN Git Service

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