1 diff -uprN -X dontdiff linux-2.6.5.orig/Documentation/lirc/lirc_it87 linux-2.6.5/Documentation/lirc/lirc_it87
2 --- linux-2.6.5.orig/Documentation/lirc/lirc_it87 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.6.5/Documentation/lirc/lirc_it87 2004-04-04 14:05:29.398630000 +0200
5 +This is the README using the ITE IT8705 and IT8712 CIR port for LIRC.
7 +The IT8705 for example can be found on the ECS K7S5A.
9 +The driver supports receiving (MODE2) and sending (PULSE). It seems
10 +sending 'LIRC_CAN_SEND_PULSE' isn't optimal for this type of hardware.
11 +But because I don't know how to implement 'LIRC_CAN_SEND_CODE', I did
15 +Because of missing hardware, the following hasn't been tested:
16 +a) receiving with demodulator enabled,
17 +b) sending (debugging output looks good) and
20 +Any help and/or additions etc. is welcome.
22 +lirc_it87 knows about the following module-parameters:
23 +MODULE_DESCRIPTION("LIRC driver for ITE IT8712/IT8705 CIR port");
24 +MODULE_PARM(io, "i");
25 +MODULE_PARM_DESC(io, "I/O base address (default: 0x310)");
26 +MODULE_PARM(irq, "i");
27 +MODULE_PARM_DESC(irq, "Interrupt (1,3-12) (default: 7)");
28 +MODULE_PARM(it87_enable_demodulator, "i");
29 +MODULE_PARM_DESC(it87_enable_demodulator, "Receiver demodulator
30 + enable/disable (1/0), default: 0");
37 +If the driver finds the IT8705/12-CIR port initialized, io and irq of
38 +the preinitialized hardware is used by the driver. If both values are
39 +read 0x0 from the hardware, the default or given value is used.
40 +Note: I experienced using irq=3. The driver initialized without any
41 +problems, but no irqs are recognized by the system. I had to switch
42 +back to default, irq 7.
44 +b) it87_enable_demodulator:
46 +The demodulator for the receiver can be switched off (default within
47 +the driver). If you need the demodulator simple enable it by the
48 +following way: it87_enable_demodulator=1.
50 +Hans-Günter Lütke Uphues
55 +This is my todo-list for lirc_it87:
57 +1. enabling/using shared IRQ
58 +2. init/drop IRQ-usage in lirc_open/lirc_close
59 diff -uprN -X dontdiff linux-2.6.5.orig/drivers/char/Kconfig linux-2.6.5/drivers/char/Kconfig
60 --- linux-2.6.5.orig/drivers/char/Kconfig 2004-04-04 13:59:17.669141472 +0200
61 +++ linux-2.6.5/drivers/char/Kconfig 2004-04-04 14:05:29.400629696 +0200
62 @@ -444,6 +444,9 @@ config A2232
64 source "drivers/serial/Kconfig"
67 +source "drivers/char/lirc/Kconfig"
70 bool "Unix98 PTY support" if EMBEDDED
72 diff -uprN -X dontdiff linux-2.6.5.orig/drivers/char/lirc/Kconfig linux-2.6.5/drivers/char/lirc/Kconfig
73 --- linux-2.6.5.orig/drivers/char/lirc/Kconfig 1970-01-01 01:00:00.000000000 +0100
74 +++ linux-2.6.5/drivers/char/lirc/Kconfig 2004-04-04 14:05:29.401629544 +0200
76 +# LIRC http://lirc.sf.net/
77 +# Kernel patch by Flameeyes <dgp85@users.sf.net>
78 +# Check for new patch at http://flameeyes.web.ctonet.it
80 +# Thanks to Koos Vriezen <koos.vriezen@xs4all.nl> for the Homebrew support.
81 +# Thanks to Jeff Clark <jeff@tmtrading.com> for support when I wasn't able
82 +# to update it and for his patch (found at http://www.clarkmania.com/~jclark/
83 +# Thanks to Bernhard Rosenkraenzer <bero@arklinux.org> for SMP patch.
84 +# Thanks to Vince <fuzzy77@free.fr> for the temporary lirc_atiusb driver.
85 +# Thanks to Paul Miller <pmiller9@users.sourceforge.net> for the new working
86 +# lirc_atiusb driver.
88 +menu "Linux InfraRed Controller"
91 + tristate "Linux InfraRed Controller"
94 + int "Maximum LIRC devices"
96 + depends on LIRC_SUPPORT
99 + tristate "I2C Driver"
100 + depends on LIRC_SUPPORT && VIDEO_BT848 && I2C && I2C_ALGOBIT
102 + Say Y here if you need support for the following cards:
110 + If these dont make sense to you, then dont use the module.
113 + tristate "GPIO Driver"
114 + depends on LIRC_SUPPORT && VIDEO_BT848
117 + tristate "BT829 Driver"
118 + depends on LIRC_SUPPORT
121 + tristate "IT87 Driver"
122 + depends on LIRC_SUPPORT
125 + tristate "ATI USB Driver"
126 + depends on LIRC_SUPPORT && USB
129 + tristate "MCE USB Driver"
130 + depends on LIRC_SUPPORT && USB
132 + config LIRC_PARALLEL
133 + tristate "Parallel Driver"
134 + depends on LIRC_SUPPORT && !SMP && PARPORT
137 + prompt "Parallel Port"
138 + depends on LIRC_PARALLEL
139 + config LIRC_PARALLEL_LPT1
140 + bool "LPT1 (0x378, 7)"
141 + config LIRC_PARALLEL_LPT2
142 + bool "LPT2 (0x278, 5)"
143 + config LIRC_PARALLEL_LPT3
144 + bool "COM3 (0x3bc, none)"
145 + config LIRC_PARALLEL_OTHER
146 + bool "Other (custom values)"
149 + config LIRC_PORT_PARALLEL
151 + default "0x378" if LIRC_PARALLEL_LPT1
152 + default "0x278" if LIRC_PARALLEL_LPT2
153 + default "0x3bc" if LIRC_PARALLEL_LPT3
154 + depends on LIRC_PARALLEL
156 + config LIRC_IRQ_PARALLEL
158 + default "7" if LIRC_PARALLEL_LPT1
159 + default "5" if LIRC_PARALLEL_LPT2
160 + depends on LIRC_PARALLEL
165 + depends on LIRC_PARALLEL
168 + tristate "Serial Driver"
169 + depends on LIRC_SUPPORT && SERIAL_8250
172 + prompt "Serial Receiver Type"
173 + depends on LIRC_SERIAL
175 + config LIRC_HOMEBREW
178 + config LIRC_SERIAL_ANIMAX
181 + config LIRC_SERIAL_IRDEO
184 + config LIRC_SERIAL_IRDEO_REMOTE
185 + bool "IRdeo Remote"
189 + config LIRC_SERIAL_TRANSMITTER
190 + bool "With transmitter diode"
191 + depends on LIRC_SERIAL && !LIRC_SERIAL_ANIMAX
193 + config LIRC_SERIAL_SOFTCARRIER
194 + bool "With software carrier"
195 + depends on LIRC_SERIAL_TRANSMITTER
197 + config LIRC_SERIAL_IGOR
198 + bool "Igor Ceska's variation"
199 + depends on LIRC_SERIAL
202 + prompt "Serial Port"
203 + depends on LIRC_SERIAL
204 + config LIRC_SERIAL_COM1
205 + bool "COM1 (0x3f8, 4)"
206 + config LIRC_SERIAL_COM2
207 + bool "COM2 (0x2f8, 3)"
208 + config LIRC_SERIAL_COM3
209 + bool "COM3 (0x3e8, 4)"
210 + config LIRC_SERIAL_COM4
211 + bool "COM4 (0x2e8, 3)"
212 + config LIRC_SERIAL_OTHER
213 + bool "Other (custom values)"
216 + config LIRC_PORT_SERIAL
218 + default "0x3f8" if LIRC_SERIAL_COM1
219 + default "0x2f8" if LIRC_SERIAL_COM2
220 + default "0x3e8" if LIRC_SERIAL_COM3
221 + default "0x2e8" if LIRC_SERIAL_COM4
222 + depends on LIRC_SERIAL
224 + config LIRC_IRQ_SERIAL
226 + default "4" if LIRC_SERIAL_COM1 || LIRC_SERIAL_COM3
227 + default "3" if LIRC_SERIAL_COM2 || LIRC_SERIAL_COM4
228 + depends on LIRC_SERIAL
231 + tristate "SIR Driver"
232 + depends on LIRC_SUPPORT
234 + config LIRC_ON_SA1100
235 + bool "LIRC driver for StrongARM SA1100 embedded microprocessor"
236 + depends on LIRC_SIR
240 + depends on LIRC_SIR && !LIRC_ON_SA1100
242 + config LIRC_SIR_IRDA
243 + bool "SIR IrDA (built-in IR ports)"
245 + config LIRC_SIR_TEKRAM
246 + bool "Tekram Irmate 210 (16x50 UART compatible serial port)"
248 + config LIRC_SIR_ACTISYS_ACT200L
249 + bool "Actisys Act200L SIR driver support"
254 + prompt "Serial Port"
255 + depends on LIRC_SIR
256 + config LIRC_SIR_COM1
257 + bool "COM1 (0x3f8, 4)"
258 + config LIRC_SIR_COM2
259 + bool "COM2 (0x2f8, 3)"
260 + config LIRC_SIR_COM3
261 + bool "COM3 (0x3e8, 4)"
262 + config LIRC_SIR_COM4
263 + bool "COM4 (0x2e8, 3)"
264 + config LIRC_SIR_OTHER
265 + bool "Other (custom values)"
268 + config LIRC_PORT_SIR
270 + default "0x3f8" if LIRC_SIR_COM1
271 + default "0x2f8" if LIRC_SIR_COM2
272 + default "0x3e8" if LIRC_SIR_COM3
273 + default "0x2e8" if LIRC_SIR_COM4
274 + depends on LIRC_SIR
276 + config LIRC_IRQ_SIR
278 + default "4" if LIRC_SIR_COM1 || LIRC_SIR_COM3
279 + default "3" if LIRC_SIR_COM2 || LIRC_SIR_COM4
280 + depends on LIRC_SIR
284 diff -uprN -X dontdiff linux-2.6.5.orig/drivers/char/lirc/lirc_atiusb.c linux-2.6.5/drivers/char/lirc/lirc_atiusb.c
285 --- linux-2.6.5.orig/drivers/char/lirc/lirc_atiusb.c 1970-01-01 01:00:00.000000000 +0100
286 +++ linux-2.6.5/drivers/char/lirc/lirc_atiusb.c 2004-04-04 14:05:29.403629240 +0200
288 +/* lirc_atiusb - USB remote support for LIRC
289 + * (currently only supports X10 USB remotes)
290 + * Version 0.3 [beta status]
292 + * Copyright (C) 2003-2004 Paul Miller <pmiller9@users.sourceforge.net>
294 + * This driver was derived from:
295 + * Vladimir Dergachev <volodya@minspring.com>'s 2002
296 + * "USB ATI Remote support" (input device)
297 + * Adrian Dewhurst <sailor-lk@sailorfrag.net>'s 2002
298 + * "USB StreamZap remote driver" (LIRC)
299 + * Artur Lipowski <alipowski@kki.net.pl>'s 2002
300 + * "lirc_dev" and "lirc_gpio" LIRC modules
306 + * This program is free software; you can redistribute it and/or modify
307 + * it under the terms of the GNU General Public License as published by
308 + * the Free Software Foundation; either version 2 of the License, or
309 + * (at your option) any later version.
311 + * This program is distributed in the hope that it will be useful,
312 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
313 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
314 + * GNU General Public License for more details.
316 + * You should have received a copy of the GNU General Public License
317 + * along with this program; if not, write to the Free Software
318 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
322 +#include <linux/version.h>
323 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 4)
324 +#error "*******************************************************"
325 +#error "Sorry, this driver needs kernel version 2.2.4 or higher"
326 +#error "*******************************************************"
329 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
335 +#include <linux/config.h>
337 +#include <linux/kernel.h>
338 +#include <linux/errno.h>
339 +#include <linux/init.h>
340 +#include <linux/slab.h>
341 +#include <linux/module.h>
342 +#include <linux/kmod.h>
343 +#include <linux/smp_lock.h>
344 +#include <linux/completion.h>
345 +#include <asm/uaccess.h>
346 +#include <linux/usb.h>
347 +#include <linux/poll.h>
348 +#include <linux/wait.h>
351 +#include <linux/lirc.h>
352 +#include "lirc_dev.h"
354 +#include "drivers/lirc.h"
355 +#include "drivers/lirc_dev/lirc_dev.h"
358 +#define DRIVER_VERSION "0.3"
359 +#define DRIVER_AUTHOR "Paul Miller <pmiller9@users.sourceforge.net>"
360 +#define DRIVER_DESC "USB remote driver for LIRC"
361 +#define DRIVER_NAME "lirc_atiusb"
363 +#define CODE_LENGTH 5
364 +#define CODE_MIN_LENGTH 4
365 +#define USB_BUFLEN (CODE_LENGTH*4)
367 +#ifdef CONFIG_USB_DEBUG
368 + static int debug = 1;
370 + static int debug = 0;
372 +#define dprintk if (debug) printk
374 +/* get hi and low bytes of a 16-bits int */
375 +#define HI(a) ((unsigned char)((a) >> 8))
376 +#define LO(a) ((unsigned char)((a) & 0xff))
378 +/* lock irctl structure */
379 +#define IRLOCK down_interruptible(&ir->lock)
380 +#define IRUNLOCK up(&ir->lock)
382 +/* general constants */
384 +#define SEND_FLAG_IN_PROGRESS 1
385 +#define SEND_FLAG_COMPLETE 2
388 +/* data structure for each usb remote */
392 + struct usb_device *usbdev;
393 + struct urb *urb_in;
394 + struct urb *urb_out;
397 + /* buffers and dma */
398 + unsigned char *buf_in;
399 + unsigned char *buf_out;
400 + unsigned int len_in;
403 + dma_addr_t dma_out;
407 + struct lirc_plugin *p;
410 + /* handle sending (init strings) */
412 + wait_queue_head_t wait_out;
414 + struct semaphore lock;
418 +static char init1[] = {0x01, 0x00, 0x20, 0x14};
419 +static char init2[] = {0x01, 0x00, 0x20, 0x14, 0x20, 0x20, 0x20};
421 +/* send packet - used to initialize remote */
422 +static void send_packet(struct irctl *ir, u16 cmd, unsigned char *data)
424 + DECLARE_WAITQUEUE(wait, current);
425 + int timeout = HZ; /* 1 second */
426 + unsigned char buf[USB_BUFLEN];
428 + dprintk(DRIVER_NAME "[%d]: send called (%#x)\n", ir->devnum, cmd);
431 + ir->urb_out->transfer_buffer_length = LO(cmd) + 1;
432 + ir->urb_out->dev = ir->usbdev;
433 + ir->send_flags = SEND_FLAG_IN_PROGRESS;
435 + memcpy(buf+1, data, LO(cmd));
437 + memcpy(ir->buf_out, buf, LO(cmd)+1);
439 + set_current_state(TASK_INTERRUPTIBLE);
440 + add_wait_queue(&ir->wait_out, &wait);
443 + if (usb_submit_urb(ir->urb_out, SLAB_ATOMIC)) {
445 + if (usb_submit_urb(ir->urb_out)) {
447 + set_current_state(TASK_RUNNING);
448 + remove_wait_queue(&ir->wait_out, &wait);
454 + while (timeout && (ir->urb_out->status == -EINPROGRESS)
455 + && !(ir->send_flags & SEND_FLAG_COMPLETE)) {
456 + timeout = schedule_timeout(timeout);
460 + dprintk(DRIVER_NAME "[%d]: send complete (%#x)\n", ir->devnum, cmd);
462 + set_current_state(TASK_RUNNING);
463 + remove_wait_queue(&ir->wait_out, &wait);
464 + usb_unlink_urb(ir->urb_out);
467 +static int unregister_from_lirc(struct irctl *ir)
469 + struct lirc_plugin *p = ir->p;
473 + devnum = ir->devnum;
474 + dprintk(DRIVER_NAME "[%d]: unregister from lirc called\n", devnum);
476 + if ((rtn = lirc_unregister_plugin(p->minor)) > 0) {
477 + printk(DRIVER_NAME "[%d]: error in lirc_unregister minor: %d\n"
478 + "Trying again...\n", devnum, p->minor);
479 + if (rtn == -EBUSY) {
481 + "[%d]: device is opened, will unregister"
482 + " on close\n", devnum);
485 + set_current_state(TASK_INTERRUPTIBLE);
486 + schedule_timeout(HZ);
488 + if ((rtn = lirc_unregister_plugin(p->minor)) > 0) {
489 + printk(DRIVER_NAME "[%d]: lirc_unregister failed\n",
494 + if (rtn != SUCCESS) {
495 + printk(DRIVER_NAME "[%d]: didn't free resources\n", devnum);
499 + printk(DRIVER_NAME "[%d]: usb remote disconnected\n", devnum);
501 + lirc_buffer_free(p->rbuf);
508 +static int set_use_inc(void *data)
510 + struct irctl *ir = data;
513 + printk(DRIVER_NAME "[?]: set_use_inc called with no context\n");
516 + dprintk(DRIVER_NAME "[%d]: set use inc\n", ir->devnum);
518 + if (!ir->connected) {
521 + ir->urb_in->dev = ir->usbdev;
523 + if (usb_submit_urb(ir->urb_in, SLAB_ATOMIC)) {
525 + if (usb_submit_urb(ir->urb_in)) {
527 + printk(DRIVER_NAME "[%d]: open result = -EIO error "
528 + "submitting urb\n", ir->devnum);
537 +static void set_use_dec(void *data)
539 + struct irctl *ir = data;
542 + printk(DRIVER_NAME "[?]: set_use_dec called with no context\n");
545 + dprintk(DRIVER_NAME "[%d]: set use dec\n", ir->devnum);
547 + if (ir->connected) {
549 + usb_unlink_urb(ir->urb_in);
557 +static void usb_remote_recv(struct urb *urb, struct pt_regs *regs)
559 +static void usb_remote_recv(struct urb *urb)
563 + char buf[CODE_LENGTH];
569 + if (!(ir = urb->context)) {
570 + usb_unlink_urb(urb);
574 + dprintk(DRIVER_NAME "[%d]: data received (length %d)\n",
575 + ir->devnum, urb->actual_length);
577 + switch (urb->status) {
581 + /* some remotes emit both 4 and 5 byte length codes. */
582 + len = urb->actual_length;
583 + if (len < CODE_MIN_LENGTH || len > CODE_LENGTH) return;
585 + memcpy(buf,urb->transfer_buffer,len);
586 + for (i = len; i < CODE_LENGTH; i++) buf[i] = 0;
588 + lirc_buffer_write_1(ir->p->rbuf, buf);
589 + wake_up(&ir->p->rbuf->wait_poll);
596 + usb_unlink_urb(urb);
602 + usb_submit_urb(urb, SLAB_ATOMIC);
604 + usb_submit_urb(urb);
609 +static void usb_remote_send(struct urb *urb, struct pt_regs *regs)
611 +static void usb_remote_send(struct urb *urb)
619 + if (!(ir = urb->context)) {
620 + usb_unlink_urb(urb);
624 + dprintk(DRIVER_NAME "[%d]: usb out called\n", ir->devnum);
629 + ir->send_flags |= SEND_FLAG_COMPLETE;
631 + if (waitqueue_active(&ir->wait_out))
632 + wake_up(&ir->wait_out);
636 +static int usb_remote_probe(struct usb_interface *intf,
637 + const struct usb_device_id *id)
639 + struct usb_device *dev = NULL;
640 + struct usb_host_interface *idesc = NULL;
642 +static void *usb_remote_probe(struct usb_device *dev, unsigned int ifnum,
643 + const struct usb_device_id *id)
645 + struct usb_interface *intf;
646 + struct usb_interface_descriptor *idesc;
648 + struct usb_endpoint_descriptor *ep_in, *ep_out;
649 + struct irctl *ir = NULL;
650 + struct lirc_plugin *plugin = NULL;
651 + struct lirc_buffer *rbuf = NULL;
652 + int devnum, pipe, maxp, len, buf_len, bytes_in_key;
654 + char buf[63], name[128]="";
655 + int mem_failure = 0;
657 + dprintk(DRIVER_NAME ": usb probe called\n");
660 + dev = interface_to_usbdev(intf);
661 + idesc = &intf->altsetting[intf->act_altsetting];
662 + if (idesc->desc.bNumEndpoints != 2)
664 + ep_in = &idesc->endpoint[0].desc;
665 + ep_out = &idesc->endpoint[1].desc;
666 + if (((ep_in->bEndpointAddress & USB_ENDPOINT_DIR_MASK) != USB_DIR_IN)
667 + || (ep_in->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
668 + != USB_ENDPOINT_XFER_INT)
671 + intf = &dev->actconfig->interface[ifnum];
672 + idesc = &intf->altsetting[intf->act_altsetting];
673 + if (idesc->bNumEndpoints != 2)
675 + ep_in = idesc->endpoint + 0;
676 + ep_out = idesc->endpoint + 1;
677 + if (((ep_in->bEndpointAddress & USB_ENDPOINT_DIR_MASK) != USB_DIR_IN)
678 + || (ep_in->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
679 + != USB_ENDPOINT_XFER_INT)
682 + devnum = dev->devnum;
683 + pipe = usb_rcvintpipe(dev, ep_in->bEndpointAddress);
684 + maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
686 + bytes_in_key = CODE_LENGTH;
687 + len = (maxp > USB_BUFLEN) ? USB_BUFLEN : maxp;
688 + buf_len = len - (len % bytes_in_key);
690 + dprintk(DRIVER_NAME "[%d]: bytes_in_key=%d len=%d maxp=%d buf_len=%d\n",
691 + devnum, bytes_in_key, len, maxp, buf_len);
694 + /* allocate kernel memory */
696 + if (!(ir = kmalloc(sizeof(struct irctl), GFP_KERNEL))) {
699 + memset(ir, 0, sizeof(struct irctl));
701 + if (!(plugin = kmalloc(sizeof(struct lirc_plugin), GFP_KERNEL))) {
703 + } else if (!(rbuf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL))) {
705 + } else if (lirc_buffer_init(rbuf, bytes_in_key, USB_BUFLEN/bytes_in_key)) {
708 + } else if (!(ir->buf_in = usb_buffer_alloc(dev, buf_len, SLAB_ATOMIC, &ir->dma_in))) {
710 + } else if (!(ir->buf_out = usb_buffer_alloc(dev, USB_BUFLEN, SLAB_ATOMIC, &ir->dma_out))) {
712 + } else if (!(ir->urb_in = usb_alloc_urb(0, GFP_KERNEL))) {
714 + } else if (!(ir->urb_out = usb_alloc_urb(0, GFP_KERNEL))) {
717 + } else if (!(ir->buf_in = kmalloc(buf_len, GFP_KERNEL))) {
719 + } else if (!(ir->buf_out = kmalloc(USB_BUFLEN, GFP_KERNEL))) {
721 + } else if (!(ir->urb_in = usb_alloc_urb(0))) {
723 + } else if (!(ir->urb_out = usb_alloc_urb(0))) {
728 + memset(plugin, 0, sizeof(struct lirc_plugin));
730 + strcpy(plugin->name, DRIVER_NAME " ");
731 + plugin->minor = -1;
732 + plugin->code_length = bytes_in_key*8;
733 + plugin->features = LIRC_CAN_REC_LIRCCODE;
735 + plugin->rbuf = rbuf;
736 + plugin->set_use_inc = &set_use_inc;
737 + plugin->set_use_dec = &set_use_dec;
739 + init_MUTEX(&ir->lock);
740 + init_waitqueue_head(&ir->wait_out);
742 + if ((minor = lirc_register_plugin(plugin)) < 0) {
748 + /* free allocated memory incase of failure */
749 + switch (mem_failure) {
751 + lirc_buffer_free(rbuf);
753 + usb_free_urb(ir->urb_out);
755 + usb_free_urb(ir->urb_in);
758 + usb_buffer_free(dev, USB_BUFLEN, ir->buf_out, ir->dma_out);
760 + usb_buffer_free(dev, buf_len, ir->buf_in, ir->dma_in);
763 + kfree(ir->buf_out);
774 + printk(DRIVER_NAME "[%d]: out of memory (code=%d)\n",
775 + devnum, mem_failure);
783 + plugin->minor = minor;
785 + ir->devnum = devnum;
787 + ir->len_in = buf_len;
790 + usb_fill_int_urb(ir->urb_in, dev, pipe, ir->buf_in,
791 + buf_len, usb_remote_recv, ir, ep_in->bInterval);
792 + usb_fill_int_urb(ir->urb_out, dev,
793 + usb_sndintpipe(dev, ep_out->bEndpointAddress), ir->buf_out,
794 + USB_BUFLEN, usb_remote_send, ir, ep_out->bInterval);
796 + if (dev->descriptor.iManufacturer
797 + && usb_string(dev, dev->descriptor.iManufacturer, buf, 63) > 0)
798 + strncpy(name, buf, 128);
799 + if (dev->descriptor.iProduct
800 + && usb_string(dev, dev->descriptor.iProduct, buf, 63) > 0)
801 + snprintf(name, 128, "%s %s", name, buf);
802 + printk(DRIVER_NAME "[%d]: %s on usb%d:%d\n", devnum, name,
803 + dev->bus->busnum, devnum);
805 + send_packet(ir, 0x8004, init1);
806 + send_packet(ir, 0x8007, init2);
809 + usb_set_intfdata(intf, ir);
818 +static void usb_remote_disconnect(struct usb_interface *intf)
820 + struct usb_device *dev = interface_to_usbdev(intf);
821 + struct irctl *ir = usb_get_intfdata(intf);
822 + usb_set_intfdata(intf, NULL);
824 +static void usb_remote_disconnect(struct usb_device *dev, void *ptr)
826 + struct irctl *ir = ptr;
833 + wake_up_all(&ir->wait_out);
836 + usb_unlink_urb(ir->urb_in);
837 + usb_unlink_urb(ir->urb_out);
838 + usb_free_urb(ir->urb_in);
839 + usb_free_urb(ir->urb_out);
841 + usb_buffer_free(dev, ir->len_in, ir->buf_in, ir->dma_in);
842 + usb_buffer_free(dev, USB_BUFLEN, ir->buf_out, ir->dma_out);
845 + kfree(ir->buf_out);
849 + unregister_from_lirc(ir);
852 +static struct usb_device_id usb_remote_id_table [] = {
853 + { USB_DEVICE(0x0bc7, 0x0002) }, /* X10 USB Firecracker Interface */
854 + { USB_DEVICE(0x0bc7, 0x0003) }, /* X10 VGA Video Sender */
855 + { USB_DEVICE(0x0bc7, 0x0004) }, /* ATI Wireless Remote Receiver */
856 + { USB_DEVICE(0x0bc7, 0x0005) }, /* NVIDIA Wireless Remote Receiver */
857 + { USB_DEVICE(0x0bc7, 0x0006) }, /* ATI Wireless Remote Receiver */
858 + { USB_DEVICE(0x0bc7, 0x0007) }, /* X10 USB Wireless Transceiver */
859 + { USB_DEVICE(0x0bc7, 0x0008) }, /* X10 USB Wireless Transceiver */
860 + { USB_DEVICE(0x0bc7, 0x0009) }, /* X10 USB Wireless Transceiver */
861 + { USB_DEVICE(0x0bc7, 0x000A) }, /* X10 USB Wireless Transceiver */
862 + { USB_DEVICE(0x0bc7, 0x000B) }, /* X10 USB Transceiver */
863 + { USB_DEVICE(0x0bc7, 0x000C) }, /* X10 USB Transceiver */
864 + { USB_DEVICE(0x0bc7, 0x000D) }, /* X10 USB Transceiver */
865 + { USB_DEVICE(0x0bc7, 0x000E) }, /* X10 USB Transceiver */
866 + { USB_DEVICE(0x0bc7, 0x000F) }, /* X10 USB Transceiver */
868 + { } /* Terminating entry */
871 +static struct usb_driver usb_remote_driver = {
872 + .owner = THIS_MODULE,
873 + .name = DRIVER_NAME,
874 + .probe = usb_remote_probe,
875 + .disconnect = usb_remote_disconnect,
876 + .id_table = usb_remote_id_table
879 +static int __init usb_remote_init(void)
883 + printk("\n" DRIVER_NAME ": " DRIVER_DESC " v" DRIVER_VERSION "\n");
884 + printk(DRIVER_NAME ": " DRIVER_AUTHOR "\n");
885 + dprintk(DRIVER_NAME ": debug mode enabled\n");
887 + request_module("lirc_dev");
889 + if ((i = usb_register(&usb_remote_driver)) < 0) {
890 + printk(DRIVER_NAME ": usb register failed, result = %d\n", i);
897 +static void __exit usb_remote_exit(void)
899 + usb_deregister(&usb_remote_driver);
902 +module_init(usb_remote_init);
903 +module_exit(usb_remote_exit);
905 +MODULE_AUTHOR (DRIVER_AUTHOR);
906 +MODULE_DESCRIPTION (DRIVER_DESC);
907 +MODULE_LICENSE ("GPL");
908 +MODULE_DEVICE_TABLE (usb, usb_remote_id_table);
910 +MODULE_PARM(debug, "i");
911 +MODULE_PARM_DESC(debug, "enable driver debug mode");
917 diff -uprN -X dontdiff linux-2.6.5.orig/drivers/char/lirc/lirc_bt829.c linux-2.6.5/drivers/char/lirc/lirc_bt829.c
918 --- linux-2.6.5.orig/drivers/char/lirc/lirc_bt829.c 1970-01-01 01:00:00.000000000 +0100
919 +++ linux-2.6.5/drivers/char/lirc/lirc_bt829.c 2004-04-04 14:05:29.405628936 +0200
922 + * Remote control driver for the TV-card based on bt829
924 + * by Leonid Froenchenko <lfroen@galileo.co.il>
926 + * This program is free software; you can redistribute it and/or modify
927 + * it under the terms of the GNU General Public License as published by
928 + * the Free Software Foundation; either version 2 of the License, or
929 + * (at your option) any later version.
931 + * This program is distributed in the hope that it will be useful,
932 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
933 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
934 + * GNU General Public License for more details.
936 + * You should have received a copy of the GNU General Public License
937 + * along with this program; if not, write to the Free Software
938 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
941 +#include <linux/version.h>
942 +#include <linux/config.h>
943 +#include <linux/kernel.h>
944 +#include <linux/module.h>
945 +#include <linux/threads.h>
946 +#include <linux/sched.h>
947 +#include <linux/ioport.h>
948 +#include <linux/pci.h>
949 +#include <linux/delay.h>
950 +#include <linux/init.h>
952 +#include "lirc_dev.h"
954 +int poll_main(void);
955 +int atir_init_start(void);
957 +void write_index(unsigned char index,unsigned int value);
958 +unsigned int read_index(unsigned char index);
960 +void do_i2c_start(void);
961 +void do_i2c_stop(void);
963 +void seems_wr_byte(unsigned char al);
964 +unsigned char seems_rd_byte(void);
966 +unsigned int read_index(unsigned char al);
967 +void write_index(unsigned char ah,unsigned int edx);
969 +void cycle_delay(int cycle);
971 +void do_set_bits(unsigned char bl);
972 +unsigned char do_get_bits(void);
974 +#define DATA_PCI_OFF 0x7FFC00
975 +#define WAIT_CYCLE 20
979 +unsigned long pci_addr_phys, pci_addr_lin;
981 +struct lirc_plugin atir_plugin;
983 +int do_pci_probe(void)
985 + struct pci_dev *my_dev;
986 + my_dev = (struct pci_dev *)pci_find_device(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_264VT,NULL);
988 + printk(KERN_ERR "ATIR: Using device: %s\n",my_dev->slot_name);
990 + if ( my_dev->resource[0].flags & IORESOURCE_MEM ) {
991 + pci_addr_phys = my_dev->resource[0].start;
992 + printk(KERN_INFO "ATIR memory at 0x%08X \n",(unsigned int)pci_addr_phys);
994 + if ( pci_addr_phys == 0 ) {
995 + printk(KERN_ERR "ATIR no memory resource ?\n");
999 + printk(KERN_ERR "ATIR: pci_prob failed\n");
1006 +int atir_add_to_buf (void* data, struct lirc_buffer* buf)
1008 + unsigned char key;
1010 + status = poll_main();
1011 + key = (status >> 8) & 0xFF;
1012 + if( status & 0xFF )
1014 + // printk(KERN_INFO "ATIR reading key %02X\n",*key);
1015 + lirc_buffer_write_1( buf, &key );
1021 +int atir_set_use_inc(void* data)
1023 + printk(KERN_DEBUG "ATIR driver is opened\n");
1027 +void atir_set_use_dec(void* data)
1029 + printk(KERN_DEBUG "ATIR driver is closed\n");
1032 +static int __init lirc_bt829_init(void)
1034 + if ( !do_pci_probe() ) {
1038 + if ( !atir_init_start() ) {
1042 + strcpy(atir_plugin.name,"ATIR");
1043 + atir_plugin.minor = -1;
1044 + atir_plugin.code_length = 8;
1045 + atir_plugin.sample_rate = 10;
1046 + atir_plugin.data = 0;
1047 + atir_plugin.add_to_buf = atir_add_to_buf;
1048 + atir_plugin.set_use_inc = atir_set_use_inc;
1049 + atir_plugin.set_use_dec = atir_set_use_dec;
1051 + atir_minor = lirc_register_plugin(&atir_plugin);
1052 + printk(KERN_DEBUG "ATIR driver is registered on minor %d\n",atir_minor);
1058 +static void __exit lirc_bt829_exit(void)
1060 + lirc_unregister_plugin(atir_minor);
1064 +int atir_init_start(void)
1066 + pci_addr_lin = (unsigned long)ioremap(pci_addr_phys + DATA_PCI_OFF,0x400);
1067 + if ( pci_addr_lin == 0 ) {
1068 + printk(KERN_INFO "atir: pci mem must be mapped\n");
1074 +void cycle_delay(int cycle)
1076 + udelay(WAIT_CYCLE*cycle);
1082 + unsigned char status_high, status_low;
1086 + seems_wr_byte(0xAA);
1087 + seems_wr_byte(0x01);
1091 + seems_wr_byte(0xAB);
1093 + status_low = seems_rd_byte();
1094 + status_high = seems_rd_byte();
1098 + return (status_high << 8) | status_low;
1101 +void do_i2c_start(void)
1113 +void do_i2c_stop(void)
1115 + unsigned char bits;
1116 + bits = do_get_bits() & 0xFD;
1117 + do_set_bits(bits);
1121 + do_set_bits(bits);
1125 + do_set_bits(bits);
1127 + do_set_bits(bits);
1132 +void seems_wr_byte(unsigned char value)
1135 + unsigned char reg;
1137 + reg = do_get_bits();
1138 + for(i = 0;i < 8;i++) {
1139 + if ( value & 0x80 ) {
1172 +unsigned char seems_rd_byte(void)
1176 + unsigned char bits_2, bits_1;
1178 + bits_1 = do_get_bits() | 2;
1179 + do_set_bits(bits_1);
1182 + for(i = 0;i < 8;i++) {
1184 + do_set_bits(bits_1);
1188 + do_set_bits(bits_1);
1191 + if ( (bits_2 = do_get_bits()) & 2 ) {
1198 + if ( bits_2 == 0 ) {
1201 + do_set_bits(bits_1);
1205 + do_set_bits(bits_1);
1209 + do_set_bits(bits_1);
1217 +void do_set_bits(unsigned char new_bits)
1220 + reg_val = read_index(0x34);
1221 + if ( new_bits & 2 ) {
1222 + reg_val &= 0xFFFFFFDF;
1225 + reg_val &= 0xFFFFFFFE;
1229 + write_index(0x34,reg_val);
1231 + reg_val = read_index(0x31);
1232 + if ( new_bits & 1 ) {
1233 + reg_val |= 0x1000000;
1235 + reg_val &= 0xFEFFFFFF;
1237 + reg_val |= 0x8000000;
1238 + write_index(0x31,reg_val);
1241 +unsigned char do_get_bits(void)
1243 + unsigned char bits;
1246 + reg_val = read_index(0x34);
1248 + reg_val &= 0xFFFFFFDF;
1249 + write_index(0x34,reg_val);
1251 + reg_val = read_index(0x34);
1253 + if ( reg_val & 8 ) {
1258 + reg_val = read_index(0x31);
1259 + if ( reg_val & 0x1000000 ) {
1267 +unsigned int read_index(unsigned char index)
1269 + unsigned int addr, value;
1270 + // addr = pci_addr_lin + DATA_PCI_OFF + ((index & 0xFF) << 2);
1271 + addr = pci_addr_lin + ((index & 0xFF) << 2);
1272 + value = readl(addr);
1276 +void write_index(unsigned char index,unsigned int reg_val)
1278 + unsigned int addr;
1279 + addr = pci_addr_lin + ((index & 0xFF) << 2);
1280 + writel(reg_val,addr);
1283 +MODULE_AUTHOR("Froenchenko Leonid");
1284 +MODULE_DESCRIPTION("IR remote driver for bt829 based TV cards");
1285 +MODULE_LICENSE("GPL");
1287 +module_init(lirc_bt829_init);
1288 +module_exit(lirc_bt829_exit);
1289 diff -uprN -X dontdiff linux-2.6.5.orig/drivers/char/lirc/lirc_dev.c linux-2.6.5/drivers/char/lirc/lirc_dev.c
1290 --- linux-2.6.5.orig/drivers/char/lirc/lirc_dev.c 1970-01-01 01:00:00.000000000 +0100
1291 +++ linux-2.6.5/drivers/char/lirc/lirc_dev.c 2004-04-04 14:05:29.407628632 +0200
1294 + * LIRC base driver
1296 + * (L) by Artur Lipowski <alipowski@interia.pl>
1298 + * This program is free software; you can redistribute it and/or modify
1299 + * it under the terms of the GNU General Public License as published by
1300 + * the Free Software Foundation; either version 2 of the License, or
1301 + * (at your option) any later version.
1303 + * This program is distributed in the hope that it will be useful,
1304 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1305 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1306 + * GNU General Public License for more details.
1308 + * You should have received a copy of the GNU General Public License
1309 + * along with this program; if not, write to the Free Software
1310 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1316 +#include <linux/version.h>
1318 +#include <linux/config.h>
1319 +#include <linux/module.h>
1320 +#include <linux/kernel.h>
1321 +#include <linux/sched.h>
1322 +#include <linux/ioctl.h>
1323 +#include <linux/fs.h>
1324 +#include <linux/poll.h>
1325 +#include <linux/smp_lock.h>
1326 +#include <asm/uaccess.h>
1327 +#include <asm/semaphore.h>
1328 +#include <asm/errno.h>
1329 +#define __KERNEL_SYSCALLS__
1330 +#include <linux/unistd.h>
1331 +#include <linux/init.h>
1332 +#include <linux/devfs_fs_kernel.h>
1334 +#include <linux/lirc.h>
1336 +#include "lirc_dev.h"
1338 +static int debug = 0;
1340 +MODULE_PARM(debug,"i");
1342 +#define IRCTL_DEV_NAME "BaseRemoteCtl"
1345 +#define dprintk if (debug) printk
1347 +#define LOGHEAD "lirc_dev (%s[%d]): "
1351 + struct lirc_plugin p;
1354 + struct lirc_buffer *buf;
1358 + struct semaphore *t_notify;
1359 + struct semaphore *t_notify2;
1361 + long jiffies_to_wait;
1364 +DECLARE_MUTEX(plugin_lock);
1366 +static struct irctl irctls[CONFIG_LIRC_MAX_DEV];
1367 +static struct file_operations fops;
1371 + * initializes the irctl structure
1373 +static inline void init_irctl(struct irctl *ir)
1375 + memset(&ir->p, 0, sizeof(struct lirc_plugin));
1376 + ir->p.minor = NOPLUG;
1379 + ir->t_notify = NULL;
1380 + ir->t_notify2 = NULL;
1383 + ir->jiffies_to_wait = 0;
1390 + * reads key codes from plugin and puts them into buffer
1391 + * buffer free space is checked and locking performed
1392 + * returns 0 on success
1395 +inline static int add_to_buf(struct irctl *ir)
1397 + if (lirc_buffer_full(ir->buf)) {
1398 + dprintk(LOGHEAD "buffer overflow\n",
1399 + ir->p.name, ir->p.minor);
1400 + return -EOVERFLOW;
1403 + if(ir->p.add_to_buf) {
1404 + int res = -ENODATA;
1407 + /* Service the device as long as it is returning
1408 + * data and we have space
1410 + while( !lirc_buffer_full(ir->buf) )
1412 + res = ir->p.add_to_buf( ir->p.data, ir->buf );
1413 + if( res == SUCCESS )
1419 + if( res == -ENODEV )
1423 + return (got_data ? SUCCESS : res);
1429 +/* main function of the polling thread
1431 +static int lirc_thread(void *irctl)
1433 + struct irctl *ir = irctl;
1435 + daemonize("lirc_dev");
1437 + if (ir->t_notify != NULL) {
1441 + dprintk(LOGHEAD "poll thread started\n", ir->p.name, ir->p.minor);
1445 + if (ir->jiffies_to_wait) {
1446 + current->state = TASK_INTERRUPTIBLE;
1447 + schedule_timeout(ir->jiffies_to_wait);
1449 + interruptible_sleep_on(ir->p.get_queue(ir->p.data));
1451 + if (ir->shutdown || !ir->open) {
1454 + if (!add_to_buf(ir)) {
1455 + wake_up_interruptible(&ir->buf->wait_poll);
1458 + /* if device not opened so we can sleep half a second */
1459 + current->state = TASK_INTERRUPTIBLE;
1460 + schedule_timeout(HZ/2);
1462 + } while (!ir->shutdown);
1464 + dprintk(LOGHEAD "poll thread ended\n", ir->p.name, ir->p.minor);
1466 + if (ir->t_notify2 != NULL) {
1467 + down(ir->t_notify2);
1472 + if (ir->t_notify != NULL) {
1482 +int lirc_register_plugin(struct lirc_plugin *p)
1487 + DECLARE_MUTEX_LOCKED(tn);
1490 + printk("lirc_dev: lirc_register_plugin:"
1491 + "plugin pointer must be not NULL!\n");
1495 + if (CONFIG_LIRC_MAX_DEV <= p->minor) {
1496 + printk("lirc_dev: lirc_register_plugin:"
1497 + "\" minor\" must be beetween 0 and %d (%d)!\n",
1498 + CONFIG_LIRC_MAX_DEV-1, p->minor);
1502 + if (1 > p->code_length || (BUFLEN*8) < p->code_length) {
1503 + printk("lirc_dev: lirc_register_plugin:"
1504 + "code length in bits for minor (%d) "
1505 + "must be less than %d!\n",
1506 + p->minor, BUFLEN*8);
1510 + printk("lirc_dev: lirc_register_plugin:"
1511 + "sample_rate: %d\n",p->sample_rate);
1512 + if (p->sample_rate) {
1513 + if (2 > p->sample_rate || 100 < p->sample_rate) {
1514 + printk("lirc_dev: lirc_register_plugin:"
1515 + "sample_rate must be beetween 2 and 100!\n");
1518 + if (!p->add_to_buf) {
1519 + printk("lirc_dev: lirc_register_plugin:"
1520 + "add_to_buf cannot be NULL when sample_rate is set\n");
1523 + } else if (!(p->fops && p->fops->read)
1524 + && !p->get_queue && !p->rbuf) {
1525 + printk("lirc_dev: lirc_register_plugin:"
1526 + "fops->read, get_queue and rbuf cannot all be NULL!\n");
1528 + } else if (!p->get_queue && !p->rbuf) {
1529 + if (!(p->fops && p->fops->read && p->fops->poll)
1530 + || (!p->fops->ioctl && !p->ioctl)) {
1531 + printk("lirc_dev: lirc_register_plugin:"
1532 + "neither read, poll nor ioctl can be NULL!\n");
1537 + down_interruptible(&plugin_lock);
1542 + /* find first free slot for plugin */
1543 + for (minor=0; minor<CONFIG_LIRC_MAX_DEV; minor++)
1544 + if (irctls[minor].p.minor == NOPLUG)
1546 + if (CONFIG_LIRC_MAX_DEV == minor) {
1547 + printk("lirc_dev: lirc_register_plugin: "
1548 + "no free slots for plugins!\n");
1552 + } else if (irctls[minor].p.minor != NOPLUG) {
1553 + printk("lirc_dev: lirc_register_plugin:"
1554 + "minor (%d) just registerd!\n", minor);
1559 + ir = &irctls[minor];
1561 + if (p->sample_rate) {
1562 + ir->jiffies_to_wait = HZ / p->sample_rate;
1564 + /* it means - wait for externeal event in task queue */
1565 + ir->jiffies_to_wait = 0;
1568 + /* some safety check 8-) */
1569 + p->name[sizeof(p->name)-1] = '\0';
1571 + bytes_in_key = p->code_length/8 + (p->code_length%8 ? 1 : 0);
1574 + ir->buf = p->rbuf;
1576 + ir->buf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
1577 + lirc_buffer_init(ir->buf, bytes_in_key, BUFLEN/bytes_in_key);
1580 + if (p->features==0)
1581 + p->features = (p->code_length > 8) ?
1582 + LIRC_CAN_REC_LIRCCODE : LIRC_CAN_REC_CODE;
1585 + ir->p.minor = minor;
1587 +#ifdef CONFIG_DEVFS_FS
1588 + devfs_mk_cdev(MKDEV(IRCTL_DEV_MAJOR, ir->p.minor), S_IFCHR | S_IRUSR | S_IWUSR, "lirc/lirc%d", ir->p.minor);
1591 + if(p->sample_rate || p->get_queue) {
1592 + /* try to fire up polling thread */
1593 + ir->t_notify = &tn;
1594 + ir->t_pid = kernel_thread(lirc_thread, (void*)ir, 0);
1595 + if (ir->t_pid < 0) {
1597 + printk("lirc_dev: lirc_register_plugin:"
1598 + "cannot run poll thread for minor = %d\n",
1603 + ir->t_notify = NULL;
1607 + try_module_get(THIS_MODULE);
1609 + dprintk("lirc_dev: plugin %s registered at minor number = %d\n",
1610 + ir->p.name, ir->p.minor);
1618 +int lirc_unregister_plugin(int minor)
1621 + DECLARE_MUTEX_LOCKED(tn);
1622 + DECLARE_MUTEX_LOCKED(tn2);
1624 + if (minor < 0 || minor >= CONFIG_LIRC_MAX_DEV) {
1625 + printk("lirc_dev: lirc_unregister_plugin:"
1626 + "\" minor\" must be beetween 0 and %d!\n",
1627 + CONFIG_LIRC_MAX_DEV-1);
1631 + ir = &irctls[minor];
1633 + down_interruptible(&plugin_lock);
1635 + if (ir->p.minor != minor) {
1636 + printk("lirc_dev: lirc_unregister_plugin:"
1637 + "minor (%d) device not registered!", minor);
1643 + printk("lirc_dev: lirc_unregister_plugin:"
1644 + "plugin %s[%d] in use!", ir->p.name, ir->p.minor);
1649 + /* end up polling thread */
1650 + if (ir->t_pid >= 0) {
1651 + ir->t_notify = &tn;
1652 + ir->t_notify2 = &tn2;
1655 + struct task_struct *p;
1657 + p = find_task_by_pid(ir->t_pid);
1658 + wake_up_process(p);
1662 + ir->t_notify = NULL;
1663 + ir->t_notify2 = NULL;
1666 + dprintk("lirc_dev: plugin %s unregistered from minor number = %d\n",
1667 + ir->p.name, ir->p.minor);
1669 +#ifdef CONFIG_DEVFS_FS
1670 + devfs_remove("lirc/lirc%d", ir->p.minor);
1673 + if (ir->buf != ir->p.rbuf){
1674 + lirc_buffer_free(ir->buf);
1681 + module_put(THIS_MODULE);
1689 +static int irctl_open(struct inode *inode, struct file *file)
1694 + if (MINOR(inode->i_rdev) >= CONFIG_LIRC_MAX_DEV) {
1695 + dprintk("lirc_dev [%d]: open result = -ENODEV\n",
1696 + MINOR(inode->i_rdev));
1700 + ir = &irctls[MINOR(inode->i_rdev)];
1702 + dprintk(LOGHEAD "open called\n", ir->p.name, ir->p.minor);
1704 + /* if the plugin has an open function use it instead */
1705 + if(ir->p.fops && ir->p.fops->open)
1706 + return ir->p.fops->open(inode, file);
1708 + down_interruptible(&plugin_lock);
1710 + if (ir->p.minor == NOPLUG) {
1712 + dprintk(LOGHEAD "open result = -ENODEV\n",
1713 + ir->p.name, ir->p.minor);
1719 + dprintk(LOGHEAD "open result = -EBUSY\n",
1720 + ir->p.name, ir->p.minor);
1724 + /* there is no need for locking here because ir->open is 0
1725 + * and lirc_thread isn't using buffer
1726 + * plugins which use irq's should allocate them on set_use_inc,
1727 + * so there should be no problem with those either.
1729 + ir->buf->head = ir->buf->tail;
1730 + ir->buf->fill = 0;
1733 + retval = ir->p.set_use_inc(ir->p.data);
1737 + if (retval != SUCCESS) {
1742 + dprintk(LOGHEAD "open result = %d\n", ir->p.name, ir->p.minor, SUCCESS);
1750 +static int irctl_close(struct inode *inode, struct file *file)
1752 + struct irctl *ir = &irctls[MINOR(inode->i_rdev)];
1754 + dprintk(LOGHEAD "close called\n", ir->p.name, ir->p.minor);
1756 + /* if the plugin has a close function use it instead */
1757 + if(ir->p.fops && ir->p.fops->release)
1758 + return ir->p.fops->release(inode, file);
1760 + down_interruptible(&plugin_lock);
1763 + ir->p.set_use_dec(ir->p.data);
1773 +static unsigned int irctl_poll(struct file *file, poll_table *wait)
1775 + struct irctl *ir = &irctls[MINOR(file->f_dentry->d_inode->i_rdev)];
1777 + dprintk(LOGHEAD "poll called\n", ir->p.name, ir->p.minor);
1779 + /* if the plugin has a poll function use it instead */
1780 + if(ir->p.fops && ir->p.fops->poll)
1781 + return ir->p.fops->poll(file, wait);
1783 + poll_wait(file, &ir->buf->wait_poll, wait);
1785 + dprintk(LOGHEAD "poll result = %s\n",
1786 + ir->p.name, ir->p.minor,
1787 + lirc_buffer_empty(ir->buf) ? "0" : "POLLIN|POLLRDNORM");
1789 + return lirc_buffer_empty(ir->buf) ? 0 : (POLLIN|POLLRDNORM);
1795 +static int irctl_ioctl(struct inode *inode, struct file *file,
1796 + unsigned int cmd, unsigned long arg)
1798 + unsigned long mode;
1800 + struct irctl *ir = &irctls[MINOR(inode->i_rdev)];
1802 + dprintk(LOGHEAD "ioctl called (%u)\n",
1803 + ir->p.name, ir->p.minor, cmd);
1805 + /* if the plugin has a ioctl function use it instead */
1806 + if(ir->p.fops && ir->p.fops->ioctl)
1807 + return ir->p.fops->ioctl(inode, file, cmd, arg);
1809 + if (ir->p.minor == NOPLUG) {
1810 + dprintk(LOGHEAD "ioctl result = -ENODEV\n",
1811 + ir->p.name, ir->p.minor);
1815 + /* Give the plugin a chance to handle the ioctl */
1817 + result = ir->p.ioctl(inode, file, cmd, arg);
1818 + if (result != -ENOIOCTLCMD)
1821 + /* The plugin can't handle cmd */
1826 + case LIRC_GET_FEATURES:
1827 + result = put_user(ir->p.features, (unsigned long*)arg);
1829 + case LIRC_GET_REC_MODE:
1830 + if(!(ir->p.features&LIRC_CAN_REC_MASK))
1833 + result = put_user(LIRC_REC2MODE
1834 + (ir->p.features&LIRC_CAN_REC_MASK),
1835 + (unsigned long*)arg);
1837 + case LIRC_SET_REC_MODE:
1838 + if(!(ir->p.features&LIRC_CAN_REC_MASK))
1841 + result = get_user(mode, (unsigned long*)arg);
1842 + if(!result && !(LIRC_MODE2REC(mode) & ir->p.features)) {
1845 + /* FIXME: We should actually set the mode somehow
1846 + * but for now, lirc_serial doesn't support mode changin
1849 + case LIRC_GET_LENGTH:
1850 + result = put_user((unsigned long)ir->p.code_length,
1851 + (unsigned long *)arg);
1854 + result = -ENOIOCTLCMD;
1857 + dprintk(LOGHEAD "ioctl result = %d\n",
1858 + ir->p.name, ir->p.minor, result);
1866 +static ssize_t irctl_read(struct file *file,
1871 + struct irctl *ir = &irctls[MINOR(file->f_dentry->d_inode->i_rdev)];
1872 + unsigned char buf[ir->buf->chunk_size];
1873 + int ret=0, written=0;
1874 + DECLARE_WAITQUEUE(wait, current);
1876 + dprintk(LOGHEAD "read called\n", ir->p.name, ir->p.minor);
1878 + /* if the plugin has a specific read function use it instead */
1879 + if(ir->p.fops && ir->p.fops->read)
1880 + return ir->p.fops->read(file, buffer, length, ppos);
1882 + if (length % ir->buf->chunk_size) {
1883 + dprintk(LOGHEAD "read result = -EINVAL\n",
1884 + ir->p.name, ir->p.minor);
1888 + /* we add ourselves to the task queue before buffer check
1889 + * to avoid losing scan code (in case when queue is awaken somewhere
1890 + * beetwen while condition checking and scheduling)
1892 + add_wait_queue(&ir->buf->wait_poll, &wait);
1893 + current->state = TASK_INTERRUPTIBLE;
1895 + /* while we did't provide 'length' bytes, device is opened in blocking
1896 + * mode and 'copy_to_user' is happy, wait for data.
1898 + while (written < length && ret == 0) {
1899 + if (lirc_buffer_empty(ir->buf)) {
1900 + /* According to the read(2) man page, 'written' can be
1901 + * returned as less than 'length', instead of blocking
1902 + * again, returning -EWOULDBLOCK, or returning
1904 + if (written) break;
1905 + if (file->f_flags & O_NONBLOCK) {
1906 + dprintk(LOGHEAD "read result = -EWOULDBLOCK\n",
1907 + ir->p.name, ir->p.minor);
1908 + remove_wait_queue(&ir->buf->wait_poll, &wait);
1909 + current->state = TASK_RUNNING;
1910 + return -EWOULDBLOCK;
1912 + if (signal_pending(current)) {
1913 + dprintk(LOGHEAD "read result = -ERESTARTSYS\n",
1914 + ir->p.name, ir->p.minor);
1915 + remove_wait_queue(&ir->buf->wait_poll, &wait);
1916 + current->state = TASK_RUNNING;
1917 + return -ERESTARTSYS;
1920 + current->state = TASK_INTERRUPTIBLE;
1922 + lirc_buffer_read_1(ir->buf, buf);
1923 + ret = copy_to_user((void *)buffer+written, buf,
1924 + ir->buf->chunk_size);
1925 + written += ir->buf->chunk_size;
1929 + remove_wait_queue(&ir->buf->wait_poll, &wait);
1930 + current->state = TASK_RUNNING;
1932 + dprintk(LOGHEAD "read result = %s (%d)\n",
1933 + ir->p.name, ir->p.minor, ret ? "-EFAULT" : "OK", ret);
1935 + return ret ? -EFAULT : written;
1938 +static ssize_t irctl_write(struct file *file, const char *buffer,
1939 + size_t length, loff_t * ppos)
1941 + struct irctl *ir = &irctls[MINOR(file->f_dentry->d_inode->i_rdev)];
1943 + dprintk(LOGHEAD "write called\n", ir->p.name, ir->p.minor);
1945 + /* if the plugin has a specific read function use it instead */
1946 + if(ir->p.fops && ir->p.fops->write)
1947 + return ir->p.fops->write(file, buffer, length, ppos);
1953 +static struct file_operations fops = {
1955 + write: irctl_write,
1957 + ioctl: irctl_ioctl,
1959 + release: irctl_close
1962 +static int __init lirc_dev_init(void)
1966 + for (i=0; i < CONFIG_LIRC_MAX_DEV; ++i) {
1967 + init_irctl(&irctls[i]);
1970 + i = register_chrdev(IRCTL_DEV_MAJOR,
1975 + printk ("lirc_dev: device registration failed with %d\n", i);
1979 + printk("lirc_dev: IR Remote Control driver registered, at major %d \n",
1985 +static void __exit lirc_dev_exit(void)
1989 + ret = unregister_chrdev(IRCTL_DEV_MAJOR, IRCTL_DEV_NAME);
1992 + printk("lirc_dev: error in module_unregister_chrdev: %d\n",
1995 + dprintk("lirc_dev: module successfully unloaded\n");
1999 +/* ---------------------------------------------------------------------- */
2001 +/* For now dont try to use it as a static version ! */
2003 +MODULE_DESCRIPTION("LIRC base driver module");
2004 +MODULE_AUTHOR("Artur Lipowski");
2005 +MODULE_LICENSE("GPL");
2007 +EXPORT_SYMBOL(lirc_register_plugin);
2008 +EXPORT_SYMBOL(lirc_unregister_plugin);
2010 +module_init(lirc_dev_init);
2011 +module_exit(lirc_dev_exit);
2014 + * Overrides for Emacs so that we follow Linus's tabbing style.
2015 + * ---------------------------------------------------------------------------
2016 + * Local variables:
2017 + * c-basic-offset: 4
2020 diff -uprN -X dontdiff linux-2.6.5.orig/drivers/char/lirc/lirc_dev.h linux-2.6.5/drivers/char/lirc/lirc_dev.h
2021 --- linux-2.6.5.orig/drivers/char/lirc/lirc_dev.h 1970-01-01 01:00:00.000000000 +0100
2022 +++ linux-2.6.5/drivers/char/lirc/lirc_dev.h 2004-04-04 14:05:29.409628328 +0200
2025 + * LIRC base driver
2027 + * (L) by Artur Lipowski <alipowski@interia.pl>
2028 + * This code is licensed under GNU GPL
2034 +#ifndef _LINUX_LIRC_DEV_H
2035 +#define _LINUX_LIRC_DEV_H
2039 +//#define LIRC_BUFF_POWER_OF_2
2040 +#ifdef LIRC_BUFF_POWER_OF_2
2041 +#define mod(n, div) ((n) & ((div) -1))
2043 +#define mod(n, div) ((n) % (div))
2045 +#include <linux/slab.h>
2046 +#include <linux/fs.h>
2049 + wait_queue_head_t wait_poll;
2052 + unsigned char *data;
2053 + unsigned int chunk_size;
2054 + unsigned int size; /* in chunks */
2055 + unsigned int fill; /* in chunks */
2056 + int head, tail; /* in chunks */
2057 + /* Using chunks instead of bytes pretends to simplify boundary checking
2058 + * And should allow for some performance fine tunning later */
2060 +static inline int lirc_buffer_init(struct lirc_buffer *buf,
2061 + unsigned int chunk_size,
2062 + unsigned int size)
2064 + /* Adjusting size to the next power of 2 would allow for
2065 + * inconditional LIRC_BUFF_POWER_OF_2 optimization */
2066 + init_waitqueue_head(&buf->wait_poll);
2067 + spin_lock_init(&buf->lock);
2068 + buf->head = buf->tail = buf->fill = 0;
2069 + buf->chunk_size = chunk_size;
2071 + buf->data = kmalloc(size*chunk_size, GFP_KERNEL);
2072 + if (buf->data == NULL)
2074 + memset(buf->data, 0, size*chunk_size);
2077 +static inline void lirc_buffer_free(struct lirc_buffer *buf)
2081 + buf->head = buf->tail = buf->fill = 0;
2082 + buf->chunk_size = 0;
2085 +static inline int lirc_buffer_full(struct lirc_buffer *buf)
2087 + return (buf->fill >= buf->size);
2089 +static inline int lirc_buffer_empty(struct lirc_buffer *buf)
2091 + return !(buf->fill);
2093 +static inline int lirc_buffer_available(struct lirc_buffer *buf)
2095 + return (buf->size - buf->fill);
2097 +extern inline void lirc_buffer_lock(struct lirc_buffer *buf, unsigned long *flags)
2099 + spin_lock_irqsave(&buf->lock, *flags);
2101 +extern inline void lirc_buffer_unlock(struct lirc_buffer *buf, unsigned long *flags)
2103 + spin_unlock_irqrestore(&buf->lock, *flags);
2105 +static inline void _lirc_buffer_remove_1(struct lirc_buffer *buf)
2107 + buf->head = mod(buf->head+1, buf->size);
2110 +static inline void lirc_buffer_remove_1(struct lirc_buffer *buf)
2112 + unsigned long flags;
2113 + lirc_buffer_lock(buf, &flags);
2114 + _lirc_buffer_remove_1(buf);
2115 + lirc_buffer_unlock(buf, &flags);
2117 +static inline void _lirc_buffer_read_1(struct lirc_buffer *buf,
2118 + unsigned char *dest)
2120 + memcpy(dest, &buf->data[buf->head*buf->chunk_size], buf->chunk_size);
2121 + buf->head = mod(buf->head+1, buf->size);
2124 +static inline void lirc_buffer_read_1(struct lirc_buffer *buf,
2125 + unsigned char *dest)
2127 + unsigned long flags;
2128 + lirc_buffer_lock(buf, &flags);
2129 + _lirc_buffer_read_1(buf, dest);
2130 + lirc_buffer_unlock(buf, &flags);
2132 +static inline void _lirc_buffer_write_1(struct lirc_buffer *buf,
2133 + unsigned char *orig)
2135 + memcpy(&buf->data[buf->tail*buf->chunk_size], orig, buf->chunk_size);
2136 + buf->tail = mod(buf->tail+1, buf->size);
2139 +static inline void lirc_buffer_write_1(struct lirc_buffer *buf,
2140 + unsigned char *orig)
2142 + unsigned long flags;
2143 + lirc_buffer_lock(buf, &flags);
2144 + _lirc_buffer_write_1(buf, orig);
2145 + lirc_buffer_unlock(buf, &flags);
2147 +static inline void _lirc_buffer_write_n(struct lirc_buffer *buf,
2148 + unsigned char* orig, int count)
2150 + memcpy(&buf->data[buf->tail*buf->chunk_size], orig, count*buf->chunk_size);
2151 + buf->tail = mod(buf->tail+count, buf->size);
2152 + buf->fill += count;
2154 +static inline void lirc_buffer_write_n(struct lirc_buffer *buf,
2155 + unsigned char* orig, int count)
2157 + unsigned long flags;
2159 + lirc_buffer_lock(buf,&flags);
2160 + if( buf->head > buf->tail ) space1 = buf->head - buf->tail;
2161 + else space1 = buf->size - buf->tail;
2163 + if( count > space1 )
2165 + _lirc_buffer_write_n(buf, orig, space1);
2166 + _lirc_buffer_write_n(buf, orig+(space1*buf->chunk_size), count-space1);
2169 + _lirc_buffer_write_n(buf, orig, count);
2170 + lirc_buffer_unlock(buf, &flags);
2179 + unsigned long features;
2181 + int (*add_to_buf) (void* data, struct lirc_buffer* buf);
2182 + wait_queue_head_t* (*get_queue) (void* data);
2183 + struct lirc_buffer *rbuf;
2184 + int (*set_use_inc) (void* data);
2185 + void (*set_use_dec) (void* data);
2186 + int (*ioctl) (struct inode *,struct file *,unsigned int, unsigned long);
2187 + struct file_operations *fops;
2190 + * this string will be used for logs
2193 + * indicates minor device (/dev/lircd) number for registered plugin
2194 + * if caller fills it with negative value, then the first free minor
2195 + * number will be used (if available)
2198 + * length of the remote control key code expressed in bits
2199 + * if code_length > 8 then many bytes are returned through the device read
2200 + * in such situation get_key should return key code values starting
2201 + * from most significant byte (device read will preseve this order)
2202 + * in addition if code_length > 8 then get_key will be called
2203 + * several (ceil(code_length/8)) times in one pool pass (or after task queue
2204 + * awake) key_no parameter denotes number of the requested byte (0 means first
2208 + * sample_rate equal to 0 means that no polling will be performed and add_to_buf
2209 + * will be triggered by external events (through task queue returned by
2213 + * it may point to any plugin data and this pointer will be passed to all
2214 + * callback functions
2217 + * add_to_buf will be called after specified period of the time or triggered
2218 + * by the external event, this behavior depends on value of the sample_rate
2219 + * this function will be called in user context. this routine should return 0
2220 + * if data was added to the buffer and -ENODATA if none was available. this should
2221 + * add some number of bits evenly divisible by code_length to the buffer
2224 + * this callback should return a pointer to the task queue which will be used
2225 + * for external event waiting
2228 + * if not NULL, it will be used as a read buffer, you will have to write to
2229 + * the buffer by other means, like irq's (see also lirc_serial.c).
2232 + * set_use_inc will be called after device is opened
2235 + * set_use_dec will be called after device is closed
2238 + * Some ioctl's can be directly handled by lirc_dev but will be forwared here
2239 + * if not NULL and only handled if it returns -ENOIOCTLCMD (see also
2243 + * file_operations for drivers which don't fit the current plugin model.
2247 +/* following functions can be called ONLY from user context
2249 + * returns negative value on error or minor number
2250 + * of the registered device if success
2251 + * contens of the structure pointed by p is copied
2253 +extern int lirc_register_plugin(struct lirc_plugin *p);
2255 +/* returns negative value on error or 0 if success
2257 +extern int lirc_unregister_plugin(int minor);
2261 diff -uprN -X dontdiff linux-2.6.5.orig/drivers/char/lirc/lirc_gpio.c linux-2.6.5/drivers/char/lirc/lirc_gpio.c
2262 --- linux-2.6.5.orig/drivers/char/lirc/lirc_gpio.c 1970-01-01 01:00:00.000000000 +0100
2263 +++ linux-2.6.5/drivers/char/lirc/lirc_gpio.c 2004-04-04 14:05:29.411628024 +0200
2266 + * Remote control driver for the TV-card
2267 + * key codes are obtained from GPIO port
2269 + * (L) by Artur Lipowski <alipowski@interia.pl>
2270 + * patch for the AverMedia by Santiago Garcia Mantinan <manty@i.am>
2271 + * and Christoph Bartelmus <lirc@bartelmus.de>
2272 + * patch for the BestBuy by Miguel Angel Alvarez <maacruz@navegalia.com>
2273 + * patch for the Winfast TV2000 by Juan Toledo
2274 + * <toledo@users.sourceforge.net>
2275 + * patch for the I-O Data GV-BCTV5/PCI by Jens C. Rasmussen
2276 + * <jens.rasmussen@ieee.org>
2278 + * This program is free software; you can redistribute it and/or modify
2279 + * it under the terms of the GNU General Public License as published by
2280 + * the Free Software Foundation; either version 2 of the License, or
2281 + * (at your option) any later version.
2283 + * This program is distributed in the hope that it will be useful,
2284 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2285 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2286 + * GNU General Public License for more details.
2288 + * You should have received a copy of the GNU General Public License
2289 + * along with this program; if not, write to the Free Software
2290 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2296 +#include <linux/version.h>
2298 +#include <linux/module.h>
2299 +#include <linux/kmod.h>
2300 +#include <linux/sched.h>
2301 +#include <linux/errno.h>
2302 +#include <linux/init.h>
2303 +#include <linux/moduleparam.h>
2305 +#include "../../media/video/bttv.h"
2306 +#include "../../media/video/bttvp.h"
2308 +#include "lirc_dev.h"
2310 +static int debug = 0;
2311 +static int card = 0;
2312 +static int minor = -1;
2313 +static int bttv_id = BTTV_UNKNOWN;
2314 +static unsigned long gpio_mask = 0;
2315 +static unsigned long gpio_enable = 0;
2316 +static unsigned long gpio_lock_mask = 0;
2317 +static unsigned long gpio_xor_mask = 0;
2318 +static unsigned int soft_gap = 0;
2319 +static unsigned char sample_rate = 10;
2321 +MODULE_PARM(debug,"i");
2322 +MODULE_PARM(card,"i");
2323 +MODULE_PARM(minor,"i");
2324 +MODULE_PARM(gpio_mask,"l");
2325 +MODULE_PARM(gpio_lock_mask,"l");
2326 +MODULE_PARM(gpio_xor_mask,"l");
2327 +MODULE_PARM(soft_gap,"i");
2328 +MODULE_PARM(sample_rate,"b");
2329 +MODULE_PARM(bttv_id,"i");
2332 +#define dprintk if (debug) printk
2337 + unsigned long gpio_mask;
2338 + unsigned long gpio_enable;
2339 + unsigned long gpio_lock_mask;
2340 + unsigned long gpio_xor_mask;
2341 + unsigned int soft_gap;
2342 + unsigned char sample_rate;
2343 + unsigned char code_length;
2346 +static struct rcv_info rcv_infos[] = {
2347 + {BTTV_UNKNOWN, 0, 0, 0, 0, 0, 0, 1, 0},
2348 + {BTTV_PXELVWPLTVPAK, 0, 0x00003e00, 0, 0x0010000, 0, 0, 15, 32},
2349 + {BTTV_PXELVWPLTVPRO, 0, 0x00001f00, 0, 0x0008000, 0, 500, 12, 32},
2350 + {BTTV_PV_BT878P_9B, 0, 0x00001f00, 0, 0x0008000, 0, 500, 12, 32},
2351 + {BTTV_PV_BT878P_PLUS, 0, 0x00001f00, 0, 0x0008000, 0, 500, 12, 32},
2352 + {BTTV_AVERMEDIA, 0, 0x00f88000, 0, 0x0010000, 0x00010000, 0, 10, 32},
2353 + {BTTV_AVPHONE98, 0x00011461, 0x003b8000, 0x00004000, 0x0800000, 0x00800000, 0, 10, 0}, /*mapped to Capture98*/
2354 + {BTTV_AVERMEDIA98, 0x00021461, 0x003b8000, 0x00004000, 0x0800000, 0x00800000, 0, 10, 0}, /*mapped to Capture98*/
2355 + {BTTV_AVPHONE98, 0x00031461, 0x00f88000, 0, 0x0010000, 0x00010000, 0, 10, 32}, /*mapped to Phone98*/
2356 + /* is this one correct? */
2357 + {BTTV_AVERMEDIA98, 0x00041461, 0x00f88000, 0, 0x0010000, 0x00010000, 0, 10, 32}, /*mapped to Phone98*/
2358 + /* work-around for VDOMATE */
2359 + {BTTV_AVERMEDIA98, 0x03001461, 0x00f88000, 0, 0x0010000, 0x00010000, 0, 10, 32}, /*mapped to Phone98*/
2360 + /* reported by Danijel Korzinek, AVerTV GOw/FM */
2361 + {BTTV_AVERMEDIA98, 0x00000000, 0x00f88000, 0, 0x0010000, 0x00010000, 0, 10, 32}, /*mapped to Phone98*/
2362 + {BTTV_CHRONOS_VS2, 0, 0x000000f8, 0, 0x0000100, 0, 0, 20, 0},
2363 + /* CPH031 and CPH033 cards (?) */
2364 + /* MIRO was just a work-around */
2365 + {BTTV_MIRO, 0, 0x00001f00, 0, 0x0004000, 0, 0, 10, 32},
2366 + {BTTV_DYNALINK, 0, 0x00001f00, 0, 0x0004000, 0, 0, 10, 32},
2367 + {BTTV_WINVIEW_601, 0, 0x00001f00, 0, 0x0004000, 0, 0, 0, 32},
2369 + {BTTV_KWORLD, 0, 0x00007f00, 0, 0x0004000, 0, 0, 12, 32},
2371 + /* just a guess */
2372 + {BTTV_MAGICTVIEW061, 0, 0x0028e000, 0, 0x0020000, 0, 0, 20, 32},
2373 + {BTTV_MAGICTVIEW063, 0, 0x0028e000, 0, 0x0020000, 0, 0, 20, 32},
2374 + {BTTV_PHOEBE_TVMAS, 0, 0x0028e000, 0, 0x0020000, 0, 0, 20, 32},
2375 +#ifdef BTTV_BESTBUY_EASYTV2
2376 + {BTTV_BESTBUY_EASYTV, 0, 0x00007F00, 0, 0x0004000, 0, 0, 10, 8},
2377 + {BTTV_BESTBUY_EASYTV2, 0, 0x00007F00, 0, 0x0008000, 0, 0, 10, 8},
2379 + /* lock_mask probably also 0x100, or maybe it is 0x0 for all others !?! */
2380 + {BTTV_FLYVIDEO, 0, 0x000000f8, 0, 0, 0, 0, 0, 42},
2381 + {BTTV_FLYVIDEO_98, 0, 0x000000f8, 0, 0x0000100, 0, 0, 0, 42},
2382 + {BTTV_TYPHOON_TVIEW, 0, 0x000000f8, 0, 0x0000100, 0, 0, 0, 42},
2383 +#ifdef BTTV_FLYVIDEO_98FM
2384 + /* smorar@alfonzo.smuts.uct.ac.za */
2385 + {BTTV_FLYVIDEO_98FM, 0, 0x000000f8, 0, 0x0000100, 0, 0, 0, 42},
2387 + /* The Leadtek WinFast TV 2000 XP card (id 0x6606107d) uses an
2388 + * extra gpio bit compared to the original TV 2000 card (id
2389 + * 0x217d6606); as the bttv-0.7.100 driver does not
2390 + * distinguish between the two cards, we enable the extra bit
2391 + * based on the card id: */
2392 + {BTTV_WINFAST2000, 0x6606107d, 0x000008f8, 0, 0x0000100, 0, 0, 0, 32},
2394 + {BTTV_WINFAST2000, 0, 0x000000f8, 0, 0x0000100, 0, 0, 0, 32},
2395 +#ifdef BTTV_GVBCTV5PCI
2396 + {BTTV_GVBCTV5PCI, 0, 0x00f0b000, 0, 0, 0, 0, 20, 8},
2400 +static unsigned char code_length = 0;
2401 +static unsigned char code_bytes = 1;
2403 +#define MAX_BYTES 8
2406 +#define LOGHEAD "lirc_gpio (%d): "
2408 +/* how many bits GPIO value can be shifted right before processing
2409 + * it is computed from the value of gpio_mask_parameter
2411 +static unsigned char gpio_pre_shift = 0;
2414 +static inline int reverse(int data, int bits)
2419 + for (c=0,i=0; i<bits; i++) {
2420 + c |= (((data & (1<<i)) ? 1:0)) << (bits-1-i);
2426 +static int build_key(unsigned long gpio_val, unsigned char codes[MAX_BYTES])
2428 + unsigned long mask = gpio_mask;
2429 + unsigned char shift = 0;
2431 + dprintk(LOGHEAD "gpio_val is %lx\n",card,(unsigned long) gpio_val);
2433 + gpio_val ^= gpio_xor_mask;
2435 + if (gpio_lock_mask && (gpio_val & gpio_lock_mask)) {
2441 + case BTTV_AVERMEDIA98:
2442 + if (bttv_write_gpio(card, gpio_enable, gpio_enable)) {
2443 + dprintk(LOGHEAD "cannot write to GPIO\n", card);
2446 + if (bttv_read_gpio(card, &gpio_val)) {
2447 + dprintk(LOGHEAD "cannot read GPIO\n", card);
2450 + if (bttv_write_gpio(card, gpio_enable, 0)) {
2451 + dprintk(LOGHEAD "cannot write to GPIO\n", card);
2459 + /* extract bits from "raw" GPIO value using gpio_mask */
2461 + gpio_val >>= gpio_pre_shift;
2464 + codes[0] |= (gpio_val & 1u) << shift++;
2470 + dprintk(LOGHEAD "code is %lx\n",card,(unsigned long) codes[0]);
2473 + case BTTV_AVERMEDIA:
2474 + codes[2] = (codes[0]<<2)&0xff;
2475 + codes[3] = (~codes[2])&0xff;
2479 + case BTTV_AVPHONE98:
2480 + codes[2] = ((codes[0]&(~0x1))<<2)&0xff;
2481 + codes[3] = (~codes[2])&0xff;
2482 + if (codes[0]&0x1) {
2490 + case BTTV_AVERMEDIA98:
2492 + case BTTV_FLYVIDEO:
2493 + case BTTV_FLYVIDEO_98:
2494 + case BTTV_TYPHOON_TVIEW:
2495 +#ifdef BTTV_FLYVIDEO_98FM
2496 + case BTTV_FLYVIDEO_98FM:
2498 + codes[4]=codes[0]<<3;
2499 + codes[5]=((~codes[4])&0xff);
2506 + case BTTV_MAGICTVIEW061:
2507 + case BTTV_MAGICTVIEW063:
2508 + case BTTV_PHOEBE_TVMAS:
2509 + codes[0] = (codes[0]&0x01)
2510 + |((codes[0]&0x02)<<1)
2511 + |((codes[0]&0x04)<<2)
2512 + |((codes[0]&0x08)>>2)
2513 + |((codes[0]&0x10)>>1);
2516 + case BTTV_DYNALINK:
2517 + case BTTV_PXELVWPLTVPAK:
2518 + case BTTV_PXELVWPLTVPRO:
2519 + case BTTV_PV_BT878P_9B:
2520 + case BTTV_PV_BT878P_PLUS:
2524 + codes[2] = reverse(codes[0],8);
2525 + codes[3] = (~codes[2])&0xff;
2530 + /* derived from e-tech config file */
2531 + /* 26 + 16 bits */
2532 + /* won't apply it until it's confirmed with a fly98 */
2533 + case BTTV_FLYVIDEO_98:
2534 + case BTTV_FLYVIDEO_98FM:
2535 + codes[4]=codes[0]<<3;
2536 + codes[5]=(~codes[4])&0xff;
2544 + case BTTV_WINFAST2000:
2545 + /* shift extra bit */
2546 + codes[0] = (codes[0]&0x1f) | ((codes[0]&0x20) << 1);
2547 + case BTTV_WINVIEW_601:
2548 + codes[2] = reverse(codes[0],8);
2549 + codes[3] = (~codes[2])&0xff;
2560 +/* add_to_buf - copy a code to the buffer */
2561 +static int add_to_buf(void* data, struct lirc_buffer* buf)
2563 + static unsigned long next_time = 0;
2564 + static unsigned char prev_codes[MAX_BYTES];
2565 + unsigned long code = 0;
2566 + unsigned char cur_codes[MAX_BYTES];
2568 + if (bttv_read_gpio(card, &code)) {
2569 + dprintk(LOGHEAD "cannot read GPIO\n", card);
2573 + if (build_key(code, cur_codes)) {
2578 + /* XXX this should be double checked; i think the soft_gap
2579 + * here is supposed to track repeats, which is why i save off
2580 + * the prev_codes, but i'm not certain this is correct
2583 + if (!memcmp(prev_codes, cur_codes, code_bytes) &&
2584 + jiffies < next_time) {
2587 + next_time = jiffies + soft_gap;
2589 + memcpy( prev_codes, cur_codes, code_bytes );
2591 + lirc_buffer_write_1( buf, cur_codes );
2596 +static int set_use_inc(void* data)
2598 + try_module_get(THIS_MODULE);
2602 +static void set_use_dec(void* data)
2604 + module_put(THIS_MODULE);
2607 +static wait_queue_head_t* get_queue(void* data)
2609 + return bttv_get_gpio_queue(card);
2612 +static struct lirc_plugin plugin = {
2613 + .name = "lirc_gpio ",
2614 + .add_to_buf = add_to_buf,
2615 + .get_queue = get_queue,
2616 + .set_use_inc = set_use_inc,
2617 + .set_use_dec = set_use_dec,
2623 +int gpio_remote_init(void)
2626 + unsigned int mask;
2628 + /* "normalize" gpio_mask
2629 + * this means shift it right until first bit is set
2631 + while (!(gpio_mask & 1u)) {
2636 + if (code_length) {
2637 + plugin.code_length = code_length;
2639 + /* calculate scan code length in bits if needed */
2640 + plugin.code_length = 1;
2641 + mask = gpio_mask >> 1;
2644 + plugin.code_length++;
2650 + code_bytes = (plugin.code_length/8) + (plugin.code_length%8 ? 1 : 0);
2651 + if (MAX_BYTES < code_bytes) {
2652 + printk (LOGHEAD "scan code too long (%d bytes)\n",
2653 + minor, code_bytes);
2657 + if (gpio_enable) {
2658 + if(bttv_gpio_enable(card, gpio_enable, gpio_enable)) {
2659 + printk(LOGHEAD "gpio_enable failure\n", minor);
2665 + /* translate ms to jiffies */
2666 + soft_gap = (soft_gap*HZ) / 1000;
2668 + plugin.minor = minor;
2669 + plugin.sample_rate = sample_rate;
2671 + ret = lirc_register_plugin(&plugin);
2674 + printk (LOGHEAD "device registration failed with %d\n",
2680 + printk(LOGHEAD "driver registered\n", minor);
2685 +static int __init lirc_gpio_init(void)
2687 + int type,cardid,card_type;
2689 + if (CONFIG_LIRC_MAX_DEV < minor) {
2690 + printk("lirc_gpio: parameter minor (%d) must be less than %d!\n",
2691 + minor, CONFIG_LIRC_MAX_DEV-1);
2695 + request_module("bttv");
2697 + /* if gpio_mask not zero then use module parameters
2698 + * instead of autodetecting TV card
2701 + if (sample_rate!=0 && (2 > sample_rate || 50 < sample_rate)) {
2702 + printk(LOGHEAD "parameter sample_rate "
2703 + "must be beetween 2 and 50!\n", minor);
2707 + if (sample_rate!=0 && soft_gap &&
2708 + ((2000/sample_rate) > soft_gap || 1000 < soft_gap)) {
2709 + printk(LOGHEAD "parameter soft_gap "
2710 + "must be beetween %d and 1000!\n",
2711 + minor, 2000/sample_rate);
2715 + if(bttv_get_cardinfo(card,&type,&cardid)==-1) {
2716 + printk(LOGHEAD "could not get card type\n", minor);
2718 + printk(LOGHEAD "card type 0x%x, id 0x%x\n",minor,
2721 + if (type == BTTV_UNKNOWN) {
2722 + printk(LOGHEAD "cannot detect TV card nr %d!\n",
2726 + for (card_type = 1;
2727 + card_type < sizeof(rcv_infos)/sizeof(struct rcv_info);
2729 + if (rcv_infos[card_type].bttv_id == type &&
2730 + (rcv_infos[card_type].card_id == 0 ||
2731 + rcv_infos[card_type].card_id == cardid)) {
2732 + bttv_id = rcv_infos[card_type].bttv_id;
2733 + gpio_mask = rcv_infos[card_type].gpio_mask;
2734 + gpio_enable = rcv_infos[card_type].gpio_enable;
2735 + gpio_lock_mask = rcv_infos[card_type].gpio_lock_mask;
2736 + gpio_xor_mask = rcv_infos[card_type].gpio_xor_mask;
2737 + soft_gap = rcv_infos[card_type].soft_gap;
2738 + sample_rate = rcv_infos[card_type].sample_rate;
2739 + code_length = rcv_infos[card_type].code_length;
2743 + if (type==BTTV_AVPHONE98 && cardid==0x00011461) {
2744 + bttv_id = BTTV_AVERMEDIA98;
2746 + if (type==BTTV_AVERMEDIA98 && cardid==0x00041461) {
2747 + bttv_id = BTTV_AVPHONE98;
2749 + if (type==BTTV_AVERMEDIA98 && cardid==0x03001461) {
2750 + bttv_id = BTTV_AVPHONE98;
2752 + if (type==BTTV_AVERMEDIA98 && cardid==0x00000000) {
2753 + bttv_id = BTTV_AVPHONE98;
2755 + if (card_type == sizeof(rcv_infos)/sizeof(struct rcv_info)) {
2756 + printk(LOGHEAD "TV card type 0x%x not supported!\n",
2762 + request_module("lirc_dev");
2764 + return gpio_remote_init();
2767 +void __exit lirc_gpio_exit(void)
2771 + ret = lirc_unregister_plugin(minor);
2774 + printk(LOGHEAD "error in lirc_unregister_minor: %d\n"
2775 + "Trying again...\n",
2778 + current->state = TASK_INTERRUPTIBLE;
2779 + schedule_timeout(HZ);
2781 + ret = lirc_unregister_plugin(minor);
2784 + printk(LOGHEAD "error in lirc_unregister_minor: %d!!!\n",
2790 + dprintk(LOGHEAD "module successfully unloaded\n", minor);
2793 +MODULE_DESCRIPTION("Driver module for remote control (data from bt848 GPIO port)");
2794 +MODULE_AUTHOR("Artur Lipowski");
2795 +MODULE_LICENSE("GPL");
2798 + module_init(lirc_gpio_init);
2800 + late_initcall(lirc_gpio_init);
2802 +module_exit(lirc_gpio_exit);
2805 + * Overrides for Emacs so that we follow Linus's tabbing style.
2806 + * ---------------------------------------------------------------------------
2807 + * Local variables:
2808 + * c-basic-offset: 8
2811 diff -uprN -X dontdiff linux-2.6.5.orig/drivers/char/lirc/lirc_i2c.c linux-2.6.5/drivers/char/lirc/lirc_i2c.c
2812 --- linux-2.6.5.orig/drivers/char/lirc/lirc_i2c.c 1970-01-01 01:00:00.000000000 +0100
2813 +++ linux-2.6.5/drivers/char/lirc/lirc_i2c.c 2004-04-04 14:05:29.413627720 +0200
2818 + * i2c IR lirc plugin for Hauppauge and Pixelview cards - new 2.8.x i2c stack
2820 + * Copyright (c) 2000 Gerd Knorr <kraxel@goldbach.in-berlin.de>
2821 + * modified for PixelView (BT878P+W/FM) by
2822 + * Michal Kochanowicz <mkochano@pld.org.pl>
2823 + * Christoph Bartelmus <lirc@bartelmus.de>
2824 + * modified for KNC ONE TV Station/Anubis Typhoon TView Tuner by
2825 + * Ulrich Mueller <ulrich.mueller42@web.de>
2826 + * modified for Asus TV-Box and Creative/VisionTek BreakOut-Box by
2827 + * Stefan Jahn <stefan@lkcc.org>
2828 + * modified for Linux 2.6 by
2829 + * Jeffrey Clark <jeff@clarkmania.com>
2831 + * parts are cut&pasted from the old lirc_haup.c driver
2833 + * This program is free software; you can redistribute it and/or modify
2834 + * it under the terms of the GNU General Public License as published by
2835 + * the Free Software Foundation; either version 2 of the License, or
2836 + * (at your option) any later version.
2838 + * This program is distributed in the hope that it will be useful,
2839 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2840 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2841 + * GNU General Public License for more details.
2843 + * You should have received a copy of the GNU General Public License
2844 + * along with this program; if not, write to the Free Software
2845 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2849 +#include <linux/module.h>
2850 +#include <linux/kmod.h>
2851 +#include <linux/kernel.h>
2852 +#include <linux/sched.h>
2853 +#include <linux/string.h>
2854 +#include <linux/timer.h>
2855 +#include <linux/delay.h>
2856 +#include <linux/errno.h>
2857 +#include <linux/slab.h>
2858 +#include <linux/init.h>
2859 +#include <linux/moduleparam.h>
2861 +#include <linux/i2c.h>
2862 +#include <linux/i2c-algo-bit.h>
2863 +#include <asm/semaphore.h>
2865 +#include "../../media/video/bttv.h"
2867 +#include "lirc_dev.h"
2869 +static unsigned short normal_i2c[] = { 0x1a, 0x18, 0x4b, 0x64, 0x30, 0x21, 0x23, I2C_CLIENT_END };
2870 +static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
2871 +static unsigned short probe[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
2872 +static unsigned short probe_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
2873 +static unsigned short ignore[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
2874 +static unsigned short ignore_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
2875 +static unsigned short force[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
2877 +static struct i2c_client_address_data addr_data = {
2878 + .normal_i2c = normal_i2c,
2879 + .normal_i2c_range = normal_i2c_range,
2881 + .probe_range = probe_range,
2883 + .ignore_range = ignore_range,
2888 + struct lirc_plugin lirc;
2889 + struct i2c_client client;
2891 + unsigned char b[3];
2892 + unsigned char bits;
2893 + unsigned char flag;
2896 +/* ----------------------------------------------------------------------- */
2897 +/* insmod parameters */
2899 +static int debug = 0; /* debug output */
2900 +static int minor = -1; /* minor number */
2902 +MODULE_PARM(debug,"i");
2903 +MODULE_PARM(minor,"i");
2905 +MODULE_DESCRIPTION("Infrared receiver driver for Hauppauge and Pixelview cards (i2c stack)");
2906 +MODULE_AUTHOR("Gerd Knorr, Michal Kochanowicz, Christoph Bartelmus, Ulrich Mueller, Stefan Jahn, Jeffrey Clark");
2907 +MODULE_LICENSE("GPL");
2909 +#define dprintk if (debug) printk
2911 +/* ----------------------------------------------------------------------- */
2913 +#define DRIVER_NAME "lirc_i2c"
2914 +#define DEVICE_NAME DRIVER_NAME
2916 +/* ----------------------------------------------------------------------- */
2918 +static inline int reverse(int data, int bits)
2923 + for (c=0,i=0; i<bits; i++) {
2924 + c |= (((data & (1<<i)) ? 1:0)) << (bits-1-i);
2930 +static int add_to_buf_pcf8574(void* data, struct lirc_buffer* buf)
2932 + struct i2c_ir *ir = data;
2934 + unsigned char all, mask;
2935 + unsigned char key;
2937 + /* compute all valid bits (key code + pressed/release flag) */
2938 + all = ir->bits | ir->flag;
2940 + /* save IR writable mask bits */
2941 + mask = i2c_smbus_read_byte(&ir->client) & ~all;
2943 + /* send bit mask */
2944 + rc = i2c_smbus_write_byte(&ir->client, (0xff & all) | mask);
2946 + /* receive scan code */
2947 + rc = i2c_smbus_read_byte(&ir->client);
2950 + /* should this return -EIO? */
2951 + dprintk(DEVICE_NAME ": %s read error\n", ir->c.name);
2955 + /* drop duplicate polls */
2956 + if (ir->b[0] == (rc & all)) {
2959 + ir->b[0] = rc & all;
2961 + dprintk(DRIVER_NAME ": %s key 0x%02X %s\n",
2962 + ir->client.name, rc & ir->bits,
2963 + (rc & ir->flag) ? "released" : "pressed");
2965 + if (rc & ir->flag) {
2966 + /* ignore released buttons */
2970 + /* set valid key code */
2971 + key = rc & ir->bits;
2972 + lirc_buffer_write_1( buf, &key );
2976 +static int add_to_buf_haup(void* data, struct lirc_buffer* buf)
2978 + struct i2c_ir *ir = data;
2979 + unsigned char keybuf[3];
2981 + unsigned char codes[2];
2983 + /* poll IR chip */
2984 + if (3 == i2c_master_recv(&ir->c,keybuf,3)) {
2985 + ir->b[0] = keybuf[0];
2986 + ir->b[1] = keybuf[1];
2987 + ir->b[2] = keybuf[2];
2989 + dprintk(DRIVER_NAME ": read error\n");
2990 + /* keep last successfull read buffer */
2993 + /* key pressed ? */
2994 + if ((ir->b[0] & 0x80) == 0)
2997 + dprintk(DRIVER_NAME ": key (0x%02x/0x%02x)\n",
2998 + ir->b[0], ir->b[1]);
3000 + /* look what we have */
3001 + code = (((__u16)ir->b[0]&0x7f)<<6) | (ir->b[1]>>2);
3003 + codes[0] = (code >> 8) & 0xff;
3004 + codes[1] = code & 0xff;
3007 + lirc_buffer_write_1( buf, codes );
3011 +static int add_to_buf_pixelview(void* data, struct lirc_buffer* buf)
3013 + struct i2c_ir *ir = data;
3014 + unsigned char key;
3016 + /* poll IR chip */
3017 + if (1 != i2c_master_recv(&ir->c,&key,1)) {
3018 + dprintk(DRIVER_NAME ": read error\n");
3022 + dprintk(KERN_DEBUG DEVICE_NAME ": key %02x\n", key);
3025 + lirc_buffer_write_1( buf, &key );
3030 +static int add_to_buf_pv951(void* data, struct lirc_buffer* buf)
3032 + struct i2c_ir *ir = data;
3033 + unsigned char key;
3034 + unsigned char codes[4];
3036 + /* poll IR chip */
3037 + if (1 != i2c_master_recv(&ir->c,&key,1)) {
3038 + dprintk(DRIVER_NAME ": read error\n");
3044 + dprintk(KERN_DEBUG DEVICE_NAME ": key %02x\n", key);
3048 + codes[1] = reverse(key,8);
3049 + codes[0] = (~codes[2])&0xff;
3051 + lirc_buffer_write_1( buf, codes );
3055 +static int add_to_buf_knc1(void *data, struct lirc_buffer* buf)
3057 + static unsigned char last_key = 0xFF;
3058 + struct i2c_ir *ir = data;
3059 + unsigned char key;
3061 + /* poll IR chip */
3062 + if (1 != i2c_master_recv(&ir->c,&key,1)) {
3063 + dprintk(DRIVER_NAME ": read error\n");
3067 + /* it seems that 0xFE indicates that a button is still hold
3068 + down, while 0xFF indicates that no button is hold
3069 + down. 0xFE sequences are sometimes interrupted by 0xFF */
3071 + dprintk(KERN_DEBUG DEVICE_NAME ": key %02x\n", key);
3076 + if ( key == 0xFE )
3080 + lirc_buffer_write_1( buf, &key );
3085 +static int set_use_inc(void* data)
3087 + try_module_get(THIS_MODULE);
3091 +static void set_use_dec(void* data)
3093 + module_put(THIS_MODULE);
3096 +static struct lirc_plugin lirc_template = {
3097 + .name = "lirc_i2c",
3098 + .set_use_inc = set_use_inc,
3099 + .set_use_dec = set_use_dec
3102 +/* ----------------------------------------------------------------------- */
3104 +static int lirc_i2c_attach(struct i2c_adapter *adap, int addr, int kind);
3105 +static int lirc_i2c_detach(struct i2c_client *client);
3106 +static int lirc_i2c_probe(struct i2c_adapter *adap);
3108 +static struct i2c_driver driver = {
3109 + .owner = THIS_MODULE,
3110 + .name = DRIVER_NAME,
3111 + .id = I2C_DRIVERID_EXP3, /* FIXME */
3112 + .flags = I2C_DF_NOTIFY,
3113 + .attach_adapter = lirc_i2c_probe,
3114 + .detach_client = lirc_i2c_detach,
3117 +static struct i2c_client client_template =
3119 + I2C_DEVNAME("(unset)"),
3120 + .flags = I2C_CLIENT_ALLOW_USE,
3124 +static int lirc_i2c_attach(struct i2c_adapter *adap, int addr, int kind)
3126 + struct i2c_ir *ir;
3129 + client_template.adapter = adap;
3130 + client_template.addr = addr;
3132 + if (NULL == (ir = kmalloc(sizeof(struct i2c_ir),GFP_KERNEL)))
3134 + memset(ir,0,sizeof(struct i2c_ir));
3135 + memcpy(&ir->client,&client_template,sizeof(struct i2c_client));
3136 + memcpy(&ir->lirc,&lirc_template,sizeof(struct lirc_plugin));
3138 + ir->lirc.data = ir;
3139 + ir->lirc.minor = minor;
3142 + i2c_set_clientdata(&ir->client,ir);
3147 + strncpy(ir->client.name, "Pixelview IR", I2C_NAME_SIZE);
3148 + ir->lirc.code_length = 8;
3149 + ir->lirc.sample_rate = 10;
3150 + ir->lirc.add_to_buf = add_to_buf_pixelview;
3153 + strncpy(ir->client.name,"PV951 IR", I2C_NAME_SIZE);
3154 + ir->lirc.code_length = 32;
3155 + ir->lirc.sample_rate = 10;
3156 + ir->lirc.add_to_buf = add_to_buf_pv951;
3160 + strncpy(ir->client.name,"Hauppauge IR", I2C_NAME_SIZE);
3161 + ir->lirc.code_length = 13;
3162 + ir->lirc.sample_rate = 6;
3163 + ir->lirc.add_to_buf = add_to_buf_haup;
3166 + strncpy(ir->client.name,"KNC ONE IR", I2C_NAME_SIZE);
3167 + ir->lirc.code_length = 8;
3168 + ir->lirc.sample_rate = 10;
3169 + ir->lirc.add_to_buf = add_to_buf_knc1;
3173 + strncpy(ir->client.name,"TV-Box IR", I2C_NAME_SIZE);
3174 + ir->lirc.code_length = 8;
3175 + ir->lirc.sample_rate = 10;
3176 + ir->lirc.add_to_buf = add_to_buf_pcf8574;
3177 + ir->bits = ir->client.flags & 0xff;
3178 + ir->flag = (ir->client.flags >> 8) & 0xff;
3182 + /* shouldn't happen */
3183 + dprintk(DRIVER_NAME ": unknown i2c address (0x%02x)?\n",addr);
3187 + dprintk(DRIVER_NAME ": chip found @ 0x%02x (%s)\n",addr,
3190 + /* register device */
3191 + i2c_attach_client(&ir->client);
3193 + if((ret = lirc_register_plugin(&ir->lirc))) {
3194 + dprintk(DRIVER_NAME ": device registration failed with %d\n",
3200 + ir->lirc.minor = ret;
3201 + dprintk(DRIVER_NAME ": driver registered\n");
3206 +static int lirc_i2c_detach(struct i2c_client *client)
3208 + struct i2c_ir *ir = i2c_get_clientdata(client);
3211 + /* unregister device */
3212 + if ((err = lirc_unregister_plugin(ir->lirc.minor))) {
3213 + dprintk(DRIVER_NAME ": lirc unregister failed\n");
3216 + dprintk(DRIVER_NAME ": lirc unregister successful\n");
3219 + if ((err = i2c_detach_client(&ir->client))) {
3220 + dprintk(DRIVER_NAME ": i2c detach failed\n");
3223 + dprintk(DRIVER_NAME ": i2c detach successful\n");
3231 +static int lirc_i2c_probe(struct i2c_adapter *adap) {
3232 + dprintk(DRIVER_NAME ": starting probe for adapter %s (0x%x)\n",
3233 + adap->name, adap->id);
3234 + return i2c_probe(adap, &addr_data, lirc_i2c_attach);
3237 +static int __init lirc_i2c_init(void)
3239 + dprintk(DRIVER_NAME ": init\n");
3240 + request_module("bttv");
3241 + request_module("lirc_dev");
3242 + return i2c_add_driver(&driver);
3245 +static void __exit lirc_i2c_exit(void)
3247 + dprintk(DRIVER_NAME ": exit\n");
3248 + i2c_del_driver(&driver);
3251 +module_init(lirc_i2c_init);
3252 +module_exit(lirc_i2c_exit);
3253 diff -uprN -X dontdiff linux-2.6.5.orig/drivers/char/lirc/lirc_it87.c linux-2.6.5/drivers/char/lirc/lirc_it87.c
3254 --- linux-2.6.5.orig/drivers/char/lirc/lirc_it87.c 1970-01-01 01:00:00.000000000 +0100
3255 +++ linux-2.6.5/drivers/char/lirc/lirc_it87.c 2004-04-04 14:05:29.416627264 +0200
3258 + * LIRC driver for ITE IT8712/IT8705 CIR port
3260 + * Copyright (C) 2001 Hans-Günter Lütke Uphues <hg_lu@web.de>
3262 + * This program is free software; you can redistribute it and/or
3263 + * modify it under the terms of the GNU General Public License as
3264 + * published by the Free Software Foundation; either version 2 of the
3265 + * License, or (at your option) any later version.
3267 + * This program is distributed in the hope that it will be useful, but
3268 + * WITHOUT ANY WARRANTY; without even the implied warranty of
3269 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3270 + * General Public License for more details.
3272 + * You should have received a copy of the GNU General Public License
3273 + * along with this program; if not, write to the Free Software
3274 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
3277 + * ITE IT8705 and IT8712(not tested) CIR-port support for lirc based
3278 + * via cut and paste from lirc_sir.c (C) 2000 Milan Pikula
3280 + * Attention: Sendmode only tested with debugging logs
3282 + * 2001/02/27 Christoph Bartelmus <lirc@bartelmus.de> :
3283 + * reimplemented read function
3287 +#include <linux/version.h>
3288 +#include <linux/module.h>
3290 +#include <linux/config.h>
3293 +#include <linux/sched.h>
3294 +#include <linux/errno.h>
3295 +#include <linux/signal.h>
3296 +#include <linux/fs.h>
3297 +#include <linux/interrupt.h>
3298 +#include <linux/ioport.h>
3299 +#include <linux/kernel.h>
3300 +#include <linux/major.h>
3301 +#include <linux/serial_reg.h>
3302 +#include <linux/time.h>
3303 +#include <linux/string.h>
3304 +#include <linux/types.h>
3305 +#include <linux/wait.h>
3306 +#include <linux/mm.h>
3307 +#include <linux/delay.h>
3308 +#include <linux/poll.h>
3309 +#include <asm/system.h>
3310 +#include <asm/segment.h>
3311 +#include <asm/io.h>
3312 +#include <asm/irq.h>
3313 +#include <asm/fcntl.h>
3315 +#include <linux/timer.h>
3317 +#include <linux/lirc.h>
3318 +#include "lirc_dev.h"
3320 +#include "lirc_it87.h"
3322 +static unsigned long it87_bits_in_byte_out = 0;
3323 +static unsigned long it87_send_counter = 0;
3324 +static unsigned char it87_RXEN_mask = IT87_CIR_RCR_RXEN;
3326 +#define RBUF_LEN 1024
3327 +#define WBUF_LEN 1024
3329 +#define LIRC_DRIVER_NAME "lirc_it87"
3331 +/* timeout for sequences in jiffies (=5/100s) */
3332 +/* must be longer than TIME_CONST */
3333 +#define IT87_TIMEOUT (HZ*5/100)
3335 +static int io = IT87_CIR_DEFAULT_IOBASE;
3336 +static int irq = IT87_CIR_DEFAULT_IRQ;
3337 +static unsigned char it87_freq = 38; /* kHz */
3338 +/* receiver demodulator default: off */
3339 +static unsigned char it87_enable_demodulator = 0;
3341 +static spinlock_t timer_lock = SPIN_LOCK_UNLOCKED;
3342 +static struct timer_list timerlist;
3343 +/* time of last signal change detected */
3344 +static struct timeval last_tv = {0, 0};
3345 +/* time of last UART data ready interrupt */
3346 +static struct timeval last_intr_tv = {0, 0};
3347 +static int last_value = 0;
3349 +static DECLARE_WAIT_QUEUE_HEAD(lirc_read_queue);
3351 +static spinlock_t hardware_lock = SPIN_LOCK_UNLOCKED;
3352 +static spinlock_t dev_lock = SPIN_LOCK_UNLOCKED;
3354 +static lirc_t rx_buf[RBUF_LEN]; unsigned int rx_tail = 0, rx_head = 0;
3355 +static lirc_t tx_buf[WBUF_LEN];
3357 +/* SECTION: Prototypes */
3359 +/* Communication with user-space */
3360 +static int lirc_open(struct inode * inode,
3361 + struct file * file);
3362 +static int lirc_close(struct inode * inode,
3363 + struct file *file);
3364 +static unsigned int lirc_poll(struct file * file,
3365 + poll_table * wait);
3366 +static ssize_t lirc_read(struct file * file,
3370 +static ssize_t lirc_write(struct file * file,
3374 +static int lirc_ioctl(struct inode *node,
3375 + struct file *filep,
3377 + unsigned long arg);
3378 +static void add_read_queue(int flag,
3379 + unsigned long val);
3380 +static int init_chrdev(void);
3381 +static void drop_chrdev(void);
3383 +static void it87_interrupt(int irq,
3385 + struct pt_regs * regs);
3386 +static void send_space(unsigned long len);
3387 +static void send_pulse(unsigned long len);
3388 +static void init_send(void);
3389 +static void terminate_send(unsigned long len);
3390 +static int init_hardware(void);
3391 +static void drop_hardware(void);
3392 + /* Initialisation */
3393 +static int init_port(void);
3394 +static void drop_port(void);
3395 +int init_module(void);
3396 +void cleanup_module(void);
3399 +/* SECTION: Communication with user-space */
3401 +static int lirc_open(struct inode * inode,
3402 + struct file * file)
3404 + spin_lock(&dev_lock);
3405 +#ifdef CONFIG_MODULE_UNLOAD
3406 + if (module_refcount(THIS_MODULE))
3408 + spin_unlock(&dev_lock);
3412 + try_module_get(THIS_MODULE);
3413 + spin_unlock(&dev_lock);
3418 +static int lirc_close(struct inode * inode,
3419 + struct file *file)
3421 + module_put(THIS_MODULE);
3426 +static unsigned int lirc_poll(struct file * file,
3427 + poll_table * wait)
3429 + poll_wait(file, &lirc_read_queue, wait);
3430 + if (rx_head != rx_tail)
3431 + return POLLIN | POLLRDNORM;
3436 +static ssize_t lirc_read(struct file * file,
3446 + if(file->f_flags & O_NONBLOCK &&
3452 + retval=wait_event_interruptible(lirc_read_queue,
3453 + rx_head!=rx_tail);
3459 + retval=verify_area(VERIFY_WRITE,(void *) buf+n,
3465 + copy_to_user((void *) buf+n,(void *) (rx_buf+rx_head),
3467 + rx_head=(rx_head+1)&(RBUF_LEN-1);
3468 + n+=sizeof(lirc_t);
3478 +static ssize_t lirc_write(struct file * file,
3486 + if(n%sizeof(lirc_t) || (n/sizeof(lirc_t)) > WBUF_LEN)
3488 + retval = verify_area(VERIFY_READ, buf, n);
3491 + copy_from_user(tx_buf, buf, n);
3493 + n/=sizeof(lirc_t);
3499 + send_pulse(tx_buf[i]);
3504 + send_space(tx_buf[i]);
3507 + terminate_send(tx_buf[i-1]);
3512 +static int lirc_ioctl(struct inode *node,
3513 + struct file *filep,
3515 + unsigned long arg)
3518 + unsigned long value = 0;
3519 + unsigned int ivalue;
3521 + if (cmd == LIRC_GET_FEATURES)
3522 + value = LIRC_CAN_SEND_PULSE |
3523 + LIRC_CAN_SET_SEND_CARRIER |
3524 + LIRC_CAN_REC_MODE2;
3525 + else if (cmd == LIRC_GET_SEND_MODE)
3526 + value = LIRC_MODE_PULSE;
3527 + else if (cmd == LIRC_GET_REC_MODE)
3528 + value = LIRC_MODE_MODE2;
3531 + case LIRC_GET_FEATURES:
3532 + case LIRC_GET_SEND_MODE:
3533 + case LIRC_GET_REC_MODE:
3534 + retval = put_user(value, (unsigned long *) arg);
3537 + case LIRC_SET_SEND_MODE:
3538 + case LIRC_SET_REC_MODE:
3539 + retval = get_user(value, (unsigned long *) arg);
3542 + case LIRC_SET_SEND_CARRIER:
3543 + retval=get_user(ivalue,(unsigned int *) arg);
3544 + if(retval) return(retval);
3546 + if (ivalue > IT87_CIR_FREQ_MAX ||
3547 + ivalue < IT87_CIR_FREQ_MIN) return(-EINVAL);
3549 + it87_freq = ivalue;
3551 + unsigned long hw_flags;
3553 + spin_lock_irqsave(&hardware_lock, hw_flags);
3554 + outb(((inb(io + IT87_CIR_TCR2) & IT87_CIR_TCR2_TXMPW) |
3555 + (it87_freq - IT87_CIR_FREQ_MIN) << 3),
3556 + io + IT87_CIR_TCR2);
3557 + spin_unlock_irqrestore(&hardware_lock, hw_flags);
3559 + printk(KERN_DEBUG LIRC_DRIVER_NAME
3560 + " demodulation frequency: %d kHz\n", it87_freq);
3567 + retval = -ENOIOCTLCMD;
3573 + if (cmd == LIRC_SET_REC_MODE) {
3574 + if (value != LIRC_MODE_MODE2)
3576 + } else if (cmd == LIRC_SET_SEND_MODE) {
3577 + if (value != LIRC_MODE_PULSE)
3583 +static void add_read_queue(int flag,
3584 + unsigned long val)
3586 + unsigned int new_rx_tail;
3589 +#ifdef DEBUG_SIGNAL
3590 + printk(KERN_DEBUG LIRC_DRIVER_NAME
3591 + ": add flag %d with val %lu\n",
3595 + newval = val & PULSE_MASK;
3597 + /* statistically pulses are ~TIME_CONST/2 too long: we could
3598 + maybe make this more exactly but this is good enough */
3599 + if(flag) /* pulse */ {
3600 + if(newval>TIME_CONST/2) {
3601 + newval-=TIME_CONST/2;
3603 + else /* should not ever happen */ {
3606 + newval|=PULSE_BIT;
3609 + newval+=TIME_CONST/2;
3611 + new_rx_tail = (rx_tail + 1) & (RBUF_LEN - 1);
3612 + if (new_rx_tail == rx_head) {
3614 + printk(KERN_WARNING LIRC_DRIVER_NAME ": Buffer overrun.\n");
3618 + rx_buf[rx_tail] = newval;
3619 + rx_tail = new_rx_tail;
3620 + wake_up_interruptible(&lirc_read_queue);
3624 +static struct file_operations lirc_fops = {
3626 + write: lirc_write,
3628 + ioctl: lirc_ioctl,
3630 + release: lirc_close,
3633 +static int set_use_inc(void* data)
3635 +#if WE_DONT_USE_LOCAL_OPEN_CLOSE
3636 + try_module_get(THIS_MODULE);
3641 +static void set_use_dec(void* data)
3643 +#if WE_DONT_USE_LOCAL_OPEN_CLOSE
3644 + module_put(THIS_MODULE);
3647 +static struct lirc_plugin plugin = {
3648 + name: LIRC_DRIVER_NAME,
3655 + set_use_inc: set_use_inc,
3656 + set_use_dec: set_use_dec,
3661 +int init_chrdev(void)
3663 + plugin.minor = lirc_register_plugin(&plugin);
3665 + if (plugin.minor < 0) {
3666 + printk(KERN_ERR LIRC_DRIVER_NAME ": init_chrdev() failed.\n");
3673 +static void drop_chrdev(void)
3675 + lirc_unregister_plugin(plugin.minor);
3678 +/* SECTION: Hardware */
3679 +static long delta(struct timeval * tv1,
3680 + struct timeval * tv2)
3682 + unsigned long deltv;
3684 + deltv = tv2->tv_sec - tv1->tv_sec;
3688 + deltv = deltv*1000000 +
3695 +static void it87_timeout(unsigned long data)
3697 + /* if last received signal was a pulse, but receiving stopped
3698 + within the 9 bit frame, we need to finish this pulse and
3699 + simulate a signal change to from pulse to space. Otherwise
3700 + upper layers will receive two sequences next time. */
3702 + unsigned long flags;
3703 + unsigned long pulse_end;
3705 + /* avoid interference with interrupt */
3706 + spin_lock_irqsave(&timer_lock, flags);
3708 + /* determine 'virtual' pulse end: */
3709 + pulse_end = delta(&last_tv, &last_intr_tv);
3710 +#ifdef DEBUG_SIGNAL
3711 + printk(KERN_DEBUG LIRC_DRIVER_NAME
3712 + ": timeout add %d for %lu usec\n",
3716 + add_read_queue(last_value,
3719 + last_tv=last_intr_tv;
3721 + spin_unlock_irqrestore(&timer_lock, flags);
3725 +static void it87_interrupt(int irq,
3727 + struct pt_regs * regs)
3729 + unsigned char data;
3730 + struct timeval curr_tv;
3731 + static unsigned long deltv;
3732 + unsigned long deltintrtv;
3733 + unsigned long flags, hw_flags;
3737 + iir = inb(io + IT87_CIR_IIR);
3739 + switch (iir & IT87_CIR_IIR_IID) {
3742 + lsr = inb(io + IT87_CIR_RSR) & (IT87_CIR_RSR_RXFTO |
3743 + IT87_CIR_RSR_RXFBC);
3744 + fifo = lsr & IT87_CIR_RSR_RXFBC;
3745 +#ifdef DEBUG_SIGNAL
3746 + printk(KERN_DEBUG LIRC_DRIVER_NAME
3747 + "iir: 0x%x fifo: 0x%x\n", iir, lsr);
3750 + /* avoid interference with timer */
3751 + spin_lock_irqsave(&timer_lock, flags);
3752 + spin_lock_irqsave(&hardware_lock, hw_flags);
3754 + del_timer(&timerlist);
3755 + data = inb(io + IT87_CIR_DR);
3756 +#ifdef DEBUG_SIGNAL
3757 + printk(KERN_DEBUG LIRC_DRIVER_NAME
3761 + do_gettimeofday(&curr_tv);
3762 + deltv = delta(&last_tv, &curr_tv);
3763 + deltintrtv = delta(&last_intr_tv, &curr_tv);
3764 +#ifdef DEBUG_SIGNAL
3765 + printk(KERN_DEBUG LIRC_DRIVER_NAME
3766 + ": t %lu , d %d\n",
3770 + /* if nothing came in last 2 cycles,
3772 + if (deltintrtv > TIME_CONST * 2) {
3774 +#ifdef DEBUG_SIGNAL
3775 + printk(KERN_DEBUG LIRC_DRIVER_NAME ": GAP\n");
3777 + /* simulate signal change */
3778 + add_read_queue(last_value,
3782 + last_tv.tv_sec = last_intr_tv.tv_sec;
3783 + last_tv.tv_usec = last_intr_tv.tv_usec;
3784 + deltv = deltintrtv;
3788 + if (data ^ last_value) {
3789 + /* deltintrtv > 2*TIME_CONST,
3791 + /* the other case is timeout */
3792 + add_read_queue(last_value,
3793 + deltv-TIME_CONST);
3794 + last_value = data;
3795 + last_tv = curr_tv;
3796 + if(last_tv.tv_usec>=TIME_CONST) {
3797 + last_tv.tv_usec-=TIME_CONST;
3801 + last_tv.tv_usec+=1000000-
3805 + last_intr_tv = curr_tv;
3807 + /* start timer for end of sequence detection */
3808 + timerlist.expires = jiffies + IT87_TIMEOUT;
3809 + add_timer(&timerlist);
3811 + outb((inb(io + IT87_CIR_RCR) & ~IT87_CIR_RCR_RXEN) |
3812 + IT87_CIR_RCR_RXACT,
3813 + io + IT87_CIR_RCR);
3814 + if (it87_RXEN_mask) {
3815 + outb(inb(io + IT87_CIR_RCR) | IT87_CIR_RCR_RXEN,
3816 + io + IT87_CIR_RCR);
3820 + while (fifo != 0);
3821 + spin_unlock_irqrestore(&hardware_lock, hw_flags);
3822 + spin_unlock_irqrestore(&timer_lock, flags);
3827 +#ifdef DEBUG_SIGNAL
3828 + printk(KERN_DEBUG LIRC_DRIVER_NAME
3829 + "unknown IRQ (shouldn't happen) !!\n");
3836 +static void send_it87(unsigned long len,
3837 + unsigned long stime,
3838 + unsigned char send_byte,
3839 + unsigned int count_bits)
3841 + long count = len / stime;
3842 + long time_left = 0;
3843 + static unsigned char byte_out = 0;
3845 +#ifdef DEBUG_SIGNAL
3846 + printk(KERN_DEBUG LIRC_DRIVER_NAME
3847 + "send_it87: len=%ld, sb=%d\n",
3851 + time_left = (long)len - (long)count * (long)stime;
3852 + count += ((2 * time_left) / stime);
3855 + for (i=0; i<count_bits; i++) {
3856 + byte_out = (byte_out << 1) | (send_byte & 1);
3857 + it87_bits_in_byte_out++;
3859 + if (it87_bits_in_byte_out == 8) {
3860 +#ifdef DEBUG_SIGNAL
3861 + printk(KERN_DEBUG LIRC_DRIVER_NAME
3862 + "out=0x%x, tsr_txfbc: 0x%x\n",
3864 + inb(io + IT87_CIR_TSR) &
3865 + IT87_CIR_TSR_TXFBC);
3867 + while ((inb(io + IT87_CIR_TSR) &
3868 + IT87_CIR_TSR_TXFBC) >= IT87_CIR_FIFO_SIZE);
3870 + unsigned long hw_flags;
3872 + spin_lock_irqsave(&hardware_lock, hw_flags);
3873 + outb(byte_out, io + IT87_CIR_DR);
3874 + spin_unlock_irqrestore(&hardware_lock, hw_flags);
3876 + it87_bits_in_byte_out = 0;
3877 + it87_send_counter++;
3886 +maybe: exchange space and pulse because
3887 +it8705 only modulates 0-bits
3891 +static void send_space(unsigned long len)
3896 + IT87_CIR_BAUDRATE_DIVISOR);
3899 +static void send_pulse(unsigned long len)
3904 + IT87_CIR_BAUDRATE_DIVISOR);
3908 +static void init_send()
3910 + unsigned long flags;
3912 + spin_lock_irqsave(&hardware_lock, flags);
3913 + /* RXEN=0: receiver disable */
3914 + it87_RXEN_mask = 0;
3915 + outb(inb(io + IT87_CIR_RCR) & ~IT87_CIR_RCR_RXEN,
3916 + io + IT87_CIR_RCR);
3917 + spin_unlock_irqrestore(&hardware_lock, flags);
3918 + it87_bits_in_byte_out = 0;
3919 + it87_send_counter = 0;
3923 +static void terminate_send(unsigned long len)
3925 + unsigned long flags;
3926 + unsigned long last = 0;
3928 + last = it87_send_counter;
3929 + /* make sure all necessary data has been sent */
3930 + while (last == it87_send_counter)
3932 + /* wait until all data sent */
3933 + while ((inb(io + IT87_CIR_TSR) & IT87_CIR_TSR_TXFBC) != 0);
3934 + /* then reenable receiver */
3935 + spin_lock_irqsave(&hardware_lock, flags);
3936 + it87_RXEN_mask = IT87_CIR_RCR_RXEN;
3937 + outb(inb(io + IT87_CIR_RCR) | IT87_CIR_RCR_RXEN,
3938 + io + IT87_CIR_RCR);
3939 + spin_unlock_irqrestore(&hardware_lock, flags);
3943 +static int init_hardware(void)
3945 + unsigned long flags;
3946 + unsigned char it87_rcr = 0;
3948 + spin_lock_irqsave(&hardware_lock, flags);
3949 + /* init cir-port */
3950 + /* enable r/w-access to Baudrate-Register */
3951 + outb(IT87_CIR_IER_BR, io + IT87_CIR_IER);
3952 + outb(IT87_CIR_BAUDRATE_DIVISOR % 0x100, io+IT87_CIR_BDLR);
3953 + outb(IT87_CIR_BAUDRATE_DIVISOR / 0x100, io+IT87_CIR_BDHR);
3954 + /* Baudrate Register off, define IRQs: Input only */
3955 + outb(IT87_CIR_IER_IEC | IT87_CIR_IER_RDAIE, io + IT87_CIR_IER);
3956 + /* RX: HCFS=0, RXDCR = 001b (35,6..40,3 kHz), RXEN=1 */
3957 + it87_rcr = (IT87_CIR_RCR_RXEN & it87_RXEN_mask) | 0x1;
3958 + if (it87_enable_demodulator)
3959 + it87_rcr |= IT87_CIR_RCR_RXEND;
3960 + outb(it87_rcr, io + IT87_CIR_RCR);
3961 + /* TX: 38kHz, 13,3us (pulse-width */
3962 + outb(((it87_freq - IT87_CIR_FREQ_MIN) << 3) | 0x06,
3963 + io + IT87_CIR_TCR2);
3964 + spin_unlock_irqrestore(&hardware_lock, flags);
3969 +static void drop_hardware(void)
3971 + unsigned long flags;
3973 + spin_lock_irqsave(&hardware_lock, flags);
3975 + /* receiver disable */
3976 + it87_RXEN_mask = 0;
3977 + outb(0x1, io + IT87_CIR_RCR);
3978 + /* turn off irqs */
3979 + outb(0, io + IT87_CIR_IER);
3981 + outb(IT87_CIR_TCR1_FIFOCLR, io+IT87_CIR_TCR1);
3983 + outb(IT87_CIR_IER_RESET, io+IT87_CIR_IER);
3985 + spin_unlock_irqrestore(&hardware_lock, flags);
3989 +static unsigned char it87_read(unsigned char port)
3991 + outb(port, IT87_ADRPORT);
3992 + return inb(IT87_DATAPORT);
3996 +static void it87_write(unsigned char port,
3997 + unsigned char data)
3999 + outb(port, IT87_ADRPORT);
4000 + outb(data, IT87_DATAPORT);
4004 +/* SECTION: Initialisation */
4006 +static int init_port(void)
4010 + unsigned char init_bytes[4] = {IT87_INIT};
4011 + unsigned char it87_chipid = 0;
4012 + unsigned char ldn = 0;
4013 + unsigned int it87_io = 0;
4014 + unsigned int it87_irq = 0;
4016 + /* Enter MB PnP Mode */
4017 + outb(init_bytes[0], IT87_ADRPORT);
4018 + outb(init_bytes[1], IT87_ADRPORT);
4019 + outb(init_bytes[2], IT87_ADRPORT);
4020 + outb(init_bytes[3], IT87_ADRPORT);
4022 + /* 8712 or 8705 ? */
4023 + it87_chipid = it87_read(IT87_CHIP_ID1);
4024 + if (it87_chipid != 0x87) {
4028 + it87_chipid = it87_read(IT87_CHIP_ID2);
4029 + if ((it87_chipid != 0x12) && (it87_chipid != 0x05)) {
4030 + printk(KERN_INFO LIRC_DRIVER_NAME
4031 + ": no IT8705/12 found, exiting..\n");
4035 + printk(KERN_INFO LIRC_DRIVER_NAME
4036 + ": found IT87%.2x.\n",
4039 + /* get I/O-Port and IRQ */
4040 + if (it87_chipid == 0x12)
4041 + ldn = IT8712_CIR_LDN;
4043 + ldn = IT8705_CIR_LDN;
4044 + it87_write(IT87_LDN, ldn);
4046 + it87_io = it87_read(IT87_CIR_BASE_MSB) * 256 +
4047 + it87_read(IT87_CIR_BASE_LSB);
4048 + if (it87_io == 0) {
4050 + io = IT87_CIR_DEFAULT_IOBASE;
4051 + printk(KERN_INFO LIRC_DRIVER_NAME
4052 + ": set default io 0x%x\n",
4054 + it87_write(IT87_CIR_BASE_MSB, io / 0x100);
4055 + it87_write(IT87_CIR_BASE_LSB, io % 0x100);
4060 + it87_irq = it87_read(IT87_CIR_IRQ);
4061 + if (it87_irq == 0) {
4063 + irq = IT87_CIR_DEFAULT_IRQ;
4064 + printk(KERN_INFO LIRC_DRIVER_NAME
4065 + ": set default irq 0x%x\n",
4067 + it87_write(IT87_CIR_IRQ, irq);
4073 + unsigned long hw_flags;
4075 + spin_lock_irqsave(&hardware_lock, hw_flags);
4077 + outb(IT87_CIR_IER_RESET, io+IT87_CIR_IER);
4079 + outb(IT87_CIR_TCR1_FIFOCLR |
4080 + /* IT87_CIR_TCR1_ILE | */
4081 + IT87_CIR_TCR1_TXRLE |
4082 + IT87_CIR_TCR1_TXENDF, io+IT87_CIR_TCR1);
4083 + spin_unlock_irqrestore(&hardware_lock, hw_flags);
4086 + /* get I/O port access and IRQ line */
4087 + retval = request_region(io, 8, LIRC_DRIVER_NAME);
4090 + printk(KERN_ERR LIRC_DRIVER_NAME
4091 + ": Unable to reserve IO region for LIRC IT87. Port 0x%.4x already in use.\n",
4093 + /* Leaving MB PnP Mode */
4094 + it87_write(IT87_CFGCTRL, 0x2);
4098 + /* activate CIR-Device */
4099 + it87_write(IT87_CIR_ACT, 0x1);
4101 + /* Leaving MB PnP Mode */
4102 + it87_write(IT87_CFGCTRL, 0x2);
4104 + retval = request_irq(irq, it87_interrupt, 0 /*SA_INTERRUPT*/,
4105 + LIRC_DRIVER_NAME, NULL);
4107 + printk(KERN_ERR LIRC_DRIVER_NAME
4108 + ": IRQ %d already in use.\n",
4113 + printk(KERN_INFO LIRC_DRIVER_NAME
4114 + ": I/O port 0x%.4x, IRQ %d.\n",
4118 + request_region(io, 8, LIRC_DRIVER_NAME);
4119 + init_timer(&timerlist);
4120 + timerlist.function = it87_timeout;
4121 + timerlist.data = 0xabadcafe;
4127 +static void drop_port(void)
4130 + unsigned char init_bytes[4] = {IT87_INIT};
4132 + / * Enter MB PnP Mode * /
4133 + outb(init_bytes[0], IT87_ADRPORT);
4134 + outb(init_bytes[1], IT87_ADRPORT);
4135 + outb(init_bytes[2], IT87_ADRPORT);
4136 + outb(init_bytes[3], IT87_ADRPORT);
4138 + / * deactivate CIR-Device * /
4139 + it87_write(IT87_CIR_ACT, 0x0);
4141 + / * Leaving MB PnP Mode * /
4142 + it87_write(IT87_CFGCTRL, 0x2);
4145 + del_timer_sync(&timerlist);
4146 + free_irq(irq, NULL);
4147 + release_region(io, 8);
4151 +int init_lirc_it87(void)
4155 + init_waitqueue_head(&lirc_read_queue);
4156 + retval = init_port();
4160 + printk(KERN_INFO LIRC_DRIVER_NAME
4161 + ": Installed.\n");
4166 +MODULE_AUTHOR("Hans-Günter Lütke Uphues");
4167 +MODULE_DESCRIPTION("LIRC driver for ITE IT8712/IT8705 CIR port");
4168 +MODULE_PARM(io, "i");
4169 +MODULE_PARM_DESC(io,
4170 + "I/O base address (default: 0x310)");
4171 +MODULE_PARM(irq, "i");
4172 +MODULE_PARM_DESC(irq,
4173 + "Interrupt (1,3-12) (default: 7)");
4174 +MODULE_PARM(it87_enable_demodulator, "i");
4175 +MODULE_PARM_DESC(it87_enable_demodulator,
4176 + "Receiver demodulator enable/disable (1/0), default: 0");
4177 +MODULE_LICENSE("GPL");
4179 +static int __init lirc_it87_init(void)
4183 + retval=init_chrdev();
4186 + retval = init_lirc_it87();
4195 +static void __exit lirc_it87_exit(void)
4200 + printk(KERN_INFO LIRC_DRIVER_NAME ": Uninstalled.\n");
4203 +module_init(lirc_it87_init);
4204 +module_exit(lirc_it87_exit);
4207 + * Overrides for Emacs so that we follow Linus's tabbing style.
4208 + * ---------------------------------------------------------------------------
4209 + * Local variables:
4210 + * c-basic-offset: 8
4213 diff -uprN -X dontdiff linux-2.6.5.orig/drivers/char/lirc/lirc_it87.h linux-2.6.5/drivers/char/lirc/lirc_it87.h
4214 --- linux-2.6.5.orig/drivers/char/lirc/lirc_it87.h 1970-01-01 01:00:00.000000000 +0100
4215 +++ linux-2.6.5/drivers/char/lirc/lirc_it87.h 2004-04-04 14:05:29.417627112 +0200
4218 +/* SECTION: Definitions */
4220 +/********************************* ITE IT87xx ************************/
4222 +/* based on the following documentation from ITE:
4223 + a) IT8712F Preliminary CIR Programming Guide V0.1
4224 + b) IT8705F Simple LPC I/O Preliminary Specifiction V0.3
4225 + c) IT8712F EC-LPC I/O Preliminary Specification V0.5
4228 +/* IT8712/05 Ports: */
4229 +#define IT87_ADRPORT 0x2e
4230 +#define IT87_DATAPORT 0x2f
4231 +#define IT87_INIT 0x87, 0x01, 0x55, 0x55
4233 +/* alternate Ports: */
4235 +#define IT87_ADRPORT 0x4e
4236 +#define IT87_DATAPORT 0x4f
4237 +#define IT87_INIT 0x87, 0x01, 0x55, 0xaa
4240 +/* IT8712/05 Registers */
4241 +#define IT87_CFGCTRL 0x2
4242 +#define IT87_LDN 0x7
4243 +#define IT87_CHIP_ID1 0x20
4244 +#define IT87_CHIP_ID2 0x21
4245 +#define IT87_CFG_VERSION 0x22
4246 +#define IT87_SWSUSPEND 0x23
4248 +#define IT8712_CIR_LDN 0xa
4249 +#define IT8705_CIR_LDN 0x7
4251 +/* CIR Configuration Registers: */
4252 +#define IT87_CIR_ACT 0x30
4253 +#define IT87_CIR_BASE_MSB 0x60
4254 +#define IT87_CIR_BASE_LSB 0x61
4255 +#define IT87_CIR_IRQ 0x70
4256 +#define IT87_CIR_CONFIG 0xf0
4258 +/* List of IT87_CIR registers: offset to BaseAddr */
4259 +#define IT87_CIR_DR 0
4260 +#define IT87_CIR_IER 1
4261 +#define IT87_CIR_RCR 2
4262 +#define IT87_CIR_TCR1 3
4263 +#define IT87_CIR_TCR2 4
4264 +#define IT87_CIR_TSR 5
4265 +#define IT87_CIR_RSR 6
4266 +#define IT87_CIR_BDLR 5
4267 +#define IT87_CIR_BDHR 6
4268 +#define IT87_CIR_IIR 7
4270 +/* Bit Definitionen */
4272 +#define IT87_CIR_IER_TM_EN 0x80
4273 +#define IT87_CIR_IER_RESEVED 0x40
4274 +#define IT87_CIR_IER_RESET 0x20
4275 +#define IT87_CIR_IER_BR 0x10
4276 +#define IT87_CIR_IER_IEC 0x8
4277 +#define IT87_CIR_IER_RFOIE 0x4
4278 +#define IT87_CIR_IER_RDAIE 0x2
4279 +#define IT87_CIR_IER_TLDLIE 0x1
4282 +#define IT87_CIR_RCR_RDWOS 0x80
4283 +#define IT87_CIR_RCR_HCFS 0x40
4284 +#define IT87_CIR_RCR_RXEN 0x20
4285 +#define IT87_CIR_RCR_RXEND 0x10
4286 +#define IT87_CIR_RCR_RXACT 0x8
4287 +#define IT87_CIR_RCR_RXDCR 0x7
4290 +#define IT87_CIR_TCR1_FIFOCLR 0x80
4291 +#define IT87_CIR_TCR1_ILE 0x40
4292 +#define IT87_CIR_TCR1_FIFOTL 0x30
4293 +#define IT87_CIR_TCR1_TXRLE 0x8
4294 +#define IT87_CIR_TCR1_TXENDF 0x4
4295 +#define IT87_CIR_TCR1_TXMPM 0x3
4298 +#define IT87_CIR_TCR2_CFQ 0xf8
4299 +#define IT87_CIR_TCR2_TXMPW 0x7
4302 +#define IT87_CIR_TSR_RESERVED 0xc0
4303 +#define IT87_CIR_TSR_TXFBC 0x3f
4306 +#define IT87_CIR_RSR_RXFTO 0x80
4307 +#define IT87_CIR_RSR_RESERVED 0x40
4308 +#define IT87_CIR_RSR_RXFBC 0x3f
4311 +#define IT87_CIR_IIR_RESERVED 0xf8
4312 +#define IT87_CIR_IIR_IID 0x6
4313 +#define IT87_CIR_IIR_IIP 0x1
4316 +#define IT87_CIR_TM_IL_SEL 0x80
4317 +#define IT87_CIR_TM_RESERVED 0x40
4318 +#define IT87_CIR_TM_TM_REG 0x3f
4320 +#define IT87_CIR_FIFO_SIZE 32
4322 +/* Baudratedivisor for IT87: power of 2: only 1,2,4 or 8) */
4323 +#define IT87_CIR_BAUDRATE_DIVISOR 0x1
4324 +#define IT87_CIR_DEFAULT_IOBASE 0x310
4325 +#define IT87_CIR_DEFAULT_IRQ 0x7
4326 +#define IT87_CIR_SPACE 0x00
4327 +#define IT87_CIR_PULSE 0xff
4328 +#define IT87_CIR_FREQ_MIN 27
4329 +#define IT87_CIR_FREQ_MAX 58
4330 +#define TIME_CONST (IT87_CIR_BAUDRATE_DIVISOR * 8000000ul / 115200ul)
4332 +/********************************* ITE IT87xx ************************/
4333 diff -uprN -X dontdiff linux-2.6.5.orig/drivers/char/lirc/lirc_mceusb.c linux-2.6.5/drivers/char/lirc/lirc_mceusb.c
4334 --- linux-2.6.5.orig/drivers/char/lirc/lirc_mceusb.c 1970-01-01 01:00:00.000000000 +0100
4335 +++ linux-2.6.5/drivers/char/lirc/lirc_mceusb.c 2004-04-04 14:05:29.422626352 +0200
4338 + * USB Microsoft IR Transceiver driver - 0.1
4340 + * Copyright (c) 2003-2004 Dan Conti (dconti@acm.wwu.edu)
4342 + * This driver is based on the USB skeleton driver packaged with the
4343 + * kernel, and the notice from that package has been retained below.
4345 + * The Microsoft IR Transceiver is a neat little IR receiver with two
4346 + * emitters on it designed for Windows Media Center. This driver might
4347 + * work for all media center remotes, but I have only tested it with
4348 + * the philips model. The first revision of this driver only supports
4349 + * the receive function - the transmit function will be much more
4350 + * tricky due to the nature of the hardware. Microsoft chose to build
4351 + * this device inexpensively, therefore making it extra dumb. There
4352 + * is no interrupt endpoint on this device; all usb traffic happens
4353 + * over two bulk endpoints. As a result of this, poll() for this
4354 + * device is an actual hardware poll (instead of a receive queue
4355 + * check) and is rather expensive.
4357 + * This driver is structured in three basic layers
4358 + * - lower - interface with the usb device and manage usb data
4359 + * - middle - api to convert usb data into mode2 and provide this in
4361 + * - mceusb_* - linux driver interface
4363 + * The key routines are as follows:
4364 + * msir_fetch_more_data - this reads incoming data, strips off the
4365 + * start codes the ir receiver places on them,
4366 + * and dumps it in an * internal buffer
4367 + * msir_generate_mode2 - this takes the above data, depacketizes it,
4368 + * and generates mode2 data to feed out
4369 + * through read calls
4372 + * All trademarks property of their respective owners.
4374 + * 2003_11_11 - Restructured to minimalize code interpretation in the
4375 + * driver. The normal use case will be with lirc.
4377 + * 2004_01_01 - Removed all code interpretation. Generate mode2 data
4378 + * for passing off to lirc. Cleanup
4380 + * 2004_01_04 - Removed devfs handle. Put in a temporary workaround
4381 + * for a known issue where repeats generate two
4382 + * sequential spaces * (last_was_repeat_gap)
4385 + * - Fix up minor number, registration of major/minor with usb subsystem
4386 + * - Fix up random EINTR being sent
4387 + * - Fix problem where third key in a repeat sequence is randomly truncated
4391 + * USB Skeleton driver - 0.6
4393 + * Copyright (c) 2001 Greg Kroah-Hartman (greg@kroah.com)
4395 + * This program is free software; you can redistribute it and/or
4396 + * modify it under the terms of the GNU General Public License as
4397 + * published by the Free Software Foundation; either version 2 of
4398 + * the License, or (at your option) any later version.
4401 + * This driver is to be used as a skeleton driver to be able to create a
4402 + * USB driver quickly. The design of it is based on the usb-serial and
4405 + * Thanks to Oliver Neukum and David Brownell for their help in debugging
4409 + * - fix urb->status race condition in write sequence
4410 + * - move minor_table to a dynamic list.
4414 + * 2001_11_05 - 0.6 - fix minor locking problem in skel_disconnect.
4415 + * Thanks to Pete Zaitcev for the fix.
4416 + * 2001_09_04 - 0.5 - fix devfs bug in skel_disconnect. Thanks to wim delvaux
4417 + * 2001_08_21 - 0.4 - more small bug fixes.
4418 + * 2001_05_29 - 0.3 - more bug fixes based on review from linux-usb-devel
4419 + * 2001_05_24 - 0.2 - bug fixes based on review from linux-usb-devel people
4420 + * 2001_05_01 - 0.1 - first version
4424 +#include <linux/config.h>
4425 +#include <linux/kernel.h>
4426 +#include <linux/sched.h>
4427 +#include <linux/wait.h>
4428 +#include <linux/signal.h>
4429 +#include <linux/errno.h>
4430 +#include <linux/poll.h>
4431 +#include <linux/init.h>
4432 +#include <linux/slab.h>
4433 +#include <linux/fcntl.h>
4434 +#include <linux/module.h>
4435 +#include <linux/spinlock.h>
4436 +#include <linux/list.h>
4437 +#include <linux/smp_lock.h>
4438 +#include <linux/usb.h>
4440 +#ifdef CONFIG_USB_DEBUG
4441 + static int debug = 1;
4443 + static int debug = 1;
4446 +#include <linux/lirc.h>
4447 +#include "drivers/lirc_dev/lirc_dev.h"
4449 +/* Version Information */
4450 +#define DRIVER_VERSION "v0.1"
4451 +#define DRIVER_AUTHOR "Dan Conti, dconti@acm.wwu.edu"
4452 +#define DRIVER_DESC "USB Microsoft IR Transceiver Driver"
4454 +/* Module paramaters */
4455 +MODULE_PARM(debug, "i");
4456 +MODULE_PARM_DESC(debug, "Debug enabled or not");
4458 +/* Define these values to match your device */
4459 +#define USB_MCEUSB_VENDOR_ID 0x045e
4460 +#define USB_MCEUSB_PRODUCT_ID 0x006d
4462 +/* table of devices that work with this driver */
4463 +static struct usb_device_id mceusb_table [] = {
4464 + { USB_DEVICE(USB_MCEUSB_VENDOR_ID, USB_MCEUSB_PRODUCT_ID) },
4465 + { } /* Terminating entry */
4468 +MODULE_DEVICE_TABLE (usb, mceusb_table);
4470 +/* XXX TODO, 244 is likely unused but not reserved */
4471 +/* Get a minor range for your devices from the usb maintainer */
4472 +#define USB_MCEUSB_MINOR_BASE 244
4475 +/* we can have up to this number of device plugged in at once */
4476 +#define MAX_DEVICES 16
4478 +/* Structure to hold all of our device specific stuff */
4480 + /* save off the usb device pointer */
4481 + struct usb_device * udev;
4482 + /* the interface for this device */
4483 + struct usb_interface * interface;
4484 + /* the starting minor number for this device */
4485 + unsigned char minor;
4486 + /* the number of ports this device has */
4487 + unsigned char num_ports;
4488 + /* number of interrupt in endpoints we have */
4489 + char num_interrupt_in;
4490 + /* number of bulk in endpoints we have */
4492 + /* number of bulk out endpoints we have */
4493 + char num_bulk_out;
4495 + /* the buffer to receive data */
4496 + unsigned char * bulk_in_buffer;
4497 + /* the size of the receive buffer */
4499 + /* the address of the bulk in endpoint */
4500 + __u8 bulk_in_endpointAddr;
4502 + /* the buffer to send data */
4503 + unsigned char * bulk_out_buffer;
4504 + /* the size of the send buffer */
4505 + int bulk_out_size;
4506 + /* the urb used to send data */
4507 + struct urb * write_urb;
4508 + /* the address of the bulk out endpoint */
4509 + __u8 bulk_out_endpointAddr;
4511 + wait_queue_head_t wait_q; /* for timeouts */
4512 + int open_count; /* number of times this port
4513 + * has been opened */
4514 + struct semaphore sem; /* locks this structure */
4516 + struct lirc_plugin* plugin;
4518 + /* Used in converting to mode2 and storing */
4519 + /* buffer for the mode2 data, since lirc reads 4bytes */
4520 + int mode2_data[256];
4521 + int mode2_idx; /* read index */
4522 + int mode2_count; /* words available (i.e. write
4524 + int mode2_partial_pkt_size;
4527 + /* Used for storing preprocessed usb data before converting to mode2*/
4528 + char usb_dbuffer[1024];
4531 + int usb_valid_bytes_in_bulk_buffer;
4533 + /* Set to 1 if the last value we adjusted was a repeat gap; we
4534 + * need to hold this value around until we process a lead
4535 + * space on the repeat code, otherwise we pass off two
4536 + * sequential spaces */
4537 + int last_was_repeat_gap;
4541 +static ssize_t mceusb_read (struct file *file, char *buffer,
4542 + size_t count, loff_t *ppos);
4543 +static ssize_t mceusb_write (struct file *file, const char *buffer,
4544 + size_t count, loff_t *ppos);
4545 +static unsigned int mceusb_poll (struct file* file, poll_table* wait);
4547 +static int mceusb_open (struct inode *inode, struct file *file);
4548 +static int mceusb_release (struct inode *inode, struct file *file);
4550 +static void * mceusb_probe (struct usb_device *dev, unsigned int ifnum,
4551 + const struct usb_device_id *id);
4552 +static void *mceusb_disconnect (struct usb_interface *intf);
4554 +static void mceusb_write_bulk_callback (struct urb *urb);
4556 +/* lower level api */
4557 +static int msir_fetch_more_data( struct usb_skel* dev, int dont_block );
4558 +static int msir_read_from_buffer( struct usb_skel* dev, char* buffer, int len );
4559 +static int msir_mark_as_read( struct usb_skel* dev, int count );
4560 +static int msir_available_data( struct usb_skel* dev );
4563 +static int msir_generate_mode2( struct usb_skel* dev, signed char* usb_data,
4565 +static int msir_copy_mode2( struct usb_skel* dev, int* mode2_data, int count );
4566 +static int msir_available_mode2( struct usb_skel* dev );
4568 +/* helper functions */
4569 +static void msir_cleanup( struct usb_skel* dev );
4570 +static int set_use_inc(void* data);
4571 +static void set_use_dec(void* data);
4573 +/* array of pointers to our devices that are currently connected */
4574 +static struct usb_skel *minor_table[MAX_DEVICES];
4576 +/* lock to protect the minor_table structure */
4577 +static DECLARE_MUTEX (minor_table_mutex);
4580 + * File operations needed when we register this driver.
4581 + * This assumes that this driver NEEDS file operations,
4582 + * of course, which means that the driver is expected
4583 + * to have a node in the /dev directory. If the USB
4584 + * device were for a network interface then the driver
4585 + * would use "struct net_driver" instead, and a serial
4586 + * device would use "struct tty_driver".
4588 +static struct file_operations mceusb_fops = {
4590 + * The owner field is part of the module-locking
4591 + * mechanism. The idea is that the kernel knows
4592 + * which module to increment the use-counter of
4593 + * BEFORE it calls the device's open() function.
4594 + * This also means that the kernel can decrement
4595 + * the use-counter again before calling release()
4596 + * or should the open() function fail.
4598 + * Not all device structures have an "owner" field
4599 + * yet. "struct file_operations" and "struct net_device"
4600 + * do, while "struct tty_driver" does not. If the struct
4601 + * has an "owner" field, then initialize it to the value
4602 + * THIS_MODULE and the kernel will handle all module
4603 + * locking for you automatically. Otherwise, you must
4604 + * increment the use-counter in the open() function
4605 + * and decrement it again in the release() function
4608 + owner: THIS_MODULE,
4610 + read: mceusb_read,
4611 + write: mceusb_write,
4612 + poll: mceusb_poll,
4614 + open: mceusb_open,
4615 + release: mceusb_release,
4619 +/* usb specific object needed to register this driver with the usb subsystem */
4620 +static struct usb_driver mceusb_driver = {
4621 + name: "ir_transceiver",
4622 + probe: mceusb_probe,
4623 + disconnect: mceusb_disconnect,
4624 + fops: &mceusb_fops,
4625 + minor: USB_MCEUSB_MINOR_BASE,
4626 + id_table: mceusb_table,
4631 + * usb_mceusb_debug_data
4633 +static inline void usb_mceusb_debug_data (const char *function, int size,
4634 + const unsigned char *data)
4641 + printk (KERN_DEBUG __FILE__": %s - length = %d, data = ",
4643 + for (i = 0; i < size; ++i) {
4644 + printk ("%.2x ", data[i]);
4653 +static inline void mceusb_delete (struct usb_skel *dev)
4655 + minor_table[dev->minor] = NULL;
4656 + if (dev->bulk_in_buffer != NULL)
4657 + kfree (dev->bulk_in_buffer);
4658 + if (dev->bulk_out_buffer != NULL)
4659 + kfree (dev->bulk_out_buffer);
4660 + if (dev->write_urb != NULL)
4661 + usb_free_urb (dev->write_urb);
4665 +static void mceusb_setup( struct usb_device *udev )
4669 + memset( data, 0, 8 );
4672 + res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
4673 + USB_REQ_GET_STATUS, USB_DIR_IN,
4674 + 0, 0, data, 2, HZ * 3);
4676 + /* res = usb_get_status( udev, 0, 0, data ); */
4677 + dbg(__FUNCTION__ " res = %d status = 0x%x 0x%x",
4678 + res, data[0], data[1] );
4680 + /* This is a strange one. They issue a set address to the
4681 + * device on the receive control pipe and expect a certain
4684 + memset( data, 0, 8 );
4686 + res = usb_control_msg( udev, usb_rcvctrlpipe(udev, 0),
4687 + 5, USB_TYPE_VENDOR, 0, 0,
4688 + data, 2, HZ * 3 );
4689 + dbg(__FUNCTION__ " res = %d, devnum = %d", res, udev->devnum);
4690 + dbg(__FUNCTION__ " data[0] = %d, data[1] = %d", data[0], data[1] );
4693 + res = usb_control_msg( udev, usb_sndctrlpipe(udev, 0),
4694 + USB_REQ_SET_FEATURE, USB_TYPE_VENDOR,
4695 + 0xc04e, 0x0000, NULL, 0, HZ * 3 );
4697 + dbg(__FUNCTION__ " res = %d", res);
4699 + /* These two are sent by the windows driver, but stall for
4700 + * me. I dont have an analyzer on the linux side so i can't
4701 + * see what is actually different and why * the device takes
4705 + /* this is some custom control message they send */
4706 + res = usb_control_msg( udev, usb_sndctrlpipe(udev, 0),
4707 + 0x04, USB_TYPE_VENDOR,
4708 + 0x0808, 0x0000, NULL, 0, HZ * 3 );
4710 + dbg(__FUNCTION__ " res = %d", res);
4712 + /* this is another custom control message they send */
4713 + res = usb_control_msg( udev, usb_sndctrlpipe(udev, 0),
4714 + 0x02, USB_TYPE_VENDOR,
4715 + 0x0000, 0x0100, NULL, 0, HZ * 3 );
4717 + dbg(__FUNCTION__ " res = %d", res);
4724 +static int mceusb_open (struct inode *inode, struct file *file)
4726 + struct usb_skel *dev = NULL;
4727 + struct usb_device* udev = NULL;
4731 + dbg(__FUNCTION__);
4733 + /* This is a very sucky point. On lirc, we get passed the
4734 + * minor number of the lirc device, which is totally
4735 + * retarded. We want to support people opening /dev/usb/msir0
4736 + * directly though, so try and determine who the hell is
4739 + if( MAJOR( inode->i_rdev ) != USB_MAJOR )
4741 + /* This is the lirc device just passing on the
4742 + * request. We probably mismatch minor numbers here,
4743 + * but the lucky fact is that nobody will ever use two
4744 + * of the exact same remotes with two recievers on one
4749 + subminor = MINOR (inode->i_rdev) - USB_MCEUSB_MINOR_BASE;
4751 + if ((subminor < 0) ||
4752 + (subminor >= MAX_DEVICES)) {
4753 + dbg("subminor %d", subminor);
4757 + /* Increment our usage count for the module.
4758 + * This is redundant here, because "struct file_operations"
4759 + * has an "owner" field. This line is included here soley as
4760 + * a reference for drivers using lesser structures... ;-)
4762 + try_module_get(THIS_MODULE);
4764 + /* lock our minor table and get our local data for this minor */
4765 + down (&minor_table_mutex);
4766 + dev = minor_table[subminor];
4767 + if (dev == NULL) {
4768 + dbg("dev == NULL");
4769 + up (&minor_table_mutex);
4770 + module_put(THIS_MODULE);
4775 + /* lock this device */
4778 + /* unlock the minor table */
4779 + up (&minor_table_mutex);
4781 + /* increment our usage count for the driver */
4782 + ++dev->open_count;
4784 + /* save our object in the file's private structure */
4785 + file->private_data = dev;
4787 + /* init the waitq */
4788 + init_waitqueue_head( &dev->wait_q );
4790 + /* clear off the first few messages. these look like
4791 + * calibration or test data, i can't really tell
4792 + * this also flushes in case we have random ir data queued up
4796 + int partial = 0, retval, i;
4797 + for( i = 0; i < 40; i++ )
4799 + retval = usb_bulk_msg (udev,
4802 + dev->bulk_in_endpointAddr),
4808 + msir_cleanup( dev );
4810 + /* unlock this device */
4820 +static int mceusb_release (struct inode *inode, struct file *file)
4822 + struct usb_skel *dev;
4825 + dev = (struct usb_skel *)file->private_data;
4826 + if (dev == NULL) {
4827 + dbg (__FUNCTION__ " - object is NULL");
4831 + dbg(__FUNCTION__ " - minor %d", dev->minor);
4833 + /* lock our minor table */
4834 + down (&minor_table_mutex);
4836 + /* lock our device */
4839 + if (dev->open_count <= 0) {
4840 + dbg (__FUNCTION__ " - device not opened");
4842 + goto exit_not_opened;
4845 + if (dev->udev == NULL) {
4846 + /* the device was unplugged before the file was released */
4848 + mceusb_delete (dev);
4849 + up (&minor_table_mutex);
4850 + module_put(THIS_MODULE);
4854 + /* decrement our usage count for the device */
4855 + --dev->open_count;
4856 + if (dev->open_count <= 0) {
4857 + /* shutdown any bulk writes that might be going on */
4858 + usb_unlink_urb (dev->write_urb);
4859 + dev->open_count = 0;
4862 + /* decrement our usage count for the module */
4863 + module_put(THIS_MODULE);
4867 + up (&minor_table_mutex);
4872 +static void msir_cleanup( struct usb_skel* dev )
4874 + memset( dev->bulk_in_buffer, 0, dev->bulk_in_size );
4876 + memset( dev->usb_dbuffer, 0, sizeof(dev->usb_dbuffer) );
4877 + dev->usb_dstart = 0;
4878 + dev->usb_dcount = 0;
4879 + dev->usb_valid_bytes_in_bulk_buffer = 0;
4881 + memset( dev->mode2_data, 0, sizeof(dev->mode2_data) );
4882 + dev->mode2_partial_pkt_size = 0;
4883 + dev->mode2_count = 0;
4884 + dev->mode2_idx = 0;
4885 + dev->mode2_once = 0;
4886 + dev->last_was_repeat_gap = 0;
4889 +static int set_use_inc(void* data)
4891 + /* struct usb_skel* skel = (struct usb_skel*)data; */
4893 + try_module_get(THIS_MODULE);
4897 +static void set_use_dec(void* data)
4899 + /* check for unplug here */
4900 + struct usb_skel* dev = (struct usb_skel*) data;
4903 + lirc_unregister_plugin( dev->minor );
4904 + lirc_buffer_free( dev->plugin->rbuf );
4905 + kfree( dev->plugin->rbuf );
4906 + kfree( dev->plugin );
4909 + module_put(THIS_MODULE);
4912 +static int msir_available_mode2( struct usb_skel* dev )
4914 + return dev->mode2_count - dev->last_was_repeat_gap;
4917 +static int msir_available_data( struct usb_skel* dev )
4919 + return dev->usb_dcount;
4922 +static int msir_copy_mode2( struct usb_skel* dev, int* mode2_data, int count )
4924 + int words_to_read = count;
4925 + // int words_avail = dev->mode2_count;
4926 + int words_avail = msir_available_mode2( dev );
4928 + if( !dev->mode2_once && words_avail )
4930 + int space = PULSE_MASK;
4932 + copy_to_user( mode2_data, &space, 4 );
4933 + dev->mode2_once = 1;
4945 + if( !words_avail )
4950 + if( words_to_read > words_avail )
4952 + words_to_read = words_avail;
4955 + dbg(__FUNCTION__ " dev->mode2_count %d, dev->mode2_idx %d",
4956 + dev->mode2_count, dev->mode2_idx);
4957 + dbg(__FUNCTION__ " words_avail %d words_to_read %d",
4958 + words_avail, words_to_read);
4959 + copy_to_user( mode2_data, &( dev->mode2_data[dev->mode2_idx] ),
4960 + words_to_read<<2 );
4961 + dbg(__FUNCTION__ " would copy_to_user() %d w", words_to_read);
4963 + dev->mode2_idx += words_to_read;
4964 + dev->mode2_count -= words_to_read;
4966 + if( dev->mode2_count == 0 )
4968 + dev->mode2_idx = 0;
4970 + else if( dev->mode2_count == 1 && dev->last_was_repeat_gap )
4972 + // shift down the repeat gap and map it up to a
4973 + // lirc-acceptable value
4974 + dev->mode2_data[0] = dev->mode2_data[dev->mode2_idx];
4975 + if( dev->mode2_data[0] >= 60000 &&
4976 + dev->mode2_data[0] <= 70000 )
4977 + dev->mode2_data[0] = 95000;
4978 + //printk(__FUNCTION__ " shifting value %d down from %d prev %d\n", dev->mode2_data[0], dev->mode2_idx,
4979 + // dev->mode2_data[dev->mode2_idx-1]);
4980 + dev->mode2_idx = 0;
4983 + return words_to_read;
4986 +static int msir_read_from_buffer( struct usb_skel* dev, char* buffer, int len )
4988 + if( len > dev->usb_dcount )
4990 + len = dev->usb_dcount;
4992 + memcpy( buffer, dev->usb_dbuffer + dev->usb_dstart, len );
4996 +static int msir_mark_as_read( struct usb_skel* dev, int count )
4998 + // if( count != dev->usb_dcount )
4999 + // printk(KERN_INFO __FUNCTION__ " count %d dev->usb_dcount %d dev->usb_dstart %d", count, dev->usb_dcount, dev->usb_dstart );
5000 + if( count > dev->usb_dcount )
5001 + count = dev->usb_dcount;
5002 + dev->usb_dcount -= count;
5003 + dev->usb_dstart += count;
5005 + if( !dev->usb_dcount )
5006 + dev->usb_dstart = 0;
5013 + * msir_fetch_more_data
5015 + * The goal here is to read in more remote codes from the remote. In
5016 + * the event that the remote isn't sending us anything, the caller
5017 + * will block until a key is pressed (i.e. this performs phys read,
5018 + * filtering, and queueing of data) unless dont_block is set to 1; in
5019 + * this situation, it will perform a few reads and will exit out if it
5020 + * does not see any appropriate data
5022 + * dev->sem should be locked when this function is called - fine grain
5023 + * locking isn't really important here anyways
5025 + * TODO change this to do partials based on term codes, or not always fill
5028 +static int msir_fetch_more_data( struct usb_skel* dev, int dont_block )
5031 + int count, this_read, partial;
5033 + int writeindex, terminators = 0;
5034 + int bytes_to_read = sizeof(dev->usb_dbuffer) - dev->usb_dcount;
5035 + signed char* ibuf;
5036 + int sequential_empty_reads = 0;
5038 + /* special case where we are already full */
5039 + if( bytes_to_read == 0 )
5040 + return dev->usb_dcount;
5043 + if( dev->usb_dcount && dev->usb_dstart != 0 )
5045 + printk( __FUNCTION__ " shifting %d bytes from %d\n",
5046 + dev->usb_dcount, dev->usb_dstart );
5047 + memcpy( dev->usb_dbuffer, dev->usb_dbuffer + dev->usb_dstart,
5048 + dev->usb_dcount );
5051 + dev->usb_dstart = 0;
5053 + writeindex = dev->usb_dcount;
5055 + count = bytes_to_read;
5057 + ibuf = (signed char*)dev->bulk_in_buffer;
5058 + if( !dev->usb_valid_bytes_in_bulk_buffer )
5060 + memset( ibuf, 0, dev->bulk_in_size );
5064 + printk( __FUNCTION__ " going to read, dev->usb_dcount %d, bytes_to_read %d vbb %d\n", dev->usb_dcount, bytes_to_read,
5065 + dev->usb_valid_bytes_in_bulk_buffer );
5067 + /* 8 is the minimum read size */
5068 + while( count > 8 )
5070 + int i, goodbytes = 0;
5072 + /* break out if we were interrupted */
5073 + if( signal_pending(current) )
5075 + printk( __FUNCTION__ " got signal %ld\n",
5076 + current->pending.signal.sig[0]);
5077 + return dev->usb_dcount ? dev->usb_dcount : -EINTR;
5080 + /* or if we were unplugged */
5086 + /* or on data issues */
5087 + if( writeindex == sizeof(dev->usb_dbuffer) )
5089 + printk( __FUNCTION__ " buffer full, returning\n");
5090 + return dev->usb_dcount;
5093 + // always read the maximum
5094 + this_read = dev->bulk_in_size;
5098 + if( dev->usb_valid_bytes_in_bulk_buffer ) {
5100 + this_read = partial = dev->usb_valid_bytes_in_bulk_buffer;
5101 + dev->usb_valid_bytes_in_bulk_buffer = 0;
5103 + // This call always returns almost immediately
5104 + // with data, since this device will always
5105 + // provide a 2 byte response on a bulk
5106 + // read. Not exactly friendly to the usb bus
5107 + // or our load avg. We attempt to compensate
5108 + // for this on 2 byte reads below
5110 + memset( ibuf, 0, dev->bulk_in_size );
5111 + retval = usb_bulk_msg (dev->udev,
5114 + dev->bulk_in_endpointAddr),
5115 + (unsigned char*)ibuf, this_read,
5121 + /* break out on errors */
5122 + printk(__FUNCTION__ " got retval %d %d %d",
5123 + retval, this_read, partial );
5124 + if( retval == USB_ST_DATAOVERRUN && retries < 5 )
5127 + interruptible_sleep_on_timeout
5128 + ( &dev->wait_q, HZ );
5141 + this_read = partial;
5144 + /* All packets i've seen start with b1 60. If no data
5145 + * was actually available, the transceiver still gives
5146 + * this byte pair back. We only care about actual
5147 + * codes, so we can safely ignore these 2 byte reads
5149 + if( this_read > 2 )
5152 + printk( __FUNCTION__ " read %d bytes partial %d goodbytes %d writeidx %d\n",
5153 + this_read, partial, goodbytes, writeindex );
5155 + sequential_empty_reads = 0;
5156 + /* copy from the input buffer to the capture buffer */
5157 + for( i = 0; i < this_read; i++ )
5159 + if( (((unsigned char*)ibuf)[i] == 0xb1) ||
5160 + (ibuf[i] == 0x60) )
5164 + if( writeindex == sizeof(dev->usb_dbuffer) )
5166 + /* this can happen in
5168 + * basically the bulk
5169 + * buffer is getting
5171 + * aren't processing
5172 + * data fast enough
5175 + dev->usb_valid_bytes_in_bulk_buffer = this_read - i;
5176 + memcpy( ibuf, &( ibuf[i] ),
5177 + dev->usb_valid_bytes_in_bulk_buffer );
5181 + dev->usb_dbuffer[writeindex++] = ibuf[i];
5184 + if( ibuf[i] == 0x7f )
5188 + /* This is a bug - we should either get 10 or 15 */
5189 + if( terminators > 15 )
5191 + dbg("bugbug - terminators %d at %d gb %d", terminators, i, goodbytes );
5193 + dbg("terminator %d at %d gb %d", terminators, i, goodbytes );
5194 + dbg("writeindex %d", writeindex);
5196 + else if( terminators )
5198 + if( ((unsigned char*)ibuf)[i] == 128 )
5200 + /* copy back any remainder and break out */
5201 + dev->usb_valid_bytes_in_bulk_buffer = this_read - (i + 1);
5202 + if( dev->usb_valid_bytes_in_bulk_buffer )
5204 + memcpy( ibuf, &( ibuf[i+1] ), dev->usb_valid_bytes_in_bulk_buffer );
5210 + if( terminators == 10 ||
5211 + terminators == 15 )
5212 + dbg("post-termination data %d idx %d %d", ibuf[i], dev->usb_dcount, i);
5216 + dev->usb_dcount += goodbytes;
5217 + count -= goodbytes;
5219 + sequential_empty_reads++;
5222 + if( dont_block && sequential_empty_reads == 5 )
5225 + // Try to be nice to the usb bus by sleeping
5226 + // for a bit here before going in to the next
5228 + interruptible_sleep_on_timeout( &dev->wait_q, 1 );
5232 + /* return the number of bytes available now */
5233 + return dev->usb_dcount;
5236 +// layout of data, per Christoph Bartelmus
5237 +// The protocol is:
5238 +// 1 byte: -length of following packet
5239 +// the following bytes of the packet are:
5241 +// -(number of time units) of pulse
5243 +// (number of time units) of space
5244 +// one time unit is 50us
5246 +#define MCE_TIME_UNIT 50
5248 +// returns the number of bytes processed from the 'usb_data' array
5249 +static int msir_generate_mode2( struct usb_skel* dev, signed char* usb_data,
5252 + int bytes_left_in_packet = 0;
5254 + int mode2count = 0;
5255 + int last_was_pulse = 1;
5257 + int split_pkt_size = 0;
5258 + // XXX no bounds checking here
5260 + int mode2_limit = sizeof( dev->mode2_data ) - dev->mode2_count;
5262 + // If data exists in the buffer, we have to point to the last
5263 + // item there so we can append consecutive pulse/space
5264 + // ops. Otherwise, set last_was_pulse 1 (since the first byte
5265 + // is a pulse, and we want to store in the first array
5267 + if( dev->mode2_count == 0 )
5269 + mode2_data = &( dev->mode2_data[0] );
5270 + last_was_pulse = (dev->mode2_once ? 1 : 0);
5271 + mode2_data[0] = 0;
5275 + mode2_data = &( dev->mode2_data[dev->mode2_idx +
5276 + dev->mode2_count - 1] );
5277 + last_was_pulse = (mode2_data[0] & PULSE_BIT) ? 1 : 0;
5280 + while( pos < bytecount && !last_pkt &&
5281 + (mode2_limit > (dev->mode2_count + mode2count)) )
5283 + if( dev->mode2_partial_pkt_size )
5285 + bytes_left_in_packet = dev->mode2_partial_pkt_size;
5286 + dev->mode2_partial_pkt_size = 0;
5289 + bytes_left_in_packet = 128 + usb_data[pos];
5291 + // XXX out of sync? find the next packet
5292 + // header, establish a distance, and fix the
5294 + if( bytes_left_in_packet > 4 )
5297 + for( i = pos + 1; i < pos + 4; i++ )
5299 + if( (int)(128 + usb_data[i]) <= 4 )
5301 + bytes_left_in_packet = i - pos;
5308 + // otherwise, increment past the header
5313 + // special case where we have a terminator at the
5314 + // start but not at the end of this packet, indicating
5315 + // potential repeat, or the packet is less than 4
5316 + // bytes, indicating end also special case a split
5317 + // starting packet
5318 + if( pos > 1 && bytes_left_in_packet < 4 )
5323 + else if( usb_data[pos] == 127 &&
5324 + usb_data[pos+bytes_left_in_packet-1] != 127 )
5326 + // the genius ir transciever is blending data
5327 + // from the repeat events into a single
5328 + // packet. how we handle this is by splitting
5329 + // the packet (and truncating the packet size
5330 + // value we read), then rewriting a new packet
5331 + // header onto the outbound data. it's
5333 + while( usb_data[pos+bytes_left_in_packet-1] != 127 )
5335 + bytes_left_in_packet--;
5341 + while( bytes_left_in_packet && pos < bytecount )
5343 + int keycode = usb_data[pos];
5352 + keycode *= MCE_TIME_UNIT;
5354 + // on a state change, increment the position
5355 + // for the output buffer and initialize the
5356 + // current spot to 0; otherwise we need to
5357 + // concatenate pulse/gap values for lirc to be
5359 + if( pulse != last_was_pulse &&
5360 + (mode2count || mode2_data[mode2count]))
5362 + if( dev->last_was_repeat_gap )
5364 + //printk( __FUNCTION__ " transition with lwrg set lastval %d idx1 %d idx2 %d\n",
5365 + // mode2_data[mode2count],mode2count, dev->mode2_count+dev->mode2_idx-1 );
5368 + mode2_data[mode2count] = 0;
5371 + mode2_data[mode2count] += keycode;
5373 + // Or in the pulse bit, and map all gap
5374 + // lengths to a fixed value; this makes lirc
5375 + // happy, sort of.
5377 + mode2_data[mode2count] |= PULSE_BIT;
5378 + dev->last_was_repeat_gap = 0;
5381 + last_was_pulse = pulse;
5382 + bytes_left_in_packet--;
5386 + // If the last value in the data array is a repeat gap, set
5387 + // the last_was_repeat_gap flag
5388 + if( mode2_data[mode2count] > 20000 && mode2_data[mode2count] < 70000 )
5390 + // printk(__FUNCTION__ " setting lwrg for val %d idx1 %d idx2 %d\n",
5391 + // mode2_data[mode2count], mode2count, dev->mode2_count+dev->mode2_idx-1 );
5392 + dev->last_was_repeat_gap = 1;
5394 + dev->last_was_repeat_gap = 0;
5397 + // this is a bit tricky; we need to change to a counter, but
5398 + // if we already had data in dev->mode2_data, then byte 0
5399 + // actually was pre-existing data and shouldn't be counted
5400 + if( mode2count && !dev->mode2_count )
5403 + // printk(__FUNCTION__ " mode2count++ to %d\n", mode2count);
5406 + // never lie about how much output we have
5407 + dev->mode2_count += mode2count;
5409 + if( last_pkt == 1 )
5415 + // note the partial pkt size, and make sure we only claim
5416 + // the bytes we processed
5417 + if( last_pkt == 2 )
5419 + dev->mode2_partial_pkt_size = split_pkt_size;
5422 + // XXX this i am not sure about; it seems like this should be required, but it
5423 + // isn't, and seems to cause problems
5426 + dev->mode2_partial_pkt_size = bytes_left_in_packet;
5433 +static ssize_t mceusb_read( struct file* file, char* buffer,
5434 + size_t count, loff_t* ppos)
5436 + char _data_buffer[128];
5437 + struct usb_skel* dev;
5439 + int bytes_copied = 0;
5441 + dev = (struct usb_skel*) file->private_data;
5443 + if( (count % 4) != 0 )
5448 + down( &dev->sem );
5450 + /* verify that the device wasn't unplugged */
5451 + if (dev->udev == NULL) {
5456 + dbg(__FUNCTION__ " (1) calling msir_copy_mode2 with %d", count);
5457 + bytes_copied = 4 * msir_copy_mode2( dev, (int*)buffer, count >> 2 );
5458 + if( bytes_copied == count )
5464 + /* we didn't get enough mode2 data. the process now is a bit complex
5465 + * 1. see if we have data read from the usb device that hasn't
5466 + * been converted to mode2; if so, convert that, and try to
5468 + * 2. otherwise, go ahead and read more, then convert that, then copy
5471 + if( dev->usb_dcount )
5473 + read_count = msir_read_from_buffer( dev, _data_buffer, 128 );
5474 + read_count = msir_generate_mode2
5475 + ( dev, (signed char*)_data_buffer, read_count );
5476 + msir_mark_as_read( dev, read_count );
5477 + bytes_copied += (4 * msir_copy_mode2
5478 + ( dev, (int*)(buffer + bytes_copied),
5479 + (count-bytes_copied) >> 2 ));
5482 + if( bytes_copied == count )
5488 + /* read more data in a loop until we get enough */
5489 + while( bytes_copied < count )
5491 + read_count = msir_fetch_more_data
5492 + ( dev, (file->f_flags & O_NONBLOCK ? 1 : 0) );
5494 + if( read_count <= 0 )
5497 + return (read_count ? read_count : -EWOULDBLOCK);
5500 + read_count = msir_read_from_buffer( dev, _data_buffer, 128 );
5501 + read_count = msir_generate_mode2
5502 + ( dev, (signed char*)_data_buffer, read_count );
5503 + msir_mark_as_read( dev, read_count );
5505 + bytes_copied += (4 * msir_copy_mode2
5506 + ( dev, (int*)(buffer + bytes_copied),
5507 + (count-bytes_copied) >> 2 ));
5511 + return bytes_copied;
5517 +static unsigned int mceusb_poll(struct file* file, poll_table* wait)
5519 + struct usb_skel* dev;
5521 + dev = (struct usb_skel*)file->private_data;
5523 + // So this is a crummy poll. Unfortunately all the lirc tools
5524 + // assume your hardware is interrupt driven. Instead, we have
5525 + // to actually read here to see whether or not there is data
5526 + // (unless we have a key saved up - unlikely )
5528 + // if( dev->usb_dcount || dev->mode2_count )
5529 + if( msir_available_data( dev ) || msir_available_mode2( dev ) )
5531 + return POLLIN | POLLRDNORM;
5534 + down( &dev->sem );
5535 + data = msir_fetch_more_data( dev, 1 );
5539 + return POLLIN | POLLRDNORM;
5548 +static ssize_t mceusb_write (struct file *file, const char *buffer, size_t count, loff_t *ppos)
5550 + struct usb_skel *dev;
5551 + ssize_t bytes_written = 0;
5554 + dev = (struct usb_skel *)file->private_data;
5556 + dbg(__FUNCTION__ " - minor %d, count = %d", dev->minor, count);
5558 + /* lock this object */
5561 + /* verify that the device wasn't unplugged */
5562 + if (dev->udev == NULL) {
5567 + /* verify that we actually have some data to write */
5569 + dbg(__FUNCTION__ " - write request of 0 bytes");
5573 + /* see if we are already in the middle of a write */
5574 + if (dev->write_urb->status == -EINPROGRESS) {
5575 + dbg (__FUNCTION__ " - already writing");
5579 + /* we can only write as much as 1 urb will hold */
5580 + bytes_written = (count > dev->bulk_out_size) ?
5581 + dev->bulk_out_size : count;
5583 + /* copy the data from userspace into our urb */
5584 + if (copy_from_user(dev->write_urb->transfer_buffer, buffer,
5590 + usb_mceusb_debug_data (__FUNCTION__, bytes_written,
5591 + dev->write_urb->transfer_buffer);
5593 + /* set up our urb */
5594 + FILL_BULK_URB(dev->write_urb, dev->udev,
5595 + usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr),
5596 + dev->write_urb->transfer_buffer, bytes_written,
5597 + mceusb_write_bulk_callback, dev);
5599 + /* send the data out the bulk port */
5600 + retval = usb_submit_urb(dev->write_urb);
5602 + err(__FUNCTION__ " - failed submitting write urb, error %d",
5605 + retval = bytes_written;
5609 + /* unlock the device */
5616 + * mceusb_write_bulk_callback
5619 +static void mceusb_write_bulk_callback (struct urb *urb)
5621 + struct usb_skel *dev = (struct usb_skel *)urb->context;
5623 + dbg(__FUNCTION__ " - minor %d", dev->minor);
5625 + if ((urb->status != -ENOENT) &&
5626 + (urb->status != -ECONNRESET)) {
5627 + dbg(__FUNCTION__ " - nonzero write bulk status received: %d",
5638 + * Called by the usb core when a new device is connected that it
5639 + * thinks this driver might be interested in.
5641 +static void * mceusb_probe(struct usb_device *udev, unsigned int ifnum,
5642 + const struct usb_device_id *id)
5644 + struct usb_skel *dev = NULL;
5645 + struct usb_interface *interface;
5646 + struct usb_interface_descriptor *iface_desc;
5647 + struct usb_endpoint_descriptor *endpoint;
5648 + struct lirc_plugin* plugin;
5649 + struct lirc_buffer* rbuf;
5657 + /* See if the device offered us matches what we can accept */
5658 + if ((udev->descriptor.idVendor != USB_MCEUSB_VENDOR_ID) ||
5659 + (udev->descriptor.idProduct != USB_MCEUSB_PRODUCT_ID)) {
5663 + /* select a "subminor" number (part of a minor number) */
5664 + down (&minor_table_mutex);
5665 + for (minor = 0; minor < MAX_DEVICES; ++minor) {
5666 + if (minor_table[minor] == NULL)
5669 + if (minor >= MAX_DEVICES) {
5670 + info ("Too many devices plugged in, can not handle this device.");
5674 + /* allocate memory for our device state and intialize it */
5675 + dev = kmalloc (sizeof(struct usb_skel), GFP_KERNEL);
5676 + if (dev == NULL) {
5677 + err ("Out of memory");
5680 + minor_table[minor] = dev;
5682 + interface = &udev->actconfig->interface[ifnum];
5684 + init_MUTEX (&dev->sem);
5686 + dev->interface = interface;
5687 + dev->minor = minor;
5689 + /* set up the endpoint information */
5690 + /* check out the endpoints */
5691 + iface_desc = &interface->altsetting[0];
5692 + for (i = 0; i < iface_desc->bNumEndpoints; ++i) {
5693 + endpoint = &iface_desc->endpoint[i];
5695 + if ((endpoint->bEndpointAddress & 0x80) &&
5696 + ((endpoint->bmAttributes & 3) == 0x02)) {
5697 + /* we found a bulk in endpoint */
5698 + buffer_size = endpoint->wMaxPacketSize;
5699 + dev->bulk_in_size = buffer_size;
5700 + dev->bulk_in_endpointAddr = endpoint->bEndpointAddress;
5701 + dev->bulk_in_buffer = kmalloc (buffer_size, GFP_KERNEL);
5702 + if (!dev->bulk_in_buffer) {
5703 + err("Couldn't allocate bulk_in_buffer");
5708 + if (((endpoint->bEndpointAddress & 0x80) == 0x00) &&
5709 + ((endpoint->bmAttributes & 3) == 0x02)) {
5710 + /* we found a bulk out endpoint */
5711 + dev->write_urb = usb_alloc_urb(0);
5712 + if (!dev->write_urb) {
5713 + err("No free urbs available");
5716 + buffer_size = endpoint->wMaxPacketSize;
5717 + dev->bulk_out_size = buffer_size;
5718 + dev->bulk_out_endpointAddr = endpoint->bEndpointAddress;
5719 + dev->bulk_out_buffer = kmalloc (buffer_size, GFP_KERNEL);
5720 + if (!dev->bulk_out_buffer) {
5721 + err("Couldn't allocate bulk_out_buffer");
5724 + FILL_BULK_URB(dev->write_urb, udev,
5726 + (udev, endpoint->bEndpointAddress),
5727 + dev->bulk_out_buffer, buffer_size,
5728 + mceusb_write_bulk_callback, dev);
5732 + memset( dev->mode2_data, 0, sizeof( dev->mode2_data ) );
5733 + dev->mode2_idx = 0;
5734 + dev->mode2_count = 0;
5735 + dev->mode2_partial_pkt_size = 0;
5736 + dev->mode2_once = 0;
5737 + dev->last_was_repeat_gap = 0;
5739 + /* Set up our lirc plugin */
5740 + if(!(plugin = kmalloc(sizeof(struct lirc_plugin), GFP_KERNEL))) {
5741 + err("out of memory");
5744 + memset( plugin, 0, sizeof(struct lirc_plugin) );
5746 + if(!(rbuf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL))) {
5747 + err("out of memory");
5751 + /* the lirc_atiusb module doesn't memset rbuf here ... ? */
5752 + if( lirc_buffer_init( rbuf, sizeof(lirc_t),
5753 + sizeof(struct lirc_buffer))) {
5754 + err("out of memory");
5759 + strcpy(plugin->name, "lirc_mce ");
5760 + plugin->minor = minor;
5761 + plugin->code_length = sizeof(lirc_t);
5762 + plugin->features = LIRC_CAN_REC_MODE2; // | LIRC_CAN_SEND_MODE2;
5763 + plugin->data = dev;
5764 + plugin->rbuf = rbuf;
5765 + plugin->ioctl = NULL;
5766 + plugin->set_use_inc = &set_use_inc;
5767 + plugin->set_use_dec = &set_use_dec;
5768 + plugin->fops = &mceusb_fops;
5769 + if( lirc_register_plugin( plugin ) < 0 )
5772 + lirc_buffer_free( rbuf );
5776 + dev->plugin = plugin;
5778 + mceusb_setup( udev );
5780 + /* let the user know what node this device is now attached to */
5781 + info ("USB Microsoft IR Transceiver device now attached to msir%d",
5786 + mceusb_delete (dev);
5790 + up (&minor_table_mutex);
5795 + * mceusb_disconnect
5797 + * Called by the usb core when the device is removed from the system.
5799 +static void mceusb_disconnect(struct usb_device *udev, void *ptr)
5803 + down (&minor_table_mutex);
5806 + minor = dev->minor;
5808 + /* unhook lirc things */
5809 + lirc_unregister_plugin( dev->minor );
5810 + lirc_buffer_free( dev->plugin->rbuf );
5811 + kfree( dev->plugin->rbuf );
5812 + kfree( dev->plugin );
5814 + /* if the device is not opened, then we clean up right now */
5815 + if (!dev->open_count) {
5817 + mceusb_delete (dev);
5823 + info("USB Skeleton #%d now disconnected", minor);
5824 + up (&minor_table_mutex);
5833 +static int __init usb_mceusb_init(void)
5837 + /* register this driver with the USB subsystem */
5838 + result = usb_register(&mceusb_driver);
5840 + err("usb_register failed for the "__FILE__" driver. Error number %d",
5845 + info(DRIVER_DESC " " DRIVER_VERSION);
5853 +static void __exit usb_mceusb_exit(void)
5855 + /* deregister this driver with the USB subsystem */
5856 + usb_deregister(&mceusb_driver);
5860 +module_init (usb_mceusb_init);
5861 +module_exit (usb_mceusb_exit);
5863 +MODULE_AUTHOR(DRIVER_AUTHOR);
5864 +MODULE_DESCRIPTION(DRIVER_DESC);
5865 +MODULE_LICENSE("GPL");
5867 diff -uprN -X dontdiff linux-2.6.5.orig/drivers/char/lirc/lirc_parallel.c linux-2.6.5/drivers/char/lirc/lirc_parallel.c
5868 --- linux-2.6.5.orig/drivers/char/lirc/lirc_parallel.c 1970-01-01 01:00:00.000000000 +0100
5869 +++ linux-2.6.5/drivers/char/lirc/lirc_parallel.c 2004-04-04 14:05:29.424626048 +0200
5873 +/****************************************************************************
5874 + ** lirc_parallel.c *********************************************************
5875 + ****************************************************************************
5877 + * lirc_parallel - device driver for infra-red signal receiving and
5878 + * transmitting unit built by the author
5880 + * Copyright (C) 1998 Christoph Bartelmus <lirc@bartelmus.de>
5882 + * This program is free software; you can redistribute it and/or modify
5883 + * it under the terms of the GNU General Public License as published by
5884 + * the Free Software Foundation; either version 2 of the License, or
5885 + * (at your option) any later version.
5887 + * This program is distributed in the hope that it will be useful,
5888 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5889 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5890 + * GNU General Public License for more details.
5892 + * You should have received a copy of the GNU General Public License
5893 + * along with this program; if not, write to the Free Software
5894 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
5898 +/***********************************************************************
5899 + ************************* Includes ***********************
5900 + ***********************************************************************/
5902 +#include <linux/version.h>
5904 +#include <linux/config.h>
5906 +#include <linux/module.h>
5907 +#include <linux/sched.h>
5908 +#include <linux/errno.h>
5909 +#include <linux/signal.h>
5910 +#include <linux/config.h>
5911 +#include <linux/fs.h>
5912 +#include <linux/kernel.h>
5913 +#include <linux/ioport.h>
5914 +#include <linux/time.h>
5915 +#include <linux/mm.h>
5916 +#include <linux/delay.h>
5917 +#include <linux/init.h>
5919 +#include <asm/io.h>
5920 +#include <asm/signal.h>
5921 +#include <asm/irq.h>
5922 +#include <asm/system.h>
5924 +#include <asm/uaccess.h>
5925 +#include <linux/poll.h>
5926 +#include <linux/parport.h>
5928 +#include <linux/lirc.h>
5929 +#include "lirc_dev.h"
5931 +#include "lirc_parallel.h"
5933 +#define LIRC_DRIVER_NAME "lirc_parallel"
5935 +/***********************************************************************
5936 + ************************* Globale Variablen ***********************
5937 + ***********************************************************************/
5939 +unsigned int irq = CONFIG_LIRC_IRQ_PARALLEL;
5940 +unsigned int io = CONFIG_LIRC_PORT_PARALLEL;
5941 +#ifdef CONFIG_LIRC_TIMER
5942 +unsigned int timer = 0;
5943 +unsigned int default_timer = CONFIG_LIRC_TIMER;
5946 +#define WBUF_SIZE (256)
5947 +#define RBUF_SIZE (256) /* this must be a power of 2 larger than 1 */
5949 +static lirc_t wbuf[WBUF_SIZE];
5950 +static lirc_t rbuf[RBUF_SIZE];
5952 +DECLARE_WAIT_QUEUE_HEAD(lirc_wait);
5954 +unsigned int rptr=0,wptr=0;
5955 +unsigned int lost_irqs=0;
5958 +struct parport *pport;
5959 +struct pardevice *ppdevice;
5962 +int pf(void *handle);
5963 +void kf(void *handle);
5965 +/***********************************************************************
5966 + ************************* Interne Funktionen ***********************
5967 + ***********************************************************************/
5969 +unsigned int __inline__ in(int offset)
5973 + case LIRC_LP_BASE:
5974 + return(parport_read_data(pport));
5975 + case LIRC_LP_STATUS:
5976 + return(parport_read_status(pport));
5977 + case LIRC_LP_CONTROL:
5978 + return(parport_read_control(pport));
5980 + return(0); /* make compiler happy */
5983 +void __inline__ out(int offset, int value)
5987 + case LIRC_LP_BASE:
5988 + parport_write_data(pport,value);
5990 + case LIRC_LP_CONTROL:
5991 + parport_write_control(pport,value);
5993 + case LIRC_LP_STATUS:
5994 + printk(KERN_INFO "%s: attempt to write to status register\n",
5995 + LIRC_DRIVER_NAME);
6000 +unsigned int __inline__ lirc_get_timer(void)
6002 + return(in(LIRC_PORT_TIMER)&LIRC_PORT_TIMER_BIT);
6005 +unsigned int __inline__ lirc_get_signal(void)
6007 + return(in(LIRC_PORT_SIGNAL)&LIRC_PORT_SIGNAL_BIT);
6010 +void __inline__ lirc_on(void)
6012 + out(LIRC_PORT_DATA,LIRC_PORT_DATA_BIT);
6015 +void __inline__ lirc_off(void)
6017 + out(LIRC_PORT_DATA,0);
6020 +unsigned int init_CONFIG_LIRC_TIMER(void)
6022 + struct timeval tv,now;
6023 + unsigned int level,newlevel,timeelapsed,newtimer;
6026 + do_gettimeofday(&tv);
6027 + tv.tv_sec++; /* wait max. 1 sec. */
6028 + level=lirc_get_timer();
6031 + newlevel=lirc_get_timer();
6032 + if(level==0 && newlevel!=0) count++;
6034 + do_gettimeofday(&now);
6036 + while(count<1000 && (now.tv_sec<tv.tv_sec
6037 + || (now.tv_sec==tv.tv_sec
6038 + && now.tv_usec<tv.tv_usec)));
6040 + timeelapsed=((now.tv_sec+1-tv.tv_sec)*1000000
6041 + +(now.tv_usec-tv.tv_usec));
6042 + if(count>=1000 && timeelapsed>0)
6044 + if(default_timer==0) /* autodetect timer */
6046 + newtimer=(1000000*count)/timeelapsed;
6047 + printk(KERN_INFO "%s: %u Hz timer detected\n",
6048 + LIRC_DRIVER_NAME,newtimer);
6053 + newtimer=(1000000*count)/timeelapsed;
6054 + if(abs(newtimer-default_timer)>
6055 + default_timer/10) /* bad timer */
6057 + printk(KERN_NOTICE "%s: bad timer: %u Hz\n",
6058 + LIRC_DRIVER_NAME,newtimer);
6059 + printk(KERN_NOTICE "%s: using default timer: "
6061 + LIRC_DRIVER_NAME,default_timer);
6062 + return(default_timer);
6066 + printk(KERN_INFO "%s: %u Hz timer detected\n",
6067 + LIRC_DRIVER_NAME,newtimer);
6068 + return(newtimer); /* use detected value */
6074 + printk(KERN_NOTICE "%s: no timer detected\n",LIRC_DRIVER_NAME);
6079 +int lirc_claim(void)
6081 + if(parport_claim(ppdevice)!=0)
6083 + printk(KERN_WARNING "%s: could not claim port\n",
6084 + LIRC_DRIVER_NAME);
6085 + printk(KERN_WARNING "%s: waiting for port becoming available"
6086 + "\n",LIRC_DRIVER_NAME);
6087 + if(parport_claim_or_block(ppdevice)<0)
6089 + printk(KERN_NOTICE "%s: could not claim port, giving"
6090 + " up\n",LIRC_DRIVER_NAME);
6094 + out(LIRC_LP_CONTROL,LP_PSELECP|LP_PINITP);
6099 +/***********************************************************************
6100 + ************************* interrupt handler ************************
6101 + ***********************************************************************/
6103 +static inline void rbuf_write(lirc_t signal)
6105 + unsigned int nwptr;
6107 + nwptr=(wptr+1) & (RBUF_SIZE-1);
6108 + if(nwptr==rptr) /* no new signals will be accepted */
6111 + printk(KERN_NOTICE "%s: buffer overrun\n",LIRC_DRIVER_NAME);
6114 + rbuf[wptr]=signal;
6118 +void irq_handler(int i,void *blah,struct pt_regs * regs)
6120 + struct timeval tv;
6121 + static struct timeval lasttv;
6122 + static int init=0;
6125 + unsigned int level,newlevel;
6126 + unsigned int timeout;
6128 +#ifdef CONFIG_MODULE_UNLOAD
6129 + if(!module_refcount(THIS_MODULE))
6138 + /* disable interrupt */
6141 + out(LIRC_PORT_IRQ,in(LIRC_PORT_IRQ)&(~LP_PINTEN));
6143 + if(in(1)&LP_PSELECD)
6148 +#ifdef CONFIG_LIRC_TIMER
6151 + do_gettimeofday(&tv);
6153 + signal=tv.tv_sec-lasttv.tv_sec;
6156 + data=PULSE_MASK; /* really long time */
6160 + data=(lirc_t) (signal*1000000+
6161 + tv.tv_usec-lasttv.tv_usec+
6162 + LIRC_SFH506_DELAY);
6165 + rbuf_write(data); /* space */
6169 + if(timer==0) /* wake up; we'll lose this signal
6170 + but it will be garbage if the device
6171 + is turned on anyway
6174 + timer=init_CONFIG_LIRC_TIMER();
6175 + /* enable_irq(irq); */
6181 + timeout=timer/10; /* timeout after 1/10 sec. */
6183 + level=lirc_get_timer();
6185 + newlevel=lirc_get_timer();
6186 + if(level==0 && newlevel!=0) signal++;
6190 + if(signal>timeout || (in(1)&LP_PSELECD))
6193 + printk(KERN_NOTICE "%s: timeout\n",LIRC_DRIVER_NAME);
6197 + while(lirc_get_signal());
6200 + /* ajust value to usecs */
6201 + signal=(long) (((unsigned long long) signal)*1000000)/timer;
6203 + if(signal>LIRC_SFH506_DELAY)
6205 + data=signal-LIRC_SFH506_DELAY;
6211 + rbuf_write(PULSE_BIT|data); /* pulse */
6213 + do_gettimeofday(&lasttv);
6215 + /* add your code here */
6218 + wake_up_interruptible(&lirc_wait);
6220 + /* enable interrupt */
6223 + out(LIRC_PORT_IRQ,in(LIRC_PORT_IRQ)|LP_PINTEN);
6227 +/***********************************************************************
6228 + ************************** file_operations ************************
6229 + ***********************************************************************/
6231 +static loff_t lirc_lseek(struct file *filep,loff_t offset,int orig)
6236 +static ssize_t lirc_read(struct file *filep,char *buf,size_t n,loff_t *ppos)
6240 + DECLARE_WAITQUEUE(wait, current);
6242 + if(n%sizeof(lirc_t)) return(-EINVAL);
6244 + result=verify_area(VERIFY_WRITE,buf,n);
6245 + if(result) return(result);
6247 + add_wait_queue(&lirc_wait,&wait);
6248 + current->state=TASK_INTERRUPTIBLE;
6253 + copy_to_user(buf+count,(char *) &rbuf[rptr],
6255 + rptr=(rptr+1)&(RBUF_SIZE-1);
6256 + count+=sizeof(lirc_t);
6260 + if(filep->f_flags & O_NONBLOCK)
6265 + if (signal_pending(current))
6267 + result=-ERESTARTSYS;
6271 + current->state=TASK_INTERRUPTIBLE;
6274 + remove_wait_queue(&lirc_wait,&wait);
6275 + current->state=TASK_RUNNING;
6276 + return(count ? count:result);
6279 +static ssize_t lirc_write(struct file *filep,const char *buf,size_t n,
6284 + unsigned int level,newlevel;
6285 + unsigned long flags;
6286 + lirc_t counttimer;
6292 + if(n%sizeof(lirc_t)) return(-EINVAL);
6293 + result=verify_area(VERIFY_READ,buf,n);
6294 + if(result) return(result);
6296 + count=n/sizeof(lirc_t);
6298 + if(count>WBUF_SIZE || count%2==0) return(-EINVAL);
6300 + copy_from_user(wbuf,buf,n);
6302 +#ifdef CONFIG_LIRC_TIMER
6303 + if(timer==0) /* try again if device is ready */
6305 + timer=init_CONFIG_LIRC_TIMER();
6306 + if(timer==0) return(-EIO);
6309 + /* ajust values from usecs */
6310 + for(i=0;i<count;i++)
6312 + wbuf[i]=(lirc_t) (((double) wbuf[i])*timer/1000000);
6315 + local_save_flags(flags);local_irq_disable();
6319 + level=lirc_get_timer();
6324 + newlevel=lirc_get_timer();
6325 + if(level==0 && newlevel!=0) counttimer++;
6327 + if(in(1)&LP_PSELECD)
6330 + local_irq_restore(flags); /* sti(); */
6334 + while(counttimer<wbuf[i]);i++;
6337 + if(i==count) break;
6341 + newlevel=lirc_get_timer();
6342 + if(level==0 && newlevel!=0) counttimer++;
6344 + if(in(1)&LP_PSELECD)
6346 + local_irq_restore(flags); /* sti(); */
6350 + while(counttimer<wbuf[i]);i++;
6352 + local_irq_restore(flags); /* sti(); */
6355 + place code that handles write
6356 + without extarnal timer here
6362 +static unsigned int lirc_poll(struct file *file, poll_table * wait)
6364 + poll_wait(file, &lirc_wait,wait);
6366 + return(POLLIN|POLLRDNORM);
6370 +static int lirc_ioctl(struct inode *node,struct file *filep,unsigned int cmd,
6371 + unsigned long arg)
6374 + unsigned long features=LIRC_CAN_SEND_PULSE|LIRC_CAN_REC_MODE2,mode;
6378 + case LIRC_GET_FEATURES:
6379 + result=put_user(features,(unsigned long *) arg);
6380 + if(result) return(result);
6382 + case LIRC_GET_SEND_MODE:
6383 + result=put_user(LIRC_MODE_PULSE,(unsigned long *) arg);
6384 + if(result) return(result);
6386 + case LIRC_GET_REC_MODE:
6387 + result=put_user(LIRC_MODE_MODE2,(unsigned long *) arg);
6388 + if(result) return(result);
6390 + case LIRC_SET_SEND_MODE:
6391 + result=get_user(mode,(unsigned long *) arg);
6392 + if(result) return(result);
6393 + if(mode!=LIRC_MODE_PULSE) return(-EINVAL);
6395 + case LIRC_SET_REC_MODE:
6396 + result=get_user(mode,(unsigned long *) arg);
6397 + if(result) return(result);
6398 + if(mode!=LIRC_MODE_MODE2) return(-ENOSYS);
6401 + return(-ENOIOCTLCMD);
6406 +static int lirc_open(struct inode* node,struct file* filep)
6408 +#ifdef CONFIG_MODULE_UNLOAD
6409 + if(module_refcount(THIS_MODULE))
6418 + pport->ops->enable_irq(pport);
6420 + /* init read ptr */
6424 + try_module_get(THIS_MODULE);
6429 +static int lirc_close(struct inode* node,struct file* filep)
6434 + parport_release(ppdevice);
6437 + module_put(THIS_MODULE);
6441 +static struct file_operations lirc_fops =
6443 + llseek: lirc_lseek,
6445 + write: lirc_write,
6447 + ioctl: lirc_ioctl,
6449 + release: lirc_close
6452 +static int set_use_inc(void* data)
6454 +#if WE_DONT_USE_LOCAL_OPEN_CLOSE
6455 + try_module_get(THIS_MODULE);
6460 +static void set_use_dec(void* data)
6462 +#if WE_DONT_USE_LOCAL_OPEN_CLOSE
6463 + module_put(THIS_MODULE);
6466 +static struct lirc_plugin plugin = {
6467 + name: LIRC_DRIVER_NAME,
6474 + set_use_inc: set_use_inc,
6475 + set_use_dec: set_use_dec,
6479 +static int __init lirc_parallel_init (void)
6481 + pport=parport_enumerate();
6482 + while(pport!=NULL)
6484 + if(pport->base==io)
6488 + pport=pport->next;
6492 + printk(KERN_NOTICE "%s: no port at %x found\n",
6493 + LIRC_DRIVER_NAME,io);
6496 + ppdevice=parport_register_device(pport,LIRC_DRIVER_NAME,
6497 + pf,kf,irq_handler,0,NULL);
6498 + if(ppdevice==NULL)
6500 + printk(KERN_NOTICE "%s: parport_register_device() failed\n",
6501 + LIRC_DRIVER_NAME);
6504 + if(parport_claim(ppdevice)!=0)
6507 + out(LIRC_LP_CONTROL,LP_PSELECP|LP_PINITP);
6509 +#ifdef CONFIG_LIRC_TIMER
6511 + out(LIRC_PORT_DATA,LIRC_PORT_DATA_BIT);
6514 + timer=init_CONFIG_LIRC_TIMER();
6516 +# if 0 /* continue even if device is offline */
6520 + parport_release(pport);
6521 + parport_unregister_device(ppdevice);
6527 + out(LIRC_PORT_DATA,0);
6532 + parport_release(ppdevice);
6534 + if ((plugin.minor = lirc_register_plugin(&plugin)) < 0)
6536 + printk(KERN_NOTICE "%s: register_chrdev() failed\n",LIRC_DRIVER_NAME);
6537 + parport_unregister_device(ppdevice);
6540 + printk(KERN_INFO "%s: installed using port 0x%04x irq %d\n",LIRC_DRIVER_NAME,io,irq);
6544 +static void __exit lirc_parallel_exit(void)
6546 +#ifdef CONFIG_MODULE_UNLOAD
6547 + if(module_refcount(THIS_MODULE)) return;
6549 + parport_unregister_device(ppdevice);
6550 + lirc_unregister_plugin(plugin.minor);
6553 +static struct timer_list poll_timer;
6554 +static void poll_state(unsigned long ignored);
6556 +static void poll_state(unsigned long ignored)
6558 + printk(KERN_NOTICE "%s: time\n",
6559 + LIRC_DRIVER_NAME);
6560 + del_timer(&poll_timer);
6566 + printk(KERN_NOTICE "%s: could not claim port, giving up\n",
6567 + LIRC_DRIVER_NAME);
6568 + init_timer(&poll_timer);
6569 + poll_timer.expires=jiffies+HZ;
6570 + poll_timer.data=(unsigned long) current;
6571 + poll_timer.function=poll_state;
6572 + add_timer(&poll_timer);
6576 +int pf(void *handle)
6578 + pport->ops->disable_irq(pport);
6584 +void kf(void *handle)
6590 + pport->ops->enable_irq(pport);
6591 + /* this is a bit annoying when you actually print...*/
6593 + printk(KERN_INFO "%s: reclaimed port\n",LIRC_DRIVER_NAME);
6597 +MODULE_AUTHOR("Christoph Bartelmus");
6598 +MODULE_DESCRIPTION("Infrared receiver driver for parallel ports.");
6599 +MODULE_LICENSE("GPL");
6601 +MODULE_PARM(io, "i");
6602 +MODULE_PARM_DESC(io, "I/O address base (0x3bc, 0x378 or 0x278)");
6604 +MODULE_PARM(irq, "i");
6605 +MODULE_PARM_DESC(irq, "Interrupt (7 or 5)");
6607 +module_init(lirc_parallel_init);
6608 +module_exit(lirc_parallel_exit);
6610 diff -uprN -X dontdiff linux-2.6.5.orig/drivers/char/lirc/lirc_parallel.h linux-2.6.5/drivers/char/lirc/lirc_parallel.h
6611 --- linux-2.6.5.orig/drivers/char/lirc/lirc_parallel.h 1970-01-01 01:00:00.000000000 +0100
6612 +++ linux-2.6.5/drivers/char/lirc/lirc_parallel.h 2004-04-04 14:05:29.425625896 +0200
6616 +#ifndef _LIRC_PARALLEL_H
6617 +#define _LIRC_PARALLEL_H
6619 +#include <linux/lp.h>
6621 +#define LIRC_PORT_LEN 3
6623 +#define LIRC_LP_BASE 0
6624 +#define LIRC_LP_STATUS 1
6625 +#define LIRC_LP_CONTROL 2
6627 +#define LIRC_PORT_DATA LIRC_LP_BASE /* base */
6628 +#define LIRC_PORT_DATA_BIT 0x01 /* 1st bit */
6629 +#define LIRC_PORT_TIMER LIRC_LP_STATUS /* status port */
6630 +#define LIRC_PORT_TIMER_BIT LP_PBUSY /* busy signal */
6631 +#define LIRC_PORT_SIGNAL LIRC_LP_STATUS /* status port */
6632 +#define LIRC_PORT_SIGNAL_BIT LP_PACK /* ack signal */
6633 +#define LIRC_PORT_IRQ LIRC_LP_CONTROL /* control port */
6635 +#define LIRC_SFH506_DELAY 0 /* delay t_phl in usecs */
6638 diff -uprN -X dontdiff linux-2.6.5.orig/drivers/char/lirc/lirc_serial.c linux-2.6.5/drivers/char/lirc/lirc_serial.c
6639 --- linux-2.6.5.orig/drivers/char/lirc/lirc_serial.c 1970-01-01 01:00:00.000000000 +0100
6640 +++ linux-2.6.5/drivers/char/lirc/lirc_serial.c 2004-04-04 14:05:29.428625440 +0200
6644 +/****************************************************************************
6645 + ** lirc_serial.c ***********************************************************
6646 + ****************************************************************************
6648 + * lirc_serial - Device driver that records pulse- and pause-lengths
6649 + * (space-lengths) between DDCD event on a serial port.
6651 + * Copyright (C) 1996,97 Ralph Metzler <rjkm@thp.uni-koeln.de>
6652 + * Copyright (C) 1998 Trent Piepho <xyzzy@u.washington.edu>
6653 + * Copyright (C) 1998 Ben Pfaff <blp@gnu.org>
6654 + * Copyright (C) 1999 Christoph Bartelmus <lirc@bartelmus.de>
6656 + * This program is free software; you can redistribute it and/or modify
6657 + * it under the terms of the GNU General Public License as published by
6658 + * the Free Software Foundation; either version 2 of the License, or
6659 + * (at your option) any later version.
6661 + * This program is distributed in the hope that it will be useful,
6662 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6663 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6664 + * GNU General Public License for more details.
6666 + * You should have received a copy of the GNU General Public License
6667 + * along with this program; if not, write to the Free Software
6668 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6672 +/* Steve's changes to improve transmission fidelity:
6673 + - for systems with the rdtsc instruction and the clock counter, a
6674 + send_pule that times the pulses directly using the counter.
6675 + This means that the CONFIG_LIRC_SERIAL_TRANSMITTER_LATENCY fudge is
6676 + not needed. Measurement shows very stable waveform, even where
6677 + PCI activity slows the access to the UART, which trips up other
6679 + - For other system, non-integer-microsecond pulse/space lengths,
6680 + done using fixed point binary. So, much more accurate carrier
6682 + - fine tuned transmitter latency, taking advantage of fractional
6683 + microseconds in previous change
6684 + - Fixed bug in the way transmitter latency was accounted for by
6685 + tuning the pulse lengths down - the send_pulse routine ignored
6686 + this overhead as it timed the overall pulse length - so the
6687 + pulse frequency was right but overall pulse length was too
6688 + long. Fixed by accounting for latency on each pulse/space
6691 + Steve Davies <steve@daviesfam.org> July 2001
6693 + Flameeyes Patches Contribution
6694 + - Ronald Wahl <ronald.wahl@informatik.tu-chemnitz.de> sent a patch to
6695 + eliminate a deadlock on SMP systems.
6696 + - Florian Steinel <Florian.Steinel@t-online.de> sent a patch to fix irq
6697 + disabling by kernel.
6698 + - Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz> sent a patch fixing
6699 + one-shot use of lirc_serial.
6702 +#include <linux/config.h>
6703 +#include <linux/module.h>
6704 +#include <linux/errno.h>
6705 +#include <linux/signal.h>
6706 +#include <linux/sched.h>
6707 +#include <linux/fs.h>
6708 +#include <linux/interrupt.h>
6709 +#include <linux/ioport.h>
6710 +#include <linux/kernel.h>
6711 +#include <linux/major.h>
6712 +#include <linux/serial_reg.h>
6713 +#include <linux/time.h>
6714 +#include <linux/string.h>
6715 +#include <linux/types.h>
6716 +#include <linux/wait.h>
6717 +#include <linux/mm.h>
6718 +#include <linux/delay.h>
6719 +#include <linux/poll.h>
6720 +#include <linux/smp_lock.h>
6722 +#include <asm/system.h>
6723 +#include <asm/segment.h>
6724 +#include <asm/io.h>
6725 +#include <asm/irq.h>
6726 +#include <asm/fcntl.h>
6728 +#include <linux/lirc.h>
6729 +#include "lirc_dev.h"
6734 +#warning "Note: using rdtsc instruction"
6741 + int signal_pin_change;
6744 + long (*send_pulse)(unsigned long length);
6745 + void (*send_space)(long length);
6749 +#define LIRC_HOMEBREW 0
6750 +#define LIRC_IRDEO 1
6751 +#define LIRC_IRDEO_REMOTE 2
6752 +#define LIRC_ANIMAX 3
6753 +#define LIRC_IGOR 4
6755 +#ifdef CONFIG_LIRC_SERIAL_IRDEO
6756 +int type=LIRC_IRDEO;
6757 +#elif defined(CONFIG_LIRC_SERIAL_IRDEO_REMOTE)
6758 +int type=LIRC_IRDEO_REMOTE;
6759 +#elif defined(CONFIG_LIRC_SERIAL_ANIMAX)
6760 +int type=LIRC_ANIMAX;
6761 +#elif defined(CONFIG_LIRC_SERIAL_IGOR)
6762 +int type=LIRC_IGOR;
6764 +int type=LIRC_HOMEBREW;
6767 +#ifdef CONFIG_LIRC_SERIAL_SOFTCARRIER
6773 +static int sense = -1; /* -1 = auto, 0 = active high, 1 = active low */
6775 +static int io = CONFIG_LIRC_PORT_SERIAL;
6777 +static int irq = CONFIG_LIRC_IRQ_SERIAL;
6779 +static int debug = 0;
6781 +MODULE_PARM(type, "i");
6782 +MODULE_PARM_DESC(type, "Hardware type (0 = home-brew, 1 = IRdeo,"
6783 + " 2 = IRdeo Remote, 3 = AnimaX");
6785 +MODULE_PARM(io, "i");
6786 +MODULE_PARM_DESC(io, "I/O address base (0x3f8 or 0x2f8)");
6788 +MODULE_PARM(irq, "i");
6789 +MODULE_PARM_DESC(irq, "Interrupt (4 or 3)");
6791 +MODULE_PARM(sense, "i");
6792 +MODULE_PARM_DESC(sense, "Override autodetection of IR receiver circuit"
6793 + " (0 = active high, 1 = active low )");
6795 +MODULE_PARM(softcarrier, "i");
6796 +MODULE_PARM_DESC(softcarrier, "Software carrier (0 = off, 1 = on)");
6798 +MODULE_PARM(debug,"i");
6800 +#define dprintk if (debug) printk
6802 +#define LOGHEAD "lirc_serial: "
6804 +/* forward declarations */
6805 +long send_pulse_irdeo(unsigned long length);
6806 +long send_pulse_homebrew(unsigned long length);
6807 +void send_space_irdeo(long length);
6808 +void send_space_homebrew(long length);
6810 +struct lirc_serial hardware[]=
6812 + /* home-brew receiver/transmitter */
6817 + UART_MCR_RTS|UART_MCR_OUT2|UART_MCR_DTR,
6818 + UART_MCR_RTS|UART_MCR_OUT2,
6819 + send_pulse_homebrew,
6820 + send_space_homebrew,
6822 +#ifdef CONFIG_LIRC_SERIAL_TRANSMITTER
6823 + LIRC_CAN_SET_SEND_DUTY_CYCLE|
6824 + LIRC_CAN_SET_SEND_CARRIER|
6825 + LIRC_CAN_SEND_PULSE|
6827 + LIRC_CAN_REC_MODE2)
6830 + /* IRdeo classic */
6836 + UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2,
6839 + (LIRC_CAN_SET_SEND_DUTY_CYCLE|
6840 + LIRC_CAN_SEND_PULSE|
6841 + LIRC_CAN_REC_MODE2)
6844 + /* IRdeo remote */
6846 + LIRC_IRDEO_REMOTE,
6849 + UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2,
6850 + UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2,
6853 + (LIRC_CAN_SET_SEND_DUTY_CYCLE|
6854 + LIRC_CAN_SEND_PULSE|
6855 + LIRC_CAN_REC_MODE2)
6864 + UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2,
6867 + LIRC_CAN_REC_MODE2
6870 + /* home-brew receiver/transmitter (Igor Cesko's variation) */
6875 + UART_MCR_RTS|UART_MCR_OUT2|UART_MCR_DTR,
6876 + UART_MCR_RTS|UART_MCR_OUT2,
6877 + send_pulse_homebrew,
6878 + send_space_homebrew,
6880 +#ifdef CONFIG_LIRC_SERIAL_TRANSMITTER
6881 + LIRC_CAN_SET_SEND_DUTY_CYCLE|
6882 + LIRC_CAN_SET_SEND_CARRIER|
6883 + LIRC_CAN_SEND_PULSE|
6885 + LIRC_CAN_REC_MODE2)
6890 +#define LIRC_DRIVER_NAME "lirc_serial"
6892 +#define RS_ISR_PASS_LIMIT 256
6894 +/* A long pulse code from a remote might take upto 300 bytes. The
6895 + daemon should read the bytes as soon as they are generated, so take
6896 + the number of keys you think you can push before the daemon runs
6897 + and multiply by 300. The driver will warn you if you overrun this
6898 + buffer. If you have a slow computer or non-busmastering IDE disks,
6899 + maybe you will need to increase this. */
6901 +/* This MUST be a power of two! It has to be larger than 1 as well. */
6903 +#define RBUF_LEN 256
6904 +#define WBUF_LEN 256
6906 +static struct timeval lasttv = {0, 0};
6908 +static spinlock_t lirc_lock = SPIN_LOCK_UNLOCKED;
6910 +static struct lirc_buffer rbuf;
6912 +static lirc_t wbuf[WBUF_LEN];
6914 +unsigned int freq = 38000;
6915 +unsigned int duty_cycle = 50;
6917 +/* Initialized in init_timing_params() */
6918 +unsigned long period = 0;
6919 +unsigned long pulse_width = 0;
6920 +unsigned long space_width = 0;
6922 +#if defined(__i386__)
6925 + Linux I/O port programming mini-HOWTO
6926 + Author: Riku Saikkonen <Riku.Saikkonen@hut.fi>
6927 + v, 28 December 1997
6930 + Actually, a port I/O instruction on most ports in the 0-0x3ff range
6931 + takes almost exactly 1 microsecond, so if you're, for example, using
6932 + the parallel port directly, just do additional inb()s from that port
6936 +/* transmitter latency 1.5625us 0x1.90 - this figure arrived at from
6937 + * comment above plus trimming to match actual measured frequency.
6938 + * This will be sensitive to cpu speed, though hopefully most of the 1.5us
6939 + * is spent in the uart access. Still - for reference test machine was a
6940 + * 1.13GHz Athlon system - Steve
6943 +/* changed from 400 to 450 as this works better on slower machines;
6944 + faster machines will use the rdtsc code anyway */
6946 +#define CONFIG_LIRC_SERIAL_TRANSMITTER_LATENCY 450
6950 +/* does anybody have information on other platforms ? */
6952 +#define CONFIG_LIRC_SERIAL_TRANSMITTER_LATENCY 256
6954 +#endif /* __i386__ */
6956 +static inline unsigned int sinp(int offset)
6958 + return inb(io + offset);
6961 +static inline void soutp(int offset, int value)
6963 + outb(value, io + offset);
6966 +static inline void on(void)
6968 + soutp(UART_MCR,hardware[type].on);
6971 +static inline void off(void)
6973 + soutp(UART_MCR,hardware[type].off);
6976 +#ifndef MAX_UDELAY_MS
6977 +#define MAX_UDELAY_US 5000
6979 +#define MAX_UDELAY_US (MAX_UDELAY_MS*1000)
6982 +static inline void safe_udelay(unsigned long usecs)
6984 + while(usecs>MAX_UDELAY_US)
6986 + udelay(MAX_UDELAY_US);
6987 + usecs-=MAX_UDELAY_US;
6993 +/* This is an overflow/precision juggle, complicated in that we can't
6994 + do long long divide in the kernel */
6996 +/* When we use the rdtsc instruction to measure clocks, we keep the
6997 + * pulse and space widths as clock cycles. As this is CPU speed
6998 + * dependent, the widths must be calculated in init_port and ioctl
7002 +/* So send_pulse can quickly convert microseconds to clocks */
7003 +unsigned long conv_us_to_clocks = 0;
7005 +static inline int init_timing_params(unsigned int new_duty_cycle,
7006 + unsigned int new_freq)
7008 + unsigned long long loops_per_sec,work;
7010 + duty_cycle=new_duty_cycle;
7013 + loops_per_sec=current_cpu_data.loops_per_jiffy;
7014 + loops_per_sec*=HZ;
7016 + /* How many clocks in a microsecond?, avoiding long long divide */
7017 + work=loops_per_sec;
7018 + work*=4295; /* 4295 = 2^32 / 1e6 */
7019 + conv_us_to_clocks=(work>>32);
7021 + /* Carrier period in clocks, approach good up to 32GHz clock,
7022 + gets carrier frequency within 8Hz */
7023 + period=loops_per_sec>>3;
7024 + period/=(freq>>3);
7026 + /* Derive pulse and space from the period */
7028 + pulse_width = period*duty_cycle/100;
7029 + space_width = period - pulse_width;
7031 + ": in init_timing_params, freq=%d, duty_cycle=%d, "
7032 + "clk/jiffy=%ld, pulse=%ld, space=%ld, conv_us_to_clocks=%ld\n",
7033 + freq, duty_cycle, current_cpu_data.loops_per_jiffy,
7034 + pulse_width, space_width, conv_us_to_clocks);
7037 +#else /* ! USE_RDTSC */
7038 +static inline int init_timing_params(unsigned int new_duty_cycle,
7039 + unsigned int new_freq)
7041 +/* period, pulse/space width are kept with 8 binary places -
7042 + * IE multiplied by 256. */
7043 + if(256*1000000L/new_freq*new_duty_cycle/100<=
7044 + CONFIG_LIRC_SERIAL_TRANSMITTER_LATENCY) return(-EINVAL);
7045 + if(256*1000000L/new_freq*(100-new_duty_cycle)/100<=
7046 + CONFIG_LIRC_SERIAL_TRANSMITTER_LATENCY) return(-EINVAL);
7047 + duty_cycle=new_duty_cycle;
7049 + period=256*1000000L/freq;
7050 + pulse_width=period*duty_cycle/100;
7051 + space_width=period-pulse_width;
7053 + ": in init_timing_params, freq=%d pulse=%ld, "
7054 + "space=%ld\n", freq, pulse_width, space_width);
7057 +#endif /* USE_RDTSC */
7060 +/* return value: space length delta */
7062 +long send_pulse_irdeo(unsigned long length)
7066 + unsigned char output;
7067 + unsigned char chunk,shifted;
7069 + /* how many bits have to be sent ? */
7070 + rawbits=length*1152/10000;
7071 + if(duty_cycle>50) chunk=3;
7073 + for(i=0,output=0x7f;rawbits>0;rawbits-=3)
7075 + shifted=chunk<<(i*3);
7077 + output&=(~shifted);
7081 + soutp(UART_TX,output);
7082 + while(!(sinp(UART_LSR) & UART_LSR_THRE));
7089 + soutp(UART_TX,output);
7090 + while(!(sinp(UART_LSR) & UART_LSR_TEMT));
7095 + return((-rawbits)*10000/1152);
7099 + return((3-i)*3*10000/1152+(-rawbits)*10000/1152);
7104 +/* Version that uses Pentium rdtsc instruction to measure clocks */
7106 +/* This version does sub-microsecond timing using rdtsc instruction,
7107 + * and does away with the fudged CONFIG_LIRC_SERIAL_TRANSMITTER_LATENCY
7108 + * Implicitly i586 architecture... - Steve
7111 +static inline long send_pulse_homebrew_softcarrier(unsigned long length)
7114 + unsigned long target, start, now;
7116 + /* Get going quick as we can */
7117 + rdtscl(start);on();
7118 + /* Convert length from microseconds to clocks */
7119 + length*=conv_us_to_clocks;
7120 + /* And loop till time is up - flipping at right intervals */
7122 + target=pulse_width;
7124 + while((now-start)<length)
7126 + /* Delay till flip time */
7131 + while ((now-start)<target);
7135 + rdtscl(now);off();
7136 + target+=space_width;
7141 + target+=pulse_width;
7146 + return(((now-start)-length)/conv_us_to_clocks);
7148 +#else /* ! USE_RDTSC */
7149 +/* Version using udelay() */
7151 +/* here we use fixed point arithmetic, with 8
7152 + fractional bits. that gets us within 0.1% or so of the right average
7153 + frequency, albeit with some jitter in pulse length - Steve */
7155 +/* To match 8 fractional bits used for pulse/space length */
7157 +static inline long send_pulse_homebrew_softcarrier(unsigned long length)
7160 + unsigned long actual, target, d;
7163 + actual=target=0; flag=0;
7164 + while(actual<length)
7169 + target+=space_width;
7174 + target+=pulse_width;
7176 + d=(target-actual-CONFIG_LIRC_SERIAL_TRANSMITTER_LATENCY+128)>>8;
7177 + /* Note - we've checked in ioctl that the pulse/space
7178 + widths are big enough so that d is > 0 */
7180 + actual+=(d<<8)+CONFIG_LIRC_SERIAL_TRANSMITTER_LATENCY;
7183 + return((actual-length)>>8);
7185 +#endif /* USE_RDTSC */
7187 +long send_pulse_homebrew(unsigned long length)
7189 + if(length<=0) return 0;
7192 + return send_pulse_homebrew_softcarrier(length);
7197 + safe_udelay(length);
7202 +void send_space_irdeo(long length)
7204 + if(length<=0) return;
7205 + safe_udelay(length);
7208 +void send_space_homebrew(long length)
7211 + if(length<=0) return;
7212 + safe_udelay(length);
7215 +static void inline rbwrite(lirc_t l)
7217 + if(lirc_buffer_full(&rbuf)) /* no new signals will be accepted */
7219 + dprintk(LOGHEAD ": Buffer overrun\n");
7222 + _lirc_buffer_write_1(&rbuf, (void *)&l);
7225 +static void inline frbwrite(lirc_t l)
7227 + /* simple noise filter */
7228 + static lirc_t pulse=0L,space=0L;
7229 + static unsigned int ptr=0;
7231 + if(ptr>0 && (l&PULSE_BIT))
7233 + pulse+=l&PULSE_MASK;
7237 + rbwrite(pulse|PULSE_BIT);
7243 + if(!(l&PULSE_BIT))
7259 + if(space>PULSE_MASK) space=PULSE_MASK;
7261 + if(space>PULSE_MASK) space=PULSE_MASK;
7266 + rbwrite(pulse|PULSE_BIT);
7274 +irqreturn_t irq_handler(int i, void *blah, struct pt_regs *regs)
7276 + struct timeval tv;
7277 + int status,counter,dcd;
7284 + status=sinp(UART_MSR);
7285 + if(counter>RS_ISR_PASS_LIMIT)
7287 + printk(KERN_WARNING LIRC_DRIVER_NAME ": AIEEEE: "
7288 + "We're caught!\n");
7291 + if((status&hardware[type].signal_pin_change) && sense!=-1)
7293 + /* get current time */
7294 + do_gettimeofday(&tv);
7296 + /* New mode, written by Trent Piepho
7297 + <xyzzy@u.washington.edu>. */
7299 + /* The old format was not very portable.
7300 + We now use the type lirc_t to pass pulses
7301 + and spaces to user space.
7303 + If PULSE_BIT is set a pulse has been
7304 + received, otherwise a space has been
7305 + received. The driver needs to know if your
7306 + receiver is active high or active low, or
7307 + the space/pulse sense could be
7308 + inverted. The bits denoted by PULSE_MASK are
7309 + the length in microseconds. Lengths greater
7310 + than or equal to 16 seconds are clamped to
7311 + PULSE_MASK. All other bits are unused.
7312 + This is a much simpler interface for user
7313 + programs, as well as eliminating "out of
7314 + phase" errors with space/pulse
7317 + /* calculate time since last interrupt in
7319 + dcd=(status & hardware[type].signal_pin) ? 1:0;
7321 + deltv=tv.tv_sec-lasttv.tv_sec;
7325 + ": AIEEEE: %d %d %lx %lx %lx %lx\n",
7327 + tv.tv_sec,lasttv.tv_sec,
7328 + tv.tv_usec,lasttv.tv_usec);
7329 + data=PULSE_MASK; /* really long time */
7330 + if(!(dcd^sense)) /* sanity check */
7332 + /* detecting pulse while this
7333 + MUST be a space! */
7334 + sense=sense ? 0:1;
7339 + data=(lirc_t) (deltv*1000000+
7343 + if(tv.tv_sec<lasttv.tv_sec ||
7344 + (tv.tv_sec==lasttv.tv_sec &&
7345 + tv.tv_usec<lasttv.tv_usec))
7347 + printk(KERN_WARNING LIRC_DRIVER_NAME
7348 + ": AIEEEE: your clock just jumped "
7350 + printk(KERN_WARNING LIRC_DRIVER_NAME
7351 + ": %d %d %lx %lx %lx %lx\n",
7353 + tv.tv_sec,lasttv.tv_sec,
7354 + tv.tv_usec,lasttv.tv_usec);
7357 + frbwrite(dcd^sense ? data : (data|PULSE_BIT));
7359 + wake_up_interruptible(&rbuf.wait_poll);
7361 + } while(!(sinp(UART_IIR) & UART_IIR_NO_INT)); /* still pending ? */
7363 + return IRQ_HANDLED;
7366 +static DECLARE_WAIT_QUEUE_HEAD(power_supply_queue);
7367 +static spinlock_t lirc_lock;
7369 +static int init_port(void)
7371 + unsigned long flags;
7373 + /* Reserve io region. */
7374 + if(!request_region(io, 8, LIRC_DRIVER_NAME))
7376 + printk(KERN_ERR LIRC_DRIVER_NAME
7377 + ": port %04x already in use\n", io);
7378 + printk(KERN_WARNING LIRC_DRIVER_NAME
7379 + ": use 'setserial /dev/ttySX uart none'\n");
7380 + printk(KERN_WARNING LIRC_DRIVER_NAME
7381 + ": or compile the serial port driver as module and\n");
7382 + printk(KERN_WARNING LIRC_DRIVER_NAME
7383 + ": make sure this module is loaded first\n");
7389 + spin_lock_irqsave(&lirc_lock, flags);
7392 + soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
7394 + /* First of all, disable all interrupts */
7395 + soutp(UART_IER, sinp(UART_IER)&
7396 + (~(UART_IER_MSI|UART_IER_RLSI|UART_IER_THRI|UART_IER_RDI)));
7398 + /* Clear registers. */
7404 + /* Set line for power source */
7405 + soutp(UART_MCR, hardware[type].off);
7407 + /* Clear registers again to be sure. */
7413 + switch(hardware[type].type)
7416 + case LIRC_IRDEO_REMOTE:
7417 + /* setup port to 7N1 @ 115200 Baud */
7418 + /* 7N1+start = 9 bits at 115200 ~ 3 bits at 38kHz */
7421 + soutp(UART_LCR, sinp(UART_LCR) | UART_LCR_DLAB);
7422 + /* Set divisor to 1 => 115200 Baud */
7423 + soutp(UART_DLM,0);
7424 + soutp(UART_DLL,1);
7425 + /* Set DLAB 0 + 7N1 */
7426 + soutp(UART_LCR,UART_LCR_WLEN7);
7427 + /* THR interrupt already disabled at this point */
7433 + spin_unlock_irqrestore(&lirc_lock, flags);
7435 + /* Initialize pulse/space widths */
7436 + init_timing_params(duty_cycle, freq);
7438 + /* If pin is high, then this must be an active low receiver. */
7441 + /* wait 1 sec for the power supply */
7443 + sleep_on_timeout(&power_supply_queue,HZ);
7445 + sense=(sinp(UART_MSR) & hardware[type].signal_pin) ? 1:0;
7446 + printk(KERN_INFO LIRC_DRIVER_NAME ": auto-detected active "
7447 + "%s receiver\n",sense ? "low":"high");
7451 + printk(KERN_INFO LIRC_DRIVER_NAME ": Manually using active "
7452 + "%s receiver\n",sense ? "low":"high");
7460 +static int set_use_inc(void* data)
7463 + unsigned long flags;
7465 + spin_lock(&lirc_lock);
7466 +#ifdef CONFIG_MODULE_UNLOAD
7467 + if(module_refcount(THIS_MODULE))
7469 + spin_unlock(&lirc_lock);
7474 + /* initialize timestamp */
7475 + do_gettimeofday(&lasttv);
7477 + result=request_irq(irq,irq_handler,SA_INTERRUPT,LIRC_DRIVER_NAME,NULL);
7481 + printk(KERN_ERR LIRC_DRIVER_NAME ": IRQ %d busy\n", irq);
7482 + spin_unlock(&lirc_lock);
7485 + printk(KERN_ERR LIRC_DRIVER_NAME
7486 + ": Bad irq number or handler\n");
7487 + spin_unlock(&lirc_lock);
7491 + ": Interrupt %d, port %04x obtained\n", irq, io);
7495 + local_irq_save(flags);
7498 + soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
7500 + soutp(UART_IER, sinp(UART_IER)|UART_IER_MSI);
7502 + local_irq_restore(flags);
7504 + try_module_get(THIS_MODULE);
7505 + spin_unlock(&lirc_lock);
7509 +static void set_use_dec(void* data)
7510 +{ unsigned long flags;
7512 + spin_lock_irqsave(&lirc_lock, flags);
7515 + soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
7517 + /* First of all, disable all interrupts */
7518 + soutp(UART_IER, sinp(UART_IER)&
7519 + (~(UART_IER_MSI|UART_IER_RLSI|UART_IER_THRI|UART_IER_RDI)));
7520 + spin_unlock_irqrestore(&lirc_lock, flags);
7522 + free_irq(irq, NULL);
7523 + dprintk(LOGHEAD ": freed IRQ %d\n", irq);
7525 + module_put(THIS_MODULE);
7528 +static ssize_t lirc_write(struct file *file, const char *buf,
7529 + size_t n, loff_t * ppos)
7531 + int retval,i,count;
7532 + unsigned long flags;
7535 + if(!(hardware[type].features&LIRC_CAN_SEND_PULSE))
7540 + if(n%sizeof(lirc_t)) return(-EINVAL);
7541 + retval=verify_area(VERIFY_READ,buf,n);
7542 + if(retval) return(retval);
7543 + count=n/sizeof(lirc_t);
7544 + if(count>WBUF_LEN || count%2==0) return(-EINVAL);
7545 + copy_from_user(wbuf,buf,n);
7546 + spin_lock_irqsave(&lirc_lock, flags);
7547 + if(hardware[type].type==LIRC_IRDEO)
7549 + /* DTR, RTS down */
7552 + for(i=0;i<count;i++)
7554 + if(i%2) hardware[type].send_space(wbuf[i]-delta);
7555 + else delta=hardware[type].send_pulse(wbuf[i]);
7558 + spin_unlock_irqrestore(&lirc_lock, flags);
7562 +static int lirc_ioctl(struct inode *node,struct file *filep,unsigned int cmd,
7563 + unsigned long arg)
7566 + unsigned long value;
7567 + unsigned int ivalue;
7571 + case LIRC_GET_SEND_MODE:
7572 + if(!(hardware[type].features&LIRC_CAN_SEND_MASK))
7574 + return(-ENOIOCTLCMD);
7577 + result=put_user(LIRC_SEND2MODE
7578 + (hardware[type].features&LIRC_CAN_SEND_MASK),
7579 + (unsigned long *) arg);
7580 + if(result) return(result);
7583 + case LIRC_SET_SEND_MODE:
7584 + if(!(hardware[type].features&LIRC_CAN_SEND_MASK))
7586 + return(-ENOIOCTLCMD);
7589 + result=get_user(value,(unsigned long *) arg);
7590 + if(result) return(result);
7591 + /* only LIRC_MODE_PULSE supported */
7592 + if(value!=LIRC_MODE_PULSE) return(-ENOSYS);
7595 + case LIRC_GET_LENGTH:
7599 + case LIRC_SET_SEND_DUTY_CYCLE:
7600 + dprintk(LOGHEAD ": SET_SEND_DUTY_CYCLE\n");
7601 + if(!(hardware[type].features&LIRC_CAN_SET_SEND_DUTY_CYCLE))
7603 + return(-ENOIOCTLCMD);
7606 + result=get_user(ivalue,(unsigned int *) arg);
7607 + if(result) return(result);
7608 + if(ivalue<=0 || ivalue>100) return(-EINVAL);
7609 + return init_timing_params(ivalue, freq);
7612 + case LIRC_SET_SEND_CARRIER:
7613 + dprintk(LOGHEAD ": SET_SEND_CARRIER\n");
7614 + if(!(hardware[type].features&LIRC_CAN_SET_SEND_CARRIER))
7616 + return(-ENOIOCTLCMD);
7619 + result=get_user(ivalue,(unsigned int *) arg);
7620 + if(result) return(result);
7621 + if(ivalue>500000 || ivalue<20000) return(-EINVAL);
7622 + return init_timing_params(duty_cycle, ivalue);
7626 + return(-ENOIOCTLCMD);
7631 +static struct file_operations lirc_fops =
7633 + write: lirc_write,
7636 +static struct lirc_plugin plugin = {
7637 + name: LIRC_DRIVER_NAME,
7645 + set_use_inc: set_use_inc,
7646 + set_use_dec: set_use_dec,
7647 + ioctl: lirc_ioctl,
7651 +MODULE_AUTHOR("Ralph Metzler, Trent Piepho, Ben Pfaff, Christoph Bartelmus");
7652 +MODULE_DESCRIPTION("Infra-red receiver driver for serial ports.");
7653 +MODULE_LICENSE("GPL");
7655 +static int __init lirc_serial_init(void)
7661 + case LIRC_HOMEBREW:
7663 + case LIRC_IRDEO_REMOTE:
7670 + if(!softcarrier && hardware[type].type==LIRC_HOMEBREW)
7672 + hardware[type].features&=~(LIRC_CAN_SET_SEND_DUTY_CYCLE|
7673 + LIRC_CAN_SET_SEND_CARRIER);
7675 + if ((result = init_port()) < 0)
7677 + plugin.features = hardware[type].features;
7678 + lirc_buffer_init(&rbuf, sizeof(lirc_t), RBUF_LEN);
7679 + if ((plugin.minor = lirc_register_plugin(&plugin)) < 0) {
7680 + printk(KERN_ERR LIRC_DRIVER_NAME
7681 + ": register_chrdev failed!\n");
7682 + release_region(io, 8);
7688 +static void __exit lirc_serial_exit(void)
7690 + release_region(io, 8);
7691 + lirc_buffer_free(&rbuf);
7692 + lirc_unregister_plugin(plugin.minor);
7693 + dprintk(LOGHEAD ": cleaned up module\n");
7696 +module_init(lirc_serial_init);
7697 +module_exit(lirc_serial_exit);
7698 diff -uprN -X dontdiff linux-2.6.5.orig/drivers/char/lirc/lirc_sir.c linux-2.6.5/drivers/char/lirc/lirc_sir.c
7699 --- linux-2.6.5.orig/drivers/char/lirc/lirc_sir.c 1970-01-01 01:00:00.000000000 +0100
7700 +++ linux-2.6.5/drivers/char/lirc/lirc_sir.c 2004-04-04 14:05:29.432624832 +0200
7703 + * LIRC SIR driver, (C) 2000 Milan Pikula <www@fornax.sk>
7705 + * lirc_sir - Device driver for use with SIR (serial infra red)
7706 + * mode of IrDA on many notebooks.
7708 + * This program is free software; you can redistribute it and/or modify
7709 + * it under the terms of the GNU General Public License as published by
7710 + * the Free Software Foundation; either version 2 of the License, or
7711 + * (at your option) any later version.
7713 + * This program is distributed in the hope that it will be useful,
7714 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7715 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7716 + * GNU General Public License for more details.
7718 + * You should have received a copy of the GNU General Public License
7719 + * along with this program; if not, write to the Free Software
7720 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
7723 + * 2000/09/16 Frank Przybylski <mail@frankprzybylski.de> :
7724 + * added timeout and relaxed pulse detection, removed gap bug
7726 + * 2000/12/15 Christoph Bartelmus <lirc@bartelmus.de> :
7727 + * added support for Tekram Irmate 210 (sending does not work yet,
7728 + * kind of disappointing that nobody was able to implement that
7732 + * 2001/02/27 Christoph Bartelmus <lirc@bartelmus.de> :
7733 + * added support for StrongARM SA1100 embedded microprocessor
7734 + * parts cut'n'pasted from sa1100_ir.c (C) 2000 Russell King
7738 +#include <linux/version.h>
7739 +#include <linux/module.h>
7740 +#include <linux/config.h>
7742 +#if !defined(CONFIG_LIRC_ON_SA1100) && !defined(CONFIG_SERIAL_MODULE)
7743 +#warning "******************************************"
7744 +#warning " Your serial port driver is compiled into "
7745 +#warning " the kernel. You will have to release the "
7746 +#warning " port you want to use for LIRC with: "
7747 +#warning " setserial /dev/ttySx uart none "
7748 +#warning "******************************************"
7751 +#include <linux/sched.h>
7752 +#include <linux/errno.h>
7753 +#include <linux/signal.h>
7754 +#include <linux/fs.h>
7755 +#include <linux/interrupt.h>
7756 +#include <linux/ioport.h>
7757 +#include <linux/kernel.h>
7758 +#include <linux/major.h>
7759 +#include <linux/serial_reg.h>
7760 +#include <linux/time.h>
7761 +#include <linux/string.h>
7762 +#include <linux/types.h>
7763 +#include <linux/wait.h>
7764 +#include <linux/mm.h>
7765 +#include <linux/delay.h>
7766 +#include <linux/poll.h>
7767 +#include <asm/system.h>
7768 +#include <asm/segment.h>
7769 +#include <asm/io.h>
7770 +#include <asm/irq.h>
7771 +#include <asm/fcntl.h>
7772 +#ifdef CONFIG_LIRC_ON_SA1100
7773 +#include <asm/hardware.h>
7774 +#ifdef CONFIG_SA1100_COLLIE
7775 +#include <asm/arch/tc35143.h>
7776 +#include <asm/ucb1200.h>
7780 +#include <linux/timer.h>
7782 +#include <linux/lirc.h>
7783 +#include "lirc_dev.h"
7785 +/* SECTION: Definitions */
7787 +/**************************** Tekram dongle ***************************/
7788 +#ifdef CONFIG_LIRC_SIR_TEKRAM
7789 +/* stolen from kernel source */
7790 +/* definitions for Tekram dongle */
7791 +#define TEKRAM_115200 0x00
7792 +#define TEKRAM_57600 0x01
7793 +#define TEKRAM_38400 0x02
7794 +#define TEKRAM_19200 0x03
7795 +#define TEKRAM_9600 0x04
7796 +#define TEKRAM_2400 0x08
7798 +#define TEKRAM_PW 0x10 /* Pulse select bit */
7800 +/* 10bit * 1s/115200bit in milli seconds = 87ms*/
7801 +#define TIME_CONST (10000000ul/115200ul)
7805 +#ifdef CONFIG_LIRC_SIR_ACTISYS_ACT200L
7806 +static void init_act200(void);
7809 +/******************************* SA1100 ********************************/
7810 +#ifdef CONFIG_LIRC_ON_SA1100
7811 +struct sa1100_ser2_registers
7813 + /* HSSP control register */
7814 + unsigned char hscr0;
7815 + /* UART registers */
7816 + unsigned char utcr0;
7817 + unsigned char utcr1;
7818 + unsigned char utcr2;
7819 + unsigned char utcr3;
7820 + unsigned char utcr4;
7821 + unsigned char utdr;
7822 + unsigned char utsr0;
7823 + unsigned char utsr1;
7826 +static int irq=IRQ_Ser2ICP;
7828 +#define LIRC_ON_SA1100_TRANSMITTER_LATENCY 0
7830 +/* pulse/space ratio of 50/50 */
7831 +unsigned long pulse_width = (13-LIRC_ON_SA1100_TRANSMITTER_LATENCY);
7832 +/* 1000000/freq-pulse_width */
7833 +unsigned long space_width = (13-LIRC_ON_SA1100_TRANSMITTER_LATENCY);
7834 +unsigned int freq = 38000; /* modulation frequency */
7835 +unsigned int duty_cycle = 50; /* duty cycle of 50% */
7839 +#define RBUF_LEN 1024
7840 +#define WBUF_LEN 1024
7842 +#define LIRC_DRIVER_NAME "lirc_sir"
7844 +#ifndef CONFIG_LIRC_SIR_TEKRAM
7847 +/* 9bit * 1s/115200bit in milli seconds = 78.125ms*/
7848 +#define TIME_CONST (9000000ul/115200ul)
7852 +/* timeout for sequences in jiffies (=5/100s) */
7853 +/* must be longer than TIME_CONST */
7854 +#define SIR_TIMEOUT (HZ*5/100)
7856 +#ifndef CONFIG_LIRC_ON_SA1100
7857 +static int io = CONFIG_LIRC_PORT_SIR;
7858 +static int irq = CONFIG_LIRC_IRQ_SIR;
7859 +static int threshold = 3;
7862 +static spinlock_t timer_lock = SPIN_LOCK_UNLOCKED;
7863 +static struct timer_list timerlist;
7864 +/* time of last signal change detected */
7865 +static struct timeval last_tv = {0, 0};
7866 +/* time of last UART data ready interrupt */
7867 +static struct timeval last_intr_tv = {0, 0};
7868 +static int last_value = 0;
7869 +static spinlock_t lirc_lock;
7871 +static DECLARE_WAIT_QUEUE_HEAD(lirc_read_queue);
7873 +static spinlock_t hardware_lock = SPIN_LOCK_UNLOCKED;
7874 +static spinlock_t dev_lock = SPIN_LOCK_UNLOCKED;
7876 +static lirc_t rx_buf[RBUF_LEN]; unsigned int rx_tail = 0, rx_head = 0;
7877 +#ifndef CONFIG_LIRC_SIR_TEKRAM
7878 +static lirc_t tx_buf[WBUF_LEN];
7881 +/* SECTION: Prototypes */
7883 +/* Communication with user-space */
7884 +static int lirc_open(struct inode * inode, struct file * file);
7885 +static int lirc_close(struct inode * inode, struct file *file);
7886 +static unsigned int lirc_poll(struct file * file, poll_table * wait);
7887 +static ssize_t lirc_read(struct file * file, char * buf, size_t count,
7889 +static ssize_t lirc_write(struct file * file, const char * buf, size_t n, loff_t * pos);
7890 +static int lirc_ioctl(struct inode *node,struct file *filep,unsigned int cmd,
7891 + unsigned long arg);
7892 +static void add_read_queue(int flag, unsigned long val);
7894 +static int init_chrdev(void);
7895 +static void drop_chrdev(void);
7898 +static irqreturn_t sir_interrupt(int irq, void * dev_id, struct pt_regs * regs);
7899 +#ifndef CONFIG_LIRC_SIR_TEKRAM
7900 +static void send_space(unsigned long len);
7901 +static void send_pulse(unsigned long len);
7903 +static int init_hardware(void);
7904 +static void drop_hardware(void);
7905 + /* Initialisation */
7906 +static int init_port(void);
7907 +static void drop_port(void);
7908 +int init_module(void);
7909 +void cleanup_module(void);
7911 +#ifdef CONFIG_LIRC_ON_SA1100
7912 +void inline on(void)
7917 +void inline off(void)
7922 +static inline unsigned int sinp(int offset)
7924 + return inb(io + offset);
7927 +static inline void soutp(int offset, int value)
7929 + outb(value, io + offset);
7933 +#ifndef MAX_UDELAY_MS
7934 +#define MAX_UDELAY_US 5000
7936 +#define MAX_UDELAY_US (MAX_UDELAY_MS*1000)
7939 +static inline void safe_udelay(unsigned long usecs)
7941 + while(usecs>MAX_UDELAY_US)
7943 + udelay(MAX_UDELAY_US);
7944 + usecs-=MAX_UDELAY_US;
7949 +/* SECTION: Communication with user-space */
7951 +static int lirc_open(struct inode * inode, struct file * file)
7953 + spin_lock(&dev_lock);
7954 +#ifdef CONFIG_MODULE_UNLOAD
7955 + if (module_refcount(THIS_MODULE))
7957 + spin_unlock(&dev_lock);
7961 + if (!try_module_get(THIS_MODULE))
7963 + spin_unlock(&dev_lock);
7966 + spin_unlock(&dev_lock);
7970 +static int lirc_close(struct inode * inode, struct file *file)
7972 + module_put(THIS_MODULE);
7976 +static unsigned int lirc_poll(struct file * file, poll_table * wait)
7978 + poll_wait(file, &lirc_read_queue, wait);
7979 + if (rx_head != rx_tail)
7980 + return POLLIN | POLLRDNORM;
7984 +static ssize_t lirc_read(struct file * file, char * buf, size_t count,
7989 + DECLARE_WAITQUEUE(wait,current);
7991 + if(n%sizeof(lirc_t)) return(-EINVAL);
7993 + add_wait_queue(&lirc_read_queue,&wait);
7994 + current->state=TASK_INTERRUPTIBLE;
7997 + if(rx_head!=rx_tail)
7999 + retval=verify_area(VERIFY_WRITE,
8000 + (void *) buf+n,sizeof(lirc_t));
8005 + copy_to_user((void *) buf+n,(void *) (rx_buf+rx_head),
8007 + rx_head=(rx_head+1)&(RBUF_LEN-1);
8008 + n+=sizeof(lirc_t);
8012 + if(file->f_flags & O_NONBLOCK)
8017 + if(signal_pending(current))
8019 + retval=-ERESTARTSYS;
8023 + current->state=TASK_INTERRUPTIBLE;
8026 + remove_wait_queue(&lirc_read_queue,&wait);
8027 + current->state=TASK_RUNNING;
8028 + return (n ? n : retval);
8030 +static ssize_t lirc_write(struct file * file, const char * buf, size_t n, loff_t * pos)
8032 + unsigned long flags;
8033 +#ifdef CONFIG_LIRC_SIR_TEKRAM
8039 + if(n%sizeof(lirc_t) || (n/sizeof(lirc_t)) > WBUF_LEN)
8041 + retval = verify_area(VERIFY_READ, buf, n);
8044 + copy_from_user(tx_buf, buf, n);
8046 + n/=sizeof(lirc_t);
8047 +#ifdef CONFIG_LIRC_ON_SA1100
8048 + /* disable receiver */
8051 + spin_lock_irqsave(&lirc_lock, flags);
8056 + send_pulse(tx_buf[i]);
8061 + send_space(tx_buf[i]);
8064 + spin_unlock_irqrestore(&lirc_lock, flags);
8065 +#ifdef CONFIG_LIRC_ON_SA1100
8067 + udelay(1000); /* wait 1ms for IR diode to recover */
8069 + /* clear status register to prevent unwanted interrupts */
8070 + Ser2UTSR0 &= (UTSR0_RID | UTSR0_RBB | UTSR0_REB);
8071 + /* enable receiver */
8072 + Ser2UTCR3=UTCR3_RXE|UTCR3_RIE;
8078 +static int lirc_ioctl(struct inode *node,struct file *filep,unsigned int cmd,
8079 + unsigned long arg)
8082 + unsigned long value = 0;
8083 +#ifdef CONFIG_LIRC_ON_SA1100
8084 + unsigned int ivalue;
8087 +#ifdef CONFIG_LIRC_SIR_TEKRAM
8088 + if (cmd == LIRC_GET_FEATURES)
8089 + value = LIRC_CAN_REC_MODE2;
8090 + else if (cmd == LIRC_GET_SEND_MODE)
8092 + else if (cmd == LIRC_GET_REC_MODE)
8093 + value = LIRC_MODE_MODE2;
8094 +#elif defined(CONFIG_LIRC_ON_SA1100)
8095 + if (cmd == LIRC_GET_FEATURES)
8096 + value = LIRC_CAN_SEND_PULSE |
8097 + LIRC_CAN_SET_SEND_DUTY_CYCLE |
8098 + LIRC_CAN_SET_SEND_CARRIER |
8099 + LIRC_CAN_REC_MODE2;
8100 + else if (cmd == LIRC_GET_SEND_MODE)
8101 + value = LIRC_MODE_PULSE;
8102 + else if (cmd == LIRC_GET_REC_MODE)
8103 + value = LIRC_MODE_MODE2;
8105 + if (cmd == LIRC_GET_FEATURES)
8106 + value = LIRC_CAN_SEND_PULSE | LIRC_CAN_REC_MODE2;
8107 + else if (cmd == LIRC_GET_SEND_MODE)
8108 + value = LIRC_MODE_PULSE;
8109 + else if (cmd == LIRC_GET_REC_MODE)
8110 + value = LIRC_MODE_MODE2;
8114 + case LIRC_GET_FEATURES:
8115 + case LIRC_GET_SEND_MODE:
8116 + case LIRC_GET_REC_MODE:
8117 + retval = put_user(value, (unsigned long *) arg);
8120 + case LIRC_SET_SEND_MODE:
8121 + case LIRC_SET_REC_MODE:
8122 + retval = get_user(value, (unsigned long *) arg);
8124 +#ifdef CONFIG_LIRC_ON_SA1100
8125 + case LIRC_SET_SEND_DUTY_CYCLE:
8126 + retval=get_user(ivalue,(unsigned int *) arg);
8127 + if(retval) return(retval);
8128 + if(ivalue<=0 || ivalue>100) return(-EINVAL);
8129 + /* (ivalue/100)*(1000000/freq) */
8130 + duty_cycle=ivalue;
8131 + pulse_width=(unsigned long) duty_cycle*10000/freq;
8132 + space_width=(unsigned long) 1000000L/freq-pulse_width;
8133 + if(pulse_width>=LIRC_ON_SA1100_TRANSMITTER_LATENCY)
8134 + pulse_width-=LIRC_ON_SA1100_TRANSMITTER_LATENCY;
8135 + if(space_width>=LIRC_ON_SA1100_TRANSMITTER_LATENCY)
8136 + space_width-=LIRC_ON_SA1100_TRANSMITTER_LATENCY;
8138 + case LIRC_SET_SEND_CARRIER:
8139 + retval=get_user(ivalue,(unsigned int *) arg);
8140 + if(retval) return(retval);
8141 + if(ivalue>500000 || ivalue<20000) return(-EINVAL);
8143 + pulse_width=(unsigned long) duty_cycle*10000/freq;
8144 + space_width=(unsigned long) 1000000L/freq-pulse_width;
8145 + if(pulse_width>=LIRC_ON_SA1100_TRANSMITTER_LATENCY)
8146 + pulse_width-=LIRC_ON_SA1100_TRANSMITTER_LATENCY;
8147 + if(space_width>=LIRC_ON_SA1100_TRANSMITTER_LATENCY)
8148 + space_width-=LIRC_ON_SA1100_TRANSMITTER_LATENCY;
8152 + retval = -ENOIOCTLCMD;
8159 +#ifdef CONFIG_LIRC_SIR_TEKRAM
8160 + if (cmd == LIRC_SET_REC_MODE) {
8161 + if (value != LIRC_MODE_MODE2)
8163 + } else if (cmd == LIRC_SET_SEND_MODE) {
8167 + if (cmd == LIRC_SET_REC_MODE) {
8168 + if (value != LIRC_MODE_MODE2)
8170 + } else if (cmd == LIRC_SET_SEND_MODE) {
8171 + if (value != LIRC_MODE_PULSE)
8178 +static void add_read_queue(int flag, unsigned long val)
8180 + unsigned int new_rx_tail;
8183 +#ifdef DEBUG_SIGNAL
8184 + printk(KERN_DEBUG LIRC_DRIVER_NAME
8185 + ": add flag %d with val %lu\n",
8189 + newval = val & PULSE_MASK;
8191 + /* statistically pulses are ~TIME_CONST/2 too long: we could
8192 + maybe make this more exactly but this is good enough */
8193 + if(flag) /* pulse */
8195 + if(newval>TIME_CONST/2)
8197 + newval-=TIME_CONST/2;
8199 + else /* should not ever happen */
8203 + newval|=PULSE_BIT;
8207 + newval+=TIME_CONST/2;
8209 + new_rx_tail = (rx_tail + 1) & (RBUF_LEN - 1);
8210 + if (new_rx_tail == rx_head) {
8212 + printk(KERN_WARNING LIRC_DRIVER_NAME ": Buffer overrun.\n");
8216 + rx_buf[rx_tail] = newval;
8217 + rx_tail = new_rx_tail;
8218 + wake_up_interruptible(&lirc_read_queue);
8221 +static struct file_operations lirc_fops =
8223 + .read = lirc_read,
8224 + .write = lirc_write,
8225 + .poll = lirc_poll,
8226 + .ioctl = lirc_ioctl,
8227 + .open = lirc_open,
8228 + .release = lirc_close,
8231 +static int set_use_inc(void* data)
8233 +#if WE_DONT_USE_LOCAL_OPEN_CLOSE
8234 + if (!try_module_get(THIS_MODULE)) {
8241 +static void set_use_dec(void* data)
8243 +#if WE_DONT_USE_LOCAL_OPEN_CLOSE
8244 + module_put(THIS_MODULE);
8247 +static struct lirc_plugin plugin = {
8248 + .name = LIRC_DRIVER_NAME,
8253 + .add_to_buf = NULL,
8254 + .get_queue = NULL,
8255 + .set_use_inc = set_use_inc,
8256 + .set_use_dec = set_use_dec,
8257 + .fops = &lirc_fops,
8260 +int init_chrdev(void)
8262 + plugin.minor = lirc_register_plugin(&plugin);
8263 + if (plugin.minor < 0) {
8264 + printk(KERN_ERR LIRC_DRIVER_NAME ": init_chrdev() failed.\n");
8270 +static void drop_chrdev(void)
8272 + lirc_unregister_plugin(plugin.minor);
8275 +/* SECTION: Hardware */
8276 +static long delta(struct timeval * tv1, struct timeval * tv2)
8278 + unsigned long deltv;
8280 + deltv = tv2->tv_sec - tv1->tv_sec;
8284 + deltv = deltv*1000000 +
8290 +static void sir_timeout(unsigned long data)
8292 + /* if last received signal was a pulse, but receiving stopped
8293 + within the 9 bit frame, we need to finish this pulse and
8294 + simulate a signal change to from pulse to space. Otherwise
8295 + upper layers will receive two sequences next time. */
8297 + unsigned long flags;
8298 + unsigned long pulse_end;
8300 + /* avoid interference with interrupt */
8301 + spin_lock_irqsave(&timer_lock, flags);
8304 +#ifndef CONFIG_LIRC_ON_SA1100
8305 + /* clear unread bits in UART and restart */
8306 + outb(UART_FCR_CLEAR_RCVR, io + UART_FCR);
8308 + /* determine 'virtual' pulse end: */
8309 + pulse_end = delta(&last_tv, &last_intr_tv);
8310 +#ifdef DEBUG_SIGNAL
8311 + printk(KERN_DEBUG LIRC_DRIVER_NAME
8312 + ": timeout add %d for %lu usec\n",last_value,pulse_end);
8314 + add_read_queue(last_value,pulse_end);
8316 + last_tv=last_intr_tv;
8318 + spin_unlock_irqrestore(&timer_lock, flags);
8321 +static irqreturn_t sir_interrupt(int irq, void *dev_id, struct pt_regs *regs)
8323 + unsigned char data;
8324 + struct timeval curr_tv;
8325 + static unsigned long deltv;
8326 +#ifdef CONFIG_LIRC_ON_SA1100
8330 + //printk("interrupt\n");
8331 + status = Ser2UTSR0;
8333 + * Deal with any receive errors first. The bytes in error may be
8334 + * the only bytes in the receive FIFO, so we do this first.
8336 + while (status & UTSR0_EIF)
8342 + bstat = Ser2UTSR1;
8344 + if (bstat & UTSR1_FRE)
8345 + printk("frame error\n");
8346 + if (bstat & UTSR1_ROR)
8347 + printk("receive fifo overrun\n");
8348 + if(bstat&UTSR1_PRE)
8349 + printk("parity error\n");
8354 + status = Ser2UTSR0;
8357 + if (status & (UTSR0_RFS | UTSR0_RID))
8359 + do_gettimeofday(&curr_tv);
8360 + deltv = delta(&last_tv, &curr_tv);
8363 +#ifdef DEBUG_SIGNAL
8364 + printk(KERN_DEBUG LIRC_DRIVER_NAME": t %lu , d %d\n",
8365 + deltintrtv,(int)data);
8368 + //printk("data: %d\n",data);
8371 + while(status&UTSR0_RID && /* do not empty fifo in
8372 + order to get UTSR0_RID in
8374 + Ser2UTSR1 & UTSR1_RNE); /* data ready */
8376 + if(status&UTSR0_RID)
8378 + //printk("add\n");
8379 + add_read_queue(0,deltv-n*TIME_CONST); /*space*/
8380 + add_read_queue(1,n*TIME_CONST); /*pulse*/
8386 + if (status & UTSR0_TFS) {
8388 + printk("transmit fifo not full, shouldn't ever happen\n");
8392 + * We must clear certain bits.
8394 + status &= (UTSR0_RID | UTSR0_RBB | UTSR0_REB);
8396 + Ser2UTSR0 = status;
8398 + unsigned long deltintrtv;
8399 + unsigned long flags;
8402 + while ((iir = inb(io + UART_IIR) & UART_IIR_ID)) {
8403 + switch (iir&UART_IIR_ID) { /* FIXME toto treba preriedit */
8404 + case UART_IIR_MSI:
8405 + (void) inb(io + UART_MSR);
8407 + case UART_IIR_RLSI:
8408 + (void) inb(io + UART_LSR);
8410 + case UART_IIR_THRI:
8412 + if (lsr & UART_LSR_THRE) /* FIFO is empty */
8413 + outb(data, io + UART_TX)
8416 + case UART_IIR_RDI:
8417 + /* avoid interference with timer */
8418 + spin_lock_irqsave(&timer_lock, flags);
8421 + del_timer(&timerlist);
8422 + data = inb(io + UART_RX);
8423 + do_gettimeofday(&curr_tv);
8424 + deltv = delta(&last_tv, &curr_tv);
8425 + deltintrtv = delta(&last_intr_tv, &curr_tv);
8426 +#ifdef DEBUG_SIGNAL
8427 + printk(KERN_DEBUG LIRC_DRIVER_NAME": t %lu , d %d\n",deltintrtv,(int)data);
8429 + /* if nothing came in last X cycles,
8431 + if (deltintrtv > TIME_CONST * threshold) {
8433 +#ifdef DEBUG_SIGNAL
8434 + printk(KERN_DEBUG LIRC_DRIVER_NAME ": GAP\n");
8436 + /* simulate signal change */
8437 + add_read_queue(last_value,
8441 + last_tv.tv_sec = last_intr_tv.tv_sec;
8442 + last_tv.tv_usec = last_intr_tv.tv_usec;
8443 + deltv = deltintrtv;
8447 + if (data ^ last_value) {
8448 + /* deltintrtv > 2*TIME_CONST,
8450 + /* the other case is timeout */
8451 + add_read_queue(last_value,
8452 + deltv-TIME_CONST);
8453 + last_value = data;
8454 + last_tv = curr_tv;
8455 + if(last_tv.tv_usec>=TIME_CONST)
8457 + last_tv.tv_usec-=TIME_CONST;
8462 + last_tv.tv_usec+=1000000-
8466 + last_intr_tv = curr_tv;
8469 + /* start timer for end of sequence detection */
8470 + timerlist.expires = jiffies + SIR_TIMEOUT;
8471 + add_timer(&timerlist);
8474 + while ((lsr = inb(io + UART_LSR))
8475 + & UART_LSR_DR); /* data ready */
8476 + spin_unlock_irqrestore(&timer_lock, flags);
8483 + return IRQ_HANDLED;
8486 +#ifdef CONFIG_LIRC_ON_SA1100
8487 +void send_pulse(unsigned long length)
8489 + unsigned long k,delay;
8492 + if(length==0) return;
8493 + /* this won't give us the carrier frequency we really want
8494 + due to integer arithmetic, but we can accept this inaccuracy */
8496 + for(k=flag=0;k<length;k+=delay,flag=!flag)
8501 + delay=space_width;
8506 + delay=pulse_width;
8508 + safe_udelay(delay);
8513 +void send_space(unsigned long length)
8515 + if(length==0) return;
8517 + safe_udelay(length);
8519 +#elif defined(CONFIG_LIRC_SIR_TEKRAM)
8521 +static void send_space(unsigned long len)
8526 +static void send_pulse(unsigned long len)
8528 + long bytes_out = len / TIME_CONST;
8533 + time_left = (long)len - (long)bytes_out * (long)TIME_CONST;
8534 + while (--bytes_out) {
8535 + outb(PULSE, io + UART_TX);
8536 + /* FIXME treba seriozne cakanie z drivers/char/serial.c */
8537 + while (!(inb(io + UART_LSR) & UART_LSR_THRE));
8540 + if (time_left > 0)
8541 + safe_udelay(time_left);
8546 +#ifdef CONFIG_SA1100_COLLIE
8547 +static inline int sa1100_irda_set_power_collie(int state)
8552 + * 1 - short range, lowest power
8553 + * 2 - medium range, medium power
8554 + * 3 - maximum range, high power
8556 + ucb1200_set_io_direction(TC35143_GPIO_IR_ON,
8557 + TC35143_IODIR_OUTPUT);
8558 + ucb1200_set_io(TC35143_GPIO_IR_ON, TC35143_IODAT_LOW);
8563 + ucb1200_set_io_direction(TC35143_GPIO_IR_ON,
8564 + TC35143_IODIR_OUTPUT);
8565 + ucb1200_set_io(TC35143_GPIO_IR_ON, TC35143_IODAT_HIGH);
8571 +static int init_hardware(void)
8575 + spin_lock_irqsave(&hardware_lock, flags);
8577 +#ifdef CONFIG_LIRC_ON_SA1100
8578 +#ifdef CONFIG_SA1100_BITSY
8579 + if (machine_is_bitsy()) {
8580 + printk("Power on IR module\n");
8581 + set_bitsy_egpio(EGPIO_BITSY_IR_ON);
8584 +#ifdef CONFIG_SA1100_COLLIE
8585 + sa1100_irda_set_power_collie(3); /* power on */
8587 + sr.hscr0=Ser2HSCR0;
8589 + sr.utcr0=Ser2UTCR0;
8590 + sr.utcr1=Ser2UTCR1;
8591 + sr.utcr2=Ser2UTCR2;
8592 + sr.utcr3=Ser2UTCR3;
8593 + sr.utcr4=Ser2UTCR4;
8596 + sr.utsr0=Ser2UTSR0;
8597 + sr.utsr1=Ser2UTSR1;
8599 + /* configure GPIO */
8603 + /* set output to 0 */
8607 + * Enable HP-SIR modulation, and ensure that the port is disabled.
8610 + Ser2HSCR0=sr.hscr0 & (~HSCR0_HSSP);
8612 + /* clear status register to prevent unwanted interrupts */
8613 + Ser2UTSR0 &= (UTSR0_RID | UTSR0_RBB | UTSR0_REB);
8616 + Ser2UTCR0=UTCR0_1StpBit|UTCR0_7BitData;
8620 + /* use HPSIR, 1.6 usec pulses */
8621 + Ser2UTCR4=UTCR4_HPSIR|UTCR4_Z1_6us;
8623 + /* enable receiver, receive fifo interrupt */
8624 + Ser2UTCR3=UTCR3_RXE|UTCR3_RIE;
8626 + /* clear status register to prevent unwanted interrupts */
8627 + Ser2UTSR0 &= (UTSR0_RID | UTSR0_RBB | UTSR0_REB);
8629 +#elif defined(CONFIG_LIRC_SIR_TEKRAM)
8630 + /* disable FIFO */
8632 + UART_FCR_CLEAR_RCVR|
8633 + UART_FCR_CLEAR_XMIT|
8634 + UART_FCR_TRIGGER_1);
8637 + soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
8639 + /* First of all, disable all interrupts */
8640 + soutp(UART_IER, sinp(UART_IER)&
8641 + (~(UART_IER_MSI|UART_IER_RLSI|UART_IER_THRI|UART_IER_RDI)));
8644 + soutp(UART_LCR, sinp(UART_LCR) | UART_LCR_DLAB);
8646 + /* Set divisor to 12 => 9600 Baud */
8647 + soutp(UART_DLM,0);
8648 + soutp(UART_DLL,12);
8651 + soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
8653 + /* power supply */
8654 + soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2);
8655 + safe_udelay(50*1000);
8657 + /* -DTR low -> reset PIC */
8658 + soutp(UART_MCR, UART_MCR_RTS|UART_MCR_OUT2);
8661 + soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2);
8665 + /* -RTS low -> send control byte */
8666 + soutp(UART_MCR, UART_MCR_DTR|UART_MCR_OUT2);
8668 + soutp(UART_TX, TEKRAM_115200|TEKRAM_PW);
8670 + /* one byte takes ~1042 usec to transmit at 9600,8N1 */
8673 + /* back to normal operation */
8674 + soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2);
8679 + /* read previous control byte */
8680 + printk(KERN_INFO LIRC_DRIVER_NAME
8681 + ": 0x%02x\n",sinp(UART_RX));
8684 + soutp(UART_LCR, sinp(UART_LCR) | UART_LCR_DLAB);
8686 + /* Set divisor to 1 => 115200 Baud */
8687 + soutp(UART_DLM,0);
8688 + soutp(UART_DLL,1);
8690 + /* Set DLAB 0, 8 Bit */
8691 + soutp(UART_LCR, UART_LCR_WLEN8);
8692 + /* enable interrupts */
8693 + soutp(UART_IER, sinp(UART_IER)|UART_IER_RDI);
8695 + outb(0, io + UART_MCR);
8696 + outb(0, io + UART_IER);
8698 + /* set DLAB, speed = 115200 */
8699 + outb(UART_LCR_DLAB | UART_LCR_WLEN7, io + UART_LCR);
8700 + outb(1, io + UART_DLL); outb(0, io + UART_DLM);
8701 + /* 7N1+start = 9 bits at 115200 ~ 3 bits at 44000 */
8702 + outb(UART_LCR_WLEN7, io + UART_LCR);
8703 + /* FIFO operation */
8704 + outb(UART_FCR_ENABLE_FIFO, io + UART_FCR);
8706 + // outb(UART_IER_RLSI|UART_IER_RDI|UART_IER_THRI, io + UART_IER);
8707 + outb(UART_IER_RDI, io + UART_IER);
8708 + /* turn on UART */
8709 + outb(UART_MCR_DTR|UART_MCR_RTS|UART_MCR_OUT2, io + UART_MCR);
8710 +#ifdef CONFIG_LIRC_SIR_ACTISYS_ACT200L
8714 + spin_unlock_irqrestore(&hardware_lock, flags);
8718 +static void drop_hardware(void)
8722 + spin_lock_irqsave(&hardware_lock, flags);
8724 +#ifdef CONFIG_LIRC_ON_SA1100
8727 + Ser2UTCR0=sr.utcr0;
8728 + Ser2UTCR1=sr.utcr1;
8729 + Ser2UTCR2=sr.utcr2;
8730 + Ser2UTCR4=sr.utcr4;
8731 + Ser2UTCR3=sr.utcr3;
8733 + Ser2HSCR0=sr.hscr0;
8734 +#ifdef CONFIG_SA1100_BITSY
8735 + if (machine_is_bitsy()) {
8736 + clr_bitsy_egpio(EGPIO_BITSY_IR_ON);
8739 +#ifdef CONFIG_SA1100_COLLIE
8740 + sa1100_irda_set_power_collie(0); /* power off */
8743 + /* turn off interrupts */
8744 + outb(0, io + UART_IER);
8746 + spin_unlock_irqrestore(&hardware_lock, flags);
8749 +/* SECTION: Initialisation */
8751 +static int init_port(void)
8755 +#ifndef CONFIG_LIRC_ON_SA1100
8756 + /* get I/O port access and IRQ line */
8757 + retval = request_region(io, 8, LIRC_DRIVER_NAME);
8759 + printk(KERN_ERR LIRC_DRIVER_NAME
8760 + ": i/o port 0x%.4x already in use.\n",
8764 + printk(KERN_INFO LIRC_DRIVER_NAME
8765 + ": I/O port 0x%.4x, IRQ %d.\n",
8768 + retval = request_irq(irq, sir_interrupt, SA_INTERRUPT,
8769 + LIRC_DRIVER_NAME, NULL);
8771 + printk(KERN_ERR LIRC_DRIVER_NAME
8772 + ": IRQ %d already in use.\n",
8777 + init_timer(&timerlist);
8778 + timerlist.function = sir_timeout;
8779 + timerlist.data = 0xabadcafe;
8784 +static void drop_port(void)
8787 + free_irq(irq, NULL);
8788 + del_timer_sync(&timerlist);
8789 +#ifndef CONFIG_LIRC_ON_SA1100
8790 + release_region(io, 8);
8794 +#ifdef CONFIG_LIRC_SIR_ACTISYS_ACT200L
8795 +/******************************************************/
8796 +/* Crystal/Cirrus CS8130 IR transceiver, used in Actisys Act200L dongle */
8797 +/* some code borrowed from Linux IRDA driver */
8799 +/* Regsiter 0: Control register #1 */
8800 +#define ACT200L_REG0 0x00
8801 +#define ACT200L_TXEN 0x01 /* Enable transmitter */
8802 +#define ACT200L_RXEN 0x02 /* Enable receiver */
8803 +#define ACT200L_ECHO 0x08 /* Echo control chars */
8805 +/* Register 1: Control register #2 */
8806 +#define ACT200L_REG1 0x10
8807 +#define ACT200L_LODB 0x01 /* Load new baud rate count value */
8808 +#define ACT200L_WIDE 0x04 /* Expand the maximum allowable pulse */
8810 +/* Register 3: Transmit mode register #2 */
8811 +#define ACT200L_REG3 0x30
8812 +#define ACT200L_B0 0x01 /* DataBits, 0=6, 1=7, 2=8, 3=9(8P) */
8813 +#define ACT200L_B1 0x02 /* DataBits, 0=6, 1=7, 2=8, 3=9(8P) */
8814 +#define ACT200L_CHSY 0x04 /* StartBit Synced 0=bittime, 1=startbit */
8816 +/* Register 4: Output Power register */
8817 +#define ACT200L_REG4 0x40
8818 +#define ACT200L_OP0 0x01 /* Enable LED1C output */
8819 +#define ACT200L_OP1 0x02 /* Enable LED2C output */
8820 +#define ACT200L_BLKR 0x04
8822 +/* Register 5: Receive Mode register */
8823 +#define ACT200L_REG5 0x50
8824 +#define ACT200L_RWIDL 0x01 /* fixed 1.6us pulse mode */
8825 + /*.. other various IRDA bit modes, and TV remote modes..*/
8827 +/* Register 6: Receive Sensitivity register #1 */
8828 +#define ACT200L_REG6 0x60
8829 +#define ACT200L_RS0 0x01 /* receive threshold bit 0 */
8830 +#define ACT200L_RS1 0x02 /* receive threshold bit 1 */
8832 +/* Register 7: Receive Sensitivity register #2 */
8833 +#define ACT200L_REG7 0x70
8834 +#define ACT200L_ENPOS 0x04 /* Ignore the falling edge */
8836 +/* Register 8,9: Baud Rate Dvider register #1,#2 */
8837 +#define ACT200L_REG8 0x80
8838 +#define ACT200L_REG9 0x90
8840 +#define ACT200L_2400 0x5f
8841 +#define ACT200L_9600 0x17
8842 +#define ACT200L_19200 0x0b
8843 +#define ACT200L_38400 0x05
8844 +#define ACT200L_57600 0x03
8845 +#define ACT200L_115200 0x01
8847 +/* Register 13: Control register #3 */
8848 +#define ACT200L_REG13 0xd0
8849 +#define ACT200L_SHDW 0x01 /* Enable access to shadow registers */
8851 +/* Register 15: Status register */
8852 +#define ACT200L_REG15 0xf0
8854 +/* Register 21: Control register #4 */
8855 +#define ACT200L_REG21 0x50
8856 +#define ACT200L_EXCK 0x02 /* Disable clock output driver */
8857 +#define ACT200L_OSCL 0x04 /* oscillator in low power, medium accuracy mode */
8859 +static void init_act200(void)
8862 + __u8 control[] = {
8864 + ACT200L_REG13 | ACT200L_SHDW,
8865 + ACT200L_REG21 | ACT200L_EXCK | ACT200L_OSCL,
8867 + ACT200L_REG7 | ACT200L_ENPOS,
8868 + ACT200L_REG6 | ACT200L_RS0 | ACT200L_RS1,
8869 + ACT200L_REG5 | ACT200L_RWIDL,
8870 + ACT200L_REG4 | ACT200L_OP0 | ACT200L_OP1 | ACT200L_BLKR,
8871 + ACT200L_REG3 | ACT200L_B0,
8872 + ACT200L_REG0 | ACT200L_TXEN | ACT200L_RXEN,
8873 + ACT200L_REG8 | (ACT200L_115200 & 0x0f),
8874 + ACT200L_REG9 | ((ACT200L_115200 >> 4) & 0x0f),
8875 + ACT200L_REG1 | ACT200L_LODB | ACT200L_WIDE
8879 + soutp(UART_LCR, UART_LCR_DLAB | UART_LCR_WLEN8);
8881 + /* Set divisor to 12 => 9600 Baud */
8882 + soutp(UART_DLM,0);
8883 + soutp(UART_DLL,12);
8886 + soutp(UART_LCR, UART_LCR_WLEN8);
8887 + /* Set divisor to 12 => 9600 Baud */
8889 + /* power supply */
8890 + soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2);
8891 + for (i=0; i<50; i++) {
8892 + safe_udelay(1000);
8895 + /* Reset the dongle : set RTS low for 25 ms */
8896 + soutp(UART_MCR, UART_MCR_DTR|UART_MCR_OUT2);
8897 + for (i=0; i<25; i++) {
8901 + soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2);
8904 + /* Clear DTR and set RTS to enter command mode */
8905 + soutp(UART_MCR, UART_MCR_RTS|UART_MCR_OUT2);
8908 +/* send out the control register settings for 115K 7N1 SIR operation */
8909 + for (i=0; i<sizeof(control); i++) {
8910 + soutp(UART_TX, control[i]);
8911 + /* one byte takes ~1042 usec to transmit at 9600,8N1 */
8915 + /* back to normal operation */
8916 + soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2);
8920 + soutp(UART_LCR, sinp(UART_LCR) | UART_LCR_DLAB);
8923 + soutp(UART_LCR, UART_LCR_DLAB | UART_LCR_WLEN7);
8925 + /* Set divisor to 1 => 115200 Baud */
8926 + soutp(UART_DLM,0);
8927 + soutp(UART_DLL,1);
8930 + soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
8932 + /* Set DLAB 0, 7 Bit */
8933 + soutp(UART_LCR, UART_LCR_WLEN7);
8935 + /* enable interrupts */
8936 + soutp(UART_IER, sinp(UART_IER)|UART_IER_RDI);
8940 +int init_lirc_sir(void)
8944 + init_waitqueue_head(&lirc_read_queue);
8945 + retval = init_port();
8950 + printk(KERN_INFO LIRC_DRIVER_NAME
8951 + ": Installed.\n");
8955 +#ifdef CONFIG_LIRC_SIR_TEKRAM
8956 +MODULE_AUTHOR("Christoph Bartelmus");
8957 +MODULE_DESCRIPTION("Infrared receiver driver for Tekram Irmate 210");
8958 +#elif defined(CONFIG_LIRC_ON_SA1100)
8959 +MODULE_AUTHOR("Christoph Bartelmus");
8960 +MODULE_DESCRIPTION("LIRC driver for StrongARM SA1100 embedded microprocessor");
8961 +#elif defined(CONFIG_LIRC_SIR_ACTISYS_ACT200L)
8962 +MODULE_AUTHOR("Karl Bongers");
8963 +MODULE_DESCRIPTION("LIRC driver for Actisys Act200L");
8965 +MODULE_AUTHOR("Milan Pikula");
8966 +MODULE_DESCRIPTION("Infrared receiver driver for SIR type serial ports");
8969 +#ifdef CONFIG_LIRC_ON_SA1100
8970 +MODULE_PARM(irq, "i");
8971 +MODULE_PARM_DESC(irq, "Interrupt (16)");
8973 +MODULE_PARM(io, "i");
8974 +MODULE_PARM_DESC(io, "I/O address base (0x3f8 or 0x2f8)");
8975 +MODULE_PARM(irq, "i");
8976 +MODULE_PARM_DESC(irq, "Interrupt (4 or 3)");
8977 +MODULE_PARM(threshold, "i");
8978 +MODULE_PARM_DESC(threshold, "space detection threshold (3)");
8981 +MODULE_LICENSE("GPL");
8983 +static int __init lirc_sir_init(void)
8987 + retval=init_chrdev();
8990 + retval = init_lirc_sir();
8998 +static void __exit lirc_sir_exit(void)
9000 +#ifdef CONFIG_MODULE_UNLOAD
9001 + if(module_refcount(THIS_MODULE)) return;
9006 + printk(KERN_INFO LIRC_DRIVER_NAME ": Uninstalled.\n");
9009 +module_init(lirc_sir_init);
9010 +module_exit(lirc_sir_exit);
9011 diff -uprN -X dontdiff linux-2.6.5.orig/drivers/char/lirc/Makefile linux-2.6.5/drivers/char/lirc/Makefile
9012 --- linux-2.6.5.orig/drivers/char/lirc/Makefile 1970-01-01 01:00:00.000000000 +0100
9013 +++ linux-2.6.5/drivers/char/lirc/Makefile 2004-04-04 14:05:29.434624528 +0200
9016 +# Makefile for the lirc drivers
9019 +obj-$(CONFIG_LIRC_SUPPORT) += lirc_dev.o
9020 +obj-$(CONFIG_LIRC_GPIO) += lirc_gpio.o
9021 +obj-$(CONFIG_LIRC_BT829) += lirc_bt829.o
9022 +obj-$(CONFIG_LIRC_IT87) += lirc_it87.o
9023 +obj-$(CONFIG_LIRC_PARALLEL) += lirc_parallel.o
9024 +obj-$(CONFIG_LIRC_SERIAL) += lirc_serial.o
9025 +obj-$(CONFIG_LIRC_SIR) += lirc_sir.o
9026 +obj-$(CONFIG_LIRC_ATIUSB) += lirc_atiusb.o
9027 +obj-$(CONFIG_LIRC_MCEUSB) += lirc_mceusb.o
9028 +obj-$(CONFIG_LIRC_I2C) += lirc_i2c.o
9029 diff -uprN -X dontdiff linux-2.6.5.orig/drivers/char/Makefile linux-2.6.5/drivers/char/Makefile
9030 --- linux-2.6.5.orig/drivers/char/Makefile 2004-04-04 13:59:17.630147400 +0200
9031 +++ linux-2.6.5/drivers/char/Makefile 2004-04-04 14:05:29.437624072 +0200
9034 FONTMAPFILE = cp437.uni
9036 -obj-y += mem.o random.o tty_io.o n_tty.o tty_ioctl.o pty.o misc.o
9037 +obj-y += mem.o random.o tty_io.o n_tty.o tty_ioctl.o pty.o misc.o lirc/
9039 obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o consolemap.o \
9040 consolemap_deftbl.o selection.o keyboard.o
9041 diff -uprN -X dontdiff linux-2.6.5.orig/include/linux/lirc.h linux-2.6.5/include/linux/lirc.h
9042 --- linux-2.6.5.orig/include/linux/lirc.h 1970-01-01 01:00:00.000000000 +0100
9043 +++ linux-2.6.5/include/linux/lirc.h 2004-04-04 14:05:29.439623768 +0200
9047 +#ifndef _LINUX_LIRC_H
9048 +#define _LINUX_LIRC_H
9050 +#if defined (__linux__)
9051 +#include <asm/types.h>
9052 +#include <linux/ioctl.h>
9054 +#include <sys/types.h>
9055 +typedef u_int32_t __u32;
9058 +#define PULSE_BIT 0x01000000
9059 +#define PULSE_MASK 0x00FFFFFF
9061 +typedef int lirc_t;
9064 + * lirc compatible hardware features
9068 +#define LIRC_MODE2SEND(x) (x)
9069 +#define LIRC_SEND2MODE(x) (x)
9070 +#define LIRC_MODE2REC(x) ((x) << 16)
9071 +#define LIRC_REC2MODE(x) ((x) >> 16)
9073 +#define LIRC_MODE_RAW 0x00000001
9074 +#define LIRC_MODE_PULSE 0x00000002
9075 +#define LIRC_MODE_MODE2 0x00000004
9076 +#define LIRC_MODE_CODE 0x00000008
9077 +#define LIRC_MODE_LIRCCODE 0x00000010
9078 +#define LIRC_MODE_STRING 0x00000020
9081 +#define LIRC_CAN_SEND_RAW LIRC_MODE2SEND(LIRC_MODE_RAW)
9082 +#define LIRC_CAN_SEND_PULSE LIRC_MODE2SEND(LIRC_MODE_PULSE)
9083 +#define LIRC_CAN_SEND_MODE2 LIRC_MODE2SEND(LIRC_MODE_MODE2)
9084 +#define LIRC_CAN_SEND_CODE LIRC_MODE2SEND(LIRC_MODE_CODE)
9085 +#define LIRC_CAN_SEND_LIRCCODE LIRC_MODE2SEND(LIRC_MODE_LIRCCODE)
9086 +#define LIRC_CAN_SEND_STRING LIRC_MODE2SEND(LIRC_MODE_STRING)
9088 +#define LIRC_CAN_SEND_MASK 0x0000003f
9090 +#define LIRC_CAN_SET_SEND_CARRIER 0x00000100
9091 +#define LIRC_CAN_SET_SEND_DUTY_CYCLE 0x00000200
9093 +#define LIRC_CAN_REC_RAW LIRC_MODE2REC(LIRC_MODE_RAW)
9094 +#define LIRC_CAN_REC_PULSE LIRC_MODE2REC(LIRC_MODE_PULSE)
9095 +#define LIRC_CAN_REC_MODE2 LIRC_MODE2REC(LIRC_MODE_MODE2)
9096 +#define LIRC_CAN_REC_CODE LIRC_MODE2REC(LIRC_MODE_CODE)
9097 +#define LIRC_CAN_REC_LIRCCODE LIRC_MODE2REC(LIRC_MODE_LIRCCODE)
9098 +#define LIRC_CAN_REC_STRING LIRC_MODE2REC(LIRC_MODE_STRING)
9100 +#define LIRC_CAN_REC_MASK LIRC_MODE2REC(LIRC_CAN_SEND_MASK)
9102 +#define LIRC_CAN_SET_REC_CARRIER (LIRC_CAN_SET_SEND_CARRIER << 16)
9103 +#define LIRC_CAN_SET_REC_DUTY_CYCLE (LIRC_CAN_SET_SEND_DUTY_CYCLE << 16)
9105 +#define LIRC_CAN_SET_REC_DUTY_CYCLE_RANGE 0x40000000
9106 +#define LIRC_CAN_SET_REC_CARRIER_RANGE 0x80000000
9109 +#define LIRC_CAN_SEND(x) ((x)&LIRC_CAN_SEND_MASK)
9110 +#define LIRC_CAN_REC(x) ((x)&LIRC_CAN_REC_MASK)
9113 + * IOCTL commands for lirc driver
9116 +#define LIRC_GET_FEATURES _IOR('i', 0x00000000, __u32)
9118 +#define LIRC_GET_SEND_MODE _IOR('i', 0x00000001, __u32)
9119 +#define LIRC_GET_REC_MODE _IOR('i', 0x00000002, __u32)
9120 +#define LIRC_GET_SEND_CARRIER _IOR('i', 0x00000003, __u32)
9121 +#define LIRC_GET_REC_CARRIER _IOR('i', 0x00000004, __u32)
9122 +#define LIRC_GET_SEND_DUTY_CYCLE _IOR('i', 0x00000005, __u32)
9123 +#define LIRC_GET_REC_DUTY_CYCLE _IOR('i', 0x00000006, __u32)
9125 +/* code length in bits, currently only for LIRC_MODE_LIRCCODE */
9126 +#define LIRC_GET_LENGTH _IOR('i', 0x0000000f, __u32)
9128 +#define LIRC_SET_SEND_MODE _IOW('i', 0x00000011, __u32)
9129 +#define LIRC_SET_REC_MODE _IOW('i', 0x00000012, __u32)
9130 +/* Note: these can reset the according pulse_width */
9131 +#define LIRC_SET_SEND_CARRIER _IOW('i', 0x00000013, __u32)
9132 +#define LIRC_SET_REC_CARRIER _IOW('i', 0x00000014, __u32)
9133 +#define LIRC_SET_SEND_DUTY_CYCLE _IOW('i', 0x00000015, __u32)
9134 +#define LIRC_SET_REC_DUTY_CYCLE _IOW('i', 0x00000016, __u32)
9136 +/* to set a range use
9137 + LIRC_SET_REC_DUTY_CYCLE_RANGE/LIRC_SET_REC_CARRIER_RANGE with the
9138 + lower bound first and later
9139 + LIRC_SET_REC_DUTY_CYCLE/LIRC_SET_REC_CARRIER with the upper bound */
9141 +#define LIRC_SET_REC_DUTY_CYCLE_RANGE _IOW('i', 0x0000001e, __u32)
9142 +#define LIRC_SET_REC_CARRIER_RANGE _IOW('i', 0x0000001f, __u32)
9144 +#define DEV_LIRC "lirc"
9145 +#define IRCTL_DEV_MAJOR 61