Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-3]: src/sys/dev/usb Pull up revision 1.51 (requested by itohy in ...
details: https://anonhg.NetBSD.org/src/rev/efe530345d72
branches: netbsd-3
changeset: 575389:efe530345d72
user: tron <tron%NetBSD.org@localhost>
date: Sun Apr 17 10:27:59 2005 +0000
description:
Pull up revision 1.51 (requested by itohy in ticket #160):
Split common modem part of umodem.c to umodem_common.c and umodemvar.h,
to be shared with other umodem-like drivers.
diffstat:
sys/dev/usb/umodem.c | 611 +-------------------------------------------------
1 files changed, 14 insertions(+), 597 deletions(-)
diffs (truncated from 664 to 300 lines):
diff -r dcafa05e7898 -r efe530345d72 sys/dev/usb/umodem.c
--- a/sys/dev/usb/umodem.c Sun Apr 17 10:25:10 2005 +0000
+++ b/sys/dev/usb/umodem.c Sun Apr 17 10:27:59 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: umodem.c,v 1.49.10.1 2005/04/17 10:25:10 tron Exp $ */
+/* $NetBSD: umodem.c,v 1.49.10.2 2005/04/17 10:27:59 tron Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -51,7 +51,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umodem.c,v 1.49.10.1 2005/04/17 10:25:10 tron Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umodem.c,v 1.49.10.2 2005/04/17 10:27:59 tron Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -76,6 +76,7 @@
#include <dev/usb/usbdevs.h>
#include <dev/usb/ucomvar.h>
+#include <dev/usb/umodemvar.h>
#ifdef UMODEM_DEBUG
#define DPRINTFN(n, x) if (umodemdebug > (n)) logprintf x
@@ -85,65 +86,6 @@
#endif
#define DPRINTF(x) DPRINTFN(0, x)
-/*
- * These are the maximum number of bytes transferred per frame.
- * If some really high speed devices should use this driver they
- * may need to be increased, but this is good enough for normal modems.
- */
-#define UMODEMIBUFSIZE 64
-#define UMODEMOBUFSIZE 256
-
-struct umodem_softc {
- USBBASEDEVICE sc_dev; /* base device */
-
- usbd_device_handle sc_udev; /* USB device */
-
- int sc_ctl_iface_no;
- usbd_interface_handle sc_ctl_iface; /* control interface */
- int sc_data_iface_no;
- usbd_interface_handle sc_data_iface; /* data interface */
-
- int sc_cm_cap; /* CM capabilities */
- int sc_acm_cap; /* ACM capabilities */
-
- int sc_cm_over_data;
-
- usb_cdc_line_state_t sc_line_state; /* current line state */
- u_char sc_dtr; /* current DTR state */
- u_char sc_rts; /* current RTS state */
-
- device_ptr_t sc_subdev; /* ucom device */
-
- u_char sc_opening; /* lock during open */
- u_char sc_dying; /* disconnecting */
-
- int sc_ctl_notify; /* Notification endpoint */
- usbd_pipe_handle sc_notify_pipe; /* Notification pipe */
- usb_cdc_notification_t sc_notify_buf; /* Notification structure */
- u_char sc_lsr; /* Local status register */
- u_char sc_msr; /* Modem status register */
-};
-
-Static usbd_status umodem_set_comm_feature(struct umodem_softc *sc,
- int feature, int state);
-Static usbd_status umodem_set_line_coding(struct umodem_softc *sc,
- usb_cdc_line_state_t *state);
-
-Static void umodem_get_caps(usbd_device_handle, int *, int *,
- usb_interface_descriptor_t *);
-
-Static void umodem_get_status(void *, int portno, u_char *lsr, u_char *msr);
-Static void umodem_set(void *, int, int, int);
-Static void umodem_dtr(struct umodem_softc *, int);
-Static void umodem_rts(struct umodem_softc *, int);
-Static void umodem_break(struct umodem_softc *, int);
-Static void umodem_set_line_state(struct umodem_softc *);
-Static int umodem_param(void *, int, struct termios *);
-Static int umodem_ioctl(void *, int, u_long, caddr_t, int, usb_proc_ptr );
-Static int umodem_open(void *, int portno);
-Static void umodem_close(void *, int portno);
-Static void umodem_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
-
Static struct ucom_methods umodem_methods = {
umodem_get_status,
umodem_set,
@@ -185,560 +127,35 @@
USB_ATTACH(umodem)
{
USB_ATTACH_START(umodem, sc, uaa);
- usbd_device_handle dev = uaa->device;
- usb_interface_descriptor_t *id;
- usb_endpoint_descriptor_t *ed;
- const usb_cdc_cm_descriptor_t *cmd;
- char devinfo[1024];
- usbd_status err;
- int data_ifcno;
- int i;
struct ucom_attach_args uca;
- usbd_devinfo(uaa->device, 0, devinfo, sizeof(devinfo));
- USB_ATTACH_SETUP;
-
- sc->sc_udev = dev;
- sc->sc_ctl_iface = uaa->iface;
-
- id = usbd_get_interface_descriptor(sc->sc_ctl_iface);
- printf("%s: %s, iclass %d/%d\n", USBDEVNAME(sc->sc_dev),
- devinfo, id->bInterfaceClass, id->bInterfaceSubClass);
- sc->sc_ctl_iface_no = id->bInterfaceNumber;
-
- umodem_get_caps(dev, &sc->sc_cm_cap, &sc->sc_acm_cap, id);
-
- /* Get the data interface no. */
- cmd = (usb_cdc_cm_descriptor_t *)usb_find_desc_if(dev,
- UDESC_CS_INTERFACE,
- UDESCSUB_CDC_CM, id);
- if (cmd == NULL) {
- printf("%s: no CM descriptor\n", USBDEVNAME(sc->sc_dev));
- goto bad;
- }
- sc->sc_data_iface_no = data_ifcno = cmd->bDataInterface;
-
- printf("%s: data interface %d, has %sCM over data, has %sbreak\n",
- USBDEVNAME(sc->sc_dev), data_ifcno,
- sc->sc_cm_cap & USB_CDC_CM_OVER_DATA ? "" : "no ",
- sc->sc_acm_cap & USB_CDC_ACM_HAS_BREAK ? "" : "no ");
-
- /* Get the data interface too. */
- for (i = 0; i < uaa->nifaces; i++) {
- if (uaa->ifaces[i] != NULL) {
- id = usbd_get_interface_descriptor(uaa->ifaces[i]);
- if (id != NULL && id->bInterfaceNumber == data_ifcno) {
- sc->sc_data_iface = uaa->ifaces[i];
- uaa->ifaces[i] = NULL;
- }
- }
- }
- if (sc->sc_data_iface == NULL) {
- printf("%s: no data interface\n", USBDEVNAME(sc->sc_dev));
- goto bad;
- }
-
- /*
- * Find the bulk endpoints.
- * Iterate over all endpoints in the data interface and take note.
- */
- uca.bulkin = uca.bulkout = -1;
-
- id = usbd_get_interface_descriptor(sc->sc_data_iface);
- for (i = 0; i < id->bNumEndpoints; i++) {
- ed = usbd_interface2endpoint_descriptor(sc->sc_data_iface, i);
- if (ed == NULL) {
- printf("%s: no endpoint descriptor for %d\n",
- USBDEVNAME(sc->sc_dev), i);
- goto bad;
- }
- if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
- (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
- uca.bulkin = ed->bEndpointAddress;
- } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
- (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
- uca.bulkout = ed->bEndpointAddress;
- }
- }
-
- if (uca.bulkin == -1) {
- printf("%s: Could not find data bulk in\n",
- USBDEVNAME(sc->sc_dev));
- goto bad;
- }
- if (uca.bulkout == -1) {
- printf("%s: Could not find data bulk out\n",
- USBDEVNAME(sc->sc_dev));
- goto bad;
- }
-
- if (usbd_get_quirks(sc->sc_udev)->uq_flags & UQ_ASSUME_CM_OVER_DATA) {
- sc->sc_cm_over_data = 1;
- } else {
- if (sc->sc_cm_cap & USB_CDC_CM_OVER_DATA) {
- if (sc->sc_acm_cap & USB_CDC_ACM_HAS_FEATURE)
- err = umodem_set_comm_feature(sc,
- UCDC_ABSTRACT_STATE, UCDC_DATA_MULTIPLEXED);
- else
- err = 0;
- if (err) {
- printf("%s: could not set data multiplex mode\n",
- USBDEVNAME(sc->sc_dev));
- goto bad;
- }
- sc->sc_cm_over_data = 1;
- }
- }
-
- /*
- * The standard allows for notification messages (to indicate things
- * like a modem hangup) to come in via an interrupt endpoint
- * off of the control interface. Iterate over the endpoints on
- * the control interface and see if there are any interrupt
- * endpoints; if there are, then register it.
- */
-
- sc->sc_ctl_notify = -1;
- sc->sc_notify_pipe = NULL;
-
- for (i = 0; i < id->bNumEndpoints; i++) {
- ed = usbd_interface2endpoint_descriptor(sc->sc_ctl_iface, i);
- if (ed == NULL)
- continue;
-
- if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
- (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) {
- printf("%s: status change notification available\n",
- USBDEVNAME(sc->sc_dev));
- sc->sc_ctl_notify = ed->bEndpointAddress;
- }
- }
-
- sc->sc_dtr = -1;
-
uca.portno = UCOM_UNK_PORTNO;
- /* bulkin, bulkout set above */
- uca.ibufsize = UMODEMIBUFSIZE;
- uca.obufsize = UMODEMOBUFSIZE;
- uca.ibufsizepad = UMODEMIBUFSIZE;
- uca.opkthdrlen = 0;
- uca.device = sc->sc_udev;
- uca.iface = sc->sc_data_iface;
uca.methods = &umodem_methods;
- uca.arg = sc;
uca.info = NULL;
- usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
- USBDEV(sc->sc_dev));
-
- DPRINTF(("umodem_attach: sc=%p\n", sc));
- sc->sc_subdev = config_found_sm_loc(self, "ucombus", NULL, &uca,
- ucomprint, ucomsubmatch);
-
+ if (umodem_common_attach(self, sc, uaa, &uca))
+ USB_ATTACH_ERROR_RETURN;
USB_ATTACH_SUCCESS_RETURN;
-
- bad:
- sc->sc_dying = 1;
- USB_ATTACH_ERROR_RETURN;
-}
-
-Static int
-umodem_open(void *addr, int portno)
-{
- struct umodem_softc *sc = addr;
- int err;
-
- DPRINTF(("umodem_open: sc=%p\n", sc));
-
- if (sc->sc_ctl_notify != -1 && sc->sc_notify_pipe == NULL) {
- err = usbd_open_pipe_intr(sc->sc_ctl_iface, sc->sc_ctl_notify,
- USBD_SHORT_XFER_OK, &sc->sc_notify_pipe, sc,
- &sc->sc_notify_buf, sizeof(sc->sc_notify_buf),
- umodem_intr, USBD_DEFAULT_INTERVAL);
-
- if (err) {
- DPRINTF(("Failed to establish notify pipe: %s\n",
- usbd_errstr(err)));
- return EIO;
- }
- }
-
- return 0;
-}
-
-Static void
-umodem_close(void *addr, int portno)
-{
- struct umodem_softc *sc = addr;
- int err;
-
- DPRINTF(("umodem_close: sc=%p\n", sc));
-
- if (sc->sc_notify_pipe != NULL) {
- err = usbd_abort_pipe(sc->sc_notify_pipe);
- if (err)
- printf("%s: abort notify pipe failed: %s\n",
- USBDEVNAME(sc->sc_dev), usbd_errstr(err));
- err = usbd_close_pipe(sc->sc_notify_pipe);
- if (err)
- printf("%s: close notify pipe failed: %s\n",
- USBDEVNAME(sc->sc_dev), usbd_errstr(err));
- sc->sc_notify_pipe = NULL;
- }
}
Home |
Main Index |
Thread Index |
Old Index