iio:core: timestamping clock selection support
authorGregor Boirie <gregor.boirie@parrot.com>
Wed, 9 Mar 2016 18:05:49 +0000 (19:05 +0100)
committerJonathan Cameron <jic23@kernel.org>
Thu, 30 Jun 2016 18:41:38 +0000 (19:41 +0100)
Adds a new per-device sysfs attribute "current_timestamp_clock" to allow
userspace to select a particular POSIX clock for buffered samples and
events timestamping.

Following clocks, as listed in clock_gettime(2), are supported:
CLOCK_REALTIME, CLOCK_MONOTONIC, CLOCK_MONOTONIC_RAW,
CLOCK_REALTIME_COARSE, CLOCK_MONOTONIC_COARSE, CLOCK_BOOTTIME and
CLOCK_TAI.

Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com>
Acked-by: Sanchayan Maity <maitysanchayan@gmail.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
69 files changed:
Documentation/ABI/testing/sysfs-bus-iio
Documentation/DocBook/iio.tmpl
drivers/iio/accel/bma180.c
drivers/iio/accel/bmc150-accel-core.c
drivers/iio/accel/kxcjk-1013.c
drivers/iio/accel/mma7455_core.c
drivers/iio/accel/mma8452.c
drivers/iio/accel/mma9551.c
drivers/iio/accel/mma9553.c
drivers/iio/adc/ad7291.c
drivers/iio/adc/ad7298.c
drivers/iio/adc/ad7476.c
drivers/iio/adc/ad7887.c
drivers/iio/adc/ad7923.c
drivers/iio/adc/ad799x.c
drivers/iio/adc/cc10001_adc.c
drivers/iio/adc/hi8435.c
drivers/iio/adc/ina2xx-adc.c
drivers/iio/adc/max1363.c
drivers/iio/adc/ti-adc081c.c
drivers/iio/adc/ti-ads1015.c
drivers/iio/adc/vf610_adc.c
drivers/iio/adc/xilinx-xadc-events.c
drivers/iio/chemical/atlas-ph-sensor.c
drivers/iio/common/st_sensors/st_sensors_buffer.c
drivers/iio/common/st_sensors/st_sensors_trigger.c
drivers/iio/dac/ad5421.c
drivers/iio/dac/ad5504.c
drivers/iio/dummy/iio_simple_dummy_buffer.c
drivers/iio/dummy/iio_simple_dummy_events.c
drivers/iio/gyro/bmg160_core.c
drivers/iio/iio_core.h
drivers/iio/imu/bmi160/bmi160_core.c
drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
drivers/iio/industrialio-core.c
drivers/iio/industrialio-event.c
drivers/iio/industrialio-trigger.c
drivers/iio/light/acpi-als.c
drivers/iio/light/adjd_s311.c
drivers/iio/light/apds9300.c
drivers/iio/light/apds9960.c
drivers/iio/light/cm36651.c
drivers/iio/light/gp2ap020a00f.c
drivers/iio/light/isl29125.c
drivers/iio/light/lm3533-als.c
drivers/iio/light/ltr501.c
drivers/iio/light/max44000.c
drivers/iio/light/opt3001.c
drivers/iio/light/stk3310.c
drivers/iio/light/tcs3414.c
drivers/iio/light/tcs3472.c
drivers/iio/light/tsl2563.c
drivers/iio/light/us5182d.c
drivers/iio/magnetometer/ak8975.c
drivers/iio/magnetometer/hmc5843_core.c
drivers/iio/magnetometer/mag3110.c
drivers/iio/pressure/mpl3115.c
drivers/iio/pressure/ms5611_core.c
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
drivers/iio/proximity/sx9500.c
drivers/staging/iio/accel/lis3l02dq_core.c
drivers/staging/iio/accel/sca3000_core.c
drivers/staging/iio/adc/ad7280a.c
drivers/staging/iio/adc/ad7606_ring.c
drivers/staging/iio/adc/ad7816.c
drivers/staging/iio/addac/adt7316.c
drivers/staging/iio/cdc/ad7150.c
drivers/staging/iio/light/tsl2x7x_core.c
include/linux/iio/iio.h

index e7f590c6ef8e1e8a1ec7e5eb0364b752cf9047f4..fee35c00cc4ed6fd59fdff3fd14cac396e9336a4 100644 (file)
@@ -32,6 +32,13 @@ Description:
                Description of the physical chip / device for device X.
                Typically a part number.
 
+What:          /sys/bus/iio/devices/iio:deviceX/timestamp_clock
+KernelVersion: 4.5
+Contact:       linux-iio@vger.kernel.org
+Description:
+               String identifying current posix clock used to timestamp
+               buffered samples and events for device X.
+
 What:          /sys/bus/iio/devices/iio:deviceX/sampling_frequency
 What:          /sys/bus/iio/devices/iio:deviceX/buffer/sampling_frequency
 What:          /sys/bus/iio/devices/triggerX/sampling_frequency
index f525bf56d1dd0183d8614c9130fafe0196e82b0d..e2ab6a1f223e99ace1751eaddbde1d3736132486 100644 (file)
 
     irqreturn_t sensor_iio_pollfunc(int irq, void *p)
     {
-        pf->timestamp = iio_get_time_ns();
+        pf->timestamp = iio_get_time_ns((struct indio_dev *)p);
         return IRQ_WAKE_THREAD;
     }
 
index f04b88406995175bc5159a8f300295e33ec3df80..e3f88ba5faf33ff4b7179fb96f603d20875f77a6 100644 (file)
@@ -654,7 +654,7 @@ static irqreturn_t bma180_trigger_handler(int irq, void *p)
        struct iio_poll_func *pf = p;
        struct iio_dev *indio_dev = pf->indio_dev;
        struct bma180_data *data = iio_priv(indio_dev);
-       int64_t time_ns = iio_get_time_ns();
+       s64 time_ns = iio_get_time_ns(indio_dev);
        int bit, ret, i = 0;
 
        mutex_lock(&data->mutex);
