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