~ubuntu-branches/ubuntu/precise/lirc/precise

« back to all changes in this revision

Viewing changes to drivers/lirc_dev/lirc_dev.h

  • Committer: Bazaar Package Importer
  • Author(s): Mario Limonciello
  • Date: 2009-06-18 01:48:20 UTC
  • mfrom: (1.2.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090618014820-xd3wmu47cd23ejtc
Tags: 0.8.5-0ubuntu1
* New upstream version. (LP: #383446)
  - Fixes imon support (LP: #283317)
* Refresh the following patches for new version:
  - debian/patches/04_man_pages
  - debian/patches/13-warning-cleanup
  - debian/patches/21_atiusb
  - debian/patches/23_pad2keys
  - debian/patches/28_irrecord_resume_support
  - debian/patches/35_general_deviniput
* debian/control:
  - Add build-depends on libftdi-dev to prevent FTBFS.
* debian/copyright:
  - Update to what debian is shipping.
* debian/modules-source/{lirc-modules-source.conf, Makefile}
  - Don't build cmdir anymore.  It's now a userspace module
* debian/rules:
  - Generate dkms.conf using sed instead.
* debian/patches/12_pvr150_transmit_support:
  - Drop.  Upstream didn't like this patch due to questionable
   copyright, and we aren't properly supporting it anyway.
  - Refresh 20_serial_igor
  - Refresh 26_transmitter_lircd
* debian/lirc-modules-source.README.Debian:
  - Drop, inaccurate now.
* debian/lirc.init.d:
  - Cleanup a useless for loop.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * (L) by Artur Lipowski <alipowski@interia.pl>
5
5
 *        This code is licensed under GNU GPL
6
6
 *
7
 
 * $Id: lirc_dev.h,v 1.22 2008/01/13 10:45:02 lirc Exp $
 
7
 * $Id: lirc_dev.h,v 1.37 2009/03/15 09:34:00 lirc Exp $
8
8
 *
9
9
 */
10
10
 
11
11
#ifndef _LINUX_LIRC_DEV_H
12
12
#define _LINUX_LIRC_DEV_H
13
13
 
 
14
#ifndef LIRC_REMOVE_DURING_EXPORT
 
15
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
 
16
/* when was it really introduced? */
 
17
#define LIRC_HAVE_KFIFO
 
18
#endif
 
19
#endif
14
20
#define MAX_IRCTL_DEVICES 4
15
21
#define BUFLEN            16
16
22
 
17
 
/* #define LIRC_BUFF_POWER_OF_2 */
18
 
#ifdef LIRC_BUFF_POWER_OF_2
19
 
#define mod(n, div) ((n) & ((div) - 1))
20
 
#else
21
23
#define mod(n, div) ((n) % (div))
22
 
#endif
 
24
 
23
25
#include <linux/slab.h>
24
26
#include <linux/fs.h>
 
27
#ifdef LIRC_HAVE_KFIFO
 
28
#include <linux/kfifo.h>
 
29
#endif
25
30
 
26
31
struct lirc_buffer {
27
32
        wait_queue_head_t wait_poll;
28
33
        spinlock_t lock;
29
 
 
30
 
        unsigned char *data;
31
34
        unsigned int chunk_size;
32
35
        unsigned int size; /* in chunks */
 
36
        /* Using chunks instead of bytes pretends to simplify boundary checking
 
37
         * And should allow for some performance fine tunning later */
 
38
#ifdef LIRC_HAVE_KFIFO
 
39
        struct kfifo *fifo;
 
40
#else
33
41
        unsigned int fill; /* in chunks */
34
42
        int head, tail;    /* in chunks */
35
 
        /* Using chunks instead of bytes pretends to simplify boundary checking
36
 
         * And should allow for some performance fine tunning later */
 
43
        unsigned char *data;
 
44
#endif
37
45
};
 
46
#ifndef LIRC_HAVE_KFIFO
 
47
static inline void lirc_buffer_lock(struct lirc_buffer *buf,
 
48
                                    unsigned long *flags)
 
49
{
 
50
        spin_lock_irqsave(&buf->lock, *flags);
 
51
}
 
52
static inline void lirc_buffer_unlock(struct lirc_buffer *buf,
 
53
                                      unsigned long *flags)
 
54
{
 
55
        spin_unlock_irqrestore(&buf->lock, *flags);
 
56
}
38
57
static inline void _lirc_buffer_clear(struct lirc_buffer *buf)
39
58
{
40
59
        buf->head = 0;
41
60
        buf->tail = 0;
42
61
        buf->fill = 0;
43
62
}
 
63
#endif
 
64
static inline void lirc_buffer_clear(struct lirc_buffer *buf)
 
65
{
 
66
#ifdef LIRC_HAVE_KFIFO
 
67
        if (buf->fifo)
 
68
                kfifo_reset(buf->fifo);
 
69
#else
 
70
        unsigned long flags;
 
71
        lirc_buffer_lock(buf, &flags);
 
72
        _lirc_buffer_clear(buf);
 
73
        lirc_buffer_unlock(buf, &flags);
 
74
#endif
 
75
}
44
76
static inline int lirc_buffer_init(struct lirc_buffer *buf,
45
77
                                    unsigned int chunk_size,
46
78
                                    unsigned int size)
47
79
{
48
 
        /* Adjusting size to the next power of 2 would allow for
49
 
         * inconditional LIRC_BUFF_POWER_OF_2 optimization */
50
80
        init_waitqueue_head(&buf->wait_poll);
51
81
        spin_lock_init(&buf->lock);
 
82
#ifndef LIRC_HAVE_KFIFO
52
83
        _lirc_buffer_clear(buf);
 
84
#endif
53
85
        buf->chunk_size = chunk_size;
54
86
        buf->size = size;
 
87
#ifdef LIRC_HAVE_KFIFO
 
88
        buf->fifo = kfifo_alloc(size*chunk_size, GFP_KERNEL, &buf->lock);
 
89
        if (!buf->fifo)
 
90
                return -ENOMEM;
 
91
#else
55
92
        buf->data = kmalloc(size*chunk_size, GFP_KERNEL);
56
93
        if (buf->data == NULL)
57
 
                return -1;
 
94
                return -ENOMEM;
58
95
        memset(buf->data, 0, size*chunk_size);
 
96
#endif
59
97
        return 0;
60
98
}
61
99
static inline void lirc_buffer_free(struct lirc_buffer *buf)
62
100
{
 
101
#ifdef LIRC_HAVE_KFIFO
 
102
        if (buf->fifo)
 
103
                kfifo_free(buf->fifo);
 
104
#else
63
105
        kfree(buf->data);
64
106
        buf->data = NULL;
65
107
        buf->head = 0;
67
109
        buf->fill = 0;
68
110
        buf->chunk_size = 0;
69
111
        buf->size = 0;
70
 
}
 
112
#endif
 
113
}
 
114
#ifndef LIRC_HAVE_KFIFO
 
115
static inline int  _lirc_buffer_full(struct lirc_buffer *buf)
 
116
{
 
117
        return (buf->fill >= buf->size);
 
118
}
 
119
#endif
71
120
static inline int  lirc_buffer_full(struct lirc_buffer *buf)
72
121
{
73
 
        return (buf->fill >= buf->size);
74
 
}
 
122
#ifdef LIRC_HAVE_KFIFO
 
123
        return kfifo_len(buf->fifo) == buf->size * buf->chunk_size;
 
124
#else
 
125
        unsigned long flags;
 
126
        int ret;
 
127
        lirc_buffer_lock(buf, &flags);
 
128
        ret = _lirc_buffer_full(buf);
 
129
        lirc_buffer_unlock(buf, &flags);
 
130
        return ret;
 
131
#endif
 
132
}
 
133
#ifndef LIRC_HAVE_KFIFO
 
134
static inline int  _lirc_buffer_empty(struct lirc_buffer *buf)
 
135
{
 
136
        return !(buf->fill);
 
137
}
 
138
#endif
75
139
static inline int  lirc_buffer_empty(struct lirc_buffer *buf)
76
140
{
77
 
        return !(buf->fill);
78
 
}
 
141
#ifdef LIRC_HAVE_KFIFO
 
142
        return !kfifo_len(buf->fifo);
 
143
#else
 
144
        unsigned long flags;
 
145
        int ret;
 
146
        lirc_buffer_lock(buf, &flags);
 
147
        ret = _lirc_buffer_empty(buf);
 
148
        lirc_buffer_unlock(buf, &flags);
 
149
        return ret;
 
150
#endif
 
151
}
 
