poplar: add DWC2 OTG gadget support
authorShawn Guo <shawn.guo@linaro.org>
Tue, 18 Dec 2018 09:52:06 +0000 (17:52 +0800)
committerTom Rini <trini@konsulko.com>
Mon, 14 Jan 2019 22:42:44 +0000 (17:42 -0500)
It enables DWC2 OTG gadget driver support for Poplar board.  As
usb2_phy_init() is being always called from board_init(), we can save
the call from board_usb_init().

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
arch/arm/include/asm/arch-hi3798cv200/hi3798cv200.h
board/hisilicon/poplar/poplar.c

index f97b1eb29f841d7bc5cf930cc3d0c871813891d6..bb221e17e0ed9efa82774ebfedc1734b518f4cdd 100644 (file)
 /* DEVICES */
 #define REG_BASE_MCI                   0xF9830000
 #define REG_BASE_UART0                 0xF8B00000
+#define HIOTG_BASE_ADDR                        0xF98C0000
 
 /* PERI control registers (4KB) */
        /* USB2 PHY01 configuration register */
 #define PERI_CTRL_USB0                 (REG_BASE_PERI_CTRL + 0x120)
 
+       /* USB2 controller configuration register */
+#define PERI_CTRL_USB3                 (REG_BASE_PERI_CTRL + 0x12c)
+#define USB2_2P_CHIPID                 (1 << 28)
+
 /* PERI CRG registers (4KB) */
        /* USB2 CTRL0 clock and soft reset */
 #define PERI_CRG46                     (REG_BASE_CRG + 0xb8)
index 8adc750962a10f35626d778eb31394bc98ed3223..155dfbb401f1239bedb5807db263ca84b0346d25 100644 (file)
@@ -166,6 +166,34 @@ int board_mmc_init(bd_t *bis)
        return ret;
 }
 
+#if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
+#include <usb.h>
+#include <usb/dwc2_udc.h>
+#include <g_dnl.h>
+
+static struct dwc2_plat_otg_data poplar_otg_data = {
+       .regs_otg = HIOTG_BASE_ADDR
+};
+
+static void set_usb_to_device(void)
+{
+       setbits_le32(PERI_CTRL_USB3, USB2_2P_CHIPID);
+}
+
+int board_usb_init(int index, enum usb_init_type init)
+{
+       set_usb_to_device();
+       return dwc2_udc_probe(&poplar_otg_data);
+}
+
+int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
+{
+       if (!env_get("serial#"))
+               g_dnl_set_serialnumber("0123456789POPLAR");
+       return 0;
+}
+#endif
+
 int board_init(void)
 {
        usb2_phy_init();