^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) * Silicon Laboratories CP210x USB to RS232 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) 2005 Craig Shelley (craig@microtron.org.uk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Support to set flow control line levels using TIOCMGET and TIOCMSET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * thanks to Karl Hiramoto karl@hiramoto.org. RTSCTS hardware flow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * control thanks to Munir Nassar nassarmu@real-time.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/tty.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/tty_flip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/usb/serial.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/gpio/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define DRIVER_DESC "Silicon Labs CP210x RS232 serial adaptor driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * Function Prototypes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static void cp210x_close(struct usb_serial_port *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static void cp210x_get_termios(struct tty_struct *, struct usb_serial_port *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static void cp210x_get_termios_port(struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) tcflag_t *cflagp, unsigned int *baudp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static void cp210x_change_speed(struct tty_struct *, struct usb_serial_port *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct ktermios *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static void cp210x_set_termios(struct tty_struct *, struct usb_serial_port *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct ktermios*);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static bool cp210x_tx_empty(struct usb_serial_port *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static int cp210x_tiocmget(struct tty_struct *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static int cp210x_tiocmset(struct tty_struct *, unsigned int, unsigned int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static int cp210x_tiocmset_port(struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) unsigned int, unsigned int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static void cp210x_break_ctl(struct tty_struct *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static int cp210x_attach(struct usb_serial *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static void cp210x_disconnect(struct usb_serial *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static void cp210x_release(struct usb_serial *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static int cp210x_port_probe(struct usb_serial_port *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static int cp210x_port_remove(struct usb_serial_port *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static void cp210x_dtr_rts(struct usb_serial_port *p, int on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static void cp210x_process_read_urb(struct urb *urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static void cp210x_enable_event_mode(struct usb_serial_port *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static void cp210x_disable_event_mode(struct usb_serial_port *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static const struct usb_device_id id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) { USB_DEVICE(0x0404, 0x034C) }, /* NCR Retail IO Box */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) { USB_DEVICE(0x045B, 0x0053) }, /* Renesas RX610 RX-Stick */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) { USB_DEVICE(0x0471, 0x066A) }, /* AKTAKOM ACE-1001 cable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) { USB_DEVICE(0x0489, 0xE000) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) { USB_DEVICE(0x0489, 0xE003) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) { USB_DEVICE(0x0745, 0x1000) }, /* CipherLab USB CCD Barcode Scanner 1000 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) { USB_DEVICE(0x0846, 0x1100) }, /* NetGear Managed Switch M4100 series, M5300 series, M7100 series */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) { USB_DEVICE(0x08e6, 0x5501) }, /* Gemalto Prox-PU/CU contactless smartcard reader */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) { USB_DEVICE(0x08FD, 0x000A) }, /* Digianswer A/S , ZigBee/802.15.4 MAC Device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) { USB_DEVICE(0x0908, 0x01FF) }, /* Siemens RUGGEDCOM USB Serial Console */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) { USB_DEVICE(0x0988, 0x0578) }, /* Teraoka AD2000 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) { USB_DEVICE(0x0B00, 0x3070) }, /* Ingenico 3070 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) { USB_DEVICE(0x0BED, 0x1100) }, /* MEI (TM) Cashflow-SC Bill/Voucher Acceptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) { USB_DEVICE(0x0BED, 0x1101) }, /* MEI series 2000 Combo Acceptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) { USB_DEVICE(0x0FCF, 0x1003) }, /* Dynastream ANT development board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) { USB_DEVICE(0x0FCF, 0x1004) }, /* Dynastream ANT2USB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) { USB_DEVICE(0x0FCF, 0x1006) }, /* Dynastream ANT development board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) { USB_DEVICE(0x0FDE, 0xCA05) }, /* OWL Wireless Electricity Monitor CM-160 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) { USB_DEVICE(0x106F, 0x0003) }, /* CPI / Money Controls Bulk Coin Recycler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) { USB_DEVICE(0x10A6, 0xAA26) }, /* Knock-off DCU-11 cable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) { USB_DEVICE(0x10B5, 0xAC70) }, /* Nokia CA-42 USB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) { USB_DEVICE(0x10C4, 0x0F91) }, /* Vstabi */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) { USB_DEVICE(0x10C4, 0x1101) }, /* Arkham Technology DS101 Bus Monitor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) { USB_DEVICE(0x10C4, 0x1601) }, /* Arkham Technology DS101 Adapter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) { USB_DEVICE(0x10C4, 0x800A) }, /* SPORTident BSM7-D-USB main station */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) { USB_DEVICE(0x10C4, 0x803B) }, /* Pololu USB-serial converter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) { USB_DEVICE(0x10C4, 0x8044) }, /* Cygnal Debug Adapter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) { USB_DEVICE(0x10C4, 0x804E) }, /* Software Bisque Paramount ME build-in converter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) { USB_DEVICE(0x10C4, 0x8053) }, /* Enfora EDG1228 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) { USB_DEVICE(0x10C4, 0x8054) }, /* Enfora GSM2228 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) { USB_DEVICE(0x10C4, 0x8056) }, /* Lorenz Messtechnik devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) { USB_DEVICE(0x10C4, 0x8066) }, /* Argussoft In-System Programmer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) { USB_DEVICE(0x10C4, 0x806F) }, /* IMS USB to RS422 Converter Cable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) { USB_DEVICE(0x10C4, 0x807A) }, /* Crumb128 board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) { USB_DEVICE(0x10C4, 0x80C4) }, /* Cygnal Integrated Products, Inc., Optris infrared thermometer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) { USB_DEVICE(0x10C4, 0x80CA) }, /* Degree Controls Inc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) { USB_DEVICE(0x10C4, 0x80DD) }, /* Tracient RFID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) { USB_DEVICE(0x10C4, 0x80F6) }, /* Suunto sports instrument */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) { USB_DEVICE(0x10C4, 0x8115) }, /* Arygon NFC/Mifare Reader */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) { USB_DEVICE(0x10C4, 0x813D) }, /* Burnside Telecom Deskmobile */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) { USB_DEVICE(0x10C4, 0x813F) }, /* Tams Master Easy Control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) { USB_DEVICE(0x10C4, 0x814A) }, /* West Mountain Radio RIGblaster P&P */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) { USB_DEVICE(0x10C4, 0x814B) }, /* West Mountain Radio RIGtalk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) { USB_DEVICE(0x2405, 0x0003) }, /* West Mountain Radio RIGblaster Advantage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) { USB_DEVICE(0x10C4, 0x8156) }, /* B&G H3000 link cable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) { USB_DEVICE(0x10C4, 0x815E) }, /* Helicomm IP-Link 1220-DVM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) { USB_DEVICE(0x10C4, 0x815F) }, /* Timewave HamLinkUSB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) { USB_DEVICE(0x10C4, 0x817C) }, /* CESINEL MEDCAL N Power Quality Monitor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) { USB_DEVICE(0x10C4, 0x817D) }, /* CESINEL MEDCAL NT Power Quality Monitor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) { USB_DEVICE(0x10C4, 0x817E) }, /* CESINEL MEDCAL S Power Quality Monitor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) { USB_DEVICE(0x10C4, 0x818B) }, /* AVIT Research USB to TTL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) { USB_DEVICE(0x10C4, 0x819F) }, /* MJS USB Toslink Switcher */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) { USB_DEVICE(0x10C4, 0x81A6) }, /* ThinkOptics WavIt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) { USB_DEVICE(0x10C4, 0x81A9) }, /* Multiplex RC Interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) { USB_DEVICE(0x10C4, 0x81AC) }, /* MSD Dash Hawk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) { USB_DEVICE(0x10C4, 0x81AD) }, /* INSYS USB Modem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) { USB_DEVICE(0x10C4, 0x81C8) }, /* Lipowsky Industrie Elektronik GmbH, Baby-JTAG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) { USB_DEVICE(0x10C4, 0x81D7) }, /* IAI Corp. RCB-CV-USB USB to RS485 Adaptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) { USB_DEVICE(0x10C4, 0x81E2) }, /* Lipowsky Industrie Elektronik GmbH, Baby-LIN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) { USB_DEVICE(0x10C4, 0x81E7) }, /* Aerocomm Radio */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) { USB_DEVICE(0x10C4, 0x81E8) }, /* Zephyr Bioharness */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) { USB_DEVICE(0x10C4, 0x81F2) }, /* C1007 HF band RFID controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) { USB_DEVICE(0x10C4, 0x822B) }, /* Modem EDGE(GSM) Comander 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) { USB_DEVICE(0x10C4, 0x826B) }, /* Cygnal Integrated Products, Inc., Fasttrax GPS demonstration module */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) { USB_DEVICE(0x10C4, 0x8281) }, /* Nanotec Plug & Drive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) { USB_DEVICE(0x10C4, 0x8293) }, /* Telegesis ETRX2USB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) { USB_DEVICE(0x10C4, 0x82EF) }, /* CESINEL FALCO 6105 AC Power Supply */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) { USB_DEVICE(0x10C4, 0x82F1) }, /* CESINEL MEDCAL EFD Earth Fault Detector */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) { USB_DEVICE(0x10C4, 0x82F2) }, /* CESINEL MEDCAL ST Network Analyzer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) { USB_DEVICE(0x10C4, 0x82F4) }, /* Starizona MicroTouch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) { USB_DEVICE(0x10C4, 0x82F9) }, /* Procyon AVS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) { USB_DEVICE(0x10C4, 0x8341) }, /* Siemens MC35PU GPRS Modem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) { USB_DEVICE(0x10C4, 0x8382) }, /* Cygnal Integrated Products, Inc. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) { USB_DEVICE(0x10C4, 0x83A8) }, /* Amber Wireless AMB2560 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) { USB_DEVICE(0x10C4, 0x83AA) }, /* Mark-10 Digital Force Gauge */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) { USB_DEVICE(0x10C4, 0x83D8) }, /* DekTec DTA Plus VHF/UHF Booster/Attenuator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) { USB_DEVICE(0x10C4, 0x8411) }, /* Kyocera GPS Module */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) { USB_DEVICE(0x10C4, 0x8418) }, /* IRZ Automation Teleport SG-10 GSM/GPRS Modem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) { USB_DEVICE(0x10C4, 0x846E) }, /* BEI USB Sensor Interface (VCP) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) { USB_DEVICE(0x10C4, 0x8470) }, /* Juniper Networks BX Series System Console */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) { USB_DEVICE(0x10C4, 0x8477) }, /* Balluff RFID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) { USB_DEVICE(0x10C4, 0x84B6) }, /* Starizona Hyperion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) { USB_DEVICE(0x10C4, 0x851E) }, /* CESINEL MEDCAL PT Network Analyzer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) { USB_DEVICE(0x10C4, 0x85A7) }, /* LifeScan OneTouch Verio IQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) { USB_DEVICE(0x10C4, 0x85B8) }, /* CESINEL ReCon T Energy Logger */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) { USB_DEVICE(0x10C4, 0x85EA) }, /* AC-Services IBUS-IF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) { USB_DEVICE(0x10C4, 0x85EB) }, /* AC-Services CIS-IBUS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) { USB_DEVICE(0x10C4, 0x85F8) }, /* Virtenio Preon32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) { USB_DEVICE(0x10C4, 0x8664) }, /* AC-Services CAN-IF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) { USB_DEVICE(0x10C4, 0x8665) }, /* AC-Services OBD-IF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) { USB_DEVICE(0x10C4, 0x8856) }, /* CEL EM357 ZigBee USB Stick - LR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) { USB_DEVICE(0x10C4, 0x8857) }, /* CEL EM357 ZigBee USB Stick */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) { USB_DEVICE(0x10C4, 0x88A4) }, /* MMB Networks ZigBee USB Device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) { USB_DEVICE(0x10C4, 0x88A5) }, /* Planet Innovation Ingeni ZigBee USB Device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) { USB_DEVICE(0x10C4, 0x88D8) }, /* Acuity Brands nLight Air Adapter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) { USB_DEVICE(0x10C4, 0x88FB) }, /* CESINEL MEDCAL STII Network Analyzer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) { USB_DEVICE(0x10C4, 0x8938) }, /* CESINEL MEDCAL S II Network Analyzer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) { USB_DEVICE(0x10C4, 0x8946) }, /* Ketra N1 Wireless Interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) { USB_DEVICE(0x10C4, 0x8962) }, /* Brim Brothers charging dock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) { USB_DEVICE(0x10C4, 0x8977) }, /* CEL MeshWorks DevKit Device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) { USB_DEVICE(0x10C4, 0x8998) }, /* KCF Technologies PRN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) { USB_DEVICE(0x10C4, 0x89A4) }, /* CESINEL FTBC Flexible Thyristor Bridge Controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) { USB_DEVICE(0x10C4, 0x89FB) }, /* Qivicon ZigBee USB Radio Stick */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) { USB_DEVICE(0x10C4, 0x8A2A) }, /* HubZ dual ZigBee and Z-Wave dongle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) { USB_DEVICE(0x10C4, 0x8A5B) }, /* CEL EM3588 ZigBee USB Stick */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) { USB_DEVICE(0x10C4, 0x8A5E) }, /* CEL EM3588 ZigBee USB Stick Long Range */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) { USB_DEVICE(0x10C4, 0x8B34) }, /* Qivicon ZigBee USB Radio Stick */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) { USB_DEVICE(0x10C4, 0xEA63) }, /* Silicon Labs Windows Update (CP2101-4/CP2102N) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) { USB_DEVICE(0x10C4, 0xEA70) }, /* Silicon Labs factory default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) { USB_DEVICE(0x10C4, 0xEA71) }, /* Infinity GPS-MIC-1 Radio Monophone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) { USB_DEVICE(0x10C4, 0xEA7A) }, /* Silicon Labs Windows Update (CP2105) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) { USB_DEVICE(0x10C4, 0xEA7B) }, /* Silicon Labs Windows Update (CP2108) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) { USB_DEVICE(0x10C4, 0xF001) }, /* Elan Digital Systems USBscope50 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) { USB_DEVICE(0x10C4, 0xF002) }, /* Elan Digital Systems USBwave12 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) { USB_DEVICE(0x10C4, 0xF003) }, /* Elan Digital Systems USBpulse100 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) { USB_DEVICE(0x10C4, 0xF004) }, /* Elan Digital Systems USBcount50 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) { USB_DEVICE(0x10C5, 0xEA61) }, /* Silicon Labs MobiData GPRS USB Modem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) { USB_DEVICE(0x10CE, 0xEA6A) }, /* Silicon Labs MobiData GPRS USB Modem 100EU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) { USB_DEVICE(0x12B8, 0xEC60) }, /* Link G4 ECU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) { USB_DEVICE(0x12B8, 0xEC62) }, /* Link G4+ ECU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) { USB_DEVICE(0x1555, 0x0004) }, /* Owen AC4 USB-RS485 Converter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) { USB_DEVICE(0x155A, 0x1006) }, /* ELDAT Easywave RX09 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) { USB_DEVICE(0x166A, 0x0201) }, /* Clipsal 5500PACA C-Bus Pascal Automation Controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) { USB_DEVICE(0x166A, 0x0301) }, /* Clipsal 5800PC C-Bus Wireless PC Interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) { USB_DEVICE(0x166A, 0x0303) }, /* Clipsal 5500PCU C-Bus USB interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) { USB_DEVICE(0x166A, 0x0304) }, /* Clipsal 5000CT2 C-Bus Black and White Touchscreen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) { USB_DEVICE(0x166A, 0x0305) }, /* Clipsal C-5000CT2 C-Bus Spectrum Colour Touchscreen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) { USB_DEVICE(0x166A, 0x0401) }, /* Clipsal L51xx C-Bus Architectural Dimmer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) { USB_DEVICE(0x166A, 0x0101) }, /* Clipsal 5560884 C-Bus Multi-room Audio Matrix Switcher */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) { USB_DEVICE(0x16C0, 0x09B0) }, /* Lunatico Seletek */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) { USB_DEVICE(0x16C0, 0x09B1) }, /* Lunatico Seletek */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) { USB_DEVICE(0x16DC, 0x0010) }, /* W-IE-NE-R Plein & Baus GmbH PL512 Power Supply */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) { USB_DEVICE(0x16DC, 0x0011) }, /* W-IE-NE-R Plein & Baus GmbH RCM Remote Control for MARATON Power Supply */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) { USB_DEVICE(0x16DC, 0x0012) }, /* W-IE-NE-R Plein & Baus GmbH MPOD Multi Channel Power Supply */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) { USB_DEVICE(0x16DC, 0x0015) }, /* W-IE-NE-R Plein & Baus GmbH CML Control, Monitoring and Data Logger */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) { USB_DEVICE(0x17A8, 0x0001) }, /* Kamstrup Optical Eye/3-wire */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) { USB_DEVICE(0x17A8, 0x0005) }, /* Kamstrup M-Bus Master MultiPort 250D */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) { USB_DEVICE(0x17F4, 0xAAAA) }, /* Wavesense Jazz blood glucose meter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) { USB_DEVICE(0x1843, 0x0200) }, /* Vaisala USB Instrument Cable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) { USB_DEVICE(0x18EF, 0xE00F) }, /* ELV USB-I2C-Interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) { USB_DEVICE(0x18EF, 0xE025) }, /* ELV Marble Sound Board 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) { USB_DEVICE(0x18EF, 0xE030) }, /* ELV ALC 8xxx Battery Charger */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) { USB_DEVICE(0x18EF, 0xE032) }, /* ELV TFD500 Data Logger */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) { USB_DEVICE(0x1901, 0x0190) }, /* GE B850 CP2105 Recorder interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) { USB_DEVICE(0x1901, 0x0193) }, /* GE B650 CP2104 PMC interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) { USB_DEVICE(0x1901, 0x0194) }, /* GE Healthcare Remote Alarm Box */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) { USB_DEVICE(0x1901, 0x0195) }, /* GE B850/B650/B450 CP2104 DP UART interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) { USB_DEVICE(0x1901, 0x0196) }, /* GE B850 CP2105 DP UART interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) { USB_DEVICE(0x1901, 0x0197) }, /* GE CS1000 M.2 Key E serial interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) { USB_DEVICE(0x1901, 0x0198) }, /* GE CS1000 Display serial interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) { USB_DEVICE(0x199B, 0xBA30) }, /* LORD WSDA-200-USB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) { USB_DEVICE(0x19CF, 0x3000) }, /* Parrot NMEA GPS Flight Recorder */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) { USB_DEVICE(0x1ADB, 0x0001) }, /* Schweitzer Engineering C662 Cable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) { USB_DEVICE(0x1B1C, 0x1C00) }, /* Corsair USB Dongle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) { USB_DEVICE(0x1BA4, 0x0002) }, /* Silicon Labs 358x factory default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) { USB_DEVICE(0x1BE3, 0x07A6) }, /* WAGO 750-923 USB Service Cable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) { USB_DEVICE(0x1D6F, 0x0010) }, /* Seluxit ApS RF Dongle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) { USB_DEVICE(0x1E29, 0x0102) }, /* Festo CPX-USB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) { USB_DEVICE(0x1E29, 0x0501) }, /* Festo CMSP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) { USB_DEVICE(0x1FB9, 0x0100) }, /* Lake Shore Model 121 Current Source */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) { USB_DEVICE(0x1FB9, 0x0200) }, /* Lake Shore Model 218A Temperature Monitor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) { USB_DEVICE(0x1FB9, 0x0201) }, /* Lake Shore Model 219 Temperature Monitor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) { USB_DEVICE(0x1FB9, 0x0202) }, /* Lake Shore Model 233 Temperature Transmitter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) { USB_DEVICE(0x1FB9, 0x0203) }, /* Lake Shore Model 235 Temperature Transmitter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) { USB_DEVICE(0x1FB9, 0x0300) }, /* Lake Shore Model 335 Temperature Controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) { USB_DEVICE(0x1FB9, 0x0301) }, /* Lake Shore Model 336 Temperature Controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) { USB_DEVICE(0x1FB9, 0x0302) }, /* Lake Shore Model 350 Temperature Controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) { USB_DEVICE(0x1FB9, 0x0303) }, /* Lake Shore Model 371 AC Bridge */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) { USB_DEVICE(0x1FB9, 0x0400) }, /* Lake Shore Model 411 Handheld Gaussmeter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) { USB_DEVICE(0x1FB9, 0x0401) }, /* Lake Shore Model 425 Gaussmeter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) { USB_DEVICE(0x1FB9, 0x0402) }, /* Lake Shore Model 455A Gaussmeter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) { USB_DEVICE(0x1FB9, 0x0403) }, /* Lake Shore Model 475A Gaussmeter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) { USB_DEVICE(0x1FB9, 0x0404) }, /* Lake Shore Model 465 Three Axis Gaussmeter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) { USB_DEVICE(0x1FB9, 0x0600) }, /* Lake Shore Model 625A Superconducting MPS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) { USB_DEVICE(0x1FB9, 0x0601) }, /* Lake Shore Model 642A Magnet Power Supply */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) { USB_DEVICE(0x1FB9, 0x0602) }, /* Lake Shore Model 648 Magnet Power Supply */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) { USB_DEVICE(0x1FB9, 0x0700) }, /* Lake Shore Model 737 VSM Controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) { USB_DEVICE(0x1FB9, 0x0701) }, /* Lake Shore Model 776 Hall Matrix */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) { USB_DEVICE(0x2184, 0x0030) }, /* GW Instek GDM-834x Digital Multimeter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) { USB_DEVICE(0x2626, 0xEA60) }, /* Aruba Networks 7xxx USB Serial Console */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) { USB_DEVICE(0x3195, 0xF190) }, /* Link Instruments MSO-19 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) { USB_DEVICE(0x3195, 0xF280) }, /* Link Instruments MSO-28 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) { USB_DEVICE(0x3195, 0xF281) }, /* Link Instruments MSO-28 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) { USB_DEVICE(0x3923, 0x7A0B) }, /* National Instruments USB Serial Console */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) { USB_DEVICE(0x413C, 0x9500) }, /* DW700 GPS USB interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) { } /* Terminating Entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) MODULE_DEVICE_TABLE(usb, id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct cp210x_serial_private {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) #ifdef CONFIG_GPIOLIB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) struct gpio_chip gc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) bool gpio_registered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) u8 gpio_pushpull;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) u8 gpio_altfunc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) u8 gpio_input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) u8 partnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) speed_t min_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) speed_t max_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) bool use_actual_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) bool no_event_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) enum cp210x_event_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) ES_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) ES_ESCAPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) ES_LSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) ES_LSR_DATA_0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) ES_LSR_DATA_1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) ES_MSR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) struct cp210x_port_private {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) u8 bInterfaceNumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) bool has_swapped_line_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) bool event_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) enum cp210x_event_state event_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) u8 lsr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static struct usb_serial_driver cp210x_device = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) .name = "cp210x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) .id_table = id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) .num_ports = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) .bulk_in_size = 256,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) .bulk_out_size = 256,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) .open = cp210x_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) .close = cp210x_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) .break_ctl = cp210x_break_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) .set_termios = cp210x_set_termios,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) .tx_empty = cp210x_tx_empty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) .throttle = usb_serial_generic_throttle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) .unthrottle = usb_serial_generic_unthrottle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) .tiocmget = cp210x_tiocmget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) .tiocmset = cp210x_tiocmset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) .get_icount = usb_serial_generic_get_icount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) .attach = cp210x_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) .disconnect = cp210x_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) .release = cp210x_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) .port_probe = cp210x_port_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) .port_remove = cp210x_port_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) .dtr_rts = cp210x_dtr_rts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) .process_read_urb = cp210x_process_read_urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static struct usb_serial_driver * const serial_drivers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) &cp210x_device, NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) /* Config request types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) #define REQTYPE_HOST_TO_INTERFACE 0x41
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) #define REQTYPE_INTERFACE_TO_HOST 0xc1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) #define REQTYPE_HOST_TO_DEVICE 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) #define REQTYPE_DEVICE_TO_HOST 0xc0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) /* Config request codes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) #define CP210X_IFC_ENABLE 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) #define CP210X_SET_BAUDDIV 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) #define CP210X_GET_BAUDDIV 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) #define CP210X_SET_LINE_CTL 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) #define CP210X_GET_LINE_CTL 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) #define CP210X_SET_BREAK 0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) #define CP210X_IMM_CHAR 0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) #define CP210X_SET_MHS 0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) #define CP210X_GET_MDMSTS 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) #define CP210X_SET_XON 0x09
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) #define CP210X_SET_XOFF 0x0A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) #define CP210X_SET_EVENTMASK 0x0B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) #define CP210X_GET_EVENTMASK 0x0C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) #define CP210X_SET_CHAR 0x0D
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) #define CP210X_GET_CHARS 0x0E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) #define CP210X_GET_PROPS 0x0F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) #define CP210X_GET_COMM_STATUS 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) #define CP210X_RESET 0x11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) #define CP210X_PURGE 0x12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) #define CP210X_SET_FLOW 0x13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) #define CP210X_GET_FLOW 0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) #define CP210X_EMBED_EVENTS 0x15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) #define CP210X_GET_EVENTSTATE 0x16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) #define CP210X_SET_CHARS 0x19
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) #define CP210X_GET_BAUDRATE 0x1D
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) #define CP210X_SET_BAUDRATE 0x1E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) #define CP210X_VENDOR_SPECIFIC 0xFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) /* CP210X_IFC_ENABLE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) #define UART_ENABLE 0x0001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) #define UART_DISABLE 0x0000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) /* CP210X_(SET|GET)_BAUDDIV */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) #define BAUD_RATE_GEN_FREQ 0x384000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) /* CP210X_(SET|GET)_LINE_CTL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) #define BITS_DATA_MASK 0X0f00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) #define BITS_DATA_5 0X0500
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) #define BITS_DATA_6 0X0600
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) #define BITS_DATA_7 0X0700
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) #define BITS_DATA_8 0X0800
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) #define BITS_DATA_9 0X0900
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) #define BITS_PARITY_MASK 0x00f0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) #define BITS_PARITY_NONE 0x0000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) #define BITS_PARITY_ODD 0x0010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) #define BITS_PARITY_EVEN 0x0020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) #define BITS_PARITY_MARK 0x0030
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) #define BITS_PARITY_SPACE 0x0040
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) #define BITS_STOP_MASK 0x000f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) #define BITS_STOP_1 0x0000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) #define BITS_STOP_1_5 0x0001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) #define BITS_STOP_2 0x0002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) /* CP210X_SET_BREAK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) #define BREAK_ON 0x0001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) #define BREAK_OFF 0x0000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) /* CP210X_(SET_MHS|GET_MDMSTS) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) #define CONTROL_DTR 0x0001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) #define CONTROL_RTS 0x0002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) #define CONTROL_CTS 0x0010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) #define CONTROL_DSR 0x0020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) #define CONTROL_RING 0x0040
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) #define CONTROL_DCD 0x0080
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) #define CONTROL_WRITE_DTR 0x0100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) #define CONTROL_WRITE_RTS 0x0200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) /* CP210X_VENDOR_SPECIFIC values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) #define CP210X_READ_2NCONFIG 0x000E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) #define CP210X_READ_LATCH 0x00C2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) #define CP210X_GET_PARTNUM 0x370B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) #define CP210X_GET_PORTCONFIG 0x370C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) #define CP210X_GET_DEVICEMODE 0x3711
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) #define CP210X_WRITE_LATCH 0x37E1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) /* Part number definitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) #define CP210X_PARTNUM_CP2101 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) #define CP210X_PARTNUM_CP2102 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) #define CP210X_PARTNUM_CP2103 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) #define CP210X_PARTNUM_CP2104 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) #define CP210X_PARTNUM_CP2105 0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) #define CP210X_PARTNUM_CP2108 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) #define CP210X_PARTNUM_CP2102N_QFN28 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) #define CP210X_PARTNUM_CP2102N_QFN24 0x21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) #define CP210X_PARTNUM_CP2102N_QFN20 0x22
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) #define CP210X_PARTNUM_UNKNOWN 0xFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) /* CP210X_GET_COMM_STATUS returns these 0x13 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) struct cp210x_comm_status {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) __le32 ulErrors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) __le32 ulHoldReasons;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) __le32 ulAmountInInQueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) __le32 ulAmountInOutQueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) u8 bEofReceived;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) u8 bWaitForImmediate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) u8 bReserved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) } __packed;
^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) * CP210X_PURGE - 16 bits passed in wValue of USB request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) * SiLabs app note AN571 gives a strange description of the 4 bits:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) * bit 0 or bit 2 clears the transmit queue and 1 or 3 receive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) * writing 1 to all, however, purges cp2108 well enough to avoid the hang.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) #define PURGE_ALL 0x000f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) /* CP210X_EMBED_EVENTS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) #define CP210X_ESCCHAR 0xec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) #define CP210X_LSR_OVERRUN BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) #define CP210X_LSR_PARITY BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) #define CP210X_LSR_FRAME BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) #define CP210X_LSR_BREAK BIT(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) /* CP210X_GET_FLOW/CP210X_SET_FLOW read/write these 0x10 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) struct cp210x_flow_ctl {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) __le32 ulControlHandshake;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) __le32 ulFlowReplace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) __le32 ulXonLimit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) __le32 ulXoffLimit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) /* cp210x_flow_ctl::ulControlHandshake */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) #define CP210X_SERIAL_DTR_MASK GENMASK(1, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) #define CP210X_SERIAL_DTR_SHIFT(_mode) (_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) #define CP210X_SERIAL_CTS_HANDSHAKE BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) #define CP210X_SERIAL_DSR_HANDSHAKE BIT(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) #define CP210X_SERIAL_DCD_HANDSHAKE BIT(5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) #define CP210X_SERIAL_DSR_SENSITIVITY BIT(6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) /* values for cp210x_flow_ctl::ulControlHandshake::CP210X_SERIAL_DTR_MASK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) #define CP210X_SERIAL_DTR_INACTIVE 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) #define CP210X_SERIAL_DTR_ACTIVE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) #define CP210X_SERIAL_DTR_FLOW_CTL 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) /* cp210x_flow_ctl::ulFlowReplace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) #define CP210X_SERIAL_AUTO_TRANSMIT BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) #define CP210X_SERIAL_AUTO_RECEIVE BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) #define CP210X_SERIAL_ERROR_CHAR BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) #define CP210X_SERIAL_NULL_STRIPPING BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) #define CP210X_SERIAL_BREAK_CHAR BIT(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) #define CP210X_SERIAL_RTS_MASK GENMASK(7, 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) #define CP210X_SERIAL_RTS_SHIFT(_mode) (_mode << 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) #define CP210X_SERIAL_XOFF_CONTINUE BIT(31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) /* values for cp210x_flow_ctl::ulFlowReplace::CP210X_SERIAL_RTS_MASK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) #define CP210X_SERIAL_RTS_INACTIVE 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) #define CP210X_SERIAL_RTS_ACTIVE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) #define CP210X_SERIAL_RTS_FLOW_CTL 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) /* CP210X_VENDOR_SPECIFIC, CP210X_GET_DEVICEMODE call reads these 0x2 bytes. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) struct cp210x_pin_mode {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) u8 eci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) u8 sci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) #define CP210X_PIN_MODE_MODEM 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) #define CP210X_PIN_MODE_GPIO BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) * CP210X_VENDOR_SPECIFIC, CP210X_GET_PORTCONFIG call reads these 0xf bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) * on a CP2105 chip. Structure needs padding due to unused/unspecified bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) struct cp210x_dual_port_config {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) __le16 gpio_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) u8 __pad0[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) __le16 reset_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) u8 __pad1[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) __le16 suspend_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) u8 sci_cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) u8 eci_cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) u8 device_cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) * CP210X_VENDOR_SPECIFIC, CP210X_GET_PORTCONFIG call reads these 0xd bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) * on a CP2104 chip. Structure needs padding due to unused/unspecified bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) struct cp210x_single_port_config {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) __le16 gpio_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) u8 __pad0[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) __le16 reset_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) u8 __pad1[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) __le16 suspend_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) u8 device_cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) /* GPIO modes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) #define CP210X_SCI_GPIO_MODE_OFFSET 9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) #define CP210X_SCI_GPIO_MODE_MASK GENMASK(11, 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) #define CP210X_ECI_GPIO_MODE_OFFSET 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) #define CP210X_ECI_GPIO_MODE_MASK GENMASK(3, 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) #define CP210X_GPIO_MODE_OFFSET 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) #define CP210X_GPIO_MODE_MASK GENMASK(11, 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) /* CP2105 port configuration values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) #define CP2105_GPIO0_TXLED_MODE BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) #define CP2105_GPIO1_RXLED_MODE BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) #define CP2105_GPIO1_RS485_MODE BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) /* CP2104 port configuration values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) #define CP2104_GPIO0_TXLED_MODE BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) #define CP2104_GPIO1_RXLED_MODE BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) #define CP2104_GPIO2_RS485_MODE BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) /* CP2102N configuration array indices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) #define CP210X_2NCONFIG_CONFIG_VERSION_IDX 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) #define CP210X_2NCONFIG_GPIO_MODE_IDX 581
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) #define CP210X_2NCONFIG_GPIO_RSTLATCH_IDX 587
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) #define CP210X_2NCONFIG_GPIO_CONTROL_IDX 600
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) /* CP2102N QFN20 port configuration values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) #define CP2102N_QFN20_GPIO2_TXLED_MODE BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) #define CP2102N_QFN20_GPIO3_RXLED_MODE BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) #define CP2102N_QFN20_GPIO1_RS485_MODE BIT(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) #define CP2102N_QFN20_GPIO0_CLK_MODE BIT(6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) /* CP210X_VENDOR_SPECIFIC, CP210X_WRITE_LATCH call writes these 0x2 bytes. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) struct cp210x_gpio_write {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) u8 mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) u8 state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) * Helper to get interface number when we only have struct usb_serial.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) static u8 cp210x_interface_num(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) struct usb_host_interface *cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) cur_altsetting = serial->interface->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) return cur_altsetting->desc.bInterfaceNumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) * Reads a variable-sized block of CP210X_ registers, identified by req.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) * Returns data into buf in native USB byte order.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) static int cp210x_read_reg_block(struct usb_serial_port *port, u8 req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) void *buf, int bufsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) struct usb_serial *serial = port->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) void *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) dmabuf = kmalloc(bufsize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) if (!dmabuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) * FIXME Some callers don't bother to check for error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) * at least give them consistent junk until they are fixed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) memset(buf, 0, bufsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) req, REQTYPE_INTERFACE_TO_HOST, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) port_priv->bInterfaceNumber, dmabuf, bufsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) USB_CTRL_SET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) if (result == bufsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) memcpy(buf, dmabuf, bufsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) dev_err(&port->dev, "failed get req 0x%x size %d status: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) req, bufsize, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) if (result >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) result = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) * FIXME Some callers don't bother to check for error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) * at least give them consistent junk until they are fixed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) memset(buf, 0, bufsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) kfree(dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) }
^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) * Reads any 32-bit CP210X_ register identified by req.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) static int cp210x_read_u32_reg(struct usb_serial_port *port, u8 req, u32 *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) __le32 le32_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) err = cp210x_read_reg_block(port, req, &le32_val, sizeof(le32_val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) * FIXME Some callers don't bother to check for error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) * at least give them consistent junk until they are fixed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) *val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) *val = le32_to_cpu(le32_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) * Reads any 16-bit CP210X_ register identified by req.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) static int cp210x_read_u16_reg(struct usb_serial_port *port, u8 req, u16 *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) __le16 le16_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) err = cp210x_read_reg_block(port, req, &le16_val, sizeof(le16_val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) *val = le16_to_cpu(le16_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) * Reads any 8-bit CP210X_ register identified by req.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) static int cp210x_read_u8_reg(struct usb_serial_port *port, u8 req, u8 *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) return cp210x_read_reg_block(port, req, val, sizeof(*val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) * Reads a variable-sized vendor block of CP210X_ registers, identified by val.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) * Returns data into buf in native USB byte order.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) static int cp210x_read_vendor_block(struct usb_serial *serial, u8 type, u16 val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) void *buf, int bufsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) void *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) dmabuf = kmalloc(bufsize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) if (!dmabuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) CP210X_VENDOR_SPECIFIC, type, val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) cp210x_interface_num(serial), dmabuf, bufsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) USB_CTRL_GET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) if (result == bufsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) memcpy(buf, dmabuf, bufsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) dev_err(&serial->interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) "failed to get vendor val 0x%04x size %d: %d\n", val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) bufsize, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) if (result >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) result = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) kfree(dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) * Writes any 16-bit CP210X_ register (req) whose value is passed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) * entirely in the wValue field of the USB request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) static int cp210x_write_u16_reg(struct usb_serial_port *port, u8 req, u16 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) struct usb_serial *serial = port->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) req, REQTYPE_HOST_TO_INTERFACE, val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) port_priv->bInterfaceNumber, NULL, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) USB_CTRL_SET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) if (result < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) dev_err(&port->dev, "failed set request 0x%x status: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) req, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) * Writes a variable-sized block of CP210X_ registers, identified by req.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) * Data in buf must be in native USB byte order.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) static int cp210x_write_reg_block(struct usb_serial_port *port, u8 req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) void *buf, int bufsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) struct usb_serial *serial = port->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) void *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) dmabuf = kmemdup(buf, bufsize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) if (!dmabuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) req, REQTYPE_HOST_TO_INTERFACE, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) port_priv->bInterfaceNumber, dmabuf, bufsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) USB_CTRL_SET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) kfree(dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) if (result == bufsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) dev_err(&port->dev, "failed set req 0x%x size %d status: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) req, bufsize, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) if (result >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) result = -EIO;
^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) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) * Writes any 32-bit CP210X_ register identified by req.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) static int cp210x_write_u32_reg(struct usb_serial_port *port, u8 req, u32 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) __le32 le32_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) le32_val = cpu_to_le32(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) return cp210x_write_reg_block(port, req, &le32_val, sizeof(le32_val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) #ifdef CONFIG_GPIOLIB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) * Writes a variable-sized vendor block of CP210X_ registers, identified by val.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) * Data in buf must be in native USB byte order.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) static int cp210x_write_vendor_block(struct usb_serial *serial, u8 type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) u16 val, void *buf, int bufsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) void *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) dmabuf = kmemdup(buf, bufsize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) if (!dmabuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) CP210X_VENDOR_SPECIFIC, type, val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) cp210x_interface_num(serial), dmabuf, bufsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) USB_CTRL_SET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) kfree(dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) if (result == bufsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) dev_err(&serial->interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) "failed to set vendor val 0x%04x size %d: %d\n", val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) bufsize, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) if (result >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) result = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) * Detect CP2108 GET_LINE_CTL bug and activate workaround.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) * Write a known good value 0x800, read it back.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) * If it comes back swapped the bug is detected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) * Preserve the original register value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) static int cp210x_detect_swapped_line_ctl(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) u16 line_ctl_save;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) u16 line_ctl_test;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) err = cp210x_read_u16_reg(port, CP210X_GET_LINE_CTL, &line_ctl_save);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) err = cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, 0x800);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) err = cp210x_read_u16_reg(port, CP210X_GET_LINE_CTL, &line_ctl_test);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) if (line_ctl_test == 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) port_priv->has_swapped_line_ctl = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) line_ctl_save = swab16(line_ctl_save);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) return cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, line_ctl_save);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) * Must always be called instead of cp210x_read_u16_reg(CP210X_GET_LINE_CTL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) * to workaround cp2108 bug and get correct value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) static int cp210x_get_line_ctl(struct usb_serial_port *port, u16 *ctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) err = cp210x_read_u16_reg(port, CP210X_GET_LINE_CTL, ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) /* Workaround swapped bytes in 16-bit value from CP210X_GET_LINE_CTL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) if (port_priv->has_swapped_line_ctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) *ctl = swab16(*ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) result = cp210x_write_u16_reg(port, CP210X_IFC_ENABLE, UART_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) dev_err(&port->dev, "%s - Unable to enable UART\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) /* Configure the termios structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) cp210x_get_termios(tty, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) if (tty) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) /* The baud rate must be initialised on cp2104 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) cp210x_change_speed(tty, port, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) if (I_INPCK(tty))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) cp210x_enable_event_mode(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) result = usb_serial_generic_open(tty, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) goto err_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) err_disable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) cp210x_write_u16_reg(port, CP210X_IFC_ENABLE, UART_DISABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) port_priv->event_mode = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) static void cp210x_close(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) usb_serial_generic_close(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) /* Clear both queues; cp2108 needs this to avoid an occasional hang */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) cp210x_write_u16_reg(port, CP210X_PURGE, PURGE_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) cp210x_write_u16_reg(port, CP210X_IFC_ENABLE, UART_DISABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) /* Disabling the interface disables event-insertion mode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) port_priv->event_mode = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) static void cp210x_process_lsr(struct usb_serial_port *port, unsigned char lsr, char *flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) if (lsr & CP210X_LSR_BREAK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) port->icount.brk++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) *flag = TTY_BREAK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) } else if (lsr & CP210X_LSR_PARITY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) port->icount.parity++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) *flag = TTY_PARITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) } else if (lsr & CP210X_LSR_FRAME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) port->icount.frame++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) *flag = TTY_FRAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) if (lsr & CP210X_LSR_OVERRUN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) port->icount.overrun++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) tty_insert_flip_char(&port->port, 0, TTY_OVERRUN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) static bool cp210x_process_char(struct usb_serial_port *port, unsigned char *ch, char *flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) switch (port_priv->event_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) case ES_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) if (*ch == CP210X_ESCCHAR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) port_priv->event_state = ES_ESCAPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) case ES_ESCAPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) switch (*ch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) dev_dbg(&port->dev, "%s - escape char\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) *ch = CP210X_ESCCHAR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) port_priv->event_state = ES_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) port_priv->event_state = ES_LSR_DATA_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) port_priv->event_state = ES_LSR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) port_priv->event_state = ES_MSR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) dev_err(&port->dev, "malformed event 0x%02x\n", *ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) port_priv->event_state = ES_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) case ES_LSR_DATA_0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) port_priv->lsr = *ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) port_priv->event_state = ES_LSR_DATA_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) case ES_LSR_DATA_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) dev_dbg(&port->dev, "%s - lsr = 0x%02x, data = 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) __func__, port_priv->lsr, *ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) cp210x_process_lsr(port, port_priv->lsr, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) port_priv->event_state = ES_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) case ES_LSR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) dev_dbg(&port->dev, "%s - lsr = 0x%02x\n", __func__, *ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) port_priv->lsr = *ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) cp210x_process_lsr(port, port_priv->lsr, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) port_priv->event_state = ES_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) case ES_MSR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) dev_dbg(&port->dev, "%s - msr = 0x%02x\n", __func__, *ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) /* unimplemented */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) port_priv->event_state = ES_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) static void cp210x_process_read_urb(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) struct usb_serial_port *port = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) unsigned char *ch = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) char flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) if (!urb->actual_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) if (port_priv->event_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) for (i = 0; i < urb->actual_length; i++, ch++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) flag = TTY_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) if (cp210x_process_char(port, ch, &flag))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) tty_insert_flip_char(&port->port, *ch, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) tty_insert_flip_string(&port->port, ch, urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) tty_flip_buffer_push(&port->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) * Read how many bytes are waiting in the TX queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) static int cp210x_get_tx_queue_byte_count(struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) u32 *count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) struct usb_serial *serial = port->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) struct cp210x_comm_status *sts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) sts = kmalloc(sizeof(*sts), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) if (!sts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) CP210X_GET_COMM_STATUS, REQTYPE_INTERFACE_TO_HOST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 0, port_priv->bInterfaceNumber, sts, sizeof(*sts),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) USB_CTRL_GET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) if (result == sizeof(*sts)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) *count = le32_to_cpu(sts->ulAmountInOutQueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) dev_err(&port->dev, "failed to get comm status: %d\n", result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) if (result >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) result = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) kfree(sts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) static bool cp210x_tx_empty(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) u32 count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) err = cp210x_get_tx_queue_byte_count(port, &count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) return !count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) * cp210x_get_termios
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) * Reads the baud rate, data bits, parity, stop bits and flow control mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) * from the device, corrects any unsupported values, and configures the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) * termios structure to reflect the state of the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) static void cp210x_get_termios(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) unsigned int baud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) if (tty) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) cp210x_get_termios_port(tty->driver_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) &tty->termios.c_cflag, &baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) tty_encode_baud_rate(tty, baud, baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) tcflag_t cflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) cflag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) cp210x_get_termios_port(port, &cflag, &baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) * cp210x_get_termios_port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) * This is the heart of cp210x_get_termios which always uses a &usb_serial_port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) static void cp210x_get_termios_port(struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) tcflag_t *cflagp, unsigned int *baudp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) struct device *dev = &port->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) tcflag_t cflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) struct cp210x_flow_ctl flow_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) u32 baud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) u16 bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) u32 ctl_hs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) u32 flow_repl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) cp210x_read_u32_reg(port, CP210X_GET_BAUDRATE, &baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) dev_dbg(dev, "%s - baud rate = %d\n", __func__, baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) *baudp = baud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) cflag = *cflagp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) cp210x_get_line_ctl(port, &bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) cflag &= ~CSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) switch (bits & BITS_DATA_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) case BITS_DATA_5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) dev_dbg(dev, "%s - data bits = 5\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) cflag |= CS5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) case BITS_DATA_6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) dev_dbg(dev, "%s - data bits = 6\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) cflag |= CS6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) case BITS_DATA_7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) dev_dbg(dev, "%s - data bits = 7\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) cflag |= CS7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) case BITS_DATA_8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) dev_dbg(dev, "%s - data bits = 8\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) cflag |= CS8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) case BITS_DATA_9:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) dev_dbg(dev, "%s - data bits = 9 (not supported, using 8 data bits)\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) cflag |= CS8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) bits &= ~BITS_DATA_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) bits |= BITS_DATA_8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) dev_dbg(dev, "%s - Unknown number of data bits, using 8\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) cflag |= CS8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) bits &= ~BITS_DATA_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) bits |= BITS_DATA_8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) switch (bits & BITS_PARITY_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) case BITS_PARITY_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) dev_dbg(dev, "%s - parity = NONE\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) cflag &= ~PARENB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) case BITS_PARITY_ODD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) dev_dbg(dev, "%s - parity = ODD\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) cflag |= (PARENB|PARODD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) case BITS_PARITY_EVEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) dev_dbg(dev, "%s - parity = EVEN\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) cflag &= ~PARODD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) cflag |= PARENB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) case BITS_PARITY_MARK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) dev_dbg(dev, "%s - parity = MARK\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) cflag |= (PARENB|PARODD|CMSPAR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) case BITS_PARITY_SPACE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) dev_dbg(dev, "%s - parity = SPACE\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) cflag &= ~PARODD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) cflag |= (PARENB|CMSPAR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) dev_dbg(dev, "%s - Unknown parity mode, disabling parity\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) cflag &= ~PARENB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) bits &= ~BITS_PARITY_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) break;
^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) cflag &= ~CSTOPB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) switch (bits & BITS_STOP_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) case BITS_STOP_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) dev_dbg(dev, "%s - stop bits = 1\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) case BITS_STOP_1_5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) dev_dbg(dev, "%s - stop bits = 1.5 (not supported, using 1 stop bit)\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) bits &= ~BITS_STOP_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) case BITS_STOP_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) dev_dbg(dev, "%s - stop bits = 2\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) cflag |= CSTOPB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) dev_dbg(dev, "%s - Unknown number of stop bits, using 1 stop bit\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) bits &= ~BITS_STOP_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) sizeof(flow_ctl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) if (ctl_hs & CP210X_SERIAL_CTS_HANDSHAKE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) * When the port is closed, the CP210x hardware disables
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) * auto-RTS and RTS is deasserted but it leaves auto-CTS when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) * in hardware flow control mode. When re-opening the port, if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) * auto-CTS is enabled on the cp210x, then auto-RTS must be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) * re-enabled in the driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) flow_repl = le32_to_cpu(flow_ctl.ulFlowReplace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) flow_repl &= ~CP210X_SERIAL_RTS_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) flow_repl |= CP210X_SERIAL_RTS_SHIFT(CP210X_SERIAL_RTS_FLOW_CTL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) flow_ctl.ulFlowReplace = cpu_to_le32(flow_repl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) cp210x_write_reg_block(port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) CP210X_SET_FLOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) &flow_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) sizeof(flow_ctl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) cflag |= CRTSCTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) dev_dbg(dev, "%s - flow control = NONE\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) cflag &= ~CRTSCTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) *cflagp = cflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) struct cp210x_rate {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) speed_t rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) speed_t high;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) static const struct cp210x_rate cp210x_an205_table1[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) { 300, 300 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) { 600, 600 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) { 1200, 1200 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) { 1800, 1800 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) { 2400, 2400 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) { 4000, 4000 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) { 4800, 4803 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) { 7200, 7207 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) { 9600, 9612 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) { 14400, 14428 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) { 16000, 16062 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) { 19200, 19250 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) { 28800, 28912 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) { 38400, 38601 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) { 51200, 51558 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) { 56000, 56280 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) { 57600, 58053 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) { 64000, 64111 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) { 76800, 77608 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) { 115200, 117028 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) { 128000, 129347 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) { 153600, 156868 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) { 230400, 237832 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) { 250000, 254234 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) { 256000, 273066 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) { 460800, 491520 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) { 500000, 567138 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) { 576000, 670254 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) { 921600, UINT_MAX }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) * Quantises the baud rate as per AN205 Table 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) static speed_t cp210x_get_an205_rate(speed_t baud)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) for (i = 0; i < ARRAY_SIZE(cp210x_an205_table1); ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) if (baud <= cp210x_an205_table1[i].high)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) return cp210x_an205_table1[i].rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) static speed_t cp210x_get_actual_rate(speed_t baud)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) unsigned int prescale = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) unsigned int div;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) if (baud <= 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) prescale = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) div = DIV_ROUND_CLOSEST(48000000, 2 * prescale * baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) baud = 48000000 / (2 * prescale * div);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) return baud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) * CP2101 supports the following baud rates:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) * 300, 600, 1200, 1800, 2400, 4800, 7200, 9600, 14400, 19200, 28800,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) * 38400, 56000, 57600, 115200, 128000, 230400, 460800, 921600
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) * CP2102 and CP2103 support the following additional rates:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) * 4000, 16000, 51200, 64000, 76800, 153600, 250000, 256000, 500000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) * 576000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) * The device will map a requested rate to a supported one, but the result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) * of requests for rates greater than 1053257 is undefined (see AN205).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) * CP2104, CP2105 and CP2110 support most rates up to 2M, 921k and 1M baud,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) * respectively, with an error less than 1%. The actual rates are determined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) * by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) * div = round(freq / (2 x prescale x request))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) * actual = freq / (2 x prescale x div)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) * For CP2104 and CP2105 freq is 48Mhz and prescale is 4 for request <= 365bps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) * or 1 otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) * For CP2110 freq is 24Mhz and prescale is 4 for request <= 300bps or 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) * otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) static void cp210x_change_speed(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) struct usb_serial_port *port, struct ktermios *old_termios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) struct usb_serial *serial = port->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) struct cp210x_serial_private *priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) u32 baud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) * This maps the requested rate to the actual rate, a valid rate on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) * cp2102 or cp2103, or to an arbitrary rate in [1M, max_speed].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) * NOTE: B0 is not implemented.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) baud = clamp(tty->termios.c_ospeed, priv->min_speed, priv->max_speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) if (priv->use_actual_rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) baud = cp210x_get_actual_rate(baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) else if (baud < 1000000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) baud = cp210x_get_an205_rate(baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) dev_dbg(&port->dev, "%s - setting baud rate to %u\n", __func__, baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) if (cp210x_write_u32_reg(port, CP210X_SET_BAUDRATE, baud)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) dev_warn(&port->dev, "failed to set baud rate to %u\n", baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) if (old_termios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) baud = old_termios->c_ospeed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) baud = 9600;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) tty_encode_baud_rate(tty, baud, baud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) static void cp210x_enable_event_mode(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) struct cp210x_serial_private *priv = usb_get_serial_data(port->serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) if (port_priv->event_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) if (priv->no_event_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) port_priv->event_state = ES_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) port_priv->event_mode = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) ret = cp210x_write_u16_reg(port, CP210X_EMBED_EVENTS, CP210X_ESCCHAR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) dev_err(&port->dev, "failed to enable events: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) port_priv->event_mode = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) static void cp210x_disable_event_mode(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) if (!port_priv->event_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) ret = cp210x_write_u16_reg(port, CP210X_EMBED_EVENTS, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) dev_err(&port->dev, "failed to disable events: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) port_priv->event_mode = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) static void cp210x_set_termios(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) struct usb_serial_port *port, struct ktermios *old_termios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) struct device *dev = &port->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) unsigned int cflag, old_cflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) u16 bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) cflag = tty->termios.c_cflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) old_cflag = old_termios->c_cflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) if (tty->termios.c_ospeed != old_termios->c_ospeed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) cp210x_change_speed(tty, port, old_termios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) /* If the number of data bits is to be updated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) cp210x_get_line_ctl(port, &bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) bits &= ~BITS_DATA_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) switch (cflag & CSIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) case CS5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) bits |= BITS_DATA_5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) dev_dbg(dev, "%s - data bits = 5\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) case CS6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) bits |= BITS_DATA_6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) dev_dbg(dev, "%s - data bits = 6\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) case CS7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) bits |= BITS_DATA_7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) dev_dbg(dev, "%s - data bits = 7\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) case CS8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) bits |= BITS_DATA_8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) dev_dbg(dev, "%s - data bits = 8\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) if (cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) dev_dbg(dev, "Number of data bits requested not supported by device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) if ((cflag & (PARENB|PARODD|CMSPAR)) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) (old_cflag & (PARENB|PARODD|CMSPAR))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) cp210x_get_line_ctl(port, &bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) bits &= ~BITS_PARITY_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) if (cflag & PARENB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) if (cflag & CMSPAR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) if (cflag & PARODD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) bits |= BITS_PARITY_MARK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) dev_dbg(dev, "%s - parity = MARK\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) bits |= BITS_PARITY_SPACE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) dev_dbg(dev, "%s - parity = SPACE\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) if (cflag & PARODD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) bits |= BITS_PARITY_ODD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) dev_dbg(dev, "%s - parity = ODD\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) bits |= BITS_PARITY_EVEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) dev_dbg(dev, "%s - parity = EVEN\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) if (cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) dev_dbg(dev, "Parity mode not supported by device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) cp210x_get_line_ctl(port, &bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) bits &= ~BITS_STOP_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) if (cflag & CSTOPB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) bits |= BITS_STOP_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) dev_dbg(dev, "%s - stop bits = 2\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) bits |= BITS_STOP_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) dev_dbg(dev, "%s - stop bits = 1\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) if (cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) dev_dbg(dev, "Number of stop bits requested not supported by device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) struct cp210x_flow_ctl flow_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) u32 ctl_hs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) u32 flow_repl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) sizeof(flow_ctl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) flow_repl = le32_to_cpu(flow_ctl.ulFlowReplace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) dev_dbg(dev, "%s - read ulControlHandshake=0x%08x, ulFlowReplace=0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) __func__, ctl_hs, flow_repl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) ctl_hs &= ~CP210X_SERIAL_DSR_HANDSHAKE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) ctl_hs &= ~CP210X_SERIAL_DCD_HANDSHAKE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) ctl_hs &= ~CP210X_SERIAL_DSR_SENSITIVITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) ctl_hs &= ~CP210X_SERIAL_DTR_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) ctl_hs |= CP210X_SERIAL_DTR_SHIFT(CP210X_SERIAL_DTR_ACTIVE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) if (cflag & CRTSCTS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) ctl_hs |= CP210X_SERIAL_CTS_HANDSHAKE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) flow_repl &= ~CP210X_SERIAL_RTS_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) flow_repl |= CP210X_SERIAL_RTS_SHIFT(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) CP210X_SERIAL_RTS_FLOW_CTL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) ctl_hs &= ~CP210X_SERIAL_CTS_HANDSHAKE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) flow_repl &= ~CP210X_SERIAL_RTS_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) flow_repl |= CP210X_SERIAL_RTS_SHIFT(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) CP210X_SERIAL_RTS_ACTIVE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) dev_dbg(dev, "%s - flow control = NONE\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) dev_dbg(dev, "%s - write ulControlHandshake=0x%08x, ulFlowReplace=0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) __func__, ctl_hs, flow_repl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) flow_ctl.ulControlHandshake = cpu_to_le32(ctl_hs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) flow_ctl.ulFlowReplace = cpu_to_le32(flow_repl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) cp210x_write_reg_block(port, CP210X_SET_FLOW, &flow_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) sizeof(flow_ctl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) * Enable event-insertion mode only if input parity checking is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) * enabled for now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) if (I_INPCK(tty))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) cp210x_enable_event_mode(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) cp210x_disable_event_mode(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) static int cp210x_tiocmset(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) unsigned int set, unsigned int clear)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) return cp210x_tiocmset_port(port, set, clear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) static int cp210x_tiocmset_port(struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) unsigned int set, unsigned int clear)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) u16 control = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) if (set & TIOCM_RTS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) control |= CONTROL_RTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) control |= CONTROL_WRITE_RTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) if (set & TIOCM_DTR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) control |= CONTROL_DTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) control |= CONTROL_WRITE_DTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) if (clear & TIOCM_RTS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) control &= ~CONTROL_RTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) control |= CONTROL_WRITE_RTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) if (clear & TIOCM_DTR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) control &= ~CONTROL_DTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) control |= CONTROL_WRITE_DTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) dev_dbg(&port->dev, "%s - control = 0x%.4x\n", __func__, control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) return cp210x_write_u16_reg(port, CP210X_SET_MHS, control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) static void cp210x_dtr_rts(struct usb_serial_port *p, int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) if (on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) cp210x_tiocmset_port(p, TIOCM_DTR|TIOCM_RTS, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) cp210x_tiocmset_port(p, 0, TIOCM_DTR|TIOCM_RTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) static int cp210x_tiocmget(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) u8 control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) result = cp210x_read_u8_reg(port, CP210X_GET_MDMSTS, &control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) |((control & CONTROL_RTS) ? TIOCM_RTS : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) |((control & CONTROL_CTS) ? TIOCM_CTS : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) |((control & CONTROL_DSR) ? TIOCM_DSR : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) |((control & CONTROL_RING)? TIOCM_RI : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) |((control & CONTROL_DCD) ? TIOCM_CD : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) dev_dbg(&port->dev, "%s - control = 0x%.2x\n", __func__, control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) static void cp210x_break_ctl(struct tty_struct *tty, int break_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) u16 state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) if (break_state == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) state = BREAK_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) state = BREAK_ON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) dev_dbg(&port->dev, "%s - turning break %s\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) state == BREAK_OFF ? "off" : "on");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) cp210x_write_u16_reg(port, CP210X_SET_BREAK, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) #ifdef CONFIG_GPIOLIB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) static int cp210x_gpio_request(struct gpio_chip *gc, unsigned int offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) struct usb_serial *serial = gpiochip_get_data(gc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) struct cp210x_serial_private *priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) if (priv->gpio_altfunc & BIT(offset))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) static int cp210x_gpio_get(struct gpio_chip *gc, unsigned int gpio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) struct usb_serial *serial = gpiochip_get_data(gc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) struct cp210x_serial_private *priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) u8 req_type = REQTYPE_DEVICE_TO_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) u8 buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) if (priv->partnum == CP210X_PARTNUM_CP2105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) req_type = REQTYPE_INTERFACE_TO_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) result = usb_autopm_get_interface(serial->interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) result = cp210x_read_vendor_block(serial, req_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) CP210X_READ_LATCH, &buf, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) usb_autopm_put_interface(serial->interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) return !!(buf & BIT(gpio));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) static void cp210x_gpio_set(struct gpio_chip *gc, unsigned int gpio, int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) struct usb_serial *serial = gpiochip_get_data(gc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) struct cp210x_serial_private *priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) struct cp210x_gpio_write buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) if (value == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) buf.state = BIT(gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) buf.state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) buf.mask = BIT(gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) result = usb_autopm_get_interface(serial->interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) if (priv->partnum == CP210X_PARTNUM_CP2105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) result = cp210x_write_vendor_block(serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) REQTYPE_HOST_TO_INTERFACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) CP210X_WRITE_LATCH, &buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) u16 wIndex = buf.state << 8 | buf.mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) result = usb_control_msg(serial->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) usb_sndctrlpipe(serial->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) CP210X_VENDOR_SPECIFIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) REQTYPE_HOST_TO_DEVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) CP210X_WRITE_LATCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) wIndex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) NULL, 0, USB_CTRL_SET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) usb_autopm_put_interface(serial->interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) if (result < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) dev_err(&serial->interface->dev, "failed to set GPIO value: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) static int cp210x_gpio_direction_get(struct gpio_chip *gc, unsigned int gpio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) struct usb_serial *serial = gpiochip_get_data(gc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) struct cp210x_serial_private *priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) return priv->gpio_input & BIT(gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) static int cp210x_gpio_direction_input(struct gpio_chip *gc, unsigned int gpio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) struct usb_serial *serial = gpiochip_get_data(gc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) struct cp210x_serial_private *priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) if (priv->partnum == CP210X_PARTNUM_CP2105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) /* hardware does not support an input mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) return -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) /* push-pull pins cannot be changed to be inputs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) if (priv->gpio_pushpull & BIT(gpio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) /* make sure to release pin if it is being driven low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) cp210x_gpio_set(gc, gpio, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) priv->gpio_input |= BIT(gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) static int cp210x_gpio_direction_output(struct gpio_chip *gc, unsigned int gpio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) struct usb_serial *serial = gpiochip_get_data(gc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) struct cp210x_serial_private *priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) priv->gpio_input &= ~BIT(gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) cp210x_gpio_set(gc, gpio, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) static int cp210x_gpio_set_config(struct gpio_chip *gc, unsigned int gpio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) unsigned long config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) struct usb_serial *serial = gpiochip_get_data(gc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) struct cp210x_serial_private *priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) enum pin_config_param param = pinconf_to_config_param(config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) /* Succeed only if in correct mode (this can't be set at runtime) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) if ((param == PIN_CONFIG_DRIVE_PUSH_PULL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) (priv->gpio_pushpull & BIT(gpio)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) if ((param == PIN_CONFIG_DRIVE_OPEN_DRAIN) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) !(priv->gpio_pushpull & BIT(gpio)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) return -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) * This function is for configuring GPIO using shared pins, where other signals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) * are made unavailable by configuring the use of GPIO. This is believed to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) * only applicable to the cp2105 at this point, the other devices supported by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) * this driver that provide GPIO do so in a way that does not impact other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) * signals and are thus expected to have very different initialisation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) static int cp2105_gpioconf_init(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) struct cp210x_serial_private *priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) struct cp210x_pin_mode mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) struct cp210x_dual_port_config config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) u8 intf_num = cp210x_interface_num(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) u8 iface_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) result = cp210x_read_vendor_block(serial, REQTYPE_DEVICE_TO_HOST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) CP210X_GET_DEVICEMODE, &mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) sizeof(mode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) result = cp210x_read_vendor_block(serial, REQTYPE_DEVICE_TO_HOST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) CP210X_GET_PORTCONFIG, &config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) sizeof(config));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) /* 2 banks of GPIO - One for the pins taken from each serial port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) if (intf_num == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) priv->gc.ngpio = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) if (mode.eci == CP210X_PIN_MODE_MODEM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) /* mark all GPIOs of this interface as reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) priv->gpio_altfunc = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) iface_config = config.eci_cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) priv->gpio_pushpull = (u8)((le16_to_cpu(config.gpio_mode) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) CP210X_ECI_GPIO_MODE_MASK) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) CP210X_ECI_GPIO_MODE_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) } else if (intf_num == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) priv->gc.ngpio = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) if (mode.sci == CP210X_PIN_MODE_MODEM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) /* mark all GPIOs of this interface as reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) priv->gpio_altfunc = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) iface_config = config.sci_cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) priv->gpio_pushpull = (u8)((le16_to_cpu(config.gpio_mode) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) CP210X_SCI_GPIO_MODE_MASK) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) CP210X_SCI_GPIO_MODE_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) /* mark all pins which are not in GPIO mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) if (iface_config & CP2105_GPIO0_TXLED_MODE) /* GPIO 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) priv->gpio_altfunc |= BIT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) if (iface_config & (CP2105_GPIO1_RXLED_MODE | /* GPIO 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) CP2105_GPIO1_RS485_MODE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) priv->gpio_altfunc |= BIT(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) /* driver implementation for CP2105 only supports outputs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) priv->gpio_input = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) static int cp2104_gpioconf_init(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) struct cp210x_serial_private *priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) struct cp210x_single_port_config config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) u8 iface_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) u8 gpio_latch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) u8 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) result = cp210x_read_vendor_block(serial, REQTYPE_DEVICE_TO_HOST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) CP210X_GET_PORTCONFIG, &config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) sizeof(config));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) priv->gc.ngpio = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) iface_config = config.device_cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) priv->gpio_pushpull = (u8)((le16_to_cpu(config.gpio_mode) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) CP210X_GPIO_MODE_MASK) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) CP210X_GPIO_MODE_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) gpio_latch = (u8)((le16_to_cpu(config.reset_state) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) CP210X_GPIO_MODE_MASK) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) CP210X_GPIO_MODE_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) /* mark all pins which are not in GPIO mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) if (iface_config & CP2104_GPIO0_TXLED_MODE) /* GPIO 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) priv->gpio_altfunc |= BIT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) if (iface_config & CP2104_GPIO1_RXLED_MODE) /* GPIO 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) priv->gpio_altfunc |= BIT(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) if (iface_config & CP2104_GPIO2_RS485_MODE) /* GPIO 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) priv->gpio_altfunc |= BIT(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) * Like CP2102N, CP2104 has also no strict input and output pin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) * modes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) * Do the same input mode emulation as CP2102N.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) for (i = 0; i < priv->gc.ngpio; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) * Set direction to "input" iff pin is open-drain and reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) * value is 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) if (!(priv->gpio_pushpull & BIT(i)) && (gpio_latch & BIT(i)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) priv->gpio_input |= BIT(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) static int cp2102n_gpioconf_init(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) struct cp210x_serial_private *priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) const u16 config_size = 0x02a6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) u8 gpio_rst_latch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) u8 config_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) u8 gpio_pushpull;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) u8 *config_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) u8 gpio_latch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) u8 gpio_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) u8 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) * Retrieve device configuration from the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) * The array received contains all customization settings done at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) * factory/manufacturer. Format of the array is documented at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) * time of writing at:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) * https://www.silabs.com/community/interface/knowledge-base.entry.html/2017/03/31/cp2102n_setconfig-xsfa
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) config_buf = kmalloc(config_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) if (!config_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) result = cp210x_read_vendor_block(serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) REQTYPE_DEVICE_TO_HOST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) CP210X_READ_2NCONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) config_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) config_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) if (result < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) kfree(config_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) config_version = config_buf[CP210X_2NCONFIG_CONFIG_VERSION_IDX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) gpio_pushpull = config_buf[CP210X_2NCONFIG_GPIO_MODE_IDX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) gpio_ctrl = config_buf[CP210X_2NCONFIG_GPIO_CONTROL_IDX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) gpio_rst_latch = config_buf[CP210X_2NCONFIG_GPIO_RSTLATCH_IDX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) kfree(config_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) /* Make sure this is a config format we understand. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) if (config_version != 0x01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) return -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) priv->gc.ngpio = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) * Get default pin states after reset. Needed so we can determine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) * the direction of an open-drain pin.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) gpio_latch = (gpio_rst_latch >> 3) & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) /* 0 indicates open-drain mode, 1 is push-pull */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) priv->gpio_pushpull = (gpio_pushpull >> 3) & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) /* 0 indicates GPIO mode, 1 is alternate function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) if (priv->partnum == CP210X_PARTNUM_CP2102N_QFN20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) /* QFN20 is special... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) if (gpio_ctrl & CP2102N_QFN20_GPIO0_CLK_MODE) /* GPIO 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) priv->gpio_altfunc |= BIT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) if (gpio_ctrl & CP2102N_QFN20_GPIO1_RS485_MODE) /* GPIO 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) priv->gpio_altfunc |= BIT(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) if (gpio_ctrl & CP2102N_QFN20_GPIO2_TXLED_MODE) /* GPIO 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) priv->gpio_altfunc |= BIT(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) if (gpio_ctrl & CP2102N_QFN20_GPIO3_RXLED_MODE) /* GPIO 3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) priv->gpio_altfunc |= BIT(3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) priv->gpio_altfunc = (gpio_ctrl >> 2) & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) if (priv->partnum == CP210X_PARTNUM_CP2102N_QFN28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) * For the QFN28 package, GPIO4-6 are controlled by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) * the low three bits of the mode/latch fields.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) * Contrary to the document linked above, the bits for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) * the SUSPEND pins are elsewhere. No alternate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) * function is available for these pins.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) priv->gc.ngpio = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) gpio_latch |= (gpio_rst_latch & 7) << 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) priv->gpio_pushpull |= (gpio_pushpull & 7) << 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) * The CP2102N does not strictly has input and output pin modes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) * it only knows open-drain and push-pull modes which is set at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) * factory. An open-drain pin can function both as an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) * input or an output. We emulate input mode for open-drain pins
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) * by making sure they are not driven low, and we do not allow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) * push-pull pins to be set as an input.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) for (i = 0; i < priv->gc.ngpio; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) * Set direction to "input" iff pin is open-drain and reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) * value is 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) if (!(priv->gpio_pushpull & BIT(i)) && (gpio_latch & BIT(i)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) priv->gpio_input |= BIT(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) static int cp210x_gpio_init(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) struct cp210x_serial_private *priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) switch (priv->partnum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) case CP210X_PARTNUM_CP2104:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) result = cp2104_gpioconf_init(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) case CP210X_PARTNUM_CP2105:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) result = cp2105_gpioconf_init(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) case CP210X_PARTNUM_CP2102N_QFN28:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) case CP210X_PARTNUM_CP2102N_QFN24:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) case CP210X_PARTNUM_CP2102N_QFN20:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) result = cp2102n_gpioconf_init(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) priv->gc.label = "cp210x";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) priv->gc.request = cp210x_gpio_request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) priv->gc.get_direction = cp210x_gpio_direction_get;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) priv->gc.direction_input = cp210x_gpio_direction_input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) priv->gc.direction_output = cp210x_gpio_direction_output;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) priv->gc.get = cp210x_gpio_get;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) priv->gc.set = cp210x_gpio_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) priv->gc.set_config = cp210x_gpio_set_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) priv->gc.owner = THIS_MODULE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) priv->gc.parent = &serial->interface->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) priv->gc.base = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) priv->gc.can_sleep = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) result = gpiochip_add_data(&priv->gc, serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) if (!result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) priv->gpio_registered = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) static void cp210x_gpio_remove(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) struct cp210x_serial_private *priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) if (priv->gpio_registered) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) gpiochip_remove(&priv->gc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) priv->gpio_registered = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) static int cp210x_gpio_init(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) static void cp210x_gpio_remove(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) /* Nothing to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) static int cp210x_port_probe(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) struct usb_serial *serial = port->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) struct cp210x_port_private *port_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) port_priv = kzalloc(sizeof(*port_priv), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) if (!port_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) port_priv->bInterfaceNumber = cp210x_interface_num(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) usb_set_serial_port_data(port, port_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) ret = cp210x_detect_swapped_line_ctl(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) kfree(port_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) static int cp210x_port_remove(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) struct cp210x_port_private *port_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) port_priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) kfree(port_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) static void cp210x_init_max_speed(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) struct cp210x_serial_private *priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) bool use_actual_rate = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) speed_t min = 300;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) speed_t max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) switch (priv->partnum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) case CP210X_PARTNUM_CP2101:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) max = 921600;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) case CP210X_PARTNUM_CP2102:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) case CP210X_PARTNUM_CP2103:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) max = 1000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) case CP210X_PARTNUM_CP2104:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) use_actual_rate = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) max = 2000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) case CP210X_PARTNUM_CP2108:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) max = 2000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) case CP210X_PARTNUM_CP2105:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) if (cp210x_interface_num(serial) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) use_actual_rate = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) max = 2000000; /* ECI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) min = 2400;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) max = 921600; /* SCI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) case CP210X_PARTNUM_CP2102N_QFN28:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) case CP210X_PARTNUM_CP2102N_QFN24:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) case CP210X_PARTNUM_CP2102N_QFN20:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) use_actual_rate = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) max = 3000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) max = 2000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) priv->min_speed = min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) priv->max_speed = max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) priv->use_actual_rate = use_actual_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) static void cp2102_determine_quirks(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) struct cp210x_serial_private *priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) u8 *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) buf = kmalloc(2, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) * Some (possibly counterfeit) CP2102 do not support event-insertion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) * mode and respond differently to malformed vendor requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) * Specifically, they return one instead of two bytes when sent a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) * two-byte part-number request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) ret = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) CP210X_VENDOR_SPECIFIC, REQTYPE_DEVICE_TO_HOST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) CP210X_GET_PARTNUM, 0, buf, 2, USB_CTRL_GET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) if (ret == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) dev_dbg(&serial->interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) "device does not support event-insertion mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) priv->no_event_mode = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) static void cp210x_determine_quirks(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) struct cp210x_serial_private *priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) switch (priv->partnum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) case CP210X_PARTNUM_CP2102:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) cp2102_determine_quirks(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) static int cp210x_attach(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) struct cp210x_serial_private *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) priv = kzalloc(sizeof(*priv), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) if (!priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) result = cp210x_read_vendor_block(serial, REQTYPE_DEVICE_TO_HOST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) CP210X_GET_PARTNUM, &priv->partnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) sizeof(priv->partnum));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) if (result < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) dev_warn(&serial->interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) "querying part number failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) priv->partnum = CP210X_PARTNUM_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) usb_set_serial_data(serial, priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) cp210x_determine_quirks(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) cp210x_init_max_speed(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) result = cp210x_gpio_init(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) if (result < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) dev_err(&serial->interface->dev, "GPIO initialisation failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) static void cp210x_disconnect(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) cp210x_gpio_remove(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) static void cp210x_release(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) struct cp210x_serial_private *priv = usb_get_serial_data(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) cp210x_gpio_remove(serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) kfree(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) module_usb_serial_driver(serial_drivers, id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) MODULE_LICENSE("GPL v2");