kernel-playground/dummy-gpio/dummy-gpio.c

74 lines
1.6 KiB
C

#include <linux/kernel.h>
#include <linux/platform_device.h>
#include <linux/gpio.h>
#include <linux/gpio/driver.h>
#include <linux/module.h>
#include <linux/init.h>
struct dummy_gpio {
struct gpio_chip gc;
struct mutex lock;
};
static struct dummy_gpio dgpio;
static int dummy_gpio_direction_input(struct gpio_chip *chip, unsigned offset) {
printk("direction input\n");
return 0;
}
static void dummy_gpio_set(struct gpio_chip *chip, unsigned offset, int value) {
printk("set\n");
}
static int dummy_gpio_direction_output(struct gpio_chip *chip, unsigned offset, int value) {
printk("output\n");
return 0;
}
static int dummy_gpio_get(struct gpio_chip *chip, unsigned offset) {
printk("get\n");
return 0;
}
static int __init dummy_gpio_init(void) {
int err;
mutex_init(&dgpio.lock);
dgpio.gc.label = "dummy_gpio";
dgpio.gc.direction_input = dummy_gpio_direction_input;
dgpio.gc.get = dummy_gpio_get;
dgpio.gc.direction_output = dummy_gpio_direction_output;
dgpio.gc.set = dummy_gpio_set;
dgpio.gc.ngpio = 8;
dgpio.gc.can_sleep = true;
// from 4.5
dgpio.gc.parent = NULL;
// dgpio.gc.dev = NULL;
dgpio.gc.owner = THIS_MODULE;
// gpiochip_add_data from 4.5
err = gpiochip_add(&dgpio.gc);
//err = gpiochip_add_data()
if(err)
goto exit_destroy;
return err;
exit_destroy:
mutex_destroy(&dgpio.lock);
return err;
}
static void __exit dummy_gpio_exit(void) {
gpiochip_remove(&dgpio.gc);
mutex_destroy(&dgpio.lock);
printk("dummy_gpio: Cya in another life\n");
}
module_init(dummy_gpio_init);
module_exit(dummy_gpio_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("encrypt";)
MODULE_DESCRIPTION("Dummy gpiochip");