index 197e693e7e7b795e9002e10430fd3f41399f96a7..bf17aae6614535b0ab3d68d3bfd84aec653a2f45 100644 (file)
@@ -901,7 +901,7 @@ static int __bmc150_accel_fifo_flush(struct iio_dev *indio_dev,
         */
        if (!irq) {
                data->old_timestamp = data->timestamp;
-               data->timestamp = iio_get_time_ns();
+               data->timestamp = iio_get_time_ns(indio_dev);
        }
 
        /*
@@ -1303,7 +1303,7 @@ static irqreturn_t bmc150_accel_irq_handler(int irq, void *private)
        int i;
 
        data->old_timestamp = data->timestamp;
-       data->timestamp = iio_get_time_ns();
+       data->timestamp = iio_get_time_ns(indio_dev);
 
        for (i = 0; i < BMC150_ACCEL_TRIGGERS; i++) {
                if (data->triggers[i].enabled) {
index bfe219a8bea244619b2e5ed9602998527328d856..765a72362dc61e37d32ad7cf75e805fcba1cc8a1 100644 (file)
@@ -1129,7 +1129,7 @@ static irqreturn_t kxcjk1013_data_rdy_trig_poll(int irq, void *private)
        struct iio_dev *indio_dev = private;
        struct kxcjk1013_data *data = iio_priv(indio_dev);
 
-       data->timestamp = iio_get_time_ns();
+       data->timestamp = iio_get_time_ns(indio_dev);
 
        if (data->dready_trigger_on)
                iio_trigger_poll(data->dready_trig);
index c902f54c23f57fee5ee587b8d701ae818f591785..6551085bedd75818741a48725d9df14fa17d1a34 100644 (file)
@@ -97,7 +97,8 @@ static irqreturn_t mma7455_trigger_handler(int irq, void *p)
        if (ret)
                goto done;
 
-       iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns());
+       iio_push_to_buffers_with_timestamp(indio_dev, buf,
+                                          iio_get_time_ns(indio_dev));
 
 done:
        iio_trigger_notify_done(indio_dev->trig);
index 799fe64fc286f81377c87e81e97ee43236dd26e6..c0df2832836859441e68aeccac02e5500a603494 100644 (file)
@@ -917,7 +917,7 @@ static int mma8452_write_event_config(struct iio_dev *indio_dev,
 static void mma8452_transient_interrupt(struct iio_dev *indio_dev)
 {
        struct mma8452_data *data = iio_priv(indio_dev);
-       s64 ts = iio_get_time_ns();
+       s64 ts = iio_get_time_ns(indio_dev);
        int src;
 
        src = i2c_smbus_read_byte_data(data->client, data->chip_info->ev_src);
@@ -997,7 +997,7 @@ static irqreturn_t mma8452_trigger_handler(int irq, void *p)
                goto done;
 
        iio_push_to_buffers_with_timestamp(indio_dev, buffer,
-                                          iio_get_time_ns());
+                                          iio_get_time_ns(indio_dev));
 
 done:
        iio_trigger_notify_done(indio_dev->trig);
index d899a4d4307f9dbb9abf011281874ad629a6e026..bf2704435629b56f94a35dc7db37bcdd2732c108 100644 (file)
@@ -391,7 +391,7 @@ static irqreturn_t mma9551_event_handler(int irq, void *private)
        iio_push_event(indio_dev,
                       IIO_MOD_EVENT_CODE(IIO_INCLI, 0, (mma_axis + 1),
                                          IIO_EV_TYPE_ROC, IIO_EV_DIR_RISING),
-                      iio_get_time_ns());
+                      iio_get_time_ns(indio_dev));
 
 out:
        mutex_unlock(&data->mutex);
index bb05f3efddca04b381e552be34b5465e19167d0b..36bf19733be0bed4fb5eb0fad810c2cf84ab5d8c 100644 (file)
@@ -1001,7 +1001,7 @@ static irqreturn_t mma9553_irq_handler(int irq, void *private)
        struct iio_dev *indio_dev = private;
        struct mma9553_data *data = iio_priv(indio_dev);
 
-       data->timestamp = iio_get_time_ns();
+       data->timestamp = iio_get_time_ns(indio_dev);
        /*
         * Since we only configure the interrupt pin when an
         * event is enabled, we are sure we have at least
index c0eabf156702a7d4da6a26a477d8cbc50e62c3cb..03763093274957c91d115d62d068537075e55848 100644 (file)
@@ -115,7 +115,7 @@ static irqreturn_t ad7291_event_handler(int irq, void *private)
        u16 t_status, v_status;
        u16 command;
        int i;
-       s64 timestamp = iio_get_time_ns();
+       s64 timestamp = iio_get_time_ns(indio_dev);
 
        if (ad7291_i2c_read(chip, AD7291_T_ALERT_STATUS, &t_status))
                return IRQ_HANDLED;
index 62bb8f7ce4a0f93e0d657a584d56cd3feea75bd7..5dd0742da75ab5ae4fe096532f472dd8125f57ce 100644 (file)
@@ -163,7 +163,7 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p)
                goto done;
 
        iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf,
-               iio_get_time_ns());
+               iio_get_time_ns(indio_dev));
 
 done:
        iio_trigger_notify_done(indio_dev->trig);
index 810c9a9fa62fc1951077192d342b84c5539269cb..a819be288577e2fd00056f3ea07fbdbcd0ab5c77 100644 (file)
@@ -70,7 +70,7 @@ static irqreturn_t ad7476_trigger_handler(int irq, void  *p)
                goto done;
 
        iio_push_to_buffers_with_timestamp(indio_dev, st->data,
-               iio_get_time_ns());
+               iio_get_time_ns(indio_dev));
 done:
        iio_trigger_notify_done(indio_dev->trig);
 
index ee2ccc19fab6d4baf0e3b8c44901966d728bc8b2..1bc363b0a4c11616b1f45e916dae16fe95661214 100644 (file)
@@ -122,7 +122,7 @@ static irqreturn_t ad7887_trigger_handler(int irq, void *p)
                goto done;
 
        iio_push_to_buffers_with_timestamp(indio_dev, st->data,
-               iio_get_time_ns());
+               iio_get_time_ns(indio_dev));
 done:
        iio_trigger_notify_done(indio_dev->trig);
 
index ff444c19d7499628f1a45380e45b920d469662b9..133711680e55cd227b8de066b6dac86ce19723f5 100644 (file)
@@ -181,7 +181,7 @@ static irqreturn_t ad7923_trigger_handler(int irq, void *p)
                goto done;
 
        iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf,
-               iio_get_time_ns());
+               iio_get_time_ns(indio_dev));
 
 done:
        iio_trigger_notify_done(indio_dev->trig);
index ec0200dd52cb347cd68874fe919ac63c97e5e239..54284766d2ef859a99ded409053257112a16f3ab 100644 (file)
@@ -212,7 +212,7 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p)
                goto out;
 
        iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf,
-                       iio_get_time_ns());
+                       iio_get_time_ns(indio_dev));
 out:
        iio_trigger_notify_done(indio_dev->trig);
 
@@ -502,7 +502,7 @@ static irqreturn_t ad799x_event_handler(int irq, void *private)
                                                            (i >> 1),
                                                            IIO_EV_TYPE_THRESH,
                                                            IIO_EV_DIR_FALLING),
-                                      iio_get_time_ns());
+                                      iio_get_time_ns(indio_dev));
        }
 
 done:
index 8254f529b2a9a00738eb017f9e5d0f77c4aacfd8..91636c0ba5b534da240084f48670dfefd01f6764 100644 (file)
@@ -186,7 +186,7 @@ done:
 
        if (!sample_invalid)
                iio_push_to_buffers_with_timestamp(indio_dev, data,
-                                                  iio_get_time_ns());
+                                                  iio_get_time_ns(indio_dev));
        iio_trigger_notify_done(indio_dev->trig);
 
        return IRQ_HANDLED;
index c73c6c62a6aca39e8b6ccebc7128719320f4f4b5..c62bdb0a809e34c99cf895a6f79a24548fa52b58 100644 (file)
@@ -400,7 +400,7 @@ static void hi8435_iio_push_event(struct iio_dev *idev, unsigned int val)
                        iio_push_event(idev,
                                       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, i,
                                                    IIO_EV_TYPE_THRESH, dir),
-                                      iio_get_time_ns());
+                                      iio_get_time_ns(idev));
                }
        }
 
index 502f2fbe8aefca92e27c2e5449a46990c0d1da14..b95ce5d7ee2c7629fce9a9eff9bb0aa4f35de2df 100644 (file)
@@ -465,7 +465,7 @@ static int ina2xx_work_buffer(struct iio_dev *indio_dev)
        s64 time_a, time_b;
        unsigned int alert;
 
-       time_a = iio_get_time_ns();
+       time_a = iio_get_time_ns(indio_dev);
 
        /*
         * Because the timer thread and the chip conversion clock
@@ -504,7 +504,7 @@ static int ina2xx_work_buffer(struct iio_dev *indio_dev)
                data[i++] = val;
        }
 
-       time_b = iio_get_time_ns();
+       time_b = iio_get_time_ns(indio_dev);
 
        iio_push_to_buffers_with_timestamp(indio_dev,
                                           (unsigned int *)data, time_a);
@@ -554,7 +554,7 @@ static int ina2xx_buffer_enable(struct iio_dev *indio_dev)
        dev_dbg(&indio_dev->dev, "Async readout mode: %d\n",
                chip->allow_async_readout);
 
-       chip->prev_ns = iio_get_time_ns();
+       chip->prev_ns = iio_get_time_ns(indio_dev);
 
        chip->task = kthread_run(ina2xx_capture_thread, (void *)indio_dev,
                                 "%s:%d-%uus", indio_dev->name, indio_dev->id,
index 998dc3caad4c15cabe58f7922a594e6976de23ec..73af306846571a80758fc3496c5d6415c9956cce 100644 (file)
@@ -788,7 +788,7 @@ static irqreturn_t max1363_event_handler(int irq, void *private)
 {
        struct iio_dev *indio_dev = private;
        struct max1363_state *st = iio_priv(indio_dev);
-       s64 timestamp = iio_get_time_ns();
+       s64 timestamp = iio_get_time_ns(indio_dev);
        unsigned long mask, loc;
        u8 rx;
        u8 tx[2] = { st->setupbyte,
@@ -1506,7 +1506,8 @@ static irqreturn_t max1363_trigger_handler(int irq, void *p)
        if (b_sent < 0)
                goto done_free;
 
-       iio_push_to_buffers_with_timestamp(indio_dev, rxbuf, iio_get_time_ns());
+       iio_push_to_buffers_with_timestamp(indio_dev, rxbuf,
+                                          iio_get_time_ns(indio_dev));
 
 done_free:
        kfree(rxbuf);
index f8807adc08c424fb57a3e0c372aa361c42e5d9ac..283d2a12b6da5f382f9c8d48646f6f0f16af5989 100644 (file)
@@ -139,7 +139,8 @@ static irqreturn_t adc081c_trigger_handler(int irq, void *p)
        if (ret < 0)
                goto out;
        buf[0] = ret;
-       iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns());
+       iio_push_to_buffers_with_timestamp(indio_dev, buf,
+                                          iio_get_time_ns(indio_dev));
 out:
        iio_trigger_notify_done(indio_dev->trig);
        return IRQ_HANDLED;
index 8be192a848934b38d435af864b380540284b1432..c9574af098821de44a5f9f737eb8661b1586fce9 100644 (file)
@@ -288,7 +288,8 @@ static irqreturn_t ads1015_trigger_handler(int irq, void *p)
        buf[0] = res;
        mutex_unlock(&data->lock);
 
-       iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns());
+       iio_push_to_buffers_with_timestamp(indio_dev, buf,
+                                          iio_get_time_ns(indio_dev));
 
 err:
        iio_trigger_notify_done(indio_dev->trig);
index 653bf1379d2e5ea02b62184e26fee530b34ae46c..228a003adeed222ee45e9d8823afaf04edb8bfe7 100644 (file)
@@ -594,7 +594,8 @@ static irqreturn_t vf610_adc_isr(int irq, void *dev_id)
                if (iio_buffer_enabled(indio_dev)) {
                        info->buffer[0] = info->value;
                        iio_push_to_buffers_with_timestamp(indio_dev,
-                                       info->buffer, iio_get_time_ns());
+                                       info->buffer,
+                                       iio_get_time_ns(indio_dev));
                        iio_trigger_notify_done(indio_dev->trig);
                } else
                        complete(&info->completion);
index edcf3aabd70d905e8a66910b0459b8a82af0df6d..6d5c2a6f4e6ea7382a461bef2d33476468e183fb 100644 (file)
@@ -46,7 +46,7 @@ static void xadc_handle_event(struct iio_dev *indio_dev, unsigned int event)
                iio_push_event(indio_dev,
                        IIO_UNMOD_EVENT_CODE(chan->type, chan->channel,
                                IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING),
-                       iio_get_time_ns());
+                       iio_get_time_ns(indio_dev));
        } else {
                /*
                 * For other channels we don't know whether it is a upper or
@@ -56,7 +56,7 @@ static void xadc_handle_event(struct iio_dev *indio_dev, unsigned int event)
                iio_push_event(indio_dev,
                        IIO_UNMOD_EVENT_CODE(chan->type, chan->channel,
                                IIO_EV_TYPE_THRESH, IIO_EV_DIR_EITHER),
-                       iio_get_time_ns());
+                       iio_get_time_ns(indio_dev));
        }
 }
 
index 02e85db5d31fc8bfe8678ffcd649941974c46848..ae038a59d256c1c9f6ff89acb65819090e66a829 100644 (file)
@@ -343,7 +343,7 @@ static irqreturn_t atlas_trigger_handler(int irq, void *private)
 
        if (!ret)
                iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
-                               iio_get_time_ns());
+                               iio_get_time_ns(indio_dev));
 
        iio_trigger_notify_done(indio_dev->trig);
 
index 50afc0f8f16bd84bc79a15120b8cf509bb96fbee..7c84e90d8ce8846578df2576f37ec122588e5efd 100644 (file)
@@ -62,7 +62,7 @@ irqreturn_t st_sensors_trigger_handler(int irq, void *p)
        if (sdata->hw_irq_trigger)
                timestamp = sdata->hw_timestamp;
        else
-               timestamp = iio_get_time_ns();
+               timestamp = iio_get_time_ns(indio_dev);
 
        len = st_sensors_get_buffer_element(indio_dev, sdata->buffer_data);
        if (len < 0)
index 296e4ff19ae8d9cb4d40a0a852ecdecefb2e127f..fab494d719511447e8be4538e84688a5b466cdee 100644 (file)
@@ -29,7 +29,7 @@ irqreturn_t st_sensors_irq_handler(int irq, void *p)
        struct st_sensor_data *sdata = iio_priv(indio_dev);
 
        /* Get the time stamp as close in time as possible */
-       sdata->hw_timestamp = iio_get_time_ns();
+       sdata->hw_timestamp = iio_get_time_ns(indio_dev);
        return IRQ_WAKE_THREAD;
 }
 
