1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
| struct device platform_bus = { .init_name = "platform", }; struct bus_type platform_bus_type = { .name = "platform", .dev_attrs=platform_dev_attrs, .match = platform_match, .uevent = platform_uevent, .pm = &platform_dev_pm_ops, }; stat_kernel() rest_init() kernel_thread(kernel_init...) kernel_init do_basic_setup() driver_init() platform_bus_init() device_register(&platform_bus) bus_register(&platform_bus_type)
struct resources{ resource_size start; resource_size end; const char *name; ulong flags; struct resources *parent, *sibling, *child; } struct platform_device{ const char *name; int id; struct device dev; u32 num_resources; struct resources *resources; const struct platform_device_id *id_entry; ... }
struct platform_driver{ int (*probe)(struct platform_device *); int (*remove)(struct platform_device* ); shutdown,suspend,resume struct device_driver driver; const struct platform_device_id *id_table; }
platform_device_register(struct platform_device *pdev) platform_device_add(pdev); pdev->dev.parent = &platform_bus; pdev->dev.bus = &platform_bus_type; device_add(&pdev->dev);
platform_driver_register(struct platform_driver *drv) drv->driver.bus = &platform_bus_type; drv->driver.probe = platform_drv_probe; drv->driver.remove = platform_drv_remove; dirver_register(&drv->dirver); bus_add_driver(&drv->dirver) dirver_attach(&drv->dirver) bus_for_each_dev(drv->bus, NULL, &drv->driver, __driver_attach) __driver_attach(dev, drv) if(!driver_match_device(drv,dev)) return 0; driver_probe_device(drv, dev) really_probe(dev,drv) dev->driver = drv; drv->probe(dev)
platform_match(struct device *dev, struct device_driver *drv) struct platform_device *pdev = to_platform_device(dev); struct platform_driver *pdrv = to_platform_driver(drv); if(pdrv->id_table){ return platform_match_id(pdrv->id_table, pdev); } return (strcmp(pdev->name, drv->name) == 0);
platform_drv_probe(struct device *_dev) struct platform_driver *drv = to_platform_ddriver(_dev->driver); struct platform_device *dev = to_platform_device(_dev); drv->probe(dev);
int charDrvInit(void) { platform_device_register(&s3c_device_lcd); platform_driver_register(&s3c2410led_driver); } void __exit charDrvExit(void) { platform_device_unregister(&s3c_device_lcd); platform_driver_unregister(&s3c2410led_driver); }
|