#!/bin/sh

module="ISP"
device="/dev/ISP"
mode="666"
module_ex="ExISP"

#check module location
. /etc/default/devcap
if [ "$ISP_TYPE" != "A1_ISP" ]; then
	# camera uses external ISP
	rm -f /lib/modules/$module.ko
	ln -s /lib/modules/$module_ex.ko /lib/modules/$module.ko
	ARG="isp_type=\"$ISP_TYPE\" debug_ctrl=0"
	echo "$0: external ISP, ARG=$ARG"
else
	# camera uses internal ISP
	MODEL=`fw_printenv serial |cut -d= -f2 |cut -b 1-9`
	if [ -z "$MODEL" ]; then
		ARG="debug_ctrl=0"
	else
		ARG="cam_model=\"$MODEL\" debug_ctrl=0"
	fi
	echo "$0: internal ISP, ARG=$ARG"
fi
if [ -f /etc/config/$module.ko ]; then
	rm -f /lib/modules/$module.ko 
	ln -s /etc/config/$module.ko /lib/modules/$module.ko
	echo "$0: use test ISP.ko"
fi
#insert module
insmod /lib/modules/$module.ko $ARG || exit 1

echo "module $module inserted"

#remove old nod
rm -f $device

#read the major asigned at loading time
major=`cat /proc/devices | grep $module | cut -c1-3`

echo "$module major = $major"

#create dev node
mknod $device c $major 0

echo "node $device created"

#give all 'rw' access
chmod $mode $device

echo "set node access to $mode"

#the end
echo
