#!/bin/sh

# Set the system time from hardware RTC
#hwclock
#hwclock -r -f /dev/rtc1
#date
#insmod /mnt/mmc/linux/softcursor.ko
#insmod /mnt/mmc/linux/font.ko
#insmod /mnt/mmc/linux/tileblit.ko
#insmod /mnt/mmc/linux/bitblit.ko
#insmod /mnt/mmc/linux/vfb.ko
#insmod /mnt/mmc/linux/fbcon.ko

#kexec /mnt/mmc/zImage

#cat /proc/asound/version > /dev/tty0

#The relevant ones are SDL_AUDIODRIVER which should be set to alsa, and AUDIODEV or SDL_PATH_DSP which should be set to the name of the ALSA audio device, usually default or dsp0.

#export SDL_VIDEODRIVER="dummy"
#export SDL_FBDEV="/dev/fb0"
#export SDL_FBACCEL=0
#export SDL_NOMOUSE=0
#export SDL_AUDIODRIVER="alsa"
#export AUDIODEV="default"
#export AUDIODEV="/dev/snd/pcmC0D0p"
#export SDL_PATH_DSP="/dev/mxc_pcm_dev"
#export SDL_DISKAUDIOFILE="/dev/mxc_pcm_dev"
#export SDL_DISKAUDIOFILE="/dev/snd/pcmC0D0p"
#export SDL_DEBUG=1
#export AUDIODEV="hw:0,0"
#export SDL_DSP_NOSELECT=1
#export ESD_NO_SPAWN=1
#export SDL_PATH_DSP="/dev/dsp"
#export SDL_PATH_DSP="/dev/snd/pcmC0D0p"
# It requests a big buffer to give the ALSA driver plenty of data.
# This lets it get past system busy times without gaps in the audio.
# The new driver also waits for the buffer to fill a bit before playing.
# This avoids most of the jittery mess when rockbox first starts up.
# You can adjust/debug the parameters with these environment variables.

# Enable this if you want to print SDL ALSA debug info on stdout.
#export SDL_AUDIO_ALSA_DEBUG=1

# The default behavior is to ask for a 1000ms (1 second) ALSA buffer.
# The driver only gives a max of 32768 frames (3/4 secs @ 44.1KHz) though.
#export SDL_AUDIO_ALSA_SET_BUFFER_SIZE=32768

# By default wait for 500ms (.5 secs) in buffer before ALSA starts playing.
#export SDL_AUDIO_ALSA_SET_START_THRESH=500

# The default is to let the SDL app ask for the period size.
# Rockbox asks for 2048 frames, GMU wants 4096 frames per period.
# But the ALSA driver likes to pick 1024 frames with a big buffer.
#export SDL_AUDIO_ALSA_SET_PERIOD_SIZE=1024

#export SDL_JOYSTICK_DEVICE="/dev/input/event0"

#Blank-Unblank video to get rid of Samsung BootLogo
echo -n "0" > /sys/devices/platform/afe.0/bli
echo -n "1" > /sys/class/graphics/fb0/blank
echo -n "0" >> /sys/class/graphics/fb0/blank
#echo -n "3" >> /sys/class/graphics/fb0/blank
#echo -n "1" > /sys/class/graphics/fb1/blank
#echo -n "1" > /sys/class/graphics/fb2/blank
#echo -n "0" >> /sys/class/graphics/fb2/blank
#echo -n "3" > /sys/class/graphics/fb2/blank
#echo -n "3" > /sys/class/graphics/fb1/blank
#/mnt/mmc/fb_test
#sleep 10
#reboot
#Enable our nice console on a player :D
#echo 1 > /sys/class/vtconsole/vtcon1/bind
#cat /sys/class/vtconsole/vtcon1/name
#echo 1 > /sys/class/vtconsole/vtcon0/bind
#cat /sys/class/vtconsole/vtcon0/name
#We use SDL, that's here
#export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib

