OSDN Git Service

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