qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] hw: usb: hcd-ohci: Move OHCISysBusState and TYPE_SYSBUS_OHCI to include file
@ 2020-02-14  6:21 Guenter Roeck
  2020-02-14  6:21 ` [PATCH 2/3] arm: allwinner: Wire up USB OHCI Guenter Roeck
  2020-02-14  6:21 ` [PATCH 3/3] arm: allwinner: Wire up USB EHCI Guenter Roeck
  0 siblings, 2 replies; 5+ messages in thread
From: Guenter Roeck @ 2020-02-14  6:21 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Beniamino Galvani, qemu-arm, Gerd Hoffmann, Guenter Roeck, qemu-devel

We need to be able to use OHCISysBusState outside hcd-ohci.c, so move it
to its include file.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 hw/usb/hcd-ohci.c | 15 ---------------
 hw/usb/hcd-ohci.h | 16 ++++++++++++++++
 2 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c
index 8a94bd004a..1e6e85e86a 100644
--- a/hw/usb/hcd-ohci.c
+++ b/hw/usb/hcd-ohci.c
@@ -1870,21 +1870,6 @@ void ohci_sysbus_die(struct OHCIState *ohci)
     ohci_bus_stop(ohci);
 }
 
-#define TYPE_SYSBUS_OHCI "sysbus-ohci"
-#define SYSBUS_OHCI(obj) OBJECT_CHECK(OHCISysBusState, (obj), TYPE_SYSBUS_OHCI)
-
-typedef struct {
-    /*< private >*/
-    SysBusDevice parent_obj;
-    /*< public >*/
-
-    OHCIState ohci;
-    char *masterbus;
-    uint32_t num_ports;
-    uint32_t firstport;
-    dma_addr_t dma_offset;
-} OHCISysBusState;
-
 static void ohci_realize_pxa(DeviceState *dev, Error **errp)
 {
     OHCISysBusState *s = SYSBUS_OHCI(dev);
diff --git a/hw/usb/hcd-ohci.h b/hw/usb/hcd-ohci.h
index 16e3f1e13a..5c8819aedf 100644
--- a/hw/usb/hcd-ohci.h
+++ b/hw/usb/hcd-ohci.h
@@ -22,6 +22,7 @@
 #define HCD_OHCI_H
 
 #include "sysemu/dma.h"
+#include "hw/usb.h"
 
 /* Number of Downstream Ports on the root hub: */
 #define OHCI_MAX_PORTS 15
@@ -90,6 +91,21 @@ typedef struct OHCIState {
     void (*ohci_die)(struct OHCIState *ohci);
 } OHCIState;
 
+#define TYPE_SYSBUS_OHCI "sysbus-ohci"
+#define SYSBUS_OHCI(obj) OBJECT_CHECK(OHCISysBusState, (obj), TYPE_SYSBUS_OHCI)
+
+typedef struct {
+    /*< private >*/
+    SysBusDevice parent_obj;
+    /*< public >*/
+
+    OHCIState ohci;
+    char *masterbus;
+    uint32_t num_ports;
+    uint32_t firstport;
+    dma_addr_t dma_offset;
+} OHCISysBusState;
+
 extern const VMStateDescription vmstate_ohci_state;
 
 void usb_ohci_init(OHCIState *ohci, DeviceState *dev, uint32_t num_ports,
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] arm: allwinner: Wire up USB OHCI
  2020-02-14  6:21 [PATCH 1/3] hw: usb: hcd-ohci: Move OHCISysBusState and TYPE_SYSBUS_OHCI to include file Guenter Roeck
@ 2020-02-14  6:21 ` Guenter Roeck
  2020-02-14  6:21 ` [PATCH 3/3] arm: allwinner: Wire up USB EHCI Guenter Roeck
  1 sibling, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2020-02-14  6:21 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Beniamino Galvani, qemu-arm, Gerd Hoffmann, Guenter Roeck, qemu-devel

Initialize OHCI controllers on Allwinner A10. With this patch applied,
USB OHCI ports are discovered when booting the cubieboard machine with
a recent Linux kernel.

ohci-platform 1c14400.usb: Generic Platform OHCI controller
ohci-platform 1c14400.usb: new USB bus registered, assigned bus number 3
ohci-platform 1c14400.usb: irq 27, io mem 0x01c14400
ohci-platform 1c1c400.usb: Generic Platform OHCI controller
ohci-platform 1c1c400.usb: new USB bus registered, assigned bus number 4
ohci-platform 1c1c400.usb: irq 32, io mem 0x01c1c400

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 hw/arm/allwinner-a10.c         | 30 ++++++++++++++++++++++++++++++
 include/hw/arm/allwinner-a10.h |  2 ++
 2 files changed, 32 insertions(+)

diff --git a/hw/arm/allwinner-a10.c b/hw/arm/allwinner-a10.c
index 45cd8d2db5..818145428c 100644
--- a/hw/arm/allwinner-a10.c
+++ b/hw/arm/allwinner-a10.c
@@ -24,12 +24,15 @@
 #include "hw/arm/allwinner-a10.h"
 #include "hw/misc/unimp.h"
 #include "sysemu/sysemu.h"
+#include "hw/boards.h"
+#include "hw/usb/hcd-ohci.h"
 
 #define AW_A10_CCM_REG_BASE     0x01c20000
 #define AW_A10_PIC_REG_BASE     0x01c20400
 #define AW_A10_PIT_REG_BASE     0x01c20c00
 #define AW_A10_UART0_REG_BASE   0x01c28000
 #define AW_A10_EMAC_BASE        0x01c0b000
+#define AW_A10_OHCI_BASE        0x01c14400
 #define AW_A10_SATA_BASE        0x01c18000
 
 static void aw_a10_init(Object *obj)
@@ -53,6 +56,15 @@ static void aw_a10_init(Object *obj)
 
     sysbus_init_child_obj(obj, "sata", &s->sata, sizeof(s->sata),
                           TYPE_ALLWINNER_AHCI);
+
+    if (machine_usb(current_machine)) {
+        int i;
+
+        for (i = 0; i < ARRAY_SIZE(s->ohci); i++) {
+            sysbus_init_child_obj(obj, "ohci[*]", OBJECT(&s->ohci[i]),
+                                  sizeof(s->ohci[i]), TYPE_SYSBUS_OHCI);
+        }
+    }
 }
 
 static void aw_a10_realize(DeviceState *dev, Error **errp)
