iio: dummy: Demonstrate the usage of new channel types
[firefly-linux-kernel-4.4.55.git] / drivers / staging / iio / iio_simple_dummy_events.c
index 719dfa5ae7dfb5037290322d1d4777ef7e15eedd..ac15a44ba2713213a14c4dc3ccaecc11b4ed9606 100644 (file)
@@ -72,6 +72,22 @@ int iio_simple_dummy_write_event_config(struct iio_dev *indio_dev,
                                st->event_en = state;
                        else
                                return -EINVAL;
+               default:
+                       return -EINVAL;
+               }
+               break;
+       case IIO_ACTIVITY:
+               switch (type) {
+               case IIO_EV_TYPE_THRESH:
+                       st->event_en = state;
+                       break;
+               default:
+                       return -EINVAL;
+               }
+       case IIO_STEPS:
+               switch (type) {
+               case IIO_EV_TYPE_INSTANCE:
+                       st->event_en = state;
                        break;
                default:
                        return -EINVAL;
@@ -161,6 +177,33 @@ static irqreturn_t iio_simple_dummy_event_handler(int irq, void *private)
                                              IIO_EV_TYPE_THRESH, 0, 0, 0),
                               iio_get_time_ns());
                break;
+       case 1:
+               if (st->activity_running > st->event_val)
+                       iio_push_event(indio_dev,
+                                      IIO_EVENT_CODE(IIO_ACTIVITY, 0,
+                                                     IIO_MOD_RUNNING,
+                                                     IIO_EV_DIR_RISING,
+                                                     IIO_EV_TYPE_THRESH,
+                                                     0, 0, 0),
+                                      iio_get_time_ns());
+               break;
+       case 2:
+               if (st->activity_walking < st->event_val)
+                       iio_push_event(indio_dev,
+                                      IIO_EVENT_CODE(IIO_ACTIVITY, 0,
+                                                     IIO_MOD_WALKING,
+                                                     IIO_EV_DIR_FALLING,
+                                                     IIO_EV_TYPE_THRESH,
+                                                     0, 0, 0),
+                                      iio_get_time_ns());
+               break;
+       case 3:
+               iio_push_event(indio_dev,
+                              IIO_EVENT_CODE(IIO_STEPS, 0, IIO_NO_MOD,
+                                             IIO_EV_DIR_NONE,
+                                             IIO_EV_TYPE_INSTANCE, 0, 0, 0),
+                              iio_get_time_ns());
+               break;
        default:
                break;
        }