Linux platform device-driven match automatic matching

Source: Internet
Author: User

<span style= "FONT-SIZE:14PX;" >struct Platform_device {   //linux/platform_device.hconst char* name;intid;struct devicedev;u32num_resources; struct resource* resource;struct platform_device_id*id_entry;/* Arch specific additions */struct Pdev_archdataarchdata ;}; </span>

There is also a more important structure resource more critical, usually < Span style= "font-size:14px" > define a platform_device General need to initialize two aspects of the content: device occupied by the resources resource and device private data dev.platform_data. The resources occupied by the device are mainly two aspects: IO memory and IRQ resource.

struct Resource {   //linux/ioportsresource_size_t start;resource_size_t end;const char *name;unsigned long flags; struct resource *parent, *sibling, *child;};
static struct resource myled_resource[] = {        [0] = {                . Start = 0x56000010,                . End   = 0x56000010 + +,                . Flag s = Ioresource_mem        },};
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;};
A bus_type instance is defined for the platform bus in the system platform_bus_type,struct bus_type platform_bus_type = {    . Name = "Platform",    . Dev_attrs = Platform_dev_attrs,    . Match = Platform_match,    . uevent = platform_uevent,    . PM = Platform_pm_ops _ptr,}; EXPORT_SYMBOL_GPL (Platform_bus_type); The focus here is on the match () member function, which shows how Platform_device and Platform_driver match. static int Platform_match (struct device *dev, struct device_driver *drv) {    struct platform_device *pdev;    Pdev = container_of (dev, struct platform_device, dev);    Return (STRNCMP (Pdev->name, drv->name, bus_id_size) = = 0);} Matching Platform_device and Platform_driver mainly depends on whether the name field is the same. The definition of Platform_device is usually implemented in the BSP Board file, in the board file, the Platform_device is summed up as an array, which is eventually registered through the Platform_add_devices () function. The Platform_add_devices () function can add a platform device to the system, and the prototype of the function is: int platform_add_devices (struct platform_device **devs, int num); /The first parameter of the function is a pointer to the platform device array, the second parameter is the number of platform devices, which internally calls the Platform_device_register () function to register a single platform device.


Example

MYLED.C Equipment

static struct Platform_device myledplatform_device_led = {        . Name           = "Myled_platform_device_driver",        . Id             =-1,        . Num_resources  = array_size (Myled_resource),        . Resource       = Myled_resource,        . Dev            = {              . Release  = Myled_platform_device_release,        },};
myled_drv.c Device Driver
static struct Platform_driver Myled_platform_driver = {. Probe  = Myled_probe,.remove = __devexit_p (Myled_remove),. Driver = {. Name = "Myled_platform_device_driver",. Owner = This_module,}};

as long as we set the Driver.name in the Platform_device and Platform_driver, the match of the platform bus will match automatically .Platform_device and Platform_driver.

Linux platform device-driven match automatic matching

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.