cypress_m8.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  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 <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 <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 int 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 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, struct ktermios *old);
  113. static int cypress_tiocmget(struct tty_struct *tty);
  114. static int cypress_tiocmset(struct tty_struct *tty,
  115. unsigned int set, unsigned int clear);
  116. static int cypress_chars_in_buffer(struct tty_struct *tty);
  117. static void cypress_throttle(struct tty_struct *tty);
  118. static void cypress_unthrottle(struct tty_struct *tty);
  119. static void cypress_set_dead(struct usb_serial_port *port);
  120. static void cypress_read_int_callback(struct urb *urb);
  121. static void cypress_write_int_callback(struct urb *urb);
  122. static struct usb_serial_driver cypress_earthmate_device = {
  123. .driver = {
  124. .owner = THIS_MODULE,
  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. .owner = THIS_MODULE,
  151. .name = "cyphidcom",
  152. },
  153. .description = "HID->COM RS232 Adapter",
  154. .id_table = id_table_cyphidcomrs232,
  155. .num_ports = 1,
  156. .port_probe = cypress_hidcom_port_probe,
  157. .port_remove = cypress_port_remove,
  158. .open = cypress_open,
  159. .close = cypress_close,
  160. .dtr_rts = cypress_dtr_rts,
  161. .write = cypress_write,
  162. .write_room = cypress_write_room,
  163. .set_termios = cypress_set_termios,
  164. .tiocmget = cypress_tiocmget,
  165. .tiocmset = cypress_tiocmset,
  166. .tiocmiwait = usb_serial_generic_tiocmiwait,
  167. .chars_in_buffer = cypress_chars_in_buffer,
  168. .throttle = cypress_throttle,
  169. .unthrottle = cypress_unthrottle,
  170. .read_int_callback = cypress_read_int_callback,
  171. .write_int_callback = cypress_write_int_callback,
  172. };
  173. static struct usb_serial_driver cypress_ca42v2_device = {
  174. .driver = {
  175. .owner = THIS_MODULE,
  176. .name = "nokiaca42v2",
  177. },
  178. .description = "Nokia CA-42 V2 Adapter",
  179. .id_table = id_table_nokiaca42v2,
  180. .num_ports = 1,
  181. .port_probe = cypress_ca42v2_port_probe,
  182. .port_remove = cypress_port_remove,
  183. .open = cypress_open,
  184. .close = cypress_close,
  185. .dtr_rts = cypress_dtr_rts,
  186. .write = cypress_write,
  187. .write_room = cypress_write_room,
  188. .set_termios = cypress_set_termios,
  189. .tiocmget = cypress_tiocmget,
  190. .tiocmset = cypress_tiocmset,
  191. .tiocmiwait = usb_serial_generic_tiocmiwait,
  192. .chars_in_buffer = cypress_chars_in_buffer,
  193. .throttle = cypress_throttle,
  194. .unthrottle = cypress_unthrottle,
  195. .read_int_callback = cypress_read_int_callback,
  196. .write_int_callback = cypress_write_int_callback,
  197. };
  198. static struct usb_serial_driver * const serial_drivers[] = {
  199. &cypress_earthmate_device, &cypress_hidcom_device,
  200. &cypress_ca42v2_device, NULL
  201. };
  202. /*****************************************************************************
  203. * Cypress serial helper functions
  204. *****************************************************************************/
  205. /* FRWD Dongle hidcom needs to skip reset and speed checks */
  206. static inline bool is_frwd(struct usb_device *dev)
  207. {
  208. return ((le16_to_cpu(dev->descriptor.idVendor) == VENDOR_ID_FRWD) &&
  209. (le16_to_cpu(dev->descriptor.idProduct) == PRODUCT_ID_CYPHIDCOM_FRWD));
  210. }
  211. static int analyze_baud_rate(struct usb_serial_port *port, speed_t new_rate)
  212. {
  213. struct cypress_private *priv;
  214. priv = usb_get_serial_port_data(port);
  215. if (unstable_bauds)
  216. return new_rate;
  217. /* FRWD Dongle uses 115200 bps */
  218. if (is_frwd(port->serial->dev))
  219. return new_rate;
  220. /*
  221. * The general purpose firmware for the Cypress M8 allows for
  222. * a maximum speed of 57600bps (I have no idea whether DeLorme
  223. * chose to use the general purpose firmware or not), if you
  224. * need to modify this speed setting for your own project
  225. * please add your own chiptype and modify the code likewise.
  226. * The Cypress HID->COM device will work successfully up to
  227. * 115200bps (but the actual throughput is around 3kBps).
  228. */
  229. if (port->serial->dev->speed == USB_SPEED_LOW) {
  230. /*
  231. * Mike Isely <isely@pobox.com> 2-Feb-2008: The
  232. * Cypress app note that describes this mechanism
  233. * states the the low-speed part can't handle more
  234. * than 800 bytes/sec, in which case 4800 baud is the
  235. * safest speed for a part like that.
  236. */
  237. if (new_rate > 4800) {
  238. dev_dbg(&port->dev,
  239. "%s - failed setting baud rate, device incapable speed %d\n",
  240. __func__, new_rate);
  241. return -1;
  242. }
  243. }
  244. switch (priv->chiptype) {
  245. case CT_EARTHMATE:
  246. if (new_rate <= 600) {
  247. /* 300 and 600 baud rates are supported under
  248. * the generic firmware, but are not used with
  249. * NMEA and SiRF protocols */
  250. dev_dbg(&port->dev,
  251. "%s - failed setting baud rate, unsupported speed of %d on Earthmate GPS\n",
  252. __func__, new_rate);
  253. return -1;
  254. }
  255. break;
  256. default:
  257. break;
  258. }
  259. return new_rate;
  260. }
  261. /* This function can either set or retrieve the current serial line settings */
  262. static int cypress_serial_control(struct tty_struct *tty,
  263. struct usb_serial_port *port, speed_t baud_rate, int data_bits,
  264. int stop_bits, int parity_enable, int parity_type, int reset,
  265. int cypress_request_type)
  266. {
  267. int new_baudrate = 0, retval = 0, tries = 0;
  268. struct cypress_private *priv;
  269. struct device *dev = &port->dev;
  270. u8 *feature_buffer;
  271. const unsigned int feature_len = 5;
  272. unsigned long flags;
  273. priv = usb_get_serial_port_data(port);
  274. if (!priv->comm_is_ok)
  275. return -ENODEV;
  276. feature_buffer = kcalloc(feature_len, sizeof(u8), GFP_KERNEL);
  277. if (!feature_buffer)
  278. return -ENOMEM;
  279. switch (cypress_request_type) {
  280. case CYPRESS_SET_CONFIG:
  281. /* 0 means 'Hang up' so doesn't change the true bit rate */
  282. new_baudrate = priv->baud_rate;
  283. if (baud_rate && baud_rate != priv->baud_rate) {
  284. dev_dbg(dev, "%s - baud rate is changing\n", __func__);
  285. retval = analyze_baud_rate(port, baud_rate);
  286. if (retval >= 0) {
  287. new_baudrate = retval;
  288. dev_dbg(dev, "%s - New baud rate set to %d\n",
  289. __func__, new_baudrate);
  290. }
  291. }
  292. dev_dbg(dev, "%s - baud rate is being sent as %d\n", __func__,
  293. new_baudrate);
  294. /* fill the feature_buffer with new configuration */
  295. put_unaligned_le32(new_baudrate, feature_buffer);
  296. feature_buffer[4] |= data_bits; /* assign data bits in 2 bit space ( max 3 ) */
  297. /* 1 bit gap */
  298. feature_buffer[4] |= (stop_bits << 3); /* assign stop bits in 1 bit space */
  299. feature_buffer[4] |= (parity_enable << 4); /* assign parity flag in 1 bit space */
  300. feature_buffer[4] |= (parity_type << 5); /* assign parity type in 1 bit space */
  301. /* 1 bit gap */
  302. feature_buffer[4] |= (reset << 7); /* assign reset at end of byte, 1 bit space */
  303. dev_dbg(dev, "%s - device is being sent this feature report:\n", __func__);
  304. dev_dbg(dev, "%s - %02X - %02X - %02X - %02X - %02X\n", __func__,
  305. feature_buffer[0], feature_buffer[1],
  306. feature_buffer[2], feature_buffer[3],
  307. feature_buffer[4]);
  308. do {
  309. retval = usb_control_msg(port->serial->dev,
  310. usb_sndctrlpipe(port->serial->dev, 0),
  311. HID_REQ_SET_REPORT,
  312. USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
  313. 0x0300, 0, feature_buffer,
  314. feature_len, 500);
  315. if (tries++ >= 3)
  316. break;
  317. } while (retval != feature_len &&
  318. retval != -ENODEV);
  319. if (retval != feature_len) {
  320. dev_err(dev, "%s - failed sending serial line settings - %d\n",
  321. __func__, retval);
  322. cypress_set_dead(port);
  323. } else {
  324. spin_lock_irqsave(&priv->lock, flags);
  325. priv->baud_rate = new_baudrate;
  326. priv->current_config = feature_buffer[4];
  327. spin_unlock_irqrestore(&priv->lock, flags);
  328. /* If we asked for a speed change encode it */
  329. if (baud_rate)
  330. tty_encode_baud_rate(tty,
  331. new_baudrate, new_baudrate);
  332. }
  333. break;
  334. case CYPRESS_GET_CONFIG:
  335. if (priv->get_cfg_unsafe) {
  336. /* Not implemented for this device,
  337. and if we try to do it we're likely
  338. to crash the hardware. */
  339. retval = -ENOTTY;
  340. goto out;
  341. }
  342. dev_dbg(dev, "%s - retrieving serial line settings\n", __func__);
  343. do {
  344. retval = usb_control_msg(port->serial->dev,
  345. usb_rcvctrlpipe(port->serial->dev, 0),
  346. HID_REQ_GET_REPORT,
  347. USB_DIR_IN | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
  348. 0x0300, 0, feature_buffer,
  349. feature_len, 500);
  350. if (tries++ >= 3)
  351. break;
  352. } while (retval != feature_len
  353. && retval != -ENODEV);
  354. if (retval != feature_len) {
  355. dev_err(dev, "%s - failed to retrieve serial line settings - %d\n",
  356. __func__, retval);
  357. cypress_set_dead(port);
  358. goto out;
  359. } else {
  360. spin_lock_irqsave(&priv->lock, flags);
  361. /* store the config in one byte, and later
  362. use bit masks to check values */
  363. priv->current_config = feature_buffer[4];
  364. priv->baud_rate = get_unaligned_le32(feature_buffer);
  365. spin_unlock_irqrestore(&priv->lock, flags);
  366. }
  367. }
  368. spin_lock_irqsave(&priv->lock, flags);
  369. ++priv->cmd_count;
  370. spin_unlock_irqrestore(&priv->lock, flags);
  371. out:
  372. kfree(feature_buffer);
  373. return retval;
  374. } /* cypress_serial_control */
  375. static void cypress_set_dead(struct usb_serial_port *port)
  376. {
  377. struct cypress_private *priv = usb_get_serial_port_data(port);
  378. unsigned long flags;
  379. spin_lock_irqsave(&priv->lock, flags);
  380. if (!priv->comm_is_ok) {
  381. spin_unlock_irqrestore(&priv->lock, flags);
  382. return;
  383. }
  384. priv->comm_is_ok = 0;
  385. spin_unlock_irqrestore(&priv->lock, flags);
  386. dev_err(&port->dev, "cypress_m8 suspending failing port %d - "
  387. "interval might be too short\n", port->port_number);
  388. }
  389. /*****************************************************************************
  390. * Cypress serial driver functions
  391. *****************************************************************************/
  392. static int cypress_generic_port_probe(struct usb_serial_port *port)
  393. {
  394. struct usb_serial *serial = port->serial;
  395. struct cypress_private *priv;
  396. if (!port->interrupt_out_urb || !port->interrupt_in_urb) {
  397. dev_err(&port->dev, "required endpoint is missing\n");
  398. return -ENODEV;
  399. }
  400. priv = kzalloc(sizeof(struct cypress_private), GFP_KERNEL);
  401. if (!priv)
  402. return -ENOMEM;
  403. priv->comm_is_ok = !0;
  404. spin_lock_init(&priv->lock);
  405. if (kfifo_alloc(&priv->write_fifo, CYPRESS_BUF_SIZE, GFP_KERNEL)) {
  406. kfree(priv);
  407. return -ENOMEM;
  408. }
  409. /* Skip reset for FRWD device. It is a workaound:
  410. device hangs if it receives SET_CONFIGURE in Configured
  411. state. */
  412. if (!is_frwd(serial->dev))
  413. usb_reset_configuration(serial->dev);
  414. priv->cmd_ctrl = 0;
  415. priv->line_control = 0;
  416. priv->rx_flags = 0;
  417. /* Default packet format setting is determined by packet size.
  418. Anything with a size larger then 9 must have a separate
  419. count field since the 3 bit count field is otherwise too
  420. small. Otherwise we can use the slightly more compact
  421. format. This is in accordance with the cypress_m8 serial
  422. converter app note. */
  423. if (port->interrupt_out_size > 9)
  424. priv->pkt_fmt = packet_format_1;
  425. else
  426. priv->pkt_fmt = packet_format_2;
  427. if (interval > 0) {
  428. priv->write_urb_interval = interval;
  429. priv->read_urb_interval = interval;
  430. dev_dbg(&port->dev, "%s - read & write intervals forced to %d\n",
  431. __func__, interval);
  432. } else {
  433. priv->write_urb_interval = port->interrupt_out_urb->interval;
  434. priv->read_urb_interval = port->interrupt_in_urb->interval;
  435. dev_dbg(&port->dev, "%s - intervals: read=%d write=%d\n",
  436. __func__, priv->read_urb_interval,
  437. priv->write_urb_interval);
  438. }
  439. usb_set_serial_port_data(port, priv);
  440. port->port.drain_delay = 256;
  441. return 0;
  442. }
  443. static int cypress_earthmate_port_probe(struct usb_serial_port *port)
  444. {
  445. struct usb_serial *serial = port->serial;
  446. struct cypress_private *priv;
  447. int ret;
  448. ret = cypress_generic_port_probe(port);
  449. if (ret) {
  450. dev_dbg(&port->dev, "%s - Failed setting up port\n", __func__);
  451. return ret;
  452. }
  453. priv = usb_get_serial_port_data(port);
  454. priv->chiptype = CT_EARTHMATE;
  455. /* All Earthmate devices use the separated-count packet
  456. format! Idiotic. */
  457. priv->pkt_fmt = packet_format_1;
  458. if (serial->dev->descriptor.idProduct !=
  459. cpu_to_le16(PRODUCT_ID_EARTHMATEUSB)) {
  460. /* The old original USB Earthmate seemed able to
  461. handle GET_CONFIG requests; everything they've
  462. produced since that time crashes if this command is
  463. attempted :-( */
  464. dev_dbg(&port->dev,
  465. "%s - Marking this device as unsafe for GET_CONFIG commands\n",
  466. __func__);
  467. priv->get_cfg_unsafe = !0;
  468. }
  469. return 0;
  470. }
  471. static int cypress_hidcom_port_probe(struct usb_serial_port *port)
  472. {
  473. struct cypress_private *priv;
  474. int ret;
  475. ret = cypress_generic_port_probe(port);
  476. if (ret) {
  477. dev_dbg(&port->dev, "%s - Failed setting up port\n", __func__);
  478. return ret;
  479. }
  480. priv = usb_get_serial_port_data(port);
  481. priv->chiptype = CT_CYPHIDCOM;
  482. return 0;
  483. }
  484. static int cypress_ca42v2_port_probe(struct usb_serial_port *port)
  485. {
  486. struct cypress_private *priv;
  487. int ret;
  488. ret = cypress_generic_port_probe(port);
  489. if (ret) {
  490. dev_dbg(&port->dev, "%s - Failed setting up port\n", __func__);
  491. return ret;
  492. }
  493. priv = usb_get_serial_port_data(port);
  494. priv->chiptype = CT_CA42V2;
  495. return 0;
  496. }
  497. static int cypress_port_remove(struct usb_serial_port *port)
  498. {
  499. struct cypress_private *priv;
  500. priv = usb_get_serial_port_data(port);
  501. kfifo_free(&priv->write_fifo);
  502. kfree(priv);
  503. return 0;
  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 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. int room = 0;
  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 %d\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, struct ktermios *old_termios)
  735. {
  736. struct cypress_private *priv = usb_get_serial_port_data(port);
  737. struct device *dev = &port->dev;
  738. int data_bits, stop_bits, parity_type, parity_enable;
  739. unsigned int cflag;
  740. unsigned long flags;
  741. __u8 oldlines;
  742. int linechange = 0;
  743. /* Unsupported features need clearing */
  744. tty->termios.c_cflag &= ~(CMSPAR|CRTSCTS);
  745. cflag = tty->termios.c_cflag;
  746. /* set number of data bits, parity, stop bits */
  747. /* when parity is disabled the parity type bit is ignored */
  748. /* 1 means 2 stop bits, 0 means 1 stop bit */
  749. stop_bits = cflag & CSTOPB ? 1 : 0;
  750. if (cflag & PARENB) {
  751. parity_enable = 1;
  752. /* 1 means odd parity, 0 means even parity */
  753. parity_type = cflag & PARODD ? 1 : 0;
  754. } else
  755. parity_enable = parity_type = 0;
  756. switch (cflag & CSIZE) {
  757. case CS5:
  758. data_bits = 0;
  759. break;
  760. case CS6:
  761. data_bits = 1;
  762. break;
  763. case CS7:
  764. data_bits = 2;
  765. break;
  766. case CS8:
  767. data_bits = 3;
  768. break;
  769. default:
  770. dev_err(dev, "%s - CSIZE was set, but not CS5-CS8\n", __func__);
  771. data_bits = 3;
  772. }
  773. spin_lock_irqsave(&priv->lock, flags);
  774. oldlines = priv->line_control;
  775. if ((cflag & CBAUD) == B0) {
  776. /* drop dtr and rts */
  777. dev_dbg(dev, "%s - dropping the lines, baud rate 0bps\n", __func__);
  778. priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS);
  779. } else
  780. priv->line_control = (CONTROL_DTR | CONTROL_RTS);
  781. spin_unlock_irqrestore(&priv->lock, flags);
  782. dev_dbg(dev, "%s - sending %d stop_bits, %d parity_enable, %d parity_type, %d data_bits (+5)\n",
  783. __func__, stop_bits, parity_enable, parity_type, data_bits);
  784. cypress_serial_control(tty, port, tty_get_baud_rate(tty),
  785. data_bits, stop_bits,
  786. parity_enable, parity_type,
  787. 0, CYPRESS_SET_CONFIG);
  788. /* we perform a CYPRESS_GET_CONFIG so that the current settings are
  789. * filled into the private structure this should confirm that all is
  790. * working if it returns what we just set */
  791. cypress_serial_control(tty, port, 0, 0, 0, 0, 0, 0, CYPRESS_GET_CONFIG);
  792. /* Here we can define custom tty settings for devices; the main tty
  793. * termios flag base comes from empeg.c */
  794. spin_lock_irqsave(&priv->lock, flags);
  795. if (priv->chiptype == CT_EARTHMATE && priv->baud_rate == 4800) {
  796. dev_dbg(dev, "Using custom termios settings for a baud rate of 4800bps.\n");
  797. /* define custom termios settings for NMEA protocol */
  798. tty->termios.c_iflag /* input modes - */
  799. &= ~(IGNBRK /* disable ignore break */
  800. | BRKINT /* disable break causes interrupt */
  801. | PARMRK /* disable mark parity errors */
  802. | ISTRIP /* disable clear high bit of input char */
  803. | INLCR /* disable translate NL to CR */
  804. | IGNCR /* disable ignore CR */
  805. | ICRNL /* disable translate CR to NL */
  806. | IXON); /* disable enable XON/XOFF flow control */
  807. tty->termios.c_oflag /* output modes */
  808. &= ~OPOST; /* disable postprocess output char */
  809. tty->termios.c_lflag /* line discipline modes */
  810. &= ~(ECHO /* disable echo input characters */
  811. | ECHONL /* disable echo new line */
  812. | ICANON /* disable erase, kill, werase, and rprnt
  813. special characters */
  814. | ISIG /* disable interrupt, quit, and suspend
  815. special characters */
  816. | IEXTEN); /* disable non-POSIX special characters */
  817. } /* CT_CYPHIDCOM: Application should handle this for device */
  818. linechange = (priv->line_control != oldlines);
  819. spin_unlock_irqrestore(&priv->lock, flags);
  820. /* if necessary, set lines */
  821. if (linechange) {
  822. priv->cmd_ctrl = 1;
  823. cypress_write(tty, port, NULL, 0);
  824. }
  825. } /* cypress_set_termios */
  826. /* returns amount of data still left in soft buffer */
  827. static int cypress_chars_in_buffer(struct tty_struct *tty)
  828. {
  829. struct usb_serial_port *port = tty->driver_data;
  830. struct cypress_private *priv = usb_get_serial_port_data(port);
  831. int chars = 0;
  832. unsigned long flags;
  833. spin_lock_irqsave(&priv->lock, flags);
  834. chars = kfifo_len(&priv->write_fifo);
  835. spin_unlock_irqrestore(&priv->lock, flags);
  836. dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars);
  837. return chars;
  838. }
  839. static void cypress_throttle(struct tty_struct *tty)
  840. {
  841. struct usb_serial_port *port = tty->driver_data;
  842. struct cypress_private *priv = usb_get_serial_port_data(port);
  843. spin_lock_irq(&priv->lock);
  844. priv->rx_flags = THROTTLED;
  845. spin_unlock_irq(&priv->lock);
  846. }
  847. static void cypress_unthrottle(struct tty_struct *tty)
  848. {
  849. struct usb_serial_port *port = tty->driver_data;
  850. struct cypress_private *priv = usb_get_serial_port_data(port);
  851. int actually_throttled, result;
  852. spin_lock_irq(&priv->lock);
  853. actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED;
  854. priv->rx_flags = 0;
  855. spin_unlock_irq(&priv->lock);
  856. if (!priv->comm_is_ok)
  857. return;
  858. if (actually_throttled) {
  859. result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  860. if (result) {
  861. dev_err(&port->dev, "%s - failed submitting read urb, "
  862. "error %d\n", __func__, result);
  863. cypress_set_dead(port);
  864. }
  865. }
  866. }
  867. static void cypress_read_int_callback(struct urb *urb)
  868. {
  869. struct usb_serial_port *port = urb->context;
  870. struct cypress_private *priv = usb_get_serial_port_data(port);
  871. struct device *dev = &urb->dev->dev;
  872. struct tty_struct *tty;
  873. unsigned char *data = urb->transfer_buffer;
  874. unsigned long flags;
  875. char tty_flag = TTY_NORMAL;
  876. int bytes = 0;
  877. int result;
  878. int i = 0;
  879. int status = urb->status;
  880. switch (status) {
  881. case 0: /* success */
  882. break;
  883. case -ECONNRESET:
  884. case -ENOENT:
  885. case -ESHUTDOWN:
  886. /* precursor to disconnect so just go away */
  887. return;
  888. case -EPIPE:
  889. /* Can't call usb_clear_halt while in_interrupt */
  890. /* FALLS THROUGH */
  891. default:
  892. /* something ugly is going on... */
  893. dev_err(dev, "%s - unexpected nonzero read status received: %d\n",
  894. __func__, status);
  895. cypress_set_dead(port);
  896. return;
  897. }
  898. spin_lock_irqsave(&priv->lock, flags);
  899. if (priv->rx_flags & THROTTLED) {
  900. dev_dbg(dev, "%s - now throttling\n", __func__);
  901. priv->rx_flags |= ACTUALLY_THROTTLED;
  902. spin_unlock_irqrestore(&priv->lock, flags);
  903. return;
  904. }
  905. spin_unlock_irqrestore(&priv->lock, flags);
  906. tty = tty_port_tty_get(&port->port);
  907. if (!tty) {
  908. dev_dbg(dev, "%s - bad tty pointer - exiting\n", __func__);
  909. return;
  910. }
  911. spin_lock_irqsave(&priv->lock, flags);
  912. result = urb->actual_length;
  913. switch (priv->pkt_fmt) {
  914. default:
  915. case packet_format_1:
  916. /* This is for the CY7C64013... */
  917. priv->current_status = data[0] & 0xF8;
  918. bytes = data[1] + 2;
  919. i = 2;
  920. break;
  921. case packet_format_2:
  922. /* This is for the CY7C63743... */
  923. priv->current_status = data[0] & 0xF8;
  924. bytes = (data[0] & 0x07) + 1;
  925. i = 1;
  926. break;
  927. }
  928. spin_unlock_irqrestore(&priv->lock, flags);
  929. if (result < bytes) {
  930. dev_dbg(dev,
  931. "%s - wrong packet size - received %d bytes but packet said %d bytes\n",
  932. __func__, result, bytes);
  933. goto continue_read;
  934. }
  935. usb_serial_debug_data(&port->dev, __func__, urb->actual_length, data);
  936. spin_lock_irqsave(&priv->lock, flags);
  937. /* check to see if status has changed */
  938. if (priv->current_status != priv->prev_status) {
  939. u8 delta = priv->current_status ^ priv->prev_status;
  940. if (delta & UART_MSR_MASK) {
  941. if (delta & UART_CTS)
  942. port->icount.cts++;
  943. if (delta & UART_DSR)
  944. port->icount.dsr++;
  945. if (delta & UART_RI)
  946. port->icount.rng++;
  947. if (delta & UART_CD)
  948. port->icount.dcd++;
  949. wake_up_interruptible(&port->port.delta_msr_wait);
  950. }
  951. priv->prev_status = priv->current_status;
  952. }
  953. spin_unlock_irqrestore(&priv->lock, flags);
  954. /* hangup, as defined in acm.c... this might be a bad place for it
  955. * though */
  956. if (tty && !C_CLOCAL(tty) && !(priv->current_status & UART_CD)) {
  957. dev_dbg(dev, "%s - calling hangup\n", __func__);
  958. tty_hangup(tty);
  959. goto continue_read;
  960. }
  961. /* There is one error bit... I'm assuming it is a parity error
  962. * indicator as the generic firmware will set this bit to 1 if a
  963. * parity error occurs.
  964. * I can not find reference to any other error events. */
  965. spin_lock_irqsave(&priv->lock, flags);
  966. if (priv->current_status & CYP_ERROR) {
  967. spin_unlock_irqrestore(&priv->lock, flags);
  968. tty_flag = TTY_PARITY;
  969. dev_dbg(dev, "%s - Parity Error detected\n", __func__);
  970. } else
  971. spin_unlock_irqrestore(&priv->lock, flags);
  972. /* process read if there is data other than line status */
  973. if (bytes > i) {
  974. tty_insert_flip_string_fixed_flag(&port->port, data + i,
  975. tty_flag, bytes - i);
  976. tty_flip_buffer_push(&port->port);
  977. }
  978. spin_lock_irqsave(&priv->lock, flags);
  979. /* control and status byte(s) are also counted */
  980. priv->bytes_in += bytes;
  981. spin_unlock_irqrestore(&priv->lock, flags);
  982. continue_read:
  983. tty_kref_put(tty);
  984. /* Continue trying to always read */
  985. if (priv->comm_is_ok) {
  986. usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev,
  987. usb_rcvintpipe(port->serial->dev,
  988. port->interrupt_in_endpointAddress),
  989. port->interrupt_in_urb->transfer_buffer,
  990. port->interrupt_in_urb->transfer_buffer_length,
  991. cypress_read_int_callback, port,
  992. priv->read_urb_interval);
  993. result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
  994. if (result && result != -EPERM) {
  995. dev_err(dev, "%s - failed resubmitting read urb, error %d\n",
  996. __func__, result);
  997. cypress_set_dead(port);
  998. }
  999. }
  1000. } /* cypress_read_int_callback */
  1001. static void cypress_write_int_callback(struct urb *urb)
  1002. {
  1003. struct usb_serial_port *port = urb->context;
  1004. struct cypress_private *priv = usb_get_serial_port_data(port);
  1005. struct device *dev = &urb->dev->dev;
  1006. int status = urb->status;
  1007. switch (status) {
  1008. case 0:
  1009. /* success */
  1010. break;
  1011. case -ECONNRESET:
  1012. case -ENOENT:
  1013. case -ESHUTDOWN:
  1014. /* this urb is terminated, clean up */
  1015. dev_dbg(dev, "%s - urb shutting down with status: %d\n",
  1016. __func__, status);
  1017. priv->write_urb_in_use = 0;
  1018. return;
  1019. case -EPIPE:
  1020. /* Cannot call usb_clear_halt while in_interrupt */
  1021. /* FALLTHROUGH */
  1022. default:
  1023. dev_err(dev, "%s - unexpected nonzero write status received: %d\n",
  1024. __func__, status);
  1025. cypress_set_dead(port);
  1026. break;
  1027. }
  1028. priv->write_urb_in_use = 0;
  1029. /* send any buffered data */
  1030. cypress_send(port);
  1031. }
  1032. module_usb_serial_driver(serial_drivers, id_table_combined);
  1033. MODULE_AUTHOR(DRIVER_AUTHOR);
  1034. MODULE_DESCRIPTION(DRIVER_DESC);
  1035. MODULE_LICENSE("GPL");
  1036. module_param(stats, bool, S_IRUGO | S_IWUSR);
  1037. MODULE_PARM_DESC(stats, "Enable statistics or not");
  1038. module_param(interval, int, S_IRUGO | S_IWUSR);
  1039. MODULE_PARM_DESC(interval, "Overrides interrupt interval");
  1040. module_param(unstable_bauds, bool, S_IRUGO | S_IWUSR);
  1041. MODULE_PARM_DESC(unstable_bauds, "Allow unstable baud rates");