mmc_over_gpio.init 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2008 OpenWrt.org
  3. START=90
  4. CONFIGFS_DIR="/config/gpiommc"
  5. # add_device(name, DI_pin, DO_pin, CLK_pin, CS_pin, mode)
  6. add_device() {
  7. local dir="$CONFIGFS_DIR/$1"
  8. mkdir -p $dir
  9. [ $? -eq 0 ] || return 1
  10. echo $2 > $dir/gpio_data_in
  11. [ $? -eq 0 ] || return 1
  12. echo $3 > $dir/gpio_data_out
  13. [ $? -eq 0 ] || return 1
  14. echo $4 > $dir/gpio_clock
  15. [ $? -eq 0 ] || return 1
  16. echo $5 > $dir/gpio_chipselect
  17. [ $? -eq 0 ] || return 1
  18. echo $6 > $dir/spi_mode
  19. [ $? -eq 0 ] || return 1
  20. # XXX We have more config options available. Use defaults for now.
  21. echo 1 > $dir/register
  22. [ $? -eq 0 ] || return 1
  23. return 0
  24. }
  25. # remove_device(name)
  26. remove_device() {
  27. local dir="$CONFIGFS_DIR/$1"
  28. rmdir $dir
  29. }
  30. mount_configfs() {
  31. # FIXME: This should probably be done somewhere else.
  32. mount | grep configfs
  33. if [ $? -eq 0 ]; then
  34. # already mounted
  35. return 0
  36. fi
  37. mkdir -p /config
  38. [ $? -eq 0 ] || return 1
  39. mount configfs -t configfs /config
  40. [ $? -eq 0 ] || return 1
  41. return 0
  42. }
  43. start_service() {
  44. local section="$1"
  45. config_get "name" "$section" "name"
  46. config_get "DI_pin" "$section" "DI_pin"
  47. config_get "DO_pin" "$section" "DO_pin"
  48. config_get "CLK_pin" "$section" "CLK_pin"
  49. config_get "CS_pin" "$section" "CS_pin"
  50. config_get "mode" "$section" "mode"
  51. config_get_bool "enabled" "$section" "enabled" '1'
  52. [ "$enabled" -gt 0 ] && add_device "$name" $DI_pin $DO_pin $CLK_pin $CS_pin $mode &
  53. }
  54. stop_service() {
  55. local section="$1"
  56. config_get "name" "$section" "name"
  57. remove_device "$name"
  58. }
  59. start() {
  60. # Make sure configfs is mounted
  61. mount_configfs
  62. [ $? -eq 0 ] || return 1
  63. config_load "mmc_over_gpio"
  64. config_foreach start_service "mmc_over_gpio"
  65. }
  66. stop() {
  67. config_load "mmc_over_gpio"
  68. config_foreach stop_service "mmc_over_gpio"
  69. }