Commit bdf034d9 authored by Julian Andres Klode's avatar Julian Andres Klode Committed by Greg Kroah-Hartman

staging: nvec: Document public and private API

Add kernel-doc comments describing the functions
and structs we currently have.
Signed-off-by: default avatarJulian Andres Klode <jak@jak-linux.org>
Acked-by: default avatarMarc Dietrich <marvin24@gmx.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 1b9bf629
...@@ -71,6 +71,15 @@ static struct mfd_cell nvec_devices[] = { ...@@ -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, int nvec_register_notifier(struct nvec_chip *nvec, struct notifier_block *nb,
unsigned int events) unsigned int events)
{ {
...@@ -78,6 +87,12 @@ int nvec_register_notifier(struct nvec_chip *nvec, struct notifier_block *nb, ...@@ -78,6 +87,12 @@ int nvec_register_notifier(struct nvec_chip *nvec, struct notifier_block *nb,
} }
EXPORT_SYMBOL_GPL(nvec_register_notifier); 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, static int nvec_status_notifier(struct notifier_block *nb,
unsigned long event_type, void *data) unsigned long event_type, void *data)
{ {
...@@ -93,6 +108,14 @@ static int nvec_status_notifier(struct notifier_block *nb, ...@@ -93,6 +108,14 @@ static int nvec_status_notifier(struct notifier_block *nb,
return NOTIFY_OK; 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) static struct nvec_msg *nvec_msg_alloc(struct nvec_chip *nvec)
{ {
int i; int i;
...@@ -109,6 +132,13 @@ static struct nvec_msg *nvec_msg_alloc(struct nvec_chip *nvec) ...@@ -109,6 +132,13 @@ static struct nvec_msg *nvec_msg_alloc(struct nvec_chip *nvec)
return NULL; 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) static void nvec_msg_free(struct nvec_chip *nvec, struct nvec_msg *msg)
{ {
if (msg != &nvec->tx_scratch) if (msg != &nvec->tx_scratch)
...@@ -147,6 +177,13 @@ static size_t nvec_msg_size(struct nvec_msg *msg) ...@@ -147,6 +177,13 @@ static size_t nvec_msg_size(struct nvec_msg *msg)
return 0; 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) static void nvec_gpio_set_value(struct nvec_chip *nvec, int value)
{ {
dev_dbg(nvec->dev, "GPIO changed from %u to %u\n", dev_dbg(nvec->dev, "GPIO changed from %u to %u\n",
...@@ -154,6 +191,18 @@ static void nvec_gpio_set_value(struct nvec_chip *nvec, int value) ...@@ -154,6 +191,18 @@ static void nvec_gpio_set_value(struct nvec_chip *nvec, int value)
gpio_set_value(nvec->gpio, 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, int nvec_write_async(struct nvec_chip *nvec, const unsigned char *data,
short size) short size)
{ {
...@@ -178,6 +227,20 @@ int nvec_write_async(struct nvec_chip *nvec, const unsigned char *data, ...@@ -178,6 +227,20 @@ int nvec_write_async(struct nvec_chip *nvec, const unsigned char *data,
} }
EXPORT_SYMBOL(nvec_write_async); 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, struct nvec_msg *nvec_write_sync(struct nvec_chip *nvec,
const unsigned char *data, short size) const unsigned char *data, short size)
{ {
...@@ -209,7 +272,14 @@ struct nvec_msg *nvec_write_sync(struct nvec_chip *nvec, ...@@ -209,7 +272,14 @@ struct nvec_msg *nvec_write_sync(struct nvec_chip *nvec,
} }
EXPORT_SYMBOL(nvec_write_sync); 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) static void nvec_request_master(struct work_struct *work)
{ {
struct nvec_chip *nvec = container_of(work, struct nvec_chip, tx_work); struct nvec_chip *nvec = container_of(work, struct nvec_chip, tx_work);
...@@ -241,6 +311,14 @@ static void nvec_request_master(struct work_struct *work) ...@@ -241,6 +311,14 @@ static void nvec_request_master(struct work_struct *work)
spin_unlock_irqrestore(&nvec->tx_lock, flags); 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) static int parse_msg(struct nvec_chip *nvec, struct nvec_msg *msg)
{ {
if ((msg->data[0] & 1 << 7) == 0 && msg->data[3]) { if ((msg->data[0] & 1 << 7) == 0 && msg->data[3]) {
...@@ -260,7 +338,13 @@ static int parse_msg(struct nvec_chip *nvec, struct nvec_msg *msg) ...@@ -260,7 +338,13 @@ static int parse_msg(struct nvec_chip *nvec, struct nvec_msg *msg)
return 0; 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) static void nvec_dispatch(struct work_struct *work)
{ {
struct nvec_chip *nvec = container_of(work, struct nvec_chip, rx_work); struct nvec_chip *nvec = container_of(work, struct nvec_chip, rx_work);
...@@ -288,6 +372,12 @@ static void nvec_dispatch(struct work_struct *work) ...@@ -288,6 +372,12 @@ static void nvec_dispatch(struct work_struct *work)
spin_unlock_irqrestore(&nvec->rx_lock, flags); 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) static void nvec_tx_completed(struct nvec_chip *nvec)
{ {
/* We got an END_TRANS, let's skip this, maybe there's an event */ /* We got an END_TRANS, let's skip this, maybe there's an event */
...@@ -300,6 +390,12 @@ static void nvec_tx_completed(struct nvec_chip *nvec) ...@@ -300,6 +390,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) static void nvec_rx_completed(struct nvec_chip *nvec)
{ {
if (nvec->rx->pos != nvec_msg_size(nvec->rx)) if (nvec->rx->pos != nvec_msg_size(nvec->rx))
...@@ -340,6 +436,11 @@ static void nvec_invalid_flags(struct nvec_chip *nvec, unsigned int status, ...@@ -340,6 +436,11 @@ static void nvec_invalid_flags(struct nvec_chip *nvec, unsigned int status,
/** /**
* nvec_tx_set - Set the message to transfer (nvec->tx) * 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) static void nvec_tx_set(struct nvec_chip *nvec)
{ {
...@@ -366,6 +467,10 @@ static void nvec_tx_set(struct nvec_chip *nvec) ...@@ -366,6 +467,10 @@ static void nvec_tx_set(struct nvec_chip *nvec)
* nvec_interrupt - Interrupt handler * nvec_interrupt - Interrupt handler
* @irq: The IRQ * @irq: The IRQ
* @dev: The nvec device * @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) static irqreturn_t nvec_interrupt(int irq, void *dev)
{ {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* Authors: Pierre-Hugues Husson <phhusson@free.fr> * Authors: Pierre-Hugues Husson <phhusson@free.fr>
* Ilya Petrov <ilya.muromec@gmail.com> * Ilya Petrov <ilya.muromec@gmail.com>
* Marc Dietrich <marvin24@gmx.de> * Marc Dietrich <marvin24@gmx.de>
* Julian Andres Klode <jak@jak-linux.org>
* *
* This file is subject to the terms and conditions of the GNU General Public * 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 * License. See the file "COPYING" in the main directory of this archive
...@@ -32,13 +33,37 @@ ...@@ -32,13 +33,37 @@
*/ */
#define NVEC_MSG_SIZE 34 #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_2BYTES,
NVEC_3BYTES, NVEC_3BYTES,
NVEC_VAR_SIZE, 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_SYS = 1,
NVEC_BAT, NVEC_BAT,
NVEC_KBD = 5, NVEC_KBD = 5,
...@@ -48,6 +73,19 @@ enum { ...@@ -48,6 +73,19 @@ enum {
NVEC_PS2_EVT, 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 nvec_msg {
struct list_head node; struct list_head node;
unsigned char data[NVEC_MSG_SIZE]; unsigned char data[NVEC_MSG_SIZE];
...@@ -56,17 +94,61 @@ struct nvec_msg { ...@@ -56,17 +94,61 @@ struct nvec_msg {
atomic_t used; 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 { struct nvec_subdev {
const char *name; const char *name;
void *platform_data; void *platform_data;
int id; 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 { struct nvec_platform_data {
int i2c_addr; int i2c_addr;
int gpio; 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 nvec_chip {
struct device *dev; struct device *dev;
int gpio; int gpio;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment