aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/io_ti.c
diff options
context:
space:
mode:
authorAlan Cox <alan@lxorguk.ukuu.org.uk>2008-04-29 09:45:15 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2008-07-21 18:15:53 -0400
commit2742fd8899328345d97a3443fb787b051b79ebae (patch)
treed64405d61cbfed5f44e62524089cd45ba52d3aa0 /drivers/usb/serial/io_ti.c
parent4330354f7660828d97834598633054b413f6264d (diff)
USB: io_ti: FIrst cut at a big clean up
Sort out the insane naming like "OperationalFirmwareVersion" which seems designed to cause formatting problems and RSI Merge various common code together Clean up the pointlessly complex and spread about MCR handling This is really just the low hanging fruit. Needs lots of testing before it goes upstream so testers and reports appreciated Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/serial/io_ti.c')
-rw-r--r--drivers/usb/serial/io_ti.c1860
1 files changed, 852 insertions, 1008 deletions
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index 61daea3f7b2..a58822a14a8 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -18,8 +18,8 @@
18 * 18 *
19 * Version history: 19 * Version history:
20 * 20 *
21 * July 11, 2002 Removed 4 port device structure since all TI UMP 21 * July 11, 2002 Removed 4 port device structure since all TI UMP
22 * chips have only 2 ports 22 * chips have only 2 ports
23 * David Iacovelli (davidi@ionetworks.com) 23 * David Iacovelli (davidi@ionetworks.com)
24 * 24 *
25 */ 25 */
@@ -38,7 +38,7 @@
38#include <linux/serial.h> 38#include <linux/serial.h>
39#include <linux/ioctl.h> 39#include <linux/ioctl.h>
40#include <linux/firmware.h> 40#include <linux/firmware.h>
41#include <asm/uaccess.h> 41#include <linux/uaccess.h>
42#include <linux/usb.h> 42#include <linux/usb.h>
43#include <linux/usb/serial.h> 43#include <linux/usb/serial.h>
44 44
@@ -57,18 +57,19 @@
57 57
58 58
59struct edgeport_uart_buf_desc { 59struct edgeport_uart_buf_desc {
60 __u32 count; // Number of bytes currently in buffer 60 __u32 count; /* Number of bytes currently in buffer */
61}; 61};
62 62
63/* different hardware types */ 63/* different hardware types */
64#define HARDWARE_TYPE_930 0 64#define HARDWARE_TYPE_930 0
65#define HARDWARE_TYPE_TIUMP 1 65#define HARDWARE_TYPE_TIUMP 1
66 66
67// IOCTL_PRIVATE_TI_GET_MODE Definitions 67/* IOCTL_PRIVATE_TI_GET_MODE Definitions */
68#define TI_MODE_CONFIGURING 0 // Device has not entered start device 68#define TI_MODE_CONFIGURING 0 /* Device has not entered start device */
69#define TI_MODE_BOOT 1 // Staying in boot mode 69#define TI_MODE_BOOT 1 /* Staying in boot mode */
70#define TI_MODE_DOWNLOAD 2 // Made it to download mode 70#define TI_MODE_DOWNLOAD 2 /* Made it to download mode */
71#define TI_MODE_TRANSITIONING 3 // Currently in boot mode but transitioning to download mode 71#define TI_MODE_TRANSITIONING 3 /* Currently in boot mode but
72 transitioning to download mode */
72 73
73/* read urb state */ 74/* read urb state */
74#define EDGE_READ_URB_RUNNING 0 75#define EDGE_READ_URB_RUNNING 0
@@ -82,10 +83,9 @@ struct edgeport_uart_buf_desc {
82 83
83 84
84/* Product information read from the Edgeport */ 85/* Product information read from the Edgeport */
85struct product_info 86struct product_info {
86{ 87 int TiMode; /* Current TI Mode */
87 int TiMode; // Current TI Mode 88 __u8 hardware_type; /* Type of hardware */
88 __u8 hardware_type; // Type of hardware
89} __attribute__((packed)); 89} __attribute__((packed));
90 90
91/* circular buffer */ 91/* circular buffer */
@@ -116,7 +116,7 @@ struct edgeport_port {
116 happen */ 116 happen */
117 struct edgeport_serial *edge_serial; 117 struct edgeport_serial *edge_serial;
118 struct usb_serial_port *port; 118 struct usb_serial_port *port;
119 __u8 bUartMode; /* Port type, 0: RS232, etc. */ 119 __u8 bUartMode; /* Port type, 0: RS232, etc. */
120 spinlock_t ep_lock; 120 spinlock_t ep_lock;
121 int ep_read_urb_state; 121 int ep_read_urb_state;
122 int ep_write_urb_in_use; 122 int ep_write_urb_in_use;
@@ -125,8 +125,9 @@ struct edgeport_port {
125 125
126struct edgeport_serial { 126struct edgeport_serial {
127 struct product_info product_info; 127 struct product_info product_info;
128 u8 TI_I2C_Type; // Type of I2C in UMP 128 u8 TI_I2C_Type; /* Type of I2C in UMP */
129 u8 TiReadI2C; // Set to TRUE if we have read the I2c in Boot Mode 129 u8 TiReadI2C; /* Set to TRUE if we have read the
130 I2c in Boot Mode */
130 struct mutex es_lock; 131 struct mutex es_lock;
131 int num_ports_open; 132 int num_ports_open;
132 struct usb_serial *serial; 133 struct usb_serial *serial;
@@ -214,7 +215,7 @@ static struct usb_device_id id_table_combined [] = {
214 { } 215 { }
215}; 216};
216 217
217MODULE_DEVICE_TABLE (usb, id_table_combined); 218MODULE_DEVICE_TABLE(usb, id_table_combined);
218 219
219static struct usb_driver io_driver = { 220static struct usb_driver io_driver = {
220 .name = "io_ti", 221 .name = "io_ti",
@@ -231,19 +232,19 @@ static unsigned short OperationalBuildNumber;
231 232
232static int debug; 233static int debug;
233 234
234static int TIStayInBootMode = 0;
235static int low_latency = EDGE_LOW_LATENCY; 235static int low_latency = EDGE_LOW_LATENCY;
236static int closing_wait = EDGE_CLOSING_WAIT; 236static int closing_wait = EDGE_CLOSING_WAIT;
237static int ignore_cpu_rev = 0; 237static int ignore_cpu_rev;
238static int default_uart_mode = 0; /* RS232 */ 238static int default_uart_mode; /* RS232 */
239
240 239
241static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned char *data, int length); 240static void edge_tty_recv(struct device *dev, struct tty_struct *tty,
241 unsigned char *data, int length);
242 242
243static void stop_read(struct edgeport_port *edge_port); 243static void stop_read(struct edgeport_port *edge_port);
244static int restart_read(struct edgeport_port *edge_port); 244static int restart_read(struct edgeport_port *edge_port);
245 245
246static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old_termios); 246static void edge_set_termios(struct usb_serial_port *port,
247 struct ktermios *old_termios);
247static void edge_send(struct usb_serial_port *port); 248static void edge_send(struct usb_serial_port *port);
248 249
249/* sysfs attributes */ 250/* sysfs attributes */
@@ -262,87 +263,57 @@ static unsigned int edge_buf_get(struct edge_buf *eb, char *buf,
262 unsigned int count); 263 unsigned int count);
263 264
264 265
265static int TIReadVendorRequestSync (struct usb_device *dev, 266static int ti_vread_sync(struct usb_device *dev, __u8 request,
266 __u8 request, 267 __u16 value, __u16 index, u8 *data, int size)
267 __u16 value,
268 __u16 index,
269 u8 *data,
270 int size)
271{ 268{
272 int status; 269 int status;
273 270
274 status = usb_control_msg (dev, 271 status = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), request,
275 usb_rcvctrlpipe(dev, 0), 272 (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN),
276 request, 273 value, index, data, size, 1000);
277 (USB_TYPE_VENDOR |
278 USB_RECIP_DEVICE |
279 USB_DIR_IN),
280 value,
281 index,
282 data,
283 size,
284 1000);
285 if (status < 0) 274 if (status < 0)
286 return status; 275 return status;
287 if (status != size) { 276 if (status != size) {
288 dbg ("%s - wanted to write %d, but only wrote %d", 277 dbg("%s - wanted to write %d, but only wrote %d",
289 __func__, size, status); 278 __func__, size, status);
290 return -ECOMM; 279 return -ECOMM;
291 } 280 }
292 return 0; 281 return 0;
293} 282}
294 283
295static int TISendVendorRequestSync (struct usb_device *dev, 284static int ti_vsend_sync(struct usb_device *dev, __u8 request,
296 __u8 request, 285 __u16 value, __u16 index, u8 *data, int size)
297 __u16 value,
298 __u16 index,
299 u8 *data,
300 int size)
301{ 286{
302 int status; 287 int status;
303 288
304 status = usb_control_msg (dev, 289 status = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), request,
305 usb_sndctrlpipe(dev, 0), 290 (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT),
306 request, 291 value, index, data, size, 1000);
307 (USB_TYPE_VENDOR |
308 USB_RECIP_DEVICE |
309 USB_DIR_OUT),
310 value,
311 index,
312 data,
313 size,
314 1000);
315 if (status < 0) 292 if (status < 0)
316 return status; 293 return status;
317 if (status != size) { 294 if (status != size) {
318 dbg ("%s - wanted to write %d, but only wrote %d", 295 dbg("%s - wanted to write %d, but only wrote %d",
319 __func__, size, status); 296 __func__, size, status);
320 return -ECOMM; 297 return -ECOMM;
321 } 298 }
322 return 0; 299 return 0;
323} 300}
324 301
325static int TIWriteCommandSync (struct usb_device *dev, __u8 command, 302static int send_cmd(struct usb_device *dev, __u8 command,
326 __u8 moduleid, __u16 value, u8 *data, 303 __u8 moduleid, __u16 value, u8 *data,
327 int size) 304 int size)
328{ 305{
329 return TISendVendorRequestSync (dev, 306 return ti_vsend_sync(dev, command, value, moduleid, data, size);
330 command, // Request
331 value, // wValue
332 moduleid, // wIndex
333 data, // TransferBuffer
334 size); // TransferBufferLength
335
336} 307}
337 308
338/* clear tx/rx buffers and fifo in TI UMP */ 309/* clear tx/rx buffers and fifo in TI UMP */
339static int TIPurgeDataSync (struct usb_serial_port *port, __u16 mask) 310static int purge_port(struct usb_serial_port *port, __u16 mask)
340{ 311{
341 int port_number = port->number - port->serial->minor; 312 int port_number = port->number - port->serial->minor;
342 313
343 dbg ("%s - port %d, mask %x", __func__, port_number, mask); 314 dbg("%s - port %d, mask %x", __func__, port_number, mask);
344 315
345 return TIWriteCommandSync (port->serial->dev, 316 return send_cmd(port->serial->dev,
346 UMPC_PURGE_PORT, 317 UMPC_PURGE_PORT,
347 (__u8)(UMPM_UART1_PORT + port_number), 318 (__u8)(UMPM_UART1_PORT + port_number),
348 mask, 319 mask,
@@ -351,92 +322,87 @@ static int TIPurgeDataSync (struct usb_serial_port *port, __u16 mask)
351} 322}
352 323
353/** 324/**
354 * TIReadDownloadMemory - Read edgeport memory from TI chip 325 * read_download_mem - Read edgeport memory from TI chip
355 * @dev: usb device pointer 326 * @dev: usb device pointer
356 * @start_address: Device CPU address at which to read 327 * @start_address: Device CPU address at which to read
357 * @length: Length of above data 328 * @length: Length of above data
358 * @address_type: Can read both XDATA and I2C 329 * @address_type: Can read both XDATA and I2C
359 * @buffer: pointer to input data buffer 330 * @buffer: pointer to input data buffer
360 */ 331 */
361static int TIReadDownloadMemory(struct usb_device *dev, int start_address, 332static int read_download_mem(struct usb_device *dev, int start_address,
362 int length, __u8 address_type, __u8 *buffer) 333 int length, __u8 address_type, __u8 *buffer)
363{ 334{
364 int status = 0; 335 int status = 0;
365 __u8 read_length; 336 __u8 read_length;
366 __be16 be_start_address; 337 __be16 be_start_address;
367 338
368 dbg ("%s - @ %x for %d", __func__, start_address, length); 339 dbg("%s - @ %x for %d", __func__, start_address, length);
369 340
370 /* Read in blocks of 64 bytes 341 /* Read in blocks of 64 bytes
371 * (TI firmware can't handle more than 64 byte reads) 342 * (TI firmware can't handle more than 64 byte reads)
372 */ 343 */
373 while (length) { 344 while (length) {
374 if (length > 64) 345 if (length > 64)
375 read_length= 64; 346 read_length = 64;
376 else 347 else
377 read_length = (__u8)length; 348 read_length = (__u8)length;
378 349
379 if (read_length > 1) { 350 if (read_length > 1) {
380 dbg ("%s - @ %x for %d", __func__, 351 dbg("%s - @ %x for %d", __func__,
381 start_address, read_length); 352 start_address, read_length);
382 } 353 }
383 be_start_address = cpu_to_be16 (start_address); 354 be_start_address = cpu_to_be16(start_address);
384 status = TIReadVendorRequestSync (dev, 355 status = ti_vread_sync(dev, UMPC_MEMORY_READ,
385 UMPC_MEMORY_READ, // Request 356 (__u16)address_type,
386 (__u16)address_type, // wValue (Address type) 357 (__force __u16)be_start_address,
387 (__force __u16)be_start_address, // wIndex (Address to read) 358 buffer, read_length);
388 buffer, // TransferBuffer
389 read_length); // TransferBufferLength
390 359
391 if (status) { 360 if (status) {
392 dbg ("%s - ERROR %x", __func__, status); 361 dbg("%s - ERROR %x", __func__, status);
393 return status; 362 return status;
394 } 363 }
395 364
396 if (read_length > 1) { 365 if (read_length > 1)
397 usb_serial_debug_data(debug, &dev->dev, __func__, 366 usb_serial_debug_data(debug, &dev->dev, __func__,
398 read_length, buffer); 367 read_length, buffer);
399 }
400 368
401 /* Update pointers/length */ 369 /* Update pointers/length */
402 start_address += read_length; 370 start_address += read_length;
403 buffer += read_length; 371 buffer += read_length;
404 length -= read_length; 372 length -= read_length;
405 } 373 }
406 374
407 return status; 375 return status;
408} 376}
409 377
410static int TIReadRam (struct usb_device *dev, int start_address, int length, __u8 *buffer) 378static int read_ram(struct usb_device *dev, int start_address,
379 int length, __u8 *buffer)
411{ 380{
412 return TIReadDownloadMemory (dev, 381 return read_download_mem(dev, start_address, length,
413 start_address, 382 DTK_ADDR_SPACE_XDATA, buffer);
414 length,
415 DTK_ADDR_SPACE_XDATA,
416 buffer);
417} 383}
418 384
419/* Read edgeport memory to a given block */ 385/* Read edgeport memory to a given block */
420static int TIReadBootMemory (struct edgeport_serial *serial, int start_address, int length, __u8 * buffer) 386static int read_boot_mem(struct edgeport_serial *serial,
387 int start_address, int length, __u8 *buffer)
421{ 388{
422 int status = 0; 389 int status = 0;
423 int i; 390 int i;
424 391
425 for (i=0; i< length; i++) { 392 for (i = 0; i < length; i++) {
426 status = TIReadVendorRequestSync (serial->serial->dev, 393 status = ti_vread_sync(serial->serial->dev,
427 UMPC_MEMORY_READ, // Request 394 UMPC_MEMORY_READ, serial->TI_I2C_Type,
428 serial->TI_I2C_Type, // wValue (Address type) 395 (__u16)(start_address+i), &buffer[i], 0x01);
429 (__u16)(start_address+i), // wIndex
430 &buffer[i], // TransferBuffer
431 0x01); // TransferBufferLength
432 if (status) { 396 if (status) {
433 dbg ("%s - ERROR %x", __func__, status); 397 dbg("%s - ERROR %x", __func__, status);
434 return status; 398 return status;
435 } 399 }
436 } 400 }
437 401
438 dbg ("%s - start_address = %x, length = %d", __func__, start_address, length); 402 dbg("%s - start_address = %x, length = %d",
439 usb_serial_debug_data(debug, &serial->serial->dev->dev, __func__, length, buffer); 403 __func__, start_address, length);
404 usb_serial_debug_data(debug, &serial->serial->dev->dev,
405 __func__, length, buffer);
440 406
441 serial->TiReadI2C = 1; 407 serial->TiReadI2C = 1;
442 408
@@ -444,7 +410,8 @@ static int TIReadBootMemory (struct edgeport_serial *serial, int start_address,
444} 410}
445 411
446/* Write given block to TI EPROM memory */ 412/* Write given block to TI EPROM memory */
447static int TIWriteBootMemory (struct edgeport_serial *serial, int start_address, int length, __u8 *buffer) 413static int write_boot_mem(struct edgeport_serial *serial,
414 int start_address, int length, __u8 *buffer)
448{ 415{
449 int status = 0; 416 int status = 0;
450 int i; 417 int i;
@@ -452,57 +419,58 @@ static int TIWriteBootMemory (struct edgeport_serial *serial, int start_address,
452 419
453 /* Must do a read before write */ 420 /* Must do a read before write */
454 if (!serial->TiReadI2C) { 421 if (!serial->TiReadI2C) {
455 status = TIReadBootMemory(serial, 0, 1, &temp); 422 status = read_boot_mem(serial, 0, 1, &temp);
456 if (status) 423 if (status)
457 return status; 424 return status;
458 } 425 }
459 426
460 for (i=0; i < length; ++i) { 427 for (i = 0; i < length; ++i) {
461 status = TISendVendorRequestSync (serial->serial->dev, 428 status = ti_vsend_sync(serial->serial->dev,
462 UMPC_MEMORY_WRITE, // Request 429 UMPC_MEMORY_WRITE, buffer[i],
463 buffer[i], // wValue 430 (__u16)(i + start_address), NULL, 0);
464 (__u16)(i+start_address), // wIndex
465 NULL, // TransferBuffer
466 0); // TransferBufferLength
467 if (status) 431 if (status)
468 return status; 432 return status;
469 } 433 }
470 434
471 dbg ("%s - start_sddr = %x, length = %d", __func__, start_address, length); 435 dbg("%s - start_sddr = %x, length = %d",
472 usb_serial_debug_data(debug, &serial->serial->dev->dev, __func__, length, buffer); 436 __func__, start_address, length);
437 usb_serial_debug_data(debug, &serial->serial->dev->dev,
438 __func__, length, buffer);
473 439
474 return status; 440 return status;
475} 441}
476 442
477 443
478/* Write edgeport I2C memory to TI chip */ 444/* Write edgeport I2C memory to TI chip */
479static int TIWriteDownloadI2C (struct edgeport_serial *serial, int start_address, int length, __u8 address_type, __u8 *buffer) 445static int write_i2c_mem(struct edgeport_serial *serial,
446 int start_address, int length, __u8 address_type, __u8 *buffer)
480{ 447{
481 int status = 0; 448 int status = 0;
482 int write_length; 449 int write_length;
483 __be16 be_start_address; 450 __be16 be_start_address;
484 451
485 /* We can only send a maximum of 1 aligned byte page at a time */ 452 /* We can only send a maximum of 1 aligned byte page at a time */
486 453
487 /* calulate the number of bytes left in the first page */ 454 /* calulate the number of bytes left in the first page */
488 write_length = EPROM_PAGE_SIZE - (start_address & (EPROM_PAGE_SIZE - 1)); 455 write_length = EPROM_PAGE_SIZE -
456 (start_address & (EPROM_PAGE_SIZE - 1));
489 457
490 if (write_length > length) 458 if (write_length > length)
491 write_length = length; 459 write_length = length;
492 460
493 dbg ("%s - BytesInFirstPage Addr = %x, length = %d", __func__, start_address, write_length); 461 dbg("%s - BytesInFirstPage Addr = %x, length = %d",
494 usb_serial_debug_data(debug, &serial->serial->dev->dev, __func__, write_length, buffer); 462 __func__, start_address, write_length);
463 usb_serial_debug_data(debug, &serial->serial->dev->dev,
464 __func__, write_length, buffer);
495 465
496 /* Write first page */ 466 /* Write first page */
497 be_start_address = cpu_to_be16 (start_address); 467 be_start_address = cpu_to_be16(start_address);
498 status = TISendVendorRequestSync (serial->serial->dev, 468 status = ti_vsend_sync(serial->serial->dev,
499 UMPC_MEMORY_WRITE, // Request 469 UMPC_MEMORY_WRITE, (__u16)address_type,
500 (__u16)address_type, // wValue 470 (__force __u16)be_start_address,
501 (__force __u16)be_start_address, // wIndex 471 buffer, write_length);
502 buffer, // TransferBuffer
503 write_length);
504 if (status) { 472 if (status) {
505 dbg ("%s - ERROR %d", __func__, status); 473 dbg("%s - ERROR %d", __func__, status);
506 return status; 474 return status;
507 } 475 }
508 476
@@ -510,29 +478,31 @@ static int TIWriteDownloadI2C (struct edgeport_serial *serial, int start_address
510 start_address += write_length; 478 start_address += write_length;
511 buffer += write_length; 479 buffer += write_length;
512 480
513 /* We should be aligned now -- can write max page size bytes at a time */ 481 /* We should be aligned now -- can write
482 max page size bytes at a time */
514 while (length) { 483 while (length) {
515 if (length > EPROM_PAGE_SIZE) 484 if (length > EPROM_PAGE_SIZE)
516 write_length = EPROM_PAGE_SIZE; 485 write_length = EPROM_PAGE_SIZE;
517 else 486 else
518 write_length = length; 487 write_length = length;
519 488
520 dbg ("%s - Page Write Addr = %x, length = %d", __func__, start_address, write_length); 489 dbg("%s - Page Write Addr = %x, length = %d",
521 usb_serial_debug_data(debug, &serial->serial->dev->dev, __func__, write_length, buffer); 490 __func__, start_address, write_length);
491 usb_serial_debug_data(debug, &serial->serial->dev->dev,
492 __func__, write_length, buffer);
522 493
523 /* Write next page */ 494 /* Write next page */
524 be_start_address = cpu_to_be16 (start_address); 495 be_start_address = cpu_to_be16(start_address);
525 status = TISendVendorRequestSync (serial->serial->dev, 496 status = ti_vsend_sync(serial->serial->dev, UMPC_MEMORY_WRITE,
526 UMPC_MEMORY_WRITE, // Request 497 (__u16)address_type,
527 (__u16)address_type, // wValue 498 (__force __u16)be_start_address,
528 (__force __u16)be_start_address, // wIndex 499 buffer, write_length);
529 buffer, // TransferBuffer
530 write_length); // TransferBufferLength
531 if (status) { 500 if (status) {
532 dev_err (&serial->serial->dev->dev, "%s - ERROR %d\n", __func__, status); 501 dev_err(&serial->serial->dev->dev, "%s - ERROR %d\n",
502 __func__, status);
533 return status; 503 return status;
534 } 504 }
535 505
536 length -= write_length; 506 length -= write_length;
537 start_address += write_length; 507 start_address += write_length;
538 buffer += write_length; 508 buffer += write_length;
@@ -541,25 +511,25 @@ static int TIWriteDownloadI2C (struct edgeport_serial *serial, int start_address
541} 511}
542 512
543/* Examine the UMP DMA registers and LSR 513/* Examine the UMP DMA registers and LSR
544 * 514 *
545 * Check the MSBit of the X and Y DMA byte count registers. 515 * Check the MSBit of the X and Y DMA byte count registers.
546 * A zero in this bit indicates that the TX DMA buffers are empty 516 * A zero in this bit indicates that the TX DMA buffers are empty
547 * then check the TX Empty bit in the UART. 517 * then check the TX Empty bit in the UART.
548 */ 518 */
549static int TIIsTxActive (struct edgeport_port *port) 519static int tx_active(struct edgeport_port *port)
550{ 520{
551 int status; 521 int status;
552 struct out_endpoint_desc_block *oedb; 522 struct out_endpoint_desc_block *oedb;
553 __u8 *lsr; 523 __u8 *lsr;
554 int bytes_left = 0; 524 int bytes_left = 0;
555 525
556 oedb = kmalloc (sizeof (* oedb), GFP_KERNEL); 526 oedb = kmalloc(sizeof(*oedb), GFP_KERNEL);
557 if (!oedb) { 527 if (!oedb) {
558 dev_err (&port->port->dev, "%s - out of memory\n", __func__); 528 dev_err(&port->port->dev, "%s - out of memory\n", __func__);
559 return -ENOMEM; 529 return -ENOMEM;
560 } 530 }
561 531
562 lsr = kmalloc (1, GFP_KERNEL); /* Sigh, that's right, just one byte, 532 lsr = kmalloc(1, GFP_KERNEL); /* Sigh, that's right, just one byte,
563 as not all platforms can do DMA 533 as not all platforms can do DMA
564 from stack */ 534 from stack */
565 if (!lsr) { 535 if (!lsr) {
@@ -567,43 +537,39 @@ static int TIIsTxActive (struct edgeport_port *port)
567 return -ENOMEM; 537 return -ENOMEM;
568 } 538 }
569 /* Read the DMA Count Registers */ 539 /* Read the DMA Count Registers */
570 status = TIReadRam (port->port->serial->dev, 540 status = read_ram(port->port->serial->dev, port->dma_address,
571 port->dma_address, 541 sizeof(*oedb), (void *)oedb);
572 sizeof( *oedb),
573 (void *)oedb);
574
575 if (status) 542 if (status)
576 goto exit_is_tx_active; 543 goto exit_is_tx_active;
577 544
578 dbg ("%s - XByteCount 0x%X", __func__, oedb->XByteCount); 545 dbg("%s - XByteCount 0x%X", __func__, oedb->XByteCount);
579 546
580 /* and the LSR */ 547 /* and the LSR */
581 status = TIReadRam (port->port->serial->dev, 548 status = read_ram(port->port->serial->dev,
582 port->uart_base + UMPMEM_OFFS_UART_LSR, 549 port->uart_base + UMPMEM_OFFS_UART_LSR, 1, lsr);
583 1,
584 lsr);
585 550
586 if (status) 551 if (status)
587 goto exit_is_tx_active; 552 goto exit_is_tx_active;
588 dbg ("%s - LSR = 0x%X", __func__, *lsr); 553 dbg("%s - LSR = 0x%X", __func__, *lsr);
589 554
590 /* If either buffer has data or we are transmitting then return TRUE */ 555 /* If either buffer has data or we are transmitting then return TRUE */
591 if ((oedb->XByteCount & 0x80 ) != 0 ) 556 if ((oedb->XByteCount & 0x80) != 0)
592 bytes_left += 64; 557 bytes_left += 64;
593 558
594 if ((*lsr & UMP_UART_LSR_TX_MASK ) == 0 ) 559 if ((*lsr & UMP_UART_LSR_TX_MASK) == 0)
595 bytes_left += 1; 560 bytes_left += 1;
596 561
597 /* We return Not Active if we get any kind of error */ 562 /* We return Not Active if we get any kind of error */
598exit_is_tx_active: 563exit_is_tx_active:
599 dbg ("%s - return %d", __func__, bytes_left ); 564 dbg("%s - return %d", __func__, bytes_left);
600 565
601 kfree(lsr); 566 kfree(lsr);
602 kfree(oedb); 567 kfree(oedb);
603 return bytes_left; 568 return bytes_left;
604} 569}
605 570
606static void TIChasePort(struct edgeport_port *port, unsigned long timeout, int flush) 571static void chase_port(struct edgeport_port *port, unsigned long timeout,
572 int flush)
607{ 573{
608 int baud_rate; 574 int baud_rate;
609 struct tty_struct *tty = port->port->tty; 575 struct tty_struct *tty = port->port->tty;
@@ -611,7 +577,7 @@ static void TIChasePort(struct edgeport_port *port, unsigned long timeout, int f
611 unsigned long flags; 577 unsigned long flags;
612 578
613 if (!timeout) 579 if (!timeout)
614 timeout = (HZ*EDGE_CLOSING_WAIT)/100; 580 timeout = (HZ * EDGE_CLOSING_WAIT)/100;
615 581
616 /* wait for data to drain from the buffer */ 582 /* wait for data to drain from the buffer */
617 spin_lock_irqsave(&port->ep_lock, flags); 583 spin_lock_irqsave(&port->ep_lock, flags);
@@ -621,7 +587,8 @@ static void TIChasePort(struct edgeport_port *port, unsigned long timeout, int f
621 set_current_state(TASK_INTERRUPTIBLE); 587 set_current_state(TASK_INTERRUPTIBLE);
622 if (edge_buf_data_avail(port->ep_out_buf) == 0 588 if (edge_buf_data_avail(port->ep_out_buf) == 0
623 || timeout == 0 || signal_pending(current) 589 || timeout == 0 || signal_pending(current)
624 || !usb_get_intfdata(port->port->serial->interface)) /* disconnect */ 590 || !usb_get_intfdata(port->port->serial->interface))
591 /* disconnect */
625 break; 592 break;
626 spin_unlock_irqrestore(&port->ep_lock, flags); 593 spin_unlock_irqrestore(&port->ep_lock, flags);
627 timeout = schedule_timeout(timeout); 594 timeout = schedule_timeout(timeout);
@@ -636,8 +603,9 @@ static void TIChasePort(struct edgeport_port *port, unsigned long timeout, int f
636 /* wait for data to drain from the device */ 603 /* wait for data to drain from the device */
637 timeout += jiffies; 604 timeout += jiffies;
638 while ((long)(jiffies - timeout) < 0 && !signal_pending(current) 605 while ((long)(jiffies - timeout) < 0 && !signal_pending(current)
639 && usb_get_intfdata(port->port->serial->interface)) { /* not disconnected */ 606 && usb_get_intfdata(port->port->serial->interface)) {
640 if (!TIIsTxActive(port)) 607 /* not disconnected */
608 if (!tx_active(port))
641 break; 609 break;
642 msleep(10); 610 msleep(10);
643 } 611 }
@@ -647,72 +615,72 @@ static void TIChasePort(struct edgeport_port *port, unsigned long timeout, int f
647 return; 615 return;
648 616
649 /* wait one more character time, based on baud rate */ 617 /* wait one more character time, based on baud rate */
650 /* (TIIsTxActive doesn't seem to wait for the last byte) */ 618 /* (tx_active doesn't seem to wait for the last byte) */
651 if ((baud_rate=port->baud_rate) == 0) 619 baud_rate = port->baud_rate;
620 if (baud_rate == 0)
652 baud_rate = 50; 621 baud_rate = 50;
653 msleep(max(1, DIV_ROUND_UP(10000, baud_rate))); 622 msleep(max(1, DIV_ROUND_UP(10000, baud_rate)));
654} 623}
655 624
656static int TIChooseConfiguration (struct usb_device *dev) 625static int choose_config(struct usb_device *dev)
657{ 626{
658 // There may be multiple configurations on this device, in which case 627 /*
659 // we would need to read and parse all of them to find out which one 628 * There may be multiple configurations on this device, in which case
660 // we want. However, we just support one config at this point, 629 * we would need to read and parse all of them to find out which one
661 // configuration # 1, which is Config Descriptor 0. 630 * we want. However, we just support one config at this point,
631 * configuration # 1, which is Config Descriptor 0.
632 */
662 633
663 dbg ("%s - Number of Interfaces = %d", __func__, dev->config->desc.bNumInterfaces); 634 dbg("%s - Number of Interfaces = %d",
664 dbg ("%s - MAX Power = %d", __func__, dev->config->desc.bMaxPower*2); 635 __func__, dev->config->desc.bNumInterfaces);
636 dbg("%s - MAX Power = %d",
637 __func__, dev->config->desc.bMaxPower * 2);
665 638
666 if (dev->config->desc.bNumInterfaces != 1) { 639 if (dev->config->desc.bNumInterfaces != 1) {
667 dev_err (&dev->dev, "%s - bNumInterfaces is not 1, ERROR!\n", __func__); 640 dev_err(&dev->dev, "%s - bNumInterfaces is not 1, ERROR!\n",
641 __func__);
668 return -ENODEV; 642 return -ENODEV;
669 } 643 }
670 644
671 return 0; 645 return 0;
672} 646}
673 647
674static int TIReadRom (struct edgeport_serial *serial, int start_address, int length, __u8 *buffer) 648static int read_rom(struct edgeport_serial *serial,
649 int start_address, int length, __u8 *buffer)
675{ 650{
676 int status; 651 int status;
677 652
678 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) { 653 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) {
679 status = TIReadDownloadMemory (serial->serial->dev, 654 status = read_download_mem(serial->serial->dev,
680 start_address, 655 start_address,
681 length, 656 length,
682 serial->TI_I2C_Type, 657 serial->TI_I2C_Type,
683 buffer); 658 buffer);
684 } else { 659 } else {
685 status = TIReadBootMemory (serial, 660 status = read_boot_mem(serial, start_address, length,
686 start_address, 661 buffer);
687 length,
688 buffer);
689 } 662 }
690
691 return status; 663 return status;
692} 664}
693 665
694static int TIWriteRom (struct edgeport_serial *serial, int start_address, int length, __u8 *buffer) 666static int write_rom(struct edgeport_serial *serial, int start_address,
667 int length, __u8 *buffer)
695{ 668{
696 if (serial->product_info.TiMode == TI_MODE_BOOT) 669 if (serial->product_info.TiMode == TI_MODE_BOOT)
697 return TIWriteBootMemory (serial, 670 return write_boot_mem(serial, start_address, length,
698 start_address, 671 buffer);
699 length,
700 buffer);
701 672
702 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) 673 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD)
703 return TIWriteDownloadI2C (serial, 674 return write_i2c_mem(serial, start_address, length,
704 start_address, 675 serial->TI_I2C_Type, buffer);
705 length,
706 serial->TI_I2C_Type,
707 buffer);
708
709 return -EINVAL; 676 return -EINVAL;
710} 677}
711 678
712 679
713 680
714/* Read a descriptor header from I2C based on type */ 681/* Read a descriptor header from I2C based on type */
715static int TIGetDescriptorAddress (struct edgeport_serial *serial, int desc_type, struct ti_i2c_desc *rom_desc) 682static int get_descriptor_addr(struct edgeport_serial *serial,
683 int desc_type, struct ti_i2c_desc *rom_desc)
716{ 684{
717 int start_address; 685 int start_address;
718 int status; 686 int status;
@@ -720,41 +688,42 @@ static int TIGetDescriptorAddress (struct edgeport_serial *serial, int desc_type
720 /* Search for requested descriptor in I2C */ 688 /* Search for requested descriptor in I2C */
721 start_address = 2; 689 start_address = 2;
722 do { 690 do {
723 status = TIReadRom (serial, 691 status = read_rom(serial,
724 start_address, 692 start_address,
725 sizeof(struct ti_i2c_desc), 693 sizeof(struct ti_i2c_desc),
726 (__u8 *)rom_desc ); 694 (__u8 *)rom_desc);
727 if (status) 695 if (status)
728 return 0; 696 return 0;
729 697
730 if (rom_desc->Type == desc_type) 698 if (rom_desc->Type == desc_type)
731 return start_address; 699 return start_address;
732 700
733 start_address = start_address + sizeof(struct ti_i2c_desc) + rom_desc->Size; 701 start_address = start_address + sizeof(struct ti_i2c_desc)
702 + rom_desc->Size;
734 703
735 } while ((start_address < TI_MAX_I2C_SIZE) && rom_desc->Type); 704 } while ((start_address < TI_MAX_I2C_SIZE) && rom_desc->Type);
736 705
737 return 0; 706 return 0;
738} 707}
739 708
740/* Validate descriptor checksum */ 709/* Validate descriptor checksum */
741static int ValidChecksum(struct ti_i2c_desc *rom_desc, __u8 *buffer) 710static int valid_csum(struct ti_i2c_desc *rom_desc, __u8 *buffer)
742{ 711{
743 __u16 i; 712 __u16 i;
744 __u8 cs = 0; 713 __u8 cs = 0;
745 714
746 for (i=0; i < rom_desc->Size; i++) { 715 for (i = 0; i < rom_desc->Size; i++)
747 cs = (__u8)(cs + buffer[i]); 716 cs = (__u8)(cs + buffer[i]);
748 } 717
749 if (cs != rom_desc->CheckSum) { 718 if (cs != rom_desc->CheckSum) {
750 dbg ("%s - Mismatch %x - %x", __func__, rom_desc->CheckSum, cs); 719 dbg("%s - Mismatch %x - %x", __func__, rom_desc->CheckSum, cs);
751 return -EINVAL; 720 return -EINVAL;
752 } 721 }
753 return 0; 722 return 0;
754} 723}
755 724
756/* Make sure that the I2C image is good */ 725/* Make sure that the I2C image is good */
757static int TiValidateI2cImage (struct edgeport_serial *serial) 726static int check_i2c_image(struct edgeport_serial *serial)
758{ 727{
759 struct device *dev = &serial->serial->dev->dev; 728 struct device *dev = &serial->serial->dev->dev;
760 int status = 0; 729 int status = 0;
@@ -763,120 +732,124 @@ static int TiValidateI2cImage (struct edgeport_serial *serial)
763 __u8 *buffer; 732 __u8 *buffer;
764 __u16 ttype; 733 __u16 ttype;
765 734
766 rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL); 735 rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
767 if (!rom_desc) { 736 if (!rom_desc) {
768 dev_err (dev, "%s - out of memory\n", __func__); 737 dev_err(dev, "%s - out of memory\n", __func__);
769 return -ENOMEM; 738 return -ENOMEM;
770 } 739 }
771 buffer = kmalloc (TI_MAX_I2C_SIZE, GFP_KERNEL); 740 buffer = kmalloc(TI_MAX_I2C_SIZE, GFP_KERNEL);
772 if (!buffer) { 741 if (!buffer) {
773 dev_err (dev, "%s - out of memory when allocating buffer\n", __func__); 742 dev_err(dev, "%s - out of memory when allocating buffer\n",
774 kfree (rom_desc); 743 __func__);
744 kfree(rom_desc);
775 return -ENOMEM; 745 return -ENOMEM;
776 } 746 }
777 747
778 // Read the first byte (Signature0) must be 0x52 or 0x10 748 /* Read the first byte (Signature0) must be 0x52 or 0x10 */
779 status = TIReadRom (serial, 0, 1, buffer); 749 status = read_rom(serial, 0, 1, buffer);
780 if (status) 750 if (status)
781 goto ExitTiValidateI2cImage; 751 goto out;
782 752
783 if (*buffer != UMP5152 && *buffer != UMP3410) { 753 if (*buffer != UMP5152 && *buffer != UMP3410) {
784 dev_err (dev, "%s - invalid buffer signature\n", __func__); 754 dev_err(dev, "%s - invalid buffer signature\n", __func__);
785 status = -ENODEV; 755 status = -ENODEV;
786 goto ExitTiValidateI2cImage; 756 goto out;
787 } 757 }
788 758
789 do { 759 do {
790 // Validate the I2C 760 /* Validate the I2C */
791 status = TIReadRom (serial, 761 status = read_rom(serial,
792 start_address, 762 start_address,
793 sizeof(struct ti_i2c_desc), 763 sizeof(struct ti_i2c_desc),
794 (__u8 *)rom_desc); 764 (__u8 *)rom_desc);
795 if (status) 765 if (status)
796 break; 766 break;
797 767
798 if ((start_address + sizeof(struct ti_i2c_desc) + rom_desc->Size) > TI_MAX_I2C_SIZE) { 768 if ((start_address + sizeof(struct ti_i2c_desc) +
769 rom_desc->Size) > TI_MAX_I2C_SIZE) {
799 status = -ENODEV; 770 status = -ENODEV;
800 dbg ("%s - structure too big, erroring out.", __func__); 771 dbg("%s - structure too big, erroring out.", __func__);
801 break; 772 break;
802 } 773 }
803 774
804 dbg ("%s Type = 0x%x", __func__, rom_desc->Type); 775 dbg("%s Type = 0x%x", __func__, rom_desc->Type);
805 776
806 // Skip type 2 record 777 /* Skip type 2 record */
807 ttype = rom_desc->Type & 0x0f; 778 ttype = rom_desc->Type & 0x0f;
808 if ( ttype != I2C_DESC_TYPE_FIRMWARE_BASIC 779 if (ttype != I2C_DESC_TYPE_FIRMWARE_BASIC
809 && ttype != I2C_DESC_TYPE_FIRMWARE_AUTO ) { 780 && ttype != I2C_DESC_TYPE_FIRMWARE_AUTO) {
810 // Read the descriptor data 781 /* Read the descriptor data */
811 status = TIReadRom(serial, 782 status = read_rom(serial, start_address +
812 start_address+sizeof(struct ti_i2c_desc), 783 sizeof(struct ti_i2c_desc),
813 rom_desc->Size, 784 rom_desc->Size, buffer);
814 buffer);
815 if (status) 785 if (status)
816 break; 786 break;
817 787
818 status = ValidChecksum(rom_desc, buffer); 788 status = valid_csum(rom_desc, buffer);
819 if (status) 789 if (status)
820 break; 790 break;
821 } 791 }
822 start_address = start_address + sizeof(struct ti_i2c_desc) + rom_desc->Size; 792 start_address = start_address + sizeof(struct ti_i2c_desc) +
793 rom_desc->Size;
823 794
824 } while ((rom_desc->Type != I2C_DESC_TYPE_ION) && (start_address < TI_MAX_I2C_SIZE)); 795 } while ((rom_desc->Type != I2C_DESC_TYPE_ION) &&
796 (start_address < TI_MAX_I2C_SIZE));
825 797
826 if ((rom_desc->Type != I2C_DESC_TYPE_ION) || (start_address > TI_MAX_I2C_SIZE)) 798 if ((rom_desc->Type != I2C_DESC_TYPE_ION) ||
799 (start_address > TI_MAX_I2C_SIZE))
827 status = -ENODEV; 800 status = -ENODEV;
828 801
829ExitTiValidateI2cImage: 802out:
830 kfree (buffer); 803 kfree(buffer);
831 kfree (rom_desc); 804 kfree(rom_desc);
832 return status; 805 return status;
833} 806}
834 807
835static int TIReadManufDescriptor (struct edgeport_serial *serial, __u8 *buffer) 808static int get_manuf_info(struct edgeport_serial *serial, __u8 *buffer)
836{ 809{
837 int status; 810 int status;
838 int start_address; 811 int start_address;
839 struct ti_i2c_desc *rom_desc; 812 struct ti_i2c_desc *rom_desc;
840 struct edge_ti_manuf_descriptor *desc; 813 struct edge_ti_manuf_descriptor *desc;
841 814
842 rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL); 815 rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
843 if (!rom_desc) { 816 if (!rom_desc) {
844 dev_err (&serial->serial->dev->dev, "%s - out of memory\n", __func__); 817 dev_err(&serial->serial->dev->dev, "%s - out of memory\n",
818 __func__);
845 return -ENOMEM; 819 return -ENOMEM;
846 } 820 }
847 start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_ION, rom_desc); 821 start_address = get_descriptor_addr(serial, I2C_DESC_TYPE_ION,
822 rom_desc);
848 823
849 if (!start_address) { 824 if (!start_address) {
850 dbg ("%s - Edge Descriptor not found in I2C", __func__); 825 dbg("%s - Edge Descriptor not found in I2C", __func__);
851 status = -ENODEV; 826 status = -ENODEV;
852 goto exit; 827 goto exit;
853 } 828 }
854 829
855 // Read the descriptor data 830 /* Read the descriptor data */
856 status = TIReadRom (serial, 831 status = read_rom(serial, start_address+sizeof(struct ti_i2c_desc),
857 start_address+sizeof(struct ti_i2c_desc), 832 rom_desc->Size, buffer);
858 rom_desc->Size,
859 buffer);
860 if (status) 833 if (status)
861 goto exit; 834 goto exit;
862 835
863 status = ValidChecksum(rom_desc, buffer); 836 status = valid_csum(rom_desc, buffer);
864 837
865 desc = (struct edge_ti_manuf_descriptor *)buffer; 838 desc = (struct edge_ti_manuf_descriptor *)buffer;
866 dbg ( "%s - IonConfig 0x%x", __func__, desc->IonConfig ); 839 dbg("%s - IonConfig 0x%x", __func__, desc->IonConfig);
867 dbg ( "%s - Version %d", __func__, desc->Version ); 840 dbg("%s - Version %d", __func__, desc->Version);
868 dbg ( "%s - Cpu/Board 0x%x", __func__, desc->CpuRev_BoardRev ); 841 dbg("%s - Cpu/Board 0x%x", __func__, desc->CpuRev_BoardRev);
869 dbg ( "%s - NumPorts %d", __func__, desc->NumPorts ); 842 dbg("%s - NumPorts %d", __func__, desc->NumPorts);
870 dbg ( "%s - NumVirtualPorts %d", __func__, desc->NumVirtualPorts ); 843 dbg("%s - NumVirtualPorts %d", __func__, desc->NumVirtualPorts);
871 dbg ( "%s - TotalPorts %d", __func__, desc->TotalPorts ); 844 dbg("%s - TotalPorts %d", __func__, desc->TotalPorts);
872 845
873exit: 846exit:
874 kfree (rom_desc); 847 kfree(rom_desc);
875 return status; 848 return status;
876} 849}
877 850
878/* Build firmware header used for firmware update */ 851/* Build firmware header used for firmware update */
879static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev) 852static int build_i2c_fw_hdr(__u8 *header, struct device *dev)
880{ 853{
881 __u8 *buffer; 854 __u8 *buffer;
882 int buffer_size; 855 int buffer_size;
@@ -889,24 +862,28 @@ static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev)
889 const struct firmware *fw; 862 const struct firmware *fw;
890 const char *fw_name = "edgeport/down3.bin"; 863 const char *fw_name = "edgeport/down3.bin";
891 864
892 // In order to update the I2C firmware we must change the type 2 record to type 0xF2. 865 /* In order to update the I2C firmware we must change the type 2 record
893 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver 866 * to type 0xF2. This will force the UMP to come up in Boot Mode.
894 // will download the latest firmware (padded to 15.5k) into the UMP ram. 867 * Then while in boot mode, the driver will download the latest
895 // And finally when the device comes back up in download mode the driver will cause 868 * firmware (padded to 15.5k) into the UMP ram. And finally when the
896 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update 869 * device comes back up in download mode the driver will cause the new
897 // the record type from 0xf2 to 0x02. 870 * firmware to be copied from the UMP Ram to I2C and the firmware will
898 871 * update the record type from 0xf2 to 0x02.
899 // Allocate a 15.5k buffer + 2 bytes for version number (Firmware Record) 872 */
900 buffer_size = (((1024 * 16) - 512 )+ sizeof(struct ti_i2c_firmware_rec)); 873
901 874 /* Allocate a 15.5k buffer + 2 bytes for version number
902 buffer = kmalloc (buffer_size, GFP_KERNEL); 875 * (Firmware Record) */
876 buffer_size = (((1024 * 16) - 512 ) +
877 sizeof(struct ti_i2c_firmware_rec));
878
879 buffer = kmalloc(buffer_size, GFP_KERNEL);
903 if (!buffer) { 880 if (!buffer) {
904 dev_err (dev, "%s - out of memory\n", __func__); 881 dev_err(dev, "%s - out of memory\n", __func__);
905 return -ENOMEM; 882 return -ENOMEM;
906 } 883 }
907 884
908 // Set entire image of 0xffs 885 // Set entire image of 0xffs
909 memset (buffer, 0xff, buffer_size); 886 memset(buffer, 0xff, buffer_size);
910 887
911 err = request_firmware(&fw, fw_name, dev); 888 err = request_firmware(&fw, fw_name, dev);
912 if (err) { 889 if (err) {
@@ -921,16 +898,16 @@ static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev)
921 OperationalMinorVersion = fw->data[1]; 898 OperationalMinorVersion = fw->data[1];
922 OperationalBuildNumber = fw->data[2] | (fw->data[3] << 8); 899 OperationalBuildNumber = fw->data[2] | (fw->data[3] << 8);
923 900
924 // Copy version number into firmware record 901 /* Copy version number into firmware record */
925 firmware_rec = (struct ti_i2c_firmware_rec *)buffer; 902 firmware_rec = (struct ti_i2c_firmware_rec *)buffer;
926 903
927 firmware_rec->Ver_Major = OperationalMajorVersion; 904 firmware_rec->Ver_Major = OperationalMajorVersion;
928 firmware_rec->Ver_Minor = OperationalMinorVersion; 905 firmware_rec->Ver_Minor = OperationalMinorVersion;
929 906
930 // Pointer to fw_down memory image 907 /* Pointer to fw_down memory image */
931 img_header = (struct ti_i2c_image_header *)&fw->data[4]; 908 img_header = (struct ti_i2c_image_header *)&fw->data[4];
932 909
933 memcpy (buffer + sizeof(struct ti_i2c_firmware_rec), 910 memcpy(buffer + sizeof(struct ti_i2c_firmware_rec),
934 &fw->data[4 + sizeof(struct ti_i2c_image_header)], 911 &fw->data[4 + sizeof(struct ti_i2c_image_header)],
935 le16_to_cpu(img_header->Length)); 912 le16_to_cpu(img_header->Length));
936 913
@@ -940,12 +917,12 @@ static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev)
940 cs = (__u8)(cs + buffer[i]); 917 cs = (__u8)(cs + buffer[i]);
941 } 918 }
942 919
943 kfree (buffer); 920 kfree(buffer);
944 921
945 // Build new header 922 /* Build new header */
946 i2c_header = (struct ti_i2c_desc *)header; 923 i2c_header = (struct ti_i2c_desc *)header;
947 firmware_rec = (struct ti_i2c_firmware_rec*)i2c_header->Data; 924 firmware_rec = (struct ti_i2c_firmware_rec*)i2c_header->Data;
948 925
949 i2c_header->Type = I2C_DESC_TYPE_FIRMWARE_BLANK; 926 i2c_header->Type = I2C_DESC_TYPE_FIRMWARE_BLANK;
950 i2c_header->Size = (__u16)buffer_size; 927 i2c_header->Size = (__u16)buffer_size;
951 i2c_header->CheckSum = cs; 928 i2c_header->CheckSum = cs;
@@ -956,103 +933,100 @@ static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev)
956} 933}
957 934
958/* Try to figure out what type of I2c we have */ 935/* Try to figure out what type of I2c we have */
959static int TIGetI2cTypeInBootMode (struct edgeport_serial *serial) 936static int i2c_type_bootmode(struct edgeport_serial *serial)
960{ 937{
961 int status; 938 int status;
962 __u8 data; 939 __u8 data;
963 940
964 // Try to read type 2 941 /* Try to read type 2 */
965 status = TIReadVendorRequestSync (serial->serial->dev, 942 status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ,
966 UMPC_MEMORY_READ, // Request 943 DTK_ADDR_SPACE_I2C_TYPE_II, 0, &data, 0x01);
967 DTK_ADDR_SPACE_I2C_TYPE_II, // wValue (Address type)
968 0, // wIndex
969 &data, // TransferBuffer
970 0x01); // TransferBufferLength
971 if (status) 944 if (status)
972 dbg ("%s - read 2 status error = %d", __func__, status); 945 dbg("%s - read 2 status error = %d", __func__, status);
973 else 946 else
974 dbg ("%s - read 2 data = 0x%x", __func__, data); 947 dbg("%s - read 2 data = 0x%x", __func__, data);
975 if ((!status) && (data == UMP5152 || data == UMP3410)) { 948 if ((!status) && (data == UMP5152 || data == UMP3410)) {
976 dbg ("%s - ROM_TYPE_II", __func__); 949 dbg("%s - ROM_TYPE_II", __func__);
977 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II; 950 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
978 return 0; 951 return 0;
979 } 952 }
980 953
981 // Try to read type 3 954 /* Try to read type 3 */
982 status = TIReadVendorRequestSync (serial->serial->dev, 955 status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ,
983 UMPC_MEMORY_READ, // Request 956 DTK_ADDR_SPACE_I2C_TYPE_III, 0, &data, 0x01);
984 DTK_ADDR_SPACE_I2C_TYPE_III, // wValue (Address type)
985 0, // wIndex
986 &data, // TransferBuffer
987 0x01); // TransferBufferLength
988 if (status) 957 if (status)
989 dbg ("%s - read 3 status error = %d", __func__, status); 958 dbg("%s - read 3 status error = %d", __func__, status);
990 else 959 else
991 dbg ("%s - read 2 data = 0x%x", __func__, data); 960 dbg("%s - read 2 data = 0x%x", __func__, data);
992 if ((!status) && (data == UMP5152 || data == UMP3410)) { 961 if ((!status) && (data == UMP5152 || data == UMP3410)) {
993 dbg ("%s - ROM_TYPE_III", __func__); 962 dbg("%s - ROM_TYPE_III", __func__);
994 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_III; 963 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_III;
995 return 0; 964 return 0;
996 } 965 }
997 966
998 dbg ("%s - Unknown", __func__); 967 dbg("%s - Unknown", __func__);
999 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II; 968 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
1000 return -ENODEV; 969 return -ENODEV;
1001} 970}
1002 971
1003static int TISendBulkTransferSync (struct usb_serial *serial, void *buffer, int length, int *num_sent) 972static int bulk_xfer(struct usb_serial *serial, void *buffer,
973 int length, int *num_sent)
1004{ 974{
1005 int status; 975 int status;
1006 976
1007 status = usb_bulk_msg (serial->dev, 977 status = usb_bulk_msg(serial->dev,
1008 usb_sndbulkpipe(serial->dev, 978 usb_sndbulkpipe(serial->dev,
1009 serial->port[0]->bulk_out_endpointAddress), 979 serial->port[0]->bulk_out_endpointAddress),
1010 buffer, 980 buffer, length, num_sent, 1000);
1011 length,
1012 num_sent,
1013 1000);
1014 return status; 981 return status;
1015} 982}
1016 983
1017/* Download given firmware image to the device (IN BOOT MODE) */ 984/* Download given firmware image to the device (IN BOOT MODE) */
1018static int TIDownloadCodeImage (struct edgeport_serial *serial, __u8 *image, int image_length) 985static int download_code(struct edgeport_serial *serial, __u8 *image,
986 int image_length)
1019{ 987{
1020 int status = 0; 988 int status = 0;
1021 int pos; 989 int pos;
1022 int transfer; 990 int transfer;
1023 int done; 991 int done;
1024 992
1025 // Transfer firmware image 993 /* Transfer firmware image */
1026 for (pos = 0; pos < image_length; ) { 994 for (pos = 0; pos < image_length; ) {
1027 // Read the next buffer from file 995 /* Read the next buffer from file */
1028 transfer = image_length - pos; 996 transfer = image_length - pos;
1029 if (transfer > EDGE_FW_BULK_MAX_PACKET_SIZE) 997 if (transfer > EDGE_FW_BULK_MAX_PACKET_SIZE)
1030 transfer = EDGE_FW_BULK_MAX_PACKET_SIZE; 998 transfer = EDGE_FW_BULK_MAX_PACKET_SIZE;
1031 999
1032 // Transfer data 1000 /* Transfer data */
1033 status = TISendBulkTransferSync (serial->serial, &image[pos], transfer, &done); 1001 status = bulk_xfer(serial->serial, &image[pos],
1002 transfer, &done);
1034 if (status) 1003 if (status)
1035 break; 1004 break;
1036 // Advance buffer pointer 1005 /* Advance buffer pointer */
1037 pos += done; 1006 pos += done;
1038 } 1007 }
1039 1008
1040 return status; 1009 return status;
1041} 1010}
1042 1011
1043// FIXME!!! 1012/* FIXME!!! */
1044static int TIConfigureBootDevice (struct usb_device *dev) 1013static int config_boot_dev(struct usb_device *dev)
1045{ 1014{
1046 return 0; 1015 return 0;
1047} 1016}
1048 1017
1018static int ti_cpu_rev(struct edge_ti_manuf_descriptor *desc)
1019{
1020 return TI_GET_CPU_REVISION(desc->CpuRev_BoardRev);
1021}
1022
1049/** 1023/**
1050 * DownloadTIFirmware - Download run-time operating firmware to the TI5052 1024 * DownloadTIFirmware - Download run-time operating firmware to the TI5052
1051 * 1025 *
1052 * This routine downloads the main operating code into the TI5052, using the 1026 * This routine downloads the main operating code into the TI5052, using the
1053 * boot code already burned into E2PROM or ROM. 1027 * boot code already burned into E2PROM or ROM.
1054 */ 1028 */
1055static int TIDownloadFirmware (struct edgeport_serial *serial) 1029static int download_fw(struct edgeport_serial *serial)
1056{ 1030{
1057 struct device *dev = &serial->serial->dev->dev; 1031 struct device *dev = &serial->serial->dev->dev;
1058 int status = 0; 1032 int status = 0;
@@ -1071,22 +1045,25 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1071 /* Default to type 2 i2c */ 1045 /* Default to type 2 i2c */
1072 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II; 1046 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
1073 1047
1074 status = TIChooseConfiguration (serial->serial->dev); 1048 status = choose_config(serial->serial->dev);
1075 if (status) 1049 if (status)
1076 return status; 1050 return status;
1077 1051
1078 interface = &serial->serial->interface->cur_altsetting->desc; 1052 interface = &serial->serial->interface->cur_altsetting->desc;
1079 if (!interface) { 1053 if (!interface) {
1080 dev_err (dev, "%s - no interface set, error!\n", __func__); 1054 dev_err(dev, "%s - no interface set, error!\n", __func__);
1081 return -ENODEV; 1055 return -ENODEV;
1082 } 1056 }
1083 1057
1084 // Setup initial mode -- the default mode 0 is TI_MODE_CONFIGURING 1058 /*
1085 // if we have more than one endpoint we are definitely in download mode 1059 * Setup initial mode -- the default mode 0 is TI_MODE_CONFIGURING
1060 * if we have more than one endpoint we are definitely in download
1061 * mode
1062 */
1086 if (interface->bNumEndpoints > 1) 1063 if (interface->bNumEndpoints > 1)
1087 serial->product_info.TiMode = TI_MODE_DOWNLOAD; 1064 serial->product_info.TiMode = TI_MODE_DOWNLOAD;
1088 else 1065 else
1089 // Otherwise we will remain in configuring mode 1066 /* Otherwise we will remain in configuring mode */
1090 serial->product_info.TiMode = TI_MODE_CONFIGURING; 1067 serial->product_info.TiMode = TI_MODE_CONFIGURING;
1091 1068
1092 /********************************************************************/ 1069 /********************************************************************/
@@ -1097,256 +1074,273 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1097 1074
1098 dbg("%s - RUNNING IN DOWNLOAD MODE", __func__); 1075 dbg("%s - RUNNING IN DOWNLOAD MODE", __func__);
1099 1076
1100 status = TiValidateI2cImage (serial); 1077 status = check_i2c_image(serial);
1101 if (status) { 1078 if (status) {
1102 dbg("%s - DOWNLOAD MODE -- BAD I2C", __func__); 1079 dbg("%s - DOWNLOAD MODE -- BAD I2C", __func__);
1103 return status; 1080 return status;
1104 } 1081 }
1105 1082
1106 /* Validate Hardware version number 1083 /* Validate Hardware version number
1107 * Read Manufacturing Descriptor from TI Based Edgeport 1084 * Read Manufacturing Descriptor from TI Based Edgeport
1108 */ 1085 */
1109 ti_manuf_desc = kmalloc (sizeof (*ti_manuf_desc), GFP_KERNEL); 1086 ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL);
1110 if (!ti_manuf_desc) { 1087 if (!ti_manuf_desc) {
1111 dev_err (dev, "%s - out of memory.\n", __func__); 1088 dev_err(dev, "%s - out of memory.\n", __func__);
1112 return -ENOMEM; 1089 return -ENOMEM;
1113 } 1090 }
1114 status = TIReadManufDescriptor (serial, (__u8 *)ti_manuf_desc); 1091 status = get_manuf_info(serial, (__u8 *)ti_manuf_desc);
1115 if (status) { 1092 if (status) {
1116 kfree (ti_manuf_desc); 1093 kfree(ti_manuf_desc);
1117 return status; 1094 return status;
1118 } 1095 }
1119 1096
1120 // Check version number of ION descriptor 1097 /* Check version number of ION descriptor */
1121 if (!ignore_cpu_rev && TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev) < 2) { 1098 if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) {
1122 dbg ( "%s - Wrong CPU Rev %d (Must be 2)", __func__, 1099 dbg("%s - Wrong CPU Rev %d (Must be 2)",
1123 TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev)); 1100 __func__, ti_cpu_rev(ti_manuf_desc));
1124 kfree (ti_manuf_desc); 1101 kfree(ti_manuf_desc);
1125 return -EINVAL; 1102 return -EINVAL;
1126 } 1103 }
1127 1104
1128 rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL); 1105 rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
1129 if (!rom_desc) { 1106 if (!rom_desc) {
1130 dev_err (dev, "%s - out of memory.\n", __func__); 1107 dev_err(dev, "%s - out of memory.\n", __func__);
1131 kfree (ti_manuf_desc); 1108 kfree(ti_manuf_desc);
1132 return -ENOMEM; 1109 return -ENOMEM;
1133 } 1110 }
1134 1111
1135 // Search for type 2 record (firmware record) 1112 /* Search for type 2 record (firmware record) */
1136 if ((start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_FIRMWARE_BASIC, rom_desc)) != 0) { 1113 start_address = get_descriptor_addr(serial,
1114 I2C_DESC_TYPE_FIRMWARE_BASIC, rom_desc);
1115 if (start_address != 0) {
1137 struct ti_i2c_firmware_rec *firmware_version; 1116 struct ti_i2c_firmware_rec *firmware_version;
1138 __u8 record; 1117 __u8 record;
1139 1118
1140 dbg ("%s - Found Type FIRMWARE (Type 2) record", __func__); 1119 dbg("%s - Found Type FIRMWARE (Type 2) record",
1120 __func__);
1141 1121
1142 firmware_version = kmalloc (sizeof (*firmware_version), GFP_KERNEL); 1122 firmware_version = kmalloc(sizeof(*firmware_version),
1123 GFP_KERNEL);
1143 if (!firmware_version) { 1124 if (!firmware_version) {
1144 dev_err (dev, "%s - out of memory.\n", __func__); 1125 dev_err(dev, "%s - out of memory.\n", __func__);
1145 kfree (rom_desc); 1126 kfree(rom_desc);
1146 kfree (ti_manuf_desc); 1127 kfree(ti_manuf_desc);
1147 return -ENOMEM; 1128 return -ENOMEM;
1148 } 1129 }
1149 1130
1150 // Validate version number 1131 /* Validate version number
1151 // Read the descriptor data 1132 * Read the descriptor data
1152 status = TIReadRom (serial, 1133 */
1153 start_address+sizeof(struct ti_i2c_desc), 1134 status = read_rom(serial, start_address +
1135 sizeof(struct ti_i2c_desc),
1154 sizeof(struct ti_i2c_firmware_rec), 1136 sizeof(struct ti_i2c_firmware_rec),
1155 (__u8 *)firmware_version); 1137 (__u8 *)firmware_version);
1156 if (status) { 1138 if (status) {
1157 kfree (firmware_version); 1139 kfree(firmware_version);
1158 kfree (rom_desc); 1140 kfree(rom_desc);
1159 kfree (ti_manuf_desc); 1141 kfree(ti_manuf_desc);
1160 return status; 1142 return status;
1161 } 1143 }
1162 1144
1163 // Check version number of download with current version in I2c 1145 /* Check version number of download with current
1164 download_cur_ver = (firmware_version->Ver_Major << 8) + 1146 version in I2c */
1147 download_cur_ver = (firmware_version->Ver_Major << 8) +
1165 (firmware_version->Ver_Minor); 1148 (firmware_version->Ver_Minor);
1166 download_new_ver = (OperationalMajorVersion << 8) + 1149 download_new_ver = (OperationalMajorVersion << 8) +
1167 (OperationalMinorVersion); 1150 (OperationalMinorVersion);
1168 1151
1169 dbg ("%s - >>>Firmware Versions Device %d.%d Driver %d.%d", 1152 dbg("%s - >> FW Versions Device %d.%d Driver %d.%d",
1170 __func__, 1153 __func__,
1171 firmware_version->Ver_Major, 1154 firmware_version->Ver_Major,
1172 firmware_version->Ver_Minor, 1155 firmware_version->Ver_Minor,
1173 OperationalMajorVersion, 1156 OperationalMajorVersion,
1174 OperationalMinorVersion); 1157 OperationalMinorVersion);
1175 1158
1176 // Check if we have an old version in the I2C and update if necessary 1159 /* Check if we have an old version in the I2C and
1160 update if necessary */
1177 if (download_cur_ver != download_new_ver) { 1161 if (download_cur_ver != download_new_ver) {
1178 dbg ("%s - Update I2C Download from %d.%d to %d.%d", 1162 dbg("%s - Update I2C dld from %d.%d to %d.%d",
1179 __func__, 1163 __func__,
1180 firmware_version->Ver_Major, 1164 firmware_version->Ver_Major,
1181 firmware_version->Ver_Minor, 1165 firmware_version->Ver_Minor,
1182 OperationalMajorVersion, 1166 OperationalMajorVersion,
1183 OperationalMinorVersion); 1167 OperationalMinorVersion);
1184 1168
1185 // In order to update the I2C firmware we must change the type 2 record to type 0xF2. 1169 /* In order to update the I2C firmware we must
1186 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver 1170 * change the type 2 record to type 0xF2. This
1187 // will download the latest firmware (padded to 15.5k) into the UMP ram. 1171 * will force the UMP to come up in Boot Mode.
1188 // And finally when the device comes back up in download mode the driver will cause 1172 * Then while in boot mode, the driver will
1189 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update 1173 * download the latest firmware (padded to
1190 // the record type from 0xf2 to 0x02. 1174 * 15.5k) into the UMP ram. Finally when the
1191 1175 * device comes back up in download mode the
1176 * driver will cause the new firmware to be
1177 * copied from the UMP Ram to I2C and the
1178 * firmware will update the record type from
1179 * 0xf2 to 0x02.
1180 */
1192 record = I2C_DESC_TYPE_FIRMWARE_BLANK; 1181 record = I2C_DESC_TYPE_FIRMWARE_BLANK;
1193 1182
1194 // Change the I2C Firmware record type to 0xf2 to trigger an update 1183 /* Change the I2C Firmware record type to
1195 status = TIWriteRom (serial, 1184 0xf2 to trigger an update */
1196 start_address, 1185 status = write_rom(serial, start_address,
1197 sizeof(record), 1186 sizeof(record), &record);
1198 &record);
1199 if (status) { 1187 if (status) {
1200 kfree (firmware_version); 1188 kfree(firmware_version);
1201 kfree (rom_desc); 1189 kfree(rom_desc);
1202 kfree (ti_manuf_desc); 1190 kfree(ti_manuf_desc);
1203 return status; 1191 return status;
1204 } 1192 }
1205 1193
1206 // verify the write -- must do this in order for write to 1194 /* verify the write -- must do this in order
1207 // complete before we do the hardware reset 1195 * for write to complete before we do the
1208 status = TIReadRom (serial, 1196 * hardware reset
1197 */
1198 status = read_rom(serial,
1209 start_address, 1199 start_address,
1210 sizeof(record), 1200 sizeof(record),
1211 &record); 1201 &record);
1212
1213 if (status) { 1202 if (status) {
1214 kfree (firmware_version); 1203 kfree(firmware_version);
1215 kfree (rom_desc); 1204 kfree(rom_desc);
1216 kfree (ti_manuf_desc); 1205 kfree(ti_manuf_desc);
1217 return status; 1206 return status;
1218 } 1207 }
1219 1208
1220 if (record != I2C_DESC_TYPE_FIRMWARE_BLANK) { 1209 if (record != I2C_DESC_TYPE_FIRMWARE_BLANK) {
1221 dev_err (dev, "%s - error resetting device\n", __func__); 1210 dev_err(dev,
1222 kfree (firmware_version); 1211 "%s - error resetting device\n",
1223 kfree (rom_desc); 1212 __func__);
1224 kfree (ti_manuf_desc); 1213 kfree(firmware_version);
1214 kfree(rom_desc);
1215 kfree(ti_manuf_desc);
1225 return -ENODEV; 1216 return -ENODEV;
1226 } 1217 }
1227 1218
1228 dbg ("%s - HARDWARE RESET", __func__); 1219 dbg("%s - HARDWARE RESET", __func__);
1229 1220
1230 // Reset UMP -- Back to BOOT MODE 1221 /* Reset UMP -- Back to BOOT MODE */
1231 status = TISendVendorRequestSync (serial->serial->dev, 1222 status = ti_vsend_sync(serial->serial->dev,
1232 UMPC_HARDWARE_RESET, // Request 1223 UMPC_HARDWARE_RESET,
1233 0, // wValue 1224 0, 0, NULL, 0);
1234 0, // wIndex
1235 NULL, // TransferBuffer
1236 0); // TransferBufferLength
1237 1225
1238 dbg ( "%s - HARDWARE RESET return %d", __func__, status); 1226 dbg("%s - HARDWARE RESET return %d",
1227 __func__, status);
1239 1228
1240 /* return an error on purpose. */ 1229 /* return an error on purpose. */
1241 kfree (firmware_version); 1230 kfree(firmware_version);
1242 kfree (rom_desc); 1231 kfree(rom_desc);
1243 kfree (ti_manuf_desc); 1232 kfree(ti_manuf_desc);
1244 return -ENODEV; 1233 return -ENODEV;
1245 } 1234 }
1246 kfree (firmware_version); 1235 kfree(firmware_version);
1247 } 1236 }
1248 // Search for type 0xF2 record (firmware blank record) 1237 /* Search for type 0xF2 record (firmware blank record) */
1249 else if ((start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_FIRMWARE_BLANK, rom_desc)) != 0) { 1238 else if ((start_address = get_descriptor_addr(serial, I2C_DESC_TYPE_FIRMWARE_BLANK, rom_desc)) != 0) {
1250 #define HEADER_SIZE (sizeof(struct ti_i2c_desc) + sizeof(struct ti_i2c_firmware_rec)) 1239#define HEADER_SIZE (sizeof(struct ti_i2c_desc) + \
1240 sizeof(struct ti_i2c_firmware_rec))
1251 __u8 *header; 1241 __u8 *header;
1252 __u8 *vheader; 1242 __u8 *vheader;
1253 1243
1254 header = kmalloc (HEADER_SIZE, GFP_KERNEL); 1244 header = kmalloc(HEADER_SIZE, GFP_KERNEL);
1255 if (!header) { 1245 if (!header) {
1256 dev_err (dev, "%s - out of memory.\n", __func__); 1246 dev_err(dev, "%s - out of memory.\n", __func__);
1257 kfree (rom_desc); 1247 kfree(rom_desc);
1258 kfree (ti_manuf_desc); 1248 kfree(ti_manuf_desc);
1259 return -ENOMEM; 1249 return -ENOMEM;
1260 } 1250 }
1261 1251
1262 vheader = kmalloc (HEADER_SIZE, GFP_KERNEL); 1252 vheader = kmalloc(HEADER_SIZE, GFP_KERNEL);
1263 if (!vheader) { 1253 if (!vheader) {
1264 dev_err (dev, "%s - out of memory.\n", __func__); 1254 dev_err(dev, "%s - out of memory.\n", __func__);
1265 kfree (header); 1255 kfree(header);
1266 kfree (rom_desc); 1256 kfree(rom_desc);
1267 kfree (ti_manuf_desc); 1257 kfree(ti_manuf_desc);
1268 return -ENOMEM; 1258 return -ENOMEM;
1269 } 1259 }
1270 1260
1271 dbg ("%s - Found Type BLANK FIRMWARE (Type F2) record", __func__); 1261 dbg("%s - Found Type BLANK FIRMWARE (Type F2) record",
1272 1262 __func__);
1273 // In order to update the I2C firmware we must change the type 2 record to type 0xF2. 1263
1274 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver 1264 /*
1275 // will download the latest firmware (padded to 15.5k) into the UMP ram. 1265 * In order to update the I2C firmware we must change
1276 // And finally when the device comes back up in download mode the driver will cause 1266 * the type 2 record to type 0xF2. This will force the
1277 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update 1267 * UMP to come up in Boot Mode. Then while in boot
1278 // the record type from 0xf2 to 0x02. 1268 * mode, the driver will download the latest firmware
1279 status = BuildI2CFirmwareHeader(header, dev); 1269 * (padded to 15.5k) into the UMP ram. Finally when the
1270 * device comes back up in download mode the driver
1271 * will cause the new firmware to be copied from the
1272 * UMP Ram to I2C and the firmware will update the
1273 * record type from 0xf2 to 0x02.
1274 */
1275 status = build_i2c_fw_hdr(header, dev);
1280 if (status) { 1276 if (status) {
1281 kfree (vheader); 1277 kfree(vheader);
1282 kfree (header); 1278 kfree(header);
1283 kfree (rom_desc); 1279 kfree(rom_desc);
1284 kfree (ti_manuf_desc); 1280 kfree(ti_manuf_desc);
1285 return status; 1281 return status;
1286 } 1282 }
1287 1283
1288 // Update I2C with type 0xf2 record with correct size and checksum 1284 /* Update I2C with type 0xf2 record with correct
1289 status = TIWriteRom (serial, 1285 size and checksum */
1286 status = write_rom(serial,
1290 start_address, 1287 start_address,
1291 HEADER_SIZE, 1288 HEADER_SIZE,
1292 header); 1289 header);
1293 if (status) { 1290 if (status) {
1294 kfree (vheader); 1291 kfree(vheader);
1295 kfree (header); 1292 kfree(header);
1296 kfree (rom_desc); 1293 kfree(rom_desc);
1297 kfree (ti_manuf_desc); 1294 kfree(ti_manuf_desc);
1298 return status; 1295 return status;
1299 } 1296 }
1300 1297
1301 // verify the write -- must do this in order for write to 1298 /* verify the write -- must do this in order for
1302 // complete before we do the hardware reset 1299 write to complete before we do the hardware reset */
1303 status = TIReadRom (serial, 1300 status = read_rom(serial, start_address,
1304 start_address, 1301 HEADER_SIZE, vheader);
1305 HEADER_SIZE,
1306 vheader);
1307 1302
1308 if (status) { 1303 if (status) {
1309 dbg ("%s - can't read header back", __func__); 1304 dbg("%s - can't read header back", __func__);
1310 kfree (vheader); 1305 kfree(vheader);
1311 kfree (header); 1306 kfree(header);
1312 kfree (rom_desc); 1307 kfree(rom_desc);
1313 kfree (ti_manuf_desc); 1308 kfree(ti_manuf_desc);
1314 return status; 1309 return status;
1315 } 1310 }
1316 if (memcmp(vheader, header, HEADER_SIZE)) { 1311 if (memcmp(vheader, header, HEADER_SIZE)) {
1317 dbg ("%s - write download record failed", __func__); 1312 dbg("%s - write download record failed",
1318 kfree (vheader); 1313 __func__);
1319 kfree (header); 1314 kfree(vheader);
1320 kfree (rom_desc); 1315 kfree(header);
1321 kfree (ti_manuf_desc); 1316 kfree(rom_desc);
1317 kfree(ti_manuf_desc);
1322 return status; 1318 return status;
1323 } 1319 }
1324 1320
1325 kfree (vheader); 1321 kfree(vheader);
1326 kfree (header); 1322 kfree(header);
1327 1323
1328 dbg ("%s - Start firmware update", __func__); 1324 dbg("%s - Start firmware update", __func__);
1329 1325
1330 // Tell firmware to copy download image into I2C 1326 /* Tell firmware to copy download image into I2C */
1331 status = TISendVendorRequestSync (serial->serial->dev, 1327 status = ti_vsend_sync(serial->serial->dev,
1332 UMPC_COPY_DNLD_TO_I2C, // Request 1328 UMPC_COPY_DNLD_TO_I2C, 0, 0, NULL, 0);
1333 0, // wValue
1334 0, // wIndex
1335 NULL, // TransferBuffer
1336 0); // TransferBufferLength
1337 1329
1338 dbg ("%s - Update complete 0x%x", __func__, status); 1330 dbg("%s - Update complete 0x%x", __func__, status);
1339 if (status) { 1331 if (status) {
1340 dev_err (dev, "%s - UMPC_COPY_DNLD_TO_I2C failed\n", __func__); 1332 dev_err(dev,
1341 kfree (rom_desc); 1333 "%s - UMPC_COPY_DNLD_TO_I2C failed\n",
1342 kfree (ti_manuf_desc); 1334 __func__);
1335 kfree(rom_desc);
1336 kfree(ti_manuf_desc);
1343 return status; 1337 return status;
1344 } 1338 }
1345 } 1339 }
1346 1340
1347 // The device is running the download code 1341 // The device is running the download code
1348 kfree (rom_desc); 1342 kfree(rom_desc);
1349 kfree (ti_manuf_desc); 1343 kfree(ti_manuf_desc);
1350 return 0; 1344 return 0;
1351 } 1345 }
1352 1346
@@ -1355,32 +1349,26 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1355 /********************************************************************/ 1349 /********************************************************************/
1356 dbg("%s - RUNNING IN BOOT MODE", __func__); 1350 dbg("%s - RUNNING IN BOOT MODE", __func__);
1357 1351
1358 // Configure the TI device so we can use the BULK pipes for download 1352 /* Configure the TI device so we can use the BULK pipes for download */
1359 status = TIConfigureBootDevice (serial->serial->dev); 1353 status = config_boot_dev(serial->serial->dev);
1360 if (status) 1354 if (status)
1361 return status; 1355 return status;
1362 1356
1363 if (le16_to_cpu(serial->serial->dev->descriptor.idVendor) != USB_VENDOR_ID_ION) { 1357 if (le16_to_cpu(serial->serial->dev->descriptor.idVendor)
1364 dbg ("%s - VID = 0x%x", __func__, 1358 != USB_VENDOR_ID_ION) {
1359 dbg("%s - VID = 0x%x", __func__,
1365 le16_to_cpu(serial->serial->dev->descriptor.idVendor)); 1360 le16_to_cpu(serial->serial->dev->descriptor.idVendor));
1366 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II; 1361 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
1367 goto StayInBootMode; 1362 goto stayinbootmode;
1368 }
1369
1370 // We have an ION device (I2c Must be programmed)
1371 // Determine I2C image type
1372 if (TIGetI2cTypeInBootMode(serial)) {
1373 goto StayInBootMode;
1374 } 1363 }
1375 1364
1376 // Registry variable set? 1365 /* We have an ION device (I2c Must be programmed)
1377 if (TIStayInBootMode) { 1366 Determine I2C image type */
1378 dbg ("%s - TIStayInBootMode", __func__); 1367 if (i2c_type_bootmode(serial))
1379 goto StayInBootMode; 1368 goto stayinbootmode;
1380 }
1381 1369
1382 // Check for ION Vendor ID and that the I2C is valid 1370 /* Check for ION Vendor ID and that the I2C is valid */
1383 if (!TiValidateI2cImage(serial)) { 1371 if (!check_i2c_image(serial)) {
1384 struct ti_i2c_image_header *header; 1372 struct ti_i2c_image_header *header;
1385 int i; 1373 int i;
1386 __u8 cs = 0; 1374 __u8 cs = 0;
@@ -1393,49 +1381,52 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1393 /* Validate Hardware version number 1381 /* Validate Hardware version number
1394 * Read Manufacturing Descriptor from TI Based Edgeport 1382 * Read Manufacturing Descriptor from TI Based Edgeport
1395 */ 1383 */
1396 ti_manuf_desc = kmalloc (sizeof (*ti_manuf_desc), GFP_KERNEL); 1384 ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL);
1397 if (!ti_manuf_desc) { 1385 if (!ti_manuf_desc) {
1398 dev_err (dev, "%s - out of memory.\n", __func__); 1386 dev_err(dev, "%s - out of memory.\n", __func__);
1399 return -ENOMEM; 1387 return -ENOMEM;
1400 } 1388 }
1401 status = TIReadManufDescriptor (serial, (__u8 *)ti_manuf_desc); 1389 status = get_manuf_info(serial, (__u8 *)ti_manuf_desc);
1402 if (status) { 1390 if (status) {
1403 kfree (ti_manuf_desc); 1391 kfree(ti_manuf_desc);
1404 goto StayInBootMode; 1392 goto stayinbootmode;
1405 } 1393 }
1406 1394
1407 // Check for version 2 1395 /* Check for version 2 */
1408 if (!ignore_cpu_rev && TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev) < 2) { 1396 if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) {
1409 dbg ("%s - Wrong CPU Rev %d (Must be 2)", __func__, 1397 dbg("%s - Wrong CPU Rev %d (Must be 2)",
1410 TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev)); 1398 __func__, ti_cpu_rev(ti_manuf_desc));
1411 kfree (ti_manuf_desc); 1399 kfree(ti_manuf_desc);
1412 goto StayInBootMode; 1400 goto stayinbootmode;
1413 } 1401 }
1414 1402
1415 kfree (ti_manuf_desc); 1403 kfree(ti_manuf_desc);
1416 1404
1417 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1418 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
1419 // will download the latest firmware (padded to 15.5k) into the UMP ram.
1420 // And finally when the device comes back up in download mode the driver will cause
1421 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1422 // the record type from 0xf2 to 0x02.
1423
1424 /* 1405 /*
1406 * In order to update the I2C firmware we must change the type
1407 * 2 record to type 0xF2. This will force the UMP to come up
1408 * in Boot Mode. Then while in boot mode, the driver will
1409 * download the latest firmware (padded to 15.5k) into the
1410 * UMP ram. Finally when the device comes back up in download
1411 * mode the driver will cause the new firmware to be copied
1412 * from the UMP Ram to I2C and the firmware will update the
1413 * record type from 0xf2 to 0x02.
1414 *
1425 * Do we really have to copy the whole firmware image, 1415 * Do we really have to copy the whole firmware image,
1426 * or could we do this in place! 1416 * or could we do this in place!
1427 */ 1417 */
1428 1418
1429 // Allocate a 15.5k buffer + 3 byte header 1419 /* Allocate a 15.5k buffer + 3 byte header */
1430 buffer_size = (((1024 * 16) - 512) + sizeof(struct ti_i2c_image_header)); 1420 buffer_size = (((1024 * 16) - 512) +
1431 buffer = kmalloc (buffer_size, GFP_KERNEL); 1421 sizeof(struct ti_i2c_image_header));
1422 buffer = kmalloc(buffer_size, GFP_KERNEL);
1432 if (!buffer) { 1423 if (!buffer) {
1433 dev_err (dev, "%s - out of memory\n", __func__); 1424 dev_err(dev, "%s - out of memory\n", __func__);
1434 return -ENOMEM; 1425 return -ENOMEM;
1435 } 1426 }
1436 1427
1437 // Initialize the buffer to 0xff (pad the buffer) 1428 /* Initialize the buffer to 0xff (pad the buffer) */
1438 memset (buffer, 0xff, buffer_size); 1429 memset(buffer, 0xff, buffer_size);
1439 1430
1440 err = request_firmware(&fw, fw_name, dev); 1431 err = request_firmware(&fw, fw_name, dev);
1441 if (err) { 1432 if (err) {
@@ -1447,38 +1438,43 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
1447 memcpy(buffer, &fw->data[4], fw->size - 4); 1438 memcpy(buffer, &fw->data[4], fw->size - 4);
1448 release_firmware(fw); 1439 release_firmware(fw);
1449 1440
1450 for(i = sizeof(struct ti_i2c_image_header); i < buffer_size; i++) { 1441 for (i = sizeof(struct ti_i2c_image_header);
1442 i < buffer_size; i++) {
1451 cs = (__u8)(cs + buffer[i]); 1443 cs = (__u8)(cs + buffer[i]);
1452 } 1444 }
1453 1445
1454 header = (struct ti_i2c_image_header *)buffer; 1446 header = (struct ti_i2c_image_header *)buffer;
1455 1447
1456 // update length and checksum after padding 1448 /* update length and checksum after padding */
1457 header->Length = cpu_to_le16((__u16)(buffer_size - sizeof(struct ti_i2c_image_header))); 1449 header->Length = cpu_to_le16((__u16)(buffer_size -
1450 sizeof(struct ti_i2c_image_header)));
1458 header->CheckSum = cs; 1451 header->CheckSum = cs;
1459 1452
1460 // Download the operational code 1453 /* Download the operational code */
1461 dbg ("%s - Downloading operational code image (TI UMP)", __func__); 1454 dbg("%s - Downloading operational code image (TI UMP)",
1462 status = TIDownloadCodeImage (serial, buffer, buffer_size); 1455 __func__);
1456 status = download_code(serial, buffer, buffer_size);
1463 1457
1464 kfree (buffer); 1458 kfree(buffer);
1465 1459
1466 if (status) { 1460 if (status) {
1467 dbg ("%s - Error downloading operational code image", __func__); 1461 dbg("%s - Error downloading operational code image",
1462 __func__);
1468 return status; 1463 return status;
1469 } 1464 }
1470 1465
1471 // Device will reboot 1466 /* Device will reboot */
1472 serial->product_info.TiMode = TI_MODE_TRANSITIONING; 1467 serial->product_info.TiMode = TI_MODE_TRANSITIONING;
1473 1468
1474 dbg ("%s - Download successful -- Device rebooting...", __func__); 1469 dbg("%s - Download successful -- Device rebooting...",
1470 __func__);
1475 1471
1476 /* return an error on purpose */ 1472 /* return an error on purpose */
1477 return -ENODEV; 1473 return -ENODEV;
1478 } 1474 }
1479 1475
1480StayInBootMode: 1476stayinbootmode:
1481 // Eprom is invalid or blank stay in boot mode 1477 /* Eprom is invalid or blank stay in boot mode */
1482 dbg("%s - STAYING IN BOOT MODE", __func__); 1478 dbg("%s - STAYING IN BOOT MODE", __func__);
1483 serial->product_info.TiMode = TI_MODE_BOOT; 1479 serial->product_info.TiMode = TI_MODE_BOOT;
1484 1480
@@ -1486,156 +1482,33 @@ StayInBootMode:
1486} 1482}
1487 1483
1488 1484
1489static int TISetDtr (struct edgeport_port *port) 1485static int ti_do_config(struct edgeport_port *port, int feature, int on)
1490{ 1486{
1491 int port_number = port->port->number - port->port->serial->minor; 1487 int port_number = port->port->number - port->port->serial->minor;
1492 1488 on = !!on; /* 1 or 0 not bitmask */
1493 dbg ("%s", __func__); 1489 return send_cmd(port->port->serial->dev,
1494 port->shadow_mcr |= MCR_DTR; 1490 feature, (__u8)(UMPM_UART1_PORT + port_number),
1495 1491 on, NULL, 0);
1496 return TIWriteCommandSync (port->port->serial->dev,
1497 UMPC_SET_CLR_DTR,
1498 (__u8)(UMPM_UART1_PORT + port_number),
1499 1, /* set */
1500 NULL,
1501 0);
1502} 1492}
1503 1493
1504static int TIClearDtr (struct edgeport_port *port)
1505{
1506 int port_number = port->port->number - port->port->serial->minor;
1507
1508 dbg ("%s", __func__);
1509 port->shadow_mcr &= ~MCR_DTR;
1510 1494
1511 return TIWriteCommandSync (port->port->serial->dev, 1495static int restore_mcr(struct edgeport_port *port, __u8 mcr)
1512 UMPC_SET_CLR_DTR,
1513 (__u8)(UMPM_UART1_PORT + port_number),
1514 0, /* clear */
1515 NULL,
1516 0);
1517}
1518
1519static int TISetRts (struct edgeport_port *port)
1520{
1521 int port_number = port->port->number - port->port->serial->minor;
1522
1523 dbg ("%s", __func__);
1524 port->shadow_mcr |= MCR_RTS;
1525
1526 return TIWriteCommandSync (port->port->serial->dev,
1527 UMPC_SET_CLR_RTS,
1528 (__u8)(UMPM_UART1_PORT + port_number),
1529 1, /* set */
1530 NULL,
1531 0);
1532}
1533
1534static int TIClearRts (struct edgeport_port *port)
1535{
1536 int port_number = port->port->number - port->port->serial->minor;
1537
1538 dbg ("%s", __func__);
1539 port->shadow_mcr &= ~MCR_RTS;
1540
1541 return TIWriteCommandSync (port->port->serial->dev,
1542 UMPC_SET_CLR_RTS,
1543 (__u8)(UMPM_UART1_PORT + port_number),
1544 0, /* clear */
1545 NULL,
1546 0);
1547}
1548
1549static int TISetLoopBack (struct edgeport_port *port)
1550{
1551 int port_number = port->port->number - port->port->serial->minor;
1552
1553 dbg ("%s", __func__);
1554
1555 return TIWriteCommandSync (port->port->serial->dev,
1556 UMPC_SET_CLR_LOOPBACK,
1557 (__u8)(UMPM_UART1_PORT + port_number),
1558 1, /* set */
1559 NULL,
1560 0);
1561}
1562
1563static int TIClearLoopBack (struct edgeport_port *port)
1564{
1565 int port_number = port->port->number - port->port->serial->minor;
1566
1567 dbg ("%s", __func__);
1568
1569 return TIWriteCommandSync (port->port->serial->dev,
1570 UMPC_SET_CLR_LOOPBACK,
1571 (__u8)(UMPM_UART1_PORT + port_number),
1572 0, /* clear */
1573 NULL,
1574 0);
1575}
1576
1577static int TISetBreak (struct edgeport_port *port)
1578{
1579 int port_number = port->port->number - port->port->serial->minor;
1580
1581 dbg ("%s", __func__);
1582
1583 return TIWriteCommandSync (port->port->serial->dev,
1584 UMPC_SET_CLR_BREAK,
1585 (__u8)(UMPM_UART1_PORT + port_number),
1586 1, /* set */
1587 NULL,
1588 0);
1589}
1590
1591static int TIClearBreak (struct edgeport_port *port)
1592{
1593 int port_number = port->port->number - port->port->serial->minor;
1594
1595 dbg ("%s", __func__);
1596
1597 return TIWriteCommandSync (port->port->serial->dev,
1598 UMPC_SET_CLR_BREAK,
1599 (__u8)(UMPM_UART1_PORT + port_number),
1600 0, /* clear */
1601 NULL,
1602 0);
1603}
1604
1605static int TIRestoreMCR (struct edgeport_port *port, __u8 mcr)
1606{ 1496{
1607 int status = 0; 1497 int status = 0;
1608 1498
1609 dbg ("%s - %x", __func__, mcr); 1499 dbg("%s - %x", __func__, mcr);
1610
1611 if (mcr & MCR_DTR)
1612 status = TISetDtr (port);
1613 else
1614 status = TIClearDtr (port);
1615 1500
1501 status = ti_do_config(port, UMPC_SET_CLR_DTR, mcr & MCR_DTR);
1616 if (status) 1502 if (status)
1617 return status; 1503 return status;
1618 1504 status = ti_do_config(port, UMPC_SET_CLR_RTS, mcr & MCR_RTS);
1619 if (mcr & MCR_RTS)
1620 status = TISetRts (port);
1621 else
1622 status = TIClearRts (port);
1623
1624 if (status) 1505 if (status)
1625 return status; 1506 return status;
1626 1507 return ti_do_config(port, UMPC_SET_CLR_LOOPBACK, mcr & MCR_LOOPBACK);
1627 if (mcr & MCR_LOOPBACK)
1628 status = TISetLoopBack (port);
1629 else
1630 status = TIClearLoopBack (port);
1631
1632 return status;
1633} 1508}
1634 1509
1635
1636
1637/* Convert TI LSR to standard UART flags */ 1510/* Convert TI LSR to standard UART flags */
1638static __u8 MapLineStatus (__u8 ti_lsr) 1511static __u8 map_line_status(__u8 ti_lsr)
1639{ 1512{
1640 __u8 lsr = 0; 1513 __u8 lsr = 0;
1641 1514
@@ -1647,22 +1520,23 @@ static __u8 MapLineStatus (__u8 ti_lsr)
1647 MAP_FLAG(UMP_UART_LSR_PE_MASK, LSR_PAR_ERR) /* parity error */ 1520 MAP_FLAG(UMP_UART_LSR_PE_MASK, LSR_PAR_ERR) /* parity error */
1648 MAP_FLAG(UMP_UART_LSR_FE_MASK, LSR_FRM_ERR) /* framing error */ 1521 MAP_FLAG(UMP_UART_LSR_FE_MASK, LSR_FRM_ERR) /* framing error */
1649 MAP_FLAG(UMP_UART_LSR_BR_MASK, LSR_BREAK) /* break detected */ 1522 MAP_FLAG(UMP_UART_LSR_BR_MASK, LSR_BREAK) /* break detected */
1650 MAP_FLAG(UMP_UART_LSR_RX_MASK, LSR_RX_AVAIL) /* receive data available */ 1523 MAP_FLAG(UMP_UART_LSR_RX_MASK, LSR_RX_AVAIL) /* rx data available */
1651 MAP_FLAG(UMP_UART_LSR_TX_MASK, LSR_TX_EMPTY) /* transmit holding register empty */ 1524 MAP_FLAG(UMP_UART_LSR_TX_MASK, LSR_TX_EMPTY) /* tx hold reg empty */
1652 1525
1653#undef MAP_FLAG 1526#undef MAP_FLAG
1654 1527
1655 return lsr; 1528 return lsr;
1656} 1529}
1657 1530
1658static void handle_new_msr (struct edgeport_port *edge_port, __u8 msr) 1531static void handle_new_msr(struct edgeport_port *edge_port, __u8 msr)
1659{ 1532{
1660 struct async_icount *icount; 1533 struct async_icount *icount;
1661 struct tty_struct *tty; 1534 struct tty_struct *tty;
1662 1535
1663 dbg ("%s - %02x", __func__, msr); 1536 dbg("%s - %02x", __func__, msr);
1664 1537
1665 if (msr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR | EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) { 1538 if (msr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR |
1539 EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) {
1666 icount = &edge_port->icount; 1540 icount = &edge_port->icount;
1667 1541
1668 /* update input line counters */ 1542 /* update input line counters */
@@ -1674,7 +1548,7 @@ static void handle_new_msr (struct edgeport_port *edge_port, __u8 msr)
1674 icount->dcd++; 1548 icount->dcd++;
1675 if (msr & EDGEPORT_MSR_DELTA_RI) 1549 if (msr & EDGEPORT_MSR_DELTA_RI)
1676 icount->rng++; 1550 icount->rng++;
1677 wake_up_interruptible (&edge_port->delta_msr_wait); 1551 wake_up_interruptible(&edge_port->delta_msr_wait);
1678 } 1552 }
1679 1553
1680 /* Save the new modem status */ 1554 /* Save the new modem status */
@@ -1694,26 +1568,28 @@ static void handle_new_msr (struct edgeport_port *edge_port, __u8 msr)
1694 return; 1568 return;
1695} 1569}
1696 1570
1697static void handle_new_lsr (struct edgeport_port *edge_port, int lsr_data, __u8 lsr, __u8 data) 1571static void handle_new_lsr(struct edgeport_port *edge_port, int lsr_data,
1572 __u8 lsr, __u8 data)
1698{ 1573{
1699 struct async_icount *icount; 1574 struct async_icount *icount;
1700 __u8 new_lsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR | LSR_FRM_ERR | LSR_BREAK)); 1575 __u8 new_lsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR |
1576 LSR_FRM_ERR | LSR_BREAK));
1701 1577
1702 dbg ("%s - %02x", __func__, new_lsr); 1578 dbg("%s - %02x", __func__, new_lsr);
1703 1579
1704 edge_port->shadow_lsr = lsr; 1580 edge_port->shadow_lsr = lsr;
1705 1581
1706 if (new_lsr & LSR_BREAK) { 1582 if (new_lsr & LSR_BREAK)
1707 /* 1583 /*
1708 * Parity and Framing errors only count if they 1584 * Parity and Framing errors only count if they
1709 * occur exclusive of a break being received. 1585 * occur exclusive of a break being received.
1710 */ 1586 */
1711 new_lsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK); 1587 new_lsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK);
1712 }
1713 1588
1714 /* Place LSR data byte into Rx buffer */ 1589 /* Place LSR data byte into Rx buffer */
1715 if (lsr_data && edge_port->port->tty) 1590 if (lsr_data && edge_port->port->tty)
1716 edge_tty_recv(&edge_port->port->dev, edge_port->port->tty, &data, 1); 1591 edge_tty_recv(&edge_port->port->dev, edge_port->port->tty,
1592 &data, 1);
1717 1593
1718 /* update input line counters */ 1594 /* update input line counters */
1719 icount = &edge_port->icount; 1595 icount = &edge_port->icount;
@@ -1728,7 +1604,7 @@ static void handle_new_lsr (struct edgeport_port *edge_port, int lsr_data, __u8
1728} 1604}
1729 1605
1730 1606
1731static void edge_interrupt_callback (struct urb *urb) 1607static void edge_interrupt_callback(struct urb *urb)
1732{ 1608{
1733 struct edgeport_serial *edge_serial = urb->context; 1609 struct edgeport_serial *edge_serial = urb->context;
1734 struct usb_serial_port *port; 1610 struct usb_serial_port *port;
@@ -1762,66 +1638,71 @@ static void edge_interrupt_callback (struct urb *urb)
1762 } 1638 }
1763 1639
1764 if (!length) { 1640 if (!length) {
1765 dbg ("%s - no data in urb", __func__); 1641 dbg("%s - no data in urb", __func__);
1766 goto exit; 1642 goto exit;
1767 } 1643 }
1768 1644
1769 usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, __func__, length, data); 1645 usb_serial_debug_data(debug, &edge_serial->serial->dev->dev,
1770 1646 __func__, length, data);
1647
1771 if (length != 2) { 1648 if (length != 2) {
1772 dbg ("%s - expecting packet of size 2, got %d", __func__, length); 1649 dbg("%s - expecting packet of size 2, got %d",
1650 __func__, length);
1773 goto exit; 1651 goto exit;
1774 } 1652 }
1775 1653
1776 port_number = TIUMP_GET_PORT_FROM_CODE (data[0]); 1654 port_number = TIUMP_GET_PORT_FROM_CODE(data[0]);
1777 function = TIUMP_GET_FUNC_FROM_CODE (data[0]); 1655 function = TIUMP_GET_FUNC_FROM_CODE(data[0]);
1778 dbg ("%s - port_number %d, function %d, info 0x%x", 1656 dbg("%s - port_number %d, function %d, info 0x%x",
1779 __func__, port_number, function, data[1]); 1657 __func__, port_number, function, data[1]);
1780 port = edge_serial->serial->port[port_number]; 1658 port = edge_serial->serial->port[port_number];
1781 edge_port = usb_get_serial_port_data(port); 1659 edge_port = usb_get_serial_port_data(port);
1782 if (!edge_port) { 1660 if (!edge_port) {
1783 dbg ("%s - edge_port not found", __func__); 1661 dbg("%s - edge_port not found", __func__);
1784 return; 1662 return;
1785 } 1663 }
1786 switch (function) { 1664 switch (function) {
1787 case TIUMP_INTERRUPT_CODE_LSR: 1665 case TIUMP_INTERRUPT_CODE_LSR:
1788 lsr = MapLineStatus(data[1]); 1666 lsr = map_line_status(data[1]);
1789 if (lsr & UMP_UART_LSR_DATA_MASK) { 1667 if (lsr & UMP_UART_LSR_DATA_MASK) {
1790 /* Save the LSR event for bulk read completion routine */ 1668 /* Save the LSR event for bulk read
1791 dbg ("%s - LSR Event Port %u LSR Status = %02x", 1669 completion routine */
1670 dbg("%s - LSR Event Port %u LSR Status = %02x",
1792 __func__, port_number, lsr); 1671 __func__, port_number, lsr);
1793 edge_port->lsr_event = 1; 1672 edge_port->lsr_event = 1;
1794 edge_port->lsr_mask = lsr; 1673 edge_port->lsr_mask = lsr;
1795 } else { 1674 } else {
1796 dbg ("%s - ===== Port %d LSR Status = %02x ======", 1675 dbg("%s - ===== Port %d LSR Status = %02x ======",
1797 __func__, port_number, lsr); 1676 __func__, port_number, lsr);
1798 handle_new_lsr (edge_port, 0, lsr, 0); 1677 handle_new_lsr(edge_port, 0, lsr, 0);
1799 } 1678 }
1800 break; 1679 break;
1801 1680
1802 case TIUMP_INTERRUPT_CODE_MSR: // MSR 1681 case TIUMP_INTERRUPT_CODE_MSR: /* MSR */
1803 /* Copy MSR from UMP */ 1682 /* Copy MSR from UMP */
1804 msr = data[1]; 1683 msr = data[1];
1805 dbg ("%s - ===== Port %u MSR Status = %02x ======\n", 1684 dbg("%s - ===== Port %u MSR Status = %02x ======\n",
1806 __func__, port_number, msr); 1685 __func__, port_number, msr);
1807 handle_new_msr (edge_port, msr); 1686 handle_new_msr(edge_port, msr);
1808 break; 1687 break;
1809 1688
1810 default: 1689 default:
1811 dev_err (&urb->dev->dev, "%s - Unknown Interrupt code from UMP %x\n", 1690 dev_err(&urb->dev->dev,
1812 __func__, data[1]); 1691 "%s - Unknown Interrupt code from UMP %x\n",
1692 __func__, data[1]);
1813 break; 1693 break;
1814 1694
1815 } 1695 }
1816 1696
1817exit: 1697exit:
1818 retval = usb_submit_urb (urb, GFP_ATOMIC); 1698 retval = usb_submit_urb(urb, GFP_ATOMIC);
1819 if (retval) 1699 if (retval)
1820 dev_err (&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n", 1700 dev_err(&urb->dev->dev,
1701 "%s - usb_submit_urb failed with result %d\n",
1821 __func__, retval); 1702 __func__, retval);
1822} 1703}
1823 1704
1824static void edge_bulk_in_callback (struct urb *urb) 1705static void edge_bulk_in_callback(struct urb *urb)
1825{ 1706{
1826 struct edgeport_port *edge_port = urb->context; 1707 struct edgeport_port *edge_port = urb->context;
1827 unsigned char *data = urb->transfer_buffer; 1708 unsigned char *data = urb->transfer_buffer;
@@ -1844,15 +1725,16 @@ static void edge_bulk_in_callback (struct urb *urb)
1844 __func__, status); 1725 __func__, status);
1845 return; 1726 return;
1846 default: 1727 default:
1847 dev_err (&urb->dev->dev,"%s - nonzero read bulk status received: %d\n", 1728 dev_err(&urb->dev->dev,
1848 __func__, status); 1729 "%s - nonzero read bulk status received: %d\n",
1730 __func__, status);
1849 } 1731 }
1850 1732
1851 if (status == -EPIPE) 1733 if (status == -EPIPE)
1852 goto exit; 1734 goto exit;
1853 1735
1854 if (status) { 1736 if (status) {
1855 dev_err(&urb->dev->dev,"%s - stopping read!\n", __func__); 1737 dev_err(&urb->dev->dev, "%s - stopping read!\n", __func__);
1856 return; 1738 return;
1857 } 1739 }
1858 1740
@@ -1860,9 +1742,9 @@ static void edge_bulk_in_callback (struct urb *urb)
1860 1742
1861 if (edge_port->lsr_event) { 1743 if (edge_port->lsr_event) {
1862 edge_port->lsr_event = 0; 1744 edge_port->lsr_event = 0;
1863 dbg ("%s ===== Port %u LSR Status = %02x, Data = %02x ======", 1745 dbg("%s ===== Port %u LSR Status = %02x, Data = %02x ======",
1864 __func__, port_number, edge_port->lsr_mask, *data); 1746 __func__, port_number, edge_port->lsr_mask, *data);
1865 handle_new_lsr (edge_port, 1, edge_port->lsr_mask, *data); 1747 handle_new_lsr(edge_port, 1, edge_port->lsr_mask, *data);
1866 /* Adjust buffer length/pointer */ 1748 /* Adjust buffer length/pointer */
1867 --urb->actual_length; 1749 --urb->actual_length;
1868 ++data; 1750 ++data;
@@ -1870,13 +1752,14 @@ static void edge_bulk_in_callback (struct urb *urb)
1870 1752
1871 tty = edge_port->port->tty; 1753 tty = edge_port->port->tty;
1872 if (tty && urb->actual_length) { 1754 if (tty && urb->actual_length) {
1873 usb_serial_debug_data(debug, &edge_port->port->dev, __func__, urb->actual_length, data); 1755 usb_serial_debug_data(debug, &edge_port->port->dev,
1874 1756 __func__, urb->actual_length, data);
1875 if (edge_port->close_pending) { 1757 if (edge_port->close_pending)
1876 dbg ("%s - close is pending, dropping data on the floor.", __func__); 1758 dbg("%s - close pending, dropping data on the floor",
1877 } else { 1759 __func__);
1878 edge_tty_recv(&edge_port->port->dev, tty, data, urb->actual_length); 1760 else
1879 } 1761 edge_tty_recv(&edge_port->port->dev, tty, data,
1762 urb->actual_length);
1880 edge_port->icount.rx += urb->actual_length; 1763 edge_port->icount.rx += urb->actual_length;
1881 } 1764 }
1882 1765
@@ -1891,37 +1774,31 @@ exit:
1891 } 1774 }
1892 spin_unlock(&edge_port->ep_lock); 1775 spin_unlock(&edge_port->ep_lock);
1893 if (retval) 1776 if (retval)
1894 dev_err (&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n", 1777 dev_err(&urb->dev->dev,
1778 "%s - usb_submit_urb failed with result %d\n",
1895 __func__, retval); 1779 __func__, retval);
1896} 1780}
1897 1781
1898static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned char *data, int length) 1782static void edge_tty_recv(struct device *dev, struct tty_struct *tty,
1783 unsigned char *data, int length)
1899{ 1784{
1900 int cnt; 1785 int queued;
1901
1902 do {
1903 cnt = tty_buffer_request_room(tty, length);
1904 if (cnt < length) {
1905 dev_err(dev, "%s - dropping data, %d bytes lost\n",
1906 __func__, length - cnt);
1907 if(cnt == 0)
1908 break;
1909 }
1910 tty_insert_flip_string(tty, data, cnt);
1911 data += cnt;
1912 length -= cnt;
1913 } while (length > 0);
1914 1786
1787 tty_buffer_request_room(tty, length);
1788 queued = tty_insert_flip_string(tty, data, length);
1789 if (queued < length)
1790 dev_err(dev, "%s - dropping data, %d bytes lost\n",
1791 __func__, length - queued);
1915 tty_flip_buffer_push(tty); 1792 tty_flip_buffer_push(tty);
1916} 1793}
1917 1794
1918static void edge_bulk_out_callback (struct urb *urb) 1795static void edge_bulk_out_callback(struct urb *urb)
1919{ 1796{
1920 struct usb_serial_port *port = urb->context; 1797 struct usb_serial_port *port = urb->context;
1921 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1798 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1922 int status = urb->status; 1799 int status = urb->status;
1923 1800
1924 dbg ("%s - port %d", __func__, port->number); 1801 dbg("%s - port %d", __func__, port->number);
1925 1802
1926 edge_port->ep_write_urb_in_use = 0; 1803 edge_port->ep_write_urb_in_use = 0;
1927 1804
@@ -1945,7 +1822,7 @@ static void edge_bulk_out_callback (struct urb *urb)
1945 edge_send(port); 1822 edge_send(port);
1946} 1823}
1947 1824
1948static int edge_open (struct usb_serial_port *port, struct file * filp) 1825static int edge_open(struct usb_serial_port *port, struct file *filp)
1949{ 1826{
1950 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1827 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1951 struct edgeport_serial *edge_serial; 1828 struct edgeport_serial *edge_serial;
@@ -1965,118 +1842,119 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
1965 1842
1966 port_number = port->number - port->serial->minor; 1843 port_number = port->number - port->serial->minor;
1967 switch (port_number) { 1844 switch (port_number) {
1968 case 0: 1845 case 0:
1969 edge_port->uart_base = UMPMEM_BASE_UART1; 1846 edge_port->uart_base = UMPMEM_BASE_UART1;
1970 edge_port->dma_address = UMPD_OEDB1_ADDRESS; 1847 edge_port->dma_address = UMPD_OEDB1_ADDRESS;
1971 break; 1848 break;
1972 case 1: 1849 case 1:
1973 edge_port->uart_base = UMPMEM_BASE_UART2; 1850 edge_port->uart_base = UMPMEM_BASE_UART2;
1974 edge_port->dma_address = UMPD_OEDB2_ADDRESS; 1851 edge_port->dma_address = UMPD_OEDB2_ADDRESS;
1975 break; 1852 break;
1976 default: 1853 default:
1977 dev_err (&port->dev, "Unknown port number!!!\n"); 1854 dev_err(&port->dev, "Unknown port number!!!\n");
1978 return -ENODEV; 1855 return -ENODEV;
1979 } 1856 }
1980 1857
1981 dbg ("%s - port_number = %d, uart_base = %04x, dma_address = %04x", 1858 dbg("%s - port_number = %d, uart_base = %04x, dma_address = %04x",
1982 __func__, port_number, edge_port->uart_base, edge_port->dma_address); 1859 __func__, port_number, edge_port->uart_base,
1860 edge_port->dma_address);
1983 1861
1984 dev = port->serial->dev; 1862 dev = port->serial->dev;
1985 1863
1986 memset (&(edge_port->icount), 0x00, sizeof(edge_port->icount)); 1864 memset(&(edge_port->icount), 0x00, sizeof(edge_port->icount));
1987 init_waitqueue_head (&edge_port->delta_msr_wait); 1865 init_waitqueue_head(&edge_port->delta_msr_wait);
1988 1866
1989 /* turn off loopback */ 1867 /* turn off loopback */
1990 status = TIClearLoopBack (edge_port); 1868 status = ti_do_config(edge_port, UMPC_SET_CLR_LOOPBACK, 0);
1991 if (status) { 1869 if (status) {
1992 dev_err(&port->dev,"%s - cannot send clear loopback command, %d\n", 1870 dev_err(&port->dev,
1871 "%s - cannot send clear loopback command, %d\n",
1993 __func__, status); 1872 __func__, status);
1994 return status; 1873 return status;
1995 } 1874 }
1996 1875
1997 /* set up the port settings */ 1876 /* set up the port settings */
1998 edge_set_termios (port, port->tty->termios); 1877 edge_set_termios(port, port->tty->termios);
1999 1878
2000 /* open up the port */ 1879 /* open up the port */
2001 1880
2002 /* milliseconds to timeout for DMA transfer */ 1881 /* milliseconds to timeout for DMA transfer */
2003 transaction_timeout = 2; 1882 transaction_timeout = 2;
2004 1883
2005 edge_port->ump_read_timeout = max (20, ((transaction_timeout * 3) / 2) ); 1884 edge_port->ump_read_timeout =
1885 max(20, ((transaction_timeout * 3) / 2));
2006 1886
2007 // milliseconds to timeout for DMA transfer 1887 /* milliseconds to timeout for DMA transfer */
2008 open_settings = (u8)(UMP_DMA_MODE_CONTINOUS | 1888 open_settings = (u8)(UMP_DMA_MODE_CONTINOUS |
2009 UMP_PIPE_TRANS_TIMEOUT_ENA | 1889 UMP_PIPE_TRANS_TIMEOUT_ENA |
2010 (transaction_timeout << 2)); 1890 (transaction_timeout << 2));
2011 1891
2012 dbg ("%s - Sending UMPC_OPEN_PORT", __func__); 1892 dbg("%s - Sending UMPC_OPEN_PORT", __func__);
2013 1893
2014 /* Tell TI to open and start the port */ 1894 /* Tell TI to open and start the port */
2015 status = TIWriteCommandSync (dev, 1895 status = send_cmd(dev, UMPC_OPEN_PORT,
2016 UMPC_OPEN_PORT, 1896 (u8)(UMPM_UART1_PORT + port_number), open_settings, NULL, 0);
2017 (u8)(UMPM_UART1_PORT + port_number),
2018 open_settings,
2019 NULL,
2020 0);
2021 if (status) { 1897 if (status) {
2022 dev_err(&port->dev,"%s - cannot send open command, %d\n", __func__, status); 1898 dev_err(&port->dev, "%s - cannot send open command, %d\n",
1899 __func__, status);
2023 return status; 1900 return status;
2024 } 1901 }
2025 1902
2026 /* Start the DMA? */ 1903 /* Start the DMA? */
2027 status = TIWriteCommandSync (dev, 1904 status = send_cmd(dev, UMPC_START_PORT,
2028 UMPC_START_PORT, 1905 (u8)(UMPM_UART1_PORT + port_number), 0, NULL, 0);
2029 (u8)(UMPM_UART1_PORT + port_number),
2030 0,
2031 NULL,
2032 0);
2033 if (status) { 1906 if (status) {
2034 dev_err(&port->dev,"%s - cannot send start DMA command, %d\n", __func__, status); 1907 dev_err(&port->dev, "%s - cannot send start DMA command, %d\n",
1908 __func__, status);
2035 return status; 1909 return status;
2036 } 1910 }
2037 1911
2038 /* Clear TX and RX buffers in UMP */ 1912 /* Clear TX and RX buffers in UMP */
2039 status = TIPurgeDataSync (port, UMP_PORT_DIR_OUT | UMP_PORT_DIR_IN); 1913 status = purge_port(port, UMP_PORT_DIR_OUT | UMP_PORT_DIR_IN);
2040 if (status) { 1914 if (status) {
2041 dev_err(&port->dev,"%s - cannot send clear buffers command, %d\n", __func__, status); 1915 dev_err(&port->dev,
1916 "%s - cannot send clear buffers command, %d\n",
1917 __func__, status);
2042 return status; 1918 return status;
2043 } 1919 }
2044 1920
2045 /* Read Initial MSR */ 1921 /* Read Initial MSR */
2046 status = TIReadVendorRequestSync (dev, 1922 status = ti_vread_sync(dev, UMPC_READ_MSR, 0,
2047 UMPC_READ_MSR, // Request 1923 (__u16)(UMPM_UART1_PORT + port_number),
2048 0, // wValue 1924 &edge_port->shadow_msr, 1);
2049 (__u16)(UMPM_UART1_PORT + port_number), // wIndex (Address)
2050 &edge_port->shadow_msr, // TransferBuffer
2051 1); // TransferBufferLength
2052 if (status) { 1925 if (status) {
2053 dev_err(&port->dev,"%s - cannot send read MSR command, %d\n", __func__, status); 1926 dev_err(&port->dev, "%s - cannot send read MSR command, %d\n",
1927 __func__, status);
2054 return status; 1928 return status;
2055 } 1929 }
2056 1930
2057 dbg ("ShadowMSR 0x%X", edge_port->shadow_msr); 1931 dbg("ShadowMSR 0x%X", edge_port->shadow_msr);
2058 1932
2059 /* Set Initial MCR */ 1933 /* Set Initial MCR */
2060 edge_port->shadow_mcr = MCR_RTS | MCR_DTR; 1934 edge_port->shadow_mcr = MCR_RTS | MCR_DTR;
2061 dbg ("ShadowMCR 0x%X", edge_port->shadow_mcr); 1935 dbg("ShadowMCR 0x%X", edge_port->shadow_mcr);
2062 1936
2063 edge_serial = edge_port->edge_serial; 1937 edge_serial = edge_port->edge_serial;
2064 if (mutex_lock_interruptible(&edge_serial->es_lock)) 1938 if (mutex_lock_interruptible(&edge_serial->es_lock))
2065 return -ERESTARTSYS; 1939 return -ERESTARTSYS;
2066 if (edge_serial->num_ports_open == 0) { 1940 if (edge_serial->num_ports_open == 0) {
2067 /* we are the first port to be opened, let's post the interrupt urb */ 1941 /* we are the first port to open, post the interrupt urb */
2068 urb = edge_serial->serial->port[0]->interrupt_in_urb; 1942 urb = edge_serial->serial->port[0]->interrupt_in_urb;
2069 if (!urb) { 1943 if (!urb) {
2070 dev_err (&port->dev, "%s - no interrupt urb present, exiting\n", __func__); 1944 dev_err(&port->dev,
1945 "%s - no interrupt urb present, exiting\n",
1946 __func__);
2071 status = -EINVAL; 1947 status = -EINVAL;
2072 goto release_es_lock; 1948 goto release_es_lock;
2073 } 1949 }
2074 urb->complete = edge_interrupt_callback; 1950 urb->complete = edge_interrupt_callback;
2075 urb->context = edge_serial; 1951 urb->context = edge_serial;
2076 urb->dev = dev; 1952 urb->dev = dev;
2077 status = usb_submit_urb (urb, GFP_KERNEL); 1953 status = usb_submit_urb(urb, GFP_KERNEL);
2078 if (status) { 1954 if (status) {
2079 dev_err (&port->dev, "%s - usb_submit_urb failed with value %d\n", __func__, status); 1955 dev_err(&port->dev,
1956 "%s - usb_submit_urb failed with value %d\n",
1957 __func__, status);
2080 goto release_es_lock; 1958 goto release_es_lock;
2081 } 1959 }
2082 } 1960 }
@@ -2085,13 +1963,14 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
2085 * reset the data toggle on the bulk endpoints to work around bug in 1963 * reset the data toggle on the bulk endpoints to work around bug in
2086 * host controllers where things get out of sync some times 1964 * host controllers where things get out of sync some times
2087 */ 1965 */
2088 usb_clear_halt (dev, port->write_urb->pipe); 1966 usb_clear_halt(dev, port->write_urb->pipe);
2089 usb_clear_halt (dev, port->read_urb->pipe); 1967 usb_clear_halt(dev, port->read_urb->pipe);
2090 1968
2091 /* start up our bulk read urb */ 1969 /* start up our bulk read urb */
2092 urb = port->read_urb; 1970 urb = port->read_urb;
2093 if (!urb) { 1971 if (!urb) {
2094 dev_err (&port->dev, "%s - no read urb present, exiting\n", __func__); 1972 dev_err(&port->dev, "%s - no read urb present, exiting\n",
1973 __func__);
2095 status = -EINVAL; 1974 status = -EINVAL;
2096 goto unlink_int_urb; 1975 goto unlink_int_urb;
2097 } 1976 }
@@ -2099,9 +1978,11 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
2099 urb->complete = edge_bulk_in_callback; 1978 urb->complete = edge_bulk_in_callback;
2100 urb->context = edge_port; 1979 urb->context = edge_port;
2101 urb->dev = dev; 1980 urb->dev = dev;
2102 status = usb_submit_urb (urb, GFP_KERNEL); 1981 status = usb_submit_urb(urb, GFP_KERNEL);
2103 if (status) { 1982 if (status) {
2104 dev_err (&port->dev, "%s - read bulk usb_submit_urb failed with value %d\n", __func__, status); 1983 dev_err(&port->dev,
1984 "%s - read bulk usb_submit_urb failed with value %d\n",
1985 __func__, status);
2105 goto unlink_int_urb; 1986 goto unlink_int_urb;
2106 } 1987 }
2107 1988
@@ -2119,7 +2000,7 @@ release_es_lock:
2119 return status; 2000 return status;
2120} 2001}
2121 2002
2122static void edge_close (struct usb_serial_port *port, struct file *filp) 2003static void edge_close(struct usb_serial_port *port, struct file *filp)
2123{ 2004{
2124 struct edgeport_serial *edge_serial; 2005 struct edgeport_serial *edge_serial;
2125 struct edgeport_port *edge_port; 2006 struct edgeport_port *edge_port;
@@ -2127,18 +2008,18 @@ static void edge_close (struct usb_serial_port *port, struct file *filp)
2127 int status; 2008 int status;
2128 2009
2129 dbg("%s - port %d", __func__, port->number); 2010 dbg("%s - port %d", __func__, port->number);
2130 2011
2131 edge_serial = usb_get_serial_data(port->serial); 2012 edge_serial = usb_get_serial_data(port->serial);
2132 edge_port = usb_get_serial_port_data(port); 2013 edge_port = usb_get_serial_port_data(port);
2133 if ((edge_serial == NULL) || (edge_port == NULL)) 2014 if (edge_serial == NULL || edge_port == NULL)
2134 return; 2015 return;
2135 2016
2136 /* The bulkreadcompletion routine will check 2017 /* The bulkreadcompletion routine will check
2137 * this flag and dump add read data */ 2018 * this flag and dump add read data */
2138 edge_port->close_pending = 1; 2019 edge_port->close_pending = 1;
2139 2020
2140 /* chase the port close and flush */ 2021 /* chase the port close and flush */
2141 TIChasePort (edge_port, (HZ*closing_wait)/100, 1); 2022 chase_port(edge_port, (HZ * closing_wait) / 100, 1);
2142 2023
2143 usb_kill_urb(port->read_urb); 2024 usb_kill_urb(port->read_urb);
2144 usb_kill_urb(port->write_urb); 2025 usb_kill_urb(port->write_urb);
@@ -2148,7 +2029,7 @@ static void edge_close (struct usb_serial_port *port, struct file *filp)
2148 * send a close port command to it */ 2029 * send a close port command to it */
2149 dbg("%s - send umpc_close_port", __func__); 2030 dbg("%s - send umpc_close_port", __func__);
2150 port_number = port->number - port->serial->minor; 2031 port_number = port->number - port->serial->minor;
2151 status = TIWriteCommandSync (port->serial->dev, 2032 status = send_cmd(port->serial->dev,
2152 UMPC_CLOSE_PORT, 2033 UMPC_CLOSE_PORT,
2153 (__u8)(UMPM_UART1_PORT + port_number), 2034 (__u8)(UMPM_UART1_PORT + port_number),
2154 0, 2035 0,
@@ -2167,7 +2048,8 @@ static void edge_close (struct usb_serial_port *port, struct file *filp)
2167 dbg("%s - exited", __func__); 2048 dbg("%s - exited", __func__);
2168} 2049}
2169 2050
2170static int edge_write (struct usb_serial_port *port, const unsigned char *data, int count) 2051static int edge_write(struct usb_serial_port *port, const unsigned char *data,
2052 int count)
2171{ 2053{
2172 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2054 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2173 unsigned long flags; 2055 unsigned long flags;
@@ -2223,11 +2105,12 @@ static void edge_send(struct usb_serial_port *port)
2223 2105
2224 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 2106 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2225 2107
2226 usb_serial_debug_data(debug, &port->dev, __func__, count, port->write_urb->transfer_buffer); 2108 usb_serial_debug_data(debug, &port->dev, __func__, count,
2109 port->write_urb->transfer_buffer);
2227 2110
2228 /* set up our urb */ 2111 /* set up our urb */
2229 usb_fill_bulk_urb (port->write_urb, port->serial->dev, 2112 usb_fill_bulk_urb(port->write_urb, port->serial->dev,
2230 usb_sndbulkpipe (port->serial->dev, 2113 usb_sndbulkpipe(port->serial->dev,
2231 port->bulk_out_endpointAddress), 2114 port->bulk_out_endpointAddress),
2232 port->write_urb->transfer_buffer, count, 2115 port->write_urb->transfer_buffer, count,
2233 edge_bulk_out_callback, 2116 edge_bulk_out_callback,
@@ -2236,22 +2119,21 @@ static void edge_send(struct usb_serial_port *port)
2236 /* send the data out the bulk port */ 2119 /* send the data out the bulk port */
2237 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 2120 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
2238 if (result) { 2121 if (result) {
2239 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result); 2122 dev_err(&port->dev,
2123 "%s - failed submitting write urb, error %d\n",
2124 __func__, result);
2240 edge_port->ep_write_urb_in_use = 0; 2125 edge_port->ep_write_urb_in_use = 0;
2241 // TODO: reschedule edge_send 2126 /* TODO: reschedule edge_send */
2242 } else { 2127 } else
2243 edge_port->icount.tx += count; 2128 edge_port->icount.tx += count;
2244 }
2245 2129
2246 /* wakeup any process waiting for writes to complete */ 2130 /* wakeup any process waiting for writes to complete */
2247 /* there is now more room in the buffer for new writes */ 2131 /* there is now more room in the buffer for new writes */
2248 if (tty) { 2132 if (tty)
2249 /* let the tty driver wakeup if it has a special write_wakeup function */
2250 tty_wakeup(tty); 2133 tty_wakeup(tty);
2251 }
2252} 2134}
2253 2135
2254static int edge_write_room (struct usb_serial_port *port) 2136static int edge_write_room(struct usb_serial_port *port)
2255{ 2137{
2256 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2138 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2257 int room = 0; 2139 int room = 0;
@@ -2260,9 +2142,9 @@ static int edge_write_room (struct usb_serial_port *port)
2260 dbg("%s - port %d", __func__, port->number); 2142 dbg("%s - port %d", __func__, port->number);
2261 2143
2262 if (edge_port == NULL) 2144 if (edge_port == NULL)
2263 return -ENODEV; 2145 return 0;
2264 if (edge_port->close_pending == 1) 2146 if (edge_port->close_pending == 1)
2265 return -ENODEV; 2147 return 0;
2266 2148
2267 spin_lock_irqsave(&edge_port->ep_lock, flags); 2149 spin_lock_irqsave(&edge_port->ep_lock, flags);
2268 room = edge_buf_space_avail(edge_port->ep_out_buf); 2150 room = edge_buf_space_avail(edge_port->ep_out_buf);
@@ -2272,7 +2154,7 @@ static int edge_write_room (struct usb_serial_port *port)
2272 return room; 2154 return room;
2273} 2155}
2274 2156
2275static int edge_chars_in_buffer (struct usb_serial_port *port) 2157static int edge_chars_in_buffer(struct usb_serial_port *port)
2276{ 2158{
2277 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2159 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2278 int chars = 0; 2160 int chars = 0;
@@ -2281,22 +2163,22 @@ static int edge_chars_in_buffer (struct usb_serial_port *port)
2281 dbg("%s - port %d", __func__, port->number); 2163 dbg("%s - port %d", __func__, port->number);
2282 2164
2283 if (edge_port == NULL) 2165 if (edge_port == NULL)
2284 return -ENODEV; 2166 return 0;
2285 if (edge_port->close_pending == 1) 2167 if (edge_port->close_pending == 1)
2286 return -ENODEV; 2168 return 0;
2287 2169
2288 spin_lock_irqsave(&edge_port->ep_lock, flags); 2170 spin_lock_irqsave(&edge_port->ep_lock, flags);
2289 chars = edge_buf_data_avail(edge_port->ep_out_buf); 2171 chars = edge_buf_data_avail(edge_port->ep_out_buf);
2290 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 2172 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2291 2173
2292 dbg ("%s - returns %d", __func__, chars); 2174 dbg("%s - returns %d", __func__, chars);
2293 return chars; 2175 return chars;
2294} 2176}
2295 2177
2296static void edge_throttle (struct usb_serial_port *port) 2178static void edge_throttle(struct usb_serial_port *port)
2297{ 2179{
2298 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2180 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2299 struct tty_struct *tty; 2181 struct tty_struct *tty = port->tty;
2300 int status; 2182 int status;
2301 2183
2302 dbg("%s - port %d", __func__, port->number); 2184 dbg("%s - port %d", __func__, port->number);
@@ -2304,19 +2186,14 @@ static void edge_throttle (struct usb_serial_port *port)
2304 if (edge_port == NULL) 2186 if (edge_port == NULL)
2305 return; 2187 return;
2306 2188
2307 tty = port->tty;
2308 if (!tty) {
2309 dbg ("%s - no tty available", __func__);
2310 return;
2311 }
2312
2313 /* if we are implementing XON/XOFF, send the stop character */ 2189 /* if we are implementing XON/XOFF, send the stop character */
2314 if (I_IXOFF(tty)) { 2190 if (I_IXOFF(tty)) {
2315 unsigned char stop_char = STOP_CHAR(tty); 2191 unsigned char stop_char = STOP_CHAR(tty);
2316 status = edge_write (port, &stop_char, 1); 2192 status = edge_write(port, &stop_char, 1);
2317 if (status <= 0) { 2193 if (status <= 0)
2318 dev_err(&port->dev, "%s - failed to write stop character, %d\n", __func__, status); 2194 dev_err(&port->dev,
2319 } 2195 "%s - failed to write stop character, %d\n",
2196 __func__, status);
2320 } 2197 }
2321 2198
2322 /* if we are implementing RTS/CTS, stop reads */ 2199 /* if we are implementing RTS/CTS, stop reads */
@@ -2326,10 +2203,10 @@ static void edge_throttle (struct usb_serial_port *port)
2326 2203
2327} 2204}
2328 2205
2329static void edge_unthrottle (struct usb_serial_port *port) 2206static void edge_unthrottle(struct usb_serial_port *port)
2330{ 2207{
2331 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2208 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2332 struct tty_struct *tty; 2209 struct tty_struct *tty = port->tty;
2333 int status; 2210 int status;
2334 2211
2335 dbg("%s - port %d", __func__, port->number); 2212 dbg("%s - port %d", __func__, port->number);
@@ -2337,27 +2214,23 @@ static void edge_unthrottle (struct usb_serial_port *port)
2337 if (edge_port == NULL) 2214 if (edge_port == NULL)
2338 return; 2215 return;
2339 2216
2340 tty = port->tty;
2341 if (!tty) {
2342 dbg ("%s - no tty available", __func__);
2343 return;
2344 }
2345
2346 /* if we are implementing XON/XOFF, send the start character */ 2217 /* if we are implementing XON/XOFF, send the start character */
2347 if (I_IXOFF(tty)) { 2218 if (I_IXOFF(tty)) {
2348 unsigned char start_char = START_CHAR(tty); 2219 unsigned char start_char = START_CHAR(tty);
2349 status = edge_write (port, &start_char, 1); 2220 status = edge_write(port, &start_char, 1);
2350 if (status <= 0) { 2221 if (status <= 0)
2351 dev_err(&port->dev, "%s - failed to write start character, %d\n", __func__, status); 2222 dev_err(&port->dev,
2352 } 2223 "%s - failed to write start character, %d\n",
2224 __func__, status);
2353 } 2225 }
2354
2355 /* if we are implementing RTS/CTS, restart reads */ 2226 /* if we are implementing RTS/CTS, restart reads */
2356 /* are the Edgeport will assert the RTS line */ 2227 /* are the Edgeport will assert the RTS line */
2357 if (C_CRTSCTS(tty)) { 2228 if (C_CRTSCTS(tty)) {
2358 status = restart_read(edge_port); 2229 status = restart_read(edge_port);
2359 if (status) 2230 if (status)
2360 dev_err(&port->dev, "%s - read bulk usb_submit_urb failed with value %d\n", __func__, status); 2231 dev_err(&port->dev,
2232 "%s - read bulk usb_submit_urb failed: %d\n",
2233 __func__, status);
2361 } 2234 }
2362 2235
2363} 2236}
@@ -2398,22 +2271,26 @@ static int restart_read(struct edgeport_port *edge_port)
2398 return status; 2271 return status;
2399} 2272}
2400 2273
2401static void change_port_settings (struct edgeport_port *edge_port, struct ktermios *old_termios) 2274static void change_port_settings(struct edgeport_port *edge_port,
2275 struct ktermios *old_termios)
2402{ 2276{
2403 struct ump_uart_config *config; 2277 struct ump_uart_config *config;
2404 struct tty_struct *tty; 2278 struct tty_struct *tty;
2405 int baud; 2279 int baud;
2406 unsigned cflag; 2280 unsigned cflag;
2407 int status; 2281 int status;
2408 int port_number = edge_port->port->number - edge_port->port->serial->minor; 2282 int port_number = edge_port->port->number -
2283 edge_port->port->serial->minor;
2409 2284
2410 dbg("%s - port %d", __func__, edge_port->port->number); 2285 dbg("%s - port %d", __func__, edge_port->port->number);
2411 2286
2412 tty = edge_port->port->tty; 2287 tty = edge_port->port->tty;
2413 2288
2414 config = kmalloc (sizeof (*config), GFP_KERNEL); 2289 config = kmalloc(sizeof(*config), GFP_KERNEL);
2415 if (!config) { 2290 if (!config) {
2416 dev_err (&edge_port->port->dev, "%s - out of memory\n", __func__); 2291 *tty->termios = *old_termios;
2292 dev_err(&edge_port->port->dev, "%s - out of memory\n",
2293 __func__);
2417 return; 2294 return;
2418 } 2295 }
2419 2296
@@ -2427,22 +2304,22 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2427 config->bUartMode = (__u8)(edge_port->bUartMode); 2304 config->bUartMode = (__u8)(edge_port->bUartMode);
2428 2305
2429 switch (cflag & CSIZE) { 2306 switch (cflag & CSIZE) {
2430 case CS5: 2307 case CS5:
2431 config->bDataBits = UMP_UART_CHAR5BITS; 2308 config->bDataBits = UMP_UART_CHAR5BITS;
2432 dbg ("%s - data bits = 5", __func__); 2309 dbg("%s - data bits = 5", __func__);
2433 break; 2310 break;
2434 case CS6: 2311 case CS6:
2435 config->bDataBits = UMP_UART_CHAR6BITS; 2312 config->bDataBits = UMP_UART_CHAR6BITS;
2436 dbg ("%s - data bits = 6", __func__); 2313 dbg("%s - data bits = 6", __func__);
2437 break; 2314 break;
2438 case CS7: 2315 case CS7:
2439 config->bDataBits = UMP_UART_CHAR7BITS; 2316 config->bDataBits = UMP_UART_CHAR7BITS;
2440 dbg ("%s - data bits = 7", __func__); 2317 dbg("%s - data bits = 7", __func__);
2441 break; 2318 break;
2442 default: 2319 default:
2443 case CS8: 2320 case CS8:
2444 config->bDataBits = UMP_UART_CHAR8BITS; 2321 config->bDataBits = UMP_UART_CHAR8BITS;
2445 dbg ("%s - data bits = 8", __func__); 2322 dbg("%s - data bits = 8", __func__);
2446 break; 2323 break;
2447 } 2324 }
2448 2325
@@ -2457,7 +2334,7 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2457 dbg("%s - parity = even", __func__); 2334 dbg("%s - parity = even", __func__);
2458 } 2335 }
2459 } else { 2336 } else {
2460 config->bParity = UMP_UART_NOPARITY; 2337 config->bParity = UMP_UART_NOPARITY;
2461 dbg("%s - parity = none", __func__); 2338 dbg("%s - parity = none", __func__);
2462 } 2339 }
2463 2340
@@ -2480,29 +2357,26 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2480 restart_read(edge_port); 2357 restart_read(edge_port);
2481 } 2358 }
2482 2359
2483 /* if we are implementing XON/XOFF, set the start and stop character in the device */ 2360 /* if we are implementing XON/XOFF, set the start and stop
2484 if (I_IXOFF(tty) || I_IXON(tty)) { 2361 character in the device */
2485 config->cXon = START_CHAR(tty); 2362 config->cXon = START_CHAR(tty);
2486 config->cXoff = STOP_CHAR(tty); 2363 config->cXoff = STOP_CHAR(tty);
2487 2364
2488 /* if we are implementing INBOUND XON/XOFF */ 2365 /* if we are implementing INBOUND XON/XOFF */
2489 if (I_IXOFF(tty)) { 2366 if (I_IXOFF(tty)) {
2490 config->wFlags |= UMP_MASK_UART_FLAGS_IN_X; 2367 config->wFlags |= UMP_MASK_UART_FLAGS_IN_X;
2491 dbg ("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", 2368 dbg("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2492 __func__, config->cXon, config->cXoff); 2369 __func__, config->cXon, config->cXoff);
2493 } else { 2370 } else
2494 dbg ("%s - INBOUND XON/XOFF is disabled", __func__); 2371 dbg("%s - INBOUND XON/XOFF is disabled", __func__);
2495 }
2496 2372
2497 /* if we are implementing OUTBOUND XON/XOFF */ 2373 /* if we are implementing OUTBOUND XON/XOFF */
2498 if (I_IXON(tty)) { 2374 if (I_IXON(tty)) {
2499 config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X; 2375 config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X;
2500 dbg ("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", 2376 dbg("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2501 __func__, config->cXon, config->cXoff); 2377 __func__, config->cXon, config->cXoff);
2502 } else { 2378 } else
2503 dbg ("%s - OUTBOUND XON/XOFF is disabled", __func__); 2379 dbg("%s - OUTBOUND XON/XOFF is disabled", __func__);
2504 }
2505 }
2506 2380
2507 tty->termios->c_cflag &= ~CMSPAR; 2381 tty->termios->c_cflag &= ~CMSPAR;
2508 2382
@@ -2519,62 +2393,52 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2519 2393
2520 /* FIXME: Recompute actual baud from divisor here */ 2394 /* FIXME: Recompute actual baud from divisor here */
2521 2395
2522 dbg ("%s - baud rate = %d, wBaudRate = %d", __func__, baud, config->wBaudRate); 2396 dbg("%s - baud rate = %d, wBaudRate = %d", __func__, baud,
2397 config->wBaudRate);
2523 2398
2524 dbg ("wBaudRate: %d", (int)(461550L / config->wBaudRate)); 2399 dbg("wBaudRate: %d", (int)(461550L / config->wBaudRate));
2525 dbg ("wFlags: 0x%x", config->wFlags); 2400 dbg("wFlags: 0x%x", config->wFlags);
2526 dbg ("bDataBits: %d", config->bDataBits); 2401 dbg("bDataBits: %d", config->bDataBits);
2527 dbg ("bParity: %d", config->bParity); 2402 dbg("bParity: %d", config->bParity);
2528 dbg ("bStopBits: %d", config->bStopBits); 2403 dbg("bStopBits: %d", config->bStopBits);
2529 dbg ("cXon: %d", config->cXon); 2404 dbg("cXon: %d", config->cXon);
2530 dbg ("cXoff: %d", config->cXoff); 2405 dbg("cXoff: %d", config->cXoff);
2531 dbg ("bUartMode: %d", config->bUartMode); 2406 dbg("bUartMode: %d", config->bUartMode);
2532 2407
2533 /* move the word values into big endian mode */ 2408 /* move the word values into big endian mode */
2534 cpu_to_be16s (&config->wFlags); 2409 cpu_to_be16s(&config->wFlags);
2535 cpu_to_be16s (&config->wBaudRate); 2410 cpu_to_be16s(&config->wBaudRate);
2536 2411
2537 status = TIWriteCommandSync (edge_port->port->serial->dev, 2412 status = send_cmd(edge_port->port->serial->dev, UMPC_SET_CONFIG,
2538 UMPC_SET_CONFIG,
2539 (__u8)(UMPM_UART1_PORT + port_number), 2413 (__u8)(UMPM_UART1_PORT + port_number),
2540 0, 2414 0, (__u8 *)config, sizeof(*config));
2541 (__u8 *)config, 2415 if (status)
2542 sizeof(*config)); 2416 dbg("%s - error %d when trying to write config to device",
2543 if (status) {
2544 dbg ("%s - error %d when trying to write config to device",
2545 __func__, status); 2417 __func__, status);
2546 } 2418 kfree(config);
2547
2548 kfree (config);
2549
2550 return; 2419 return;
2551} 2420}
2552 2421
2553static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old_termios) 2422static void edge_set_termios(struct usb_serial_port *port,
2423 struct ktermios *old_termios)
2554{ 2424{
2555 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2425 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2556 struct tty_struct *tty = port->tty; 2426 struct tty_struct *tty = port->tty;
2557 unsigned int cflag;
2558
2559 cflag = tty->termios->c_cflag;
2560 2427
2561 dbg("%s - clfag %08x iflag %08x", __func__, 2428 dbg("%s - clfag %08x iflag %08x", __func__,
2562 tty->termios->c_cflag, tty->termios->c_iflag); 2429 tty->termios->c_cflag, tty->termios->c_iflag);
2563 dbg("%s - old clfag %08x old iflag %08x", __func__, 2430 dbg("%s - old clfag %08x old iflag %08x", __func__,
2564 old_termios->c_cflag, old_termios->c_iflag); 2431 old_termios->c_cflag, old_termios->c_iflag);
2565
2566 dbg("%s - port %d", __func__, port->number); 2432 dbg("%s - port %d", __func__, port->number);
2567 2433
2568 if (edge_port == NULL) 2434 if (edge_port == NULL)
2569 return; 2435 return;
2570
2571 /* change the port settings to the new ones specified */ 2436 /* change the port settings to the new ones specified */
2572 change_port_settings (edge_port, old_termios); 2437 change_port_settings(edge_port, old_termios);
2573
2574 return;
2575} 2438}
2576 2439
2577static int edge_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear) 2440static int edge_tiocmset(struct usb_serial_port *port, struct file *file,
2441 unsigned int set, unsigned int clear)
2578{ 2442{
2579 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2443 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2580 unsigned int mcr; 2444 unsigned int mcr;
@@ -2601,8 +2465,7 @@ static int edge_tiocmset (struct usb_serial_port *port, struct file *file, unsig
2601 edge_port->shadow_mcr = mcr; 2465 edge_port->shadow_mcr = mcr;
2602 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 2466 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2603 2467
2604 TIRestoreMCR (edge_port, mcr); 2468 restore_mcr(edge_port, mcr);
2605
2606 return 0; 2469 return 0;
2607} 2470}
2608 2471
@@ -2634,7 +2497,8 @@ static int edge_tiocmget(struct usb_serial_port *port, struct file *file)
2634 return result; 2497 return result;
2635} 2498}
2636 2499
2637static int get_serial_info (struct edgeport_port *edge_port, struct serial_struct __user *retinfo) 2500static int get_serial_info(struct edgeport_port *edge_port,
2501 struct serial_struct __user *retinfo)
2638{ 2502{
2639 struct serial_struct tmp; 2503 struct serial_struct tmp;
2640 2504
@@ -2652,17 +2516,14 @@ static int get_serial_info (struct edgeport_port *edge_port, struct serial_struc
2652 tmp.baud_base = 9600; 2516 tmp.baud_base = 9600;
2653 tmp.close_delay = 5*HZ; 2517 tmp.close_delay = 5*HZ;
2654 tmp.closing_wait = closing_wait; 2518 tmp.closing_wait = closing_wait;
2655// tmp.custom_divisor = state->custom_divisor;
2656// tmp.hub6 = state->hub6;
2657// tmp.io_type = state->io_type;
2658
2659 2519
2660 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 2520 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2661 return -EFAULT; 2521 return -EFAULT;
2662 return 0; 2522 return 0;
2663} 2523}
2664 2524
2665static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg) 2525static int edge_ioctl(struct usb_serial_port *port, struct file *file,
2526 unsigned int cmd, unsigned long arg)
2666{ 2527{
2667 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2528 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2668 struct async_icount cnow; 2529 struct async_icount cnow;
@@ -2671,81 +2532,63 @@ static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned
2671 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd); 2532 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
2672 2533
2673 switch (cmd) { 2534 switch (cmd) {
2674 case TIOCINQ: 2535 case TIOCGSERIAL:
2675 dbg("%s - (%d) TIOCINQ", __func__, port->number); 2536 dbg("%s - (%d) TIOCGSERIAL", __func__, port->number);
2676// return get_number_bytes_avail(edge_port, (unsigned int *) arg); 2537 return get_serial_info(edge_port,
2677 break; 2538 (struct serial_struct __user *) arg);
2678 2539 case TIOCMIWAIT:
2679 case TIOCSERGETLSR: 2540 dbg("%s - (%d) TIOCMIWAIT", __func__, port->number);
2680 dbg("%s - (%d) TIOCSERGETLSR", __func__, port->number); 2541 cprev = edge_port->icount;
2681// return get_lsr_info(edge_port, (unsigned int *) arg); 2542 while (1) {
2682 break; 2543 interruptible_sleep_on(&edge_port->delta_msr_wait);
2683 2544 /* see if a signal did it */
2684 case TIOCGSERIAL: 2545 if (signal_pending(current))
2685 dbg("%s - (%d) TIOCGSERIAL", __func__, port->number); 2546 return -ERESTARTSYS;
2686 return get_serial_info(edge_port, (struct serial_struct __user *) arg); 2547 cnow = edge_port->icount;
2687 break; 2548 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2688 2549 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2689 case TIOCSSERIAL: 2550 return -EIO; /* no change => error */
2690 dbg("%s - (%d) TIOCSSERIAL", __func__, port->number); 2551 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2691 break; 2552 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2692 2553 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2693 case TIOCMIWAIT: 2554 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
2694 dbg("%s - (%d) TIOCMIWAIT", __func__, port->number); 2555 return 0;
2695 cprev = edge_port->icount;
2696 while (1) {
2697 interruptible_sleep_on(&edge_port->delta_msr_wait);
2698 /* see if a signal did it */
2699 if (signal_pending(current))
2700 return -ERESTARTSYS;
2701 cnow = edge_port->icount;
2702 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2703 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2704 return -EIO; /* no change => error */
2705 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2706 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2707 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2708 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
2709 return 0;
2710 }
2711 cprev = cnow;
2712 } 2556 }
2713 /* not reached */ 2557 cprev = cnow;
2714 break; 2558 }
2715 2559 /* not reached */
2716 case TIOCGICOUNT: 2560 break;
2717 dbg ("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __func__, 2561 case TIOCGICOUNT:
2718 port->number, edge_port->icount.rx, edge_port->icount.tx); 2562 dbg("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
2719 if (copy_to_user((void __user *)arg, &edge_port->icount, sizeof(edge_port->icount))) 2563 port->number, edge_port->icount.rx, edge_port->icount.tx);
2720 return -EFAULT; 2564 if (copy_to_user((void __user *)arg, &edge_port->icount,
2721 return 0; 2565 sizeof(edge_port->icount)))
2566 return -EFAULT;
2567 return 0;
2722 } 2568 }
2723
2724 return -ENOIOCTLCMD; 2569 return -ENOIOCTLCMD;
2725} 2570}
2726 2571
2727static void edge_break (struct usb_serial_port *port, int break_state) 2572static void edge_break(struct usb_serial_port *port, int on)
2728{ 2573{
2729 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2574 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2730 int status; 2575 int status;
2576 int bv = 0; /* Off */
2731 2577
2732 dbg ("%s - state = %d", __func__, break_state); 2578 dbg("%s - state = %d", __func__, on);
2733 2579
2734 /* chase the port close */ 2580 /* chase the port close */
2735 TIChasePort (edge_port, 0, 0); 2581 chase_port(edge_port, 0, 0);
2736 2582
2737 if (break_state == -1) { 2583 if (on == -1)
2738 status = TISetBreak (edge_port); 2584 bv = 1; /* On */
2739 } else { 2585 status = ti_do_config(edge_port, UMPC_SET_CLR_BREAK, bv);
2740 status = TIClearBreak (edge_port); 2586 if (status)
2741 } 2587 dbg("%s - error %d sending break set/clear command.",
2742 if (status) {
2743 dbg ("%s - error %d sending break set/clear command.",
2744 __func__, status); 2588 __func__, status);
2745 }
2746} 2589}
2747 2590
2748static int edge_startup (struct usb_serial *serial) 2591static int edge_startup(struct usb_serial *serial)
2749{ 2592{
2750 struct edgeport_serial *edge_serial; 2593 struct edgeport_serial *edge_serial;
2751 struct edgeport_port *edge_port; 2594 struct edgeport_port *edge_port;
@@ -2765,9 +2608,9 @@ static int edge_startup (struct usb_serial *serial)
2765 edge_serial->serial = serial; 2608 edge_serial->serial = serial;
2766 usb_set_serial_data(serial, edge_serial); 2609 usb_set_serial_data(serial, edge_serial);
2767 2610
2768 status = TIDownloadFirmware (edge_serial); 2611 status = download_fw(edge_serial);
2769 if (status) { 2612 if (status) {
2770 kfree (edge_serial); 2613 kfree(edge_serial);
2771 return status; 2614 return status;
2772 } 2615 }
2773 2616
@@ -2775,13 +2618,15 @@ static int edge_startup (struct usb_serial *serial)
2775 for (i = 0; i < serial->num_ports; ++i) { 2618 for (i = 0; i < serial->num_ports; ++i) {
2776 edge_port = kzalloc(sizeof(struct edgeport_port), GFP_KERNEL); 2619 edge_port = kzalloc(sizeof(struct edgeport_port), GFP_KERNEL);
2777 if (edge_port == NULL) { 2620 if (edge_port == NULL) {
2778 dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__); 2621 dev_err(&serial->dev->dev, "%s - Out of memory\n",
2622 __func__);
2779 goto cleanup; 2623 goto cleanup;
2780 } 2624 }
2781 spin_lock_init(&edge_port->ep_lock); 2625 spin_lock_init(&edge_port->ep_lock);
2782 edge_port->ep_out_buf = edge_buf_alloc(EDGE_OUT_BUF_SIZE); 2626 edge_port->ep_out_buf = edge_buf_alloc(EDGE_OUT_BUF_SIZE);
2783 if (edge_port->ep_out_buf == NULL) { 2627 if (edge_port->ep_out_buf == NULL) {
2784 dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__); 2628 dev_err(&serial->dev->dev, "%s - Out of memory\n",
2629 __func__);
2785 kfree(edge_port); 2630 kfree(edge_port);
2786 goto cleanup; 2631 goto cleanup;
2787 } 2632 }
@@ -2790,27 +2635,27 @@ static int edge_startup (struct usb_serial *serial)
2790 usb_set_serial_port_data(serial->port[i], edge_port); 2635 usb_set_serial_port_data(serial->port[i], edge_port);
2791 edge_port->bUartMode = default_uart_mode; 2636 edge_port->bUartMode = default_uart_mode;
2792 } 2637 }
2793 2638
2794 return 0; 2639 return 0;
2795 2640
2796cleanup: 2641cleanup:
2797 for (--i; i>=0; --i) { 2642 for (--i; i >= 0; --i) {
2798 edge_port = usb_get_serial_port_data(serial->port[i]); 2643 edge_port = usb_get_serial_port_data(serial->port[i]);
2799 edge_buf_free(edge_port->ep_out_buf); 2644 edge_buf_free(edge_port->ep_out_buf);
2800 kfree(edge_port); 2645 kfree(edge_port);
2801 usb_set_serial_port_data(serial->port[i], NULL); 2646 usb_set_serial_port_data(serial->port[i], NULL);
2802 } 2647 }
2803 kfree (edge_serial); 2648 kfree(edge_serial);
2804 usb_set_serial_data(serial, NULL); 2649 usb_set_serial_data(serial, NULL);
2805 return -ENOMEM; 2650 return -ENOMEM;
2806} 2651}
2807 2652
2808static void edge_shutdown (struct usb_serial *serial) 2653static void edge_shutdown(struct usb_serial *serial)
2809{ 2654{
2810 int i; 2655 int i;
2811 struct edgeport_port *edge_port; 2656 struct edgeport_port *edge_port;
2812 2657
2813 dbg ("%s", __func__); 2658 dbg("%s", __func__);
2814 2659
2815 for (i = 0; i < serial->num_ports; ++i) { 2660 for (i = 0; i < serial->num_ports; ++i) {
2816 edge_port = usb_get_serial_port_data(serial->port[i]); 2661 edge_port = usb_get_serial_port_data(serial->port[i]);
@@ -2852,7 +2697,8 @@ static ssize_t store_uart_mode(struct device *dev,
2852 return count; 2697 return count;
2853} 2698}
2854 2699
2855static DEVICE_ATTR(uart_mode, S_IWUSR | S_IRUGO, show_uart_mode, store_uart_mode); 2700static DEVICE_ATTR(uart_mode, S_IWUSR | S_IRUGO, show_uart_mode,
2701 store_uart_mode);
2856 2702
2857static int edge_create_sysfs_attrs(struct usb_serial_port *port) 2703static int edge_create_sysfs_attrs(struct usb_serial_port *port)
2858{ 2704{
@@ -2922,9 +2768,9 @@ static void edge_buf_free(struct edge_buf *eb)
2922 2768
2923static void edge_buf_clear(struct edge_buf *eb) 2769static void edge_buf_clear(struct edge_buf *eb)
2924{ 2770{
2925 if (eb != NULL) 2771 if (eb != NULL)
2926 eb->buf_get = eb->buf_put; 2772 eb->buf_get = eb->buf_put;
2927 /* equivalent to a get of all data available */ 2773 /* equivalent to a get of all data available */
2928} 2774}
2929 2775
2930 2776
@@ -2937,10 +2783,9 @@ static void edge_buf_clear(struct edge_buf *eb)
2937 2783
2938static unsigned int edge_buf_data_avail(struct edge_buf *eb) 2784static unsigned int edge_buf_data_avail(struct edge_buf *eb)
2939{ 2785{
2940 if (eb != NULL) 2786 if (eb == NULL)
2941 return ((eb->buf_size + eb->buf_put - eb->buf_get) % eb->buf_size);
2942 else
2943 return 0; 2787 return 0;
2788 return ((eb->buf_size + eb->buf_put - eb->buf_get) % eb->buf_size);
2944} 2789}
2945 2790
2946 2791
@@ -2953,10 +2798,9 @@ static unsigned int edge_buf_data_avail(struct edge_buf *eb)
2953 2798
2954static unsigned int edge_buf_space_avail(struct edge_buf *eb) 2799static unsigned int edge_buf_space_avail(struct edge_buf *eb)
2955{ 2800{
2956 if (eb != NULL) 2801 if (eb == NULL)
2957 return ((eb->buf_size + eb->buf_get - eb->buf_put - 1) % eb->buf_size);
2958 else
2959 return 0; 2802 return 0;
2803 return ((eb->buf_size + eb->buf_get - eb->buf_put - 1) % eb->buf_size);
2960} 2804}
2961 2805
2962 2806
@@ -3113,7 +2957,7 @@ static int __init edgeport_init(void)
3113 if (retval) 2957 if (retval)
3114 goto failed_2port_device_register; 2958 goto failed_2port_device_register;
3115 retval = usb_register(&io_driver); 2959 retval = usb_register(&io_driver);
3116 if (retval) 2960 if (retval)
3117 goto failed_usb_register; 2961 goto failed_usb_register;
3118 info(DRIVER_DESC " " DRIVER_VERSION); 2962 info(DRIVER_DESC " " DRIVER_VERSION);
3119 return 0; 2963 return 0;
@@ -3125,11 +2969,11 @@ failed_1port_device_register:
3125 return retval; 2969 return retval;
3126} 2970}
3127 2971
3128static void __exit edgeport_exit (void) 2972static void __exit edgeport_exit(void)
3129{ 2973{
3130 usb_deregister (&io_driver); 2974 usb_deregister(&io_driver);
3131 usb_serial_deregister (&edgeport_1port_device); 2975 usb_serial_deregister(&edgeport_1port_device);
3132 usb_serial_deregister (&edgeport_2port_device); 2976 usb_serial_deregister(&edgeport_2port_device);
3133} 2977}
3134 2978
3135module_init(edgeport_init); 2979module_init(edgeport_init);
@@ -3151,8 +2995,8 @@ module_param(closing_wait, int, S_IRUGO | S_IWUSR);
3151MODULE_PARM_DESC(closing_wait, "Maximum wait for data to drain, in .01 secs"); 2995MODULE_PARM_DESC(closing_wait, "Maximum wait for data to drain, in .01 secs");
3152 2996
3153module_param(ignore_cpu_rev, bool, S_IRUGO | S_IWUSR); 2997module_param(ignore_cpu_rev, bool, S_IRUGO | S_IWUSR);
3154MODULE_PARM_DESC(ignore_cpu_rev, "Ignore the cpu revision when connecting to a device"); 2998MODULE_PARM_DESC(ignore_cpu_rev,
2999 "Ignore the cpu revision when connecting to a device");
3155 3000
3156module_param(default_uart_mode, int, S_IRUGO | S_IWUSR); 3001module_param(default_uart_mode, int, S_IRUGO | S_IWUSR);
3157MODULE_PARM_DESC(default_uart_mode, "Default uart_mode, 0=RS232, ..."); 3002MODULE_PARM_DESC(default_uart_mode, "Default uart_mode, 0=RS232, ...");
3158