Deleted Added
full compact
ugensa.c (193644) ugensa.c (194228)
1/* $FreeBSD: head/sys/dev/usb/serial/ugensa.c 193644 2009-06-07 19:41:11Z thompsa $ */
1/* $FreeBSD: head/sys/dev/usb/serial/ugensa.c 194228 2009-06-15 01:02:43Z thompsa $ */
2/* $NetBSD: ugensa.c,v 1.9.2.1 2007/03/24 14:55:50 yamt Exp $ */
3
4/*
5 * Copyright (c) 2004, 2005 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Roland C. Dowdeswell <elric@netbsd.org>.

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

43 */
44
45#include "usbdevs.h"
46#include <dev/usb/usb.h>
47#include <dev/usb/usb_mfunc.h>
48#include <dev/usb/usb_error.h>
49#include <dev/usb/usb_cdc.h>
50
2/* $NetBSD: ugensa.c,v 1.9.2.1 2007/03/24 14:55:50 yamt Exp $ */
3
4/*
5 * Copyright (c) 2004, 2005 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Roland C. Dowdeswell <elric@netbsd.org>.

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

43 */
44
45#include "usbdevs.h"
46#include <dev/usb/usb.h>
47#include <dev/usb/usb_mfunc.h>
48#include <dev/usb/usb_error.h>
49#include <dev/usb/usb_cdc.h>
50
51#define USB_DEBUG_VAR usb2_debug
51#define USB_DEBUG_VAR usb_debug
52
53#include <dev/usb/usb_core.h>
54#include <dev/usb/usb_debug.h>
55#include <dev/usb/usb_process.h>
56#include <dev/usb/usb_request.h>
57#include <dev/usb/usb_lookup.h>
58#include <dev/usb/usb_util.h>
59#include <dev/usb/usb_device.h>

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

