Expand usb_port.h macros.

This commit is contained in:
Warner Losh 2007-06-18 22:30:08 +00:00
parent 70c1d26317
commit bd6bb69705
3 changed files with 78 additions and 35 deletions

View File

@ -44,6 +44,8 @@ __FBSDID("$FreeBSD$");
* Printer Class spec: http://www.usb.org/developers/data/devclass/usbprint109.PDF
*/
/* XXXimp: need to migrate from devclass_get_softc */
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
@ -110,7 +112,7 @@ struct ulpt_softc {
usbd_xfer_handle sc_in_xfer;
void *sc_in_buf;
usb_callout_t sc_read_callout;
struct callout sc_read_callout;
int sc_has_callout;
u_char sc_state;
@ -164,8 +166,28 @@ void ieee1284_print_id(char *);
#define ULPTUNIT(s) (minor(s) & 0x1f)
#define ULPTFLAGS(s) (minor(s) & 0xe0)
static device_probe_t ulpt_match;
static device_attach_t ulpt_attach;
static device_detach_t ulpt_detach;
USB_DECLARE_DRIVER(ulpt);
static device_method_t ulpt_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, ulpt_match),
DEVMETHOD(device_attach, ulpt_attach),
DEVMETHOD(device_detach, ulpt_detach),
{ 0, 0 }
};
static driver_t ulpt_driver = {
"ulpt",
ulpt_methods,
sizeof(struct ulpt_softc)
};
static devclass_t ulpt_devclass;
DRIVER_MODULE(ulpt, uhub, ulpt_driver, ulpt_devclass, usbd_driver_load, 0);
static int
ulpt_match(device_t self)
@ -190,7 +212,8 @@ ulpt_match(device_t self)
static int
ulpt_attach(device_t self)
{
USB_ATTACH_START(ulpt, sc, uaa);
struct ulpt_softc *sc = device_get_softc(self);
struct usb_attach_arg *uaa = device_get_ivars(self);
usbd_device_handle dev = uaa->device;
usbd_interface_handle iface = uaa->iface;
usb_interface_descriptor_t *ifcd = usbd_get_interface_descriptor(iface);
@ -340,7 +363,7 @@ ulpt_attach(device_t self)
static int
ulpt_detach(device_t self)
{
USB_DETACH_START(ulpt, sc);
struct ulpt_softc *sc = device_get_softc(self);
int s;
DPRINTF(("ulpt_detach: sc=%p\n", sc));
@ -444,7 +467,9 @@ ulptopen(struct cdev *dev, int flag, int mode, struct thread *p)
usbd_status err;
int error;
USB_GET_SC_OPEN(ulpt, ULPTUNIT(dev), sc);
sc = devclass_get_softc(ulpt_devclass, ULPTUNIT(dev));
if (sc == NULL)
return (ENXIO);
if (sc == NULL || sc->sc_iface == NULL || sc->sc_dying)
return (ENXIO);
@ -513,8 +538,9 @@ ulptopen(struct cdev *dev, int flag, int mode, struct thread *p)
/* If it's not opened for read the set up a reader. */
if (!(flag & FREAD)) {
DPRINTF(("ulpt_open: start read callout\n"));
usb_callout_init(sc->sc_read_callout);
usb_callout(sc->sc_read_callout, hz/5, ulpt_tick, sc);
callout_init(&sc->sc_read_callout, 0);
callout_reset(&sc->sc_read_callout, hz/5, ulpt_tick,
sc);
sc->sc_has_callout = 1;
}
}
@ -569,14 +595,14 @@ ulptclose(struct cdev *dev, int flag, int mode, struct thread *p)
{
struct ulpt_softc *sc;
USB_GET_SC(ulpt, ULPTUNIT(dev), sc);
sc = devclass_get_softc(ulpt_devclass, ULPTUNIT(dev));
if (sc->sc_state != ULPT_OPEN)
/* We are being forced to close before the open completed. */
return (0);
if (sc->sc_has_callout) {
usb_uncallout(sc->sc_read_callout, ulpt_tick, sc);
callout_stop(&sc->sc_read_callout);
sc->sc_has_callout = 0;
}
@ -642,7 +668,7 @@ ulptwrite(struct cdev *dev, struct uio *uio, int flags)
struct ulpt_softc *sc;
int error;
USB_GET_SC(ulpt, ULPTUNIT(dev), sc);
sc = devclass_get_softc(ulpt_devclass, ULPTUNIT(dev));
if (sc->sc_dying)
return (EIO);
@ -697,7 +723,7 @@ ulptread(struct cdev *dev, struct uio *uio, int flags)
struct ulpt_softc *sc;
int error;
USB_GET_SC(ulpt, ULPTUNIT(dev), sc);
sc = devclass_get_softc(ulpt_devclass, ULPTUNIT(dev));
if (sc->sc_dying)
return (EIO);
@ -728,8 +754,8 @@ ulpt_read_cb(usbd_xfer_handle xfer, usbd_private_handle priv,
DPRINTF(("ulpt_tick: discarding %d bytes\n", n));
#endif
if (!err || err == USBD_TIMEOUT)
usb_callout(sc->sc_read_callout, hz / ULPT_READS_PER_SEC,
ulpt_tick, sc);
callout_reset(&sc->sc_read_callout, hz / ULPT_READS_PER_SEC,
ulpt_tick, sc);
}
void
@ -786,5 +812,3 @@ ieee1284_print_id(char *str)
}
}
#endif
DRIVER_MODULE(ulpt, uhub, ulpt_driver, ulpt_devclass, usbd_driver_load, 0);

