174 structPlatform_driver {175 int(*probe) (structPlatform_device *);176 int(*remove) (structPlatform_device *);177 void(*shutdown) (structPlatform_device *);178 int(*suspend) (structPlatform_device *, pm_message_t state);179 int(*resume) (structPlatform_device *); the structDevice_driver driver;181 Const structPLATFORM_DEVICE_ID *id_table;182 BOOLPrevent_deferred_probe;183};
259 structDevice_driver {260 Const Char*name;261 structBus_type *bus;262 263 structModule *owner; the Const Char*mod_name;/*used for built-in modules*/ 265 266 BOOLSuppress_bind_attrs;/*disables Bind/unbind via Sysfs*/ 267 enumProbe_type Probe_type;268 269 Const structOF_DEVICE_ID *of_match_table; //device tree through this to match the Const structACPI_DEVICE_ID *acpi_match_table;271 272 int(*probe) (structDevice *Dev); 273 int(*remove) (structDevice *Dev); 274 void(*shutdown) (structDevice *Dev); 275 int(*suspend) (structDevice *Dev, pm_message_t State); 276 int(*resume) (structDevice *Dev); 277 Const structAttribute_group * *groups;278 279 Const structDev_pm_ops *pm;280 281 structDriver_private *p;282};
A structPlatform_device { at Const Char*name; - intID; - BOOLId_auto; - structdevice Dev; -u32 num_resources; - structResource *resource; in - Const structPLATFORM_DEVICE_ID *Id_entry; to Char*driver_override;/*Driver name to force a match*/ + - /*MFD Cell Pointer*/ the structMfd_cell *Mfd_cell; * $ /*Arch Specific Additions*/ Panax Notoginseng structPdev_archdata Archdata; -};
The above is the structure definition of the header file
129 Static Const structof_device_id dw_spi_mmio_of_match[] = { the{. compatible ="Snps,dw-apb-ssi", },131{/*End of Table*/} the };133module_device_table (OF, dw_spi_mmio_of_match);134 135 Static structPlatform_driver Dw_spi_mmio_driver = {136. Probe =Dw_spi_mmio_probe,137. remove =Dw_spi_mmio_remove,138. Driver = {139. Name =driver_name, $. of_match_table =Dw_spi_mmio_of_match,141 },142 };143Module_platform_driver (dw_spi_mmio_driver);144 145Module_author ("jean-hugues deschenes <[email protected]>");146Module_description ("memory-mapped I/O interface driver for DW SPI Core");147Module_license ("GPL v2");
The previous wording:
structPlatform_device S3c_device_usb ={. Name="S3C2410-OHCI",//S3c6410-usb. ID =-1,. Num_resources=array_size (S3c_usb_resource),. Resource=s3c_usb_resource,. Dev={. Dma_mask= &s3c_device_usb_dmamask,. Coherent_dma_mask=0xffffffffUL } };
With Platform_device, you can call the function platform_add_devices to add the device to the system. Device resources in the system can be enumerated in this way, and then into an array of pointers, such as:Static structPlatform_device *smdk6410_devices[] __initdata = {...... &S3c_device_usbgadget,&S3C_DEVICE_USB,//Jeff Add.......} Static structPlatform_driver Ohci_hcd_s3c2410_driver ={. Probe=ohci_hcd_s3c2410_drv_probe,. Remove=Ohci_hcd_s3c2410_drv_remove,. Shutdown=Usb_hcd_platform_shutdown,/*. Suspend = Ohci_hcd_s3c2410_drv_suspend,*/ /*. Resume = Ohci_hcd_s3c2410_drv_resume,*/. Driver={. Owner=this_module,. Name="S3C2410-OHCI", }, };
(1Kernel_init ()->do_basic_setup ()->driver_init ()->platform_bus_init () initializes the Platform_bus (virtual bus) during kernel initialization;
(2) When the device is registered Platform_device_register ()->platform_device_add () (Pdev->dev.bus = &platform_bus_type ) Hang the equipment under the virtual platform bus;
(3) driver Registration Platform_driver_register ()->driver_register ()->bus_add_driver ()->driver_attach ()->bus_for_ Each_dev (), for each hanging on a virtual
Platform Bus's device is __driver_attach ()->driver_probe_device () to determine if Drv->bus->match () is present and successful, The Platform_match is executed by the pointer,
Compare strncmp (Pdev->name, Drv->name, bus_id_size) and call Really_probe if it matches (actually the platform_driver-> of the corresponding device being executed)Probe (Platform_device),
Note that the _dev parameter of Platform_drv_probe is obtained by Bus_for_each_dev Next_device) to start a real probe load, and if probe succeeds then bind the device to that drive. When you enter the probe function, you need to obtain the resource information of the device, depending on the type specified by the parameter type, such as IORESOURCE_MEM, to obtain the specified resource separately. structResource * Platform_get_resource (structPlatform_device *dev, unsignedintType, unsignedintnum); Of course, you can also fix resource types,
If you get the interrupt number in the resource:struct intPLATFORM_GET_IRQ (structPlatform_device *dev, unsignedintnum); Probe function generally completes the hardware device enable,structThe acquisition of resource and the dynamic mapping of virtual addresses and the registration of specific types of devices (because the platform device is only a virtual device type);
The Remove function completes the shutdown of the hardware device,structResource and the release of dynamic mappings for virtual addresses and the logoff of specific types of devices. As long as the core itself is running on a less dependent peripheral device
(in other words, as long as the device is not within the minimum system required to run the kernel), a relatively independent resource (addresses and IRQs) can be implemented with Platform_driver.
such as: Lcd,usb,uart, etc., can be written with platfrom_driver, and timer,irq such as the smallest system within the device is best not platfrom_driver mechanism, in fact, the implementation of the kernel is also the case.
http://blog.csdn.net/zhandoushi1982/article/details/5130207
http://blog.csdn.net/lichengtongxiazai/article/details/38941997 DT Writing Specification
Http://www.right.com.cn/forum/thread-146260-1-1.html DT (2)
Linux platform devices and drives