USB: pl2303: distinguish between original and cloned HX chips

According to Prolific, several (unauthorized) cheap and less functional
clones of the PL2303HX chip are in circulation. [1]
I've had the chance to test such a cloned device and it turned out that
it doesn't support any baud rates above 115200 baud (original: 6 Mbaud)
It also doesn't support the divisior based baud rate encoding method,
so no continuous baud rate adjustment is possible.
Nevertheless, these devices have been working (unintentionally) with
the driver up to commit 61fa8d694b ("pl2303: also use the divisor based
baud rate encoding method for baud rates < 115200 with HX chips"), and
this commit broke support for them.
Fortunately, it is pretty simple to distinguish between the original
and the cloned HX chips, so I've added a check and an extra chip type
to keep the clones working.
The same check is used by the latest Prolific Windows driver, so it
should be solid.

[1] http://www.prolific.com.tw/US/ShowProduct.aspx?p_id=225&pcid=41

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by Frank Schäfer and committed by Greg Kroah-Hartman 7d26a78f dfe29020

Changed files
+32 -11
drivers
usb
serial
+32 -11
drivers/usb/serial/pl2303.c
··· 139 139 HX_TA, /* HX(A) / X(A) / TA version */ /* TODO: improve */ 140 140 HXD_EA_RA_SA, /* HXD / EA / RA / SA version */ /* TODO: improve */ 141 141 TB, /* TB version */ 142 + HX_CLONE, /* Cheap and less functional clone of the HX chip */ 142 143 }; 143 144 /* 144 145 * NOTE: don't know the difference between type 0 and type 1, ··· 207 206 * the device descriptors of the X/HX, HXD, EA, RA, SA, TA, TB 208 207 */ 209 208 if (le16_to_cpu(serial->dev->descriptor.bcdDevice) == 0x300) { 210 - type = HX_TA; 211 - type_str = "X/HX/TA"; 209 + /* Check if the device is a clone */ 210 + pl2303_vendor_read(0x9494, 0, serial, buf); 211 + /* 212 + * NOTE: Not sure if this read is really needed. 213 + * The HX returns 0x00, the clone 0x02, but the Windows 214 + * driver seems to ignore the value and continues. 215 + */ 216 + pl2303_vendor_write(0x0606, 0xaa, serial); 217 + pl2303_vendor_read(0x8686, 0, serial, buf); 218 + if (buf[0] != 0xaa) { 219 + type = HX_CLONE; 220 + type_str = "X/HX clone (limited functionality)"; 221 + } else { 222 + type = HX_TA; 223 + type_str = "X/HX/TA"; 224 + } 225 + pl2303_vendor_write(0x0606, 0x00, serial); 212 226 } else if (le16_to_cpu(serial->dev->descriptor.bcdDevice) 213 227 == 0x400) { 214 228 type = HXD_EA_RA_SA; ··· 321 305 { 322 306 /* 323 307 * NOTE: Only the values defined in baud_sup are supported ! 324 - * => if unsupported values are set, the PL2303 seems to 325 - * use 9600 baud (at least my PL2303X always does) 308 + * => if unsupported values are set, the PL2303 uses 9600 baud instead 309 + * => HX clones just don't work at unsupported baud rates < 115200 baud, 310 + * for baud rates > 115200 they run at 115200 baud 326 311 */ 327 312 const int baud_sup[] = { 75, 150, 300, 600, 1200, 1800, 2400, 3600, 328 313 4800, 7200, 9600, 14400, 19200, 28800, 38400, ··· 333 316 * NOTE: With the exception of type_0/1 devices, the following 334 317 * additional baud rates are supported (tested with HX rev. 3A only): 335 318 * 110*, 56000*, 128000, 134400, 161280, 201600, 256000*, 268800, 336 - * 403200, 806400. (*: not HX) 319 + * 403200, 806400. (*: not HX and HX clones) 337 320 * 338 321 * Maximum values: HXD, TB: 12000000; HX, TA: 6000000; 339 - * type_0+1: 1228800; RA: 921600; SA: 115200 322 + * type_0+1: 1228800; RA: 921600; HX clones, SA: 115200 340 323 * 341 324 * As long as we are not using this encoding method for anything else 342 - * than the type_0+1 and HX chips, there is no point in complicating 343 - * the code to support them. 325 + * than the type_0+1, HX and HX clone chips, there is no point in 326 + * complicating the code to support them. 344 327 */ 345 328 int i; 346 329 ··· 364 347 baud = min_t(int, baud, 6000000); 365 348 else if (type == type_0 || type == type_1) 366 349 baud = min_t(int, baud, 1228800); 350 + else if (type == HX_CLONE) 351 + baud = min_t(int, baud, 115200); 367 352 /* Direct (standard) baud rate encoding method */ 368 353 put_unaligned_le32(baud, buf); 369 354 ··· 378 359 /* 379 360 * Divisor based baud rate encoding method 380 361 * 381 - * NOTE: it's not clear if the type_0/1 chips support this method 362 + * NOTE: HX clones do NOT support this method. 363 + * It's not clear if the type_0/1 chips support it. 382 364 * 383 365 * divisor = 12MHz * 32 / baudrate = 2^A * B 384 366 * ··· 472 452 * 1) Direct method: encodes the baud rate value directly 473 453 * => supported by all chip types 474 454 * 2) Divisor based method: encodes a divisor to a base value (12MHz*32) 475 - * => supported by HX chips (and likely not by type_0/1 chips) 455 + * => not supported by HX clones (and likely type_0/1 chips) 476 456 * 477 457 * NOTE: Although the divisor based baud rate encoding method is much 478 458 * more flexible, some of the standard baud rate values can not be ··· 480 460 * the device likely uses the same baud rate generator for both methods 481 461 * so that there is likley no difference. 482 462 */ 483 - if (type == type_0 || type == type_1) 463 + if (type == type_0 || type == type_1 || type == HX_CLONE) 484 464 baud = pl2303_baudrate_encode_direct(baud, type, buf); 485 465 else 486 466 baud = pl2303_baudrate_encode_divisor(baud, type, buf); ··· 833 813 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 834 814 BREAK_REQUEST, BREAK_REQUEST_TYPE, state, 835 815 0, NULL, 0, 100); 816 + /* NOTE: HX clones don't support sending breaks, -EPIPE is returned */ 836 817 if (result) 837 818 dev_err(&port->dev, "error sending break = %d\n", result); 838 819 }