index 968712be967f44bc73d5d34f04edbcc492f69589..559061ab1982d03fce3b38400efc34234bb47ca2 100644 (file)
@@ -242,7 +242,7 @@ static irqreturn_t ad5421_fault_handler(int irq, void *data)
                                        0,
                                        IIO_EV_TYPE_THRESH,
                                        IIO_EV_DIR_RISING),
-                       iio_get_time_ns());
+                       iio_get_time_ns(indio_dev));
                }
 
                if (events & AD5421_FAULT_UNDER_CURRENT) {
@@ -251,7 +251,7 @@ static irqreturn_t ad5421_fault_handler(int irq, void *data)
                                        0,
                                        IIO_EV_TYPE_THRESH,
                                        IIO_EV_DIR_FALLING),
-                               iio_get_time_ns());
+                               iio_get_time_ns(indio_dev));
                }
 
                if (events & AD5421_FAULT_TEMP_OVER_140) {
@@ -260,7 +260,7 @@ static irqreturn_t ad5421_fault_handler(int irq, void *data)
                                        0,
                                        IIO_EV_TYPE_MAG,
                                        IIO_EV_DIR_RISING),
-                               iio_get_time_ns());
+                               iio_get_time_ns(indio_dev));
                }
 
                old_fault = fault;
index 4e4c20d6d8b57a763bb043eaf47af0d76709204c..788b3d6fd1cc973ae398baeaf5b4a88e2207186c 100644 (file)
@@ -223,7 +223,7 @@ static irqreturn_t ad5504_event_handler(int irq, void *private)
                                            0,
                                            IIO_EV_TYPE_THRESH,
                                            IIO_EV_DIR_RISING),
-                      iio_get_time_ns());
+                      iio_get_time_ns((struct iio_dev *)private));
 
        return IRQ_HANDLED;
 }
index cf44a6f7943118bab29c335edd807cb4f186e7b8..b383892a519372c21fd3db1e437a87e39359b88a 100644 (file)
@@ -85,7 +85,8 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p)
                }
        }
 
