aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/lirc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/lirc')
-rw-r--r--drivers/staging/lirc/Kconfig12
-rw-r--r--drivers/staging/lirc/Makefile2
-rw-r--r--drivers/staging/lirc/TODO.lirc_zilog51
-rw-r--r--drivers/staging/lirc/lirc_ene0100.h4
-rw-r--r--drivers/staging/lirc/lirc_imon.c2
-rw-r--r--drivers/staging/lirc/lirc_it87.c1027
-rw-r--r--drivers/staging/lirc/lirc_it87.h116
-rw-r--r--drivers/staging/lirc/lirc_ite8709.c542
-rw-r--r--drivers/staging/lirc/lirc_sasem.c2
-rw-r--r--drivers/staging/lirc/lirc_zilog.c814
10 files changed, 535 insertions, 2037 deletions
diff --git a/drivers/staging/lirc/Kconfig b/drivers/staging/lirc/Kconfig
index cdaff5903a8f..526ec0fc2f04 100644
--- a/drivers/staging/lirc/Kconfig
+++ b/drivers/staging/lirc/Kconfig
@@ -32,18 +32,6 @@ config LIRC_IMON
Current generation iMON devices use the input layer imon driver.
-config LIRC_IT87
- tristate "ITE IT87XX CIR Port Receiver"
- depends on LIRC && PNP
- help
- Driver for the ITE IT87xx IR Receiver
-
-config LIRC_ITE8709
- tristate "ITE8709 CIR Port Receiver"
- depends on LIRC && PNP
- help
- Driver for the ITE8709 IR Receiver
-
config LIRC_PARALLEL
tristate "Homebrew Parallel Port Receiver"
depends on LIRC && PARPORT
diff --git a/drivers/staging/lirc/Makefile b/drivers/staging/lirc/Makefile
index 94af218d8373..d76b0fa2af53 100644
--- a/drivers/staging/lirc/Makefile
+++ b/drivers/staging/lirc/Makefile
@@ -6,8 +6,6 @@
obj-$(CONFIG_LIRC_BT829) += lirc_bt829.o
obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o
obj-$(CONFIG_LIRC_IMON) += lirc_imon.o
-obj-$(CONFIG_LIRC_IT87) += lirc_it87.o
-obj-$(CONFIG_LIRC_ITE8709) += lirc_ite8709.o
obj-$(CONFIG_LIRC_PARALLEL) += lirc_parallel.o
obj-$(CONFIG_LIRC_SASEM) += lirc_sasem.o
obj-$(CONFIG_LIRC_SERIAL) += lirc_serial.o
diff --git a/drivers/staging/lirc/TODO.lirc_zilog b/drivers/staging/lirc/TODO.lirc_zilog
index 2d0263f07937..a97800a8e127 100644
--- a/drivers/staging/lirc/TODO.lirc_zilog
+++ b/drivers/staging/lirc/TODO.lirc_zilog
@@ -1,34 +1,33 @@
-1. Both ir-kbd-i2c and lirc_zilog provide support for RX events.
-The 'tx_only' lirc_zilog module parameter will allow ir-kbd-i2c
-and lirc_zilog to coexist in the kernel, if the user requires such a set-up.
-However the IR unit will not work well without coordination between the
-two modules. A shared mutex, for transceiver access locking, needs to be
-supplied by bridge drivers, in struct IR_i2_init_data, to both ir-kbd-i2c
-and lirc_zilog, before they will coexist usefully. This should be fixed
-before moving out of staging.
-
-2. References and locking need careful examination. For cx18 and ivtv PCI
-cards, which are not easily "hot unplugged", the imperfect state of reference
-counting and locking is acceptable if not correct. For USB connected units
-like HD PVR, PVR USB2, HVR-1900, and HVR1950, the likelyhood of an Ooops on
-unplug is probably great. Proper reference counting and locking needs to be
-implemented before this module is moved out of staging.
-
-3. The binding between hdpvr and lirc_zilog is currently disabled,
-due to an OOPS reported a few years ago when both the hdpvr and cx18
-drivers were loaded in his system. More details can be seen at:
- http://www.mail-archive.com/linux-media@vger.kernel.org/msg09163.html
-More tests need to be done, in order to fix the reported issue.
-
-4. In addition to providing a shared mutex for transceiver access
-locking, bridge drivers, if able, should provide a chip reset() callback
+1. Both ir-kbd-i2c and lirc_zilog provide support for RX events for
+the chips supported by lirc_zilog. Before moving lirc_zilog out of staging:
+
+a. ir-kbd-i2c needs a module parameter added to allow the user to tell
+ ir-kbd-i2c to ignore Z8 IR units.
+
+b. lirc_zilog should provide Rx key presses to the rc core like ir-kbd-i2c
+ does.
+
+
+2. lirc_zilog module ref-counting need examination. It has not been
+verified that cdev and lirc_dev will take the proper module references on
+lirc_zilog to prevent removal of lirc_zilog when the /dev/lircN device node
+is open.
+
+(The good news is ref-counting of lirc_zilog internal structures appears to be
+complete. Testing has shown the cx18 module can be unloaded out from under
+irw + lircd + lirc_dev, with the /dev/lirc0 device node open, with no adverse
+effects. The cx18 module could then be reloaded and irw properly began
+receiving button presses again and ir_send worked without error.)
+
+
+3. Bridge drivers, if able, should provide a chip reset() callback
to lirc_zilog via struct IR_i2c_init_data. cx18 and ivtv already have routines
-to perform Z8 chip resets via GPIO manipulations. This will allow lirc_zilog
+to perform Z8 chip resets via GPIO manipulations. This would allow lirc_zilog
to bring the chip back to normal when it hangs, in the same places the
original lirc_pvr150 driver code does. This is not strictly needed, so it
is not required to move lirc_zilog out of staging.
-5. Both lirc_zilog and ir-kbd-i2c support the Zilog Z8 for IR, as programmed
+Note: Both lirc_zilog and ir-kbd-i2c support the Zilog Z8 for IR, as programmed
and installed on Hauppauge products. When working on either module, developers
must consider at least the following bridge drivers which mention an IR Rx unit
at address 0x71 (indicative of a Z8):
diff --git a/drivers/staging/lirc/lirc_ene0100.h b/drivers/staging/lirc/lirc_ene0100.h
index 776b693bb307..06bebd6acc46 100644
--- a/drivers/staging/lirc/lirc_ene0100.h
+++ b/drivers/staging/lirc/lirc_ene0100.h
@@ -81,7 +81,7 @@
/* CIR block settings */
#define ENE_CIR_CONF1 0xFEC0
-#define ENE_CIR_CONF1_ADC_ON 0x7 /* reciever on gpio40 enabled */
+#define ENE_CIR_CONF1_ADC_ON 0x7 /* receiver on gpio40 enabled */
#define ENE_CIR_CONF1_LEARN1 (1 << 3) /* enabled on learning mode */
#define ENE_CIR_CONF1_TX_ON 0x30 /* enabled on transmit */
#define ENE_CIR_CONF1_TX_CARR (1 << 7) /* send TX carrier or not */
@@ -96,7 +96,7 @@
/* transmitter - not implemented yet */
/* KB3926C and higher */
-/* transmission is very similiar to recieving, a byte is written to */
+/* transmission is very similar to receiving, a byte is written to */
/* ENE_TX_INPUT, in same manner as it is read from sample buffer */
/* sample period is fixed*/
diff --git a/drivers/staging/lirc/lirc_imon.c b/drivers/staging/lirc/lirc_imon.c
index 235cab0eb087..4039eda2a15b 100644
--- a/drivers/staging/lirc/lirc_imon.c
+++ b/drivers/staging/lirc/lirc_imon.c
@@ -379,7 +379,7 @@ static ssize_t vfd_write(struct file *file, const char *buf,
struct imon_context *context;
const unsigned char vfd_packet6[] = {
0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF };
- int *data_buf;
+ int *data_buf = NULL;
context = file->private_data;
if (!context) {
diff --git a/drivers/staging/lirc/lirc_it87.c b/drivers/staging/lirc/lirc_it87.c
deleted file mode 100644
index 5938616f3e8f..000000000000
--- a/drivers/staging/lirc/lirc_it87.c
+++ /dev/null
@@ -1,1027 +0,0 @@
-/*
- * LIRC driver for ITE IT8712/IT8705 CIR port
- *
- * Copyright (C) 2001 Hans-Gunter Lutke Uphues <hg_lu@web.de>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- *
- * ITE IT8705 and IT8712(not tested) and IT8720 CIR-port support for lirc based
- * via cut and paste from lirc_sir.c (C) 2000 Milan Pikula
- *
- * Attention: Sendmode only tested with debugging logs
- *
- * 2001/02/27 Christoph Bartelmus <lirc@bartelmus.de> :
- * reimplemented read function
- * 2005/06/05 Andrew Calkin implemented support for Asus Digimatrix,
- * based on work of the following member of the Outertrack Digimatrix
- * Forum: Art103 <r_tay@hotmail.com>
- * 2009/12/24 James Edwards <jimbo-lirc@edwardsclan.net> implemeted support
- * for ITE8704/ITE8718, on my machine, the DSDT reports 8704, but the
- * chip identifies as 18.
- */
-
-#include <linux/module.h>
-#include <linux/sched.h>
-#include <linux/errno.h>
-#include <linux/signal.h>
-#include <linux/fs.h>
-#include <linux/interrupt.h>
-#include <linux/ioport.h>
-#include <linux/kernel.h>
-#include <linux/time.h>
-#include <linux/string.h>
-#include <linux/types.h>
-#include <linux/wait.h>
-#include <linux/mm.h>
-#include <linux/delay.h>
-#include <linux/poll.h>
-#include <asm/system.h>
-#include <linux/io.h>
-#include <linux/irq.h>
-#include <linux/fcntl.h>
-
-#include <linux/timer.h>
-#include <linux/pnp.h>
-
-#include <media/lirc.h>
-#include <media/lirc_dev.h>
-
-#include "lirc_it87.h"
-
-#ifdef LIRC_IT87_DIGIMATRIX
-static int digimatrix = 1;
-static int it87_freq = 36; /* kHz */
-static int irq = 9;
-#else
-static int digimatrix;
-static int it87_freq = 38; /* kHz */
-static int irq = IT87_CIR_DEFAULT_IRQ;
-#endif
-
-static unsigned long it87_bits_in_byte_out;
-static unsigned long it87_send_counter;
-static unsigned char it87_RXEN_mask = IT87_CIR_RCR_RXEN;
-
-#define RBUF_LEN 1024
-
-#define LIRC_DRIVER_NAME "lirc_it87"
-
-/* timeout for sequences in jiffies (=5/100s) */
-/* must be longer than TIME_CONST */
-#define IT87_TIMEOUT (HZ*5/100)
-
-/* module parameters */
-static int debug;
-#define dprintk(fmt, args...) \
- do { \
- if (debug) \
- printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
- fmt, ## args); \
- } while (0)
-
-static int io = IT87_CIR_DEFAULT_IOBASE;
-/* receiver demodulator default: off */
-static int it87_enable_demodulator;
-
-static int timer_enabled;
-static DEFINE_SPINLOCK(timer_lock);
-static struct timer_list timerlist;
-/* time of last signal change detected */
-static struct timeval last_tv = {0, 0};
-/* time of last UART data ready interrupt */
-static struct timeval last_intr_tv = {0, 0};
-static int last_value;
-
-static DECLARE_WAIT_QUEUE_HEAD(lirc_read_queue);
-
-static DEFINE_SPINLOCK(hardware_lock);
-static DEFINE_SPINLOCK(dev_lock);
-static bool device_open;
-
-static int rx_buf[RBUF_LEN];
-unsigned int rx_tail, rx_head;
-
-static struct pnp_driver it87_pnp_driver;
-
-/* SECTION: Prototypes */
-
-/* Communication with user-space */
-static int lirc_open(struct inode *inode, struct file *file);
-static int lirc_close(struct inode *inode, struct file *file);
-static unsigned int lirc_poll(struct file *file, poll_table *wait);
-static ssize_t lirc_read(struct file *file, char *buf,
- size_t count, loff_t *ppos);
-static ssize_t lirc_write(struct file *file, const char *buf,
- size_t n, loff_t *pos);
-static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
-static void add_read_queue(int flag, unsigned long val);
-static int init_chrdev(void);
-static void drop_chrdev(void);
-/* Hardware */
-static irqreturn_t it87_interrupt(int irq, void *dev_id);
-static void send_space(unsigned long len);
-static void send_pulse(unsigned long len);
-static void init_send(void);
-static void terminate_send(unsigned long len);
-static int init_hardware(void);
-static void drop_hardware(void);
-/* Initialisation */
-static int init_port(void);
-static void drop_port(void);
-
-
-/* SECTION: Communication with user-space */
-
-static int lirc_open(struct inode *inode, struct file *file)
-{
- spin_lock(&dev_lock);
- if (device_open) {
- spin_unlock(&dev_lock);
- return -EBUSY;
- }
- device_open = true;
- spin_unlock(&dev_lock);
- return 0;
-}
-
-
-static int lirc_close(struct inode *inode, struct file *file)
-{
- spin_lock(&dev_lock);
- device_open = false;
- spin_unlock(&dev_lock);
- return 0;
-}
-
-
-static unsigned int lirc_poll(struct file *file, poll_table *wait)
-{
- poll_wait(file, &lirc_read_queue, wait);
- if (rx_head != rx_tail)
- return POLLIN | POLLRDNORM;
- return 0;
-}
-
-
-static ssize_t lirc_read(struct file *file, char *buf,
- size_t count, loff_t *ppos)
-{
- int n = 0;
- int retval = 0;
-
- while (n < count) {
- if (file->f_flags & O_NONBLOCK && rx_head == rx_tail) {
- retval = -EAGAIN;
- break;
- }
- retval = wait_event_interruptible(lirc_read_queue,
- rx_head != rx_tail);
- if (retval)
- break;
-
- if (copy_to_user((void *) buf + n, (void *) (rx_buf + rx_head),
- sizeof(int))) {
- retval = -EFAULT;
- break;
- }
- rx_head = (rx_head + 1) & (RBUF_LEN - 1);
- n += sizeof(int);
- }
- if (n)
- return n;
- return retval;
-}
-
-
-static ssize_t lirc_write(struct file *file, const char *buf,
- size_t n, loff_t *pos)
-{
- int i = 0;
- int *tx_buf;
-
- if (n % sizeof(int))
- return -EINVAL;
- tx_buf = memdup_user(buf, n);
- if (IS_ERR(tx_buf))
- return PTR_ERR(tx_buf);
- n /= sizeof(int);
- init_send();
- while (1) {
- if (i >= n)
- break;
- if (tx_buf[i])
- send_pulse(tx_buf[i]);
- i++;
- if (i >= n)
- break;
- if (tx_buf[i])
- send_space(tx_buf[i]);
- i++;
- }
- terminate_send(tx_buf[i - 1]);
- kfree(tx_buf);
- return n;
-}
-
-
-static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
-{
- int retval = 0;
- __u32 value = 0;
- unsigned long hw_flags;
-
- if (cmd == LIRC_GET_FEATURES)
- value = LIRC_CAN_SEND_PULSE |
- LIRC_CAN_SET_SEND_CARRIER |
- LIRC_CAN_REC_MODE2;
- else if (cmd == LIRC_GET_SEND_MODE)
- value = LIRC_MODE_PULSE;
- else if (cmd == LIRC_GET_REC_MODE)
- value = LIRC_MODE_MODE2;
-
- switch (cmd) {
- case LIRC_GET_FEATURES:
- case LIRC_GET_SEND_MODE:
- case LIRC_GET_REC_MODE:
- retval = put_user(value, (__u32 *) arg);
- break;
-
- case LIRC_SET_SEND_MODE:
- case LIRC_SET_REC_MODE:
- retval = get_user(value, (__u32 *) arg);
- break;
-
- case LIRC_SET_SEND_CARRIER:
- retval = get_user(value, (__u32 *) arg);
- if (retval)
- return retval;
- value /= 1000;
- if (value > IT87_CIR_FREQ_MAX ||
- value < IT87_CIR_FREQ_MIN)
- return -EINVAL;
-
- it87_freq = value;
-
- spin_lock_irqsave(&hardware_lock, hw_flags);
- outb(((inb(io + IT87_CIR_TCR2) & IT87_CIR_TCR2_TXMPW) |
- (it87_freq - IT87_CIR_FREQ_MIN) << 3),
- io + IT87_CIR_TCR2);
- spin_unlock_irqrestore(&hardware_lock, hw_flags);
- dprintk("demodulation frequency: %d kHz\n", it87_freq);
-
- break;
-
- default:
- retval = -EINVAL;
- }
-
- if (retval)
- return retval;
-
- if (cmd == LIRC_SET_REC_MODE) {
- if (value != LIRC_MODE_MODE2)
- retval = -ENOSYS;
- } else if (cmd == LIRC_SET_SEND_MODE) {
- if (value != LIRC_MODE_PULSE)
- retval = -ENOSYS;
- }
- return retval;
-}
-
-static void add_read_queue(int flag, unsigned long val)
-{
- unsigned int new_rx_tail;
- int newval;
-
- dprintk("add flag %d with val %lu\n", flag, val);
-
- newval = val & PULSE_MASK;
-
- /*
- * statistically, pulses are ~TIME_CONST/2 too long. we could
- * maybe make this more exact, but this is good enough
- */
- if (flag) {
- /* pulse */
- if (newval > TIME_CONST / 2)
- newval -= TIME_CONST / 2;
- else /* should not ever happen */
- newval = 1;
- newval |= PULSE_BIT;
- } else
- newval += TIME_CONST / 2;
- new_rx_tail = (rx_tail + 1) & (RBUF_LEN - 1);
- if (new_rx_tail == rx_head) {
- dprintk("Buffer overrun.\n");
- return;
- }
- rx_buf[rx_tail] = newval;
- rx_tail = new_rx_tail;
- wake_up_interruptible(&lirc_read_queue);
-}
-
-
-static const struct file_operations lirc_fops = {
- .owner = THIS_MODULE,
- .read = lirc_read,
- .write = lirc_write,
- .poll = lirc_poll,
- .unlocked_ioctl = lirc_ioctl,
-#ifdef CONFIG_COMPAT
- .compat_ioctl = lirc_ioctl,
-#endif
- .open = lirc_open,
- .release = lirc_close,
- .llseek = noop_llseek,
-};
-
-static int set_use_inc(void *data)
-{
- return 0;
-}
-
-static void set_use_dec(void *data)
-{
-}
-
-static struct lirc_driver driver = {
- .name = LIRC_DRIVER_NAME,
- .minor = -1,
- .code_length = 1,
- .sample_rate = 0,
- .data = NULL,
- .add_to_buf = NULL,
- .set_use_inc = set_use_inc,
- .set_use_dec = set_use_dec,
- .fops = &lirc_fops,
- .dev = NULL,
- .owner = THIS_MODULE,
-};
-
-
-static int init_chrdev(void)
-{
- driver.minor = lirc_register_driver(&driver);
-
- if (driver.minor < 0) {
- printk(KERN_ERR LIRC_DRIVER_NAME ": init_chrdev() failed.\n");
- return -EIO;
- }
- return 0;
-}
-
-
-static void drop_chrdev(void)
-{
- lirc_unregister_driver(driver.minor);
-}
-
-
-/* SECTION: Hardware */
-static long delta(struct timeval *tv1, struct timeval *tv2)
-{
- unsigned long deltv;
-
- deltv = tv2->tv_sec - tv1->tv_sec;
- if (deltv > 15)
- deltv = 0xFFFFFF;
- else
- deltv = deltv*1000000 + tv2->tv_usec - tv1->tv_usec;
- return deltv;
-}
-
-static void it87_timeout(unsigned long data)
-{
- unsigned long flags;
-
- /* avoid interference with interrupt */
- spin_lock_irqsave(&timer_lock, flags);
-
- if (digimatrix) {
- /* We have timed out. Disable the RX mechanism. */
-
- outb((inb(io + IT87_CIR_RCR) & ~IT87_CIR_RCR_RXEN) |
- IT87_CIR_RCR_RXACT, io + IT87_CIR_RCR);
- if (it87_RXEN_mask)
- outb(inb(io + IT87_CIR_RCR) | IT87_CIR_RCR_RXEN,
- io + IT87_CIR_RCR);
- dprintk(" TIMEOUT\n");
- timer_enabled = 0;
-
- /* fifo clear */
- outb(inb(io + IT87_CIR_TCR1) | IT87_CIR_TCR1_FIFOCLR,
- io+IT87_CIR_TCR1);
-
- } else {
- /*
- * if last received signal was a pulse, but receiving stopped
- * within the 9 bit frame, we need to finish this pulse and
- * simulate a signal change to from pulse to space. Otherwise
- * upper layers will receive two sequences next time.
- */
-
- if (last_value) {
- unsigned long pulse_end;
-
- /* determine 'virtual' pulse end: */
- pulse_end = delta(&last_tv, &last_intr_tv);
- dprintk("timeout add %d for %lu usec\n",
- last_value, pulse_end);
- add_read_queue(last_value, pulse_end);
- last_value = 0;
- last_tv = last_intr_tv;
- }
- }
- spin_unlock_irqrestore(&timer_lock, flags);
-}
-
-static irqreturn_t it87_interrupt(int irq, void *dev_id)
-{
- unsigned char data;
- struct timeval curr_tv;
- static unsigned long deltv;
- unsigned long deltintrtv;
- unsigned long flags, hw_flags;
- int iir, lsr;
- int fifo = 0;
- static char lastbit;
- char bit;
-
- /* Bit duration in microseconds */
- const unsigned long bit_duration = 1000000ul /
- (115200 / IT87_CIR_BAUDRATE_DIVISOR);
-
-
- iir = inb(io + IT87_CIR_IIR);
-
- switch (iir & IT87_CIR_IIR_IID) {
- case 0x4:
- case 0x6:
- lsr = inb(io + IT87_CIR_RSR) & (IT87_CIR_RSR_RXFTO |
- IT87_CIR_RSR_RXFBC);
- fifo = lsr & IT87_CIR_RSR_RXFBC;
- dprintk("iir: 0x%x fifo: 0x%x\n", iir, lsr);
-
- /* avoid interference with timer */
- spin_lock_irqsave(&timer_lock, flags);
- spin_lock_irqsave(&hardware_lock, hw_flags);
- if (digimatrix) {
- static unsigned long acc_pulse;
- static unsigned long acc_space;
-
- do {
- data = inb(io + IT87_CIR_DR);
- data = ~data;
- fifo--;
- if (data != 0x00) {
- if (timer_enabled)
- del_timer(&timerlist);
- /*
- * start timer for end of
- * sequence detection
- */
- timerlist.expires = jiffies +
- IT87_TIMEOUT;
- add_timer(&timerlist);
- timer_enabled = 1;
- }
- /* Loop through */
- for (bit = 0; bit < 8; ++bit) {
- if ((data >> bit) & 1) {
- ++acc_pulse;
- if (lastbit == 0) {
- add_read_queue(0,
- acc_space *
- bit_duration);
- acc_space = 0;
- }
- } else {
- ++acc_space;
- if (lastbit == 1) {
- add_read_queue(1,
- acc_pulse *
- bit_duration);
- acc_pulse = 0;
- }
- }
- lastbit = (data >> bit) & 1;
- }
-
- } while (fifo != 0);
- } else { /* Normal Operation */
- do {
- del_timer(&timerlist);
- data = inb(io + IT87_CIR_DR);
-
- dprintk("data=%02x\n", data);
- do_gettimeofday(&curr_tv);
- deltv = delta(&last_tv, &curr_tv);
- deltintrtv = delta(&last_intr_tv, &curr_tv);
-
- dprintk("t %lu , d %d\n",
- deltintrtv, (int)data);
-
- /*
- * if nothing came in last 2 cycles,
- * it was gap
- */
- if (deltintrtv > TIME_CONST * 2) {
- if (last_value) {
- dprintk("GAP\n");
-
- /* simulate signal change */
- add_read_queue(last_value,
- deltv -
- deltintrtv);
- last_value = 0;
- last_tv.tv_sec =
- last_intr_tv.tv_sec;
- last_tv.tv_usec =
- last_intr_tv.tv_usec;
- deltv = deltintrtv;
- }
- }
- data = 1;
- if (data ^ last_value) {
- /*
- * deltintrtv > 2*TIME_CONST,
- * remember ? the other case is
- * timeout
- */
- add_read_queue(last_value,
- deltv-TIME_CONST);
- last_value = data;
- last_tv = curr_tv;
- if (last_tv.tv_usec >= TIME_CONST)
- last_tv.tv_usec -= TIME_CONST;
- else {
- last_tv.tv_sec--;
- last_tv.tv_usec += 1000000 -
- TIME_CONST;
- }
- }
- last_intr_tv = curr_tv;
- if (data) {
- /*
- * start timer for end of
- * sequence detection
- */
- timerlist.expires =
- jiffies + IT87_TIMEOUT;
- add_timer(&timerlist);
- }
- outb((inb(io + IT87_CIR_RCR) &
- ~IT87_CIR_RCR_RXEN) |
- IT87_CIR_RCR_RXACT,
- io + IT87_CIR_RCR);
- if (it87_RXEN_mask)
- outb(inb(io + IT87_CIR_RCR) |
- IT87_CIR_RCR_RXEN,
- io + IT87_CIR_RCR);
- fifo--;
- } while (fifo != 0);
- }
- spin_unlock_irqrestore(&hardware_lock, hw_flags);
- spin_unlock_irqrestore(&timer_lock, flags);
-
- return IRQ_RETVAL(IRQ_HANDLED);
-
- default:
- /* not our irq */
- dprintk("unknown IRQ (shouldn't happen) !!\n");
- return IRQ_RETVAL(IRQ_NONE);
- }
-}
-
-
-static void send_it87(unsigned long len, unsigned long stime,
- unsigned char send_byte, unsigned int count_bits)
-{
- long count = len / stime;
- long time_left = 0;
- static unsigned char byte_out;
- unsigned long hw_flags;
-
- dprintk("%s: len=%ld, sb=%d\n", __func__, len, send_byte);
-
- time_left = (long)len - (long)count * (long)stime;
- count += ((2 * time_left) / stime);
- while (count) {
- long i = 0;
- for (i = 0; i < count_bits; i++) {
- byte_out = (byte_out << 1) | (send_byte & 1);
- it87_bits_in_byte_out++;
- }
- if (it87_bits_in_byte_out == 8) {
- dprintk("out=0x%x, tsr_txfbc: 0x%x\n",
- byte_out,
- inb(io + IT87_CIR_TSR) &
- IT87_CIR_TSR_TXFBC);
-
- while ((inb(io + IT87_CIR_TSR) &
- IT87_CIR_TSR_TXFBC) >= IT87_CIR_FIFO_SIZE)
- ;
-
- spin_lock_irqsave(&hardware_lock, hw_flags);
- outb(byte_out, io + IT87_CIR_DR);
- spin_unlock_irqrestore(&hardware_lock, hw_flags);
-
- it87_bits_in_byte_out = 0;
- it87_send_counter++;
- byte_out = 0;
- }
- count--;
- }
-}
-
-
-/*TODO: maybe exchange space and pulse because it8705 only modulates 0-bits */
-
-static void send_space(unsigned long len)
-{
- send_it87(len, TIME_CONST, IT87_CIR_SPACE, IT87_CIR_BAUDRATE_DIVISOR);
-}
-
-static void send_pulse(unsigned long len)
-{
- send_it87(len, TIME_CONST, IT87_CIR_PULSE, IT87_CIR_BAUDRATE_DIVISOR);
-}
-
-
-static void init_send()
-{
- unsigned long flags;
-
- spin_lock_irqsave(&hardware_lock, flags);
- /* RXEN=0: receiver disable */
- it87_RXEN_mask = 0;
- outb(inb(io + IT87_CIR_RCR) & ~IT87_CIR_RCR_RXEN,
- io + IT87_CIR_RCR);
- spin_unlock_irqrestore(&hardware_lock, flags);
- it87_bits_in_byte_out = 0;
- it87_send_counter = 0;
-}
-
-
-static void terminate_send(unsigned long len)
-{
- unsigned long flags;
- unsigned long last = 0;
-
- last = it87_send_counter;
- /* make sure all necessary data has been sent */
- while (last == it87_send_counter)
- send_space(len);
- /* wait until all data sent */
- while ((inb(io + IT87_CIR_TSR) & IT87_CIR_TSR_TXFBC) != 0)
- ;
- /* then re-enable receiver */
- spin_lock_irqsave(&hardware_lock, flags);
- it87_RXEN_mask = IT87_CIR_RCR_RXEN;
- outb(inb(io + IT87_CIR_RCR) | IT87_CIR_RCR_RXEN,
- io + IT87_CIR_RCR);
- spin_unlock_irqrestore(&hardware_lock, flags);
-}
-
-
-static int init_hardware(void)
-{
- unsigned long flags;
- unsigned char it87_rcr = 0;
-
- spin_lock_irqsave(&hardware_lock, flags);
- /* init cir-port */
- /* enable r/w-access to Baudrate-Register */
- outb(IT87_CIR_IER_BR, io + IT87_CIR_IER);
- outb(IT87_CIR_BAUDRATE_DIVISOR % 0x100, io+IT87_CIR_BDLR);
- outb(IT87_CIR_BAUDRATE_DIVISOR / 0x100, io+IT87_CIR_BDHR);
- /* Baudrate Register off, define IRQs: Input only */
- if (digimatrix) {
- outb(IT87_CIR_IER_IEC | IT87_CIR_IER_RFOIE, io + IT87_CIR_IER);
- /* RX: HCFS=0, RXDCR = 001b (33,75..38,25 kHz), RXEN=1 */
- } else {
- outb(IT87_CIR_IER_IEC | IT87_CIR_IER_RDAIE, io + IT87_CIR_IER);
- /* RX: HCFS=0, RXDCR = 001b (35,6..40,3 kHz), RXEN=1 */
- }
- it87_rcr = (IT87_CIR_RCR_RXEN & it87_RXEN_mask) | 0x1;
- if (it87_enable_demodulator)
- it87_rcr |= IT87_CIR_RCR_RXEND;
- outb(it87_rcr, io + IT87_CIR_RCR);
- if (digimatrix) {
- /* Set FIFO depth to 1 byte, and disable TX */
- outb(inb(io + IT87_CIR_TCR1) | 0x00,
- io + IT87_CIR_TCR1);
-
- /*
- * TX: it87_freq (36kHz), 'reserved' sensitivity
- * setting (0x00)
- */
- outb(((it87_freq - IT87_CIR_FREQ_MIN) << 3) | 0x00,
- io + IT87_CIR_TCR2);
- } else {
- /* TX: 38kHz, 13,3us (pulse-width) */
- outb(((it87_freq - IT87_CIR_FREQ_MIN) << 3) | 0x06,
- io + IT87_CIR_TCR2);
- }
- spin_unlock_irqrestore(&hardware_lock, flags);
- return 0;
-}
-
-
-static void drop_hardware(void)
-{
- unsigned long flags;
-
- spin_lock_irqsave(&hardware_lock, flags);
- disable_irq(irq);
- /* receiver disable */
- it87_RXEN_mask = 0;
- outb(0x1, io + IT87_CIR_RCR);
- /* turn off irqs */
- outb(0, io + IT87_CIR_IER);
- /* fifo clear */
- outb(IT87_CIR_TCR1_FIFOCLR, io+IT87_CIR_TCR1);
- /* reset */
- outb(IT87_CIR_IER_RESET, io+IT87_CIR_IER);
- enable_irq(irq);
- spin_unlock_irqrestore(&hardware_lock, flags);
-}
-
-
-static unsigned char it87_read(unsigned char port)
-{
- outb(port, IT87_ADRPORT);
- return inb(IT87_DATAPORT);
-}
-
-
-static void it87_write(unsigned char port, unsigned char data)
-{
- outb(port, IT87_ADRPORT);
- outb(data, IT87_DATAPORT);
-}
-
-
-/* SECTION: Initialisation */
-
-static int init_port(void)
-{
- unsigned long hw_flags;
- int retval = 0;
-
- unsigned char init_bytes[4] = IT87_INIT;
- unsigned char it87_chipid = 0;
- unsigned char ldn = 0;
- unsigned int it87_io = 0;
- unsigned int it87_irq = 0;
-
- /* Enter MB PnP Mode */
- outb(init_bytes[0], IT87_ADRPORT);
- outb(init_bytes[1], IT87_ADRPORT);
- outb(init_bytes[2], IT87_ADRPORT);
- outb(init_bytes[3], IT87_ADRPORT);
-
- /* 8712 or 8705 ? */
- it87_chipid = it87_read(IT87_CHIP_ID1);
- if (it87_chipid != 0x87) {
- retval = -ENXIO;
- return retval;
- }
- it87_chipid = it87_read(IT87_CHIP_ID2);
- if ((it87_chipid != 0x05) &&
- (it87_chipid != 0x12) &&
- (it87_chipid != 0x18) &&
- (it87_chipid != 0x20)) {
- printk(KERN_INFO LIRC_DRIVER_NAME
- ": no IT8704/05/12/18/20 found (claimed IT87%02x), "
- "exiting..\n", it87_chipid);
- retval = -ENXIO;
- return retval;
- }
- printk(KERN_INFO LIRC_DRIVER_NAME
- ": found IT87%02x.\n",
- it87_chipid);
-
- /* get I/O-Port and IRQ */
- if (it87_chipid == 0x12 || it87_chipid == 0x18)
- ldn = IT8712_CIR_LDN;
- else
- ldn = IT8705_CIR_LDN;
- it87_write(IT87_LDN, ldn);
-
- it87_io = it87_read(IT87_CIR_BASE_MSB) * 256 +
- it87_read(IT87_CIR_BASE_LSB);
- if (it87_io == 0) {
- if (io == 0)
- io = IT87_CIR_DEFAULT_IOBASE;
- printk(KERN_INFO LIRC_DRIVER_NAME
- ": set default io 0x%x\n",
- io);
- it87_write(IT87_CIR_BASE_MSB, io / 0x100);
- it87_write(IT87_CIR_BASE_LSB, io % 0x100);
- } else
- io = it87_io;
-
- it87_irq = it87_read(IT87_CIR_IRQ);
- if (digimatrix || it87_irq == 0) {
- if (irq == 0)
- irq = IT87_CIR_DEFAULT_IRQ;
- printk(KERN_INFO LIRC_DRIVER_NAME
- ": set default irq 0x%x\n",
- irq);
- it87_write(IT87_CIR_IRQ, irq);
- } else
- irq = it87_irq;
-
- spin_lock_irqsave(&hardware_lock, hw_flags);
- /* reset */
- outb(IT87_CIR_IER_RESET, io+IT87_CIR_IER);
- /* fifo clear */
- outb(IT87_CIR_TCR1_FIFOCLR |
- /* IT87_CIR_TCR1_ILE | */
- IT87_CIR_TCR1_TXRLE |
- IT87_CIR_TCR1_TXENDF, io+IT87_CIR_TCR1);
- spin_unlock_irqrestore(&hardware_lock, hw_flags);
-
- /* get I/O port access and IRQ line */
- if (request_region(io, 8, LIRC_DRIVER_NAME) == NULL) {
- printk(KERN_ERR LIRC_DRIVER_NAME
- ": i/o port 0x%.4x already in use.\n", io);
- /* Leaving MB PnP Mode */
- it87_write(IT87_CFGCTRL, 0x2);
- return -EBUSY;
- }
-
- /* activate CIR-Device */
- it87_write(IT87_CIR_ACT, 0x1);
-
- /* Leaving MB PnP Mode */
- it87_write(IT87_CFGCTRL, 0x2);
-
- retval = request_irq(irq, it87_interrupt, 0 /*IRQF_DISABLED*/,
- LIRC_DRIVER_NAME, NULL);
- if (retval < 0) {
- printk(KERN_ERR LIRC_DRIVER_NAME
- ": IRQ %d already in use.\n",
- irq);
- release_region(io, 8);
- return retval;
- }
-
- printk(KERN_INFO LIRC_DRIVER_NAME
- ": I/O port 0x%.4x, IRQ %d.\n", io, irq);
-
- init_timer(&timerlist);
- timerlist.function = it87_timeout;
- timerlist.data = 0xabadcafe;
-
- return 0;
-}
-
-
-static void drop_port(void)
-{
-#if 0
- unsigned char init_bytes[4] = IT87_INIT;
-
- /* Enter MB PnP Mode */
- outb(init_bytes[0], IT87_ADRPORT);
- outb(init_bytes[1], IT87_ADRPORT);
- outb(init_bytes[2], IT87_ADRPORT);
- outb(init_bytes[3], IT87_ADRPORT);
-
- /* deactivate CIR-Device */
- it87_write(IT87_CIR_ACT, 0x0);
-
- /* Leaving MB PnP Mode */
- it87_write(IT87_CFGCTRL, 0x2);
-#endif
-
- del_timer_sync(&timerlist);
- free_irq(irq, NULL);
- release_region(io, 8);
-}
-
-
-static int init_lirc_it87(void)
-{
- int retval;
-
- init_waitqueue_head(&lirc_read_queue);
- retval = init_port();
- if (retval < 0)
- return retval;
- init_hardware();
- printk(KERN_INFO LIRC_DRIVER_NAME ": Installed.\n");
- return 0;
-}
-
-static int it87_probe(struct pnp_dev *pnp_dev,
- const struct pnp_device_id *dev_id)
-{
- int retval;
-
- driver.dev = &pnp_dev->dev;
-
- retval = init_chrdev();
- if (retval < 0)
- return retval;
-
- retval = init_lirc_it87();
- if (retval)
- goto init_lirc_it87_failed;
-
- return 0;
-
-init_lirc_it87_failed:
- drop_chrdev();
-
- return retval;
-}
-
-static int __init lirc_it87_init(void)
-{
- return pnp_register_driver(&it87_pnp_driver);
-}
-
-
-static void __exit lirc_it87_exit(void)
-{
- drop_hardware();
- drop_chrdev();
- drop_port();
- pnp_unregister_driver(&it87_pnp_driver);
- printk(KERN_INFO LIRC_DRIVER_NAME ": Uninstalled.\n");
-}
-
-/* SECTION: PNP for ITE8704/13/18 */
-
-static const struct pnp_device_id pnp_dev_table[] = {
- {"ITE8704", 0},
- {"ITE8713", 0},
- {}
-};
-
-MODULE_DEVICE_TABLE(pnp, pnp_dev_table);
-
-static struct pnp_driver it87_pnp_driver = {
- .name = LIRC_DRIVER_NAME,
- .id_table = pnp_dev_table,
- .probe = it87_probe,
-};
-
-module_init(lirc_it87_init);
-module_exit(lirc_it87_exit);
-
-MODULE_DESCRIPTION("LIRC driver for ITE IT8704/05/12/18/20 CIR port");
-MODULE_AUTHOR("Hans-Gunter Lutke Uphues");
-MODULE_LICENSE("GPL");
-
-module_param(io, int, S_IRUGO);
-MODULE_PARM_DESC(io, "I/O base address (default: 0x310)");
-
-module_param(irq, int, S_IRUGO);
-#ifdef LIRC_IT87_DIGIMATRIX
-MODULE_PARM_DESC(irq, "Interrupt (1,3-12) (default: 9)");
-#else
-MODULE_PARM_DESC(irq, "Interrupt (1,3-12) (default: 7)");
-#endif
-
-module_param(it87_enable_demodulator, bool, S_IRUGO);
-MODULE_PARM_DESC(it87_enable_demodulator,
- "Receiver demodulator enable/disable (1/0), default: 0");
-
-module_param(debug, bool, S_IRUGO | S_IWUSR);
-MODULE_PARM_DESC(debug, "Enable debugging messages");
-
-module_param(digimatrix, bool, S_IRUGO | S_IWUSR);
-#ifdef LIRC_IT87_DIGIMATRIX
-MODULE_PARM_DESC(digimatrix,
- "Asus Digimatrix it87 compat. enable/disable (1/0), default: 1");
-#else
-MODULE_PARM_DESC(digimatrix,
- "Asus Digimatrix it87 compat. enable/disable (1/0), default: 0");
-#endif
-
-
-module_param(it87_freq, int, S_IRUGO);
-#ifdef LIRC_IT87_DIGIMATRIX
-MODULE_PARM_DESC(it87_freq,
- "Carrier demodulator frequency (kHz), (default: 36)");
-#else
-MODULE_PARM_DESC(it87_freq,
- "Carrier demodulator frequency (kHz), (default: 38)");
-#endif
diff --git a/drivers/staging/lirc/lirc_it87.h b/drivers/staging/lirc/lirc_it87.h
deleted file mode 100644
index cf021c893a35..000000000000
--- a/drivers/staging/lirc/lirc_it87.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/* lirc_it87.h */
-/* SECTION: Definitions */
-
-/********************************* ITE IT87xx ************************/
-
-/* based on the following documentation from ITE:
- a) IT8712F Preliminary CIR Programming Guide V0.1
- b) IT8705F Simple LPC I/O Preliminary Specification V0.3
- c) IT8712F EC-LPC I/O Preliminary Specification V0.5
-*/
-
-/* IT8712/05 Ports: */
-#define IT87_ADRPORT 0x2e
-#define IT87_DATAPORT 0x2f
-#define IT87_INIT {0x87, 0x01, 0x55, 0x55}
-
-/* alternate Ports: */
-/*
-#define IT87_ADRPORT 0x4e
-#define IT87_DATAPORT 0x4f
-#define IT87_INIT {0x87, 0x01, 0x55, 0xaa}
- */
-
-/* IT8712/05 Registers */
-#define IT87_CFGCTRL 0x2
-#define IT87_LDN 0x7
-#define IT87_CHIP_ID1 0x20
-#define IT87_CHIP_ID2 0x21
-#define IT87_CFG_VERSION 0x22
-#define IT87_SWSUSPEND 0x23
-
-#define IT8712_CIR_LDN 0xa
-#define IT8705_CIR_LDN 0x7
-
-/* CIR Configuration Registers: */
-#define IT87_CIR_ACT 0x30
-#define IT87_CIR_BASE_MSB 0x60
-#define IT87_CIR_BASE_LSB 0x61
-#define IT87_CIR_IRQ 0x70
-#define IT87_CIR_CONFIG 0xf0
-
-/* List of IT87_CIR registers: offset to BaseAddr */
-#define IT87_CIR_DR 0
-#define IT87_CIR_IER 1
-#define IT87_CIR_RCR 2
-#define IT87_CIR_TCR1 3
-#define IT87_CIR_TCR2 4
-#define IT87_CIR_TSR 5
-#define IT87_CIR_RSR 6
-#define IT87_CIR_BDLR 5
-#define IT87_CIR_BDHR 6
-#define IT87_CIR_IIR 7
-
-/* Bit Definition */
-/* IER: */
-#define IT87_CIR_IER_TM_EN 0x80
-#define IT87_CIR_IER_RESEVED 0x40
-#define IT87_CIR_IER_RESET 0x20
-#define IT87_CIR_IER_BR 0x10
-#define IT87_CIR_IER_IEC 0x8
-#define IT87_CIR_IER_RFOIE 0x4
-#define IT87_CIR_IER_RDAIE 0x2
-#define IT87_CIR_IER_TLDLIE 0x1
-
-/* RCR: */
-#define IT87_CIR_RCR_RDWOS 0x80
-#define IT87_CIR_RCR_HCFS 0x40
-#define IT87_CIR_RCR_RXEN 0x20
-#define IT87_CIR_RCR_RXEND 0x10
-#define IT87_CIR_RCR_RXACT 0x8
-#define IT87_CIR_RCR_RXDCR 0x7
-
-/* TCR1: */
-#define IT87_CIR_TCR1_FIFOCLR 0x80
-#define IT87_CIR_TCR1_ILE 0x40
-#define IT87_CIR_TCR1_FIFOTL 0x30
-#define IT87_CIR_TCR1_TXRLE 0x8
-#define IT87_CIR_TCR1_TXENDF 0x4
-#define IT87_CIR_TCR1_TXMPM 0x3
-
-/* TCR2: */
-#define IT87_CIR_TCR2_CFQ 0xf8
-#define IT87_CIR_TCR2_TXMPW 0x7
-
-/* TSR: */
-#define IT87_CIR_TSR_RESERVED 0xc0
-#define IT87_CIR_TSR_TXFBC 0x3f
-
-/* RSR: */
-#define IT87_CIR_RSR_RXFTO 0x80
-#define IT87_CIR_RSR_RESERVED 0x40
-#define IT87_CIR_RSR_RXFBC 0x3f
-
-/* IIR: */
-#define IT87_CIR_IIR_RESERVED 0xf8
-#define IT87_CIR_IIR_IID 0x6
-#define IT87_CIR_IIR_IIP 0x1
-
-/* TM: */
-#define IT87_CIR_TM_IL_SEL 0x80
-#define IT87_CIR_TM_RESERVED 0x40
-#define IT87_CIR_TM_TM_REG 0x3f
-
-#define IT87_CIR_FIFO_SIZE 32
-
-/* Baudratedivisor for IT87: power of 2: only 1,2,4 or 8) */
-#define IT87_CIR_BAUDRATE_DIVISOR 0x1
-#define IT87_CIR_DEFAULT_IOBASE 0x310
-#define IT87_CIR_DEFAULT_IRQ 0x7
-#define IT87_CIR_SPACE 0x00
-#define IT87_CIR_PULSE 0xff
-#define IT87_CIR_FREQ_MIN 27
-#define IT87_CIR_FREQ_MAX 58
-#define TIME_CONST (IT87_CIR_BAUDRATE_DIVISOR * 8000000ul / 115200ul)
-
-/********************************* ITE IT87xx ************************/
diff --git a/drivers/staging/lirc/lirc_ite8709.c b/drivers/staging/lirc/lirc_ite8709.c
deleted file mode 100644
index cb20cfdcfadd..000000000000
--- a/drivers/staging/lirc/lirc_ite8709.c
+++ /dev/null
@@ -1,542 +0,0 @@
-/*
- * LIRC driver for ITE8709 CIR port
- *
- * Copyright (C) 2008 Grégory Lardière <spmf2004-lirc@yahoo.fr>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-#include <linux/module.h>
-#include <linux/interrupt.h>
-#include <linux/sched.h>
-#include <linux/delay.h>
-#include <linux/pnp.h>
-#include <linux/io.h>
-
-#include <media/lirc.h>
-#include <media/lirc_dev.h>
-
-#define LIRC_DRIVER_NAME "lirc_ite8709"
-
-#define BUF_CHUNK_SIZE sizeof(int)
-#define BUF_SIZE (128*BUF_CHUNK_SIZE)
-
-/*
- * The ITE8709 device seems to be the combination of IT8512 superIO chip and
- * a specific firmware running on the IT8512's embedded micro-controller.
- * In addition of the embedded micro-controller, the IT8512 chip contains a
- * CIR module and several other modules. A few modules are directly accessible
- * by the host CPU, but most of them are only accessible by the
- * micro-controller. The CIR module is only accessible by the micro-controller.
- * The battery-backed SRAM module is accessible by the host CPU and the
- * micro-controller. So one of the MC's firmware role is to act as a bridge
- * between the host CPU and the CIR module. The firmware implements a kind of
- * communication protocol using the SRAM module as a shared memory. The IT8512
- * specification is publicly available on ITE's web site, but the communication
- * protocol is not, so it was reverse-engineered.
- */
-
-/* ITE8709 Registers addresses and values (reverse-engineered) */
-#define ITE8709_MODE 0x1a
-#define ITE8709_REG_ADR 0x1b
-#define ITE8709_REG_VAL 0x1c
-#define ITE8709_IIR 0x1e /* Interrupt identification register */
-#define ITE8709_RFSR 0x1f /* Receiver FIFO status register */
-#define ITE8709_FIFO_START 0x20
-
-#define ITE8709_MODE_READY 0X00
-#define ITE8709_MODE_WRITE 0X01
-#define ITE8709_MODE_READ 0X02
-#define ITE8709_IIR_RDAI 0x02 /* Receiver data available interrupt */
-#define ITE8709_IIR_RFOI 0x04 /* Receiver FIFO overrun interrupt */
-#define ITE8709_RFSR_MASK 0x3f /* FIFO byte count mask */
-
-/*
- * IT8512 CIR-module registers addresses and values
- * (from IT8512 E/F specification v0.4.1)
- */
-#define IT8512_REG_MSTCR 0x01 /* Master control register */
-#define IT8512_REG_IER 0x02 /* Interrupt enable register */
-#define IT8512_REG_CFR 0x04 /* Carrier frequency register */
-#define IT8512_REG_RCR 0x05 /* Receive control register */
-#define IT8512_REG_BDLR 0x08 /* Baud rate divisor low byte register */
-#define IT8512_REG_BDHR 0x09 /* Baud rate divisor high byte register */
-
-#define IT8512_MSTCR_RESET 0x01 /* Reset registers to default value */
-#define IT8512_MSTCR_FIFOCLR 0x02 /* Clear FIFO */
-#define IT8512_MSTCR_FIFOTL_7 0x04 /* FIFO threshold level : 7 */
-#define IT8512_MSTCR_FIFOTL_25 0x0c /* FIFO threshold level : 25 */
-#define IT8512_IER_RDAIE 0x02 /* Enable data interrupt request */
-#define IT8512_IER_RFOIE 0x04 /* Enable FIFO overrun interrupt req */
-#define IT8512_IER_IEC 0x80 /* Enable interrupt request */
-#define IT8512_CFR_CF_36KHZ 0x09 /* Carrier freq : low speed, 36kHz */
-#define IT8512_RCR_RXDCR_1 0x01 /* Demodulation carrier range : 1 */
-#define IT8512_RCR_RXACT 0x08 /* Receiver active */
-#define IT8512_RCR_RXEN 0x80 /* Receiver enable */
-#define IT8512_BDR_6 6 /* Baud rate divisor : 6 */
-
-/* Actual values used by this driver */
-#define CFG_FIFOTL IT8512_MSTCR_FIFOTL_25
-#define CFG_CR_FREQ IT8512_CFR_CF_36KHZ
-#define CFG_DCR IT8512_RCR_RXDCR_1
-#define CFG_BDR IT8512_BDR_6
-#define CFG_TIMEOUT 100000 /* Rearm interrupt when a space is > 100 ms */
-
-static int debug;
-
-struct ite8709_device {
- int use_count;
- int io;
- int irq;
- spinlock_t hardware_lock;
- __u64 acc_pulse;
- __u64 acc_space;
- char lastbit;
- struct timeval last_tv;
- struct lirc_driver driver;
- struct tasklet_struct tasklet;
- char force_rearm;
- char rearmed;
- char device_busy;
-};
-
-#define dprintk(fmt, args...) \
- do { \
- if (debug) \
- printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
- fmt, ## args); \
- } while (0)
-
-
-static unsigned char ite8709_read(struct ite8709_device *dev,
- unsigned char port)
-{
- outb(port, dev->io);
- return inb(dev->io+1);
-}
-
-static void ite8709_write(struct ite8709_device *dev, unsigned char port,
- unsigned char data)
-{
- outb(port, dev->io);
- outb(data, dev->io+1);
-}
-
-static void ite8709_wait_device(struct ite8709_device *dev)
-{
- int i = 0;
- /*
- * loop until device tells it's ready to continue
- * iterations count is usually ~750 but can sometimes achieve 13000
- */
- for (i = 0; i < 15000; i++) {
- udelay(2);
- if (ite8709_read(dev, ITE8709_MODE) == ITE8709_MODE_READY)
- break;
- }
-}
-
-static void ite8709_write_register(struct ite8709_device *dev,
- unsigned char reg_adr, unsigned char reg_value)
-{
- ite8709_wait_device(dev);
-
- ite8709_write(dev, ITE8709_REG_VAL, reg_value);
- ite8709_write(dev, ITE8709_REG_ADR, reg_adr);
- ite8709_write(dev, ITE8709_MODE, ITE8709_MODE_WRITE);
-}
-
-static void ite8709_init_hardware(struct ite8709_device *dev)
-{
- spin_lock_irq(&dev->hardware_lock);
- dev->device_busy = 1;
- spin_unlock_irq(&dev->hardware_lock);
-
- ite8709_write_register(dev, IT8512_REG_BDHR, (CFG_BDR >> 8) & 0xff);
- ite8709_write_register(dev, IT8512_REG_BDLR, CFG_BDR & 0xff);
- ite8709_write_register(dev, IT8512_REG_CFR, CFG_CR_FREQ);
- ite8709_write_register(dev, IT8512_REG_IER,
- IT8512_IER_IEC | IT8512_IER_RFOIE | IT8512_IER_RDAIE);
- ite8709_write_register(dev, IT8512_REG_RCR, CFG_DCR);
- ite8709_write_register(dev, IT8512_REG_MSTCR,
- CFG_FIFOTL | IT8512_MSTCR_FIFOCLR);
- ite8709_write_register(dev, IT8512_REG_RCR,
- IT8512_RCR_RXEN | IT8512_RCR_RXACT | CFG_DCR);
-
- spin_lock_irq(&dev->hardware_lock);
- dev->device_busy = 0;
- spin_unlock_irq(&dev->hardware_lock);
-
- tasklet_enable(&dev->tasklet);
-}
-
-static void ite8709_drop_hardware(struct ite8709_device *dev)
-{
- tasklet_disable(&dev->tasklet);
-
- spin_lock_irq(&dev->hardware_lock);
- dev->device_busy = 1;
- spin_unlock_irq(&dev->hardware_lock);
-
- ite8709_write_register(dev, IT8512_REG_RCR, 0);
- ite8709_write_register(dev, IT8512_REG_MSTCR,
- IT8512_MSTCR_RESET | IT8512_MSTCR_FIFOCLR);
-
- spin_lock_irq(&dev->hardware_lock);
- dev->device_busy = 0;
- spin_unlock_irq(&dev->hardware_lock);
-}
-
-static int ite8709_set_use_inc(void *data)
-{
- struct ite8709_device *dev;
- dev = data;
- if (dev->use_count == 0)
- ite8709_init_hardware(dev);
- dev->use_count++;
- return 0;
-}
-
-static void ite8709_set_use_dec(void *data)
-{
- struct ite8709_device *dev;
- dev = data;
- dev->use_count--;
- if (dev->use_count == 0)
- ite8709_drop_hardware(dev);
-}
-
-static void ite8709_add_read_queue(struct ite8709_device *dev, int flag,
- __u64 val)
-{
- int value;
-
- dprintk("add a %llu usec %s\n", val, flag ? "pulse" : "space");
-
- value = (val > PULSE_MASK) ? PULSE_MASK : val;
- if (flag)
- value |= PULSE_BIT;
-
- if (!lirc_buffer_full(dev->driver.rbuf)) {
- lirc_buffer_write(dev->driver.rbuf, (void *) &value);
- wake_up(&dev->driver.rbuf->wait_poll);
- }
-}
-
-static irqreturn_t ite8709_interrupt(int irq, void *dev_id)
-{
- unsigned char data;
- int iir, rfsr, i;
- int fifo = 0;
- char bit;
- struct timeval curr_tv;
-
- /* Bit duration in microseconds */
- const unsigned long bit_duration = 1000000ul / (115200 / CFG_BDR);
-
- struct ite8709_device *dev;
- dev = dev_id;
-
- /*
- * If device is busy, we simply discard data because we are in one of
- * these two cases : shutting down or rearming the device, so this
- * doesn't really matter and this avoids waiting too long in IRQ ctx
- */
- spin_lock(&dev->hardware_lock);
- if (dev->device_busy) {
- spin_unlock(&dev->hardware_lock);
- return IRQ_RETVAL(IRQ_HANDLED);
- }
-
- iir = ite8709_read(dev, ITE8709_IIR);
-
- switch (iir) {
- case ITE8709_IIR_RFOI:
- dprintk("fifo overrun, scheduling forced rearm just in case\n");
- dev->force_rearm = 1;
- tasklet_schedule(&dev->tasklet);
- spin_unlock(&dev->hardware_lock);
- return IRQ_RETVAL(IRQ_HANDLED);
-
- case ITE8709_IIR_RDAI:
- rfsr = ite8709_read(dev, ITE8709_RFSR);
- fifo = rfsr & ITE8709_RFSR_MASK;
- if (fifo > 32)
- fifo = 32;
- dprintk("iir: 0x%x rfsr: 0x%x fifo: %d\n", iir, rfsr, fifo);
-
- if (dev->rearmed) {
- do_gettimeofday(&curr_tv);
- dev->acc_space += 1000000ull
- * (curr_tv.tv_sec - dev->last_tv.tv_sec)
- + (curr_tv.tv_usec - dev->last_tv.tv_usec);
- dev->rearmed = 0;
- }
- for (i = 0; i < fifo; i++) {
- data = ite8709_read(dev, i+ITE8709_FIFO_START);
- data = ~data;
- /* Loop through */
- for (bit = 0; bit < 8; ++bit) {
- if ((data >> bit) & 1) {
- dev->acc_pulse += bit_duration;
- if (dev->lastbit == 0) {
- ite8709_add_read_queue(dev, 0,
- dev->acc_space);
- dev->acc_space = 0;
- }
- } else {
- dev->acc_space += bit_duration;
- if (dev->lastbit == 1) {
- ite8709_add_read_queue(dev, 1,
- dev->acc_pulse);
- dev->acc_pulse = 0;
- }
- }
- dev->lastbit = (data >> bit) & 1;
- }
- }
- ite8709_write(dev, ITE8709_RFSR, 0);
-
- if (dev->acc_space > CFG_TIMEOUT) {
- dprintk("scheduling rearm IRQ\n");
- do_gettimeofday(&dev->last_tv);
- dev->force_rearm = 0;
- tasklet_schedule(&dev->tasklet);
- }
-
- spin_unlock(&dev->hardware_lock);
- return IRQ_RETVAL(IRQ_HANDLED);
-
- default:
- /* not our irq */
- dprintk("unknown IRQ (shouldn't happen) !!\n");
- spin_unlock(&dev->hardware_lock);
- return IRQ_RETVAL(IRQ_NONE);
- }
-}
-
-static void ite8709_rearm_irq(unsigned long data)
-{
- struct ite8709_device *dev;
- unsigned long flags;
- dev = (struct ite8709_device *) data;
-
- spin_lock_irqsave(&dev->hardware_lock, flags);
- dev->device_busy = 1;
- spin_unlock_irqrestore(&dev->hardware_lock, flags);
-
- if (dev->force_rearm || dev->acc_space > CFG_TIMEOUT) {
- dprintk("rearming IRQ\n");
- ite8709_write_register(dev, IT8512_REG_RCR,
- IT8512_RCR_RXACT | CFG_DCR);
- ite8709_write_register(dev, IT8512_REG_MSTCR,
- CFG_FIFOTL | IT8512_MSTCR_FIFOCLR);
- ite8709_write_register(dev, IT8512_REG_RCR,
- IT8512_RCR_RXEN | IT8512_RCR_RXACT | CFG_DCR);
- if (!dev->force_rearm)
- dev->rearmed = 1;
- dev->force_rearm = 0;
- }
-
- spin_lock_irqsave(&dev->hardware_lock, flags);
- dev->device_busy = 0;
- spin_unlock_irqrestore(&dev->hardware_lock, flags);
-}
-
-static int ite8709_cleanup(struct ite8709_device *dev, int stage, int errno,
- char *msg)
-{
- if (msg != NULL)
- printk(KERN_ERR LIRC_DRIVER_NAME ": %s\n", msg);
-
- switch (stage) {
- case 6:
- if (dev->use_count > 0)
- ite8709_drop_hardware(dev);
- case 5:
- free_irq(dev->irq, dev);
- case 4:
- release_region(dev->io, 2);
- case 3:
- lirc_unregister_driver(dev->driver.minor);
- case 2:
- lirc_buffer_free(dev->driver.rbuf);
- kfree(dev->driver.rbuf);
- case 1:
- kfree(dev);
- case 0:
- ;
- }
-
- return errno;
-}
-
-static int __devinit ite8709_pnp_probe(struct pnp_dev *dev,
- const struct pnp_device_id *dev_id)
-{
- struct lirc_driver *driver;
- struct ite8709_device *ite8709_dev;
- int ret;
-
- /* Check resources validity */
- if (!pnp_irq_valid(dev, 0))
- return ite8709_cleanup(NULL, 0, -ENODEV, "invalid IRQ");
- if (!pnp_port_valid(dev, 2))
- return ite8709_cleanup(NULL, 0, -ENODEV, "invalid IO port");
-
- /* Allocate memory for device struct */
- ite8709_dev = kzalloc(sizeof(struct ite8709_device), GFP_KERNEL);
- if (ite8709_dev == NULL)
- return ite8709_cleanup(NULL, 0, -ENOMEM, "kzalloc failed");
- pnp_set_drvdata(dev, ite8709_dev);
-
- /* Initialize device struct */
- ite8709_dev->use_count = 0;
- ite8709_dev->irq = pnp_irq(dev, 0);
- ite8709_dev->io = pnp_port_start(dev, 2);
- ite8709_dev->hardware_lock =
- __SPIN_LOCK_UNLOCKED(ite8709_dev->hardware_lock);
- ite8709_dev->acc_pulse = 0;
- ite8709_dev->acc_space = 0;
- ite8709_dev->lastbit = 0;
- do_gettimeofday(&ite8709_dev->last_tv);
- tasklet_init(&ite8709_dev->tasklet, ite8709_rearm_irq,
- (long) ite8709_dev);
- ite8709_dev->force_rearm = 0;
- ite8709_dev->rearmed = 0;
- ite8709_dev->device_busy = 0;
-
- /* Initialize driver struct */
- driver = &ite8709_dev->driver;
- strcpy(driver->name, LIRC_DRIVER_NAME);
- driver->minor = -1;
- driver->code_length = sizeof(int) * 8;
- driver->sample_rate = 0;
- driver->features = LIRC_CAN_REC_MODE2;
- driver->data = ite8709_dev;
- driver->add_to_buf = NULL;
- driver->set_use_inc = ite8709_set_use_inc;
- driver->set_use_dec = ite8709_set_use_dec;
- driver->dev = &dev->dev;
- driver->owner = THIS_MODULE;
-
- /* Initialize LIRC buffer */
- driver->rbuf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
- if (!driver->rbuf)
- return ite8709_cleanup(ite8709_dev, 1, -ENOMEM,
- "can't allocate lirc_buffer");
- if (lirc_buffer_init(driver->rbuf, BUF_CHUNK_SIZE, BUF_SIZE))
- return ite8709_cleanup(ite8709_dev, 1, -ENOMEM,
- "lirc_buffer_init() failed");
-
- /* Register LIRC driver */
- ret = lirc_register_driver(driver);
- if (ret < 0)
- return ite8709_cleanup(ite8709_dev, 2, ret,
- "lirc_register_driver() failed");
-
- /* Reserve I/O port access */
- if (!request_region(ite8709_dev->io, 2, LIRC_DRIVER_NAME))
- return ite8709_cleanup(ite8709_dev, 3, -EBUSY,
- "i/o port already in use");
-
- /* Reserve IRQ line */
- ret = request_irq(ite8709_dev->irq, ite8709_interrupt, 0,
- LIRC_DRIVER_NAME, ite8709_dev);
- if (ret < 0)
- return ite8709_cleanup(ite8709_dev, 4, ret,
- "IRQ already in use");
-
- /* Initialize hardware */
- ite8709_drop_hardware(ite8709_dev); /* Shutdown hw until first use */
-
- printk(KERN_INFO LIRC_DRIVER_NAME ": device found : irq=%d io=0x%x\n",
- ite8709_dev->irq, ite8709_dev->io);
-
- return 0;
-}
-
-static void __devexit ite8709_pnp_remove(struct pnp_dev *dev)
-{
- struct ite8709_device *ite8709_dev;
- ite8709_dev = pnp_get_drvdata(dev);
-
- ite8709_cleanup(ite8709_dev, 6, 0, NULL);
-
- printk(KERN_INFO LIRC_DRIVER_NAME ": device removed\n");
-}
-
-#ifdef CONFIG_PM
-static int ite8709_pnp_suspend(struct pnp_dev *dev, pm_message_t state)
-{
- struct ite8709_device *ite8709_dev;
- ite8709_dev = pnp_get_drvdata(dev);
-
- if (ite8709_dev->use_count > 0)
- ite8709_drop_hardware(ite8709_dev);
-
- return 0;
-}
-
-static int ite8709_pnp_resume(struct pnp_dev *dev)
-{
- struct ite8709_device *ite8709_dev;
- ite8709_dev = pnp_get_drvdata(dev);
-
- if (ite8709_dev->use_count > 0)
- ite8709_init_hardware(ite8709_dev);
-
- return 0;
-}
-#else
-#define ite8709_pnp_suspend NULL
-#define ite8709_pnp_resume NULL
-#endif
-
-static const struct pnp_device_id pnp_dev_table[] = {
- {"ITE8709", 0},
- {}
-};
-
-MODULE_DEVICE_TABLE(pnp, pnp_dev_table);
-
-static struct pnp_driver ite8709_pnp_driver = {
- .name = LIRC_DRIVER_NAME,
- .probe = ite8709_pnp_probe,
- .remove = __devexit_p(ite8709_pnp_remove),
- .suspend = ite8709_pnp_suspend,
- .resume = ite8709_pnp_resume,
- .id_table = pnp_dev_table,
-};
-
-static int __init ite8709_init_module(void)
-{
- return pnp_register_driver(&ite8709_pnp_driver);
-}
-module_init(ite8709_init_module);
-
-static void __exit ite8709_cleanup_module(void)
-{
- pnp_unregister_driver(&ite8709_pnp_driver);
-}
-module_exit(ite8709_cleanup_module);
-
-MODULE_DESCRIPTION("LIRC driver for ITE8709 CIR port");
-MODULE_AUTHOR("Grégory Lardière");
-MODULE_LICENSE("GPL");
-
-module_param(debug, bool, S_IRUGO | S_IWUSR);
-MODULE_PARM_DESC(debug, "Enable debugging messages");
diff --git a/drivers/staging/lirc/lirc_sasem.c b/drivers/staging/lirc/lirc_sasem.c
index 925eabe14854..63a438d1c849 100644
--- a/drivers/staging/lirc/lirc_sasem.c
+++ b/drivers/staging/lirc/lirc_sasem.c
@@ -364,7 +364,7 @@ static ssize_t vfd_write(struct file *file, const char *buf,
int i;
int retval = 0;
struct sasem_context *context;
- int *data_buf;
+ int *data_buf = NULL;
context = (struct sasem_context *) file->private_data;
if (!context) {
diff --git a/drivers/staging/lirc/lirc_zilog.c b/drivers/staging/lirc/lirc_zilog.c
index 0aad0d7a74a3..dd6a57c3c3a3 100644
--- a/drivers/staging/lirc/lirc_zilog.c
+++ b/drivers/staging/lirc/lirc_zilog.c
@@ -63,14 +63,16 @@
#include <media/lirc_dev.h>
#include <media/lirc.h>
+struct IR;
+
struct IR_rx {
+ struct kref ref;
+ struct IR *ir;
+
/* RX device */
+ struct mutex client_lock;
struct i2c_client *c;
- /* RX device buffer & lock */
- struct lirc_buffer buf;
- struct mutex buf_lock;
-
/* RX polling thread data */
struct task_struct *task;
@@ -80,7 +82,11 @@ struct IR_rx {
};
struct IR_tx {
+ struct kref ref;
+ struct IR *ir;
+
/* TX device */
+ struct mutex client_lock;
struct i2c_client *c;
/* TX additional actions needed */
@@ -89,19 +95,34 @@ struct IR_tx {
};
struct IR {
+ struct kref ref;
+ struct list_head list;
+
+ /* FIXME spinlock access to l.features */
struct lirc_driver l;
+ struct lirc_buffer rbuf;
struct mutex ir_lock;
- int open;
+ atomic_t open_count;
struct i2c_adapter *adapter;
+
+ spinlock_t rx_ref_lock; /* struct IR_rx kref get()/put() */
struct IR_rx *rx;
+
+ spinlock_t tx_ref_lock; /* struct IR_tx kref get()/put() */
struct IR_tx *tx;
};
-/* Minor -> data mapping */
-static struct mutex ir_devices_lock;
-static struct IR *ir_devices[MAX_IRCTL_DEVICES];
+/* IR transceiver instance object list */
+/*
+ * This lock is used for the following:
+ * a. ir_devices_list access, insertions, deletions
+ * b. struct IR kref get()s and put()s
+ * c. serialization of ir_probe() for the two i2c_clients for a Z8
+ */
+static DEFINE_MUTEX(ir_devices_lock);
+static LIST_HEAD(ir_devices_list);
/* Block size for IR transmitter */
#define TX_BLOCK_SIZE 99
@@ -147,6 +168,157 @@ static int minor = -1; /* minor number */
## args); \
} while (0)
+
+/* struct IR reference counting */
+static struct IR *get_ir_device(struct IR *ir, bool ir_devices_lock_held)
+{
+ if (ir_devices_lock_held) {
+ kref_get(&ir->ref);
+ } else {
+ mutex_lock(&ir_devices_lock);
+ kref_get(&ir->ref);
+ mutex_unlock(&ir_devices_lock);
+ }
+ return ir;
+}
+
+static void release_ir_device(struct kref *ref)
+{
+ struct IR *ir = container_of(ref, struct IR, ref);
+
+ /*
+ * Things should be in this state by now:
+ * ir->rx set to NULL and deallocated - happens before ir->rx->ir put()
+ * ir->rx->task kthread stopped - happens before ir->rx->ir put()
+ * ir->tx set to NULL and deallocated - happens before ir->tx->ir put()
+ * ir->open_count == 0 - happens on final close()
+ * ir_lock, tx_ref_lock, rx_ref_lock, all released
+ */
+ if (ir->l.minor >= 0 && ir->l.minor < MAX_IRCTL_DEVICES) {
+ lirc_unregister_driver(ir->l.minor);
+ ir->l.minor = MAX_IRCTL_DEVICES;
+ }
+ if (ir->rbuf.fifo_initialized)
+ lirc_buffer_free(&ir->rbuf);
+ list_del(&ir->list);
+ kfree(ir);
+}
+
+static int put_ir_device(struct IR *ir, bool ir_devices_lock_held)
+{
+ int released;
+
+ if (ir_devices_lock_held)
+ return kref_put(&ir->ref, release_ir_device);
+
+ mutex_lock(&ir_devices_lock);
+ released = kref_put(&ir->ref, release_ir_device);
+ mutex_unlock(&ir_devices_lock);
+
+ return released;
+}
+
+/* struct IR_rx reference counting */
+static struct IR_rx *get_ir_rx(struct IR *ir)
+{
+ struct IR_rx *rx;
+
+ spin_lock(&ir->rx_ref_lock);
+ rx = ir->rx;
+ if (rx != NULL)
+ kref_get(&rx->ref);
+ spin_unlock(&ir->rx_ref_lock);
+ return rx;
+}
+
+static void destroy_rx_kthread(struct IR_rx *rx, bool ir_devices_lock_held)
+{
+ /* end up polling thread */
+ if (!IS_ERR_OR_NULL(rx->task)) {
+ kthread_stop(rx->task);
+ rx->task = NULL;
+ /* Put the ir ptr that ir_probe() gave to the rx poll thread */
+ put_ir_device(rx->ir, ir_devices_lock_held);
+ }
+}
+
+static void release_ir_rx(struct kref *ref)
+{
+ struct IR_rx *rx = container_of(ref, struct IR_rx, ref);
+ struct IR *ir = rx->ir;
+
+ /*
+ * This release function can't do all the work, as we want
+ * to keep the rx_ref_lock a spinlock, and killing the poll thread
+ * and releasing the ir reference can cause a sleep. That work is
+ * performed by put_ir_rx()
+ */
+ ir->l.features &= ~LIRC_CAN_REC_LIRCCODE;
+ /* Don't put_ir_device(rx->ir) here; lock can't be freed yet */
+ ir->rx = NULL;
+ /* Don't do the kfree(rx) here; we still need to kill the poll thread */
+ return;
+}
+
+static int put_ir_rx(struct IR_rx *rx, bool ir_devices_lock_held)
+{
+ int released;
+ struct IR *ir = rx->ir;
+
+ spin_lock(&ir->rx_ref_lock);
+ released = kref_put(&rx->ref, release_ir_rx);
+ spin_unlock(&ir->rx_ref_lock);
+ /* Destroy the rx kthread while not holding the spinlock */
+ if (released) {
+ destroy_rx_kthread(rx, ir_devices_lock_held);
+ kfree(rx);
+ /* Make sure we're not still in a poll_table somewhere */
+ wake_up_interruptible(&ir->rbuf.wait_poll);
+ }
+ /* Do a reference put() for the rx->ir reference, if we released rx */
+ if (released)
+ put_ir_device(ir, ir_devices_lock_held);
+ return released;
+}
+
+/* struct IR_tx reference counting */
+static struct IR_tx *get_ir_tx(struct IR *ir)
+{
+ struct IR_tx *tx;
+
+ spin_lock(&ir->tx_ref_lock);
+ tx = ir->tx;
+ if (tx != NULL)
+ kref_get(&tx->ref);
+ spin_unlock(&ir->tx_ref_lock);
+ return tx;
+}
+
+static void release_ir_tx(struct kref *ref)
+{
+ struct IR_tx *tx = container_of(ref, struct IR_tx, ref);
+ struct IR *ir = tx->ir;
+
+ ir->l.features &= ~LIRC_CAN_SEND_PULSE;
+ /* Don't put_ir_device(tx->ir) here, so our lock doesn't get freed */
+ ir->tx = NULL;
+ kfree(tx);
+}
+
+static int put_ir_tx(struct IR_tx *tx, bool ir_devices_lock_held)
+{
+ int released;
+ struct IR *ir = tx->ir;
+
+ spin_lock(&ir->tx_ref_lock);
+ released = kref_put(&tx->ref, release_ir_tx);
+ spin_unlock(&ir->tx_ref_lock);
+ /* Do a reference put() for the tx->ir reference, if we released tx */
+ if (released)
+ put_ir_device(ir, ir_devices_lock_held);
+ return released;
+}
+
static int add_to_buf(struct IR *ir)
{
__u16 code;
@@ -156,23 +328,38 @@ static int add_to_buf(struct IR *ir)
int ret;
int failures = 0;
unsigned char sendbuf[1] = { 0 };
- struct IR_rx *rx = ir->rx;
+ struct lirc_buffer *rbuf = ir->l.rbuf;
+ struct IR_rx *rx;
+ struct IR_tx *tx;
+ if (lirc_buffer_full(rbuf)) {
+ dprintk("buffer overflow\n");
+ return -EOVERFLOW;
+ }
+
+ rx = get_ir_rx(ir);
if (rx == NULL)
return -ENXIO;
- if (lirc_buffer_full(&rx->buf)) {
- dprintk("buffer overflow\n");
- return -EOVERFLOW;
+ /* Ensure our rx->c i2c_client remains valid for the duration */
+ mutex_lock(&rx->client_lock);
+ if (rx->c == NULL) {
+ mutex_unlock(&rx->client_lock);
+ put_ir_rx(rx, false);
+ return -ENXIO;
}
+ tx = get_ir_tx(ir);
+
/*
* service the device as long as it is returning
* data and we have space
*/
do {
- if (kthread_should_stop())
- return -ENODATA;
+ if (kthread_should_stop()) {
+ ret = -ENODATA;
+ break;
+ }
/*
* Lock i2c bus for the duration. RX/TX chips interfere so
@@ -182,7 +369,8 @@ static int add_to_buf(struct IR *ir)
if (kthread_should_stop()) {
mutex_unlock(&ir->ir_lock);
- return -ENODATA;
+ ret = -ENODATA;
+ break;
}
/*
@@ -196,7 +384,7 @@ static int add_to_buf(struct IR *ir)
mutex_unlock(&ir->ir_lock);
zilog_error("unable to read from the IR chip "
"after 3 resets, giving up\n");
- return ret;
+ break;
}
/* Looks like the chip crashed, reset it */
@@ -206,19 +394,23 @@ static int add_to_buf(struct IR *ir)
set_current_state(TASK_UNINTERRUPTIBLE);
if (kthread_should_stop()) {
mutex_unlock(&ir->ir_lock);
- return -ENODATA;
+ ret = -ENODATA;
+ break;
}
schedule_timeout((100 * HZ + 999) / 1000);
- ir->tx->need_boot = 1;
+ if (tx != NULL)
+ tx->need_boot = 1;
++failures;
mutex_unlock(&ir->ir_lock);
+ ret = 0;
continue;
}
if (kthread_should_stop()) {
mutex_unlock(&ir->ir_lock);
- return -ENODATA;
+ ret = -ENODATA;
+ break;
}
ret = i2c_master_recv(rx->c, keybuf, sizeof(keybuf));
mutex_unlock(&ir->ir_lock);
@@ -234,12 +426,17 @@ static int add_to_buf(struct IR *ir)
/* key pressed ? */
if (rx->hdpvr_data_fmt) {
- if (got_data && (keybuf[0] == 0x80))
- return 0;
- else if (got_data && (keybuf[0] == 0x00))
- return -ENODATA;
- } else if ((rx->b[0] & 0x80) == 0)
- return got_data ? 0 : -ENODATA;
+ if (got_data && (keybuf[0] == 0x80)) {
+ ret = 0;
+ break;
+ } else if (got_data && (keybuf[0] == 0x00)) {
+ ret = -ENODATA;
+ break;
+ }
+ } else if ((rx->b[0] & 0x80) == 0) {
+ ret = got_data ? 0 : -ENODATA;
+ break;
+ }
/* look what we have */
code = (((__u16)rx->b[0] & 0x7f) << 6) | (rx->b[1] >> 2);
@@ -248,11 +445,16 @@ static int add_to_buf(struct IR *ir)
codes[1] = code & 0xff;
/* return it */
- lirc_buffer_write(&rx->buf, codes);
+ lirc_buffer_write(rbuf, codes);
++got_data;
- } while (!lirc_buffer_full(&rx->buf));
+ ret = 0;
+ } while (!lirc_buffer_full(rbuf));
- return 0;
+ mutex_unlock(&rx->client_lock);
+ if (tx != NULL)
+ put_ir_tx(tx, false);
+ put_ir_rx(rx, false);
+ return ret;
}
/*
@@ -268,19 +470,19 @@ static int add_to_buf(struct IR *ir)
static int lirc_thread(void *arg)
{
struct IR *ir = arg;
- struct IR_rx *rx = ir->rx;
+ struct lirc_buffer *rbuf = ir->l.rbuf;
dprintk("poll thread started\n");
while (!kthread_should_stop()) {
- set_current_state(TASK_INTERRUPTIBLE);
-
/* if device not opened, we can sleep half a second */
- if (!ir->open) {
+ if (atomic_read(&ir->open_count) == 0) {
schedule_timeout(HZ/2);
continue;
}
+ set_current_state(TASK_INTERRUPTIBLE);
+
/*
* This is ~113*2 + 24 + jitter (2*repeat gap + code length).
* We use this interval as the chip resets every time you poll
@@ -295,7 +497,7 @@ static int lirc_thread(void *arg)
if (kthread_should_stop())
break;
if (!add_to_buf(ir))
- wake_up_interruptible(&rx->buf.wait_poll);
+ wake_up_interruptible(&rbuf->wait_poll);
}
dprintk("poll thread ended\n");
@@ -304,34 +506,12 @@ static int lirc_thread(void *arg)
static int set_use_inc(void *data)
{
- struct IR *ir = data;
-
- if (ir->l.owner == NULL || try_module_get(ir->l.owner) == 0)
- return -ENODEV;
-
- /* lock bttv in memory while /dev/lirc is in use */
- /*
- * this is completely broken code. lirc_unregister_driver()
- * must be possible even when the device is open
- */
- if (ir->rx != NULL)
- i2c_use_client(ir->rx->c);
- if (ir->tx != NULL)
- i2c_use_client(ir->tx->c);
-
return 0;
}
static void set_use_dec(void *data)
{
- struct IR *ir = data;
-
- if (ir->rx)
- i2c_release_client(ir->rx->c);
- if (ir->tx)
- i2c_release_client(ir->tx->c);
- if (ir->l.owner != NULL)
- module_put(ir->l.owner);
+ return;
}
/* safe read of a uint32 (always network byte order) */
@@ -585,7 +765,7 @@ static int fw_load(struct IR_tx *tx)
}
/* Request codeset data file */
- ret = request_firmware(&fw_entry, "haup-ir-blaster.bin", &tx->c->dev);
+ ret = request_firmware(&fw_entry, "haup-ir-blaster.bin", tx->ir->l.dev);
if (ret != 0) {
zilog_error("firmware haup-ir-blaster.bin not available "
"(%d)\n", ret);
@@ -711,59 +891,32 @@ out:
return ret;
}
-/* initialise the IR TX device */
-static int tx_init(struct IR_tx *tx)
-{
- int ret;
-
- /* Load 'firmware' */
- ret = fw_load(tx);
- if (ret != 0)
- return ret;
-
- /* Send boot block */
- ret = send_boot_data(tx);
- if (ret != 0)
- return ret;
- tx->need_boot = 0;
-
- /* Looks good */
- return 0;
-}
-
-/* do nothing stub to make LIRC happy */
-static loff_t lseek(struct file *filep, loff_t offset, int orig)
-{
- return -ESPIPE;
-}
-
/* copied from lirc_dev */
static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos)
{
struct IR *ir = filep->private_data;
- struct IR_rx *rx = ir->rx;
- int ret = 0, written = 0;
+ struct IR_rx *rx;
+ struct lirc_buffer *rbuf = ir->l.rbuf;
+ int ret = 0, written = 0, retries = 0;
+ unsigned int m;
DECLARE_WAITQUEUE(wait, current);
dprintk("read called\n");
- if (rx == NULL)
- return -ENODEV;
-
- if (mutex_lock_interruptible(&rx->buf_lock))
- return -ERESTARTSYS;
-
- if (n % rx->buf.chunk_size) {
+ if (n % rbuf->chunk_size) {
dprintk("read result = -EINVAL\n");
- mutex_unlock(&rx->buf_lock);
return -EINVAL;
}
+ rx = get_ir_rx(ir);
+ if (rx == NULL)
+ return -ENXIO;
+
/*
* we add ourselves to the task queue before buffer check
* to avoid losing scan code (in case when queue is awaken somewhere
* between while condition checking and scheduling)
*/
- add_wait_queue(&rx->buf.wait_poll, &wait);
+ add_wait_queue(&rbuf->wait_poll, &wait);
set_current_state(TASK_INTERRUPTIBLE);
/*
@@ -771,7 +924,7 @@ static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos)
* mode and 'copy_to_user' is happy, wait for data.
*/
while (written < n && ret == 0) {
- if (lirc_buffer_empty(&rx->buf)) {
+ if (lirc_buffer_empty(rbuf)) {
/*
* According to the read(2) man page, 'written' can be
* returned as less than 'n', instead of blocking
@@ -791,20 +944,27 @@ static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos)
schedule();
set_current_state(TASK_INTERRUPTIBLE);
} else {
- unsigned char buf[rx->buf.chunk_size];
- lirc_buffer_read(&rx->buf, buf);
- ret = copy_to_user((void *)outbuf+written, buf,
- rx->buf.chunk_size);
- written += rx->buf.chunk_size;
+ unsigned char buf[rbuf->chunk_size];
+ m = lirc_buffer_read(rbuf, buf);
+ if (m == rbuf->chunk_size) {
+ ret = copy_to_user((void *)outbuf+written, buf,
+ rbuf->chunk_size);
+ written += rbuf->chunk_size;
+ } else {
+ retries++;
+ }
+ if (retries >= 5) {
+ zilog_error("Buffer read failed!\n");
+ ret = -EIO;
+ }
}
}
- remove_wait_queue(&rx->buf.wait_poll, &wait);
+ remove_wait_queue(&rbuf->wait_poll, &wait);
+ put_ir_rx(rx, false);
set_current_state(TASK_RUNNING);
- mutex_unlock(&rx->buf_lock);
- dprintk("read result = %s (%d)\n",
- ret ? "-EFAULT" : "OK", ret);
+ dprintk("read result = %d (%s)\n", ret, ret ? "Error" : "OK");
return ret ? ret : written;
}
@@ -931,17 +1091,27 @@ static ssize_t write(struct file *filep, const char *buf, size_t n,
loff_t *ppos)
{
struct IR *ir = filep->private_data;
- struct IR_tx *tx = ir->tx;
+ struct IR_tx *tx;
size_t i;
int failures = 0;
- if (tx == NULL)
- return -ENODEV;
-
/* Validate user parameters */
if (n % sizeof(int))
return -EINVAL;
+ /* Get a struct IR_tx reference */
+ tx = get_ir_tx(ir);
+ if (tx == NULL)
+ return -ENXIO;
+
+ /* Ensure our tx->c i2c_client remains valid for the duration */
+ mutex_lock(&tx->client_lock);
+ if (tx->c == NULL) {
+ mutex_unlock(&tx->client_lock);
+ put_ir_tx(tx, false);
+ return -ENXIO;
+ }
+
/* Lock i2c bus for the duration */
mutex_lock(&ir->ir_lock);
@@ -952,11 +1122,24 @@ static ssize_t write(struct file *filep, const char *buf, size_t n,
if (copy_from_user(&command, buf + i, sizeof(command))) {
mutex_unlock(&ir->ir_lock);
+ mutex_unlock(&tx->client_lock);
+ put_ir_tx(tx, false);
return -EFAULT;
}
/* Send boot data first if required */
if (tx->need_boot == 1) {
+ /* Make sure we have the 'firmware' loaded, first */
+ ret = fw_load(tx);
+ if (ret != 0) {
+ mutex_unlock(&ir->ir_lock);
+ mutex_unlock(&tx->client_lock);
+ put_ir_tx(tx, false);
+ if (ret != -ENOMEM)
+ ret = -EIO;
+ return ret;
+ }
+ /* Prep the chip for transmitting codes */
ret = send_boot_data(tx);
if (ret == 0)
tx->need_boot = 0;
@@ -968,6 +1151,8 @@ static ssize_t write(struct file *filep, const char *buf, size_t n,
(unsigned)command & 0xFFFF);
if (ret == -EPROTO) {
mutex_unlock(&ir->ir_lock);
+ mutex_unlock(&tx->client_lock);
+ put_ir_tx(tx, false);
return ret;
}
}
@@ -985,6 +1170,8 @@ static ssize_t write(struct file *filep, const char *buf, size_t n,
zilog_error("unable to send to the IR chip "
"after 3 resets, giving up\n");
mutex_unlock(&ir->ir_lock);
+ mutex_unlock(&tx->client_lock);
+ put_ir_tx(tx, false);
return ret;
}
set_current_state(TASK_UNINTERRUPTIBLE);
@@ -998,6 +1185,11 @@ static ssize_t write(struct file *filep, const char *buf, size_t n,
/* Release i2c bus */
mutex_unlock(&ir->ir_lock);
+ mutex_unlock(&tx->client_lock);
+
+ /* Give back our struct IR_tx reference */
+ put_ir_tx(tx, false);
+
/* All looks good */
return n;
}
@@ -1006,23 +1198,32 @@ static ssize_t write(struct file *filep, const char *buf, size_t n,
static unsigned int poll(struct file *filep, poll_table *wait)
{
struct IR *ir = filep->private_data;
- struct IR_rx *rx = ir->rx;
+ struct IR_rx *rx;
+ struct lirc_buffer *rbuf = ir->l.rbuf;
unsigned int ret;
dprintk("poll called\n");
- if (rx == NULL)
- return -ENODEV;
-
- mutex_lock(&rx->buf_lock);
- poll_wait(filep, &rx->buf.wait_poll, wait);
+ rx = get_ir_rx(ir);
+ if (rx == NULL) {
+ /*
+ * Revisit this, if our poll function ever reports writeable
+ * status for Tx
+ */
+ dprintk("poll result = POLLERR\n");
+ return POLLERR;
+ }
- dprintk("poll result = %s\n",
- lirc_buffer_empty(&rx->buf) ? "0" : "POLLIN|POLLRDNORM");
+ /*
+ * Add our lirc_buffer's wait_queue to the poll_table. A wake up on
+ * that buffer's wait queue indicates we may have a new poll status.
+ */
+ poll_wait(filep, &rbuf->wait_poll, wait);
- ret = lirc_buffer_empty(&rx->buf) ? 0 : (POLLIN|POLLRDNORM);
+ /* Indicate what ops could happen immediately without blocking */
+ ret = lirc_buffer_empty(rbuf) ? 0 : (POLLIN|POLLRDNORM);
- mutex_unlock(&rx->buf_lock);
+ dprintk("poll result = %s\n", ret ? "POLLIN|POLLRDNORM" : "none");
return ret;
}
@@ -1030,11 +1231,9 @@ static long ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
{
struct IR *ir = filep->private_data;
int result;
- unsigned long mode, features = 0;
+ unsigned long mode, features;
- features |= LIRC_CAN_SEND_PULSE;
- if (ir->rx != NULL)
- features |= LIRC_CAN_REC_LIRCCODE;
+ features = ir->l.features;
switch (cmd) {
case LIRC_GET_LENGTH:
@@ -1061,9 +1260,15 @@ static long ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
result = -EINVAL;
break;
case LIRC_GET_SEND_MODE:
+ if (!(features&LIRC_CAN_SEND_MASK))
+ return -ENOSYS;
+
result = put_user(LIRC_MODE_PULSE, (unsigned long *) arg);
break;
case LIRC_SET_SEND_MODE:
+ if (!(features&LIRC_CAN_SEND_MASK))
+ return -ENOSYS;
+
result = get_user(mode, (unsigned long *) arg);
if (!result && mode != LIRC_MODE_PULSE)
return -EINVAL;
@@ -1074,13 +1279,24 @@ static long ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
return result;
}
-/* ir_devices_lock must be held */
-static struct IR *find_ir_device_by_minor(unsigned int minor)
+static struct IR *get_ir_device_by_minor(unsigned int minor)
{
- if (minor >= MAX_IRCTL_DEVICES)
- return NULL;
+ struct IR *ir;
+ struct IR *ret = NULL;
+
+ mutex_lock(&ir_devices_lock);
+
+ if (!list_empty(&ir_devices_list)) {
+ list_for_each_entry(ir, &ir_devices_list, list) {
+ if (ir->l.minor == minor) {
+ ret = get_ir_device(ir, true);
+ break;
+ }
+ }
+ }
- return ir_devices[minor];
+ mutex_unlock(&ir_devices_lock);
+ return ret;
}
/*
@@ -1090,31 +1306,20 @@ static struct IR *find_ir_device_by_minor(unsigned int minor)
static int open(struct inode *node, struct file *filep)
{
struct IR *ir;
- int ret;
unsigned int minor = MINOR(node->i_rdev);
/* find our IR struct */
- mutex_lock(&ir_devices_lock);
- ir = find_ir_device_by_minor(minor);
- mutex_unlock(&ir_devices_lock);
+ ir = get_ir_device_by_minor(minor);
if (ir == NULL)
return -ENODEV;
- /* increment in use count */
- mutex_lock(&ir->ir_lock);
- ++ir->open;
- ret = set_use_inc(ir);
- if (ret != 0) {
- --ir->open;
- mutex_unlock(&ir->ir_lock);
- return ret;
- }
- mutex_unlock(&ir->ir_lock);
+ atomic_inc(&ir->open_count);
/* stash our IR struct */
filep->private_data = ir;
+ nonseekable_open(node, filep);
return 0;
}
@@ -1128,22 +1333,12 @@ static int close(struct inode *node, struct file *filep)
return -ENODEV;
}
- /* decrement in use count */
- mutex_lock(&ir->ir_lock);
- --ir->open;
- set_use_dec(ir);
- mutex_unlock(&ir->ir_lock);
+ atomic_dec(&ir->open_count);
+ put_ir_device(ir, false);
return 0;
}
-static struct lirc_driver lirc_template = {
- .name = "lirc_zilog",
- .set_use_inc = set_use_inc,
- .set_use_dec = set_use_dec,
- .owner = THIS_MODULE
-};
-
static int ir_remove(struct i2c_client *client);
static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id);
@@ -1170,7 +1365,7 @@ static struct i2c_driver driver = {
static const struct file_operations lirc_fops = {
.owner = THIS_MODULE,
- .llseek = lseek,
+ .llseek = no_llseek,
.read = read,
.write = write,
.poll = poll,
@@ -1182,97 +1377,64 @@ static const struct file_operations lirc_fops = {
.release = close
};
-static void destroy_rx_kthread(struct IR_rx *rx)
-{
- /* end up polling thread */
- if (rx != NULL && !IS_ERR_OR_NULL(rx->task)) {
- kthread_stop(rx->task);
- rx->task = NULL;
- }
-}
+static struct lirc_driver lirc_template = {
+ .name = "lirc_zilog",
+ .minor = -1,
+ .code_length = 13,
+ .buffer_size = BUFLEN / 2,
+ .sample_rate = 0, /* tell lirc_dev to not start its own kthread */
+ .chunk_size = 2,
+ .set_use_inc = set_use_inc,
+ .set_use_dec = set_use_dec,
+ .fops = &lirc_fops,
+ .owner = THIS_MODULE,
+};
-/* ir_devices_lock must be held */
-static int add_ir_device(struct IR *ir)
+static int ir_remove(struct i2c_client *client)
{
- int i;
-
- for (i = 0; i < MAX_IRCTL_DEVICES; i++)
- if (ir_devices[i] == NULL) {
- ir_devices[i] = ir;
- break;
+ if (strncmp("ir_tx_z8", client->name, 8) == 0) {
+ struct IR_tx *tx = i2c_get_clientdata(client);
+ if (tx != NULL) {
+ mutex_lock(&tx->client_lock);
+ tx->c = NULL;
+ mutex_unlock(&tx->client_lock);
+ put_ir_tx(tx, false);
}
-
- return i == MAX_IRCTL_DEVICES ? -ENOMEM : i;
-}
-
-/* ir_devices_lock must be held */
-static void del_ir_device(struct IR *ir)
-{
- int i;
-
- for (i = 0; i < MAX_IRCTL_DEVICES; i++)
- if (ir_devices[i] == ir) {
- ir_devices[i] = NULL;
- break;
+ } else if (strncmp("ir_rx_z8", client->name, 8) == 0) {
+ struct IR_rx *rx = i2c_get_clientdata(client);
+ if (rx != NULL) {
+ mutex_lock(&rx->client_lock);
+ rx->c = NULL;
+ mutex_unlock(&rx->client_lock);
+ put_ir_rx(rx, false);
}
-}
-
-static int ir_remove(struct i2c_client *client)
-{
- struct IR *ir = i2c_get_clientdata(client);
-
- mutex_lock(&ir_devices_lock);
-
- if (ir == NULL) {
- /* We destroyed everything when the first client came through */
- mutex_unlock(&ir_devices_lock);
- return 0;
}
-
- /* Good-bye LIRC */
- lirc_unregister_driver(ir->l.minor);
-
- /* Good-bye Rx */
- destroy_rx_kthread(ir->rx);
- if (ir->rx != NULL) {
- if (ir->rx->buf.fifo_initialized)
- lirc_buffer_free(&ir->rx->buf);
- i2c_set_clientdata(ir->rx->c, NULL);
- kfree(ir->rx);
- }
-
- /* Good-bye Tx */
- i2c_set_clientdata(ir->tx->c, NULL);
- kfree(ir->tx);
-
- /* Good-bye IR */
- del_ir_device(ir);
- kfree(ir);
-
- mutex_unlock(&ir_devices_lock);
return 0;
}
/* ir_devices_lock must be held */
-static struct IR *find_ir_device_by_adapter(struct i2c_adapter *adapter)
+static struct IR *get_ir_device_by_adapter(struct i2c_adapter *adapter)
{
- int i;
- struct IR *ir = NULL;
+ struct IR *ir;
- for (i = 0; i < MAX_IRCTL_DEVICES; i++)
- if (ir_devices[i] != NULL &&
- ir_devices[i]->adapter == adapter) {
- ir = ir_devices[i];
- break;
+ if (list_empty(&ir_devices_list))
+ return NULL;
+
+ list_for_each_entry(ir, &ir_devices_list, list)
+ if (ir->adapter == adapter) {
+ get_ir_device(ir, true);
+ return ir;
}
- return ir;
+ return NULL;
}
static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
struct IR *ir;
+ struct IR_tx *tx;
+ struct IR_rx *rx;
struct i2c_adapter *adap = client->adapter;
int ret;
bool tx_probe = false;
@@ -1296,133 +1458,170 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
mutex_lock(&ir_devices_lock);
/* Use a single struct IR instance for both the Rx and Tx functions */
- ir = find_ir_device_by_adapter(adap);
+ ir = get_ir_device_by_adapter(adap);
if (ir == NULL) {
ir = kzalloc(sizeof(struct IR), GFP_KERNEL);
if (ir == NULL) {
ret = -ENOMEM;
goto out_no_ir;
}
+ kref_init(&ir->ref);
+
/* store for use in ir_probe() again, and open() later on */
- ret = add_ir_device(ir);
- if (ret)
- goto out_free_ir;
+ INIT_LIST_HEAD(&ir->list);
+ list_add_tail(&ir->list, &ir_devices_list);
ir->adapter = adap;
mutex_init(&ir->ir_lock);
+ atomic_set(&ir->open_count, 0);
+ spin_lock_init(&ir->tx_ref_lock);
+ spin_lock_init(&ir->rx_ref_lock);
/* set lirc_dev stuff */
memcpy(&ir->l, &lirc_template, sizeof(struct lirc_driver));
- ir->l.minor = minor; /* module option */
- ir->l.code_length = 13;
- ir->l.rbuf = NULL;
- ir->l.fops = &lirc_fops;
- ir->l.data = ir;
- ir->l.dev = &adap->dev;
- ir->l.sample_rate = 0;
+ /*
+ * FIXME this is a pointer reference to us, but no refcount.
+ *
+ * This OK for now, since lirc_dev currently won't touch this
+ * buffer as we provide our own lirc_fops.
+ *
+ * Currently our own lirc_fops rely on this ir->l.rbuf pointer
+ */
+ ir->l.rbuf = &ir->rbuf;
+ ir->l.dev = &adap->dev;
+ ret = lirc_buffer_init(ir->l.rbuf,
+ ir->l.chunk_size, ir->l.buffer_size);
+ if (ret)
+ goto out_put_ir;
}
if (tx_probe) {
+ /* Get the IR_rx instance for later, if already allocated */
+ rx = get_ir_rx(ir);
+
/* Set up a struct IR_tx instance */
- ir->tx = kzalloc(sizeof(struct IR_tx), GFP_KERNEL);
- if (ir->tx == NULL) {
+ tx = kzalloc(sizeof(struct IR_tx), GFP_KERNEL);
+ if (tx == NULL) {
ret = -ENOMEM;
- goto out_free_xx;
+ goto out_put_xx;
}
-
- ir->tx->c = client;
- ir->tx->need_boot = 1;
- ir->tx->post_tx_ready_poll =
+ kref_init(&tx->ref);
+ ir->tx = tx;
+
+ ir->l.features |= LIRC_CAN_SEND_PULSE;
+ mutex_init(&tx->client_lock);
+ tx->c = client;
+ tx->need_boot = 1;
+ tx->post_tx_ready_poll =
(id->driver_data & ID_FLAG_HDPVR) ? false : true;
+
+ /* An ir ref goes to the struct IR_tx instance */
+ tx->ir = get_ir_device(ir, true);
+
+ /* A tx ref goes to the i2c_client */
+ i2c_set_clientdata(client, get_ir_tx(ir));
+
+ /*
+ * Load the 'firmware'. We do this before registering with
+ * lirc_dev, so the first firmware load attempt does not happen
+ * after a open() or write() call on the device.
+ *
+ * Failure here is not deemed catastrophic, so the receiver will
+ * still be usable. Firmware load will be retried in write(),
+ * if it is needed.
+ */
+ fw_load(tx);
+
+ /* Proceed only if the Rx client is also ready or not needed */
+ if (rx == NULL && !tx_only) {
+ zilog_info("probe of IR Tx on %s (i2c-%d) done. Waiting"
+ " on IR Rx.\n", adap->name, adap->nr);
+ goto out_ok;
+ }
} else {
+ /* Get the IR_tx instance for later, if already allocated */
+ tx = get_ir_tx(ir);
+
/* Set up a struct IR_rx instance */
- ir->rx = kzalloc(sizeof(struct IR_rx), GFP_KERNEL);
- if (ir->rx == NULL) {
+ rx = kzalloc(sizeof(struct IR_rx), GFP_KERNEL);
+ if (rx == NULL) {
ret = -ENOMEM;
- goto out_free_xx;
+ goto out_put_xx;
}
+ kref_init(&rx->ref);
+ ir->rx = rx;
- ret = lirc_buffer_init(&ir->rx->buf, 2, BUFLEN / 2);
- if (ret)
- goto out_free_xx;
-
- mutex_init(&ir->rx->buf_lock);
- ir->rx->c = client;
- ir->rx->hdpvr_data_fmt =
+ ir->l.features |= LIRC_CAN_REC_LIRCCODE;
+ mutex_init(&rx->client_lock);
+ rx->c = client;
+ rx->hdpvr_data_fmt =
(id->driver_data & ID_FLAG_HDPVR) ? true : false;
- /* set lirc_dev stuff */
- ir->l.rbuf = &ir->rx->buf;
- }
-
- i2c_set_clientdata(client, ir);
+ /* An ir ref goes to the struct IR_rx instance */
+ rx->ir = get_ir_device(ir, true);
- /* Proceed only if we have the required Tx and Rx clients ready to go */
- if (ir->tx == NULL ||
- (ir->rx == NULL && !tx_only)) {
- zilog_info("probe of IR %s on %s (i2c-%d) done. Waiting on "
- "IR %s.\n", tx_probe ? "Tx" : "Rx", adap->name,
- adap->nr, tx_probe ? "Rx" : "Tx");
- goto out_ok;
- }
+ /* An rx ref goes to the i2c_client */
+ i2c_set_clientdata(client, get_ir_rx(ir));
- /* initialise RX device */
- if (ir->rx != NULL) {
- /* try to fire up polling thread */
- ir->rx->task = kthread_run(lirc_thread, ir,
- "zilog-rx-i2c-%d", adap->nr);
- if (IS_ERR(ir->rx->task)) {
- ret = PTR_ERR(ir->rx->task);
+ /*
+ * Start the polling thread.
+ * It will only perform an empty loop around schedule_timeout()
+ * until we register with lirc_dev and the first user open()
+ */
+ /* An ir ref goes to the new rx polling kthread */
+ rx->task = kthread_run(lirc_thread, get_ir_device(ir, true),
+ "zilog-rx-i2c-%d", adap->nr);
+ if (IS_ERR(rx->task)) {
+ ret = PTR_ERR(rx->task);
zilog_error("%s: could not start IR Rx polling thread"
"\n", __func__);
- goto out_free_xx;
+ /* Failed kthread, so put back the ir ref */
+ put_ir_device(ir, true);
+ /* Failure exit, so put back rx ref from i2c_client */
+ i2c_set_clientdata(client, NULL);
+ put_ir_rx(rx, true);
+ ir->l.features &= ~LIRC_CAN_REC_LIRCCODE;
+ goto out_put_xx;
+ }
+
+ /* Proceed only if the Tx client is also ready */
+ if (tx == NULL) {
+ zilog_info("probe of IR Rx on %s (i2c-%d) done. Waiting"
+ " on IR Tx.\n", adap->name, adap->nr);
+ goto out_ok;
}
}
/* register with lirc */
+ ir->l.minor = minor; /* module option: user requested minor number */
ir->l.minor = lirc_register_driver(&ir->l);
if (ir->l.minor < 0 || ir->l.minor >= MAX_IRCTL_DEVICES) {
zilog_error("%s: \"minor\" must be between 0 and %d (%d)!\n",
__func__, MAX_IRCTL_DEVICES-1, ir->l.minor);
ret = -EBADRQC;
- goto out_free_thread;
+ goto out_put_xx;
}
+ zilog_info("IR unit on %s (i2c-%d) registered as lirc%d and ready\n",
+ adap->name, adap->nr, ir->l.minor);
- /*
- * if we have the tx device, load the 'firmware'. We do this
- * after registering with lirc as otherwise hotplug seems to take
- * 10s to create the lirc device.
- */
- ret = tx_init(ir->tx);
- if (ret != 0)
- goto out_unregister;
-
- zilog_info("probe of IR %s on %s (i2c-%d) done. IR unit ready.\n",
- tx_probe ? "Tx" : "Rx", adap->name, adap->nr);
out_ok:
+ if (rx != NULL)
+ put_ir_rx(rx, true);
+ if (tx != NULL)
+ put_ir_tx(tx, true);
+ put_ir_device(ir, true);
+ zilog_info("probe of IR %s on %s (i2c-%d) done\n",
+ tx_probe ? "Tx" : "Rx", adap->name, adap->nr);
mutex_unlock(&ir_devices_lock);
return 0;
-out_unregister:
- lirc_unregister_driver(ir->l.minor);
-out_free_thread:
- destroy_rx_kthread(ir->rx);
-out_free_xx:
- if (ir->rx != NULL) {
- if (ir->rx->buf.fifo_initialized)
- lirc_buffer_free(&ir->rx->buf);
- if (ir->rx->c != NULL)
- i2c_set_clientdata(ir->rx->c, NULL);
- kfree(ir->rx);
- }
- if (ir->tx != NULL) {
- if (ir->tx->c != NULL)
- i2c_set_clientdata(ir->tx->c, NULL);
- kfree(ir->tx);
- }
-out_free_ir:
- del_ir_device(ir);
- kfree(ir);
+out_put_xx:
+ if (rx != NULL)
+ put_ir_rx(rx, true);
+ if (tx != NULL)
+ put_ir_tx(tx, true);
+out_put_ir:
+ put_ir_device(ir, true);
out_no_ir:
zilog_error("%s: probing IR %s on %s (i2c-%d) failed with %d\n",
__func__, tx_probe ? "Tx" : "Rx", adap->name, adap->nr,
@@ -1438,7 +1637,6 @@ static int __init zilog_init(void)
zilog_notify("Zilog/Hauppauge IR driver initializing\n");
mutex_init(&tx_data_lock);
- mutex_init(&ir_devices_lock);
request_module("firmware_class");