linux2.6中的platform和of_platform机制B

A  platform机制
platform_driver_register,什么时候调用PROBE函数 注册后如何找到驱动匹配的设备
platform_driver_register(struct platform_driver *drv)注册后如何找到驱动匹配的设备

struct platform_driver {
        int (*probe)(struct platform_device *);
        int (*remove)(struct platform_device *);
        void (*shutdown)(struct platform_device *);
        int (*suspend)(struct platform_device *, pm_message_t state);
        int (*suspend_late)(struct platform_device *, pm_message_t state);
        int (*resume_early)(struct platform_device *);
        int (*resume)(struct platform_device *);
        struct device_driver driver;
};

BUS首先初始化总线   do_basic_setup()->driver_init()->platform_bus_init()->...初始化platform_bus_type(虚拟总线)

DEVICE生成有2种方法

1 用函数platform_device_register()直接注册一个platform_device设备 

   设备向内核注册的时候platform_device_register()->platform_device_add()->...内核把设备挂在虚拟的platform bus下
 platform_device_register(&physmap_flash); /*这是一个flash驱动例子*/

2 从dts文件中读出来形成一个platform_device设备

   用下面的函数_init gfar_of_init(void) 读取dts文件获得platform_device结构体 /*这是一个mac驱动的例子*/
struct platform_device {
 const char * name;
 u32  id;
 struct device dev;
 u32  num_resources;
 struct resource * resource;
};

读取的是下面dts里面的结构
ethernet@24000 {
   #address-cells = <0x1>;
   #size-cells = <0x0>;
   device_type = "network";
   model = "eTSEC";
   compatible = "gianfar";
   reg = <0x24000 0x1000>;
   local-mac-address = [00 00 00 00 00 00];
   interrupts = <0x1d 0x2 0x1e 0x2 0x22 0x2>;
   interrupt-parent = <0x1>;
   phy-handle = <0x2>;
   phy-connection-type = "sgmii";
  };

DRIVER驱动注册的时候 platform_driver_register()->driver_register()->bus_add_driver()->driver_attach()->bus_for_each_dev() 对每个挂在虚拟的platform bus的设备作

__driver_attach()->driver_probe_device()->drv->bus->match() 就是下面的platform_match比较strncmp(pdev->name, drv->name, BUS_ID_SIZE),如果相符就调用platform_drv_probe()->driver->probe(),如果probe成功则绑定该设备到该驱动.

static int platform_match(struct device * dev, struct device_driver * drv)
{
 struct
platform_device *pdev = container_of(dev, struct platform_device, dev);

 return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0);
}


当最后匹配后就调用platform_drv_probe()->driver->probe() 进入驱动的probe()。

 

 

B   of_platform机制

struct of_platform_driver
{
 const char  *name;
 const struct
of_device_id *match_table;
 struct module  *owner;

 int (*probe)(struct of_device* dev,
    const struct of_device_id *match);
 int (*remove)(struct of_device* dev);

 int (*suspend)(struct of_device* dev, pm_message_t state);
 int (*resume)(struct of_device* dev);
 int (*shutdown)(struct of_device* dev);

 struct device_driver driver;
};

struct of_device_id
{
 char name[32];
 char type[32];
 char compatible[128];
#ifdef __KERNEL__
 void *data;
#else
 kernel_ulong_t data;
#endif
};


BUS首先初始化总线   do_basic_setup()->driver_init()->platform_bus_init()->...初始化of_platform_bus_type(虚拟总线)

DEVICE设备生成用下面的函数mpc8572_register_mtd(void)读取dts文件 获得device_node结构
struct
device_node {
 const char *name;
 const char *type;
 phandle node;
 phandle linux_phandle;
 char *full_name;

 struct property *properties;
 struct  property *deadprops; /* removed properties */
 struct device_node *parent;
 struct device_node *child;
 struct device_node *sibling;
 struct device_node *next; /* next device of same type */
 struct device_node *allnext; /* next in list of all nodes */
 struct  proc_dir_entry *pde; /* this node's proc directory */
 struct  kref kref;
 unsigned long _flags;
 void *data;
};

读取的是下面dts里面的结构
nor@ef800000 {
  device_type = "rom";
  compatible = "direct-mapped";
  reg = <0xef800000 0x800000>;
  probe-type = "CFI";
  bank-width = <0x1>;
  partitions = <0x0 0x400000 0x400000 0x8001 0x408000 0x300001 0x708000 0x78001 0x780000 0x80001>;
  partition-names = "JFFS2(RW)", "DTB(RO)", "Linux Kernel(RO)", "Parameters(RO)", "U-BOOT(RO)";
 };


