1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 | #include <linux/init.h>
#include <linux/module.h>
#include <linux/gpio.h>
#define MY_GPIO_PIN 17
static int __init my_gpio_init(void)
{
int ret;
ret = gpio_request(MY_GPIO_PIN, "my_gpio");
if (ret) {
printk(KERN_ERR "Failed to request GPIO %d\n", MY_GPIO_PIN);
return ret;
}
ret = gpio_direction_output(MY_GPIO_PIN, 1);
if (ret) {
printk(KERN_ERR "Failed to set GPIO %d as output\n", MY_GPIO_PIN);
gpio_free(MY_GPIO_PIN);
return ret;
}
gpio_set_value(MY_GPIO_PIN, 0);
printk(KERN_INFO "GPIO %d set to low level\n", MY_GPIO_PIN);
return 0;
}
static void __exit my_gpio_exit(void)
{
gpio_free(MY_GPIO_PIN);
printk(KERN_INFO "GPIO %d freed\n", MY_GPIO_PIN);
}
module_init(my_gpio_init);
module_exit(my_gpio_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("ygc");
|