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/slab.h>
40 #include <linux/input.h>
41 #include <linux/bitops.h>
42 #include <media/rc-core.h>
43 #include <linux/pci_ids.h>
47 /* module parameters */
51 module_param(debug
, int, S_IRUGO
| S_IWUSR
);
52 MODULE_PARM_DESC(debug
, "Enable debugging output");
54 /* low limit for RX carrier freq, Hz, 0 for no RX demodulation */
55 static int rx_low_carrier_freq
;
56 module_param(rx_low_carrier_freq
, int, S_IRUGO
| S_IWUSR
);
57 MODULE_PARM_DESC(rx_low_carrier_freq
, "Override low RX carrier frequency, Hz, "
58 "0 for no RX demodulation");
60 /* high limit for RX carrier freq, Hz, 0 for no RX demodulation */
61 static int rx_high_carrier_freq
;
62 module_param(rx_high_carrier_freq
, int, S_IRUGO
| S_IWUSR
);
63 MODULE_PARM_DESC(rx_high_carrier_freq
, "Override high RX carrier frequency, "
64 "Hz, 0 for no RX demodulation");
66 /* override tx carrier frequency */
67 static int tx_carrier_freq
;
68 module_param(tx_carrier_freq
, int, S_IRUGO
| S_IWUSR
);
69 MODULE_PARM_DESC(tx_carrier_freq
, "Override TX carrier frequency, Hz");
71 /* override tx duty cycle */
72 static int tx_duty_cycle
;
73 module_param(tx_duty_cycle
, int, S_IRUGO
| S_IWUSR
);
74 MODULE_PARM_DESC(tx_duty_cycle
, "Override TX duty cycle, 1-100");
76 /* override default sample period */
77 static long sample_period
;
78 module_param(sample_period
, long, S_IRUGO
| S_IWUSR
);
79 MODULE_PARM_DESC(sample_period
, "Override carrier sample period, us");
81 /* override detected model id */
82 static int model_number
= -1;
83 module_param(model_number
, int, S_IRUGO
| S_IWUSR
);
84 MODULE_PARM_DESC(model_number
, "Use this model number, don't autodetect");
87 /* HW-independent code functions */
89 /* check whether carrier frequency is high frequency */
90 static inline bool ite_is_high_carrier_freq(unsigned int freq
)
92 return freq
>= ITE_HCF_MIN_CARRIER_FREQ
;
95 /* get the bits required to program the carrier frequency in CFQ bits,
97 static u8
ite_get_carrier_freq_bits(unsigned int freq
)
99 if (ite_is_high_carrier_freq(freq
)) {
103 else if (freq
< 465000)
106 else if (freq
< 490000)
113 if (freq
< ITE_LCF_MIN_CARRIER_FREQ
)
114 freq
= ITE_LCF_MIN_CARRIER_FREQ
;
115 if (freq
> ITE_LCF_MAX_CARRIER_FREQ
)
116 freq
= ITE_LCF_MAX_CARRIER_FREQ
;
118 /* convert to kHz and subtract the base freq */
120 DIV_ROUND_CLOSEST(freq
- ITE_LCF_MIN_CARRIER_FREQ
,
127 /* get the bits required to program the pulse with in TXMPW */
128 static u8
ite_get_pulse_width_bits(unsigned int freq
, int duty_cycle
)
130 unsigned long period_ns
, on_ns
;
132 /* sanitize freq into range */
133 if (freq
< ITE_LCF_MIN_CARRIER_FREQ
)
134 freq
= ITE_LCF_MIN_CARRIER_FREQ
;
135 if (freq
> ITE_HCF_MAX_CARRIER_FREQ
)
136 freq
= ITE_HCF_MAX_CARRIER_FREQ
;
138 period_ns
= 1000000000UL / freq
;
139 on_ns
= period_ns
* duty_cycle
/ 100;
141 if (ite_is_high_carrier_freq(freq
)) {
145 else if (on_ns
< 850)
148 else if (on_ns
< 950)
151 else if (on_ns
< 1080)
160 else if (on_ns
< 7850)
163 else if (on_ns
< 9650)
166 else if (on_ns
< 11950)
174 /* decode raw bytes as received by the hardware, and push them to the ir-core
176 static void ite_decode_bytes(struct ite_dev
*dev
, const u8
* data
, int
180 unsigned long *ldata
;
181 unsigned int next_one
, next_zero
, size
;
182 DEFINE_IR_RAW_EVENT(ev
);
187 sample_period
= dev
->params
.sample_period
;
188 ldata
= (unsigned long *)data
;
190 next_one
= find_next_bit_le(ldata
, size
, 0);
194 ITE_BITS_TO_NS(next_one
, sample_period
);
195 ir_raw_event_store_with_filter(dev
->rdev
, &ev
);
198 while (next_one
< size
) {
199 next_zero
= find_next_zero_bit_le(ldata
, size
, next_one
+ 1);
201 ev
.duration
= ITE_BITS_TO_NS(next_zero
- next_one
, sample_period
);
202 ir_raw_event_store_with_filter(dev
->rdev
, &ev
);
204 if (next_zero
< size
) {
206 find_next_bit_le(ldata
,
211 ITE_BITS_TO_NS(next_one
- next_zero
,
213 ir_raw_event_store_with_filter
219 ir_raw_event_handle(dev
->rdev
);
221 ite_dbg_verbose("decoded %d bytes.", length
);
224 /* set all the rx/tx carrier parameters; this must be called with the device
226 static void ite_set_carrier_params(struct ite_dev
*dev
)
228 unsigned int freq
, low_freq
, high_freq
;
230 bool use_demodulator
;
231 bool for_tx
= dev
->transmitting
;
233 ite_dbg("%s called", __func__
);
236 /* we don't need no stinking calculations */
237 freq
= dev
->params
.tx_carrier_freq
;
238 allowance
= ITE_RXDCR_DEFAULT
;
239 use_demodulator
= false;
241 low_freq
= dev
->params
.rx_low_carrier_freq
;
242 high_freq
= dev
->params
.rx_high_carrier_freq
;
245 /* don't demodulate */
247 ITE_DEFAULT_CARRIER_FREQ
;
248 allowance
= ITE_RXDCR_DEFAULT
;
249 use_demodulator
= false;
251 /* calculate the middle freq */
252 freq
= (low_freq
+ high_freq
) / 2;
254 /* calculate the allowance */
256 DIV_ROUND_CLOSEST(10000 * (high_freq
- low_freq
),
257 ITE_RXDCR_PER_10000_STEP
258 * (high_freq
+ low_freq
));
263 if (allowance
> ITE_RXDCR_MAX
)
264 allowance
= ITE_RXDCR_MAX
;
268 /* set the carrier parameters in a device-dependent way */
269 dev
->params
.set_carrier_params(dev
, ite_is_high_carrier_freq(freq
),
270 use_demodulator
, ite_get_carrier_freq_bits(freq
), allowance
,
271 ite_get_pulse_width_bits(freq
, dev
->params
.tx_duty_cycle
));
274 /* interrupt service routine for incoming and outgoing CIR data */
275 static irqreturn_t
ite_cir_isr(int irq
, void *data
)
277 struct ite_dev
*dev
= data
;
279 irqreturn_t ret
= IRQ_RETVAL(IRQ_NONE
);
280 u8 rx_buf
[ITE_RX_FIFO_LEN
];
284 ite_dbg_verbose("%s firing", __func__
);
286 /* grab the spinlock */
287 spin_lock_irqsave(&dev
->lock
, flags
);
289 /* read the interrupt flags */
290 iflags
= dev
->params
.get_irq_causes(dev
);
292 /* check for the receive interrupt */
293 if (iflags
& (ITE_IRQ_RX_FIFO
| ITE_IRQ_RX_FIFO_OVERRUN
)) {
294 /* read the FIFO bytes */
296 dev
->params
.get_rx_bytes(dev
, rx_buf
,
300 /* drop the spinlock, since the ir-core layer
301 * may call us back again through
303 spin_unlock_irqrestore(&dev
->
307 /* decode the data we've just received */
308 ite_decode_bytes(dev
, rx_buf
,
311 /* reacquire the spinlock */
312 spin_lock_irqsave(&dev
->lock
,
315 /* mark the interrupt as serviced */
316 ret
= IRQ_RETVAL(IRQ_HANDLED
);
318 } else if (iflags
& ITE_IRQ_TX_FIFO
) {
319 /* FIFO space available interrupt */
320 ite_dbg_verbose("got interrupt for TX FIFO");
322 /* wake any sleeping transmitter */
323 wake_up_interruptible(&dev
->tx_queue
);
325 /* mark the interrupt as serviced */
326 ret
= IRQ_RETVAL(IRQ_HANDLED
);
329 /* drop the spinlock */
330 spin_unlock_irqrestore(&dev
->lock
, flags
);
332 ite_dbg_verbose("%s done returning %d", __func__
, (int)ret
);
337 /* set the rx carrier freq range, guess it's in Hz... */
338 static int ite_set_rx_carrier_range(struct rc_dev
*rcdev
, u32 carrier_low
, u32
342 struct ite_dev
*dev
= rcdev
->priv
;
344 spin_lock_irqsave(&dev
->lock
, flags
);
345 dev
->params
.rx_low_carrier_freq
= carrier_low
;
346 dev
->params
.rx_high_carrier_freq
= carrier_high
;
347 ite_set_carrier_params(dev
);
348 spin_unlock_irqrestore(&dev
->lock
, flags
);
353 /* set the tx carrier freq, guess it's in Hz... */
354 static int ite_set_tx_carrier(struct rc_dev
*rcdev
, u32 carrier
)
357 struct ite_dev
*dev
= rcdev
->priv
;
359 spin_lock_irqsave(&dev
->lock
, flags
);
360 dev
->params
.tx_carrier_freq
= carrier
;
361 ite_set_carrier_params(dev
);
362 spin_unlock_irqrestore(&dev
->lock
, flags
);
367 /* set the tx duty cycle by controlling the pulse width */
368 static int ite_set_tx_duty_cycle(struct rc_dev
*rcdev
, u32 duty_cycle
)
371 struct ite_dev
*dev
= rcdev
->priv
;
373 spin_lock_irqsave(&dev
->lock
, flags
);
374 dev
->params
.tx_duty_cycle
= duty_cycle
;
375 ite_set_carrier_params(dev
);
376 spin_unlock_irqrestore(&dev
->lock
, flags
);
381 /* transmit out IR pulses; what you get here is a batch of alternating
382 * pulse/space/pulse/space lengths that we should write out completely through
383 * the FIFO, blocking on a full FIFO */
384 static int ite_tx_ir(struct rc_dev
*rcdev
, int *txbuf
, u32 n
)
387 struct ite_dev
*dev
= rcdev
->priv
;
388 bool is_pulse
= false;
389 int remaining_us
, fifo_avail
, fifo_remaining
, last_idx
= 0;
390 int max_rle_us
, next_rle_us
;
392 u8 last_sent
[ITE_TX_FIFO_LEN
];
395 ite_dbg("%s called", __func__
);
397 /* clear the array just in case */
398 memset(last_sent
, 0, ARRAY_SIZE(last_sent
));
400 /* n comes in bytes; convert to ints */
403 spin_lock_irqsave(&dev
->lock
, flags
);
405 /* let everybody know we're now transmitting */
406 dev
->transmitting
= true;
408 /* and set the carrier values for transmission */
409 ite_set_carrier_params(dev
);
411 /* calculate how much time we can send in one byte */
413 (ITE_BAUDRATE_DIVISOR
* dev
->params
.sample_period
*
414 ITE_TX_MAX_RLE
) / 1000;
416 /* disable the receiver */
417 dev
->params
.disable_rx(dev
);
419 /* this is where we'll begin filling in the FIFO, until it's full.
420 * then we'll just activate the interrupt, wait for it to wake us up
421 * again, disable it, continue filling the FIFO... until everything
422 * has been pushed out */
424 ITE_TX_FIFO_LEN
- dev
->params
.get_tx_used_slots(dev
);
426 while (n
> 0 && dev
->in_use
) {
427 /* transmit the next sample */
428 is_pulse
= !is_pulse
;
429 remaining_us
= *(txbuf
++);
433 ((is_pulse
) ? "pulse" : "space"),
437 /* repeat while the pulse is non-zero length */
438 while (remaining_us
> 0 && dev
->in_use
) {
439 if (remaining_us
> max_rle_us
)
440 next_rle_us
= max_rle_us
;
443 next_rle_us
= remaining_us
;
445 remaining_us
-= next_rle_us
;
447 /* check what's the length we have to pump out */
448 val
= (ITE_TX_MAX_RLE
* next_rle_us
) / max_rle_us
;
450 /* put it into the sent buffer */
451 last_sent
[last_idx
++] = val
;
452 last_idx
&= (ITE_TX_FIFO_LEN
);
454 /* encode it for 7 bits */
455 val
= (val
- 1) & ITE_TX_RLE_MASK
;
457 /* take into account pulse/space prefix */
465 * if we get to 0 available, read again, just in case
466 * some other slot got freed
469 fifo_avail
= ITE_TX_FIFO_LEN
- dev
->params
.get_tx_used_slots(dev
);
471 /* if it's still full */
472 if (fifo_avail
<= 0) {
473 /* enable the tx interrupt */
475 enable_tx_interrupt(dev
);
477 /* drop the spinlock */
478 spin_unlock_irqrestore(&dev
->lock
, flags
);
480 /* wait for the FIFO to empty enough */
481 wait_event_interruptible(dev
->tx_queue
, (fifo_avail
= ITE_TX_FIFO_LEN
- dev
->params
.get_tx_used_slots(dev
)) >= 8);
483 /* get the spinlock again */
484 spin_lock_irqsave(&dev
->lock
, flags
);
486 /* disable the tx interrupt again. */
488 disable_tx_interrupt(dev
);
491 /* now send the byte through the FIFO */
492 dev
->params
.put_tx_byte(dev
, val
);
497 /* wait and don't return until the whole FIFO has been sent out;
498 * otherwise we could configure the RX carrier params instead of the
499 * TX ones while the transmission is still being performed! */
500 fifo_remaining
= dev
->params
.get_tx_used_slots(dev
);
502 while (fifo_remaining
> 0) {
505 last_idx
&= (ITE_TX_FIFO_LEN
- 1);
506 remaining_us
+= last_sent
[last_idx
];
508 remaining_us
= (remaining_us
* max_rle_us
) / (ITE_TX_MAX_RLE
);
510 /* drop the spinlock while we sleep */
511 spin_unlock_irqrestore(&dev
->lock
, flags
);
513 /* sleep remaining_us microseconds */
514 mdelay(DIV_ROUND_UP(remaining_us
, 1000));
516 /* reacquire the spinlock */
517 spin_lock_irqsave(&dev
->lock
, flags
);
519 /* now we're not transmitting anymore */
520 dev
->transmitting
= false;
522 /* and set the carrier values for reception */
523 ite_set_carrier_params(dev
);
525 /* reenable the receiver */
527 dev
->params
.enable_rx(dev
);
529 /* notify transmission end */
530 wake_up_interruptible(&dev
->tx_ended
);
532 spin_unlock_irqrestore(&dev
->lock
, flags
);
537 /* idle the receiver if needed */
538 static void ite_s_idle(struct rc_dev
*rcdev
, bool enable
)
541 struct ite_dev
*dev
= rcdev
->priv
;
543 ite_dbg("%s called", __func__
);
546 spin_lock_irqsave(&dev
->lock
, flags
);
547 dev
->params
.idle_rx(dev
);
548 spin_unlock_irqrestore(&dev
->lock
, flags
);
553 /* IT8712F HW-specific functions */
555 /* retrieve a bitmask of the current causes for a pending interrupt; this may
556 * be composed of ITE_IRQ_TX_FIFO, ITE_IRQ_RX_FIFO and ITE_IRQ_RX_FIFO_OVERRUN
558 static int it87_get_irq_causes(struct ite_dev
*dev
)
563 ite_dbg("%s called", __func__
);
565 /* read the interrupt flags */
566 iflags
= inb(dev
->cir_addr
+ IT87_IIR
) & IT87_II
;
570 ret
= ITE_IRQ_RX_FIFO
;
573 ret
= ITE_IRQ_RX_FIFO_OVERRUN
;
576 ret
= ITE_IRQ_TX_FIFO
;
583 /* set the carrier parameters; to be called with the spinlock held */
584 static void it87_set_carrier_params(struct ite_dev
*dev
, bool high_freq
,
585 bool use_demodulator
,
586 u8 carrier_freq_bits
, u8 allowance_bits
,
591 ite_dbg("%s called", __func__
);
593 /* program the RCR register */
594 val
= inb(dev
->cir_addr
+ IT87_RCR
)
595 & ~(IT87_HCFS
| IT87_RXEND
| IT87_RXDCR
);
603 val
|= allowance_bits
;
605 outb(val
, dev
->cir_addr
+ IT87_RCR
);
607 /* program the TCR2 register */
608 outb((carrier_freq_bits
<< IT87_CFQ_SHIFT
) | pulse_width_bits
,
609 dev
->cir_addr
+ IT87_TCR2
);
612 /* read up to buf_size bytes from the RX FIFO; to be called with the spinlock
614 static int it87_get_rx_bytes(struct ite_dev
*dev
, u8
* buf
, int buf_size
)
618 ite_dbg("%s called", __func__
);
620 /* read how many bytes are still in the FIFO */
621 fifo
= inb(dev
->cir_addr
+ IT87_RSR
) & IT87_RXFBC
;
623 while (fifo
> 0 && buf_size
> 0) {
624 *(buf
++) = inb(dev
->cir_addr
+ IT87_DR
);
633 /* return how many bytes are still in the FIFO; this will be called
634 * with the device spinlock NOT HELD while waiting for the TX FIFO to get
635 * empty; let's expect this won't be a problem */
636 static int it87_get_tx_used_slots(struct ite_dev
*dev
)
638 ite_dbg("%s called", __func__
);
640 return inb(dev
->cir_addr
+ IT87_TSR
) & IT87_TXFBC
;
643 /* put a byte to the TX fifo; this should be called with the spinlock held */
644 static void it87_put_tx_byte(struct ite_dev
*dev
, u8 value
)
646 outb(value
, dev
->cir_addr
+ IT87_DR
);
649 /* idle the receiver so that we won't receive samples until another
650 pulse is detected; this must be called with the device spinlock held */
651 static void it87_idle_rx(struct ite_dev
*dev
)
653 ite_dbg("%s called", __func__
);
655 /* disable streaming by clearing RXACT writing it as 1 */
656 outb(inb(dev
->cir_addr
+ IT87_RCR
) | IT87_RXACT
,
657 dev
->cir_addr
+ IT87_RCR
);
660 outb(inb(dev
->cir_addr
+ IT87_TCR1
) | IT87_FIFOCLR
,
661 dev
->cir_addr
+ IT87_TCR1
);
664 /* disable the receiver; this must be called with the device spinlock held */
665 static void it87_disable_rx(struct ite_dev
*dev
)
667 ite_dbg("%s called", __func__
);
669 /* disable the receiver interrupts */
670 outb(inb(dev
->cir_addr
+ IT87_IER
) & ~(IT87_RDAIE
| IT87_RFOIE
),
671 dev
->cir_addr
+ IT87_IER
);
673 /* disable the receiver */
674 outb(inb(dev
->cir_addr
+ IT87_RCR
) & ~IT87_RXEN
,
675 dev
->cir_addr
+ IT87_RCR
);
677 /* clear the FIFO and RXACT (actually RXACT should have been cleared
678 * in the previous outb() call) */
682 /* enable the receiver; this must be called with the device spinlock held */
683 static void it87_enable_rx(struct ite_dev
*dev
)
685 ite_dbg("%s called", __func__
);
687 /* enable the receiver by setting RXEN */
688 outb(inb(dev
->cir_addr
+ IT87_RCR
) | IT87_RXEN
,
689 dev
->cir_addr
+ IT87_RCR
);
691 /* just prepare it to idle for the next reception */
694 /* enable the receiver interrupts and master enable flag */
695 outb(inb(dev
->cir_addr
+ IT87_IER
) | IT87_RDAIE
| IT87_RFOIE
| IT87_IEC
,
696 dev
->cir_addr
+ IT87_IER
);
699 /* disable the transmitter interrupt; this must be called with the device
701 static void it87_disable_tx_interrupt(struct ite_dev
*dev
)
703 ite_dbg("%s called", __func__
);
705 /* disable the transmitter interrupts */
706 outb(inb(dev
->cir_addr
+ IT87_IER
) & ~IT87_TLDLIE
,
707 dev
->cir_addr
+ IT87_IER
);
710 /* enable the transmitter interrupt; this must be called with the device
712 static void it87_enable_tx_interrupt(struct ite_dev
*dev
)
714 ite_dbg("%s called", __func__
);
716 /* enable the transmitter interrupts and master enable flag */
717 outb(inb(dev
->cir_addr
+ IT87_IER
) | IT87_TLDLIE
| IT87_IEC
,
718 dev
->cir_addr
+ IT87_IER
);
721 /* disable the device; this must be called with the device spinlock held */
722 static void it87_disable(struct ite_dev
*dev
)
724 ite_dbg("%s called", __func__
);
726 /* clear out all interrupt enable flags */
727 outb(inb(dev
->cir_addr
+ IT87_IER
) &
728 ~(IT87_IEC
| IT87_RFOIE
| IT87_RDAIE
| IT87_TLDLIE
),
729 dev
->cir_addr
+ IT87_IER
);
731 /* disable the receiver */
732 it87_disable_rx(dev
);
735 outb(IT87_FIFOCLR
| inb(dev
->cir_addr
+ IT87_TCR1
),
736 dev
->cir_addr
+ IT87_TCR1
);
739 /* initialize the hardware */
740 static void it87_init_hardware(struct ite_dev
*dev
)
742 ite_dbg("%s called", __func__
);
744 /* enable just the baud rate divisor register,
745 disabling all the interrupts at the same time */
746 outb((inb(dev
->cir_addr
+ IT87_IER
) &
747 ~(IT87_IEC
| IT87_RFOIE
| IT87_RDAIE
| IT87_TLDLIE
)) | IT87_BR
,
748 dev
->cir_addr
+ IT87_IER
);
750 /* write out the baud rate divisor */
751 outb(ITE_BAUDRATE_DIVISOR
& 0xff, dev
->cir_addr
+ IT87_BDLR
);
752 outb((ITE_BAUDRATE_DIVISOR
>> 8) & 0xff, dev
->cir_addr
+ IT87_BDHR
);
754 /* disable the baud rate divisor register again */
755 outb(inb(dev
->cir_addr
+ IT87_IER
) & ~IT87_BR
,
756 dev
->cir_addr
+ IT87_IER
);
758 /* program the RCR register defaults */
759 outb(ITE_RXDCR_DEFAULT
, dev
->cir_addr
+ IT87_RCR
);
761 /* program the TCR1 register */
762 outb(IT87_TXMPM_DEFAULT
| IT87_TXENDF
| IT87_TXRLE
763 | IT87_FIFOTL_DEFAULT
| IT87_FIFOCLR
,
764 dev
->cir_addr
+ IT87_TCR1
);
766 /* program the carrier parameters */
767 ite_set_carrier_params(dev
);
770 /* IT8512F on ITE8708 HW-specific functions */
772 /* retrieve a bitmask of the current causes for a pending interrupt; this may
773 * be composed of ITE_IRQ_TX_FIFO, ITE_IRQ_RX_FIFO and ITE_IRQ_RX_FIFO_OVERRUN
775 static int it8708_get_irq_causes(struct ite_dev
*dev
)
780 ite_dbg("%s called", __func__
);
782 /* read the interrupt flags */
783 iflags
= inb(dev
->cir_addr
+ IT8708_C0IIR
);
785 if (iflags
& IT85_TLDLI
)
786 ret
|= ITE_IRQ_TX_FIFO
;
787 if (iflags
& IT85_RDAI
)
788 ret
|= ITE_IRQ_RX_FIFO
;
789 if (iflags
& IT85_RFOI
)
790 ret
|= ITE_IRQ_RX_FIFO_OVERRUN
;
795 /* set the carrier parameters; to be called with the spinlock held */
796 static void it8708_set_carrier_params(struct ite_dev
*dev
, bool high_freq
,
797 bool use_demodulator
,
798 u8 carrier_freq_bits
, u8 allowance_bits
,
803 ite_dbg("%s called", __func__
);
805 /* program the C0CFR register, with HRAE=1 */
806 outb(inb(dev
->cir_addr
+ IT8708_BANKSEL
) | IT8708_HRAE
,
807 dev
->cir_addr
+ IT8708_BANKSEL
);
809 val
= (inb(dev
->cir_addr
+ IT8708_C0CFR
)
810 & ~(IT85_HCFS
| IT85_CFQ
)) | carrier_freq_bits
;
815 outb(val
, dev
->cir_addr
+ IT8708_C0CFR
);
817 outb(inb(dev
->cir_addr
+ IT8708_BANKSEL
) & ~IT8708_HRAE
,
818 dev
->cir_addr
+ IT8708_BANKSEL
);
820 /* program the C0RCR register */
821 val
= inb(dev
->cir_addr
+ IT8708_C0RCR
)
822 & ~(IT85_RXEND
| IT85_RXDCR
);
827 val
|= allowance_bits
;
829 outb(val
, dev
->cir_addr
+ IT8708_C0RCR
);
831 /* program the C0TCR register */
832 val
= inb(dev
->cir_addr
+ IT8708_C0TCR
) & ~IT85_TXMPW
;
833 val
|= pulse_width_bits
;
834 outb(val
, dev
->cir_addr
+ IT8708_C0TCR
);
837 /* read up to buf_size bytes from the RX FIFO; to be called with the spinlock
839 static int it8708_get_rx_bytes(struct ite_dev
*dev
, u8
* buf
, int buf_size
)
843 ite_dbg("%s called", __func__
);
845 /* read how many bytes are still in the FIFO */
846 fifo
= inb(dev
->cir_addr
+ IT8708_C0RFSR
) & IT85_RXFBC
;
848 while (fifo
> 0 && buf_size
> 0) {
849 *(buf
++) = inb(dev
->cir_addr
+ IT8708_C0DR
);
858 /* return how many bytes are still in the FIFO; this will be called
859 * with the device spinlock NOT HELD while waiting for the TX FIFO to get
860 * empty; let's expect this won't be a problem */
861 static int it8708_get_tx_used_slots(struct ite_dev
*dev
)
863 ite_dbg("%s called", __func__
);
865 return inb(dev
->cir_addr
+ IT8708_C0TFSR
) & IT85_TXFBC
;
868 /* put a byte to the TX fifo; this should be called with the spinlock held */
869 static void it8708_put_tx_byte(struct ite_dev
*dev
, u8 value
)
871 outb(value
, dev
->cir_addr
+ IT8708_C0DR
);
874 /* idle the receiver so that we won't receive samples until another
875 pulse is detected; this must be called with the device spinlock held */
876 static void it8708_idle_rx(struct ite_dev
*dev
)
878 ite_dbg("%s called", __func__
);
880 /* disable streaming by clearing RXACT writing it as 1 */
881 outb(inb(dev
->cir_addr
+ IT8708_C0RCR
) | IT85_RXACT
,
882 dev
->cir_addr
+ IT8708_C0RCR
);
885 outb(inb(dev
->cir_addr
+ IT8708_C0MSTCR
) | IT85_FIFOCLR
,
886 dev
->cir_addr
+ IT8708_C0MSTCR
);
889 /* disable the receiver; this must be called with the device spinlock held */
890 static void it8708_disable_rx(struct ite_dev
*dev
)
892 ite_dbg("%s called", __func__
);
894 /* disable the receiver interrupts */
895 outb(inb(dev
->cir_addr
+ IT8708_C0IER
) &
896 ~(IT85_RDAIE
| IT85_RFOIE
),
897 dev
->cir_addr
+ IT8708_C0IER
);
899 /* disable the receiver */
900 outb(inb(dev
->cir_addr
+ IT8708_C0RCR
) & ~IT85_RXEN
,
901 dev
->cir_addr
+ IT8708_C0RCR
);
903 /* clear the FIFO and RXACT (actually RXACT should have been cleared
904 * in the previous outb() call) */
908 /* enable the receiver; this must be called with the device spinlock held */
909 static void it8708_enable_rx(struct ite_dev
*dev
)
911 ite_dbg("%s called", __func__
);
913 /* enable the receiver by setting RXEN */
914 outb(inb(dev
->cir_addr
+ IT8708_C0RCR
) | IT85_RXEN
,
915 dev
->cir_addr
+ IT8708_C0RCR
);
917 /* just prepare it to idle for the next reception */
920 /* enable the receiver interrupts and master enable flag */
921 outb(inb(dev
->cir_addr
+ IT8708_C0IER
)
922 |IT85_RDAIE
| IT85_RFOIE
| IT85_IEC
,
923 dev
->cir_addr
+ IT8708_C0IER
);
926 /* disable the transmitter interrupt; this must be called with the device
928 static void it8708_disable_tx_interrupt(struct ite_dev
*dev
)
930 ite_dbg("%s called", __func__
);
932 /* disable the transmitter interrupts */
933 outb(inb(dev
->cir_addr
+ IT8708_C0IER
) & ~IT85_TLDLIE
,
934 dev
->cir_addr
+ IT8708_C0IER
);
937 /* enable the transmitter interrupt; this must be called with the device
939 static void it8708_enable_tx_interrupt(struct ite_dev
*dev
)
941 ite_dbg("%s called", __func__
);
943 /* enable the transmitter interrupts and master enable flag */
944 outb(inb(dev
->cir_addr
+ IT8708_C0IER
)
945 |IT85_TLDLIE
| IT85_IEC
,
946 dev
->cir_addr
+ IT8708_C0IER
);
949 /* disable the device; this must be called with the device spinlock held */
950 static void it8708_disable(struct ite_dev
*dev
)
952 ite_dbg("%s called", __func__
);
954 /* clear out all interrupt enable flags */
955 outb(inb(dev
->cir_addr
+ IT8708_C0IER
) &
956 ~(IT85_IEC
| IT85_RFOIE
| IT85_RDAIE
| IT85_TLDLIE
),
957 dev
->cir_addr
+ IT8708_C0IER
);
959 /* disable the receiver */
960 it8708_disable_rx(dev
);
963 outb(IT85_FIFOCLR
| inb(dev
->cir_addr
+ IT8708_C0MSTCR
),
964 dev
->cir_addr
+ IT8708_C0MSTCR
);
967 /* initialize the hardware */
968 static void it8708_init_hardware(struct ite_dev
*dev
)
970 ite_dbg("%s called", __func__
);
972 /* disable all the interrupts */
973 outb(inb(dev
->cir_addr
+ IT8708_C0IER
) &
974 ~(IT85_IEC
| IT85_RFOIE
| IT85_RDAIE
| IT85_TLDLIE
),
975 dev
->cir_addr
+ IT8708_C0IER
);
977 /* program the baud rate divisor */
978 outb(inb(dev
->cir_addr
+ IT8708_BANKSEL
) | IT8708_HRAE
,
979 dev
->cir_addr
+ IT8708_BANKSEL
);
981 outb(ITE_BAUDRATE_DIVISOR
& 0xff, dev
->cir_addr
+ IT8708_C0BDLR
);
982 outb((ITE_BAUDRATE_DIVISOR
>> 8) & 0xff,
983 dev
->cir_addr
+ IT8708_C0BDHR
);
985 outb(inb(dev
->cir_addr
+ IT8708_BANKSEL
) & ~IT8708_HRAE
,
986 dev
->cir_addr
+ IT8708_BANKSEL
);
988 /* program the C0MSTCR register defaults */
989 outb((inb(dev
->cir_addr
+ IT8708_C0MSTCR
) &
990 ~(IT85_ILSEL
| IT85_ILE
| IT85_FIFOTL
|
991 IT85_FIFOCLR
| IT85_RESET
)) |
993 dev
->cir_addr
+ IT8708_C0MSTCR
);
995 /* program the C0RCR register defaults */
996 outb((inb(dev
->cir_addr
+ IT8708_C0RCR
) &
997 ~(IT85_RXEN
| IT85_RDWOS
| IT85_RXEND
|
998 IT85_RXACT
| IT85_RXDCR
)) |
1000 dev
->cir_addr
+ IT8708_C0RCR
);
1002 /* program the C0TCR register defaults */
1003 outb((inb(dev
->cir_addr
+ IT8708_C0TCR
) &
1004 ~(IT85_TXMPM
| IT85_TXMPW
))
1005 |IT85_TXRLE
| IT85_TXENDF
|
1006 IT85_TXMPM_DEFAULT
| IT85_TXMPW_DEFAULT
,
1007 dev
->cir_addr
+ IT8708_C0TCR
);
1009 /* program the carrier parameters */
1010 ite_set_carrier_params(dev
);
1013 /* IT8512F on ITE8709 HW-specific functions */
1015 /* read a byte from the SRAM module */
1016 static inline u8
it8709_rm(struct ite_dev
*dev
, int index
)
1018 outb(index
, dev
->cir_addr
+ IT8709_RAM_IDX
);
1019 return inb(dev
->cir_addr
+ IT8709_RAM_VAL
);
1022 /* write a byte to the SRAM module */
1023 static inline void it8709_wm(struct ite_dev
*dev
, u8 val
, int index
)
1025 outb(index
, dev
->cir_addr
+ IT8709_RAM_IDX
);
1026 outb(val
, dev
->cir_addr
+ IT8709_RAM_VAL
);
1029 static void it8709_wait(struct ite_dev
*dev
)
1033 * loop until device tells it's ready to continue
1034 * iterations count is usually ~750 but can sometimes achieve 13000
1036 for (i
= 0; i
< 15000; i
++) {
1038 if (it8709_rm(dev
, IT8709_MODE
) == IT8709_IDLE
)
1043 /* read the value of a CIR register */
1044 static u8
it8709_rr(struct ite_dev
*dev
, int index
)
1046 /* just wait in case the previous access was a write */
1048 it8709_wm(dev
, index
, IT8709_REG_IDX
);
1049 it8709_wm(dev
, IT8709_READ
, IT8709_MODE
);
1051 /* wait for the read data to be available */
1054 /* return the read value */
1055 return it8709_rm(dev
, IT8709_REG_VAL
);
1058 /* write the value of a CIR register */
1059 static void it8709_wr(struct ite_dev
*dev
, u8 val
, int index
)
1061 /* we wait before writing, and not afterwards, since this allows us to
1062 * pipeline the host CPU with the microcontroller */
1064 it8709_wm(dev
, val
, IT8709_REG_VAL
);
1065 it8709_wm(dev
, index
, IT8709_REG_IDX
);
1066 it8709_wm(dev
, IT8709_WRITE
, IT8709_MODE
);
1069 /* retrieve a bitmask of the current causes for a pending interrupt; this may
1070 * be composed of ITE_IRQ_TX_FIFO, ITE_IRQ_RX_FIFO and ITE_IRQ_RX_FIFO_OVERRUN
1072 static int it8709_get_irq_causes(struct ite_dev
*dev
)
1077 ite_dbg("%s called", __func__
);
1079 /* read the interrupt flags */
1080 iflags
= it8709_rm(dev
, IT8709_IIR
);
1082 if (iflags
& IT85_TLDLI
)
1083 ret
|= ITE_IRQ_TX_FIFO
;
1084 if (iflags
& IT85_RDAI
)
1085 ret
|= ITE_IRQ_RX_FIFO
;
1086 if (iflags
& IT85_RFOI
)
1087 ret
|= ITE_IRQ_RX_FIFO_OVERRUN
;
1092 /* set the carrier parameters; to be called with the spinlock held */
1093 static void it8709_set_carrier_params(struct ite_dev
*dev
, bool high_freq
,
1094 bool use_demodulator
,
1095 u8 carrier_freq_bits
, u8 allowance_bits
,
1096 u8 pulse_width_bits
)
1100 ite_dbg("%s called", __func__
);
1102 val
= (it8709_rr(dev
, IT85_C0CFR
)
1103 &~(IT85_HCFS
| IT85_CFQ
)) |
1109 it8709_wr(dev
, val
, IT85_C0CFR
);
1111 /* program the C0RCR register */
1112 val
= it8709_rr(dev
, IT85_C0RCR
)
1113 & ~(IT85_RXEND
| IT85_RXDCR
);
1115 if (use_demodulator
)
1118 val
|= allowance_bits
;
1120 it8709_wr(dev
, val
, IT85_C0RCR
);
1122 /* program the C0TCR register */
1123 val
= it8709_rr(dev
, IT85_C0TCR
) & ~IT85_TXMPW
;
1124 val
|= pulse_width_bits
;
1125 it8709_wr(dev
, val
, IT85_C0TCR
);
1128 /* read up to buf_size bytes from the RX FIFO; to be called with the spinlock
1130 static int it8709_get_rx_bytes(struct ite_dev
*dev
, u8
* buf
, int buf_size
)
1134 ite_dbg("%s called", __func__
);
1136 /* read how many bytes are still in the FIFO */
1137 fifo
= it8709_rm(dev
, IT8709_RFSR
) & IT85_RXFBC
;
1139 while (fifo
> 0 && buf_size
> 0) {
1140 *(buf
++) = it8709_rm(dev
, IT8709_FIFO
+ read
);
1146 /* 'clear' the FIFO by setting the writing index to 0; this is
1147 * completely bound to be racy, but we can't help it, since it's a
1148 * limitation of the protocol */
1149 it8709_wm(dev
, 0, IT8709_RFSR
);
1154 /* return how many bytes are still in the FIFO; this will be called
1155 * with the device spinlock NOT HELD while waiting for the TX FIFO to get
1156 * empty; let's expect this won't be a problem */
1157 static int it8709_get_tx_used_slots(struct ite_dev
*dev
)
1159 ite_dbg("%s called", __func__
);
1161 return it8709_rr(dev
, IT85_C0TFSR
) & IT85_TXFBC
;
1164 /* put a byte to the TX fifo; this should be called with the spinlock held */
1165 static void it8709_put_tx_byte(struct ite_dev
*dev
, u8 value
)
1167 it8709_wr(dev
, value
, IT85_C0DR
);
1170 /* idle the receiver so that we won't receive samples until another
1171 pulse is detected; this must be called with the device spinlock held */
1172 static void it8709_idle_rx(struct ite_dev
*dev
)
1174 ite_dbg("%s called", __func__
);
1176 /* disable streaming by clearing RXACT writing it as 1 */
1177 it8709_wr(dev
, it8709_rr(dev
, IT85_C0RCR
) | IT85_RXACT
,
1180 /* clear the FIFO */
1181 it8709_wr(dev
, it8709_rr(dev
, IT85_C0MSTCR
) | IT85_FIFOCLR
,
1185 /* disable the receiver; this must be called with the device spinlock held */
1186 static void it8709_disable_rx(struct ite_dev
*dev
)
1188 ite_dbg("%s called", __func__
);
1190 /* disable the receiver interrupts */
1191 it8709_wr(dev
, it8709_rr(dev
, IT85_C0IER
) &
1192 ~(IT85_RDAIE
| IT85_RFOIE
),
1195 /* disable the receiver */
1196 it8709_wr(dev
, it8709_rr(dev
, IT85_C0RCR
) & ~IT85_RXEN
,
1199 /* clear the FIFO and RXACT (actually RXACT should have been cleared
1200 * in the previous it8709_wr(dev, ) call) */
1201 it8709_idle_rx(dev
);
1204 /* enable the receiver; this must be called with the device spinlock held */
1205 static void it8709_enable_rx(struct ite_dev
*dev
)
1207 ite_dbg("%s called", __func__
);
1209 /* enable the receiver by setting RXEN */
1210 it8709_wr(dev
, it8709_rr(dev
, IT85_C0RCR
) | IT85_RXEN
,
1213 /* just prepare it to idle for the next reception */
1214 it8709_idle_rx(dev
);
1216 /* enable the receiver interrupts and master enable flag */
1217 it8709_wr(dev
, it8709_rr(dev
, IT85_C0IER
)
1218 |IT85_RDAIE
| IT85_RFOIE
| IT85_IEC
,
1222 /* disable the transmitter interrupt; this must be called with the device
1224 static void it8709_disable_tx_interrupt(struct ite_dev
*dev
)
1226 ite_dbg("%s called", __func__
);
1228 /* disable the transmitter interrupts */
1229 it8709_wr(dev
, it8709_rr(dev
, IT85_C0IER
) & ~IT85_TLDLIE
,
1233 /* enable the transmitter interrupt; this must be called with the device
1235 static void it8709_enable_tx_interrupt(struct ite_dev
*dev
)
1237 ite_dbg("%s called", __func__
);
1239 /* enable the transmitter interrupts and master enable flag */
1240 it8709_wr(dev
, it8709_rr(dev
, IT85_C0IER
)
1241 |IT85_TLDLIE
| IT85_IEC
,
1245 /* disable the device; this must be called with the device spinlock held */
1246 static void it8709_disable(struct ite_dev
*dev
)
1248 ite_dbg("%s called", __func__
);
1250 /* clear out all interrupt enable flags */
1253 IT85_C0IER
) & ~(IT85_IEC
| IT85_RFOIE
|
1255 IT85_TLDLIE
), IT85_C0IER
);
1257 /* disable the receiver */
1258 it8709_disable_rx(dev
);
1260 /* erase the FIFO */
1261 it8709_wr(dev
, IT85_FIFOCLR
| it8709_rr(dev
, IT85_C0MSTCR
),
1265 /* initialize the hardware */
1266 static void it8709_init_hardware(struct ite_dev
*dev
)
1268 ite_dbg("%s called", __func__
);
1270 /* disable all the interrupts */
1273 IT85_C0IER
) & ~(IT85_IEC
| IT85_RFOIE
|
1275 IT85_TLDLIE
), IT85_C0IER
);
1277 /* program the baud rate divisor */
1278 it8709_wr(dev
, ITE_BAUDRATE_DIVISOR
& 0xff, IT85_C0BDLR
);
1279 it8709_wr(dev
, (ITE_BAUDRATE_DIVISOR
>> 8) & 0xff,
1282 /* program the C0MSTCR register defaults */
1283 it8709_wr(dev
, (it8709_rr(dev
, IT85_C0MSTCR
) & ~(IT85_ILSEL
|
1290 | IT85_FIFOTL_DEFAULT
, IT85_C0MSTCR
);
1292 /* program the C0RCR register defaults */
1294 (it8709_rr(dev
, IT85_C0RCR
) &
1295 ~(IT85_RXEN
| IT85_RDWOS
| IT85_RXEND
1296 | IT85_RXACT
| IT85_RXDCR
)) |
1297 ITE_RXDCR_DEFAULT
, IT85_C0RCR
);
1299 /* program the C0TCR register defaults */
1300 it8709_wr(dev
, (it8709_rr(dev
, IT85_C0TCR
)
1301 &~(IT85_TXMPM
| IT85_TXMPW
))
1302 |IT85_TXRLE
| IT85_TXENDF
|
1303 IT85_TXMPM_DEFAULT
|
1304 IT85_TXMPW_DEFAULT
, IT85_C0TCR
);
1306 /* program the carrier parameters */
1307 ite_set_carrier_params(dev
);
1311 /* generic hardware setup/teardown code */
1313 /* activate the device for use */
1314 static int ite_open(struct rc_dev
*rcdev
)
1316 struct ite_dev
*dev
= rcdev
->priv
;
1317 unsigned long flags
;
1319 ite_dbg("%s called", __func__
);
1321 spin_lock_irqsave(&dev
->lock
, flags
);
1324 /* enable the receiver */
1325 dev
->params
.enable_rx(dev
);
1327 spin_unlock_irqrestore(&dev
->lock
, flags
);
1332 /* deactivate the device for use */
1333 static void ite_close(struct rc_dev
*rcdev
)
1335 struct ite_dev
*dev
= rcdev
->priv
;
1336 unsigned long flags
;
1338 ite_dbg("%s called", __func__
);
1340 spin_lock_irqsave(&dev
->lock
, flags
);
1341 dev
->in_use
= false;
1343 /* wait for any transmission to end */
1344 spin_unlock_irqrestore(&dev
->lock
, flags
);
1345 wait_event_interruptible(dev
->tx_ended
, !dev
->transmitting
);
1346 spin_lock_irqsave(&dev
->lock
, flags
);
1348 dev
->params
.disable(dev
);
1350 spin_unlock_irqrestore(&dev
->lock
, flags
);
1353 /* supported models and their parameters */
1354 static const struct ite_dev_params ite_dev_descs
[] = {
1356 .model
= "ITE8704 CIR transceiver",
1357 .io_region_size
= IT87_IOREG_LENGTH
,
1358 .hw_tx_capable
= true,
1359 .sample_period
= (u32
) (1000000000ULL / 115200),
1360 .tx_carrier_freq
= 38000,
1361 .tx_duty_cycle
= 33,
1362 .rx_low_carrier_freq
= 0,
1363 .rx_high_carrier_freq
= 0,
1366 .get_irq_causes
= it87_get_irq_causes
,
1367 .enable_rx
= it87_enable_rx
,
1368 .idle_rx
= it87_idle_rx
,
1369 .disable_rx
= it87_idle_rx
,
1370 .get_rx_bytes
= it87_get_rx_bytes
,
1371 .enable_tx_interrupt
= it87_enable_tx_interrupt
,
1372 .disable_tx_interrupt
= it87_disable_tx_interrupt
,
1373 .get_tx_used_slots
= it87_get_tx_used_slots
,
1374 .put_tx_byte
= it87_put_tx_byte
,
1375 .disable
= it87_disable
,
1376 .init_hardware
= it87_init_hardware
,
1377 .set_carrier_params
= it87_set_carrier_params
,
1380 .model
= "ITE8713 CIR transceiver",
1381 .io_region_size
= IT87_IOREG_LENGTH
,
1382 .hw_tx_capable
= true,
1383 .sample_period
= (u32
) (1000000000ULL / 115200),
1384 .tx_carrier_freq
= 38000,
1385 .tx_duty_cycle
= 33,
1386 .rx_low_carrier_freq
= 0,
1387 .rx_high_carrier_freq
= 0,
1390 .get_irq_causes
= it87_get_irq_causes
,
1391 .enable_rx
= it87_enable_rx
,
1392 .idle_rx
= it87_idle_rx
,
1393 .disable_rx
= it87_idle_rx
,
1394 .get_rx_bytes
= it87_get_rx_bytes
,
1395 .enable_tx_interrupt
= it87_enable_tx_interrupt
,
1396 .disable_tx_interrupt
= it87_disable_tx_interrupt
,
1397 .get_tx_used_slots
= it87_get_tx_used_slots
,
1398 .put_tx_byte
= it87_put_tx_byte
,
1399 .disable
= it87_disable
,
1400 .init_hardware
= it87_init_hardware
,
1401 .set_carrier_params
= it87_set_carrier_params
,
1404 .model
= "ITE8708 CIR transceiver",
1405 .io_region_size
= IT8708_IOREG_LENGTH
,
1406 .hw_tx_capable
= true,
1407 .sample_period
= (u32
) (1000000000ULL / 115200),
1408 .tx_carrier_freq
= 38000,
1409 .tx_duty_cycle
= 33,
1410 .rx_low_carrier_freq
= 0,
1411 .rx_high_carrier_freq
= 0,
1414 .get_irq_causes
= it8708_get_irq_causes
,
1415 .enable_rx
= it8708_enable_rx
,
1416 .idle_rx
= it8708_idle_rx
,
1417 .disable_rx
= it8708_idle_rx
,
1418 .get_rx_bytes
= it8708_get_rx_bytes
,
1419 .enable_tx_interrupt
= it8708_enable_tx_interrupt
,
1420 .disable_tx_interrupt
=
1421 it8708_disable_tx_interrupt
,
1422 .get_tx_used_slots
= it8708_get_tx_used_slots
,
1423 .put_tx_byte
= it8708_put_tx_byte
,
1424 .disable
= it8708_disable
,
1425 .init_hardware
= it8708_init_hardware
,
1426 .set_carrier_params
= it8708_set_carrier_params
,
1429 .model
= "ITE8709 CIR transceiver",
1430 .io_region_size
= IT8709_IOREG_LENGTH
,
1431 .hw_tx_capable
= true,
1432 .sample_period
= (u32
) (1000000000ULL / 115200),
1433 .tx_carrier_freq
= 38000,
1434 .tx_duty_cycle
= 33,
1435 .rx_low_carrier_freq
= 0,
1436 .rx_high_carrier_freq
= 0,
1439 .get_irq_causes
= it8709_get_irq_causes
,
1440 .enable_rx
= it8709_enable_rx
,
1441 .idle_rx
= it8709_idle_rx
,
1442 .disable_rx
= it8709_idle_rx
,
1443 .get_rx_bytes
= it8709_get_rx_bytes
,
1444 .enable_tx_interrupt
= it8709_enable_tx_interrupt
,
1445 .disable_tx_interrupt
=
1446 it8709_disable_tx_interrupt
,
1447 .get_tx_used_slots
= it8709_get_tx_used_slots
,
1448 .put_tx_byte
= it8709_put_tx_byte
,
1449 .disable
= it8709_disable
,
1450 .init_hardware
= it8709_init_hardware
,
1451 .set_carrier_params
= it8709_set_carrier_params
,
1455 static const struct pnp_device_id ite_ids
[] = {
1456 {"ITE8704", 0}, /* Default model */
1457 {"ITE8713", 1}, /* CIR found in EEEBox 1501U */
1458 {"ITE8708", 2}, /* Bridged IT8512 */
1459 {"ITE8709", 3}, /* SRAM-Bridged IT8512 */
1463 /* allocate memory, probe hardware, and initialize everything */
1464 static int ite_probe(struct pnp_dev
*pdev
, const struct pnp_device_id
1467 const struct ite_dev_params
*dev_desc
= NULL
;
1468 struct ite_dev
*itdev
= NULL
;
1469 struct rc_dev
*rdev
= NULL
;
1473 ite_dbg("%s called", __func__
);
1475 itdev
= kzalloc(sizeof(struct ite_dev
), GFP_KERNEL
);
1479 /* input device for IR remote (and tx) */
1480 rdev
= rc_allocate_device();
1486 /* get the model number */
1487 model_no
= (int)dev_id
->driver_data
;
1488 ite_pr(KERN_NOTICE
, "Auto-detected model: %s\n",
1489 ite_dev_descs
[model_no
].model
);
1491 if (model_number
>= 0 && model_number
< ARRAY_SIZE(ite_dev_descs
)) {
1492 model_no
= model_number
;
1493 ite_pr(KERN_NOTICE
, "The model has been fixed by a module "
1497 ite_pr(KERN_NOTICE
, "Using model: %s\n", ite_dev_descs
[model_no
].model
);
1499 /* get the description for the device */
1500 dev_desc
= &ite_dev_descs
[model_no
];
1502 /* validate pnp resources */
1503 if (!pnp_port_valid(pdev
, 0) ||
1504 pnp_port_len(pdev
, 0) != dev_desc
->io_region_size
) {
1505 dev_err(&pdev
->dev
, "IR PNP Port not valid!\n");
1509 if (!pnp_irq_valid(pdev
, 0)) {
1510 dev_err(&pdev
->dev
, "PNP IRQ not valid!\n");
1514 /* store resource values */
1515 itdev
->cir_addr
= pnp_port_start(pdev
, 0);
1516 itdev
->cir_irq
= pnp_irq(pdev
, 0);
1518 /* initialize spinlocks */
1519 spin_lock_init(&itdev
->lock
);
1521 /* initialize raw event */
1522 init_ir_raw_event(&itdev
->rawir
);
1525 /* now claim resources */
1526 if (!request_region(itdev
->cir_addr
,
1527 dev_desc
->io_region_size
, ITE_DRIVER_NAME
))
1530 if (request_irq(itdev
->cir_irq
, ite_cir_isr
, IRQF_SHARED
,
1531 ITE_DRIVER_NAME
, (void *)itdev
))
1534 /* set driver data into the pnp device */
1535 pnp_set_drvdata(pdev
, itdev
);
1538 /* initialize waitqueues for transmission */
1539 init_waitqueue_head(&itdev
->tx_queue
);
1540 init_waitqueue_head(&itdev
->tx_ended
);
1542 /* copy model-specific parameters */
1543 itdev
->params
= *dev_desc
;
1545 /* apply any overrides */
1546 if (sample_period
> 0)
1547 itdev
->params
.sample_period
= sample_period
;
1549 if (tx_carrier_freq
> 0)
1550 itdev
->params
.tx_carrier_freq
= tx_carrier_freq
;
1552 if (tx_duty_cycle
> 0 && tx_duty_cycle
<= 100)
1553 itdev
->params
.tx_duty_cycle
= tx_duty_cycle
;
1555 if (rx_low_carrier_freq
> 0)
1556 itdev
->params
.rx_low_carrier_freq
= rx_low_carrier_freq
;
1558 if (rx_high_carrier_freq
> 0)
1559 itdev
->params
.rx_high_carrier_freq
= rx_high_carrier_freq
;
1561 /* print out parameters */
1562 ite_pr(KERN_NOTICE
, "TX-capable: %d\n", (int)
1563 itdev
->params
.hw_tx_capable
);
1564 ite_pr(KERN_NOTICE
, "Sample period (ns): %ld\n", (long)
1565 itdev
->params
.sample_period
);
1566 ite_pr(KERN_NOTICE
, "TX carrier frequency (Hz): %d\n", (int)
1567 itdev
->params
.tx_carrier_freq
);
1568 ite_pr(KERN_NOTICE
, "TX duty cycle (%%): %d\n", (int)
1569 itdev
->params
.tx_duty_cycle
);
1570 ite_pr(KERN_NOTICE
, "RX low carrier frequency (Hz): %d\n", (int)
1571 itdev
->params
.rx_low_carrier_freq
);
1572 ite_pr(KERN_NOTICE
, "RX high carrier frequency (Hz): %d\n", (int)
1573 itdev
->params
.rx_high_carrier_freq
);
1575 /* set up hardware initial state */
1576 itdev
->params
.init_hardware(itdev
);
1578 /* set up ir-core props */
1580 rdev
->driver_type
= RC_DRIVER_IR_RAW
;
1581 rdev
->allowed_protos
= RC_TYPE_ALL
;
1582 rdev
->open
= ite_open
;
1583 rdev
->close
= ite_close
;
1584 rdev
->s_idle
= ite_s_idle
;
1585 rdev
->s_rx_carrier_range
= ite_set_rx_carrier_range
;
1586 rdev
->min_timeout
= ITE_MIN_IDLE_TIMEOUT
;
1587 rdev
->max_timeout
= ITE_MAX_IDLE_TIMEOUT
;
1588 rdev
->timeout
= ITE_IDLE_TIMEOUT
;
1589 rdev
->rx_resolution
= ITE_BAUDRATE_DIVISOR
*
1590 itdev
->params
.sample_period
;
1591 rdev
->tx_resolution
= ITE_BAUDRATE_DIVISOR
*
1592 itdev
->params
.sample_period
;
1594 /* set up transmitter related values if needed */
1595 if (itdev
->params
.hw_tx_capable
) {
1596 rdev
->tx_ir
= ite_tx_ir
;
1597 rdev
->s_tx_carrier
= ite_set_tx_carrier
;
1598 rdev
->s_tx_duty_cycle
= ite_set_tx_duty_cycle
;
1601 rdev
->input_name
= dev_desc
->model
;
1602 rdev
->input_id
.bustype
= BUS_HOST
;
1603 rdev
->input_id
.vendor
= PCI_VENDOR_ID_ITE
;
1604 rdev
->input_id
.product
= 0;
1605 rdev
->input_id
.version
= 0;
1606 rdev
->driver_name
= ITE_DRIVER_NAME
;
1607 rdev
->map_name
= RC_MAP_RC6_MCE
;
1609 ret
= rc_register_device(rdev
);
1614 ite_pr(KERN_NOTICE
, "driver has been successfully loaded\n");
1620 free_irq(itdev
->cir_irq
, itdev
);
1622 if (itdev
->cir_addr
)
1623 release_region(itdev
->cir_addr
, itdev
->params
.io_region_size
);
1625 rc_free_device(rdev
);
1631 static void __devexit
ite_remove(struct pnp_dev
*pdev
)
1633 struct ite_dev
*dev
= pnp_get_drvdata(pdev
);
1634 unsigned long flags
;
1636 ite_dbg("%s called", __func__
);
1638 spin_lock_irqsave(&dev
->lock
, flags
);
1640 /* disable hardware */
1641 dev
->params
.disable(dev
);
1643 spin_unlock_irqrestore(&dev
->lock
, flags
);
1645 /* free resources */
1646 free_irq(dev
->cir_irq
, dev
);
1647 release_region(dev
->cir_addr
, dev
->params
.io_region_size
);
1649 rc_unregister_device(dev
->rdev
);
1654 static int ite_suspend(struct pnp_dev
*pdev
, pm_message_t state
)
1656 struct ite_dev
*dev
= pnp_get_drvdata(pdev
);
1657 unsigned long flags
;
1659 ite_dbg("%s called", __func__
);
1661 spin_lock_irqsave(&dev
->lock
, flags
);
1663 /* disable all interrupts */
1664 dev
->params
.disable(dev
);
1666 spin_unlock_irqrestore(&dev
->lock
, flags
);
1671 static int ite_resume(struct pnp_dev
*pdev
)
1674 struct ite_dev
*dev
= pnp_get_drvdata(pdev
);
1675 unsigned long flags
;
1677 ite_dbg("%s called", __func__
);
1679 spin_lock_irqsave(&dev
->lock
, flags
);
1681 if (dev
->transmitting
) {
1682 /* wake up the transmitter */
1683 wake_up_interruptible(&dev
->tx_queue
);
1685 /* enable the receiver */
1686 dev
->params
.enable_rx(dev
);
1689 spin_unlock_irqrestore(&dev
->lock
, flags
);
1694 static void ite_shutdown(struct pnp_dev
*pdev
)
1696 struct ite_dev
*dev
= pnp_get_drvdata(pdev
);
1697 unsigned long flags
;
1699 ite_dbg("%s called", __func__
);
1701 spin_lock_irqsave(&dev
->lock
, flags
);
1703 /* disable all interrupts */
1704 dev
->params
.disable(dev
);
1706 spin_unlock_irqrestore(&dev
->lock
, flags
);
1709 static struct pnp_driver ite_driver
= {
1710 .name
= ITE_DRIVER_NAME
,
1711 .id_table
= ite_ids
,
1713 .remove
= __devexit_p(ite_remove
),
1714 .suspend
= ite_suspend
,
1715 .resume
= ite_resume
,
1716 .shutdown
= ite_shutdown
,
1721 return pnp_register_driver(&ite_driver
);
1726 pnp_unregister_driver(&ite_driver
);
1729 MODULE_DEVICE_TABLE(pnp
, ite_ids
);
1730 MODULE_DESCRIPTION("ITE Tech Inc. IT8712F/ITE8512F CIR driver");
1732 MODULE_AUTHOR("Juan J. Garcia de Soria <skandalfo@gmail.com>");
1733 MODULE_LICENSE("GPL");
1735 module_init(ite_init
);
1736 module_exit(ite_exit
);