四、【GPIO驱动框架》设备device】

arch/arm/mach-omap2/gpio.c中

1、static int __init omap2_gpio_init(void)

{

returnomap_hwmod_for_each_by_class("gpio", omap2_gpio_dev_init,

NULL);

}

archarm/mach-omap2/omap_hwmod.c 中

2、int omap_hwmod_for_each_by_class(constchar *classname,

int (*fn)(struct omap_hwmod *oh,

void *user),

void *user)

{

structomap_hwmod *temp_oh;

intret = 0;

if(!classname || !fn)

return -EINVAL;

pr_debug("omap_hwmod:%s: looking for modules of class %s\n",

__func__, classname);

list_for_each_entry(temp_oh, &omap_hwmod_list, node){

if (!strcmp(temp_oh->class->name,classname)) {

pr_debug("omap_hwmod:%s: %s: calling callback fn\n",

__func__, temp_oh->name);

ret= (*fn)(temp_oh, user);

if(ret)

break;

}

}

if(ret)

pr_debug("omap_hwmod: %s: iteratorterminated early: %d\n",

__func__, ret);

returnret;

}

arch/arm/mach-omap2/gpio.c中

3、static int omap2_gpio_dev_init(struct omap_hwmod *oh, void*unused)

{

structomap_device *od;

structomap_gpio_platform_data *pdata;

structomap_gpio_dev_attr *dev_attr;

char*name = "omap_gpio";

intid;

/*

* extract the device id from name fieldavailable in the

* hwmod database and use the same forconstructing ids for

* gpio devices.

* CAUTION: Make sure the name in the hwmoddatabase does

* not change. If changed, make correspondingchange here

* or make use of static variable mechanism tohandle this.

*/

sscanf(oh->name,"gpio%d", &id);

/*以gpio4为例

*static struct omap_hwmod ti814x_gpio4_hwmod = {

*     .name             ="gpio4",

*所以id = 4

*/

pdata= kzalloc(sizeof(struct omap_gpio_platform_data), GFP_KERNEL);

if(!pdata) {

pr_err("gpio%d: Memory allocationfailed\n", id);

return -ENOMEM;

}

dev_attr= (struct omap_gpio_dev_attr *)oh->dev_attr;

pdata->bank_width= dev_attr->bank_width;

pdata->dbck_flag= dev_attr->dbck_flag;

pdata->virtual_irq_start= IH_GPIO_BASE + 32 * (id - 1);

switch(oh->class->rev) {

case0:

case1:

pdata->bank_type = METHOD_GPIO_24XX;

break;

case2:

pdata->bank_type = METHOD_GPIO_44XX;

break;

default:

WARN(1, "Invalid gpiobank_type\n");

kfree(pdata);

return -EINVAL;

}

od= omap_device_build(name, id - 1, oh, pdata,

sizeof(*pdata),       omap_gpio_latency,

ARRAY_SIZE(omap_gpio_latency),

false);

kfree(pdata);

if(IS_ERR(od)) {

WARN(1, "Cant build omap_device for%s:%s.\n",

name,oh->name);

return PTR_ERR(od);

}

gpio_bank_count++;

return0;

}

arch/arm/plat-omap/omap_device.c 中

4、struct omap_device *omap_device_build(const char *pdev_name, int pdev_id,

struct omap_hwmod *oh, void *pdata,

int pdata_len,

struct omap_device_pm_latency *pm_lats,

int pm_lats_cnt, int is_early_device)

{

structomap_hwmod *ohs[] = { oh };

if(!oh)

return ERR_PTR(-EINVAL);

returnomap_device_build_ss(pdev_name, pdev_id, ohs, 1,pdata,

pdata_len, pm_lats, pm_lats_cnt,

is_early_device);

}

5、struct omap_device *omap_device_build_ss(const char *pdev_name, int pdev_id,

struct omap_hwmod **ohs, int oh_cnt,

void *pdata, int pdata_len,

struct omap_device_pm_latency *pm_lats,

int pm_lats_cnt, int is_early_device)

