Staging: add CSR wifi module
[linux-2.6-block.git] / drivers / staging / csr / csr_time.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
14 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
15 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
16 #include <linux/autoconf.h>
17 #include <linux/config.h>
18 #endif
19
20 #include <linux/time.h>
21 #include <linux/module.h>
22
23 #include "csr_types.h"
24 #include "csr_time.h"
25
26 CsrTime CsrTimeGet(CsrTime *high)
27 {
28     struct timespec ts;
29     CsrUint64 time;
30     CsrTime low;
31
32     ts = current_kernel_time();
33     time = (CsrUint64) ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
34
35     if (high != NULL)
36     {
37         *high = (CsrTime) ((time >> 32) & 0xFFFFFFFF);
38     }
39
40     low = (CsrTime) (time & 0xFFFFFFFF);
41
42     return low;
43 }
44 EXPORT_SYMBOL_GPL(CsrTimeGet);
45
46 void CsrTimeUtcGet(CsrTimeUtc *tod, CsrTime *low, CsrTime *high)
47 {
48     struct timespec ts;
49     CsrUint64 time;
50
51     ts = current_kernel_time();
52     time = (CsrUint64) ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
53
54     if (high != NULL)
55     {
56         *high = (CsrTime) ((time >> 32) & 0xFFFFFFFF);
57     }
58
59     if (low != NULL)
60     {
61         *low = (CsrTime) (time & 0xFFFFFFFF);
62     }
63
64     if (tod != NULL)
65     {
66         struct timeval tv;
67         do_gettimeofday(&tv);
68         tod->sec = tv.tv_sec;
69         tod->msec = tv.tv_usec / 1000;
70     }
71 }