All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [PULL 18/48] hw/arm/npcm7xx: Add EHCI and OHCI controllers
Date: Tue, 27 Oct 2020 11:44:08 +0000	[thread overview]
Message-ID: <20201027114438.17662-19-peter.maydell@linaro.org> (raw)
In-Reply-To: <20201027114438.17662-1-peter.maydell@linaro.org>

From: Havard Skinnemoen <hskinnemoen@google.com>

The NPCM730 and NPCM750 chips have a single USB host port shared between
a USB 2.0 EHCI host controller and a USB 1.1 OHCI host controller. This
adds support for both of them.

Testing notes:
  * With -device usb-kbd, qemu will automatically insert a full-speed
    hub, and the keyboard becomes controlled by the OHCI controller.
  * With -device usb-kbd,bus=usb-bus.0,port=1, the keyboard is directly
    attached to the port without any hubs, and the device becomes
    controlled by the EHCI controller since it's high speed capable.
  * With -device usb-kbd,bus=usb-bus.0,port=1,usb_version=1, the
    keyboard is directly attached to the port, but it only advertises
    itself as full-speed capable, so it becomes controlled by the OHCI
    controller.

In all cases, the keyboard device enumerates correctly.

Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 docs/system/arm/nuvoton.rst |  2 +-
 hw/usb/hcd-ehci.h           |  1 +
 include/hw/arm/npcm7xx.h    |  4 ++++
 hw/arm/npcm7xx.c            | 27 +++++++++++++++++++++++++--
 hw/usb/hcd-ehci-sysbus.c    | 19 +++++++++++++++++++
 5 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst
index 4342434df4a..99fc61c740c 100644
--- a/docs/system/arm/nuvoton.rst
+++ b/docs/system/arm/nuvoton.rst
@@ -39,6 +39,7 @@ Supported devices
  * OTP controllers (no protection features)
  * Flash Interface Unit (FIU; no protection features)
  * Random Number Generator (RNG)
+ * USB host (USBH)
 
 Missing devices
 ---------------
@@ -54,7 +55,6 @@ Missing devices
    * eSPI slave interface
 
  * Ethernet controllers (GMAC and EMC)
- * USB host (USBH)
  * USB device (USBD)
  * SMBus controller (SMBF)
  * Peripheral SPI controller (PSPI)
diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h
index fd122dd4cdd..a173707d9bf 100644
--- a/hw/usb/hcd-ehci.h
+++ b/hw/usb/hcd-ehci.h
@@ -344,6 +344,7 @@ struct EHCIPCIState {
 #define TYPE_PLATFORM_EHCI "platform-ehci-usb"
 #define TYPE_EXYNOS4210_EHCI "exynos4210-ehci-usb"
 #define TYPE_AW_H3_EHCI "aw-h3-ehci-usb"
+#define TYPE_NPCM7XX_EHCI "npcm7xx-ehci-usb"
 #define TYPE_TEGRA2_EHCI "tegra2-ehci-usb"
 #define TYPE_PPC4xx_EHCI "ppc4xx-ehci-usb"
 #define TYPE_FUSBH200_EHCI "fusbh200-ehci-usb"
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
index 761f9b987ed..aeee1beaaa4 100644
--- a/include/hw/arm/npcm7xx.h
+++ b/include/hw/arm/npcm7xx.h
@@ -25,6 +25,8 @@
 #include "hw/nvram/npcm7xx_otp.h"
 #include "hw/timer/npcm7xx_timer.h"
 #include "hw/ssi/npcm7xx_fiu.h"
+#include "hw/usb/hcd-ehci.h"
+#include "hw/usb/hcd-ohci.h"
 #include "target/arm/cpu.h"
 
 #define NPCM7XX_MAX_NUM_CPUS    (2)
@@ -77,6 +79,8 @@ typedef struct NPCM7xxState {
     NPCM7xxOTPState     fuse_array;
     NPCM7xxMCState      mc;
     NPCM7xxRNGState     rng;
+    EHCISysBusState     ehci;
+    OHCISysBusState     ohci;
     NPCM7xxFIUState     fiu[2];
 } NPCM7xxState;
 
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
index cb4db41c542..c1d122576b7 100644
--- a/hw/arm/npcm7xx.c
+++ b/hw/arm/npcm7xx.c
@@ -46,6 +46,10 @@
 #define NPCM7XX_MC_BA           (0xf0824000)
 #define NPCM7XX_RNG_BA          (0xf000b000)
 
+/* USB Host modules */
+#define NPCM7XX_EHCI_BA         (0xf0806000)
+#define NPCM7XX_OHCI_BA         (0xf0807000)
+
 /* Internal AHB SRAM */
 #define NPCM7XX_RAM3_BA         (0xc0008000)
 #define NPCM7XX_RAM3_SZ         (4 * KiB)
@@ -90,6 +94,8 @@ enum NPCM7xxInterrupt {
     NPCM7XX_WDG0_IRQ            = 47,   /* Timer Module 0 Watchdog */
     NPCM7XX_WDG1_IRQ,                   /* Timer Module 1 Watchdog */
     NPCM7XX_WDG2_IRQ,                   /* Timer Module 2 Watchdog */
+    NPCM7XX_EHCI_IRQ            = 61,
+    NPCM7XX_OHCI_IRQ            = 62,
 };
 
 /* Total number of GIC interrupts, including internal Cortex-A9 interrupts. */
@@ -263,6 +269,9 @@ static void npcm7xx_init(Object *obj)
         object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER);
     }
 
