summaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpio-idio-16.h
diff options
context:
space:
mode:
authorWilliam Breathitt Gray <william.gray@linaro.org>2022-09-18 12:50:43 -0400
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>2022-10-25 09:56:46 +0200
commitb9b1fc1ae1191243d3956888c65a280a9b2c847f (patch)
tree0da9df8e0d043ec8797153465153d619be73f7a2 /drivers/gpio/gpio-idio-16.h
parent6de0cb80e601df16f481a614daa0e84adbf0b552 (diff)
downloadlinux-stable-b9b1fc1ae1191243d3956888c65a280a9b2c847f.tar.gz
linux-stable-b9b1fc1ae1191243d3956888c65a280a9b2c847f.tar.bz2
linux-stable-b9b1fc1ae1191243d3956888c65a280a9b2c847f.zip
gpio: idio-16: Introduce the ACCES IDIO-16 GPIO library module
Exposes consumer library functions to facilitate communication with devices within the ACCES IDIO-16 family such as the 104-IDIO-16 and the PCI-IDIO-16. A CONFIG_GPIO_IDIO_16 Kconfig option is introduced by this patch. Modules wanting access to these idio-16 library functions should select this Kconfig option and import the GPIO_IDIO_16 symbol namespace. Cc: Andy Shevchenko <andriy.shevchenko@intel.com> Signed-off-by: William Breathitt Gray <william.gray@linaro.org> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Diffstat (limited to 'drivers/gpio/gpio-idio-16.h')
-rw-r--r--drivers/gpio/gpio-idio-16.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/drivers/gpio/gpio-idio-16.h b/drivers/gpio/gpio-idio-16.h
new file mode 100644
index 000000000000..928f8251a2bd
--- /dev/null
+++ b/drivers/gpio/gpio-idio-16.h
@@ -0,0 +1,71 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright 2022 William Breathitt Gray */
+#ifndef _IDIO_16_H_
+#define _IDIO_16_H_
+
+#include <linux/spinlock.h>
+#include <linux/types.h>
+
+/**
+ * struct idio_16 - IDIO-16 registers structure
+ * @out0_7: Read: FET Drive Outputs 0-7
+ * Write: FET Drive Outputs 0-7
+ * @in0_7: Read: Isolated Inputs 0-7
+ * Write: Clear Interrupt
+ * @irq_ctl: Read: Enable IRQ
+ * Write: Disable IRQ
+ * @filter_ctl: Read: Activate Input Filters 0-15
+ * Write: Deactivate Input Filters 0-15
+ * @out8_15: Read: FET Drive Outputs 8-15
+ * Write: FET Drive Outputs 8-15
+ * @in8_15: Read: Isolated Inputs 8-15
+ * Write: Unused
+ * @irq_status: Read: Interrupt status
+ * Write: Unused
+ */
+struct idio_16 {
+ u8 out0_7;
+ u8 in0_7;
+ u8 irq_ctl;
+ u8 filter_ctl;
+ u8 out8_15;
+ u8 in8_15;
+ u8 irq_status;
+};
+
+#define IDIO_16_NOUT 16
+
+/**
+ * struct idio_16_state - IDIO-16 state structure
+ * @lock: synchronization lock for accessing device state
+ * @out_state: output signals state
+ */
+struct idio_16_state {
+ spinlock_t lock;
+ DECLARE_BITMAP(out_state, IDIO_16_NOUT);
+};
+
+/**
+ * idio_16_get_direction - get the I/O direction for a signal offset
+ * @offset: offset of signal to get direction
+ *
+ * Returns the signal direction (0=output, 1=input) for the signal at @offset.
+ */
+static inline int idio_16_get_direction(const unsigned long offset)
+{
+ return (offset >= IDIO_16_NOUT) ? 1 : 0;
+}
+
+int idio_16_get(struct idio_16 __iomem *reg, struct idio_16_state *state,
+ unsigned long offset);
+void idio_16_get_multiple(struct idio_16 __iomem *reg,
+ struct idio_16_state *state,
+ const unsigned long *mask, unsigned long *bits);
+void idio_16_set(struct idio_16 __iomem *reg, struct idio_16_state *state,
+ unsigned long offset, unsigned long value);
+void idio_16_set_multiple(struct idio_16 __iomem *reg,
+ struct idio_16_state *state,
+ const unsigned long *mask, const unsigned long *bits);
+void idio_16_state_init(struct idio_16_state *state);
+
+#endif /* _IDIO_16_H_ */