Merge branch 'stable-3.2' into pandora-3.2
[pandora-kernel.git] / drivers / staging / media / lirc / lirc_sir.c
1 /*
2  * LIRC SIR driver, (C) 2000 Milan Pikula <www@fornax.sk>
3  *
4  * lirc_sir - Device driver for use with SIR (serial infra red)
5  * mode of IrDA on many notebooks.
6  *
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.
11  *
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.
16  *
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
20  *
21  *
22  * 2000/09/16 Frank Przybylski <mail@frankprzybylski.de> :
23  *  added timeout and relaxed pulse detection, removed gap bug
24  *
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
28  *   before),
29  *   major clean-up
30  *
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
34  */
35
36 #include <linux/module.h>
37 #include <linux/sched.h>
38 #include <linux/errno.h>
39 #include <linux/signal.h>
40 #include <linux/fs.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>
49 #include <linux/mm.h>
50 #include <linux/delay.h>
51 #include <linux/poll.h>
52 #include <asm/system.h>
53 #include <linux/io.h>
54 #include <asm/irq.h>
55 #include <linux/fcntl.h>
56 #include <linux/platform_device.h>
57 #ifdef LIRC_ON_SA1100
58 #include <asm/hardware.h>
59 #ifdef CONFIG_SA1100_COLLIE
60 #include <asm/arch/tc35143.h>
61 #include <asm/ucb1200.h>
62 #endif
63 #endif
64
65 #include <linux/timer.h>
66
67 #include <media/lirc.h>
68 #include <media/lirc_dev.h>
69
70 /* SECTION: Definitions */
71
72 /*** Tekram dongle ***/
73 #ifdef LIRC_SIR_TEKRAM
74 /* stolen from kernel source */
75 /* definitions for Tekram dongle */
76 #define TEKRAM_115200 0x00
77 #define TEKRAM_57600  0x01
78 #define TEKRAM_38400  0x02
79 #define TEKRAM_19200  0x03
80 #define TEKRAM_9600   0x04
81 #define TEKRAM_2400   0x08
82
83 #define TEKRAM_PW 0x10 /* Pulse select bit */
84
85 /* 10bit * 1s/115200bit in milliseconds = 87ms*/
86 #define TIME_CONST (10000000ul/115200ul)
87
88 #endif
89
90 #ifdef LIRC_SIR_ACTISYS_ACT200L
91 static void init_act200(void);
92 #elif defined(LIRC_SIR_ACTISYS_ACT220L)
93 static void init_act220(void);
94 #endif
95
96 /*** SA1100 ***/
97 #ifdef LIRC_ON_SA1100
98 struct sa1100_ser2_registers {
99         /* HSSP control register */
100         unsigned char hscr0;
101         /* UART registers */
102         unsigned char utcr0;
103         unsigned char utcr1;
104         unsigned char utcr2;
105         unsigned char utcr3;
106         unsigned char utcr4;
107         unsigned char utdr;
108         unsigned char utsr0;
109         unsigned char utsr1;
110 } sr;
111
112 static int irq = IRQ_Ser2ICP;
113
114 #define LIRC_ON_SA1100_TRANSMITTER_LATENCY 0
115
116 /* pulse/space ratio of 50/50 */
117 static unsigned long pulse_width = (13-LIRC_ON_SA1100_TRANSMITTER_LATENCY);
118 /* 1000000/freq-pulse_width */
119 static unsigned long space_width = (13-LIRC_ON_SA1100_TRANSMITTER_LATENCY);
120 static unsigned int freq = 38000;      /* modulation frequency */
121 static unsigned int duty_cycle = 50;   /* duty cycle of 50% */
122
123 #endif
124
125 #define RBUF_LEN 1024
126 #define WBUF_LEN 1024
127
128 #define LIRC_DRIVER_NAME "lirc_sir"
129
130 #define PULSE '['
131
132 #ifndef LIRC_SIR_TEKRAM
133 /* 9bit * 1s/115200bit in milli seconds = 78.125ms*/
134 #define TIME_CONST (9000000ul/115200ul)
135 #endif
136
137
138 /* timeout for sequences in jiffies (=5/100s), must be longer than TIME_CONST */
139 #define SIR_TIMEOUT     (HZ*5/100)
140
141 #ifndef LIRC_ON_SA1100
142 #ifndef LIRC_IRQ
143 #define LIRC_IRQ 4
144 #endif
145 #ifndef LIRC_PORT
146 /* for external dongles, default to com1 */
147 #if defined(LIRC_SIR_ACTISYS_ACT200L)         || \
148             defined(LIRC_SIR_ACTISYS_ACT220L) || \
149             defined(LIRC_SIR_TEKRAM)
150 #define LIRC_PORT 0x3f8
151 #else
152 /* onboard sir ports are typically com3 */
153 #define LIRC_PORT 0x3e8
154 #endif
155 #endif
156
157 static int io = LIRC_PORT;
158 static int irq = LIRC_IRQ;
159 static int threshold = 3;
160 #endif
161
162 static DEFINE_SPINLOCK(timer_lock);
163 static struct timer_list timerlist;
164 /* time of last signal change detected */
165 static struct timeval last_tv = {0, 0};
166 /* time of last UART data ready interrupt */
167 static struct timeval last_intr_tv = {0, 0};
168 static int last_value;
169
170 static DECLARE_WAIT_QUEUE_HEAD(lirc_read_queue);
171
172 static DEFINE_SPINLOCK(hardware_lock);
173
174 static int rx_buf[RBUF_LEN];
175 static unsigned int rx_tail, rx_head;
176
177 static int debug;
178 #define dprintk(fmt, args...)                                           \
179         do {                                                            \
180                 if (debug)                                              \
181                         printk(KERN_DEBUG LIRC_DRIVER_NAME ": "         \
182                                 fmt, ## args);                          \
183         } while (0)
184
185 /* SECTION: Prototypes */
186
187 /* Communication with user-space */
188 static unsigned int lirc_poll(struct file *file, poll_table *wait);
189 static ssize_t lirc_read(struct file *file, char *buf, size_t count,
190                 loff_t *ppos);
191 static ssize_t lirc_write(struct file *file, const char *buf, size_t n,
192                 loff_t *pos);
193 static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
194 static void add_read_queue(int flag, unsigned long val);
195 static int init_chrdev(void);
196 static void drop_chrdev(void);
197 /* Hardware */
198 static irqreturn_t sir_interrupt(int irq, void *dev_id);
199 static void send_space(unsigned long len);
200 static void send_pulse(unsigned long len);
201 static int init_hardware(void);
202 static void drop_hardware(void);
203 /* Initialisation */
204 static int init_port(void);
205 static void drop_port(void);
206
207 #ifdef LIRC_ON_SA1100
208 static void on(void)
209 {
210         PPSR |= PPC_TXD2;
211 }
212
213 static void off(void)
214 {
215         PPSR &= ~PPC_TXD2;
216 }
217 #else
218 static inline unsigned int sinp(int offset)
219 {
220         return inb(io + offset);
221 }
222
223 static inline void soutp(int offset, int value)
224 {
225         outb(value, io + offset);
226 }
227 #endif
228
229 #ifndef MAX_UDELAY_MS
230 #define MAX_UDELAY_US 5000
231 #else
232 #define MAX_UDELAY_US (MAX_UDELAY_MS*1000)
233 #endif
234
235 static void safe_udelay(unsigned long usecs)
236 {
237         while (usecs > MAX_UDELAY_US) {
238                 udelay(MAX_UDELAY_US);
239                 usecs -= MAX_UDELAY_US;
240         }
241         udelay(usecs);
242 }
243
244 /* SECTION: Communication with user-space */
245
246 static unsigned int lirc_poll(struct file *file, poll_table *wait)
247 {
248         poll_wait(file, &lirc_read_queue, wait);
249         if (rx_head != rx_tail)
250                 return POLLIN | POLLRDNORM;
251         return 0;
252 }
253
254 static ssize_t lirc_read(struct file *file, char *buf, size_t count,
255                 loff_t *ppos)
256 {
257         int n = 0;
258         int retval = 0;
259         DECLARE_WAITQUEUE(wait, current);
260
261         if (count % sizeof(int))
262                 return -EINVAL;
263
264         add_wait_queue(&lirc_read_queue, &wait);
265         set_current_state(TASK_INTERRUPTIBLE);
266         while (n < count) {
267                 if (rx_head != rx_tail) {
268                         if (copy_to_user((void *) buf + n,
269                                         (void *) (rx_buf + rx_head),
270                                         sizeof(int))) {
271                                 retval = -EFAULT;
272                                 break;
273                         }
274                         rx_head = (rx_head + 1) & (RBUF_LEN - 1);
275                         n += sizeof(int);
276                 } else {
277                         if (file->f_flags & O_NONBLOCK) {
278                                 retval = -EAGAIN;
279                                 break;
280                         }
281                         if (signal_pending(current)) {
282                                 retval = -ERESTARTSYS;
283                                 break;
284                         }
285                         schedule();
286                         set_current_state(TASK_INTERRUPTIBLE);
287                 }
288         }
289         remove_wait_queue(&lirc_read_queue, &wait);
290         set_current_state(TASK_RUNNING);
291         return n ? n : retval;
292 }
293 static ssize_t lirc_write(struct file *file, const char *buf, size_t n,
294                                 loff_t *pos)
295 {
296         unsigned long flags;
297         int i, count;
298         int *tx_buf;
299
300         count = n / sizeof(int);
301         if (n % sizeof(int) || count % 2 == 0)
302                 return -EINVAL;
303         tx_buf = memdup_user(buf, n);
304         if (IS_ERR(tx_buf))
305                 return PTR_ERR(tx_buf);
306         i = 0;
307 #ifdef LIRC_ON_SA1100
308         /* disable receiver */
309         Ser2UTCR3 = 0;
310 #endif
311         local_irq_save(flags);
312         while (1) {
313                 if (i >= count)
314                         break;
315                 if (tx_buf[i])
316                         send_pulse(tx_buf[i]);
317                 i++;
318                 if (i >= count)
319                         break;
320                 if (tx_buf[i])
321                         send_space(tx_buf[i]);
322                 i++;
323         }
324         local_irq_restore(flags);
325 #ifdef LIRC_ON_SA1100
326         off();
327         udelay(1000); /* wait 1ms for IR diode to recover */
328         Ser2UTCR3 = 0;
329         /* clear status register to prevent unwanted interrupts */
330         Ser2UTSR0 &= (UTSR0_RID | UTSR0_RBB | UTSR0_REB);
331         /* enable receiver */
332         Ser2UTCR3 = UTCR3_RXE|UTCR3_RIE;
333 #endif
334         kfree(tx_buf);
335         return count;
336 }
337
338 static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
339 {
340         int retval = 0;
341         __u32 value = 0;
342 #ifdef LIRC_ON_SA1100
343
344         if (cmd == LIRC_GET_FEATURES)
345                 value = LIRC_CAN_SEND_PULSE |
346                         LIRC_CAN_SET_SEND_DUTY_CYCLE |
347                         LIRC_CAN_SET_SEND_CARRIER |
348                         LIRC_CAN_REC_MODE2;
349         else if (cmd == LIRC_GET_SEND_MODE)
350                 value = LIRC_MODE_PULSE;
351         else if (cmd == LIRC_GET_REC_MODE)
352                 value = LIRC_MODE_MODE2;
353 #else
354         if (cmd == LIRC_GET_FEATURES)
355                 value = LIRC_CAN_SEND_PULSE | LIRC_CAN_REC_MODE2;
356         else if (cmd == LIRC_GET_SEND_MODE)
357                 value = LIRC_MODE_PULSE;
358         else if (cmd == LIRC_GET_REC_MODE)
359                 value = LIRC_MODE_MODE2;
360 #endif
361
362         switch (cmd) {
363         case LIRC_GET_FEATURES:
364         case LIRC_GET_SEND_MODE:
365         case LIRC_GET_REC_MODE:
366                 retval = put_user(value, (__u32 *) arg);
367                 break;
368
369         case LIRC_SET_SEND_MODE:
370         case LIRC_SET_REC_MODE:
371                 retval = get_user(value, (__u32 *) arg);
372                 break;
373 #ifdef LIRC_ON_SA1100
374         case LIRC_SET_SEND_DUTY_CYCLE:
375                 retval = get_user(value, (__u32 *) arg);
376                 if (retval)
377                         return retval;
378                 if (value <= 0 || value > 100)
379                         return -EINVAL;
380                 /* (value/100)*(1000000/freq) */
381                 duty_cycle = value;
382                 pulse_width = (unsigned long) duty_cycle*10000/freq;
383                 space_width = (unsigned long) 1000000L/freq-pulse_width;
384                 if (pulse_width >= LIRC_ON_SA1100_TRANSMITTER_LATENCY)
385                         pulse_width -= LIRC_ON_SA1100_TRANSMITTER_LATENCY;
386                 if (space_width >= LIRC_ON_SA1100_TRANSMITTER_LATENCY)
387                         space_width -= LIRC_ON_SA1100_TRANSMITTER_LATENCY;
388                 break;
389         case LIRC_SET_SEND_CARRIER:
390                 retval = get_user(value, (__u32 *) arg);
391                 if (retval)
392                         return retval;
393                 if (value > 500000 || value < 20000)
394                         return -EINVAL;
395                 freq = value;
396                 pulse_width = (unsigned long) duty_cycle*10000/freq;
397                 space_width = (unsigned long) 1000000L/freq-pulse_width;
398                 if (pulse_width >= LIRC_ON_SA1100_TRANSMITTER_LATENCY)
399                         pulse_width -= LIRC_ON_SA1100_TRANSMITTER_LATENCY;
400                 if (space_width >= LIRC_ON_SA1100_TRANSMITTER_LATENCY)
401                         space_width -= LIRC_ON_SA1100_TRANSMITTER_LATENCY;
402                 break;
403 #endif
404         default:
405                 retval = -ENOIOCTLCMD;
406
407         }
408
409         if (retval)
410                 return retval;
411         if (cmd == LIRC_SET_REC_MODE) {
412                 if (value != LIRC_MODE_MODE2)
413                         retval = -ENOSYS;
414         } else if (cmd == LIRC_SET_SEND_MODE) {
415                 if (value != LIRC_MODE_PULSE)
416                         retval = -ENOSYS;
417         }
418
419         return retval;
420 }
421
422 static void add_read_queue(int flag, unsigned long val)
423 {
424         unsigned int new_rx_tail;
425         int newval;
426
427         dprintk("add flag %d with val %lu\n", flag, val);
428
429         newval = val & PULSE_MASK;
430
431         /*
432          * statistically, pulses are ~TIME_CONST/2 too long. we could
433          * maybe make this more exact, but this is good enough
434          */
435         if (flag) {
436                 /* pulse */
437                 if (newval > TIME_CONST/2)
438                         newval -= TIME_CONST/2;
439                 else /* should not ever happen */
440                         newval = 1;
441                 newval |= PULSE_BIT;
442         } else {
443                 newval += TIME_CONST/2;
444         }
445         new_rx_tail = (rx_tail + 1) & (RBUF_LEN - 1);
446         if (new_rx_tail == rx_head) {
447                 dprintk("Buffer overrun.\n");
448                 return;
449         }
450         rx_buf[rx_tail] = newval;
451         rx_tail = new_rx_tail;
452         wake_up_interruptible(&lirc_read_queue);
453 }
454
455 static const struct file_operations lirc_fops = {
456         .owner          = THIS_MODULE,
457         .read           = lirc_read,
458         .write          = lirc_write,
459         .poll           = lirc_poll,
460         .unlocked_ioctl = lirc_ioctl,
461 #ifdef CONFIG_COMPAT
462         .compat_ioctl   = lirc_ioctl,
463 #endif
464         .open           = lirc_dev_fop_open,
465         .release        = lirc_dev_fop_close,
466         .llseek         = no_llseek,
467 };
468
469 static int set_use_inc(void *data)
470 {
471         return 0;
472 }
473
474 static void set_use_dec(void *data)
475 {
476 }
477
478 static struct lirc_driver driver = {
479         .name           = LIRC_DRIVER_NAME,
480         .minor          = -1,
481         .code_length    = 1,
482         .sample_rate    = 0,
483         .data           = NULL,
484         .add_to_buf     = NULL,
485         .set_use_inc    = set_use_inc,
486         .set_use_dec    = set_use_dec,
487         .fops           = &lirc_fops,
488         .dev            = NULL,
489         .owner          = THIS_MODULE,
490 };
491
492 static struct platform_device *lirc_sir_dev;
493
494 static int init_chrdev(void)
495 {
496         driver.dev = &lirc_sir_dev->dev;
497         driver.minor = lirc_register_driver(&driver);
498         if (driver.minor < 0) {
499                 printk(KERN_ERR LIRC_DRIVER_NAME ": init_chrdev() failed.\n");
500                 return -EIO;
501         }
502         return 0;
503 }
504
505 static void drop_chrdev(void)
506 {
507         lirc_unregister_driver(driver.minor);
508 }
509
510 /* SECTION: Hardware */
511 static long delta(struct timeval *tv1, struct timeval *tv2)
512 {
513         unsigned long deltv;
514
515         deltv = tv2->tv_sec - tv1->tv_sec;
516         if (deltv > 15)
517                 deltv = 0xFFFFFF;
518         else
519                 deltv = deltv*1000000 +
520                         tv2->tv_usec -
521                         tv1->tv_usec;
522         return deltv;
523 }
524
525 static void sir_timeout(unsigned long data)
526 {
527         /*
528          * if last received signal was a pulse, but receiving stopped
529          * within the 9 bit frame, we need to finish this pulse and
530          * simulate a signal change to from pulse to space. Otherwise
531          * upper layers will receive two sequences next time.
532          */
533
534         unsigned long flags;
535         unsigned long pulse_end;
536
537         /* avoid interference with interrupt */
538         spin_lock_irqsave(&timer_lock, flags);
539         if (last_value) {
540 #ifndef LIRC_ON_SA1100
541                 /* clear unread bits in UART and restart */
542                 outb(UART_FCR_CLEAR_RCVR, io + UART_FCR);
543 #endif
544                 /* determine 'virtual' pulse end: */
545                 pulse_end = delta(&last_tv, &last_intr_tv);
546                 dprintk("timeout add %d for %lu usec\n", last_value, pulse_end);
547                 add_read_queue(last_value, pulse_end);
548                 last_value = 0;
549                 last_tv = last_intr_tv;
550         }
551         spin_unlock_irqrestore(&timer_lock, flags);
552 }
553
554 static irqreturn_t sir_interrupt(int irq, void *dev_id)
555 {
556         unsigned char data;
557         struct timeval curr_tv;
558         static unsigned long deltv;
559 #ifdef LIRC_ON_SA1100
560         int status;
561         static int n;
562
563         status = Ser2UTSR0;
564         /*
565          * Deal with any receive errors first.  The bytes in error may be
566          * the only bytes in the receive FIFO, so we do this first.
567          */
568         while (status & UTSR0_EIF) {
569                 int bstat;
570
571                 if (debug) {
572                         dprintk("EIF\n");
573                         bstat = Ser2UTSR1;
574
575                         if (bstat & UTSR1_FRE)
576                                 dprintk("frame error\n");
577                         if (bstat & UTSR1_ROR)
578                                 dprintk("receive fifo overrun\n");
579                         if (bstat & UTSR1_PRE)
580                                 dprintk("parity error\n");
581                 }
582
583                 bstat = Ser2UTDR;
584                 n++;
585                 status = Ser2UTSR0;
586         }
587
588         if (status & (UTSR0_RFS | UTSR0_RID)) {
589                 do_gettimeofday(&curr_tv);
590                 deltv = delta(&last_tv, &curr_tv);
591                 do {
592                         data = Ser2UTDR;
593                         dprintk("%d data: %u\n", n, (unsigned int) data);
594                         n++;
595                 } while (status & UTSR0_RID && /* do not empty fifo in order to
596                                                 * get UTSR0_RID in any case */
597                       Ser2UTSR1 & UTSR1_RNE); /* data ready */
598
599                 if (status&UTSR0_RID) {
600                         add_read_queue(0 , deltv - n * TIME_CONST); /*space*/
601                         add_read_queue(1, n * TIME_CONST); /*pulse*/
602                         n = 0;
603                         last_tv = curr_tv;
604                 }
605         }
606
607         if (status & UTSR0_TFS)
608                 printk(KERN_ERR "transmit fifo not full, shouldn't happen\n");
609
610         /* We must clear certain bits. */
611         status &= (UTSR0_RID | UTSR0_RBB | UTSR0_REB);
612         if (status)
613                 Ser2UTSR0 = status;
614 #else
615         unsigned long deltintrtv;
616         unsigned long flags;
617         int iir, lsr;
618
619         while ((iir = inb(io + UART_IIR) & UART_IIR_ID)) {
620                 switch (iir&UART_IIR_ID) { /* FIXME toto treba preriedit */
621                 case UART_IIR_MSI:
622                         (void) inb(io + UART_MSR);
623                         break;
624                 case UART_IIR_RLSI:
625                         (void) inb(io + UART_LSR);
626                         break;
627                 case UART_IIR_THRI:
628 #if 0
629                         if (lsr & UART_LSR_THRE) /* FIFO is empty */
630                                 outb(data, io + UART_TX)
631 #endif
632                         break;
633                 case UART_IIR_RDI:
634                         /* avoid interference with timer */
635                         spin_lock_irqsave(&timer_lock, flags);
636                         do {
637                                 del_timer(&timerlist);
638                                 data = inb(io + UART_RX);
639                                 do_gettimeofday(&curr_tv);
640                                 deltv = delta(&last_tv, &curr_tv);
641                                 deltintrtv = delta(&last_intr_tv, &curr_tv);
642                                 dprintk("t %lu, d %d\n", deltintrtv, (int)data);
643                                 /*
644                                  * if nothing came in last X cycles,
645                                  * it was gap
646                                  */
647                                 if (deltintrtv > TIME_CONST * threshold) {
648                                         if (last_value) {
649                                                 dprintk("GAP\n");
650                                                 /* simulate signal change */
651                                                 add_read_queue(last_value,
652                                                                deltv -
653                                                                deltintrtv);
654                                                 last_value = 0;
655                                                 last_tv.tv_sec =
656                                                         last_intr_tv.tv_sec;
657                                                 last_tv.tv_usec =
658                                                         last_intr_tv.tv_usec;
659                                                 deltv = deltintrtv;
660                                         }
661                                 }
662                                 data = 1;
663                                 if (data ^ last_value) {
664                                         /*
665                                          * deltintrtv > 2*TIME_CONST, remember?
666                                          * the other case is timeout
667                                          */
668                                         add_read_queue(last_value,
669                                                        deltv-TIME_CONST);
670                                         last_value = data;
671                                         last_tv = curr_tv;
672                                         if (last_tv.tv_usec >= TIME_CONST) {
673                                                 last_tv.tv_usec -= TIME_CONST;
674                                         } else {
675                                                 last_tv.tv_sec--;
676                                                 last_tv.tv_usec += 1000000 -
677                                                         TIME_CONST;
678                                         }
679                                 }
680                                 last_intr_tv = curr_tv;
681                                 if (data) {
682                                         /*
683                                          * start timer for end of
684                                          * sequence detection
685                                          */
686                                         timerlist.expires = jiffies +
687                                                                 SIR_TIMEOUT;
688                                         add_timer(&timerlist);
689                                 }
690
691                                 lsr = inb(io + UART_LSR);
692                         } while (lsr & UART_LSR_DR); /* data ready */
693                         spin_unlock_irqrestore(&timer_lock, flags);
694                         break;
695                 default:
696                         break;
697                 }
698         }
699 #endif
700         return IRQ_RETVAL(IRQ_HANDLED);
701 }
702
703 #ifdef LIRC_ON_SA1100
704 static void send_pulse(unsigned long length)
705 {
706         unsigned long k, delay;
707         int flag;
708
709         if (length == 0)
710                 return;
711         /*
712          * this won't give us the carrier frequency we really want
713          * due to integer arithmetic, but we can accept this inaccuracy
714          */
715
716         for (k = flag = 0; k < length; k += delay, flag = !flag) {
717                 if (flag) {
718                         off();
719                         delay = space_width;
720                 } else {
721                         on();
722                         delay = pulse_width;
723                 }
724                 safe_udelay(delay);
725         }
726         off();
727 }
728
729 static void send_space(unsigned long length)
730 {
731         if (length == 0)
732                 return;
733         off();
734         safe_udelay(length);
735 }
736 #else
737 static void send_space(unsigned long len)
738 {
739         safe_udelay(len);
740 }
741
742 static void send_pulse(unsigned long len)
743 {
744         long bytes_out = len / TIME_CONST;
745
746         if (bytes_out == 0)
747                 bytes_out++;
748
749         while (bytes_out--) {
750                 outb(PULSE, io + UART_TX);
751                 /* FIXME treba seriozne cakanie z char/serial.c */
752                 while (!(inb(io + UART_LSR) & UART_LSR_THRE))
753                         ;
754         }
755 }
756 #endif
757
758 #ifdef CONFIG_SA1100_COLLIE
759 static int sa1100_irda_set_power_collie(int state)
760 {
761         if (state) {
762                 /*
763                  *  0 - off
764                  *  1 - short range, lowest power
765                  *  2 - medium range, medium power
766                  *  3 - maximum range, high power
767                  */
768                 ucb1200_set_io_direction(TC35143_GPIO_IR_ON,
769                                          TC35143_IODIR_OUTPUT);
770                 ucb1200_set_io(TC35143_GPIO_IR_ON, TC35143_IODAT_LOW);
771                 udelay(100);
772         } else {
773                 /* OFF */
774                 ucb1200_set_io_direction(TC35143_GPIO_IR_ON,
775                                          TC35143_IODIR_OUTPUT);
776                 ucb1200_set_io(TC35143_GPIO_IR_ON, TC35143_IODAT_HIGH);
777         }
778         return 0;
779 }
780 #endif
781
782 static int init_hardware(void)
783 {
784         unsigned long flags;
785
786         spin_lock_irqsave(&hardware_lock, flags);
787         /* reset UART */
788 #ifdef LIRC_ON_SA1100
789 #ifdef CONFIG_SA1100_BITSY
790         if (machine_is_bitsy()) {
791                 printk(KERN_INFO "Power on IR module\n");
792                 set_bitsy_egpio(EGPIO_BITSY_IR_ON);
793         }
794 #endif
795 #ifdef CONFIG_SA1100_COLLIE
796         sa1100_irda_set_power_collie(3);        /* power on */
797 #endif
798         sr.hscr0 = Ser2HSCR0;
799
800         sr.utcr0 = Ser2UTCR0;
801         sr.utcr1 = Ser2UTCR1;
802         sr.utcr2 = Ser2UTCR2;
803         sr.utcr3 = Ser2UTCR3;
804         sr.utcr4 = Ser2UTCR4;
805
806         sr.utdr = Ser2UTDR;
807         sr.utsr0 = Ser2UTSR0;
808         sr.utsr1 = Ser2UTSR1;
809
810         /* configure GPIO */
811         /* output */
812         PPDR |= PPC_TXD2;
813         PSDR |= PPC_TXD2;
814         /* set output to 0 */
815         off();
816
817         /* Enable HP-SIR modulation, and ensure that the port is disabled. */
818         Ser2UTCR3 = 0;
819         Ser2HSCR0 = sr.hscr0 & (~HSCR0_HSSP);
820
821         /* clear status register to prevent unwanted interrupts */
822         Ser2UTSR0 &= (UTSR0_RID | UTSR0_RBB | UTSR0_REB);
823
824         /* 7N1 */
825         Ser2UTCR0 = UTCR0_1StpBit|UTCR0_7BitData;
826         /* 115200 */
827         Ser2UTCR1 = 0;
828         Ser2UTCR2 = 1;
829         /* use HPSIR, 1.6 usec pulses */
830         Ser2UTCR4 = UTCR4_HPSIR|UTCR4_Z1_6us;
831
832         /* enable receiver, receive fifo interrupt */
833         Ser2UTCR3 = UTCR3_RXE|UTCR3_RIE;
834
835         /* clear status register to prevent unwanted interrupts */
836         Ser2UTSR0 &= (UTSR0_RID | UTSR0_RBB | UTSR0_REB);
837
838 #elif defined(LIRC_SIR_TEKRAM)
839         /* disable FIFO */
840         soutp(UART_FCR,
841               UART_FCR_CLEAR_RCVR|
842               UART_FCR_CLEAR_XMIT|
843               UART_FCR_TRIGGER_1);
844
845         /* Set DLAB 0. */
846         soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
847
848         /* First of all, disable all interrupts */
849         soutp(UART_IER, sinp(UART_IER) &
850               (~(UART_IER_MSI|UART_IER_RLSI|UART_IER_THRI|UART_IER_RDI)));
851
852         /* Set DLAB 1. */
853         soutp(UART_LCR, sinp(UART_LCR) | UART_LCR_DLAB);
854
855         /* Set divisor to 12 => 9600 Baud */
856         soutp(UART_DLM, 0);
857         soutp(UART_DLL, 12);
858
859         /* Set DLAB 0. */
860         soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
861
862         /* power supply */
863         soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2);
864         safe_udelay(50*1000);
865
866         /* -DTR low -> reset PIC */
867         soutp(UART_MCR, UART_MCR_RTS|UART_MCR_OUT2);
868         udelay(1*1000);
869
870         soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2);
871         udelay(100);
872
873
874         /* -RTS low -> send control byte */
875         soutp(UART_MCR, UART_MCR_DTR|UART_MCR_OUT2);
876         udelay(7);
877         soutp(UART_TX, TEKRAM_115200|TEKRAM_PW);
878
879         /* one byte takes ~1042 usec to transmit at 9600,8N1 */
880         udelay(1500);
881
882         /* back to normal operation */
883         soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2);
884         udelay(50);
885
886         udelay(1500);
887
888         /* read previous control byte */
889         printk(KERN_INFO LIRC_DRIVER_NAME
890                ": 0x%02x\n", sinp(UART_RX));
891
892         /* Set DLAB 1. */
893         soutp(UART_LCR, sinp(UART_LCR) | UART_LCR_DLAB);
894
895         /* Set divisor to 1 => 115200 Baud */
896         soutp(UART_DLM, 0);
897         soutp(UART_DLL, 1);
898
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);
903 #else
904         outb(0, io + UART_MCR);
905         outb(0, io + UART_IER);
906         /* init UART */
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);
912         /* FIFO operation */
913         outb(UART_FCR_ENABLE_FIFO, io + UART_FCR);
914         /* interrupts */
915         /* outb(UART_IER_RLSI|UART_IER_RDI|UART_IER_THRI, io + UART_IER); */
916         outb(UART_IER_RDI, io + UART_IER);
917         /* turn on UART */
918         outb(UART_MCR_DTR|UART_MCR_RTS|UART_MCR_OUT2, io + UART_MCR);
919 #ifdef LIRC_SIR_ACTISYS_ACT200L
920         init_act200();
921 #elif defined(LIRC_SIR_ACTISYS_ACT220L)
922         init_act220();
923 #endif
924 #endif
925         spin_unlock_irqrestore(&hardware_lock, flags);
926         return 0;
927 }
928
929 static void drop_hardware(void)
930 {
931         unsigned long flags;
932
933         spin_lock_irqsave(&hardware_lock, flags);
934
935 #ifdef LIRC_ON_SA1100
936         Ser2UTCR3 = 0;
937
938         Ser2UTCR0 = sr.utcr0;
939         Ser2UTCR1 = sr.utcr1;
940         Ser2UTCR2 = sr.utcr2;
941         Ser2UTCR4 = sr.utcr4;
942         Ser2UTCR3 = sr.utcr3;
943
944         Ser2HSCR0 = sr.hscr0;
945 #ifdef CONFIG_SA1100_BITSY
946         if (machine_is_bitsy())
947                 clr_bitsy_egpio(EGPIO_BITSY_IR_ON);
948 #endif
949 #ifdef CONFIG_SA1100_COLLIE
950         sa1100_irda_set_power_collie(0);        /* power off */
951 #endif
952 #else
953         /* turn off interrupts */
954         outb(0, io + UART_IER);
955 #endif
956         spin_unlock_irqrestore(&hardware_lock, flags);
957 }
958
959 /* SECTION: Initialisation */
960
961 static int init_port(void)
962 {
963         int retval;
964
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                 printk(KERN_ERR LIRC_DRIVER_NAME
969                        ": i/o port 0x%.4x already in use.\n", io);
970                 return -EBUSY;
971         }
972 #endif
973         retval = request_irq(irq, sir_interrupt, 0,
974                              LIRC_DRIVER_NAME, NULL);
975         if (retval < 0) {
976 #               ifndef LIRC_ON_SA1100
977                 release_region(io, 8);
978 #               endif
979                 printk(KERN_ERR LIRC_DRIVER_NAME
980                         ": IRQ %d already in use.\n",
981                         irq);
982                 return retval;
983         }
984 #ifndef LIRC_ON_SA1100
985         printk(KERN_INFO LIRC_DRIVER_NAME
986                 ": I/O port 0x%.4x, IRQ %d.\n",
987                 io, irq);
988 #endif
989
990         init_timer(&timerlist);
991         timerlist.function = sir_timeout;
992         timerlist.data = 0xabadcafe;
993
994         return 0;
995 }
996
997 static void drop_port(void)
998 {
999         free_irq(irq, NULL);
1000         del_timer_sync(&timerlist);
1001 #ifndef LIRC_ON_SA1100
1002         release_region(io, 8);
1003 #endif
1004 }
1005
1006 #ifdef LIRC_SIR_ACTISYS_ACT200L
1007 /* Crystal/Cirrus CS8130 IR transceiver, used in Actisys Act200L dongle */
1008 /* some code borrowed from Linux IRDA driver */
1009
1010 /* Register 0: Control register #1 */
1011 #define ACT200L_REG0    0x00
1012 #define ACT200L_TXEN    0x01 /* Enable transmitter */
1013 #define ACT200L_RXEN    0x02 /* Enable receiver */
1014 #define ACT200L_ECHO    0x08 /* Echo control chars */
1015
1016 /* Register 1: Control register #2 */
1017 #define ACT200L_REG1    0x10
1018 #define ACT200L_LODB    0x01 /* Load new baud rate count value */
1019 #define ACT200L_WIDE    0x04 /* Expand the maximum allowable pulse */
1020
1021 /* Register 3: Transmit mode register #2 */
1022 #define ACT200L_REG3    0x30
1023 #define ACT200L_B0      0x01 /* DataBits, 0=6, 1=7, 2=8, 3=9(8P)  */
1024 #define ACT200L_B1      0x02 /* DataBits, 0=6, 1=7, 2=8, 3=9(8P)  */
1025 #define ACT200L_CHSY    0x04 /* StartBit Synced 0=bittime, 1=startbit */
1026
1027 /* Register 4: Output Power register */
1028 #define ACT200L_REG4    0x40
1029 #define ACT200L_OP0     0x01 /* Enable LED1C output */
1030 #define ACT200L_OP1     0x02 /* Enable LED2C output */
1031 #define ACT200L_BLKR    0x04
1032
1033 /* Register 5: Receive Mode register */
1034 #define ACT200L_REG5    0x50
1035 #define ACT200L_RWIDL   0x01 /* fixed 1.6us pulse mode */
1036     /*.. other various IRDA bit modes, and TV remote modes..*/
1037
1038 /* Register 6: Receive Sensitivity register #1 */
1039 #define ACT200L_REG6    0x60
1040 #define ACT200L_RS0     0x01 /* receive threshold bit 0 */
1041 #define ACT200L_RS1     0x02 /* receive threshold bit 1 */
1042
1043 /* Register 7: Receive Sensitivity register #2 */
1044 #define ACT200L_REG7    0x70
1045 #define ACT200L_ENPOS   0x04 /* Ignore the falling edge */
1046
1047 /* Register 8,9: Baud Rate Divider register #1,#2 */
1048 #define ACT200L_REG8    0x80
1049 #define ACT200L_REG9    0x90
1050
1051 #define ACT200L_2400    0x5f
1052 #define ACT200L_9600    0x17
1053 #define ACT200L_19200   0x0b
1054 #define ACT200L_38400   0x05
1055 #define ACT200L_57600   0x03
1056 #define ACT200L_115200  0x01
1057
1058 /* Register 13: Control register #3 */
1059 #define ACT200L_REG13   0xd0
1060 #define ACT200L_SHDW    0x01 /* Enable access to shadow registers */
1061
1062 /* Register 15: Status register */
1063 #define ACT200L_REG15   0xf0
1064
1065 /* Register 21: Control register #4 */
1066 #define ACT200L_REG21   0x50
1067 #define ACT200L_EXCK    0x02 /* Disable clock output driver */
1068 #define ACT200L_OSCL    0x04 /* oscillator in low power, medium accuracy mode */
1069
1070 static void init_act200(void)
1071 {
1072         int i;
1073         __u8 control[] = {
1074                 ACT200L_REG15,
1075                 ACT200L_REG13 | ACT200L_SHDW,
1076                 ACT200L_REG21 | ACT200L_EXCK | ACT200L_OSCL,
1077                 ACT200L_REG13,
1078                 ACT200L_REG7  | ACT200L_ENPOS,
1079                 ACT200L_REG6  | ACT200L_RS0  | ACT200L_RS1,
1080                 ACT200L_REG5  | ACT200L_RWIDL,
1081                 ACT200L_REG4  | ACT200L_OP0  | ACT200L_OP1 | ACT200L_BLKR,
1082                 ACT200L_REG3  | ACT200L_B0,
1083                 ACT200L_REG0  | ACT200L_TXEN | ACT200L_RXEN,
1084                 ACT200L_REG8 |  (ACT200L_115200       & 0x0f),
1085                 ACT200L_REG9 | ((ACT200L_115200 >> 4) & 0x0f),
1086                 ACT200L_REG1 | ACT200L_LODB | ACT200L_WIDE
1087         };
1088
1089         /* Set DLAB 1. */
1090         soutp(UART_LCR, UART_LCR_DLAB | UART_LCR_WLEN8);
1091
1092         /* Set divisor to 12 => 9600 Baud */
1093         soutp(UART_DLM, 0);
1094         soutp(UART_DLL, 12);
1095
1096         /* Set DLAB 0. */
1097         soutp(UART_LCR, UART_LCR_WLEN8);
1098         /* Set divisor to 12 => 9600 Baud */
1099
1100         /* power supply */
1101         soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2);
1102         for (i = 0; i < 50; i++)
1103                 safe_udelay(1000);
1104
1105                 /* Reset the dongle : set RTS low for 25 ms */
1106         soutp(UART_MCR, UART_MCR_DTR|UART_MCR_OUT2);
1107         for (i = 0; i < 25; i++)
1108                 udelay(1000);
1109
1110         soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2);
1111         udelay(100);
1112
1113         /* Clear DTR and set RTS to enter command mode */
1114         soutp(UART_MCR, UART_MCR_RTS|UART_MCR_OUT2);
1115         udelay(7);
1116
1117         /* send out the control register settings for 115K 7N1 SIR operation */
1118         for (i = 0; i < sizeof(control); i++) {
1119                 soutp(UART_TX, control[i]);
1120                 /* one byte takes ~1042 usec to transmit at 9600,8N1 */
1121                 udelay(1500);
1122         }
1123
1124         /* back to normal operation */
1125         soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2);
1126         udelay(50);
1127
1128         udelay(1500);
1129         soutp(UART_LCR, sinp(UART_LCR) | UART_LCR_DLAB);
1130
1131         /* Set DLAB 1. */
1132         soutp(UART_LCR, UART_LCR_DLAB | UART_LCR_WLEN7);
1133
1134         /* Set divisor to 1 => 115200 Baud */
1135         soutp(UART_DLM, 0);
1136         soutp(UART_DLL, 1);
1137
1138         /* Set DLAB 0. */
1139         soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
1140
1141         /* Set DLAB 0, 7 Bit */
1142         soutp(UART_LCR, UART_LCR_WLEN7);
1143
1144         /* enable interrupts */
1145         soutp(UART_IER, sinp(UART_IER)|UART_IER_RDI);
1146 }
1147 #endif
1148
1149 #ifdef LIRC_SIR_ACTISYS_ACT220L
1150 /*
1151  * Derived from linux IrDA driver (net/irda/actisys.c)
1152  * Drop me a mail for any kind of comment: maxx@spaceboyz.net
1153  */
1154
1155 void init_act220(void)
1156 {
1157         int i;
1158
1159         /* DLAB 1 */
1160         soutp(UART_LCR, UART_LCR_DLAB|UART_LCR_WLEN7);
1161
1162         /* 9600 baud */
1163         soutp(UART_DLM, 0);
1164         soutp(UART_DLL, 12);
1165
1166         /* DLAB 0 */
1167         soutp(UART_LCR, UART_LCR_WLEN7);
1168
1169         /* reset the dongle, set DTR low for 10us */
1170         soutp(UART_MCR, UART_MCR_RTS|UART_MCR_OUT2);
1171         udelay(10);
1172
1173         /* back to normal (still 9600) */
1174         soutp(UART_MCR, UART_MCR_DTR|UART_MCR_RTS|UART_MCR_OUT2);
1175
1176         /*
1177          * send RTS pulses until we reach 115200
1178          * i hope this is really the same for act220l/act220l+
1179          */
1180         for (i = 0; i < 3; i++) {
1181                 udelay(10);
1182                 /* set RTS low for 10 us */
1183                 soutp(UART_MCR, UART_MCR_DTR|UART_MCR_OUT2);
1184                 udelay(10);
1185                 /* set RTS high for 10 us */
1186                 soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2);
1187         }
1188
1189         /* back to normal operation */
1190         udelay(1500); /* better safe than sorry ;) */
1191
1192         /* Set DLAB 1. */
1193         soutp(UART_LCR, UART_LCR_DLAB | UART_LCR_WLEN7);
1194
1195         /* Set divisor to 1 => 115200 Baud */
1196         soutp(UART_DLM, 0);
1197         soutp(UART_DLL, 1);
1198
1199         /* Set DLAB 0, 7 Bit */
1200         /* The dongle doesn't seem to have any problems with operation at 7N1 */
1201         soutp(UART_LCR, UART_LCR_WLEN7);
1202
1203         /* enable interrupts */
1204         soutp(UART_IER, UART_IER_RDI);
1205 }
1206 #endif
1207
1208 static int init_lirc_sir(void)
1209 {
1210         int retval;
1211
1212         init_waitqueue_head(&lirc_read_queue);
1213         retval = init_port();
1214         if (retval < 0)
1215                 return retval;
1216         init_hardware();
1217         printk(KERN_INFO LIRC_DRIVER_NAME
1218                 ": Installed.\n");
1219         return 0;
1220 }
1221
1222 static int __devinit lirc_sir_probe(struct platform_device *dev)
1223 {
1224         return 0;
1225 }
1226
1227 static int __devexit lirc_sir_remove(struct platform_device *dev)
1228 {
1229         return 0;
1230 }
1231
1232 static struct platform_driver lirc_sir_driver = {
1233         .probe          = lirc_sir_probe,
1234         .remove         = __devexit_p(lirc_sir_remove),
1235         .driver         = {
1236                 .name   = "lirc_sir",
1237                 .owner  = THIS_MODULE,
1238         },
1239 };
1240
1241 static int __init lirc_sir_init(void)
1242 {
1243         int retval;
1244
1245         retval = platform_driver_register(&lirc_sir_driver);
1246         if (retval) {
1247                 printk(KERN_ERR LIRC_DRIVER_NAME ": Platform driver register "
1248                        "failed!\n");
1249                 return -ENODEV;
1250         }
1251
1252         lirc_sir_dev = platform_device_alloc("lirc_dev", 0);
1253         if (!lirc_sir_dev) {
1254                 printk(KERN_ERR LIRC_DRIVER_NAME ": Platform device alloc "
1255                        "failed!\n");
1256                 retval = -ENOMEM;
1257                 goto pdev_alloc_fail;
1258         }
1259
1260         retval = platform_device_add(lirc_sir_dev);
1261         if (retval) {
1262                 printk(KERN_ERR LIRC_DRIVER_NAME ": Platform device add "
1263                        "failed!\n");
1264                 retval = -ENODEV;
1265                 goto pdev_add_fail;
1266         }
1267
1268         retval = init_chrdev();
1269         if (retval < 0)
1270                 goto fail;
1271
1272         retval = init_lirc_sir();
1273         if (retval) {
1274                 drop_chrdev();
1275                 goto fail;
1276         }
1277
1278         return 0;
1279
1280 fail:
1281         platform_device_del(lirc_sir_dev);
1282 pdev_add_fail:
1283         platform_device_put(lirc_sir_dev);
1284 pdev_alloc_fail:
1285         platform_driver_unregister(&lirc_sir_driver);
1286         return retval;
1287 }
1288
1289 static void __exit lirc_sir_exit(void)
1290 {
1291         drop_hardware();
1292         drop_chrdev();
1293         drop_port();
1294         platform_device_unregister(lirc_sir_dev);
1295         platform_driver_unregister(&lirc_sir_driver);
1296         printk(KERN_INFO LIRC_DRIVER_NAME ": Uninstalled.\n");
1297 }
1298
1299 module_init(lirc_sir_init);
1300 module_exit(lirc_sir_exit);
1301
1302 #ifdef LIRC_SIR_TEKRAM
1303 MODULE_DESCRIPTION("Infrared receiver driver for Tekram Irmate 210");
1304 MODULE_AUTHOR("Christoph Bartelmus");
1305 #elif defined(LIRC_ON_SA1100)
1306 MODULE_DESCRIPTION("LIRC driver for StrongARM SA1100 embedded microprocessor");
1307 MODULE_AUTHOR("Christoph Bartelmus");
1308 #elif defined(LIRC_SIR_ACTISYS_ACT200L)
1309 MODULE_DESCRIPTION("LIRC driver for Actisys Act200L");
1310 MODULE_AUTHOR("Karl Bongers");
1311 #elif defined(LIRC_SIR_ACTISYS_ACT220L)
1312 MODULE_DESCRIPTION("LIRC driver for Actisys Act220L(+)");
1313 MODULE_AUTHOR("Jan Roemisch");
1314 #else
1315 MODULE_DESCRIPTION("Infrared receiver driver for SIR type serial ports");
1316 MODULE_AUTHOR("Milan Pikula");
1317 #endif
1318 MODULE_LICENSE("GPL");
1319
1320 #ifdef LIRC_ON_SA1100
1321 module_param(irq, int, S_IRUGO);
1322 MODULE_PARM_DESC(irq, "Interrupt (16)");
1323 #else
1324 module_param(io, int, S_IRUGO);
1325 MODULE_PARM_DESC(io, "I/O address base (0x3f8 or 0x2f8)");
1326
1327 module_param(irq, int, S_IRUGO);
1328 MODULE_PARM_DESC(irq, "Interrupt (4 or 3)");
1329
1330 module_param(threshold, int, S_IRUGO);
1331 MODULE_PARM_DESC(threshold, "space detection threshold (3)");
1332 #endif
1333
1334 module_param(debug, bool, S_IRUGO | S_IWUSR);
1335 MODULE_PARM_DESC(debug, "Enable debugging messages");