--- pl2303.c	2018-11-07 23:21:00.000000000 +0800
+++ pl2303_new.c	2018-11-21 00:50:56.000000000 +0800
@@ -10,7 +10,7 @@
  * See Documentation/usb/usb-serial.txt for more information on using this
  * driver
  */
-
+ 
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/slab.h>
@@ -31,6 +31,8 @@
 #define PL2303_QUIRK_UART_STATE_IDX0		BIT(0)
 #define PL2303_QUIRK_LEGACY			BIT(1)
 #define PL2303_QUIRK_ENDPOINT_HACK		BIT(2)
+#define PL2303_QUIRK_LEGACY_HX			BIT(3)   /* Identification IC type  old*/
+#define PL2303_QUIRK_LEGACY_N			BIT(4)   /* Identification IC type: new */
 
 static const struct usb_device_id id_table[] = {
 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID),
@@ -46,6 +48,13 @@ static const struct usb_device_id id_tab
 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_HCR331) },
 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_MOTOROLA) },
 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_ZTEK) },
+	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_TB) },  /* Prolific PL2303TB chip */
+	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303G_PRODUCT_ID_GC) }, /* Prolific PL2303GC chip */
+	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303G_PRODUCT_ID_GB) },  /* Prolific PL2303GB chip */
+	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303G_PRODUCT_ID_GT) },  /* Prolific PL2303GT chip */
+	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303G_PRODUCT_ID_GL) }, /* Prolific PL2303GL chip */
+	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303G_PRODUCT_ID_GE) },  /* Prolific PL2303GE chip */
+    { USB_DEVICE(PL2303_VENDOR_ID, PL2303G_PRODUCT_ID_GS) },  /* Prolific PL2303GS chip */
 	{ USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID) },
 	{ USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID_RSAQ5) },
 	{ USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_ID),
@@ -90,10 +99,16 @@ static const struct usb_device_id id_tab
 	{ USB_DEVICE(COREGA_VENDOR_ID, COREGA_PRODUCT_ID) },
 	{ USB_DEVICE(YCCABLE_VENDOR_ID, YCCABLE_PRODUCT_ID) },
 	{ USB_DEVICE(SUPERIAL_VENDOR_ID, SUPERIAL_PRODUCT_ID) },
-	{ USB_DEVICE(HP_VENDOR_ID, HP_LD220_PRODUCT_ID) },
+	{ USB_DEVICE(HP_VENDOR_ID, HP_LD220_PRODUCT_ID) }, 
 	{ USB_DEVICE(HP_VENDOR_ID, HP_LD960_PRODUCT_ID) },
 	{ USB_DEVICE(HP_VENDOR_ID, HP_LCM220_PRODUCT_ID) },
 	{ USB_DEVICE(HP_VENDOR_ID, HP_LCM960_PRODUCT_ID) },
+	{ USB_DEVICE(HP_VENDOR_ID, HP_LD220_Display_ID) },/* HP_LD220 */
+	{ USB_DEVICE(HP_VENDOR_ID, HP_LD960_Display_ID) },/* HP_LD960 */
+	{ USB_DEVICE(HP_VENDOR_ID, HP_LDM350_Pole_Display_ID) },/* HP_LDM350 */
+	{ USB_DEVICE(HP_VENDOR_ID, HP_LM940_Display_ID) },/* HP_LM940 */
+	{ USB_DEVICE(HP_VENDOR_ID, HP_2X20_CFD_Display_ID) },/* HP_2X20 */
+	{ USB_DEVICE(HP_VENDOR_ID, HP_Engage_2X20_Pole_Display_ID) },/* HP_Engage */
 	{ USB_DEVICE(CRESSI_VENDOR_ID, CRESSI_EDY_PRODUCT_ID) },
 	{ USB_DEVICE(ZEAGLE_VENDOR_ID, ZEAGLE_N2ITION3_PRODUCT_ID) },
 	{ USB_DEVICE(SONY_VENDOR_ID, SONY_QN3USB_PRODUCT_ID) },
@@ -123,9 +138,11 @@ MODULE_DEVICE_TABLE(usb, id_table);
 
 #define VENDOR_WRITE_REQUEST_TYPE	0x40
 #define VENDOR_WRITE_REQUEST		0x01