@@ -133,6 +145,24 @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
     serial_mm_init(get_system_memory(), AW_A10_UART0_REG_BASE, 2,
                    qdev_get_gpio_in(dev, 1),
                    115200, serial_hd(0), DEVICE_NATIVE_ENDIAN);
+
+    if (machine_usb(current_machine)) {
+        int i;
+
+        for (i = 0; i < ARRAY_SIZE(s->ohci); i++) {
+
+            object_property_set_bool(OBJECT(&s->ohci[i]), true, "realized",
+                                     &err);
+            if (err) {
+                error_propagate(errp, err);
+                return;
+            }
+            sysbus_mmio_map(SYS_BUS_DEVICE(&s->ohci[i]), 0,
+                            AW_A10_OHCI_BASE + i * 0x8000);
+            sysbus_connect_irq(SYS_BUS_DEVICE(&s->ohci[i]), 0,
+                               qdev_get_gpio_in(dev, 64 + i));
+        }
+    }
 }
 
 static void aw_a10_class_init(ObjectClass *oc, void *data)
diff --git a/include/hw/arm/allwinner-a10.h b/include/hw/arm/allwinner-a10.h
index 0007a927bb..4864adbec3 100644
--- a/include/hw/arm/allwinner-a10.h
+++ b/include/hw/arm/allwinner-a10.h
@@ -9,6 +9,7 @@
 #include "hw/intc/allwinner-a10-pic.h"
 #include "hw/net/allwinner_emac.h"
 #include "hw/ide/ahci.h"
+#include "hw/usb/hcd-ohci.h"
 
 #include "target/arm/cpu.h"
 
