36 #include <linux/module.h>
37 #include <linux/sched.h>
38 #include <linux/errno.h>
39 #include <linux/signal.h>
43 #include <linux/kernel.h>
45 #include <linux/time.h>
46 #include <linux/string.h>
47 #include <linux/types.h>
48 #include <linux/wait.h>
51 #include <linux/poll.h>
54 #include <linux/fcntl.h>
58 #ifdef CONFIG_SA1100_COLLIE
59 #include <asm/arch/tc35143.h>
60 #include <asm/ucb1200.h>
72 #ifdef LIRC_SIR_TEKRAM
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
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 {
113 #define LIRC_ON_SA1100_TRANSMITTER_LATENCY 0
116 static unsigned long pulse_width = (13-LIRC_ON_SA1100_TRANSMITTER_LATENCY);
118 static unsigned long space_width = (13-LIRC_ON_SA1100_TRANSMITTER_LATENCY);
119 static unsigned int freq = 38000;
120 static unsigned int duty_cycle = 50;
124 #define RBUF_LEN 1024
125 #define WBUF_LEN 1024
127 #define LIRC_DRIVER_NAME "lirc_sir"
131 #ifndef LIRC_SIR_TEKRAM
133 #define TIME_CONST (9000000ul/115200ul)
138 #define SIR_TIMEOUT (HZ*5/100)
140 #ifndef LIRC_ON_SA1100
146 #if defined(LIRC_SIR_ACTISYS_ACT200L) || \
147 defined(LIRC_SIR_ACTISYS_ACT220L) || \
148 defined(LIRC_SIR_TEKRAM)
149 #define LIRC_PORT 0x3f8
152 #define LIRC_PORT 0x3e8
164 static struct timeval last_tv = {0, 0};
166 static struct timeval last_intr_tv = {0, 0};
167 static int last_value;
174 static unsigned int rx_tail, rx_head;
177 #define dprintk(fmt, args...) \
180 printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
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);
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);
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)
247 poll_wait(file, &lirc_read_queue, wait);
248 if (rx_head != rx_tail)
260 if (count %
sizeof(
int))
266 if (rx_head != rx_tail) {
268 (
void *) (rx_buf + rx_head),
273 rx_head = (rx_head + 1) & (
RBUF_LEN - 1);
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)
304 return PTR_ERR(tx_buf);
306 #ifdef LIRC_ON_SA1100
315 send_pulse(tx_buf[i]);
320 send_space(tx_buf[i]);
324 #ifdef LIRC_ON_SA1100
337 static long lirc_ioctl(
struct file *filep,
unsigned int cmd,
unsigned long arg)
341 #ifdef LIRC_ON_SA1100
372 #ifdef LIRC_ON_SA1100
377 if (value <= 0 || value > 100)
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;
392 if (value > 500000 || value < 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;
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);
444 new_rx_tail = (rx_tail + 1) & (
RBUF_LEN - 1);
445 if (new_rx_tail == rx_head) {
449 rx_buf[rx_tail] = newval;
450 rx_tail = new_rx_tail;
459 .unlocked_ioctl = lirc_ioctl,
461 .compat_ioctl = lirc_ioctl,
468 static int set_use_inc(
void *
data)
473 static void set_use_dec(
void *
data)
493 static int init_chrdev(
void)
495 driver.
dev = &lirc_sir_dev->
dev;
497 if (driver.
minor < 0) {
504 static void drop_chrdev(
void)
518 deltv = deltv*1000000 +
524 static void sir_timeout(
unsigned long data)
534 unsigned long pulse_end;
539 #ifndef LIRC_ON_SA1100
544 pulse_end =
delta(&last_tv, &last_intr_tv);
545 dprintk(
"timeout add %d for %lu usec\n", last_value, pulse_end);
546 add_read_queue(last_value, pulse_end);
548 last_tv = last_intr_tv;
550 spin_unlock_irqrestore(&timer_lock, flags);
557 static unsigned long deltv;
558 #ifdef LIRC_ON_SA1100
577 dprintk(
"receive fifo overrun\n");
589 deltv =
delta(&last_tv, &curr_tv);
592 dprintk(
"%d data: %u\n", n, (
unsigned int) data);
614 unsigned long deltintrtv;
619 switch (iir&UART_IIR_ID) {
639 deltv =
delta(&last_tv, &curr_tv);
640 deltintrtv =
delta(&last_intr_tv, &curr_tv);
641 dprintk(
"t %lu, d %d\n", deltintrtv, (
int)data);
650 add_read_queue(last_value,
662 if (data ^ last_value) {
667 add_read_queue(last_value,
679 last_intr_tv = curr_tv;
692 spin_unlock_irqrestore(&timer_lock, flags);
702 #ifdef LIRC_ON_SA1100
703 static void send_pulse(
unsigned long length)
728 static void send_space(
unsigned long length)
736 static void send_space(
unsigned long len)
741 static void send_pulse(
unsigned long len)
748 while (bytes_out--) {
757 #ifdef CONFIG_SA1100_COLLIE
758 static int sa1100_irda_set_power_collie(
int state)
767 ucb1200_set_io_direction(TC35143_GPIO_IR_ON,
768 TC35143_IODIR_OUTPUT);
769 ucb1200_set_io(TC35143_GPIO_IR_ON, TC35143_IODAT_LOW);
773 ucb1200_set_io_direction(TC35143_GPIO_IR_ON,
774 TC35143_IODIR_OUTPUT);
775 ucb1200_set_io(TC35143_GPIO_IR_ON, TC35143_IODAT_HIGH);
781 static int init_hardware(
void)
787 #ifdef LIRC_ON_SA1100
788 #ifdef CONFIG_SA1100_BITSY
789 if (machine_is_bitsy()) {
791 set_bitsy_egpio(EGPIO_BITSY_IR_ON);
794 #ifdef CONFIG_SA1100_COLLIE
795 sa1100_irda_set_power_collie(3);
837 #elif defined(LIRC_SIR_TEKRAM)
863 safe_udelay(50*1000);
918 #ifdef LIRC_SIR_ACTISYS_ACT200L
920 #elif defined(LIRC_SIR_ACTISYS_ACT220L)
924 spin_unlock_irqrestore(&hardware_lock, flags);
928 static void drop_hardware(
void)
934 #ifdef LIRC_ON_SA1100
944 #ifdef CONFIG_SA1100_BITSY
945 if (machine_is_bitsy())
946 clr_bitsy_egpio(EGPIO_BITSY_IR_ON);
948 #ifdef CONFIG_SA1100_COLLIE
949 sa1100_irda_set_power_collie(0);
955 spin_unlock_irqrestore(&hardware_lock, flags);
960 static int init_port(
void)
965 #ifndef LIRC_ON_SA1100
968 ": i/o port 0x%.4x already in use.\n",
io);
973 LIRC_DRIVER_NAME,
NULL);
975 # ifndef LIRC_ON_SA1100
979 ": IRQ %d already in use.\n",
983 #ifndef LIRC_ON_SA1100
985 ": I/O port 0x%.4x, IRQ %d.\n",
990 timerlist.function = sir_timeout;
991 timerlist.data = 0xabadcafe;
996 static void drop_port(
void)
1000 #ifndef LIRC_ON_SA1100
1005 #ifdef LIRC_SIR_ACTISYS_ACT200L
1010 #define ACT200L_REG0 0x00
1011 #define ACT200L_TXEN 0x01
1012 #define ACT200L_RXEN 0x02
1013 #define ACT200L_ECHO 0x08
1016 #define ACT200L_REG1 0x10
1017 #define ACT200L_LODB 0x01
1018 #define ACT200L_WIDE 0x04
1021 #define ACT200L_REG3 0x30
1022 #define ACT200L_B0 0x01
1023 #define ACT200L_B1 0x02
1024 #define ACT200L_CHSY 0x04
1027 #define ACT200L_REG4 0x40
1028 #define ACT200L_OP0 0x01
1029 #define ACT200L_OP1 0x02
1030 #define ACT200L_BLKR 0x04
1033 #define ACT200L_REG5 0x50
1034 #define ACT200L_RWIDL 0x01
1038 #define ACT200L_REG6 0x60
1039 #define ACT200L_RS0 0x01
1040 #define ACT200L_RS1 0x02
1043 #define ACT200L_REG7 0x70
1044 #define ACT200L_ENPOS 0x04
1047 #define ACT200L_REG8 0x80
1048 #define ACT200L_REG9 0x90
1050 #define ACT200L_2400 0x5f
1051 #define ACT200L_9600 0x17
1052 #define ACT200L_19200 0x0b
1053 #define ACT200L_38400 0x05
1054 #define ACT200L_57600 0x03
1055 #define ACT200L_115200 0x01
1058 #define ACT200L_REG13 0xd0
1059 #define ACT200L_SHDW 0x01
1062 #define ACT200L_REG15 0xf0
1065 #define ACT200L_REG21 0x50
1066 #define ACT200L_EXCK 0x02
1067 #define ACT200L_OSCL 0x04
1069 static void init_act200(
void)
1081 ACT200L_REG3 | ACT200L_B0,
1101 for (i = 0; i < 50; i++)
1106 for (i = 0; i < 25; i++)
1117 for (i = 0; i <
sizeof(
control); i++) {
1148 #ifdef LIRC_SIR_ACTISYS_ACT220L
1154 void init_act220(
void)
1179 for (i = 0; i < 3; i++) {
1207 static int init_lirc_sir(
void)
1212 retval = init_port();
1232 .probe = lirc_sir_probe,
1240 static int __init lirc_sir_init(
void)
1252 if (!lirc_sir_dev) {
1256 goto pdev_alloc_fail;
1267 retval = init_chrdev();
1271 retval = init_lirc_sir();
1288 static void __exit lirc_sir_exit(
void)
1301 #ifdef LIRC_SIR_TEKRAM
1304 #elif defined(LIRC_ON_SA1100)
1307 #elif defined(LIRC_SIR_ACTISYS_ACT200L)
1310 #elif defined(LIRC_SIR_ACTISYS_ACT220L)
1319 #ifdef LIRC_ON_SA1100