一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

linux2.6中的platform和of_platform機(jī)制B

 langhuayipian 2011-02-14

A  platform機(jī)制
platform_driver_register,什么時候調(diào)用PROBE函數(shù) 注冊后如何找到驅(qū)動匹配的設(shè)備
platform_driver_register(struct platform_driver *drv)注冊后如何找到驅(qū)動匹配的設(shè)備

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 用函數(shù)platform_device_register()直接注冊一個platform_device設(shè)備 

2 從dts文件中讀出來形成一個platform_device設(shè)備
1   設(shè)備向內(nèi)核注冊的時候platform_device_register()->platform_device_add()->...內(nèi)核把設(shè)備掛在虛擬的platform bus下
 platform_device_register(&physmap_flash); /*這是一個flash驅(qū)動例子*/

2   用下面的函數(shù)_init gfar_of_init(void) 讀取dts文件獲得platform_device結(jié)構(gòu)體 /*這是一個mac驅(qū)動的例子*/
struct platform_device {
 const char * name;
 u32  id;
 struct device dev;
 u32  num_resources;
 struct resource * resource;
};

讀取的是下面dts里面的結(jié)構(gòu)
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";
  };


static int __init gfar_of_init(void)  /*在fsl_soc.c文件下的*/
{
 struct device_node *np;
 unsigned int i;
 struct platform_device *gfar_dev;
 struct resource res;
 int ret;

 for (np = NULL, i = 0;
      (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
      i++) {
  struct resource r[4];
  struct device_node *phy, *mdio;
  struct gianfar_platform_data gfar_data;
  const unsigned int *id;
  const char *model;
  const char *ctype;
  const void *mac_addr;
  const phandle *ph;
  int n_res = 2;

  memset(r, 0, sizeof(r));
  memset(&gfar_data, 0, sizeof(gfar_data));

  ret = of_address_to_resource(np, 0, &r[0]);
  if (ret)
   goto err;

  of_irq_to_resource(np, 0, &r[1]);

  model = of_get_property(np, "model", NULL);

  /* If we aren't the FEC we have multiple interrupts */
  if (model && strcasecmp(model, "FEC")) {
   r[1].name = gfar_tx_intr;

   r[2].name = gfar_rx_intr;
   of_irq_to_resource(np, 1, &r[2]);

   r[3].name = gfar_err_intr;
   of_irq_to_resource(np, 2, &r[3]);

   n_res += 2;
  }

  gfar_dev =
      platform_device_register_simple("fsl-gianfar", i, &r[0],
          n_res);

 ..........

  ret =
      platform_device_add_data(gfar_dev, &gfar_data,
          sizeof(struct
          gianfar_platform_data));
  if (ret)
   goto unreg;
 }


DRIVER驅(qū)動注冊的時候 platform_driver_register()->driver_register()->bus_add_driver()->driver_attach()->bus_for_each_dev() 對每個掛在虛擬的platform bus的設(shè)備作

__driver_attach()->driver_probe_device()->drv->bus->match() 就是下面的platform_match比較strncmp(pdev->name, drv->name, BUS_ID_SIZE),如果相符就調(diào)用platform_drv_probe()

->driver->probe(),如果probe成功則綁定該設(shè)備到該驅(qū)動.

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);
}


當(dāng)最后匹配后就調(diào)用platform_drv_probe()->driver->probe() 進(jìn)入驅(qū)動的probe()。

 

 

B   of_platform機(jī)制

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設(shè)備生成用下面的函數(shù)mpc8572_register_mtd(void)讀取dts文件 獲得device_node結(jié)構(gòu)
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里面的結(jié)構(gòu)
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)";
 };

static int __init mpc8572_register_mtd(void)  /*在mpc85xx_ds.c文件中*/
{
 struct device_node *np;

 np = of_find_compatible_node(NULL, "rom", "direct-mapped");
 if (np == NULL)
  return 0;

 of_platform_device_create(np, np->name, NULL);
 return 0;
}

DRIVER驅(qū)動注冊的時候 platform_driver_register()->driver_register()->bus_add_driver()->driver_attach()->bus_for_each_dev() 對每個掛在虛擬的platform bus的設(shè)備作 __driver_attach()->driver_probe_device()->drv->bus->match(), 就是下面的of_platform_bus_match,如果相符就調(diào)用 platform_drv_probe()->driver->probe()。

.最終比較的是of_platform_driver.match_table與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;
}

當(dāng)最后匹配后就調(diào)用platform_drv_probe()->driver->probe() 進(jìn)入驅(qū)動的probe()。

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多

    老司机精品视频免费入口| 91久久精品在这里色伊人| 老司机精品视频免费入口| 大香蕉久久精品一区二区字幕| 国产成人精品一区二区在线看| 日韩中文字幕欧美亚洲| 亚洲欧美日韩精品永久| 国产肥妇一区二区熟女精品| 国产欧美日本在线播放| 一级片二级片欧美日韩| 福利专区 久久精品午夜| 国产又粗又猛又长又黄视频| 久久精品福利在线观看| 欧美激情视频一区二区三区| 91日韩欧美在线视频| 国产精品免费视频专区| 欧美人禽色视频免费看| 日韩欧美91在线视频| 国产日韩熟女中文字幕| 国产精品一区二区三区黄色片| 在线一区二区免费的视频| 国产精品成人一区二区在线| 日韩欧美国产精品自拍| 欧美成人黄色一区二区三区| 激情爱爱一区二区三区| 中文字幕乱码免费人妻av| 国产欧美日韩精品自拍 | 亚洲伦理中文字幕在线观看| 日韩专区欧美中文字幕| 国产精品福利一级久久| 国产精品午夜小视频观看| 日韩精品少妇人妻一区二区| 亚洲视频一级二级三级| 欧美精品一区久久精品| 一区二区三区在线不卡免费| 国产在线观看不卡一区二区| 欧美尤物在线观看西比尔| 国产传媒欧美日韩成人精品| 国产中文另类天堂二区| 69精品一区二区蜜桃视频| 精品人妻一区二区三区免费看|