OSDN Git Service

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