--- drivers/lirc_parallel/lirc_parallel.c.orig	2010-08-20 11:01:21.000000000 -0600
+++ drivers/lirc_parallel/lirc_parallel.c	2010-08-20 14:00:28.000000000 -0600
@@ -87,6 +87,13 @@
 #define LIRC_TIMER 65536
 #endif
 
+#undef LIRC_TIMER
+
+#define PERIOD 1000
+#define SHORT_PERIOD 2*PERIOD
+#define LONG_PERIOD 3*PERIOD
+#define SYNC_PERIOD 6*PERIOD
+
 /*** Global Variables ***/
 
 static int debug;
@@ -94,15 +101,9 @@
 
 unsigned int irq = LIRC_IRQ;
 unsigned int io = LIRC_PORT;
-#ifdef LIRC_TIMER
-unsigned int timer;
-unsigned int default_timer = LIRC_TIMER;
-#endif
 
-#define WBUF_SIZE (256)
-#define RBUF_SIZE (256) /* this must be a power of 2 larger than 1 */
+#define RBUF_SIZE (1024) /* this must be a power of 2 larger than 1 */
 
-static lirc_t wbuf[WBUF_SIZE];
 static lirc_t rbuf[RBUF_SIZE];
 
 DECLARE_WAIT_QUEUE_HEAD(lirc_wait);
@@ -123,14 +124,15 @@
 static unsigned int in(int offset)
 {
 	switch (offset) {
-	case LIRC_LP_BASE:
-		return parport_read_data(pport);
-	case LIRC_LP_STATUS:
-		return parport_read_status(pport);
-	case LIRC_LP_CONTROL:
-		return parport_read_control(pport);
+		case LIRC_LP_BASE:
+			return parport_read_data(pport);
+		case LIRC_LP_STATUS:
+			return parport_read_status(pport);
+		case LIRC_LP_CONTROL:
+			return parport_read_control(pport);
+		default:
+			return 0;
 	}
-	return 0; /* make compiler happy */
 }
 
 static void out(int offset, int value)
@@ -149,73 +151,21 @@
 	}
 }
 