DRIVER驱动注册的时候 platform_driver_register()->driver_register()->bus_add_driver()->driver_attach()->bus_for_each_dev() 对每个挂在虚拟的platform bus的设备作 __driver_attach()->driver_probe_device()->drv->bus->match(), 就是下面的of_platform_bus_match,如果相符就调用 platform_drv_probe()->driver->probe()。

.最终比较的是of_platform_driver.match_table里面的那么,type,compatible与device_node里面的name,type,compatible

static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
{
 struct of_device *of_dev = to_of_device(dev);
 struct of_platform_driver *of_drv = to_of_platform_driver(drv);
 const struct of_device_id *matches = of_drv->match_table;

 if (!matches)
  return 0;

 return of_match_device(matches, of_dev) != NULL;
}

const struct of_device_id *of_match_device(const struct of_device_id *matches,
     const struct of_device *dev)
{
 if (!dev->node)
  return NULL;
 return of_match_node(matches, dev->node);
}

const struct of_device_id *of_match_node(const struct of_device_id *matches,
      const struct device_node *node)
{
 while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
  int match = 1;
  if (matches->name[0])
   match &= node->name
    && !strcmp(matches->name, node->name);
  if (matches->type[0])
   match &= node->type
    && !strcmp(matches->type, node->type);
  if (matches->compatible[0])
   match &= of_device_is_compatible(node,
      matches->compatible);
  if (match)
   return matches;
  matches++;
 }
 return NULL;
}

当最后匹配后就调用platform_drv_probe()->driver->probe() 进入驱动的probe()。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
探索全栈前端技术的魅力:HTML+CSS+JS+JQ+Bootstrap网站源码深度解析 在这个数字化时代,构建一个既美观又功能强大的网站成为了许多开发者和企业追逐的目标。本份资源精心汇集了一套完整网站源码,融合了HTML的骨架搭建、CSS的视觉美化、JavaScript的交互逻辑、jQuery的高效操作以及Bootstrap的响应式设计,全方位揭秘了现代网页开发的精髓。 HTML,作为网页的基础,它构建了信息的框架;CSS则赋予网页生动的外观,让设计创意跃然屏上;JavaScript的加入,使网站拥有了灵动的交互体验;jQuery,作为JavaScript的强力辅助,简化了DOM操作与事件处理,让编码更为高效;而Bootstrap的融入,则确保了网站在不同设备上的完美呈现,响应式设计让访问无界限。 通过这份源码,你将: 学习如何高效组织HTML结构,提升页面加载速度与SEO友好度; 掌握CSS高级技巧,如Flexbox与Grid布局,打造适应各种屏幕的视觉盛宴; 理解JavaScript核心概念,动手实现动画、表单验证等动态效果; 利用jQuery插件快速增强用户体验,实现滑动效果、Ajax请求等; 深入Bootstrap框架,掌握移动优先的开发策略,响应式设计信手拈来。 无论是前端开发新手渴望系统学习,还是资深开发者寻求灵感与实用技巧,这份资源都是不可多得的宝藏。立即深入了解,开启你的全栈前端探索之旅,让每一个网页都成为技术与艺术的完美融合!
探索全栈前端技术的魅力:HTML+CSS+JS+JQ+Bootstrap网站源码深度解析 在这个数字化时代,构建一个既美观又功能强大的网站成为了许多开发者和企业追逐的目标。本份资源精心汇集了一套完整网站源码,融合了HTML的骨架搭建、CSS的视觉美化、JavaScript的交互逻辑、jQuery的高效操作以及Bootstrap的响应式设计,全方位揭秘了现代网页开发的精髓。 HTML,作为网页的基础,它构建了信息的框架;CSS则赋予网页生动的外观,让设计创意跃然屏上;JavaScript的加入,使网站拥有了灵动的交互体验;jQuery,作为JavaScript的强力辅助,简化了DOM操作与事件处理,让编码更为高效;而Bootstrap的融入,则确保了网站在不同设备上的完美呈现,响应式设计让访问无界限。 通过这份源码,你将: 学习如何高效组织HTML结构,提升页面加载速度与SEO友好度; 掌握CSS高级技巧,如Flexbox与Grid布局,打造适应各种屏幕的视觉盛宴; 理解JavaScript核心概念,动手实现动画、表单验证等动态效果; 利用jQuery插件快速增强用户体验,实现滑动效果、Ajax请求等; 深入Bootstrap框架,掌握移动优先的开发策略,响应式设计信手拈来。 无论是前端开发新手渴望系统学习,还是资深开发者寻求灵感与实用技巧,这份资源都是不可多得的宝藏。立即深入了解,开启你的全栈前端探索之旅,让每一个网页都成为技术与艺术的完美融合!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值