OSDN Git Service

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