drm/i915: Record device minor rather than pointer in TRACE_EVENT
[safe/jmp/linux-2.6] / drivers / staging / iio / trigger.h
1 /* The industrial I/O core, trigger handling functions
2  *
3  * Copyright (c) 2008 Jonathan Cameron
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 as published by
7  * the Free Software Foundation.
8  */
9 #ifndef _IIO_TRIGGER_H_
10 #define _IIO_TRIGGER_H_
11 #define IIO_TRIGGER_NAME_LENGTH 20
12 #define IIO_TRIGGER_ID_PREFIX "iio:trigger"
13 #define IIO_TRIGGER_ID_FORMAT IIO_TRIGGER_ID_PREFIX "%d"
14
15
16 /**
17  * struct iio_trigger - industrial I/O trigger device
18  *
19  * @id:                 [INTERN] unique id number
20  * @name:               [DRIVER] unique name
21  * @dev:                [DRIVER] associated device (if relevant)
22  * @sysfs_dev:          [INTERN] sysfs relevant device
23  * @private_data:       [DRIVER] device specific data
24  * @list:               [INTERN] used in maintenance of global trigger list
25  * @alloc_list:         [DRIVER] used for driver specific trigger list
26  * @poll_func_list_lock:[INTERN] protection of the polling function list
27  * @pollfunc_list:      [INTERN] list of functions to run on trigger.
28  * @control_attrs:      [DRIVER] sysfs attributes relevant to trigger type
29  * @set_trigger_state:  [DRIVER] switch on/off the trigger on demand
30  * @timestamp:          [INTERN] timestamp usesd by some trigs (e.g. datardy)
31  * @owner:              [DRIVER] used to monitor usage count of the trigger.
32  **/
33 struct iio_trigger {
34         int                             id;
35         const char                      *name;
36         struct device                   dev;
37
38         void                            *private_data;
39         struct list_head                list;
40         struct list_head                alloc_list;
41         spinlock_t                      pollfunc_list_lock;
42         struct list_head                pollfunc_list;
43         const struct attribute_group    *control_attrs;
44         s64                             timestamp;
45         struct module                   *owner;
46         int use_count;
47
48         int (*set_trigger_state)(struct iio_trigger *trig, bool state);
49         int (*try_reenable)(struct iio_trigger *trig);
50 };
51
52 static inline struct iio_trigger *to_iio_trigger(struct device *d)
53 {
54         return container_of(d, struct iio_trigger, dev);
55 };
56
57 static inline void iio_put_trigger(struct iio_trigger *trig)
58 {
59         put_device(&trig->dev);
60         module_put(trig->owner);
61 };
62
63 static inline void iio_get_trigger(struct iio_trigger *trig)
64 {
65         __module_get(trig->owner);
66         get_device(&trig->dev);
67 };
68
69 /**
70  * iio_trigger_read_name() - sysfs access function to get the trigger name
71  **/
72 ssize_t iio_trigger_read_name(struct device *dev,
73                               struct device_attribute *attr,
74                               char *buf);
75
76 #define IIO_TRIGGER_NAME_ATTR DEVICE_ATTR(name, S_IRUGO,                \
77                                           iio_trigger_read_name,        \
78                                           NULL);
79
80 /**
81  * iio_trigger_find_by_name() - search global trigger list
82  **/
83 struct iio_trigger *iio_trigger_find_by_name(const char *name, size_t len);
84
85 /**
86  * iio_trigger_register() - register a trigger with the IIO core
87  * @trig_info:  trigger to be registered
88  **/
89 int iio_trigger_register(struct iio_trigger *trig_info);
90
91 /**
92  * iio_trigger_unregister() - unregister a trigger from the core
93  **/
94 void iio_trigger_unregister(struct iio_trigger *trig_info);
95
96 /**
97  * iio_trigger_attach_poll_func() - add a function pair to be run on trigger
98  * @trig:       trigger to which the function pair are being added
99  * @pf: poll function pair
100  **/
101 int iio_trigger_attach_poll_func(struct iio_trigger *trig,
102                                  struct iio_poll_func *pf);
103
104 /**
105  * iio_trigger_dettach_poll_func() -    remove function pair from those to be
106  *                                      run on trigger.
107  * @trig:       trigger from which the function is being removed.
108  * @pf:         poll function pair
109  **/
110 int iio_trigger_dettach_poll_func(struct iio_trigger *trig,
111                                   struct iio_poll_func *pf);
112
113 /**
114  * iio_trigger_poll() - called on a trigger occuring
115  * Typically called in relevant hardware interrupt handler.
116  **/
117 void iio_trigger_poll(struct iio_trigger *);
118 void iio_trigger_notify_done(struct iio_trigger *);
119
120 /**
121  * struct iio_poll_func - poll function pair
122  *
123  * @list:                       associate this with a triggers pollfunc_list
124  * @private_data:               data specific to device (passed into poll func)
125  * @poll_func_immediate:        function in here is run first. They should be
126  *                              extremely lightweight.  Typically used for latch
127  *                              control on sensor supporting it.
128  * @poll_func_main:             function in here is run after all immediates.
129  *                              Reading from sensor etc typically involves
130  *                              scheduling
131  *                              from here.
132  *
133  * The two stage approach used here only important when multiple sensors are
134  * being triggered by a single trigger. This really comes into it's own with
135  * simultaneous sampling devices where a simple latch command can be used to
136  * make the device store the values on all inputs.
137  **/
138 struct iio_poll_func {
139         struct                          list_head list;
140         void                            *private_data;
141         void (*poll_func_immediate)(struct iio_dev *indio_dev);
142         void (*poll_func_main)(struct iio_dev  *private_data);
143
144 };
145
146 struct iio_trigger *iio_allocate_trigger(void);
147
148 void iio_free_trigger(struct iio_trigger *trig);
149
150
151 #endif /* _IIO_TRIGGER_H_ */