#cat /proc/asound/cards
#cat /sys/devices/platform/as3543-imx-audio/as3543-codec/codec_reg
cd /usr/bin
./amixer sset 'Soft Mute' 0
#./amixer sset 'Master Power Switch' 1
#./amixer sset 'Master Mute' 0
#./amixer sset 'FM Mute' 1
./amixer sset 'Master' 85%
#./amixer cset iface=MIXER,name='Master Power Switch' 0
#./amixer cset numid=1 1
#./amixer cset numid=7 1
#./amixer controls
#./amixer contents
#cat /sys/devices/platform/as3543-imx-audio/as3543-codec/codec_reg
#echo "HW volume set to max"
#echo "Now starting RockBox in 2..." > /dev/tty0
#sleep 1
#echo "Now starting RockBox..."
#echo "Enjoy RockBox!"

# Do that in firmware!
#for i in 0 1 2 3 4 5 6 7; do mknod /dev/tty$i c 4 $i; done
# We set-up various settings for the cpu governor: default are
# Every 1,5 s the kernel evaluates if it's the case to down/up clocking the cpu
echo "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo "1" > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/ignore_nice_load
echo "150000" > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate
echo "95" > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold
#echo "200" > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/powersave_bias
#echo "65" > /sys/devices/system/cpu/cpu0/cpufreq/conservative/freq_step
#echo "40" > /sys/devices/system/cpu/cpu0/cpufreq/conservative/down_threshold
#echo "" > /sys/devices/system/cpu/cpu0/cpufreq/conservative/sampling_down_factor
#SDL audio test..
#alsactl -f /mnt/mmc/alsa.before store
#cat /sys/devices/platform/as3543-imx-audio/as3543-codec/codec_reg
# Workaround to enable alsa audio :S
#/usr/bin/aplay "/mnt/mmc/test.wav" &
#cat /sys/devices/platform/as3543-imx-audio/as3543-codec/codec_reg
#sleep 1
#alsactl -f /mnt/mmc/alsa.after store
#./loopwave &
#./amixer sset 'Soft Mute' 0
#./amixer sset 'Master Mute' 0
#./amixer sset 'FM Mute' 1
#./amixer sset 'Master' 70%
#./amixer cset numid=1 1
#./amixer cset numid=7 1
#cd /usr/bin
#./amixer sset 'Soft Mute' 0
#./amixer sset 'Master' 100%
#sleep 5
#sync
#reboot
#Important to make the lib to be read by rockbox
#export LD_PRELOAD="/mnt/mmc/libSDL-1.2.so.0"
#NOTE: this defines settings folder
#export RB_DIR="/mnt/mmc/rockbox"
# We need to unbind consoles just before starting RockBox, otherwise when we close it @ 200 MHz, having the fb0/1/2
# in sleep mode, the player crashes for some reason.
#echo 0 > /sys/class/vtconsole/vtcon1/bind
#echo 0 > /sys/class/vtconsole/vtcon0/bind

echo "enable_lp_audio" > /sys/devices/platform/mx37_lpmode.0/lp_modes
cat /sys/devices/platform/mx37_lpmode.0/lp_modes

mount --bind /mnt/media0/.rockbox /.rockbox
MAINFILE="/mnt/media0/.rockbox/rockbox"

#cd /mnt/media0/.rockbox
#chmod +x rockbox
#./rockbox > err.txt 2>&1
#sync
#echo -n "0" > /sys/class/graphics/fb1/blank
#echo -n "0" > /sys/class/graphics/fb2/blank
#cd /usr/bin
#test () {
#while [ 1 ]; do
#./amixer sset 'Soft Mute' 0
# ./amixer sset 'Master' 100%
#done
#}

#test
#insmod /mnt/mmc/linux/mxc_si4702.ko
#dmesg
#sleep 1
#ls /dev
#/mnt/mmc/checkkeys
# &
#dmesg

#dmesg
#sleep 10
#reboot
#cd /mnt/media0/scripts
#chmod +x sdltest
#./sdltest