#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <asm/io.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/bitmap.h>
#include <asm/gpio.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/sched.h>
#include <linux/of.h> static volatile unsigned long *ledcon;
static volatile unsigned long *leddat;
static struct class *led_class;
static unsigned int pin_th;
dev_t led_dev;
struct cdev *cdev; /* 打开led灯 */
static int led_open(struct inode *inode, struct file *file)
{
*ledcon &= ~(0x3 << (pin_th * ));
*ledcon |= (0x1 << (pin_th * ));
*leddat &= ~( << pin_th);
return ;
} static struct file_operations led_fops = {
.owner = THIS_MODULE,
.open = led_open,
}; static int led_probe(struct platform_device *pdev)
{
int pin_info;
int phy_addr;
int io_base;
of_property_read_s32(pdev->dev.of_node, "pin", &pin_info);
printk("pin_info = 0x%x\n", pin_info);
of_property_read_s32(pdev->dev.of_node, "iobase", &io_base);
printk("io_base = 0x%x\n", io_base);
pin_th = pin_info & (0xffff);
phy_addr = (io_base | ((pin_info>>)<<));
ledcon = ioremap(phy_addr, );
leddat = ledcon + ; if (alloc_chrdev_region(&led_dev, MINOR(led_dev), , "led"))
return -;
cdev = cdev_alloc();
if (!cdev)
return -;
cdev_init(cdev, &led_fops);
cdev_add(cdev, led_dev, ); led_class = class_create(THIS_MODULE, "led");
device_create(led_class,NULL,led_dev,NULL,"led0"); // is /dev/led0 return ; } int led_remove(struct platform_device *pdev)
{
device_destroy(led_class, led_dev);
class_destroy(led_class);
cdev_del(cdev);
unregister_chrdev_region(led_dev, );
iounmap(ledcon);
return ;
} static struct of_device_id led_id[] = {
{.compatible = "jz2440_led"},
{},
}; static struct platform_driver led_drv = {
.probe = led_probe,
.remove = led_remove,
.driver = {
.name = "jz2440_led",
.of_match_table = led_id,
},
}; static int led_init(void)
{
platform_driver_register(&led_drv);
return ;
} static void led_exit(void)
{
platform_driver_unregister(&led_drv);
} module_init(led_init);
module_exit(led_exit); MODULE_LICENSE("GPL");

以上是驱动程序,下面是设备树dts文件:

 #define S3C2440_GPA(_nr)    ((0<<16) + (_nr))
#define S3C2440_GPB(_nr) ((1<<16) + (_nr))
#define S3C2440_GPC(_nr) ((2<<16) + (_nr))
#define S3C2440_GPD(_nr) ((3<<16) + (_nr))
#define S3C2440_GPE(_nr) ((4<<16) + (_nr))
#define S3C2440_GPF(_nr) ((5<<16) + (_nr))
#define S3C2440_GPG(_nr) ((6<<16) + (_nr))
#define S3C2440_GPH(_nr) ((7<<16) + (_nr))
#define S3C2440_GPJ(_nr) ((8<<16) + (_nr))
#define S3C2440_GPK(_nr) ((9<<16) + (_nr))
#define S3C2440_GPL(_nr) ((10<<16) + (_nr))
#define S3C2440_GPM(_nr) ((11<<16) + (_nr)) /dts-v1/; / {
model = "SMDK2440";
compatible = "samsung,smdk2440"; #address-cells = <>;
#size-cells = <>; memory@ {
device_type = "memory";
reg = <0x30000000 0x4000000>;
};

chosen {
bootargs = "noinitrd root=/dev/mtdblock4 rw init=/linuxrc console=ttySAC0,115200";
}; led {
compatible = "jz2440_led";
pin = <S3C2440_GPF()>;
iobase = <0x56000000>;
};
};