152
#ifndef LIRC_HAVE_KFIFO
 
153
static inline int  _lirc_buffer_available(struct lirc_buffer *buf)
 
154
{
 
155
        return (buf->size - buf->fill);
 
156
}
 
157
#endif
79
158
static inline int  lirc_buffer_available(struct lirc_buffer *buf)
80
159
{
81
 
    return (buf->size - buf->fill);
82
 
}
83
 
static inline void lirc_buffer_lock(struct lirc_buffer *buf,
84
 
                                    unsigned long *flags)
85
 
{
86
 
        spin_lock_irqsave(&buf->lock, *flags);
87
 
}
88
 
static inline void lirc_buffer_unlock(struct lirc_buffer *buf,
89
 
                                      unsigned long *flags)
90
 
{
91
 
        spin_unlock_irqrestore(&buf->lock, *flags);
92
 
}
93
 
static inline void lirc_buffer_clear(struct lirc_buffer *buf)
94
 
{
95
 
        unsigned long flags;
96
 
        lirc_buffer_lock(buf, &flags);
97
 
        _lirc_buffer_clear(buf);
98
 
        lirc_buffer_unlock(buf, &flags);
99
 
}
100
 
static inline void _lirc_buffer_remove_1(struct lirc_buffer *buf)
101
 
