linux DTS gpio example
来源:互联网 发布:慕课网java视频下载 编辑:程序博客网 时间:2024/04/30 02:34
http://developer.t-firefly.com/thread-648-1-1.html
http://v.youku.com/v_show/id_XODY4NTA3OTcy.html?from=s1.8-1-1.2&spm=a2h0k.8191407.0.0
1. add configuration in dts
hello-led{compatible = "firefly,hello_led";led= <&gpio8 GPIO_A2 GPIO_ACTIVE_LOW>;status = "okay";};
2. source code
#include <linux/kernel.h>#include <linux/init.h>#include <linux/module.h> #include <linux/delay.h>#include <linux/gpio.h>#ifdef CONFIG_OF#include <linux/of.h>#include <linux/of_gpio.h>#include <linux/of_platform.h>#endif#define GPIO_LOW 0#define GPIO_HIGH 1static int firefly_hello_probe(struct platform_device *pdev){ int ret = -1;int i; int gpio,flag;struct device_node *hello_node = pdev->dev.of_node;printk("%s-%d: enter\n",__FUNCTION__,__LINE__);gpio = of_get_named_gpio_flags(hello_node,"led", 0,&flag);if (!gpio_is_valid(gpio)){printk("hello: invalid gpio : %d\n",gpio);return -1;} ret = gpio_request(gpio, "hello_led");if (ret != 0) {gpio_free(gpio);return -EIO;}gpio_direction_output(gpio, GPIO_HIGH);for(i=0; i < 10; i++){gpio_set_value(gpio,GPIO_LOW);mdelay(500);gpio_set_value(gpio,GPIO_HIGH);mdelay(500);} printk("%s-%d: exit\n",__FUNCTION__,__LINE__);return 0; //return Ok}static int firefly_hello_remove(struct platform_device *pdev){ return 0;}#ifdef CONFIG_OFstatic const struct of_device_id of_firefly_hello_match[] = {{ .compatible = "firefly,hello_led" },{ /* Sentinel */ }};#endifstatic struct platform_driver firefly_hello_driver = {.probe= firefly_hello_probe,.remove= firefly_hello_remove,.driver= {.name= "firefly_hello",.owner= THIS_MODULE,#ifdef CONFIG_OF.of_match_table= of_firefly_hello_match,#endif},};static int __init hello_init(void){ printk(KERN_INFO "Enter %s\n", __FUNCTION__); return platform_driver_register(&firefly_hello_driver); return 0;}static void __exit hello_exit(void){platform_driver_unregister(&firefly_hello_driver); printk("Exit Hello world\n");}subsys_initcall(hello_init);module_exit(hello_exit);MODULE_AUTHOR("sai <271319925@qq.com>");MODULE_DESCRIPTION("Firefly hello driver");MODULE_LICENSE("GPL");
0 0
- linux DTS gpio example
- linux dts gpio sysfs example
- linux dts gpio kernel example
- Linux GPIO
- Linux-GPIO
- Linux DTS配置总结
- linux 的dts
- linux DTS 分析
- linux 驱动之 dts
- Linux-DTS基础
- linux dts interrupt
- linux dts i2c
- Linux-DTS基础
- Linux DTS 设备树
- openwrt-dts-gpio-控制LTE上电及LED点亮
- linux msm dts加载分析
- 【linux】 linux gpio操作
- DTS
- 硬盘分区相关
- Spark:用Scala和Java实现WordCount
- 数据结构-二叉树主要性质
- 如何编译支持在Windows2000下运行的Qt程序
- 1042. 字符统计(20)
- linux DTS gpio example
- CentOS 7 Linux安装NFS
- CSS 网格视图
- 第十二周项目4 利用遍历思想求解图问题
- JAVA栅栏和闭锁的区别
- (二)归并排序
- 几个GIS网站
- Golang-简洁的并发
- 浅谈C中的malloc和free