Drive develops reading notes. 0.04 Linux 2.6 Platform device register platform equipment registration 1/2 Total 2 articles

Source: Internet
Author: User
Tags function prototype

Drive develops reading notes. 0.04 Linux 2.6 Platform device register platform equipment registration 1/2 Total 2 articles

Documentation/driver-model/platform.txt
Device Enumeration the~~~~~~~~~~~~~~~~~~as a rule, platform specific (and often board-specific) Setup code'll, register platform devices: -   the        intPlatform_device_register (structPlatform_device *Pdev);  the   the        intPlatform_add_devices (structPlatform_device **pdevs,intNdev);  theThe General rule isto register only those devices that actually existinchsome cases extra devices might be registered. For example, a kernel might is configured to work with an external network adapter that might not the is populated on  All boards, or likewise-to-work with a integrated controller 94 that some boards might not hooks up to any peripherals.  thein some cases, boot firmware would export tables describing the devices, that is populated on a given board. Without such tables, often the 98 only forSystem Setup code toSetUp the correct devices isTo build a kernel forA specific target board. Such board-specific kernels is common with embedded and custom systems development.101102 In many cases, the memory and IRQ resources associated with the platform 103 device is not enough to let the dev Ice's driver work. Board Setup Code104 'll often provide additional informationusingThe device's Platform_dataThe additional information field to the hold.106107 Embedded Systems frequently need one or more clocks forplatform devices, 108 which is normally kept off until they're actively needed (to save power).109 System Setup also associates those clocks with the device, so that's calls to Clk_get (&pdev->dev, Clock_name)returnthem asneeded.111  the113 Legacy Drivers:device probing the~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Some drivers is not fully converted to the driver model, because they take-on a non-Driver Role:the Driver registers its platform device, rather than 117 leaving that forSystem infrastructure. Such drivers can't be hotplugged118 or coldplugged, since those mechanisms require device creation to beincha 119 different system component than the driver. -121 The only"Good"Reason for  This  isto handle older system designs which, like 122 original IBM PCs, rely on error-prone"Probe-the-hardware"Models forHardware 123 configuration. Newer systems has largely abandoned that model,inchfavor of 124 bus-level Support fordynamic Configuration (PCI, USB), or device tables provided by the boot firmware (e.g. PNPACPI on x86). There is too many 126 conflicting options about what the might bewhere, and even educated guesses by 127 an operating system would be wrong often enough to make trouble. -129 This style of driver isDiscouraged. If You're updating such a driver,PleaseTryto move the device enumeration to a more appropriate location, 131 outside the driver. This would usually be cleanup, since such drivers. tend to already has"Normal"modes, such asOnesusingdevice nodes, 133 were created by PNP or by platform device setup.134135 None, there is some APIs to support such legacy drivers. Avoid 136usingThese calls except with such hotplug-deficient drivers.137 138        structPlatform_device *Platform_device_alloc (139                        Const Char*name,intID);  $141 You can use Platform_device_alloc () to dynamically allocate a device, which 142 you'll then initialize with RE Sources and Platform_device_register (). 143 A Better Solution isusually:144 145        structPlatform_device *Platform_device_register_simple (146                        Const Char*name,intID,147                        structResource *res, unsignedintnres); 148149 can use Platform_device_register_simple () asA one-step call to allocate and register a device.

The above mentioned two kinds of platform device registration method, one is

Platform specific (and often board-specific) Setup code

Platform-specific, find related data structures and code in/ARCH/ARM/PLAT-S3C24XX/DEVS.C

First step: Define the resource structure body
static struct resource s3c_lcd_resource[] = {        [0] = {                . Start = S3c24xx_pa_lcd,                . End   = S3c24xx_pa_lcd + S3c24xx_sz_lcd-1,                . Flags = Ioresource_mem,        },        [1] = {                . Start = Irq_lcd,                . End   = IRQ_LCD,                . Flags = IORESOURCE_IRQ,        }};


Step Two: Define Platform_device (the main device name device ID (distinguish the same device names) resource number resource definition embedded device)
struct Platform_device S3C_DEVICE_LCD = {       . Name             "S3c2410-lcd",       . ID               =-1,       . num_resources    = Array_size (S3c_lcd_resource),       . Resource         = S3c_lcd_resource,       . Dev              = {                . dma_mask               = &s3c_device_lcd_dmamask,                . Coherent_dma_mask      = 0xffffffffUL        };
  (ARCH/ARM/MACH-S3C2440/MACH-SMDK2440.C)
static struct Platform_device *smdk2440_devices[] __initdata = {        &s3c_device_usb,        &S3C_DEVICE_LCD,        &S3C_DEVICE_WDT,        &s3c_device_i2c,        &s3c_device_iis,};
Fourth step: Add to Platform_device pointer Array (ARCH/ARM/MACH-S3C2440/MACH-SMDK2440.C)
static void __init Smdk2440_machine_init (void) {        s3c24xx_fb_set_platdata (&smdk2440_lcd_cfg);        Platform_add_devices (Smdk2440_devices, Array_size (smdk2440_devices));        Smdk_machine_init ();}
Platform_add_devices will register platform_device to the kernel
Fifth step: Have you found a s3c24xx_fb_set_platdata  function above? What did he do?
Platform.txt wrote:
In many cases, the memory and IRQ resources associated with the platform
Device is not enough to let the device's driver work. Board Setup Codewill often provide additional information using the device ' s platform_datafield to hold additional inf Ormation.

Because the resource structure is well defined, it is not convenient to add more information platform provides support for platform data Platform_data.

Here is the function prototype: (Feeling is an ugly patch ...) )
void __init s3c24xx_fb_set_platdata (struct s3c2410fb_mach_info *pd) {        struct s3c2410fb_mach_info *npd;        NPD = Kmalloc (sizeof (*NPD), gfp_kernel);        if (NPD) {                memcpy (NPD, PD, sizeof (*NPD));                S3c_device_lcd.dev.platform_data = NPD;        } else {                "no memory for LCD platform data\n");}        }
 Sixth step: The fourth step of the code also has a smdk_machine_init (); 
is the setting of Gpio and registered led devices

Summary: The first method defines the resource definition platform data setting Platdata (associated with Platform_device) and then uses Platform_add_ The devices function is registered
Note that platform_add_devices and platform_device_add differ greatly, platform_add_devices (struct platform_device * * Devs,int num) based on the incoming pointer,
calculates the number of Platform_device to register (note that this is not a platform_device.id) and then uses the iteration to invoke Platform_device_  Register (struct Platform_device *)
.
so the core function call is platform_device_register This function, when multiple devices call Platform_add_devices

interested friends can take a look at Platform_add_devices (Smdk2440_devices, Array_size (smdk2440_devices)); Inside Array_size counts the number of array elements The implementation of
this macro in <linux/kernel.h>

Note: The above code is compiled into the kernel, not the kernel module


A small impression:
After writing the character device driver, learning this platform device driver, is very curious to say is the device driver, but did not provide the application interface open write method, baffled its solution; and then turned back and forth several books, and found that platform seemed
There is no and not designed to provide these interfaces, you can register the character/Mix/class device in the driver initialization or ProE probe function, to provide write open for the application, and the character device and platform device-driven
Contact seems to only provide registration and destruction of the relationship, the device driver is really complex, I hope to overcome early.


Next introduction to the second method of registration

Resources:
Linux Source 2.6.22


23:56:02
2016-10-05

Drive develops reading notes. 0.04 Linux 2.6 Platform device register platform equipment registration 1/2 Total 2 articles

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.