#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. python str、int、dict

    一.str print(dir(int))#['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', ...

  2. 讲座: conversation

    一, Zhouming MSRA NLP group NLP 2.0 attention model 二,Yan Rui 一, retrived based-conversation system t ...

  3. Object中的clone方法

      Java中对象的创建 clone顾名思义就是复制, 在Java语言中, clone方法被对象调用,所以会复制对象.所谓的复制对象,首先要分配一个和源对象同样大小的空间,在这个空间中创建一个新的对象 ...

  4. file中mkdirs和mkdir的区别-文件上传

    mkdirs()可以建立多级文件夹, mkdir()只会建立一级的文件夹, 如下: new File("/tmp/one/two/three").mkdirs(); 执行后, 会建 ...

  5. day01-struts框架

    一.框架概述 1.框架的意义与作用: 所谓框架,就是把一些繁琐的重复性代码封装起来,使程序员在编码中把更多的经历放到业务需求的分析和理解上面. 特点:封装了很多细节,程序员在使用的时候会非常简单. 2 ...

  6. ZooKeeper 典型应用场景-负载均衡

    负载均衡(Load Balance)是一种相当常见的计算机网络技术,用来对多个计算机(计算机集群).网络连接.CPU.硬盘驱动器或其他资源进行分配负载,以达到优化资源使用.最大化吞吐率.最小化响应时间 ...

  7. June 16th 2017 Week 24th Friday

    Progress is the activity of today and the assurance of tomorrow. 进步是今天的活动,明天的保证. The best preparatio ...

  8. 数据结构与算法分析java——线性表3 (LinkedList)

    1. LinkedList简介 LinkedList 是一个继承于AbstractSequentialList的双向链表.它也可以被当作堆栈.队列或双端队列进行操作.LinkedList 实现 Lis ...

  9. CF25E Test

    嘟嘟嘟 因为只有三个字符串,所以就有一个比较暴力的做法:枚举这三个串所有排列,然后对于每一个排列,减去这三个串两两的公共部分的长度,更新答案. 求公共部分自然想到kmp:比如s[1]接在s[0]后面, ...

  10. 2018.10.30 mac环境下卸载和安装mysql及安装过程遇到的一些问题解决方案

    Mac下mysql的安装与卸载 配置初始化密码修改 第一:首先去官网网站下载Mysql软件 https://downloads.mysql.com/archives/community/ 记住选择对应 ...