-       iio_push_to_buffers_with_timestamp(indio_dev, data, iio_get_time_ns());
+       iio_push_to_buffers_with_timestamp(indio_dev, data,
+                                          iio_get_time_ns(indio_dev));
 
        kfree(data);
 
index 6eb600ff70569ef6ceb902afcc49ddce08b09953..ed63ffd849f8201505499d2be4594572b09b535d 100644 (file)
@@ -158,7 +158,7 @@ static irqreturn_t iio_simple_dummy_get_timestamp(int irq, void *private)
        struct iio_dev *indio_dev = private;
        struct iio_dummy_state *st = iio_priv(indio_dev);
 
-       st->event_timestamp = iio_get_time_ns();
+       st->event_timestamp = iio_get_time_ns(indio_dev);
        return IRQ_WAKE_THREAD;
 }
 
index 7ccc044063f65e3429f170571d318b026be9f59d..8155251d99845d7bfeb8d19104c267032b295b5f 100644 (file)
@@ -885,25 +885,25 @@ static irqreturn_t bmg160_event_handler(int irq, void *private)
 
        if (val & BMG160_ANY_MOTION_BIT_X)
                iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
-                                                       0,
-                                                       IIO_MOD_X,
-                                                       IIO_EV_TYPE_ROC,
-                                                       dir),
-                                                       iio_get_time_ns());
+                                                            0,
+                                                            IIO_MOD_X,
+                                                            IIO_EV_TYPE_ROC,
+                                                            dir),
+                              iio_get_time_ns(indio_dev));
        if (val & BMG160_ANY_MOTION_BIT_Y)
                iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
-                                                       0,
-                                                       IIO_MOD_Y,
-                                                       IIO_EV_TYPE_ROC,
-                                                       dir),
-                                                       iio_get_time_ns());
+                                                            0,
+                                                            IIO_MOD_Y,
+                                                            IIO_EV_TYPE_ROC,
+                                                            dir),
+                              iio_get_time_ns(indio_dev));
        if (val & BMG160_ANY_MOTION_BIT_Z)
                iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
-                                                       0,
-                                                       IIO_MOD_Z,
-                                                       IIO_EV_TYPE_ROC,
-                                                       dir),
-                                                       iio_get_time_ns());
+                                                            0,
+                                                            IIO_MOD_Z,
+                                                            IIO_EV_TYPE_ROC,
+                                                            dir),
+                              iio_get_time_ns(indio_dev));
 
 ack_intr_status:
        if (!data->dready_trigger_on) {
index 359883525ab72b463ca041207a88a60724fadfa6..4c45488e3a7f51d9fec1f3f70e555a24be9d5a18 100644 (file)
@@ -79,4 +79,7 @@ void iio_device_unregister_eventset(struct iio_dev *indio_dev);
 void iio_device_wakeup_eventset(struct iio_dev *indio_dev);
 int iio_event_getfd(struct iio_dev *indio_dev);
 
+struct iio_event_interface;
+bool iio_event_enabled(const struct iio_event_interface *ev_int);
+
 #endif
index 97928d558a15816cd7d1ccaec1c39d9f1f3e473d..e0251b8c1a527aa7fe97ef443c0b1614888e63fc 100644 (file)
@@ -411,7 +411,8 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p)
                buf[j++] = sample;
        }
 
-       iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns());
+       iio_push_to_buffers_with_timestamp(indio_dev, buf,
+                                          iio_get_time_ns(indio_dev));
 done:
        iio_trigger_notify_done(indio_dev->trig);
        return IRQ_HANDLED;
index d0700628ee6df32479d8a53de456f9d593bbe3f1..3a9f3eac91ab6a4d9311139861b52def36719d57 100644 (file)
@@ -107,7 +107,7 @@ irqreturn_t inv_mpu6050_irq_handler(int irq, void *p)
        struct inv_mpu6050_state *st = iio_priv(indio_dev);
        s64 timestamp;
 
-       timestamp = iio_get_time_ns();
+       timestamp = iio_get_time_ns(indio_dev);
        kfifo_in_spinlocked(&st->timestamps, &timestamp, 1,
                            &st->time_stamp_lock);
 
index 2a85bd8886190c1a63fcea803cff40e931b7dc61..f914d5d140e4014f5a31011c7783959fe8022755 100644 (file)
@@ -178,6 +178,86 @@ ssize_t iio_read_const_attr(struct device *dev,
 }
 EXPORT_SYMBOL(iio_read_const_attr);
 
