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