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