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