4 * by Artur Lipowski <alipowski@interia.pl>
5 * This code is licensed under GNU GPL
9 #ifndef _LINUX_LIRC_DEV_H
10 #define _LINUX_LIRC_DEV_H
12 #define MAX_IRCTL_DEVICES 8
15 #include <linux/slab.h>
17 #include <linux/ioctl.h>
18 #include <linux/poll.h>
19 #include <linux/kfifo.h>
20 #include <media/lirc.h>
23 wait_queue_head_t wait_poll
;
25 unsigned int chunk_size
;
26 unsigned int size
; /* in chunks */
27 /* Using chunks instead of bytes pretends to simplify boundary checking
28 * And should allow for some performance fine tunning later */
32 static inline void lirc_buffer_clear(struct lirc_buffer
*buf
)
36 if (kfifo_initialized(&buf
->fifo
)) {
37 spin_lock_irqsave(&buf
->fifo_lock
, flags
);
38 kfifo_reset(&buf
->fifo
);
39 spin_unlock_irqrestore(&buf
->fifo_lock
, flags
);
41 WARN(1, "calling %s on an uninitialized lirc_buffer\n",
45 static inline int lirc_buffer_init(struct lirc_buffer
*buf
,
46 unsigned int chunk_size
,
51 init_waitqueue_head(&buf
->wait_poll
);
52 spin_lock_init(&buf
->fifo_lock
);
53 buf
->chunk_size
= chunk_size
;
55 ret
= kfifo_alloc(&buf
->fifo
, size
* chunk_size
, GFP_KERNEL
);
60 static inline void lirc_buffer_free(struct lirc_buffer
*buf
)
62 if (kfifo_initialized(&buf
->fifo
)) {
63 kfifo_free(&buf
->fifo
);
65 WARN(1, "calling %s on an uninitialized lirc_buffer\n",
69 static inline int lirc_buffer_len(struct lirc_buffer
*buf
)
74 spin_lock_irqsave(&buf
->fifo_lock
, flags
);
75 len
= kfifo_len(&buf
->fifo
);
76 spin_unlock_irqrestore(&buf
->fifo_lock
, flags
);
81 static inline int lirc_buffer_full(struct lirc_buffer
*buf
)
83 return lirc_buffer_len(buf
) == buf
->size
* buf
->chunk_size
;
86 static inline int lirc_buffer_empty(struct lirc_buffer
*buf
)
88 return !lirc_buffer_len(buf
);
91 static inline unsigned int lirc_buffer_read(struct lirc_buffer
*buf
,
96 if (lirc_buffer_len(buf
) >= buf
->chunk_size
)
97 ret
= kfifo_out_locked(&buf
->fifo
, dest
, buf
->chunk_size
,
103 static inline unsigned int lirc_buffer_write(struct lirc_buffer
*buf
,
108 ret
= kfifo_in_locked(&buf
->fifo
, orig
, buf
->chunk_size
,
115 * struct lirc_driver - Defines the parameters on a LIRC driver
117 * @name: this string will be used for logs
119 * @minor: indicates minor device (/dev/lirc) number for
120 * registered driver if caller fills it with negative
121 * value, then the first free minor number will be used
124 * @code_length: length of the remote control key code expressed in bits.
126 * @buffer_size: Number of FIFO buffers with @chunk_size size. If zero,
127 * creates a buffer with BUFLEN size (16 bytes).
129 * @features: lirc compatible hardware features, like LIRC_MODE_RAW,
130 * LIRC_CAN\_\*, as defined at include/media/lirc.h.
132 * @chunk_size: Size of each FIFO buffer.
134 * @data: it may point to any driver data and this pointer will
135 * be passed to all callback functions.
137 * @min_timeout: Minimum timeout for record. Valid only if
138 * LIRC_CAN_SET_REC_TIMEOUT is defined.
140 * @max_timeout: Maximum timeout for record. Valid only if
141 * LIRC_CAN_SET_REC_TIMEOUT is defined.
143 * @rbuf: if not NULL, it will be used as a read buffer, you will
144 * have to write to the buffer by other means, like irq's
145 * (see also lirc_serial.c).
147 * @rdev: Pointed to struct rc_dev associated with the LIRC
150 * @fops: file_operations for drivers which don't fit the current
152 * Some ioctl's can be directly handled by lirc_dev if the
153 * driver's ioctl function is NULL or if it returns
154 * -ENOIOCTLCMD (see also lirc_serial.c).
156 * @dev: pointer to the struct device associated with the LIRC
159 * @owner: the module owning this struct
165 unsigned int buffer_size
; /* in chunks holding one code each */
168 unsigned int chunk_size
;
173 struct lirc_buffer
*rbuf
;
175 const struct file_operations
*fops
;
177 struct module
*owner
;
180 /* following functions can be called ONLY from user context
182 * returns negative value on error or minor number
183 * of the registered device if success
184 * contents of the structure pointed by p is copied
186 extern int lirc_register_driver(struct lirc_driver
*d
);
188 /* returns negative value on error or 0 if success
190 extern int lirc_unregister_driver(int minor
);
192 /* Returns the private data stored in the lirc_driver
193 * associated with the given device file pointer.
195 void *lirc_get_pdata(struct file
*file
);
197 /* default file operations
198 * used by drivers if they override only some operations
200 int lirc_dev_fop_open(struct inode
*inode
, struct file
*file
);
201 int lirc_dev_fop_close(struct inode
*inode
, struct file
*file
);
202 unsigned int lirc_dev_fop_poll(struct file
*file
, poll_table
*wait
);
203 long lirc_dev_fop_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
);
204 ssize_t
lirc_dev_fop_read(struct file
*file
, char __user
*buffer
, size_t length
,