import init.${ro.hardware}.usb.rc
import init.${ro.hardware}.${ro.soc}.rc

on early-init
    setprop ro.boot.write_on_console disabled
    # mount the debugfs
    mount debugfs none /sys/kernel/debug/ mode=0755

on init
    start watchdogd

    # See storage config details at http://source.android.com/tech/storage/
    mkdir /mnt/shell/emulated 0700 shell shell
    mkdir /storage/emulated 0555 root root

    # Support legacy paths
    symlink /sdcard /mnt/sdcard
    symlink /sdcard /storage/sdcard0

    # setup the global environment
    export SHM_MOUNTPOINT /mnt/shm
    export LIGHTSENSOR_PATH /sys/class/i2c-adapter/i2c-1/1-0044
    export VPU_FW_PATH /system/lib/firmware/vpu
    export CODEC_SHM_PATH /mnt/shm
    export CORE_REGISTER_FILE /system/etc/core_register
    export COMPONENT_REGISTER_FILE /system/etc/component_register
    export CONTENTPIPE_REGISTER_FILE /system/etc/contentpipe_register
    
    # disable cursor blink for fbcon, if no splash screen support
    write /sys/class/graphics/fbcon/cursor_blink 0

    # deattch the fbcon as hdmi hotplug conflict with fbcon
    write /sys/class/vtconsole/vtcon1/bind 0

on boot

    # emmulate battery property
    setprop sys.emulated.battery 1

    # Set permission for IIM node
    symlink /dev/mxs_viim /dev/mxc_mem

    # Enable Tethering in the Settings
    setprop ro.tether.denied false

    # 3D acceleration property
    setprop debug.sf.showfps    0
    setprop debug.sf.enable_hgl 1
    setprop debug.egl.hw	1

    setprop hwc.stretch.filter  1
    setprop hwc.enable_dither   1

    # fsl omx graphic manager media framework property
    setprop media.omxgm.enable-player 1
    setprop media.omxgm.enable-record 1
    setprop media.omxgm.enable-scan 1
    setprop rw.VIDEO_RENDER_NAME video_render.surface

    #Define the config for dual camera
    setprop camera.disable_zsl_mode 1
    #For landscape mode, orient is 0
    #For portrait mode, orient is 90
    #the android before honycomb are all in portrait mode
    setprop back_camera_orient 180
    setprop front_camera_orient 0

    # Tweak the mmc device read ahead buffer size
    write /sys/block/mmcblk1/queue/read_ahead_kb 2048
    write /sys/block/mmcblk3/queue/read_ahead_kb 2048

    # ALSA mixer naming define
    setprop alsa.mixer.playback.master Playback
    setprop alsa.mixer.capture.master Capture
    setprop alsa.mixer.playback.speaker Playback
    setprop alsa.mixer.playback.headset Headphone
    setprop alsa.mixer.capture.headset Capture

    # Prepare for wifi
    setprop wifi.interface wlan0
    setprop wifi.ap.interface wlan0

#    #  Enable adb security for JB4.2.2
#    setprop ro.adb.secure 1

    # Set rotation to 270 to cofigure as portrait mode
    setprop ro.sf.hwrotation 0

    # Set the density to 160dpi, default 128dpi is not good
    setprop ro.sf.lcd_density 160

    # Set extsd access permission
    setprop persist.sampling_profiler 1

# change for FSL specific service
    chown root system /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
    chmod 0664 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
    chown root system /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
    chmod 0664 /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
    chown root system /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
    chmod 0664 /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
    chown root system /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
    chmod 0440 /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
    chown root system /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
    chown root system /sys/devices/system/cpu/cpu0/online
    chmod 0664 /sys/devices/system/cpu/cpu0/online
    chown root system /sys/devices/system/cpu/cpu1/online
    chmod 0664 /sys/devices/system/cpu/cpu1/online
    chown root system /sys/devices/system/cpu/cpu2/online
    chmod 0664 /sys/devices/system/cpu/cpu2/online
    chown root system /sys/devices/system/cpu/cpu3/online
    chmod 0664 /sys/devices/system/cpu/cpu3/online

    # prepare for ril
    setprop gsm.ril.delay 15
    setprop ro.ril.wake_lock_timeout 300

    # Default backlight device
    setprop hw.backlight.dev "backlight"
    # Chmod/chown FSL specific sys entry
    chown system system /sys/class/backlight/backlight/brightness
    chmod 0660 /sys/class/backlight/backlight/brightness
    write /sys/class/backlight/backlight/brightness 6


    # Set light sensor sysfs path and light sensor threshold lux value
    setprop ro.hardware.lightsensor "/sys/class/i2c-dev/i2c-2/device/2-0044/"
    setprop ro.lightsensor.threshold  20

     # BT and WLAN up
    setprop wlan.interface wlan0
    setprop hw.bluetooth 1

    # Set WiFi Display Source VideoBitRate Adaptive
    setprop media.wfd.video-bitrate 3000000

# Set watchdog timer to 30 seconds and pet it every 10 seconds to get a 20 second margin
    service watchdogd /sbin/watchdogd 10 20
    class core
    seclabel u:r:watchdogd:s0

