Skip to contentSkip to conversation

armv8/fsl-layerscape: add dwc3 gadget driver support

PATCH Superseded Rajat Srivastava 5 participants 12 messages May 31, 2016 – Jun 1, 2016

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover armv8/fsl-layerscape: add dwc3 gadget driver support

Adds support for dwc3 gadget driver for ARM v8 platform of layerscape series. Currently this patch has been tested for LS1043A.

Rajat Srivastava (3):
usb: ums: support multiple controllers using controller_index armv8/fsl-layerscape: add dwc3 gadget driver support armv8/fsl-layerscape: enable dwc3 gadget driver support

 arch/arm/cpu/armv8/fsl-layerscape/soc.c            | 87 +++++++++++++++++++++-
 .../include/asm/arch-fsl-layerscape/immap_lsch2.h  |  6 ++
 .../include/asm/arch-fsl-layerscape/sys_proto.h    | 11 +++
 cmd/usb_mass_storage.c                             |  2 +-
 drivers/usb/dwc3/core.c                            | 12 +++
 drivers/usb/gadget/f_mass_storage.c                | 10 ++-
 include/configs/ls1043aqds.h                       | 15 ++++
 7 files changed, 139 insertions(+), 4 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-fsl-layerscape/sys_proto.h
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/3 usb: ums: support multiple controllers using controller_index

From: Rajesh Bhagat <[email protected]>

Adds a new field in fsg_common namely controller_index to support multiple controllers usb gadget support.

---
 cmd/usb_mass_storage.c              |  2 +-
 drivers/usb/gadget/f_mass_storage.c | 10 +++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
