这里会显示出您选择的修订版和当前版本之间的差别。
jaysnote:platform [2019/04/29 15:33] jaylee 创建 |
jaysnote:platform [2021/06/22 23:14] |
||
---|---|---|---|
行 1: | 行 1: | ||
- | < | ||
- | |||
- | # Platform Devices and Drivers | ||
- | |||
- | See < | ||
- | like those used to integrate peripherals on many system-on-chip processors, or some " | ||
- | |||
- | ## 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. | ||
- | |||
- | Platform devices are given a name, used in driver binding, and a list of resources such as addresses and IRQs. | ||
- | |||
- | ```c | ||
- | struct platform_device { | ||
- | const char *name; | ||
- | u32 id; | ||
- | struct device dev; | ||
- | u32 num_resources; | ||
- | struct resource *resource; | ||
- | }; | ||
- | ``` | ||
- | |||
- | ## Platform drivers | ||
- | |||
- | Platform drivers follow the standard driver model convention, where discovery/ | ||
- | |||
- | ```c | ||
- | 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; | ||
- | }; | ||
- | ``` | ||
- | |||
- | Note that probe() should general verify that the specified device hardware actually exists; sometimes platform setup code can't be sure. The probing can use device resources, including clocks, and device platform_data. | ||
- | |||
- | Platform drivers register themselves the normal way: | ||
- | |||
- | ```c | ||
- | 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' | ||
- | |||
- | ```c | ||
- | int platform_driver_probe(struct platform_driver *drv, | ||
- | int (*probe)(struct platform_device *)) | ||
- | ``` | ||
- | |||
- | ## Device Enumeration | ||
- | |||
- | As a rule, platform specific (and often board-specific) setup code will register platform devices: | ||
- | |||
- | ```c | ||
- | 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. | ||
- | |||
- | In some cases, boot firmware will export tables describing the devices that are populated on a given board. | ||
- | |||
- | In many cases, the memory and IRQ resources associated with the platform device are not enough to let the device' | ||
- | |||
- | Embedded systems frequently need one or more clocks for platform devices, | ||
- | |||
- | ## Legacy Drivers: | ||
- | |||
- | Some drivers are not fully converted to the driver model, because they take on a non-driver role: the driver registers its platform device, rather than leaving that for system infrastructure. | ||
- | |||
- | The only " | ||
- | |||
- | This style of driver is discouraged. | ||
- | please try to move the device enumeration to a more appropriate location, | ||
- | outside the driver. | ||
- | |||
- | None the less, there are some APIs to support such legacy drivers. | ||
- | |||
- | ```c | ||
- | struct platform_device *platform_device_alloc( | ||
- | const char *name, int id); | ||
- | ``` | ||
- | |||
- | You can use platform_device_alloc() to dynamically allocate a device, which you will then initialize with resources and platform_device_register(). | ||
- | A better solution is usually: | ||
- | |||
- | ```c | ||
- | struct platform_device *platform_device_register_simple( | ||
- | const char *name, int id, | ||
- | struct resource *res, unsigned int nres); | ||
- | ``` | ||
- | |||
- | You can use platform_device_register_simple() as a one-step call to allocate and register a device. | ||
- | |||
- | Device Naming and Driver Binding | ||
- | | ||
- | The platform_device.dev.bus_id is the canonical name for the devices. | ||
- | It's built from two components: | ||
- | |||
- | ```c | ||
- | * platform_device.name ... which is also used to for driver matching. | ||
- | |||
- | * platform_device.id ... the device instance number, or else " | ||
- | to indicate there' | ||
- | ``` | ||
- | |||
- | These are concatenated, | ||
- | " | ||
- | and use the platform_driver called " | ||
- | |||
- | Driver binding is performed automatically by the driver core, invoking driver probe() after finding a match between device and driver. | ||
- | |||
- | - Whenever a device is registered, the drivers for that bus are | ||
- | checked for matches. | ||
- | early during system boot. | ||
- | |||
- | - When a driver is registered using platform_driver_register(), | ||
- | unbound devices on that bus are checked for matches. | ||
- | usually register later during booting, or by module loading. | ||
- | |||
- | - Registering a driver using platform_driver_probe() works just like | ||
- | using platform_driver_register(), | ||
- | be probed later if another device registers. | ||
- | this interface is only for use with non-hotpluggable devices.) | ||
- | |||
- | ## Early Platform Devices and Drivers | ||
- | |||
- | |||
- | The early platform interfaces provide platform data to platform device drivers early on during the system boot. The code is built on top of the early_param() command line parsing and can be executed very early on. | ||
- | |||
- | Example: " | ||
- | |||
- | 1. Registering early platform device data | ||
- | |||
- | The architecture code registers platform device data using the function early_platform_add_devices(). In the case of early serial console this should be hardware configuration for the serial port. Devices registered at this point will later on be matched against early platform drivers. | ||
- | |||
- | 2. Parsing kernel command line | ||
- | The architecture code calls parse_early_param() to parse the kernel command line. This will execute all matching early_param() callbacks. | ||
- | User specified early platform devices will be registered at this point. | ||
- | For the early serial console case the user can specify port on the kernel command line as " | ||
- | |||
- | 3. Installing early platform drivers belonging to a certain class | ||
- | |||
- | The architecture code may optionally force registration of all early platform drivers belonging to a certain class using the function early_platform_driver_register_all(). User specified devices from step 2 have priority over these. This step is omitted by the serial driver example since the early serial driver code should be disabled unless the user has specified port on the kernel command line. | ||
- | |||
- | 4. Early platform driver registration | ||
- | |||
- | Compiled-in platform drivers making use of early_platform_init() are automatically registered during step 2 or 3. The serial driver example should use early_platform_init(" | ||
- | |||
- | 5. Probing of early platform drivers belonging to a certain class | ||
- | |||
- | The architecture code calls early_platform_driver_probe() to match registered early platform devices associated with a certain class with registered early platform drivers. Matched devices will get probed(). | ||
- | This step can be executed at any point during the early boot. As soon as possible may be good for the serial port case. | ||
- | |||
- | 6. Inside the early platform driver probe() | ||
- | |||
- | The driver code needs to take special care during early boot, especially when it comes to memory allocation and interrupt registration. The code in the probe() function can use is_early_platform_device() to check if it is called at early platform device or at the regular platform device time. The early serial driver performs register_console() at this point. | ||
- | |||
- | For further information, | ||
- | |||
- | </ | ||