]> Pileus Git - ~andy/linux/blob - drivers/staging/csr/csr_framework_ext.c
staging: csr: remove unused including <linux/version.h>
[~andy/linux] / 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/kthread.h>
13 #include <linux/module.h>
14 #include <linux/freezer.h>
15 #include <linux/semaphore.h>
16 #include <linux/slab.h>
17 #include <linux/bitops.h>
18
19 #include "csr_framework_ext.h"
20 #include "csr_panic.h"
21
22 /*----------------------------------------------------------------------------*
23  *  NAME
24  *      CsrMutexCreate
25  *
26  *  DESCRIPTION
27  *      Create a mutex and return a handle to the created mutex.
28  *
29  *  RETURNS
30  *      Possible values:
31  *          CSR_RESULT_SUCCESS           in case of success
32  *          CSR_FE_RESULT_NO_MORE_MUTEXES   in case of out of mutex resources
33  *          CSR_FE_RESULT_INVALID_POINTER   in case the mutexHandle pointer is invalid
34  *
35  *----------------------------------------------------------------------------*/
36 CsrResult CsrMutexCreate(CsrMutexHandle *mutexHandle)
37 {
38     if (mutexHandle == NULL)
39     {
40         return CSR_FE_RESULT_INVALID_POINTER;
41     }
42
43     sema_init(mutexHandle, 1);
44
45     return CSR_RESULT_SUCCESS;
46 }
47
48 /*----------------------------------------------------------------------------*
49  *  NAME
50  *      CsrMutexDestroy
51  *
52  *  DESCRIPTION
53  *      Destroy the previously created mutex.
54  *
55  *  RETURNS
56  *      void
57  *
58  *----------------------------------------------------------------------------*/
59 void CsrMutexDestroy(CsrMutexHandle *mutexHandle)
60 {
61 }
62
63 /*----------------------------------------------------------------------------*
64  *  NAME
65  *      CsrMutexLock
66  *
67  *  DESCRIPTION
68  *      Lock the mutex refered to by the provided handle.
69  *
70  *  RETURNS
71  *      Possible values:
72  *          CSR_RESULT_SUCCESS           in case of success
73  *          CSR_FE_RESULT_INVALID_HANDLE    in case the mutexHandle is invalid
74  *
75  *----------------------------------------------------------------------------*/
76 CsrResult CsrMutexLock(CsrMutexHandle *mutexHandle)
77 {
78     if (mutexHandle == NULL)
79     {
80         return CSR_FE_RESULT_INVALID_POINTER;
81     }
82
83     if (down_interruptible(mutexHandle))
84     {
85         CsrPanic(CSR_TECH_FW, CSR_PANIC_FW_UNEXPECTED_VALUE, "CsrMutexLock Failed");
86         return CSR_FE_RESULT_INVALID_POINTER;
87     }
88
89     return CSR_RESULT_SUCCESS;
90 }
91
92 /*----------------------------------------------------------------------------*
93  *  NAME
94  *      CsrMutexUnlock
95  *
96  *  DESCRIPTION
97  *      Unlock the mutex refered to by the provided handle.
98  *
99  *  RETURNS
100  *      Possible values:
101  *          CSR_RESULT_SUCCESS           in case of success
102  *          CSR_FE_RESULT_INVALID_HANDLE    in case the mutexHandle is invalid
103  *
104  *----------------------------------------------------------------------------*/
105 CsrResult CsrMutexUnlock(CsrMutexHandle *mutexHandle)
106 {
107     if (mutexHandle == NULL)
108     {
109         return CSR_FE_RESULT_INVALID_POINTER;
110     }
111
112     up(mutexHandle);
113
114     return CSR_RESULT_SUCCESS;
115 }
116
117 /*----------------------------------------------------------------------------*
118  *  NAME
119  *      CsrThreadSleep
120  *
121  *  DESCRIPTION
122  *      Sleep for a given period.
123  *
124  *  RETURNS
125  *      void
126  *
127  *----------------------------------------------------------------------------*/
128 void CsrThreadSleep(u16 sleepTimeInMs)
129 {
130     unsigned long t;
131
132     /* Convert t in ms to jiffies and round up */
133     t = ((sleepTimeInMs * HZ) + 999) / 1000;
134     schedule_timeout_uninterruptible(t);
135 }
136 EXPORT_SYMBOL_GPL(CsrThreadSleep);