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