siox.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2015 Pengutronix, Uwe Kleine-König <[email protected]>
  4. */
  5. #include <linux/device.h>
  6. #define to_siox_device(_dev) container_of((_dev), struct siox_device, dev)
  7. struct siox_device {
  8. struct list_head node; /* node in smaster->devices */
  9. struct siox_master *smaster;
  10. struct device dev;
  11. const char *type;
  12. size_t inbytes;
  13. size_t outbytes;
  14. u8 statustype;
  15. u8 status_read_clean;
  16. u8 status_written;
  17. u8 status_written_lastcycle;
  18. bool connected;
  19. /* statistics */
  20. unsigned int watchdog_errors;
  21. unsigned int status_errors;
  22. struct kernfs_node *status_errors_kn;
  23. struct kernfs_node *watchdog_kn;
  24. struct kernfs_node *watchdog_errors_kn;
  25. struct kernfs_node *connected_kn;
  26. };
  27. bool siox_device_synced(struct siox_device *sdevice);
  28. bool siox_device_connected(struct siox_device *sdevice);
  29. struct siox_driver {
  30. int (*probe)(struct siox_device *sdevice);
  31. void (*remove)(struct siox_device *sdevice);
  32. void (*shutdown)(struct siox_device *sdevice);
  33. /*
  34. * buf is big enough to hold sdev->inbytes - 1 bytes, the status byte
  35. * is in the scope of the framework.
  36. */
  37. int (*set_data)(struct siox_device *sdevice, u8 status, u8 buf[]);
  38. /*
  39. * buf is big enough to hold sdev->outbytes - 1 bytes, the status byte
  40. * is in the scope of the framework
  41. */
  42. int (*get_data)(struct siox_device *sdevice, const u8 buf[]);
  43. struct device_driver driver;
  44. };
  45. static inline struct siox_driver *to_siox_driver(struct device_driver *driver)
  46. {
  47. if (driver)
  48. return container_of(driver, struct siox_driver, driver);
  49. else
  50. return NULL;
  51. }
  52. int __siox_driver_register(struct siox_driver *sdriver, struct module *owner);
  53. static inline int siox_driver_register(struct siox_driver *sdriver)
  54. {
  55. return __siox_driver_register(sdriver, THIS_MODULE);
  56. }
  57. static inline void siox_driver_unregister(struct siox_driver *sdriver)
  58. {
  59. return driver_unregister(&sdriver->driver);
  60. }
  61. /*
  62. * module_siox_driver() - Helper macro for drivers that don't do
  63. * anything special in module init/exit. This eliminates a lot of
  64. * boilerplate. Each module may only use this macro once, and
  65. * calling it replaces module_init() and module_exit()
  66. */
  67. #define module_siox_driver(__siox_driver) \
  68. module_driver(__siox_driver, siox_driver_register, \
  69. siox_driver_unregister)