2 * Driver for ITE Tech Inc. IT8712F/IT8512 CIR
4 * Copyright (C) 2010 Juan Jesús García de Soria <skandalfo@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 * Inspired by the original lirc_it87 and lirc_ite8709 drivers, on top of the
22 * skeleton provided by the nuvoton-cir driver.
24 * The lirc_it87 driver was originally written by Hans-Gunter Lutke Uphues
25 * <hg_lu@web.de> in 2001, with enhancements by Christoph Bartelmus
26 * <lirc@bartelmus.de>, Andrew Calkin <r_tay@hotmail.com> and James Edwards
27 * <jimbo-lirc@edwardsclan.net>.
29 * The lirc_ite8709 driver was written by Grégory Lardière
30 * <spmf2004-lirc@yahoo.fr> in 2008.
33 #include <linux/kernel.h>
34 #include <linux/module.h>
35 #include <linux/pnp.h>
37 #include <linux/interrupt.h>
38 #include <linux/sched.h>
39 #include <linux/delay.h>
40 #include <linux/slab.h>
41 #include <linux/input.h>
42 #include <linux/bitops.h>
43 #include <media/rc-core.h>
44 #include <linux/pci_ids.h>
45 #include <linux/delay.h>
49 /* module parameters */
53 module_param(debug, int, S_IRUGO | S_IWUSR);
54 MODULE_PARM_DESC(debug, "Enable debugging output");
56 /* low limit for RX carrier freq, Hz, 0 for no RX demodulation */
57 static int rx_low_carrier_freq;
58 module_param(rx_low_carrier_freq, int, S_IRUGO | S_IWUSR);
59 MODULE_PARM_DESC(rx_low_carrier_freq, "Override low RX carrier frequency, Hz, "
60 "0 for no RX demodulation");
62 /* high limit for RX carrier freq, Hz, 0 for no RX demodulation */
63 static int rx_high_carrier_freq;
64 module_param(rx_high_carrier_freq, int, S_IRUGO | S_IWUSR);
65 MODULE_PARM_DESC(rx_high_carrier_freq, "Override high RX carrier frequency, "
66 "Hz, 0 for no RX demodulation");
68 /* override tx carrier frequency */
69 static int tx_carrier_freq;
70 module_param(tx_carrier_freq, int, S_IRUGO | S_IWUSR);
71 MODULE_PARM_DESC(tx_carrier_freq, "Override TX carrier frequency, Hz");
73 /* override tx duty cycle */
74 static int tx_duty_cycle;
75 module_param(tx_duty_cycle, int, S_IRUGO | S_IWUSR);
76 MODULE_PARM_DESC(tx_duty_cycle, "Override TX duty cycle, 1-100");
78 /* override default sample period */
79 static long sample_period;
80 module_param(sample_period, long, S_IRUGO | S_IWUSR);
81 MODULE_PARM_DESC(sample_period, "Override carrier sample period, us");
83 /* override detected model id */
84 static int model_number = -1;
85 module_param(model_number, int, S_IRUGO | S_IWUSR);
86 MODULE_PARM_DESC(model_number, "Use this model number, don't autodetect");
89 /* HW-independent code functions */
91 /* check whether carrier frequency is high frequency */
92 static inline bool ite_is_high_carrier_freq(unsigned int freq)
94 return freq >= ITE_HCF_MIN_CARRIER_FREQ;
97 /* get the bits required to program the carrier frequency in CFQ bits,
99 static u8 ite_get_carrier_freq_bits(unsigned int freq)
101 if (ite_is_high_carrier_freq(freq)) {
105 else if (freq < 465000)
108 else if (freq < 490000)
115 if (freq < ITE_LCF_MIN_CARRIER_FREQ)
116 freq = ITE_LCF_MIN_CARRIER_FREQ;
117 if (freq > ITE_LCF_MAX_CARRIER_FREQ)
118 freq = ITE_LCF_MAX_CARRIER_FREQ;
120 /* convert to kHz and subtract the base freq */
122 DIV_ROUND_CLOSEST(freq - ITE_LCF_MIN_CARRIER_FREQ,
129 /* get the bits required to program the pulse with in TXMPW */
130 static u8 ite_get_pulse_width_bits(unsigned int freq, int duty_cycle)
132 unsigned long period_ns, on_ns;
134 /* sanitize freq into range */
135 if (freq < ITE_LCF_MIN_CARRIER_FREQ)
136 freq = ITE_LCF_MIN_CARRIER_FREQ;
137 if (freq > ITE_HCF_MAX_CARRIER_FREQ)
138 freq = ITE_HCF_MAX_CARRIER_FREQ;
140 period_ns = 1000000000UL / freq;
141 on_ns = period_ns * duty_cycle / 100;
143 if (ite_is_high_carrier_freq(freq)) {
147 else if (on_ns < 850)
150 else if (on_ns < 950)
153 else if (on_ns < 1080)
162 else if (on_ns < 7850)
165 else if (on_ns < 9650)
168 else if (on_ns < 11950)
176 /* decode raw bytes as received by the hardware, and push them to the ir-core
178 static void ite_decode_bytes(struct ite_dev *dev, const u8 * data, int
182 unsigned long *ldata;
183 unsigned int next_one, next_zero, size;
184 DEFINE_IR_RAW_EVENT(ev);
189 sample_period = dev->params.sample_period;
190 ldata = (unsigned long *)data;
192 next_one = find_next_bit_le(ldata, size, 0);
196 ITE_BITS_TO_NS(next_one, sample_period);
197 ir_raw_event_store_with_filter(dev->rdev, &ev);
200 while (next_one < size) {
201 next_zero = find_next_zero_bit_le(ldata, size, next_one + 1);
203 ev.duration = ITE_BITS_TO_NS(next_zero - next_one, sample_period);
204 ir_raw_event_store_with_filter(dev->rdev, &ev);
206 if (next_zero < size) {
208 find_next_bit_le(ldata,
213 ITE_BITS_TO_NS(next_one - next_zero,
215 ir_raw_event_store_with_filter
221 ir_raw_event_handle(dev->rdev);
223 ite_dbg_verbose("decoded %d bytes.", length);
226 /* set all the rx/tx carrier parameters; this must be called with the device
228 static void ite_set_carrier_params(struct ite_dev *dev)
230 unsigned int freq, low_freq, high_freq;
232 bool use_demodulator;
233 bool for_tx = dev->transmitting;
235 ite_dbg("%s called", __func__);
238 /* we don't need no stinking calculations */
239 freq = dev->params.tx_carrier_freq;
240 allowance = ITE_RXDCR_DEFAULT;
241 use_demodulator = false;
243 low_freq = dev->params.rx_low_carrier_freq;
244 high_freq = dev->params.rx_high_carrier_freq;
247 /* don't demodulate */
249 ITE_DEFAULT_CARRIER_FREQ;
250 allowance = ITE_RXDCR_DEFAULT;
251 use_demodulator = false;
253 /* calculate the middle freq */
254 freq = (low_freq + high_freq) / 2;
256 /* calculate the allowance */
258 DIV_ROUND_CLOSEST(10000 * (high_freq - low_freq),
259 ITE_RXDCR_PER_10000_STEP
260 * (high_freq + low_freq));
265 if (allowance > ITE_RXDCR_MAX)
266 allowance = ITE_RXDCR_MAX;
270 /* set the carrier parameters in a device-dependent way */
271 dev->params.set_carrier_params(dev, ite_is_high_carrier_freq(freq),
272 use_demodulator, ite_get_carrier_freq_bits(freq), allowance,
273 ite_get_pulse_width_bits(freq, dev->params.tx_duty_cycle));
276 /* interrupt service routine for incoming and outgoing CIR data */
277 static irqreturn_t ite_cir_isr(int irq, void *data)
279 struct ite_dev *dev = data;
281 irqreturn_t ret = IRQ_RETVAL(IRQ_NONE);
282 u8 rx_buf[ITE_RX_FIFO_LEN];
286 ite_dbg_verbose("%s firing", __func__);
288 /* grab the spinlock */
289 spin_lock_irqsave(&dev->lock, flags);
291 /* read the interrupt flags */
292 iflags = dev->params.get_irq_causes(dev);
294 /* check for the receive interrupt */
295 if (iflags & (ITE_IRQ_RX_FIFO | ITE_IRQ_RX_FIFO_OVERRUN)) {
296 /* read the FIFO bytes */
298 dev->params.get_rx_bytes(dev, rx_buf,
302 /* drop the spinlock, since the ir-core layer
303 * may call us back again through
305 spin_unlock_irqrestore(&dev->
309 /* decode the data we've just received */
310 ite_decode_bytes(dev, rx_buf,
313 /* reacquire the spinlock */
314 spin_lock_irqsave(&dev->lock,
317 /* mark the interrupt as serviced */
318 ret = IRQ_RETVAL(IRQ_HANDLED);
320 } else if (iflags & ITE_IRQ_TX_FIFO) {
321 /* FIFO space available interrupt */
322 ite_dbg_verbose("got interrupt for TX FIFO");
324 /* wake any sleeping transmitter */
325 wake_up_interruptible(&dev->tx_queue);
327 /* mark the interrupt as serviced */
328 ret = IRQ_RETVAL(IRQ_HANDLED);
331 /* drop the spinlock */
332 spin_unlock_irqrestore(&dev->lock, flags);
334 ite_dbg_verbose("%s done returning %d", __func__, (int)ret);
339 /* set the rx carrier freq range, guess it's in Hz... */
340 static int ite_set_rx_carrier_range(struct rc_dev *rcdev, u32 carrier_low, u32
344 struct ite_dev *dev = rcdev->priv;
346 spin_lock_irqsave(&dev->lock, flags);
347 dev->params.rx_low_carrier_freq = carrier_low;
348 dev->params.rx_high_carrier_freq = carrier_high;
349 ite_set_carrier_params(dev);
350 spin_unlock_irqrestore(&dev->lock, flags);
355 /* set the tx carrier freq, guess it's in Hz... */
356 static int ite_set_tx_carrier(struct rc_dev *rcdev, u32 carrier)
359 struct ite_dev *dev = rcdev->priv;
361 spin_lock_irqsave(&dev->lock, flags);
362 dev->params.tx_carrier_freq = carrier;
363 ite_set_carrier_params(dev);
364 spin_unlock_irqrestore(&dev->lock, flags);
369 /* set the tx duty cycle by controlling the pulse width */
370 static int ite_set_tx_duty_cycle(struct rc_dev *rcdev, u32 duty_cycle)
373 struct ite_dev *dev = rcdev->priv;
375 spin_lock_irqsave(&dev->lock, flags);
376 dev->params.tx_duty_cycle = duty_cycle;
377 ite_set_carrier_params(dev);
378 spin_unlock_irqrestore(&dev->lock, flags);
383 /* transmit out IR pulses; what you get here is a batch of alternating
384 * pulse/space/pulse/space lengths that we should write out completely through
385 * the FIFO, blocking on a full FIFO */
386 static int ite_tx_ir(struct rc_dev *rcdev, int *txbuf, u32 n)
389 struct ite_dev *dev = rcdev->priv;
390 bool is_pulse = false;
391 int remaining_us, fifo_avail, fifo_remaining, last_idx = 0;
392 int max_rle_us, next_rle_us;
394 u8 last_sent[ITE_TX_FIFO_LEN];
397 ite_dbg("%s called", __func__);
399 /* clear the array just in case */
400 memset(last_sent, 0, ARRAY_SIZE(last_sent));
402 /* n comes in bytes; convert to ints */
405 spin_lock_irqsave(&dev->lock, flags);
407 /* let everybody know we're now transmitting */
408 dev->transmitting = true;
410 /* and set the carrier values for transmission */
411 ite_set_carrier_params(dev);
413 /* calculate how much time we can send in one byte */
415 (ITE_BAUDRATE_DIVISOR * dev->params.sample_period *
416 ITE_TX_MAX_RLE) / 1000;
418 /* disable the receiver */
419 dev->params.disable_rx(dev);
421 /* this is where we'll begin filling in the FIFO, until it's full.
422 * then we'll just activate the interrupt, wait for it to wake us up
423 * again, disable it, continue filling the FIFO... until everything
424 * has been pushed out */
426 ITE_TX_FIFO_LEN - dev->params.get_tx_used_slots(dev);
428 while (n > 0 && dev->in_use) {
429 /* transmit the next sample */
430 is_pulse = !is_pulse;
431 remaining_us = *(txbuf++);
435 ((is_pulse) ? "pulse" : "space"),
439 /* repeat while the pulse is non-zero length */
440 while (remaining_us > 0 && dev->in_use) {
441 if (remaining_us > max_rle_us)
442 next_rle_us = max_rle_us;
445 next_rle_us = remaining_us;
447 remaining_us -= next_rle_us;
449 /* check what's the length we have to pump out */
450 val = (ITE_TX_MAX_RLE * next_rle_us) / max_rle_us;
452 /* put it into the sent buffer */
453 last_sent[last_idx++] = val;
454 last_idx &= (ITE_TX_FIFO_LEN);
456 /* encode it for 7 bits */
457 val = (val - 1) & ITE_TX_RLE_MASK;
459 /* take into account pulse/space prefix */
467 * if we get to 0 available, read again, just in case
468 * some other slot got freed
471 fifo_avail = ITE_TX_FIFO_LEN - dev->params.get_tx_used_slots(dev);
473 /* if it's still full */
474 if (fifo_avail <= 0) {
475 /* enable the tx interrupt */
477 enable_tx_interrupt(dev);
479 /* drop the spinlock */
480 spin_unlock_irqrestore(&dev->lock, flags);
482 /* wait for the FIFO to empty enough */
483 wait_event_interruptible(dev->tx_queue, (fifo_avail = ITE_TX_FIFO_LEN - dev->params.get_tx_used_slots(dev)) >= 8);
485 /* get the spinlock again */
486 spin_lock_irqsave(&dev->lock, flags);
488 /* disable the tx interrupt again. */
490 disable_tx_interrupt(dev);
493 /* now send the byte through the FIFO */
494 dev->params.put_tx_byte(dev, val);
499 /* wait and don't return until the whole FIFO has been sent out;
500 * otherwise we could configure the RX carrier params instead of the
501 * TX ones while the transmission is still being performed! */
502 fifo_remaining = dev->params.get_tx_used_slots(dev);
504 while (fifo_remaining > 0) {
507 last_idx &= (ITE_TX_FIFO_LEN - 1);
508 remaining_us += last_sent[last_idx];
510 remaining_us = (remaining_us * max_rle_us) / (ITE_TX_MAX_RLE);
512 /* drop the spinlock while we sleep */
513 spin_unlock_irqrestore(&dev->lock, flags);
515 /* sleep remaining_us microseconds */
516 mdelay(DIV_ROUND_UP(remaining_us, 1000));
518 /* reacquire the spinlock */
519 spin_lock_irqsave(&dev->lock, flags);
521 /* now we're not transmitting anymore */
522 dev->transmitting = false;
524 /* and set the carrier values for reception */
525 ite_set_carrier_params(dev);
527 /* reenable the receiver */
529 dev->params.enable_rx(dev);
531 /* notify transmission end */
532 wake_up_interruptible(&dev->tx_ended);
534 spin_unlock_irqrestore(&dev->lock, flags);
539 /* idle the receiver if needed */
540 static void ite_s_idle(struct rc_dev *rcdev, bool enable)
543 struct ite_dev *dev = rcdev->priv;
545 ite_dbg("%s called", __func__);
548 spin_lock_irqsave(&dev->lock, flags);
549 dev->params.idle_rx(dev);
550 spin_unlock_irqrestore(&dev->lock, flags);
555 /* IT8712F HW-specific functions */
557 /* retrieve a bitmask of the current causes for a pending interrupt; this may
558 * be composed of ITE_IRQ_TX_FIFO, ITE_IRQ_RX_FIFO and ITE_IRQ_RX_FIFO_OVERRUN
560 static int it87_get_irq_causes(struct ite_dev *dev)
565 ite_dbg("%s called", __func__);
567 /* read the interrupt flags */
568 iflags = inb(dev->cir_addr + IT87_IIR) & IT87_II;
572 ret = ITE_IRQ_RX_FIFO;
575 ret = ITE_IRQ_RX_FIFO_OVERRUN;
578 ret = ITE_IRQ_TX_FIFO;
585 /* set the carrier parameters; to be called with the spinlock held */
586 static void it87_set_carrier_params(struct ite_dev *dev, bool high_freq,
587 bool use_demodulator,
588 u8 carrier_freq_bits, u8 allowance_bits,
593 ite_dbg("%s called", __func__);
595 /* program the RCR register */
596 val = inb(dev->cir_addr + IT87_RCR)
597 & ~(IT87_HCFS | IT87_RXEND | IT87_RXDCR);
605 val |= allowance_bits;
607 outb(val, dev->cir_addr + IT87_RCR);
609 /* program the TCR2 register */
610 outb((carrier_freq_bits << IT87_CFQ_SHIFT) | pulse_width_bits,
611 dev->cir_addr + IT87_TCR2);
614 /* read up to buf_size bytes from the RX FIFO; to be called with the spinlock
616 static int it87_get_rx_bytes(struct ite_dev *dev, u8 * buf, int buf_size)
620 ite_dbg("%s called", __func__);
622 /* read how many bytes are still in the FIFO */
623 fifo = inb(dev->cir_addr + IT87_RSR) & IT87_RXFBC;
625 while (fifo > 0 && buf_size > 0) {
626 *(buf++) = inb(dev->cir_addr + IT87_DR);
635 /* return how many bytes are still in the FIFO; this will be called
636 * with the device spinlock NOT HELD while waiting for the TX FIFO to get
637 * empty; let's expect this won't be a problem */
638 static int it87_get_tx_used_slots(struct ite_dev *dev)
640 ite_dbg("%s called", __func__);
642 return inb(dev->cir_addr + IT87_TSR) & IT87_TXFBC;
645 /* put a byte to the TX fifo; this should be called with the spinlock held */
646 static void it87_put_tx_byte(struct ite_dev *dev, u8 value)
648 outb(value, dev->cir_addr + IT87_DR);
651 /* idle the receiver so that we won't receive samples until another
652 pulse is detected; this must be called with the device spinlock held */
653 static void it87_idle_rx(struct ite_dev *dev)
655 ite_dbg("%s called", __func__);
657 /* disable streaming by clearing RXACT writing it as 1 */
658 outb(inb(dev->cir_addr + IT87_RCR) | IT87_RXACT,
659 dev->cir_addr + IT87_RCR);
662 outb(inb(dev->cir_addr + IT87_TCR1) | IT87_FIFOCLR,
663 dev->cir_addr + IT87_TCR1);
666 /* disable the receiver; this must be called with the device spinlock held */
667 static void it87_disable_rx(struct ite_dev *dev)
669 ite_dbg("%s called", __func__);
671 /* disable the receiver interrupts */
672 outb(inb(dev->cir_addr + IT87_IER) & ~(IT87_RDAIE | IT87_RFOIE),
673 dev->cir_addr + IT87_IER);
675 /* disable the receiver */
676 outb(inb(dev->cir_addr + IT87_RCR) & ~IT87_RXEN,
677 dev->cir_addr + IT87_RCR);
679 /* clear the FIFO and RXACT (actually RXACT should have been cleared
680 * in the previous outb() call) */
684 /* enable the receiver; this must be called with the device spinlock held */
685 static void it87_enable_rx(struct ite_dev *dev)
687 ite_dbg("%s called", __func__);
689 /* enable the receiver by setting RXEN */
690 outb(inb(dev->cir_addr + IT87_RCR) | IT87_RXEN,
691 dev->cir_addr + IT87_RCR);
693 /* just prepare it to idle for the next reception */
696 /* enable the receiver interrupts and master enable flag */
697 outb(inb(dev->cir_addr + IT87_IER) | IT87_RDAIE | IT87_RFOIE | IT87_IEC,
698 dev->cir_addr + IT87_IER);
701 /* disable the transmitter interrupt; this must be called with the device
703 static void it87_disable_tx_interrupt(struct ite_dev *dev)
705 ite_dbg("%s called", __func__);
707 /* disable the transmitter interrupts */
708 outb(inb(dev->cir_addr + IT87_IER) & ~IT87_TLDLIE,
709 dev->cir_addr + IT87_IER);
712 /* enable the transmitter interrupt; this must be called with the device
714 static void it87_enable_tx_interrupt(struct ite_dev *dev)
716 ite_dbg("%s called", __func__);
718 /* enable the transmitter interrupts and master enable flag */
719 outb(inb(dev->cir_addr + IT87_IER) | IT87_TLDLIE | IT87_IEC,
720 dev->cir_addr + IT87_IER);
723 /* disable the device; this must be called with the device spinlock held */
724 static void it87_disable(struct ite_dev *dev)
726 ite_dbg("%s called", __func__);
728 /* clear out all interrupt enable flags */
729 outb(inb(dev->cir_addr + IT87_IER) &
730 ~(IT87_IEC | IT87_RFOIE | IT87_RDAIE | IT87_TLDLIE),
731 dev->cir_addr + IT87_IER);
733 /* disable the receiver */
734 it87_disable_rx(dev);
737 outb(IT87_FIFOCLR | inb(dev->cir_addr + IT87_TCR1),
738 dev->cir_addr + IT87_TCR1);
741 /* initialize the hardware */
742 static void it87_init_hardware(struct ite_dev *dev)
744 ite_dbg("%s called", __func__);
746 /* enable just the baud rate divisor register,
747 disabling all the interrupts at the same time */
748 outb((inb(dev->cir_addr + IT87_IER) &
749 ~(IT87_IEC | IT87_RFOIE | IT87_RDAIE | IT87_TLDLIE)) | IT87_BR,
750 dev->cir_addr + IT87_IER);
752 /* write out the baud rate divisor */
753 outb(ITE_BAUDRATE_DIVISOR & 0xff, dev->cir_addr + IT87_BDLR);
754 outb((ITE_BAUDRATE_DIVISOR >> 8) & 0xff, dev->cir_addr + IT87_BDHR);
756 /* disable the baud rate divisor register again */
757 outb(inb(dev->cir_addr + IT87_IER) & ~IT87_BR,
758 dev->cir_addr + IT87_IER);
760 /* program the RCR register defaults */
761 outb(ITE_RXDCR_DEFAULT, dev->cir_addr + IT87_RCR);
763 /* program the TCR1 register */
764 outb(IT87_TXMPM_DEFAULT | IT87_TXENDF | IT87_TXRLE
765 | IT87_FIFOTL_DEFAULT | IT87_FIFOCLR,
766 dev->cir_addr + IT87_TCR1);
768 /* program the carrier parameters */
769 ite_set_carrier_params(dev);
772 /* IT8512F on ITE8708 HW-specific functions */
774 /* retrieve a bitmask of the current causes for a pending interrupt; this may
775 * be composed of ITE_IRQ_TX_FIFO, ITE_IRQ_RX_FIFO and ITE_IRQ_RX_FIFO_OVERRUN
777 static int it8708_get_irq_causes(struct ite_dev *dev)
782 ite_dbg("%s called", __func__);
784 /* read the interrupt flags */
785 iflags = inb(dev->cir_addr + IT8708_C0IIR);
787 if (iflags & IT85_TLDLI)
788 ret |= ITE_IRQ_TX_FIFO;
789 if (iflags & IT85_RDAI)
790 ret |= ITE_IRQ_RX_FIFO;
791 if (iflags & IT85_RFOI)
792 ret |= ITE_IRQ_RX_FIFO_OVERRUN;
797 /* set the carrier parameters; to be called with the spinlock held */
798 static void it8708_set_carrier_params(struct ite_dev *dev, bool high_freq,
799 bool use_demodulator,
800 u8 carrier_freq_bits, u8 allowance_bits,
805 ite_dbg("%s called", __func__);
807 /* program the C0CFR register, with HRAE=1 */
808 outb(inb(dev->cir_addr + IT8708_BANKSEL) | IT8708_HRAE,
809 dev->cir_addr + IT8708_BANKSEL);
811 val = (inb(dev->cir_addr + IT8708_C0CFR)
812 & ~(IT85_HCFS | IT85_CFQ)) | carrier_freq_bits;
817 outb(val, dev->cir_addr + IT8708_C0CFR);
819 outb(inb(dev->cir_addr + IT8708_BANKSEL) & ~IT8708_HRAE,
820 dev->cir_addr + IT8708_BANKSEL);
822 /* program the C0RCR register */
823 val = inb(dev->cir_addr + IT8708_C0RCR)
824 & ~(IT85_RXEND | IT85_RXDCR);
829 val |= allowance_bits;
831 outb(val, dev->cir_addr + IT8708_C0RCR);
833 /* program the C0TCR register */
834 val = inb(dev->cir_addr + IT8708_C0TCR) & ~IT85_TXMPW;
835 val |= pulse_width_bits;
836 outb(val, dev->cir_addr + IT8708_C0TCR);
839 /* read up to buf_size bytes from the RX FIFO; to be called with the spinlock
841 static int it8708_get_rx_bytes(struct ite_dev *dev, u8 * buf, int buf_size)
845 ite_dbg("%s called", __func__);
847 /* read how many bytes are still in the FIFO */
848 fifo = inb(dev->cir_addr + IT8708_C0RFSR) & IT85_RXFBC;
850 while (fifo > 0 && buf_size > 0) {
851 *(buf++) = inb(dev->cir_addr + IT8708_C0DR);
860 /* return how many bytes are still in the FIFO; this will be called
861 * with the device spinlock NOT HELD while waiting for the TX FIFO to get
862 * empty; let's expect this won't be a problem */
863 static int it8708_get_tx_used_slots(struct ite_dev *dev)
865 ite_dbg("%s called", __func__);
867 return inb(dev->cir_addr + IT8708_C0TFSR) & IT85_TXFBC;
870 /* put a byte to the TX fifo; this should be called with the spinlock held */
871 static void it8708_put_tx_byte(struct ite_dev *dev, u8 value)
873 outb(value, dev->cir_addr + IT8708_C0DR);
876 /* idle the receiver so that we won't receive samples until another
877 pulse is detected; this must be called with the device spinlock held */
878 static void it8708_idle_rx(struct ite_dev *dev)
880 ite_dbg("%s called", __func__);
882 /* disable streaming by clearing RXACT writing it as 1 */
883 outb(inb(dev->cir_addr + IT8708_C0RCR) | IT85_RXACT,
884 dev->cir_addr + IT8708_C0RCR);
887 outb(inb(dev->cir_addr + IT8708_C0MSTCR) | IT85_FIFOCLR,
888 dev->cir_addr + IT8708_C0MSTCR);
891 /* disable the receiver; this must be called with the device spinlock held */
892 static void it8708_disable_rx(struct ite_dev *dev)
894 ite_dbg("%s called", __func__);
896 /* disable the receiver interrupts */
897 outb(inb(dev->cir_addr + IT8708_C0IER) &
898 ~(IT85_RDAIE | IT85_RFOIE),
899 dev->cir_addr + IT8708_C0IER);
901 /* disable the receiver */
902 outb(inb(dev->cir_addr + IT8708_C0RCR) & ~IT85_RXEN,
903 dev->cir_addr + IT8708_C0RCR);
905 /* clear the FIFO and RXACT (actually RXACT should have been cleared
906 * in the previous outb() call) */
910 /* enable the receiver; this must be called with the device spinlock held */
911 static void it8708_enable_rx(struct ite_dev *dev)
913 ite_dbg("%s called", __func__);
915 /* enable the receiver by setting RXEN */
916 outb(inb(dev->cir_addr + IT8708_C0RCR) | IT85_RXEN,
917 dev->cir_addr + IT8708_C0RCR);
919 /* just prepare it to idle for the next reception */
922 /* enable the receiver interrupts and master enable flag */
923 outb(inb(dev->cir_addr + IT8708_C0IER)
924 |IT85_RDAIE | IT85_RFOIE | IT85_IEC,
925 dev->cir_addr + IT8708_C0IER);
928 /* disable the transmitter interrupt; this must be called with the device
930 static void it8708_disable_tx_interrupt(struct ite_dev *dev)
932 ite_dbg("%s called", __func__);
934 /* disable the transmitter interrupts */
935 outb(inb(dev->cir_addr + IT8708_C0IER) & ~IT85_TLDLIE,
936 dev->cir_addr + IT8708_C0IER);
939 /* enable the transmitter interrupt; this must be called with the device
941 static void it8708_enable_tx_interrupt(struct ite_dev *dev)
943 ite_dbg("%s called", __func__);
945 /* enable the transmitter interrupts and master enable flag */
946 outb(inb(dev->cir_addr + IT8708_C0IER)
947 |IT85_TLDLIE | IT85_IEC,
948 dev->cir_addr + IT8708_C0IER);
951 /* disable the device; this must be called with the device spinlock held */
952 static void it8708_disable(struct ite_dev *dev)
954 ite_dbg("%s called", __func__);
956 /* clear out all interrupt enable flags */
957 outb(inb(dev->cir_addr + IT8708_C0IER) &
958 ~(IT85_IEC | IT85_RFOIE | IT85_RDAIE | IT85_TLDLIE),
959 dev->cir_addr + IT8708_C0IER);
961 /* disable the receiver */
962 it8708_disable_rx(dev);
965 outb(IT85_FIFOCLR | inb(dev->cir_addr + IT8708_C0MSTCR),
966 dev->cir_addr + IT8708_C0MSTCR);
969 /* initialize the hardware */
970 static void it8708_init_hardware(struct ite_dev *dev)
972 ite_dbg("%s called", __func__);
974 /* disable all the interrupts */
975 outb(inb(dev->cir_addr + IT8708_C0IER) &
976 ~(IT85_IEC | IT85_RFOIE | IT85_RDAIE | IT85_TLDLIE),
977 dev->cir_addr + IT8708_C0IER);
979 /* program the baud rate divisor */
980 outb(inb(dev->cir_addr + IT8708_BANKSEL) | IT8708_HRAE,
981 dev->cir_addr + IT8708_BANKSEL);
983 outb(ITE_BAUDRATE_DIVISOR & 0xff, dev->cir_addr + IT8708_C0BDLR);
984 outb((ITE_BAUDRATE_DIVISOR >> 8) & 0xff,
985 dev->cir_addr + IT8708_C0BDHR);
987 outb(inb(dev->cir_addr + IT8708_BANKSEL) & ~IT8708_HRAE,
988 dev->cir_addr + IT8708_BANKSEL);
990 /* program the C0MSTCR register defaults */
991 outb((inb(dev->cir_addr + IT8708_C0MSTCR) &
992 ~(IT85_ILSEL | IT85_ILE | IT85_FIFOTL |
993 IT85_FIFOCLR | IT85_RESET)) |
995 dev->cir_addr + IT8708_C0MSTCR);
997 /* program the C0RCR register defaults */
998 outb((inb(dev->cir_addr + IT8708_C0RCR) &
999 ~(IT85_RXEN | IT85_RDWOS | IT85_RXEND |
1000 IT85_RXACT | IT85_RXDCR)) |
1002 dev->cir_addr + IT8708_C0RCR);
1004 /* program the C0TCR register defaults */
1005 outb((inb(dev->cir_addr + IT8708_C0TCR) &
1006 ~(IT85_TXMPM | IT85_TXMPW))
1007 |IT85_TXRLE | IT85_TXENDF |
1008 IT85_TXMPM_DEFAULT | IT85_TXMPW_DEFAULT,
1009 dev->cir_addr + IT8708_C0TCR);
1011 /* program the carrier parameters */
1012 ite_set_carrier_params(dev);
1015 /* IT8512F on ITE8709 HW-specific functions */
1017 /* read a byte from the SRAM module */
1018 static inline u8 it8709_rm(struct ite_dev *dev, int index)
1020 outb(index, dev->cir_addr + IT8709_RAM_IDX);
1021 return inb(dev->cir_addr + IT8709_RAM_VAL);
1024 /* write a byte to the SRAM module */
1025 static inline void it8709_wm(struct ite_dev *dev, u8 val, int index)
1027 outb(index, dev->cir_addr + IT8709_RAM_IDX);
1028 outb(val, dev->cir_addr + IT8709_RAM_VAL);
1031 static void it8709_wait(struct ite_dev *dev)
1035 * loop until device tells it's ready to continue
1036 * iterations count is usually ~750 but can sometimes achieve 13000
1038 for (i = 0; i < 15000; i++) {
1040 if (it8709_rm(dev, IT8709_MODE) == IT8709_IDLE)
1045 /* read the value of a CIR register */
1046 static u8 it8709_rr(struct ite_dev *dev, int index)
1048 /* just wait in case the previous access was a write */
1050 it8709_wm(dev, index, IT8709_REG_IDX);
1051 it8709_wm(dev, IT8709_READ, IT8709_MODE);
1053 /* wait for the read data to be available */
1056 /* return the read value */
1057 return it8709_rm(dev, IT8709_REG_VAL);
1060 /* write the value of a CIR register */
1061 static void it8709_wr(struct ite_dev *dev, u8 val, int index)
1063 /* we wait before writing, and not afterwards, since this allows us to
1064 * pipeline the host CPU with the microcontroller */
1066 it8709_wm(dev, val, IT8709_REG_VAL);
1067 it8709_wm(dev, index, IT8709_REG_IDX);
1068 it8709_wm(dev, IT8709_WRITE, IT8709_MODE);
1071 /* retrieve a bitmask of the current causes for a pending interrupt; this may
1072 * be composed of ITE_IRQ_TX_FIFO, ITE_IRQ_RX_FIFO and ITE_IRQ_RX_FIFO_OVERRUN
1074 static int it8709_get_irq_causes(struct ite_dev *dev)
1079 ite_dbg("%s called", __func__);
1081 /* read the interrupt flags */
1082 iflags = it8709_rm(dev, IT8709_IIR);
1084 if (iflags & IT85_TLDLI)
1085 ret |= ITE_IRQ_TX_FIFO;
1086 if (iflags & IT85_RDAI)
1087 ret |= ITE_IRQ_RX_FIFO;
1088 if (iflags & IT85_RFOI)
1089 ret |= ITE_IRQ_RX_FIFO_OVERRUN;
1094 /* set the carrier parameters; to be called with the spinlock held */
1095 static void it8709_set_carrier_params(struct ite_dev *dev, bool high_freq,
1096 bool use_demodulator,
1097 u8 carrier_freq_bits, u8 allowance_bits,
1098 u8 pulse_width_bits)
1102 ite_dbg("%s called", __func__);
1104 val = (it8709_rr(dev, IT85_C0CFR)
1105 &~(IT85_HCFS | IT85_CFQ)) |
1111 it8709_wr(dev, val, IT85_C0CFR);
1113 /* program the C0RCR register */
1114 val = it8709_rr(dev, IT85_C0RCR)
1115 & ~(IT85_RXEND | IT85_RXDCR);
1117 if (use_demodulator)
1120 val |= allowance_bits;
1122 it8709_wr(dev, val, IT85_C0RCR);
1124 /* program the C0TCR register */
1125 val = it8709_rr(dev, IT85_C0TCR) & ~IT85_TXMPW;
1126 val |= pulse_width_bits;
1127 it8709_wr(dev, val, IT85_C0TCR);
1130 /* read up to buf_size bytes from the RX FIFO; to be called with the spinlock
1132 static int it8709_get_rx_bytes(struct ite_dev *dev, u8 * buf, int buf_size)
1136 ite_dbg("%s called", __func__);
1138 /* read how many bytes are still in the FIFO */
1139 fifo = it8709_rm(dev, IT8709_RFSR) & IT85_RXFBC;
1141 while (fifo > 0 && buf_size > 0) {
1142 *(buf++) = it8709_rm(dev, IT8709_FIFO + read);
1148 /* 'clear' the FIFO by setting the writing index to 0; this is
1149 * completely bound to be racy, but we can't help it, since it's a
1150 * limitation of the protocol */
1151 it8709_wm(dev, 0, IT8709_RFSR);
1156 /* return how many bytes are still in the FIFO; this will be called
1157 * with the device spinlock NOT HELD while waiting for the TX FIFO to get
1158 * empty; let's expect this won't be a problem */
1159 static int it8709_get_tx_used_slots(struct ite_dev *dev)
1161 ite_dbg("%s called", __func__);
1163 return it8709_rr(dev, IT85_C0TFSR) & IT85_TXFBC;
1166 /* put a byte to the TX fifo; this should be called with the spinlock held */
1167 static void it8709_put_tx_byte(struct ite_dev *dev, u8 value)
1169 it8709_wr(dev, value, IT85_C0DR);
1172 /* idle the receiver so that we won't receive samples until another
1173 pulse is detected; this must be called with the device spinlock held */
1174 static void it8709_idle_rx(struct ite_dev *dev)
1176 ite_dbg("%s called", __func__);
1178 /* disable streaming by clearing RXACT writing it as 1 */
1179 it8709_wr(dev, it8709_rr(dev, IT85_C0RCR) | IT85_RXACT,
1182 /* clear the FIFO */
1183 it8709_wr(dev, it8709_rr(dev, IT85_C0MSTCR) | IT85_FIFOCLR,
1187 /* disable the receiver; this must be called with the device spinlock held */
1188 static void it8709_disable_rx(struct ite_dev *dev)
1190 ite_dbg("%s called", __func__);
1192 /* disable the receiver interrupts */
1193 it8709_wr(dev, it8709_rr(dev, IT85_C0IER) &
1194 ~(IT85_RDAIE | IT85_RFOIE),
1197 /* disable the receiver */
1198 it8709_wr(dev, it8709_rr(dev, IT85_C0RCR) & ~IT85_RXEN,
1201 /* clear the FIFO and RXACT (actually RXACT should have been cleared
1202 * in the previous it8709_wr(dev, ) call) */
1203 it8709_idle_rx(dev);
1206 /* enable the receiver; this must be called with the device spinlock held */
1207 static void it8709_enable_rx(struct ite_dev *dev)
1209 ite_dbg("%s called", __func__);
1211 /* enable the receiver by setting RXEN */
1212 it8709_wr(dev, it8709_rr(dev, IT85_C0RCR) | IT85_RXEN,
1215 /* just prepare it to idle for the next reception */
1216 it8709_idle_rx(dev);
1218 /* enable the receiver interrupts and master enable flag */
1219 it8709_wr(dev, it8709_rr(dev, IT85_C0IER)
1220 |IT85_RDAIE | IT85_RFOIE | IT85_IEC,
1224 /* disable the transmitter interrupt; this must be called with the device
1226 static void it8709_disable_tx_interrupt(struct ite_dev *dev)
1228 ite_dbg("%s called", __func__);
1230 /* disable the transmitter interrupts */
1231 it8709_wr(dev, it8709_rr(dev, IT85_C0IER) & ~IT85_TLDLIE,
1235 /* enable the transmitter interrupt; this must be called with the device
1237 static void it8709_enable_tx_interrupt(struct ite_dev *dev)
1239 ite_dbg("%s called", __func__);
1241 /* enable the transmitter interrupts and master enable flag */
1242 it8709_wr(dev, it8709_rr(dev, IT85_C0IER)
1243 |IT85_TLDLIE | IT85_IEC,
1247 /* disable the device; this must be called with the device spinlock held */
1248 static void it8709_disable(struct ite_dev *dev)
1250 ite_dbg("%s called", __func__);
1252 /* clear out all interrupt enable flags */
1255 IT85_C0IER) & ~(IT85_IEC | IT85_RFOIE |
1257 IT85_TLDLIE), IT85_C0IER);
1259 /* disable the receiver */
1260 it8709_disable_rx(dev);
1262 /* erase the FIFO */
1263 it8709_wr(dev, IT85_FIFOCLR | it8709_rr(dev, IT85_C0MSTCR),
1267 /* initialize the hardware */
1268 static void it8709_init_hardware(struct ite_dev *dev)
1270 ite_dbg("%s called", __func__);
1272 /* disable all the interrupts */
1275 IT85_C0IER) & ~(IT85_IEC | IT85_RFOIE |
1277 IT85_TLDLIE), IT85_C0IER);
1279 /* program the baud rate divisor */
1280 it8709_wr(dev, ITE_BAUDRATE_DIVISOR & 0xff, IT85_C0BDLR);
1281 it8709_wr(dev, (ITE_BAUDRATE_DIVISOR >> 8) & 0xff,
1284 /* program the C0MSTCR register defaults */
1285 it8709_wr(dev, (it8709_rr(dev, IT85_C0MSTCR) & ~(IT85_ILSEL |
1292 | IT85_FIFOTL_DEFAULT, IT85_C0MSTCR);
1294 /* program the C0RCR register defaults */
1296 (it8709_rr(dev, IT85_C0RCR) &
1297 ~(IT85_RXEN | IT85_RDWOS | IT85_RXEND
1298 | IT85_RXACT | IT85_RXDCR)) |
1299 ITE_RXDCR_DEFAULT, IT85_C0RCR);
1301 /* program the C0TCR register defaults */
1302 it8709_wr(dev, (it8709_rr(dev, IT85_C0TCR)
1303 &~(IT85_TXMPM | IT85_TXMPW))
1304 |IT85_TXRLE | IT85_TXENDF |
1305 IT85_TXMPM_DEFAULT |
1306 IT85_TXMPW_DEFAULT, IT85_C0TCR);
1308 /* program the carrier parameters */
1309 ite_set_carrier_params(dev);
1313 /* generic hardware setup/teardown code */
1315 /* activate the device for use */
1316 static int ite_open(struct rc_dev *rcdev)
1318 struct ite_dev *dev = rcdev->priv;
1319 unsigned long flags;
1321 ite_dbg("%s called", __func__);
1323 spin_lock_irqsave(&dev->lock, flags);
1326 /* enable the receiver */
1327 dev->params.enable_rx(dev);
1329 spin_unlock_irqrestore(&dev->lock, flags);
1334 /* deactivate the device for use */
1335 static void ite_close(struct rc_dev *rcdev)
1337 struct ite_dev *dev = rcdev->priv;
1338 unsigned long flags;
1340 ite_dbg("%s called", __func__);
1342 spin_lock_irqsave(&dev->lock, flags);
1343 dev->in_use = false;
1345 /* wait for any transmission to end */
1346 spin_unlock_irqrestore(&dev->lock, flags);
1347 wait_event_interruptible(dev->tx_ended, !dev->transmitting);
1348 spin_lock_irqsave(&dev->lock, flags);
1350 dev->params.disable(dev);
1352 spin_unlock_irqrestore(&dev->lock, flags);
1355 /* supported models and their parameters */
1356 static const struct ite_dev_params ite_dev_descs[] = {
1358 .model = "ITE8704 CIR transceiver",
1359 .io_region_size = IT87_IOREG_LENGTH,
1360 .hw_tx_capable = true,
1361 .sample_period = (u32) (1000000000ULL / 115200),
1362 .tx_carrier_freq = 38000,
1363 .tx_duty_cycle = 33,
1364 .rx_low_carrier_freq = 0,
1365 .rx_high_carrier_freq = 0,
1368 .get_irq_causes = it87_get_irq_causes,
1369 .enable_rx = it87_enable_rx,
1370 .idle_rx = it87_idle_rx,
1371 .disable_rx = it87_idle_rx,
1372 .get_rx_bytes = it87_get_rx_bytes,
1373 .enable_tx_interrupt = it87_enable_tx_interrupt,
1374 .disable_tx_interrupt = it87_disable_tx_interrupt,
1375 .get_tx_used_slots = it87_get_tx_used_slots,
1376 .put_tx_byte = it87_put_tx_byte,
1377 .disable = it87_disable,
1378 .init_hardware = it87_init_hardware,
1379 .set_carrier_params = it87_set_carrier_params,
1382 .model = "ITE8713 CIR transceiver",
1383 .io_region_size = IT87_IOREG_LENGTH,
1384 .hw_tx_capable = true,
1385 .sample_period = (u32) (1000000000ULL / 115200),
1386 .tx_carrier_freq = 38000,
1387 .tx_duty_cycle = 33,
1388 .rx_low_carrier_freq = 0,
1389 .rx_high_carrier_freq = 0,
1392 .get_irq_causes = it87_get_irq_causes,
1393 .enable_rx = it87_enable_rx,
1394 .idle_rx = it87_idle_rx,
1395 .disable_rx = it87_idle_rx,
1396 .get_rx_bytes = it87_get_rx_bytes,
1397 .enable_tx_interrupt = it87_enable_tx_interrupt,
1398 .disable_tx_interrupt = it87_disable_tx_interrupt,
1399 .get_tx_used_slots = it87_get_tx_used_slots,
1400 .put_tx_byte = it87_put_tx_byte,
1401 .disable = it87_disable,
1402 .init_hardware = it87_init_hardware,
1403 .set_carrier_params = it87_set_carrier_params,
1406 .model = "ITE8708 CIR transceiver",
1407 .io_region_size = IT8708_IOREG_LENGTH,
1408 .hw_tx_capable = true,
1409 .sample_period = (u32) (1000000000ULL / 115200),
1410 .tx_carrier_freq = 38000,
1411 .tx_duty_cycle = 33,
1412 .rx_low_carrier_freq = 0,
1413 .rx_high_carrier_freq = 0,
1416 .get_irq_causes = it8708_get_irq_causes,
1417 .enable_rx = it8708_enable_rx,
1418 .idle_rx = it8708_idle_rx,
1419 .disable_rx = it8708_idle_rx,
1420 .get_rx_bytes = it8708_get_rx_bytes,
1421 .enable_tx_interrupt = it8708_enable_tx_interrupt,
1422 .disable_tx_interrupt =
1423 it8708_disable_tx_interrupt,
1424 .get_tx_used_slots = it8708_get_tx_used_slots,
1425 .put_tx_byte = it8708_put_tx_byte,
1426 .disable = it8708_disable,
1427 .init_hardware = it8708_init_hardware,
1428 .set_carrier_params = it8708_set_carrier_params,
1431 .model = "ITE8709 CIR transceiver",
1432 .io_region_size = IT8709_IOREG_LENGTH,
1433 .hw_tx_capable = true,
1434 .sample_period = (u32) (1000000000ULL / 115200),
1435 .tx_carrier_freq = 38000,
1436 .tx_duty_cycle = 33,
1437 .rx_low_carrier_freq = 0,
1438 .rx_high_carrier_freq = 0,
1441 .get_irq_causes = it8709_get_irq_causes,
1442 .enable_rx = it8709_enable_rx,
1443 .idle_rx = it8709_idle_rx,
1444 .disable_rx = it8709_idle_rx,
1445 .get_rx_bytes = it8709_get_rx_bytes,
1446 .enable_tx_interrupt = it8709_enable_tx_interrupt,
1447 .disable_tx_interrupt =
1448 it8709_disable_tx_interrupt,
1449 .get_tx_used_slots = it8709_get_tx_used_slots,
1450 .put_tx_byte = it8709_put_tx_byte,
1451 .disable = it8709_disable,
1452 .init_hardware = it8709_init_hardware,
1453 .set_carrier_params = it8709_set_carrier_params,
1457 static const struct pnp_device_id ite_ids[] = {
1458 {"ITE8704", 0}, /* Default model */
1459 {"ITE8713", 1}, /* CIR found in EEEBox 1501U */
1460 {"ITE8708", 2}, /* Bridged IT8512 */
1461 {"ITE8709", 3}, /* SRAM-Bridged IT8512 */
1465 /* allocate memory, probe hardware, and initialize everything */
1466 static int ite_probe(struct pnp_dev *pdev, const struct pnp_device_id
1469 const struct ite_dev_params *dev_desc = NULL;
1470 struct ite_dev *itdev = NULL;
1471 struct rc_dev *rdev = NULL;
1475 ite_dbg("%s called", __func__);
1477 itdev = kzalloc(sizeof(struct ite_dev), GFP_KERNEL);
1481 /* input device for IR remote (and tx) */
1482 rdev = rc_allocate_device();
1488 /* get the model number */
1489 model_no = (int)dev_id->driver_data;
1490 ite_pr(KERN_NOTICE, "Auto-detected model: %s\n",
1491 ite_dev_descs[model_no].model);
1493 if (model_number >= 0 && model_number < ARRAY_SIZE(ite_dev_descs)) {
1494 model_no = model_number;
1495 ite_pr(KERN_NOTICE, "The model has been fixed by a module "
1499 ite_pr(KERN_NOTICE, "Using model: %s\n", ite_dev_descs[model_no].model);
1501 /* get the description for the device */
1502 dev_desc = &ite_dev_descs[model_no];
1504 /* validate pnp resources */
1505 if (!pnp_port_valid(pdev, 0) ||
1506 pnp_port_len(pdev, 0) != dev_desc->io_region_size) {
1507 dev_err(&pdev->dev, "IR PNP Port not valid!\n");
1511 if (!pnp_irq_valid(pdev, 0)) {
1512 dev_err(&pdev->dev, "PNP IRQ not valid!\n");
1516 /* store resource values */
1517 itdev->cir_addr = pnp_port_start(pdev, 0);
1518 itdev->cir_irq = pnp_irq(pdev, 0);
1520 /* initialize spinlocks */
1521 spin_lock_init(&itdev->lock);
1523 /* initialize raw event */
1524 init_ir_raw_event(&itdev->rawir);
1527 /* now claim resources */
1528 if (!request_region(itdev->cir_addr,
1529 dev_desc->io_region_size, ITE_DRIVER_NAME))
1532 if (request_irq(itdev->cir_irq, ite_cir_isr, IRQF_SHARED,
1533 ITE_DRIVER_NAME, (void *)itdev))
1536 /* set driver data into the pnp device */
1537 pnp_set_drvdata(pdev, itdev);
1540 /* initialize waitqueues for transmission */
1541 init_waitqueue_head(&itdev->tx_queue);
1542 init_waitqueue_head(&itdev->tx_ended);
1544 /* copy model-specific parameters */
1545 itdev->params = *dev_desc;
1547 /* apply any overrides */
1548 if (sample_period > 0)
1549 itdev->params.sample_period = sample_period;
1551 if (tx_carrier_freq > 0)
1552 itdev->params.tx_carrier_freq = tx_carrier_freq;
1554 if (tx_duty_cycle > 0 && tx_duty_cycle <= 100)
1555 itdev->params.tx_duty_cycle = tx_duty_cycle;
1557 if (rx_low_carrier_freq > 0)
1558 itdev->params.rx_low_carrier_freq = rx_low_carrier_freq;
1560 if (rx_high_carrier_freq > 0)
1561 itdev->params.rx_high_carrier_freq = rx_high_carrier_freq;
1563 /* print out parameters */
1564 ite_pr(KERN_NOTICE, "TX-capable: %d\n", (int)
1565 itdev->params.hw_tx_capable);
1566 ite_pr(KERN_NOTICE, "Sample period (ns): %ld\n", (long)
1567 itdev->params.sample_period);
1568 ite_pr(KERN_NOTICE, "TX carrier frequency (Hz): %d\n", (int)
1569 itdev->params.tx_carrier_freq);
1570 ite_pr(KERN_NOTICE, "TX duty cycle (%%): %d\n", (int)
1571 itdev->params.tx_duty_cycle);
1572 ite_pr(KERN_NOTICE, "RX low carrier frequency (Hz): %d\n", (int)
1573 itdev->params.rx_low_carrier_freq);
1574 ite_pr(KERN_NOTICE, "RX high carrier frequency (Hz): %d\n", (int)
1575 itdev->params.rx_high_carrier_freq);
1577 /* set up hardware initial state */
1578 itdev->params.init_hardware(itdev);
1580 /* set up ir-core props */
1582 rdev->driver_type = RC_DRIVER_IR_RAW;
1583 rdev->allowed_protos = RC_TYPE_ALL;
1584 rdev->open = ite_open;
1585 rdev->close = ite_close;
1586 rdev->s_idle = ite_s_idle;
1587 rdev->s_rx_carrier_range = ite_set_rx_carrier_range;
1588 rdev->min_timeout = ITE_MIN_IDLE_TIMEOUT;
1589 rdev->max_timeout = ITE_MAX_IDLE_TIMEOUT;
1590 rdev->timeout = ITE_IDLE_TIMEOUT;
1591 rdev->rx_resolution = ITE_BAUDRATE_DIVISOR *
1592 itdev->params.sample_period;
1593 rdev->tx_resolution = ITE_BAUDRATE_DIVISOR *
1594 itdev->params.sample_period;
1596 /* set up transmitter related values if needed */
1597 if (itdev->params.hw_tx_capable) {
1598 rdev->tx_ir = ite_tx_ir;
1599 rdev->s_tx_carrier = ite_set_tx_carrier;
1600 rdev->s_tx_duty_cycle = ite_set_tx_duty_cycle;
1603 rdev->input_name = dev_desc->model;
1604 rdev->input_id.bustype = BUS_HOST;
1605 rdev->input_id.vendor = PCI_VENDOR_ID_ITE;
1606 rdev->input_id.product = 0;
1607 rdev->input_id.version = 0;
1608 rdev->driver_name = ITE_DRIVER_NAME;
1609 rdev->map_name = RC_MAP_RC6_MCE;
1611 ret = rc_register_device(rdev);
1616 ite_pr(KERN_NOTICE, "driver has been successfully loaded\n");
1622 free_irq(itdev->cir_irq, itdev);
1624 if (itdev->cir_addr)
1625 release_region(itdev->cir_addr, itdev->params.io_region_size);
1627 rc_free_device(rdev);
1633 static void __devexit ite_remove(struct pnp_dev *pdev)
1635 struct ite_dev *dev = pnp_get_drvdata(pdev);
1636 unsigned long flags;
1638 ite_dbg("%s called", __func__);
1640 spin_lock_irqsave(&dev->lock, flags);
1642 /* disable hardware */
1643 dev->params.disable(dev);
1645 spin_unlock_irqrestore(&dev->lock, flags);
1647 /* free resources */
1648 free_irq(dev->cir_irq, dev);
1649 release_region(dev->cir_addr, dev->params.io_region_size);
1651 rc_unregister_device(dev->rdev);
1656 static int ite_suspend(struct pnp_dev *pdev, pm_message_t state)
1658 struct ite_dev *dev = pnp_get_drvdata(pdev);
1659 unsigned long flags;
1661 ite_dbg("%s called", __func__);
1663 spin_lock_irqsave(&dev->lock, flags);
1665 /* disable all interrupts */
1666 dev->params.disable(dev);
1668 spin_unlock_irqrestore(&dev->lock, flags);
1673 static int ite_resume(struct pnp_dev *pdev)
1676 struct ite_dev *dev = pnp_get_drvdata(pdev);
1677 unsigned long flags;
1679 ite_dbg("%s called", __func__);
1681 spin_lock_irqsave(&dev->lock, flags);
1683 if (dev->transmitting) {
1684 /* wake up the transmitter */
1685 wake_up_interruptible(&dev->tx_queue);
1687 /* enable the receiver */
1688 dev->params.enable_rx(dev);
1691 spin_unlock_irqrestore(&dev->lock, flags);
1696 static void ite_shutdown(struct pnp_dev *pdev)
1698 struct ite_dev *dev = pnp_get_drvdata(pdev);
1699 unsigned long flags;
1701 ite_dbg("%s called", __func__);
1703 spin_lock_irqsave(&dev->lock, flags);
1705 /* disable all interrupts */
1706 dev->params.disable(dev);
1708 spin_unlock_irqrestore(&dev->lock, flags);
1711 static struct pnp_driver ite_driver = {
1712 .name = ITE_DRIVER_NAME,
1713 .id_table = ite_ids,
1715 .remove = __devexit_p(ite_remove),
1716 .suspend = ite_suspend,
1717 .resume = ite_resume,
1718 .shutdown = ite_shutdown,
1723 return pnp_register_driver(&ite_driver);
1728 pnp_unregister_driver(&ite_driver);
1731 MODULE_DEVICE_TABLE(pnp, ite_ids);
1732 MODULE_DESCRIPTION("ITE Tech Inc. IT8712F/ITE8512F CIR driver");
1734 MODULE_AUTHOR("Juan J. Garcia de Soria <skandalfo@gmail.com>");
1735 MODULE_LICENSE("GPL");
1737 module_init(ite_init);
1738 module_exit(ite_exit);