summaryrefslogtreecommitdiff
path: root/drivers/staging/csr/csr_time.c
blob: 1ef61e3efac6ffdcbe90131db26e60625b2118af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*****************************************************************************

            (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>

#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
#elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
#include <linux/autoconf.h>
#include <linux/config.h>
#endif

#include <linux/time.h>
#include <linux/module.h>

#include "csr_types.h"
#include "csr_time.h"

CsrTime CsrTimeGet(CsrTime *high)
{
    struct timespec ts;
    CsrUint64 time;
    CsrTime low;

    ts = current_kernel_time();
    time = (CsrUint64) ts.tv_sec * 1000000 + ts.tv_nsec / 1000;

    if (high != NULL)
    {
        *high = (CsrTime) ((time >> 32) & 0xFFFFFFFF);
    }

    low = (CsrTime) (time & 0xFFFFFFFF);

    return low;
}
EXPORT_SYMBOL_GPL(CsrTimeGet);

void CsrTimeUtcGet(CsrTimeUtc *tod, CsrTime *low, CsrTime *high)
{
    struct timespec ts;
    CsrUint64 time;

    ts = current_kernel_time();
    time = (CsrUint64) ts.tv_sec * 1000000 + ts.tv_nsec / 1000;

    if (high != NULL)
    {
        *high = (CsrTime) ((time >> 32) & 0xFFFFFFFF);
    }

    if (low != NULL)
    {
        *low = (CsrTime) (time & 0xFFFFFFFF);
    }

    if (tod != NULL)
    {
        struct timeval tv;
        do_gettimeofday(&tv);
        tod->sec = tv.tv_sec;
        tod->msec = tv.tv_usec / 1000;
    }
}