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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
38 #include <linux/module.h>
39 #include <linux/sched.h>
40 #include <linux/errno.h>
41 #include <linux/signal.h>
43 #include <linux/interrupt.h>
44 #include <linux/ioport.h>
45 #include <linux/kernel.h>
46 #include <linux/serial_reg.h>
47 #include <linux/time.h>
48 #include <linux/string.h>
49 #include <linux/types.h>
50 #include <linux/wait.h>
52 #include <linux/delay.h>
53 #include <linux/poll.h>
56 #include <linux/fcntl.h>
57 #include <linux/platform_device.h>
59 #include <asm/hardware.h>
60 #ifdef CONFIG_SA1100_COLLIE
61 #include <asm/arch/tc35143.h>
62 #include <asm/ucb1200.h>
66 #include <linux/timer.h>
68 #include <media/lirc.h>
69 #include <media/lirc_dev.h>
71 /* SECTION: Definitions */
73 /*** Tekram dongle ***/
74 #ifdef LIRC_SIR_TEKRAM
75 /* stolen from kernel source */
76 /* definitions for Tekram dongle */
77 #define TEKRAM_115200 0x00
78 #define TEKRAM_57600 0x01
79 #define TEKRAM_38400 0x02
80 #define TEKRAM_19200 0x03
81 #define TEKRAM_9600 0x04
82 #define TEKRAM_2400 0x08
84 #define TEKRAM_PW 0x10 /* Pulse select bit */
86 /* 10bit * 1s/115200bit in milliseconds = 87ms*/
87 #define TIME_CONST (10000000ul/115200ul)
91 #ifdef LIRC_SIR_ACTISYS_ACT200L
92 static void init_act200(void);
93 #elif defined(LIRC_SIR_ACTISYS_ACT220L)
94 static void init_act220(void);
99 struct sa1100_ser2_registers
{
100 /* HSSP control register */
113 static int irq
= IRQ_Ser2ICP
;
115 #define LIRC_ON_SA1100_TRANSMITTER_LATENCY 0
117 /* pulse/space ratio of 50/50 */
118 static unsigned long pulse_width
= (13-LIRC_ON_SA1100_TRANSMITTER_LATENCY
);
119 /* 1000000/freq-pulse_width */
120 static unsigned long space_width
= (13-LIRC_ON_SA1100_TRANSMITTER_LATENCY
);
121 static unsigned int freq
= 38000; /* modulation frequency */
122 static unsigned int duty_cycle
= 50; /* duty cycle of 50% */
126 #define RBUF_LEN 1024
127 #define WBUF_LEN 1024
129 #define LIRC_DRIVER_NAME "lirc_sir"
133 #ifndef LIRC_SIR_TEKRAM
134 /* 9bit * 1s/115200bit in milli seconds = 78.125ms*/
135 #define TIME_CONST (9000000ul/115200ul)
139 /* timeout for sequences in jiffies (=5/100s), must be longer than TIME_CONST */
140 #define SIR_TIMEOUT (HZ*5/100)
142 #ifndef LIRC_ON_SA1100
147 /* for external dongles, default to com1 */
148 #if defined(LIRC_SIR_ACTISYS_ACT200L) || \
149 defined(LIRC_SIR_ACTISYS_ACT220L) || \
150 defined(LIRC_SIR_TEKRAM)
151 #define LIRC_PORT 0x3f8
153 /* onboard sir ports are typically com3 */
154 #define LIRC_PORT 0x3e8
158 static int io
= LIRC_PORT
;
159 static int irq
= LIRC_IRQ
;
160 static int threshold
= 3;
163 static DEFINE_SPINLOCK(timer_lock
);
164 static struct timer_list timerlist
;
165 /* time of last signal change detected */
166 static struct timeval last_tv
= {0, 0};
167 /* time of last UART data ready interrupt */
168 static struct timeval last_intr_tv
= {0, 0};
169 static int last_value
;
171 static DECLARE_WAIT_QUEUE_HEAD(lirc_read_queue
);
173 static DEFINE_SPINLOCK(hardware_lock
);
175 static int rx_buf
[RBUF_LEN
];
176 static unsigned int rx_tail
, rx_head
;
179 #define dprintk(fmt, args...) \
182 printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
186 /* SECTION: Prototypes */
188 /* Communication with user-space */
189 static unsigned int lirc_poll(struct file
*file
, poll_table
*wait
);
190 static ssize_t
lirc_read(struct file
*file
, char *buf
, size_t count
,
192 static ssize_t
lirc_write(struct file
*file
, const char *buf
, size_t n
,
194 static long lirc_ioctl(struct file
*filep
, unsigned int cmd
, unsigned long arg
);
195 static void add_read_queue(int flag
, unsigned long val
);
196 static int init_chrdev(void);
197 static void drop_chrdev(void);
199 static irqreturn_t
sir_interrupt(int irq
, void *dev_id
);
200 static void send_space(unsigned long len
);
201 static void send_pulse(unsigned long len
);
202 static int init_hardware(void);
203 static void drop_hardware(void);
205 static int init_port(void);
206 static void drop_port(void);
208 #ifdef LIRC_ON_SA1100
214 static void off(void)
219 static inline unsigned int sinp(int offset
)
221 return inb(io
+ offset
);
224 static inline void soutp(int offset
, int value
)
226 outb(value
, io
+ offset
);
230 #ifndef MAX_UDELAY_MS
231 #define MAX_UDELAY_US 5000
233 #define MAX_UDELAY_US (MAX_UDELAY_MS*1000)
236 static void safe_udelay(unsigned long usecs
)
238 while (usecs
> MAX_UDELAY_US
) {
239 udelay(MAX_UDELAY_US
);
240 usecs
-= MAX_UDELAY_US
;
245 /* SECTION: Communication with user-space */
247 static unsigned int lirc_poll(struct file
*file
, poll_table
*wait
)
249 poll_wait(file
, &lirc_read_queue
, wait
);
250 if (rx_head
!= rx_tail
)
251 return POLLIN
| POLLRDNORM
;
255 static ssize_t
lirc_read(struct file
*file
, char *buf
, size_t count
,
260 DECLARE_WAITQUEUE(wait
, current
);
262 if (count
% sizeof(int))
265 add_wait_queue(&lirc_read_queue
, &wait
);
266 set_current_state(TASK_INTERRUPTIBLE
);
268 if (rx_head
!= rx_tail
) {
269 if (copy_to_user((void *) buf
+ n
,
270 (void *) (rx_buf
+ rx_head
),
275 rx_head
= (rx_head
+ 1) & (RBUF_LEN
- 1);
278 if (file
->f_flags
& O_NONBLOCK
) {
282 if (signal_pending(current
)) {
283 retval
= -ERESTARTSYS
;
287 set_current_state(TASK_INTERRUPTIBLE
);
290 remove_wait_queue(&lirc_read_queue
, &wait
);
291 set_current_state(TASK_RUNNING
);
292 return n
? n
: retval
;
294 static ssize_t
lirc_write(struct file
*file
, const char *buf
, size_t n
,
301 count
= n
/ sizeof(int);
302 if (n
% sizeof(int) || count
% 2 == 0)
304 tx_buf
= memdup_user(buf
, n
);
306 return PTR_ERR(tx_buf
);
308 #ifdef LIRC_ON_SA1100
309 /* disable receiver */
312 local_irq_save(flags
);
317 send_pulse(tx_buf
[i
]);
322 send_space(tx_buf
[i
]);
325 local_irq_restore(flags
);
326 #ifdef LIRC_ON_SA1100
328 udelay(1000); /* wait 1ms for IR diode to recover */
330 /* clear status register to prevent unwanted interrupts */
331 Ser2UTSR0
&= (UTSR0_RID
| UTSR0_RBB
| UTSR0_REB
);
332 /* enable receiver */
333 Ser2UTCR3
= UTCR3_RXE
|UTCR3_RIE
;
339 static long lirc_ioctl(struct file
*filep
, unsigned int cmd
, unsigned long arg
)
343 #ifdef LIRC_ON_SA1100
345 if (cmd
== LIRC_GET_FEATURES
)
346 value
= LIRC_CAN_SEND_PULSE
|
347 LIRC_CAN_SET_SEND_DUTY_CYCLE
|
348 LIRC_CAN_SET_SEND_CARRIER
|
350 else if (cmd
== LIRC_GET_SEND_MODE
)
351 value
= LIRC_MODE_PULSE
;
352 else if (cmd
== LIRC_GET_REC_MODE
)
353 value
= LIRC_MODE_MODE2
;
355 if (cmd
== LIRC_GET_FEATURES
)
356 value
= LIRC_CAN_SEND_PULSE
| LIRC_CAN_REC_MODE2
;
357 else if (cmd
== LIRC_GET_SEND_MODE
)
358 value
= LIRC_MODE_PULSE
;
359 else if (cmd
== LIRC_GET_REC_MODE
)
360 value
= LIRC_MODE_MODE2
;
364 case LIRC_GET_FEATURES
:
365 case LIRC_GET_SEND_MODE
:
366 case LIRC_GET_REC_MODE
:
367 retval
= put_user(value
, (__u32
*) arg
);
370 case LIRC_SET_SEND_MODE
:
371 case LIRC_SET_REC_MODE
:
372 retval
= get_user(value
, (__u32
*) arg
);
374 #ifdef LIRC_ON_SA1100
375 case LIRC_SET_SEND_DUTY_CYCLE
:
376 retval
= get_user(value
, (__u32
*) arg
);
379 if (value
<= 0 || value
> 100)
381 /* (value/100)*(1000000/freq) */
383 pulse_width
= (unsigned long) duty_cycle
*10000/freq
;
384 space_width
= (unsigned long) 1000000L/freq
-pulse_width
;
385 if (pulse_width
>= LIRC_ON_SA1100_TRANSMITTER_LATENCY
)
386 pulse_width
-= LIRC_ON_SA1100_TRANSMITTER_LATENCY
;
387 if (space_width
>= LIRC_ON_SA1100_TRANSMITTER_LATENCY
)
388 space_width
-= LIRC_ON_SA1100_TRANSMITTER_LATENCY
;
390 case LIRC_SET_SEND_CARRIER
:
391 retval
= get_user(value
, (__u32
*) arg
);
394 if (value
> 500000 || value
< 20000)
397 pulse_width
= (unsigned long) duty_cycle
*10000/freq
;
398 space_width
= (unsigned long) 1000000L/freq
-pulse_width
;
399 if (pulse_width
>= LIRC_ON_SA1100_TRANSMITTER_LATENCY
)
400 pulse_width
-= LIRC_ON_SA1100_TRANSMITTER_LATENCY
;
401 if (space_width
>= LIRC_ON_SA1100_TRANSMITTER_LATENCY
)
402 space_width
-= LIRC_ON_SA1100_TRANSMITTER_LATENCY
;
406 retval
= -ENOIOCTLCMD
;
412 if (cmd
== LIRC_SET_REC_MODE
) {
413 if (value
!= LIRC_MODE_MODE2
)
415 } else if (cmd
== LIRC_SET_SEND_MODE
) {
416 if (value
!= LIRC_MODE_PULSE
)
423 static void add_read_queue(int flag
, unsigned long val
)
425 unsigned int new_rx_tail
;
428 dprintk("add flag %d with val %lu\n", flag
, val
);
430 newval
= val
& PULSE_MASK
;
433 * statistically, pulses are ~TIME_CONST/2 too long. we could
434 * maybe make this more exact, but this is good enough
438 if (newval
> TIME_CONST
/2)
439 newval
-= TIME_CONST
/2;
440 else /* should not ever happen */
444 newval
+= TIME_CONST
/2;
446 new_rx_tail
= (rx_tail
+ 1) & (RBUF_LEN
- 1);
447 if (new_rx_tail
== rx_head
) {
448 dprintk("Buffer overrun.\n");
451 rx_buf
[rx_tail
] = newval
;
452 rx_tail
= new_rx_tail
;
453 wake_up_interruptible(&lirc_read_queue
);
456 static const struct file_operations lirc_fops
= {
457 .owner
= THIS_MODULE
,
461 .unlocked_ioctl
= lirc_ioctl
,
463 .compat_ioctl
= lirc_ioctl
,
465 .open
= lirc_dev_fop_open
,
466 .release
= lirc_dev_fop_close
,
470 static int set_use_inc(void *data
)
475 static void set_use_dec(void *data
)
479 static struct lirc_driver driver
= {
480 .name
= LIRC_DRIVER_NAME
,
486 .set_use_inc
= set_use_inc
,
487 .set_use_dec
= set_use_dec
,
490 .owner
= THIS_MODULE
,
493 static struct platform_device
*lirc_sir_dev
;
495 static int init_chrdev(void)
497 driver
.dev
= &lirc_sir_dev
->dev
;
498 driver
.minor
= lirc_register_driver(&driver
);
499 if (driver
.minor
< 0) {
500 pr_err("init_chrdev() failed.\n");
506 static void drop_chrdev(void)
508 lirc_unregister_driver(driver
.minor
);
511 /* SECTION: Hardware */
512 static long delta(struct timeval
*tv1
, struct timeval
*tv2
)
516 deltv
= tv2
->tv_sec
- tv1
->tv_sec
;
520 deltv
= deltv
*1000000 +
526 static void sir_timeout(unsigned long data
)
529 * if last received signal was a pulse, but receiving stopped
530 * within the 9 bit frame, we need to finish this pulse and
531 * simulate a signal change to from pulse to space. Otherwise
532 * upper layers will receive two sequences next time.
536 unsigned long pulse_end
;
538 /* avoid interference with interrupt */
539 spin_lock_irqsave(&timer_lock
, flags
);
541 #ifndef LIRC_ON_SA1100
542 /* clear unread bits in UART and restart */
543 outb(UART_FCR_CLEAR_RCVR
, io
+ UART_FCR
);
545 /* determine 'virtual' pulse end: */
546 pulse_end
= delta(&last_tv
, &last_intr_tv
);
547 dprintk("timeout add %d for %lu usec\n", last_value
, pulse_end
);
548 add_read_queue(last_value
, pulse_end
);
550 last_tv
= last_intr_tv
;
552 spin_unlock_irqrestore(&timer_lock
, flags
);
555 static irqreturn_t
sir_interrupt(int irq
, void *dev_id
)
558 struct timeval curr_tv
;
559 static unsigned long deltv
;
560 #ifdef LIRC_ON_SA1100
566 * Deal with any receive errors first. The bytes in error may be
567 * the only bytes in the receive FIFO, so we do this first.
569 while (status
& UTSR0_EIF
) {
576 if (bstat
& UTSR1_FRE
)
577 dprintk("frame error\n");
578 if (bstat
& UTSR1_ROR
)
579 dprintk("receive fifo overrun\n");
580 if (bstat
& UTSR1_PRE
)
581 dprintk("parity error\n");
589 if (status
& (UTSR0_RFS
| UTSR0_RID
)) {
590 do_gettimeofday(&curr_tv
);
591 deltv
= delta(&last_tv
, &curr_tv
);
594 dprintk("%d data: %u\n", n
, (unsigned int) data
);
596 } while (status
& UTSR0_RID
&& /* do not empty fifo in order to
597 * get UTSR0_RID in any case */
598 Ser2UTSR1
& UTSR1_RNE
); /* data ready */
600 if (status
&UTSR0_RID
) {
601 add_read_queue(0 , deltv
- n
* TIME_CONST
); /*space*/
602 add_read_queue(1, n
* TIME_CONST
); /*pulse*/
608 if (status
& UTSR0_TFS
)
609 pr_err("transmit fifo not full, shouldn't happen\n");
611 /* We must clear certain bits. */
612 status
&= (UTSR0_RID
| UTSR0_RBB
| UTSR0_REB
);
616 unsigned long deltintrtv
;
620 while ((iir
= inb(io
+ UART_IIR
) & UART_IIR_ID
)) {
621 switch (iir
&UART_IIR_ID
) { /* FIXME toto treba preriedit */
623 (void) inb(io
+ UART_MSR
);
626 (void) inb(io
+ UART_LSR
);
630 if (lsr
& UART_LSR_THRE
) /* FIFO is empty */
631 outb(data
, io
+ UART_TX
)
635 /* avoid interference with timer */
636 spin_lock_irqsave(&timer_lock
, flags
);
638 del_timer(&timerlist
);
639 data
= inb(io
+ UART_RX
);
640 do_gettimeofday(&curr_tv
);
641 deltv
= delta(&last_tv
, &curr_tv
);
642 deltintrtv
= delta(&last_intr_tv
, &curr_tv
);
643 dprintk("t %lu, d %d\n", deltintrtv
, (int)data
);
645 * if nothing came in last X cycles,
648 if (deltintrtv
> TIME_CONST
* threshold
) {
651 /* simulate signal change */
652 add_read_queue(last_value
,
659 last_intr_tv
.tv_usec
;
664 if (data
^ last_value
) {
666 * deltintrtv > 2*TIME_CONST, remember?
667 * the other case is timeout
669 add_read_queue(last_value
,
673 if (last_tv
.tv_usec
>= TIME_CONST
) {
674 last_tv
.tv_usec
-= TIME_CONST
;
677 last_tv
.tv_usec
+= 1000000 -
681 last_intr_tv
= curr_tv
;
684 * start timer for end of
687 timerlist
.expires
= jiffies
+
689 add_timer(&timerlist
);
692 lsr
= inb(io
+ UART_LSR
);
693 } while (lsr
& UART_LSR_DR
); /* data ready */
694 spin_unlock_irqrestore(&timer_lock
, flags
);
701 return IRQ_RETVAL(IRQ_HANDLED
);
704 #ifdef LIRC_ON_SA1100
705 static void send_pulse(unsigned long length
)
707 unsigned long k
, delay
;
713 * this won't give us the carrier frequency we really want
714 * due to integer arithmetic, but we can accept this inaccuracy
717 for (k
= flag
= 0; k
< length
; k
+= delay
, flag
= !flag
) {
730 static void send_space(unsigned long length
)
738 static void send_space(unsigned long len
)
743 static void send_pulse(unsigned long len
)
745 long bytes_out
= len
/ TIME_CONST
;
750 while (bytes_out
--) {
751 outb(PULSE
, io
+ UART_TX
);
752 /* FIXME treba seriozne cakanie z char/serial.c */
753 while (!(inb(io
+ UART_LSR
) & UART_LSR_THRE
))
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 pr_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 pr_info("0x%02x\n", sinp(UART_RX
));
893 soutp(UART_LCR
, sinp(UART_LCR
) | UART_LCR_DLAB
);
895 /* Set divisor to 1 => 115200 Baud */
899 /* Set DLAB 0, 8 Bit */
900 soutp(UART_LCR
, UART_LCR_WLEN8
);
901 /* enable interrupts */
902 soutp(UART_IER
, sinp(UART_IER
)|UART_IER_RDI
);
904 outb(0, io
+ UART_MCR
);
905 outb(0, io
+ UART_IER
);
907 /* set DLAB, speed = 115200 */
908 outb(UART_LCR_DLAB
| UART_LCR_WLEN7
, io
+ UART_LCR
);
909 outb(1, io
+ UART_DLL
); outb(0, io
+ UART_DLM
);
910 /* 7N1+start = 9 bits at 115200 ~ 3 bits at 44000 */
911 outb(UART_LCR_WLEN7
, io
+ UART_LCR
);
913 outb(UART_FCR_ENABLE_FIFO
, io
+ UART_FCR
);
915 /* outb(UART_IER_RLSI|UART_IER_RDI|UART_IER_THRI, io + UART_IER); */
916 outb(UART_IER_RDI
, io
+ UART_IER
);
918 outb(UART_MCR_DTR
|UART_MCR_RTS
|UART_MCR_OUT2
, io
+ UART_MCR
);
919 #ifdef LIRC_SIR_ACTISYS_ACT200L
921 #elif defined(LIRC_SIR_ACTISYS_ACT220L)
925 spin_unlock_irqrestore(&hardware_lock
, flags
);
929 static void drop_hardware(void)
933 spin_lock_irqsave(&hardware_lock
, flags
);
935 #ifdef LIRC_ON_SA1100
938 Ser2UTCR0
= sr
.utcr0
;
939 Ser2UTCR1
= sr
.utcr1
;
940 Ser2UTCR2
= sr
.utcr2
;
941 Ser2UTCR4
= sr
.utcr4
;
942 Ser2UTCR3
= sr
.utcr3
;
944 Ser2HSCR0
= sr
.hscr0
;
945 #ifdef CONFIG_SA1100_BITSY
946 if (machine_is_bitsy())
947 clr_bitsy_egpio(EGPIO_BITSY_IR_ON
);
949 #ifdef CONFIG_SA1100_COLLIE
950 sa1100_irda_set_power_collie(0); /* power off */
953 /* turn off interrupts */
954 outb(0, io
+ UART_IER
);
956 spin_unlock_irqrestore(&hardware_lock
, flags
);
959 /* SECTION: Initialisation */
961 static int init_port(void)
965 /* get I/O port access and IRQ line */
966 #ifndef LIRC_ON_SA1100
967 if (request_region(io
, 8, LIRC_DRIVER_NAME
) == NULL
) {
968 pr_err("i/o port 0x%.4x already in use.\n", io
);
972 retval
= request_irq(irq
, sir_interrupt
, 0,
973 LIRC_DRIVER_NAME
, NULL
);
975 # ifndef LIRC_ON_SA1100
976 release_region(io
, 8);
978 pr_err("IRQ %d already in use.\n", irq
);
981 #ifndef LIRC_ON_SA1100
982 pr_info("I/O port 0x%.4x, IRQ %d.\n", io
, irq
);
985 init_timer(&timerlist
);
986 timerlist
.function
= sir_timeout
;
987 timerlist
.data
= 0xabadcafe;
992 static void drop_port(void)
995 del_timer_sync(&timerlist
);
996 #ifndef LIRC_ON_SA1100
997 release_region(io
, 8);
1001 #ifdef LIRC_SIR_ACTISYS_ACT200L
1002 /* Crystal/Cirrus CS8130 IR transceiver, used in Actisys Act200L dongle */
1003 /* some code borrowed from Linux IRDA driver */
1005 /* Register 0: Control register #1 */
1006 #define ACT200L_REG0 0x00
1007 #define ACT200L_TXEN 0x01 /* Enable transmitter */
1008 #define ACT200L_RXEN 0x02 /* Enable receiver */
1009 #define ACT200L_ECHO 0x08 /* Echo control chars */
1011 /* Register 1: Control register #2 */
1012 #define ACT200L_REG1 0x10
1013 #define ACT200L_LODB 0x01 /* Load new baud rate count value */
1014 #define ACT200L_WIDE 0x04 /* Expand the maximum allowable pulse */
1016 /* Register 3: Transmit mode register #2 */
1017 #define ACT200L_REG3 0x30
1018 #define ACT200L_B0 0x01 /* DataBits, 0=6, 1=7, 2=8, 3=9(8P) */
1019 #define ACT200L_B1 0x02 /* DataBits, 0=6, 1=7, 2=8, 3=9(8P) */
1020 #define ACT200L_CHSY 0x04 /* StartBit Synced 0=bittime, 1=startbit */
1022 /* Register 4: Output Power register */
1023 #define ACT200L_REG4 0x40
1024 #define ACT200L_OP0 0x01 /* Enable LED1C output */
1025 #define ACT200L_OP1 0x02 /* Enable LED2C output */
1026 #define ACT200L_BLKR 0x04
1028 /* Register 5: Receive Mode register */
1029 #define ACT200L_REG5 0x50
1030 #define ACT200L_RWIDL 0x01 /* fixed 1.6us pulse mode */
1031 /*.. other various IRDA bit modes, and TV remote modes..*/
1033 /* Register 6: Receive Sensitivity register #1 */
1034 #define ACT200L_REG6 0x60
1035 #define ACT200L_RS0 0x01 /* receive threshold bit 0 */
1036 #define ACT200L_RS1 0x02 /* receive threshold bit 1 */
1038 /* Register 7: Receive Sensitivity register #2 */
1039 #define ACT200L_REG7 0x70
1040 #define ACT200L_ENPOS 0x04 /* Ignore the falling edge */
1042 /* Register 8,9: Baud Rate Divider register #1,#2 */
1043 #define ACT200L_REG8 0x80
1044 #define ACT200L_REG9 0x90
1046 #define ACT200L_2400 0x5f
1047 #define ACT200L_9600 0x17
1048 #define ACT200L_19200 0x0b
1049 #define ACT200L_38400 0x05
1050 #define ACT200L_57600 0x03
1051 #define ACT200L_115200 0x01
1053 /* Register 13: Control register #3 */
1054 #define ACT200L_REG13 0xd0
1055 #define ACT200L_SHDW 0x01 /* Enable access to shadow registers */
1057 /* Register 15: Status register */
1058 #define ACT200L_REG15 0xf0
1060 /* Register 21: Control register #4 */
1061 #define ACT200L_REG21 0x50
1062 #define ACT200L_EXCK 0x02 /* Disable clock output driver */
1063 #define ACT200L_OSCL 0x04 /* oscillator in low power, medium accuracy mode */
1065 static void init_act200(void)
1070 ACT200L_REG13
| ACT200L_SHDW
,
1071 ACT200L_REG21
| ACT200L_EXCK
| ACT200L_OSCL
,
1073 ACT200L_REG7
| ACT200L_ENPOS
,
1074 ACT200L_REG6
| ACT200L_RS0
| ACT200L_RS1
,
1075 ACT200L_REG5
| ACT200L_RWIDL
,
1076 ACT200L_REG4
| ACT200L_OP0
| ACT200L_OP1
| ACT200L_BLKR
,
1077 ACT200L_REG3
| ACT200L_B0
,
1078 ACT200L_REG0
| ACT200L_TXEN
| ACT200L_RXEN
,
1079 ACT200L_REG8
| (ACT200L_115200
& 0x0f),
1080 ACT200L_REG9
| ((ACT200L_115200
>> 4) & 0x0f),
1081 ACT200L_REG1
| ACT200L_LODB
| ACT200L_WIDE
1085 soutp(UART_LCR
, UART_LCR_DLAB
| UART_LCR_WLEN8
);
1087 /* Set divisor to 12 => 9600 Baud */
1089 soutp(UART_DLL
, 12);
1092 soutp(UART_LCR
, UART_LCR_WLEN8
);
1093 /* Set divisor to 12 => 9600 Baud */
1096 soutp(UART_MCR
, UART_MCR_RTS
|UART_MCR_DTR
|UART_MCR_OUT2
);
1097 for (i
= 0; i
< 50; i
++)
1100 /* Reset the dongle : set RTS low for 25 ms */
1101 soutp(UART_MCR
, UART_MCR_DTR
|UART_MCR_OUT2
);
1102 for (i
= 0; i
< 25; i
++)
1105 soutp(UART_MCR
, UART_MCR_RTS
|UART_MCR_DTR
|UART_MCR_OUT2
);
1108 /* Clear DTR and set RTS to enter command mode */
1109 soutp(UART_MCR
, UART_MCR_RTS
|UART_MCR_OUT2
);
1112 /* send out the control register settings for 115K 7N1 SIR operation */
1113 for (i
= 0; i
< sizeof(control
); i
++) {
1114 soutp(UART_TX
, control
[i
]);
1115 /* one byte takes ~1042 usec to transmit at 9600,8N1 */
1119 /* back to normal operation */
1120 soutp(UART_MCR
, UART_MCR_RTS
|UART_MCR_DTR
|UART_MCR_OUT2
);
1124 soutp(UART_LCR
, sinp(UART_LCR
) | UART_LCR_DLAB
);
1127 soutp(UART_LCR
, UART_LCR_DLAB
| UART_LCR_WLEN7
);
1129 /* Set divisor to 1 => 115200 Baud */
1134 soutp(UART_LCR
, sinp(UART_LCR
) & (~UART_LCR_DLAB
));
1136 /* Set DLAB 0, 7 Bit */
1137 soutp(UART_LCR
, UART_LCR_WLEN7
);
1139 /* enable interrupts */
1140 soutp(UART_IER
, sinp(UART_IER
)|UART_IER_RDI
);
1144 #ifdef LIRC_SIR_ACTISYS_ACT220L
1146 * Derived from linux IrDA driver (net/irda/actisys.c)
1147 * Drop me a mail for any kind of comment: maxx@spaceboyz.net
1150 void init_act220(void)
1155 soutp(UART_LCR
, UART_LCR_DLAB
|UART_LCR_WLEN7
);
1159 soutp(UART_DLL
, 12);
1162 soutp(UART_LCR
, UART_LCR_WLEN7
);
1164 /* reset the dongle, set DTR low for 10us */
1165 soutp(UART_MCR
, UART_MCR_RTS
|UART_MCR_OUT2
);
1168 /* back to normal (still 9600) */
1169 soutp(UART_MCR
, UART_MCR_DTR
|UART_MCR_RTS
|UART_MCR_OUT2
);
1172 * send RTS pulses until we reach 115200
1173 * i hope this is really the same for act220l/act220l+
1175 for (i
= 0; i
< 3; i
++) {
1177 /* set RTS low for 10 us */
1178 soutp(UART_MCR
, UART_MCR_DTR
|UART_MCR_OUT2
);
1180 /* set RTS high for 10 us */
1181 soutp(UART_MCR
, UART_MCR_RTS
|UART_MCR_DTR
|UART_MCR_OUT2
);
1184 /* back to normal operation */
1185 udelay(1500); /* better safe than sorry ;) */
1188 soutp(UART_LCR
, UART_LCR_DLAB
| UART_LCR_WLEN7
);
1190 /* Set divisor to 1 => 115200 Baud */
1194 /* Set DLAB 0, 7 Bit */
1195 /* The dongle doesn't seem to have any problems with operation at 7N1 */
1196 soutp(UART_LCR
, UART_LCR_WLEN7
);
1198 /* enable interrupts */
1199 soutp(UART_IER
, UART_IER_RDI
);
1203 static int init_lirc_sir(void)
1207 init_waitqueue_head(&lirc_read_queue
);
1208 retval
= init_port();
1212 pr_info("Installed.\n");
1216 static int lirc_sir_probe(struct platform_device
*dev
)
1221 static int lirc_sir_remove(struct platform_device
*dev
)
1226 static struct platform_driver lirc_sir_driver
= {
1227 .probe
= lirc_sir_probe
,
1228 .remove
= lirc_sir_remove
,
1231 .owner
= THIS_MODULE
,
1235 static int __init
lirc_sir_init(void)
1239 retval
= platform_driver_register(&lirc_sir_driver
);
1241 pr_err("Platform driver register failed!\n");
1245 lirc_sir_dev
= platform_device_alloc("lirc_dev", 0);
1246 if (!lirc_sir_dev
) {
1247 pr_err("Platform device alloc failed!\n");
1249 goto pdev_alloc_fail
;
1252 retval
= platform_device_add(lirc_sir_dev
);
1254 pr_err("Platform device add failed!\n");
1259 retval
= init_chrdev();
1263 retval
= init_lirc_sir();
1272 platform_device_del(lirc_sir_dev
);
1274 platform_device_put(lirc_sir_dev
);
1276 platform_driver_unregister(&lirc_sir_driver
);
1280 static void __exit
lirc_sir_exit(void)
1285 platform_device_unregister(lirc_sir_dev
);
1286 platform_driver_unregister(&lirc_sir_driver
);
1287 pr_info("Uninstalled.\n");
1290 module_init(lirc_sir_init
);
1291 module_exit(lirc_sir_exit
);
1293 #ifdef LIRC_SIR_TEKRAM
1294 MODULE_DESCRIPTION("Infrared receiver driver for Tekram Irmate 210");
1295 MODULE_AUTHOR("Christoph Bartelmus");
1296 #elif defined(LIRC_ON_SA1100)
1297 MODULE_DESCRIPTION("LIRC driver for StrongARM SA1100 embedded microprocessor");
1298 MODULE_AUTHOR("Christoph Bartelmus");
1299 #elif defined(LIRC_SIR_ACTISYS_ACT200L)
1300 MODULE_DESCRIPTION("LIRC driver for Actisys Act200L");
1301 MODULE_AUTHOR("Karl Bongers");
1302 #elif defined(LIRC_SIR_ACTISYS_ACT220L)
1303 MODULE_DESCRIPTION("LIRC driver for Actisys Act220L(+)");
1304 MODULE_AUTHOR("Jan Roemisch");
1306 MODULE_DESCRIPTION("Infrared receiver driver for SIR type serial ports");
1307 MODULE_AUTHOR("Milan Pikula");
1309 MODULE_LICENSE("GPL");
1311 #ifdef LIRC_ON_SA1100
1312 module_param(irq
, int, S_IRUGO
);
1313 MODULE_PARM_DESC(irq
, "Interrupt (16)");
1315 module_param(io
, int, S_IRUGO
);
1316 MODULE_PARM_DESC(io
, "I/O address base (0x3f8 or 0x2f8)");
1318 module_param(irq
, int, S_IRUGO
);
1319 MODULE_PARM_DESC(irq
, "Interrupt (4 or 3)");
1321 module_param(threshold
, int, S_IRUGO
);
1322 MODULE_PARM_DESC(threshold
, "space detection threshold (3)");
1325 module_param(debug
, bool, S_IRUGO
| S_IWUSR
);
1326 MODULE_PARM_DESC(debug
, "Enable debugging messages");