67
68enum {
69 UGENSA_BULK_DT_WR,
70 UGENSA_BULK_DT_RD,
71 UGENSA_N_TRANSFER,
72};
73
74struct ugensa_sub_softc {
52
53#include <dev/usb/usb_core.h>
54#include <dev/usb/usb_debug.h>
55#include <dev/usb/usb_process.h>
56#include <dev/usb/usb_request.h>
57#include <dev/usb/usb_lookup.h>
58#include <dev/usb/usb_util.h>
59#include <dev/usb/usb_device.h>

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

67
68enum {
69 UGENSA_BULK_DT_WR,
70 UGENSA_BULK_DT_RD,
71 UGENSA_N_TRANSFER,
72};
73
74struct ugensa_sub_softc {
75 struct ucom_softc *sc_usb2_com_ptr;
75 struct ucom_softc *sc_ucom_ptr;
76 struct usb_xfer *sc_xfer[UGENSA_N_TRANSFER];
77};
78
79struct ugensa_softc {
80 struct ucom_super_softc sc_super_ucom;
81 struct ucom_softc sc_ucom[UGENSA_IFACE_MAX];
82 struct ugensa_sub_softc sc_sub[UGENSA_IFACE_MAX];
83

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

117 .direction = UE_DIR_IN,
118 .bufsize = UGENSA_BUF_SIZE,
119 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
120 .callback = &ugensa_bulk_read_callback,
121 },
122};
123
124static const struct ucom_callback ugensa_callback = {
76 struct usb_xfer *sc_xfer[UGENSA_N_TRANSFER];
77};
78
79struct ugensa_softc {
80 struct ucom_super_softc sc_super_ucom;
81 struct ucom_softc sc_ucom[UGENSA_IFACE_MAX];
82 struct ugensa_sub_softc sc_sub[UGENSA_IFACE_MAX];
83

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

117 .direction = UE_DIR_IN,
118 .bufsize = UGENSA_BUF_SIZE,
119 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
120 .callback = &ugensa_bulk_read_callback,
121 },
122};
123
124static const struct ucom_callback ugensa_callback = {
125 .usb2_com_start_read = &ugensa_start_read,
126 .usb2_com_stop_read = &ugensa_stop_read,
127 .usb2_com_start_write = &ugensa_start_write,
128 .usb2_com_stop_write = &ugensa_stop_write,
125 .ucom_start_read = &ugensa_start_read,
126 .ucom_stop_read = &ugensa_stop_read,
127 .ucom_start_write = &ugensa_start_write,
128 .ucom_stop_write = &ugensa_stop_write,
129};
130
131static device_method_t ugensa_methods[] = {
132 /* Device methods */
133 DEVMETHOD(device_probe, ugensa_probe),
134 DEVMETHOD(device_attach, ugensa_attach),
135 DEVMETHOD(device_detach, ugensa_detach),
136 {0, 0}

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

165 return (ENXIO);
166 }
167 if (uaa->info.bConfigIndex != UGENSA_CONFIG_INDEX) {
168 return (ENXIO);
169 }
170 if (uaa->info.bIfaceIndex != 0) {
171 return (ENXIO);
172 }
129};
130
131static device_method_t ugensa_methods[] = {
132 /* Device methods */
133 DEVMETHOD(device_probe, ugensa_probe),
134 DEVMETHOD(device_attach, ugensa_attach),
135 DEVMETHOD(device_detach, ugensa_detach),
136 {0, 0}

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

165 return (ENXIO);
166 }
167 if (uaa->info.bConfigIndex != UGENSA_CONFIG_INDEX) {
168 return (ENXIO);
169 }
170 if (uaa->info.bIfaceIndex != 0) {
171 return (ENXIO);
172 }
173 return (usb2_lookup_id_by_uaa(ugensa_devs, sizeof(ugensa_devs), uaa));
173 return (usbd_lookup_id_by_uaa(ugensa_devs, sizeof(ugensa_devs), uaa));
174}
175
176static int
177ugensa_attach(device_t dev)
178{
179 struct usb_attach_arg *uaa = device_get_ivars(dev);
180 struct ugensa_softc *sc = device_get_softc(dev);
181 struct ugensa_sub_softc *ssc;
182 struct usb_interface *iface;
183 int32_t error;
184 uint8_t iface_index;
185 int x, cnt;
186
174}
175
176static int
177ugensa_attach(device_t dev)
178{
179 struct usb_attach_arg *uaa = device_get_ivars(dev);
180 struct ugensa_softc *sc = device_get_softc(dev);
181 struct ugensa_sub_softc *ssc;
182 struct usb_interface *iface;
183 int32_t error;
184 uint8_t iface_index;
185 int x, cnt;
186
187 device_set_usb2_desc(dev);
187 device_set_usb_desc(dev);
188 mtx_init(&sc->sc_mtx, "ugensa", NULL, MTX_DEF);
189
190 /* Figure out how many interfaces this device has got */
191 for (cnt = 0; cnt < UGENSA_IFACE_MAX; cnt++) {
188 mtx_init(&sc->sc_mtx, "ugensa", NULL, MTX_DEF);
189
190 /* Figure out how many interfaces this device has got */
191 for (cnt = 0; cnt < UGENSA_IFACE_MAX; cnt++) {
192 if ((usb2_get_endpoint(uaa->device, cnt, ugensa_xfer_config + 0) == NULL) ||
193 (usb2_get_endpoint(uaa->device, cnt, ugensa_xfer_config + 1) == NULL)) {
192 if ((usbd_get_endpoint(uaa->device, cnt, ugensa_xfer_config + 0) == NULL) ||
193 (usbd_get_endpoint(uaa->device, cnt, ugensa_xfer_config + 1) == NULL)) {
194 /* we have reached the end */
195 break;
196 }
197 }
198
199 if (cnt == 0) {
200 device_printf(dev, "No interfaces!\n");
201 goto detach;
202 }
203 for (x = 0; x < cnt; x++) {
194 /* we have reached the end */
195 break;
196 }
197 }
198
199 if (cnt == 0) {
200 device_printf(dev, "No interfaces!\n");
201 goto detach;
202 }
203 for (x = 0; x < cnt; x++) {
204 iface = usb2_get_iface(uaa->device, x);
204 iface = usbd_get_iface(uaa->device, x);
205 if (iface->idesc->bInterfaceClass != UICLASS_VENDOR)
206 /* Not a serial port, most likely a SD reader */
207 continue;
208
209 ssc = sc->sc_sub + sc->sc_niface;
205 if (iface->idesc->bInterfaceClass != UICLASS_VENDOR)
206 /* Not a serial port, most likely a SD reader */
207 continue;
208
209 ssc = sc->sc_sub + sc->sc_niface;
210 ssc->sc_usb2_com_ptr = sc->sc_ucom + sc->sc_niface;
210 ssc->sc_ucom_ptr = sc->sc_ucom + sc->sc_niface;
211
212 iface_index = (UGENSA_IFACE_INDEX + x);
211
212 iface_index = (UGENSA_IFACE_INDEX + x);
213 error = usb2_transfer_setup(uaa->device,
213 error = usbd_transfer_setup(uaa->device,
214 &iface_index, ssc->sc_xfer, ugensa_xfer_config,
215 UGENSA_N_TRANSFER, ssc, &sc->sc_mtx);
216
217 if (error) {
218 device_printf(dev, "allocating USB "
219 "transfers failed!\n");
220 goto detach;
221 }
222 /* clear stall at first run */
223 mtx_lock(&sc->sc_mtx);
214 &iface_index, ssc->sc_xfer, ugensa_xfer_config,
215 UGENSA_N_TRANSFER, ssc, &sc->sc_mtx);
216
217 if (error) {
218 device_printf(dev, "allocating USB "
219 "transfers failed!\n");
220 goto detach;
221 }
222 /* clear stall at first run */
223 mtx_lock(&sc->sc_mtx);
224 usb2_transfer_set_stall(ssc->sc_xfer[UGENSA_BULK_DT_WR]);
225 usb2_transfer_set_stall(ssc->sc_xfer[UGENSA_BULK_DT_RD]);
224 usbd_transfer_set_stall(ssc->sc_xfer[UGENSA_BULK_DT_WR]);
225 usbd_transfer_set_stall(ssc->sc_xfer[UGENSA_BULK_DT_RD]);
226 mtx_unlock(&sc->sc_mtx);
227
228 /* initialize port number */
226 mtx_unlock(&sc->sc_mtx);
227
228 /* initialize port number */
229 ssc->sc_usb2_com_ptr->sc_portno = sc->sc_niface;
229 ssc->sc_ucom_ptr->sc_portno = sc->sc_niface;
230 sc->sc_niface++;
231 if (x != uaa->info.bIfaceIndex)
230 sc->sc_niface++;
231 if (x != uaa->info.bIfaceIndex)
232 usb2_set_parent_iface(uaa->device, x,
232 usbd_set_parent_iface(uaa->device, x,
233 uaa->info.bIfaceIndex);
234 }
235 device_printf(dev, "Found %d interfaces.\n", sc->sc_niface);
236
233 uaa->info.bIfaceIndex);
234 }
235 device_printf(dev, "Found %d interfaces.\n", sc->sc_niface);
236
237 error = usb2_com_attach(&sc->sc_super_ucom, sc->sc_ucom, sc->sc_niface, sc,
237 error = ucom_attach(&sc->sc_super_ucom, sc->sc_ucom, sc->sc_niface, sc,
238 &ugensa_callback, &sc->sc_mtx);
239 if (error) {
240 DPRINTF("attach failed\n");
241 goto detach;
242 }
243 return (0); /* success */
244
245detach:
246 ugensa_detach(dev);
247 return (ENXIO); /* failure */
248}
249
250static int
251ugensa_detach(device_t dev)
252{
253 struct ugensa_softc *sc = device_get_softc(dev);
254 uint8_t x;
255
238 &ugensa_callback, &sc->sc_mtx);
239 if (error) {
240 DPRINTF("attach failed\n");
241 goto detach;
242 }
243 return (0); /* success */
244
245detach:
246 ugensa_detach(dev);
247 return (ENXIO); /* failure */
248}
249
250static int
251ugensa_detach(device_t dev)
252{
253 struct ugensa_softc *sc = device_get_softc(dev);
254 uint8_t x;
255
256 usb2_com_detach(&sc->sc_super_ucom, sc->sc_ucom, sc->sc_niface);
256 ucom_detach(&sc->sc_super_ucom, sc->sc_ucom, sc->sc_niface);
257
258 for (x = 0; x < sc->sc_niface; x++) {
257
258 for (x = 0; x < sc->sc_niface; x++) {
259 usb2_transfer_unsetup(sc->sc_sub[x].sc_xfer, UGENSA_N_TRANSFER);
259 usbd_transfer_unsetup(sc->sc_sub[x].sc_xfer, UGENSA_N_TRANSFER);
260 }
261 mtx_destroy(&sc->sc_mtx);
262
263 return (0);
264}
265
266static void
267ugensa_bulk_write_callback(struct usb_xfer *xfer)
268{
269 struct ugensa_sub_softc *ssc = xfer->priv_sc;
270 uint32_t actlen;
271
272 switch (USB_GET_STATE(xfer)) {
273 case USB_ST_SETUP:
274 case USB_ST_TRANSFERRED:
275tr_setup:
260 }
261 mtx_destroy(&sc->sc_mtx);
262
263 return (0);
264}
265
266static void
267ugensa_bulk_write_callback(struct usb_xfer *xfer)
268{
269 struct ugensa_sub_softc *ssc = xfer->priv_sc;
270 uint32_t actlen;
271
272 switch (USB_GET_STATE(xfer)) {
273 case USB_ST_SETUP:
274 case USB_ST_TRANSFERRED:
275tr_setup:
276 if (usb2_com_get_data(ssc->sc_usb2_com_ptr, xfer->frbuffers, 0,
276 if (ucom_get_data(ssc->sc_ucom_ptr, xfer->frbuffers, 0,
277 UGENSA_BUF_SIZE, &actlen)) {
278 xfer->frlengths[0] = actlen;
277 UGENSA_BUF_SIZE, &actlen)) {
278 xfer->frlengths[0] = actlen;
279 usb2_start_hardware(xfer);
279 usbd_transfer_submit(xfer);
280 }
281 return;
282
283 default: /* Error */
284 if (xfer->error != USB_ERR_CANCELLED) {
285 /* try to clear stall first */
286 xfer->flags.stall_pipe = 1;
287 goto tr_setup;

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

292
293static void
294ugensa_bulk_read_callback(struct usb_xfer *xfer)
295{
296 struct ugensa_sub_softc *ssc = xfer->priv_sc;
297
298 switch (USB_GET_STATE(xfer)) {
299 case USB_ST_TRANSFERRED:
280 }
281 return;
282
283 default: /* Error */
284 if (xfer->error != USB_ERR_CANCELLED) {
285 /* try to clear stall first */
286 xfer->flags.stall_pipe = 1;
287 goto tr_setup;

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

292
293static void
294ugensa_bulk_read_callback(struct usb_xfer *xfer)
295{
296 struct ugensa_sub_softc *ssc = xfer->priv_sc;
297
298 switch (USB_GET_STATE(xfer)) {
299 case USB_ST_TRANSFERRED:
300 usb2_com_put_data(ssc->sc_usb2_com_ptr, xfer->frbuffers, 0,
300 ucom_put_data(ssc->sc_ucom_ptr, xfer->frbuffers, 0,
301 xfer->actlen);
302
303 case USB_ST_SETUP:
304tr_setup:
305 xfer->frlengths[0] = xfer->max_data_length;
301 xfer->actlen);
302
303 case USB_ST_SETUP:
304tr_setup:
305 xfer->frlengths[0] = xfer->max_data_length;
306 usb2_start_hardware(xfer);
306 usbd_transfer_submit(xfer);
307 return;
308
309 default: /* Error */
310 if (xfer->error != USB_ERR_CANCELLED) {
311 /* try to clear stall first */
312 xfer->flags.stall_pipe = 1;
313 goto tr_setup;
314 }
315 return;
316 }
317}
318
319static void
320ugensa_start_read(struct ucom_softc *ucom)
321{
322 struct ugensa_softc *sc = ucom->sc_parent;
323 struct ugensa_sub_softc *ssc = sc->sc_sub + ucom->sc_portno;
324
307 return;
308
309 default: /* Error */
310 if (xfer->error != USB_ERR_CANCELLED) {
311 /* try to clear stall first */
312 xfer->flags.stall_pipe = 1;
313 goto tr_setup;
314 }
315 return;
316 }
317}
318
319static void
320ugensa_start_read(struct ucom_softc *ucom)
321{
322 struct ugensa_softc *sc = ucom->sc_parent;
323 struct ugensa_sub_softc *ssc = sc->sc_sub + ucom->sc_portno;
324
325 usb2_transfer_start(ssc->sc_xfer[UGENSA_BULK_DT_RD]);
325 usbd_transfer_start(ssc->sc_xfer[UGENSA_BULK_DT_RD]);
326}
327
328static void
329ugensa_stop_read(struct ucom_softc *ucom)
330{
331 struct ugensa_softc *sc = ucom->sc_parent;
332 struct ugensa_sub_softc *ssc = sc->sc_sub + ucom->sc_portno;
333
326}
327
328static void
329ugensa_stop_read(struct ucom_softc *ucom)
330{
331 struct ugensa_softc *sc = ucom->sc_parent;
332 struct ugensa_sub_softc *ssc = sc->sc_sub + ucom->sc_portno;
333
334 usb2_transfer_stop(ssc->sc_xfer[UGENSA_BULK_DT_RD]);
334 usbd_transfer_stop(ssc->sc_xfer[UGENSA_BULK_DT_RD]);
335}
336
337static void
338ugensa_start_write(struct ucom_softc *ucom)
339{
340 struct ugensa_softc *sc = ucom->sc_parent;
341 struct ugensa_sub_softc *ssc = sc->sc_sub + ucom->sc_portno;
342
335}
336
337static void
338ugensa_start_write(struct ucom_softc *ucom)
339{
340 struct ugensa_softc *sc = ucom->sc_parent;
341 struct ugensa_sub_softc *ssc = sc->sc_sub + ucom->sc_portno;
342
343 usb2_transfer_start(ssc->sc_xfer[UGENSA_BULK_DT_WR]);
343 usbd_transfer_start(ssc->sc_xfer[UGENSA_BULK_DT_WR]);
344}
345
346static void
347ugensa_stop_write(struct ucom_softc *ucom)
348{
349 struct ugensa_softc *sc = ucom->sc_parent;
350 struct ugensa_sub_softc *ssc = sc->sc_sub + ucom->sc_portno;
351
344}
345
346static void
347ugensa_stop_write(struct ucom_softc *ucom)
348{
349 struct ugensa_softc *sc = ucom->sc_parent;
350 struct ugensa_sub_softc *ssc = sc->sc_sub + ucom->sc_portno;
351
352 usb2_transfer_stop(ssc->sc_xfer[UGENSA_BULK_DT_WR]);
352 usbd_transfer_stop(ssc->sc_xfer[UGENSA_BULK_DT_WR]);
353}
353}