xref: /linux/drivers/gpio/gpio-idio-16.h (revision 497e6b37b0099dc415578488287fd84fb74433eb)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright 2022 William Breathitt Gray */
3 #ifndef _IDIO_16_H_
4 #define _IDIO_16_H_
5 
6 #include <linux/spinlock.h>
7 #include <linux/types.h>
8 
9 /**
10  * struct idio_16 - IDIO-16 registers structure
11  * @out0_7:	Read: FET Drive Outputs 0-7
12  *		Write: FET Drive Outputs 0-7
13  * @in0_7:	Read: Isolated Inputs 0-7
14  *		Write: Clear Interrupt
15  * @irq_ctl:	Read: Enable IRQ
16  *		Write: Disable IRQ
17  * @filter_ctl:	Read: Activate Input Filters 0-15
18  *		Write: Deactivate Input Filters 0-15
19  * @out8_15:	Read: FET Drive Outputs 8-15
20  *		Write: FET Drive Outputs 8-15
21  * @in8_15:	Read: Isolated Inputs 8-15
22  *		Write: Unused
23  * @irq_status:	Read: Interrupt status
24  *		Write: Unused
25  */
26 struct idio_16 {
27 	u8 out0_7;
28 	u8 in0_7;
29 	u8 irq_ctl;
30 	u8 filter_ctl;
31 	u8 out8_15;
32 	u8 in8_15;
33 	u8 irq_status;
34 };
35 
36 #define IDIO_16_NOUT 16
37 
38 /**
39  * struct idio_16_state - IDIO-16 state structure
40  * @lock:	synchronization lock for accessing device state
41  * @out_state:	output signals state
42  */
43 struct idio_16_state {
44 	spinlock_t lock;
45 	DECLARE_BITMAP(out_state, IDIO_16_NOUT);
46 };
47 
48 /**
49  * idio_16_get_direction - get the I/O direction for a signal offset
50  * @offset:	offset of signal to get direction
51  *
52  * Returns the signal direction (0=output, 1=input) for the signal at @offset.
53  */
54 static inline int idio_16_get_direction(const unsigned long offset)
55 {
56 	return (offset >= IDIO_16_NOUT) ? 1 : 0;
57 }
58 
59 int idio_16_get(struct idio_16 __iomem *reg, struct idio_16_state *state,
60 		unsigned long offset);
61 void idio_16_get_multiple(struct idio_16 __iomem *reg,
62 			  struct idio_16_state *state,
63 			  const unsigned long *mask, unsigned long *bits);
64 void idio_16_set(struct idio_16 __iomem *reg, struct idio_16_state *state,
65 		 unsigned long offset, unsigned long value);
66 void idio_16_set_multiple(struct idio_16 __iomem *reg,
67 			  struct idio_16_state *state,
68 			  const unsigned long *mask, const unsigned long *bits);
69 void idio_16_state_init(struct idio_16_state *state);
70 
71 #endif /* _IDIO_16_H_ */
72