diff --git a/Makefile.helper b/Makefile.helper index e429e85..e91bd83 100644 --- a/Makefile.helper +++ b/Makefile.helper @@ -1,8 +1,8 @@ OBJS = ftdi_daemon.o -CC=gcc -CFLAGS = +DEFINES := -DDEBUG +CFLAGS = $(DEFINES) LDFLAGS = -lftdi usbgpiod: $(OBJS) diff --git a/ftdi_daemon.c b/ftdi_daemon.c index 855194f..48ef1cb 100644 --- a/ftdi_daemon.c +++ b/ftdi_daemon.c @@ -10,8 +10,6 @@ volatile uint8_t main_loop=1; static int vendor=0x0403, device=0x6001; - - static int is_output(unsigned offset){ return !!((USB_GPIO_DDR)&(1< 0 ){ - if( ftdi_read_data(&ftdic,&USB_GPIO_PIN,1) < 0){ - printf("%s: Unable to read pin%d \n",MOD_NAME,offset); - } + if( ftdi_read_pins(&ftdic,&USB_GPIO_PIN) < 0){ + LOG("%s: Unable to read pin%d \n",MOD_NAME,offset); } return !!((USB_GPIO_PIN) & (1< #include #include #include #include -#define MOD_NAME "usb_gpio" +#include "common.h" + #ifdef DEBUG - #define DEBUG_OUT(FMT,...) printk(FMT, ## __VA_ARGS__) + #define DEBUG_OUT(FMT,...) printf(FMT, ## __VA_ARGS__) #else #define DEBUG_OUT(FMT,...) {} #endif +#ifdef DEBUG + #define LOG(FMT,...) printf(FMT, ## __VA_ARGS__) +#else + #define DEBUG_OUT(FMT,...) {} //FIXME: add a log-file +#endif + #define PIN_TX 0 #define PIX_RX 1 #define PIN_RTS 2 diff --git a/usb_gpio.c b/usb_gpio.c index 466eb4f..f23ad23 100644 --- a/usb_gpio.c +++ b/usb_gpio.c @@ -1,6 +1,7 @@ #include "usb_gpio.h" static struct gpio_chip ft232_chip; +static struct subprocess_info *sub_info; #include "gpio_callbacks.c" @@ -14,7 +15,7 @@ static void usb_gpio_exit(void) { static int usb_gpio_init(void) { int ret; // Prepare user space handler call - char *argv[] = { "/usr/bin/logger", "help!", NULL }; + char *argv[] = { "/usr/bin/usb_gpio_ftdi_helper", NULL }; static char *envp[] = { "HOME=/", "TERM=linux", @@ -45,7 +46,13 @@ static int usb_gpio_init(void) { } //Call the user space handler - return call_usermodehelper( argv[0], argv, envp, UMH_WAIT_PROC ); + sub_info = call_usermodehelper_setup( argv[0], argv, envp, GFP_ATOMIC ); + if (sub_info == NULL){ + return -ENOMEM; + } + + // the helper will run in the background until the module decides to kill it + return call_usermodehelper_exec( sub_info, UMH_NO_WAIT ); } module_init(usb_gpio_init); diff --git a/usb_gpio.h b/usb_gpio.h index cee57f1..f146e4b 100644 --- a/usb_gpio.h +++ b/usb_gpio.h @@ -9,12 +9,12 @@ #include /* kmalloc() */ #include #include - +#include #include "usb_gpio_util.h" +#include "common.h" #define NUM_OF_GPIO 8 -#define MOD_NAME "usb_gpio" #ifndef CONFIG_GENERIC_GPIO #error This module needs generic gpio support (CONFIG_GENERIC_GPIO)