summaryrefslogtreecommitdiffstats
path: root/drivers/staging/csr/csr_framework_ext.c
diff options
context:
space:
mode:
authorGreg Kroah-Hartman2012-06-20 01:15:42 +0200
committerGreg Kroah-Hartman2012-06-20 01:37:01 +0200
commit635d2b00e5070378e7bf812acf47fb135c6ab928 (patch)
tree7048a0a511f3d221aa2dfe40aa3a401991f1b175 /drivers/staging/csr/csr_framework_ext.c
parentStaging: add CSR Wifi "os helper" module (diff)
downloadkernel-qcow2-linux-635d2b00e5070378e7bf812acf47fb135c6ab928.tar.gz
kernel-qcow2-linux-635d2b00e5070378e7bf812acf47fb135c6ab928.tar.xz
kernel-qcow2-linux-635d2b00e5070378e7bf812acf47fb135c6ab928.zip
Staging: add CSR wifi module
This consists of two modules, the driver, and a "helper" module that is just a wrapper around common kernel functions. The wrapper module will be removed soon, but for now it's needed. These files were based on the csr-linux-wifi-5.0.3-oss.tar.gz package provided by CSR and Blue Giga, and is covered under the license specified in the LICENSE.txt file (basically dual BSD and GPLv2). The files were flattened out of the deep directory mess they were originally in, and a few EXPORT_SYMBOL_GPL() were added in order for everything to link properly with the helper module setup. Cc: Mikko Virkkilä <mikko.virkkila@bluegiga.com> Cc: Lauri Hintsala <Lauri.Hintsala@bluegiga.com> Cc: Riku Mettälä <riku.mettala@bluegiga.com> Cc: Veli-Pekka Peltola <veli-pekka.peltola@bluegiga.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/csr/csr_framework_ext.c')
-rw-r--r--drivers/staging/csr/csr_framework_ext.c213
1 files changed, 213 insertions, 0 deletions
diff --git a/drivers/staging/csr/csr_framework_ext.c b/drivers/staging/csr/csr_framework_ext.c
new file mode 100644
index 000000000000..0406a4b0f786
--- /dev/null
+++ b/drivers/staging/csr/csr_framework_ext.c
@@ -0,0 +1,213 @@
+/*****************************************************************************
+
+ (c) Cambridge Silicon Radio Limited 2010
+ All rights reserved and confidential information of CSR
+
+ Refer to LICENSE.txt included with this source for details
+ on the license terms.
+
+*****************************************************************************/
+
+#include <linux/kernel.h>
+#include <linux/version.h>
+#include <linux/kthread.h>
+#include <linux/module.h>
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34)
+#include <linux/slab.h>
+#endif
+
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 19)
+#include <linux/freezer.h>
+#endif
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27)
+#include <asm/semaphore.h>
+#else
+#include <linux/semaphore.h>
+#endif
+
+#include <linux/bitops.h>
+
+#include "csr_types.h"
+#include "csr_framework_ext.h"
+#include "csr_panic.h"
+
+/*----------------------------------------------------------------------------*
+ * NAME
+ * CsrMutexCreate
+ *
+ * DESCRIPTION
+ * Create a mutex and return a handle to the created mutex.
+ *
+ * RETURNS
+ * Possible values:
+ * CSR_RESULT_SUCCESS in case of success
+ * CSR_FE_RESULT_NO_MORE_MUTEXES in case of out of mutex resources
+ * CSR_FE_RESULT_INVALID_POINTER in case the mutexHandle pointer is invalid
+ *
+ *----------------------------------------------------------------------------*/
+CsrResult CsrMutexCreate(CsrMutexHandle *mutexHandle)
+{
+ if (mutexHandle == NULL)
+ {
+ return CSR_FE_RESULT_INVALID_POINTER;
+ }
+
+ sema_init(mutexHandle, 1);
+
+ return CSR_RESULT_SUCCESS;
+}
+
+/*----------------------------------------------------------------------------*
+ * NAME
+ * CsrMutexDestroy
+ *
+ * DESCRIPTION
+ * Destroy the previously created mutex.
+ *
+ * RETURNS
+ * void
+ *
+ *----------------------------------------------------------------------------*/
+void CsrMutexDestroy(CsrMutexHandle *mutexHandle)
+{
+}
+
+/*----------------------------------------------------------------------------*
+ * NAME
+ * CsrMutexLock
+ *
+ * DESCRIPTION
+ * Lock the mutex refered to by the provided handle.
+ *
+ * RETURNS
+ * Possible values:
+ * CSR_RESULT_SUCCESS in case of success
+ * CSR_FE_RESULT_INVALID_HANDLE in case the mutexHandle is invalid
+ *
+ *----------------------------------------------------------------------------*/
+CsrResult CsrMutexLock(CsrMutexHandle *mutexHandle)
+{
+ if (mutexHandle == NULL)
+ {
+ return CSR_FE_RESULT_INVALID_POINTER;
+ }
+
+ if (down_interruptible(mutexHandle))
+ {
+ CsrPanic(CSR_TECH_FW, CSR_PANIC_FW_UNEXPECTED_VALUE, "CsrMutexLock Failed");
+ return CSR_FE_RESULT_INVALID_POINTER;
+ }
+
+ return CSR_RESULT_SUCCESS;
+}
+
+/*----------------------------------------------------------------------------*
+ * NAME
+ * CsrMutexUnlock
+ *
+ * DESCRIPTION
+ * Unlock the mutex refered to by the provided handle.
+ *
+ * RETURNS
+ * Possible values:
+ * CSR_RESULT_SUCCESS in case of success
+ * CSR_FE_RESULT_INVALID_HANDLE in case the mutexHandle is invalid
+ *
+ *----------------------------------------------------------------------------*/
+CsrResult CsrMutexUnlock(CsrMutexHandle *mutexHandle)
+{
+ if (mutexHandle == NULL)
+ {
+ return CSR_FE_RESULT_INVALID_POINTER;
+ }
+
+ up(mutexHandle);
+
+ return CSR_RESULT_SUCCESS;
+}
+
+/*----------------------------------------------------------------------------*
+ * NAME
+ * CsrThreadSleep
+ *
+ * DESCRIPTION
+ * Sleep for a given period.
+ *
+ * RETURNS
+ * void
+ *
+ *----------------------------------------------------------------------------*/
+void CsrThreadSleep(CsrUint16 sleepTimeInMs)
+{
+ unsigned long t;
+
+ /* Convert t in ms to jiffies and round up */
+ t = ((sleepTimeInMs * HZ) + 999) / 1000;
+ schedule_timeout_uninterruptible(t);
+}
+EXPORT_SYMBOL_GPL(CsrThreadSleep);
+
+/*----------------------------------------------------------------------------*
+ * NAME
+ * CsrMemCalloc
+ *
+ * DESCRIPTION
+ * Allocate dynamic memory of a given size calculated as the
+ * numberOfElements times the elementSize.
+ *
+ * RETURNS
+ * Pointer to allocated memory, or NULL in case of failure.
+ * Allocated memory is zero initialised.
+ *
+ *----------------------------------------------------------------------------*/
+void *CsrMemCalloc(CsrSize numberOfElements, CsrSize elementSize)
+{
+ void *buf;
+ size_t size;
+
+ size = numberOfElements * elementSize;
+
+ buf = kmalloc(size, GFP_KERNEL);
+ if (buf != NULL)
+ {
+ memset(buf, 0, size);
+ }
+
+ return buf;
+}
+
+/*----------------------------------------------------------------------------*
+ * NAME
+ * CsrMemAlloc
+ *
+ * DESCRIPTION
+ * Allocate dynamic memory of a given size.
+ *
+ * RETURNS
+ * Pointer to allocated memory, or NULL in case of failure.
+ * Allocated memory is not initialised.
+ *
+ *----------------------------------------------------------------------------*/
+void *CsrMemAlloc(CsrSize size)
+{
+ return kmalloc(size, GFP_KERNEL);
+}
+EXPORT_SYMBOL_GPL(CsrMemAlloc);
+
+/*----------------------------------------------------------------------------*
+ * NAME
+ * CsrMemFree
+ *
+ * DESCRIPTION
+ * Free dynamic allocated memory.
+ *
+ * RETURNS
+ * void
+ *
+ *----------------------------------------------------------------------------*/
+void CsrMemFree(void *pointer)
+{
+ kfree(pointer);
+}
+EXPORT_SYMBOL_GPL(CsrMemFree);