Documentation_driver-model_binding

Chinese translated version of Documentation/Driver Binding


If you have any comment or update to the content, please contact the
original document maintainer directly.  However, if you have a problem
communicating in English you can also ask the Chinese maintainer for
help.  Contact the Chinese maintainer if this translation is outdated
or if there is a problem with the translation.


Chinese maintainer: biyu tang<tangbiyu17@qq.com>
---------------------------------------------------------------------
Documentation/Driver Binding的中文翻译


如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文
交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
译存在问题,请联系中文版维护者。


中文版维护者: 唐碧瑜  biyu tang<tangbiyu17@qq.com>
中文版翻译者: 唐碧瑜  biyu tang<tangbiyu17@qq.com>
中文版校译者: 唐碧瑜  biyu tang<tangbiyu17@qq.com>










以下为正文
---------------------------------------------------------------------
Driver binding is the process of associating a device with a device
driver that can control it. Bus drivers have typically handled this
because there have been bus-specific structures to represent the
devices and the drivers. With generic device and device driver
structures, most of the binding can take place using common code.


驱动程序绑定是关联一个设备和能控制这个设备的驱动程序的过程。总线驱动
通常来处理驱动程序绑定,是因为总线有特定的结构来表现设备和驱动程序。通
过通用设备和设备驱动程序结构,大多数的绑定可以在常见的代码发生。


Bus
~~~
总线


The bus type structure contains a list of all devices that are on that bus
type in the system. When device_register is called for a device, it is
inserted into the end of this list. The bus object also contains a
list of all drivers of that bus type. When driver_register is called
for a driver, it is inserted at the end of this list. These are the
two events which trigger driver binding.


总线类型结构包含一个记录了系统总线上所有设备的列表。当device_register被设备
调用时,那这个设备将被加入到列表的尾部。总线对象还包含一个记录了这个总
线类型所有驱动程序的列表。当driver_register被驱动程序调用时,那这个驱动程序
将被加入到列表的尾部。这就是触发驱动程序绑定的两个事件。


device_register
~~~~~~~~~~~~~~~
设备寄存器


When a new device is added, the bus's list of drivers is iterated over
to find one that supports it. In order to determine that, the device
ID of the device must match one of the device IDs that the driver
supports. The format and semantics for comparing IDs is bus-specific. 
Instead of trying to derive a complex state machine and matching
algorithm, it is up to the bus driver to provide a callback to compare
a device against the IDs of a driver. The bus returns 1 if a match was
found; 0 otherwise.


当一个新的设备被添加时,总线遍历驱动程序列表寻找支持它的那个。要判定
一个设备是否能被列表中的驱动程序驱动,那么这个设备的id必须和驱动程序列表
中的某一个id相匹配。特定的总线来比较id的格式和语义。代替实现一个复
杂的状态机和比较逻辑,总线驱动程序为设备提供了一个回调函数来比较设备ID
与驱动ID。如果匹配,则总线返回1,否则返回0。


int match(struct device * dev, struct device_driver * drv);


If a match is found, the device's driver field is set to the driver
and the driver's probe callback is called. This gives the driver a
chance to verify that it really does support the hardware, and that
it's in a working state. 




如果找到了一个匹配的设备,那么这个设备驱动的驱动成员将会被设置为该驱动,
并且该驱动中的probe回调将会被调用。这给驱动提供一次机会去验证它是否支
持该硬件且该硬件是否已经在运行。


Device Class
~~~~~~~~~~~~
设备类


Upon the successful completion of probe, the device is registered with
the class to which it belongs. Device drivers belong to one and only one
class, and that is set in the driver's devclass field. 
devclass_add_device is called to enumerate the device within the class
and actually register it with the class, which happens with the
class's register_dev callback.


当probe操作成功完成之后,该设备就会向它所属的类申请注册。设备驱动有且
只有一个它所属的类,该类被设置在驱动的devclass成员中。devclass_add_device
被调用枚举类中的设备,同时会在类结构的register_dev回调中注册该设备。


Driver
~~~~~~
驱动


When a driver is attached to a device, the device is inserted into the
driver's list of devices. 


当一个驱动被一个设备所依附时,这个设备会被插入到驱动设备列表


sysfs
~~~~~
系统


A symlink is created in the bus's 'devices' directory that points to
the device's directory in the physical hierarchy.


在总线的'devices'目录下创建一个指向设备目录所在的物理层的符号链接。


A symlink is created in the driver's 'devices' directory that points
to the device's directory in the physical hierarchy.


在驱动的'devices'目录下创建一个指向设备目录所在的物理层的符号链接。


A directory for the device is created in the class's directory. A
symlink is created in that directory that points to the device's
physical location in the sysfs tree. 


在类目录下给创建一个设备目录。在该目录下创建一个指向设备目录所在的
物理层的符号链接。


A symlink can be created (though this isn't done yet) in the device's
physical directory to either its class directory, or the class's
top-level directory. One can also be created to point to its driver's
directory also. 


可以在设备物理层目录下创建一个指向该类的目录、设备类顶层目录的符号链
接。也可以创建一个指向设备驱动的符号链接。
 
driver_register
~~~~~~~~~~~~~~~
驱动注册


The process is almost identical for when a new driver is added. 
The bus's list of devices is iterated over to find a match. Devices
that already have a driver are skipped. All the devices are iterated
over, to bind as many devices as possible to the driver.


驱动注册的过程跟添加一个新的驱动程序差不多。总线的设备列表会被遍历
寻找一个匹配的设备。那些已经匹配了驱动的设备将被跳过。所有的设备将
被遍历,为当前驱动绑定尽可能多的设备


Removal
~~~~~~~
移除


When a device is removed, the reference count for it will eventually
go to 0. When it does, the remove callback of the driver is called. It
is removed from the driver's list of devices and the reference count
of the driver is decremented. All symlinks between the two are removed.


当一个设备被移除时,它的引用计数器会归0。归零后,remove回调将会被调用。
该设备会从驱动的设备列表中移除,同时驱动的引用计数也会减少。两者之间
关联的符号链接会被移除。


When a driver is removed, the list of devices that it supports is
iterated over, and the driver's remove callback is called for each
one. The device is removed from that list and the symlinks removed. 


当一个驱动被移除时,该驱动支持的设备列表将会被遍历,同时为每一个设备调
用remove回调。设备会被从该列表中移除。同时,符号链接也会被移除。
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值