mct_u232.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Definitions for MCT (Magic Control Technology) USB-RS232 Converter Driver
  4. *
  5. * Copyright (C) 2000 Wolfgang Grandegger (wolfgang@ces.ch)
  6. *
  7. * This driver is for the device MCT USB-RS232 Converter (25 pin, Model No.
  8. * U232-P25) from Magic Control Technology Corp. (there is also a 9 pin
  9. * Model No. U232-P9). See http://www.mct.com.tw/products/product_us232.html
  10. * for further information. The properties of this device are listed at the end
  11. * of this file. This device was used in the Dlink DSB-S25.
  12. *
  13. * All of the information about the device was acquired by using SniffUSB
  14. * on Windows98. The technical details of the reverse engineering are
  15. * summarized at the end of this file.
  16. */
  17. #ifndef __LINUX_USB_SERIAL_MCT_U232_H
  18. #define __LINUX_USB_SERIAL_MCT_U232_H
  19. #define MCT_U232_VID 0x0711 /* Vendor Id */
  20. #define MCT_U232_PID 0x0210 /* Original MCT Product Id */
  21. /* U232-P25, Sitecom */
  22. #define MCT_U232_SITECOM_PID 0x0230 /* Sitecom Product Id */
  23. /* DU-H3SP USB BAY hub */
  24. #define MCT_U232_DU_H3SP_PID 0x0200 /* D-Link DU-H3SP USB BAY */
  25. /* Belkin badge the MCT U232-P9 as the F5U109 */
  26. #define MCT_U232_BELKIN_F5U109_VID 0x050d /* Vendor Id */
  27. #define MCT_U232_BELKIN_F5U109_PID 0x0109 /* Product Id */
  28. /*
  29. * Vendor Request Interface
  30. */
  31. #define MCT_U232_SET_REQUEST_TYPE 0x40
  32. #define MCT_U232_GET_REQUEST_TYPE 0xc0
  33. /* Get Modem Status Register (MSR) */
  34. #define MCT_U232_GET_MODEM_STAT_REQUEST 2
  35. #define MCT_U232_GET_MODEM_STAT_SIZE 1
  36. /* Get Line Control Register (LCR) */
  37. /* ... not used by this driver */
  38. #define MCT_U232_GET_LINE_CTRL_REQUEST 6
  39. #define MCT_U232_GET_LINE_CTRL_SIZE 1
  40. /* Set Baud Rate Divisor */
  41. #define MCT_U232_SET_BAUD_RATE_REQUEST 5
  42. #define MCT_U232_SET_BAUD_RATE_SIZE 4
  43. /* Set Line Control Register (LCR) */
  44. #define MCT_U232_SET_LINE_CTRL_REQUEST 7
  45. #define MCT_U232_SET_LINE_CTRL_SIZE 1
  46. /* Set Modem Control Register (MCR) */
  47. #define MCT_U232_SET_MODEM_CTRL_REQUEST 10
  48. #define MCT_U232_SET_MODEM_CTRL_SIZE 1
  49. /*
  50. * This USB device request code is not well understood. It is transmitted by
  51. * the MCT-supplied Windows driver whenever the baud rate changes.
  52. */
  53. #define MCT_U232_SET_UNKNOWN1_REQUEST 11 /* Unknown functionality */
  54. #define MCT_U232_SET_UNKNOWN1_SIZE 1
  55. /*
  56. * This USB device request code appears to control whether CTS is required
  57. * during transmission.
  58. *
  59. * Sending a zero byte allows data transmission to a device which is not
  60. * asserting CTS. Sending a '1' byte will cause transmission to be deferred
  61. * until the device asserts CTS.
  62. */
  63. #define MCT_U232_SET_CTS_REQUEST 12
  64. #define MCT_U232_SET_CTS_SIZE 1
  65. #define MCT_U232_MAX_SIZE 4 /* of MCT_XXX_SIZE */
  66. /*
  67. * Baud rate (divisor)
  68. * Actually, there are two of them, MCT website calls them "Philips solution"
  69. * and "Intel solution". They are the regular MCT and "Sitecom" for us.
  70. * This is pointless to document in the header, see the code for the bits.
  71. */
  72. static int mct_u232_calculate_baud_rate(struct usb_serial *serial,
  73. speed_t value, speed_t *result);
  74. /*
  75. * Line Control Register (LCR)
  76. */
  77. #define MCT_U232_SET_BREAK 0x40
  78. #define MCT_U232_PARITY_SPACE 0x38
  79. #define MCT_U232_PARITY_MARK 0x28
  80. #define MCT_U232_PARITY_EVEN 0x18
  81. #define MCT_U232_PARITY_ODD 0x08
  82. #define MCT_U232_PARITY_NONE 0x00
  83. #define MCT_U232_DATA_BITS_5 0x00
  84. #define MCT_U232_DATA_BITS_6 0x01
  85. #define MCT_U232_DATA_BITS_7 0x02
  86. #define MCT_U232_DATA_BITS_8 0x03
  87. #define MCT_U232_STOP_BITS_2 0x04
  88. #define MCT_U232_STOP_BITS_1 0x00
  89. /*
  90. * Modem Control Register (MCR)
  91. */
  92. #define MCT_U232_MCR_NONE 0x8 /* Deactivate DTR and RTS */
  93. #define MCT_U232_MCR_RTS 0xa /* Activate RTS */
  94. #define MCT_U232_MCR_DTR 0x9 /* Activate DTR */
  95. /*
  96. * Modem Status Register (MSR)
  97. */
  98. #define MCT_U232_MSR_INDEX 0x0 /* data[index] */
  99. #define MCT_U232_MSR_CD 0x80 /* Current CD */
  100. #define MCT_U232_MSR_RI 0x40 /* Current RI */
  101. #define MCT_U232_MSR_DSR 0x20 /* Current DSR */
  102. #define MCT_U232_MSR_CTS 0x10 /* Current CTS */
  103. #define MCT_U232_MSR_DCD 0x08 /* Delta CD */
  104. #define MCT_U232_MSR_DRI 0x04 /* Delta RI */
  105. #define MCT_U232_MSR_DDSR 0x02 /* Delta DSR */
  106. #define MCT_U232_MSR_DCTS 0x01 /* Delta CTS */
  107. /*
  108. * Line Status Register (LSR)
  109. */
  110. #define MCT_U232_LSR_INDEX 1 /* data[index] */
  111. #define MCT_U232_LSR_ERR 0x80 /* OE | PE | FE | BI */
  112. #define MCT_U232_LSR_TEMT 0x40 /* transmit register empty */
  113. #define MCT_U232_LSR_THRE 0x20 /* transmit holding register empty */
  114. #define MCT_U232_LSR_BI 0x10 /* break indicator */
  115. #define MCT_U232_LSR_FE 0x08 /* framing error */
  116. #define MCT_U232_LSR_OE 0x02 /* overrun error */
  117. #define MCT_U232_LSR_PE 0x04 /* parity error */
  118. #define MCT_U232_LSR_OE 0x02 /* overrun error */
  119. #define MCT_U232_LSR_DR 0x01 /* receive data ready */
  120. /* -----------------------------------------------------------------------------
  121. * Technical Specification reverse engineered with SniffUSB on Windows98
  122. * =====================================================================
  123. *
  124. * The technical details of the device have been acquired be using "SniffUSB"
  125. * and the vendor-supplied device driver (version 2.3A) under Windows98. To
  126. * identify the USB vendor-specific requests and to assign them to terminal
  127. * settings (flow control, baud rate, etc.) the program "SerialSettings" from
  128. * William G. Greathouse has been proven to be very useful. I also used the
  129. * Win98 "HyperTerminal" and "usb-robot" on Linux for testing. The results and
  130. * observations are summarized below:
  131. *
  132. * The USB requests seem to be directly mapped to the registers of a 8250,
  133. * 16450 or 16550 UART. The FreeBSD handbook (appendix F.4 "Input/Output
  134. * devices") contains a comprehensive description of UARTs and its registers.
  135. * The bit descriptions are actually taken from there.
  136. *
  137. *
  138. * Baud rate (divisor)
  139. * -------------------
  140. *
  141. * BmRequestType: 0x40 (0100 0000B)
  142. * bRequest: 0x05
  143. * wValue: 0x0000
  144. * wIndex: 0x0000
  145. * wLength: 0x0004
  146. * Data: divisor = 115200 / baud_rate
  147. *
  148. * SniffUSB observations (Nov 2003): Contrary to the 'wLength' value of 4
  149. * shown above, observations with a Belkin F5U109 adapter, using the
  150. * MCT-supplied Windows98 driver (U2SPORT.VXD, "File version: 1.21P.0104 for
  151. * Win98/Me"), show this request has a length of 1 byte, presumably because
  152. * of the fact that the Belkin adapter and the 'Sitecom U232-P25' adapter
  153. * use a baud-rate code instead of a conventional RS-232 baud rate divisor.
  154. * The current source code for this driver does not reflect this fact, but
  155. * the driver works fine with this adapter/driver combination nonetheless.
  156. *
  157. *
  158. * Line Control Register (LCR)
  159. * ---------------------------
  160. *
  161. * BmRequestType: 0x40 (0100 0000B) 0xc0 (1100 0000B)
  162. * bRequest: 0x07 0x06
  163. * wValue: 0x0000
  164. * wIndex: 0x0000
  165. * wLength: 0x0001
  166. * Data: LCR (see below)
  167. *
  168. * Bit 7: Divisor Latch Access Bit (DLAB). When set, access to the data
  169. * transmit/receive register (THR/RBR) and the Interrupt Enable Register
  170. * (IER) is disabled. Any access to these ports is now redirected to the
  171. * Divisor Latch Registers. Setting this bit, loading the Divisor
  172. * Registers, and clearing DLAB should be done with interrupts disabled.
  173. * Bit 6: Set Break. When set to "1", the transmitter begins to transmit
  174. * continuous Spacing until this bit is set to "0". This overrides any
  175. * bits of characters that are being transmitted.
  176. * Bit 5: Stick Parity. When parity is enabled, setting this bit causes parity
  177. * to always be "1" or "0", based on the value of Bit 4.
  178. * Bit 4: Even Parity Select (EPS). When parity is enabled and Bit 5 is "0",
  179. * setting this bit causes even parity to be transmitted and expected.
  180. * Otherwise, odd parity is used.
  181. * Bit 3: Parity Enable (PEN). When set to "1", a parity bit is inserted
  182. * between the last bit of the data and the Stop Bit. The UART will also
  183. * expect parity to be present in the received data.
  184. * Bit 2: Number of Stop Bits (STB). If set to "1" and using 5-bit data words,
  185. * 1.5 Stop Bits are transmitted and expected in each data word. For
  186. * 6, 7 and 8-bit data words, 2 Stop Bits are transmitted and expected.
  187. * When this bit is set to "0", one Stop Bit is used on each data word.
  188. * Bit 1: Word Length Select Bit #1 (WLSB1)
  189. * Bit 0: Word Length Select Bit #0 (WLSB0)
  190. * Together these bits specify the number of bits in each data word.
  191. * 1 0 Word Length
  192. * 0 0 5 Data Bits
  193. * 0 1 6 Data Bits
  194. * 1 0 7 Data Bits
  195. * 1 1 8 Data Bits
  196. *
  197. * SniffUSB observations: Bit 7 seems not to be used. There seem to be two bugs
  198. * in the Win98 driver: the break does not work (bit 6 is not asserted) and the
  199. * stick parity bit is not cleared when set once. The LCR can also be read
  200. * back with USB request 6 but this has never been observed with SniffUSB.
  201. *
  202. *
  203. * Modem Control Register (MCR)
  204. * ----------------------------
  205. *
  206. * BmRequestType: 0x40 (0100 0000B)
  207. * bRequest: 0x0a
  208. * wValue: 0x0000
  209. * wIndex: 0x0000
  210. * wLength: 0x0001
  211. * Data: MCR (Bit 4..7, see below)
  212. *
  213. * Bit 7: Reserved, always 0.
  214. * Bit 6: Reserved, always 0.
  215. * Bit 5: Reserved, always 0.
  216. * Bit 4: Loop-Back Enable. When set to "1", the UART transmitter and receiver
  217. * are internally connected together to allow diagnostic operations. In
  218. * addition, the UART modem control outputs are connected to the UART
  219. * modem control inputs. CTS is connected to RTS, DTR is connected to
  220. * DSR, OUT1 is connected to RI, and OUT 2 is connected to DCD.
  221. * Bit 3: OUT 2. An auxiliary output that the host processor may set high or
  222. * low. In the IBM PC serial adapter (and most clones), OUT 2 is used
  223. * to tri-state (disable) the interrupt signal from the
  224. * 8250/16450/16550 UART.
  225. * Bit 2: OUT 1. An auxiliary output that the host processor may set high or
  226. * low. This output is not used on the IBM PC serial adapter.
  227. * Bit 1: Request to Send (RTS). When set to "1", the output of the UART -RTS
  228. * line is Low (Active).
  229. * Bit 0: Data Terminal Ready (DTR). When set to "1", the output of the UART
  230. * -DTR line is Low (Active).
  231. *
  232. * SniffUSB observations: Bit 2 and 4 seem not to be used but bit 3 has been
  233. * seen _always_ set.
  234. *
  235. *
  236. * Modem Status Register (MSR)
  237. * ---------------------------
  238. *
  239. * BmRequestType: 0xc0 (1100 0000B)
  240. * bRequest: 0x02
  241. * wValue: 0x0000
  242. * wIndex: 0x0000
  243. * wLength: 0x0001
  244. * Data: MSR (see below)
  245. *
  246. * Bit 7: Data Carrier Detect (CD). Reflects the state of the DCD line on the
  247. * UART.
  248. * Bit 6: Ring Indicator (RI). Reflects the state of the RI line on the UART.
  249. * Bit 5: Data Set Ready (DSR). Reflects the state of the DSR line on the UART.
  250. * Bit 4: Clear To Send (CTS). Reflects the state of the CTS line on the UART.
  251. * Bit 3: Delta Data Carrier Detect (DDCD). Set to "1" if the -DCD line has
  252. * changed state one more more times since the last time the MSR was
  253. * read by the host.
  254. * Bit 2: Trailing Edge Ring Indicator (TERI). Set to "1" if the -RI line has
  255. * had a low to high transition since the last time the MSR was read by
  256. * the host.
  257. * Bit 1: Delta Data Set Ready (DDSR). Set to "1" if the -DSR line has changed
  258. * state one more more times since the last time the MSR was read by the
  259. * host.
  260. * Bit 0: Delta Clear To Send (DCTS). Set to "1" if the -CTS line has changed
  261. * state one more times since the last time the MSR was read by the
  262. * host.
  263. *
  264. * SniffUSB observations: the MSR is also returned as first byte on the
  265. * interrupt-in endpoint 0x83 to signal changes of modem status lines. The USB
  266. * request to read MSR cannot be applied during normal device operation.
  267. *
  268. *
  269. * Line Status Register (LSR)
  270. * --------------------------
  271. *
  272. * Bit 7 Error in Receiver FIFO. On the 8250/16450 UART, this bit is zero.
  273. * This bit is set to "1" when any of the bytes in the FIFO have one
  274. * or more of the following error conditions: PE, FE, or BI.
  275. * Bit 6 Transmitter Empty (TEMT). When set to "1", there are no words
  276. * remaining in the transmit FIFO or the transmit shift register. The
  277. * transmitter is completely idle.
  278. * Bit 5 Transmitter Holding Register Empty (THRE). When set to "1", the
  279. * FIFO (or holding register) now has room for at least one additional
  280. * word to transmit. The transmitter may still be transmitting when
  281. * this bit is set to "1".
  282. * Bit 4 Break Interrupt (BI). The receiver has detected a Break signal.
  283. * Bit 3 Framing Error (FE). A Start Bit was detected but the Stop Bit did
  284. * not appear at the expected time. The received word is probably
  285. * garbled.
  286. * Bit 2 Parity Error (PE). The parity bit was incorrect for the word
  287. * received.
  288. * Bit 1 Overrun Error (OE). A new word was received and there was no room
  289. * in the receive buffer. The newly-arrived word in the shift register
  290. * is discarded. On 8250/16450 UARTs, the word in the holding register
  291. * is discarded and the newly- arrived word is put in the holding
  292. * register.
  293. * Bit 0 Data Ready (DR). One or more words are in the receive FIFO that the
  294. * host may read. A word must be completely received and moved from
  295. * the shift register into the FIFO (or holding register for
  296. * 8250/16450 designs) before this bit is set.
  297. *
  298. * SniffUSB observations: the LSR is returned as second byte on the
  299. * interrupt-in endpoint 0x83 to signal error conditions. Such errors have
  300. * been seen with minicom/zmodem transfers (CRC errors).
  301. *
  302. *
  303. * Unknown #1
  304. * -------------------
  305. *
  306. * BmRequestType: 0x40 (0100 0000B)
  307. * bRequest: 0x0b
  308. * wValue: 0x0000
  309. * wIndex: 0x0000
  310. * wLength: 0x0001
  311. * Data: 0x00
  312. *
  313. * SniffUSB observations (Nov 2003): With the MCT-supplied Windows98 driver
  314. * (U2SPORT.VXD, "File version: 1.21P.0104 for Win98/Me"), this request
  315. * occurs immediately after a "Baud rate (divisor)" message. It was not
  316. * observed at any other time. It is unclear what purpose this message
  317. * serves.
  318. *
  319. *
  320. * Unknown #2
  321. * -------------------
  322. *
  323. * BmRequestType: 0x40 (0100 0000B)
  324. * bRequest: 0x0c
  325. * wValue: 0x0000
  326. * wIndex: 0x0000
  327. * wLength: 0x0001
  328. * Data: 0x00
  329. *
  330. * SniffUSB observations (Nov 2003): With the MCT-supplied Windows98 driver
  331. * (U2SPORT.VXD, "File version: 1.21P.0104 for Win98/Me"), this request
  332. * occurs immediately after the 'Unknown #1' message (see above). It was
  333. * not observed at any other time. It is unclear what other purpose (if
  334. * any) this message might serve, but without it, the USB/RS-232 adapter
  335. * will not write to RS-232 devices which do not assert the 'CTS' signal.
  336. *
  337. *
  338. * Flow control
  339. * ------------
  340. *
  341. * SniffUSB observations: no flow control specific requests have been realized
  342. * apart from DTR/RTS settings. Both signals are dropped for no flow control
  343. * but asserted for hardware or software flow control.
  344. *
  345. *
  346. * Endpoint usage
  347. * --------------
  348. *
  349. * SniffUSB observations: the bulk-out endpoint 0x1 and interrupt-in endpoint
  350. * 0x81 is used to transmit and receive characters. The second interrupt-in
  351. * endpoint 0x83 signals exceptional conditions like modem line changes and
  352. * errors. The first byte returned is the MSR and the second byte the LSR.
  353. *
  354. *
  355. * Other observations
  356. * ------------------
  357. *
  358. * Queued bulk transfers like used in visor.c did not work.
  359. *
  360. *
  361. * Properties of the USB device used (as found in /var/log/messages)
  362. * -----------------------------------------------------------------
  363. *
  364. * Manufacturer: MCT Corporation.
  365. * Product: USB-232 Interfact Controller
  366. * SerialNumber: U2S22050
  367. *
  368. * Length = 18
  369. * DescriptorType = 01
  370. * USB version = 1.00
  371. * Vendor:Product = 0711:0210
  372. * MaxPacketSize0 = 8
  373. * NumConfigurations = 1
  374. * Device version = 1.02
  375. * Device Class:SubClass:Protocol = 00:00:00
  376. * Per-interface classes
  377. * Configuration:
  378. * bLength = 9
  379. * bDescriptorType = 02
  380. * wTotalLength = 0027
  381. * bNumInterfaces = 01
  382. * bConfigurationValue = 01
  383. * iConfiguration = 00
  384. * bmAttributes = c0
  385. * MaxPower = 100mA
  386. *
  387. * Interface: 0
  388. * Alternate Setting: 0
  389. * bLength = 9
  390. * bDescriptorType = 04
  391. * bInterfaceNumber = 00
  392. * bAlternateSetting = 00
  393. * bNumEndpoints = 03
  394. * bInterface Class:SubClass:Protocol = 00:00:00
  395. * iInterface = 00
  396. * Endpoint:
  397. * bLength = 7
  398. * bDescriptorType = 05
  399. * bEndpointAddress = 81 (in)
  400. * bmAttributes = 03 (Interrupt)
  401. * wMaxPacketSize = 0040
  402. * bInterval = 02
  403. * Endpoint:
  404. * bLength = 7
  405. * bDescriptorType = 05
  406. * bEndpointAddress = 01 (out)
  407. * bmAttributes = 02 (Bulk)
  408. * wMaxPacketSize = 0040
  409. * bInterval = 00
  410. * Endpoint:
  411. * bLength = 7
  412. * bDescriptorType = 05
  413. * bEndpointAddress = 83 (in)
  414. * bmAttributes = 03 (Interrupt)
  415. * wMaxPacketSize = 0002
  416. * bInterval = 02
  417. *
  418. *
  419. * Hardware details (added by Martin Hamilton, 2001/12/06)
  420. * -----------------------------------------------------------------
  421. *
  422. * This info was gleaned from opening a Belkin F5U109 DB9 USB serial
  423. * adaptor, which turns out to simply be a re-badged U232-P9. We
  424. * know this because there is a sticky label on the circuit board
  425. * which says "U232-P9" ;-)
  426. *
  427. * The circuit board inside the adaptor contains a Philips PDIUSBD12
  428. * USB endpoint chip and a Philips P87C52UBAA microcontroller with
  429. * embedded UART. Exhaustive documentation for these is available at:
  430. *
  431. * http://www.semiconductors.philips.com/pip/p87c52ubaa
  432. * http://www.nxp.com/acrobat_download/various/PDIUSBD12_PROGRAMMING_GUIDE.pdf
  433. *
  434. * Thanks to Julian Highfield for the pointer to the Philips database.
  435. *
  436. */
  437. #endif /* __LINUX_USB_SERIAL_MCT_U232_H */