Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * Prolific PL2303 USB to serial adaptor driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright (C) 2001-2007 Greg Kroah-Hartman (greg@kroah.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Copyright (C) 2003 IBM Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * Original driver for 2.2.x by anonymous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  * See Documentation/usb/usb-serial.rst for more information on using this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  * driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/tty.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/tty_driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/tty_flip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/serial.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/usb/serial.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include "pl2303.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #define PL2303_QUIRK_UART_STATE_IDX0		BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #define PL2303_QUIRK_LEGACY			BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #define PL2303_QUIRK_ENDPOINT_HACK		BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) static const struct usb_device_id id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 		.driver_info = PL2303_QUIRK_ENDPOINT_HACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_RSAQ2) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_DCU11) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_RSAQ3) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_CHILITAG) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_PHAROS) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_ALDIGA) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_MMX) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GPRS) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_HCR331) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_MOTOROLA) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_ZTEK) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_TB) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GC) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GB) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GT) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GE) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GS) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 	{ USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 	{ USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID_RSAQ5) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 	{ USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_ID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 		.driver_info = PL2303_QUIRK_ENDPOINT_HACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 	{ USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_UC485),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 		.driver_info = PL2303_QUIRK_ENDPOINT_HACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 	{ USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_UC232B),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 		.driver_info = PL2303_QUIRK_ENDPOINT_HACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 	{ USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_ID2) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 	{ USB_DEVICE(ATEN_VENDOR_ID2, ATEN_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 	{ USB_DEVICE(ELCOM_VENDOR_ID, ELCOM_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 	{ USB_DEVICE(ELCOM_VENDOR_ID, ELCOM_PRODUCT_ID_UCSGT) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 	{ USB_DEVICE(ITEGNO_VENDOR_ID, ITEGNO_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 	{ USB_DEVICE(ITEGNO_VENDOR_ID, ITEGNO_PRODUCT_ID_2080) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 	{ USB_DEVICE(MA620_VENDOR_ID, MA620_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 	{ USB_DEVICE(RATOC_VENDOR_ID, RATOC_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 	{ USB_DEVICE(TRIPP_VENDOR_ID, TRIPP_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 	{ USB_DEVICE(RADIOSHACK_VENDOR_ID, RADIOSHACK_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 	{ USB_DEVICE(DCU10_VENDOR_ID, DCU10_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	{ USB_DEVICE(SITECOM_VENDOR_ID, SITECOM_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 	{ USB_DEVICE(ALCATEL_VENDOR_ID, ALCATEL_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	{ USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_SX1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 		.driver_info = PL2303_QUIRK_UART_STATE_IDX0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	{ USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_X65),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 		.driver_info = PL2303_QUIRK_UART_STATE_IDX0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	{ USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_X75),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 		.driver_info = PL2303_QUIRK_UART_STATE_IDX0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	{ USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_EF81),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 		.driver_info = PL2303_QUIRK_ENDPOINT_HACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	{ USB_DEVICE(BENQ_VENDOR_ID, BENQ_PRODUCT_ID_S81) }, /* Benq/Siemens S81 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	{ USB_DEVICE(SYNTECH_VENDOR_ID, SYNTECH_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	{ USB_DEVICE(NOKIA_CA42_VENDOR_ID, NOKIA_CA42_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 	{ USB_DEVICE(CA_42_CA42_VENDOR_ID, CA_42_CA42_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	{ USB_DEVICE(SAGEM_VENDOR_ID, SAGEM_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	{ USB_DEVICE(LEADTEK_VENDOR_ID, LEADTEK_9531_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 	{ USB_DEVICE(SPEEDDRAGON_VENDOR_ID, SPEEDDRAGON_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 	{ USB_DEVICE(DATAPILOT_U2_VENDOR_ID, DATAPILOT_U2_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 	{ USB_DEVICE(BELKIN_VENDOR_ID, BELKIN_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	{ USB_DEVICE(ALCOR_VENDOR_ID, ALCOR_PRODUCT_ID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 		.driver_info = PL2303_QUIRK_ENDPOINT_HACK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	{ USB_DEVICE(WS002IN_VENDOR_ID, WS002IN_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	{ USB_DEVICE(COREGA_VENDOR_ID, COREGA_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	{ USB_DEVICE(YCCABLE_VENDOR_ID, YCCABLE_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	{ USB_DEVICE(SUPERIAL_VENDOR_ID, SUPERIAL_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 	{ USB_DEVICE(HP_VENDOR_ID, HP_LD220_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 	{ USB_DEVICE(HP_VENDOR_ID, HP_LD220TA_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	{ USB_DEVICE(HP_VENDOR_ID, HP_LD381_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	{ USB_DEVICE(HP_VENDOR_ID, HP_LD381GC_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	{ USB_DEVICE(HP_VENDOR_ID, HP_LD960_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	{ USB_DEVICE(HP_VENDOR_ID, HP_LD960TA_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	{ USB_DEVICE(HP_VENDOR_ID, HP_LCM220_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	{ USB_DEVICE(HP_VENDOR_ID, HP_LCM960_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	{ USB_DEVICE(HP_VENDOR_ID, HP_LM920_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	{ USB_DEVICE(HP_VENDOR_ID, HP_LM940_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	{ USB_DEVICE(HP_VENDOR_ID, HP_TD620_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	{ USB_DEVICE(CRESSI_VENDOR_ID, CRESSI_EDY_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	{ USB_DEVICE(ZEAGLE_VENDOR_ID, ZEAGLE_N2ITION3_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	{ USB_DEVICE(SONY_VENDOR_ID, SONY_QN3USB_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	{ USB_DEVICE(SANWA_VENDOR_ID, SANWA_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	{ USB_DEVICE(ADLINK_VENDOR_ID, ADLINK_ND6530_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	{ USB_DEVICE(ADLINK_VENDOR_ID, ADLINK_ND6530GC_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	{ USB_DEVICE(SMART_VENDOR_ID, SMART_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	{ USB_DEVICE(AT_VENDOR_ID, AT_VTKIT3_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	{ USB_DEVICE(IBM_VENDOR_ID, IBM_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	{ }					/* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) MODULE_DEVICE_TABLE(usb, id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) #define SET_LINE_REQUEST_TYPE		0x21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) #define SET_LINE_REQUEST		0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) #define SET_CONTROL_REQUEST_TYPE	0x21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) #define SET_CONTROL_REQUEST		0x22
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) #define CONTROL_DTR			0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) #define CONTROL_RTS			0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) #define BREAK_REQUEST_TYPE		0x21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) #define BREAK_REQUEST			0x23
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) #define BREAK_ON			0xffff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) #define BREAK_OFF			0x0000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) #define GET_LINE_REQUEST_TYPE		0xa1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) #define GET_LINE_REQUEST		0x21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) #define VENDOR_WRITE_REQUEST_TYPE	0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) #define VENDOR_WRITE_REQUEST		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) #define VENDOR_WRITE_NREQUEST		0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) #define VENDOR_READ_REQUEST_TYPE	0xc0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) #define VENDOR_READ_REQUEST		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) #define VENDOR_READ_NREQUEST		0x81
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) #define UART_STATE_INDEX		8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) #define UART_STATE_MSR_MASK		0x8b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) #define UART_STATE_TRANSIENT_MASK	0x74
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) #define UART_DCD			0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) #define UART_DSR			0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) #define UART_BREAK_ERROR		0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) #define UART_RING			0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) #define UART_FRAME_ERROR		0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) #define UART_PARITY_ERROR		0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) #define UART_OVERRUN_ERROR		0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) #define UART_CTS			0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) #define PL2303_FLOWCTRL_MASK		0xf0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) #define PL2303_READ_TYPE_HX_STATUS	0x8080
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) #define PL2303_HXN_RESET_REG		0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) #define PL2303_HXN_RESET_UPSTREAM_PIPE	0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) #define PL2303_HXN_RESET_DOWNSTREAM_PIPE	0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) #define PL2303_HXN_FLOWCTRL_REG		0x0a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) #define PL2303_HXN_FLOWCTRL_MASK	0x1c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) #define PL2303_HXN_FLOWCTRL_NONE	0x1c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) #define PL2303_HXN_FLOWCTRL_RTS_CTS	0x18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) #define PL2303_HXN_FLOWCTRL_XON_XOFF	0x0c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) static void pl2303_set_break(struct usb_serial_port *port, bool enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) enum pl2303_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	TYPE_01,	/* Type 0 and 1 (difference unknown) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	TYPE_HX,	/* HX version of the pl2303 chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	TYPE_HXN,	/* HXN version of the pl2303 chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	TYPE_COUNT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) struct pl2303_type_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	speed_t max_baud_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	unsigned long quirks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	unsigned int no_autoxonxoff:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	unsigned int no_divisors:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) struct pl2303_serial_private {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	const struct pl2303_type_data *type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	unsigned long quirks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) struct pl2303_private {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	u8 line_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	u8 line_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	u8 line_settings[7];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) static const struct pl2303_type_data pl2303_type_data[TYPE_COUNT] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	[TYPE_01] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 		.max_baud_rate		= 1228800,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 		.quirks			= PL2303_QUIRK_LEGACY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 		.no_autoxonxoff		= true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	[TYPE_HX] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 		.max_baud_rate		= 12000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	[TYPE_HXN] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 		.max_baud_rate		= 12000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 		.no_divisors		= true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) static int pl2303_vendor_read(struct usb_serial *serial, u16 value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 							unsigned char buf[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	struct device *dev = &serial->interface->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	u8 request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	if (spriv->type == &pl2303_type_data[TYPE_HXN])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 		request = VENDOR_READ_NREQUEST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 		request = VENDOR_READ_REQUEST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	res = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 			request, VENDOR_READ_REQUEST_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 			value, 0, buf, 1, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	if (res != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 		dev_err(dev, "%s - failed to read [%04x]: %d\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 								value, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 		if (res >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 			res = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	dev_dbg(dev, "%s - [%04x] = %02x\n", __func__, value, buf[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) static int pl2303_vendor_write(struct usb_serial *serial, u16 value, u16 index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	struct device *dev = &serial->interface->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	u8 request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	dev_dbg(dev, "%s - [%04x] = %02x\n", __func__, value, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	if (spriv->type == &pl2303_type_data[TYPE_HXN])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 		request = VENDOR_WRITE_NREQUEST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 		request = VENDOR_WRITE_REQUEST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 			request, VENDOR_WRITE_REQUEST_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 			value, index, NULL, 0, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 		dev_err(dev, "%s - failed to write [%04x]: %d\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 								value, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) static int pl2303_update_reg(struct usb_serial *serial, u8 reg, u8 mask, u8 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	u8 *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	buf = kmalloc(1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	if (spriv->type == &pl2303_type_data[TYPE_HXN])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 		ret = pl2303_vendor_read(serial, reg, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 		ret = pl2303_vendor_read(serial, reg | 0x80, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	*buf &= ~mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	*buf |= val & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	ret = pl2303_vendor_write(serial, reg, *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) static int pl2303_probe(struct usb_serial *serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 					const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	usb_set_serial_data(serial, (void *)id->driver_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312)  * Use interrupt endpoint from first interface if available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314)  * This is needed due to the looney way its endpoints are set up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) static int pl2303_endpoint_hack(struct usb_serial *serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 					struct usb_serial_endpoints *epds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	struct usb_interface *interface = serial->interface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	struct usb_device *dev = serial->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	struct device *ddev = &interface->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	struct usb_host_interface *iface_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	struct usb_endpoint_descriptor *endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	if (interface == dev->actconfig->interface[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	/* check out the endpoints of the other interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	iface_desc = dev->actconfig->interface[0]->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 		endpoint = &iface_desc->endpoint[i].desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 		if (!usb_endpoint_is_int_in(endpoint))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 		dev_dbg(ddev, "found interrupt in on separate interface\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 		if (epds->num_interrupt_in < ARRAY_SIZE(epds->interrupt_in))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 			epds->interrupt_in[epds->num_interrupt_in++] = endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) static int pl2303_calc_num_ports(struct usb_serial *serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 					struct usb_serial_endpoints *epds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	unsigned long quirks = (unsigned long)usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	struct device *dev = &serial->interface->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	if (quirks & PL2303_QUIRK_ENDPOINT_HACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 		ret = pl2303_endpoint_hack(serial, epds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	if (epds->num_interrupt_in < 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 		dev_err(dev, "required interrupt-in endpoint missing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) static int pl2303_startup(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	struct pl2303_serial_private *spriv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	enum pl2303_type type = TYPE_01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	unsigned char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	if (!spriv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	buf = kmalloc(1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 		kfree(spriv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	if (serial->dev->descriptor.bDeviceClass == 0x02)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 		type = TYPE_01;		/* type 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	else if (serial->dev->descriptor.bMaxPacketSize0 == 0x40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 		type = TYPE_HX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	else if (serial->dev->descriptor.bDeviceClass == 0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 		type = TYPE_01;		/* type 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	else if (serial->dev->descriptor.bDeviceClass == 0xFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 		type = TYPE_01;		/* type 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	dev_dbg(&serial->interface->dev, "device type: %d\n", type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	if (type == TYPE_HX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 		res = usb_control_msg(serial->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 				usb_rcvctrlpipe(serial->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 				VENDOR_READ_REQUEST, VENDOR_READ_REQUEST_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 				PL2303_READ_TYPE_HX_STATUS, 0, buf, 1, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 		if (res != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 			type = TYPE_HXN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	spriv->type = &pl2303_type_data[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	spriv->quirks = (unsigned long)usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	spriv->quirks |= spriv->type->quirks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 	usb_set_serial_data(serial, spriv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	if (type != TYPE_HXN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 		pl2303_vendor_read(serial, 0x8484, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		pl2303_vendor_write(serial, 0x0404, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 		pl2303_vendor_read(serial, 0x8484, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 		pl2303_vendor_read(serial, 0x8383, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 		pl2303_vendor_read(serial, 0x8484, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 		pl2303_vendor_write(serial, 0x0404, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 		pl2303_vendor_read(serial, 0x8484, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 		pl2303_vendor_read(serial, 0x8383, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 		pl2303_vendor_write(serial, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 		pl2303_vendor_write(serial, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 		if (spriv->quirks & PL2303_QUIRK_LEGACY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 			pl2303_vendor_write(serial, 2, 0x24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 			pl2303_vendor_write(serial, 2, 0x44);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) static void pl2303_release(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	kfree(spriv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) static int pl2303_port_probe(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	struct pl2303_private *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	if (!priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	spin_lock_init(&priv->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	usb_set_serial_port_data(port, priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	port->port.drain_delay = 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) static int pl2303_port_remove(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	struct pl2303_private *priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	kfree(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) static int pl2303_set_control_lines(struct usb_serial_port *port, u8 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	struct usb_device *dev = port->serial->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	dev_dbg(&port->dev, "%s - %02x\n", __func__, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 				 SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 				 value, 0, NULL, 0, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 		dev_err(&port->dev, "%s - failed: %d\n", __func__, retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481)  * Returns the nearest supported baud rate that can be set directly without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482)  * using divisors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) static speed_t pl2303_get_supported_baud_rate(speed_t baud)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	static const speed_t baud_sup[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 		75, 150, 300, 600, 1200, 1800, 2400, 3600, 4800, 7200, 9600,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 		14400, 19200, 28800, 38400, 57600, 115200, 230400, 460800,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		614400, 921600, 1228800, 2457600, 3000000, 6000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	unsigned i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	for (i = 0; i < ARRAY_SIZE(baud_sup); ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		if (baud_sup[i] > baud)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	if (i == ARRAY_SIZE(baud_sup))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 		baud = baud_sup[i - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	else if (i > 0 && (baud_sup[i] - baud) > (baud - baud_sup[i - 1]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 		baud = baud_sup[i - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 		baud = baud_sup[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	return baud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510)  * NOTE: If unsupported baud rates are set directly, the PL2303 seems to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511)  *       use 9600 baud.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) static speed_t pl2303_encode_baud_rate_direct(unsigned char buf[4],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 								speed_t baud)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	put_unaligned_le32(baud, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	return baud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) static speed_t pl2303_encode_baud_rate_divisor(unsigned char buf[4],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 								speed_t baud)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	unsigned int baseline, mantissa, exponent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	 * Apparently the formula is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	 *   baudrate = 12M * 32 / (mantissa * 4^exponent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	 * where
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	 *   mantissa = buf[8:0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	 *   exponent = buf[11:9]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	baseline = 12000000 * 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	mantissa = baseline / baud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	if (mantissa == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 		mantissa = 1;	/* Avoid dividing by zero if baud > 32*12M. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	exponent = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	while (mantissa >= 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 		if (exponent < 7) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 			mantissa >>= 2;	/* divide by 4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 			exponent++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 			/* Exponent is maxed. Trim mantissa and leave. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 			mantissa = 511;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	buf[3] = 0x80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	buf[2] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	buf[1] = exponent << 1 | mantissa >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	buf[0] = mantissa & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	/* Calculate and return the exact baud rate. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	baud = (baseline / mantissa) >> (exponent << 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	return baud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) static void pl2303_encode_baud_rate(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 					struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 					u8 buf[4])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	struct usb_serial *serial = port->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	speed_t	baud_sup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	speed_t baud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	baud = tty_get_baud_rate(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	dev_dbg(&port->dev, "baud requested = %u\n", baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	if (!baud)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	if (spriv->type->max_baud_rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 		baud = min_t(speed_t, baud, spriv->type->max_baud_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	 * Use direct method for supported baud rates, otherwise use divisors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	 * Newer chip types do not support divisor encoding.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	if (spriv->type->no_divisors)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		baud_sup = baud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 		baud_sup = pl2303_get_supported_baud_rate(baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	if (baud == baud_sup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 		baud = pl2303_encode_baud_rate_direct(buf, baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 		baud = pl2303_encode_baud_rate_divisor(buf, baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	/* Save resulting baud rate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	tty_encode_baud_rate(tty, baud, baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	dev_dbg(&port->dev, "baud set = %u\n", baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) static int pl2303_get_line_request(struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 							unsigned char buf[7])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	struct usb_device *udev = port->serial->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 				GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 				0, 0, buf, 7, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	if (ret != 7) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 		dev_err(&port->dev, "%s - failed: %d\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 		if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	dev_dbg(&port->dev, "%s - %7ph\n", __func__, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) static int pl2303_set_line_request(struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 							unsigned char buf[7])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	struct usb_device *udev = port->serial->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 				SET_LINE_REQUEST, SET_LINE_REQUEST_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 				0, 0, buf, 7, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 		dev_err(&port->dev, "%s - failed: %d\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	dev_dbg(&port->dev, "%s - %7ph\n", __func__, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) static bool pl2303_termios_change(const struct ktermios *a, const struct ktermios *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	bool ixon_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	ixon_change = ((a->c_iflag ^ b->c_iflag) & (IXON | IXANY)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 			a->c_cc[VSTART] != b->c_cc[VSTART] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 			a->c_cc[VSTOP] != b->c_cc[VSTOP];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	return tty_termios_hw_change(a, b) || ixon_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) static bool pl2303_enable_xonxoff(struct tty_struct *tty, const struct pl2303_type_data *type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	if (!I_IXON(tty) || I_IXANY(tty))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	if (START_CHAR(tty) != 0x11 || STOP_CHAR(tty) != 0x13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	if (type->no_autoxonxoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) static void pl2303_set_termios(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 		struct usb_serial_port *port, struct ktermios *old_termios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	struct usb_serial *serial = port->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	struct pl2303_private *priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	unsigned char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	u8 control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	if (old_termios && !pl2303_termios_change(&tty->termios, old_termios))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	buf = kzalloc(7, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		/* Report back no change occurred */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 		if (old_termios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 			tty->termios = *old_termios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	pl2303_get_line_request(port, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	switch (C_CSIZE(tty)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	case CS5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 		buf[6] = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	case CS6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		buf[6] = 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	case CS7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 		buf[6] = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	case CS8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 		buf[6] = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	dev_dbg(&port->dev, "data bits = %d\n", buf[6]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	/* For reference buf[0]:buf[3] baud rate value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	pl2303_encode_baud_rate(tty, port, &buf[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	/* For reference buf[4]=0 is 1 stop bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	/* For reference buf[4]=1 is 1.5 stop bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	/* For reference buf[4]=2 is 2 stop bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	if (C_CSTOPB(tty)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 		 * NOTE: Comply with "real" UARTs / RS232:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 		 *       use 1.5 instead of 2 stop bits with 5 data bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 		if (C_CSIZE(tty) == CS5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 			buf[4] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 			dev_dbg(&port->dev, "stop bits = 1.5\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 			buf[4] = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 			dev_dbg(&port->dev, "stop bits = 2\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		buf[4] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 		dev_dbg(&port->dev, "stop bits = 1\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	if (C_PARENB(tty)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 		/* For reference buf[5]=0 is none parity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 		/* For reference buf[5]=1 is odd parity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		/* For reference buf[5]=2 is even parity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 		/* For reference buf[5]=3 is mark parity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 		/* For reference buf[5]=4 is space parity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 		if (C_PARODD(tty)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 			if (C_CMSPAR(tty)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 				buf[5] = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 				dev_dbg(&port->dev, "parity = mark\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 				buf[5] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 				dev_dbg(&port->dev, "parity = odd\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 			if (C_CMSPAR(tty)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 				buf[5] = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 				dev_dbg(&port->dev, "parity = space\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 				buf[5] = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 				dev_dbg(&port->dev, "parity = even\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		buf[5] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		dev_dbg(&port->dev, "parity = none\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	 * Some PL2303 are known to lose bytes if you change serial settings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	 * even to the same values as before. Thus we actually need to filter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	 * in this specific case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	 * Note that the tty_termios_hw_change check above is not sufficient
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	 * as a previously requested baud rate may differ from the one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	 * actually used (and stored in old_termios).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	 * NOTE: No additional locking needed for line_settings as it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	 *       only used in set_termios, which is serialised against itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	if (!old_termios || memcmp(buf, priv->line_settings, 7)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 		ret = pl2303_set_line_request(port, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 			memcpy(priv->line_settings, buf, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	/* change control lines if we are switching to or from B0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	spin_lock_irqsave(&priv->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	control = priv->line_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	if (C_BAUD(tty) == B0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 		priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	else if (old_termios && (old_termios->c_cflag & CBAUD) == B0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 		priv->line_control |= (CONTROL_DTR | CONTROL_RTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	if (control != priv->line_control) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 		control = priv->line_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		spin_unlock_irqrestore(&priv->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 		pl2303_set_control_lines(port, control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 		spin_unlock_irqrestore(&priv->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	if (C_CRTSCTS(tty)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 		if (spriv->quirks & PL2303_QUIRK_LEGACY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 			pl2303_update_reg(serial, 0, PL2303_FLOWCTRL_MASK, 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 		} else if (spriv->type == &pl2303_type_data[TYPE_HXN]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 			pl2303_update_reg(serial, PL2303_HXN_FLOWCTRL_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 					PL2303_HXN_FLOWCTRL_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 					PL2303_HXN_FLOWCTRL_RTS_CTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 			pl2303_update_reg(serial, 0, PL2303_FLOWCTRL_MASK, 0x60);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	} else if (pl2303_enable_xonxoff(tty, spriv->type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 		if (spriv->type == &pl2303_type_data[TYPE_HXN]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 			pl2303_update_reg(serial, PL2303_HXN_FLOWCTRL_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 					PL2303_HXN_FLOWCTRL_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 					PL2303_HXN_FLOWCTRL_XON_XOFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 			pl2303_update_reg(serial, 0, PL2303_FLOWCTRL_MASK, 0xc0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 		if (spriv->type == &pl2303_type_data[TYPE_HXN]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 			pl2303_update_reg(serial, PL2303_HXN_FLOWCTRL_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 					PL2303_HXN_FLOWCTRL_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 					PL2303_HXN_FLOWCTRL_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 			pl2303_update_reg(serial, 0, PL2303_FLOWCTRL_MASK, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) static void pl2303_dtr_rts(struct usb_serial_port *port, int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	struct pl2303_private *priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	u8 control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	spin_lock_irqsave(&priv->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	if (on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 		priv->line_control |= (CONTROL_DTR | CONTROL_RTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 		priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	control = priv->line_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	spin_unlock_irqrestore(&priv->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	pl2303_set_control_lines(port, control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) static void pl2303_close(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	usb_serial_generic_close(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	usb_kill_urb(port->interrupt_in_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	pl2303_set_break(port, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) static int pl2303_open(struct tty_struct *tty, struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	struct usb_serial *serial = port->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	if (spriv->quirks & PL2303_QUIRK_LEGACY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 		usb_clear_halt(serial->dev, port->write_urb->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 		usb_clear_halt(serial->dev, port->read_urb->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 		/* reset upstream data pipes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 		if (spriv->type == &pl2303_type_data[TYPE_HXN]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 			pl2303_vendor_write(serial, PL2303_HXN_RESET_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 					PL2303_HXN_RESET_UPSTREAM_PIPE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 					PL2303_HXN_RESET_DOWNSTREAM_PIPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 			pl2303_vendor_write(serial, 8, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 			pl2303_vendor_write(serial, 9, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	/* Setup termios */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	if (tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 		pl2303_set_termios(tty, port, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 		dev_err(&port->dev, "failed to submit interrupt urb: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 			result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	result = usb_serial_generic_open(tty, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 		usb_kill_urb(port->interrupt_in_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) static int pl2303_tiocmset(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 			   unsigned int set, unsigned int clear)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	struct pl2303_private *priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	u8 control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	spin_lock_irqsave(&priv->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	if (set & TIOCM_RTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 		priv->line_control |= CONTROL_RTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	if (set & TIOCM_DTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 		priv->line_control |= CONTROL_DTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	if (clear & TIOCM_RTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 		priv->line_control &= ~CONTROL_RTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	if (clear & TIOCM_DTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		priv->line_control &= ~CONTROL_DTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	control = priv->line_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	spin_unlock_irqrestore(&priv->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	ret = pl2303_set_control_lines(port, control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 		return usb_translate_errors(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) static int pl2303_tiocmget(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	struct pl2303_private *priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	unsigned int mcr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	unsigned int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	spin_lock_irqsave(&priv->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	mcr = priv->line_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	status = priv->line_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	spin_unlock_irqrestore(&priv->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	result = ((mcr & CONTROL_DTR)		? TIOCM_DTR : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 		  | ((mcr & CONTROL_RTS)	? TIOCM_RTS : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 		  | ((status & UART_CTS)	? TIOCM_CTS : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 		  | ((status & UART_DSR)	? TIOCM_DSR : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 		  | ((status & UART_RING)	? TIOCM_RI  : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 		  | ((status & UART_DCD)	? TIOCM_CD  : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	dev_dbg(&port->dev, "%s - result = %x\n", __func__, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) static int pl2303_carrier_raised(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	struct pl2303_private *priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	if (priv->line_status & UART_DCD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) static int pl2303_get_serial(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 			struct serial_struct *ss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	ss->type = PORT_16654;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	ss->line = port->minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	ss->port = port->port_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	ss->baud_base = 460800;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) static void pl2303_set_break(struct usb_serial_port *port, bool enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	struct usb_serial *serial = port->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	u16 state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	if (enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 		state = BREAK_ON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 		state = BREAK_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	dev_dbg(&port->dev, "%s - turning break %s\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 			state == BREAK_OFF ? "off" : "on");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 				 BREAK_REQUEST, BREAK_REQUEST_TYPE, state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 				 0, NULL, 0, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 		dev_err(&port->dev, "error sending break = %d\n", result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) static void pl2303_break_ctl(struct tty_struct *tty, int state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	pl2303_set_break(port, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) static void pl2303_update_line_status(struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 				      unsigned char *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 				      unsigned int actual_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	struct usb_serial *serial = port->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	struct pl2303_private *priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	struct tty_struct *tty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	unsigned int status_idx = UART_STATE_INDEX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	u8 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	u8 delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	if (spriv->quirks & PL2303_QUIRK_UART_STATE_IDX0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 		status_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	if (actual_length < status_idx + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	status = data[status_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	/* Save off the uart status for others to look at */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	spin_lock_irqsave(&priv->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	delta = priv->line_status ^ status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	priv->line_status = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	spin_unlock_irqrestore(&priv->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	if (status & UART_BREAK_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 		usb_serial_handle_break(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	if (delta & UART_STATE_MSR_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 		if (delta & UART_CTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 			port->icount.cts++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 		if (delta & UART_DSR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 			port->icount.dsr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 		if (delta & UART_RING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 			port->icount.rng++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 		if (delta & UART_DCD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 			port->icount.dcd++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 			tty = tty_port_tty_get(&port->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 			if (tty) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 				usb_serial_handle_dcd_change(port, tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 							status & UART_DCD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 				tty_kref_put(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 		wake_up_interruptible(&port->port.delta_msr_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) static void pl2303_read_int_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	struct usb_serial_port *port =  urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	unsigned char *data = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	unsigned int actual_length = urb->actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 		/* success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	case -ECONNRESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	case -ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 		/* this urb is terminated, clean up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 		dev_dbg(&port->dev, "%s - urb shutting down with status: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 			__func__, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 		dev_dbg(&port->dev, "%s - nonzero urb status received: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 			__func__, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	usb_serial_debug_data(&port->dev, __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 			      urb->actual_length, urb->transfer_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	pl2303_update_line_status(port, data, actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	retval = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 		dev_err(&port->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 			"%s - usb_submit_urb failed with result %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 			__func__, retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) static void pl2303_process_read_urb(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	struct usb_serial_port *port = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	struct pl2303_private *priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	unsigned char *data = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	char tty_flag = TTY_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	u8 line_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	/* update line status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	spin_lock_irqsave(&priv->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	line_status = priv->line_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	priv->line_status &= ~UART_STATE_TRANSIENT_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	spin_unlock_irqrestore(&priv->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	if (!urb->actual_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	 * Break takes precedence over parity, which takes precedence over
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	 * framing errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	if (line_status & UART_BREAK_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 		tty_flag = TTY_BREAK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	else if (line_status & UART_PARITY_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 		tty_flag = TTY_PARITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	else if (line_status & UART_FRAME_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 		tty_flag = TTY_FRAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	if (tty_flag != TTY_NORMAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 		dev_dbg(&port->dev, "%s - tty_flag = %d\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 								tty_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	/* overrun is special, not associated with a char */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	if (line_status & UART_OVERRUN_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 		tty_insert_flip_char(&port->port, 0, TTY_OVERRUN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	if (port->sysrq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 		for (i = 0; i < urb->actual_length; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 			if (!usb_serial_handle_sysrq_char(port, data[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 				tty_insert_flip_char(&port->port, data[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 						tty_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 		tty_insert_flip_string_fixed_flag(&port->port, data, tty_flag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 							urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	tty_flip_buffer_push(&port->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) static struct usb_serial_driver pl2303_device = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 		.owner =	THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 		.name =		"pl2303",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	.id_table =		id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	.num_bulk_in =		1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	.num_bulk_out =		1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	.num_interrupt_in =	0,	/* see pl2303_calc_num_ports */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	.bulk_in_size =		256,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	.bulk_out_size =	256,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	.open =			pl2303_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	.close =		pl2303_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	.dtr_rts =		pl2303_dtr_rts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	.carrier_raised =	pl2303_carrier_raised,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	.get_serial =		pl2303_get_serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	.break_ctl =		pl2303_break_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	.set_termios =		pl2303_set_termios,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	.tiocmget =		pl2303_tiocmget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	.tiocmset =		pl2303_tiocmset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	.tiocmiwait =		usb_serial_generic_tiocmiwait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	.process_read_urb =	pl2303_process_read_urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	.read_int_callback =	pl2303_read_int_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	.probe =		pl2303_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	.calc_num_ports =	pl2303_calc_num_ports,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	.attach =		pl2303_startup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	.release =		pl2303_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	.port_probe =		pl2303_port_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	.port_remove =		pl2303_port_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) static struct usb_serial_driver * const serial_drivers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	&pl2303_device, NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) module_usb_serial_driver(serial_drivers, id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) MODULE_DESCRIPTION("Prolific PL2303 USB to serial adaptor driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) MODULE_LICENSE("GPL v2");