]>
Commit | Line | Data |
---|---|---|
19770693 JW |
1 | /* |
2 | * Streamzap Remote Control driver | |
3 | * | |
4 | * Copyright (c) 2005 Christoph Bartelmus <lirc@bartelmus.de> | |
8e9e6064 | 5 | * Copyright (c) 2010 Jarod Wilson <jarod@wilsonet.com> |
19770693 JW |
6 | * |
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 | * | |
8e9e6064 JW |
14 | * Ported to in-kernel ir-core interface by Jarod Wilson |
15 | * | |
19770693 JW |
16 | * 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 | ||
8e9e6064 | 34 | #include <linux/device.h> |
19770693 | 35 | #include <linux/module.h> |
8e9e6064 | 36 | #include <linux/slab.h> |
635f76b2 PB |
37 | #include <linux/usb.h> |
38 | #include <linux/usb/input.h> | |
6bda9644 | 39 | #include <media/rc-core.h> |
19770693 | 40 | |
7a569f52 | 41 | #define DRIVER_VERSION "1.61" |
8e9e6064 | 42 | #define DRIVER_NAME "streamzap" |
19770693 JW |
43 | #define DRIVER_DESC "Streamzap Remote Control driver" |
44 | ||
8e9e6064 JW |
45 | #ifdef CONFIG_USB_DEBUG |
46 | static int debug = 1; | |
47 | #else | |
19770693 | 48 | static int debug; |
8e9e6064 | 49 | #endif |
19770693 JW |
50 | |
51 | #define USB_STREAMZAP_VENDOR_ID 0x0e9c | |
52 | #define USB_STREAMZAP_PRODUCT_ID 0x0000 | |
53 | ||
19770693 JW |
54 | /* table of devices that work with this driver */ |
55 | static 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 | ||
62 | MODULE_DEVICE_TABLE(usb, streamzap_table); | |
63 | ||
b768d47e JW |
64 | #define SZ_PULSE_MASK 0xf0 |
65 | #define SZ_SPACE_MASK 0x0f | |
66 | #define SZ_TIMEOUT 0xff | |
67 | #define SZ_RESOLUTION 256 | |
19770693 JW |
68 | |
69 | /* number of samples buffered */ | |
8e9e6064 | 70 | #define SZ_BUF_LEN 128 |
19770693 | 71 | |
7a569f52 JW |
72 | /* 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 | |
0170f6bc | 76 | #define load_rc5_sz_decode() {} |
7a569f52 JW |
77 | #endif |
78 | ||
19770693 JW |
79 | enum StreamzapDecoderState { |
80 | PulseSpace, | |
81 | FullPulse, | |
82 | FullSpace, | |
83 | IgnorePulse | |
84 | }; | |
85 | ||
8e9e6064 JW |
86 | /* structure to hold our device specific stuff */ |
87 | struct streamzap_ir { | |
8e9e6064 | 88 | /* ir-core */ |
d8b4b582 | 89 | struct rc_dev *rdev; |
8e9e6064 JW |
90 | |
91 | /* core device info */ | |
92 | struct device *dev; | |
19770693 JW |
93 | |
94 | /* usb */ | |
8e9e6064 | 95 | struct usb_device *usbdev; |
19770693 | 96 | struct usb_interface *interface; |
8e9e6064 JW |
97 | struct usb_endpoint_descriptor *endpoint; |
98 | struct urb *urb_in; | |
19770693 JW |
99 | |
100 | /* buffer & dma */ | |
101 | unsigned char *buf_in; | |
102 | dma_addr_t dma_in; | |
103 | unsigned int buf_in_len; | |
104 | ||
8e9e6064 JW |
105 | /* track what state we're in */ |
106 | enum StreamzapDecoderState decoder_state; | |
19770693 | 107 | /* tracks whether we are currently receiving some signal */ |
8e9e6064 | 108 | bool idle; |
19770693 JW |
109 | /* sum of signal lengths received since signal start */ |
110 | unsigned long sum; | |
111 | /* start time of signal; necessary for gap tracking */ | |
112 | struct timeval signal_last; | |
113 | struct timeval signal_start; | |
7a569f52 | 114 | bool timeout_enabled; |
8e9e6064 JW |
115 | |
116 | char name[128]; | |
117 | char phys[64]; | |
19770693 JW |
118 | }; |
119 | ||
120 | ||
121 | /* local function prototypes */ | |
122 | static int streamzap_probe(struct usb_interface *interface, | |
123 | const struct usb_device_id *id); | |
124 | static void streamzap_disconnect(struct usb_interface *interface); | |
8e9e6064 | 125 | static void streamzap_callback(struct urb *urb); |
19770693 JW |
126 | static int streamzap_suspend(struct usb_interface *intf, pm_message_t message); |
127 | static int streamzap_resume(struct usb_interface *intf); | |
128 | ||
129 | /* usb specific object needed to register this driver with the usb subsystem */ | |
19770693 JW |
130 | static struct usb_driver streamzap_driver = { |
131 | .name = DRIVER_NAME, | |
132 | .probe = streamzap_probe, | |
133 | .disconnect = streamzap_disconnect, | |
134 | .suspend = streamzap_suspend, | |
135 | .resume = streamzap_resume, | |
136 | .id_table = streamzap_table, | |
137 | }; | |
138 | ||
7a569f52 | 139 | static void sz_push(struct streamzap_ir *sz, struct ir_raw_event rawir) |
19770693 | 140 | { |
1338c925 JW |
141 | dev_dbg(sz->dev, "Storing %s with duration %u us\n", |
142 | (rawir.pulse ? "pulse" : "space"), rawir.duration); | |
d8b4b582 | 143 | ir_raw_event_store_with_filter(sz->rdev, &rawir); |
19770693 JW |
144 | } |
145 | ||
8e9e6064 JW |
146 | static void sz_push_full_pulse(struct streamzap_ir *sz, |
147 | unsigned char value) | |
19770693 | 148 | { |
4651918a | 149 | DEFINE_IR_RAW_EVENT(rawir); |
7a569f52 | 150 | |
19770693 JW |
151 | if (sz->idle) { |
152 | long deltv; | |
19770693 JW |
153 | |
154 | sz->signal_last = sz->signal_start; | |
155 | do_gettimeofday(&sz->signal_start); | |
156 | ||
8e9e6064 | 157 | deltv = sz->signal_start.tv_sec - sz->signal_last.tv_sec; |
7a569f52 | 158 | rawir.pulse = false; |
19770693 JW |
159 | if (deltv > 15) { |
160 | /* really long time */ | |
7a569f52 | 161 | rawir.duration = IR_MAX_DURATION; |
19770693 | 162 | } else { |
7a569f52 | 163 | rawir.duration = (int)(deltv * 1000000 + |
8e9e6064 JW |
164 | sz->signal_start.tv_usec - |
165 | sz->signal_last.tv_usec); | |
7a569f52 | 166 | rawir.duration -= sz->sum; |
b4608fae | 167 | rawir.duration = US_TO_NS(rawir.duration); |
7a569f52 | 168 | rawir.duration &= IR_MAX_DURATION; |
19770693 | 169 | } |
7a569f52 | 170 | sz_push(sz, rawir); |
19770693 | 171 | |
7a569f52 | 172 | sz->idle = false; |
19770693 JW |
173 | sz->sum = 0; |
174 | } | |
175 | ||
7a569f52 | 176 | rawir.pulse = true; |
b768d47e JW |
177 | rawir.duration = ((int) value) * SZ_RESOLUTION; |
178 | rawir.duration += SZ_RESOLUTION / 2; | |
7a569f52 | 179 | sz->sum += rawir.duration; |
b4608fae | 180 | rawir.duration = US_TO_NS(rawir.duration); |
7a569f52 | 181 | rawir.duration &= IR_MAX_DURATION; |
7a569f52 | 182 | sz_push(sz, rawir); |
19770693 JW |
183 | } |
184 | ||
8e9e6064 JW |
185 | static void sz_push_half_pulse(struct streamzap_ir *sz, |
186 | unsigned char value) | |
19770693 | 187 | { |
b768d47e | 188 | sz_push_full_pulse(sz, (value & SZ_PULSE_MASK) >> 4); |
19770693 JW |
189 | } |
190 | ||
8e9e6064 JW |
191 | static void sz_push_full_space(struct streamzap_ir *sz, |
192 | unsigned char value) | |
19770693 | 193 | { |
4651918a | 194 | DEFINE_IR_RAW_EVENT(rawir); |
7a569f52 JW |
195 | |
196 | rawir.pulse = false; | |
b768d47e JW |
197 | rawir.duration = ((int) value) * SZ_RESOLUTION; |
198 | rawir.duration += SZ_RESOLUTION / 2; | |
7a569f52 | 199 | sz->sum += rawir.duration; |
b4608fae | 200 | rawir.duration = US_TO_NS(rawir.duration); |
7a569f52 | 201 | sz_push(sz, rawir); |
19770693 JW |
202 | } |
203 | ||
8e9e6064 JW |
204 | static void sz_push_half_space(struct streamzap_ir *sz, |
205 | unsigned long value) | |
19770693 | 206 | { |
b768d47e | 207 | sz_push_full_space(sz, value & SZ_SPACE_MASK); |
19770693 JW |
208 | } |
209 | ||
210 | /** | |
8e9e6064 | 211 | * streamzap_callback - usb IRQ handler callback |
19770693 JW |
212 | * |
213 | * This procedure is invoked on reception of data from | |
214 | * the usb remote. | |
215 | */ | |
8e9e6064 | 216 | static void streamzap_callback(struct urb *urb) |
19770693 | 217 | { |
8e9e6064 JW |
218 | struct streamzap_ir *sz; |
219 | unsigned int i; | |
220 | int len; | |
19770693 JW |
221 | |
222 | if (!urb) | |
223 | return; | |
224 | ||
225 | sz = urb->context; | |
226 | len = urb->actual_length; | |
227 | ||
228 | switch (urb->status) { | |
229 | case -ECONNRESET: | |
230 | case -ENOENT: | |
231 | case -ESHUTDOWN: | |
232 | /* | |
233 | * this urb is terminated, clean up. | |
234 | * sz might already be invalid at this point | |
235 | */ | |
8e9e6064 | 236 | dev_err(sz->dev, "urb terminated, status: %d\n", urb->status); |
19770693 JW |
237 | return; |
238 | default: | |
239 | break; | |
240 | } | |
241 | ||
8e9e6064 | 242 | dev_dbg(sz->dev, "%s: received urb, len %d\n", __func__, len); |
7a569f52 | 243 | for (i = 0; i < len; i++) { |
1338c925 | 244 | dev_dbg(sz->dev, "sz->buf_in[%d]: %x\n", |
7a569f52 JW |
245 | i, (unsigned char)sz->buf_in[i]); |
246 | switch (sz->decoder_state) { | |
247 | case PulseSpace: | |
b768d47e JW |
248 | if ((sz->buf_in[i] & SZ_PULSE_MASK) == |
249 | SZ_PULSE_MASK) { | |
7a569f52 JW |
250 | sz->decoder_state = FullPulse; |
251 | continue; | |
b768d47e JW |
252 | } else if ((sz->buf_in[i] & SZ_SPACE_MASK) |
253 | == SZ_SPACE_MASK) { | |
7a569f52 JW |
254 | sz_push_half_pulse(sz, sz->buf_in[i]); |
255 | sz->decoder_state = FullSpace; | |
256 | continue; | |
257 | } else { | |
258 | sz_push_half_pulse(sz, sz->buf_in[i]); | |
8e9e6064 | 259 | sz_push_half_space(sz, sz->buf_in[i]); |
19770693 | 260 | } |
7a569f52 JW |
261 | break; |
262 | case FullPulse: | |
263 | sz_push_full_pulse(sz, sz->buf_in[i]); | |
264 | sz->decoder_state = IgnorePulse; | |
265 | break; | |
266 | case FullSpace: | |
b768d47e | 267 | if (sz->buf_in[i] == SZ_TIMEOUT) { |
4651918a | 268 | DEFINE_IR_RAW_EVENT(rawir); |
7a569f52 JW |
269 | |
270 | rawir.pulse = false; | |
d8b4b582 | 271 | rawir.duration = sz->rdev->timeout; |
7a569f52 JW |
272 | sz->idle = true; |
273 | if (sz->timeout_enabled) | |
274 | sz_push(sz, rawir); | |
d8b4b582 | 275 | ir_raw_event_handle(sz->rdev); |
7a569f52 JW |
276 | } else { |
277 | sz_push_full_space(sz, sz->buf_in[i]); | |
278 | } | |
279 | sz->decoder_state = PulseSpace; | |
280 | break; | |
281 | case IgnorePulse: | |
b768d47e JW |
282 | if ((sz->buf_in[i] & SZ_SPACE_MASK) == |
283 | SZ_SPACE_MASK) { | |
7a569f52 JW |
284 | sz->decoder_state = FullSpace; |
285 | continue; | |
286 | } | |
287 | sz_push_half_space(sz, sz->buf_in[i]); | |
288 | sz->decoder_state = PulseSpace; | |
289 | break; | |
19770693 JW |
290 | } |
291 | } | |
292 | ||
293 | usb_submit_urb(urb, GFP_ATOMIC); | |
294 | ||
295 | return; | |
296 | } | |
297 | ||
d8b4b582 | 298 | static struct rc_dev *streamzap_init_rc_dev(struct streamzap_ir *sz) |
8e9e6064 | 299 | { |
d8b4b582 | 300 | struct rc_dev *rdev; |
8e9e6064 JW |
301 | struct device *dev = sz->dev; |
302 | int ret; | |
303 | ||
d8b4b582 DH |
304 | rdev = rc_allocate_device(); |
305 | if (!rdev) { | |
306 | dev_err(dev, "remote dev allocation failed\n"); | |
307 | goto out; | |
8e9e6064 JW |
308 | } |
309 | ||
310 | snprintf(sz->name, sizeof(sz->name), "Streamzap PC Remote Infrared " | |
311 | "Receiver (%04x:%04x)", | |
312 | le16_to_cpu(sz->usbdev->descriptor.idVendor), | |
313 | le16_to_cpu(sz->usbdev->descriptor.idProduct)); | |
8e9e6064 JW |
314 | usb_make_path(sz->usbdev, sz->phys, sizeof(sz->phys)); |
315 | strlcat(sz->phys, "/input0", sizeof(sz->phys)); | |
8e9e6064 | 316 | |
d8b4b582 DH |
317 | rdev->input_name = sz->name; |
318 | rdev->input_phys = sz->phys; | |
5ad1a555 PB |
319 | usb_to_input_id(sz->usbdev, &rdev->input_id); |
320 | rdev->dev.parent = dev; | |
d8b4b582 DH |
321 | rdev->priv = sz; |
322 | rdev->driver_type = RC_DRIVER_IR_RAW; | |
52b66144 | 323 | rdev->allowed_protos = RC_TYPE_ALL; |
d8b4b582 DH |
324 | rdev->driver_name = DRIVER_NAME; |
325 | rdev->map_name = RC_MAP_STREAMZAP; | |
635f76b2 | 326 | |
d8b4b582 | 327 | ret = rc_register_device(rdev); |
8e9e6064 JW |
328 | if (ret < 0) { |
329 | dev_err(dev, "remote input device register failed\n"); | |
d8b4b582 | 330 | goto out; |
8e9e6064 JW |
331 | } |
332 | ||
d8b4b582 | 333 | return rdev; |
8e9e6064 | 334 | |
d8b4b582 DH |
335 | out: |
336 | rc_free_device(rdev); | |
8e9e6064 JW |
337 | return NULL; |
338 | } | |
339 | ||
19770693 JW |
340 | /** |
341 | * streamzap_probe | |
342 | * | |
343 | * Called by usb-core to associated with a candidate device | |
344 | * On any failure the return value is the ERROR | |
345 | * On success return 0 | |
346 | */ | |
8e9e6064 JW |
347 | static int __devinit streamzap_probe(struct usb_interface *intf, |
348 | const struct usb_device_id *id) | |
19770693 | 349 | { |
8e9e6064 | 350 | struct usb_device *usbdev = interface_to_usbdev(intf); |
19770693 | 351 | struct usb_host_interface *iface_host; |
8e9e6064 | 352 | struct streamzap_ir *sz = NULL; |
19770693 JW |
353 | char buf[63], name[128] = ""; |
354 | int retval = -ENOMEM; | |
8e9e6064 | 355 | int pipe, maxp; |
19770693 JW |
356 | |
357 | /* Allocate space for device driver specific data */ | |
8e9e6064 JW |
358 | sz = kzalloc(sizeof(struct streamzap_ir), GFP_KERNEL); |
359 | if (!sz) | |
19770693 JW |
360 | return -ENOMEM; |
361 | ||
8e9e6064 JW |
362 | sz->usbdev = usbdev; |
363 | sz->interface = intf; | |
19770693 JW |
364 | |
365 | /* Check to ensure endpoint information matches requirements */ | |
8e9e6064 | 366 | iface_host = intf->cur_altsetting; |
19770693 JW |
367 | |
368 | if (iface_host->desc.bNumEndpoints != 1) { | |
8e9e6064 JW |
369 | dev_err(&intf->dev, "%s: Unexpected desc.bNumEndpoints (%d)\n", |
370 | __func__, iface_host->desc.bNumEndpoints); | |
19770693 JW |
371 | retval = -ENODEV; |
372 | goto free_sz; | |
373 | } | |
374 | ||
375 | sz->endpoint = &(iface_host->endpoint[0].desc); | |
376 | if ((sz->endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) | |
377 | != USB_DIR_IN) { | |
8e9e6064 JW |
378 | dev_err(&intf->dev, "%s: endpoint doesn't match input device " |
379 | "02%02x\n", __func__, sz->endpoint->bEndpointAddress); | |
19770693 JW |
380 | retval = -ENODEV; |
381 | goto free_sz; | |
382 | } | |
383 | ||
384 | if ((sz->endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) | |
385 | != USB_ENDPOINT_XFER_INT) { | |
8e9e6064 JW |
386 | dev_err(&intf->dev, "%s: endpoint attributes don't match xfer " |
387 | "02%02x\n", __func__, sz->endpoint->bmAttributes); | |
19770693 JW |
388 | retval = -ENODEV; |
389 | goto free_sz; | |
390 | } | |
391 | ||
8e9e6064 JW |
392 | pipe = usb_rcvintpipe(usbdev, sz->endpoint->bEndpointAddress); |
393 | maxp = usb_maxpacket(usbdev, pipe, usb_pipeout(pipe)); | |
394 | ||
395 | if (maxp == 0) { | |
396 | dev_err(&intf->dev, "%s: endpoint Max Packet Size is 0!?!\n", | |
397 | __func__); | |
19770693 JW |
398 | retval = -ENODEV; |
399 | goto free_sz; | |
400 | } | |
401 | ||
402 | /* Allocate the USB buffer and IRQ URB */ | |
8e9e6064 JW |
403 | sz->buf_in = usb_alloc_coherent(usbdev, maxp, GFP_ATOMIC, &sz->dma_in); |
404 | if (!sz->buf_in) | |
19770693 JW |
405 | goto free_sz; |
406 | ||
407 | sz->urb_in = usb_alloc_urb(0, GFP_KERNEL); | |
8e9e6064 JW |
408 | if (!sz->urb_in) |
409 | goto free_buf_in; | |
19770693 | 410 | |
8e9e6064 JW |
411 | sz->dev = &intf->dev; |
412 | sz->buf_in_len = maxp; | |
19770693 | 413 | |
8e9e6064 JW |
414 | if (usbdev->descriptor.iManufacturer |
415 | && usb_string(usbdev, usbdev->descriptor.iManufacturer, | |
19770693 JW |
416 | buf, sizeof(buf)) > 0) |
417 | strlcpy(name, buf, sizeof(name)); | |
418 | ||
8e9e6064 JW |
419 | if (usbdev->descriptor.iProduct |
420 | && usb_string(usbdev, usbdev->descriptor.iProduct, | |
19770693 JW |
421 | buf, sizeof(buf)) > 0) |
422 | snprintf(name + strlen(name), sizeof(name) - strlen(name), | |
423 | " %s", buf); | |
424 | ||
d8b4b582 DH |
425 | sz->rdev = streamzap_init_rc_dev(sz); |
426 | if (!sz->rdev) | |
427 | goto rc_dev_fail; | |
19770693 | 428 | |
8e9e6064 JW |
429 | sz->idle = true; |
430 | sz->decoder_state = PulseSpace; | |
7a569f52 JW |
431 | /* FIXME: don't yet have a way to set this */ |
432 | sz->timeout_enabled = true; | |
b4608fae | 433 | sz->rdev->timeout = ((US_TO_NS(SZ_TIMEOUT * SZ_RESOLUTION) & |
1338c925 | 434 | IR_MAX_DURATION) | 0x03000000); |
8e9e6064 JW |
435 | #if 0 |
436 | /* not yet supported, depends on patches from maxim */ | |
437 | /* see also: LIRC_GET_REC_RESOLUTION and LIRC_SET_REC_TIMEOUT */ | |
b4608fae JW |
438 | sz->min_timeout = US_TO_NS(SZ_TIMEOUT * SZ_RESOLUTION); |
439 | sz->max_timeout = US_TO_NS(SZ_TIMEOUT * SZ_RESOLUTION); | |
8e9e6064 | 440 | #endif |
19770693 | 441 | |
8e9e6064 | 442 | do_gettimeofday(&sz->signal_start); |
19770693 | 443 | |
8e9e6064 JW |
444 | /* Complete final initialisations */ |
445 | usb_fill_int_urb(sz->urb_in, usbdev, pipe, sz->buf_in, | |
446 | maxp, (usb_complete_t)streamzap_callback, | |
447 | sz, sz->endpoint->bInterval); | |
448 | sz->urb_in->transfer_dma = sz->dma_in; | |
449 | sz->urb_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | |
19770693 | 450 | |
8e9e6064 | 451 | usb_set_intfdata(intf, sz); |
19770693 | 452 | |
7a569f52 JW |
453 | if (usb_submit_urb(sz->urb_in, GFP_ATOMIC)) |
454 | dev_err(sz->dev, "urb submit failed\n"); | |
19770693 | 455 | |
8e9e6064 JW |
456 | dev_info(sz->dev, "Registered %s on usb%d:%d\n", name, |
457 | usbdev->bus->busnum, usbdev->devnum); | |
19770693 | 458 | |
7a569f52 JW |
459 | /* Load the streamzap not-quite-rc5 decoder too */ |
460 | load_rc5_sz_decode(); | |
461 | ||
8e9e6064 | 462 | return 0; |
19770693 | 463 | |
d8b4b582 | 464 | rc_dev_fail: |
8e9e6064 JW |
465 | usb_free_urb(sz->urb_in); |
466 | free_buf_in: | |
467 | usb_free_coherent(usbdev, maxp, sz->buf_in, sz->dma_in); | |
468 | free_sz: | |
469 | kfree(sz); | |
19770693 | 470 | |
8e9e6064 | 471 | return retval; |
19770693 JW |
472 | } |
473 | ||
474 | /** | |
475 | * streamzap_disconnect | |
476 | * | |
477 | * Called by the usb core when the device is removed from the system. | |
478 | * | |
479 | * This routine guarantees that the driver will not submit any more urbs | |
8e9e6064 | 480 | * by clearing dev->usbdev. It is also supposed to terminate any currently |
19770693 JW |
481 | * active urbs. Unfortunately, usb_bulk_msg(), used in streamzap_read(), |
482 | * does not provide any way to do this. | |
483 | */ | |
484 | static void streamzap_disconnect(struct usb_interface *interface) | |
485 | { | |
8e9e6064 JW |
486 | struct streamzap_ir *sz = usb_get_intfdata(interface); |
487 | struct usb_device *usbdev = interface_to_usbdev(interface); | |
19770693 | 488 | |
8e9e6064 | 489 | usb_set_intfdata(interface, NULL); |
19770693 | 490 | |
8e9e6064 JW |
491 | if (!sz) |
492 | return; | |
19770693 | 493 | |
8e9e6064 | 494 | sz->usbdev = NULL; |
d8b4b582 | 495 | rc_unregister_device(sz->rdev); |
8e9e6064 | 496 | usb_kill_urb(sz->urb_in); |
19770693 | 497 | usb_free_urb(sz->urb_in); |
8e9e6064 | 498 | usb_free_coherent(usbdev, sz->buf_in_len, sz->buf_in, sz->dma_in); |
19770693 | 499 | |
19770693 | 500 | kfree(sz); |
19770693 JW |
501 | } |
502 | ||
503 | static int streamzap_suspend(struct usb_interface *intf, pm_message_t message) | |
504 | { | |
8e9e6064 | 505 | struct streamzap_ir *sz = usb_get_intfdata(intf); |
19770693 | 506 | |
8e9e6064 | 507 | usb_kill_urb(sz->urb_in); |
19770693 | 508 | |
19770693 JW |
509 | return 0; |
510 | } | |
511 | ||
512 | static int streamzap_resume(struct usb_interface *intf) | |
513 | { | |
8e9e6064 | 514 | struct streamzap_ir *sz = usb_get_intfdata(intf); |
19770693 | 515 | |
8e9e6064 JW |
516 | if (usb_submit_urb(sz->urb_in, GFP_ATOMIC)) { |
517 | dev_err(sz->dev, "Error sumbiting urb\n"); | |
518 | return -EIO; | |
19770693 | 519 | } |
8e9e6064 | 520 | |
19770693 JW |
521 | return 0; |
522 | } | |
523 | ||
524 | /** | |
8e9e6064 | 525 | * streamzap_init |
19770693 | 526 | */ |
8e9e6064 | 527 | static int __init streamzap_init(void) |
19770693 | 528 | { |
8e9e6064 | 529 | int ret; |
19770693 JW |
530 | |
531 | /* register this driver with the USB subsystem */ | |
8e9e6064 JW |
532 | ret = usb_register(&streamzap_driver); |
533 | if (ret < 0) | |
534 | printk(KERN_ERR DRIVER_NAME ": usb register failed, " | |
535 | "result = %d\n", ret); | |
19770693 | 536 | |
8e9e6064 | 537 | return ret; |
19770693 JW |
538 | } |
539 | ||
540 | /** | |
8e9e6064 | 541 | * streamzap_exit |
19770693 | 542 | */ |
8e9e6064 | 543 | static void __exit streamzap_exit(void) |
19770693 JW |
544 | { |
545 | usb_deregister(&streamzap_driver); | |
546 | } | |
547 | ||
548 | ||
8e9e6064 JW |
549 | module_init(streamzap_init); |
550 | module_exit(streamzap_exit); | |
19770693 | 551 | |
8e9e6064 | 552 | MODULE_AUTHOR("Jarod Wilson <jarod@wilsonet.com>"); |
19770693 JW |
553 | MODULE_DESCRIPTION(DRIVER_DESC); |
554 | MODULE_LICENSE("GPL"); | |
555 | ||
556 | module_param(debug, bool, S_IRUGO | S_IWUSR); | |
557 | MODULE_PARM_DESC(debug, "Enable debugging messages"); |