#!/bin/sh

# this is necessary for RedHat-distributions,
# because all module tools (depmod, insmod, rmmod)
# are located in /sbin, which is not included
# in the standard search path for anyone

#
# shamlessly stolen from linuxtv.org driver.mxb
# place in /etc/init.d/ and start as service
#

export PATH=$PATH:/sbin

# fresh up the dependencies first
depmod -ae

case "$1" in

    start)
	echo -n -e "Inserting Marvel modules into kernel"
	d_i2c=0
	d_core=0
	d_mjpg=0
	d_mw=0
	modprobe i2c-core i2c_debug=0;
	modprobe ti2c-algo-ks i2c_debug=0 bit_scan=1
	modprobe msp3400 debug=$d_i2c simple=0
	modprobe maven   debug=$d_i2c
	modprobe ks0127  debug=$d_i2c
	modprobe tuner
	modprobe videodev
	modprobe mga_core vdo_enable=1 bes_brightness=31 mgacore_debug=$d_core mgai2c_debug=$d_i2c mgaclk_debug=$d_core mgabus_debug=$d_core
	modprobe mgagrab    debug=$d_mw
	modprobe mgacap     debug=$d_mw
	modprobe mgavideo   default_norm=0 debug=$d_mw
	modprobe zr36060    debug=$d_mjpg
	modprobe i33	    debug=$d_mjpg
	modprobe mgajpg     debug=$d_mjpg
	echo
	;;
    debug)
	echo -n -e "Inserting Marvel modules with debug options into kernel"
	d_i2c=255
	d_core=255
	d_mjpg=255
	d_mw=255
	modprobe i2c-core i2c_debug=0;
	modprobe ti2c-algo-ks i2c_debug=0 bit_scan=1
	modprobe msp3400 debug=$d_i2c simple=0
	modprobe maven   debug=$d_i2c
	modprobe ks0127  debug=$d_i2c
	modprobe tuner
	modprobe videodev
	modprobe mga_core vdo_enable=1 bes_brightness=31 mgacore_debug=$d_core mgai2c_debug=$d_i2c mgaclk_debug=$d_core mgabus_debug=$d_core
	modprobe mgagrab    debug=$d_mw
	modprobe mgacap     debug=$d_mw
	modprobe mgavideo   default_norm=0 debug=$d_mw
	modprobe zr36060    debug=$d_mjpg
	modprobe i33	    debug=$d_mjpg
	modprobe mgajpg     debug=$d_mjpg
	echo
	;;
    stop)
	echo -n -e "Unloading Marvel modules from kernel"
	rmmod mgajpg i33 mgavideo mgacap mgayuv mgagrab zr36060 mga_core maven msp3400 ks0127 tuner videodev i2c-algo-ks i2c-core /&> /dev/null
	echo
	;;
    restart|reload)
	$0 stop && $0 debug
	;;
    *)
	echo "Usage$0 {start|stop|debug|restart}"
	exit 1
esac

exit 0
