#include "usb_gpio.h" static struct gpio_chip ft232_chip; static struct subprocess_info *sub_info; static struct semaphore read_sema; static char pin_status[1]; static int major; static uint8_t buff_empty=1; static uint8_t buff_start; static uint8_t buff_end; static uint8_t buffer[BUFFER_SIZE]; #include "char_dev.c" #include "gpio_callbacks.c" static void usb_gpio_exit(void) { if( gpiochip_remove(&ft232_chip)<0 ){ printk("<1>%s: Couldn't free GPIO-pins!\n",MOD_NAME); } unregister_chrdev(major, MOD_NAME); printk("<1>%s: Bye!\n",MOD_NAME); } static int usb_gpio_init(void) { int ret; // Prepare user space handler call char *argv[] = { "/usr/bin/usb_gpio_ftdi_helper", NULL }; static char *envp[] = { "HOME=/", "TERM=linux", "PATH=/sbin:/bin:/usr/sbin:/usr/bin", NULL }; printk("<1>%s: Loading... \n",MOD_NAME); major = register_chrdev(0, MOD_NAME, &fops); if(major<0){ printk("<1>%s: Can't register character device!\n",MOD_NAME); } printk("<1>%s: Assigned device major #%d minor #0!\n",MOD_NAME,major); printk("<1>%s: Create device file with: \"mknod /dev/usb_gpio c %d 0\"\n",MOD_NAME,major); sema_init(&read_sema,0); //GPIO registration ft232_chip.label = MOD_NAME; //Callback functions ft232_chip.direction_input = set_in; ft232_chip.direction_output = set_out; ft232_chip.get = get_value; ft232_chip.set = set_value; //Automaticaly choose GPIO numbers - manual seems not to be possible ft232_chip.base = -1; //Number of GPIO pins ft232_chip.ngpio = NUM_OF_GPIO; //This indicates that get and set functions can sleep ft232_chip.can_sleep = 1; ft232_chip.owner = THIS_MODULE; ret = gpiochip_add(&ft232_chip); DEBUG_OUT("<1>%s: gpiochip_add returned %d\n",MOD_NAME,ret); if (ret){ printk("<1>%s: Can't register chip!\n",MOD_NAME); } return ret; //Call the user space handler /*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 ret=call_usermodehelper_exec( sub_info, UMH_NO_WAIT ); if(ret<0){ printk("<1>%s: Couldn't run userspace helper process (%s)!\n",MOD_NAME,); }*/ } module_init(usb_gpio_init); module_exit(usb_gpio_exit); MODULE_LICENSE("Dual BSD/GPL");