OSDN Git Service

Add support for GSL1680 I2C touchscreen on ST70416-6
[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                 ST70416-6*)
247                         modprobe gslx680_ts_acpi
248                         ;&
249                 T91|T101|ET2002|74499FU|945GSE-ITE8712|CF-19[CDYFGKLP]*)
250                         create_pointercal
251                         return
252                         ;;
253                 *)
254                         ;;
255         esac
256
257         for usbts in $(lsusb | awk '{ print $6 }'); do
258                 case "$usbts" in
259                         0596:0001|0eef:0001)
260                                 create_pointercal
261                                 return
262                                 ;;
263                         *)
264                                 ;;
265                 esac
266         done
267 }
268
269 function init_ril()
270 {
271         case "$(cat $DMIPATH/uevent)" in
272                 *TEGA*|*2010:svnIntel:*|*Lucid-MWE*)
273                         set_property rild.libpath /system/lib/libhuaweigeneric-ril.so
274                         set_property rild.libargs "-d /dev/ttyUSB2 -v /dev/ttyUSB1"
275                         ;;
276                 *)
277                         ;;
278         esac
279 }
280
281 function init_cpu_governor()
282 {
283         governor=$(getprop cpu.governor)
284
285         [ $governor ] && {
286                 for cpu in $(ls -d /sys/devices/system/cpu/cpu?); do
287                         echo $governor > $cpu/cpufreq/scaling_governor || return 1
288                 done
289         }
290 }
291
292 function do_init()
293 {
294         init_misc
295         init_hal_audio
296         init_hal_bluetooth
297         init_hal_camera
298         init_hal_gps
299         init_hal_gralloc
300         init_hal_hwcomposer
301         init_hal_lights
302         init_hal_power
303         init_hal_sensors
304         init_tscal
305         init_ril
306         chmod 640 /x86.prop
307         post_init
308 }
309
310 function do_netconsole()
311 {
312         modprobe netconsole netconsole="@/,@$(getprop dhcp.eth0.gateway)/"
313 }
314
315 function do_bootcomplete()
316 {
317         init_cpu_governor
318
319         [ -z "$(getprop persist.sys.root_access)" ] && setprop persist.sys.root_access 3
320
321         # FIXME: autosleep works better on i965?
322         [ "$(getprop debug.mesa.driver)" = "i965" ] && setprop debug.autosleep 1
323
324         lsmod | grep -e brcmfmac && setprop wlan.no-unload-driver 1
325
326         case "$PRODUCT" in
327                 1866???|1867???|1869???) # ThinkPad X41 Tablet
328                         start tablet-mode
329                         start wacom-input
330                         setkeycodes 0x6d 115
331                         setkeycodes 0x6e 114
332                         setkeycodes 0x69 28
333                         setkeycodes 0x6b 158
334                         setkeycodes 0x68 172
335                         setkeycodes 0x6c 127
336                         setkeycodes 0x67 217
337                         ;;
338                 6363???|6364???|6366???) # ThinkPad X60 Tablet
339                         ;&
340                 7762???|7763???|7767???) # ThinkPad X61 Tablet
341                         start tablet-mode
342                         start wacom-input
343                         setkeycodes 0x6d 115
344                         setkeycodes 0x6e 114
345                         setkeycodes 0x69 28
346                         setkeycodes 0x6b 158
347                         setkeycodes 0x68 172
348                         setkeycodes 0x6c 127
349                         setkeycodes 0x67 217
350                         ;;
351                 7448???|7449???|7450???|7453???) # ThinkPad X200 Tablet
352                         start tablet-mode
353                         start wacom-input
354                         setkeycodes 0xe012 158
355                         setkeycodes 0x66 172
356                         setkeycodes 0x6b 127
357                         ;;
358                 *)
359                         ;;
360         esac
361
362 #       [ -d /proc/asound/card0 ] || modprobe snd-dummy
363         for c in $(grep '\[.*\]' /proc/asound/cards | awk '{print $1}'); do
364                 f=/system/etc/alsa/$(cat /proc/asound/card$c/id).state
365                 if [ -e $f ]; then
366                         alsa_ctl -f $f restore $c
367                 else
368                         alsa_ctl init $c
369                         alsa_amixer -c $c set Master on
370                         alsa_amixer -c $c set Master 100%
371                         alsa_amixer -c $c set Headphone on
372                         alsa_amixer -c $c set Headphone 100%
373                         alsa_amixer -c $c set Speaker 100%
374                         alsa_amixer -c $c set Capture 100%
375                         alsa_amixer -c $c set Capture cap
376                         alsa_amixer -c $c set PCM 100 unmute
377                         alsa_amixer -c $c set SPO unmute
378                         alsa_amixer -c $c set 'Mic Boost' 3
379                         alsa_amixer -c $c set 'Internal Mic Boost' 3
380                 fi
381         done
382 }
383
384 function do_hci()
385 {
386         local hci=`hciconfig | grep ^hci | cut -d: -f1`
387         local btd="`getprop init.svc.bluetoothd`"
388         log -t bluetoothd -p i "$btd ($hci)"
389         if [ -n "`getprop hal.bluetooth.uart`" ]; then
390                 [ "`getprop init.svc.bluetoothd`" = "running" ] && hciconfig $hci up
391         fi
392 }
393
394 PATH=/sbin:/system/bin:/system/xbin
395
396 DMIPATH=/sys/class/dmi/id
397 BOARD=$(cat $DMIPATH/board_name)
398 PRODUCT=$(cat $DMIPATH/product_name)
399
400 # import cmdline variables
401 for c in `cat /proc/cmdline`; do
402         case $c in
403                 androidboot.hardware=*)
404                         ;;
405                 *=*)
406                         eval $c
407                         case $c in
408                                 HWACCEL=*)
409                                         set_property debug.egl.hw $HWACCEL
410                                         ;;
411                                 DEBUG=*)
412                                         set_property debug.logcat 1
413                                         ;;
414                         esac
415                         ;;
416         esac
417 done
418
419 [ -n "$DEBUG" ] && set -x || exec &> /dev/null
420
421 # import the vendor specific script
422 hw_sh=/vendor/etc/init.sh
423 [ -e $hw_sh ] && source $hw_sh
424
425 case "$1" in
426         netconsole)
427                 [ -n "$DEBUG" ] && do_netconsole
428                 ;;
429         bootcomplete)
430                 do_bootcomplete
431                 ;;
432         hci)
433                 do_hci
434                 ;;
435         init|"")
436                 do_init
437                 ;;
438 esac
439
440 return 0