1. 驱动框架

pinctrl子系统+gpio子系统+设备树+platform总线。
pinctrl子系统重点在设置引脚复用,gpio子系统用于初始化引脚。
Linxu提供总线-设备-驱动模型,用于将驱动分离与分成,提高代码复用性。
总线:内核提供
设备:设备树完成
驱动:驱动工程师完成

2. 框架源码

/* dts设备树 */
/ {# gpio节点leds {compatible = "gpio-leds";pinctrl-names = "default";status = "okay";pinctrl-0 = <&pinctrl_gpio_led>;
}&iomuxc {# pinctrl节点pinctrl_gpio_led: gpioledgrp {}
}
/* led_driver.c */
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/ide.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/gpio.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/of_gpio.h>
#include <linux/semaphore.h>
#include <linux/timer.h>
#include <linux/irq.h>
#include <linux/wait.h>
#include <linux/poll.h>
#include <linux/fs.h>
#include <linux/fcntl.h>
#include <linux/platform_device.h>static int led_open(struct inode *inode, struct file *filp)
{return 0;
}static ssize_t led_write(struct file *filp, const char __user *buf, size_t cnt, loff_t *offt)
{return 0;
}static struct file_operations led_fops = {.owner = THIS_MODULE,.open = led_open,.write = led_write,
};static int led_probe(struct platform_device *dev)
{printk("***led_probe***\r\n");return 0;
}static int led_remove(struct platform_device *dev)
{printk("***led_remove***\r\n");return 0;
}static const struct of_device_id led_of_match[] = {{ .compatible = "gpio-leds" },{ /* Sentinel */ }
};static struct platform_driver led_driver = {.driver         = {.name   = "my-leds", /* /sys/bus/platform/devices/my-leds */                .of_match_table = led_of_match, },.probe          = led_probe,.remove         = led_remove,
};static int __init led_init(void)
{printk("***led_init***\r\n");return platform_driver_register(&led_driver);
}
module_init(led_init);static void __exit led_exit(void)
{printk("***led_exit***\r\n");platform_driver_unregister(&led_driver);
}
module_exit(led_exit);MODULE_LICENSE("GPL");
MODULE_AUTHOR("lljwork2021@163.com");

3. 验证

当设备树中compatible属性与led_of_match中的compatible属性匹配时,就会调用led_probe函数。

# insmod led_driver.ko
[  752.844068] ***led_init***
[  752.847292] ***led_probe***
# ls /sys/bus/platform/devices/
leds
# ls /sys/bus/platform/devices/
my-leds
# rmmod led_driver.ko
[  755.040587] ***led_exit***
[  755.043427] ***led_remove***

LINUX驱动开发(二)GPIO驱动框架相关推荐

  1. Linux嵌入式驱动开发07——GPIO驱动过程记录(飞凌开发板)

    文章目录 全系列传送门 1. 在/arch/arm/boot/dts/imx6q-pinfunc.h查找 2. 在设备树配置文件中添加设备节点定义以及其引脚定义 3. 修改设备树文件添加配置 4. d ...

  2. <Linux开发>驱动开发 -之-platform 驱动

    <Linux开发>驱动开发 -之-platform 驱动 交叉编译环境搭建: <Linux开发> linux开发工具-之-交叉编译环境搭建 uboot移植可参考以下: < ...

  3. <Linux开发>--驱动开发-- 字符设备驱动(3) 过程详细记录

    <Linux开发>–驱动开发-- 字符设备驱动(3) 过程详细记录 驱动开发是建立再系统之上的,前面作者也记录了系统移植的过程记录,如果有兴趣,可进入博主的主页查看相关文章,这里就不添加链 ...

  4. Linux驱动开发—内核I2C驱动详解

    Linux驱动开发--内核I2C驱动 I2C驱动文件结构 I2C数据传输过程 i2c_transfer i2c_msg I2C通讯常用的接口函数(老版本) 快速读写接口函数:(连续读写) 常用的读操作 ...

  5. 基于MTD的NAND驱动开发(二)

    基于MTD的NAND驱动开发(二) 基于MTD的NAND驱动开发(三) http://blog.csdn.net/leibniz_zsu/article/details/4977853 http:// ...

  6. Linux 设备驱动开发 —— platform设备驱动应用实例解析

    前面我们已经学习了platform设备的理论知识Linux 设备驱动开发 -- platform 设备驱动 ,下面将通过一个实例来深入我们的学习. 一.platform 驱动的工作过程 platfor ...

  7. Linux驱动开发1:驱动开发与裸机开发的区别

    Linux驱动开发1:驱动开发与裸机开发的区别 1.裸机驱动开发回顾: 裸机驱动开发是非常底层的,跟寄存器打交道,有些MCU为了方便我们开发,提供了一些库,让我们通过调用API函数来间接的实现利用寄存 ...

  8. STM32MP157驱动开发——platform设备驱动(中)

    STM32MP157驱动开发--platform设备驱动(中) 0.前言 一.platform设备模块--设备信息解析 二.platform驱动模块--加载设备 三.测试App 四.编译及运行 相关文 ...

  9. STM32MP157驱动开发——蜂鸣器设备驱动

    STM32MP157驱动开发--蜂鸣器设备驱动 0.相关知识 一.驱动程序开发 1.设备树修改 2.启动程序编写 3.测试程序编写 二.编译及运行测试 0.相关知识   蜂鸣器常用于计算机.打印机.报 ...

最新文章

  1. 为什么铺天盖地都是Python的广告?
  2. 索引初识一 MySql
  3. Xilinx FFT IP core V9.0的介绍和使用
  4. wxPython多线程界面卡死或在不同平台崩溃问题
  5. SAP移动类型详细说明
  6. IDEA的maven项目报错BeanCreationException: Error creating bean with name “xxxController”
  7. 【译】探索更轻量的Electron替代品来托管Blazor桌面应用程序
  8. jsonp react 获取返回值_必须要会的 50 个React 面试题(下)
  9. java redis rpush_Redis Rpush 命令
  10. asp.net 移除Server, X-Powered-By, 和X-AspNet-Version头
  11. 把执行结果转成json对象报错_给Hangfire的webjob增加callback和动态判断返回结果功能设计...
  12. PAT 1059 Prime Factors[难]
  13. C语言编程学习gotoxy()与clrscr()函数
  14. GBase 8c 备份控制函数(四)
  15. 如何使用手机通过校园无线网在知网免费下载论文
  16. taylor+swift纽约公寓_Taylor Swift $1,800 万美元的纽约豪宅到底豪在哪里?
  17. Oliver的救援【BFS】
  18. Java的故事(猫与老鼠)
  19. HTML5 代码规范
  20. 我们这一代人的困惑 --转自于宙TEDx大会上的演讲

热门文章

  1. 任何实践都是理论的载体和表现形式(转)
  2. 广东深圳形位公差检测服务CAV比对服务异形件三维尺寸测量-CASAIM
  3. creator打包微信小游戏笔记
  4. 中国自行车十强企业FRW辐轮王国内外十大最著名自行车品牌排行榜
  5. 力扣-生成每种字符都是奇数个的字符串
  6. js正则验证不能有中文和空格
  7. 奖品免费送,为什么用户激励还是不起作用?
  8. C# log4net将日志写入sql server,winform项目
  9. JS递归函数return返回undefined
  10. JSTL标签循环集合列表