diff options
Diffstat (limited to 'include/linux/iio/iio.h')
-rw-r--r-- | include/linux/iio/iio.h | 108 |
1 files changed, 93 insertions, 15 deletions
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h index 3a4f6a3ab80d..be82936c4089 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h | |||
@@ -130,14 +130,78 @@ struct iio_chan_spec_ext_info { | |||
130 | }; | 130 | }; |
131 | 131 | ||
132 | /** | 132 | /** |
133 | * struct iio_enum - Enum channel info attribute | ||
134 | * @items: An array of strings. | ||
135 | * @num_items: Length of the item array. | ||
136 | * @set: Set callback function, may be NULL. | ||
137 | * @get: Get callback function, may be NULL. | ||
138 | * | ||
139 | * The iio_enum struct can be used to implement enum style channel attributes. | ||
140 | * Enum style attributes are those which have a set of strings which map to | ||
141 | * unsigned integer values. The IIO enum helper code takes care of mapping | ||
142 | * between value and string as well as generating a "_available" file which | ||
143 | * contains a list of all available items. The set callback will be called when | ||
144 | * the attribute is updated. The last parameter is the index to the newly | ||
145 | * activated item. The get callback will be used to query the currently active | ||
146 | * item and is supposed to return the index for it. | ||
147 | */ | ||
148 | struct iio_enum { | ||
149 | const char * const *items; | ||
150 | unsigned int num_items; | ||
151 | int (*set)(struct iio_dev *, const struct iio_chan_spec *, unsigned int); | ||
152 | int (*get)(struct iio_dev *, const struct iio_chan_spec *); | ||
153 | }; | ||
154 | |||
155 | ssize_t iio_enum_available_read(struct iio_dev *indio_dev, | ||
156 | uintptr_t priv, const struct iio_chan_spec *chan, char *buf); | ||
157 | ssize_t iio_enum_read(struct iio_dev *indio_dev, | ||
158 | uintptr_t priv, const struct iio_chan_spec *chan, char *buf); | ||
159 | ssize_t iio_enum_write(struct iio_dev *indio_dev, | ||
160 | uintptr_t priv, const struct iio_chan_spec *chan, const char *buf, | ||
161 | size_t len); | ||
162 | |||
163 | /** | ||
164 | * IIO_ENUM() - Initialize enum extended channel attribute | ||
165 | * @_name: Attribute name | ||
166 | * @_shared: Whether the attribute is shared between all channels | ||
167 | * @_e: Pointer to a iio_enum struct | ||
168 | * | ||
169 | * This should usually be used together with IIO_ENUM_AVAILABLE() | ||
170 | */ | ||
171 | #define IIO_ENUM(_name, _shared, _e) \ | ||
172 | { \ | ||
173 | .name = (_name), \ | ||
174 | .shared = (_shared), \ | ||
175 | .read = iio_enum_read, \ | ||
176 | .write = iio_enum_write, \ | ||
177 | .private = (uintptr_t)(_e), \ | ||
178 | } | ||
179 | |||
180 | /** | ||
181 | * IIO_ENUM_AVAILABLE() - Initialize enum available extended channel attribute | ||
182 | * @_name: Attribute name ("_available" will be appended to the name) | ||
183 | * @_e: Pointer to a iio_enum struct | ||
184 | * | ||
185 | * Creates a read only attribute which list all the available enum items in a | ||
186 | * space separated list. This should usually be used together with IIO_ENUM() | ||
187 | */ | ||
188 | #define IIO_ENUM_AVAILABLE(_name, _e) \ | ||
189 | { \ | ||
190 | .name = (_name "_available"), \ | ||
191 | .shared = true, \ | ||
192 | .read = iio_enum_available_read, \ | ||
193 | .private = (uintptr_t)(_e), \ | ||
194 | } | ||
195 | |||
196 | /** | ||
133 | * struct iio_chan_spec - specification of a single channel | 197 | * struct iio_chan_spec - specification of a single channel |
134 | * @type: What type of measurement is the channel making. | 198 | * @type: What type of measurement is the channel making. |
135 | * @channel: What number or name do we wish to assign the channel. | 199 | * @channel: What number do we wish to assign the channel. |
136 | * @channel2: If there is a second number for a differential | 200 | * @channel2: If there is a second number for a differential |
137 | * channel then this is it. If modified is set then the | 201 | * channel then this is it. If modified is set then the |
138 | * value here specifies the modifier. | 202 | * value here specifies the modifier. |
139 | * @address: Driver specific identifier. | 203 | * @address: Driver specific identifier. |
140 | * @scan_index: Monotonic index to give ordering in scans when read | 204 | * @scan_index: Monotonic index to give ordering in scans when read |
141 | * from a buffer. | 205 | * from a buffer. |
142 | * @scan_type: Sign: 's' or 'u' to specify signed or unsigned | 206 | * @scan_type: Sign: 's' or 'u' to specify signed or unsigned |
143 | * realbits: Number of valid bits of data | 207 | * realbits: Number of valid bits of data |
@@ -147,14 +211,14 @@ struct iio_chan_spec_ext_info { | |||
147 | * endianness: little or big endian | 211 | * endianness: little or big endian |
148 | * @info_mask: What information is to be exported about this channel. | 212 | * @info_mask: What information is to be exported about this channel. |
149 | * This includes calibbias, scale etc. | 213 | * This includes calibbias, scale etc. |
150 | * @event_mask: What events can this channel produce. | 214 | * @event_mask: What events can this channel produce. |
151 | * @ext_info: Array of extended info attributes for this channel. | 215 | * @ext_info: Array of extended info attributes for this channel. |
152 | * The array is NULL terminated, the last element should | 216 | * The array is NULL terminated, the last element should |
153 | * have it's name field set to NULL. | 217 | * have its name field set to NULL. |
154 | * @extend_name: Allows labeling of channel attributes with an | 218 | * @extend_name: Allows labeling of channel attributes with an |
155 | * informative name. Note this has no effect codes etc, | 219 | * informative name. Note this has no effect codes etc, |
156 | * unlike modifiers. | 220 | * unlike modifiers. |
157 | * @datasheet_name: A name used in in kernel mapping of channels. It should | 221 | * @datasheet_name: A name used in in-kernel mapping of channels. It should |
158 | * correspond to the first name that the channel is referred | 222 | * correspond to the first name that the channel is referred |
159 | * to by in the datasheet (e.g. IND), or the nearest | 223 | * to by in the datasheet (e.g. IND), or the nearest |
160 | * possible compound name (e.g. IND-INC). | 224 | * possible compound name (e.g. IND-INC). |
@@ -163,9 +227,8 @@ struct iio_chan_spec_ext_info { | |||
163 | * channel2. Examples are IIO_MOD_X for axial sensors about | 227 | * channel2. Examples are IIO_MOD_X for axial sensors about |
164 | * the 'x' axis. | 228 | * the 'x' axis. |
165 | * @indexed: Specify the channel has a numerical index. If not, | 229 | * @indexed: Specify the channel has a numerical index. If not, |
166 | * the value in channel will be suppressed for attribute | 230 | * the channel index number will be suppressed for sysfs |
167 | * but not for event codes. Typically set it to 0 when | 231 | * attributes but not for event codes. |
168 | * the index is false. | ||
169 | * @differential: Channel is differential. | 232 | * @differential: Channel is differential. |
170 | */ | 233 | */ |
171 | struct iio_chan_spec { | 234 | struct iio_chan_spec { |
@@ -300,12 +363,16 @@ struct iio_info { | |||
300 | * @predisable: [DRIVER] function to run prior to marking buffer | 363 | * @predisable: [DRIVER] function to run prior to marking buffer |
301 | * disabled | 364 | * disabled |
302 | * @postdisable: [DRIVER] function to run after marking buffer disabled | 365 | * @postdisable: [DRIVER] function to run after marking buffer disabled |
366 | * @validate_scan_mask: [DRIVER] function callback to check whether a given | ||
367 | * scan mask is valid for the device. | ||
303 | */ | 368 | */ |
304 | struct iio_buffer_setup_ops { | 369 | struct iio_buffer_setup_ops { |
305 | int (*preenable)(struct iio_dev *); | 370 | int (*preenable)(struct iio_dev *); |
306 | int (*postenable)(struct iio_dev *); | 371 | int (*postenable)(struct iio_dev *); |
307 | int (*predisable)(struct iio_dev *); | 372 | int (*predisable)(struct iio_dev *); |
308 | int (*postdisable)(struct iio_dev *); | 373 | int (*postdisable)(struct iio_dev *); |
374 | bool (*validate_scan_mask)(struct iio_dev *indio_dev, | ||
375 | const unsigned long *scan_mask); | ||
309 | }; | 376 | }; |
310 | 377 | ||
311 | /** | 378 | /** |
@@ -329,7 +396,7 @@ struct iio_buffer_setup_ops { | |||
329 | * @trig: [INTERN] current device trigger (buffer modes) | 396 | * @trig: [INTERN] current device trigger (buffer modes) |
330 | * @pollfunc: [DRIVER] function run on trigger being received | 397 | * @pollfunc: [DRIVER] function run on trigger being received |
331 | * @channels: [DRIVER] channel specification structure table | 398 | * @channels: [DRIVER] channel specification structure table |
332 | * @num_channels: [DRIVER] number of chanels specified in @channels. | 399 | * @num_channels: [DRIVER] number of channels specified in @channels. |
333 | * @channel_attr_list: [INTERN] keep track of automatically created channel | 400 | * @channel_attr_list: [INTERN] keep track of automatically created channel |
334 | * attributes | 401 | * attributes |
335 | * @chan_attr_group: [INTERN] group for all attrs in base directory | 402 | * @chan_attr_group: [INTERN] group for all attrs in base directory |
@@ -419,7 +486,7 @@ extern struct bus_type iio_bus_type; | |||
419 | 486 | ||
420 | /** | 487 | /** |
421 | * iio_device_put() - reference counted deallocation of struct device | 488 | * iio_device_put() - reference counted deallocation of struct device |
422 | * @dev: the iio_device containing the device | 489 | * @indio_dev: IIO device structure containing the device |
423 | **/ | 490 | **/ |
424 | static inline void iio_device_put(struct iio_dev *indio_dev) | 491 | static inline void iio_device_put(struct iio_dev *indio_dev) |
425 | { | 492 | { |
@@ -429,7 +496,7 @@ static inline void iio_device_put(struct iio_dev *indio_dev) | |||
429 | 496 | ||
430 | /** | 497 | /** |
431 | * dev_to_iio_dev() - Get IIO device struct from a device struct | 498 | * dev_to_iio_dev() - Get IIO device struct from a device struct |
432 | * @dev: The device embedded in the IIO device | 499 | * @dev: The device embedded in the IIO device |
433 | * | 500 | * |
434 | * Note: The device must be a IIO device, otherwise the result is undefined. | 501 | * Note: The device must be a IIO device, otherwise the result is undefined. |
435 | */ | 502 | */ |
@@ -438,11 +505,22 @@ static inline struct iio_dev *dev_to_iio_dev(struct device *dev) | |||
438 | return container_of(dev, struct iio_dev, dev); | 505 | return container_of(dev, struct iio_dev, dev); |
439 | } | 506 | } |
440 | 507 | ||
508 | /** | ||
509 | * iio_device_get() - increment reference count for the device | ||
510 | * @indio_dev: IIO device structure | ||
511 | * | ||
512 | * Returns: The passed IIO device | ||
513 | **/ | ||
514 | static inline struct iio_dev *iio_device_get(struct iio_dev *indio_dev) | ||
515 | { | ||
516 | return indio_dev ? dev_to_iio_dev(get_device(&indio_dev->dev)) : NULL; | ||
517 | } | ||
518 | |||
441 | /* Can we make this smaller? */ | 519 | /* Can we make this smaller? */ |
442 | #define IIO_ALIGN L1_CACHE_BYTES | 520 | #define IIO_ALIGN L1_CACHE_BYTES |
443 | /** | 521 | /** |
444 | * iio_device_alloc() - allocate an iio_dev from a driver | 522 | * iio_device_alloc() - allocate an iio_dev from a driver |
445 | * @sizeof_priv: Space to allocate for private structure. | 523 | * @sizeof_priv: Space to allocate for private structure. |
446 | **/ | 524 | **/ |
447 | struct iio_dev *iio_device_alloc(int sizeof_priv); | 525 | struct iio_dev *iio_device_alloc(int sizeof_priv); |
448 | 526 | ||
@@ -459,13 +537,13 @@ static inline struct iio_dev *iio_priv_to_dev(void *priv) | |||
459 | 537 | ||
460 | /** | 538 | /** |
461 | * iio_device_free() - free an iio_dev from a driver | 539 | * iio_device_free() - free an iio_dev from a driver |
462 | * @dev: the iio_dev associated with the device | 540 | * @indio_dev: the iio_dev associated with the device |
463 | **/ | 541 | **/ |
464 | void iio_device_free(struct iio_dev *indio_dev); | 542 | void iio_device_free(struct iio_dev *indio_dev); |
465 | 543 | ||
466 | /** | 544 | /** |
467 | * iio_buffer_enabled() - helper function to test if the buffer is enabled | 545 | * iio_buffer_enabled() - helper function to test if the buffer is enabled |
468 | * @indio_dev: IIO device info structure for device | 546 | * @indio_dev: IIO device structure for device |
469 | **/ | 547 | **/ |
470 | static inline bool iio_buffer_enabled(struct iio_dev *indio_dev) | 548 | static inline bool iio_buffer_enabled(struct iio_dev *indio_dev) |
471 | { | 549 | { |
@@ -475,7 +553,7 @@ static inline bool iio_buffer_enabled(struct iio_dev *indio_dev) | |||
475 | 553 | ||
476 | /** | 554 | /** |
477 | * iio_get_debugfs_dentry() - helper function to get the debugfs_dentry | 555 | * iio_get_debugfs_dentry() - helper function to get the debugfs_dentry |
478 | * @indio_dev: IIO device info structure for device | 556 | * @indio_dev: IIO device structure for device |
479 | **/ | 557 | **/ |
480 | #if defined(CONFIG_DEBUG_FS) | 558 | #if defined(CONFIG_DEBUG_FS) |
481 | static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev) | 559 | static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev) |