~ubuntu-branches/ubuntu/precise/lirc/precise

« back to all changes in this revision

Viewing changes to drivers/lirc_sir/lirc_sir.c

  • Committer: Bazaar Package Importer
  • Author(s): Mario Limonciello
  • Date: 2009-06-18 01:48:20 UTC
  • mfrom: (1.2.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090618014820-xd3wmu47cd23ejtc
Tags: 0.8.5-0ubuntu1
* New upstream version. (LP: #383446)
  - Fixes imon support (LP: #283317)
* Refresh the following patches for new version:
  - debian/patches/04_man_pages
  - debian/patches/13-warning-cleanup
  - debian/patches/21_atiusb
  - debian/patches/23_pad2keys
  - debian/patches/28_irrecord_resume_support
  - debian/patches/35_general_deviniput
* debian/control:
  - Add build-depends on libftdi-dev to prevent FTBFS.
* debian/copyright:
  - Update to what debian is shipping.
* debian/modules-source/{lirc-modules-source.conf, Makefile}
  - Don't build cmdir anymore.  It's now a userspace module
* debian/rules:
  - Generate dkms.conf using sed instead.
* debian/patches/12_pvr150_transmit_support:
  - Drop.  Upstream didn't like this patch due to questionable
   copyright, and we aren't properly supporting it anyway.
  - Refresh 20_serial_igor
  - Refresh 26_transmitter_lircd
* debian/lirc-modules-source.README.Debian:
  - Drop, inaccurate now.
* debian/lirc.init.d:
  - Cleanup a useless for loop.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 *   parts cut'n'pasted from sa1100_ir.c (C) 2000 Russell King
34
34
 */
35
35
 
36
 
 
37
36
#include <linux/version.h>
38
37
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18)
39
38
#error "**********************************************************"
47
46
#endif
48
47
 
49
48
#include <linux/autoconf.h>
50
 
 
51
 
#if !defined(LIRC_ON_SA1100) && !defined(CONFIG_SERIAL_MODULE)
 
49
#if !defined(CONFIG_SERIAL_MODULE)
 
50
#if !defined(LIRC_ON_SA1100)
52
51
#warning "******************************************"
53
52
#warning " Your serial port driver is compiled into "
54
53
#warning " the kernel. You will have to release the "
56
55
#warning "    setserial /dev/ttySx uart none        "
57
56
#warning "******************************************"
58
57
#endif
 
58
#endif
59
59
 
60
 
#include <linux/module.h>
61
60
#include <linux/sched.h>
62
61
#include <linux/errno.h>
63
62
#include <linux/signal.h>
65
64
#include <linux/interrupt.h>
66
65
#include <linux/ioport.h>
67
66
#include <linux/kernel.h>
68
 
#include <linux/major.h>
69
67
#include <linux/serial_reg.h>
70
68
#include <linux/time.h>
71
69
#include <linux/string.h>
75
73
#include <linux/delay.h>
76
74
#include <linux/poll.h>
77
75
#include <asm/system.h>
 
76
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
78
77
#include <asm/uaccess.h>
 
78
#endif
 
79
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
79
80
#include <asm/io.h>
 
81
#else
 
82
#include <linux/io.h>
 
83
#endif
80
84
#include <asm/irq.h>
81
 
#include <asm/fcntl.h>
 
85
#include <linux/fcntl.h>
82
86
#ifdef LIRC_ON_SA1100
83
87
#include <asm/hardware.h>
84
88
#ifdef CONFIG_SA1100_COLLIE
95
99
 
96
100
/* SECTION: Definitions */
97
101
 
98
 
/**************************** Tekram dongle ***************************/
 
102
/*** Tekram dongle ***/
99
103
#ifdef LIRC_SIR_TEKRAM
100
104
/* stolen from kernel source */
101
105
/* definitions for Tekram dongle */
108
112
 
109
113
#define TEKRAM_PW 0x10 /* Pulse select bit */
110
114
 
111
 
/* 10bit * 1s/115200bit in miliseconds = 87ms*/
 
115
/* 10bit * 1s/115200bit in milliseconds = 87ms*/
112
116
#define TIME_CONST (10000000ul/115200ul)
113
117
 
114
118
#endif
119
123
static void init_act220(void);
120
124
#endif
121
125
 
122
 
/******************************* SA1100 ********************************/
 
126
/*** SA1100 ***/
123
127
#ifdef LIRC_ON_SA1100
124
128
struct sa1100_ser2_registers {
125
129
        /* HSSP control register */
161
165
#endif
162
166
 
163
167
 
164
 
/* timeout for sequences in jiffies (=5/100s) */
165
 
/* must be longer than TIME_CONST */
 
168
/* timeout for sequences in jiffies (=5/100s), must be longer than TIME_CONST */
166
169
#define SIR_TIMEOUT     (HZ*5/100)
167
170
 
168
171
#ifndef LIRC_ON_SA1100
220
223
static int init_chrdev(void);
221
224
static void drop_chrdev(void);
222
225
#endif
223
 
        /* Hardware */
 
226
/* Hardware */
224
227
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)
225
228
static irqreturn_t sir_interrupt(int irq, void *dev_id,
226
229
                                 struct pt_regs *regs);
231
234
static void send_pulse(unsigned long len);
232
235
static int init_hardware(void);
233
236
static void drop_hardware(void);
234
 
        /* Initialisation */
 
237
/* Initialisation */
235
238
static int init_port(void);
236
239
static void drop_port(void);
237
 
int init_module(void);
238
 
void cleanup_module(void);
239
240
 
240
241
#ifdef LIRC_ON_SA1100
241
 
static inline void on(void)
 
242
static void on(void)
242
243
{
243
244
        PPSR |= PPC_TXD2;
244
245
}
245
246
 
246
 
static inline void off(void)
 
247
static void off(void)
247
248
{
248
249
        PPSR &= ~PPC_TXD2;
249
250
}
250
251
#else
251
 
static inline unsigned int sinp(int offset)
 
252
static unsigned int sinp(int offset)
252
253
{
253
254
        return inb(io + offset);
254
255
}
255
256
 
256
 
static inline void soutp(int offset, int value)
 
257
static void soutp(int offset, int value)
257
258
{
258
259
        outb(value, io + offset);
259
260
}
265
266
#define MAX_UDELAY_US (MAX_UDELAY_MS*1000)
266
267
#endif
267
268
 
268
 
static inline void safe_udelay(unsigned long usecs)
 
269
static void safe_udelay(unsigned long usecs)
269
270
{
270
271
        while (usecs > MAX_UDELAY_US) {
271
272
                udelay(MAX_UDELAY_US);
309
310
        int retval = 0;
310
311
        DECLARE_WAITQUEUE(wait, current);
311
312
 
312
 
        if (n % sizeof(lirc_t))
 
313
        if (count % sizeof(lirc_t))
313
314
                return -EINVAL;
314
315
 
315
316
        add_wait_queue(&lirc_read_queue, &wait);
339
340
        }
340
341
        remove_wait_queue(&lirc_read_queue, &wait);
341
342
        set_current_state(TASK_RUNNING);
342
 
        return (n ? n : retval);
 
343
        return n ? n : retval;
343
344
}
344
345
static ssize_t lirc_write(struct file *file, const char *buf, size_t n,
345
346
                                loff_t *pos)
347
348
        unsigned long flags;
348
349
        int i;
349
350
 
350
 
        if (n % sizeof(lirc_t) || (n/sizeof(lirc_t)) > WBUF_LEN)
 
351
        if (n % sizeof(lirc_t) || (n / sizeof(lirc_t)) > WBUF_LEN)
351
352
                return -EINVAL;
352
353
        if (copy_from_user(tx_buf, buf, n))
353
354
                return -EFAULT;
478
479
 
479
480
        newval = val & PULSE_MASK;
480
481
 
481
 
        /* statistically pulses are ~TIME_CONST/2 too long: we could
482
 
           maybe make this more exactly but this is good enough */
 
482
        /*
 
483
         * statistically, pulses are ~TIME_CONST/2 too long. we could
 
484
         * maybe make this more exact, but this is good enough
 
485
         */
483
486
        if (flag) {
484
487
                /* pulse */
485
488
                if (newval > TIME_CONST/2)
501
504
}
502
505
 
503
506
static struct file_operations lirc_fops = {
 
507
        .owner          = THIS_MODULE,
504
508
        .read           = lirc_read,
505
509
        .write          = lirc_write,
506
510
        .poll           = lirc_poll,
511
515
 
512
516
static int set_use_inc(void *data)
513
517
{
514
 
#if WE_DONT_USE_LOCAL_OPEN_CLOSE
515
 
        MOD_INC_USE_COUNT;
516
 
#endif
517
518
       return 0;
518
519
}
519
520
 
520
521
static void set_use_dec(void *data)
521
522
{
522
 
#if WE_DONT_USE_LOCAL_OPEN_CLOSE
523
 
        MOD_DEC_USE_COUNT;
524
 
#endif
525
523
}
526
 
static struct lirc_plugin plugin = {
 
524
 
 
525
static struct lirc_driver driver = {
527
526
       .name            = LIRC_DRIVER_NAME,
528
527
       .minor           = -1,
529
528
       .code_length     = 1,
530
529
       .sample_rate     = 0,
531
530
       .data            = NULL,
532
531
       .add_to_buf      = NULL,
 
532
#ifndef LIRC_REMOVE_DURING_EXPORT
533
533
       .get_queue       = NULL,
 
534
#endif
534
535
       .set_use_inc     = set_use_inc,
535
536
       .set_use_dec     = set_use_dec,
536
537
       .fops            = &lirc_fops,
542
543
#ifdef MODULE
543
544
static int init_chrdev(void)
544
545
{
545
 
        plugin.minor = lirc_register_plugin(&plugin);
546
 
        if (plugin.minor < 0) {
 
546
        driver.minor = lirc_register_driver(&driver);
 
547
        if (driver.minor < 0) {
547
548
                printk(KERN_ERR LIRC_DRIVER_NAME ": init_chrdev() failed.\n");
548
549
                return -EIO;
549
550
        }
552
553
 
553
554
static void drop_chrdev(void)
554
555
{
555
 
        lirc_unregister_plugin(plugin.minor);
 
556
        lirc_unregister_driver(driver.minor);
556
557
}
557
558
#endif
558
559
 
573
574
 
574
575
static void sir_timeout(unsigned long data)
575
576
{
576
 
        /* if last received signal was a pulse, but receiving stopped
577
 
           within the 9 bit frame, we need to finish this pulse and
578
 
           simulate a signal change to from pulse to space. Otherwise
579
 
           upper layers will receive two sequences next time. */
 
577
        /*
 
578
         * if last received signal was a pulse, but receiving stopped
 
579
         * within the 9 bit frame, we need to finish this pulse and
 
580
         * simulate a signal change to from pulse to space. Otherwise
 
581
         * upper layers will receive two sequences next time.
 
582
         */
580
583
 
581
584
        unsigned long flags;
582
585
        unsigned long pulse_end;
644
647
                        data = Ser2UTDR;
645
648
                        dprintk("%d data: %u\n", n, (unsigned int) data);
646
649
                        n++;
647
 
                } while (status & UTSR0_RID && /* do not empty fifo in
648
 
                                                order to get UTSR0_RID in
649
 
                                                any case */
 
650
                } while (status & UTSR0_RID && /* do not empty fifo in order to
 
651
                                                * get UTSR0_RID in any case */
650
652
                      Ser2UTSR1 & UTSR1_RNE); /* data ready */
651
653
 
652
654
                if (status&UTSR0_RID) {
660
662
        if (status & UTSR0_TFS)
661
663
                printk(KERN_ERR "transmit fifo not full, shouldn't happen\n");
662
664
 
663
 
        /*
664
 
         * We must clear certain bits.
665
 
         */
 
665
        /* We must clear certain bits. */
666
666
        status &= (UTSR0_RID | UTSR0_RBB | UTSR0_REB);
667
667
        if (status)
668
668
                Ser2UTSR0 = status;
695
695
                                deltv = delta(&last_tv, &curr_tv);
696
696
                                deltintrtv = delta(&last_intr_tv, &curr_tv);
697
697
                                dprintk("t %lu, d %d\n", deltintrtv, (int)data);
698
 
                                /* if nothing came in last X cycles,
699
 
                                   it was gap */
 
698
                                /*
 
699
                                 * if nothing came in last X cycles,
 
700
                                 * it was gap
 
701
                                 */
700
702
                                if (deltintrtv > TIME_CONST * threshold) {
701
703
                                        if (last_value) {
702
704
                                                dprintk("GAP\n");
714
716
                                }
715
717
                                data = 1;
716
718
                                if (data ^ last_value) {
717
 
                                        /* deltintrtv > 2*TIME_CONST,
718
 
                                                remember ? */
719
 
                                        /* the other case is timeout */
 
719
                                        /*
 
720
                                         * deltintrtv > 2*TIME_CONST, remember?
 
721
                                         * the other case is timeout
 
722
                                         */
720
723
                                        add_read_queue(last_value,
721
724
                                                       deltv-TIME_CONST);
722
725
                                        last_value = data;
731
734
                                }
732
735
                                last_intr_tv = curr_tv;
733
736
                                if (data) {
734
 
                                        /* start timer for end of
735
 
                                         * sequence detection */
 
737
                                        /*
 
738
                                         * start timer for end of
 
739
                                         * sequence detection
 
740
                                         */
736
741
                                        timerlist.expires = jiffies +
737
742
                                                                SIR_TIMEOUT;
738
743
                                        add_timer(&timerlist);
739
744
                                }
740
 
                        }
741
 
                        while ((lsr = inb(io + UART_LSR))
742
 
                                & UART_LSR_DR); /* data ready */
 
745
 
 
746
                                lsr = inb(io + UART_LSR);
 
747
                        } while (lsr & UART_LSR_DR); /* data ready */
743
748
                        spin_unlock_irqrestore(&timer_lock, flags);
744
749
                        break;
745
750
                default:
758
763
 
759
764
        if (length == 0)
760
765
                return;
761
 
        /* this won't give us the carrier frequency we really want
762
 
           due to integer arithmetic, but we can accept this inaccuracy */
 
766
        /*
 
767
         * this won't give us the carrier frequency we really want
 
768
         * due to integer arithmetic, but we can accept this inaccuracy
 
769
         */
763
770
 
764
771
        for (k = flag = 0; k < length; k += delay, flag = !flag) {
765
772
                if (flag) {
800
807
        while (bytes_out--) {
801
808
                outb(PULSE, io + UART_TX);
802
809
                /* FIXME treba seriozne cakanie z drivers/char/serial.c */
803
 
                while (!(inb(io + UART_LSR) & UART_LSR_THRE));
 
810
                while (!(inb(io + UART_LSR) & UART_LSR_THRE))
 
811
                        ;
804
812
        }
805
813
#if 0
806
814
        if (time_left > 0)
810
818
#endif
811
819
 
812
820
#ifdef CONFIG_SA1100_COLLIE
813
 
static inline int sa1100_irda_set_power_collie(int state)
 
821
static int sa1100_irda_set_power_collie(int state)
814
822
{
815
823
        if (state) {
816
824
                /*
868
876
        /* set output to 0 */
869
877
        off();
870
878
 
871
 
        /*
872
 
         * Enable HP-SIR modulation, and ensure that the port is disabled.
873
 
         */
 
879
        /* Enable HP-SIR modulation, and ensure that the port is disabled. */
874
880
        Ser2UTCR3 = 0;
875
881
        Ser2HSCR0 = sr.hscr0 & (~HSCR0_HSSP);
876
882
 
960
966
        outb(0, io + UART_MCR);
961
967
        outb(0, io + UART_IER);
962
968
        /* init UART */
963
 
                /* set DLAB, speed = 115200 */
 
969
        /* set DLAB, speed = 115200 */
964
970
        outb(UART_LCR_DLAB | UART_LCR_WLEN7, io + UART_LCR);
965
971
        outb(1, io + UART_DLL); outb(0, io + UART_DLM);
966
 
                /* 7N1+start = 9 bits at 115200 ~ 3 bits at 44000 */
 
972
        /* 7N1+start = 9 bits at 115200 ~ 3 bits at 44000 */
967
973
        outb(UART_LCR_WLEN7, io + UART_LCR);
968
 
                /* FIFO operation */
 
974
        /* FIFO operation */
969
975
        outb(UART_FCR_ENABLE_FIFO, io + UART_FCR);
970
 
                /* interrupts */
 
976
        /* interrupts */
971
977
        /* outb(UART_IER_RLSI|UART_IER_RDI|UART_IER_THRI, io + UART_IER); */
972
978
        outb(UART_IER_RDI, io + UART_IER);
973
979
        /* turn on UART */
1060
1066
}
1061
1067
 
1062
1068
#ifdef LIRC_SIR_ACTISYS_ACT200L
1063
 
/******************************************************/
1064
1069
/* Crystal/Cirrus CS8130 IR transceiver, used in Actisys Act200L dongle */
1065
1070
/* some code borrowed from Linux IRDA driver */
1066
1071
 
1067
 
/* Regsiter 0: Control register #1 */
 
1072
/* Register 0: Control register #1 */
1068
1073
#define ACT200L_REG0    0x00
1069
1074
#define ACT200L_TXEN    0x01 /* Enable transmitter */
1070
1075
#define ACT200L_RXEN    0x02 /* Enable receiver */
1101
1106
#define ACT200L_REG7    0x70
1102
1107
#define ACT200L_ENPOS   0x04 /* Ignore the falling edge */
1103
1108
 
1104
 
/* Register 8,9: Baud Rate Dvider register #1,#2 */
 
1109
/* Register 8,9: Baud Rate Divider register #1,#2 */
1105
1110
#define ACT200L_REG8    0x80
1106
1111
#define ACT200L_REG9    0x90
1107
1112
 
1171
1176
        soutp(UART_MCR, UART_MCR_RTS|UART_MCR_OUT2);
1172
1177
        udelay(7);
1173
1178
 
1174
 
/* send out the control register settings for 115K 7N1 SIR operation */
 
1179
        /* send out the control register settings for 115K 7N1 SIR operation */
1175
1180
        for (i = 0; i < sizeof(control); i++) {
1176
1181
                soutp(UART_TX, control[i]);
1177
1182
                /* one byte takes ~1042 usec to transmit at 9600,8N1 */
1204
1209
#endif
1205
1210
 
1206
1211
#ifdef LIRC_SIR_ACTISYS_ACT220L
1207
 
/* Derived from linux IrDA driver (drivers/net/irda/actisys.c)
1208
 
 * Drop me a mail for any kind of comment: maxx@spaceboyz.net */
 
1212
/*
 
1213
 * Derived from linux IrDA driver (net/irda/actisys.c)
 
1214
 * Drop me a mail for any kind of comment: maxx@spaceboyz.net
 
1215
 */
1209
1216
 
1210
1217
void init_act220(void)
1211
1218
{
1228
1235
        /* back to normal (still 9600) */
1229
1236
        soutp(UART_MCR, UART_MCR_DTR|UART_MCR_RTS|UART_MCR_OUT2);
1230
1237
 
1231
 
        /* send RTS pulses until we reach 115200
1232
 
         * i hope this is really the same for act220l/act220l+ */
 
1238
        /*
 
1239
         * send RTS pulses until we reach 115200
 
1240
         * i hope this is really the same for act220l/act220l+
 
1241
         */
1233
1242
        for (i = 0; i < 3; i++) {
1234
1243
                udelay(10);
1235
1244
                /* set RTS low for 10 us */
1250
1259
        soutp(UART_DLL, 1);
1251
1260
 
1252
1261
        /* Set DLAB 0, 7 Bit */
1253
 
        /* The dongle doesn't seem to have any problems with operation
1254
 
           at 7N1 */
 
1262
        /* The dongle doesn't seem to have any problems with operation at 7N1 */
1255
1263
        soutp(UART_LCR, UART_LCR_WLEN7);
1256
1264
 
1257
1265
        /* enable interrupts */
1275
1283
 
1276
1284
#ifdef MODULE
1277
1285
 
1278
 
int init_module(void)
 
1286
static int __init lirc_sir_init(void)
1279
1287
{
1280
1288
        int retval;
1281
1289
 
1290
1298
        return 0;
1291
1299
}
1292
1300
 
1293
 
void cleanup_module(void)
 
1301
static void __exit lirc_sir_exit(void)
1294
1302
{
1295
1303
        drop_hardware();
1296
1304
        drop_chrdev();
1298
1306
        printk(KERN_INFO LIRC_DRIVER_NAME ": Uninstalled.\n");
1299
1307
}
1300
1308
 
 
1309
module_init(lirc_sir_init);
 
1310
module_exit(lirc_sir_exit);
 
1311
 
1301
1312
#ifdef LIRC_SIR_TEKRAM
1302
1313
MODULE_DESCRIPTION("Infrared receiver driver for Tekram Irmate 210");
1303
1314
MODULE_AUTHOR("Christoph Bartelmus");
1317
1328
MODULE_LICENSE("GPL");
1318
1329
 
1319
1330
#ifdef LIRC_ON_SA1100
1320
 
module_param(irq, int, 0444);
 
1331
module_param(irq, int, S_IRUGO);
1321
1332
MODULE_PARM_DESC(irq, "Interrupt (16)");
1322
1333
#else
1323
 
module_param(io, int, 0444);
 
1334
module_param(io, int, S_IRUGO);
1324
1335
MODULE_PARM_DESC(io, "I/O address base (0x3f8 or 0x2f8)");
1325
1336
 
1326
 
module_param(irq, int, 0444);
 
1337
module_param(irq, int, S_IRUGO);
1327
1338
MODULE_PARM_DESC(irq, "Interrupt (4 or 3)");
1328
1339
 
1329
 
module_param(threshold, int, 0444);
 
1340
module_param(threshold, int, S_IRUGO);
1330
1341
MODULE_PARM_DESC(threshold, "space detection threshold (3)");
1331
1342
#endif
1332
1343
 
1333
 
module_param(debug, bool, 0644);
 
1344
module_param(debug, bool, S_IRUGO | S_IWUSR);
1334
1345
MODULE_PARM_DESC(debug, "Enable debugging messages");
1335
1346
 
1336
1347
EXPORT_NO_SYMBOLS;