57
57
#define TD_CTRL_NAK (1 << 19)
58
58
#define TD_CTRL_TIMEOUT (1 << 18)
60
#define UHCI_PORT_SUSPEND (1 << 12)
60
61
#define UHCI_PORT_RESET (1 << 9)
61
62
#define UHCI_PORT_LSDA (1 << 8)
63
#define UHCI_PORT_RD (1 << 6)
62
64
#define UHCI_PORT_ENC (1 << 3)
63
65
#define UHCI_PORT_EN (1 << 2)
64
66
#define UHCI_PORT_CSC (1 << 1)
65
67
#define UHCI_PORT_CCS (1 << 0)
69
#define UHCI_PORT_READ_ONLY (0x1bb)
70
#define UHCI_PORT_WRITE_CLEAR (UHCI_PORT_CSC | UHCI_PORT_ENC)
67
72
#define FRAME_TIMER_FREQ 1000
69
74
#define FRAME_MAX_LOOPS 100
348
351
for(i = 0; i < NB_PORTS; i++) {
349
352
port = &s->ports[i];
350
353
port->ctrl = 0x0080;
352
uhci_attach(&port->port, port->port.dev);
354
if (port->port.dev) {
355
usb_attach(&port->port, port->port.dev);
355
359
uhci_async_cancel_all(s);
498
502
usb_send_msg(dev, USB_MSG_RESET);
501
port->ctrl = (port->ctrl & 0x01fb) | (val & ~0x01fb);
505
port->ctrl &= UHCI_PORT_READ_ONLY;
506
port->ctrl |= (val & ~UHCI_PORT_READ_ONLY);
502
507
/* some bits are reset when a '1' is written to them */
503
port->ctrl &= ~(val & 0x000a);
508
port->ctrl &= ~(val & UHCI_PORT_WRITE_CLEAR);
596
static void uhci_attach(USBPort *port1, USBDevice *dev)
601
static void uhci_attach(USBPort *port1)
598
603
UHCIState *s = port1->opaque;
599
604
UHCIPort *port = &s->ports[port1->index];
602
if (port->port.dev) {
603
usb_attach(port1, NULL);
605
/* set connect status */
606
port->ctrl |= UHCI_PORT_CCS | UHCI_PORT_CSC;
609
if (dev->speed == USB_SPEED_LOW)
610
port->ctrl |= UHCI_PORT_LSDA;
612
port->ctrl &= ~UHCI_PORT_LSDA;
616
port->port.dev = dev;
617
/* send the attach message */
618
usb_send_msg(dev, USB_MSG_ATTACH);
606
/* set connect status */
607
port->ctrl |= UHCI_PORT_CCS | UHCI_PORT_CSC;
610
if (port->port.dev->speed == USB_SPEED_LOW) {
611
port->ctrl |= UHCI_PORT_LSDA;
620
/* set connect status */
621
if (port->ctrl & UHCI_PORT_CCS) {
622
port->ctrl &= ~UHCI_PORT_CCS;
623
port->ctrl |= UHCI_PORT_CSC;
626
if (port->ctrl & UHCI_PORT_EN) {
627
port->ctrl &= ~UHCI_PORT_EN;
628
port->ctrl |= UHCI_PORT_ENC;
613
port->ctrl &= ~UHCI_PORT_LSDA;
619
static void uhci_detach(USBPort *port1)
621
UHCIState *s = port1->opaque;
622
UHCIPort *port = &s->ports[port1->index];
624
/* set connect status */
625
if (port->ctrl & UHCI_PORT_CCS) {
626
port->ctrl &= ~UHCI_PORT_CCS;
627
port->ctrl |= UHCI_PORT_CSC;
630
if (port->ctrl & UHCI_PORT_EN) {
631
port->ctrl &= ~UHCI_PORT_EN;
632
port->ctrl |= UHCI_PORT_ENC;
638
static void uhci_wakeup(USBDevice *dev)
640
USBBus *bus = usb_bus_from_device(dev);
641
UHCIState *s = container_of(bus, UHCIState, bus);
642
UHCIPort *port = s->ports + dev->port->index;
644
if (port->ctrl & UHCI_PORT_SUSPEND && !(port->ctrl & UHCI_PORT_RD)) {
645
port->ctrl |= UHCI_PORT_RD;
633
dev = port->port.dev;
635
/* send the detach message */
636
usb_send_msg(dev, USB_MSG_DETACH);
638
port->port.dev = NULL;
1101
1109
register_ioport_read(addr, 32, 1, uhci_ioport_readb, s);
1112
static USBPortOps uhci_port_ops = {
1113
.attach = uhci_attach,
1114
.detach = uhci_detach,
1115
.wakeup = uhci_wakeup,
1104
1118
static int usb_uhci_common_initfn(UHCIState *s)
1106
1120
uint8_t *pci_conf = s->dev.config;
1116
1130
usb_bus_new(&s->bus, &s->dev.qdev);
1117
1131
for(i = 0; i < NB_PORTS; i++) {
1118
usb_register_port(&s->bus, &s->ports[i].port, s, i, uhci_attach);
1132
usb_register_port(&s->bus, &s->ports[i].port, s, i, &uhci_port_ops,
1133
USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL);
1134
usb_port_location(&s->ports[i].port, NULL, i+1);
1120
1136
s->frame_timer = qemu_new_timer(vm_clock, uhci_frame_timer, s);
1121
1137
s->expire_time = qemu_get_clock(vm_clock) +