Merge tag 'asoc-v4.16-5' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie...
[sfrench/cifs-2.6.git] / include / linux / siox.h
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
9 #include <linux/device.h>
10
11 #define to_siox_device(_dev)    container_of((_dev), struct siox_device, dev)
12 struct siox_device {
13         struct list_head node; /* node in smaster->devices */
14         struct siox_master *smaster;
15         struct device dev;
16
17         const char *type;
18         size_t inbytes;
19         size_t outbytes;
20         u8 statustype;
21
22         u8 status_read_clean;
23         u8 status_written;
24         u8 status_written_lastcycle;
25         bool connected;
26
27         /* statistics */
28         unsigned int watchdog_errors;
29         unsigned int status_errors;
30
31         struct kernfs_node *status_errors_kn;
32         struct kernfs_node *watchdog_kn;
33         struct kernfs_node *watchdog_errors_kn;
34         struct kernfs_node *connected_kn;
35 };
36
37 bool siox_device_synced(struct siox_device *sdevice);
38 bool siox_device_connected(struct siox_device *sdevice);
39
40 struct siox_driver {
41         int (*probe)(struct siox_device *sdevice);
42         int (*remove)(struct siox_device *sdevice);
43         void (*shutdown)(struct siox_device *sdevice);
44
45         /*
46          * buf is big enough to hold sdev->inbytes - 1 bytes, the status byte
47          * is in the scope of the framework.
48          */
49         int (*set_data)(struct siox_device *sdevice, u8 status, u8 buf[]);
50         /*
51          * buf is big enough to hold sdev->outbytes - 1 bytes, the status byte
52          * is in the scope of the framework
53          */
54         int (*get_data)(struct siox_device *sdevice, const u8 buf[]);
55
56         struct device_driver driver;
57 };
58
59 static inline struct siox_driver *to_siox_driver(struct device_driver *driver)
60 {
61         if (driver)
62                 return container_of(driver, struct siox_driver, driver);
63         else
64                 return NULL;
65 }
66
67 int __siox_driver_register(struct siox_driver *sdriver, struct module *owner);
68
69 static inline int siox_driver_register(struct siox_driver *sdriver)
70 {
71         return __siox_driver_register(sdriver, THIS_MODULE);
72 }
73
74 static inline void siox_driver_unregister(struct siox_driver *sdriver)
75 {
76         return driver_unregister(&sdriver->driver);
77 }