diff options
author | Alan Cox <alan@redhat.com> | 2008-07-22 06:16:34 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-07-22 16:03:27 -0400 |
commit | 03f0dbf74c7a117c270e63d62d5e4927af6f295b (patch) | |
tree | 068aef14e0f6182744bcc68988cc250b26a76d05 /drivers/usb/serial/io_edgeport.c | |
parent | 4da1a17dbc5211ac90264cfc4f0e076c8bdc1732 (diff) |
tty-usb-io_edgeport: Coding style
Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/usb/serial/io_edgeport.c')
-rw-r--r-- | drivers/usb/serial/io_edgeport.c | 1823 |
1 files changed, 1020 insertions, 803 deletions
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c index 29346d79df7b..b4bd6847a96d 100644 --- a/drivers/usb/serial/io_edgeport.c +++ b/drivers/usb/serial/io_edgeport.c | |||
@@ -44,7 +44,7 @@ | |||
44 | #include <linux/wait.h> | 44 | #include <linux/wait.h> |
45 | #include <linux/firmware.h> | 45 | #include <linux/firmware.h> |
46 | #include <linux/ihex.h> | 46 | #include <linux/ihex.h> |
47 | #include <asm/uaccess.h> | 47 | #include <linux/uaccess.h> |
48 | #include <linux/usb.h> | 48 | #include <linux/usb.h> |
49 | #include <linux/usb/serial.h> | 49 | #include <linux/usb/serial.h> |
50 | #include "io_edgeport.h" | 50 | #include "io_edgeport.h" |
@@ -66,16 +66,16 @@ | |||
66 | 66 | ||
67 | /* receive port state */ | 67 | /* receive port state */ |
68 | enum RXSTATE { | 68 | enum RXSTATE { |
69 | EXPECT_HDR1 = 0, /* Expect header byte 1 */ | 69 | EXPECT_HDR1 = 0, /* Expect header byte 1 */ |
70 | EXPECT_HDR2 = 1, /* Expect header byte 2 */ | 70 | EXPECT_HDR2 = 1, /* Expect header byte 2 */ |
71 | EXPECT_DATA = 2, /* Expect 'RxBytesRemaining' data */ | 71 | EXPECT_DATA = 2, /* Expect 'RxBytesRemaining' data */ |
72 | EXPECT_HDR3 = 3, /* Expect header byte 3 (for status hdrs only) */ | 72 | EXPECT_HDR3 = 3, /* Expect header byte 3 (for status hdrs only) */ |
73 | }; | 73 | }; |
74 | 74 | ||
75 | 75 | ||
76 | /* Transmit Fifo | 76 | /* Transmit Fifo |
77 | * This Transmit queue is an extension of the edgeport Rx buffer. | 77 | * This Transmit queue is an extension of the edgeport Rx buffer. |
78 | * The maximum amount of data buffered in both the edgeport | 78 | * The maximum amount of data buffered in both the edgeport |
79 | * Rx buffer (maxTxCredits) and this buffer will never exceed maxTxCredits. | 79 | * Rx buffer (maxTxCredits) and this buffer will never exceed maxTxCredits. |
80 | */ | 80 | */ |
81 | struct TxFifo { | 81 | struct TxFifo { |
@@ -132,12 +132,12 @@ struct edgeport_serial { | |||
132 | int is_epic; /* flag if EPiC device or not */ | 132 | int is_epic; /* flag if EPiC device or not */ |
133 | 133 | ||
134 | __u8 interrupt_in_endpoint; /* the interrupt endpoint handle */ | 134 | __u8 interrupt_in_endpoint; /* the interrupt endpoint handle */ |
135 | unsigned char * interrupt_in_buffer; /* the buffer we use for the interrupt endpoint */ | 135 | unsigned char *interrupt_in_buffer; /* the buffer we use for the interrupt endpoint */ |
136 | struct urb * interrupt_read_urb; /* our interrupt urb */ | 136 | struct urb *interrupt_read_urb; /* our interrupt urb */ |
137 | 137 | ||
138 | __u8 bulk_in_endpoint; /* the bulk in endpoint handle */ | 138 | __u8 bulk_in_endpoint; /* the bulk in endpoint handle */ |
139 | unsigned char * bulk_in_buffer; /* the buffer we use for the bulk in endpoint */ | 139 | unsigned char *bulk_in_buffer; /* the buffer we use for the bulk in endpoint */ |
140 | struct urb * read_urb; /* our bulk read urb */ | 140 | struct urb *read_urb; /* our bulk read urb */ |
141 | bool read_in_progress; | 141 | bool read_in_progress; |
142 | spinlock_t es_lock; | 142 | spinlock_t es_lock; |
143 | 143 | ||
@@ -162,16 +162,17 @@ struct divisor_table_entry { | |||
162 | __u16 Divisor; | 162 | __u16 Divisor; |
163 | }; | 163 | }; |
164 | 164 | ||
165 | // | 165 | /* |
166 | // Define table of divisors for Rev A EdgePort/4 hardware | 166 | * Define table of divisors for Rev A EdgePort/4 hardware |
167 | // These assume a 3.6864MHz crystal, the standard /16, and | 167 | * These assume a 3.6864MHz crystal, the standard /16, and |
168 | // MCR.7 = 0. | 168 | * MCR.7 = 0. |
169 | // | 169 | */ |
170 | |||
170 | static const struct divisor_table_entry divisor_table[] = { | 171 | static const struct divisor_table_entry divisor_table[] = { |
171 | { 50, 4608}, | 172 | { 50, 4608}, |
172 | { 75, 3072}, | 173 | { 75, 3072}, |
173 | { 110, 2095}, /* 2094.545455 => 230450 => .0217 % over */ | 174 | { 110, 2095}, /* 2094.545455 => 230450 => .0217 % over */ |
174 | { 134, 1713}, /* 1713.011152 => 230398.5 => .00065% under */ | 175 | { 134, 1713}, /* 1713.011152 => 230398.5 => .00065% under */ |
175 | { 150, 1536}, | 176 | { 150, 1536}, |
176 | { 300, 768}, | 177 | { 300, 768}, |
177 | { 600, 384}, | 178 | { 600, 384}, |
@@ -194,65 +195,86 @@ static int debug; | |||
194 | 195 | ||
195 | static int low_latency = 1; /* tty low latency flag, on by default */ | 196 | static int low_latency = 1; /* tty low latency flag, on by default */ |
196 | 197 | ||
197 | static atomic_t CmdUrbs; /* Number of outstanding Command Write Urbs */ | 198 | static atomic_t CmdUrbs; /* Number of outstanding Command Write Urbs */ |
198 | 199 | ||
199 | 200 | ||
200 | /* local function prototypes */ | 201 | /* local function prototypes */ |
201 | 202 | ||
202 | /* function prototypes for all URB callbacks */ | 203 | /* function prototypes for all URB callbacks */ |
203 | static void edge_interrupt_callback (struct urb *urb); | 204 | static void edge_interrupt_callback(struct urb *urb); |
204 | static void edge_bulk_in_callback (struct urb *urb); | 205 | static void edge_bulk_in_callback(struct urb *urb); |
205 | static void edge_bulk_out_data_callback (struct urb *urb); | 206 | static void edge_bulk_out_data_callback(struct urb *urb); |
206 | static void edge_bulk_out_cmd_callback (struct urb *urb); | 207 | static void edge_bulk_out_cmd_callback(struct urb *urb); |
207 | 208 | ||
208 | /* function prototypes for the usbserial callbacks */ | 209 | /* function prototypes for the usbserial callbacks */ |
209 | static int edge_open (struct tty_struct *tty, struct usb_serial_port *port, struct file *filp); | 210 | static int edge_open(struct tty_struct *tty, struct usb_serial_port *port, |
210 | static void edge_close (struct tty_struct *tty, struct usb_serial_port *port, struct file *filp); | 211 | struct file *filp); |
211 | static int edge_write (struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count); | 212 | static void edge_close(struct tty_struct *tty, struct usb_serial_port *port, |
212 | static int edge_write_room (struct tty_struct *tty); | 213 | struct file *filp); |
213 | static int edge_chars_in_buffer (struct tty_struct *tty); | 214 | static int edge_write(struct tty_struct *tty, struct usb_serial_port *port, |
214 | static void edge_throttle (struct tty_struct *tty); | 215 | const unsigned char *buf, int count); |
215 | static void edge_unthrottle (struct tty_struct *tty); | 216 | static int edge_write_room(struct tty_struct *tty); |
216 | static void edge_set_termios (struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios); | 217 | static int edge_chars_in_buffer(struct tty_struct *tty); |
217 | static int edge_ioctl (struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg); | 218 | static void edge_throttle(struct tty_struct *tty); |
218 | static void edge_break (struct tty_struct *tty, int break_state); | 219 | static void edge_unthrottle(struct tty_struct *tty); |
219 | static int edge_tiocmget (struct tty_struct *tty, struct file *file); | 220 | static void edge_set_termios(struct tty_struct *tty, |
220 | static int edge_tiocmset (struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear); | 221 | struct usb_serial_port *port, |
221 | static int edge_startup (struct usb_serial *serial); | 222 | struct ktermios *old_termios); |
222 | static void edge_shutdown (struct usb_serial *serial); | 223 | static int edge_ioctl(struct tty_struct *tty, struct file *file, |
223 | 224 | unsigned int cmd, unsigned long arg); | |
225 | static void edge_break(struct tty_struct *tty, int break_state); | ||
226 | static int edge_tiocmget(struct tty_struct *tty, struct file *file); | ||
227 | static int edge_tiocmset(struct tty_struct *tty, struct file *file, | ||
228 | unsigned int set, unsigned int clear); | ||
229 | static int edge_startup(struct usb_serial *serial); | ||
230 | static void edge_shutdown(struct usb_serial *serial); | ||
224 | 231 | ||
225 | #include "io_tables.h" /* all of the devices that this driver supports */ | 232 | #include "io_tables.h" /* all of the devices that this driver supports */ |
226 | 233 | ||
227 | /* function prototypes for all of our local functions */ | 234 | /* function prototypes for all of our local functions */ |
228 | static void process_rcvd_data (struct edgeport_serial *edge_serial, unsigned char *buffer, __u16 bufferLength); | 235 | |
229 | static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2, __u8 byte3); | 236 | static void process_rcvd_data(struct edgeport_serial *edge_serial, |
230 | static void edge_tty_recv (struct device *dev, struct tty_struct *tty, unsigned char *data, int length); | 237 | unsigned char *buffer, __u16 bufferLength); |
231 | static void handle_new_msr (struct edgeport_port *edge_port, __u8 newMsr); | 238 | static void process_rcvd_status(struct edgeport_serial *edge_serial, |
232 | static void handle_new_lsr (struct edgeport_port *edge_port, __u8 lsrData, __u8 lsr, __u8 data); | 239 | __u8 byte2, __u8 byte3); |
233 | static int send_iosp_ext_cmd (struct edgeport_port *edge_port, __u8 command, __u8 param); | 240 | static void edge_tty_recv(struct device *dev, struct tty_struct *tty, |
234 | static int calc_baud_rate_divisor (int baud_rate, int *divisor); | 241 | unsigned char *data, int length); |
235 | static int send_cmd_write_baud_rate (struct edgeport_port *edge_port, int baudRate); | 242 | static void handle_new_msr(struct edgeport_port *edge_port, __u8 newMsr); |
236 | static void change_port_settings (struct tty_struct *tty, struct edgeport_port *edge_port, | 243 | static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData, |
237 | struct ktermios *old_termios); | 244 | __u8 lsr, __u8 data); |
238 | static int send_cmd_write_uart_register (struct edgeport_port *edge_port, __u8 regNum, __u8 regValue); | 245 | static int send_iosp_ext_cmd(struct edgeport_port *edge_port, __u8 command, |
239 | static int write_cmd_usb (struct edgeport_port *edge_port, unsigned char *buffer, int writeLength); | 246 | __u8 param); |
240 | static void send_more_port_data (struct edgeport_serial *edge_serial, struct edgeport_port *edge_port); | 247 | static int calc_baud_rate_divisor(int baud_rate, int *divisor); |
241 | 248 | static int send_cmd_write_baud_rate(struct edgeport_port *edge_port, | |
242 | static int sram_write (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, const __u8 *data); | 249 | int baudRate); |
243 | static int rom_read (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, __u8 *data); | 250 | static void change_port_settings(struct tty_struct *tty, |
244 | static int rom_write (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, const __u8 *data); | 251 | struct edgeport_port *edge_port, |
245 | static void get_manufacturing_desc (struct edgeport_serial *edge_serial); | 252 | struct ktermios *old_termios); |
246 | static void get_boot_desc (struct edgeport_serial *edge_serial); | 253 | static int send_cmd_write_uart_register(struct edgeport_port *edge_port, |
247 | static void load_application_firmware (struct edgeport_serial *edge_serial); | 254 | __u8 regNum, __u8 regValue); |
248 | 255 | static int write_cmd_usb(struct edgeport_port *edge_port, | |
249 | static void unicode_to_ascii(char *string, int buflen, __le16 *unicode, int unicode_size); | 256 | unsigned char *buffer, int writeLength); |
250 | 257 | static void send_more_port_data(struct edgeport_serial *edge_serial, | |
251 | 258 | struct edgeport_port *edge_port); | |
252 | // ************************************************************************ | 259 | |
253 | // ************************************************************************ | 260 | static int sram_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, |
254 | // ************************************************************************ | 261 | __u16 length, const __u8 *data); |
255 | // ************************************************************************ | 262 | static int rom_read(struct usb_serial *serial, __u16 extAddr, __u16 addr, |
263 | __u16 length, __u8 *data); | ||
264 | static int rom_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, | ||
265 | __u16 length, const __u8 *data); | ||
266 | static void get_manufacturing_desc(struct edgeport_serial *edge_serial); | ||
267 | static void get_boot_desc(struct edgeport_serial *edge_serial); | ||
268 | static void load_application_firmware(struct edgeport_serial *edge_serial); | ||
269 | |||
270 | static void unicode_to_ascii(char *string, int buflen, | ||
271 | __le16 *unicode, int unicode_size); | ||
272 | |||
273 | |||
274 | /* ************************************************************************ */ | ||
275 | /* ************************************************************************ */ | ||
276 | /* ************************************************************************ */ | ||
277 | /* ************************************************************************ */ | ||
256 | 278 | ||
257 | /************************************************************************ | 279 | /************************************************************************ |
258 | * * | 280 | * * |
@@ -262,7 +284,7 @@ static void unicode_to_ascii(char *string, int buflen, __le16 *unicode, int unic | |||
262 | * embedded in this driver * | 284 | * embedded in this driver * |
263 | * * | 285 | * * |
264 | ************************************************************************/ | 286 | ************************************************************************/ |
265 | static void update_edgeport_E2PROM (struct edgeport_serial *edge_serial) | 287 | static void update_edgeport_E2PROM(struct edgeport_serial *edge_serial) |
266 | { | 288 | { |
267 | __u32 BootCurVer; | 289 | __u32 BootCurVer; |
268 | __u32 BootNewVer; | 290 | __u32 BootNewVer; |
@@ -276,16 +298,14 @@ static void update_edgeport_E2PROM (struct edgeport_serial *edge_serial) | |||
276 | int response; | 298 | int response; |
277 | 299 | ||
278 | switch (edge_serial->product_info.iDownloadFile) { | 300 | switch (edge_serial->product_info.iDownloadFile) { |
279 | case EDGE_DOWNLOAD_FILE_I930: | 301 | case EDGE_DOWNLOAD_FILE_I930: |
280 | fw_name = "edgeport/boot.fw"; | 302 | fw_name = "edgeport/boot.fw"; |
281 | break; | 303 | break; |
282 | 304 | case EDGE_DOWNLOAD_FILE_80251: | |
283 | case EDGE_DOWNLOAD_FILE_80251: | 305 | fw_name = "edgeport/boot2.fw"; |
284 | fw_name = "edgeport/boot2.fw"; | 306 | break; |
285 | break; | 307 | default: |
286 | 308 | return; | |
287 | default: | ||
288 | return; | ||
289 | } | 309 | } |
290 | 310 | ||
291 | response = request_ihex_firmware(&fw, fw_name, | 311 | response = request_ihex_firmware(&fw, fw_name, |
@@ -301,7 +321,7 @@ static void update_edgeport_E2PROM (struct edgeport_serial *edge_serial) | |||
301 | BootMinorVersion = rec->data[1]; | 321 | BootMinorVersion = rec->data[1]; |
302 | BootBuildNumber = (rec->data[2] << 8) | rec->data[3]; | 322 | BootBuildNumber = (rec->data[2] << 8) | rec->data[3]; |
303 | 323 | ||
304 | // Check Boot Image Version | 324 | /* Check Boot Image Version */ |
305 | BootCurVer = (edge_serial->boot_descriptor.MajorVersion << 24) + | 325 | BootCurVer = (edge_serial->boot_descriptor.MajorVersion << 24) + |
306 | (edge_serial->boot_descriptor.MinorVersion << 16) + | 326 | (edge_serial->boot_descriptor.MinorVersion << 16) + |
307 | le16_to_cpu(edge_serial->boot_descriptor.BuildNumber); | 327 | le16_to_cpu(edge_serial->boot_descriptor.BuildNumber); |
@@ -353,29 +373,29 @@ static void update_edgeport_E2PROM (struct edgeport_serial *edge_serial) | |||
353 | * Get string descriptor from device * | 373 | * Get string descriptor from device * |
354 | * * | 374 | * * |
355 | ************************************************************************/ | 375 | ************************************************************************/ |
356 | static int get_string (struct usb_device *dev, int Id, char *string, int buflen) | 376 | static int get_string(struct usb_device *dev, int Id, char *string, int buflen) |
357 | { | 377 | { |
358 | struct usb_string_descriptor StringDesc; | 378 | struct usb_string_descriptor StringDesc; |
359 | struct usb_string_descriptor *pStringDesc; | 379 | struct usb_string_descriptor *pStringDesc; |
360 | 380 | ||
361 | dbg("%s - USB String ID = %d", __func__, Id ); | 381 | dbg("%s - USB String ID = %d", __func__, Id); |
362 | 382 | ||
363 | if (!usb_get_descriptor(dev, USB_DT_STRING, Id, &StringDesc, sizeof(StringDesc))) { | 383 | if (!usb_get_descriptor(dev, USB_DT_STRING, Id, |
384 | &StringDesc, sizeof(StringDesc))) | ||
364 | return 0; | 385 | return 0; |
365 | } | ||
366 | |||
367 | pStringDesc = kmalloc (StringDesc.bLength, GFP_KERNEL); | ||
368 | 386 | ||
369 | if (!pStringDesc) { | 387 | pStringDesc = kmalloc(StringDesc.bLength, GFP_KERNEL); |
388 | if (!pStringDesc) | ||
370 | return 0; | 389 | return 0; |
371 | } | ||
372 | 390 | ||
373 | if (!usb_get_descriptor(dev, USB_DT_STRING, Id, pStringDesc, StringDesc.bLength )) { | 391 | if (!usb_get_descriptor(dev, USB_DT_STRING, Id, |
392 | pStringDesc, StringDesc.bLength)) { | ||
374 | kfree(pStringDesc); | 393 | kfree(pStringDesc); |
375 | return 0; | 394 | return 0; |
376 | } | 395 | } |
377 | 396 | ||
378 | unicode_to_ascii(string, buflen, pStringDesc->wData, pStringDesc->bLength/2); | 397 | unicode_to_ascii(string, buflen, |
398 | pStringDesc->wData, pStringDesc->bLength/2); | ||
379 | 399 | ||
380 | kfree(pStringDesc); | 400 | kfree(pStringDesc); |
381 | dbg("%s - USB String %s", __func__, string); | 401 | dbg("%s - USB String %s", __func__, string); |
@@ -389,24 +409,24 @@ static int get_string (struct usb_device *dev, int Id, char *string, int buflen) | |||
389 | * Get string descriptor from device | 409 | * Get string descriptor from device |
390 | * | 410 | * |
391 | ************************************************************************/ | 411 | ************************************************************************/ |
392 | static int get_string_desc (struct usb_device *dev, int Id, struct usb_string_descriptor **pRetDesc) | 412 | static int get_string_desc(struct usb_device *dev, int Id, |
413 | struct usb_string_descriptor **pRetDesc) | ||
393 | { | 414 | { |
394 | struct usb_string_descriptor StringDesc; | 415 | struct usb_string_descriptor StringDesc; |
395 | struct usb_string_descriptor *pStringDesc; | 416 | struct usb_string_descriptor *pStringDesc; |
396 | 417 | ||
397 | dbg("%s - USB String ID = %d", __func__, Id ); | 418 | dbg("%s - USB String ID = %d", __func__, Id); |
398 | 419 | ||
399 | if (!usb_get_descriptor(dev, USB_DT_STRING, Id, &StringDesc, sizeof(StringDesc))) { | 420 | if (!usb_get_descriptor(dev, USB_DT_STRING, Id, &StringDesc, |
421 | sizeof(StringDesc))) | ||
400 | return 0; | 422 | return 0; |
401 | } | ||
402 | |||
403 | pStringDesc = kmalloc (StringDesc.bLength, GFP_KERNEL); | ||
404 | 423 | ||
405 | if (!pStringDesc) { | 424 | pStringDesc = kmalloc(StringDesc.bLength, GFP_KERNEL); |
425 | if (!pStringDesc) | ||
406 | return -1; | 426 | return -1; |
407 | } | ||
408 | 427 | ||
409 | if (!usb_get_descriptor(dev, USB_DT_STRING, Id, pStringDesc, StringDesc.bLength )) { | 428 | if (!usb_get_descriptor(dev, USB_DT_STRING, Id, pStringDesc, |
429 | StringDesc.bLength)) { | ||
410 | kfree(pStringDesc); | 430 | kfree(pStringDesc); |
411 | return -1; | 431 | return -1; |
412 | } | 432 | } |
@@ -418,25 +438,30 @@ static int get_string_desc (struct usb_device *dev, int Id, struct usb_string_de | |||
418 | 438 | ||
419 | static void dump_product_info(struct edgeport_product_info *product_info) | 439 | static void dump_product_info(struct edgeport_product_info *product_info) |
420 | { | 440 | { |
421 | // Dump Product Info structure | 441 | /* Dump Product Info structure */ |
422 | dbg("**Product Information:"); | 442 | dbg("**Product Information:"); |
423 | dbg(" ProductId %x", product_info->ProductId ); | 443 | dbg(" ProductId %x", product_info->ProductId); |
424 | dbg(" NumPorts %d", product_info->NumPorts ); | 444 | dbg(" NumPorts %d", product_info->NumPorts); |
425 | dbg(" ProdInfoVer %d", product_info->ProdInfoVer ); | 445 | dbg(" ProdInfoVer %d", product_info->ProdInfoVer); |
426 | dbg(" IsServer %d", product_info->IsServer); | 446 | dbg(" IsServer %d", product_info->IsServer); |
427 | dbg(" IsRS232 %d", product_info->IsRS232 ); | 447 | dbg(" IsRS232 %d", product_info->IsRS232); |
428 | dbg(" IsRS422 %d", product_info->IsRS422 ); | 448 | dbg(" IsRS422 %d", product_info->IsRS422); |
429 | dbg(" IsRS485 %d", product_info->IsRS485 ); | 449 | dbg(" IsRS485 %d", product_info->IsRS485); |
430 | dbg(" RomSize %d", product_info->RomSize ); | 450 | dbg(" RomSize %d", product_info->RomSize); |
431 | dbg(" RamSize %d", product_info->RamSize ); | 451 | dbg(" RamSize %d", product_info->RamSize); |
432 | dbg(" CpuRev %x", product_info->CpuRev ); | 452 | dbg(" CpuRev %x", product_info->CpuRev); |
433 | dbg(" BoardRev %x", product_info->BoardRev); | 453 | dbg(" BoardRev %x", product_info->BoardRev); |
434 | dbg(" BootMajorVersion %d.%d.%d", product_info->BootMajorVersion, | 454 | dbg(" BootMajorVersion %d.%d.%d", product_info->BootMajorVersion, |
435 | product_info->BootMinorVersion, | 455 | product_info->BootMinorVersion, |
436 | le16_to_cpu(product_info->BootBuildNumber)); | 456 | le16_to_cpu(product_info->BootBuildNumber)); |
437 | dbg(" ManufactureDescDate %d/%d/%d", product_info->ManufactureDescDate[0], | 457 | dbg(" FirmwareMajorVersion %d.%d.%d", |
438 | product_info->ManufactureDescDate[1], | 458 | product_info->FirmwareMajorVersion, |
439 | product_info->ManufactureDescDate[2]+1900); | 459 | product_info->FirmwareMinorVersion, |
460 | le16_to_cpu(product_info->FirmwareBuildNumber)); | ||
461 | dbg(" ManufactureDescDate %d/%d/%d", | ||
462 | product_info->ManufactureDescDate[0], | ||
463 | product_info->ManufactureDescDate[1], | ||
464 | product_info->ManufactureDescDate[2]+1900); | ||
440 | dbg(" iDownloadFile 0x%x", product_info->iDownloadFile); | 465 | dbg(" iDownloadFile 0x%x", product_info->iDownloadFile); |
441 | dbg(" EpicVer %d", product_info->EpicVer); | 466 | dbg(" EpicVer %d", product_info->EpicVer); |
442 | } | 467 | } |
@@ -445,55 +470,60 @@ static void get_product_info(struct edgeport_serial *edge_serial) | |||
445 | { | 470 | { |
446 | struct edgeport_product_info *product_info = &edge_serial->product_info; | 471 | struct edgeport_product_info *product_info = &edge_serial->product_info; |
447 | 472 | ||
448 | memset (product_info, 0, sizeof(struct edgeport_product_info)); | 473 | memset(product_info, 0, sizeof(struct edgeport_product_info)); |
449 | 474 | ||
450 | product_info->ProductId = (__u16)(le16_to_cpu(edge_serial->serial->dev->descriptor.idProduct) & ~ION_DEVICE_ID_80251_NETCHIP); | 475 | product_info->ProductId = (__u16)(le16_to_cpu(edge_serial->serial->dev->descriptor.idProduct) & ~ION_DEVICE_ID_80251_NETCHIP); |
451 | product_info->NumPorts = edge_serial->manuf_descriptor.NumPorts; | 476 | product_info->NumPorts = edge_serial->manuf_descriptor.NumPorts; |
452 | product_info->ProdInfoVer = 0; | 477 | product_info->ProdInfoVer = 0; |
453 | 478 | ||
454 | product_info->RomSize = edge_serial->manuf_descriptor.RomSize; | 479 | product_info->RomSize = edge_serial->manuf_descriptor.RomSize; |
455 | product_info->RamSize = edge_serial->manuf_descriptor.RamSize; | 480 | product_info->RamSize = edge_serial->manuf_descriptor.RamSize; |
456 | product_info->CpuRev = edge_serial->manuf_descriptor.CpuRev; | 481 | product_info->CpuRev = edge_serial->manuf_descriptor.CpuRev; |
457 | product_info->BoardRev = edge_serial->manuf_descriptor.BoardRev; | 482 | product_info->BoardRev = edge_serial->manuf_descriptor.BoardRev; |
458 | 483 | ||
459 | product_info->BootMajorVersion = edge_serial->boot_descriptor.MajorVersion; | 484 | product_info->BootMajorVersion = |
460 | product_info->BootMinorVersion = edge_serial->boot_descriptor.MinorVersion; | 485 | edge_serial->boot_descriptor.MajorVersion; |
461 | product_info->BootBuildNumber = edge_serial->boot_descriptor.BuildNumber; | 486 | product_info->BootMinorVersion = |
462 | 487 | edge_serial->boot_descriptor.MinorVersion; | |
463 | memcpy(product_info->ManufactureDescDate, edge_serial->manuf_descriptor.DescDate, sizeof(edge_serial->manuf_descriptor.DescDate)); | 488 | product_info->BootBuildNumber = |
464 | 489 | edge_serial->boot_descriptor.BuildNumber; | |
465 | // check if this is 2nd generation hardware | 490 | |
466 | if (le16_to_cpu(edge_serial->serial->dev->descriptor.idProduct) & ION_DEVICE_ID_80251_NETCHIP) { | 491 | memcpy(product_info->ManufactureDescDate, |
467 | product_info->iDownloadFile = EDGE_DOWNLOAD_FILE_80251; | 492 | edge_serial->manuf_descriptor.DescDate, |
468 | } else { | 493 | sizeof(edge_serial->manuf_descriptor.DescDate)); |
469 | product_info->iDownloadFile = EDGE_DOWNLOAD_FILE_I930; | 494 | |
470 | } | 495 | /* check if this is 2nd generation hardware */ |
471 | 496 | if (le16_to_cpu(edge_serial->serial->dev->descriptor.idProduct) | |
472 | // Determine Product type and set appropriate flags | 497 | & ION_DEVICE_ID_80251_NETCHIP) |
498 | product_info->iDownloadFile = EDGE_DOWNLOAD_FILE_80251; | ||
499 | else | ||
500 | product_info->iDownloadFile = EDGE_DOWNLOAD_FILE_I930; | ||
501 | |||
502 | /* Determine Product type and set appropriate flags */ | ||
473 | switch (DEVICE_ID_FROM_USB_PRODUCT_ID(product_info->ProductId)) { | 503 | switch (DEVICE_ID_FROM_USB_PRODUCT_ID(product_info->ProductId)) { |
474 | case ION_DEVICE_ID_EDGEPORT_COMPATIBLE: | 504 | case ION_DEVICE_ID_EDGEPORT_COMPATIBLE: |
475 | case ION_DEVICE_ID_EDGEPORT_4T: | 505 | case ION_DEVICE_ID_EDGEPORT_4T: |
476 | case ION_DEVICE_ID_EDGEPORT_4: | 506 | case ION_DEVICE_ID_EDGEPORT_4: |
477 | case ION_DEVICE_ID_EDGEPORT_2: | 507 | case ION_DEVICE_ID_EDGEPORT_2: |
478 | case ION_DEVICE_ID_EDGEPORT_8_DUAL_CPU: | 508 | case ION_DEVICE_ID_EDGEPORT_8_DUAL_CPU: |
479 | case ION_DEVICE_ID_EDGEPORT_8: | 509 | case ION_DEVICE_ID_EDGEPORT_8: |
480 | case ION_DEVICE_ID_EDGEPORT_421: | 510 | case ION_DEVICE_ID_EDGEPORT_421: |
481 | case ION_DEVICE_ID_EDGEPORT_21: | 511 | case ION_DEVICE_ID_EDGEPORT_21: |
482 | case ION_DEVICE_ID_EDGEPORT_2_DIN: | 512 | case ION_DEVICE_ID_EDGEPORT_2_DIN: |
483 | case ION_DEVICE_ID_EDGEPORT_4_DIN: | 513 | case ION_DEVICE_ID_EDGEPORT_4_DIN: |
484 | case ION_DEVICE_ID_EDGEPORT_16_DUAL_CPU: | 514 | case ION_DEVICE_ID_EDGEPORT_16_DUAL_CPU: |
485 | product_info->IsRS232 = 1; | 515 | product_info->IsRS232 = 1; |
486 | break; | 516 | break; |
487 | 517 | ||
488 | case ION_DEVICE_ID_EDGEPORT_2I: // Edgeport/2 RS422/RS485 | 518 | case ION_DEVICE_ID_EDGEPORT_2I: /* Edgeport/2 RS422/RS485 */ |
489 | product_info->IsRS422 = 1; | 519 | product_info->IsRS422 = 1; |
490 | product_info->IsRS485 = 1; | 520 | product_info->IsRS485 = 1; |
491 | break; | 521 | break; |
492 | 522 | ||
493 | case ION_DEVICE_ID_EDGEPORT_8I: // Edgeport/4 RS422 | 523 | case ION_DEVICE_ID_EDGEPORT_8I: /* Edgeport/4 RS422 */ |
494 | case ION_DEVICE_ID_EDGEPORT_4I: // Edgeport/4 RS422 | 524 | case ION_DEVICE_ID_EDGEPORT_4I: /* Edgeport/4 RS422 */ |
495 | product_info->IsRS422 = 1; | 525 | product_info->IsRS422 = 1; |
496 | break; | 526 | break; |
497 | } | 527 | } |
498 | 528 | ||
499 | dump_product_info(product_info); | 529 | dump_product_info(product_info); |
@@ -521,32 +551,32 @@ static int get_epic_descriptor(struct edgeport_serial *ep) | |||
521 | ep->is_epic = 1; | 551 | ep->is_epic = 1; |
522 | memset(product_info, 0, sizeof(struct edgeport_product_info)); | 552 | memset(product_info, 0, sizeof(struct edgeport_product_info)); |
523 | 553 | ||
524 | product_info->NumPorts = epic->NumPorts; | 554 | product_info->NumPorts = epic->NumPorts; |
525 | product_info->ProdInfoVer = 0; | 555 | product_info->ProdInfoVer = 0; |
526 | product_info->FirmwareMajorVersion = epic->MajorVersion; | 556 | product_info->FirmwareMajorVersion = epic->MajorVersion; |
527 | product_info->FirmwareMinorVersion = epic->MinorVersion; | 557 | product_info->FirmwareMinorVersion = epic->MinorVersion; |
528 | product_info->FirmwareBuildNumber = epic->BuildNumber; | 558 | product_info->FirmwareBuildNumber = epic->BuildNumber; |
529 | product_info->iDownloadFile = epic->iDownloadFile; | 559 | product_info->iDownloadFile = epic->iDownloadFile; |
530 | product_info->EpicVer = epic->EpicVer; | 560 | product_info->EpicVer = epic->EpicVer; |
531 | product_info->Epic = epic->Supports; | 561 | product_info->Epic = epic->Supports; |
532 | product_info->ProductId = ION_DEVICE_ID_EDGEPORT_COMPATIBLE; | 562 | product_info->ProductId = ION_DEVICE_ID_EDGEPORT_COMPATIBLE; |
533 | dump_product_info(product_info); | 563 | dump_product_info(product_info); |
534 | 564 | ||
535 | bits = &ep->epic_descriptor.Supports; | 565 | bits = &ep->epic_descriptor.Supports; |
536 | dbg("**EPIC descriptor:"); | 566 | dbg("**EPIC descriptor:"); |
537 | dbg(" VendEnableSuspend: %s", bits->VendEnableSuspend ? "TRUE": "FALSE"); | 567 | dbg(" VendEnableSuspend: %s", bits->VendEnableSuspend ? "TRUE": "FALSE"); |
538 | dbg(" IOSPOpen : %s", bits->IOSPOpen ? "TRUE": "FALSE" ); | 568 | dbg(" IOSPOpen : %s", bits->IOSPOpen ? "TRUE": "FALSE"); |
539 | dbg(" IOSPClose : %s", bits->IOSPClose ? "TRUE": "FALSE" ); | 569 | dbg(" IOSPClose : %s", bits->IOSPClose ? "TRUE": "FALSE"); |
540 | dbg(" IOSPChase : %s", bits->IOSPChase ? "TRUE": "FALSE" ); | 570 | dbg(" IOSPChase : %s", bits->IOSPChase ? "TRUE": "FALSE"); |
541 | dbg(" IOSPSetRxFlow : %s", bits->IOSPSetRxFlow ? "TRUE": "FALSE" ); | 571 | dbg(" IOSPSetRxFlow : %s", bits->IOSPSetRxFlow ? "TRUE": "FALSE"); |
542 | dbg(" IOSPSetTxFlow : %s", bits->IOSPSetTxFlow ? "TRUE": "FALSE" ); | 572 | dbg(" IOSPSetTxFlow : %s", bits->IOSPSetTxFlow ? "TRUE": "FALSE"); |
543 | dbg(" IOSPSetXChar : %s", bits->IOSPSetXChar ? "TRUE": "FALSE" ); | 573 | dbg(" IOSPSetXChar : %s", bits->IOSPSetXChar ? "TRUE": "FALSE"); |
544 | dbg(" IOSPRxCheck : %s", bits->IOSPRxCheck ? "TRUE": "FALSE" ); | 574 | dbg(" IOSPRxCheck : %s", bits->IOSPRxCheck ? "TRUE": "FALSE"); |
545 | dbg(" IOSPSetClrBreak : %s", bits->IOSPSetClrBreak ? "TRUE": "FALSE" ); | 575 | dbg(" IOSPSetClrBreak : %s", bits->IOSPSetClrBreak ? "TRUE": "FALSE"); |
546 | dbg(" IOSPWriteMCR : %s", bits->IOSPWriteMCR ? "TRUE": "FALSE" ); | 576 | dbg(" IOSPWriteMCR : %s", bits->IOSPWriteMCR ? "TRUE": "FALSE"); |
547 | dbg(" IOSPWriteLCR : %s", bits->IOSPWriteLCR ? "TRUE": "FALSE" ); | 577 | dbg(" IOSPWriteLCR : %s", bits->IOSPWriteLCR ? "TRUE": "FALSE"); |
548 | dbg(" IOSPSetBaudRate : %s", bits->IOSPSetBaudRate ? "TRUE": "FALSE" ); | 578 | dbg(" IOSPSetBaudRate : %s", bits->IOSPSetBaudRate ? "TRUE": "FALSE"); |
549 | dbg(" TrueEdgeport : %s", bits->TrueEdgeport ? "TRUE": "FALSE" ); | 579 | dbg(" TrueEdgeport : %s", bits->TrueEdgeport ? "TRUE": "FALSE"); |
550 | } | 580 | } |
551 | 581 | ||
552 | return result; | 582 | return result; |
@@ -562,10 +592,10 @@ static int get_epic_descriptor(struct edgeport_serial *ep) | |||
562 | 592 | ||
563 | /***************************************************************************** | 593 | /***************************************************************************** |
564 | * edge_interrupt_callback | 594 | * edge_interrupt_callback |
565 | * this is the callback function for when we have received data on the | 595 | * this is the callback function for when we have received data on the |
566 | * interrupt endpoint. | 596 | * interrupt endpoint. |
567 | *****************************************************************************/ | 597 | *****************************************************************************/ |
568 | static void edge_interrupt_callback (struct urb *urb) | 598 | static void edge_interrupt_callback(struct urb *urb) |
569 | { | 599 | { |
570 | struct edgeport_serial *edge_serial = urb->context; | 600 | struct edgeport_serial *edge_serial = urb->context; |
571 | struct edgeport_port *edge_port; | 601 | struct edgeport_port *edge_port; |
@@ -590,17 +620,17 @@ static void edge_interrupt_callback (struct urb *urb) | |||
590 | case -ESHUTDOWN: | 620 | case -ESHUTDOWN: |
591 | /* this urb is terminated, clean up */ | 621 | /* this urb is terminated, clean up */ |
592 | dbg("%s - urb shutting down with status: %d", | 622 | dbg("%s - urb shutting down with status: %d", |
593 | __func__, status); | 623 | __func__, status); |
594 | return; | 624 | return; |
595 | default: | 625 | default: |
596 | dbg("%s - nonzero urb status received: %d", | 626 | dbg("%s - nonzero urb status received: %d", __func__, status); |
597 | __func__, status); | ||
598 | goto exit; | 627 | goto exit; |
599 | } | 628 | } |
600 | 629 | ||
601 | // process this interrupt-read even if there are no ports open | 630 | /* process this interrupt-read even if there are no ports open */ |
602 | if (length) { | 631 | if (length) { |
603 | usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, __func__, length, data); | 632 | usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, |
633 | __func__, length, data); | ||
604 | 634 | ||
605 | if (length > 1) { | 635 | if (length > 1) { |
606 | bytes_avail = data[0] | (data[1] << 8); | 636 | bytes_avail = data[0] | (data[1] << 8); |
@@ -614,7 +644,8 @@ static void edge_interrupt_callback (struct urb *urb) | |||
614 | dbg("%s - posting a read", __func__); | 644 | dbg("%s - posting a read", __func__); |
615 | edge_serial->read_in_progress = true; | 645 | edge_serial->read_in_progress = true; |
616 | 646 | ||
617 | /* we have pending bytes on the bulk in pipe, send a request */ | 647 | /* we have pending bytes on the |
648 | bulk in pipe, send a request */ | ||
618 | edge_serial->read_urb->dev = edge_serial->serial->dev; | 649 | edge_serial->read_urb->dev = edge_serial->serial->dev; |
619 | result = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC); | 650 | result = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC); |
620 | if (result) { | 651 | if (result) { |
@@ -628,7 +659,8 @@ static void edge_interrupt_callback (struct urb *urb) | |||
628 | /* grab the txcredits for the ports if available */ | 659 | /* grab the txcredits for the ports if available */ |
629 | position = 2; | 660 | position = 2; |
630 | portNumber = 0; | 661 | portNumber = 0; |
631 | while ((position < length) && (portNumber < edge_serial->serial->num_ports)) { | 662 | while ((position < length) && |
663 | (portNumber < edge_serial->serial->num_ports)) { | ||
632 | txCredits = data[position] | (data[position+1] << 8); | 664 | txCredits = data[position] | (data[position+1] << 8); |
633 | if (txCredits) { | 665 | if (txCredits) { |
634 | port = edge_serial->serial->port[portNumber]; | 666 | port = edge_serial->serial->port[portNumber]; |
@@ -637,14 +669,19 @@ static void edge_interrupt_callback (struct urb *urb) | |||
637 | spin_lock(&edge_port->ep_lock); | 669 | spin_lock(&edge_port->ep_lock); |
638 | edge_port->txCredits += txCredits; | 670 | edge_port->txCredits += txCredits; |
639 | spin_unlock(&edge_port->ep_lock); | 671 | spin_unlock(&edge_port->ep_lock); |
640 | dbg("%s - txcredits for port%d = %d", __func__, portNumber, edge_port->txCredits); | 672 | dbg("%s - txcredits for port%d = %d", |
673 | __func__, portNumber, | ||
674 | edge_port->txCredits); | ||
641 | 675 | ||
642 | /* tell the tty driver that something has changed */ | 676 | /* tell the tty driver that something |
677 | has changed */ | ||
643 | if (edge_port->port->port.tty) | 678 | if (edge_port->port->port.tty) |
644 | tty_wakeup(edge_port->port->port.tty); | 679 | tty_wakeup(edge_port->port->port.tty); |
645 | 680 | ||
646 | // Since we have more credit, check if more data can be sent | 681 | /* Since we have more credit, check |
647 | send_more_port_data(edge_serial, edge_port); | 682 | if more data can be sent */ |
683 | send_more_port_data(edge_serial, | ||
684 | edge_port); | ||
648 | } | 685 | } |
649 | } | 686 | } |
650 | position += 2; | 687 | position += 2; |
@@ -653,19 +690,20 @@ static void edge_interrupt_callback (struct urb *urb) | |||
653 | } | 690 | } |
654 | 691 | ||
655 | exit: | 692 | exit: |
656 | result = usb_submit_urb (urb, GFP_ATOMIC); | 693 | result = usb_submit_urb(urb, GFP_ATOMIC); |
657 | if (result) { | 694 | if (result) |
658 | dev_err(&urb->dev->dev, "%s - Error %d submitting control urb\n", __func__, result); | 695 | dev_err(&urb->dev->dev, |
659 | } | 696 | "%s - Error %d submitting control urb\n", |
697 | __func__, result); | ||
660 | } | 698 | } |
661 | 699 | ||
662 | 700 | ||
663 | /***************************************************************************** | 701 | /***************************************************************************** |
664 | * edge_bulk_in_callback | 702 | * edge_bulk_in_callback |
665 | * this is the callback function for when we have received data on the | 703 | * this is the callback function for when we have received data on the |
666 | * bulk in endpoint. | 704 | * bulk in endpoint. |
667 | *****************************************************************************/ | 705 | *****************************************************************************/ |
668 | static void edge_bulk_in_callback (struct urb *urb) | 706 | static void edge_bulk_in_callback(struct urb *urb) |
669 | { | 707 | { |
670 | struct edgeport_serial *edge_serial = urb->context; | 708 | struct edgeport_serial *edge_serial = urb->context; |
671 | unsigned char *data = urb->transfer_buffer; | 709 | unsigned char *data = urb->transfer_buffer; |
@@ -690,16 +728,18 @@ static void edge_bulk_in_callback (struct urb *urb) | |||
690 | 728 | ||
691 | raw_data_length = urb->actual_length; | 729 | raw_data_length = urb->actual_length; |
692 | 730 | ||
693 | usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, __func__, raw_data_length, data); | 731 | usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, |
732 | __func__, raw_data_length, data); | ||
694 | 733 | ||
695 | spin_lock(&edge_serial->es_lock); | 734 | spin_lock(&edge_serial->es_lock); |
696 | 735 | ||
697 | /* decrement our rxBytes available by the number that we just got */ | 736 | /* decrement our rxBytes available by the number that we just got */ |
698 | edge_serial->rxBytesAvail -= raw_data_length; | 737 | edge_serial->rxBytesAvail -= raw_data_length; |
699 | 738 | ||
700 | dbg("%s - Received = %d, rxBytesAvail %d", __func__, raw_data_length, edge_serial->rxBytesAvail); | 739 | dbg("%s - Received = %d, rxBytesAvail %d", __func__, |
740 | raw_data_length, edge_serial->rxBytesAvail); | ||
701 | 741 | ||
702 | process_rcvd_data (edge_serial, data, urb->actual_length); | 742 | process_rcvd_data(edge_serial, data, urb->actual_length); |
703 | 743 | ||
704 | /* check to see if there's any more data for us to read */ | 744 | /* check to see if there's any more data for us to read */ |
705 | if (edge_serial->rxBytesAvail > 0) { | 745 | if (edge_serial->rxBytesAvail > 0) { |
@@ -722,10 +762,10 @@ static void edge_bulk_in_callback (struct urb *urb) | |||
722 | 762 | ||
723 | /***************************************************************************** | 763 | /***************************************************************************** |
724 | * edge_bulk_out_data_callback | 764 | * edge_bulk_out_data_callback |
725 | * this is the callback function for when we have finished sending serial data | 765 | * this is the callback function for when we have finished sending |
726 | * on the bulk out endpoint. | 766 | * serial data on the bulk out endpoint. |
727 | *****************************************************************************/ | 767 | *****************************************************************************/ |
728 | static void edge_bulk_out_data_callback (struct urb *urb) | 768 | static void edge_bulk_out_data_callback(struct urb *urb) |
729 | { | 769 | { |
730 | struct edgeport_port *edge_port = urb->context; | 770 | struct edgeport_port *edge_port = urb->context; |
731 | struct tty_struct *tty; | 771 | struct tty_struct *tty; |
@@ -741,24 +781,26 @@ static void edge_bulk_out_data_callback (struct urb *urb) | |||
741 | tty = edge_port->port->port.tty; | 781 | tty = edge_port->port->port.tty; |
742 | 782 | ||
743 | if (tty && edge_port->open) { | 783 | if (tty && edge_port->open) { |
744 | /* let the tty driver wakeup if it has a special write_wakeup function */ | 784 | /* let the tty driver wakeup if it has a special |
785 | write_wakeup function */ | ||
745 | tty_wakeup(tty); | 786 | tty_wakeup(tty); |
746 | } | 787 | } |
747 | 788 | ||
748 | // Release the Write URB | 789 | /* Release the Write URB */ |
749 | edge_port->write_in_progress = false; | 790 | edge_port->write_in_progress = false; |
750 | 791 | ||
751 | // Check if more data needs to be sent | 792 | /* Check if more data needs to be sent */ |
752 | send_more_port_data((struct edgeport_serial *)(usb_get_serial_data(edge_port->port->serial)), edge_port); | 793 | send_more_port_data((struct edgeport_serial *) |
794 | (usb_get_serial_data(edge_port->port->serial)), edge_port); | ||
753 | } | 795 | } |
754 | 796 | ||
755 | 797 | ||
756 | /***************************************************************************** | 798 | /***************************************************************************** |
757 | * BulkOutCmdCallback | 799 | * BulkOutCmdCallback |
758 | * this is the callback function for when we have finished sending a command | 800 | * this is the callback function for when we have finished sending a |
759 | * on the bulk out endpoint. | 801 | * command on the bulk out endpoint. |
760 | *****************************************************************************/ | 802 | *****************************************************************************/ |
761 | static void edge_bulk_out_cmd_callback (struct urb *urb) | 803 | static void edge_bulk_out_cmd_callback(struct urb *urb) |
762 | { | 804 | { |
763 | struct edgeport_port *edge_port = urb->context; | 805 | struct edgeport_port *edge_port = urb->context; |
764 | struct tty_struct *tty; | 806 | struct tty_struct *tty; |
@@ -767,17 +809,19 @@ static void edge_bulk_out_cmd_callback (struct urb *urb) | |||
767 | dbg("%s", __func__); | 809 | dbg("%s", __func__); |
768 | 810 | ||
769 | atomic_dec(&CmdUrbs); | 811 | atomic_dec(&CmdUrbs); |
770 | dbg("%s - FREE URB %p (outstanding %d)", __func__, urb, atomic_read(&CmdUrbs)); | 812 | dbg("%s - FREE URB %p (outstanding %d)", __func__, |
813 | urb, atomic_read(&CmdUrbs)); | ||
771 | 814 | ||
772 | 815 | ||
773 | /* clean up the transfer buffer */ | 816 | /* clean up the transfer buffer */ |
774 | kfree(urb->transfer_buffer); | 817 | kfree(urb->transfer_buffer); |
775 | 818 | ||
776 | /* Free the command urb */ | 819 | /* Free the command urb */ |
777 | usb_free_urb (urb); | 820 | usb_free_urb(urb); |
778 | 821 | ||
779 | if (status) { | 822 | if (status) { |
780 | dbg("%s - nonzero write bulk status received: %d", __func__, status); | 823 | dbg("%s - nonzero write bulk status received: %d", |
824 | __func__, status); | ||
781 | return; | 825 | return; |
782 | } | 826 | } |
783 | 827 | ||
@@ -805,7 +849,7 @@ static void edge_bulk_out_cmd_callback (struct urb *urb) | |||
805 | * Otherwise we return a negative error number. | 849 | * Otherwise we return a negative error number. |
806 | *****************************************************************************/ | 850 | *****************************************************************************/ |
807 | static int edge_open(struct tty_struct *tty, | 851 | static int edge_open(struct tty_struct *tty, |
808 | struct usb_serial_port *port, struct file * filp) | 852 | struct usb_serial_port *port, struct file *filp) |
809 | { | 853 | { |
810 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 854 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); |
811 | struct usb_serial *serial; | 855 | struct usb_serial *serial; |
@@ -820,51 +864,59 @@ static int edge_open(struct tty_struct *tty, | |||
820 | if (tty) | 864 | if (tty) |
821 | tty->low_latency = low_latency; | 865 | tty->low_latency = low_latency; |
822 | 866 | ||
823 | /* see if we've set up our endpoint info yet (can't set it up in edge_startup | 867 | /* see if we've set up our endpoint info yet (can't set it up |
824 | as the structures were not set up at that time.) */ | 868 | in edge_startup as the structures were not set up at that time.) */ |
825 | serial = port->serial; | 869 | serial = port->serial; |
826 | edge_serial = usb_get_serial_data(serial); | 870 | edge_serial = usb_get_serial_data(serial); |
827 | if (edge_serial == NULL) | 871 | if (edge_serial == NULL) |
828 | return -ENODEV; | 872 | return -ENODEV; |
829 | if (edge_serial->interrupt_in_buffer == NULL) { | 873 | if (edge_serial->interrupt_in_buffer == NULL) { |
830 | struct usb_serial_port *port0 = serial->port[0]; | 874 | struct usb_serial_port *port0 = serial->port[0]; |
831 | 875 | ||
832 | /* not set up yet, so do it now */ | 876 | /* not set up yet, so do it now */ |
833 | edge_serial->interrupt_in_buffer = port0->interrupt_in_buffer; | 877 | edge_serial->interrupt_in_buffer = |
834 | edge_serial->interrupt_in_endpoint = port0->interrupt_in_endpointAddress; | 878 | port0->interrupt_in_buffer; |
879 | edge_serial->interrupt_in_endpoint = | ||
880 | port0->interrupt_in_endpointAddress; | ||
835 | edge_serial->interrupt_read_urb = port0->interrupt_in_urb; | 881 | edge_serial->interrupt_read_urb = port0->interrupt_in_urb; |
836 | edge_serial->bulk_in_buffer = port0->bulk_in_buffer; | 882 | edge_serial->bulk_in_buffer = port0->bulk_in_buffer; |
837 | edge_serial->bulk_in_endpoint = port0->bulk_in_endpointAddress; | 883 | edge_serial->bulk_in_endpoint = |
884 | port0->bulk_in_endpointAddress; | ||
838 | edge_serial->read_urb = port0->read_urb; | 885 | edge_serial->read_urb = port0->read_urb; |
839 | edge_serial->bulk_out_endpoint = port0->bulk_out_endpointAddress; | 886 | edge_serial->bulk_out_endpoint = |
840 | 887 | port0->bulk_out_endpointAddress; | |
888 | |||
841 | /* set up our interrupt urb */ | 889 | /* set up our interrupt urb */ |
842 | usb_fill_int_urb(edge_serial->interrupt_read_urb, | 890 | usb_fill_int_urb(edge_serial->interrupt_read_urb, |
843 | serial->dev, | 891 | serial->dev, |
844 | usb_rcvintpipe(serial->dev, | 892 | usb_rcvintpipe(serial->dev, |
845 | port0->interrupt_in_endpointAddress), | 893 | port0->interrupt_in_endpointAddress), |
846 | port0->interrupt_in_buffer, | 894 | port0->interrupt_in_buffer, |
847 | edge_serial->interrupt_read_urb->transfer_buffer_length, | 895 | edge_serial->interrupt_read_urb->transfer_buffer_length, |
848 | edge_interrupt_callback, edge_serial, | 896 | edge_interrupt_callback, edge_serial, |
849 | edge_serial->interrupt_read_urb->interval); | 897 | edge_serial->interrupt_read_urb->interval); |
850 | 898 | ||
851 | /* set up our bulk in urb */ | 899 | /* set up our bulk in urb */ |
852 | usb_fill_bulk_urb(edge_serial->read_urb, serial->dev, | 900 | usb_fill_bulk_urb(edge_serial->read_urb, serial->dev, |
853 | usb_rcvbulkpipe(serial->dev, | 901 | usb_rcvbulkpipe(serial->dev, |
854 | port0->bulk_in_endpointAddress), | 902 | port0->bulk_in_endpointAddress), |
855 | port0->bulk_in_buffer, | 903 | port0->bulk_in_buffer, |
856 | edge_serial->read_urb->transfer_buffer_length, | 904 | edge_serial->read_urb->transfer_buffer_length, |
857 | edge_bulk_in_callback, edge_serial); | 905 | edge_bulk_in_callback, edge_serial); |
858 | edge_serial->read_in_progress = false; | 906 | edge_serial->read_in_progress = false; |
859 | 907 | ||
860 | /* start interrupt read for this edgeport | 908 | /* start interrupt read for this edgeport |
861 | * this interrupt will continue as long as the edgeport is connected */ | 909 | * this interrupt will continue as long |
862 | response = usb_submit_urb (edge_serial->interrupt_read_urb, GFP_KERNEL); | 910 | * as the edgeport is connected */ |
911 | response = usb_submit_urb(edge_serial->interrupt_read_urb, | ||
912 | GFP_KERNEL); | ||
863 | if (response) { | 913 | if (response) { |
864 | dev_err(&port->dev, "%s - Error %d submitting control urb\n", __func__, response); | 914 | dev_err(&port->dev, |
915 | "%s - Error %d submitting control urb\n", | ||
916 | __func__, response); | ||
865 | } | 917 | } |
866 | } | 918 | } |
867 | 919 | ||
868 | /* initialize our wait queues */ | 920 | /* initialize our wait queues */ |
869 | init_waitqueue_head(&edge_port->wait_open); | 921 | init_waitqueue_head(&edge_port->wait_open); |
870 | init_waitqueue_head(&edge_port->wait_chase); | 922 | init_waitqueue_head(&edge_port->wait_chase); |
@@ -872,26 +924,29 @@ static int edge_open(struct tty_struct *tty, | |||
872 | init_waitqueue_head(&edge_port->wait_command); | 924 | init_waitqueue_head(&edge_port->wait_command); |
873 | 925 | ||
874 | /* initialize our icount structure */ | 926 | /* initialize our icount structure */ |
875 | memset (&(edge_port->icount), 0x00, sizeof(edge_port->icount)); | 927 | memset(&(edge_port->icount), 0x00, sizeof(edge_port->icount)); |
876 | 928 | ||
877 | /* initialize our port settings */ | 929 | /* initialize our port settings */ |
878 | edge_port->txCredits = 0; /* Can't send any data yet */ | 930 | edge_port->txCredits = 0; /* Can't send any data yet */ |
879 | edge_port->shadowMCR = MCR_MASTER_IE; /* Must always set this bit to enable ints! */ | 931 | /* Must always set this bit to enable ints! */ |
932 | edge_port->shadowMCR = MCR_MASTER_IE; | ||
880 | edge_port->chaseResponsePending = false; | 933 | edge_port->chaseResponsePending = false; |
881 | 934 | ||
882 | /* send a open port command */ | 935 | /* send a open port command */ |
883 | edge_port->openPending = true; | 936 | edge_port->openPending = true; |
884 | edge_port->open = false; | 937 | edge_port->open = false; |
885 | response = send_iosp_ext_cmd (edge_port, IOSP_CMD_OPEN_PORT, 0); | 938 | response = send_iosp_ext_cmd(edge_port, IOSP_CMD_OPEN_PORT, 0); |
886 | 939 | ||
887 | if (response < 0) { | 940 | if (response < 0) { |
888 | dev_err(&port->dev, "%s - error sending open port command\n", __func__); | 941 | dev_err(&port->dev, "%s - error sending open port command\n", |
942 | __func__); | ||
889 | edge_port->openPending = false; | 943 | edge_port->openPending = false; |
890 | return -ENODEV; | 944 | return -ENODEV; |
891 | } | 945 | } |
892 | 946 | ||
893 | /* now wait for the port to be completely opened */ | 947 | /* now wait for the port to be completely opened */ |
894 | wait_event_timeout(edge_port->wait_open, !edge_port->openPending, OPEN_TIMEOUT); | 948 | wait_event_timeout(edge_port->wait_open, !edge_port->openPending, |
949 | OPEN_TIMEOUT); | ||
895 | 950 | ||
896 | if (!edge_port->open) { | 951 | if (!edge_port->open) { |
897 | /* open timed out */ | 952 | /* open timed out */ |
@@ -905,25 +960,26 @@ static int edge_open(struct tty_struct *tty, | |||
905 | edge_port->txfifo.tail = 0; | 960 | edge_port->txfifo.tail = 0; |
906 | edge_port->txfifo.count = 0; | 961 | edge_port->txfifo.count = 0; |
907 | edge_port->txfifo.size = edge_port->maxTxCredits; | 962 | edge_port->txfifo.size = edge_port->maxTxCredits; |
908 | edge_port->txfifo.fifo = kmalloc (edge_port->maxTxCredits, GFP_KERNEL); | 963 | edge_port->txfifo.fifo = kmalloc(edge_port->maxTxCredits, GFP_KERNEL); |
909 | 964 | ||
910 | if (!edge_port->txfifo.fifo) { | 965 | if (!edge_port->txfifo.fifo) { |
911 | dbg("%s - no memory", __func__); | 966 | dbg("%s - no memory", __func__); |
912 | edge_close (tty, port, filp); | 967 | edge_close(tty, port, filp); |
913 | return -ENOMEM; | 968 | return -ENOMEM; |
914 | } | 969 | } |
915 | 970 | ||
916 | /* Allocate a URB for the write */ | 971 | /* Allocate a URB for the write */ |
917 | edge_port->write_urb = usb_alloc_urb (0, GFP_KERNEL); | 972 | edge_port->write_urb = usb_alloc_urb(0, GFP_KERNEL); |
918 | edge_port->write_in_progress = false; | 973 | edge_port->write_in_progress = false; |
919 | 974 | ||
920 | if (!edge_port->write_urb) { | 975 | if (!edge_port->write_urb) { |
921 | dbg("%s - no memory", __func__); | 976 | dbg("%s - no memory", __func__); |
922 | edge_close (tty, port, filp); | 977 | edge_close(tty, port, filp); |
923 | return -ENOMEM; | 978 | return -ENOMEM; |
924 | } | 979 | } |
925 | 980 | ||
926 | dbg("%s(%d) - Initialize TX fifo to %d bytes", __func__, port->number, edge_port->maxTxCredits); | 981 | dbg("%s(%d) - Initialize TX fifo to %d bytes", |
982 | __func__, port->number, edge_port->maxTxCredits); | ||
927 | 983 | ||
928 | dbg("%s exited", __func__); | 984 | dbg("%s exited", __func__); |
929 | 985 | ||
@@ -949,27 +1005,28 @@ static void block_until_chase_response(struct edgeport_port *edge_port) | |||
949 | int loop = 10; | 1005 | int loop = 10; |
950 | 1006 | ||
951 | while (1) { | 1007 | while (1) { |
952 | // Save Last credits | 1008 | /* Save Last credits */ |
953 | lastCredits = edge_port->txCredits; | 1009 | lastCredits = edge_port->txCredits; |
954 | 1010 | ||
955 | // Did we get our Chase response | 1011 | /* Did we get our Chase response */ |
956 | if (!edge_port->chaseResponsePending) { | 1012 | if (!edge_port->chaseResponsePending) { |
957 | dbg("%s - Got Chase Response", __func__); | 1013 | dbg("%s - Got Chase Response", __func__); |
958 | 1014 | ||
959 | // did we get all of our credit back? | 1015 | /* did we get all of our credit back? */ |
960 | if (edge_port->txCredits == edge_port->maxTxCredits ) { | 1016 | if (edge_port->txCredits == edge_port->maxTxCredits) { |
961 | dbg("%s - Got all credits", __func__); | 1017 | dbg("%s - Got all credits", __func__); |
962 | return; | 1018 | return; |
963 | } | 1019 | } |
964 | } | 1020 | } |
965 | 1021 | ||
966 | // Block the thread for a while | 1022 | /* Block the thread for a while */ |
967 | prepare_to_wait(&edge_port->wait_chase, &wait, TASK_UNINTERRUPTIBLE); | 1023 | prepare_to_wait(&edge_port->wait_chase, &wait, |
1024 | TASK_UNINTERRUPTIBLE); | ||
968 | schedule_timeout(timeout); | 1025 | schedule_timeout(timeout); |
969 | finish_wait(&edge_port->wait_chase, &wait); | 1026 | finish_wait(&edge_port->wait_chase, &wait); |
970 | 1027 | ||
971 | if (lastCredits == edge_port->txCredits) { | 1028 | if (lastCredits == edge_port->txCredits) { |
972 | // No activity.. count down. | 1029 | /* No activity.. count down. */ |
973 | loop--; | 1030 | loop--; |
974 | if (loop == 0) { | 1031 | if (loop == 0) { |
975 | edge_port->chaseResponsePending = false; | 1032 | edge_port->chaseResponsePending = false; |
@@ -977,8 +1034,9 @@ static void block_until_chase_response(struct edgeport_port *edge_port) | |||
977 | return; | 1034 | return; |
978 | } | 1035 | } |
979 | } else { | 1036 | } else { |
980 | // Reset timeout value back to 10 seconds | 1037 | /* Reset timeout value back to 10 seconds */ |
981 | dbg("%s - Last %d, Current %d", __func__, lastCredits, edge_port->txCredits); | 1038 | dbg("%s - Last %d, Current %d", __func__, |
1039 | lastCredits, edge_port->txCredits); | ||
982 | loop = 10; | 1040 | loop = 10; |
983 | } | 1041 | } |
984 | } | 1042 | } |
@@ -995,7 +1053,7 @@ static void block_until_chase_response(struct edgeport_port *edge_port) | |||
995 | * 3. A timeout of 3 seconds without activity has expired | 1053 | * 3. A timeout of 3 seconds without activity has expired |
996 | * | 1054 | * |
997 | ************************************************************************/ | 1055 | ************************************************************************/ |
998 | static void block_until_tx_empty (struct edgeport_port *edge_port) | 1056 | static void block_until_tx_empty(struct edgeport_port *edge_port) |
999 | { | 1057 | { |
1000 | DEFINE_WAIT(wait); | 1058 | DEFINE_WAIT(wait); |
1001 | struct TxFifo *fifo = &edge_port->txfifo; | 1059 | struct TxFifo *fifo = &edge_port->txfifo; |
@@ -1004,31 +1062,32 @@ static void block_until_tx_empty (struct edgeport_port *edge_port) | |||
1004 | int loop = 30; | 1062 | int loop = 30; |
1005 | 1063 | ||
1006 | while (1) { | 1064 | while (1) { |
1007 | // Save Last count | 1065 | /* Save Last count */ |
1008 | lastCount = fifo->count; | 1066 | lastCount = fifo->count; |
1009 | 1067 | ||
1010 | // Is the Edgeport Buffer empty? | 1068 | /* Is the Edgeport Buffer empty? */ |
1011 | if (lastCount == 0) { | 1069 | if (lastCount == 0) { |
1012 | dbg("%s - TX Buffer Empty", __func__); | 1070 | dbg("%s - TX Buffer Empty", __func__); |
1013 | return; | 1071 | return; |
1014 | } | 1072 | } |
1015 | 1073 | ||
1016 | // Block the thread for a while | 1074 | /* Block the thread for a while */ |
1017 | prepare_to_wait (&edge_port->wait_chase, &wait, TASK_UNINTERRUPTIBLE); | 1075 | prepare_to_wait(&edge_port->wait_chase, &wait, |
1076 | TASK_UNINTERRUPTIBLE); | ||
1018 | schedule_timeout(timeout); | 1077 | schedule_timeout(timeout); |
1019 | finish_wait(&edge_port->wait_chase, &wait); | 1078 | finish_wait(&edge_port->wait_chase, &wait); |
1020 | 1079 | ||
1021 | dbg("%s wait", __func__); | 1080 | dbg("%s wait", __func__); |
1022 | 1081 | ||
1023 | if (lastCount == fifo->count) { | 1082 | if (lastCount == fifo->count) { |
1024 | // No activity.. count down. | 1083 | /* No activity.. count down. */ |
1025 | loop--; | 1084 | loop--; |
1026 | if (loop == 0) { | 1085 | if (loop == 0) { |
1027 | dbg("%s - TIMEOUT", __func__); | 1086 | dbg("%s - TIMEOUT", __func__); |
1028 | return; | 1087 | return; |
1029 | } | 1088 | } |
1030 | } else { | 1089 | } else { |
1031 | // Reset timeout value back to seconds | 1090 | /* Reset timeout value back to seconds */ |
1032 | loop = 30; | 1091 | loop = 30; |
1033 | } | 1092 | } |
1034 | } | 1093 | } |
@@ -1040,20 +1099,20 @@ static void block_until_tx_empty (struct edgeport_port *edge_port) | |||
1040 | * this function is called by the tty driver when a port is closed | 1099 | * this function is called by the tty driver when a port is closed |
1041 | *****************************************************************************/ | 1100 | *****************************************************************************/ |
1042 | static void edge_close(struct tty_struct *tty, | 1101 | static void edge_close(struct tty_struct *tty, |
1043 | struct usb_serial_port *port, struct file * filp) | 1102 | struct usb_serial_port *port, struct file *filp) |
1044 | { | 1103 | { |
1045 | struct edgeport_serial *edge_serial; | 1104 | struct edgeport_serial *edge_serial; |
1046 | struct edgeport_port *edge_port; | 1105 | struct edgeport_port *edge_port; |
1047 | int status; | 1106 | int status; |
1048 | 1107 | ||
1049 | dbg("%s - port %d", __func__, port->number); | 1108 | dbg("%s - port %d", __func__, port->number); |
1050 | 1109 | ||
1051 | edge_serial = usb_get_serial_data(port->serial); | 1110 | edge_serial = usb_get_serial_data(port->serial); |
1052 | edge_port = usb_get_serial_port_data(port); | 1111 | edge_port = usb_get_serial_port_data(port); |
1053 | if ((edge_serial == NULL) || (edge_port == NULL)) | 1112 | if (edge_serial == NULL || edge_port == NULL) |
1054 | return; | 1113 | return; |
1055 | 1114 | ||
1056 | // block until tx is empty | 1115 | /* block until tx is empty */ |
1057 | block_until_tx_empty(edge_port); | 1116 | block_until_tx_empty(edge_port); |
1058 | 1117 | ||
1059 | edge_port->closePending = true; | 1118 | edge_port->closePending = true; |
@@ -1065,13 +1124,12 @@ static void edge_close(struct tty_struct *tty, | |||
1065 | edge_port->chaseResponsePending = true; | 1124 | edge_port->chaseResponsePending = true; |
1066 | 1125 | ||
1067 | dbg("%s - Sending IOSP_CMD_CHASE_PORT", __func__); | 1126 | dbg("%s - Sending IOSP_CMD_CHASE_PORT", __func__); |
1068 | status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CHASE_PORT, 0); | 1127 | status = send_iosp_ext_cmd(edge_port, IOSP_CMD_CHASE_PORT, 0); |
1069 | if (status == 0) { | 1128 | if (status == 0) |
1070 | // block until chase finished | 1129 | /* block until chase finished */ |
1071 | block_until_chase_response(edge_port); | 1130 | block_until_chase_response(edge_port); |
1072 | } else { | 1131 | else |
1073 | edge_port->chaseResponsePending = false; | 1132 | edge_port->chaseResponsePending = false; |
1074 | } | ||
1075 | } | 1133 | } |
1076 | 1134 | ||
1077 | if ((!edge_serial->is_epic) || | 1135 | if ((!edge_serial->is_epic) || |
@@ -1079,10 +1137,10 @@ static void edge_close(struct tty_struct *tty, | |||
1079 | (edge_serial->epic_descriptor.Supports.IOSPClose))) { | 1137 | (edge_serial->epic_descriptor.Supports.IOSPClose))) { |
1080 | /* close the port */ | 1138 | /* close the port */ |
1081 | dbg("%s - Sending IOSP_CMD_CLOSE_PORT", __func__); | 1139 | dbg("%s - Sending IOSP_CMD_CLOSE_PORT", __func__); |
1082 | send_iosp_ext_cmd (edge_port, IOSP_CMD_CLOSE_PORT, 0); | 1140 | send_iosp_ext_cmd(edge_port, IOSP_CMD_CLOSE_PORT, 0); |
1083 | } | 1141 | } |
1084 | 1142 | ||
1085 | //port->close = true; | 1143 | /* port->close = true; */ |
1086 | edge_port->closePending = false; | 1144 | edge_port->closePending = false; |
1087 | edge_port->open = false; | 1145 | edge_port->open = false; |
1088 | edge_port->openPending = false; | 1146 | edge_port->openPending = false; |
@@ -1090,7 +1148,8 @@ static void edge_close(struct tty_struct *tty, | |||
1090 | usb_kill_urb(edge_port->write_urb); | 1148 | usb_kill_urb(edge_port->write_urb); |
1091 | 1149 | ||
1092 | if (edge_port->write_urb) { | 1150 | if (edge_port->write_urb) { |
1093 | /* if this urb had a transfer buffer already (old transfer) free it */ | 1151 | /* if this urb had a transfer buffer already |
1152 | (old transfer) free it */ | ||
1094 | kfree(edge_port->write_urb->transfer_buffer); | 1153 | kfree(edge_port->write_urb->transfer_buffer); |
1095 | usb_free_urb(edge_port->write_urb); | 1154 | usb_free_urb(edge_port->write_urb); |
1096 | edge_port->write_urb = NULL; | 1155 | edge_port->write_urb = NULL; |
@@ -1099,14 +1158,14 @@ static void edge_close(struct tty_struct *tty, | |||
1099 | edge_port->txfifo.fifo = NULL; | 1158 | edge_port->txfifo.fifo = NULL; |
1100 | 1159 | ||
1101 | dbg("%s exited", __func__); | 1160 | dbg("%s exited", __func__); |
1102 | } | 1161 | } |
1103 | 1162 | ||
1104 | /***************************************************************************** | 1163 | /***************************************************************************** |
1105 | * SerialWrite | 1164 | * SerialWrite |
1106 | * this function is called by the tty driver when data should be written to | 1165 | * this function is called by the tty driver when data should be written |
1107 | * the port. | 1166 | * to the port. |
1108 | * If successful, we return the number of bytes written, otherwise we return | 1167 | * If successful, we return the number of bytes written, otherwise we |
1109 | * a negative error number. | 1168 | * return a negative error number. |
1110 | *****************************************************************************/ | 1169 | *****************************************************************************/ |
1111 | static int edge_write(struct tty_struct *tty, struct usb_serial_port *port, | 1170 | static int edge_write(struct tty_struct *tty, struct usb_serial_port *port, |
1112 | const unsigned char *data, int count) | 1171 | const unsigned char *data, int count) |
@@ -1124,66 +1183,76 @@ static int edge_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
1124 | if (edge_port == NULL) | 1183 | if (edge_port == NULL) |
1125 | return -ENODEV; | 1184 | return -ENODEV; |
1126 | 1185 | ||
1127 | // get a pointer to the Tx fifo | 1186 | /* get a pointer to the Tx fifo */ |
1128 | fifo = &edge_port->txfifo; | 1187 | fifo = &edge_port->txfifo; |
1129 | 1188 | ||
1130 | spin_lock_irqsave(&edge_port->ep_lock, flags); | 1189 | spin_lock_irqsave(&edge_port->ep_lock, flags); |
1131 | 1190 | ||
1132 | // calculate number of bytes to put in fifo | 1191 | /* calculate number of bytes to put in fifo */ |
1133 | copySize = min ((unsigned int)count, (edge_port->txCredits - fifo->count)); | 1192 | copySize = min((unsigned int)count, |
1193 | (edge_port->txCredits - fifo->count)); | ||
1134 | 1194 | ||
1135 | dbg("%s(%d) of %d byte(s) Fifo room %d -- will copy %d bytes", __func__, | 1195 | dbg("%s(%d) of %d byte(s) Fifo room %d -- will copy %d bytes", |
1136 | port->number, count, edge_port->txCredits - fifo->count, copySize); | 1196 | __func__, port->number, count, |
1197 | edge_port->txCredits - fifo->count, copySize); | ||
1137 | 1198 | ||
1138 | /* catch writes of 0 bytes which the tty driver likes to give us, and when txCredits is empty */ | 1199 | /* catch writes of 0 bytes which the tty driver likes to give us, |
1200 | and when txCredits is empty */ | ||
1139 | if (copySize == 0) { | 1201 | if (copySize == 0) { |
1140 | dbg("%s - copySize = Zero", __func__); | 1202 | dbg("%s - copySize = Zero", __func__); |
1141 | goto finish_write; | 1203 | goto finish_write; |
1142 | } | 1204 | } |
1143 | 1205 | ||
1144 | // queue the data | 1206 | /* queue the data |
1145 | // since we can never overflow the buffer we do not have to check for full condition | 1207 | * since we can never overflow the buffer we do not have to check for a |
1146 | 1208 | * full condition | |
1147 | // the copy is done is two parts -- first fill to the end of the buffer | 1209 | * |
1148 | // then copy the reset from the start of the buffer | 1210 | * the copy is done is two parts -- first fill to the end of the buffer |
1149 | 1211 | * then copy the reset from the start of the buffer | |
1212 | */ | ||
1150 | bytesleft = fifo->size - fifo->head; | 1213 | bytesleft = fifo->size - fifo->head; |
1151 | firsthalf = min (bytesleft, copySize); | 1214 | firsthalf = min(bytesleft, copySize); |
1152 | dbg("%s - copy %d bytes of %d into fifo ", __func__, firsthalf, bytesleft); | 1215 | dbg("%s - copy %d bytes of %d into fifo ", __func__, |
1216 | firsthalf, bytesleft); | ||
1153 | 1217 | ||
1154 | /* now copy our data */ | 1218 | /* now copy our data */ |
1155 | memcpy(&fifo->fifo[fifo->head], data, firsthalf); | 1219 | memcpy(&fifo->fifo[fifo->head], data, firsthalf); |
1156 | usb_serial_debug_data(debug, &port->dev, __func__, firsthalf, &fifo->fifo[fifo->head]); | 1220 | usb_serial_debug_data(debug, &port->dev, __func__, |
1221 | firsthalf, &fifo->fifo[fifo->head]); | ||
1157 | 1222 | ||
1158 | // update the index and size | 1223 | /* update the index and size */ |
1159 | fifo->head += firsthalf; | 1224 | fifo->head += firsthalf; |
1160 | fifo->count += firsthalf; | 1225 | fifo->count += firsthalf; |
1161 | 1226 | ||
1162 | // wrap the index | 1227 | /* wrap the index */ |
1163 | if (fifo->head == fifo->size) { | 1228 | if (fifo->head == fifo->size) |
1164 | fifo->head = 0; | 1229 | fifo->head = 0; |
1165 | } | ||
1166 | 1230 | ||
1167 | secondhalf = copySize-firsthalf; | 1231 | secondhalf = copySize-firsthalf; |
1168 | 1232 | ||
1169 | if (secondhalf) { | 1233 | if (secondhalf) { |
1170 | dbg("%s - copy rest of data %d", __func__, secondhalf); | 1234 | dbg("%s - copy rest of data %d", __func__, secondhalf); |
1171 | memcpy(&fifo->fifo[fifo->head], &data[firsthalf], secondhalf); | 1235 | memcpy(&fifo->fifo[fifo->head], &data[firsthalf], secondhalf); |
1172 | usb_serial_debug_data(debug, &port->dev, __func__, secondhalf, &fifo->fifo[fifo->head]); | 1236 | usb_serial_debug_data(debug, &port->dev, __func__, |
1173 | // update the index and size | 1237 | secondhalf, &fifo->fifo[fifo->head]); |
1238 | /* update the index and size */ | ||
1174 | fifo->count += secondhalf; | 1239 | fifo->count += secondhalf; |
1175 | fifo->head += secondhalf; | 1240 | fifo->head += secondhalf; |
1176 | // No need to check for wrap since we can not get to end of fifo in this part | 1241 | /* No need to check for wrap since we can not get to end of |
1242 | * the fifo in this part | ||
1243 | */ | ||
1177 | } | 1244 | } |
1178 | 1245 | ||
1179 | finish_write: | 1246 | finish_write: |
1180 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); | 1247 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); |
1181 | 1248 | ||
1182 | send_more_port_data((struct edgeport_serial *)usb_get_serial_data(port->serial), edge_port); | 1249 | send_more_port_data((struct edgeport_serial *) |
1250 | usb_get_serial_data(port->serial), edge_port); | ||
1183 | 1251 | ||
1184 | dbg("%s wrote %d byte(s) TxCredits %d, Fifo %d", __func__, copySize, edge_port->txCredits, fifo->count); | 1252 | dbg("%s wrote %d byte(s) TxCredits %d, Fifo %d", __func__, |
1253 | copySize, edge_port->txCredits, fifo->count); | ||
1185 | 1254 | ||
1186 | return copySize; | 1255 | return copySize; |
1187 | } | 1256 | } |
1188 | 1257 | ||
1189 | 1258 | ||
@@ -1200,7 +1269,8 @@ finish_write: | |||
1200 | * can transmit more. | 1269 | * can transmit more. |
1201 | * | 1270 | * |
1202 | ************************************************************************/ | 1271 | ************************************************************************/ |
1203 | static void send_more_port_data(struct edgeport_serial *edge_serial, struct edgeport_port *edge_port) | 1272 | static void send_more_port_data(struct edgeport_serial *edge_serial, |
1273 | struct edgeport_port *edge_port) | ||
1204 | { | 1274 | { |
1205 | struct TxFifo *fifo = &edge_port->txfifo; | 1275 | struct TxFifo *fifo = &edge_port->txfifo; |
1206 | struct urb *urb; | 1276 | struct urb *urb; |
@@ -1219,67 +1289,78 @@ static void send_more_port_data(struct edgeport_serial *edge_serial, struct edge | |||
1219 | if (edge_port->write_in_progress || | 1289 | if (edge_port->write_in_progress || |
1220 | !edge_port->open || | 1290 | !edge_port->open || |
1221 | (fifo->count == 0)) { | 1291 | (fifo->count == 0)) { |
1222 | dbg("%s(%d) EXIT - fifo %d, PendingWrite = %d", __func__, edge_port->port->number, fifo->count, edge_port->write_in_progress); | 1292 | dbg("%s(%d) EXIT - fifo %d, PendingWrite = %d", |
1293 | __func__, edge_port->port->number, | ||
1294 | fifo->count, edge_port->write_in_progress); | ||
1223 | goto exit_send; | 1295 | goto exit_send; |
1224 | } | 1296 | } |
1225 | 1297 | ||
1226 | // since the amount of data in the fifo will always fit into the | 1298 | /* since the amount of data in the fifo will always fit into the |
1227 | // edgeport buffer we do not need to check the write length | 1299 | * edgeport buffer we do not need to check the write length |
1228 | 1300 | * | |
1229 | // Do we have enough credits for this port to make it worthwhile | 1301 | * Do we have enough credits for this port to make it worthwhile |
1230 | // to bother queueing a write. If it's too small, say a few bytes, | 1302 | * to bother queueing a write. If it's too small, say a few bytes, |
1231 | // it's better to wait for more credits so we can do a larger | 1303 | * it's better to wait for more credits so we can do a larger write. |
1232 | // write. | 1304 | */ |
1233 | if (edge_port->txCredits < EDGE_FW_GET_TX_CREDITS_SEND_THRESHOLD(edge_port->maxTxCredits,EDGE_FW_BULK_MAX_PACKET_SIZE)) { | 1305 | if (edge_port->txCredits < EDGE_FW_GET_TX_CREDITS_SEND_THRESHOLD(edge_port->maxTxCredits, EDGE_FW_BULK_MAX_PACKET_SIZE)) { |
1234 | dbg("%s(%d) Not enough credit - fifo %d TxCredit %d", __func__, edge_port->port->number, fifo->count, edge_port->txCredits ); | 1306 | dbg("%s(%d) Not enough credit - fifo %d TxCredit %d", |
1307 | __func__, edge_port->port->number, fifo->count, | ||
1308 | edge_port->txCredits); | ||
1235 | goto exit_send; | 1309 | goto exit_send; |
1236 | } | 1310 | } |
1237 | 1311 | ||
1238 | // lock this write | 1312 | /* lock this write */ |
1239 | edge_port->write_in_progress = true; | 1313 | edge_port->write_in_progress = true; |
1240 | 1314 | ||
1241 | // get a pointer to the write_urb | 1315 | /* get a pointer to the write_urb */ |
1242 | urb = edge_port->write_urb; | 1316 | urb = edge_port->write_urb; |
1243 | 1317 | ||
1244 | /* make sure transfer buffer is freed */ | 1318 | /* make sure transfer buffer is freed */ |
1245 | kfree(urb->transfer_buffer); | 1319 | kfree(urb->transfer_buffer); |
1246 | urb->transfer_buffer = NULL; | 1320 | urb->transfer_buffer = NULL; |
1247 | 1321 | ||
1248 | /* build the data header for the buffer and port that we are about to send out */ | 1322 | /* build the data header for the buffer and port that we are about |
1323 | to send out */ | ||
1249 | count = fifo->count; | 1324 | count = fifo->count; |
1250 | buffer = kmalloc (count+2, GFP_ATOMIC); | 1325 | buffer = kmalloc(count+2, GFP_ATOMIC); |
1251 | if (buffer == NULL) { | 1326 | if (buffer == NULL) { |
1252 | dev_err(&edge_port->port->dev, "%s - no more kernel memory...\n", __func__); | 1327 | dev_err(&edge_port->port->dev, |
1328 | "%s - no more kernel memory...\n", __func__); | ||
1253 | edge_port->write_in_progress = false; | 1329 | edge_port->write_in_progress = false; |
1254 | goto exit_send; | 1330 | goto exit_send; |
1255 | } | 1331 | } |
1256 | buffer[0] = IOSP_BUILD_DATA_HDR1 (edge_port->port->number - edge_port->port->serial->minor, count); | 1332 | buffer[0] = IOSP_BUILD_DATA_HDR1(edge_port->port->number |
1257 | buffer[1] = IOSP_BUILD_DATA_HDR2 (edge_port->port->number - edge_port->port->serial->minor, count); | 1333 | - edge_port->port->serial->minor, count); |
1334 | buffer[1] = IOSP_BUILD_DATA_HDR2(edge_port->port->number | ||
1335 | - edge_port->port->serial->minor, count); | ||
1258 | 1336 | ||
1259 | /* now copy our data */ | 1337 | /* now copy our data */ |
1260 | bytesleft = fifo->size - fifo->tail; | 1338 | bytesleft = fifo->size - fifo->tail; |
1261 | firsthalf = min (bytesleft, count); | 1339 | firsthalf = min(bytesleft, count); |
1262 | memcpy(&buffer[2], &fifo->fifo[fifo->tail], firsthalf); | 1340 | memcpy(&buffer[2], &fifo->fifo[fifo->tail], firsthalf); |
1263 | fifo->tail += firsthalf; | 1341 | fifo->tail += firsthalf; |
1264 | fifo->count -= firsthalf; | 1342 | fifo->count -= firsthalf; |
1265 | if (fifo->tail == fifo->size) { | 1343 | if (fifo->tail == fifo->size) |
1266 | fifo->tail = 0; | 1344 | fifo->tail = 0; |
1267 | } | ||
1268 | 1345 | ||
1269 | secondhalf = count-firsthalf; | 1346 | secondhalf = count-firsthalf; |
1270 | if (secondhalf) { | 1347 | if (secondhalf) { |
1271 | memcpy(&buffer[2+firsthalf], &fifo->fifo[fifo->tail], secondhalf); | 1348 | memcpy(&buffer[2+firsthalf], &fifo->fifo[fifo->tail], |
1349 | secondhalf); | ||
1272 | fifo->tail += secondhalf; | 1350 | fifo->tail += secondhalf; |
1273 | fifo->count -= secondhalf; | 1351 | fifo->count -= secondhalf; |
1274 | } | 1352 | } |
1275 | 1353 | ||
1276 | if (count) | 1354 | if (count) |
1277 | usb_serial_debug_data(debug, &edge_port->port->dev, __func__, count, &buffer[2]); | 1355 | usb_serial_debug_data(debug, &edge_port->port->dev, |
1356 | __func__, count, &buffer[2]); | ||
1278 | 1357 | ||
1279 | /* fill up the urb with all of our data and submit it */ | 1358 | /* fill up the urb with all of our data and submit it */ |
1280 | usb_fill_bulk_urb (urb, edge_serial->serial->dev, | 1359 | usb_fill_bulk_urb(urb, edge_serial->serial->dev, |
1281 | usb_sndbulkpipe(edge_serial->serial->dev, edge_serial->bulk_out_endpoint), | 1360 | usb_sndbulkpipe(edge_serial->serial->dev, |
1282 | buffer, count+2, edge_bulk_out_data_callback, edge_port); | 1361 | edge_serial->bulk_out_endpoint), |
1362 | buffer, count+2, | ||
1363 | edge_bulk_out_data_callback, edge_port); | ||
1283 | 1364 | ||
1284 | /* decrement the number of credits we have by the number we just sent */ | 1365 | /* decrement the number of credits we have by the number we just sent */ |
1285 | edge_port->txCredits -= count; | 1366 | edge_port->txCredits -= count; |
@@ -1289,14 +1370,17 @@ static void send_more_port_data(struct edgeport_serial *edge_serial, struct edge | |||
1289 | status = usb_submit_urb(urb, GFP_ATOMIC); | 1370 | status = usb_submit_urb(urb, GFP_ATOMIC); |
1290 | if (status) { | 1371 | if (status) { |
1291 | /* something went wrong */ | 1372 | /* something went wrong */ |
1292 | dev_err(&edge_port->port->dev, "%s - usb_submit_urb(write bulk) failed, status = %d, data lost\n", __func__, status); | 1373 | dev_err(&edge_port->port->dev, |
1374 | "%s - usb_submit_urb(write bulk) failed, status = %d, data lost\n", | ||
1375 | __func__, status); | ||
1293 | edge_port->write_in_progress = false; | 1376 | edge_port->write_in_progress = false; |
1294 | 1377 | ||
1295 | /* revert the credits as something bad happened. */ | 1378 | /* revert the credits as something bad happened. */ |
1296 | edge_port->txCredits += count; | 1379 | edge_port->txCredits += count; |
1297 | edge_port->icount.tx -= count; | 1380 | edge_port->icount.tx -= count; |
1298 | } | 1381 | } |
1299 | dbg("%s wrote %d byte(s) TxCredit %d, Fifo %d", __func__, count, edge_port->txCredits, fifo->count); | 1382 | dbg("%s wrote %d byte(s) TxCredit %d, Fifo %d", |
1383 | __func__, count, edge_port->txCredits, fifo->count); | ||
1300 | 1384 | ||
1301 | exit_send: | 1385 | exit_send: |
1302 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); | 1386 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); |
@@ -1305,11 +1389,10 @@ exit_send: | |||
1305 | 1389 | ||
1306 | /***************************************************************************** | 1390 | /***************************************************************************** |
1307 | * edge_write_room | 1391 | * edge_write_room |
1308 | * this function is called by the tty driver when it wants to know how many | 1392 | * this function is called by the tty driver when it wants to know how |
1309 | * bytes of data we can accept for a specific port. | 1393 | * many bytes of data we can accept for a specific port. If successful, |
1310 | * If successful, we return the amount of room that we have for this port | 1394 | * we return the amount of room that we have for this port (the txCredits) |
1311 | * (the txCredits), | 1395 | * otherwise we return a negative error number. |
1312 | * Otherwise we return a negative error number. | ||
1313 | *****************************************************************************/ | 1396 | *****************************************************************************/ |
1314 | static int edge_write_room(struct tty_struct *tty) | 1397 | static int edge_write_room(struct tty_struct *tty) |
1315 | { | 1398 | { |
@@ -1332,7 +1415,7 @@ static int edge_write_room(struct tty_struct *tty) | |||
1332 | return -EINVAL; | 1415 | return -EINVAL; |
1333 | } | 1416 | } |
1334 | 1417 | ||
1335 | // total of both buffers is still txCredit | 1418 | /* total of both buffers is still txCredit */ |
1336 | spin_lock_irqsave(&edge_port->ep_lock, flags); | 1419 | spin_lock_irqsave(&edge_port->ep_lock, flags); |
1337 | room = edge_port->txCredits - edge_port->txfifo.count; | 1420 | room = edge_port->txCredits - edge_port->txfifo.count; |
1338 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); | 1421 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); |
@@ -1344,11 +1427,11 @@ static int edge_write_room(struct tty_struct *tty) | |||
1344 | 1427 | ||
1345 | /***************************************************************************** | 1428 | /***************************************************************************** |
1346 | * edge_chars_in_buffer | 1429 | * edge_chars_in_buffer |
1347 | * this function is called by the tty driver when it wants to know how many | 1430 | * this function is called by the tty driver when it wants to know how |
1348 | * bytes of data we currently have outstanding in the port (data that has | 1431 | * many bytes of data we currently have outstanding in the port (data that |
1349 | * been written, but hasn't made it out the port yet) | 1432 | * has been written, but hasn't made it out the port yet) |
1350 | * If successful, we return the number of bytes left to be written in the | 1433 | * If successful, we return the number of bytes left to be written in the |
1351 | * system, | 1434 | * system, |
1352 | * Otherwise we return a negative error number. | 1435 | * Otherwise we return a negative error number. |
1353 | *****************************************************************************/ | 1436 | *****************************************************************************/ |
1354 | static int edge_chars_in_buffer(struct tty_struct *tty) | 1437 | static int edge_chars_in_buffer(struct tty_struct *tty) |
@@ -1371,10 +1454,12 @@ static int edge_chars_in_buffer(struct tty_struct *tty) | |||
1371 | } | 1454 | } |
1372 | 1455 | ||
1373 | spin_lock_irqsave(&edge_port->ep_lock, flags); | 1456 | spin_lock_irqsave(&edge_port->ep_lock, flags); |
1374 | num_chars = edge_port->maxTxCredits - edge_port->txCredits + edge_port->txfifo.count; | 1457 | num_chars = edge_port->maxTxCredits - edge_port->txCredits + |
1458 | edge_port->txfifo.count; | ||
1375 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); | 1459 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); |
1376 | if (num_chars) { | 1460 | if (num_chars) { |
1377 | dbg("%s(port %d) - returns %d", __func__, port->number, num_chars); | 1461 | dbg("%s(port %d) - returns %d", __func__, |
1462 | port->number, num_chars); | ||
1378 | } | 1463 | } |
1379 | 1464 | ||
1380 | return num_chars; | 1465 | return num_chars; |
@@ -1405,19 +1490,18 @@ static void edge_throttle(struct tty_struct *tty) | |||
1405 | /* if we are implementing XON/XOFF, send the stop character */ | 1490 | /* if we are implementing XON/XOFF, send the stop character */ |
1406 | if (I_IXOFF(tty)) { | 1491 | if (I_IXOFF(tty)) { |
1407 | unsigned char stop_char = STOP_CHAR(tty); | 1492 | unsigned char stop_char = STOP_CHAR(tty); |
1408 | status = edge_write (tty, port, &stop_char, 1); | 1493 | status = edge_write(tty, port, &stop_char, 1); |
1409 | if (status <= 0) { | 1494 | if (status <= 0) |
1410 | return; | 1495 | return; |
1411 | } | ||
1412 | } | 1496 | } |
1413 | 1497 | ||
1414 | /* if we are implementing RTS/CTS, toggle that line */ | 1498 | /* if we are implementing RTS/CTS, toggle that line */ |
1415 | if (tty->termios->c_cflag & CRTSCTS) { | 1499 | if (tty->termios->c_cflag & CRTSCTS) { |
1416 | edge_port->shadowMCR &= ~MCR_RTS; | 1500 | edge_port->shadowMCR &= ~MCR_RTS; |
1417 | status = send_cmd_write_uart_register(edge_port, MCR, edge_port->shadowMCR); | 1501 | status = send_cmd_write_uart_register(edge_port, MCR, |
1418 | if (status != 0) { | 1502 | edge_port->shadowMCR); |
1503 | if (status != 0) | ||
1419 | return; | 1504 | return; |
1420 | } | ||
1421 | } | 1505 | } |
1422 | 1506 | ||
1423 | return; | 1507 | return; |
@@ -1426,8 +1510,8 @@ static void edge_throttle(struct tty_struct *tty) | |||
1426 | 1510 | ||
1427 | /***************************************************************************** | 1511 | /***************************************************************************** |
1428 | * edge_unthrottle | 1512 | * edge_unthrottle |
1429 | * this function is called by the tty driver when it wants to resume the data | 1513 | * this function is called by the tty driver when it wants to resume the |
1430 | * being read from the port (called after SerialThrottle is called) | 1514 | * data being read from the port (called after SerialThrottle is called) |
1431 | *****************************************************************************/ | 1515 | *****************************************************************************/ |
1432 | static void edge_unthrottle(struct tty_struct *tty) | 1516 | static void edge_unthrottle(struct tty_struct *tty) |
1433 | { | 1517 | { |
@@ -1455,14 +1539,16 @@ static void edge_unthrottle(struct tty_struct *tty) | |||
1455 | /* if we are implementing RTS/CTS, toggle that line */ | 1539 | /* if we are implementing RTS/CTS, toggle that line */ |
1456 | if (tty->termios->c_cflag & CRTSCTS) { | 1540 | if (tty->termios->c_cflag & CRTSCTS) { |
1457 | edge_port->shadowMCR |= MCR_RTS; | 1541 | edge_port->shadowMCR |= MCR_RTS; |
1458 | send_cmd_write_uart_register(edge_port, MCR, edge_port->shadowMCR); | 1542 | send_cmd_write_uart_register(edge_port, MCR, |
1543 | edge_port->shadowMCR); | ||
1459 | } | 1544 | } |
1460 | } | 1545 | } |
1461 | 1546 | ||
1462 | 1547 | ||
1463 | /***************************************************************************** | 1548 | /***************************************************************************** |
1464 | * SerialSetTermios | 1549 | * SerialSetTermios |
1465 | * this function is called by the tty driver when it wants to change the termios structure | 1550 | * this function is called by the tty driver when it wants to change |
1551 | * the termios structure | ||
1466 | *****************************************************************************/ | 1552 | *****************************************************************************/ |
1467 | static void edge_set_termios(struct tty_struct *tty, | 1553 | static void edge_set_termios(struct tty_struct *tty, |
1468 | struct usb_serial_port *port, struct ktermios *old_termios) | 1554 | struct usb_serial_port *port, struct ktermios *old_termios) |
@@ -1499,9 +1585,10 @@ static void edge_set_termios(struct tty_struct *tty, | |||
1499 | * release the bus after transmitting. This must be done when | 1585 | * release the bus after transmitting. This must be done when |
1500 | * the transmit shift register is empty, not be done when the | 1586 | * the transmit shift register is empty, not be done when the |
1501 | * transmit holding register is empty. This functionality | 1587 | * transmit holding register is empty. This functionality |
1502 | * allows an RS485 driver to be written in user space. | 1588 | * allows an RS485 driver to be written in user space. |
1503 | *****************************************************************************/ | 1589 | *****************************************************************************/ |
1504 | static int get_lsr_info(struct edgeport_port *edge_port, unsigned int __user *value) | 1590 | static int get_lsr_info(struct edgeport_port *edge_port, |
1591 | unsigned int __user *value) | ||
1505 | { | 1592 | { |
1506 | unsigned int result = 0; | 1593 | unsigned int result = 0; |
1507 | unsigned long flags; | 1594 | unsigned long flags; |
@@ -1519,7 +1606,8 @@ static int get_lsr_info(struct edgeport_port *edge_port, unsigned int __user *va | |||
1519 | return 0; | 1606 | return 0; |
1520 | } | 1607 | } |
1521 | 1608 | ||
1522 | static int edge_tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear) | 1609 | static int edge_tiocmset(struct tty_struct *tty, struct file *file, |
1610 | unsigned int set, unsigned int clear) | ||
1523 | { | 1611 | { |
1524 | struct usb_serial_port *port = tty->driver_data; | 1612 | struct usb_serial_port *port = tty->driver_data; |
1525 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 1613 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); |
@@ -1574,7 +1662,8 @@ static int edge_tiocmget(struct tty_struct *tty, struct file *file) | |||
1574 | return result; | 1662 | return result; |
1575 | } | 1663 | } |
1576 | 1664 | ||
1577 | static int get_serial_info(struct edgeport_port *edge_port, struct serial_struct __user *retinfo) | 1665 | static int get_serial_info(struct edgeport_port *edge_port, |
1666 | struct serial_struct __user *retinfo) | ||
1578 | { | 1667 | { |
1579 | struct serial_struct tmp; | 1668 | struct serial_struct tmp; |
1580 | 1669 | ||
@@ -1617,60 +1706,61 @@ static int edge_ioctl(struct tty_struct *tty, struct file *file, | |||
1617 | dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd); | 1706 | dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd); |
1618 | 1707 | ||
1619 | switch (cmd) { | 1708 | switch (cmd) { |
1620 | case TIOCSERGETLSR: | 1709 | case TIOCSERGETLSR: |
1621 | dbg("%s (%d) TIOCSERGETLSR", __func__, port->number); | 1710 | dbg("%s (%d) TIOCSERGETLSR", __func__, port->number); |
1622 | return get_lsr_info(edge_port, (unsigned int __user *) arg); | 1711 | return get_lsr_info(edge_port, (unsigned int __user *) arg); |
1623 | 1712 | ||
1624 | case TIOCGSERIAL: | 1713 | case TIOCGSERIAL: |
1625 | dbg("%s (%d) TIOCGSERIAL", __func__, port->number); | 1714 | dbg("%s (%d) TIOCGSERIAL", __func__, port->number); |
1626 | return get_serial_info(edge_port, (struct serial_struct __user *) arg); | 1715 | return get_serial_info(edge_port, (struct serial_struct __user *) arg); |
1627 | 1716 | ||
1628 | case TIOCMIWAIT: | 1717 | case TIOCMIWAIT: |
1629 | dbg("%s (%d) TIOCMIWAIT", __func__, port->number); | 1718 | dbg("%s (%d) TIOCMIWAIT", __func__, port->number); |
1630 | cprev = edge_port->icount; | 1719 | cprev = edge_port->icount; |
1631 | while (1) { | 1720 | while (1) { |
1632 | prepare_to_wait(&edge_port->delta_msr_wait, &wait, TASK_INTERRUPTIBLE); | 1721 | prepare_to_wait(&edge_port->delta_msr_wait, |
1633 | schedule(); | 1722 | &wait, TASK_INTERRUPTIBLE); |
1634 | finish_wait(&edge_port->delta_msr_wait, &wait); | 1723 | schedule(); |
1635 | /* see if a signal did it */ | 1724 | finish_wait(&edge_port->delta_msr_wait, &wait); |
1636 | if (signal_pending(current)) | 1725 | /* see if a signal did it */ |
1637 | return -ERESTARTSYS; | 1726 | if (signal_pending(current)) |
1638 | cnow = edge_port->icount; | 1727 | return -ERESTARTSYS; |
1639 | if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && | 1728 | cnow = edge_port->icount; |
1640 | cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) | 1729 | if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && |
1641 | return -EIO; /* no change => error */ | 1730 | cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) |
1642 | if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || | 1731 | return -EIO; /* no change => error */ |
1643 | ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || | 1732 | if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || |
1644 | ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || | 1733 | ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || |
1645 | ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) { | 1734 | ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || |
1646 | return 0; | 1735 | ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) { |
1647 | } | 1736 | return 0; |
1648 | cprev = cnow; | ||
1649 | } | 1737 | } |
1650 | /* NOTREACHED */ | 1738 | cprev = cnow; |
1651 | break; | 1739 | } |
1740 | /* NOTREACHED */ | ||
1741 | break; | ||
1652 | 1742 | ||
1653 | case TIOCGICOUNT: | 1743 | case TIOCGICOUNT: |
1654 | cnow = edge_port->icount; | 1744 | cnow = edge_port->icount; |
1655 | memset(&icount, 0, sizeof(icount)); | 1745 | memset(&icount, 0, sizeof(icount)); |
1656 | icount.cts = cnow.cts; | 1746 | icount.cts = cnow.cts; |
1657 | icount.dsr = cnow.dsr; | 1747 | icount.dsr = cnow.dsr; |
1658 | icount.rng = cnow.rng; | 1748 | icount.rng = cnow.rng; |
1659 | icount.dcd = cnow.dcd; | 1749 | icount.dcd = cnow.dcd; |
1660 | icount.rx = cnow.rx; | 1750 | icount.rx = cnow.rx; |
1661 | icount.tx = cnow.tx; | 1751 | icount.tx = cnow.tx; |
1662 | icount.frame = cnow.frame; | 1752 | icount.frame = cnow.frame; |
1663 | icount.overrun = cnow.overrun; | 1753 | icount.overrun = cnow.overrun; |
1664 | icount.parity = cnow.parity; | 1754 | icount.parity = cnow.parity; |
1665 | icount.brk = cnow.brk; | 1755 | icount.brk = cnow.brk; |
1666 | icount.buf_overrun = cnow.buf_overrun; | 1756 | icount.buf_overrun = cnow.buf_overrun; |
1667 | 1757 | ||
1668 | dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__, port->number, icount.rx, icount.tx ); | 1758 | dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", |
1669 | if (copy_to_user((void __user *)arg, &icount, sizeof(icount))) | 1759 | __func__, port->number, icount.rx, icount.tx); |
1670 | return -EFAULT; | 1760 | if (copy_to_user((void __user *)arg, &icount, sizeof(icount))) |
1671 | return 0; | 1761 | return -EFAULT; |
1762 | return 0; | ||
1672 | } | 1763 | } |
1673 | |||
1674 | return -ENOIOCTLCMD; | 1764 | return -ENOIOCTLCMD; |
1675 | } | 1765 | } |
1676 | 1766 | ||
@@ -1679,7 +1769,7 @@ static int edge_ioctl(struct tty_struct *tty, struct file *file, | |||
1679 | * SerialBreak | 1769 | * SerialBreak |
1680 | * this function sends a break to the port | 1770 | * this function sends a break to the port |
1681 | *****************************************************************************/ | 1771 | *****************************************************************************/ |
1682 | static void edge_break (struct tty_struct *tty, int break_state) | 1772 | static void edge_break(struct tty_struct *tty, int break_state) |
1683 | { | 1773 | { |
1684 | struct usb_serial_port *port = tty->driver_data; | 1774 | struct usb_serial_port *port = tty->driver_data; |
1685 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 1775 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); |
@@ -1693,9 +1783,9 @@ static void edge_break (struct tty_struct *tty, int break_state) | |||
1693 | edge_port->chaseResponsePending = true; | 1783 | edge_port->chaseResponsePending = true; |
1694 | 1784 | ||
1695 | dbg("%s - Sending IOSP_CMD_CHASE_PORT", __func__); | 1785 | dbg("%s - Sending IOSP_CMD_CHASE_PORT", __func__); |
1696 | status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CHASE_PORT, 0); | 1786 | status = send_iosp_ext_cmd(edge_port, IOSP_CMD_CHASE_PORT, 0); |
1697 | if (status == 0) { | 1787 | if (status == 0) { |
1698 | // block until chase finished | 1788 | /* block until chase finished */ |
1699 | block_until_chase_response(edge_port); | 1789 | block_until_chase_response(edge_port); |
1700 | } else { | 1790 | } else { |
1701 | edge_port->chaseResponsePending = false; | 1791 | edge_port->chaseResponsePending = false; |
@@ -1707,14 +1797,16 @@ static void edge_break (struct tty_struct *tty, int break_state) | |||
1707 | (edge_serial->epic_descriptor.Supports.IOSPSetClrBreak))) { | 1797 | (edge_serial->epic_descriptor.Supports.IOSPSetClrBreak))) { |
1708 | if (break_state == -1) { | 1798 | if (break_state == -1) { |
1709 | dbg("%s - Sending IOSP_CMD_SET_BREAK", __func__); | 1799 | dbg("%s - Sending IOSP_CMD_SET_BREAK", __func__); |
1710 | status = send_iosp_ext_cmd (edge_port, IOSP_CMD_SET_BREAK, 0); | 1800 | status = send_iosp_ext_cmd(edge_port, |
1801 | IOSP_CMD_SET_BREAK, 0); | ||
1711 | } else { | 1802 | } else { |
1712 | dbg("%s - Sending IOSP_CMD_CLEAR_BREAK", __func__); | 1803 | dbg("%s - Sending IOSP_CMD_CLEAR_BREAK", __func__); |
1713 | status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CLEAR_BREAK, 0); | 1804 | status = send_iosp_ext_cmd(edge_port, |
1714 | } | 1805 | IOSP_CMD_CLEAR_BREAK, 0); |
1715 | if (status) { | ||
1716 | dbg("%s - error sending break set/clear command.", __func__); | ||
1717 | } | 1806 | } |
1807 | if (status) | ||
1808 | dbg("%s - error sending break set/clear command.", | ||
1809 | __func__); | ||
1718 | } | 1810 | } |
1719 | 1811 | ||
1720 | return; | 1812 | return; |
@@ -1725,7 +1817,8 @@ static void edge_break (struct tty_struct *tty, int break_state) | |||
1725 | * process_rcvd_data | 1817 | * process_rcvd_data |
1726 | * this function handles the data received on the bulk in pipe. | 1818 | * this function handles the data received on the bulk in pipe. |
1727 | *****************************************************************************/ | 1819 | *****************************************************************************/ |
1728 | static void process_rcvd_data (struct edgeport_serial *edge_serial, unsigned char * buffer, __u16 bufferLength) | 1820 | static void process_rcvd_data(struct edgeport_serial *edge_serial, |
1821 | unsigned char *buffer, __u16 bufferLength) | ||
1729 | { | 1822 | { |
1730 | struct usb_serial_port *port; | 1823 | struct usb_serial_port *port; |
1731 | struct edgeport_port *edge_port; | 1824 | struct edgeport_port *edge_port; |
@@ -1746,105 +1839,123 @@ static void process_rcvd_data (struct edgeport_serial *edge_serial, unsigned cha | |||
1746 | lastBufferLength = bufferLength; | 1839 | lastBufferLength = bufferLength; |
1747 | 1840 | ||
1748 | switch (edge_serial->rxState) { | 1841 | switch (edge_serial->rxState) { |
1749 | case EXPECT_HDR1: | 1842 | case EXPECT_HDR1: |
1750 | edge_serial->rxHeader1 = *buffer; | 1843 | edge_serial->rxHeader1 = *buffer; |
1751 | ++buffer; | 1844 | ++buffer; |
1752 | --bufferLength; | 1845 | --bufferLength; |
1753 | 1846 | ||
1754 | if (bufferLength == 0) { | 1847 | if (bufferLength == 0) { |
1755 | edge_serial->rxState = EXPECT_HDR2; | 1848 | edge_serial->rxState = EXPECT_HDR2; |
1849 | break; | ||
1850 | } | ||
1851 | /* otherwise, drop on through */ | ||
1852 | case EXPECT_HDR2: | ||
1853 | edge_serial->rxHeader2 = *buffer; | ||
1854 | ++buffer; | ||
1855 | --bufferLength; | ||
1856 | |||
1857 | dbg("%s - Hdr1=%02X Hdr2=%02X", __func__, | ||
1858 | edge_serial->rxHeader1, edge_serial->rxHeader2); | ||
1859 | /* Process depending on whether this header is | ||
1860 | * data or status */ | ||
1861 | |||
1862 | if (IS_CMD_STAT_HDR(edge_serial->rxHeader1)) { | ||
1863 | /* Decode this status header and go to | ||
1864 | * EXPECT_HDR1 (if we can process the status | ||
1865 | * with only 2 bytes), or go to EXPECT_HDR3 to | ||
1866 | * get the third byte. */ | ||
1867 | edge_serial->rxPort = | ||
1868 | IOSP_GET_HDR_PORT(edge_serial->rxHeader1); | ||
1869 | edge_serial->rxStatusCode = | ||
1870 | IOSP_GET_STATUS_CODE( | ||
1871 | edge_serial->rxHeader1); | ||
1872 | |||
1873 | if (!IOSP_STATUS_IS_2BYTE( | ||
1874 | edge_serial->rxStatusCode)) { | ||
1875 | /* This status needs additional bytes. | ||
1876 | * Save what we have and then wait for | ||
1877 | * more data. | ||
1878 | */ | ||
1879 | edge_serial->rxStatusParam | ||
1880 | = edge_serial->rxHeader2; | ||
1881 | edge_serial->rxState = EXPECT_HDR3; | ||
1756 | break; | 1882 | break; |
1757 | } | 1883 | } |
1758 | /* otherwise, drop on through */ | 1884 | /* We have all the header bytes, process the |
1759 | 1885 | status now */ | |
1760 | case EXPECT_HDR2: | 1886 | process_rcvd_status(edge_serial, |
1761 | edge_serial->rxHeader2 = *buffer; | 1887 | edge_serial->rxHeader2, 0); |
1762 | ++buffer; | 1888 | edge_serial->rxState = EXPECT_HDR1; |
1763 | --bufferLength; | 1889 | break; |
1764 | 1890 | } else { | |
1765 | dbg("%s - Hdr1=%02X Hdr2=%02X", __func__, edge_serial->rxHeader1, edge_serial->rxHeader2); | 1891 | edge_serial->rxPort = |
1766 | 1892 | IOSP_GET_HDR_PORT(edge_serial->rxHeader1); | |
1767 | // Process depending on whether this header is | 1893 | edge_serial->rxBytesRemaining = |
1768 | // data or status | 1894 | IOSP_GET_HDR_DATA_LEN( |
1769 | 1895 | edge_serial->rxHeader1, | |
1770 | if (IS_CMD_STAT_HDR(edge_serial->rxHeader1)) { | 1896 | edge_serial->rxHeader2); |
1771 | // Decode this status header and goto EXPECT_HDR1 (if we | 1897 | dbg("%s - Data for Port %u Len %u", |
1772 | // can process the status with only 2 bytes), or goto | 1898 | __func__, |
1773 | // EXPECT_HDR3 to get the third byte. | 1899 | edge_serial->rxPort, |
1774 | 1900 | edge_serial->rxBytesRemaining); | |
1775 | edge_serial->rxPort = IOSP_GET_HDR_PORT(edge_serial->rxHeader1); | 1901 | |
1776 | edge_serial->rxStatusCode = IOSP_GET_STATUS_CODE(edge_serial->rxHeader1); | 1902 | /* ASSERT(DevExt->RxPort < DevExt->NumPorts); |
1777 | 1903 | * ASSERT(DevExt->RxBytesRemaining < | |
1778 | if (!IOSP_STATUS_IS_2BYTE(edge_serial->rxStatusCode)) { | 1904 | * IOSP_MAX_DATA_LENGTH); |
1779 | // This status needs additional bytes. Save what we have | 1905 | */ |
1780 | // and then wait for more data. | ||
1781 | edge_serial->rxStatusParam = edge_serial->rxHeader2; | ||
1782 | |||
1783 | edge_serial->rxState = EXPECT_HDR3; | ||
1784 | break; | ||
1785 | } | ||
1786 | 1906 | ||
1787 | // We have all the header bytes, process the status now | 1907 | if (bufferLength == 0) { |
1788 | process_rcvd_status (edge_serial, edge_serial->rxHeader2, 0); | 1908 | edge_serial->rxState = EXPECT_DATA; |
1789 | edge_serial->rxState = EXPECT_HDR1; | ||
1790 | break; | 1909 | break; |
1791 | } else { | ||
1792 | edge_serial->rxPort = IOSP_GET_HDR_PORT(edge_serial->rxHeader1); | ||
1793 | edge_serial->rxBytesRemaining = IOSP_GET_HDR_DATA_LEN(edge_serial->rxHeader1, edge_serial->rxHeader2); | ||
1794 | |||
1795 | dbg("%s - Data for Port %u Len %u", __func__, edge_serial->rxPort, edge_serial->rxBytesRemaining); | ||
1796 | |||
1797 | //ASSERT( DevExt->RxPort < DevExt->NumPorts ); | ||
1798 | //ASSERT( DevExt->RxBytesRemaining < IOSP_MAX_DATA_LENGTH ); | ||
1799 | |||
1800 | if (bufferLength == 0 ) { | ||
1801 | edge_serial->rxState = EXPECT_DATA; | ||
1802 | break; | ||
1803 | } | ||
1804 | // Else, drop through | ||
1805 | } | 1910 | } |
1911 | /* Else, drop through */ | ||
1912 | } | ||
1913 | case EXPECT_DATA: /* Expect data */ | ||
1914 | if (bufferLength < edge_serial->rxBytesRemaining) { | ||
1915 | rxLen = bufferLength; | ||
1916 | /* Expect data to start next buffer */ | ||
1917 | edge_serial->rxState = EXPECT_DATA; | ||
1918 | } else { | ||
1919 | /* BufLen >= RxBytesRemaining */ | ||
1920 | rxLen = edge_serial->rxBytesRemaining; | ||
1921 | /* Start another header next time */ | ||
1922 | edge_serial->rxState = EXPECT_HDR1; | ||
1923 | } | ||
1806 | 1924 | ||
1807 | case EXPECT_DATA: // Expect data | 1925 | bufferLength -= rxLen; |
1808 | 1926 | edge_serial->rxBytesRemaining -= rxLen; | |
1809 | if (bufferLength < edge_serial->rxBytesRemaining) { | ||
1810 | rxLen = bufferLength; | ||
1811 | edge_serial->rxState = EXPECT_DATA; // Expect data to start next buffer | ||
1812 | } else { | ||
1813 | // BufLen >= RxBytesRemaining | ||
1814 | rxLen = edge_serial->rxBytesRemaining; | ||
1815 | edge_serial->rxState = EXPECT_HDR1; // Start another header next time | ||
1816 | } | ||
1817 | 1927 | ||
1818 | bufferLength -= rxLen; | 1928 | /* spit this data back into the tty driver if this |
1819 | edge_serial->rxBytesRemaining -= rxLen; | 1929 | port is open */ |
1820 | 1930 | if (rxLen) { | |
1821 | /* spit this data back into the tty driver if this port is open */ | 1931 | port = edge_serial->serial->port[ |
1822 | if (rxLen) { | 1932 | edge_serial->rxPort]; |
1823 | port = edge_serial->serial->port[edge_serial->rxPort]; | 1933 | edge_port = usb_get_serial_port_data(port); |
1824 | edge_port = usb_get_serial_port_data(port); | 1934 | if (edge_port->open) { |
1825 | if (edge_port->open) { | 1935 | tty = edge_port->port->port.tty; |
1826 | tty = edge_port->port->port.tty; | 1936 | if (tty) { |
1827 | if (tty) { | 1937 | dbg("%s - Sending %d bytes to TTY for port %d", |
1828 | dbg("%s - Sending %d bytes to TTY for port %d", __func__, rxLen, edge_serial->rxPort); | 1938 | __func__, rxLen, edge_serial->rxPort); |
1829 | edge_tty_recv(&edge_serial->serial->dev->dev, tty, buffer, rxLen); | 1939 | edge_tty_recv(&edge_serial->serial->dev->dev, tty, buffer, rxLen); |
1830 | } | ||
1831 | edge_port->icount.rx += rxLen; | ||
1832 | } | 1940 | } |
1833 | buffer += rxLen; | 1941 | edge_port->icount.rx += rxLen; |
1834 | } | 1942 | } |
1943 | buffer += rxLen; | ||
1944 | } | ||
1945 | break; | ||
1835 | 1946 | ||
1836 | break; | 1947 | case EXPECT_HDR3: /* Expect 3rd byte of status header */ |
1837 | 1948 | edge_serial->rxHeader3 = *buffer; | |
1838 | case EXPECT_HDR3: // Expect 3rd byte of status header | 1949 | ++buffer; |
1839 | edge_serial->rxHeader3 = *buffer; | 1950 | --bufferLength; |
1840 | ++buffer; | 1951 | |
1841 | --bufferLength; | 1952 | /* We have all the header bytes, process the |
1842 | 1953 | status now */ | |
1843 | // We have all the header bytes, process the status now | 1954 | process_rcvd_status(edge_serial, |
1844 | process_rcvd_status (edge_serial, edge_serial->rxStatusParam, edge_serial->rxHeader3); | 1955 | edge_serial->rxStatusParam, |
1845 | edge_serial->rxState = EXPECT_HDR1; | 1956 | edge_serial->rxHeader3); |
1846 | break; | 1957 | edge_serial->rxState = EXPECT_HDR1; |
1847 | 1958 | break; | |
1848 | } | 1959 | } |
1849 | } | 1960 | } |
1850 | } | 1961 | } |
@@ -1852,9 +1963,11 @@ static void process_rcvd_data (struct edgeport_serial *edge_serial, unsigned cha | |||
1852 | 1963 | ||
1853 | /***************************************************************************** | 1964 | /***************************************************************************** |
1854 | * process_rcvd_status | 1965 | * process_rcvd_status |
1855 | * this function handles the any status messages received on the bulk in pipe. | 1966 | * this function handles the any status messages received on the |
1967 | * bulk in pipe. | ||
1856 | *****************************************************************************/ | 1968 | *****************************************************************************/ |
1857 | static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2, __u8 byte3) | 1969 | static void process_rcvd_status(struct edgeport_serial *edge_serial, |
1970 | __u8 byte2, __u8 byte3) | ||
1858 | { | 1971 | { |
1859 | struct usb_serial_port *port; | 1972 | struct usb_serial_port *port; |
1860 | struct edgeport_port *edge_port; | 1973 | struct edgeport_port *edge_port; |
@@ -1864,7 +1977,9 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2 | |||
1864 | port = edge_serial->serial->port[edge_serial->rxPort]; | 1977 | port = edge_serial->serial->port[edge_serial->rxPort]; |
1865 | edge_port = usb_get_serial_port_data(port); | 1978 | edge_port = usb_get_serial_port_data(port); |
1866 | if (edge_port == NULL) { | 1979 | if (edge_port == NULL) { |
1867 | dev_err(&edge_serial->serial->dev->dev, "%s - edge_port == NULL for port %d\n", __func__, edge_serial->rxPort); | 1980 | dev_err(&edge_serial->serial->dev->dev, |
1981 | "%s - edge_port == NULL for port %d\n", | ||
1982 | __func__, edge_serial->rxPort); | ||
1868 | return; | 1983 | return; |
1869 | } | 1984 | } |
1870 | 1985 | ||
@@ -1872,22 +1987,28 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2 | |||
1872 | 1987 | ||
1873 | if (code == IOSP_EXT_STATUS) { | 1988 | if (code == IOSP_EXT_STATUS) { |
1874 | switch (byte2) { | 1989 | switch (byte2) { |
1875 | case IOSP_EXT_STATUS_CHASE_RSP: | 1990 | case IOSP_EXT_STATUS_CHASE_RSP: |
1876 | // we want to do EXT status regardless of port open/closed | 1991 | /* we want to do EXT status regardless of port |
1877 | dbg("%s - Port %u EXT CHASE_RSP Data = %02x", __func__, edge_serial->rxPort, byte3 ); | 1992 | * open/closed */ |
1878 | // Currently, the only EXT_STATUS is Chase, so process here instead of one more call | 1993 | dbg("%s - Port %u EXT CHASE_RSP Data = %02x", |
1879 | // to one more subroutine. If/when more EXT_STATUS, there'll be more work to do. | 1994 | __func__, edge_serial->rxPort, byte3); |
1880 | // Also, we currently clear flag and close the port regardless of content of above's Byte3. | 1995 | /* Currently, the only EXT_STATUS is Chase, so process |
1881 | // We could choose to do something else when Byte3 says Timeout on Chase from Edgeport, | 1996 | * here instead of one more call to one more subroutine |
1882 | // like wait longer in block_until_chase_response, but for now we don't. | 1997 | * If/when more EXT_STATUS, there'll be more work to do |
1883 | edge_port->chaseResponsePending = false; | 1998 | * Also, we currently clear flag and close the port |
1884 | wake_up (&edge_port->wait_chase); | 1999 | * regardless of content of above's Byte3. |
1885 | return; | 2000 | * We could choose to do something else when Byte3 says |
2001 | * Timeout on Chase from Edgeport, like wait longer in | ||
2002 | * block_until_chase_response, but for now we don't. | ||
2003 | */ | ||
2004 | edge_port->chaseResponsePending = false; | ||
2005 | wake_up(&edge_port->wait_chase); | ||
2006 | return; | ||
1886 | 2007 | ||
1887 | case IOSP_EXT_STATUS_RX_CHECK_RSP: | 2008 | case IOSP_EXT_STATUS_RX_CHECK_RSP: |
1888 | dbg("%s ========== Port %u CHECK_RSP Sequence = %02x =============\n", __func__, edge_serial->rxPort, byte3 ); | 2009 | dbg("%s ========== Port %u CHECK_RSP Sequence = %02x =============\n", __func__, edge_serial->rxPort, byte3); |
1889 | //Port->RxCheckRsp = true; | 2010 | /* Port->RxCheckRsp = true; */ |
1890 | return; | 2011 | return; |
1891 | } | 2012 | } |
1892 | } | 2013 | } |
1893 | 2014 | ||
@@ -1895,12 +2016,14 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2 | |||
1895 | edge_port->txCredits = GET_TX_BUFFER_SIZE(byte3); | 2016 | edge_port->txCredits = GET_TX_BUFFER_SIZE(byte3); |
1896 | edge_port->maxTxCredits = edge_port->txCredits; | 2017 | edge_port->maxTxCredits = edge_port->txCredits; |
1897 | dbg("%s - Port %u Open Response Inital MSR = %02x TxBufferSize = %d", __func__, edge_serial->rxPort, byte2, edge_port->txCredits); | 2018 | dbg("%s - Port %u Open Response Inital MSR = %02x TxBufferSize = %d", __func__, edge_serial->rxPort, byte2, edge_port->txCredits); |
1898 | handle_new_msr (edge_port, byte2); | 2019 | handle_new_msr(edge_port, byte2); |
1899 | 2020 | ||
1900 | /* send the current line settings to the port so we are in sync with any further termios calls */ | 2021 | /* send the current line settings to the port so we are |
2022 | in sync with any further termios calls */ | ||
1901 | /* FIXME: locking on tty */ | 2023 | /* FIXME: locking on tty */ |
1902 | if (edge_port->port->port.tty) | 2024 | if (edge_port->port->port.tty) |
1903 | change_port_settings(edge_port->port->port.tty, edge_port, edge_port->port->port.tty->termios); | 2025 | change_port_settings(edge_port->port->port.tty, |
2026 | edge_port, edge_port->port->port.tty->termios); | ||
1904 | 2027 | ||
1905 | /* we have completed the open */ | 2028 | /* we have completed the open */ |
1906 | edge_port->openPending = false; | 2029 | edge_port->openPending = false; |
@@ -1909,45 +2032,49 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2 | |||
1909 | return; | 2032 | return; |
1910 | } | 2033 | } |
1911 | 2034 | ||
1912 | // If port is closed, silently discard all rcvd status. We can | 2035 | /* If port is closed, silently discard all rcvd status. We can |
1913 | // have cases where buffered status is received AFTER the close | 2036 | * have cases where buffered status is received AFTER the close |
1914 | // port command is sent to the Edgeport. | 2037 | * port command is sent to the Edgeport. |
1915 | if (!edge_port->open || edge_port->closePending) { | 2038 | */ |
2039 | if (!edge_port->open || edge_port->closePending) | ||
1916 | return; | 2040 | return; |
1917 | } | ||
1918 | 2041 | ||
1919 | switch (code) { | 2042 | switch (code) { |
1920 | // Not currently sent by Edgeport | 2043 | /* Not currently sent by Edgeport */ |
1921 | case IOSP_STATUS_LSR: | 2044 | case IOSP_STATUS_LSR: |
1922 | dbg("%s - Port %u LSR Status = %02x", __func__, edge_serial->rxPort, byte2); | 2045 | dbg("%s - Port %u LSR Status = %02x", |
1923 | handle_new_lsr(edge_port, false, byte2, 0); | 2046 | __func__, edge_serial->rxPort, byte2); |
1924 | break; | 2047 | handle_new_lsr(edge_port, false, byte2, 0); |
2048 | break; | ||
1925 | 2049 | ||
1926 | case IOSP_STATUS_LSR_DATA: | 2050 | case IOSP_STATUS_LSR_DATA: |
1927 | dbg("%s - Port %u LSR Status = %02x, Data = %02x", __func__, edge_serial->rxPort, byte2, byte3); | 2051 | dbg("%s - Port %u LSR Status = %02x, Data = %02x", |
1928 | // byte2 is LSR Register | 2052 | __func__, edge_serial->rxPort, byte2, byte3); |
1929 | // byte3 is broken data byte | 2053 | /* byte2 is LSR Register */ |
1930 | handle_new_lsr(edge_port, true, byte2, byte3); | 2054 | /* byte3 is broken data byte */ |
1931 | break; | 2055 | handle_new_lsr(edge_port, true, byte2, byte3); |
1932 | // | 2056 | break; |
1933 | // case IOSP_EXT_4_STATUS: | 2057 | /* |
1934 | // dbg("%s - Port %u LSR Status = %02x Data = %02x", __func__, edge_serial->rxPort, byte2, byte3); | 2058 | * case IOSP_EXT_4_STATUS: |
1935 | // break; | 2059 | * dbg("%s - Port %u LSR Status = %02x Data = %02x", |
1936 | // | 2060 | * __func__, edge_serial->rxPort, byte2, byte3); |
1937 | case IOSP_STATUS_MSR: | 2061 | * break; |
1938 | dbg("%s - Port %u MSR Status = %02x", __func__, edge_serial->rxPort, byte2); | 2062 | */ |
1939 | 2063 | case IOSP_STATUS_MSR: | |
1940 | // Process this new modem status and generate appropriate | 2064 | dbg("%s - Port %u MSR Status = %02x", |
1941 | // events, etc, based on the new status. This routine | 2065 | __func__, edge_serial->rxPort, byte2); |
1942 | // also saves the MSR in Port->ShadowMsr. | 2066 | /* |
1943 | handle_new_msr(edge_port, byte2); | 2067 | * Process this new modem status and generate appropriate |
1944 | break; | 2068 | * events, etc, based on the new status. This routine |
2069 | * also saves the MSR in Port->ShadowMsr. | ||
2070 | */ | ||
2071 | handle_new_msr(edge_port, byte2); | ||
2072 | break; | ||
1945 | 2073 | ||
1946 | default: | 2074 | default: |
1947 | dbg("%s - Unrecognized IOSP status code %u\n", __func__, code); | 2075 | dbg("%s - Unrecognized IOSP status code %u\n", __func__, code); |
1948 | break; | 2076 | break; |
1949 | } | 2077 | } |
1950 | |||
1951 | return; | 2078 | return; |
1952 | } | 2079 | } |
1953 | 2080 | ||
@@ -1956,7 +2083,8 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2 | |||
1956 | * edge_tty_recv | 2083 | * edge_tty_recv |
1957 | * this function passes data on to the tty flip buffer | 2084 | * this function passes data on to the tty flip buffer |
1958 | *****************************************************************************/ | 2085 | *****************************************************************************/ |
1959 | static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned char *data, int length) | 2086 | static void edge_tty_recv(struct device *dev, struct tty_struct *tty, |
2087 | unsigned char *data, int length) | ||
1960 | { | 2088 | { |
1961 | int cnt; | 2089 | int cnt; |
1962 | 2090 | ||
@@ -1965,7 +2093,7 @@ static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned c | |||
1965 | if (cnt < length) { | 2093 | if (cnt < length) { |
1966 | dev_err(dev, "%s - dropping data, %d bytes lost\n", | 2094 | dev_err(dev, "%s - dropping data, %d bytes lost\n", |
1967 | __func__, length - cnt); | 2095 | __func__, length - cnt); |
1968 | if(cnt == 0) | 2096 | if (cnt == 0) |
1969 | break; | 2097 | break; |
1970 | } | 2098 | } |
1971 | tty_insert_flip_string(tty, data, cnt); | 2099 | tty_insert_flip_string(tty, data, cnt); |
@@ -1987,22 +2115,19 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 newMsr) | |||
1987 | 2115 | ||
1988 | dbg("%s %02x", __func__, newMsr); | 2116 | dbg("%s %02x", __func__, newMsr); |
1989 | 2117 | ||
1990 | if (newMsr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR | EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) { | 2118 | if (newMsr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR | |
2119 | EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) { | ||
1991 | icount = &edge_port->icount; | 2120 | icount = &edge_port->icount; |
1992 | 2121 | ||
1993 | /* update input line counters */ | 2122 | /* update input line counters */ |
1994 | if (newMsr & EDGEPORT_MSR_DELTA_CTS) { | 2123 | if (newMsr & EDGEPORT_MSR_DELTA_CTS) |
1995 | icount->cts++; | 2124 | icount->cts++; |
1996 | } | 2125 | if (newMsr & EDGEPORT_MSR_DELTA_DSR) |
1997 | if (newMsr & EDGEPORT_MSR_DELTA_DSR) { | ||
1998 | icount->dsr++; | 2126 | icount->dsr++; |
1999 | } | 2127 | if (newMsr & EDGEPORT_MSR_DELTA_CD) |
2000 | if (newMsr & EDGEPORT_MSR_DELTA_CD) { | ||
2001 | icount->dcd++; | 2128 | icount->dcd++; |
2002 | } | 2129 | if (newMsr & EDGEPORT_MSR_DELTA_RI) |
2003 | if (newMsr & EDGEPORT_MSR_DELTA_RI) { | ||
2004 | icount->rng++; | 2130 | icount->rng++; |
2005 | } | ||
2006 | wake_up_interruptible(&edge_port->delta_msr_wait); | 2131 | wake_up_interruptible(&edge_port->delta_msr_wait); |
2007 | } | 2132 | } |
2008 | 2133 | ||
@@ -2017,42 +2142,41 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 newMsr) | |||
2017 | * handle_new_lsr | 2142 | * handle_new_lsr |
2018 | * this function handles any change to the lsr register for a port. | 2143 | * this function handles any change to the lsr register for a port. |
2019 | *****************************************************************************/ | 2144 | *****************************************************************************/ |
2020 | static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData, __u8 lsr, __u8 data) | 2145 | static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData, |
2146 | __u8 lsr, __u8 data) | ||
2021 | { | 2147 | { |
2022 | __u8 newLsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR | LSR_FRM_ERR | LSR_BREAK)); | 2148 | __u8 newLsr = (__u8) (lsr & (__u8) |
2023 | struct async_icount *icount; | 2149 | (LSR_OVER_ERR | LSR_PAR_ERR | LSR_FRM_ERR | LSR_BREAK)); |
2150 | struct async_icount *icount; | ||
2024 | 2151 | ||
2025 | dbg("%s - %02x", __func__, newLsr); | 2152 | dbg("%s - %02x", __func__, newLsr); |
2026 | 2153 | ||
2027 | edge_port->shadowLSR = lsr; | 2154 | edge_port->shadowLSR = lsr; |
2028 | 2155 | ||
2029 | if (newLsr & LSR_BREAK) { | 2156 | if (newLsr & LSR_BREAK) { |
2030 | // | 2157 | /* |
2031 | // Parity and Framing errors only count if they | 2158 | * Parity and Framing errors only count if they |
2032 | // occur exclusive of a break being | 2159 | * occur exclusive of a break being |
2033 | // received. | 2160 | * received. |
2034 | // | 2161 | */ |
2035 | newLsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK); | 2162 | newLsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK); |
2036 | } | 2163 | } |
2037 | 2164 | ||
2038 | /* Place LSR data byte into Rx buffer */ | 2165 | /* Place LSR data byte into Rx buffer */ |
2039 | if (lsrData && edge_port->port->port.tty) | 2166 | if (lsrData && edge_port->port->port.tty) |
2040 | edge_tty_recv(&edge_port->port->dev, edge_port->port->port.tty, &data, 1); | 2167 | edge_tty_recv(&edge_port->port->dev, |
2168 | edge_port->port->port.tty, &data, 1); | ||
2041 | 2169 | ||
2042 | /* update input line counters */ | 2170 | /* update input line counters */ |
2043 | icount = &edge_port->icount; | 2171 | icount = &edge_port->icount; |
2044 | if (newLsr & LSR_BREAK) { | 2172 | if (newLsr & LSR_BREAK) |
2045 | icount->brk++; | 2173 | icount->brk++; |
2046 | } | 2174 | if (newLsr & LSR_OVER_ERR) |
2047 | if (newLsr & LSR_OVER_ERR) { | ||
2048 | icount->overrun++; | 2175 | icount->overrun++; |
2049 | } | 2176 | if (newLsr & LSR_PAR_ERR) |
2050 | if (newLsr & LSR_PAR_ERR) { | ||
2051 | icount->parity++; | 2177 | icount->parity++; |
2052 | } | 2178 | if (newLsr & LSR_FRM_ERR) |
2053 | if (newLsr & LSR_FRM_ERR) { | ||
2054 | icount->frame++; | 2179 | icount->frame++; |
2055 | } | ||
2056 | 2180 | ||
2057 | return; | 2181 | return; |
2058 | } | 2182 | } |
@@ -2060,12 +2184,13 @@ static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData, __u8 l | |||
2060 | 2184 | ||
2061 | /**************************************************************************** | 2185 | /**************************************************************************** |
2062 | * sram_write | 2186 | * sram_write |
2063 | * writes a number of bytes to the Edgeport device's sram starting at the | 2187 | * writes a number of bytes to the Edgeport device's sram starting at the |
2064 | * given address. | 2188 | * given address. |
2065 | * If successful returns the number of bytes written, otherwise it returns | 2189 | * If successful returns the number of bytes written, otherwise it returns |
2066 | * a negative error number of the problem. | 2190 | * a negative error number of the problem. |
2067 | ****************************************************************************/ | 2191 | ****************************************************************************/ |
2068 | static int sram_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, const __u8 *data) | 2192 | static int sram_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, |
2193 | __u16 length, const __u8 *data) | ||
2069 | { | 2194 | { |
2070 | int result; | 2195 | int result; |
2071 | __u16 current_length; | 2196 | __u16 current_length; |
@@ -2073,32 +2198,37 @@ static int sram_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, __u1 | |||
2073 | 2198 | ||
2074 | dbg("%s - %x, %x, %d", __func__, extAddr, addr, length); | 2199 | dbg("%s - %x, %x, %d", __func__, extAddr, addr, length); |
2075 | 2200 | ||
2076 | transfer_buffer = kmalloc (64, GFP_KERNEL); | 2201 | transfer_buffer = kmalloc(64, GFP_KERNEL); |
2077 | if (!transfer_buffer) { | 2202 | if (!transfer_buffer) { |
2078 | dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", __func__, 64); | 2203 | dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", |
2204 | __func__, 64); | ||
2079 | return -ENOMEM; | 2205 | return -ENOMEM; |
2080 | } | 2206 | } |
2081 | 2207 | ||
2082 | /* need to split these writes up into 64 byte chunks */ | 2208 | /* need to split these writes up into 64 byte chunks */ |
2083 | result = 0; | 2209 | result = 0; |
2084 | while (length > 0) { | 2210 | while (length > 0) { |
2085 | if (length > 64) { | 2211 | if (length > 64) |
2086 | current_length = 64; | 2212 | current_length = 64; |
2087 | } else { | 2213 | else |
2088 | current_length = length; | 2214 | current_length = length; |
2089 | } | 2215 | |
2090 | // dbg("%s - writing %x, %x, %d", __func__, extAddr, addr, current_length); | 2216 | /* dbg("%s - writing %x, %x, %d", __func__, |
2091 | memcpy (transfer_buffer, data, current_length); | 2217 | extAddr, addr, current_length); */ |
2092 | result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), USB_REQUEST_ION_WRITE_RAM, | 2218 | memcpy(transfer_buffer, data, current_length); |
2093 | 0x40, addr, extAddr, transfer_buffer, current_length, 300); | 2219 | result = usb_control_msg(serial->dev, |
2220 | usb_sndctrlpipe(serial->dev, 0), | ||
2221 | USB_REQUEST_ION_WRITE_RAM, | ||
2222 | 0x40, addr, extAddr, transfer_buffer, | ||
2223 | current_length, 300); | ||
2094 | if (result < 0) | 2224 | if (result < 0) |
2095 | break; | 2225 | break; |
2096 | length -= current_length; | 2226 | length -= current_length; |
2097 | addr += current_length; | 2227 | addr += current_length; |
2098 | data += current_length; | 2228 | data += current_length; |
2099 | } | 2229 | } |
2100 | 2230 | ||
2101 | kfree (transfer_buffer); | 2231 | kfree(transfer_buffer); |
2102 | return result; | 2232 | return result; |
2103 | } | 2233 | } |
2104 | 2234 | ||
@@ -2110,40 +2240,45 @@ static int sram_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, __u1 | |||
2110 | * If successful returns the number of bytes written, otherwise it returns | 2240 | * If successful returns the number of bytes written, otherwise it returns |
2111 | * a negative error number of the problem. | 2241 | * a negative error number of the problem. |
2112 | ****************************************************************************/ | 2242 | ****************************************************************************/ |
2113 | static int rom_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, const __u8 *data) | 2243 | static int rom_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, |
2244 | __u16 length, const __u8 *data) | ||
2114 | { | 2245 | { |
2115 | int result; | 2246 | int result; |
2116 | __u16 current_length; | 2247 | __u16 current_length; |
2117 | unsigned char *transfer_buffer; | 2248 | unsigned char *transfer_buffer; |
2118 | 2249 | ||
2119 | // dbg("%s - %x, %x, %d", __func__, extAddr, addr, length); | 2250 | /* dbg("%s - %x, %x, %d", __func__, extAddr, addr, length); */ |
2120 | 2251 | ||
2121 | transfer_buffer = kmalloc (64, GFP_KERNEL); | 2252 | transfer_buffer = kmalloc(64, GFP_KERNEL); |
2122 | if (!transfer_buffer) { | 2253 | if (!transfer_buffer) { |
2123 | dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", __func__, 64); | 2254 | dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", |
2255 | __func__, 64); | ||
2124 | return -ENOMEM; | 2256 | return -ENOMEM; |
2125 | } | 2257 | } |
2126 | 2258 | ||
2127 | /* need to split these writes up into 64 byte chunks */ | 2259 | /* need to split these writes up into 64 byte chunks */ |
2128 | result = 0; | 2260 | result = 0; |
2129 | while (length > 0) { | 2261 | while (length > 0) { |
2130 | if (length > 64) { | 2262 | if (length > 64) |
2131 | current_length = 64; | 2263 | current_length = 64; |
2132 | } else { | 2264 | else |
2133 | current_length = length; | 2265 | current_length = length; |
2134 | } | 2266 | /* dbg("%s - writing %x, %x, %d", __func__, |
2135 | // dbg("%s - writing %x, %x, %d", __func__, extAddr, addr, current_length); | 2267 | extAddr, addr, current_length); */ |
2136 | memcpy (transfer_buffer, data, current_length); | 2268 | memcpy(transfer_buffer, data, current_length); |
2137 | result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), USB_REQUEST_ION_WRITE_ROM, | 2269 | result = usb_control_msg(serial->dev, |
2138 | 0x40, addr, extAddr, transfer_buffer, current_length, 300); | 2270 | usb_sndctrlpipe(serial->dev, 0), |
2271 | USB_REQUEST_ION_WRITE_ROM, 0x40, | ||
2272 | addr, extAddr, | ||
2273 | transfer_buffer, current_length, 300); | ||
2139 | if (result < 0) | 2274 | if (result < 0) |
2140 | break; | 2275 | break; |
2141 | length -= current_length; | 2276 | length -= current_length; |
2142 | addr += current_length; | 2277 | addr += current_length; |
2143 | data += current_length; | 2278 | data += current_length; |
2144 | } | 2279 | } |
2145 | 2280 | ||
2146 | kfree (transfer_buffer); | 2281 | kfree(transfer_buffer); |
2147 | return result; | 2282 | return result; |
2148 | } | 2283 | } |
2149 | 2284 | ||
@@ -2155,7 +2290,8 @@ static int rom_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 | |||
2155 | * If successful returns the number of bytes read, otherwise it returns | 2290 | * If successful returns the number of bytes read, otherwise it returns |
2156 | * a negative error number of the problem. | 2291 | * a negative error number of the problem. |
2157 | ****************************************************************************/ | 2292 | ****************************************************************************/ |
2158 | static int rom_read (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 length, __u8 *data) | 2293 | static int rom_read(struct usb_serial *serial, __u16 extAddr, |
2294 | __u16 addr, __u16 length, __u8 *data) | ||
2159 | { | 2295 | { |
2160 | int result; | 2296 | int result; |
2161 | __u16 current_length; | 2297 | __u16 current_length; |
@@ -2163,32 +2299,36 @@ static int rom_read (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 | |||
2163 | 2299 | ||
2164 | dbg("%s - %x, %x, %d", __func__, extAddr, addr, length); | 2300 | dbg("%s - %x, %x, %d", __func__, extAddr, addr, length); |
2165 | 2301 | ||
2166 | transfer_buffer = kmalloc (64, GFP_KERNEL); | 2302 | transfer_buffer = kmalloc(64, GFP_KERNEL); |
2167 | if (!transfer_buffer) { | 2303 | if (!transfer_buffer) { |
2168 | dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", __func__, 64); | 2304 | dev_err(&serial->dev->dev, |
2305 | "%s - kmalloc(%d) failed.\n", __func__, 64); | ||
2169 | return -ENOMEM; | 2306 | return -ENOMEM; |
2170 | } | 2307 | } |
2171 | 2308 | ||
2172 | /* need to split these reads up into 64 byte chunks */ | 2309 | /* need to split these reads up into 64 byte chunks */ |
2173 | result = 0; | 2310 | result = 0; |
2174 | while (length > 0) { | 2311 | while (length > 0) { |
2175 | if (length > 64) { | 2312 | if (length > 64) |
2176 | current_length = 64; | 2313 | current_length = 64; |
2177 | } else { | 2314 | else |
2178 | current_length = length; | 2315 | current_length = length; |
2179 | } | 2316 | /* dbg("%s - %x, %x, %d", __func__, |
2180 | // dbg("%s - %x, %x, %d", __func__, extAddr, addr, current_length); | 2317 | extAddr, addr, current_length); */ |
2181 | result = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0), USB_REQUEST_ION_READ_ROM, | 2318 | result = usb_control_msg(serial->dev, |
2182 | 0xC0, addr, extAddr, transfer_buffer, current_length, 300); | 2319 | usb_rcvctrlpipe(serial->dev, 0), |
2320 | USB_REQUEST_ION_READ_ROM, | ||
2321 | 0xC0, addr, extAddr, transfer_buffer, | ||
2322 | current_length, 300); | ||
2183 | if (result < 0) | 2323 | if (result < 0) |
2184 | break; | 2324 | break; |
2185 | memcpy (data, transfer_buffer, current_length); | 2325 | memcpy(data, transfer_buffer, current_length); |
2186 | length -= current_length; | 2326 | length -= current_length; |
2187 | addr += current_length; | 2327 | addr += current_length; |
2188 | data += current_length; | 2328 | data += current_length; |
2189 | } | 2329 | } |
2190 | 2330 | ||
2191 | kfree (transfer_buffer); | 2331 | kfree(transfer_buffer); |
2192 | return result; | 2332 | return result; |
2193 | } | 2333 | } |
2194 | 2334 | ||
@@ -2197,7 +2337,8 @@ static int rom_read (struct usb_serial *serial, __u16 extAddr, __u16 addr, __u16 | |||
2197 | * send_iosp_ext_cmd | 2337 | * send_iosp_ext_cmd |
2198 | * Is used to send a IOSP message to the Edgeport device | 2338 | * Is used to send a IOSP message to the Edgeport device |
2199 | ****************************************************************************/ | 2339 | ****************************************************************************/ |
2200 | static int send_iosp_ext_cmd (struct edgeport_port *edge_port, __u8 command, __u8 param) | 2340 | static int send_iosp_ext_cmd(struct edgeport_port *edge_port, |
2341 | __u8 command, __u8 param) | ||
2201 | { | 2342 | { |
2202 | unsigned char *buffer; | 2343 | unsigned char *buffer; |
2203 | unsigned char *currentCommand; | 2344 | unsigned char *currentCommand; |
@@ -2206,19 +2347,20 @@ static int send_iosp_ext_cmd (struct edgeport_port *edge_port, __u8 command, __u | |||
2206 | 2347 | ||
2207 | dbg("%s - %d, %d", __func__, command, param); | 2348 | dbg("%s - %d, %d", __func__, command, param); |
2208 | 2349 | ||
2209 | buffer = kmalloc (10, GFP_ATOMIC); | 2350 | buffer = kmalloc(10, GFP_ATOMIC); |
2210 | if (!buffer) { | 2351 | if (!buffer) { |
2211 | dev_err(&edge_port->port->dev, "%s - kmalloc(%d) failed.\n", __func__, 10); | 2352 | dev_err(&edge_port->port->dev, |
2353 | "%s - kmalloc(%d) failed.\n", __func__, 10); | ||
2212 | return -ENOMEM; | 2354 | return -ENOMEM; |
2213 | } | 2355 | } |
2214 | 2356 | ||
2215 | currentCommand = buffer; | 2357 | currentCommand = buffer; |
2216 | 2358 | ||
2217 | MAKE_CMD_EXT_CMD (¤tCommand, &length, | 2359 | MAKE_CMD_EXT_CMD(¤tCommand, &length, |
2218 | edge_port->port->number - edge_port->port->serial->minor, | 2360 | edge_port->port->number - edge_port->port->serial->minor, |
2219 | command, param); | 2361 | command, param); |
2220 | 2362 | ||
2221 | status = write_cmd_usb (edge_port, buffer, length); | 2363 | status = write_cmd_usb(edge_port, buffer, length); |
2222 | if (status) { | 2364 | if (status) { |
2223 | /* something bad happened, let's free up the memory */ | 2365 | /* something bad happened, let's free up the memory */ |
2224 | kfree(buffer); | 2366 | kfree(buffer); |
@@ -2232,43 +2374,50 @@ static int send_iosp_ext_cmd (struct edgeport_port *edge_port, __u8 command, __u | |||
2232 | * write_cmd_usb | 2374 | * write_cmd_usb |
2233 | * this function writes the given buffer out to the bulk write endpoint. | 2375 | * this function writes the given buffer out to the bulk write endpoint. |
2234 | *****************************************************************************/ | 2376 | *****************************************************************************/ |
2235 | static int write_cmd_usb (struct edgeport_port *edge_port, unsigned char *buffer, int length) | 2377 | static int write_cmd_usb(struct edgeport_port *edge_port, |
2378 | unsigned char *buffer, int length) | ||
2236 | { | 2379 | { |
2237 | struct edgeport_serial *edge_serial = usb_get_serial_data(edge_port->port->serial); | 2380 | struct edgeport_serial *edge_serial = |
2381 | usb_get_serial_data(edge_port->port->serial); | ||
2238 | int status = 0; | 2382 | int status = 0; |
2239 | struct urb *urb; | 2383 | struct urb *urb; |
2240 | int timeout; | 2384 | int timeout; |
2241 | 2385 | ||
2242 | usb_serial_debug_data(debug, &edge_port->port->dev, __func__, length, buffer); | 2386 | usb_serial_debug_data(debug, &edge_port->port->dev, |
2387 | __func__, length, buffer); | ||
2243 | 2388 | ||
2244 | /* Allocate our next urb */ | 2389 | /* Allocate our next urb */ |
2245 | urb = usb_alloc_urb (0, GFP_ATOMIC); | 2390 | urb = usb_alloc_urb(0, GFP_ATOMIC); |
2246 | if (!urb) | 2391 | if (!urb) |
2247 | return -ENOMEM; | 2392 | return -ENOMEM; |
2248 | 2393 | ||
2249 | atomic_inc(&CmdUrbs); | 2394 | atomic_inc(&CmdUrbs); |
2250 | dbg("%s - ALLOCATE URB %p (outstanding %d)", __func__, urb, atomic_read(&CmdUrbs)); | 2395 | dbg("%s - ALLOCATE URB %p (outstanding %d)", |
2396 | __func__, urb, atomic_read(&CmdUrbs)); | ||
2251 | 2397 | ||
2252 | usb_fill_bulk_urb (urb, edge_serial->serial->dev, | 2398 | usb_fill_bulk_urb(urb, edge_serial->serial->dev, |
2253 | usb_sndbulkpipe(edge_serial->serial->dev, edge_serial->bulk_out_endpoint), | 2399 | usb_sndbulkpipe(edge_serial->serial->dev, |
2254 | buffer, length, edge_bulk_out_cmd_callback, edge_port); | 2400 | edge_serial->bulk_out_endpoint), |
2401 | buffer, length, edge_bulk_out_cmd_callback, edge_port); | ||
2255 | 2402 | ||
2256 | edge_port->commandPending = true; | 2403 | edge_port->commandPending = true; |
2257 | status = usb_submit_urb(urb, GFP_ATOMIC); | 2404 | status = usb_submit_urb(urb, GFP_ATOMIC); |
2258 | 2405 | ||
2259 | if (status) { | 2406 | if (status) { |
2260 | /* something went wrong */ | 2407 | /* something went wrong */ |
2261 | dev_err(&edge_port->port->dev, "%s - usb_submit_urb(write command) failed, status = %d\n", __func__, status); | 2408 | dev_err(&edge_port->port->dev, |
2409 | "%s - usb_submit_urb(write command) failed, status = %d\n", | ||
2410 | __func__, status); | ||
2262 | usb_kill_urb(urb); | 2411 | usb_kill_urb(urb); |
2263 | usb_free_urb(urb); | 2412 | usb_free_urb(urb); |
2264 | atomic_dec(&CmdUrbs); | 2413 | atomic_dec(&CmdUrbs); |
2265 | return status; | 2414 | return status; |
2266 | } | 2415 | } |
2267 | 2416 | ||
2268 | // wait for command to finish | 2417 | /* wait for command to finish */ |
2269 | timeout = COMMAND_TIMEOUT; | 2418 | timeout = COMMAND_TIMEOUT; |
2270 | #if 0 | 2419 | #if 0 |
2271 | wait_event (&edge_port->wait_command, !edge_port->commandPending); | 2420 | wait_event(&edge_port->wait_command, !edge_port->commandPending); |
2272 | 2421 | ||
2273 | if (edge_port->commandPending) { | 2422 | if (edge_port->commandPending) { |
2274 | /* command timed out */ | 2423 | /* command timed out */ |
@@ -2285,15 +2434,18 @@ static int write_cmd_usb (struct edgeport_port *edge_port, unsigned char *buffer | |||
2285 | * this function sends the proper command to change the baud rate of the | 2434 | * this function sends the proper command to change the baud rate of the |
2286 | * specified port. | 2435 | * specified port. |
2287 | *****************************************************************************/ | 2436 | *****************************************************************************/ |
2288 | static int send_cmd_write_baud_rate (struct edgeport_port *edge_port, int baudRate) | 2437 | static int send_cmd_write_baud_rate(struct edgeport_port *edge_port, |
2438 | int baudRate) | ||
2289 | { | 2439 | { |
2290 | struct edgeport_serial *edge_serial = usb_get_serial_data(edge_port->port->serial); | 2440 | struct edgeport_serial *edge_serial = |
2441 | usb_get_serial_data(edge_port->port->serial); | ||
2291 | unsigned char *cmdBuffer; | 2442 | unsigned char *cmdBuffer; |
2292 | unsigned char *currCmd; | 2443 | unsigned char *currCmd; |
2293 | int cmdLen = 0; | 2444 | int cmdLen = 0; |
2294 | int divisor; | 2445 | int divisor; |
2295 | int status; | 2446 | int status; |
2296 | unsigned char number = edge_port->port->number - edge_port->port->serial->minor; | 2447 | unsigned char number = |
2448 | edge_port->port->number - edge_port->port->serial->minor; | ||
2297 | 2449 | ||
2298 | if (edge_serial->is_epic && | 2450 | if (edge_serial->is_epic && |
2299 | !edge_serial->epic_descriptor.Supports.IOSPSetBaudRate) { | 2451 | !edge_serial->epic_descriptor.Supports.IOSPSetBaudRate) { |
@@ -2302,36 +2454,40 @@ static int send_cmd_write_baud_rate (struct edgeport_port *edge_port, int baudRa | |||
2302 | return 0; | 2454 | return 0; |
2303 | } | 2455 | } |
2304 | 2456 | ||
2305 | dbg("%s - port = %d, baud = %d", __func__, edge_port->port->number, baudRate); | 2457 | dbg("%s - port = %d, baud = %d", __func__, |
2458 | edge_port->port->number, baudRate); | ||
2306 | 2459 | ||
2307 | status = calc_baud_rate_divisor (baudRate, &divisor); | 2460 | status = calc_baud_rate_divisor(baudRate, &divisor); |
2308 | if (status) { | 2461 | if (status) { |
2309 | dev_err(&edge_port->port->dev, "%s - bad baud rate\n", __func__); | 2462 | dev_err(&edge_port->port->dev, "%s - bad baud rate\n", |
2463 | __func__); | ||
2310 | return status; | 2464 | return status; |
2311 | } | 2465 | } |
2312 | 2466 | ||
2313 | // Alloc memory for the string of commands. | 2467 | /* Alloc memory for the string of commands. */ |
2314 | cmdBuffer = kmalloc (0x100, GFP_ATOMIC); | 2468 | cmdBuffer = kmalloc(0x100, GFP_ATOMIC); |
2315 | if (!cmdBuffer) { | 2469 | if (!cmdBuffer) { |
2316 | dev_err(&edge_port->port->dev, "%s - kmalloc(%d) failed.\n", __func__, 0x100); | 2470 | dev_err(&edge_port->port->dev, |
2471 | "%s - kmalloc(%d) failed.\n", __func__, 0x100); | ||
2317 | return -ENOMEM; | 2472 | return -ENOMEM; |
2318 | } | 2473 | } |
2319 | currCmd = cmdBuffer; | 2474 | currCmd = cmdBuffer; |
2320 | 2475 | ||
2321 | // Enable access to divisor latch | 2476 | /* Enable access to divisor latch */ |
2322 | MAKE_CMD_WRITE_REG( &currCmd, &cmdLen, number, LCR, LCR_DL_ENABLE ); | 2477 | MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, number, LCR, LCR_DL_ENABLE); |
2323 | 2478 | ||
2324 | // Write the divisor itself | 2479 | /* Write the divisor itself */ |
2325 | MAKE_CMD_WRITE_REG( &currCmd, &cmdLen, number, DLL, LOW8 (divisor) ); | 2480 | MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, number, DLL, LOW8(divisor)); |
2326 | MAKE_CMD_WRITE_REG( &currCmd, &cmdLen, number, DLM, HIGH8(divisor) ); | 2481 | MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, number, DLM, HIGH8(divisor)); |
2327 | 2482 | ||
2328 | // Restore original value to disable access to divisor latch | 2483 | /* Restore original value to disable access to divisor latch */ |
2329 | MAKE_CMD_WRITE_REG( &currCmd, &cmdLen, number, LCR, edge_port->shadowLCR); | 2484 | MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, number, LCR, |
2485 | edge_port->shadowLCR); | ||
2330 | 2486 | ||
2331 | status = write_cmd_usb(edge_port, cmdBuffer, cmdLen ); | 2487 | status = write_cmd_usb(edge_port, cmdBuffer, cmdLen); |
2332 | if (status) { | 2488 | if (status) { |
2333 | /* something bad happened, let's free up the memory */ | 2489 | /* something bad happened, let's free up the memory */ |
2334 | kfree (cmdBuffer); | 2490 | kfree(cmdBuffer); |
2335 | } | 2491 | } |
2336 | 2492 | ||
2337 | return status; | 2493 | return status; |
@@ -2343,7 +2499,7 @@ static int send_cmd_write_baud_rate (struct edgeport_port *edge_port, int baudRa | |||
2343 | * this function calculates the proper baud rate divisor for the specified | 2499 | * this function calculates the proper baud rate divisor for the specified |
2344 | * baud rate. | 2500 | * baud rate. |
2345 | *****************************************************************************/ | 2501 | *****************************************************************************/ |
2346 | static int calc_baud_rate_divisor (int baudrate, int *divisor) | 2502 | static int calc_baud_rate_divisor(int baudrate, int *divisor) |
2347 | { | 2503 | { |
2348 | int i; | 2504 | int i; |
2349 | __u16 custom; | 2505 | __u16 custom; |
@@ -2352,17 +2508,17 @@ static int calc_baud_rate_divisor (int baudrate, int *divisor) | |||
2352 | dbg("%s - %d", __func__, baudrate); | 2508 | dbg("%s - %d", __func__, baudrate); |
2353 | 2509 | ||
2354 | for (i = 0; i < ARRAY_SIZE(divisor_table); i++) { | 2510 | for (i = 0; i < ARRAY_SIZE(divisor_table); i++) { |
2355 | if ( divisor_table[i].BaudRate == baudrate ) { | 2511 | if (divisor_table[i].BaudRate == baudrate) { |
2356 | *divisor = divisor_table[i].Divisor; | 2512 | *divisor = divisor_table[i].Divisor; |
2357 | return 0; | 2513 | return 0; |
2358 | } | 2514 | } |
2359 | } | 2515 | } |
2360 | 2516 | ||
2361 | // We have tried all of the standard baud rates | 2517 | /* We have tried all of the standard baud rates |
2362 | // lets try to calculate the divisor for this baud rate | 2518 | * lets try to calculate the divisor for this baud rate |
2363 | // Make sure the baud rate is reasonable | 2519 | * Make sure the baud rate is reasonable */ |
2364 | if (baudrate > 50 && baudrate < 230400) { | 2520 | if (baudrate > 50 && baudrate < 230400) { |
2365 | // get divisor | 2521 | /* get divisor */ |
2366 | custom = (__u16)((230400L + baudrate/2) / baudrate); | 2522 | custom = (__u16)((230400L + baudrate/2) / baudrate); |
2367 | 2523 | ||
2368 | *divisor = custom; | 2524 | *divisor = custom; |
@@ -2377,17 +2533,20 @@ static int calc_baud_rate_divisor (int baudrate, int *divisor) | |||
2377 | 2533 | ||
2378 | /***************************************************************************** | 2534 | /***************************************************************************** |
2379 | * send_cmd_write_uart_register | 2535 | * send_cmd_write_uart_register |
2380 | * this function builds up a uart register message and sends to to the device. | 2536 | * this function builds up a uart register message and sends to to the device. |
2381 | *****************************************************************************/ | 2537 | *****************************************************************************/ |
2382 | static int send_cmd_write_uart_register (struct edgeport_port *edge_port, __u8 regNum, __u8 regValue) | 2538 | static int send_cmd_write_uart_register(struct edgeport_port *edge_port, |
2539 | __u8 regNum, __u8 regValue) | ||
2383 | { | 2540 | { |
2384 | struct edgeport_serial *edge_serial = usb_get_serial_data(edge_port->port->serial); | 2541 | struct edgeport_serial *edge_serial = |
2542 | usb_get_serial_data(edge_port->port->serial); | ||
2385 | unsigned char *cmdBuffer; | 2543 | unsigned char *cmdBuffer; |
2386 | unsigned char *currCmd; | 2544 | unsigned char *currCmd; |
2387 | unsigned long cmdLen = 0; | 2545 | unsigned long cmdLen = 0; |
2388 | int status; | 2546 | int status; |
2389 | 2547 | ||
2390 | dbg("%s - write to %s register 0x%02x", (regNum == MCR) ? "MCR" : "LCR", __func__, regValue); | 2548 | dbg("%s - write to %s register 0x%02x", |
2549 | (regNum == MCR) ? "MCR" : "LCR", __func__, regValue); | ||
2391 | 2550 | ||
2392 | if (edge_serial->is_epic && | 2551 | if (edge_serial->is_epic && |
2393 | !edge_serial->epic_descriptor.Supports.IOSPWriteMCR && | 2552 | !edge_serial->epic_descriptor.Supports.IOSPWriteMCR && |
@@ -2399,27 +2558,26 @@ static int send_cmd_write_uart_register (struct edgeport_port *edge_port, __u8 r | |||
2399 | if (edge_serial->is_epic && | 2558 | if (edge_serial->is_epic && |
2400 | !edge_serial->epic_descriptor.Supports.IOSPWriteLCR && | 2559 | !edge_serial->epic_descriptor.Supports.IOSPWriteLCR && |
2401 | regNum == LCR) { | 2560 | regNum == LCR) { |
2402 | dbg ("SendCmdWriteUartReg - Not writing to LCR Register"); | 2561 | dbg("SendCmdWriteUartReg - Not writing to LCR Register"); |
2403 | return 0; | 2562 | return 0; |
2404 | } | 2563 | } |
2405 | 2564 | ||
2406 | // Alloc memory for the string of commands. | 2565 | /* Alloc memory for the string of commands. */ |
2407 | cmdBuffer = kmalloc (0x10, GFP_ATOMIC); | 2566 | cmdBuffer = kmalloc(0x10, GFP_ATOMIC); |
2408 | if (cmdBuffer == NULL ) { | 2567 | if (cmdBuffer == NULL) |
2409 | return -ENOMEM; | 2568 | return -ENOMEM; |
2410 | } | ||
2411 | 2569 | ||
2412 | currCmd = cmdBuffer; | 2570 | currCmd = cmdBuffer; |
2413 | 2571 | ||
2414 | // Build a cmd in the buffer to write the given register | 2572 | /* Build a cmd in the buffer to write the given register */ |
2415 | MAKE_CMD_WRITE_REG (&currCmd, &cmdLen, | 2573 | MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, |
2416 | edge_port->port->number - edge_port->port->serial->minor, | 2574 | edge_port->port->number - edge_port->port->serial->minor, |
2417 | regNum, regValue); | 2575 | regNum, regValue); |
2418 | 2576 | ||
2419 | status = write_cmd_usb(edge_port, cmdBuffer, cmdLen); | 2577 | status = write_cmd_usb(edge_port, cmdBuffer, cmdLen); |
2420 | if (status) { | 2578 | if (status) { |
2421 | /* something bad happened, let's free up the memory */ | 2579 | /* something bad happened, let's free up the memory */ |
2422 | kfree (cmdBuffer); | 2580 | kfree(cmdBuffer); |
2423 | } | 2581 | } |
2424 | 2582 | ||
2425 | return status; | 2583 | return status; |
@@ -2428,14 +2586,15 @@ static int send_cmd_write_uart_register (struct edgeport_port *edge_port, __u8 r | |||
2428 | 2586 | ||
2429 | /***************************************************************************** | 2587 | /***************************************************************************** |
2430 | * change_port_settings | 2588 | * change_port_settings |
2431 | * This routine is called to set the UART on the device to match the specified | 2589 | * This routine is called to set the UART on the device to match the |
2432 | * new settings. | 2590 | * specified new settings. |
2433 | *****************************************************************************/ | 2591 | *****************************************************************************/ |
2434 | 2592 | ||
2435 | static void change_port_settings(struct tty_struct *tty, | 2593 | static void change_port_settings(struct tty_struct *tty, |
2436 | struct edgeport_port *edge_port, struct ktermios *old_termios) | 2594 | struct edgeport_port *edge_port, struct ktermios *old_termios) |
2437 | { | 2595 | { |
2438 | struct edgeport_serial *edge_serial = usb_get_serial_data(edge_port->port->serial); | 2596 | struct edgeport_serial *edge_serial = |
2597 | usb_get_serial_data(edge_port->port->serial); | ||
2439 | int baud; | 2598 | int baud; |
2440 | unsigned cflag; | 2599 | unsigned cflag; |
2441 | __u8 mask = 0xff; | 2600 | __u8 mask = 0xff; |
@@ -2457,11 +2616,23 @@ static void change_port_settings(struct tty_struct *tty, | |||
2457 | cflag = tty->termios->c_cflag; | 2616 | cflag = tty->termios->c_cflag; |
2458 | 2617 | ||
2459 | switch (cflag & CSIZE) { | 2618 | switch (cflag & CSIZE) { |
2460 | case CS5: lData = LCR_BITS_5; mask = 0x1f; dbg("%s - data bits = 5", __func__); break; | 2619 | case CS5: |
2461 | case CS6: lData = LCR_BITS_6; mask = 0x3f; dbg("%s - data bits = 6", __func__); break; | 2620 | lData = LCR_BITS_5; mask = 0x1f; |
2462 | case CS7: lData = LCR_BITS_7; mask = 0x7f; dbg("%s - data bits = 7", __func__); break; | 2621 | dbg("%s - data bits = 5", __func__); |
2463 | default: | 2622 | break; |
2464 | case CS8: lData = LCR_BITS_8; dbg("%s - data bits = 8", __func__); break; | 2623 | case CS6: |
2624 | lData = LCR_BITS_6; mask = 0x3f; | ||
2625 | dbg("%s - data bits = 6", __func__); | ||
2626 | break; | ||
2627 | case CS7: | ||
2628 | lData = LCR_BITS_7; mask = 0x7f; | ||
2629 | dbg("%s - data bits = 7", __func__); | ||
2630 | break; | ||
2631 | default: | ||
2632 | case CS8: | ||
2633 | lData = LCR_BITS_8; | ||
2634 | dbg("%s - data bits = 8", __func__); | ||
2635 | break; | ||
2465 | } | 2636 | } |
2466 | 2637 | ||
2467 | lParity = LCR_PAR_NONE; | 2638 | lParity = LCR_PAR_NONE; |
@@ -2503,7 +2674,8 @@ static void change_port_settings(struct tty_struct *tty, | |||
2503 | dbg("%s - RTS/CTS is disabled", __func__); | 2674 | dbg("%s - RTS/CTS is disabled", __func__); |
2504 | } | 2675 | } |
2505 | 2676 | ||
2506 | /* if we are implementing XON/XOFF, set the start and stop character in the device */ | 2677 | /* if we are implementing XON/XOFF, set the start and stop character |
2678 | in the device */ | ||
2507 | if (I_IXOFF(tty) || I_IXON(tty)) { | 2679 | if (I_IXOFF(tty) || I_IXON(tty)) { |
2508 | unsigned char stop_char = STOP_CHAR(tty); | 2680 | unsigned char stop_char = STOP_CHAR(tty); |
2509 | unsigned char start_char = START_CHAR(tty); | 2681 | unsigned char start_char = START_CHAR(tty); |
@@ -2511,14 +2683,17 @@ static void change_port_settings(struct tty_struct *tty, | |||
2511 | if ((!edge_serial->is_epic) || | 2683 | if ((!edge_serial->is_epic) || |
2512 | ((edge_serial->is_epic) && | 2684 | ((edge_serial->is_epic) && |
2513 | (edge_serial->epic_descriptor.Supports.IOSPSetXChar))) { | 2685 | (edge_serial->epic_descriptor.Supports.IOSPSetXChar))) { |
2514 | send_iosp_ext_cmd(edge_port, IOSP_CMD_SET_XON_CHAR, start_char); | 2686 | send_iosp_ext_cmd(edge_port, |
2515 | send_iosp_ext_cmd(edge_port, IOSP_CMD_SET_XOFF_CHAR, stop_char); | 2687 | IOSP_CMD_SET_XON_CHAR, start_char); |
2688 | send_iosp_ext_cmd(edge_port, | ||
2689 | IOSP_CMD_SET_XOFF_CHAR, stop_char); | ||
2516 | } | 2690 | } |
2517 | 2691 | ||
2518 | /* if we are implementing INBOUND XON/XOFF */ | 2692 | /* if we are implementing INBOUND XON/XOFF */ |
2519 | if (I_IXOFF(tty)) { | 2693 | if (I_IXOFF(tty)) { |
2520 | rxFlow |= IOSP_RX_FLOW_XON_XOFF; | 2694 | rxFlow |= IOSP_RX_FLOW_XON_XOFF; |
2521 | dbg("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", __func__, start_char, stop_char); | 2695 | dbg("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", |
2696 | __func__, start_char, stop_char); | ||
2522 | } else { | 2697 | } else { |
2523 | dbg("%s - INBOUND XON/XOFF is disabled", __func__); | 2698 | dbg("%s - INBOUND XON/XOFF is disabled", __func__); |
2524 | } | 2699 | } |
@@ -2526,7 +2701,8 @@ static void change_port_settings(struct tty_struct *tty, | |||
2526 | /* if we are implementing OUTBOUND XON/XOFF */ | 2701 | /* if we are implementing OUTBOUND XON/XOFF */ |
2527 | if (I_IXON(tty)) { | 2702 | if (I_IXON(tty)) { |
2528 | txFlow |= IOSP_TX_FLOW_XON_XOFF; | 2703 | txFlow |= IOSP_TX_FLOW_XON_XOFF; |
2529 | dbg("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", __func__, start_char, stop_char); | 2704 | dbg("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", |
2705 | __func__, start_char, stop_char); | ||
2530 | } else { | 2706 | } else { |
2531 | dbg("%s - OUTBOUND XON/XOFF is disabled", __func__); | 2707 | dbg("%s - OUTBOUND XON/XOFF is disabled", __func__); |
2532 | } | 2708 | } |
@@ -2549,20 +2725,20 @@ static void change_port_settings(struct tty_struct *tty, | |||
2549 | edge_port->validDataMask = mask; | 2725 | edge_port->validDataMask = mask; |
2550 | 2726 | ||
2551 | /* Send the updated LCR value to the EdgePort */ | 2727 | /* Send the updated LCR value to the EdgePort */ |
2552 | status = send_cmd_write_uart_register(edge_port, LCR, edge_port->shadowLCR); | 2728 | status = send_cmd_write_uart_register(edge_port, LCR, |
2553 | if (status != 0) { | 2729 | edge_port->shadowLCR); |
2730 | if (status != 0) | ||
2554 | return; | 2731 | return; |
2555 | } | ||
2556 | 2732 | ||
2557 | /* set up the MCR register and send it to the EdgePort */ | 2733 | /* set up the MCR register and send it to the EdgePort */ |
2558 | edge_port->shadowMCR = MCR_MASTER_IE; | 2734 | edge_port->shadowMCR = MCR_MASTER_IE; |
2559 | if (cflag & CBAUD) { | 2735 | if (cflag & CBAUD) |
2560 | edge_port->shadowMCR |= (MCR_DTR | MCR_RTS); | 2736 | edge_port->shadowMCR |= (MCR_DTR | MCR_RTS); |
2561 | } | 2737 | |
2562 | status = send_cmd_write_uart_register(edge_port, MCR, edge_port->shadowMCR); | 2738 | status = send_cmd_write_uart_register(edge_port, MCR, |
2563 | if (status != 0) { | 2739 | edge_port->shadowMCR); |
2740 | if (status != 0) | ||
2564 | return; | 2741 | return; |
2565 | } | ||
2566 | 2742 | ||
2567 | /* Determine divisor based on baud rate */ | 2743 | /* Determine divisor based on baud rate */ |
2568 | baud = tty_get_baud_rate(tty); | 2744 | baud = tty_get_baud_rate(tty); |
@@ -2572,7 +2748,7 @@ static void change_port_settings(struct tty_struct *tty, | |||
2572 | } | 2748 | } |
2573 | 2749 | ||
2574 | dbg("%s - baud rate = %d", __func__, baud); | 2750 | dbg("%s - baud rate = %d", __func__, baud); |
2575 | status = send_cmd_write_baud_rate (edge_port, baud); | 2751 | status = send_cmd_write_baud_rate(edge_port, baud); |
2576 | if (status == -1) { | 2752 | if (status == -1) { |
2577 | /* Speed change was not possible - put back the old speed */ | 2753 | /* Speed change was not possible - put back the old speed */ |
2578 | baud = tty_termios_baud_rate(old_termios); | 2754 | baud = tty_termios_baud_rate(old_termios); |
@@ -2589,7 +2765,8 @@ static void change_port_settings(struct tty_struct *tty, | |||
2589 | * ASCII range, but it's only for debugging... | 2765 | * ASCII range, but it's only for debugging... |
2590 | * NOTE: expects the unicode in LE format | 2766 | * NOTE: expects the unicode in LE format |
2591 | ****************************************************************************/ | 2767 | ****************************************************************************/ |
2592 | static void unicode_to_ascii(char *string, int buflen, __le16 *unicode, int unicode_size) | 2768 | static void unicode_to_ascii(char *string, int buflen, |
2769 | __le16 *unicode, int unicode_size) | ||
2593 | { | 2770 | { |
2594 | int i; | 2771 | int i; |
2595 | 2772 | ||
@@ -2608,75 +2785,99 @@ static void unicode_to_ascii(char *string, int buflen, __le16 *unicode, int unic | |||
2608 | 2785 | ||
2609 | /**************************************************************************** | 2786 | /**************************************************************************** |
2610 | * get_manufacturing_desc | 2787 | * get_manufacturing_desc |
2611 | * reads in the manufacturing descriptor and stores it into the serial | 2788 | * reads in the manufacturing descriptor and stores it into the serial |
2612 | * structure. | 2789 | * structure. |
2613 | ****************************************************************************/ | 2790 | ****************************************************************************/ |
2614 | static void get_manufacturing_desc (struct edgeport_serial *edge_serial) | 2791 | static void get_manufacturing_desc(struct edgeport_serial *edge_serial) |
2615 | { | 2792 | { |
2616 | int response; | 2793 | int response; |
2617 | 2794 | ||
2618 | dbg("getting manufacturer descriptor"); | 2795 | dbg("getting manufacturer descriptor"); |
2619 | 2796 | ||
2620 | response = rom_read (edge_serial->serial, (EDGE_MANUF_DESC_ADDR & 0xffff0000) >> 16, | 2797 | response = rom_read(edge_serial->serial, |
2621 | (__u16)(EDGE_MANUF_DESC_ADDR & 0x0000ffff), EDGE_MANUF_DESC_LEN, | 2798 | (EDGE_MANUF_DESC_ADDR & 0xffff0000) >> 16, |
2622 | (__u8 *)(&edge_serial->manuf_descriptor)); | 2799 | (__u16)(EDGE_MANUF_DESC_ADDR & 0x0000ffff), |
2800 | EDGE_MANUF_DESC_LEN, | ||
2801 | (__u8 *)(&edge_serial->manuf_descriptor)); | ||
2623 | 2802 | ||
2624 | if (response < 1) { | 2803 | if (response < 1) |
2625 | dev_err(&edge_serial->serial->dev->dev, "error in getting manufacturer descriptor\n"); | 2804 | dev_err(&edge_serial->serial->dev->dev, |
2626 | } else { | 2805 | "error in getting manufacturer descriptor\n"); |
2806 | else { | ||
2627 | char string[30]; | 2807 | char string[30]; |
2628 | dbg("**Manufacturer Descriptor"); | 2808 | dbg("**Manufacturer Descriptor"); |
2629 | dbg(" RomSize: %dK", edge_serial->manuf_descriptor.RomSize); | 2809 | dbg(" RomSize: %dK", |
2630 | dbg(" RamSize: %dK", edge_serial->manuf_descriptor.RamSize); | 2810 | edge_serial->manuf_descriptor.RomSize); |
2631 | dbg(" CpuRev: %d", edge_serial->manuf_descriptor.CpuRev); | 2811 | dbg(" RamSize: %dK", |
2632 | dbg(" BoardRev: %d", edge_serial->manuf_descriptor.BoardRev); | 2812 | edge_serial->manuf_descriptor.RamSize); |
2633 | dbg(" NumPorts: %d", edge_serial->manuf_descriptor.NumPorts); | 2813 | dbg(" CpuRev: %d", |
2634 | dbg(" DescDate: %d/%d/%d", edge_serial->manuf_descriptor.DescDate[0], edge_serial->manuf_descriptor.DescDate[1], edge_serial->manuf_descriptor.DescDate[2]+1900); | 2814 | edge_serial->manuf_descriptor.CpuRev); |
2815 | dbg(" BoardRev: %d", | ||
2816 | edge_serial->manuf_descriptor.BoardRev); | ||
2817 | dbg(" NumPorts: %d", | ||
2818 | edge_serial->manuf_descriptor.NumPorts); | ||
2819 | dbg(" DescDate: %d/%d/%d", | ||
2820 | edge_serial->manuf_descriptor.DescDate[0], | ||
2821 | edge_serial->manuf_descriptor.DescDate[1], | ||
2822 | edge_serial->manuf_descriptor.DescDate[2]+1900); | ||
2635 | unicode_to_ascii(string, sizeof(string), | 2823 | unicode_to_ascii(string, sizeof(string), |
2636 | edge_serial->manuf_descriptor.SerialNumber, | 2824 | edge_serial->manuf_descriptor.SerialNumber, |
2637 | edge_serial->manuf_descriptor.SerNumLength/2); | 2825 | edge_serial->manuf_descriptor.SerNumLength/2); |
2638 | dbg(" SerialNumber: %s", string); | 2826 | dbg(" SerialNumber: %s", string); |
2639 | unicode_to_ascii(string, sizeof(string), | 2827 | unicode_to_ascii(string, sizeof(string), |
2640 | edge_serial->manuf_descriptor.AssemblyNumber, | 2828 | edge_serial->manuf_descriptor.AssemblyNumber, |
2641 | edge_serial->manuf_descriptor.AssemblyNumLength/2); | 2829 | edge_serial->manuf_descriptor.AssemblyNumLength/2); |
2642 | dbg(" AssemblyNumber: %s", string); | 2830 | dbg(" AssemblyNumber: %s", string); |
2643 | unicode_to_ascii(string, sizeof(string), | 2831 | unicode_to_ascii(string, sizeof(string), |
2644 | edge_serial->manuf_descriptor.OemAssyNumber, | 2832 | edge_serial->manuf_descriptor.OemAssyNumber, |
2645 | edge_serial->manuf_descriptor.OemAssyNumLength/2); | 2833 | edge_serial->manuf_descriptor.OemAssyNumLength/2); |
2646 | dbg(" OemAssyNumber: %s", string); | 2834 | dbg(" OemAssyNumber: %s", string); |
2647 | dbg(" UartType: %d", edge_serial->manuf_descriptor.UartType); | 2835 | dbg(" UartType: %d", |
2648 | dbg(" IonPid: %d", edge_serial->manuf_descriptor.IonPid); | 2836 | edge_serial->manuf_descriptor.UartType); |
2649 | dbg(" IonConfig: %d", edge_serial->manuf_descriptor.IonConfig); | 2837 | dbg(" IonPid: %d", |
2838 | edge_serial->manuf_descriptor.IonPid); | ||
2839 | dbg(" IonConfig: %d", | ||
2840 | edge_serial->manuf_descriptor.IonConfig); | ||
2650 | } | 2841 | } |
2651 | } | 2842 | } |
2652 | 2843 | ||
2653 | 2844 | ||
2654 | /**************************************************************************** | 2845 | /**************************************************************************** |
2655 | * get_boot_desc | 2846 | * get_boot_desc |
2656 | * reads in the bootloader descriptor and stores it into the serial | 2847 | * reads in the bootloader descriptor and stores it into the serial |
2657 | * structure. | 2848 | * structure. |
2658 | ****************************************************************************/ | 2849 | ****************************************************************************/ |
2659 | static void get_boot_desc (struct edgeport_serial *edge_serial) | 2850 | static void get_boot_desc(struct edgeport_serial *edge_serial) |
2660 | { | 2851 | { |
2661 | int response; | 2852 | int response; |
2662 | 2853 | ||
2663 | dbg("getting boot descriptor"); | 2854 | dbg("getting boot descriptor"); |
2664 | 2855 | ||
2665 | response = rom_read (edge_serial->serial, (EDGE_BOOT_DESC_ADDR & 0xffff0000) >> 16, | 2856 | response = rom_read(edge_serial->serial, |
2666 | (__u16)(EDGE_BOOT_DESC_ADDR & 0x0000ffff), EDGE_BOOT_DESC_LEN, | 2857 | (EDGE_BOOT_DESC_ADDR & 0xffff0000) >> 16, |
2667 | (__u8 *)(&edge_serial->boot_descriptor)); | 2858 | (__u16)(EDGE_BOOT_DESC_ADDR & 0x0000ffff), |
2859 | EDGE_BOOT_DESC_LEN, | ||
2860 | (__u8 *)(&edge_serial->boot_descriptor)); | ||
2668 | 2861 | ||
2669 | if (response < 1) { | 2862 | if (response < 1) |
2670 | dev_err(&edge_serial->serial->dev->dev, "error in getting boot descriptor\n"); | 2863 | dev_err(&edge_serial->serial->dev->dev, |
2671 | } else { | 2864 | "error in getting boot descriptor\n"); |
2865 | else { | ||
2672 | dbg("**Boot Descriptor:"); | 2866 | dbg("**Boot Descriptor:"); |
2673 | dbg(" BootCodeLength: %d", le16_to_cpu(edge_serial->boot_descriptor.BootCodeLength)); | 2867 | dbg(" BootCodeLength: %d", |
2674 | dbg(" MajorVersion: %d", edge_serial->boot_descriptor.MajorVersion); | 2868 | le16_to_cpu(edge_serial->boot_descriptor.BootCodeLength)); |
2675 | dbg(" MinorVersion: %d", edge_serial->boot_descriptor.MinorVersion); | 2869 | dbg(" MajorVersion: %d", |
2676 | dbg(" BuildNumber: %d", le16_to_cpu(edge_serial->boot_descriptor.BuildNumber)); | 2870 | edge_serial->boot_descriptor.MajorVersion); |
2677 | dbg(" Capabilities: 0x%x", le16_to_cpu(edge_serial->boot_descriptor.Capabilities)); | 2871 | dbg(" MinorVersion: %d", |
2678 | dbg(" UConfig0: %d", edge_serial->boot_descriptor.UConfig0); | 2872 | edge_serial->boot_descriptor.MinorVersion); |
2679 | dbg(" UConfig1: %d", edge_serial->boot_descriptor.UConfig1); | 2873 | dbg(" BuildNumber: %d", |
2874 | le16_to_cpu(edge_serial->boot_descriptor.BuildNumber)); | ||
2875 | dbg(" Capabilities: 0x%x", | ||
2876 | le16_to_cpu(edge_serial->boot_descriptor.Capabilities)); | ||
2877 | dbg(" UConfig0: %d", | ||
2878 | edge_serial->boot_descriptor.UConfig0); | ||
2879 | dbg(" UConfig1: %d", | ||
2880 | edge_serial->boot_descriptor.UConfig1); | ||
2680 | } | 2881 | } |
2681 | } | 2882 | } |
2682 | 2883 | ||
@@ -2685,7 +2886,7 @@ static void get_boot_desc (struct edgeport_serial *edge_serial) | |||
2685 | * load_application_firmware | 2886 | * load_application_firmware |
2686 | * This is called to load the application firmware to the device | 2887 | * This is called to load the application firmware to the device |
2687 | ****************************************************************************/ | 2888 | ****************************************************************************/ |
2688 | static void load_application_firmware (struct edgeport_serial *edge_serial) | 2889 | static void load_application_firmware(struct edgeport_serial *edge_serial) |
2689 | { | 2890 | { |
2690 | const struct ihex_binrec *rec; | 2891 | const struct ihex_binrec *rec; |
2691 | const struct firmware *fw; | 2892 | const struct firmware *fw; |
@@ -2762,7 +2963,7 @@ static void load_application_firmware (struct edgeport_serial *edge_serial) | |||
2762 | /**************************************************************************** | 2963 | /**************************************************************************** |
2763 | * edge_startup | 2964 | * edge_startup |
2764 | ****************************************************************************/ | 2965 | ****************************************************************************/ |
2765 | static int edge_startup (struct usb_serial *serial) | 2966 | static int edge_startup(struct usb_serial *serial) |
2766 | { | 2967 | { |
2767 | struct edgeport_serial *edge_serial; | 2968 | struct edgeport_serial *edge_serial; |
2768 | struct edgeport_port *edge_port; | 2969 | struct edgeport_port *edge_port; |
@@ -2804,10 +3005,10 @@ static int edge_startup (struct usb_serial *serial) | |||
2804 | sizeof(struct edge_compatibility_bits)); | 3005 | sizeof(struct edge_compatibility_bits)); |
2805 | 3006 | ||
2806 | /* get the manufacturing descriptor for this device */ | 3007 | /* get the manufacturing descriptor for this device */ |
2807 | get_manufacturing_desc (edge_serial); | 3008 | get_manufacturing_desc(edge_serial); |
2808 | 3009 | ||
2809 | /* get the boot descriptor */ | 3010 | /* get the boot descriptor */ |
2810 | get_boot_desc (edge_serial); | 3011 | get_boot_desc(edge_serial); |
2811 | 3012 | ||
2812 | get_product_info(edge_serial); | 3013 | get_product_info(edge_serial); |
2813 | } | 3014 | } |
@@ -2828,41 +3029,43 @@ static int edge_startup (struct usb_serial *serial) | |||
2828 | /* If not an EPiC device */ | 3029 | /* If not an EPiC device */ |
2829 | if (!edge_serial->is_epic) { | 3030 | if (!edge_serial->is_epic) { |
2830 | /* now load the application firmware into this device */ | 3031 | /* now load the application firmware into this device */ |
2831 | load_application_firmware (edge_serial); | 3032 | load_application_firmware(edge_serial); |
2832 | 3033 | ||
2833 | dbg("%s - time 2 %ld", __func__, jiffies); | 3034 | dbg("%s - time 2 %ld", __func__, jiffies); |
2834 | 3035 | ||
2835 | /* Check current Edgeport EEPROM and update if necessary */ | 3036 | /* Check current Edgeport EEPROM and update if necessary */ |
2836 | update_edgeport_E2PROM (edge_serial); | 3037 | update_edgeport_E2PROM(edge_serial); |
2837 | 3038 | ||
2838 | dbg("%s - time 3 %ld", __func__, jiffies); | 3039 | dbg("%s - time 3 %ld", __func__, jiffies); |
2839 | 3040 | ||
2840 | /* set the configuration to use #1 */ | 3041 | /* set the configuration to use #1 */ |
2841 | // dbg("set_configuration 1"); | 3042 | /* dbg("set_configuration 1"); */ |
2842 | // usb_set_configuration (dev, 1); | 3043 | /* usb_set_configuration (dev, 1); */ |
2843 | } | 3044 | } |
2844 | dbg(" FirmwareMajorVersion %d.%d.%d", | 3045 | dbg(" FirmwareMajorVersion %d.%d.%d", |
2845 | edge_serial->product_info.FirmwareMajorVersion, | 3046 | edge_serial->product_info.FirmwareMajorVersion, |
2846 | edge_serial->product_info.FirmwareMinorVersion, | 3047 | edge_serial->product_info.FirmwareMinorVersion, |
2847 | le16_to_cpu(edge_serial->product_info.FirmwareBuildNumber)); | 3048 | le16_to_cpu(edge_serial->product_info.FirmwareBuildNumber)); |
2848 | 3049 | ||
2849 | /* we set up the pointers to the endpoints in the edge_open function, | 3050 | /* we set up the pointers to the endpoints in the edge_open function, |
2850 | * as the structures aren't created yet. */ | 3051 | * as the structures aren't created yet. */ |
2851 | 3052 | ||
2852 | /* set up our port private structures */ | 3053 | /* set up our port private structures */ |
2853 | for (i = 0; i < serial->num_ports; ++i) { | 3054 | for (i = 0; i < serial->num_ports; ++i) { |
2854 | edge_port = kmalloc (sizeof(struct edgeport_port), GFP_KERNEL); | 3055 | edge_port = kmalloc(sizeof(struct edgeport_port), GFP_KERNEL); |
2855 | if (edge_port == NULL) { | 3056 | if (edge_port == NULL) { |
2856 | dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__); | 3057 | dev_err(&serial->dev->dev, "%s - Out of memory\n", |
3058 | __func__); | ||
2857 | for (j = 0; j < i; ++j) { | 3059 | for (j = 0; j < i; ++j) { |
2858 | kfree (usb_get_serial_port_data(serial->port[j])); | 3060 | kfree(usb_get_serial_port_data(serial->port[j])); |
2859 | usb_set_serial_port_data(serial->port[j], NULL); | 3061 | usb_set_serial_port_data(serial->port[j], |
3062 | NULL); | ||
2860 | } | 3063 | } |
2861 | usb_set_serial_data(serial, NULL); | 3064 | usb_set_serial_data(serial, NULL); |
2862 | kfree(edge_serial); | 3065 | kfree(edge_serial); |
2863 | return -ENOMEM; | 3066 | return -ENOMEM; |
2864 | } | 3067 | } |
2865 | memset (edge_port, 0, sizeof(struct edgeport_port)); | 3068 | memset(edge_port, 0, sizeof(struct edgeport_port)); |
2866 | spin_lock_init(&edge_port->ep_lock); | 3069 | spin_lock_init(&edge_port->ep_lock); |
2867 | edge_port->port = serial->port[i]; | 3070 | edge_port->port = serial->port[i]; |
2868 | usb_set_serial_port_data(serial->port[i], edge_port); | 3071 | usb_set_serial_port_data(serial->port[i], edge_port); |
@@ -2871,14 +3074,16 @@ static int edge_startup (struct usb_serial *serial) | |||
2871 | response = 0; | 3074 | response = 0; |
2872 | 3075 | ||
2873 | if (edge_serial->is_epic) { | 3076 | if (edge_serial->is_epic) { |
2874 | /* EPIC thing, set up our interrupt polling now and our read urb, so | 3077 | /* EPIC thing, set up our interrupt polling now and our read |
2875 | * that the device knows it really is connected. */ | 3078 | * urb, so that the device knows it really is connected. */ |
2876 | interrupt_in_found = bulk_in_found = bulk_out_found = false; | 3079 | interrupt_in_found = bulk_in_found = bulk_out_found = false; |
2877 | for (i = 0; i < serial->interface->altsetting[0].desc.bNumEndpoints; ++i) { | 3080 | for (i = 0; i < serial->interface->altsetting[0] |
3081 | .desc.bNumEndpoints; ++i) { | ||
2878 | struct usb_endpoint_descriptor *endpoint; | 3082 | struct usb_endpoint_descriptor *endpoint; |
2879 | int buffer_size; | 3083 | int buffer_size; |
2880 | 3084 | ||
2881 | endpoint = &serial->interface->altsetting[0].endpoint[i].desc; | 3085 | endpoint = &serial->interface->altsetting[0]. |
3086 | endpoint[i].desc; | ||
2882 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); | 3087 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); |
2883 | if (!interrupt_in_found && | 3088 | if (!interrupt_in_found && |
2884 | (usb_endpoint_is_int_in(endpoint))) { | 3089 | (usb_endpoint_is_int_in(endpoint))) { |
@@ -2886,58 +3091,67 @@ static int edge_startup (struct usb_serial *serial) | |||
2886 | dbg("found interrupt in"); | 3091 | dbg("found interrupt in"); |
2887 | 3092 | ||
2888 | /* not set up yet, so do it now */ | 3093 | /* not set up yet, so do it now */ |
2889 | edge_serial->interrupt_read_urb = usb_alloc_urb(0, GFP_KERNEL); | 3094 | edge_serial->interrupt_read_urb = |
3095 | usb_alloc_urb(0, GFP_KERNEL); | ||
2890 | if (!edge_serial->interrupt_read_urb) { | 3096 | if (!edge_serial->interrupt_read_urb) { |
2891 | err("out of memory"); | 3097 | err("out of memory"); |
2892 | return -ENOMEM; | 3098 | return -ENOMEM; |
2893 | } | 3099 | } |
2894 | edge_serial->interrupt_in_buffer = kmalloc(buffer_size, GFP_KERNEL); | 3100 | edge_serial->interrupt_in_buffer = |
3101 | kmalloc(buffer_size, GFP_KERNEL); | ||
2895 | if (!edge_serial->interrupt_in_buffer) { | 3102 | if (!edge_serial->interrupt_in_buffer) { |
2896 | err("out of memory"); | 3103 | err("out of memory"); |
2897 | usb_free_urb(edge_serial->interrupt_read_urb); | 3104 | usb_free_urb(edge_serial->interrupt_read_urb); |
2898 | return -ENOMEM; | 3105 | return -ENOMEM; |
2899 | } | 3106 | } |
2900 | edge_serial->interrupt_in_endpoint = endpoint->bEndpointAddress; | 3107 | edge_serial->interrupt_in_endpoint = |
3108 | endpoint->bEndpointAddress; | ||
2901 | 3109 | ||
2902 | /* set up our interrupt urb */ | 3110 | /* set up our interrupt urb */ |
2903 | usb_fill_int_urb(edge_serial->interrupt_read_urb, | 3111 | usb_fill_int_urb( |
2904 | dev, | 3112 | edge_serial->interrupt_read_urb, |
2905 | usb_rcvintpipe(dev, endpoint->bEndpointAddress), | 3113 | dev, |
2906 | edge_serial->interrupt_in_buffer, | 3114 | usb_rcvintpipe(dev, |
2907 | buffer_size, | 3115 | endpoint->bEndpointAddress), |
2908 | edge_interrupt_callback, | 3116 | edge_serial->interrupt_in_buffer, |
2909 | edge_serial, | 3117 | buffer_size, |
2910 | endpoint->bInterval); | 3118 | edge_interrupt_callback, |
3119 | edge_serial, | ||
3120 | endpoint->bInterval); | ||
2911 | 3121 | ||
2912 | interrupt_in_found = true; | 3122 | interrupt_in_found = true; |
2913 | } | 3123 | } |
2914 | 3124 | ||
2915 | if (!bulk_in_found && | 3125 | if (!bulk_in_found && |
2916 | (usb_endpoint_is_bulk_in(endpoint))) { | 3126 | (usb_endpoint_is_bulk_in(endpoint))) { |
2917 | /* we found a bulk in endpoint */ | 3127 | /* we found a bulk in endpoint */ |
2918 | dbg("found bulk in"); | 3128 | dbg("found bulk in"); |
2919 | 3129 | ||
2920 | /* not set up yet, so do it now */ | 3130 | /* not set up yet, so do it now */ |
2921 | edge_serial->read_urb = usb_alloc_urb(0, GFP_KERNEL); | 3131 | edge_serial->read_urb = |
3132 | usb_alloc_urb(0, GFP_KERNEL); | ||
2922 | if (!edge_serial->read_urb) { | 3133 | if (!edge_serial->read_urb) { |
2923 | err("out of memory"); | 3134 | err("out of memory"); |
2924 | return -ENOMEM; | 3135 | return -ENOMEM; |
2925 | } | 3136 | } |
2926 | edge_serial->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL); | 3137 | edge_serial->bulk_in_buffer = |
3138 | kmalloc(buffer_size, GFP_KERNEL); | ||
2927 | if (!edge_serial->bulk_in_buffer) { | 3139 | if (!edge_serial->bulk_in_buffer) { |
2928 | err ("out of memory"); | 3140 | err("out of memory"); |
2929 | usb_free_urb(edge_serial->read_urb); | 3141 | usb_free_urb(edge_serial->read_urb); |
2930 | return -ENOMEM; | 3142 | return -ENOMEM; |
2931 | } | 3143 | } |
2932 | edge_serial->bulk_in_endpoint = endpoint->bEndpointAddress; | 3144 | edge_serial->bulk_in_endpoint = |
3145 | endpoint->bEndpointAddress; | ||
2933 | 3146 | ||
2934 | /* set up our bulk in urb */ | 3147 | /* set up our bulk in urb */ |
2935 | usb_fill_bulk_urb(edge_serial->read_urb, dev, | 3148 | usb_fill_bulk_urb(edge_serial->read_urb, dev, |
2936 | usb_rcvbulkpipe(dev, endpoint->bEndpointAddress), | 3149 | usb_rcvbulkpipe(dev, |
2937 | edge_serial->bulk_in_buffer, | 3150 | endpoint->bEndpointAddress), |
2938 | le16_to_cpu(endpoint->wMaxPacketSize), | 3151 | edge_serial->bulk_in_buffer, |
2939 | edge_bulk_in_callback, | 3152 | le16_to_cpu(endpoint->wMaxPacketSize), |
2940 | edge_serial); | 3153 | edge_bulk_in_callback, |
3154 | edge_serial); | ||
2941 | bulk_in_found = true; | 3155 | bulk_in_found = true; |
2942 | } | 3156 | } |
2943 | 3157 | ||
@@ -2945,21 +3159,24 @@ static int edge_startup (struct usb_serial *serial) | |||
2945 | (usb_endpoint_is_bulk_out(endpoint))) { | 3159 | (usb_endpoint_is_bulk_out(endpoint))) { |
2946 | /* we found a bulk out endpoint */ | 3160 | /* we found a bulk out endpoint */ |
2947 | dbg("found bulk out"); | 3161 | dbg("found bulk out"); |
2948 | edge_serial->bulk_out_endpoint = endpoint->bEndpointAddress; | 3162 | edge_serial->bulk_out_endpoint = |
3163 | endpoint->bEndpointAddress; | ||
2949 | bulk_out_found = true; | 3164 | bulk_out_found = true; |
2950 | } | 3165 | } |
2951 | } | 3166 | } |
2952 | 3167 | ||
2953 | if (!interrupt_in_found || !bulk_in_found || !bulk_out_found) { | 3168 | if (!interrupt_in_found || !bulk_in_found || !bulk_out_found) { |
2954 | err ("Error - the proper endpoints were not found!"); | 3169 | err("Error - the proper endpoints were not found!"); |
2955 | return -ENODEV; | 3170 | return -ENODEV; |
2956 | } | 3171 | } |
2957 | 3172 | ||
2958 | /* start interrupt read for this edgeport this interrupt will | 3173 | /* start interrupt read for this edgeport this interrupt will |
2959 | * continue as long as the edgeport is connected */ | 3174 | * continue as long as the edgeport is connected */ |
2960 | response = usb_submit_urb(edge_serial->interrupt_read_urb, GFP_KERNEL); | 3175 | response = usb_submit_urb(edge_serial->interrupt_read_urb, |
3176 | GFP_KERNEL); | ||
2961 | if (response) | 3177 | if (response) |
2962 | err("%s - Error %d submitting control urb", __func__, response); | 3178 | err("%s - Error %d submitting control urb", |
3179 | __func__, response); | ||
2963 | } | 3180 | } |
2964 | return response; | 3181 | return response; |
2965 | } | 3182 | } |
@@ -2969,7 +3186,7 @@ static int edge_startup (struct usb_serial *serial) | |||
2969 | * edge_shutdown | 3186 | * edge_shutdown |
2970 | * This function is called whenever the device is removed from the usb bus. | 3187 | * This function is called whenever the device is removed from the usb bus. |
2971 | ****************************************************************************/ | 3188 | ****************************************************************************/ |
2972 | static void edge_shutdown (struct usb_serial *serial) | 3189 | static void edge_shutdown(struct usb_serial *serial) |
2973 | { | 3190 | { |
2974 | struct edgeport_serial *edge_serial = usb_get_serial_data(serial); | 3191 | struct edgeport_serial *edge_serial = usb_get_serial_data(serial); |
2975 | int i; | 3192 | int i; |
@@ -2977,8 +3194,8 @@ static void edge_shutdown (struct usb_serial *serial) | |||
2977 | dbg("%s", __func__); | 3194 | dbg("%s", __func__); |
2978 | 3195 | ||
2979 | /* stop reads and writes on all ports */ | 3196 | /* stop reads and writes on all ports */ |
2980 | for (i=0; i < serial->num_ports; ++i) { | 3197 | for (i = 0; i < serial->num_ports; ++i) { |
2981 | kfree (usb_get_serial_port_data(serial->port[i])); | 3198 | kfree(usb_get_serial_port_data(serial->port[i])); |
2982 | usb_set_serial_port_data(serial->port[i], NULL); | 3199 | usb_set_serial_port_data(serial->port[i], NULL); |
2983 | } | 3200 | } |
2984 | /* free up our endpoint stuff */ | 3201 | /* free up our endpoint stuff */ |
@@ -3018,7 +3235,7 @@ static int __init edgeport_init(void) | |||
3018 | if (retval) | 3235 | if (retval) |
3019 | goto failed_epic_device_register; | 3236 | goto failed_epic_device_register; |
3020 | retval = usb_register(&io_driver); | 3237 | retval = usb_register(&io_driver); |
3021 | if (retval) | 3238 | if (retval) |
3022 | goto failed_usb_register; | 3239 | goto failed_usb_register; |
3023 | atomic_set(&CmdUrbs, 0); | 3240 | atomic_set(&CmdUrbs, 0); |
3024 | info(DRIVER_DESC " " DRIVER_VERSION); | 3241 | info(DRIVER_DESC " " DRIVER_VERSION); |
@@ -3043,19 +3260,19 @@ failed_2port_device_register: | |||
3043 | ****************************************************************************/ | 3260 | ****************************************************************************/ |
3044 | static void __exit edgeport_exit (void) | 3261 | static void __exit edgeport_exit (void) |
3045 | { | 3262 | { |
3046 | usb_deregister (&io_driver); | 3263 | usb_deregister(&io_driver); |
3047 | usb_serial_deregister (&edgeport_2port_device); | 3264 | usb_serial_deregister(&edgeport_2port_device); |
3048 | usb_serial_deregister (&edgeport_4port_device); | 3265 | usb_serial_deregister(&edgeport_4port_device); |
3049 | usb_serial_deregister (&edgeport_8port_device); | 3266 | usb_serial_deregister(&edgeport_8port_device); |
3050 | usb_serial_deregister (&epic_device); | 3267 | usb_serial_deregister(&epic_device); |
3051 | } | 3268 | } |
3052 | 3269 | ||
3053 | module_init(edgeport_init); | 3270 | module_init(edgeport_init); |
3054 | module_exit(edgeport_exit); | 3271 | module_exit(edgeport_exit); |
3055 | 3272 | ||
3056 | /* Module information */ | 3273 | /* Module information */ |
3057 | MODULE_AUTHOR( DRIVER_AUTHOR ); | 3274 | MODULE_AUTHOR(DRIVER_AUTHOR); |
3058 | MODULE_DESCRIPTION( DRIVER_DESC ); | 3275 | MODULE_DESCRIPTION(DRIVER_DESC); |
3059 | MODULE_LICENSE("GPL"); | 3276 | MODULE_LICENSE("GPL"); |
3060 | MODULE_FIRMWARE("edgeport/boot.fw"); | 3277 | MODULE_FIRMWARE("edgeport/boot.fw"); |
3061 | MODULE_FIRMWARE("edgeport/boot2.fw"); | 3278 | MODULE_FIRMWARE("edgeport/boot2.fw"); |