1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#include <linux/kernel.h>
29#include <linux/module.h>
30#include <linux/pnp.h>
31#include <linux/io.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>
40
41#include "ite-cir.h"
42
43
44
45
46static int debug;
47module_param(debug, int, S_IRUGO | S_IWUSR);
48MODULE_PARM_DESC(debug, "Enable debugging output");
49
50
51static int rx_low_carrier_freq;
52module_param(rx_low_carrier_freq, int, S_IRUGO | S_IWUSR);
53MODULE_PARM_DESC(rx_low_carrier_freq, "Override low RX carrier frequency, Hz, 0 for no RX demodulation");
54
55
56static int rx_high_carrier_freq;
57module_param(rx_high_carrier_freq, int, S_IRUGO | S_IWUSR);
58MODULE_PARM_DESC(rx_high_carrier_freq, "Override high RX carrier frequency, Hz, 0 for no RX demodulation");
59
60
61static int tx_carrier_freq;
62module_param(tx_carrier_freq, int, S_IRUGO | S_IWUSR);
63MODULE_PARM_DESC(tx_carrier_freq, "Override TX carrier frequency, Hz");
64
65
66static int tx_duty_cycle;
67module_param(tx_duty_cycle, int, S_IRUGO | S_IWUSR);
68MODULE_PARM_DESC(tx_duty_cycle, "Override TX duty cycle, 1-100");
69
70
71static long sample_period;
72module_param(sample_period, long, S_IRUGO | S_IWUSR);
73MODULE_PARM_DESC(sample_period, "Override carrier sample period, us");
74
75
76static int model_number = -1;
77module_param(model_number, int, S_IRUGO | S_IWUSR);
78MODULE_PARM_DESC(model_number, "Use this model number, don't autodetect");
79
80
81
82
83
84static inline bool ite_is_high_carrier_freq(unsigned int freq)
85{
86 return freq >= ITE_HCF_MIN_CARRIER_FREQ;
87}
88
89
90
91static u8 ite_get_carrier_freq_bits(unsigned int freq)
92{
93 if (ite_is_high_carrier_freq(freq)) {
94 if (freq < 425000)
95 return ITE_CFQ_400;
96
97 else if (freq < 465000)
98 return ITE_CFQ_450;
99
100 else if (freq < 490000)
101 return ITE_CFQ_480;
102
103 else
104 return ITE_CFQ_500;
105 } else {
106
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;
111
112
113 freq =
114 DIV_ROUND_CLOSEST(freq - ITE_LCF_MIN_CARRIER_FREQ,
115 1000);
116
117 return (u8) freq;
118 }
119}
120
121
122static u8 ite_get_pulse_width_bits(unsigned int freq, int duty_cycle)
123{
124 unsigned long period_ns, on_ns;
125
126
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;
131
132 period_ns = 1000000000UL / freq;
133 on_ns = period_ns * duty_cycle / 100;
134
135 if (ite_is_high_carrier_freq(freq)) {
136 if (on_ns < 750)
137 return ITE_TXMPW_A;
138
139 else if (on_ns < 850)
140 return ITE_TXMPW_B;
141
142 else if (on_ns < 950)
143 return ITE_TXMPW_C;
144
145 else if (on_ns < 1080)
146 return ITE_TXMPW_D;
147
148 else
149 return ITE_TXMPW_E;
150 } else {
151 if (on_ns < 6500)
152 return ITE_TXMPW_A;
153
154 else if (on_ns < 7850)
155 return ITE_TXMPW_B;
156
157 else if (on_ns < 9650)
158 return ITE_TXMPW_C;
159
160 else if (on_ns < 11950)
161 return ITE_TXMPW_D;
162
163 else
164 return ITE_TXMPW_E;
165 }
166}
167
168
169
170static void ite_decode_bytes(struct ite_dev *dev, const u8 * data, int
171 length)
172{
173 u32 sample_period;
174 unsigned long *ldata;
175 unsigned int next_one, next_zero, size;
176 DEFINE_IR_RAW_EVENT(ev);
177
178 if (length == 0)
179 return;
180
181 sample_period = dev->params.sample_period;
182 ldata = (unsigned long *)data;
183 size = length << 3;
184 next_one = find_next_bit_le(ldata, size, 0);
185 if (next_one > 0) {
186 ev.pulse = true;
187 ev.duration =
188 ITE_BITS_TO_NS(next_one, sample_period);
189 ir_raw_event_store_with_filter(dev->rdev, &ev);
190 }
191
192 while (next_one < size) {
193 next_zero = find_next_zero_bit_le(ldata, size, next_one + 1);
194 ev.pulse = false;
195 ev.duration = ITE_BITS_TO_NS(next_zero - next_one, sample_period);
196 ir_raw_event_store_with_filter(dev->rdev, &ev);
197
198 if (next_zero < size) {
199 next_one =
200 find_next_bit_le(ldata,
201 size,
202 next_zero + 1);
203 ev.pulse = true;
204 ev.duration =
205 ITE_BITS_TO_NS(next_one - next_zero,
206 sample_period);
207 ir_raw_event_store_with_filter
208 (dev->rdev, &ev);
209 } else
210 next_one = size;
211 }
212
213 ir_raw_event_handle(dev->rdev);
214
215 ite_dbg_verbose("decoded %d bytes.", length);
216}
217
218
219
220static void ite_set_carrier_params(struct ite_dev *dev)
221{
222 unsigned int freq, low_freq, high_freq;
223 int allowance;
224 bool use_demodulator;
225 bool for_tx = dev->transmitting;
226
227 ite_dbg("%s called", __func__);
228
229 if (for_tx) {
230
231 freq = dev->params.tx_carrier_freq;
232 allowance = ITE_RXDCR_DEFAULT;
233 use_demodulator = false;
234 } else {
235 low_freq = dev->params.rx_low_carrier_freq;
236 high_freq = dev->params.rx_high_carrier_freq;
237
238 if (low_freq == 0) {
239
240 freq =
241 ITE_DEFAULT_CARRIER_FREQ;
242 allowance = ITE_RXDCR_DEFAULT;
243 use_demodulator = false;
244 } else {
245
246 freq = (low_freq + high_freq) / 2;
247
248
249 allowance =
250 DIV_ROUND_CLOSEST(10000 * (high_freq - low_freq),
251 ITE_RXDCR_PER_10000_STEP
252 * (high_freq + low_freq));
253
254 if (allowance < 1)
255 allowance = 1;
256
257 if (allowance > ITE_RXDCR_MAX)
258 allowance = ITE_RXDCR_MAX;
259
260 use_demodulator = true;
261 }
262 }
263
264
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));
268}
269
270
271static irqreturn_t ite_cir_isr(int irq, void *data)
272{
273 struct ite_dev *dev = data;
274 unsigned long flags;
275 irqreturn_t ret = IRQ_RETVAL(IRQ_NONE);
276 u8 rx_buf[ITE_RX_FIFO_LEN];
277 int rx_bytes;
278 int iflags;
279
280 ite_dbg_verbose("%s firing", __func__);
281
282
283 spin_lock_irqsave(&dev->lock, flags);
284
285
286 iflags = dev->params.get_irq_causes(dev);
287
288
289 if (iflags & (ITE_IRQ_RX_FIFO | ITE_IRQ_RX_FIFO_OVERRUN)) {
290
291 rx_bytes =
292 dev->params.get_rx_bytes(dev, rx_buf,
293 ITE_RX_FIFO_LEN);
294
295 if (rx_bytes > 0) {
296
297
298
299 spin_unlock_irqrestore(&dev->
300 lock,
301 flags);
302
303
304 ite_decode_bytes(dev, rx_buf,
305 rx_bytes);
306
307
308 spin_lock_irqsave(&dev->lock,
309 flags);
310
311
312 ret = IRQ_RETVAL(IRQ_HANDLED);
313 }
314 } else if (iflags & ITE_IRQ_TX_FIFO) {
315
316 ite_dbg_verbose("got interrupt for TX FIFO");
317
318
319 wake_up_interruptible(&dev->tx_queue);
320
321
322 ret = IRQ_RETVAL(IRQ_HANDLED);
323 }
324
325
326 spin_unlock_irqrestore(&dev->lock, flags);
327
328 ite_dbg_verbose("%s done returning %d", __func__, (int)ret);
329
330 return ret;
331}
332
333
334static int ite_set_rx_carrier_range(struct rc_dev *rcdev, u32 carrier_low, u32
335 carrier_high)
336{
337 unsigned long flags;
338 struct ite_dev *dev = rcdev->priv;
339
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);
345
346 return 0;
347}
348
349
350static int ite_set_tx_carrier(struct rc_dev *rcdev, u32 carrier)
351{
352 unsigned long flags;
353 struct ite_dev *dev = rcdev->priv;
354
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);
359
360 return 0;
361}
362
363
364static int ite_set_tx_duty_cycle(struct rc_dev *rcdev, u32 duty_cycle)
365{
366 unsigned long flags;
367 struct ite_dev *dev = rcdev->priv;
368
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);
373
374 return 0;
375}
376
377
378
379
380static int ite_tx_ir(struct rc_dev *rcdev, unsigned *txbuf, unsigned n)
381{
382 unsigned long flags;
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;
387 int ret = n;
388 u8 last_sent[ITE_TX_FIFO_LEN];
389 u8 val;
390
391 ite_dbg("%s called", __func__);
392
393
394 memset(last_sent, 0, ARRAY_SIZE(last_sent));
395
396 spin_lock_irqsave(&dev->lock, flags);
397
398
399 dev->transmitting = true;
400
401
402 ite_set_carrier_params(dev);
403
404
405 max_rle_us =
406 (ITE_BAUDRATE_DIVISOR * dev->params.sample_period *
407 ITE_TX_MAX_RLE) / 1000;
408
409
410 dev->params.disable_rx(dev);
411
412
413
414
415
416 fifo_avail =
417 ITE_TX_FIFO_LEN - dev->params.get_tx_used_slots(dev);
418
419 while (n > 0 && dev->in_use) {
420
421 is_pulse = !is_pulse;
422 remaining_us = *(txbuf++);
423 n--;
424
425 ite_dbg("%s: %ld",
426 ((is_pulse) ? "pulse" : "space"),
427 (long int)
428 remaining_us);
429
430
431 while (remaining_us > 0 && dev->in_use) {
432 if (remaining_us > max_rle_us)
433 next_rle_us = max_rle_us;
434
435 else
436 next_rle_us = remaining_us;
437
438 remaining_us -= next_rle_us;
439
440
441 val = (ITE_TX_MAX_RLE * next_rle_us) / max_rle_us;
442
443
444 last_sent[last_idx++] = val;
445 last_idx &= (ITE_TX_FIFO_LEN);
446
447
448 val = (val - 1) & ITE_TX_RLE_MASK;
449
450
451 if (is_pulse)
452 val |= ITE_TX_PULSE;
453
454 else
455 val |= ITE_TX_SPACE;
456
457
458
459
460
461 if (fifo_avail <= 0)
462 fifo_avail = ITE_TX_FIFO_LEN - dev->params.get_tx_used_slots(dev);
463
464
465 if (fifo_avail <= 0) {
466
467 dev->params.
468 enable_tx_interrupt(dev);
469
470
471 spin_unlock_irqrestore(&dev->lock, flags);
472
473
474 wait_event_interruptible(dev->tx_queue, (fifo_avail = ITE_TX_FIFO_LEN - dev->params.get_tx_used_slots(dev)) >= 8);
475
476
477 spin_lock_irqsave(&dev->lock, flags);
478
479
480 dev->params.
481 disable_tx_interrupt(dev);
482 }
483
484
485 dev->params.put_tx_byte(dev, val);
486 fifo_avail--;
487 }
488 }
489
490
491
492
493 fifo_remaining = dev->params.get_tx_used_slots(dev);
494 remaining_us = 0;
495 while (fifo_remaining > 0) {
496 fifo_remaining--;
497 last_idx--;
498 last_idx &= (ITE_TX_FIFO_LEN - 1);
499 remaining_us += last_sent[last_idx];
500 }
501 remaining_us = (remaining_us * max_rle_us) / (ITE_TX_MAX_RLE);
502
503
504 spin_unlock_irqrestore(&dev->lock, flags);
505
506
507 mdelay(DIV_ROUND_UP(remaining_us, 1000));
508
509
510 spin_lock_irqsave(&dev->lock, flags);
511
512
513 dev->transmitting = false;
514
515
516 ite_set_carrier_params(dev);
517
518
519 if (dev->in_use)
520 dev->params.enable_rx(dev);
521
522
523 wake_up_interruptible(&dev->tx_ended);
524
525 spin_unlock_irqrestore(&dev->lock, flags);
526
527 return ret;
528}
529
530
531static void ite_s_idle(struct rc_dev *rcdev, bool enable)
532{
533 unsigned long flags;
534 struct ite_dev *dev = rcdev->priv;
535
536 ite_dbg("%s called", __func__);
537
538 if (enable) {
539 spin_lock_irqsave(&dev->lock, flags);
540 dev->params.idle_rx(dev);
541 spin_unlock_irqrestore(&dev->lock, flags);
542 }
543}
544
545
546
547
548
549
550
551static int it87_get_irq_causes(struct ite_dev *dev)
552{
553 u8 iflags;
554 int ret = 0;
555
556 ite_dbg("%s called", __func__);
557
558
559 iflags = inb(dev->cir_addr + IT87_IIR) & IT87_II;
560
561 switch (iflags) {
562 case IT87_II_RXDS:
563 ret = ITE_IRQ_RX_FIFO;
564 break;
565 case IT87_II_RXFO:
566 ret = ITE_IRQ_RX_FIFO_OVERRUN;
567 break;
568 case IT87_II_TXLDL:
569 ret = ITE_IRQ_TX_FIFO;
570 break;
571 }
572
573 return ret;
574}
575
576
577static void it87_set_carrier_params(struct ite_dev *dev, bool high_freq,
578 bool use_demodulator,
579 u8 carrier_freq_bits, u8 allowance_bits,
580 u8 pulse_width_bits)
581{
582 u8 val;
583
584 ite_dbg("%s called", __func__);
585
586
587 val = inb(dev->cir_addr + IT87_RCR)
588 & ~(IT87_HCFS | IT87_RXEND | IT87_RXDCR);
589
590 if (high_freq)
591 val |= IT87_HCFS;
592
593 if (use_demodulator)
594 val |= IT87_RXEND;
595
596 val |= allowance_bits;
597
598 outb(val, dev->cir_addr + IT87_RCR);
599
600
601 outb((carrier_freq_bits << IT87_CFQ_SHIFT) | pulse_width_bits,
602 dev->cir_addr + IT87_TCR2);
603}
604
605
606
607static int it87_get_rx_bytes(struct ite_dev *dev, u8 * buf, int buf_size)
608{
609 int fifo, read = 0;
610
611 ite_dbg("%s called", __func__);
612
613
614 fifo = inb(dev->cir_addr + IT87_RSR) & IT87_RXFBC;
615
616 while (fifo > 0 && buf_size > 0) {
617 *(buf++) = inb(dev->cir_addr + IT87_DR);
618 fifo--;
619 read++;
620 buf_size--;
621 }
622
623 return read;
624}
625
626
627
628
629static int it87_get_tx_used_slots(struct ite_dev *dev)
630{
631 ite_dbg("%s called", __func__);
632
633 return inb(dev->cir_addr + IT87_TSR) & IT87_TXFBC;
634}
635
636
637static void it87_put_tx_byte(struct ite_dev *dev, u8 value)
638{
639 outb(value, dev->cir_addr + IT87_DR);
640}
641
642
643
644static void it87_idle_rx(struct ite_dev *dev)
645{
646 ite_dbg("%s called", __func__);
647
648
649 outb(inb(dev->cir_addr + IT87_RCR) | IT87_RXACT,
650 dev->cir_addr + IT87_RCR);
651
652
653 outb(inb(dev->cir_addr + IT87_TCR1) | IT87_FIFOCLR,
654 dev->cir_addr + IT87_TCR1);
655}
656
657
658static void it87_disable_rx(struct ite_dev *dev)
659{
660 ite_dbg("%s called", __func__);
661
662
663 outb(inb(dev->cir_addr + IT87_IER) & ~(IT87_RDAIE | IT87_RFOIE),
664 dev->cir_addr + IT87_IER);
665
666
667 outb(inb(dev->cir_addr + IT87_RCR) & ~IT87_RXEN,
668 dev->cir_addr + IT87_RCR);
669
670
671
672 it87_idle_rx(dev);
673}
674
675
676static void it87_enable_rx(struct ite_dev *dev)
677{
678 ite_dbg("%s called", __func__);
679
680
681 outb(inb(dev->cir_addr + IT87_RCR) | IT87_RXEN,
682 dev->cir_addr + IT87_RCR);
683
684
685 it87_idle_rx(dev);
686
687
688 outb(inb(dev->cir_addr + IT87_IER) | IT87_RDAIE | IT87_RFOIE | IT87_IEC,
689 dev->cir_addr + IT87_IER);
690}
691
692
693
694static void it87_disable_tx_interrupt(struct ite_dev *dev)
695{
696 ite_dbg("%s called", __func__);
697
698
699 outb(inb(dev->cir_addr + IT87_IER) & ~IT87_TLDLIE,
700 dev->cir_addr + IT87_IER);
701}
702
703
704
705static void it87_enable_tx_interrupt(struct ite_dev *dev)
706{
707 ite_dbg("%s called", __func__);
708
709
710 outb(inb(dev->cir_addr + IT87_IER) | IT87_TLDLIE | IT87_IEC,
711 dev->cir_addr + IT87_IER);
712}
713
714
715static void it87_disable(struct ite_dev *dev)
716{
717 ite_dbg("%s called", __func__);
718
719
720 outb(inb(dev->cir_addr + IT87_IER) &
721 ~(IT87_IEC | IT87_RFOIE | IT87_RDAIE | IT87_TLDLIE),
722 dev->cir_addr + IT87_IER);
723
724
725 it87_disable_rx(dev);
726
727
728 outb(IT87_FIFOCLR | inb(dev->cir_addr + IT87_TCR1),
729 dev->cir_addr + IT87_TCR1);
730}
731
732
733static void it87_init_hardware(struct ite_dev *dev)
734{
735 ite_dbg("%s called", __func__);
736
737
738
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);
742
743
744 outb(ITE_BAUDRATE_DIVISOR & 0xff, dev->cir_addr + IT87_BDLR);
745 outb((ITE_BAUDRATE_DIVISOR >> 8) & 0xff, dev->cir_addr + IT87_BDHR);
746
747
748 outb(inb(dev->cir_addr + IT87_IER) & ~IT87_BR,
749 dev->cir_addr + IT87_IER);
750
751
752 outb(ITE_RXDCR_DEFAULT, dev->cir_addr + IT87_RCR);
753
754
755 outb(IT87_TXMPM_DEFAULT | IT87_TXENDF | IT87_TXRLE
756 | IT87_FIFOTL_DEFAULT | IT87_FIFOCLR,
757 dev->cir_addr + IT87_TCR1);
758
759
760 ite_set_carrier_params(dev);
761}
762
763
764
765
766
767
768static int it8708_get_irq_causes(struct ite_dev *dev)
769{
770 u8 iflags;
771 int ret = 0;
772
773 ite_dbg("%s called", __func__);
774
775
776 iflags = inb(dev->cir_addr + IT8708_C0IIR);
777
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;
784
785 return ret;
786}
787
788
789static void it8708_set_carrier_params(struct ite_dev *dev, bool high_freq,
790 bool use_demodulator,
791 u8 carrier_freq_bits, u8 allowance_bits,
792 u8 pulse_width_bits)
793{
794 u8 val;
795
796 ite_dbg("%s called", __func__);
797
798
799 outb(inb(dev->cir_addr + IT8708_BANKSEL) | IT8708_HRAE,
800 dev->cir_addr + IT8708_BANKSEL);
801
802 val = (inb(dev->cir_addr + IT8708_C0CFR)
803 & ~(IT85_HCFS | IT85_CFQ)) | carrier_freq_bits;
804
805 if (high_freq)
806 val |= IT85_HCFS;
807
808 outb(val, dev->cir_addr + IT8708_C0CFR);
809
810 outb(inb(dev->cir_addr + IT8708_BANKSEL) & ~IT8708_HRAE,
811 dev->cir_addr + IT8708_BANKSEL);
812
813
814 val = inb(dev->cir_addr + IT8708_C0RCR)
815 & ~(IT85_RXEND | IT85_RXDCR);
816
817 if (use_demodulator)
818 val |= IT85_RXEND;
819
820 val |= allowance_bits;
821
822 outb(val, dev->cir_addr + IT8708_C0RCR);
823
824
825 val = inb(dev->cir_addr + IT8708_C0TCR) & ~IT85_TXMPW;
826 val |= pulse_width_bits;
827 outb(val, dev->cir_addr + IT8708_C0TCR);
828}
829
830
831
832static int it8708_get_rx_bytes(struct ite_dev *dev, u8 * buf, int buf_size)
833{
834 int fifo, read = 0;
835
836 ite_dbg("%s called", __func__);
837
838
839 fifo = inb(dev->cir_addr + IT8708_C0RFSR) & IT85_RXFBC;
840
841 while (fifo > 0 && buf_size > 0) {
842 *(buf++) = inb(dev->cir_addr + IT8708_C0DR);
843 fifo--;
844 read++;
845 buf_size--;
846 }
847
848 return read;
849}
850
851
852
853
854static int it8708_get_tx_used_slots(struct ite_dev *dev)
855{
856 ite_dbg("%s called", __func__);
857
858 return inb(dev->cir_addr + IT8708_C0TFSR) & IT85_TXFBC;
859}
860
861
862static void it8708_put_tx_byte(struct ite_dev *dev, u8 value)
863{
864 outb(value, dev->cir_addr + IT8708_C0DR);
865}
866
867
868
869static void it8708_idle_rx(struct ite_dev *dev)
870{
871 ite_dbg("%s called", __func__);
872
873
874 outb(inb(dev->cir_addr + IT8708_C0RCR) | IT85_RXACT,
875 dev->cir_addr + IT8708_C0RCR);
876
877
878 outb(inb(dev->cir_addr + IT8708_C0MSTCR) | IT85_FIFOCLR,
879 dev->cir_addr + IT8708_C0MSTCR);
880}
881
882
883static void it8708_disable_rx(struct ite_dev *dev)
884{
885 ite_dbg("%s called", __func__);
886
887
888 outb(inb(dev->cir_addr + IT8708_C0IER) &
889 ~(IT85_RDAIE | IT85_RFOIE),
890 dev->cir_addr + IT8708_C0IER);
891
892
893 outb(inb(dev->cir_addr + IT8708_C0RCR) & ~IT85_RXEN,
894 dev->cir_addr + IT8708_C0RCR);
895
896
897
898 it8708_idle_rx(dev);
899}
900
901
902static void it8708_enable_rx(struct ite_dev *dev)
903{
904 ite_dbg("%s called", __func__);
905
906
907 outb(inb(dev->cir_addr + IT8708_C0RCR) | IT85_RXEN,
908 dev->cir_addr + IT8708_C0RCR);
909
910
911 it8708_idle_rx(dev);
912
913
914 outb(inb(dev->cir_addr + IT8708_C0IER)
915 |IT85_RDAIE | IT85_RFOIE | IT85_IEC,
916 dev->cir_addr + IT8708_C0IER);
917}
918
919
920
921static void it8708_disable_tx_interrupt(struct ite_dev *dev)
922{
923 ite_dbg("%s called", __func__);
924
925
926 outb(inb(dev->cir_addr + IT8708_C0IER) & ~IT85_TLDLIE,
927 dev->cir_addr + IT8708_C0IER);
928}
929
930
931
932static void it8708_enable_tx_interrupt(struct ite_dev *dev)
933{
934 ite_dbg("%s called", __func__);
935
936
937 outb(inb(dev->cir_addr + IT8708_C0IER)
938 |IT85_TLDLIE | IT85_IEC,
939 dev->cir_addr + IT8708_C0IER);
940}
941
942
943static void it8708_disable(struct ite_dev *dev)
944{
945 ite_dbg("%s called", __func__);
946
947
948 outb(inb(dev->cir_addr + IT8708_C0IER) &
949 ~(IT85_IEC | IT85_RFOIE | IT85_RDAIE | IT85_TLDLIE),
950 dev->cir_addr + IT8708_C0IER);
951
952
953 it8708_disable_rx(dev);
954
955
956 outb(IT85_FIFOCLR | inb(dev->cir_addr + IT8708_C0MSTCR),
957 dev->cir_addr + IT8708_C0MSTCR);
958}
959
960
961static void it8708_init_hardware(struct ite_dev *dev)
962{
963 ite_dbg("%s called", __func__);
964
965
966 outb(inb(dev->cir_addr + IT8708_C0IER) &
967 ~(IT85_IEC | IT85_RFOIE | IT85_RDAIE | IT85_TLDLIE),
968 dev->cir_addr + IT8708_C0IER);
969
970
971 outb(inb(dev->cir_addr + IT8708_BANKSEL) | IT8708_HRAE,
972 dev->cir_addr + IT8708_BANKSEL);
973
974 outb(ITE_BAUDRATE_DIVISOR & 0xff, dev->cir_addr + IT8708_C0BDLR);
975 outb((ITE_BAUDRATE_DIVISOR >> 8) & 0xff,
976 dev->cir_addr + IT8708_C0BDHR);
977
978 outb(inb(dev->cir_addr + IT8708_BANKSEL) & ~IT8708_HRAE,
979 dev->cir_addr + IT8708_BANKSEL);
980
981
982 outb((inb(dev->cir_addr + IT8708_C0MSTCR) &
983 ~(IT85_ILSEL | IT85_ILE | IT85_FIFOTL |
984 IT85_FIFOCLR | IT85_RESET)) |
985 IT85_FIFOTL_DEFAULT,
986 dev->cir_addr + IT8708_C0MSTCR);
987
988
989 outb((inb(dev->cir_addr + IT8708_C0RCR) &
990 ~(IT85_RXEN | IT85_RDWOS | IT85_RXEND |
991 IT85_RXACT | IT85_RXDCR)) |
992 ITE_RXDCR_DEFAULT,
993 dev->cir_addr + IT8708_C0RCR);
994
995
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);
1001
1002
1003 ite_set_carrier_params(dev);
1004}
1005
1006
1007
1008
1009static inline u8 it8709_rm(struct ite_dev *dev, int index)
1010{
1011 outb(index, dev->cir_addr + IT8709_RAM_IDX);
1012 return inb(dev->cir_addr + IT8709_RAM_VAL);
1013}
1014
1015
1016static inline void it8709_wm(struct ite_dev *dev, u8 val, int index)
1017{
1018 outb(index, dev->cir_addr + IT8709_RAM_IDX);
1019 outb(val, dev->cir_addr + IT8709_RAM_VAL);
1020}
1021
1022static void it8709_wait(struct ite_dev *dev)
1023{
1024 int i = 0;
1025
1026
1027
1028
1029 for (i = 0; i < 15000; i++) {
1030 udelay(2);
1031 if (it8709_rm(dev, IT8709_MODE) == IT8709_IDLE)
1032 break;
1033 }
1034}
1035
1036
1037static u8 it8709_rr(struct ite_dev *dev, int index)
1038{
1039
1040 it8709_wait(dev);
1041 it8709_wm(dev, index, IT8709_REG_IDX);
1042 it8709_wm(dev, IT8709_READ, IT8709_MODE);
1043
1044
1045 it8709_wait(dev);
1046
1047
1048 return it8709_rm(dev, IT8709_REG_VAL);
1049}
1050
1051
1052static void it8709_wr(struct ite_dev *dev, u8 val, int index)
1053{
1054
1055
1056 it8709_wait(dev);
1057 it8709_wm(dev, val, IT8709_REG_VAL);
1058 it8709_wm(dev, index, IT8709_REG_IDX);
1059 it8709_wm(dev, IT8709_WRITE, IT8709_MODE);
1060}
1061
1062
1063
1064
1065static int it8709_get_irq_causes(struct ite_dev *dev)
1066{
1067 u8 iflags;
1068 int ret = 0;
1069
1070 ite_dbg("%s called", __func__);
1071
1072
1073 iflags = it8709_rm(dev, IT8709_IIR);
1074
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;
1081
1082 return ret;
1083}
1084
1085
1086static 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)
1090{
1091 u8 val;
1092
1093 ite_dbg("%s called", __func__);
1094
1095 val = (it8709_rr(dev, IT85_C0CFR)
1096 &~(IT85_HCFS | IT85_CFQ)) |
1097 carrier_freq_bits;
1098
1099 if (high_freq)
1100 val |= IT85_HCFS;
1101
1102 it8709_wr(dev, val, IT85_C0CFR);
1103
1104
1105 val = it8709_rr(dev, IT85_C0RCR)
1106 & ~(IT85_RXEND | IT85_RXDCR);
1107
1108 if (use_demodulator)
1109 val |= IT85_RXEND;
1110
1111 val |= allowance_bits;
1112
1113 it8709_wr(dev, val, IT85_C0RCR);
1114
1115
1116 val = it8709_rr(dev, IT85_C0TCR) & ~IT85_TXMPW;
1117 val |= pulse_width_bits;
1118 it8709_wr(dev, val, IT85_C0TCR);
1119}
1120
1121
1122
1123static int it8709_get_rx_bytes(struct ite_dev *dev, u8 * buf, int buf_size)
1124{
1125 int fifo, read = 0;
1126
1127 ite_dbg("%s called", __func__);
1128
1129
1130 fifo = it8709_rm(dev, IT8709_RFSR) & IT85_RXFBC;
1131
1132 while (fifo > 0 && buf_size > 0) {
1133 *(buf++) = it8709_rm(dev, IT8709_FIFO + read);
1134 fifo--;
1135 read++;
1136 buf_size--;
1137 }
1138
1139
1140
1141
1142 it8709_wm(dev, 0, IT8709_RFSR);
1143
1144 return read;
1145}
1146
1147
1148
1149
1150static int it8709_get_tx_used_slots(struct ite_dev *dev)
1151{
1152 ite_dbg("%s called", __func__);
1153
1154 return it8709_rr(dev, IT85_C0TFSR) & IT85_TXFBC;
1155}
1156
1157
1158static void it8709_put_tx_byte(struct ite_dev *dev, u8 value)
1159{
1160 it8709_wr(dev, value, IT85_C0DR);
1161}
1162
1163
1164
1165static void it8709_idle_rx(struct ite_dev *dev)
1166{
1167 ite_dbg("%s called", __func__);
1168
1169
1170 it8709_wr(dev, it8709_rr(dev, IT85_C0RCR) | IT85_RXACT,
1171 IT85_C0RCR);
1172
1173
1174 it8709_wr(dev, it8709_rr(dev, IT85_C0MSTCR) | IT85_FIFOCLR,
1175 IT85_C0MSTCR);
1176}
1177
1178
1179static void it8709_disable_rx(struct ite_dev *dev)
1180{
1181 ite_dbg("%s called", __func__);
1182
1183
1184 it8709_wr(dev, it8709_rr(dev, IT85_C0IER) &
1185 ~(IT85_RDAIE | IT85_RFOIE),
1186 IT85_C0IER);
1187
1188
1189 it8709_wr(dev, it8709_rr(dev, IT85_C0RCR) & ~IT85_RXEN,
1190 IT85_C0RCR);
1191
1192
1193
1194 it8709_idle_rx(dev);
1195}
1196
1197
1198static void it8709_enable_rx(struct ite_dev *dev)
1199{
1200 ite_dbg("%s called", __func__);
1201
1202
1203 it8709_wr(dev, it8709_rr(dev, IT85_C0RCR) | IT85_RXEN,
1204 IT85_C0RCR);
1205
1206
1207 it8709_idle_rx(dev);
1208
1209
1210 it8709_wr(dev, it8709_rr(dev, IT85_C0IER)
1211 |IT85_RDAIE | IT85_RFOIE | IT85_IEC,
1212 IT85_C0IER);
1213}
1214
1215
1216
1217static void it8709_disable_tx_interrupt(struct ite_dev *dev)
1218{
1219 ite_dbg("%s called", __func__);
1220
1221
1222 it8709_wr(dev, it8709_rr(dev, IT85_C0IER) & ~IT85_TLDLIE,
1223 IT85_C0IER);
1224}
1225
1226
1227
1228static void it8709_enable_tx_interrupt(struct ite_dev *dev)
1229{
1230 ite_dbg("%s called", __func__);
1231
1232
1233 it8709_wr(dev, it8709_rr(dev, IT85_C0IER)
1234 |IT85_TLDLIE | IT85_IEC,
1235 IT85_C0IER);
1236}
1237
1238
1239static void it8709_disable(struct ite_dev *dev)
1240{
1241 ite_dbg("%s called", __func__);
1242
1243
1244 it8709_wr(dev, it8709_rr(dev, IT85_C0IER) &
1245 ~(IT85_IEC | IT85_RFOIE | IT85_RDAIE | IT85_TLDLIE),
1246 IT85_C0IER);
1247
1248
1249 it8709_disable_rx(dev);
1250
1251
1252 it8709_wr(dev, IT85_FIFOCLR | it8709_rr(dev, IT85_C0MSTCR),
1253 IT85_C0MSTCR);
1254}
1255
1256
1257static void it8709_init_hardware(struct ite_dev *dev)
1258{
1259 ite_dbg("%s called", __func__);
1260
1261
1262 it8709_wr(dev, it8709_rr(dev, IT85_C0IER) &
1263 ~(IT85_IEC | IT85_RFOIE | IT85_RDAIE | IT85_TLDLIE),
1264 IT85_C0IER);
1265
1266
1267 it8709_wr(dev, ITE_BAUDRATE_DIVISOR & 0xff, IT85_C0BDLR);
1268 it8709_wr(dev, (ITE_BAUDRATE_DIVISOR >> 8) & 0xff,
1269 IT85_C0BDHR);
1270
1271
1272 it8709_wr(dev, (it8709_rr(dev, IT85_C0MSTCR) &
1273 ~(IT85_ILSEL | IT85_ILE | IT85_FIFOTL
1274 | IT85_FIFOCLR | IT85_RESET)) | IT85_FIFOTL_DEFAULT,
1275 IT85_C0MSTCR);
1276
1277
1278 it8709_wr(dev, (it8709_rr(dev, IT85_C0RCR) &
1279 ~(IT85_RXEN | IT85_RDWOS | IT85_RXEND | IT85_RXACT
1280 | IT85_RXDCR)) | ITE_RXDCR_DEFAULT,
1281 IT85_C0RCR);
1282
1283
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,
1287 IT85_C0TCR);
1288
1289
1290 ite_set_carrier_params(dev);
1291}
1292
1293
1294
1295
1296
1297static int ite_open(struct rc_dev *rcdev)
1298{
1299 struct ite_dev *dev = rcdev->priv;
1300 unsigned long flags;
1301
1302 ite_dbg("%s called", __func__);
1303
1304 spin_lock_irqsave(&dev->lock, flags);
1305 dev->in_use = true;
1306
1307
1308 dev->params.enable_rx(dev);
1309
1310 spin_unlock_irqrestore(&dev->lock, flags);
1311
1312 return 0;
1313}
1314
1315
1316static void ite_close(struct rc_dev *rcdev)
1317{
1318 struct ite_dev *dev = rcdev->priv;
1319 unsigned long flags;
1320
1321 ite_dbg("%s called", __func__);
1322
1323 spin_lock_irqsave(&dev->lock, flags);
1324 dev->in_use = false;
1325
1326
1327 spin_unlock_irqrestore(&dev->lock, flags);
1328 wait_event_interruptible(dev->tx_ended, !dev->transmitting);
1329 spin_lock_irqsave(&dev->lock, flags);
1330
1331 dev->params.disable(dev);
1332
1333 spin_unlock_irqrestore(&dev->lock, flags);
1334}
1335
1336
1337static const struct ite_dev_params ite_dev_descs[] = {
1338 {
1339 .model = "ITE8704 CIR transceiver",
1340 .io_region_size = IT87_IOREG_LENGTH,
1341 .io_rsrc_no = 0,
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,
1348
1349
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,
1362 },
1363 {
1364 .model = "ITE8713 CIR transceiver",
1365 .io_region_size = IT87_IOREG_LENGTH,
1366 .io_rsrc_no = 0,
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,
1373
1374
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,
1387 },
1388 {
1389 .model = "ITE8708 CIR transceiver",
1390 .io_region_size = IT8708_IOREG_LENGTH,
1391 .io_rsrc_no = 0,
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,
1398
1399
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,
1413 },
1414 {
1415 .model = "ITE8709 CIR transceiver",
1416 .io_region_size = IT8709_IOREG_LENGTH,
1417 .io_rsrc_no = 2,
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,
1424
1425
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,
1439 },
1440};
1441
1442static const struct pnp_device_id ite_ids[] = {
1443 {"ITE8704", 0},
1444 {"ITE8713", 1},
1445 {"ITE8708", 2},
1446 {"ITE8709", 3},
1447 {"", 0},
1448};
1449
1450
1451static int ite_probe(struct pnp_dev *pdev, const struct pnp_device_id
1452 *dev_id)
1453{
1454 const struct ite_dev_params *dev_desc = NULL;
1455 struct ite_dev *itdev = NULL;
1456 struct rc_dev *rdev = NULL;
1457 int ret = -ENOMEM;
1458 int model_no;
1459 int io_rsrc_no;
1460
1461 ite_dbg("%s called", __func__);
1462
1463 itdev = kzalloc(sizeof(struct ite_dev), GFP_KERNEL);
1464 if (!itdev)
1465 return ret;
1466
1467
1468 rdev = rc_allocate_device(RC_DRIVER_IR_RAW);
1469 if (!rdev)
1470 goto exit_free_dev_rdev;
1471 itdev->rdev = rdev;
1472
1473 ret = -ENODEV;
1474
1475
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);
1479
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.");
1483 }
1484
1485 ite_pr(KERN_NOTICE, "Using model: %s\n", ite_dev_descs[model_no].model);
1486
1487
1488 dev_desc = &ite_dev_descs[model_no];
1489 io_rsrc_no = dev_desc->io_rsrc_no;
1490
1491
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;
1496 }
1497
1498 if (!pnp_irq_valid(pdev, 0)) {
1499 dev_err(&pdev->dev, "PNP IRQ not valid!\n");
1500 goto exit_free_dev_rdev;
1501 }
1502
1503
1504 itdev->cir_addr = pnp_port_start(pdev, io_rsrc_no);
1505 itdev->cir_irq = pnp_irq(pdev, 0);
1506
1507
1508 spin_lock_init(&itdev->lock);
1509
1510
1511 init_ir_raw_event(&itdev->rawir);
1512
1513
1514 pnp_set_drvdata(pdev, itdev);
1515 itdev->pdev = pdev;
1516
1517
1518 init_waitqueue_head(&itdev->tx_queue);
1519 init_waitqueue_head(&itdev->tx_ended);
1520
1521
1522 itdev->params = *dev_desc;
1523
1524
1525 if (sample_period > 0)
1526 itdev->params.sample_period = sample_period;
1527
1528 if (tx_carrier_freq > 0)
1529 itdev->params.tx_carrier_freq = tx_carrier_freq;
1530
1531 if (tx_duty_cycle > 0 && tx_duty_cycle <= 100)
1532 itdev->params.tx_duty_cycle = tx_duty_cycle;
1533
1534 if (rx_low_carrier_freq > 0)
1535 itdev->params.rx_low_carrier_freq = rx_low_carrier_freq;
1536
1537 if (rx_high_carrier_freq > 0)
1538 itdev->params.rx_high_carrier_freq = rx_high_carrier_freq;
1539
1540
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);
1553
1554
1555 itdev->params.init_hardware(itdev);
1556
1557
1558 rdev->priv = itdev;
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;
1571
1572
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;
1577 }
1578
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;
1586
1587 ret = rc_register_device(rdev);
1588 if (ret)
1589 goto exit_free_dev_rdev;
1590
1591 ret = -EBUSY;
1592
1593 if (!request_region(itdev->cir_addr,
1594 dev_desc->io_region_size, ITE_DRIVER_NAME))
1595 goto exit_unregister_device;
1596
1597 if (request_irq(itdev->cir_irq, ite_cir_isr, IRQF_SHARED,
1598 ITE_DRIVER_NAME, (void *)itdev))
1599 goto exit_release_cir_addr;
1600
1601 ite_pr(KERN_NOTICE, "driver has been successfully loaded\n");
1602
1603 return 0;
1604
1605exit_release_cir_addr:
1606 release_region(itdev->cir_addr, itdev->params.io_region_size);
1607exit_unregister_device:
1608 rc_unregister_device(rdev);
1609 rdev = NULL;
1610exit_free_dev_rdev:
1611 rc_free_device(rdev);
1612 kfree(itdev);
1613
1614 return ret;
1615}
1616
1617static void ite_remove(struct pnp_dev *pdev)
1618{
1619 struct ite_dev *dev = pnp_get_drvdata(pdev);
1620 unsigned long flags;
1621
1622 ite_dbg("%s called", __func__);
1623
1624 spin_lock_irqsave(&dev->lock, flags);
1625
1626
1627 dev->params.disable(dev);
1628
1629 spin_unlock_irqrestore(&dev->lock, flags);
1630
1631
1632 free_irq(dev->cir_irq, dev);
1633 release_region(dev->cir_addr, dev->params.io_region_size);
1634
1635 rc_unregister_device(dev->rdev);
1636
1637 kfree(dev);
1638}
1639
1640static int ite_suspend(struct pnp_dev *pdev, pm_message_t state)
1641{
1642 struct ite_dev *dev = pnp_get_drvdata(pdev);
1643 unsigned long flags;
1644
1645 ite_dbg("%s called", __func__);
1646
1647
1648 wait_event_interruptible(dev->tx_ended, !dev->transmitting);
1649
1650 spin_lock_irqsave(&dev->lock, flags);
1651
1652
1653 dev->params.disable(dev);
1654
1655 spin_unlock_irqrestore(&dev->lock, flags);
1656
1657 return 0;
1658}
1659
1660static int ite_resume(struct pnp_dev *pdev)
1661{
1662 struct ite_dev *dev = pnp_get_drvdata(pdev);
1663 unsigned long flags;
1664
1665 ite_dbg("%s called", __func__);
1666
1667 spin_lock_irqsave(&dev->lock, flags);
1668
1669
1670 dev->params.init_hardware(dev);
1671
1672 dev->params.enable_rx(dev);
1673
1674 spin_unlock_irqrestore(&dev->lock, flags);
1675
1676 return 0;
1677}
1678
1679static void ite_shutdown(struct pnp_dev *pdev)
1680{
1681 struct ite_dev *dev = pnp_get_drvdata(pdev);
1682 unsigned long flags;
1683
1684 ite_dbg("%s called", __func__);
1685
1686 spin_lock_irqsave(&dev->lock, flags);
1687
1688
1689 dev->params.disable(dev);
1690
1691 spin_unlock_irqrestore(&dev->lock, flags);
1692}
1693
1694static struct pnp_driver ite_driver = {
1695 .name = ITE_DRIVER_NAME,
1696 .id_table = ite_ids,
1697 .probe = ite_probe,
1698 .remove = ite_remove,
1699 .suspend = ite_suspend,
1700 .resume = ite_resume,
1701 .shutdown = ite_shutdown,
1702};
1703
1704MODULE_DEVICE_TABLE(pnp, ite_ids);
1705MODULE_DESCRIPTION("ITE Tech Inc. IT8712F/ITE8512F CIR driver");
1706
1707MODULE_AUTHOR("Juan J. Garcia de Soria <skandalfo@gmail.com>");
1708MODULE_LICENSE("GPL");
1709
1710module_pnp_driver(ite_driver);
1711