From bc96c0ad1ed0c938fefc0423aa99f086c5a2a1ea Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Mon, 25 Apr 2005 11:21:31 -0400 Subject: [PATCH] ohci-omap, sl811, dummy: remove hub_set_power_budget This patch changes the HCDs that used the old hub_set_power_budget call, making them use the new hcd->power_budget field instead. Signed-off-by: Alan Stern Acked-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/dummy_hcd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/usb/gadget/dummy_hcd.c') diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index c039d2fbe7a..9d37fc771b2 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c @@ -1646,6 +1646,9 @@ static int dummy_start (struct usb_hcd *hcd) if (!root) return -ENOMEM; + /* only show a low-power port: just 8mA */ + hcd->power_budget = 8; + /* root hub enters addressed state... */ hcd->state = HC_STATE_RUNNING; root->speed = USB_SPEED_HIGH; @@ -1655,9 +1658,6 @@ static int dummy_start (struct usb_hcd *hcd) goto err1; } - /* only show a low-power port: just 8mA */ - hub_set_power_budget (root, 8); - if ((retval = dummy_register_udc (dum)) != 0) goto err2; -- cgit v1.2.3 From 247f3105636caa9d1d8a4c3dfb755de42633bc80 Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Mon, 25 Apr 2005 11:28:04 -0400 Subject: [PATCH] USB HCDs: no longer need to register root hub This patch changes the host controller drivers; they no longer need to register their root hubs because usbcore will take care of it for them. Signed-off-by: Alan Stern Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/dummy_hcd.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) (limited to 'drivers/usb/gadget/dummy_hcd.c') diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index 9d37fc771b2..1918d10f756 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c @@ -1625,7 +1625,6 @@ static DEVICE_ATTR (urbs, S_IRUGO, show_urbs, NULL); static int dummy_start (struct usb_hcd *hcd) { struct dummy *dum; - struct usb_device *root; int retval; dum = hcd_to_dummy (hcd); @@ -1642,35 +1641,16 @@ static int dummy_start (struct usb_hcd *hcd) INIT_LIST_HEAD (&dum->urbp_list); - root = usb_alloc_dev (NULL, &hcd->self, 0); - if (!root) - return -ENOMEM; + if ((retval = dummy_register_udc (dum)) != 0) + return retval; /* only show a low-power port: just 8mA */ hcd->power_budget = 8; - - /* root hub enters addressed state... */ hcd->state = HC_STATE_RUNNING; - root->speed = USB_SPEED_HIGH; - - /* ...then configured, so khubd sees us. */ - if ((retval = usb_hcd_register_root_hub (root, hcd)) != 0) { - goto err1; - } - - if ((retval = dummy_register_udc (dum)) != 0) - goto err2; /* FIXME 'urbs' should be a per-device thing, maybe in usbcore */ device_create_file (dummy_dev(dum), &dev_attr_urbs); return 0; - - err2: - usb_disconnect (&hcd->self.root_hub); - err1: - usb_put_dev (root); - hcd->state = HC_STATE_QUIESCING; - return retval; } static void dummy_stop (struct usb_hcd *hcd) -- cgit v1.2.3 From 5742b0c95026c817d9c266174ca39a909e8d38ca Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Mon, 2 May 2005 11:25:17 -0400 Subject: [PATCH] USB dummy_hcd: Partial OTG emulation Partial OTG support for dummy_hcd, mostly as a framework for further work. It emulates the new OTG flags in the host and peripheral frameworks, if that option is configured. But it's incomplete: - Resetting the peripheral needs to clear the OTG state bits; a second enumeration won't work correctly. - This stops modeling HNP right when roles should switch the first time. It should probably disconnect, then set the usb_bus.is_b_host and usb_gadget.is_a_peripheral flags; then it'd enumerate almost normally, except for the role reversal. Roles could then switch a second time, back to "normal" (with those flags cleared). - SRP should be modeled as "resume from port-unpowered", which is a state that usbcore doesn't yet use. HNP can be triggered by enabling the OTG whitelist and configuring a gadget driver that's not in that list; or by configuring Gadget Zero to identify itself as the HNP test device. Sent-by: David Brownell Signed-off-by: Alan Stern Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/dummy_hcd.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'drivers/usb/gadget/dummy_hcd.c') diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index 1918d10f756..e9b95df5b23 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c @@ -601,8 +601,10 @@ static int dummy_wakeup (struct usb_gadget *_gadget) struct dummy *dum; dum = gadget_to_dummy (_gadget); - if ((dum->devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP)) == 0 - || !(dum->port_status & (1 << USB_PORT_FEAT_SUSPEND))) + if (!(dum->port_status & (1 << USB_PORT_FEAT_SUSPEND)) + || !(dum->devstatus & + ( (1 << USB_DEVICE_B_HNP_ENABLE) + | (1 << USB_DEVICE_REMOTE_WAKEUP)))) return -EINVAL; /* hub notices our request, issues downstream resume, etc */ @@ -713,6 +715,9 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver) dum->gadget.ops = &dummy_ops; dum->gadget.is_dualspeed = 1; + /* maybe claim OTG support, though we won't complete HNP */ + dum->gadget.is_otg = (dummy_to_hcd(dum)->self.otg_port != 0); + dum->devstatus = 0; dum->resuming = 0; @@ -1215,6 +1220,16 @@ restart: switch (setup.wValue) { case USB_DEVICE_REMOTE_WAKEUP: break; + case USB_DEVICE_B_HNP_ENABLE: + dum->gadget.b_hnp_enable = 1; + break; + case USB_DEVICE_A_HNP_SUPPORT: + dum->gadget.a_hnp_support = 1; + break; + case USB_DEVICE_A_ALT_HNP_SUPPORT: + dum->gadget.a_alt_hnp_support + = 1; + break; default: value = -EOPNOTSUPP; } @@ -1533,6 +1548,13 @@ static int dummy_hub_control ( spin_unlock (&dum->lock); dum->driver->suspend (&dum->gadget); spin_lock (&dum->lock); + /* HNP would happen here; for now we + * assume b_bus_req is always true. + */ + if (((1 << USB_DEVICE_B_HNP_ENABLE) + & dum->devstatus) != 0) + dev_dbg (dummy_dev(dum), + "no HNP yet!\n"); } } break; @@ -1648,6 +1670,10 @@ static int dummy_start (struct usb_hcd *hcd) hcd->power_budget = 8; hcd->state = HC_STATE_RUNNING; +#ifdef CONFIG_USB_OTG + hcd->self.otg_port = 1; +#endif + /* FIXME 'urbs' should be a per-device thing, maybe in usbcore */ device_create_file (dummy_dev(dum), &dev_attr_urbs); return 0; -- cgit v1.2.3 From c2db8b5e5692a6f35913a829607ee6efde3c7cbd Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Fri, 29 Apr 2005 16:30:48 -0400 Subject: [PATCH] USB: dummy_hcd: USB_PORT_FEAT changed to USB_PORT_STAT This patch makes some cosmetic changes to dummy_hcd: Minor alterations of comments and whitespace. Replace USB_PORT_FEAT_xxx with USB_PORT_STAT_xxx. This is appropriate as the values are stored in a status variable and they aren't feature indices. Also it allows the elimination of a bunch of awkward bit shift operations. Signed-off-by: Alan Stern Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/dummy_hcd.c | 50 +++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 27 deletions(-) (limited to 'drivers/usb/gadget/dummy_hcd.c') diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index e9b95df5b23..ffedf4d1b74 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c @@ -601,7 +601,7 @@ static int dummy_wakeup (struct usb_gadget *_gadget) struct dummy *dum; dum = gadget_to_dummy (_gadget); - if (!(dum->port_status & (1 << USB_PORT_FEAT_SUSPEND)) + if (!(dum->port_status & USB_PORT_STAT_SUSPEND) || !(dum->devstatus & ( (1 << USB_DEVICE_B_HNP_ENABLE) | (1 << USB_DEVICE_REMOTE_WAKEUP)))) @@ -609,7 +609,7 @@ static int dummy_wakeup (struct usb_gadget *_gadget) /* hub notices our request, issues downstream resume, etc */ dum->resuming = 1; - dum->port_status |= (1 << USB_PORT_FEAT_C_SUSPEND); + dum->port_status |= (USB_PORT_STAT_C_SUSPEND << 16); return 0; } @@ -661,15 +661,15 @@ DEVICE_ATTR (function, S_IRUGO, show_function, NULL); * for each driver that registers: just add to a big root hub. */ +/* This doesn't need to do anything because the udc device structure is + * stored inside the hcd and will be deallocated along with it. */ static void -dummy_udc_release (struct device *dev) -{ -} +dummy_udc_release (struct device *dev) {} +/* This doesn't need to do anything because the pdev structure is + * statically allocated. */ static void -dummy_pdev_release (struct device *dev) -{ -} +dummy_pdev_release (struct device *dev) {} static int dummy_register_udc (struct dummy *dum) @@ -753,15 +753,13 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver) return retval; } - // FIXME: Check these calls for errors and re-order driver->driver.bus = dum->gadget.dev.parent->bus; driver_register (&driver->driver); - device_bind_driver (&dum->gadget.dev); /* khubd will enumerate this in a while */ dum->port_status |= USB_PORT_STAT_CONNECTION - | (1 << USB_PORT_FEAT_C_CONNECTION); + | (USB_PORT_STAT_C_CONNECTION << 16); return 0; } EXPORT_SYMBOL (usb_gadget_register_driver); @@ -807,14 +805,13 @@ usb_gadget_unregister_driver (struct usb_gadget_driver *driver) stop_activity (dum, driver); dum->port_status &= ~(USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE | USB_PORT_STAT_LOW_SPEED | USB_PORT_STAT_HIGH_SPEED); - dum->port_status |= (1 << USB_PORT_FEAT_C_CONNECTION); + dum->port_status |= (USB_PORT_STAT_C_CONNECTION << 16); spin_unlock_irqrestore (&dum->lock, flags); driver->unbind (&dum->gadget); dum->driver = NULL; device_release_driver (&dum->gadget.dev); - driver_unregister (&driver->driver); return 0; @@ -1406,11 +1403,11 @@ return_urb: /*-------------------------------------------------------------------------*/ #define PORT_C_MASK \ - ((1 << USB_PORT_FEAT_C_CONNECTION) \ - | (1 << USB_PORT_FEAT_C_ENABLE) \ - | (1 << USB_PORT_FEAT_C_SUSPEND) \ - | (1 << USB_PORT_FEAT_C_OVER_CURRENT) \ - | (1 << USB_PORT_FEAT_C_RESET)) + ((USB_PORT_STAT_C_CONNECTION \ + | USB_PORT_STAT_C_ENABLE \ + | USB_PORT_STAT_C_SUSPEND \ + | USB_PORT_STAT_C_OVERCURRENT \ + | USB_PORT_STAT_C_RESET) << 16) static int dummy_hub_status (struct usb_hcd *hcd, char *buf) { @@ -1465,7 +1462,7 @@ static int dummy_hub_control ( case ClearPortFeature: switch (wValue) { case USB_PORT_FEAT_SUSPEND: - if (dum->port_status & (1 << USB_PORT_FEAT_SUSPEND)) { + if (dum->port_status & USB_PORT_STAT_SUSPEND) { /* 20msec resume signaling */ dum->resuming = 1; dum->re_timeout = jiffies + @@ -1495,8 +1492,8 @@ static int dummy_hub_control ( * complete it!! */ if (dum->resuming && time_after (jiffies, dum->re_timeout)) { - dum->port_status |= (1 << USB_PORT_FEAT_C_SUSPEND); - dum->port_status &= ~(1 << USB_PORT_FEAT_SUSPEND); + dum->port_status |= (USB_PORT_STAT_C_SUSPEND << 16); + dum->port_status &= ~USB_PORT_STAT_SUSPEND; dum->resuming = 0; dum->re_timeout = 0; if (dum->driver && dum->driver->resume) { @@ -1505,10 +1502,10 @@ static int dummy_hub_control ( spin_lock (&dum->lock); } } - if ((dum->port_status & (1 << USB_PORT_FEAT_RESET)) != 0 + if ((dum->port_status & USB_PORT_STAT_RESET) != 0 && time_after (jiffies, dum->re_timeout)) { - dum->port_status |= (1 << USB_PORT_FEAT_C_RESET); - dum->port_status &= ~(1 << USB_PORT_FEAT_RESET); + dum->port_status |= (USB_PORT_STAT_C_RESET << 16); + dum->port_status &= ~USB_PORT_STAT_RESET; dum->re_timeout = 0; if (dum->driver) { dum->port_status |= USB_PORT_STAT_ENABLE; @@ -1540,10 +1537,9 @@ static int dummy_hub_control ( case SetPortFeature: switch (wValue) { case USB_PORT_FEAT_SUSPEND: - if ((dum->port_status & (1 << USB_PORT_FEAT_SUSPEND)) + if ((dum->port_status & USB_PORT_STAT_SUSPEND) == 0) { - dum->port_status |= - (1 << USB_PORT_FEAT_SUSPEND); + dum->port_status |= USB_PORT_STAT_SUSPEND; if (dum->driver && dum->driver->suspend) { spin_unlock (&dum->lock); dum->driver->suspend (&dum->gadget); -- cgit v1.2.3 From d9b762510c186584a6be0d3ece03e8a4b2ac13a8 Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Tue, 3 May 2005 16:15:43 -0400 Subject: [PATCH] USB dummy_hcd: Use separate pdevs for HC and UDC This patch makes the dummy_hcd driver create separate platform devices for the emulated host controller and emulated device controller. This gives a more accurate simulation and will permit testing of situations where only one of the two devices is suspended. This also changes the name of the host controller platform device to match the name of the driver. That way the normal platform bus probe mechanism will handle binding the driver to the device. Signed-off-by: Alan Stern Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/dummy_hcd.c | 231 ++++++++++++++++++++++++----------------- 1 file changed, 133 insertions(+), 98 deletions(-) (limited to 'drivers/usb/gadget/dummy_hcd.c') diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index ffedf4d1b74..dc0e3233b0e 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c @@ -141,6 +141,8 @@ static const char *const ep_name [] = { }; #define DUMMY_ENDPOINTS (sizeof(ep_name)/sizeof(char *)) +/*-------------------------------------------------------------------------*/ + #define FIFO_SIZE 64 struct urbp { @@ -189,6 +191,11 @@ static inline struct device *dummy_dev (struct dummy *dum) return dummy_to_hcd(dum)->self.controller; } +static inline struct device *udc_dev (struct dummy *dum) +{ + return dum->gadget.dev.parent; +} + static inline struct dummy *ep_to_dummy (struct dummy_ep *ep) { return container_of (ep->gadget, struct dummy, gadget); @@ -208,19 +215,6 @@ static struct dummy *the_controller; /*-------------------------------------------------------------------------*/ -/* - * This "hardware" may look a bit odd in diagnostics since it's got both - * host and device sides; and it binds different drivers to each side. - */ -static struct platform_device the_pdev; - -static struct device_driver dummy_driver = { - .name = (char *) driver_name, - .bus = &platform_bus_type, -}; - -/*-------------------------------------------------------------------------*/ - /* SLAVE/GADGET SIDE DRIVER * * This only tracks gadget state. All the work is done when the host @@ -324,7 +318,7 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) _ep->maxpacket = max; ep->desc = desc; - dev_dbg (dummy_dev(dum), "enabled %s (ep%d%s-%s) maxpacket %d\n", + dev_dbg (udc_dev(dum), "enabled %s (ep%d%s-%s) maxpacket %d\n", _ep->name, desc->bEndpointAddress & 0x0f, (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out", @@ -379,7 +373,7 @@ static int dummy_disable (struct usb_ep *_ep) nuke (dum, ep); spin_unlock_irqrestore (&dum->lock, flags); - dev_dbg (dummy_dev(dum), "disabled %s\n", _ep->name); + dev_dbg (udc_dev(dum), "disabled %s\n", _ep->name); return retval; } @@ -474,7 +468,7 @@ dummy_queue (struct usb_ep *_ep, struct usb_request *_req, int mem_flags) return -ESHUTDOWN; #if 0 - dev_dbg (dummy_dev(dum), "ep %p queue req %p to %s, len %d buf %p\n", + dev_dbg (udc_dev(dum), "ep %p queue req %p to %s, len %d buf %p\n", ep, _req, _ep->name, _req->length, _req->buf); #endif @@ -537,7 +531,7 @@ static int dummy_dequeue (struct usb_ep *_ep, struct usb_request *_req) spin_unlock_irqrestore (&dum->lock, flags); if (retval == 0) { - dev_dbg (dummy_dev(dum), + dev_dbg (udc_dev(dum), "dequeued req %p from %s, len %d buf %p\n", req, _ep->name, _req->length, _req->buf); _req->complete (_ep, _req); @@ -661,38 +655,6 @@ DEVICE_ATTR (function, S_IRUGO, show_function, NULL); * for each driver that registers: just add to a big root hub. */ -/* This doesn't need to do anything because the udc device structure is - * stored inside the hcd and will be deallocated along with it. */ -static void -dummy_udc_release (struct device *dev) {} - -/* This doesn't need to do anything because the pdev structure is - * statically allocated. */ -static void -dummy_pdev_release (struct device *dev) {} - -static int -dummy_register_udc (struct dummy *dum) -{ - int rc; - - strcpy (dum->gadget.dev.bus_id, "udc"); - dum->gadget.dev.parent = dummy_dev(dum); - dum->gadget.dev.release = dummy_udc_release; - - rc = device_register (&dum->gadget.dev); - if (rc == 0) - device_create_file (&dum->gadget.dev, &dev_attr_function); - return rc; -} - -static void -dummy_unregister_udc (struct dummy *dum) -{ - device_remove_file (&dum->gadget.dev, &dev_attr_function); - device_unregister (&dum->gadget.dev); -} - int usb_gadget_register_driver (struct usb_gadget_driver *driver) { @@ -711,12 +673,6 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver) * SLAVE side init ... the layer above hardware, which * can't enumerate without help from the driver we're binding. */ - dum->gadget.name = gadget_name; - dum->gadget.ops = &dummy_ops; - dum->gadget.is_dualspeed = 1; - - /* maybe claim OTG support, though we won't complete HNP */ - dum->gadget.is_otg = (dummy_to_hcd(dum)->self.otg_port != 0); dum->devstatus = 0; dum->resuming = 0; @@ -745,7 +701,7 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver) dum->driver = driver; dum->gadget.dev.driver = &driver->driver; - dev_dbg (dummy_dev(dum), "binding gadget driver '%s'\n", + dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n", driver->driver.name); if ((retval = driver->bind (&dum->gadget)) != 0) { dum->driver = NULL; @@ -798,7 +754,7 @@ usb_gadget_unregister_driver (struct usb_gadget_driver *driver) if (!driver || driver != dum->driver) return -EINVAL; - dev_dbg (dummy_dev(dum), "unregister gadget driver '%s'\n", + dev_dbg (udc_dev(dum), "unregister gadget driver '%s'\n", driver->driver.name); spin_lock_irqsave (&dum->lock, flags); @@ -826,6 +782,64 @@ int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode) } EXPORT_SYMBOL (net2280_set_fifo_mode); + +/* The gadget structure is stored inside the hcd structure and will be + * released along with it. */ +static void +dummy_gadget_release (struct device *dev) +{ +#if 0 /* usb_bus_put isn't EXPORTed! */ + struct dummy *dum = gadget_dev_to_dummy (dev); + + usb_bus_put (&dummy_to_hcd (dum)->self); +#endif +} + +static int dummy_udc_probe (struct device *dev) +{ + struct dummy *dum = the_controller; + int rc; + + dum->gadget.name = gadget_name; + dum->gadget.ops = &dummy_ops; + dum->gadget.is_dualspeed = 1; + + /* maybe claim OTG support, though we won't complete HNP */ + dum->gadget.is_otg = (dummy_to_hcd(dum)->self.otg_port != 0); + + strcpy (dum->gadget.dev.bus_id, "gadget"); + dum->gadget.dev.parent = dev; + dum->gadget.dev.release = dummy_gadget_release; + rc = device_register (&dum->gadget.dev); + if (rc < 0) + return rc; + +#if 0 /* usb_bus_get isn't EXPORTed! */ + usb_bus_get (&dummy_to_hcd (dum)->self); +#endif + + dev_set_drvdata (dev, dum); + device_create_file (&dum->gadget.dev, &dev_attr_function); + return rc; +} + +static int dummy_udc_remove (struct device *dev) +{ + struct dummy *dum = dev_get_drvdata (dev); + + dev_set_drvdata (dev, NULL); + device_remove_file (&dum->gadget.dev, &dev_attr_function); + device_unregister (&dum->gadget.dev); + return 0; +} + +static struct device_driver dummy_udc_driver = { + .name = (char *) gadget_name, + .bus = &platform_bus_type, + .probe = dummy_udc_probe, + .remove = dummy_udc_remove, +}; + /*-------------------------------------------------------------------------*/ /* MASTER/HOST SIDE DRIVER @@ -1184,7 +1198,7 @@ restart: list_for_each_entry (req, &ep->queue, queue) { list_del_init (&req->queue); req->req.status = -EOVERFLOW; - dev_dbg (dummy_dev(dum), "stale req = %p\n", + dev_dbg (udc_dev(dum), "stale req = %p\n", req); spin_unlock (&dum->lock); @@ -1207,7 +1221,7 @@ restart: break; dum->address = setup.wValue; maybe_set_status (urb, 0); - dev_dbg (dummy_dev(dum), "set_address = %d\n", + dev_dbg (udc_dev(dum), "set_address = %d\n", setup.wValue); value = 0; break; @@ -1333,7 +1347,7 @@ restart: if (value < 0) { if (value != -EOPNOTSUPP) - dev_dbg (dummy_dev(dum), + dev_dbg (udc_dev(dum), "setup --> %d\n", value); maybe_set_status (urb, -EPIPE); @@ -1561,7 +1575,7 @@ static int dummy_hub_control ( | USB_PORT_STAT_LOW_SPEED | USB_PORT_STAT_HIGH_SPEED); if (dum->driver) { - dev_dbg (dummy_dev(dum), + dev_dbg (udc_dev(dum), "disconnect\n"); stop_activity (dum, dum->driver); } @@ -1643,7 +1657,6 @@ static DEVICE_ATTR (urbs, S_IRUGO, show_urbs, NULL); static int dummy_start (struct usb_hcd *hcd) { struct dummy *dum; - int retval; dum = hcd_to_dummy (hcd); @@ -1659,9 +1672,6 @@ static int dummy_start (struct usb_hcd *hcd) INIT_LIST_HEAD (&dum->urbp_list); - if ((retval = dummy_register_udc (dum)) != 0) - return retval; - /* only show a low-power port: just 8mA */ hcd->power_budget = 8; hcd->state = HC_STATE_RUNNING; @@ -1682,10 +1692,7 @@ static void dummy_stop (struct usb_hcd *hcd) dum = hcd_to_dummy (hcd); device_remove_file (dummy_dev(dum), &dev_attr_urbs); - usb_gadget_unregister_driver (dum->driver); - dummy_unregister_udc (dum); - dev_info (dummy_dev(dum), "stopped\n"); } @@ -1715,7 +1722,7 @@ static const struct hc_driver dummy_hcd = { .hub_control = dummy_hub_control, }; -static int dummy_probe (struct device *dev) +static int dummy_hcd_probe (struct device *dev) { struct usb_hcd *hcd; int retval; @@ -1735,7 +1742,7 @@ static int dummy_probe (struct device *dev) return retval; } -static void dummy_remove (struct device *dev) +static int dummy_hcd_remove (struct device *dev) { struct usb_hcd *hcd; @@ -1743,35 +1750,41 @@ static void dummy_remove (struct device *dev) usb_remove_hcd (hcd); usb_put_hcd (hcd); the_controller = NULL; + return 0; } -/*-------------------------------------------------------------------------*/ - -static int dummy_pdev_detect (void) -{ - int retval; - - retval = driver_register (&dummy_driver); - if (retval < 0) - return retval; +static struct device_driver dummy_hcd_driver = { + .name = (char *) driver_name, + .bus = &platform_bus_type, + .probe = dummy_hcd_probe, + .remove = dummy_hcd_remove, +}; - the_pdev.name = "hc"; - the_pdev.dev.driver = &dummy_driver; - the_pdev.dev.release = dummy_pdev_release; +/*-------------------------------------------------------------------------*/ - retval = platform_device_register (&the_pdev); - if (retval < 0) - driver_unregister (&dummy_driver); - return retval; -} +/* These don't need to do anything because the pdev structures are + * statically allocated. */ +static void +dummy_udc_release (struct device *dev) {} -static void dummy_pdev_remove (void) -{ - platform_device_unregister (&the_pdev); - driver_unregister (&dummy_driver); -} +static void +dummy_hcd_release (struct device *dev) {} + +static struct platform_device the_udc_pdev = { + .name = (char *) gadget_name, + .id = -1, + .dev = { + .release = dummy_udc_release, + }, +}; -/*-------------------------------------------------------------------------*/ +static struct platform_device the_hcd_pdev = { + .name = (char *) driver_name, + .id = -1, + .dev = { + .release = dummy_hcd_release, + }, +}; static int __init init (void) { @@ -1779,17 +1792,39 @@ static int __init init (void) if (usb_disabled ()) return -ENODEV; - if ((retval = dummy_pdev_detect ()) != 0) + + retval = driver_register (&dummy_hcd_driver); + if (retval < 0) return retval; - if ((retval = dummy_probe (&the_pdev.dev)) != 0) - dummy_pdev_remove (); + + retval = driver_register (&dummy_udc_driver); + if (retval < 0) + goto err_register_udc_driver; + + retval = platform_device_register (&the_hcd_pdev); + if (retval < 0) + goto err_register_hcd; + + retval = platform_device_register (&the_udc_pdev); + if (retval < 0) + goto err_register_udc; + return retval; + +err_register_udc: + platform_device_unregister (&the_hcd_pdev); +err_register_hcd: + driver_unregister (&dummy_udc_driver); +err_register_udc_driver: + driver_unregister (&dummy_hcd_driver); return retval; } module_init (init); static void __exit cleanup (void) { - dummy_remove (&the_pdev.dev); - dummy_pdev_remove (); + platform_device_unregister (&the_udc_pdev); + platform_device_unregister (&the_hcd_pdev); + driver_unregister (&dummy_udc_driver); + driver_unregister (&dummy_hcd_driver); } module_exit (cleanup); -- cgit v1.2.3 From f1c39fad7d1bbea31744138cd3a532ff346cd4ab Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Tue, 3 May 2005 16:24:04 -0400 Subject: [PATCH] USB dummy_hcd: Centralize link state computations This patch adds to the dummy_hcd driver a new routine for keeping track of all changes in the state of the emulated USB link. The logic is now kept in one spot instead of spread around, and it's easier to verify and update the code. The behavior of the port features has been corrected in a few respects as well (for instance, if the POWER feature is clear then none of the other features can be set). Also added is support for the (relatively new) _connect() and _disconnect() calls of the Gadget API. Signed-off-by: Alan Stern Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/dummy_hcd.c | 254 ++++++++++++++++++++++++++--------------- 1 file changed, 162 insertions(+), 92 deletions(-) (limited to 'drivers/usb/gadget/dummy_hcd.c') diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index dc0e3233b0e..2d6d2295132 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c @@ -163,12 +163,16 @@ struct dummy { struct dummy_request fifo_req; u8 fifo_buf [FIFO_SIZE]; u16 devstatus; + unsigned pullup:1; + unsigned active:1; + unsigned old_active:1; /* * MASTER/HOST side support */ struct timer_list timer; u32 port_status; + u32 old_status; unsigned resuming:1; unsigned long re_timeout; @@ -215,6 +219,98 @@ static struct dummy *the_controller; /*-------------------------------------------------------------------------*/ +/* SLAVE/GADGET SIDE UTILITY ROUTINES */ + +/* called with spinlock held */ +static void nuke (struct dummy *dum, struct dummy_ep *ep) +{ + while (!list_empty (&ep->queue)) { + struct dummy_request *req; + + req = list_entry (ep->queue.next, struct dummy_request, queue); + list_del_init (&req->queue); + req->req.status = -ESHUTDOWN; + + spin_unlock (&dum->lock); + req->req.complete (&ep->ep, &req->req); + spin_lock (&dum->lock); + } +} + +/* caller must hold lock */ +static void +stop_activity (struct dummy *dum) +{ + struct dummy_ep *ep; + + /* prevent any more requests */ + dum->address = 0; + + /* The timer is left running so that outstanding URBs can fail */ + + /* nuke any pending requests first, so driver i/o is quiesced */ + list_for_each_entry (ep, &dum->gadget.ep_list, ep.ep_list) + nuke (dum, ep); + + /* driver now does any non-usb quiescing necessary */ +} + +/* caller must hold lock */ +static void +set_link_state (struct dummy *dum) +{ + dum->active = 0; + if ((dum->port_status & USB_PORT_STAT_POWER) == 0) + dum->port_status = 0; + else if (!dum->pullup) { + dum->port_status &= ~(USB_PORT_STAT_CONNECTION | + USB_PORT_STAT_ENABLE | + USB_PORT_STAT_LOW_SPEED | + USB_PORT_STAT_HIGH_SPEED | + USB_PORT_STAT_SUSPEND); + if ((dum->old_status & USB_PORT_STAT_CONNECTION) != 0) + dum->port_status |= (USB_PORT_STAT_C_CONNECTION << 16); + } else { + dum->port_status |= USB_PORT_STAT_CONNECTION; + if ((dum->old_status & USB_PORT_STAT_CONNECTION) == 0) + dum->port_status |= (USB_PORT_STAT_C_CONNECTION << 16); + if ((dum->port_status & USB_PORT_STAT_ENABLE) == 0) + dum->port_status &= ~USB_PORT_STAT_SUSPEND; + else if ((dum->port_status & USB_PORT_STAT_SUSPEND) == 0) + dum->active = 1; + } + + if ((dum->port_status & USB_PORT_STAT_ENABLE) == 0 || dum->active) + dum->resuming = 0; + + if ((dum->port_status & USB_PORT_STAT_CONNECTION) == 0 || + (dum->port_status & USB_PORT_STAT_RESET) != 0) { + if ((dum->old_status & USB_PORT_STAT_CONNECTION) != 0 && + (dum->old_status & USB_PORT_STAT_RESET) == 0 && + dum->driver) { + stop_activity (dum); + spin_unlock (&dum->lock); + dum->driver->disconnect (&dum->gadget); + spin_lock (&dum->lock); + } + } else if (dum->active != dum->old_active) { + if (dum->old_active && dum->driver->suspend) { + spin_unlock (&dum->lock); + dum->driver->suspend (&dum->gadget); + spin_lock (&dum->lock); + } else if (!dum->old_active && dum->driver->resume) { + spin_unlock (&dum->lock); + dum->driver->resume (&dum->gadget); + spin_lock (&dum->lock); + } + } + + dum->old_status = dum->port_status; + dum->old_active = dum->active; +} + +/*-------------------------------------------------------------------------*/ + /* SLAVE/GADGET SIDE DRIVER * * This only tracks gadget state. All the work is done when the host @@ -339,22 +435,6 @@ done: return retval; } -/* called with spinlock held */ -static void nuke (struct dummy *dum, struct dummy_ep *ep) -{ - while (!list_empty (&ep->queue)) { - struct dummy_request *req; - - req = list_entry (ep->queue.next, struct dummy_request, queue); - list_del_init (&req->queue); - req->req.status = -ESHUTDOWN; - - spin_unlock (&dum->lock); - req->req.complete (&ep->ep, &req->req); - spin_lock (&dum->lock); - } -} - static int dummy_disable (struct usb_ep *_ep) { struct dummy_ep *ep; @@ -603,7 +683,7 @@ static int dummy_wakeup (struct usb_gadget *_gadget) /* hub notices our request, issues downstream resume, etc */ dum->resuming = 1; - dum->port_status |= (USB_PORT_STAT_C_SUSPEND << 16); + dum->re_timeout = jiffies + msecs_to_jiffies(20); return 0; } @@ -619,10 +699,24 @@ static int dummy_set_selfpowered (struct usb_gadget *_gadget, int value) return 0; } +static int dummy_pullup (struct usb_gadget *_gadget, int value) +{ + struct dummy *dum; + unsigned long flags; + + dum = gadget_to_dummy (_gadget); + spin_lock_irqsave (&dum->lock, flags); + dum->pullup = (value != 0); + set_link_state (dum); + spin_unlock_irqrestore (&dum->lock, flags); + return 0; +} + static const struct usb_gadget_ops dummy_ops = { .get_frame = dummy_g_get_frame, .wakeup = dummy_wakeup, .set_selfpowered = dummy_set_selfpowered, + .pullup = dummy_pullup, }; /*-------------------------------------------------------------------------*/ @@ -675,7 +769,6 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver) */ dum->devstatus = 0; - dum->resuming = 0; INIT_LIST_HEAD (&dum->gadget.ep_list); for (i = 0; i < DUMMY_ENDPOINTS; i++) { @@ -714,35 +807,14 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver) device_bind_driver (&dum->gadget.dev); /* khubd will enumerate this in a while */ - dum->port_status |= USB_PORT_STAT_CONNECTION - | (USB_PORT_STAT_C_CONNECTION << 16); + spin_lock_irq (&dum->lock); + dum->pullup = 1; + set_link_state (dum); + spin_unlock_irq (&dum->lock); return 0; } EXPORT_SYMBOL (usb_gadget_register_driver); -/* caller must hold lock */ -static void -stop_activity (struct dummy *dum, struct usb_gadget_driver *driver) -{ - struct dummy_ep *ep; - - /* prevent any more requests */ - dum->address = 0; - - /* The timer is left running so that outstanding URBs can fail */ - - /* nuke any pending requests first, so driver i/o is quiesced */ - list_for_each_entry (ep, &dum->gadget.ep_list, ep.ep_list) - nuke (dum, ep); - - /* driver now does any non-usb quiescing necessary */ - if (driver) { - spin_unlock (&dum->lock); - driver->disconnect (&dum->gadget); - spin_lock (&dum->lock); - } -} - int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) { @@ -758,10 +830,8 @@ usb_gadget_unregister_driver (struct usb_gadget_driver *driver) driver->driver.name); spin_lock_irqsave (&dum->lock, flags); - stop_activity (dum, driver); - dum->port_status &= ~(USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE | - USB_PORT_STAT_LOW_SPEED | USB_PORT_STAT_HIGH_SPEED); - dum->port_status |= (USB_PORT_STAT_C_CONNECTION << 16); + dum->pullup = 0; + set_link_state (dum); spin_unlock_irqrestore (&dum->lock, flags); driver->unbind (&dum->gadget); @@ -770,6 +840,11 @@ usb_gadget_unregister_driver (struct usb_gadget_driver *driver) device_release_driver (&dum->gadget.dev); driver_unregister (&driver->driver); + spin_lock_irqsave (&dum->lock, flags); + dum->pullup = 0; + set_link_state (dum); + spin_unlock_irqrestore (&dum->lock, flags); + return 0; } EXPORT_SYMBOL (usb_gadget_unregister_driver); @@ -1432,6 +1507,13 @@ static int dummy_hub_status (struct usb_hcd *hcd, char *buf) dum = hcd_to_dummy (hcd); spin_lock_irqsave (&dum->lock, flags); + + if (dum->resuming && time_after_eq (jiffies, dum->re_timeout)) { + dum->port_status |= (USB_PORT_STAT_C_SUSPEND << 16); + dum->port_status &= ~USB_PORT_STAT_SUSPEND; + set_link_state (dum); + } + if (!(dum->port_status & PORT_C_MASK)) retval = 0; else { @@ -1480,16 +1562,16 @@ static int dummy_hub_control ( /* 20msec resume signaling */ dum->resuming = 1; dum->re_timeout = jiffies + - msecs_to_jiffies(20); + msecs_to_jiffies(20); } break; case USB_PORT_FEAT_POWER: - dum->port_status = 0; - dum->resuming = 0; - stop_activity(dum, dum->driver); - break; + if (dum->port_status & USB_PORT_STAT_POWER) + dev_dbg (dummy_dev(dum), "power-off\n"); + /* FALLS THROUGH */ default: dum->port_status &= ~(1 << wValue); + set_link_state (dum); } break; case GetHubDescriptor: @@ -1505,23 +1587,16 @@ static int dummy_hub_control ( /* whoever resets or resumes must GetPortStatus to * complete it!! */ - if (dum->resuming && time_after (jiffies, dum->re_timeout)) { + if (dum->resuming && + time_after_eq (jiffies, dum->re_timeout)) { dum->port_status |= (USB_PORT_STAT_C_SUSPEND << 16); dum->port_status &= ~USB_PORT_STAT_SUSPEND; - dum->resuming = 0; - dum->re_timeout = 0; - if (dum->driver && dum->driver->resume) { - spin_unlock (&dum->lock); - dum->driver->resume (&dum->gadget); - spin_lock (&dum->lock); - } } - if ((dum->port_status & USB_PORT_STAT_RESET) != 0 - && time_after (jiffies, dum->re_timeout)) { + if ((dum->port_status & USB_PORT_STAT_RESET) != 0 && + time_after_eq (jiffies, dum->re_timeout)) { dum->port_status |= (USB_PORT_STAT_C_RESET << 16); dum->port_status &= ~USB_PORT_STAT_RESET; - dum->re_timeout = 0; - if (dum->driver) { + if (dum->pullup) { dum->port_status |= USB_PORT_STAT_ENABLE; /* give it the best speed we agree on */ dum->gadget.speed = dum->driver->speed; @@ -1542,6 +1617,7 @@ static int dummy_hub_control ( } } } + set_link_state (dum); ((u16 *) buf)[0] = cpu_to_le16 (dum->port_status); ((u16 *) buf)[1] = cpu_to_le16 (dum->port_status >> 16); break; @@ -1551,42 +1627,36 @@ static int dummy_hub_control ( case SetPortFeature: switch (wValue) { case USB_PORT_FEAT_SUSPEND: - if ((dum->port_status & USB_PORT_STAT_SUSPEND) - == 0) { + if (dum->active) { dum->port_status |= USB_PORT_STAT_SUSPEND; - if (dum->driver && dum->driver->suspend) { - spin_unlock (&dum->lock); - dum->driver->suspend (&dum->gadget); - spin_lock (&dum->lock); - /* HNP would happen here; for now we - * assume b_bus_req is always true. - */ - if (((1 << USB_DEVICE_B_HNP_ENABLE) - & dum->devstatus) != 0) - dev_dbg (dummy_dev(dum), + + /* HNP would happen here; for now we + * assume b_bus_req is always true. + */ + set_link_state (dum); + if (((1 << USB_DEVICE_B_HNP_ENABLE) + & dum->devstatus) != 0) + dev_dbg (dummy_dev(dum), "no HNP yet!\n"); - } } break; + case USB_PORT_FEAT_POWER: + dum->port_status |= USB_PORT_STAT_POWER; + set_link_state (dum); + break; case USB_PORT_FEAT_RESET: - /* if it's already running, disconnect first */ - if (dum->port_status & USB_PORT_STAT_ENABLE) { - dum->port_status &= ~(USB_PORT_STAT_ENABLE - | USB_PORT_STAT_LOW_SPEED - | USB_PORT_STAT_HIGH_SPEED); - if (dum->driver) { - dev_dbg (udc_dev(dum), - "disconnect\n"); - stop_activity (dum, dum->driver); - } - - /* FIXME test that code path! */ - } + /* if it's already enabled, disable */ + dum->port_status &= ~(USB_PORT_STAT_ENABLE + | USB_PORT_STAT_LOW_SPEED + | USB_PORT_STAT_HIGH_SPEED); /* 50msec reset signaling */ dum->re_timeout = jiffies + msecs_to_jiffies(50); - /* FALLTHROUGH */ + /* FALLS THROUGH */ default: - dum->port_status |= (1 << wValue); + if ((dum->port_status & USB_PORT_STAT_POWER) != 0) { + dum->port_status |= (1 << wValue); + set_link_state (dum); + } } break; -- cgit v1.2.3 From 685eb93f086eb15d9fb1e82c7400fd750f564640 Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Tue, 3 May 2005 16:27:26 -0400 Subject: [PATCH] USB dummy_hcd: Use root-hub interrupts instead of polling This patch makes the dummy_hcd driver use emulated root-hub interrupts instead of polling. It's in the spirit of similar changes being made to the other HCDs. Signed-off-by: Alan Stern Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/dummy_hcd.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'drivers/usb/gadget/dummy_hcd.c') diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index 2d6d2295132..73d2f24050a 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c @@ -684,6 +684,7 @@ static int dummy_wakeup (struct usb_gadget *_gadget) /* hub notices our request, issues downstream resume, etc */ dum->resuming = 1; dum->re_timeout = jiffies + msecs_to_jiffies(20); + mod_timer (&dummy_to_hcd (dum)->rh_timer, dum->re_timeout); return 0; } @@ -709,6 +710,8 @@ static int dummy_pullup (struct usb_gadget *_gadget, int value) dum->pullup = (value != 0); set_link_state (dum); spin_unlock_irqrestore (&dum->lock, flags); + + usb_hcd_poll_rh_status (dummy_to_hcd (dum)); return 0; } @@ -811,6 +814,8 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver) dum->pullup = 1; set_link_state (dum); spin_unlock_irq (&dum->lock); + + usb_hcd_poll_rh_status (dummy_to_hcd (dum)); return 0; } EXPORT_SYMBOL (usb_gadget_register_driver); @@ -845,6 +850,7 @@ usb_gadget_unregister_driver (struct usb_gadget_driver *driver) set_link_state (dum); spin_unlock_irqrestore (&dum->lock, flags); + usb_hcd_poll_rh_status (dummy_to_hcd (dum)); return 0; } EXPORT_SYMBOL (usb_gadget_unregister_driver); @@ -1669,6 +1675,9 @@ static int dummy_hub_control ( retval = -EPIPE; } spin_unlock_irqrestore (&dum->lock, flags); + + if ((dum->port_status & PORT_C_MASK) != 0) + usb_hcd_poll_rh_status (hcd); return retval; } @@ -1745,6 +1754,7 @@ static int dummy_start (struct usb_hcd *hcd) /* only show a low-power port: just 8mA */ hcd->power_budget = 8; hcd->state = HC_STATE_RUNNING; + hcd->uses_new_polling = 1; #ifdef CONFIG_USB_OTG hcd->self.otg_port = 1; -- cgit v1.2.3 From 1bbc169621cbe502b9143a27eb12802a0f1d43a0 Mon Sep 17 00:00:00 2001 From: David Brownell Date: Sat, 7 May 2005 13:05:13 -0700 Subject: [PATCH] USB: gadget driver updates (SETUP api change) This updates most of the gadget framework to expect SETUP packets use USB byteorder (matching the annotation in and usage in the host side stack): - definition in - gadget drivers: Ethernet/RNDIS, serial/ACM, file_storage, gadgetfs. - dummy_hcd It also includes some other similar changes as suggested by "sparse", which was used to detect byteorder bugs. Signed-off-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/dummy_hcd.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'drivers/usb/gadget/dummy_hcd.c') diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index 73d2f24050a..f9540adf2a4 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c @@ -1267,9 +1267,6 @@ restart: struct dummy_ep *ep2; setup = *(struct usb_ctrlrequest*) urb->setup_packet; - le16_to_cpus (&setup.wIndex); - le16_to_cpus (&setup.wValue); - le16_to_cpus (&setup.wLength); if (setup.wLength != urb->transfer_buffer_length) { maybe_set_status (urb, -EOVERFLOW); goto return_urb; -- cgit v1.2.3 From cc095b0b5b653dca3e106710a72ba28b5bb7456b Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Tue, 10 May 2005 15:28:38 -0400 Subject: [PATCH] USB: dummy_hcd: sparse cleanups This patch fixes the byte-ordering issue for setup packets in the dummy_hcd driver and cleans up a few things that sparse -Wbitwise dislikes. Signed-off-by: Alan Stern Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/dummy_hcd.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'drivers/usb/gadget/dummy_hcd.c') diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index f9540adf2a4..c78c64ae87a 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c @@ -734,7 +734,7 @@ show_function (struct device *dev, struct device_attribute *attr, char *buf) return 0; return scnprintf (buf, PAGE_SIZE, "%s\n", dum->driver->function); } -DEVICE_ATTR (function, S_IRUGO, show_function, NULL); +static DEVICE_ATTR (function, S_IRUGO, show_function, NULL); /*-------------------------------------------------------------------------*/ @@ -857,6 +857,9 @@ EXPORT_SYMBOL (usb_gadget_unregister_driver); #undef is_enabled +/* just declare this in any driver that really need it */ +extern int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode); + int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode) { return -ENOSYS; @@ -1122,7 +1125,6 @@ static int periodic_bytes (struct dummy *dum, struct dummy_ep *ep) /* high bandwidth mode */ tmp = le16_to_cpu(ep->desc->wMaxPacketSize); - tmp = le16_to_cpu (tmp); tmp = (tmp >> 11) & 0x03; tmp *= 8 /* applies to entire frame */; limit += limit * tmp; @@ -1265,9 +1267,14 @@ restart: struct usb_ctrlrequest setup; int value = 1; struct dummy_ep *ep2; + unsigned w_index; + unsigned w_value; setup = *(struct usb_ctrlrequest*) urb->setup_packet; - if (setup.wLength != urb->transfer_buffer_length) { + w_index = le16_to_cpu(setup.wIndex); + w_value = le16_to_cpu(setup.wValue); + if (le16_to_cpu(setup.wLength) != + urb->transfer_buffer_length) { maybe_set_status (urb, -EOVERFLOW); goto return_urb; } @@ -1297,16 +1304,16 @@ restart: case USB_REQ_SET_ADDRESS: if (setup.bRequestType != Dev_Request) break; - dum->address = setup.wValue; + dum->address = w_value; maybe_set_status (urb, 0); dev_dbg (udc_dev(dum), "set_address = %d\n", - setup.wValue); + w_value); value = 0; break; case USB_REQ_SET_FEATURE: if (setup.bRequestType == Dev_Request) { value = 0; - switch (setup.wValue) { + switch (w_value) { case USB_DEVICE_REMOTE_WAKEUP: break; case USB_DEVICE_B_HNP_ENABLE: @@ -1324,14 +1331,13 @@ restart: } if (value == 0) { dum->devstatus |= - (1 << setup.wValue); + (1 << w_value); maybe_set_status (urb, 0); } } else if (setup.bRequestType == Ep_Request) { // endpoint halt - ep2 = find_endpoint (dum, - setup.wIndex); + ep2 = find_endpoint (dum, w_index); if (!ep2) { value = -EOPNOTSUPP; break; @@ -1343,7 +1349,7 @@ restart: break; case USB_REQ_CLEAR_FEATURE: if (setup.bRequestType == Dev_Request) { - switch (setup.wValue) { + switch (w_value) { case USB_DEVICE_REMOTE_WAKEUP: dum->devstatus &= ~(1 << USB_DEVICE_REMOTE_WAKEUP); @@ -1356,8 +1362,7 @@ restart: } } else if (setup.bRequestType == Ep_Request) { // endpoint halt - ep2 = find_endpoint (dum, - setup.wIndex); + ep2 = find_endpoint (dum, w_index); if (!ep2) { value = -EOPNOTSUPP; break; @@ -1383,7 +1388,7 @@ restart: if (urb->transfer_buffer_length > 0) { if (setup.bRequestType == Ep_InRequest) { - ep2 = find_endpoint (dum, setup.wIndex); + ep2 = find_endpoint (dum, w_index); if (!ep2) { value = -EOPNOTSUPP; break; @@ -1535,7 +1540,8 @@ hub_descriptor (struct usb_hub_descriptor *desc) memset (desc, 0, sizeof *desc); desc->bDescriptorType = 0x29; desc->bDescLength = 9; - desc->wHubCharacteristics = __constant_cpu_to_le16 (0x0001); + desc->wHubCharacteristics = (__force __u16) + (__constant_cpu_to_le16 (0x0001)); desc->bNbrPorts = 1; desc->bitmap [0] = 0xff; desc->bitmap [1] = 0xff; @@ -1581,7 +1587,7 @@ static int dummy_hub_control ( hub_descriptor ((struct usb_hub_descriptor *) buf); break; case GetHubStatus: - *(u32 *) buf = __constant_cpu_to_le32 (0); + *(__le32 *) buf = __constant_cpu_to_le32 (0); break; case GetPortStatus: if (wIndex != 1) @@ -1621,8 +1627,8 @@ static int dummy_hub_control ( } } set_link_state (dum); - ((u16 *) buf)[0] = cpu_to_le16 (dum->port_status); - ((u16 *) buf)[1] = cpu_to_le16 (dum->port_status >> 16); + ((__le16 *) buf)[0] = cpu_to_le16 (dum->port_status); + ((__le16 *) buf)[1] = cpu_to_le16 (dum->port_status >> 16); break; case SetHubFeature: retval = -EPIPE; -- cgit v1.2.3 From 391eca9d8892a940ff8dbfee2ca78942e05c2d37 Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Tue, 10 May 2005 15:34:16 -0400 Subject: [PATCH] USB: dummy_hcd: add suspend/resume support This patch adds support to dummy_hcd for suspending and resuming the root hub and the emulated platform devices. Signed-off-by: Alan Stern Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/dummy_hcd.c | 179 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 162 insertions(+), 17 deletions(-) (limited to 'drivers/usb/gadget/dummy_hcd.c') diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index c78c64ae87a..4d692670f28 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c @@ -65,7 +65,7 @@ #define DRIVER_DESC "USB Host+Gadget Emulator" -#define DRIVER_VERSION "17 Dec 2004" +#define DRIVER_VERSION "02 May 2005" static const char driver_name [] = "dummy_hcd"; static const char driver_desc [] = "USB Host+Gadget Emulator"; @@ -150,6 +150,13 @@ struct urbp { struct list_head urbp_list; }; + +enum dummy_rh_state { + DUMMY_RH_RESET, + DUMMY_RH_SUSPENDED, + DUMMY_RH_RUNNING +}; + struct dummy { spinlock_t lock; @@ -163,6 +170,7 @@ struct dummy { struct dummy_request fifo_req; u8 fifo_buf [FIFO_SIZE]; u16 devstatus; + unsigned udc_suspended:1; unsigned pullup:1; unsigned active:1; unsigned old_active:1; @@ -170,6 +178,7 @@ struct dummy { /* * MASTER/HOST side support */ + enum dummy_rh_state rh_state; struct timer_list timer; u32 port_status; u32 old_status; @@ -262,7 +271,9 @@ set_link_state (struct dummy *dum) dum->active = 0; if ((dum->port_status & USB_PORT_STAT_POWER) == 0) dum->port_status = 0; - else if (!dum->pullup) { + + /* UDC suspend must cause a disconnect */ + else if (!dum->pullup || dum->udc_suspended) { dum->port_status &= ~(USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE | USB_PORT_STAT_LOW_SPEED | @@ -276,7 +287,8 @@ set_link_state (struct dummy *dum) dum->port_status |= (USB_PORT_STAT_C_CONNECTION << 16); if ((dum->port_status & USB_PORT_STAT_ENABLE) == 0) dum->port_status &= ~USB_PORT_STAT_SUSPEND; - else if ((dum->port_status & USB_PORT_STAT_SUSPEND) == 0) + else if ((dum->port_status & USB_PORT_STAT_SUSPEND) == 0 && + dum->rh_state != DUMMY_RH_SUSPENDED) dum->active = 1; } @@ -675,11 +687,16 @@ static int dummy_wakeup (struct usb_gadget *_gadget) struct dummy *dum; dum = gadget_to_dummy (_gadget); - if (!(dum->port_status & USB_PORT_STAT_SUSPEND) - || !(dum->devstatus & - ( (1 << USB_DEVICE_B_HNP_ENABLE) + if (!(dum->devstatus & ( (1 << USB_DEVICE_B_HNP_ENABLE) | (1 << USB_DEVICE_REMOTE_WAKEUP)))) return -EINVAL; + if ((dum->port_status & USB_PORT_STAT_CONNECTION) == 0) + return -ENOLINK; + if ((dum->port_status & USB_PORT_STAT_SUSPEND) == 0 && + dum->rh_state != DUMMY_RH_SUSPENDED) + return -EIO; + + /* FIXME: What if the root hub is suspended but the port isn't? */ /* hub notices our request, issues downstream resume, etc */ dum->resuming = 1; @@ -917,11 +934,50 @@ static int dummy_udc_remove (struct device *dev) return 0; } +static int dummy_udc_suspend (struct device *dev, pm_message_t state, + u32 level) +{ + struct dummy *dum = dev_get_drvdata(dev); + + if (level != SUSPEND_DISABLE) + return 0; + + dev_dbg (dev, "%s\n", __FUNCTION__); + spin_lock_irq (&dum->lock); + dum->udc_suspended = 1; + set_link_state (dum); + spin_unlock_irq (&dum->lock); + + dev->power.power_state = state; + usb_hcd_poll_rh_status (dummy_to_hcd (dum)); + return 0; +} + +static int dummy_udc_resume (struct device *dev, u32 level) +{ + struct dummy *dum = dev_get_drvdata(dev); + + if (level != RESUME_ENABLE) + return 0; + + dev_dbg (dev, "%s\n", __FUNCTION__); + spin_lock_irq (&dum->lock); + dum->udc_suspended = 0; + set_link_state (dum); + spin_unlock_irq (&dum->lock); + + dev->power.power_state = PMSG_ON; + usb_hcd_poll_rh_status (dummy_to_hcd (dum)); + return 0; +} + static struct device_driver dummy_udc_driver = { .name = (char *) gadget_name, .bus = &platform_bus_type, .probe = dummy_udc_probe, .remove = dummy_udc_remove, + .suspend = dummy_udc_suspend, + .resume = dummy_udc_resume, }; /*-------------------------------------------------------------------------*/ @@ -980,7 +1036,16 @@ static int dummy_urb_enqueue ( static int dummy_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) { - /* giveback happens automatically in timer callback */ + struct dummy *dum; + unsigned long flags; + + /* giveback happens automatically in timer callback, + * so make sure the callback happens */ + dum = hcd_to_dummy (hcd); + spin_lock_irqsave (&dum->lock, flags); + if (dum->rh_state != DUMMY_RH_RUNNING && !list_empty(&dum->urbp_list)) + mod_timer (&dum->timer, jiffies); + spin_unlock_irqrestore (&dum->lock, flags); return 0; } @@ -1222,7 +1287,8 @@ restart: if (urb->status != -EINPROGRESS) { /* likely it was just unlinked */ goto return_urb; - } + } else if (dum->rh_state != DUMMY_RH_RUNNING) + continue; type = usb_pipetype (urb->pipe); /* used up this frame's non-periodic bandwidth? @@ -1486,12 +1552,12 @@ return_urb: goto restart; } - /* want a 1 msec delay here */ - if (!list_empty (&dum->urbp_list)) - mod_timer (&dum->timer, jiffies + msecs_to_jiffies(1)); - else { + if (list_empty (&dum->urbp_list)) { usb_put_dev (dum->udev); dum->udev = NULL; + } else if (dum->rh_state == DUMMY_RH_RUNNING) { + /* want a 1 msec delay here */ + mod_timer (&dum->timer, jiffies + msecs_to_jiffies(1)); } spin_unlock_irqrestore (&dum->lock, flags); @@ -1510,11 +1576,13 @@ static int dummy_hub_status (struct usb_hcd *hcd, char *buf) { struct dummy *dum; unsigned long flags; - int retval; + int retval = 0; dum = hcd_to_dummy (hcd); spin_lock_irqsave (&dum->lock, flags); + if (hcd->state != HC_STATE_RUNNING) + goto done; if (dum->resuming && time_after_eq (jiffies, dum->re_timeout)) { dum->port_status |= (USB_PORT_STAT_C_SUSPEND << 16); @@ -1522,14 +1590,15 @@ static int dummy_hub_status (struct usb_hcd *hcd, char *buf) set_link_state (dum); } - if (!(dum->port_status & PORT_C_MASK)) - retval = 0; - else { + if ((dum->port_status & PORT_C_MASK) != 0) { *buf = (1 << 1); dev_dbg (dummy_dev(dum), "port status 0x%08x has changes\n", - dum->port_status); + dum->port_status); retval = 1; + if (dum->rh_state == DUMMY_RH_SUSPENDED) + usb_hcd_resume_root_hub (hcd); } +done: spin_unlock_irqrestore (&dum->lock, flags); return retval; } @@ -1559,6 +1628,9 @@ static int dummy_hub_control ( int retval = 0; unsigned long flags; + if (hcd->state != HC_STATE_RUNNING) + return -ETIMEDOUT; + dum = hcd_to_dummy (hcd); spin_lock_irqsave (&dum->lock, flags); switch (typeReq) { @@ -1658,6 +1730,7 @@ static int dummy_hub_control ( dum->port_status &= ~(USB_PORT_STAT_ENABLE | USB_PORT_STAT_LOW_SPEED | USB_PORT_STAT_HIGH_SPEED); + dum->devstatus = 0; /* 50msec reset signaling */ dum->re_timeout = jiffies + msecs_to_jiffies(50); /* FALLS THROUGH */ @@ -1684,6 +1757,29 @@ static int dummy_hub_control ( return retval; } +static int dummy_hub_suspend (struct usb_hcd *hcd) +{ + struct dummy *dum = hcd_to_dummy (hcd); + + spin_lock_irq (&dum->lock); + dum->rh_state = DUMMY_RH_SUSPENDED; + set_link_state (dum); + spin_unlock_irq (&dum->lock); + return 0; +} + +static int dummy_hub_resume (struct usb_hcd *hcd) +{ + struct dummy *dum = hcd_to_dummy (hcd); + + spin_lock_irq (&dum->lock); + dum->rh_state = DUMMY_RH_RUNNING; + set_link_state (dum); + if (!list_empty(&dum->urbp_list)) + mod_timer (&dum->timer, jiffies); + spin_unlock_irq (&dum->lock); + return 0; +} /*-------------------------------------------------------------------------*/ @@ -1751,6 +1847,7 @@ static int dummy_start (struct usb_hcd *hcd) init_timer (&dum->timer); dum->timer.function = dummy_timer; dum->timer.data = (unsigned long) dum; + dum->rh_state = DUMMY_RH_RUNNING; INIT_LIST_HEAD (&dum->urbp_list); @@ -1803,6 +1900,8 @@ static const struct hc_driver dummy_hcd = { .hub_status_data = dummy_hub_status, .hub_control = dummy_hub_control, + .hub_suspend = dummy_hub_suspend, + .hub_resume = dummy_hub_resume, }; static int dummy_hcd_probe (struct device *dev) @@ -1836,11 +1935,57 @@ static int dummy_hcd_remove (struct device *dev) return 0; } +static int dummy_hcd_suspend (struct device *dev, pm_message_t state, + u32 level) +{ + struct usb_hcd *hcd; + + if (level != SUSPEND_DISABLE) + return 0; + + dev_dbg (dev, "%s\n", __FUNCTION__); + hcd = dev_get_drvdata (dev); + +#ifndef CONFIG_USB_SUSPEND + /* Otherwise this would never happen */ + usb_lock_device (hcd->self.root_hub); + dummy_hub_suspend (hcd); + usb_unlock_device (hcd->self.root_hub); +#endif + + hcd->state = HC_STATE_SUSPENDED; + return 0; +} + +static int dummy_hcd_resume (struct device *dev, u32 level) +{ + struct usb_hcd *hcd; + + if (level != RESUME_ENABLE) + return 0; + + dev_dbg (dev, "%s\n", __FUNCTION__); + hcd = dev_get_drvdata (dev); + hcd->state = HC_STATE_RUNNING; + +#ifndef CONFIG_USB_SUSPEND + /* Otherwise this would never happen */ + usb_lock_device (hcd->self.root_hub); + dummy_hub_resume (hcd); + usb_unlock_device (hcd->self.root_hub); +#endif + + usb_hcd_poll_rh_status (hcd); + return 0; +} + static struct device_driver dummy_hcd_driver = { .name = (char *) driver_name, .bus = &platform_bus_type, .probe = dummy_hcd_probe, .remove = dummy_hcd_remove, + .suspend = dummy_hcd_suspend, + .resume = dummy_hcd_resume, }; /*-------------------------------------------------------------------------*/ -- cgit v1.2.3