blob: 6b408d5678507f15ef80c5ebbd37481c6477f074 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
2 * Copyright (c) 2014 The Linux Foundation. All rights reserved.
3 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * DOC: cdf_threads
30 *
31 * Connectivity driver framework (CDF) thread APIs
32 *
33 */
34
35/* Include Files */
36#include <cdf_threads.h>
37#include <cdf_trace.h>
38#include <linux/jiffies.h>
39#include <linux/sched.h>
40#include <linux/delay.h>
41#include <linux/interrupt.h>
42
43/* Preprocessor definitions and constants */
44
45/* Type declarations */
46
47/* Function declarations and documenation */
48
49/**
50 * cdf_sleep() - sleep
51 * @msInterval : Number of milliseconds to suspend the current thread.
52 * A value of 0 may or may not cause the current thread to yield.
53 *
54 * This function suspends the execution of the current thread
55 * until the specified time out interval elapses.
56 *
57 * Return: nothing
58 */
59void cdf_sleep(uint32_t msInterval)
60{
61 if (in_interrupt()) {
62 CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_ERROR,
63 "%s cannot be called from interrupt context!!!",
64 __func__);
65 return;
66 }
67 msleep_interruptible(msInterval);
68}
69
70/**
71 * cdf_sleep_us() - sleep
72 * @usInterval : Number of microseconds to suspend the current thread.
73 * A value of 0 may or may not cause the current thread to yield.
74 *
75 * This function suspends the execution of the current thread
76 * until the specified time out interval elapses.
77 *
78 * Return : nothing
79 */
80void cdf_sleep_us(uint32_t usInterval)
81{
82 unsigned long timeout = usecs_to_jiffies(usInterval) + 1;
83 if (in_interrupt()) {
84 CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_ERROR,
85 "%s cannot be called from interrupt context!!!",
86 __func__);
87 return;
88 }
89
90 while (timeout && !signal_pending(current))
91 timeout = schedule_timeout_interruptible(timeout);
92}
93
94/**
95 * cdf_busy_wait() - busy wait
96 * @usInterval : Number of microseconds to busy wait.
97 *
98 * This function places the current thread in busy wait until the specified
99 * time out interval elapses. If the interval is greater than 50us on WM, the
100 * behaviour is undefined.
101 *
102 * Return : nothing
103 */
104void cdf_busy_wait(uint32_t usInterval)
105{
106 udelay(usInterval);
107}