Mauro Carvalho Chehab | 1c349f4 | 2019-06-18 17:53:40 -0300 | [diff] [blame] | 1 | =============================== |
Daniel Baluta | 4c3e2a4 | 2015-11-09 09:14:02 +0200 | [diff] [blame] | 2 | Industrial IIO configfs support |
Mauro Carvalho Chehab | 1c349f4 | 2019-06-18 17:53:40 -0300 | [diff] [blame] | 3 | =============================== |
Daniel Baluta | 4c3e2a4 | 2015-11-09 09:14:02 +0200 | [diff] [blame] | 4 | |
| 5 | 1. Overview |
Mauro Carvalho Chehab | 1c349f4 | 2019-06-18 17:53:40 -0300 | [diff] [blame] | 6 | =========== |
Daniel Baluta | 4c3e2a4 | 2015-11-09 09:14:02 +0200 | [diff] [blame] | 7 | |
| 8 | Configfs is a filesystem-based manager of kernel objects. IIO uses some |
| 9 | objects that could be easily configured using configfs (e.g.: devices, |
| 10 | triggers). |
| 11 | |
| 12 | See Documentation/filesystems/configfs/configfs.txt for more information |
| 13 | about how configfs works. |
| 14 | |
| 15 | 2. Usage |
Mauro Carvalho Chehab | 1c349f4 | 2019-06-18 17:53:40 -0300 | [diff] [blame] | 16 | ======== |
Daniel Baluta | 4c3e2a4 | 2015-11-09 09:14:02 +0200 | [diff] [blame] | 17 | |
| 18 | In order to use configfs support in IIO we need to select it at compile |
| 19 | time via CONFIG_IIO_CONFIGFS config option. |
| 20 | |
Mauro Carvalho Chehab | 1c349f4 | 2019-06-18 17:53:40 -0300 | [diff] [blame] | 21 | Then, mount the configfs filesystem (usually under /config directory):: |
Daniel Baluta | 4c3e2a4 | 2015-11-09 09:14:02 +0200 | [diff] [blame] | 22 | |
Mauro Carvalho Chehab | 1c349f4 | 2019-06-18 17:53:40 -0300 | [diff] [blame] | 23 | $ mkdir /config |
| 24 | $ mount -t configfs none /config |
Daniel Baluta | 4c3e2a4 | 2015-11-09 09:14:02 +0200 | [diff] [blame] | 25 | |
| 26 | At this point, all default IIO groups will be created and can be accessed |
| 27 | under /config/iio. Next chapters will describe available IIO configuration |
| 28 | objects. |
| 29 | |
| 30 | 3. Software triggers |
Mauro Carvalho Chehab | 1c349f4 | 2019-06-18 17:53:40 -0300 | [diff] [blame] | 31 | ==================== |
Daniel Baluta | 4c3e2a4 | 2015-11-09 09:14:02 +0200 | [diff] [blame] | 32 | |
| 33 | One of the IIO default configfs groups is the "triggers" group. It is |
| 34 | automagically accessible when the configfs is mounted and can be found |
| 35 | under /config/iio/triggers. |
| 36 | |
| 37 | IIO software triggers implementation offers support for creating multiple |
| 38 | trigger types. A new trigger type is usually implemented as a separate |
Mauro Carvalho Chehab | 1c349f4 | 2019-06-18 17:53:40 -0300 | [diff] [blame] | 39 | kernel module following the interface in include/linux/iio/sw_trigger.h:: |
Daniel Baluta | 4c3e2a4 | 2015-11-09 09:14:02 +0200 | [diff] [blame] | 40 | |
Mauro Carvalho Chehab | 1c349f4 | 2019-06-18 17:53:40 -0300 | [diff] [blame] | 41 | /* |
| 42 | * drivers/iio/trigger/iio-trig-sample.c |
| 43 | * sample kernel module implementing a new trigger type |
| 44 | */ |
| 45 | #include <linux/iio/sw_trigger.h> |
Daniel Baluta | 4c3e2a4 | 2015-11-09 09:14:02 +0200 | [diff] [blame] | 46 | |
| 47 | |
Mauro Carvalho Chehab | 1c349f4 | 2019-06-18 17:53:40 -0300 | [diff] [blame] | 48 | static struct iio_sw_trigger *iio_trig_sample_probe(const char *name) |
| 49 | { |
Daniel Baluta | 4c3e2a4 | 2015-11-09 09:14:02 +0200 | [diff] [blame] | 50 | /* |
| 51 | * This allocates and registers an IIO trigger plus other |
| 52 | * trigger type specific initialization. |
| 53 | */ |
Mauro Carvalho Chehab | 1c349f4 | 2019-06-18 17:53:40 -0300 | [diff] [blame] | 54 | } |
Daniel Baluta | 4c3e2a4 | 2015-11-09 09:14:02 +0200 | [diff] [blame] | 55 | |
Mauro Carvalho Chehab | 1c349f4 | 2019-06-18 17:53:40 -0300 | [diff] [blame] | 56 | static int iio_trig_hrtimer_remove(struct iio_sw_trigger *swt) |
| 57 | { |
Daniel Baluta | 4c3e2a4 | 2015-11-09 09:14:02 +0200 | [diff] [blame] | 58 | /* |
| 59 | * This undoes the actions in iio_trig_sample_probe |
| 60 | */ |
Mauro Carvalho Chehab | 1c349f4 | 2019-06-18 17:53:40 -0300 | [diff] [blame] | 61 | } |
Daniel Baluta | 4c3e2a4 | 2015-11-09 09:14:02 +0200 | [diff] [blame] | 62 | |
Mauro Carvalho Chehab | 1c349f4 | 2019-06-18 17:53:40 -0300 | [diff] [blame] | 63 | static const struct iio_sw_trigger_ops iio_trig_sample_ops = { |
Daniel Baluta | 4c3e2a4 | 2015-11-09 09:14:02 +0200 | [diff] [blame] | 64 | .probe = iio_trig_sample_probe, |
| 65 | .remove = iio_trig_sample_remove, |
Mauro Carvalho Chehab | 1c349f4 | 2019-06-18 17:53:40 -0300 | [diff] [blame] | 66 | }; |
Daniel Baluta | 4c3e2a4 | 2015-11-09 09:14:02 +0200 | [diff] [blame] | 67 | |
Mauro Carvalho Chehab | 1c349f4 | 2019-06-18 17:53:40 -0300 | [diff] [blame] | 68 | static struct iio_sw_trigger_type iio_trig_sample = { |
Daniel Baluta | 4c3e2a4 | 2015-11-09 09:14:02 +0200 | [diff] [blame] | 69 | .name = "trig-sample", |
| 70 | .owner = THIS_MODULE, |
| 71 | .ops = &iio_trig_sample_ops, |
Mauro Carvalho Chehab | 1c349f4 | 2019-06-18 17:53:40 -0300 | [diff] [blame] | 72 | }; |
Daniel Baluta | 4c3e2a4 | 2015-11-09 09:14:02 +0200 | [diff] [blame] | 73 | |
| 74 | module_iio_sw_trigger_driver(iio_trig_sample); |
| 75 | |
| 76 | Each trigger type has its own directory under /config/iio/triggers. Loading |
| 77 | iio-trig-sample module will create 'trig-sample' trigger type directory |
| 78 | /config/iio/triggers/trig-sample. |
| 79 | |
| 80 | We support the following interrupt sources (trigger types): |
Mauro Carvalho Chehab | 1c349f4 | 2019-06-18 17:53:40 -0300 | [diff] [blame] | 81 | |
Daniel Baluta | 4c3e2a4 | 2015-11-09 09:14:02 +0200 | [diff] [blame] | 82 | * hrtimer, uses high resolution timers as interrupt source |
| 83 | |
| 84 | 3.1 Hrtimer triggers creation and destruction |
Mauro Carvalho Chehab | 1c349f4 | 2019-06-18 17:53:40 -0300 | [diff] [blame] | 85 | --------------------------------------------- |
Daniel Baluta | 4c3e2a4 | 2015-11-09 09:14:02 +0200 | [diff] [blame] | 86 | |
| 87 | Loading iio-trig-hrtimer module will register hrtimer trigger types allowing |
| 88 | users to create hrtimer triggers under /config/iio/triggers/hrtimer. |
| 89 | |
Mauro Carvalho Chehab | 1c349f4 | 2019-06-18 17:53:40 -0300 | [diff] [blame] | 90 | e.g:: |
Daniel Baluta | 4c3e2a4 | 2015-11-09 09:14:02 +0200 | [diff] [blame] | 91 | |
Mauro Carvalho Chehab | 1c349f4 | 2019-06-18 17:53:40 -0300 | [diff] [blame] | 92 | $ mkdir /config/iio/triggers/hrtimer/instance1 |
| 93 | $ rmdir /config/iio/triggers/hrtimer/instance1 |
Daniel Baluta | 4c3e2a4 | 2015-11-09 09:14:02 +0200 | [diff] [blame] | 94 | |
| 95 | Each trigger can have one or more attributes specific to the trigger type. |
| 96 | |
| 97 | 3.2 "hrtimer" trigger types attributes |
Mauro Carvalho Chehab | 1c349f4 | 2019-06-18 17:53:40 -0300 | [diff] [blame] | 98 | -------------------------------------- |
Daniel Baluta | 4c3e2a4 | 2015-11-09 09:14:02 +0200 | [diff] [blame] | 99 | |
| 100 | "hrtimer" trigger type doesn't have any configurable attribute from /config dir. |
| 101 | It does introduce the sampling_frequency attribute to trigger directory. |