aboutsummaryrefslogtreecommitdiffstats
path: root/include/media
diff options
context:
space:
mode:
authorJarod Wilson <jarod@redhat.com>2010-07-16 13:25:33 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-08-02 15:42:55 -0400
commit5690085e7ba7f3081c6ab6db3a3b543444ad8a21 (patch)
tree09d33f31298e00fa10ca8a05316e5c651ae75e4c /include/media
parent1e687528777acab2c73cd12fb35d71088ad73a3c (diff)
V4L/DVB: IR/lirc: make lirc userspace and staging modules buildable
The lirc userspace needs all the current ioctls defined, and we need to put the header files in places out-of-tree and/or staging lirc drivers (which I plan to prep soon) can easily build with. I've actually tested this in a tree w/all the lirc drivers queued up to be submitted for staging. I'm also reasonably sure that Andy Walls is going to need most of the ioctls anyway for his cx23888 IR driver work. Signed-off-by: Jarod Wilson <jarod@redhat.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'include/media')
-rw-r--r--include/media/lirc.h34
-rw-r--r--include/media/lirc_dev.h225
2 files changed, 243 insertions, 16 deletions
diff --git a/include/media/lirc.h b/include/media/lirc.h
index 8dffd4f47bf6..42c467c50519 100644
--- a/include/media/lirc.h
+++ b/include/media/lirc.h
@@ -1,6 +1,6 @@
1/* 1/*
2 * lirc.h - linux infrared remote control header file 2 * lirc.h - linux infrared remote control header file
3 * last modified 2010/06/03 by Jarod Wilson 3 * last modified 2010/07/13 by Jarod Wilson
4 */ 4 */
5 5
6#ifndef _LINUX_LIRC_H 6#ifndef _LINUX_LIRC_H
@@ -33,6 +33,9 @@
33#define LIRC_IS_FREQUENCY(val) (LIRC_MODE2(val) == LIRC_MODE2_FREQUENCY) 33#define LIRC_IS_FREQUENCY(val) (LIRC_MODE2(val) == LIRC_MODE2_FREQUENCY)
34#define LIRC_IS_TIMEOUT(val) (LIRC_MODE2(val) == LIRC_MODE2_TIMEOUT) 34#define LIRC_IS_TIMEOUT(val) (LIRC_MODE2(val) == LIRC_MODE2_TIMEOUT)
35 35
36/* used heavily by lirc userspace */
37#define lirc_t int
38
36/*** lirc compatible hardware features ***/ 39/*** lirc compatible hardware features ***/
37 40
38#define LIRC_MODE2SEND(x) (x) 41#define LIRC_MODE2SEND(x) (x)
@@ -95,12 +98,10 @@
95#define LIRC_GET_MIN_TIMEOUT _IOR('i', 0x00000008, __u32) 98#define LIRC_GET_MIN_TIMEOUT _IOR('i', 0x00000008, __u32)
96#define LIRC_GET_MAX_TIMEOUT _IOR('i', 0x00000009, __u32) 99#define LIRC_GET_MAX_TIMEOUT _IOR('i', 0x00000009, __u32)
97 100
98#if 0 /* these ioctls are not used at the moment */
99#define LIRC_GET_MIN_FILTER_PULSE _IOR('i', 0x0000000a, __u32) 101#define LIRC_GET_MIN_FILTER_PULSE _IOR('i', 0x0000000a, __u32)
100#define LIRC_GET_MAX_FILTER_PULSE _IOR('i', 0x0000000b, __u32) 102#define LIRC_GET_MAX_FILTER_PULSE _IOR('i', 0x0000000b, __u32)
101#define LIRC_GET_MIN_FILTER_SPACE _IOR('i', 0x0000000c, __u32) 103#define LIRC_GET_MIN_FILTER_SPACE _IOR('i', 0x0000000c, __u32)
102#define LIRC_GET_MAX_FILTER_SPACE _IOR('i', 0x0000000d, __u32) 104#define LIRC_GET_MAX_FILTER_SPACE _IOR('i', 0x0000000d, __u32)
103#endif
104 105
105/* code length in bits, currently only for LIRC_MODE_LIRCCODE */ 106/* code length in bits, currently only for LIRC_MODE_LIRCCODE */
106#define LIRC_GET_LENGTH _IOR('i', 0x0000000f, __u32) 107#define LIRC_GET_LENGTH _IOR('i', 0x0000000f, __u32)
@@ -121,23 +122,30 @@
121 */ 122 */
122#define LIRC_SET_REC_TIMEOUT _IOW('i', 0x00000018, __u32) 123#define LIRC_SET_REC_TIMEOUT _IOW('i', 0x00000018, __u32)
123 124
124#if 0 /* these ioctls are not used at the moment */ 125/* 1 enables, 0 disables timeout reports in MODE2 */
126#define LIRC_SET_REC_TIMEOUT_REPORTS _IOW('i', 0x00000019, __u32)
127
125/* 128/*
126 * pulses shorter than this are filtered out by hardware (software 129 * pulses shorter than this are filtered out by hardware (software
127 * emulation in lirc_dev?) 130 * emulation in lirc_dev?)
128 */ 131 */
129#define LIRC_SET_REC_FILTER_PULSE _IOW('i', 0x00000019, __u32) 132#define LIRC_SET_REC_FILTER_PULSE _IOW('i', 0x0000001a, __u32)
130/* 133/*
131 * spaces shorter than this are filtered out by hardware (software 134 * spaces shorter than this are filtered out by hardware (software
132 * emulation in lirc_dev?) 135 * emulation in lirc_dev?)
133 */ 136 */
134#define LIRC_SET_REC_FILTER_SPACE _IOW('i', 0x0000001a, __u32) 137#define LIRC_SET_REC_FILTER_SPACE _IOW('i', 0x0000001b, __u32)
135/* 138/*
136 * if filter cannot be set independantly for pulse/space, this should 139 * if filter cannot be set independantly for pulse/space, this should
137 * be used 140 * be used
138 */ 141 */
139#define LIRC_SET_REC_FILTER _IOW('i', 0x0000001b, __u32) 142#define LIRC_SET_REC_FILTER _IOW('i', 0x0000001c, __u32)
140#endif 143
144/*
145 * if enabled from the next key press on the driver will send
146 * LIRC_MODE2_FREQUENCY packets
147 */
148#define LIRC_SET_MEASURE_CARRIER_MODE _IOW('i', 0x0000001d, __u32)
141 149
142/* 150/*
143 * to set a range use 151 * to set a range use
@@ -151,13 +159,7 @@
151 159
152#define LIRC_NOTIFY_DECODE _IO('i', 0x00000020) 160#define LIRC_NOTIFY_DECODE _IO('i', 0x00000020)
153 161
154#if 0 /* these ioctls are not used at the moment */ 162#define LIRC_SETUP_START _IO('i', 0x00000021)
155/* 163#define LIRC_SETUP_END _IO('i', 0x00000022)
156 * from the next key press on the driver will send
157 * LIRC_MODE2_FREQUENCY packets
158 */
159#define LIRC_MEASURE_CARRIER_ENABLE _IO('i', 0x00000021)
160#define LIRC_MEASURE_CARRIER_DISABLE _IO('i', 0x00000022)
161#endif
162 164
163#endif 165#endif
diff --git a/include/media/lirc_dev.h b/include/media/lirc_dev.h
new file mode 100644
index 000000000000..b1f60663cb39
--- /dev/null
+++ b/include/media/lirc_dev.h
@@ -0,0 +1,225 @@
1/*
2 * LIRC base driver
3 *
4 * by Artur Lipowski <alipowski@interia.pl>
5 * This code is licensed under GNU GPL
6 *
7 */
8
9#ifndef _LINUX_LIRC_DEV_H
10#define _LINUX_LIRC_DEV_H
11
12#define MAX_IRCTL_DEVICES 4
13#define BUFLEN 16
14
15#define mod(n, div) ((n) % (div))
16
17#include <linux/slab.h>
18#include <linux/fs.h>
19#include <linux/ioctl.h>
20#include <linux/poll.h>
21#include <linux/kfifo.h>
22#include <media/lirc.h>
23
24struct lirc_buffer {
25 wait_queue_head_t wait_poll;
26 spinlock_t fifo_lock;
27 unsigned int chunk_size;
28 unsigned int size; /* in chunks */
29 /* Using chunks instead of bytes pretends to simplify boundary checking
30 * And should allow for some performance fine tunning later */
31 struct kfifo fifo;
32 u8 fifo_initialized;
33};
34
35static inline void lirc_buffer_clear(struct lirc_buffer *buf)
36{
37 unsigned long flags;
38
39 if (buf->fifo_initialized) {
40 spin_lock_irqsave(&buf->fifo_lock, flags);
41 kfifo_reset(&buf->fifo);
42 spin_unlock_irqrestore(&buf->fifo_lock, flags);
43 } else
44 WARN(1, "calling %s on an uninitialized lirc_buffer\n",
45 __func__);
46}
47
48static inline int lirc_buffer_init(struct lirc_buffer *buf,
49 unsigned int chunk_size,
50 unsigned int size)
51{
52 int ret;
53
54 init_waitqueue_head(&buf->wait_poll);
55 spin_lock_init(&buf->fifo_lock);
56 buf->chunk_size = chunk_size;
57 buf->size = size;
58 ret = kfifo_alloc(&buf->fifo, size * chunk_size, GFP_KERNEL);
59 if (ret == 0)
60 buf->fifo_initialized = 1;
61
62 return ret;
63}
64
65static inline void lirc_buffer_free(struct lirc_buffer *buf)
66{
67 if (buf->fifo_initialized) {
68 kfifo_free(&buf->fifo);
69 buf->fifo_initialized = 0;
70 } else
71 WARN(1, "calling %s on an uninitialized lirc_buffer\n",
72 __func__);
73}
74
75static inline int lirc_buffer_len(struct lirc_buffer *buf)
76{
77 int len;
78 unsigned long flags;
79
80 spin_lock_irqsave(&buf->fifo_lock, flags);
81 len = kfifo_len(&buf->fifo);
82 spin_unlock_irqrestore(&buf->fifo_lock, flags);
83
84 return len;
85}
86
87static inline int lirc_buffer_full(struct lirc_buffer *buf)
88{
89 return lirc_buffer_len(buf) == buf->size * buf->chunk_size;
90}
91
92static inline int lirc_buffer_empty(struct lirc_buffer *buf)
93{
94 return !lirc_buffer_len(buf);
95}
96
97static inline int lirc_buffer_available(struct lirc_buffer *buf)
98{
99 return buf->size - (lirc_buffer_len(buf) / buf->chunk_size);
100}
101
102static inline unsigned int lirc_buffer_read(struct lirc_buffer *buf,
103 unsigned char *dest)
104{
105 unsigned int ret = 0;
106
107 if (lirc_buffer_len(buf) >= buf->chunk_size)
108 ret = kfifo_out_locked(&buf->fifo, dest, buf->chunk_size,
109 &buf->fifo_lock);
110 return ret;
111
112}
113
114static inline unsigned int lirc_buffer_write(struct lirc_buffer *buf,
115 unsigned char *orig)
116{
117 unsigned int ret;
118
119 ret = kfifo_in_locked(&buf->fifo, orig, buf->chunk_size,
120 &buf->fifo_lock);
121
122 return ret;
123}
124
125struct lirc_driver {
126 char name[40];
127 int minor;
128 unsigned long code_length;
129 unsigned int buffer_size; /* in chunks holding one code each */
130 int sample_rate;
131 unsigned long features;
132
133 unsigned int chunk_size;
134
135 void *data;
136 int min_timeout;
137 int max_timeout;
138 int (*add_to_buf) (void *data, struct lirc_buffer *buf);
139 struct lirc_buffer *rbuf;
140 int (*set_use_inc) (void *data);
141 void (*set_use_dec) (void *data);
142 struct file_operations *fops;
143 struct device *dev;
144 struct module *owner;
145};
146
147/* name:
148 * this string will be used for logs
149 *
150 * minor:
151 * indicates minor device (/dev/lirc) number for registered driver
152 * if caller fills it with negative value, then the first free minor
153 * number will be used (if available)
154 *
155 * code_length:
156 * length of the remote control key code expressed in bits
157 *
158 * sample_rate:
159 *
160 * data:
161 * it may point to any driver data and this pointer will be passed to
162 * all callback functions
163 *
164 * add_to_buf:
165 * add_to_buf will be called after specified period of the time or
166 * triggered by the external event, this behavior depends on value of
167 * the sample_rate this function will be called in user context. This
168 * routine should return 0 if data was added to the buffer and
169 * -ENODATA if none was available. This should add some number of bits
170 * evenly divisible by code_length to the buffer
171 *
172 * rbuf:
173 * if not NULL, it will be used as a read buffer, you will have to
174 * write to the buffer by other means, like irq's (see also
175 * lirc_serial.c).
176 *
177 * set_use_inc:
178 * set_use_inc will be called after device is opened
179 *
180 * set_use_dec:
181 * set_use_dec will be called after device is closed
182 *
183 * fops:
184 * file_operations for drivers which don't fit the current driver model.
185 *
186 * Some ioctl's can be directly handled by lirc_dev if the driver's
187 * ioctl function is NULL or if it returns -ENOIOCTLCMD (see also
188 * lirc_serial.c).
189 *
190 * owner:
191 * the module owning this struct
192 *
193 */
194
195
196/* following functions can be called ONLY from user context
197 *
198 * returns negative value on error or minor number
199 * of the registered device if success
200 * contents of the structure pointed by p is copied
201 */
202extern int lirc_register_driver(struct lirc_driver *d);
203
204/* returns negative value on error or 0 if success
205*/
206extern int lirc_unregister_driver(int minor);
207
208/* Returns the private data stored in the lirc_driver
209 * associated with the given device file pointer.
210 */
211void *lirc_get_pdata(struct file *file);
212
213/* default file operations
214 * used by drivers if they override only some operations
215 */
216int lirc_dev_fop_open(struct inode *inode, struct file *file);
217int lirc_dev_fop_close(struct inode *inode, struct file *file);
218unsigned int lirc_dev_fop_poll(struct file *file, poll_table *wait);
219long lirc_dev_fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
220ssize_t lirc_dev_fop_read(struct file *file, char *buffer, size_t length,
221 loff_t *ppos);
222ssize_t lirc_dev_fop_write(struct file *file, const char *buffer, size_t length,
223 loff_t *ppos);
224
225#endif