[PATCH 17/30] staging: nvec: Document public and private API

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

 



Add kernel-doc comments describing the functions
and structs we currently have.

Signed-off-by: Julian Andres Klode <jak@xxxxxxxxxxxxx>
---
 drivers/staging/nvec/nvec.c |  109 ++++++++++++++++++++++++++++++++++++++++++-
 drivers/staging/nvec/nvec.h |   86 +++++++++++++++++++++++++++++++++-
 2 files changed, 191 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/nvec/nvec.c b/drivers/staging/nvec/nvec.c
index bad3389..4df2fd8 100644
--- a/drivers/staging/nvec/nvec.c
+++ b/drivers/staging/nvec/nvec.c
@@ -71,6 +71,15 @@ static struct mfd_cell nvec_devices[] = {
 	},
 };
 
+/**
+ * nvec_register_notifier - Register a notifier with nvec
+ * @nvec: A &struct nvec_chip
+ * @nb: The notifier block to register
+ *
+ * Registers a notifier with @nvec. The notifier will be added to an atomic
+ * notifier chain that is called for all received messages except those that
+ * correspond to a request initiated by nvec_write_sync().
+ */
 int nvec_register_notifier(struct nvec_chip *nvec, struct notifier_block *nb,
 			   unsigned int events)
 {
@@ -78,6 +87,12 @@ int nvec_register_notifier(struct nvec_chip *nvec, struct notifier_block *nb,
 }
 EXPORT_SYMBOL_GPL(nvec_register_notifier);
 
+/**
+ * nvec_status_notifier - The final notifier
+ *
+ * Prints a message about control events not handled in the notifier
+ * chain.
+ */
 static int nvec_status_notifier(struct notifier_block *nb,
 				unsigned long event_type, void *data)
 {
@@ -93,6 +108,14 @@ static int nvec_status_notifier(struct notifier_block *nb,
 	return NOTIFY_OK;
 }
 
+/**
+ * nvec_msg_alloc:
+ * @nvec: A &struct nvec_chip
+ *
+ * Allocate a single &struct nvec_msg object from the message pool of
+ * @nvec. The result shall be passed to nvec_msg_free() if no longer
+ * used.
+ */
 static struct nvec_msg *nvec_msg_alloc(struct nvec_chip *nvec)
 {
 	size_t i;
@@ -107,6 +130,13 @@ static struct nvec_msg *nvec_msg_alloc(struct nvec_chip *nvec)
 	return NULL;
 }
 
+/**
+ * nvec_msg_free:
+ * @nvec: A &struct nvec_chip
+ * @msg:  A message (must be allocated by nvec_msg_alloc() and belong to @nvec)
+ *
+ * Free the given message
+ */
 static void nvec_msg_free(struct nvec_chip *nvec, struct nvec_msg *msg)
 {
 	dev_vdbg(nvec->dev, "INFO: Free %i\n", (int) (msg - nvec->msg_pool));
@@ -144,6 +174,13 @@ static size_t nvec_msg_size(struct nvec_msg *msg)
 		return 0;
 }
 
+/**
+ * nvec_gpio_set_value - Set the GPIO value
+ * @nvec: A &struct nvec_chip
+ * @value: The value to write (0 or 1)
+ *
+ * Like gpio_set_value(), but generating debugging information
+ */
 static void nvec_gpio_set_value(struct nvec_chip *nvec, int value)
 {
 	dev_dbg(nvec->dev, "GPIO changed from %u to %u\n",
@@ -151,6 +188,18 @@ static void nvec_gpio_set_value(struct nvec_chip *nvec, int value)
 	gpio_set_value(nvec->gpio, value);
 }
 
+/**
+ * nvec_write_async - Asynchronously write a message to NVEC
+ * @nvec: An nvec_chip instance
+ * @data: The message data, starting with the request type
+ * @size: The size of @data
+ *
+ * Queue a single message to be transferred to the embedded controller
+ * and return immediately.
+ *
+ * Returns: 0 on success, a negative error code on failure. If a failure
+ * occured, the nvec driver may print an error.
+ */
 int nvec_write_async(struct nvec_chip *nvec, const unsigned char *data,
 			short size)
 {
@@ -175,6 +224,20 @@ int nvec_write_async(struct nvec_chip *nvec, const unsigned char *data,
 }
 EXPORT_SYMBOL(nvec_write_async);
 
+/**
+ * nvec_write_sync - Write a message to nvec and read the response
+ * @nvec: An &struct nvec_chip
+ * @data: The data to write
+ * @size: The size of @data
+ *
+ * This is similar to nvec_write_async(), but waits for the
+ * request to be answered before returning. This function
+ * uses a mutex and can thus not be called from e.g.
+ * interrupt handlers.
+ *
+ * Returns: A pointer to the response message on success,
+ * %NULL on failure.
+ */
 struct nvec_msg *nvec_write_sync(struct nvec_chip *nvec,
 		const unsigned char *data, short size)
 {
@@ -202,7 +265,14 @@ struct nvec_msg *nvec_write_sync(struct nvec_chip *nvec,
 }
 EXPORT_SYMBOL(nvec_write_sync);
 
-/* TX worker */
+/**
+ * nvec_request_master - Process outgoing messages
+ * @work: A &struct work_struct (the tx_worker member of &struct nvec_chip)
+ *
+ * Processes all outgoing requests by sending the request and awaiting the
+ * response, then continuing with the next request. Once a request has a
+ * matching response, it will be freed and removed from the list.
+ */
 static void nvec_request_master(struct work_struct *work)
 {
 	struct nvec_chip *nvec = container_of(work, struct nvec_chip, tx_work);
@@ -228,6 +298,14 @@ static void nvec_request_master(struct work_struct *work)
 	spin_unlock_irqrestore(&nvec->tx_lock, flags);
 }
 
+/**
+ * parse_msg - Print some information and call the notifiers on an RX message
+ * @nvec: A &struct nvec_chip
+ * @msg: A message received by @nvec
+ *
+ * Paarse some pieces of the message and then call the chain of notifiers
+ * registered via nvec_register_notifier.
+ */
 static int parse_msg(struct nvec_chip *nvec, struct nvec_msg *msg)
 {
 	if ((msg->data[0] & 1 << 7) == 0 && msg->data[3]) {
@@ -247,7 +325,13 @@ static int parse_msg(struct nvec_chip *nvec, struct nvec_msg *msg)
 	return 0;
 }
 
-/* RX worker */
+/**
+ * nvec_dispatch - Process messages received from the EC
+ * @work: A &struct work_struct (the tx_worker member of &struct nvec_chip)
+ *
+ * Process messages previously received from the EC and put into the RX
+ * queue of the &struct nvec_chip instance associated with @work.
+ */
 static void nvec_dispatch(struct work_struct *work)
 {
 	struct nvec_chip *nvec = container_of(work, struct nvec_chip, rx_work);
@@ -275,6 +359,12 @@ static void nvec_dispatch(struct work_struct *work)
 	spin_unlock_irqrestore(&nvec->rx_lock, flags);
 }
 
+/**
+ * nvec_tx_completed - Complete the current transfer
+ * @nvec: A &struct nvec_chip
+ *
+ * This is called when we have received an END_TRANS on a TX transfer.
+ */
 static void nvec_tx_completed(struct nvec_chip *nvec)
 {
 	/* We got an END_TRANS, let's skip this, maybe there's an event */
@@ -287,6 +377,12 @@ static void nvec_tx_completed(struct nvec_chip *nvec)
 	}
 }
 
+/**
+ * nvec_rx_completed - Complete the current transfer
+ * @nvec: A &struct nvec_chip
+ *
+ * This is called when we have received an END_TRANS on a RX transfer.
+ */
 static void nvec_rx_completed(struct nvec_chip *nvec)
 {
 	unsigned long flags;
@@ -329,6 +425,11 @@ static void nvec_invalid_flags(struct nvec_chip *nvec, unsigned int status,
 
 /**
  * nvec_tx_set - Set the message to transfer (nvec->tx)
+ * @nvec: A &struct nvec_chip
+ *
+ * Gets the first entry from the tx_data list of @nvec and sets the
+ * tx member to it. If the tx_data list is empty, this uses the
+ * tx_scratch message to send a no operation message.
  */
 static void nvec_tx_set(struct nvec_chip *nvec)
 {
@@ -357,6 +458,10 @@ static void nvec_tx_set(struct nvec_chip *nvec)
  * nvec_interrupt - Interrupt handler
  * @irq: The IRQ
  * @dev: The nvec device
+ *
+ * Interrupt handler that fills our RX buffers and empties our TX
+ * buffers. This uses a finite state machine with ridiculous amounts
+ * of error checking, in order to be fairly reliable.
  */
 static irqreturn_t nvec_interrupt(int irq, void *dev)
 {
diff --git a/drivers/staging/nvec/nvec.h b/drivers/staging/nvec/nvec.h
index 333cb2e..29e0f2f 100644
--- a/drivers/staging/nvec/nvec.h
+++ b/drivers/staging/nvec/nvec.h
@@ -6,6 +6,7 @@
  * Authors:  Pierre-Hugues Husson <phhusson@xxxxxxx>
  *           Ilya Petrov <ilya.muromec@xxxxxxxxx>
  *           Marc Dietrich <marvin24@xxxxxx>
+ *           Julian Andres Klode <jak@xxxxxxxxxxxxx>
  *
  * This file is subject to the terms and conditions of the GNU General Public
  * License.  See the file "COPYING" in the main directory of this archive
@@ -32,13 +33,37 @@
  */
 #define NVEC_MSG_SIZE	34
 
-enum {
+/**
+ * enum nvec_event_size - The size of an event message
+ * @NVEC_2BYTES: The message has one command byte and one data byte
+ * @NVEC_3BYTES: The message has one command byte and two data bytes
+ * @NVEC_VAR_SIZE: The message has one command byte, one count byte, and as
+ *                 up to as many bytes as the number in the count byte. The
+ *                 maximum is 32
+ *
+ * Events can be fixed or variable sized. This is useless on other message
+ * types, which are always variable sized.
+ */
+enum nvec_event_size {
 	NVEC_2BYTES,
 	NVEC_3BYTES,
 	NVEC_VAR_SIZE,
 };
 
-enum {
+/**
+ * enum nvec_msg_type - The type of a message
+ * @NVEC_SYS: A system request/response
+ * @NVEC_BAT: A battery request/response
+ * @NVEC_KBD: A keyboard request/response
+ * @NVEC_PS2: A mouse request/response
+ * @NVEC_CNTL: A EC control request/response
+ * @NVEC_KB_EVT: An event from the keyboard
+ * @NVEC_PS2_EVT: An event from the mouse
+ *
+ * Events can be fixed or variable sized. This is useless on other message
+ * types, which are always variable sized.
+ */
+enum nvec_msg_type {
 	NVEC_SYS = 1,
 	NVEC_BAT,
 	NVEC_KBD = 5,
@@ -48,6 +73,19 @@ enum {
 	NVEC_PS2_EVT,
 };
 
+/**
+ * struct nvec_msg - A buffer for a single message
+ * @node: Messages are part of various lists in a &struct nvec_chip
+ * @data: The data of the message
+ * @size: For TX messages, the number of bytes used in @data
+ * @pos:  For RX messages, the current position to write to. For TX messages,
+ *        the position to read from.
+ * @used: Used for the message pool to mark a message as free/allocated.
+ *
+ * This structure is used to hold outgoing and incoming messages. Outgoing
+ * messages have a different format than incoming messages, and that is not
+ * documented yet.
+ */
 struct nvec_msg {
 	struct list_head node;
 	unsigned char data[NVEC_MSG_SIZE];
@@ -56,17 +94,61 @@ struct nvec_msg {
 	atomic_t used;
 };
 
+/**
+ * struct nvec_subdev - A subdevice of nvec, such as nvec_kbd
+ * @name: The name of the sub device
+ * @platform_data: Platform data
+ * @id: Identifier of the sub device
+ */
 struct nvec_subdev {
 	const char *name;
 	void *platform_data;
 	int id;
 };
 
+/**
+ * struct nvec_platform_data - platform data for a tegra slave controller
+ * @i2c_addr: number of i2c slave adapter the ec is connected to
+ * @gpio: gpio number for the ec request line
+ *
+ * Platform data, to be used in board definitions. For an example, take a
+ * look at the paz00 board in arch/arm/mach-tegra/board-paz00.c
+ */
 struct nvec_platform_data {
 	int i2c_addr;
 	int gpio;
 };
 
+/**
+ * struct nvec_chip - A single connection to an NVIDIA Embedded controller
+ * @dev: The device
+ * @gpio: The same as for &struct nvec_platform_data
+ * @irq: The IRQ of the I2C device
+ * @i2c_addr: The address of the I2C slave
+ * @base: The base of the memory mapped region of the I2C device
+ * @clk: The clock of the I2C device
+ * @notifier_list: Notifiers to be called on received messages, see
+ *                 nvec_register_notifier()
+ * @rx_data: Received messages that have to be processed
+ * @tx_data: Messages waiting to be sent to the controller
+ * @nvec_status_notifier: Internal notifier (see nvec_status_notifier())
+ * @rx_work: A work structure for the RX worker nvec_dispatch()
+ * @tx_work: A work structure for the TX worker nvec_request_master()
+ * @wq: The work queue in which @rx_work and @tx_work are executed
+ * @rx: The message currently being retrieved or %NULL
+ * @msg_pool: A pool of messages for allocation
+ * @tx: The message currently being transferred
+ * @tx_scratch: Used for building pseudo messages
+ * @ec_transfer: A completion that will be completed once a message has been
+ *               received (see nvec_rx_completed())
+ * @tx_lock: Spinlock for modifications on @tx_data
+ * @rx_lock: Spinlock for modifications on @rx_data
+ * @sync_write_mutex: A mutex for nvec_write_sync()
+ * @sync_write: A completion to signal that a synchronous message is complete
+ * @sync_write_pending: The first two bytes of the request (type and subtype)
+ * @last_sync_msg: The last synchronous message.
+ * @state: State of our finite state machine used in nvec_interrupt()
+ */
 struct nvec_chip {
 	struct device *dev;
 	int gpio;
-- 
1.7.5.4

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


[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux