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

« back to all changes in this revision

Viewing changes to drivers/lirc_it87/lirc_it87.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:
30
30
 *   Forum: Art103 <r_tay@hotmail.com>
31
31
 */
32
32
 
 
33
#ifdef HAVE_CONFIG_H
 
34
#include <config.h>
 
35
#endif
33
36
 
34
37
#include <linux/version.h>
35
38
#include <linux/module.h>
36
 
 
37
 
#ifdef HAVE_CONFIG_H
38
 
#include <config.h>
39
 
#endif
40
 
 
41
39
#include <linux/autoconf.h>
42
 
 
43
 
 
44
40
#include <linux/sched.h>
45
41
#include <linux/errno.h>
46
42
#include <linux/signal.h>
48
44
#include <linux/interrupt.h>
49
45
#include <linux/ioport.h>
50
46
#include <linux/kernel.h>
51
 
#include <linux/major.h>
52
47
#include <linux/serial_reg.h>
53
48
#include <linux/time.h>
54
49
#include <linux/string.h>
59
54
#include <linux/poll.h>
60
55
#include <asm/system.h>
61
56
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)
62
 
#include <asm/uaccess.h>
63
57
#include <asm/io.h>
64
58
#include <asm/irq.h>
65
59
#include <asm/fcntl.h>
66
60
#else
67
 
#include <linux/uaccess.h>
68
61
#include <linux/io.h>
69
62
#include <linux/irq.h>
70
63
#include <linux/fcntl.h>
101
94
/* must be longer than TIME_CONST */
102
95
#define IT87_TIMEOUT    (HZ*5/100)
103
96
 
104
 
/* insmod parameters */
 
97
/* module parameters */
105
98
static int debug;
106
99
#define dprintk(fmt, args...)                                   \
107
100
        do {                                                    \
145
138
static int lirc_ioctl(struct inode *node, struct file *filep,
146
139
                      unsigned int cmd, unsigned long arg);
147
140
static void add_read_queue(int flag, unsigned long val);
148
 
#ifdef MODULE
149
141
static int init_chrdev(void);
150
142
static void drop_chrdev(void);
151
 
#endif
152
143
        /* Hardware */
153
144
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)
154
145
static irqreturn_t it87_interrupt(int irq, void *dev_id,
162
153
static void terminate_send(unsigned long len);
163
154
static int init_hardware(void);
164
155
static void drop_hardware(void);
165
 
        /* Initialisation */
 
156
/* Initialisation */
166
157
static int init_port(void);
167
158
static void drop_port(void);
168
 
int init_module(void);
169
 
void cleanup_module(void);
170
159
 
171
160
 
172
161
/* SECTION: Communication with user-space */
308
297
                break;
309
298
 
310
299
        default:
311
 
                retval = -ENOIOCTLCMD;
 
300
                retval = -EINVAL;
312
301
        }
313
302
 
314
303
        if (retval)
333
322
 
334
323
        newval = val & PULSE_MASK;
335
324
 
336
 
        /* statistically pulses are ~TIME_CONST/2 too long: we could
337
 
           maybe make this more exactly but this is good enough */
 
325
        /*
 
326
         * statistically, pulses are ~TIME_CONST/2 too long. we could
 
327
         * maybe make this more exact, but this is good enough
 
328
         */
