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