[PATCH 3/5] staging: nvec: add NVEC_CALL helper macro

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


Add a helper macro to wrap nvec_{a}sync_writes and to get rid of
the various strings distributed all over the nvec code.

Signed-off-by: Marc Dietrich <marvin24@xxxxxx>
---
 drivers/staging/nvec/nvec.h |   38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/drivers/staging/nvec/nvec.h b/drivers/staging/nvec/nvec.h
index ba6ed8f..3291767 100644
--- a/drivers/staging/nvec/nvec.h
+++ b/drivers/staging/nvec/nvec.h
@@ -78,6 +78,44 @@ enum nvec_msg_type {
 	NVEC_PS2_EVT,
 };
 
+/* construct a nvec command string */
+#define NVEC_CMD_STR(type, subtype, payload...)		\
+    { NVEC_##type, NVEC_##type##_##subtype, payload }
+
+/*
+ * NVEC_CALL: submit an async nvec command string
+ * @nvec: holds the pointer to the nvec handle
+ * @type: contains the message type (see nvec_msg_type)
+ * @subtype: contains the message sub-type
+ * @payload: contains pointer to an array of char for the payload
+ * returns -ENOMEM if the send buffer is full or 0.
+ */
+#ifdef DEBUG
+#define NVEC_CALL(nvec, type, subtype, payload...) (		\
+    {								\
+	char buf[] = NVEC_CMD_STR(type, subtype, payload);	\
+	print_hex_dump(KERN_WARNING, "payload: ", DUMP_PREFIX_NONE, 16, 1, \
+		buf, sizeof(buf), false);			\
+	nvec_write_async((nvec), buf, sizeof(buf));		\
+    })
+#else
+#define NVEC_CALL(nvec, type, subtype, payload...) (		\
+    {								\
+	char buf[] = NVEC_CMD_STR(type, subtype, payload);	\
+	nvec_write_async((nvec), buf, sizeof(buf));		\
+    })
+#endif
+
+/**
+  * NVEC_SYNC_CALL: submit a nvec command string synchronously
+  * same paramters as for async call, but return the received message
+  */
+#define NVEC_SYNC_CALL(nvec, type, subtype, payload...) (	\
+    {								\
+	char buf[] = NVEC_CMD_STR(type, subtype, payload);	\
+	nvec_write_sync((nvec), buf, sizeof(buf));		\
+    })
+
 /**
  * struct nvec_msg - A buffer for a single message
  * @node: Messages are part of various lists in a &struct nvec_chip
-- 
1.7.9.5

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel


[Video for Linux]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Photos]     [Yosemite Photos]     [Free Singles Community]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Devices]     [Yosemite Backpacking]

Add to Google Powered by Linux