1 /* $NetBSD: uftdi.c,v 1.13 2002/09/23 05:51:23 simonb Exp $ */ 2 3 /*- 4 * SPDX-License-Identifier: BSD-2-Clause-NetBSD 5 * 6 * Copyright (c) 2000 The NetBSD Foundation, Inc. 7 * All rights reserved. 8 * 9 * This code is derived from software contributed to The NetBSD Foundation 10 * by Lennart Augustsson (lennart@augustsson.net). 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #include <sys/cdefs.h> 35 __FBSDID("$FreeBSD$"); 36 37 /* 38 * NOTE: all function names beginning like "uftdi_cfg_" can only 39 * be called from within the config thread function ! 40 */ 41 42 /* 43 * FTDI FT232x, FT2232x, FT4232x, FT8U100AX and FT8U232xM serial adapters. 44 * 45 * Note that we specifically do not do a reset or otherwise alter the state of 46 * the chip during attach, detach, open, and close, because it could be 47 * pre-initialized (via an attached serial eeprom) to power-on into a mode such 48 * as bitbang in which the pins are being driven to a specific state which we 49 * must not perturb. The device gets reset at power-on, and doesn't need to be 50 * reset again after that to function, except as directed by ioctl() calls. 51 */ 52 53 #include <sys/stdint.h> 54 #include <sys/stddef.h> 55 #include <sys/param.h> 56 #include <sys/queue.h> 57 #include <sys/types.h> 58 #include <sys/systm.h> 59 #include <sys/kernel.h> 60 #include <sys/bus.h> 61 #include <sys/module.h> 62 #include <sys/lock.h> 63 #include <sys/mutex.h> 64 #include <sys/condvar.h> 65 #include <sys/sysctl.h> 66 #include <sys/sx.h> 67 #include <sys/unistd.h> 68 #include <sys/callout.h> 69 #include <sys/malloc.h> 70 #include <sys/priv.h> 71 72 #include <dev/usb/usb.h> 73 #include <dev/usb/usbdi.h> 74 #include <dev/usb/usbdi_util.h> 75 #include <dev/usb/usb_core.h> 76 #include <dev/usb/usb_ioctl.h> 77 #include "usbdevs.h" 78 79 #define USB_DEBUG_VAR uftdi_debug 80 #include <dev/usb/usb_debug.h> 81 #include <dev/usb/usb_process.h> 82 83 #include <dev/usb/serial/usb_serial.h> 84 #include <dev/usb/serial/uftdi_reg.h> 85 #include <dev/usb/uftdiio.h> 86 87 static SYSCTL_NODE(_hw_usb, OID_AUTO, uftdi, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 88 "USB uftdi"); 89 90 #ifdef USB_DEBUG 91 static int uftdi_debug = 0; 92 SYSCTL_INT(_hw_usb_uftdi, OID_AUTO, debug, CTLFLAG_RWTUN, 93 &uftdi_debug, 0, "Debug level"); 94 #endif 95 96 #define UFTDI_CONFIG_INDEX 0 97 98 /* 99 * IO buffer sizes and FTDI device procotol sizes. 100 * 101 * Note that the output packet size in the following defines is not the usb 102 * protocol packet size based on bus speed, it is the size dictated by the FTDI 103 * device itself, and is used only on older chips. 104 * 105 * We allocate buffers bigger than the hardware's packet size, and process 106 * multiple packets within each buffer. This allows the controller to make 107 * optimal use of the usb bus by conducting multiple transfers with the device 108 * during a single bus timeslice to fill or drain the chip's fifos. 109 * 110 * The output data on newer chips has no packet header, and we are able to pack 111 * any number of output bytes into a buffer. On some older chips, each output 112 * packet contains a 1-byte header and up to 63 bytes of payload. The size is 113 * encoded in 6 bits of the header, hence the 64-byte limit on packet size. We 114 * loop to fill the buffer with many of these header+payload packets. 115 * 116 * The input data on all chips consists of packets which contain a 2-byte header 117 * followed by data payload. The total size of the packet is wMaxPacketSize 118 * which can change based on the bus speed (e.g., 64 for full speed, 512 for 119 * high speed). We loop to extract the headers and payloads from the packets 120 * packed into an input buffer. 121 */ 122 #define UFTDI_IBUFSIZE 2048 123 #define UFTDI_IHDRSIZE 2 124 #define UFTDI_OBUFSIZE 2048 125 #define UFTDI_OPKTSIZE 64 126 127 enum { 128 UFTDI_BULK_DT_WR, 129 UFTDI_BULK_DT_RD, 130 UFTDI_N_TRANSFER, 131 }; 132 133 enum { 134 DEVT_SIO, 135 DEVT_232A, 136 DEVT_232B, 137 DEVT_2232D, /* Includes 2232C */ 138 DEVT_232R, 139 DEVT_2232H, 140 DEVT_4232H, 141 DEVT_232H, 142 DEVT_230X, 143 }; 144 145 #define DEVF_BAUDBITS_HINDEX 0x01 /* Baud bits in high byte of index. */ 146 #define DEVF_BAUDCLK_12M 0X02 /* Base baud clock is 12MHz. */ 147 148 struct uftdi_softc { 149 struct ucom_super_softc sc_super_ucom; 150 struct ucom_softc sc_ucom; 151 152 struct usb_device *sc_udev; 153 struct usb_xfer *sc_xfer[UFTDI_N_TRANSFER]; 154 device_t sc_dev; 155 struct mtx sc_mtx; 156 157 uint32_t sc_unit; 158 159 uint16_t sc_last_lcr; 160 uint16_t sc_bcdDevice; 161 162 uint8_t sc_devtype; 163 uint8_t sc_devflags; 164 uint8_t sc_hdrlen; 165 uint8_t sc_msr; 166 uint8_t sc_lsr; 167 uint8_t sc_bitmode; 168 }; 169 170 struct uftdi_param_config { 171 uint16_t baud_lobits; 172 uint16_t baud_hibits; 173 uint16_t lcr; 174 uint8_t v_start; 175 uint8_t v_stop; 176 uint8_t v_flow; 177 }; 178 179 /* prototypes */ 180 181 static device_probe_t uftdi_probe; 182 static device_attach_t uftdi_attach; 183 static device_detach_t uftdi_detach; 184 static void uftdi_free_softc(struct uftdi_softc *); 185 186 static usb_callback_t uftdi_write_callback; 187 static usb_callback_t uftdi_read_callback; 188 189 static void uftdi_free(struct ucom_softc *); 190 static void uftdi_cfg_open(struct ucom_softc *); 191 static void uftdi_cfg_close(struct ucom_softc *); 192 static void uftdi_cfg_set_dtr(struct ucom_softc *, uint8_t); 193 static void uftdi_cfg_set_rts(struct ucom_softc *, uint8_t); 194 static void uftdi_cfg_set_break(struct ucom_softc *, uint8_t); 195 static int uftdi_set_parm_soft(struct ucom_softc *, struct termios *, 196 struct uftdi_param_config *); 197 static int uftdi_pre_param(struct ucom_softc *, struct termios *); 198 static void uftdi_cfg_param(struct ucom_softc *, struct termios *); 199 static void uftdi_cfg_get_status(struct ucom_softc *, uint8_t *, 200 uint8_t *); 201 static int uftdi_reset(struct ucom_softc *, int); 202 static int uftdi_set_bitmode(struct ucom_softc *, uint8_t, uint8_t); 203 static int uftdi_get_bitmode(struct ucom_softc *, uint8_t *, uint8_t *); 204 static int uftdi_set_latency(struct ucom_softc *, int); 205 static int uftdi_get_latency(struct ucom_softc *, int *); 206 static int uftdi_set_event_char(struct ucom_softc *, int); 207 static int uftdi_set_error_char(struct ucom_softc *, int); 208 static int uftdi_ioctl(struct ucom_softc *, uint32_t, caddr_t, int, 209 struct thread *); 210 static void uftdi_start_read(struct ucom_softc *); 211 static void uftdi_stop_read(struct ucom_softc *); 212 static void uftdi_start_write(struct ucom_softc *); 213 static void uftdi_stop_write(struct ucom_softc *); 214 static void uftdi_poll(struct ucom_softc *ucom); 215 216 static const struct usb_config uftdi_config[UFTDI_N_TRANSFER] = { 217 [UFTDI_BULK_DT_WR] = { 218 .type = UE_BULK, 219 .endpoint = UE_ADDR_ANY, 220 .direction = UE_DIR_OUT, 221 .bufsize = UFTDI_OBUFSIZE, 222 .flags = {.pipe_bof = 1,}, 223 .callback = &uftdi_write_callback, 224 }, 225 226 [UFTDI_BULK_DT_RD] = { 227 .type = UE_BULK, 228 .endpoint = UE_ADDR_ANY, 229 .direction = UE_DIR_IN, 230 .bufsize = UFTDI_IBUFSIZE, 231 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 232 .callback = &uftdi_read_callback, 233 }, 234 }; 235 236 static const struct ucom_callback uftdi_callback = { 237 .ucom_cfg_get_status = &uftdi_cfg_get_status, 238 .ucom_cfg_set_dtr = &uftdi_cfg_set_dtr, 239 .ucom_cfg_set_rts = &uftdi_cfg_set_rts, 240 .ucom_cfg_set_break = &uftdi_cfg_set_break, 241 .ucom_cfg_param = &uftdi_cfg_param, 242 .ucom_cfg_open = &uftdi_cfg_open, 243 .ucom_cfg_close = &uftdi_cfg_close, 244 .ucom_pre_param = &uftdi_pre_param, 245 .ucom_ioctl = &uftdi_ioctl, 246 .ucom_start_read = &uftdi_start_read, 247 .ucom_stop_read = &uftdi_stop_read, 248 .ucom_start_write = &uftdi_start_write, 249 .ucom_stop_write = &uftdi_stop_write, 250 .ucom_poll = &uftdi_poll, 251 .ucom_free = &uftdi_free, 252 }; 253 254 static device_method_t uftdi_methods[] = { 255 /* Device interface */ 256 DEVMETHOD(device_probe, uftdi_probe), 257 DEVMETHOD(device_attach, uftdi_attach), 258 DEVMETHOD(device_detach, uftdi_detach), 259 DEVMETHOD_END 260 }; 261 262 static devclass_t uftdi_devclass; 263 264 static driver_t uftdi_driver = { 265 .name = "uftdi", 266 .methods = uftdi_methods, 267 .size = sizeof(struct uftdi_softc), 268 }; 269 270 static const STRUCT_USB_HOST_ID uftdi_devs[] = { 271 #define UFTDI_DEV(v, p, i) \ 272 { USB_VPI(USB_VENDOR_##v, USB_PRODUCT_##v##_##p, i) } 273 UFTDI_DEV(ACTON, SPECTRAPRO, 0), 274 UFTDI_DEV(ALTI2, N3, 0), 275 UFTDI_DEV(ANALOGDEVICES, GNICE, UFTDI_JTAG_IFACE(0)), 276 UFTDI_DEV(ANALOGDEVICES, GNICEPLUS, UFTDI_JTAG_IFACE(0)), 277 UFTDI_DEV(ATMEL, STK541, 0), 278 UFTDI_DEV(BAYER, CONTOUR_CABLE, 0), 279 UFTDI_DEV(BBELECTRONICS, 232USB9M, 0), 280 UFTDI_DEV(BBELECTRONICS, 485USB9F_2W, 0), 281 UFTDI_DEV(BBELECTRONICS, 485USB9F_4W, 0), 282 UFTDI_DEV(BBELECTRONICS, 485USBTB_2W, 0), 283 UFTDI_DEV(BBELECTRONICS, 485USBTB_4W, 0), 284 UFTDI_DEV(BBELECTRONICS, TTL3USB9M, 0), 285 UFTDI_DEV(BBELECTRONICS, TTL5USB9M, 0), 286 UFTDI_DEV(BBELECTRONICS, USO9ML2, 0), 287 UFTDI_DEV(BBELECTRONICS, USO9ML2DR, 0), 288 UFTDI_DEV(BBELECTRONICS, USO9ML2DR_2, 0), 289 UFTDI_DEV(BBELECTRONICS, USOPTL4, 0), 290 UFTDI_DEV(BBELECTRONICS, USOPTL4DR, 0), 291 UFTDI_DEV(BBELECTRONICS, USOPTL4DR2, 0), 292 UFTDI_DEV(BBELECTRONICS, USOTL4, 0), 293 UFTDI_DEV(BBELECTRONICS, USPTL4, 0), 294 UFTDI_DEV(BBELECTRONICS, USTL4, 0), 295 UFTDI_DEV(BBELECTRONICS, ZZ_PROG1_USB, 0), 296 UFTDI_DEV(BRAINBOXES, US257, 0), 297 UFTDI_DEV(BRAINBOXES, US25701, 0), 298 UFTDI_DEV(CONTEC, COM1USBH, 0), 299 UFTDI_DEV(DRESDENELEKTRONIK, SENSORTERMINALBOARD, 0), 300 UFTDI_DEV(DRESDENELEKTRONIK, WIRELESSHANDHELDTERMINAL, 0), 301 UFTDI_DEV(DRESDENELEKTRONIK, DE_RFNODE, 0), 302 UFTDI_DEV(DRESDENELEKTRONIK, LEVELSHIFTERSTICKLOWCOST, 0), 303 UFTDI_DEV(ELEKTOR, FT323R, 0), 304 UFTDI_DEV(EVOLUTION, ER1, 0), 305 UFTDI_DEV(EVOLUTION, HYBRID, 0), 306 UFTDI_DEV(EVOLUTION, RCM4, 0), 307 UFTDI_DEV(FALCOM, SAMBA, 0), 308 UFTDI_DEV(FALCOM, TWIST, 0), 309 UFTDI_DEV(FIC, NEO1973_DEBUG, UFTDI_JTAG_IFACE(0)), 310 UFTDI_DEV(FIC, NEO1973_DEBUG, UFTDI_JTAG_IFACE(0)), 311 UFTDI_DEV(FTDI, 232EX, 0), 312 UFTDI_DEV(FTDI, 232H, 0), 313 UFTDI_DEV(FTDI, 232RL, 0), 314 UFTDI_DEV(FTDI, 4N_GALAXY_DE_1, 0), 315 UFTDI_DEV(FTDI, 4N_GALAXY_DE_2, 0), 316 UFTDI_DEV(FTDI, 4N_GALAXY_DE_3, 0), 317 UFTDI_DEV(FTDI, 8U232AM_ALT, 0), 318 UFTDI_DEV(FTDI, ACCESSO, 0), 319 UFTDI_DEV(FTDI, ACG_HFDUAL, 0), 320 UFTDI_DEV(FTDI, ACTIVE_ROBOTS, 0), 321 UFTDI_DEV(FTDI, ACTZWAVE, 0), 322 UFTDI_DEV(FTDI, AMC232, 0), 323 UFTDI_DEV(FTDI, ARTEMIS, 0), 324 UFTDI_DEV(FTDI, ASK_RDR400, 0), 325 UFTDI_DEV(FTDI, ATIK_ATK16, 0), 326 UFTDI_DEV(FTDI, ATIK_ATK16C, 0), 327 UFTDI_DEV(FTDI, ATIK_ATK16HR, 0), 328 UFTDI_DEV(FTDI, ATIK_ATK16HRC, 0), 329 UFTDI_DEV(FTDI, ATIK_ATK16IC, 0), 330 UFTDI_DEV(FTDI, BCS_SE923, 0), 331 UFTDI_DEV(FTDI, CANDAPTER, 0), 332 UFTDI_DEV(FTDI, CANUSB, 0), 333 UFTDI_DEV(FTDI, CCSICDU20_0, 0), 334 UFTDI_DEV(FTDI, CCSICDU40_1, 0), 335 UFTDI_DEV(FTDI, CCSICDU64_4, 0), 336 UFTDI_DEV(FTDI, CCSLOAD_N_GO_3, 0), 337 UFTDI_DEV(FTDI, CCSMACHX_2, 0), 338 UFTDI_DEV(FTDI, CCSPRIME8_5, 0), 339 UFTDI_DEV(FTDI, CFA_631, 0), 340 UFTDI_DEV(FTDI, CFA_632, 0), 341 UFTDI_DEV(FTDI, CFA_633, 0), 342 UFTDI_DEV(FTDI, CFA_634, 0), 343 UFTDI_DEV(FTDI, CFA_635, 0), 344 UFTDI_DEV(FTDI, CHAMSYS_24_MASTER_WING, 0), 345 UFTDI_DEV(FTDI, CHAMSYS_MAXI_WING, 0), 346 UFTDI_DEV(FTDI, CHAMSYS_MEDIA_WING, 0), 347 UFTDI_DEV(FTDI, CHAMSYS_MIDI_TIMECODE, 0), 348 UFTDI_DEV(FTDI, CHAMSYS_MINI_WING, 0), 349 UFTDI_DEV(FTDI, CHAMSYS_PC_WING, 0), 350 UFTDI_DEV(FTDI, CHAMSYS_USB_DMX, 0), 351 UFTDI_DEV(FTDI, CHAMSYS_WING, 0), 352 UFTDI_DEV(FTDI, COM4SM, 0), 353 UFTDI_DEV(FTDI, CONVERTER_0, 0), 354 UFTDI_DEV(FTDI, CONVERTER_1, 0), 355 UFTDI_DEV(FTDI, CONVERTER_2, 0), 356 UFTDI_DEV(FTDI, CONVERTER_3, 0), 357 UFTDI_DEV(FTDI, CONVERTER_4, 0), 358 UFTDI_DEV(FTDI, CONVERTER_5, 0), 359 UFTDI_DEV(FTDI, CONVERTER_6, 0), 360 UFTDI_DEV(FTDI, CONVERTER_7, 0), 361 UFTDI_DEV(FTDI, CTI_USB_MINI_485, 0), 362 UFTDI_DEV(FTDI, CTI_USB_NANO_485, 0), 363 UFTDI_DEV(FTDI, DMX4ALL, 0), 364 UFTDI_DEV(FTDI, DOMINTELL_DGQG, 0), 365 UFTDI_DEV(FTDI, DOMINTELL_DUSB, 0), 366 UFTDI_DEV(FTDI, DOTEC, 0), 367 UFTDI_DEV(FTDI, ECLO_COM_1WIRE, 0), 368 UFTDI_DEV(FTDI, ECO_PRO_CDS, 0), 369 UFTDI_DEV(FTDI, EISCOU, 0), 370 UFTDI_DEV(FTDI, ELSTER_UNICOM, 0), 371 UFTDI_DEV(FTDI, ELV_ALC8500, 0), 372 UFTDI_DEV(FTDI, ELV_CLI7000, 0), 373 UFTDI_DEV(FTDI, ELV_CSI8, 0), 374 UFTDI_DEV(FTDI, ELV_EC3000, 0), 375 UFTDI_DEV(FTDI, ELV_EM1000DL, 0), 376 UFTDI_DEV(FTDI, ELV_EM1010PC, 0), 377 UFTDI_DEV(FTDI, ELV_FEM, 0), 378 UFTDI_DEV(FTDI, ELV_FHZ1000PC, 0), 379 UFTDI_DEV(FTDI, ELV_FHZ1300PC, 0), 380 UFTDI_DEV(FTDI, ELV_FM3RX, 0), 381 UFTDI_DEV(FTDI, ELV_FS20SIG, 0), 382 UFTDI_DEV(FTDI, ELV_HS485, 0), 383 UFTDI_DEV(FTDI, ELV_KL100, 0), 384 UFTDI_DEV(FTDI, ELV_MSM1, 0), 385 UFTDI_DEV(FTDI, ELV_PCD200, 0), 386 UFTDI_DEV(FTDI, ELV_PCK100, 0), 387 UFTDI_DEV(FTDI, ELV_PPS7330, 0), 388 UFTDI_DEV(FTDI, ELV_RFP500, 0), 389 UFTDI_DEV(FTDI, ELV_T1100, 0), 390 UFTDI_DEV(FTDI, ELV_TFD128, 0), 391 UFTDI_DEV(FTDI, ELV_TFM100, 0), 392 UFTDI_DEV(FTDI, ELV_TWS550, 0), 393 UFTDI_DEV(FTDI, ELV_UAD8, 0), 394 UFTDI_DEV(FTDI, ELV_UDA7, 0), 395 UFTDI_DEV(FTDI, ELV_UDF77, 0), 396 UFTDI_DEV(FTDI, ELV_UIO88, 0), 397 UFTDI_DEV(FTDI, ELV_ULA200, 0), 398 UFTDI_DEV(FTDI, ELV_UM100, 0), 399 UFTDI_DEV(FTDI, ELV_UMS100, 0), 400 UFTDI_DEV(FTDI, ELV_UO100, 0), 401 UFTDI_DEV(FTDI, ELV_UR100, 0), 402 UFTDI_DEV(FTDI, ELV_USI2, 0), 403 UFTDI_DEV(FTDI, ELV_USR, 0), 404 UFTDI_DEV(FTDI, ELV_UTP8, 0), 405 UFTDI_DEV(FTDI, ELV_WS300PC, 0), 406 UFTDI_DEV(FTDI, ELV_WS444PC, 0), 407 UFTDI_DEV(FTDI, ELV_WS500, 0), 408 UFTDI_DEV(FTDI, ELV_WS550, 0), 409 UFTDI_DEV(FTDI, ELV_WS777, 0), 410 UFTDI_DEV(FTDI, ELV_WS888, 0), 411 UFTDI_DEV(FTDI, EMCU2D, 0), 412 UFTDI_DEV(FTDI, EMCU2H, 0), 413 UFTDI_DEV(FTDI, FUTURE_0, 0), 414 UFTDI_DEV(FTDI, FUTURE_1, 0), 415 UFTDI_DEV(FTDI, FUTURE_2, 0), 416 UFTDI_DEV(FTDI, GAMMASCOUT, 0), 417 UFTDI_DEV(FTDI, GENERIC, 0), 418 UFTDI_DEV(FTDI, GUDEADS_E808, 0), 419 UFTDI_DEV(FTDI, GUDEADS_E809, 0), 420 UFTDI_DEV(FTDI, GUDEADS_E80A, 0), 421 UFTDI_DEV(FTDI, GUDEADS_E80B, 0), 422 UFTDI_DEV(FTDI, GUDEADS_E80C, 0), 423 UFTDI_DEV(FTDI, GUDEADS_E80D, 0), 424 UFTDI_DEV(FTDI, GUDEADS_E80E, 0), 425 UFTDI_DEV(FTDI, GUDEADS_E80F, 0), 426 UFTDI_DEV(FTDI, GUDEADS_E88D, 0), 427 UFTDI_DEV(FTDI, GUDEADS_E88E, 0), 428 UFTDI_DEV(FTDI, GUDEADS_E88F, 0), 429 UFTDI_DEV(FTDI, HD_RADIO, 0), 430 UFTDI_DEV(FTDI, HO720, 0), 431 UFTDI_DEV(FTDI, HO730, 0), 432 UFTDI_DEV(FTDI, HO820, 0), 433 UFTDI_DEV(FTDI, HO870, 0), 434 UFTDI_DEV(FTDI, IBS_APP70, 0), 435 UFTDI_DEV(FTDI, IBS_PCMCIA, 0), 436 UFTDI_DEV(FTDI, IBS_PEDO, 0), 437 UFTDI_DEV(FTDI, IBS_PICPRO, 0), 438 UFTDI_DEV(FTDI, IBS_PK1, 0), 439 UFTDI_DEV(FTDI, IBS_PROD, 0), 440 UFTDI_DEV(FTDI, IBS_RS232MON, 0), 441 UFTDI_DEV(FTDI, IBS_US485, 0), 442 UFTDI_DEV(FTDI, IPLUS, 0), 443 UFTDI_DEV(FTDI, IPLUS2, 0), 444 UFTDI_DEV(FTDI, IRTRANS, 0), 445 UFTDI_DEV(FTDI, KBS, 0), 446 UFTDI_DEV(FTDI, KTLINK, UFTDI_JTAG_IFACE(0)), 447 UFTDI_DEV(FTDI, LENZ_LIUSB, 0), 448 UFTDI_DEV(FTDI, LK202, 0), 449 UFTDI_DEV(FTDI, LK204, 0), 450 UFTDI_DEV(FTDI, LM3S_DEVEL_BOARD, UFTDI_JTAG_IFACE(0)), 451 UFTDI_DEV(FTDI, LM3S_EVAL_BOARD, UFTDI_JTAG_IFACE(0)), 452 UFTDI_DEV(FTDI, LM3S_ICDI_B_BOARD, UFTDI_JTAG_IFACE(0)), 453 UFTDI_DEV(FTDI, MASTERDEVEL2, 0), 454 UFTDI_DEV(FTDI, MAXSTREAM, 0), 455 UFTDI_DEV(FTDI, MHAM_DB9, 0), 456 UFTDI_DEV(FTDI, MHAM_IC, 0), 457 UFTDI_DEV(FTDI, MHAM_KW, 0), 458 UFTDI_DEV(FTDI, MHAM_RS232, 0), 459 UFTDI_DEV(FTDI, MHAM_Y6, 0), 460 UFTDI_DEV(FTDI, MHAM_Y8, 0), 461 UFTDI_DEV(FTDI, MHAM_Y9, 0), 462 UFTDI_DEV(FTDI, MHAM_YS, 0), 463 UFTDI_DEV(FTDI, MICRO_CHAMELEON, 0), 464 UFTDI_DEV(FTDI, MTXORB_5, 0), 465 UFTDI_DEV(FTDI, MTXORB_6, 0), 466 UFTDI_DEV(FTDI, MX2_3, 0), 467 UFTDI_DEV(FTDI, MX4_5, 0), 468 UFTDI_DEV(FTDI, NXTCAM, 0), 469 UFTDI_DEV(FTDI, OCEANIC, 0), 470 UFTDI_DEV(FTDI, OOCDLINK, UFTDI_JTAG_IFACE(0)), 471 UFTDI_DEV(FTDI, OPENDCC, 0), 472 UFTDI_DEV(FTDI, OPENDCC_GATEWAY, 0), 473 UFTDI_DEV(FTDI, OPENDCC_GBM, 0), 474 UFTDI_DEV(FTDI, OPENDCC_SNIFFER, 0), 475 UFTDI_DEV(FTDI, OPENDCC_THROTTLE, 0), 476 UFTDI_DEV(FTDI, PCDJ_DAC2, 0), 477 UFTDI_DEV(FTDI, PCMSFU, 0), 478 UFTDI_DEV(FTDI, PERLE_ULTRAPORT, 0), 479 UFTDI_DEV(FTDI, PHI_FISCO, 0), 480 UFTDI_DEV(FTDI, PIEGROUP, 0), 481 UFTDI_DEV(FTDI, PROPOX_JTAGCABLEII, 0), 482 UFTDI_DEV(FTDI, R2000KU_TRUE_RNG, 0), 483 UFTDI_DEV(FTDI, R2X0, 0), 484 UFTDI_DEV(FTDI, RELAIS, 0), 485 UFTDI_DEV(FTDI, REU_TINY, 0), 486 UFTDI_DEV(FTDI, RMP200, 0), 487 UFTDI_DEV(FTDI, RM_CANVIEW, 0), 488 UFTDI_DEV(FTDI, RRCIRKITS_LOCOBUFFER, 0), 489 UFTDI_DEV(FTDI, SCIENCESCOPE_HS_LOGBOOK, 0), 490 UFTDI_DEV(FTDI, SCIENCESCOPE_LOGBOOKML, 0), 491 UFTDI_DEV(FTDI, SCIENCESCOPE_LS_LOGBOOK, 0), 492 UFTDI_DEV(FTDI, SCS_DEVICE_0, 0), 493 UFTDI_DEV(FTDI, SCS_DEVICE_1, 0), 494 UFTDI_DEV(FTDI, SCS_DEVICE_2, 0), 495 UFTDI_DEV(FTDI, SCS_DEVICE_3, 0), 496 UFTDI_DEV(FTDI, SCS_DEVICE_4, 0), 497 UFTDI_DEV(FTDI, SCS_DEVICE_5, 0), 498 UFTDI_DEV(FTDI, SCS_DEVICE_6, 0), 499 UFTDI_DEV(FTDI, SCS_DEVICE_7, 0), 500 UFTDI_DEV(FTDI, SCX8_USB_PHOENIX, 0), 501 UFTDI_DEV(FTDI, SDMUSBQSS, 0), 502 UFTDI_DEV(FTDI, SEMC_DSS20, 0), 503 UFTDI_DEV(FTDI, SERIAL_2232C, UFTDI_JTAG_CHECK_STRING), 504 UFTDI_DEV(FTDI, SERIAL_2232D, 0), 505 UFTDI_DEV(FTDI, SERIAL_232RL, 0), 506 UFTDI_DEV(FTDI, SERIAL_4232H, 0), 507 UFTDI_DEV(FTDI, SERIAL_8U100AX, 0), 508 UFTDI_DEV(FTDI, SERIAL_8U232AM, 0), 509 UFTDI_DEV(FTDI, SERIAL_8U232AM4, 0), 510 UFTDI_DEV(FTDI, SIGNALYZER_SH2, UFTDI_JTAG_IFACE(0)), 511 UFTDI_DEV(FTDI, SIGNALYZER_SH4, UFTDI_JTAG_IFACE(0)), 512 UFTDI_DEV(FTDI, SIGNALYZER_SLITE, UFTDI_JTAG_IFACE(0)), 513 UFTDI_DEV(FTDI, SIGNALYZER_ST, UFTDI_JTAG_IFACE(0)), 514 UFTDI_DEV(FTDI, SPECIAL_1, 0), 515 UFTDI_DEV(FTDI, SPECIAL_3, 0), 516 UFTDI_DEV(FTDI, SPECIAL_4, 0), 517 UFTDI_DEV(FTDI, SPROG_II, 0), 518 UFTDI_DEV(FTDI, SR_RADIO, 0), 519 UFTDI_DEV(FTDI, SUUNTO_SPORTS, 0), 520 UFTDI_DEV(FTDI, TACTRIX_OPENPORT_13M, 0), 521 UFTDI_DEV(FTDI, TACTRIX_OPENPORT_13S, 0), 522 UFTDI_DEV(FTDI, TACTRIX_OPENPORT_13U, 0), 523 UFTDI_DEV(FTDI, TAVIR_STK500, 0), 524 UFTDI_DEV(FTDI, TERATRONIK_D2XX, 0), 525 UFTDI_DEV(FTDI, TERATRONIK_VCP, 0), 526 UFTDI_DEV(FTDI, THORLABS, 0), 527 UFTDI_DEV(FTDI, TIAO, 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, UFTDI_JTAG_IFACE(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 DRIVER_MODULE(uftdi, uhub, uftdi_driver, uftdi_devclass, NULL, NULL); 918 MODULE_DEPEND(uftdi, ucom, 1, 1, 1); 919 MODULE_DEPEND(uftdi, usb, 1, 1, 1); 920 MODULE_VERSION(uftdi, 1); 921 USB_PNP_HOST_INFO(uftdi_devs); 922 923 /* 924 * Jtag product name strings table. Some products have one or more interfaces 925 * dedicated to jtag or gpio, but use a product ID that's the same as other 926 * products which don't. They are marked with a flag in the table above, and 927 * the following string table is checked for flagged products. The string check 928 * is done with strstr(); in effect there is an implicit wildcard at the 929 * beginning and end of each product name string in table. 930 */ 931 static const struct jtag_by_name { 932 const char * product_name; 933 uint32_t jtag_interfaces; 934 } jtag_products_by_name[] = { 935 /* TI Beaglebone and TI XDS100Vn jtag product line. */ 936 {"XDS100V", UFTDI_JTAG_IFACE(0)}, 937 }; 938 939 /* 940 * Set up a sysctl and tunable to en/disable the feature of skipping the 941 * creation of tty devices for jtag interfaces. Enabled by default. 942 */ 943 static int skip_jtag_interfaces = 1; 944 SYSCTL_INT(_hw_usb_uftdi, OID_AUTO, skip_jtag_interfaces, CTLFLAG_RWTUN, 945 &skip_jtag_interfaces, 1, "Skip creating tty devices for jtag interfaces"); 946 947 static boolean_t 948 is_jtag_interface(struct usb_attach_arg *uaa, const struct usb_device_id *id) 949 { 950 int i, iface_bit; 951 const char * product_name; 952 const struct jtag_by_name *jbn; 953 954 /* We only allocate 8 flag bits for jtag interface flags. */ 955 if (uaa->info.bIfaceIndex >= UFTDI_JTAG_IFACES_MAX) 956 return (0); 957 iface_bit = UFTDI_JTAG_IFACE(uaa->info.bIfaceIndex); 958 959 /* 960 * If requested, search the name strings table and use the interface 961 * bits from that table when the product name string matches, else use 962 * the jtag interface bits from the main ID table. 963 */ 964 if ((id->driver_info & UFTDI_JTAG_MASK) == UFTDI_JTAG_CHECK_STRING) { 965 product_name = usb_get_product(uaa->device); 966 for (i = 0; i < nitems(jtag_products_by_name); i++) { 967 jbn = &jtag_products_by_name[i]; 968 if (strstr(product_name, jbn->product_name) != NULL && 969 (jbn->jtag_interfaces & iface_bit) != 0) 970 return (1); 971 } 972 } else if ((id->driver_info & iface_bit) != 0) 973 return (1); 974 975 return (0); 976 } 977 978 /* 979 * Set up softc fields whose value depends on the device type. 980 * 981 * Note that the 2232C and 2232D devices are the same for our purposes. In the 982 * silicon the difference is that the D series has CPU FIFO mode and C doesn't. 983 * I haven't found any way of determining the C/D difference from info provided 984 * by the chip other than trying to set CPU FIFO mode and having it work or not. 985 * 986 * Due to a hardware bug, a 232B chip without an eeprom reports itself as a 987 * 232A, but if the serial number is also zero we know it's really a 232B. 988 */ 989 static void 990 uftdi_devtype_setup(struct uftdi_softc *sc, struct usb_attach_arg *uaa) 991 { 992 struct usb_device_descriptor *dd; 993 994 sc->sc_bcdDevice = uaa->info.bcdDevice; 995 996 switch (uaa->info.bcdDevice) { 997 case 0x200: 998 dd = usbd_get_device_descriptor(sc->sc_udev); 999 if (dd->iSerialNumber == 0) { 1000 sc->sc_devtype = DEVT_232B; 1001 } else { 1002 sc->sc_devtype = DEVT_232A; 1003 } 1004 sc->sc_ucom.sc_portno = 0; 1005 break; 1006 case 0x400: 1007 sc->sc_devtype = DEVT_232B; 1008 sc->sc_ucom.sc_portno = 0; 1009 break; 1010 case 0x500: 1011 sc->sc_devtype = DEVT_2232D; 1012 sc->sc_devflags |= DEVF_BAUDBITS_HINDEX; 1013 sc->sc_ucom.sc_portno = FTDI_PIT_SIOA + uaa->info.bIfaceNum; 1014 break; 1015 case 0x600: 1016 sc->sc_devtype = DEVT_232R; 1017 sc->sc_ucom.sc_portno = 0; 1018 break; 1019 case 0x700: 1020 sc->sc_devtype = DEVT_2232H; 1021 sc->sc_devflags |= DEVF_BAUDBITS_HINDEX | DEVF_BAUDCLK_12M; 1022 sc->sc_ucom.sc_portno = FTDI_PIT_SIOA + uaa->info.bIfaceNum; 1023 break; 1024 case 0x800: 1025 sc->sc_devtype = DEVT_4232H; 1026 sc->sc_devflags |= DEVF_BAUDBITS_HINDEX | DEVF_BAUDCLK_12M; 1027 sc->sc_ucom.sc_portno = FTDI_PIT_SIOA + uaa->info.bIfaceNum; 1028 break; 1029 case 0x900: 1030 sc->sc_devtype = DEVT_232H; 1031 sc->sc_devflags |= DEVF_BAUDBITS_HINDEX | DEVF_BAUDCLK_12M; 1032 sc->sc_ucom.sc_portno = FTDI_PIT_SIOA + uaa->info.bIfaceNum; 1033 break; 1034 case 0x1000: 1035 sc->sc_devtype = DEVT_230X; 1036 sc->sc_devflags |= DEVF_BAUDBITS_HINDEX; 1037 sc->sc_ucom.sc_portno = FTDI_PIT_SIOA + uaa->info.bIfaceNum; 1038 break; 1039 default: 1040 if (uaa->info.bcdDevice < 0x200) { 1041 sc->sc_devtype = DEVT_SIO; 1042 sc->sc_hdrlen = 1; 1043 } else { 1044 sc->sc_devtype = DEVT_232R; 1045 device_printf(sc->sc_dev, "Warning: unknown FTDI " 1046 "device type, bcdDevice=0x%04x, assuming 232R\n", 1047 uaa->info.bcdDevice); 1048 } 1049 sc->sc_ucom.sc_portno = 0; 1050 break; 1051 } 1052 } 1053 1054 static int 1055 uftdi_probe(device_t dev) 1056 { 1057 struct usb_attach_arg *uaa = device_get_ivars(dev); 1058 const struct usb_device_id *id; 1059 1060 if (uaa->usb_mode != USB_MODE_HOST) { 1061 return (ENXIO); 1062 } 1063 if (uaa->info.bConfigIndex != UFTDI_CONFIG_INDEX) { 1064 return (ENXIO); 1065 } 1066 1067 /* 1068 * Attach to all present interfaces unless this is a JTAG one, which 1069 * we leave for userland. 1070 */ 1071 id = usbd_lookup_id_by_info(uftdi_devs, sizeof(uftdi_devs), 1072 &uaa->info); 1073 if (id == NULL) 1074 return (ENXIO); 1075 if (skip_jtag_interfaces && is_jtag_interface(uaa, id)) { 1076 printf("%s: skipping JTAG interface #%d for '%s' at %u.%u\n", 1077 device_get_name(dev), 1078 uaa->info.bIfaceIndex, 1079 usb_get_product(uaa->device), 1080 usbd_get_bus_index(uaa->device), 1081 usbd_get_device_index(uaa->device)); 1082 return (ENXIO); 1083 } 1084 uaa->driver_info = id->driver_info; 1085 return (BUS_PROBE_SPECIFIC); 1086 } 1087 1088 static int 1089 uftdi_attach(device_t dev) 1090 { 1091 struct usb_attach_arg *uaa = device_get_ivars(dev); 1092 struct uftdi_softc *sc = device_get_softc(dev); 1093 int error; 1094 1095 DPRINTF("\n"); 1096 1097 sc->sc_udev = uaa->device; 1098 sc->sc_dev = dev; 1099 sc->sc_unit = device_get_unit(dev); 1100 sc->sc_bitmode = UFTDI_BITMODE_NONE; 1101 1102 device_set_usb_desc(dev); 1103 mtx_init(&sc->sc_mtx, "uftdi", NULL, MTX_DEF); 1104 ucom_ref(&sc->sc_super_ucom); 1105 1106 uftdi_devtype_setup(sc, uaa); 1107 1108 error = usbd_transfer_setup(uaa->device, 1109 &uaa->info.bIfaceIndex, sc->sc_xfer, uftdi_config, 1110 UFTDI_N_TRANSFER, sc, &sc->sc_mtx); 1111 1112 if (error) { 1113 device_printf(dev, "allocating USB " 1114 "transfers failed\n"); 1115 goto detach; 1116 } 1117 /* clear stall at first run */ 1118 mtx_lock(&sc->sc_mtx); 1119 usbd_xfer_set_stall(sc->sc_xfer[UFTDI_BULK_DT_WR]); 1120 usbd_xfer_set_stall(sc->sc_xfer[UFTDI_BULK_DT_RD]); 1121 mtx_unlock(&sc->sc_mtx); 1122 1123 /* set a valid "lcr" value */ 1124 1125 sc->sc_last_lcr = 1126 (FTDI_SIO_SET_DATA_STOP_BITS_2 | 1127 FTDI_SIO_SET_DATA_PARITY_NONE | 1128 FTDI_SIO_SET_DATA_BITS(8)); 1129 1130 /* Indicate tx bits in sc_lsr can be used to determine busy vs idle. */ 1131 ucom_use_lsr_txbits(&sc->sc_ucom); 1132 1133 error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc, 1134 &uftdi_callback, &sc->sc_mtx); 1135 if (error) { 1136 goto detach; 1137 } 1138 ucom_set_pnpinfo_usb(&sc->sc_super_ucom, dev); 1139 1140 return (0); /* success */ 1141 1142 detach: 1143 uftdi_detach(dev); 1144 return (ENXIO); 1145 } 1146 1147 static int 1148 uftdi_detach(device_t dev) 1149 { 1150 struct uftdi_softc *sc = device_get_softc(dev); 1151 1152 ucom_detach(&sc->sc_super_ucom, &sc->sc_ucom); 1153 usbd_transfer_unsetup(sc->sc_xfer, UFTDI_N_TRANSFER); 1154 1155 device_claim_softc(dev); 1156 1157 uftdi_free_softc(sc); 1158 1159 return (0); 1160 } 1161 1162 UCOM_UNLOAD_DRAIN(uftdi); 1163 1164 static void 1165 uftdi_free_softc(struct uftdi_softc *sc) 1166 { 1167 if (ucom_unref(&sc->sc_super_ucom)) { 1168 mtx_destroy(&sc->sc_mtx); 1169 device_free_softc(sc); 1170 } 1171 } 1172 1173 static void 1174 uftdi_free(struct ucom_softc *ucom) 1175 { 1176 uftdi_free_softc(ucom->sc_parent); 1177 } 1178 1179 static void 1180 uftdi_cfg_open(struct ucom_softc *ucom) 1181 { 1182 1183 /* 1184 * This do-nothing open routine exists for the sole purpose of this 1185 * DPRINTF() so that you can see the point at which open gets called 1186 * when debugging is enabled. 1187 */ 1188 DPRINTF("\n"); 1189 } 1190 1191 static void 1192 uftdi_cfg_close(struct ucom_softc *ucom) 1193 { 1194 1195 /* 1196 * This do-nothing close routine exists for the sole purpose of this 1197 * DPRINTF() so that you can see the point at which close gets called 1198 * when debugging is enabled. 1199 */ 1200 DPRINTF("\n"); 1201 } 1202 1203 static void 1204 uftdi_write_callback(struct usb_xfer *xfer, usb_error_t error) 1205 { 1206 struct uftdi_softc *sc = usbd_xfer_softc(xfer); 1207 struct usb_page_cache *pc; 1208 uint32_t pktlen; 1209 uint32_t buflen; 1210 uint8_t buf[1]; 1211 1212 DPRINTFN(3, "\n"); 1213 1214 switch (USB_GET_STATE(xfer)) { 1215 default: /* Error */ 1216 if (error != USB_ERR_CANCELLED) { 1217 /* try to clear stall first */ 1218 usbd_xfer_set_stall(xfer); 1219 } 1220 /* FALLTHROUGH */ 1221 case USB_ST_SETUP: 1222 case USB_ST_TRANSFERRED: 1223 /* 1224 * If output packets don't require headers (the common case) we 1225 * can just load the buffer up with payload bytes all at once. 1226 * Otherwise, loop to format packets into the buffer while there 1227 * is data available, and room for a packet header and at least 1228 * one byte of payload. 1229 * 1230 * NOTE: The FTDI chip doesn't accept zero length 1231 * packets. This cannot happen because the "pktlen" 1232 * will always be non-zero when "ucom_get_data()" 1233 * returns non-zero which we check below. 1234 */ 1235 pc = usbd_xfer_get_frame(xfer, 0); 1236 if (sc->sc_hdrlen == 0) { 1237 if (ucom_get_data(&sc->sc_ucom, pc, 0, UFTDI_OBUFSIZE, 1238 &buflen) == 0) 1239 break; 1240 } else { 1241 buflen = 0; 1242 while (buflen < UFTDI_OBUFSIZE - sc->sc_hdrlen - 1 && 1243 ucom_get_data(&sc->sc_ucom, pc, buflen + 1244 sc->sc_hdrlen, UFTDI_OPKTSIZE - sc->sc_hdrlen, 1245 &pktlen) != 0) { 1246 buf[0] = FTDI_OUT_TAG(pktlen, 1247 sc->sc_ucom.sc_portno); 1248 usbd_copy_in(pc, buflen, buf, 1); 1249 buflen += pktlen + sc->sc_hdrlen; 1250 } 1251 } 1252 if (buflen != 0) { 1253 usbd_xfer_set_frame_len(xfer, 0, buflen); 1254 usbd_transfer_submit(xfer); 1255 } 1256 break; 1257 } 1258 } 1259 1260 static void 1261 uftdi_read_callback(struct usb_xfer *xfer, usb_error_t error) 1262 { 1263 struct uftdi_softc *sc = usbd_xfer_softc(xfer); 1264 struct usb_page_cache *pc; 1265 uint8_t buf[2]; 1266 uint8_t ftdi_msr; 1267 uint8_t msr; 1268 uint8_t lsr; 1269 int buflen; 1270 int pktlen; 1271 int pktmax; 1272 int offset; 1273 1274 DPRINTFN(3, "\n"); 1275 1276 usbd_xfer_status(xfer, &buflen, NULL, NULL, NULL); 1277 1278 switch (USB_GET_STATE(xfer)) { 1279 case USB_ST_TRANSFERRED: 1280 if (buflen < UFTDI_IHDRSIZE) 1281 goto tr_setup; 1282 pc = usbd_xfer_get_frame(xfer, 0); 1283 pktmax = xfer->max_packet_size - UFTDI_IHDRSIZE; 1284 lsr = 0; 1285 msr = 0; 1286 offset = 0; 1287 /* 1288 * Extract packet headers and payload bytes from the buffer. 1289 * Feed payload bytes to ucom/tty layer; OR-accumulate the 1290 * receiver-related header status bits which are transient and 1291 * could toggle with each packet, but for transmitter-related 1292 * bits keep only the ones from the last packet. 1293 * 1294 * After processing all packets in the buffer, process the 1295 * accumulated transient MSR and LSR values along with the 1296 * non-transient bits from the last packet header. 1297 */ 1298 while (buflen >= UFTDI_IHDRSIZE) { 1299 usbd_copy_out(pc, offset, buf, UFTDI_IHDRSIZE); 1300 offset += UFTDI_IHDRSIZE; 1301 buflen -= UFTDI_IHDRSIZE; 1302 lsr &= ~(ULSR_TXRDY | ULSR_TSRE); 1303 lsr |= FTDI_GET_LSR(buf); 1304 if (FTDI_GET_MSR(buf) & FTDI_SIO_RI_MASK) 1305 msr |= SER_RI; 1306 pktlen = min(buflen, pktmax); 1307 if (pktlen != 0) { 1308 ucom_put_data(&sc->sc_ucom, pc, offset, 1309 pktlen); 1310 offset += pktlen; 1311 buflen -= pktlen; 1312 } 1313 } 1314 ftdi_msr = FTDI_GET_MSR(buf); 1315 1316 if (ftdi_msr & FTDI_SIO_CTS_MASK) 1317 msr |= SER_CTS; 1318 if (ftdi_msr & FTDI_SIO_DSR_MASK) 1319 msr |= SER_DSR; 1320 if (ftdi_msr & FTDI_SIO_RI_MASK) 1321 msr |= SER_RI; 1322 if (ftdi_msr & FTDI_SIO_RLSD_MASK) 1323 msr |= SER_DCD; 1324 1325 if (sc->sc_msr != msr || sc->sc_lsr != lsr) { 1326 DPRINTF("status change msr=0x%02x (0x%02x) " 1327 "lsr=0x%02x (0x%02x)\n", msr, sc->sc_msr, 1328 lsr, sc->sc_lsr); 1329 1330 sc->sc_msr = msr; 1331 sc->sc_lsr = lsr; 1332 1333 ucom_status_change(&sc->sc_ucom); 1334 } 1335 /* FALLTHROUGH */ 1336 case USB_ST_SETUP: 1337 tr_setup: 1338 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer)); 1339 usbd_transfer_submit(xfer); 1340 return; 1341 1342 default: /* Error */ 1343 if (error != USB_ERR_CANCELLED) { 1344 /* try to clear stall first */ 1345 usbd_xfer_set_stall(xfer); 1346 goto tr_setup; 1347 } 1348 return; 1349 } 1350 } 1351 1352 static void 1353 uftdi_cfg_set_dtr(struct ucom_softc *ucom, uint8_t onoff) 1354 { 1355 struct uftdi_softc *sc = ucom->sc_parent; 1356 uint16_t wIndex = ucom->sc_portno; 1357 uint16_t wValue; 1358 struct usb_device_request req; 1359 1360 DPRINTFN(2, "DTR=%u\n", onoff); 1361 1362 wValue = onoff ? FTDI_SIO_SET_DTR_HIGH : FTDI_SIO_SET_DTR_LOW; 1363 1364 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1365 req.bRequest = FTDI_SIO_MODEM_CTRL; 1366 USETW(req.wValue, wValue); 1367 USETW(req.wIndex, wIndex); 1368 USETW(req.wLength, 0); 1369 ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 1370 &req, NULL, 0, 1000); 1371 } 1372 1373 static void 1374 uftdi_cfg_set_rts(struct ucom_softc *ucom, uint8_t onoff) 1375 { 1376 struct uftdi_softc *sc = ucom->sc_parent; 1377 uint16_t wIndex = ucom->sc_portno; 1378 uint16_t wValue; 1379 struct usb_device_request req; 1380 1381 DPRINTFN(2, "RTS=%u\n", onoff); 1382 1383 wValue = onoff ? FTDI_SIO_SET_RTS_HIGH : FTDI_SIO_SET_RTS_LOW; 1384 1385 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1386 req.bRequest = FTDI_SIO_MODEM_CTRL; 1387 USETW(req.wValue, wValue); 1388 USETW(req.wIndex, wIndex); 1389 USETW(req.wLength, 0); 1390 ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 1391 &req, NULL, 0, 1000); 1392 } 1393 1394 static void 1395 uftdi_cfg_set_break(struct ucom_softc *ucom, uint8_t onoff) 1396 { 1397 struct uftdi_softc *sc = ucom->sc_parent; 1398 uint16_t wIndex = ucom->sc_portno; 1399 uint16_t wValue; 1400 struct usb_device_request req; 1401 1402 DPRINTFN(2, "BREAK=%u\n", onoff); 1403 1404 if (onoff) { 1405 sc->sc_last_lcr |= FTDI_SIO_SET_BREAK; 1406 } else { 1407 sc->sc_last_lcr &= ~FTDI_SIO_SET_BREAK; 1408 } 1409 1410 wValue = sc->sc_last_lcr; 1411 1412 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1413 req.bRequest = FTDI_SIO_SET_DATA; 1414 USETW(req.wValue, wValue); 1415 USETW(req.wIndex, wIndex); 1416 USETW(req.wLength, 0); 1417 ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 1418 &req, NULL, 0, 1000); 1419 } 1420 1421 /* 1422 * Return true if the given speed is within operational tolerance of the target 1423 * speed. FTDI recommends that the hardware speed be within 3% of nominal. 1424 */ 1425 static inline boolean_t 1426 uftdi_baud_within_tolerance(uint64_t speed, uint64_t target) 1427 { 1428 return ((speed >= (target * 100) / 103) && 1429 (speed <= (target * 100) / 97)); 1430 } 1431 1432 static int 1433 uftdi_sio_encode_baudrate(struct uftdi_softc *sc, speed_t speed, 1434 struct uftdi_param_config *cfg) 1435 { 1436 u_int i; 1437 const speed_t sio_speeds[] = { 1438 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200 1439 }; 1440 1441 /* 1442 * The original SIO chips were limited to a small choice of speeds 1443 * listed in an internal table of speeds chosen by an index value. 1444 */ 1445 for (i = 0; i < nitems(sio_speeds); ++i) { 1446 if (speed == sio_speeds[i]) { 1447 cfg->baud_lobits = i; 1448 cfg->baud_hibits = 0; 1449 return (0); 1450 } 1451 } 1452 return (ERANGE); 1453 } 1454 1455 static int 1456 uftdi_encode_baudrate(struct uftdi_softc *sc, speed_t speed, 1457 struct uftdi_param_config *cfg) 1458 { 1459 static const uint8_t encoded_fraction[8] = {0, 3, 2, 4, 1, 5, 6, 7}; 1460 static const uint8_t roundoff_232a[16] = { 1461 0, 1, 0, 1, 0, -1, 2, 1, 1462 0, -1, -2, -3, 4, 3, 2, 1, 1463 }; 1464 uint32_t clk, divisor, fastclk_flag, frac, hwspeed; 1465 1466 /* 1467 * If this chip has the fast clock capability and the speed is within 1468 * range, use the 12MHz clock, otherwise the standard clock is 3MHz. 1469 */ 1470 if ((sc->sc_devflags & DEVF_BAUDCLK_12M) && speed >= 1200) { 1471 clk = 12000000; 1472 fastclk_flag = (1 << 17); 1473 } else { 1474 clk = 3000000; 1475 fastclk_flag = 0; 1476 } 1477 1478 /* 1479 * Make sure the requested speed is reachable with the available clock 1480 * and a 14-bit divisor. 1481 */ 1482 if (speed < (clk >> 14) || speed > clk) 1483 return (ERANGE); 1484 1485 /* 1486 * Calculate the divisor, initially yielding a fixed point number with a 1487 * 4-bit (1/16ths) fraction, then round it to the nearest fraction the 1488 * hardware can handle. When the integral part of the divisor is 1489 * greater than one, the fractional part is in 1/8ths of the base clock. 1490 * The FT8U232AM chips can handle only 0.125, 0.250, and 0.5 fractions. 1491 * Later chips can handle all 1/8th fractions. 1492 * 1493 * If the integral part of the divisor is 1, a special rule applies: the 1494 * fractional part can only be .0 or .5 (this is a limitation of the 1495 * hardware). We handle this by truncating the fraction rather than 1496 * rounding, because this only applies to the two fastest speeds the 1497 * chip can achieve and rounding doesn't matter, either you've asked for 1498 * that exact speed or you've asked for something the chip can't do. 1499 * 1500 * For the FT8U232AM chips, use a roundoff table to adjust the result 1501 * to the nearest 1/8th fraction that is supported by the hardware, 1502 * leaving a fixed-point number with a 3-bit fraction which exactly 1503 * represents the math the hardware divider will do. For later-series 1504 * chips that support all 8 fractional divisors, just round 16ths to 1505 * 8ths by adding 1 and dividing by 2. 1506 */ 1507 divisor = (clk << 4) / speed; 1508 if ((divisor & 0xf) == 1) 1509 divisor &= 0xfffffff8; 1510 else if (sc->sc_devtype == DEVT_232A) 1511 divisor += roundoff_232a[divisor & 0x0f]; 1512 else 1513 divisor += 1; /* Rounds odd 16ths up to next 8th. */ 1514 divisor >>= 1; 1515 1516 /* 1517 * Ensure the resulting hardware speed will be within operational 1518 * tolerance (within 3% of nominal). 1519 */ 1520 hwspeed = (clk << 3) / divisor; 1521 if (!uftdi_baud_within_tolerance(hwspeed, speed)) 1522 return (ERANGE); 1523 1524 /* 1525 * Re-pack the divisor into hardware format. The lower 14-bits hold the 1526 * integral part, while the upper bits specify the fraction by indexing 1527 * a table of fractions within the hardware which is laid out as: 1528 * {0.0, 0.5, 0.25, 0.125, 0.325, 0.625, 0.725, 0.875} 1529 * The A-series chips only have the first four table entries; the 1530 * roundoff table logic above ensures that the fractional part for those 1531 * chips will be one of the first four values. 1532 * 1533 * When the divisor is 1 a special encoding applies: 1.0 is encoded as 1534 * 0.0, and 1.5 is encoded as 1.0. The rounding logic above has already 1535 * ensured that the fraction is either .0 or .5 if the integral is 1. 1536 */ 1537 frac = divisor & 0x07; 1538 divisor >>= 3; 1539 if (divisor == 1) { 1540 if (frac == 0) 1541 divisor = 0; /* 1.0 becomes 0.0 */ 1542 else 1543 frac = 0; /* 1.5 becomes 1.0 */ 1544 } 1545 divisor |= (encoded_fraction[frac] << 14) | fastclk_flag; 1546 1547 cfg->baud_lobits = (uint16_t)divisor; 1548 cfg->baud_hibits = (uint16_t)(divisor >> 16); 1549 1550 /* 1551 * If this chip requires the baud bits to be in the high byte of the 1552 * index word, move the bits up to that location. 1553 */ 1554 if (sc->sc_devflags & DEVF_BAUDBITS_HINDEX) { 1555 cfg->baud_hibits <<= 8; 1556 } 1557 1558 return (0); 1559 } 1560 1561 static int 1562 uftdi_set_parm_soft(struct ucom_softc *ucom, struct termios *t, 1563 struct uftdi_param_config *cfg) 1564 { 1565 struct uftdi_softc *sc = ucom->sc_parent; 1566 int err; 1567 1568 memset(cfg, 0, sizeof(*cfg)); 1569 1570 if (sc->sc_devtype == DEVT_SIO) 1571 err = uftdi_sio_encode_baudrate(sc, t->c_ospeed, cfg); 1572 else 1573 err = uftdi_encode_baudrate(sc, t->c_ospeed, cfg); 1574 if (err != 0) 1575 return (err); 1576 1577 if (t->c_cflag & CSTOPB) 1578 cfg->lcr = FTDI_SIO_SET_DATA_STOP_BITS_2; 1579 else 1580 cfg->lcr = FTDI_SIO_SET_DATA_STOP_BITS_1; 1581 1582 if (t->c_cflag & PARENB) { 1583 if (t->c_cflag & PARODD) { 1584 cfg->lcr |= FTDI_SIO_SET_DATA_PARITY_ODD; 1585 } else { 1586 cfg->lcr |= FTDI_SIO_SET_DATA_PARITY_EVEN; 1587 } 1588 } else { 1589 cfg->lcr |= FTDI_SIO_SET_DATA_PARITY_NONE; 1590 } 1591 1592 switch (t->c_cflag & CSIZE) { 1593 case CS5: 1594 cfg->lcr |= FTDI_SIO_SET_DATA_BITS(5); 1595 break; 1596 1597 case CS6: 1598 cfg->lcr |= FTDI_SIO_SET_DATA_BITS(6); 1599 break; 1600 1601 case CS7: 1602 cfg->lcr |= FTDI_SIO_SET_DATA_BITS(7); 1603 break; 1604 1605 case CS8: 1606 cfg->lcr |= FTDI_SIO_SET_DATA_BITS(8); 1607 break; 1608 } 1609 1610 if (t->c_cflag & CRTSCTS) { 1611 cfg->v_flow = FTDI_SIO_RTS_CTS_HS; 1612 } else if (t->c_iflag & (IXON | IXOFF)) { 1613 cfg->v_flow = FTDI_SIO_XON_XOFF_HS; 1614 cfg->v_start = t->c_cc[VSTART]; 1615 cfg->v_stop = t->c_cc[VSTOP]; 1616 } else { 1617 cfg->v_flow = FTDI_SIO_DISABLE_FLOW_CTRL; 1618 } 1619 1620 return (0); 1621 } 1622 1623 static int 1624 uftdi_pre_param(struct ucom_softc *ucom, struct termios *t) 1625 { 1626 struct uftdi_param_config cfg; 1627 1628 DPRINTF("\n"); 1629 1630 return (uftdi_set_parm_soft(ucom, t, &cfg)); 1631 } 1632 1633 static void 1634 uftdi_cfg_param(struct ucom_softc *ucom, struct termios *t) 1635 { 1636 struct uftdi_softc *sc = ucom->sc_parent; 1637 uint16_t wIndex = ucom->sc_portno; 1638 struct uftdi_param_config cfg; 1639 struct usb_device_request req; 1640 1641 DPRINTF("\n"); 1642 1643 if (uftdi_set_parm_soft(ucom, t, &cfg)) { 1644 /* should not happen */ 1645 return; 1646 } 1647 sc->sc_last_lcr = cfg.lcr; 1648 1649 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1650 req.bRequest = FTDI_SIO_SET_BAUD_RATE; 1651 USETW(req.wValue, cfg.baud_lobits); 1652 USETW(req.wIndex, cfg.baud_hibits | wIndex); 1653 USETW(req.wLength, 0); 1654 ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 1655 &req, NULL, 0, 1000); 1656 1657 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1658 req.bRequest = FTDI_SIO_SET_DATA; 1659 USETW(req.wValue, cfg.lcr); 1660 USETW(req.wIndex, wIndex); 1661 USETW(req.wLength, 0); 1662 ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 1663 &req, NULL, 0, 1000); 1664 1665 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1666 req.bRequest = FTDI_SIO_SET_FLOW_CTRL; 1667 USETW2(req.wValue, cfg.v_stop, cfg.v_start); 1668 USETW2(req.wIndex, cfg.v_flow, wIndex); 1669 USETW(req.wLength, 0); 1670 ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 1671 &req, NULL, 0, 1000); 1672 } 1673 1674 static void 1675 uftdi_cfg_get_status(struct ucom_softc *ucom, uint8_t *lsr, uint8_t *msr) 1676 { 1677 struct uftdi_softc *sc = ucom->sc_parent; 1678 1679 DPRINTFN(3, "msr=0x%02x lsr=0x%02x\n", sc->sc_msr, sc->sc_lsr); 1680 1681 *msr = sc->sc_msr; 1682 *lsr = sc->sc_lsr; 1683 } 1684 1685 static int 1686 uftdi_reset(struct ucom_softc *ucom, int reset_type) 1687 { 1688 struct uftdi_softc *sc = ucom->sc_parent; 1689 usb_device_request_t req; 1690 1691 DPRINTFN(2, "\n"); 1692 1693 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1694 req.bRequest = FTDI_SIO_RESET; 1695 1696 USETW(req.wIndex, sc->sc_ucom.sc_portno); 1697 USETW(req.wLength, 0); 1698 USETW(req.wValue, reset_type); 1699 1700 return (usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, NULL)); 1701 } 1702 1703 static int 1704 uftdi_set_bitmode(struct ucom_softc *ucom, uint8_t bitmode, uint8_t iomask) 1705 { 1706 struct uftdi_softc *sc = ucom->sc_parent; 1707 usb_device_request_t req; 1708 int rv; 1709 1710 DPRINTFN(2, "\n"); 1711 1712 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1713 req.bRequest = FTDI_SIO_SET_BITMODE; 1714 1715 USETW(req.wIndex, sc->sc_ucom.sc_portno); 1716 USETW(req.wLength, 0); 1717 1718 if (bitmode == UFTDI_BITMODE_NONE) 1719 USETW2(req.wValue, 0, 0); 1720 else 1721 USETW2(req.wValue, (1 << bitmode), iomask); 1722 1723 rv = usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, NULL); 1724 if (rv == USB_ERR_NORMAL_COMPLETION) 1725 sc->sc_bitmode = bitmode; 1726 1727 return (rv); 1728 } 1729 1730 static int 1731 uftdi_get_bitmode(struct ucom_softc *ucom, uint8_t *bitmode, uint8_t *iomask) 1732 { 1733 struct uftdi_softc *sc = ucom->sc_parent; 1734 usb_device_request_t req; 1735 1736 DPRINTFN(2, "\n"); 1737 1738 req.bmRequestType = UT_READ_VENDOR_DEVICE; 1739 req.bRequest = FTDI_SIO_GET_BITMODE; 1740 1741 USETW(req.wIndex, sc->sc_ucom.sc_portno); 1742 USETW(req.wLength, 1); 1743 USETW(req.wValue, 0); 1744 1745 *bitmode = sc->sc_bitmode; 1746 return (usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, iomask)); 1747 } 1748 1749 static int 1750 uftdi_set_latency(struct ucom_softc *ucom, int latency) 1751 { 1752 struct uftdi_softc *sc = ucom->sc_parent; 1753 usb_device_request_t req; 1754 1755 DPRINTFN(2, "\n"); 1756 1757 if (latency < 0 || latency > 255) 1758 return (USB_ERR_INVAL); 1759 1760 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1761 req.bRequest = FTDI_SIO_SET_LATENCY; 1762 1763 USETW(req.wIndex, sc->sc_ucom.sc_portno); 1764 USETW(req.wLength, 0); 1765 USETW2(req.wValue, 0, latency); 1766 1767 return (usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, NULL)); 1768 } 1769 1770 static int 1771 uftdi_get_latency(struct ucom_softc *ucom, int *latency) 1772 { 1773 struct uftdi_softc *sc = ucom->sc_parent; 1774 usb_device_request_t req; 1775 usb_error_t err; 1776 uint8_t buf; 1777 1778 DPRINTFN(2, "\n"); 1779 1780 req.bmRequestType = UT_READ_VENDOR_DEVICE; 1781 req.bRequest = FTDI_SIO_GET_LATENCY; 1782 1783 USETW(req.wIndex, sc->sc_ucom.sc_portno); 1784 USETW(req.wLength, 1); 1785 USETW(req.wValue, 0); 1786 1787 err = usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, &buf); 1788 *latency = buf; 1789 1790 return (err); 1791 } 1792 1793 static int 1794 uftdi_set_event_char(struct ucom_softc *ucom, int echar) 1795 { 1796 struct uftdi_softc *sc = ucom->sc_parent; 1797 usb_device_request_t req; 1798 uint8_t enable; 1799 1800 DPRINTFN(2, "\n"); 1801 1802 enable = (echar == -1) ? 0 : 1; 1803 1804 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1805 req.bRequest = FTDI_SIO_SET_EVENT_CHAR; 1806 1807 USETW(req.wIndex, sc->sc_ucom.sc_portno); 1808 USETW(req.wLength, 0); 1809 USETW2(req.wValue, enable, echar & 0xff); 1810 1811 return (usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, NULL)); 1812 } 1813 1814 static int 1815 uftdi_set_error_char(struct ucom_softc *ucom, int echar) 1816 { 1817 struct uftdi_softc *sc = ucom->sc_parent; 1818 usb_device_request_t req; 1819 uint8_t enable; 1820 1821 DPRINTFN(2, "\n"); 1822 1823 enable = (echar == -1) ? 0 : 1; 1824 1825 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1826 req.bRequest = FTDI_SIO_SET_ERROR_CHAR; 1827 1828 USETW(req.wIndex, sc->sc_ucom.sc_portno); 1829 USETW(req.wLength, 0); 1830 USETW2(req.wValue, enable, echar & 0xff); 1831 1832 return (usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, NULL)); 1833 } 1834 1835 static int 1836 uftdi_read_eeprom(struct ucom_softc *ucom, struct uftdi_eeio *eeio) 1837 { 1838 struct uftdi_softc *sc = ucom->sc_parent; 1839 usb_device_request_t req; 1840 usb_error_t err; 1841 uint16_t widx, wlength, woffset; 1842 1843 DPRINTFN(3, "\n"); 1844 1845 /* Offset and length must both be evenly divisible by two. */ 1846 if ((eeio->offset | eeio->length) & 0x01) 1847 return (EINVAL); 1848 1849 woffset = eeio->offset / 2U; 1850 wlength = eeio->length / 2U; 1851 for (widx = 0; widx < wlength; widx++) { 1852 req.bmRequestType = UT_READ_VENDOR_DEVICE; 1853 req.bRequest = FTDI_SIO_READ_EEPROM; 1854 USETW(req.wIndex, widx + woffset); 1855 USETW(req.wLength, 2); 1856 USETW(req.wValue, 0); 1857 err = usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, 1858 &eeio->data[widx]); 1859 if (err != USB_ERR_NORMAL_COMPLETION) 1860 return (err); 1861 } 1862 return (USB_ERR_NORMAL_COMPLETION); 1863 } 1864 1865 static int 1866 uftdi_write_eeprom(struct ucom_softc *ucom, struct uftdi_eeio *eeio) 1867 { 1868 struct uftdi_softc *sc = ucom->sc_parent; 1869 usb_device_request_t req; 1870 usb_error_t err; 1871 uint16_t widx, wlength, woffset; 1872 1873 DPRINTFN(3, "\n"); 1874 1875 /* Offset and length must both be evenly divisible by two. */ 1876 if ((eeio->offset | eeio->length) & 0x01) 1877 return (EINVAL); 1878 1879 woffset = eeio->offset / 2U; 1880 wlength = eeio->length / 2U; 1881 for (widx = 0; widx < wlength; widx++) { 1882 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1883 req.bRequest = FTDI_SIO_WRITE_EEPROM; 1884 USETW(req.wIndex, widx + woffset); 1885 USETW(req.wLength, 0); 1886 USETW(req.wValue, eeio->data[widx]); 1887 err = usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, NULL); 1888 if (err != USB_ERR_NORMAL_COMPLETION) 1889 return (err); 1890 } 1891 return (USB_ERR_NORMAL_COMPLETION); 1892 } 1893 1894 static int 1895 uftdi_erase_eeprom(struct ucom_softc *ucom, int confirmation) 1896 { 1897 struct uftdi_softc *sc = ucom->sc_parent; 1898 usb_device_request_t req; 1899 usb_error_t err; 1900 1901 DPRINTFN(2, "\n"); 1902 1903 /* Small effort to prevent accidental erasure. */ 1904 if (confirmation != UFTDI_CONFIRM_ERASE) 1905 return (EINVAL); 1906 1907 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 1908 req.bRequest = FTDI_SIO_ERASE_EEPROM; 1909 USETW(req.wIndex, 0); 1910 USETW(req.wLength, 0); 1911 USETW(req.wValue, 0); 1912 err = usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, NULL); 1913 1914 return (err); 1915 } 1916 1917 static int 1918 uftdi_ioctl(struct ucom_softc *ucom, uint32_t cmd, caddr_t data, 1919 int flag, struct thread *td) 1920 { 1921 struct uftdi_softc *sc = ucom->sc_parent; 1922 int err; 1923 struct uftdi_bitmode * mode; 1924 1925 switch (cmd) { 1926 case UFTDIIOC_RESET_IO: 1927 case UFTDIIOC_RESET_RX: 1928 case UFTDIIOC_RESET_TX: 1929 err = uftdi_reset(ucom, 1930 cmd == UFTDIIOC_RESET_IO ? FTDI_SIO_RESET_SIO : 1931 (cmd == UFTDIIOC_RESET_RX ? FTDI_SIO_RESET_PURGE_RX : 1932 FTDI_SIO_RESET_PURGE_TX)); 1933 break; 1934 case UFTDIIOC_SET_BITMODE: 1935 mode = (struct uftdi_bitmode *)data; 1936 err = uftdi_set_bitmode(ucom, mode->mode, mode->iomask); 1937 break; 1938 case UFTDIIOC_GET_BITMODE: 1939 mode = (struct uftdi_bitmode *)data; 1940 err = uftdi_get_bitmode(ucom, &mode->mode, &mode->iomask); 1941 break; 1942 case UFTDIIOC_SET_LATENCY: 1943 err = uftdi_set_latency(ucom, *((int *)data)); 1944 break; 1945 case UFTDIIOC_GET_LATENCY: 1946 err = uftdi_get_latency(ucom, (int *)data); 1947 break; 1948 case UFTDIIOC_SET_ERROR_CHAR: 1949 err = uftdi_set_error_char(ucom, *(int *)data); 1950 break; 1951 case UFTDIIOC_SET_EVENT_CHAR: 1952 err = uftdi_set_event_char(ucom, *(int *)data); 1953 break; 1954 case UFTDIIOC_GET_HWREV: 1955 *(int *)data = sc->sc_bcdDevice; 1956 err = 0; 1957 break; 1958 case UFTDIIOC_READ_EEPROM: 1959 err = uftdi_read_eeprom(ucom, (struct uftdi_eeio *)data); 1960 break; 1961 case UFTDIIOC_WRITE_EEPROM: 1962 err = uftdi_write_eeprom(ucom, (struct uftdi_eeio *)data); 1963 break; 1964 case UFTDIIOC_ERASE_EEPROM: 1965 err = uftdi_erase_eeprom(ucom, *(int *)data); 1966 break; 1967 default: 1968 return (ENOIOCTL); 1969 } 1970 if (err != USB_ERR_NORMAL_COMPLETION) 1971 return (EIO); 1972 return (0); 1973 } 1974 1975 static void 1976 uftdi_start_read(struct ucom_softc *ucom) 1977 { 1978 struct uftdi_softc *sc = ucom->sc_parent; 1979 1980 usbd_transfer_start(sc->sc_xfer[UFTDI_BULK_DT_RD]); 1981 } 1982 1983 static void 1984 uftdi_stop_read(struct ucom_softc *ucom) 1985 { 1986 struct uftdi_softc *sc = ucom->sc_parent; 1987 1988 usbd_transfer_stop(sc->sc_xfer[UFTDI_BULK_DT_RD]); 1989 } 1990 1991 static void 1992 uftdi_start_write(struct ucom_softc *ucom) 1993 { 1994 struct uftdi_softc *sc = ucom->sc_parent; 1995 1996 usbd_transfer_start(sc->sc_xfer[UFTDI_BULK_DT_WR]); 1997 } 1998 1999 static void 2000 uftdi_stop_write(struct ucom_softc *ucom) 2001 { 2002 struct uftdi_softc *sc = ucom->sc_parent; 2003 2004 usbd_transfer_stop(sc->sc_xfer[UFTDI_BULK_DT_WR]); 2005 } 2006 2007 static void 2008 uftdi_poll(struct ucom_softc *ucom) 2009 { 2010 struct uftdi_softc *sc = ucom->sc_parent; 2011 2012 usbd_transfer_poll(sc->sc_xfer, UFTDI_N_TRANSFER); 2013 } 2014