cypress_m8.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * USB Cypress M8 driver
  4. *
  5. * Copyright (C) 2004
  6. * Lonnie Mendez (dignome@gmail.com)
  7. * Copyright (C) 2003,2004
  8. * Neil Whelchel (koyama@firstlight.net)
  9. *
  10. * See Documentation/usb/usb-serial.rst for more information on using this
  11. * driver
  12. *
  13. * See http://geocities.com/i0xox0i for information on this driver and the
  14. * earthmate usb device.
  15. */
  16. /* Thanks to Neil Whelchel for writing the first cypress m8 implementation
  17. for linux. */
  18. /* Thanks to cypress for providing references for the hid reports. */
  19. /* Thanks to Jiang Zhang for providing links and for general help. */
  20. /* Code originates and was built up from ftdi_sio, belkin, pl2303 and others.*/
  21. #include <linux/kernel.h>
  22. #include <linux/errno.h>
  23. #include <linux/slab.h>
  24. #include <linux/tty.h>
  25. #include <linux/tty_driver.h>
  26. #include <linux/tty_flip.h>
  27. #include <linux/module.h>
  28. #include <linux/moduleparam.h>
  29. #include <linux/spinlock.h>
  30. #include <linux/usb.h>
  31. #include <linux/usb/serial.h>
  32. #include <linux/serial.h>
  33. #include <linux/kfifo.h>
  34. #include <linux/delay.h>
  35. #include <linux/uaccess.h>
  36. #include <linux/unaligned.h>
  37. #include "cypress_m8.h"
  38. static bool stats;
  39. static int interval;
  40. static bool unstable_bauds;
  41. #define DRIVER_AUTHOR "Lonnie Mendez <dignome@gmail.com>, Neil Whelchel <koyama@firstlight.net>"
  42. #define DRIVER_DESC "Cypress USB to Serial Driver"
  43. /* write buffer size defines */
  44. #define CYPRESS_BUF_SIZE 1024
  45. static const struct usb_device_id id_table_earthmate[] = {
  46. { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB) },
  47. { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB_LT20) },
  48. { } /* Terminating entry */
  49. };
  50. static const struct usb_device_id id_table_cyphidcomrs232[] = {
  51. { USB_DEVICE(VENDOR_ID_CYPRESS, PRODUCT_ID_CYPHIDCOM) },
  52. { USB_DEVICE(VENDOR_ID_SAI, PRODUCT_ID_CYPHIDCOM) },
  53. { USB_DEVICE(VENDOR_ID_POWERCOM, PRODUCT_ID_UPS) },
  54. { USB_DEVICE(VENDOR_ID_FRWD, PRODUCT_ID_CYPHIDCOM_FRWD) },
  55. { } /* Terminating entry */
  56. };
  57. static const struct usb_device_id id_table_nokiaca42v2[] = {
  58. { USB_DEVICE(VENDOR_ID_DAZZLE, PRODUCT_ID_CA42) },
  59. { } /* Terminating entry */
  60. };
  61. static const struct usb_device_id id_table_combined[] = {
  62. { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB) },
  63. { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB_LT20) },
  64. { USB_DEVICE(VENDOR_ID_CYPRESS, PRODUCT_ID_CYPHIDCOM) },
  65. { USB_DEVICE(VENDOR_ID_SAI, PRODUCT_ID_CYPHIDCOM) },
  66. { USB_DEVICE(VENDOR_ID_POWERCOM, PRODUCT_ID_UPS) },
  67. { USB_DEVICE(VENDOR_ID_FRWD, PRODUCT_ID_CYPHIDCOM_FRWD) },
  68. { USB_DEVICE(VENDOR_ID_DAZZLE, PRODUCT_ID_CA42) },
  69. { } /* Terminating entry */
  70. };
  71. MODULE_DEVICE_TABLE(usb, id_table_combined);
  72. enum packet_format {
  73. packet_format_1, /* b0:status, b1:payload count */
  74. packet_format_2 /* b0[7:3]:status, b0[2:0]:payload count */
  75. };
  76. struct cypress_private {
  77. spinlock_t lock; /* private lock */
  78. int chiptype; /* identifier of device, for quirks/etc */
  79. int bytes_in; /* used for statistics */
  80. int bytes_out; /* used for statistics */
  81. int cmd_count; /* used for statistics */
  82. int cmd_ctrl; /* always set this to 1 before issuing a command */
  83. struct kfifo write_fifo; /* write fifo */
  84. int write_urb_in_use; /* write urb in use indicator */
  85. int write_urb_interval; /* interval to use for write urb */
  86. int read_urb_interval; /* interval to use for read urb */
  87. int comm_is_ok; /* true if communication is (still) ok */
  88. __u8 line_control; /* holds dtr / rts value */
  89. __u8 current_status; /* received from last read - info on dsr,cts,cd,ri,etc */
  90. __u8 current_config; /* stores the current configuration byte */
  91. __u8 rx_flags; /* throttling - used from whiteheat/ftdi_sio */
  92. enum packet_format pkt_fmt; /* format to use for packet send / receive */
  93. int get_cfg_unsafe; /* If true, the CYPRESS_GET_CONFIG is unsafe */
  94. int baud_rate; /* stores current baud rate in
  95. integer form */
  96. char prev_status; /* used for TIOCMIWAIT */
  97. };
  98. /* function prototypes for the Cypress USB to serial device */
  99. static int cypress_earthmate_port_probe(struct usb_serial_port *port);
  100. static int cypress_hidcom_port_probe(struct usb_serial_port *port);
  101. static int cypress_ca42v2_port_probe(struct usb_serial_port *port);
  102. static void cypress_port_remove(struct usb_serial_port *port);
  103. static int cypress_open(struct tty_struct *tty, struct usb_serial_port *port);
  104. static void cypress_close(struct usb_serial_port *port);
  105. static void cypress_dtr_rts(struct usb_serial_port *port, int on);
  106. static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port,
  107. const unsigned char *buf, int count);
  108. static void cypress_send(struct usb_serial_port *port);
  109. static unsigned int cypress_write_room(struct tty_struct *tty);
  110. static void cypress_earthmate_init_termios(struct tty_struct *tty);
  111. static void cypress_set_termios(struct tty_struct *tty,
  112. struct usb_serial_port *port,
  113. const struct ktermios *old_termios);
  114. static int cypress_tiocmget(struct tty_struct *tty);
  115. static int cypress_tiocmset(struct tty_struct *tty,
  116. unsigned int set, unsigned int clear);
  117. static unsigned int cypress_chars_in_buffer(struct tty_struct *tty);
  118. static void cypress_throttle(struct tty_struct *tty);
  119. static void cypress_unthrottle(struct tty_struct *tty);
  120. static void cypress_set_dead(struct usb_serial_port *port);
  121. static void cypress_read_int_callback(struct urb *urb);
  122. static void cypress_write_int_callback(struct urb *urb);
  123. static struct usb_serial_driver cypress_earthmate_device = {
  124. .driver = {
  125. .name = "earthmate",
  126. },
  127. .description = "DeLorme Earthmate USB",
  128. .id_table = id_table_earthmate,
  129. .num_ports = 1,
  130. .port_probe = cypress_earthmate_port_probe,
  131. .port_remove = cypress_port_remove,
  132. .open = cypress_open,
  133. .close = cypress_close,
  134. .dtr_rts = cypress_dtr_rts,
  135. .write = cypress_write,
  136. .write_room = cypress_write_room,
  137. .init_termios = cypress_earthmate_init_termios,
  138. .set_termios = cypress_set_termios,
  139. .tiocmget = cypress_tiocmget,
  140. .tiocmset = cypress_tiocmset,
  141. .tiocmiwait = usb_serial_generic_tiocmiwait,
  142. .chars_in_buffer = cypress_chars_in_buffer,
  143. .throttle = cypress_throttle,
  144. .unthrottle = cypress_unthrottle,
  145. .read_int_callback = cypress_read_int_callback,
  146. .write_int_callback = cypress_write_int_callback,
  147. };
  148. static struct usb_serial_driver cypress_hidcom_device = {
  149. .driver = {
  150. .name = "cyphidcom",
  151. },
  152. .description = "HID->COM RS232 Adapter",
  153. .id_table = id_table_cyphidcomrs232,
  154. .num_ports = 1,
  155. .port_probe = cypress_hidcom_port_probe,
  156. .port_remove = cypress_port_remove,
  157. .open = cypress_open,
  158. .close = cypress_close,
  159. .dtr_rts = cypress_dtr_rts,
  160. .write = cypress_write,
  161. .write_room = cypress_write_room,
  162. .set_termios = cypress_set_termios,
  163. .tiocmget = cypress_tiocmget,
  164. .tiocmset = cypress_tiocmset,
  165. .tiocmiwait = usb_serial_generic_tiocmiwait,
  166. .chars_in_buffer = cypress_chars_in_buffer,
  167. .throttle = cypress_throttle,
  168. .unthrottle = cypress_unthrottle,
  169. .read_int_callback = cypress_read_int_callback,
  170. .write_int_callback = cypress_write_int_callback,
  171. };
  172. static struct usb_serial_driver cypress_ca42v2_device = {
  173. .driver = {
  174. .name = "nokiaca42v2",
  175. },
  176. .description = "Nokia CA-42 V2 Adapter",
  177. .id_table = id_table_nokiaca42v2,
  178. .num_ports = 1,
  179. .port_probe = cypress_ca42v2_port_probe,
  180. .port_remove = cypress_port_remove,
  181. .open = cypress_open,
  182. .close = cypress_close,
  183. .dtr_rts = cypress_dtr_rts,
  184. .write = cypress_write,
  185. .write_room = cypress_write_room,
  186. .set_termios = cypress_set_termios,
  187. .tiocmget = cypress_tiocmget,
  188. .tiocmset = cypress_tiocmset,
  189. .tiocmiwait = usb_serial_generic_tiocmiwait,
  190. .chars_in_buffer = cypress_chars_in_buffer,
  191. .throttle = cypress_throttle,
  192. .unthrottle = cypress_unthrottle,
  193. .read_int_callback = cypress_read_int_callback,
  194. .write_int_callback = cypress_write_int_callback,
  195. };
  196. static struct usb_serial_driver * const serial_drivers[] = {
  197. &cypress_earthmate_device, &cypress_hidcom_device,
  198. &cypress_ca42v2_device, NULL
  199. };
  200. /*****************************************************************************
  201. * Cypress serial helper functions
  202. *****************************************************************************/
  203. /* FRWD Dongle hidcom needs to skip reset and speed checks */
  204. static inline bool is_frwd(struct usb_device *dev)
  205. {
  206. return ((le16_to_cpu(dev->descriptor.idVendor) == VENDOR_ID_FRWD) &&
  207. (le16_to_cpu(dev->descriptor.idProduct) == PRODUCT_ID_CYPHIDCOM_FRWD));
  208. }
  209. static int analyze_baud_rate(struct usb_serial_port *port, speed_t new_rate)
  210. {
  211. struct cypress_private *priv;
  212. priv = usb_get_serial_port_data(port);
  213. if (unstable_bauds)
  214. return new_rate;
  215. /* FRWD Dongle uses 115200 bps */
  216. if (is_frwd(port->serial->dev))
  217. return new_rate;
  218. /*
  219. * The general purpose firmware for the Cypress M8 allows for
  220. * a maximum speed of 57600bps (I have no idea whether DeLorme
  221. * chose to use the general purpose firmware or not), if you
  222. * need to modify this speed setting for your own project
  223. * please add your own chiptype and modify the code likewise.
  224. * The Cypress HID->COM device will work successfully up to
  225. * 115200bps (but the actual throughput is around 3kBps).
  226. */
  227. if (port->serial->dev->speed == USB_SPEED_LOW) {
  228. /*
  229. * Mike Isely <isely@pobox.com> 2-Feb-2008: The
  230. * Cypress app note that describes this mechanism
  231. * states that the low-speed part can't handle more
  232. * than 800 bytes/sec, in which case 4800 baud is the
  233. * safest speed for a part like that.
  234. */
  235. if (new_rate > 4800) {
  236. dev_dbg(&port->dev,
  237. "%s - failed setting baud rate, device incapable speed %d\n",
  238. __func__, new_rate);
  239. return -1;
  240. }
  241. }
  242. switch (priv->chiptype) {
  243. case CT_EARTHMATE:
  244. if (new_rate <= 600) {
  245. /* 300 and 600 baud rates are supported under
  246. * the generic firmware, but are not used with
  247. * NMEA and SiRF protocols */
  248. dev_dbg(&port->dev,
  249. "%s - failed setting baud rate, unsupported speed of %d on Earthmate GPS\n",
  250. __func__, new_rate);
  251. return -1;
  252. }
  253. break;
  254. default:
  255. break;
  256. }
  257. return new_rate;
  258. }
  259. /* This function can either set or retrieve the current serial line settings */
  260. static int cypress_serial_control(struct tty_struct *tty,
  261. struct usb_serial_port *port, speed_t baud_rate, int data_bits,
  262. int stop_bits, int parity_enable, int parity_type, int reset,
  263. int cypress_request_type)
  264. {
  265. int new_baudrate = 0, retval = 0, tries = 0;
  266. struct cypress_private *priv;
  267. struct device *dev = &port->dev;
  268. u8 *feature_buffer;
  269. const unsigned int feature_len = 5;
  270. unsigned long flags;
  271. priv = usb_get_serial_port_data(port);
  272. if (!priv->comm_is_ok)
  273. return -ENODEV;
  274. feature_buffer = kcalloc(feature_len, sizeof(u8), GFP_KERNEL);
  275. if (!feature_buffer)
  276. return -ENOMEM;
  277. switch (cypress_request_type) {
  278. case CYPRESS_SET_CONFIG:
  279. /* 0 means 'Hang up' so doesn't change the true bit rate */
  280. new_baudrate = priv->baud_rate;
  281. if (baud_rate && baud_rate != priv->baud_rate) {
  282. dev_dbg(dev, "%s - baud rate is changing\n", __func__);
  283. retval = analyze_baud_rate(port, baud_rate);
  284. if (retval >= 0) {
  285. new_baudrate = retval;
  286. dev_dbg(dev, "%s - New baud rate set to %d\n",
  287. __func__, new_baudrate);
  288. }
  289. }
  290. dev_dbg(dev, "%s - baud rate is being sent as %d\n", __func__,
  291. new_baudrate);
  292. /* fill the feature_buffer with new configuration */
  293. put_unaligned_le32(new_baudrate, feature_buffer);
  294. feature_buffer[4] |= data_bits - 5; /* assign data bits in 2 bit space ( max 3 ) */
  295. /* 1 bit gap */
  296. feature_buffer[4] |= (stop_bits << 3); /* assign stop bits in 1 bit space */
  297. feature_buffer[4] |= (parity_enable << 4); /* assign parity flag in 1 bit space */
  298. feature_buffer[4] |= (parity_type << 5); /* assign parity type in 1 bit space */
  299. /* 1 bit gap */
  300. feature_buffer[4] |= (reset << 7); /* assign reset at end of byte, 1 bit space */
  301. dev_dbg(dev, "%s - device is being sent this feature report:\n", __func__);
  302. dev_dbg(dev, "%s - %02X - %02X - %02X - %02X - %02X\n", __func__,
  303. feature_buffer[0], feature_buffer[1],
  304. feature_buffer[2], feature_buffer[3],
  305. feature_buffer[4]);
  306. do {
  307. retval = usb_control_msg(port->serial->dev,
  308. usb_sndctrlpipe(port->serial->dev, 0),
  309. HID_REQ_SET_REPORT,
  310. USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
  311. 0x0300, 0, feature_buffer,
  312. feature_len, 500);
  313. if (tries++ >= 3)
  314. break;
  315. } while (retval != feature_len &&
  316. retval != -ENODEV);
  317. if (retval != feature_len) {
  318. dev_err(dev, "%s - failed sending serial line settings - %d\n",
  319. __func__, retval);
  320. cypress_set_dead(port);
  321. } else {
  322. spin_lock_irqsave(&priv->lock, flags);
  323. priv->baud_rate = new_baudrate;
  324. priv->current_config = feature_buffer[4];
  325. spin_unlock_irqrestore(&priv->lock, flags);
  326. /* If we asked for a speed change encode it */
  327. if (baud_rate)
  328. tty_encode_baud_rate(tty,
  329. new_baudrate, new_baudrate);
  330. }
  331. break;
  332. case CYPRESS_GET_CONFIG:
  333. if (priv->get_cfg_unsafe) {
  334. /* Not implemented for this device,
  335. and if we try to do it we're likely
  336. to crash the hardware. */
  337. retval = -ENOTTY;
  338. goto out;
  339. }
  340. dev_dbg(dev, "%s - retrieving serial line settings\n", __func__);
  341. do {
  342. retval = usb_control_msg(port->serial->dev,
  343. usb_rcvctrlpipe(port->serial->dev, 0),
  344. HID_REQ_GET_REPORT,
  345. USB_DIR_IN | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
  346. 0x0300, 0, feature_buffer,
  347. feature_len, 500);
  348. if (tries++ >= 3)
  349. break;
  350. } while (retval != feature_len
  351. && retval != -ENODEV);
  352. if (retval != feature_len) {
  353. dev_err(dev, "%s - failed to retrieve serial line settings - %d\n",
  354. __func__, retval);
  355. cypress_set_dead(port);
  356. goto out;
  357. } else {
  358. spin_lock_irqsave(&priv->lock, flags);
  359. /* store the config in one byte, and later
  360. use bit masks to check values */
  361. priv->current_config = feature_buffer[4];
  362. priv->baud_rate = get_unaligned_le32(feature_buffer);
  363. spin_unlock_irqrestore(&priv->lock, flags);
  364. }
  365. }
  366. spin_lock_irqsave(&priv->lock, flags);
  367. ++priv->cmd_count;
  368. spin_unlock_irqrestore(&priv->lock, flags);
  369. out:
  370. kfree(feature_buffer);
  371. return retval;
  372. } /* cypress_serial_control */
  373. static void cypress_set_dead(struct usb_serial_port *port)
  374. {
  375. struct cypress_private *priv = usb_get_serial_port_data(port);
  376. unsigned long flags;
  377. spin_lock_irqsave(&priv->lock, flags);
  378. if (!priv->comm_is_ok) {
  379. spin_unlock_irqrestore(&priv->lock, flags);
  380. return;
  381. }
  382. priv->comm_is_ok = 0;
  383. spin_unlock_irqrestore(&priv->lock, flags);
  384. dev_err(&port->dev, "cypress_m8 suspending failing port %d - "
  385. "interval might be too short\n", port->port_number);
  386. }
  387. /*****************************************************************************
  388. * Cypress serial driver functions
  389. *****************************************************************************/
  390. static int cypress_generic_port_probe(struct usb_serial_port *port)
  391. {
  392. struct usb_serial *serial = port->serial;
  393. struct cypress_private *priv;
  394. if (!port->interrupt_out_urb || !port->interrupt_in_urb) {
  395. dev_err(&port->dev, "required endpoint is missing\n");
  396. return -ENODEV;
  397. }
  398. priv = kzalloc(sizeof(struct cypress_private), GFP_KERNEL);
  399. if (!priv)
  400. return -ENOMEM;
  401. priv->comm_is_ok = !0;
  402. spin_lock_init(&priv->lock);
  403. if (kfifo_alloc(&priv->write_fifo, CYPRESS_BUF_SIZE, GFP_KERNEL)) {
  404. kfree(priv);
  405. return -ENOMEM;
  406. }
  407. /* Skip reset for FRWD device. It is a workaound:
  408. device hangs if it receives SET_CONFIGURE in Configured
  409. state. */
  410. if (!is_frwd(serial->dev))
  411. usb_reset_configuration(serial->dev);
  412. priv->cmd_ctrl = 0;
  413. priv->line_control = 0;
  414. priv->rx_flags = 0;
  415. /* Default packet format setting is determined by packet size.
  416. Anything with a size larger then 9 must have a separate
  417. count field since the 3 bit count field is otherwise too
  418. small. Otherwise we can use the slightly more compact
  419. format. This is in accordance with the cypress_m8 serial
  420. converter app note. */
  421. if (port->interrupt_out_size > 9)
  422. priv->pkt_fmt = packet_format_1;
  423. else
  424. priv->pkt_fmt = packet_format_2;
  425. if (interval > 0) {
  426. priv->write_urb_interval = interval;
  427. priv->read_urb_interval = interval;
  428. dev_dbg(&port->dev, "%s - read & write intervals forced to %d\n",
  429. __func__, interval);
  430. } else {
  431. priv->write_urb_interval = port->interrupt_out_urb->interval;
  432. priv->read_urb_interval = port->interrupt_in_urb->interval;
  433. dev_dbg(&port->dev, "%s - intervals: read=%d write=%d\n",
  434. __func__, priv->read_urb_interval,
  435. priv->write_urb_interval);
  436. }
  437. usb_set_serial_port_data(port, priv);
  438. port->port.drain_delay = 256;
  439. return 0;
  440. }
  441. static int cypress_earthmate_port_probe(struct usb_serial_port *port)
  442. {
  443. struct usb_serial *serial = port->serial;
  444. struct cypress_private *priv;
  445. int ret;
  446. ret = cypress_generic_port_probe(port);
  447. if (ret) {
  448. dev_dbg(&port->dev, "%s - Failed setting up port\n", __func__);
  449. return ret;
  450. }
  451. priv = usb_get_serial_port_data(port);
  452. priv->chiptype = CT_EARTHMATE;
  453. /* All Earthmate devices use the separated-count packet
  454. format! Idiotic. */
  455. priv->pkt_fmt = packet_format_1;
  456. if (serial->dev->descriptor.idProduct !=
  457. cpu_to_le16(PRODUCT_ID_EARTHMATEUSB)) {
  458. /* The old original USB Earthmate seemed able to
  459. handle GET_CONFIG requests; everything they've
  460. produced since that time crashes if this command is
  461. attempted :-( */
  462. dev_dbg(&port->dev,
  463. "%s - Marking this device as unsafe for GET_CONFIG commands\n",
  464. __func__);
  465. priv->get_cfg_unsafe = !0;
  466. }
  467. return 0;
  468. }
  469. static int cypress_hidcom_port_probe(struct usb_serial_port *port)
  470. {
  471. struct cypress_private *priv;
  472. int ret;
  473. ret = cypress_generic_port_probe(port);
  474. if (ret) {
  475. dev_dbg(&port->dev, "%s - Failed setting up port\n", __func__);
  476. return ret;
  477. }
  478. priv = usb_get_serial_port_data(port);
  479. priv->chiptype = CT_CYPHIDCOM;
  480. return 0;
  481. }
  482. static int cypress_ca42v2_port_probe(struct usb_serial_port *port)
  483. {
  484. struct cypress_private *priv;
  485. int ret;
  486. ret = cypress_generic_port_probe(port);
  487. if (ret) {
  488. dev_dbg(&port->dev, "%s - Failed setting up port\n", __func__);
  489. return ret;
  490. }
  491. priv = usb_get_serial_port_data(port);
  492. priv->chiptype = CT_CA42V2;
  493. return 0;
  494. }
  495. static void cypress_port_remove(struct usb_serial_port *port)
  496. {
  497. struct cypress_private *priv;
  498. priv = usb_get_serial_port_data(port);
  499. kfifo_free(&priv->write_fifo);
  500. kfree(priv);
  501. }
  502. static int cypress_open(struct tty_struct *tty, struct usb_serial_port *port)
  503. {
  504. struct cypress_private *priv = usb_get_serial_port_data(port);
  505. struct usb_serial *serial = port->serial;
  506. unsigned long flags;
  507. int result = 0;
  508. if (!priv->comm_is_ok)
  509. return -EIO;
  510. /* clear halts before open */
  511. usb_clear_halt(serial->dev, 0x81);
  512. usb_clear_halt(serial->dev, 0x02);
  513. spin_lock_irqsave(&priv->lock, flags);
  514. /* reset read/write statistics */
  515. priv->bytes_in = 0;
  516. priv->bytes_out = 0;
  517. priv->cmd_count = 0;
  518. priv->rx_flags = 0;
  519. spin_unlock_irqrestore(&priv->lock, flags);
  520. /* Set termios */
  521. cypress_send(port);
  522. if (tty)
  523. cypress_set_termios(tty, port, NULL);
  524. /* setup the port and start reading from the device */
  525. usb_fill_int_urb(port->interrupt_in_urb, serial->dev,
  526. usb_rcvintpipe(serial->dev, port->interrupt_in_endpointAddress),
  527. port->interrupt_in_urb->transfer_buffer,
  528. port->interrupt_in_urb->transfer_buffer_length,
  529. cypress_read_int_callback, port, priv->read_urb_interval);
  530. result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  531. if (result) {
  532. dev_err(&port->dev,
  533. "%s - failed submitting read urb, error %d\n",
  534. __func__, result);
  535. cypress_set_dead(port);
  536. }
  537. return result;
  538. } /* cypress_open */
  539. static void cypress_dtr_rts(struct usb_serial_port *port, int on)
  540. {
  541. struct cypress_private *priv = usb_get_serial_port_data(port);
  542. /* drop dtr and rts */
  543. spin_lock_irq(&priv->lock);
  544. if (on == 0)
  545. priv->line_control = 0;
  546. else
  547. priv->line_control = CONTROL_DTR | CONTROL_RTS;
  548. priv->cmd_ctrl = 1;
  549. spin_unlock_irq(&priv->lock);
  550. cypress_write(NULL, port, NULL, 0);
  551. }
  552. static void cypress_close(struct usb_serial_port *port)
  553. {
  554. struct cypress_private *priv = usb_get_serial_port_data(port);
  555. unsigned long flags;
  556. spin_lock_irqsave(&priv->lock, flags);
  557. kfifo_reset_out(&priv->write_fifo);
  558. spin_unlock_irqrestore(&priv->lock, flags);
  559. dev_dbg(&port->dev, "%s - stopping urbs\n", __func__);
  560. usb_kill_urb(port->interrupt_in_urb);
  561. usb_kill_urb(port->interrupt_out_urb);
  562. if (stats)
  563. dev_info(&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n",
  564. priv->bytes_in, priv->bytes_out, priv->cmd_count);
  565. } /* cypress_close */
  566. static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port,
  567. const unsigned char *buf, int count)
  568. {
  569. struct cypress_private *priv = usb_get_serial_port_data(port);
  570. dev_dbg(&port->dev, "%s - %d bytes\n", __func__, count);
  571. /* line control commands, which need to be executed immediately,
  572. are not put into the buffer for obvious reasons.
  573. */
  574. if (priv->cmd_ctrl) {
  575. count = 0;
  576. goto finish;
  577. }
  578. if (!count)
  579. return count;
  580. count = kfifo_in_locked(&priv->write_fifo, buf, count, &priv->lock);
  581. finish:
  582. cypress_send(port);
  583. return count;
  584. } /* cypress_write */
  585. static void cypress_send(struct usb_serial_port *port)
  586. {
  587. int count = 0, result, offset, actual_size;
  588. struct cypress_private *priv = usb_get_serial_port_data(port);
  589. struct device *dev = &port->dev;
  590. unsigned long flags;
  591. if (!priv->comm_is_ok)
  592. return;
  593. dev_dbg(dev, "%s - interrupt out size is %d\n", __func__,
  594. port->interrupt_out_size);
  595. spin_lock_irqsave(&priv->lock, flags);
  596. if (priv->write_urb_in_use) {
  597. dev_dbg(dev, "%s - can't write, urb in use\n", __func__);
  598. spin_unlock_irqrestore(&priv->lock, flags);
  599. return;
  600. }
  601. spin_unlock_irqrestore(&priv->lock, flags);
  602. /* clear buffer */
  603. memset(port->interrupt_out_urb->transfer_buffer, 0,
  604. port->interrupt_out_size);
  605. spin_lock_irqsave(&priv->lock, flags);
  606. switch (priv->pkt_fmt) {
  607. default:
  608. case packet_format_1:
  609. /* this is for the CY7C64013... */
  610. offset = 2;
  611. port->interrupt_out_buffer[0] = priv->line_control;
  612. break;
  613. case packet_format_2:
  614. /* this is for the CY7C63743... */
  615. offset = 1;
  616. port->interrupt_out_buffer[0] = priv->line_control;
  617. break;
  618. }
  619. if (priv->line_control & CONTROL_RESET)
  620. priv->line_control &= ~CONTROL_RESET;
  621. if (priv->cmd_ctrl) {
  622. priv->cmd_count++;
  623. dev_dbg(dev, "%s - line control command being issued\n", __func__);
  624. spin_unlock_irqrestore(&priv->lock, flags);
  625. goto send;
  626. } else
  627. spin_unlock_irqrestore(&priv->lock, flags);
  628. count = kfifo_out_locked(&priv->write_fifo,
  629. &port->interrupt_out_buffer[offset],
  630. port->interrupt_out_size - offset,
  631. &priv->lock);
  632. if (count == 0)
  633. return;
  634. switch (priv->pkt_fmt) {
  635. default:
  636. case packet_format_1:
  637. port->interrupt_out_buffer[1] = count;
  638. break;
  639. case packet_format_2:
  640. port->interrupt_out_buffer[0] |= count;
  641. }
  642. dev_dbg(dev, "%s - count is %d\n", __func__, count);
  643. send:
  644. spin_lock_irqsave(&priv->lock, flags);
  645. priv->write_urb_in_use = 1;
  646. spin_unlock_irqrestore(&priv->lock, flags);
  647. if (priv->cmd_ctrl)
  648. actual_size = 1;
  649. else
  650. actual_size = count +
  651. (priv->pkt_fmt == packet_format_1 ? 2 : 1);
  652. usb_serial_debug_data(dev, __func__, port->interrupt_out_size,
  653. port->interrupt_out_urb->transfer_buffer);
  654. usb_fill_int_urb(port->interrupt_out_urb, port->serial->dev,
  655. usb_sndintpipe(port->serial->dev, port->interrupt_out_endpointAddress),
  656. port->interrupt_out_buffer, actual_size,
  657. cypress_write_int_callback, port, priv->write_urb_interval);
  658. result = usb_submit_urb(port->interrupt_out_urb, GFP_ATOMIC);
  659. if (result) {
  660. dev_err_console(port,
  661. "%s - failed submitting write urb, error %d\n",
  662. __func__, result);
  663. priv->write_urb_in_use = 0;
  664. cypress_set_dead(port);
  665. }
  666. spin_lock_irqsave(&priv->lock, flags);
  667. if (priv->cmd_ctrl)
  668. priv->cmd_ctrl = 0;
  669. /* do not count the line control and size bytes */
  670. priv->bytes_out += count;
  671. spin_unlock_irqrestore(&priv->lock, flags);
  672. usb_serial_port_softint(port);
  673. } /* cypress_send */
  674. /* returns how much space is available in the soft buffer */
  675. static unsigned int cypress_write_room(struct tty_struct *tty)
  676. {
  677. struct usb_serial_port *port = tty->driver_data;
  678. struct cypress_private *priv = usb_get_serial_port_data(port);
  679. unsigned int room;
  680. unsigned long flags;
  681. spin_lock_irqsave(&priv->lock, flags);
  682. room = kfifo_avail(&priv->write_fifo);
  683. spin_unlock_irqrestore(&priv->lock, flags);
  684. dev_dbg(&port->dev, "%s - returns %u\n", __func__, room);
  685. return room;
  686. }
  687. static int cypress_tiocmget(struct tty_struct *tty)
  688. {
  689. struct usb_serial_port *port = tty->driver_data;
  690. struct cypress_private *priv = usb_get_serial_port_data(port);
  691. __u8 status, control;
  692. unsigned int result = 0;
  693. unsigned long flags;
  694. spin_lock_irqsave(&priv->lock, flags);
  695. control = priv->line_control;
  696. status = priv->current_status;
  697. spin_unlock_irqrestore(&priv->lock, flags);
  698. result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0)
  699. | ((control & CONTROL_RTS) ? TIOCM_RTS : 0)
  700. | ((status & UART_CTS) ? TIOCM_CTS : 0)
  701. | ((status & UART_DSR) ? TIOCM_DSR : 0)
  702. | ((status & UART_RI) ? TIOCM_RI : 0)
  703. | ((status & UART_CD) ? TIOCM_CD : 0);
  704. dev_dbg(&port->dev, "%s - result = %x\n", __func__, result);
  705. return result;
  706. }
  707. static int cypress_tiocmset(struct tty_struct *tty,
  708. unsigned int set, unsigned int clear)
  709. {
  710. struct usb_serial_port *port = tty->driver_data;
  711. struct cypress_private *priv = usb_get_serial_port_data(port);
  712. unsigned long flags;
  713. spin_lock_irqsave(&priv->lock, flags);
  714. if (set & TIOCM_RTS)
  715. priv->line_control |= CONTROL_RTS;
  716. if (set & TIOCM_DTR)
  717. priv->line_control |= CONTROL_DTR;
  718. if (clear & TIOCM_RTS)
  719. priv->line_control &= ~CONTROL_RTS;
  720. if (clear & TIOCM_DTR)
  721. priv->line_control &= ~CONTROL_DTR;
  722. priv->cmd_ctrl = 1;
  723. spin_unlock_irqrestore(&priv->lock, flags);
  724. return cypress_write(tty, port, NULL, 0);
  725. }
  726. static void cypress_earthmate_init_termios(struct tty_struct *tty)
  727. {
  728. tty_encode_baud_rate(tty, 4800, 4800);
  729. }
  730. static void cypress_set_termios(struct tty_struct *tty,
  731. struct usb_serial_port *port,
  732. const struct ktermios *old_termios)
  733. {
  734. struct cypress_private *priv = usb_get_serial_port_data(port);
  735. struct device *dev = &port->dev;
  736. int data_bits, stop_bits, parity_type, parity_enable;
  737. unsigned int cflag;
  738. unsigned long flags;
  739. __u8 oldlines;
  740. int linechange = 0;
  741. /* Unsupported features need clearing */
  742. tty->termios.c_cflag &= ~(CMSPAR|CRTSCTS);
  743. cflag = tty->termios.c_cflag;
  744. /* set number of data bits, parity, stop bits */
  745. /* when parity is disabled the parity type bit is ignored */
  746. /* 1 means 2 stop bits, 0 means 1 stop bit */
  747. stop_bits = cflag & CSTOPB ? 1 : 0;
  748. if (cflag & PARENB) {
  749. parity_enable = 1;
  750. /* 1 means odd parity, 0 means even parity */
  751. parity_type = cflag & PARODD ? 1 : 0;
  752. } else
  753. parity_enable = parity_type = 0;
  754. data_bits = tty_get_char_size(cflag);
  755. spin_lock_irqsave(&priv->lock, flags);
  756. oldlines = priv->line_control;
  757. if ((cflag & CBAUD) == B0) {
  758. /* drop dtr and rts */
  759. dev_dbg(dev, "%s - dropping the lines, baud rate 0bps\n", __func__);
  760. priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS);
  761. } else
  762. priv->line_control = (CONTROL_DTR | CONTROL_RTS);
  763. spin_unlock_irqrestore(&priv->lock, flags);
  764. dev_dbg(dev, "%s - sending %d stop_bits, %d parity_enable, %d parity_type, %d data_bits (+5)\n",
  765. __func__, stop_bits, parity_enable, parity_type, data_bits);
  766. cypress_serial_control(tty, port, tty_get_baud_rate(tty),
  767. data_bits, stop_bits,
  768. parity_enable, parity_type,
  769. 0, CYPRESS_SET_CONFIG);
  770. /* we perform a CYPRESS_GET_CONFIG so that the current settings are
  771. * filled into the private structure this should confirm that all is
  772. * working if it returns what we just set */
  773. cypress_serial_control(tty, port, 0, 0, 0, 0, 0, 0, CYPRESS_GET_CONFIG);
  774. /* Here we can define custom tty settings for devices; the main tty
  775. * termios flag base comes from empeg.c */
  776. spin_lock_irqsave(&priv->lock, flags);
  777. if (priv->chiptype == CT_EARTHMATE && priv->baud_rate == 4800) {
  778. dev_dbg(dev, "Using custom termios settings for a baud rate of 4800bps.\n");
  779. /* define custom termios settings for NMEA protocol */
  780. tty->termios.c_iflag /* input modes - */
  781. &= ~(IGNBRK /* disable ignore break */
  782. | BRKINT /* disable break causes interrupt */
  783. | PARMRK /* disable mark parity errors */
  784. | ISTRIP /* disable clear high bit of input char */
  785. | INLCR /* disable translate NL to CR */
  786. | IGNCR /* disable ignore CR */
  787. | ICRNL /* disable translate CR to NL */
  788. | IXON); /* disable enable XON/XOFF flow control */
  789. tty->termios.c_oflag /* output modes */
  790. &= ~OPOST; /* disable postprocess output char */
  791. tty->termios.c_lflag /* line discipline modes */
  792. &= ~(ECHO /* disable echo input characters */
  793. | ECHONL /* disable echo new line */
  794. | ICANON /* disable erase, kill, werase, and rprnt
  795. special characters */
  796. | ISIG /* disable interrupt, quit, and suspend
  797. special characters */
  798. | IEXTEN); /* disable non-POSIX special characters */
  799. } /* CT_CYPHIDCOM: Application should handle this for device */
  800. linechange = (priv->line_control != oldlines);
  801. spin_unlock_irqrestore(&priv->lock, flags);
  802. /* if necessary, set lines */
  803. if (linechange) {
  804. priv->cmd_ctrl = 1;
  805. cypress_write(tty, port, NULL, 0);
  806. }
  807. } /* cypress_set_termios */
  808. /* returns amount of data still left in soft buffer */
  809. static unsigned int cypress_chars_in_buffer(struct tty_struct *tty)
  810. {
  811. struct usb_serial_port *port = tty->driver_data;
  812. struct cypress_private *priv = usb_get_serial_port_data(port);
  813. unsigned int chars;
  814. unsigned long flags;
  815. spin_lock_irqsave(&priv->lock, flags);
  816. chars = kfifo_len(&priv->write_fifo);
  817. spin_unlock_irqrestore(&priv->lock, flags);
  818. dev_dbg(&port->dev, "%s - returns %u\n", __func__, chars);
  819. return chars;
  820. }
  821. static void cypress_throttle(struct tty_struct *tty)
  822. {
  823. struct usb_serial_port *port = tty->driver_data;
  824. struct cypress_private *priv = usb_get_serial_port_data(port);
  825. spin_lock_irq(&priv->lock);
  826. priv->rx_flags = THROTTLED;
  827. spin_unlock_irq(&priv->lock);
  828. }
  829. static void cypress_unthrottle(struct tty_struct *tty)
  830. {
  831. struct usb_serial_port *port = tty->driver_data;
  832. struct cypress_private *priv = usb_get_serial_port_data(port);
  833. int actually_throttled, result;
  834. spin_lock_irq(&priv->lock);
  835. actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED;
  836. priv->rx_flags = 0;
  837. spin_unlock_irq(&priv->lock);
  838. if (!priv->comm_is_ok)
  839. return;
  840. if (actually_throttled) {
  841. result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  842. if (result) {
  843. dev_err(&port->dev, "%s - failed submitting read urb, "
  844. "error %d\n", __func__, result);
  845. cypress_set_dead(port);
  846. }
  847. }
  848. }
  849. static void cypress_read_int_callback(struct urb *urb)
  850. {
  851. struct usb_serial_port *port = urb->context;
  852. struct cypress_private *priv = usb_get_serial_port_data(port);
  853. struct device *dev = &urb->dev->dev;
  854. struct tty_struct *tty;
  855. unsigned char *data = urb->transfer_buffer;
  856. unsigned long flags;
  857. char tty_flag = TTY_NORMAL;
  858. int bytes = 0;
  859. int result;
  860. int i = 0;
  861. int status = urb->status;
  862. switch (status) {
  863. case 0: /* success */
  864. break;
  865. case -ECONNRESET:
  866. case -ENOENT:
  867. case -ESHUTDOWN:
  868. /* precursor to disconnect so just go away */
  869. return;
  870. case -EPIPE:
  871. /* Can't call usb_clear_halt while in_interrupt */
  872. fallthrough;
  873. default:
  874. /* something ugly is going on... */
  875. dev_err(dev, "%s - unexpected nonzero read status received: %d\n",
  876. __func__, status);
  877. cypress_set_dead(port);
  878. return;
  879. }
  880. spin_lock_irqsave(&priv->lock, flags);
  881. if (priv->rx_flags & THROTTLED) {
  882. dev_dbg(dev, "%s - now throttling\n", __func__);
  883. priv->rx_flags |= ACTUALLY_THROTTLED;
  884. spin_unlock_irqrestore(&priv->lock, flags);
  885. return;
  886. }
  887. spin_unlock_irqrestore(&priv->lock, flags);
  888. tty = tty_port_tty_get(&port->port);
  889. if (!tty) {
  890. dev_dbg(dev, "%s - bad tty pointer - exiting\n", __func__);
  891. return;
  892. }
  893. spin_lock_irqsave(&priv->lock, flags);
  894. result = urb->actual_length;
  895. switch (priv->pkt_fmt) {
  896. default:
  897. case packet_format_1:
  898. /* This is for the CY7C64013... */
  899. priv->current_status = data[0] & 0xF8;
  900. bytes = data[1] + 2;
  901. i = 2;
  902. break;
  903. case packet_format_2:
  904. /* This is for the CY7C63743... */
  905. priv->current_status = data[0] & 0xF8;
  906. bytes = (data[0] & 0x07) + 1;
  907. i = 1;
  908. break;
  909. }
  910. spin_unlock_irqrestore(&priv->lock, flags);
  911. if (result < bytes) {
  912. dev_dbg(dev,
  913. "%s - wrong packet size - received %d bytes but packet said %d bytes\n",
  914. __func__, result, bytes);
  915. goto continue_read;
  916. }
  917. usb_serial_debug_data(&port->dev, __func__, urb->actual_length, data);
  918. spin_lock_irqsave(&priv->lock, flags);
  919. /* check to see if status has changed */
  920. if (priv->current_status != priv->prev_status) {
  921. u8 delta = priv->current_status ^ priv->prev_status;
  922. if (delta & UART_MSR_MASK) {
  923. if (delta & UART_CTS)
  924. port->icount.cts++;
  925. if (delta & UART_DSR)
  926. port->icount.dsr++;
  927. if (delta & UART_RI)
  928. port->icount.rng++;
  929. if (delta & UART_CD)
  930. port->icount.dcd++;
  931. wake_up_interruptible(&port->port.delta_msr_wait);
  932. }
  933. priv->prev_status = priv->current_status;
  934. }
  935. spin_unlock_irqrestore(&priv->lock, flags);
  936. /* hangup, as defined in acm.c... this might be a bad place for it
  937. * though */
  938. if (tty && !C_CLOCAL(tty) && !(priv->current_status & UART_CD)) {
  939. dev_dbg(dev, "%s - calling hangup\n", __func__);
  940. tty_hangup(tty);
  941. goto continue_read;
  942. }
  943. /* There is one error bit... I'm assuming it is a parity error
  944. * indicator as the generic firmware will set this bit to 1 if a
  945. * parity error occurs.
  946. * I can not find reference to any other error events. */
  947. spin_lock_irqsave(&priv->lock, flags);
  948. if (priv->current_status & CYP_ERROR) {
  949. spin_unlock_irqrestore(&priv->lock, flags);
  950. tty_flag = TTY_PARITY;
  951. dev_dbg(dev, "%s - Parity Error detected\n", __func__);
  952. } else
  953. spin_unlock_irqrestore(&priv->lock, flags);
  954. /* process read if there is data other than line status */
  955. if (bytes > i) {
  956. tty_insert_flip_string_fixed_flag(&port->port, data + i,
  957. tty_flag, bytes - i);
  958. tty_flip_buffer_push(&port->port);
  959. }
  960. spin_lock_irqsave(&priv->lock, flags);
  961. /* control and status byte(s) are also counted */
  962. priv->bytes_in += bytes;
  963. spin_unlock_irqrestore(&priv->lock, flags);
  964. continue_read:
  965. tty_kref_put(tty);
  966. /* Continue trying to always read */
  967. if (priv->comm_is_ok) {
  968. usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev,
  969. usb_rcvintpipe(port->serial->dev,
  970. port->interrupt_in_endpointAddress),
  971. port->interrupt_in_urb->transfer_buffer,
  972. port->interrupt_in_urb->transfer_buffer_length,
  973. cypress_read_int_callback, port,
  974. priv->read_urb_interval);
  975. result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
  976. if (result && result != -EPERM) {
  977. dev_err(dev, "%s - failed resubmitting read urb, error %d\n",
  978. __func__, result);
  979. cypress_set_dead(port);
  980. }
  981. }
  982. } /* cypress_read_int_callback */
  983. static void cypress_write_int_callback(struct urb *urb)
  984. {
  985. struct usb_serial_port *port = urb->context;
  986. struct cypress_private *priv = usb_get_serial_port_data(port);
  987. struct device *dev = &urb->dev->dev;
  988. int status = urb->status;
  989. switch (status) {
  990. case 0:
  991. /* success */
  992. break;
  993. case -ECONNRESET:
  994. case -ENOENT:
  995. case -ESHUTDOWN:
  996. /* this urb is terminated, clean up */
  997. dev_dbg(dev, "%s - urb shutting down with status: %d\n",
  998. __func__, status);
  999. priv->write_urb_in_use = 0;
  1000. return;
  1001. case -EPIPE:
  1002. /* Cannot call usb_clear_halt while in_interrupt */
  1003. fallthrough;
  1004. default:
  1005. dev_err(dev, "%s - unexpected nonzero write status received: %d\n",
  1006. __func__, status);
  1007. cypress_set_dead(port);
  1008. break;
  1009. }
  1010. priv->write_urb_in_use = 0;
  1011. /* send any buffered data */
  1012. cypress_send(port);
  1013. }
  1014. module_usb_serial_driver(serial_drivers, id_table_combined);
  1015. MODULE_AUTHOR(DRIVER_AUTHOR);
  1016. MODULE_DESCRIPTION(DRIVER_DESC);
  1017. MODULE_LICENSE("GPL");
  1018. module_param(stats, bool, 0644);
  1019. MODULE_PARM_DESC(stats, "Enable statistics or not");
  1020. module_param(interval, int, 0644);
  1021. MODULE_PARM_DESC(interval, "Overrides interrupt interval");
  1022. module_param(unstable_bauds, bool, 0644);
  1023. MODULE_PARM_DESC(unstable_bauds, "Allow unstable baud rates");