+static int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id)
+{
+       int ret;
+       const struct iio_event_interface *ev_int = indio_dev->event_interface;
+
+       ret = mutex_lock_interruptible(&indio_dev->mlock);
+       if (ret)
+               return ret;
+       if ((ev_int && iio_event_enabled(ev_int)) ||
+           iio_buffer_enabled(indio_dev)) {
+               mutex_unlock(&indio_dev->mlock);
+               return -EBUSY;
+       }
+       indio_dev->clock_id = clock_id;
+       mutex_unlock(&indio_dev->mlock);
+
+       return 0;
+}
+
+/**
+ * iio_get_time_ns() - utility function to get a time stamp for events etc
+ * @indio_dev: device
+ */
+s64 iio_get_time_ns(const struct iio_dev *indio_dev)
+{
+       struct timespec tp;
+
+       switch (iio_device_get_clock(indio_dev)) {
+       case CLOCK_REALTIME:
+               ktime_get_real_ts(&tp);
+               break;
+       case CLOCK_MONOTONIC:
+               ktime_get_ts(&tp);
+               break;
+       case CLOCK_MONOTONIC_RAW:
+               getrawmonotonic(&tp);
+               break;
+       case CLOCK_REALTIME_COARSE:
+               tp = current_kernel_time();
+               break;
+       case CLOCK_MONOTONIC_COARSE:
+               tp = get_monotonic_coarse();
+               break;
+       case CLOCK_BOOTTIME:
+               get_monotonic_boottime(&tp);
+               break;
+       case CLOCK_TAI:
+               timekeeping_clocktai(&tp);
+               break;
+       default:
+               BUG();
+       }
+
+       return timespec_to_ns(&tp);
+}
+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 (iio_device_get_clock(indio_dev)) {
+       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;
@@ -990,11 +1070,91 @@ static ssize_t iio_show_dev_name(struct device *dev,
 
 static DEVICE_ATTR(name, S_IRUGO, iio_show_dev_name, NULL);
 
+static ssize_t iio_show_timestamp_clock(struct device *dev,
+                                       struct device_attribute *attr,
+                                       char *buf)
+{
+       const struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+       const clockid_t clk = iio_device_get_clock(indio_dev);
+       const char *name;
+       ssize_t sz;
+
+       switch (clk) {
+       case CLOCK_REALTIME:
+               name = "realtime\n";
+               sz = sizeof("realtime\n");
+               break;
+       case CLOCK_MONOTONIC:
+               name = "monotonic\n";
+               sz = sizeof("monotonic\n");
+               break;
+       case CLOCK_MONOTONIC_RAW:
+               name = "monotonic_raw\n";
+               sz = sizeof("monotonic_raw\n");
+               break;
+       case CLOCK_REALTIME_COARSE:
+               name = "realtime_coarse\n";
+               sz = sizeof("realtime_coarse\n");
+               break;
+       case CLOCK_MONOTONIC_COARSE:
+               name = "monotonic_coarse\n";
+               sz = sizeof("monotonic_coarse\n");
+               break;
+       case CLOCK_BOOTTIME:
+               name = "boottime\n";
+               sz = sizeof("boottime\n");
+               break;
+       case CLOCK_TAI:
+               name = "tai\n";
+               sz = sizeof("tai\n");
+               break;
+       default:
+               BUG();
+       }
+
+       memcpy(buf, name, sz);
+       return sz;
+}
+
+static ssize_t iio_store_timestamp_clock(struct device *dev,
+                                        struct device_attribute *attr,
+                                        const char *buf, size_t len)
+{
+       clockid_t clk;
+       int ret;
+
+       if (sysfs_streq(buf, "realtime"))
+               clk = CLOCK_REALTIME;
+       else if (sysfs_streq(buf, "monotonic"))
+               clk = CLOCK_MONOTONIC;
+       else if (sysfs_streq(buf, "monotonic_raw"))
+               clk = CLOCK_MONOTONIC_RAW;
+       else if (sysfs_streq(buf, "realtime_coarse"))
+               clk = CLOCK_REALTIME_COARSE;
+       else if (sysfs_streq(buf, "monotonic_coarse"))
+               clk = CLOCK_MONOTONIC_COARSE;
+       else if (sysfs_streq(buf, "boottime"))
+               clk = CLOCK_BOOTTIME;
+       else if (sysfs_streq(buf, "tai"))
+               clk = CLOCK_TAI;
+       else
+               return -EINVAL;
+
+       ret = iio_device_set_clock(dev_to_iio_dev(dev), clk);
+       if (ret)
+               return ret;
+
+       return len;
+}
+
+static DEVICE_ATTR(current_timestamp_clock, S_IRUGO | S_IWUSR,
+                  iio_show_timestamp_clock, iio_store_timestamp_clock);
+
 static int iio_device_register_sysfs(struct iio_dev *indio_dev)
 {
        int i, ret = 0, attrcount, attrn, attrcount_orig = 0;
        struct iio_dev_attr *p;
-       struct attribute **attr;
+       struct attribute **attr, *clk = NULL;
 
        /* First count elements in any existing group */
        if (indio_dev->info->attrs) {
@@ -1009,16 +1169,25 @@ static int iio_device_register_sysfs(struct iio_dev *indio_dev)
         */
        if (indio_dev->channels)
                for (i = 0; i < indio_dev->num_channels; i++) {
-                       ret = iio_device_add_channel_sysfs(indio_dev,
-                                                          &indio_dev
-                                                          ->channels[i]);
+                       const struct iio_chan_spec *chan =
+                               &indio_dev->channels[i];
+
+                       if (chan->type == IIO_TIMESTAMP)
+                               clk = &dev_attr_current_timestamp_clock.attr;
+
+                       ret = iio_device_add_channel_sysfs(indio_dev, chan);
                        if (ret < 0)
                                goto error_clear_attrs;
                        attrcount += ret;
                }
 
+       if (indio_dev->event_interface)
+               clk = &dev_attr_current_timestamp_clock.attr;
+
        if (indio_dev->name)
                attrcount++;
+       if (clk)
+               attrcount++;
 
        indio_dev->chan_attr_group.attrs = kcalloc(attrcount + 1,
                                                   sizeof(indio_dev->chan_attr_group.attrs[0]),
@@ -1039,6 +1208,8 @@ static int iio_device_register_sysfs(struct iio_dev *indio_dev)
                indio_dev->chan_attr_group.attrs[attrn++] = &p->dev_attr.attr;
        if (indio_dev->name)
                indio_dev->chan_attr_group.attrs[attrn++] = &dev_attr_name.attr;
+       if (clk)
+               indio_dev->chan_attr_group.attrs[attrn++] = clk;
 
        indio_dev->groups[indio_dev->groupcounter++] =
                &indio_dev->chan_attr_group;
index cae332b1d7ea595959c53ecb3c8f51eef9ba095b..0ebfc923a9975a39326b38049f93cd3dfd1c0601 100644 (file)
@@ -44,6 +44,11 @@ struct iio_event_interface {
        struct mutex            read_lock;
 };
 
+bool iio_event_enabled(const struct iio_event_interface *ev_int)
+{
+       return !!test_bit(IIO_BUSY_BIT_POS, &ev_int->flags);
+}
+
 /**
  * iio_push_event() - try to add event to the list for userspace reading
  * @indio_dev:         IIO device structure
@@ -60,7 +65,7 @@ int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp)
        int copied;
 
        /* Does anyone care? */
-       if (test_bit(IIO_BUSY_BIT_POS, &ev_int->flags)) {
+       if (iio_event_enabled(ev_int)) {
 
                ev.id = ev_code;
                ev.timestamp = timestamp;
@@ -180,8 +185,14 @@ int iio_event_getfd(struct iio_dev *indio_dev)
        if (ev_int == NULL)
                return -ENODEV;
 
-       if (test_and_set_bit(IIO_BUSY_BIT_POS, &ev_int->flags))
-               return -EBUSY;
+       fd = mutex_lock_interruptible(&indio_dev->mlock);
+       if (fd)
+               return fd;
+
+       if (test_and_set_bit(IIO_BUSY_BIT_POS, &ev_int->flags)) {
+               fd = -EBUSY;
+               goto unlock;
+       }
 
        iio_device_get(indio_dev);
 
@@ -194,6 +205,8 @@ int iio_event_getfd(struct iio_dev *indio_dev)
                kfifo_reset_out(&ev_int->det_events);
        }
 
+unlock:
+       mutex_unlock(&indio_dev->mlock);
        return fd;
 }
 
index 98457f044aa54535438d7610997e3c1776d9db04..7ad82fdd3e5bfb0e39565f93fb2491962f97e01b 100644 (file)
@@ -289,7 +289,7 @@ static int iio_trigger_detach_poll_func(struct iio_trigger *trig,
 irqreturn_t iio_pollfunc_store_time(int irq, void *p)
 {
        struct iio_poll_func *pf = p;
-       pf->timestamp = iio_get_time_ns();
+       pf->timestamp = iio_get_time_ns(pf->indio_dev);
        return IRQ_WAKE_THREAD;
 }
 EXPORT_SYMBOL(iio_pollfunc_store_time);
index 53201d99a16c8d760f4ec909c8c5fb1cba6bc8be..f0b47c501f4ecf2dba26ddca6fc60c12bd07cc84 100644 (file)
@@ -118,7 +118,7 @@ static void acpi_als_notify(struct acpi_device *device, u32 event)
        struct iio_dev *indio_dev = acpi_driver_data(device);
        struct acpi_als *als = iio_priv(indio_dev);
        s32 *buffer = als->evt_buffer;
-       s64 time_ns = iio_get_time_ns();
+       s64 time_ns = iio_get_time_ns(indio_dev);
        s32 val;
        int ret;
 
index 09ad5f1ce539a413e65084cac9032819d5b38cbf..0113fc843a8106b83d23b1ad01a81c732feda84e 100644 (file)
@@ -118,7 +118,7 @@ static irqreturn_t adjd_s311_trigger_handler(int irq, void *p)
        struct iio_poll_func *pf = p;
        struct iio_dev *indio_dev = pf->indio_dev;
        struct adjd_s311_data *data = iio_priv(indio_dev);
-       s64 time_ns = iio_get_time_ns();
+       s64 time_ns = iio_get_time_ns(indio_dev);
        int i, j = 0;
 
        int ret = adjd_s311_req_data(indio_dev);
index e1b9fa5a7e9153e0923f8c5f9d7df60928cfe875..649b26f678131f0797bb8ecd5e3fd6ef9f42cc03 100644 (file)
@@ -396,7 +396,7 @@ static irqreturn_t apds9300_interrupt_handler(int irq, void *private)
                       IIO_UNMOD_EVENT_CODE(IIO_INTENSITY, 0,
                                            IIO_EV_TYPE_THRESH,
                                            IIO_EV_DIR_EITHER),
-                      iio_get_time_ns());
+                      iio_get_time_ns(dev_info));
 
        apds9300_clear_intr(data);
 
index 651d57b8abbf910b3e94ad9e628e312b958cbb50..a4304edc3e0fac6b161daa1342c6b99c967b4225 100644 (file)
@@ -807,7 +807,7 @@ static irqreturn_t apds9960_interrupt_handler(int irq, void *private)
                               IIO_UNMOD_EVENT_CODE(IIO_INTENSITY, 0,
                                                    IIO_EV_TYPE_THRESH,
                                                    IIO_EV_DIR_EITHER),
-                              iio_get_time_ns());
+                              iio_get_time_ns(indio_dev));
                regmap_write(data->regmap, APDS9960_REG_CICLEAR, 1);
        }
 
@@ -816,7 +816,7 @@ static irqreturn_t apds9960_interrupt_handler(int irq, void *private)
                               IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 0,
                                                    IIO_EV_TYPE_THRESH,
                                                    IIO_EV_DIR_EITHER),
