Linux Kernel
3.7.1
Main Page
Related Pages
Modules
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
drivers
staging
iio
iio_simple_dummy_events.c
Go to the documentation of this file.
1
10
#include <linux/kernel.h>
11
#include <linux/slab.h>
12
#include <
linux/interrupt.h
>
13
#include <
linux/irq.h
>
14
15
#include <
linux/iio/iio.h
>
16
#include <
linux/iio/sysfs.h
>
17
#include <
linux/iio/events.h
>
18
#include "
iio_simple_dummy.h
"
19
20
/* Evgen 'fakes' interrupt events for this example */
21
#include "
iio_dummy_evgen.h
"
22
31
int
iio_simple_dummy_read_event_config
(
struct
iio_dev
*indio_dev,
32
u64
event_code
)
33
{
34
struct
iio_dummy_state
*
st
= iio_priv(indio_dev);
35
36
return
st->event_en;
37
}
38
49
int
iio_simple_dummy_write_event_config
(
struct
iio_dev
*indio_dev,
50
u64
event_code
,
51
int
state
)
52
{
53
struct
iio_dummy_state
*
st
= iio_priv(indio_dev);
54
55
/*
56
* Deliberately over the top code splitting to illustrate
57
* how this is done when multiple events exist.
58
*/
59
switch
(
IIO_EVENT_CODE_EXTRACT_CHAN_TYPE
(event_code)) {
60
case
IIO_VOLTAGE
:
61
switch
(
IIO_EVENT_CODE_EXTRACT_TYPE
(event_code)) {
62
case
IIO_EV_TYPE_THRESH
:
63
if
(
IIO_EVENT_CODE_EXTRACT_DIR
(event_code) ==
64
IIO_EV_DIR_RISING
)
65
st->event_en =
state
;
66
else
67
return
-
EINVAL
;
68
break
;
69
default
:
70
return
-
EINVAL
;
71
}
72
default
:
73
return
-
EINVAL
;
74
}
75
76
return
0;
77
}
78
91
int
iio_simple_dummy_read_event_value
(
struct
iio_dev
*indio_dev,
92
u64
event_code
,
93
int
*
val
)
94
{
95
struct
iio_dummy_state
*
st
= iio_priv(indio_dev);
96
97
*val = st->event_val;
98
99
return
0;
100
}
101
108
int
iio_simple_dummy_write_event_value
(
struct
iio_dev
*indio_dev,
109
u64
event_code
,
110
int
val
)
111
{
112
struct
iio_dummy_state
*
st
= iio_priv(indio_dev);
113
114
st->event_val =
val
;
115
116
return
0;
117
}
118
129
static
irqreturn_t
iio_simple_dummy_event_handler(
int
irq,
void
*
private
)
130
{
131
struct
iio_dev
*indio_dev =
private
;
132
iio_push_event
(indio_dev,
133
IIO_EVENT_CODE
(
IIO_VOLTAGE
, 0, 0,
134
IIO_EV_DIR_RISING
,
135
IIO_EV_TYPE_THRESH
, 0, 0, 0),
136
iio_get_time_ns());
137
return
IRQ_HANDLED
;
138
}
139
151
int
iio_simple_dummy_events_register
(
struct
iio_dev
*indio_dev)
152
{
153
struct
iio_dummy_state
*
st
= iio_priv(indio_dev);
154
int
ret
;
155
156
/* Fire up event source - normally not present */
157
st->event_irq =
iio_dummy_evgen_get_irq
();
158
if
(st->event_irq < 0) {
159
ret = st->event_irq;
160
goto
error_ret;
161
}
162
ret =
request_threaded_irq
(st->event_irq,
163
NULL
,
164
&iio_simple_dummy_event_handler,
165
IRQF_ONESHOT
,
166
"iio_simple_event"
,
167
indio_dev);
168
if
(ret < 0)
169
goto
error_free_evgen;
170
return
0;
171
172
error_free_evgen:
173
iio_dummy_evgen_release_irq
(st->event_irq);
174
error_ret:
175
return
ret
;
176
}
177
182
int
iio_simple_dummy_events_unregister
(
struct
iio_dev
*indio_dev)
183
{
184
struct
iio_dummy_state
*
st
= iio_priv(indio_dev);
185
186
free_irq
(st->event_irq, indio_dev);
187
/* Not part of normal driver */
188
iio_dummy_evgen_release_irq
(st->event_irq);
189
190
return
0;
191
}
Generated on Thu Jan 10 2013 14:28:46 for Linux Kernel by
1.8.2