From c29c79bb548435a4de00ff67908b4a851c5bd4ff Mon Sep 17 00:00:00 2001 From: Hamad Kadmany Date: Thu, 31 Jan 2013 14:53:32 +0200 Subject: [PATCH] tsif: Add option to read TSIF clock reference counter Reading the current value of TSIF clock reference counter is required by some application. Change-Id: I5ca2a280f864fbb9c4a69518ce9672538f9c8489 Signed-off-by: Hamad Kadmany --- drivers/misc/tsif.c | 18 +++++++++++++++++- include/linux/tsif_api.h | 13 ++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/drivers/misc/tsif.c b/drivers/misc/tsif.c index b7b1203f781..05f6c86769f 100644 --- a/drivers/misc/tsif.c +++ b/drivers/misc/tsif.c @@ -1,7 +1,7 @@ /* * TSIF Driver * - * Copyright (c) 2009-2012, Code Aurora Forum. All rights reserved. + * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -1770,6 +1770,22 @@ void tsif_stop(void *cookie) } EXPORT_SYMBOL(tsif_stop); +int tsif_get_ref_clk_counter(void *cookie, u32 *tcr_counter) +{ + struct msm_tsif_device *tsif_device = cookie; + + if (!tsif_device || !tcr_counter) + return -EINVAL; + + if (tsif_device->state == tsif_state_running) + *tcr_counter = ioread32(tsif_device->base + TSIF_CLK_REF_OFF); + else + *tcr_counter = 0; + + return 0; +} +EXPORT_SYMBOL(tsif_get_ref_clk_counter); + void tsif_reclaim_packets(void *cookie, int read_index) { struct msm_tsif_device *tsif_device = cookie; diff --git a/include/linux/tsif_api.h b/include/linux/tsif_api.h index 0c182282946..b69ddf595f3 100644 --- a/include/linux/tsif_api.h +++ b/include/linux/tsif_api.h @@ -3,7 +3,7 @@ * * Kernel API * - * Copyright (c) 2009-2010, 2012, The Linux Foundation. All rights reserved. + * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -255,6 +255,17 @@ int tsif_start(void *cookie); */ void tsif_stop(void *cookie); +/** + * tsif_get_ref_clk_counter - return the TSIF clock reference (TCR) counter. + * @cookie: TSIF cookie previously obtained with tsif_attach() + * @tcr_counter: the value of TCR counter + * + * Return error code + * + * TCR increments at a rate equal to 27 MHz/256 = 105.47 kHz. + */ +int tsif_get_ref_clk_counter(void *cookie, u32 *tcr_counter); + /** * tsif_reclaim_packets - inform that buffer space may be reclaimed * @cookie: TSIF cookie previously obtained with tsif_attach()