1、在Linux2.6的设备驱动模型中,关心总线、设备和驱动这三个实体,总线将设备和驱动绑定。在系统每注册一个设备的时候,会寻找与之匹配的驱动;相反的,在系统每注册一个驱动的时候,会寻找与之匹配的设备,为匹配由总线实现。
Platform Devices and Drivers 平台设备和驱动
the driver model interface to the platform bus:设备驱动模型接口平台总线 platform_device, and platform_driver.
This pseudo-bus is used to connect devices on busses with minimal infrastructure, like those used to integrate peripherals on many system-on-chip processors;as opposed to large formally specified ones like PCI or USB.这个虚拟的总线用来连接设备,是最小的基础设施,用于芯片内部的集成的外设和古老的PC内部连线,和那些总线比如PCI or USB相对应。
2、Platform devices平台设备
Platform devices are devices that typically appear as autonomous entities in the system.平台设备作为自治的实体存在。 This includes legacy port-based devices and host bridges to peripheral buses, and most controllers integrated into system-on-chip platforms. What they usually have in common is direct addressing from a CPU bus.它们通常拥有直接的地址 通过CPU bus。 Rarely, a platform_device will be connected through a segment of some other kind of bus; but its registers will still be directly addressable.
Platform devices are given a name, used in driver binding, and a list of resources such as addresses and IRQs.
平台设备拥有一个名字,用于和驱动绑定,可以给一个资源列表。
注意:Platform devices平台设备并不是与字符设备、块设备和网络设备并列的概念,而是Linux提供的一种附加手段,例如内部集成的I2C、RTC等控制器都归纳为Platform devices平台设备,而它们本身就是字符设备。
struct platform_device {
const char*name;设备名
u32id;
struct device dev;
u32num_resources;设备所使用的各类资源数量
struct resource*resource; 资源
};
3、
Platform drivers
Platform drivers follow the standard driver model convention约定, where discovery/enumeration is handled outside the drivers, and drivers provide probe() and remove() methods. They support power management and shutdown notifications通知 using the standard conventions.
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;
};
Platform drivers register themselves the normal way:
int platform_driver_register(struct platform_driver *drv);
Or, in common situations where the device is known not to be hot-pluggable热拔插, the probe() routine 程序can live in an init section to reduce the driver's runtime memory footprint:
int platform_driver_probe(struct platform_driver *drv, int (*probe)(struct platform_device *)) 一般设备都不是热拔插,probe程序可以放在init段中,以减少内存的占用
4、
Device Enumeration设备列表
As a rule, platform specific (and often board-specific) setup code will register platform devices:设备注册函数
int platform_device_register(struct platform_device *pdev);注册单个设备
int platform_add_devices(struct platform_device **pdevs, int ndev);注册多个设备
The general rule is to register only those devices that actually exist, but in some cases extra devices might be registered. For example, a kernel might be configured to work with an external network adapter that might not be populated on all boards, or likewise to work with an integrated controller that some boards might not hook up to any peripherals.一般注册已经存在的设备,也有可能注册新加的设备
In many cases, the memory and IRQ resources associated with the platform device are not enough to let the device's driver work. Board setup code will often provide additional information using the device's platform_data field to hold additional information.设备资源,其他的额外资源可以通过device's platform_data设置
5、
Device Naming and Driver Binding 设备命名和驱动绑定
(1)、The platform_device.dev.bus_id is the canonical(典型) name for the devices. It's built from two components:
* platform_device.name ... which is also used to for driver matching.用于驱动绑定
* platform_device.id ... the device instance number, or else "-1" to indicate there's only one.设备实例编号,-1时表名只有一个设备
platform_device.dev.bus_id是设备的典型的名字,它有两部分组成,platform_device.name和 platform_device.id 。
举例说明:
These are concatenated, so name/id "serial"/0 indicates bus_id "serial.0", and "serial/3" indicates bus_id "serial.3"; both would use the platform_driver named "serial". While "my_rtc"/-1 would be bus_id "my_rtc" (no instance id) and use the platform_driver called "my_rtc".
(2)、Driver binding is performed automatically by the driver core, invoking driver probe() after finding a match between device and driver.驱动绑定由设备核心自动完成,在设备和驱动匹配后,调用驱动驱动的probe() 函数。 If the probe() succeeds, the driver and device are bound as usual. 如果probe() 成功,设备和驱动绑定正常。
There are three different ways to find such a match:有三种匹配方式:
- Whenever a device is registered, the drivers for that bus are checked for matches. Platform devices should be registered very early during system boot.当一个设备注册是,这个总线上的驱动被检查,去match,设备应该在系统引导开始时注册。
- When a driver is registered using platform_driver_register(), all unbound devices on that bus are checked for matches. Drivers usually register later during booting, or by module loading.当驱动注册时,所有还没绑定的设备被检查,去match,驱动通常在系统引导后半部分注册,或者模块加载时。
- Registering a driver using platform_driver_probe() works just like using platform_driver_register(), except that the driver won't be probed later if another device registers. (Which is OK, since this interface is only for use with non-hotpluggable devices.) 用platform_driver_probe() 注册驱动和用platform_driver_register()注册驱动一样,除非其他设备注册时没有和这个驱动匹配,这种方法只能用于非热拔插设备。