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 the receive interrupt */
289 if (iflags
& (ITE_IRQ_RX_FIFO
| ITE_IRQ_RX_FIFO_OVERRUN
)) {
290 /* read the FIFO bytes */
292 dev
->params
.get_rx_bytes(dev
, rx_buf
,
296 /* drop the spinlock, since the ir-core layer
297 * may call us back again through
299 spin_unlock_irqrestore(&dev
->
303 /* decode the data we've just received */
304 ite_decode_bytes(dev
, rx_buf
,
307 /* reacquire the spinlock */
308 spin_lock_irqsave(&dev
->lock
,
311 /* mark the interrupt as serviced */
312 ret
= IRQ_RETVAL(IRQ_HANDLED
);
314 } else if (iflags
& ITE_IRQ_TX_FIFO
) {
315 /* FIFO space available interrupt */
316 ite_dbg_verbose("got interrupt for TX FIFO");
318 /* wake any sleeping transmitter */
319 wake_up_interruptible(&dev
->tx_queue
);
321 /* mark the interrupt as serviced */
322 ret
= IRQ_RETVAL(IRQ_HANDLED
);
325 /* drop the spinlock */
326 spin_unlock_irqrestore(&dev
->lock
, flags
);
328 ite_dbg_verbose("%s done returning %d", __func__
, (int)ret
);
333 /* set the rx carrier freq range, guess it's in Hz... */
334 static int ite_set_rx_carrier_range(struct rc_dev
*rcdev
, u32 carrier_low
, u32
338 struct ite_dev
*dev
= rcdev
->priv
;
340 spin_lock_irqsave(&dev
->lock
, flags
);
341 dev
->params
.rx_low_carrier_freq
= carrier_low
;
342 dev
->params
.rx_high_carrier_freq
= carrier_high
;
343 ite_set_carrier_params(dev
);
344 spin_unlock_irqrestore(&dev
->lock
, flags
);
349 /* set the tx carrier freq, guess it's in Hz... */
350 static int ite_set_tx_carrier(struct rc_dev
*rcdev
, u32 carrier
)
353 struct ite_dev
*dev
= rcdev
->priv
;
355 spin_lock_irqsave(&dev
->lock
, flags
);
356 dev
->params
.tx_carrier_freq
= carrier
;
357 ite_set_carrier_params(dev
);
358 spin_unlock_irqrestore(&dev
->lock
, flags
);
363 /* set the tx duty cycle by controlling the pulse width */
364 static int ite_set_tx_duty_cycle(struct rc_dev
*rcdev
, u32 duty_cycle
)
367 struct ite_dev
*dev
= rcdev
->priv
;
369 spin_lock_irqsave(&dev
->lock
, flags
);
370 dev
->params
.tx_duty_cycle
= duty_cycle
;
371 ite_set_carrier_params(dev
);
372 spin_unlock_irqrestore(&dev
->lock
, flags
);
377 /* transmit out IR pulses; what you get here is a batch of alternating
378 * pulse/space/pulse/space lengths that we should write out completely through
379 * the FIFO, blocking on a full FIFO */
380 static int ite_tx_ir(struct rc_dev
*rcdev
, unsigned *txbuf
, unsigned n
)
383 struct ite_dev
*dev
= rcdev
->priv
;
384 bool is_pulse
= false;
385 int remaining_us
, fifo_avail
, fifo_remaining
, last_idx
= 0;
386 int max_rle_us
, next_rle_us
;
388 u8 last_sent
[ITE_TX_FIFO_LEN
];
391 ite_dbg("%s called", __func__
);
393 /* clear the array just in case */
394 memset(last_sent
, 0, ARRAY_SIZE(last_sent
));
396 spin_lock_irqsave(&dev
->lock
, flags
);
398 /* let everybody know we're now transmitting */
399 dev
->transmitting
= true;
401 /* and set the carrier values for transmission */
402 ite_set_carrier_params(dev
);
404 /* calculate how much time we can send in one byte */
406 (ITE_BAUDRATE_DIVISOR
* dev
->params
.sample_period
*
407 ITE_TX_MAX_RLE
) / 1000;
409 /* disable the receiver */
410 dev
->params
.disable_rx(dev
);
412 /* this is where we'll begin filling in the FIFO, until it's full.
413 * then we'll just activate the interrupt, wait for it to wake us up
414 * again, disable it, continue filling the FIFO... until everything
415 * has been pushed out */
417 ITE_TX_FIFO_LEN
- dev
->params
.get_tx_used_slots(dev
);
419 while (n
> 0 && dev
->in_use
) {
420 /* transmit the next sample */
421 is_pulse
= !is_pulse
;
422 remaining_us
= *(txbuf
++);
426 ((is_pulse
) ? "pulse" : "space"),
430 /* repeat while the pulse is non-zero length */
431 while (remaining_us
> 0 && dev
->in_use
) {
432 if (remaining_us
> max_rle_us
)
433 next_rle_us
= max_rle_us
;
436 next_rle_us
= remaining_us
;
438 remaining_us
-= next_rle_us
;
440 /* check what's the length we have to pump out */
441 val
= (ITE_TX_MAX_RLE
* next_rle_us
) / max_rle_us
;
443 /* put it into the sent buffer */
444 last_sent
[last_idx
++] = val
;
445 last_idx
&= (ITE_TX_FIFO_LEN
);
447 /* encode it for 7 bits */
448 val
= (val
- 1) & ITE_TX_RLE_MASK
;
450 /* take into account pulse/space prefix */
458 * if we get to 0 available, read again, just in case
459 * some other slot got freed
462 fifo_avail
= ITE_TX_FIFO_LEN
- dev
->params
.get_tx_used_slots(dev
);
464 /* if it's still full */
465 if (fifo_avail
<= 0) {
466 /* enable the tx interrupt */
468 enable_tx_interrupt(dev
);
470 /* drop the spinlock */
471 spin_unlock_irqrestore(&dev
->lock
, flags
);
473 /* wait for the FIFO to empty enough */
474 wait_event_interruptible(dev
->tx_queue
, (fifo_avail
= ITE_TX_FIFO_LEN
- dev
->params
.get_tx_used_slots(dev
)) >= 8);
476 /* get the spinlock again */
477 spin_lock_irqsave(&dev
->lock
, flags
);
479 /* disable the tx interrupt again. */
481 disable_tx_interrupt(dev
);
484 /* now send the byte through the FIFO */
485 dev
->params
.put_tx_byte(dev
, val
);
490 /* wait and don't return until the whole FIFO has been sent out;
491 * otherwise we could configure the RX carrier params instead of the
492 * TX ones while the transmission is still being performed! */
493 fifo_remaining
= dev
->params
.get_tx_used_slots(dev
);
495 while (fifo_remaining
> 0) {
498 last_idx
&= (ITE_TX_FIFO_LEN
- 1);
499 remaining_us
+= last_sent
[last_idx
];
501 remaining_us
= (remaining_us
* max_rle_us
) / (ITE_TX_MAX_RLE
);
503 /* drop the spinlock while we sleep */
504 spin_unlock_irqrestore(&dev
->lock
, flags
);
506 /* sleep remaining_us microseconds */
507 mdelay(DIV_ROUND_UP(remaining_us
, 1000));
509 /* reacquire the spinlock */
510 spin_lock_irqsave(&dev
->lock
, flags
);
512 /* now we're not transmitting anymore */
513 dev
->transmitting
= false;
515 /* and set the carrier values for reception */
516 ite_set_carrier_params(dev
);
518 /* reenable the receiver */
520 dev
->params
.enable_rx(dev
);
522 /* notify transmission end */
523 wake_up_interruptible(&dev
->tx_ended
);
525 spin_unlock_irqrestore(&dev
->lock
, flags
);
530 /* idle the receiver if needed */
531 static void ite_s_idle(struct rc_dev
*rcdev
, bool enable
)
534 struct ite_dev
*dev
= rcdev
->priv
;
536 ite_dbg("%s called", __func__
);
539 spin_lock_irqsave(&dev
->lock
, flags
);
540 dev
->params
.idle_rx(dev
);
541 spin_unlock_irqrestore(&dev
->lock
, flags
);
546 /* IT8712F HW-specific functions */
548 /* retrieve a bitmask of the current causes for a pending interrupt; this may
549 * be composed of ITE_IRQ_TX_FIFO, ITE_IRQ_RX_FIFO and ITE_IRQ_RX_FIFO_OVERRUN
551 static int it87_get_irq_causes(struct ite_dev
*dev
)
556 ite_dbg("%s called", __func__
);
558 /* read the interrupt flags */
559 iflags
= inb(dev
->cir_addr
+ IT87_IIR
) & IT87_II
;
563 ret
= ITE_IRQ_RX_FIFO
;
566 ret
= ITE_IRQ_RX_FIFO_OVERRUN
;
569 ret
= ITE_IRQ_TX_FIFO
;
576 /* set the carrier parameters; to be called with the spinlock held */
577 static void it87_set_carrier_params(struct ite_dev
*dev
, bool high_freq
,
578 bool use_demodulator
,
579 u8 carrier_freq_bits
, u8 allowance_bits
,
584 ite_dbg("%s called", __func__
);
586 /* program the RCR register */
587 val
= inb(dev
->cir_addr
+ IT87_RCR
)
588 & ~(IT87_HCFS
| IT87_RXEND
| IT87_RXDCR
);
596 val
|= allowance_bits
;
598 outb(val
, dev
->cir_addr
+ IT87_RCR
);
600 /* program the TCR2 register */
601 outb((carrier_freq_bits
<< IT87_CFQ_SHIFT
) | pulse_width_bits
,
602 dev
->cir_addr
+ IT87_TCR2
);
605 /* read up to buf_size bytes from the RX FIFO; to be called with the spinlock
607 static int it87_get_rx_bytes(struct ite_dev
*dev
, u8
* buf
, int buf_size
)
611 ite_dbg("%s called", __func__
);
613 /* read how many bytes are still in the FIFO */
614 fifo
= inb(dev
->cir_addr
+ IT87_RSR
) & IT87_RXFBC
;
616 while (fifo
> 0 && buf_size
> 0) {
617 *(buf
++) = inb(dev
->cir_addr
+ IT87_DR
);
626 /* return how many bytes are still in the FIFO; this will be called
627 * with the device spinlock NOT HELD while waiting for the TX FIFO to get
628 * empty; let's expect this won't be a problem */
629 static int it87_get_tx_used_slots(struct ite_dev
*dev
)
631 ite_dbg("%s called", __func__
);
633 return inb(dev
->cir_addr
+ IT87_TSR
) & IT87_TXFBC
;
636 /* put a byte to the TX fifo; this should be called with the spinlock held */
637 static void it87_put_tx_byte(struct ite_dev
*dev
, u8 value
)
639 outb(value
, dev
->cir_addr
+ IT87_DR
);
642 /* idle the receiver so that we won't receive samples until another
643 pulse is detected; this must be called with the device spinlock held */
644 static void it87_idle_rx(struct ite_dev
*dev
)
646 ite_dbg("%s called", __func__
);
648 /* disable streaming by clearing RXACT writing it as 1 */
649 outb(inb(dev
->cir_addr
+ IT87_RCR
) | IT87_RXACT
,
650 dev
->cir_addr
+ IT87_RCR
);
653 outb(inb(dev
->cir_addr
+ IT87_TCR1
) | IT87_FIFOCLR
,
654 dev
->cir_addr
+ IT87_TCR1
);
657 /* disable the receiver; this must be called with the device spinlock held */
658 static void it87_disable_rx(struct ite_dev
*dev
)
660 ite_dbg("%s called", __func__
);
662 /* disable the receiver interrupts */
663 outb(inb(dev
->cir_addr
+ IT87_IER
) & ~(IT87_RDAIE
| IT87_RFOIE
),
664 dev
->cir_addr
+ IT87_IER
);
666 /* disable the receiver */
667 outb(inb(dev
->cir_addr
+ IT87_RCR
) & ~IT87_RXEN
,
668 dev
->cir_addr
+ IT87_RCR
);
670 /* clear the FIFO and RXACT (actually RXACT should have been cleared
671 * in the previous outb() call) */
675 /* enable the receiver; this must be called with the device spinlock held */
676 static void it87_enable_rx(struct ite_dev
*dev
)
678 ite_dbg("%s called", __func__
);
680 /* enable the receiver by setting RXEN */
681 outb(inb(dev
->cir_addr
+ IT87_RCR
) | IT87_RXEN
,
682 dev
->cir_addr
+ IT87_RCR
);
684 /* just prepare it to idle for the next reception */
687 /* enable the receiver interrupts and master enable flag */
688 outb(inb(dev
->cir_addr
+ IT87_IER
) | IT87_RDAIE
| IT87_RFOIE
| IT87_IEC
,
689 dev
->cir_addr
+ IT87_IER
);
692 /* disable the transmitter interrupt; this must be called with the device
694 static void it87_disable_tx_interrupt(struct ite_dev
*dev
)
696 ite_dbg("%s called", __func__
);
698 /* disable the transmitter interrupts */
699 outb(inb(dev
->cir_addr
+ IT87_IER
) & ~IT87_TLDLIE
,
700 dev
->cir_addr
+ IT87_IER
);
703 /* enable the transmitter interrupt; this must be called with the device
705 static void it87_enable_tx_interrupt(struct ite_dev
*dev
)
707 ite_dbg("%s called", __func__
);
709 /* enable the transmitter interrupts and master enable flag */
710 outb(inb(dev
->cir_addr
+ IT87_IER
) | IT87_TLDLIE
| IT87_IEC
,
711 dev
->cir_addr
+ IT87_IER
);
714 /* disable the device; this must be called with the device spinlock held */
715 static void it87_disable(struct ite_dev
*dev
)
717 ite_dbg("%s called", __func__
);
719 /* clear out all interrupt enable flags */
720 outb(inb(dev
->cir_addr
+ IT87_IER
) &
721 ~(IT87_IEC
| IT87_RFOIE
| IT87_RDAIE
| IT87_TLDLIE
),
722 dev
->cir_addr
+ IT87_IER
);
724 /* disable the receiver */
725 it87_disable_rx(dev
);
728 outb(IT87_FIFOCLR
| inb(dev
->cir_addr
+ IT87_TCR1
),
729 dev
->cir_addr
+ IT87_TCR1
);
732 /* initialize the hardware */
733 static void it87_init_hardware(struct ite_dev
*dev
)
735 ite_dbg("%s called", __func__
);
737 /* enable just the baud rate divisor register,
738 disabling all the interrupts at the same time */
739 outb((inb(dev
->cir_addr
+ IT87_IER
) &
740 ~(IT87_IEC
| IT87_RFOIE
| IT87_RDAIE
| IT87_TLDLIE
)) | IT87_BR
,
741 dev
->cir_addr
+ IT87_IER
);
743 /* write out the baud rate divisor */
744 outb(ITE_BAUDRATE_DIVISOR
& 0xff, dev
->cir_addr
+ IT87_BDLR
);
745 outb((ITE_BAUDRATE_DIVISOR
>> 8) & 0xff, dev
->cir_addr
+ IT87_BDHR
);
747 /* disable the baud rate divisor register again */
748 outb(inb(dev
->cir_addr
+ IT87_IER
) & ~IT87_BR
,
749 dev
->cir_addr
+ IT87_IER
);
751 /* program the RCR register defaults */
752 outb(ITE_RXDCR_DEFAULT
, dev
->cir_addr
+ IT87_RCR
);
754 /* program the TCR1 register */
755 outb(IT87_TXMPM_DEFAULT
| IT87_TXENDF
| IT87_TXRLE
756 | IT87_FIFOTL_DEFAULT
| IT87_FIFOCLR
,
757 dev
->cir_addr
+ IT87_TCR1
);
759 /* program the carrier parameters */
760 ite_set_carrier_params(dev
);
763 /* IT8512F on ITE8708 HW-specific functions */
765 /* retrieve a bitmask of the current causes for a pending interrupt; this may
766 * be composed of ITE_IRQ_TX_FIFO, ITE_IRQ_RX_FIFO and ITE_IRQ_RX_FIFO_OVERRUN
768 static int it8708_get_irq_causes(struct ite_dev
*dev
)
773 ite_dbg("%s called", __func__
);
775 /* read the interrupt flags */
776 iflags
= inb(dev
->cir_addr
+ IT8708_C0IIR
);
778 if (iflags
& IT85_TLDLI
)
779 ret
|= ITE_IRQ_TX_FIFO
;
780 if (iflags
& IT85_RDAI
)
781 ret
|= ITE_IRQ_RX_FIFO
;
782 if (iflags
& IT85_RFOI
)
783 ret
|= ITE_IRQ_RX_FIFO_OVERRUN
;
788 /* set the carrier parameters; to be called with the spinlock held */
789 static void it8708_set_carrier_params(struct ite_dev
*dev
, bool high_freq
,
790 bool use_demodulator
,
791 u8 carrier_freq_bits
, u8 allowance_bits
,
796 ite_dbg("%s called", __func__
);
798 /* program the C0CFR register, with HRAE=1 */
799 outb(inb(dev
->cir_addr
+ IT8708_BANKSEL
) | IT8708_HRAE
,
800 dev
->cir_addr
+ IT8708_BANKSEL
);
802 val
= (inb(dev
->cir_addr
+ IT8708_C0CFR
)
803 & ~(IT85_HCFS
| IT85_CFQ
)) | carrier_freq_bits
;
808 outb(val
, dev
->cir_addr
+ IT8708_C0CFR
);
810 outb(inb(dev
->cir_addr
+ IT8708_BANKSEL
) & ~IT8708_HRAE
,
811 dev
->cir_addr
+ IT8708_BANKSEL
);
813 /* program the C0RCR register */
814 val
= inb(dev
->cir_addr
+ IT8708_C0RCR
)
815 & ~(IT85_RXEND
| IT85_RXDCR
);
820 val
|= allowance_bits
;
822 outb(val
, dev
->cir_addr
+ IT8708_C0RCR
);
824 /* program the C0TCR register */
825 val
= inb(dev
->cir_addr
+ IT8708_C0TCR
) & ~IT85_TXMPW
;
826 val
|= pulse_width_bits
;
827 outb(val
, dev
->cir_addr
+ IT8708_C0TCR
);
830 /* read up to buf_size bytes from the RX FIFO; to be called with the spinlock
832 static int it8708_get_rx_bytes(struct ite_dev
*dev
, u8
* buf
, int buf_size
)
836 ite_dbg("%s called", __func__
);
838 /* read how many bytes are still in the FIFO */
839 fifo
= inb(dev
->cir_addr
+ IT8708_C0RFSR
) & IT85_RXFBC
;
841 while (fifo
> 0 && buf_size
> 0) {
842 *(buf
++) = inb(dev
->cir_addr
+ IT8708_C0DR
);
851 /* return how many bytes are still in the FIFO; this will be called
852 * with the device spinlock NOT HELD while waiting for the TX FIFO to get
853 * empty; let's expect this won't be a problem */
854 static int it8708_get_tx_used_slots(struct ite_dev
*dev
)
856 ite_dbg("%s called", __func__
);
858 return inb(dev
->cir_addr
+ IT8708_C0TFSR
) & IT85_TXFBC
;
861 /* put a byte to the TX fifo; this should be called with the spinlock held */
862 static void it8708_put_tx_byte(struct ite_dev
*dev
, u8 value
)
864 outb(value
, dev
->cir_addr
+ IT8708_C0DR
);
867 /* idle the receiver so that we won't receive samples until another
868 pulse is detected; this must be called with the device spinlock held */
869 static void it8708_idle_rx(struct ite_dev
*dev
)
871 ite_dbg("%s called", __func__
);
873 /* disable streaming by clearing RXACT writing it as 1 */
874 outb(inb(dev
->cir_addr
+ IT8708_C0RCR
) | IT85_RXACT
,
875 dev
->cir_addr
+ IT8708_C0RCR
);
878 outb(inb(dev
->cir_addr
+ IT8708_C0MSTCR
) | IT85_FIFOCLR
,
879 dev
->cir_addr
+ IT8708_C0MSTCR
);
882 /* disable the receiver; this must be called with the device spinlock held */
883 static void it8708_disable_rx(struct ite_dev
*dev
)
885 ite_dbg("%s called", __func__
);
887 /* disable the receiver interrupts */
888 outb(inb(dev
->cir_addr
+ IT8708_C0IER
) &
889 ~(IT85_RDAIE
| IT85_RFOIE
),
890 dev
->cir_addr
+ IT8708_C0IER
);
892 /* disable the receiver */
893 outb(inb(dev
->cir_addr
+ IT8708_C0RCR
) & ~IT85_RXEN
,
894 dev
->cir_addr
+ IT8708_C0RCR
);
896 /* clear the FIFO and RXACT (actually RXACT should have been cleared
897 * in the previous outb() call) */
901 /* enable the receiver; this must be called with the device spinlock held */
902 static void it8708_enable_rx(struct ite_dev
*dev
)
904 ite_dbg("%s called", __func__
);
906 /* enable the receiver by setting RXEN */
907 outb(inb(dev
->cir_addr
+ IT8708_C0RCR
) | IT85_RXEN
,
908 dev
->cir_addr
+ IT8708_C0RCR
);
910 /* just prepare it to idle for the next reception */
913 /* enable the receiver interrupts and master enable flag */
914 outb(inb(dev
->cir_addr
+ IT8708_C0IER
)
915 |IT85_RDAIE
| IT85_RFOIE
| IT85_IEC
,
916 dev
->cir_addr
+ IT8708_C0IER
);
919 /* disable the transmitter interrupt; this must be called with the device
921 static void it8708_disable_tx_interrupt(struct ite_dev
*dev
)
923 ite_dbg("%s called", __func__
);
925 /* disable the transmitter interrupts */
926 outb(inb(dev
->cir_addr
+ IT8708_C0IER
) & ~IT85_TLDLIE
,
927 dev
->cir_addr
+ IT8708_C0IER
);
930 /* enable the transmitter interrupt; this must be called with the device
932 static void it8708_enable_tx_interrupt(struct ite_dev
*dev
)
934 ite_dbg("%s called", __func__
);
936 /* enable the transmitter interrupts and master enable flag */
937 outb(inb(dev
->cir_addr
+ IT8708_C0IER
)
938 |IT85_TLDLIE
| IT85_IEC
,
939 dev
->cir_addr
+ IT8708_C0IER
);
942 /* disable the device; this must be called with the device spinlock held */
943 static void it8708_disable(struct ite_dev
*dev
)
945 ite_dbg("%s called", __func__
);
947 /* clear out all interrupt enable flags */
948 outb(inb(dev
->cir_addr
+ IT8708_C0IER
) &
949 ~(IT85_IEC
| IT85_RFOIE
| IT85_RDAIE
| IT85_TLDLIE
),
950 dev
->cir_addr
+ IT8708_C0IER
);
952 /* disable the receiver */
953 it8708_disable_rx(dev
);
956 outb(IT85_FIFOCLR
| inb(dev
->cir_addr
+ IT8708_C0MSTCR
),
957 dev
->cir_addr
+ IT8708_C0MSTCR
);
960 /* initialize the hardware */
961 static void it8708_init_hardware(struct ite_dev
*dev
)
963 ite_dbg("%s called", __func__
);
965 /* disable all the interrupts */
966 outb(inb(dev
->cir_addr
+ IT8708_C0IER
) &
967 ~(IT85_IEC
| IT85_RFOIE
| IT85_RDAIE
| IT85_TLDLIE
),
968 dev
->cir_addr
+ IT8708_C0IER
);
970 /* program the baud rate divisor */
971 outb(inb(dev
->cir_addr
+ IT8708_BANKSEL
) | IT8708_HRAE
,
972 dev
->cir_addr
+ IT8708_BANKSEL
);
974 outb(ITE_BAUDRATE_DIVISOR
& 0xff, dev
->cir_addr
+ IT8708_C0BDLR
);
975 outb((ITE_BAUDRATE_DIVISOR
>> 8) & 0xff,
976 dev
->cir_addr
+ IT8708_C0BDHR
);
978 outb(inb(dev
->cir_addr
+ IT8708_BANKSEL
) & ~IT8708_HRAE
,
979 dev
->cir_addr
+ IT8708_BANKSEL
);
981 /* program the C0MSTCR register defaults */
982 outb((inb(dev
->cir_addr
+ IT8708_C0MSTCR
) &
983 ~(IT85_ILSEL
| IT85_ILE
| IT85_FIFOTL
|
984 IT85_FIFOCLR
| IT85_RESET
)) |
986 dev
->cir_addr
+ IT8708_C0MSTCR
);
988 /* program the C0RCR register defaults */
989 outb((inb(dev
->cir_addr
+ IT8708_C0RCR
) &
990 ~(IT85_RXEN
| IT85_RDWOS
| IT85_RXEND
|
991 IT85_RXACT
| IT85_RXDCR
)) |
993 dev
->cir_addr
+ IT8708_C0RCR
);
995 /* program the C0TCR register defaults */
996 outb((inb(dev
->cir_addr
+ IT8708_C0TCR
) &
997 ~(IT85_TXMPM
| IT85_TXMPW
))
998 |IT85_TXRLE
| IT85_TXENDF
|
999 IT85_TXMPM_DEFAULT
| IT85_TXMPW_DEFAULT
,
1000 dev
->cir_addr
+ IT8708_C0TCR
);
1002 /* program the carrier parameters */
1003 ite_set_carrier_params(dev
);
1006 /* IT8512F on ITE8709 HW-specific functions */
1008 /* read a byte from the SRAM module */
1009 static inline u8
it8709_rm(struct ite_dev
*dev
, int index
)
1011 outb(index
, dev
->cir_addr
+ IT8709_RAM_IDX
);
1012 return inb(dev
->cir_addr
+ IT8709_RAM_VAL
);
1015 /* write a byte to the SRAM module */
1016 static inline void it8709_wm(struct ite_dev
*dev
, u8 val
, int index
)
1018 outb(index
, dev
->cir_addr
+ IT8709_RAM_IDX
);
1019 outb(val
, dev
->cir_addr
+ IT8709_RAM_VAL
);
1022 static void it8709_wait(struct ite_dev
*dev
)
1026 * loop until device tells it's ready to continue
1027 * iterations count is usually ~750 but can sometimes achieve 13000
1029 for (i
= 0; i
< 15000; i
++) {
1031 if (it8709_rm(dev
, IT8709_MODE
) == IT8709_IDLE
)
1036 /* read the value of a CIR register */
1037 static u8
it8709_rr(struct ite_dev
*dev
, int index
)
1039 /* just wait in case the previous access was a write */
1041 it8709_wm(dev
, index
, IT8709_REG_IDX
);
1042 it8709_wm(dev
, IT8709_READ
, IT8709_MODE
);
1044 /* wait for the read data to be available */
1047 /* return the read value */
1048 return it8709_rm(dev
, IT8709_REG_VAL
);
1051 /* write the value of a CIR register */
1052 static void it8709_wr(struct ite_dev
*dev
, u8 val
, int index
)
1054 /* we wait before writing, and not afterwards, since this allows us to
1055 * pipeline the host CPU with the microcontroller */
1057 it8709_wm(dev
, val
, IT8709_REG_VAL
);
1058 it8709_wm(dev
, index
, IT8709_REG_IDX
);
1059 it8709_wm(dev
, IT8709_WRITE
, IT8709_MODE
);
1062 /* retrieve a bitmask of the current causes for a pending interrupt; this may
1063 * be composed of ITE_IRQ_TX_FIFO, ITE_IRQ_RX_FIFO and ITE_IRQ_RX_FIFO_OVERRUN
1065 static int it8709_get_irq_causes(struct ite_dev
*dev
)
1070 ite_dbg("%s called", __func__
);
1072 /* read the interrupt flags */
1073 iflags
= it8709_rm(dev
, IT8709_IIR
);
1075 if (iflags
& IT85_TLDLI
)
1076 ret
|= ITE_IRQ_TX_FIFO
;
1077 if (iflags
& IT85_RDAI
)
1078 ret
|= ITE_IRQ_RX_FIFO
;
1079 if (iflags
& IT85_RFOI
)
1080 ret
|= ITE_IRQ_RX_FIFO_OVERRUN
;
1085 /* set the carrier parameters; to be called with the spinlock held */
1086 static void it8709_set_carrier_params(struct ite_dev
*dev
, bool high_freq
,
1087 bool use_demodulator
,
1088 u8 carrier_freq_bits
, u8 allowance_bits
,
1089 u8 pulse_width_bits
)
1093 ite_dbg("%s called", __func__
);
1095 val
= (it8709_rr(dev
, IT85_C0CFR
)
1096 &~(IT85_HCFS
| IT85_CFQ
)) |
1102 it8709_wr(dev
, val
, IT85_C0CFR
);
1104 /* program the C0RCR register */
1105 val
= it8709_rr(dev
, IT85_C0RCR
)
1106 & ~(IT85_RXEND
| IT85_RXDCR
);
1108 if (use_demodulator
)
1111 val
|= allowance_bits
;
1113 it8709_wr(dev
, val
, IT85_C0RCR
);
1115 /* program the C0TCR register */
1116 val
= it8709_rr(dev
, IT85_C0TCR
) & ~IT85_TXMPW
;
1117 val
|= pulse_width_bits
;
1118 it8709_wr(dev
, val
, IT85_C0TCR
);
1121 /* read up to buf_size bytes from the RX FIFO; to be called with the spinlock
1123 static int it8709_get_rx_bytes(struct ite_dev
*dev
, u8
* buf
, int buf_size
)
1127 ite_dbg("%s called", __func__
);
1129 /* read how many bytes are still in the FIFO */
1130 fifo
= it8709_rm(dev
, IT8709_RFSR
) & IT85_RXFBC
;
1132 while (fifo
> 0 && buf_size
> 0) {
1133 *(buf
++) = it8709_rm(dev
, IT8709_FIFO
+ read
);
1139 /* 'clear' the FIFO by setting the writing index to 0; this is
1140 * completely bound to be racy, but we can't help it, since it's a
1141 * limitation of the protocol */
1142 it8709_wm(dev
, 0, IT8709_RFSR
);
1147 /* return how many bytes are still in the FIFO; this will be called
1148 * with the device spinlock NOT HELD while waiting for the TX FIFO to get
1149 * empty; let's expect this won't be a problem */
1150 static int it8709_get_tx_used_slots(struct ite_dev
*dev
)
1152 ite_dbg("%s called", __func__
);
1154 return it8709_rr(dev
, IT85_C0TFSR
) & IT85_TXFBC
;
1157 /* put a byte to the TX fifo; this should be called with the spinlock held */
1158 static void it8709_put_tx_byte(struct ite_dev
*dev
, u8 value
)
1160 it8709_wr(dev
, value
, IT85_C0DR
);
1163 /* idle the receiver so that we won't receive samples until another
1164 pulse is detected; this must be called with the device spinlock held */
1165 static void it8709_idle_rx(struct ite_dev
*dev
)
1167 ite_dbg("%s called", __func__
);
1169 /* disable streaming by clearing RXACT writing it as 1 */
1170 it8709_wr(dev
, it8709_rr(dev
, IT85_C0RCR
) | IT85_RXACT
,
1173 /* clear the FIFO */
1174 it8709_wr(dev
, it8709_rr(dev
, IT85_C0MSTCR
) | IT85_FIFOCLR
,
1178 /* disable the receiver; this must be called with the device spinlock held */
1179 static void it8709_disable_rx(struct ite_dev
*dev
)
1181 ite_dbg("%s called", __func__
);
1183 /* disable the receiver interrupts */
1184 it8709_wr(dev
, it8709_rr(dev
, IT85_C0IER
) &
1185 ~(IT85_RDAIE
| IT85_RFOIE
),
1188 /* disable the receiver */
1189 it8709_wr(dev
, it8709_rr(dev
, IT85_C0RCR
) & ~IT85_RXEN
,
1192 /* clear the FIFO and RXACT (actually RXACT should have been cleared
1193 * in the previous it8709_wr(dev, ) call) */
1194 it8709_idle_rx(dev
);
1197 /* enable the receiver; this must be called with the device spinlock held */
1198 static void it8709_enable_rx(struct ite_dev
*dev
)
1200 ite_dbg("%s called", __func__
);
1202 /* enable the receiver by setting RXEN */
1203 it8709_wr(dev
, it8709_rr(dev
, IT85_C0RCR
) | IT85_RXEN
,
1206 /* just prepare it to idle for the next reception */
1207 it8709_idle_rx(dev
);
1209 /* enable the receiver interrupts and master enable flag */
1210 it8709_wr(dev
, it8709_rr(dev
, IT85_C0IER
)
1211 |IT85_RDAIE
| IT85_RFOIE
| IT85_IEC
,
1215 /* disable the transmitter interrupt; this must be called with the device
1217 static void it8709_disable_tx_interrupt(struct ite_dev
*dev
)
1219 ite_dbg("%s called", __func__
);
1221 /* disable the transmitter interrupts */
1222 it8709_wr(dev
, it8709_rr(dev
, IT85_C0IER
) & ~IT85_TLDLIE
,
1226 /* enable the transmitter interrupt; this must be called with the device
1228 static void it8709_enable_tx_interrupt(struct ite_dev
*dev
)
1230 ite_dbg("%s called", __func__
);
1232 /* enable the transmitter interrupts and master enable flag */
1233 it8709_wr(dev
, it8709_rr(dev
, IT85_C0IER
)
1234 |IT85_TLDLIE
| IT85_IEC
,
1238 /* disable the device; this must be called with the device spinlock held */
1239 static void it8709_disable(struct ite_dev
*dev
)
1241 ite_dbg("%s called", __func__
);
1243 /* clear out all interrupt enable flags */
1244 it8709_wr(dev
, it8709_rr(dev
, IT85_C0IER
) &
1245 ~(IT85_IEC
| IT85_RFOIE
| IT85_RDAIE
| IT85_TLDLIE
),
1248 /* disable the receiver */
1249 it8709_disable_rx(dev
);
1251 /* erase the FIFO */
1252 it8709_wr(dev
, IT85_FIFOCLR
| it8709_rr(dev
, IT85_C0MSTCR
),
1256 /* initialize the hardware */
1257 static void it8709_init_hardware(struct ite_dev
*dev
)
1259 ite_dbg("%s called", __func__
);
1261 /* disable all the interrupts */
1262 it8709_wr(dev
, it8709_rr(dev
, IT85_C0IER
) &
1263 ~(IT85_IEC
| IT85_RFOIE
| IT85_RDAIE
| IT85_TLDLIE
),
1266 /* program the baud rate divisor */
1267 it8709_wr(dev
, ITE_BAUDRATE_DIVISOR
& 0xff, IT85_C0BDLR
);
1268 it8709_wr(dev
, (ITE_BAUDRATE_DIVISOR
>> 8) & 0xff,
1271 /* program the C0MSTCR register defaults */
1272 it8709_wr(dev
, (it8709_rr(dev
, IT85_C0MSTCR
) &
1273 ~(IT85_ILSEL
| IT85_ILE
| IT85_FIFOTL
1274 | IT85_FIFOCLR
| IT85_RESET
)) | IT85_FIFOTL_DEFAULT
,
1277 /* program the C0RCR register defaults */
1278 it8709_wr(dev
, (it8709_rr(dev
, IT85_C0RCR
) &
1279 ~(IT85_RXEN
| IT85_RDWOS
| IT85_RXEND
| IT85_RXACT
1280 | IT85_RXDCR
)) | ITE_RXDCR_DEFAULT
,
1283 /* program the C0TCR register defaults */
1284 it8709_wr(dev
, (it8709_rr(dev
, IT85_C0TCR
) & ~(IT85_TXMPM
| IT85_TXMPW
))
1285 | IT85_TXRLE
| IT85_TXENDF
| IT85_TXMPM_DEFAULT
1286 | IT85_TXMPW_DEFAULT
,
1289 /* program the carrier parameters */
1290 ite_set_carrier_params(dev
);
1294 /* generic hardware setup/teardown code */
1296 /* activate the device for use */
1297 static int ite_open(struct rc_dev
*rcdev
)
1299 struct ite_dev
*dev
= rcdev
->priv
;
1300 unsigned long flags
;
1302 ite_dbg("%s called", __func__
);
1304 spin_lock_irqsave(&dev
->lock
, flags
);
1307 /* enable the receiver */
1308 dev
->params
.enable_rx(dev
);
1310 spin_unlock_irqrestore(&dev
->lock
, flags
);
1315 /* deactivate the device for use */
1316 static void ite_close(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
);
1324 dev
->in_use
= false;
1326 /* wait for any transmission to end */
1327 spin_unlock_irqrestore(&dev
->lock
, flags
);
1328 wait_event_interruptible(dev
->tx_ended
, !dev
->transmitting
);
1329 spin_lock_irqsave(&dev
->lock
, flags
);
1331 dev
->params
.disable(dev
);
1333 spin_unlock_irqrestore(&dev
->lock
, flags
);
1336 /* supported models and their parameters */
1337 static const struct ite_dev_params ite_dev_descs
[] = {
1339 .model
= "ITE8704 CIR transceiver",
1340 .io_region_size
= IT87_IOREG_LENGTH
,
1342 .hw_tx_capable
= true,
1343 .sample_period
= (u32
) (1000000000ULL / 115200),
1344 .tx_carrier_freq
= 38000,
1345 .tx_duty_cycle
= 33,
1346 .rx_low_carrier_freq
= 0,
1347 .rx_high_carrier_freq
= 0,
1350 .get_irq_causes
= it87_get_irq_causes
,
1351 .enable_rx
= it87_enable_rx
,
1352 .idle_rx
= it87_idle_rx
,
1353 .disable_rx
= it87_idle_rx
,
1354 .get_rx_bytes
= it87_get_rx_bytes
,
1355 .enable_tx_interrupt
= it87_enable_tx_interrupt
,
1356 .disable_tx_interrupt
= it87_disable_tx_interrupt
,
1357 .get_tx_used_slots
= it87_get_tx_used_slots
,
1358 .put_tx_byte
= it87_put_tx_byte
,
1359 .disable
= it87_disable
,
1360 .init_hardware
= it87_init_hardware
,
1361 .set_carrier_params
= it87_set_carrier_params
,
1364 .model
= "ITE8713 CIR transceiver",
1365 .io_region_size
= IT87_IOREG_LENGTH
,
1367 .hw_tx_capable
= true,
1368 .sample_period
= (u32
) (1000000000ULL / 115200),
1369 .tx_carrier_freq
= 38000,
1370 .tx_duty_cycle
= 33,
1371 .rx_low_carrier_freq
= 0,
1372 .rx_high_carrier_freq
= 0,
1375 .get_irq_causes
= it87_get_irq_causes
,
1376 .enable_rx
= it87_enable_rx
,
1377 .idle_rx
= it87_idle_rx
,
1378 .disable_rx
= it87_idle_rx
,
1379 .get_rx_bytes
= it87_get_rx_bytes
,
1380 .enable_tx_interrupt
= it87_enable_tx_interrupt
,
1381 .disable_tx_interrupt
= it87_disable_tx_interrupt
,
1382 .get_tx_used_slots
= it87_get_tx_used_slots
,
1383 .put_tx_byte
= it87_put_tx_byte
,
1384 .disable
= it87_disable
,
1385 .init_hardware
= it87_init_hardware
,
1386 .set_carrier_params
= it87_set_carrier_params
,
1389 .model
= "ITE8708 CIR transceiver",
1390 .io_region_size
= IT8708_IOREG_LENGTH
,
1392 .hw_tx_capable
= true,
1393 .sample_period
= (u32
) (1000000000ULL / 115200),
1394 .tx_carrier_freq
= 38000,
1395 .tx_duty_cycle
= 33,
1396 .rx_low_carrier_freq
= 0,
1397 .rx_high_carrier_freq
= 0,
1400 .get_irq_causes
= it8708_get_irq_causes
,
1401 .enable_rx
= it8708_enable_rx
,
1402 .idle_rx
= it8708_idle_rx
,
1403 .disable_rx
= it8708_idle_rx
,
1404 .get_rx_bytes
= it8708_get_rx_bytes
,
1405 .enable_tx_interrupt
= it8708_enable_tx_interrupt
,
1406 .disable_tx_interrupt
=
1407 it8708_disable_tx_interrupt
,
1408 .get_tx_used_slots
= it8708_get_tx_used_slots
,
1409 .put_tx_byte
= it8708_put_tx_byte
,
1410 .disable
= it8708_disable
,
1411 .init_hardware
= it8708_init_hardware
,
1412 .set_carrier_params
= it8708_set_carrier_params
,
1415 .model
= "ITE8709 CIR transceiver",
1416 .io_region_size
= IT8709_IOREG_LENGTH
,
1418 .hw_tx_capable
= true,
1419 .sample_period
= (u32
) (1000000000ULL / 115200),
1420 .tx_carrier_freq
= 38000,
1421 .tx_duty_cycle
= 33,
1422 .rx_low_carrier_freq
= 0,
1423 .rx_high_carrier_freq
= 0,
1426 .get_irq_causes
= it8709_get_irq_causes
,
1427 .enable_rx
= it8709_enable_rx
,
1428 .idle_rx
= it8709_idle_rx
,
1429 .disable_rx
= it8709_idle_rx
,
1430 .get_rx_bytes
= it8709_get_rx_bytes
,
1431 .enable_tx_interrupt
= it8709_enable_tx_interrupt
,
1432 .disable_tx_interrupt
=
1433 it8709_disable_tx_interrupt
,
1434 .get_tx_used_slots
= it8709_get_tx_used_slots
,
1435 .put_tx_byte
= it8709_put_tx_byte
,
1436 .disable
= it8709_disable
,
1437 .init_hardware
= it8709_init_hardware
,
1438 .set_carrier_params
= it8709_set_carrier_params
,
1442 static const struct pnp_device_id ite_ids
[] = {
1443 {"ITE8704", 0}, /* Default model */
1444 {"ITE8713", 1}, /* CIR found in EEEBox 1501U */
1445 {"ITE8708", 2}, /* Bridged IT8512 */
1446 {"ITE8709", 3}, /* SRAM-Bridged IT8512 */
1450 /* allocate memory, probe hardware, and initialize everything */
1451 static int ite_probe(struct pnp_dev
*pdev
, const struct pnp_device_id
1454 const struct ite_dev_params
*dev_desc
= NULL
;
1455 struct ite_dev
*itdev
= NULL
;
1456 struct rc_dev
*rdev
= NULL
;
1461 ite_dbg("%s called", __func__
);
1463 itdev
= kzalloc(sizeof(struct ite_dev
), GFP_KERNEL
);
1467 /* input device for IR remote (and tx) */
1468 rdev
= rc_allocate_device(RC_DRIVER_IR_RAW
);
1470 goto exit_free_dev_rdev
;
1475 /* get the model number */
1476 model_no
= (int)dev_id
->driver_data
;
1477 ite_pr(KERN_NOTICE
, "Auto-detected model: %s\n",
1478 ite_dev_descs
[model_no
].model
);
1480 if (model_number
>= 0 && model_number
< ARRAY_SIZE(ite_dev_descs
)) {
1481 model_no
= model_number
;
1482 ite_pr(KERN_NOTICE
, "The model has been fixed by a module parameter.");
1485 ite_pr(KERN_NOTICE
, "Using model: %s\n", ite_dev_descs
[model_no
].model
);
1487 /* get the description for the device */
1488 dev_desc
= &ite_dev_descs
[model_no
];
1489 io_rsrc_no
= dev_desc
->io_rsrc_no
;
1491 /* validate pnp resources */
1492 if (!pnp_port_valid(pdev
, io_rsrc_no
) ||
1493 pnp_port_len(pdev
, io_rsrc_no
) != dev_desc
->io_region_size
) {
1494 dev_err(&pdev
->dev
, "IR PNP Port not valid!\n");
1495 goto exit_free_dev_rdev
;
1498 if (!pnp_irq_valid(pdev
, 0)) {
1499 dev_err(&pdev
->dev
, "PNP IRQ not valid!\n");
1500 goto exit_free_dev_rdev
;
1503 /* store resource values */
1504 itdev
->cir_addr
= pnp_port_start(pdev
, io_rsrc_no
);
1505 itdev
->cir_irq
= pnp_irq(pdev
, 0);
1507 /* initialize spinlocks */
1508 spin_lock_init(&itdev
->lock
);
1510 /* initialize raw event */
1511 init_ir_raw_event(&itdev
->rawir
);
1513 /* set driver data into the pnp device */
1514 pnp_set_drvdata(pdev
, itdev
);
1517 /* initialize waitqueues for transmission */
1518 init_waitqueue_head(&itdev
->tx_queue
);
1519 init_waitqueue_head(&itdev
->tx_ended
);
1521 /* copy model-specific parameters */
1522 itdev
->params
= *dev_desc
;
1524 /* apply any overrides */
1525 if (sample_period
> 0)
1526 itdev
->params
.sample_period
= sample_period
;
1528 if (tx_carrier_freq
> 0)
1529 itdev
->params
.tx_carrier_freq
= tx_carrier_freq
;
1531 if (tx_duty_cycle
> 0 && tx_duty_cycle
<= 100)
1532 itdev
->params
.tx_duty_cycle
= tx_duty_cycle
;
1534 if (rx_low_carrier_freq
> 0)
1535 itdev
->params
.rx_low_carrier_freq
= rx_low_carrier_freq
;
1537 if (rx_high_carrier_freq
> 0)
1538 itdev
->params
.rx_high_carrier_freq
= rx_high_carrier_freq
;
1540 /* print out parameters */
1541 ite_pr(KERN_NOTICE
, "TX-capable: %d\n", (int)
1542 itdev
->params
.hw_tx_capable
);
1543 ite_pr(KERN_NOTICE
, "Sample period (ns): %ld\n", (long)
1544 itdev
->params
.sample_period
);
1545 ite_pr(KERN_NOTICE
, "TX carrier frequency (Hz): %d\n", (int)
1546 itdev
->params
.tx_carrier_freq
);
1547 ite_pr(KERN_NOTICE
, "TX duty cycle (%%): %d\n", (int)
1548 itdev
->params
.tx_duty_cycle
);
1549 ite_pr(KERN_NOTICE
, "RX low carrier frequency (Hz): %d\n", (int)
1550 itdev
->params
.rx_low_carrier_freq
);
1551 ite_pr(KERN_NOTICE
, "RX high carrier frequency (Hz): %d\n", (int)
1552 itdev
->params
.rx_high_carrier_freq
);
1554 /* set up hardware initial state */
1555 itdev
->params
.init_hardware(itdev
);
1557 /* set up ir-core props */
1559 rdev
->allowed_protocols
= RC_PROTO_BIT_ALL_IR_DECODER
;
1560 rdev
->open
= ite_open
;
1561 rdev
->close
= ite_close
;
1562 rdev
->s_idle
= ite_s_idle
;
1563 rdev
->s_rx_carrier_range
= ite_set_rx_carrier_range
;
1564 rdev
->min_timeout
= ITE_MIN_IDLE_TIMEOUT
;
1565 rdev
->max_timeout
= ITE_MAX_IDLE_TIMEOUT
;
1566 rdev
->timeout
= ITE_IDLE_TIMEOUT
;
1567 rdev
->rx_resolution
= ITE_BAUDRATE_DIVISOR
*
1568 itdev
->params
.sample_period
;
1569 rdev
->tx_resolution
= ITE_BAUDRATE_DIVISOR
*
1570 itdev
->params
.sample_period
;
1572 /* set up transmitter related values if needed */
1573 if (itdev
->params
.hw_tx_capable
) {
1574 rdev
->tx_ir
= ite_tx_ir
;
1575 rdev
->s_tx_carrier
= ite_set_tx_carrier
;
1576 rdev
->s_tx_duty_cycle
= ite_set_tx_duty_cycle
;
1579 rdev
->device_name
= dev_desc
->model
;
1580 rdev
->input_id
.bustype
= BUS_HOST
;
1581 rdev
->input_id
.vendor
= PCI_VENDOR_ID_ITE
;
1582 rdev
->input_id
.product
= 0;
1583 rdev
->input_id
.version
= 0;
1584 rdev
->driver_name
= ITE_DRIVER_NAME
;
1585 rdev
->map_name
= RC_MAP_RC6_MCE
;
1587 ret
= rc_register_device(rdev
);
1589 goto exit_free_dev_rdev
;
1592 /* now claim resources */
1593 if (!request_region(itdev
->cir_addr
,
1594 dev_desc
->io_region_size
, ITE_DRIVER_NAME
))
1595 goto exit_unregister_device
;
1597 if (request_irq(itdev
->cir_irq
, ite_cir_isr
, IRQF_SHARED
,
1598 ITE_DRIVER_NAME
, (void *)itdev
))
1599 goto exit_release_cir_addr
;
1601 ite_pr(KERN_NOTICE
, "driver has been successfully loaded\n");
1605 exit_release_cir_addr
:
1606 release_region(itdev
->cir_addr
, itdev
->params
.io_region_size
);
1607 exit_unregister_device
:
1608 rc_unregister_device(rdev
);
1611 rc_free_device(rdev
);
1617 static void ite_remove(struct pnp_dev
*pdev
)
1619 struct ite_dev
*dev
= pnp_get_drvdata(pdev
);
1620 unsigned long flags
;
1622 ite_dbg("%s called", __func__
);
1624 spin_lock_irqsave(&dev
->lock
, flags
);
1626 /* disable hardware */
1627 dev
->params
.disable(dev
);
1629 spin_unlock_irqrestore(&dev
->lock
, flags
);
1631 /* free resources */
1632 free_irq(dev
->cir_irq
, dev
);
1633 release_region(dev
->cir_addr
, dev
->params
.io_region_size
);
1635 rc_unregister_device(dev
->rdev
);
1640 static int ite_suspend(struct pnp_dev
*pdev
, pm_message_t state
)
1642 struct ite_dev
*dev
= pnp_get_drvdata(pdev
);
1643 unsigned long flags
;
1645 ite_dbg("%s called", __func__
);
1647 /* wait for any transmission to end */
1648 wait_event_interruptible(dev
->tx_ended
, !dev
->transmitting
);
1650 spin_lock_irqsave(&dev
->lock
, flags
);
1652 /* disable all interrupts */
1653 dev
->params
.disable(dev
);
1655 spin_unlock_irqrestore(&dev
->lock
, flags
);
1660 static int ite_resume(struct pnp_dev
*pdev
)
1662 struct ite_dev
*dev
= pnp_get_drvdata(pdev
);
1663 unsigned long flags
;
1665 ite_dbg("%s called", __func__
);
1667 spin_lock_irqsave(&dev
->lock
, flags
);
1669 /* reinitialize hardware config registers */
1670 dev
->params
.init_hardware(dev
);
1671 /* enable the receiver */
1672 dev
->params
.enable_rx(dev
);
1674 spin_unlock_irqrestore(&dev
->lock
, flags
);
1679 static void ite_shutdown(struct pnp_dev
*pdev
)
1681 struct ite_dev
*dev
= pnp_get_drvdata(pdev
);
1682 unsigned long flags
;
1684 ite_dbg("%s called", __func__
);
1686 spin_lock_irqsave(&dev
->lock
, flags
);
1688 /* disable all interrupts */
1689 dev
->params
.disable(dev
);
1691 spin_unlock_irqrestore(&dev
->lock
, flags
);
1694 static struct pnp_driver ite_driver
= {
1695 .name
= ITE_DRIVER_NAME
,
1696 .id_table
= ite_ids
,
1698 .remove
= ite_remove
,
1699 .suspend
= ite_suspend
,
1700 .resume
= ite_resume
,
1701 .shutdown
= ite_shutdown
,
1704 MODULE_DEVICE_TABLE(pnp
, ite_ids
);
1705 MODULE_DESCRIPTION("ITE Tech Inc. IT8712F/ITE8512F CIR driver");
1707 MODULE_AUTHOR("Juan J. Garcia de Soria <skandalfo@gmail.com>");
1708 MODULE_LICENSE("GPL");
1710 module_pnp_driver(ite_driver
);