OSDN Git Service

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