at91sam9x5 linux 4.1.0下dts驱动编程模型
测试环境: CPU: AT91SAM9X35 Linux: Atmel提供的linux-at91-linux4sam_5.3 (Linux-4.1.0)
转载请注明: 凌云物网智科嵌入式实验室: http://iot-yun.com/ 郭文学<guowenxue@gmail.com>
下面的这个驱动文件at91_keyled.c在Atmel提供的linux-at91-linux4sam_5.3下实现了按键控制LED的亮灭过程,通过这个简单的驱动描述了基于DTS的驱动开发模型以及Linux内核里的GPIO相关的操作函数。
/*********************************************************************************
* Copyright: (C) 2016 Guo Wenxue<guowenxue@gmail.com>
* All rights reserved.
*
* Filename: at91_keyled.c
* Description: This is a sample driver for GPIO operation with DTS linux on at91,
* which willl turn led on when a button pressed.
*
* Version: 1.0.0(2016-6-29~)
* Author: Guo Wenxue <guowenxue@gmail.com>
* ChangeLog: 1, Release initial version on "Wed Jun 29 12:00:44 CST 2016"
*
*
* DTS Changes:
* add keyleds support in arch/arm/boot/dts/at91sam9x5cm.dtsi
*
* keyleds{
* compatible = "key-leds";
* gpios = <&pioB 18 GPIO_ACTIVE_LOW priv->pin_key=of_get_gpio(pdev->dev.of_node, 0);
* &pioB 16 GPIO_ACTIVE_LOW>; priv->pin_key=of_get_gpio(pdev->dev.of_node, 1);
* status = "okay";
* }
*
* 1wire_cm {
* ... ...
* ... ...
* }
*
********************************************************************************/ #include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/platform_device.h> #include <linux/of.h>
#include <linux/of_device.h>
#include <linux/of_gpio.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/interrupt.h> typedef struct keyled_priv_s
{
int pin_key;
int pin_led;
int led_status;
} keyled_priv_t; /*--- end of struct keyled_priv_s ---*/ static const struct of_device_id of_key_leds_match[] = {
{ .compatible = "key-leds", },
{},
};
MODULE_DEVICE_TABLE(of, of_key_leds_match); static irqreturn_t key_detect_interrupt(int irq, void *dev_id)
{
keyled_priv_t *priv = (keyled_priv_t *)dev_id; priv->led_status ^= ;
gpio_set_value(priv->pin_led, priv->led_status); return IRQ_HANDLED;
} static int at91_keyled_probe(struct platform_device *pdev)
{
int res;
keyled_priv_t *priv; printk(KERN_INFO "at91_keyled driver probe\n"); if( != of_gpio_count(pdev->dev.of_node) )
{
printk(KERN_ERR "keyled pins definition in dts invalid\n");
return -EINVAL;
} priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if(!priv)
return -ENOMEM; platform_set_drvdata(pdev, priv); priv->pin_key=of_get_gpio(pdev->dev.of_node, );
priv->pin_led=of_get_gpio(pdev->dev.of_node, ); if( gpio_is_valid(priv->pin_key) )
{
if( (res=devm_gpio_request(&pdev->dev, priv->pin_key, "keyled_key")) < )
{
dev_err(&pdev->dev, "can't request key gpio %d\n", priv->pin_key);
return res;
}
dev_info(&pdev->dev, "request key gpio %d ok\n", priv->pin_key); if( (res=gpio_direction_input(priv->pin_key)) < )
{
dev_err(&pdev->dev, "can't request input direction key gpio %d\n", priv->pin_key);
return res;
}
dev_info(&pdev->dev, "request input direction key gpio %d ok\n", priv->pin_key); printk(KERN_INFO "Key gpio current status: %d\n", gpio_get_value(priv->pin_key)); res = request_irq( gpio_to_irq(priv->pin_key), key_detect_interrupt, IRQF_TRIGGER_FALLING, "keyled", priv);
if( res )
{
dev_err(&pdev->dev, "can't request IRQ<%d> for key gpio %d\n", gpio_to_irq(priv->pin_key), priv->pin_key);
return -EBUSY;
}
dev_info(&pdev->dev, "request IRQ<%d> for key gpio %d ok\n", gpio_to_irq(priv->pin_key), priv->pin_key);
} if( gpio_is_valid(priv->pin_led) )
{
if( (res=devm_gpio_request(&pdev->dev, priv->pin_led, "keyled_led")) < )
{
dev_err(&pdev->dev, "can't request key gpio %d\n", priv->pin_led);
return res;
} if( (res=gpio_direction_output(priv->pin_led, )) < )
{
dev_err(&pdev->dev, "can't request output direction key gpio %d\n", priv->pin_led);
return res;
}
} return ;
} static int at91_keyled_remove(struct platform_device *pdev)
{
keyled_priv_t *priv = platform_get_drvdata(pdev); printk(KERN_INFO "at91_keyled driver remove\n"); devm_gpio_free(&pdev->dev, priv->pin_led);
devm_gpio_free(&pdev->dev, priv->pin_key); free_irq(gpio_to_irq(priv->pin_key), priv); devm_kfree(&pdev->dev, priv); return ;
} static struct platform_driver at91_keyled_driver = {
.probe = at91_keyled_probe,
.remove = at91_keyled_remove,
.driver = {
.name = "key-leds",
.of_match_table = of_key_leds_match,
},
}; module_platform_driver(at91_keyled_driver); MODULE_AUTHOR("guowenxue <guowenxue@gmail.com>");
MODULE_DESCRIPTION("AT91 Linux DTS GPIO driver for Key and LED");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:key-leds");
at91sam9x5 linux 4.1.0下dts驱动编程模型的更多相关文章
- at91sam9x5 linux 4.1.0下使能蜂鸣器驱动
测试环境: CPU: AT91SAM9X35 Linux: Atmel提供的linux-at91-linux4sam_5.3 (Linux-4.1.0) 转载请注明: 凌云物网智科嵌入式实 ...
- 【Linux】CentOS7.0下安装JDK环境
写在前面:此次试验是在CentOS7上面安装的,亲测成功. 所需工具:JDK1.8安装包,xftp 具体步骤: 1,首先使用xftp连接到自己的虚拟机,然后查看是否有"/usr/java/j ...
- Windows平台VC++ 6.0 下的网络编程学习 - 简单的测试winsock.h头文件
最近学习数据结构和算法学得有点累了(貌似也没那么累...)...找了本网络编程翻了翻当做打一个小基础吧,打算一边继续学习数据结构一边也看看网络编程相关的... 简单的第一次尝试,就大致梳理一下看书+自 ...
- SpringCloud的应用发布(二)vmvare+linux,Centos7.0下发布应用
一.运行环境 1.jdk下载安装 地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html 检查是否有老版本jdk 如 ...
- 【Tomcat】CentOS7.0下安装多个Tomcat及其配置
安装前所需环境 在开始安装Tomcat之前,需要安装环境JDK,并配置JAVA环境.如果不知道如何配置,可参考这篇博客:[Linux]CentOS7.0下安装JDK环境 Tomcat安装 Tomcat ...
- 梦织未来Windows驱动编程 第03课 驱动的编程规范
最近根据梦织未来论坛的驱动教程学习了一下Windows下的驱动编程,做个笔记备忘.这是第03课<驱动的编程规范>. 驱动部分包括基本的驱动卸载函数.驱动打开关闭读取写入操作最简单的分发例程 ...
- linux下无线鼠标驱动执行流程
操作系统: debian 7.4(linux 3.2.54) 硬件: 一个无线鼠标.一个有线鼠标.usb集线器. 从淘宝上花了15块钱买了个无线鼠标,很好奇它的驱动程序是如何执行的. 首先将usb集线 ...
- 很好的linux下GPIO驱动详解文章
原文地址 http://blog.csdn.net/llxmedici/article/details/6282372 打算跟着友善之臂的<mini2440 linux移植开发指南>来做 ...
- linux下I2C驱动架构全面分析【转】
本文转载自:http://blog.csdn.net/wangpengqi/article/details/17711165 I2C 概述 I2C是philips提出的外设总线. I2C只有两条线,一 ...
随机推荐
- 【HDU 3810】 Magina (01背包,优先队列优化,并查集)
Magina Problem Description Magina, also known as Anti-Mage, is a very cool hero in DotA (Defense of ...
- 使用eclipse开发webService很简单
原文转自:http://blog.csdn.net/guo_rui22/article/details/6253745 使用Eclipse生成一个WebService应用 1.创建一个Dynamic ...
- 李洪强漫谈iOS开发[C语言-031]-逻辑短路
- [topcoder]ActivateGame
http://community.topcoder.com/stat?c=problem_statement&pm=10750&rd=14153 http://apps.topcode ...
- [转贴]一个将表格变成 INSERT 的SQL 语句的存储过程(sql server)
来源自http://vyaskn.tripod.com/code.htm#inserts SET NOCOUNT ON GO PRINT 'Using Master database' USE mas ...
- Maven 的安装配置
Maven 的安装配置 一.在安装 Maven 之前,先确保JDK1.7及以上版本并且配置好环境变量. 二.下载maven的bin,在apache官方网站可以下载. 1.首先去官网下载 Maven:h ...
- 转:三十二、Java图形化界面设计——布局管理器之CardLayout(卡片布局)
转:http://blog.csdn.net/liujun13579/article/details/7773945 卡片布局能够让多个组件共享同一个显示空间,共享空间的组件之间的关系就像一叠牌,组件 ...
- 【HDOJ】1166 敌兵布阵
线段树. #include <stdio.h> #define maxn 55555 ]; void PushUP(int rt) { sums[rt] = sums[rt<< ...
- 如何在windows系统自带命令查看硬件信息?
如何在windows系统自带命令查看硬件信息? 对于在windows下查看系统信息大家一定不陌生了,我现在说几个最常用的方法,对命令感兴趣的朋友看看,(给菜鸟看的,老手就不要笑话我了,大家都是从那个时 ...
- Android开发学习笔记:浅谈WebView
本文转自:http://www.2cto.com/kf/201108/101518.html WebView(网络视图)能加载显示网页,可以将其视为一个浏览器.它使用了WebKit渲染引擎加载显示网页 ...