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)
12struct 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
37bool siox_device_synced(struct siox_device *sdevice);
38bool siox_device_connected(struct siox_device *sdevice);
39
40struct 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
59static 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
67int __siox_driver_register(struct siox_driver *sdriver, struct module *owner);
68
69static inline int siox_driver_register(struct siox_driver *sdriver)
70{
71 return __siox_driver_register(sdriver, THIS_MODULE);
72}
73
74static inline void siox_driver_unregister(struct siox_driver *sdriver)
75{
76 return driver_unregister(&sdriver->driver);
77}
78