uftdi.c revision 1.3.2.2 1 1.3.2.2 bouyer /* $NetBSD: uftdi.c,v 1.3.2.2 2000/11/20 11:43:23 bouyer Exp $ */
2 1.3.2.2 bouyer
3 1.3.2.2 bouyer /*
4 1.3.2.2 bouyer * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.3.2.2 bouyer * All rights reserved.
6 1.3.2.2 bouyer *
7 1.3.2.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
8 1.3.2.2 bouyer * by Lennart Augustsson (lennart (at) augustsson.net).
9 1.3.2.2 bouyer *
10 1.3.2.2 bouyer * Redistribution and use in source and binary forms, with or without
11 1.3.2.2 bouyer * modification, are permitted provided that the following conditions
12 1.3.2.2 bouyer * are met:
13 1.3.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
14 1.3.2.2 bouyer * notice, this list of conditions and the following disclaimer.
15 1.3.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
16 1.3.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
17 1.3.2.2 bouyer * documentation and/or other materials provided with the distribution.
18 1.3.2.2 bouyer * 3. All advertising materials mentioning features or use of this software
19 1.3.2.2 bouyer * must display the following acknowledgement:
20 1.3.2.2 bouyer * This product includes software developed by the NetBSD
21 1.3.2.2 bouyer * Foundation, Inc. and its contributors.
22 1.3.2.2 bouyer * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.3.2.2 bouyer * contributors may be used to endorse or promote products derived
24 1.3.2.2 bouyer * from this software without specific prior written permission.
25 1.3.2.2 bouyer *
26 1.3.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.3.2.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.3.2.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.3.2.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.3.2.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.3.2.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.3.2.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.3.2.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.3.2.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.3.2.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.3.2.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
37 1.3.2.2 bouyer */
38 1.3.2.2 bouyer
39 1.3.2.2 bouyer /*
40 1.3.2.2 bouyer * FTDI FT8U100AX serial adapter driver
41 1.3.2.2 bouyer */
42 1.3.2.2 bouyer
43 1.3.2.2 bouyer /*
44 1.3.2.2 bouyer * XXX This driver will not support multiple serial ports.
45 1.3.2.2 bouyer * XXX The ucom layer needs to be extended first.
46 1.3.2.2 bouyer */
47 1.3.2.2 bouyer
48 1.3.2.2 bouyer #include <sys/param.h>
49 1.3.2.2 bouyer #include <sys/systm.h>
50 1.3.2.2 bouyer #include <sys/kernel.h>
51 1.3.2.2 bouyer #include <sys/device.h>
52 1.3.2.2 bouyer #include <sys/conf.h>
53 1.3.2.2 bouyer #include <sys/tty.h>
54 1.3.2.2 bouyer
55 1.3.2.2 bouyer #include <dev/usb/usb.h>
56 1.3.2.2 bouyer #include <dev/usb/usbhid.h>
57 1.3.2.2 bouyer
58 1.3.2.2 bouyer #include <dev/usb/usbdi.h>
59 1.3.2.2 bouyer #include <dev/usb/usbdi_util.h>
60 1.3.2.2 bouyer #include <dev/usb/usbdevs.h>
61 1.3.2.2 bouyer
62 1.3.2.2 bouyer #include <dev/usb/ucomvar.h>
63 1.3.2.2 bouyer
64 1.3.2.2 bouyer #include <dev/usb/uftdireg.h>
65 1.3.2.2 bouyer
66 1.3.2.2 bouyer #ifdef UFTDI_DEBUG
67 1.3.2.2 bouyer #define DPRINTF(x) if (uftdidebug) printf x
68 1.3.2.2 bouyer #define DPRINTFN(n,x) if (uftdidebug>(n)) printf x
69 1.3.2.2 bouyer int uftdidebug = 15;
70 1.3.2.2 bouyer #else
71 1.3.2.2 bouyer #define DPRINTF(x)
72 1.3.2.2 bouyer #define DPRINTFN(n,x)
73 1.3.2.2 bouyer #endif
74 1.3.2.2 bouyer
75 1.3.2.2 bouyer #define UFTDI_CONFIG_INDEX 0
76 1.3.2.2 bouyer #define UFTDI_IFACE_INDEX 0
77 1.3.2.2 bouyer
78 1.3.2.2 bouyer
79 1.3.2.2 bouyer /*
80 1.3.2.2 bouyer * These are the maximum number of bytes transferred per frame.
81 1.3.2.2 bouyer * The output buffer size cannot be increased due to the size encoding.
82 1.3.2.2 bouyer */
83 1.3.2.2 bouyer #define UFTDIIBUFSIZE 64
84 1.3.2.2 bouyer #define UFTDIOBUFSIZE 64
85 1.3.2.2 bouyer
86 1.3.2.2 bouyer struct uftdi_softc {
87 1.3.2.2 bouyer USBBASEDEVICE sc_dev; /* base device */
88 1.3.2.2 bouyer usbd_device_handle sc_udev; /* device */
89 1.3.2.2 bouyer usbd_interface_handle sc_iface; /* interface */
90 1.3.2.2 bouyer
91 1.3.2.2 bouyer u_char sc_msr;
92 1.3.2.2 bouyer u_char sc_lsr;
93 1.3.2.2 bouyer
94 1.3.2.2 bouyer device_ptr_t sc_subdev;
95 1.3.2.2 bouyer
96 1.3.2.2 bouyer u_char sc_dying;
97 1.3.2.2 bouyer };
98 1.3.2.2 bouyer
99 1.3.2.2 bouyer Static void uftdi_get_status(void *, int portno, u_char *lsr, u_char *msr);
100 1.3.2.2 bouyer Static void uftdi_set(void *, int, int, int);
101 1.3.2.2 bouyer Static int uftdi_param(void *, int, struct termios *);
102 1.3.2.2 bouyer Static int uftdi_open(void *sc, int portno);
103 1.3.2.2 bouyer Static void uftdi_read(void *sc, int portno, u_char **ptr,u_int32_t *count);
104 1.3.2.2 bouyer Static void uftdi_write(void *sc, int portno, u_char *to, u_char *from,
105 1.3.2.2 bouyer u_int32_t *count);
106 1.3.2.2 bouyer
107 1.3.2.2 bouyer struct ucom_methods uftdi_methods = {
108 1.3.2.2 bouyer uftdi_get_status,
109 1.3.2.2 bouyer uftdi_set,
110 1.3.2.2 bouyer uftdi_param,
111 1.3.2.2 bouyer NULL,
112 1.3.2.2 bouyer uftdi_open,
113 1.3.2.2 bouyer NULL,
114 1.3.2.2 bouyer uftdi_read,
115 1.3.2.2 bouyer uftdi_write,
116 1.3.2.2 bouyer };
117 1.3.2.2 bouyer
118 1.3.2.2 bouyer USB_DECLARE_DRIVER(uftdi);
119 1.3.2.2 bouyer
120 1.3.2.2 bouyer USB_MATCH(uftdi)
121 1.3.2.2 bouyer {
122 1.3.2.2 bouyer USB_MATCH_START(uftdi, uaa);
123 1.3.2.2 bouyer
124 1.3.2.2 bouyer if (uaa->iface != NULL)
125 1.3.2.2 bouyer return (UMATCH_NONE);
126 1.3.2.2 bouyer
127 1.3.2.2 bouyer DPRINTFN(20,("uftdi: vendor=0x%x, product=0x%x\n",
128 1.3.2.2 bouyer uaa->vendor, uaa->product));
129 1.3.2.2 bouyer
130 1.3.2.2 bouyer if (uaa->vendor == USB_VENDOR_FTDI &&
131 1.3.2.2 bouyer uaa->product == USB_PRODUCT_FTDI_SERIAL)
132 1.3.2.2 bouyer return (UMATCH_VENDOR_PRODUCT);
133 1.3.2.2 bouyer
134 1.3.2.2 bouyer return (UMATCH_NONE);
135 1.3.2.2 bouyer }
136 1.3.2.2 bouyer
137 1.3.2.2 bouyer USB_ATTACH(uftdi)
138 1.3.2.2 bouyer {
139 1.3.2.2 bouyer USB_ATTACH_START(uftdi, sc, uaa);
140 1.3.2.2 bouyer usbd_device_handle dev = uaa->device;
141 1.3.2.2 bouyer usbd_interface_handle iface;
142 1.3.2.2 bouyer usb_interface_descriptor_t *id;
143 1.3.2.2 bouyer usb_endpoint_descriptor_t *ed;
144 1.3.2.2 bouyer char devinfo[1024];
145 1.3.2.2 bouyer char *devname = USBDEVNAME(sc->sc_dev);
146 1.3.2.2 bouyer int i;
147 1.3.2.2 bouyer usbd_status err;
148 1.3.2.2 bouyer struct ucom_attach_args uca;
149 1.3.2.2 bouyer
150 1.3.2.2 bouyer DPRINTFN(10,("\nuftdi_attach: sc=%p\n", sc));
151 1.3.2.2 bouyer
152 1.3.2.2 bouyer /* Move the device into the configured state. */
153 1.3.2.2 bouyer err = usbd_set_config_index(dev, UFTDI_CONFIG_INDEX, 1);
154 1.3.2.2 bouyer if (err) {
155 1.3.2.2 bouyer printf("\n%s: failed to set configuration, err=%s\n",
156 1.3.2.2 bouyer devname, usbd_errstr(err));
157 1.3.2.2 bouyer goto bad;
158 1.3.2.2 bouyer }
159 1.3.2.2 bouyer
160 1.3.2.2 bouyer err = usbd_device2interface_handle(dev, UFTDI_IFACE_INDEX, &iface);
161 1.3.2.2 bouyer if (err) {
162 1.3.2.2 bouyer printf("\n%s: failed to get interface, err=%s\n",
163 1.3.2.2 bouyer devname, usbd_errstr(err));
164 1.3.2.2 bouyer goto bad;
165 1.3.2.2 bouyer }
166 1.3.2.2 bouyer
167 1.3.2.2 bouyer usbd_devinfo(dev, 0, devinfo);
168 1.3.2.2 bouyer USB_ATTACH_SETUP;
169 1.3.2.2 bouyer printf("%s: %s\n", devname, devinfo);
170 1.3.2.2 bouyer
171 1.3.2.2 bouyer id = usbd_get_interface_descriptor(iface);
172 1.3.2.2 bouyer
173 1.3.2.2 bouyer sc->sc_udev = dev;
174 1.3.2.2 bouyer sc->sc_iface = iface;
175 1.3.2.2 bouyer
176 1.3.2.2 bouyer uca.bulkin = uca.bulkout = -1;
177 1.3.2.2 bouyer for (i = 0; i < id->bNumEndpoints; i++) {
178 1.3.2.2 bouyer int addr, dir, attr;
179 1.3.2.2 bouyer ed = usbd_interface2endpoint_descriptor(iface, i);
180 1.3.2.2 bouyer if (ed == NULL) {
181 1.3.2.2 bouyer printf("%s: could not read endpoint descriptor"
182 1.3.2.2 bouyer ": %s\n", devname, usbd_errstr(err));
183 1.3.2.2 bouyer goto bad;
184 1.3.2.2 bouyer }
185 1.3.2.2 bouyer
186 1.3.2.2 bouyer addr = ed->bEndpointAddress;
187 1.3.2.2 bouyer dir = UE_GET_DIR(ed->bEndpointAddress);
188 1.3.2.2 bouyer attr = ed->bmAttributes & UE_XFERTYPE;
189 1.3.2.2 bouyer if (dir == UE_DIR_IN && attr == UE_BULK)
190 1.3.2.2 bouyer uca.bulkin = addr;
191 1.3.2.2 bouyer else if (dir == UE_DIR_OUT && attr == UE_BULK)
192 1.3.2.2 bouyer uca.bulkout = addr;
193 1.3.2.2 bouyer else {
194 1.3.2.2 bouyer printf("%s: unexpected endpoint\n", devname);
195 1.3.2.2 bouyer goto bad;
196 1.3.2.2 bouyer }
197 1.3.2.2 bouyer }
198 1.3.2.2 bouyer if (uca.bulkin == -1) {
199 1.3.2.2 bouyer printf("%s: Could not find data bulk in\n",
200 1.3.2.2 bouyer USBDEVNAME(sc->sc_dev));
201 1.3.2.2 bouyer goto bad;
202 1.3.2.2 bouyer }
203 1.3.2.2 bouyer if (uca.bulkout == -1) {
204 1.3.2.2 bouyer printf("%s: Could not find data bulk out\n",
205 1.3.2.2 bouyer USBDEVNAME(sc->sc_dev));
206 1.3.2.2 bouyer goto bad;
207 1.3.2.2 bouyer }
208 1.3.2.2 bouyer
209 1.3.2.2 bouyer uca.portno = FTDI_PIT_SIOA;
210 1.3.2.2 bouyer /* bulkin, bulkout set above */
211 1.3.2.2 bouyer uca.ibufsize = UFTDIIBUFSIZE;
212 1.3.2.2 bouyer uca.obufsize = UFTDIOBUFSIZE - 1;
213 1.3.2.2 bouyer uca.ibufsizepad = UFTDIIBUFSIZE;
214 1.3.2.2 bouyer uca.opkthdrlen = 1;
215 1.3.2.2 bouyer uca.device = dev;
216 1.3.2.2 bouyer uca.iface = iface;
217 1.3.2.2 bouyer uca.methods = &uftdi_methods;
218 1.3.2.2 bouyer uca.arg = sc;
219 1.3.2.2 bouyer
220 1.3.2.2 bouyer DPRINTF(("uftdi: in=0x%x out=0x%x\n", uca.bulkin, uca.bulkout));
221 1.3.2.2 bouyer sc->sc_subdev = config_found_sm(self, &uca, ucomprint, ucomsubmatch);
222 1.3.2.2 bouyer
223 1.3.2.2 bouyer USB_ATTACH_SUCCESS_RETURN;
224 1.3.2.2 bouyer
225 1.3.2.2 bouyer bad:
226 1.3.2.2 bouyer DPRINTF(("uftdi_attach: ATTACH ERROR\n"));
227 1.3.2.2 bouyer sc->sc_dying = 1;
228 1.3.2.2 bouyer USB_ATTACH_ERROR_RETURN;
229 1.3.2.2 bouyer }
230 1.3.2.2 bouyer
231 1.3.2.2 bouyer int
232 1.3.2.2 bouyer uftdi_activate(device_ptr_t self, enum devact act)
233 1.3.2.2 bouyer {
234 1.3.2.2 bouyer struct uftdi_softc *sc = (struct uftdi_softc *)self;
235 1.3.2.2 bouyer int rv = 0;
236 1.3.2.2 bouyer
237 1.3.2.2 bouyer switch (act) {
238 1.3.2.2 bouyer case DVACT_ACTIVATE:
239 1.3.2.2 bouyer return (EOPNOTSUPP);
240 1.3.2.2 bouyer break;
241 1.3.2.2 bouyer
242 1.3.2.2 bouyer case DVACT_DEACTIVATE:
243 1.3.2.2 bouyer if (sc->sc_subdev != NULL)
244 1.3.2.2 bouyer rv = config_deactivate(sc->sc_subdev);
245 1.3.2.2 bouyer sc->sc_dying = 1;
246 1.3.2.2 bouyer break;
247 1.3.2.2 bouyer }
248 1.3.2.2 bouyer return (rv);
249 1.3.2.2 bouyer }
250 1.3.2.2 bouyer
251 1.3.2.2 bouyer int
252 1.3.2.2 bouyer uftdi_detach(device_ptr_t self, int flags)
253 1.3.2.2 bouyer {
254 1.3.2.2 bouyer struct uftdi_softc *sc = (struct uftdi_softc *)self;
255 1.3.2.2 bouyer int rv = 0;
256 1.3.2.2 bouyer
257 1.3.2.2 bouyer DPRINTF(("uftdi_detach: sc=%p flags=%d\n", sc, flags));
258 1.3.2.2 bouyer sc->sc_dying = 1;
259 1.3.2.2 bouyer if (sc->sc_subdev != NULL) {
260 1.3.2.2 bouyer rv = config_detach(sc->sc_subdev, flags);
261 1.3.2.2 bouyer sc->sc_subdev = NULL;
262 1.3.2.2 bouyer }
263 1.3.2.2 bouyer return (0);
264 1.3.2.2 bouyer }
265 1.3.2.2 bouyer
266 1.3.2.2 bouyer Static int
267 1.3.2.2 bouyer uftdi_open(void *vsc, int portno)
268 1.3.2.2 bouyer {
269 1.3.2.2 bouyer struct uftdi_softc *sc = vsc;
270 1.3.2.2 bouyer usb_device_request_t req;
271 1.3.2.2 bouyer usbd_status err;
272 1.3.2.2 bouyer struct termios t;
273 1.3.2.2 bouyer
274 1.3.2.2 bouyer DPRINTF(("uftdi_open: sc=%p\n", sc));
275 1.3.2.2 bouyer
276 1.3.2.2 bouyer if (sc->sc_dying)
277 1.3.2.2 bouyer return (EIO);
278 1.3.2.2 bouyer
279 1.3.2.2 bouyer /* Perform a full reset on the device */
280 1.3.2.2 bouyer req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
281 1.3.2.2 bouyer req.bRequest = FTDI_SIO_RESET;
282 1.3.2.2 bouyer USETW(req.wValue, FTDI_SIO_RESET_SIO);
283 1.3.2.2 bouyer USETW(req.wIndex, portno);
284 1.3.2.2 bouyer USETW(req.wLength, 0);
285 1.3.2.2 bouyer err = usbd_do_request(sc->sc_udev, &req, NULL);
286 1.3.2.2 bouyer if (err)
287 1.3.2.2 bouyer return (EIO);
288 1.3.2.2 bouyer
289 1.3.2.2 bouyer /* Set 9600 baud, 2 stop bits, no parity, 8 bits */
290 1.3.2.2 bouyer t.c_ospeed = 9600;
291 1.3.2.2 bouyer t.c_cflag = CSTOPB | CS8;
292 1.3.2.2 bouyer (void)uftdi_param(sc, portno, &t);
293 1.3.2.2 bouyer
294 1.3.2.2 bouyer /* Turn on RTS/CTS flow control */
295 1.3.2.2 bouyer req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
296 1.3.2.2 bouyer req.bRequest = FTDI_SIO_SET_FLOW_CTRL;
297 1.3.2.2 bouyer USETW(req.wValue, 0);
298 1.3.2.2 bouyer USETW2(req.wIndex, FTDI_SIO_RTS_CTS_HS, portno);
299 1.3.2.2 bouyer USETW(req.wLength, 0);
300 1.3.2.2 bouyer err = usbd_do_request(sc->sc_udev, &req, NULL);
301 1.3.2.2 bouyer if (err)
302 1.3.2.2 bouyer return (EIO);
303 1.3.2.2 bouyer
304 1.3.2.2 bouyer return (0);
305 1.3.2.2 bouyer }
306 1.3.2.2 bouyer
307 1.3.2.2 bouyer Static void
308 1.3.2.2 bouyer uftdi_read(void *vsc, int portno, u_char **ptr, u_int32_t *count)
309 1.3.2.2 bouyer {
310 1.3.2.2 bouyer struct uftdi_softc *sc = vsc;
311 1.3.2.2 bouyer u_char msr, lsr;
312 1.3.2.2 bouyer
313 1.3.2.2 bouyer DPRINTFN(15,("uftdi_read: sc=%p, port=%d count=%d\n", sc, portno,
314 1.3.2.2 bouyer *count));
315 1.3.2.2 bouyer
316 1.3.2.2 bouyer msr = FTDI_GET_MSR(*ptr);
317 1.3.2.2 bouyer lsr = FTDI_GET_LSR(*ptr);
318 1.3.2.2 bouyer
319 1.3.2.2 bouyer #ifdef UFTDI_DEBUG
320 1.3.2.2 bouyer if (*count != 2)
321 1.3.2.2 bouyer DPRINTFN(10,("uftdi_read: sc=%p, port=%d count=%d data[0]="
322 1.3.2.2 bouyer "0x%02x\n", sc, portno, *count, (*ptr)[2]));
323 1.3.2.2 bouyer #endif
324 1.3.2.2 bouyer
325 1.3.2.2 bouyer if (sc->sc_msr != msr ||
326 1.3.2.2 bouyer (sc->sc_lsr & FTDI_LSR_MASK) != (lsr & FTDI_LSR_MASK)) {
327 1.3.2.2 bouyer DPRINTF(("uftdi_read: status change msr=0x%02x(0x%02x) "
328 1.3.2.2 bouyer "lsr=0x%02x(0x%02x)\n", msr, sc->sc_msr,
329 1.3.2.2 bouyer lsr, sc->sc_lsr));
330 1.3.2.2 bouyer sc->sc_msr = msr;
331 1.3.2.2 bouyer sc->sc_lsr = lsr;
332 1.3.2.2 bouyer ucom_status_change((struct ucom_softc *)sc->sc_subdev);
333 1.3.2.2 bouyer }
334 1.3.2.2 bouyer
335 1.3.2.2 bouyer /* Pick up status and adjust data part. */
336 1.3.2.2 bouyer *ptr += 2;
337 1.3.2.2 bouyer *count -= 2;
338 1.3.2.2 bouyer }
339 1.3.2.2 bouyer
340 1.3.2.2 bouyer Static void
341 1.3.2.2 bouyer uftdi_write(void *vsc, int portno, u_char *to, u_char *from, u_int32_t *count)
342 1.3.2.2 bouyer {
343 1.3.2.2 bouyer DPRINTFN(10,("uftdi_write: sc=%p, port=%d count=%u data[0]=0x%02x\n",
344 1.3.2.2 bouyer vsc, portno, *count, from[0]));
345 1.3.2.2 bouyer
346 1.3.2.2 bouyer /* Make length tag and copy data */
347 1.3.2.2 bouyer *to = FTDI_OUT_TAG(*count, portno);
348 1.3.2.2 bouyer memcpy(to+1, from, *count);
349 1.3.2.2 bouyer ++*count;
350 1.3.2.2 bouyer }
351 1.3.2.2 bouyer
352 1.3.2.2 bouyer Static void
353 1.3.2.2 bouyer uftdi_set(void *vsc, int portno, int reg, int onoff)
354 1.3.2.2 bouyer {
355 1.3.2.2 bouyer struct uftdi_softc *sc = vsc;
356 1.3.2.2 bouyer usb_device_request_t req;
357 1.3.2.2 bouyer int ctl;
358 1.3.2.2 bouyer
359 1.3.2.2 bouyer DPRINTF(("uftdi_set: sc=%p, port=%d reg=%d onoff=%d\n", vsc, portno,
360 1.3.2.2 bouyer reg, onoff));
361 1.3.2.2 bouyer
362 1.3.2.2 bouyer switch (reg) {
363 1.3.2.2 bouyer case UCOM_SET_DTR:
364 1.3.2.2 bouyer ctl = onoff ? FTDI_SIO_SET_DTR_HIGH : FTDI_SIO_SET_DTR_LOW;
365 1.3.2.2 bouyer break;
366 1.3.2.2 bouyer case UCOM_SET_RTS:
367 1.3.2.2 bouyer ctl = onoff ? FTDI_SIO_SET_RTS_HIGH : FTDI_SIO_SET_RTS_LOW;
368 1.3.2.2 bouyer break;
369 1.3.2.2 bouyer case UCOM_SET_BREAK:
370 1.3.2.2 bouyer /* XXX how do we set break? */
371 1.3.2.2 bouyer return;
372 1.3.2.2 bouyer default:
373 1.3.2.2 bouyer return;
374 1.3.2.2 bouyer }
375 1.3.2.2 bouyer req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
376 1.3.2.2 bouyer req.bRequest = FTDI_SIO_MODEM_CTRL;
377 1.3.2.2 bouyer USETW(req.wValue, ctl);
378 1.3.2.2 bouyer USETW(req.wIndex, portno);
379 1.3.2.2 bouyer USETW(req.wLength, 0);
380 1.3.2.2 bouyer DPRINTFN(2,("uftdi_set: reqtype=0x%02x req=0x%02x value=0x%04x "
381 1.3.2.2 bouyer "index=0x%04x len=%d\n", req.bmRequestType, req.bRequest,
382 1.3.2.2 bouyer UGETW(req.wValue), UGETW(req.wIndex), UGETW(req.wLength)));
383 1.3.2.2 bouyer (void)usbd_do_request(sc->sc_udev, &req, NULL);
384 1.3.2.2 bouyer }
385 1.3.2.2 bouyer
386 1.3.2.2 bouyer Static int
387 1.3.2.2 bouyer uftdi_param(void *vsc, int portno, struct termios *t)
388 1.3.2.2 bouyer {
389 1.3.2.2 bouyer struct uftdi_softc *sc = vsc;
390 1.3.2.2 bouyer usb_device_request_t req;
391 1.3.2.2 bouyer usbd_status err;
392 1.3.2.2 bouyer int rate, data;
393 1.3.2.2 bouyer
394 1.3.2.2 bouyer DPRINTF(("uftdi_param: sc=%p\n", sc));
395 1.3.2.2 bouyer
396 1.3.2.2 bouyer if (sc->sc_dying)
397 1.3.2.2 bouyer return (EIO);
398 1.3.2.2 bouyer
399 1.3.2.2 bouyer switch (t->c_ospeed) {
400 1.3.2.2 bouyer case 300: rate = ftdi_sio_b300; break;
401 1.3.2.2 bouyer case 600: rate = ftdi_sio_b600; break;
402 1.3.2.2 bouyer case 1200: rate = ftdi_sio_b1200; break;
403 1.3.2.2 bouyer case 2400: rate = ftdi_sio_b2400; break;
404 1.3.2.2 bouyer case 4800: rate = ftdi_sio_b4800; break;
405 1.3.2.2 bouyer case 9600: rate = ftdi_sio_b9600; break;
406 1.3.2.2 bouyer case 19200: rate = ftdi_sio_b19200; break;
407 1.3.2.2 bouyer case 38400: rate = ftdi_sio_b38400; break;
408 1.3.2.2 bouyer case 57600: rate = ftdi_sio_b57600; break;
409 1.3.2.2 bouyer case 115200: rate = ftdi_sio_b115200; break;
410 1.3.2.2 bouyer default:
411 1.3.2.2 bouyer return (EINVAL);
412 1.3.2.2 bouyer }
413 1.3.2.2 bouyer req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
414 1.3.2.2 bouyer req.bRequest = FTDI_SIO_SET_BAUD_RATE;
415 1.3.2.2 bouyer USETW(req.wValue, rate);
416 1.3.2.2 bouyer USETW(req.wIndex, portno);
417 1.3.2.2 bouyer USETW(req.wLength, 0);
418 1.3.2.2 bouyer DPRINTFN(2,("uftdi_param: reqtype=0x%02x req=0x%02x value=0x%04x "
419 1.3.2.2 bouyer "index=0x%04x len=%d\n", req.bmRequestType, req.bRequest,
420 1.3.2.2 bouyer UGETW(req.wValue), UGETW(req.wIndex), UGETW(req.wLength)));
421 1.3.2.2 bouyer err = usbd_do_request(sc->sc_udev, &req, NULL);
422 1.3.2.2 bouyer if (err)
423 1.3.2.2 bouyer return (EIO);
424 1.3.2.2 bouyer
425 1.3.2.2 bouyer if (ISSET(t->c_cflag, CSTOPB))
426 1.3.2.2 bouyer data = FTDI_SIO_SET_DATA_STOP_BITS_2;
427 1.3.2.2 bouyer else
428 1.3.2.2 bouyer data = FTDI_SIO_SET_DATA_STOP_BITS_1;
429 1.3.2.2 bouyer if (ISSET(t->c_cflag, PARENB)) {
430 1.3.2.2 bouyer if (ISSET(t->c_cflag, PARODD))
431 1.3.2.2 bouyer data |= FTDI_SIO_SET_DATA_PARITY_ODD;
432 1.3.2.2 bouyer else
433 1.3.2.2 bouyer data |= FTDI_SIO_SET_DATA_PARITY_EVEN;
434 1.3.2.2 bouyer } else
435 1.3.2.2 bouyer data |= FTDI_SIO_SET_DATA_PARITY_NONE;
436 1.3.2.2 bouyer switch (ISSET(t->c_cflag, CSIZE)) {
437 1.3.2.2 bouyer case CS5:
438 1.3.2.2 bouyer data |= FTDI_SIO_SET_DATA_BITS(5);
439 1.3.2.2 bouyer break;
440 1.3.2.2 bouyer case CS6:
441 1.3.2.2 bouyer data |= FTDI_SIO_SET_DATA_BITS(6);
442 1.3.2.2 bouyer break;
443 1.3.2.2 bouyer case CS7:
444 1.3.2.2 bouyer data |= FTDI_SIO_SET_DATA_BITS(7);
445 1.3.2.2 bouyer break;
446 1.3.2.2 bouyer case CS8:
447 1.3.2.2 bouyer data |= FTDI_SIO_SET_DATA_BITS(8);
448 1.3.2.2 bouyer break;
449 1.3.2.2 bouyer }
450 1.3.2.2 bouyer req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
451 1.3.2.2 bouyer req.bRequest = FTDI_SIO_SET_DATA;
452 1.3.2.2 bouyer USETW(req.wValue, data);
453 1.3.2.2 bouyer USETW(req.wIndex, portno);
454 1.3.2.2 bouyer USETW(req.wLength, 0);
455 1.3.2.2 bouyer DPRINTFN(2,("uftdi_param: reqtype=0x%02x req=0x%02x value=0x%04x "
456 1.3.2.2 bouyer "index=0x%04x len=%d\n", req.bmRequestType, req.bRequest,
457 1.3.2.2 bouyer UGETW(req.wValue), UGETW(req.wIndex), UGETW(req.wLength)));
458 1.3.2.2 bouyer err = usbd_do_request(sc->sc_udev, &req, NULL);
459 1.3.2.2 bouyer if (err)
460 1.3.2.2 bouyer return (EIO);
461 1.3.2.2 bouyer
462 1.3.2.2 bouyer return (0);
463 1.3.2.2 bouyer }
464 1.3.2.2 bouyer
465 1.3.2.2 bouyer void
466 1.3.2.2 bouyer uftdi_get_status(void *vsc, int portno, u_char *lsr, u_char *msr)
467 1.3.2.2 bouyer {
468 1.3.2.2 bouyer struct uftdi_softc *sc = vsc;
469 1.3.2.2 bouyer
470 1.3.2.2 bouyer DPRINTF(("uftdi_status: msr=0x%02x lsr=0x%02x\n",
471 1.3.2.2 bouyer sc->sc_msr, sc->sc_lsr));
472 1.3.2.2 bouyer
473 1.3.2.2 bouyer if (msr != NULL)
474 1.3.2.2 bouyer *msr = sc->sc_msr;
475 1.3.2.2 bouyer if (lsr != NULL)
476 1.3.2.2 bouyer *lsr = sc->sc_lsr;
477 1.3.2.2 bouyer }
478