staging:iio: ABI documentation (partial)
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / staging / iio / chrdev.h
CommitLineData
847ec80b
JC
1/* The industrial I/O core - character device related
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
10#ifndef _IIO_CHRDEV_H_
11#define _IIO_CHRDEV_H_
12struct iio_dev;
13
14/**
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
21 * the chrdev.
22 */
23struct iio_handler {
24 struct cdev chrdev;
25 int id;
26 unsigned long flags;
27 void *private;
28};
29
30#define iio_cdev_to_handler(cd) \
31 container_of(cd, struct iio_handler, chrdev)
32
33/**
34 * struct iio_event_data - The actual event being pushed to userspace
35 * @id: event identifier
36 * @timestamp: best estimate of time of event occurance (often from
37 * the interrupt handler)
38 */
39struct iio_event_data {
40 int id;
41 s64 timestamp;
42};
43
44/**
45 * struct iio_detected_event_list - list element for events that have occured
46 * @list: linked list header
47 * @ev: the event itself
48 * @shared_pointer: used when the event is shared - i.e. can be escallated
49 * on demand (eg ring buffer 50%->100% full)
50 */
51struct iio_detected_event_list {
52 struct list_head list;
53 struct iio_event_data ev;
54 struct iio_shared_ev_pointer *shared_pointer;
55};
56/**
57 * struct iio_shared_ev_pointer - allows shared events to identify if currently
58 * in the detected event list
59 * @ev_p: pointer to detected event list element (null if not in list)
60 * @lock: protect this element to prevent simultaneous edit and remove
61 */
62struct iio_shared_ev_pointer {
63 struct iio_detected_event_list *ev_p;
64 spinlock_t lock;
65};
66
67/**
68 * struct iio_event_interface - chrdev interface for an event line
69 * @dev: device assocated with event interface
70 * @handler: fileoperations and related control for the chrdev
71 * @wait: wait queue to allow blocking reads of events
72 * @event_list_lock: mutex to protect the list of detected events
73 * @det_events: list of detected events
74 * @max_events: maximum number of events before new ones are dropped
75 * @current_events: number of events in detected list
76 * @id: indentifier to allow the event interface to know which
77 * physical line it corresponds to
4c572605 78 * @attr: this chrdev's minor number sysfs attribute
847ec80b
JC
79 * @owner: ensure the driver module owns the file, not iio
80 * @private: driver specific data
81 * @_name: used internally to store the sysfs name for minor id
82 * attribute
4c572605 83 * @_attrname: the event interface's attribute name
847ec80b
JC
84 */
85struct iio_event_interface {
86 struct device dev;
87 struct iio_handler handler;
88 wait_queue_head_t wait;
89 struct mutex event_list_lock;
90 struct iio_detected_event_list det_events;
91 int max_events;
92 int current_events;
93 int id;
94 struct iio_chrdev_minor_attr attr;
95 struct module *owner;
96 void *private;
97 char _name[20];
98 char _attrname[20];
99};
100
101/**
102 * struct iio_event_handler_list - element in list of handlers for events
103 * @list: list header
104 * @refcount: as the handler may be shared between multiple device
105 * side events, reference counting ensures clean removal
106 * @exist_lock: prevents race conditions related to refcount useage.
107 * @handler: event handler function - called on event if this
108 * event_handler is enabled.
109 *
4c572605 110 * Each device has one list of these per interrupt line.
847ec80b
JC
111 **/
112struct iio_event_handler_list {
113 struct list_head list;
114 int refcount;
115 struct mutex exist_lock;
116 int (*handler)(struct iio_dev *dev_info, int index, s64 timestamp,
117 int no_test);
118};
119
120#endif