-                              iio_get_time_ns());
+                              iio_get_time_ns(indio_dev));
                regmap_write(data->regmap, APDS9960_REG_PICLEAR, 1);
        }
 
index c8d7b5ea7e78c880b7bfc1cc1ff829c8c4c4b8aa..9d66e89c57ef6d6aba8bd78c26f5b55d979441e5 100644 (file)
@@ -268,7 +268,7 @@ static irqreturn_t cm36651_irq_handler(int irq, void *data)
                                CM36651_CMD_READ_RAW_PROXIMITY,
                                IIO_EV_TYPE_THRESH, ev_dir);
 
-       iio_push_event(indio_dev, ev_code, iio_get_time_ns());
+       iio_push_event(indio_dev, ev_code, iio_get_time_ns(indio_dev));
 
        return IRQ_HANDLED;
 }
index af73af3586a95a729acd1511bbb7518c59b12c81..6ada9149f1422b644a7340a770fa7f1537595a99 100644 (file)
@@ -851,7 +851,7 @@ static irqreturn_t gp2ap020a00f_prox_sensing_handler(int irq, void *data)
                                    GP2AP020A00F_SCAN_MODE_PROXIMITY,
                                    IIO_EV_TYPE_ROC,
                                    IIO_EV_DIR_RISING),
-                              iio_get_time_ns());
+                              iio_get_time_ns(indio_dev));
                } else {
                        iio_push_event(indio_dev,
                               IIO_UNMOD_EVENT_CODE(
@@ -859,7 +859,7 @@ static irqreturn_t gp2ap020a00f_prox_sensing_handler(int irq, void *data)
                                    GP2AP020A00F_SCAN_MODE_PROXIMITY,
                                    IIO_EV_TYPE_ROC,
                                    IIO_EV_DIR_FALLING),
-                              iio_get_time_ns());
+                              iio_get_time_ns(indio_dev));
                }
        }
 
@@ -925,7 +925,7 @@ static irqreturn_t gp2ap020a00f_thresh_event_handler(int irq, void *data)
                                            IIO_MOD_LIGHT_CLEAR,
                                            IIO_EV_TYPE_THRESH,
                                            IIO_EV_DIR_RISING),
-                                      iio_get_time_ns());
+                                      iio_get_time_ns(indio_dev));
                }
 
                if (test_bit(GP2AP020A00F_FLAG_ALS_FALLING_EV, &priv->flags)) {
@@ -939,7 +939,7 @@ static irqreturn_t gp2ap020a00f_thresh_event_handler(int irq, void *data)
                                            IIO_MOD_LIGHT_CLEAR,
                                            IIO_EV_TYPE_THRESH,
                                            IIO_EV_DIR_FALLING),
-                                      iio_get_time_ns());
+                                      iio_get_time_ns(indio_dev));
                }
        }
 
index a6b9d66233d524fb1d48c338cf59a8891468935f..f48b9e5bdb0ec047c12f1b178e1cff2e273f65ae 100644 (file)
@@ -188,7 +188,7 @@ static irqreturn_t isl29125_trigger_handler(int irq, void *p)
        }
 
        iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
-               iio_get_time_ns());
+               iio_get_time_ns(indio_dev));
 
 done:
        iio_trigger_notify_done(indio_dev->trig);
index e56937c40a189a8f076440c9e2f361755a81cbc8..f409c2047c050104437ca0387bccb5c401c6a602 100644 (file)
@@ -267,7 +267,7 @@ static irqreturn_t lm3533_als_isr(int irq, void *dev_id)
                                            0,
                                            IIO_EV_TYPE_THRESH,
                                            IIO_EV_DIR_EITHER),
-                      iio_get_time_ns());
+                      iio_get_time_ns(indio_dev));
 out:
        return IRQ_HANDLED;
 }
index 6bf89d8f374191cee48f258d1c25810b0e5dc410..3afc53a3d0b607cd0c02ae27e5fb3b7e1a8f3a40 100644 (file)
@@ -1256,7 +1256,8 @@ static irqreturn_t ltr501_trigger_handler(int irq, void *p)
                buf[j++] = psdata & LTR501_PS_DATA_MASK;
        }
 
-       iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns());
+       iio_push_to_buffers_with_timestamp(indio_dev, buf,
+                                          iio_get_time_ns(indio_dev));
 
 done:
        iio_trigger_notify_done(indio_dev->trig);
@@ -1282,14 +1283,14 @@ static irqreturn_t ltr501_interrupt_handler(int irq, void *private)
                               IIO_UNMOD_EVENT_CODE(IIO_INTENSITY, 0,
                                                    IIO_EV_TYPE_THRESH,
                                                    IIO_EV_DIR_EITHER),
-                              iio_get_time_ns());
+                              iio_get_time_ns(indio_dev));
 
        if (status & LTR501_STATUS_PS_INTR)
                iio_push_event(indio_dev,
                               IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 0,
                                                    IIO_EV_TYPE_THRESH,
                                                    IIO_EV_DIR_EITHER),
-                              iio_get_time_ns());
+                              iio_get_time_ns(indio_dev));
 
        return IRQ_HANDLED;
 }
index f17cb2ea18f59c9ea4f368e26488e50d114b05ec..6511b20a2a2966b7db3987e46dae98774f4d5540 100644 (file)
@@ -511,7 +511,8 @@ static irqreturn_t max44000_trigger_handler(int irq, void *p)
        }
        mutex_unlock(&data->lock);
 
-       iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns());
+       iio_push_to_buffers_with_timestamp(indio_dev, buf,
+                                          iio_get_time_ns(indio_dev));
        iio_trigger_notify_done(indio_dev->trig);
        return IRQ_HANDLED;
 
index b776c8ed4387dc289eef2b5810b4217346c8f10f..78c9b3a6453ae57286923a42d9284774b2a696c0 100644 (file)
@@ -713,13 +713,13 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
                                        IIO_UNMOD_EVENT_CODE(IIO_LIGHT, 0,
                                                        IIO_EV_TYPE_THRESH,
                                                        IIO_EV_DIR_RISING),
-                                       iio_get_time_ns());
+                                       iio_get_time_ns(iio));
                if (ret & OPT3001_CONFIGURATION_FL)
                        iio_push_event(iio,
                                        IIO_UNMOD_EVENT_CODE(IIO_LIGHT, 0,
                                                        IIO_EV_TYPE_THRESH,
                                                        IIO_EV_DIR_FALLING),
-                                       iio_get_time_ns());
+                                       iio_get_time_ns(iio));
        } else if (ret & OPT3001_CONFIGURATION_CRF) {
                ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_RESULT);
                if (ret < 0) {
index 9e847f8f4f0cd8b04bbc498f77625d46501a47ec..45cf8b0a43637863456240d6c6bfce9e42db9790 100644 (file)
@@ -528,7 +528,7 @@ static irqreturn_t stk3310_irq_handler(int irq, void *private)
        struct iio_dev *indio_dev = private;
        struct stk3310_data *data = iio_priv(indio_dev);
 
-       data->timestamp = iio_get_time_ns();
+       data->timestamp = iio_get_time_ns(indio_dev);
 
        return IRQ_WAKE_THREAD;
 }
