1 /* $NetBSD: uftdi.c,v 1.13 2002/09/23 05:51:23 simonb Exp $ */ 2 3 /*- 4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Lennart Augustsson (lennart@augustsson.net). 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 __FBSDID("$FreeBSD$"); 34 35 /* 36 * NOTE: all function names beginning like "uftdi_cfg_" can only 37 * be called from within the config thread function ! 38 */ 39 40 /* 41 * FTDI FT232x, FT2232x, FT4232x, FT8U100AX and FT8U232xM serial adapters. 42 * 43 * Note that we specifically do not do a reset or otherwise alter the state of 44 * the chip during attach, detach, open, and close, because it could be 45 * pre-initialized (via an attached serial eeprom) to power-on into a mode such 46 * as bitbang in which the pins are being driven to a specific state which we 47 * must not perturb. The device gets reset at power-on, and doesn't need to be 48 * reset again after that to function, except as directed by ioctl() calls. 49 */ 50 51 #include <sys/stdint.h> 52 #include <sys/stddef.h> 53 #include <sys/param.h> 54 #include <sys/queue.h> 55 #include <sys/types.h> 56 #include <sys/systm.h> 57 #include <sys/kernel.h> 58 #include <sys/bus.h> 59 #include <sys/module.h> 60 #include <sys/lock.h> 61 #include <sys/mutex.h> 62 #include <sys/condvar.h> 63 #include <sys/sysctl.h> 64 #include <sys/sx.h> 65 #include <sys/unistd.h> 66 #include <sys/callout.h> 67 #include <sys/malloc.h> 68 #include <sys/priv.h> 69 70 #include <dev/usb/usb.h> 71 #include <dev/usb/usbdi.h> 72 #include <dev/usb/usbdi_util.h> 73 #include <dev/usb/usb_core.h> 74 #include <dev/usb/usb_ioctl.h> 75 #include "usbdevs.h" 76 77 #define USB_DEBUG_VAR uftdi_debug 78 #include <dev/usb/usb_debug.h> 79 #include <dev/usb/usb_process.h> 80 81 #include <dev/usb/serial/usb_serial.h> 82 #include <dev/usb/serial/uftdi_reg.h> 83 #include <dev/usb/uftdiio.h> 84 85 static SYSCTL_NODE(_hw_usb, OID_AUTO, uftdi, CTLFLAG_RW, 0, "USB uftdi"); 86 87 #ifdef USB_DEBUG 88 static int uftdi_debug = 0; 89 SYSCTL_INT(_hw_usb_uftdi, OID_AUTO, debug, CTLFLAG_RWTUN, 90 &uftdi_debug, 0, "Debug level"); 91 #endif 92 93 #define UFTDI_CONFIG_INDEX 0 94 95 /* 96 * IO buffer sizes and FTDI device procotol sizes. 97 * 98 * Note that the output packet size in the following defines is not the usb 99 * protocol packet size based on bus speed, it is the size dictated by the FTDI 100 * device itself, and is used only on older chips. 101 * 102 * We allocate buffers bigger than the hardware's packet size, and process 103 * multiple packets within each buffer. This allows the controller to make 104 * optimal use of the usb bus by conducting multiple transfers with the device 105 * during a single bus timeslice to fill or drain the chip's fifos. 106 * 107 * The output data on newer chips has no packet header, and we are able to pack 108 * any number of output bytes into a buffer. On some older chips, each output 109 * packet contains a 1-byte header and up to 63 bytes of payload. The size is 110 * encoded in 6 bits of the header, hence the 64-byte limit on packet size. We 111 * loop to fill the buffer with many of these header+payload packets. 112 * 113 * The input data on all chips consists of packets which contain a 2-byte header 114 * followed by data payload. The total size of the packet is wMaxPacketSize 115 * which can change based on the bus speed (e.g., 64 for full speed, 512 for 116 * high speed). We loop to extract the headers and payloads from the packets 117 * packed into an input buffer. 118 */ 119 #define UFTDI_IBUFSIZE 2048 120 #define UFTDI_IHDRSIZE 2 121 #define UFTDI_OBUFSIZE 2048 122 #define UFTDI_OPKTSIZE 64 123 124 enum { 125 UFTDI_BULK_DT_WR, 126 UFTDI_BULK_DT_RD, 127 UFTDI_N_TRANSFER, 128 }; 129 130 enum { 131 DEVT_SIO, 132 DEVT_232A, 133 DEVT_232B, 134 DEVT_2232D, /* Includes 2232C */ 135 DEVT_232R, 136 DEVT_2232H, 137 DEVT_4232H, 138 DEVT_232H, 139 DEVT_230X, 140 }; 141 142 #define DEVF_BAUDBITS_HINDEX 0x01 /* Baud bits in high byte of index. */ 143 #define DEVF_BAUDCLK_12M 0X02 /* Base baud clock is 12MHz. */ 144 145 struct uftdi_softc { 146 struct ucom_super_softc sc_super_ucom; 147 struct ucom_softc sc_ucom; 148 149 struct usb_device *sc_udev; 150 struct usb_xfer *sc_xfer[UFTDI_N_TRANSFER]; 151 device_t sc_dev; 152 struct mtx sc_mtx; 153 154 uint32_t sc_unit; 155 156 uint16_t sc_last_lcr; 157 uint16_t sc_bcdDevice; 158 159 uint8_t sc_devtype; 160 uint8_t sc_devflags; 161 uint8_t sc_hdrlen; 162 uint8_t sc_msr; 163 uint8_t sc_lsr; 164 uint8_t sc_bitmode; 165 }; 166 167 struct uftdi_param_config { 168 uint16_t baud_lobits; 169 uint16_t baud_hibits; 170 uint16_t lcr; 171 uint8_t v_start; 172 uint8_t v_stop; 173 uint8_t v_flow; 174 }; 175 176 /* prototypes */ 177 178 static device_probe_t uftdi_probe; 179 static device_attach_t uftdi_attach; 180 static device_detach_t uftdi_detach; 181 static void uftdi_free_softc(struct uftdi_softc *); 182 183 static usb_callback_t uftdi_write_callback; 184 static usb_callback_t uftdi_read_callback; 185 186 static void uftdi_free(struct ucom_softc *); 187 static void uftdi_cfg_open(struct ucom_softc *); 188 static void uftdi_cfg_close(struct ucom_softc *); 189 static void uftdi_cfg_set_dtr(struct ucom_softc *, uint8_t); 190 static void uftdi_cfg_set_rts(struct ucom_softc *, uint8_t); 191 static void uftdi_cfg_set_break(struct ucom_softc *, uint8_t); 192 static int uftdi_set_parm_soft(struct ucom_softc *, struct termios *, 193 struct uftdi_param_config *); 194 static int uftdi_pre_param(struct ucom_softc *, struct termios *); 195 static void uftdi_cfg_param(struct ucom_softc *, struct termios *); 196 static void uftdi_cfg_get_status(struct ucom_softc *, uint8_t *, 197 uint8_t *); 198 static int uftdi_reset(struct ucom_softc *, int); 199 static int uftdi_set_bitmode(struct ucom_softc *, uint8_t, uint8_t); 200 static int uftdi_get_bitmode(struct ucom_softc *, uint8_t *, uint8_t *); 201 static int uftdi_set_latency(struct ucom_softc *, int); 202 static int uftdi_get_latency(struct ucom_softc *, int *); 203 static int uftdi_set_event_char(struct ucom_softc *, int); 204 static int uftdi_set_error_char(struct ucom_softc *, int); 205 static int uftdi_ioctl(struct ucom_softc *, uint32_t, caddr_t, int, 206 struct thread *); 207 static void uftdi_start_read(struct ucom_softc *); 208 static void uftdi_stop_read(struct ucom_softc *); 209 static void uftdi_start_write(struct ucom_softc *); 210 static void uftdi_stop_write(struct ucom_softc *); 211 static void uftdi_poll(struct ucom_softc *ucom); 212 213 static const struct usb_config uftdi_config[UFTDI_N_TRANSFER] = { 214 215 [UFTDI_BULK_DT_WR] = { 216 .type = UE_BULK, 217 .endpoint = UE_ADDR_ANY, 218 .direction = UE_DIR_OUT, 219 .bufsize = UFTDI_OBUFSIZE, 220 .flags = {.pipe_bof = 1,}, 221 .callback = &uftdi_write_callback, 222 }, 223 224 [UFTDI_BULK_DT_RD] = { 225 .type = UE_BULK, 226 .endpoint = UE_ADDR_ANY, 227 .direction = UE_DIR_IN, 228 .bufsize = UFTDI_IBUFSIZE, 229 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 230 .callback = &uftdi_read_callback, 231 }, 232 }; 233 234 static const struct ucom_callback uftdi_callback = { 235 .ucom_cfg_get_status = &uftdi_cfg_get_status, 236 .ucom_cfg_set_dtr = &uftdi_cfg_set_dtr, 237 .ucom_cfg_set_rts = &uftdi_cfg_set_rts, 238 .ucom_cfg_set_break = &uftdi_cfg_set_break, 239 .ucom_cfg_param = &uftdi_cfg_param, 240 .ucom_cfg_open = &uftdi_cfg_open, 241 .ucom_cfg_close = &uftdi_cfg_close, 242 .ucom_pre_param = &uftdi_pre_param, 243 .ucom_ioctl = &uftdi_ioctl, 244 .ucom_start_read = &uftdi_start_read, 245 .ucom_stop_read = &uftdi_stop_read, 246 .ucom_start_write = &uftdi_start_write, 247 .ucom_stop_write = &uftdi_stop_write, 248 .ucom_poll = &uftdi_poll, 249 .ucom_free = &uftdi_free, 250 }; 251 252 static device_method_t uftdi_methods[] = { 253 /* Device interface */ 254 DEVMETHOD(device_probe, uftdi_probe), 255 DEVMETHOD(device_attach, uftdi_attach), 256 DEVMETHOD(device_detach, uftdi_detach), 257 DEVMETHOD_END 258 }; 259 260 static devclass_t uftdi_devclass; 261 262 static driver_t uftdi_driver = { 263 .name = "uftdi", 264 .methods = uftdi_methods, 265 .size = sizeof(struct uftdi_softc), 266 }; 267 268 DRIVER_MODULE(uftdi, uhub, uftdi_driver, uftdi_devclass, NULL, NULL); 269 MODULE_DEPEND(uftdi, ucom, 1, 1, 1); 270 MODULE_DEPEND(uftdi, usb, 1, 1, 1); 271 MODULE_VERSION(uftdi, 1); 272 273 static const STRUCT_USB_HOST_ID uftdi_devs[] = { 274 #define UFTDI_DEV(v, p, i) \ 275 { USB_VPI(USB_VENDOR_##v, USB_PRODUCT_##v##_##p, i) } 276 UFTDI_DEV(ACTON, SPECTRAPRO, 0), 277 UFTDI_DEV(ALTI2, N3, 0), 278 UFTDI_DEV(ANALOGDEVICES, GNICE, UFTDI_JTAG_IFACE(0)), 279 UFTDI_DEV(ANALOGDEVICES, GNICEPLUS, UFTDI_JTAG_IFACE(0)), 280 UFTDI_DEV(ATMEL, STK541, 0), 281 UFTDI_DEV(BAYER, CONTOUR_CABLE, 0), 282 UFTDI_DEV(BBELECTRONICS, 232USB9M, 0), 283 UFTDI_DEV(BBELECTRONICS, 485USB9F_2W, 0), 284 UFTDI_DEV(BBELECTRONICS, 485USB9F_4W, 0), 285 UFTDI_DEV(BBELECTRONICS, 485USBTB_2W, 0), 286 UFTDI_DEV(BBELECTRONICS, 485USBTB_4W, 0), 287 UFTDI_DEV(BBELECTRONICS, TTL3USB9M, 0), 288 UFTDI_DEV(BBELECTRONICS, TTL5USB9M, 0), 289 UFTDI_DEV(BBELECTRONICS, USO9ML2, 0), 290 UFTDI_DEV(BBELECTRONICS, USO9ML2DR, 0), 291 UFTDI_DEV(BBELECTRONICS, USO9ML2DR_2, 0), 292 UFTDI_DEV(BBELECTRONICS, USOPTL4, 0), 293 UFTDI_DEV(BBELECTRONICS, USOPTL4DR, 0), 294 UFTDI_DEV(BBELECTRONICS, USOPTL4DR2, 0), 295 UFTDI_DEV(BBELECTRONICS, USOTL4, 0), 296 UFTDI_DEV(BBELECTRONICS, USPTL4, 0), 297 UFTDI_DEV(BBELECTRONICS, USTL4, 0), 298 UFTDI_DEV(BBELECTRONICS, ZZ_PROG1_USB, 0), 299 UFTDI_DEV(CONTEC, COM1USBH, 0), 300 UFTDI_DEV(DRESDENELEKTRONIK, SENSORTERMINALBOARD, 0), 301 UFTDI_DEV(DRESDENELEKTRONIK, WIRELESSHANDHELDTERMINAL, 0), 302 UFTDI_DEV(DRESDENELEKTRONIK, DE_RFNODE, 0), 303 UFTDI_DEV(DRESDENELEKTRONIK, LEVELSHIFTERSTICKLOWCOST, 0), 304 UFTDI_DEV(ELEKTOR, FT323R, 0), 305 UFTDI_DEV(EVOLUTION, ER1, 0), 306 UFTDI_DEV(EVOLUTION, HYBRID, 0), 307 UFTDI_DEV(EVOLUTION, RCM4, 0), 308 UFTDI_DEV(FALCOM, SAMBA, 0), 309 UFTDI_DEV(FALCOM, TWIST, 0), 310 UFTDI_DEV(FIC, NEO1973_DEBUG, UFTDI_JTAG_IFACE(0)), 311 UFTDI_DEV(FIC, NEO1973_DEBUG, UFTDI_JTAG_IFACE(0)), 312 UFTDI_DEV(FTDI, 232EX, 0), 313 UFTDI_DEV(FTDI, 232H, 0), 314 UFTDI_DEV(FTDI, 232RL, 0), 315 UFTDI_DEV(FTDI, 4N_GALAXY_DE_1, 0), 316 UFTDI_DEV(FTDI, 4N_GALAXY_DE_2, 0), 317 UFTDI_DEV(FTDI, 4N_GALAXY_DE_3, 0), 318 UFTDI_DEV(FTDI, 8U232AM_ALT, 0), 319 UFTDI_DEV(FTDI, ACCESSO, 0), 320 UFTDI_DEV(FTDI, ACG_HFDUAL, 0), 321 UFTDI_DEV(FTDI, ACTIVE_ROBOTS, 0), 322 UFTDI_DEV(FTDI, ACTZWAVE, 0), 323 UFTDI_DEV(FTDI, AMC232, 0), 324 UFTDI_DEV(FTDI, ARTEMIS, 0), 325 UFTDI_DEV(FTDI, ASK_RDR400, 0), 326 UFTDI_DEV(FTDI, ATIK_ATK16, 0), 327 UFTDI_DEV(FTDI, ATIK_ATK16C, 0), 328 UFTDI_DEV(FTDI, ATIK_ATK16HR, 0), 329 UFTDI_DEV(FTDI, ATIK_ATK16HRC, 0), 330 UFTDI_DEV(FTDI, ATIK_ATK16IC, 0), 331 UFTDI_DEV(FTDI, BCS_SE923, 0), 332 UFTDI_DEV(FTDI, CANDAPTER, 0), 333 UFTDI_DEV(FTDI, CANUSB, 0), 334 UFTDI_DEV(FTDI, CCSICDU20_0, 0), 335 UFTDI_DEV(FTDI, CCSICDU40_1, 0), 336 UFTDI_DEV(FTDI, CCSICDU64_4, 0), 337 UFTDI_DEV(FTDI, CCSLOAD_N_GO_3, 0), 338 UFTDI_DEV(FTDI, CCSMACHX_2, 0), 339 UFTDI_DEV(FTDI, CCSPRIME8_5, 0), 340 UFTDI_DEV(FTDI, CFA_631, 0), 341 UFTDI_DEV(FTDI, CFA_632, 0), 342 UFTDI_DEV(FTDI, CFA_633, 0), 343 UFTDI_DEV(FTDI, CFA_634, 0), 344 UFTDI_DEV(FTDI, CFA_635, 0), 345 UFTDI_DEV(FTDI, CHAMSYS_24_MASTER_WING, 0), 346 UFTDI_DEV(FTDI, CHAMSYS_MAXI_WING, 0), 347 UFTDI_DEV(FTDI, CHAMSYS_MEDIA_WING, 0), 348 UFTDI_DEV(FTDI, CHAMSYS_MIDI_TIMECODE, 0), 349 UFTDI_DEV(FTDI, CHAMSYS_MINI_WING, 0), 350 UFTDI_DEV(FTDI, CHAMSYS_PC_WING, 0), 351 UFTDI_DEV(FTDI, CHAMSYS_USB_DMX, 0), 352 UFTDI_DEV(FTDI, CHAMSYS_WING, 0), 353 UFTDI_DEV(FTDI, COM4SM, 0), 354 UFTDI_DEV(FTDI, CONVERTER_0, 0), 355 UFTDI_DEV(FTDI, CONVERTER_1, 0), 356 UFTDI_DEV(FTDI, CONVERTER_2, 0), 357 UFTDI_DEV(FTDI, CONVERTER_3, 0), 358 UFTDI_DEV(FTDI, CONVERTER_4, 0), 359 UFTDI_DEV(FTDI, CONVERTER_5, 0), 360 UFTDI_DEV(FTDI, CONVERTER_6, 0), 361 UFTDI_DEV(FTDI, CONVERTER_7, 0), 362 UFTDI_DEV(FTDI, CTI_USB_MINI_485, 0), 363 UFTDI_DEV(FTDI, CTI_USB_NANO_485, 0), 364 UFTDI_DEV(FTDI, DMX4ALL, 0), 365 UFTDI_DEV(FTDI, DOMINTELL_DGQG, 0), 366 UFTDI_DEV(FTDI, DOMINTELL_DUSB, 0), 367 UFTDI_DEV(FTDI, DOTEC, 0), 368 UFTDI_DEV(FTDI, ECLO_COM_1WIRE, 0), 369 UFTDI_DEV(FTDI, ECO_PRO_CDS, 0), 370 UFTDI_DEV(FTDI, EISCOU, 0), 371 UFTDI_DEV(FTDI, ELSTER_UNICOM, 0), 372 UFTDI_DEV(FTDI, ELV_ALC8500, 0), 373 UFTDI_DEV(FTDI, ELV_CLI7000, 0), 374 UFTDI_DEV(FTDI, ELV_CSI8, 0), 375 UFTDI_DEV(FTDI, ELV_EC3000, 0), 376 UFTDI_DEV(FTDI, ELV_EM1000DL, 0), 377 UFTDI_DEV(FTDI, ELV_EM1010PC, 0), 378 UFTDI_DEV(FTDI, ELV_FEM, 0), 379 UFTDI_DEV(FTDI, ELV_FHZ1000PC, 0), 380 UFTDI_DEV(FTDI, ELV_FHZ1300PC, 0), 381 UFTDI_DEV(FTDI, ELV_FM3RX, 0), 382 UFTDI_DEV(FTDI, ELV_FS20SIG, 0), 383 UFTDI_DEV(FTDI, ELV_HS485, 0), 384 UFTDI_DEV(FTDI, ELV_KL100, 0), 385 UFTDI_DEV(FTDI, ELV_MSM1, 0), 386 UFTDI_DEV(FTDI, ELV_PCD200, 0), 387 UFTDI_DEV(FTDI, ELV_PCK100, 0), 388 UFTDI_DEV(FTDI, ELV_PPS7330, 0), 389 UFTDI_DEV(FTDI, ELV_RFP500, 0), 390 UFTDI_DEV(FTDI, ELV_T1100, 0), 391 UFTDI_DEV(FTDI, ELV_TFD128, 0), 392 UFTDI_DEV(FTDI, ELV_TFM100, 0), 393 UFTDI_DEV(FTDI, ELV_TWS550, 0), 394 UFTDI_DEV(FTDI, ELV_UAD8, 0), 395 UFTDI_DEV(FTDI, ELV_UDA7, 0), 396 UFTDI_DEV(FTDI, ELV_UDF77, 0), 397 UFTDI_DEV(FTDI, ELV_UIO88, 0), 398 UFTDI_DEV(FTDI, ELV_ULA200, 0), 399 UFTDI_DEV(FTDI, ELV_UM100, 0), 400 UFTDI_DEV(FTDI, ELV_UMS100, 0), 401 UFTDI_DEV(FTDI, ELV_UO100, 0), 402 UFTDI_DEV(FTDI, ELV_UR100, 0), 403 UFTDI_DEV(FTDI, ELV_USI2, 0), 404 UFTDI_DEV(FTDI, ELV_USR, 0), 405 UFTDI_DEV(FTDI, ELV_UTP8, 0), 406 UFTDI_DEV(FTDI, ELV_WS300PC, 0), 407 UFTDI_DEV(FTDI, ELV_WS444PC, 0), 408 UFTDI_DEV(FTDI, ELV_WS500, 0), 409 UFTDI_DEV(FTDI, ELV_WS550, 0), 410 UFTDI_DEV(FTDI, ELV_WS777, 0), 411 UFTDI_DEV(FTDI, ELV_WS888, 0), 412 UFTDI_DEV(FTDI, EMCU2D, 0), 413 UFTDI_DEV(FTDI, EMCU2H, 0), 414 UFTDI_DEV(FTDI, FUTURE_0, 0), 415 UFTDI_DEV(FTDI, FUTURE_1, 0), 416 UFTDI_DEV(FTDI, FUTURE_2, 0), 417 UFTDI_DEV(FTDI, GAMMASCOUT, 0), 418 UFTDI_DEV(FTDI, GENERIC, 0), 419 UFTDI_DEV(FTDI, GUDEADS_E808, 0), 420 UFTDI_DEV(FTDI, GUDEADS_E809, 0), 421 UFTDI_DEV(FTDI, GUDEADS_E80A, 0), 422 UFTDI_DEV(FTDI, GUDEADS_E80B, 0), 423 UFTDI_DEV(FTDI, GUDEADS_E80C, 0), 424 UFTDI_DEV(FTDI, GUDEADS_E80D, 0), 425 UFTDI_DEV(FTDI, GUDEADS_E80E, 0), 426 UFTDI_DEV(FTDI, GUDEADS_E80F, 0), 427 UFTDI_DEV(FTDI, GUDEADS_E88D, 0), 428 UFTDI_DEV(FTDI, GUDEADS_E88E, 0), 429 UFTDI_DEV(FTDI, GUDEADS_E88F, 0), 430 UFTDI_DEV(FTDI, HD_RADIO, 0), 431 UFTDI_DEV(FTDI, HO720, 0), 432 UFTDI_DEV(FTDI, HO730, 0), 433 UFTDI_DEV(FTDI, HO820, 0), 434 UFTDI_DEV(FTDI, HO870, 0), 435 UFTDI_DEV(FTDI, IBS_APP70, 0), 436 UFTDI_DEV(FTDI, IBS_PCMCIA, 0), 437 UFTDI_DEV(FTDI, IBS_PEDO, 0), 438 UFTDI_DEV(FTDI, IBS_PICPRO, 0), 439 UFTDI_DEV(FTDI, IBS_PK1, 0), 440 UFTDI_DEV(FTDI, IBS_PROD, 0), 441 UFTDI_DEV(FTDI, IBS_RS232MON, 0), 442 UFTDI_DEV(FTDI, IBS_US485, 0), 443 UFTDI_DEV(FTDI, IPLUS, 0), 444 UFTDI_DEV(FTDI, IPLUS2, 0), 445 UFTDI_DEV(FTDI, IRTRANS, 0), 446 UFTDI_DEV(FTDI, KBS, 0), 447 UFTDI_DEV(FTDI, KTLINK, 0), 448 UFTDI_DEV(FTDI, LENZ_LIUSB, 0), 449 UFTDI_DEV(FTDI, LK202, 0), 450 UFTDI_DEV(FTDI, LK204, 0), 451 UFTDI_DEV(FTDI, LM3S_DEVEL_BOARD, UFTDI_JTAG_IFACE(0)), 452 UFTDI_DEV(FTDI, LM3S_EVAL_BOARD, UFTDI_JTAG_IFACE(0)), 453 UFTDI_DEV(FTDI, LM3S_ICDI_B_BOARD, UFTDI_JTAG_IFACE(0)), 454 UFTDI_DEV(FTDI, MASTERDEVEL2, 0), 455 UFTDI_DEV(FTDI, MAXSTREAM, 0), 456 UFTDI_DEV(FTDI, MHAM_DB9, 0), 457 UFTDI_DEV(FTDI, MHAM_IC, 0), 458 UFTDI_DEV(FTDI, MHAM_KW, 0), 459 UFTDI_DEV(FTDI, MHAM_RS232, 0), 460 UFTDI_DEV(FTDI, MHAM_Y6, 0), 461 UFTDI_DEV(FTDI, MHAM_Y8, 0), 462 UFTDI_DEV(FTDI, MHAM_Y9, 0), 463 UFTDI_DEV(FTDI, MHAM_YS, 0), 464 UFTDI_DEV(FTDI, MICRO_CHAMELEON, 0), 465 UFTDI_DEV(FTDI, MTXORB_5, 0), 466 UFTDI_DEV(FTDI, MTXORB_6, 0), 467 UFTDI_DEV(FTDI, MX2_3, 0), 468 UFTDI_DEV(FTDI, MX4_5, 0), 469 UFTDI_DEV(FTDI, NXTCAM, 0), 470 UFTDI_DEV(FTDI, OCEANIC, 0), 471 UFTDI_DEV(FTDI, OOCDLINK, UFTDI_JTAG_IFACE(0)), 472 UFTDI_DEV(FTDI, OPENDCC, 0), 473 UFTDI_DEV(FTDI, OPENDCC_GATEWAY, 0), 474 UFTDI_DEV(FTDI, OPENDCC_GBM, 0), 475 UFTDI_DEV(FTDI, OPENDCC_SNIFFER, 0), 476 UFTDI_DEV(FTDI, OPENDCC_THROTTLE, 0), 477 UFTDI_DEV(FTDI, PCDJ_DAC2, 0), 478 UFTDI_DEV(FTDI, PCMSFU, 0), 479 UFTDI_DEV(FTDI, PERLE_ULTRAPORT, 0), 480 UFTDI_DEV(FTDI, PHI_FISCO, 0), 481 UFTDI_DEV(FTDI, PIEGROUP, 0), 482 UFTDI_DEV(FTDI, PROPOX_JTAGCABLEII, 0), 483 UFTDI_DEV(FTDI, R2000KU_TRUE_RNG, 0), 484 UFTDI_DEV(FTDI, R2X0, 0), 485 UFTDI_DEV(FTDI, RELAIS, 0), 486 UFTDI_DEV(FTDI, REU_TINY, 0), 487 UFTDI_DEV(FTDI, RMP200, 0), 488 UFTDI_DEV(FTDI, RM_CANVIEW, 0), 489 UFTDI_DEV(FTDI, RRCIRKITS_LOCOBUFFER, 0), 490 UFTDI_DEV(FTDI, SCIENCESCOPE_HS_LOGBOOK, 0), 491 UFTDI_DEV(FTDI, SCIENCESCOPE_LOGBOOKML, 0), 492 UFTDI_DEV(FTDI, SCIENCESCOPE_LS_LOGBOOK, 0), 493 UFTDI_DEV(FTDI, SCS_DEVICE_0, 0), 494 UFTDI_DEV(FTDI, SCS_DEVICE_1, 0), 495 UFTDI_DEV(FTDI, SCS_DEVICE_2, 0), 496 UFTDI_DEV(FTDI, SCS_DEVICE_3, 0), 497 UFTDI_DEV(FTDI, SCS_DEVICE_4, 0), 498 UFTDI_DEV(FTDI, SCS_DEVICE_5, 0), 499 UFTDI_DEV(FTDI, SCS_DEVICE_6, 0), 500 UFTDI_DEV(FTDI, SCS_DEVICE_7, 0), 501 UFTDI_DEV(FTDI, SCX8_USB_PHOENIX, 0), 502 UFTDI_DEV(FTDI, SDMUSBQSS, 0), 503 UFTDI_DEV(FTDI, SEMC_DSS20, 0), 504 UFTDI_DEV(FTDI, SERIAL_2232C, UFTDI_JTAG_CHECK_STRING), 505 UFTDI_DEV(FTDI, SERIAL_2232D, 0), 506 UFTDI_DEV(FTDI, SERIAL_232RL, 0), 507 UFTDI_DEV(FTDI, SERIAL_4232H, 0), 508 UFTDI_DEV(FTDI, SERIAL_8U100AX, 0), 509 UFTDI_DEV(FTDI, SERIAL_8U232AM, 0), 510 UFTDI_DEV(FTDI, SERIAL_8U232AM4, 0), 511 UFTDI_DEV(FTDI, SIGNALYZER_SH2, UFTDI_JTAG_IFACE(0)), 512 UFTDI_DEV(FTDI, SIGNALYZER_SH4, UFTDI_JTAG_IFACE(0)), 513 UFTDI_DEV(FTDI, SIGNALYZER_SLITE, UFTDI_JTAG_IFACE(0)), 514 UFTDI_DEV(FTDI, SIGNALYZER_ST, UFTDI_JTAG_IFACE(0)), 515 UFTDI_DEV(FTDI, SPECIAL_1, 0), 516 UFTDI_DEV(FTDI, SPECIAL_3, 0), 517 UFTDI_DEV(FTDI, SPECIAL_4, 0), 518 UFTDI_DEV(FTDI, SPROG_II, 0), 519 UFTDI_DEV(FTDI, SR_RADIO, 0), 520 UFTDI_DEV(FTDI, SUUNTO_SPORTS, 0), 521 UFTDI_DEV(FTDI, TACTRIX_OPENPORT_13M, 0), 522 UFTDI_DEV(FTDI, TACTRIX_OPENPORT_13S, 0), 523 UFTDI_DEV(FTDI, TACTRIX_OPENPORT_13U, 0), 524 UFTDI_DEV(FTDI, TAVIR_STK500, 0), 525 UFTDI_DEV(FTDI, TERATRONIK_D2XX, 0), 526 UFTDI_DEV(FTDI, TERATRONIK_VCP, 0), 527 UFTDI_DEV(FTDI, THORLABS, 0), 528 UFTDI_DEV(FTDI, TNC_X, 0), 529 UFTDI_DEV(FTDI, TTUSB, 0), 530 UFTDI_DEV(FTDI, TURTELIZER2, UFTDI_JTAG_IFACE(0)), 531 UFTDI_DEV(FTDI, UOPTBR, 0), 532 UFTDI_DEV(FTDI, USBSERIAL, 0), 533 UFTDI_DEV(FTDI, USBX_707, 0), 534 UFTDI_DEV(FTDI, USB_UIRT, 0), 535 UFTDI_DEV(FTDI, USINT_CAT, 0), 536 UFTDI_DEV(FTDI, USINT_RS232, 0), 537 UFTDI_DEV(FTDI, USINT_WKEY, 0), 538 UFTDI_DEV(FTDI, VARDAAN, 0), 539 UFTDI_DEV(FTDI, VNHCPCUSB_D, 0), 540 UFTDI_DEV(FTDI, WESTREX_MODEL_777, 0), 541 UFTDI_DEV(FTDI, WESTREX_MODEL_8900F, 0), 542 UFTDI_DEV(FTDI, XDS100V2, UFTDI_JTAG_IFACE(0)), 543 UFTDI_DEV(FTDI, XDS100V3, UFTDI_JTAG_IFACE(0)), 544 UFTDI_DEV(FTDI, XF_547, 0), 545 UFTDI_DEV(FTDI, XF_640, 0), 546 UFTDI_DEV(FTDI, XF_642, 0), 547 UFTDI_DEV(FTDI, XM_RADIO, 0), 548 UFTDI_DEV(FTDI, YEI_SERVOCENTER31, 0), 549 UFTDI_DEV(GNOTOMETRICS, USB, 0), 550 UFTDI_DEV(ICOM, SP1, 0), 551 UFTDI_DEV(ICOM, OPC_U_UC, 0), 552 UFTDI_DEV(ICOM, RP2C1, 0), 553 UFTDI_DEV(ICOM, RP2C2, 0), 554 UFTDI_DEV(ICOM, RP2D, 0), 555 UFTDI_DEV(ICOM, RP2KVR, 0), 556 UFTDI_DEV(ICOM, RP2KVT, 0), 557 UFTDI_DEV(ICOM, RP2VR, 0), 558 UFTDI_DEV(ICOM, RP2VT, 0), 559 UFTDI_DEV(ICOM, RP4KVR, 0), 560 UFTDI_DEV(ICOM, RP4KVT, 0), 561 UFTDI_DEV(IDTECH, IDT1221U, 0), 562 UFTDI_DEV(INTERBIOMETRICS, IOBOARD, 0), 563 UFTDI_DEV(INTERBIOMETRICS, MINI_IOBOARD, 0), 564 UFTDI_DEV(INTREPIDCS, NEOVI, 0), 565 UFTDI_DEV(INTREPIDCS, VALUECAN, 0), 566 UFTDI_DEV(IONICS, PLUGCOMPUTER, UFTDI_JTAG_IFACE(0)), 567 UFTDI_DEV(JETI, SPC1201, 0), 568 UFTDI_DEV(KOBIL, CONV_B1, 0), 569 UFTDI_DEV(KOBIL, CONV_KAAN, 0), 570 UFTDI_DEV(LARSENBRUSGAARD, ALTITRACK, 0), 571 UFTDI_DEV(MARVELL, SHEEVAPLUG, 0), 572 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0100, 0), 573 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0101, 0), 574 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0102, 0), 575 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0103, 0), 576 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0104, 0), 577 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0105, 0), 578 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0106, 0), 579 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0107, 0), 580 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0108, 0), 581 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0109, 0), 582 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_010A, 0), 583 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_010B, 0), 584 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_010C, 0), 585 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_010D, 0), 586 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_010E, 0), 587 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_010F, 0), 588 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0110, 0), 589 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0111, 0), 590 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0112, 0), 591 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0113, 0), 592 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0114, 0), 593 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0115, 0), 594 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0116, 0), 595 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0117, 0), 596 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0118, 0), 597 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0119, 0), 598 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_011A, 0), 599 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_011B, 0), 600 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_011C, 0), 601 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_011D, 0), 602 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_011E, 0), 603 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_011F, 0), 604 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0120, 0), 605 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0121, 0), 606 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0122, 0), 607 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0123, 0), 608 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0124, 0), 609 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0125, 0), 610 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0126, 0), 611 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0128, 0), 612 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0129, 0), 613 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_012A, 0), 614 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_012B, 0), 615 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_012D, 0), 616 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_012E, 0), 617 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_012F, 0), 618 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0130, 0), 619 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0131, 0), 620 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0132, 0), 621 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0133, 0), 622 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0134, 0), 623 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0135, 0), 624 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0136, 0), 625 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0137, 0), 626 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0138, 0), 627 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0139, 0), 628 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_013A, 0), 629 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_013B, 0), 630 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_013C, 0), 631 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_013D, 0), 632 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_013E, 0), 633 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_013F, 0), 634 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0140, 0), 635 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0141, 0), 636 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0142, 0), 637 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0143, 0), 638 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0144, 0), 639 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0145, 0), 640 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0146, 0), 641 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0147, 0), 642 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0148, 0), 643 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0149, 0), 644 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_014A, 0), 645 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_014B, 0), 646 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_014C, 0), 647 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_014D, 0), 648 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_014E, 0), 649 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_014F, 0), 650 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0150, 0), 651 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0151, 0), 652 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0152, 0), 653 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0159, 0), 654 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_015A, 0), 655 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_015B, 0), 656 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_015C, 0), 657 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_015D, 0), 658 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_015E, 0), 659 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_015F, 0), 660 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0160, 0), 661 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0161, 0), 662 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0162, 0), 663 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0163, 0), 664 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0164, 0), 665 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0165, 0), 666 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0166, 0), 667 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0167, 0), 668 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0168, 0), 669 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0169, 0), 670 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_016A, 0), 671 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_016B, 0), 672 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_016C, 0), 673 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_016D, 0), 674 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_016E, 0), 675 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_016F, 0), 676 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0170, 0), 677 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0171, 0), 678 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0172, 0), 679 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0173, 0), 680 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0174, 0), 681 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0175, 0), 682 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0176, 0), 683 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0177, 0), 684 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0178, 0), 685 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0179, 0), 686 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_017A, 0), 687 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_017B, 0), 688 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_017C, 0), 689 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_017D, 0), 690 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_017E, 0), 691 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_017F, 0), 692 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0180, 0), 693 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0181, 0), 694 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0182, 0), 695 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0183, 0), 696 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0184, 0), 697 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0185, 0), 698 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0186, 0), 699 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0187, 0), 700 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0188, 0), 701 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0189, 0), 702 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_018A, 0), 703 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_018B, 0), 704 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_018C, 0), 705 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_018D, 0), 706 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_018E, 0), 707 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_018F, 0), 708 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0190, 0), 709 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0191, 0), 710 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0192, 0), 711 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0193, 0), 712 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0194, 0), 713 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0195, 0), 714 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0196, 0), 715 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0197, 0), 716 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0198, 0), 717 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0199, 0), 718 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_019A, 0), 719 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_019B, 0), 720 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_019C, 0), 721 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_019D, 0), 722 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_019E, 0), 723 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_019F, 0), 724 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01A0, 0), 725 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01A1, 0), 726 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01A2, 0), 727 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01A3, 0), 728 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01A4, 0), 729 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01A5, 0), 730 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01A6, 0), 731 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01A7, 0), 732 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01A8, 0), 733 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01A9, 0), 734 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01AA, 0), 735 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01AB, 0), 736 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01AC, 0), 737 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01AD, 0), 738 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01AE, 0), 739 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01AF, 0), 740 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01B0, 0), 741 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01B1, 0), 742 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01B2, 0), 743 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01B3, 0), 744 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01B4, 0), 745 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01B5, 0), 746 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01B6, 0), 747 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01B7, 0), 748 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01B8, 0), 749 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01B9, 0), 750 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01BA, 0), 751 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01BB, 0), 752 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01BC, 0), 753 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01BD, 0), 754 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01BE, 0), 755 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01BF, 0), 756 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01C0, 0), 757 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01C1, 0), 758 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01C2, 0), 759 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01C3, 0), 760 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01C4, 0), 761 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01C5, 0), 762 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01C6, 0), 763 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01C7, 0), 764 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01C8, 0), 765 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01C9, 0), 766 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01CA, 0), 767 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01CB, 0), 768 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01CC, 0), 769 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01CD, 0), 770 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01CE, 0), 771 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01CF, 0), 772 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01D0, 0), 773 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01D1, 0), 774 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01D2, 0), 775 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01D3, 0), 776 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01D4, 0), 777 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01D5, 0), 778 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01D6, 0), 779 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01D7, 0), 780 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01D8, 0), 781 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01D9, 0), 782 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01DA, 0), 783 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01DB, 0), 784 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01DC, 0), 785 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01DD, 0), 786 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01DE, 0), 787 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01DF, 0), 788 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01E0, 0), 789 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01E1, 0), 790 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01E2, 0), 791 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01E3, 0), 792 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01E4, 0), 793 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01E5, 0), 794 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01E6, 0), 795 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01E7, 0), 796 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01E8, 0), 797 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01E9, 0), 798 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01EA, 0), 799 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01EB, 0), 800 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01EC, 0), 801 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01ED, 0), 802 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01EE, 0), 803 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01EF, 0), 804 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01F0, 0), 805 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01F1, 0), 806 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01F2, 0), 807 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01F3, 0), 808 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01F4, 0), 809 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01F5, 0), 810 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01F6, 0), 811 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01F7, 0), 812 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01F8, 0), 813 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01F9, 0), 814 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01FA, 0), 815 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01FB, 0), 816 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01FC, 0), 817 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01FD, 0), 818 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01FE, 0), 819 UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_01FF, 0), 820 UFTDI_DEV(MATRIXORBITAL, MOUA, 0), 821 UFTDI_DEV(MELCO, PCOPRS1, 0), 822 UFTDI_DEV(METAGEEK, TELLSTICK, 0), 823 UFTDI_DEV(MOBILITY, USB_SERIAL, 0), 824 UFTDI_DEV(OLIMEX, ARM_USB_OCD, UFTDI_JTAG_IFACE(0)), 825 UFTDI_DEV(OLIMEX, ARM_USB_OCD_H, UFTDI_JTAG_IFACE(0)), 826 UFTDI_DEV(OPTO, CRD7734, 0), 827 UFTDI_DEV(OPTO, CRD7734_1, 0), 828 UFTDI_DEV(PAPOUCH, AD4USB, 0), 829 UFTDI_DEV(PAPOUCH, AP485, 0), 830 UFTDI_DEV(PAPOUCH, AP485_2, 0), 831 UFTDI_DEV(PAPOUCH, DRAK5, 0), 832 UFTDI_DEV(PAPOUCH, DRAK6, 0), 833 UFTDI_DEV(PAPOUCH, GMSR, 0), 834 UFTDI_DEV(PAPOUCH, GMUX, 0), 835 UFTDI_DEV(PAPOUCH, IRAMP, 0), 836 UFTDI_DEV(PAPOUCH, LEC, 0), 837 UFTDI_DEV(PAPOUCH, MU, 0), 838 UFTDI_DEV(PAPOUCH, QUIDO10X1, 0), 839 UFTDI_DEV(PAPOUCH, QUIDO2X16, 0), 840 UFTDI_DEV(PAPOUCH, QUIDO2X2, 0), 841 UFTDI_DEV(PAPOUCH, QUIDO30X3, 0), 842 UFTDI_DEV(PAPOUCH, QUIDO3X32, 0), 843 UFTDI_DEV(PAPOUCH, QUIDO4X4, 0), 844 UFTDI_DEV(PAPOUCH, QUIDO60X3, 0), 845 UFTDI_DEV(PAPOUCH, QUIDO8X8, 0), 846 UFTDI_DEV(PAPOUCH, SB232, 0), 847 UFTDI_DEV(PAPOUCH, SB422, 0), 848 UFTDI_DEV(PAPOUCH, SB422_2, 0), 849 UFTDI_DEV(PAPOUCH, SB485, 0), 850 UFTDI_DEV(PAPOUCH, SB485C, 0), 851 UFTDI_DEV(PAPOUCH, SB485S, 0), 852 UFTDI_DEV(PAPOUCH, SB485_2, 0), 853 UFTDI_DEV(PAPOUCH, SIMUKEY, 0), 854 UFTDI_DEV(PAPOUCH, TMU, 0), 855 UFTDI_DEV(PAPOUCH, UPSUSB, 0), 856 UFTDI_DEV(POSIFLEX, PP7000, 0), 857 UFTDI_DEV(QIHARDWARE, JTAGSERIAL, UFTDI_JTAG_IFACE(0)), 858 UFTDI_DEV(RATOC, REXUSB60F, 0), 859 UFTDI_DEV(RTSYSTEMS, CT29B, 0), 860 UFTDI_DEV(RTSYSTEMS, SERIAL_VX7, 0), 861 UFTDI_DEV(SEALEVEL, 2101, 0), 862 UFTDI_DEV(SEALEVEL, 2102, 0), 863 UFTDI_DEV(SEALEVEL, 2103, 0), 864 UFTDI_DEV(SEALEVEL, 2104, 0), 865 UFTDI_DEV(SEALEVEL, 2106, 0), 866 UFTDI_DEV(SEALEVEL, 2201_1, 0), 867 UFTDI_DEV(SEALEVEL, 2201_2, 0), 868 UFTDI_DEV(SEALEVEL, 2202_1, 0), 869 UFTDI_DEV(SEALEVEL, 2202_2, 0), 870 UFTDI_DEV(SEALEVEL, 2203_1, 0), 871 UFTDI_DEV(SEALEVEL, 2203_2, 0), 872 UFTDI_DEV(SEALEVEL, 2401_1, 0), 873 UFTDI_DEV(SEALEVEL, 2401_2, 0), 874 UFTDI_DEV(SEALEVEL, 2401_3, 0), 875 UFTDI_DEV(SEALEVEL, 2401_4, 0), 876 UFTDI_DEV(SEALEVEL, 2402_1, 0), 877 UFTDI_DEV(SEALEVEL, 2402_2, 0), 878 UFTDI_DEV(SEALEVEL, 2402_3, 0), 879 UFTDI_DEV(SEALEVEL, 2402_4, 0), 880 UFTDI_DEV(SEALEVEL, 2403_1, 0), 881 UFTDI_DEV(SEALEVEL, 2403_2, 0), 882 UFTDI_DEV(SEALEVEL, 2403_3, 0), 883 UFTDI_DEV(SEALEVEL, 2403_4, 0), 884 UFTDI_DEV(SEALEVEL, 2801_1, 0), 885 UFTDI_DEV(SEALEVEL, 2801_2, 0), 886 UFTDI_DEV(SEALEVEL, 2801_3, 0), 887 UFTDI_DEV(SEALEVEL, 2801_4, 0), 888 UFTDI_DEV(SEALEVEL, 2801_5, 0), 889 UFTDI_DEV(SEALEVEL, 2801_6, 0), 890 UFTDI_DEV(SEALEVEL, 2801_7, 0), 891 UFTDI_DEV(SEALEVEL, 2801_8, 0), 892 UFTDI_DEV(SEALEVEL, 2802_1, 0), 893 UFTDI_DEV(SEALEVEL, 2802_2, 0), 894 UFTDI_DEV(SEALEVEL, 2802_3, 0), 895 UFTDI_DEV(SEALEVEL, 2802_4, 0), 896 UFTDI_DEV(SEALEVEL, 2802_5, 0), 897 UFTDI_DEV(SEALEVEL, 2802_6, 0), 898 UFTDI_DEV(SEALEVEL, 2802_7, 0), 899 UFTDI_DEV(SEALEVEL, 2802_8, 0), 900 UFTDI_DEV(SEALEVEL, 2803_1, 0), 901 UFTDI_DEV(SEALEVEL, 2803_2, 0), 902 UFTDI_DEV(SEALEVEL, 2803_3, 0), 903 UFTDI_DEV(SEALEVEL, 2803_4, 0), 904 UFTDI_DEV(SEALEVEL, 2803_5, 0), 905 UFTDI_DEV(SEALEVEL, 2803_6, 0), 906 UFTDI_DEV(SEALEVEL, 2803_7, 0), 907 UFTDI_DEV(SEALEVEL, 2803_8, 0), 908 UFTDI_DEV(SIIG2, DK201, 0), 909 UFTDI_DEV(SIIG2, US2308, 0), 910 UFTDI_DEV(TESTO, USB_INTERFACE, 0), 911 UFTDI_DEV(TML, USB_SERIAL, 0), 912 UFTDI_DEV(TTI, QL355P, 0), 913 UFTDI_DEV(UNKNOWN4, NF_RIC, 0), 914 #undef UFTDI_DEV 915 }; 916 917 /* 918 * Jtag product name strings table. Some products have one or more interfaces 919 * dedicated to jtag or gpio, but use a product ID that's the same as other 920 * products which don't. They are marked with a flag in the table above, and 921 * the following string table is checked for flagged products. The string check 922 * is done with strstr(); in effect there is an implicit wildcard at the 923 * beginning and end of each product name string in table. 924 */ 925 static const struct jtag_by_name { 926 const char * product_name; 927 uint32_t jtag_interfaces; 928 } jtag_products_by_name[] = { 929 /* TI Beaglebone and TI XDS100Vn jtag product line. */ 930 {"XDS100V", UFTDI_JTAG_IFACE(0)}, 931 }; 932 933 /* 934 * Set up a sysctl and tunable to en/disable the feature of skipping the 935 * creation of tty devices for jtag interfaces. Enabled by default. 936 */ 937 static int skip_jtag_interfaces = 1; 938 SYSCTL_INT(_hw_usb_uftdi, OID_AUTO, skip_jtag_interfaces, CTLFLAG_RWTUN, 939 &skip_jtag_interfaces, 1, "Skip creating tty devices for jtag interfaces"); 940 941 static boolean_t 942 is_jtag_interface(struct usb_attach_arg *uaa, const struct usb_device_id *id) 943 { 944 int i, iface_bit; 945 const char * product_name; 946 const struct jtag_by_name *jbn; 947 948 /* We only allocate 8 flag bits for jtag interface flags. */ 949 if (uaa->info.bIfaceIndex >= UFTDI_JTAG_IFACES_MAX) 950 return (0); 951 iface_bit = UFTDI_JTAG_IFACE(uaa->info.bIfaceIndex); 952 953 /* 954 * If requested, search the name strings table and use the interface 955 * bits from that table when the product name string matches, else use 956 * the jtag interface bits from the main ID table. 957 */ 958 if ((id->driver_info & UFTDI_JTAG_MASK) == UFTDI_JTAG_CHECK_STRING) { 959 product_name = usb_get_product(uaa->device); 960 for (i = 0; i < nitems(jtag_products_by_name); i++) { 961 jbn = &jtag_products_by_name[i]; 962 if (strstr(product_name, jbn->product_name) != NULL && 963 (jbn->jtag_interfaces & iface_bit) != 0) 964 return (1); 965 } 966 } else if ((id->driver_info & iface_bit) != 0) 967 return (1); 968 969 return (0); 970 } 971 972 /* 973 * Set up softc fields whose value depends on the device type. 974 * 975 * Note that the 2232C and 2232D devices are the same for our purposes. In the 976 * silicon the difference is that the D series has CPU FIFO mode and C doesn't. 977 * I haven't found any way of determining the C/D difference from info provided 978 * by the chip other than trying to set CPU FIFO mode and having it work or not. 979 * 980 * Due to a hardware bug, a 232B chip without an eeprom reports itself as a 981 * 232A, but if the serial number is also zero we know it's really a 232B. 982 */ 983 static void 984 uftdi_devtype_setup(struct uftdi_softc *sc, struct usb_attach_arg *uaa) 985 { 986 struct usb_device_descriptor *dd; 987 988 sc->sc_bcdDevice = uaa->info.bcdDevice; 989 990 switch (uaa->info.bcdDevice) { 991 case 0x200: 992 dd = usbd_get_device_descriptor(sc->sc_udev); 993 if (dd->iSerialNumber == 0) { 994 sc->sc_devtype = DEVT_232B; 995 } else { 996 sc->sc_devtype = DEVT_232A; 997 } 998 sc->sc_ucom.sc_portno = 0; 999 break; 1000 case 0x400: 1001 sc->sc_devtype = DEVT_232B; 1002 sc->sc_ucom.sc_portno = 0; 1003 break; 1004 case 0x500: 1005 sc->sc_devtype = DEVT_2232D; 1006 sc->sc_devflags |= DEVF_BAUDBITS_HINDEX; 1007 sc->sc_ucom.sc_portno = FTDI_PIT_SIOA + uaa->info.bIfaceNum; 1008 break; 1009 case 0x600: 1010 sc->sc_devtype = DEVT_232R; 1011 sc->sc_ucom.sc_portno = 0; 1012 break; 1013 case 0x700: 1014 sc->sc_devtype = DEVT_2232H; 1015 sc->sc_devflags |= DEVF_BAUDBITS_HINDEX | DEVF_BAUDCLK_12M; 1016 sc->sc_ucom.sc_portno = FTDI_PIT_SIOA + uaa->info.bIfaceNum; 1017 break; 1018 case 0x800: 1019 sc->sc_devtype = DEVT_4232H; 1020 sc->sc_devflags |= DEVF_BAUDBITS_HINDEX | DEVF_BAUDCLK_12M; 1021 sc->sc_ucom.sc_portno = FTDI_PIT_SIOA + uaa->info.bIfaceNum; 1022 break; 1023 case 0x900: 1024 sc->sc_devtype = DEVT_232H; 1025 sc->sc_devflags |= DEVF_BAUDBITS_HINDEX | DEVF_BAUDCLK_12M; 1026 sc->sc_ucom.sc_portno = FTDI_PIT_SIOA + uaa->info.bIfaceNum; 1027 break; 1028 case 0x1000: 1029 sc->sc_devtype = DEVT_230X; 1030 sc->sc_devflags |= DEVF_BAUDBITS_HINDEX; 1031 sc->sc_ucom.sc_portno = FTDI_PIT_SIOA + uaa->info.bIfaceNum; 1032 break; 1033 default: 1034 if (uaa->info.bcdDevice < 0x200) { 1035 sc->sc_devtype = DEVT_SIO; 1036 sc->sc_hdrlen = 1; 1037 } else { 1038 sc->sc_devtype = DEVT_232R; 1039 device_printf(sc->sc_dev, "Warning: unknown FTDI " 1040 "device type, bcdDevice=0x%04x, assuming 232R\n", 1041 uaa->info.bcdDevice); 1042 } 1043 sc->sc_ucom.sc_portno = 0; 1044 break; 1045 } 1046 } 1047 1048 static int 1049 uftdi_probe(device_t dev) 1050 { 1051 struct usb_attach_arg *uaa = device_get_ivars(dev); 1052 const struct usb_device_id *id; 1053 1054 if (uaa->usb_mode != USB_MODE_HOST) { 1055 return (ENXIO); 1056 } 1057 if (uaa->info.bConfigIndex != UFTDI_CONFIG_INDEX) { 1058 return (ENXIO); 1059 } 1060 1061 /* 1062 * Attach to all present interfaces unless this is a JTAG one, which 1063 * we leave for userland. 1064 */ 1065 id = usbd_lookup_id_by_info(uftdi_devs, sizeof(uftdi_devs), 1066 &uaa->info); 1067 if (id == NULL) 1068 return (ENXIO); 1069 if (skip_jtag_interfaces && is_jtag_interface(uaa, id)) { 1070 printf("%s: skipping JTAG interface #%d for '%s' at %u.%u\n", 1071 device_get_name(dev), 1072 uaa->info.bIfaceIndex, 1073 usb_get_product(uaa->device), 1074 usbd_get_bus_index(uaa->device), 1075 usbd_get_device_index(uaa->device)); 1076 return (ENXIO); 1077 } 1078 uaa->driver_info = id->driver_info; 1079 return (BUS_PROBE_SPECIFIC); 1080 } 1081 1082 static int 1083 uftdi_attach(device_t dev) 1084 { 1085 struct usb_attach_arg *uaa = device_get_ivars(dev); 1086 struct uftdi_softc *sc = device_get_softc(dev); 1087 int error; 1088 1089 DPRINTF("\n"); 1090 1091 sc->sc_udev = uaa->device; 1092 sc->sc_dev = dev; 1093 sc->sc_unit = device_get_unit(dev); 1094 sc->sc_bitmode = UFTDI_BITMODE_NONE; 1095 1096 device_set_usb_desc(dev); 1097 mtx_init(&sc->sc_mtx, "uftdi", NULL, MTX_DEF); 1098 ucom_ref(&sc->sc_super_ucom); 1099 1100 1101 uftdi_devtype_setup(sc, uaa); 1102 1103 error = usbd_transfer_setup(uaa->device, 1104 &uaa->info.bIfaceIndex, sc->sc_xfer, uftdi_config, 1105 UFTDI_N_TRANSFER, sc, &sc->sc_mtx); 1106 1107 if (error) { 1108 device_printf(dev, "allocating USB " 1109 "transfers failed\n"); 1110 goto detach; 1111 } 1112 /* clear stall at first run */ 1113 mtx_lock(&sc->sc_mtx); 1114 usbd_xfer_set_stall(sc->sc_xfer[UFTDI_BULK_DT_WR]); 1115 usbd_xfer_set_stall(sc->sc_xfer[UFTDI_BULK_DT_RD]); 1116 mtx_unlock(&sc->sc_mtx); 1117 1118 /* set a valid "lcr" value */ 1119 1120 sc->sc_last_lcr = 1121 (FTDI_SIO_SET_DATA_STOP_BITS_2 | 1122 FTDI_SIO_SET_DATA_PARITY_NONE | 1123 FTDI_SIO_SET_DATA_BITS(8)); 1124 1125 error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc, 1126 &uftdi_callback, &sc->sc_mtx); 1127 if (error) { 1128 goto detach; 1129 } 1130 ucom_set_pnpinfo_usb(&sc->sc_super_ucom, dev); 1131 1132 return (0); /* success */ 1133 1134 detach: 1135 uftdi_detach(dev); 1136 return (ENXIO); 1137 } 1138 1139 static int 1140 uftdi_detach(device_t dev) 1141 { 1142 struct uftdi_softc *sc = device_get_softc(dev); 1143 1144 ucom_detach(&sc->sc_super_ucom, &sc->sc_ucom); 1145 usbd_transfer_unsetup(sc->sc_xfer, UFTDI_N_TRANSFER); 1146 1147 device_claim_softc(dev); 1148 1149 uftdi_free_softc(sc); 1150 1151 return (0); 1152 } 1153 1154 UCOM_UNLOAD_DRAIN(uftdi); 1155 1156 static void 1157 uftdi_free_softc(struct uftdi_softc *sc) 1158 { 1159 if (ucom_unref(&sc->sc_super_ucom)) { 1160 mtx_destroy(&sc->sc_mtx); 1161 device_free_softc(sc); 1162 } 1163 } 1164 1165 static void 1166 uftdi_free(struct ucom_softc *ucom) 1167 { 1168 uftdi_free_softc(ucom->sc_parent); 1169 } 1170 1171 static void 1172 uftdi_cfg_open(struct ucom_softc *ucom) 1173 { 1174 1175 /* 1176 * This do-nothing open routine exists for the sole purpose of this 1177 * DPRINTF() so that you can see the point at which open gets called 1178 * when debugging is enabled. 1179 */ 1180 DPRINTF(""); 1181 } 1182 1183 static void 1184 uftdi_cfg_close(struct ucom_softc *ucom) 1185 { 1186 1187 /* 1188 * This do-nothing close routine exists for the sole purpose of this 1189 * DPRINTF() so that you can see the point at which close gets called 1190 * when debugging is enabled. 1191 */ 1192 DPRINTF(""); 1193 } 1194 1195 static void 1196 uftdi_write_callback(struct usb_xfer *xfer, usb_error_t error) 1197 { 1198 struct uftdi_softc *sc = usbd_xfer_softc(xfer); 1199 struct usb_page_cache *pc; 1200 uint32_t pktlen; 1201 uint32_t buflen; 1202 uint8_t buf[1]; 1203 1204 switch (USB_GET_STATE(xfer)) { 1205 default: /* Error */ 1206 if (error != USB_ERR_CANCELLED) { 1207 /* try to clear stall first */ 1208 usbd_xfer_set_stall(xfer); 1209 } 1210 /* FALLTHROUGH */ 1211 case USB_ST_SETUP: 1212 case USB_ST_TRANSFERRED: 1213 /* 1214 * If output packets don't require headers (the common case) we 1215 * can just load the buffer up with payload bytes all at once. 1216 * Otherwise, loop to format packets into the buffer while there 1217 * is data available, and room for a packet header and at least 1218 * one byte of payload. 1219 * 1220 * NOTE: The FTDI chip doesn't accept zero length 1221 * packets. This cannot happen because the "pktlen" 1222 * will always be non-zero when "ucom_get_data()" 1223 * returns non-zero which we check below. 1224 */ 1225 pc = usbd_xfer_get_frame(xfer, 0); 1226 if (sc->sc_hdrlen == 0) { 1227 if (ucom_get_data(&sc->sc_ucom, pc, 0, UFTDI_OBUFSIZE, 1228 &buflen) == 0) 1229 break; 1230 } else { 1231 buflen = 0; 1232 while (buflen < UFTDI_OBUFSIZE - sc->sc_hdrlen - 1 && 1233 ucom_get_data(&sc->sc_ucom, pc, buflen + 1234 sc->sc_hdrlen, UFTDI_OPKTSIZE - sc->sc_hdrlen, 1235 &pktlen) != 0) { 1236 buf[0] = FTDI_OUT_TAG(pktlen, 1237 sc->sc_ucom.sc_portno); 1238 usbd_copy_in(pc, buflen, buf, 1); 1239 buflen += pktlen + sc->sc_hdrlen; 1240 } 1241 } 1242 if (buflen != 0) { 1243 usbd_xfer_set_frame_len(xfer, 0, buflen); 1244 usbd_transfer_submit(xfer); 1245 } 1246 break; 1247 } 1248 } 1249 1250 static void 1251 uftdi_read_callback(struct usb_xfer *xfer, usb_error_t error) 1252 { 1253 struct uftdi_softc *sc = usbd_xfer_softc(xfer); 1254 struct usb_page_cache *pc; 1255 uint8_t buf[2]; 1256 uint8_t ftdi_msr; 1257 uint8_t msr; 1258 uint8_t lsr; 1259 int buflen; 1260 int pktlen; 1261 int pktmax; 1262 int offset; 1263 1264 usbd_xfer_status(xfer, &buflen, NULL, NULL, NULL); 1265 1266 switch (USB_GET_STATE(xfer)) { 1267 case USB_ST_TRANSFERRED: 1268 if (buflen < UFTDI_IHDRSIZE) 1269 goto tr_setup; 1270 pc = usbd_xfer_get_frame(xfer, 0); 1271 pktmax = xfer->max_packet_size - UFTDI_IHDRSIZE; 1272 lsr = 0; 1273 msr = 0; 1274 offset = 0; 1275 /* 1276 * Extract packet headers and payload bytes from the buffer. 1277 * Feed payload bytes to ucom/tty layer; OR-accumulate header 1278 * status bits which are transient and could toggle with each 1279 * packet. After processing all packets in the buffer, process 1280 * the accumulated transient MSR and LSR values along with the 1281 * non-transient bits from the last packet header. 1282 */ 1283 while (buflen >= UFTDI_IHDRSIZE) { 1284 usbd_copy_out(pc, offset, buf, UFTDI_IHDRSIZE); 1285 offset += UFTDI_IHDRSIZE; 1286 buflen -= UFTDI_IHDRSIZE; 1287 lsr |= FTDI_GET_LSR(buf); 1288 if (FTDI_GET_MSR(buf) & FTDI_SIO_RI_MASK) 1289 msr |= SER_RI; 1290 pktlen = min(buflen, pktmax); 1291 if (pktlen != 0) { 1292 ucom_put_data(&sc->sc_ucom, pc, offset, 1293 pktlen); 1294 offset += pktlen; 1295 buflen -= pktlen; 1296 } 1297 } 1298 ftdi_msr = FTDI_GET_MSR(buf); 1299 1300 if (ftdi_msr & FTDI_SIO_CTS_MASK) 1301 msr |= SER_CTS; 1302 if (ftdi_msr & FTDI_SIO_DSR_MASK) 1303 msr |= SER_DSR; 1304 if (ftdi_msr & FTDI_SIO_RI_MASK) 1305 msr |= SER_RI; 1306 if (ftdi_msr & FTDI_SIO_RLSD_MASK) 1307 msr |= SER_DCD; 1308 1309 if ((sc->sc_msr != msr) || 1310 ((sc->sc_lsr & FTDI_LSR_MASK) != (lsr & FTDI_LSR_MASK))) { 1311 DPRINTF("status change msr=0x%02x (0x%02x) " 1312 "lsr=0x%02x (0x%02x)\n", msr, sc->sc_msr, 1313 lsr, sc->sc_lsr); 1314 1315 sc->sc_msr = msr; 1316 sc->sc_lsr = lsr; 1317 1318 ucom_status_change(&sc->sc_ucom); 1319 } 1320 /* FALLTHROUGH */ 1321 case USB_ST_SETUP: 1322 tr_setup: 1323 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer)); 1324 usbd_transfer_submit(xfer); 1325 return; 1326 1327 default: /* Error */ 1328 if (error != USB_ERR_CANCELLED) { 1329 /* try to clear stall first */ 1330 usbd_xfer_set_stall(xfer); 1331 goto tr_setup; 1332 } 1333 return; 1334 } 1335 } 1336 1337 static void 1338 uftdi_cfg_set_dtr(struct ucom_softc *ucom, uint8_t onoff) 1339 { 1340 struct uftdi_softc *sc = ucom->sc_parent; 1341 uint16_t wIndex = ucom->sc_portno; 1342 uint16_t wValue; 1343 struct usb_device_request req; 1344 1345 wValue = onoff ? FTDI_SIO_SET_DTR_HIGH : FTDI_SIO_SET_DTR_LOW; 1346 1347 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1348 req.bRequest = FTDI_SIO_MODEM_CTRL; 1349 USETW(req.wValue, wValue); 1350 USETW(req.wIndex, wIndex); 1351 USETW(req.wLength, 0); 1352 ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 1353 &req, NULL, 0, 1000); 1354 } 1355 1356 static void 1357 uftdi_cfg_set_rts(struct ucom_softc *ucom, uint8_t onoff) 1358 { 1359 struct uftdi_softc *sc = ucom->sc_parent; 1360 uint16_t wIndex = ucom->sc_portno; 1361 uint16_t wValue; 1362 struct usb_device_request req; 1363 1364 wValue = onoff ? FTDI_SIO_SET_RTS_HIGH : FTDI_SIO_SET_RTS_LOW; 1365 1366 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1367 req.bRequest = FTDI_SIO_MODEM_CTRL; 1368 USETW(req.wValue, wValue); 1369 USETW(req.wIndex, wIndex); 1370 USETW(req.wLength, 0); 1371 ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 1372 &req, NULL, 0, 1000); 1373 } 1374 1375 static void 1376 uftdi_cfg_set_break(struct ucom_softc *ucom, uint8_t onoff) 1377 { 1378 struct uftdi_softc *sc = ucom->sc_parent; 1379 uint16_t wIndex = ucom->sc_portno; 1380 uint16_t wValue; 1381 struct usb_device_request req; 1382 1383 if (onoff) { 1384 sc->sc_last_lcr |= FTDI_SIO_SET_BREAK; 1385 } else { 1386 sc->sc_last_lcr &= ~FTDI_SIO_SET_BREAK; 1387 } 1388 1389 wValue = sc->sc_last_lcr; 1390 1391 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1392 req.bRequest = FTDI_SIO_SET_DATA; 1393 USETW(req.wValue, wValue); 1394 USETW(req.wIndex, wIndex); 1395 USETW(req.wLength, 0); 1396 ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 1397 &req, NULL, 0, 1000); 1398 } 1399 1400 /* 1401 * Return true if the given speed is within operational tolerance of the target 1402 * speed. FTDI recommends that the hardware speed be within 3% of nominal. 1403 */ 1404 static inline boolean_t 1405 uftdi_baud_within_tolerance(uint64_t speed, uint64_t target) 1406 { 1407 return ((speed >= (target * 100) / 103) && 1408 (speed <= (target * 100) / 97)); 1409 } 1410 1411 static int 1412 uftdi_sio_encode_baudrate(struct uftdi_softc *sc, speed_t speed, 1413 struct uftdi_param_config *cfg) 1414 { 1415 u_int i; 1416 const speed_t sio_speeds[] = { 1417 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200 1418 }; 1419 1420 /* 1421 * The original SIO chips were limited to a small choice of speeds 1422 * listed in an internal table of speeds chosen by an index value. 1423 */ 1424 for (i = 0; i < nitems(sio_speeds); ++i) { 1425 if (speed == sio_speeds[i]) { 1426 cfg->baud_lobits = i; 1427 cfg->baud_hibits = 0; 1428 return (0); 1429 } 1430 } 1431 return (ERANGE); 1432 } 1433 1434 static int 1435 uftdi_encode_baudrate(struct uftdi_softc *sc, speed_t speed, 1436 struct uftdi_param_config *cfg) 1437 { 1438 static const uint8_t encoded_fraction[8] = {0, 3, 2, 4, 1, 5, 6, 7}; 1439 static const uint8_t roundoff_232a[16] = { 1440 0, 1, 0, 1, 0, -1, 2, 1, 1441 0, -1, -2, -3, 4, 3, 2, 1, 1442 }; 1443 uint32_t clk, divisor, fastclk_flag, frac, hwspeed; 1444 1445 /* 1446 * If this chip has the fast clock capability and the speed is within 1447 * range, use the 12MHz clock, otherwise the standard clock is 3MHz. 1448 */ 1449 if ((sc->sc_devflags & DEVF_BAUDCLK_12M) && speed >= 1200) { 1450 clk = 12000000; 1451 fastclk_flag = (1 << 17); 1452 } else { 1453 clk = 3000000; 1454 fastclk_flag = 0; 1455 } 1456 1457 /* 1458 * Make sure the requested speed is reachable with the available clock 1459 * and a 14-bit divisor. 1460 */ 1461 if (speed < (clk >> 14) || speed > clk) 1462 return (ERANGE); 1463 1464 /* 1465 * Calculate the divisor, initially yielding a fixed point number with a 1466 * 4-bit (1/16ths) fraction, then round it to the nearest fraction the 1467 * hardware can handle. When the integral part of the divisor is 1468 * greater than one, the fractional part is in 1/8ths of the base clock. 1469 * The FT8U232AM chips can handle only 0.125, 0.250, and 0.5 fractions. 1470 * Later chips can handle all 1/8th fractions. 1471 * 1472 * If the integral part of the divisor is 1, a special rule applies: the 1473 * fractional part can only be .0 or .5 (this is a limitation of the 1474 * hardware). We handle this by truncating the fraction rather than 1475 * rounding, because this only applies to the two fastest speeds the 1476 * chip can achieve and rounding doesn't matter, either you've asked for 1477 * that exact speed or you've asked for something the chip can't do. 1478 * 1479 * For the FT8U232AM chips, use a roundoff table to adjust the result 1480 * to the nearest 1/8th fraction that is supported by the hardware, 1481 * leaving a fixed-point number with a 3-bit fraction which exactly 1482 * represents the math the hardware divider will do. For later-series 1483 * chips that support all 8 fractional divisors, just round 16ths to 1484 * 8ths by adding 1 and dividing by 2. 1485 */ 1486 divisor = (clk << 4) / speed; 1487 if ((divisor & 0xf) == 1) 1488 divisor &= 0xfffffff8; 1489 else if (sc->sc_devtype == DEVT_232A) 1490 divisor += roundoff_232a[divisor & 0x0f]; 1491 else 1492 divisor += 1; /* Rounds odd 16ths up to next 8th. */ 1493 divisor >>= 1; 1494 1495 /* 1496 * Ensure the resulting hardware speed will be within operational 1497 * tolerance (within 3% of nominal). 1498 */ 1499 hwspeed = (clk << 3) / divisor; 1500 if (!uftdi_baud_within_tolerance(hwspeed, speed)) 1501 return (ERANGE); 1502 1503 /* 1504 * Re-pack the divisor into hardware format. The lower 14-bits hold the 1505 * integral part, while the upper bits specify the fraction by indexing 1506 * a table of fractions within the hardware which is laid out as: 1507 * {0.0, 0.5, 0.25, 0.125, 0.325, 0.625, 0.725, 0.875} 1508 * The A-series chips only have the first four table entries; the 1509 * roundoff table logic above ensures that the fractional part for those 1510 * chips will be one of the first four values. 1511 * 1512 * When the divisor is 1 a special encoding applies: 1.0 is encoded as 1513 * 0.0, and 1.5 is encoded as 1.0. The rounding logic above has already 1514 * ensured that the fraction is either .0 or .5 if the integral is 1. 1515 */ 1516 frac = divisor & 0x07; 1517 divisor >>= 3; 1518 if (divisor == 1) { 1519 if (frac == 0) 1520 divisor = 0; /* 1.0 becomes 0.0 */ 1521 else 1522 frac = 0; /* 1.5 becomes 1.0 */ 1523 } 1524 divisor |= (encoded_fraction[frac] << 14) | fastclk_flag; 1525 1526 cfg->baud_lobits = (uint16_t)divisor; 1527 cfg->baud_hibits = (uint16_t)(divisor >> 16); 1528 1529 /* 1530 * If this chip requires the baud bits to be in the high byte of the 1531 * index word, move the bits up to that location. 1532 */ 1533 if (sc->sc_devflags & DEVF_BAUDBITS_HINDEX) { 1534 cfg->baud_hibits <<= 8; 1535 } 1536 1537 return (0); 1538 } 1539 1540 static int 1541 uftdi_set_parm_soft(struct ucom_softc *ucom, struct termios *t, 1542 struct uftdi_param_config *cfg) 1543 { 1544 struct uftdi_softc *sc = ucom->sc_parent; 1545 int err; 1546 1547 memset(cfg, 0, sizeof(*cfg)); 1548 1549 if (sc->sc_devtype == DEVT_SIO) 1550 err = uftdi_sio_encode_baudrate(sc, t->c_ospeed, cfg); 1551 else 1552 err = uftdi_encode_baudrate(sc, t->c_ospeed, cfg); 1553 if (err != 0) 1554 return (err); 1555 1556 if (t->c_cflag & CSTOPB) 1557 cfg->lcr = FTDI_SIO_SET_DATA_STOP_BITS_2; 1558 else 1559 cfg->lcr = FTDI_SIO_SET_DATA_STOP_BITS_1; 1560 1561 if (t->c_cflag & PARENB) { 1562 if (t->c_cflag & PARODD) { 1563 cfg->lcr |= FTDI_SIO_SET_DATA_PARITY_ODD; 1564 } else { 1565 cfg->lcr |= FTDI_SIO_SET_DATA_PARITY_EVEN; 1566 } 1567 } else { 1568 cfg->lcr |= FTDI_SIO_SET_DATA_PARITY_NONE; 1569 } 1570 1571 switch (t->c_cflag & CSIZE) { 1572 case CS5: 1573 cfg->lcr |= FTDI_SIO_SET_DATA_BITS(5); 1574 break; 1575 1576 case CS6: 1577 cfg->lcr |= FTDI_SIO_SET_DATA_BITS(6); 1578 break; 1579 1580 case CS7: 1581 cfg->lcr |= FTDI_SIO_SET_DATA_BITS(7); 1582 break; 1583 1584 case CS8: 1585 cfg->lcr |= FTDI_SIO_SET_DATA_BITS(8); 1586 break; 1587 } 1588 1589 if (t->c_cflag & CRTSCTS) { 1590 cfg->v_flow = FTDI_SIO_RTS_CTS_HS; 1591 } else if (t->c_iflag & (IXON | IXOFF)) { 1592 cfg->v_flow = FTDI_SIO_XON_XOFF_HS; 1593 cfg->v_start = t->c_cc[VSTART]; 1594 cfg->v_stop = t->c_cc[VSTOP]; 1595 } else { 1596 cfg->v_flow = FTDI_SIO_DISABLE_FLOW_CTRL; 1597 } 1598 1599 return (0); 1600 } 1601 1602 static int 1603 uftdi_pre_param(struct ucom_softc *ucom, struct termios *t) 1604 { 1605 struct uftdi_param_config cfg; 1606 1607 DPRINTF("\n"); 1608 1609 return (uftdi_set_parm_soft(ucom, t, &cfg)); 1610 } 1611 1612 static void 1613 uftdi_cfg_param(struct ucom_softc *ucom, struct termios *t) 1614 { 1615 struct uftdi_softc *sc = ucom->sc_parent; 1616 uint16_t wIndex = ucom->sc_portno; 1617 struct uftdi_param_config cfg; 1618 struct usb_device_request req; 1619 1620 if (uftdi_set_parm_soft(ucom, t, &cfg)) { 1621 /* should not happen */ 1622 return; 1623 } 1624 sc->sc_last_lcr = cfg.lcr; 1625 1626 DPRINTF("\n"); 1627 1628 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1629 req.bRequest = FTDI_SIO_SET_BAUD_RATE; 1630 USETW(req.wValue, cfg.baud_lobits); 1631 USETW(req.wIndex, cfg.baud_hibits | wIndex); 1632 USETW(req.wLength, 0); 1633 ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 1634 &req, NULL, 0, 1000); 1635 1636 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1637 req.bRequest = FTDI_SIO_SET_DATA; 1638 USETW(req.wValue, cfg.lcr); 1639 USETW(req.wIndex, wIndex); 1640 USETW(req.wLength, 0); 1641 ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 1642 &req, NULL, 0, 1000); 1643 1644 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1645 req.bRequest = FTDI_SIO_SET_FLOW_CTRL; 1646 USETW2(req.wValue, cfg.v_stop, cfg.v_start); 1647 USETW2(req.wIndex, cfg.v_flow, wIndex); 1648 USETW(req.wLength, 0); 1649 ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 1650 &req, NULL, 0, 1000); 1651 } 1652 1653 static void 1654 uftdi_cfg_get_status(struct ucom_softc *ucom, uint8_t *lsr, uint8_t *msr) 1655 { 1656 struct uftdi_softc *sc = ucom->sc_parent; 1657 1658 DPRINTF("msr=0x%02x lsr=0x%02x\n", 1659 sc->sc_msr, sc->sc_lsr); 1660 1661 *msr = sc->sc_msr; 1662 *lsr = sc->sc_lsr; 1663 } 1664 1665 static int 1666 uftdi_reset(struct ucom_softc *ucom, int reset_type) 1667 { 1668 struct uftdi_softc *sc = ucom->sc_parent; 1669 usb_device_request_t req; 1670 1671 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1672 req.bRequest = FTDI_SIO_RESET; 1673 1674 USETW(req.wIndex, sc->sc_ucom.sc_portno); 1675 USETW(req.wLength, 0); 1676 USETW(req.wValue, reset_type); 1677 1678 return (usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, NULL)); 1679 } 1680 1681 static int 1682 uftdi_set_bitmode(struct ucom_softc *ucom, uint8_t bitmode, uint8_t iomask) 1683 { 1684 struct uftdi_softc *sc = ucom->sc_parent; 1685 usb_device_request_t req; 1686 int rv; 1687 1688 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1689 req.bRequest = FTDI_SIO_SET_BITMODE; 1690 1691 USETW(req.wIndex, sc->sc_ucom.sc_portno); 1692 USETW(req.wLength, 0); 1693 1694 if (bitmode == UFTDI_BITMODE_NONE) 1695 USETW2(req.wValue, 0, 0); 1696 else 1697 USETW2(req.wValue, (1 << bitmode), iomask); 1698 1699 rv = usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, NULL); 1700 if (rv == USB_ERR_NORMAL_COMPLETION) 1701 sc->sc_bitmode = bitmode; 1702 1703 return (rv); 1704 } 1705 1706 static int 1707 uftdi_get_bitmode(struct ucom_softc *ucom, uint8_t *bitmode, uint8_t *iomask) 1708 { 1709 struct uftdi_softc *sc = ucom->sc_parent; 1710 usb_device_request_t req; 1711 1712 req.bmRequestType = UT_READ_VENDOR_DEVICE; 1713 req.bRequest = FTDI_SIO_GET_BITMODE; 1714 1715 USETW(req.wIndex, sc->sc_ucom.sc_portno); 1716 USETW(req.wLength, 1); 1717 USETW(req.wValue, 0); 1718 1719 *bitmode = sc->sc_bitmode; 1720 return (usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, iomask)); 1721 } 1722 1723 static int 1724 uftdi_set_latency(struct ucom_softc *ucom, int latency) 1725 { 1726 struct uftdi_softc *sc = ucom->sc_parent; 1727 usb_device_request_t req; 1728 1729 if (latency < 0 || latency > 255) 1730 return (USB_ERR_INVAL); 1731 1732 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1733 req.bRequest = FTDI_SIO_SET_LATENCY; 1734 1735 USETW(req.wIndex, sc->sc_ucom.sc_portno); 1736 USETW(req.wLength, 0); 1737 USETW2(req.wValue, 0, latency); 1738 1739 return (usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, NULL)); 1740 } 1741 1742 static int 1743 uftdi_get_latency(struct ucom_softc *ucom, int *latency) 1744 { 1745 struct uftdi_softc *sc = ucom->sc_parent; 1746 usb_device_request_t req; 1747 usb_error_t err; 1748 uint8_t buf; 1749 1750 req.bmRequestType = UT_READ_VENDOR_DEVICE; 1751 req.bRequest = FTDI_SIO_GET_LATENCY; 1752 1753 USETW(req.wIndex, sc->sc_ucom.sc_portno); 1754 USETW(req.wLength, 1); 1755 USETW(req.wValue, 0); 1756 1757 err = usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, &buf); 1758 *latency = buf; 1759 1760 return (err); 1761 } 1762 1763 static int 1764 uftdi_set_event_char(struct ucom_softc *ucom, int echar) 1765 { 1766 struct uftdi_softc *sc = ucom->sc_parent; 1767 usb_device_request_t req; 1768 uint8_t enable; 1769 1770 enable = (echar == -1) ? 0 : 1; 1771 1772 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1773 req.bRequest = FTDI_SIO_SET_EVENT_CHAR; 1774 1775 USETW(req.wIndex, sc->sc_ucom.sc_portno); 1776 USETW(req.wLength, 0); 1777 USETW2(req.wValue, enable, echar & 0xff); 1778 1779 return (usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, NULL)); 1780 } 1781 1782 static int 1783 uftdi_set_error_char(struct ucom_softc *ucom, int echar) 1784 { 1785 struct uftdi_softc *sc = ucom->sc_parent; 1786 usb_device_request_t req; 1787 uint8_t enable; 1788 1789 enable = (echar == -1) ? 0 : 1; 1790 1791 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1792 req.bRequest = FTDI_SIO_SET_ERROR_CHAR; 1793 1794 USETW(req.wIndex, sc->sc_ucom.sc_portno); 1795 USETW(req.wLength, 0); 1796 USETW2(req.wValue, enable, echar & 0xff); 1797 1798 return (usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, NULL)); 1799 } 1800 1801 static int 1802 uftdi_read_eeprom(struct ucom_softc *ucom, struct uftdi_eeio *eeio) 1803 { 1804 struct uftdi_softc *sc = ucom->sc_parent; 1805 usb_device_request_t req; 1806 usb_error_t err; 1807 uint16_t widx, wlength, woffset; 1808 1809 /* Offset and length must both be evenly divisible by two. */ 1810 if ((eeio->offset | eeio->length) & 0x01) 1811 return (EINVAL); 1812 1813 woffset = eeio->offset / 2U; 1814 wlength = eeio->length / 2U; 1815 for (widx = 0; widx < wlength; widx++) { 1816 req.bmRequestType = UT_READ_VENDOR_DEVICE; 1817 req.bRequest = FTDI_SIO_READ_EEPROM; 1818 USETW(req.wIndex, widx + woffset); 1819 USETW(req.wLength, 2); 1820 USETW(req.wValue, 0); 1821 err = usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, 1822 &eeio->data[widx]); 1823 if (err != USB_ERR_NORMAL_COMPLETION) 1824 return (err); 1825 } 1826 return (USB_ERR_NORMAL_COMPLETION); 1827 } 1828 1829 static int 1830 uftdi_write_eeprom(struct ucom_softc *ucom, struct uftdi_eeio *eeio) 1831 { 1832 struct uftdi_softc *sc = ucom->sc_parent; 1833 usb_device_request_t req; 1834 usb_error_t err; 1835 uint16_t widx, wlength, woffset; 1836 1837 /* Offset and length must both be evenly divisible by two. */ 1838 if ((eeio->offset | eeio->length) & 0x01) 1839 return (EINVAL); 1840 1841 woffset = eeio->offset / 2U; 1842 wlength = eeio->length / 2U; 1843 for (widx = 0; widx < wlength; widx++) { 1844 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1845 req.bRequest = FTDI_SIO_WRITE_EEPROM; 1846 USETW(req.wIndex, widx + woffset); 1847 USETW(req.wLength, 0); 1848 USETW(req.wValue, eeio->data[widx]); 1849 err = usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, NULL); 1850 if (err != USB_ERR_NORMAL_COMPLETION) 1851 return (err); 1852 } 1853 return (USB_ERR_NORMAL_COMPLETION); 1854 } 1855 1856 static int 1857 uftdi_erase_eeprom(struct ucom_softc *ucom, int confirmation) 1858 { 1859 struct uftdi_softc *sc = ucom->sc_parent; 1860 usb_device_request_t req; 1861 usb_error_t err; 1862 1863 /* Small effort to prevent accidental erasure. */ 1864 if (confirmation != UFTDI_CONFIRM_ERASE) 1865 return (EINVAL); 1866 1867 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1868 req.bRequest = FTDI_SIO_ERASE_EEPROM; 1869 USETW(req.wIndex, 0); 1870 USETW(req.wLength, 0); 1871 USETW(req.wValue, 0); 1872 err = usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, NULL); 1873 1874 return (err); 1875 } 1876 1877 static int 1878 uftdi_ioctl(struct ucom_softc *ucom, uint32_t cmd, caddr_t data, 1879 int flag, struct thread *td) 1880 { 1881 struct uftdi_softc *sc = ucom->sc_parent; 1882 int err; 1883 struct uftdi_bitmode * mode; 1884 1885 DPRINTF("portno: %d cmd: %#x\n", ucom->sc_portno, cmd); 1886 1887 switch (cmd) { 1888 case UFTDIIOC_RESET_IO: 1889 case UFTDIIOC_RESET_RX: 1890 case UFTDIIOC_RESET_TX: 1891 err = uftdi_reset(ucom, 1892 cmd == UFTDIIOC_RESET_IO ? FTDI_SIO_RESET_SIO : 1893 (cmd == UFTDIIOC_RESET_RX ? FTDI_SIO_RESET_PURGE_RX : 1894 FTDI_SIO_RESET_PURGE_TX)); 1895 break; 1896 case UFTDIIOC_SET_BITMODE: 1897 mode = (struct uftdi_bitmode *)data; 1898 err = uftdi_set_bitmode(ucom, mode->mode, mode->iomask); 1899 break; 1900 case UFTDIIOC_GET_BITMODE: 1901 mode = (struct uftdi_bitmode *)data; 1902 err = uftdi_get_bitmode(ucom, &mode->mode, &mode->iomask); 1903 break; 1904 case UFTDIIOC_SET_LATENCY: 1905 err = uftdi_set_latency(ucom, *((int *)data)); 1906 break; 1907 case UFTDIIOC_GET_LATENCY: 1908 err = uftdi_get_latency(ucom, (int *)data); 1909 break; 1910 case UFTDIIOC_SET_ERROR_CHAR: 1911 err = uftdi_set_error_char(ucom, *(int *)data); 1912 break; 1913 case UFTDIIOC_SET_EVENT_CHAR: 1914 err = uftdi_set_event_char(ucom, *(int *)data); 1915 break; 1916 case UFTDIIOC_GET_HWREV: 1917 *(int *)data = sc->sc_bcdDevice; 1918 err = 0; 1919 break; 1920 case UFTDIIOC_READ_EEPROM: 1921 err = uftdi_read_eeprom(ucom, (struct uftdi_eeio *)data); 1922 break; 1923 case UFTDIIOC_WRITE_EEPROM: 1924 err = uftdi_write_eeprom(ucom, (struct uftdi_eeio *)data); 1925 break; 1926 case UFTDIIOC_ERASE_EEPROM: 1927 err = uftdi_erase_eeprom(ucom, *(int *)data); 1928 break; 1929 default: 1930 return (ENOIOCTL); 1931 } 1932 if (err != USB_ERR_NORMAL_COMPLETION) 1933 return (EIO); 1934 return (0); 1935 } 1936 1937 static void 1938 uftdi_start_read(struct ucom_softc *ucom) 1939 { 1940 struct uftdi_softc *sc = ucom->sc_parent; 1941 1942 usbd_transfer_start(sc->sc_xfer[UFTDI_BULK_DT_RD]); 1943 } 1944 1945 static void 1946 uftdi_stop_read(struct ucom_softc *ucom) 1947 { 1948 struct uftdi_softc *sc = ucom->sc_parent; 1949 1950 usbd_transfer_stop(sc->sc_xfer[UFTDI_BULK_DT_RD]); 1951 } 1952 1953 static void 1954 uftdi_start_write(struct ucom_softc *ucom) 1955 { 1956 struct uftdi_softc *sc = ucom->sc_parent; 1957 1958 usbd_transfer_start(sc->sc_xfer[UFTDI_BULK_DT_WR]); 1959 } 1960 1961 static void 1962 uftdi_stop_write(struct ucom_softc *ucom) 1963 { 1964 struct uftdi_softc *sc = ucom->sc_parent; 1965 1966 usbd_transfer_stop(sc->sc_xfer[UFTDI_BULK_DT_WR]); 1967 } 1968 1969 static void 1970 uftdi_poll(struct ucom_softc *ucom) 1971 { 1972 struct uftdi_softc *sc = ucom->sc_parent; 1973 1974 usbd_transfer_poll(sc->sc_xfer, UFTDI_N_TRANSFER); 1975 } 1976