{
102
 
        buf->head = mod(buf->head+1, buf->size);
103
 
        buf->fill -= 1;
104
 
}
105
 
static inline void lirc_buffer_remove_1(struct lirc_buffer *buf)
106
 
{
107
 
        unsigned long flags;
108
 
        lirc_buffer_lock(buf, &flags);
109
 
        _lirc_buffer_remove_1(buf);
110
 
        lirc_buffer_unlock(buf, &flags);
111
 
}
 
160
#ifdef LIRC_HAVE_KFIFO
 
161
        return buf->size - (kfifo_len(buf->fifo) / buf->chunk_size);
 
162
#else
 
163
        unsigned long flags;
 
164
        int ret;
 
165
        lirc_buffer_lock(buf, &flags);
 
166
        ret = _lirc_buffer_available(buf);
 
167
        lirc_buffer_unlock(buf, &flags);
 
168
        return ret;
 
169
#endif
 
170
}
 
171
#ifndef LIRC_HAVE_KFIFO
112
172
static inline void _lirc_buffer_read_1(struct lirc_buffer *buf,
113
 
                                     unsigned char *dest)
 
173
                                       unsigned char *dest)
114
174
{
115
175
        memcpy(dest, &buf->data[buf->head*buf->chunk_size], buf->chunk_size);
116
176
        buf->head = mod(buf->head+1, buf->size);
117
177
        buf->fill -= 1;
118
178
}
119
 
static inline void lirc_buffer_read_1(struct lirc_buffer *buf,
120
 
                                      unsigned char *dest)
 
179
#endif
 
180
static inline void lirc_buffer_read(struct lirc_buffer *buf,
 
181
                                    unsigned char *dest)
121
182
{
 
183
#ifdef LIRC_HAVE_KFIFO
 
184
        if (kfifo_len(buf->fifo) >= buf->chunk_size)
 
185
                kfifo_get(buf->fifo, dest, buf->chunk_size);
 
186
#else
122
187
        unsigned long flags;
123
188
        lirc_buffer_lock(buf, &flags);
124
189
        _lirc_buffer_read_1(buf, dest);
125
190
        lirc_buffer_unlock(buf, &flags);
 
191
#endif
126
192
}
 
193
#ifndef LIRC_HAVE_KFIFO
127
194
static inline void _lirc_buffer_write_1(struct lirc_buffer *buf,
128
195
                                      unsigned char *orig)
129
196
{
131
198
        buf->tail = mod(buf->tail+1, buf->size);
132
199
        buf->fill++;
133
200
}
134
 
static inline void lirc_buffer_write_1(struct lirc_buffer *buf,
135
 
                                       unsigned char *orig)
 
201
#endif
 
202
static inline void lirc_buffer_write(struct lirc_buffer *buf,
 
203
                                     unsigned char *orig)
136
204
{
 
205
#ifdef LIRC_HAVE_KFIFO
 
206
        kfifo_put(buf->fifo, orig, buf->chunk_size);
 
207
#else
137
208
        unsigned long flags;
138
209
        lirc_buffer_lock(buf, &flags);
139
210
        _lirc_buffer_write_1(buf, orig);
140
211
        lirc_buffer_unlock(buf, &flags);
 
212
#endif
141
213
}
 
214
#ifndef LIRC_HAVE_KFIFO
142
215
static inline void _lirc_buffer_write_n(struct lirc_buffer *buf,
143
216
                                        unsigned char *orig, int count)
144
217
{
145
 
        memcpy(&buf->data[buf->tail * buf->chunk_size], orig,
146
 
               count * buf->chunk_size);
147
 
        buf->tail = mod(buf->tail + count, buf->size);
148
 
        buf->fill += count;
149
 
}
150
 
static inline void lirc_buffer_write_n(struct lirc_buffer *buf,
151
 
                                       unsigned char *orig, int count)
152
 