View File

@ -58,6 +58,7 @@ __FBSDID("$FreeBSD$");
#include <sys/sysctl.h>
#include <sys/uio.h>
#include <dev/usb/usb_port.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbhid.h>

View File

@ -153,7 +153,6 @@ struct cdevsw usb_cdevsw = {
};
static void usb_discover(void *);
static bus_child_detached_t usb_child_detached;
static void usb_create_event_thread(void *);
static void usb_event_thread(void *);
static void usb_task_thread(void *);
@ -181,13 +180,38 @@ static int usb_get_next_event(struct usb_event *);
static const char *usbrev_str[] = USBREV_STR;
USB_DECLARE_DRIVER_INIT(usb,
DEVMETHOD(bus_child_detached, usb_child_detached),
DEVMETHOD(device_suspend, bus_generic_suspend),
DEVMETHOD(device_resume, bus_generic_resume),
DEVMETHOD(device_shutdown, bus_generic_shutdown)
);
static device_probe_t usb_match;
static device_attach_t usb_attach;
static device_detach_t usb_detach;
static bus_child_detached_t usb_child_detached;
static device_method_t usb_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, usb_match),
DEVMETHOD(device_attach, usb_attach),
DEVMETHOD(device_detach, usb_detach),
DEVMETHOD(device_suspend, bus_generic_suspend),
DEVMETHOD(device_resume, bus_generic_resume),
DEVMETHOD(device_shutdown, bus_generic_shutdown),
/* Bus interface */
DEVMETHOD(bus_child_detached, usb_child_detached),
{ 0, 0 }
};
static driver_t usb_driver = {
"usb",
usb_methods,
sizeof(struct usb_softc)
};
static devclass_t usb_devclass;
DRIVER_MODULE(usb, ohci, usb_driver, usb_devclass, 0, 0);
DRIVER_MODULE(usb, uhci, usb_driver, usb_devclass, 0, 0);
DRIVER_MODULE(usb, ehci, usb_driver, usb_devclass, 0, 0);
DRIVER_MODULE(usb, slhci, usb_driver, usb_devclass, 0, 0);
MODULE_VERSION(usb, 1);
static int
@ -291,7 +315,7 @@ usb_attach(device_t self)
if (cold)
sc->sc_bus->use_polling--;
config_pending_incr();
/* XXX really do right config_pending_incr(); */
usb_create_event_thread(sc);
/* The per controller devices (used for usb_discover) */
/* XXX This is redundant now, but old usbd's will want it */
@ -407,7 +431,7 @@ usb_event_thread(void *arg)
/* Make sure first discover does something. */
sc->sc_bus->needs_explore = 1;
usb_discover(sc);
config_pending_decr();
/* XXX really do right config_pending_decr(); */
while (!sc->sc_dying) {
#ifdef USB_DEBUG
@ -482,9 +506,9 @@ usbopen(struct cdev *dev, int flag, int mode, struct thread *p)
usb_async_proc = 0;
return (0);
}
USB_GET_SC_OPEN(usb, unit, sc);
sc = devclass_get_softc(usb_devclass, unit);
if (sc == NULL)
return (ENXIO);
if (sc->sc_dying)
return (EIO);
@ -561,9 +585,7 @@ usbioctl(struct cdev *devt, u_long cmd, caddr_t data, int flag, struct thread *p
return (EINVAL);
}
}
USB_GET_SC(usb, unit, sc);
sc = devclass_get_softc(usb_devclass, unit);
if (sc->sc_dying)
return (EIO);
@ -826,7 +848,7 @@ usb_schedsoftintr(usbd_bus_handle bus)
static int
usb_detach(device_t self)
{
USB_DETACH_START(usb, sc);
struct usb_softc *sc = device_get_softc(self);
struct usb_event ue;
struct usb_taskq *taskq;
int i;
@ -909,9 +931,5 @@ usb_cold_explore(void *arg)
}
}
DRIVER_MODULE(usb, ohci, usb_driver, usb_devclass, 0, 0);
DRIVER_MODULE(usb, uhci, usb_driver, usb_devclass, 0, 0);
DRIVER_MODULE(usb, ehci, usb_driver, usb_devclass, 0, 0);
DRIVER_MODULE(usb, slhci, usb_driver, usb_devclass, 0, 0);
SYSINIT(usb_cold_explore, SI_SUB_CONFIGURE, SI_ORDER_MIDDLE,
usb_cold_explore, NULL);