cypress_m8.c 36 KB

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