diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-11-01 15:23:56 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-11-01 15:23:56 -0400 |
commit | 9119e33e507d3b8fe234f2c2bafd3199ea2e883b (patch) | |
tree | 2ddb56754af4deeb73c0d9a94747277420a1d4b8 | |
parent | f9adfbfbf3f856e142bbc607d51c0827901d32fc (diff) | |
parent | e1466ad5b1aeda303f9282463d55798d2eda218c (diff) |
Merge tag 'usb-3.12-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
Pull USB fixes from Greg KH:
"Here is a set of patches that revert all of the changes done to the
pl2303 USB serial driver in the 3.12-rc timeframe, as it turns out
they break some devices that work just fine on 3.11. As it's not a
good idea to break working systems, drop them all and they will be
reworked for future kernel versions such that there is no breakage.
I've also included a MAINTAINERS update for the USB serial subsystem
and a new device id for the ftdi_sio driver as well"
* tag 'usb-3.12-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb:
USB: serial: ftdi_sio: add id for Z3X Box device
USB: Maintainers change for usb serial drivers
Revert "USB: pl2303: restrict the divisor based baud rate encoding method to the "HX" chip type"
Revert "usb: pl2303: fix+improve the divsor based baud rate encoding method"
Revert "usb: pl2303: do not round to the next nearest standard baud rate for the divisor based baud rate encoding method"
Revert "usb: pl2303: remove 500000 baud from the list of standard baud rates"
Revert "usb: pl2303: move the two baud rate encoding methods to separate functions"
Revert "usb: pl2303: increase the allowed baud rate range for the divisor based encoding method"
Revert "usb: pl2303: also use the divisor based baud rate encoding method for baud rates < 115200 with HX chips"
Revert "usb: pl2303: add two comments concerning the supported baud rates with HX chips"
Revert "pl2303: simplify the else-if contruct for type_1 chips in pl2303_startup()"
Revert "pl2303: improve the chip type information output on startup"
Revert "pl2303: improve the chip type detection/distinction"
Revert "USB: pl2303: distinguish between original and cloned HX chips"
-rw-r--r-- | MAINTAINERS | 53 | ||||
-rw-r--r-- | drivers/usb/serial/ftdi_sio.c | 1 | ||||
-rw-r--r-- | drivers/usb/serial/ftdi_sio_ids.h | 6 | ||||
-rw-r--r-- | drivers/usb/serial/pl2303.c | 274 |
4 files changed, 66 insertions, 268 deletions
diff --git a/MAINTAINERS b/MAINTAINERS index 3438384d270c..ffcaf975bed7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
@@ -8917,61 +8917,14 @@ W: http://pegasus2.sourceforge.net/ | |||
8917 | S: Maintained | 8917 | S: Maintained |
8918 | F: drivers/net/usb/rtl8150.c | 8918 | F: drivers/net/usb/rtl8150.c |
8919 | 8919 | ||
8920 | USB SERIAL BELKIN F5U103 DRIVER | 8920 | USB SERIAL SUBSYSTEM |
8921 | M: William Greathouse <wgreathouse@smva.com> | 8921 | M: Johan Hovold <jhovold@gmail.com> |
8922 | L: linux-usb@vger.kernel.org | 8922 | L: linux-usb@vger.kernel.org |
8923 | S: Maintained | 8923 | S: Maintained |
8924 | F: drivers/usb/serial/belkin_sa.* | ||
8925 | |||
8926 | USB SERIAL CYPRESS M8 DRIVER | ||
8927 | M: Lonnie Mendez <dignome@gmail.com> | ||
8928 | L: linux-usb@vger.kernel.org | ||
8929 | S: Maintained | ||
8930 | W: http://geocities.com/i0xox0i | ||
8931 | W: http://firstlight.net/cvs | ||
8932 | F: drivers/usb/serial/cypress_m8.* | ||
8933 | |||
8934 | USB SERIAL CYBERJACK DRIVER | ||
8935 | M: Matthias Bruestle and Harald Welte <support@reiner-sct.com> | ||
8936 | W: http://www.reiner-sct.de/support/treiber_cyberjack.php | ||
8937 | S: Maintained | ||
8938 | F: drivers/usb/serial/cyberjack.c | ||
8939 | |||
8940 | USB SERIAL DIGI ACCELEPORT DRIVER | ||
8941 | M: Peter Berger <pberger@brimson.com> | ||
8942 | M: Al Borchers <alborchers@steinerpoint.com> | ||
8943 | L: linux-usb@vger.kernel.org | ||
8944 | S: Maintained | ||
8945 | F: drivers/usb/serial/digi_acceleport.c | ||
8946 | |||
8947 | USB SERIAL DRIVER | ||
8948 | M: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | ||
8949 | L: linux-usb@vger.kernel.org | ||
8950 | S: Supported | ||
8951 | F: Documentation/usb/usb-serial.txt | 8924 | F: Documentation/usb/usb-serial.txt |
8952 | F: drivers/usb/serial/generic.c | 8925 | F: drivers/usb/serial/ |
8953 | F: drivers/usb/serial/usb-serial.c | ||
8954 | F: include/linux/usb/serial.h | 8926 | F: include/linux/usb/serial.h |
8955 | 8927 | ||
8956 | USB SERIAL EMPEG EMPEG-CAR MARK I/II DRIVER | ||
8957 | M: Gary Brubaker <xavyer@ix.netcom.com> | ||
8958 | L: linux-usb@vger.kernel.org | ||
8959 | S: Maintained | ||
8960 | F: drivers/usb/serial/empeg.c | ||
8961 | |||
8962 | USB SERIAL KEYSPAN DRIVER | ||
8963 | M: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | ||
8964 | L: linux-usb@vger.kernel.org | ||
8965 | S: Maintained | ||
8966 | F: drivers/usb/serial/*keyspan* | ||
8967 | |||
8968 | USB SERIAL WHITEHEAT DRIVER | ||
8969 | M: Support Department <support@connecttech.com> | ||
8970 | L: linux-usb@vger.kernel.org | ||
8971 | W: http://www.connecttech.com | ||
8972 | S: Supported | ||
8973 | F: drivers/usb/serial/whiteheat* | ||
8974 | |||
8975 | USB SMSC75XX ETHERNET DRIVER | 8928 | USB SMSC75XX ETHERNET DRIVER |
8976 | M: Steve Glendinning <steve.glendinning@shawell.net> | 8929 | M: Steve Glendinning <steve.glendinning@shawell.net> |
8977 | L: netdev@vger.kernel.org | 8930 | L: netdev@vger.kernel.org |
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index c45f9c0a1b34..b21d553c245b 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c | |||
@@ -904,6 +904,7 @@ static struct usb_device_id id_table_combined [] = { | |||
904 | { USB_DEVICE(FTDI_VID, FTDI_LUMEL_PD12_PID) }, | 904 | { USB_DEVICE(FTDI_VID, FTDI_LUMEL_PD12_PID) }, |
905 | /* Crucible Devices */ | 905 | /* Crucible Devices */ |
906 | { USB_DEVICE(FTDI_VID, FTDI_CT_COMET_PID) }, | 906 | { USB_DEVICE(FTDI_VID, FTDI_CT_COMET_PID) }, |
907 | { USB_DEVICE(FTDI_VID, FTDI_Z3X_PID) }, | ||
907 | { } /* Terminating entry */ | 908 | { } /* Terminating entry */ |
908 | }; | 909 | }; |
909 | 910 | ||
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h index 1b8af461b522..a7019d1e3058 100644 --- a/drivers/usb/serial/ftdi_sio_ids.h +++ b/drivers/usb/serial/ftdi_sio_ids.h | |||
@@ -1307,3 +1307,9 @@ | |||
1307 | * Manufacturer: Crucible Technologies | 1307 | * Manufacturer: Crucible Technologies |
1308 | */ | 1308 | */ |
1309 | #define FTDI_CT_COMET_PID 0x8e08 | 1309 | #define FTDI_CT_COMET_PID 0x8e08 |
1310 | |||
1311 | /* | ||
1312 | * Product: Z3X Box | ||
1313 | * Manufacturer: Smart GSM Team | ||
1314 | */ | ||
1315 | #define FTDI_Z3X_PID 0x0011 | ||
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index bedf8e47713b..1e6de4cd079d 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c | |||
@@ -4,11 +4,6 @@ | |||
4 | * Copyright (C) 2001-2007 Greg Kroah-Hartman (greg@kroah.com) | 4 | * Copyright (C) 2001-2007 Greg Kroah-Hartman (greg@kroah.com) |
5 | * Copyright (C) 2003 IBM Corp. | 5 | * Copyright (C) 2003 IBM Corp. |
6 | * | 6 | * |
7 | * Copyright (C) 2009, 2013 Frank Schäfer <fschaefer.oss@googlemail.com> | ||
8 | * - fixes, improvements and documentation for the baud rate encoding methods | ||
9 | * Copyright (C) 2013 Reinhard Max <max@suse.de> | ||
10 | * - fixes and improvements for the divisor based baud rate encoding method | ||
11 | * | ||
12 | * Original driver for 2.2.x by anonymous | 7 | * Original driver for 2.2.x by anonymous |
13 | * | 8 | * |
14 | * This program is free software; you can redistribute it and/or | 9 | * This program is free software; you can redistribute it and/or |
@@ -134,18 +129,10 @@ MODULE_DEVICE_TABLE(usb, id_table); | |||
134 | 129 | ||
135 | 130 | ||
136 | enum pl2303_type { | 131 | enum pl2303_type { |
137 | type_0, /* H version ? */ | 132 | type_0, /* don't know the difference between type 0 and */ |
138 | type_1, /* H version ? */ | 133 | type_1, /* type 1, until someone from prolific tells us... */ |
139 | HX_TA, /* HX(A) / X(A) / TA version */ /* TODO: improve */ | 134 | HX, /* HX version of the pl2303 chip */ |
140 | HXD_EA_RA_SA, /* HXD / EA / RA / SA version */ /* TODO: improve */ | ||
141 | TB, /* TB version */ | ||
142 | HX_CLONE, /* Cheap and less functional clone of the HX chip */ | ||
143 | }; | 135 | }; |
144 | /* | ||
145 | * NOTE: don't know the difference between type 0 and type 1, | ||
146 | * until someone from Prolific tells us... | ||
147 | * TODO: distinguish between X/HX, TA and HXD, EA, RA, SA variants | ||
148 | */ | ||
149 | 136 | ||
150 | struct pl2303_serial_private { | 137 | struct pl2303_serial_private { |
151 | enum pl2303_type type; | 138 | enum pl2303_type type; |
@@ -185,7 +172,6 @@ static int pl2303_startup(struct usb_serial *serial) | |||
185 | { | 172 | { |
186 | struct pl2303_serial_private *spriv; | 173 | struct pl2303_serial_private *spriv; |
187 | enum pl2303_type type = type_0; | 174 | enum pl2303_type type = type_0; |
188 | char *type_str = "unknown (treating as type_0)"; | ||
189 | unsigned char *buf; | 175 | unsigned char *buf; |
190 | 176 | ||
191 | spriv = kzalloc(sizeof(*spriv), GFP_KERNEL); | 177 | spriv = kzalloc(sizeof(*spriv), GFP_KERNEL); |
@@ -198,53 +184,15 @@ static int pl2303_startup(struct usb_serial *serial) | |||
198 | return -ENOMEM; | 184 | return -ENOMEM; |
199 | } | 185 | } |
200 | 186 | ||
201 | if (serial->dev->descriptor.bDeviceClass == 0x02) { | 187 | if (serial->dev->descriptor.bDeviceClass == 0x02) |
202 | type = type_0; | 188 | type = type_0; |
203 | type_str = "type_0"; | 189 | else if (serial->dev->descriptor.bMaxPacketSize0 == 0x40) |
204 | } else if (serial->dev->descriptor.bMaxPacketSize0 == 0x40) { | 190 | type = HX; |
205 | /* | 191 | else if (serial->dev->descriptor.bDeviceClass == 0x00) |
206 | * NOTE: The bcdDevice version is the only difference between | ||
207 | * the device descriptors of the X/HX, HXD, EA, RA, SA, TA, TB | ||
208 | */ | ||
209 | if (le16_to_cpu(serial->dev->descriptor.bcdDevice) == 0x300) { | ||
210 | /* Check if the device is a clone */ | ||
211 | pl2303_vendor_read(0x9494, 0, serial, buf); | ||
212 | /* | ||
213 | * NOTE: Not sure if this read is really needed. | ||
214 | * The HX returns 0x00, the clone 0x02, but the Windows | ||
215 | * driver seems to ignore the value and continues. | ||
216 | */ | ||
217 | pl2303_vendor_write(0x0606, 0xaa, serial); | ||
218 | pl2303_vendor_read(0x8686, 0, serial, buf); | ||
219 | if (buf[0] != 0xaa) { | ||
220 | type = HX_CLONE; | ||
221 | type_str = "X/HX clone (limited functionality)"; | ||
222 | } else { | ||
223 | type = HX_TA; | ||
224 | type_str = "X/HX/TA"; | ||
225 | } | ||
226 | pl2303_vendor_write(0x0606, 0x00, serial); | ||
227 | } else if (le16_to_cpu(serial->dev->descriptor.bcdDevice) | ||
228 | == 0x400) { | ||
229 | type = HXD_EA_RA_SA; | ||
230 | type_str = "HXD/EA/RA/SA"; | ||
231 | } else if (le16_to_cpu(serial->dev->descriptor.bcdDevice) | ||
232 | == 0x500) { | ||
233 | type = TB; | ||
234 | type_str = "TB"; | ||
235 | } else { | ||
236 | dev_info(&serial->interface->dev, | ||
237 | "unknown/unsupported device type\n"); | ||
238 | kfree(spriv); | ||
239 | kfree(buf); | ||
240 | return -ENODEV; | ||
241 | } | ||
242 | } else if (serial->dev->descriptor.bDeviceClass == 0x00 | ||
243 | || serial->dev->descriptor.bDeviceClass == 0xFF) { | ||
244 | type = type_1; | 192 | type = type_1; |
245 | type_str = "type_1"; | 193 | else if (serial->dev->descriptor.bDeviceClass == 0xFF) |
246 | } | 194 | type = type_1; |
247 | dev_dbg(&serial->interface->dev, "device type: %s\n", type_str); | 195 | dev_dbg(&serial->interface->dev, "device type: %d\n", type); |
248 | 196 | ||
249 | spriv->type = type; | 197 | spriv->type = type; |
250 | usb_set_serial_data(serial, spriv); | 198 | usb_set_serial_data(serial, spriv); |
@@ -259,10 +207,10 @@ static int pl2303_startup(struct usb_serial *serial) | |||
259 | pl2303_vendor_read(0x8383, 0, serial, buf); | 207 | pl2303_vendor_read(0x8383, 0, serial, buf); |
260 | pl2303_vendor_write(0, 1, serial); | 208 | pl2303_vendor_write(0, 1, serial); |
261 | pl2303_vendor_write(1, 0, serial); | 209 | pl2303_vendor_write(1, 0, serial); |
262 | if (type == type_0 || type == type_1) | 210 | if (type == HX) |
263 | pl2303_vendor_write(2, 0x24, serial); | ||
264 | else | ||
265 | pl2303_vendor_write(2, 0x44, serial); | 211 | pl2303_vendor_write(2, 0x44, serial); |
212 | else | ||
213 | pl2303_vendor_write(2, 0x24, serial); | ||
266 | 214 | ||
267 | kfree(buf); | 215 | kfree(buf); |
268 | return 0; | 216 | return 0; |
@@ -316,174 +264,65 @@ static int pl2303_set_control_lines(struct usb_serial_port *port, u8 value) | |||
316 | return retval; | 264 | return retval; |
317 | } | 265 | } |
318 | 266 | ||
319 | static int pl2303_baudrate_encode_direct(int baud, enum pl2303_type type, | 267 | static void pl2303_encode_baudrate(struct tty_struct *tty, |
320 | u8 buf[4]) | 268 | struct usb_serial_port *port, |
269 | u8 buf[4]) | ||
321 | { | 270 | { |
322 | /* | ||
323 | * NOTE: Only the values defined in baud_sup are supported ! | ||
324 | * => if unsupported values are set, the PL2303 uses 9600 baud instead | ||
325 | * => HX clones just don't work at unsupported baud rates < 115200 baud, | ||
326 | * for baud rates > 115200 they run at 115200 baud | ||
327 | */ | ||
328 | const int baud_sup[] = { 75, 150, 300, 600, 1200, 1800, 2400, 3600, | 271 | const int baud_sup[] = { 75, 150, 300, 600, 1200, 1800, 2400, 3600, |
329 | 4800, 7200, 9600, 14400, 19200, 28800, 38400, | 272 | 4800, 7200, 9600, 14400, 19200, 28800, 38400, |
330 | 57600, 115200, 230400, 460800, 614400, 921600, | 273 | 57600, 115200, 230400, 460800, 500000, 614400, |
331 | 1228800, 2457600, 3000000, 6000000, 12000000 }; | 274 | 921600, 1228800, 2457600, 3000000, 6000000 }; |
275 | |||
276 | struct usb_serial *serial = port->serial; | ||
277 | struct pl2303_serial_private *spriv = usb_get_serial_data(serial); | ||
278 | int baud; | ||
279 | int i; | ||
280 | |||
332 | /* | 281 | /* |
333 | * NOTE: With the exception of type_0/1 devices, the following | 282 | * NOTE: Only the values defined in baud_sup are supported! |
334 | * additional baud rates are supported (tested with HX rev. 3A only): | 283 | * => if unsupported values are set, the PL2303 seems to use |
335 | * 110*, 56000*, 128000, 134400, 161280, 201600, 256000*, 268800, | 284 | * 9600 baud (at least my PL2303X always does) |
336 | * 403200, 806400. (*: not HX and HX clones) | ||
337 | * | ||
338 | * Maximum values: HXD, TB: 12000000; HX, TA: 6000000; | ||
339 | * type_0+1: 1228800; RA: 921600; HX clones, SA: 115200 | ||
340 | * | ||
341 | * As long as we are not using this encoding method for anything else | ||
342 | * than the type_0+1, HX and HX clone chips, there is no point in | ||
343 | * complicating the code to support them. | ||
344 | */ | 285 | */ |
345 | int i; | 286 | baud = tty_get_baud_rate(tty); |
287 | dev_dbg(&port->dev, "baud requested = %d\n", baud); | ||
288 | if (!baud) | ||
289 | return; | ||
346 | 290 | ||
347 | /* Set baudrate to nearest supported value */ | 291 | /* Set baudrate to nearest supported value */ |
348 | for (i = 0; i < ARRAY_SIZE(baud_sup); ++i) { | 292 | for (i = 0; i < ARRAY_SIZE(baud_sup); ++i) { |
349 | if (baud_sup[i] > baud) | 293 | if (baud_sup[i] > baud) |
350 | break; | 294 | break; |
351 | } | 295 | } |
296 | |||
352 | if (i == ARRAY_SIZE(baud_sup)) | 297 | if (i == ARRAY_SIZE(baud_sup)) |
353 | baud = baud_sup[i - 1]; | 298 | baud = baud_sup[i - 1]; |
354 | else if (i > 0 && (baud_sup[i] - baud) > (baud - baud_sup[i - 1])) | 299 | else if (i > 0 && (baud_sup[i] - baud) > (baud - baud_sup[i - 1])) |
355 | baud = baud_sup[i - 1]; | 300 | baud = baud_sup[i - 1]; |
356 | else | 301 | else |
357 | baud = baud_sup[i]; | 302 | baud = baud_sup[i]; |
358 | /* Respect the chip type specific baud rate limits */ | ||
359 | /* | ||
360 | * FIXME: as long as we don't know how to distinguish between the | ||
361 | * HXD, EA, RA, and SA chip variants, allow the max. value of 12M. | ||
362 | */ | ||
363 | if (type == HX_TA) | ||
364 | baud = min_t(int, baud, 6000000); | ||
365 | else if (type == type_0 || type == type_1) | ||
366 | baud = min_t(int, baud, 1228800); | ||
367 | else if (type == HX_CLONE) | ||
368 | baud = min_t(int, baud, 115200); | ||
369 | /* Direct (standard) baud rate encoding method */ | ||
370 | put_unaligned_le32(baud, buf); | ||
371 | |||
372 | return baud; | ||
373 | } | ||
374 | 303 | ||
375 | static int pl2303_baudrate_encode_divisor(int baud, enum pl2303_type type, | 304 | /* type_0, type_1 only support up to 1228800 baud */ |
376 | u8 buf[4]) | 305 | if (spriv->type != HX) |
377 | { | 306 | baud = min_t(int, baud, 1228800); |
378 | /* | ||
379 | * Divisor based baud rate encoding method | ||
380 | * | ||
381 | * NOTE: HX clones do NOT support this method. | ||
382 | * It's not clear if the type_0/1 chips support it. | ||
383 | * | ||
384 | * divisor = 12MHz * 32 / baudrate = 2^A * B | ||
385 | * | ||
386 | * with | ||
387 | * | ||
388 | * A = buf[1] & 0x0e | ||
389 | * B = buf[0] + (buf[1] & 0x01) << 8 | ||
390 | * | ||
391 | * Special cases: | ||
392 | * => 8 < B < 16: device seems to work not properly | ||
393 | * => B <= 8: device uses the max. value B = 512 instead | ||
394 | */ | ||
395 | unsigned int A, B; | ||
396 | 307 | ||
397 | /* | 308 | if (baud <= 115200) { |
398 | * NOTE: The Windows driver allows maximum baud rates of 110% of the | 309 | put_unaligned_le32(baud, buf); |
399 | * specified maximium value. | ||
400 | * Quick tests with early (2004) HX (rev. A) chips suggest, that even | ||
401 | * higher baud rates (up to the maximum of 24M baud !) are working fine, | ||
402 | * but that should really be tested carefully in "real life" scenarios | ||
403 | * before removing the upper limit completely. | ||
404 | * Baud rates smaller than the specified 75 baud are definitely working | ||
405 | * fine. | ||
406 | */ | ||
407 | if (type == type_0 || type == type_1) | ||
408 | baud = min_t(int, baud, 1228800 * 1.1); | ||
409 | else if (type == HX_TA) | ||
410 | baud = min_t(int, baud, 6000000 * 1.1); | ||
411 | else if (type == HXD_EA_RA_SA) | ||
412 | /* HXD, EA: 12Mbps; RA: 1Mbps; SA: 115200 bps */ | ||
413 | /* | ||
414 | * FIXME: as long as we don't know how to distinguish between | ||
415 | * these chip variants, allow the max. of these values | ||
416 | */ | ||
417 | baud = min_t(int, baud, 12000000 * 1.1); | ||
418 | else if (type == TB) | ||
419 | baud = min_t(int, baud, 12000000 * 1.1); | ||
420 | /* Determine factors A and B */ | ||
421 | A = 0; | ||
422 | B = 12000000 * 32 / baud; /* 12MHz */ | ||
423 | B <<= 1; /* Add one bit for rounding */ | ||
424 | while (B > (512 << 1) && A <= 14) { | ||
425 | A += 2; | ||
426 | B >>= 2; | ||
427 | } | ||
428 | if (A > 14) { /* max. divisor = min. baudrate reached */ | ||
429 | A = 14; | ||
430 | B = 512; | ||
431 | /* => ~45.78 baud */ | ||
432 | } else { | 310 | } else { |
433 | B = (B + 1) >> 1; /* Round the last bit */ | ||
434 | } | ||
435 | /* Handle special cases */ | ||
436 | if (B == 512) | ||
437 | B = 0; /* also: 1 to 8 */ | ||
438 | else if (B < 16) | ||
439 | /* | 311 | /* |
440 | * NOTE: With the current algorithm this happens | 312 | * Apparently the formula for higher speeds is: |
441 | * only for A=0 and means that the min. divisor | 313 | * baudrate = 12M * 32 / (2^buf[1]) / buf[0] |
442 | * (respectively: the max. baudrate) is reached. | ||
443 | */ | 314 | */ |
444 | B = 16; /* => 24 MBaud */ | 315 | unsigned tmp = 12000000 * 32 / baud; |
445 | /* Encode the baud rate */ | 316 | buf[3] = 0x80; |
446 | buf[3] = 0x80; /* Select divisor encoding method */ | 317 | buf[2] = 0; |
447 | buf[2] = 0; | 318 | buf[1] = (tmp >= 256); |
448 | buf[1] = (A & 0x0e); /* A */ | 319 | while (tmp >= 256) { |
449 | buf[1] |= ((B & 0x100) >> 8); /* MSB of B */ | 320 | tmp >>= 2; |
450 | buf[0] = B & 0xff; /* 8 LSBs of B */ | 321 | buf[1] <<= 1; |
451 | /* Calculate the actual/resulting baud rate */ | 322 | } |
452 | if (B <= 8) | 323 | buf[0] = tmp; |
453 | B = 512; | 324 | } |
454 | baud = 12000000 * 32 / ((1 << A) * B); | ||
455 | |||
456 | return baud; | ||
457 | } | ||
458 | |||
459 | static void pl2303_encode_baudrate(struct tty_struct *tty, | ||
460 | struct usb_serial_port *port, | ||
461 | enum pl2303_type type, | ||
462 | u8 buf[4]) | ||
463 | { | ||
464 | int baud; | ||
465 | 325 | ||
466 | baud = tty_get_baud_rate(tty); | ||
467 | dev_dbg(&port->dev, "baud requested = %d\n", baud); | ||
468 | if (!baud) | ||
469 | return; | ||
470 | /* | ||
471 | * There are two methods for setting/encoding the baud rate | ||
472 | * 1) Direct method: encodes the baud rate value directly | ||
473 | * => supported by all chip types | ||
474 | * 2) Divisor based method: encodes a divisor to a base value (12MHz*32) | ||
475 | * => not supported by HX clones (and likely type_0/1 chips) | ||
476 | * | ||
477 | * NOTE: Although the divisor based baud rate encoding method is much | ||
478 | * more flexible, some of the standard baud rate values can not be | ||
479 | * realized exactly. But the difference is very small (max. 0.2%) and | ||
480 | * the device likely uses the same baud rate generator for both methods | ||
481 | * so that there is likley no difference. | ||
482 | */ | ||
483 | if (type == type_0 || type == type_1 || type == HX_CLONE) | ||
484 | baud = pl2303_baudrate_encode_direct(baud, type, buf); | ||
485 | else | ||
486 | baud = pl2303_baudrate_encode_divisor(baud, type, buf); | ||
487 | /* Save resulting baud rate */ | 326 | /* Save resulting baud rate */ |
488 | tty_encode_baud_rate(tty, baud, baud); | 327 | tty_encode_baud_rate(tty, baud, baud); |
489 | dev_dbg(&port->dev, "baud set = %d\n", baud); | 328 | dev_dbg(&port->dev, "baud set = %d\n", baud); |
@@ -540,8 +379,8 @@ static void pl2303_set_termios(struct tty_struct *tty, | |||
540 | dev_dbg(&port->dev, "data bits = %d\n", buf[6]); | 379 | dev_dbg(&port->dev, "data bits = %d\n", buf[6]); |
541 | } | 380 | } |
542 | 381 | ||
543 | /* For reference: buf[0]:buf[3] baud rate value */ | 382 | /* For reference buf[0]:buf[3] baud rate value */ |
544 | pl2303_encode_baudrate(tty, port, spriv->type, buf); | 383 | pl2303_encode_baudrate(tty, port, &buf[0]); |
545 | 384 | ||
546 | /* For reference buf[4]=0 is 1 stop bits */ | 385 | /* For reference buf[4]=0 is 1 stop bits */ |
547 | /* For reference buf[4]=1 is 1.5 stop bits */ | 386 | /* For reference buf[4]=1 is 1.5 stop bits */ |
@@ -618,10 +457,10 @@ static void pl2303_set_termios(struct tty_struct *tty, | |||
618 | dev_dbg(&port->dev, "0xa1:0x21:0:0 %d - %7ph\n", i, buf); | 457 | dev_dbg(&port->dev, "0xa1:0x21:0:0 %d - %7ph\n", i, buf); |
619 | 458 | ||
620 | if (C_CRTSCTS(tty)) { | 459 | if (C_CRTSCTS(tty)) { |
621 | if (spriv->type == type_0 || spriv->type == type_1) | 460 | if (spriv->type == HX) |
622 | pl2303_vendor_write(0x0, 0x41, serial); | ||
623 | else | ||
624 | pl2303_vendor_write(0x0, 0x61, serial); | 461 | pl2303_vendor_write(0x0, 0x61, serial); |
462 | else | ||
463 | pl2303_vendor_write(0x0, 0x41, serial); | ||
625 | } else { | 464 | } else { |
626 | pl2303_vendor_write(0x0, 0x0, serial); | 465 | pl2303_vendor_write(0x0, 0x0, serial); |
627 | } | 466 | } |
@@ -658,7 +497,7 @@ static int pl2303_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
658 | struct pl2303_serial_private *spriv = usb_get_serial_data(serial); | 497 | struct pl2303_serial_private *spriv = usb_get_serial_data(serial); |
659 | int result; | 498 | int result; |
660 | 499 | ||
661 | if (spriv->type == type_0 || spriv->type == type_1) { | 500 | if (spriv->type != HX) { |
662 | usb_clear_halt(serial->dev, port->write_urb->pipe); | 501 | usb_clear_halt(serial->dev, port->write_urb->pipe); |
663 | usb_clear_halt(serial->dev, port->read_urb->pipe); | 502 | usb_clear_halt(serial->dev, port->read_urb->pipe); |
664 | } else { | 503 | } else { |
@@ -833,7 +672,6 @@ static void pl2303_break_ctl(struct tty_struct *tty, int break_state) | |||
833 | result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), | 672 | result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), |
834 | BREAK_REQUEST, BREAK_REQUEST_TYPE, state, | 673 | BREAK_REQUEST, BREAK_REQUEST_TYPE, state, |
835 | 0, NULL, 0, 100); | 674 | 0, NULL, 0, 100); |
836 | /* NOTE: HX clones don't support sending breaks, -EPIPE is returned */ | ||
837 | if (result) | 675 | if (result) |
838 | dev_err(&port->dev, "error sending break = %d\n", result); | 676 | dev_err(&port->dev, "error sending break = %d\n", result); |
839 | } | 677 | } |