1 /* The industrial I/O core - character device related
3 * Copyright (c) 2008 Jonathan Cameron
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.
10 #ifndef _IIO_CHRDEV_H_
11 #define _IIO_CHRDEV_H_
15 * struct iio_handler - Structure used to specify file operations
16 * for a particular chrdev
17 * @chrdev: character device structure
18 * @id: the location in the handler table - used for deallocation.
19 * @flags: file operations related flags including busy flag.
20 * @private: handler specific data used by the fileops registered with
30 #define iio_cdev_to_handler(cd) \
31 container_of(cd, struct iio_handler, chrdev)
34 * struct iio_event_data - The actual event being pushed to userspace
35 * @id: event identifier
36 * @timestamp: best estimate of time of event occurrence (often from
37 * the interrupt handler)
39 struct iio_event_data {
45 * struct iio_detected_event_list - list element for events that have occurred
46 * @list: linked list header
47 * @ev: the event itself
49 struct iio_detected_event_list {
50 struct list_head list;
51 struct iio_event_data ev;
55 * struct iio_event_interface - chrdev interface for an event line
56 * @dev: device assocated with event interface
57 * @handler: fileoperations and related control for the chrdev
58 * @wait: wait queue to allow blocking reads of events
59 * @event_list_lock: mutex to protect the list of detected events
60 * @det_events: list of detected events
61 * @max_events: maximum number of events before new ones are dropped
62 * @current_events: number of events in detected list
63 * @owner: ensure the driver module owns the file, not iio
64 * @private: driver specific data
65 * @_name: used internally to store the sysfs name for minor id
67 * @_attrname: the event interface's attribute name
69 struct iio_event_interface {
71 struct iio_handler handler;
72 wait_queue_head_t wait;
73 struct mutex event_list_lock;
74 struct iio_detected_event_list det_events;
82 struct list_head event_attr_list;
83 struct list_head dev_attr_list;
87 * struct iio_event_handler_list - element in list of handlers for events
89 * @refcount: as the handler may be shared between multiple device
90 * side events, reference counting ensures clean removal
91 * @exist_lock: prevents race conditions related to refcount usage.
92 * @handler: event handler function - called on event if this
93 * event_handler is enabled.
95 * Each device has one list of these per interrupt line.
97 struct iio_event_handler_list {
98 struct list_head list;
100 struct mutex exist_lock;
101 int (*handler)(struct iio_dev *dev_info, int index, s64 timestamp,