blob: 69378a7ee342524ce6f796016ccc284974ca4825 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -070018 */
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/kernel.h>
21#include <linux/jiffies.h>
22#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/slab.h>
24#include <linux/tty.h>
25#include <linux/tty_driver.h>
26#include <linux/tty_flip.h>
27#include <linux/module.h>
28#include <linux/spinlock.h>
Matthias Kaehlcke241ca642007-12-04 16:15:40 +010029#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/serial.h>
Johan Hovold55090762014-04-25 15:23:03 +020031#include <linux/swab.h>
Johan Hovoldd733cec2010-05-19 00:01:37 +020032#include <linux/kfifo.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/ioctl.h>
Jaswinder Singhd12b2192008-07-04 23:06:09 +053034#include <linux/firmware.h>
Alan Cox2742fd82008-04-29 14:45:15 +010035#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/usb.h>
Greg Kroah-Hartmana9698882006-07-11 21:22:58 -070037#include <linux/usb/serial.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include "io_16654.h"
40#include "io_usbvend.h"
41#include "io_ti.h"
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com> and David Iacovelli"
44#define DRIVER_DESC "Edgeport USB Serial Driver"
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#define EPROM_PAGE_SIZE 64
47
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049/* different hardware types */
50#define HARDWARE_TYPE_930 0
51#define HARDWARE_TYPE_TIUMP 1
52
Alan Cox2742fd82008-04-29 14:45:15 +010053/* IOCTL_PRIVATE_TI_GET_MODE Definitions */
54#define TI_MODE_CONFIGURING 0 /* Device has not entered start device */
55#define TI_MODE_BOOT 1 /* Staying in boot mode */
56#define TI_MODE_DOWNLOAD 2 /* Made it to download mode */
57#define TI_MODE_TRANSITIONING 3 /* Currently in boot mode but
58 transitioning to download mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60/* read urb state */
61#define EDGE_READ_URB_RUNNING 0
62#define EDGE_READ_URB_STOPPING 1
63#define EDGE_READ_URB_STOPPED 2
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#define EDGE_CLOSING_WAIT 4000 /* in .01 sec */
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68/* Product information read from the Edgeport */
Alan Cox2742fd82008-04-29 14:45:15 +010069struct product_info {
70 int TiMode; /* Current TI Mode */
71 __u8 hardware_type; /* Type of hardware */
Linus Torvalds1da177e2005-04-16 15:20:36 -070072} __attribute__((packed));
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074struct edgeport_port {
75 __u16 uart_base;
76 __u16 dma_address;
77 __u8 shadow_msr;
78 __u8 shadow_mcr;
79 __u8 shadow_lsr;
80 __u8 lsr_mask;
Martin Olsson19af5cd2009-04-23 11:37:37 +020081 __u32 ump_read_timeout; /* Number of milliseconds the UMP will
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 wait without data before completing
83 a read short */
84 int baud_rate;
85 int close_pending;
86 int lsr_event;
Johan Hovold48ee5802013-03-21 12:37:10 +010087
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 struct edgeport_serial *edge_serial;
89 struct usb_serial_port *port;
Alan Cox2742fd82008-04-29 14:45:15 +010090 __u8 bUartMode; /* Port type, 0: RS232, etc. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 spinlock_t ep_lock;
92 int ep_read_urb_state;
93 int ep_write_urb_in_use;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094};
95
96struct edgeport_serial {
97 struct product_info product_info;
Alan Cox2742fd82008-04-29 14:45:15 +010098 u8 TI_I2C_Type; /* Type of I2C in UMP */
99 u8 TiReadI2C; /* Set to TRUE if we have read the
100 I2c in Boot Mode */
Matthias Kaehlcke241ca642007-12-04 16:15:40 +0100101 struct mutex es_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 int num_ports_open;
103 struct usb_serial *serial;
104};
105
106
107/* Devices that this driver supports */
Németh Márton7d40d7e2010-01-10 15:34:24 +0100108static const struct usb_device_id edgeport_1port_id_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) },
110 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1) },
111 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I) },
112 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROXIMITY) },
113 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOTION) },
114 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOISTURE) },
115 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_TEMPERATURE) },
116 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_HUMIDITY) },
117 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_POWER) },
118 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_LIGHT) },
119 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_RADIATION) },
120 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_DISTANCE) },
121 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_ACCELERATION) },
122 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROX_DIST) },
123 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_HP4CD) },
124 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_PCI) },
125 { }
126};
127
Németh Márton7d40d7e2010-01-10 15:34:24 +0100128static const struct usb_device_id edgeport_2port_id_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2) },
130 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2C) },
131 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2I) },
132 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421) },
133 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21) },
134 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_42) },
135 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4) },
136 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4I) },
137 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22I) },
138 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_221C) },
139 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22C) },
140 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21C) },
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -0400141 /* The 4, 8 and 16 port devices show up as multiple 2 port devices */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4S) },
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -0400143 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8) },
144 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8S) },
145 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416) },
146 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416B) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 { }
148};
149
150/* Devices that this driver supports */
Németh Márton7d40d7e2010-01-10 15:34:24 +0100151static const struct usb_device_id id_table_combined[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) },
153 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1) },
154 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I) },
155 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROXIMITY) },
156 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOTION) },
157 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOISTURE) },
158 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_TEMPERATURE) },
159 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_HUMIDITY) },
160 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_POWER) },
161 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_LIGHT) },
162 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_RADIATION) },
163 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_DISTANCE) },
164 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_ACCELERATION) },
165 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROX_DIST) },
166 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_HP4CD) },
167 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_PCI) },
168 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2) },
169 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2C) },
170 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2I) },
171 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421) },
172 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21) },
173 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_42) },
174 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4) },
175 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4I) },
176 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22I) },
177 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_221C) },
178 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22C) },
179 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21C) },
180 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4S) },
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -0400181 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8) },
182 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8S) },
183 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416) },
184 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416B) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 { }
186};
187
Alan Cox2742fd82008-04-29 14:45:15 +0100188MODULE_DEVICE_TABLE(usb, id_table_combined);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530190static unsigned char OperationalMajorVersion;
191static unsigned char OperationalMinorVersion;
192static unsigned short OperationalBuildNumber;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194static int closing_wait = EDGE_CLOSING_WAIT;
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030195static bool ignore_cpu_rev;
Alan Cox2742fd82008-04-29 14:45:15 +0100196static int default_uart_mode; /* RS232 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
Jiri Slaby2e124b42013-01-03 15:53:06 +0100198static void edge_tty_recv(struct usb_serial_port *port, unsigned char *data,
199 int length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201static void stop_read(struct edgeport_port *edge_port);
202static int restart_read(struct edgeport_port *edge_port);
203
Alan Cox95da3102008-07-22 11:09:07 +0100204static void edge_set_termios(struct tty_struct *tty,
205 struct usb_serial_port *port, struct ktermios *old_termios);
Jiri Slabyae3759c2013-04-04 22:41:01 +0200206static void edge_send(struct usb_serial_port *port, struct tty_struct *tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -0400208/* sysfs attributes */
209static int edge_create_sysfs_attrs(struct usb_serial_port *port);
210static int edge_remove_sysfs_attrs(struct usb_serial_port *port);
211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Peter E. Bergerc3ece7e2015-07-31 01:55:05 -0500213/* Timeouts in msecs: firmware downloads take longer */
214#define TI_VSEND_TIMEOUT_DEFAULT 1000
215#define TI_VSEND_TIMEOUT_FW_DOWNLOAD 10000
216
Alan Cox2742fd82008-04-29 14:45:15 +0100217static int ti_vread_sync(struct usb_device *dev, __u8 request,
218 __u16 value, __u16 index, u8 *data, int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219{
220 int status;
221
Alan Cox2742fd82008-04-29 14:45:15 +0100222 status = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), request,
223 (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN),
224 value, index, data, size, 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 if (status < 0)
226 return status;
227 if (status != size) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700228 dev_dbg(&dev->dev, "%s - wanted to write %d, but only wrote %d\n",
229 __func__, size, status);
Alan Cox2742fd82008-04-29 14:45:15 +0100230 return -ECOMM;
231 }
232 return 0;
233}
234
Peter E. Bergerc3ece7e2015-07-31 01:55:05 -0500235static int ti_vsend_sync(struct usb_device *dev, u8 request, u16 value,
236 u16 index, u8 *data, int size, int timeout)
Alan Cox2742fd82008-04-29 14:45:15 +0100237{
238 int status;
239
240 status = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), request,
241 (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT),
Peter E. Bergerc3ece7e2015-07-31 01:55:05 -0500242 value, index, data, size, timeout);
Alan Cox2742fd82008-04-29 14:45:15 +0100243 if (status < 0)
244 return status;
245 if (status != size) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700246 dev_dbg(&dev->dev, "%s - wanted to write %d, but only wrote %d\n",
247 __func__, size, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 return -ECOMM;
249 }
250 return 0;
251}
252
Alan Cox2742fd82008-04-29 14:45:15 +0100253static int send_cmd(struct usb_device *dev, __u8 command,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 __u8 moduleid, __u16 value, u8 *data,
255 int size)
256{
Peter E. Bergerc3ece7e2015-07-31 01:55:05 -0500257 return ti_vsend_sync(dev, command, value, moduleid, data, size,
258 TI_VSEND_TIMEOUT_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259}
260
261/* clear tx/rx buffers and fifo in TI UMP */
Alan Cox2742fd82008-04-29 14:45:15 +0100262static int purge_port(struct usb_serial_port *port, __u16 mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263{
Greg Kroah-Hartman11438322013-06-06 10:32:00 -0700264 int port_number = port->port_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700266 dev_dbg(&port->dev, "%s - port %d, mask %x\n", __func__, port_number, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Alan Cox2742fd82008-04-29 14:45:15 +0100268 return send_cmd(port->serial->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 UMPC_PURGE_PORT,
270 (__u8)(UMPM_UART1_PORT + port_number),
271 mask,
272 NULL,
273 0);
274}
275
276/**
Alan Cox2742fd82008-04-29 14:45:15 +0100277 * read_download_mem - Read edgeport memory from TI chip
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 * @dev: usb device pointer
279 * @start_address: Device CPU address at which to read
280 * @length: Length of above data
281 * @address_type: Can read both XDATA and I2C
282 * @buffer: pointer to input data buffer
283 */
Alan Cox2742fd82008-04-29 14:45:15 +0100284static int read_download_mem(struct usb_device *dev, int start_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 int length, __u8 address_type, __u8 *buffer)
286{
287 int status = 0;
288 __u8 read_length;
Johan Hovold55090762014-04-25 15:23:03 +0200289 u16 be_start_address;
Alan Cox2742fd82008-04-29 14:45:15 +0100290
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700291 dev_dbg(&dev->dev, "%s - @ %x for %d\n", __func__, start_address, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
293 /* Read in blocks of 64 bytes
294 * (TI firmware can't handle more than 64 byte reads)
295 */
296 while (length) {
297 if (length > 64)
Alan Cox2742fd82008-04-29 14:45:15 +0100298 read_length = 64;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 else
300 read_length = (__u8)length;
301
302 if (read_length > 1) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700303 dev_dbg(&dev->dev, "%s - @ %x for %d\n", __func__, start_address, read_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 }
Johan Hovold55090762014-04-25 15:23:03 +0200305 /*
306 * NOTE: Must use swab as wIndex is sent in little-endian
307 * byte order regardless of host byte order.
308 */
309 be_start_address = swab16((u16)start_address);
Alan Cox2742fd82008-04-29 14:45:15 +0100310 status = ti_vread_sync(dev, UMPC_MEMORY_READ,
311 (__u16)address_type,
Johan Hovold55090762014-04-25 15:23:03 +0200312 be_start_address,
Alan Cox2742fd82008-04-29 14:45:15 +0100313 buffer, read_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
315 if (status) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700316 dev_dbg(&dev->dev, "%s - ERROR %x\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 return status;
318 }
319
Alan Cox2742fd82008-04-29 14:45:15 +0100320 if (read_length > 1)
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +0100321 usb_serial_debug_data(&dev->dev, __func__, read_length, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323 /* Update pointers/length */
324 start_address += read_length;
325 buffer += read_length;
326 length -= read_length;
327 }
Alan Cox2742fd82008-04-29 14:45:15 +0100328
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 return status;
330}
331
Alan Cox2742fd82008-04-29 14:45:15 +0100332static int read_ram(struct usb_device *dev, int start_address,
333 int length, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
Alan Cox2742fd82008-04-29 14:45:15 +0100335 return read_download_mem(dev, start_address, length,
336 DTK_ADDR_SPACE_XDATA, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337}
338
339/* Read edgeport memory to a given block */
Alan Cox2742fd82008-04-29 14:45:15 +0100340static int read_boot_mem(struct edgeport_serial *serial,
341 int start_address, int length, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342{
343 int status = 0;
344 int i;
345
Alan Cox2742fd82008-04-29 14:45:15 +0100346 for (i = 0; i < length; i++) {
347 status = ti_vread_sync(serial->serial->dev,
348 UMPC_MEMORY_READ, serial->TI_I2C_Type,
349 (__u16)(start_address+i), &buffer[i], 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 if (status) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700351 dev_dbg(&serial->serial->dev->dev, "%s - ERROR %x\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 return status;
353 }
354 }
355
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700356 dev_dbg(&serial->serial->dev->dev, "%s - start_address = %x, length = %d\n",
357 __func__, start_address, length);
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +0100358 usb_serial_debug_data(&serial->serial->dev->dev, __func__, length, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360 serial->TiReadI2C = 1;
361
362 return status;
363}
364
365/* Write given block to TI EPROM memory */
Alan Cox2742fd82008-04-29 14:45:15 +0100366static int write_boot_mem(struct edgeport_serial *serial,
367 int start_address, int length, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
369 int status = 0;
370 int i;
Johan Hovolde9305d22009-12-28 23:01:50 +0100371 u8 *temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
373 /* Must do a read before write */
374 if (!serial->TiReadI2C) {
Johan Hovolde9305d22009-12-28 23:01:50 +0100375 temp = kmalloc(1, GFP_KERNEL);
Johan Hovold10c642d2013-12-29 19:22:56 +0100376 if (!temp)
Johan Hovolde9305d22009-12-28 23:01:50 +0100377 return -ENOMEM;
Johan Hovold10c642d2013-12-29 19:22:56 +0100378
Johan Hovolde9305d22009-12-28 23:01:50 +0100379 status = read_boot_mem(serial, 0, 1, temp);
380 kfree(temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 if (status)
382 return status;
383 }
384
Alan Cox2742fd82008-04-29 14:45:15 +0100385 for (i = 0; i < length; ++i) {
Peter E. Bergerc3ece7e2015-07-31 01:55:05 -0500386 status = ti_vsend_sync(serial->serial->dev, UMPC_MEMORY_WRITE,
387 buffer[i], (u16)(i + start_address), NULL,
388 0, TI_VSEND_TIMEOUT_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 if (status)
390 return status;
391 }
392
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700393 dev_dbg(&serial->serial->dev->dev, "%s - start_sddr = %x, length = %d\n", __func__, start_address, length);
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +0100394 usb_serial_debug_data(&serial->serial->dev->dev, __func__, length, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
396 return status;
397}
398
399
400/* Write edgeport I2C memory to TI chip */
Alan Cox2742fd82008-04-29 14:45:15 +0100401static int write_i2c_mem(struct edgeport_serial *serial,
402 int start_address, int length, __u8 address_type, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700404 struct device *dev = &serial->serial->dev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 int status = 0;
406 int write_length;
Johan Hovold55090762014-04-25 15:23:03 +0200407 u16 be_start_address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 /* We can only send a maximum of 1 aligned byte page at a time */
Alan Cox2742fd82008-04-29 14:45:15 +0100410
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300411 /* calculate the number of bytes left in the first page */
Alan Cox2742fd82008-04-29 14:45:15 +0100412 write_length = EPROM_PAGE_SIZE -
413 (start_address & (EPROM_PAGE_SIZE - 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
415 if (write_length > length)
416 write_length = length;
417
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700418 dev_dbg(dev, "%s - BytesInFirstPage Addr = %x, length = %d\n",
419 __func__, start_address, write_length);
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +0100420 usb_serial_debug_data(dev, __func__, write_length, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Johan Hovold55090762014-04-25 15:23:03 +0200422 /*
423 * Write first page.
424 *
425 * NOTE: Must use swab as wIndex is sent in little-endian byte order
426 * regardless of host byte order.
427 */
428 be_start_address = swab16((u16)start_address);
Peter E. Bergerc3ece7e2015-07-31 01:55:05 -0500429 status = ti_vsend_sync(serial->serial->dev, UMPC_MEMORY_WRITE,
430 (u16)address_type, be_start_address,
431 buffer, write_length, TI_VSEND_TIMEOUT_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 if (status) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700433 dev_dbg(dev, "%s - ERROR %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 return status;
435 }
436
437 length -= write_length;
438 start_address += write_length;
439 buffer += write_length;
440
Alan Cox2742fd82008-04-29 14:45:15 +0100441 /* We should be aligned now -- can write
442 max page size bytes at a time */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 while (length) {
444 if (length > EPROM_PAGE_SIZE)
445 write_length = EPROM_PAGE_SIZE;
446 else
447 write_length = length;
448
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700449 dev_dbg(dev, "%s - Page Write Addr = %x, length = %d\n",
450 __func__, start_address, write_length);
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +0100451 usb_serial_debug_data(dev, __func__, write_length, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
Johan Hovold55090762014-04-25 15:23:03 +0200453 /*
454 * Write next page.
455 *
456 * NOTE: Must use swab as wIndex is sent in little-endian byte
457 * order regardless of host byte order.
458 */
459 be_start_address = swab16((u16)start_address);
Alan Cox2742fd82008-04-29 14:45:15 +0100460 status = ti_vsend_sync(serial->serial->dev, UMPC_MEMORY_WRITE,
Peter E. Bergerc3ece7e2015-07-31 01:55:05 -0500461 (u16)address_type, be_start_address, buffer,
462 write_length, TI_VSEND_TIMEOUT_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 if (status) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700464 dev_err(dev, "%s - ERROR %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 return status;
466 }
Alan Cox2742fd82008-04-29 14:45:15 +0100467
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 length -= write_length;
469 start_address += write_length;
470 buffer += write_length;
471 }
472 return status;
473}
474
475/* Examine the UMP DMA registers and LSR
Alan Cox2742fd82008-04-29 14:45:15 +0100476 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 * Check the MSBit of the X and Y DMA byte count registers.
478 * A zero in this bit indicates that the TX DMA buffers are empty
479 * then check the TX Empty bit in the UART.
480 */
Alan Cox2742fd82008-04-29 14:45:15 +0100481static int tx_active(struct edgeport_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482{
483 int status;
484 struct out_endpoint_desc_block *oedb;
485 __u8 *lsr;
486 int bytes_left = 0;
487
Alan Cox2742fd82008-04-29 14:45:15 +0100488 oedb = kmalloc(sizeof(*oedb), GFP_KERNEL);
Johan Hovold10c642d2013-12-29 19:22:56 +0100489 if (!oedb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Alan Cox2742fd82008-04-29 14:45:15 +0100492 lsr = kmalloc(1, GFP_KERNEL); /* Sigh, that's right, just one byte,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 as not all platforms can do DMA
494 from stack */
495 if (!lsr) {
496 kfree(oedb);
497 return -ENOMEM;
498 }
499 /* Read the DMA Count Registers */
Alan Cox2742fd82008-04-29 14:45:15 +0100500 status = read_ram(port->port->serial->dev, port->dma_address,
501 sizeof(*oedb), (void *)oedb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 if (status)
503 goto exit_is_tx_active;
504
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700505 dev_dbg(&port->port->dev, "%s - XByteCount 0x%X\n", __func__, oedb->XByteCount);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
507 /* and the LSR */
Alan Cox2742fd82008-04-29 14:45:15 +0100508 status = read_ram(port->port->serial->dev,
509 port->uart_base + UMPMEM_OFFS_UART_LSR, 1, lsr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
511 if (status)
512 goto exit_is_tx_active;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700513 dev_dbg(&port->port->dev, "%s - LSR = 0x%X\n", __func__, *lsr);
Alan Cox2742fd82008-04-29 14:45:15 +0100514
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 /* If either buffer has data or we are transmitting then return TRUE */
Alan Cox2742fd82008-04-29 14:45:15 +0100516 if ((oedb->XByteCount & 0x80) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 bytes_left += 64;
518
Alan Cox2742fd82008-04-29 14:45:15 +0100519 if ((*lsr & UMP_UART_LSR_TX_MASK) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 bytes_left += 1;
521
522 /* We return Not Active if we get any kind of error */
523exit_is_tx_active:
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700524 dev_dbg(&port->port->dev, "%s - return %d\n", __func__, bytes_left);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
526 kfree(lsr);
527 kfree(oedb);
528 return bytes_left;
529}
530
Alan Cox2742fd82008-04-29 14:45:15 +0100531static int choose_config(struct usb_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532{
Alan Cox2742fd82008-04-29 14:45:15 +0100533 /*
534 * There may be multiple configurations on this device, in which case
535 * we would need to read and parse all of them to find out which one
536 * we want. However, we just support one config at this point,
537 * configuration # 1, which is Config Descriptor 0.
538 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700540 dev_dbg(&dev->dev, "%s - Number of Interfaces = %d\n",
541 __func__, dev->config->desc.bNumInterfaces);
542 dev_dbg(&dev->dev, "%s - MAX Power = %d\n",
543 __func__, dev->config->desc.bMaxPower * 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
545 if (dev->config->desc.bNumInterfaces != 1) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700546 dev_err(&dev->dev, "%s - bNumInterfaces is not 1, ERROR!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 return -ENODEV;
548 }
549
550 return 0;
551}
552
Alan Cox2742fd82008-04-29 14:45:15 +0100553static int read_rom(struct edgeport_serial *serial,
554 int start_address, int length, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555{
556 int status;
557
558 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) {
Alan Cox2742fd82008-04-29 14:45:15 +0100559 status = read_download_mem(serial->serial->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 start_address,
561 length,
562 serial->TI_I2C_Type,
563 buffer);
564 } else {
Alan Cox2742fd82008-04-29 14:45:15 +0100565 status = read_boot_mem(serial, start_address, length,
566 buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 return status;
569}
570
Alan Cox2742fd82008-04-29 14:45:15 +0100571static int write_rom(struct edgeport_serial *serial, int start_address,
572 int length, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573{
574 if (serial->product_info.TiMode == TI_MODE_BOOT)
Alan Cox2742fd82008-04-29 14:45:15 +0100575 return write_boot_mem(serial, start_address, length,
576 buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
578 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD)
Alan Cox2742fd82008-04-29 14:45:15 +0100579 return write_i2c_mem(serial, start_address, length,
580 serial->TI_I2C_Type, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 return -EINVAL;
582}
583
584
585
586/* Read a descriptor header from I2C based on type */
Alan Cox2742fd82008-04-29 14:45:15 +0100587static int get_descriptor_addr(struct edgeport_serial *serial,
588 int desc_type, struct ti_i2c_desc *rom_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589{
590 int start_address;
591 int status;
592
593 /* Search for requested descriptor in I2C */
594 start_address = 2;
595 do {
Alan Cox2742fd82008-04-29 14:45:15 +0100596 status = read_rom(serial,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 start_address,
598 sizeof(struct ti_i2c_desc),
Alan Cox2742fd82008-04-29 14:45:15 +0100599 (__u8 *)rom_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 if (status)
601 return 0;
602
603 if (rom_desc->Type == desc_type)
604 return start_address;
605
Johan Hovold55090762014-04-25 15:23:03 +0200606 start_address = start_address + sizeof(struct ti_i2c_desc) +
607 le16_to_cpu(rom_desc->Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
609 } while ((start_address < TI_MAX_I2C_SIZE) && rom_desc->Type);
Alan Cox2742fd82008-04-29 14:45:15 +0100610
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 return 0;
612}
613
614/* Validate descriptor checksum */
Alan Cox2742fd82008-04-29 14:45:15 +0100615static int valid_csum(struct ti_i2c_desc *rom_desc, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616{
617 __u16 i;
618 __u8 cs = 0;
619
Johan Hovold55090762014-04-25 15:23:03 +0200620 for (i = 0; i < le16_to_cpu(rom_desc->Size); i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 cs = (__u8)(cs + buffer[i]);
Alan Cox2742fd82008-04-29 14:45:15 +0100622
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 if (cs != rom_desc->CheckSum) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700624 pr_debug("%s - Mismatch %x - %x", __func__, rom_desc->CheckSum, cs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 return -EINVAL;
626 }
627 return 0;
628}
629
630/* Make sure that the I2C image is good */
Alan Cox2742fd82008-04-29 14:45:15 +0100631static int check_i2c_image(struct edgeport_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632{
633 struct device *dev = &serial->serial->dev->dev;
634 int status = 0;
635 struct ti_i2c_desc *rom_desc;
636 int start_address = 2;
637 __u8 *buffer;
638 __u16 ttype;
639
Alan Cox2742fd82008-04-29 14:45:15 +0100640 rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
Johan Hovold10c642d2013-12-29 19:22:56 +0100641 if (!rom_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 return -ENOMEM;
Johan Hovold10c642d2013-12-29 19:22:56 +0100643
Alan Cox2742fd82008-04-29 14:45:15 +0100644 buffer = kmalloc(TI_MAX_I2C_SIZE, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 if (!buffer) {
Alan Cox2742fd82008-04-29 14:45:15 +0100646 kfree(rom_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 return -ENOMEM;
648 }
649
Alan Cox2742fd82008-04-29 14:45:15 +0100650 /* Read the first byte (Signature0) must be 0x52 or 0x10 */
651 status = read_rom(serial, 0, 1, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 if (status)
Alan Cox2742fd82008-04-29 14:45:15 +0100653 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
655 if (*buffer != UMP5152 && *buffer != UMP3410) {
Alan Cox2742fd82008-04-29 14:45:15 +0100656 dev_err(dev, "%s - invalid buffer signature\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 status = -ENODEV;
Alan Cox2742fd82008-04-29 14:45:15 +0100658 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 }
660
661 do {
Alan Cox2742fd82008-04-29 14:45:15 +0100662 /* Validate the I2C */
663 status = read_rom(serial,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 start_address,
665 sizeof(struct ti_i2c_desc),
666 (__u8 *)rom_desc);
667 if (status)
668 break;
669
Alan Cox2742fd82008-04-29 14:45:15 +0100670 if ((start_address + sizeof(struct ti_i2c_desc) +
Johan Hovold55090762014-04-25 15:23:03 +0200671 le16_to_cpu(rom_desc->Size)) > TI_MAX_I2C_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 status = -ENODEV;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700673 dev_dbg(dev, "%s - structure too big, erroring out.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 break;
675 }
676
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700677 dev_dbg(dev, "%s Type = 0x%x\n", __func__, rom_desc->Type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
Alan Cox2742fd82008-04-29 14:45:15 +0100679 /* Skip type 2 record */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 ttype = rom_desc->Type & 0x0f;
Alan Cox2742fd82008-04-29 14:45:15 +0100681 if (ttype != I2C_DESC_TYPE_FIRMWARE_BASIC
682 && ttype != I2C_DESC_TYPE_FIRMWARE_AUTO) {
683 /* Read the descriptor data */
684 status = read_rom(serial, start_address +
685 sizeof(struct ti_i2c_desc),
Johan Hovold55090762014-04-25 15:23:03 +0200686 le16_to_cpu(rom_desc->Size),
687 buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 if (status)
689 break;
690
Alan Cox2742fd82008-04-29 14:45:15 +0100691 status = valid_csum(rom_desc, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 if (status)
693 break;
694 }
Alan Cox2742fd82008-04-29 14:45:15 +0100695 start_address = start_address + sizeof(struct ti_i2c_desc) +
Johan Hovold55090762014-04-25 15:23:03 +0200696 le16_to_cpu(rom_desc->Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
Alan Cox2742fd82008-04-29 14:45:15 +0100698 } while ((rom_desc->Type != I2C_DESC_TYPE_ION) &&
699 (start_address < TI_MAX_I2C_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
Alan Cox2742fd82008-04-29 14:45:15 +0100701 if ((rom_desc->Type != I2C_DESC_TYPE_ION) ||
702 (start_address > TI_MAX_I2C_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 status = -ENODEV;
704
Alan Cox2742fd82008-04-29 14:45:15 +0100705out:
706 kfree(buffer);
707 kfree(rom_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 return status;
709}
710
Alan Cox2742fd82008-04-29 14:45:15 +0100711static int get_manuf_info(struct edgeport_serial *serial, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712{
713 int status;
714 int start_address;
715 struct ti_i2c_desc *rom_desc;
716 struct edge_ti_manuf_descriptor *desc;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700717 struct device *dev = &serial->serial->dev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Alan Cox2742fd82008-04-29 14:45:15 +0100719 rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
Johan Hovold10c642d2013-12-29 19:22:56 +0100720 if (!rom_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 return -ENOMEM;
Johan Hovold10c642d2013-12-29 19:22:56 +0100722
Alan Cox2742fd82008-04-29 14:45:15 +0100723 start_address = get_descriptor_addr(serial, I2C_DESC_TYPE_ION,
724 rom_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
726 if (!start_address) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700727 dev_dbg(dev, "%s - Edge Descriptor not found in I2C\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 status = -ENODEV;
729 goto exit;
730 }
731
Alan Cox2742fd82008-04-29 14:45:15 +0100732 /* Read the descriptor data */
733 status = read_rom(serial, start_address+sizeof(struct ti_i2c_desc),
Johan Hovold55090762014-04-25 15:23:03 +0200734 le16_to_cpu(rom_desc->Size), buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 if (status)
736 goto exit;
Alan Cox2742fd82008-04-29 14:45:15 +0100737
738 status = valid_csum(rom_desc, buffer);
739
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 desc = (struct edge_ti_manuf_descriptor *)buffer;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700741 dev_dbg(dev, "%s - IonConfig 0x%x\n", __func__, desc->IonConfig);
742 dev_dbg(dev, "%s - Version %d\n", __func__, desc->Version);
743 dev_dbg(dev, "%s - Cpu/Board 0x%x\n", __func__, desc->CpuRev_BoardRev);
744 dev_dbg(dev, "%s - NumPorts %d\n", __func__, desc->NumPorts);
745 dev_dbg(dev, "%s - NumVirtualPorts %d\n", __func__, desc->NumVirtualPorts);
746 dev_dbg(dev, "%s - TotalPorts %d\n", __func__, desc->TotalPorts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
748exit:
Alan Cox2742fd82008-04-29 14:45:15 +0100749 kfree(rom_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 return status;
751}
752
753/* Build firmware header used for firmware update */
Alan Cox2742fd82008-04-29 14:45:15 +0100754static int build_i2c_fw_hdr(__u8 *header, struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755{
756 __u8 *buffer;
757 int buffer_size;
758 int i;
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530759 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 __u8 cs = 0;
761 struct ti_i2c_desc *i2c_header;
762 struct ti_i2c_image_header *img_header;
763 struct ti_i2c_firmware_rec *firmware_rec;
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530764 const struct firmware *fw;
765 const char *fw_name = "edgeport/down3.bin";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766
Alan Cox2742fd82008-04-29 14:45:15 +0100767 /* In order to update the I2C firmware we must change the type 2 record
768 * to type 0xF2. This will force the UMP to come up in Boot Mode.
769 * Then while in boot mode, the driver will download the latest
770 * firmware (padded to 15.5k) into the UMP ram. And finally when the
771 * device comes back up in download mode the driver will cause the new
772 * firmware to be copied from the UMP Ram to I2C and the firmware will
773 * update the record type from 0xf2 to 0x02.
774 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
Alan Cox2742fd82008-04-29 14:45:15 +0100776 /* Allocate a 15.5k buffer + 2 bytes for version number
777 * (Firmware Record) */
778 buffer_size = (((1024 * 16) - 512 ) +
779 sizeof(struct ti_i2c_firmware_rec));
780
781 buffer = kmalloc(buffer_size, GFP_KERNEL);
Johan Hovold10c642d2013-12-29 19:22:56 +0100782 if (!buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 return -ENOMEM;
Alan Cox2742fd82008-04-29 14:45:15 +0100784
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 // Set entire image of 0xffs
Alan Cox2742fd82008-04-29 14:45:15 +0100786 memset(buffer, 0xff, buffer_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530788 err = request_firmware(&fw, fw_name, dev);
789 if (err) {
Greg Kroah-Hartmand9bb03d2012-09-18 16:59:23 +0100790 dev_err(dev, "Failed to load image \"%s\" err %d\n",
791 fw_name, err);
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530792 kfree(buffer);
793 return err;
794 }
795
796 /* Save Download Version Number */
797 OperationalMajorVersion = fw->data[0];
798 OperationalMinorVersion = fw->data[1];
799 OperationalBuildNumber = fw->data[2] | (fw->data[3] << 8);
800
Alan Cox2742fd82008-04-29 14:45:15 +0100801 /* Copy version number into firmware record */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 firmware_rec = (struct ti_i2c_firmware_rec *)buffer;
803
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530804 firmware_rec->Ver_Major = OperationalMajorVersion;
805 firmware_rec->Ver_Minor = OperationalMinorVersion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
Alan Cox2742fd82008-04-29 14:45:15 +0100807 /* Pointer to fw_down memory image */
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530808 img_header = (struct ti_i2c_image_header *)&fw->data[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
Alan Cox2742fd82008-04-29 14:45:15 +0100810 memcpy(buffer + sizeof(struct ti_i2c_firmware_rec),
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530811 &fw->data[4 + sizeof(struct ti_i2c_image_header)],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 le16_to_cpu(img_header->Length));
813
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530814 release_firmware(fw);
815
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 for (i=0; i < buffer_size; i++) {
817 cs = (__u8)(cs + buffer[i]);
818 }
819
Alan Cox2742fd82008-04-29 14:45:15 +0100820 kfree(buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
Alan Cox2742fd82008-04-29 14:45:15 +0100822 /* Build new header */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 i2c_header = (struct ti_i2c_desc *)header;
824 firmware_rec = (struct ti_i2c_firmware_rec*)i2c_header->Data;
Alan Cox2742fd82008-04-29 14:45:15 +0100825
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 i2c_header->Type = I2C_DESC_TYPE_FIRMWARE_BLANK;
Johan Hovoldc03890f2014-04-26 11:53:44 +0200827 i2c_header->Size = cpu_to_le16(buffer_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 i2c_header->CheckSum = cs;
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530829 firmware_rec->Ver_Major = OperationalMajorVersion;
830 firmware_rec->Ver_Minor = OperationalMinorVersion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
832 return 0;
833}
834
835/* Try to figure out what type of I2c we have */
Alan Cox2742fd82008-04-29 14:45:15 +0100836static int i2c_type_bootmode(struct edgeport_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837{
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700838 struct device *dev = &serial->serial->dev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 int status;
Johan Hovolde9305d22009-12-28 23:01:50 +0100840 u8 *data;
841
842 data = kmalloc(1, GFP_KERNEL);
Johan Hovold10c642d2013-12-29 19:22:56 +0100843 if (!data)
Johan Hovolde9305d22009-12-28 23:01:50 +0100844 return -ENOMEM;
Alan Cox2742fd82008-04-29 14:45:15 +0100845
846 /* Try to read type 2 */
847 status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ,
Johan Hovolde9305d22009-12-28 23:01:50 +0100848 DTK_ADDR_SPACE_I2C_TYPE_II, 0, data, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 if (status)
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700850 dev_dbg(dev, "%s - read 2 status error = %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 else
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700852 dev_dbg(dev, "%s - read 2 data = 0x%x\n", __func__, *data);
Johan Hovolde9305d22009-12-28 23:01:50 +0100853 if ((!status) && (*data == UMP5152 || *data == UMP3410)) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700854 dev_dbg(dev, "%s - ROM_TYPE_II\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
Johan Hovolde9305d22009-12-28 23:01:50 +0100856 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 }
858
Alan Cox2742fd82008-04-29 14:45:15 +0100859 /* Try to read type 3 */
860 status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ,
Johan Hovolde9305d22009-12-28 23:01:50 +0100861 DTK_ADDR_SPACE_I2C_TYPE_III, 0, data, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 if (status)
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700863 dev_dbg(dev, "%s - read 3 status error = %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 else
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700865 dev_dbg(dev, "%s - read 2 data = 0x%x\n", __func__, *data);
Johan Hovolde9305d22009-12-28 23:01:50 +0100866 if ((!status) && (*data == UMP5152 || *data == UMP3410)) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700867 dev_dbg(dev, "%s - ROM_TYPE_III\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_III;
Johan Hovolde9305d22009-12-28 23:01:50 +0100869 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 }
871
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700872 dev_dbg(dev, "%s - Unknown\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
Johan Hovolde9305d22009-12-28 23:01:50 +0100874 status = -ENODEV;
875out:
876 kfree(data);
877 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878}
879
Alan Cox2742fd82008-04-29 14:45:15 +0100880static int bulk_xfer(struct usb_serial *serial, void *buffer,
881 int length, int *num_sent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882{
883 int status;
884
Alan Cox2742fd82008-04-29 14:45:15 +0100885 status = usb_bulk_msg(serial->dev,
886 usb_sndbulkpipe(serial->dev,
887 serial->port[0]->bulk_out_endpointAddress),
888 buffer, length, num_sent, 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 return status;
890}
891
892/* Download given firmware image to the device (IN BOOT MODE) */
Alan Cox2742fd82008-04-29 14:45:15 +0100893static int download_code(struct edgeport_serial *serial, __u8 *image,
894 int image_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895{
896 int status = 0;
897 int pos;
898 int transfer;
899 int done;
900
Alan Cox2742fd82008-04-29 14:45:15 +0100901 /* Transfer firmware image */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 for (pos = 0; pos < image_length; ) {
Alan Cox2742fd82008-04-29 14:45:15 +0100903 /* Read the next buffer from file */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 transfer = image_length - pos;
905 if (transfer > EDGE_FW_BULK_MAX_PACKET_SIZE)
906 transfer = EDGE_FW_BULK_MAX_PACKET_SIZE;
907
Alan Cox2742fd82008-04-29 14:45:15 +0100908 /* Transfer data */
909 status = bulk_xfer(serial->serial, &image[pos],
910 transfer, &done);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 if (status)
912 break;
Alan Cox2742fd82008-04-29 14:45:15 +0100913 /* Advance buffer pointer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 pos += done;
915 }
916
917 return status;
918}
919
Alan Cox2742fd82008-04-29 14:45:15 +0100920/* FIXME!!! */
921static int config_boot_dev(struct usb_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922{
923 return 0;
924}
925
Alan Cox2742fd82008-04-29 14:45:15 +0100926static int ti_cpu_rev(struct edge_ti_manuf_descriptor *desc)
927{
928 return TI_GET_CPU_REVISION(desc->CpuRev_BoardRev);
929}
930
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931/**
932 * DownloadTIFirmware - Download run-time operating firmware to the TI5052
Alan Cox2742fd82008-04-29 14:45:15 +0100933 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 * This routine downloads the main operating code into the TI5052, using the
935 * boot code already burned into E2PROM or ROM.
936 */
Alan Cox2742fd82008-04-29 14:45:15 +0100937static int download_fw(struct edgeport_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938{
939 struct device *dev = &serial->serial->dev->dev;
940 int status = 0;
941 int start_address;
942 struct edge_ti_manuf_descriptor *ti_manuf_desc;
943 struct usb_interface_descriptor *interface;
944 int download_cur_ver;
945 int download_new_ver;
946
947 /* This routine is entered by both the BOOT mode and the Download mode
948 * We can determine which code is running by the reading the config
949 * descriptor and if we have only one bulk pipe it is in boot mode
950 */
951 serial->product_info.hardware_type = HARDWARE_TYPE_TIUMP;
952
953 /* Default to type 2 i2c */
954 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
955
Alan Cox2742fd82008-04-29 14:45:15 +0100956 status = choose_config(serial->serial->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 if (status)
958 return status;
959
960 interface = &serial->serial->interface->cur_altsetting->desc;
961 if (!interface) {
Alan Cox2742fd82008-04-29 14:45:15 +0100962 dev_err(dev, "%s - no interface set, error!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 return -ENODEV;
964 }
965
Alan Cox2742fd82008-04-29 14:45:15 +0100966 /*
967 * Setup initial mode -- the default mode 0 is TI_MODE_CONFIGURING
968 * if we have more than one endpoint we are definitely in download
969 * mode
970 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 if (interface->bNumEndpoints > 1)
972 serial->product_info.TiMode = TI_MODE_DOWNLOAD;
973 else
Alan Cox2742fd82008-04-29 14:45:15 +0100974 /* Otherwise we will remain in configuring mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 serial->product_info.TiMode = TI_MODE_CONFIGURING;
976
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 /********************************************************************/
978 /* Download Mode */
979 /********************************************************************/
980 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) {
981 struct ti_i2c_desc *rom_desc;
982
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700983 dev_dbg(dev, "%s - RUNNING IN DOWNLOAD MODE\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
Alan Cox2742fd82008-04-29 14:45:15 +0100985 status = check_i2c_image(serial);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 if (status) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700987 dev_dbg(dev, "%s - DOWNLOAD MODE -- BAD I2C\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 return status;
989 }
Alan Cox2742fd82008-04-29 14:45:15 +0100990
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 /* Validate Hardware version number
992 * Read Manufacturing Descriptor from TI Based Edgeport
993 */
Alan Cox2742fd82008-04-29 14:45:15 +0100994 ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL);
Johan Hovold10c642d2013-12-29 19:22:56 +0100995 if (!ti_manuf_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 return -ENOMEM;
Johan Hovold10c642d2013-12-29 19:22:56 +0100997
Alan Cox2742fd82008-04-29 14:45:15 +0100998 status = get_manuf_info(serial, (__u8 *)ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001000 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 return status;
1002 }
1003
Alan Cox2742fd82008-04-29 14:45:15 +01001004 /* Check version number of ION descriptor */
1005 if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001006 dev_dbg(dev, "%s - Wrong CPU Rev %d (Must be 2)\n",
Alan Cox2742fd82008-04-29 14:45:15 +01001007 __func__, ti_cpu_rev(ti_manuf_desc));
1008 kfree(ti_manuf_desc);
1009 return -EINVAL;
1010 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
Alan Cox2742fd82008-04-29 14:45:15 +01001012 rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 if (!rom_desc) {
Alan Cox2742fd82008-04-29 14:45:15 +01001014 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 return -ENOMEM;
1016 }
1017
Alan Cox2742fd82008-04-29 14:45:15 +01001018 /* Search for type 2 record (firmware record) */
1019 start_address = get_descriptor_addr(serial,
1020 I2C_DESC_TYPE_FIRMWARE_BASIC, rom_desc);
1021 if (start_address != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 struct ti_i2c_firmware_rec *firmware_version;
Johan Hovolde9305d22009-12-28 23:01:50 +01001023 u8 *record;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001025 dev_dbg(dev, "%s - Found Type FIRMWARE (Type 2) record\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026
Alan Cox2742fd82008-04-29 14:45:15 +01001027 firmware_version = kmalloc(sizeof(*firmware_version),
1028 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 if (!firmware_version) {
Alan Cox2742fd82008-04-29 14:45:15 +01001030 kfree(rom_desc);
1031 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 return -ENOMEM;
1033 }
1034
Alan Cox2742fd82008-04-29 14:45:15 +01001035 /* Validate version number
1036 * Read the descriptor data
1037 */
1038 status = read_rom(serial, start_address +
1039 sizeof(struct ti_i2c_desc),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 sizeof(struct ti_i2c_firmware_rec),
1041 (__u8 *)firmware_version);
1042 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001043 kfree(firmware_version);
1044 kfree(rom_desc);
1045 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 return status;
1047 }
1048
Alan Cox2742fd82008-04-29 14:45:15 +01001049 /* Check version number of download with current
1050 version in I2c */
1051 download_cur_ver = (firmware_version->Ver_Major << 8) +
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 (firmware_version->Ver_Minor);
Jaswinder Singhd12b2192008-07-04 23:06:09 +05301053 download_new_ver = (OperationalMajorVersion << 8) +
1054 (OperationalMinorVersion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001056 dev_dbg(dev, "%s - >> FW Versions Device %d.%d Driver %d.%d\n",
1057 __func__, firmware_version->Ver_Major,
1058 firmware_version->Ver_Minor,
1059 OperationalMajorVersion,
1060 OperationalMinorVersion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
Alan Cox2742fd82008-04-29 14:45:15 +01001062 /* Check if we have an old version in the I2C and
1063 update if necessary */
Greg Kroah-Hartman0827a9f2010-08-17 15:15:37 -07001064 if (download_cur_ver < download_new_ver) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001065 dev_dbg(dev, "%s - Update I2C dld from %d.%d to %d.%d\n",
1066 __func__,
1067 firmware_version->Ver_Major,
1068 firmware_version->Ver_Minor,
1069 OperationalMajorVersion,
1070 OperationalMinorVersion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
Johan Hovolde9305d22009-12-28 23:01:50 +01001072 record = kmalloc(1, GFP_KERNEL);
1073 if (!record) {
Johan Hovolde9305d22009-12-28 23:01:50 +01001074 kfree(firmware_version);
1075 kfree(rom_desc);
1076 kfree(ti_manuf_desc);
1077 return -ENOMEM;
1078 }
Alan Cox2742fd82008-04-29 14:45:15 +01001079 /* In order to update the I2C firmware we must
1080 * change the type 2 record to type 0xF2. This
1081 * will force the UMP to come up in Boot Mode.
1082 * Then while in boot mode, the driver will
1083 * download the latest firmware (padded to
1084 * 15.5k) into the UMP ram. Finally when the
1085 * device comes back up in download mode the
1086 * driver will cause the new firmware to be
1087 * copied from the UMP Ram to I2C and the
1088 * firmware will update the record type from
1089 * 0xf2 to 0x02.
1090 */
Johan Hovolde9305d22009-12-28 23:01:50 +01001091 *record = I2C_DESC_TYPE_FIRMWARE_BLANK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
Alan Cox2742fd82008-04-29 14:45:15 +01001093 /* Change the I2C Firmware record type to
1094 0xf2 to trigger an update */
1095 status = write_rom(serial, start_address,
Johan Hovolde9305d22009-12-28 23:01:50 +01001096 sizeof(*record), record);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 if (status) {
Johan Hovolde9305d22009-12-28 23:01:50 +01001098 kfree(record);
Alan Cox2742fd82008-04-29 14:45:15 +01001099 kfree(firmware_version);
1100 kfree(rom_desc);
1101 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 return status;
1103 }
1104
Alan Cox2742fd82008-04-29 14:45:15 +01001105 /* verify the write -- must do this in order
1106 * for write to complete before we do the
1107 * hardware reset
1108 */
1109 status = read_rom(serial,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 start_address,
Johan Hovolde9305d22009-12-28 23:01:50 +01001111 sizeof(*record),
1112 record);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 if (status) {
Johan Hovolde9305d22009-12-28 23:01:50 +01001114 kfree(record);
Alan Cox2742fd82008-04-29 14:45:15 +01001115 kfree(firmware_version);
1116 kfree(rom_desc);
1117 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 return status;
1119 }
1120
Johan Hovolde9305d22009-12-28 23:01:50 +01001121 if (*record != I2C_DESC_TYPE_FIRMWARE_BLANK) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001122 dev_err(dev, "%s - error resetting device\n", __func__);
Johan Hovolde9305d22009-12-28 23:01:50 +01001123 kfree(record);
Alan Cox2742fd82008-04-29 14:45:15 +01001124 kfree(firmware_version);
1125 kfree(rom_desc);
1126 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 return -ENODEV;
1128 }
1129
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001130 dev_dbg(dev, "%s - HARDWARE RESET\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131
Alan Cox2742fd82008-04-29 14:45:15 +01001132 /* Reset UMP -- Back to BOOT MODE */
1133 status = ti_vsend_sync(serial->serial->dev,
1134 UMPC_HARDWARE_RESET,
Peter E. Bergerc3ece7e2015-07-31 01:55:05 -05001135 0, 0, NULL, 0,
1136 TI_VSEND_TIMEOUT_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001138 dev_dbg(dev, "%s - HARDWARE RESET return %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
1140 /* return an error on purpose. */
Johan Hovolde9305d22009-12-28 23:01:50 +01001141 kfree(record);
Alan Cox2742fd82008-04-29 14:45:15 +01001142 kfree(firmware_version);
1143 kfree(rom_desc);
1144 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 return -ENODEV;
1146 }
Alan Cox2742fd82008-04-29 14:45:15 +01001147 kfree(firmware_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 }
Alan Cox2742fd82008-04-29 14:45:15 +01001149 /* Search for type 0xF2 record (firmware blank record) */
1150 else if ((start_address = get_descriptor_addr(serial, I2C_DESC_TYPE_FIRMWARE_BLANK, rom_desc)) != 0) {
1151#define HEADER_SIZE (sizeof(struct ti_i2c_desc) + \
1152 sizeof(struct ti_i2c_firmware_rec))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 __u8 *header;
1154 __u8 *vheader;
1155
Alan Cox2742fd82008-04-29 14:45:15 +01001156 header = kmalloc(HEADER_SIZE, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 if (!header) {
Alan Cox2742fd82008-04-29 14:45:15 +01001158 kfree(rom_desc);
1159 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 return -ENOMEM;
1161 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
Alan Cox2742fd82008-04-29 14:45:15 +01001163 vheader = kmalloc(HEADER_SIZE, GFP_KERNEL);
1164 if (!vheader) {
Alan Cox2742fd82008-04-29 14:45:15 +01001165 kfree(header);
1166 kfree(rom_desc);
1167 kfree(ti_manuf_desc);
1168 return -ENOMEM;
1169 }
1170
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001171 dev_dbg(dev, "%s - Found Type BLANK FIRMWARE (Type F2) record\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01001172
1173 /*
1174 * In order to update the I2C firmware we must change
1175 * the type 2 record to type 0xF2. This will force the
1176 * UMP to come up in Boot Mode. Then while in boot
1177 * mode, the driver will download the latest firmware
1178 * (padded to 15.5k) into the UMP ram. Finally when the
1179 * device comes back up in download mode the driver
1180 * will cause the new firmware to be copied from the
1181 * UMP Ram to I2C and the firmware will update the
1182 * record type from 0xf2 to 0x02.
1183 */
1184 status = build_i2c_fw_hdr(header, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001186 kfree(vheader);
1187 kfree(header);
1188 kfree(rom_desc);
1189 kfree(ti_manuf_desc);
Roel Kluinfd6e5bb2010-08-10 14:29:19 -07001190 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 }
1192
Alan Cox2742fd82008-04-29 14:45:15 +01001193 /* Update I2C with type 0xf2 record with correct
1194 size and checksum */
1195 status = write_rom(serial,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 start_address,
1197 HEADER_SIZE,
1198 header);
1199 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001200 kfree(vheader);
1201 kfree(header);
1202 kfree(rom_desc);
1203 kfree(ti_manuf_desc);
Roel Kluin9800eb32010-07-20 15:29:08 -07001204 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 }
1206
Alan Cox2742fd82008-04-29 14:45:15 +01001207 /* verify the write -- must do this in order for
1208 write to complete before we do the hardware reset */
1209 status = read_rom(serial, start_address,
1210 HEADER_SIZE, vheader);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
1212 if (status) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001213 dev_dbg(dev, "%s - can't read header back\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01001214 kfree(vheader);
1215 kfree(header);
1216 kfree(rom_desc);
1217 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 return status;
1219 }
1220 if (memcmp(vheader, header, HEADER_SIZE)) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001221 dev_dbg(dev, "%s - write download record failed\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01001222 kfree(vheader);
1223 kfree(header);
1224 kfree(rom_desc);
1225 kfree(ti_manuf_desc);
Roel Kluin1e297092010-07-02 00:36:43 +02001226 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 }
1228
Alan Cox2742fd82008-04-29 14:45:15 +01001229 kfree(vheader);
1230 kfree(header);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001232 dev_dbg(dev, "%s - Start firmware update\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
Alan Cox2742fd82008-04-29 14:45:15 +01001234 /* Tell firmware to copy download image into I2C */
1235 status = ti_vsend_sync(serial->serial->dev,
Peter E. Bergerc3ece7e2015-07-31 01:55:05 -05001236 UMPC_COPY_DNLD_TO_I2C,
1237 0, 0, NULL, 0,
1238 TI_VSEND_TIMEOUT_FW_DOWNLOAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001240 dev_dbg(dev, "%s - Update complete 0x%x\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001242 dev_err(dev,
1243 "%s - UMPC_COPY_DNLD_TO_I2C failed\n",
1244 __func__);
1245 kfree(rom_desc);
1246 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 return status;
1248 }
1249 }
1250
1251 // The device is running the download code
Alan Cox2742fd82008-04-29 14:45:15 +01001252 kfree(rom_desc);
1253 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 return 0;
1255 }
1256
1257 /********************************************************************/
1258 /* Boot Mode */
1259 /********************************************************************/
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001260 dev_dbg(dev, "%s - RUNNING IN BOOT MODE\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
Alan Cox2742fd82008-04-29 14:45:15 +01001262 /* Configure the TI device so we can use the BULK pipes for download */
1263 status = config_boot_dev(serial->serial->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 if (status)
1265 return status;
1266
Alan Cox2742fd82008-04-29 14:45:15 +01001267 if (le16_to_cpu(serial->serial->dev->descriptor.idVendor)
1268 != USB_VENDOR_ID_ION) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001269 dev_dbg(dev, "%s - VID = 0x%x\n", __func__,
1270 le16_to_cpu(serial->serial->dev->descriptor.idVendor));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
Alan Cox2742fd82008-04-29 14:45:15 +01001272 goto stayinbootmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 }
1274
Alan Cox2742fd82008-04-29 14:45:15 +01001275 /* We have an ION device (I2c Must be programmed)
1276 Determine I2C image type */
1277 if (i2c_type_bootmode(serial))
1278 goto stayinbootmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
Alan Cox2742fd82008-04-29 14:45:15 +01001280 /* Check for ION Vendor ID and that the I2C is valid */
1281 if (!check_i2c_image(serial)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 struct ti_i2c_image_header *header;
1283 int i;
1284 __u8 cs = 0;
1285 __u8 *buffer;
1286 int buffer_size;
Jaswinder Singhd12b2192008-07-04 23:06:09 +05301287 int err;
1288 const struct firmware *fw;
1289 const char *fw_name = "edgeport/down3.bin";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
1291 /* Validate Hardware version number
1292 * Read Manufacturing Descriptor from TI Based Edgeport
1293 */
Alan Cox2742fd82008-04-29 14:45:15 +01001294 ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL);
Johan Hovold10c642d2013-12-29 19:22:56 +01001295 if (!ti_manuf_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 return -ENOMEM;
Johan Hovold10c642d2013-12-29 19:22:56 +01001297
Alan Cox2742fd82008-04-29 14:45:15 +01001298 status = get_manuf_info(serial, (__u8 *)ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001300 kfree(ti_manuf_desc);
1301 goto stayinbootmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 }
1303
Alan Cox2742fd82008-04-29 14:45:15 +01001304 /* Check for version 2 */
1305 if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001306 dev_dbg(dev, "%s - Wrong CPU Rev %d (Must be 2)\n",
1307 __func__, ti_cpu_rev(ti_manuf_desc));
Alan Cox2742fd82008-04-29 14:45:15 +01001308 kfree(ti_manuf_desc);
1309 goto stayinbootmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 }
1311
Alan Cox2742fd82008-04-29 14:45:15 +01001312 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 /*
Alan Cox2742fd82008-04-29 14:45:15 +01001315 * In order to update the I2C firmware we must change the type
1316 * 2 record to type 0xF2. This will force the UMP to come up
1317 * in Boot Mode. Then while in boot mode, the driver will
1318 * download the latest firmware (padded to 15.5k) into the
1319 * UMP ram. Finally when the device comes back up in download
1320 * mode the driver will cause the new firmware to be copied
1321 * from the UMP Ram to I2C and the firmware will update the
1322 * record type from 0xf2 to 0x02.
1323 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 * Do we really have to copy the whole firmware image,
1325 * or could we do this in place!
1326 */
1327
Alan Cox2742fd82008-04-29 14:45:15 +01001328 /* Allocate a 15.5k buffer + 3 byte header */
1329 buffer_size = (((1024 * 16) - 512) +
1330 sizeof(struct ti_i2c_image_header));
1331 buffer = kmalloc(buffer_size, GFP_KERNEL);
Johan Hovold10c642d2013-12-29 19:22:56 +01001332 if (!buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 return -ENOMEM;
Alan Cox2742fd82008-04-29 14:45:15 +01001334
1335 /* Initialize the buffer to 0xff (pad the buffer) */
1336 memset(buffer, 0xff, buffer_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337
Jaswinder Singhd12b2192008-07-04 23:06:09 +05301338 err = request_firmware(&fw, fw_name, dev);
1339 if (err) {
Greg Kroah-Hartmand9bb03d2012-09-18 16:59:23 +01001340 dev_err(dev, "Failed to load image \"%s\" err %d\n",
1341 fw_name, err);
Jaswinder Singhd12b2192008-07-04 23:06:09 +05301342 kfree(buffer);
1343 return err;
1344 }
1345 memcpy(buffer, &fw->data[4], fw->size - 4);
1346 release_firmware(fw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347
Alan Cox2742fd82008-04-29 14:45:15 +01001348 for (i = sizeof(struct ti_i2c_image_header);
1349 i < buffer_size; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 cs = (__u8)(cs + buffer[i]);
1351 }
Alan Cox2742fd82008-04-29 14:45:15 +01001352
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 header = (struct ti_i2c_image_header *)buffer;
Alan Cox2742fd82008-04-29 14:45:15 +01001354
1355 /* update length and checksum after padding */
1356 header->Length = cpu_to_le16((__u16)(buffer_size -
1357 sizeof(struct ti_i2c_image_header)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 header->CheckSum = cs;
1359
Alan Cox2742fd82008-04-29 14:45:15 +01001360 /* Download the operational code */
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001361 dev_dbg(dev, "%s - Downloading operational code image (TI UMP)\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01001362 status = download_code(serial, buffer, buffer_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363
Alan Cox2742fd82008-04-29 14:45:15 +01001364 kfree(buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
1366 if (status) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001367 dev_dbg(dev, "%s - Error downloading operational code image\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 return status;
1369 }
1370
Alan Cox2742fd82008-04-29 14:45:15 +01001371 /* Device will reboot */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 serial->product_info.TiMode = TI_MODE_TRANSITIONING;
1373
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001374 dev_dbg(dev, "%s - Download successful -- Device rebooting...\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
1376 /* return an error on purpose */
1377 return -ENODEV;
1378 }
1379
Alan Cox2742fd82008-04-29 14:45:15 +01001380stayinbootmode:
1381 /* Eprom is invalid or blank stay in boot mode */
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001382 dev_dbg(dev, "%s - STAYING IN BOOT MODE\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 serial->product_info.TiMode = TI_MODE_BOOT;
1384
1385 return 0;
1386}
1387
1388
Alan Cox2742fd82008-04-29 14:45:15 +01001389static int ti_do_config(struct edgeport_port *port, int feature, int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390{
Greg Kroah-Hartman11438322013-06-06 10:32:00 -07001391 int port_number = port->port->port_number;
1392
Alan Cox2742fd82008-04-29 14:45:15 +01001393 on = !!on; /* 1 or 0 not bitmask */
1394 return send_cmd(port->port->serial->dev,
1395 feature, (__u8)(UMPM_UART1_PORT + port_number),
1396 on, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397}
1398
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
Alan Cox2742fd82008-04-29 14:45:15 +01001400static int restore_mcr(struct edgeport_port *port, __u8 mcr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401{
1402 int status = 0;
1403
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001404 dev_dbg(&port->port->dev, "%s - %x\n", __func__, mcr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
Alan Cox2742fd82008-04-29 14:45:15 +01001406 status = ti_do_config(port, UMPC_SET_CLR_DTR, mcr & MCR_DTR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 if (status)
1408 return status;
Alan Cox2742fd82008-04-29 14:45:15 +01001409 status = ti_do_config(port, UMPC_SET_CLR_RTS, mcr & MCR_RTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 if (status)
1411 return status;
Alan Cox2742fd82008-04-29 14:45:15 +01001412 return ti_do_config(port, UMPC_SET_CLR_LOOPBACK, mcr & MCR_LOOPBACK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413}
1414
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415/* Convert TI LSR to standard UART flags */
Alan Cox2742fd82008-04-29 14:45:15 +01001416static __u8 map_line_status(__u8 ti_lsr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417{
1418 __u8 lsr = 0;
1419
1420#define MAP_FLAG(flagUmp, flagUart) \
1421 if (ti_lsr & flagUmp) \
1422 lsr |= flagUart;
1423
1424 MAP_FLAG(UMP_UART_LSR_OV_MASK, LSR_OVER_ERR) /* overrun */
1425 MAP_FLAG(UMP_UART_LSR_PE_MASK, LSR_PAR_ERR) /* parity error */
1426 MAP_FLAG(UMP_UART_LSR_FE_MASK, LSR_FRM_ERR) /* framing error */
1427 MAP_FLAG(UMP_UART_LSR_BR_MASK, LSR_BREAK) /* break detected */
Alan Cox2742fd82008-04-29 14:45:15 +01001428 MAP_FLAG(UMP_UART_LSR_RX_MASK, LSR_RX_AVAIL) /* rx data available */
1429 MAP_FLAG(UMP_UART_LSR_TX_MASK, LSR_TX_EMPTY) /* tx hold reg empty */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
1431#undef MAP_FLAG
1432
1433 return lsr;
1434}
1435
Alan Cox2742fd82008-04-29 14:45:15 +01001436static void handle_new_msr(struct edgeport_port *edge_port, __u8 msr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437{
1438 struct async_icount *icount;
1439 struct tty_struct *tty;
1440
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001441 dev_dbg(&edge_port->port->dev, "%s - %02x\n", __func__, msr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442
Alan Cox2742fd82008-04-29 14:45:15 +01001443 if (msr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR |
1444 EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) {
Johan Hovoldcf9a9d62013-03-21 12:37:09 +01001445 icount = &edge_port->port->icount;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
1447 /* update input line counters */
1448 if (msr & EDGEPORT_MSR_DELTA_CTS)
1449 icount->cts++;
1450 if (msr & EDGEPORT_MSR_DELTA_DSR)
1451 icount->dsr++;
1452 if (msr & EDGEPORT_MSR_DELTA_CD)
1453 icount->dcd++;
1454 if (msr & EDGEPORT_MSR_DELTA_RI)
1455 icount->rng++;
Johan Hovold48ee5802013-03-21 12:37:10 +01001456 wake_up_interruptible(&edge_port->port->port.delta_msr_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 }
1458
1459 /* Save the new modem status */
1460 edge_port->shadow_msr = msr & 0xf0;
1461
Alan Cox4a90f092008-10-13 10:39:46 +01001462 tty = tty_port_tty_get(&edge_port->port->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 /* handle CTS flow control */
1464 if (tty && C_CRTSCTS(tty)) {
Peter Hurleyd95e3ca2014-09-10 15:06:27 -04001465 if (msr & EDGEPORT_MSR_CTS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 tty_wakeup(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 }
Alan Cox4a90f092008-10-13 10:39:46 +01001468 tty_kref_put(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469}
1470
Alan Cox2742fd82008-04-29 14:45:15 +01001471static void handle_new_lsr(struct edgeport_port *edge_port, int lsr_data,
1472 __u8 lsr, __u8 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473{
1474 struct async_icount *icount;
Alan Cox2742fd82008-04-29 14:45:15 +01001475 __u8 new_lsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR |
1476 LSR_FRM_ERR | LSR_BREAK));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001478 dev_dbg(&edge_port->port->dev, "%s - %02x\n", __func__, new_lsr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
1480 edge_port->shadow_lsr = lsr;
1481
Alan Cox2742fd82008-04-29 14:45:15 +01001482 if (new_lsr & LSR_BREAK)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 /*
1484 * Parity and Framing errors only count if they
1485 * occur exclusive of a break being received.
1486 */
1487 new_lsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
1489 /* Place LSR data byte into Rx buffer */
Jiri Slaby2e124b42013-01-03 15:53:06 +01001490 if (lsr_data)
1491 edge_tty_recv(edge_port->port, &data, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
1493 /* update input line counters */
Johan Hovoldcf9a9d62013-03-21 12:37:09 +01001494 icount = &edge_port->port->icount;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 if (new_lsr & LSR_BREAK)
1496 icount->brk++;
1497 if (new_lsr & LSR_OVER_ERR)
1498 icount->overrun++;
1499 if (new_lsr & LSR_PAR_ERR)
1500 icount->parity++;
1501 if (new_lsr & LSR_FRM_ERR)
1502 icount->frame++;
1503}
1504
1505
Alan Cox2742fd82008-04-29 14:45:15 +01001506static void edge_interrupt_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507{
Ming Leicdc97792008-02-24 18:41:47 +08001508 struct edgeport_serial *edge_serial = urb->context;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 struct usb_serial_port *port;
1510 struct edgeport_port *edge_port;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001511 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 unsigned char *data = urb->transfer_buffer;
1513 int length = urb->actual_length;
1514 int port_number;
1515 int function;
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001516 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 __u8 lsr;
1518 __u8 msr;
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001519 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001521 switch (status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 case 0:
1523 /* success */
1524 break;
1525 case -ECONNRESET:
1526 case -ENOENT:
1527 case -ESHUTDOWN:
1528 /* this urb is terminated, clean up */
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001529 dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -08001530 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 return;
1532 default:
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001533 dev_err(&urb->dev->dev, "%s - nonzero urb status received: "
Harvey Harrison441b62c2008-03-03 16:08:34 -08001534 "%d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 goto exit;
1536 }
1537
1538 if (!length) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001539 dev_dbg(&urb->dev->dev, "%s - no data in urb\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 goto exit;
1541 }
1542
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001543 dev = &edge_serial->serial->dev->dev;
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +01001544 usb_serial_debug_data(dev, __func__, length, data);
Alan Cox2742fd82008-04-29 14:45:15 +01001545
1546 if (length != 2) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001547 dev_dbg(dev, "%s - expecting packet of size 2, got %d\n", __func__, length);
Alan Cox2742fd82008-04-29 14:45:15 +01001548 goto exit;
1549 }
1550
1551 port_number = TIUMP_GET_PORT_FROM_CODE(data[0]);
1552 function = TIUMP_GET_FUNC_FROM_CODE(data[0]);
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001553 dev_dbg(dev, "%s - port_number %d, function %d, info 0x%x\n", __func__,
1554 port_number, function, data[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 port = edge_serial->serial->port[port_number];
1556 edge_port = usb_get_serial_port_data(port);
1557 if (!edge_port) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001558 dev_dbg(dev, "%s - edge_port not found\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 return;
1560 }
1561 switch (function) {
1562 case TIUMP_INTERRUPT_CODE_LSR:
Alan Cox2742fd82008-04-29 14:45:15 +01001563 lsr = map_line_status(data[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 if (lsr & UMP_UART_LSR_DATA_MASK) {
Alan Cox2742fd82008-04-29 14:45:15 +01001565 /* Save the LSR event for bulk read
1566 completion routine */
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001567 dev_dbg(dev, "%s - LSR Event Port %u LSR Status = %02x\n",
1568 __func__, port_number, lsr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 edge_port->lsr_event = 1;
1570 edge_port->lsr_mask = lsr;
1571 } else {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001572 dev_dbg(dev, "%s - ===== Port %d LSR Status = %02x ======\n",
1573 __func__, port_number, lsr);
Alan Cox2742fd82008-04-29 14:45:15 +01001574 handle_new_lsr(edge_port, 0, lsr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 }
1576 break;
1577
Alan Cox2742fd82008-04-29 14:45:15 +01001578 case TIUMP_INTERRUPT_CODE_MSR: /* MSR */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 /* Copy MSR from UMP */
1580 msr = data[1];
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001581 dev_dbg(dev, "%s - ===== Port %u MSR Status = %02x ======\n",
1582 __func__, port_number, msr);
Alan Cox2742fd82008-04-29 14:45:15 +01001583 handle_new_msr(edge_port, msr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 break;
1585
1586 default:
Alan Cox2742fd82008-04-29 14:45:15 +01001587 dev_err(&urb->dev->dev,
1588 "%s - Unknown Interrupt code from UMP %x\n",
1589 __func__, data[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 break;
Alan Cox2742fd82008-04-29 14:45:15 +01001591
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 }
1593
1594exit:
Alan Cox2742fd82008-04-29 14:45:15 +01001595 retval = usb_submit_urb(urb, GFP_ATOMIC);
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001596 if (retval)
Alan Cox2742fd82008-04-29 14:45:15 +01001597 dev_err(&urb->dev->dev,
1598 "%s - usb_submit_urb failed with result %d\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -08001599 __func__, retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600}
1601
Alan Cox2742fd82008-04-29 14:45:15 +01001602static void edge_bulk_in_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603{
Ming Leicdc97792008-02-24 18:41:47 +08001604 struct edgeport_port *edge_port = urb->context;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001605 struct device *dev = &edge_port->port->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 unsigned char *data = urb->transfer_buffer;
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001607 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 int port_number;
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001609 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001611 switch (status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 case 0:
1613 /* success */
1614 break;
1615 case -ECONNRESET:
1616 case -ENOENT:
1617 case -ESHUTDOWN:
1618 /* this urb is terminated, clean up */
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001619 dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 return;
1621 default:
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001622 dev_err(&urb->dev->dev, "%s - nonzero read bulk status received: %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 }
1624
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001625 if (status == -EPIPE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 goto exit;
1627
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001628 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001629 dev_err(&urb->dev->dev, "%s - stopping read!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 return;
1631 }
1632
Greg Kroah-Hartman11438322013-06-06 10:32:00 -07001633 port_number = edge_port->port->port_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634
1635 if (edge_port->lsr_event) {
1636 edge_port->lsr_event = 0;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001637 dev_dbg(dev, "%s ===== Port %u LSR Status = %02x, Data = %02x ======\n",
1638 __func__, port_number, edge_port->lsr_mask, *data);
Alan Cox2742fd82008-04-29 14:45:15 +01001639 handle_new_lsr(edge_port, 1, edge_port->lsr_mask, *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 /* Adjust buffer length/pointer */
1641 --urb->actual_length;
1642 ++data;
1643 }
1644
Jiri Slaby2e124b42013-01-03 15:53:06 +01001645 if (urb->actual_length) {
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +01001646 usb_serial_debug_data(dev, __func__, urb->actual_length, data);
Alan Cox2742fd82008-04-29 14:45:15 +01001647 if (edge_port->close_pending)
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001648 dev_dbg(dev, "%s - close pending, dropping data on the floor\n",
Alan Cox2742fd82008-04-29 14:45:15 +01001649 __func__);
1650 else
Jiri Slaby2e124b42013-01-03 15:53:06 +01001651 edge_tty_recv(edge_port->port, data,
Jiri Slaby05c7cd32013-01-03 15:53:04 +01001652 urb->actual_length);
Johan Hovoldcf9a9d62013-03-21 12:37:09 +01001653 edge_port->port->icount.rx += urb->actual_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 }
1655
1656exit:
1657 /* continue read unless stopped */
1658 spin_lock(&edge_port->ep_lock);
Johan Hovold58330412011-11-06 19:06:28 +01001659 if (edge_port->ep_read_urb_state == EDGE_READ_URB_RUNNING)
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001660 retval = usb_submit_urb(urb, GFP_ATOMIC);
Johan Hovold58330412011-11-06 19:06:28 +01001661 else if (edge_port->ep_read_urb_state == EDGE_READ_URB_STOPPING)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 edge_port->ep_read_urb_state = EDGE_READ_URB_STOPPED;
Johan Hovold58330412011-11-06 19:06:28 +01001663
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 spin_unlock(&edge_port->ep_lock);
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001665 if (retval)
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001666 dev_err(dev, "%s - usb_submit_urb failed with result %d\n", __func__, retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667}
1668
Jiri Slaby2e124b42013-01-03 15:53:06 +01001669static void edge_tty_recv(struct usb_serial_port *port, unsigned char *data,
1670 int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671{
Alan Cox2742fd82008-04-29 14:45:15 +01001672 int queued;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
Jiri Slaby05c7cd32013-01-03 15:53:04 +01001674 queued = tty_insert_flip_string(&port->port, data, length);
Alan Cox2742fd82008-04-29 14:45:15 +01001675 if (queued < length)
Jiri Slaby05c7cd32013-01-03 15:53:04 +01001676 dev_err(&port->dev, "%s - dropping data, %d bytes lost\n",
Alan Cox2742fd82008-04-29 14:45:15 +01001677 __func__, length - queued);
Jiri Slaby2e124b42013-01-03 15:53:06 +01001678 tty_flip_buffer_push(&port->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679}
1680
Alan Cox2742fd82008-04-29 14:45:15 +01001681static void edge_bulk_out_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682{
Ming Leicdc97792008-02-24 18:41:47 +08001683 struct usb_serial_port *port = urb->context;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001685 int status = urb->status;
Alan Cox4a90f092008-10-13 10:39:46 +01001686 struct tty_struct *tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 edge_port->ep_write_urb_in_use = 0;
1689
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001690 switch (status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 case 0:
1692 /* success */
1693 break;
1694 case -ECONNRESET:
1695 case -ENOENT:
1696 case -ESHUTDOWN:
1697 /* this urb is terminated, clean up */
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001698 dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -08001699 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 return;
1701 default:
Johan Hovold22a416c2012-02-10 13:20:51 +01001702 dev_err_console(port, "%s - nonzero write bulk status "
Harvey Harrison441b62c2008-03-03 16:08:34 -08001703 "received: %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 }
1705
1706 /* send any buffered data */
Alan Cox4a90f092008-10-13 10:39:46 +01001707 tty = tty_port_tty_get(&port->port);
Jiri Slabyae3759c2013-04-04 22:41:01 +02001708 edge_send(port, tty);
Alan Cox4a90f092008-10-13 10:39:46 +01001709 tty_kref_put(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710}
1711
Alan Coxa509a7e2009-09-19 13:13:26 -07001712static int edge_open(struct tty_struct *tty, struct usb_serial_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713{
1714 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1715 struct edgeport_serial *edge_serial;
1716 struct usb_device *dev;
1717 struct urb *urb;
1718 int port_number;
1719 int status;
1720 u16 open_settings;
1721 u8 transaction_timeout;
1722
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 if (edge_port == NULL)
1724 return -ENODEV;
1725
Greg Kroah-Hartman11438322013-06-06 10:32:00 -07001726 port_number = port->port_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727
1728 dev = port->serial->dev;
1729
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 /* turn off loopback */
Alan Cox2742fd82008-04-29 14:45:15 +01001731 status = ti_do_config(edge_port, UMPC_SET_CLR_LOOPBACK, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001733 dev_err(&port->dev,
1734 "%s - cannot send clear loopback command, %d\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -08001735 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 return status;
1737 }
Alan Cox2742fd82008-04-29 14:45:15 +01001738
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 /* set up the port settings */
Alan Cox95da3102008-07-22 11:09:07 +01001740 if (tty)
Alan Coxadc8d742012-07-14 15:31:47 +01001741 edge_set_termios(tty, port, &tty->termios);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742
1743 /* open up the port */
1744
1745 /* milliseconds to timeout for DMA transfer */
1746 transaction_timeout = 2;
1747
Alan Cox2742fd82008-04-29 14:45:15 +01001748 edge_port->ump_read_timeout =
1749 max(20, ((transaction_timeout * 3) / 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750
Alan Cox2742fd82008-04-29 14:45:15 +01001751 /* milliseconds to timeout for DMA transfer */
1752 open_settings = (u8)(UMP_DMA_MODE_CONTINOUS |
1753 UMP_PIPE_TRANS_TIMEOUT_ENA |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 (transaction_timeout << 2));
1755
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001756 dev_dbg(&port->dev, "%s - Sending UMPC_OPEN_PORT\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757
1758 /* Tell TI to open and start the port */
Alan Cox2742fd82008-04-29 14:45:15 +01001759 status = send_cmd(dev, UMPC_OPEN_PORT,
1760 (u8)(UMPM_UART1_PORT + port_number), open_settings, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001762 dev_err(&port->dev, "%s - cannot send open command, %d\n",
1763 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 return status;
1765 }
1766
1767 /* Start the DMA? */
Alan Cox2742fd82008-04-29 14:45:15 +01001768 status = send_cmd(dev, UMPC_START_PORT,
1769 (u8)(UMPM_UART1_PORT + port_number), 0, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001771 dev_err(&port->dev, "%s - cannot send start DMA command, %d\n",
1772 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 return status;
1774 }
1775
1776 /* Clear TX and RX buffers in UMP */
Alan Cox2742fd82008-04-29 14:45:15 +01001777 status = purge_port(port, UMP_PORT_DIR_OUT | UMP_PORT_DIR_IN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001779 dev_err(&port->dev,
1780 "%s - cannot send clear buffers command, %d\n",
1781 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 return status;
1783 }
1784
1785 /* Read Initial MSR */
Alan Cox2742fd82008-04-29 14:45:15 +01001786 status = ti_vread_sync(dev, UMPC_READ_MSR, 0,
1787 (__u16)(UMPM_UART1_PORT + port_number),
1788 &edge_port->shadow_msr, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001790 dev_err(&port->dev, "%s - cannot send read MSR command, %d\n",
1791 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 return status;
1793 }
1794
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001795 dev_dbg(&port->dev, "ShadowMSR 0x%X\n", edge_port->shadow_msr);
Alan Cox2742fd82008-04-29 14:45:15 +01001796
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 /* Set Initial MCR */
1798 edge_port->shadow_mcr = MCR_RTS | MCR_DTR;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001799 dev_dbg(&port->dev, "ShadowMCR 0x%X\n", edge_port->shadow_mcr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800
1801 edge_serial = edge_port->edge_serial;
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01001802 if (mutex_lock_interruptible(&edge_serial->es_lock))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 return -ERESTARTSYS;
1804 if (edge_serial->num_ports_open == 0) {
Alan Cox2742fd82008-04-29 14:45:15 +01001805 /* we are the first port to open, post the interrupt urb */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 urb = edge_serial->serial->port[0]->interrupt_in_urb;
1807 if (!urb) {
Alan Cox2742fd82008-04-29 14:45:15 +01001808 dev_err(&port->dev,
1809 "%s - no interrupt urb present, exiting\n",
1810 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 status = -EINVAL;
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01001812 goto release_es_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 urb->context = edge_serial;
Alan Cox2742fd82008-04-29 14:45:15 +01001815 status = usb_submit_urb(urb, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001817 dev_err(&port->dev,
1818 "%s - usb_submit_urb failed with value %d\n",
1819 __func__, status);
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01001820 goto release_es_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 }
1822 }
1823
1824 /*
1825 * reset the data toggle on the bulk endpoints to work around bug in
1826 * host controllers where things get out of sync some times
1827 */
Alan Cox2742fd82008-04-29 14:45:15 +01001828 usb_clear_halt(dev, port->write_urb->pipe);
1829 usb_clear_halt(dev, port->read_urb->pipe);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830
1831 /* start up our bulk read urb */
1832 urb = port->read_urb;
1833 if (!urb) {
Alan Cox2742fd82008-04-29 14:45:15 +01001834 dev_err(&port->dev, "%s - no read urb present, exiting\n",
1835 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 status = -EINVAL;
1837 goto unlink_int_urb;
1838 }
1839 edge_port->ep_read_urb_state = EDGE_READ_URB_RUNNING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 urb->context = edge_port;
Alan Cox2742fd82008-04-29 14:45:15 +01001841 status = usb_submit_urb(urb, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001843 dev_err(&port->dev,
1844 "%s - read bulk usb_submit_urb failed with value %d\n",
1845 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 goto unlink_int_urb;
1847 }
1848
1849 ++edge_serial->num_ports_open;
1850
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01001851 goto release_es_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852
1853unlink_int_urb:
1854 if (edge_port->edge_serial->num_ports_open == 0)
1855 usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01001856release_es_lock:
1857 mutex_unlock(&edge_serial->es_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 return status;
1859}
1860
Alan Cox335f8512009-06-11 12:26:29 +01001861static void edge_close(struct usb_serial_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862{
1863 struct edgeport_serial *edge_serial;
1864 struct edgeport_port *edge_port;
Johan Hovoldaf581052012-03-26 20:31:38 +02001865 struct usb_serial *serial = port->serial;
Johan Hovold77de2512013-01-14 16:52:54 +01001866 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 int port_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 edge_serial = usb_get_serial_data(port->serial);
1870 edge_port = usb_get_serial_port_data(port);
Alan Cox2742fd82008-04-29 14:45:15 +01001871 if (edge_serial == NULL || edge_port == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 return;
Alan Cox2742fd82008-04-29 14:45:15 +01001873
1874 /* The bulkreadcompletion routine will check
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 * this flag and dump add read data */
1876 edge_port->close_pending = 1;
1877
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 usb_kill_urb(port->read_urb);
1879 usb_kill_urb(port->write_urb);
1880 edge_port->ep_write_urb_in_use = 0;
Johan Hovold77de2512013-01-14 16:52:54 +01001881 spin_lock_irqsave(&edge_port->ep_lock, flags);
Johan Hovoldddca16e2013-06-26 16:47:37 +02001882 kfifo_reset_out(&port->write_fifo);
Johan Hovold77de2512013-01-14 16:52:54 +01001883 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001885 dev_dbg(&port->dev, "%s - send umpc_close_port\n", __func__);
Greg Kroah-Hartman11438322013-06-06 10:32:00 -07001886 port_number = port->port_number;
Johan Hovoldbca87e92013-03-21 12:37:38 +01001887 send_cmd(serial->dev, UMPC_CLOSE_PORT,
1888 (__u8)(UMPM_UART1_PORT + port_number), 0, NULL, 0);
Johan Hovoldaf581052012-03-26 20:31:38 +02001889
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01001890 mutex_lock(&edge_serial->es_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 --edge_port->edge_serial->num_ports_open;
1892 if (edge_port->edge_serial->num_ports_open <= 0) {
1893 /* last port is now closed, let's shut down our interrupt urb */
1894 usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
1895 edge_port->edge_serial->num_ports_open = 0;
1896 }
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01001897 mutex_unlock(&edge_serial->es_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 edge_port->close_pending = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899}
1900
Alan Cox95da3102008-07-22 11:09:07 +01001901static int edge_write(struct tty_struct *tty, struct usb_serial_port *port,
1902 const unsigned char *data, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903{
1904 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 if (count == 0) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001907 dev_dbg(&port->dev, "%s - write request of 0 bytes\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 return 0;
1909 }
1910
1911 if (edge_port == NULL)
1912 return -ENODEV;
1913 if (edge_port->close_pending == 1)
1914 return -ENODEV;
1915
Johan Hovoldddca16e2013-06-26 16:47:37 +02001916 count = kfifo_in_locked(&port->write_fifo, data, count,
Johan Hovoldd733cec2010-05-19 00:01:37 +02001917 &edge_port->ep_lock);
Jiri Slabyae3759c2013-04-04 22:41:01 +02001918 edge_send(port, tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919
1920 return count;
1921}
1922
Jiri Slabyae3759c2013-04-04 22:41:01 +02001923static void edge_send(struct usb_serial_port *port, struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924{
1925 int count, result;
1926 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 unsigned long flags;
1928
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 spin_lock_irqsave(&edge_port->ep_lock, flags);
1930
1931 if (edge_port->ep_write_urb_in_use) {
1932 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1933 return;
1934 }
1935
Johan Hovoldddca16e2013-06-26 16:47:37 +02001936 count = kfifo_out(&port->write_fifo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 port->write_urb->transfer_buffer,
1938 port->bulk_out_size);
1939
1940 if (count == 0) {
1941 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1942 return;
1943 }
1944
1945 edge_port->ep_write_urb_in_use = 1;
1946
1947 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1948
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +01001949 usb_serial_debug_data(&port->dev, __func__, count, port->write_urb->transfer_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950
1951 /* set up our urb */
Johan Hovoldfd119612011-11-06 19:06:30 +01001952 port->write_urb->transfer_buffer_length = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953
1954 /* send the data out the bulk port */
1955 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
1956 if (result) {
Johan Hovold22a416c2012-02-10 13:20:51 +01001957 dev_err_console(port,
Alan Cox2742fd82008-04-29 14:45:15 +01001958 "%s - failed submitting write urb, error %d\n",
1959 __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 edge_port->ep_write_urb_in_use = 0;
Alan Cox2742fd82008-04-29 14:45:15 +01001961 /* TODO: reschedule edge_send */
1962 } else
Johan Hovoldcf9a9d62013-03-21 12:37:09 +01001963 edge_port->port->icount.tx += count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964
1965 /* wakeup any process waiting for writes to complete */
1966 /* there is now more room in the buffer for new writes */
Alan Cox2742fd82008-04-29 14:45:15 +01001967 if (tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 tty_wakeup(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969}
1970
Alan Cox95da3102008-07-22 11:09:07 +01001971static int edge_write_room(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972{
Alan Cox95da3102008-07-22 11:09:07 +01001973 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1975 int room = 0;
1976 unsigned long flags;
1977
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 if (edge_port == NULL)
Alan Cox2742fd82008-04-29 14:45:15 +01001979 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 if (edge_port->close_pending == 1)
Alan Cox2742fd82008-04-29 14:45:15 +01001981 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982
1983 spin_lock_irqsave(&edge_port->ep_lock, flags);
Johan Hovoldddca16e2013-06-26 16:47:37 +02001984 room = kfifo_avail(&port->write_fifo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1986
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001987 dev_dbg(&port->dev, "%s - returns %d\n", __func__, room);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 return room;
1989}
1990
Alan Cox95da3102008-07-22 11:09:07 +01001991static int edge_chars_in_buffer(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992{
Alan Cox95da3102008-07-22 11:09:07 +01001993 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1995 int chars = 0;
1996 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 if (edge_port == NULL)
Alan Cox2742fd82008-04-29 14:45:15 +01001998 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999
2000 spin_lock_irqsave(&edge_port->ep_lock, flags);
Johan Hovoldddca16e2013-06-26 16:47:37 +02002001 chars = kfifo_len(&port->write_fifo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2003
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002004 dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 return chars;
2006}
2007
Johan Hovoldb16634a2013-05-05 20:32:31 +02002008static bool edge_tx_empty(struct usb_serial_port *port)
2009{
2010 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2011 int ret;
2012
2013 ret = tx_active(edge_port);
2014 if (ret > 0)
2015 return false;
2016
2017 return true;
2018}
2019
Alan Cox95da3102008-07-22 11:09:07 +01002020static void edge_throttle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021{
Alan Cox95da3102008-07-22 11:09:07 +01002022 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 int status;
2025
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 if (edge_port == NULL)
2027 return;
2028
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 /* if we are implementing XON/XOFF, send the stop character */
2030 if (I_IXOFF(tty)) {
2031 unsigned char stop_char = STOP_CHAR(tty);
Alan Cox95da3102008-07-22 11:09:07 +01002032 status = edge_write(tty, port, &stop_char, 1);
2033 if (status <= 0) {
2034 dev_err(&port->dev, "%s - failed to write stop character, %d\n", __func__, status);
2035 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 }
2037
2038 /* if we are implementing RTS/CTS, stop reads */
2039 /* and the Edgeport will clear the RTS line */
2040 if (C_CRTSCTS(tty))
2041 stop_read(edge_port);
2042
2043}
2044
Alan Cox95da3102008-07-22 11:09:07 +01002045static void edge_unthrottle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046{
Alan Cox95da3102008-07-22 11:09:07 +01002047 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 int status;
2050
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 if (edge_port == NULL)
2052 return;
2053
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 /* if we are implementing XON/XOFF, send the start character */
2055 if (I_IXOFF(tty)) {
2056 unsigned char start_char = START_CHAR(tty);
Alan Cox95da3102008-07-22 11:09:07 +01002057 status = edge_write(tty, port, &start_char, 1);
2058 if (status <= 0) {
2059 dev_err(&port->dev, "%s - failed to write start character, %d\n", __func__, status);
2060 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 /* if we are implementing RTS/CTS, restart reads */
2063 /* are the Edgeport will assert the RTS line */
2064 if (C_CRTSCTS(tty)) {
2065 status = restart_read(edge_port);
2066 if (status)
Alan Cox2742fd82008-04-29 14:45:15 +01002067 dev_err(&port->dev,
2068 "%s - read bulk usb_submit_urb failed: %d\n",
2069 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 }
2071
2072}
2073
2074static void stop_read(struct edgeport_port *edge_port)
2075{
2076 unsigned long flags;
2077
2078 spin_lock_irqsave(&edge_port->ep_lock, flags);
2079
2080 if (edge_port->ep_read_urb_state == EDGE_READ_URB_RUNNING)
2081 edge_port->ep_read_urb_state = EDGE_READ_URB_STOPPING;
2082 edge_port->shadow_mcr &= ~MCR_RTS;
2083
2084 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2085}
2086
2087static int restart_read(struct edgeport_port *edge_port)
2088{
2089 struct urb *urb;
2090 int status = 0;
2091 unsigned long flags;
2092
2093 spin_lock_irqsave(&edge_port->ep_lock, flags);
2094
2095 if (edge_port->ep_read_urb_state == EDGE_READ_URB_STOPPED) {
2096 urb = edge_port->port->read_urb;
Oliver Neukumefdff602007-06-05 10:50:48 +02002097 status = usb_submit_urb(urb, GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 }
2099 edge_port->ep_read_urb_state = EDGE_READ_URB_RUNNING;
2100 edge_port->shadow_mcr |= MCR_RTS;
2101
2102 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2103
2104 return status;
2105}
2106
Alan Cox95da3102008-07-22 11:09:07 +01002107static void change_port_settings(struct tty_struct *tty,
2108 struct edgeport_port *edge_port, struct ktermios *old_termios)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109{
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002110 struct device *dev = &edge_port->port->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 struct ump_uart_config *config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 int baud;
2113 unsigned cflag;
2114 int status;
Greg Kroah-Hartman11438322013-06-06 10:32:00 -07002115 int port_number = edge_port->port->port_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116
Alan Cox95da3102008-07-22 11:09:07 +01002117 config = kmalloc (sizeof (*config), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 if (!config) {
Alan Coxadc8d742012-07-14 15:31:47 +01002119 tty->termios = *old_termios;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 return;
2121 }
2122
Alan Coxadc8d742012-07-14 15:31:47 +01002123 cflag = tty->termios.c_cflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
2125 config->wFlags = 0;
2126
2127 /* These flags must be set */
2128 config->wFlags |= UMP_MASK_UART_FLAGS_RECEIVE_MS_INT;
2129 config->wFlags |= UMP_MASK_UART_FLAGS_AUTO_START_ON_ERR;
2130 config->bUartMode = (__u8)(edge_port->bUartMode);
2131
2132 switch (cflag & CSIZE) {
Alan Cox2742fd82008-04-29 14:45:15 +01002133 case CS5:
2134 config->bDataBits = UMP_UART_CHAR5BITS;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002135 dev_dbg(dev, "%s - data bits = 5\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01002136 break;
2137 case CS6:
2138 config->bDataBits = UMP_UART_CHAR6BITS;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002139 dev_dbg(dev, "%s - data bits = 6\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01002140 break;
2141 case CS7:
2142 config->bDataBits = UMP_UART_CHAR7BITS;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002143 dev_dbg(dev, "%s - data bits = 7\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01002144 break;
2145 default:
2146 case CS8:
2147 config->bDataBits = UMP_UART_CHAR8BITS;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002148 dev_dbg(dev, "%s - data bits = 8\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 break;
2150 }
2151
2152 if (cflag & PARENB) {
2153 if (cflag & PARODD) {
2154 config->wFlags |= UMP_MASK_UART_FLAGS_PARITY;
2155 config->bParity = UMP_UART_ODDPARITY;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002156 dev_dbg(dev, "%s - parity = odd\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 } else {
2158 config->wFlags |= UMP_MASK_UART_FLAGS_PARITY;
2159 config->bParity = UMP_UART_EVENPARITY;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002160 dev_dbg(dev, "%s - parity = even\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 }
2162 } else {
Alan Cox2742fd82008-04-29 14:45:15 +01002163 config->bParity = UMP_UART_NOPARITY;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002164 dev_dbg(dev, "%s - parity = none\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 }
2166
2167 if (cflag & CSTOPB) {
2168 config->bStopBits = UMP_UART_STOPBIT2;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002169 dev_dbg(dev, "%s - stop bits = 2\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 } else {
2171 config->bStopBits = UMP_UART_STOPBIT1;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002172 dev_dbg(dev, "%s - stop bits = 1\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 }
2174
2175 /* figure out the flow control settings */
2176 if (cflag & CRTSCTS) {
2177 config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X_CTS_FLOW;
2178 config->wFlags |= UMP_MASK_UART_FLAGS_RTS_FLOW;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002179 dev_dbg(dev, "%s - RTS/CTS is enabled\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 } else {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002181 dev_dbg(dev, "%s - RTS/CTS is disabled\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 restart_read(edge_port);
2183 }
2184
Alan Cox2742fd82008-04-29 14:45:15 +01002185 /* if we are implementing XON/XOFF, set the start and stop
2186 character in the device */
2187 config->cXon = START_CHAR(tty);
2188 config->cXoff = STOP_CHAR(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189
Alan Cox2742fd82008-04-29 14:45:15 +01002190 /* if we are implementing INBOUND XON/XOFF */
2191 if (I_IXOFF(tty)) {
2192 config->wFlags |= UMP_MASK_UART_FLAGS_IN_X;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002193 dev_dbg(dev, "%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x\n",
2194 __func__, config->cXon, config->cXoff);
Alan Cox2742fd82008-04-29 14:45:15 +01002195 } else
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002196 dev_dbg(dev, "%s - INBOUND XON/XOFF is disabled\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197
Alan Cox2742fd82008-04-29 14:45:15 +01002198 /* if we are implementing OUTBOUND XON/XOFF */
2199 if (I_IXON(tty)) {
2200 config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002201 dev_dbg(dev, "%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x\n",
2202 __func__, config->cXon, config->cXoff);
Alan Cox2742fd82008-04-29 14:45:15 +01002203 } else
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002204 dev_dbg(dev, "%s - OUTBOUND XON/XOFF is disabled\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205
Alan Coxadc8d742012-07-14 15:31:47 +01002206 tty->termios.c_cflag &= ~CMSPAR;
Alan Coxd5f5bcd2008-01-03 16:57:33 +00002207
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 /* Round the baud rate */
2209 baud = tty_get_baud_rate(tty);
2210 if (!baud) {
2211 /* pick a default, any default... */
2212 baud = 9600;
Alan Coxd5f5bcd2008-01-03 16:57:33 +00002213 } else
2214 tty_encode_baud_rate(tty, baud, baud);
2215
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 edge_port->baud_rate = baud;
2217 config->wBaudRate = (__u16)((461550L + baud/2) / baud);
2218
Alan Coxd5f5bcd2008-01-03 16:57:33 +00002219 /* FIXME: Recompute actual baud from divisor here */
2220
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002221 dev_dbg(dev, "%s - baud rate = %d, wBaudRate = %d\n", __func__, baud, config->wBaudRate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002223 dev_dbg(dev, "wBaudRate: %d\n", (int)(461550L / config->wBaudRate));
2224 dev_dbg(dev, "wFlags: 0x%x\n", config->wFlags);
2225 dev_dbg(dev, "bDataBits: %d\n", config->bDataBits);
2226 dev_dbg(dev, "bParity: %d\n", config->bParity);
2227 dev_dbg(dev, "bStopBits: %d\n", config->bStopBits);
2228 dev_dbg(dev, "cXon: %d\n", config->cXon);
2229 dev_dbg(dev, "cXoff: %d\n", config->cXoff);
2230 dev_dbg(dev, "bUartMode: %d\n", config->bUartMode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231
2232 /* move the word values into big endian mode */
Alan Cox2742fd82008-04-29 14:45:15 +01002233 cpu_to_be16s(&config->wFlags);
2234 cpu_to_be16s(&config->wBaudRate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235
Alan Cox2742fd82008-04-29 14:45:15 +01002236 status = send_cmd(edge_port->port->serial->dev, UMPC_SET_CONFIG,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 (__u8)(UMPM_UART1_PORT + port_number),
Alan Cox2742fd82008-04-29 14:45:15 +01002238 0, (__u8 *)config, sizeof(*config));
2239 if (status)
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002240 dev_dbg(dev, "%s - error %d when trying to write config to device\n",
2241 __func__, status);
Alan Cox2742fd82008-04-29 14:45:15 +01002242 kfree(config);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243}
2244
Alan Cox2e0ddd62008-07-22 11:12:33 +01002245static void edge_set_termios(struct tty_struct *tty,
Alan Cox95da3102008-07-22 11:09:07 +01002246 struct usb_serial_port *port, struct ktermios *old_termios)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247{
2248 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
Alan Cox95da3102008-07-22 11:09:07 +01002249 unsigned int cflag;
2250
Alan Coxadc8d742012-07-14 15:31:47 +01002251 cflag = tty->termios.c_cflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002253 dev_dbg(&port->dev, "%s - clfag %08x iflag %08x\n", __func__,
Linus Torvaldsd9a80742012-10-01 13:23:01 -07002254 tty->termios.c_cflag, tty->termios.c_iflag);
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002255 dev_dbg(&port->dev, "%s - old clfag %08x old iflag %08x\n", __func__,
2256 old_termios->c_cflag, old_termios->c_iflag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257
2258 if (edge_port == NULL)
2259 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 /* change the port settings to the new ones specified */
Alan Cox95da3102008-07-22 11:09:07 +01002261 change_port_settings(tty, edge_port, old_termios);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262}
2263
Alan Cox20b9d172011-02-14 16:26:50 +00002264static int edge_tiocmset(struct tty_struct *tty,
Alan Cox2742fd82008-04-29 14:45:15 +01002265 unsigned int set, unsigned int clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266{
Alan Cox95da3102008-07-22 11:09:07 +01002267 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2269 unsigned int mcr;
Alan Cox3d71fe02008-02-20 21:38:32 +00002270 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271
Alan Cox3d71fe02008-02-20 21:38:32 +00002272 spin_lock_irqsave(&edge_port->ep_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 mcr = edge_port->shadow_mcr;
2274 if (set & TIOCM_RTS)
2275 mcr |= MCR_RTS;
2276 if (set & TIOCM_DTR)
2277 mcr |= MCR_DTR;
2278 if (set & TIOCM_LOOP)
2279 mcr |= MCR_LOOPBACK;
2280
2281 if (clear & TIOCM_RTS)
2282 mcr &= ~MCR_RTS;
2283 if (clear & TIOCM_DTR)
2284 mcr &= ~MCR_DTR;
2285 if (clear & TIOCM_LOOP)
2286 mcr &= ~MCR_LOOPBACK;
2287
2288 edge_port->shadow_mcr = mcr;
Alan Cox3d71fe02008-02-20 21:38:32 +00002289 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290
Alan Cox2742fd82008-04-29 14:45:15 +01002291 restore_mcr(edge_port, mcr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 return 0;
2293}
2294
Alan Cox60b33c12011-02-14 16:26:14 +00002295static int edge_tiocmget(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296{
Alan Cox95da3102008-07-22 11:09:07 +01002297 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2299 unsigned int result = 0;
2300 unsigned int msr;
2301 unsigned int mcr;
Alan Cox3d71fe02008-02-20 21:38:32 +00002302 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303
Alan Cox3d71fe02008-02-20 21:38:32 +00002304 spin_lock_irqsave(&edge_port->ep_lock, flags);
2305
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 msr = edge_port->shadow_msr;
2307 mcr = edge_port->shadow_mcr;
2308 result = ((mcr & MCR_DTR) ? TIOCM_DTR: 0) /* 0x002 */
2309 | ((mcr & MCR_RTS) ? TIOCM_RTS: 0) /* 0x004 */
2310 | ((msr & EDGEPORT_MSR_CTS) ? TIOCM_CTS: 0) /* 0x020 */
2311 | ((msr & EDGEPORT_MSR_CD) ? TIOCM_CAR: 0) /* 0x040 */
2312 | ((msr & EDGEPORT_MSR_RI) ? TIOCM_RI: 0) /* 0x080 */
2313 | ((msr & EDGEPORT_MSR_DSR) ? TIOCM_DSR: 0); /* 0x100 */
2314
2315
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002316 dev_dbg(&port->dev, "%s -- %x\n", __func__, result);
Alan Cox3d71fe02008-02-20 21:38:32 +00002317 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318
2319 return result;
2320}
2321
Alan Cox2742fd82008-04-29 14:45:15 +01002322static int get_serial_info(struct edgeport_port *edge_port,
2323 struct serial_struct __user *retinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324{
2325 struct serial_struct tmp;
Johan Hovoldf40d7812013-01-14 16:52:58 +01002326 unsigned cwait;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327
2328 if (!retinfo)
2329 return -EFAULT;
2330
Johan Hovoldf40d7812013-01-14 16:52:58 +01002331 cwait = edge_port->port->port.closing_wait;
2332 if (cwait != ASYNC_CLOSING_WAIT_NONE)
Johan Hovoldb6fd35e2013-04-18 17:33:17 +02002333 cwait = jiffies_to_msecs(cwait) / 10;
Johan Hovoldf40d7812013-01-14 16:52:58 +01002334
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 memset(&tmp, 0, sizeof(tmp));
2336
2337 tmp.type = PORT_16550A;
Greg Kroah-Hartmane5b1e202013-06-07 11:04:28 -07002338 tmp.line = edge_port->port->minor;
Greg Kroah-Hartman11438322013-06-06 10:32:00 -07002339 tmp.port = edge_port->port->port_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 tmp.irq = 0;
2341 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
2342 tmp.xmit_fifo_size = edge_port->port->bulk_out_size;
2343 tmp.baud_base = 9600;
2344 tmp.close_delay = 5*HZ;
Johan Hovoldf40d7812013-01-14 16:52:58 +01002345 tmp.closing_wait = cwait;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346
2347 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2348 return -EFAULT;
2349 return 0;
2350}
2351
Alan Cox00a0d0d2011-02-14 16:27:06 +00002352static int edge_ioctl(struct tty_struct *tty,
Alan Cox2742fd82008-04-29 14:45:15 +01002353 unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354{
Alan Cox95da3102008-07-22 11:09:07 +01002355 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 switch (cmd) {
Alan Cox2742fd82008-04-29 14:45:15 +01002359 case TIOCGSERIAL:
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002360 dev_dbg(&port->dev, "%s - TIOCGSERIAL\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01002361 return get_serial_info(edge_port,
2362 (struct serial_struct __user *) arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 return -ENOIOCTLCMD;
2365}
2366
Alan Cox95da3102008-07-22 11:09:07 +01002367static void edge_break(struct tty_struct *tty, int break_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368{
Alan Cox95da3102008-07-22 11:09:07 +01002369 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2371 int status;
Alan Cox2742fd82008-04-29 14:45:15 +01002372 int bv = 0; /* Off */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373
Alan Cox95da3102008-07-22 11:09:07 +01002374 if (break_state == -1)
Alan Cox2742fd82008-04-29 14:45:15 +01002375 bv = 1; /* On */
2376 status = ti_do_config(edge_port, UMPC_SET_CLR_BREAK, bv);
2377 if (status)
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002378 dev_dbg(&port->dev, "%s - error %d sending break set/clear command.\n",
2379 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380}
2381
Alan Cox2742fd82008-04-29 14:45:15 +01002382static int edge_startup(struct usb_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383{
2384 struct edgeport_serial *edge_serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386
2387 /* create our private serial structure */
Eric Sesterhenn80b6ca42006-02-27 21:29:43 +01002388 edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL);
Johan Hovold10c642d2013-12-29 19:22:56 +01002389 if (!edge_serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 return -ENOMEM;
Johan Hovold10c642d2013-12-29 19:22:56 +01002391
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01002392 mutex_init(&edge_serial->es_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 edge_serial->serial = serial;
2394 usb_set_serial_data(serial, edge_serial);
2395
Alan Cox2742fd82008-04-29 14:45:15 +01002396 status = download_fw(edge_serial);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01002398 kfree(edge_serial);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 return status;
2400 }
2401
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403}
2404
Alan Sternf9c99bb2009-06-02 11:53:55 -04002405static void edge_disconnect(struct usb_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406{
Alan Sternf9c99bb2009-06-02 11:53:55 -04002407}
2408
2409static void edge_release(struct usb_serial *serial)
2410{
Jesper Juhl0d46c002007-07-16 22:17:25 +02002411 kfree(usb_get_serial_data(serial));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412}
2413
Johan Hovold00361532012-10-17 13:34:58 +02002414static int edge_port_probe(struct usb_serial_port *port)
2415{
2416 struct edgeport_port *edge_port;
2417 int ret;
2418
2419 edge_port = kzalloc(sizeof(*edge_port), GFP_KERNEL);
2420 if (!edge_port)
2421 return -ENOMEM;
2422
Johan Hovold00361532012-10-17 13:34:58 +02002423 spin_lock_init(&edge_port->ep_lock);
2424 edge_port->port = port;
2425 edge_port->edge_serial = usb_get_serial_data(port->serial);
2426 edge_port->bUartMode = default_uart_mode;
2427
Johan Hovold0fce06d2013-06-26 16:47:38 +02002428 switch (port->port_number) {
2429 case 0:
2430 edge_port->uart_base = UMPMEM_BASE_UART1;
2431 edge_port->dma_address = UMPD_OEDB1_ADDRESS;
2432 break;
2433 case 1:
2434 edge_port->uart_base = UMPMEM_BASE_UART2;
2435 edge_port->dma_address = UMPD_OEDB2_ADDRESS;
2436 break;
2437 default:
2438 dev_err(&port->dev, "unknown port number\n");
2439 ret = -ENODEV;
2440 goto err;
2441 }
2442
2443 dev_dbg(&port->dev,
2444 "%s - port_number = %d, uart_base = %04x, dma_address = %04x\n",
2445 __func__, port->port_number, edge_port->uart_base,
2446 edge_port->dma_address);
2447
Johan Hovold00361532012-10-17 13:34:58 +02002448 usb_set_serial_port_data(port, edge_port);
2449
Johan Hovold5d8c61b2012-10-18 11:43:28 +02002450 ret = edge_create_sysfs_attrs(port);
Johan Hovold0fce06d2013-06-26 16:47:38 +02002451 if (ret)
2452 goto err;
Johan Hovold5d8c61b2012-10-18 11:43:28 +02002453
Johan Hovoldf40d7812013-01-14 16:52:58 +01002454 port->port.closing_wait = msecs_to_jiffies(closing_wait * 10);
Johan Hovoldd7be6222013-06-26 16:47:23 +02002455 port->port.drain_delay = 1;
Johan Hovoldf40d7812013-01-14 16:52:58 +01002456
Johan Hovold00361532012-10-17 13:34:58 +02002457 return 0;
Johan Hovold0fce06d2013-06-26 16:47:38 +02002458err:
2459 kfree(edge_port);
2460
2461 return ret;
Johan Hovold00361532012-10-17 13:34:58 +02002462}
2463
2464static int edge_port_remove(struct usb_serial_port *port)
2465{
2466 struct edgeport_port *edge_port;
2467
2468 edge_port = usb_get_serial_port_data(port);
Johan Hovold00361532012-10-17 13:34:58 +02002469 edge_remove_sysfs_attrs(port);
Johan Hovold00361532012-10-17 13:34:58 +02002470 kfree(edge_port);
2471
2472 return 0;
2473}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -04002475/* Sysfs Attributes */
2476
Greg Kroah-Hartman154547c2013-08-23 16:18:34 -07002477static ssize_t uart_mode_show(struct device *dev,
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -04002478 struct device_attribute *attr, char *buf)
2479{
2480 struct usb_serial_port *port = to_usb_serial_port(dev);
2481 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2482
2483 return sprintf(buf, "%d\n", edge_port->bUartMode);
2484}
2485
Greg Kroah-Hartman154547c2013-08-23 16:18:34 -07002486static ssize_t uart_mode_store(struct device *dev,
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -04002487 struct device_attribute *attr, const char *valbuf, size_t count)
2488{
2489 struct usb_serial_port *port = to_usb_serial_port(dev);
2490 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2491 unsigned int v = simple_strtoul(valbuf, NULL, 0);
2492
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002493 dev_dbg(dev, "%s: setting uart_mode = %d\n", __func__, v);
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -04002494
2495 if (v < 256)
2496 edge_port->bUartMode = v;
2497 else
Harvey Harrison441b62c2008-03-03 16:08:34 -08002498 dev_err(dev, "%s - uart_mode %d is invalid\n", __func__, v);
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -04002499
2500 return count;
2501}
Greg Kroah-Hartman154547c2013-08-23 16:18:34 -07002502static DEVICE_ATTR_RW(uart_mode);
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -04002503
2504static int edge_create_sysfs_attrs(struct usb_serial_port *port)
2505{
2506 return device_create_file(&port->dev, &dev_attr_uart_mode);
2507}
2508
2509static int edge_remove_sysfs_attrs(struct usb_serial_port *port)
2510{
2511 device_remove_file(&port->dev, &dev_attr_uart_mode);
2512 return 0;
2513}
2514
2515
Greg Kroah-Hartmanea653702005-06-20 21:15:16 -07002516static struct usb_serial_driver edgeport_1port_device = {
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -07002517 .driver = {
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -07002518 .owner = THIS_MODULE,
2519 .name = "edgeport_ti_1",
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -07002520 },
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -07002521 .description = "Edgeport TI 1 port adapter",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 .id_table = edgeport_1port_id_table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 .num_ports = 1,
2524 .open = edge_open,
2525 .close = edge_close,
2526 .throttle = edge_throttle,
2527 .unthrottle = edge_unthrottle,
2528 .attach = edge_startup,
Alan Sternf9c99bb2009-06-02 11:53:55 -04002529 .disconnect = edge_disconnect,
2530 .release = edge_release,
Johan Hovold00361532012-10-17 13:34:58 +02002531 .port_probe = edge_port_probe,
2532 .port_remove = edge_port_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 .ioctl = edge_ioctl,
2534 .set_termios = edge_set_termios,
2535 .tiocmget = edge_tiocmget,
2536 .tiocmset = edge_tiocmset,
Johan Hovold48ee5802013-03-21 12:37:10 +01002537 .tiocmiwait = usb_serial_generic_tiocmiwait,
Johan Hovoldcf9a9d62013-03-21 12:37:09 +01002538 .get_icount = usb_serial_generic_get_icount,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 .write = edge_write,
2540 .write_room = edge_write_room,
2541 .chars_in_buffer = edge_chars_in_buffer,
Johan Hovoldb16634a2013-05-05 20:32:31 +02002542 .tx_empty = edge_tx_empty,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 .break_ctl = edge_break,
2544 .read_int_callback = edge_interrupt_callback,
2545 .read_bulk_callback = edge_bulk_in_callback,
2546 .write_bulk_callback = edge_bulk_out_callback,
2547};
2548
Greg Kroah-Hartmanea653702005-06-20 21:15:16 -07002549static struct usb_serial_driver edgeport_2port_device = {
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -07002550 .driver = {
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -07002551 .owner = THIS_MODULE,
2552 .name = "edgeport_ti_2",
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -07002553 },
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -07002554 .description = "Edgeport TI 2 port adapter",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 .id_table = edgeport_2port_id_table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 .num_ports = 2,
2557 .open = edge_open,
2558 .close = edge_close,
2559 .throttle = edge_throttle,
2560 .unthrottle = edge_unthrottle,
2561 .attach = edge_startup,
Alan Sternf9c99bb2009-06-02 11:53:55 -04002562 .disconnect = edge_disconnect,
2563 .release = edge_release,
Johan Hovold00361532012-10-17 13:34:58 +02002564 .port_probe = edge_port_probe,
2565 .port_remove = edge_port_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 .ioctl = edge_ioctl,
2567 .set_termios = edge_set_termios,
2568 .tiocmget = edge_tiocmget,
2569 .tiocmset = edge_tiocmset,
Johan Hovold48ee5802013-03-21 12:37:10 +01002570 .tiocmiwait = usb_serial_generic_tiocmiwait,
Johan Hovoldcf9a9d62013-03-21 12:37:09 +01002571 .get_icount = usb_serial_generic_get_icount,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 .write = edge_write,
2573 .write_room = edge_write_room,
2574 .chars_in_buffer = edge_chars_in_buffer,
Johan Hovoldb16634a2013-05-05 20:32:31 +02002575 .tx_empty = edge_tx_empty,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 .break_ctl = edge_break,
2577 .read_int_callback = edge_interrupt_callback,
2578 .read_bulk_callback = edge_bulk_in_callback,
2579 .write_bulk_callback = edge_bulk_out_callback,
2580};
2581
Alan Stern7dbe2462012-02-23 14:56:57 -05002582static struct usb_serial_driver * const serial_drivers[] = {
2583 &edgeport_1port_device, &edgeport_2port_device, NULL
2584};
2585
Greg Kroah-Hartman68e24112012-05-08 15:46:14 -07002586module_usb_serial_driver(serial_drivers, id_table_combined);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588MODULE_AUTHOR(DRIVER_AUTHOR);
2589MODULE_DESCRIPTION(DRIVER_DESC);
2590MODULE_LICENSE("GPL");
Jaswinder Singhd12b2192008-07-04 23:06:09 +05302591MODULE_FIRMWARE("edgeport/down3.bin");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593module_param(closing_wait, int, S_IRUGO | S_IWUSR);
2594MODULE_PARM_DESC(closing_wait, "Maximum wait for data to drain, in .01 secs");
2595
2596module_param(ignore_cpu_rev, bool, S_IRUGO | S_IWUSR);
Alan Cox2742fd82008-04-29 14:45:15 +01002597MODULE_PARM_DESC(ignore_cpu_rev,
2598 "Ignore the cpu revision when connecting to a device");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -04002600module_param(default_uart_mode, int, S_IRUGO | S_IWUSR);
2601MODULE_PARM_DESC(default_uart_mode, "Default uart_mode, 0=RS232, ...");