+#define VENDOR_WRITE_NREQUEST		0x80 /* New chip: Write Request */
 
 #define VENDOR_READ_REQUEST_TYPE	0xc0
 #define VENDOR_READ_REQUEST		0x01
+#define VENDOR_READ_NREQUEST		0x81  /* New chip: Read Request */
 
 #define UART_STATE_INDEX		8
 #define UART_STATE_MSR_MASK		0x8b
@@ -144,6 +161,7 @@ static void pl2303_set_break(struct usb_
 enum pl2303_type {
 	TYPE_01,	/* Type 0 and 1 (difference unknown) */
 	TYPE_HX,	/* HX version of the pl2303 chip */
+	TYPE_HXN,	/* HXN version of the pl2303 chip */
 	TYPE_COUNT
 };
 
@@ -172,6 +190,11 @@ static const struct pl2303_type_data pl2
 	},
 	[TYPE_HX] = {
 		.max_baud_rate =	12000000,
+		.quirks =		PL2303_QUIRK_LEGACY_HX, /* old chip: type data */
+	},
+	[TYPE_HXN] = {
+		.max_baud_rate =	12000000,
+		.quirks =		PL2303_QUIRK_LEGACY_N, /* New chip: type data */
 	},
 };
 
@@ -179,10 +202,16 @@ static int pl2303_vendor_read(struct usb
 							unsigned char buf[1])
 {
 	struct device *dev = &serial->interface->dev;
+	struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
 	int res;
+	__u8 request;
 
+	/* Identification old / new  read request */
+	if (spriv->quirks & PL2303_QUIRK_LEGACY_N) request= VENDOR_READ_NREQUEST;
+	else request= VENDOR_READ_REQUEST;
+	
 	res = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
-			VENDOR_READ_REQUEST, VENDOR_READ_REQUEST_TYPE,
+			request, VENDOR_READ_REQUEST_TYPE,
 			value, 0, buf, 1, 100);
 	if (res != 1) {
 		dev_err(dev, "%s - failed to read [%04x]: %d\n", __func__,
@@ -201,12 +230,19 @@ static int pl2303_vendor_read(struct usb
 static int pl2303_vendor_write(struct usb_serial *serial, u16 value, u16 index)
 {
 	struct device *dev = &serial->interface->dev;
+	struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
 	int res;
+	__u8 request;
 
 	dev_dbg(dev, "%s - [%04x] = %02x\n", __func__, value, index);
-
+	
+    /* Identification old / new  write request */
+	if (spriv->quirks & PL2303_QUIRK_LEGACY_N) request= VENDOR_WRITE_NREQUEST;
+	else request= VENDOR_WRITE_REQUEST;
+	
+	
 	res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
-			VENDOR_WRITE_REQUEST, VENDOR_WRITE_REQUEST_TYPE,
+			request, VENDOR_WRITE_REQUEST_TYPE,
 			value, index, NULL, 0, 100);
 	if (res) {
 		dev_err(dev, "%s - failed to write [%04x]: %d\n", __func__,
@@ -296,7 +332,7 @@ static int pl2303_startup(struct usb_ser
 		kfree(spriv);
 		return -ENOMEM;
 	}
-
+  
 	if (serial->dev->descriptor.bDeviceClass == 0x02)
 		type = TYPE_01;		/* type 0 */
 	else if (serial->dev->descriptor.bMaxPacketSize0 == 0x40)
@@ -313,21 +349,39 @@ static int pl2303_startup(struct usb_ser
 
 	usb_set_serial_data(serial, spriv);
 
-	pl2303_vendor_read(serial, 0x8484, buf);
-	pl2303_vendor_write(serial, 0x0404, 0);
-	pl2303_vendor_read(serial, 0x8484, buf);
-	pl2303_vendor_read(serial, 0x8383, buf);
-	pl2303_vendor_read(serial, 0x8484, buf);
-	pl2303_vendor_write(serial, 0x0404, 1);
-	pl2303_vendor_read(serial, 0x8484, buf);
-	pl2303_vendor_read(serial, 0x8383, buf);
-	pl2303_vendor_write(serial, 0, 1);
-	pl2303_vendor_write(serial, 1, 0);
-	if (spriv->quirks & PL2303_QUIRK_LEGACY)
-		pl2303_vendor_write(serial, 2, 0x24);
-	else
-		pl2303_vendor_write(serial, 2, 0x44);
-
+	/* new chip */
+    if(serial->dev->descriptor.bcdUSB == 0x0200) {
+        pl2303_vendor_read(serial, 0x8484, buf);
+        if((u16)*buf != 0x02){
+		
+            type = TYPE_HXN;   /* new type HXN */	
+             
+	        spriv->type = &pl2303_type_data[type];
+	        spriv->quirks = (unsigned long)usb_get_serial_data(serial);
+	        spriv->quirks |= spriv->type->quirks;
+
+	        usb_set_serial_data(serial, spriv);
+        }
+    }
+	
+    /* old chip */	
+	if(type!=TYPE_HXN) {
+		pl2303_vendor_read(serial, 0x8484, buf);
+	    pl2303_vendor_write(serial, 0x0404, 0);
+		pl2303_vendor_read(serial, 0x8484, buf);
+		pl2303_vendor_read(serial, 0x8383, buf);
+		pl2303_vendor_read(serial, 0x8484, buf);
+		pl2303_vendor_write(serial, 0x0404, 1);
+		pl2303_vendor_read(serial, 0x8484, buf);
+		pl2303_vendor_read(serial, 0x8383, buf);
+		pl2303_vendor_write(serial, 0, 1);
+		pl2303_vendor_write(serial, 1, 0);
+		if (spriv->quirks & PL2303_QUIRK_LEGACY)
+			pl2303_vendor_write(serial, 2, 0x24);
+		else
+			pl2303_vendor_write(serial, 2, 0x44);
+	}
+	
 	kfree(buf);
 
 	return 0;
@@ -673,13 +727,33 @@ static void pl2303_set_termios(struct tt
 	if (C_CRTSCTS(tty)) {
 		if (spriv->quirks & PL2303_QUIRK_LEGACY)
 			pl2303_vendor_write(serial, 0x0, 0x41);
+		else if(spriv->quirks & PL2303_QUIRK_LEGACY_N)
+			pl2303_vendor_write(serial, 0x0A, 0xFA);  /*New chip  */
 		else
 			pl2303_vendor_write(serial, 0x0, 0x61);
 	} else if (I_IXON(tty) && !I_IXANY(tty) && START_CHAR(tty) == 0x11 &&
 			STOP_CHAR(tty) == 0x13) {
-		pl2303_vendor_write(serial, 0x0, 0xc0);
+			if(spriv->quirks & PL2303_QUIRK_LEGACY_N)
+				pl2303_vendor_write(serial, 0x0A, 0xEE); /*New chip  */
+            else 				
+		        pl2303_vendor_write(serial, 0x0, 0xc0);
 	} else {
-		pl2303_vendor_write(serial, 0x0, 0x0);
+		if(spriv->quirks & PL2303_QUIRK_LEGACY_N)
+		    pl2303_vendor_write(serial, 0x0A, 0xFF);  /*New chip  */
+	    else 
+			pl2303_vendor_write(serial, 0x0, 0x0);
+	}
+	
+	/*Old chip, External Pull-Up Mode  */
+	if(spriv->quirks & PL2303_QUIRK_LEGACY_HX){
+		pl2303_vendor_read(serial, 0x8484, buf);
+	    pl2303_vendor_write(serial, 0x0404, 0x09);
+		pl2303_vendor_read(serial, 0x8484, buf);
+		pl2303_vendor_read(serial, 0x8383, buf);
+		if((u16)*buf & 0x08){
+			pl2303_vendor_write(serial, 0x0, 0x31);
+			pl2303_vendor_write(serial, 0x1, 0x08);
+		}
 	}
 
 	kfree(buf);
@@ -720,8 +794,15 @@ static int pl2303_open(struct tty_struct
 		usb_clear_halt(serial->dev, port->read_urb->pipe);
 	} else {
 		/* reset upstream data pipes */
-		pl2303_vendor_write(serial, 8, 0);
-		pl2303_vendor_write(serial, 9, 0);
+		if(spriv->quirks & PL2303_QUIRK_LEGACY_N){
+			/* reset new chip */
+			pl2303_vendor_write(serial, 7, 0);
+		}	
+		else {
+			/* reset old chip */
+			pl2303_vendor_write(serial, 8, 0);
+			pl2303_vendor_write(serial, 9, 0);
+		}
 	}
 
 	/* Setup termios */
