devicemodel.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include <linux/kernel.h>
  2. #include <linux/module.h>
  3. #include <linux/platform_device.h>
  4. struct devicemodel_data {
  5. char *greeting;
  6. int number;
  7. };
  8. static int devicemodel_probe(struct platform_device *dev)
  9. {
  10. struct devicemodel_data *pd = (struct devicemodel_data *)(dev->dev.platform_data);
  11. pr_info("devicemodel probe\n");
  12. pr_info("devicemodel greeting: %s; %d\n", pd->greeting, pd->number);
  13. /* Your device initialisation code */
  14. return 0;
  15. }
  16. static int devicemodel_remove(struct platform_device *dev)
  17. {
  18. pr_info("devicemodel example removed\n");
  19. /* Your device removal code */
  20. return 0;
  21. }
  22. static int devicemodel_suspend(struct device *dev)
  23. {
  24. pr_info("devicemodel example suspend\n");
  25. /* Your device suspend code */
  26. return 0;
  27. }
  28. static int devicemodel_resume(struct device *dev)
  29. {
  30. pr_info("devicemodel example resume\n");
  31. /* Your device resume code */
  32. return 0;
  33. }
  34. static const struct dev_pm_ops devicemodel_pm_ops =
  35. {
  36. .suspend = devicemodel_suspend,
  37. .resume = devicemodel_resume,
  38. .poweroff = devicemodel_suspend,
  39. .freeze = devicemodel_suspend,
  40. .thaw = devicemodel_resume,
  41. .restore = devicemodel_resume
  42. };
  43. static struct platform_driver devicemodel_driver = {
  44. .driver = {
  45. .name = "devicemodel_example",
  46. .owner = THIS_MODULE,
  47. .pm = &devicemodel_pm_ops,
  48. },
  49. .probe = devicemodel_probe,
  50. .remove = devicemodel_remove,
  51. };
  52. static int devicemodel_init(void)
  53. {
  54. int ret;
  55. pr_info("devicemodel init\n");
  56. ret = platform_driver_register(&devicemodel_driver);
  57. if (ret) {
  58. pr_err("Unable to register driver\n");
  59. return ret;
  60. }
  61. return 0;
  62. }
  63. static void devicemodel_exit(void)
  64. {
  65. pr_info("devicemodel exit\n");
  66. platform_driver_unregister(&devicemodel_driver);
  67. }
  68. MODULE_LICENSE("GPL");
  69. MODULE_AUTHOR("Bob Mottram");
  70. MODULE_DESCRIPTION("Linux Device Model example");
  71. module_init(devicemodel_init);
  72. module_exit(devicemodel_exit);