siox.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (C) 2015 Pengutronix, Uwe Kleine-König <kernel@pengutronix.de>
  3. *
  4. * This program is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU General Public License version 2 as published by the
  6. * Free Software Foundation.
  7. */
  8. #include <linux/device.h>
  9. #define to_siox_device(_dev) container_of((_dev), struct siox_device, dev)
  10. struct siox_device {
  11. struct list_head node; /* node in smaster->devices */
  12. struct siox_master *smaster;
  13. struct device dev;
  14. const char *type;
  15. size_t inbytes;
  16. size_t outbytes;
  17. u8 statustype;
  18. u8 status_read_clean;
  19. u8 status_written;
  20. u8 status_written_lastcycle;
  21. bool connected;
  22. /* statistics */
  23. unsigned int watchdog_errors;
  24. unsigned int status_errors;
  25. struct kernfs_node *status_errors_kn;
  26. struct kernfs_node *watchdog_kn;
  27. struct kernfs_node *watchdog_errors_kn;
  28. struct kernfs_node *connected_kn;
  29. };
  30. bool siox_device_synced(struct siox_device *sdevice);
  31. bool siox_device_connected(struct siox_device *sdevice);
  32. struct siox_driver {
  33. int (*probe)(struct siox_device *sdevice);
  34. int (*remove)(struct siox_device *sdevice);
  35. void (*shutdown)(struct siox_device *sdevice);
  36. /*
  37. * buf is big enough to hold sdev->inbytes - 1 bytes, the status byte
  38. * is in the scope of the framework.
  39. */
  40. int (*set_data)(struct siox_device *sdevice, u8 status, u8 buf[]);
  41. /*
  42. * buf is big enough to hold sdev->outbytes - 1 bytes, the status byte
  43. * is in the scope of the framework
  44. */
  45. int (*get_data)(struct siox_device *sdevice, const u8 buf[]);
  46. struct device_driver driver;
  47. };
  48. static inline struct siox_driver *to_siox_driver(struct device_driver *driver)
  49. {
  50. if (driver)
  51. return container_of(driver, struct siox_driver, driver);
  52. else
  53. return NULL;
  54. }
  55. int __siox_driver_register(struct siox_driver *sdriver, struct module *owner);
  56. static inline int siox_driver_register(struct siox_driver *sdriver)
  57. {
  58. return __siox_driver_register(sdriver, THIS_MODULE);
  59. }
  60. static inline void siox_driver_unregister(struct siox_driver *sdriver)
  61. {
  62. return driver_unregister(&sdriver->driver);
  63. }