基于设备树的led驱动程序的更多相关文章

  1. 基于设备树的controller学习(2)

    作者 彭东林 pengdonglin137@163.com 平台 TQ2440 Linux-4.10.17 概述 上一篇大概介绍了一下demo-controller的结构,下面结合驱动分析.   正文 ...

  2. 基于设备树的TQ2440触摸屏驱动移植

    平台 开发板:tq2440 内核:Linux-4.9 u-boot:u-boot-2015.04   概述 之前移植了LCD驱动,下面继续移植触摸屏驱动,然后将tslib也移植上去. 正文 一.移植触 ...

  3. 基于设备树的TQ2440的中断(2)

    下面以按键中断为例看看基于设备数的中断的用法: 设备树: tq2440_key { compatible = "tq2440,key"; interrupt-parent = &l ...

  4. 基于设备树的controller学习(1)

    作者 彭东林pengdonglin137@163.com 平台 TQ2440Linux-4.10.17 概述 在设备树中我们经常见到诸如"#clock-cells"."# ...

  5. 基于设备树的TQ2440的中断(1)

    作者 姓名:彭东林 E-mail:pengdonglin137@163.com QQ:405728433 平台 板子:TQ2440 内核:Linux-4.9 u-boot: 2015.04 工具链: ...

  6. 芯灵思Sinlinx A64 linux 通过设备树写LED驱动(附参考代码,未测试)

    开发平台 芯灵思Sinlinx A64 内存: 1GB 存储: 4GB 详细参数 https://m.tb.cn/h.3wMaSKm 开发板交流群 641395230 全志A64设备树结构体 #inc ...

  7. 基于设备树的TQ2440 DMA学习(3)—— DMA控制器驱动

    作者 彭东林pengdonglin137@163.com 平台 TQ2440Linux-4.9 概述 上一篇直接操作DMA控制器实现了一个mem2mem的DMA传输,但是这样不符合linux driv ...

  8. 基于设备树的TQ2440 DMA学习(4)—— client驱动

    作者 彭东林pengdonglin137@163.com 平台 TQ2440Linux-4.9 概述 前面分析了DMA控制器驱动,下面我们调用DMAENGINE的API写一个MEM2MEM的驱动 正文 ...

  9. 基于设备树的TQ2440 DMA学习(2)—— 简单的DMA传输

    作者 彭东林 pengdonglin137@163.com   平台 TQ2440 Linux-4.9   概述 上一篇博客分析了DMA控制器的寄存器,循序渐进,下面我们直接操作DMA控制器的寄存器实 ...

随机推荐

  1. SQLite入门操作(一)

    //++其他的头文件 #include "sqlite3.h" #pragma comment(lib,"sqlite3.lib") int GetItemCo ...

  2. 在科技圈不懂“机器学习”?那你就out了

    当联网的终端设备越来越多时,产生的信息数据也将呈指数式增长,大型.复杂.增长快速的数据收集已经无处不在.而机器学习能够扩增这些数据的价值,并基于这些趋势提出更广泛的应用情境. 那么,被人们津津乐道的机 ...

  3. htmlunit模拟登录

    htmlunit jar项目路径http://sourceforge.net/projects/htmlunit/files/htmlunit/ demo代码如下 public class AutoL ...

  4. /etc/hosts.allow和/etc/hosts.deny详解

    今天遇到一台服务器22端口正常,但是通过ssh连接的问题.排查了防火墙和端口问题,半天没有找出来原因,后来求助大神,终于明白了通过etc目录下hosts.deny和hosts.allow文件可以限制远 ...

  5. HDU 1575 Tr A 【矩阵经典2 矩阵快速幂入门】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1575 Tr A Time Limit: 1000/1000 MS (Java/Others)    Me ...

  6. 腾讯2016校招编程题【PHP实现】

    2016腾讯春招的编程题 话不多说,直接上题!!! 给定一个字符串s,你可以从中删除一些字符,使得剩下的串是一个回文串.如何删除才能使得回文串最长呢?输出需要删除的字符个数 . 这道题是以回文为载体, ...

  7. Python-Url编码和解码

    一.为什么要进行Url编码 url带参数的请求格式为(举例): http://www.baidu.com/s?k1=v1&k2=v2 当请求数据为字典data = {k1:v1, k2:v2} ...

  8. MYSQL5.7.15安装步骤

    下载完成之后双击安装: 接下来一路next (出现的问题) 在我第一次安装myslq过程中,上图中的mysql server failed ,这是因为电脑环境需要升级一个插件,Visual C++ 2 ...

  9. Openresty最佳案例 | 第8篇:RBAC介绍、sql和redis模块工具类

    转载请标明出处: http://blog.csdn.net/forezp/article/details/78616738 本文出自方志朋的博客 RBAC介绍 RBAC(Role-Based Acce ...

  10. SpringBoot非官方教程 | 第二篇:Spring Boot配置文件详解

    转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springboot2-config-file/ 本文出自方志朋的博客 ...