on charger
    # Enable Power modes and set the CPU Freq Sampling rates
    write /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor "powersave"
    write /sys/devices/system/cpu/cpufreq/ondemand/up_threshold 90
    write /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate 50000
    write /sys/devices/system/cpu/cpufreq/ondemand/io_is_busy 1
    write /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor 4
    write /sys/devices/system/cpu/cpu1/online 0
    write /sys/devices/system/cpu/cpu2/online 0
    write /sys/devices/system/cpu/cpu3/online 0

on property:sys.boot_completed=1
# Set default CPU frequency governor
# Set timer 40ms, min sample 60ms,hispeed at cpufreq MAX freq in freq_table at load 40%
    write /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor interactive
    write /sys/devices/system/cpu/cpufreq/interactive/timer_rate 40000
    write /sys/devices/system/cpu/cpufreq/interactive/min_sample_time 60000
    write /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load 40
    #write /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq 792000

# change interactive atrrubuties permissions when interactive is actived
on property:sys.interactive="active"
    chown system root /sys/devices/system/cpu/cpufreq/interactive/timer_rate
    chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/timer_rate
    chown system root /sys/devices/system/cpu/cpufreq/interactive/min_sample_time
    chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/min_sample_time
    chown system root /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq
    chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq
    chown system root /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load
    chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load
    chown system root /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay
    chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay
    chown system root /sys/devices/system/cpu/cpufreq/interactive/boost
    chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/boost
    chown system root /sys/devices/system/cpu/cpufreq/interactive/boostpulse
    chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/boostpulse
    chown system root /sys/devices/system/cpu/cpufreq/interactive/input_boost
    chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/input_boost
    chown system system /sys/devices/system/cpu/cpufreq/interactive/boostpulse_duration
    chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/boostpulse_duration
    chown system system /sys/devices/system/cpu/cpufreq/interactive/io_is_busy
    chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/io_is_busy

service p2p_supplicant /system/bin/wpa_supplicant \
    -iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf \
    -I/system/etc/wifi/wpa_supplicant_overlay.conf \
    -O/data/misc/wifi/sockets -pp2p_device=1\
    -e/data/misc/wifi/entropy.bin -g@android:wpa_wlan0
    socket wpa_wlan0 dgram 660 wifi wifi
    class late_start
    disabled
    oneshot

service wpa_supplicant /system/bin/wpa_supplicant \
    -iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf \
    -I/system/etc/wifi/wpa_supplicant_overlay.conf \
    -O/data/misc/wifi/sockets \
    -e/data/misc/wifi/entropy.bin -g@android:wpa_wlan0
    socket wpa_wlan0 dgram 660 wifi wifi
    class late_start
    disabled
    oneshot

service charger /charger
    class charger

service dhcpcd_wlan0 /system/bin/dhcpcd -aABDKL
    class main
    disabled
    oneshot

service dhcpcd_p2p /system/bin/dhcpcd -aABKL
    class main
    disabled
    oneshot

service dhcpcd_eth0 /system/bin/dhcpcd -ABKL
    class main
    disabled
    oneshot

service dhcpcd_bt-pan /system/bin/dhcpcd -ABKL
    class main
    disabled
    oneshot

service iprenew_wlan0 /system/bin/dhcpcd -n
    class main
    disabled
    oneshot

service iprenew_p2p /system/bin/dhcpcd -n
    class main
    disabled
    oneshot

service iprenew_eth0 /system/bin/dhcpcd -n
    class main
    disabled
    oneshot

service iprenew_bt-pan /system/bin/dhcpcd -n
    class main
    disabled
    oneshot

service hostapd /system/bin/hostapd /data/misc/wifi/hostapd.conf
    socket hostapd_wlan0 dgram 660 root wifi
    user root
    group wifi
    oneshot
    disabled

on fs
# mount ext4 partitions
    mount_all /fstab.freescale

    # wi-fi
    mkdir /data/misc/wifi/sockets 0770 wifi wifi
    mkdir /data/misc/dhcp 0770 dhcp dhcp
    insmod /system/lib/modules/compat.ko
    insmod /system/lib/modules/cfg80211.ko
    insmod /system/lib/modules/mac80211.ko
    insmod /system/lib/modules/wlcore.ko
    insmod /system/lib/modules/wl12xx.ko
    insmod /system/lib/modules/wl18xx.ko
    insmod /system/lib/modules/wlcore_sdio.ko

#shared transport user space mgr service for Bluetooth, FM and GPS
service uim /system/bin/uim-sysfs
    class core
    user root
    group bluetooth net_bt_admin
    seclabel u:r:hci_attach:s0


on post-fs
    # Turn on swap
    swapon_all /fstab.freescale

    # Swap in only 1 page at a time
    write /proc/sys/vm/page-cluster 0

    # prepare alsa configs
    exec - root system -- /system/bin/sh -c "/system/bin/tinymix 'PCM Playback Volume' 127 127"
    exec - root system -- /system/bin/sh -c "/system/bin/tinymix 'HP DAC Playback Volume' 118 118"
    exec - root system -- /system/bin/sh -c "/system/bin/tinymix 'PGA Capture Volume' 110 110"