338
329
        if (flag) {
339
330
                /* pulse */
340
331
                if (newval > TIME_CONST / 2)
356
347
 
357
348
 
358
349
static struct file_operations lirc_fops = {
 
350
        .owner          = THIS_MODULE,
359
351
        .read           = lirc_read,
360
352
        .write          = lirc_write,
361
353
        .poll           = lirc_poll,
366
358
 
367
359
static int set_use_inc(void *data)
368
360
{
369
 
#if WE_DONT_USE_LOCAL_OPEN_CLOSE
370
 
        MOD_INC_USE_COUNT;
371
 
#endif
372
361
       return 0;
373
362
}
374
363
 
375
364
static void set_use_dec(void *data)
376
365
{
377
 
#if WE_DONT_USE_LOCAL_OPEN_CLOSE
378
 
        MOD_DEC_USE_COUNT;
379
 
#endif
380
366
}
381
 
static struct lirc_plugin plugin = {
 
367
 
 
368
static struct lirc_driver driver = {
382
369
       .name            = LIRC_DRIVER_NAME,
383
370
       .minor           = -1,
384
371
       .code_length     = 1,
385
372
       .sample_rate     = 0,
386
373
       .data            = NULL,
387
374
       .add_to_buf      = NULL,
 
375
#ifndef LIRC_REMOVE_DURING_EXPORT
388
376
       .get_queue       = NULL,
 
377
#endif
389
378
       .set_use_inc     = set_use_inc,
390
379
       .set_use_dec     = set_use_dec,
391
380
       .fops            = &lirc_fops,
394
383
};
395
384
 
396
385
 
397
 
#ifdef MODULE
398
386
static int init_chrdev(void)
399
387
{
400
 
        plugin.minor = lirc_register_plugin(&plugin);
 
388
        driver.minor = lirc_register_driver(&driver);
401
389
 
402
 
        if (plugin.minor < 0) {
 
390
        if (driver.minor < 0) {
403
391
                printk(KERN_ERR LIRC_DRIVER_NAME ": init_chrdev() failed.\n");
404
392
                return -EIO;
405
393
        }
409
397
 
410
398
static void drop_chrdev(void)
411
399
{
412
 
        lirc_unregister_plugin(plugin.minor);
 
400
        lirc_unregister_driver(driver.minor);
413
401
}
414
 
#endif
415
402
 
416
403
 
417
404
/* SECTION: Hardware */
435
422
        spin_lock_irqsave(&timer_lock, flags);
436
423
 
437
424
        if (digimatrix) {
438
 
                /* We have timed out.
439
 
                   Disable the RX mechanism.
440
 
                */
 
425
                /* We have timed out. Disable the RX mechanism. */
441
426
 
442
427
                outb((inb(io + IT87_CIR_RCR) & ~IT87_CIR_RCR_RXEN) |
443
428
                     IT87_CIR_RCR_RXACT, io + IT87_CIR_RCR);
452
437
                     io+IT87_CIR_TCR1);
453
438
 
454
439
        } else {
455
 
                /* if last received signal was a pulse, but receiving
456
 
                   stopped within the 9 bit frame, we need to finish
457
 
                   this pulse and simulate a signal change to from
458
 
                   pulse to space. Otherwise upper layers will receive
459
 
                   two sequences next time. */
 
440
                /*
 
441
                 * if last received signal was a pulse, but receiving stopped
 
442
                 * within the 9 bit frame, we need to finish this pulse and
 
443
                 * simulate a signal change to from pulse to space. Otherwise
 
444
                 * upper layers will receive two sequences next time.
 
445
                 */
460
446
 
461
447
                if (last_value) {
462
448
                        unsigned long pulse_end;
518
504
                                if (data != 0x00) {
519
505
                                        if (timer_enabled)
520
506
                                                del_timer(&timerlist);
521
 
                                        /* start timer for end of
522
 
                                         * sequence detection */
 
507
                                        /*
 
508
                                         * start timer for end of
 
509
                                         * sequence detection
 
510
                                         */
523
511
                                        timerlist.expires = jiffies +
524
512
                                                            IT87_TIMEOUT;
525
513
                                        add_timer(&timerlist);
561
549
                                dprintk("t %lu , d %d\n",
562
550
                                        deltintrtv, (int)data);
563
551
 
564
 
                                /* if nothing came in last 2 cycles,
565
 
                                   it was gap */
 
552
                                /*
 
553
                                 * if nothing came in last 2 cycles,
 
554
                                 * it was gap
 
555
                                 */
566
556
                                if (deltintrtv > TIME_CONST * 2) {
567
557
                                        if (last_value) {
568
558
                                                dprintk("GAP\n");
581
571
                                }
582
572
                                data = 1;
583
573
                                if (data ^ last_value) {
584
 
                                        /* deltintrtv > 2*TIME_CONST,
585
 
                                           remember ? */
586
 
                                        /* the other case is timeout */
 
574
                                        /*
 
575
                                         * deltintrtv > 2*TIME_CONST,
 
576
                                         * remember ? the other case is
 
577
                                         * timeout
 
578
                                         */
587
579
                                        add_read_queue(last_value,
588
580
                                                       deltv-TIME_CONST);
589
581
                                        last_value = data;
598
590
                                }
599
591
                                last_intr_tv = curr_tv;
600
592
                                if (data) {
601
 
                                        /* start timer for end of
602
 
                                         * sequence detection */
 
593
                                        /*
 
594
                                         * start timer for end of
 
595
                                         * sequence detection
 
596
                                         */
603
597
                                        timerlist.expires =
604
598
                                                jiffies + IT87_TIMEOUT;
605
599
                                        add_timer(&timerlist);
636
630
        static unsigned char byte_out;
637
631
        unsigned long hw_flags;
638
632
 
639
 
        dprintk("%s: len=%ld, sb=%d\n", __FUNCTION__, len, send_byte);
 
633
        dprintk("%s: len=%ld, sb=%d\n", __func__, len, send_byte);
640
634
 
641
635
        time_left = (long)len - (long)count * (long)stime;
642
636
        count += ((2 * time_left) / stime);
669
663
}
670
664
 
671
665
 
672
 
/*
673
 
maybe: exchange space and pulse because
674
 
it8705 only modulates 0-bits
675
 
*/
676
 
 
 
666
/*TODO: maybe exchange space and pulse because it8705 only modulates 0-bits */
677
667
 
678
668
static void send_space(unsigned long len)
679
669
{
711
701
        while (last == it87_send_counter)
712
702
                send_space(len);
713
703
        /* wait until all data sent */
714
 
        while ((inb(io + IT87_CIR_TSR) & IT87_CIR_TSR_TXFBC) != 0);
715
 
        /* then reenable receiver */
 
704
        while ((inb(io + IT87_CIR_TSR) & IT87_CIR_TSR_TXFBC) != 0)
 
705
                ;
 
706
        /* then re-enable receiver */
716
707
        spin_lock_irqsave(&hardware_lock, flags);
717
708
        it87_RXEN_mask = IT87_CIR_RCR_RXEN;
718
709
        outb(inb(io + IT87_CIR_RCR) | IT87_CIR_RCR_RXEN,
749
740
                outb(inb(io + IT87_CIR_TCR1) |  0x00,
750
741
                     io + IT87_CIR_TCR1);
751
742
 
752
 
                /* TX: it87_freq (36kHz),
753
 
                   'reserved' sensitivity setting (0x00) */
 
743
                /*
 
744
                 * TX: it87_freq (36kHz), 'reserved' sensitivity
 
745
                 * setting (0x00)
 
746
                 */
754
747
                outb(((it87_freq - IT87_CIR_FREQ_MIN) << 3) | 0x00,
755
748
                     io + IT87_CIR_TCR2);
756
749
        } else {
757
 
                /* TX: 38kHz, 13,3us (pulse-width */
 
750
                /* TX: 38kHz, 13,3us (pulse-width) */
758
751
                outb(((it87_freq - IT87_CIR_FREQ_MIN) << 3) | 0x06,
759
752
                     io + IT87_CIR_TCR2);
760
753
        }
804
797
        unsigned long hw_flags;
805
798
        int retval = 0;
806
799
 
807
 
        unsigned char init_bytes[4] = {IT87_INIT};
 
800
        unsigned char init_bytes[4] = IT87_INIT;
808
801
        unsigned char it87_chipid = 0;
809
802
        unsigned char ldn = 0;
810
803
        unsigned int  it87_io = 0;
912
905
 
913
906
static void drop_port(void)
914
907
{
915
 
/*
916
 
        unsigned char init_bytes[4] = {IT87_INIT};
 
908
#if 0
 
909
        unsigned char init_bytes[4] = IT87_INIT;
917
910
 
918
911
        / * Enter MB PnP Mode * /
919
912
        outb(init_bytes[0], IT87_ADRPORT);
926
919
 
927
920
        / * Leaving MB PnP Mode * /
928
921
        it87_write(IT87_CFGCTRL, 0x2);
929
 
*/
 
922
#endif
930
923
 
931
924
        del_timer_sync(&timerlist);
932
925
        free_irq(irq, NULL);
948
941
}
949
942
 
950
943
 
951
 
#ifdef MODULE
952
 
 
953
 
int init_module(void)
 
944
static int __init lirc_it87_init(void)
954
945
{
955
946
        int retval;
956
947
 
966
957
}
967
958
 
968
959
 
969
 
void cleanup_module(void)
 
960
static void __exit lirc_it87_exit(void)
970
961
{
971
962
        drop_hardware();
972
963
        drop_chrdev();
974
965
        printk(KERN_INFO LIRC_DRIVER_NAME ": Uninstalled.\n");
975
966
}
976
967
 
 
968
module_init(lirc_it87_init);
 
969
module_exit(lirc_it87_exit);
 
970
 
977
971
MODULE_DESCRIPTION("LIRC driver for ITE IT8712/IT8705 CIR port");
978
972
MODULE_AUTHOR("Hans-G�nter L�tke Uphues");
979
973
MODULE_LICENSE("GPL");
980
974
 
981
 
module_param(io, int, 0444);
 
975
module_param(io, int, S_IRUGO);
982
976
MODULE_PARM_DESC(io, "I/O base address (default: 0x310)");
983
977
 
984
 
module_param(irq, int, 0444);
 
978
module_param(irq, int, S_IRUGO);
985
979
#ifdef LIRC_IT87_DIGIMATRIX
986
980
MODULE_PARM_DESC(irq, "Interrupt (1,3-12) (default: 9)");
987
981
#else
988
982
MODULE_PARM_DESC(irq, "Interrupt (1,3-12) (default: 7)");
989
983
#endif
990
984
 
991
 
module_param(it87_enable_demodulator, bool, 0444);
 
985
module_param(it87_enable_demodulator, bool, S_IRUGO);
992
986
MODULE_PARM_DESC(it87_enable_demodulator,
993
987
                 "Receiver demodulator enable/disable (1/0), default: 0");
994
988
 
995
 
module_param(debug, bool, 0644);
 
989
module_param(debug, bool, S_IRUGO | S_IWUSR);
996
990
MODULE_PARM_DESC(debug, "Enable debugging messages");
997
991
 
998
 
module_param(digimatrix, bool, 0644);
 
992
module_param(digimatrix, bool, S_IRUGO | S_IWUSR);
999
993
#ifdef LIRC_IT87_DIGIMATRIX
1000
994
MODULE_PARM_DESC(digimatrix,
1001
995
        "Asus Digimatrix it87 compat. enable/disable (1/0), default: 1");
1005
999
#endif
1006
1000
 
1007
1001
 
1008
 
module_param(it87_freq, int, 0444);
 
1002
module_param(it87_freq, int, S_IRUGO);
1009
1003
#ifdef LIRC_IT87_DIGIMATRIX
1010
1004
MODULE_PARM_DESC(it87_freq,
1011
1005
    "Carrier demodulator frequency (kHz), (default: 36)");
1013
1007
MODULE_PARM_DESC(it87_freq,
1014
1008
    "Carrier demodulator frequency (kHz), (default: 38)");
1015
1009
#endif
1016
 
 
1017
1010
EXPORT_NO_SYMBOLS;
1018
 
 
1019
 
#endif /* MODULE */
1020
 
 
1021
 
 
1022
 
/*
1023
 
 * Overrides for Emacs so that we follow Linus's tabbing style.
1024
 
 * ---------------------------------------------------------------------------
1025
 
 * Local variables:
1026
 
 * c-basic-offset: 8
1027
 
 * End:
1028
 
 */