cmd/usb_mass_storage.c +1 -1
index b05913a..1c955f8 100644
@@ -214,7 +214,7 @@ int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
 	while (1) {
 		usb_gadget_handle_interrupts(controller_index);
 
-		rc = fsg_main_thread(NULL);
+		rc = fsg_main_thread(&controller_index);
 		if (rc) {
 			/* Check I/O error */
 			if (rc == -EIO)
drivers/usb/gadget/f_mass_storage.c +9 -1
index 1ecb92a..cc3e4af 100644
@@ -362,6 +362,7 @@ struct fsg_common {
 	char inquiry_string[8 + 16 + 4 + 1];
 
 	struct kref		ref;
+	unsigned int controller_index;
 };
 
 struct fsg_config {
@@ -691,7 +692,7 @@ static int sleep_thread(struct fsg_common *common)
 			k = 0;
 		}
 
-		usb_gadget_handle_interrupts(0);
+		usb_gadget_handle_interrupts(common->controller_index);
 	}
 	common->thread_wakeup_needed = 0;
 	return rc;
@@ -2406,6 +2407,11 @@ int fsg_main_thread(void *common_)
 {
 	int ret;
 	struct fsg_common	*common = the_fsg_common;
+
+	/* update the controller_index */
+	if (common_)
+		common->controller_index = *(unsigned int *)common_;
+
 	/* The main loop */
 	do {
 		if (exception_in_progress(common)) {
@@ -2476,6 +2482,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
 
 	common->ops = NULL;
 	common->private_data = NULL;
+	common->controller_index = 0;
 
 	common->gadget = gadget;
 	common->ep0 = gadget->ep0;
@@ -2770,6 +2777,7 @@ int fsg_add(struct usb_configuration *c)
 
 	fsg_common->ops = NULL;
 	fsg_common->private_data = NULL;
+	fsg_common->controller_index = 0;
 
 	the_fsg_common = fsg_common;
 
Signature · 1 line
1.9.1
#2 lore raw

PATCH 1/3 usb: ums: support multiple controllers using controller_index

Hi Rajat,

Quoted 17 lines

From: Rajesh Bhagat <[email protected]>

Adds a new field in fsg_common namely controller_index to support multiple controllers usb gadget support.

---
 cmd/usb_mass_storage.c              |  2 +-
 drivers/usb/gadget/f_mass_storage.c | 10 +++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
cmd/usb_mass_storage.c +0 -0
index b05913a..1c955f8 100644

cmd/usb_mass_storage.c int do_usb_mass_storage(cmd_tbl_t *cmdtp, int · line 217

Quoted 5 lines
cmd/usb_mass_storage.c +1 -1
@@ -214,7 +214,7 @@ int do_usb_mass_storage(cmd_tbl_t *cmdtp, int
 flag, while (1) {
 		usb_gadget_handle_interrupts(controller_index);
 
-		rc = fsg_main_thread(NULL);
+		rc = fsg_main_thread(&controller_index);

controller_index is defined as unsigned int.

However, fsg_main_thread(void *common_) accepts void * as its parameter.

Could you adjust it to accept unsigned int index parameter?

Quoted 25 lines
cmd/usb_mass_storage.c +0 -0
 		if (rc) {
 			/* Check I/O error */
 			if (rc == -EIO)
(quoted diff) +0 -0

b/drivers/usb/gadget/f_mass_storage.c index 1ecb92a..cc3e4af 100644

drivers/usb/gadget/f_mass_storage.c +2 -1
@@ -362,6 +362,7 @@ struct fsg_common {
 	char inquiry_string[8 + 16 + 4 + 1];
 
 	struct kref		ref;
+	unsigned int controller_index;
 };
 
 struct fsg_config {
@@ -691,7 +692,7 @@ static int sleep_thread(struct fsg_common *common)
 			k = 0;
 		}
 
-		usb_gadget_handle_interrupts(0);
+
 usb_gadget_handle_interrupts(common->controller_index); }
 	common->thread_wakeup_needed = 0;
 	return rc;

drivers/usb/gadget/f_mass_storage.c int fsg_main_thread(void *common_) · line 2412

Quoted 6 lines
drivers/usb/gadget/f_mass_storage.c +3 -0
@@ -2406,6 +2407,11 @@ int fsg_main_thread(void *common_)
 {
 	int ret;
 	struct fsg_common	*common = the_fsg_common;
+
+	/* update the controller_index */
+	if (common_)

Replace common_ with unsigned int index

Quoted 21 lines
drivers/usb/gadget/f_mass_storage.c +4 -0
+		common->controller_index = *(unsigned int *)common_;
+
 	/* The main loop */
 	do {
 		if (exception_in_progress(common)) {
@@ -2476,6 +2482,7 @@ static struct fsg_common
 *fsg_common_init(struct fsg_common *common, 
 	common->ops = NULL;
 	common->private_data = NULL;
+	common->controller_index = 0;
 
 	common->gadget = gadget;
 	common->ep0 = gadget->ep0;
@@ -2770,6 +2777,7 @@ int fsg_add(struct usb_configuration *c)
 
 	fsg_common->ops = NULL;
 	fsg_common->private_data = NULL;
+	fsg_common->controller_index = 0;
 
 	the_fsg_common = fsg_common;
 
Signature · 5 lines
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group
#3 lore raw

PATCH 1/3 usb: ums: support multiple controllers using controller_index

Quoted 35 lines

-----Original Message-----
From: Lukasz Majewski [mailto:l.majewski at samsung.com]
Sent: Tuesday, May 31, 2016 8:22 PM
To: Rajat Srivastava <[email protected]>
Cc: u-boot at lists.denx.de; sjg at chromium.org; marex at denx.de; albert.u.boot at aribaud.net; prabhakar at freescale.com; york sun <[email protected]>; Mingkai Hu <[email protected]>; Rajesh Bhagat <[email protected]>; michal.simek at xilinx.com; felipe.balbi at linux.intel.com
Subject: Re: [PATCH 1/3] usb: ums: support multiple controllers using controller_index

Hi Rajat,

Quoted 20 lines

From: Rajesh Bhagat <[email protected]>

Adds a new field in fsg_common namely controller_index to support multiple controllers usb gadget support.

---
 cmd/usb_mass_storage.c              |  2 +-
 drivers/usb/gadget/f_mass_storage.c | 10 +++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
cmd/usb_mass_storage.c index renamed from cmd/usb_mass_storage.c +0 -0

b05913a..1c955f8 100644

cmd/usb_mass_storage.c +0 -0
@@ -214,7 +214,7 @@ int do_usb_mass_storage(cmd_tbl_t *cmdtp, int
 flag, while (1) {
 		usb_gadget_handle_interrupts(controller_index);
 
Quoted 3 lines

cmd/usb_mass_storage.c int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag, · line 217

Quoted 2 lines
cmd/usb_mass_storage.c +1 -1
-		rc = fsg_main_thread(NULL);
+		rc = fsg_main_thread(&controller_index);

Hello Lukasz,

Quoted 6 lines

controller_index is defined as unsigned int.

However, fsg_main_thread(void *common_) accepts void * as its parameter.

Could you adjust it to accept unsigned int index parameter?

Will take care in v2.

Quoted 19 lines
Quoted 19 lines
cmd/usb_mass_storage.c +0 -0
 		if (rc) {
 			/* Check I/O error */
 			if (rc == -EIO)
(quoted diff) +0 -0

b/drivers/usb/gadget/f_mass_storage.c index 1ecb92a..cc3e4af 100644

drivers/usb/gadget/f_mass_storage.c +1 -0
@@ -362,6 +362,7 @@ struct fsg_common {
 	char inquiry_string[8 + 16 + 4 + 1];
 
 	struct kref		ref;
+	unsigned int controller_index;
 };
 
 struct fsg_config {
@@ -691,7 +692,7 @@ static int sleep_thread(struct fsg_common *common)
 			k = 0;
 		}
 
Quoted 14 lines

drivers/usb/gadget/f_mass_storage.c int fsg_main_thread(void *common_) { · line 2411

Quoted 11 lines
drivers/usb/gadget/f_mass_storage.c +4 -1
-		usb_gadget_handle_interrupts(0);
+
 usb_gadget_handle_interrupts(common->controller_index); }
 	common->thread_wakeup_needed = 0;
 	return rc;
@@ -2406,6 +2407,11 @@ int fsg_main_thread(void *common_)  {
 	int ret;
 	struct fsg_common	*common = the_fsg_common;
+
+	/* update the controller_index */
+	if (common_)

Replace common_ with unsigned int index

Will take care in v2.

Quoted 29 lines
Quoted 13 lines
drivers/usb/gadget/f_mass_storage.c +2 -0
+		common->controller_index = *(unsigned int *)common_;
+
 	/* The main loop */
 	do {
 		if (exception_in_progress(common)) { @@ -2476,6 +2482,7 @@ static
 struct fsg_common *fsg_common_init(struct fsg_common *common,
drivers/usb/gadget/f_mass_storage.c +1 -0
 	common->ops = NULL;
 	common->private_data = NULL;
+	common->controller_index = 0;
 
 	common->gadget = gadget;
 	common->ep0 = gadget->ep0;

drivers/usb/gadget/f_mass_storage.c int fsg_add(struct usb_configuration *c) · line 2783

Quoted 7 lines
drivers/usb/gadget/f_mass_storage.c +1 -0
@@ -2770,6 +2777,7 @@ int fsg_add(struct usb_configuration *c)
 
 	fsg_common->ops = NULL;
 	fsg_common->private_data = NULL;
+	fsg_common->controller_index = 0;
 
 	the_fsg_common = fsg_common;
 

--
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

#4 lore raw

PATCH 2/3 armv8/fsl-layerscape: add dwc3 gadget driver support

In reply to Rajat Srivastava

From: Rajesh Bhagat <[email protected]>

Implements the dwc3 gadget driver support for LS1043 platform, and performs below operations:
1. Enables snooping support for DWC3 controller.
2. Enables cache coherency in LS1043 platform.

---
 arch/arm/cpu/armv8/fsl-layerscape/soc.c            | 87 +++++++++++++++++++++-
 .../include/asm/arch-fsl-layerscape/immap_lsch2.h  |  6 ++
 .../include/asm/arch-fsl-layerscape/sys_proto.h    | 11 +++
 drivers/usb/dwc3/core.c                            | 12 +++
 4 files changed, 114 insertions(+), 2 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-fsl-layerscape/sys_proto.h
arch/arm/cpu/armv8/fsl-layerscape/soc.c +85 -2
index 0fb5c7f..84b973d 100644
@@ -17,6 +17,10 @@
 #ifdef CONFIG_CHAIN_OF_TRUST
 #include <fsl_validate.h>
 #endif
+#include <usb.h>
+#include <dwc3-uboot.h>
+#include <linux/usb/xhci-fsl.h>
+
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -318,9 +322,12 @@ void fsl_lsch2_early_init_f(void)
 #if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
 	out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
 #endif
-	/* Make SEC reads and writes snoopable */
+	/* Make SEC and USB reads and writes snoopable */
 	setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
-		     SCFG_SNPCNFGCR_SECWRSNP);
+		     SCFG_SNPCNFGCR_SECWRSNP | SCFG_SNPCNFGCR_USB1RDSNP |
+		     SCFG_SNPCNFGCR_USB1WRSNP | SCFG_SNPCNFGCR_USB2RDSNP |
+		     SCFG_SNPCNFGCR_USB2WRSNP | SCFG_SNPCNFGCR_USB3RDSNP |
+		     SCFG_SNPCNFGCR_USB3WRSNP);
 
 	/*
 	 * Enable snoop requests and DVM message requests for
@@ -336,6 +343,82 @@ void fsl_lsch2_early_init_f(void)
 }
 #endif
 
+#ifdef CONFIG_USB_DWC3
+
+#if defined(CONFIG_LS1043A)
+static struct dwc3_device dwc3_device_data0 = {
+	.maximum_speed = USB_SPEED_HIGH,
+	.base = CONFIG_SYS_FSL_XHCI_USB1_ADDR,
+	.dr_mode = USB_DR_MODE_PERIPHERAL,
+	.index = 0,
+};
+
+static struct dwc3_device dwc3_device_data1 = {
+	.maximum_speed = USB_SPEED_HIGH,
+	.base = CONFIG_SYS_FSL_XHCI_USB2_ADDR,
+	.dr_mode = USB_DR_MODE_PERIPHERAL,
+	.index = 1,
+};
+
+static struct dwc3_device dwc3_device_data2 = {
+	.maximum_speed = USB_SPEED_HIGH,
+	.base = CONFIG_SYS_FSL_XHCI_USB3_ADDR,
+	.dr_mode = USB_DR_MODE_PERIPHERAL,
+	.index = 2,
+};
+
+int usb_gadget_handle_interrupts(int index)
+{
+	dwc3_uboot_handle_interrupt(index);
+	return 0;
+}
+#endif
+
+int board_usb_init(int index, enum usb_init_type init)
+{
+	switch (init) {
+	case USB_INIT_DEVICE:
+		switch (index) {
+#if defined(CONFIG_LS1043A)
+		case 0:
+			dwc3_uboot_init(&dwc3_device_data0);
+			break;
+
+		case 1:
+			dwc3_uboot_init(&dwc3_device_data1);
+			break;
+		case 2:
+			dwc3_uboot_init(&dwc3_device_data2);
+			break;
+#endif
+		default:
+			printf("Invalid Controller Index\n");
+			return -1;
+		}
+		break;
+	default:
+		break;
+	}
+	return 0;
+}
+
+int board_usb_cleanup(int index, enum usb_init_type init)
+{
+	switch (init) {
+	case USB_INIT_DEVICE:
+#if defined(CONFIG_LS1043A)
+		dwc3_uboot_exit(index);
+#endif
+		break;
+	default:
+		break;
+	}
+	return 0;
+}
+#endif
+
+
+
 #ifdef CONFIG_BOARD_LATE_INIT
 int board_late_init(void)
 {
arch/arm/include/asm/arch-fsl-layerscape/immap_lsch2.h +6 -0
index 57b99d4..13ba1a6 100644
@@ -328,6 +328,12 @@ struct ccsr_gur {
 
 #define SCFG_SNPCNFGCR_SECRDSNP		0x80000000
 #define SCFG_SNPCNFGCR_SECWRSNP		0x40000000
+#define SCFG_SNPCNFGCR_USB1RDSNP	0x00200000
+#define SCFG_SNPCNFGCR_USB1WRSNP	0x00100000
+#define SCFG_SNPCNFGCR_USB2RDSNP	0x00008000
+#define SCFG_SNPCNFGCR_USB2WRSNP	0x00010000
+#define SCFG_SNPCNFGCR_USB3RDSNP	0x00002000
+#define SCFG_SNPCNFGCR_USB3WRSNP	0x00004000
 
 /* Supplemental Configuration Unit */
 struct ccsr_scfg {
arch/arm/include/asm/arch-fsl-layerscape/sys_proto.h new file +11 -0
new file mode 100644
index 0000000..252c676
@@ -0,0 +1,11 @@
+/*
+ * Copyright 2016 Freescale Semiconductor
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef _ASM_ARMV8_FSL_LAYERSCAPE_SYS_PROTO_H_
+#define _ASM_ARMV8_FSL_LAYERSCAPE_SYS_PROTO_H_
+
+
+#endif /* _ASM_ARMV8_FSL_LAYERSCAPE_SYS_PROTO_H_ */
drivers/usb/dwc3/core.c +12 -0
index 85cc96a..5eeb71d 100644
@@ -690,6 +690,18 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
 		return -ENOMEM;
 	}
 
+#if defined(CONFIG_LS1043A)
+	 /* Change burst beat and outstanding pipelined transfers requests */
+	dwc3_writel(dwc->regs, DWC3_GSBUSCFG0,
+		    (dwc3_readl(dwc->regs, DWC3_GSBUSCFG0) & ~0xff) | 0xf);
+	dwc3_writel(dwc->regs, DWC3_GSBUSCFG1,
+		    dwc3_readl(dwc->regs, DWC3_GSBUSCFG1) | 0xf00);
+
+	/* Enable snooping */
+	dwc3_writel(dwc->regs, DWC3_GSBUSCFG0,
+		    dwc3_readl(dwc->regs, DWC3_GSBUSCFG0) | 0x22220000);
+#endif
+
 	if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
 		dwc->dr_mode = USB_DR_MODE_HOST;
 	else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
Signature · 1 line
1.9.1
#5 lore raw

PATCH 2/3 armv8/fsl-layerscape: add dwc3 gadget driver support

arch/arm/cpu/armv8/fsl-layerscape/soc.c

Quoted 18 lines · Rajat Srivastava

From: Rajesh Bhagat <[email protected]>

Implements the dwc3 gadget driver support for LS1043 platform, and performs below operations:
1. Enables snooping support for DWC3 controller.
2. Enables cache coherency in LS1043 platform.

---
 arch/arm/cpu/armv8/fsl-layerscape/soc.c            | 87 +++++++++++++++++++++-
 .../include/asm/arch-fsl-layerscape/immap_lsch2.h  |  6 ++
 .../include/asm/arch-fsl-layerscape/sys_proto.h    | 11 +++
 drivers/usb/dwc3/core.c                            | 12 +++
 4 files changed, 114 insertions(+), 2 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-fsl-layerscape/sys_proto.h
arch/arm/cpu/armv8/fsl-layerscape/soc.c +0 -0

Don't mix platform code with driver code, split this patch.

Quoted 151 lines

index 0fb5c7f..84b973d 100644

arch/arm/cpu/armv8/fsl-layerscape/soc.c +85 -2
@@ -17,6 +17,10 @@
 #ifdef CONFIG_CHAIN_OF_TRUST
 #include <fsl_validate.h>
 #endif
+#include <usb.h>
+#include <dwc3-uboot.h>
+#include <linux/usb/xhci-fsl.h>
+
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -318,9 +322,12 @@ void fsl_lsch2_early_init_f(void)
 #if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
 	out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
 #endif
-	/* Make SEC reads and writes snoopable */
+	/* Make SEC and USB reads and writes snoopable */
 	setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
-		     SCFG_SNPCNFGCR_SECWRSNP);
+		     SCFG_SNPCNFGCR_SECWRSNP | SCFG_SNPCNFGCR_USB1RDSNP |
+		     SCFG_SNPCNFGCR_USB1WRSNP | SCFG_SNPCNFGCR_USB2RDSNP |
+		     SCFG_SNPCNFGCR_USB2WRSNP | SCFG_SNPCNFGCR_USB3RDSNP |
+		     SCFG_SNPCNFGCR_USB3WRSNP);
 
 	/*
 	 * Enable snoop requests and DVM message requests for
@@ -336,6 +343,82 @@ void fsl_lsch2_early_init_f(void)
 }
 #endif
 
+#ifdef CONFIG_USB_DWC3
+
+#if defined(CONFIG_LS1043A)
+static struct dwc3_device dwc3_device_data0 = {
+	.maximum_speed = USB_SPEED_HIGH,
+	.base = CONFIG_SYS_FSL_XHCI_USB1_ADDR,
+	.dr_mode = USB_DR_MODE_PERIPHERAL,
+	.index = 0,
+};
+
+static struct dwc3_device dwc3_device_data1 = {
+	.maximum_speed = USB_SPEED_HIGH,
+	.base = CONFIG_SYS_FSL_XHCI_USB2_ADDR,
+	.dr_mode = USB_DR_MODE_PERIPHERAL,
+	.index = 1,
+};
+
+static struct dwc3_device dwc3_device_data2 = {
+	.maximum_speed = USB_SPEED_HIGH,
+	.base = CONFIG_SYS_FSL_XHCI_USB3_ADDR,
+	.dr_mode = USB_DR_MODE_PERIPHERAL,
+	.index = 2,
+};
+
+int usb_gadget_handle_interrupts(int index)
+{
+	dwc3_uboot_handle_interrupt(index);
+	return 0;
+}
+#endif
+
+int board_usb_init(int index, enum usb_init_type init)
+{
+	switch (init) {
+	case USB_INIT_DEVICE:
+		switch (index) {
+#if defined(CONFIG_LS1043A)
+		case 0:
+			dwc3_uboot_init(&dwc3_device_data0);
+			break;
+
+		case 1:
+			dwc3_uboot_init(&dwc3_device_data1);
+			break;
+		case 2:
+			dwc3_uboot_init(&dwc3_device_data2);
+			break;
+#endif
+		default:
+			printf("Invalid Controller Index\n");
+			return -1;
+		}
+		break;
+	default:
+		break;
+	}
+	return 0;
+}
+
+int board_usb_cleanup(int index, enum usb_init_type init)
+{
+	switch (init) {
+	case USB_INIT_DEVICE:
+#if defined(CONFIG_LS1043A)
+		dwc3_uboot_exit(index);
+#endif
+		break;
+	default:
+		break;
+	}
+	return 0;
+}
+#endif
+
+
+
 #ifdef CONFIG_BOARD_LATE_INIT
 int board_late_init(void)
 {
arch/arm/include/asm/arch-fsl-layerscape/immap_lsch2.h +6 -0
index 57b99d4..13ba1a6 100644
@@ -328,6 +328,12 @@ struct ccsr_gur {
 
 #define SCFG_SNPCNFGCR_SECRDSNP		0x80000000
 #define SCFG_SNPCNFGCR_SECWRSNP		0x40000000
+#define SCFG_SNPCNFGCR_USB1RDSNP	0x00200000
+#define SCFG_SNPCNFGCR_USB1WRSNP	0x00100000
+#define SCFG_SNPCNFGCR_USB2RDSNP	0x00008000
+#define SCFG_SNPCNFGCR_USB2WRSNP	0x00010000
+#define SCFG_SNPCNFGCR_USB3RDSNP	0x00002000
+#define SCFG_SNPCNFGCR_USB3WRSNP	0x00004000
 
 /* Supplemental Configuration Unit */
 struct ccsr_scfg {
arch/arm/include/asm/arch-fsl-layerscape/sys_proto.h new file +11 -0
new file mode 100644
index 0000000..252c676
@@ -0,0 +1,11 @@
+/*
+ * Copyright 2016 Freescale Semiconductor
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef _ASM_ARMV8_FSL_LAYERSCAPE_SYS_PROTO_H_
+#define _ASM_ARMV8_FSL_LAYERSCAPE_SYS_PROTO_H_
+
+
+#endif /* _ASM_ARMV8_FSL_LAYERSCAPE_SYS_PROTO_H_ */
drivers/usb/dwc3/core.c +0 -0
index 85cc96a..5eeb71d 100644

drivers/usb/dwc3/core.c int dwc3_uboot_init(struct dwc3_device *dwc3_dev) · line 693

Quoted 4 lines
drivers/usb/dwc3/core.c +1 -0
@@ -690,6 +690,18 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
 		return -ENOMEM;
 	}
 
+#if defined(CONFIG_LS1043A)

How was this added in Linux ? I doubt such horrid ifdef was allowed. I presume it went through either DT or struct dwc3_device, right ? So fix this here the same way.

Quoted 15 lines
drivers/usb/dwc3/core.c +11 -0
+	 /* Change burst beat and outstanding pipelined transfers requests */
+	dwc3_writel(dwc->regs, DWC3_GSBUSCFG0,
+		    (dwc3_readl(dwc->regs, DWC3_GSBUSCFG0) & ~0xff) | 0xf);
+	dwc3_writel(dwc->regs, DWC3_GSBUSCFG1,
+		    dwc3_readl(dwc->regs, DWC3_GSBUSCFG1) | 0xf00);
+
+	/* Enable snooping */
+	dwc3_writel(dwc->regs, DWC3_GSBUSCFG0,
+		    dwc3_readl(dwc->regs, DWC3_GSBUSCFG0) | 0x22220000);
+#endif
+
 	if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
 		dwc->dr_mode = USB_DR_MODE_HOST;
 	else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
Signature · 2 lines
Best regards,
Marek Vasut
#6 lore raw

PATCH 2/3 armv8/fsl-layerscape: add dwc3 gadget driver support

Hi,

Quoted 8 lines · Marek Vasut
Quoted 8 lines
drivers/usb/dwc3/core.c +0 -0
index 85cc96a..5eeb71d 100644
@@ -690,6 +690,18 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
 		return -ENOMEM;
 	}
 
Quoted 5 lines

drivers/usb/dwc3/core.c int dwc3_uboot_init(struct dwc3_device *dwc3_dev) · line 693

Quoted 1 line
drivers/usb/dwc3/core.c +1 -0
+#if defined(CONFIG_LS1043A)

How was this added in Linux ? I doubt such horrid ifdef was allowed. I presume it went through either DT or struct dwc3_device, right ? So fix this here the same way.

dwc3 doesn't have any of that. I wouldn't take it :-p

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160531/e0838818/attachment.sig>
#7 lore raw

PATCH 2/3 armv8/fsl-layerscape: add dwc3 gadget driver support

Quoted 25 lines

-----Original Message-----
From: Felipe Balbi [mailto:felipe.balbi at linux.intel.com]
Sent: Tuesday, May 31, 2016 5:40 PM
To: Marek Vasut <[email protected]>; Rajat Srivastava <[email protected]>; u-boot at lists.denx.de
Cc: l.majewski at samsung.com; sjg at chromium.org; albert.u.boot at aribaud.net; prabhakar at freescale.com; york sun <[email protected]>; Mingkai Hu <[email protected]>; Rajesh Bhagat <[email protected]>; michal.simek at xilinx.com
Subject: Re: [PATCH 2/3] armv8/fsl-layerscape: add dwc3 gadget driver support

Hi,

Quoted 8 lines · Marek Vasut
Quoted 8 lines
drivers/usb/dwc3/core.c index renamed from drivers/usb/dwc3/core.c +0 -0

85cc96a..5eeb71d 100644

drivers/usb/dwc3/core.c +0 -0
@@ -690,6 +690,18 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
 		return -ENOMEM;
 	}
 
Quoted 8 lines
Quoted 5 lines

drivers/usb/dwc3/core.c int dwc3_uboot_init(struct dwc3_device *dwc3_dev) · line 693

Quoted 1 line
drivers/usb/dwc3/core.c +1 -0
+#if defined(CONFIG_LS1043A)

How was this added in Linux ? I doubt such horrid ifdef was allowed. I presume it went through either DT or struct dwc3_device, right ? So fix this here the same way.

dwc3 doesn't have any of that. I wouldn't take it :-p

Hello Felipe/Marek,

It is not currently added in Linux, These registers setting is required for Setting the burst beat transactions and enabling the snooping for DWC3 USB IP.

Can it be added using dwc3 uboot glue layer e.g. dwc3-fsl.c ?

Best Regards,
Rajesh Bhagat

Quoted 2 lines

--
balbi

#8 lore raw

PATCH 2/3 armv8/fsl-layerscape: add dwc3 gadget driver support

Hi,

Quoted 15 lines · Rajesh Bhagat
Quoted 15 lines
Quoted 13 lines · Marek Vasut

drivers/usb/dwc3/core.c int dwc3_uboot_init(struct dwc3_device *dwc3_dev) · line 693

Quoted 9 lines
drivers/usb/dwc3/core.c index renamed from drivers/usb/dwc3/core.c +0 -0

85cc96a..5eeb71d 100644

drivers/usb/dwc3/core.c +1 -0
@@ -690,6 +690,18 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
 		return -ENOMEM;
 	}
 
+#if defined(CONFIG_LS1043A)

How was this added in Linux ? I doubt such horrid ifdef was allowed. I presume it went through either DT or struct dwc3_device, right ? So fix this here the same way.

Quoted 7 lines
Quoted 2 lines

dwc3 doesn't have any of that. I wouldn't take it :-p

Hello Felipe/Marek,

It is not currently added in Linux, These registers setting is required for Setting the burst beat transactions and enabling the snooping for DWC3 USB IP.

that's fine, but you don't need to ifdef around that. Pass these values from your platform code.

Quoted 1 line

Can it be added using dwc3 uboot glue layer e.g. dwc3-fsl.c ?

keep in core, but pass them from plat code instead of hardcoding under ifdef.

Also, get rid of the magic constant ;-)

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160601/53441d1c/attachment.sig>
#9 lore raw

PATCH 2/3 armv8/fsl-layerscape: add dwc3 gadget driver support

Quoted 40 lines

-----Original Message-----
From: Felipe Balbi [mailto:felipe.balbi at linux.intel.com]
Sent: Wednesday, June 01, 2016 12:07 PM
To: Rajesh Bhagat <[email protected]>; Marek Vasut <[email protected]>; Rajat Srivastava <[email protected]>; u-boot at lists.denx.de
Cc: l.majewski at samsung.com; sjg at chromium.org; albert.u.boot at aribaud.net; prabhakar at freescale.com; york sun <[email protected]>; Mingkai Hu <[email protected]>; michal.simek at xilinx.com
Subject: RE: [PATCH 2/3] armv8/fsl-layerscape: add dwc3 gadget driver support

Hi,

Quoted 15 lines · Rajesh Bhagat
Quoted 15 lines
Quoted 13 lines · Marek Vasut

drivers/usb/dwc3/core.c int dwc3_uboot_init(struct dwc3_device *dwc3_dev) · line 693

Quoted 9 lines
drivers/usb/dwc3/core.c +1 -0
index 85cc96a..5eeb71d 100644
@@ -690,6 +690,18 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
 		return -ENOMEM;
 	}
 
+#if defined(CONFIG_LS1043A)

How was this added in Linux ? I doubt such horrid ifdef was allowed. I presume it went through either DT or struct dwc3_device, right ? So fix this here the same way.

Quoted 7 lines
Quoted 2 lines

dwc3 doesn't have any of that. I wouldn't take it :-p

Hello Felipe/Marek,

It is not currently added in Linux, These registers setting is required for Setting the burst beat transactions and enabling the snooping for DWC3

USB IP.

Quoted 9 lines

that's fine, but you don't need to ifdef around that. Pass these values from your platform code.

Quoted 1 line

Can it be added using dwc3 uboot glue layer e.g. dwc3-fsl.c ?

keep in core, but pass them from plat code instead of hardcoding under ifdef.

Also, get rid of the magic constant ;-)

Ok, thanks. Will take care in v2.

Quoted 2 lines

--
balbi

#10 lore raw

PATCH 2/3 armv8/fsl-layerscape: add dwc3 gadget driver support

In reply to Rajat Srivastava

Hi Rajat,

Quoted 189 lines

From: Rajesh Bhagat <[email protected]>

Implements the dwc3 gadget driver support for LS1043 platform, and performs below operations:
1. Enables snooping support for DWC3 controller.
2. Enables cache coherency in LS1043 platform.

---
 arch/arm/cpu/armv8/fsl-layerscape/soc.c            | 87
+++++++++++++++++++++- .../include/asm/arch-fsl-layerscape/immap_lsch2.h
|  6 ++ .../include/asm/arch-fsl-layerscape/sys_proto.h    | 11 +++
 drivers/usb/dwc3/core.c                            | 12 +++
 4 files changed, 114 insertions(+), 2 deletions(-)
 create mode 100644

arch/arm/include/asm/arch-fsl-layerscape/sys_proto.h

(quoted diff) +0 -0

b/arch/arm/cpu/armv8/fsl-layerscape/soc.c index 0fb5c7f..84b973d 100644 --- a/arch/arm/cpu/armv8/fsl-layerscape/soc.c +++ b/arch/arm/cpu/armv8/fsl-layerscape/soc.c

arch/arm/cpu/armv8/fsl-layerscape/soc.c +6 -2
@@ -17,6 +17,10 @@
 #ifdef CONFIG_CHAIN_OF_TRUST
 #include <fsl_validate.h>
 #endif
+#include <usb.h>
+#include <dwc3-uboot.h>
+#include <linux/usb/xhci-fsl.h>
+
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -318,9 +322,12 @@ void fsl_lsch2_early_init_f(void)
 #if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
 	out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
 #endif
-	/* Make SEC reads and writes snoopable */
+	/* Make SEC and USB reads and writes snoopable */
 	setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
-		     SCFG_SNPCNFGCR_SECWRSNP);
+		     SCFG_SNPCNFGCR_SECWRSNP |

SCFG_SNPCNFGCR_USB1RDSNP |

(quoted diff) +1 -0
+		     SCFG_SNPCNFGCR_USB1WRSNP |

SCFG_SNPCNFGCR_USB2RDSNP |

(quoted diff) +1 -0
+		     SCFG_SNPCNFGCR_USB2WRSNP |

SCFG_SNPCNFGCR_USB3RDSNP |

arch/arm/cpu/armv8/fsl-layerscape/soc.c +77 -0
+		     SCFG_SNPCNFGCR_USB3WRSNP);
 
 	/*
 	 * Enable snoop requests and DVM message requests for
@@ -336,6 +343,82 @@ void fsl_lsch2_early_init_f(void)
 }
 #endif
 
+#ifdef CONFIG_USB_DWC3
+
+#if defined(CONFIG_LS1043A)
+static struct dwc3_device dwc3_device_data0 = {
+	.maximum_speed = USB_SPEED_HIGH,
+	.base = CONFIG_SYS_FSL_XHCI_USB1_ADDR,
+	.dr_mode = USB_DR_MODE_PERIPHERAL,
+	.index = 0,
+};
+
+static struct dwc3_device dwc3_device_data1 = {
+	.maximum_speed = USB_SPEED_HIGH,
+	.base = CONFIG_SYS_FSL_XHCI_USB2_ADDR,
+	.dr_mode = USB_DR_MODE_PERIPHERAL,
+	.index = 1,
+};
+
+static struct dwc3_device dwc3_device_data2 = {
+	.maximum_speed = USB_SPEED_HIGH,
+	.base = CONFIG_SYS_FSL_XHCI_USB3_ADDR,
+	.dr_mode = USB_DR_MODE_PERIPHERAL,
+	.index = 2,
+};
+
+int usb_gadget_handle_interrupts(int index)
+{
+	dwc3_uboot_handle_interrupt(index);
+	return 0;
+}
+#endif
+
+int board_usb_init(int index, enum usb_init_type init)
+{
+	switch (init) {
+	case USB_INIT_DEVICE:
+		switch (index) {
+#if defined(CONFIG_LS1043A)
+		case 0:
+			dwc3_uboot_init(&dwc3_device_data0);
+			break;
+
+		case 1:
+			dwc3_uboot_init(&dwc3_device_data1);
+			break;
+		case 2:
+			dwc3_uboot_init(&dwc3_device_data2);
+			break;
+#endif
+		default:
+			printf("Invalid Controller Index\n");
+			return -1;
+		}
+		break;
+	default:
+		break;
+	}
+	return 0;
+}
+
+int board_usb_cleanup(int index, enum usb_init_type init)
+{
+	switch (init) {
+	case USB_INIT_DEVICE:
+#if defined(CONFIG_LS1043A)
+		dwc3_uboot_exit(index);
+#endif
+		break;
+	default:
+		break;
+	}
+	return 0;
+}
+#endif
+
+
+
 #ifdef CONFIG_BOARD_LATE_INIT
 int board_late_init(void)
 {
(quoted diff) +0 -0

b/arch/arm/include/asm/arch-fsl-layerscape/immap_lsch2.h index 57b99d4..13ba1a6 100644 --- a/arch/arm/include/asm/arch-fsl-layerscape/immap_lsch2.h +++ b/arch/arm/include/asm/arch-fsl-layerscape/immap_lsch2.h @@ -328,6 +328,12 @@ struct ccsr_gur {
#define SCFG_SNPCNFGCR_SECRDSNP 0x80000000
#define SCFG_SNPCNFGCR_SECWRSNP 0x40000000

arch/arm/include/asm/arch-fsl-layerscape/immap_lsch2.h +6 -0
+#define SCFG_SNPCNFGCR_USB1RDSNP	0x00200000
+#define SCFG_SNPCNFGCR_USB1WRSNP	0x00100000
+#define SCFG_SNPCNFGCR_USB2RDSNP	0x00008000
+#define SCFG_SNPCNFGCR_USB2WRSNP	0x00010000
+#define SCFG_SNPCNFGCR_USB3RDSNP	0x00002000
+#define SCFG_SNPCNFGCR_USB3WRSNP	0x00004000
 
 /* Supplemental Configuration Unit */
 struct ccsr_scfg {
(quoted diff) +0 -0

b/arch/arm/include/asm/arch-fsl-layerscape/sys_proto.h new file mode 100644 index 0000000..252c676

arch/arm/include/asm/arch-fsl-layerscape/sys_proto.h new file +11 -0
@@ -0,0 +1,11 @@
+/*
+ * Copyright 2016 Freescale Semiconductor
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef _ASM_ARMV8_FSL_LAYERSCAPE_SYS_PROTO_H_
+#define _ASM_ARMV8_FSL_LAYERSCAPE_SYS_PROTO_H_
+
+
+#endif /* _ASM_ARMV8_FSL_LAYERSCAPE_SYS_PROTO_H_ */
drivers/usb/dwc3/core.c +2 -0
index 85cc96a..5eeb71d 100644
@@ -690,6 +690,18 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
 		return -ENOMEM;
 	}
 
+#if defined(CONFIG_LS1043A)
+	 /* Change burst beat and outstanding pipelined transfers

requests */

drivers/usb/dwc3/core.c +2 -0
+	dwc3_writel(dwc->regs, DWC3_GSBUSCFG0,
+		    (dwc3_readl(dwc->regs, DWC3_GSBUSCFG0) & ~0xff)

| 0xf);

drivers/usb/dwc3/core.c +6 -0
+	dwc3_writel(dwc->regs, DWC3_GSBUSCFG1,
+		    dwc3_readl(dwc->regs, DWC3_GSBUSCFG1) | 0xf00);
+
+	/* Enable snooping */
+	dwc3_writel(dwc->regs, DWC3_GSBUSCFG0,
+		    dwc3_readl(dwc->regs, DWC3_GSBUSCFG0) |

0x22220000); +#endif

drivers/usb/dwc3/core.c int dwc3_uboot_init(struct dwc3_device *dwc3_dev) · line 707

Quoted 4 lines
drivers/usb/dwc3/core.c +1 -0
+
 	if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
 		dwc->dr_mode = USB_DR_MODE_HOST;
 	else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
Signature · 5 lines
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group
#11 lore raw

PATCH 3/3 armv8/fsl-layerscape: enable dwc3 gadget driver support

In reply to Rajat Srivastava

From: Rajesh Bhagat <[email protected]>

Enables dwc3 gadget driver support on LS1043QDS platform.

---
 include/configs/ls1043aqds.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
include/configs/ls1043aqds.h +15 -0
index af1f73d..8c99641 100644
@@ -394,6 +394,21 @@ unsigned long get_board_ddr_clk(void);
 #define CONFIG_USB_MAX_CONTROLLER_COUNT		3
 #define CONFIG_SYS_USB_XHCI_MAX_ROOT_PORTS	2
 #define CONFIG_USB_STORAGE
+
+#define CONFIG_USB_DWC3
+#define CONFIG_USB_DWC3_GADGET
+
+#define CONFIG_USB_GADGET
+#define CONFIG_USB_FUNCTION_MASS_STORAGE
+#define CONFIG_USB_GADGET_DOWNLOAD
+#define CONFIG_USB_GADGET_VBUS_DRAW 2
+#define CONFIG_G_DNL_MANUFACTURER "NXP Semiconductor"
+#define CONFIG_G_DNL_VENDOR_NUM 0x0471
+#define CONFIG_G_DNL_PRODUCT_NUM 0x1234
+#define CONFIG_USB_GADGET_DUALSPEED
+
+/* USB Gadget ums command */
+#define CONFIG_CMD_USB_MASS_STORAGE
 #endif
 
 /*
Signature · 1 line
1.9.1