Deleted Added
sdiff udiff text old ( 187970 ) new ( 188413 )
full compact
1/* $OpenBSD: uark.c,v 1.1 2006/08/14 08:30:22 jsg Exp $ */
2
3/*
4 * Copyright (c) 2006 Jonathan Gray <jsg@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 *
18 * $FreeBSD: head/sys/dev/usb2/serial/uark2.c 188413 2009-02-09 22:05:25Z thompsa $
19 */
20
21/*
22 * NOTE: all function names beginning like "uark_cfg_" can only
23 * be called from within the config thread function !
24 */
25
26#include <dev/usb2/include/usb2_devid.h>

--- 32 unchanged lines hidden (view full) ---

59#define UARK_REQUEST 0xfe
60
61#define UARK_CONFIG_INDEX 0
62#define UARK_IFACE_INDEX 0
63
64enum {
65 UARK_BULK_DT_WR,
66 UARK_BULK_DT_RD,
67 UARK_N_TRANSFER,
68};
69
70struct uark_softc {
71 struct usb2_com_super_softc sc_super_ucom;
72 struct usb2_com_softc sc_ucom;
73
74 struct usb2_xfer *sc_xfer[UARK_N_TRANSFER];
75 struct usb2_device *sc_udev;
76
77 uint8_t sc_msr;
78 uint8_t sc_lsr;
79};
80
81/* prototypes */
82
83static device_probe_t uark_probe;
84static device_attach_t uark_attach;
85static device_detach_t uark_detach;
86
87static usb2_callback_t uark_bulk_write_callback;
88static usb2_callback_t uark_bulk_read_callback;
89
90static void uark_start_read(struct usb2_com_softc *);
91static void uark_stop_read(struct usb2_com_softc *);
92static void uark_start_write(struct usb2_com_softc *);
93static void uark_stop_write(struct usb2_com_softc *);
94static int uark_pre_param(struct usb2_com_softc *, struct termios *);
95static void uark_cfg_param(struct usb2_com_softc *, struct termios *);
96static void uark_cfg_get_status(struct usb2_com_softc *, uint8_t *,

--- 16 unchanged lines hidden (view full) ---

113 [UARK_BULK_DT_RD] = {
114 .type = UE_BULK,
115 .endpoint = UE_ADDR_ANY,
116 .direction = UE_DIR_IN,
117 .mh.bufsize = UARK_BUF_SIZE,
118 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
119 .mh.callback = &uark_bulk_read_callback,
120 },
121};
122
123static const struct usb2_com_callback uark_callback = {
124 .usb2_com_cfg_get_status = &uark_cfg_get_status,
125 .usb2_com_cfg_set_break = &uark_cfg_set_break,
126 .usb2_com_cfg_param = &uark_cfg_param,
127 .usb2_com_pre_param = &uark_pre_param,
128 .usb2_com_start_read = &uark_start_read,

--- 61 unchanged lines hidden (view full) ---

190 uark_xfer_config, UARK_N_TRANSFER, sc, &Giant);
191
192 if (error) {
193 device_printf(dev, "allocating control USB "
194 "transfers failed!\n");
195 goto detach;
196 }
197 /* clear stall at first run */
198 usb2_transfer_set_stall(sc->sc_xfer[UARK_BULK_DT_WR]);
199 usb2_transfer_set_stall(sc->sc_xfer[UARK_BULK_DT_RD]);
200
201 error = usb2_com_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
202 &uark_callback, &Giant);
203 if (error) {
204 DPRINTF("usb2_com_attach failed\n");
205 goto detach;
206 }
207 return (0); /* success */

--- 19 unchanged lines hidden (view full) ---

227uark_bulk_write_callback(struct usb2_xfer *xfer)
228{
229 struct uark_softc *sc = xfer->priv_sc;
230 uint32_t actlen;
231
232 switch (USB_GET_STATE(xfer)) {
233 case USB_ST_SETUP:
234 case USB_ST_TRANSFERRED:
235tr_setup:
236 if (usb2_com_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
237 UARK_BUF_SIZE, &actlen)) {
238 xfer->frlengths[0] = actlen;
239 usb2_start_hardware(xfer);
240 }
241 return;
242
243 default: /* Error */
244 if (xfer->error != USB_ERR_CANCELLED) {
245 /* try to clear stall first */
246 xfer->flags.stall_pipe = 1;
247 goto tr_setup;
248 }
249 return;
250
251 }
252}
253
254static void
255uark_bulk_read_callback(struct usb2_xfer *xfer)
256{
257 struct uark_softc *sc = xfer->priv_sc;
258
259 switch (USB_GET_STATE(xfer)) {
260 case USB_ST_TRANSFERRED:
261 usb2_com_put_data(&sc->sc_ucom, xfer->frbuffers, 0,
262 xfer->actlen);
263
264 case USB_ST_SETUP:
265tr_setup:
266 xfer->frlengths[0] = xfer->max_data_length;
267 usb2_start_hardware(xfer);
268 return;
269
270 default: /* Error */
271 if (xfer->error != USB_ERR_CANCELLED) {
272 /* try to clear stall first */
273 xfer->flags.stall_pipe = 1;
274 goto tr_setup;
275 }
276 return;
277 }
278}
279
280static void
281uark_start_read(struct usb2_com_softc *ucom)
282{
283 struct uark_softc *sc = ucom->sc_parent;
284
285 usb2_transfer_start(sc->sc_xfer[UARK_BULK_DT_RD]);
286}
287
288static void
289uark_stop_read(struct usb2_com_softc *ucom)
290{
291 struct uark_softc *sc = ucom->sc_parent;
292
293 usb2_transfer_stop(sc->sc_xfer[UARK_BULK_DT_RD]);
294}
295
296static void
297uark_start_write(struct usb2_com_softc *ucom)
298{
299 struct uark_softc *sc = ucom->sc_parent;
300
301 usb2_transfer_start(sc->sc_xfer[UARK_BULK_DT_WR]);
302}
303
304static void
305uark_stop_write(struct usb2_com_softc *ucom)
306{
307 struct uark_softc *sc = ucom->sc_parent;
308
309 usb2_transfer_stop(sc->sc_xfer[UARK_BULK_DT_WR]);
310}
311
312static int
313uark_pre_param(struct usb2_com_softc *ucom, struct termios *t)
314{
315 if ((t->c_ospeed < 300) || (t->c_ospeed > 115200))
316 return (EINVAL);

--- 70 unchanged lines hidden (view full) ---

387}
388
389static void
390uark_cfg_write(struct uark_softc *sc, uint16_t index, uint16_t value)
391{
392 struct usb2_device_request req;
393 usb2_error_t err;
394
395 req.bmRequestType = UARK_WRITE;
396 req.bRequest = UARK_REQUEST;
397 USETW(req.wValue, value);
398 USETW(req.wIndex, index);
399 USETW(req.wLength, 0);
400
401 err = usb2_com_cfg_do_request(sc->sc_udev, &sc->sc_ucom,
402 &req, NULL, 0, 1000);
403 if (err) {
404 DPRINTFN(0, "device request failed, err=%s "
405 "(ignored)\n", usb2_errstr(err));
406 }
407}