index 8a15fb541dc34393346d6f08d11418c0af4a2c63..a795afb7667bdeb7ec23987a64aaa897a88ed890 100644 (file)
@@ -216,7 +216,7 @@ static irqreturn_t tcs3414_trigger_handler(int irq, void *p)
        }
 
        iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
-               iio_get_time_ns());
+               iio_get_time_ns(indio_dev));
 
 done:
        iio_trigger_notify_done(indio_dev->trig);
index b29312f9907705fddb100d0b0e253fabfadfde1d..3aa71e34ae28b39350033616805eb6f2d5480714 100644 (file)
@@ -202,7 +202,7 @@ static irqreturn_t tcs3472_trigger_handler(int irq, void *p)
        }
 
        iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
-               iio_get_time_ns());
+               iio_get_time_ns(indio_dev));
 
 done:
        iio_trigger_notify_done(indio_dev->trig);
index 57b108c30e9801165658a9fef26d3b0e44586b94..04598ae993d44913a822e61f74901fb194076a01 100644 (file)
@@ -630,7 +630,7 @@ static irqreturn_t tsl2563_event_handler(int irq, void *private)
                                            0,
                                            IIO_EV_TYPE_THRESH,
                                            IIO_EV_DIR_EITHER),
-                      iio_get_time_ns());
+                      iio_get_time_ns(dev_info));
 
        /* clear the interrupt and push the event */
        i2c_smbus_write_byte(chip->client, TSL2563_CMD | TSL2563_CLEARINT);
index 45bc2f742f46af4c3485da83f3920fc2cabaff37..20c40f7809643342756db86060b98ea6536053e9 100644 (file)
@@ -833,7 +833,7 @@ static irqreturn_t us5182d_irq_thread_handler(int irq, void *private)
        dir = ret & US5182D_CFG0_PROX ? IIO_EV_DIR_RISING : IIO_EV_DIR_FALLING;
        ev = IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 1, IIO_EV_TYPE_THRESH, dir);
 
-       iio_push_event(indio_dev, ev, iio_get_time_ns());
+       iio_push_event(indio_dev, ev, iio_get_time_ns(indio_dev));
 
        ret = i2c_smbus_write_byte_data(data->client, US5182D_REG_CFG0,
                                        ret & ~US5182D_CFG0_PX_IRQ);
index 57d3654d7caf63755ebf6beba5933353778343a0..2121b50ab9b3cfb823414c2ff7a286c891e40751 100644 (file)
@@ -829,7 +829,8 @@ static void ak8975_fill_buffer(struct iio_dev *indio_dev)
        buff[1] = clamp_t(s16, le16_to_cpu(buff[1]), -def->range, def->range);
        buff[2] = clamp_t(s16, le16_to_cpu(buff[2]), -def->range, def->range);
 
-       iio_push_to_buffers_with_timestamp(indio_dev, buff, iio_get_time_ns());
+       iio_push_to_buffers_with_timestamp(indio_dev, buff,
+                                          iio_get_time_ns(indio_dev));
        return;
 
 unlock:
index 77882b466e0f481b8c0d15180134b60a0afbebec..ba3e2a374ee5f51e9a3528fbfddb65aeccc1e7b6 100644 (file)
@@ -451,7 +451,7 @@ static irqreturn_t hmc5843_trigger_handler(int irq, void *p)
                goto done;
 
        iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
-                                          iio_get_time_ns());
+                                          iio_get_time_ns(indio_dev));
 
 done:
        iio_trigger_notify_done(indio_dev->trig);
index 261d517428e475d49b89d9d8567666abe42750a0..f2be4a04905665426a198bfda9628beaa365d7cb 100644 (file)
@@ -261,7 +261,7 @@ static irqreturn_t mag3110_trigger_handler(int irq, void *p)
        }
 
        iio_push_to_buffers_with_timestamp(indio_dev, buffer,
-               iio_get_time_ns());
+               iio_get_time_ns(indio_dev));
 
 done:
        iio_trigger_notify_done(indio_dev->trig);
index 01b2e0b1887881910874a43fb7efec4c4298a609..6392d7b62841024e237cc5a4d19bdb5b0fbb18b5 100644 (file)
@@ -171,7 +171,7 @@ static irqreturn_t mpl3115_trigger_handler(int irq, void *p)
        mutex_unlock(&data->lock);
 
        iio_push_to_buffers_with_timestamp(indio_dev, buffer,
-               iio_get_time_ns());
+               iio_get_time_ns(indio_dev));
 
 done:
        iio_trigger_notify_done(indio_dev->trig);
index 76578b07bb6e6e67734cbcf0236131c612cec92c..feb41f82c64ad58dacde63c35ba7096868b37965 100644 (file)
@@ -224,7 +224,8 @@ static irqreturn_t ms5611_trigger_handler(int irq, void *p)
        if (ret < 0)
                goto err;
 
-       iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns());
+       iio_push_to_buffers_with_timestamp(indio_dev, buf,
+                                          iio_get_time_ns(indio_dev));
 
 err:
        iio_trigger_notify_done(indio_dev->trig);
index c0b0e82abf9471766cb047cc2d2159a326f74905..3141c3c161bb4335cae5bc16f40c72339c474948 100644 (file)
@@ -238,7 +238,7 @@ static irqreturn_t lidar_trigger_handler(int irq, void *private)
        ret = lidar_get_measurement(data, data->buffer);
        if (!ret) {
                iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
-                                                  iio_get_time_ns());
+                                                  iio_get_time_ns(indio_dev));
        } else if (ret != -EINVAL) {
                dev_err(&data->client->dev, "cannot read LIDAR measurement");
        }
index 66cd09a18786a9123c7eeeb82c0e503ae9dee5e6..1d74b3aafeedbcc7a7c44dc8abd8505424b17932 100644 (file)
@@ -492,7 +492,7 @@ static void sx9500_push_events(struct iio_dev *indio_dev)
                dir = new_prox ? IIO_EV_DIR_FALLING : IIO_EV_DIR_RISING;
                ev = IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, chan,
                                          IIO_EV_TYPE_THRESH, dir);
-               iio_push_event(indio_dev, ev, iio_get_time_ns());
+               iio_push_event(indio_dev, ev, iio_get_time_ns(indio_dev));
                data->prox_stat[chan] = new_prox;
        }
 }
@@ -669,7 +669,7 @@ static irqreturn_t sx9500_trigger_handler(int irq, void *private)
        }
 
        iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
-                                          iio_get_time_ns());
+                                          iio_get_time_ns(indio_dev));
 
 out:
        mutex_unlock(&data->mutex);
index 7a6fed3f2d3f1074ebbe3d9987fe5d5ac347128b..5c3410a74fdb4d174eee6c8fb6770d0cba16eac4 100644 (file)
@@ -451,7 +451,7 @@ static irqreturn_t lis3l02dq_event_handler(int irq, void *private)
        struct iio_dev *indio_dev = private;
        u8 t;
 
