blob: fb9e66480f17ed90b0489db4207b7dbc90af14de [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 Hovoldd733cec2010-05-19 00:01:37 +020032#include <linux/kfifo.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/ioctl.h>
Jaswinder Singhd12b2192008-07-04 23:06:09 +053034#include <linux/firmware.h>
Alan Cox2742fd82008-04-29 14:45:15 +010035#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/usb.h>
Greg Kroah-Hartmana9698882006-07-11 21:22:58 -070037#include <linux/usb/serial.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include "io_16654.h"
40#include "io_usbvend.h"
41#include "io_ti.h"
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com> and David Iacovelli"
44#define DRIVER_DESC "Edgeport USB Serial Driver"
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#define EPROM_PAGE_SIZE 64
47
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049/* different hardware types */
50#define HARDWARE_TYPE_930 0
51#define HARDWARE_TYPE_TIUMP 1
52
Alan Cox2742fd82008-04-29 14:45:15 +010053/* IOCTL_PRIVATE_TI_GET_MODE Definitions */
54#define TI_MODE_CONFIGURING 0 /* Device has not entered start device */
55#define TI_MODE_BOOT 1 /* Staying in boot mode */
56#define TI_MODE_DOWNLOAD 2 /* Made it to download mode */
57#define TI_MODE_TRANSITIONING 3 /* Currently in boot mode but
58 transitioning to download mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60/* read urb state */
61#define EDGE_READ_URB_RUNNING 0
62#define EDGE_READ_URB_STOPPING 1
63#define EDGE_READ_URB_STOPPED 2
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#define EDGE_CLOSING_WAIT 4000 /* in .01 sec */
66
67#define EDGE_OUT_BUF_SIZE 1024
68
69
70/* Product information read from the Edgeport */
Alan Cox2742fd82008-04-29 14:45:15 +010071struct product_info {
72 int TiMode; /* Current TI Mode */
73 __u8 hardware_type; /* Type of hardware */
Linus Torvalds1da177e2005-04-16 15:20:36 -070074} __attribute__((packed));
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076struct edgeport_port {
77 __u16 uart_base;
78 __u16 dma_address;
79 __u8 shadow_msr;
80 __u8 shadow_mcr;
81 __u8 shadow_lsr;
82 __u8 lsr_mask;
Martin Olsson19af5cd2009-04-23 11:37:37 +020083 __u32 ump_read_timeout; /* Number of milliseconds the UMP will
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 wait without data before completing
85 a read short */
86 int baud_rate;
87 int close_pending;
88 int lsr_event;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 struct edgeport_serial *edge_serial;
90 struct usb_serial_port *port;
Alan Cox2742fd82008-04-29 14:45:15 +010091 __u8 bUartMode; /* Port type, 0: RS232, etc. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 spinlock_t ep_lock;
93 int ep_read_urb_state;
94 int ep_write_urb_in_use;
Johan Hovoldd733cec2010-05-19 00:01:37 +020095 struct kfifo write_fifo;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096};
97
98struct edgeport_serial {
99 struct product_info product_info;
Alan Cox2742fd82008-04-29 14:45:15 +0100100 u8 TI_I2C_Type; /* Type of I2C in UMP */
101 u8 TiReadI2C; /* Set to TRUE if we have read the
102 I2c in Boot Mode */
Matthias Kaehlcke241ca642007-12-04 16:15:40 +0100103 struct mutex es_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 int num_ports_open;
105 struct usb_serial *serial;
106};
107
108
109/* Devices that this driver supports */
Németh Márton7d40d7e2010-01-10 15:34:24 +0100110static const struct usb_device_id edgeport_1port_id_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) },
112 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1) },
113 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I) },
114 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROXIMITY) },
115 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOTION) },
116 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOISTURE) },
117 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_TEMPERATURE) },
118 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_HUMIDITY) },
119 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_POWER) },
120 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_LIGHT) },
121 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_RADIATION) },
122 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_DISTANCE) },
123 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_ACCELERATION) },
124 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROX_DIST) },
125 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_HP4CD) },
126 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_PCI) },
127 { }
128};
129
Németh Márton7d40d7e2010-01-10 15:34:24 +0100130static const struct usb_device_id edgeport_2port_id_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2) },
132 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2C) },
133 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2I) },
134 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421) },
135 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21) },
136 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_42) },
137 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4) },
138 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4I) },
139 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22I) },
140 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_221C) },
141 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22C) },
142 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21C) },
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -0400143 /* The 4, 8 and 16 port devices show up as multiple 2 port devices */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4S) },
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -0400145 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8) },
146 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8S) },
147 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416) },
148 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416B) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 { }
150};
151
152/* Devices that this driver supports */
Németh Márton7d40d7e2010-01-10 15:34:24 +0100153static const struct usb_device_id id_table_combined[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) },
155 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1) },
156 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I) },
157 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROXIMITY) },
158 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOTION) },
159 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOISTURE) },
160 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_TEMPERATURE) },
161 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_HUMIDITY) },
162 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_POWER) },
163 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_LIGHT) },
164 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_RADIATION) },
165 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_DISTANCE) },
166 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_ACCELERATION) },
167 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROX_DIST) },
168 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_HP4CD) },
169 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_PCI) },
170 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2) },
171 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2C) },
172 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2I) },
173 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421) },
174 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21) },
175 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_42) },
176 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4) },
177 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4I) },
178 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22I) },
179 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_221C) },
180 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22C) },
181 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21C) },
182 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4S) },
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -0400183 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8) },
184 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8S) },
185 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416) },
186 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416B) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 { }
188};
189
Alan Cox2742fd82008-04-29 14:45:15 +0100190MODULE_DEVICE_TABLE(usb, id_table_combined);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530192static unsigned char OperationalMajorVersion;
193static unsigned char OperationalMinorVersion;
194static unsigned short OperationalBuildNumber;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196static int closing_wait = EDGE_CLOSING_WAIT;
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030197static bool ignore_cpu_rev;
Alan Cox2742fd82008-04-29 14:45:15 +0100198static int default_uart_mode; /* RS232 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Jiri Slaby2e124b42013-01-03 15:53:06 +0100200static void edge_tty_recv(struct usb_serial_port *port, unsigned char *data,
201 int length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203static void stop_read(struct edgeport_port *edge_port);
204static int restart_read(struct edgeport_port *edge_port);
205
Alan Cox95da3102008-07-22 11:09:07 +0100206static void edge_set_termios(struct tty_struct *tty,
207 struct usb_serial_port *port, struct ktermios *old_termios);
208static void edge_send(struct tty_struct *tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -0400210/* sysfs attributes */
211static int edge_create_sysfs_attrs(struct usb_serial_port *port);
212static int edge_remove_sysfs_attrs(struct usb_serial_port *port);
213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Alan Cox2742fd82008-04-29 14:45:15 +0100215static int ti_vread_sync(struct usb_device *dev, __u8 request,
216 __u16 value, __u16 index, u8 *data, int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217{
218 int status;
219
Alan Cox2742fd82008-04-29 14:45:15 +0100220 status = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), request,
221 (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN),
222 value, index, data, size, 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 if (status < 0)
224 return status;
225 if (status != size) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700226 dev_dbg(&dev->dev, "%s - wanted to write %d, but only wrote %d\n",
227 __func__, size, status);
Alan Cox2742fd82008-04-29 14:45:15 +0100228 return -ECOMM;
229 }
230 return 0;
231}
232
233static int ti_vsend_sync(struct usb_device *dev, __u8 request,
234 __u16 value, __u16 index, u8 *data, int size)
235{
236 int status;
237
238 status = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), request,
239 (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT),
240 value, index, data, size, 1000);
241 if (status < 0)
242 return status;
243 if (status != size) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700244 dev_dbg(&dev->dev, "%s - wanted to write %d, but only wrote %d\n",
245 __func__, size, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 return -ECOMM;
247 }
248 return 0;
249}
250
Alan Cox2742fd82008-04-29 14:45:15 +0100251static int send_cmd(struct usb_device *dev, __u8 command,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 __u8 moduleid, __u16 value, u8 *data,
253 int size)
254{
Alan Cox2742fd82008-04-29 14:45:15 +0100255 return ti_vsend_sync(dev, command, value, moduleid, data, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256}
257
258/* clear tx/rx buffers and fifo in TI UMP */
Alan Cox2742fd82008-04-29 14:45:15 +0100259static int purge_port(struct usb_serial_port *port, __u16 mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
261 int port_number = port->number - port->serial->minor;
262
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700263 dev_dbg(&port->dev, "%s - port %d, mask %x\n", __func__, port_number, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Alan Cox2742fd82008-04-29 14:45:15 +0100265 return send_cmd(port->serial->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 UMPC_PURGE_PORT,
267 (__u8)(UMPM_UART1_PORT + port_number),
268 mask,
269 NULL,
270 0);
271}
272
273/**
Alan Cox2742fd82008-04-29 14:45:15 +0100274 * read_download_mem - Read edgeport memory from TI chip
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 * @dev: usb device pointer
276 * @start_address: Device CPU address at which to read
277 * @length: Length of above data
278 * @address_type: Can read both XDATA and I2C
279 * @buffer: pointer to input data buffer
280 */
Alan Cox2742fd82008-04-29 14:45:15 +0100281static int read_download_mem(struct usb_device *dev, int start_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 int length, __u8 address_type, __u8 *buffer)
283{
284 int status = 0;
285 __u8 read_length;
286 __be16 be_start_address;
Alan Cox2742fd82008-04-29 14:45:15 +0100287
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700288 dev_dbg(&dev->dev, "%s - @ %x for %d\n", __func__, start_address, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
290 /* Read in blocks of 64 bytes
291 * (TI firmware can't handle more than 64 byte reads)
292 */
293 while (length) {
294 if (length > 64)
Alan Cox2742fd82008-04-29 14:45:15 +0100295 read_length = 64;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 else
297 read_length = (__u8)length;
298
299 if (read_length > 1) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700300 dev_dbg(&dev->dev, "%s - @ %x for %d\n", __func__, start_address, read_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 }
Alan Cox2742fd82008-04-29 14:45:15 +0100302 be_start_address = cpu_to_be16(start_address);
303 status = ti_vread_sync(dev, UMPC_MEMORY_READ,
304 (__u16)address_type,
305 (__force __u16)be_start_address,
306 buffer, read_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308 if (status) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700309 dev_dbg(&dev->dev, "%s - ERROR %x\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 return status;
311 }
312
Alan Cox2742fd82008-04-29 14:45:15 +0100313 if (read_length > 1)
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +0100314 usb_serial_debug_data(&dev->dev, __func__, read_length, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
316 /* Update pointers/length */
317 start_address += read_length;
318 buffer += read_length;
319 length -= read_length;
320 }
Alan Cox2742fd82008-04-29 14:45:15 +0100321
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 return status;
323}
324
Alan Cox2742fd82008-04-29 14:45:15 +0100325static int read_ram(struct usb_device *dev, int start_address,
326 int length, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327{
Alan Cox2742fd82008-04-29 14:45:15 +0100328 return read_download_mem(dev, start_address, length,
329 DTK_ADDR_SPACE_XDATA, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330}
331
332/* Read edgeport memory to a given block */
Alan Cox2742fd82008-04-29 14:45:15 +0100333static int read_boot_mem(struct edgeport_serial *serial,
334 int start_address, int length, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335{
336 int status = 0;
337 int i;
338
Alan Cox2742fd82008-04-29 14:45:15 +0100339 for (i = 0; i < length; i++) {
340 status = ti_vread_sync(serial->serial->dev,
341 UMPC_MEMORY_READ, serial->TI_I2C_Type,
342 (__u16)(start_address+i), &buffer[i], 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 if (status) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700344 dev_dbg(&serial->serial->dev->dev, "%s - ERROR %x\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 return status;
346 }
347 }
348
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700349 dev_dbg(&serial->serial->dev->dev, "%s - start_address = %x, length = %d\n",
350 __func__, start_address, length);
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +0100351 usb_serial_debug_data(&serial->serial->dev->dev, __func__, length, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353 serial->TiReadI2C = 1;
354
355 return status;
356}
357
358/* Write given block to TI EPROM memory */
Alan Cox2742fd82008-04-29 14:45:15 +0100359static int write_boot_mem(struct edgeport_serial *serial,
360 int start_address, int length, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361{
362 int status = 0;
363 int i;
Johan Hovolde9305d22009-12-28 23:01:50 +0100364 u8 *temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
366 /* Must do a read before write */
367 if (!serial->TiReadI2C) {
Johan Hovolde9305d22009-12-28 23:01:50 +0100368 temp = kmalloc(1, GFP_KERNEL);
369 if (!temp) {
370 dev_err(&serial->serial->dev->dev,
371 "%s - out of memory\n", __func__);
372 return -ENOMEM;
373 }
374 status = read_boot_mem(serial, 0, 1, temp);
375 kfree(temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 if (status)
377 return status;
378 }
379
Alan Cox2742fd82008-04-29 14:45:15 +0100380 for (i = 0; i < length; ++i) {
381 status = ti_vsend_sync(serial->serial->dev,
382 UMPC_MEMORY_WRITE, buffer[i],
383 (__u16)(i + start_address), NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 if (status)
385 return status;
386 }
387
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700388 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 +0100389 usb_serial_debug_data(&serial->serial->dev->dev, __func__, length, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
391 return status;
392}
393
394
395/* Write edgeport I2C memory to TI chip */
Alan Cox2742fd82008-04-29 14:45:15 +0100396static int write_i2c_mem(struct edgeport_serial *serial,
397 int start_address, int length, __u8 address_type, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700399 struct device *dev = &serial->serial->dev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 int status = 0;
401 int write_length;
402 __be16 be_start_address;
403
404 /* We can only send a maximum of 1 aligned byte page at a time */
Alan Cox2742fd82008-04-29 14:45:15 +0100405
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300406 /* calculate the number of bytes left in the first page */
Alan Cox2742fd82008-04-29 14:45:15 +0100407 write_length = EPROM_PAGE_SIZE -
408 (start_address & (EPROM_PAGE_SIZE - 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
410 if (write_length > length)
411 write_length = length;
412
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700413 dev_dbg(dev, "%s - BytesInFirstPage Addr = %x, length = %d\n",
414 __func__, start_address, write_length);
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +0100415 usb_serial_debug_data(dev, __func__, write_length, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
417 /* Write first page */
Alan Cox2742fd82008-04-29 14:45:15 +0100418 be_start_address = cpu_to_be16(start_address);
419 status = ti_vsend_sync(serial->serial->dev,
420 UMPC_MEMORY_WRITE, (__u16)address_type,
421 (__force __u16)be_start_address,
422 buffer, write_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 if (status) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700424 dev_dbg(dev, "%s - ERROR %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 return status;
426 }
427
428 length -= write_length;
429 start_address += write_length;
430 buffer += write_length;
431
Alan Cox2742fd82008-04-29 14:45:15 +0100432 /* We should be aligned now -- can write
433 max page size bytes at a time */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 while (length) {
435 if (length > EPROM_PAGE_SIZE)
436 write_length = EPROM_PAGE_SIZE;
437 else
438 write_length = length;
439
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700440 dev_dbg(dev, "%s - Page Write Addr = %x, length = %d\n",
441 __func__, start_address, write_length);
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +0100442 usb_serial_debug_data(dev, __func__, write_length, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
444 /* Write next page */
Alan Cox2742fd82008-04-29 14:45:15 +0100445 be_start_address = cpu_to_be16(start_address);
446 status = ti_vsend_sync(serial->serial->dev, UMPC_MEMORY_WRITE,
447 (__u16)address_type,
448 (__force __u16)be_start_address,
449 buffer, write_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 if (status) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700451 dev_err(dev, "%s - ERROR %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 return status;
453 }
Alan Cox2742fd82008-04-29 14:45:15 +0100454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 length -= write_length;
456 start_address += write_length;
457 buffer += write_length;
458 }
459 return status;
460}
461
462/* Examine the UMP DMA registers and LSR
Alan Cox2742fd82008-04-29 14:45:15 +0100463 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 * Check the MSBit of the X and Y DMA byte count registers.
465 * A zero in this bit indicates that the TX DMA buffers are empty
466 * then check the TX Empty bit in the UART.
467 */
Alan Cox2742fd82008-04-29 14:45:15 +0100468static int tx_active(struct edgeport_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469{
470 int status;
471 struct out_endpoint_desc_block *oedb;
472 __u8 *lsr;
473 int bytes_left = 0;
474
Alan Cox2742fd82008-04-29 14:45:15 +0100475 oedb = kmalloc(sizeof(*oedb), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 if (!oedb) {
Alan Cox2742fd82008-04-29 14:45:15 +0100477 dev_err(&port->port->dev, "%s - out of memory\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 return -ENOMEM;
479 }
480
Alan Cox2742fd82008-04-29 14:45:15 +0100481 lsr = kmalloc(1, GFP_KERNEL); /* Sigh, that's right, just one byte,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 as not all platforms can do DMA
483 from stack */
484 if (!lsr) {
485 kfree(oedb);
486 return -ENOMEM;
487 }
488 /* Read the DMA Count Registers */
Alan Cox2742fd82008-04-29 14:45:15 +0100489 status = read_ram(port->port->serial->dev, port->dma_address,
490 sizeof(*oedb), (void *)oedb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 if (status)
492 goto exit_is_tx_active;
493
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700494 dev_dbg(&port->port->dev, "%s - XByteCount 0x%X\n", __func__, oedb->XByteCount);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
496 /* and the LSR */
Alan Cox2742fd82008-04-29 14:45:15 +0100497 status = read_ram(port->port->serial->dev,
498 port->uart_base + UMPMEM_OFFS_UART_LSR, 1, lsr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
500 if (status)
501 goto exit_is_tx_active;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700502 dev_dbg(&port->port->dev, "%s - LSR = 0x%X\n", __func__, *lsr);
Alan Cox2742fd82008-04-29 14:45:15 +0100503
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 /* If either buffer has data or we are transmitting then return TRUE */
Alan Cox2742fd82008-04-29 14:45:15 +0100505 if ((oedb->XByteCount & 0x80) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 bytes_left += 64;
507
Alan Cox2742fd82008-04-29 14:45:15 +0100508 if ((*lsr & UMP_UART_LSR_TX_MASK) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 bytes_left += 1;
510
511 /* We return Not Active if we get any kind of error */
512exit_is_tx_active:
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700513 dev_dbg(&port->port->dev, "%s - return %d\n", __func__, bytes_left);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
515 kfree(lsr);
516 kfree(oedb);
517 return bytes_left;
518}
519
Alan Cox2742fd82008-04-29 14:45:15 +0100520static int choose_config(struct usb_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521{
Alan Cox2742fd82008-04-29 14:45:15 +0100522 /*
523 * There may be multiple configurations on this device, in which case
524 * we would need to read and parse all of them to find out which one
525 * we want. However, we just support one config at this point,
526 * configuration # 1, which is Config Descriptor 0.
527 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700529 dev_dbg(&dev->dev, "%s - Number of Interfaces = %d\n",
530 __func__, dev->config->desc.bNumInterfaces);
531 dev_dbg(&dev->dev, "%s - MAX Power = %d\n",
532 __func__, dev->config->desc.bMaxPower * 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
534 if (dev->config->desc.bNumInterfaces != 1) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700535 dev_err(&dev->dev, "%s - bNumInterfaces is not 1, ERROR!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 return -ENODEV;
537 }
538
539 return 0;
540}
541
Alan Cox2742fd82008-04-29 14:45:15 +0100542static int read_rom(struct edgeport_serial *serial,
543 int start_address, int length, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544{
545 int status;
546
547 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) {
Alan Cox2742fd82008-04-29 14:45:15 +0100548 status = read_download_mem(serial->serial->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 start_address,
550 length,
551 serial->TI_I2C_Type,
552 buffer);
553 } else {
Alan Cox2742fd82008-04-29 14:45:15 +0100554 status = read_boot_mem(serial, start_address, length,
555 buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 return status;
558}
559
Alan Cox2742fd82008-04-29 14:45:15 +0100560static int write_rom(struct edgeport_serial *serial, int start_address,
561 int length, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562{
563 if (serial->product_info.TiMode == TI_MODE_BOOT)
Alan Cox2742fd82008-04-29 14:45:15 +0100564 return write_boot_mem(serial, start_address, length,
565 buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
567 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD)
Alan Cox2742fd82008-04-29 14:45:15 +0100568 return write_i2c_mem(serial, start_address, length,
569 serial->TI_I2C_Type, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 return -EINVAL;
571}
572
573
574
575/* Read a descriptor header from I2C based on type */
Alan Cox2742fd82008-04-29 14:45:15 +0100576static int get_descriptor_addr(struct edgeport_serial *serial,
577 int desc_type, struct ti_i2c_desc *rom_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578{
579 int start_address;
580 int status;
581
582 /* Search for requested descriptor in I2C */
583 start_address = 2;
584 do {
Alan Cox2742fd82008-04-29 14:45:15 +0100585 status = read_rom(serial,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 start_address,
587 sizeof(struct ti_i2c_desc),
Alan Cox2742fd82008-04-29 14:45:15 +0100588 (__u8 *)rom_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 if (status)
590 return 0;
591
592 if (rom_desc->Type == desc_type)
593 return start_address;
594
Alan Cox2742fd82008-04-29 14:45:15 +0100595 start_address = start_address + sizeof(struct ti_i2c_desc)
596 + rom_desc->Size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
598 } while ((start_address < TI_MAX_I2C_SIZE) && rom_desc->Type);
Alan Cox2742fd82008-04-29 14:45:15 +0100599
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 return 0;
601}
602
603/* Validate descriptor checksum */
Alan Cox2742fd82008-04-29 14:45:15 +0100604static int valid_csum(struct ti_i2c_desc *rom_desc, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605{
606 __u16 i;
607 __u8 cs = 0;
608
Alan Cox2742fd82008-04-29 14:45:15 +0100609 for (i = 0; i < rom_desc->Size; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 cs = (__u8)(cs + buffer[i]);
Alan Cox2742fd82008-04-29 14:45:15 +0100611
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 if (cs != rom_desc->CheckSum) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700613 pr_debug("%s - Mismatch %x - %x", __func__, rom_desc->CheckSum, cs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 return -EINVAL;
615 }
616 return 0;
617}
618
619/* Make sure that the I2C image is good */
Alan Cox2742fd82008-04-29 14:45:15 +0100620static int check_i2c_image(struct edgeport_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621{
622 struct device *dev = &serial->serial->dev->dev;
623 int status = 0;
624 struct ti_i2c_desc *rom_desc;
625 int start_address = 2;
626 __u8 *buffer;
627 __u16 ttype;
628
Alan Cox2742fd82008-04-29 14:45:15 +0100629 rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 if (!rom_desc) {
Alan Cox2742fd82008-04-29 14:45:15 +0100631 dev_err(dev, "%s - out of memory\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 return -ENOMEM;
633 }
Alan Cox2742fd82008-04-29 14:45:15 +0100634 buffer = kmalloc(TI_MAX_I2C_SIZE, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 if (!buffer) {
Alan Cox2742fd82008-04-29 14:45:15 +0100636 dev_err(dev, "%s - out of memory when allocating buffer\n",
637 __func__);
638 kfree(rom_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 return -ENOMEM;
640 }
641
Alan Cox2742fd82008-04-29 14:45:15 +0100642 /* Read the first byte (Signature0) must be 0x52 or 0x10 */
643 status = read_rom(serial, 0, 1, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 if (status)
Alan Cox2742fd82008-04-29 14:45:15 +0100645 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
647 if (*buffer != UMP5152 && *buffer != UMP3410) {
Alan Cox2742fd82008-04-29 14:45:15 +0100648 dev_err(dev, "%s - invalid buffer signature\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 status = -ENODEV;
Alan Cox2742fd82008-04-29 14:45:15 +0100650 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 }
652
653 do {
Alan Cox2742fd82008-04-29 14:45:15 +0100654 /* Validate the I2C */
655 status = read_rom(serial,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 start_address,
657 sizeof(struct ti_i2c_desc),
658 (__u8 *)rom_desc);
659 if (status)
660 break;
661
Alan Cox2742fd82008-04-29 14:45:15 +0100662 if ((start_address + sizeof(struct ti_i2c_desc) +
663 rom_desc->Size) > TI_MAX_I2C_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 status = -ENODEV;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700665 dev_dbg(dev, "%s - structure too big, erroring out.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 break;
667 }
668
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700669 dev_dbg(dev, "%s Type = 0x%x\n", __func__, rom_desc->Type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
Alan Cox2742fd82008-04-29 14:45:15 +0100671 /* Skip type 2 record */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 ttype = rom_desc->Type & 0x0f;
Alan Cox2742fd82008-04-29 14:45:15 +0100673 if (ttype != I2C_DESC_TYPE_FIRMWARE_BASIC
674 && ttype != I2C_DESC_TYPE_FIRMWARE_AUTO) {
675 /* Read the descriptor data */
676 status = read_rom(serial, start_address +
677 sizeof(struct ti_i2c_desc),
678 rom_desc->Size, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 if (status)
680 break;
681
Alan Cox2742fd82008-04-29 14:45:15 +0100682 status = valid_csum(rom_desc, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 if (status)
684 break;
685 }
Alan Cox2742fd82008-04-29 14:45:15 +0100686 start_address = start_address + sizeof(struct ti_i2c_desc) +
687 rom_desc->Size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Alan Cox2742fd82008-04-29 14:45:15 +0100689 } while ((rom_desc->Type != I2C_DESC_TYPE_ION) &&
690 (start_address < TI_MAX_I2C_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
Alan Cox2742fd82008-04-29 14:45:15 +0100692 if ((rom_desc->Type != I2C_DESC_TYPE_ION) ||
693 (start_address > TI_MAX_I2C_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 status = -ENODEV;
695
Alan Cox2742fd82008-04-29 14:45:15 +0100696out:
697 kfree(buffer);
698 kfree(rom_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 return status;
700}
701
Alan Cox2742fd82008-04-29 14:45:15 +0100702static int get_manuf_info(struct edgeport_serial *serial, __u8 *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703{
704 int status;
705 int start_address;
706 struct ti_i2c_desc *rom_desc;
707 struct edge_ti_manuf_descriptor *desc;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700708 struct device *dev = &serial->serial->dev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
Alan Cox2742fd82008-04-29 14:45:15 +0100710 rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 if (!rom_desc) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700712 dev_err(dev, "%s - out of memory\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 return -ENOMEM;
714 }
Alan Cox2742fd82008-04-29 14:45:15 +0100715 start_address = get_descriptor_addr(serial, I2C_DESC_TYPE_ION,
716 rom_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
718 if (!start_address) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700719 dev_dbg(dev, "%s - Edge Descriptor not found in I2C\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 status = -ENODEV;
721 goto exit;
722 }
723
Alan Cox2742fd82008-04-29 14:45:15 +0100724 /* Read the descriptor data */
725 status = read_rom(serial, start_address+sizeof(struct ti_i2c_desc),
726 rom_desc->Size, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 if (status)
728 goto exit;
Alan Cox2742fd82008-04-29 14:45:15 +0100729
730 status = valid_csum(rom_desc, buffer);
731
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 desc = (struct edge_ti_manuf_descriptor *)buffer;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700733 dev_dbg(dev, "%s - IonConfig 0x%x\n", __func__, desc->IonConfig);
734 dev_dbg(dev, "%s - Version %d\n", __func__, desc->Version);
735 dev_dbg(dev, "%s - Cpu/Board 0x%x\n", __func__, desc->CpuRev_BoardRev);
736 dev_dbg(dev, "%s - NumPorts %d\n", __func__, desc->NumPorts);
737 dev_dbg(dev, "%s - NumVirtualPorts %d\n", __func__, desc->NumVirtualPorts);
738 dev_dbg(dev, "%s - TotalPorts %d\n", __func__, desc->TotalPorts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
740exit:
Alan Cox2742fd82008-04-29 14:45:15 +0100741 kfree(rom_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 return status;
743}
744
745/* Build firmware header used for firmware update */
Alan Cox2742fd82008-04-29 14:45:15 +0100746static int build_i2c_fw_hdr(__u8 *header, struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747{
748 __u8 *buffer;
749 int buffer_size;
750 int i;
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530751 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 __u8 cs = 0;
753 struct ti_i2c_desc *i2c_header;
754 struct ti_i2c_image_header *img_header;
755 struct ti_i2c_firmware_rec *firmware_rec;
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530756 const struct firmware *fw;
757 const char *fw_name = "edgeport/down3.bin";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
Alan Cox2742fd82008-04-29 14:45:15 +0100759 /* In order to update the I2C firmware we must change the type 2 record
760 * to type 0xF2. This will force the UMP to come up in Boot Mode.
761 * Then while in boot mode, the driver will download the latest
762 * firmware (padded to 15.5k) into the UMP ram. And finally when the
763 * device comes back up in download mode the driver will cause the new
764 * firmware to be copied from the UMP Ram to I2C and the firmware will
765 * update the record type from 0xf2 to 0x02.
766 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Alan Cox2742fd82008-04-29 14:45:15 +0100768 /* Allocate a 15.5k buffer + 2 bytes for version number
769 * (Firmware Record) */
770 buffer_size = (((1024 * 16) - 512 ) +
771 sizeof(struct ti_i2c_firmware_rec));
772
773 buffer = kmalloc(buffer_size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 if (!buffer) {
Alan Cox2742fd82008-04-29 14:45:15 +0100775 dev_err(dev, "%s - out of memory\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 return -ENOMEM;
777 }
Alan Cox2742fd82008-04-29 14:45:15 +0100778
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 // Set entire image of 0xffs
Alan Cox2742fd82008-04-29 14:45:15 +0100780 memset(buffer, 0xff, buffer_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530782 err = request_firmware(&fw, fw_name, dev);
783 if (err) {
Greg Kroah-Hartmand9bb03d2012-09-18 16:59:23 +0100784 dev_err(dev, "Failed to load image \"%s\" err %d\n",
785 fw_name, err);
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530786 kfree(buffer);
787 return err;
788 }
789
790 /* Save Download Version Number */
791 OperationalMajorVersion = fw->data[0];
792 OperationalMinorVersion = fw->data[1];
793 OperationalBuildNumber = fw->data[2] | (fw->data[3] << 8);
794
Alan Cox2742fd82008-04-29 14:45:15 +0100795 /* Copy version number into firmware record */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 firmware_rec = (struct ti_i2c_firmware_rec *)buffer;
797
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530798 firmware_rec->Ver_Major = OperationalMajorVersion;
799 firmware_rec->Ver_Minor = OperationalMinorVersion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
Alan Cox2742fd82008-04-29 14:45:15 +0100801 /* Pointer to fw_down memory image */
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530802 img_header = (struct ti_i2c_image_header *)&fw->data[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
Alan Cox2742fd82008-04-29 14:45:15 +0100804 memcpy(buffer + sizeof(struct ti_i2c_firmware_rec),
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530805 &fw->data[4 + sizeof(struct ti_i2c_image_header)],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 le16_to_cpu(img_header->Length));
807
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530808 release_firmware(fw);
809
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 for (i=0; i < buffer_size; i++) {
811 cs = (__u8)(cs + buffer[i]);
812 }
813
Alan Cox2742fd82008-04-29 14:45:15 +0100814 kfree(buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
Alan Cox2742fd82008-04-29 14:45:15 +0100816 /* Build new header */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 i2c_header = (struct ti_i2c_desc *)header;
818 firmware_rec = (struct ti_i2c_firmware_rec*)i2c_header->Data;
Alan Cox2742fd82008-04-29 14:45:15 +0100819
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 i2c_header->Type = I2C_DESC_TYPE_FIRMWARE_BLANK;
821 i2c_header->Size = (__u16)buffer_size;
822 i2c_header->CheckSum = cs;
Jaswinder Singhd12b2192008-07-04 23:06:09 +0530823 firmware_rec->Ver_Major = OperationalMajorVersion;
824 firmware_rec->Ver_Minor = OperationalMinorVersion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
826 return 0;
827}
828
829/* Try to figure out what type of I2c we have */
Alan Cox2742fd82008-04-29 14:45:15 +0100830static int i2c_type_bootmode(struct edgeport_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831{
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700832 struct device *dev = &serial->serial->dev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 int status;
Johan Hovolde9305d22009-12-28 23:01:50 +0100834 u8 *data;
835
836 data = kmalloc(1, GFP_KERNEL);
837 if (!data) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700838 dev_err(dev, "%s - out of memory\n", __func__);
Johan Hovolde9305d22009-12-28 23:01:50 +0100839 return -ENOMEM;
840 }
Alan Cox2742fd82008-04-29 14:45:15 +0100841
842 /* Try to read type 2 */
843 status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ,
Johan Hovolde9305d22009-12-28 23:01:50 +0100844 DTK_ADDR_SPACE_I2C_TYPE_II, 0, data, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 if (status)
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700846 dev_dbg(dev, "%s - read 2 status error = %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 else
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700848 dev_dbg(dev, "%s - read 2 data = 0x%x\n", __func__, *data);
Johan Hovolde9305d22009-12-28 23:01:50 +0100849 if ((!status) && (*data == UMP5152 || *data == UMP3410)) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700850 dev_dbg(dev, "%s - ROM_TYPE_II\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
Johan Hovolde9305d22009-12-28 23:01:50 +0100852 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 }
854
Alan Cox2742fd82008-04-29 14:45:15 +0100855 /* Try to read type 3 */
856 status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ,
Johan Hovolde9305d22009-12-28 23:01:50 +0100857 DTK_ADDR_SPACE_I2C_TYPE_III, 0, data, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 if (status)
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700859 dev_dbg(dev, "%s - read 3 status error = %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 else
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700861 dev_dbg(dev, "%s - read 2 data = 0x%x\n", __func__, *data);
Johan Hovolde9305d22009-12-28 23:01:50 +0100862 if ((!status) && (*data == UMP5152 || *data == UMP3410)) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700863 dev_dbg(dev, "%s - ROM_TYPE_III\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_III;
Johan Hovolde9305d22009-12-28 23:01:50 +0100865 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 }
867
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700868 dev_dbg(dev, "%s - Unknown\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
Johan Hovolde9305d22009-12-28 23:01:50 +0100870 status = -ENODEV;
871out:
872 kfree(data);
873 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874}
875
Alan Cox2742fd82008-04-29 14:45:15 +0100876static int bulk_xfer(struct usb_serial *serial, void *buffer,
877 int length, int *num_sent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878{
879 int status;
880
Alan Cox2742fd82008-04-29 14:45:15 +0100881 status = usb_bulk_msg(serial->dev,
882 usb_sndbulkpipe(serial->dev,
883 serial->port[0]->bulk_out_endpointAddress),
884 buffer, length, num_sent, 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 return status;
886}
887
888/* Download given firmware image to the device (IN BOOT MODE) */
Alan Cox2742fd82008-04-29 14:45:15 +0100889static int download_code(struct edgeport_serial *serial, __u8 *image,
890 int image_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891{
892 int status = 0;
893 int pos;
894 int transfer;
895 int done;
896
Alan Cox2742fd82008-04-29 14:45:15 +0100897 /* Transfer firmware image */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 for (pos = 0; pos < image_length; ) {
Alan Cox2742fd82008-04-29 14:45:15 +0100899 /* Read the next buffer from file */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 transfer = image_length - pos;
901 if (transfer > EDGE_FW_BULK_MAX_PACKET_SIZE)
902 transfer = EDGE_FW_BULK_MAX_PACKET_SIZE;
903
Alan Cox2742fd82008-04-29 14:45:15 +0100904 /* Transfer data */
905 status = bulk_xfer(serial->serial, &image[pos],
906 transfer, &done);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 if (status)
908 break;
Alan Cox2742fd82008-04-29 14:45:15 +0100909 /* Advance buffer pointer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 pos += done;
911 }
912
913 return status;
914}
915
Alan Cox2742fd82008-04-29 14:45:15 +0100916/* FIXME!!! */
917static int config_boot_dev(struct usb_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918{
919 return 0;
920}
921
Alan Cox2742fd82008-04-29 14:45:15 +0100922static int ti_cpu_rev(struct edge_ti_manuf_descriptor *desc)
923{
924 return TI_GET_CPU_REVISION(desc->CpuRev_BoardRev);
925}
926
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927/**
928 * DownloadTIFirmware - Download run-time operating firmware to the TI5052
Alan Cox2742fd82008-04-29 14:45:15 +0100929 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 * This routine downloads the main operating code into the TI5052, using the
931 * boot code already burned into E2PROM or ROM.
932 */
Alan Cox2742fd82008-04-29 14:45:15 +0100933static int download_fw(struct edgeport_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934{
935 struct device *dev = &serial->serial->dev->dev;
936 int status = 0;
937 int start_address;
938 struct edge_ti_manuf_descriptor *ti_manuf_desc;
939 struct usb_interface_descriptor *interface;
940 int download_cur_ver;
941 int download_new_ver;
942
943 /* This routine is entered by both the BOOT mode and the Download mode
944 * We can determine which code is running by the reading the config
945 * descriptor and if we have only one bulk pipe it is in boot mode
946 */
947 serial->product_info.hardware_type = HARDWARE_TYPE_TIUMP;
948
949 /* Default to type 2 i2c */
950 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
951
Alan Cox2742fd82008-04-29 14:45:15 +0100952 status = choose_config(serial->serial->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 if (status)
954 return status;
955
956 interface = &serial->serial->interface->cur_altsetting->desc;
957 if (!interface) {
Alan Cox2742fd82008-04-29 14:45:15 +0100958 dev_err(dev, "%s - no interface set, error!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 return -ENODEV;
960 }
961
Alan Cox2742fd82008-04-29 14:45:15 +0100962 /*
963 * Setup initial mode -- the default mode 0 is TI_MODE_CONFIGURING
964 * if we have more than one endpoint we are definitely in download
965 * mode
966 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 if (interface->bNumEndpoints > 1)
968 serial->product_info.TiMode = TI_MODE_DOWNLOAD;
969 else
Alan Cox2742fd82008-04-29 14:45:15 +0100970 /* Otherwise we will remain in configuring mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 serial->product_info.TiMode = TI_MODE_CONFIGURING;
972
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 /********************************************************************/
974 /* Download Mode */
975 /********************************************************************/
976 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) {
977 struct ti_i2c_desc *rom_desc;
978
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700979 dev_dbg(dev, "%s - RUNNING IN DOWNLOAD MODE\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
Alan Cox2742fd82008-04-29 14:45:15 +0100981 status = check_i2c_image(serial);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 if (status) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -0700983 dev_dbg(dev, "%s - DOWNLOAD MODE -- BAD I2C\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 return status;
985 }
Alan Cox2742fd82008-04-29 14:45:15 +0100986
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 /* Validate Hardware version number
988 * Read Manufacturing Descriptor from TI Based Edgeport
989 */
Alan Cox2742fd82008-04-29 14:45:15 +0100990 ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 if (!ti_manuf_desc) {
Alan Cox2742fd82008-04-29 14:45:15 +0100992 dev_err(dev, "%s - out of memory.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 return -ENOMEM;
994 }
Alan Cox2742fd82008-04-29 14:45:15 +0100995 status = get_manuf_info(serial, (__u8 *)ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +0100997 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 return status;
999 }
1000
Alan Cox2742fd82008-04-29 14:45:15 +01001001 /* Check version number of ION descriptor */
1002 if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001003 dev_dbg(dev, "%s - Wrong CPU Rev %d (Must be 2)\n",
Alan Cox2742fd82008-04-29 14:45:15 +01001004 __func__, ti_cpu_rev(ti_manuf_desc));
1005 kfree(ti_manuf_desc);
1006 return -EINVAL;
1007 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
Alan Cox2742fd82008-04-29 14:45:15 +01001009 rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 if (!rom_desc) {
Alan Cox2742fd82008-04-29 14:45:15 +01001011 dev_err(dev, "%s - out of memory.\n", __func__);
1012 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 return -ENOMEM;
1014 }
1015
Alan Cox2742fd82008-04-29 14:45:15 +01001016 /* Search for type 2 record (firmware record) */
1017 start_address = get_descriptor_addr(serial,
1018 I2C_DESC_TYPE_FIRMWARE_BASIC, rom_desc);
1019 if (start_address != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 struct ti_i2c_firmware_rec *firmware_version;
Johan Hovolde9305d22009-12-28 23:01:50 +01001021 u8 *record;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001023 dev_dbg(dev, "%s - Found Type FIRMWARE (Type 2) record\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
Alan Cox2742fd82008-04-29 14:45:15 +01001025 firmware_version = kmalloc(sizeof(*firmware_version),
1026 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 if (!firmware_version) {
Alan Cox2742fd82008-04-29 14:45:15 +01001028 dev_err(dev, "%s - out of memory.\n", __func__);
1029 kfree(rom_desc);
1030 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 return -ENOMEM;
1032 }
1033
Alan Cox2742fd82008-04-29 14:45:15 +01001034 /* Validate version number
1035 * Read the descriptor data
1036 */
1037 status = read_rom(serial, start_address +
1038 sizeof(struct ti_i2c_desc),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 sizeof(struct ti_i2c_firmware_rec),
1040 (__u8 *)firmware_version);
1041 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001042 kfree(firmware_version);
1043 kfree(rom_desc);
1044 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 return status;
1046 }
1047
Alan Cox2742fd82008-04-29 14:45:15 +01001048 /* Check version number of download with current
1049 version in I2c */
1050 download_cur_ver = (firmware_version->Ver_Major << 8) +
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 (firmware_version->Ver_Minor);
Jaswinder Singhd12b2192008-07-04 23:06:09 +05301052 download_new_ver = (OperationalMajorVersion << 8) +
1053 (OperationalMinorVersion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001055 dev_dbg(dev, "%s - >> FW Versions Device %d.%d Driver %d.%d\n",
1056 __func__, firmware_version->Ver_Major,
1057 firmware_version->Ver_Minor,
1058 OperationalMajorVersion,
1059 OperationalMinorVersion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
Alan Cox2742fd82008-04-29 14:45:15 +01001061 /* Check if we have an old version in the I2C and
1062 update if necessary */
Greg Kroah-Hartman0827a9f2010-08-17 15:15:37 -07001063 if (download_cur_ver < download_new_ver) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001064 dev_dbg(dev, "%s - Update I2C dld from %d.%d to %d.%d\n",
1065 __func__,
1066 firmware_version->Ver_Major,
1067 firmware_version->Ver_Minor,
1068 OperationalMajorVersion,
1069 OperationalMinorVersion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070
Johan Hovolde9305d22009-12-28 23:01:50 +01001071 record = kmalloc(1, GFP_KERNEL);
1072 if (!record) {
1073 dev_err(dev, "%s - out of memory.\n",
1074 __func__);
1075 kfree(firmware_version);
1076 kfree(rom_desc);
1077 kfree(ti_manuf_desc);
1078 return -ENOMEM;
1079 }
Alan Cox2742fd82008-04-29 14:45:15 +01001080 /* In order to update the I2C firmware we must
1081 * change the type 2 record to type 0xF2. This
1082 * will force the UMP to come up in Boot Mode.
1083 * Then while in boot mode, the driver will
1084 * download the latest firmware (padded to
1085 * 15.5k) into the UMP ram. Finally when the
1086 * device comes back up in download mode the
1087 * driver will cause the new firmware to be
1088 * copied from the UMP Ram to I2C and the
1089 * firmware will update the record type from
1090 * 0xf2 to 0x02.
1091 */
Johan Hovolde9305d22009-12-28 23:01:50 +01001092 *record = I2C_DESC_TYPE_FIRMWARE_BLANK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
Alan Cox2742fd82008-04-29 14:45:15 +01001094 /* Change the I2C Firmware record type to
1095 0xf2 to trigger an update */
1096 status = write_rom(serial, start_address,
Johan Hovolde9305d22009-12-28 23:01:50 +01001097 sizeof(*record), record);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 if (status) {
Johan Hovolde9305d22009-12-28 23:01:50 +01001099 kfree(record);
Alan Cox2742fd82008-04-29 14:45:15 +01001100 kfree(firmware_version);
1101 kfree(rom_desc);
1102 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 return status;
1104 }
1105
Alan Cox2742fd82008-04-29 14:45:15 +01001106 /* verify the write -- must do this in order
1107 * for write to complete before we do the
1108 * hardware reset
1109 */
1110 status = read_rom(serial,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 start_address,
Johan Hovolde9305d22009-12-28 23:01:50 +01001112 sizeof(*record),
1113 record);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 if (status) {
Johan Hovolde9305d22009-12-28 23:01:50 +01001115 kfree(record);
Alan Cox2742fd82008-04-29 14:45:15 +01001116 kfree(firmware_version);
1117 kfree(rom_desc);
1118 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 return status;
1120 }
1121
Johan Hovolde9305d22009-12-28 23:01:50 +01001122 if (*record != I2C_DESC_TYPE_FIRMWARE_BLANK) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001123 dev_err(dev, "%s - error resetting device\n", __func__);
Johan Hovolde9305d22009-12-28 23:01:50 +01001124 kfree(record);
Alan Cox2742fd82008-04-29 14:45:15 +01001125 kfree(firmware_version);
1126 kfree(rom_desc);
1127 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 return -ENODEV;
1129 }
1130
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001131 dev_dbg(dev, "%s - HARDWARE RESET\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
Alan Cox2742fd82008-04-29 14:45:15 +01001133 /* Reset UMP -- Back to BOOT MODE */
1134 status = ti_vsend_sync(serial->serial->dev,
1135 UMPC_HARDWARE_RESET,
1136 0, 0, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001138 dev_dbg(dev, "%s - HARDWARE RESET return %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
1140 /* return an error on purpose. */
Johan Hovolde9305d22009-12-28 23:01:50 +01001141 kfree(record);
Alan Cox2742fd82008-04-29 14:45:15 +01001142 kfree(firmware_version);
1143 kfree(rom_desc);
1144 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 return -ENODEV;
1146 }
Alan Cox2742fd82008-04-29 14:45:15 +01001147 kfree(firmware_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 }
Alan Cox2742fd82008-04-29 14:45:15 +01001149 /* Search for type 0xF2 record (firmware blank record) */
1150 else if ((start_address = get_descriptor_addr(serial, I2C_DESC_TYPE_FIRMWARE_BLANK, rom_desc)) != 0) {
1151#define HEADER_SIZE (sizeof(struct ti_i2c_desc) + \
1152 sizeof(struct ti_i2c_firmware_rec))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 __u8 *header;
1154 __u8 *vheader;
1155
Alan Cox2742fd82008-04-29 14:45:15 +01001156 header = kmalloc(HEADER_SIZE, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 if (!header) {
Alan Cox2742fd82008-04-29 14:45:15 +01001158 dev_err(dev, "%s - out of memory.\n", __func__);
1159 kfree(rom_desc);
1160 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 return -ENOMEM;
1162 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163
Alan Cox2742fd82008-04-29 14:45:15 +01001164 vheader = kmalloc(HEADER_SIZE, GFP_KERNEL);
1165 if (!vheader) {
1166 dev_err(dev, "%s - out of memory.\n", __func__);
1167 kfree(header);
1168 kfree(rom_desc);
1169 kfree(ti_manuf_desc);
1170 return -ENOMEM;
1171 }
1172
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001173 dev_dbg(dev, "%s - Found Type BLANK FIRMWARE (Type F2) record\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01001174
1175 /*
1176 * In order to update the I2C firmware we must change
1177 * the type 2 record to type 0xF2. This will force the
1178 * UMP to come up in Boot Mode. Then while in boot
1179 * mode, the driver will download the latest firmware
1180 * (padded to 15.5k) into the UMP ram. Finally when the
1181 * device comes back up in download mode the driver
1182 * will cause the new firmware to be copied from the
1183 * UMP Ram to I2C and the firmware will update the
1184 * record type from 0xf2 to 0x02.
1185 */
1186 status = build_i2c_fw_hdr(header, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001188 kfree(vheader);
1189 kfree(header);
1190 kfree(rom_desc);
1191 kfree(ti_manuf_desc);
Roel Kluinfd6e5bb2010-08-10 14:29:19 -07001192 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 }
1194
Alan Cox2742fd82008-04-29 14:45:15 +01001195 /* Update I2C with type 0xf2 record with correct
1196 size and checksum */
1197 status = write_rom(serial,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 start_address,
1199 HEADER_SIZE,
1200 header);
1201 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001202 kfree(vheader);
1203 kfree(header);
1204 kfree(rom_desc);
1205 kfree(ti_manuf_desc);
Roel Kluin9800eb32010-07-20 15:29:08 -07001206 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 }
1208
Alan Cox2742fd82008-04-29 14:45:15 +01001209 /* verify the write -- must do this in order for
1210 write to complete before we do the hardware reset */
1211 status = read_rom(serial, start_address,
1212 HEADER_SIZE, vheader);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213
1214 if (status) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001215 dev_dbg(dev, "%s - can't read header back\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01001216 kfree(vheader);
1217 kfree(header);
1218 kfree(rom_desc);
1219 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 return status;
1221 }
1222 if (memcmp(vheader, header, HEADER_SIZE)) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001223 dev_dbg(dev, "%s - write download record failed\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01001224 kfree(vheader);
1225 kfree(header);
1226 kfree(rom_desc);
1227 kfree(ti_manuf_desc);
Roel Kluin1e297092010-07-02 00:36:43 +02001228 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 }
1230
Alan Cox2742fd82008-04-29 14:45:15 +01001231 kfree(vheader);
1232 kfree(header);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001234 dev_dbg(dev, "%s - Start firmware update\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235
Alan Cox2742fd82008-04-29 14:45:15 +01001236 /* Tell firmware to copy download image into I2C */
1237 status = ti_vsend_sync(serial->serial->dev,
1238 UMPC_COPY_DNLD_TO_I2C, 0, 0, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001240 dev_dbg(dev, "%s - Update complete 0x%x\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001242 dev_err(dev,
1243 "%s - UMPC_COPY_DNLD_TO_I2C failed\n",
1244 __func__);
1245 kfree(rom_desc);
1246 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 return status;
1248 }
1249 }
1250
1251 // The device is running the download code
Alan Cox2742fd82008-04-29 14:45:15 +01001252 kfree(rom_desc);
1253 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 return 0;
1255 }
1256
1257 /********************************************************************/
1258 /* Boot Mode */
1259 /********************************************************************/
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001260 dev_dbg(dev, "%s - RUNNING IN BOOT MODE\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
Alan Cox2742fd82008-04-29 14:45:15 +01001262 /* Configure the TI device so we can use the BULK pipes for download */
1263 status = config_boot_dev(serial->serial->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 if (status)
1265 return status;
1266
Alan Cox2742fd82008-04-29 14:45:15 +01001267 if (le16_to_cpu(serial->serial->dev->descriptor.idVendor)
1268 != USB_VENDOR_ID_ION) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001269 dev_dbg(dev, "%s - VID = 0x%x\n", __func__,
1270 le16_to_cpu(serial->serial->dev->descriptor.idVendor));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
Alan Cox2742fd82008-04-29 14:45:15 +01001272 goto stayinbootmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 }
1274
Alan Cox2742fd82008-04-29 14:45:15 +01001275 /* We have an ION device (I2c Must be programmed)
1276 Determine I2C image type */
1277 if (i2c_type_bootmode(serial))
1278 goto stayinbootmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
Alan Cox2742fd82008-04-29 14:45:15 +01001280 /* Check for ION Vendor ID and that the I2C is valid */
1281 if (!check_i2c_image(serial)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 struct ti_i2c_image_header *header;
1283 int i;
1284 __u8 cs = 0;
1285 __u8 *buffer;
1286 int buffer_size;
Jaswinder Singhd12b2192008-07-04 23:06:09 +05301287 int err;
1288 const struct firmware *fw;
1289 const char *fw_name = "edgeport/down3.bin";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
1291 /* Validate Hardware version number
1292 * Read Manufacturing Descriptor from TI Based Edgeport
1293 */
Alan Cox2742fd82008-04-29 14:45:15 +01001294 ti_manuf_desc = kmalloc(sizeof(*ti_manuf_desc), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 if (!ti_manuf_desc) {
Alan Cox2742fd82008-04-29 14:45:15 +01001296 dev_err(dev, "%s - out of memory.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 return -ENOMEM;
1298 }
Alan Cox2742fd82008-04-29 14:45:15 +01001299 status = get_manuf_info(serial, (__u8 *)ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001301 kfree(ti_manuf_desc);
1302 goto stayinbootmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 }
1304
Alan Cox2742fd82008-04-29 14:45:15 +01001305 /* Check for version 2 */
1306 if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001307 dev_dbg(dev, "%s - Wrong CPU Rev %d (Must be 2)\n",
1308 __func__, ti_cpu_rev(ti_manuf_desc));
Alan Cox2742fd82008-04-29 14:45:15 +01001309 kfree(ti_manuf_desc);
1310 goto stayinbootmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 }
1312
Alan Cox2742fd82008-04-29 14:45:15 +01001313 kfree(ti_manuf_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 /*
Alan Cox2742fd82008-04-29 14:45:15 +01001316 * In order to update the I2C firmware we must change the type
1317 * 2 record to type 0xF2. This will force the UMP to come up
1318 * in Boot Mode. Then while in boot mode, the driver will
1319 * download the latest firmware (padded to 15.5k) into the
1320 * UMP ram. Finally when the device comes back up in download
1321 * mode the driver will cause the new firmware to be copied
1322 * from the UMP Ram to I2C and the firmware will update the
1323 * record type from 0xf2 to 0x02.
1324 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 * Do we really have to copy the whole firmware image,
1326 * or could we do this in place!
1327 */
1328
Alan Cox2742fd82008-04-29 14:45:15 +01001329 /* Allocate a 15.5k buffer + 3 byte header */
1330 buffer_size = (((1024 * 16) - 512) +
1331 sizeof(struct ti_i2c_image_header));
1332 buffer = kmalloc(buffer_size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 if (!buffer) {
Alan Cox2742fd82008-04-29 14:45:15 +01001334 dev_err(dev, "%s - out of memory\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 return -ENOMEM;
1336 }
Alan Cox2742fd82008-04-29 14:45:15 +01001337
1338 /* Initialize the buffer to 0xff (pad the buffer) */
1339 memset(buffer, 0xff, buffer_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340
Jaswinder Singhd12b2192008-07-04 23:06:09 +05301341 err = request_firmware(&fw, fw_name, dev);
1342 if (err) {
Greg Kroah-Hartmand9bb03d2012-09-18 16:59:23 +01001343 dev_err(dev, "Failed to load image \"%s\" err %d\n",
1344 fw_name, err);
Jaswinder Singhd12b2192008-07-04 23:06:09 +05301345 kfree(buffer);
1346 return err;
1347 }
1348 memcpy(buffer, &fw->data[4], fw->size - 4);
1349 release_firmware(fw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350
Alan Cox2742fd82008-04-29 14:45:15 +01001351 for (i = sizeof(struct ti_i2c_image_header);
1352 i < buffer_size; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 cs = (__u8)(cs + buffer[i]);
1354 }
Alan Cox2742fd82008-04-29 14:45:15 +01001355
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 header = (struct ti_i2c_image_header *)buffer;
Alan Cox2742fd82008-04-29 14:45:15 +01001357
1358 /* update length and checksum after padding */
1359 header->Length = cpu_to_le16((__u16)(buffer_size -
1360 sizeof(struct ti_i2c_image_header)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 header->CheckSum = cs;
1362
Alan Cox2742fd82008-04-29 14:45:15 +01001363 /* Download the operational code */
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001364 dev_dbg(dev, "%s - Downloading operational code image (TI UMP)\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01001365 status = download_code(serial, buffer, buffer_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
Alan Cox2742fd82008-04-29 14:45:15 +01001367 kfree(buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368
1369 if (status) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001370 dev_dbg(dev, "%s - Error downloading operational code image\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 return status;
1372 }
1373
Alan Cox2742fd82008-04-29 14:45:15 +01001374 /* Device will reboot */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 serial->product_info.TiMode = TI_MODE_TRANSITIONING;
1376
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001377 dev_dbg(dev, "%s - Download successful -- Device rebooting...\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378
1379 /* return an error on purpose */
1380 return -ENODEV;
1381 }
1382
Alan Cox2742fd82008-04-29 14:45:15 +01001383stayinbootmode:
1384 /* Eprom is invalid or blank stay in boot mode */
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001385 dev_dbg(dev, "%s - STAYING IN BOOT MODE\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 serial->product_info.TiMode = TI_MODE_BOOT;
1387
1388 return 0;
1389}
1390
1391
Alan Cox2742fd82008-04-29 14:45:15 +01001392static int ti_do_config(struct edgeport_port *port, int feature, int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393{
1394 int port_number = port->port->number - port->port->serial->minor;
Alan Cox2742fd82008-04-29 14:45:15 +01001395 on = !!on; /* 1 or 0 not bitmask */
1396 return send_cmd(port->port->serial->dev,
1397 feature, (__u8)(UMPM_UART1_PORT + port_number),
1398 on, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399}
1400
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401
Alan Cox2742fd82008-04-29 14:45:15 +01001402static int restore_mcr(struct edgeport_port *port, __u8 mcr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403{
1404 int status = 0;
1405
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001406 dev_dbg(&port->port->dev, "%s - %x\n", __func__, mcr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407
Alan Cox2742fd82008-04-29 14:45:15 +01001408 status = ti_do_config(port, UMPC_SET_CLR_DTR, mcr & MCR_DTR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 if (status)
1410 return status;
Alan Cox2742fd82008-04-29 14:45:15 +01001411 status = ti_do_config(port, UMPC_SET_CLR_RTS, mcr & MCR_RTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 if (status)
1413 return status;
Alan Cox2742fd82008-04-29 14:45:15 +01001414 return ti_do_config(port, UMPC_SET_CLR_LOOPBACK, mcr & MCR_LOOPBACK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415}
1416
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417/* Convert TI LSR to standard UART flags */
Alan Cox2742fd82008-04-29 14:45:15 +01001418static __u8 map_line_status(__u8 ti_lsr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419{
1420 __u8 lsr = 0;
1421
1422#define MAP_FLAG(flagUmp, flagUart) \
1423 if (ti_lsr & flagUmp) \
1424 lsr |= flagUart;
1425
1426 MAP_FLAG(UMP_UART_LSR_OV_MASK, LSR_OVER_ERR) /* overrun */
1427 MAP_FLAG(UMP_UART_LSR_PE_MASK, LSR_PAR_ERR) /* parity error */
1428 MAP_FLAG(UMP_UART_LSR_FE_MASK, LSR_FRM_ERR) /* framing error */
1429 MAP_FLAG(UMP_UART_LSR_BR_MASK, LSR_BREAK) /* break detected */
Alan Cox2742fd82008-04-29 14:45:15 +01001430 MAP_FLAG(UMP_UART_LSR_RX_MASK, LSR_RX_AVAIL) /* rx data available */
1431 MAP_FLAG(UMP_UART_LSR_TX_MASK, LSR_TX_EMPTY) /* tx hold reg empty */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432
1433#undef MAP_FLAG
1434
1435 return lsr;
1436}
1437
Alan Cox2742fd82008-04-29 14:45:15 +01001438static void handle_new_msr(struct edgeport_port *edge_port, __u8 msr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439{
1440 struct async_icount *icount;
1441 struct tty_struct *tty;
1442
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001443 dev_dbg(&edge_port->port->dev, "%s - %02x\n", __func__, msr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444
Alan Cox2742fd82008-04-29 14:45:15 +01001445 if (msr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR |
1446 EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) {
Johan Hovoldcf9a9d62013-03-21 12:37:09 +01001447 icount = &edge_port->port->icount;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
1449 /* update input line counters */
1450 if (msr & EDGEPORT_MSR_DELTA_CTS)
1451 icount->cts++;
1452 if (msr & EDGEPORT_MSR_DELTA_DSR)
1453 icount->dsr++;
1454 if (msr & EDGEPORT_MSR_DELTA_CD)
1455 icount->dcd++;
1456 if (msr & EDGEPORT_MSR_DELTA_RI)
1457 icount->rng++;
Johan Hovold7b245962013-03-19 09:21:17 +01001458 wake_up_interruptible(&edge_port->port->delta_msr_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 }
1460
1461 /* Save the new modem status */
1462 edge_port->shadow_msr = msr & 0xf0;
1463
Alan Cox4a90f092008-10-13 10:39:46 +01001464 tty = tty_port_tty_get(&edge_port->port->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 /* handle CTS flow control */
1466 if (tty && C_CRTSCTS(tty)) {
1467 if (msr & EDGEPORT_MSR_CTS) {
1468 tty->hw_stopped = 0;
1469 tty_wakeup(tty);
1470 } else {
1471 tty->hw_stopped = 1;
1472 }
1473 }
Alan Cox4a90f092008-10-13 10:39:46 +01001474 tty_kref_put(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475}
1476
Alan Cox2742fd82008-04-29 14:45:15 +01001477static void handle_new_lsr(struct edgeport_port *edge_port, int lsr_data,
1478 __u8 lsr, __u8 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479{
1480 struct async_icount *icount;
Alan Cox2742fd82008-04-29 14:45:15 +01001481 __u8 new_lsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR |
1482 LSR_FRM_ERR | LSR_BREAK));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001484 dev_dbg(&edge_port->port->dev, "%s - %02x\n", __func__, new_lsr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485
1486 edge_port->shadow_lsr = lsr;
1487
Alan Cox2742fd82008-04-29 14:45:15 +01001488 if (new_lsr & LSR_BREAK)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 /*
1490 * Parity and Framing errors only count if they
1491 * occur exclusive of a break being received.
1492 */
1493 new_lsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
1495 /* Place LSR data byte into Rx buffer */
Jiri Slaby2e124b42013-01-03 15:53:06 +01001496 if (lsr_data)
1497 edge_tty_recv(edge_port->port, &data, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
1499 /* update input line counters */
Johan Hovoldcf9a9d62013-03-21 12:37:09 +01001500 icount = &edge_port->port->icount;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 if (new_lsr & LSR_BREAK)
1502 icount->brk++;
1503 if (new_lsr & LSR_OVER_ERR)
1504 icount->overrun++;
1505 if (new_lsr & LSR_PAR_ERR)
1506 icount->parity++;
1507 if (new_lsr & LSR_FRM_ERR)
1508 icount->frame++;
1509}
1510
1511
Alan Cox2742fd82008-04-29 14:45:15 +01001512static void edge_interrupt_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513{
Ming Leicdc97792008-02-24 18:41:47 +08001514 struct edgeport_serial *edge_serial = urb->context;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 struct usb_serial_port *port;
1516 struct edgeport_port *edge_port;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001517 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 unsigned char *data = urb->transfer_buffer;
1519 int length = urb->actual_length;
1520 int port_number;
1521 int function;
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001522 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 __u8 lsr;
1524 __u8 msr;
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001525 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001527 switch (status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 case 0:
1529 /* success */
1530 break;
1531 case -ECONNRESET:
1532 case -ENOENT:
1533 case -ESHUTDOWN:
1534 /* this urb is terminated, clean up */
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001535 dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -08001536 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 return;
1538 default:
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001539 dev_err(&urb->dev->dev, "%s - nonzero urb status received: "
Harvey Harrison441b62c2008-03-03 16:08:34 -08001540 "%d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 goto exit;
1542 }
1543
1544 if (!length) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001545 dev_dbg(&urb->dev->dev, "%s - no data in urb\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 goto exit;
1547 }
1548
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001549 dev = &edge_serial->serial->dev->dev;
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +01001550 usb_serial_debug_data(dev, __func__, length, data);
Alan Cox2742fd82008-04-29 14:45:15 +01001551
1552 if (length != 2) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001553 dev_dbg(dev, "%s - expecting packet of size 2, got %d\n", __func__, length);
Alan Cox2742fd82008-04-29 14:45:15 +01001554 goto exit;
1555 }
1556
1557 port_number = TIUMP_GET_PORT_FROM_CODE(data[0]);
1558 function = TIUMP_GET_FUNC_FROM_CODE(data[0]);
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001559 dev_dbg(dev, "%s - port_number %d, function %d, info 0x%x\n", __func__,
1560 port_number, function, data[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 port = edge_serial->serial->port[port_number];
1562 edge_port = usb_get_serial_port_data(port);
1563 if (!edge_port) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001564 dev_dbg(dev, "%s - edge_port not found\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 return;
1566 }
1567 switch (function) {
1568 case TIUMP_INTERRUPT_CODE_LSR:
Alan Cox2742fd82008-04-29 14:45:15 +01001569 lsr = map_line_status(data[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 if (lsr & UMP_UART_LSR_DATA_MASK) {
Alan Cox2742fd82008-04-29 14:45:15 +01001571 /* Save the LSR event for bulk read
1572 completion routine */
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001573 dev_dbg(dev, "%s - LSR Event Port %u LSR Status = %02x\n",
1574 __func__, port_number, lsr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 edge_port->lsr_event = 1;
1576 edge_port->lsr_mask = lsr;
1577 } else {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001578 dev_dbg(dev, "%s - ===== Port %d LSR Status = %02x ======\n",
1579 __func__, port_number, lsr);
Alan Cox2742fd82008-04-29 14:45:15 +01001580 handle_new_lsr(edge_port, 0, lsr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 }
1582 break;
1583
Alan Cox2742fd82008-04-29 14:45:15 +01001584 case TIUMP_INTERRUPT_CODE_MSR: /* MSR */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 /* Copy MSR from UMP */
1586 msr = data[1];
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001587 dev_dbg(dev, "%s - ===== Port %u MSR Status = %02x ======\n",
1588 __func__, port_number, msr);
Alan Cox2742fd82008-04-29 14:45:15 +01001589 handle_new_msr(edge_port, msr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 break;
1591
1592 default:
Alan Cox2742fd82008-04-29 14:45:15 +01001593 dev_err(&urb->dev->dev,
1594 "%s - Unknown Interrupt code from UMP %x\n",
1595 __func__, data[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 break;
Alan Cox2742fd82008-04-29 14:45:15 +01001597
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 }
1599
1600exit:
Alan Cox2742fd82008-04-29 14:45:15 +01001601 retval = usb_submit_urb(urb, GFP_ATOMIC);
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001602 if (retval)
Alan Cox2742fd82008-04-29 14:45:15 +01001603 dev_err(&urb->dev->dev,
1604 "%s - usb_submit_urb failed with result %d\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -08001605 __func__, retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606}
1607
Alan Cox2742fd82008-04-29 14:45:15 +01001608static void edge_bulk_in_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609{
Ming Leicdc97792008-02-24 18:41:47 +08001610 struct edgeport_port *edge_port = urb->context;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001611 struct device *dev = &edge_port->port->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 unsigned char *data = urb->transfer_buffer;
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001613 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 int port_number;
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001615 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001617 switch (status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 case 0:
1619 /* success */
1620 break;
1621 case -ECONNRESET:
1622 case -ENOENT:
1623 case -ESHUTDOWN:
1624 /* this urb is terminated, clean up */
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001625 dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 return;
1627 default:
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001628 dev_err(&urb->dev->dev, "%s - nonzero read bulk status received: %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 }
1630
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001631 if (status == -EPIPE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 goto exit;
1633
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001634 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001635 dev_err(&urb->dev->dev, "%s - stopping read!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 return;
1637 }
1638
1639 port_number = edge_port->port->number - edge_port->port->serial->minor;
1640
1641 if (edge_port->lsr_event) {
1642 edge_port->lsr_event = 0;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001643 dev_dbg(dev, "%s ===== Port %u LSR Status = %02x, Data = %02x ======\n",
1644 __func__, port_number, edge_port->lsr_mask, *data);
Alan Cox2742fd82008-04-29 14:45:15 +01001645 handle_new_lsr(edge_port, 1, edge_port->lsr_mask, *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 /* Adjust buffer length/pointer */
1647 --urb->actual_length;
1648 ++data;
1649 }
1650
Jiri Slaby2e124b42013-01-03 15:53:06 +01001651 if (urb->actual_length) {
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +01001652 usb_serial_debug_data(dev, __func__, urb->actual_length, data);
Alan Cox2742fd82008-04-29 14:45:15 +01001653 if (edge_port->close_pending)
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001654 dev_dbg(dev, "%s - close pending, dropping data on the floor\n",
Alan Cox2742fd82008-04-29 14:45:15 +01001655 __func__);
1656 else
Jiri Slaby2e124b42013-01-03 15:53:06 +01001657 edge_tty_recv(edge_port->port, data,
Jiri Slaby05c7cd32013-01-03 15:53:04 +01001658 urb->actual_length);
Johan Hovoldcf9a9d62013-03-21 12:37:09 +01001659 edge_port->port->icount.rx += urb->actual_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 }
1661
1662exit:
1663 /* continue read unless stopped */
1664 spin_lock(&edge_port->ep_lock);
Johan Hovold58330412011-11-06 19:06:28 +01001665 if (edge_port->ep_read_urb_state == EDGE_READ_URB_RUNNING)
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001666 retval = usb_submit_urb(urb, GFP_ATOMIC);
Johan Hovold58330412011-11-06 19:06:28 +01001667 else if (edge_port->ep_read_urb_state == EDGE_READ_URB_STOPPING)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 edge_port->ep_read_urb_state = EDGE_READ_URB_STOPPED;
Johan Hovold58330412011-11-06 19:06:28 +01001669
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 spin_unlock(&edge_port->ep_lock);
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001671 if (retval)
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001672 dev_err(dev, "%s - usb_submit_urb failed with result %d\n", __func__, retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673}
1674
Jiri Slaby2e124b42013-01-03 15:53:06 +01001675static void edge_tty_recv(struct usb_serial_port *port, unsigned char *data,
1676 int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677{
Alan Cox2742fd82008-04-29 14:45:15 +01001678 int queued;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679
Jiri Slaby05c7cd32013-01-03 15:53:04 +01001680 queued = tty_insert_flip_string(&port->port, data, length);
Alan Cox2742fd82008-04-29 14:45:15 +01001681 if (queued < length)
Jiri Slaby05c7cd32013-01-03 15:53:04 +01001682 dev_err(&port->dev, "%s - dropping data, %d bytes lost\n",
Alan Cox2742fd82008-04-29 14:45:15 +01001683 __func__, length - queued);
Jiri Slaby2e124b42013-01-03 15:53:06 +01001684 tty_flip_buffer_push(&port->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685}
1686
Alan Cox2742fd82008-04-29 14:45:15 +01001687static void edge_bulk_out_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688{
Ming Leicdc97792008-02-24 18:41:47 +08001689 struct usb_serial_port *port = urb->context;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001691 int status = urb->status;
Alan Cox4a90f092008-10-13 10:39:46 +01001692 struct tty_struct *tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 edge_port->ep_write_urb_in_use = 0;
1695
Greg Kroah-Hartmanee337c22007-06-15 15:44:13 -07001696 switch (status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 case 0:
1698 /* success */
1699 break;
1700 case -ECONNRESET:
1701 case -ENOENT:
1702 case -ESHUTDOWN:
1703 /* this urb is terminated, clean up */
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001704 dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -08001705 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 return;
1707 default:
Johan Hovold22a416c2012-02-10 13:20:51 +01001708 dev_err_console(port, "%s - nonzero write bulk status "
Harvey Harrison441b62c2008-03-03 16:08:34 -08001709 "received: %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 }
1711
1712 /* send any buffered data */
Alan Cox4a90f092008-10-13 10:39:46 +01001713 tty = tty_port_tty_get(&port->port);
1714 edge_send(tty);
1715 tty_kref_put(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716}
1717
Alan Coxa509a7e2009-09-19 13:13:26 -07001718static int edge_open(struct tty_struct *tty, struct usb_serial_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719{
1720 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1721 struct edgeport_serial *edge_serial;
1722 struct usb_device *dev;
1723 struct urb *urb;
1724 int port_number;
1725 int status;
1726 u16 open_settings;
1727 u8 transaction_timeout;
1728
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 if (edge_port == NULL)
1730 return -ENODEV;
1731
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 port_number = port->number - port->serial->minor;
1733 switch (port_number) {
Alan Cox2742fd82008-04-29 14:45:15 +01001734 case 0:
1735 edge_port->uart_base = UMPMEM_BASE_UART1;
1736 edge_port->dma_address = UMPD_OEDB1_ADDRESS;
1737 break;
1738 case 1:
1739 edge_port->uart_base = UMPMEM_BASE_UART2;
1740 edge_port->dma_address = UMPD_OEDB2_ADDRESS;
1741 break;
1742 default:
1743 dev_err(&port->dev, "Unknown port number!!!\n");
1744 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 }
1746
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001747 dev_dbg(&port->dev, "%s - port_number = %d, uart_base = %04x, dma_address = %04x\n",
1748 __func__, port_number, edge_port->uart_base, edge_port->dma_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749
1750 dev = port->serial->dev;
1751
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 /* turn off loopback */
Alan Cox2742fd82008-04-29 14:45:15 +01001753 status = ti_do_config(edge_port, UMPC_SET_CLR_LOOPBACK, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001755 dev_err(&port->dev,
1756 "%s - cannot send clear loopback command, %d\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -08001757 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 return status;
1759 }
Alan Cox2742fd82008-04-29 14:45:15 +01001760
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 /* set up the port settings */
Alan Cox95da3102008-07-22 11:09:07 +01001762 if (tty)
Alan Coxadc8d742012-07-14 15:31:47 +01001763 edge_set_termios(tty, port, &tty->termios);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764
1765 /* open up the port */
1766
1767 /* milliseconds to timeout for DMA transfer */
1768 transaction_timeout = 2;
1769
Alan Cox2742fd82008-04-29 14:45:15 +01001770 edge_port->ump_read_timeout =
1771 max(20, ((transaction_timeout * 3) / 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772
Alan Cox2742fd82008-04-29 14:45:15 +01001773 /* milliseconds to timeout for DMA transfer */
1774 open_settings = (u8)(UMP_DMA_MODE_CONTINOUS |
1775 UMP_PIPE_TRANS_TIMEOUT_ENA |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 (transaction_timeout << 2));
1777
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001778 dev_dbg(&port->dev, "%s - Sending UMPC_OPEN_PORT\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
1780 /* Tell TI to open and start the port */
Alan Cox2742fd82008-04-29 14:45:15 +01001781 status = send_cmd(dev, UMPC_OPEN_PORT,
1782 (u8)(UMPM_UART1_PORT + port_number), open_settings, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001784 dev_err(&port->dev, "%s - cannot send open command, %d\n",
1785 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 return status;
1787 }
1788
1789 /* Start the DMA? */
Alan Cox2742fd82008-04-29 14:45:15 +01001790 status = send_cmd(dev, UMPC_START_PORT,
1791 (u8)(UMPM_UART1_PORT + port_number), 0, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001793 dev_err(&port->dev, "%s - cannot send start DMA command, %d\n",
1794 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 return status;
1796 }
1797
1798 /* Clear TX and RX buffers in UMP */
Alan Cox2742fd82008-04-29 14:45:15 +01001799 status = purge_port(port, UMP_PORT_DIR_OUT | UMP_PORT_DIR_IN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001801 dev_err(&port->dev,
1802 "%s - cannot send clear buffers command, %d\n",
1803 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 return status;
1805 }
1806
1807 /* Read Initial MSR */
Alan Cox2742fd82008-04-29 14:45:15 +01001808 status = ti_vread_sync(dev, UMPC_READ_MSR, 0,
1809 (__u16)(UMPM_UART1_PORT + port_number),
1810 &edge_port->shadow_msr, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001812 dev_err(&port->dev, "%s - cannot send read MSR command, %d\n",
1813 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 return status;
1815 }
1816
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001817 dev_dbg(&port->dev, "ShadowMSR 0x%X\n", edge_port->shadow_msr);
Alan Cox2742fd82008-04-29 14:45:15 +01001818
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 /* Set Initial MCR */
1820 edge_port->shadow_mcr = MCR_RTS | MCR_DTR;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001821 dev_dbg(&port->dev, "ShadowMCR 0x%X\n", edge_port->shadow_mcr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
1823 edge_serial = edge_port->edge_serial;
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01001824 if (mutex_lock_interruptible(&edge_serial->es_lock))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 return -ERESTARTSYS;
1826 if (edge_serial->num_ports_open == 0) {
Alan Cox2742fd82008-04-29 14:45:15 +01001827 /* we are the first port to open, post the interrupt urb */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 urb = edge_serial->serial->port[0]->interrupt_in_urb;
1829 if (!urb) {
Alan Cox2742fd82008-04-29 14:45:15 +01001830 dev_err(&port->dev,
1831 "%s - no interrupt urb present, exiting\n",
1832 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 status = -EINVAL;
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01001834 goto release_es_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 urb->context = edge_serial;
Alan Cox2742fd82008-04-29 14:45:15 +01001837 status = usb_submit_urb(urb, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001839 dev_err(&port->dev,
1840 "%s - usb_submit_urb failed with value %d\n",
1841 __func__, status);
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01001842 goto release_es_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 }
1844 }
1845
1846 /*
1847 * reset the data toggle on the bulk endpoints to work around bug in
1848 * host controllers where things get out of sync some times
1849 */
Alan Cox2742fd82008-04-29 14:45:15 +01001850 usb_clear_halt(dev, port->write_urb->pipe);
1851 usb_clear_halt(dev, port->read_urb->pipe);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852
1853 /* start up our bulk read urb */
1854 urb = port->read_urb;
1855 if (!urb) {
Alan Cox2742fd82008-04-29 14:45:15 +01001856 dev_err(&port->dev, "%s - no read urb present, exiting\n",
1857 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 status = -EINVAL;
1859 goto unlink_int_urb;
1860 }
1861 edge_port->ep_read_urb_state = EDGE_READ_URB_RUNNING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 urb->context = edge_port;
Alan Cox2742fd82008-04-29 14:45:15 +01001863 status = usb_submit_urb(urb, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01001865 dev_err(&port->dev,
1866 "%s - read bulk usb_submit_urb failed with value %d\n",
1867 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 goto unlink_int_urb;
1869 }
1870
1871 ++edge_serial->num_ports_open;
1872
Johan Hovoldfcdb6a22013-01-14 16:52:55 +01001873 port->port.drain_delay = 1;
1874
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01001875 goto release_es_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876
1877unlink_int_urb:
1878 if (edge_port->edge_serial->num_ports_open == 0)
1879 usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01001880release_es_lock:
1881 mutex_unlock(&edge_serial->es_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 return status;
1883}
1884
Alan Cox335f8512009-06-11 12:26:29 +01001885static void edge_close(struct usb_serial_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886{
1887 struct edgeport_serial *edge_serial;
1888 struct edgeport_port *edge_port;
Johan Hovoldaf581052012-03-26 20:31:38 +02001889 struct usb_serial *serial = port->serial;
Johan Hovold77de2512013-01-14 16:52:54 +01001890 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 int port_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 edge_serial = usb_get_serial_data(port->serial);
1894 edge_port = usb_get_serial_port_data(port);
Alan Cox2742fd82008-04-29 14:45:15 +01001895 if (edge_serial == NULL || edge_port == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 return;
Alan Cox2742fd82008-04-29 14:45:15 +01001897
1898 /* The bulkreadcompletion routine will check
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 * this flag and dump add read data */
1900 edge_port->close_pending = 1;
1901
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 usb_kill_urb(port->read_urb);
1903 usb_kill_urb(port->write_urb);
1904 edge_port->ep_write_urb_in_use = 0;
Johan Hovold77de2512013-01-14 16:52:54 +01001905 spin_lock_irqsave(&edge_port->ep_lock, flags);
1906 kfifo_reset_out(&edge_port->write_fifo);
1907 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908
1909 /* assuming we can still talk to the device,
1910 * send a close port command to it */
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001911 dev_dbg(&port->dev, "%s - send umpc_close_port\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 port_number = port->number - port->serial->minor;
Johan Hovoldaf581052012-03-26 20:31:38 +02001913
1914 mutex_lock(&serial->disc_mutex);
1915 if (!serial->disconnected) {
1916 send_cmd(serial->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 UMPC_CLOSE_PORT,
1918 (__u8)(UMPM_UART1_PORT + port_number),
1919 0,
1920 NULL,
1921 0);
Johan Hovoldaf581052012-03-26 20:31:38 +02001922 }
1923 mutex_unlock(&serial->disc_mutex);
1924
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01001925 mutex_lock(&edge_serial->es_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 --edge_port->edge_serial->num_ports_open;
1927 if (edge_port->edge_serial->num_ports_open <= 0) {
1928 /* last port is now closed, let's shut down our interrupt urb */
1929 usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
1930 edge_port->edge_serial->num_ports_open = 0;
1931 }
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01001932 mutex_unlock(&edge_serial->es_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 edge_port->close_pending = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934}
1935
Alan Cox95da3102008-07-22 11:09:07 +01001936static int edge_write(struct tty_struct *tty, struct usb_serial_port *port,
1937 const unsigned char *data, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938{
1939 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 if (count == 0) {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07001942 dev_dbg(&port->dev, "%s - write request of 0 bytes\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 return 0;
1944 }
1945
1946 if (edge_port == NULL)
1947 return -ENODEV;
1948 if (edge_port->close_pending == 1)
1949 return -ENODEV;
1950
Johan Hovoldd733cec2010-05-19 00:01:37 +02001951 count = kfifo_in_locked(&edge_port->write_fifo, data, count,
1952 &edge_port->ep_lock);
Alan Cox95da3102008-07-22 11:09:07 +01001953 edge_send(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954
1955 return count;
1956}
1957
Alan Cox95da3102008-07-22 11:09:07 +01001958static void edge_send(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959{
Alan Cox95da3102008-07-22 11:09:07 +01001960 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 int count, result;
1962 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 unsigned long flags;
1964
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 spin_lock_irqsave(&edge_port->ep_lock, flags);
1966
1967 if (edge_port->ep_write_urb_in_use) {
1968 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1969 return;
1970 }
1971
Johan Hovoldd733cec2010-05-19 00:01:37 +02001972 count = kfifo_out(&edge_port->write_fifo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 port->write_urb->transfer_buffer,
1974 port->bulk_out_size);
1975
1976 if (count == 0) {
1977 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1978 return;
1979 }
1980
1981 edge_port->ep_write_urb_in_use = 1;
1982
1983 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1984
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +01001985 usb_serial_debug_data(&port->dev, __func__, count, port->write_urb->transfer_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986
1987 /* set up our urb */
Johan Hovoldfd119612011-11-06 19:06:30 +01001988 port->write_urb->transfer_buffer_length = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
1990 /* send the data out the bulk port */
1991 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
1992 if (result) {
Johan Hovold22a416c2012-02-10 13:20:51 +01001993 dev_err_console(port,
Alan Cox2742fd82008-04-29 14:45:15 +01001994 "%s - failed submitting write urb, error %d\n",
1995 __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 edge_port->ep_write_urb_in_use = 0;
Alan Cox2742fd82008-04-29 14:45:15 +01001997 /* TODO: reschedule edge_send */
1998 } else
Johan Hovoldcf9a9d62013-03-21 12:37:09 +01001999 edge_port->port->icount.tx += count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000
2001 /* wakeup any process waiting for writes to complete */
2002 /* there is now more room in the buffer for new writes */
Alan Cox2742fd82008-04-29 14:45:15 +01002003 if (tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 tty_wakeup(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005}
2006
Alan Cox95da3102008-07-22 11:09:07 +01002007static int edge_write_room(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008{
Alan Cox95da3102008-07-22 11:09:07 +01002009 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2011 int room = 0;
2012 unsigned long flags;
2013
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 if (edge_port == NULL)
Alan Cox2742fd82008-04-29 14:45:15 +01002015 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 if (edge_port->close_pending == 1)
Alan Cox2742fd82008-04-29 14:45:15 +01002017 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018
2019 spin_lock_irqsave(&edge_port->ep_lock, flags);
Johan Hovoldd733cec2010-05-19 00:01:37 +02002020 room = kfifo_avail(&edge_port->write_fifo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2022
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002023 dev_dbg(&port->dev, "%s - returns %d\n", __func__, room);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 return room;
2025}
2026
Alan Cox95da3102008-07-22 11:09:07 +01002027static int edge_chars_in_buffer(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028{
Alan Cox95da3102008-07-22 11:09:07 +01002029 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2031 int chars = 0;
2032 unsigned long flags;
Johan Hovold263e1f92013-01-14 16:52:57 +01002033 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 if (edge_port == NULL)
Alan Cox2742fd82008-04-29 14:45:15 +01002036 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037
2038 spin_lock_irqsave(&edge_port->ep_lock, flags);
Johan Hovoldd733cec2010-05-19 00:01:37 +02002039 chars = kfifo_len(&edge_port->write_fifo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2041
Johan Hovold263e1f92013-01-14 16:52:57 +01002042 if (!chars) {
2043 ret = tx_active(edge_port);
2044 if (ret > 0)
2045 chars = ret;
2046 }
2047
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002048 dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 return chars;
2050}
2051
Alan Cox95da3102008-07-22 11:09:07 +01002052static void edge_throttle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053{
Alan Cox95da3102008-07-22 11:09:07 +01002054 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 int status;
2057
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 if (edge_port == NULL)
2059 return;
2060
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 /* if we are implementing XON/XOFF, send the stop character */
2062 if (I_IXOFF(tty)) {
2063 unsigned char stop_char = STOP_CHAR(tty);
Alan Cox95da3102008-07-22 11:09:07 +01002064 status = edge_write(tty, port, &stop_char, 1);
2065 if (status <= 0) {
2066 dev_err(&port->dev, "%s - failed to write stop character, %d\n", __func__, status);
2067 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 }
2069
2070 /* if we are implementing RTS/CTS, stop reads */
2071 /* and the Edgeport will clear the RTS line */
2072 if (C_CRTSCTS(tty))
2073 stop_read(edge_port);
2074
2075}
2076
Alan Cox95da3102008-07-22 11:09:07 +01002077static void edge_unthrottle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078{
Alan Cox95da3102008-07-22 11:09:07 +01002079 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 int status;
2082
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 if (edge_port == NULL)
2084 return;
2085
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 /* if we are implementing XON/XOFF, send the start character */
2087 if (I_IXOFF(tty)) {
2088 unsigned char start_char = START_CHAR(tty);
Alan Cox95da3102008-07-22 11:09:07 +01002089 status = edge_write(tty, port, &start_char, 1);
2090 if (status <= 0) {
2091 dev_err(&port->dev, "%s - failed to write start character, %d\n", __func__, status);
2092 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 /* if we are implementing RTS/CTS, restart reads */
2095 /* are the Edgeport will assert the RTS line */
2096 if (C_CRTSCTS(tty)) {
2097 status = restart_read(edge_port);
2098 if (status)
Alan Cox2742fd82008-04-29 14:45:15 +01002099 dev_err(&port->dev,
2100 "%s - read bulk usb_submit_urb failed: %d\n",
2101 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 }
2103
2104}
2105
2106static void stop_read(struct edgeport_port *edge_port)
2107{
2108 unsigned long flags;
2109
2110 spin_lock_irqsave(&edge_port->ep_lock, flags);
2111
2112 if (edge_port->ep_read_urb_state == EDGE_READ_URB_RUNNING)
2113 edge_port->ep_read_urb_state = EDGE_READ_URB_STOPPING;
2114 edge_port->shadow_mcr &= ~MCR_RTS;
2115
2116 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2117}
2118
2119static int restart_read(struct edgeport_port *edge_port)
2120{
2121 struct urb *urb;
2122 int status = 0;
2123 unsigned long flags;
2124
2125 spin_lock_irqsave(&edge_port->ep_lock, flags);
2126
2127 if (edge_port->ep_read_urb_state == EDGE_READ_URB_STOPPED) {
2128 urb = edge_port->port->read_urb;
Oliver Neukumefdff602007-06-05 10:50:48 +02002129 status = usb_submit_urb(urb, GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 }
2131 edge_port->ep_read_urb_state = EDGE_READ_URB_RUNNING;
2132 edge_port->shadow_mcr |= MCR_RTS;
2133
2134 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2135
2136 return status;
2137}
2138
Alan Cox95da3102008-07-22 11:09:07 +01002139static void change_port_settings(struct tty_struct *tty,
2140 struct edgeport_port *edge_port, struct ktermios *old_termios)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141{
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002142 struct device *dev = &edge_port->port->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 struct ump_uart_config *config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 int baud;
2145 unsigned cflag;
2146 int status;
Alan Cox2742fd82008-04-29 14:45:15 +01002147 int port_number = edge_port->port->number -
2148 edge_port->port->serial->minor;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002150 dev_dbg(dev, "%s - port %d\n", __func__, edge_port->port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151
Alan Cox95da3102008-07-22 11:09:07 +01002152 config = kmalloc (sizeof (*config), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 if (!config) {
Alan Coxadc8d742012-07-14 15:31:47 +01002154 tty->termios = *old_termios;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002155 dev_err(dev, "%s - out of memory\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 return;
2157 }
2158
Alan Coxadc8d742012-07-14 15:31:47 +01002159 cflag = tty->termios.c_cflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160
2161 config->wFlags = 0;
2162
2163 /* These flags must be set */
2164 config->wFlags |= UMP_MASK_UART_FLAGS_RECEIVE_MS_INT;
2165 config->wFlags |= UMP_MASK_UART_FLAGS_AUTO_START_ON_ERR;
2166 config->bUartMode = (__u8)(edge_port->bUartMode);
2167
2168 switch (cflag & CSIZE) {
Alan Cox2742fd82008-04-29 14:45:15 +01002169 case CS5:
2170 config->bDataBits = UMP_UART_CHAR5BITS;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002171 dev_dbg(dev, "%s - data bits = 5\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01002172 break;
2173 case CS6:
2174 config->bDataBits = UMP_UART_CHAR6BITS;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002175 dev_dbg(dev, "%s - data bits = 6\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01002176 break;
2177 case CS7:
2178 config->bDataBits = UMP_UART_CHAR7BITS;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002179 dev_dbg(dev, "%s - data bits = 7\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01002180 break;
2181 default:
2182 case CS8:
2183 config->bDataBits = UMP_UART_CHAR8BITS;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002184 dev_dbg(dev, "%s - data bits = 8\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 break;
2186 }
2187
2188 if (cflag & PARENB) {
2189 if (cflag & PARODD) {
2190 config->wFlags |= UMP_MASK_UART_FLAGS_PARITY;
2191 config->bParity = UMP_UART_ODDPARITY;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002192 dev_dbg(dev, "%s - parity = odd\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 } else {
2194 config->wFlags |= UMP_MASK_UART_FLAGS_PARITY;
2195 config->bParity = UMP_UART_EVENPARITY;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002196 dev_dbg(dev, "%s - parity = even\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 }
2198 } else {
Alan Cox2742fd82008-04-29 14:45:15 +01002199 config->bParity = UMP_UART_NOPARITY;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002200 dev_dbg(dev, "%s - parity = none\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 }
2202
2203 if (cflag & CSTOPB) {
2204 config->bStopBits = UMP_UART_STOPBIT2;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002205 dev_dbg(dev, "%s - stop bits = 2\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 } else {
2207 config->bStopBits = UMP_UART_STOPBIT1;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002208 dev_dbg(dev, "%s - stop bits = 1\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 }
2210
2211 /* figure out the flow control settings */
2212 if (cflag & CRTSCTS) {
2213 config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X_CTS_FLOW;
2214 config->wFlags |= UMP_MASK_UART_FLAGS_RTS_FLOW;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002215 dev_dbg(dev, "%s - RTS/CTS is enabled\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 } else {
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002217 dev_dbg(dev, "%s - RTS/CTS is disabled\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 tty->hw_stopped = 0;
2219 restart_read(edge_port);
2220 }
2221
Alan Cox2742fd82008-04-29 14:45:15 +01002222 /* if we are implementing XON/XOFF, set the start and stop
2223 character in the device */
2224 config->cXon = START_CHAR(tty);
2225 config->cXoff = STOP_CHAR(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226
Alan Cox2742fd82008-04-29 14:45:15 +01002227 /* if we are implementing INBOUND XON/XOFF */
2228 if (I_IXOFF(tty)) {
2229 config->wFlags |= UMP_MASK_UART_FLAGS_IN_X;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002230 dev_dbg(dev, "%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x\n",
2231 __func__, config->cXon, config->cXoff);
Alan Cox2742fd82008-04-29 14:45:15 +01002232 } else
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002233 dev_dbg(dev, "%s - INBOUND XON/XOFF is disabled\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234
Alan Cox2742fd82008-04-29 14:45:15 +01002235 /* if we are implementing OUTBOUND XON/XOFF */
2236 if (I_IXON(tty)) {
2237 config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X;
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002238 dev_dbg(dev, "%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x\n",
2239 __func__, config->cXon, config->cXoff);
Alan Cox2742fd82008-04-29 14:45:15 +01002240 } else
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002241 dev_dbg(dev, "%s - OUTBOUND XON/XOFF is disabled\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242
Alan Coxadc8d742012-07-14 15:31:47 +01002243 tty->termios.c_cflag &= ~CMSPAR;
Alan Coxd5f5bcd2008-01-03 16:57:33 +00002244
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 /* Round the baud rate */
2246 baud = tty_get_baud_rate(tty);
2247 if (!baud) {
2248 /* pick a default, any default... */
2249 baud = 9600;
Alan Coxd5f5bcd2008-01-03 16:57:33 +00002250 } else
2251 tty_encode_baud_rate(tty, baud, baud);
2252
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 edge_port->baud_rate = baud;
2254 config->wBaudRate = (__u16)((461550L + baud/2) / baud);
2255
Alan Coxd5f5bcd2008-01-03 16:57:33 +00002256 /* FIXME: Recompute actual baud from divisor here */
2257
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002258 dev_dbg(dev, "%s - baud rate = %d, wBaudRate = %d\n", __func__, baud, config->wBaudRate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002260 dev_dbg(dev, "wBaudRate: %d\n", (int)(461550L / config->wBaudRate));
2261 dev_dbg(dev, "wFlags: 0x%x\n", config->wFlags);
2262 dev_dbg(dev, "bDataBits: %d\n", config->bDataBits);
2263 dev_dbg(dev, "bParity: %d\n", config->bParity);
2264 dev_dbg(dev, "bStopBits: %d\n", config->bStopBits);
2265 dev_dbg(dev, "cXon: %d\n", config->cXon);
2266 dev_dbg(dev, "cXoff: %d\n", config->cXoff);
2267 dev_dbg(dev, "bUartMode: %d\n", config->bUartMode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268
2269 /* move the word values into big endian mode */
Alan Cox2742fd82008-04-29 14:45:15 +01002270 cpu_to_be16s(&config->wFlags);
2271 cpu_to_be16s(&config->wBaudRate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272
Alan Cox2742fd82008-04-29 14:45:15 +01002273 status = send_cmd(edge_port->port->serial->dev, UMPC_SET_CONFIG,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 (__u8)(UMPM_UART1_PORT + port_number),
Alan Cox2742fd82008-04-29 14:45:15 +01002275 0, (__u8 *)config, sizeof(*config));
2276 if (status)
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002277 dev_dbg(dev, "%s - error %d when trying to write config to device\n",
2278 __func__, status);
Alan Cox2742fd82008-04-29 14:45:15 +01002279 kfree(config);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280}
2281
Alan Cox2e0ddd62008-07-22 11:12:33 +01002282static void edge_set_termios(struct tty_struct *tty,
Alan Cox95da3102008-07-22 11:09:07 +01002283 struct usb_serial_port *port, struct ktermios *old_termios)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284{
2285 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
Alan Cox95da3102008-07-22 11:09:07 +01002286 unsigned int cflag;
2287
Alan Coxadc8d742012-07-14 15:31:47 +01002288 cflag = tty->termios.c_cflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002290 dev_dbg(&port->dev, "%s - clfag %08x iflag %08x\n", __func__,
Linus Torvaldsd9a80742012-10-01 13:23:01 -07002291 tty->termios.c_cflag, tty->termios.c_iflag);
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002292 dev_dbg(&port->dev, "%s - old clfag %08x old iflag %08x\n", __func__,
2293 old_termios->c_cflag, old_termios->c_iflag);
2294 dev_dbg(&port->dev, "%s - port %d\n", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295
2296 if (edge_port == NULL)
2297 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 /* change the port settings to the new ones specified */
Alan Cox95da3102008-07-22 11:09:07 +01002299 change_port_settings(tty, edge_port, old_termios);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300}
2301
Alan Cox20b9d172011-02-14 16:26:50 +00002302static int edge_tiocmset(struct tty_struct *tty,
Alan Cox2742fd82008-04-29 14:45:15 +01002303 unsigned int set, unsigned int clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304{
Alan Cox95da3102008-07-22 11:09:07 +01002305 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2307 unsigned int mcr;
Alan Cox3d71fe02008-02-20 21:38:32 +00002308 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309
Alan Cox3d71fe02008-02-20 21:38:32 +00002310 spin_lock_irqsave(&edge_port->ep_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 mcr = edge_port->shadow_mcr;
2312 if (set & TIOCM_RTS)
2313 mcr |= MCR_RTS;
2314 if (set & TIOCM_DTR)
2315 mcr |= MCR_DTR;
2316 if (set & TIOCM_LOOP)
2317 mcr |= MCR_LOOPBACK;
2318
2319 if (clear & TIOCM_RTS)
2320 mcr &= ~MCR_RTS;
2321 if (clear & TIOCM_DTR)
2322 mcr &= ~MCR_DTR;
2323 if (clear & TIOCM_LOOP)
2324 mcr &= ~MCR_LOOPBACK;
2325
2326 edge_port->shadow_mcr = mcr;
Alan Cox3d71fe02008-02-20 21:38:32 +00002327 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328
Alan Cox2742fd82008-04-29 14:45:15 +01002329 restore_mcr(edge_port, mcr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 return 0;
2331}
2332
Alan Cox60b33c12011-02-14 16:26:14 +00002333static int edge_tiocmget(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334{
Alan Cox95da3102008-07-22 11:09:07 +01002335 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2337 unsigned int result = 0;
2338 unsigned int msr;
2339 unsigned int mcr;
Alan Cox3d71fe02008-02-20 21:38:32 +00002340 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
Alan Cox3d71fe02008-02-20 21:38:32 +00002342 spin_lock_irqsave(&edge_port->ep_lock, flags);
2343
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 msr = edge_port->shadow_msr;
2345 mcr = edge_port->shadow_mcr;
2346 result = ((mcr & MCR_DTR) ? TIOCM_DTR: 0) /* 0x002 */
2347 | ((mcr & MCR_RTS) ? TIOCM_RTS: 0) /* 0x004 */
2348 | ((msr & EDGEPORT_MSR_CTS) ? TIOCM_CTS: 0) /* 0x020 */
2349 | ((msr & EDGEPORT_MSR_CD) ? TIOCM_CAR: 0) /* 0x040 */
2350 | ((msr & EDGEPORT_MSR_RI) ? TIOCM_RI: 0) /* 0x080 */
2351 | ((msr & EDGEPORT_MSR_DSR) ? TIOCM_DSR: 0); /* 0x100 */
2352
2353
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002354 dev_dbg(&port->dev, "%s -- %x\n", __func__, result);
Alan Cox3d71fe02008-02-20 21:38:32 +00002355 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356
2357 return result;
2358}
2359
Alan Cox2742fd82008-04-29 14:45:15 +01002360static int get_serial_info(struct edgeport_port *edge_port,
2361 struct serial_struct __user *retinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362{
2363 struct serial_struct tmp;
Johan Hovoldf40d7812013-01-14 16:52:58 +01002364 unsigned cwait;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365
2366 if (!retinfo)
2367 return -EFAULT;
2368
Johan Hovoldf40d7812013-01-14 16:52:58 +01002369 cwait = edge_port->port->port.closing_wait;
2370 if (cwait != ASYNC_CLOSING_WAIT_NONE)
2371 cwait = jiffies_to_msecs(closing_wait) / 10;
2372
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 memset(&tmp, 0, sizeof(tmp));
2374
2375 tmp.type = PORT_16550A;
2376 tmp.line = edge_port->port->serial->minor;
2377 tmp.port = edge_port->port->number;
2378 tmp.irq = 0;
2379 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
2380 tmp.xmit_fifo_size = edge_port->port->bulk_out_size;
2381 tmp.baud_base = 9600;
2382 tmp.close_delay = 5*HZ;
Johan Hovoldf40d7812013-01-14 16:52:58 +01002383 tmp.closing_wait = cwait;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384
2385 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2386 return -EFAULT;
2387 return 0;
2388}
2389
Alan Cox00a0d0d2011-02-14 16:27:06 +00002390static int edge_ioctl(struct tty_struct *tty,
Alan Cox2742fd82008-04-29 14:45:15 +01002391 unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392{
Alan Cox95da3102008-07-22 11:09:07 +01002393 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2395 struct async_icount cnow;
2396 struct async_icount cprev;
2397
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002398 dev_dbg(&port->dev, "%s - port %d, cmd = 0x%x\n", __func__, port->number, cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399
2400 switch (cmd) {
Alan Cox2742fd82008-04-29 14:45:15 +01002401 case TIOCGSERIAL:
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002402 dev_dbg(&port->dev, "%s - TIOCGSERIAL\n", __func__);
Alan Cox2742fd82008-04-29 14:45:15 +01002403 return get_serial_info(edge_port,
2404 (struct serial_struct __user *) arg);
2405 case TIOCMIWAIT:
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002406 dev_dbg(&port->dev, "%s - TIOCMIWAIT\n", __func__);
Johan Hovoldcf9a9d62013-03-21 12:37:09 +01002407 cprev = edge_port->port->icount;
Alan Cox2742fd82008-04-29 14:45:15 +01002408 while (1) {
Johan Hovold7b245962013-03-19 09:21:17 +01002409 interruptible_sleep_on(&port->delta_msr_wait);
Alan Cox2742fd82008-04-29 14:45:15 +01002410 /* see if a signal did it */
2411 if (signal_pending(current))
2412 return -ERESTARTSYS;
Johan Hovold7b245962013-03-19 09:21:17 +01002413
2414 if (port->serial->disconnected)
2415 return -EIO;
2416
Johan Hovoldcf9a9d62013-03-21 12:37:09 +01002417 cnow = port->icount;
Alan Cox2742fd82008-04-29 14:45:15 +01002418 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2419 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2420 return -EIO; /* no change => error */
2421 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2422 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2423 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2424 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
2425 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 }
Alan Cox2742fd82008-04-29 14:45:15 +01002427 cprev = cnow;
2428 }
2429 /* not reached */
2430 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 return -ENOIOCTLCMD;
2433}
2434
Alan Cox95da3102008-07-22 11:09:07 +01002435static void edge_break(struct tty_struct *tty, int break_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436{
Alan Cox95da3102008-07-22 11:09:07 +01002437 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2439 int status;
Alan Cox2742fd82008-04-29 14:45:15 +01002440 int bv = 0; /* Off */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441
Johan Hovoldf40d7812013-01-14 16:52:58 +01002442 tty_wait_until_sent(tty, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443
Alan Cox95da3102008-07-22 11:09:07 +01002444 if (break_state == -1)
Alan Cox2742fd82008-04-29 14:45:15 +01002445 bv = 1; /* On */
2446 status = ti_do_config(edge_port, UMPC_SET_CLR_BREAK, bv);
2447 if (status)
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002448 dev_dbg(&port->dev, "%s - error %d sending break set/clear command.\n",
2449 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450}
2451
Alan Cox2742fd82008-04-29 14:45:15 +01002452static int edge_startup(struct usb_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453{
2454 struct edgeport_serial *edge_serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456
2457 /* create our private serial structure */
Eric Sesterhenn80b6ca42006-02-27 21:29:43 +01002458 edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 if (edge_serial == NULL) {
Harvey Harrison441b62c2008-03-03 16:08:34 -08002460 dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 return -ENOMEM;
2462 }
Matthias Kaehlcke241ca642007-12-04 16:15:40 +01002463 mutex_init(&edge_serial->es_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 edge_serial->serial = serial;
2465 usb_set_serial_data(serial, edge_serial);
2466
Alan Cox2742fd82008-04-29 14:45:15 +01002467 status = download_fw(edge_serial);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 if (status) {
Alan Cox2742fd82008-04-29 14:45:15 +01002469 kfree(edge_serial);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 return status;
2471 }
2472
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474}
2475
Alan Sternf9c99bb2009-06-02 11:53:55 -04002476static void edge_disconnect(struct usb_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477{
Alan Sternf9c99bb2009-06-02 11:53:55 -04002478}
2479
2480static void edge_release(struct usb_serial *serial)
2481{
Jesper Juhl0d46c002007-07-16 22:17:25 +02002482 kfree(usb_get_serial_data(serial));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483}
2484
Johan Hovold00361532012-10-17 13:34:58 +02002485static int edge_port_probe(struct usb_serial_port *port)
2486{
2487 struct edgeport_port *edge_port;
2488 int ret;
2489
2490 edge_port = kzalloc(sizeof(*edge_port), GFP_KERNEL);
2491 if (!edge_port)
2492 return -ENOMEM;
2493
2494 ret = kfifo_alloc(&edge_port->write_fifo, EDGE_OUT_BUF_SIZE,
2495 GFP_KERNEL);
2496 if (ret) {
2497 kfree(edge_port);
2498 return -ENOMEM;
2499 }
2500
Johan Hovold00361532012-10-17 13:34:58 +02002501 spin_lock_init(&edge_port->ep_lock);
2502 edge_port->port = port;
2503 edge_port->edge_serial = usb_get_serial_data(port->serial);
2504 edge_port->bUartMode = default_uart_mode;
2505
2506 usb_set_serial_port_data(port, edge_port);
2507
Johan Hovold5d8c61b2012-10-18 11:43:28 +02002508 ret = edge_create_sysfs_attrs(port);
2509 if (ret) {
2510 kfifo_free(&edge_port->write_fifo);
2511 kfree(edge_port);
2512 return ret;
2513 }
2514
Johan Hovoldf40d7812013-01-14 16:52:58 +01002515 port->port.closing_wait = msecs_to_jiffies(closing_wait * 10);
2516
Johan Hovold00361532012-10-17 13:34:58 +02002517 return 0;
2518}
2519
2520static int edge_port_remove(struct usb_serial_port *port)
2521{
2522 struct edgeport_port *edge_port;
2523
2524 edge_port = usb_get_serial_port_data(port);
2525
2526 edge_remove_sysfs_attrs(port);
2527 kfifo_free(&edge_port->write_fifo);
2528 kfree(edge_port);
2529
2530 return 0;
2531}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -04002533/* Sysfs Attributes */
2534
2535static ssize_t show_uart_mode(struct device *dev,
2536 struct device_attribute *attr, char *buf)
2537{
2538 struct usb_serial_port *port = to_usb_serial_port(dev);
2539 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2540
2541 return sprintf(buf, "%d\n", edge_port->bUartMode);
2542}
2543
2544static ssize_t store_uart_mode(struct device *dev,
2545 struct device_attribute *attr, const char *valbuf, size_t count)
2546{
2547 struct usb_serial_port *port = to_usb_serial_port(dev);
2548 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2549 unsigned int v = simple_strtoul(valbuf, NULL, 0);
2550
Greg Kroah-Hartman67e6da72012-09-14 16:58:58 -07002551 dev_dbg(dev, "%s: setting uart_mode = %d\n", __func__, v);
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -04002552
2553 if (v < 256)
2554 edge_port->bUartMode = v;
2555 else
Harvey Harrison441b62c2008-03-03 16:08:34 -08002556 dev_err(dev, "%s - uart_mode %d is invalid\n", __func__, v);
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -04002557
2558 return count;
2559}
2560
Alan Cox2742fd82008-04-29 14:45:15 +01002561static DEVICE_ATTR(uart_mode, S_IWUSR | S_IRUGO, show_uart_mode,
2562 store_uart_mode);
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -04002563
2564static int edge_create_sysfs_attrs(struct usb_serial_port *port)
2565{
2566 return device_create_file(&port->dev, &dev_attr_uart_mode);
2567}
2568
2569static int edge_remove_sysfs_attrs(struct usb_serial_port *port)
2570{
2571 device_remove_file(&port->dev, &dev_attr_uart_mode);
2572 return 0;
2573}
2574
2575
Greg Kroah-Hartmanea653702005-06-20 21:15:16 -07002576static struct usb_serial_driver edgeport_1port_device = {
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -07002577 .driver = {
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -07002578 .owner = THIS_MODULE,
2579 .name = "edgeport_ti_1",
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -07002580 },
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -07002581 .description = "Edgeport TI 1 port adapter",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 .id_table = edgeport_1port_id_table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 .num_ports = 1,
2584 .open = edge_open,
2585 .close = edge_close,
2586 .throttle = edge_throttle,
2587 .unthrottle = edge_unthrottle,
2588 .attach = edge_startup,
Alan Sternf9c99bb2009-06-02 11:53:55 -04002589 .disconnect = edge_disconnect,
2590 .release = edge_release,
Johan Hovold00361532012-10-17 13:34:58 +02002591 .port_probe = edge_port_probe,
2592 .port_remove = edge_port_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 .ioctl = edge_ioctl,
2594 .set_termios = edge_set_termios,
2595 .tiocmget = edge_tiocmget,
2596 .tiocmset = edge_tiocmset,
Johan Hovoldcf9a9d62013-03-21 12:37:09 +01002597 .get_icount = usb_serial_generic_get_icount,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 .write = edge_write,
2599 .write_room = edge_write_room,
2600 .chars_in_buffer = edge_chars_in_buffer,
2601 .break_ctl = edge_break,
2602 .read_int_callback = edge_interrupt_callback,
2603 .read_bulk_callback = edge_bulk_in_callback,
2604 .write_bulk_callback = edge_bulk_out_callback,
2605};
2606
Greg Kroah-Hartmanea653702005-06-20 21:15:16 -07002607static struct usb_serial_driver edgeport_2port_device = {
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -07002608 .driver = {
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -07002609 .owner = THIS_MODULE,
2610 .name = "edgeport_ti_2",
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -07002611 },
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -07002612 .description = "Edgeport TI 2 port adapter",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 .id_table = edgeport_2port_id_table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 .num_ports = 2,
2615 .open = edge_open,
2616 .close = edge_close,
2617 .throttle = edge_throttle,
2618 .unthrottle = edge_unthrottle,
2619 .attach = edge_startup,
Alan Sternf9c99bb2009-06-02 11:53:55 -04002620 .disconnect = edge_disconnect,
2621 .release = edge_release,
Johan Hovold00361532012-10-17 13:34:58 +02002622 .port_probe = edge_port_probe,
2623 .port_remove = edge_port_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 .ioctl = edge_ioctl,
2625 .set_termios = edge_set_termios,
2626 .tiocmget = edge_tiocmget,
2627 .tiocmset = edge_tiocmset,
Johan Hovoldcf9a9d62013-03-21 12:37:09 +01002628 .get_icount = usb_serial_generic_get_icount,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 .write = edge_write,
2630 .write_room = edge_write_room,
2631 .chars_in_buffer = edge_chars_in_buffer,
2632 .break_ctl = edge_break,
2633 .read_int_callback = edge_interrupt_callback,
2634 .read_bulk_callback = edge_bulk_in_callback,
2635 .write_bulk_callback = edge_bulk_out_callback,
2636};
2637
Alan Stern7dbe2462012-02-23 14:56:57 -05002638static struct usb_serial_driver * const serial_drivers[] = {
2639 &edgeport_1port_device, &edgeport_2port_device, NULL
2640};
2641
Greg Kroah-Hartman68e24112012-05-08 15:46:14 -07002642module_usb_serial_driver(serial_drivers, id_table_combined);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644MODULE_AUTHOR(DRIVER_AUTHOR);
2645MODULE_DESCRIPTION(DRIVER_DESC);
2646MODULE_LICENSE("GPL");
Jaswinder Singhd12b2192008-07-04 23:06:09 +05302647MODULE_FIRMWARE("edgeport/down3.bin");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649module_param(closing_wait, int, S_IRUGO | S_IWUSR);
2650MODULE_PARM_DESC(closing_wait, "Maximum wait for data to drain, in .01 secs");
2651
2652module_param(ignore_cpu_rev, bool, S_IRUGO | S_IWUSR);
Alan Cox2742fd82008-04-29 14:45:15 +01002653MODULE_PARM_DESC(ignore_cpu_rev,
2654 "Ignore the cpu revision when connecting to a device");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655
Martin K. Petersenfc4cbd72007-05-22 15:57:04 -04002656module_param(default_uart_mode, int, S_IRUGO | S_IWUSR);
2657MODULE_PARM_DESC(default_uart_mode, "Default uart_mode, 0=RS232, ...");