[RFC PATCH v1 2/3] iio:core: timestamping clock resolution support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Adds a new function iio_get_time_res() to retrieve the current timestamping
clock resolution.

Signed-off-by: Gregor Boirie <gregor.boirie@xxxxxxxxxx>
---
 drivers/iio/industrialio-core.c | 23 +++++++++++++++++++++++
 include/linux/iio/iio.h         |  1 +
 2 files changed, 24 insertions(+)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 97bdb95..eb56cdf 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -212,6 +212,29 @@ s64 iio_get_time_ns(const struct iio_dev* indio_dev)
 }
 EXPORT_SYMBOL(iio_get_time_ns);
 
+/**
+ * iio_get_time_res() - utility function to get time stamp clock resolution in
+ *                      nano seconds.
+ * @indio_dev: device
+ */
+unsigned int iio_get_time_res(const struct iio_dev* indio_dev)
+{
+	switch (indio_dev->clock_id) {
+	case CLOCK_REALTIME:
+	case CLOCK_MONOTONIC:
+	case CLOCK_MONOTONIC_RAW:
+	case CLOCK_BOOTTIME:
+	case CLOCK_TAI:
+		return hrtimer_resolution;
+	case CLOCK_REALTIME_COARSE:
+	case CLOCK_MONOTONIC_COARSE:
+		return LOW_RES_NSEC;
+	default:
+		BUG();
+	}
+}
+EXPORT_SYMBOL(iio_get_time_res);
+
 static int __init iio_init(void)
 {
 	int ret;
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 904a5b0..931b0ab 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -282,6 +282,7 @@ static inline bool iio_channel_has_info(const struct iio_chan_spec *chan,
 }
 
 extern s64 iio_get_time_ns(const struct iio_dev*);
+extern unsigned int iio_get_time_res(const struct iio_dev*);
 
 /* Device operating modes */
 #define INDIO_DIRECT_MODE		0x01
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux