aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/nvec
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@jak-linux.org>2011-09-27 19:00:48 +0200
committerGreg Kroah-Hartman <gregkh@suse.de>2011-09-29 17:40:40 -0700
commit0b1076c4b2a06e517fafbb2b4704f23e69b05386 (patch)
treed6d3b853d09e5305fa6c781cf0030306ca87571f /drivers/staging/nvec
parentstaging: nvec: fix Kconfig dependencies (diff)
downloadlinux-dev-0b1076c4b2a06e517fafbb2b4704f23e69b05386.tar.xz
linux-dev-0b1076c4b2a06e517fafbb2b4704f23e69b05386.zip
staging: nvec: Introduce new internal API for msg alloc/free
Introduce two new functions nvec_msg_alloc() and nvec_msg_free() that allocate and free message buffers from the internal pool of messages. Signed-off-by: Julian Andres Klode <jak@jak-linux.org> Acked-by: Marc Dietrich <marvin24@gmx.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/nvec')
-rw-r--r--drivers/staging/nvec/nvec.c23
-rw-r--r--drivers/staging/nvec/nvec.h6
2 files changed, 29 insertions, 0 deletions
diff --git a/drivers/staging/nvec/nvec.c b/drivers/staging/nvec/nvec.c
index 43a83a953d46..fb0f51a2b0bf 100644
--- a/drivers/staging/nvec/nvec.c
+++ b/drivers/staging/nvec/nvec.c
@@ -17,6 +17,7 @@
#include <asm/irq.h>
+#include <linux/atomic.h>
#include <linux/completion.h>
#include <linux/interrupt.h>
#include <linux/io.h>
@@ -91,6 +92,28 @@ static int nvec_status_notifier(struct notifier_block *nb,
return NOTIFY_OK;
}
+static struct nvec_msg *nvec_msg_alloc(struct nvec_chip *nvec)
+{
+ int i;
+
+ for (i = 0; i < NVEC_POOL_SIZE; i++) {
+ if (atomic_xchg(&nvec->msg_pool[i].used, 1) == 0) {
+ dev_vdbg(nvec->dev, "INFO: Allocate %i\n", i);
+ return &nvec->msg_pool[i];
+ }
+ }
+
+ dev_err(nvec->dev, "could not allocate buffer\n");
+
+ return NULL;
+}
+
+static void nvec_msg_free(struct nvec_chip *nvec, struct nvec_msg *msg)
+{
+ dev_vdbg(nvec->dev, "INFO: Free %ti\n", msg - nvec->msg_pool);
+ atomic_set(&msg->used, 0);
+}
+
void nvec_write_async(struct nvec_chip *nvec, const unsigned char *data,
short size)
{
diff --git a/drivers/staging/nvec/nvec.h b/drivers/staging/nvec/nvec.h
index fe11225bcec1..544080259e2c 100644
--- a/drivers/staging/nvec/nvec.h
+++ b/drivers/staging/nvec/nvec.h
@@ -16,9 +16,13 @@
#ifndef __LINUX_MFD_NVEC
#define __LINUX_MFD_NVEC
+#include <linux/atomic.h>
#include <linux/notifier.h>
#include <linux/semaphore.h>
+/* NVEC_POOL_SIZE - Size of the pool in &struct nvec_msg */
+#define NVEC_POOL_SIZE 64
+
typedef enum {
NVEC_2BYTES,
NVEC_3BYTES,
@@ -52,6 +56,7 @@ struct nvec_msg {
unsigned short size;
unsigned short pos;
struct list_head node;
+ atomic_t used;
};
struct nvec_subdev {
@@ -78,6 +83,7 @@ struct nvec_chip {
struct notifier_block nvec_status_notifier;
struct work_struct rx_work, tx_work;
struct nvec_msg *rx, *tx;
+ struct nvec_msg msg_pool[NVEC_POOL_SIZE];
/* sync write stuff */
struct semaphore sync_write_mutex;