diff options
Diffstat (limited to 'drivers/usb/serial/whiteheat.c')
-rw-r--r-- | drivers/usb/serial/whiteheat.c | 518 |
1 files changed, 299 insertions, 219 deletions
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c index f07e8a4c1f3d..3a9d14384a43 100644 --- a/drivers/usb/serial/whiteheat.c +++ b/drivers/usb/serial/whiteheat.c | |||
@@ -12,29 +12,31 @@ | |||
12 | * the Free Software Foundation; either version 2 of the License, or | 12 | * the Free Software Foundation; either version 2 of the License, or |
13 | * (at your option) any later version. | 13 | * (at your option) any later version. |
14 | * | 14 | * |
15 | * See Documentation/usb/usb-serial.txt for more information on using this driver | 15 | * See Documentation/usb/usb-serial.txt for more information on using this |
16 | * driver | ||
16 | * | 17 | * |
17 | * (10/09/2002) Stuart MacDonald (stuartm@connecttech.com) | 18 | * (10/09/2002) Stuart MacDonald (stuartm@connecttech.com) |
18 | * Upgrade to full working driver | 19 | * Upgrade to full working driver |
19 | * | 20 | * |
20 | * (05/30/2001) gkh | 21 | * (05/30/2001) gkh |
21 | * switched from using spinlock to a semaphore, which fixes lots of problems. | 22 | * switched from using spinlock to a semaphore, which fixes lots of |
23 | * problems. | ||
22 | * | 24 | * |
23 | * (04/08/2001) gb | 25 | * (04/08/2001) gb |
24 | * Identify version on module load. | 26 | * Identify version on module load. |
25 | * | 27 | * |
26 | * 2001_Mar_19 gkh | 28 | * 2001_Mar_19 gkh |
27 | * Fixed MOD_INC and MOD_DEC logic, the ability to open a port more | 29 | * Fixed MOD_INC and MOD_DEC logic, the ability to open a port more |
28 | * than once, and the got the proper usb_device_id table entries so | 30 | * than once, and the got the proper usb_device_id table entries so |
29 | * the driver works again. | 31 | * the driver works again. |
30 | * | 32 | * |
31 | * (11/01/2000) Adam J. Richter | 33 | * (11/01/2000) Adam J. Richter |
32 | * usb_device_id table support | 34 | * usb_device_id table support |
33 | * | 35 | * |
34 | * (10/05/2000) gkh | 36 | * (10/05/2000) gkh |
35 | * Fixed bug with urb->dev not being set properly, now that the usb | 37 | * Fixed bug with urb->dev not being set properly, now that the usb |
36 | * core needs it. | 38 | * core needs it. |
37 | * | 39 | * |
38 | * (10/03/2000) smd | 40 | * (10/03/2000) smd |
39 | * firmware is improved to guard against crap sent to device | 41 | * firmware is improved to guard against crap sent to device |
40 | * firmware now replies CMD_FAILURE on bad things | 42 | * firmware now replies CMD_FAILURE on bad things |
@@ -52,9 +54,9 @@ | |||
52 | * Fixed bug with port->minor that was found by Al Borchers | 54 | * Fixed bug with port->minor that was found by Al Borchers |
53 | * | 55 | * |
54 | * (07/04/2000) gkh | 56 | * (07/04/2000) gkh |
55 | * Added support for port settings. Baud rate can now be changed. Line signals | 57 | * Added support for port settings. Baud rate can now be changed. Line |
56 | * are not transferred to and from the tty layer yet, but things seem to be | 58 | * signals are not transferred to and from the tty layer yet, but things |
57 | * working well now. | 59 | * seem to be working well now. |
58 | * | 60 | * |
59 | * (05/04/2000) gkh | 61 | * (05/04/2000) gkh |
60 | * First cut at open and close commands. Data can flow through the ports at | 62 | * First cut at open and close commands. Data can flow through the ports at |
@@ -62,7 +64,7 @@ | |||
62 | * | 64 | * |
63 | * (03/26/2000) gkh | 65 | * (03/26/2000) gkh |
64 | * Split driver up into device specific pieces. | 66 | * Split driver up into device specific pieces. |
65 | * | 67 | * |
66 | */ | 68 | */ |
67 | 69 | ||
68 | #include <linux/kernel.h> | 70 | #include <linux/kernel.h> |
@@ -75,13 +77,14 @@ | |||
75 | #include <linux/module.h> | 77 | #include <linux/module.h> |
76 | #include <linux/spinlock.h> | 78 | #include <linux/spinlock.h> |
77 | #include <linux/mutex.h> | 79 | #include <linux/mutex.h> |
78 | #include <asm/uaccess.h> | 80 | #include <linux/uaccess.h> |
79 | #include <asm/termbits.h> | 81 | #include <asm/termbits.h> |
80 | #include <linux/usb.h> | 82 | #include <linux/usb.h> |
81 | #include <linux/serial_reg.h> | 83 | #include <linux/serial_reg.h> |
82 | #include <linux/serial.h> | 84 | #include <linux/serial.h> |
83 | #include <linux/usb/serial.h> | 85 | #include <linux/usb/serial.h> |
84 | #include "whiteheat_fw.h" /* firmware for the ConnectTech WhiteHEAT device */ | 86 | #include <linux/firmware.h> |
87 | #include <linux/ihex.h> | ||
85 | #include "whiteheat.h" /* WhiteHEAT specific commands */ | 88 | #include "whiteheat.h" /* WhiteHEAT specific commands */ |
86 | 89 | ||
87 | static int debug; | 90 | static int debug; |
@@ -124,7 +127,7 @@ static struct usb_device_id id_table_combined [] = { | |||
124 | { } /* Terminating entry */ | 127 | { } /* Terminating entry */ |
125 | }; | 128 | }; |
126 | 129 | ||
127 | MODULE_DEVICE_TABLE (usb, id_table_combined); | 130 | MODULE_DEVICE_TABLE(usb, id_table_combined); |
128 | 131 | ||
129 | static struct usb_driver whiteheat_driver = { | 132 | static struct usb_driver whiteheat_driver = { |
130 | .name = "whiteheat", | 133 | .name = "whiteheat", |
@@ -135,26 +138,34 @@ static struct usb_driver whiteheat_driver = { | |||
135 | }; | 138 | }; |
136 | 139 | ||
137 | /* function prototypes for the Connect Tech WhiteHEAT prerenumeration device */ | 140 | /* function prototypes for the Connect Tech WhiteHEAT prerenumeration device */ |
138 | static int whiteheat_firmware_download (struct usb_serial *serial, const struct usb_device_id *id); | 141 | static int whiteheat_firmware_download(struct usb_serial *serial, |
139 | static int whiteheat_firmware_attach (struct usb_serial *serial); | 142 | const struct usb_device_id *id); |
143 | static int whiteheat_firmware_attach(struct usb_serial *serial); | ||
140 | 144 | ||
141 | /* function prototypes for the Connect Tech WhiteHEAT serial converter */ | 145 | /* function prototypes for the Connect Tech WhiteHEAT serial converter */ |
142 | static int whiteheat_attach (struct usb_serial *serial); | 146 | static int whiteheat_attach(struct usb_serial *serial); |
143 | static void whiteheat_shutdown (struct usb_serial *serial); | 147 | static void whiteheat_shutdown(struct usb_serial *serial); |
144 | static int whiteheat_open (struct usb_serial_port *port, struct file *filp); | 148 | static int whiteheat_open(struct tty_struct *tty, |
145 | static void whiteheat_close (struct usb_serial_port *port, struct file *filp); | 149 | struct usb_serial_port *port, struct file *filp); |
146 | static int whiteheat_write (struct usb_serial_port *port, const unsigned char *buf, int count); | 150 | static void whiteheat_close(struct tty_struct *tty, |
147 | static int whiteheat_write_room (struct usb_serial_port *port); | 151 | struct usb_serial_port *port, struct file *filp); |
148 | static int whiteheat_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); | 152 | static int whiteheat_write(struct tty_struct *tty, |
149 | static void whiteheat_set_termios (struct usb_serial_port *port, struct ktermios * old); | 153 | struct usb_serial_port *port, |
150 | static int whiteheat_tiocmget (struct usb_serial_port *port, struct file *file); | 154 | const unsigned char *buf, int count); |
151 | static int whiteheat_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear); | 155 | static int whiteheat_write_room(struct tty_struct *tty); |
152 | static void whiteheat_break_ctl (struct usb_serial_port *port, int break_state); | 156 | static int whiteheat_ioctl(struct tty_struct *tty, struct file *file, |
153 | static int whiteheat_chars_in_buffer (struct usb_serial_port *port); | 157 | unsigned int cmd, unsigned long arg); |
154 | static void whiteheat_throttle (struct usb_serial_port *port); | 158 | static void whiteheat_set_termios(struct tty_struct *tty, |
155 | static void whiteheat_unthrottle (struct usb_serial_port *port); | 159 | struct usb_serial_port *port, struct ktermios *old); |
156 | static void whiteheat_read_callback (struct urb *urb); | 160 | static int whiteheat_tiocmget(struct tty_struct *tty, struct file *file); |
157 | static void whiteheat_write_callback (struct urb *urb); | 161 | static int whiteheat_tiocmset(struct tty_struct *tty, struct file *file, |
162 | unsigned int set, unsigned int clear); | ||
163 | static void whiteheat_break_ctl(struct tty_struct *tty, int break_state); | ||
164 | static int whiteheat_chars_in_buffer(struct tty_struct *tty); | ||
165 | static void whiteheat_throttle(struct tty_struct *tty); | ||
166 | static void whiteheat_unthrottle(struct tty_struct *tty); | ||
167 | static void whiteheat_read_callback(struct urb *urb); | ||
168 | static void whiteheat_write_callback(struct urb *urb); | ||
158 | 169 | ||
159 | static struct usb_serial_driver whiteheat_fake_device = { | 170 | static struct usb_serial_driver whiteheat_fake_device = { |
160 | .driver = { | 171 | .driver = { |
@@ -201,7 +212,9 @@ struct whiteheat_command_private { | |||
201 | struct mutex mutex; | 212 | struct mutex mutex; |
202 | __u8 port_running; | 213 | __u8 port_running; |
203 | __u8 command_finished; | 214 | __u8 command_finished; |
204 | wait_queue_head_t wait_command; /* for handling sleeping while waiting for a command to finish */ | 215 | wait_queue_head_t wait_command; /* for handling sleeping whilst |
216 | waiting for a command to | ||
217 | finish */ | ||
205 | __u8 result_buffer[64]; | 218 | __u8 result_buffer[64]; |
206 | }; | 219 | }; |
207 | 220 | ||
@@ -238,14 +251,16 @@ static void command_port_write_callback(struct urb *urb); | |||
238 | static void command_port_read_callback(struct urb *urb); | 251 | static void command_port_read_callback(struct urb *urb); |
239 | 252 | ||
240 | static int start_port_read(struct usb_serial_port *port); | 253 | static int start_port_read(struct usb_serial_port *port); |
241 | static struct whiteheat_urb_wrap *urb_to_wrap(struct urb *urb, struct list_head *head); | 254 | static struct whiteheat_urb_wrap *urb_to_wrap(struct urb *urb, |
255 | struct list_head *head); | ||
242 | static struct list_head *list_first(struct list_head *head); | 256 | static struct list_head *list_first(struct list_head *head); |
243 | static void rx_data_softint(struct work_struct *work); | 257 | static void rx_data_softint(struct work_struct *work); |
244 | 258 | ||
245 | static int firm_send_command(struct usb_serial_port *port, __u8 command, __u8 *data, __u8 datasize); | 259 | static int firm_send_command(struct usb_serial_port *port, __u8 command, |
260 | __u8 *data, __u8 datasize); | ||
246 | static int firm_open(struct usb_serial_port *port); | 261 | static int firm_open(struct usb_serial_port *port); |
247 | static int firm_close(struct usb_serial_port *port); | 262 | static int firm_close(struct usb_serial_port *port); |
248 | static int firm_setup_port(struct usb_serial_port *port); | 263 | static int firm_setup_port(struct tty_struct *tty); |
249 | static int firm_set_rts(struct usb_serial_port *port, __u8 onoff); | 264 | static int firm_set_rts(struct usb_serial_port *port, __u8 onoff); |
250 | static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff); | 265 | static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff); |
251 | static int firm_set_break(struct usb_serial_port *port, __u8 onoff); | 266 | static int firm_set_break(struct usb_serial_port *port, __u8 onoff); |
@@ -277,65 +292,85 @@ static int firm_report_tx_done(struct usb_serial_port *port); | |||
277 | - device renumerated itself and comes up as new device id with all | 292 | - device renumerated itself and comes up as new device id with all |
278 | firmware download completed. | 293 | firmware download completed. |
279 | */ | 294 | */ |
280 | static int whiteheat_firmware_download (struct usb_serial *serial, const struct usb_device_id *id) | 295 | static int whiteheat_firmware_download(struct usb_serial *serial, |
296 | const struct usb_device_id *id) | ||
281 | { | 297 | { |
282 | int response; | 298 | int response, ret = -ENOENT; |
283 | const struct whiteheat_hex_record *record; | 299 | const struct firmware *loader_fw = NULL, *firmware_fw = NULL; |
284 | 300 | const struct ihex_binrec *record; | |
301 | |||
285 | dbg("%s", __func__); | 302 | dbg("%s", __func__); |
286 | 303 | ||
304 | if (request_ihex_firmware(&firmware_fw, "whiteheat.fw", | ||
305 | &serial->dev->dev)) { | ||
306 | err("%s - request \"whiteheat.fw\" failed", __func__); | ||
307 | goto out; | ||
308 | } | ||
309 | if (request_ihex_firmware(&loader_fw, "whiteheat_loader.fw", | ||
310 | &serial->dev->dev)) { | ||
311 | err("%s - request \"whiteheat_loader.fw\" failed", __func__); | ||
312 | goto out; | ||
313 | } | ||
314 | ret = 0; | ||
287 | response = ezusb_set_reset (serial, 1); | 315 | response = ezusb_set_reset (serial, 1); |
288 | 316 | ||
289 | record = &whiteheat_loader[0]; | 317 | record = (const struct ihex_binrec *)loader_fw->data; |
290 | while (record->address != 0xffff) { | 318 | while (record) { |
291 | response = ezusb_writememory (serial, record->address, | 319 | response = ezusb_writememory (serial, be32_to_cpu(record->addr), |
292 | (unsigned char *)record->data, record->data_size, 0xa0); | 320 | (unsigned char *)record->data, |
321 | be16_to_cpu(record->len), 0xa0); | ||
293 | if (response < 0) { | 322 | if (response < 0) { |
294 | err("%s - ezusb_writememory failed for loader (%d %04X %p %d)", | 323 | err("%s - ezusb_writememory failed for loader (%d %04X %p %d)", |
295 | __func__, response, record->address, record->data, record->data_size); | 324 | __func__, response, be32_to_cpu(record->addr), |
325 | record->data, be16_to_cpu(record->len)); | ||
296 | break; | 326 | break; |
297 | } | 327 | } |
298 | ++record; | 328 | record = ihex_next_binrec(record); |
299 | } | 329 | } |
300 | 330 | ||
301 | response = ezusb_set_reset (serial, 0); | 331 | response = ezusb_set_reset(serial, 0); |
302 | 332 | ||
303 | record = &whiteheat_firmware[0]; | 333 | record = (const struct ihex_binrec *)firmware_fw->data; |
304 | while (record->address < 0x1b40) { | 334 | while (record && be32_to_cpu(record->addr) < 0x1b40) |
305 | ++record; | 335 | record = ihex_next_binrec(record); |
306 | } | 336 | while (record) { |
307 | while (record->address != 0xffff) { | 337 | response = ezusb_writememory (serial, be32_to_cpu(record->addr), |
308 | response = ezusb_writememory (serial, record->address, | 338 | (unsigned char *)record->data, |
309 | (unsigned char *)record->data, record->data_size, 0xa3); | 339 | be16_to_cpu(record->len), 0xa3); |
310 | if (response < 0) { | 340 | if (response < 0) { |
311 | err("%s - ezusb_writememory failed for first firmware step (%d %04X %p %d)", | 341 | err("%s - ezusb_writememory failed for first firmware step (%d %04X %p %d)", |
312 | __func__, response, record->address, record->data, record->data_size); | 342 | __func__, response, be32_to_cpu(record->addr), |
343 | record->data, be16_to_cpu(record->len)); | ||
313 | break; | 344 | break; |
314 | } | 345 | } |
315 | ++record; | 346 | ++record; |
316 | } | 347 | } |
317 | |||
318 | response = ezusb_set_reset (serial, 1); | ||
319 | 348 | ||
320 | record = &whiteheat_firmware[0]; | 349 | response = ezusb_set_reset(serial, 1); |
321 | while (record->address < 0x1b40) { | 350 | |
322 | response = ezusb_writememory (serial, record->address, | 351 | record = (const struct ihex_binrec *)firmware_fw->data; |
323 | (unsigned char *)record->data, record->data_size, 0xa0); | 352 | while (record && be32_to_cpu(record->addr) < 0x1b40) { |
353 | response = ezusb_writememory (serial, be32_to_cpu(record->addr), | ||
354 | (unsigned char *)record->data, | ||
355 | be16_to_cpu(record->len), 0xa0); | ||
324 | if (response < 0) { | 356 | if (response < 0) { |
325 | err("%s - ezusb_writememory failed for second firmware step (%d %04X %p %d)", | 357 | err("%s - ezusb_writememory failed for second firmware step (%d %04X %p %d)", |
326 | __func__, response, record->address, record->data, record->data_size); | 358 | __func__, response, be32_to_cpu(record->addr), |
359 | record->data, be16_to_cpu(record->len)); | ||
327 | break; | 360 | break; |
328 | } | 361 | } |
329 | ++record; | 362 | ++record; |
330 | } | 363 | } |
331 | 364 | ret = 0; | |
332 | response = ezusb_set_reset (serial, 0); | 365 | response = ezusb_set_reset (serial, 0); |
333 | 366 | out: | |
334 | return 0; | 367 | release_firmware(loader_fw); |
368 | release_firmware(firmware_fw); | ||
369 | return ret; | ||
335 | } | 370 | } |
336 | 371 | ||
337 | 372 | ||
338 | static int whiteheat_firmware_attach (struct usb_serial *serial) | 373 | static int whiteheat_firmware_attach(struct usb_serial *serial) |
339 | { | 374 | { |
340 | /* We want this device to fail to have a driver assigned to it */ | 375 | /* We want this device to fail to have a driver assigned to it */ |
341 | return 1; | 376 | return 1; |
@@ -345,7 +380,7 @@ static int whiteheat_firmware_attach (struct usb_serial *serial) | |||
345 | /***************************************************************************** | 380 | /***************************************************************************** |
346 | * Connect Tech's White Heat serial driver functions | 381 | * Connect Tech's White Heat serial driver functions |
347 | *****************************************************************************/ | 382 | *****************************************************************************/ |
348 | static int whiteheat_attach (struct usb_serial *serial) | 383 | static int whiteheat_attach(struct usb_serial *serial) |
349 | { | 384 | { |
350 | struct usb_serial_port *command_port; | 385 | struct usb_serial_port *command_port; |
351 | struct whiteheat_command_private *command_info; | 386 | struct whiteheat_command_private *command_info; |
@@ -366,43 +401,52 @@ static int whiteheat_attach (struct usb_serial *serial) | |||
366 | 401 | ||
367 | command_port = serial->port[COMMAND_PORT]; | 402 | command_port = serial->port[COMMAND_PORT]; |
368 | 403 | ||
369 | pipe = usb_sndbulkpipe (serial->dev, command_port->bulk_out_endpointAddress); | 404 | pipe = usb_sndbulkpipe(serial->dev, |
405 | command_port->bulk_out_endpointAddress); | ||
370 | command = kmalloc(2, GFP_KERNEL); | 406 | command = kmalloc(2, GFP_KERNEL); |
371 | if (!command) | 407 | if (!command) |
372 | goto no_command_buffer; | 408 | goto no_command_buffer; |
373 | command[0] = WHITEHEAT_GET_HW_INFO; | 409 | command[0] = WHITEHEAT_GET_HW_INFO; |
374 | command[1] = 0; | 410 | command[1] = 0; |
375 | 411 | ||
376 | result = kmalloc(sizeof(*hw_info) + 1, GFP_KERNEL); | 412 | result = kmalloc(sizeof(*hw_info) + 1, GFP_KERNEL); |
377 | if (!result) | 413 | if (!result) |
378 | goto no_result_buffer; | 414 | goto no_result_buffer; |
379 | /* | 415 | /* |
380 | * When the module is reloaded the firmware is still there and | 416 | * When the module is reloaded the firmware is still there and |
381 | * the endpoints are still in the usb core unchanged. This is the | 417 | * the endpoints are still in the usb core unchanged. This is the |
382 | * unlinking bug in disguise. Same for the call below. | 418 | * unlinking bug in disguise. Same for the call below. |
383 | */ | 419 | */ |
384 | usb_clear_halt(serial->dev, pipe); | 420 | usb_clear_halt(serial->dev, pipe); |
385 | ret = usb_bulk_msg (serial->dev, pipe, command, 2, &alen, COMMAND_TIMEOUT_MS); | 421 | ret = usb_bulk_msg(serial->dev, pipe, command, 2, |
422 | &alen, COMMAND_TIMEOUT_MS); | ||
386 | if (ret) { | 423 | if (ret) { |
387 | err("%s: Couldn't send command [%d]", serial->type->description, ret); | 424 | err("%s: Couldn't send command [%d]", |
425 | serial->type->description, ret); | ||
388 | goto no_firmware; | 426 | goto no_firmware; |
389 | } else if (alen != 2) { | 427 | } else if (alen != 2) { |
390 | err("%s: Send command incomplete [%d]", serial->type->description, alen); | 428 | err("%s: Send command incomplete [%d]", |
429 | serial->type->description, alen); | ||
391 | goto no_firmware; | 430 | goto no_firmware; |
392 | } | 431 | } |
393 | 432 | ||
394 | pipe = usb_rcvbulkpipe (serial->dev, command_port->bulk_in_endpointAddress); | 433 | pipe = usb_rcvbulkpipe(serial->dev, |
434 | command_port->bulk_in_endpointAddress); | ||
395 | /* See the comment on the usb_clear_halt() above */ | 435 | /* See the comment on the usb_clear_halt() above */ |
396 | usb_clear_halt(serial->dev, pipe); | 436 | usb_clear_halt(serial->dev, pipe); |
397 | ret = usb_bulk_msg (serial->dev, pipe, result, sizeof(*hw_info) + 1, &alen, COMMAND_TIMEOUT_MS); | 437 | ret = usb_bulk_msg(serial->dev, pipe, result, |
438 | sizeof(*hw_info) + 1, &alen, COMMAND_TIMEOUT_MS); | ||
398 | if (ret) { | 439 | if (ret) { |
399 | err("%s: Couldn't get results [%d]", serial->type->description, ret); | 440 | err("%s: Couldn't get results [%d]", |
441 | serial->type->description, ret); | ||
400 | goto no_firmware; | 442 | goto no_firmware; |
401 | } else if (alen != sizeof(*hw_info) + 1) { | 443 | } else if (alen != sizeof(*hw_info) + 1) { |
402 | err("%s: Get results incomplete [%d]", serial->type->description, alen); | 444 | err("%s: Get results incomplete [%d]", |
445 | serial->type->description, alen); | ||
403 | goto no_firmware; | 446 | goto no_firmware; |
404 | } else if (result[0] != command[0]) { | 447 | } else if (result[0] != command[0]) { |
405 | err("%s: Command failed [%d]", serial->type->description, result[0]); | 448 | err("%s: Command failed [%d]", |
449 | serial->type->description, result[0]); | ||
406 | goto no_firmware; | 450 | goto no_firmware; |
407 | } | 451 | } |
408 | 452 | ||
@@ -416,7 +460,8 @@ static int whiteheat_attach (struct usb_serial *serial) | |||
416 | 460 | ||
417 | info = kmalloc(sizeof(struct whiteheat_private), GFP_KERNEL); | 461 | info = kmalloc(sizeof(struct whiteheat_private), GFP_KERNEL); |
418 | if (info == NULL) { | 462 | if (info == NULL) { |
419 | err("%s: Out of memory for port structures\n", serial->type->description); | 463 | err("%s: Out of memory for port structures\n", |
464 | serial->type->description); | ||
420 | goto no_private; | 465 | goto no_private; |
421 | } | 466 | } |
422 | 467 | ||
@@ -486,9 +531,11 @@ static int whiteheat_attach (struct usb_serial *serial) | |||
486 | usb_set_serial_port_data(port, info); | 531 | usb_set_serial_port_data(port, info); |
487 | } | 532 | } |
488 | 533 | ||
489 | command_info = kmalloc(sizeof(struct whiteheat_command_private), GFP_KERNEL); | 534 | command_info = kmalloc(sizeof(struct whiteheat_command_private), |
535 | GFP_KERNEL); | ||
490 | if (command_info == NULL) { | 536 | if (command_info == NULL) { |
491 | err("%s: Out of memory for port structures\n", serial->type->description); | 537 | err("%s: Out of memory for port structures\n", |
538 | serial->type->description); | ||
492 | goto no_command_private; | 539 | goto no_command_private; |
493 | } | 540 | } |
494 | 541 | ||
@@ -505,9 +552,12 @@ static int whiteheat_attach (struct usb_serial *serial) | |||
505 | 552 | ||
506 | no_firmware: | 553 | no_firmware: |
507 | /* Firmware likely not running */ | 554 | /* Firmware likely not running */ |
508 | err("%s: Unable to retrieve firmware version, try replugging\n", serial->type->description); | 555 | err("%s: Unable to retrieve firmware version, try replugging\n", |
509 | err("%s: If the firmware is not running (status led not blinking)\n", serial->type->description); | 556 | serial->type->description); |
510 | err("%s: please contact support@connecttech.com\n", serial->type->description); | 557 | err("%s: If the firmware is not running (status led not blinking)\n", |
558 | serial->type->description); | ||
559 | err("%s: please contact support@connecttech.com\n", | ||
560 | serial->type->description); | ||
511 | kfree(result); | 561 | kfree(result); |
512 | return -ENODEV; | 562 | return -ENODEV; |
513 | 563 | ||
@@ -550,7 +600,7 @@ no_command_buffer: | |||
550 | } | 600 | } |
551 | 601 | ||
552 | 602 | ||
553 | static void whiteheat_shutdown (struct usb_serial *serial) | 603 | static void whiteheat_shutdown(struct usb_serial *serial) |
554 | { | 604 | { |
555 | struct usb_serial_port *command_port; | 605 | struct usb_serial_port *command_port; |
556 | struct usb_serial_port *port; | 606 | struct usb_serial_port *port; |
@@ -565,7 +615,7 @@ static void whiteheat_shutdown (struct usb_serial *serial) | |||
565 | 615 | ||
566 | /* free up our private data for our command port */ | 616 | /* free up our private data for our command port */ |
567 | command_port = serial->port[COMMAND_PORT]; | 617 | command_port = serial->port[COMMAND_PORT]; |
568 | kfree (usb_get_serial_port_data(command_port)); | 618 | kfree(usb_get_serial_port_data(command_port)); |
569 | 619 | ||
570 | for (i = 0; i < serial->num_ports; i++) { | 620 | for (i = 0; i < serial->num_ports; i++) { |
571 | port = serial->port[i]; | 621 | port = serial->port[i]; |
@@ -592,11 +642,10 @@ static void whiteheat_shutdown (struct usb_serial *serial) | |||
592 | return; | 642 | return; |
593 | } | 643 | } |
594 | 644 | ||
595 | 645 | static int whiteheat_open(struct tty_struct *tty, | |
596 | static int whiteheat_open (struct usb_serial_port *port, struct file *filp) | 646 | struct usb_serial_port *port, struct file *filp) |
597 | { | 647 | { |
598 | int retval = 0; | 648 | int retval = 0; |
599 | struct ktermios old_term; | ||
600 | 649 | ||
601 | dbg("%s - port %d", __func__, port->number); | 650 | dbg("%s - port %d", __func__, port->number); |
602 | 651 | ||
@@ -604,7 +653,8 @@ static int whiteheat_open (struct usb_serial_port *port, struct file *filp) | |||
604 | if (retval) | 653 | if (retval) |
605 | goto exit; | 654 | goto exit; |
606 | 655 | ||
607 | port->tty->low_latency = 1; | 656 | if (tty) |
657 | tty->low_latency = 1; | ||
608 | 658 | ||
609 | /* send an open port command */ | 659 | /* send an open port command */ |
610 | retval = firm_open(port); | 660 | retval = firm_open(port); |
@@ -620,9 +670,8 @@ static int whiteheat_open (struct usb_serial_port *port, struct file *filp) | |||
620 | goto exit; | 670 | goto exit; |
621 | } | 671 | } |
622 | 672 | ||
623 | old_term.c_cflag = ~port->tty->termios->c_cflag; | 673 | if (tty) |
624 | old_term.c_iflag = ~port->tty->termios->c_iflag; | 674 | firm_setup_port(tty); |
625 | whiteheat_set_termios(port, &old_term); | ||
626 | 675 | ||
627 | /* Work around HCD bugs */ | 676 | /* Work around HCD bugs */ |
628 | usb_clear_halt(port->serial->dev, port->read_urb->pipe); | 677 | usb_clear_halt(port->serial->dev, port->read_urb->pipe); |
@@ -631,7 +680,8 @@ static int whiteheat_open (struct usb_serial_port *port, struct file *filp) | |||
631 | /* Start reading from the device */ | 680 | /* Start reading from the device */ |
632 | retval = start_port_read(port); | 681 | retval = start_port_read(port); |
633 | if (retval) { | 682 | if (retval) { |
634 | err("%s - failed submitting read urb, error %d", __func__, retval); | 683 | err("%s - failed submitting read urb, error %d", |
684 | __func__, retval); | ||
635 | firm_close(port); | 685 | firm_close(port); |
636 | stop_command_port(port->serial); | 686 | stop_command_port(port->serial); |
637 | goto exit; | 687 | goto exit; |
@@ -643,7 +693,8 @@ exit: | |||
643 | } | 693 | } |
644 | 694 | ||
645 | 695 | ||
646 | static void whiteheat_close(struct usb_serial_port *port, struct file * filp) | 696 | static void whiteheat_close(struct tty_struct *tty, |
697 | struct usb_serial_port *port, struct file *filp) | ||
647 | { | 698 | { |
648 | struct whiteheat_private *info = usb_get_serial_port_data(port); | 699 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
649 | struct whiteheat_urb_wrap *wrap; | 700 | struct whiteheat_urb_wrap *wrap; |
@@ -661,7 +712,7 @@ static void whiteheat_close(struct usb_serial_port *port, struct file * filp) | |||
661 | } | 712 | } |
662 | mutex_unlock(&port->serial->disc_mutex); | 713 | mutex_unlock(&port->serial->disc_mutex); |
663 | 714 | ||
664 | port->tty->closing = 1; | 715 | tty->closing = 1; |
665 | 716 | ||
666 | /* | 717 | /* |
667 | * Not currently in use; tty_wait_until_sent() calls | 718 | * Not currently in use; tty_wait_until_sent() calls |
@@ -669,12 +720,12 @@ static void whiteheat_close(struct usb_serial_port *port, struct file * filp) | |||
669 | * acquisition. This should be fixed at some point. Greg's been | 720 | * acquisition. This should be fixed at some point. Greg's been |
670 | * notified. | 721 | * notified. |
671 | if ((filp->f_flags & (O_NDELAY | O_NONBLOCK)) == 0) { | 722 | if ((filp->f_flags & (O_NDELAY | O_NONBLOCK)) == 0) { |
672 | tty_wait_until_sent(port->tty, CLOSING_DELAY); | 723 | tty_wait_until_sent(tty, CLOSING_DELAY); |
673 | } | 724 | } |
674 | */ | 725 | */ |
675 | 726 | ||
676 | tty_driver_flush_buffer(port->tty); | 727 | tty_driver_flush_buffer(tty); |
677 | tty_ldisc_flush(port->tty); | 728 | tty_ldisc_flush(tty); |
678 | 729 | ||
679 | firm_report_tx_done(port); | 730 | firm_report_tx_done(port); |
680 | 731 | ||
@@ -708,11 +759,12 @@ static void whiteheat_close(struct usb_serial_port *port, struct file * filp) | |||
708 | 759 | ||
709 | stop_command_port(port->serial); | 760 | stop_command_port(port->serial); |
710 | 761 | ||
711 | port->tty->closing = 0; | 762 | tty->closing = 0; |
712 | } | 763 | } |
713 | 764 | ||
714 | 765 | ||
715 | static int whiteheat_write(struct usb_serial_port *port, const unsigned char *buf, int count) | 766 | static int whiteheat_write(struct tty_struct *tty, |
767 | struct usb_serial_port *port, const unsigned char *buf, int count) | ||
716 | { | 768 | { |
717 | struct usb_serial *serial = port->serial; | 769 | struct usb_serial *serial = port->serial; |
718 | struct whiteheat_private *info = usb_get_serial_port_data(port); | 770 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
@@ -743,16 +795,19 @@ static int whiteheat_write(struct usb_serial_port *port, const unsigned char *bu | |||
743 | 795 | ||
744 | wrap = list_entry(tmp, struct whiteheat_urb_wrap, list); | 796 | wrap = list_entry(tmp, struct whiteheat_urb_wrap, list); |
745 | urb = wrap->urb; | 797 | urb = wrap->urb; |
746 | bytes = (count > port->bulk_out_size) ? port->bulk_out_size : count; | 798 | bytes = (count > port->bulk_out_size) ? |
747 | memcpy (urb->transfer_buffer, buf + sent, bytes); | 799 | port->bulk_out_size : count; |
800 | memcpy(urb->transfer_buffer, buf + sent, bytes); | ||
748 | 801 | ||
749 | usb_serial_debug_data(debug, &port->dev, __func__, bytes, urb->transfer_buffer); | 802 | usb_serial_debug_data(debug, &port->dev, |
803 | __func__, bytes, urb->transfer_buffer); | ||
750 | 804 | ||
751 | urb->dev = serial->dev; | 805 | urb->dev = serial->dev; |
752 | urb->transfer_buffer_length = bytes; | 806 | urb->transfer_buffer_length = bytes; |
753 | result = usb_submit_urb(urb, GFP_ATOMIC); | 807 | result = usb_submit_urb(urb, GFP_ATOMIC); |
754 | if (result) { | 808 | if (result) { |
755 | err("%s - failed submitting write urb, error %d", __func__, result); | 809 | err("%s - failed submitting write urb, error %d", |
810 | __func__, result); | ||
756 | sent = result; | 811 | sent = result; |
757 | spin_lock_irqsave(&info->lock, flags); | 812 | spin_lock_irqsave(&info->lock, flags); |
758 | list_add(tmp, &info->tx_urbs_free); | 813 | list_add(tmp, &info->tx_urbs_free); |
@@ -770,16 +825,16 @@ static int whiteheat_write(struct usb_serial_port *port, const unsigned char *bu | |||
770 | return sent; | 825 | return sent; |
771 | } | 826 | } |
772 | 827 | ||
773 | 828 | static int whiteheat_write_room(struct tty_struct *tty) | |
774 | static int whiteheat_write_room(struct usb_serial_port *port) | ||
775 | { | 829 | { |
830 | struct usb_serial_port *port = tty->driver_data; | ||
776 | struct whiteheat_private *info = usb_get_serial_port_data(port); | 831 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
777 | struct list_head *tmp; | 832 | struct list_head *tmp; |
778 | int room = 0; | 833 | int room = 0; |
779 | unsigned long flags; | 834 | unsigned long flags; |
780 | 835 | ||
781 | dbg("%s - port %d", __func__, port->number); | 836 | dbg("%s - port %d", __func__, port->number); |
782 | 837 | ||
783 | spin_lock_irqsave(&info->lock, flags); | 838 | spin_lock_irqsave(&info->lock, flags); |
784 | list_for_each(tmp, &info->tx_urbs_free) | 839 | list_for_each(tmp, &info->tx_urbs_free) |
785 | room++; | 840 | room++; |
@@ -790,9 +845,9 @@ static int whiteheat_write_room(struct usb_serial_port *port) | |||
790 | return (room); | 845 | return (room); |
791 | } | 846 | } |
792 | 847 | ||
793 | 848 | static int whiteheat_tiocmget(struct tty_struct *tty, struct file *file) | |
794 | static int whiteheat_tiocmget (struct usb_serial_port *port, struct file *file) | ||
795 | { | 849 | { |
850 | struct usb_serial_port *port = tty->driver_data; | ||
796 | struct whiteheat_private *info = usb_get_serial_port_data(port); | 851 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
797 | unsigned int modem_signals = 0; | 852 | unsigned int modem_signals = 0; |
798 | 853 | ||
@@ -807,10 +862,10 @@ static int whiteheat_tiocmget (struct usb_serial_port *port, struct file *file) | |||
807 | return modem_signals; | 862 | return modem_signals; |
808 | } | 863 | } |
809 | 864 | ||
810 | 865 | static int whiteheat_tiocmset(struct tty_struct *tty, struct file *file, | |
811 | static int whiteheat_tiocmset (struct usb_serial_port *port, struct file *file, | ||
812 | unsigned int set, unsigned int clear) | 866 | unsigned int set, unsigned int clear) |
813 | { | 867 | { |
868 | struct usb_serial_port *port = tty->driver_data; | ||
814 | struct whiteheat_private *info = usb_get_serial_port_data(port); | 869 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
815 | 870 | ||
816 | dbg("%s - port %d", __func__, port->number); | 871 | dbg("%s - port %d", __func__, port->number); |
@@ -831,65 +886,55 @@ static int whiteheat_tiocmset (struct usb_serial_port *port, struct file *file, | |||
831 | } | 886 | } |
832 | 887 | ||
833 | 888 | ||
834 | static int whiteheat_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) | 889 | static int whiteheat_ioctl(struct tty_struct *tty, struct file *file, |
890 | unsigned int cmd, unsigned long arg) | ||
835 | { | 891 | { |
892 | struct usb_serial_port *port = tty->driver_data; | ||
836 | struct serial_struct serstruct; | 893 | struct serial_struct serstruct; |
837 | void __user *user_arg = (void __user *)arg; | 894 | void __user *user_arg = (void __user *)arg; |
838 | 895 | ||
839 | dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd); | 896 | dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd); |
840 | 897 | ||
841 | switch (cmd) { | 898 | switch (cmd) { |
842 | case TIOCGSERIAL: | 899 | case TIOCGSERIAL: |
843 | memset(&serstruct, 0, sizeof(serstruct)); | 900 | memset(&serstruct, 0, sizeof(serstruct)); |
844 | serstruct.type = PORT_16654; | 901 | serstruct.type = PORT_16654; |
845 | serstruct.line = port->serial->minor; | 902 | serstruct.line = port->serial->minor; |
846 | serstruct.port = port->number; | 903 | serstruct.port = port->number; |
847 | serstruct.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ; | 904 | serstruct.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ; |
848 | serstruct.xmit_fifo_size = port->bulk_out_size; | 905 | serstruct.xmit_fifo_size = port->bulk_out_size; |
849 | serstruct.custom_divisor = 0; | 906 | serstruct.custom_divisor = 0; |
850 | serstruct.baud_base = 460800; | 907 | serstruct.baud_base = 460800; |
851 | serstruct.close_delay = CLOSING_DELAY; | 908 | serstruct.close_delay = CLOSING_DELAY; |
852 | serstruct.closing_wait = CLOSING_DELAY; | 909 | serstruct.closing_wait = CLOSING_DELAY; |
853 | 910 | ||
854 | if (copy_to_user(user_arg, &serstruct, sizeof(serstruct))) | 911 | if (copy_to_user(user_arg, &serstruct, sizeof(serstruct))) |
855 | return -EFAULT; | 912 | return -EFAULT; |
856 | 913 | break; | |
857 | break; | 914 | default: |
858 | 915 | break; | |
859 | case TIOCSSERIAL: | ||
860 | if (copy_from_user(&serstruct, user_arg, sizeof(serstruct))) | ||
861 | return -EFAULT; | ||
862 | |||
863 | /* | ||
864 | * For now this is ignored. dip sets the ASYNC_[V]HI flags | ||
865 | * but this isn't used by us at all. Maybe someone somewhere | ||
866 | * will need the custom_divisor setting. | ||
867 | */ | ||
868 | |||
869 | break; | ||
870 | |||
871 | default: | ||
872 | break; | ||
873 | } | 916 | } |
874 | 917 | ||
875 | return -ENOIOCTLCMD; | 918 | return -ENOIOCTLCMD; |
876 | } | 919 | } |
877 | 920 | ||
878 | 921 | ||
879 | static void whiteheat_set_termios(struct usb_serial_port *port, struct ktermios *old_termios) | 922 | static void whiteheat_set_termios(struct tty_struct *tty, |
923 | struct usb_serial_port *port, struct ktermios *old_termios) | ||
880 | { | 924 | { |
881 | dbg("%s -port %d", __func__, port->number); | 925 | firm_setup_port(tty); |
882 | firm_setup_port(port); | ||
883 | } | 926 | } |
884 | 927 | ||
885 | 928 | static void whiteheat_break_ctl(struct tty_struct *tty, int break_state) | |
886 | static void whiteheat_break_ctl(struct usb_serial_port *port, int break_state) { | 929 | { |
930 | struct usb_serial_port *port = tty->driver_data; | ||
887 | firm_set_break(port, break_state); | 931 | firm_set_break(port, break_state); |
888 | } | 932 | } |
889 | 933 | ||
890 | 934 | ||
891 | static int whiteheat_chars_in_buffer(struct usb_serial_port *port) | 935 | static int whiteheat_chars_in_buffer(struct tty_struct *tty) |
892 | { | 936 | { |
937 | struct usb_serial_port *port = tty->driver_data; | ||
893 | struct whiteheat_private *info = usb_get_serial_port_data(port); | 938 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
894 | struct list_head *tmp; | 939 | struct list_head *tmp; |
895 | struct whiteheat_urb_wrap *wrap; | 940 | struct whiteheat_urb_wrap *wrap; |
@@ -905,13 +950,14 @@ static int whiteheat_chars_in_buffer(struct usb_serial_port *port) | |||
905 | } | 950 | } |
906 | spin_unlock_irqrestore(&info->lock, flags); | 951 | spin_unlock_irqrestore(&info->lock, flags); |
907 | 952 | ||
908 | dbg ("%s - returns %d", __func__, chars); | 953 | dbg("%s - returns %d", __func__, chars); |
909 | return chars; | 954 | return chars; |
910 | } | 955 | } |
911 | 956 | ||
912 | 957 | ||
913 | static void whiteheat_throttle (struct usb_serial_port *port) | 958 | static void whiteheat_throttle(struct tty_struct *tty) |
914 | { | 959 | { |
960 | struct usb_serial_port *port = tty->driver_data; | ||
915 | struct whiteheat_private *info = usb_get_serial_port_data(port); | 961 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
916 | unsigned long flags; | 962 | unsigned long flags; |
917 | 963 | ||
@@ -925,8 +971,9 @@ static void whiteheat_throttle (struct usb_serial_port *port) | |||
925 | } | 971 | } |
926 | 972 | ||
927 | 973 | ||
928 | static void whiteheat_unthrottle (struct usb_serial_port *port) | 974 | static void whiteheat_unthrottle(struct tty_struct *tty) |
929 | { | 975 | { |
976 | struct usb_serial_port *port = tty->driver_data; | ||
930 | struct whiteheat_private *info = usb_get_serial_port_data(port); | 977 | struct whiteheat_private *info = usb_get_serial_port_data(port); |
931 | int actually_throttled; | 978 | int actually_throttled; |
932 | unsigned long flags; | 979 | unsigned long flags; |
@@ -973,7 +1020,7 @@ static void command_port_read_callback(struct urb *urb) | |||
973 | 1020 | ||
974 | command_info = usb_get_serial_port_data(command_port); | 1021 | command_info = usb_get_serial_port_data(command_port); |
975 | if (!command_info) { | 1022 | if (!command_info) { |
976 | dbg ("%s - command_info is NULL, exiting.", __func__); | 1023 | dbg("%s - command_info is NULL, exiting.", __func__); |
977 | return; | 1024 | return; |
978 | } | 1025 | } |
979 | if (status) { | 1026 | if (status) { |
@@ -984,7 +1031,8 @@ static void command_port_read_callback(struct urb *urb) | |||
984 | return; | 1031 | return; |
985 | } | 1032 | } |
986 | 1033 | ||
987 | usb_serial_debug_data(debug, &command_port->dev, __func__, urb->actual_length, data); | 1034 | usb_serial_debug_data(debug, &command_port->dev, |
1035 | __func__, urb->actual_length, data); | ||
988 | 1036 | ||
989 | if (data[0] == WHITEHEAT_CMD_COMPLETE) { | 1037 | if (data[0] == WHITEHEAT_CMD_COMPLETE) { |
990 | command_info->command_finished = WHITEHEAT_CMD_COMPLETE; | 1038 | command_info->command_finished = WHITEHEAT_CMD_COMPLETE; |
@@ -993,21 +1041,23 @@ static void command_port_read_callback(struct urb *urb) | |||
993 | command_info->command_finished = WHITEHEAT_CMD_FAILURE; | 1041 | command_info->command_finished = WHITEHEAT_CMD_FAILURE; |
994 | wake_up(&command_info->wait_command); | 1042 | wake_up(&command_info->wait_command); |
995 | } else if (data[0] == WHITEHEAT_EVENT) { | 1043 | } else if (data[0] == WHITEHEAT_EVENT) { |
996 | /* These are unsolicited reports from the firmware, hence no waiting command to wakeup */ | 1044 | /* These are unsolicited reports from the firmware, hence no |
1045 | waiting command to wakeup */ | ||
997 | dbg("%s - event received", __func__); | 1046 | dbg("%s - event received", __func__); |
998 | } else if (data[0] == WHITEHEAT_GET_DTR_RTS) { | 1047 | } else if (data[0] == WHITEHEAT_GET_DTR_RTS) { |
999 | memcpy(command_info->result_buffer, &data[1], urb->actual_length - 1); | 1048 | memcpy(command_info->result_buffer, &data[1], |
1049 | urb->actual_length - 1); | ||
1000 | command_info->command_finished = WHITEHEAT_CMD_COMPLETE; | 1050 | command_info->command_finished = WHITEHEAT_CMD_COMPLETE; |
1001 | wake_up(&command_info->wait_command); | 1051 | wake_up(&command_info->wait_command); |
1002 | } else { | 1052 | } else |
1003 | dbg("%s - bad reply from firmware", __func__); | 1053 | dbg("%s - bad reply from firmware", __func__); |
1004 | } | 1054 | |
1005 | |||
1006 | /* Continue trying to always read */ | 1055 | /* Continue trying to always read */ |
1007 | command_port->read_urb->dev = command_port->serial->dev; | 1056 | command_port->read_urb->dev = command_port->serial->dev; |
1008 | result = usb_submit_urb(command_port->read_urb, GFP_ATOMIC); | 1057 | result = usb_submit_urb(command_port->read_urb, GFP_ATOMIC); |
1009 | if (result) | 1058 | if (result) |
1010 | dbg("%s - failed resubmitting read urb, error %d", __func__, result); | 1059 | dbg("%s - failed resubmitting read urb, error %d", |
1060 | __func__, result); | ||
1011 | } | 1061 | } |
1012 | 1062 | ||
1013 | 1063 | ||
@@ -1040,7 +1090,8 @@ static void whiteheat_read_callback(struct urb *urb) | |||
1040 | return; | 1090 | return; |
1041 | } | 1091 | } |
1042 | 1092 | ||
1043 | usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); | 1093 | usb_serial_debug_data(debug, &port->dev, |
1094 | __func__, urb->actual_length, data); | ||
1044 | 1095 | ||
1045 | spin_lock(&info->lock); | 1096 | spin_lock(&info->lock); |
1046 | list_add_tail(&wrap->list, &info->rx_urb_q); | 1097 | list_add_tail(&wrap->list, &info->rx_urb_q); |
@@ -1087,7 +1138,8 @@ static void whiteheat_write_callback(struct urb *urb) | |||
1087 | /***************************************************************************** | 1138 | /***************************************************************************** |
1088 | * Connect Tech's White Heat firmware interface | 1139 | * Connect Tech's White Heat firmware interface |
1089 | *****************************************************************************/ | 1140 | *****************************************************************************/ |
1090 | static int firm_send_command(struct usb_serial_port *port, __u8 command, __u8 *data, __u8 datasize) | 1141 | static int firm_send_command(struct usb_serial_port *port, __u8 command, |
1142 | __u8 *data, __u8 datasize) | ||
1091 | { | 1143 | { |
1092 | struct usb_serial_port *command_port; | 1144 | struct usb_serial_port *command_port; |
1093 | struct whiteheat_command_private *command_info; | 1145 | struct whiteheat_command_private *command_info; |
@@ -1102,13 +1154,13 @@ static int firm_send_command(struct usb_serial_port *port, __u8 command, __u8 *d | |||
1102 | command_info = usb_get_serial_port_data(command_port); | 1154 | command_info = usb_get_serial_port_data(command_port); |
1103 | mutex_lock(&command_info->mutex); | 1155 | mutex_lock(&command_info->mutex); |
1104 | command_info->command_finished = false; | 1156 | command_info->command_finished = false; |
1105 | 1157 | ||
1106 | transfer_buffer = (__u8 *)command_port->write_urb->transfer_buffer; | 1158 | transfer_buffer = (__u8 *)command_port->write_urb->transfer_buffer; |
1107 | transfer_buffer[0] = command; | 1159 | transfer_buffer[0] = command; |
1108 | memcpy (&transfer_buffer[1], data, datasize); | 1160 | memcpy(&transfer_buffer[1], data, datasize); |
1109 | command_port->write_urb->transfer_buffer_length = datasize + 1; | 1161 | command_port->write_urb->transfer_buffer_length = datasize + 1; |
1110 | command_port->write_urb->dev = port->serial->dev; | 1162 | command_port->write_urb->dev = port->serial->dev; |
1111 | retval = usb_submit_urb (command_port->write_urb, GFP_NOIO); | 1163 | retval = usb_submit_urb(command_port->write_urb, GFP_NOIO); |
1112 | if (retval) { | 1164 | if (retval) { |
1113 | dbg("%s - submit urb failed", __func__); | 1165 | dbg("%s - submit urb failed", __func__); |
1114 | goto exit; | 1166 | goto exit; |
@@ -1135,51 +1187,57 @@ static int firm_send_command(struct usb_serial_port *port, __u8 command, __u8 *d | |||
1135 | if (command_info->command_finished == WHITEHEAT_CMD_COMPLETE) { | 1187 | if (command_info->command_finished == WHITEHEAT_CMD_COMPLETE) { |
1136 | dbg("%s - command completed.", __func__); | 1188 | dbg("%s - command completed.", __func__); |
1137 | switch (command) { | 1189 | switch (command) { |
1138 | case WHITEHEAT_GET_DTR_RTS: | 1190 | case WHITEHEAT_GET_DTR_RTS: |
1139 | info = usb_get_serial_port_data(port); | 1191 | info = usb_get_serial_port_data(port); |
1140 | memcpy(&info->mcr, command_info->result_buffer, sizeof(struct whiteheat_dr_info)); | 1192 | memcpy(&info->mcr, command_info->result_buffer, |
1193 | sizeof(struct whiteheat_dr_info)); | ||
1141 | break; | 1194 | break; |
1142 | } | 1195 | } |
1143 | } | 1196 | } |
1144 | |||
1145 | exit: | 1197 | exit: |
1146 | mutex_unlock(&command_info->mutex); | 1198 | mutex_unlock(&command_info->mutex); |
1147 | return retval; | 1199 | return retval; |
1148 | } | 1200 | } |
1149 | 1201 | ||
1150 | 1202 | ||
1151 | static int firm_open(struct usb_serial_port *port) { | 1203 | static int firm_open(struct usb_serial_port *port) |
1204 | { | ||
1152 | struct whiteheat_simple open_command; | 1205 | struct whiteheat_simple open_command; |
1153 | 1206 | ||
1154 | open_command.port = port->number - port->serial->minor + 1; | 1207 | open_command.port = port->number - port->serial->minor + 1; |
1155 | return firm_send_command(port, WHITEHEAT_OPEN, (__u8 *)&open_command, sizeof(open_command)); | 1208 | return firm_send_command(port, WHITEHEAT_OPEN, |
1209 | (__u8 *)&open_command, sizeof(open_command)); | ||
1156 | } | 1210 | } |
1157 | 1211 | ||
1158 | 1212 | ||
1159 | static int firm_close(struct usb_serial_port *port) { | 1213 | static int firm_close(struct usb_serial_port *port) |
1214 | { | ||
1160 | struct whiteheat_simple close_command; | 1215 | struct whiteheat_simple close_command; |
1161 | 1216 | ||
1162 | close_command.port = port->number - port->serial->minor + 1; | 1217 | close_command.port = port->number - port->serial->minor + 1; |
1163 | return firm_send_command(port, WHITEHEAT_CLOSE, (__u8 *)&close_command, sizeof(close_command)); | 1218 | return firm_send_command(port, WHITEHEAT_CLOSE, |
1219 | (__u8 *)&close_command, sizeof(close_command)); | ||
1164 | } | 1220 | } |
1165 | 1221 | ||
1166 | 1222 | ||
1167 | static int firm_setup_port(struct usb_serial_port *port) { | 1223 | static int firm_setup_port(struct tty_struct *tty) |
1224 | { | ||
1225 | struct usb_serial_port *port = tty->driver_data; | ||
1168 | struct whiteheat_port_settings port_settings; | 1226 | struct whiteheat_port_settings port_settings; |
1169 | unsigned int cflag = port->tty->termios->c_cflag; | 1227 | unsigned int cflag = tty->termios->c_cflag; |
1170 | 1228 | ||
1171 | port_settings.port = port->number + 1; | 1229 | port_settings.port = port->number + 1; |
1172 | 1230 | ||
1173 | /* get the byte size */ | 1231 | /* get the byte size */ |
1174 | switch (cflag & CSIZE) { | 1232 | switch (cflag & CSIZE) { |
1175 | case CS5: port_settings.bits = 5; break; | 1233 | case CS5: port_settings.bits = 5; break; |
1176 | case CS6: port_settings.bits = 6; break; | 1234 | case CS6: port_settings.bits = 6; break; |
1177 | case CS7: port_settings.bits = 7; break; | 1235 | case CS7: port_settings.bits = 7; break; |
1178 | default: | 1236 | default: |
1179 | case CS8: port_settings.bits = 8; break; | 1237 | case CS8: port_settings.bits = 8; break; |
1180 | } | 1238 | } |
1181 | dbg("%s - data bits = %d", __func__, port_settings.bits); | 1239 | dbg("%s - data bits = %d", __func__, port_settings.bits); |
1182 | 1240 | ||
1183 | /* determine the parity */ | 1241 | /* determine the parity */ |
1184 | if (cflag & PARENB) | 1242 | if (cflag & PARENB) |
1185 | if (cflag & CMSPAR) | 1243 | if (cflag & CMSPAR) |
@@ -1205,7 +1263,8 @@ static int firm_setup_port(struct usb_serial_port *port) { | |||
1205 | 1263 | ||
1206 | /* figure out the flow control settings */ | 1264 | /* figure out the flow control settings */ |
1207 | if (cflag & CRTSCTS) | 1265 | if (cflag & CRTSCTS) |
1208 | port_settings.hflow = (WHITEHEAT_HFLOW_CTS | WHITEHEAT_HFLOW_RTS); | 1266 | port_settings.hflow = (WHITEHEAT_HFLOW_CTS | |
1267 | WHITEHEAT_HFLOW_RTS); | ||
1209 | else | 1268 | else |
1210 | port_settings.hflow = WHITEHEAT_HFLOW_NONE; | 1269 | port_settings.hflow = WHITEHEAT_HFLOW_NONE; |
1211 | dbg("%s - hardware flow control = %s %s %s %s", __func__, | 1270 | dbg("%s - hardware flow control = %s %s %s %s", __func__, |
@@ -1213,81 +1272,95 @@ static int firm_setup_port(struct usb_serial_port *port) { | |||
1213 | (port_settings.hflow & WHITEHEAT_HFLOW_RTS) ? "RTS" : "", | 1272 | (port_settings.hflow & WHITEHEAT_HFLOW_RTS) ? "RTS" : "", |
1214 | (port_settings.hflow & WHITEHEAT_HFLOW_DSR) ? "DSR" : "", | 1273 | (port_settings.hflow & WHITEHEAT_HFLOW_DSR) ? "DSR" : "", |
1215 | (port_settings.hflow & WHITEHEAT_HFLOW_DTR) ? "DTR" : ""); | 1274 | (port_settings.hflow & WHITEHEAT_HFLOW_DTR) ? "DTR" : ""); |
1216 | 1275 | ||
1217 | /* determine software flow control */ | 1276 | /* determine software flow control */ |
1218 | if (I_IXOFF(port->tty)) | 1277 | if (I_IXOFF(tty)) |
1219 | port_settings.sflow = WHITEHEAT_SFLOW_RXTX; | 1278 | port_settings.sflow = WHITEHEAT_SFLOW_RXTX; |
1220 | else | 1279 | else |
1221 | port_settings.sflow = WHITEHEAT_SFLOW_NONE; | 1280 | port_settings.sflow = WHITEHEAT_SFLOW_NONE; |
1222 | dbg("%s - software flow control = %c", __func__, port_settings.sflow); | 1281 | dbg("%s - software flow control = %c", __func__, port_settings.sflow); |
1223 | 1282 | ||
1224 | port_settings.xon = START_CHAR(port->tty); | 1283 | port_settings.xon = START_CHAR(tty); |
1225 | port_settings.xoff = STOP_CHAR(port->tty); | 1284 | port_settings.xoff = STOP_CHAR(tty); |
1226 | dbg("%s - XON = %2x, XOFF = %2x", __func__, port_settings.xon, port_settings.xoff); | 1285 | dbg("%s - XON = %2x, XOFF = %2x", |
1286 | __func__, port_settings.xon, port_settings.xoff); | ||
1227 | 1287 | ||
1228 | /* get the baud rate wanted */ | 1288 | /* get the baud rate wanted */ |
1229 | port_settings.baud = tty_get_baud_rate(port->tty); | 1289 | port_settings.baud = tty_get_baud_rate(tty); |
1230 | dbg("%s - baud rate = %d", __func__, port_settings.baud); | 1290 | dbg("%s - baud rate = %d", __func__, port_settings.baud); |
1231 | 1291 | ||
1232 | /* fixme: should set validated settings */ | 1292 | /* fixme: should set validated settings */ |
1233 | tty_encode_baud_rate(port->tty, port_settings.baud, port_settings.baud); | 1293 | tty_encode_baud_rate(tty, port_settings.baud, port_settings.baud); |
1234 | /* handle any settings that aren't specified in the tty structure */ | 1294 | /* handle any settings that aren't specified in the tty structure */ |
1235 | port_settings.lloop = 0; | 1295 | port_settings.lloop = 0; |
1236 | 1296 | ||
1237 | /* now send the message to the device */ | 1297 | /* now send the message to the device */ |
1238 | return firm_send_command(port, WHITEHEAT_SETUP_PORT, (__u8 *)&port_settings, sizeof(port_settings)); | 1298 | return firm_send_command(port, WHITEHEAT_SETUP_PORT, |
1299 | (__u8 *)&port_settings, sizeof(port_settings)); | ||
1239 | } | 1300 | } |
1240 | 1301 | ||
1241 | 1302 | ||
1242 | static int firm_set_rts(struct usb_serial_port *port, __u8 onoff) { | 1303 | static int firm_set_rts(struct usb_serial_port *port, __u8 onoff) |
1304 | { | ||
1243 | struct whiteheat_set_rdb rts_command; | 1305 | struct whiteheat_set_rdb rts_command; |
1244 | 1306 | ||
1245 | rts_command.port = port->number - port->serial->minor + 1; | 1307 | rts_command.port = port->number - port->serial->minor + 1; |
1246 | rts_command.state = onoff; | 1308 | rts_command.state = onoff; |
1247 | return firm_send_command(port, WHITEHEAT_SET_RTS, (__u8 *)&rts_command, sizeof(rts_command)); | 1309 | return firm_send_command(port, WHITEHEAT_SET_RTS, |
1310 | (__u8 *)&rts_command, sizeof(rts_command)); | ||
1248 | } | 1311 | } |
1249 | 1312 | ||
1250 | 1313 | ||
1251 | static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff) { | 1314 | static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff) |
1315 | { | ||
1252 | struct whiteheat_set_rdb dtr_command; | 1316 | struct whiteheat_set_rdb dtr_command; |
1253 | 1317 | ||
1254 | dtr_command.port = port->number - port->serial->minor + 1; | 1318 | dtr_command.port = port->number - port->serial->minor + 1; |
1255 | dtr_command.state = onoff; | 1319 | dtr_command.state = onoff; |
1256 | return firm_send_command(port, WHITEHEAT_SET_RTS, (__u8 *)&dtr_command, sizeof(dtr_command)); | 1320 | return firm_send_command(port, WHITEHEAT_SET_DTR, |
1321 | (__u8 *)&dtr_command, sizeof(dtr_command)); | ||
1257 | } | 1322 | } |
1258 | 1323 | ||
1259 | 1324 | ||
1260 | static int firm_set_break(struct usb_serial_port *port, __u8 onoff) { | 1325 | static int firm_set_break(struct usb_serial_port *port, __u8 onoff) |
1326 | { | ||
1261 | struct whiteheat_set_rdb break_command; | 1327 | struct whiteheat_set_rdb break_command; |
1262 | 1328 | ||
1263 | break_command.port = port->number - port->serial->minor + 1; | 1329 | break_command.port = port->number - port->serial->minor + 1; |
1264 | break_command.state = onoff; | 1330 | break_command.state = onoff; |
1265 | return firm_send_command(port, WHITEHEAT_SET_RTS, (__u8 *)&break_command, sizeof(break_command)); | 1331 | return firm_send_command(port, WHITEHEAT_SET_BREAK, |
1332 | (__u8 *)&break_command, sizeof(break_command)); | ||
1266 | } | 1333 | } |
1267 | 1334 | ||
1268 | 1335 | ||
1269 | static int firm_purge(struct usb_serial_port *port, __u8 rxtx) { | 1336 | static int firm_purge(struct usb_serial_port *port, __u8 rxtx) |
1337 | { | ||
1270 | struct whiteheat_purge purge_command; | 1338 | struct whiteheat_purge purge_command; |
1271 | 1339 | ||
1272 | purge_command.port = port->number - port->serial->minor + 1; | 1340 | purge_command.port = port->number - port->serial->minor + 1; |
1273 | purge_command.what = rxtx; | 1341 | purge_command.what = rxtx; |
1274 | return firm_send_command(port, WHITEHEAT_PURGE, (__u8 *)&purge_command, sizeof(purge_command)); | 1342 | return firm_send_command(port, WHITEHEAT_PURGE, |
1343 | (__u8 *)&purge_command, sizeof(purge_command)); | ||
1275 | } | 1344 | } |
1276 | 1345 | ||
1277 | 1346 | ||
1278 | static int firm_get_dtr_rts(struct usb_serial_port *port) { | 1347 | static int firm_get_dtr_rts(struct usb_serial_port *port) |
1348 | { | ||
1279 | struct whiteheat_simple get_dr_command; | 1349 | struct whiteheat_simple get_dr_command; |
1280 | 1350 | ||
1281 | get_dr_command.port = port->number - port->serial->minor + 1; | 1351 | get_dr_command.port = port->number - port->serial->minor + 1; |
1282 | return firm_send_command(port, WHITEHEAT_GET_DTR_RTS, (__u8 *)&get_dr_command, sizeof(get_dr_command)); | 1352 | return firm_send_command(port, WHITEHEAT_GET_DTR_RTS, |
1353 | (__u8 *)&get_dr_command, sizeof(get_dr_command)); | ||
1283 | } | 1354 | } |
1284 | 1355 | ||
1285 | 1356 | ||
1286 | static int firm_report_tx_done(struct usb_serial_port *port) { | 1357 | static int firm_report_tx_done(struct usb_serial_port *port) |
1358 | { | ||
1287 | struct whiteheat_simple close_command; | 1359 | struct whiteheat_simple close_command; |
1288 | 1360 | ||
1289 | close_command.port = port->number - port->serial->minor + 1; | 1361 | close_command.port = port->number - port->serial->minor + 1; |
1290 | return firm_send_command(port, WHITEHEAT_REPORT_TX_DONE, (__u8 *)&close_command, sizeof(close_command)); | 1362 | return firm_send_command(port, WHITEHEAT_REPORT_TX_DONE, |
1363 | (__u8 *)&close_command, sizeof(close_command)); | ||
1291 | } | 1364 | } |
1292 | 1365 | ||
1293 | 1366 | ||
@@ -1299,7 +1372,7 @@ static int start_command_port(struct usb_serial *serial) | |||
1299 | struct usb_serial_port *command_port; | 1372 | struct usb_serial_port *command_port; |
1300 | struct whiteheat_command_private *command_info; | 1373 | struct whiteheat_command_private *command_info; |
1301 | int retval = 0; | 1374 | int retval = 0; |
1302 | 1375 | ||
1303 | command_port = serial->port[COMMAND_PORT]; | 1376 | command_port = serial->port[COMMAND_PORT]; |
1304 | command_info = usb_get_serial_port_data(command_port); | 1377 | command_info = usb_get_serial_port_data(command_port); |
1305 | mutex_lock(&command_info->mutex); | 1378 | mutex_lock(&command_info->mutex); |
@@ -1310,7 +1383,8 @@ static int start_command_port(struct usb_serial *serial) | |||
1310 | command_port->read_urb->dev = serial->dev; | 1383 | command_port->read_urb->dev = serial->dev; |
1311 | retval = usb_submit_urb(command_port->read_urb, GFP_KERNEL); | 1384 | retval = usb_submit_urb(command_port->read_urb, GFP_KERNEL); |
1312 | if (retval) { | 1385 | if (retval) { |
1313 | err("%s - failed submitting read urb, error %d", __func__, retval); | 1386 | err("%s - failed submitting read urb, error %d", |
1387 | __func__, retval); | ||
1314 | goto exit; | 1388 | goto exit; |
1315 | } | 1389 | } |
1316 | } | 1390 | } |
@@ -1380,7 +1454,8 @@ static int start_port_read(struct usb_serial_port *port) | |||
1380 | } | 1454 | } |
1381 | 1455 | ||
1382 | 1456 | ||
1383 | static struct whiteheat_urb_wrap *urb_to_wrap(struct urb* urb, struct list_head *head) | 1457 | static struct whiteheat_urb_wrap *urb_to_wrap(struct urb *urb, |
1458 | struct list_head *head) | ||
1384 | { | 1459 | { |
1385 | struct whiteheat_urb_wrap *wrap; | 1460 | struct whiteheat_urb_wrap *wrap; |
1386 | struct list_head *tmp; | 1461 | struct list_head *tmp; |
@@ -1406,7 +1481,7 @@ static void rx_data_softint(struct work_struct *work) | |||
1406 | struct whiteheat_private *info = | 1481 | struct whiteheat_private *info = |
1407 | container_of(work, struct whiteheat_private, rx_work); | 1482 | container_of(work, struct whiteheat_private, rx_work); |
1408 | struct usb_serial_port *port = info->port; | 1483 | struct usb_serial_port *port = info->port; |
1409 | struct tty_struct *tty = port->tty; | 1484 | struct tty_struct *tty = port->port.tty; |
1410 | struct whiteheat_urb_wrap *wrap; | 1485 | struct whiteheat_urb_wrap *wrap; |
1411 | struct urb *urb; | 1486 | struct urb *urb; |
1412 | unsigned long flags; | 1487 | unsigned long flags; |
@@ -1429,7 +1504,8 @@ static void rx_data_softint(struct work_struct *work) | |||
1429 | urb = wrap->urb; | 1504 | urb = wrap->urb; |
1430 | 1505 | ||
1431 | if (tty && urb->actual_length) { | 1506 | if (tty && urb->actual_length) { |
1432 | int len = tty_buffer_request_room(tty, urb->actual_length); | 1507 | int len = tty_buffer_request_room(tty, |
1508 | urb->actual_length); | ||
1433 | /* This stuff can go away now I suspect */ | 1509 | /* This stuff can go away now I suspect */ |
1434 | if (unlikely(len < urb->actual_length)) { | 1510 | if (unlikely(len < urb->actual_length)) { |
1435 | spin_lock_irqsave(&info->lock, flags); | 1511 | spin_lock_irqsave(&info->lock, flags); |
@@ -1446,7 +1522,8 @@ static void rx_data_softint(struct work_struct *work) | |||
1446 | urb->dev = port->serial->dev; | 1522 | urb->dev = port->serial->dev; |
1447 | result = usb_submit_urb(urb, GFP_ATOMIC); | 1523 | result = usb_submit_urb(urb, GFP_ATOMIC); |
1448 | if (result) { | 1524 | if (result) { |
1449 | err("%s - failed resubmitting read urb, error %d", __func__, result); | 1525 | err("%s - failed resubmitting read urb, error %d", |
1526 | __func__, result); | ||
1450 | spin_lock_irqsave(&info->lock, flags); | 1527 | spin_lock_irqsave(&info->lock, flags); |
1451 | list_add(tmp, &info->rx_urbs_free); | 1528 | list_add(tmp, &info->rx_urbs_free); |
1452 | continue; | 1529 | continue; |
@@ -1465,7 +1542,7 @@ static void rx_data_softint(struct work_struct *work) | |||
1465 | /***************************************************************************** | 1542 | /***************************************************************************** |
1466 | * Connect Tech's White Heat module functions | 1543 | * Connect Tech's White Heat module functions |
1467 | *****************************************************************************/ | 1544 | *****************************************************************************/ |
1468 | static int __init whiteheat_init (void) | 1545 | static int __init whiteheat_init(void) |
1469 | { | 1546 | { |
1470 | int retval; | 1547 | int retval; |
1471 | retval = usb_serial_register(&whiteheat_fake_device); | 1548 | retval = usb_serial_register(&whiteheat_fake_device); |
@@ -1488,21 +1565,24 @@ failed_fake_register: | |||
1488 | } | 1565 | } |
1489 | 1566 | ||
1490 | 1567 | ||
1491 | static void __exit whiteheat_exit (void) | 1568 | static void __exit whiteheat_exit(void) |
1492 | { | 1569 | { |
1493 | usb_deregister (&whiteheat_driver); | 1570 | usb_deregister(&whiteheat_driver); |
1494 | usb_serial_deregister (&whiteheat_fake_device); | 1571 | usb_serial_deregister(&whiteheat_fake_device); |
1495 | usb_serial_deregister (&whiteheat_device); | 1572 | usb_serial_deregister(&whiteheat_device); |
1496 | } | 1573 | } |
1497 | 1574 | ||
1498 | 1575 | ||
1499 | module_init(whiteheat_init); | 1576 | module_init(whiteheat_init); |
1500 | module_exit(whiteheat_exit); | 1577 | module_exit(whiteheat_exit); |
1501 | 1578 | ||
1502 | MODULE_AUTHOR( DRIVER_AUTHOR ); | 1579 | MODULE_AUTHOR(DRIVER_AUTHOR); |
1503 | MODULE_DESCRIPTION( DRIVER_DESC ); | 1580 | MODULE_DESCRIPTION(DRIVER_DESC); |
1504 | MODULE_LICENSE("GPL"); | 1581 | MODULE_LICENSE("GPL"); |
1505 | 1582 | ||
1583 | MODULE_FIRMWARE("whiteheat.fw"); | ||
1584 | MODULE_FIRMWARE("whiteheat_loader.fw"); | ||
1585 | |||
1506 | module_param(urb_pool_size, int, 0); | 1586 | module_param(urb_pool_size, int, 0); |
1507 | MODULE_PARM_DESC(urb_pool_size, "Number of urbs to use for buffering"); | 1587 | MODULE_PARM_DESC(urb_pool_size, "Number of urbs to use for buffering"); |
1508 | 1588 | ||