@@ -29,6 +30,7 @@ typedef struct AwA10State {
     AwEmacState emac;
     AllwinnerAHCIState sata;
     MemoryRegion sram_a;
+    OHCISysBusState ohci[2];
 } AwA10State;
 
 #endif
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] arm: allwinner: Wire up USB EHCI
  2020-02-14  6:21 [PATCH 1/3] hw: usb: hcd-ohci: Move OHCISysBusState and TYPE_SYSBUS_OHCI to include file Guenter Roeck
  2020-02-14  6:21 ` [PATCH 2/3] arm: allwinner: Wire up USB OHCI Guenter Roeck
@ 2020-02-14  6:21 ` Guenter Roeck
  2020-02-14 10:08   ` Gerd Hoffmann
  1 sibling, 1 reply; 5+ messages in thread
From: Guenter Roeck @ 2020-02-14  6:21 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Beniamino Galvani, qemu-arm, Gerd Hoffmann, Guenter Roeck, qemu-devel

Initialize EHCI controllers on Allwinner A10. With this patch applied,
USB EHCI ports are discovered when booting the cubieboard machine with
a recent Linux kernel.

ehci-platform 1c14000.usb: EHCI Host Controller
ehci-platform 1c14000.usb: new USB bus registered, assigned bus number 1
ehci-platform 1c14000.usb: irq 26, io mem 0x01c14000
ehci-platform 1c14000.usb: USB 2.0 started, EHCI 1.00
ehci-platform 1c1c000.usb: EHCI Host Controller
ehci-platform 1c1c000.usb: new USB bus registered, assigned bus number 2
ehci-platform 1c1c000.usb: irq 31, io mem 0x01c1c000
ehci-platform 1c1c000.usb: USB 2.0 started, EHCI 1.00

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 hw/arm/allwinner-a10.c         | 17 +++++++++++++++++
 include/hw/arm/allwinner-a10.h |  2 ++
 2 files changed, 19 insertions(+)

diff --git a/hw/arm/allwinner-a10.c b/hw/arm/allwinner-a10.c
index 818145428c..f8b963b5c3 100644
--- a/hw/arm/allwinner-a10.c
+++ b/hw/arm/allwinner-a10.c
@@ -32,6 +32,7 @@
 #define AW_A10_PIT_REG_BASE     0x01c20c00
 #define AW_A10_UART0_REG_BASE   0x01c28000
 #define AW_A10_EMAC_BASE        0x01c0b000
+#define AW_A10_EHCI_BASE        0x01c14000
 #define AW_A10_OHCI_BASE        0x01c14400
 #define AW_A10_SATA_BASE        0x01c18000
 
@@ -64,6 +65,10 @@ static void aw_a10_init(Object *obj)
             sysbus_init_child_obj(obj, "ohci[*]", OBJECT(&s->ohci[i]),
                                   sizeof(s->ohci[i]), TYPE_SYSBUS_OHCI);
         }
+        for (i = 0; i < ARRAY_SIZE(s->ehci); i++) {
+            sysbus_init_child_obj(obj, "ehci[*]", OBJECT(&s->ehci[i]),
+                                  sizeof(s->ehci[i]), TYPE_PLATFORM_EHCI);
+        }
     }
 }
 
@@ -162,6 +167,18 @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
             sysbus_connect_irq(SYS_BUS_DEVICE(&s->ohci[i]), 0,
                                qdev_get_gpio_in(dev, 64 + i));
         }
+        for (i = 0; i < ARRAY_SIZE(s->ehci); i++) {
+            object_property_set_bool(OBJECT(&s->ehci[i]), true, "realized",
+                                     &err);
+            if (err) {
+                error_propagate(errp, err);
+                return;
+            }
+            sysbus_mmio_map(SYS_BUS_DEVICE(&s->ehci[i]), 0,
+                            AW_A10_EHCI_BASE + i * 0x8000);
+            sysbus_connect_irq(SYS_BUS_DEVICE(&s->ehci[i]), 0,
+                               qdev_get_gpio_in(dev, 39 + i));
+        }
     }
 }
 
diff --git a/include/hw/arm/allwinner-a10.h b/include/hw/arm/allwinner-a10.h
index 4864adbec3..17e1ee92e2 100644
--- a/include/hw/arm/allwinner-a10.h
+++ b/include/hw/arm/allwinner-a10.h
@@ -10,6 +10,7 @@
 #include "hw/net/allwinner_emac.h"
 #include "hw/ide/ahci.h"
 #include "hw/usb/hcd-ohci.h"
+#include "hw/usb/hcd-ehci.h"
 
 #include "target/arm/cpu.h"
 
@@ -31,6 +32,7 @@ typedef struct AwA10State {
     AllwinnerAHCIState sata;
     MemoryRegion sram_a;
     OHCISysBusState ohci[2];
+    EHCISysBusState ehci[2];
 } AwA10State;
 
 #endif
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 3/3] arm: allwinner: Wire up USB EHCI
  2020-02-14  6:21 ` [PATCH 3/3] arm: allwinner: Wire up USB EHCI Guenter Roeck