{
153
 
        unsigned long flags;
154
218
        int space1;
155
 
 
156
 
        lirc_buffer_lock(buf, &flags);
157
219
        if (buf->head > buf->tail)
158
220
                space1 = buf->head - buf->tail;
159
221
        else
160
222
                space1 = buf->size - buf->tail;
161
223
 
162
224
        if (count > space1) {
163
 
                _lirc_buffer_write_n(buf, orig, space1);
164
 
                _lirc_buffer_write_n(buf, orig+(space1*buf->chunk_size),
165
 
                                     count-space1);
 
225
                memcpy(&buf->data[buf->tail * buf->chunk_size], orig,
 
226
                       space1 * buf->chunk_size);
 
227
                memcpy(&buf->data[0], orig + (space1 * buf->chunk_size),
 
228
                       (count - space1) * buf->chunk_size);
166
229
        } else {
167
 
                _lirc_buffer_write_n(buf, orig, count);
 
230
                memcpy(&buf->data[buf->tail * buf->chunk_size], orig,
 
231
                       count * buf->chunk_size);
168
232
        }
 
233
        buf->tail = mod(buf->tail + count, buf->size);
 
234
        buf->fill += count;
 
235
}
 
236
#endif
 
237
static inline void lirc_buffer_write_n(struct lirc_buffer *buf,
 
238
                                       unsigned char *orig, int count)
 
239
{
 
240
#ifdef LIRC_HAVE_KFIFO
 
241
        kfifo_put(buf->fifo, orig, count * buf->chunk_size);
 
242
#else
 
243
        unsigned long flags;
 
244
        lirc_buffer_lock(buf, &flags);
 
245
        _lirc_buffer_write_n(buf, orig, count);
169
246
        lirc_buffer_unlock(buf, &flags);
 
247
#endif
170
248
}
171
249
 
172
 
struct lirc_plugin {
 
250
struct lirc_driver {
173
251
        char name[40];
174
252
        int minor;
175
 
        int code_length;
 
253
        unsigned long code_length;
 
254
        unsigned int buffer_size; /* in chunks holding one code each */
176
255
        int sample_rate;
177
256
        unsigned long features;
178
257
        void *data;
179
258
        int (*add_to_buf) (void *data, struct lirc_buffer *buf);
 
259
#ifndef LIRC_REMOVE_DURING_EXPORT
180
260
        wait_queue_head_t* (*get_queue) (void *data);
 
261
#endif
181
262
        struct lirc_buffer *rbuf;
182
263
        int (*set_use_inc) (void *data);
183
264
        void (*set_use_dec) (void *data);
184
 
        int (*ioctl) (struct inode *, struct file *, unsigned int,
185
 
                      unsigned long);
186
265
        struct file_operations *fops;
187
266
        struct device *dev;
188
267
        struct module *owner;
191
270
 * this string will be used for logs
192
271
 *
193
272
 * minor:
194
 
 * indicates minor device (/dev/lirc) number for registered plugin
 
273
 * indicates minor device (/dev/lirc) number for registered driver
195
274
 * if caller fills it with negative value, then the first free minor
196
275
 * number will be used (if available)
197
276
 *
204
283
 * returned by get_queue)
205
284
 *
206
285
 * data:
207
 
 * it may point to any plugin data and this pointer will be passed to
 
286
 * it may point to any driver data and this pointer will be passed to
208
287
 * all callback functions
209
288
 *
210
289
 * add_to_buf:
230
309
 * set_use_dec:
231
310
 * set_use_dec will be called after device is closed
232
311
 *
233
 
 * ioctl:
234
 
 * Some ioctl's can be directly handled by lirc_dev but will be
235
 
 * forwared here if not NULL and only handled if it returns
236
 
 * -ENOIOCTLCMD (see also lirc_serial.c).
237
 
 *
238
312
 * fops:
239
 
 * file_operations for drivers which don't fit the current plugin model.
 
313
 * file_operations for drivers which don't fit the current driver model.
 
314
 *
 
315
 * Some ioctl's can be directly handled by lirc_dev if the driver's
 
316
 * ioctl function is NULL or if it returns -ENOIOCTLCMD (see also
 
317
 * lirc_serial.c).
240
318
 *
241
319
 * owner:
242
320
 * the module owning this struct
248
326
 *
249
327
 * returns negative value on error or minor number
250
328
 * of the registered device if success
251
 
 * contens of the structure pointed by p is copied
 
329
 * contents of the structure pointed by d is copied
252
330
 */
253
 
extern int lirc_register_plugin(struct lirc_plugin *p);
 
331
extern int lirc_register_driver(struct lirc_driver *d);
254
332
 
255
333
/* returns negative value on error or 0 if success
256
334
*/
257
 
extern int lirc_unregister_plugin(int minor);
 
335
extern int lirc_unregister_driver(int minor);
258
336
 
259
 
/* Returns the private data stored in the lirc_plugin
 
337
/* Returns the private data stored in the lirc_driver
260
338
 * associated with the given device file pointer.
261
339
 */
262
340
void *lirc_get_pdata(struct file *file);