2
* LIRC driver for Philips eHome USB Infrared Transceiver
3
* and the Microsoft MCE 2005 Remote Control
5
* (C) by Martin A. Blatter <martin_a_blatter@yahoo.com>
7
* Transmitter support and reception code cleanup.
8
* (C) by Daniel Melander <lirc@rajidae.se>
10
* Derived from ATI USB driver by Paul Miller and the original
11
* MCE USB driver by Dan Corti
13
* This driver will only work reliably with kernel version 2.6.10
14
* or higher, probably because of differences in USB device enumeration
15
* in the kernel code. Device initialization fails most of the time
16
* with earlier kernel versions.
18
**********************************************************************
20
* This program is free software; you can redistribute it and/or modify
21
* it under the terms of the GNU General Public License as published by
22
* the Free Software Foundation; either version 2 of the License, or
23
* (at your option) any later version.
25
* This program is distributed in the hope that it will be useful,
26
* but WITHOUT ANY WARRANTY; without even the implied warranty of
27
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28
* GNU General Public License for more details.
30
* You should have received a copy of the GNU General Public License
31
* along with this program; if not, write to the Free Software
32
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36
#include <linux/version.h>
37
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 5)
38
#error "*******************************************************"
39
#error "Sorry, this driver needs kernel version 2.6.5 or higher"
40
#error "*******************************************************"
42
#include <linux/autoconf.h>
43
#include <linux/kernel.h>
44
#include <linux/errno.h>
45
#include <linux/init.h>
46
#include <linux/slab.h>
47
#include <linux/module.h>
48
#include <linux/kmod.h>
49
#include <linux/smp_lock.h>
50
#include <linux/completion.h>
51
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
52
#include <asm/uaccess.h>
54
#include <linux/uaccess.h>
56
#include <linux/usb.h>
57
#include <linux/wait.h>
58
#include <linux/time.h>
61
#include "../kcompat.h"
62
#include "../lirc_dev/lirc_dev.h"
64
#define DRIVER_VERSION "$Revision: 1.81 $"
65
#define DRIVER_AUTHOR "Daniel Melander <lirc@rajidae.se>, " \
66
"Martin Blatter <martin_a_blatter@yahoo.com>"
67
#define DRIVER_DESC "Philips eHome USB IR Transceiver and Microsoft " \
68
"MCE 2005 Remote Control driver for LIRC"
69
#define DRIVER_NAME "lirc_mceusb2"
71
#define USB_BUFLEN 32 /* USB reception buffer length */
72
#define LIRCBUF_SIZE 256 /* LIRC work buffer length */
75
#define MCE_CMDBUF_SIZE 384 /* MCE Command buffer length */
76
#define MCE_TIME_UNIT 50 /* Approx 50us resolution */
77
#define MCE_CODE_LENGTH 5 /* Normal length of packet (with header) */
78
#define MCE_PACKET_SIZE 4 /* Normal length of packet (without header) */
79
#define MCE_PACKET_HEADER 0x84 /* Actual header format is 0x80 + num_bytes */
80
#define MCE_CONTROL_HEADER 0x9F /* MCE status header */
81
#define MCE_TX_HEADER_LENGTH 3 /* # of bytes in the initializing tx header */
82
#define MCE_MAX_CHANNELS 2 /* Two transmitters, hardware dependent? */
83
#define MCE_DEFAULT_TX_MASK 0x03 /* Val opts: TX1=0x01, TX2=0x02, ALL=0x03 */
84
#define MCE_PULSE_BIT 0x80 /* Pulse bit, MSB set == PULSE else SPACE */
85
#define MCE_PULSE_MASK 0x7F /* Pulse mask */
86
#define MCE_MAX_PULSE_LENGTH 0x7F /* Longest transmittable pulse symbol */
87
#define MCE_PACKET_LENGTH_MASK 0x7F /* Pulse mask */
90
/* module parameters */
91
#ifdef CONFIG_USB_DEBUG
96
#define dprintk(fmt, args...) \
99
printk(KERN_DEBUG fmt, ## args); \
102
/* general constants */
103
#define SEND_FLAG_IN_PROGRESS 1
104
#define SEND_FLAG_COMPLETE 2
105
#define RECV_FLAG_IN_PROGRESS 3
106
#define RECV_FLAG_COMPLETE 4
108
#define PHILUSB_INBOUND 1
109
#define PHILUSB_OUTBOUND 2
111
#define VENDOR_PHILIPS 0x0471
112
#define VENDOR_SMK 0x0609
113
#define VENDOR_TATUNG 0x1460
114
#define VENDOR_GATEWAY 0x107b
115
#define VENDOR_SHUTTLE 0x1308
116
#define VENDOR_SHUTTLE2 0x051c
117
#define VENDOR_MITSUMI 0x03ee
118
#define VENDOR_TOPSEED 0x1784
119
#define VENDOR_RICAVISION 0x179d
120
#define VENDOR_ITRON 0x195d
121
#define VENDOR_FIC 0x1509
122
#define VENDOR_LG 0x043e
123
#define VENDOR_MICROSOFT 0x045e
124
#define VENDOR_FORMOSA 0x147a
125
#define VENDOR_FINTEK 0x1934
126
#define VENDOR_PINNACLE 0x2304
127
#define VENDOR_ECS 0x1019
128
#define VENDOR_WISTRON 0x0fb8
129
#define VENDOR_COMPRO 0x185b
130
#define VENDOR_NORTHSTAR 0x04eb
132
static struct usb_device_id mceusb_dev_table[] = {
133
/* Philips Infrared Transceiver - Sahara branded */
134
{ USB_DEVICE(VENDOR_PHILIPS, 0x0608) },
135
/* Philips Infrared Transceiver - HP branded */
136
{ USB_DEVICE(VENDOR_PHILIPS, 0x060c) },
137
/* Philips SRM5100 */
138
{ USB_DEVICE(VENDOR_PHILIPS, 0x060d) },
139
/* Philips Infrared Transceiver - Omaura */
140
{ USB_DEVICE(VENDOR_PHILIPS, 0x060f) },
141
/* Philips Infrared Transceiver - Spinel plus */
142
{ USB_DEVICE(VENDOR_PHILIPS, 0x0613) },
143
/* Philips eHome Infrared Transceiver */
144
{ USB_DEVICE(VENDOR_PHILIPS, 0x0815) },
145
/* SMK/Toshiba G83C0004D410 */
146
{ USB_DEVICE(VENDOR_SMK, 0x031d) },
147
/* SMK eHome Infrared Transceiver (Sony VAIO) */
148
{ USB_DEVICE(VENDOR_SMK, 0x0322) },
149
/* bundled with Hauppauge PVR-150 */
150
{ USB_DEVICE(VENDOR_SMK, 0x0334) },
151
/* Tatung eHome Infrared Transceiver */
152
{ USB_DEVICE(VENDOR_TATUNG, 0x9150) },
153
/* Shuttle eHome Infrared Transceiver */
154
{ USB_DEVICE(VENDOR_SHUTTLE, 0xc001) },
155
/* Shuttle eHome Infrared Transceiver */
156
{ USB_DEVICE(VENDOR_SHUTTLE2, 0xc001) },
157
/* Gateway eHome Infrared Transceiver */
158
{ USB_DEVICE(VENDOR_GATEWAY, 0x3009) },
160
{ USB_DEVICE(VENDOR_MITSUMI, 0x2501) },
161
/* Topseed eHome Infrared Transceiver */
162
{ USB_DEVICE(VENDOR_TOPSEED, 0x0001) },
163
/* Topseed HP eHome Infrared Transceiver */
164
{ USB_DEVICE(VENDOR_TOPSEED, 0x0006) },
165
/* Topseed eHome Infrared Transceiver */
166
{ USB_DEVICE(VENDOR_TOPSEED, 0x0007) },
167
/* Topseed eHome Infrared Transceiver */
168
{ USB_DEVICE(VENDOR_TOPSEED, 0x0008) },
169
/* Ricavision internal Infrared Transceiver */
170
{ USB_DEVICE(VENDOR_RICAVISION, 0x0010) },
171
/* Itron ione Libra Q-11 */
172
{ USB_DEVICE(VENDOR_ITRON, 0x7002) },
173
/* FIC eHome Infrared Transceiver */
174
{ USB_DEVICE(VENDOR_FIC, 0x9242) },
175
/* LG eHome Infrared Transceiver */
176
{ USB_DEVICE(VENDOR_LG, 0x9803) },
177
/* Microsoft MCE Infrared Transceiver */
178
{ USB_DEVICE(VENDOR_MICROSOFT, 0x00a0) },
179
/* Formosa eHome Infrared Transceiver */
180
{ USB_DEVICE(VENDOR_FORMOSA, 0xe015) },
181
/* Formosa21 / eHome Infrared Receiver */
182
{ USB_DEVICE(VENDOR_FORMOSA, 0xe016) },
183
/* Formosa aim / Trust MCE Infrared Receiver */
184
{ USB_DEVICE(VENDOR_FORMOSA, 0xe017) },
185
/* Formosa Industrial Computing / Beanbag Emulation Device */
186
{ USB_DEVICE(VENDOR_FORMOSA, 0xe018) },
187
/* Fintek eHome Infrared Transceiver */
188
{ USB_DEVICE(VENDOR_FINTEK, 0x0602) },
189
/* Fintek eHome Infrared Transceiver (in the AOpen MP45) */
190
{ USB_DEVICE(VENDOR_FINTEK, 0x0702) },
191
/* Pinnacle Remote Kit */
192
{ USB_DEVICE(VENDOR_PINNACLE, 0x0225) },
193
/* Elitegroup Computer Systems IR */
194
{ USB_DEVICE(VENDOR_ECS, 0x0f38) },
195
/* Wistron Corp. eHome Infrared Receiver */
196
{ USB_DEVICE(VENDOR_WISTRON, 0x0002) },
198
{ USB_DEVICE(VENDOR_COMPRO, 0x3020) },
199
/* Northstar Systems eHome Infrared Transceiver */
200
{ USB_DEVICE(VENDOR_NORTHSTAR, 0xe004) },
201
/* Terminating entry */
205
static struct usb_device_id pinnacle_list[] = {
206
{ USB_DEVICE(VENDOR_PINNACLE, 0x0225) },
210
static struct usb_device_id transmitter_mask_list[] = {
211
{ USB_DEVICE(VENDOR_SMK, 0x031d) },
212
{ USB_DEVICE(VENDOR_SMK, 0x0322) },
213
{ USB_DEVICE(VENDOR_SMK, 0x0334) },
214
{ USB_DEVICE(VENDOR_TOPSEED, 0x0001) },
215
{ USB_DEVICE(VENDOR_TOPSEED, 0x0007) },
216
{ USB_DEVICE(VENDOR_TOPSEED, 0x0008) },
217
{ USB_DEVICE(VENDOR_PINNACLE, 0x0225) },
221
/* data structure for each usb transceiver */
225
struct usb_device *usbdev;
228
struct usb_endpoint_descriptor *usb_ep_in;
229
struct usb_endpoint_descriptor *usb_ep_out;
231
/* buffers and dma */
232
unsigned char *buf_in;
238
struct lirc_driver *d;
240
unsigned char is_pulse;
244
u32 transmitter_mask_inverted:1;
248
unsigned char transmitter_mask;
249
unsigned int carrier_freq;
251
/* handle sending (init strings) */
253
wait_queue_head_t wait_out;
259
static char init1[] = {0x00, 0xff, 0xaa, 0xff, 0x0b};
260
static char init2[] = {0xff, 0x18};
262
static char pin_init1[] = { 0x9f, 0x07};
263
static char pin_init2[] = { 0x9f, 0x13};
264
static char pin_init3[] = { 0x9f, 0x0d};
266
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11)
267
static unsigned long usecs_to_jiffies(const unsigned int u)
269
if (u > jiffies_to_usecs(MAX_JIFFY_OFFSET))
270
return MAX_JIFFY_OFFSET;
271
#if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
272
return (u + (USEC_PER_SEC / HZ) - 1) / (USEC_PER_SEC / HZ);
273
#elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC)
274
return u * (HZ / USEC_PER_SEC);
276
return (u * HZ + USEC_PER_SEC - 1) / USEC_PER_SEC;
280
static void mceusb_dev_printdata(struct mceusb2_dev *ir, char *buf, int len)
282
char codes[USB_BUFLEN*3 + 1];
288
for (i = 0; i < len && i < USB_BUFLEN; i++)
289
snprintf(codes+i*3, 4, "%02x ", buf[i] & 0xFF);
291
printk(KERN_INFO "" DRIVER_NAME "[%d]: data received %s (length=%d)\n",
292
ir->devnum, codes, len);
295
static void usb_async_callback(struct urb *urb, struct pt_regs *regs)
297
struct mceusb2_dev *ir;
305
len = urb->actual_length;
308
"[%d]: callback called (status=%d len=%d)\n",
309
ir->devnum, urb->status, len);
312
mceusb_dev_printdata(ir, urb->transfer_buffer, len);
318
/* request incoming or send outgoing usb packet - used to initialize remote */
319
static void request_packet_async(struct mceusb2_dev *ir,
320
struct usb_endpoint_descriptor *ep,
321
unsigned char *data, int size, int urb_type)
324
struct urb *async_urb;
325
unsigned char *async_buf;
328
async_urb = usb_alloc_urb(0, GFP_KERNEL);
329
if (likely(async_urb)) {
331
async_buf = kmalloc(size, GFP_KERNEL);
333
if (urb_type == PHILUSB_OUTBOUND) {
335
usb_fill_int_urb(async_urb, ir->usbdev,
336
usb_sndintpipe(ir->usbdev,
337
ep->bEndpointAddress),
340
(usb_complete_t) usb_async_callback,
343
memcpy(async_buf, data, size);
346
usb_fill_int_urb(async_urb, ir->usbdev,
347
usb_rcvintpipe(ir->usbdev,
348
ep->bEndpointAddress),
350
(usb_complete_t) usb_async_callback,
353
async_urb->transfer_flags = URB_ASYNC_UNLINK;
355
usb_free_urb(async_urb);
360
/* standard request */
361
async_urb = ir->urb_in;
362
ir->send_flags = RECV_FLAG_IN_PROGRESS;
364
dprintk(DRIVER_NAME "[%d]: receive request called (size=%#x)\n",
367
async_urb->transfer_buffer_length = size;
368
async_urb->dev = ir->usbdev;
370
res = usb_submit_urb(async_urb, GFP_ATOMIC);
372
dprintk(DRIVER_NAME "[%d]: receive request FAILED! (res=%d)\n",
376
dprintk(DRIVER_NAME "[%d]: receive request complete (res=%d)\n",
380
static int unregister_from_lirc(struct mceusb2_dev *ir)
382
struct lirc_driver *d = ir->d;
387
dprintk(DRIVER_NAME "[%d]: unregister from lirc called\n", devnum);
389
rtn = lirc_unregister_driver(d->minor);
391
printk(DRIVER_NAME "[%d]: error in lirc_unregister minor: %d\n"
392
"Trying again...\n", devnum, d->minor);
395
"[%d]: device is opened, will unregister"
396
" on close\n", devnum);
399
set_current_state(TASK_INTERRUPTIBLE);
400
schedule_timeout(HZ);
402
rtn = lirc_unregister_driver(d->minor);
404
printk(DRIVER_NAME "[%d]: lirc_unregister failed\n",
409
printk(DRIVER_NAME "[%d]: didn't free resources\n", devnum);
413
printk(DRIVER_NAME "[%d]: usb remote disconnected\n", devnum);
415
lirc_buffer_free(d->rbuf);
422
static int set_use_inc(void *data)
424
struct mceusb2_dev *ir = data;
427
printk(DRIVER_NAME "[?]: set_use_inc called with no context\n");
430
dprintk(DRIVER_NAME "[%d]: set use inc\n", ir->devnum);
433
if (!ir->flags.connected) {
436
ir->flags.connected = 1;
442
static void set_use_dec(void *data)
444
struct mceusb2_dev *ir = data;
447
printk(DRIVER_NAME "[?]: set_use_dec called with no context\n");
450
dprintk(DRIVER_NAME "[%d]: set use dec\n", ir->devnum);
452
if (ir->flags.connected) {
453
mutex_lock(&ir->lock);
454
ir->flags.connected = 0;
455
mutex_unlock(&ir->lock);
460
static void send_packet_to_lirc(struct mceusb2_dev *ir)
462
if (ir->lircdata != 0) {
463
lirc_buffer_write(ir->d->rbuf,
464
(unsigned char *) &ir->lircdata);
465
wake_up(&ir->d->rbuf->wait_poll);
470
static void mceusb_dev_recv(struct urb *urb, struct pt_regs *regs)
472
struct mceusb2_dev *ir;
473
int buf_len, packet_len;
481
urb->transfer_flags |= URB_ASYNC_UNLINK;
486
buf_len = urb->actual_length;
490
mceusb_dev_printdata(ir, urb->transfer_buffer, buf_len);
492
if (ir->send_flags == RECV_FLAG_IN_PROGRESS) {
493
ir->send_flags = SEND_FLAG_COMPLETE;
494
dprintk(DRIVER_NAME "[%d]: setup answer received %d bytes\n",
495
ir->devnum, buf_len);
498
switch (urb->status) {
501
for (i = 0; i < buf_len; i++) {
502
/* decode mce packets of the form (84),AA,BB,CC,DD */
503
if (ir->buf_in[i] >= 0x80 && ir->buf_in[i] <= 0x9e) {
505
/* decode packet data */
507
ir->buf_in[i] & MCE_PACKET_LENGTH_MASK;
509
j <= packet_len && (i+j < buf_len);
511
/* rising/falling flank */
515
send_packet_to_lirc(ir);
521
/* accumulate mce pulse/space values */
524
MCE_PULSE_MASK)*MCE_TIME_UNIT;
526
(ir->is_pulse ? PULSE_BIT : 0);
530
} else if (ir->buf_in[i] == MCE_CONTROL_HEADER) {
531
/* status header (0x9F) */
533
* A transmission containing one or
534
* more consecutive ir commands always
535
* ends with a GAP of 100ms followed by the
536
* sequence 0x9F 0x01 0x01 0x9F 0x15
541
Uncomment this if the last 100ms
542
"infinity"-space should be transmitted
543
to lirc directly instead of at the beginning
544
of the next transmission. Changes pulse/space order.
546
if (++i < buf_len && ir->buf_in[i]==0x01)
547
send_packet_to_lirc(ir);
551
/* end decode loop */
561
urb->transfer_flags |= URB_ASYNC_UNLINK;
570
usb_submit_urb(urb, GFP_ATOMIC);
574
static ssize_t lirc_write(struct file *file, const char *buf,
575
size_t n, loff_t *ppos)
577
int i, count = 0, cmdcount = 0;
578
struct mceusb2_dev *ir = NULL;
579
lirc_t wbuf[LIRCBUF_SIZE]; /* Workbuffer with values from lirc */
580
unsigned char cmdbuf[MCE_CMDBUF_SIZE]; /* MCE command buffer */
581
unsigned long signal_duration = 0; /* Singnal length in us */
582
struct timeval start_time, end_time;
584
do_gettimeofday(&start_time);
586
/* Retrieve lirc_driver data for the device */
587
ir = lirc_get_pdata(file);
588
if (!ir || !ir->usb_ep_out)
591
if (n % sizeof(lirc_t))
593
count = n / sizeof(lirc_t);
595
/* Check if command is within limits */
596
if (count > LIRCBUF_SIZE || count%2 == 0)
598
if (copy_from_user(wbuf, buf, n))
601
/* MCE tx init header */
602
cmdbuf[cmdcount++] = MCE_CONTROL_HEADER;
603
cmdbuf[cmdcount++] = 0x08;
604
cmdbuf[cmdcount++] = ir->transmitter_mask;
606
/* Generate mce packet data */
607
for (i = 0; (i < count) && (cmdcount < MCE_CMDBUF_SIZE); i++) {
608
signal_duration += wbuf[i];
609
wbuf[i] = wbuf[i] / MCE_TIME_UNIT;
611
do { /* loop to support long pulses/spaces > 127*50us=6.35ms */
613
/* Insert mce packet header every 4th entry */
614
if ((cmdcount < MCE_CMDBUF_SIZE) &&
615
(cmdcount - MCE_TX_HEADER_LENGTH) %
616
MCE_CODE_LENGTH == 0)
617
cmdbuf[cmdcount++] = MCE_PACKET_HEADER;
619
/* Insert mce packet data */
620
if (cmdcount < MCE_CMDBUF_SIZE)
622
(wbuf[i] < MCE_PULSE_BIT ?
623
wbuf[i] : MCE_MAX_PULSE_LENGTH) |
624
(i & 1 ? 0x00 : MCE_PULSE_BIT);
627
} while ((wbuf[i] > MCE_MAX_PULSE_LENGTH) &&
628
(wbuf[i] -= MCE_MAX_PULSE_LENGTH));
631
/* Fix packet length in last header */
632
cmdbuf[cmdcount - (cmdcount - MCE_TX_HEADER_LENGTH) % MCE_CODE_LENGTH] =
633
0x80 + (cmdcount - MCE_TX_HEADER_LENGTH) % MCE_CODE_LENGTH - 1;
635
/* Check if we have room for the empty packet at the end */
636
if (cmdcount >= MCE_CMDBUF_SIZE)
639
/* All mce commands end with an empty packet (0x80) */
640
cmdbuf[cmdcount++] = 0x80;
642
/* Transmit the command to the mce device */
643
request_packet_async(ir, ir->usb_ep_out, cmdbuf,
644
cmdcount, PHILUSB_OUTBOUND);
647
* The lircd gap calculation expects the write function to
648
* wait the time it takes for the ircommand to be sent before
651
do_gettimeofday(&end_time);
652
signal_duration -= (end_time.tv_usec - start_time.tv_usec) +
653
(end_time.tv_sec - start_time.tv_sec) * 1000000;
655
/* delay with the closest number of ticks */
656
set_current_state(TASK_INTERRUPTIBLE);
657
schedule_timeout(usecs_to_jiffies(signal_duration));
662
static void set_transmitter_mask(struct mceusb2_dev *ir, unsigned int mask)
664
if (ir->flags.transmitter_mask_inverted)
666
* The mask begins at 0x02 and has an inverted
669
ir->transmitter_mask =
670
(mask != 0x03 ? mask ^ 0x03 : mask) << 1;
672
ir->transmitter_mask = mask;
676
/* Sets the send carrier frequency */
677
static int set_send_carrier(struct mceusb2_dev *ir, int carrier)
680
int prescaler = 0, divisor = 0;
681
unsigned char cmdbuf[] = { 0x9F, 0x06, 0x01, 0x80 };
683
/* Carrier is changed */
684
if (ir->carrier_freq != carrier) {
687
ir->carrier_freq = carrier;
688
dprintk(DRIVER_NAME "[%d]: SET_CARRIER disabling "
689
"carrier modulation\n", ir->devnum);
690
request_packet_async(ir, ir->usb_ep_out,
691
cmdbuf, sizeof(cmdbuf),
696
for (prescaler = 0; prescaler < 4; ++prescaler) {
697
divisor = (clk >> (2 * prescaler)) / carrier;
698
if (divisor <= 0xFF) {
699
ir->carrier_freq = carrier;
700
cmdbuf[2] = prescaler;
702
dprintk(DRIVER_NAME "[%d]: SET_CARRIER "
703
"requesting %d Hz\n",
704
ir->devnum, carrier);
706
/* Transmit new carrier to mce device */
707
request_packet_async(ir, ir->usb_ep_out,
708
cmdbuf, sizeof(cmdbuf),
722
static int lirc_ioctl(struct inode *node, struct file *filep,
723
unsigned int cmd, unsigned long arg)
727
unsigned long lvalue;
728
struct mceusb2_dev *ir = NULL;
730
/* Retrieve lirc_driver data for the device */
731
ir = lirc_get_pdata(filep);
732
if (!ir || !ir->usb_ep_out)
737
case LIRC_SET_TRANSMITTER_MASK:
739
result = get_user(ivalue, (unsigned int *) arg);
743
case 0x01: /* Transmitter 1 => 0x04 */
744
case 0x02: /* Transmitter 2 => 0x02 */
745
case 0x03: /* Transmitter 1 & 2 => 0x06 */
746
set_transmitter_mask(ir, ivalue);
749
default: /* Unsupported transmitter mask */
750
return MCE_MAX_CHANNELS;
753
dprintk(DRIVER_NAME ": SET_TRANSMITTERS mask=%d\n", ivalue);
756
case LIRC_GET_SEND_MODE:
758
result = put_user(LIRC_SEND2MODE(LIRC_CAN_SEND_PULSE &
760
(unsigned long *) arg);
766
case LIRC_SET_SEND_MODE:
768
result = get_user(lvalue, (unsigned long *) arg);
772
if (lvalue != (LIRC_MODE_PULSE&LIRC_CAN_SEND_MASK))
776
case LIRC_SET_SEND_CARRIER:
778
result = get_user(ivalue, (unsigned int *) arg);
782
set_send_carrier(ir, ivalue);
792
static struct file_operations lirc_fops = {
793
.owner = THIS_MODULE,
799
static int mceusb_dev_probe(struct usb_interface *intf,
800
const struct usb_device_id *id)
802
struct usb_device *dev = interface_to_usbdev(intf);
803
struct usb_host_interface *idesc;
804
struct usb_endpoint_descriptor *ep = NULL;
805
struct usb_endpoint_descriptor *ep_in = NULL;
806
struct usb_endpoint_descriptor *ep_out = NULL;
807
struct usb_host_config *config;
808
struct mceusb2_dev *ir = NULL;
809
struct lirc_driver *driver = NULL;
810
struct lirc_buffer *rbuf = NULL;
811
int devnum, pipe, maxp;
814
char buf[63], name[128] = "";
818
dprintk(DRIVER_NAME ": usb probe called\n");
820
usb_reset_device(dev);
822
config = dev->actconfig;
824
idesc = intf->cur_altsetting;
826
is_pinnacle = usb_match_id(intf, pinnacle_list) ? 1 : 0;
828
/* step through the endpoints to find first bulk in and out endpoint */
829
for (i = 0; i < idesc->desc.bNumEndpoints; ++i) {
830
ep = &idesc->endpoint[i].desc;
833
&& ((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
835
&& (((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
836
== USB_ENDPOINT_XFER_BULK)
837
|| ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
838
== USB_ENDPOINT_XFER_INT))) {
840
dprintk(DRIVER_NAME ": acceptable inbound endpoint "
843
ep_in->bmAttributes = USB_ENDPOINT_XFER_INT;
846
* setting seems to 1 seem to cause issues with
847
* Pinnacle timing out on transfer.
849
ep_in->bInterval = ep->bInterval;
851
ep_in->bInterval = 1;
855
&& ((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
857
&& (((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
858
== USB_ENDPOINT_XFER_BULK)
859
|| ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
860
== USB_ENDPOINT_XFER_INT))) {
862
dprintk(DRIVER_NAME ": acceptable outbound endpoint "
865
ep_out->bmAttributes = USB_ENDPOINT_XFER_INT;
868
* setting seems to 1 seem to cause issues with
869
* Pinnacle timing out on transfer.
871
ep_out->bInterval = ep->bInterval;
873
ep_out->bInterval = 1;
876
if (ep_in == NULL || ep_out == NULL) {
877
dprintk(DRIVER_NAME ": inbound and/or "
878
"outbound endpoint not found\n");
882
devnum = dev->devnum;
883
pipe = usb_rcvintpipe(dev, ep_in->bEndpointAddress);
884
maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
887
ir = kzalloc(sizeof(struct mceusb2_dev), GFP_KERNEL);
890
goto mem_failure_switch;
893
driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL);
896
goto mem_failure_switch;
899
rbuf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
902
goto mem_failure_switch;
905
if (lirc_buffer_init(rbuf, sizeof(lirc_t), LIRCBUF_SIZE)) {
907
goto mem_failure_switch;
910
ir->buf_in = usb_buffer_alloc(dev, maxp, GFP_ATOMIC, &ir->dma_in);
913
goto mem_failure_switch;
916
ir->urb_in = usb_alloc_urb(0, GFP_KERNEL);
919
goto mem_failure_switch;
922
strcpy(driver->name, DRIVER_NAME " ");
924
driver->features = LIRC_CAN_SEND_PULSE |
925
LIRC_CAN_SET_TRANSMITTER_MASK |
927
LIRC_CAN_SET_SEND_CARRIER;
930
driver->set_use_inc = &set_use_inc;
931
driver->set_use_dec = &set_use_dec;
932
driver->code_length = sizeof(lirc_t) * 8;
933
driver->fops = &lirc_fops;
934
driver->dev = &intf->dev;
935
driver->owner = THIS_MODULE;
937
mutex_init(&ir->lock);
938
init_waitqueue_head(&ir->wait_out);
940
minor = lirc_register_driver(driver);
946
switch (mem_failure) {
948
usb_free_urb(ir->urb_in);
950
usb_buffer_free(dev, maxp, ir->buf_in, ir->dma_in);
952
lirc_buffer_free(rbuf);
960
printk(DRIVER_NAME "[%d]: out of memory (code=%d)\n",
961
devnum, mem_failure);
965
driver->minor = minor;
970
ir->flags.connected = 0;
971
ir->flags.pinnacle = is_pinnacle;
972
ir->flags.transmitter_mask_inverted =
973
usb_match_id(intf, transmitter_mask_list) ? 0 : 1;
975
ir->lircdata = PULSE_MASK;
978
/* ir->flags.transmitter_mask_inverted must be set */
979
set_transmitter_mask(ir, MCE_DEFAULT_TX_MASK);
980
/* Saving usb interface data for use by the transmitter routine */
981
ir->usb_ep_in = ep_in;
982
ir->usb_ep_out = ep_out;
984
if (dev->descriptor.iManufacturer
985
&& usb_string(dev, dev->descriptor.iManufacturer,
986
buf, sizeof(buf)) > 0)
987
strlcpy(name, buf, sizeof(name));
988
if (dev->descriptor.iProduct
989
&& usb_string(dev, dev->descriptor.iProduct,
990
buf, sizeof(buf)) > 0)
991
snprintf(name + strlen(name), sizeof(name) - strlen(name),
993
printk(DRIVER_NAME "[%d]: %s on usb%d:%d\n", devnum, name,
994
dev->bus->busnum, devnum);
997
usb_fill_int_urb(ir->urb_in, dev, pipe, ir->buf_in,
998
maxp, (usb_complete_t) mceusb_dev_recv, ir, ep_in->bInterval);
999
ir->urb_in->transfer_dma = ir->dma_in;
1000
ir->urb_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1002
/* initialize device */
1003
if (ir->flags.pinnacle) {
1007
* I have no idea why but this reset seems to be crucial to
1008
* getting the device to do outbound IO correctly - without
1009
* this the device seems to hang, ignoring all input - although
1010
* IR signals are correctly sent from the device, no input is
1011
* interpreted by the device and the host never does the
1012
* completion routine
1015
usbret = usb_reset_configuration(dev);
1016
printk(DRIVER_NAME "[%d]: usb reset config ret %x\n",
1020
* its possible we really should wait for a return
1021
* for each of these...
1023
request_packet_async(ir, ep_in, NULL, maxp, PHILUSB_INBOUND);
1024
request_packet_async(ir, ep_out, pin_init1, sizeof(pin_init1),
1026
request_packet_async(ir, ep_in, NULL, maxp, PHILUSB_INBOUND);
1027
request_packet_async(ir, ep_out, pin_init2, sizeof(pin_init2),
1029
request_packet_async(ir, ep_in, NULL, maxp, PHILUSB_INBOUND);
1030
request_packet_async(ir, ep_out, pin_init3, sizeof(pin_init3),
1032
/* if we don't issue the correct number of receives
1033
* (PHILUSB_INBOUND) for each outbound, then the first few ir
1034
* pulses will be interpreted by the usb_async_callback routine
1035
* - we should ensure we have the right amount OR less - as the
1036
* mceusb_dev_recv routine will handle the control packets OK -
1037
* they start with 0x9f - but the async callback doesn't handle
1040
request_packet_async(ir, ep_in, NULL, maxp, 0);
1042
request_packet_async(ir, ep_in, NULL, maxp, PHILUSB_INBOUND);
1043
request_packet_async(ir, ep_in, NULL, maxp, PHILUSB_INBOUND);
1044
request_packet_async(ir, ep_out, init1,
1045
sizeof(init1), PHILUSB_OUTBOUND);
1046
request_packet_async(ir, ep_in, NULL, maxp, PHILUSB_INBOUND);
1047
request_packet_async(ir, ep_out, init2,
1048
sizeof(init2), PHILUSB_OUTBOUND);
1049
request_packet_async(ir, ep_in, NULL, maxp, 0);
1052
usb_set_intfdata(intf, ir);
1058
static void mceusb_dev_disconnect(struct usb_interface *intf)
1060
struct usb_device *dev = interface_to_usbdev(intf);
1061
struct mceusb2_dev *ir = usb_get_intfdata(intf);
1063
usb_set_intfdata(intf, NULL);
1069
wake_up_all(&ir->wait_out);
1071
mutex_lock(&ir->lock);
1072
usb_kill_urb(ir->urb_in);
1073
usb_free_urb(ir->urb_in);
1074
usb_buffer_free(dev, ir->len_in, ir->buf_in, ir->dma_in);
1075
mutex_unlock(&ir->lock);
1077
unregister_from_lirc(ir);
1080
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
1081
static int mceusb_dev_suspend(struct usb_interface *intf, pm_message_t message)
1083
struct mceusb2_dev *ir = usb_get_intfdata(intf);
1084
printk(DRIVER_NAME "[%d]: suspend\n", ir->devnum);
1085
usb_kill_urb(ir->urb_in);
1089
static int mceusb_dev_resume(struct usb_interface *intf)
1091
struct mceusb2_dev *ir = usb_get_intfdata(intf);
1092
printk(DRIVER_NAME "[%d]: resume\n", ir->devnum);
1093
if (usb_submit_urb(ir->urb_in, GFP_ATOMIC))
1099
static struct usb_driver mceusb_dev_driver = {
1100
LIRC_THIS_MODULE(.owner = THIS_MODULE)
1101
.name = DRIVER_NAME,
1102
.probe = mceusb_dev_probe,
1103
.disconnect = mceusb_dev_disconnect,
1104
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
1105
.suspend = mceusb_dev_suspend,
1106
.resume = mceusb_dev_resume,
1108
.id_table = mceusb_dev_table
1111
static int __init mceusb_dev_init(void)
1115
printk(KERN_INFO "\n");
1116
printk(KERN_INFO DRIVER_NAME ": " DRIVER_DESC " " DRIVER_VERSION "\n");
1117
printk(KERN_INFO DRIVER_NAME ": " DRIVER_AUTHOR "\n");
1118
dprintk(DRIVER_NAME ": debug mode enabled\n");
1120
i = usb_register(&mceusb_dev_driver);
1122
printk(DRIVER_NAME ": usb register failed, result = %d\n", i);
1129
static void __exit mceusb_dev_exit(void)
1131
usb_deregister(&mceusb_dev_driver);
1134
module_init(mceusb_dev_init);
1135
module_exit(mceusb_dev_exit);
1137
MODULE_DESCRIPTION(DRIVER_DESC);
1138
MODULE_AUTHOR(DRIVER_AUTHOR);
1139
MODULE_LICENSE("GPL");
1140
MODULE_DEVICE_TABLE(usb, mceusb_dev_table);
1142
module_param(debug, bool, S_IRUGO | S_IWUSR);
1143
MODULE_PARM_DESC(debug, "Debug enabled or not");