{。。。。。。

struct omap_device *od;

struct resource *res = NULL;

。。。。。。

omap_device_fill_resources(od, res);

od->pdev.num_resources= res_count;

od->pdev.resource = res;

//将od->hwmods中的资源赋值给od->pdev.resource

。。。。。。

ret = omap_device_register(od);

//od->pdev.name = “omap_gpio”

//od->hwmods =&ti814x_gpio4_hwmod

。。。。。。

6、int omap_device_register(structomap_device *od)

{

pr_debug("omap_device:%s: registering\n", od->pdev.name);

od->pdev.dev.parent= &omap_device_parent;

returnplatform_device_register(&od->pdev);

}

====================================================================

linux驱动:TI+DM8127+GPIO(四)之设备相关推荐

  1. linux驱动开发篇(四)—— platform平台设备驱动

    linux系列目录: linux基础篇(一)--GCC和Makefile编译过程 linux基础篇(二)--静态和动态链接 ARM裸机篇(一)--i.MX6ULL介绍 ARM裸机篇(二)--i.MX6 ...

  2. Linux驱动编程 step-by-step (四) 字符设备的注册与设备节点的自动创建

    字符设备的注册与设备节点的自动创建 cdev 结构 内核内部使用struct cdev<linux/cdev.h>来表示一个字符设备 struct cdev {     struct ko ...

  3. 【嵌入式Linux】嵌入式Linux驱动开发基础知识之总线设备驱动模型

    文章目录 前言 1.驱动编写的三种方法 1.1.传统写法 1.2.总线驱动模型 1.3.设备树驱动模型 2.Linux实现分离:Bus/Dev/Drv模型 2.1.Bus/Dev/Drv模型 2.2. ...

  4. linux 驱动基础知识(2)---设备树

    转载自 http://huaqianlee.me/2015/08/19/Android/高通平台Android源码分析之Linux内核设备树-DT-Device-Tree-dts文件/ 刚开始接触An ...

  5. Linux驱动开发中的中间件:设备树

    Linux设备树 设备树的产生是为了解决内核源码的arch/arm目录下代码混乱和臃肿的问题(过去每个厂商出个板子就要提供外设硬件和平台硬件信息,这些信息以.c和.h文件的形式呈现).在使用设备树之后 ...

  6. 嵌入式Linux驱动笔记(二十四)------framebuffer之使用spi-tft屏幕(上)

    你好!这里是风筝的博客, 欢迎和我一起交流. 最近入手了一块spi接口的tft彩屏,想着在我的h3板子上使用framebuffer驱动起来. 我们知道: Linux抽象出FrameBuffer这个设备 ...

  7. linux驱动:TI+DM8127+GPIO(二)之驱动

    二.[GPIO驱动框架>驱动driver] 重要结构体 gpio_chip:管理一组GPIO gpio_desc:描述每个GPIO gpio_bank:封装了gpio_chip加入GPIO控制的 ...

  8. linux驱动:TI+DM8127+GPIO(五)之plarform

    五.[GPIO驱动框架>平台platform] (一)设备找驱动 1.drivers/base/platform.c中 int platform_device_register(structpl ...

  9. linux驱动:TI+DM8127+GPIO(三)之omap_hwmod中添加GPIO资源

    三.[GPIO驱动框架>向omap_hwmod中添加GPIO资源] ***将GPIO硬件信息添加到注册到omap_hwmod_list列表中 Arch/arm/plat-omap/include ...

最新文章

  1. ssd测试软件cy,目标检测实践_tensorflow版SSD模型测试
  2. wordpress模版post.php,WordPress主题开发手册
  3. NR 5G L1物理层
  4. MySQL 搜索指定时间范围数据, 时间字段有索引但是还是很费时
  5. CocosEditor 1.0Final-IDEA13.0和1.5-IDEA13.1 发布–2014.03.25
  6. 《疯狂java讲义》6
  7. 实践1-qq邮箱主页
  8. gprof 使用例程(转)
  9. winform在表格中输入一个完整的时间字段_【ArcGIS小技巧视频教程】(5):在ArcGIS中挂接其他数据...
  10. java垃圾回收到老年代次数,Java垃圾回收之回收算法
  11. 云计算odps使用笔记(一)环境搭建
  12. vb devcon获取u盘信息_iOS 13 U盘越狱法,卡代码及U盘终极解决
  13. (转载)SQL Server2008附加数据库之后显示为只读时解决方法
  14. 计算机网络上机指导,计算机网络上机指导书.pdf
  15. “最快3个月复制支付宝的核心能力” 解密蚂蚁金服bPaaS
  16. python中矩阵除法_Python numpy矩阵处理运算工具用法汇总
  17. 如何下载最新Windows10镜像文件(.iso文件)
  18. Java架构师面试十大连环炮
  19. linux返回根目录的命令
  20. android倒计时小工具,为五一放假倒计时《倒数日小工具》

热门文章

  1. Gmapping 乱七八糟
  2. C++中结构体与类的区别(struct与class的区别)
  3. ajax请求中的reponseType和withCredetials分别是啥?
  4. vue下轻松解决模拟微信视频缩略图拖拽→吸附窗口边界的功能
  5. Unity完全学习教程-从初学者到C#中的RPG游戏开发
  6. CSS、JavaScript、PHP和Python编程合二为一
  7. SUST_ACM_2019届暑期ACM集训热身赛题解
  8. C功底挑战Java菜鸟入门概念干货(一)
  9. 项目微管理29 - 转正
  10. 5793. 【NOIP2008模拟】小S练跑步