#!/bin/bash

#    GNU/Linux PCI driver for Khomp boards.  
#    Copyright (C) -- Khomp Ind. & Com.  
#
#  This program is free software; you can redistribute it and/or  
#  modify it under the terms of the GNU General Public License  
#  as published by the Free Software Foundation; either version 2  
#  of the License, or (at your option) any later version.  
#    
#  This program is distributed in the hope that it will be useful,  
#  but WITHOUT ANY WARRANTY; without even the implied warranty of  
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
#  GNU General Public License for more details.  
#    
#  You should have received a copy of the GNU General Public License  
#  along with this program; if not, write to the Free Software  
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.  

path="/dev/khomp"
modulepci="kpci9030"
modulepex="kpex8311"

/sbin/insmod "./${modulepci}.ko" $*
/sbin/insmod "./${modulepex}.ko" $*

majorpci=`cat /proc/devices | awk "\\$2==\"$modulepci\" {print \\$1}"`
majorpex=`cat /proc/devices | awk "\\$2==\"$modulepex\" {print \\$1}"`

if [ -d "${path}" ]; then
    chmod 777 "${path}"
else
    mkdir "${path}"
    chmod 777 "${path}"
fi

rm -f ${path}/${name}*

if [ "${majorpci}w" = "w" ]; then
    echo "Loading KHOMP devices: pci module not loaded!"
else
	for ((i=0;i<=20;i++))
	do
  	    mknod "${path}/${modulepci}_$i" c "${majorpci}" "$i"
	done
    echo "Loading KHOMP devices: pci module loaded!"
fi

if [ "${majorpex}w" = "w" ]; then
    echo "Loading KHOMP devices: pci express module not loaded!"
else
	for ((i=0;i<=20;i++))
	do
        mknod "${path}/${modulepex}_$i" c "${majorpex}" "$i"
	done
    echo "Loading KHOMP devices: pci express module loaded!"
fi

chmod 777 -R "${path}"
