1 // SPDX-License-Identifier: GPL-2.0+
3 * aspeed-vhub -- Driver for Aspeed SoC "vHub" USB gadget
5 * hub.c - virtual hub handling
7 * Copyright 2017 IBM Corporation
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/platform_device.h>
18 #include <linux/delay.h>
19 #include <linux/ioport.h>
20 #include <linux/slab.h>
21 #include <linux/errno.h>
22 #include <linux/list.h>
23 #include <linux/interrupt.h>
24 #include <linux/proc_fs.h>
25 #include <linux/prefetch.h>
26 #include <linux/clk.h>
27 #include <linux/usb/gadget.h>
29 #include <linux/of_gpio.h>
30 #include <linux/regmap.h>
31 #include <linux/dma-mapping.h>
32 #include <linux/bcd.h>
33 #include <linux/version.h>
34 #include <linux/usb.h>
35 #include <linux/usb/hcd.h>
39 /* usb 2.0 hub device descriptor
41 * A few things we may want to improve here:
43 * - We may need to indicate TT support
44 * - We may need a device qualifier descriptor
45 * as devices can pretend to be usb1 or 2
46 * - Make vid/did overridable
47 * - make it look like usb1 if usb1 mode forced
49 #define KERNEL_REL bin2bcd(((LINUX_VERSION_CODE >> 16) & 0x0ff))
50 #define KERNEL_VER bin2bcd(((LINUX_VERSION_CODE >> 8) & 0x0ff))
53 AST_VHUB_STR_MANUF = 3,
54 AST_VHUB_STR_PRODUCT = 2,
55 AST_VHUB_STR_SERIAL = 1,
58 static const struct usb_device_descriptor ast_vhub_dev_desc = {
59 .bLength = USB_DT_DEVICE_SIZE,
60 .bDescriptorType = USB_DT_DEVICE,
61 .bcdUSB = cpu_to_le16(0x0200),
62 .bDeviceClass = USB_CLASS_HUB,
65 .bMaxPacketSize0 = 64,
66 .idVendor = cpu_to_le16(0x1d6b),
67 .idProduct = cpu_to_le16(0x0107),
68 .bcdDevice = cpu_to_le16(0x0100),
69 .iManufacturer = AST_VHUB_STR_MANUF,
70 .iProduct = AST_VHUB_STR_PRODUCT,
71 .iSerialNumber = AST_VHUB_STR_SERIAL,
72 .bNumConfigurations = 1,
75 /* Patches to the above when forcing USB1 mode */
76 static void ast_vhub_patch_dev_desc_usb1(struct usb_device_descriptor *desc)
78 desc->bcdUSB = cpu_to_le16(0x0100);
79 desc->bDeviceProtocol = 0;
83 * Configuration descriptor: same comments as above
84 * regarding handling USB1 mode.
88 * We don't use sizeof() as Linux definition of
89 * struct usb_endpoint_descriptor contains 2
92 #define AST_VHUB_CONF_DESC_SIZE (USB_DT_CONFIG_SIZE + \
93 USB_DT_INTERFACE_SIZE + \
96 static const struct ast_vhub_full_cdesc {
97 struct usb_config_descriptor cfg;
98 struct usb_interface_descriptor intf;
99 struct usb_endpoint_descriptor ep;
100 } __attribute__ ((packed)) ast_vhub_conf_desc = {
102 .bLength = USB_DT_CONFIG_SIZE,
103 .bDescriptorType = USB_DT_CONFIG,
104 .wTotalLength = cpu_to_le16(AST_VHUB_CONF_DESC_SIZE),
106 .bConfigurationValue = 1,
108 .bmAttributes = USB_CONFIG_ATT_ONE |
109 USB_CONFIG_ATT_SELFPOWER |
110 USB_CONFIG_ATT_WAKEUP,
114 .bLength = USB_DT_INTERFACE_SIZE,
115 .bDescriptorType = USB_DT_INTERFACE,
116 .bInterfaceNumber = 0,
117 .bAlternateSetting = 0,
119 .bInterfaceClass = USB_CLASS_HUB,
120 .bInterfaceSubClass = 0,
121 .bInterfaceProtocol = 0,
125 .bLength = USB_DT_ENDPOINT_SIZE,
126 .bDescriptorType = USB_DT_ENDPOINT,
127 .bEndpointAddress = 0x81,
128 .bmAttributes = USB_ENDPOINT_XFER_INT,
129 .wMaxPacketSize = cpu_to_le16(1),
134 #define AST_VHUB_HUB_DESC_SIZE (USB_DT_HUB_NONVAR_SIZE + 2)
136 static const struct usb_hub_descriptor ast_vhub_hub_desc = {
137 .bDescLength = AST_VHUB_HUB_DESC_SIZE,
138 .bDescriptorType = USB_DT_HUB,
139 .bNbrPorts = AST_VHUB_NUM_PORTS,
140 .wHubCharacteristics = cpu_to_le16(HUB_CHAR_NO_LPSM),
141 .bPwrOn2PwrGood = 10,
142 .bHubContrCurrent = 0,
143 .u.hs.DeviceRemovable[0] = 0,
144 .u.hs.DeviceRemovable[1] = 0xff,
148 * These strings converted to UTF-16 must be smaller than
151 static const struct usb_string ast_vhub_str_array[] = {
153 .id = AST_VHUB_STR_SERIAL,
157 .id = AST_VHUB_STR_PRODUCT,
158 .s = "USB Virtual Hub"
161 .id = AST_VHUB_STR_MANUF,
167 static const struct usb_gadget_strings ast_vhub_strings = {
169 .strings = (struct usb_string *)ast_vhub_str_array
172 static int ast_vhub_hub_dev_status(struct ast_vhub_ep *ep,
173 u16 wIndex, u16 wValue)
177 EPDBG(ep, "GET_STATUS(dev)\n");
180 * Mark it as self-powered, I doubt the BMC is powered off
183 st0 = 1 << USB_DEVICE_SELF_POWERED;
186 * Need to double check how remote wakeup actually works
187 * on that chip and what triggers it.
189 if (ep->vhub->wakeup_en)
190 st0 |= 1 << USB_DEVICE_REMOTE_WAKEUP;
192 return ast_vhub_simple_reply(ep, st0, 0);
195 static int ast_vhub_hub_ep_status(struct ast_vhub_ep *ep,
196 u16 wIndex, u16 wValue)
201 ep_num = wIndex & USB_ENDPOINT_NUMBER_MASK;
202 EPDBG(ep, "GET_STATUS(ep%d)\n", ep_num);
204 /* On the hub we have only EP 0 and 1 */
206 if (ep->vhub->ep1_stalled)
207 st0 |= 1 << USB_ENDPOINT_HALT;
208 } else if (ep_num != 0)
209 return std_req_stall;
211 return ast_vhub_simple_reply(ep, st0, 0);
214 static int ast_vhub_hub_dev_feature(struct ast_vhub_ep *ep,
215 u16 wIndex, u16 wValue,
218 EPDBG(ep, "%s_FEATURE(dev val=%02x)\n",
219 is_set ? "SET" : "CLEAR", wValue);
221 if (wValue != USB_DEVICE_REMOTE_WAKEUP)
222 return std_req_stall;
224 ep->vhub->wakeup_en = is_set;
225 EPDBG(ep, "Hub remote wakeup %s\n",
226 is_set ? "enabled" : "disabled");
228 return std_req_complete;
231 static int ast_vhub_hub_ep_feature(struct ast_vhub_ep *ep,
232 u16 wIndex, u16 wValue,
238 ep_num = wIndex & USB_ENDPOINT_NUMBER_MASK;
239 EPDBG(ep, "%s_FEATURE(ep%d val=%02x)\n",
240 is_set ? "SET" : "CLEAR", ep_num, wValue);
243 return std_req_stall;
244 if (wValue != USB_ENDPOINT_HALT)
245 return std_req_stall;
247 return std_req_complete;
249 EPDBG(ep, "%s stall on EP 1\n",
250 is_set ? "setting" : "clearing");
252 ep->vhub->ep1_stalled = is_set;
253 reg = readl(ep->vhub->regs + AST_VHUB_EP1_CTRL);
255 reg |= VHUB_EP1_CTRL_STALL;
257 reg &= ~VHUB_EP1_CTRL_STALL;
258 reg |= VHUB_EP1_CTRL_RESET_TOGGLE;
260 writel(reg, ep->vhub->regs + AST_VHUB_EP1_CTRL);
262 return std_req_complete;
265 static int ast_vhub_rep_desc(struct ast_vhub_ep *ep,
266 u8 desc_type, u16 len)
270 EPDBG(ep, "GET_DESCRIPTOR(type:%d)\n", desc_type);
273 * Copy first to EP buffer and send from there, so
274 * we can do some in-place patching if needed. We know
275 * the EP buffer is big enough but ensure that doesn't
276 * change. We do that now rather than later after we
277 * have checked sizes etc... to avoid a gcc bug where
278 * it thinks len is constant and barfs about read
279 * overflows in memcpy.
283 dsize = USB_DT_DEVICE_SIZE;
284 memcpy(ep->buf, &ast_vhub_dev_desc, dsize);
285 BUILD_BUG_ON(dsize > sizeof(ast_vhub_dev_desc));
286 BUILD_BUG_ON(USB_DT_DEVICE_SIZE >= AST_VHUB_EP0_MAX_PACKET);
289 dsize = AST_VHUB_CONF_DESC_SIZE;
290 memcpy(ep->buf, &ast_vhub_conf_desc, dsize);
291 BUILD_BUG_ON(dsize > sizeof(ast_vhub_conf_desc));
292 BUILD_BUG_ON(AST_VHUB_CONF_DESC_SIZE >= AST_VHUB_EP0_MAX_PACKET);
295 dsize = AST_VHUB_HUB_DESC_SIZE;
296 memcpy(ep->buf, &ast_vhub_hub_desc, dsize);
297 BUILD_BUG_ON(dsize > sizeof(ast_vhub_hub_desc));
298 BUILD_BUG_ON(AST_VHUB_HUB_DESC_SIZE >= AST_VHUB_EP0_MAX_PACKET);
301 return std_req_stall;
304 /* Crop requested length */
308 /* Patch it if forcing USB1 */
309 if (desc_type == USB_DT_DEVICE && ep->vhub->force_usb1)
310 ast_vhub_patch_dev_desc_usb1(ep->buf);
312 /* Shoot it from the EP buffer */
313 return ast_vhub_reply(ep, NULL, len);
316 static int ast_vhub_rep_string(struct ast_vhub_ep *ep,
317 u8 string_id, u16 lang_id,
320 int rc = usb_gadget_get_string (&ast_vhub_strings, string_id, ep->buf);
323 * This should never happen unless we put too big strings in
326 BUG_ON(rc >= AST_VHUB_EP0_MAX_PACKET);
329 return std_req_stall;
331 /* Shoot it from the EP buffer */
332 return ast_vhub_reply(ep, NULL, min_t(u16, rc, len));
335 enum std_req_rc ast_vhub_std_hub_request(struct ast_vhub_ep *ep,
336 struct usb_ctrlrequest *crq)
338 struct ast_vhub *vhub = ep->vhub;
339 u16 wValue, wIndex, wLength;
341 wValue = le16_to_cpu(crq->wValue);
342 wIndex = le16_to_cpu(crq->wIndex);
343 wLength = le16_to_cpu(crq->wLength);
345 /* First packet, grab speed */
346 if (vhub->speed == USB_SPEED_UNKNOWN) {
347 u32 ustat = readl(vhub->regs + AST_VHUB_USBSTS);
348 if (ustat & VHUB_USBSTS_HISPEED)
349 vhub->speed = USB_SPEED_HIGH;
351 vhub->speed = USB_SPEED_FULL;
352 UDCDBG(vhub, "USB status=%08x speed=%s\n", ustat,
353 vhub->speed == USB_SPEED_HIGH ? "high" : "full");
356 switch ((crq->bRequestType << 8) | crq->bRequest) {
358 case DeviceOutRequest | USB_REQ_SET_ADDRESS:
359 EPDBG(ep, "SET_ADDRESS: Got address %x\n", wValue);
360 writel(wValue, vhub->regs + AST_VHUB_CONF);
361 return std_req_complete;
364 case DeviceRequest | USB_REQ_GET_STATUS:
365 return ast_vhub_hub_dev_status(ep, wIndex, wValue);
366 case InterfaceRequest | USB_REQ_GET_STATUS:
367 return ast_vhub_simple_reply(ep, 0, 0);
368 case EndpointRequest | USB_REQ_GET_STATUS:
369 return ast_vhub_hub_ep_status(ep, wIndex, wValue);
371 /* SET/CLEAR_FEATURE */
372 case DeviceOutRequest | USB_REQ_SET_FEATURE:
373 return ast_vhub_hub_dev_feature(ep, wIndex, wValue, true);
374 case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
375 return ast_vhub_hub_dev_feature(ep, wIndex, wValue, false);
376 case EndpointOutRequest | USB_REQ_SET_FEATURE:
377 return ast_vhub_hub_ep_feature(ep, wIndex, wValue, true);
378 case EndpointOutRequest | USB_REQ_CLEAR_FEATURE:
379 return ast_vhub_hub_ep_feature(ep, wIndex, wValue, false);
381 /* GET/SET_CONFIGURATION */
382 case DeviceRequest | USB_REQ_GET_CONFIGURATION:
383 return ast_vhub_simple_reply(ep, 1);
384 case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
386 return std_req_stall;
387 return std_req_complete;
390 case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
391 switch (wValue >> 8) {
394 return ast_vhub_rep_desc(ep, wValue >> 8,
397 return ast_vhub_rep_string(ep, wValue & 0xff,
400 return std_req_stall;
402 /* GET/SET_INTERFACE */
403 case DeviceRequest | USB_REQ_GET_INTERFACE:
404 return ast_vhub_simple_reply(ep, 0);
405 case DeviceOutRequest | USB_REQ_SET_INTERFACE:
406 if (wValue != 0 || wIndex != 0)
407 return std_req_stall;
408 return std_req_complete;
410 return std_req_stall;
413 static void ast_vhub_update_hub_ep1(struct ast_vhub *vhub,
416 /* Update HW EP1 response */
417 u32 reg = readl(vhub->regs + AST_VHUB_EP1_STS_CHG);
418 u32 pmask = (1 << (port + 1));
419 if (vhub->ports[port].change)
423 writel(reg, vhub->regs + AST_VHUB_EP1_STS_CHG);
426 static void ast_vhub_change_port_stat(struct ast_vhub *vhub,
432 struct ast_vhub_port *p = &vhub->ports[port];
435 /* Update port status */
437 p->status = (prev & ~clr_flags) | set_flags;
438 DDBG(&p->dev, "port %d status %04x -> %04x (C=%d)\n",
439 port + 1, prev, p->status, set_c);
441 /* Update change bits if needed */
443 u16 chg = p->status ^ prev;
445 /* Only these are relevant for change */
446 chg &= USB_PORT_STAT_C_CONNECTION |
447 USB_PORT_STAT_C_ENABLE |
448 USB_PORT_STAT_C_SUSPEND |
449 USB_PORT_STAT_C_OVERCURRENT |
450 USB_PORT_STAT_C_RESET |
454 ast_vhub_update_hub_ep1(vhub, port);
458 static void ast_vhub_send_host_wakeup(struct ast_vhub *vhub)
460 u32 reg = readl(vhub->regs + AST_VHUB_CTRL);
461 UDCDBG(vhub, "Waking up host !\n");
462 reg |= VHUB_CTRL_MANUAL_REMOTE_WAKEUP;
463 writel(reg, vhub->regs + AST_VHUB_CTRL);
466 void ast_vhub_device_connect(struct ast_vhub *vhub,
467 unsigned int port, bool on)
470 ast_vhub_change_port_stat(vhub, port, 0,
471 USB_PORT_STAT_CONNECTION, true);
473 ast_vhub_change_port_stat(vhub, port,
474 USB_PORT_STAT_CONNECTION |
475 USB_PORT_STAT_ENABLE,
479 * If the hub is set to wakup the host on connection events
480 * then send a wakeup.
483 ast_vhub_send_host_wakeup(vhub);
486 static void ast_vhub_wake_work(struct work_struct *work)
488 struct ast_vhub *vhub = container_of(work,
495 * Wake all sleeping ports. If a port is suspended by
496 * the host suspend (without explicit state suspend),
497 * we let the normal host wake path deal with it later.
499 spin_lock_irqsave(&vhub->lock, flags);
500 for (i = 0; i < AST_VHUB_NUM_PORTS; i++) {
501 struct ast_vhub_port *p = &vhub->ports[i];
503 if (!(p->status & USB_PORT_STAT_SUSPEND))
505 ast_vhub_change_port_stat(vhub, i,
506 USB_PORT_STAT_SUSPEND,
508 ast_vhub_dev_resume(&p->dev);
510 ast_vhub_send_host_wakeup(vhub);
511 spin_unlock_irqrestore(&vhub->lock, flags);
514 void ast_vhub_hub_wake_all(struct ast_vhub *vhub)
517 * A device is trying to wake the world, because this
518 * can recurse into the device, we break the call chain
521 schedule_work(&vhub->wake_work);
524 static void ast_vhub_port_reset(struct ast_vhub *vhub, u8 port)
526 struct ast_vhub_port *p = &vhub->ports[port];
529 /* First mark disabled */
530 ast_vhub_change_port_stat(vhub, port,
531 USB_PORT_STAT_ENABLE |
532 USB_PORT_STAT_SUSPEND,
540 * This will either "start" the port or reset the
541 * device if already started...
543 ast_vhub_dev_reset(&p->dev);
545 /* Grab the right speed */
546 speed = p->dev.driver->max_speed;
547 if (speed == USB_SPEED_UNKNOWN || speed > vhub->speed)
552 set = USB_PORT_STAT_LOW_SPEED;
553 clr = USB_PORT_STAT_HIGH_SPEED;
557 clr = USB_PORT_STAT_LOW_SPEED |
558 USB_PORT_STAT_HIGH_SPEED;
561 set = USB_PORT_STAT_HIGH_SPEED;
562 clr = USB_PORT_STAT_LOW_SPEED;
565 UDCDBG(vhub, "Unsupported speed %d when"
566 " connecting device\n",
570 clr |= USB_PORT_STAT_RESET;
571 set |= USB_PORT_STAT_ENABLE;
573 /* This should ideally be delayed ... */
574 ast_vhub_change_port_stat(vhub, port, clr, set, true);
577 static enum std_req_rc ast_vhub_set_port_feature(struct ast_vhub_ep *ep,
580 struct ast_vhub *vhub = ep->vhub;
581 struct ast_vhub_port *p;
583 if (port == 0 || port > AST_VHUB_NUM_PORTS)
584 return std_req_stall;
586 p = &vhub->ports[port];
589 case USB_PORT_FEAT_SUSPEND:
590 if (!(p->status & USB_PORT_STAT_ENABLE))
591 return std_req_complete;
592 ast_vhub_change_port_stat(vhub, port,
593 0, USB_PORT_STAT_SUSPEND,
595 ast_vhub_dev_suspend(&p->dev);
596 return std_req_complete;
597 case USB_PORT_FEAT_RESET:
598 EPDBG(ep, "Port reset !\n");
599 ast_vhub_port_reset(vhub, port);
600 return std_req_complete;
601 case USB_PORT_FEAT_POWER:
603 * On Power-on, we mark the connected flag changed,
604 * if there's a connected device, some hosts will
605 * otherwise fail to detect it.
607 if (p->status & USB_PORT_STAT_CONNECTION) {
608 p->change |= USB_PORT_STAT_C_CONNECTION;
609 ast_vhub_update_hub_ep1(vhub, port);
611 return std_req_complete;
612 case USB_PORT_FEAT_TEST:
613 case USB_PORT_FEAT_INDICATOR:
614 /* We don't do anything with these */
615 return std_req_complete;
617 return std_req_stall;
620 static enum std_req_rc ast_vhub_clr_port_feature(struct ast_vhub_ep *ep,
623 struct ast_vhub *vhub = ep->vhub;
624 struct ast_vhub_port *p;
626 if (port == 0 || port > AST_VHUB_NUM_PORTS)
627 return std_req_stall;
629 p = &vhub->ports[port];
632 case USB_PORT_FEAT_ENABLE:
633 ast_vhub_change_port_stat(vhub, port,
634 USB_PORT_STAT_ENABLE |
635 USB_PORT_STAT_SUSPEND, 0,
637 ast_vhub_dev_suspend(&p->dev);
638 return std_req_complete;
639 case USB_PORT_FEAT_SUSPEND:
640 if (!(p->status & USB_PORT_STAT_SUSPEND))
641 return std_req_complete;
642 ast_vhub_change_port_stat(vhub, port,
643 USB_PORT_STAT_SUSPEND, 0,
645 ast_vhub_dev_resume(&p->dev);
646 return std_req_complete;
647 case USB_PORT_FEAT_POWER:
648 /* We don't do power control */
649 return std_req_complete;
650 case USB_PORT_FEAT_INDICATOR:
651 /* We don't have indicators */
652 return std_req_complete;
653 case USB_PORT_FEAT_C_CONNECTION:
654 case USB_PORT_FEAT_C_ENABLE:
655 case USB_PORT_FEAT_C_SUSPEND:
656 case USB_PORT_FEAT_C_OVER_CURRENT:
657 case USB_PORT_FEAT_C_RESET:
658 /* Clear state-change feature */
659 p->change &= ~(1u << (feat - 16));
660 ast_vhub_update_hub_ep1(vhub, port);
661 return std_req_complete;
663 return std_req_stall;
666 static enum std_req_rc ast_vhub_get_port_stat(struct ast_vhub_ep *ep,
669 struct ast_vhub *vhub = ep->vhub;
672 if (port == 0 || port > AST_VHUB_NUM_PORTS)
673 return std_req_stall;
676 stat = vhub->ports[port].status;
677 chg = vhub->ports[port].change;
679 /* We always have power */
680 stat |= USB_PORT_STAT_POWER;
682 EPDBG(ep, " port status=%04x change=%04x\n", stat, chg);
684 return ast_vhub_simple_reply(ep,
691 enum std_req_rc ast_vhub_class_hub_request(struct ast_vhub_ep *ep,
692 struct usb_ctrlrequest *crq)
694 u16 wValue, wIndex, wLength;
696 wValue = le16_to_cpu(crq->wValue);
697 wIndex = le16_to_cpu(crq->wIndex);
698 wLength = le16_to_cpu(crq->wLength);
700 switch ((crq->bRequestType << 8) | crq->bRequest) {
702 EPDBG(ep, "GetHubStatus\n");
703 return ast_vhub_simple_reply(ep, 0, 0, 0, 0);
705 EPDBG(ep, "GetPortStatus(%d)\n", wIndex & 0xff);
706 return ast_vhub_get_port_stat(ep, wIndex & 0xf);
707 case GetHubDescriptor:
708 if (wValue != (USB_DT_HUB << 8))
709 return std_req_stall;
710 EPDBG(ep, "GetHubDescriptor(%d)\n", wIndex & 0xff);
711 return ast_vhub_rep_desc(ep, USB_DT_HUB, wLength);
713 case ClearHubFeature:
714 EPDBG(ep, "Get/SetHubFeature(%d)\n", wValue);
715 /* No feature, just complete the requests */
716 if (wValue == C_HUB_LOCAL_POWER ||
717 wValue == C_HUB_OVER_CURRENT)
718 return std_req_complete;
719 return std_req_stall;
721 EPDBG(ep, "SetPortFeature(%d,%d)\n", wIndex & 0xf, wValue);
722 return ast_vhub_set_port_feature(ep, wIndex & 0xf, wValue);
723 case ClearPortFeature:
724 EPDBG(ep, "ClearPortFeature(%d,%d)\n", wIndex & 0xf, wValue);
725 return ast_vhub_clr_port_feature(ep, wIndex & 0xf, wValue);
727 EPDBG(ep, "Unknown class request\n");
729 return std_req_stall;
732 void ast_vhub_hub_suspend(struct ast_vhub *vhub)
736 UDCDBG(vhub, "USB bus suspend\n");
741 vhub->suspended = true;
744 * Forward to unsuspended ports without changing
745 * their connection status.
747 for (i = 0; i < AST_VHUB_NUM_PORTS; i++) {
748 struct ast_vhub_port *p = &vhub->ports[i];
750 if (!(p->status & USB_PORT_STAT_SUSPEND))
751 ast_vhub_dev_suspend(&p->dev);
755 void ast_vhub_hub_resume(struct ast_vhub *vhub)
759 UDCDBG(vhub, "USB bus resume\n");
761 if (!vhub->suspended)
764 vhub->suspended = false;
767 * Forward to unsuspended ports without changing
768 * their connection status.
770 for (i = 0; i < AST_VHUB_NUM_PORTS; i++) {
771 struct ast_vhub_port *p = &vhub->ports[i];
773 if (!(p->status & USB_PORT_STAT_SUSPEND))
774 ast_vhub_dev_resume(&p->dev);
778 void ast_vhub_hub_reset(struct ast_vhub *vhub)
782 UDCDBG(vhub, "USB bus reset\n");
785 * Is the speed known ? If not we don't care, we aren't
786 * initialized yet and ports haven't been enabled.
788 if (vhub->speed == USB_SPEED_UNKNOWN)
791 /* We aren't suspended anymore obviously */
792 vhub->suspended = false;
795 vhub->speed = USB_SPEED_UNKNOWN;
797 /* Wakeup not enabled anymore */
798 vhub->wakeup_en = false;
801 * Clear all port status, disable gadgets and "suspend"
802 * them. They will be woken up by a port reset.
804 for (i = 0; i < AST_VHUB_NUM_PORTS; i++) {
805 struct ast_vhub_port *p = &vhub->ports[i];
807 /* Only keep the connected flag */
808 p->status &= USB_PORT_STAT_CONNECTION;
811 /* Suspend the gadget if any */
812 ast_vhub_dev_suspend(&p->dev);
816 writel(0, vhub->regs + AST_VHUB_CONF);
817 writel(0, vhub->regs + AST_VHUB_EP0_CTRL);
818 writel(VHUB_EP1_CTRL_RESET_TOGGLE |
819 VHUB_EP1_CTRL_ENABLE,
820 vhub->regs + AST_VHUB_EP1_CTRL);
821 writel(0, vhub->regs + AST_VHUB_EP1_STS_CHG);
824 void ast_vhub_init_hub(struct ast_vhub *vhub)
826 vhub->speed = USB_SPEED_UNKNOWN;
827 INIT_WORK(&vhub->wake_work, ast_vhub_wake_work);