pl2303.c revision 623c8263376c0b8a4b0c220232e7313d762cd0cc
11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Prolific PL2303 USB to serial adaptor driver 31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 44d0dce3e0b794942407391c52f8dd2760802f391Greg Kroah-Hartman * Copyright (C) 2001-2007 Greg Kroah-Hartman (greg@kroah.com) 51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 2003 IBM Corp. 61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Original driver for 2.2.x by anonymous 81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 94d0dce3e0b794942407391c52f8dd2760802f391Greg Kroah-Hartman * This program is free software; you can redistribute it and/or 104d0dce3e0b794942407391c52f8dd2760802f391Greg Kroah-Hartman * modify it under the terms of the GNU General Public License version 114d0dce3e0b794942407391c52f8dd2760802f391Greg Kroah-Hartman * 2 as published by the Free Software Foundation. 121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 133a0f43e9deffd9619ac34e3b6b9ba7089aa1e511Alan Cox * See Documentation/usb/usb-serial.txt for more information on using this 143a0f43e9deffd9619ac34e3b6b9ba7089aa1e511Alan Cox * driver 151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/kernel.h> 191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/errno.h> 201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/init.h> 211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/slab.h> 221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/tty.h> 231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/tty_driver.h> 241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/tty_flip.h> 251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/serial.h> 261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/module.h> 271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/moduleparam.h> 281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/spinlock.h> 293a0f43e9deffd9619ac34e3b6b9ba7089aa1e511Alan Cox#include <linux/uaccess.h> 301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/usb.h> 31a969888ce91673c7f4b86520d851a6f0d5a5fa7dGreg Kroah-Hartman#include <linux/usb/serial.h> 32b2d6d98fc71bb94ada78d433f26a93498802d3f8Johan Hovold#include <asm/unaligned.h> 331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "pl2303.h" 341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Version Information 371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DRIVER_DESC "Prolific PL2303 USB to serial adaptor driver" 391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 407d40d7e85a25e01948bcb4dc3eda1355af318337Németh Mártonstatic const struct usb_device_id id_table[] = { 411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID) }, 421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_RSAQ2) }, 433d861494729c70d9ebeb7d93caa107897925c355Peter Moulder { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_DCU11) }, 441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_RSAQ3) }, 451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_PHAROS) }, 46b483b6aaa56f0db72fa50e85b6499a32d82009bfMax Arnold { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_ALDIGA) }, 474be2fa186d54758296d30c565d7b5111dd45b000Steve Murphy { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_MMX) }, 48727df3569b358ef440683787c2b9fe8cc55a0954Greg Kroah-Hartman { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GPRS) }, 4918344a1cd5889d48dac67229fcf024ed300030d5Simone Contini { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_HCR331) }, 5096a3e79edff6f41b0f115a82f1a39d66218077a7Dario Lombardo { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_MOTOROLA) }, 511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID) }, 528a28dea3accda319d51a1bf4d3e280771d946f78Masakazu Mokuno { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID_RSAQ5) }, 531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_ID) }, 541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { USB_DEVICE(ATEN_VENDOR_ID2, ATEN_PRODUCT_ID) }, 551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { USB_DEVICE(ELCOM_VENDOR_ID, ELCOM_PRODUCT_ID) }, 561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { USB_DEVICE(ELCOM_VENDOR_ID, ELCOM_PRODUCT_ID_UCSGT) }, 571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { USB_DEVICE(ITEGNO_VENDOR_ID, ITEGNO_PRODUCT_ID) }, 5858381719845d9ee19a321c2eb69cfa9b7886be9aWang Jun { USB_DEVICE(ITEGNO_VENDOR_ID, ITEGNO_PRODUCT_ID_2080) }, 591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { USB_DEVICE(MA620_VENDOR_ID, MA620_PRODUCT_ID) }, 601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { USB_DEVICE(RATOC_VENDOR_ID, RATOC_PRODUCT_ID) }, 611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { USB_DEVICE(TRIPP_VENDOR_ID, TRIPP_PRODUCT_ID) }, 621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { USB_DEVICE(RADIOSHACK_VENDOR_ID, RADIOSHACK_PRODUCT_ID) }, 631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { USB_DEVICE(DCU10_VENDOR_ID, DCU10_PRODUCT_ID) }, 641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { USB_DEVICE(SITECOM_VENDOR_ID, SITECOM_PRODUCT_ID) }, 651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { USB_DEVICE(ALCATEL_VENDOR_ID, ALCATEL_PRODUCT_ID) }, 661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_PRODUCT_ID) }, 67a8310f3b8b713e52d77c56d4b8865685ee40d02aLuiz Fernando Capitulino { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_SX1) }, 681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_X65) }, 69a8310f3b8b713e52d77c56d4b8865685ee40d02aLuiz Fernando Capitulino { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_X75) }, 70e7beb667842ad0f6ec95a22e7c88e71dfbd60649Andreas Loibl { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_EF81) }, 71912299f6f0587bb6c221705ed9949709b36b3c56Alan Cox { USB_DEVICE(BENQ_VENDOR_ID, BENQ_PRODUCT_ID_S81) }, /* Benq/Siemens S81 */ 72acbb36f116243bed515357264ecbb6ff9c6d2a5bPeter Favrholdt { USB_DEVICE(SYNTECH_VENDOR_ID, SYNTECH_PRODUCT_ID) }, 73c6c27721a42b991965bb792d5c196b8331d008d5Christian Lindner { USB_DEVICE(NOKIA_CA42_VENDOR_ID, NOKIA_CA42_PRODUCT_ID) }, 74c6c27721a42b991965bb792d5c196b8331d008d5Christian Lindner { USB_DEVICE(CA_42_CA42_VENDOR_ID, CA_42_CA42_PRODUCT_ID) }, 756cceb05f8df6e28ab90f44bdeba50d33928cdee5Denis MONTERRAT { USB_DEVICE(SAGEM_VENDOR_ID, SAGEM_PRODUCT_ID) }, 76c6c27721a42b991965bb792d5c196b8331d008d5Christian Lindner { USB_DEVICE(LEADTEK_VENDOR_ID, LEADTEK_9531_PRODUCT_ID) }, 77491b04ce1c9adfa0cd73f095086f3c37da81b667Dick Streefland { USB_DEVICE(SPEEDDRAGON_VENDOR_ID, SPEEDDRAGON_PRODUCT_ID) }, 783b92847425a98d26ad9d2b8682d3ce6020c90752Matthew Meno { USB_DEVICE(DATAPILOT_U2_VENDOR_ID, DATAPILOT_U2_PRODUCT_ID) }, 79b7aa94b682dc6b6dcdc01d36f8e65cef5aae81e2Kim Oldfield { USB_DEVICE(BELKIN_VENDOR_ID, BELKIN_PRODUCT_ID) }, 808fd801339350b63cbb90730ff8b2be349fb3dc67Johannes Steingraeber { USB_DEVICE(ALCOR_VENDOR_ID, ALCOR_PRODUCT_ID) }, 812d94b981c7fcb0fba4aa3442cd180066dbedbbc8YOSHIFUJI Hideaki { USB_DEVICE(WS002IN_VENDOR_ID, WS002IN_PRODUCT_ID) }, 829e3285dba5cac12d656da66fd7d420ff1bc0ecc0Magnus Damm { USB_DEVICE(COREGA_VENDOR_ID, COREGA_PRODUCT_ID) }, 83cc311ee7d29d96f0bf15599f4456012d6f5ea23cDamien Stuart { USB_DEVICE(YCCABLE_VENDOR_ID, YCCABLE_PRODUCT_ID) }, 847c99200142c04d0f1ed3f048014591f841efdaedMatthew Arnold { USB_DEVICE(SUPERIAL_VENDOR_ID, SUPERIAL_PRODUCT_ID) }, 85af4b8514aafd53d97b05a0a30b7d4cfd2cbb7b81Mike Provencher { USB_DEVICE(HP_VENDOR_ID, HP_LD220_PRODUCT_ID) }, 868540d66615c39010168ab97eaafb476ec2851298Gianpaolo Cugola { USB_DEVICE(CRESSI_VENDOR_ID, CRESSI_EDY_PRODUCT_ID) }, 87f36ecd5de93e4c85a9e3d25100c6e233155b12e5Jef Driesen { USB_DEVICE(ZEAGLE_VENDOR_ID, ZEAGLE_N2ITION3_PRODUCT_ID) }, 8849276560c9004fce24c42e3c0ad75f34d956fc63Khanh-Dang Nguyen Thu Lam { USB_DEVICE(SONY_VENDOR_ID, SONY_QN3USB_PRODUCT_ID) }, 8935904e6b5106fda51b04c8b8080c04466865415fPawel Ludwikow { USB_DEVICE(SANWA_VENDOR_ID, SANWA_PRODUCT_ID) }, 909a61d72602771906e11a5944e8571f8006387b39Manuel Jander { USB_DEVICE(ADLINK_VENDOR_ID, ADLINK_ND6530_PRODUCT_ID) }, 91598f0b703506da841d3459dc0c48506be14d1778Eric Benoit { USB_DEVICE(SMART_VENDOR_ID, SMART_PRODUCT_ID) }, 921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { } /* Terminating entry */ 931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 95372db8a780f63368c6960a167b7a19aad776d704Thiago GalesiMODULE_DEVICE_TABLE(usb, id_table); 961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SET_LINE_REQUEST_TYPE 0x21 981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SET_LINE_REQUEST 0x20 991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SET_CONTROL_REQUEST_TYPE 0x21 1011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SET_CONTROL_REQUEST 0x22 1021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define CONTROL_DTR 0x01 1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define CONTROL_RTS 0x02 1041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define BREAK_REQUEST_TYPE 0x21 1063a0f43e9deffd9619ac34e3b6b9ba7089aa1e511Alan Cox#define BREAK_REQUEST 0x23 1071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define BREAK_ON 0xffff 1081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define BREAK_OFF 0x0000 1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define GET_LINE_REQUEST_TYPE 0xa1 1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define GET_LINE_REQUEST 0x21 1121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define VENDOR_WRITE_REQUEST_TYPE 0x40 1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define VENDOR_WRITE_REQUEST 0x01 1151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define VENDOR_READ_REQUEST_TYPE 0xc0 1171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define VENDOR_READ_REQUEST 0x01 1181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define UART_STATE 0x08 1201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define UART_STATE_TRANSIENT_MASK 0x74 1211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define UART_DCD 0x01 1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define UART_DSR 0x02 1231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define UART_BREAK_ERROR 0x04 1241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define UART_RING 0x08 1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define UART_FRAME_ERROR 0x10 1261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define UART_PARITY_ERROR 0x20 1271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define UART_OVERRUN_ERROR 0x40 1281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define UART_CTS 0x80 1291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsenum pl2303_type { 132e8bbd5c42b65b662756d67290a5c4dcda1abc596Greg Kroah-Hartman type_0, /* don't know the difference between type 0 and */ 133e8bbd5c42b65b662756d67290a5c4dcda1abc596Greg Kroah-Hartman type_1, /* type 1, until someone from prolific tells us... */ 134e8bbd5c42b65b662756d67290a5c4dcda1abc596Greg Kroah-Hartman HX, /* HX version of the pl2303 chip */ 1351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 1361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1378bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovoldstruct pl2303_serial_private { 1388bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold enum pl2303_type type; 1398bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold}; 1408bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold 1411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct pl2303_private { 1421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spinlock_t lock; 1431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u8 line_control; 1441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u8 line_status; 145623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold 146623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold u8 line_settings[7]; 1471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 1481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 149eb44da0b3aa0105cb38d81c5747a8feae64834beSarah Sharpstatic int pl2303_vendor_read(__u16 value, __u16 index, 150eb44da0b3aa0105cb38d81c5747a8feae64834beSarah Sharp struct usb_serial *serial, unsigned char *buf) 151eb44da0b3aa0105cb38d81c5747a8feae64834beSarah Sharp{ 152eb44da0b3aa0105cb38d81c5747a8feae64834beSarah Sharp int res = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 153eb44da0b3aa0105cb38d81c5747a8feae64834beSarah Sharp VENDOR_READ_REQUEST, VENDOR_READ_REQUEST_TYPE, 154eb44da0b3aa0105cb38d81c5747a8feae64834beSarah Sharp value, index, buf, 1, 100); 1557b5789a86890423e1460362798140c26822798b1Johan Hovold dev_dbg(&serial->interface->dev, "0x%x:0x%x:0x%x:0x%x %d - %x\n", 156d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, value, index, 157d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman res, buf[0]); 158eb44da0b3aa0105cb38d81c5747a8feae64834beSarah Sharp return res; 159eb44da0b3aa0105cb38d81c5747a8feae64834beSarah Sharp} 160eb44da0b3aa0105cb38d81c5747a8feae64834beSarah Sharp 161eb44da0b3aa0105cb38d81c5747a8feae64834beSarah Sharpstatic int pl2303_vendor_write(__u16 value, __u16 index, 162eb44da0b3aa0105cb38d81c5747a8feae64834beSarah Sharp struct usb_serial *serial) 163eb44da0b3aa0105cb38d81c5747a8feae64834beSarah Sharp{ 164eb44da0b3aa0105cb38d81c5747a8feae64834beSarah Sharp int res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 165eb44da0b3aa0105cb38d81c5747a8feae64834beSarah Sharp VENDOR_WRITE_REQUEST, VENDOR_WRITE_REQUEST_TYPE, 166eb44da0b3aa0105cb38d81c5747a8feae64834beSarah Sharp value, index, NULL, 0, 100); 1677b5789a86890423e1460362798140c26822798b1Johan Hovold dev_dbg(&serial->interface->dev, "0x%x:0x%x:0x%x:0x%x %d\n", 168d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, value, index, 169d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman res); 170eb44da0b3aa0105cb38d81c5747a8feae64834beSarah Sharp return res; 171eb44da0b3aa0105cb38d81c5747a8feae64834beSarah Sharp} 172eb44da0b3aa0105cb38d81c5747a8feae64834beSarah Sharp 173372db8a780f63368c6960a167b7a19aad776d704Thiago Galesistatic int pl2303_startup(struct usb_serial *serial) 1741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1758bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold struct pl2303_serial_private *spriv; 1761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds enum pl2303_type type = type_0; 1773e152505a57db6622deb1322c22551c046e33d16Sarah Sharp unsigned char *buf; 1788bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold 1798bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold spriv = kzalloc(sizeof(*spriv), GFP_KERNEL); 1808bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold if (!spriv) 1818bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold return -ENOMEM; 1821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1833e152505a57db6622deb1322c22551c046e33d16Sarah Sharp buf = kmalloc(10, GFP_KERNEL); 1848bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold if (!buf) { 1858bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold kfree(spriv); 1863e152505a57db6622deb1322c22551c046e33d16Sarah Sharp return -ENOMEM; 1878bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold } 1883e152505a57db6622deb1322c22551c046e33d16Sarah Sharp 189b52e111363e366202386f3e67f71681dbbb8e5d9Greg Kroah-Hartman if (serial->dev->descriptor.bDeviceClass == 0x02) 1901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds type = type_0; 191b52e111363e366202386f3e67f71681dbbb8e5d9Greg Kroah-Hartman else if (serial->dev->descriptor.bMaxPacketSize0 == 0x40) 192e8bbd5c42b65b662756d67290a5c4dcda1abc596Greg Kroah-Hartman type = HX; 193281393ad0bcfc309434d2bff38abc15805c2cbc4Greg Kroah-Hartman else if (serial->dev->descriptor.bDeviceClass == 0x00) 194281393ad0bcfc309434d2bff38abc15805c2cbc4Greg Kroah-Hartman type = type_1; 195281393ad0bcfc309434d2bff38abc15805c2cbc4Greg Kroah-Hartman else if (serial->dev->descriptor.bDeviceClass == 0xFF) 1961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds type = type_1; 197b52e111363e366202386f3e67f71681dbbb8e5d9Greg Kroah-Hartman dev_dbg(&serial->interface->dev, "device type: %d\n", type); 1981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1998bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold spriv->type = type; 2008bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold usb_set_serial_data(serial, spriv); 2013e152505a57db6622deb1322c22551c046e33d16Sarah Sharp 2023e152505a57db6622deb1322c22551c046e33d16Sarah Sharp pl2303_vendor_read(0x8484, 0, serial, buf); 2033e152505a57db6622deb1322c22551c046e33d16Sarah Sharp pl2303_vendor_write(0x0404, 0, serial); 2043e152505a57db6622deb1322c22551c046e33d16Sarah Sharp pl2303_vendor_read(0x8484, 0, serial, buf); 2053e152505a57db6622deb1322c22551c046e33d16Sarah Sharp pl2303_vendor_read(0x8383, 0, serial, buf); 2063e152505a57db6622deb1322c22551c046e33d16Sarah Sharp pl2303_vendor_read(0x8484, 0, serial, buf); 2073e152505a57db6622deb1322c22551c046e33d16Sarah Sharp pl2303_vendor_write(0x0404, 1, serial); 2083e152505a57db6622deb1322c22551c046e33d16Sarah Sharp pl2303_vendor_read(0x8484, 0, serial, buf); 2093e152505a57db6622deb1322c22551c046e33d16Sarah Sharp pl2303_vendor_read(0x8383, 0, serial, buf); 2103e152505a57db6622deb1322c22551c046e33d16Sarah Sharp pl2303_vendor_write(0, 1, serial); 2113e152505a57db6622deb1322c22551c046e33d16Sarah Sharp pl2303_vendor_write(1, 0, serial); 212e8bbd5c42b65b662756d67290a5c4dcda1abc596Greg Kroah-Hartman if (type == HX) 213034d1527adebd302115c87ef343497a889638275Frank Schäfer pl2303_vendor_write(2, 0x44, serial); 214e8bbd5c42b65b662756d67290a5c4dcda1abc596Greg Kroah-Hartman else 215e8bbd5c42b65b662756d67290a5c4dcda1abc596Greg Kroah-Hartman pl2303_vendor_write(2, 0x24, serial); 2163e152505a57db6622deb1322c22551c046e33d16Sarah Sharp 2173e152505a57db6622deb1322c22551c046e33d16Sarah Sharp kfree(buf); 2181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 2198bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold} 2201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2218bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovoldstatic void pl2303_release(struct usb_serial *serial) 2228bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold{ 2238bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold struct pl2303_serial_private *spriv; 2248bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold 2258bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold spriv = usb_get_serial_data(serial); 2268bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold kfree(spriv); 2278bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold} 2288bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold 2298bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovoldstatic int pl2303_port_probe(struct usb_serial_port *port) 2308bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold{ 2318bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold struct pl2303_private *priv; 2328bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold 2338bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold priv = kzalloc(sizeof(*priv), GFP_KERNEL); 2348bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold if (!priv) 2358bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold return -ENOMEM; 2368bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold 2378bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold spin_lock_init(&priv->lock); 2388bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold 2398bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold usb_set_serial_port_data(port, priv); 2408bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold 241d7be62211125c85fa1dd796e92aadce84961a502Johan Hovold port->port.drain_delay = 256; 242d7be62211125c85fa1dd796e92aadce84961a502Johan Hovold 2438bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold return 0; 2448bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold} 2458bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold 2468bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovoldstatic int pl2303_port_remove(struct usb_serial_port *port) 2478bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold{ 2488bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold struct pl2303_private *priv; 2498bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold 2508bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold priv = usb_get_serial_port_data(port); 2518bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold kfree(priv); 2528bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold 2538bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold return 0; 2541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 2551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 256f45d0a5aa593cdf48a37489fc61c145e16964288Johan Hovoldstatic int pl2303_set_control_lines(struct usb_serial_port *port, u8 value) 2571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 258f45d0a5aa593cdf48a37489fc61c145e16964288Johan Hovold struct usb_device *dev = port->serial->dev; 2591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int retval; 2603a0f43e9deffd9619ac34e3b6b9ba7089aa1e511Alan Cox 261372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 262372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE, 263372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi value, 0, NULL, 0, 100); 264f45d0a5aa593cdf48a37489fc61c145e16964288Johan Hovold dev_dbg(&port->dev, "%s - value = %d, retval = %d\n", __func__, 265d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman value, retval); 2661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return retval; 2671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 2681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 26915e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovoldstatic void pl2303_encode_baudrate(struct tty_struct *tty, 27015e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold struct usb_serial_port *port, 27115e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold u8 buf[4]) 2721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2737e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman const int baud_sup[] = { 75, 150, 300, 600, 1200, 1800, 2400, 3600, 2747e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman 4800, 7200, 9600, 14400, 19200, 28800, 38400, 2757e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman 57600, 115200, 230400, 460800, 500000, 614400, 2767e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman 921600, 1228800, 2457600, 3000000, 6000000 }; 2777e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman 278692ed4ddf0010dd643d38d6ef1a15bf64a7fbc6dGreg Kroah-Hartman struct usb_serial *serial = port->serial; 279692ed4ddf0010dd643d38d6ef1a15bf64a7fbc6dGreg Kroah-Hartman struct pl2303_serial_private *spriv = usb_get_serial_data(serial); 28015e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold int baud; 2817e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman int i; 2821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2837e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman /* 2847e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman * NOTE: Only the values defined in baud_sup are supported! 2857e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman * => if unsupported values are set, the PL2303 seems to use 2867e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman * 9600 baud (at least my PL2303X always does) 2877e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman */ 28895da310e66ee8090119596c70ca8432e57f9a97fAlan Cox baud = tty_get_baud_rate(tty); 289d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman dev_dbg(&port->dev, "baud requested = %d\n", baud); 290b2d6d98fc71bb94ada78d433f26a93498802d3f8Johan Hovold if (!baud) 291b2d6d98fc71bb94ada78d433f26a93498802d3f8Johan Hovold return; 292692ed4ddf0010dd643d38d6ef1a15bf64a7fbc6dGreg Kroah-Hartman 2937e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman /* Set baudrate to nearest supported value */ 2947e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman for (i = 0; i < ARRAY_SIZE(baud_sup); ++i) { 2957e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman if (baud_sup[i] > baud) 2967e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman break; 2977e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman } 298692ed4ddf0010dd643d38d6ef1a15bf64a7fbc6dGreg Kroah-Hartman 2997e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman if (i == ARRAY_SIZE(baud_sup)) 3007e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman baud = baud_sup[i - 1]; 3017e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman else if (i > 0 && (baud_sup[i] - baud) > (baud - baud_sup[i - 1])) 3027e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman baud = baud_sup[i - 1]; 3037e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman else 3047e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman baud = baud_sup[i]; 305692ed4ddf0010dd643d38d6ef1a15bf64a7fbc6dGreg Kroah-Hartman 3067e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman /* type_0, type_1 only support up to 1228800 baud */ 3077e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman if (spriv->type != HX) 3087e12a6fcbf266eb0d5b19761f91b2964ad18e371Greg Kroah-Hartman baud = min_t(int, baud, 1228800); 309692ed4ddf0010dd643d38d6ef1a15bf64a7fbc6dGreg Kroah-Hartman 31054dc5792ea933a3ff8c62a1f9ea9e4e6cbdd324aGreg Kroah-Hartman if (baud <= 115200) { 311692ed4ddf0010dd643d38d6ef1a15bf64a7fbc6dGreg Kroah-Hartman put_unaligned_le32(baud, buf); 312692ed4ddf0010dd643d38d6ef1a15bf64a7fbc6dGreg Kroah-Hartman } else { 313692ed4ddf0010dd643d38d6ef1a15bf64a7fbc6dGreg Kroah-Hartman /* 3141796a228762cd0b86e14d6d4a3de9ecfe65b3b8dGreg Kroah-Hartman * Apparently the formula for higher speeds is: 3151796a228762cd0b86e14d6d4a3de9ecfe65b3b8dGreg Kroah-Hartman * baudrate = 12M * 32 / (2^buf[1]) / buf[0] 316692ed4ddf0010dd643d38d6ef1a15bf64a7fbc6dGreg Kroah-Hartman */ 3171796a228762cd0b86e14d6d4a3de9ecfe65b3b8dGreg Kroah-Hartman unsigned tmp = 12000000 * 32 / baud; 3181796a228762cd0b86e14d6d4a3de9ecfe65b3b8dGreg Kroah-Hartman buf[3] = 0x80; 319692ed4ddf0010dd643d38d6ef1a15bf64a7fbc6dGreg Kroah-Hartman buf[2] = 0; 3201796a228762cd0b86e14d6d4a3de9ecfe65b3b8dGreg Kroah-Hartman buf[1] = (tmp >= 256); 3211796a228762cd0b86e14d6d4a3de9ecfe65b3b8dGreg Kroah-Hartman while (tmp >= 256) { 3221796a228762cd0b86e14d6d4a3de9ecfe65b3b8dGreg Kroah-Hartman tmp >>= 2; 3231796a228762cd0b86e14d6d4a3de9ecfe65b3b8dGreg Kroah-Hartman buf[1] <<= 1; 3241796a228762cd0b86e14d6d4a3de9ecfe65b3b8dGreg Kroah-Hartman } 3251796a228762cd0b86e14d6d4a3de9ecfe65b3b8dGreg Kroah-Hartman buf[0] = tmp; 326692ed4ddf0010dd643d38d6ef1a15bf64a7fbc6dGreg Kroah-Hartman } 327692ed4ddf0010dd643d38d6ef1a15bf64a7fbc6dGreg Kroah-Hartman 32815e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold /* Save resulting baud rate */ 329b2d6d98fc71bb94ada78d433f26a93498802d3f8Johan Hovold tty_encode_baud_rate(tty, baud, baud); 330b2d6d98fc71bb94ada78d433f26a93498802d3f8Johan Hovold dev_dbg(&port->dev, "baud set = %d\n", baud); 33115e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold} 33215e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold 33315e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovoldstatic void pl2303_set_termios(struct tty_struct *tty, 33415e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold struct usb_serial_port *port, struct ktermios *old_termios) 33515e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold{ 33615e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold struct usb_serial *serial = port->serial; 33715e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold struct pl2303_serial_private *spriv = usb_get_serial_data(serial); 33815e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold struct pl2303_private *priv = usb_get_serial_port_data(port); 33915e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold unsigned long flags; 34015e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold unsigned char *buf; 34115e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold int i; 34215e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold u8 control; 34315e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold 34415e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold if (old_termios && !tty_termios_hw_change(&tty->termios, old_termios)) 34515e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold return; 34615e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold 34715e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold buf = kzalloc(7, GFP_KERNEL); 34815e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold if (!buf) { 34915e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold dev_err(&port->dev, "%s - out of memory.\n", __func__); 35015e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold /* Report back no change occurred */ 35115e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold if (old_termios) 35215e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold tty->termios = *old_termios; 35315e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold return; 35415e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold } 35515e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold 35615e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold i = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 35715e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE, 35815e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold 0, 0, buf, 7, 100); 35915e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold dev_dbg(&port->dev, "0xa1:0x21:0:0 %d - %7ph\n", i, buf); 36015e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold 361a313249937820f8b1996133fc285efbd6aad2c5bColin Leitner switch (C_CSIZE(tty)) { 362a313249937820f8b1996133fc285efbd6aad2c5bColin Leitner case CS5: 363a313249937820f8b1996133fc285efbd6aad2c5bColin Leitner buf[6] = 5; 364a313249937820f8b1996133fc285efbd6aad2c5bColin Leitner break; 365a313249937820f8b1996133fc285efbd6aad2c5bColin Leitner case CS6: 366a313249937820f8b1996133fc285efbd6aad2c5bColin Leitner buf[6] = 6; 367a313249937820f8b1996133fc285efbd6aad2c5bColin Leitner break; 368a313249937820f8b1996133fc285efbd6aad2c5bColin Leitner case CS7: 369a313249937820f8b1996133fc285efbd6aad2c5bColin Leitner buf[6] = 7; 370a313249937820f8b1996133fc285efbd6aad2c5bColin Leitner break; 371a313249937820f8b1996133fc285efbd6aad2c5bColin Leitner default: 372a313249937820f8b1996133fc285efbd6aad2c5bColin Leitner case CS8: 373a313249937820f8b1996133fc285efbd6aad2c5bColin Leitner buf[6] = 8; 37415e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold } 375a313249937820f8b1996133fc285efbd6aad2c5bColin Leitner dev_dbg(&port->dev, "data bits = %d\n", buf[6]); 37615e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold 377692ed4ddf0010dd643d38d6ef1a15bf64a7fbc6dGreg Kroah-Hartman /* For reference buf[0]:buf[3] baud rate value */ 378692ed4ddf0010dd643d38d6ef1a15bf64a7fbc6dGreg Kroah-Hartman pl2303_encode_baudrate(tty, port, &buf[0]); 37915e7cead1ed89d445cf86c75a72368e98a7a9039Johan Hovold 3801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* For reference buf[4]=0 is 1 stop bits */ 3811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* For reference buf[4]=1 is 1.5 stop bits */ 3821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* For reference buf[4]=2 is 2 stop bits */ 38387265b4514f5a0b79efdccdcb1c6331285652640Johan Hovold if (C_CSTOPB(tty)) { 38487265b4514f5a0b79efdccdcb1c6331285652640Johan Hovold /* 38587265b4514f5a0b79efdccdcb1c6331285652640Johan Hovold * NOTE: Comply with "real" UARTs / RS232: 38629cf1b72f34519413b3fafbccc9ac776eb948edeFrank Schaefer * use 1.5 instead of 2 stop bits with 5 data bits 38729cf1b72f34519413b3fafbccc9ac776eb948edeFrank Schaefer */ 38887265b4514f5a0b79efdccdcb1c6331285652640Johan Hovold if (C_CSIZE(tty) == CS5) { 38929cf1b72f34519413b3fafbccc9ac776eb948edeFrank Schaefer buf[4] = 1; 390d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman dev_dbg(&port->dev, "stop bits = 1.5\n"); 39129cf1b72f34519413b3fafbccc9ac776eb948edeFrank Schaefer } else { 39229cf1b72f34519413b3fafbccc9ac776eb948edeFrank Schaefer buf[4] = 2; 393d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman dev_dbg(&port->dev, "stop bits = 2\n"); 39429cf1b72f34519413b3fafbccc9ac776eb948edeFrank Schaefer } 3951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 3961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds buf[4] = 0; 397d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman dev_dbg(&port->dev, "stop bits = 1\n"); 3981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 3991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 40087265b4514f5a0b79efdccdcb1c6331285652640Johan Hovold if (C_PARENB(tty)) { 4011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* For reference buf[5]=0 is none parity */ 4021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* For reference buf[5]=1 is odd parity */ 4031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* For reference buf[5]=2 is even parity */ 4041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* For reference buf[5]=3 is mark parity */ 4051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* For reference buf[5]=4 is space parity */ 40687265b4514f5a0b79efdccdcb1c6331285652640Johan Hovold if (C_PARODD(tty)) { 40787265b4514f5a0b79efdccdcb1c6331285652640Johan Hovold if (tty->termios.c_cflag & CMSPAR) { 4086dd81b45fd7628f3eb308f387aee696366718f25Frank Schaefer buf[5] = 3; 409d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman dev_dbg(&port->dev, "parity = mark\n"); 4106dd81b45fd7628f3eb308f387aee696366718f25Frank Schaefer } else { 4116dd81b45fd7628f3eb308f387aee696366718f25Frank Schaefer buf[5] = 1; 412d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman dev_dbg(&port->dev, "parity = odd\n"); 4136dd81b45fd7628f3eb308f387aee696366718f25Frank Schaefer } 4141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 41587265b4514f5a0b79efdccdcb1c6331285652640Johan Hovold if (tty->termios.c_cflag & CMSPAR) { 4166dd81b45fd7628f3eb308f387aee696366718f25Frank Schaefer buf[5] = 4; 417d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman dev_dbg(&port->dev, "parity = space\n"); 4186dd81b45fd7628f3eb308f387aee696366718f25Frank Schaefer } else { 4196dd81b45fd7628f3eb308f387aee696366718f25Frank Schaefer buf[5] = 2; 420d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman dev_dbg(&port->dev, "parity = even\n"); 4216dd81b45fd7628f3eb308f387aee696366718f25Frank Schaefer } 4221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 4241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds buf[5] = 0; 425d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman dev_dbg(&port->dev, "parity = none\n"); 4261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 428623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold /* 429623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold * Some PL2303 are known to lose bytes if you change serial settings 430623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold * even to the same values as before. Thus we actually need to filter 431623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold * in this specific case. 432623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold * 433623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold * Note that the tty_termios_hw_change check above is not sufficient 434623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold * as a previously requested baud rate may differ from the one 435623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold * actually used (and stored in old_termios). 436623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold * 437623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold * NOTE: No additional locking needed for line_settings as it is 438623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold * only used in set_termios, which is serialised against itself. 439623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold */ 440623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold if (!old_termios || memcmp(buf, priv->line_settings, 7)) { 441623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold i = usb_control_msg(serial->dev, 442623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold usb_sndctrlpipe(serial->dev, 0), 443623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold SET_LINE_REQUEST, SET_LINE_REQUEST_TYPE, 444623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold 0, 0, buf, 7, 100); 445623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold 446623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold dev_dbg(&port->dev, "0x21:0x20:0:0 %d\n", i); 447623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold 448623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold if (i == 7) 449623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold memcpy(priv->line_settings, buf, 7); 450623c8263376c0b8a4b0c220232e7313d762cd0ccJohan Hovold } 4511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* change control lines if we are switching to or from B0 */ 4531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_lock_irqsave(&priv->lock, flags); 4541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds control = priv->line_control; 45587265b4514f5a0b79efdccdcb1c6331285652640Johan Hovold if (C_BAUD(tty) == B0) 4561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS); 4572d8f4447b58bba5f8cb895c07690434c02307eafJohan Hovold else if (old_termios && (old_termios->c_cflag & CBAUD) == B0) 4581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->line_control |= (CONTROL_DTR | CONTROL_RTS); 4591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (control != priv->line_control) { 4601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds control = priv->line_control; 4611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_unlock_irqrestore(&priv->lock, flags); 462f45d0a5aa593cdf48a37489fc61c145e16964288Johan Hovold pl2303_set_control_lines(port, control); 4631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 4641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_unlock_irqrestore(&priv->lock, flags); 4651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 466372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi 46787265b4514f5a0b79efdccdcb1c6331285652640Johan Hovold memset(buf, 0, 7); 468372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi i = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 469372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE, 470372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi 0, 0, buf, 7, 100); 471715cf92aeb061c47f7170d0d7899311b7597bc66Andy Shevchenko dev_dbg(&port->dev, "0xa1:0x21:0:0 %d - %7ph\n", i, buf); 4721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 47387265b4514f5a0b79efdccdcb1c6331285652640Johan Hovold if (C_CRTSCTS(tty)) { 474e8bbd5c42b65b662756d67290a5c4dcda1abc596Greg Kroah-Hartman if (spriv->type == HX) 475034d1527adebd302115c87ef343497a889638275Frank Schäfer pl2303_vendor_write(0x0, 0x61, serial); 476e8bbd5c42b65b662756d67290a5c4dcda1abc596Greg Kroah-Hartman else 477e8bbd5c42b65b662756d67290a5c4dcda1abc596Greg Kroah-Hartman pl2303_vendor_write(0x0, 0x41, serial); 478715f9527c1c1edd1a9c7a55ab4535211279c9374t.sefzick } else { 479eb44da0b3aa0105cb38d81c5747a8feae64834beSarah Sharp pl2303_vendor_write(0x0, 0x0, serial); 4801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 481572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi 482572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi kfree(buf); 483572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi} 484572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi 485335f8514f200e63d689113d29cb7253a5c282967Alan Coxstatic void pl2303_dtr_rts(struct usb_serial_port *port, int on) 486335f8514f200e63d689113d29cb7253a5c282967Alan Cox{ 487335f8514f200e63d689113d29cb7253a5c282967Alan Cox struct pl2303_private *priv = usb_get_serial_port_data(port); 488335f8514f200e63d689113d29cb7253a5c282967Alan Cox unsigned long flags; 489335f8514f200e63d689113d29cb7253a5c282967Alan Cox u8 control; 490335f8514f200e63d689113d29cb7253a5c282967Alan Cox 491335f8514f200e63d689113d29cb7253a5c282967Alan Cox spin_lock_irqsave(&priv->lock, flags); 492335f8514f200e63d689113d29cb7253a5c282967Alan Cox /* Change DTR and RTS */ 493335f8514f200e63d689113d29cb7253a5c282967Alan Cox if (on) 494335f8514f200e63d689113d29cb7253a5c282967Alan Cox priv->line_control |= (CONTROL_DTR | CONTROL_RTS); 495335f8514f200e63d689113d29cb7253a5c282967Alan Cox else 496335f8514f200e63d689113d29cb7253a5c282967Alan Cox priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS); 497335f8514f200e63d689113d29cb7253a5c282967Alan Cox control = priv->line_control; 498335f8514f200e63d689113d29cb7253a5c282967Alan Cox spin_unlock_irqrestore(&priv->lock, flags); 499f45d0a5aa593cdf48a37489fc61c145e16964288Johan Hovold pl2303_set_control_lines(port, control); 500335f8514f200e63d689113d29cb7253a5c282967Alan Cox} 501335f8514f200e63d689113d29cb7253a5c282967Alan Cox 502335f8514f200e63d689113d29cb7253a5c282967Alan Coxstatic void pl2303_close(struct usb_serial_port *port) 503572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi{ 5048b0127b2082601e40295045414a8318f2c8ee5a0Johan Hovold usb_serial_generic_close(port); 505572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi usb_kill_urb(port->interrupt_in_urb); 5061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 5071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 508a509a7e478e4766114d69f12d19d644ac63e9765Alan Coxstatic int pl2303_open(struct tty_struct *tty, struct usb_serial_port *port) 5091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 5101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct usb_serial *serial = port->serial; 5118bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold struct pl2303_serial_private *spriv = usb_get_serial_data(serial); 5121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int result; 5131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 514e8bbd5c42b65b662756d67290a5c4dcda1abc596Greg Kroah-Hartman if (spriv->type != HX) { 5151694899fd1af43636351aac97f415fd3c9cefb1dDariusz M usb_clear_halt(serial->dev, port->write_urb->pipe); 5161694899fd1af43636351aac97f415fd3c9cefb1dDariusz M usb_clear_halt(serial->dev, port->read_urb->pipe); 5173e152505a57db6622deb1322c22551c046e33d16Sarah Sharp } else { 5181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* reset upstream data pipes */ 519eb44da0b3aa0105cb38d81c5747a8feae64834beSarah Sharp pl2303_vendor_write(8, 0, serial); 520eb44da0b3aa0105cb38d81c5747a8feae64834beSarah Sharp pl2303_vendor_write(9, 0, serial); 5211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Setup termios */ 52495da310e66ee8090119596c70ca8432e57f9a97fAlan Cox if (tty) 5252d8f4447b58bba5f8cb895c07690434c02307eafJohan Hovold pl2303_set_termios(tty, port, NULL); 5261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 527372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 5281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (result) { 529372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi dev_err(&port->dev, "%s - failed submitting interrupt urb," 530441b62c1edb986827154768d89bbac0ba779984fHarvey Harrison " error %d\n", __func__, result); 531db6e9186c90188edea20aaa5161ea073440cc2a1Johan Hovold return result; 5321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 533d4691c3fa3d371835b1eacb39066ab113c4b9d8cJohan Hovold 534f5230a53c1d551811b077ccad219105786da1becJohan Hovold result = usb_serial_generic_open(tty, port); 535d4691c3fa3d371835b1eacb39066ab113c4b9d8cJohan Hovold if (result) { 536d4691c3fa3d371835b1eacb39066ab113c4b9d8cJohan Hovold usb_kill_urb(port->interrupt_in_urb); 537d4691c3fa3d371835b1eacb39066ab113c4b9d8cJohan Hovold return result; 538d4691c3fa3d371835b1eacb39066ab113c4b9d8cJohan Hovold } 539d4691c3fa3d371835b1eacb39066ab113c4b9d8cJohan Hovold 5401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 5411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 5421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 54320b9d17715017ae4dd4ec87fabc36d33b9de708eAlan Coxstatic int pl2303_tiocmset(struct tty_struct *tty, 544372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi unsigned int set, unsigned int clear) 5451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 54695da310e66ee8090119596c70ca8432e57f9a97fAlan Cox struct usb_serial_port *port = tty->driver_data; 5471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct pl2303_private *priv = usb_get_serial_port_data(port); 5481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long flags; 5491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u8 control; 5506f1efd6c5aa63ddcfe1ffc60ade716f5421766f4Johan Hovold int ret; 5516fdd8e8e33730a2abc886113bd0b6c4343f63cc9Flavio Leitner 552372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi spin_lock_irqsave(&priv->lock, flags); 5531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (set & TIOCM_RTS) 5541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->line_control |= CONTROL_RTS; 5551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (set & TIOCM_DTR) 5561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->line_control |= CONTROL_DTR; 5571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (clear & TIOCM_RTS) 5581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->line_control &= ~CONTROL_RTS; 5591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (clear & TIOCM_DTR) 5601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds priv->line_control &= ~CONTROL_DTR; 5611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds control = priv->line_control; 562372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi spin_unlock_irqrestore(&priv->lock, flags); 5631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5645ddbb26b8b571231cace9f013b2d0ae66229b316Johan Hovold ret = pl2303_set_control_lines(port, control); 5655ddbb26b8b571231cace9f013b2d0ae66229b316Johan Hovold if (ret) 5665ddbb26b8b571231cace9f013b2d0ae66229b316Johan Hovold return usb_translate_errors(ret); 5676f1efd6c5aa63ddcfe1ffc60ade716f5421766f4Johan Hovold 5685ddbb26b8b571231cace9f013b2d0ae66229b316Johan Hovold return 0; 5691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 5701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 57160b33c133ca0b7c0b6072c87234b63fee6e80558Alan Coxstatic int pl2303_tiocmget(struct tty_struct *tty) 5721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 57395da310e66ee8090119596c70ca8432e57f9a97fAlan Cox struct usb_serial_port *port = tty->driver_data; 5741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct pl2303_private *priv = usb_get_serial_port_data(port); 5751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long flags; 5761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int mcr; 5771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int status; 5781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int result; 5791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 580372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi spin_lock_irqsave(&priv->lock, flags); 5811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mcr = priv->line_control; 5821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds status = priv->line_status; 583372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi spin_unlock_irqrestore(&priv->lock, flags); 5841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds result = ((mcr & CONTROL_DTR) ? TIOCM_DTR : 0) 5861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds | ((mcr & CONTROL_RTS) ? TIOCM_RTS : 0) 5871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds | ((status & UART_CTS) ? TIOCM_CTS : 0) 5881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds | ((status & UART_DSR) ? TIOCM_DSR : 0) 5891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds | ((status & UART_RING) ? TIOCM_RI : 0) 5901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds | ((status & UART_DCD) ? TIOCM_CD : 0); 5911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 592d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman dev_dbg(&port->dev, "%s - result = %x\n", __func__, result); 5931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return result; 5951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 5961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 597335f8514f200e63d689113d29cb7253a5c282967Alan Coxstatic int pl2303_carrier_raised(struct usb_serial_port *port) 598335f8514f200e63d689113d29cb7253a5c282967Alan Cox{ 599335f8514f200e63d689113d29cb7253a5c282967Alan Cox struct pl2303_private *priv = usb_get_serial_port_data(port); 600335f8514f200e63d689113d29cb7253a5c282967Alan Cox if (priv->line_status & UART_DCD) 601335f8514f200e63d689113d29cb7253a5c282967Alan Cox return 1; 602335f8514f200e63d689113d29cb7253a5c282967Alan Cox return 0; 603335f8514f200e63d689113d29cb7253a5c282967Alan Cox} 604335f8514f200e63d689113d29cb7253a5c282967Alan Cox 605824d11bef5540062d17380c65ee52d4b2948ca84Johan Hovoldstatic int pl2303_tiocmiwait(struct tty_struct *tty, unsigned long arg) 6061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 607824d11bef5540062d17380c65ee52d4b2948ca84Johan Hovold struct usb_serial_port *port = tty->driver_data; 6081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct pl2303_private *priv = usb_get_serial_port_data(port); 6091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long flags; 6101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int prevstatus; 6111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int status; 6121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int changed; 6131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 614372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi spin_lock_irqsave(&priv->lock, flags); 6151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds prevstatus = priv->line_status; 616372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi spin_unlock_irqrestore(&priv->lock, flags); 6171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds while (1) { 6196d0cad657a133818038683120fff9c5c5f8dc751Johan Hovold interruptible_sleep_on(&port->port.delta_msr_wait); 6201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* see if a signal did it */ 6211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (signal_pending(current)) 6221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -ERESTARTSYS; 623372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi 62440509ca982c00c4b70fc00be887509feca0bff15Johan Hovold if (port->serial->disconnected) 62540509ca982c00c4b70fc00be887509feca0bff15Johan Hovold return -EIO; 62640509ca982c00c4b70fc00be887509feca0bff15Johan Hovold 627372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi spin_lock_irqsave(&priv->lock, flags); 6281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds status = priv->line_status; 629372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi spin_unlock_irqrestore(&priv->lock, flags); 630372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi 6313a0f43e9deffd9619ac34e3b6b9ba7089aa1e511Alan Cox changed = prevstatus ^ status; 632372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi 6331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (((arg & TIOCM_RNG) && (changed & UART_RING)) || 6341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ((arg & TIOCM_DSR) && (changed & UART_DSR)) || 6351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ((arg & TIOCM_CD) && (changed & UART_DCD)) || 6363a0f43e9deffd9619ac34e3b6b9ba7089aa1e511Alan Cox ((arg & TIOCM_CTS) && (changed & UART_CTS))) { 6371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 6381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 6391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds prevstatus = status; 6401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 6411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* NOTREACHED */ 6421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 6431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 64500a0d0d65b61241a718d0aee96f46b9a2d93bf26Alan Coxstatic int pl2303_ioctl(struct tty_struct *tty, 646372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi unsigned int cmd, unsigned long arg) 6471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 64867b9946dd07eeef8188e4cab816d2c370bcaa7b2John Tsiombikas struct serial_struct ser; 64995da310e66ee8090119596c70ca8432e57f9a97fAlan Cox struct usb_serial_port *port = tty->driver_data; 650d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman 651d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman dev_dbg(&port->dev, "%s cmd = 0x%04x\n", __func__, cmd); 6521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds switch (cmd) { 65467b9946dd07eeef8188e4cab816d2c370bcaa7b2John Tsiombikas case TIOCGSERIAL: 65567b9946dd07eeef8188e4cab816d2c370bcaa7b2John Tsiombikas memset(&ser, 0, sizeof ser); 65667b9946dd07eeef8188e4cab816d2c370bcaa7b2John Tsiombikas ser.type = PORT_16654; 657e5b1e2062e0535e8ffef79bb34d857e21380d101Greg Kroah-Hartman ser.line = port->minor; 6581143832eca8f1d64da7d85642c956ae9d25c69e1Greg Kroah-Hartman ser.port = port->port_number; 65967b9946dd07eeef8188e4cab816d2c370bcaa7b2John Tsiombikas ser.baud_base = 460800; 66067b9946dd07eeef8188e4cab816d2c370bcaa7b2John Tsiombikas 66167b9946dd07eeef8188e4cab816d2c370bcaa7b2John Tsiombikas if (copy_to_user((void __user *)arg, &ser, sizeof ser)) 66267b9946dd07eeef8188e4cab816d2c370bcaa7b2John Tsiombikas return -EFAULT; 66367b9946dd07eeef8188e4cab816d2c370bcaa7b2John Tsiombikas 66467b9946dd07eeef8188e4cab816d2c370bcaa7b2John Tsiombikas return 0; 6653a0f43e9deffd9619ac34e3b6b9ba7089aa1e511Alan Cox default: 666d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman dev_dbg(&port->dev, "%s not supported = 0x%04x\n", __func__, cmd); 6673a0f43e9deffd9619ac34e3b6b9ba7089aa1e511Alan Cox break; 6681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 6691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -ENOIOCTLCMD; 6701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 67295da310e66ee8090119596c70ca8432e57f9a97fAlan Coxstatic void pl2303_break_ctl(struct tty_struct *tty, int break_state) 6731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 67495da310e66ee8090119596c70ca8432e57f9a97fAlan Cox struct usb_serial_port *port = tty->driver_data; 6751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct usb_serial *serial = port->serial; 6761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u16 state; 6771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int result; 6781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (break_state == 0) 6801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds state = BREAK_OFF; 6811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds else 6821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds state = BREAK_ON; 683d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman dev_dbg(&port->dev, "%s - turning break %s\n", __func__, 6843a0f43e9deffd9619ac34e3b6b9ba7089aa1e511Alan Cox state == BREAK_OFF ? "off" : "on"); 6851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 686372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 687372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi BREAK_REQUEST, BREAK_REQUEST_TYPE, state, 688372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi 0, NULL, 0, 100); 6891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (result) 690d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman dev_err(&port->dev, "error sending break = %d\n", result); 6911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 69397bb13ec5bc156352cca8af90080597e04299a73Flavio Leitnerstatic void pl2303_update_line_status(struct usb_serial_port *port, 69497bb13ec5bc156352cca8af90080597e04299a73Flavio Leitner unsigned char *data, 69597bb13ec5bc156352cca8af90080597e04299a73Flavio Leitner unsigned int actual_length) 69697bb13ec5bc156352cca8af90080597e04299a73Flavio Leitner{ 69797bb13ec5bc156352cca8af90080597e04299a73Flavio Leitner 69897bb13ec5bc156352cca8af90080597e04299a73Flavio Leitner struct pl2303_private *priv = usb_get_serial_port_data(port); 699d14fc1a74e846d7851f24fc9519fe87dc12a1231Libor Pechacek struct tty_struct *tty; 70097bb13ec5bc156352cca8af90080597e04299a73Flavio Leitner unsigned long flags; 70197bb13ec5bc156352cca8af90080597e04299a73Flavio Leitner u8 status_idx = UART_STATE; 70295f209f93663103db2a8fb989e226ac68a98b036Horst Schirmeier u8 length = UART_STATE + 1; 703d14fc1a74e846d7851f24fc9519fe87dc12a1231Libor Pechacek u8 prev_line_status; 7049c53761681497d598a31ed2f6b29b5b3480c49dbThiago Galesi u16 idv, idp; 70597bb13ec5bc156352cca8af90080597e04299a73Flavio Leitner 7069c53761681497d598a31ed2f6b29b5b3480c49dbThiago Galesi idv = le16_to_cpu(port->serial->dev->descriptor.idVendor); 7079c53761681497d598a31ed2f6b29b5b3480c49dbThiago Galesi idp = le16_to_cpu(port->serial->dev->descriptor.idProduct); 7089c53761681497d598a31ed2f6b29b5b3480c49dbThiago Galesi 7099c53761681497d598a31ed2f6b29b5b3480c49dbThiago Galesi 7109c53761681497d598a31ed2f6b29b5b3480c49dbThiago Galesi if (idv == SIEMENS_VENDOR_ID) { 7119c53761681497d598a31ed2f6b29b5b3480c49dbThiago Galesi if (idp == SIEMENS_PRODUCT_ID_X65 || 7129c53761681497d598a31ed2f6b29b5b3480c49dbThiago Galesi idp == SIEMENS_PRODUCT_ID_SX1 || 7139c53761681497d598a31ed2f6b29b5b3480c49dbThiago Galesi idp == SIEMENS_PRODUCT_ID_X75) { 7149c53761681497d598a31ed2f6b29b5b3480c49dbThiago Galesi 7159c53761681497d598a31ed2f6b29b5b3480c49dbThiago Galesi length = 1; 7169c53761681497d598a31ed2f6b29b5b3480c49dbThiago Galesi status_idx = 0; 7179c53761681497d598a31ed2f6b29b5b3480c49dbThiago Galesi } 71897bb13ec5bc156352cca8af90080597e04299a73Flavio Leitner } 71997bb13ec5bc156352cca8af90080597e04299a73Flavio Leitner 72097bb13ec5bc156352cca8af90080597e04299a73Flavio Leitner if (actual_length < length) 721a009b75aa0ed55f0bc473c8a3b3e872cbca807ecLuiz Fernando N. Capitulino return; 72297bb13ec5bc156352cca8af90080597e04299a73Flavio Leitner 7233a0f43e9deffd9619ac34e3b6b9ba7089aa1e511Alan Cox /* Save off the uart status for others to look at */ 72497bb13ec5bc156352cca8af90080597e04299a73Flavio Leitner spin_lock_irqsave(&priv->lock, flags); 725d14fc1a74e846d7851f24fc9519fe87dc12a1231Libor Pechacek prev_line_status = priv->line_status; 72697bb13ec5bc156352cca8af90080597e04299a73Flavio Leitner priv->line_status = data[status_idx]; 72797bb13ec5bc156352cca8af90080597e04299a73Flavio Leitner spin_unlock_irqrestore(&priv->lock, flags); 728430eb0d27c1b36c5191c16b2472b26137673a8d4Jason Wessel if (priv->line_status & UART_BREAK_ERROR) 729430eb0d27c1b36c5191c16b2472b26137673a8d4Jason Wessel usb_serial_handle_break(port); 7306d0cad657a133818038683120fff9c5c5f8dc751Johan Hovold wake_up_interruptible(&port->port.delta_msr_wait); 731d14fc1a74e846d7851f24fc9519fe87dc12a1231Libor Pechacek 732d14fc1a74e846d7851f24fc9519fe87dc12a1231Libor Pechacek tty = tty_port_tty_get(&port->port); 733d14fc1a74e846d7851f24fc9519fe87dc12a1231Libor Pechacek if (!tty) 734d14fc1a74e846d7851f24fc9519fe87dc12a1231Libor Pechacek return; 735d14fc1a74e846d7851f24fc9519fe87dc12a1231Libor Pechacek if ((priv->line_status ^ prev_line_status) & UART_DCD) 736d14fc1a74e846d7851f24fc9519fe87dc12a1231Libor Pechacek usb_serial_handle_dcd_change(port, tty, 737d14fc1a74e846d7851f24fc9519fe87dc12a1231Libor Pechacek priv->line_status & UART_DCD); 738d14fc1a74e846d7851f24fc9519fe87dc12a1231Libor Pechacek tty_kref_put(tty); 73997bb13ec5bc156352cca8af90080597e04299a73Flavio Leitner} 7401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7417d12e780e003f93433d49ce78cfedf4b4c52adc5David Howellsstatic void pl2303_read_int_callback(struct urb *urb) 7421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 743cdc97792289179974af6dda781c855696358d307Ming Lei struct usb_serial_port *port = urb->context; 7441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned char *data = urb->transfer_buffer; 74597bb13ec5bc156352cca8af90080597e04299a73Flavio Leitner unsigned int actual_length = urb->actual_length; 746461d696aeeae294ad22dfcaae462d1757f955778Greg Kroah-Hartman int status = urb->status; 747461d696aeeae294ad22dfcaae462d1757f955778Greg Kroah-Hartman int retval; 7481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 749461d696aeeae294ad22dfcaae462d1757f955778Greg Kroah-Hartman switch (status) { 7501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case 0: 7511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* success */ 7521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 7531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case -ECONNRESET: 7541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case -ENOENT: 7551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case -ESHUTDOWN: 7561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* this urb is terminated, clean up */ 757d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman dev_dbg(&port->dev, "%s - urb shutting down with status: %d\n", 758d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman __func__, status); 7591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return; 7601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds default: 761d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman dev_dbg(&port->dev, "%s - nonzero urb status received: %d\n", 762d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman __func__, status); 7631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto exit; 7641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 7651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 76659d33f2fc2d63796296b1b76143e039d6e7cf532Greg Kroah-Hartman usb_serial_debug_data(&port->dev, __func__, 767372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi urb->actual_length, urb->transfer_buffer); 768372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi 76997bb13ec5bc156352cca8af90080597e04299a73Flavio Leitner pl2303_update_line_status(port, data, actual_length); 7701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsexit: 772461d696aeeae294ad22dfcaae462d1757f955778Greg Kroah-Hartman retval = usb_submit_urb(urb, GFP_ATOMIC); 773461d696aeeae294ad22dfcaae462d1757f955778Greg Kroah-Hartman if (retval) 774d8789b2b90aeb53ce59ac232d2ff0d8357d53893Greg Kroah-Hartman dev_err(&port->dev, 775372db8a780f63368c6960a167b7a19aad776d704Thiago Galesi "%s - usb_submit_urb failed with result %d\n", 776441b62c1edb986827154768d89bbac0ba779984fHarvey Harrison __func__, retval); 7771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 7781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 779f08e07ac8b87b1a4b8ff88a061195e99282dfbbdJohan Hovoldstatic void pl2303_process_read_urb(struct urb *urb) 780d4fc4a7bfc2dee626f4fec1e209e58eaa4312de6Alan Cox{ 781f08e07ac8b87b1a4b8ff88a061195e99282dfbbdJohan Hovold struct usb_serial_port *port = urb->context; 782f08e07ac8b87b1a4b8ff88a061195e99282dfbbdJohan Hovold struct pl2303_private *priv = usb_get_serial_port_data(port); 783d4fc4a7bfc2dee626f4fec1e209e58eaa4312de6Alan Cox unsigned char *data = urb->transfer_buffer; 784d4fc4a7bfc2dee626f4fec1e209e58eaa4312de6Alan Cox char tty_flag = TTY_NORMAL; 785f08e07ac8b87b1a4b8ff88a061195e99282dfbbdJohan Hovold unsigned long flags; 786f08e07ac8b87b1a4b8ff88a061195e99282dfbbdJohan Hovold u8 line_status; 787f08e07ac8b87b1a4b8ff88a061195e99282dfbbdJohan Hovold int i; 788f08e07ac8b87b1a4b8ff88a061195e99282dfbbdJohan Hovold 789f08e07ac8b87b1a4b8ff88a061195e99282dfbbdJohan Hovold /* update line status */ 790f08e07ac8b87b1a4b8ff88a061195e99282dfbbdJohan Hovold spin_lock_irqsave(&priv->lock, flags); 791f08e07ac8b87b1a4b8ff88a061195e99282dfbbdJohan Hovold line_status = priv->line_status; 792f08e07ac8b87b1a4b8ff88a061195e99282dfbbdJohan Hovold priv->line_status &= ~UART_STATE_TRANSIENT_MASK; 793f08e07ac8b87b1a4b8ff88a061195e99282dfbbdJohan Hovold spin_unlock_irqrestore(&priv->lock, flags); 7946d0cad657a133818038683120fff9c5c5f8dc751Johan Hovold wake_up_interruptible(&port->port.delta_msr_wait); 795f08e07ac8b87b1a4b8ff88a061195e99282dfbbdJohan Hovold 796f08e07ac8b87b1a4b8ff88a061195e99282dfbbdJohan Hovold if (!urb->actual_length) 797f08e07ac8b87b1a4b8ff88a061195e99282dfbbdJohan Hovold return; 798f08e07ac8b87b1a4b8ff88a061195e99282dfbbdJohan Hovold 799d4fc4a7bfc2dee626f4fec1e209e58eaa4312de6Alan Cox /* break takes precedence over parity, */ 800d4fc4a7bfc2dee626f4fec1e209e58eaa4312de6Alan Cox /* which takes precedence over framing errors */ 801d4fc4a7bfc2dee626f4fec1e209e58eaa4312de6Alan Cox if (line_status & UART_BREAK_ERROR) 802d4fc4a7bfc2dee626f4fec1e209e58eaa4312de6Alan Cox tty_flag = TTY_BREAK; 803d4fc4a7bfc2dee626f4fec1e209e58eaa4312de6Alan Cox else if (line_status & UART_PARITY_ERROR) 804d4fc4a7bfc2dee626f4fec1e209e58eaa4312de6Alan Cox tty_flag = TTY_PARITY; 805d4fc4a7bfc2dee626f4fec1e209e58eaa4312de6Alan Cox else if (line_status & UART_FRAME_ERROR) 806d4fc4a7bfc2dee626f4fec1e209e58eaa4312de6Alan Cox tty_flag = TTY_FRAME; 807d4fc4a7bfc2dee626f4fec1e209e58eaa4312de6Alan Cox 8083ba19fe31b726371b45f91a8de9341f5625e75e4Johan Hovold if (tty_flag != TTY_NORMAL) 8093ba19fe31b726371b45f91a8de9341f5625e75e4Johan Hovold dev_dbg(&port->dev, "%s - tty_flag = %d\n", __func__, 8103ba19fe31b726371b45f91a8de9341f5625e75e4Johan Hovold tty_flag); 811d4fc4a7bfc2dee626f4fec1e209e58eaa4312de6Alan Cox /* overrun is special, not associated with a char */ 812d4fc4a7bfc2dee626f4fec1e209e58eaa4312de6Alan Cox if (line_status & UART_OVERRUN_ERROR) 81392a19f9cec9a80ad93c06e115822deb729e2c6adJiri Slaby tty_insert_flip_char(&port->port, 0, TTY_OVERRUN); 8149388e2e71a51fab0aa2309bbb45e8a23d89a95a9Johan Hovold 815d45cc8df7f59eb4db28408076ce979cd5e18f2b7Johan Hovold if (port->port.console && port->sysrq) { 816d4fc4a7bfc2dee626f4fec1e209e58eaa4312de6Alan Cox for (i = 0; i < urb->actual_length; ++i) 8176ee9f4b4affe751d313d2538999aeec134d413a6Dmitry Torokhov if (!usb_serial_handle_sysrq_char(port, data[i])) 81892a19f9cec9a80ad93c06e115822deb729e2c6adJiri Slaby tty_insert_flip_char(&port->port, data[i], 81992a19f9cec9a80ad93c06e115822deb729e2c6adJiri Slaby tty_flag); 820d45cc8df7f59eb4db28408076ce979cd5e18f2b7Johan Hovold } else { 8212f69335710884ae6112fc8196ebe29b5cda7b79bJiri Slaby tty_insert_flip_string_fixed_flag(&port->port, data, tty_flag, 822d45cc8df7f59eb4db28408076ce979cd5e18f2b7Johan Hovold urb->actual_length); 8239388e2e71a51fab0aa2309bbb45e8a23d89a95a9Johan Hovold } 8241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8252e124b4a390ca85325fae75764bef92f0547fa25Jiri Slaby tty_flip_buffer_push(&port->port); 8261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 8271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 828572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi/* All of the device info needed for the PL2303 SIO serial converter */ 829572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesistatic struct usb_serial_driver pl2303_device = { 830572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi .driver = { 831572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi .owner = THIS_MODULE, 832572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi .name = "pl2303", 833572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi }, 834572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi .id_table = id_table, 835572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi .num_ports = 1, 8367919c2fd9e07276403b9a4d9ae52305e0d70f923Johan Hovold .bulk_in_size = 256, 8373efeaff6298290b36499532f0b4c87aa4bae8aefJohan Hovold .bulk_out_size = 256, 838572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi .open = pl2303_open, 839572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi .close = pl2303_close, 840335f8514f200e63d689113d29cb7253a5c282967Alan Cox .dtr_rts = pl2303_dtr_rts, 841335f8514f200e63d689113d29cb7253a5c282967Alan Cox .carrier_raised = pl2303_carrier_raised, 842572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi .ioctl = pl2303_ioctl, 843572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi .break_ctl = pl2303_break_ctl, 844572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi .set_termios = pl2303_set_termios, 845572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi .tiocmget = pl2303_tiocmget, 846572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi .tiocmset = pl2303_tiocmset, 847824d11bef5540062d17380c65ee52d4b2948ca84Johan Hovold .tiocmiwait = pl2303_tiocmiwait, 848f08e07ac8b87b1a4b8ff88a061195e99282dfbbdJohan Hovold .process_read_urb = pl2303_process_read_urb, 849572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi .read_int_callback = pl2303_read_int_callback, 850572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi .attach = pl2303_startup, 851f9c99bb8b3a1ec81af68d484a551307326c2e933Alan Stern .release = pl2303_release, 8528bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold .port_probe = pl2303_port_probe, 8538bf769eb5f6efc33f95088850f33fcc05d28b508Johan Hovold .port_remove = pl2303_port_remove, 854572d3138eb0cf17a2bf36944cc1d2c753578862eThiago Galesi}; 8551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 856f667ddad41e303ebc2c6d5bf3105dffe2fbdd717Alan Sternstatic struct usb_serial_driver * const serial_drivers[] = { 857f667ddad41e303ebc2c6d5bf3105dffe2fbdd717Alan Stern &pl2303_device, NULL 858f667ddad41e303ebc2c6d5bf3105dffe2fbdd717Alan Stern}; 859f667ddad41e303ebc2c6d5bf3105dffe2fbdd717Alan Stern 86068e24113457e437b1576670f2419b77ed0531e9eGreg Kroah-Hartmanmodule_usb_serial_driver(serial_drivers, id_table); 8611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_DESCRIPTION(DRIVER_DESC); 8631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_LICENSE("GPL"); 864