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

« back to all changes in this revision

Viewing changes to drivers/lirc_streamzap/lirc_streamzap.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:
1
 
/*      $Id: lirc_streamzap.c,v 1.29 2008/09/17 18:20:16 lirc Exp $      */
2
 
 
 
1
/*      $Id: lirc_streamzap.c,v 1.48 2009/03/15 09:34:00 lirc Exp $      */
3
2
/*
4
3
 * Streamzap Remote Control driver
5
4
 *
28
27
 *  You should have received a copy of the GNU General Public License
29
28
 *  along with this program; if not, write to the Free Software
30
29
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
31
 
 *
32
30
 */
33
31
 
34
32
#include <linux/version.h>
37
35
#error "Sorry, this driver needs kernel version 2.4.0 or higher"
38
36
#error "*******************************************************"
39
37
#endif
40
 
 
41
38
#include <linux/autoconf.h>
42
39
#include <linux/kernel.h>
43
40
#include <linux/errno.h>
57
54
#include "drivers/kcompat.h"
58
55
#include "drivers/lirc_dev/lirc_dev.h"
59
56
 
60
 
#define DRIVER_VERSION  "$Revision: 1.29 $"
 
57
#define DRIVER_VERSION  "$Revision: 1.48 $"
61
58
#define DRIVER_NAME     "lirc_streamzap"
62
59
#define DRIVER_DESC     "Streamzap Remote Control driver"
63
60
 
64
 
/* ------------------------------------------------------------------ */
65
 
 
66
61
static int debug;
67
62
 
68
63
#define USB_STREAMZAP_VENDOR_ID         0x0e9c
76
71
                               fmt "\n", ## args);              \
77
72
        } while (0)
78
73
 
79
 
/*
80
 
 * table of devices that work with this driver
81
 
 */
82
 
static struct usb_device_id streamzap_table [] = {
 
74
/* table of devices that work with this driver */
 
75
static struct usb_device_id streamzap_table[] = {
83
76
        /* Streamzap Remote Control */
84
77
        { USB_DEVICE(USB_STREAMZAP_VENDOR_ID, USB_STREAMZAP_PRODUCT_ID) },
85
78
        /* Terminating entry */
102
95
        IgnorePulse
103
96
};
104
97
 
105
 
/* Structure to hold all of our device specific stuff */
106
 
/* some remarks regarding locking:
107
 
   theoretically this struct can be accessed from three threads:
108
 
 
109
 
   - from lirc_dev through set_use_inc/set_use_dec
110
 
 
111
 
   - from the USB layer throuh probe/disconnect/irq
112
 
 
113
 
     Careful placement of lirc_register_plugin/lirc_unregister_plugin
114
 
     calls will prevent conflicts. lirc_dev makes sure that
115
 
     set_use_inc/set_use_dec are not being executed and will not be
116
 
     called after lirc_unregister_plugin returns.
117
 
 
118
 
   - by the timer callback
119
 
 
120
 
     The timer is only running when the device is connected and the
121
 
     LIRC device is open. Making sure the timer is deleted by
122
 
     set_use_dec will make conflicts impossible.
123
 
*/
 
98
/* Structure to hold all of our device specific stuff
 
99
 *
 
100
 * some remarks regarding locking:
 
101
 * theoretically this struct can be accessed from three threads:
 
102
 *
 
103
 * - from lirc_dev through set_use_inc/set_use_dec
 
104
 *
 
105
 * - from the USB layer throuh probe/disconnect/irq
 
106
 *
 
107
 *   Careful placement of lirc_register_driver/lirc_unregister_driver
 
108
 *   calls will prevent conflicts. lirc_dev makes sure that
 
109
 *   set_use_inc/set_use_dec are not being executed and will not be
 
110
 *   called after lirc_unregister_driver returns.
 
111
 *
 
112
 * - by the timer callback
 
113
 *
 
114
 *   The timer is only running when the device is connected and the
 
115
 *   LIRC device is open. Making sure the timer is deleted by
 
116
 *   set_use_dec will make conflicts impossible.
 
117
 */
124
118
struct usb_streamzap {
125
119
 
126
120
        /* usb */
140
134
        struct urb              *urb_in;
141
135
 
142
136
        /* lirc */
143
 
