Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[DRIVER MODEL] Add platform_driver

Introduce struct platform_driver. This allows the platform device
driver methods to be passed a platform_device structure instead of
instead of a plain device structure, and therefore requiring casting
in every platform driver.

We introduce this in such a way that any existing platform drivers
registered directly via driver_register continue to work as before,
thereby allowing a gradual conversion to the new platform_driver
methods.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Russell King and committed by
Russell King
00d3dcdd 330d57fb

+88
+73
drivers/base/platform.c
··· 20 20 21 21 #include "base.h" 22 22 23 + #define to_platform_driver(drv) (container_of((drv), struct platform_driver, driver)) 24 + 23 25 struct device platform_bus = { 24 26 .bus_id = "platform", 25 27 }; ··· 355 353 platform_device_put(pdev); 356 354 return ERR_PTR(retval); 357 355 } 356 + 357 + static int platform_drv_probe(struct device *_dev) 358 + { 359 + struct platform_driver *drv = to_platform_driver(_dev->driver); 360 + struct platform_device *dev = to_platform_device(_dev); 361 + 362 + return drv->probe(dev); 363 + } 364 + 365 + static int platform_drv_remove(struct device *_dev) 366 + { 367 + struct platform_driver *drv = to_platform_driver(_dev->driver); 368 + struct platform_device *dev = to_platform_device(_dev); 369 + 370 + return drv->remove(dev); 371 + } 372 + 373 + static void platform_drv_shutdown(struct device *_dev) 374 + { 375 + struct platform_driver *drv = to_platform_driver(_dev->driver); 376 + struct platform_device *dev = to_platform_device(_dev); 377 + 378 + drv->shutdown(dev); 379 + } 380 + 381 + static int platform_drv_suspend(struct device *_dev, pm_message_t state) 382 + { 383 + struct platform_driver *drv = to_platform_driver(_dev->driver); 384 + struct platform_device *dev = to_platform_device(_dev); 385 + 386 + return drv->suspend(dev, state); 387 + } 388 + 389 + static int platform_drv_resume(struct device *_dev) 390 + { 391 + struct platform_driver *drv = to_platform_driver(_dev->driver); 392 + struct platform_device *dev = to_platform_device(_dev); 393 + 394 + return drv->resume(dev); 395 + } 396 + 397 + /** 398 + * platform_driver_register 399 + * @drv: platform driver structure 400 + */ 401 + int platform_driver_register(struct platform_driver *drv) 402 + { 403 + drv->driver.bus = &platform_bus_type; 404 + if (drv->probe) 405 + drv->driver.probe = platform_drv_probe; 406 + if (drv->remove) 407 + drv->driver.remove = platform_drv_remove; 408 + if (drv->shutdown) 409 + drv->driver.shutdown = platform_drv_shutdown; 410 + if (drv->suspend) 411 + drv->driver.suspend = platform_drv_suspend; 412 + if (drv->resume) 413 + drv->driver.resume = platform_drv_resume; 414 + return driver_register(&drv->driver); 415 + } 416 + EXPORT_SYMBOL_GPL(platform_driver_register); 417 + 418 + /** 419 + * platform_driver_unregister 420 + * @drv: platform driver structure 421 + */ 422 + void platform_driver_unregister(struct platform_driver *drv) 423 + { 424 + driver_unregister(&drv->driver); 425 + } 426 + EXPORT_SYMBOL_GPL(platform_driver_unregister); 358 427 359 428 360 429 /**
+15
include/linux/platform_device.h
··· 43 43 extern int platform_device_add(struct platform_device *pdev); 44 44 extern void platform_device_put(struct platform_device *pdev); 45 45 46 + struct platform_driver { 47 + int (*probe)(struct platform_device *); 48 + int (*remove)(struct platform_device *); 49 + void (*shutdown)(struct platform_device *); 50 + int (*suspend)(struct platform_device *, pm_message_t state); 51 + int (*resume)(struct platform_device *); 52 + struct device_driver driver; 53 + }; 54 + 55 + extern int platform_driver_register(struct platform_driver *); 56 + extern void platform_driver_unregister(struct platform_driver *); 57 + 58 + #define platform_get_drvdata(_dev) dev_get_drvdata(&(_dev)->dev) 59 + #define platform_set_drvdata(_dev,data) dev_set_drvdata(&(_dev)->dev, (data)) 60 + 46 61 #endif /* _PLATFORM_DEVICE_H_ */