Merge branch 'for-next' of git://neil.brown.name/md
[deliverable/linux.git] / drivers / staging / csr / csr_framework_ext.c
1 /*****************************************************************************
2
3 (c) Cambridge Silicon Radio Limited 2010
4 All rights reserved and confidential information of CSR
5
6 Refer to LICENSE.txt included with this source for details
7 on the license terms.
8
9 *****************************************************************************/
10
11 #include <linux/kernel.h>
12 #include <linux/version.h>
13 #include <linux/kthread.h>
14 #include <linux/module.h>
15
16 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34)
17 #include <linux/slab.h>
18 #endif
19
20 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 19)
21 #include <linux/freezer.h>
22 #endif
23 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27)
24 #include <asm/semaphore.h>
25 #else
26 #include <linux/semaphore.h>
27 #endif
28
29 #include <linux/bitops.h>
30
31 #include "csr_framework_ext.h"
32 #include "csr_panic.h"
33
34 /*----------------------------------------------------------------------------*
35 * NAME
36 * CsrMutexCreate
37 *
38 * DESCRIPTION
39 * Create a mutex and return a handle to the created mutex.
40 *
41 * RETURNS
42 * Possible values:
43 * CSR_RESULT_SUCCESS in case of success
44 * CSR_FE_RESULT_NO_MORE_MUTEXES in case of out of mutex resources
45 * CSR_FE_RESULT_INVALID_POINTER in case the mutexHandle pointer is invalid
46 *
47 *----------------------------------------------------------------------------*/
48 CsrResult CsrMutexCreate(CsrMutexHandle *mutexHandle)
49 {
50 if (mutexHandle == NULL)
51 {
52 return CSR_FE_RESULT_INVALID_POINTER;
53 }
54
55 sema_init(mutexHandle, 1);
56
57 return CSR_RESULT_SUCCESS;
58 }
59
60 /*----------------------------------------------------------------------------*
61 * NAME
62 * CsrMutexDestroy
63 *
64 * DESCRIPTION
65 * Destroy the previously created mutex.
66 *
67 * RETURNS
68 * void
69 *
70 *----------------------------------------------------------------------------*/
71 void CsrMutexDestroy(CsrMutexHandle *mutexHandle)
72 {
73 }
74
75 /*----------------------------------------------------------------------------*
76 * NAME
77 * CsrMutexLock
78 *
79 * DESCRIPTION
80 * Lock the mutex refered to by the provided handle.
81 *
82 * RETURNS
83 * Possible values:
84 * CSR_RESULT_SUCCESS in case of success
85 * CSR_FE_RESULT_INVALID_HANDLE in case the mutexHandle is invalid
86 *
87 *----------------------------------------------------------------------------*/
88 CsrResult CsrMutexLock(CsrMutexHandle *mutexHandle)
89 {
90 if (mutexHandle == NULL)
91 {
92 return CSR_FE_RESULT_INVALID_POINTER;
93 }
94
95 if (down_interruptible(mutexHandle))
96 {
97 CsrPanic(CSR_TECH_FW, CSR_PANIC_FW_UNEXPECTED_VALUE, "CsrMutexLock Failed");
98 return CSR_FE_RESULT_INVALID_POINTER;
99 }
100
101 return CSR_RESULT_SUCCESS;
102 }
103
104 /*----------------------------------------------------------------------------*
105 * NAME
106 * CsrMutexUnlock
107 *
108 * DESCRIPTION
109 * Unlock the mutex refered to by the provided handle.
110 *
111 * RETURNS
112 * Possible values:
113 * CSR_RESULT_SUCCESS in case of success
114 * CSR_FE_RESULT_INVALID_HANDLE in case the mutexHandle is invalid
115 *
116 *----------------------------------------------------------------------------*/
117 CsrResult CsrMutexUnlock(CsrMutexHandle *mutexHandle)
118 {
119 if (mutexHandle == NULL)
120 {
121 return CSR_FE_RESULT_INVALID_POINTER;
122 }
123
124 up(mutexHandle);
125
126 return CSR_RESULT_SUCCESS;
127 }
128
129 /*----------------------------------------------------------------------------*
130 * NAME
131 * CsrThreadSleep
132 *
133 * DESCRIPTION
134 * Sleep for a given period.
135 *
136 * RETURNS
137 * void
138 *
139 *----------------------------------------------------------------------------*/
140 void CsrThreadSleep(u16 sleepTimeInMs)
141 {
142 unsigned long t;
143
144 /* Convert t in ms to jiffies and round up */
145 t = ((sleepTimeInMs * HZ) + 999) / 1000;
146 schedule_timeout_uninterruptible(t);
147 }
148 EXPORT_SYMBOL_GPL(CsrThreadSleep);
This page took 0.03372 seconds and 6 git commands to generate.