2 * LIRC SIR driver, (C) 2000 Milan Pikula <www@fornax.sk>
4 * lirc_sir - Device driver for use with SIR (serial infra red)
5 * mode of IrDA on many notebooks.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * 2000/09/16 Frank Przybylski <mail@frankprzybylski.de> :
23 * added timeout and relaxed pulse detection, removed gap bug
25 * 2000/12/15 Christoph Bartelmus <lirc@bartelmus.de> :
26 * added support for Tekram Irmate 210 (sending does not work yet,
27 * kind of disappointing that nobody was able to implement that
31 * 2001/02/27 Christoph Bartelmus <lirc@bartelmus.de> :
32 * added support for StrongARM SA1100 embedded microprocessor
33 * parts cut'n'pasted from sa1100_ir.c (C) 2000 Russell King
36 #include <linux/module.h>
37 #include <linux/sched.h>
38 #include <linux/errno.h>
39 #include <linux/signal.h>
41 #include <linux/interrupt.h>
42 #include <linux/ioport.h>
43 #include <linux/kernel.h>
44 #include <linux/serial_reg.h>
45 #include <linux/time.h>
46 #include <linux/string.h>
47 #include <linux/types.h>
48 #include <linux/wait.h>
50 #include <linux/delay.h>
51 #include <linux/poll.h>
52 #include <asm/system.h>
55 #include <linux/fcntl.h>
57 #include <asm/hardware.h>
58 #ifdef CONFIG_SA1100_COLLIE
59 #include <asm/arch/tc35143.h>
60 #include <asm/ucb1200.h>
64 #include <linux/timer.h>
66 #include <media/lirc.h>
67 #include <media/lirc_dev.h>
69 /* SECTION: Definitions */
71 /*** Tekram dongle ***/
72 #ifdef LIRC_SIR_TEKRAM
73 /* stolen from kernel source */
74 /* definitions for Tekram dongle */
75 #define TEKRAM_115200 0x00
76 #define TEKRAM_57600 0x01
77 #define TEKRAM_38400 0x02
78 #define TEKRAM_19200 0x03
79 #define TEKRAM_9600 0x04
80 #define TEKRAM_2400 0x08
82 #define TEKRAM_PW 0x10 /* Pulse select bit */
84 /* 10bit * 1s/115200bit in milliseconds = 87ms*/
85 #define TIME_CONST (10000000ul/115200ul)
89 #ifdef LIRC_SIR_ACTISYS_ACT200L
90 static void init_act200(void);
91 #elif defined(LIRC_SIR_ACTISYS_ACT220L)
92 static void init_act220(void);
97 struct sa1100_ser2_registers
{
98 /* HSSP control register */
111 static int irq
= IRQ_Ser2ICP
;
113 #define LIRC_ON_SA1100_TRANSMITTER_LATENCY 0
115 /* pulse/space ratio of 50/50 */
116 static unsigned long pulse_width
= (13-LIRC_ON_SA1100_TRANSMITTER_LATENCY
);
117 /* 1000000/freq-pulse_width */
118 static unsigned long space_width
= (13-LIRC_ON_SA1100_TRANSMITTER_LATENCY
);
119 static unsigned int freq
= 38000; /* modulation frequency */
120 static unsigned int duty_cycle
= 50; /* duty cycle of 50% */
124 #define RBUF_LEN 1024
125 #define WBUF_LEN 1024
127 #define LIRC_DRIVER_NAME "lirc_sir"
131 #ifndef LIRC_SIR_TEKRAM
132 /* 9bit * 1s/115200bit in milli seconds = 78.125ms*/
133 #define TIME_CONST (9000000ul/115200ul)
137 /* timeout for sequences in jiffies (=5/100s), must be longer than TIME_CONST */
138 #define SIR_TIMEOUT (HZ*5/100)
140 #ifndef LIRC_ON_SA1100
145 /* for external dongles, default to com1 */
146 #if defined(LIRC_SIR_ACTISYS_ACT200L) || \
147 defined(LIRC_SIR_ACTISYS_ACT220L) || \
148 defined(LIRC_SIR_TEKRAM)
149 #define LIRC_PORT 0x3f8
151 /* onboard sir ports are typically com3 */
152 #define LIRC_PORT 0x3e8
156 static int io
= LIRC_PORT
;
157 static int irq
= LIRC_IRQ
;
158 static int threshold
= 3;
161 static DEFINE_SPINLOCK(timer_lock
);
162 static struct timer_list timerlist
;
163 /* time of last signal change detected */
164 static struct timeval last_tv
= {0, 0};
165 /* time of last UART data ready interrupt */
166 static struct timeval last_intr_tv
= {0, 0};
167 static int last_value
;
169 static DECLARE_WAIT_QUEUE_HEAD(lirc_read_queue
);
171 static DEFINE_SPINLOCK(hardware_lock
);
173 static int rx_buf
[RBUF_LEN
];
174 static unsigned int rx_tail
, rx_head
;
177 #define dprintk(fmt, args...) \
180 printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
184 /* SECTION: Prototypes */
186 /* Communication with user-space */
187 static unsigned int lirc_poll(struct file
*file
, poll_table
*wait
);
188 static ssize_t
lirc_read(struct file
*file
, char *buf
, size_t count
,
190 static ssize_t
lirc_write(struct file
*file
, const char *buf
, size_t n
,
192 static long lirc_ioctl(struct file
*filep
, unsigned int cmd
, unsigned long arg
);
193 static void add_read_queue(int flag
, unsigned long val
);
194 static int init_chrdev(void);
195 static void drop_chrdev(void);
197 static irqreturn_t
sir_interrupt(int irq
, void *dev_id
);
198 static void send_space(unsigned long len
);
199 static void send_pulse(unsigned long len
);
200 static int init_hardware(void);
201 static void drop_hardware(void);
203 static int init_port(void);
204 static void drop_port(void);
206 #ifdef LIRC_ON_SA1100
212 static void off(void)
217 static inline unsigned int sinp(int offset
)
219 return inb(io
+ offset
);
222 static inline void soutp(int offset
, int value
)
224 outb(value
, io
+ offset
);
228 #ifndef MAX_UDELAY_MS
229 #define MAX_UDELAY_US 5000
231 #define MAX_UDELAY_US (MAX_UDELAY_MS*1000)
234 static void safe_udelay(unsigned long usecs
)
236 while (usecs
> MAX_UDELAY_US
) {
237 udelay(MAX_UDELAY_US
);
238 usecs
-= MAX_UDELAY_US
;
243 /* SECTION: Communication with user-space */
245 static unsigned int lirc_poll(struct file
*file
, poll_table
*wait
)
247 poll_wait(file
, &lirc_read_queue
, wait
);
248 if (rx_head
!= rx_tail
)
249 return POLLIN
| POLLRDNORM
;
253 static ssize_t
lirc_read(struct file
*file
, char *buf
, size_t count
,
258 DECLARE_WAITQUEUE(wait
, current
);
260 if (count
% sizeof(int))
263 add_wait_queue(&lirc_read_queue
, &wait
);
264 set_current_state(TASK_INTERRUPTIBLE
);
266 if (rx_head
!= rx_tail
) {
267 if (copy_to_user((void *) buf
+ n
,
268 (void *) (rx_buf
+ rx_head
),
273 rx_head
= (rx_head
+ 1) & (RBUF_LEN
- 1);
276 if (file
->f_flags
& O_NONBLOCK
) {
280 if (signal_pending(current
)) {
281 retval
= -ERESTARTSYS
;
285 set_current_state(TASK_INTERRUPTIBLE
);
288 remove_wait_queue(&lirc_read_queue
, &wait
);
289 set_current_state(TASK_RUNNING
);
290 return n
? n
: retval
;
292 static ssize_t
lirc_write(struct file
*file
, const char *buf
, size_t n
,
299 count
= n
/ sizeof(int);
300 if (n
% sizeof(int) || count
% 2 == 0)
302 tx_buf
= memdup_user(buf
, n
);
304 return PTR_ERR(tx_buf
);
306 #ifdef LIRC_ON_SA1100
307 /* disable receiver */
310 local_irq_save(flags
);
315 send_pulse(tx_buf
[i
]);
320 send_space(tx_buf
[i
]);
323 local_irq_restore(flags
);
324 #ifdef LIRC_ON_SA1100
326 udelay(1000); /* wait 1ms for IR diode to recover */
328 /* clear status register to prevent unwanted interrupts */
329 Ser2UTSR0
&= (UTSR0_RID
| UTSR0_RBB
| UTSR0_REB
);
330 /* enable receiver */
331 Ser2UTCR3
= UTCR3_RXE
|UTCR3_RIE
;
336 static long lirc_ioctl(struct file
*filep
, unsigned int cmd
, unsigned long arg
)
339 unsigned long value
= 0;
340 #ifdef LIRC_ON_SA1100
343 if (cmd
== LIRC_GET_FEATURES
)
344 value
= LIRC_CAN_SEND_PULSE
|
345 LIRC_CAN_SET_SEND_DUTY_CYCLE
|
346 LIRC_CAN_SET_SEND_CARRIER
|
348 else if (cmd
== LIRC_GET_SEND_MODE
)
349 value
= LIRC_MODE_PULSE
;
350 else if (cmd
== LIRC_GET_REC_MODE
)
351 value
= LIRC_MODE_MODE2
;
353 if (cmd
== LIRC_GET_FEATURES
)
354 value
= LIRC_CAN_SEND_PULSE
| LIRC_CAN_REC_MODE2
;
355 else if (cmd
== LIRC_GET_SEND_MODE
)
356 value
= LIRC_MODE_PULSE
;
357 else if (cmd
== LIRC_GET_REC_MODE
)
358 value
= LIRC_MODE_MODE2
;
362 case LIRC_GET_FEATURES
:
363 case LIRC_GET_SEND_MODE
:
364 case LIRC_GET_REC_MODE
:
365 retval
= put_user(value
, (unsigned long *) arg
);
368 case LIRC_SET_SEND_MODE
:
369 case LIRC_SET_REC_MODE
:
370 retval
= get_user(value
, (unsigned long *) arg
);
372 #ifdef LIRC_ON_SA1100
373 case LIRC_SET_SEND_DUTY_CYCLE
:
374 retval
= get_user(ivalue
, (unsigned int *) arg
);
377 if (ivalue
<= 0 || ivalue
> 100)
379 /* (ivalue/100)*(1000000/freq) */
381 pulse_width
= (unsigned long) duty_cycle
*10000/freq
;
382 space_width
= (unsigned long) 1000000L/freq
-pulse_width
;
383 if (pulse_width
>= LIRC_ON_SA1100_TRANSMITTER_LATENCY
)
384 pulse_width
-= LIRC_ON_SA1100_TRANSMITTER_LATENCY
;
385 if (space_width
>= LIRC_ON_SA1100_TRANSMITTER_LATENCY
)
386 space_width
-= LIRC_ON_SA1100_TRANSMITTER_LATENCY
;
388 case LIRC_SET_SEND_CARRIER
:
389 retval
= get_user(ivalue
, (unsigned int *) arg
);
392 if (ivalue
> 500000 || ivalue
< 20000)
395 pulse_width
= (unsigned long) duty_cycle
*10000/freq
;
396 space_width
= (unsigned long) 1000000L/freq
-pulse_width
;
397 if (pulse_width
>= LIRC_ON_SA1100_TRANSMITTER_LATENCY
)
398 pulse_width
-= LIRC_ON_SA1100_TRANSMITTER_LATENCY
;
399 if (space_width
>= LIRC_ON_SA1100_TRANSMITTER_LATENCY
)
400 space_width
-= LIRC_ON_SA1100_TRANSMITTER_LATENCY
;
404 retval
= -ENOIOCTLCMD
;
410 if (cmd
== LIRC_SET_REC_MODE
) {
411 if (value
!= LIRC_MODE_MODE2
)
413 } else if (cmd
== LIRC_SET_SEND_MODE
) {
414 if (value
!= LIRC_MODE_PULSE
)
421 static void add_read_queue(int flag
, unsigned long val
)
423 unsigned int new_rx_tail
;
426 dprintk("add flag %d with val %lu\n", flag
, val
);
428 newval
= val
& PULSE_MASK
;
431 * statistically, pulses are ~TIME_CONST/2 too long. we could
432 * maybe make this more exact, but this is good enough
436 if (newval
> TIME_CONST
/2)
437 newval
-= TIME_CONST
/2;
438 else /* should not ever happen */
442 newval
+= TIME_CONST
/2;
444 new_rx_tail
= (rx_tail
+ 1) & (RBUF_LEN
- 1);
445 if (new_rx_tail
== rx_head
) {
446 dprintk("Buffer overrun.\n");
449 rx_buf
[rx_tail
] = newval
;
450 rx_tail
= new_rx_tail
;
451 wake_up_interruptible(&lirc_read_queue
);
454 static const struct file_operations lirc_fops
= {
455 .owner
= THIS_MODULE
,
459 .unlocked_ioctl
= lirc_ioctl
,
460 .open
= lirc_dev_fop_open
,
461 .release
= lirc_dev_fop_close
,
465 static int set_use_inc(void *data
)
470 static void set_use_dec(void *data
)
474 static struct lirc_driver driver
= {
475 .name
= LIRC_DRIVER_NAME
,
481 .set_use_inc
= set_use_inc
,
482 .set_use_dec
= set_use_dec
,
485 .owner
= THIS_MODULE
,
489 static int init_chrdev(void)
491 driver
.minor
= lirc_register_driver(&driver
);
492 if (driver
.minor
< 0) {
493 printk(KERN_ERR LIRC_DRIVER_NAME
": init_chrdev() failed.\n");
499 static void drop_chrdev(void)
501 lirc_unregister_driver(driver
.minor
);
504 /* SECTION: Hardware */
505 static long delta(struct timeval
*tv1
, struct timeval
*tv2
)
509 deltv
= tv2
->tv_sec
- tv1
->tv_sec
;
513 deltv
= deltv
*1000000 +
519 static void sir_timeout(unsigned long data
)
522 * if last received signal was a pulse, but receiving stopped
523 * within the 9 bit frame, we need to finish this pulse and
524 * simulate a signal change to from pulse to space. Otherwise
525 * upper layers will receive two sequences next time.
529 unsigned long pulse_end
;
531 /* avoid interference with interrupt */
532 spin_lock_irqsave(&timer_lock
, flags
);
534 #ifndef LIRC_ON_SA1100
535 /* clear unread bits in UART and restart */
536 outb(UART_FCR_CLEAR_RCVR
, io
+ UART_FCR
);
538 /* determine 'virtual' pulse end: */
539 pulse_end
= delta(&last_tv
, &last_intr_tv
);
540 dprintk("timeout add %d for %lu usec\n", last_value
, pulse_end
);
541 add_read_queue(last_value
, pulse_end
);
543 last_tv
= last_intr_tv
;
545 spin_unlock_irqrestore(&timer_lock
, flags
);
548 static irqreturn_t
sir_interrupt(int irq
, void *dev_id
)
551 struct timeval curr_tv
;
552 static unsigned long deltv
;
553 #ifdef LIRC_ON_SA1100
559 * Deal with any receive errors first. The bytes in error may be
560 * the only bytes in the receive FIFO, so we do this first.
562 while (status
& UTSR0_EIF
) {
569 if (bstat
& UTSR1_FRE
)
570 dprintk("frame error\n");
571 if (bstat
& UTSR1_ROR
)
572 dprintk("receive fifo overrun\n");
573 if (bstat
& UTSR1_PRE
)
574 dprintk("parity error\n");
582 if (status
& (UTSR0_RFS
| UTSR0_RID
)) {
583 do_gettimeofday(&curr_tv
);
584 deltv
= delta(&last_tv
, &curr_tv
);
587 dprintk("%d data: %u\n", n
, (unsigned int) data
);
589 } while (status
& UTSR0_RID
&& /* do not empty fifo in order to
590 * get UTSR0_RID in any case */
591 Ser2UTSR1
& UTSR1_RNE
); /* data ready */
593 if (status
&UTSR0_RID
) {
594 add_read_queue(0 , deltv
- n
* TIME_CONST
); /*space*/
595 add_read_queue(1, n
* TIME_CONST
); /*pulse*/
601 if (status
& UTSR0_TFS
)
602 printk(KERN_ERR
"transmit fifo not full, shouldn't happen\n");
604 /* We must clear certain bits. */
605 status
&= (UTSR0_RID
| UTSR0_RBB
| UTSR0_REB
);
609 unsigned long deltintrtv
;
613 while ((iir
= inb(io
+ UART_IIR
) & UART_IIR_ID
)) {
614 switch (iir
&UART_IIR_ID
) { /* FIXME toto treba preriedit */
616 (void) inb(io
+ UART_MSR
);
619 (void) inb(io
+ UART_LSR
);
623 if (lsr
& UART_LSR_THRE
) /* FIFO is empty */
624 outb(data
, io
+ UART_TX
)
628 /* avoid interference with timer */
629 spin_lock_irqsave(&timer_lock
, flags
);
631 del_timer(&timerlist
);
632 data
= inb(io
+ UART_RX
);
633 do_gettimeofday(&curr_tv
);
634 deltv
= delta(&last_tv
, &curr_tv
);
635 deltintrtv
= delta(&last_intr_tv
, &curr_tv
);
636 dprintk("t %lu, d %d\n", deltintrtv
, (int)data
);
638 * if nothing came in last X cycles,
641 if (deltintrtv
> TIME_CONST
* threshold
) {
644 /* simulate signal change */
645 add_read_queue(last_value
,
652 last_intr_tv
.tv_usec
;
657 if (data
^ last_value
) {
659 * deltintrtv > 2*TIME_CONST, remember?
660 * the other case is timeout
662 add_read_queue(last_value
,
666 if (last_tv
.tv_usec
>= TIME_CONST
) {
667 last_tv
.tv_usec
-= TIME_CONST
;
670 last_tv
.tv_usec
+= 1000000 -
674 last_intr_tv
= curr_tv
;
677 * start timer for end of
680 timerlist
.expires
= jiffies
+
682 add_timer(&timerlist
);
685 lsr
= inb(io
+ UART_LSR
);
686 } while (lsr
& UART_LSR_DR
); /* data ready */
687 spin_unlock_irqrestore(&timer_lock
, flags
);
694 return IRQ_RETVAL(IRQ_HANDLED
);
697 #ifdef LIRC_ON_SA1100
698 static void send_pulse(unsigned long length
)
700 unsigned long k
, delay
;
706 * this won't give us the carrier frequency we really want
707 * due to integer arithmetic, but we can accept this inaccuracy
710 for (k
= flag
= 0; k
< length
; k
+= delay
, flag
= !flag
) {
723 static void send_space(unsigned long length
)
731 static void send_space(unsigned long len
)
736 static void send_pulse(unsigned long len
)
738 long bytes_out
= len
/ TIME_CONST
;
741 time_left
= (long)len
- (long)bytes_out
* (long)TIME_CONST
;
742 if (bytes_out
== 0) {
746 while (bytes_out
--) {
747 outb(PULSE
, io
+ UART_TX
);
748 /* FIXME treba seriozne cakanie z char/serial.c */
749 while (!(inb(io
+ UART_LSR
) & UART_LSR_THRE
))
754 safe_udelay(time_left
);
759 #ifdef CONFIG_SA1100_COLLIE
760 static int sa1100_irda_set_power_collie(int state
)
765 * 1 - short range, lowest power
766 * 2 - medium range, medium power
767 * 3 - maximum range, high power
769 ucb1200_set_io_direction(TC35143_GPIO_IR_ON
,
770 TC35143_IODIR_OUTPUT
);
771 ucb1200_set_io(TC35143_GPIO_IR_ON
, TC35143_IODAT_LOW
);
775 ucb1200_set_io_direction(TC35143_GPIO_IR_ON
,
776 TC35143_IODIR_OUTPUT
);
777 ucb1200_set_io(TC35143_GPIO_IR_ON
, TC35143_IODAT_HIGH
);
783 static int init_hardware(void)
787 spin_lock_irqsave(&hardware_lock
, flags
);
789 #ifdef LIRC_ON_SA1100
790 #ifdef CONFIG_SA1100_BITSY
791 if (machine_is_bitsy()) {
792 printk(KERN_INFO
"Power on IR module\n");
793 set_bitsy_egpio(EGPIO_BITSY_IR_ON
);
796 #ifdef CONFIG_SA1100_COLLIE
797 sa1100_irda_set_power_collie(3); /* power on */
799 sr
.hscr0
= Ser2HSCR0
;
801 sr
.utcr0
= Ser2UTCR0
;
802 sr
.utcr1
= Ser2UTCR1
;
803 sr
.utcr2
= Ser2UTCR2
;
804 sr
.utcr3
= Ser2UTCR3
;
805 sr
.utcr4
= Ser2UTCR4
;
808 sr
.utsr0
= Ser2UTSR0
;
809 sr
.utsr1
= Ser2UTSR1
;
815 /* set output to 0 */
818 /* Enable HP-SIR modulation, and ensure that the port is disabled. */
820 Ser2HSCR0
= sr
.hscr0
& (~HSCR0_HSSP
);
822 /* clear status register to prevent unwanted interrupts */
823 Ser2UTSR0
&= (UTSR0_RID
| UTSR0_RBB
| UTSR0_REB
);
826 Ser2UTCR0
= UTCR0_1StpBit
|UTCR0_7BitData
;
830 /* use HPSIR, 1.6 usec pulses */
831 Ser2UTCR4
= UTCR4_HPSIR
|UTCR4_Z1_6us
;
833 /* enable receiver, receive fifo interrupt */
834 Ser2UTCR3
= UTCR3_RXE
|UTCR3_RIE
;
836 /* clear status register to prevent unwanted interrupts */
837 Ser2UTSR0
&= (UTSR0_RID
| UTSR0_RBB
| UTSR0_REB
);
839 #elif defined(LIRC_SIR_TEKRAM)
847 soutp(UART_LCR
, sinp(UART_LCR
) & (~UART_LCR_DLAB
));
849 /* First of all, disable all interrupts */
850 soutp(UART_IER
, sinp(UART_IER
) &
851 (~(UART_IER_MSI
|UART_IER_RLSI
|UART_IER_THRI
|UART_IER_RDI
)));
854 soutp(UART_LCR
, sinp(UART_LCR
) | UART_LCR_DLAB
);
856 /* Set divisor to 12 => 9600 Baud */
861 soutp(UART_LCR
, sinp(UART_LCR
) & (~UART_LCR_DLAB
));
864 soutp(UART_MCR
, UART_MCR_RTS
|UART_MCR_DTR
|UART_MCR_OUT2
);
865 safe_udelay(50*1000);
867 /* -DTR low -> reset PIC */
868 soutp(UART_MCR
, UART_MCR_RTS
|UART_MCR_OUT2
);
871 soutp(UART_MCR
, UART_MCR_RTS
|UART_MCR_DTR
|UART_MCR_OUT2
);
875 /* -RTS low -> send control byte */
876 soutp(UART_MCR
, UART_MCR_DTR
|UART_MCR_OUT2
);
878 soutp(UART_TX
, TEKRAM_115200
|TEKRAM_PW
);
880 /* one byte takes ~1042 usec to transmit at 9600,8N1 */
883 /* back to normal operation */
884 soutp(UART_MCR
, UART_MCR_RTS
|UART_MCR_DTR
|UART_MCR_OUT2
);
889 /* read previous control byte */
890 printk(KERN_INFO LIRC_DRIVER_NAME
891 ": 0x%02x\n", sinp(UART_RX
));
894 soutp(UART_LCR
, sinp(UART_LCR
) | UART_LCR_DLAB
);
896 /* Set divisor to 1 => 115200 Baud */
900 /* Set DLAB 0, 8 Bit */
901 soutp(UART_LCR
, UART_LCR_WLEN8
);
902 /* enable interrupts */
903 soutp(UART_IER
, sinp(UART_IER
)|UART_IER_RDI
);
905 outb(0, io
+ UART_MCR
);
906 outb(0, io
+ UART_IER
);
908 /* set DLAB, speed = 115200 */
909 outb(UART_LCR_DLAB
| UART_LCR_WLEN7
, io
+ UART_LCR
);
910 outb(1, io
+ UART_DLL
); outb(0, io
+ UART_DLM
);
911 /* 7N1+start = 9 bits at 115200 ~ 3 bits at 44000 */
912 outb(UART_LCR_WLEN7
, io
+ UART_LCR
);
914 outb(UART_FCR_ENABLE_FIFO
, io
+ UART_FCR
);
916 /* outb(UART_IER_RLSI|UART_IER_RDI|UART_IER_THRI, io + UART_IER); */
917 outb(UART_IER_RDI
, io
+ UART_IER
);
919 outb(UART_MCR_DTR
|UART_MCR_RTS
|UART_MCR_OUT2
, io
+ UART_MCR
);
920 #ifdef LIRC_SIR_ACTISYS_ACT200L
922 #elif defined(LIRC_SIR_ACTISYS_ACT220L)
926 spin_unlock_irqrestore(&hardware_lock
, flags
);
930 static void drop_hardware(void)
934 spin_lock_irqsave(&hardware_lock
, flags
);
936 #ifdef LIRC_ON_SA1100
939 Ser2UTCR0
= sr
.utcr0
;
940 Ser2UTCR1
= sr
.utcr1
;
941 Ser2UTCR2
= sr
.utcr2
;
942 Ser2UTCR4
= sr
.utcr4
;
943 Ser2UTCR3
= sr
.utcr3
;
945 Ser2HSCR0
= sr
.hscr0
;
946 #ifdef CONFIG_SA1100_BITSY
947 if (machine_is_bitsy())
948 clr_bitsy_egpio(EGPIO_BITSY_IR_ON
);
950 #ifdef CONFIG_SA1100_COLLIE
951 sa1100_irda_set_power_collie(0); /* power off */
954 /* turn off interrupts */
955 outb(0, io
+ UART_IER
);
957 spin_unlock_irqrestore(&hardware_lock
, flags
);
960 /* SECTION: Initialisation */
962 static int init_port(void)
966 /* get I/O port access and IRQ line */
967 #ifndef LIRC_ON_SA1100
968 if (request_region(io
, 8, LIRC_DRIVER_NAME
) == NULL
) {
969 printk(KERN_ERR LIRC_DRIVER_NAME
970 ": i/o port 0x%.4x already in use.\n", io
);
974 retval
= request_irq(irq
, sir_interrupt
, IRQF_DISABLED
,
975 LIRC_DRIVER_NAME
, NULL
);
977 # ifndef LIRC_ON_SA1100
978 release_region(io
, 8);
980 printk(KERN_ERR LIRC_DRIVER_NAME
981 ": IRQ %d already in use.\n",
985 #ifndef LIRC_ON_SA1100
986 printk(KERN_INFO LIRC_DRIVER_NAME
987 ": I/O port 0x%.4x, IRQ %d.\n",
991 init_timer(&timerlist
);
992 timerlist
.function
= sir_timeout
;
993 timerlist
.data
= 0xabadcafe;
998 static void drop_port(void)
1000 free_irq(irq
, NULL
);
1001 del_timer_sync(&timerlist
);
1002 #ifndef LIRC_ON_SA1100
1003 release_region(io
, 8);
1007 #ifdef LIRC_SIR_ACTISYS_ACT200L
1008 /* Crystal/Cirrus CS8130 IR transceiver, used in Actisys Act200L dongle */
1009 /* some code borrowed from Linux IRDA driver */
1011 /* Register 0: Control register #1 */
1012 #define ACT200L_REG0 0x00
1013 #define ACT200L_TXEN 0x01 /* Enable transmitter */
1014 #define ACT200L_RXEN 0x02 /* Enable receiver */
1015 #define ACT200L_ECHO 0x08 /* Echo control chars */
1017 /* Register 1: Control register #2 */
1018 #define ACT200L_REG1 0x10
1019 #define ACT200L_LODB 0x01 /* Load new baud rate count value */
1020 #define ACT200L_WIDE 0x04 /* Expand the maximum allowable pulse */
1022 /* Register 3: Transmit mode register #2 */
1023 #define ACT200L_REG3 0x30
1024 #define ACT200L_B0 0x01 /* DataBits, 0=6, 1=7, 2=8, 3=9(8P) */
1025 #define ACT200L_B1 0x02 /* DataBits, 0=6, 1=7, 2=8, 3=9(8P) */
1026 #define ACT200L_CHSY 0x04 /* StartBit Synced 0=bittime, 1=startbit */
1028 /* Register 4: Output Power register */
1029 #define ACT200L_REG4 0x40
1030 #define ACT200L_OP0 0x01 /* Enable LED1C output */
1031 #define ACT200L_OP1 0x02 /* Enable LED2C output */
1032 #define ACT200L_BLKR 0x04
1034 /* Register 5: Receive Mode register */
1035 #define ACT200L_REG5 0x50
1036 #define ACT200L_RWIDL 0x01 /* fixed 1.6us pulse mode */
1037 /*.. other various IRDA bit modes, and TV remote modes..*/
1039 /* Register 6: Receive Sensitivity register #1 */
1040 #define ACT200L_REG6 0x60
1041 #define ACT200L_RS0 0x01 /* receive threshold bit 0 */
1042 #define ACT200L_RS1 0x02 /* receive threshold bit 1 */
1044 /* Register 7: Receive Sensitivity register #2 */
1045 #define ACT200L_REG7 0x70
1046 #define ACT200L_ENPOS 0x04 /* Ignore the falling edge */
1048 /* Register 8,9: Baud Rate Divider register #1,#2 */
1049 #define ACT200L_REG8 0x80
1050 #define ACT200L_REG9 0x90
1052 #define ACT200L_2400 0x5f
1053 #define ACT200L_9600 0x17
1054 #define ACT200L_19200 0x0b
1055 #define ACT200L_38400 0x05
1056 #define ACT200L_57600 0x03
1057 #define ACT200L_115200 0x01
1059 /* Register 13: Control register #3 */
1060 #define ACT200L_REG13 0xd0
1061 #define ACT200L_SHDW 0x01 /* Enable access to shadow registers */
1063 /* Register 15: Status register */
1064 #define ACT200L_REG15 0xf0
1066 /* Register 21: Control register #4 */
1067 #define ACT200L_REG21 0x50
1068 #define ACT200L_EXCK 0x02 /* Disable clock output driver */
1069 #define ACT200L_OSCL 0x04 /* oscillator in low power, medium accuracy mode */
1071 static void init_act200(void)
1076 ACT200L_REG13
| ACT200L_SHDW
,
1077 ACT200L_REG21
| ACT200L_EXCK
| ACT200L_OSCL
,
1079 ACT200L_REG7
| ACT200L_ENPOS
,
1080 ACT200L_REG6
| ACT200L_RS0
| ACT200L_RS1
,
1081 ACT200L_REG5
| ACT200L_RWIDL
,
1082 ACT200L_REG4
| ACT200L_OP0
| ACT200L_OP1
| ACT200L_BLKR
,
1083 ACT200L_REG3
| ACT200L_B0
,
1084 ACT200L_REG0
| ACT200L_TXEN
| ACT200L_RXEN
,
1085 ACT200L_REG8
| (ACT200L_115200
& 0x0f),
1086 ACT200L_REG9
| ((ACT200L_115200
>> 4) & 0x0f),
1087 ACT200L_REG1
| ACT200L_LODB
| ACT200L_WIDE
1091 soutp(UART_LCR
, UART_LCR_DLAB
| UART_LCR_WLEN8
);
1093 /* Set divisor to 12 => 9600 Baud */
1095 soutp(UART_DLL
, 12);
1098 soutp(UART_LCR
, UART_LCR_WLEN8
);
1099 /* Set divisor to 12 => 9600 Baud */
1102 soutp(UART_MCR
, UART_MCR_RTS
|UART_MCR_DTR
|UART_MCR_OUT2
);
1103 for (i
= 0; i
< 50; i
++)
1106 /* Reset the dongle : set RTS low for 25 ms */
1107 soutp(UART_MCR
, UART_MCR_DTR
|UART_MCR_OUT2
);
1108 for (i
= 0; i
< 25; i
++)
1111 soutp(UART_MCR
, UART_MCR_RTS
|UART_MCR_DTR
|UART_MCR_OUT2
);
1114 /* Clear DTR and set RTS to enter command mode */
1115 soutp(UART_MCR
, UART_MCR_RTS
|UART_MCR_OUT2
);
1118 /* send out the control register settings for 115K 7N1 SIR operation */
1119 for (i
= 0; i
< sizeof(control
); i
++) {
1120 soutp(UART_TX
, control
[i
]);
1121 /* one byte takes ~1042 usec to transmit at 9600,8N1 */
1125 /* back to normal operation */
1126 soutp(UART_MCR
, UART_MCR_RTS
|UART_MCR_DTR
|UART_MCR_OUT2
);
1130 soutp(UART_LCR
, sinp(UART_LCR
) | UART_LCR_DLAB
);
1133 soutp(UART_LCR
, UART_LCR_DLAB
| UART_LCR_WLEN7
);
1135 /* Set divisor to 1 => 115200 Baud */
1140 soutp(UART_LCR
, sinp(UART_LCR
) & (~UART_LCR_DLAB
));
1142 /* Set DLAB 0, 7 Bit */
1143 soutp(UART_LCR
, UART_LCR_WLEN7
);
1145 /* enable interrupts */
1146 soutp(UART_IER
, sinp(UART_IER
)|UART_IER_RDI
);
1150 #ifdef LIRC_SIR_ACTISYS_ACT220L
1152 * Derived from linux IrDA driver (net/irda/actisys.c)
1153 * Drop me a mail for any kind of comment: maxx@spaceboyz.net
1156 void init_act220(void)
1161 soutp(UART_LCR
, UART_LCR_DLAB
|UART_LCR_WLEN7
);
1165 soutp(UART_DLL
, 12);
1168 soutp(UART_LCR
, UART_LCR_WLEN7
);
1170 /* reset the dongle, set DTR low for 10us */
1171 soutp(UART_MCR
, UART_MCR_RTS
|UART_MCR_OUT2
);
1174 /* back to normal (still 9600) */
1175 soutp(UART_MCR
, UART_MCR_DTR
|UART_MCR_RTS
|UART_MCR_OUT2
);
1178 * send RTS pulses until we reach 115200
1179 * i hope this is really the same for act220l/act220l+
1181 for (i
= 0; i
< 3; i
++) {
1183 /* set RTS low for 10 us */
1184 soutp(UART_MCR
, UART_MCR_DTR
|UART_MCR_OUT2
);
1186 /* set RTS high for 10 us */
1187 soutp(UART_MCR
, UART_MCR_RTS
|UART_MCR_DTR
|UART_MCR_OUT2
);
1190 /* back to normal operation */
1191 udelay(1500); /* better safe than sorry ;) */
1194 soutp(UART_LCR
, UART_LCR_DLAB
| UART_LCR_WLEN7
);
1196 /* Set divisor to 1 => 115200 Baud */
1200 /* Set DLAB 0, 7 Bit */
1201 /* The dongle doesn't seem to have any problems with operation at 7N1 */
1202 soutp(UART_LCR
, UART_LCR_WLEN7
);
1204 /* enable interrupts */
1205 soutp(UART_IER
, UART_IER_RDI
);
1209 static int init_lirc_sir(void)
1213 init_waitqueue_head(&lirc_read_queue
);
1214 retval
= init_port();
1218 printk(KERN_INFO LIRC_DRIVER_NAME
1224 static int __init
lirc_sir_init(void)
1228 retval
= init_chrdev();
1231 retval
= init_lirc_sir();
1239 static void __exit
lirc_sir_exit(void)
1244 printk(KERN_INFO LIRC_DRIVER_NAME
": Uninstalled.\n");
1247 module_init(lirc_sir_init
);
1248 module_exit(lirc_sir_exit
);
1250 #ifdef LIRC_SIR_TEKRAM
1251 MODULE_DESCRIPTION("Infrared receiver driver for Tekram Irmate 210");
1252 MODULE_AUTHOR("Christoph Bartelmus");
1253 #elif defined(LIRC_ON_SA1100)
1254 MODULE_DESCRIPTION("LIRC driver for StrongARM SA1100 embedded microprocessor");
1255 MODULE_AUTHOR("Christoph Bartelmus");
1256 #elif defined(LIRC_SIR_ACTISYS_ACT200L)
1257 MODULE_DESCRIPTION("LIRC driver for Actisys Act200L");
1258 MODULE_AUTHOR("Karl Bongers");
1259 #elif defined(LIRC_SIR_ACTISYS_ACT220L)
1260 MODULE_DESCRIPTION("LIRC driver for Actisys Act220L(+)");
1261 MODULE_AUTHOR("Jan Roemisch");
1263 MODULE_DESCRIPTION("Infrared receiver driver for SIR type serial ports");
1264 MODULE_AUTHOR("Milan Pikula");
1266 MODULE_LICENSE("GPL");
1268 #ifdef LIRC_ON_SA1100
1269 module_param(irq
, int, S_IRUGO
);
1270 MODULE_PARM_DESC(irq
, "Interrupt (16)");
1272 module_param(io
, int, S_IRUGO
);
1273 MODULE_PARM_DESC(io
, "I/O address base (0x3f8 or 0x2f8)");
1275 module_param(irq
, int, S_IRUGO
);
1276 MODULE_PARM_DESC(irq
, "Interrupt (4 or 3)");
1278 module_param(threshold
, int, S_IRUGO
);
1279 MODULE_PARM_DESC(threshold
, "space detection threshold (3)");
1282 module_param(debug
, bool, S_IRUGO
| S_IWUSR
);
1283 MODULE_PARM_DESC(debug
, "Enable debugging messages");