blob: 2cf57e64a80b4f9aeb0815d2064b45ecbf12c5e5 [file] [log] [blame]
Jarod Wilson19770692010-07-26 20:32:49 -03001/*
2 * Streamzap Remote Control driver
3 *
4 * Copyright (c) 2005 Christoph Bartelmus <lirc@bartelmus.de>
Jarod Wilson8e9e6062010-08-03 01:07:04 -03005 * Copyright (c) 2010 Jarod Wilson <jarod@wilsonet.com>
Jarod Wilson19770692010-07-26 20:32:49 -03006 *
7 * This driver was based on the work of Greg Wickham and Adrian
8 * Dewhurst. It was substantially rewritten to support correct signal
9 * gaps and now maintains a delay buffer, which is used to present
10 * consistent timing behaviour to user space applications. Without the
11 * delay buffer an ugly hack would be required in lircd, which can
12 * cause sluggish signal decoding in certain situations.
13 *
Jarod Wilson8e9e6062010-08-03 01:07:04 -030014 * Ported to in-kernel ir-core interface by Jarod Wilson
15 *
Jarod Wilson19770692010-07-26 20:32:49 -030016 * This driver is based on the USB skeleton driver packaged with the
17 * kernel; copyright (C) 2001-2003 Greg Kroah-Hartman (greg@kroah.com)
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 */
33
Jarod Wilson8e9e6062010-08-03 01:07:04 -030034#include <linux/device.h>
Jarod Wilson19770692010-07-26 20:32:49 -030035#include <linux/module.h>
Jarod Wilson8e9e6062010-08-03 01:07:04 -030036#include <linux/slab.h>
Jarod Wilson19770692010-07-26 20:32:49 -030037#include <linux/usb.h>
Jarod Wilson8e9e6062010-08-03 01:07:04 -030038#include <linux/input.h>
39#include <media/ir-core.h>
Jarod Wilson19770692010-07-26 20:32:49 -030040
Jarod Wilson7a569f52010-08-07 13:31:40 -030041#define DRIVER_VERSION "1.61"
Jarod Wilson8e9e6062010-08-03 01:07:04 -030042#define DRIVER_NAME "streamzap"
Jarod Wilson19770692010-07-26 20:32:49 -030043#define DRIVER_DESC "Streamzap Remote Control driver"
44
Jarod Wilson8e9e6062010-08-03 01:07:04 -030045#ifdef CONFIG_USB_DEBUG
46static int debug = 1;
47#else
Jarod Wilson19770692010-07-26 20:32:49 -030048static int debug;
Jarod Wilson8e9e6062010-08-03 01:07:04 -030049#endif
Jarod Wilson19770692010-07-26 20:32:49 -030050
51#define USB_STREAMZAP_VENDOR_ID 0x0e9c
52#define USB_STREAMZAP_PRODUCT_ID 0x0000
53
Jarod Wilson19770692010-07-26 20:32:49 -030054/* table of devices that work with this driver */
55static struct usb_device_id streamzap_table[] = {
56 /* Streamzap Remote Control */
57 { USB_DEVICE(USB_STREAMZAP_VENDOR_ID, USB_STREAMZAP_PRODUCT_ID) },
58 /* Terminating entry */
59 { }
60};
61
62MODULE_DEVICE_TABLE(usb, streamzap_table);
63
64#define STREAMZAP_PULSE_MASK 0xf0
65#define STREAMZAP_SPACE_MASK 0x0f
66#define STREAMZAP_TIMEOUT 0xff
67#define STREAMZAP_RESOLUTION 256
68
69/* number of samples buffered */
Jarod Wilson8e9e6062010-08-03 01:07:04 -030070#define SZ_BUF_LEN 128
Jarod Wilson19770692010-07-26 20:32:49 -030071
Jarod Wilson7a569f52010-08-07 13:31:40 -030072/* from ir-rc5-sz-decoder.c */
73#ifdef CONFIG_IR_RC5_SZ_DECODER_MODULE
74#define load_rc5_sz_decode() request_module("ir-rc5-sz-decoder")
75#else
76#define load_rc5_sz_decode() 0
77#endif
78
Jarod Wilson19770692010-07-26 20:32:49 -030079enum StreamzapDecoderState {
80 PulseSpace,
81 FullPulse,
82 FullSpace,
83 IgnorePulse
84};
85
Jarod Wilson8e9e6062010-08-03 01:07:04 -030086/* structure to hold our device specific stuff */
87struct streamzap_ir {
88
89 /* ir-core */
90 struct ir_dev_props *props;
Jarod Wilson8e9e6062010-08-03 01:07:04 -030091
92 /* core device info */
93 struct device *dev;
94 struct input_dev *idev;
Jarod Wilson19770692010-07-26 20:32:49 -030095
96 /* usb */
Jarod Wilson8e9e6062010-08-03 01:07:04 -030097 struct usb_device *usbdev;
Jarod Wilson19770692010-07-26 20:32:49 -030098 struct usb_interface *interface;
Jarod Wilson8e9e6062010-08-03 01:07:04 -030099 struct usb_endpoint_descriptor *endpoint;
100 struct urb *urb_in;
Jarod Wilson19770692010-07-26 20:32:49 -0300101
102 /* buffer & dma */
103 unsigned char *buf_in;
104 dma_addr_t dma_in;
105 unsigned int buf_in_len;
106
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300107 /* track what state we're in */
108 enum StreamzapDecoderState decoder_state;
Jarod Wilson19770692010-07-26 20:32:49 -0300109 /* tracks whether we are currently receiving some signal */
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300110 bool idle;
Jarod Wilson19770692010-07-26 20:32:49 -0300111 /* sum of signal lengths received since signal start */
112 unsigned long sum;
113 /* start time of signal; necessary for gap tracking */
114 struct timeval signal_last;
115 struct timeval signal_start;
Jarod Wilson7a569f52010-08-07 13:31:40 -0300116 bool timeout_enabled;
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300117
118 char name[128];
119 char phys[64];
Jarod Wilson19770692010-07-26 20:32:49 -0300120};
121
122
123/* local function prototypes */
124static int streamzap_probe(struct usb_interface *interface,
125 const struct usb_device_id *id);
126static void streamzap_disconnect(struct usb_interface *interface);
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300127static void streamzap_callback(struct urb *urb);
Jarod Wilson19770692010-07-26 20:32:49 -0300128static int streamzap_suspend(struct usb_interface *intf, pm_message_t message);
129static int streamzap_resume(struct usb_interface *intf);
130
131/* usb specific object needed to register this driver with the usb subsystem */
Jarod Wilson19770692010-07-26 20:32:49 -0300132static struct usb_driver streamzap_driver = {
133 .name = DRIVER_NAME,
134 .probe = streamzap_probe,
135 .disconnect = streamzap_disconnect,
136 .suspend = streamzap_suspend,
137 .resume = streamzap_resume,
138 .id_table = streamzap_table,
139};
140
Jarod Wilson7a569f52010-08-07 13:31:40 -0300141static void sz_push(struct streamzap_ir *sz, struct ir_raw_event rawir)
Jarod Wilson19770692010-07-26 20:32:49 -0300142{
Jarod Wilson7a569f52010-08-07 13:31:40 -0300143 ir_raw_event_store(sz->idev, &rawir);
Jarod Wilson19770692010-07-26 20:32:49 -0300144}
145
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300146static void sz_push_full_pulse(struct streamzap_ir *sz,
147 unsigned char value)
Jarod Wilson19770692010-07-26 20:32:49 -0300148{
Jarod Wilson7a569f52010-08-07 13:31:40 -0300149 struct ir_raw_event rawir;
150
Jarod Wilson19770692010-07-26 20:32:49 -0300151 if (sz->idle) {
152 long deltv;
Jarod Wilson19770692010-07-26 20:32:49 -0300153
154 sz->signal_last = sz->signal_start;
155 do_gettimeofday(&sz->signal_start);
156
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300157 deltv = sz->signal_start.tv_sec - sz->signal_last.tv_sec;
Jarod Wilson7a569f52010-08-07 13:31:40 -0300158 rawir.pulse = false;
Jarod Wilson19770692010-07-26 20:32:49 -0300159 if (deltv > 15) {
160 /* really long time */
Jarod Wilson7a569f52010-08-07 13:31:40 -0300161 rawir.duration = IR_MAX_DURATION;
Jarod Wilson19770692010-07-26 20:32:49 -0300162 } else {
Jarod Wilson7a569f52010-08-07 13:31:40 -0300163 rawir.duration = (int)(deltv * 1000000 +
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300164 sz->signal_start.tv_usec -
165 sz->signal_last.tv_usec);
Jarod Wilson7a569f52010-08-07 13:31:40 -0300166 rawir.duration -= sz->sum;
167 rawir.duration *= 1000;
168 rawir.duration &= IR_MAX_DURATION;
Jarod Wilson19770692010-07-26 20:32:49 -0300169 }
Jarod Wilson7a569f52010-08-07 13:31:40 -0300170 dev_dbg(sz->dev, "ls %u\n", rawir.duration);
171 sz_push(sz, rawir);
Jarod Wilson19770692010-07-26 20:32:49 -0300172
Jarod Wilson7a569f52010-08-07 13:31:40 -0300173 sz->idle = false;
Jarod Wilson19770692010-07-26 20:32:49 -0300174 sz->sum = 0;
175 }
176
Jarod Wilson7a569f52010-08-07 13:31:40 -0300177 rawir.pulse = true;
178 rawir.duration = ((int) value) * STREAMZAP_RESOLUTION;
179 rawir.duration += STREAMZAP_RESOLUTION / 2;
180 sz->sum += rawir.duration;
181 rawir.duration *= 1000;
182 rawir.duration &= IR_MAX_DURATION;
183 dev_dbg(sz->dev, "p %u\n", rawir.duration);
184 sz_push(sz, rawir);
Jarod Wilson19770692010-07-26 20:32:49 -0300185}
186
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300187static void sz_push_half_pulse(struct streamzap_ir *sz,
188 unsigned char value)
Jarod Wilson19770692010-07-26 20:32:49 -0300189{
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300190 sz_push_full_pulse(sz, (value & STREAMZAP_PULSE_MASK) >> 4);
Jarod Wilson19770692010-07-26 20:32:49 -0300191}
192
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300193static void sz_push_full_space(struct streamzap_ir *sz,
194 unsigned char value)
Jarod Wilson19770692010-07-26 20:32:49 -0300195{
Jarod Wilson7a569f52010-08-07 13:31:40 -0300196 struct ir_raw_event rawir;
197
198 rawir.pulse = false;
199 rawir.duration = ((int) value) * STREAMZAP_RESOLUTION;
200 rawir.duration += STREAMZAP_RESOLUTION / 2;
201 sz->sum += rawir.duration;
202 rawir.duration *= 1000;
203 dev_dbg(sz->dev, "s %u\n", rawir.duration);
204 sz_push(sz, rawir);
Jarod Wilson19770692010-07-26 20:32:49 -0300205}
206
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300207static void sz_push_half_space(struct streamzap_ir *sz,
208 unsigned long value)
Jarod Wilson19770692010-07-26 20:32:49 -0300209{
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300210 sz_push_full_space(sz, value & STREAMZAP_SPACE_MASK);
Jarod Wilson19770692010-07-26 20:32:49 -0300211}
212
213/**
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300214 * streamzap_callback - usb IRQ handler callback
Jarod Wilson19770692010-07-26 20:32:49 -0300215 *
216 * This procedure is invoked on reception of data from
217 * the usb remote.
218 */
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300219static void streamzap_callback(struct urb *urb)
Jarod Wilson19770692010-07-26 20:32:49 -0300220{
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300221 struct streamzap_ir *sz;
222 unsigned int i;
223 int len;
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300224 static int timeout = (((STREAMZAP_TIMEOUT * STREAMZAP_RESOLUTION) &
225 IR_MAX_DURATION) | 0x03000000);
Jarod Wilson19770692010-07-26 20:32:49 -0300226
227 if (!urb)
228 return;
229
230 sz = urb->context;
231 len = urb->actual_length;
232
233 switch (urb->status) {
234 case -ECONNRESET:
235 case -ENOENT:
236 case -ESHUTDOWN:
237 /*
238 * this urb is terminated, clean up.
239 * sz might already be invalid at this point
240 */
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300241 dev_err(sz->dev, "urb terminated, status: %d\n", urb->status);
Jarod Wilson19770692010-07-26 20:32:49 -0300242 return;
243 default:
244 break;
245 }
246
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300247 dev_dbg(sz->dev, "%s: received urb, len %d\n", __func__, len);
Jarod Wilson7a569f52010-08-07 13:31:40 -0300248 for (i = 0; i < len; i++) {
249 dev_dbg(sz->dev, "sz idx %d: %x\n",
250 i, (unsigned char)sz->buf_in[i]);
251 switch (sz->decoder_state) {
252 case PulseSpace:
253 if ((sz->buf_in[i] & STREAMZAP_PULSE_MASK) ==
254 STREAMZAP_PULSE_MASK) {
255 sz->decoder_state = FullPulse;
256 continue;
257 } else if ((sz->buf_in[i] & STREAMZAP_SPACE_MASK)
258 == STREAMZAP_SPACE_MASK) {
259 sz_push_half_pulse(sz, sz->buf_in[i]);
260 sz->decoder_state = FullSpace;
261 continue;
262 } else {
263 sz_push_half_pulse(sz, sz->buf_in[i]);
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300264 sz_push_half_space(sz, sz->buf_in[i]);
Jarod Wilson19770692010-07-26 20:32:49 -0300265 }
Jarod Wilson7a569f52010-08-07 13:31:40 -0300266 break;
267 case FullPulse:
268 sz_push_full_pulse(sz, sz->buf_in[i]);
269 sz->decoder_state = IgnorePulse;
270 break;
271 case FullSpace:
272 if (sz->buf_in[i] == STREAMZAP_TIMEOUT) {
273 struct ir_raw_event rawir;
274
275 rawir.pulse = false;
276 rawir.duration = timeout * 1000;
277 sz->idle = true;
278 if (sz->timeout_enabled)
279 sz_push(sz, rawir);
280 ir_raw_event_handle(sz->idev);
281 } else {
282 sz_push_full_space(sz, sz->buf_in[i]);
283 }
284 sz->decoder_state = PulseSpace;
285 break;
286 case IgnorePulse:
287 if ((sz->buf_in[i] & STREAMZAP_SPACE_MASK) ==
288 STREAMZAP_SPACE_MASK) {
289 sz->decoder_state = FullSpace;
290 continue;
291 }
292 sz_push_half_space(sz, sz->buf_in[i]);
293 sz->decoder_state = PulseSpace;
294 break;
Jarod Wilson19770692010-07-26 20:32:49 -0300295 }
296 }
297
298 usb_submit_urb(urb, GFP_ATOMIC);
299
300 return;
301}
302
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300303static struct input_dev *streamzap_init_input_dev(struct streamzap_ir *sz)
304{
305 struct input_dev *idev;
306 struct ir_dev_props *props;
307 struct device *dev = sz->dev;
308 int ret;
Jarod Wilson19770692010-07-26 20:32:49 -0300309
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300310 idev = input_allocate_device();
311 if (!idev) {
312 dev_err(dev, "remote input dev allocation failed\n");
313 goto idev_alloc_failed;
314 }
315
316 props = kzalloc(sizeof(struct ir_dev_props), GFP_KERNEL);
317 if (!props) {
318 dev_err(dev, "remote ir dev props allocation failed\n");
319 goto props_alloc_failed;
320 }
321
322 snprintf(sz->name, sizeof(sz->name), "Streamzap PC Remote Infrared "
323 "Receiver (%04x:%04x)",
324 le16_to_cpu(sz->usbdev->descriptor.idVendor),
325 le16_to_cpu(sz->usbdev->descriptor.idProduct));
326
327 idev->name = sz->name;
328 usb_make_path(sz->usbdev, sz->phys, sizeof(sz->phys));
329 strlcat(sz->phys, "/input0", sizeof(sz->phys));
330 idev->phys = sz->phys;
331
332 props->priv = sz;
333 props->driver_type = RC_DRIVER_IR_RAW;
Jarod Wilson7a569f52010-08-07 13:31:40 -0300334 props->allowed_protos = IR_TYPE_ALL;
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300335
336 sz->props = props;
337
Jarod Wilson7a569f52010-08-07 13:31:40 -0300338 ret = ir_input_register(idev, RC_MAP_STREAMZAP, props, DRIVER_NAME);
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300339 if (ret < 0) {
340 dev_err(dev, "remote input device register failed\n");
341 goto irdev_failed;
342 }
343
344 return idev;
345
346irdev_failed:
347 kfree(props);
348props_alloc_failed:
349 input_free_device(idev);
350idev_alloc_failed:
351 return NULL;
352}
353
Jarod Wilson19770692010-07-26 20:32:49 -0300354/**
355 * streamzap_probe
356 *
357 * Called by usb-core to associated with a candidate device
358 * On any failure the return value is the ERROR
359 * On success return 0
360 */
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300361static int __devinit streamzap_probe(struct usb_interface *intf,
362 const struct usb_device_id *id)
Jarod Wilson19770692010-07-26 20:32:49 -0300363{
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300364 struct usb_device *usbdev = interface_to_usbdev(intf);
Jarod Wilson19770692010-07-26 20:32:49 -0300365 struct usb_host_interface *iface_host;
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300366 struct streamzap_ir *sz = NULL;
Jarod Wilson19770692010-07-26 20:32:49 -0300367 char buf[63], name[128] = "";
368 int retval = -ENOMEM;
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300369 int pipe, maxp;
Jarod Wilson19770692010-07-26 20:32:49 -0300370
371 /* Allocate space for device driver specific data */
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300372 sz = kzalloc(sizeof(struct streamzap_ir), GFP_KERNEL);
373 if (!sz)
Jarod Wilson19770692010-07-26 20:32:49 -0300374 return -ENOMEM;
375
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300376 sz->usbdev = usbdev;
377 sz->interface = intf;
Jarod Wilson19770692010-07-26 20:32:49 -0300378
379 /* Check to ensure endpoint information matches requirements */
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300380 iface_host = intf->cur_altsetting;
Jarod Wilson19770692010-07-26 20:32:49 -0300381
382 if (iface_host->desc.bNumEndpoints != 1) {
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300383 dev_err(&intf->dev, "%s: Unexpected desc.bNumEndpoints (%d)\n",
384 __func__, iface_host->desc.bNumEndpoints);
Jarod Wilson19770692010-07-26 20:32:49 -0300385 retval = -ENODEV;
386 goto free_sz;
387 }
388
389 sz->endpoint = &(iface_host->endpoint[0].desc);
390 if ((sz->endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
391 != USB_DIR_IN) {
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300392 dev_err(&intf->dev, "%s: endpoint doesn't match input device "
393 "02%02x\n", __func__, sz->endpoint->bEndpointAddress);
Jarod Wilson19770692010-07-26 20:32:49 -0300394 retval = -ENODEV;
395 goto free_sz;
396 }
397
398 if ((sz->endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
399 != USB_ENDPOINT_XFER_INT) {
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300400 dev_err(&intf->dev, "%s: endpoint attributes don't match xfer "
401 "02%02x\n", __func__, sz->endpoint->bmAttributes);
Jarod Wilson19770692010-07-26 20:32:49 -0300402 retval = -ENODEV;
403 goto free_sz;
404 }
405
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300406 pipe = usb_rcvintpipe(usbdev, sz->endpoint->bEndpointAddress);
407 maxp = usb_maxpacket(usbdev, pipe, usb_pipeout(pipe));
408
409 if (maxp == 0) {
410 dev_err(&intf->dev, "%s: endpoint Max Packet Size is 0!?!\n",
411 __func__);
Jarod Wilson19770692010-07-26 20:32:49 -0300412 retval = -ENODEV;
413 goto free_sz;
414 }
415
416 /* Allocate the USB buffer and IRQ URB */
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300417 sz->buf_in = usb_alloc_coherent(usbdev, maxp, GFP_ATOMIC, &sz->dma_in);
418 if (!sz->buf_in)
Jarod Wilson19770692010-07-26 20:32:49 -0300419 goto free_sz;
420
421 sz->urb_in = usb_alloc_urb(0, GFP_KERNEL);
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300422 if (!sz->urb_in)
423 goto free_buf_in;
Jarod Wilson19770692010-07-26 20:32:49 -0300424
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300425 sz->dev = &intf->dev;
426 sz->buf_in_len = maxp;
Jarod Wilson19770692010-07-26 20:32:49 -0300427
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300428 if (usbdev->descriptor.iManufacturer
429 && usb_string(usbdev, usbdev->descriptor.iManufacturer,
Jarod Wilson19770692010-07-26 20:32:49 -0300430 buf, sizeof(buf)) > 0)
431 strlcpy(name, buf, sizeof(name));
432
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300433 if (usbdev->descriptor.iProduct
434 && usb_string(usbdev, usbdev->descriptor.iProduct,
Jarod Wilson19770692010-07-26 20:32:49 -0300435 buf, sizeof(buf)) > 0)
436 snprintf(name + strlen(name), sizeof(name) - strlen(name),
437 " %s", buf);
438
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300439 sz->idev = streamzap_init_input_dev(sz);
440 if (!sz->idev)
441 goto input_dev_fail;
Jarod Wilson19770692010-07-26 20:32:49 -0300442
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300443 sz->idle = true;
444 sz->decoder_state = PulseSpace;
Jarod Wilson7a569f52010-08-07 13:31:40 -0300445 /* FIXME: don't yet have a way to set this */
446 sz->timeout_enabled = true;
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300447 #if 0
448 /* not yet supported, depends on patches from maxim */
449 /* see also: LIRC_GET_REC_RESOLUTION and LIRC_SET_REC_TIMEOUT */
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300450 sz->min_timeout = STREAMZAP_TIMEOUT * STREAMZAP_RESOLUTION * 1000;
451 sz->max_timeout = STREAMZAP_TIMEOUT * STREAMZAP_RESOLUTION * 1000;
452 #endif
Jarod Wilson19770692010-07-26 20:32:49 -0300453
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300454 do_gettimeofday(&sz->signal_start);
455
456 /* Complete final initialisations */
457 usb_fill_int_urb(sz->urb_in, usbdev, pipe, sz->buf_in,
458 maxp, (usb_complete_t)streamzap_callback,
459 sz, sz->endpoint->bInterval);
460 sz->urb_in->transfer_dma = sz->dma_in;
461 sz->urb_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
462
463 usb_set_intfdata(intf, sz);
464
Jarod Wilson7a569f52010-08-07 13:31:40 -0300465 if (usb_submit_urb(sz->urb_in, GFP_ATOMIC))
466 dev_err(sz->dev, "urb submit failed\n");
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300467
468 dev_info(sz->dev, "Registered %s on usb%d:%d\n", name,
469 usbdev->bus->busnum, usbdev->devnum);
Jarod Wilson19770692010-07-26 20:32:49 -0300470
Jarod Wilson7a569f52010-08-07 13:31:40 -0300471 /* Load the streamzap not-quite-rc5 decoder too */
472 load_rc5_sz_decode();
473
Jarod Wilson19770692010-07-26 20:32:49 -0300474 return 0;
475
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300476input_dev_fail:
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300477 usb_free_urb(sz->urb_in);
478free_buf_in:
479 usb_free_coherent(usbdev, maxp, sz->buf_in, sz->dma_in);
Jarod Wilson19770692010-07-26 20:32:49 -0300480free_sz:
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300481 kfree(sz);
Jarod Wilson19770692010-07-26 20:32:49 -0300482
483 return retval;
484}
485
Jarod Wilson19770692010-07-26 20:32:49 -0300486/**
487 * streamzap_disconnect
488 *
489 * Called by the usb core when the device is removed from the system.
490 *
491 * This routine guarantees that the driver will not submit any more urbs
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300492 * by clearing dev->usbdev. It is also supposed to terminate any currently
Jarod Wilson19770692010-07-26 20:32:49 -0300493 * active urbs. Unfortunately, usb_bulk_msg(), used in streamzap_read(),
494 * does not provide any way to do this.
495 */
496static void streamzap_disconnect(struct usb_interface *interface)
497{
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300498 struct streamzap_ir *sz = usb_get_intfdata(interface);
499 struct usb_device *usbdev = interface_to_usbdev(interface);
Jarod Wilson19770692010-07-26 20:32:49 -0300500
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300501 usb_set_intfdata(interface, NULL);
Jarod Wilson19770692010-07-26 20:32:49 -0300502
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300503 if (!sz)
504 return;
Jarod Wilson19770692010-07-26 20:32:49 -0300505
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300506 sz->usbdev = NULL;
507 ir_input_unregister(sz->idev);
508 usb_kill_urb(sz->urb_in);
Jarod Wilson19770692010-07-26 20:32:49 -0300509 usb_free_urb(sz->urb_in);
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300510 usb_free_coherent(usbdev, sz->buf_in_len, sz->buf_in, sz->dma_in);
Jarod Wilson19770692010-07-26 20:32:49 -0300511
Jarod Wilson19770692010-07-26 20:32:49 -0300512 kfree(sz);
Jarod Wilson19770692010-07-26 20:32:49 -0300513}
514
515static int streamzap_suspend(struct usb_interface *intf, pm_message_t message)
516{
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300517 struct streamzap_ir *sz = usb_get_intfdata(intf);
Jarod Wilson19770692010-07-26 20:32:49 -0300518
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300519 usb_kill_urb(sz->urb_in);
520
Jarod Wilson19770692010-07-26 20:32:49 -0300521 return 0;
522}
523
524static int streamzap_resume(struct usb_interface *intf)
525{
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300526 struct streamzap_ir *sz = usb_get_intfdata(intf);
Jarod Wilson19770692010-07-26 20:32:49 -0300527
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300528 if (usb_submit_urb(sz->urb_in, GFP_ATOMIC)) {
529 dev_err(sz->dev, "Error sumbiting urb\n");
530 return -EIO;
Jarod Wilson19770692010-07-26 20:32:49 -0300531 }
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300532
Jarod Wilson19770692010-07-26 20:32:49 -0300533 return 0;
534}
535
536/**
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300537 * streamzap_init
Jarod Wilson19770692010-07-26 20:32:49 -0300538 */
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300539static int __init streamzap_init(void)
Jarod Wilson19770692010-07-26 20:32:49 -0300540{
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300541 int ret;
Jarod Wilson19770692010-07-26 20:32:49 -0300542
543 /* register this driver with the USB subsystem */
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300544 ret = usb_register(&streamzap_driver);
545 if (ret < 0)
546 printk(KERN_ERR DRIVER_NAME ": usb register failed, "
547 "result = %d\n", ret);
Jarod Wilson19770692010-07-26 20:32:49 -0300548
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300549 return ret;
Jarod Wilson19770692010-07-26 20:32:49 -0300550}
551
552/**
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300553 * streamzap_exit
Jarod Wilson19770692010-07-26 20:32:49 -0300554 */
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300555static void __exit streamzap_exit(void)
Jarod Wilson19770692010-07-26 20:32:49 -0300556{
557 usb_deregister(&streamzap_driver);
558}
559
560
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300561module_init(streamzap_init);
562module_exit(streamzap_exit);
Jarod Wilson19770692010-07-26 20:32:49 -0300563
Jarod Wilson8e9e6062010-08-03 01:07:04 -0300564MODULE_AUTHOR("Jarod Wilson <jarod@wilsonet.com>");
Jarod Wilson19770692010-07-26 20:32:49 -0300565MODULE_DESCRIPTION(DRIVER_DESC);
566MODULE_LICENSE("GPL");
567
568module_param(debug, bool, S_IRUGO | S_IWUSR);
569MODULE_PARM_DESC(debug, "Enable debugging messages");