Commit 2742fd88 authored by Alan Cox's avatar Alan Cox Committed by Greg Kroah-Hartman

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: default avatarAlan Cox <alan@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 4330354f
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
#include <linux/serial.h> #include <linux/serial.h>
#include <linux/ioctl.h> #include <linux/ioctl.h>
#include <linux/firmware.h> #include <linux/firmware.h>
#include <asm/uaccess.h> #include <linux/uaccess.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/usb/serial.h> #include <linux/usb/serial.h>
...@@ -57,18 +57,19 @@ ...@@ -57,18 +57,19 @@
struct edgeport_uart_buf_desc { struct edgeport_uart_buf_desc {
__u32 count; // Number of bytes currently in buffer __u32 count; /* Number of bytes currently in buffer */
}; };
/* different hardware types */ /* different hardware types */
#define HARDWARE_TYPE_930 0 #define HARDWARE_TYPE_930 0
#define HARDWARE_TYPE_TIUMP 1 #define HARDWARE_TYPE_TIUMP 1
// IOCTL_PRIVATE_TI_GET_MODE Definitions /* IOCTL_PRIVATE_TI_GET_MODE Definitions */
#define TI_MODE_CONFIGURING 0 // Device has not entered start device #define TI_MODE_CONFIGURING 0 /* Device has not entered start device */
#define TI_MODE_BOOT 1 // Staying in boot mode #define TI_MODE_BOOT 1 /* Staying in boot mode */
#define TI_MODE_DOWNLOAD 2 // Made it to download mode #define TI_MODE_DOWNLOAD 2 /* Made it to download mode */
#define TI_MODE_TRANSITIONING 3 // Currently in boot mode but transitioning to download mode #define TI_MODE_TRANSITIONING 3 /* Currently in boot mode but
transitioning to download mode */
/* read urb state */ /* read urb state */
#define EDGE_READ_URB_RUNNING 0 #define EDGE_READ_URB_RUNNING 0
...@@ -82,10 +83,9 @@ struct edgeport_uart_buf_desc { ...@@ -82,10 +83,9 @@ struct edgeport_uart_buf_desc {
/* Product information read from the Edgeport */ /* Product information read from the Edgeport */
struct product_info struct product_info {
{ int TiMode; /* Current TI Mode */
int TiMode; // Current TI Mode __u8 hardware_type; /* Type of hardware */
__u8 hardware_type; // Type of hardware
} __attribute__((packed)); } __attribute__((packed));
/* circular buffer */ /* circular buffer */
...@@ -125,8 +125,9 @@ struct edgeport_port { ...@@ -125,8 +125,9 @@ struct edgeport_port {
struct edgeport_serial { struct edgeport_serial {
struct product_info product_info; struct product_info product_info;
u8 TI_I2C_Type; // Type of I2C in UMP u8 TI_I2C_Type; /* Type of I2C in UMP */
u8 TiReadI2C; // Set to TRUE if we have read the I2c in Boot Mode u8 TiReadI2C; /* Set to TRUE if we have read the
I2c in Boot Mode */
struct mutex es_lock; struct mutex es_lock;
int num_ports_open; int num_ports_open;
struct usb_serial *serial; struct usb_serial *serial;
...@@ -214,7 +215,7 @@ static struct usb_device_id id_table_combined [] = { ...@@ -214,7 +215,7 @@ static struct usb_device_id id_table_combined [] = {
{ } { }
}; };
MODULE_DEVICE_TABLE (usb, id_table_combined); MODULE_DEVICE_TABLE(usb, id_table_combined);
static struct usb_driver io_driver = { static struct usb_driver io_driver = {
.name = "io_ti", .name = "io_ti",
...@@ -231,19 +232,19 @@ static unsigned short OperationalBuildNumber; ...@@ -231,19 +232,19 @@ static unsigned short OperationalBuildNumber;
static int debug; static int debug;
static int TIStayInBootMode = 0;
static int low_latency = EDGE_LOW_LATENCY; static int low_latency = EDGE_LOW_LATENCY;
static int closing_wait = EDGE_CLOSING_WAIT; static int closing_wait = EDGE_CLOSING_WAIT;
static int ignore_cpu_rev = 0; static int ignore_cpu_rev;
static int default_uart_mode = 0; /* RS232 */ static int default_uart_mode; /* RS232 */
static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned char *data, int length); static void edge_tty_recv(struct device *dev, struct tty_struct *tty,
unsigned char *data, int length);
static void stop_read(struct edgeport_port *edge_port); static void stop_read(struct edgeport_port *edge_port);
static int restart_read(struct edgeport_port *edge_port); static int restart_read(struct edgeport_port *edge_port);
static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old_termios); static void edge_set_termios(struct usb_serial_port *port,
struct ktermios *old_termios);
static void edge_send(struct usb_serial_port *port); static void edge_send(struct usb_serial_port *port);
/* sysfs attributes */ /* sysfs attributes */
...@@ -262,87 +263,57 @@ static unsigned int edge_buf_get(struct edge_buf *eb, char *buf, ...@@ -262,87 +263,57 @@ static unsigned int edge_buf_get(struct edge_buf *eb, char *buf,
unsigned int count); unsigned int count);
static int TIReadVendorRequestSync (struct usb_device *dev, static int ti_vread_sync(struct usb_device *dev, __u8 request,
__u8 request, __u16 value, __u16 index, u8 *data, int size)
__u16 value,
__u16 index,
u8 *data,
int size)
{ {
int status; int status;
status = usb_control_msg (dev, status = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), request,
usb_rcvctrlpipe(dev, 0), (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN),
request, value, index, data, size, 1000);
(USB_TYPE_VENDOR |
USB_RECIP_DEVICE |
USB_DIR_IN),
value,
index,
data,
size,
1000);
if (status < 0) if (status < 0)
return status; return status;
if (status != size) { if (status != size) {
dbg ("%s - wanted to write %d, but only wrote %d", dbg("%s - wanted to write %d, but only wrote %d",
__func__, size, status); __func__, size, status);
return -ECOMM; return -ECOMM;
} }
return 0; return 0;
} }
static int TISendVendorRequestSync (struct usb_device *dev, static int ti_vsend_sync(struct usb_device *dev, __u8 request,
__u8 request, __u16 value, __u16 index, u8 *data, int size)
__u16 value,
__u16 index,
u8 *data,
int size)
{ {
int status; int status;
status = usb_control_msg (dev, status = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), request,
usb_sndctrlpipe(dev, 0), (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT),
request, value, index, data, size, 1000);
(USB_TYPE_VENDOR |
USB_RECIP_DEVICE |
USB_DIR_OUT),
value,
index,
data,
size,
1000);
if (status < 0) if (status < 0)
return status; return status;
if (status != size) { if (status != size) {
dbg ("%s - wanted to write %d, but only wrote %d", dbg("%s - wanted to write %d, but only wrote %d",
__func__, size, status); __func__, size, status);
return -ECOMM; return -ECOMM;
} }
return 0; return 0;
} }
static int TIWriteCommandSync (struct usb_device *dev, __u8 command, static int send_cmd(struct usb_device *dev, __u8 command,
__u8 moduleid, __u16 value, u8 *data, __u8 moduleid, __u16 value, u8 *data,
int size) int size)
{ {
return TISendVendorRequestSync (dev, return ti_vsend_sync(dev, command, value, moduleid, data, size);
command, // Request
value, // wValue
moduleid, // wIndex
data, // TransferBuffer
size); // TransferBufferLength
} }
/* clear tx/rx buffers and fifo in TI UMP */ /* clear tx/rx buffers and fifo in TI UMP */
static int TIPurgeDataSync (struct usb_serial_port *port, __u16 mask) static int purge_port(struct usb_serial_port *port, __u16 mask)
{ {
int port_number = port->number - port->serial->minor; int port_number = port->number - port->serial->minor;
dbg ("%s - port %d, mask %x", __func__, port_number, mask); dbg("%s - port %d, mask %x", __func__, port_number, mask);
return TIWriteCommandSync (port->serial->dev, return send_cmd(port->serial->dev,
UMPC_PURGE_PORT, UMPC_PURGE_PORT,
(__u8)(UMPM_UART1_PORT + port_number), (__u8)(UMPM_UART1_PORT + port_number),
mask, mask,
...@@ -351,52 +322,49 @@ static int TIPurgeDataSync (struct usb_serial_port *port, __u16 mask) ...@@ -351,52 +322,49 @@ static int TIPurgeDataSync (struct usb_serial_port *port, __u16 mask)
} }
/** /**
* TIReadDownloadMemory - Read edgeport memory from TI chip * read_download_mem - Read edgeport memory from TI chip
* @dev: usb device pointer * @dev: usb device pointer
* @start_address: Device CPU address at which to read * @start_address: Device CPU address at which to read
* @length: Length of above data * @length: Length of above data
* @address_type: Can read both XDATA and I2C * @address_type: Can read both XDATA and I2C
* @buffer: pointer to input data buffer * @buffer: pointer to input data buffer
*/ */
static int TIReadDownloadMemory(struct usb_device *dev, int start_address, static int read_download_mem(struct usb_device *dev, int start_address,
int length, __u8 address_type, __u8 *buffer) int length, __u8 address_type, __u8 *buffer)
{ {
int status = 0; int status = 0;
__u8 read_length; __u8 read_length;
__be16 be_start_address; __be16 be_start_address;
dbg ("%s - @ %x for %d", __func__, start_address, length); dbg("%s - @ %x for %d", __func__, start_address, length);
/* Read in blocks of 64 bytes /* Read in blocks of 64 bytes
* (TI firmware can't handle more than 64 byte reads) * (TI firmware can't handle more than 64 byte reads)
*/ */
while (length) { while (length) {
if (length > 64) if (length > 64)
read_length= 64; read_length = 64;
else else
read_length = (__u8)length; read_length = (__u8)length;
if (read_length > 1) { if (read_length > 1) {
dbg ("%s - @ %x for %d", __func__, dbg("%s - @ %x for %d", __func__,
start_address, read_length); start_address, read_length);
} }
be_start_address = cpu_to_be16 (start_address); be_start_address = cpu_to_be16(start_address);
status = TIReadVendorRequestSync (dev, status = ti_vread_sync(dev, UMPC_MEMORY_READ,
UMPC_MEMORY_READ, // Request (__u16)address_type,
(__u16)address_type, // wValue (Address type) (__force __u16)be_start_address,
(__force __u16)be_start_address, // wIndex (Address to read) buffer, read_length);
buffer, // TransferBuffer
read_length); // TransferBufferLength
if (status) { if (status) {
dbg ("%s - ERROR %x", __func__, status); dbg("%s - ERROR %x", __func__, status);
return status; return status;
} }
if (read_length > 1) { if (read_length > 1)
usb_serial_debug_data(debug, &dev->dev, __func__, usb_serial_debug_data(debug, &dev->dev, __func__,
read_length, buffer); read_length, buffer);
}
/* Update pointers/length */ /* Update pointers/length */
start_address += read_length; start_address += read_length;
...@@ -407,36 +375,34 @@ static int TIReadDownloadMemory(struct usb_device *dev, int start_address, ...@@ -407,36 +375,34 @@ static int TIReadDownloadMemory(struct usb_device *dev, int start_address,
return status; return status;
} }
static int TIReadRam (struct usb_device *dev, int start_address, int length, __u8 *buffer) static int read_ram(struct usb_device *dev, int start_address,
int length, __u8 *buffer)
{ {
return TIReadDownloadMemory (dev, return read_download_mem(dev, start_address, length,
start_address, DTK_ADDR_SPACE_XDATA, buffer);
length,
DTK_ADDR_SPACE_XDATA,
buffer);
} }
/* Read edgeport memory to a given block */ /* Read edgeport memory to a given block */
static int TIReadBootMemory (struct edgeport_serial *serial, int start_address, int length, __u8 * buffer) static int read_boot_mem(struct edgeport_serial *serial,
int start_address, int length, __u8 *buffer)
{ {
int status = 0; int status = 0;
int i; int i;
for (i=0; i< length; i++) { for (i = 0; i < length; i++) {
status = TIReadVendorRequestSync (serial->serial->dev, status = ti_vread_sync(serial->serial->dev,
UMPC_MEMORY_READ, // Request UMPC_MEMORY_READ, serial->TI_I2C_Type,
serial->TI_I2C_Type, // wValue (Address type) (__u16)(start_address+i), &buffer[i], 0x01);
(__u16)(start_address+i), // wIndex
&buffer[i], // TransferBuffer
0x01); // TransferBufferLength
if (status) { if (status) {
dbg ("%s - ERROR %x", __func__, status); dbg("%s - ERROR %x", __func__, status);
return status; return status;
} }
} }
dbg ("%s - start_address = %x, length = %d", __func__, start_address, length); dbg("%s - start_address = %x, length = %d",
usb_serial_debug_data(debug, &serial->serial->dev->dev, __func__, length, buffer); __func__, start_address, length);
usb_serial_debug_data(debug, &serial->serial->dev->dev,
__func__, length, buffer);
serial->TiReadI2C = 1; serial->TiReadI2C = 1;
...@@ -444,7 +410,8 @@ static int TIReadBootMemory (struct edgeport_serial *serial, int start_address, ...@@ -444,7 +410,8 @@ static int TIReadBootMemory (struct edgeport_serial *serial, int start_address,
} }
/* Write given block to TI EPROM memory */ /* Write given block to TI EPROM memory */
static int TIWriteBootMemory (struct edgeport_serial *serial, int start_address, int length, __u8 *buffer) static int write_boot_mem(struct edgeport_serial *serial,
int start_address, int length, __u8 *buffer)
{ {
int status = 0; int status = 0;
int i; int i;
...@@ -452,31 +419,31 @@ static int TIWriteBootMemory (struct edgeport_serial *serial, int start_address, ...@@ -452,31 +419,31 @@ static int TIWriteBootMemory (struct edgeport_serial *serial, int start_address,
/* Must do a read before write */ /* Must do a read before write */
if (!serial->TiReadI2C) { if (!serial->TiReadI2C) {
status = TIReadBootMemory(serial, 0, 1, &temp); status = read_boot_mem(serial, 0, 1, &temp);
if (status) if (status)
return status; return status;
} }
for (i=0; i < length; ++i) { for (i = 0; i < length; ++i) {
status = TISendVendorRequestSync (serial->serial->dev, status = ti_vsend_sync(serial->serial->dev,
UMPC_MEMORY_WRITE, // Request UMPC_MEMORY_WRITE, buffer[i],
buffer[i], // wValue (__u16)(i + start_address), NULL, 0);
(__u16)(i+start_address), // wIndex
NULL, // TransferBuffer
0); // TransferBufferLength
if (status) if (status)
return status; return status;
} }
dbg ("%s - start_sddr = %x, length = %d", __func__, start_address, length); dbg("%s - start_sddr = %x, length = %d",
usb_serial_debug_data(debug, &serial->serial->dev->dev, __func__, length, buffer); __func__, start_address, length);
usb_serial_debug_data(debug, &serial->serial->dev->dev,
__func__, length, buffer);
return status; return status;
} }
/* Write edgeport I2C memory to TI chip */ /* Write edgeport I2C memory to TI chip */
static int TIWriteDownloadI2C (struct edgeport_serial *serial, int start_address, int length, __u8 address_type, __u8 *buffer) static int write_i2c_mem(struct edgeport_serial *serial,
int start_address, int length, __u8 address_type, __u8 *buffer)
{ {
int status = 0; int status = 0;
int write_length; int write_length;
...@@ -485,24 +452,25 @@ static int TIWriteDownloadI2C (struct edgeport_serial *serial, int start_address ...@@ -485,24 +452,25 @@ static int TIWriteDownloadI2C (struct edgeport_serial *serial, int start_address
/* We can only send a maximum of 1 aligned byte page at a time */ /* We can only send a maximum of 1 aligned byte page at a time */
/* calulate the number of bytes left in the first page */ /* calulate the number of bytes left in the first page */
write_length = EPROM_PAGE_SIZE - (start_address & (EPROM_PAGE_SIZE - 1)); write_length = EPROM_PAGE_SIZE -
(start_address & (EPROM_PAGE_SIZE - 1));
if (write_length > length) if (write_length > length)
write_length = length; write_length = length;
dbg ("%s - BytesInFirstPage Addr = %x, length = %d", __func__, start_address, write_length); dbg("%s - BytesInFirstPage Addr = %x, length = %d",
usb_serial_debug_data(debug, &serial->serial->dev->dev, __func__, write_length, buffer); __func__, start_address, write_length);
usb_serial_debug_data(debug, &serial->serial->dev->dev,
__func__, write_length, buffer);
/* Write first page */ /* Write first page */
be_start_address = cpu_to_be16 (start_address); be_start_address = cpu_to_be16(start_address);
status = TISendVendorRequestSync (serial->serial->dev, status = ti_vsend_sync(serial->serial->dev,
UMPC_MEMORY_WRITE, // Request UMPC_MEMORY_WRITE, (__u16)address_type,
(__u16)address_type, // wValue (__force __u16)be_start_address,
(__force __u16)be_start_address, // wIndex buffer, write_length);
buffer, // TransferBuffer
write_length);
if (status) { if (status) {
dbg ("%s - ERROR %d", __func__, status); dbg("%s - ERROR %d", __func__, status);
return status; return status;
} }
...@@ -510,26 +478,28 @@ static int TIWriteDownloadI2C (struct edgeport_serial *serial, int start_address ...@@ -510,26 +478,28 @@ static int TIWriteDownloadI2C (struct edgeport_serial *serial, int start_address
start_address += write_length; start_address += write_length;
buffer += write_length; buffer += write_length;
/* We should be aligned now -- can write max page size bytes at a time */ /* We should be aligned now -- can write
max page size bytes at a time */
while (length) { while (length) {
if (length > EPROM_PAGE_SIZE) if (length > EPROM_PAGE_SIZE)
write_length = EPROM_PAGE_SIZE; write_length = EPROM_PAGE_SIZE;
else else
write_length = length; write_length = length;
dbg ("%s - Page Write Addr = %x, length = %d", __func__, start_address, write_length); dbg("%s - Page Write Addr = %x, length = %d",
usb_serial_debug_data(debug, &serial->serial->dev->dev, __func__, write_length, buffer); __func__, start_address, write_length);
usb_serial_debug_data(debug, &serial->serial->dev->dev,
__func__, write_length, buffer);
/* Write next page */ /* Write next page */
be_start_address = cpu_to_be16 (start_address); be_start_address = cpu_to_be16(start_address);
status = TISendVendorRequestSync (serial->serial->dev, status = ti_vsend_sync(serial->serial->dev, UMPC_MEMORY_WRITE,
UMPC_MEMORY_WRITE, // Request (__u16)address_type,
(__u16)address_type, // wValue (__force __u16)be_start_address,
(__force __u16)be_start_address, // wIndex buffer, write_length);
buffer, // TransferBuffer
write_length); // TransferBufferLength
if (status) { if (status) {
dev_err (&serial->serial->dev->dev, "%s - ERROR %d\n", __func__, status); dev_err(&serial->serial->dev->dev, "%s - ERROR %d\n",
__func__, status);
return status; return status;
} }
...@@ -546,20 +516,20 @@ static int TIWriteDownloadI2C (struct edgeport_serial *serial, int start_address ...@@ -546,20 +516,20 @@ static int TIWriteDownloadI2C (struct edgeport_serial *serial, int start_address
* A zero in this bit indicates that the TX DMA buffers are empty * A zero in this bit indicates that the TX DMA buffers are empty
* then check the TX Empty bit in the UART. * then check the TX Empty bit in the UART.
*/ */
static int TIIsTxActive (struct edgeport_port *port) static int tx_active(struct edgeport_port *port)
{ {
int status; int status;
struct out_endpoint_desc_block *oedb; struct out_endpoint_desc_block *oedb;
__u8 *lsr; __u8 *lsr;
int bytes_left = 0; int bytes_left = 0;
oedb = kmalloc (sizeof (* oedb), GFP_KERNEL); oedb = kmalloc(sizeof(*oedb), GFP_KERNEL);
if (!oedb) { if (!oedb) {
dev_err (&port->port->dev, "%s - out of memory\n", __func__); dev_err(&port->port->dev, "%s - out of memory\n", __func__);
return -ENOMEM; return -ENOMEM;
} }
lsr = kmalloc (1, GFP_KERNEL); /* Sigh, that's right, just one byte, lsr = kmalloc(1, GFP_KERNEL); /* Sigh, that's right, just one byte,
as not all platforms can do DMA as not all platforms can do DMA
from stack */ from stack */
if (!lsr) { if (!lsr) {
...@@ -567,43 +537,39 @@ static int TIIsTxActive (struct edgeport_port *port) ...@@ -567,43 +537,39 @@ static int TIIsTxActive (struct edgeport_port *port)
return -ENOMEM; return -ENOMEM;
} }
/* Read the DMA Count Registers */ /* Read the DMA Count Registers */
status = TIReadRam (port->port->serial->dev, status = read_ram(port->port->serial->dev, port->dma_address,
port->dma_address, sizeof(*oedb), (void *)oedb);
sizeof( *oedb),
(void *)oedb);
if (status) if (status)
goto exit_is_tx_active; goto exit_is_tx_active;
dbg ("%s - XByteCount 0x%X", __func__, oedb->XByteCount); dbg("%s - XByteCount 0x%X", __func__, oedb->XByteCount);
/* and the LSR */ /* and the LSR */
status = TIReadRam (port->port->serial->dev, status = read_ram(port->port->serial->dev,
port->uart_base + UMPMEM_OFFS_UART_LSR, port->uart_base + UMPMEM_OFFS_UART_LSR, 1, lsr);
1,
lsr);
if (status) if (status)
goto exit_is_tx_active; goto exit_is_tx_active;
dbg ("%s - LSR = 0x%X", __func__, *lsr); dbg("%s - LSR = 0x%X", __func__, *lsr);
/* If either buffer has data or we are transmitting then return TRUE */ /* If either buffer has data or we are transmitting then return TRUE */
if ((oedb->XByteCount & 0x80 ) != 0 ) if ((oedb->XByteCount & 0x80) != 0)
bytes_left += 64; bytes_left += 64;
if ((*lsr & UMP_UART_LSR_TX_MASK ) == 0 ) if ((*lsr & UMP_UART_LSR_TX_MASK) == 0)
bytes_left += 1; bytes_left += 1;
/* We return Not Active if we get any kind of error */ /* We return Not Active if we get any kind of error */
exit_is_tx_active: exit_is_tx_active:
dbg ("%s - return %d", __func__, bytes_left ); dbg("%s - return %d", __func__, bytes_left);
kfree(lsr); kfree(lsr);
kfree(oedb); kfree(oedb);
return bytes_left; return bytes_left;
} }
static void TIChasePort(struct edgeport_port *port, unsigned long timeout, int flush) static void chase_port(struct edgeport_port *port, unsigned long timeout,
int flush)
{ {
int baud_rate; int baud_rate;
struct tty_struct *tty = port->port->tty; struct tty_struct *tty = port->port->tty;
...@@ -611,7 +577,7 @@ static void TIChasePort(struct edgeport_port *port, unsigned long timeout, int f ...@@ -611,7 +577,7 @@ static void TIChasePort(struct edgeport_port *port, unsigned long timeout, int f
unsigned long flags; unsigned long flags;
if (!timeout) if (!timeout)
timeout = (HZ*EDGE_CLOSING_WAIT)/100; timeout = (HZ * EDGE_CLOSING_WAIT)/100;
/* wait for data to drain from the buffer */ /* wait for data to drain from the buffer */
spin_lock_irqsave(&port->ep_lock, flags); spin_lock_irqsave(&port->ep_lock, flags);
...@@ -621,7 +587,8 @@ static void TIChasePort(struct edgeport_port *port, unsigned long timeout, int f ...@@ -621,7 +587,8 @@ static void TIChasePort(struct edgeport_port *port, unsigned long timeout, int f
set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
if (edge_buf_data_avail(port->ep_out_buf) == 0 if (edge_buf_data_avail(port->ep_out_buf) == 0
|| timeout == 0 || signal_pending(current) || timeout == 0 || signal_pending(current)
|| !usb_get_intfdata(port->port->serial->interface)) /* disconnect */ || !usb_get_intfdata(port->port->serial->interface))
/* disconnect */
break; break;
spin_unlock_irqrestore(&port->ep_lock, flags); spin_unlock_irqrestore(&port->ep_lock, flags);
timeout = schedule_timeout(timeout); timeout = schedule_timeout(timeout);
...@@ -636,8 +603,9 @@ static void TIChasePort(struct edgeport_port *port, unsigned long timeout, int f ...@@ -636,8 +603,9 @@ static void TIChasePort(struct edgeport_port *port, unsigned long timeout, int f
/* wait for data to drain from the device */ /* wait for data to drain from the device */
timeout += jiffies; timeout += jiffies;
while ((long)(jiffies - timeout) < 0 && !signal_pending(current) while ((long)(jiffies - timeout) < 0 && !signal_pending(current)
&& usb_get_intfdata(port->port->serial->interface)) { /* not disconnected */ && usb_get_intfdata(port->port->serial->interface)) {
if (!TIIsTxActive(port)) /* not disconnected */
if (!tx_active(port))
break; break;
msleep(10); msleep(10);
} }
...@@ -647,72 +615,72 @@ static void TIChasePort(struct edgeport_port *port, unsigned long timeout, int f ...@@ -647,72 +615,72 @@ static void TIChasePort(struct edgeport_port *port, unsigned long timeout, int f
return; return;
/* wait one more character time, based on baud rate */ /* wait one more character time, based on baud rate */
/* (TIIsTxActive doesn't seem to wait for the last byte) */ /* (tx_active doesn't seem to wait for the last byte) */
if ((baud_rate=port->baud_rate) == 0) baud_rate = port->baud_rate;
if (baud_rate == 0)
baud_rate = 50; baud_rate = 50;
msleep(max(1, DIV_ROUND_UP(10000, baud_rate))); msleep(max(1, DIV_ROUND_UP(10000, baud_rate)));
} }
static int TIChooseConfiguration (struct usb_device *dev) static int choose_config(struct usb_device *dev)
{ {
// There may be multiple configurations on this device, in which case /*
// we would need to read and parse all of them to find out which one * There may be multiple configurations on this device, in which case
// we want. However, we just support one config at this point, * we would need to read and parse all of them to find out which one
// configuration # 1, which is Config Descriptor 0. * we want. However, we just support one config at this point,
* configuration # 1, which is Config Descriptor 0.
*/
dbg ("%s - Number of Interfaces = %d", __func__, dev->config->desc.bNumInterfaces); dbg("%s - Number of Interfaces = %d",
dbg ("%s - MAX Power = %d", __func__, dev->config->desc.bMaxPower*2); __func__, dev->config->desc.bNumInterfaces);
dbg("%s - MAX Power = %d",
__func__, dev->config->desc.bMaxPower * 2);
if (dev->config->desc.bNumInterfaces != 1) { if (dev->config->desc.bNumInterfaces != 1) {
dev_err (&dev->dev, "%s - bNumInterfaces is not 1, ERROR!\n", __func__); dev_err(&dev->dev, "%s - bNumInterfaces is not 1, ERROR!\n",
__func__);
return -ENODEV; return -ENODEV;
} }
return 0; return 0;
} }
static int TIReadRom (struct edgeport_serial *serial, int start_address, int length, __u8 *buffer) static int read_rom(struct edgeport_serial *serial,
int start_address, int length, __u8 *buffer)
{ {
int status; int status;
if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) { if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) {
status = TIReadDownloadMemory (serial->serial->dev, status = read_download_mem(serial->serial->dev,
start_address, start_address,
length, length,
serial->TI_I2C_Type, serial->TI_I2C_Type,
buffer); buffer);
} else { } else {
status = TIReadBootMemory (serial, status = read_boot_mem(serial, start_address, length,
start_address,
length,
buffer); buffer);
} }
return status; return status;
} }
static int TIWriteRom (struct edgeport_serial *serial, int start_address, int length, __u8 *buffer) static int write_rom(struct edgeport_serial *serial, int start_address,
int length, __u8 *buffer)
{ {
if (serial->product_info.TiMode == TI_MODE_BOOT) if (serial->product_info.TiMode == TI_MODE_BOOT)
return TIWriteBootMemory (serial, return write_boot_mem(serial, start_address, length,
start_address,
length,
buffer); buffer);
if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) if (serial->product_info.TiMode == TI_MODE_DOWNLOAD)
return TIWriteDownloadI2C (serial, return write_i2c_mem(serial, start_address, length,
start_address, serial->TI_I2C_Type, buffer);
length,
serial->TI_I2C_Type,
buffer);
return -EINVAL; return -EINVAL;
} }
/* Read a descriptor header from I2C based on type */ /* Read a descriptor header from I2C based on type */
static int TIGetDescriptorAddress (struct edgeport_serial *serial, int desc_type, struct ti_i2c_desc *rom_desc) static int get_descriptor_addr(struct edgeport_serial *serial,
int desc_type, struct ti_i2c_desc *rom_desc)
{ {
int start_address; int start_address;
int status; int status;
...@@ -720,17 +688,18 @@ static int TIGetDescriptorAddress (struct edgeport_serial *serial, int desc_type ...@@ -720,17 +688,18 @@ static int TIGetDescriptorAddress (struct edgeport_serial *serial, int desc_type
/* Search for requested descriptor in I2C */ /* Search for requested descriptor in I2C */
start_address = 2; start_address = 2;
do { do {
status = TIReadRom (serial, status = read_rom(serial,
start_address, start_address,
sizeof(struct ti_i2c_desc), sizeof(struct ti_i2c_desc),
(__u8 *)rom_desc ); (__u8 *)rom_desc);
if (status) if (status)
return 0; return 0;
if (rom_desc->Type == desc_type) if (rom_desc->Type == desc_type)
return start_address; return start_address;
start_address = start_address + sizeof(struct ti_i2c_desc) + rom_desc->Size; start_address = start_address + sizeof(struct ti_i2c_desc)
+ rom_desc->Size;
} while ((start_address < TI_MAX_I2C_SIZE) && rom_desc->Type); } while ((start_address < TI_MAX_I2C_SIZE) && rom_desc->Type);
...@@ -738,23 +707,23 @@ static int TIGetDescriptorAddress (struct edgeport_serial *serial, int desc_type ...@@ -738,23 +707,23 @@ static int TIGetDescriptorAddress (struct edgeport_serial *serial, int desc_type
} }
/* Validate descriptor checksum */ /* Validate descriptor checksum */
static int ValidChecksum(struct ti_i2c_desc *rom_desc, __u8 *buffer) static int valid_csum(struct ti_i2c_desc *rom_desc, __u8 *buffer)
{ {
__u16 i; __u16 i;
__u8 cs = 0; __u8 cs = 0;
for (i=0; i < rom_desc->Size; i++) { for (i = 0; i < rom_desc->Size; i++)
cs = (__u8)(cs + buffer[i]); cs = (__u8)(cs + buffer[i]);
}
if (cs != rom_desc->CheckSum) { if (cs != rom_desc->CheckSum) {
dbg ("%s - Mismatch %x - %x", __func__, rom_desc->CheckSum, cs); dbg("%s - Mismatch %x - %x", __func__, rom_desc->CheckSum, cs);
return -EINVAL; return -EINVAL;
} }
return 0; return 0;
} }
/* Make sure that the I2C image is good */ /* Make sure that the I2C image is good */
static int TiValidateI2cImage (struct edgeport_serial *serial) static int check_i2c_image(struct edgeport_serial *serial)
{ {
struct device *dev = &serial->serial->dev->dev; struct device *dev = &serial->serial->dev->dev;
int status = 0; int status = 0;
...@@ -763,120 +732,124 @@ static int TiValidateI2cImage (struct edgeport_serial *serial) ...@@ -763,120 +732,124 @@ static int TiValidateI2cImage (struct edgeport_serial *serial)
__u8 *buffer; __u8 *buffer;
__u16 ttype; __u16 ttype;
rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL); rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
if (!rom_desc) { if (!rom_desc) {
dev_err (dev, "%s - out of memory\n", __func__); dev_err(dev, "%s - out of memory\n", __func__);
return -ENOMEM; return -ENOMEM;
} }
buffer = kmalloc (TI_MAX_I2C_SIZE, GFP_KERNEL); buffer = kmalloc(TI_MAX_I2C_SIZE, GFP_KERNEL);
if (!buffer) { if (!buffer) {
dev_err (dev, "%s - out of memory when allocating buffer\n", __func__); dev_err(dev, "%s - out of memory when allocating buffer\n",
kfree (rom_desc); __func__);
kfree(rom_desc);
return -ENOMEM; return -ENOMEM;
} }
// Read the first byte (Signature0) must be 0x52 or 0x10 /* Read the first byte (Signature0) must be 0x52 or 0x10 */
status = TIReadRom (serial, 0, 1, buffer); status = read_rom(serial, 0, 1, buffer);
if (status) if (status)
goto ExitTiValidateI2cImage; goto out;
if (*buffer != UMP5152 && *buffer != UMP3410) { if (*buffer != UMP5152 && *buffer != UMP3410) {
dev_err (dev, "%s - invalid buffer signature\n", __func__); dev_err(dev, "%s - invalid buffer signature\n", __func__);
status = -ENODEV; status = -ENODEV;
goto ExitTiValidateI2cImage; goto out;
} }
do { do {
// Validate the I2C /* Validate the I2C */
status = TIReadRom (serial, status = read_rom(serial,
start_address, start_address,
sizeof(struct ti_i2c_desc), sizeof(struct ti_i2c_desc),
(__u8 *)rom_desc); (__u8 *)rom_desc);
if (status) if (status)
break; break;
if ((start_address + sizeof(struct ti_i2c_desc) + rom_desc->Size) > TI_MAX_I2C_SIZE) { if ((start_address + sizeof(struct ti_i2c_desc) +
rom_desc->Size) > TI_MAX_I2C_SIZE) {
status = -ENODEV; status = -ENODEV;
dbg ("%s - structure too big, erroring out.", __func__); dbg("%s - structure too big, erroring out.", __func__);
break; break;
} }
dbg ("%s Type = 0x%x", __func__, rom_desc->Type); dbg("%s Type = 0x%x", __func__, rom_desc->Type);
// Skip type 2 record /* Skip type 2 record */
ttype = rom_desc->Type & 0x0f; ttype = rom_desc->Type & 0x0f;
if ( ttype != I2C_DESC_TYPE_FIRMWARE_BASIC if (ttype != I2C_DESC_TYPE_FIRMWARE_BASIC
&& ttype != I2C_DESC_TYPE_FIRMWARE_AUTO ) { && ttype != I2C_DESC_TYPE_FIRMWARE_AUTO) {
// Read the descriptor data /* Read the descriptor data */
status = TIReadRom(serial, status = read_rom(serial, start_address +
start_address+sizeof(struct ti_i2c_desc), sizeof(struct ti_i2c_desc),
rom_desc->Size, rom_desc->Size, buffer);
buffer);
if (status) if (status)
break; break;
status = ValidChecksum(rom_desc, buffer); status = valid_csum(rom_desc, buffer);
if (status) if (status)
break; break;
} }
start_address = start_address + sizeof(struct ti_i2c_desc) + rom_desc->Size; start_address = start_address + sizeof(struct ti_i2c_desc) +
rom_desc->Size;
} while ((rom_desc->Type != I2C_DESC_TYPE_ION) && (start_address < TI_MAX_I2C_SIZE)); } while ((rom_desc->Type != I2C_DESC_TYPE_ION) &&
(start_address < TI_MAX_I2C_SIZE));
if ((rom_desc->Type != I2C_DESC_TYPE_ION) || (start_address > TI_MAX_I2C_SIZE)) if ((rom_desc->Type != I2C_DESC_TYPE_ION) ||
(start_address > TI_MAX_I2C_SIZE))
status = -ENODEV; status = -ENODEV;
ExitTiValidateI2cImage: out:
kfree (buffer); kfree(buffer);
kfree (rom_desc); kfree(rom_desc);
return status; return status;
} }
static int TIReadManufDescriptor (struct edgeport_serial *serial, __u8 *buffer) static int get_manuf_info(struct edgeport_serial *serial, __u8 *buffer)
{ {
int status; int status;
int start_address; int start_address;
struct ti_i2c_desc *rom_desc; struct ti_i2c_desc *rom_desc;
struct edge_ti_manuf_descriptor *desc; struct edge_ti_manuf_descriptor *desc;
rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL); rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
if (!rom_desc) { if (!rom_desc) {
dev_err (&serial->serial->dev->dev, "%s - out of memory\n", __func__); dev_err(&serial->serial->dev->dev, "%s - out of memory\n",
__func__);
return -ENOMEM; return -ENOMEM;
} }
start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_ION, rom_desc); start_address = get_descriptor_addr(serial, I2C_DESC_TYPE_ION,
rom_desc);
if (!start_address) { if (!start_address) {
dbg ("%s - Edge Descriptor not found in I2C", __func__); dbg("%s - Edge Descriptor not found in I2C", __func__);
status = -ENODEV; status = -ENODEV;
goto exit; goto exit;
} }
// Read the descriptor data /* Read the descriptor data */
status = TIReadRom (serial, status = read_rom(serial, start_address+sizeof(struct ti_i2c_desc),
start_address+sizeof(struct ti_i2c_desc), rom_desc->Size, buffer);
rom_desc->Size,
buffer);
if (status) if (status)
goto exit; goto exit;
status = ValidChecksum(rom_desc, buffer); status = valid_csum(rom_desc, buffer);
desc = (struct edge_ti_manuf_descriptor *)buffer; desc = (struct edge_ti_manuf_descriptor *)buffer;
dbg ( "%s - IonConfig 0x%x", __func__, desc->IonConfig ); dbg("%s - IonConfig 0x%x", __func__, desc->IonConfig);
dbg ( "%s - Version %d", __func__, desc->Version ); dbg("%s - Version %d", __func__, desc->Version);
dbg ( "%s - Cpu/Board 0x%x", __func__, desc->CpuRev_BoardRev ); dbg("%s - Cpu/Board 0x%x", __func__, desc->CpuRev_BoardRev);
dbg ( "%s - NumPorts %d", __func__, desc->NumPorts ); dbg("%s - NumPorts %d", __func__, desc->NumPorts);
dbg ( "%s - NumVirtualPorts %d", __func__, desc->NumVirtualPorts ); dbg("%s - NumVirtualPorts %d", __func__, desc->NumVirtualPorts);
dbg ( "%s - TotalPorts %d", __func__, desc->TotalPorts ); dbg("%s - TotalPorts %d", __func__, desc->TotalPorts);
exit: exit:
kfree (rom_desc); kfree(rom_desc);
return status; return status;
} }
/* Build firmware header used for firmware update */ /* Build firmware header used for firmware update */
static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev) static int build_i2c_fw_hdr(__u8 *header, struct device *dev)
{ {
__u8 *buffer; __u8 *buffer;
int buffer_size; int buffer_size;
...@@ -889,24 +862,28 @@ static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev) ...@@ -889,24 +862,28 @@ static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev)
const struct firmware *fw; const struct firmware *fw;
const char *fw_name = "edgeport/down3.bin"; const char *fw_name = "edgeport/down3.bin";
// In order to update the I2C firmware we must change the type 2 record to type 0xF2. /* In order to update the I2C firmware we must change the type 2 record
// This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver * to type 0xF2. This will force the UMP to come up in Boot Mode.
// will download the latest firmware (padded to 15.5k) into the UMP ram. * Then while in boot mode, the driver will download the latest
// And finally when the device comes back up in download mode the driver will cause * firmware (padded to 15.5k) into the UMP ram. And finally when the
// the new firmware to be copied from the UMP Ram to I2C and the firmware will update * device comes back up in download mode the driver will cause the new
// the record type from 0xf2 to 0x02. * firmware to be copied from the UMP Ram to I2C and the firmware will
* update the record type from 0xf2 to 0x02.
*/
// Allocate a 15.5k buffer + 2 bytes for version number (Firmware Record) /* Allocate a 15.5k buffer + 2 bytes for version number
buffer_size = (((1024 * 16) - 512 )+ sizeof(struct ti_i2c_firmware_rec)); * (Firmware Record) */
buffer_size = (((1024 * 16) - 512 ) +
sizeof(struct ti_i2c_firmware_rec));
buffer = kmalloc (buffer_size, GFP_KERNEL); buffer = kmalloc(buffer_size, GFP_KERNEL);
if (!buffer) { if (!buffer) {
dev_err (dev, "%s - out of memory\n", __func__); dev_err(dev, "%s - out of memory\n", __func__);
return -ENOMEM; return -ENOMEM;
} }
// Set entire image of 0xffs // Set entire image of 0xffs
memset (buffer, 0xff, buffer_size); memset(buffer, 0xff, buffer_size);
err = request_firmware(&fw, fw_name, dev); err = request_firmware(&fw, fw_name, dev);
if (err) { if (err) {
...@@ -921,16 +898,16 @@ static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev) ...@@ -921,16 +898,16 @@ static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev)
OperationalMinorVersion = fw->data[1]; OperationalMinorVersion = fw->data[1];
OperationalBuildNumber = fw->data[2] | (fw->data[3] << 8); OperationalBuildNumber = fw->data[2] | (fw->data[3] << 8);
// Copy version number into firmware record /* Copy version number into firmware record */
firmware_rec = (struct ti_i2c_firmware_rec *)buffer; firmware_rec = (struct ti_i2c_firmware_rec *)buffer;
firmware_rec->Ver_Major = OperationalMajorVersion; firmware_rec->Ver_Major = OperationalMajorVersion;
firmware_rec->Ver_Minor = OperationalMinorVersion; firmware_rec->Ver_Minor = OperationalMinorVersion;
// Pointer to fw_down memory image /* Pointer to fw_down memory image */
img_header = (struct ti_i2c_image_header *)&fw->data[4]; img_header = (struct ti_i2c_image_header *)&fw->data[4];
memcpy (buffer + sizeof(struct ti_i2c_firmware_rec), memcpy(buffer + sizeof(struct ti_i2c_firmware_rec),
&fw->data[4 + sizeof(struct ti_i2c_image_header)], &fw->data[4 + sizeof(struct ti_i2c_image_header)],
le16_to_cpu(img_header->Length)); le16_to_cpu(img_header->Length));
...@@ -940,9 +917,9 @@ static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev) ...@@ -940,9 +917,9 @@ static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev)
cs = (__u8)(cs + buffer[i]); cs = (__u8)(cs + buffer[i]);
} }
kfree (buffer); kfree(buffer);
// Build new header /* Build new header */
i2c_header = (struct ti_i2c_desc *)header; i2c_header = (struct ti_i2c_desc *)header;
firmware_rec = (struct ti_i2c_firmware_rec*)i2c_header->Data; firmware_rec = (struct ti_i2c_firmware_rec*)i2c_header->Data;
...@@ -956,103 +933,100 @@ static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev) ...@@ -956,103 +933,100 @@ static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev)
} }
/* Try to figure out what type of I2c we have */ /* Try to figure out what type of I2c we have */
static int TIGetI2cTypeInBootMode (struct edgeport_serial *serial) static int i2c_type_bootmode(struct edgeport_serial *serial)
{ {
int status; int status;
__u8 data; __u8 data;
// Try to read type 2 /* Try to read type 2 */
status = TIReadVendorRequestSync (serial->serial->dev, status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ,
UMPC_MEMORY_READ, // Request DTK_ADDR_SPACE_I2C_TYPE_II, 0, &data, 0x01);
DTK_ADDR_SPACE_I2C_TYPE_II, // wValue (Address type)
0, // wIndex
&data, // TransferBuffer
0x01); // TransferBufferLength
if (status) if (status)
dbg ("%s - read 2 status error = %d", __func__, status); dbg("%s - read 2 status error = %d", __func__, status);
else else
dbg ("%s - read 2 data = 0x%x", __func__, data); dbg("%s - read 2 data = 0x%x", __func__, data);
if ((!status) && (data == UMP5152 || data == UMP3410)) { if ((!status) && (data == UMP5152 || data == UMP3410)) {
dbg ("%s - ROM_TYPE_II", __func__); dbg("%s - ROM_TYPE_II", __func__);
serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II; serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
return 0; return 0;
} }
// Try to read type 3 /* Try to read type 3 */
status = TIReadVendorRequestSync (serial->serial->dev, status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ,
UMPC_MEMORY_READ, // Request DTK_ADDR_SPACE_I2C_TYPE_III, 0, &data, 0x01);
DTK_ADDR_SPACE_I2C_TYPE_III, // wValue (Address type)
0, // wIndex
&data, // TransferBuffer
0x01); // TransferBufferLength
if (status) if (status)
dbg ("%s - read 3 status error = %d", __func__, status); dbg("%s - read 3 status error = %d", __func__, status);
else else
dbg ("%s - read 2 data = 0x%x", __func__, data); dbg("%s - read 2 data = 0x%x", __func__, data);
if ((!status) && (data == UMP5152 || data == UMP3410)) { if ((!status) && (data == UMP5152 || data == UMP3410)) {
dbg ("%s - ROM_TYPE_III", __func__); dbg("%s - ROM_TYPE_III", __func__);
serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_III; serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_III;
return 0; return 0;
} }
dbg ("%s - Unknown", __func__); dbg("%s - Unknown", __func__);
serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II; serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
return -ENODEV; return -ENODEV;
} }
static int TISendBulkTransferSync (struct usb_serial *serial, void *buffer, int length, int *num_sent) static int bulk_xfer(struct usb_serial *serial, void *buffer,
int length, int *num_sent)
{ {
int status; int status;
status = usb_bulk_msg (serial->dev, status = usb_bulk_msg(serial->dev,
usb_sndbulkpipe(serial->dev, usb_sndbulkpipe(serial->dev,
serial->port[0]->bulk_out_endpointAddress), serial->port[0]->bulk_out_endpointAddress),
buffer, buffer, length, num_sent, 1000);
length,
num_sent,
1000);
return status; return status;
} }
/* Download given firmware image to the device (IN BOOT MODE) */ /* Download given firmware image to the device (IN BOOT MODE) */
static int TIDownloadCodeImage (struct edgeport_serial *serial, __u8 *image, int image_length) static int download_code(struct edgeport_serial *serial, __u8 *image,
int image_length)
{ {
int status = 0; int status = 0;
int pos; int pos;
int transfer; int transfer;
int done; int done;
// Transfer firmware image /* Transfer firmware image */
for (pos = 0; pos < image_length; ) { for (pos = 0; pos < image_length; ) {
// Read the next buffer from file /* Read the next buffer from file */
transfer = image_length - pos; transfer = image_length - pos;
if (transfer > EDGE_FW_BULK_MAX_PACKET_SIZE) if (transfer > EDGE_FW_BULK_MAX_PACKET_SIZE)
transfer = EDGE_FW_BULK_MAX_PACKET_SIZE; transfer = EDGE_FW_BULK_MAX_PACKET_SIZE;
// Transfer data /* Transfer data */
status = TISendBulkTransferSync (serial->serial, &image[pos], transfer, &done); status = bulk_xfer(serial->serial, &image[pos],
transfer, &done);
if (status) if (status)
break; break;
// Advance buffer pointer /* Advance buffer pointer */
pos += done; pos += done;
} }
return status; return status;
} }
// FIXME!!! /* FIXME!!! */
static int TIConfigureBootDevice (struct usb_device *dev) static int config_boot_dev(struct usb_device *dev)
{ {
return 0; return 0;
} }
static int ti_cpu_rev(struct edge_ti_manuf_descriptor *desc)
{
return TI_GET_CPU_REVISION(desc->CpuRev_BoardRev);
}
/** /**
* DownloadTIFirmware - Download run-time operating firmware to the TI5052 * DownloadTIFirmware - Download run-time operating firmware to the TI5052
* *
* This routine downloads the main operating code into the TI5052, using the * This routine downloads the main operating code into the TI5052, using the
* boot code already burned into E2PROM or ROM. * boot code already burned into E2PROM or ROM.
*/ */
static int TIDownloadFirmware (struct edgeport_serial *serial) static int download_fw(struct edgeport_serial *serial)
{ {
struct device *dev = &serial->serial->dev->dev; struct device *dev = &serial->serial->dev->dev;
int status = 0; int status = 0;
...@@ -1071,22 +1045,25 @@ static int TIDownloadFirmware (struct edgeport_serial *serial) ...@@ -1071,22 +1045,25 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
/* Default to type 2 i2c */ /* Default to type 2 i2c */
serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II; serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
status = TIChooseConfiguration (serial->serial->dev); status = choose_config(serial->serial->dev);
if (status) if (status)
return status; return status;
interface = &serial->serial->interface->cur_altsetting->desc; interface = &serial->serial->interface->cur_altsetting->desc;
if (!interface) { if (!interface) {
dev_err (dev, "%s - no interface set, error!\n", __func__); dev_err(dev, "%s - no interface set, error!\n", __func__);
return -ENODEV; return -ENODEV;
} }
// Setup initial mode -- the default mode 0 is TI_MODE_CONFIGURING /*
// if we have more than one endpoint we are definitely in download mode * Setup initial mode -- the default mode 0 is TI_MODE_CONFIGURING
* if we have more than one endpoint we are definitely in download
* mode
*/
if (interface->bNumEndpoints > 1) if (interface->bNumEndpoints > 1)
serial->product_info.TiMode = TI_MODE_DOWNLOAD; serial->product_info.TiMode = TI_MODE_DOWNLOAD;
else else
// Otherwise we will remain in configuring mode /* Otherwise we will remain in configuring mode */
serial->product_info.TiMode = TI_MODE_CONFIGURING; serial->product_info.TiMode = TI_MODE_CONFIGURING;
/********************************************************************/ /********************************************************************/
...@@ -1097,7 +1074,7 @@ static int TIDownloadFirmware (struct edgeport_serial *serial) ...@@ -1097,7 +1074,7 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
dbg("%s - RUNNING IN DOWNLOAD MODE", __func__); dbg("%s - RUNNING IN DOWNLOAD MODE", __func__);
status = TiValidateI2cImage (serial); status = check_i2c_image(serial);
if (status) { if (status) {
dbg("%s - DOWNLOAD MODE -- BAD I2C", __func__); dbg("%s - DOWNLOAD MODE -- BAD I2C", __func__);
return status; return status;
...@@ -1106,247 +1083,264 @@ static int TIDownloadFirmware (struct edgeport_serial *serial) ...@@ -1106,247 +1083,264 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
/* Validate Hardware version number /* Validate Hardware version number
* Read Manufacturing Descriptor from TI Based Edgeport * Read Manufacturing Descriptor from TI Based Edgeport
*/ */
ti_manuf_desc = kmalloc (sizeof (*ti_manuf_desc), GFP_KERNEL); ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL);
if (!ti_manuf_desc) { if (!ti_manuf_desc) {
dev_err (dev, "%s - out of memory.\n", __func__); dev_err(dev, "%s - out of memory.\n", __func__);
return -ENOMEM; return -ENOMEM;
} }
status = TIReadManufDescriptor (serial, (__u8 *)ti_manuf_desc); status = get_manuf_info(serial, (__u8 *)ti_manuf_desc);
if (status) { if (status) {
kfree (ti_manuf_desc); kfree(ti_manuf_desc);
return status; return status;
} }
// Check version number of ION descriptor /* Check version number of ION descriptor */
if (!ignore_cpu_rev && TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev) < 2) { if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) {
dbg ( "%s - Wrong CPU Rev %d (Must be 2)", __func__, dbg("%s - Wrong CPU Rev %d (Must be 2)",
TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev)); __func__, ti_cpu_rev(ti_manuf_desc));
kfree (ti_manuf_desc); kfree(ti_manuf_desc);
return -EINVAL; return -EINVAL;
} }
rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL); rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
if (!rom_desc) { if (!rom_desc) {
dev_err (dev, "%s - out of memory.\n", __func__); dev_err(dev, "%s - out of memory.\n", __func__);
kfree (ti_manuf_desc); kfree(ti_manuf_desc);
return -ENOMEM; return -ENOMEM;
} }
// Search for type 2 record (firmware record) /* Search for type 2 record (firmware record) */
if ((start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_FIRMWARE_BASIC, rom_desc)) != 0) { start_address = get_descriptor_addr(serial,
I2C_DESC_TYPE_FIRMWARE_BASIC, rom_desc);
if (start_address != 0) {
struct ti_i2c_firmware_rec *firmware_version; struct ti_i2c_firmware_rec *firmware_version;
__u8 record; __u8 record;
dbg ("%s - Found Type FIRMWARE (Type 2) record", __func__); dbg("%s - Found Type FIRMWARE (Type 2) record",
__func__);
firmware_version = kmalloc (sizeof (*firmware_version), GFP_KERNEL); firmware_version = kmalloc(sizeof(*firmware_version),
GFP_KERNEL);
if (!firmware_version) { if (!firmware_version) {
dev_err (dev, "%s - out of memory.\n", __func__); dev_err(dev, "%s - out of memory.\n", __func__);
kfree (rom_desc); kfree(rom_desc);
kfree (ti_manuf_desc); kfree(ti_manuf_desc);
return -ENOMEM; return -ENOMEM;
} }
// Validate version number /* Validate version number
// Read the descriptor data * Read the descriptor data
status = TIReadRom (serial, */
start_address+sizeof(struct ti_i2c_desc), status = read_rom(serial, start_address +
sizeof(struct ti_i2c_desc),
sizeof(struct ti_i2c_firmware_rec), sizeof(struct ti_i2c_firmware_rec),
(__u8 *)firmware_version); (__u8 *)firmware_version);
if (status) { if (status) {
kfree (firmware_version); kfree(firmware_version);
kfree (rom_desc); kfree(rom_desc);
kfree (ti_manuf_desc); kfree(ti_manuf_desc);
return status; return status;
} }
// Check version number of download with current version in I2c /* Check version number of download with current
version in I2c */
download_cur_ver = (firmware_version->Ver_Major << 8) + download_cur_ver = (firmware_version->Ver_Major << 8) +
(firmware_version->Ver_Minor); (firmware_version->Ver_Minor);
download_new_ver = (OperationalMajorVersion << 8) + download_new_ver = (OperationalMajorVersion << 8) +
(OperationalMinorVersion); (OperationalMinorVersion);
dbg ("%s - >>>Firmware Versions Device %d.%d Driver %d.%d", dbg("%s - >> FW Versions Device %d.%d Driver %d.%d",
__func__, __func__,
firmware_version->Ver_Major, firmware_version->Ver_Major,
firmware_version->Ver_Minor, firmware_version->Ver_Minor,
OperationalMajorVersion, OperationalMajorVersion,
OperationalMinorVersion); OperationalMinorVersion);
// Check if we have an old version in the I2C and update if necessary /* Check if we have an old version in the I2C and
update if necessary */
if (download_cur_ver != download_new_ver) { if (download_cur_ver != download_new_ver) {
dbg ("%s - Update I2C Download from %d.%d to %d.%d", dbg("%s - Update I2C dld from %d.%d to %d.%d",
__func__, __func__,
firmware_version->Ver_Major, firmware_version->Ver_Major,
firmware_version->Ver_Minor, firmware_version->Ver_Minor,
OperationalMajorVersion, OperationalMajorVersion,
OperationalMinorVersion); OperationalMinorVersion);
// In order to update the I2C firmware we must change the type 2 record to type 0xF2. /* In order to update the I2C firmware we must
// This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver * change the type 2 record to type 0xF2. This
// will download the latest firmware (padded to 15.5k) into the UMP ram. * will force the UMP to come up in Boot Mode.
// And finally when the device comes back up in download mode the driver will cause * Then while in boot mode, the driver will
// the new firmware to be copied from the UMP Ram to I2C and the firmware will update * download the latest firmware (padded to
// the record type from 0xf2 to 0x02. * 15.5k) into the UMP ram. Finally when the
* device comes back up in download mode the
* driver will cause the new firmware to be
* copied from the UMP Ram to I2C and the
* firmware will update the record type from
* 0xf2 to 0x02.
*/
record = I2C_DESC_TYPE_FIRMWARE_BLANK; record = I2C_DESC_TYPE_FIRMWARE_BLANK;
// Change the I2C Firmware record type to 0xf2 to trigger an update /* Change the I2C Firmware record type to
status = TIWriteRom (serial, 0xf2 to trigger an update */
start_address, status = write_rom(serial, start_address,
sizeof(record), sizeof(record), &record);
&record);
if (status) { if (status) {
kfree (firmware_version); kfree(firmware_version);
kfree (rom_desc); kfree(rom_desc);
kfree (ti_manuf_desc); kfree(ti_manuf_desc);
return status; return status;
} }
// verify the write -- must do this in order for write to /* verify the write -- must do this in order
// complete before we do the hardware reset * for write to complete before we do the
status = TIReadRom (serial, * hardware reset
*/
status = read_rom(serial,
start_address, start_address,
sizeof(record), sizeof(record),
&record); &record);
if (status) { if (status) {
kfree (firmware_version); kfree(firmware_version);
kfree (rom_desc); kfree(rom_desc);
kfree (ti_manuf_desc); kfree(ti_manuf_desc);
return status; return status;
} }
if (record != I2C_DESC_TYPE_FIRMWARE_BLANK) { if (record != I2C_DESC_TYPE_FIRMWARE_BLANK) {
dev_err (dev, "%s - error resetting device\n", __func__); dev_err(dev,
kfree (firmware_version); "%s - error resetting device\n",
kfree (rom_desc); __func__);
kfree (ti_manuf_desc); kfree(firmware_version);
kfree(rom_desc);
kfree(ti_manuf_desc);
return -ENODEV; return -ENODEV;
} }
dbg ("%s - HARDWARE RESET", __func__); dbg("%s - HARDWARE RESET", __func__);
// Reset UMP -- Back to BOOT MODE /* Reset UMP -- Back to BOOT MODE */
status = TISendVendorRequestSync (serial->serial->dev, status = ti_vsend_sync(serial->serial->dev,
UMPC_HARDWARE_RESET, // Request UMPC_HARDWARE_RESET,
0, // wValue 0, 0, NULL, 0);
0, // wIndex
NULL, // TransferBuffer
0); // TransferBufferLength
dbg ( "%s - HARDWARE RESET return %d", __func__, status); dbg("%s - HARDWARE RESET return %d",
__func__, status);
/* return an error on purpose. */ /* return an error on purpose. */
kfree (firmware_version); kfree(firmware_version);
kfree (rom_desc); kfree(rom_desc);
kfree (ti_manuf_desc); kfree(ti_manuf_desc);
return -ENODEV; return -ENODEV;
} }
kfree (firmware_version); kfree(firmware_version);
} }
// Search for type 0xF2 record (firmware blank record) /* Search for type 0xF2 record (firmware blank record) */
else if ((start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_FIRMWARE_BLANK, rom_desc)) != 0) { else if ((start_address = get_descriptor_addr(serial, I2C_DESC_TYPE_FIRMWARE_BLANK, rom_desc)) != 0) {
#define HEADER_SIZE (sizeof(struct ti_i2c_desc) + sizeof(struct ti_i2c_firmware_rec)) #define HEADER_SIZE (sizeof(struct ti_i2c_desc) + \
sizeof(struct ti_i2c_firmware_rec))
__u8 *header; __u8 *header;
__u8 *vheader; __u8 *vheader;
header = kmalloc (HEADER_SIZE, GFP_KERNEL); header = kmalloc(HEADER_SIZE, GFP_KERNEL);
if (!header) { if (!header) {
dev_err (dev, "%s - out of memory.\n", __func__); dev_err(dev, "%s - out of memory.\n", __func__);
kfree (rom_desc); kfree(rom_desc);
kfree (ti_manuf_desc); kfree(ti_manuf_desc);
return -ENOMEM; return -ENOMEM;
} }
vheader = kmalloc (HEADER_SIZE, GFP_KERNEL); vheader = kmalloc(HEADER_SIZE, GFP_KERNEL);
if (!vheader) { if (!vheader) {
dev_err (dev, "%s - out of memory.\n", __func__); dev_err(dev, "%s - out of memory.\n", __func__);
kfree (header); kfree(header);
kfree (rom_desc); kfree(rom_desc);
kfree (ti_manuf_desc); kfree(ti_manuf_desc);
return -ENOMEM; return -ENOMEM;
} }
dbg ("%s - Found Type BLANK FIRMWARE (Type F2) record", __func__); dbg("%s - Found Type BLANK FIRMWARE (Type F2) record",
__func__);
// In order to update the I2C firmware we must change the type 2 record to type 0xF2. /*
// This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver * In order to update the I2C firmware we must change
// will download the latest firmware (padded to 15.5k) into the UMP ram. * the type 2 record to type 0xF2. This will force the
// And finally when the device comes back up in download mode the driver will cause * UMP to come up in Boot Mode. Then while in boot
// the new firmware to be copied from the UMP Ram to I2C and the firmware will update * mode, the driver will download the latest firmware
// the record type from 0xf2 to 0x02. * (padded to 15.5k) into the UMP ram. Finally when the
status = BuildI2CFirmwareHeader(header, dev); * device comes back up in download mode the driver
* will cause the new firmware to be copied from the
* UMP Ram to I2C and the firmware will update the
* record type from 0xf2 to 0x02.
*/
status = build_i2c_fw_hdr(header, dev);
if (status) { if (status) {
kfree (vheader); kfree(vheader);
kfree (header); kfree(header);
kfree (rom_desc); kfree(rom_desc);
kfree (ti_manuf_desc); kfree(ti_manuf_desc);
return status; return status;
} }
// Update I2C with type 0xf2 record with correct size and checksum /* Update I2C with type 0xf2 record with correct
status = TIWriteRom (serial, size and checksum */
status = write_rom(serial,
start_address, start_address,
HEADER_SIZE, HEADER_SIZE,
header); header);
if (status) { if (status) {
kfree (vheader); kfree(vheader);
kfree (header); kfree(header);
kfree (rom_desc); kfree(rom_desc);
kfree (ti_manuf_desc); kfree(ti_manuf_desc);
return status; return status;
} }
// verify the write -- must do this in order for write to /* verify the write -- must do this in order for
// complete before we do the hardware reset write to complete before we do the hardware reset */
status = TIReadRom (serial, status = read_rom(serial, start_address,
start_address, HEADER_SIZE, vheader);
HEADER_SIZE,
vheader);
if (status) { if (status) {
dbg ("%s - can't read header back", __func__); dbg("%s - can't read header back", __func__);
kfree (vheader); kfree(vheader);
kfree (header); kfree(header);
kfree (rom_desc); kfree(rom_desc);
kfree (ti_manuf_desc); kfree(ti_manuf_desc);
return status; return status;
} }
if (memcmp(vheader, header, HEADER_SIZE)) { if (memcmp(vheader, header, HEADER_SIZE)) {
dbg ("%s - write download record failed", __func__); dbg("%s - write download record failed",
kfree (vheader); __func__);
kfree (header); kfree(vheader);
kfree (rom_desc); kfree(header);
kfree (ti_manuf_desc); kfree(rom_desc);
kfree(ti_manuf_desc);
return status; return status;
} }
kfree (vheader); kfree(vheader);
kfree (header); kfree(header);
dbg ("%s - Start firmware update", __func__); dbg("%s - Start firmware update", __func__);
// Tell firmware to copy download image into I2C /* Tell firmware to copy download image into I2C */
status = TISendVendorRequestSync (serial->serial->dev, status = ti_vsend_sync(serial->serial->dev,
UMPC_COPY_DNLD_TO_I2C, // Request UMPC_COPY_DNLD_TO_I2C, 0, 0, NULL, 0);
0, // wValue
0, // wIndex
NULL, // TransferBuffer
0); // TransferBufferLength
dbg ("%s - Update complete 0x%x", __func__, status); dbg("%s - Update complete 0x%x", __func__, status);
if (status) { if (status) {
dev_err (dev, "%s - UMPC_COPY_DNLD_TO_I2C failed\n", __func__); dev_err(dev,
kfree (rom_desc); "%s - UMPC_COPY_DNLD_TO_I2C failed\n",
kfree (ti_manuf_desc); __func__);
kfree(rom_desc);
kfree(ti_manuf_desc);
return status; return status;
} }
} }
// The device is running the download code // The device is running the download code
kfree (rom_desc); kfree(rom_desc);
kfree (ti_manuf_desc); kfree(ti_manuf_desc);
return 0; return 0;
} }
...@@ -1355,32 +1349,26 @@ static int TIDownloadFirmware (struct edgeport_serial *serial) ...@@ -1355,32 +1349,26 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
/********************************************************************/ /********************************************************************/
dbg("%s - RUNNING IN BOOT MODE", __func__); dbg("%s - RUNNING IN BOOT MODE", __func__);
// Configure the TI device so we can use the BULK pipes for download /* Configure the TI device so we can use the BULK pipes for download */
status = TIConfigureBootDevice (serial->serial->dev); status = config_boot_dev(serial->serial->dev);
if (status) if (status)
return status; return status;
if (le16_to_cpu(serial->serial->dev->descriptor.idVendor) != USB_VENDOR_ID_ION) { if (le16_to_cpu(serial->serial->dev->descriptor.idVendor)
dbg ("%s - VID = 0x%x", __func__, != USB_VENDOR_ID_ION) {
dbg("%s - VID = 0x%x", __func__,
le16_to_cpu(serial->serial->dev->descriptor.idVendor)); le16_to_cpu(serial->serial->dev->descriptor.idVendor));
serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II; serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
goto StayInBootMode; goto stayinbootmode;
} }
// We have an ION device (I2c Must be programmed) /* We have an ION device (I2c Must be programmed)
// Determine I2C image type Determine I2C image type */
if (TIGetI2cTypeInBootMode(serial)) { if (i2c_type_bootmode(serial))
goto StayInBootMode; goto stayinbootmode;
}
// Registry variable set? /* Check for ION Vendor ID and that the I2C is valid */
if (TIStayInBootMode) { if (!check_i2c_image(serial)) {
dbg ("%s - TIStayInBootMode", __func__);
goto StayInBootMode;
}
// Check for ION Vendor ID and that the I2C is valid
if (!TiValidateI2cImage(serial)) {
struct ti_i2c_image_header *header; struct ti_i2c_image_header *header;
int i; int i;
__u8 cs = 0; __u8 cs = 0;
...@@ -1393,49 +1381,52 @@ static int TIDownloadFirmware (struct edgeport_serial *serial) ...@@ -1393,49 +1381,52 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
/* Validate Hardware version number /* Validate Hardware version number
* Read Manufacturing Descriptor from TI Based Edgeport * Read Manufacturing Descriptor from TI Based Edgeport
*/ */
ti_manuf_desc = kmalloc (sizeof (*ti_manuf_desc), GFP_KERNEL); ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL);
if (!ti_manuf_desc) { if (!ti_manuf_desc) {
dev_err (dev, "%s - out of memory.\n", __func__); dev_err(dev, "%s - out of memory.\n", __func__);
return -ENOMEM; return -ENOMEM;
} }
status = TIReadManufDescriptor (serial, (__u8 *)ti_manuf_desc); status = get_manuf_info(serial, (__u8 *)ti_manuf_desc);
if (status) { if (status) {
kfree (ti_manuf_desc); kfree(ti_manuf_desc);
goto StayInBootMode; goto stayinbootmode;
} }
// Check for version 2 /* Check for version 2 */
if (!ignore_cpu_rev && TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev) < 2) { if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) {
dbg ("%s - Wrong CPU Rev %d (Must be 2)", __func__, dbg("%s - Wrong CPU Rev %d (Must be 2)",
TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev)); __func__, ti_cpu_rev(ti_manuf_desc));
kfree (ti_manuf_desc); kfree(ti_manuf_desc);
goto StayInBootMode; goto stayinbootmode;
} }
kfree (ti_manuf_desc); kfree(ti_manuf_desc);
// In order to update the I2C firmware we must change the type 2 record to type 0xF2.
// This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
// will download the latest firmware (padded to 15.5k) into the UMP ram.
// And finally when the device comes back up in download mode the driver will cause
// the new firmware to be copied from the UMP Ram to I2C and the firmware will update
// the record type from 0xf2 to 0x02.
/* /*
* In order to update the I2C firmware we must change the type
* 2 record to type 0xF2. This will force the UMP to come up
* in Boot Mode. Then while in boot mode, the driver will
* download the latest firmware (padded to 15.5k) into the
* UMP ram. Finally when the device comes back up in download
* mode the driver will cause the new firmware to be copied
* from the UMP Ram to I2C and the firmware will update the
* record type from 0xf2 to 0x02.
*
* Do we really have to copy the whole firmware image, * Do we really have to copy the whole firmware image,
* or could we do this in place! * or could we do this in place!
*/ */
// Allocate a 15.5k buffer + 3 byte header /* Allocate a 15.5k buffer + 3 byte header */
buffer_size = (((1024 * 16) - 512) + sizeof(struct ti_i2c_image_header)); buffer_size = (((1024 * 16) - 512) +
buffer = kmalloc (buffer_size, GFP_KERNEL); sizeof(struct ti_i2c_image_header));
buffer = kmalloc(buffer_size, GFP_KERNEL);
if (!buffer) { if (!buffer) {
dev_err (dev, "%s - out of memory\n", __func__); dev_err(dev, "%s - out of memory\n", __func__);
return -ENOMEM; return -ENOMEM;
} }
// Initialize the buffer to 0xff (pad the buffer) /* Initialize the buffer to 0xff (pad the buffer) */
memset (buffer, 0xff, buffer_size); memset(buffer, 0xff, buffer_size);
err = request_firmware(&fw, fw_name, dev); err = request_firmware(&fw, fw_name, dev);
if (err) { if (err) {
...@@ -1447,38 +1438,43 @@ static int TIDownloadFirmware (struct edgeport_serial *serial) ...@@ -1447,38 +1438,43 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
memcpy(buffer, &fw->data[4], fw->size - 4); memcpy(buffer, &fw->data[4], fw->size - 4);
release_firmware(fw); release_firmware(fw);
for(i = sizeof(struct ti_i2c_image_header); i < buffer_size; i++) { for (i = sizeof(struct ti_i2c_image_header);
i < buffer_size; i++) {
cs = (__u8)(cs + buffer[i]); cs = (__u8)(cs + buffer[i]);
} }
header = (struct ti_i2c_image_header *)buffer; header = (struct ti_i2c_image_header *)buffer;
// update length and checksum after padding /* update length and checksum after padding */
header->Length = cpu_to_le16((__u16)(buffer_size - sizeof(struct ti_i2c_image_header))); header->Length = cpu_to_le16((__u16)(buffer_size -
sizeof(struct ti_i2c_image_header)));
header->CheckSum = cs; header->CheckSum = cs;
// Download the operational code /* Download the operational code */
dbg ("%s - Downloading operational code image (TI UMP)", __func__); dbg("%s - Downloading operational code image (TI UMP)",
status = TIDownloadCodeImage (serial, buffer, buffer_size); __func__);
status = download_code(serial, buffer, buffer_size);
kfree (buffer); kfree(buffer);
if (status) { if (status) {
dbg ("%s - Error downloading operational code image", __func__); dbg("%s - Error downloading operational code image",
__func__);
return status; return status;
} }
// Device will reboot /* Device will reboot */
serial->product_info.TiMode = TI_MODE_TRANSITIONING; serial->product_info.TiMode = TI_MODE_TRANSITIONING;
dbg ("%s - Download successful -- Device rebooting...", __func__); dbg("%s - Download successful -- Device rebooting...",
__func__);
/* return an error on purpose */ /* return an error on purpose */
return -ENODEV; return -ENODEV;
} }
StayInBootMode: stayinbootmode:
// Eprom is invalid or blank stay in boot mode /* Eprom is invalid or blank stay in boot mode */
dbg("%s - STAYING IN BOOT MODE", __func__); dbg("%s - STAYING IN BOOT MODE", __func__);
serial->product_info.TiMode = TI_MODE_BOOT; serial->product_info.TiMode = TI_MODE_BOOT;
...@@ -1486,156 +1482,33 @@ static int TIDownloadFirmware (struct edgeport_serial *serial) ...@@ -1486,156 +1482,33 @@ static int TIDownloadFirmware (struct edgeport_serial *serial)
} }
static int TISetDtr (struct edgeport_port *port) static int ti_do_config(struct edgeport_port *port, int feature, int on)
{ {
int port_number = port->port->number - port->port->serial->minor; int port_number = port->port->number - port->port->serial->minor;
on = !!on; /* 1 or 0 not bitmask */
dbg ("%s", __func__); return send_cmd(port->port->serial->dev,
port->shadow_mcr |= MCR_DTR; feature, (__u8)(UMPM_UART1_PORT + port_number),
on, NULL, 0);
return TIWriteCommandSync (port->port->serial->dev,
UMPC_SET_CLR_DTR,
(__u8)(UMPM_UART1_PORT + port_number),
1, /* set */
NULL,
0);
}
static int TIClearDtr (struct edgeport_port *port)
{
int port_number = port->port->number - port->port->serial->minor;
dbg ("%s", __func__);
port->shadow_mcr &= ~MCR_DTR;
return TIWriteCommandSync (port->port->serial->dev,
UMPC_SET_CLR_DTR,
(__u8)(UMPM_UART1_PORT + port_number),
0, /* clear */
NULL,
0);
}
static int TISetRts (struct edgeport_port *port)
{
int port_number = port->port->number - port->port->serial->minor;
dbg ("%s", __func__);
port->shadow_mcr |= MCR_RTS;
return TIWriteCommandSync (port->port->serial->dev,
UMPC_SET_CLR_RTS,
(__u8)(UMPM_UART1_PORT + port_number),
1, /* set */
NULL,
0);
}
static int TIClearRts (struct edgeport_port *port)
{
int port_number = port->port->number - port->port->serial->minor;
dbg ("%s", __func__);
port->shadow_mcr &= ~MCR_RTS;
return TIWriteCommandSync (port->port->serial->dev,
UMPC_SET_CLR_RTS,
(__u8)(UMPM_UART1_PORT + port_number),
0, /* clear */
NULL,
0);
} }
static int TISetLoopBack (struct edgeport_port *port)
{
int port_number = port->port->number - port->port->serial->minor;
dbg ("%s", __func__);
return TIWriteCommandSync (port->port->serial->dev,
UMPC_SET_CLR_LOOPBACK,
(__u8)(UMPM_UART1_PORT + port_number),
1, /* set */
NULL,
0);
}
static int TIClearLoopBack (struct edgeport_port *port)
{
int port_number = port->port->number - port->port->serial->minor;
dbg ("%s", __func__);
return TIWriteCommandSync (port->port->serial->dev,
UMPC_SET_CLR_LOOPBACK,
(__u8)(UMPM_UART1_PORT + port_number),
0, /* clear */
NULL,
0);
}
static int TISetBreak (struct edgeport_port *port) static int restore_mcr(struct edgeport_port *port, __u8 mcr)
{
int port_number = port->port->number - port->port->serial->minor;
dbg ("%s", __func__);
return TIWriteCommandSync (port->port->serial->dev,
UMPC_SET_CLR_BREAK,
(__u8)(UMPM_UART1_PORT + port_number),
1, /* set */
NULL,
0);
}
static int TIClearBreak (struct edgeport_port *port)
{
int port_number = port->port->number - port->port->serial->minor;
dbg ("%s", __func__);
return TIWriteCommandSync (port->port->serial->dev,
UMPC_SET_CLR_BREAK,
(__u8)(UMPM_UART1_PORT + port_number),
0, /* clear */
NULL,
0);
}
static int TIRestoreMCR (struct edgeport_port *port, __u8 mcr)
{ {
int status = 0; int status = 0;
dbg ("%s - %x", __func__, mcr); dbg("%s - %x", __func__, mcr);
if (mcr & MCR_DTR)
status = TISetDtr (port);
else
status = TIClearDtr (port);
status = ti_do_config(port, UMPC_SET_CLR_DTR, mcr & MCR_DTR);
if (status) if (status)
return status; return status;
status = ti_do_config(port, UMPC_SET_CLR_RTS, mcr & MCR_RTS);
if (mcr & MCR_RTS)
status = TISetRts (port);
else
status = TIClearRts (port);
if (status) if (status)
return status; return status;
return ti_do_config(port, UMPC_SET_CLR_LOOPBACK, mcr & MCR_LOOPBACK);
if (mcr & MCR_LOOPBACK)
status = TISetLoopBack (port);
else
status = TIClearLoopBack (port);
return status;
} }
/* Convert TI LSR to standard UART flags */ /* Convert TI LSR to standard UART flags */
static __u8 MapLineStatus (__u8 ti_lsr) static __u8 map_line_status(__u8 ti_lsr)
{ {
__u8 lsr = 0; __u8 lsr = 0;
...@@ -1647,22 +1520,23 @@ static __u8 MapLineStatus (__u8 ti_lsr) ...@@ -1647,22 +1520,23 @@ static __u8 MapLineStatus (__u8 ti_lsr)
MAP_FLAG(UMP_UART_LSR_PE_MASK, LSR_PAR_ERR) /* parity error */ MAP_FLAG(UMP_UART_LSR_PE_MASK, LSR_PAR_ERR) /* parity error */
MAP_FLAG(UMP_UART_LSR_FE_MASK, LSR_FRM_ERR) /* framing error */ MAP_FLAG(UMP_UART_LSR_FE_MASK, LSR_FRM_ERR) /* framing error */
MAP_FLAG(UMP_UART_LSR_BR_MASK, LSR_BREAK) /* break detected */ MAP_FLAG(UMP_UART_LSR_BR_MASK, LSR_BREAK) /* break detected */
MAP_FLAG(UMP_UART_LSR_RX_MASK, LSR_RX_AVAIL) /* receive data available */ MAP_FLAG(UMP_UART_LSR_RX_MASK, LSR_RX_AVAIL) /* rx data available */
MAP_FLAG(UMP_UART_LSR_TX_MASK, LSR_TX_EMPTY) /* transmit holding register empty */ MAP_FLAG(UMP_UART_LSR_TX_MASK, LSR_TX_EMPTY) /* tx hold reg empty */
#undef MAP_FLAG #undef MAP_FLAG
return lsr; return lsr;
} }
static void handle_new_msr (struct edgeport_port *edge_port, __u8 msr) static void handle_new_msr(struct edgeport_port *edge_port, __u8 msr)
{ {
struct async_icount *icount; struct async_icount *icount;
struct tty_struct *tty; struct tty_struct *tty;
dbg ("%s - %02x", __func__, msr); dbg("%s - %02x", __func__, msr);
if (msr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR | EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) { if (msr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR |
EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) {
icount = &edge_port->icount; icount = &edge_port->icount;
/* update input line counters */ /* update input line counters */
...@@ -1674,7 +1548,7 @@ static void handle_new_msr (struct edgeport_port *edge_port, __u8 msr) ...@@ -1674,7 +1548,7 @@ static void handle_new_msr (struct edgeport_port *edge_port, __u8 msr)
icount->dcd++; icount->dcd++;
if (msr & EDGEPORT_MSR_DELTA_RI) if (msr & EDGEPORT_MSR_DELTA_RI)
icount->rng++; icount->rng++;
wake_up_interruptible (&edge_port->delta_msr_wait); wake_up_interruptible(&edge_port->delta_msr_wait);
} }
/* Save the new modem status */ /* Save the new modem status */
...@@ -1694,26 +1568,28 @@ static void handle_new_msr (struct edgeport_port *edge_port, __u8 msr) ...@@ -1694,26 +1568,28 @@ static void handle_new_msr (struct edgeport_port *edge_port, __u8 msr)
return; return;
} }
static void handle_new_lsr (struct edgeport_port *edge_port, int lsr_data, __u8 lsr, __u8 data) static void handle_new_lsr(struct edgeport_port *edge_port, int lsr_data,
__u8 lsr, __u8 data)
{ {
struct async_icount *icount; struct async_icount *icount;
__u8 new_lsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR | LSR_FRM_ERR | LSR_BREAK)); __u8 new_lsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR |
LSR_FRM_ERR | LSR_BREAK));
dbg ("%s - %02x", __func__, new_lsr); dbg("%s - %02x", __func__, new_lsr);
edge_port->shadow_lsr = lsr; edge_port->shadow_lsr = lsr;
if (new_lsr & LSR_BREAK) { if (new_lsr & LSR_BREAK)
/* /*
* Parity and Framing errors only count if they * Parity and Framing errors only count if they
* occur exclusive of a break being received. * occur exclusive of a break being received.
*/ */
new_lsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK); new_lsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK);
}
/* Place LSR data byte into Rx buffer */ /* Place LSR data byte into Rx buffer */
if (lsr_data && edge_port->port->tty) if (lsr_data && edge_port->port->tty)
edge_tty_recv(&edge_port->port->dev, edge_port->port->tty, &data, 1); edge_tty_recv(&edge_port->port->dev, edge_port->port->tty,
&data, 1);
/* update input line counters */ /* update input line counters */
icount = &edge_port->icount; icount = &edge_port->icount;
...@@ -1728,7 +1604,7 @@ static void handle_new_lsr (struct edgeport_port *edge_port, int lsr_data, __u8 ...@@ -1728,7 +1604,7 @@ static void handle_new_lsr (struct edgeport_port *edge_port, int lsr_data, __u8
} }
static void edge_interrupt_callback (struct urb *urb) static void edge_interrupt_callback(struct urb *urb)
{ {
struct edgeport_serial *edge_serial = urb->context; struct edgeport_serial *edge_serial = urb->context;
struct usb_serial_port *port; struct usb_serial_port *port;
...@@ -1762,66 +1638,71 @@ static void edge_interrupt_callback (struct urb *urb) ...@@ -1762,66 +1638,71 @@ static void edge_interrupt_callback (struct urb *urb)
} }
if (!length) { if (!length) {
dbg ("%s - no data in urb", __func__); dbg("%s - no data in urb", __func__);
goto exit; goto exit;
} }
usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, __func__, length, data); usb_serial_debug_data(debug, &edge_serial->serial->dev->dev,
__func__, length, data);
if (length != 2) { if (length != 2) {
dbg ("%s - expecting packet of size 2, got %d", __func__, length); dbg("%s - expecting packet of size 2, got %d",
__func__, length);
goto exit; goto exit;
} }
port_number = TIUMP_GET_PORT_FROM_CODE (data[0]); port_number = TIUMP_GET_PORT_FROM_CODE(data[0]);
function = TIUMP_GET_FUNC_FROM_CODE (data[0]); function = TIUMP_GET_FUNC_FROM_CODE(data[0]);
dbg ("%s - port_number %d, function %d, info 0x%x", dbg("%s - port_number %d, function %d, info 0x%x",
__func__, port_number, function, data[1]); __func__, port_number, function, data[1]);
port = edge_serial->serial->port[port_number]; port = edge_serial->serial->port[port_number];
edge_port = usb_get_serial_port_data(port); edge_port = usb_get_serial_port_data(port);
if (!edge_port) { if (!edge_port) {
dbg ("%s - edge_port not found", __func__); dbg("%s - edge_port not found", __func__);
return; return;
} }
switch (function) { switch (function) {
case TIUMP_INTERRUPT_CODE_LSR: case TIUMP_INTERRUPT_CODE_LSR:
lsr = MapLineStatus(data[1]); lsr = map_line_status(data[1]);
if (lsr & UMP_UART_LSR_DATA_MASK) { if (lsr & UMP_UART_LSR_DATA_MASK) {
/* Save the LSR event for bulk read completion routine */ /* Save the LSR event for bulk read
dbg ("%s - LSR Event Port %u LSR Status = %02x", completion routine */
dbg("%s - LSR Event Port %u LSR Status = %02x",
__func__, port_number, lsr); __func__, port_number, lsr);
edge_port->lsr_event = 1; edge_port->lsr_event = 1;
edge_port->lsr_mask = lsr; edge_port->lsr_mask = lsr;
} else { } else {
dbg ("%s - ===== Port %d LSR Status = %02x ======", dbg("%s - ===== Port %d LSR Status = %02x ======",
__func__, port_number, lsr); __func__, port_number, lsr);
handle_new_lsr (edge_port, 0, lsr, 0); handle_new_lsr(edge_port, 0, lsr, 0);
} }
break; break;
case TIUMP_INTERRUPT_CODE_MSR: // MSR case TIUMP_INTERRUPT_CODE_MSR: /* MSR */
/* Copy MSR from UMP */ /* Copy MSR from UMP */
msr = data[1]; msr = data[1];
dbg ("%s - ===== Port %u MSR Status = %02x ======\n", dbg("%s - ===== Port %u MSR Status = %02x ======\n",
__func__, port_number, msr); __func__, port_number, msr);
handle_new_msr (edge_port, msr); handle_new_msr(edge_port, msr);
break; break;
default: default:
dev_err (&urb->dev->dev, "%s - Unknown Interrupt code from UMP %x\n", dev_err(&urb->dev->dev,
"%s - Unknown Interrupt code from UMP %x\n",
__func__, data[1]); __func__, data[1]);
break; break;
} }
exit: exit:
retval = usb_submit_urb (urb, GFP_ATOMIC); retval = usb_submit_urb(urb, GFP_ATOMIC);
if (retval) if (retval)
dev_err (&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n", dev_err(&urb->dev->dev,
"%s - usb_submit_urb failed with result %d\n",
__func__, retval); __func__, retval);
} }
static void edge_bulk_in_callback (struct urb *urb) static void edge_bulk_in_callback(struct urb *urb)
{ {
struct edgeport_port *edge_port = urb->context; struct edgeport_port *edge_port = urb->context;
unsigned char *data = urb->transfer_buffer; unsigned char *data = urb->transfer_buffer;
...@@ -1844,7 +1725,8 @@ static void edge_bulk_in_callback (struct urb *urb) ...@@ -1844,7 +1725,8 @@ static void edge_bulk_in_callback (struct urb *urb)
__func__, status); __func__, status);
return; return;
default: default:
dev_err (&urb->dev->dev,"%s - nonzero read bulk status received: %d\n", dev_err(&urb->dev->dev,
"%s - nonzero read bulk status received: %d\n",
__func__, status); __func__, status);
} }
...@@ -1852,7 +1734,7 @@ static void edge_bulk_in_callback (struct urb *urb) ...@@ -1852,7 +1734,7 @@ static void edge_bulk_in_callback (struct urb *urb)
goto exit; goto exit;
if (status) { if (status) {
dev_err(&urb->dev->dev,"%s - stopping read!\n", __func__); dev_err(&urb->dev->dev, "%s - stopping read!\n", __func__);
return; return;
} }
...@@ -1860,9 +1742,9 @@ static void edge_bulk_in_callback (struct urb *urb) ...@@ -1860,9 +1742,9 @@ static void edge_bulk_in_callback (struct urb *urb)
if (edge_port->lsr_event) { if (edge_port->lsr_event) {
edge_port->lsr_event = 0; edge_port->lsr_event = 0;
dbg ("%s ===== Port %u LSR Status = %02x, Data = %02x ======", dbg("%s ===== Port %u LSR Status = %02x, Data = %02x ======",
__func__, port_number, edge_port->lsr_mask, *data); __func__, port_number, edge_port->lsr_mask, *data);
handle_new_lsr (edge_port, 1, edge_port->lsr_mask, *data); handle_new_lsr(edge_port, 1, edge_port->lsr_mask, *data);
/* Adjust buffer length/pointer */ /* Adjust buffer length/pointer */
--urb->actual_length; --urb->actual_length;
++data; ++data;
...@@ -1870,13 +1752,14 @@ static void edge_bulk_in_callback (struct urb *urb) ...@@ -1870,13 +1752,14 @@ static void edge_bulk_in_callback (struct urb *urb)
tty = edge_port->port->tty; tty = edge_port->port->tty;
if (tty && urb->actual_length) { if (tty && urb->actual_length) {
usb_serial_debug_data(debug, &edge_port->port->dev, __func__, urb->actual_length, data); usb_serial_debug_data(debug, &edge_port->port->dev,
__func__, urb->actual_length, data);
if (edge_port->close_pending) { if (edge_port->close_pending)
dbg ("%s - close is pending, dropping data on the floor.", __func__); dbg("%s - close pending, dropping data on the floor",
} else { __func__);
edge_tty_recv(&edge_port->port->dev, tty, data, urb->actual_length); else
} edge_tty_recv(&edge_port->port->dev, tty, data,
urb->actual_length);
edge_port->icount.rx += urb->actual_length; edge_port->icount.rx += urb->actual_length;
} }
...@@ -1891,37 +1774,31 @@ static void edge_bulk_in_callback (struct urb *urb) ...@@ -1891,37 +1774,31 @@ static void edge_bulk_in_callback (struct urb *urb)
} }
spin_unlock(&edge_port->ep_lock); spin_unlock(&edge_port->ep_lock);
if (retval) if (retval)
dev_err (&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n", dev_err(&urb->dev->dev,
"%s - usb_submit_urb failed with result %d\n",
__func__, retval); __func__, retval);
} }
static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned char *data, int length) static void edge_tty_recv(struct device *dev, struct tty_struct *tty,
unsigned char *data, int length)
{ {
int cnt; int queued;
do { tty_buffer_request_room(tty, length);
cnt = tty_buffer_request_room(tty, length); queued = tty_insert_flip_string(tty, data, length);
if (cnt < length) { if (queued < length)
dev_err(dev, "%s - dropping data, %d bytes lost\n", dev_err(dev, "%s - dropping data, %d bytes lost\n",
__func__, length - cnt); __func__, length - queued);
if(cnt == 0)
break;
}
tty_insert_flip_string(tty, data, cnt);
data += cnt;
length -= cnt;
} while (length > 0);
tty_flip_buffer_push(tty); tty_flip_buffer_push(tty);
} }
static void edge_bulk_out_callback (struct urb *urb) static void edge_bulk_out_callback(struct urb *urb)
{ {
struct usb_serial_port *port = urb->context; struct usb_serial_port *port = urb->context;
struct edgeport_port *edge_port = usb_get_serial_port_data(port); struct edgeport_port *edge_port = usb_get_serial_port_data(port);
int status = urb->status; int status = urb->status;
dbg ("%s - port %d", __func__, port->number); dbg("%s - port %d", __func__, port->number);
edge_port->ep_write_urb_in_use = 0; edge_port->ep_write_urb_in_use = 0;
...@@ -1945,7 +1822,7 @@ static void edge_bulk_out_callback (struct urb *urb) ...@@ -1945,7 +1822,7 @@ static void edge_bulk_out_callback (struct urb *urb)
edge_send(port); edge_send(port);
} }
static int edge_open (struct usb_serial_port *port, struct file * filp) static int edge_open(struct usb_serial_port *port, struct file *filp)
{ {
struct edgeport_port *edge_port = usb_get_serial_port_data(port); struct edgeport_port *edge_port = usb_get_serial_port_data(port);
struct edgeport_serial *edge_serial; struct edgeport_serial *edge_serial;
...@@ -1974,109 +1851,110 @@ static int edge_open (struct usb_serial_port *port, struct file * filp) ...@@ -1974,109 +1851,110 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
edge_port->dma_address = UMPD_OEDB2_ADDRESS; edge_port->dma_address = UMPD_OEDB2_ADDRESS;
break; break;
default: default:
dev_err (&port->dev, "Unknown port number!!!\n"); dev_err(&port->dev, "Unknown port number!!!\n");
return -ENODEV; return -ENODEV;
} }
dbg ("%s - port_number = %d, uart_base = %04x, dma_address = %04x", dbg("%s - port_number = %d, uart_base = %04x, dma_address = %04x",
__func__, port_number, edge_port->uart_base, edge_port->dma_address); __func__, port_number, edge_port->uart_base,
edge_port->dma_address);
dev = port->serial->dev; dev = port->serial->dev;
memset (&(edge_port->icount), 0x00, sizeof(edge_port->icount)); memset(&(edge_port->icount), 0x00, sizeof(edge_port->icount));
init_waitqueue_head (&edge_port->delta_msr_wait); init_waitqueue_head(&edge_port->delta_msr_wait);
/* turn off loopback */ /* turn off loopback */
status = TIClearLoopBack (edge_port); status = ti_do_config(edge_port, UMPC_SET_CLR_LOOPBACK, 0);
if (status) { if (status) {
dev_err(&port->dev,"%s - cannot send clear loopback command, %d\n", dev_err(&port->dev,
"%s - cannot send clear loopback command, %d\n",
__func__, status); __func__, status);
return status; return status;
} }
/* set up the port settings */ /* set up the port settings */
edge_set_termios (port, port->tty->termios); edge_set_termios(port, port->tty->termios);
/* open up the port */ /* open up the port */
/* milliseconds to timeout for DMA transfer */ /* milliseconds to timeout for DMA transfer */
transaction_timeout = 2; transaction_timeout = 2;
edge_port->ump_read_timeout = max (20, ((transaction_timeout * 3) / 2) ); edge_port->ump_read_timeout =
max(20, ((transaction_timeout * 3) / 2));
// milliseconds to timeout for DMA transfer /* milliseconds to timeout for DMA transfer */
open_settings = (u8)(UMP_DMA_MODE_CONTINOUS | open_settings = (u8)(UMP_DMA_MODE_CONTINOUS |
UMP_PIPE_TRANS_TIMEOUT_ENA | UMP_PIPE_TRANS_TIMEOUT_ENA |
(transaction_timeout << 2)); (transaction_timeout << 2));
dbg ("%s - Sending UMPC_OPEN_PORT", __func__); dbg("%s - Sending UMPC_OPEN_PORT", __func__);
/* Tell TI to open and start the port */ /* Tell TI to open and start the port */
status = TIWriteCommandSync (dev, status = send_cmd(dev, UMPC_OPEN_PORT,
UMPC_OPEN_PORT, (u8)(UMPM_UART1_PORT + port_number), open_settings, NULL, 0);
(u8)(UMPM_UART1_PORT + port_number),
open_settings,
NULL,
0);
if (status) { if (status) {
dev_err(&port->dev,"%s - cannot send open command, %d\n", __func__, status); dev_err(&port->dev, "%s - cannot send open command, %d\n",
__func__, status);
return status; return status;
} }
/* Start the DMA? */ /* Start the DMA? */
status = TIWriteCommandSync (dev, status = send_cmd(dev, UMPC_START_PORT,
UMPC_START_PORT, (u8)(UMPM_UART1_PORT + port_number), 0, NULL, 0);
(u8)(UMPM_UART1_PORT + port_number),
0,
NULL,
0);
if (status) { if (status) {
dev_err(&port->dev,"%s - cannot send start DMA command, %d\n", __func__, status); dev_err(&port->dev, "%s - cannot send start DMA command, %d\n",
__func__, status);
return status; return status;
} }
/* Clear TX and RX buffers in UMP */ /* Clear TX and RX buffers in UMP */
status = TIPurgeDataSync (port, UMP_PORT_DIR_OUT | UMP_PORT_DIR_IN); status = purge_port(port, UMP_PORT_DIR_OUT | UMP_PORT_DIR_IN);
if (status) { if (status) {
dev_err(&port->dev,"%s - cannot send clear buffers command, %d\n", __func__, status); dev_err(&port->dev,
"%s - cannot send clear buffers command, %d\n",
__func__, status);
return status; return status;
} }
/* Read Initial MSR */ /* Read Initial MSR */
status = TIReadVendorRequestSync (dev, status = ti_vread_sync(dev, UMPC_READ_MSR, 0,
UMPC_READ_MSR, // Request (__u16)(UMPM_UART1_PORT + port_number),
0, // wValue &edge_port->shadow_msr, 1);
(__u16)(UMPM_UART1_PORT + port_number), // wIndex (Address)
&edge_port->shadow_msr, // TransferBuffer
1); // TransferBufferLength
if (status) { if (status) {
dev_err(&port->dev,"%s - cannot send read MSR command, %d\n", __func__, status); dev_err(&port->dev, "%s - cannot send read MSR command, %d\n",
__func__, status);
return status; return status;
} }
dbg ("ShadowMSR 0x%X", edge_port->shadow_msr); dbg("ShadowMSR 0x%X", edge_port->shadow_msr);
/* Set Initial MCR */ /* Set Initial MCR */
edge_port->shadow_mcr = MCR_RTS | MCR_DTR; edge_port->shadow_mcr = MCR_RTS | MCR_DTR;
dbg ("ShadowMCR 0x%X", edge_port->shadow_mcr); dbg("ShadowMCR 0x%X", edge_port->shadow_mcr);
edge_serial = edge_port->edge_serial; edge_serial = edge_port->edge_serial;
if (mutex_lock_interruptible(&edge_serial->es_lock)) if (mutex_lock_interruptible(&edge_serial->es_lock))
return -ERESTARTSYS; return -ERESTARTSYS;
if (edge_serial->num_ports_open == 0) { if (edge_serial->num_ports_open == 0) {
/* we are the first port to be opened, let's post the interrupt urb */ /* we are the first port to open, post the interrupt urb */
urb = edge_serial->serial->port[0]->interrupt_in_urb; urb = edge_serial->serial->port[0]->interrupt_in_urb;
if (!urb) { if (!urb) {
dev_err (&port->dev, "%s - no interrupt urb present, exiting\n", __func__); dev_err(&port->dev,
"%s - no interrupt urb present, exiting\n",
__func__);
status = -EINVAL; status = -EINVAL;
goto release_es_lock; goto release_es_lock;
} }
urb->complete = edge_interrupt_callback; urb->complete = edge_interrupt_callback;
urb->context = edge_serial; urb->context = edge_serial;
urb->dev = dev; urb->dev = dev;
status = usb_submit_urb (urb, GFP_KERNEL); status = usb_submit_urb(urb, GFP_KERNEL);
if (status) { if (status) {
dev_err (&port->dev, "%s - usb_submit_urb failed with value %d\n", __func__, status); dev_err(&port->dev,
"%s - usb_submit_urb failed with value %d\n",
__func__, status);
goto release_es_lock; goto release_es_lock;
} }
} }
...@@ -2085,13 +1963,14 @@ static int edge_open (struct usb_serial_port *port, struct file * filp) ...@@ -2085,13 +1963,14 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
* reset the data toggle on the bulk endpoints to work around bug in * reset the data toggle on the bulk endpoints to work around bug in
* host controllers where things get out of sync some times * host controllers where things get out of sync some times
*/ */
usb_clear_halt (dev, port->write_urb->pipe); usb_clear_halt(dev, port->write_urb->pipe);
usb_clear_halt (dev, port->read_urb->pipe); usb_clear_halt(dev, port->read_urb->pipe);
/* start up our bulk read urb */ /* start up our bulk read urb */
urb = port->read_urb; urb = port->read_urb;
if (!urb) { if (!urb) {
dev_err (&port->dev, "%s - no read urb present, exiting\n", __func__); dev_err(&port->dev, "%s - no read urb present, exiting\n",
__func__);
status = -EINVAL; status = -EINVAL;
goto unlink_int_urb; goto unlink_int_urb;
} }
...@@ -2099,9 +1978,11 @@ static int edge_open (struct usb_serial_port *port, struct file * filp) ...@@ -2099,9 +1978,11 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
urb->complete = edge_bulk_in_callback; urb->complete = edge_bulk_in_callback;
urb->context = edge_port; urb->context = edge_port;
urb->dev = dev; urb->dev = dev;
status = usb_submit_urb (urb, GFP_KERNEL); status = usb_submit_urb(urb, GFP_KERNEL);
if (status) { if (status) {
dev_err (&port->dev, "%s - read bulk usb_submit_urb failed with value %d\n", __func__, status); dev_err(&port->dev,
"%s - read bulk usb_submit_urb failed with value %d\n",
__func__, status);
goto unlink_int_urb; goto unlink_int_urb;
} }
...@@ -2119,7 +2000,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp) ...@@ -2119,7 +2000,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
return status; return status;
} }
static void edge_close (struct usb_serial_port *port, struct file *filp) static void edge_close(struct usb_serial_port *port, struct file *filp)
{ {
struct edgeport_serial *edge_serial; struct edgeport_serial *edge_serial;
struct edgeport_port *edge_port; struct edgeport_port *edge_port;
...@@ -2130,7 +2011,7 @@ static void edge_close (struct usb_serial_port *port, struct file *filp) ...@@ -2130,7 +2011,7 @@ static void edge_close (struct usb_serial_port *port, struct file *filp)
edge_serial = usb_get_serial_data(port->serial); edge_serial = usb_get_serial_data(port->serial);
edge_port = usb_get_serial_port_data(port); edge_port = usb_get_serial_port_data(port);
if ((edge_serial == NULL) || (edge_port == NULL)) if (edge_serial == NULL || edge_port == NULL)
return; return;
/* The bulkreadcompletion routine will check /* The bulkreadcompletion routine will check
...@@ -2138,7 +2019,7 @@ static void edge_close (struct usb_serial_port *port, struct file *filp) ...@@ -2138,7 +2019,7 @@ static void edge_close (struct usb_serial_port *port, struct file *filp)
edge_port->close_pending = 1; edge_port->close_pending = 1;
/* chase the port close and flush */ /* chase the port close and flush */
TIChasePort (edge_port, (HZ*closing_wait)/100, 1); chase_port(edge_port, (HZ * closing_wait) / 100, 1);
usb_kill_urb(port->read_urb); usb_kill_urb(port->read_urb);
usb_kill_urb(port->write_urb); usb_kill_urb(port->write_urb);
...@@ -2148,7 +2029,7 @@ static void edge_close (struct usb_serial_port *port, struct file *filp) ...@@ -2148,7 +2029,7 @@ static void edge_close (struct usb_serial_port *port, struct file *filp)
* send a close port command to it */ * send a close port command to it */
dbg("%s - send umpc_close_port", __func__); dbg("%s - send umpc_close_port", __func__);
port_number = port->number - port->serial->minor; port_number = port->number - port->serial->minor;
status = TIWriteCommandSync (port->serial->dev, status = send_cmd(port->serial->dev,
UMPC_CLOSE_PORT, UMPC_CLOSE_PORT,
(__u8)(UMPM_UART1_PORT + port_number), (__u8)(UMPM_UART1_PORT + port_number),
0, 0,
...@@ -2167,7 +2048,8 @@ static void edge_close (struct usb_serial_port *port, struct file *filp) ...@@ -2167,7 +2048,8 @@ static void edge_close (struct usb_serial_port *port, struct file *filp)
dbg("%s - exited", __func__); dbg("%s - exited", __func__);
} }
static int edge_write (struct usb_serial_port *port, const unsigned char *data, int count) static int edge_write(struct usb_serial_port *port, const unsigned char *data,
int count)
{ {
struct edgeport_port *edge_port = usb_get_serial_port_data(port); struct edgeport_port *edge_port = usb_get_serial_port_data(port);
unsigned long flags; unsigned long flags;
...@@ -2223,11 +2105,12 @@ static void edge_send(struct usb_serial_port *port) ...@@ -2223,11 +2105,12 @@ static void edge_send(struct usb_serial_port *port)
spin_unlock_irqrestore(&edge_port->ep_lock, flags); spin_unlock_irqrestore(&edge_port->ep_lock, flags);
usb_serial_debug_data(debug, &port->dev, __func__, count, port->write_urb->transfer_buffer); usb_serial_debug_data(debug, &port->dev, __func__, count,
port->write_urb->transfer_buffer);
/* set up our urb */ /* set up our urb */
usb_fill_bulk_urb (port->write_urb, port->serial->dev, usb_fill_bulk_urb(port->write_urb, port->serial->dev,
usb_sndbulkpipe (port->serial->dev, usb_sndbulkpipe(port->serial->dev,
port->bulk_out_endpointAddress), port->bulk_out_endpointAddress),
port->write_urb->transfer_buffer, count, port->write_urb->transfer_buffer, count,
edge_bulk_out_callback, edge_bulk_out_callback,
...@@ -2236,22 +2119,21 @@ static void edge_send(struct usb_serial_port *port) ...@@ -2236,22 +2119,21 @@ static void edge_send(struct usb_serial_port *port)
/* send the data out the bulk port */ /* send the data out the bulk port */
result = usb_submit_urb(port->write_urb, GFP_ATOMIC); result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
if (result) { if (result) {
dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result); dev_err(&port->dev,
"%s - failed submitting write urb, error %d\n",
__func__, result);
edge_port->ep_write_urb_in_use = 0; edge_port->ep_write_urb_in_use = 0;
// TODO: reschedule edge_send /* TODO: reschedule edge_send */
} else { } else
edge_port->icount.tx += count; edge_port->icount.tx += count;
}
/* wakeup any process waiting for writes to complete */ /* wakeup any process waiting for writes to complete */
/* there is now more room in the buffer for new writes */ /* there is now more room in the buffer for new writes */
if (tty) { if (tty)
/* let the tty driver wakeup if it has a special write_wakeup function */
tty_wakeup(tty); tty_wakeup(tty);
}
} }
static int edge_write_room (struct usb_serial_port *port) static int edge_write_room(struct usb_serial_port *port)
{ {
struct edgeport_port *edge_port = usb_get_serial_port_data(port); struct edgeport_port *edge_port = usb_get_serial_port_data(port);
int room = 0; int room = 0;
...@@ -2260,9 +2142,9 @@ static int edge_write_room (struct usb_serial_port *port) ...@@ -2260,9 +2142,9 @@ static int edge_write_room (struct usb_serial_port *port)
dbg("%s - port %d", __func__, port->number); dbg("%s - port %d", __func__, port->number);
if (edge_port == NULL) if (edge_port == NULL)
return -ENODEV; return 0;
if (edge_port->close_pending == 1) if (edge_port->close_pending == 1)
return -ENODEV; return 0;
spin_lock_irqsave(&edge_port->ep_lock, flags); spin_lock_irqsave(&edge_port->ep_lock, flags);
room = edge_buf_space_avail(edge_port->ep_out_buf); 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,7 +2154,7 @@ static int edge_write_room (struct usb_serial_port *port)
return room; return room;
} }
static int edge_chars_in_buffer (struct usb_serial_port *port) static int edge_chars_in_buffer(struct usb_serial_port *port)
{ {
struct edgeport_port *edge_port = usb_get_serial_port_data(port); struct edgeport_port *edge_port = usb_get_serial_port_data(port);
int chars = 0; int chars = 0;
...@@ -2281,22 +2163,22 @@ static int edge_chars_in_buffer (struct usb_serial_port *port) ...@@ -2281,22 +2163,22 @@ static int edge_chars_in_buffer (struct usb_serial_port *port)
dbg("%s - port %d", __func__, port->number); dbg("%s - port %d", __func__, port->number);
if (edge_port == NULL) if (edge_port == NULL)
return -ENODEV; return 0;
if (edge_port->close_pending == 1) if (edge_port->close_pending == 1)
return -ENODEV; return 0;
spin_lock_irqsave(&edge_port->ep_lock, flags); spin_lock_irqsave(&edge_port->ep_lock, flags);
chars = edge_buf_data_avail(edge_port->ep_out_buf); chars = edge_buf_data_avail(edge_port->ep_out_buf);
spin_unlock_irqrestore(&edge_port->ep_lock, flags); spin_unlock_irqrestore(&edge_port->ep_lock, flags);
dbg ("%s - returns %d", __func__, chars); dbg("%s - returns %d", __func__, chars);
return chars; return chars;
} }
static void edge_throttle (struct usb_serial_port *port) static void edge_throttle(struct usb_serial_port *port)
{ {
struct edgeport_port *edge_port = usb_get_serial_port_data(port); struct edgeport_port *edge_port = usb_get_serial_port_data(port);
struct tty_struct *tty; struct tty_struct *tty = port->tty;
int status; int status;
dbg("%s - port %d", __func__, port->number); dbg("%s - port %d", __func__, port->number);
...@@ -2304,19 +2186,14 @@ static void edge_throttle (struct usb_serial_port *port) ...@@ -2304,19 +2186,14 @@ static void edge_throttle (struct usb_serial_port *port)
if (edge_port == NULL) if (edge_port == NULL)
return; return;
tty = port->tty;
if (!tty) {
dbg ("%s - no tty available", __func__);
return;
}
/* if we are implementing XON/XOFF, send the stop character */ /* if we are implementing XON/XOFF, send the stop character */
if (I_IXOFF(tty)) { if (I_IXOFF(tty)) {
unsigned char stop_char = STOP_CHAR(tty); unsigned char stop_char = STOP_CHAR(tty);
status = edge_write (port, &stop_char, 1); status = edge_write(port, &stop_char, 1);
if (status <= 0) { if (status <= 0)
dev_err(&port->dev, "%s - failed to write stop character, %d\n", __func__, status); dev_err(&port->dev,
} "%s - failed to write stop character, %d\n",
__func__, status);
} }
/* if we are implementing RTS/CTS, stop reads */ /* if we are implementing RTS/CTS, stop reads */
...@@ -2326,10 +2203,10 @@ static void edge_throttle (struct usb_serial_port *port) ...@@ -2326,10 +2203,10 @@ static void edge_throttle (struct usb_serial_port *port)
} }
static void edge_unthrottle (struct usb_serial_port *port) static void edge_unthrottle(struct usb_serial_port *port)
{ {
struct edgeport_port *edge_port = usb_get_serial_port_data(port); struct edgeport_port *edge_port = usb_get_serial_port_data(port);
struct tty_struct *tty; struct tty_struct *tty = port->tty;
int status; int status;
dbg("%s - port %d", __func__, port->number); dbg("%s - port %d", __func__, port->number);
...@@ -2337,27 +2214,23 @@ static void edge_unthrottle (struct usb_serial_port *port) ...@@ -2337,27 +2214,23 @@ static void edge_unthrottle (struct usb_serial_port *port)
if (edge_port == NULL) if (edge_port == NULL)
return; return;
tty = port->tty;
if (!tty) {
dbg ("%s - no tty available", __func__);
return;
}
/* if we are implementing XON/XOFF, send the start character */ /* if we are implementing XON/XOFF, send the start character */
if (I_IXOFF(tty)) { if (I_IXOFF(tty)) {
unsigned char start_char = START_CHAR(tty); unsigned char start_char = START_CHAR(tty);
status = edge_write (port, &start_char, 1); status = edge_write(port, &start_char, 1);
if (status <= 0) { if (status <= 0)
dev_err(&port->dev, "%s - failed to write start character, %d\n", __func__, status); dev_err(&port->dev,
} "%s - failed to write start character, %d\n",
__func__, status);
} }
/* if we are implementing RTS/CTS, restart reads */ /* if we are implementing RTS/CTS, restart reads */
/* are the Edgeport will assert the RTS line */ /* are the Edgeport will assert the RTS line */
if (C_CRTSCTS(tty)) { if (C_CRTSCTS(tty)) {
status = restart_read(edge_port); status = restart_read(edge_port);
if (status) if (status)
dev_err(&port->dev, "%s - read bulk usb_submit_urb failed with value %d\n", __func__, status); dev_err(&port->dev,
"%s - read bulk usb_submit_urb failed: %d\n",
__func__, status);
} }
} }
...@@ -2398,22 +2271,26 @@ static int restart_read(struct edgeport_port *edge_port) ...@@ -2398,22 +2271,26 @@ static int restart_read(struct edgeport_port *edge_port)
return status; return status;
} }
static void change_port_settings (struct edgeport_port *edge_port, struct ktermios *old_termios) static void change_port_settings(struct edgeport_port *edge_port,
struct ktermios *old_termios)
{ {
struct ump_uart_config *config; struct ump_uart_config *config;
struct tty_struct *tty; struct tty_struct *tty;
int baud; int baud;
unsigned cflag; unsigned cflag;
int status; int status;
int port_number = edge_port->port->number - edge_port->port->serial->minor; int port_number = edge_port->port->number -
edge_port->port->serial->minor;
dbg("%s - port %d", __func__, edge_port->port->number); dbg("%s - port %d", __func__, edge_port->port->number);
tty = edge_port->port->tty; tty = edge_port->port->tty;
config = kmalloc (sizeof (*config), GFP_KERNEL); config = kmalloc(sizeof(*config), GFP_KERNEL);
if (!config) { if (!config) {
dev_err (&edge_port->port->dev, "%s - out of memory\n", __func__); *tty->termios = *old_termios;
dev_err(&edge_port->port->dev, "%s - out of memory\n",
__func__);
return; return;
} }
...@@ -2429,20 +2306,20 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi ...@@ -2429,20 +2306,20 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
switch (cflag & CSIZE) { switch (cflag & CSIZE) {
case CS5: case CS5:
config->bDataBits = UMP_UART_CHAR5BITS; config->bDataBits = UMP_UART_CHAR5BITS;
dbg ("%s - data bits = 5", __func__); dbg("%s - data bits = 5", __func__);
break; break;
case CS6: case CS6:
config->bDataBits = UMP_UART_CHAR6BITS; config->bDataBits = UMP_UART_CHAR6BITS;
dbg ("%s - data bits = 6", __func__); dbg("%s - data bits = 6", __func__);
break; break;
case CS7: case CS7:
config->bDataBits = UMP_UART_CHAR7BITS; config->bDataBits = UMP_UART_CHAR7BITS;
dbg ("%s - data bits = 7", __func__); dbg("%s - data bits = 7", __func__);
break; break;
default: default:
case CS8: case CS8:
config->bDataBits = UMP_UART_CHAR8BITS; config->bDataBits = UMP_UART_CHAR8BITS;
dbg ("%s - data bits = 8", __func__); dbg("%s - data bits = 8", __func__);
break; break;
} }
...@@ -2480,29 +2357,26 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi ...@@ -2480,29 +2357,26 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
restart_read(edge_port); restart_read(edge_port);
} }
/* if we are implementing XON/XOFF, set the start and stop character in the device */ /* if we are implementing XON/XOFF, set the start and stop
if (I_IXOFF(tty) || I_IXON(tty)) { character in the device */
config->cXon = START_CHAR(tty); config->cXon = START_CHAR(tty);
config->cXoff = STOP_CHAR(tty); config->cXoff = STOP_CHAR(tty);
/* if we are implementing INBOUND XON/XOFF */ /* if we are implementing INBOUND XON/XOFF */
if (I_IXOFF(tty)) { if (I_IXOFF(tty)) {
config->wFlags |= UMP_MASK_UART_FLAGS_IN_X; config->wFlags |= UMP_MASK_UART_FLAGS_IN_X;
dbg ("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", dbg("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
__func__, config->cXon, config->cXoff); __func__, config->cXon, config->cXoff);
} else { } else
dbg ("%s - INBOUND XON/XOFF is disabled", __func__); dbg("%s - INBOUND XON/XOFF is disabled", __func__);
}
/* if we are implementing OUTBOUND XON/XOFF */ /* if we are implementing OUTBOUND XON/XOFF */
if (I_IXON(tty)) { if (I_IXON(tty)) {
config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X; config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X;
dbg ("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", dbg("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
__func__, config->cXon, config->cXoff); __func__, config->cXon, config->cXoff);
} else { } else
dbg ("%s - OUTBOUND XON/XOFF is disabled", __func__); dbg("%s - OUTBOUND XON/XOFF is disabled", __func__);
}
}
tty->termios->c_cflag &= ~CMSPAR; tty->termios->c_cflag &= ~CMSPAR;
...@@ -2519,62 +2393,52 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi ...@@ -2519,62 +2393,52 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
/* FIXME: Recompute actual baud from divisor here */ /* FIXME: Recompute actual baud from divisor here */
dbg ("%s - baud rate = %d, wBaudRate = %d", __func__, baud, config->wBaudRate); dbg("%s - baud rate = %d, wBaudRate = %d", __func__, baud,
config->wBaudRate);
dbg ("wBaudRate: %d", (int)(461550L / config->wBaudRate)); dbg("wBaudRate: %d", (int)(461550L / config->wBaudRate));
dbg ("wFlags: 0x%x", config->wFlags); dbg("wFlags: 0x%x", config->wFlags);
dbg ("bDataBits: %d", config->bDataBits); dbg("bDataBits: %d", config->bDataBits);
dbg ("bParity: %d", config->bParity); dbg("bParity: %d", config->bParity);
dbg ("bStopBits: %d", config->bStopBits); dbg("bStopBits: %d", config->bStopBits);
dbg ("cXon: %d", config->cXon); dbg("cXon: %d", config->cXon);
dbg ("cXoff: %d", config->cXoff); dbg("cXoff: %d", config->cXoff);
dbg ("bUartMode: %d", config->bUartMode); dbg("bUartMode: %d", config->bUartMode);
/* move the word values into big endian mode */ /* move the word values into big endian mode */
cpu_to_be16s (&config->wFlags); cpu_to_be16s(&config->wFlags);
cpu_to_be16s (&config->wBaudRate); cpu_to_be16s(&config->wBaudRate);
status = TIWriteCommandSync (edge_port->port->serial->dev, status = send_cmd(edge_port->port->serial->dev, UMPC_SET_CONFIG,
UMPC_SET_CONFIG,
(__u8)(UMPM_UART1_PORT + port_number), (__u8)(UMPM_UART1_PORT + port_number),
0, 0, (__u8 *)config, sizeof(*config));
(__u8 *)config, if (status)
sizeof(*config)); dbg("%s - error %d when trying to write config to device",
if (status) {
dbg ("%s - error %d when trying to write config to device",
__func__, status); __func__, status);
} kfree(config);
kfree (config);
return; return;
} }
static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old_termios) static void edge_set_termios(struct usb_serial_port *port,
struct ktermios *old_termios)
{ {
struct edgeport_port *edge_port = usb_get_serial_port_data(port); struct edgeport_port *edge_port = usb_get_serial_port_data(port);
struct tty_struct *tty = port->tty; struct tty_struct *tty = port->tty;
unsigned int cflag;
cflag = tty->termios->c_cflag;
dbg("%s - clfag %08x iflag %08x", __func__, dbg("%s - clfag %08x iflag %08x", __func__,
tty->termios->c_cflag, tty->termios->c_iflag); tty->termios->c_cflag, tty->termios->c_iflag);
dbg("%s - old clfag %08x old iflag %08x", __func__, dbg("%s - old clfag %08x old iflag %08x", __func__,
old_termios->c_cflag, old_termios->c_iflag); old_termios->c_cflag, old_termios->c_iflag);
dbg("%s - port %d", __func__, port->number); dbg("%s - port %d", __func__, port->number);
if (edge_port == NULL) if (edge_port == NULL)
return; return;
/* change the port settings to the new ones specified */ /* change the port settings to the new ones specified */
change_port_settings (edge_port, old_termios); change_port_settings(edge_port, old_termios);
return;
} }
static int edge_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear) static int edge_tiocmset(struct usb_serial_port *port, struct file *file,
unsigned int set, unsigned int clear)
{ {
struct edgeport_port *edge_port = usb_get_serial_port_data(port); struct edgeport_port *edge_port = usb_get_serial_port_data(port);
unsigned int mcr; unsigned int mcr;
...@@ -2601,8 +2465,7 @@ static int edge_tiocmset (struct usb_serial_port *port, struct file *file, unsig ...@@ -2601,8 +2465,7 @@ static int edge_tiocmset (struct usb_serial_port *port, struct file *file, unsig
edge_port->shadow_mcr = mcr; edge_port->shadow_mcr = mcr;
spin_unlock_irqrestore(&edge_port->ep_lock, flags); spin_unlock_irqrestore(&edge_port->ep_lock, flags);
TIRestoreMCR (edge_port, mcr); restore_mcr(edge_port, mcr);
return 0; return 0;
} }
...@@ -2634,7 +2497,8 @@ static int edge_tiocmget(struct usb_serial_port *port, struct file *file) ...@@ -2634,7 +2497,8 @@ static int edge_tiocmget(struct usb_serial_port *port, struct file *file)
return result; return result;
} }
static int get_serial_info (struct edgeport_port *edge_port, struct serial_struct __user *retinfo) static int get_serial_info(struct edgeport_port *edge_port,
struct serial_struct __user *retinfo)
{ {
struct serial_struct tmp; struct serial_struct tmp;
...@@ -2652,17 +2516,14 @@ static int get_serial_info (struct edgeport_port *edge_port, struct serial_struc ...@@ -2652,17 +2516,14 @@ static int get_serial_info (struct edgeport_port *edge_port, struct serial_struc
tmp.baud_base = 9600; tmp.baud_base = 9600;
tmp.close_delay = 5*HZ; tmp.close_delay = 5*HZ;
tmp.closing_wait = closing_wait; tmp.closing_wait = closing_wait;
// tmp.custom_divisor = state->custom_divisor;
// tmp.hub6 = state->hub6;
// tmp.io_type = state->io_type;
if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
return -EFAULT; return -EFAULT;
return 0; return 0;
} }
static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg) static int edge_ioctl(struct usb_serial_port *port, struct file *file,
unsigned int cmd, unsigned long arg)
{ {
struct edgeport_port *edge_port = usb_get_serial_port_data(port); struct edgeport_port *edge_port = usb_get_serial_port_data(port);
struct async_icount cnow; struct async_icount cnow;
...@@ -2671,25 +2532,10 @@ static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned ...@@ -2671,25 +2532,10 @@ static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned
dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd); dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
switch (cmd) { switch (cmd) {
case TIOCINQ:
dbg("%s - (%d) TIOCINQ", __func__, port->number);
// return get_number_bytes_avail(edge_port, (unsigned int *) arg);
break;
case TIOCSERGETLSR:
dbg("%s - (%d) TIOCSERGETLSR", __func__, port->number);
// return get_lsr_info(edge_port, (unsigned int *) arg);
break;
case TIOCGSERIAL: case TIOCGSERIAL:
dbg("%s - (%d) TIOCGSERIAL", __func__, port->number); dbg("%s - (%d) TIOCGSERIAL", __func__, port->number);
return get_serial_info(edge_port, (struct serial_struct __user *) arg); return get_serial_info(edge_port,
break; (struct serial_struct __user *) arg);
case TIOCSSERIAL:
dbg("%s - (%d) TIOCSSERIAL", __func__, port->number);
break;
case TIOCMIWAIT: case TIOCMIWAIT:
dbg("%s - (%d) TIOCMIWAIT", __func__, port->number); dbg("%s - (%d) TIOCMIWAIT", __func__, port->number);
cprev = edge_port->icount; cprev = edge_port->icount;
...@@ -2705,47 +2551,44 @@ static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned ...@@ -2705,47 +2551,44 @@ static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned
if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) { ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
return 0; return 0;
} }
cprev = cnow; cprev = cnow;
} }
/* not reached */ /* not reached */
break; break;
case TIOCGICOUNT: case TIOCGICOUNT:
dbg ("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __func__, dbg("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
port->number, edge_port->icount.rx, edge_port->icount.tx); port->number, edge_port->icount.rx, edge_port->icount.tx);
if (copy_to_user((void __user *)arg, &edge_port->icount, sizeof(edge_port->icount))) if (copy_to_user((void __user *)arg, &edge_port->icount,
sizeof(edge_port->icount)))
return -EFAULT; return -EFAULT;
return 0; return 0;
} }
return -ENOIOCTLCMD; return -ENOIOCTLCMD;
} }
static void edge_break (struct usb_serial_port *port, int break_state) static void edge_break(struct usb_serial_port *port, int on)
{ {
struct edgeport_port *edge_port = usb_get_serial_port_data(port); struct edgeport_port *edge_port = usb_get_serial_port_data(port);
int status; int status;
int bv = 0; /* Off */
dbg ("%s - state = %d", __func__, break_state); dbg("%s - state = %d", __func__, on);
/* chase the port close */ /* chase the port close */
TIChasePort (edge_port, 0, 0); chase_port(edge_port, 0, 0);
if (break_state == -1) { if (on == -1)
status = TISetBreak (edge_port); bv = 1; /* On */
} else { status = ti_do_config(edge_port, UMPC_SET_CLR_BREAK, bv);
status = TIClearBreak (edge_port); if (status)
} dbg("%s - error %d sending break set/clear command.",
if (status) {
dbg ("%s - error %d sending break set/clear command.",
__func__, status); __func__, status);
}
} }
static int edge_startup (struct usb_serial *serial) static int edge_startup(struct usb_serial *serial)
{ {
struct edgeport_serial *edge_serial; struct edgeport_serial *edge_serial;
struct edgeport_port *edge_port; struct edgeport_port *edge_port;
...@@ -2765,9 +2608,9 @@ static int edge_startup (struct usb_serial *serial) ...@@ -2765,9 +2608,9 @@ static int edge_startup (struct usb_serial *serial)
edge_serial->serial = serial; edge_serial->serial = serial;
usb_set_serial_data(serial, edge_serial); usb_set_serial_data(serial, edge_serial);
status = TIDownloadFirmware (edge_serial); status = download_fw(edge_serial);
if (status) { if (status) {
kfree (edge_serial); kfree(edge_serial);
return status; return status;
} }
...@@ -2775,13 +2618,15 @@ static int edge_startup (struct usb_serial *serial) ...@@ -2775,13 +2618,15 @@ static int edge_startup (struct usb_serial *serial)
for (i = 0; i < serial->num_ports; ++i) { for (i = 0; i < serial->num_ports; ++i) {
edge_port = kzalloc(sizeof(struct edgeport_port), GFP_KERNEL); edge_port = kzalloc(sizeof(struct edgeport_port), GFP_KERNEL);
if (edge_port == NULL) { if (edge_port == NULL) {
dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__); dev_err(&serial->dev->dev, "%s - Out of memory\n",
__func__);
goto cleanup; goto cleanup;
} }
spin_lock_init(&edge_port->ep_lock); spin_lock_init(&edge_port->ep_lock);
edge_port->ep_out_buf = edge_buf_alloc(EDGE_OUT_BUF_SIZE); edge_port->ep_out_buf = edge_buf_alloc(EDGE_OUT_BUF_SIZE);
if (edge_port->ep_out_buf == NULL) { if (edge_port->ep_out_buf == NULL) {
dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__); dev_err(&serial->dev->dev, "%s - Out of memory\n",
__func__);
kfree(edge_port); kfree(edge_port);
goto cleanup; goto cleanup;
} }
...@@ -2794,23 +2639,23 @@ static int edge_startup (struct usb_serial *serial) ...@@ -2794,23 +2639,23 @@ static int edge_startup (struct usb_serial *serial)
return 0; return 0;
cleanup: cleanup:
for (--i; i>=0; --i) { for (--i; i >= 0; --i) {
edge_port = usb_get_serial_port_data(serial->port[i]); edge_port = usb_get_serial_port_data(serial->port[i]);
edge_buf_free(edge_port->ep_out_buf); edge_buf_free(edge_port->ep_out_buf);
kfree(edge_port); kfree(edge_port);
usb_set_serial_port_data(serial->port[i], NULL); usb_set_serial_port_data(serial->port[i], NULL);
} }
kfree (edge_serial); kfree(edge_serial);
usb_set_serial_data(serial, NULL); usb_set_serial_data(serial, NULL);
return -ENOMEM; return -ENOMEM;
} }
static void edge_shutdown (struct usb_serial *serial) static void edge_shutdown(struct usb_serial *serial)
{ {
int i; int i;
struct edgeport_port *edge_port; struct edgeport_port *edge_port;
dbg ("%s", __func__); dbg("%s", __func__);
for (i = 0; i < serial->num_ports; ++i) { for (i = 0; i < serial->num_ports; ++i) {
edge_port = usb_get_serial_port_data(serial->port[i]); edge_port = usb_get_serial_port_data(serial->port[i]);
...@@ -2852,7 +2697,8 @@ static ssize_t store_uart_mode(struct device *dev, ...@@ -2852,7 +2697,8 @@ static ssize_t store_uart_mode(struct device *dev,
return count; return count;
} }
static DEVICE_ATTR(uart_mode, S_IWUSR | S_IRUGO, show_uart_mode, store_uart_mode); static DEVICE_ATTR(uart_mode, S_IWUSR | S_IRUGO, show_uart_mode,
store_uart_mode);
static int edge_create_sysfs_attrs(struct usb_serial_port *port) static int edge_create_sysfs_attrs(struct usb_serial_port *port)
{ {
...@@ -2937,10 +2783,9 @@ static void edge_buf_clear(struct edge_buf *eb) ...@@ -2937,10 +2783,9 @@ static void edge_buf_clear(struct edge_buf *eb)
static unsigned int edge_buf_data_avail(struct edge_buf *eb) static unsigned int edge_buf_data_avail(struct edge_buf *eb)
{ {
if (eb != NULL) if (eb == NULL)
return ((eb->buf_size + eb->buf_put - eb->buf_get) % eb->buf_size);
else
return 0; return 0;
return ((eb->buf_size + eb->buf_put - eb->buf_get) % eb->buf_size);
} }
...@@ -2953,10 +2798,9 @@ static unsigned int edge_buf_data_avail(struct edge_buf *eb) ...@@ -2953,10 +2798,9 @@ static unsigned int edge_buf_data_avail(struct edge_buf *eb)
static unsigned int edge_buf_space_avail(struct edge_buf *eb) static unsigned int edge_buf_space_avail(struct edge_buf *eb)
{ {
if (eb != NULL) if (eb == NULL)
return ((eb->buf_size + eb->buf_get - eb->buf_put - 1) % eb->buf_size);
else
return 0; return 0;
return ((eb->buf_size + eb->buf_get - eb->buf_put - 1) % eb->buf_size);
} }
...@@ -3125,11 +2969,11 @@ static int __init edgeport_init(void) ...@@ -3125,11 +2969,11 @@ static int __init edgeport_init(void)
return retval; return retval;
} }
static void __exit edgeport_exit (void) static void __exit edgeport_exit(void)
{ {
usb_deregister (&io_driver); usb_deregister(&io_driver);
usb_serial_deregister (&edgeport_1port_device); usb_serial_deregister(&edgeport_1port_device);
usb_serial_deregister (&edgeport_2port_device); usb_serial_deregister(&edgeport_2port_device);
} }
module_init(edgeport_init); module_init(edgeport_init);
...@@ -3151,8 +2995,8 @@ module_param(closing_wait, int, S_IRUGO | S_IWUSR); ...@@ -3151,8 +2995,8 @@ module_param(closing_wait, int, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(closing_wait, "Maximum wait for data to drain, in .01 secs"); MODULE_PARM_DESC(closing_wait, "Maximum wait for data to drain, in .01 secs");
module_param(ignore_cpu_rev, bool, S_IRUGO | S_IWUSR); module_param(ignore_cpu_rev, bool, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(ignore_cpu_rev, "Ignore the cpu revision when connecting to a device"); MODULE_PARM_DESC(ignore_cpu_rev,
"Ignore the cpu revision when connecting to a device");
module_param(default_uart_mode, int, S_IRUGO | S_IWUSR); module_param(default_uart_mode, int, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(default_uart_mode, "Default uart_mode, 0=RS232, ..."); MODULE_PARM_DESC(default_uart_mode, "Default uart_mode, 0=RS232, ...");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment