Chinaunix首页 | 论坛 | 博客
  • 博客访问: 149036
  • 博文数量: 17
  • 博客积分: 359
  • 博客等级: 一等列兵
  • 技术积分: 382
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-08 19:51
文章分类

全部博文(17)

文章存档

2012年(17)

我的朋友

分类: C/C++

2012-04-19 22:29:49


  1. struct device_driver {
  2.     const char        *name;
  3.     struct bus_type        *bus;

  4.     struct module        *owner;
  5.     const char        *mod_name;    /* used for built-in modules */

  6.     bool suppress_bind_attrs;    /* disables bind/unbind via sysfs */

  7.     int (*probe) (struct device *dev);
  8.     int (*remove) (struct device *dev);
  9.     void (*shutdown) (struct device *dev);
  10.     int (*suspend) (struct device *dev, pm_message_t state);
  11.     int (*resume) (struct device *dev);
  12.     const struct attribute_group **groups;

  13.     const struct dev_pm_ops *pm;

  14.     struct driver_private *p;
  15. };


  1. /**
  2.  * driver_register - register driver with bus
  3.  * @drv: driver to register
  4.  *
  5.  * We pass off most of the work to the bus_add_driver() call,
  6.  * since most of the things we have to do deal with the bus
  7.  * structures.
  8.  */
  9. int driver_register(struct device_driver *drv)
  10. {
  11.     int ret;
  12.     struct device_driver *other;

  13.     BUG_ON(!drv->bus->p);

  14.     if ((drv->bus->probe && drv->probe) ||
  15.      (drv->bus->remove && drv->remove) ||
  16.      (drv->bus->shutdown && drv->shutdown))
  17.         printk(KERN_WARNING "Driver '%s' needs updating - please use "
  18.             "bus_type methods\n", drv->name);

  19.     other = driver_find(drv->name, drv->bus);
  20.     if (other) {
  21.         put_driver(other);
  22.         printk(KERN_ERR "Error: Driver '%s' is already registered, "
  23.             "aborting...\n", drv->name);
  24.         return -EBUSY;
  25.     }

  26.     ret = bus_add_driver(drv);
  27.     if (ret)
  28.         return ret;
  29.     ret = driver_add_groups(drv, drv->groups);
  30.     if (ret)
  31.         bus_remove_driver(drv);
  32.     return ret;
  33. }

阅读(1891) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

小尾巴鱼1211212012-04-23 21:06:30

比较详细啊,有例子就好