        struct lirc_plugin      plugin;
 
137
        struct lirc_driver      driver;
144
138
        struct lirc_buffer      delay_buf;
145
139
        struct lirc_buffer      lirc_buf;
146
140
 
228
222
        unsigned long flags;
229
223
        /* deliver data every 10 ms */
230
224
        static unsigned long timer_inc =
231
 
                (10000/(1000000/HZ)) == 0 ? 1:(10000/(1000000/HZ));
 
225
                (10000/(1000000/HZ)) == 0 ? 1 : (10000/(1000000/HZ));
232
226
        struct usb_streamzap *sz = (struct usb_streamzap *) arg;
233
227
        lirc_t data;
234
228
 
236
230
 
237
231
        if (!lirc_buffer_empty(&sz->delay_buf) &&
238
232
            !lirc_buffer_full(&sz->lirc_buf)) {
239
 
                lirc_buffer_read_1(&sz->delay_buf, (unsigned char *) &data);
240
 
                lirc_buffer_write_1(&sz->lirc_buf, (unsigned char *) &data);
 
233
                lirc_buffer_read(&sz->delay_buf, (unsigned char *) &data);
 
234
                lirc_buffer_write(&sz->lirc_buf, (unsigned char *) &data);
241
235
        }
242
236
        if (!lirc_buffer_empty(&sz->delay_buf)) {
243
237
                while (lirc_buffer_available(&sz->delay_buf) <
244
238
                      STREAMZAP_BUFFER_SIZE/2 &&
245
239
                      !lirc_buffer_full(&sz->lirc_buf)) {
246
 
                        lirc_buffer_read_1(&sz->delay_buf,
247
 
                                           (unsigned char *) &data);
248
 
                        lirc_buffer_write_1(&sz->lirc_buf,
249
 
                                            (unsigned char *) &data);
 
240
                        lirc_buffer_read(&sz->delay_buf,
 
241
                                         (unsigned char *) &data);
 
242
                        lirc_buffer_write(&sz->lirc_buf,
 
243
                                          (unsigned char *) &data);
250
244
                }
251
245
                if (sz->timer_running) {
252
 
                        sz->delay_timer.expires += timer_inc;
 
246
                        sz->delay_timer.expires = jiffies + timer_inc;
253
247
                        add_timer(&sz->delay_timer);
254
248
                }
255
249
        } else {
262
256
        spin_unlock_irqrestore(&sz->timer_lock, flags);
263
257
}
264
258
 
265
 
static inline void flush_delay_buffer(struct usb_streamzap *sz)
 
259
static void flush_delay_buffer(struct usb_streamzap *sz)
266
260
{
267
261
        lirc_t data;
268
262
        int empty = 1;
269
263
 
270
264
        while (!lirc_buffer_empty(&sz->delay_buf)) {
271
265
                empty = 0;
272
 
                lirc_buffer_read_1(&sz->delay_buf, (unsigned char *) &data);
 
266
                lirc_buffer_read(&sz->delay_buf, (unsigned char *) &data);
273
267
                if (!lirc_buffer_full(&sz->lirc_buf)) {
274
 
                        lirc_buffer_write_1(&sz->lirc_buf,
 
268
                        lirc_buffer_write(&sz->lirc_buf,
275
269
                                            (unsigned char *) &data);
276
270
                } else {
277
 
                        dprintk("buffer overflow\n", sz->plugin.minor);
 
271
                        dprintk("buffer overflow", sz->driver.minor);
278
272
                }
279
273
        }
280
274
        if (!empty)
281
275
                wake_up(&sz->lirc_buf.wait_poll);
282
276
}
283
277
 
284
 
static inline void push(struct usb_streamzap *sz, unsigned char *data)
 
278
static void push(struct usb_streamzap *sz, unsigned char *data)
285
279
{
286
280
        unsigned long flags;
287
281
 
289
283
        if (lirc_buffer_full(&sz->delay_buf)) {
290
284
                lirc_t data;
291
285
 
292
 
                lirc_buffer_read_1(&sz->delay_buf, (unsigned char *) &data);
 
286
                lirc_buffer_read(&sz->delay_buf, (unsigned char *) &data);
293
287
                if (!lirc_buffer_full(&sz->lirc_buf)) {
294
 
                        lirc_buffer_write_1(&sz->lirc_buf,
295
 
                                            (unsigned char *) &data);
 
288
                        lirc_buffer_write(&sz->lirc_buf,
 
289
                                          (unsigned char *) &data);
296
290
                } else {
297
 
                        dprintk("buffer overflow", sz->plugin.minor);
 
291
                        dprintk("buffer overflow", sz->driver.minor);
298
292
                }
299
293
        }
300
294
 
301
 
        lirc_buffer_write_1(&sz->delay_buf, data);
 
295
        lirc_buffer_write(&sz->delay_buf, data);
302
296
 
303
297
        if (!sz->timer_running) {
304
298
                sz->delay_timer.expires = jiffies + HZ/10;
309
303
        spin_unlock_irqrestore(&sz->timer_lock, flags);
310
304
}
311
305
 
312
 
static inline void push_full_pulse(struct usb_streamzap *sz,
 
306
static void push_full_pulse(struct usb_streamzap *sz,
313
307
                                   unsigned char value)
314
308
{
315
309
        lirc_t pulse;
330
324
                                        sz->signal_last.tv_usec);
331
325
                        tmp -= sz->sum;
332
326
                }
333
 
                dprintk("ls %u", sz->plugin.minor, tmp);
 
327
                dprintk("ls %u", sz->driver.minor, tmp);
334
328
                push(sz, (char *)&tmp);
335
329
 
336
330
                sz->idle = 0;
342
336
        sz->sum += pulse;
343
337
        pulse |= PULSE_BIT;
344
338
 
345
 
        dprintk("p %u", sz->plugin.minor, pulse&PULSE_MASK);
 
339
        dprintk("p %u", sz->driver.minor, pulse&PULSE_MASK);
346
340
        push(sz, (char *)&pulse);
347
341
}
348
342
 
349
 
static inline void push_half_pulse(struct usb_streamzap *sz,
 
343
static void push_half_pulse(struct usb_streamzap *sz,
350
344
                                   unsigned char value)
351
345
{
352
346
        push_full_pulse(sz, (value & STREAMZAP_PULSE_MASK)>>4);
353
347
}
354
348
 
355
 
static inline void push_full_space(struct usb_streamzap *sz,
 
349
static void push_full_space(struct usb_streamzap *sz,
356
350
                                   unsigned char value)
357
351
{
358
352
        lirc_t space;
360
354
        space = ((lirc_t) value)*STREAMZAP_RESOLUTION;
361
355
        space += STREAMZAP_RESOLUTION/2;
362
356
        sz->sum += space;
363
 
        dprintk("s %u", sz->plugin.minor, space);
 
357
        dprintk("s %u", sz->driver.minor, space);
364
358
        push(sz, (char *)&space);
365
359
}
366
360
 
367
 
static inline void push_half_space(struct usb_streamzap *sz,
 
361
static void push_half_space(struct usb_streamzap *sz,
368
362
                                   unsigned char value)
369
363
{
370
364
        push_full_space(sz, value & STREAMZAP_SPACE_MASK);
371
365
}
372
366
 
373
 
/*
 
367
/**
374
368
 * usb_streamzap_irq - IRQ handler
375
369
 *
376
370
 * This procedure is invoked on reception of data from
396
390
        case -ECONNRESET:
397
391
        case -ENOENT:
398
392
        case -ESHUTDOWN:
399
 
                /* this urb is terminated, clean up */
400
 
                /* sz might already be invalid at this point */
 
393
                /*
 
394
                 * this urb is terminated, clean up.
 
395
                 * sz might already be invalid at this point
 
396
                 */
401
397
                dprintk("urb status: %d", -1, urb->status);
402
398
                return;
403
399
        default:
404
400
                break;
405
401
        }
406
402
 
407
 
        dprintk("received %d", sz->plugin.minor, urb->actual_length);
 
403
        dprintk("received %d", sz->driver.minor, urb->actual_length);
408
404
        if (!sz->flush) {
409
405
                for (i = 0; i < urb->actual_length; i++) {
410
 
                        dprintk("%d: %x", sz->plugin.minor,
 
406
                        dprintk("%d: %x", sz->driver.minor,
411
407
                                i, (unsigned char) sz->buf_in[i]);
412
408
                        switch (sz->decoder_state) {
413
409
                        case PulseSpace:
452
448
        }
453
449
 
454
450
#ifdef KERNEL_2_5
455
 
        /* resubmit only for 2.6 */
456
451
        usb_submit_urb(urb, GFP_ATOMIC);
457
452
#endif
458
453
 
459
454
        return;
460
455
}
461
456
 
 
457
static struct file_operations streamzap_fops = {
 
458
        .owner          = THIS_MODULE,
 
459
        .ioctl          = streamzap_ioctl,
 
460
};
 
461
 
 
462
 
462
463
/**
463
464
 *      streamzap_probe
464
465
 *
483
484
        struct usb_streamzap *sz = NULL;
484
485
        char buf[63], name[128] = "";
485
486
 
486
 
        /***************************************************
487
 
         * Allocate space for device driver specific data
488
 
         */
489
 
        sz = kmalloc(sizeof(struct usb_streamzap), GFP_KERNEL);
 
487
        /* Allocate space for device driver specific data */
 
488
        sz = kzalloc(sizeof(struct usb_streamzap), GFP_KERNEL);
490
489
        if (sz == NULL)
491
490
                goto error;
492
491
 
493
 
        memset(sz, 0, sizeof(*sz));
494
492
        sz->udev = udev;
495
493
        sz->interface = interface;
496
494
 
497
 
        /***************************************************
498
 
         * Check to ensure endpoint information matches requirements
499
 
         */
 
495
        /* Check to ensure endpoint information matches requirements */
500
496
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 5)
501
497
        iface_host = &interface->altsetting[interface->act_altsetting];
502
498
#else
509
505
        if (iface_host->bNumEndpoints != 1) {
510
506
#endif
511
507
#ifdef KERNEL_2_5
512
 
                err("%s: Unexpected desc.bNumEndpoints (%d)", __FUNCTION__,
 
508
                err("%s: Unexpected desc.bNumEndpoints (%d)", __func__,
513
509
                    iface_host->desc.bNumEndpoints);
514
510
#else
515
 
                err("%s: Unexpected desc.bNumEndpoints (%d)", __FUNCTION__,
 
511
                err("%s: Unexpected desc.bNumEndpoints (%d)", __func__,
516
512
                    iface_host->bNumEndpoints);
517
513
#endif
518
514
                retval = -ENODEV;
527
523
        if ((sz->endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
528
524
            != USB_DIR_IN) {
529
525
                err("%s: endpoint doesn't match input device 02%02x",
530
 
                    __FUNCTION__, sz->endpoint->bEndpointAddress);
 
526
                    __func__, sz->endpoint->bEndpointAddress);
531
527
                retval = -ENODEV;
532
528
                goto error;
533
529
        }
535
531
        if ((sz->endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
536
532
            != USB_ENDPOINT_XFER_INT) {
537
533
                err("%s: endpoint attributes don't match xfer 02%02x",
538
 
                    __FUNCTION__, sz->endpoint->bmAttributes);
 
534
                    __func__, sz->endpoint->bmAttributes);
539
535
                retval = -ENODEV;
540
536
                goto error;
541
537
        }
542
538
 
543
539
        if (sz->endpoint->wMaxPacketSize == 0) {
544
 
                err("%s: endpoint message size==0? ", __FUNCTION__);
 
540
                err("%s: endpoint message size==0? ", __func__);
545
541
                retval = -ENODEV;
546
542
                goto error;
547
543
        }
548
544
 
549
 
        /***************************************************
550
 
         * Allocate the USB buffer and IRQ URB
551
 
         */
 
545
        /* Allocate the USB buffer and IRQ URB */
552
546
 
553
547
        sz->buf_in_len = sz->endpoint->wMaxPacketSize;
554
548
#ifdef KERNEL_2_5
569
563
        if (sz->urb_in == NULL)
570
564
                goto error;
571
565
 
572
 
        /***************************************************
573
 
         * Connect this device to the LIRC sub-system
574
 
         */
 
566
        /* Connect this device to the LIRC sub-system */
575
567
 
576
568
        if (lirc_buffer_init(&sz->lirc_buf, sizeof(lirc_t),
577
569
                             STREAMZAP_BUFFER_SIZE))
583
575
                goto error;
584
576
        }
585
577
 
586
 
        /***************************************************
587
 
         * As required memory is allocated now populate the plugin structure
588
 
         */
589
 
 
590
 
        memset(&sz->plugin, 0, sizeof(sz->plugin));
591
 
 
592
 
        strcpy(sz->plugin.name, DRIVER_NAME);
593
 
        sz->plugin.minor = -1;
594
 
        sz->plugin.sample_rate = 0;
595
 
        sz->plugin.code_length = sizeof(lirc_t) * 8;
596
 
        sz->plugin.features = LIRC_CAN_REC_MODE2|LIRC_CAN_GET_REC_RESOLUTION;
597
 
        sz->plugin.data = sz;
598
 
        sz->plugin.rbuf = &sz->lirc_buf;
599
 
        sz->plugin.set_use_inc = &streamzap_use_inc;
600
 
        sz->plugin.set_use_dec = &streamzap_use_dec;
601
 
        sz->plugin.ioctl = streamzap_ioctl;
 
578
        strcpy(sz->driver.name, DRIVER_NAME);
 
579
        sz->driver.minor = -1;
 
580
        sz->driver.sample_rate = 0;
 
581
        sz->driver.code_length = sizeof(lirc_t) * 8;
 
582
        sz->driver.features = LIRC_CAN_REC_MODE2 | LIRC_CAN_GET_REC_RESOLUTION;
 
583
        sz->driver.data = sz;
 
584
        sz->driver.rbuf = &sz->lirc_buf;
 
585
        sz->driver.set_use_inc = &streamzap_use_inc;
 
586
        sz->driver.set_use_dec = &streamzap_use_dec;
 
587
        sz->driver.fops = &streamzap_fops;
602
588
#ifdef LIRC_HAVE_SYSFS
603
 
        sz->plugin.dev = &udev->dev;
 
589
        sz->driver.dev = &interface->dev;
604
590
#endif
605
 
        sz->plugin.owner = THIS_MODULE;
 
591
        sz->driver.owner = THIS_MODULE;
606
592
 
607
593
        sz->idle = 1;
608
594
        sz->decoder_state = PulseSpace;
615
601
        init_timer(&sz->flush_timer);
616
602
        sz->flush_timer.function = flush_timeout;
617
603
        sz->flush_timer.data = (unsigned long) sz;
618
 
        /***************************************************
619
 
         * Complete final initialisations
620
 
         */
 
604
        /* Complete final initialisations */
621
605
 
622
606
        usb_fill_int_urb(sz->urb_in, udev,
623
607
                usb_rcvintpipe(udev, sz->endpoint->bEndpointAddress),
624
608
                sz->buf_in, sz->buf_in_len, usb_streamzap_irq, sz,
625
609
                sz->endpoint->bInterval);
 
610
#ifdef KERNEL_2_5
 
611
        sz->urb_in->transfer_dma = sz->dma_in;
 
612
        sz->urb_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
 
613
#endif
626
614
 
627
615
        if (udev->descriptor.iManufacturer
628
 
            && usb_string(udev, udev->descriptor.iManufacturer, buf, 63) > 0)
629
 
                strncpy(name, buf, 128);
 
616
            && usb_string(udev, udev->descriptor.iManufacturer,
 
617
                          buf, sizeof(buf)) > 0)
 
618
                strlcpy(name, buf, sizeof(name));
630
619
 
631
620
        if (udev->descriptor.iProduct
632
 
            && usb_string(udev,  udev->descriptor.iProduct, buf, 63) > 0)
633
 
                snprintf(name, 128, "%s %s", name, buf);
 
621
            && usb_string(udev,  udev->descriptor.iProduct,
 
622
                          buf, sizeof(buf)) > 0)
 
623
                snprintf(name + strlen(name), sizeof(name) - strlen(name),
 
624
                         " %s", buf);
634
625
 
635
626
        printk(KERN_INFO DRIVER_NAME "[%d]: %s on usb%d:%d attached\n",
636
 
               sz->plugin.minor, name,
 
627
               sz->driver.minor, name,
637
628
               udev->bus->busnum, sz->udev->devnum);
638
629
 
639
630
#ifdef KERNEL_2_5
640
631
        usb_set_intfdata(interface, sz);
641
632
#endif
642
633
 
643
 
        if (lirc_register_plugin(&sz->plugin) < 0) {
 
634
        if (lirc_register_driver(&sz->driver) < 0) {
644
635
                lirc_buffer_free(&sz->delay_buf);
645
636
                lirc_buffer_free(&sz->lirc_buf);
646
637
                goto error;
654
645
 
655
646
error:
656
647
 
657
 
        /***************************************************
 
648
        /*
658
649
         * Premise is that a 'goto error' can be invoked from inside the
659
650
         * probe function and all necessary cleanup actions will be taken
660
651
         * including freeing any necessary memory blocks
664
655
                err("Out of memory");
665
656
 
666
657
        if (sz) {
667
 
 
668
 
                if (sz->urb_in)
669
 
                        usb_free_urb(sz->urb_in);
670
 
 
 
658
                usb_free_urb(sz->urb_in);
 
659
#ifdef KERNEL_2_5
 
660
                usb_buffer_free(udev, sz->buf_in_len, sz->buf_in, sz->dma_in);
 
661
#else
671
662
                if (sz->buf_in) {
672
 
#ifdef KERNEL_2_5
673
 
                        usb_buffer_free(udev, sz->buf_in_len,
674
 
                                        sz->buf_in, sz->dma_in);
675
 
#else
676
663
                        kfree(sz->buf_in);
 
664
                }
677
665
#endif
678
 
                }
679
666
                kfree(sz);
680
667
        }
681
668
 
691
678
        struct usb_streamzap *sz = data;
692
679
 
693
680
        if (!sz) {
694
 
                dprintk("%s called with no context", -1, __FUNCTION__);
 
681
                dprintk("%s called with no context", -1, __func__);
695
682
                return -EINVAL;
696
683
        }
697
 
        dprintk("set use inc", sz->plugin.minor);
698
 
 
 
684
        dprintk("set use inc", sz->driver.minor);
699
685
        MOD_INC_USE_COUNT;
700
686
 
701
 
        while (!lirc_buffer_empty(&sz->lirc_buf))
702
 
                lirc_buffer_remove_1(&sz->lirc_buf);
703
 
        while (!lirc_buffer_empty(&sz->delay_buf))
704
 
                lirc_buffer_remove_1(&sz->delay_buf);
 
687
        lirc_buffer_clear(&sz->lirc_buf);
 
688
        lirc_buffer_clear(&sz->delay_buf);
705
689
 
706
690
        sz->flush_timer.expires = jiffies + HZ;
707
691
        sz->flush = 1;
714
698
        if (usb_submit_urb(sz->urb_in)) {
715
699
#endif
716
700
                dprintk("open result = -EIO error submitting urb",
717
 
                        sz->plugin.minor);
 
701
                        sz->driver.minor);
718
702
                MOD_DEC_USE_COUNT;
719
703
                return -EIO;
720
704
        }
728
712
        struct usb_streamzap *sz = data;
729
713
 
730
714
        if (!sz) {
731
 
                dprintk("%s called with no context", -1, __FUNCTION__);
 
715
                dprintk("%s called with no context", -1, __func__);
732
716
                return;
733
717
        }
734
 
        dprintk("set use dec", sz->plugin.minor);
 
718
        dprintk("set use dec", sz->driver.minor);
735
719
 
736
720
        if (sz->flush) {
737
721
                sz->flush = 0;
753
737
 
754
738
        switch (cmd) {
755
739
        case LIRC_GET_REC_RESOLUTION:
756
 
                result = put_user(STREAMZAP_RESOLUTION, (unsigned long *) arg);
 
740
                result = put_user(STREAMZAP_RESOLUTION, (unsigned int *) arg);
757
741
                if (result)
758
 
                        return(result);
 
742
                        return result;
759
743
                break;
760
744
        default:
761
745
                return -ENOIOCTLCMD;
764
748
}
765
749
 
766
750
/**
767
 
 *      streamzap_disconnect
768
 
 *
769
 
 *      Called by the usb core when the device is removed from the system.
770
 
 *
771
 
 *      This routine guarantees that the driver will not submit any more urbs
772
 
 *      by clearing dev->udev.  It is also supposed to terminate any currently
773
 
 *      active urbs.  Unfortunately, usb_bulk_msg(), used in streamzap_read(),
774
 
 *      does not provide any way to do this.
 
751
 * streamzap_disconnect
 
752
 *
 
753
 * Called by the usb core when the device is removed from the system.
 
754
 *
 
755
 * This routine guarantees that the driver will not submit any more urbs
 
756
 * by clearing dev->udev.  It is also supposed to terminate any currently
 
757
 * active urbs.  Unfortunately, usb_bulk_msg(), used in streamzap_read(),
 
758
 * does not provide any way to do this.
775
759
 */
776
760
#ifdef KERNEL_2_5
777
761
static void streamzap_disconnect(struct usb_interface *interface)
789
773
        sz = ptr;
790
774
#endif
791
775
 
792
 
        /*
793
 
         * unregister from the LIRC sub-system
794
 
         */
 
776
        /* unregister from the LIRC sub-system */
795
777
 
796
 
        errnum = lirc_unregister_plugin(sz->plugin.minor);
 
778
        errnum = lirc_unregister_driver(sz->driver.minor);
797
779
        if (errnum != 0)
798
780
                dprintk("error in lirc_unregister: (returned %d)",
799
 
                        sz->plugin.minor, errnum);
 
781
                        sz->driver.minor, errnum);
800
782
 
801
783
        lirc_buffer_free(&sz->delay_buf);
802
784
        lirc_buffer_free(&sz->lirc_buf);
803
785
 
804
 
        /*
805
 
         * unregister from the USB sub-system
806
 
         */
 
786
        /* unregister from the USB sub-system */
807
787
 
808
788
        usb_free_urb(sz->urb_in);
809
789
 
813
793
        kfree(sz->buf_in);
814
794
#endif
815
795
 
816
 
        minor = sz->plugin.minor;
 
796
        minor = sz->driver.minor;
817
797
        kfree(sz);
818
798
 
819
799
        printk(KERN_INFO DRIVER_NAME "[%d]: disconnected\n", minor);
824
804
{
825
805
        struct usb_streamzap *sz = usb_get_intfdata(intf);
826
806
 
827
 
        printk(DRIVER_NAME "[%d]: suspend\n", sz->plugin.minor);
 
807
        printk(KERN_INFO DRIVER_NAME "[%d]: suspend\n", sz->driver.minor);
828
808
        if (sz->in_use) {
829
809
                if (sz->flush) {
830
810
                        sz->flush = 0;
842
822
{
843
823
        struct usb_streamzap *sz = usb_get_intfdata(intf);
844
824
 
845
 
        while (!lirc_buffer_empty(&sz->lirc_buf))
846
 
                lirc_buffer_remove_1(&sz->lirc_buf);
847
 
        while (!lirc_buffer_empty(&sz->delay_buf))
848
 
                lirc_buffer_remove_1(&sz->delay_buf);
 
825
        lirc_buffer_clear(&sz->lirc_buf);
 
826
        lirc_buffer_clear(&sz->delay_buf);
849
827
 
850
828
        if (sz->in_use) {
851
829
                sz->flush_timer.expires = jiffies + HZ;
859
837
                if (usb_submit_urb(sz->urb_in)) {
860
838
#endif
861
839
                        dprintk("open result = -EIO error submitting urb",
862
 
                                sz->plugin.minor);
 
840
                                sz->driver.minor);
863
841
                        MOD_DEC_USE_COUNT;
864
842
                        return -EIO;
865
843
                }
869
847
#endif
870
848
 
871
849
#ifdef MODULE
872
 
 
873
850
/**
874
851
 *      usb_streamzap_init
875
852
 */
878
855
        int result;
879
856
 
880
857
        /* register this driver with the USB subsystem */
881
 
 
882
858
        result = usb_register(&streamzap_driver);
883
859
 
884
860
        if (result) {
896
872
 */
897
873
static void __exit usb_streamzap_exit(void)
898
874
{
899
 
        /* deregister this driver with the USB subsystem */
900
875
        usb_deregister(&streamzap_driver);
901
876
}
902
877
 
908
883
MODULE_DESCRIPTION(DRIVER_DESC);
909
884
MODULE_LICENSE("GPL");
910
885
 
911
 
module_param(debug, bool, 0644);
 
886
module_param(debug, bool, S_IRUGO | S_IWUSR);
912
887
MODULE_PARM_DESC(debug, "Enable debugging messages");
913
 
 
914
888
EXPORT_NO_SYMBOLS;
915
 
 
916
889
#endif /* MODULE */