-static unsigned int lirc_get_timer(void)
-{
-	return in(LIRC_PORT_TIMER) & LIRC_PORT_TIMER_BIT;
-}
-
-static unsigned int lirc_get_signal(void)
-{
-	return in(LIRC_PORT_SIGNAL) & LIRC_PORT_SIGNAL_BIT;
-}
-
 static void lirc_on(void)
 {
-	out(LIRC_PORT_DATA, tx_mask);
+	out(LIRC_PORT_DATA, 0xFF);
+	
+	if (debug == 0x01) {
+		printk(KERN_INFO "%s: receiver on.\n", LIRC_DRIVER_NAME);
+	}
 }
 
 static void lirc_off(void)
 {
-	out(LIRC_PORT_DATA, 0);
-}
-
-static unsigned int init_lirc_timer(void)
-{
-	struct timeval tv, now;
-	unsigned int level, newlevel, timeelapsed, newtimer;
-	int count = 0;
-
-	do_gettimeofday(&tv);
-	tv.tv_sec++;                     /* wait max. 1 sec. */
-	level = lirc_get_timer();
-	do {
-		newlevel = lirc_get_timer();
-		if (level == 0 && newlevel != 0)
-			count++;
-		level = newlevel;
-		do_gettimeofday(&now);
-	} while (count < 1000 && (now.tv_sec < tv.tv_sec
-			     || (now.tv_sec == tv.tv_sec
-				 && now.tv_usec < tv.tv_usec)));
-
-	timeelapsed = ((now.tv_sec + 1 - tv.tv_sec)*1000000
-		     + (now.tv_usec - tv.tv_usec));
-	if (count >= 1000 && timeelapsed > 0) {
-		if (default_timer == 0) {
-			/* autodetect timer */
-			newtimer = (1000000*count)/timeelapsed;
-			printk(KERN_INFO "%s: %u Hz timer detected\n",
-			       LIRC_DRIVER_NAME, newtimer);
-			return newtimer;
-		}  else {
-			newtimer = (1000000*count)/timeelapsed;
-			if (abs(newtimer - default_timer) > default_timer/10) {
-				/* bad timer */
-				printk(KERN_NOTICE "%s: bad timer: %u Hz\n",
-				       LIRC_DRIVER_NAME, newtimer);
-				printk(KERN_NOTICE "%s: using default timer: "
-				       "%u Hz\n",
-				       LIRC_DRIVER_NAME, default_timer);
-				return default_timer;
-			} else {
-				printk(KERN_INFO "%s: %u Hz timer detected\n",
-				       LIRC_DRIVER_NAME, newtimer);
-				return newtimer; /* use detected value */
-			}
-		}
-	} else {
-		printk(KERN_NOTICE "%s: no timer detected\n", LIRC_DRIVER_NAME);
-		return 0;
+	out(LIRC_PORT_DATA, 0x00);
+	
+	if (debug == 0x01) {
+		printk(KERN_INFO "%s: receiver off.\n", LIRC_DRIVER_NAME);
 	}
 }
 
@@ -266,99 +216,43 @@
 	static struct timeval lasttv;
 	static int init;
 	long signal;
-	lirc_t data;
-	unsigned int level, newlevel;
-	unsigned int timeout;
-
-	if (!MOD_IN_USE)
-		return;
-
+	long short_error;
+	long long_error;
+	long sync_error;
+	long pulse;
+	
 	if (!is_claimed)
 		return;
 
-#if 0
-	/* disable interrupt */
-	disable_irq(irq);
-	out(LIRC_PORT_IRQ, in(LIRC_PORT_IRQ) & (~LP_PINTEN));
-#endif
 	if (check_pselecd && (in(1) & LP_PSELECD))
 		return;
 
-#ifdef LIRC_TIMER
-	if (init) {
+	if (init == 0x00) { // This is the first time the IRQ routine has been run.
+		do_gettimeofday(&lasttv);
+		init = 0x01;
+	}
+	else {
 		do_gettimeofday(&tv);
-
-		signal = tv.tv_sec - lasttv.tv_sec;
-		if (signal > 15)
-			/* really long time */
-			data = PULSE_MASK;
-		else
-			data = (lirc_t) (signal*1000000 +
-					 tv.tv_usec - lasttv.tv_usec +
-					 LIRC_SFH506_DELAY);
-
-		rbuf_write(data); /* space */
-	} else {
-		if (timer == 0) {
-			/*
-			 * wake up; we'll lose this signal, but it will be
-			 * garbage if the device is turned on anyway
-			 */
-			timer = init_lirc_timer();
-			/* enable_irq(irq); */
-			return;
+		
+		signal= ((tv.tv_sec - lasttv.tv_sec)*1000000) + (tv.tv_usec - lasttv.tv_usec);
+		
+		if (debug == 0x01) {
+			printk(KERN_NOTICE "%s: Received signal of length %ld.\n", LIRC_DRIVER_NAME, signal);
 		}
-		init = 1;
-	}
-
-	timeout = timer/10;	/* timeout after 1/10 sec. */
-	signal = 1;
-	level = lirc_get_timer();
-	do {
-		newlevel = lirc_get_timer();
-		if (level == 0 && newlevel != 0)
-			signal++;
-		level = newlevel;
-
-		/* giving up */
-		if (signal > timeout
-		    || (check_pselecd && (in(1) & LP_PSELECD))) {
-			signal = 0;
-			printk(KERN_NOTICE "%s: timeout\n", LIRC_DRIVER_NAME);
-			break;
+		
+		if (signal > 200000) { // 200 milliseconds
+			rbuf_write(PULSE_MASK); 
+			rbuf_write(9000 | PULSE_BIT);
+		} 
+		else {
+			rbuf_write(signal / 2);
+			rbuf_write((signal / 2) | PULSE_BIT);
 		}
-	} while (lirc_get_signal());
-
-	if (signal != 0) {
-		/* adjust value to usecs */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 0)
-		unsigned long long helper;
-
-		helper = ((unsigned long long) signal)*1000000;
-		do_div(helper, timer);
-		signal = (long) helper;
-#else
-		signal = (long) ((((double) signal)*1000000)/timer);
-#endif
-
-		if (signal > LIRC_SFH506_DELAY)
-			data = signal - LIRC_SFH506_DELAY;
-		else
-			data = 1;
-		rbuf_write(PULSE_BIT|data); /* pulse */
 	}
+	
 	do_gettimeofday(&lasttv);
-#else
-	/* add your code here */
-#endif
 
 	wake_up_interruptible(&lirc_wait);
-
-	/* enable interrupt */
-	/*
-	  enable_irq(irq);
-	  out(LIRC_PORT_IRQ, in(LIRC_PORT_IRQ)|LP_PINTEN);
-	*/
 }
 
 /*** file operations ***/
@@ -406,92 +300,6 @@
 	return count ? count : result;
 }
 
-static ssize_t lirc_write(struct file *filep, const char *buf, size_t n,
-			  loff_t *ppos)
-{
-	int count;
-	unsigned int i;
-	unsigned int level, newlevel;
-	unsigned long flags;
-	lirc_t counttimer;
-
-	if (!is_claimed)
-		return -EBUSY;
-
-	if (n % sizeof(lirc_t))
-		return -EINVAL;
-
-	count = n / sizeof(lirc_t);
-
-	if (count > WBUF_SIZE || count % 2 == 0)
-		return -EINVAL;
-
-	if (copy_from_user(wbuf, buf, n))
-		return -EFAULT;
-
-#ifdef LIRC_TIMER
-	if (timer == 0) {
-		/* try again if device is ready */
-		timer = init_lirc_timer();
-		if (timer == 0)
-			return -EIO;
-	}
-
-	/* adjust values from usecs */
-	for (i = 0; i < count; i++) {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 0)
-		unsigned long long helper;
-
-		helper = ((unsigned long long) wbuf[i])*timer;
-		do_div(helper, 1000000);
-		wbuf[i] = (lirc_t) helper;
-#else
-		wbuf[i] = (lirc_t) (((double) wbuf[i])*timer/1000000);
-#endif
-	}
-
-	local_irq_save(flags);
-	i = 0;
-	while (i < count) {
-		level = lirc_get_timer();
-		counttimer = 0;
-		lirc_on();
-		do {
-			newlevel = lirc_get_timer();
-			if (level == 0 && newlevel != 0)
-				counttimer++;
-			level = newlevel;
-			if (check_pselecd && (in(1) & LP_PSELECD)) {
-				lirc_off();
-				local_irq_restore(flags);
-				return -EIO;
-			}
-		} while (counttimer < wbuf[i]);
-		i++;
-
-		lirc_off();
-		if (i == count)
-			break;
-		counttimer = 0;
-		do {
-			newlevel = lirc_get_timer();
-			if (level == 0 && newlevel != 0)
-				counttimer++;
-			level = newlevel;
-			if (check_pselecd && (in(1) & LP_PSELECD)) {
-				local_irq_restore(flags);
-				return -EIO;
-			}
-		} while (counttimer < wbuf[i]);
-		i++;
-	}
-	local_irq_restore(flags);
-#else
-	/* place code that handles write without external timer here */
-#endif
-	return n;
-}
-
 static unsigned int lirc_poll(struct file *file, poll_table *wait)
 {
 	poll_wait(file, &lirc_wait, wait);
@@ -504,10 +312,8 @@
 		      unsigned long arg)
 {
 	int result;
-	unsigned long features = LIRC_CAN_SET_TRANSMITTER_MASK |
-				 LIRC_CAN_SEND_PULSE | LIRC_CAN_REC_MODE2;
+	unsigned long features = LIRC_CAN_REC_MODE2;
 	unsigned long mode;
-	unsigned int ivalue;
 
 	switch (cmd) {
 	case LIRC_GET_FEATURES:
@@ -515,23 +321,11 @@
 		if (result)
 			return result;
 		break;
-	case LIRC_GET_SEND_MODE:
-		result = put_user(LIRC_MODE_PULSE, (unsigned long *) arg);
-		if (result)
-			return result;
-		break;
 	case LIRC_GET_REC_MODE:
 		result = put_user(LIRC_MODE_MODE2, (unsigned long *) arg);
 		if (result)
 			return result;
 		break;
-	case LIRC_SET_SEND_MODE:
-		result = get_user(mode, (unsigned long *) arg);
-		if (result)
-			return result;
-		if (mode != LIRC_MODE_PULSE)
-			return -EINVAL;
-		break;
 	case LIRC_SET_REC_MODE:
 		result = get_user(mode, (unsigned long *) arg);
 		if (result)
@@ -539,14 +333,6 @@
 		if (mode != LIRC_MODE_MODE2)
 			return -ENOSYS;
 		break;
-	case LIRC_SET_TRANSMITTER_MASK:
-		result = get_user(ivalue, (unsigned int *) arg);
-		if (result)
-			return result;
-		if ((ivalue & LIRC_PARALLEL_TRANSMITTER_MASK) != ivalue)
-			return LIRC_PARALLEL_MAX_TRANSMITTERS;
-		tx_mask = ivalue;
-		break;
 	default:
 		return -ENOIOCTLCMD;
 	}
@@ -564,6 +350,8 @@
 	rptr = 0;
 	wptr = 0;
 	lost_irqs = 0;
+	
+	lirc_on();
 
 	MOD_INC_USE_COUNT;
 	is_open = 1;
@@ -585,7 +373,6 @@
 	.owner		= THIS_MODULE,
 	.llseek		= lirc_lseek,
 	.read		= lirc_read,
-	.write		= lirc_write,
 	.poll		= lirc_poll,
 	.ioctl		= lirc_ioctl,
 	.open		= lirc_open,
@@ -623,26 +410,6 @@
 static void kf(void *handle);
 
 static struct timer_list poll_timer;
-static void poll_state(unsigned long ignored);
-
-static void poll_state(unsigned long ignored)
-{
-	printk(KERN_NOTICE "%s: time\n",
-	       LIRC_DRIVER_NAME);
-	del_timer(&poll_timer);
-	if (is_claimed)
-		return;
-	kf(NULL);
-	if (!is_claimed) {
-		printk(KERN_NOTICE "%s: could not claim port, giving up\n",
-		       LIRC_DRIVER_NAME);
-		init_timer(&poll_timer);
-		poll_timer.expires = jiffies + HZ;
-		poll_timer.data = (unsigned long)current;
-		poll_timer.function = poll_state;
-		add_timer(&poll_timer);
-	}
-}
 
 static int pf(void *handle)
 {
@@ -669,6 +436,9 @@
 
 static int __init lirc_parallel_init(void)
 {
+	if (debug == 0x01) {
+		printk(KERN_INFO "%s: debug on.\n", LIRC_DRIVER_NAME);
+	}
 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 3)
 	pport = parport_find_base(io);
 #else
@@ -699,25 +469,6 @@
 	is_claimed = 1;
 	out(LIRC_LP_CONTROL, LP_PSELECP|LP_PINITP);
 
-#ifdef LIRC_TIMER
-	if (debug)
-		out(LIRC_PORT_DATA, tx_mask);
-
-	timer = init_lirc_timer();
-
-#if 0	/* continue even if device is offline */
-	if (timer == 0) {
-		is_claimed = 0;
-		parport_release(pport);
-		parport_unregister_device(ppdevice);
-		return -EIO;
-	}
-
-#endif
-	if (debug)
-		out(LIRC_PORT_DATA, 0);
-#endif
-
 	is_claimed = 0;
 	parport_release(ppdevice);
  skip_init:
