#!/bin/sh
# $Id: gpio_load,v 1.1 2006/09/21 12:38:05 papps Exp $
module="gpio"
device="gpio"
mode="664"

num_of_devices=$1

echo
if [ $num_of_devices -ge 1 ] ; then
{
#Group: look for 'sys'. If not present then 'root'
if grep -q '^sys:' /etc/group; then
    group="sys"
else
    group="root"
fi

# invoke insmod with all arguments we got
# and use a pathname, as insmod doesn't look in . by default
/sbin/insmod ./$module.ko || exit 1

# retrieve major number
major=$(awk "\$2==\"$module\" {print \$1}" /proc/devices)

#echo "Major number $major, and group $group"

# Remove any stale node
rm -f /dev/${device}

echo Creating Gpio nodes....
# Create a new node for gpio

num_of_devices=$(expr $num_of_devices - 1)

for i in $(seq 0 $num_of_devices)
do

mknod /dev/${device}$i c $major $i

# Set nodes gid and permissions
chgrp $group /dev/${device}$i
chmod $mode  /dev/${device}$i

echo /dev/gpio$i Major=$major Minor=$i created
done

echo "Gpio Module Loaded"

}
else
{
echo "Invalid Parameter." 
echo "Usage: ./gpio_load num_of_devices"
echo "where 'num_of_devices' corresponds to number of Gpio devices connected to the system and must be 1 or greater"
echo
}
fi
echo
