2008-03-21 19:38:16 +02:00
|
|
|
#!/bin/sh /etc/rc.common
|
|
|
|
# Copyright (C) 2008 OpenWrt.org
|
|
|
|
START=90
|
|
|
|
|
2008-07-20 22:34:09 +03:00
|
|
|
CONFIGFS_DIR="/config/gpiommc"
|
2008-03-21 19:38:16 +02:00
|
|
|
|
|
|
|
# add_device(name, DI_pin, DO_pin, CLK_pin, CS_pin, mode)
|
|
|
|
add_device() {
|
2008-07-20 22:34:09 +03:00
|
|
|
local dir="$CONFIGFS_DIR/$1"
|
|
|
|
|
|
|
|
mkdir $dir
|
|
|
|
[ $? -eq 0 ] || return 1
|
|
|
|
echo $2 > $dir/gpio_data_in
|
|
|
|
[ $? -eq 0 ] || return 1
|
|
|
|
echo $3 > $dir/gpio_data_out
|
|
|
|
[ $? -eq 0 ] || return 1
|
|
|
|
echo $4 > $dir/gpio_clock
|
|
|
|
[ $? -eq 0 ] || return 1
|
|
|
|
echo $5 > $dir/gpio_chipselect
|
|
|
|
[ $? -eq 0 ] || return 1
|
|
|
|
echo $6 > $dir/spi_mode
|
|
|
|
[ $? -eq 0 ] || return 1
|
|
|
|
# XXX We have more config options available. Use defaults for now.
|
|
|
|
|
|
|
|
echo 1 > $dir/register
|
|
|
|
[ $? -eq 0 ] || return 1
|
|
|
|
|
|
|
|
return 0
|
2008-03-21 19:38:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# remove_device(name)
|
|
|
|
remove_device() {
|
2008-07-20 22:34:09 +03:00
|
|
|
local dir="$CONFIGFS_DIR/$1"
|
|
|
|
|
|
|
|
rmdir $dir
|
|
|
|
}
|
|
|
|
|
|
|
|
mount_configfs() {
|
|
|
|
# FIXME: This should probably be done somewhere else.
|
|
|
|
mount | grep configfs
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
# already mounted
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
mkdir -p /config
|
|
|
|
[ $? -eq 0 ] || return 1
|
|
|
|
mount configfs -t configfs /config
|
|
|
|
[ $? -eq 0 ] || return 1
|
|
|
|
|
|
|
|
return 0
|
2008-03-21 19:38:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
2008-07-20 22:34:09 +03:00
|
|
|
# Make sure configfs is mounted
|
|
|
|
mount_configfs
|
|
|
|
[ $? -eq 0 ] || return 1
|
|
|
|
|
2008-03-21 19:38:16 +02:00
|
|
|
#FIXME we should use a config file, but I dunno how that parser works.
|
|
|
|
add_device "default" 5 4 3 7 0
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
remove_device "default"
|
|
|
|
}
|