xref: /openbmc/linux/drivers/siox/siox.h (revision b830f94f)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (C) 2015-2017 Pengutronix, Uwe Kleine-König <kernel@pengutronix.de>
4  */
5 #include <linux/kernel.h>
6 #include <linux/kthread.h>
7 #include <linux/siox.h>
8 
9 #define to_siox_master(_dev)	container_of((_dev), struct siox_master, dev)
10 struct siox_master {
11 	/* these fields should be initialized by the driver */
12 	int busno;
13 	int (*pushpull)(struct siox_master *smaster,
14 			size_t setbuf_len, const u8 setbuf[],
15 			size_t getbuf_len, u8 getbuf[]);
16 
17 	/* might be initialized by the driver, if 0 it is set to HZ / 40 */
18 	unsigned long poll_interval; /* in jiffies */
19 
20 	/* framework private stuff */
21 	struct mutex lock;
22 	bool active;
23 	struct module *owner;
24 	struct device dev;
25 	unsigned int num_devices;
26 	struct list_head devices;
27 
28 	size_t setbuf_len, getbuf_len;
29 	size_t buf_len;
30 	u8 *buf;
31 	u8 status;
32 
33 	unsigned long last_poll;
34 	struct task_struct *poll_thread;
35 };
36 
37 static inline void *siox_master_get_devdata(struct siox_master *smaster)
38 {
39 	return dev_get_drvdata(&smaster->dev);
40 }
41 
42 struct siox_master *siox_master_alloc(struct device *dev, size_t size);
43 static inline void siox_master_put(struct siox_master *smaster)
44 {
45 	put_device(&smaster->dev);
46 }
47 
48 int siox_master_register(struct siox_master *smaster);
49 void siox_master_unregister(struct siox_master *smaster);
50