blob: 8cd6479a8b43000ffef126c249fb706639cceab7 [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>
23#include <linux/init.h>
24#include <linux/slab.h>
25#include <linux/tty.h>
26#include <linux/tty_driver.h>
27#include <linux/tty_flip.h>
28#include <linux/module.h>
29#include <linux/spinlock.h>
Matthias Kaehlcke241ca642007-12-04 16:15:40 +010030#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/serial.h>
Johan Hovold9e036f062014-04-25 15:23:03 +020032#include <linux/swab.h>
Johan Hovoldd733cec2010-05-19 00:01:37 +020033#include <linux/kfifo.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/ioctl.h>
Jaswinder Singhd12b2192008-07-04 23:06:09 +053035#include <linux/firmware.h>
Alan Cox2742fd82008-04-29 14:45:15 +010036#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/usb.h>
Greg Kroah-Hartmana9698882006-07-11 21:22:58 -070038#include <linux/usb/serial.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include "io_16654.h"
41#include "io_usbvend.h"
42#include "io_ti.h"
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com> and David Iacovelli"
45#define DRIVER_DESC "Edgeport USB Serial Driver"
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define EPROM_PAGE_SIZE 64
48
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050/* different hardware types */
51#define HARDWARE_TYPE_930 0
52#define HARDWARE_TYPE_TIUMP 1
53
Alan Cox2742fd82008-04-29 14:45:15 +010054/* IOCTL_PRIVATE_TI_GET_MODE Definitions */
55#define TI_MODE_CONFIGURING 0 /* Device has not entered start device */
56#define TI_MODE_BOOT 1 /* Staying in boot mode */
57#define TI_MODE_DOWNLOAD 2 /* Made it to download mode */
58#define TI_MODE_TRANSITIONING 3 /* Currently in boot mode but
59 transitioning to download mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61/* read urb state */
62#define EDGE_READ_URB_RUNNING 0
63#define EDGE_READ_URB_STOPPING 1
64#define EDGE_READ_URB_STOPPED 2
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#define EDGE_CLOSING_WAIT 4000 /* in .01 sec */
67
68#define EDGE_OUT_BUF_SIZE 1024
69
70
71/* Product information read from the Edgeport */
Alan Cox2742fd82008-04-29 14:45:15 +010072struct product_info {
73 int TiMode; /* Current TI Mode */
74 __u8 hardware_type; /* Type of hardware */
Linus Torvalds1da177e2005-04-16 15:20:36 -070075} __attribute__((packed));
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077struct edgeport_port {
78 __u16 uart_base;
79 __u16 dma_address;
80 __u8 shadow_msr;
81 __u8 shadow_mcr;
82 __u8 shadow_lsr;
83 __u8 lsr_mask;
Martin Olsson19af5cd2009-04-23 11:37:37 +020084 __u32 ump_read_timeout; /* Number of milliseconds the UMP will
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 wait without data before completing
86 a read short */
87 int baud_rate;
88 int close_pending;
89 int lsr_event;
Johan Hovold48ee5802013-03-21 12:37:10 +010090
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 struct edgeport_serial *edge_serial;
92 struct usb_serial_port *port;
Alan Cox2742fd82008-04-29 14:45:15 +010093 __u8 bUartMode; /* Port type, 0: RS232, etc. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 spinlock_t ep_lock;
95 int ep_read_urb_state;
96 int ep_write_urb_in_use;
Johan Hovoldd733cec2010-05-19 00:01:37 +020097 struct kfifo write_fifo;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098};
99
100struct edgeport_serial {
101 struct product_info product_info;
Alan Cox2742fd82008-04-29 14:45:15 +0100102 u8 TI_I2C_Type; /* Type of I2C in UMP */
103 u8 TiReadI2C; /* Set to TRUE if we have read the
104 I2c in Boot Mode */
Matthias Kaehlcke241ca642007-12-04 16:15:40 +0100105 struct mutex es_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 int num_ports_open;
107 struct usb_serial *serial;
108};
109
110
111/* Devices that this driver supports */
Németh Márton7d40d7e2010-01-10 15:34:24 +0100112static const struct usb_device_id edgeport_1port_id_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) },
114 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1) },
115 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I) },
116 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROXIMITY) },
117 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOTION) },
118 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOISTURE) },
119 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_TEMPERATURE) },
120 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_HUMIDITY) },
121 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_POWER) },
122 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_LIGHT) },
123 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_RADIATION) },
124 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_DISTANCE) },
125 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_ACCELERATION) },
126 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROX_DIST) },
127 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_HP4CD) },
128 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_PCI) },
129 { }
130};
131
Németh Márton7d40d7e2010-01-10 15:34:24 +0100132static const struct usb_device_id edgeport_2port_id_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2) },
134 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2C) },
135 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2I) },
136 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421) },
137 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21) },
138 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_42) },
139 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4) },
140 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4I) },
141 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22I) },
142 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_221C) },
143 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22C) },
144 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21C) },
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -0400145 /* The 4, 8 and 16 port devices show up as multiple 2 port devices */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4S) },
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -0400147 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8) },
148 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8S) },
149 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416) },
150 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416B) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 { }
152};
153
154/* Devices that this driver supports */
Németh Márton7d40d7e2010-01-10 15:34:24 +0100155static const struct usb_device_id id_table_combined[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) },
157 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1) },
158 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I) },
159 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROXIMITY) },
160 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOTION) },
161 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOISTURE) },
162 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_TEMPERATURE) },
163 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_HUMIDITY) },
164 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_POWER) },
165 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_LIGHT) },
166 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_RADIATION) },
167 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_DISTANCE) },
168 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_ACCELERATION) },
169 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROX_DIST) },
170 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_HP4CD) },
171 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_PCI) },
172 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2) },
173 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2C) },
174 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2I) },
175 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421) },
176 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21) },
177 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_42) },
178 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4) },
179 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4I) },
180 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22I) },
181 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_221C) },
182 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22C) },
183 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21C) },
184 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4S) },
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -0400185 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8) },
186 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8S) },
187 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416) },
188 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416B) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 { }
190};
191
Alan Cox2742fd82008-04-29 14:45:15 +0100192MODULE_DEVICE_TABLE(usb, id_table_combined);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530194static unsigned char OperationalMajorVersion;
195static unsigned char OperationalMinorVersion;
196static unsigned short OperationalBuildNumber;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198static int closing_wait = EDGE_CLOSING_WAIT;
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030199static bool ignore_cpu_rev;
Alan Cox2742fd82008-04-29 14:45:15 +0100200static int default_uart_mode; /* RS232 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Jiri Slaby2e124b42013-01-03 15:53:06 +0100202static void edge_tty_recv(struct usb_serial_port *port, unsigned char *data,
203 int length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
205static void stop_read(struct edgeport_port *edge_port);
206static int restart_read(struct edgeport_port *edge_port);
207
Alan Cox95da3102008-07-22 11:09:07 +0100208static void edge_set_termios(struct tty_struct *tty,
209 struct usb_serial_port *port, struct ktermios *old_termios);
Jiri Slabyae3759c2013-04-04 22:41:01 +0200210static void edge_send(struct usb_serial_port *port, struct tty_struct *tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -0400212/* sysfs attributes */
213static int edge_create_sysfs_attrs(struct usb_serial_port *port);
214static int edge_remove_sysfs_attrs(struct usb_serial_port *port);
215
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
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
235static int ti_vsend_sync(struct usb_device *dev, __u8 request,
236 __u16 value, __u16 index, u8 *data, int size)
237{
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),
242 value, index, data, size, 1000);
243 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{
Alan Cox2742fd82008-04-29 14:45:15 +0100257 return ti_vsend_sync(dev, command, value, moduleid, data, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258}
259
260/* clear tx/rx buffers and fifo in TI UMP */
Alan Cox2742fd82008-04-29 14:45:15 +0100261static int purge_port(struct usb_serial_port *port, __u16 mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262{
263 int port_number = port->number - port->serial->minor;
264
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700265 dev_dbg(&port->dev, "%s - port %d, mask %x\n", __func__, port_number, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
Alan Cox2742fd82008-04-29 14:45:15 +0100267 return send_cmd(port->serial->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 UMPC_PURGE_PORT,
269 (__u8)(UMPM_UART1_PORT + port_number),
270 mask,
271 NULL,
272 0);
273}
274
275/**
Alan Cox2742fd82008-04-29 14:45:15 +0100276 * read_download_mem - Read edgeport memory from TI chip
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 * @dev: usb device pointer
278 * @start_address: Device CPU address at which to read
279 * @length: Length of above data
280 * @address_type: Can read both XDATA and I2C
281 * @buffer: pointer to input data buffer
282 */
Alan Cox2742fd82008-04-29 14:45:15 +0100283static int read_download_mem(struct usb_device *dev, int start_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 int length, __u8 address_type, __u8 *buffer)
285{
286 int status = 0;
287 __u8 read_length;
Johan Hovold9e036f062014-04-25 15:23:03 +0200288 u16 be_start_address;
Alan Cox2742fd82008-04-29 14:45:15 +0100289
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700290 dev_dbg(&dev->dev, "%s - @ %x for %d\n", __func__, start_address, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
292 /* Read in blocks of 64 bytes
293 * (TI firmware can't handle more than 64 byte reads)
294 */
295 while (length) {
296 if (length > 64)
Alan Cox2742fd82008-04-29 14:45:15 +0100297 read_length = 64;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 else
299 read_length = (__u8)length;
300
301 if (read_length > 1) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700302 dev_dbg(&dev->dev, "%s - @ %x for %d\n", __func__, start_address, read_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 }
Johan Hovold9e036f062014-04-25 15:23:03 +0200304 /*
305 * NOTE: Must use swab as wIndex is sent in little-endian
306 * byte order regardless of host byte order.
307 */
308 be_start_address = swab16((u16)start_address);
Alan Cox2742fd82008-04-29 14:45:15 +0100309 status = ti_vread_sync(dev, UMPC_MEMORY_READ,
310 (__u16)address_type,
Johan Hovold9e036f062014-04-25 15:23:03 +0200311 be_start_address,
Alan Cox2742fd82008-04-29 14:45:15 +0100312 buffer, read_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
314 if (status) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700315 dev_dbg(&dev->dev, "%s - ERROR %x\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 return status;
317 }
318
Alan Cox2742fd82008-04-29 14:45:15 +0100319 if (read_length > 1)
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +0100320 usb_serial_debug_data(&dev->dev, __func__, read_length, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
322 /* Update pointers/length */
323 start_address += read_length;
324 buffer += read_length;
325 length -= read_length;
326 }
Alan Cox2742fd82008-04-29 14:45:15 +0100327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 return status;
329}
330
Alan Cox2742fd82008-04-29 14:45:15 +0100331static int read_ram(struct usb_device *dev, int start_address,
332 int length, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333{
Alan Cox2742fd82008-04-29 14:45:15 +0100334 return read_download_mem(dev, start_address, length,
335 DTK_ADDR_SPACE_XDATA, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336}
337
338/* Read edgeport memory to a given block */
Alan Cox2742fd82008-04-29 14:45:15 +0100339static int read_boot_mem(struct edgeport_serial *serial,
340 int start_address, int length, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341{
342 int status = 0;
343 int i;
344
Alan Cox2742fd82008-04-29 14:45:15 +0100345 for (i = 0; i < length; i++) {
346 status = ti_vread_sync(serial->serial->dev,
347 UMPC_MEMORY_READ, serial->TI_I2C_Type,
348 (__u16)(start_address+i), &buffer[i], 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 if (status) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700350 dev_dbg(&serial->serial->dev->dev, "%s - ERROR %x\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 return status;
352 }
353 }
354
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700355 dev_dbg(&serial->serial->dev->dev, "%s - start_address = %x, length = %d\n",
356 __func__, start_address, length);
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +0100357 usb_serial_debug_data(&serial->serial->dev->dev, __func__, length, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
359 serial->TiReadI2C = 1;
360
361 return status;
362}
363
364/* Write given block to TI EPROM memory */
Alan Cox2742fd82008-04-29 14:45:15 +0100365static int write_boot_mem(struct edgeport_serial *serial,
366 int start_address, int length, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367{
368 int status = 0;
369 int i;
Johan Hovolde9305d22009-12-28 23:01:50 +0100370 u8 *temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
372 /* Must do a read before write */
373 if (!serial->TiReadI2C) {
Johan Hovolde9305d22009-12-28 23:01:50 +0100374 temp = kmalloc(1, GFP_KERNEL);
375 if (!temp) {
376 dev_err(&serial->serial->dev->dev,
377 "%s - out of memory\n", __func__);
378 return -ENOMEM;
379 }
380 status = read_boot_mem(serial, 0, 1, temp);
381 kfree(temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 if (status)
383 return status;
384 }
385
Alan Cox2742fd82008-04-29 14:45:15 +0100386 for (i = 0; i < length; ++i) {
387 status = ti_vsend_sync(serial->serial->dev,
388 UMPC_MEMORY_WRITE, buffer[i],
389 (__u16)(i + start_address), NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 if (status)
391 return status;
392 }
393
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700394 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 +0100395 usb_serial_debug_data(&serial->serial->dev->dev, __func__, length, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
397 return status;
398}
399
400
401/* Write edgeport I2C memory to TI chip */
Alan Cox2742fd82008-04-29 14:45:15 +0100402static int write_i2c_mem(struct edgeport_serial *serial,
403 int start_address, int length, __u8 address_type, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404{
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700405 struct device *dev = &serial->serial->dev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 int status = 0;
407 int write_length;
Johan Hovold9e036f062014-04-25 15:23:03 +0200408 u16 be_start_address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
410 /* We can only send a maximum of 1 aligned byte page at a time */
Alan Cox2742fd82008-04-29 14:45:15 +0100411
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300412 /* calculate the number of bytes left in the first page */
Alan Cox2742fd82008-04-29 14:45:15 +0100413 write_length = EPROM_PAGE_SIZE -
414 (start_address & (EPROM_PAGE_SIZE - 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
416 if (write_length > length)
417 write_length = length;
418
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700419 dev_dbg(dev, "%s - BytesInFirstPage Addr = %x, length = %d\n",
420 __func__, start_address, write_length);
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +0100421 usb_serial_debug_data(dev, __func__, write_length, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Johan Hovold9e036f062014-04-25 15:23:03 +0200423 /*
424 * Write first page.
425 *
426 * NOTE: Must use swab as wIndex is sent in little-endian byte order
427 * regardless of host byte order.
428 */
429 be_start_address = swab16((u16)start_address);
Alan Cox2742fd82008-04-29 14:45:15 +0100430 status = ti_vsend_sync(serial->serial->dev,
431 UMPC_MEMORY_WRITE, (__u16)address_type,
Johan Hovold9e036f062014-04-25 15:23:03 +0200432 be_start_address,
Alan Cox2742fd82008-04-29 14:45:15 +0100433 buffer, write_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 if (status) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700435 dev_dbg(dev, "%s - ERROR %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 return status;
437 }
438
439 length -= write_length;
440 start_address += write_length;
441 buffer += write_length;
442
Alan Cox2742fd82008-04-29 14:45:15 +0100443 /* We should be aligned now -- can write
444 max page size bytes at a time */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 while (length) {
446 if (length > EPROM_PAGE_SIZE)
447 write_length = EPROM_PAGE_SIZE;
448 else
449 write_length = length;
450
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700451 dev_dbg(dev, "%s - Page Write Addr = %x, length = %d\n",
452 __func__, start_address, write_length);
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +0100453 usb_serial_debug_data(dev, __func__, write_length, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
Johan Hovold9e036f062014-04-25 15:23:03 +0200455 /*
456 * Write next page.
457 *
458 * NOTE: Must use swab as wIndex is sent in little-endian byte
459 * order regardless of host byte order.
460 */
461 be_start_address = swab16((u16)start_address);
Alan Cox2742fd82008-04-29 14:45:15 +0100462 status = ti_vsend_sync(serial->serial->dev, UMPC_MEMORY_WRITE,
463 (__u16)address_type,
Johan Hovold9e036f062014-04-25 15:23:03 +0200464 be_start_address,
Alan Cox2742fd82008-04-29 14:45:15 +0100465 buffer, write_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 if (status) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700467 dev_err(dev, "%s - ERROR %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 return status;
469 }
Alan Cox2742fd82008-04-29 14:45:15 +0100470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 length -= write_length;
472 start_address += write_length;
473 buffer += write_length;
474 }
475 return status;
476}
477
478/* Examine the UMP DMA registers and LSR
Alan Cox2742fd82008-04-29 14:45:15 +0100479 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 * Check the MSBit of the X and Y DMA byte count registers.
481 * A zero in this bit indicates that the TX DMA buffers are empty
482 * then check the TX Empty bit in the UART.
483 */
Alan Cox2742fd82008-04-29 14:45:15 +0100484static int tx_active(struct edgeport_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485{
486 int status;
487 struct out_endpoint_desc_block *oedb;
488 __u8 *lsr;
489 int bytes_left = 0;
490
Alan Cox2742fd82008-04-29 14:45:15 +0100491 oedb = kmalloc(sizeof(*oedb), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 if (!oedb) {
Alan Cox2742fd82008-04-29 14:45:15 +0100493 dev_err(&port->port->dev, "%s - out of memory\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 return -ENOMEM;
495 }
496
Alan Cox2742fd82008-04-29 14:45:15 +0100497 lsr = kmalloc(1, GFP_KERNEL); /* Sigh, that's right, just one byte,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 as not all platforms can do DMA
499 from stack */
500 if (!lsr) {
501 kfree(oedb);
502 return -ENOMEM;
503 }
504 /* Read the DMA Count Registers */
Alan Cox2742fd82008-04-29 14:45:15 +0100505 status = read_ram(port->port->serial->dev, port->dma_address,
506 sizeof(*oedb), (void *)oedb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 if (status)
508 goto exit_is_tx_active;
509
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700510 dev_dbg(&port->port->dev, "%s - XByteCount 0x%X\n", __func__, oedb->XByteCount);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
512 /* and the LSR */
Alan Cox2742fd82008-04-29 14:45:15 +0100513 status = read_ram(port->port->serial->dev,
514 port->uart_base + UMPMEM_OFFS_UART_LSR, 1, lsr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
516 if (status)
517 goto exit_is_tx_active;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700518 dev_dbg(&port->port->dev, "%s - LSR = 0x%X\n", __func__, *lsr);
Alan Cox2742fd82008-04-29 14:45:15 +0100519
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 /* If either buffer has data or we are transmitting then return TRUE */
Alan Cox2742fd82008-04-29 14:45:15 +0100521 if ((oedb->XByteCount & 0x80) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 bytes_left += 64;
523
Alan Cox2742fd82008-04-29 14:45:15 +0100524 if ((*lsr & UMP_UART_LSR_TX_MASK) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 bytes_left += 1;
526
527 /* We return Not Active if we get any kind of error */
528exit_is_tx_active:
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700529 dev_dbg(&port->port->dev, "%s - return %d\n", __func__, bytes_left);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
531 kfree(lsr);
532 kfree(oedb);
533 return bytes_left;
534}
535
Alan Cox2742fd82008-04-29 14:45:15 +0100536static int choose_config(struct usb_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537{
Alan Cox2742fd82008-04-29 14:45:15 +0100538 /*
539 * There may be multiple configurations on this device, in which case
540 * we would need to read and parse all of them to find out which one
541 * we want. However, we just support one config at this point,
542 * configuration # 1, which is Config Descriptor 0.
543 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700545 dev_dbg(&dev->dev, "%s - Number of Interfaces = %d\n",
546 __func__, dev->config->desc.bNumInterfaces);
547 dev_dbg(&dev->dev, "%s - MAX Power = %d\n",
548 __func__, dev->config->desc.bMaxPower * 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
550 if (dev->config->desc.bNumInterfaces != 1) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700551 dev_err(&dev->dev, "%s - bNumInterfaces is not 1, ERROR!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 return -ENODEV;
553 }
554
555 return 0;
556}
557
Alan Cox2742fd82008-04-29 14:45:15 +0100558static int read_rom(struct edgeport_serial *serial,
559 int start_address, int length, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560{
561 int status;
562
563 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) {
Alan Cox2742fd82008-04-29 14:45:15 +0100564 status = read_download_mem(serial->serial->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 start_address,
566 length,
567 serial->TI_I2C_Type,
568 buffer);
569 } else {
Alan Cox2742fd82008-04-29 14:45:15 +0100570 status = read_boot_mem(serial, start_address, length,
571 buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 return status;
574}
575
Alan Cox2742fd82008-04-29 14:45:15 +0100576static int write_rom(struct edgeport_serial *serial, int start_address,
577 int length, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578{
579 if (serial->product_info.TiMode == TI_MODE_BOOT)
Alan Cox2742fd82008-04-29 14:45:15 +0100580 return write_boot_mem(serial, start_address, length,
581 buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
583 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD)
Alan Cox2742fd82008-04-29 14:45:15 +0100584 return write_i2c_mem(serial, start_address, length,
585 serial->TI_I2C_Type, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 return -EINVAL;
587}
588
589
590
591/* Read a descriptor header from I2C based on type */
Alan Cox2742fd82008-04-29 14:45:15 +0100592static int get_descriptor_addr(struct edgeport_serial *serial,
593 int desc_type, struct ti_i2c_desc *rom_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594{
595 int start_address;
596 int status;
597
598 /* Search for requested descriptor in I2C */
599 start_address = 2;
600 do {
Alan Cox2742fd82008-04-29 14:45:15 +0100601 status = read_rom(serial,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 start_address,
603 sizeof(struct ti_i2c_desc),
Alan Cox2742fd82008-04-29 14:45:15 +0100604 (__u8 *)rom_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 if (status)
606 return 0;
607
608 if (rom_desc->Type == desc_type)
609 return start_address;
610
Johan Hovold9e036f062014-04-25 15:23:03 +0200611 start_address = start_address + sizeof(struct ti_i2c_desc) +
612 le16_to_cpu(rom_desc->Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
614 } while ((start_address < TI_MAX_I2C_SIZE) && rom_desc->Type);
Alan Cox2742fd82008-04-29 14:45:15 +0100615
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 return 0;
617}
618
619/* Validate descriptor checksum */
Alan Cox2742fd82008-04-29 14:45:15 +0100620static int valid_csum(struct ti_i2c_desc *rom_desc, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621{
622 __u16 i;
623 __u8 cs = 0;
624
Johan Hovold9e036f062014-04-25 15:23:03 +0200625 for (i = 0; i < le16_to_cpu(rom_desc->Size); i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 cs = (__u8)(cs + buffer[i]);
Alan Cox2742fd82008-04-29 14:45:15 +0100627
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 if (cs != rom_desc->CheckSum) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700629 pr_debug("%s - Mismatch %x - %x", __func__, rom_desc->CheckSum, cs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 return -EINVAL;
631 }
632 return 0;
633}
634
635/* Make sure that the I2C image is good */
Alan Cox2742fd82008-04-29 14:45:15 +0100636static int check_i2c_image(struct edgeport_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637{
638 struct device *dev = &serial->serial->dev->dev;
639 int status = 0;
640 struct ti_i2c_desc *rom_desc;
641 int start_address = 2;
642 __u8 *buffer;
643 __u16 ttype;
644
Alan Cox2742fd82008-04-29 14:45:15 +0100645 rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 if (!rom_desc) {
Alan Cox2742fd82008-04-29 14:45:15 +0100647 dev_err(dev, "%s - out of memory\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 return -ENOMEM;
649 }
Alan Cox2742fd82008-04-29 14:45:15 +0100650 buffer = kmalloc(TI_MAX_I2C_SIZE, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 if (!buffer) {
Alan Cox2742fd82008-04-29 14:45:15 +0100652 dev_err(dev, "%s - out of memory when allocating buffer\n",
653 __func__);
654 kfree(rom_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 return -ENOMEM;
656 }
657
Alan Cox2742fd82008-04-29 14:45:15 +0100658 /* Read the first byte (Signature0) must be 0x52 or 0x10 */
659 status = read_rom(serial, 0, 1, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 if (status)
Alan Cox2742fd82008-04-29 14:45:15 +0100661 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
663 if (*buffer != UMP5152 && *buffer != UMP3410) {
Alan Cox2742fd82008-04-29 14:45:15 +0100664 dev_err(dev, "%s - invalid buffer signature\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 status = -ENODEV;
Alan Cox2742fd82008-04-29 14:45:15 +0100666 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 }
668
669 do {
Alan Cox2742fd82008-04-29 14:45:15 +0100670 /* Validate the I2C */
671 status = read_rom(serial,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 start_address,
673 sizeof(struct ti_i2c_desc),
674 (__u8 *)rom_desc);
675 if (status)
676 break;
677
Alan Cox2742fd82008-04-29 14:45:15 +0100678 if ((start_address + sizeof(struct ti_i2c_desc) +
Johan Hovold9e036f062014-04-25 15:23:03 +0200679 le16_to_cpu(rom_desc->Size)) > TI_MAX_I2C_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 status = -ENODEV;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700681 dev_dbg(dev, "%s - structure too big, erroring out.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 break;
683 }
684
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700685 dev_dbg(dev, "%s Type = 0x%x\n", __func__, rom_desc->Type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
Alan Cox2742fd82008-04-29 14:45:15 +0100687 /* Skip type 2 record */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 ttype = rom_desc->Type & 0x0f;
Alan Cox2742fd82008-04-29 14:45:15 +0100689 if (ttype != I2C_DESC_TYPE_FIRMWARE_BASIC
690 && ttype != I2C_DESC_TYPE_FIRMWARE_AUTO) {
691 /* Read the descriptor data */
692 status = read_rom(serial, start_address +
693 sizeof(struct ti_i2c_desc),
Johan Hovold9e036f062014-04-25 15:23:03 +0200694 le16_to_cpu(rom_desc->Size),
695 buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 if (status)
697 break;
698
Alan Cox2742fd82008-04-29 14:45:15 +0100699 status = valid_csum(rom_desc, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 if (status)
701 break;
702 }
Alan Cox2742fd82008-04-29 14:45:15 +0100703 start_address = start_address + sizeof(struct ti_i2c_desc) +
Johan Hovold9e036f062014-04-25 15:23:03 +0200704 le16_to_cpu(rom_desc->Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
Alan Cox2742fd82008-04-29 14:45:15 +0100706 } while ((rom_desc->Type != I2C_DESC_TYPE_ION) &&
707 (start_address < TI_MAX_I2C_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
Alan Cox2742fd82008-04-29 14:45:15 +0100709 if ((rom_desc->Type != I2C_DESC_TYPE_ION) ||
710 (start_address > TI_MAX_I2C_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 status = -ENODEV;
712
Alan Cox2742fd82008-04-29 14:45:15 +0100713out:
714 kfree(buffer);
715 kfree(rom_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 return status;
717}
718
Alan Cox2742fd82008-04-29 14:45:15 +0100719static int get_manuf_info(struct edgeport_serial *serial, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720{
721 int status;
722 int start_address;
723 struct ti_i2c_desc *rom_desc;
724 struct edge_ti_manuf_descriptor *desc;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700725 struct device *dev = &serial->serial->dev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726
Alan Cox2742fd82008-04-29 14:45:15 +0100727 rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 if (!rom_desc) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700729 dev_err(dev, "%s - out of memory\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 return -ENOMEM;
731 }
Alan Cox2742fd82008-04-29 14:45:15 +0100732 start_address = get_descriptor_addr(serial, I2C_DESC_TYPE_ION,
733 rom_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
735 if (!start_address) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700736 dev_dbg(dev, "%s - Edge Descriptor not found in I2C\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 status = -ENODEV;
738 goto exit;
739 }
740
Alan Cox2742fd82008-04-29 14:45:15 +0100741 /* Read the descriptor data */
742 status = read_rom(serial, start_address+sizeof(struct ti_i2c_desc),
Johan Hovold9e036f062014-04-25 15:23:03 +0200743 le16_to_cpu(rom_desc->Size), buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 if (status)
745 goto exit;
Alan Cox2742fd82008-04-29 14:45:15 +0100746
747 status = valid_csum(rom_desc, buffer);
748
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 desc = (struct edge_ti_manuf_descriptor *)buffer;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700750 dev_dbg(dev, "%s - IonConfig 0x%x\n", __func__, desc->IonConfig);
751 dev_dbg(dev, "%s - Version %d\n", __func__, desc->Version);
752 dev_dbg(dev, "%s - Cpu/Board 0x%x\n", __func__, desc->CpuRev_BoardRev);
753 dev_dbg(dev, "%s - NumPorts %d\n", __func__, desc->NumPorts);
754 dev_dbg(dev, "%s - NumVirtualPorts %d\n", __func__, desc->NumVirtualPorts);
755 dev_dbg(dev, "%s - TotalPorts %d\n", __func__, desc->TotalPorts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
757exit:
Alan Cox2742fd82008-04-29 14:45:15 +0100758 kfree(rom_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 return status;
760}
761
762/* Build firmware header used for firmware update */
Alan Cox2742fd82008-04-29 14:45:15 +0100763static int build_i2c_fw_hdr(__u8 *header, struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764{
765 __u8 *buffer;
766 int buffer_size;
767 int i;
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530768 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 __u8 cs = 0;
770 struct ti_i2c_desc *i2c_header;
771 struct ti_i2c_image_header *img_header;
772 struct ti_i2c_firmware_rec *firmware_rec;
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530773 const struct firmware *fw;
774 const char *fw_name = "edgeport/down3.bin";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
Alan Cox2742fd82008-04-29 14:45:15 +0100776 /* In order to update the I2C firmware we must change the type 2 record
777 * to type 0xF2. This will force the UMP to come up in Boot Mode.
778 * Then while in boot mode, the driver will download the latest
779 * firmware (padded to 15.5k) into the UMP ram. And finally when the
780 * device comes back up in download mode the driver will cause the new
781 * firmware to be copied from the UMP Ram to I2C and the firmware will
782 * update the record type from 0xf2 to 0x02.
783 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
Alan Cox2742fd82008-04-29 14:45:15 +0100785 /* Allocate a 15.5k buffer + 2 bytes for version number
786 * (Firmware Record) */
787 buffer_size = (((1024 * 16) - 512 ) +
788 sizeof(struct ti_i2c_firmware_rec));
789
790 buffer = kmalloc(buffer_size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 if (!buffer) {
Alan Cox2742fd82008-04-29 14:45:15 +0100792 dev_err(dev, "%s - out of memory\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 return -ENOMEM;
794 }
Alan Cox2742fd82008-04-29 14:45:15 +0100795
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 // Set entire image of 0xffs
Alan Cox2742fd82008-04-29 14:45:15 +0100797 memset(buffer, 0xff, buffer_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530799 err = request_firmware(&fw, fw_name, dev);
800 if (err) {
Greg Kroah-Hartmand9bb03d2012-09-18 16:59:23 +0100801 dev_err(dev, "Failed to load image \"%s\" err %d\n",
802 fw_name, err);
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530803 kfree(buffer);
804 return err;
805 }
806
807 /* Save Download Version Number */
808 OperationalMajorVersion = fw->data[0];
809 OperationalMinorVersion = fw->data[1];
810 OperationalBuildNumber = fw->data[2] | (fw->data[3] << 8);
811
Alan Cox2742fd82008-04-29 14:45:15 +0100812 /* Copy version number into firmware record */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 firmware_rec = (struct ti_i2c_firmware_rec *)buffer;
814
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530815 firmware_rec->Ver_Major = OperationalMajorVersion;
816 firmware_rec->Ver_Minor = OperationalMinorVersion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Alan Cox2742fd82008-04-29 14:45:15 +0100818 /* Pointer to fw_down memory image */
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530819 img_header = (struct ti_i2c_image_header *)&fw->data[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
Alan Cox2742fd82008-04-29 14:45:15 +0100821 memcpy(buffer + sizeof(struct ti_i2c_firmware_rec),
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530822 &fw->data[4 + sizeof(struct ti_i2c_image_header)],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 le16_to_cpu(img_header->Length));
824
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530825 release_firmware(fw);
826
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 for (i=0; i < buffer_size; i++) {
828 cs = (__u8)(cs + buffer[i]);
829 }
830
Alan Cox2742fd82008-04-29 14:45:15 +0100831 kfree(buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
Alan Cox2742fd82008-04-29 14:45:15 +0100833 /* Build new header */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 i2c_header = (struct ti_i2c_desc *)header;
835 firmware_rec = (struct ti_i2c_firmware_rec*)i2c_header->Data;
Alan Cox2742fd82008-04-29 14:45:15 +0100836
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 i2c_header->Type = I2C_DESC_TYPE_FIRMWARE_BLANK;
Johan Hovoldd7ecf012014-04-26 11:53:44 +0200838 i2c_header->Size = cpu_to_le16(buffer_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 i2c_header->CheckSum = cs;
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530840 firmware_rec->Ver_Major = OperationalMajorVersion;
841 firmware_rec->Ver_Minor = OperationalMinorVersion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 return 0;
844}
845
846/* Try to figure out what type of I2c we have */
Alan Cox2742fd82008-04-29 14:45:15 +0100847static int i2c_type_bootmode(struct edgeport_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848{
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700849 struct device *dev = &serial->serial->dev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 int status;
Johan Hovolde9305d22009-12-28 23:01:50 +0100851 u8 *data;
852
853 data = kmalloc(1, GFP_KERNEL);
854 if (!data) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700855 dev_err(dev, "%s - out of memory\n", __func__);
Johan Hovolde9305d22009-12-28 23:01:50 +0100856 return -ENOMEM;
857 }
Alan Cox2742fd82008-04-29 14:45:15 +0100858
859 /* Try to read type 2 */
860 status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ,
Johan Hovolde9305d22009-12-28 23:01:50 +0100861 DTK_ADDR_SPACE_I2C_TYPE_II, 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 2 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_II\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
Johan Hovolde9305d22009-12-28 23:01:50 +0100869 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 }
871
Alan Cox2742fd82008-04-29 14:45:15 +0100872 /* Try to read type 3 */
873 status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ,
Johan Hovolde9305d22009-12-28 23:01:50 +0100874 DTK_ADDR_SPACE_I2C_TYPE_III, 0, data, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 if (status)
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700876 dev_dbg(dev, "%s - read 3 status error = %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 else
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700878 dev_dbg(dev, "%s - read 2 data = 0x%x\n", __func__, *data);
Johan Hovolde9305d22009-12-28 23:01:50 +0100879 if ((!status) && (*data == UMP5152 || *data == UMP3410)) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700880 dev_dbg(dev, "%s - ROM_TYPE_III\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_III;
Johan Hovolde9305d22009-12-28 23:01:50 +0100882 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 }
884
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700885 dev_dbg(dev, "%s - Unknown\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
Johan Hovolde9305d22009-12-28 23:01:50 +0100887 status = -ENODEV;
888out:
889 kfree(data);
890 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891}
892
Alan Cox2742fd82008-04-29 14:45:15 +0100893static int bulk_xfer(struct usb_serial *serial, void *buffer,
894 int length, int *num_sent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895{
896 int status;
897
Alan Cox2742fd82008-04-29 14:45:15 +0100898 status = usb_bulk_msg(serial->dev,
899 usb_sndbulkpipe(serial->dev,
900 serial->port[0]->bulk_out_endpointAddress),
901 buffer, length, num_sent, 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 return status;
903}
904
905/* Download given firmware image to the device (IN BOOT MODE) */
Alan Cox2742fd82008-04-29 14:45:15 +0100906static int download_code(struct edgeport_serial *serial, __u8 *image,
907 int image_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908{
909 int status = 0;
910 int pos;
911 int transfer;
912 int done;
913
Alan Cox2742fd82008-04-29 14:45:15 +0100914 /* Transfer firmware image */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 for (pos = 0; pos < image_length; ) {
Alan Cox2742fd82008-04-29 14:45:15 +0100916 /* Read the next buffer from file */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 transfer = image_length - pos;
918 if (transfer > EDGE_FW_BULK_MAX_PACKET_SIZE)
919 transfer = EDGE_FW_BULK_MAX_PACKET_SIZE;
920
Alan Cox2742fd82008-04-29 14:45:15 +0100921 /* Transfer data */
922 status = bulk_xfer(serial->serial, &image[pos],
923 transfer, &done);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 if (status)
925 break;
Alan Cox2742fd82008-04-29 14:45:15 +0100926 /* Advance buffer pointer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 pos += done;
928 }
929
930 return status;
931}
932
Alan Cox2742fd82008-04-29 14:45:15 +0100933/* FIXME!!! */
934static int config_boot_dev(struct usb_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935{
936 return 0;
937}
938
Alan Cox2742fd82008-04-29 14:45:15 +0100939static int ti_cpu_rev(struct edge_ti_manuf_descriptor *desc)
940{
941 return TI_GET_CPU_REVISION(desc->CpuRev_BoardRev);
942}
943
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944/**
945 * DownloadTIFirmware - Download run-time operating firmware to the TI5052
Alan Cox2742fd82008-04-29 14:45:15 +0100946 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 * This routine downloads the main operating code into the TI5052, using the
948 * boot code already burned into E2PROM or ROM.
949 */
Alan Cox2742fd82008-04-29 14:45:15 +0100950static int download_fw(struct edgeport_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951{
952 struct device *dev = &serial->serial->dev->dev;
953 int status = 0;
954 int start_address;
955 struct edge_ti_manuf_descriptor *ti_manuf_desc;
956 struct usb_interface_descriptor *interface;
957 int download_cur_ver;
958 int download_new_ver;
959
960 /* This routine is entered by both the BOOT mode and the Download mode
961 * We can determine which code is running by the reading the config
962 * descriptor and if we have only one bulk pipe it is in boot mode
963 */
964 serial->product_info.hardware_type = HARDWARE_TYPE_TIUMP;
965
966 /* Default to type 2 i2c */
967 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
968
Alan Cox2742fd82008-04-29 14:45:15 +0100969 status = choose_config(serial->serial->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 if (status)
971 return status;
972
973 interface = &serial->serial->interface->cur_altsetting->desc;
974 if (!interface) {
Alan Cox2742fd82008-04-29 14:45:15 +0100975 dev_err(dev, "%s - no interface set, error!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 return -ENODEV;
977 }
978
Alan Cox2742fd82008-04-29 14:45:15 +0100979 /*
980 * Setup initial mode -- the default mode 0 is TI_MODE_CONFIGURING
981 * if we have more than one endpoint we are definitely in download
982 * mode
983 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 if (interface->bNumEndpoints > 1)
985 serial->product_info.TiMode = TI_MODE_DOWNLOAD;
986 else
Alan Cox2742fd82008-04-29 14:45:15 +0100987 /* Otherwise we will remain in configuring mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 serial->product_info.TiMode = TI_MODE_CONFIGURING;
989
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 /********************************************************************/
991 /* Download Mode */
992 /********************************************************************/
993 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) {
994 struct ti_i2c_desc *rom_desc;
995
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700996 dev_dbg(dev, "%s - RUNNING IN DOWNLOAD MODE\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
Alan Cox2742fd82008-04-29 14:45:15 +0100998 status = check_i2c_image(serial);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 if (status) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001000 dev_dbg(dev, "%s - DOWNLOAD MODE -- BAD I2C\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 return status;
1002 }
Alan Cox2742fd82008-04-29 14:45:15 +01001003
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 /* Validate Hardware version number
1005 * Read Manufacturing Descriptor from TI Based Edgeport
1006 */
Alan Cox2742fd82008-04-29 14:45:15 +01001007 ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 if (!ti_manuf_desc) {
Alan Cox2742fd82008-04-29 14:45:15 +01001009 dev_err(dev, "%s - out of memory.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 return -ENOMEM;
1011 }
Alan Cox2742fd82008-04-29 14:45:15 +01001012 status = get_manuf_info(serial, (__u8 *)ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001014 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 return status;
1016 }
1017
Alan Cox2742fd82008-04-29 14:45:15 +01001018 /* Check version number of ION descriptor */
1019 if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001020 dev_dbg(dev, "%s - Wrong CPU Rev %d (Must be 2)\n",
Alan Cox2742fd82008-04-29 14:45:15 +01001021 __func__, ti_cpu_rev(ti_manuf_desc));
1022 kfree(ti_manuf_desc);
1023 return -EINVAL;
1024 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025
Alan Cox2742fd82008-04-29 14:45:15 +01001026 rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 if (!rom_desc) {
Alan Cox2742fd82008-04-29 14:45:15 +01001028 dev_err(dev, "%s - out of memory.\n", __func__);
1029 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 return -ENOMEM;
1031 }
1032
Alan Cox2742fd82008-04-29 14:45:15 +01001033 /* Search for type 2 record (firmware record) */
1034 start_address = get_descriptor_addr(serial,
1035 I2C_DESC_TYPE_FIRMWARE_BASIC, rom_desc);
1036 if (start_address != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 struct ti_i2c_firmware_rec *firmware_version;
Johan Hovolde9305d22009-12-28 23:01:50 +01001038 u8 *record;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001040 dev_dbg(dev, "%s - Found Type FIRMWARE (Type 2) record\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041
Alan Cox2742fd82008-04-29 14:45:15 +01001042 firmware_version = kmalloc(sizeof(*firmware_version),
1043 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 if (!firmware_version) {
Alan Cox2742fd82008-04-29 14:45:15 +01001045 dev_err(dev, "%s - out of memory.\n", __func__);
1046 kfree(rom_desc);
1047 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 return -ENOMEM;
1049 }
1050
Alan Cox2742fd82008-04-29 14:45:15 +01001051 /* Validate version number
1052 * Read the descriptor data
1053 */
1054 status = read_rom(serial, start_address +
1055 sizeof(struct ti_i2c_desc),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 sizeof(struct ti_i2c_firmware_rec),
1057 (__u8 *)firmware_version);
1058 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001059 kfree(firmware_version);
1060 kfree(rom_desc);
1061 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 return status;
1063 }
1064
Alan Cox2742fd82008-04-29 14:45:15 +01001065 /* Check version number of download with current
1066 version in I2c */
1067 download_cur_ver = (firmware_version->Ver_Major << 8) +
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 (firmware_version->Ver_Minor);
Jaswinder Singhd12b2192008-07-04 23:06:09 +05301069 download_new_ver = (OperationalMajorVersion << 8) +
1070 (OperationalMinorVersion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001072 dev_dbg(dev, "%s - >> FW Versions Device %d.%d Driver %d.%d\n",
1073 __func__, firmware_version->Ver_Major,
1074 firmware_version->Ver_Minor,
1075 OperationalMajorVersion,
1076 OperationalMinorVersion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
Alan Cox2742fd82008-04-29 14:45:15 +01001078 /* Check if we have an old version in the I2C and
1079 update if necessary */
Greg Kroah-Hartman0827a9f2010-08-17 15:15:37 -07001080 if (download_cur_ver < download_new_ver) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001081 dev_dbg(dev, "%s - Update I2C dld from %d.%d to %d.%d\n",
1082 __func__,
1083 firmware_version->Ver_Major,
1084 firmware_version->Ver_Minor,
1085 OperationalMajorVersion,
1086 OperationalMinorVersion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
Johan Hovolde9305d22009-12-28 23:01:50 +01001088 record = kmalloc(1, GFP_KERNEL);
1089 if (!record) {
1090 dev_err(dev, "%s - out of memory.\n",
1091 __func__);
1092 kfree(firmware_version);
1093 kfree(rom_desc);
1094 kfree(ti_manuf_desc);
1095 return -ENOMEM;
1096 }
Alan Cox2742fd82008-04-29 14:45:15 +01001097 /* In order to update the I2C firmware we must
1098 * change the type 2 record to type 0xF2. This
1099 * will force the UMP to come up in Boot Mode.
1100 * Then while in boot mode, the driver will
1101 * download the latest firmware (padded to
1102 * 15.5k) into the UMP ram. Finally when the
1103 * device comes back up in download mode the
1104 * driver will cause the new firmware to be
1105 * copied from the UMP Ram to I2C and the
1106 * firmware will update the record type from
1107 * 0xf2 to 0x02.
1108 */
Johan Hovolde9305d22009-12-28 23:01:50 +01001109 *record = I2C_DESC_TYPE_FIRMWARE_BLANK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110
Alan Cox2742fd82008-04-29 14:45:15 +01001111 /* Change the I2C Firmware record type to
1112 0xf2 to trigger an update */
1113 status = write_rom(serial, start_address,
Johan Hovolde9305d22009-12-28 23:01:50 +01001114 sizeof(*record), record);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 if (status) {
Johan Hovolde9305d22009-12-28 23:01:50 +01001116 kfree(record);
Alan Cox2742fd82008-04-29 14:45:15 +01001117 kfree(firmware_version);
1118 kfree(rom_desc);
1119 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 return status;
1121 }
1122
Alan Cox2742fd82008-04-29 14:45:15 +01001123 /* verify the write -- must do this in order
1124 * for write to complete before we do the
1125 * hardware reset
1126 */
1127 status = read_rom(serial,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 start_address,
Johan Hovolde9305d22009-12-28 23:01:50 +01001129 sizeof(*record),
1130 record);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 if (status) {
Johan Hovolde9305d22009-12-28 23:01:50 +01001132 kfree(record);
Alan Cox2742fd82008-04-29 14:45:15 +01001133 kfree(firmware_version);
1134 kfree(rom_desc);
1135 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 return status;
1137 }
1138
Johan Hovolde9305d22009-12-28 23:01:50 +01001139 if (*record != I2C_DESC_TYPE_FIRMWARE_BLANK) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001140 dev_err(dev, "%s - error resetting device\n", __func__);
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 }
1147
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001148 dev_dbg(dev, "%s - HARDWARE RESET\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
Alan Cox2742fd82008-04-29 14:45:15 +01001150 /* Reset UMP -- Back to BOOT MODE */
1151 status = ti_vsend_sync(serial->serial->dev,
1152 UMPC_HARDWARE_RESET,
1153 0, 0, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001155 dev_dbg(dev, "%s - HARDWARE RESET return %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
1157 /* return an error on purpose. */
Johan Hovolde9305d22009-12-28 23:01:50 +01001158 kfree(record);
Alan Cox2742fd82008-04-29 14:45:15 +01001159 kfree(firmware_version);
1160 kfree(rom_desc);
1161 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 return -ENODEV;
1163 }
Alan Cox2742fd82008-04-29 14:45:15 +01001164 kfree(firmware_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 }
Alan Cox2742fd82008-04-29 14:45:15 +01001166 /* Search for type 0xF2 record (firmware blank record) */
1167 else if ((start_address = get_descriptor_addr(serial, I2C_DESC_TYPE_FIRMWARE_BLANK, rom_desc)) != 0) {
1168#define HEADER_SIZE (sizeof(struct ti_i2c_desc) + \
1169 sizeof(struct ti_i2c_firmware_rec))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 __u8 *header;
1171 __u8 *vheader;
1172
Alan Cox2742fd82008-04-29 14:45:15 +01001173 header = kmalloc(HEADER_SIZE, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 if (!header) {
Alan Cox2742fd82008-04-29 14:45:15 +01001175 dev_err(dev, "%s - out of memory.\n", __func__);
1176 kfree(rom_desc);
1177 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 return -ENOMEM;
1179 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
Alan Cox2742fd82008-04-29 14:45:15 +01001181 vheader = kmalloc(HEADER_SIZE, GFP_KERNEL);
1182 if (!vheader) {
1183 dev_err(dev, "%s - out of memory.\n", __func__);
1184 kfree(header);
1185 kfree(rom_desc);
1186 kfree(ti_manuf_desc);
1187 return -ENOMEM;
1188 }
1189
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001190 dev_dbg(dev, "%s - Found Type BLANK FIRMWARE (Type F2) record\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01001191
1192 /*
1193 * In order to update the I2C firmware we must change
1194 * the type 2 record to type 0xF2. This will force the
1195 * UMP to come up in Boot Mode. Then while in boot
1196 * mode, the driver will download the latest firmware
1197 * (padded to 15.5k) into the UMP ram. Finally when the
1198 * device comes back up in download mode the driver
1199 * will cause the new firmware to be copied from the
1200 * UMP Ram to I2C and the firmware will update the
1201 * record type from 0xf2 to 0x02.
1202 */
1203 status = build_i2c_fw_hdr(header, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001205 kfree(vheader);
1206 kfree(header);
1207 kfree(rom_desc);
1208 kfree(ti_manuf_desc);
Roel Kluinfd6e5bb2010-08-10 14:29:19 -07001209 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 }
1211
Alan Cox2742fd82008-04-29 14:45:15 +01001212 /* Update I2C with type 0xf2 record with correct
1213 size and checksum */
1214 status = write_rom(serial,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 start_address,
1216 HEADER_SIZE,
1217 header);
1218 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001219 kfree(vheader);
1220 kfree(header);
1221 kfree(rom_desc);
1222 kfree(ti_manuf_desc);
Roel Kluin9800eb32010-07-20 15:29:08 -07001223 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 }
1225
Alan Cox2742fd82008-04-29 14:45:15 +01001226 /* verify the write -- must do this in order for
1227 write to complete before we do the hardware reset */
1228 status = read_rom(serial, start_address,
1229 HEADER_SIZE, vheader);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
1231 if (status) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001232 dev_dbg(dev, "%s - can't read header back\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01001233 kfree(vheader);
1234 kfree(header);
1235 kfree(rom_desc);
1236 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 return status;
1238 }
1239 if (memcmp(vheader, header, HEADER_SIZE)) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001240 dev_dbg(dev, "%s - write download record failed\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01001241 kfree(vheader);
1242 kfree(header);
1243 kfree(rom_desc);
1244 kfree(ti_manuf_desc);
Roel Kluin1e297092010-07-02 00:36:43 +02001245 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 }
1247
Alan Cox2742fd82008-04-29 14:45:15 +01001248 kfree(vheader);
1249 kfree(header);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001251 dev_dbg(dev, "%s - Start firmware update\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
Alan Cox2742fd82008-04-29 14:45:15 +01001253 /* Tell firmware to copy download image into I2C */
1254 status = ti_vsend_sync(serial->serial->dev,
1255 UMPC_COPY_DNLD_TO_I2C, 0, 0, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001257 dev_dbg(dev, "%s - Update complete 0x%x\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001259 dev_err(dev,
1260 "%s - UMPC_COPY_DNLD_TO_I2C failed\n",
1261 __func__);
1262 kfree(rom_desc);
1263 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 return status;
1265 }
1266 }
1267
1268 // The device is running the download code
Alan Cox2742fd82008-04-29 14:45:15 +01001269 kfree(rom_desc);
1270 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 return 0;
1272 }
1273
1274 /********************************************************************/
1275 /* Boot Mode */
1276 /********************************************************************/
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001277 dev_dbg(dev, "%s - RUNNING IN BOOT MODE\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
Alan Cox2742fd82008-04-29 14:45:15 +01001279 /* Configure the TI device so we can use the BULK pipes for download */
1280 status = config_boot_dev(serial->serial->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 if (status)
1282 return status;
1283
Alan Cox2742fd82008-04-29 14:45:15 +01001284 if (le16_to_cpu(serial->serial->dev->descriptor.idVendor)
1285 != USB_VENDOR_ID_ION) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001286 dev_dbg(dev, "%s - VID = 0x%x\n", __func__,
1287 le16_to_cpu(serial->serial->dev->descriptor.idVendor));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
Alan Cox2742fd82008-04-29 14:45:15 +01001289 goto stayinbootmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 }
1291
Alan Cox2742fd82008-04-29 14:45:15 +01001292 /* We have an ION device (I2c Must be programmed)
1293 Determine I2C image type */
1294 if (i2c_type_bootmode(serial))
1295 goto stayinbootmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
Alan Cox2742fd82008-04-29 14:45:15 +01001297 /* Check for ION Vendor ID and that the I2C is valid */
1298 if (!check_i2c_image(serial)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 struct ti_i2c_image_header *header;
1300 int i;
1301 __u8 cs = 0;
1302 __u8 *buffer;
1303 int buffer_size;
Jaswinder Singhd12b2192008-07-04 23:06:09 +05301304 int err;
1305 const struct firmware *fw;
1306 const char *fw_name = "edgeport/down3.bin";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307
1308 /* Validate Hardware version number
1309 * Read Manufacturing Descriptor from TI Based Edgeport
1310 */
Alan Cox2742fd82008-04-29 14:45:15 +01001311 ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 if (!ti_manuf_desc) {
Alan Cox2742fd82008-04-29 14:45:15 +01001313 dev_err(dev, "%s - out of memory.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 return -ENOMEM;
1315 }
Alan Cox2742fd82008-04-29 14:45:15 +01001316 status = get_manuf_info(serial, (__u8 *)ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001318 kfree(ti_manuf_desc);
1319 goto stayinbootmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 }
1321
Alan Cox2742fd82008-04-29 14:45:15 +01001322 /* Check for version 2 */
1323 if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001324 dev_dbg(dev, "%s - Wrong CPU Rev %d (Must be 2)\n",
1325 __func__, ti_cpu_rev(ti_manuf_desc));
Alan Cox2742fd82008-04-29 14:45:15 +01001326 kfree(ti_manuf_desc);
1327 goto stayinbootmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 }
1329
Alan Cox2742fd82008-04-29 14:45:15 +01001330 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 /*
Alan Cox2742fd82008-04-29 14:45:15 +01001333 * In order to update the I2C firmware we must change the type
1334 * 2 record to type 0xF2. This will force the UMP to come up
1335 * in Boot Mode. Then while in boot mode, the driver will
1336 * download the latest firmware (padded to 15.5k) into the
1337 * UMP ram. Finally when the device comes back up in download
1338 * mode the driver will cause the new firmware to be copied
1339 * from the UMP Ram to I2C and the firmware will update the
1340 * record type from 0xf2 to 0x02.
1341 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 * Do we really have to copy the whole firmware image,
1343 * or could we do this in place!
1344 */
1345
Alan Cox2742fd82008-04-29 14:45:15 +01001346 /* Allocate a 15.5k buffer + 3 byte header */
1347 buffer_size = (((1024 * 16) - 512) +
1348 sizeof(struct ti_i2c_image_header));
1349 buffer = kmalloc(buffer_size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 if (!buffer) {
Alan Cox2742fd82008-04-29 14:45:15 +01001351 dev_err(dev, "%s - out of memory\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 return -ENOMEM;
1353 }
Alan Cox2742fd82008-04-29 14:45:15 +01001354
1355 /* Initialize the buffer to 0xff (pad the buffer) */
1356 memset(buffer, 0xff, buffer_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
Jaswinder Singhd12b2192008-07-04 23:06:09 +05301358 err = request_firmware(&fw, fw_name, dev);
1359 if (err) {
Greg Kroah-Hartmand9bb03d2012-09-18 16:59:23 +01001360 dev_err(dev, "Failed to load image \"%s\" err %d\n",
1361 fw_name, err);
Jaswinder Singhd12b2192008-07-04 23:06:09 +05301362 kfree(buffer);
1363 return err;
1364 }
1365 memcpy(buffer, &fw->data[4], fw->size - 4);
1366 release_firmware(fw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367
Alan Cox2742fd82008-04-29 14:45:15 +01001368 for (i = sizeof(struct ti_i2c_image_header);
1369 i < buffer_size; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 cs = (__u8)(cs + buffer[i]);
1371 }
Alan Cox2742fd82008-04-29 14:45:15 +01001372
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 header = (struct ti_i2c_image_header *)buffer;
Alan Cox2742fd82008-04-29 14:45:15 +01001374
1375 /* update length and checksum after padding */
1376 header->Length = cpu_to_le16((__u16)(buffer_size -
1377 sizeof(struct ti_i2c_image_header)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 header->CheckSum = cs;
1379
Alan Cox2742fd82008-04-29 14:45:15 +01001380 /* Download the operational code */
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001381 dev_dbg(dev, "%s - Downloading operational code image (TI UMP)\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01001382 status = download_code(serial, buffer, buffer_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383
Alan Cox2742fd82008-04-29 14:45:15 +01001384 kfree(buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
1386 if (status) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001387 dev_dbg(dev, "%s - Error downloading operational code image\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 return status;
1389 }
1390
Alan Cox2742fd82008-04-29 14:45:15 +01001391 /* Device will reboot */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 serial->product_info.TiMode = TI_MODE_TRANSITIONING;
1393
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001394 dev_dbg(dev, "%s - Download successful -- Device rebooting...\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395
1396 /* return an error on purpose */
1397 return -ENODEV;
1398 }
1399
Alan Cox2742fd82008-04-29 14:45:15 +01001400stayinbootmode:
1401 /* Eprom is invalid or blank stay in boot mode */
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001402 dev_dbg(dev, "%s - STAYING IN BOOT MODE\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 serial->product_info.TiMode = TI_MODE_BOOT;
1404
1405 return 0;
1406}
1407
1408
Alan Cox2742fd82008-04-29 14:45:15 +01001409static int ti_do_config(struct edgeport_port *port, int feature, int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410{
1411 int port_number = port->port->number - port->port->serial->minor;
Alan Cox2742fd82008-04-29 14:45:15 +01001412 on = !!on; /* 1 or 0 not bitmask */
1413 return send_cmd(port->port->serial->dev,
1414 feature, (__u8)(UMPM_UART1_PORT + port_number),
1415 on, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416}
1417
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Alan Cox2742fd82008-04-29 14:45:15 +01001419static int restore_mcr(struct edgeport_port *port, __u8 mcr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420{
1421 int status = 0;
1422
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001423 dev_dbg(&port->port->dev, "%s - %x\n", __func__, mcr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
Alan Cox2742fd82008-04-29 14:45:15 +01001425 status = ti_do_config(port, UMPC_SET_CLR_DTR, mcr & MCR_DTR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 if (status)
1427 return status;
Alan Cox2742fd82008-04-29 14:45:15 +01001428 status = ti_do_config(port, UMPC_SET_CLR_RTS, mcr & MCR_RTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 if (status)
1430 return status;
Alan Cox2742fd82008-04-29 14:45:15 +01001431 return ti_do_config(port, UMPC_SET_CLR_LOOPBACK, mcr & MCR_LOOPBACK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432}
1433
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434/* Convert TI LSR to standard UART flags */
Alan Cox2742fd82008-04-29 14:45:15 +01001435static __u8 map_line_status(__u8 ti_lsr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436{
1437 __u8 lsr = 0;
1438
1439#define MAP_FLAG(flagUmp, flagUart) \
1440 if (ti_lsr & flagUmp) \
1441 lsr |= flagUart;
1442
1443 MAP_FLAG(UMP_UART_LSR_OV_MASK, LSR_OVER_ERR) /* overrun */
1444 MAP_FLAG(UMP_UART_LSR_PE_MASK, LSR_PAR_ERR) /* parity error */
1445 MAP_FLAG(UMP_UART_LSR_FE_MASK, LSR_FRM_ERR) /* framing error */
1446 MAP_FLAG(UMP_UART_LSR_BR_MASK, LSR_BREAK) /* break detected */
Alan Cox2742fd82008-04-29 14:45:15 +01001447 MAP_FLAG(UMP_UART_LSR_RX_MASK, LSR_RX_AVAIL) /* rx data available */
1448 MAP_FLAG(UMP_UART_LSR_TX_MASK, LSR_TX_EMPTY) /* tx hold reg empty */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449
1450#undef MAP_FLAG
1451
1452 return lsr;
1453}
1454
Alan Cox2742fd82008-04-29 14:45:15 +01001455static void handle_new_msr(struct edgeport_port *edge_port, __u8 msr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456{
1457 struct async_icount *icount;
1458 struct tty_struct *tty;
1459
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001460 dev_dbg(&edge_port->port->dev, "%s - %02x\n", __func__, msr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
Alan Cox2742fd82008-04-29 14:45:15 +01001462 if (msr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR |
1463 EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) {
Johan Hovoldcf9a9d62013-03-21 12:37:09 +01001464 icount = &edge_port->port->icount;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465
1466 /* update input line counters */
1467 if (msr & EDGEPORT_MSR_DELTA_CTS)
1468 icount->cts++;
1469 if (msr & EDGEPORT_MSR_DELTA_DSR)
1470 icount->dsr++;
1471 if (msr & EDGEPORT_MSR_DELTA_CD)
1472 icount->dcd++;
1473 if (msr & EDGEPORT_MSR_DELTA_RI)
1474 icount->rng++;
Johan Hovold48ee5802013-03-21 12:37:10 +01001475 wake_up_interruptible(&edge_port->port->port.delta_msr_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 }
1477
1478 /* Save the new modem status */
1479 edge_port->shadow_msr = msr & 0xf0;
1480
Alan Cox4a90f092008-10-13 10:39:46 +01001481 tty = tty_port_tty_get(&edge_port->port->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 /* handle CTS flow control */
1483 if (tty && C_CRTSCTS(tty)) {
1484 if (msr & EDGEPORT_MSR_CTS) {
1485 tty->hw_stopped = 0;
1486 tty_wakeup(tty);
1487 } else {
1488 tty->hw_stopped = 1;
1489 }
1490 }
Alan Cox4a90f092008-10-13 10:39:46 +01001491 tty_kref_put(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492}
1493
Alan Cox2742fd82008-04-29 14:45:15 +01001494static void handle_new_lsr(struct edgeport_port *edge_port, int lsr_data,
1495 __u8 lsr, __u8 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496{
1497 struct async_icount *icount;
Alan Cox2742fd82008-04-29 14:45:15 +01001498 __u8 new_lsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR |
1499 LSR_FRM_ERR | LSR_BREAK));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001501 dev_dbg(&edge_port->port->dev, "%s - %02x\n", __func__, new_lsr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502
1503 edge_port->shadow_lsr = lsr;
1504
Alan Cox2742fd82008-04-29 14:45:15 +01001505 if (new_lsr & LSR_BREAK)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 /*
1507 * Parity and Framing errors only count if they
1508 * occur exclusive of a break being received.
1509 */
1510 new_lsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511
1512 /* Place LSR data byte into Rx buffer */
Jiri Slaby2e124b42013-01-03 15:53:06 +01001513 if (lsr_data)
1514 edge_tty_recv(edge_port->port, &data, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515
1516 /* update input line counters */
Johan Hovoldcf9a9d62013-03-21 12:37:09 +01001517 icount = &edge_port->port->icount;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 if (new_lsr & LSR_BREAK)
1519 icount->brk++;
1520 if (new_lsr & LSR_OVER_ERR)
1521 icount->overrun++;
1522 if (new_lsr & LSR_PAR_ERR)
1523 icount->parity++;
1524 if (new_lsr & LSR_FRM_ERR)
1525 icount->frame++;
1526}
1527
1528
Alan Cox2742fd82008-04-29 14:45:15 +01001529static void edge_interrupt_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530{
Ming Leicdc97792008-02-24 18:41:47 +08001531 struct edgeport_serial *edge_serial = urb->context;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 struct usb_serial_port *port;
1533 struct edgeport_port *edge_port;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001534 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 unsigned char *data = urb->transfer_buffer;
1536 int length = urb->actual_length;
1537 int port_number;
1538 int function;
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001539 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 __u8 lsr;
1541 __u8 msr;
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001542 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001544 switch (status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 case 0:
1546 /* success */
1547 break;
1548 case -ECONNRESET:
1549 case -ENOENT:
1550 case -ESHUTDOWN:
1551 /* this urb is terminated, clean up */
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001552 dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -08001553 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 return;
1555 default:
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001556 dev_err(&urb->dev->dev, "%s - nonzero urb status received: "
Harvey Harrison441b62c2008-03-03 16:08:34 -08001557 "%d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 goto exit;
1559 }
1560
1561 if (!length) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001562 dev_dbg(&urb->dev->dev, "%s - no data in urb\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 goto exit;
1564 }
1565
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001566 dev = &edge_serial->serial->dev->dev;
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +01001567 usb_serial_debug_data(dev, __func__, length, data);
Alan Cox2742fd82008-04-29 14:45:15 +01001568
1569 if (length != 2) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001570 dev_dbg(dev, "%s - expecting packet of size 2, got %d\n", __func__, length);
Alan Cox2742fd82008-04-29 14:45:15 +01001571 goto exit;
1572 }
1573
1574 port_number = TIUMP_GET_PORT_FROM_CODE(data[0]);
1575 function = TIUMP_GET_FUNC_FROM_CODE(data[0]);
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001576 dev_dbg(dev, "%s - port_number %d, function %d, info 0x%x\n", __func__,
1577 port_number, function, data[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 port = edge_serial->serial->port[port_number];
1579 edge_port = usb_get_serial_port_data(port);
1580 if (!edge_port) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001581 dev_dbg(dev, "%s - edge_port not found\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 return;
1583 }
1584 switch (function) {
1585 case TIUMP_INTERRUPT_CODE_LSR:
Alan Cox2742fd82008-04-29 14:45:15 +01001586 lsr = map_line_status(data[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 if (lsr & UMP_UART_LSR_DATA_MASK) {
Alan Cox2742fd82008-04-29 14:45:15 +01001588 /* Save the LSR event for bulk read
1589 completion routine */
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001590 dev_dbg(dev, "%s - LSR Event Port %u LSR Status = %02x\n",
1591 __func__, port_number, lsr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 edge_port->lsr_event = 1;
1593 edge_port->lsr_mask = lsr;
1594 } else {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001595 dev_dbg(dev, "%s - ===== Port %d LSR Status = %02x ======\n",
1596 __func__, port_number, lsr);
Alan Cox2742fd82008-04-29 14:45:15 +01001597 handle_new_lsr(edge_port, 0, lsr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 }
1599 break;
1600
Alan Cox2742fd82008-04-29 14:45:15 +01001601 case TIUMP_INTERRUPT_CODE_MSR: /* MSR */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 /* Copy MSR from UMP */
1603 msr = data[1];
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001604 dev_dbg(dev, "%s - ===== Port %u MSR Status = %02x ======\n",
1605 __func__, port_number, msr);
Alan Cox2742fd82008-04-29 14:45:15 +01001606 handle_new_msr(edge_port, msr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 break;
1608
1609 default:
Alan Cox2742fd82008-04-29 14:45:15 +01001610 dev_err(&urb->dev->dev,
1611 "%s - Unknown Interrupt code from UMP %x\n",
1612 __func__, data[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 break;
Alan Cox2742fd82008-04-29 14:45:15 +01001614
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 }
1616
1617exit:
Alan Cox2742fd82008-04-29 14:45:15 +01001618 retval = usb_submit_urb(urb, GFP_ATOMIC);
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001619 if (retval)
Alan Cox2742fd82008-04-29 14:45:15 +01001620 dev_err(&urb->dev->dev,
1621 "%s - usb_submit_urb failed with result %d\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -08001622 __func__, retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623}
1624
Alan Cox2742fd82008-04-29 14:45:15 +01001625static void edge_bulk_in_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626{
Ming Leicdc97792008-02-24 18:41:47 +08001627 struct edgeport_port *edge_port = urb->context;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001628 struct device *dev = &edge_port->port->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 unsigned char *data = urb->transfer_buffer;
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001630 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 int port_number;
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001632 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001634 switch (status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 case 0:
1636 /* success */
1637 break;
1638 case -ECONNRESET:
1639 case -ENOENT:
1640 case -ESHUTDOWN:
1641 /* this urb is terminated, clean up */
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001642 dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 return;
1644 default:
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001645 dev_err(&urb->dev->dev, "%s - nonzero read bulk status received: %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 }
1647
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001648 if (status == -EPIPE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 goto exit;
1650
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001651 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001652 dev_err(&urb->dev->dev, "%s - stopping read!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 return;
1654 }
1655
1656 port_number = edge_port->port->number - edge_port->port->serial->minor;
1657
1658 if (edge_port->lsr_event) {
1659 edge_port->lsr_event = 0;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001660 dev_dbg(dev, "%s ===== Port %u LSR Status = %02x, Data = %02x ======\n",
1661 __func__, port_number, edge_port->lsr_mask, *data);
Alan Cox2742fd82008-04-29 14:45:15 +01001662 handle_new_lsr(edge_port, 1, edge_port->lsr_mask, *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 /* Adjust buffer length/pointer */
1664 --urb->actual_length;
1665 ++data;
1666 }
1667
Jiri Slaby2e124b42013-01-03 15:53:06 +01001668 if (urb->actual_length) {
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +01001669 usb_serial_debug_data(dev, __func__, urb->actual_length, data);
Alan Cox2742fd82008-04-29 14:45:15 +01001670 if (edge_port->close_pending)
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001671 dev_dbg(dev, "%s - close pending, dropping data on the floor\n",
Alan Cox2742fd82008-04-29 14:45:15 +01001672 __func__);
1673 else
Jiri Slaby2e124b42013-01-03 15:53:06 +01001674 edge_tty_recv(edge_port->port, data,
Jiri Slaby05c7cd32013-01-03 15:53:04 +01001675 urb->actual_length);
Johan Hovoldcf9a9d62013-03-21 12:37:09 +01001676 edge_port->port->icount.rx += urb->actual_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 }
1678
1679exit:
1680 /* continue read unless stopped */
1681 spin_lock(&edge_port->ep_lock);
Johan Hovold58330412011-11-06 19:06:28 +01001682 if (edge_port->ep_read_urb_state == EDGE_READ_URB_RUNNING)
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001683 retval = usb_submit_urb(urb, GFP_ATOMIC);
Johan Hovold58330412011-11-06 19:06:28 +01001684 else if (edge_port->ep_read_urb_state == EDGE_READ_URB_STOPPING)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 edge_port->ep_read_urb_state = EDGE_READ_URB_STOPPED;
Johan Hovold58330412011-11-06 19:06:28 +01001686
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 spin_unlock(&edge_port->ep_lock);
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001688 if (retval)
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001689 dev_err(dev, "%s - usb_submit_urb failed with result %d\n", __func__, retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690}
1691
Jiri Slaby2e124b42013-01-03 15:53:06 +01001692static void edge_tty_recv(struct usb_serial_port *port, unsigned char *data,
1693 int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694{
Alan Cox2742fd82008-04-29 14:45:15 +01001695 int queued;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696
Jiri Slaby05c7cd32013-01-03 15:53:04 +01001697 queued = tty_insert_flip_string(&port->port, data, length);
Alan Cox2742fd82008-04-29 14:45:15 +01001698 if (queued < length)
Jiri Slaby05c7cd32013-01-03 15:53:04 +01001699 dev_err(&port->dev, "%s - dropping data, %d bytes lost\n",
Alan Cox2742fd82008-04-29 14:45:15 +01001700 __func__, length - queued);
Jiri Slaby2e124b42013-01-03 15:53:06 +01001701 tty_flip_buffer_push(&port->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702}
1703
Alan Cox2742fd82008-04-29 14:45:15 +01001704static void edge_bulk_out_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705{
Ming Leicdc97792008-02-24 18:41:47 +08001706 struct usb_serial_port *port = urb->context;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001708 int status = urb->status;
Alan Cox4a90f092008-10-13 10:39:46 +01001709 struct tty_struct *tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 edge_port->ep_write_urb_in_use = 0;
1712
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001713 switch (status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 case 0:
1715 /* success */
1716 break;
1717 case -ECONNRESET:
1718 case -ENOENT:
1719 case -ESHUTDOWN:
1720 /* this urb is terminated, clean up */
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001721 dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -08001722 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 return;
1724 default:
Johan Hovold22a416c2012-02-10 13:20:51 +01001725 dev_err_console(port, "%s - nonzero write bulk status "
Harvey Harrison441b62c2008-03-03 16:08:34 -08001726 "received: %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 }
1728
1729 /* send any buffered data */
Alan Cox4a90f092008-10-13 10:39:46 +01001730 tty = tty_port_tty_get(&port->port);
Jiri Slabyae3759c2013-04-04 22:41:01 +02001731 edge_send(port, tty);
Alan Cox4a90f092008-10-13 10:39:46 +01001732 tty_kref_put(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733}
1734
Alan Coxa509a7e2009-09-19 13:13:26 -07001735static int edge_open(struct tty_struct *tty, struct usb_serial_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736{
1737 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1738 struct edgeport_serial *edge_serial;
1739 struct usb_device *dev;
1740 struct urb *urb;
1741 int port_number;
1742 int status;
1743 u16 open_settings;
1744 u8 transaction_timeout;
1745
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 if (edge_port == NULL)
1747 return -ENODEV;
1748
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 port_number = port->number - port->serial->minor;
1750 switch (port_number) {
Alan Cox2742fd82008-04-29 14:45:15 +01001751 case 0:
1752 edge_port->uart_base = UMPMEM_BASE_UART1;
1753 edge_port->dma_address = UMPD_OEDB1_ADDRESS;
1754 break;
1755 case 1:
1756 edge_port->uart_base = UMPMEM_BASE_UART2;
1757 edge_port->dma_address = UMPD_OEDB2_ADDRESS;
1758 break;
1759 default:
1760 dev_err(&port->dev, "Unknown port number!!!\n");
1761 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 }
1763
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001764 dev_dbg(&port->dev, "%s - port_number = %d, uart_base = %04x, dma_address = %04x\n",
1765 __func__, port_number, edge_port->uart_base, edge_port->dma_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766
1767 dev = port->serial->dev;
1768
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 /* turn off loopback */
Alan Cox2742fd82008-04-29 14:45:15 +01001770 status = ti_do_config(edge_port, UMPC_SET_CLR_LOOPBACK, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001772 dev_err(&port->dev,
1773 "%s - cannot send clear loopback command, %d\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -08001774 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 return status;
1776 }
Alan Cox2742fd82008-04-29 14:45:15 +01001777
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 /* set up the port settings */
Alan Cox95da3102008-07-22 11:09:07 +01001779 if (tty)
Alan Coxadc8d742012-07-14 15:31:47 +01001780 edge_set_termios(tty, port, &tty->termios);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781
1782 /* open up the port */
1783
1784 /* milliseconds to timeout for DMA transfer */
1785 transaction_timeout = 2;
1786
Alan Cox2742fd82008-04-29 14:45:15 +01001787 edge_port->ump_read_timeout =
1788 max(20, ((transaction_timeout * 3) / 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789
Alan Cox2742fd82008-04-29 14:45:15 +01001790 /* milliseconds to timeout for DMA transfer */
1791 open_settings = (u8)(UMP_DMA_MODE_CONTINOUS |
1792 UMP_PIPE_TRANS_TIMEOUT_ENA |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 (transaction_timeout << 2));
1794
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001795 dev_dbg(&port->dev, "%s - Sending UMPC_OPEN_PORT\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796
1797 /* Tell TI to open and start the port */
Alan Cox2742fd82008-04-29 14:45:15 +01001798 status = send_cmd(dev, UMPC_OPEN_PORT,
1799 (u8)(UMPM_UART1_PORT + port_number), open_settings, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001801 dev_err(&port->dev, "%s - cannot send open command, %d\n",
1802 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 return status;
1804 }
1805
1806 /* Start the DMA? */
Alan Cox2742fd82008-04-29 14:45:15 +01001807 status = send_cmd(dev, UMPC_START_PORT,
1808 (u8)(UMPM_UART1_PORT + port_number), 0, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001810 dev_err(&port->dev, "%s - cannot send start DMA command, %d\n",
1811 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 return status;
1813 }
1814
1815 /* Clear TX and RX buffers in UMP */
Alan Cox2742fd82008-04-29 14:45:15 +01001816 status = purge_port(port, UMP_PORT_DIR_OUT | UMP_PORT_DIR_IN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001818 dev_err(&port->dev,
1819 "%s - cannot send clear buffers command, %d\n",
1820 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 return status;
1822 }
1823
1824 /* Read Initial MSR */
Alan Cox2742fd82008-04-29 14:45:15 +01001825 status = ti_vread_sync(dev, UMPC_READ_MSR, 0,
1826 (__u16)(UMPM_UART1_PORT + port_number),
1827 &edge_port->shadow_msr, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001829 dev_err(&port->dev, "%s - cannot send read MSR command, %d\n",
1830 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 return status;
1832 }
1833
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001834 dev_dbg(&port->dev, "ShadowMSR 0x%X\n", edge_port->shadow_msr);
Alan Cox2742fd82008-04-29 14:45:15 +01001835
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 /* Set Initial MCR */
1837 edge_port->shadow_mcr = MCR_RTS | MCR_DTR;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001838 dev_dbg(&port->dev, "ShadowMCR 0x%X\n", edge_port->shadow_mcr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839
1840 edge_serial = edge_port->edge_serial;
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01001841 if (mutex_lock_interruptible(&edge_serial->es_lock))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 return -ERESTARTSYS;
1843 if (edge_serial->num_ports_open == 0) {
Alan Cox2742fd82008-04-29 14:45:15 +01001844 /* we are the first port to open, post the interrupt urb */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 urb = edge_serial->serial->port[0]->interrupt_in_urb;
1846 if (!urb) {
Alan Cox2742fd82008-04-29 14:45:15 +01001847 dev_err(&port->dev,
1848 "%s - no interrupt urb present, exiting\n",
1849 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 status = -EINVAL;
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01001851 goto release_es_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 urb->context = edge_serial;
Alan Cox2742fd82008-04-29 14:45:15 +01001854 status = usb_submit_urb(urb, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001856 dev_err(&port->dev,
1857 "%s - usb_submit_urb failed with value %d\n",
1858 __func__, status);
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01001859 goto release_es_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 }
1861 }
1862
1863 /*
1864 * reset the data toggle on the bulk endpoints to work around bug in
1865 * host controllers where things get out of sync some times
1866 */
Alan Cox2742fd82008-04-29 14:45:15 +01001867 usb_clear_halt(dev, port->write_urb->pipe);
1868 usb_clear_halt(dev, port->read_urb->pipe);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869
1870 /* start up our bulk read urb */
1871 urb = port->read_urb;
1872 if (!urb) {
Alan Cox2742fd82008-04-29 14:45:15 +01001873 dev_err(&port->dev, "%s - no read urb present, exiting\n",
1874 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 status = -EINVAL;
1876 goto unlink_int_urb;
1877 }
1878 edge_port->ep_read_urb_state = EDGE_READ_URB_RUNNING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 urb->context = edge_port;
Alan Cox2742fd82008-04-29 14:45:15 +01001880 status = usb_submit_urb(urb, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001882 dev_err(&port->dev,
1883 "%s - read bulk usb_submit_urb failed with value %d\n",
1884 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 goto unlink_int_urb;
1886 }
1887
1888 ++edge_serial->num_ports_open;
1889
Johan Hovoldfcdb6a22013-01-14 16:52:55 +01001890 port->port.drain_delay = 1;
1891
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01001892 goto release_es_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
1894unlink_int_urb:
1895 if (edge_port->edge_serial->num_ports_open == 0)
1896 usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01001897release_es_lock:
1898 mutex_unlock(&edge_serial->es_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 return status;
1900}
1901
Alan Cox335f8512009-06-11 12:26:29 +01001902static void edge_close(struct usb_serial_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903{
1904 struct edgeport_serial *edge_serial;
1905 struct edgeport_port *edge_port;
Johan Hovoldaf581052012-03-26 20:31:38 +02001906 struct usb_serial *serial = port->serial;
Johan Hovold77de2512013-01-14 16:52:54 +01001907 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 int port_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 edge_serial = usb_get_serial_data(port->serial);
1911 edge_port = usb_get_serial_port_data(port);
Alan Cox2742fd82008-04-29 14:45:15 +01001912 if (edge_serial == NULL || edge_port == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 return;
Alan Cox2742fd82008-04-29 14:45:15 +01001914
1915 /* The bulkreadcompletion routine will check
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 * this flag and dump add read data */
1917 edge_port->close_pending = 1;
1918
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 usb_kill_urb(port->read_urb);
1920 usb_kill_urb(port->write_urb);
1921 edge_port->ep_write_urb_in_use = 0;
Johan Hovold77de2512013-01-14 16:52:54 +01001922 spin_lock_irqsave(&edge_port->ep_lock, flags);
1923 kfifo_reset_out(&edge_port->write_fifo);
1924 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001926 dev_dbg(&port->dev, "%s - send umpc_close_port\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 port_number = port->number - port->serial->minor;
Johan Hovoldbca87e92013-03-21 12:37:38 +01001928 send_cmd(serial->dev, UMPC_CLOSE_PORT,
1929 (__u8)(UMPM_UART1_PORT + port_number), 0, NULL, 0);
Johan Hovoldaf581052012-03-26 20:31:38 +02001930
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01001931 mutex_lock(&edge_serial->es_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 --edge_port->edge_serial->num_ports_open;
1933 if (edge_port->edge_serial->num_ports_open <= 0) {
1934 /* last port is now closed, let's shut down our interrupt urb */
1935 usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
1936 edge_port->edge_serial->num_ports_open = 0;
1937 }
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01001938 mutex_unlock(&edge_serial->es_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 edge_port->close_pending = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940}
1941
Alan Cox95da3102008-07-22 11:09:07 +01001942static int edge_write(struct tty_struct *tty, struct usb_serial_port *port,
1943 const unsigned char *data, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944{
1945 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 if (count == 0) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001948 dev_dbg(&port->dev, "%s - write request of 0 bytes\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 return 0;
1950 }
1951
1952 if (edge_port == NULL)
1953 return -ENODEV;
1954 if (edge_port->close_pending == 1)
1955 return -ENODEV;
1956
Johan Hovoldd733cec2010-05-19 00:01:37 +02001957 count = kfifo_in_locked(&edge_port->write_fifo, data, count,
1958 &edge_port->ep_lock);
Jiri Slabyae3759c2013-04-04 22:41:01 +02001959 edge_send(port, tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960
1961 return count;
1962}
1963
Jiri Slabyae3759c2013-04-04 22:41:01 +02001964static void edge_send(struct usb_serial_port *port, struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965{
1966 int count, result;
1967 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 unsigned long flags;
1969
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 spin_lock_irqsave(&edge_port->ep_lock, flags);
1971
1972 if (edge_port->ep_write_urb_in_use) {
1973 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1974 return;
1975 }
1976
Johan Hovoldd733cec2010-05-19 00:01:37 +02001977 count = kfifo_out(&edge_port->write_fifo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 port->write_urb->transfer_buffer,
1979 port->bulk_out_size);
1980
1981 if (count == 0) {
1982 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1983 return;
1984 }
1985
1986 edge_port->ep_write_urb_in_use = 1;
1987
1988 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1989
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +01001990 usb_serial_debug_data(&port->dev, __func__, count, port->write_urb->transfer_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991
1992 /* set up our urb */
Johan Hovoldfd119612011-11-06 19:06:30 +01001993 port->write_urb->transfer_buffer_length = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994
1995 /* send the data out the bulk port */
1996 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
1997 if (result) {
Johan Hovold22a416c2012-02-10 13:20:51 +01001998 dev_err_console(port,
Alan Cox2742fd82008-04-29 14:45:15 +01001999 "%s - failed submitting write urb, error %d\n",
2000 __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 edge_port->ep_write_urb_in_use = 0;
Alan Cox2742fd82008-04-29 14:45:15 +01002002 /* TODO: reschedule edge_send */
2003 } else
Johan Hovoldcf9a9d62013-03-21 12:37:09 +01002004 edge_port->port->icount.tx += count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005
2006 /* wakeup any process waiting for writes to complete */
2007 /* there is now more room in the buffer for new writes */
Alan Cox2742fd82008-04-29 14:45:15 +01002008 if (tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 tty_wakeup(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010}
2011
Alan Cox95da3102008-07-22 11:09:07 +01002012static int edge_write_room(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013{
Alan Cox95da3102008-07-22 11:09:07 +01002014 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2016 int room = 0;
2017 unsigned long flags;
2018
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 if (edge_port == NULL)
Alan Cox2742fd82008-04-29 14:45:15 +01002020 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 if (edge_port->close_pending == 1)
Alan Cox2742fd82008-04-29 14:45:15 +01002022 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023
2024 spin_lock_irqsave(&edge_port->ep_lock, flags);
Johan Hovoldd733cec2010-05-19 00:01:37 +02002025 room = kfifo_avail(&edge_port->write_fifo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2027
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002028 dev_dbg(&port->dev, "%s - returns %d\n", __func__, room);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 return room;
2030}
2031
Alan Cox95da3102008-07-22 11:09:07 +01002032static int edge_chars_in_buffer(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033{
Alan Cox95da3102008-07-22 11:09:07 +01002034 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2036 int chars = 0;
2037 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 if (edge_port == NULL)
Alan Cox2742fd82008-04-29 14:45:15 +01002039 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040
2041 spin_lock_irqsave(&edge_port->ep_lock, flags);
Johan Hovoldd733cec2010-05-19 00:01:37 +02002042 chars = kfifo_len(&edge_port->write_fifo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2044
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002045 dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 return chars;
2047}
2048
Johan Hovoldb16634a2013-05-05 20:32:31 +02002049static bool edge_tx_empty(struct usb_serial_port *port)
2050{
2051 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2052 int ret;
2053
2054 ret = tx_active(edge_port);
2055 if (ret > 0)
2056 return false;
2057
2058 return true;
2059}
2060
Alan Cox95da3102008-07-22 11:09:07 +01002061static void edge_throttle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062{
Alan Cox95da3102008-07-22 11:09:07 +01002063 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 int status;
2066
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 if (edge_port == NULL)
2068 return;
2069
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 /* if we are implementing XON/XOFF, send the stop character */
2071 if (I_IXOFF(tty)) {
2072 unsigned char stop_char = STOP_CHAR(tty);
Alan Cox95da3102008-07-22 11:09:07 +01002073 status = edge_write(tty, port, &stop_char, 1);
2074 if (status <= 0) {
2075 dev_err(&port->dev, "%s - failed to write stop character, %d\n", __func__, status);
2076 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 }
2078
2079 /* if we are implementing RTS/CTS, stop reads */
2080 /* and the Edgeport will clear the RTS line */
2081 if (C_CRTSCTS(tty))
2082 stop_read(edge_port);
2083
2084}
2085
Alan Cox95da3102008-07-22 11:09:07 +01002086static void edge_unthrottle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087{
Alan Cox95da3102008-07-22 11:09:07 +01002088 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 int status;
2091
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 if (edge_port == NULL)
2093 return;
2094
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 /* if we are implementing XON/XOFF, send the start character */
2096 if (I_IXOFF(tty)) {
2097 unsigned char start_char = START_CHAR(tty);
Alan Cox95da3102008-07-22 11:09:07 +01002098 status = edge_write(tty, port, &start_char, 1);
2099 if (status <= 0) {
2100 dev_err(&port->dev, "%s - failed to write start character, %d\n", __func__, status);
2101 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 /* if we are implementing RTS/CTS, restart reads */
2104 /* are the Edgeport will assert the RTS line */
2105 if (C_CRTSCTS(tty)) {
2106 status = restart_read(edge_port);
2107 if (status)
Alan Cox2742fd82008-04-29 14:45:15 +01002108 dev_err(&port->dev,
2109 "%s - read bulk usb_submit_urb failed: %d\n",
2110 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 }
2112
2113}
2114
2115static void stop_read(struct edgeport_port *edge_port)
2116{
2117 unsigned long flags;
2118
2119 spin_lock_irqsave(&edge_port->ep_lock, flags);
2120
2121 if (edge_port->ep_read_urb_state == EDGE_READ_URB_RUNNING)
2122 edge_port->ep_read_urb_state = EDGE_READ_URB_STOPPING;
2123 edge_port->shadow_mcr &= ~MCR_RTS;
2124
2125 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2126}
2127
2128static int restart_read(struct edgeport_port *edge_port)
2129{
2130 struct urb *urb;
2131 int status = 0;
2132 unsigned long flags;
2133
2134 spin_lock_irqsave(&edge_port->ep_lock, flags);
2135
2136 if (edge_port->ep_read_urb_state == EDGE_READ_URB_STOPPED) {
2137 urb = edge_port->port->read_urb;
Oliver Neukumefdff602007-06-05 10:50:48 +02002138 status = usb_submit_urb(urb, GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 }
2140 edge_port->ep_read_urb_state = EDGE_READ_URB_RUNNING;
2141 edge_port->shadow_mcr |= MCR_RTS;
2142
2143 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2144
2145 return status;
2146}
2147
Alan Cox95da3102008-07-22 11:09:07 +01002148static void change_port_settings(struct tty_struct *tty,
2149 struct edgeport_port *edge_port, struct ktermios *old_termios)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150{
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002151 struct device *dev = &edge_port->port->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 struct ump_uart_config *config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 int baud;
2154 unsigned cflag;
2155 int status;
Alan Cox2742fd82008-04-29 14:45:15 +01002156 int port_number = edge_port->port->number -
2157 edge_port->port->serial->minor;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002159 dev_dbg(dev, "%s - port %d\n", __func__, edge_port->port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160
Alan Cox95da3102008-07-22 11:09:07 +01002161 config = kmalloc (sizeof (*config), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 if (!config) {
Alan Coxadc8d742012-07-14 15:31:47 +01002163 tty->termios = *old_termios;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002164 dev_err(dev, "%s - out of memory\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 return;
2166 }
2167
Alan Coxadc8d742012-07-14 15:31:47 +01002168 cflag = tty->termios.c_cflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169
2170 config->wFlags = 0;
2171
2172 /* These flags must be set */
2173 config->wFlags |= UMP_MASK_UART_FLAGS_RECEIVE_MS_INT;
2174 config->wFlags |= UMP_MASK_UART_FLAGS_AUTO_START_ON_ERR;
2175 config->bUartMode = (__u8)(edge_port->bUartMode);
2176
2177 switch (cflag & CSIZE) {
Alan Cox2742fd82008-04-29 14:45:15 +01002178 case CS5:
2179 config->bDataBits = UMP_UART_CHAR5BITS;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002180 dev_dbg(dev, "%s - data bits = 5\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01002181 break;
2182 case CS6:
2183 config->bDataBits = UMP_UART_CHAR6BITS;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002184 dev_dbg(dev, "%s - data bits = 6\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01002185 break;
2186 case CS7:
2187 config->bDataBits = UMP_UART_CHAR7BITS;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002188 dev_dbg(dev, "%s - data bits = 7\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01002189 break;
2190 default:
2191 case CS8:
2192 config->bDataBits = UMP_UART_CHAR8BITS;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002193 dev_dbg(dev, "%s - data bits = 8\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 break;
2195 }
2196
2197 if (cflag & PARENB) {
2198 if (cflag & PARODD) {
2199 config->wFlags |= UMP_MASK_UART_FLAGS_PARITY;
2200 config->bParity = UMP_UART_ODDPARITY;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002201 dev_dbg(dev, "%s - parity = odd\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 } else {
2203 config->wFlags |= UMP_MASK_UART_FLAGS_PARITY;
2204 config->bParity = UMP_UART_EVENPARITY;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002205 dev_dbg(dev, "%s - parity = even\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 }
2207 } else {
Alan Cox2742fd82008-04-29 14:45:15 +01002208 config->bParity = UMP_UART_NOPARITY;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002209 dev_dbg(dev, "%s - parity = none\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 }
2211
2212 if (cflag & CSTOPB) {
2213 config->bStopBits = UMP_UART_STOPBIT2;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002214 dev_dbg(dev, "%s - stop bits = 2\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 } else {
2216 config->bStopBits = UMP_UART_STOPBIT1;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002217 dev_dbg(dev, "%s - stop bits = 1\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 }
2219
2220 /* figure out the flow control settings */
2221 if (cflag & CRTSCTS) {
2222 config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X_CTS_FLOW;
2223 config->wFlags |= UMP_MASK_UART_FLAGS_RTS_FLOW;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002224 dev_dbg(dev, "%s - RTS/CTS is enabled\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 } else {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002226 dev_dbg(dev, "%s - RTS/CTS is disabled\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 tty->hw_stopped = 0;
2228 restart_read(edge_port);
2229 }
2230
Alan Cox2742fd82008-04-29 14:45:15 +01002231 /* if we are implementing XON/XOFF, set the start and stop
2232 character in the device */
2233 config->cXon = START_CHAR(tty);
2234 config->cXoff = STOP_CHAR(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235
Alan Cox2742fd82008-04-29 14:45:15 +01002236 /* if we are implementing INBOUND XON/XOFF */
2237 if (I_IXOFF(tty)) {
2238 config->wFlags |= UMP_MASK_UART_FLAGS_IN_X;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002239 dev_dbg(dev, "%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x\n",
2240 __func__, config->cXon, config->cXoff);
Alan Cox2742fd82008-04-29 14:45:15 +01002241 } else
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002242 dev_dbg(dev, "%s - INBOUND XON/XOFF is disabled\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243
Alan Cox2742fd82008-04-29 14:45:15 +01002244 /* if we are implementing OUTBOUND XON/XOFF */
2245 if (I_IXON(tty)) {
2246 config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002247 dev_dbg(dev, "%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x\n",
2248 __func__, config->cXon, config->cXoff);
Alan Cox2742fd82008-04-29 14:45:15 +01002249 } else
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002250 dev_dbg(dev, "%s - OUTBOUND XON/XOFF is disabled\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251
Alan Coxadc8d742012-07-14 15:31:47 +01002252 tty->termios.c_cflag &= ~CMSPAR;
Alan Coxd5f5bcd2008-01-03 16:57:33 +00002253
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 /* Round the baud rate */
2255 baud = tty_get_baud_rate(tty);
2256 if (!baud) {
2257 /* pick a default, any default... */
2258 baud = 9600;
Alan Coxd5f5bcd2008-01-03 16:57:33 +00002259 } else
2260 tty_encode_baud_rate(tty, baud, baud);
2261
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 edge_port->baud_rate = baud;
2263 config->wBaudRate = (__u16)((461550L + baud/2) / baud);
2264
Alan Coxd5f5bcd2008-01-03 16:57:33 +00002265 /* FIXME: Recompute actual baud from divisor here */
2266
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002267 dev_dbg(dev, "%s - baud rate = %d, wBaudRate = %d\n", __func__, baud, config->wBaudRate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002269 dev_dbg(dev, "wBaudRate: %d\n", (int)(461550L / config->wBaudRate));
2270 dev_dbg(dev, "wFlags: 0x%x\n", config->wFlags);
2271 dev_dbg(dev, "bDataBits: %d\n", config->bDataBits);
2272 dev_dbg(dev, "bParity: %d\n", config->bParity);
2273 dev_dbg(dev, "bStopBits: %d\n", config->bStopBits);
2274 dev_dbg(dev, "cXon: %d\n", config->cXon);
2275 dev_dbg(dev, "cXoff: %d\n", config->cXoff);
2276 dev_dbg(dev, "bUartMode: %d\n", config->bUartMode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277
2278 /* move the word values into big endian mode */
Alan Cox2742fd82008-04-29 14:45:15 +01002279 cpu_to_be16s(&config->wFlags);
2280 cpu_to_be16s(&config->wBaudRate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281
Alan Cox2742fd82008-04-29 14:45:15 +01002282 status = send_cmd(edge_port->port->serial->dev, UMPC_SET_CONFIG,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 (__u8)(UMPM_UART1_PORT + port_number),
Alan Cox2742fd82008-04-29 14:45:15 +01002284 0, (__u8 *)config, sizeof(*config));
2285 if (status)
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002286 dev_dbg(dev, "%s - error %d when trying to write config to device\n",
2287 __func__, status);
Alan Cox2742fd82008-04-29 14:45:15 +01002288 kfree(config);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289}
2290
Alan Cox2e0ddd62008-07-22 11:12:33 +01002291static void edge_set_termios(struct tty_struct *tty,
Alan Cox95da3102008-07-22 11:09:07 +01002292 struct usb_serial_port *port, struct ktermios *old_termios)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293{
2294 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
Alan Cox95da3102008-07-22 11:09:07 +01002295 unsigned int cflag;
2296
Alan Coxadc8d742012-07-14 15:31:47 +01002297 cflag = tty->termios.c_cflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002299 dev_dbg(&port->dev, "%s - clfag %08x iflag %08x\n", __func__,
Linus Torvaldsd9a80742012-10-01 13:23:01 -07002300 tty->termios.c_cflag, tty->termios.c_iflag);
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002301 dev_dbg(&port->dev, "%s - old clfag %08x old iflag %08x\n", __func__,
2302 old_termios->c_cflag, old_termios->c_iflag);
2303 dev_dbg(&port->dev, "%s - port %d\n", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304
2305 if (edge_port == NULL)
2306 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 /* change the port settings to the new ones specified */
Alan Cox95da3102008-07-22 11:09:07 +01002308 change_port_settings(tty, edge_port, old_termios);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309}
2310
Alan Cox20b9d172011-02-14 16:26:50 +00002311static int edge_tiocmset(struct tty_struct *tty,
Alan Cox2742fd82008-04-29 14:45:15 +01002312 unsigned int set, unsigned int clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313{
Alan Cox95da3102008-07-22 11:09:07 +01002314 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2316 unsigned int mcr;
Alan Cox3d71fe02008-02-20 21:38:32 +00002317 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318
Alan Cox3d71fe02008-02-20 21:38:32 +00002319 spin_lock_irqsave(&edge_port->ep_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 mcr = edge_port->shadow_mcr;
2321 if (set & TIOCM_RTS)
2322 mcr |= MCR_RTS;
2323 if (set & TIOCM_DTR)
2324 mcr |= MCR_DTR;
2325 if (set & TIOCM_LOOP)
2326 mcr |= MCR_LOOPBACK;
2327
2328 if (clear & TIOCM_RTS)
2329 mcr &= ~MCR_RTS;
2330 if (clear & TIOCM_DTR)
2331 mcr &= ~MCR_DTR;
2332 if (clear & TIOCM_LOOP)
2333 mcr &= ~MCR_LOOPBACK;
2334
2335 edge_port->shadow_mcr = mcr;
Alan Cox3d71fe02008-02-20 21:38:32 +00002336 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337
Alan Cox2742fd82008-04-29 14:45:15 +01002338 restore_mcr(edge_port, mcr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 return 0;
2340}
2341
Alan Cox60b33c12011-02-14 16:26:14 +00002342static int edge_tiocmget(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343{
Alan Cox95da3102008-07-22 11:09:07 +01002344 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2346 unsigned int result = 0;
2347 unsigned int msr;
2348 unsigned int mcr;
Alan Cox3d71fe02008-02-20 21:38:32 +00002349 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350
Alan Cox3d71fe02008-02-20 21:38:32 +00002351 spin_lock_irqsave(&edge_port->ep_lock, flags);
2352
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 msr = edge_port->shadow_msr;
2354 mcr = edge_port->shadow_mcr;
2355 result = ((mcr & MCR_DTR) ? TIOCM_DTR: 0) /* 0x002 */
2356 | ((mcr & MCR_RTS) ? TIOCM_RTS: 0) /* 0x004 */
2357 | ((msr & EDGEPORT_MSR_CTS) ? TIOCM_CTS: 0) /* 0x020 */
2358 | ((msr & EDGEPORT_MSR_CD) ? TIOCM_CAR: 0) /* 0x040 */
2359 | ((msr & EDGEPORT_MSR_RI) ? TIOCM_RI: 0) /* 0x080 */
2360 | ((msr & EDGEPORT_MSR_DSR) ? TIOCM_DSR: 0); /* 0x100 */
2361
2362
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002363 dev_dbg(&port->dev, "%s -- %x\n", __func__, result);
Alan Cox3d71fe02008-02-20 21:38:32 +00002364 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365
2366 return result;
2367}
2368
Alan Cox2742fd82008-04-29 14:45:15 +01002369static int get_serial_info(struct edgeport_port *edge_port,
2370 struct serial_struct __user *retinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371{
2372 struct serial_struct tmp;
Johan Hovoldf40d7812013-01-14 16:52:58 +01002373 unsigned cwait;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374
2375 if (!retinfo)
2376 return -EFAULT;
2377
Johan Hovoldf40d7812013-01-14 16:52:58 +01002378 cwait = edge_port->port->port.closing_wait;
2379 if (cwait != ASYNC_CLOSING_WAIT_NONE)
Johan Hovoldb6fd35e2013-04-18 17:33:17 +02002380 cwait = jiffies_to_msecs(cwait) / 10;
Johan Hovoldf40d7812013-01-14 16:52:58 +01002381
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 memset(&tmp, 0, sizeof(tmp));
2383
2384 tmp.type = PORT_16550A;
2385 tmp.line = edge_port->port->serial->minor;
2386 tmp.port = edge_port->port->number;
2387 tmp.irq = 0;
2388 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
2389 tmp.xmit_fifo_size = edge_port->port->bulk_out_size;
2390 tmp.baud_base = 9600;
2391 tmp.close_delay = 5*HZ;
Johan Hovoldf40d7812013-01-14 16:52:58 +01002392 tmp.closing_wait = cwait;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393
2394 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2395 return -EFAULT;
2396 return 0;
2397}
2398
Alan Cox00a0d0d2011-02-14 16:27:06 +00002399static int edge_ioctl(struct tty_struct *tty,
Alan Cox2742fd82008-04-29 14:45:15 +01002400 unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401{
Alan Cox95da3102008-07-22 11:09:07 +01002402 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002405 dev_dbg(&port->dev, "%s - port %d, cmd = 0x%x\n", __func__, port->number, cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406
2407 switch (cmd) {
Alan Cox2742fd82008-04-29 14:45:15 +01002408 case TIOCGSERIAL:
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002409 dev_dbg(&port->dev, "%s - TIOCGSERIAL\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01002410 return get_serial_info(edge_port,
2411 (struct serial_struct __user *) arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 return -ENOIOCTLCMD;
2414}
2415
Alan Cox95da3102008-07-22 11:09:07 +01002416static void edge_break(struct tty_struct *tty, int break_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417{
Alan Cox95da3102008-07-22 11:09:07 +01002418 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2420 int status;
Alan Cox2742fd82008-04-29 14:45:15 +01002421 int bv = 0; /* Off */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422
Alan Cox95da3102008-07-22 11:09:07 +01002423 if (break_state == -1)
Alan Cox2742fd82008-04-29 14:45:15 +01002424 bv = 1; /* On */
2425 status = ti_do_config(edge_port, UMPC_SET_CLR_BREAK, bv);
2426 if (status)
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002427 dev_dbg(&port->dev, "%s - error %d sending break set/clear command.\n",
2428 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429}
2430
Alan Cox2742fd82008-04-29 14:45:15 +01002431static int edge_startup(struct usb_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432{
2433 struct edgeport_serial *edge_serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435
2436 /* create our private serial structure */
Eric Sesterhenn80b6ca42006-02-27 21:29:43 +01002437 edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 if (edge_serial == NULL) {
Harvey Harrison441b62c2008-03-03 16:08:34 -08002439 dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 return -ENOMEM;
2441 }
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01002442 mutex_init(&edge_serial->es_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 edge_serial->serial = serial;
2444 usb_set_serial_data(serial, edge_serial);
2445
Alan Cox2742fd82008-04-29 14:45:15 +01002446 status = download_fw(edge_serial);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01002448 kfree(edge_serial);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 return status;
2450 }
2451
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453}
2454
Alan Sternf9c99bb2009-06-02 11:53:55 -04002455static void edge_disconnect(struct usb_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456{
Alan Sternf9c99bb2009-06-02 11:53:55 -04002457}
2458
2459static void edge_release(struct usb_serial *serial)
2460{
Jesper Juhl0d46c002007-07-16 22:17:25 +02002461 kfree(usb_get_serial_data(serial));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462}
2463
Johan Hovold00361532012-10-17 13:34:58 +02002464static int edge_port_probe(struct usb_serial_port *port)
2465{
2466 struct edgeport_port *edge_port;
2467 int ret;
2468
2469 edge_port = kzalloc(sizeof(*edge_port), GFP_KERNEL);
2470 if (!edge_port)
2471 return -ENOMEM;
2472
2473 ret = kfifo_alloc(&edge_port->write_fifo, EDGE_OUT_BUF_SIZE,
2474 GFP_KERNEL);
2475 if (ret) {
2476 kfree(edge_port);
2477 return -ENOMEM;
2478 }
2479
Johan Hovold00361532012-10-17 13:34:58 +02002480 spin_lock_init(&edge_port->ep_lock);
2481 edge_port->port = port;
2482 edge_port->edge_serial = usb_get_serial_data(port->serial);
2483 edge_port->bUartMode = default_uart_mode;
2484
2485 usb_set_serial_port_data(port, edge_port);
2486
Johan Hovold5d8c61b2012-10-18 11:43:28 +02002487 ret = edge_create_sysfs_attrs(port);
2488 if (ret) {
2489 kfifo_free(&edge_port->write_fifo);
2490 kfree(edge_port);
2491 return ret;
2492 }
2493
Johan Hovoldf40d7812013-01-14 16:52:58 +01002494 port->port.closing_wait = msecs_to_jiffies(closing_wait * 10);
2495
Johan Hovold00361532012-10-17 13:34:58 +02002496 return 0;
2497}
2498
2499static int edge_port_remove(struct usb_serial_port *port)
2500{
2501 struct edgeport_port *edge_port;
2502
2503 edge_port = usb_get_serial_port_data(port);
Johan Hovold00361532012-10-17 13:34:58 +02002504 edge_remove_sysfs_attrs(port);
2505 kfifo_free(&edge_port->write_fifo);
2506 kfree(edge_port);
2507
2508 return 0;
2509}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -04002511/* Sysfs Attributes */
2512
2513static ssize_t show_uart_mode(struct device *dev,
2514 struct device_attribute *attr, char *buf)
2515{
2516 struct usb_serial_port *port = to_usb_serial_port(dev);
2517 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2518
2519 return sprintf(buf, "%d\n", edge_port->bUartMode);
2520}
2521
2522static ssize_t store_uart_mode(struct device *dev,
2523 struct device_attribute *attr, const char *valbuf, size_t count)
2524{
2525 struct usb_serial_port *port = to_usb_serial_port(dev);
2526 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2527 unsigned int v = simple_strtoul(valbuf, NULL, 0);
2528
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002529 dev_dbg(dev, "%s: setting uart_mode = %d\n", __func__, v);
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -04002530
2531 if (v < 256)
2532 edge_port->bUartMode = v;
2533 else
Harvey Harrison441b62c2008-03-03 16:08:34 -08002534 dev_err(dev, "%s - uart_mode %d is invalid\n", __func__, v);
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -04002535
2536 return count;
2537}
2538
Alan Cox2742fd82008-04-29 14:45:15 +01002539static DEVICE_ATTR(uart_mode, S_IWUSR | S_IRUGO, show_uart_mode,
2540 store_uart_mode);
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -04002541
2542static int edge_create_sysfs_attrs(struct usb_serial_port *port)
2543{
2544 return device_create_file(&port->dev, &dev_attr_uart_mode);
2545}
2546
2547static int edge_remove_sysfs_attrs(struct usb_serial_port *port)
2548{
2549 device_remove_file(&port->dev, &dev_attr_uart_mode);
2550 return 0;
2551}
2552
2553
Greg Kroah-Hartmanea653702005-06-20 21:15:16 -07002554static struct usb_serial_driver edgeport_1port_device = {
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -07002555 .driver = {
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -07002556 .owner = THIS_MODULE,
2557 .name = "edgeport_ti_1",
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -07002558 },
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -07002559 .description = "Edgeport TI 1 port adapter",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 .id_table = edgeport_1port_id_table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 .num_ports = 1,
2562 .open = edge_open,
2563 .close = edge_close,
2564 .throttle = edge_throttle,
2565 .unthrottle = edge_unthrottle,
2566 .attach = edge_startup,
Alan Sternf9c99bb2009-06-02 11:53:55 -04002567 .disconnect = edge_disconnect,
2568 .release = edge_release,
Johan Hovold00361532012-10-17 13:34:58 +02002569 .port_probe = edge_port_probe,
2570 .port_remove = edge_port_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 .ioctl = edge_ioctl,
2572 .set_termios = edge_set_termios,
2573 .tiocmget = edge_tiocmget,
2574 .tiocmset = edge_tiocmset,
Johan Hovold48ee5802013-03-21 12:37:10 +01002575 .tiocmiwait = usb_serial_generic_tiocmiwait,
Johan Hovoldcf9a9d62013-03-21 12:37:09 +01002576 .get_icount = usb_serial_generic_get_icount,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 .write = edge_write,
2578 .write_room = edge_write_room,
2579 .chars_in_buffer = edge_chars_in_buffer,
Johan Hovoldb16634a2013-05-05 20:32:31 +02002580 .tx_empty = edge_tx_empty,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 .break_ctl = edge_break,
2582 .read_int_callback = edge_interrupt_callback,
2583 .read_bulk_callback = edge_bulk_in_callback,
2584 .write_bulk_callback = edge_bulk_out_callback,
2585};
2586
Greg Kroah-Hartmanea653702005-06-20 21:15:16 -07002587static struct usb_serial_driver edgeport_2port_device = {
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -07002588 .driver = {
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -07002589 .owner = THIS_MODULE,
2590 .name = "edgeport_ti_2",
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -07002591 },
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -07002592 .description = "Edgeport TI 2 port adapter",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 .id_table = edgeport_2port_id_table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 .num_ports = 2,
2595 .open = edge_open,
2596 .close = edge_close,
2597 .throttle = edge_throttle,
2598 .unthrottle = edge_unthrottle,
2599 .attach = edge_startup,
Alan Sternf9c99bb2009-06-02 11:53:55 -04002600 .disconnect = edge_disconnect,
2601 .release = edge_release,
Johan Hovold00361532012-10-17 13:34:58 +02002602 .port_probe = edge_port_probe,
2603 .port_remove = edge_port_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 .ioctl = edge_ioctl,
2605 .set_termios = edge_set_termios,
2606 .tiocmget = edge_tiocmget,
2607 .tiocmset = edge_tiocmset,
Johan Hovold48ee5802013-03-21 12:37:10 +01002608 .tiocmiwait = usb_serial_generic_tiocmiwait,
Johan Hovoldcf9a9d62013-03-21 12:37:09 +01002609 .get_icount = usb_serial_generic_get_icount,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 .write = edge_write,
2611 .write_room = edge_write_room,
2612 .chars_in_buffer = edge_chars_in_buffer,
Johan Hovoldb16634a2013-05-05 20:32:31 +02002613 .tx_empty = edge_tx_empty,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 .break_ctl = edge_break,
2615 .read_int_callback = edge_interrupt_callback,
2616 .read_bulk_callback = edge_bulk_in_callback,
2617 .write_bulk_callback = edge_bulk_out_callback,
2618};
2619
Alan Stern7dbe2462012-02-23 14:56:57 -05002620static struct usb_serial_driver * const serial_drivers[] = {
2621 &edgeport_1port_device, &edgeport_2port_device, NULL
2622};
2623
Greg Kroah-Hartman68e24112012-05-08 15:46:14 -07002624module_usb_serial_driver(serial_drivers, id_table_combined);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626MODULE_AUTHOR(DRIVER_AUTHOR);
2627MODULE_DESCRIPTION(DRIVER_DESC);
2628MODULE_LICENSE("GPL");
Jaswinder Singhd12b2192008-07-04 23:06:09 +05302629MODULE_FIRMWARE("edgeport/down3.bin");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631module_param(closing_wait, int, S_IRUGO | S_IWUSR);
2632MODULE_PARM_DESC(closing_wait, "Maximum wait for data to drain, in .01 secs");
2633
2634module_param(ignore_cpu_rev, bool, S_IRUGO | S_IWUSR);
Alan Cox2742fd82008-04-29 14:45:15 +01002635MODULE_PARM_DESC(ignore_cpu_rev,
2636 "Ignore the cpu revision when connecting to a device");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -04002638module_param(default_uart_mode, int, S_IRUGO | S_IWUSR);
2639MODULE_PARM_DESC(default_uart_mode, "Default uart_mode, 0=RS232, ...");