You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
1.7 KiB
84 lines
1.7 KiB
17 years ago
|
#!/bin/sh /etc/rc.common
|
||
|
# Copyright (C) 2008 OpenWrt.org
|
||
|
START=90
|
||
|
|
||
17 years ago
|
CONFIGFS_DIR="/config/gpiommc"
|
||
17 years ago
|
|
||
|
# add_device(name, DI_pin, DO_pin, CLK_pin, CS_pin, mode)
|
||
|
add_device() {
|
||
17 years ago
|
local dir="$CONFIGFS_DIR/$1"
|
||
|
|
||
16 years ago
|
mkdir -p $dir
|
||
17 years ago
|
[ $? -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
|
||
17 years ago
|
}
|
||
|
|
||
|
# remove_device(name)
|
||
|
remove_device() {
|
||
17 years ago
|
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
|
||
17 years ago
|
}
|
||
|
|
||
16 years ago
|
start_service() {
|
||
|
local section="$1"
|
||
|
config_get "name" "$section" "name"
|
||
|
config_get "DI_pin" "$section" "DI_pin"
|
||
|
config_get "DO_pin" "$section" "DO_pin"
|
||
|
config_get "CLK_pin" "$section" "CLK_pin"
|
||
|
config_get "CS_pin" "$section" "CS_pin"
|
||
|
config_get "mode" "$section" "mode"
|
||
|
config_get_bool "enabled" "$section" "enabled" '1'
|
||
|
[ "$enabled" -gt 0 ] && add_device "$name" $DI_pin $DO_pin $CLK_pin $CS_pin $mode &
|
||
|
}
|
||
|
|
||
|
stop_service() {
|
||
|
local section="$1"
|
||
|
config_get "name" "$section" "name"
|
||
|
remove_device "$name"
|
||
|
}
|
||
|
|
||
17 years ago
|
start() {
|
||
17 years ago
|
# Make sure configfs is mounted
|
||
|
mount_configfs
|
||
|
[ $? -eq 0 ] || return 1
|
||
|
|
||
16 years ago
|
config_load "mmc_over_gpio"
|
||
|
config_foreach start_service "mmc_over_gpio"
|
||
17 years ago
|
}
|
||
|
|
||
|
stop() {
|
||
16 years ago
|
config_load "mmc_over_gpio"
|
||
|
config_foreach stop_service "mmc_over_gpio"
|
||
17 years ago
|
}
|