One: Platform bus
1.1 Overview
A realistic Linux device driver usually needs to be hooked up on a bus, which is not a problem for devices that are attached to PCI,USB,IIC,SPI, but in embedded systems,
The Independent peripheral controller integrated in the SOC system, the peripherals attached to the SOC memory space are not attached to such a bus. Based on this background, Linux invented a kind of virtual bus, called Platform Bus, the corresponding
The device is called Platform_device, and the drive becomes platform_driver. The platform bus is a virtual bus that is added to the linux2.6 core.
1.2.Platform Bus Advantages
Platform driver compared with the traditional device driver model, the advantage is that the platform mechanism registers the resources of the device itself into the kernel, which is managed by the kernel, and uses the unified interface when the driver uses these resources, which improves the portability of the program.
Two. Drive software design process for platform devices
Three. Platform Equipment:
3.1. The platform device uses struct Platform_device to describe
struct Platform_device {
const char * name; Device Name
int id;//device number, use with device name
struct device dev;
U32 number of resources used by num_resources;//equipment
struct resource * resource;//device resources
};
3.2. Assigning a platform device structure
Strcut platform_device allocation using:
struct Platform_device *platform| | _device_alloc (const char *name,int ID)
Parameters:
Name: Device Name
ID: Device ID, typically-1
3.3. Platform Device Registration
To register a platform device, use the function:
Int platform_device_add (struct paltform_device *pdev)
3.4. Equipment Resources
Platform device resources Use struct resource to describe
struct Resource {
Resource_size_t The starting physical address of the start;//resource
resource_size_t the end physical address of the end;//resource
const char *name;//name of the resource
unsigned long flags;//type of resource, such as Mem,irq
struct resource *parent, *sibling, *child;//resource's linked list pointer
};
3.5. Access to resources
struct resource *platform_get_resource (struct platform_device *dev,unsigned int type,unsigned int num)
Parameters:
Dev: The device to which the resource belongs
Type: Gets the resource types
Num: Number of resources fetched
Eg:platform_get_resource (pdev,ioresource_irq,0)
Four: platform-driven
4.1. Platform Driver Description
The platform driver uses the struct Platform_driver description:
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 (*resume) (struct platform_device *);
struct Device_driver driver;
struct platform_device_id *id_table;
};
4.2. Platform-driven registration
Platform-driven registration uses functions:
int Platform_driver_register (struct platform_driver*)
4.3. Implement functions of some functions in struct platform_driver structure body
Five. Platform device and platform driver Code analysis
Linux device drives that point of the platform device theory Chapter