-       s64 timestamp = iio_get_time_ns();
+       s64 timestamp = iio_get_time_ns(indio_dev);
 
        lis3l02dq_spi_read_reg_8(indio_dev,
                                 LIS3L02DQ_REG_WAKE_UP_SRC_ADDR,
index 53c5425d02b3f162e574c3acb5c6ed634009f5cc..aacf643e87d3b7186d5e187439d02ef116fd1149 100644 (file)
@@ -774,7 +774,7 @@ static irqreturn_t sca3000_event_handler(int irq, void *private)
        struct iio_dev *indio_dev = private;
        struct sca3000_state *st = iio_priv(indio_dev);
        int ret, val;
-       s64 last_timestamp = iio_get_time_ns();
+       s64 last_timestamp = iio_get_time_ns(indio_dev);
 
        /*
         * Could lead if badly timed to an extra read of status reg,
index a06b46cb81caa08e74a2728e8b1d955431a0a930..2177f1dd2b5dfc4b1c66d79f7937f21014d0c9e1 100644 (file)
@@ -705,7 +705,7 @@ static irqreturn_t ad7280_event_handler(int irq, void *private)
                                                        IIO_EV_DIR_RISING,
                                                        IIO_EV_TYPE_THRESH,
                                                        0, 0, 0),
-                                              iio_get_time_ns());
+                                              iio_get_time_ns(indio_dev));
                        else if (((channels[i] >> 11) & 0xFFF) <=
                                st->cell_threshlow)
                                iio_push_event(indio_dev,
@@ -715,7 +715,7 @@ static irqreturn_t ad7280_event_handler(int irq, void *private)
                                                        IIO_EV_DIR_FALLING,
                                                        IIO_EV_TYPE_THRESH,
                                                        0, 0, 0),
-                                              iio_get_time_ns());
+                                              iio_get_time_ns(indio_dev));
                } else {
                        if (((channels[i] >> 11) & 0xFFF) >= st->aux_threshhigh)
                                iio_push_event(indio_dev,
@@ -724,7 +724,7 @@ static irqreturn_t ad7280_event_handler(int irq, void *private)
                                                        0,
                                                        IIO_EV_TYPE_THRESH,
                                                        IIO_EV_DIR_RISING),
-                                              iio_get_time_ns());
+                                              iio_get_time_ns(indio_dev));
                        else if (((channels[i] >> 11) & 0xFFF) <=
                                st->aux_threshlow)
                                iio_push_event(indio_dev,
@@ -733,7 +733,7 @@ static irqreturn_t ad7280_event_handler(int irq, void *private)
                                                        0,
                                                        IIO_EV_TYPE_THRESH,
                                                        IIO_EV_DIR_FALLING),
-                                              iio_get_time_ns());
+                                              iio_get_time_ns(indio_dev));
                }
        }
 
index a6f8eb11242c124cc292e74594e16320bf092f9f..0572df9aad85278c9242f045fc5e766f01891ef8 100644 (file)
@@ -77,7 +77,8 @@ static void ad7606_poll_bh_to_ring(struct work_struct *work_s)
                        goto done;
        }
 
-       iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns());
+       iio_push_to_buffers_with_timestamp(indio_dev, buf,
+                                          iio_get_time_ns(indio_dev));
 done:
        gpio_set_value(st->pdata->gpio_convst, 0);
        iio_trigger_notify_done(indio_dev->trig);
index ac3735c7f4a94a30dd2859bd6633fd7a739fb2d2..5e8115b0101159377c2c06f9669b7fe653276e97 100644 (file)
@@ -253,7 +253,8 @@ static const struct attribute_group ad7816_attribute_group = {
 
 static irqreturn_t ad7816_event_handler(int irq, void *private)
 {
-       iio_push_event(private, IIO_EVENT_CODE_AD7816_OTI, iio_get_time_ns());
+       iio_push_event(private, IIO_EVENT_CODE_AD7816_OTI,
+                      iio_get_time_ns((struct iio_dev *)private));
        return IRQ_HANDLED;
 }
 
index a10e7d8e600287ce63cfcab9375e164df8549fba..3faffe59c9336768394533faffc66847e7b01071 100644 (file)
@@ -1752,7 +1752,7 @@ static irqreturn_t adt7316_event_handler(int irq, void *private)
                if ((chip->id & ID_FAMILY_MASK) != ID_ADT75XX)
                        stat1 &= 0x1F;
 
-               time = iio_get_time_ns();
+               time = iio_get_time_ns(indio_dev);
                if (stat1 & BIT(0))
                        iio_push_event(indio_dev,
                                       IIO_UNMOD_EVENT_CODE(IIO_TEMP, 0,
@@ -1804,7 +1804,7 @@ static irqreturn_t adt7316_event_handler(int irq, void *private)
                                                            0,
                                                            IIO_EV_TYPE_THRESH,
                                                            IIO_EV_DIR_RISING),
-                                      iio_get_time_ns());
+                                      iio_get_time_ns(indio_dev));
        }
 
        return IRQ_HANDLED;
index f6b9a10326ea450a9873a077f09a2008c1b1cc1d..5578a077fcfbd2699209530fa9c1a1605bb0007c 100644 (file)
@@ -493,7 +493,7 @@ static irqreturn_t ad7150_event_handler(int irq, void *private)
        struct iio_dev *indio_dev = private;
        struct ad7150_chip_info *chip = iio_priv(indio_dev);
        u8 int_status;
-       s64 timestamp = iio_get_time_ns();
+       s64 timestamp = iio_get_time_ns(indio_dev);
        int ret;
 
        ret = i2c_smbus_read_byte_data(chip->client, AD7150_STATUS);
index d553c8e18fccf7c71a370a12626a0260774cff05..ea15bc1c300cf2fa1aa60bef5ffb2cc4caa0f438 100644 (file)
@@ -1554,7 +1554,7 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
 {
        struct iio_dev *indio_dev = private;
        struct tsl2X7X_chip *chip = iio_priv(indio_dev);
-       s64 timestamp = iio_get_time_ns();
+       s64 timestamp = iio_get_time_ns(indio_dev);
        int ret;
        u8 value;
 
index 7c29cb0124ae2f0e0a97764028f74985bf9e879f..854e2dad1e0df71af7f0d29f443e07ed77b3f24f 100644 (file)
@@ -312,13 +312,8 @@ static inline bool iio_channel_has_info(const struct iio_chan_spec *chan,
                },                                                      \
 }
 
-/**
- * iio_get_time_ns() - utility function to get a time stamp for events etc
- **/
-static inline s64 iio_get_time_ns(void)
-{
-       return ktime_get_real_ns();
-}
+s64 iio_get_time_ns(const struct iio_dev *indio_dev);
+unsigned int iio_get_time_res(const struct iio_dev *indio_dev);
 
 /* Device operating modes */
 #define INDIO_DIRECT_MODE              0x01
@@ -497,6 +492,7 @@ struct iio_buffer_setup_ops {
  * @chan_attr_group:   [INTERN] group for all attrs in base directory
  * @name:              [DRIVER] name of the device.
  * @info:              [DRIVER] callbacks and constant info from driver
+ * @clock_id:          [INTERN] timestamping clock posix identifier
  * @info_exist_lock:   [INTERN] lock to prevent use during removal
  * @setup_ops:         [DRIVER] callbacks to call before and after buffer
  *                     enable/disable
@@ -537,6 +533,7 @@ struct iio_dev {
        struct attribute_group          chan_attr_group;
        const char                      *name;
        const struct iio_info           *info;
+       clockid_t                       clock_id;
        struct mutex                    info_exist_lock;
        const struct iio_buffer_setup_ops       *setup_ops;
        struct cdev                     chrdev;
@@ -565,7 +562,7 @@ extern struct bus_type iio_bus_type;
 
 /**
  * iio_device_put() - reference counted deallocation of struct device
- * @indio_dev:                 IIO device structure containing the device
+ * @indio_dev: IIO device structure containing the device
  **/
 static inline void iio_device_put(struct iio_dev *indio_dev)
 {
@@ -573,6 +570,15 @@ static inline void iio_device_put(struct iio_dev *indio_dev)
                put_device(&indio_dev->dev);
 }
 
+/**
+ * iio_device_get_clock() - Retrieve current timestamping clock for the device
+ * @indio_dev: IIO device structure containing the device
+ */
+static inline clockid_t iio_device_get_clock(const struct iio_dev *indio_dev)
+{
+       return indio_dev->clock_id;
+}
+
 /**
  * dev_to_iio_dev() - Get IIO device struct from a device struct
  * @dev:               The device embedded in the IIO device