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 * Inspired by the original lirc_it87 and lirc_ite8709 drivers, on top of the
17 * skeleton provided by the nuvoton-cir driver.
19 * The lirc_it87 driver was originally written by Hans-Gunter Lutke Uphues
20 * <hg_lu@web.de> in 2001, with enhancements by Christoph Bartelmus
21 * <lirc@bartelmus.de>, Andrew Calkin <r_tay@hotmail.com> and James Edwards
22 * <jimbo-lirc@edwardsclan.net>.
24 * The lirc_ite8709 driver was written by Grégory Lardière
25 * <spmf2004-lirc@yahoo.fr> in 2008.
28 #include <linux/kernel.h>
29 #include <linux/module.h>
30 #include <linux/pnp.h>
32 #include <linux/interrupt.h>
33 #include <linux/sched.h>
34 #include <linux/delay.h>
35 #include <linux/slab.h>
36 #include <linux/input.h>
37 #include <linux/bitops.h>
38 #include <media/rc-core.h>
39 #include <linux/pci_ids.h>
43 /* module parameters */
47 module_param(debug, int, S_IRUGO | S_IWUSR);
48 MODULE_PARM_DESC(debug, "Enable debugging output");
50 /* low limit for RX carrier freq, Hz, 0 for no RX demodulation */
51 static int rx_low_carrier_freq;
52 module_param(rx_low_carrier_freq, int, S_IRUGO | S_IWUSR);
53 MODULE_PARM_DESC(rx_low_carrier_freq, "Override low RX carrier frequency, Hz, 0 for no RX demodulation");
55 /* high limit for RX carrier freq, Hz, 0 for no RX demodulation */
56 static int rx_high_carrier_freq;
57 module_param(rx_high_carrier_freq, int, S_IRUGO | S_IWUSR);
58 MODULE_PARM_DESC(rx_high_carrier_freq, "Override high RX carrier frequency, Hz, 0 for no RX demodulation");
60 /* override tx carrier frequency */
61 static int tx_carrier_freq;
62 module_param(tx_carrier_freq, int, S_IRUGO | S_IWUSR);
63 MODULE_PARM_DESC(tx_carrier_freq, "Override TX carrier frequency, Hz");
65 /* override tx duty cycle */
66 static int tx_duty_cycle;
67 module_param(tx_duty_cycle, int, S_IRUGO | S_IWUSR);
68 MODULE_PARM_DESC(tx_duty_cycle, "Override TX duty cycle, 1-100");
70 /* override default sample period */
71 static long sample_period;
72 module_param(sample_period, long, S_IRUGO | S_IWUSR);
73 MODULE_PARM_DESC(sample_period, "Override carrier sample period, us");
75 /* override detected model id */
76 static int model_number = -1;
77 module_param(model_number, int, S_IRUGO | S_IWUSR);
78 MODULE_PARM_DESC(model_number, "Use this model number, don't autodetect");
81 /* HW-independent code functions */
83 /* check whether carrier frequency is high frequency */
84 static inline bool ite_is_high_carrier_freq(unsigned int freq)
86 return freq >= ITE_HCF_MIN_CARRIER_FREQ;
89 /* get the bits required to program the carrier frequency in CFQ bits,
91 static u8 ite_get_carrier_freq_bits(unsigned int freq)
93 if (ite_is_high_carrier_freq(freq)) {
97 else if (freq < 465000)
100 else if (freq < 490000)
107 if (freq < ITE_LCF_MIN_CARRIER_FREQ)
108 freq = ITE_LCF_MIN_CARRIER_FREQ;
109 if (freq > ITE_LCF_MAX_CARRIER_FREQ)
110 freq = ITE_LCF_MAX_CARRIER_FREQ;
112 /* convert to kHz and subtract the base freq */
114 DIV_ROUND_CLOSEST(freq - ITE_LCF_MIN_CARRIER_FREQ,
121 /* get the bits required to program the pulse with in TXMPW */
122 static u8 ite_get_pulse_width_bits(unsigned int freq, int duty_cycle)
124 unsigned long period_ns, on_ns;
126 /* sanitize freq into range */
127 if (freq < ITE_LCF_MIN_CARRIER_FREQ)
128 freq = ITE_LCF_MIN_CARRIER_FREQ;
129 if (freq > ITE_HCF_MAX_CARRIER_FREQ)
130 freq = ITE_HCF_MAX_CARRIER_FREQ;
132 period_ns = 1000000000UL / freq;
133 on_ns = period_ns * duty_cycle / 100;
135 if (ite_is_high_carrier_freq(freq)) {
139 else if (on_ns < 850)
142 else if (on_ns < 950)
145 else if (on_ns < 1080)
154 else if (on_ns < 7850)
157 else if (on_ns < 9650)
160 else if (on_ns < 11950)
168 /* decode raw bytes as received by the hardware, and push them to the ir-core
170 static void ite_decode_bytes(struct ite_dev *dev, const u8 * data, int
174 unsigned long *ldata;
175 unsigned int next_one, next_zero, size;
176 DEFINE_IR_RAW_EVENT(ev);
181 sample_period = dev->params.sample_period;
182 ldata = (unsigned long *)data;
184 next_one = find_next_bit_le(ldata, size, 0);
188 ITE_BITS_TO_NS(next_one, sample_period);
189 ir_raw_event_store_with_filter(dev->rdev, &ev);
192 while (next_one < size) {
193 next_zero = find_next_zero_bit_le(ldata, size, next_one + 1);
195 ev.duration = ITE_BITS_TO_NS(next_zero - next_one, sample_period);
196 ir_raw_event_store_with_filter(dev->rdev, &ev);
198 if (next_zero < size) {
200 find_next_bit_le(ldata,
205 ITE_BITS_TO_NS(next_one - next_zero,
207 ir_raw_event_store_with_filter
213 ir_raw_event_handle(dev->rdev);
215 ite_dbg_verbose("decoded %d bytes.", length);
218 /* set all the rx/tx carrier parameters; this must be called with the device
220 static void ite_set_carrier_params(struct ite_dev *dev)
222 unsigned int freq, low_freq, high_freq;
224 bool use_demodulator;
225 bool for_tx = dev->transmitting;
227 ite_dbg("%s called", __func__);
230 /* we don't need no stinking calculations */
231 freq = dev->params.tx_carrier_freq;
232 allowance = ITE_RXDCR_DEFAULT;
233 use_demodulator = false;
235 low_freq = dev->params.rx_low_carrier_freq;
236 high_freq = dev->params.rx_high_carrier_freq;
239 /* don't demodulate */
241 ITE_DEFAULT_CARRIER_FREQ;
242 allowance = ITE_RXDCR_DEFAULT;
243 use_demodulator = false;
245 /* calculate the middle freq */
246 freq = (low_freq + high_freq) / 2;
248 /* calculate the allowance */
250 DIV_ROUND_CLOSEST(10000 * (high_freq - low_freq),
251 ITE_RXDCR_PER_10000_STEP
252 * (high_freq + low_freq));
257 if (allowance > ITE_RXDCR_MAX)
258 allowance = ITE_RXDCR_MAX;
260 use_demodulator = true;
264 /* set the carrier parameters in a device-dependent way */
265 dev->params.set_carrier_params(dev, ite_is_high_carrier_freq(freq),
266 use_demodulator, ite_get_carrier_freq_bits(freq), allowance,
267 ite_get_pulse_width_bits(freq, dev->params.tx_duty_cycle));
270 /* interrupt service routine for incoming and outgoing CIR data */
271 static irqreturn_t ite_cir_isr(int irq, void *data)
273 struct ite_dev *dev = data;
275 irqreturn_t ret = IRQ_RETVAL(IRQ_NONE);
276 u8 rx_buf[ITE_RX_FIFO_LEN];
280 ite_dbg_verbose("%s firing", __func__);
282 /* grab the spinlock */
283 spin_lock_irqsave(&dev->lock, flags);
285 /* read the interrupt flags */
286 iflags = dev->params.get_irq_causes(dev);
288 /* Check for RX overflow */
289 if (iflags & ITE_IRQ_RX_FIFO_OVERRUN) {
290 dev_warn(&dev->rdev->dev, "receive overflow\n");
291 ir_raw_event_reset(dev->rdev);
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, unsigned *txbuf, unsigned 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 spin_lock_irqsave(&dev->lock, flags);
404 /* let everybody know we're now transmitting */
405 dev->transmitting = true;
407 /* and set the carrier values for transmission */
408 ite_set_carrier_params(dev);
410 /* calculate how much time we can send in one byte */
412 (ITE_BAUDRATE_DIVISOR * dev->params.sample_period *
413 ITE_TX_MAX_RLE) / 1000;
415 /* disable the receiver */
416 dev->params.disable_rx(dev);
418 /* this is where we'll begin filling in the FIFO, until it's full.
419 * then we'll just activate the interrupt, wait for it to wake us up
420 * again, disable it, continue filling the FIFO... until everything
421 * has been pushed out */
423 ITE_TX_FIFO_LEN - dev->params.get_tx_used_slots(dev);
425 while (n > 0 && dev->in_use) {
426 /* transmit the next sample */
427 is_pulse = !is_pulse;
428 remaining_us = *(txbuf++);
432 ((is_pulse) ? "pulse" : "space"),
436 /* repeat while the pulse is non-zero length */
437 while (remaining_us > 0 && dev->in_use) {
438 if (remaining_us > max_rle_us)
439 next_rle_us = max_rle_us;
442 next_rle_us = remaining_us;
444 remaining_us -= next_rle_us;
446 /* check what's the length we have to pump out */
447 val = (ITE_TX_MAX_RLE * next_rle_us) / max_rle_us;
449 /* put it into the sent buffer */
450 last_sent[last_idx++] = val;
451 last_idx &= (ITE_TX_FIFO_LEN);
453 /* encode it for 7 bits */
454 val = (val - 1) & ITE_TX_RLE_MASK;
456 /* take into account pulse/space prefix */
464 * if we get to 0 available, read again, just in case
465 * some other slot got freed
468 fifo_avail = ITE_TX_FIFO_LEN - dev->params.get_tx_used_slots(dev);
470 /* if it's still full */
471 if (fifo_avail <= 0) {
472 /* enable the tx interrupt */
474 enable_tx_interrupt(dev);
476 /* drop the spinlock */
477 spin_unlock_irqrestore(&dev->lock, flags);
479 /* wait for the FIFO to empty enough */
480 wait_event_interruptible(dev->tx_queue, (fifo_avail = ITE_TX_FIFO_LEN - dev->params.get_tx_used_slots(dev)) >= 8);
482 /* get the spinlock again */
483 spin_lock_irqsave(&dev->lock, flags);
485 /* disable the tx interrupt again. */
487 disable_tx_interrupt(dev);
490 /* now send the byte through the FIFO */
491 dev->params.put_tx_byte(dev, val);
496 /* wait and don't return until the whole FIFO has been sent out;
497 * otherwise we could configure the RX carrier params instead of the
498 * TX ones while the transmission is still being performed! */
499 fifo_remaining = dev->params.get_tx_used_slots(dev);
501 while (fifo_remaining > 0) {
504 last_idx &= (ITE_TX_FIFO_LEN - 1);
505 remaining_us += last_sent[last_idx];
507 remaining_us = (remaining_us * max_rle_us) / (ITE_TX_MAX_RLE);
509 /* drop the spinlock while we sleep */
510 spin_unlock_irqrestore(&dev->lock, flags);
512 /* sleep remaining_us microseconds */
513 mdelay(DIV_ROUND_UP(remaining_us, 1000));
515 /* reacquire the spinlock */
516 spin_lock_irqsave(&dev->lock, flags);
518 /* now we're not transmitting anymore */
519 dev->transmitting = false;
521 /* and set the carrier values for reception */
522 ite_set_carrier_params(dev);
524 /* reenable the receiver */
526 dev->params.enable_rx(dev);
528 /* notify transmission end */
529 wake_up_interruptible(&dev->tx_ended);
531 spin_unlock_irqrestore(&dev->lock, flags);
536 /* idle the receiver if needed */
537 static void ite_s_idle(struct rc_dev *rcdev, bool enable)
540 struct ite_dev *dev = rcdev->priv;
542 ite_dbg("%s called", __func__);
545 spin_lock_irqsave(&dev->lock, flags);
546 dev->params.idle_rx(dev);
547 spin_unlock_irqrestore(&dev->lock, flags);
552 /* IT8712F HW-specific functions */
554 /* retrieve a bitmask of the current causes for a pending interrupt; this may
555 * be composed of ITE_IRQ_TX_FIFO, ITE_IRQ_RX_FIFO and ITE_IRQ_RX_FIFO_OVERRUN
557 static int it87_get_irq_causes(struct ite_dev *dev)
562 ite_dbg("%s called", __func__);
564 /* read the interrupt flags */
565 iflags = inb(dev->cir_addr + IT87_IIR) & IT87_II;
569 ret = ITE_IRQ_RX_FIFO;
572 ret = ITE_IRQ_RX_FIFO_OVERRUN;
575 ret = ITE_IRQ_TX_FIFO;
582 /* set the carrier parameters; to be called with the spinlock held */
583 static void it87_set_carrier_params(struct ite_dev *dev, bool high_freq,
584 bool use_demodulator,
585 u8 carrier_freq_bits, u8 allowance_bits,
590 ite_dbg("%s called", __func__);
592 /* program the RCR register */
593 val = inb(dev->cir_addr + IT87_RCR)
594 & ~(IT87_HCFS | IT87_RXEND | IT87_RXDCR);
602 val |= allowance_bits;
604 outb(val, dev->cir_addr + IT87_RCR);
606 /* program the TCR2 register */
607 outb((carrier_freq_bits << IT87_CFQ_SHIFT) | pulse_width_bits,
608 dev->cir_addr + IT87_TCR2);
611 /* read up to buf_size bytes from the RX FIFO; to be called with the spinlock
613 static int it87_get_rx_bytes(struct ite_dev *dev, u8 * buf, int buf_size)
617 ite_dbg("%s called", __func__);
619 /* read how many bytes are still in the FIFO */
620 fifo = inb(dev->cir_addr + IT87_RSR) & IT87_RXFBC;
622 while (fifo > 0 && buf_size > 0) {
623 *(buf++) = inb(dev->cir_addr + IT87_DR);
632 /* return how many bytes are still in the FIFO; this will be called
633 * with the device spinlock NOT HELD while waiting for the TX FIFO to get
634 * empty; let's expect this won't be a problem */
635 static int it87_get_tx_used_slots(struct ite_dev *dev)
637 ite_dbg("%s called", __func__);
639 return inb(dev->cir_addr + IT87_TSR) & IT87_TXFBC;
642 /* put a byte to the TX fifo; this should be called with the spinlock held */
643 static void it87_put_tx_byte(struct ite_dev *dev, u8 value)
645 outb(value, dev->cir_addr + IT87_DR);
648 /* idle the receiver so that we won't receive samples until another
649 pulse is detected; this must be called with the device spinlock held */
650 static void it87_idle_rx(struct ite_dev *dev)
652 ite_dbg("%s called", __func__);
654 /* disable streaming by clearing RXACT writing it as 1 */
655 outb(inb(dev->cir_addr + IT87_RCR) | IT87_RXACT,
656 dev->cir_addr + IT87_RCR);
659 outb(inb(dev->cir_addr + IT87_TCR1) | IT87_FIFOCLR,
660 dev->cir_addr + IT87_TCR1);
663 /* disable the receiver; this must be called with the device spinlock held */
664 static void it87_disable_rx(struct ite_dev *dev)
666 ite_dbg("%s called", __func__);
668 /* disable the receiver interrupts */
669 outb(inb(dev->cir_addr + IT87_IER) & ~(IT87_RDAIE | IT87_RFOIE),
670 dev->cir_addr + IT87_IER);
672 /* disable the receiver */
673 outb(inb(dev->cir_addr + IT87_RCR) & ~IT87_RXEN,
674 dev->cir_addr + IT87_RCR);
676 /* clear the FIFO and RXACT (actually RXACT should have been cleared
677 * in the previous outb() call) */
681 /* enable the receiver; this must be called with the device spinlock held */
682 static void it87_enable_rx(struct ite_dev *dev)
684 ite_dbg("%s called", __func__);
686 /* enable the receiver by setting RXEN */
687 outb(inb(dev->cir_addr + IT87_RCR) | IT87_RXEN,
688 dev->cir_addr + IT87_RCR);
690 /* just prepare it to idle for the next reception */
693 /* enable the receiver interrupts and master enable flag */
694 outb(inb(dev->cir_addr + IT87_IER) | IT87_RDAIE | IT87_RFOIE | IT87_IEC,
695 dev->cir_addr + IT87_IER);
698 /* disable the transmitter interrupt; this must be called with the device
700 static void it87_disable_tx_interrupt(struct ite_dev *dev)
702 ite_dbg("%s called", __func__);
704 /* disable the transmitter interrupts */
705 outb(inb(dev->cir_addr + IT87_IER) & ~IT87_TLDLIE,
706 dev->cir_addr + IT87_IER);
709 /* enable the transmitter interrupt; this must be called with the device
711 static void it87_enable_tx_interrupt(struct ite_dev *dev)
713 ite_dbg("%s called", __func__);
715 /* enable the transmitter interrupts and master enable flag */
716 outb(inb(dev->cir_addr + IT87_IER) | IT87_TLDLIE | IT87_IEC,
717 dev->cir_addr + IT87_IER);
720 /* disable the device; this must be called with the device spinlock held */
721 static void it87_disable(struct ite_dev *dev)
723 ite_dbg("%s called", __func__);
725 /* clear out all interrupt enable flags */
726 outb(inb(dev->cir_addr + IT87_IER) &
727 ~(IT87_IEC | IT87_RFOIE | IT87_RDAIE | IT87_TLDLIE),
728 dev->cir_addr + IT87_IER);
730 /* disable the receiver */
731 it87_disable_rx(dev);
734 outb(IT87_FIFOCLR | inb(dev->cir_addr + IT87_TCR1),
735 dev->cir_addr + IT87_TCR1);
738 /* initialize the hardware */
739 static void it87_init_hardware(struct ite_dev *dev)
741 ite_dbg("%s called", __func__);
743 /* enable just the baud rate divisor register,
744 disabling all the interrupts at the same time */
745 outb((inb(dev->cir_addr + IT87_IER) &
746 ~(IT87_IEC | IT87_RFOIE | IT87_RDAIE | IT87_TLDLIE)) | IT87_BR,
747 dev->cir_addr + IT87_IER);
749 /* write out the baud rate divisor */
750 outb(ITE_BAUDRATE_DIVISOR & 0xff, dev->cir_addr + IT87_BDLR);
751 outb((ITE_BAUDRATE_DIVISOR >> 8) & 0xff, dev->cir_addr + IT87_BDHR);
753 /* disable the baud rate divisor register again */
754 outb(inb(dev->cir_addr + IT87_IER) & ~IT87_BR,
755 dev->cir_addr + IT87_IER);
757 /* program the RCR register defaults */
758 outb(ITE_RXDCR_DEFAULT, dev->cir_addr + IT87_RCR);
760 /* program the TCR1 register */
761 outb(IT87_TXMPM_DEFAULT | IT87_TXENDF | IT87_TXRLE
762 | IT87_FIFOTL_DEFAULT | IT87_FIFOCLR,
763 dev->cir_addr + IT87_TCR1);
765 /* program the carrier parameters */
766 ite_set_carrier_params(dev);
769 /* IT8512F on ITE8708 HW-specific functions */
771 /* retrieve a bitmask of the current causes for a pending interrupt; this may
772 * be composed of ITE_IRQ_TX_FIFO, ITE_IRQ_RX_FIFO and ITE_IRQ_RX_FIFO_OVERRUN
774 static int it8708_get_irq_causes(struct ite_dev *dev)
779 ite_dbg("%s called", __func__);
781 /* read the interrupt flags */
782 iflags = inb(dev->cir_addr + IT8708_C0IIR);
784 if (iflags & IT85_TLDLI)
785 ret |= ITE_IRQ_TX_FIFO;
786 if (iflags & IT85_RDAI)
787 ret |= ITE_IRQ_RX_FIFO;
788 if (iflags & IT85_RFOI)
789 ret |= ITE_IRQ_RX_FIFO_OVERRUN;
794 /* set the carrier parameters; to be called with the spinlock held */
795 static void it8708_set_carrier_params(struct ite_dev *dev, bool high_freq,
796 bool use_demodulator,
797 u8 carrier_freq_bits, u8 allowance_bits,
802 ite_dbg("%s called", __func__);
804 /* program the C0CFR register, with HRAE=1 */
805 outb(inb(dev->cir_addr + IT8708_BANKSEL) | IT8708_HRAE,
806 dev->cir_addr + IT8708_BANKSEL);
808 val = (inb(dev->cir_addr + IT8708_C0CFR)
809 & ~(IT85_HCFS | IT85_CFQ)) | carrier_freq_bits;
814 outb(val, dev->cir_addr + IT8708_C0CFR);
816 outb(inb(dev->cir_addr + IT8708_BANKSEL) & ~IT8708_HRAE,
817 dev->cir_addr + IT8708_BANKSEL);
819 /* program the C0RCR register */
820 val = inb(dev->cir_addr + IT8708_C0RCR)
821 & ~(IT85_RXEND | IT85_RXDCR);
826 val |= allowance_bits;
828 outb(val, dev->cir_addr + IT8708_C0RCR);
830 /* program the C0TCR register */
831 val = inb(dev->cir_addr + IT8708_C0TCR) & ~IT85_TXMPW;
832 val |= pulse_width_bits;
833 outb(val, dev->cir_addr + IT8708_C0TCR);
836 /* read up to buf_size bytes from the RX FIFO; to be called with the spinlock
838 static int it8708_get_rx_bytes(struct ite_dev *dev, u8 * buf, int buf_size)
842 ite_dbg("%s called", __func__);
844 /* read how many bytes are still in the FIFO */
845 fifo = inb(dev->cir_addr + IT8708_C0RFSR) & IT85_RXFBC;
847 while (fifo > 0 && buf_size > 0) {
848 *(buf++) = inb(dev->cir_addr + IT8708_C0DR);
857 /* return how many bytes are still in the FIFO; this will be called
858 * with the device spinlock NOT HELD while waiting for the TX FIFO to get
859 * empty; let's expect this won't be a problem */
860 static int it8708_get_tx_used_slots(struct ite_dev *dev)
862 ite_dbg("%s called", __func__);
864 return inb(dev->cir_addr + IT8708_C0TFSR) & IT85_TXFBC;
867 /* put a byte to the TX fifo; this should be called with the spinlock held */
868 static void it8708_put_tx_byte(struct ite_dev *dev, u8 value)
870 outb(value, dev->cir_addr + IT8708_C0DR);
873 /* idle the receiver so that we won't receive samples until another
874 pulse is detected; this must be called with the device spinlock held */
875 static void it8708_idle_rx(struct ite_dev *dev)
877 ite_dbg("%s called", __func__);
879 /* disable streaming by clearing RXACT writing it as 1 */
880 outb(inb(dev->cir_addr + IT8708_C0RCR) | IT85_RXACT,
881 dev->cir_addr + IT8708_C0RCR);
884 outb(inb(dev->cir_addr + IT8708_C0MSTCR) | IT85_FIFOCLR,
885 dev->cir_addr + IT8708_C0MSTCR);
888 /* disable the receiver; this must be called with the device spinlock held */
889 static void it8708_disable_rx(struct ite_dev *dev)
891 ite_dbg("%s called", __func__);
893 /* disable the receiver interrupts */
894 outb(inb(dev->cir_addr + IT8708_C0IER) &
895 ~(IT85_RDAIE | IT85_RFOIE),
896 dev->cir_addr + IT8708_C0IER);
898 /* disable the receiver */
899 outb(inb(dev->cir_addr + IT8708_C0RCR) & ~IT85_RXEN,
900 dev->cir_addr + IT8708_C0RCR);
902 /* clear the FIFO and RXACT (actually RXACT should have been cleared
903 * in the previous outb() call) */
907 /* enable the receiver; this must be called with the device spinlock held */
908 static void it8708_enable_rx(struct ite_dev *dev)
910 ite_dbg("%s called", __func__);
912 /* enable the receiver by setting RXEN */
913 outb(inb(dev->cir_addr + IT8708_C0RCR) | IT85_RXEN,
914 dev->cir_addr + IT8708_C0RCR);
916 /* just prepare it to idle for the next reception */
919 /* enable the receiver interrupts and master enable flag */
920 outb(inb(dev->cir_addr + IT8708_C0IER)
921 |IT85_RDAIE | IT85_RFOIE | IT85_IEC,
922 dev->cir_addr + IT8708_C0IER);
925 /* disable the transmitter interrupt; this must be called with the device
927 static void it8708_disable_tx_interrupt(struct ite_dev *dev)
929 ite_dbg("%s called", __func__);
931 /* disable the transmitter interrupts */
932 outb(inb(dev->cir_addr + IT8708_C0IER) & ~IT85_TLDLIE,
933 dev->cir_addr + IT8708_C0IER);
936 /* enable the transmitter interrupt; this must be called with the device
938 static void it8708_enable_tx_interrupt(struct ite_dev *dev)
940 ite_dbg("%s called", __func__);
942 /* enable the transmitter interrupts and master enable flag */
943 outb(inb(dev->cir_addr + IT8708_C0IER)
944 |IT85_TLDLIE | IT85_IEC,
945 dev->cir_addr + IT8708_C0IER);
948 /* disable the device; this must be called with the device spinlock held */
949 static void it8708_disable(struct ite_dev *dev)
951 ite_dbg("%s called", __func__);
953 /* clear out all interrupt enable flags */
954 outb(inb(dev->cir_addr + IT8708_C0IER) &
955 ~(IT85_IEC | IT85_RFOIE | IT85_RDAIE | IT85_TLDLIE),
956 dev->cir_addr + IT8708_C0IER);
958 /* disable the receiver */
959 it8708_disable_rx(dev);
962 outb(IT85_FIFOCLR | inb(dev->cir_addr + IT8708_C0MSTCR),
963 dev->cir_addr + IT8708_C0MSTCR);
966 /* initialize the hardware */
967 static void it8708_init_hardware(struct ite_dev *dev)
969 ite_dbg("%s called", __func__);
971 /* disable all the interrupts */
972 outb(inb(dev->cir_addr + IT8708_C0IER) &
973 ~(IT85_IEC | IT85_RFOIE | IT85_RDAIE | IT85_TLDLIE),
974 dev->cir_addr + IT8708_C0IER);
976 /* program the baud rate divisor */
977 outb(inb(dev->cir_addr + IT8708_BANKSEL) | IT8708_HRAE,
978 dev->cir_addr + IT8708_BANKSEL);
980 outb(ITE_BAUDRATE_DIVISOR & 0xff, dev->cir_addr + IT8708_C0BDLR);
981 outb((ITE_BAUDRATE_DIVISOR >> 8) & 0xff,
982 dev->cir_addr + IT8708_C0BDHR);
984 outb(inb(dev->cir_addr + IT8708_BANKSEL) & ~IT8708_HRAE,
985 dev->cir_addr + IT8708_BANKSEL);
987 /* program the C0MSTCR register defaults */
988 outb((inb(dev->cir_addr + IT8708_C0MSTCR) &
989 ~(IT85_ILSEL | IT85_ILE | IT85_FIFOTL |
990 IT85_FIFOCLR | IT85_RESET)) |
992 dev->cir_addr + IT8708_C0MSTCR);
994 /* program the C0RCR register defaults */
995 outb((inb(dev->cir_addr + IT8708_C0RCR) &
996 ~(IT85_RXEN | IT85_RDWOS | IT85_RXEND |
997 IT85_RXACT | IT85_RXDCR)) |
999 dev->cir_addr + IT8708_C0RCR);
1001 /* program the C0TCR register defaults */
1002 outb((inb(dev->cir_addr + IT8708_C0TCR) &
1003 ~(IT85_TXMPM | IT85_TXMPW))
1004 |IT85_TXRLE | IT85_TXENDF |
1005 IT85_TXMPM_DEFAULT | IT85_TXMPW_DEFAULT,
1006 dev->cir_addr + IT8708_C0TCR);
1008 /* program the carrier parameters */
1009 ite_set_carrier_params(dev);
1012 /* IT8512F on ITE8709 HW-specific functions */
1014 /* read a byte from the SRAM module */
1015 static inline u8 it8709_rm(struct ite_dev *dev, int index)
1017 outb(index, dev->cir_addr + IT8709_RAM_IDX);
1018 return inb(dev->cir_addr + IT8709_RAM_VAL);
1021 /* write a byte to the SRAM module */
1022 static inline void it8709_wm(struct ite_dev *dev, u8 val, int index)
1024 outb(index, dev->cir_addr + IT8709_RAM_IDX);
1025 outb(val, dev->cir_addr + IT8709_RAM_VAL);
1028 static void it8709_wait(struct ite_dev *dev)
1032 * loop until device tells it's ready to continue
1033 * iterations count is usually ~750 but can sometimes achieve 13000
1035 for (i = 0; i < 15000; i++) {
1037 if (it8709_rm(dev, IT8709_MODE) == IT8709_IDLE)
1042 /* read the value of a CIR register */
1043 static u8 it8709_rr(struct ite_dev *dev, int index)
1045 /* just wait in case the previous access was a write */
1047 it8709_wm(dev, index, IT8709_REG_IDX);
1048 it8709_wm(dev, IT8709_READ, IT8709_MODE);
1050 /* wait for the read data to be available */
1053 /* return the read value */
1054 return it8709_rm(dev, IT8709_REG_VAL);
1057 /* write the value of a CIR register */
1058 static void it8709_wr(struct ite_dev *dev, u8 val, int index)
1060 /* we wait before writing, and not afterwards, since this allows us to
1061 * pipeline the host CPU with the microcontroller */
1063 it8709_wm(dev, val, IT8709_REG_VAL);
1064 it8709_wm(dev, index, IT8709_REG_IDX);
1065 it8709_wm(dev, IT8709_WRITE, IT8709_MODE);
1068 /* retrieve a bitmask of the current causes for a pending interrupt; this may
1069 * be composed of ITE_IRQ_TX_FIFO, ITE_IRQ_RX_FIFO and ITE_IRQ_RX_FIFO_OVERRUN
1071 static int it8709_get_irq_causes(struct ite_dev *dev)
1076 ite_dbg("%s called", __func__);
1078 /* read the interrupt flags */
1079 iflags = it8709_rm(dev, IT8709_IIR);
1081 if (iflags & IT85_TLDLI)
1082 ret |= ITE_IRQ_TX_FIFO;
1083 if (iflags & IT85_RDAI)
1084 ret |= ITE_IRQ_RX_FIFO;
1085 if (iflags & IT85_RFOI)
1086 ret |= ITE_IRQ_RX_FIFO_OVERRUN;
1091 /* set the carrier parameters; to be called with the spinlock held */
1092 static void it8709_set_carrier_params(struct ite_dev *dev, bool high_freq,
1093 bool use_demodulator,
1094 u8 carrier_freq_bits, u8 allowance_bits,
1095 u8 pulse_width_bits)
1099 ite_dbg("%s called", __func__);
1101 val = (it8709_rr(dev, IT85_C0CFR)
1102 &~(IT85_HCFS | IT85_CFQ)) |
1108 it8709_wr(dev, val, IT85_C0CFR);
1110 /* program the C0RCR register */
1111 val = it8709_rr(dev, IT85_C0RCR)
1112 & ~(IT85_RXEND | IT85_RXDCR);
1114 if (use_demodulator)
1117 val |= allowance_bits;
1119 it8709_wr(dev, val, IT85_C0RCR);
1121 /* program the C0TCR register */
1122 val = it8709_rr(dev, IT85_C0TCR) & ~IT85_TXMPW;
1123 val |= pulse_width_bits;
1124 it8709_wr(dev, val, IT85_C0TCR);
1127 /* read up to buf_size bytes from the RX FIFO; to be called with the spinlock
1129 static int it8709_get_rx_bytes(struct ite_dev *dev, u8 * buf, int buf_size)
1133 ite_dbg("%s called", __func__);
1135 /* read how many bytes are still in the FIFO */
1136 fifo = it8709_rm(dev, IT8709_RFSR) & IT85_RXFBC;
1138 while (fifo > 0 && buf_size > 0) {
1139 *(buf++) = it8709_rm(dev, IT8709_FIFO + read);
1145 /* 'clear' the FIFO by setting the writing index to 0; this is
1146 * completely bound to be racy, but we can't help it, since it's a
1147 * limitation of the protocol */
1148 it8709_wm(dev, 0, IT8709_RFSR);
1153 /* return how many bytes are still in the FIFO; this will be called
1154 * with the device spinlock NOT HELD while waiting for the TX FIFO to get
1155 * empty; let's expect this won't be a problem */
1156 static int it8709_get_tx_used_slots(struct ite_dev *dev)
1158 ite_dbg("%s called", __func__);
1160 return it8709_rr(dev, IT85_C0TFSR) & IT85_TXFBC;
1163 /* put a byte to the TX fifo; this should be called with the spinlock held */
1164 static void it8709_put_tx_byte(struct ite_dev *dev, u8 value)
1166 it8709_wr(dev, value, IT85_C0DR);
1169 /* idle the receiver so that we won't receive samples until another
1170 pulse is detected; this must be called with the device spinlock held */
1171 static void it8709_idle_rx(struct ite_dev *dev)
1173 ite_dbg("%s called", __func__);
1175 /* disable streaming by clearing RXACT writing it as 1 */
1176 it8709_wr(dev, it8709_rr(dev, IT85_C0RCR) | IT85_RXACT,
1179 /* clear the FIFO */
1180 it8709_wr(dev, it8709_rr(dev, IT85_C0MSTCR) | IT85_FIFOCLR,
1184 /* disable the receiver; this must be called with the device spinlock held */
1185 static void it8709_disable_rx(struct ite_dev *dev)
1187 ite_dbg("%s called", __func__);
1189 /* disable the receiver interrupts */
1190 it8709_wr(dev, it8709_rr(dev, IT85_C0IER) &
1191 ~(IT85_RDAIE | IT85_RFOIE),
1194 /* disable the receiver */
1195 it8709_wr(dev, it8709_rr(dev, IT85_C0RCR) & ~IT85_RXEN,
1198 /* clear the FIFO and RXACT (actually RXACT should have been cleared
1199 * in the previous it8709_wr(dev, ) call) */
1200 it8709_idle_rx(dev);
1203 /* enable the receiver; this must be called with the device spinlock held */
1204 static void it8709_enable_rx(struct ite_dev *dev)
1206 ite_dbg("%s called", __func__);
1208 /* enable the receiver by setting RXEN */
1209 it8709_wr(dev, it8709_rr(dev, IT85_C0RCR) | IT85_RXEN,
1212 /* just prepare it to idle for the next reception */
1213 it8709_idle_rx(dev);
1215 /* enable the receiver interrupts and master enable flag */
1216 it8709_wr(dev, it8709_rr(dev, IT85_C0IER)
1217 |IT85_RDAIE | IT85_RFOIE | IT85_IEC,
1221 /* disable the transmitter interrupt; this must be called with the device
1223 static void it8709_disable_tx_interrupt(struct ite_dev *dev)
1225 ite_dbg("%s called", __func__);
1227 /* disable the transmitter interrupts */
1228 it8709_wr(dev, it8709_rr(dev, IT85_C0IER) & ~IT85_TLDLIE,
1232 /* enable the transmitter interrupt; this must be called with the device
1234 static void it8709_enable_tx_interrupt(struct ite_dev *dev)
1236 ite_dbg("%s called", __func__);
1238 /* enable the transmitter interrupts and master enable flag */
1239 it8709_wr(dev, it8709_rr(dev, IT85_C0IER)
1240 |IT85_TLDLIE | IT85_IEC,
1244 /* disable the device; this must be called with the device spinlock held */
1245 static void it8709_disable(struct ite_dev *dev)
1247 ite_dbg("%s called", __func__);
1249 /* clear out all interrupt enable flags */
1250 it8709_wr(dev, it8709_rr(dev, IT85_C0IER) &
1251 ~(IT85_IEC | IT85_RFOIE | IT85_RDAIE | IT85_TLDLIE),
1254 /* disable the receiver */
1255 it8709_disable_rx(dev);
1257 /* erase the FIFO */
1258 it8709_wr(dev, IT85_FIFOCLR | it8709_rr(dev, IT85_C0MSTCR),
1262 /* initialize the hardware */
1263 static void it8709_init_hardware(struct ite_dev *dev)
1265 ite_dbg("%s called", __func__);
1267 /* disable all the interrupts */
1268 it8709_wr(dev, it8709_rr(dev, IT85_C0IER) &
1269 ~(IT85_IEC | IT85_RFOIE | IT85_RDAIE | IT85_TLDLIE),
1272 /* program the baud rate divisor */
1273 it8709_wr(dev, ITE_BAUDRATE_DIVISOR & 0xff, IT85_C0BDLR);
1274 it8709_wr(dev, (ITE_BAUDRATE_DIVISOR >> 8) & 0xff,
1277 /* program the C0MSTCR register defaults */
1278 it8709_wr(dev, (it8709_rr(dev, IT85_C0MSTCR) &
1279 ~(IT85_ILSEL | IT85_ILE | IT85_FIFOTL
1280 | IT85_FIFOCLR | IT85_RESET)) | IT85_FIFOTL_DEFAULT,
1283 /* program the C0RCR register defaults */
1284 it8709_wr(dev, (it8709_rr(dev, IT85_C0RCR) &
1285 ~(IT85_RXEN | IT85_RDWOS | IT85_RXEND | IT85_RXACT
1286 | IT85_RXDCR)) | ITE_RXDCR_DEFAULT,
1289 /* program the C0TCR register defaults */
1290 it8709_wr(dev, (it8709_rr(dev, IT85_C0TCR) & ~(IT85_TXMPM | IT85_TXMPW))
1291 | IT85_TXRLE | IT85_TXENDF | IT85_TXMPM_DEFAULT
1292 | IT85_TXMPW_DEFAULT,
1295 /* program the carrier parameters */
1296 ite_set_carrier_params(dev);
1300 /* generic hardware setup/teardown code */
1302 /* activate the device for use */
1303 static int ite_open(struct rc_dev *rcdev)
1305 struct ite_dev *dev = rcdev->priv;
1306 unsigned long flags;
1308 ite_dbg("%s called", __func__);
1310 spin_lock_irqsave(&dev->lock, flags);
1313 /* enable the receiver */
1314 dev->params.enable_rx(dev);
1316 spin_unlock_irqrestore(&dev->lock, flags);
1321 /* deactivate the device for use */
1322 static void ite_close(struct rc_dev *rcdev)
1324 struct ite_dev *dev = rcdev->priv;
1325 unsigned long flags;
1327 ite_dbg("%s called", __func__);
1329 spin_lock_irqsave(&dev->lock, flags);
1330 dev->in_use = false;
1332 /* wait for any transmission to end */
1333 spin_unlock_irqrestore(&dev->lock, flags);
1334 wait_event_interruptible(dev->tx_ended, !dev->transmitting);
1335 spin_lock_irqsave(&dev->lock, flags);
1337 dev->params.disable(dev);
1339 spin_unlock_irqrestore(&dev->lock, flags);
1342 /* supported models and their parameters */
1343 static const struct ite_dev_params ite_dev_descs[] = {
1345 .model = "ITE8704 CIR transceiver",
1346 .io_region_size = IT87_IOREG_LENGTH,
1348 .hw_tx_capable = true,
1349 .sample_period = (u32) (1000000000ULL / 115200),
1350 .tx_carrier_freq = 38000,
1351 .tx_duty_cycle = 33,
1352 .rx_low_carrier_freq = 0,
1353 .rx_high_carrier_freq = 0,
1356 .get_irq_causes = it87_get_irq_causes,
1357 .enable_rx = it87_enable_rx,
1358 .idle_rx = it87_idle_rx,
1359 .disable_rx = it87_idle_rx,
1360 .get_rx_bytes = it87_get_rx_bytes,
1361 .enable_tx_interrupt = it87_enable_tx_interrupt,
1362 .disable_tx_interrupt = it87_disable_tx_interrupt,
1363 .get_tx_used_slots = it87_get_tx_used_slots,
1364 .put_tx_byte = it87_put_tx_byte,
1365 .disable = it87_disable,
1366 .init_hardware = it87_init_hardware,
1367 .set_carrier_params = it87_set_carrier_params,
1370 .model = "ITE8713 CIR transceiver",
1371 .io_region_size = IT87_IOREG_LENGTH,
1373 .hw_tx_capable = true,
1374 .sample_period = (u32) (1000000000ULL / 115200),
1375 .tx_carrier_freq = 38000,
1376 .tx_duty_cycle = 33,
1377 .rx_low_carrier_freq = 0,
1378 .rx_high_carrier_freq = 0,
1381 .get_irq_causes = it87_get_irq_causes,
1382 .enable_rx = it87_enable_rx,
1383 .idle_rx = it87_idle_rx,
1384 .disable_rx = it87_idle_rx,
1385 .get_rx_bytes = it87_get_rx_bytes,
1386 .enable_tx_interrupt = it87_enable_tx_interrupt,
1387 .disable_tx_interrupt = it87_disable_tx_interrupt,
1388 .get_tx_used_slots = it87_get_tx_used_slots,
1389 .put_tx_byte = it87_put_tx_byte,
1390 .disable = it87_disable,
1391 .init_hardware = it87_init_hardware,
1392 .set_carrier_params = it87_set_carrier_params,
1395 .model = "ITE8708 CIR transceiver",
1396 .io_region_size = IT8708_IOREG_LENGTH,
1398 .hw_tx_capable = true,
1399 .sample_period = (u32) (1000000000ULL / 115200),
1400 .tx_carrier_freq = 38000,
1401 .tx_duty_cycle = 33,
1402 .rx_low_carrier_freq = 0,
1403 .rx_high_carrier_freq = 0,
1406 .get_irq_causes = it8708_get_irq_causes,
1407 .enable_rx = it8708_enable_rx,
1408 .idle_rx = it8708_idle_rx,
1409 .disable_rx = it8708_idle_rx,
1410 .get_rx_bytes = it8708_get_rx_bytes,
1411 .enable_tx_interrupt = it8708_enable_tx_interrupt,
1412 .disable_tx_interrupt =
1413 it8708_disable_tx_interrupt,
1414 .get_tx_used_slots = it8708_get_tx_used_slots,
1415 .put_tx_byte = it8708_put_tx_byte,
1416 .disable = it8708_disable,
1417 .init_hardware = it8708_init_hardware,
1418 .set_carrier_params = it8708_set_carrier_params,
1421 .model = "ITE8709 CIR transceiver",
1422 .io_region_size = IT8709_IOREG_LENGTH,
1424 .hw_tx_capable = true,
1425 .sample_period = (u32) (1000000000ULL / 115200),
1426 .tx_carrier_freq = 38000,
1427 .tx_duty_cycle = 33,
1428 .rx_low_carrier_freq = 0,
1429 .rx_high_carrier_freq = 0,
1432 .get_irq_causes = it8709_get_irq_causes,
1433 .enable_rx = it8709_enable_rx,
1434 .idle_rx = it8709_idle_rx,
1435 .disable_rx = it8709_idle_rx,
1436 .get_rx_bytes = it8709_get_rx_bytes,
1437 .enable_tx_interrupt = it8709_enable_tx_interrupt,
1438 .disable_tx_interrupt =
1439 it8709_disable_tx_interrupt,
1440 .get_tx_used_slots = it8709_get_tx_used_slots,
1441 .put_tx_byte = it8709_put_tx_byte,
1442 .disable = it8709_disable,
1443 .init_hardware = it8709_init_hardware,
1444 .set_carrier_params = it8709_set_carrier_params,
1448 static const struct pnp_device_id ite_ids[] = {
1449 {"ITE8704", 0}, /* Default model */
1450 {"ITE8713", 1}, /* CIR found in EEEBox 1501U */
1451 {"ITE8708", 2}, /* Bridged IT8512 */
1452 {"ITE8709", 3}, /* SRAM-Bridged IT8512 */
1456 /* allocate memory, probe hardware, and initialize everything */
1457 static int ite_probe(struct pnp_dev *pdev, const struct pnp_device_id
1460 const struct ite_dev_params *dev_desc = NULL;
1461 struct ite_dev *itdev = NULL;
1462 struct rc_dev *rdev = NULL;
1467 ite_dbg("%s called", __func__);
1469 itdev = kzalloc(sizeof(struct ite_dev), GFP_KERNEL);
1473 /* input device for IR remote (and tx) */
1474 rdev = rc_allocate_device(RC_DRIVER_IR_RAW);
1476 goto exit_free_dev_rdev;
1481 /* get the model number */
1482 model_no = (int)dev_id->driver_data;
1483 ite_pr(KERN_NOTICE, "Auto-detected model: %s\n",
1484 ite_dev_descs[model_no].model);
1486 if (model_number >= 0 && model_number < ARRAY_SIZE(ite_dev_descs)) {
1487 model_no = model_number;
1488 ite_pr(KERN_NOTICE, "The model has been fixed by a module parameter.");
1491 ite_pr(KERN_NOTICE, "Using model: %s\n", ite_dev_descs[model_no].model);
1493 /* get the description for the device */
1494 dev_desc = &ite_dev_descs[model_no];
1495 io_rsrc_no = dev_desc->io_rsrc_no;
1497 /* validate pnp resources */
1498 if (!pnp_port_valid(pdev, io_rsrc_no) ||
1499 pnp_port_len(pdev, io_rsrc_no) != dev_desc->io_region_size) {
1500 dev_err(&pdev->dev, "IR PNP Port not valid!\n");
1501 goto exit_free_dev_rdev;
1504 if (!pnp_irq_valid(pdev, 0)) {
1505 dev_err(&pdev->dev, "PNP IRQ not valid!\n");
1506 goto exit_free_dev_rdev;
1509 /* store resource values */
1510 itdev->cir_addr = pnp_port_start(pdev, io_rsrc_no);
1511 itdev->cir_irq = pnp_irq(pdev, 0);
1513 /* initialize spinlocks */
1514 spin_lock_init(&itdev->lock);
1516 /* initialize raw event */
1517 init_ir_raw_event(&itdev->rawir);
1519 /* set driver data into the pnp device */
1520 pnp_set_drvdata(pdev, itdev);
1523 /* initialize waitqueues for transmission */
1524 init_waitqueue_head(&itdev->tx_queue);
1525 init_waitqueue_head(&itdev->tx_ended);
1527 /* copy model-specific parameters */
1528 itdev->params = *dev_desc;
1530 /* apply any overrides */
1531 if (sample_period > 0)
1532 itdev->params.sample_period = sample_period;
1534 if (tx_carrier_freq > 0)
1535 itdev->params.tx_carrier_freq = tx_carrier_freq;
1537 if (tx_duty_cycle > 0 && tx_duty_cycle <= 100)
1538 itdev->params.tx_duty_cycle = tx_duty_cycle;
1540 if (rx_low_carrier_freq > 0)
1541 itdev->params.rx_low_carrier_freq = rx_low_carrier_freq;
1543 if (rx_high_carrier_freq > 0)
1544 itdev->params.rx_high_carrier_freq = rx_high_carrier_freq;
1546 /* print out parameters */
1547 ite_pr(KERN_NOTICE, "TX-capable: %d\n", (int)
1548 itdev->params.hw_tx_capable);
1549 ite_pr(KERN_NOTICE, "Sample period (ns): %ld\n", (long)
1550 itdev->params.sample_period);
1551 ite_pr(KERN_NOTICE, "TX carrier frequency (Hz): %d\n", (int)
1552 itdev->params.tx_carrier_freq);
1553 ite_pr(KERN_NOTICE, "TX duty cycle (%%): %d\n", (int)
1554 itdev->params.tx_duty_cycle);
1555 ite_pr(KERN_NOTICE, "RX low carrier frequency (Hz): %d\n", (int)
1556 itdev->params.rx_low_carrier_freq);
1557 ite_pr(KERN_NOTICE, "RX high carrier frequency (Hz): %d\n", (int)
1558 itdev->params.rx_high_carrier_freq);
1560 /* set up hardware initial state */
1561 itdev->params.init_hardware(itdev);
1563 /* set up ir-core props */
1565 rdev->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
1566 rdev->open = ite_open;
1567 rdev->close = ite_close;
1568 rdev->s_idle = ite_s_idle;
1569 rdev->s_rx_carrier_range = ite_set_rx_carrier_range;
1570 rdev->min_timeout = ITE_MIN_IDLE_TIMEOUT;
1571 rdev->max_timeout = ITE_MAX_IDLE_TIMEOUT;
1572 rdev->timeout = ITE_IDLE_TIMEOUT;
1573 rdev->rx_resolution = ITE_BAUDRATE_DIVISOR *
1574 itdev->params.sample_period;
1575 rdev->tx_resolution = ITE_BAUDRATE_DIVISOR *
1576 itdev->params.sample_period;
1578 /* set up transmitter related values if needed */
1579 if (itdev->params.hw_tx_capable) {
1580 rdev->tx_ir = ite_tx_ir;
1581 rdev->s_tx_carrier = ite_set_tx_carrier;
1582 rdev->s_tx_duty_cycle = ite_set_tx_duty_cycle;
1585 rdev->device_name = dev_desc->model;
1586 rdev->input_id.bustype = BUS_HOST;
1587 rdev->input_id.vendor = PCI_VENDOR_ID_ITE;
1588 rdev->input_id.product = 0;
1589 rdev->input_id.version = 0;
1590 rdev->driver_name = ITE_DRIVER_NAME;
1591 rdev->map_name = RC_MAP_RC6_MCE;
1593 ret = rc_register_device(rdev);
1595 goto exit_free_dev_rdev;
1598 /* now claim resources */
1599 if (!request_region(itdev->cir_addr,
1600 dev_desc->io_region_size, ITE_DRIVER_NAME))
1601 goto exit_unregister_device;
1603 if (request_irq(itdev->cir_irq, ite_cir_isr, IRQF_SHARED,
1604 ITE_DRIVER_NAME, (void *)itdev))
1605 goto exit_release_cir_addr;
1607 ite_pr(KERN_NOTICE, "driver has been successfully loaded\n");
1611 exit_release_cir_addr:
1612 release_region(itdev->cir_addr, itdev->params.io_region_size);
1613 exit_unregister_device:
1614 rc_unregister_device(rdev);
1617 rc_free_device(rdev);
1623 static void ite_remove(struct pnp_dev *pdev)
1625 struct ite_dev *dev = pnp_get_drvdata(pdev);
1626 unsigned long flags;
1628 ite_dbg("%s called", __func__);
1630 spin_lock_irqsave(&dev->lock, flags);
1632 /* disable hardware */
1633 dev->params.disable(dev);
1635 spin_unlock_irqrestore(&dev->lock, flags);
1637 /* free resources */
1638 free_irq(dev->cir_irq, dev);
1639 release_region(dev->cir_addr, dev->params.io_region_size);
1641 rc_unregister_device(dev->rdev);
1646 static int ite_suspend(struct pnp_dev *pdev, pm_message_t state)
1648 struct ite_dev *dev = pnp_get_drvdata(pdev);
1649 unsigned long flags;
1651 ite_dbg("%s called", __func__);
1653 /* wait for any transmission to end */
1654 wait_event_interruptible(dev->tx_ended, !dev->transmitting);
1656 spin_lock_irqsave(&dev->lock, flags);
1658 /* disable all interrupts */
1659 dev->params.disable(dev);
1661 spin_unlock_irqrestore(&dev->lock, flags);
1666 static int ite_resume(struct pnp_dev *pdev)
1668 struct ite_dev *dev = pnp_get_drvdata(pdev);
1669 unsigned long flags;
1671 ite_dbg("%s called", __func__);
1673 spin_lock_irqsave(&dev->lock, flags);
1675 /* reinitialize hardware config registers */
1676 dev->params.init_hardware(dev);
1677 /* enable the receiver */
1678 dev->params.enable_rx(dev);
1680 spin_unlock_irqrestore(&dev->lock, flags);
1685 static void ite_shutdown(struct pnp_dev *pdev)
1687 struct ite_dev *dev = pnp_get_drvdata(pdev);
1688 unsigned long flags;
1690 ite_dbg("%s called", __func__);
1692 spin_lock_irqsave(&dev->lock, flags);
1694 /* disable all interrupts */
1695 dev->params.disable(dev);
1697 spin_unlock_irqrestore(&dev->lock, flags);
1700 static struct pnp_driver ite_driver = {
1701 .name = ITE_DRIVER_NAME,
1702 .id_table = ite_ids,
1704 .remove = ite_remove,
1705 .suspend = ite_suspend,
1706 .resume = ite_resume,
1707 .shutdown = ite_shutdown,
1710 MODULE_DEVICE_TABLE(pnp, ite_ids);
1711 MODULE_DESCRIPTION("ITE Tech Inc. IT8712F/ITE8512F CIR driver");
1713 MODULE_AUTHOR("Juan J. Garcia de Soria <skandalfo@gmail.com>");
1714 MODULE_LICENSE("GPL");
1716 module_pnp_driver(ite_driver);