Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/usb/serial/usb_serial.c
Show First 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | |||||
#include <dev/usb/usb.h> | #include <dev/usb/usb.h> | ||||
#include <dev/usb/usbdi.h> | #include <dev/usb/usbdi.h> | ||||
#include <dev/usb/usbdi_util.h> | #include <dev/usb/usbdi_util.h> | ||||
#define USB_DEBUG_VAR ucom_debug | #define USB_DEBUG_VAR ucom_debug | ||||
#include <dev/usb/usb_debug.h> | #include <dev/usb/usb_debug.h> | ||||
#include <dev/usb/usb_busdma.h> | #include <dev/usb/usb_busdma.h> | ||||
#include <dev/usb/usb_process.h> | #include <dev/usb/usb_process.h> | ||||
#include <dev/usb/usb_util.h> | |||||
#include <dev/usb/serial/usb_serial.h> | #include <dev/usb/serial/usb_serial.h> | ||||
#include "opt_gdb.h" | #include "opt_gdb.h" | ||||
static SYSCTL_NODE(_hw_usb, OID_AUTO, ucom, CTLFLAG_RW, 0, "USB ucom"); | static SYSCTL_NODE(_hw_usb, OID_AUTO, ucom, CTLFLAG_RW, 0, "USB ucom"); | ||||
static int ucom_pps_mode; | static int ucom_pps_mode; | ||||
SYSCTL_INT(_hw_usb_ucom, OID_AUTO, pps_mode, CTLFLAG_RWTUN, | SYSCTL_INT(_hw_usb_ucom, OID_AUTO, pps_mode, CTLFLAG_RWTUN, | ||||
&ucom_pps_mode, 0, | &ucom_pps_mode, 0, | ||||
"pulse capture mode: 0/1/2=disabled/CTS/DCD; add 0x10 to invert"); | "pulse capture mode: 0/1/2=disabled/CTS/DCD; add 0x10 to invert"); | ||||
static int ucom_device_mode_console = 1; | static int ucom_device_mode_console = 1; | ||||
SYSCTL_INT(_hw_usb_ucom, OID_AUTO, device_mode_console, CTLFLAG_RW, | SYSCTL_INT(_hw_usb_ucom, OID_AUTO, device_mode_console, CTLFLAG_RW, | ||||
&ucom_device_mode_console, 0, | &ucom_device_mode_console, 0, | ||||
"set to 1 to mark terminals as consoles when in device mode"); | "set to 1 to mark terminals as consoles when in device mode"); | ||||
static int ucom_location_as_unit; | |||||
SYSCTL_INT(_hw_usb_ucom, OID_AUTO, location_as_unit, CTLFLAG_RDTUN, | |||||
&ucom_location_as_unit, 0, | |||||
"set to 1 to use device location as device unit"); | |||||
#ifdef USB_DEBUG | #ifdef USB_DEBUG | ||||
static int ucom_debug = 0; | static int ucom_debug = 0; | ||||
SYSCTL_INT(_hw_usb_ucom, OID_AUTO, debug, CTLFLAG_RWTUN, | SYSCTL_INT(_hw_usb_ucom, OID_AUTO, debug, CTLFLAG_RWTUN, | ||||
&ucom_debug, 0, "ucom debug level"); | &ucom_debug, 0, "ucom debug level"); | ||||
#endif | #endif | ||||
#define UCOM_CONS_BUFSIZE 1024 | #define UCOM_CONS_BUFSIZE 1024 | ||||
▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* Mark the unit number as not in use. | * Mark the unit number as not in use. | ||||
*/ | */ | ||||
static void | static void | ||||
ucom_unit_free(int unit) | ucom_unit_free(int unit) | ||||
{ | { | ||||
/* sanity checks */ | /* sanity checks */ | ||||
if (unit < 0 || unit >= UCOM_UNIT_MAX || ucom_unrhdr == NULL) { | if (unit < 0 || unit >= UCOM_UNIT_MAX || ucom_unrhdr == NULL) { | ||||
DPRINTF("cannot free unit number\n"); | DPRINTF("cannot free unit %d\n", unit); | ||||
return; | return; | ||||
} | } | ||||
DPRINTF("unit %d is freed\n", unit); | DPRINTF("unit %d is freed\n", unit); | ||||
free_unr(ucom_unrhdr, unit); | free_unr(ucom_unrhdr, unit); | ||||
} | } | ||||
/* | /* | ||||
* Setup a group of one or more serial ports. | * Setup a group of one or more serial ports. | ||||
* | * | ||||
* The mutex pointed to by "mtx" is applied before all | * The mutex pointed to by "mtx" is applied before all | ||||
* callbacks are called back. Also "mtx" must be applied | * callbacks are called back. Also "mtx" must be applied | ||||
* before calling into the ucom-layer! | * before calling into the ucom-layer! | ||||
*/ | */ | ||||
int | int | ||||
ucom_attach(struct ucom_super_softc *ssc, struct ucom_softc *sc, | ucom_attach(struct ucom_super_softc *ssc, struct ucom_softc *sc, | ||||
int subunits, void *parent, | int subunits, void *parent, | ||||
const struct ucom_callback *callback, struct mtx *mtx) | const struct ucom_callback *callback, struct mtx *mtx) | ||||
{ | { | ||||
return (ucom_attach_usb(ssc, sc, subunits, parent, callback, mtx, NULL)); | |||||
} | |||||
int | |||||
ucom_attach_usb(struct ucom_super_softc *ssc, struct ucom_softc *sc, | |||||
int subunits, void *parent, | |||||
const struct ucom_callback *callback, struct mtx *mtx, | |||||
struct usb_device *udev) | |||||
{ | |||||
int subunit; | int subunit; | ||||
int error = 0; | int error = 0; | ||||
if ((sc == NULL) || | if ((sc == NULL) || | ||||
(subunits <= 0) || | (subunits <= 0) || | ||||
(callback == NULL) || | (callback == NULL) || | ||||
(mtx == NULL)) { | (mtx == NULL)) { | ||||
return (EINVAL); | return (EINVAL); | ||||
} | } | ||||
/* allocate a uniq unit number */ | /* allocate a uniq unit number */ | ||||
if (ucom_location_as_unit == 0 || udev == NULL) { | |||||
ssc->sc_unit = ucom_unit_alloc(); | ssc->sc_unit = ucom_unit_alloc(); | ||||
} else { | |||||
ssc->sc_unit = usb_compute_uniq_location(udev) + UCOM_UNIT_MAX; | |||||
/* add fallback code just in case */ | |||||
if (ssc->sc_unit < UCOM_UNIT_MAX) | |||||
ssc->sc_unit = ucom_unit_alloc(); | |||||
DPRINTF("unit %d by location\n", location); | |||||
rpokala: `location` isn't a variable in this function; did you mean `ssc->sc_unit`? | |||||
} | |||||
if (ssc->sc_unit == -1) | if (ssc->sc_unit == -1) | ||||
return (ENOMEM); | return (ENOMEM); | ||||
/* generate TTY name string */ | /* generate TTY name string */ | ||||
snprintf(ssc->sc_ttyname, sizeof(ssc->sc_ttyname), | snprintf(ssc->sc_ttyname, sizeof(ssc->sc_ttyname), | ||||
UCOM_TTY_PREFIX "%d", ssc->sc_unit); | UCOM_TTY_PREFIX "%d", ssc->sc_unit); | ||||
/* create USB request handling process */ | /* create USB request handling process */ | ||||
▲ Show 20 Lines • Show All 1,508 Lines • Show Last 20 Lines |
location isn't a variable in this function; did you mean ssc->sc_unit?