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