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