~ubuntu-branches/ubuntu/natty/lirc/natty-proposed

« 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: 2010-04-02 15:06:19 UTC
  • mfrom: (1.2.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20100402150619-y1z8c1yqv621a11o
Tags: 0.8.7~pre2-0ubuntu1
* Update to 0.8.7~pre2
  - Fixes issues with lirc on maverick. (LP: #620498)
* Add lirc-in-kernel-ioctls.patch to use ioctls from the kernel for drivers.
* Drop patches upstream now:
  - debian/patches/appleir_repeat_issue.patch
  - debian/patches/hauppauge-tv-card.patch
  - debian/patches/lirc-i2c-2.6.patch
  - debian/patches/lirc_dev-2.6.33.patch
* Add updated-driver-names.patch 
* Refresh patches:
  - debian/patches/02_Makefile.in
  - debian/patches/13-warning-cleanup
* Update extra transmitter and remote databases to not reference atiusb.
* debian/control:
  - Update branches to be owned by ~mythbuntu-dev
* Disable in-kernel-support when starting lircd, and re-enable when
  stopping.

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.37 2009/03/15 09:34:00 lirc Exp $
 
7
 * $Id: lirc_dev.h,v 1.41 2010/04/25 08:33:52 lirc Exp $
8
8
 *
9
9
 */
10
10
 
28
28
#include <linux/kfifo.h>
29
29
#endif
30
30
 
 
31
#include "drivers/lirc.h"
 
32
 
31
33
struct lirc_buffer {
32
34
        wait_queue_head_t wait_poll;
33
 
        spinlock_t lock;
 
35
        spinlock_t fifo_lock;
34
36
        unsigned int chunk_size;
35
37
        unsigned int size; /* in chunks */
36
38
        /* Using chunks instead of bytes pretends to simplify boundary checking
37
39
         * And should allow for some performance fine tunning later */
38
40
#ifdef LIRC_HAVE_KFIFO
 
41
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
39
42
        struct kfifo *fifo;
40
43
#else
 
44
        struct kfifo fifo;
 
45
        u8 fifo_initialized;
 
46
#endif
 
47
#else
41
48
        unsigned int fill; /* in chunks */
42
49
        int head, tail;    /* in chunks */
43
50
        unsigned char *data;
47
54
static inline void lirc_buffer_lock(struct lirc_buffer *buf,
48
55
                                    unsigned long *flags)
49
56
{
50
 
        spin_lock_irqsave(&buf->lock, *flags);
 
57
        spin_lock_irqsave(&buf->fifo_lock, *flags);
51
58
}
52
59
static inline void lirc_buffer_unlock(struct lirc_buffer *buf,
53
60
                                      unsigned long *flags)
54
61
{
55
 
        spin_unlock_irqrestore(&buf->lock, *flags);
 
62
        spin_unlock_irqrestore(&buf->fifo_lock, *flags);
56
63
}
57
64
static inline void _lirc_buffer_clear(struct lirc_buffer *buf)
58
65
{
64
71
static inline void lirc_buffer_clear(struct lirc_buffer *buf)
65
72
{
66
73
#ifdef LIRC_HAVE_KFIFO
 
74
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
67
75
        if (buf->fifo)
68
76
                kfifo_reset(buf->fifo);
69
77
#else
70
78
        unsigned long flags;
 
79
 
 
80
        if (buf->fifo_initialized) {
 
81
                spin_lock_irqsave(&buf->fifo_lock, flags);
 
82
                kfifo_reset(&buf->fifo);
 
83
                spin_unlock_irqrestore(&buf->fifo_lock, flags);
 
84
        }
 
85
#endif
 
86
#else
 
87
        unsigned long flags;
 
88
 
71
89
        lirc_buffer_lock(buf, &flags);
72
90
        _lirc_buffer_clear(buf);
73
91
        lirc_buffer_unlock(buf, &flags);
77
95
                                    unsigned int chunk_size,
78
96
                                    unsigned int size)
79
97
{
 
98
        int ret = 0;
 
99
 
80
100
        init_waitqueue_head(&buf->wait_poll);
81
 
        spin_lock_init(&buf->lock);
 
101
        spin_lock_init(&buf->fifo_lock);
82
102
#ifndef LIRC_HAVE_KFIFO
83
103
        _lirc_buffer_clear(buf);
84
104
#endif
85
105
        buf->chunk_size = chunk_size;
86
106
        buf->size = size;
87
107
#ifdef LIRC_HAVE_KFIFO
88
 
        buf->fifo = kfifo_alloc(size*chunk_size, GFP_KERNEL, &buf->lock);
 
108
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
 
109
        buf->fifo = kfifo_alloc(size*chunk_size, GFP_KERNEL, &buf->fifo_lock);
89
110
        if (!buf->fifo)
90
111
                return -ENOMEM;
91
112
#else
 
113
        ret = kfifo_alloc(&buf->fifo, size * chunk_size, GFP_KERNEL);
 
114
        if (ret == 0)
 
115
                buf->fifo_initialized = 1;
 
116
#endif
 
117
#else
92
118
        buf->data = kmalloc(size*chunk_size, GFP_KERNEL);
93
119
        if (buf->data == NULL)
94
120
                return -ENOMEM;
95
121
        memset(buf->data, 0, size*chunk_size);
96
122
#endif
97
 
        return 0;
 
123
 
 
124
        return ret;
98
125
}
99
126
static inline void lirc_buffer_free(struct lirc_buffer *buf)
100
127
{
101
128
#ifdef LIRC_HAVE_KFIFO
 
129
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
102
130
        if (buf->fifo)
103
131
                kfifo_free(buf->fifo);
104
132
#else
 
133
        if (buf->fifo_initialized) {
 
134
                kfifo_free(&buf->fifo);
 
135
                buf->fifo_initialized = 0;
 
136
        }
 
137
#endif
 
138
#else
105
139
        kfree(buf->data);
106
140
        buf->data = NULL;
107
141
        buf->head = 0;
111
145
        buf->size = 0;
112
146
#endif
113
147
}
 
148
 
 
149
#ifdef LIRC_HAVE_KFIFO
 
150
static inline int lirc_buffer_len(struct lirc_buffer *buf)
 
151
{
 
152
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
 
153
        return kfifo_len(buf->fifo);
 
154
#else
 
155
        int len;
 
156
        unsigned long flags;
 
157
 
 
158
        spin_lock_irqsave(&buf->fifo_lock, flags);
 
159
        len = kfifo_len(&buf->fifo);
 
160
        spin_unlock_irqrestore(&buf->fifo_lock, flags);
 
161
 
 
162
        return len;
 
163
#endif
 
164
}
 
165
#endif
 
166
 
114
167
#ifndef LIRC_HAVE_KFIFO
115
168
static inline int  _lirc_buffer_full(struct lirc_buffer *buf)
116
169
{
120
173
static inline int  lirc_buffer_full(struct lirc_buffer *buf)
121
174
{
122
175
#ifdef LIRC_HAVE_KFIFO
123
 
        return kfifo_len(buf->fifo) == buf->size * buf->chunk_size;
 
176
        return lirc_buffer_len(buf) == buf->size * buf->chunk_size;
124
177
#else
125
178
        unsigned long flags;
126
179
        int ret;
139
192
static inline int  lirc_buffer_empty(struct lirc_buffer *buf)
140
193
{
141
194
#ifdef LIRC_HAVE_KFIFO
142
 
        return !kfifo_len(buf->fifo);
 
195
        return !lirc_buffer_len(buf);
143
196
#else
144
197
        unsigned long flags;
145
198
        int ret;
158
211
static inline int  lirc_buffer_available(struct lirc_buffer *buf)
159
212
{
160
213
#ifdef LIRC_HAVE_KFIFO
161
 
        return buf->size - (kfifo_len(buf->fifo) / buf->chunk_size);
 
214
        return buf->size - (lirc_buffer_len(buf) / buf->chunk_size);
162
215
#else
163
216
        unsigned long flags;
164
217
        int ret;
177
230
        buf->fill -= 1;
178
231
}
179
232
#endif
180
 
static inline void lirc_buffer_read(struct lirc_buffer *buf,
181
 
                                    unsigned char *dest)
 
233
static inline unsigned int lirc_buffer_read(struct lirc_buffer *buf,
 
234
                                            unsigned char *dest)
182
235
{
 
236
        unsigned int ret = 0;
 
237
 
183
238
#ifdef LIRC_HAVE_KFIFO
184
 
        if (kfifo_len(buf->fifo) >= buf->chunk_size)
185
 
                kfifo_get(buf->fifo, dest, buf->chunk_size);
 
239
        if (lirc_buffer_len(buf) >= buf->chunk_size)
 
240
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
 
241
                ret = kfifo_get(buf->fifo, dest, buf->chunk_size);
 
242
#else
 
243
                ret = kfifo_out_locked(&buf->fifo, dest, buf->chunk_size,
 
244
                                       &buf->fifo_lock);
 
245
#endif
186
246
#else
187
247
        unsigned long flags;
188
248
        lirc_buffer_lock(buf, &flags);
189
249
        _lirc_buffer_read_1(buf, dest);
190
250
        lirc_buffer_unlock(buf, &flags);
191
251
#endif
 
252
 
 
253
        return ret;
192
254
}
193
255
#ifndef LIRC_HAVE_KFIFO
194
 
static inline void _lirc_buffer_write_1(struct lirc_buffer *buf,
 
256
static inline  _lirc_buffer_write_1(struct lirc_buffer *buf,
195
257
                                      unsigned char *orig)
196
258
{
197
259
        memcpy(&buf->data[buf->tail*buf->chunk_size], orig, buf->chunk_size);
199
261
        buf->fill++;
200
262
}
201
263
#endif
202
 
static inline void lirc_buffer_write(struct lirc_buffer *buf,
203
 
                                     unsigned char *orig)
 
264
static inline unsigned int lirc_buffer_write(struct lirc_buffer *buf,
 
265
                                             unsigned char *orig)
204
266
{
 
267
        unsigned int ret = 0;
 
268
 
205
269
#ifdef LIRC_HAVE_KFIFO
206
 
        kfifo_put(buf->fifo, orig, buf->chunk_size);
 
270
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
 
271
        ret = kfifo_put(buf->fifo, orig, buf->chunk_size);
 
272
#else
 
273
        ret = kfifo_in_locked(&buf->fifo, orig, buf->chunk_size,
 
274
                              &buf->fifo_lock);
 
275
#endif
207
276
#else
208
277
        unsigned long flags;
209
278
        lirc_buffer_lock(buf, &flags);
210
279
        _lirc_buffer_write_1(buf, orig);
211
280
        lirc_buffer_unlock(buf, &flags);
212
281
#endif
 
282
 
 
283
        return ret;
213
284
}
214
285
#ifndef LIRC_HAVE_KFIFO
215
286
static inline void _lirc_buffer_write_n(struct lirc_buffer *buf,
234
305
        buf->fill += count;
235
306
}
236
307
#endif
237
 
static inline void lirc_buffer_write_n(struct lirc_buffer *buf,
238
 
                                       unsigned char *orig, int count)
 
308
static inline unsigned int lirc_buffer_write_n(struct lirc_buffer *buf,
 
309
                                               unsigned char *orig, int count)
239
310
{
 
311
        unsigned int ret = 0;
 
312
 
240
313
#ifdef LIRC_HAVE_KFIFO
241
 
        kfifo_put(buf->fifo, orig, count * buf->chunk_size);
 
314
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
 
315
        ret = kfifo_put(buf->fifo, orig, count * buf->chunk_size);
 
316
#else
 
317
        ret = kfifo_in_locked(&buf->fifo, orig, count * buf->chunk_size,
 
318
                              &buf->fifo_lock);
 
319
#endif
242
320
#else
243
321
        unsigned long flags;
244
322
        lirc_buffer_lock(buf, &flags);
245
323
        _lirc_buffer_write_n(buf, orig, count);
246
324
        lirc_buffer_unlock(buf, &flags);
247
325
#endif
 
326
 
 
327
        return ret;
248
328
}
249
329
 
250
330
struct lirc_driver {
255
335
        int sample_rate;
256
336
        unsigned long features;
257
337
        void *data;
 
338
        lirc_t min_timeout;
 
339
        lirc_t max_timeout;
258
340
        int (*add_to_buf) (void *data, struct lirc_buffer *buf);
259
341
#ifndef LIRC_REMOVE_DURING_EXPORT
260
342
        wait_queue_head_t* (*get_queue) (void *data);
262
344
        struct lirc_buffer *rbuf;
263
345
        int (*set_use_inc) (void *data);
264
346
        void (*set_use_dec) (void *data);
265
 
        struct file_operations *fops;
 
347
        const struct file_operations *fops;
266
348
        struct device *dev;
267
349
        struct module *owner;
268
350
};