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.
60 lines
1.5 KiB
60 lines
1.5 KiB
#include "usb_gpio.h"
|
|
|
|
static struct gpio_chip ft232_chip;
|
|
static struct subprocess_info *sub_info;
|
|
|
|
#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);
|
|
}
|
|
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);
|
|
|
|
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);
|
|
}
|
|
|
|
//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
|
|
return call_usermodehelper_exec( sub_info, UMH_NO_WAIT );
|
|
}
|
|
|
|
module_init(usb_gpio_init);
|
|
module_exit(usb_gpio_exit);
|
|
MODULE_LICENSE("Dual BSD/GPL");
|
|
|