@ 2020-02-14 10:08   ` Gerd Hoffmann
  2020-02-14 14:26     ` Guenter Roeck
  0 siblings, 1 reply; 5+ messages in thread
From: Gerd Hoffmann @ 2020-02-14 10:08 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Beniamino Galvani, Peter Maydell, qemu-arm, qemu-devel

> ehci-platform 1c1c000.usb: new USB bus registered, assigned bus number 2
> ehci-platform 1c1c000.usb: irq 31, io mem 0x01c1c000
> ehci-platform 1c1c000.usb: USB 2.0 started, EHCI 1.00

> +        for (i = 0; i < ARRAY_SIZE(s->ehci); i++) {
> +            object_property_set_bool(OBJECT(&s->ehci[i]), true, "realized",
> +                                     &err);

I suspect the ohci controllers are ehci companions, i.e. they handle a
single usb bus, with ehci handling usb2 and ohci handling usb1 devices?

If so then you should initialize ehci first, explicitly assign bus
names and set the masterbus property for the ohci controllers.

See also docs/usb2.txt

cheers,
  Gerd



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 3/3] arm: allwinner: Wire up USB EHCI
  2020-02-14 10:08   ` Gerd Hoffmann
@ 2020-02-14 14:26     ` Guenter Roeck
  0 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2020-02-14 14:26 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: Beniamino Galvani, Peter Maydell, qemu-arm, qemu-devel

On 2/14/20 2:08 AM, Gerd Hoffmann wrote:
>> ehci-platform 1c1c000.usb: new USB bus registered, assigned bus number 2
>> ehci-platform 1c1c000.usb: irq 31, io mem 0x01c1c000
>> ehci-platform 1c1c000.usb: USB 2.0 started, EHCI 1.00
> 
>> +        for (i = 0; i < ARRAY_SIZE(s->ehci); i++) {
>> +            object_property_set_bool(OBJECT(&s->ehci[i]), true, "realized",
>> +                                     &err);
> 
> I suspect the ohci controllers are ehci companions, i.e. they handle a
> single usb bus, with ehci handling usb2 and ohci handling usb1 devices?
> 
> If so then you should initialize ehci first, explicitly assign bus
> names and set the masterbus property for the ohci controllers.
> 
> See also docs/usb2.txt
> 

Thanks for the references. Makes sense; I'll give it a try.

Guenter


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-02-14 14:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-14  6:21 [PATCH 1/3] hw: usb: hcd-ohci: Move OHCISysBusState and TYPE_SYSBUS_OHCI to include file Guenter Roeck
2020-02-14  6:21 ` [PATCH 2/3] arm: allwinner: Wire up USB OHCI Guenter Roeck
2020-02-14  6:21 ` [PATCH 3/3] arm: allwinner: Wire up USB EHCI Guenter Roeck
2020-02-14 10:08   ` Gerd Hoffmann
2020-02-14 14:26     ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).