+    object_initialize_child(obj, "ehci", &s->ehci, TYPE_NPCM7XX_EHCI);
+    object_initialize_child(obj, "ohci", &s->ohci, TYPE_SYSBUS_OHCI);
+
     QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_fiu) != ARRAY_SIZE(s->fiu));
     for (i = 0; i < ARRAY_SIZE(s->fiu); i++) {
         object_initialize_child(obj, npcm7xx_fiu[i].name, &s->fiu[i],
@@ -380,6 +389,22 @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
     sysbus_realize(SYS_BUS_DEVICE(&s->rng), &error_abort);
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->rng), 0, NPCM7XX_RNG_BA);
 
+    /* USB Host */
+    object_property_set_bool(OBJECT(&s->ehci), "companion-enable", true,
+                             &error_abort);
+    sysbus_realize(SYS_BUS_DEVICE(&s->ehci), &error_abort);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->ehci), 0, NPCM7XX_EHCI_BA);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->ehci), 0,
+                       npcm7xx_irq(s, NPCM7XX_EHCI_IRQ));
+
+    object_property_set_str(OBJECT(&s->ohci), "masterbus", "usb-bus.0",
+                            &error_abort);
+    object_property_set_uint(OBJECT(&s->ohci), "num-ports", 1, &error_abort);
+    sysbus_realize(SYS_BUS_DEVICE(&s->ohci), &error_abort);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->ohci), 0, NPCM7XX_OHCI_BA);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->ohci), 0,
+                       npcm7xx_irq(s, NPCM7XX_OHCI_IRQ));
+
     /*
      * Flash Interface Unit (FIU). Can fail if incorrect number of chip selects
      * specified, but this is a programming error.
@@ -464,8 +489,6 @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
     create_unimplemented_device("npcm7xx.mcphy",        0xf05f0000,  64 * KiB);
     create_unimplemented_device("npcm7xx.gmac1",        0xf0802000,   8 * KiB);
     create_unimplemented_device("npcm7xx.gmac2",        0xf0804000,   8 * KiB);
-    create_unimplemented_device("npcm7xx.ehci",         0xf0806000,   4 * KiB);
-    create_unimplemented_device("npcm7xx.ohci",         0xf0807000,   4 * KiB);
     create_unimplemented_device("npcm7xx.vcd",          0xf0810000,  64 * KiB);
     create_unimplemented_device("npcm7xx.ece",          0xf0820000,   8 * KiB);
     create_unimplemented_device("npcm7xx.vdma",         0xf0822000,   8 * KiB);
diff --git a/hw/usb/hcd-ehci-sysbus.c b/hw/usb/hcd-ehci-sysbus.c
index 3730736540f..e3758db1b18 100644
--- a/hw/usb/hcd-ehci-sysbus.c
+++ b/hw/usb/hcd-ehci-sysbus.c
@@ -147,6 +147,24 @@ static const TypeInfo ehci_aw_h3_type_info = {
     .class_init    = ehci_aw_h3_class_init,
 };
 
+static void ehci_npcm7xx_class_init(ObjectClass *oc, void *data)
+{
+    SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc);
+    DeviceClass *dc = DEVICE_CLASS(oc);
+
+    sec->capsbase = 0x0;
+    sec->opregbase = 0x10;
+    sec->portscbase = 0x44;
+    sec->portnr = 1;
+    set_bit(DEVICE_CATEGORY_USB, dc->categories);
+}
+
+static const TypeInfo ehci_npcm7xx_type_info = {
+    .name          = TYPE_NPCM7XX_EHCI,
+    .parent        = TYPE_SYS_BUS_EHCI,
+    .class_init    = ehci_npcm7xx_class_init,
+};
+
 static void ehci_tegra2_class_init(ObjectClass *oc, void *data)
 {
     SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc);
@@ -269,6 +287,7 @@ static void ehci_sysbus_register_types(void)
     type_register_static(&ehci_platform_type_info);
     type_register_static(&ehci_exynos4210_type_info);
     type_register_static(&ehci_aw_h3_type_info);
+    type_register_static(&ehci_npcm7xx_type_info);
     type_register_static(&ehci_tegra2_type_info);
     type_register_static(&ehci_ppc4xx_type_info);
     type_register_static(&ehci_fusbh200_type_info);
-- 
2.20.1



  parent reply	other threads:[~2020-10-27 12:35 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-27 11:43 [PULL 00/48] target-arm queue Peter Maydell
2020-10-27 11:43 ` [PULL 01/48] linux-user/aarch64: Reset btype for signals Peter Maydell
2020-10-27 11:43 ` [PULL 02/48] linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI Peter Maydell
2020-10-27 11:43 ` [PULL 03/48] include/elf: Add defines related to GNU property notes for AArch64 Peter Maydell
2020-10-27 11:43 ` [PULL 04/48] linux-user/elfload: Avoid leaking interp_name using GLib memory API Peter Maydell
2020-10-27 11:43 ` [PULL 05/48] linux-user/elfload: Fix coding style in load_elf_image Peter Maydell
2020-10-27 11:43 ` [PULL 06/48] linux-user/elfload: Adjust iteration over phdr Peter Maydell
2020-10-27 11:43 ` [PULL 07/48] linux-user/elfload: Move PT_INTERP detection to first loop Peter Maydell
2020-10-27 11:43 ` [PULL 08/48] linux-user/elfload: Use Error for load_elf_image Peter Maydell
2020-10-27 11:43 ` [PULL 09/48] linux-user/elfload: Use Error for load_elf_interp Peter Maydell
2020-10-27 11:44 ` [PULL 10/48] linux-user/elfload: Parse NT_GNU_PROPERTY_TYPE_0 notes Peter Maydell
2020-10-27 11:44 ` [PULL 11/48] linux-user/elfload: Parse GNU_PROPERTY_AARCH64_FEATURE_1_AND Peter Maydell
2020-10-27 11:44 ` [PULL 12/48] tests/tcg/aarch64: Add bti smoke tests Peter Maydell
2020-10-27 11:44 ` [PULL 13/48] hw/arm/highbank: Silence warnings about missing fallthrough statements Peter Maydell
2020-10-27 11:44 ` [PULL 14/48] hw/arm: fix min_cpus for xlnx-versal-virt platform Peter Maydell
2020-10-27 11:44 ` [PULL 15/48] Move npcm7xx_timer_reached_zero call out of npcm7xx_timer_pause Peter Maydell
2020-10-27 11:44 ` [PULL 16/48] hw/timer: Adding watchdog for NPCM7XX Timer Peter Maydell
2020-10-27 11:44 ` [PULL 17/48] hw/misc: Add npcm7xx random number generator Peter Maydell
2020-10-27 11:44 ` Peter Maydell [this message]
2020-10-27 11:44 ` [PULL 19/48] hw/gpio: Add GPIO model for Nuvoton NPCM7xx Peter Maydell
2020-10-27 11:44 ` [PULL 20/48] hw/arm/smmuv3: Set the restoration priority of the vSMMUv3 explicitly Peter Maydell
2020-10-27 11:44 ` [PULL 21/48] hw/arm/bcm2836: Restrict BCM283XInfo declaration to C source Peter Maydell
2020-10-27 11:44 ` [PULL 22/48] hw/arm/bcm2836: QOM'ify more by adding class_init() to each SoC type Peter Maydell
2020-10-27 11:44 ` [PULL 23/48] hw/arm/bcm2836: Introduce BCM283XClass::core_count Peter Maydell
2020-10-27 11:44 ` [PULL 24/48] hw/arm/bcm2836: Only provide "enabled-cpus" property to multicore SoCs Peter Maydell
2020-10-27 11:44 ` [PULL 25/48] hw/arm/bcm2836: Split out common realize() code Peter Maydell
2020-10-27 11:44 ` [PULL 26/48] hw/arm/bcm2836: Introduce the BCM2835 SoC Peter Maydell
2020-10-27 11:44 ` [PULL 27/48] hw/arm/raspi: Add the Raspberry Pi A+ machine Peter Maydell
2020-10-27 11:44 ` [PULL 28/48] hw/arm/raspi: Add the Raspberry Pi Zero machine Peter Maydell
2020-10-27 11:44 ` [PULL 29/48] hw/arm/raspi: Add the Raspberry Pi 3 model A+ Peter Maydell
2020-10-27 11:44 ` [PULL 30/48] arm/trace: Fix hex printing Peter Maydell
2020-10-27 11:44 ` [PULL 31/48] hw/core/clock: provide the VMSTATE_ARRAY_CLOCK macro Peter Maydell
2020-10-27 11:44 ` [PULL 32/48] hw/core/clock: trace clock values in Hz instead of ns Peter Maydell
2020-10-27 11:44 ` [PULL 33/48] hw/arm/raspi: fix CPRMAN base address Peter Maydell
2020-10-27 11:44 ` [PULL 34/48] hw/arm/raspi: add a skeleton implementation of the CPRMAN Peter Maydell
2020-10-27 11:44 ` [PULL 35/48] hw/misc/bcm2835_cprman: add a PLL skeleton implementation Peter Maydell
2020-10-27 11:44 ` [PULL 36/48] hw/misc/bcm2835_cprman: implement PLLs behaviour Peter Maydell
2020-10-27 11:44 ` [PULL 37/48] hw/misc/bcm2835_cprman: add a PLL channel skeleton implementation Peter Maydell
2020-10-27 11:44 ` [PULL 38/48] hw/misc/bcm2835_cprman: implement PLL channels behaviour Peter Maydell
2020-10-27 11:44 ` [PULL 39/48] hw/misc/bcm2835_cprman: add a clock mux skeleton implementation Peter Maydell
2020-10-27 11:44 ` [PULL 40/48] hw/misc/bcm2835_cprman: implement clock mux behaviour Peter Maydell
2020-10-27 11:44 ` [PULL 41/48] hw/misc/bcm2835_cprman: add the DSI0HSCK multiplexer Peter Maydell
2020-10-27 11:44 ` [PULL 42/48] hw/misc/bcm2835_cprman: add sane reset values to the registers Peter Maydell
2020-10-27 11:44 ` [PULL 43/48] hw/char/pl011: add a clock input Peter Maydell
2020-10-27 11:44 ` [PULL 44/48] hw/arm/bcm2835_peripherals: connect the UART clock Peter Maydell
2020-10-27 11:44 ` [PULL 45/48] hw/watchdog: Implement SBSA watchdog device Peter Maydell
2020-10-27 11:44 ` [PULL 46/48] hw/arm/sbsa-ref: add " Peter Maydell
2020-10-27 11:44 ` [PULL 47/48] hw/core/ptimer: Support ptimer being disabled by timer callback Peter Maydell
2020-10-27 11:44 ` [PULL 48/48] hw/timer/armv7m_systick: Rewrite to use ptimers Peter Maydell
2020-11-04 10:03   ` Andrew Jones
2020-11-04 10:11     ` Philippe Mathieu-Daudé
2020-11-04 10:26       ` Andrew Jones
2020-10-27 13:22 ` [PULL 00/48] target-arm queue no-reply
2020-10-29 14:30 ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201027114438.17662-19-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.