1
0

devicemodel.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 =
  11. (struct devicemodel_data *) (dev->dev.platform_data);
  12. pr_info("devicemodel probe\n");
  13. pr_info("devicemodel greeting: %s; %d\n", pd->greeting, pd->number);
  14. /* Your device initialisation code */
  15. return 0;
  16. }
  17. static int devicemodel_remove(struct platform_device *dev)
  18. {
  19. pr_info("devicemodel example removed\n");
  20. /* Your device removal code */
  21. return 0;
  22. }
  23. static int devicemodel_suspend(struct device *dev)
  24. {
  25. pr_info("devicemodel example suspend\n");
  26. /* Your device suspend code */
  27. return 0;
  28. }
  29. static int devicemodel_resume(struct device *dev)
  30. {
  31. pr_info("devicemodel example resume\n");
  32. /* Your device resume code */
  33. return 0;
  34. }
  35. static const struct dev_pm_ops devicemodel_pm_ops = {
  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. static struct platform_driver devicemodel_driver = {
  43. .driver =
  44. {
  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_DESCRIPTION("Linux Device Model example");
  70. module_init(devicemodel_init);
  71. module_exit(devicemodel_exit);