]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/media/dvb-frontends/cxd2880/cxd2880_stopwatch_port.c
This is the driver for Sony CXD2880 DVB-T2/T tuner + demodulator.
[mirror_ubuntu-artful-kernel.git] / drivers / media / dvb-frontends / cxd2880 / cxd2880_stopwatch_port.c
1 /*
2 * cxd2880_stopwatch_port.c
3 * Sony CXD2880 DVB-T2/T tuner + demodulator driver
4 * time measurement functions
5 *
6 * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; version 2 of the License.
11 *
12 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
13 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
15 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
16 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
18 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
21 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, see <http://www.gnu.org/licenses/>.
25 */
26
27 #include "cxd2880_common.h"
28
29 #include <linux/ktime.h>
30 #include <linux/time.h>
31 #include <linux/timekeeping.h>
32
33 static u32 get_time_count(void)
34 {
35 struct timespec tp;
36
37 getnstimeofday(&tp);
38
39 return (u32)((tp.tv_sec * 1000) + (tp.tv_nsec / 1000000));
40 }
41
42 enum cxd2880_ret cxd2880_stopwatch_start(struct cxd2880_stopwatch *stopwatch)
43 {
44 if (!stopwatch)
45 return CXD2880_RESULT_ERROR_ARG;
46
47 stopwatch->start_time = get_time_count();
48
49 return CXD2880_RESULT_OK;
50 }
51
52 enum cxd2880_ret cxd2880_stopwatch_sleep(struct cxd2880_stopwatch *stopwatch,
53 u32 ms)
54 {
55 if (!stopwatch)
56 return CXD2880_RESULT_ERROR_ARG;
57 CXD2880_ARG_UNUSED(*stopwatch);
58 CXD2880_SLEEP(ms);
59
60 return CXD2880_RESULT_OK;
61 }
62
63 enum cxd2880_ret cxd2880_stopwatch_elapsed(struct cxd2880_stopwatch *stopwatch,
64 u32 *elapsed)
65 {
66 if (!stopwatch || !elapsed)
67 return CXD2880_RESULT_ERROR_ARG;
68 *elapsed = get_time_count() - stopwatch->start_time;
69
70 return CXD2880_RESULT_OK;
71 }