aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/cyberjack.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/serial/cyberjack.c')
-rw-r--r--drivers/usb/serial/cyberjack.c112
1 files changed, 55 insertions, 57 deletions
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index 8d9b045aa7e8..c164e2cf2752 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -90,9 +90,6 @@ static struct usb_serial_driver cyberjack_device = {
90 .description = "Reiner SCT Cyberjack USB card reader", 90 .description = "Reiner SCT Cyberjack USB card reader",
91 .usb_driver = &cyberjack_driver, 91 .usb_driver = &cyberjack_driver,
92 .id_table = id_table, 92 .id_table = id_table,
93 .num_interrupt_in = 1,
94 .num_bulk_in = 1,
95 .num_bulk_out = 1,
96 .num_ports = 1, 93 .num_ports = 1,
97 .attach = cyberjack_startup, 94 .attach = cyberjack_startup,
98 .shutdown = cyberjack_shutdown, 95 .shutdown = cyberjack_shutdown,
@@ -119,7 +116,7 @@ static int cyberjack_startup (struct usb_serial *serial)
119 struct cyberjack_private *priv; 116 struct cyberjack_private *priv;
120 int i; 117 int i;
121 118
122 dbg("%s", __FUNCTION__); 119 dbg("%s", __func__);
123 120
124 /* allocate the private data structure */ 121 /* allocate the private data structure */
125 priv = kmalloc(sizeof(struct cyberjack_private), GFP_KERNEL); 122 priv = kmalloc(sizeof(struct cyberjack_private), GFP_KERNEL);
@@ -142,7 +139,7 @@ static int cyberjack_startup (struct usb_serial *serial)
142 GFP_KERNEL); 139 GFP_KERNEL);
143 if (result) 140 if (result)
144 err(" usb_submit_urb(read int) failed"); 141 err(" usb_submit_urb(read int) failed");
145 dbg("%s - usb_submit_urb(int urb)", __FUNCTION__); 142 dbg("%s - usb_submit_urb(int urb)", __func__);
146 } 143 }
147 144
148 return( 0 ); 145 return( 0 );
@@ -152,9 +149,9 @@ static void cyberjack_shutdown (struct usb_serial *serial)
152{ 149{
153 int i; 150 int i;
154 151
155 dbg("%s", __FUNCTION__); 152 dbg("%s", __func__);
156 153
157 for (i=0; i < serial->num_ports; ++i) { 154 for (i = 0; i < serial->num_ports; ++i) {
158 usb_kill_urb(serial->port[i]->interrupt_in_urb); 155 usb_kill_urb(serial->port[i]->interrupt_in_urb);
159 /* My special items, the standard routines free my urbs */ 156 /* My special items, the standard routines free my urbs */
160 kfree(usb_get_serial_port_data(serial->port[i])); 157 kfree(usb_get_serial_port_data(serial->port[i]));
@@ -168,9 +165,9 @@ static int cyberjack_open (struct usb_serial_port *port, struct file *filp)
168 unsigned long flags; 165 unsigned long flags;
169 int result = 0; 166 int result = 0;
170 167
171 dbg("%s - port %d", __FUNCTION__, port->number); 168 dbg("%s - port %d", __func__, port->number);
172 169
173 dbg("%s - usb_clear_halt", __FUNCTION__ ); 170 dbg("%s - usb_clear_halt", __func__ );
174 usb_clear_halt(port->serial->dev, port->write_urb->pipe); 171 usb_clear_halt(port->serial->dev, port->write_urb->pipe);
175 172
176 /* force low_latency on so that our tty_push actually forces 173 /* force low_latency on so that our tty_push actually forces
@@ -191,7 +188,7 @@ static int cyberjack_open (struct usb_serial_port *port, struct file *filp)
191 188
192static void cyberjack_close (struct usb_serial_port *port, struct file *filp) 189static void cyberjack_close (struct usb_serial_port *port, struct file *filp)
193{ 190{
194 dbg("%s - port %d", __FUNCTION__, port->number); 191 dbg("%s - port %d", __func__, port->number);
195 192
196 if (port->serial->dev) { 193 if (port->serial->dev) {
197 /* shutdown any bulk reads that might be going on */ 194 /* shutdown any bulk reads that might be going on */
@@ -208,17 +205,17 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
208 int result; 205 int result;
209 int wrexpected; 206 int wrexpected;
210 207
211 dbg("%s - port %d", __FUNCTION__, port->number); 208 dbg("%s - port %d", __func__, port->number);
212 209
213 if (count == 0) { 210 if (count == 0) {
214 dbg("%s - write request of 0 bytes", __FUNCTION__); 211 dbg("%s - write request of 0 bytes", __func__);
215 return (0); 212 return 0;
216 } 213 }
217 214
218 spin_lock_bh(&port->lock); 215 spin_lock_bh(&port->lock);
219 if (port->write_urb_busy) { 216 if (port->write_urb_busy) {
220 spin_unlock_bh(&port->lock); 217 spin_unlock_bh(&port->lock);
221 dbg("%s - already writing", __FUNCTION__); 218 dbg("%s - already writing", __func__);
222 return 0; 219 return 0;
223 } 220 }
224 port->write_urb_busy = 1; 221 port->write_urb_busy = 1;
@@ -226,24 +223,24 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
226 223
227 spin_lock_irqsave(&priv->lock, flags); 224 spin_lock_irqsave(&priv->lock, flags);
228 225
229 if( (count+priv->wrfilled)>sizeof(priv->wrbuf) ) { 226 if( (count+priv->wrfilled) > sizeof(priv->wrbuf) ) {
230 /* To much data for buffer. Reset buffer. */ 227 /* To much data for buffer. Reset buffer. */
231 priv->wrfilled=0; 228 priv->wrfilled = 0;
232 spin_unlock_irqrestore(&priv->lock, flags);
233 port->write_urb_busy = 0; 229 port->write_urb_busy = 0;
234 return (0); 230 spin_unlock_irqrestore(&priv->lock, flags);
231 return 0;
235 } 232 }
236 233
237 /* Copy data */ 234 /* Copy data */
238 memcpy (priv->wrbuf+priv->wrfilled, buf, count); 235 memcpy (priv->wrbuf+priv->wrfilled, buf, count);
239 236
240 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, 237 usb_serial_debug_data(debug, &port->dev, __func__, count,
241 priv->wrbuf+priv->wrfilled); 238 priv->wrbuf+priv->wrfilled);
242 priv->wrfilled += count; 239 priv->wrfilled += count;
243 240
244 if( priv->wrfilled >= 3 ) { 241 if( priv->wrfilled >= 3 ) {
245 wrexpected = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3; 242 wrexpected = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3;
246 dbg("%s - expected data: %d", __FUNCTION__, wrexpected); 243 dbg("%s - expected data: %d", __func__, wrexpected);
247 } else { 244 } else {
248 wrexpected = sizeof(priv->wrbuf); 245 wrexpected = sizeof(priv->wrbuf);
249 } 246 }
@@ -252,7 +249,7 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
252 /* We have enough data to begin transmission */ 249 /* We have enough data to begin transmission */
253 int length; 250 int length;
254 251
255 dbg("%s - transmitting data (frame 1)", __FUNCTION__); 252 dbg("%s - transmitting data (frame 1)", __func__);
256 length = (wrexpected > port->bulk_out_size) ? port->bulk_out_size : wrexpected; 253 length = (wrexpected > port->bulk_out_size) ? port->bulk_out_size : wrexpected;
257 254
258 memcpy (port->write_urb->transfer_buffer, priv->wrbuf, length ); 255 memcpy (port->write_urb->transfer_buffer, priv->wrbuf, length );
@@ -270,23 +267,23 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
270 /* send the data out the bulk port */ 267 /* send the data out the bulk port */
271 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 268 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
272 if (result) { 269 if (result) {
273 err("%s - failed submitting write urb, error %d", __FUNCTION__, result); 270 err("%s - failed submitting write urb, error %d", __func__, result);
274 /* Throw away data. No better idea what to do with it. */ 271 /* Throw away data. No better idea what to do with it. */
275 priv->wrfilled=0; 272 priv->wrfilled = 0;
276 priv->wrsent=0; 273 priv->wrsent = 0;
277 spin_unlock_irqrestore(&priv->lock, flags); 274 spin_unlock_irqrestore(&priv->lock, flags);
278 port->write_urb_busy = 0; 275 port->write_urb_busy = 0;
279 return 0; 276 return 0;
280 } 277 }
281 278
282 dbg("%s - priv->wrsent=%d", __FUNCTION__,priv->wrsent); 279 dbg("%s - priv->wrsent=%d", __func__,priv->wrsent);
283 dbg("%s - priv->wrfilled=%d", __FUNCTION__,priv->wrfilled); 280 dbg("%s - priv->wrfilled=%d", __func__,priv->wrfilled);
284 281
285 if( priv->wrsent>=priv->wrfilled ) { 282 if( priv->wrsent>=priv->wrfilled ) {
286 dbg("%s - buffer cleaned", __FUNCTION__); 283 dbg("%s - buffer cleaned", __func__);
287 memset( priv->wrbuf, 0, sizeof(priv->wrbuf) ); 284 memset( priv->wrbuf, 0, sizeof(priv->wrbuf) );
288 priv->wrfilled=0; 285 priv->wrfilled = 0;
289 priv->wrsent=0; 286 priv->wrsent = 0;
290 } 287 }
291 } 288 }
292 289
@@ -297,27 +294,28 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
297 294
298static int cyberjack_write_room( struct usb_serial_port *port ) 295static int cyberjack_write_room( struct usb_serial_port *port )
299{ 296{
297 /* FIXME: .... */
300 return CYBERJACK_LOCAL_BUF_SIZE; 298 return CYBERJACK_LOCAL_BUF_SIZE;
301} 299}
302 300
303static void cyberjack_read_int_callback( struct urb *urb ) 301static void cyberjack_read_int_callback( struct urb *urb )
304{ 302{
305 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 303 struct usb_serial_port *port = urb->context;
306 struct cyberjack_private *priv = usb_get_serial_port_data(port); 304 struct cyberjack_private *priv = usb_get_serial_port_data(port);
307 unsigned char *data = urb->transfer_buffer; 305 unsigned char *data = urb->transfer_buffer;
308 int status = urb->status; 306 int status = urb->status;
309 int result; 307 int result;
310 308
311 dbg("%s - port %d", __FUNCTION__, port->number); 309 dbg("%s - port %d", __func__, port->number);
312 310
313 /* the urb might have been killed. */ 311 /* the urb might have been killed. */
314 if (status) 312 if (status)
315 return; 313 return;
316 314
317 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); 315 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
318 316
319 /* React only to interrupts signaling a bulk_in transfer */ 317 /* React only to interrupts signaling a bulk_in transfer */
320 if( (urb->actual_length==4) && (data[0]==0x01) ) { 318 if( (urb->actual_length == 4) && (data[0] == 0x01) ) {
321 short old_rdtodo; 319 short old_rdtodo;
322 320
323 /* This is a announcement of coming bulk_ins. */ 321 /* This is a announcement of coming bulk_ins. */
@@ -336,7 +334,7 @@ static void cyberjack_read_int_callback( struct urb *urb )
336 /* "+=" is probably more fault tollerant than "=" */ 334 /* "+=" is probably more fault tollerant than "=" */
337 priv->rdtodo += size; 335 priv->rdtodo += size;
338 336
339 dbg("%s - rdtodo: %d", __FUNCTION__, priv->rdtodo); 337 dbg("%s - rdtodo: %d", __func__, priv->rdtodo);
340 338
341 spin_unlock(&priv->lock); 339 spin_unlock(&priv->lock);
342 340
@@ -344,8 +342,8 @@ static void cyberjack_read_int_callback( struct urb *urb )
344 port->read_urb->dev = port->serial->dev; 342 port->read_urb->dev = port->serial->dev;
345 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 343 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
346 if( result ) 344 if( result )
347 err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result); 345 err("%s - failed resubmitting read urb, error %d", __func__, result);
348 dbg("%s - usb_submit_urb(read urb)", __FUNCTION__); 346 dbg("%s - usb_submit_urb(read urb)", __func__);
349 } 347 }
350 } 348 }
351 349
@@ -354,12 +352,12 @@ resubmit:
354 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 352 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
355 if (result) 353 if (result)
356 err(" usb_submit_urb(read int) failed"); 354 err(" usb_submit_urb(read int) failed");
357 dbg("%s - usb_submit_urb(int urb)", __FUNCTION__); 355 dbg("%s - usb_submit_urb(int urb)", __func__);
358} 356}
359 357
360static void cyberjack_read_bulk_callback (struct urb *urb) 358static void cyberjack_read_bulk_callback (struct urb *urb)
361{ 359{
362 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 360 struct usb_serial_port *port = urb->context;
363 struct cyberjack_private *priv = usb_get_serial_port_data(port); 361 struct cyberjack_private *priv = usb_get_serial_port_data(port);
364 struct tty_struct *tty; 362 struct tty_struct *tty;
365 unsigned char *data = urb->transfer_buffer; 363 unsigned char *data = urb->transfer_buffer;
@@ -367,18 +365,18 @@ static void cyberjack_read_bulk_callback (struct urb *urb)
367 int result; 365 int result;
368 int status = urb->status; 366 int status = urb->status;
369 367
370 dbg("%s - port %d", __FUNCTION__, port->number); 368 dbg("%s - port %d", __func__, port->number);
371 369
372 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); 370 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
373 if (status) { 371 if (status) {
374 dbg("%s - nonzero read bulk status received: %d", 372 dbg("%s - nonzero read bulk status received: %d",
375 __FUNCTION__, status); 373 __func__, status);
376 return; 374 return;
377 } 375 }
378 376
379 tty = port->tty; 377 tty = port->tty;
380 if (!tty) { 378 if (!tty) {
381 dbg("%s - ignoring since device not open\n", __FUNCTION__); 379 dbg("%s - ignoring since device not open\n", __func__);
382 return; 380 return;
383 } 381 }
384 if (urb->actual_length) { 382 if (urb->actual_length) {
@@ -397,30 +395,30 @@ static void cyberjack_read_bulk_callback (struct urb *urb)
397 395
398 spin_unlock(&priv->lock); 396 spin_unlock(&priv->lock);
399 397
400 dbg("%s - rdtodo: %d", __FUNCTION__, todo); 398 dbg("%s - rdtodo: %d", __func__, todo);
401 399
402 /* Continue to read if we have still urbs to do. */ 400 /* Continue to read if we have still urbs to do. */
403 if( todo /* || (urb->actual_length==port->bulk_in_endpointAddress)*/ ) { 401 if( todo /* || (urb->actual_length==port->bulk_in_endpointAddress)*/ ) {
404 port->read_urb->dev = port->serial->dev; 402 port->read_urb->dev = port->serial->dev;
405 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 403 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
406 if (result) 404 if (result)
407 err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result); 405 err("%s - failed resubmitting read urb, error %d", __func__, result);
408 dbg("%s - usb_submit_urb(read urb)", __FUNCTION__); 406 dbg("%s - usb_submit_urb(read urb)", __func__);
409 } 407 }
410} 408}
411 409
412static void cyberjack_write_bulk_callback (struct urb *urb) 410static void cyberjack_write_bulk_callback (struct urb *urb)
413{ 411{
414 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 412 struct usb_serial_port *port = urb->context;
415 struct cyberjack_private *priv = usb_get_serial_port_data(port); 413 struct cyberjack_private *priv = usb_get_serial_port_data(port);
416 int status = urb->status; 414 int status = urb->status;
417 415
418 dbg("%s - port %d", __FUNCTION__, port->number); 416 dbg("%s - port %d", __func__, port->number);
419 417
420 port->write_urb_busy = 0; 418 port->write_urb_busy = 0;
421 if (status) { 419 if (status) {
422 dbg("%s - nonzero write bulk status received: %d", 420 dbg("%s - nonzero write bulk status received: %d",
423 __FUNCTION__, status); 421 __func__, status);
424 return; 422 return;
425 } 423 }
426 424
@@ -430,7 +428,7 @@ static void cyberjack_write_bulk_callback (struct urb *urb)
430 if( priv->wrfilled ) { 428 if( priv->wrfilled ) {
431 int length, blksize, result; 429 int length, blksize, result;
432 430
433 dbg("%s - transmitting data (frame n)", __FUNCTION__); 431 dbg("%s - transmitting data (frame n)", __func__);
434 432
435 length = ((priv->wrfilled - priv->wrsent) > port->bulk_out_size) ? 433 length = ((priv->wrfilled - priv->wrsent) > port->bulk_out_size) ?
436 port->bulk_out_size : (priv->wrfilled - priv->wrsent); 434 port->bulk_out_size : (priv->wrfilled - priv->wrsent);
@@ -451,23 +449,23 @@ static void cyberjack_write_bulk_callback (struct urb *urb)
451 /* send the data out the bulk port */ 449 /* send the data out the bulk port */
452 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 450 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
453 if (result) { 451 if (result) {
454 err("%s - failed submitting write urb, error %d", __FUNCTION__, result); 452 err("%s - failed submitting write urb, error %d", __func__, result);
455 /* Throw away data. No better idea what to do with it. */ 453 /* Throw away data. No better idea what to do with it. */
456 priv->wrfilled=0; 454 priv->wrfilled = 0;
457 priv->wrsent=0; 455 priv->wrsent = 0;
458 goto exit; 456 goto exit;
459 } 457 }
460 458
461 dbg("%s - priv->wrsent=%d", __FUNCTION__,priv->wrsent); 459 dbg("%s - priv->wrsent=%d", __func__,priv->wrsent);
462 dbg("%s - priv->wrfilled=%d", __FUNCTION__,priv->wrfilled); 460 dbg("%s - priv->wrfilled=%d", __func__,priv->wrfilled);
463 461
464 blksize = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3; 462 blksize = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3;
465 463
466 if( (priv->wrsent>=priv->wrfilled) || (priv->wrsent>=blksize) ) { 464 if( (priv->wrsent>=priv->wrfilled) || (priv->wrsent>=blksize) ) {
467 dbg("%s - buffer cleaned", __FUNCTION__); 465 dbg("%s - buffer cleaned", __func__);
468 memset( priv->wrbuf, 0, sizeof(priv->wrbuf) ); 466 memset( priv->wrbuf, 0, sizeof(priv->wrbuf) );
469 priv->wrfilled=0; 467 priv->wrfilled = 0;
470 priv->wrsent=0; 468 priv->wrsent = 0;
471 } 469 }
472 } 470 }
473 471