Skip to contentSkip to conversation

usb: add isp1760 hcd support

PATCH New Rui Miguel Silva 1 participant 4 messages Jun 29, 2022

Subsystems (3)
lore
Share & tools
lore

Rui Miguel Silva

author maintainer
#0 lore raw

v5 cover usb: add isp1760 hcd support

Add support for the usb isp1760 host controller family, which for example is present in MPS3 FPGA board from Arm (isp1763).

First we move some helper functions and defines to a more common place to be shared by several urb users. (patch 1/3)

Then add the driver itself, is a ported version of the kernel actual driver, which I am also the maintainer. (patch 2/3)

And last, enable it for the corstone1000 platform that uses that MPS3 board for its implementation (patch 3/3).

Cheers,
Rui

v4[4] -> v5:
Marek:
- fix makefile to include the common urb code for the musb_host, musb_gadget and r8a66597 drivers
v3 -> v4:
- rebase on top of next and resend with Marek in --to

v2[3] -> v3:
- when you think you have amend commit and fix stay uncommitted.
s/[HC_FIELD_MAX] = {};/[HC_FIELD_MAX] = {},/
v1[0] -> v2:
- gentle ping
- merge fix from kernel upstream [1]

PS: This should go on top of the corstone1000 platform enable series [2]

0: https://lore.kernel.org/u-boot/[email protected]/
1: https://lore.kernel.org/linux-usb/[email protected]/
2: https://lore.kernel.org/u-boot/[email protected]/T/#t
3: https://lore.kernel.org/u-boot/[email protected]/
4: https://lore.kernel.org/u-boot/[email protected]/T/#t

Rui Miguel Silva (3):
usb: common: move urb code to common
usb: add isp1760 family driver
corstone1000: enable isp1763 usb controller and mmc

 Makefile                                      |    1 +
 configs/corstone1000_defconfig                |    3 +
 drivers/usb/Kconfig                           |    2 +
 drivers/usb/common/Makefile                   |    4 +
 drivers/usb/common/usb_urb.c                  |  160 ++
 drivers/usb/host/r8a66597-hcd.c               |   30 +-
 drivers/usb/isp1760/Kconfig                   |   12 +
 drivers/usb/isp1760/Makefile                  |    6 +
 drivers/usb/isp1760/isp1760-core.c            |  380 +++
 drivers/usb/isp1760/isp1760-core.h            |   96 +
 drivers/usb/isp1760/isp1760-hcd.c             | 2477 +++++++++++++++++
 drivers/usb/isp1760/isp1760-hcd.h             |   81 +
 drivers/usb/isp1760/isp1760-if.c              |  125 +
 drivers/usb/isp1760/isp1760-regs.h            |  292 ++
 drivers/usb/isp1760/isp1760-uboot.c           |   75 +
 drivers/usb/isp1760/isp1760-uboot.h           |   27 +
 drivers/usb/musb-new/musb_core.c              |    2 +-
 drivers/usb/musb-new/musb_host.c              |    2 +-
 drivers/usb/musb-new/musb_host.h              |    2 +-
 drivers/usb/musb-new/musb_uboot.c             |   38 +-
 drivers/usb/musb-new/musb_uboot.h             |    2 +-
 include/configs/corstone1000.h                |    6 +
 .../linux/usb/usb_urb_compat.h                |   47 +-
 include/usb_defs.h                            |   32 +
 24 files changed, 3826 insertions(+), 76 deletions(-)
 create mode 100644 drivers/usb/common/usb_urb.c
 create mode 100644 drivers/usb/isp1760/Kconfig
 create mode 100644 drivers/usb/isp1760/Makefile
 create mode 100644 drivers/usb/isp1760/isp1760-core.c
 create mode 100644 drivers/usb/isp1760/isp1760-core.h
 create mode 100644 drivers/usb/isp1760/isp1760-hcd.c
 create mode 100644 drivers/usb/isp1760/isp1760-hcd.h
 create mode 100644 drivers/usb/isp1760/isp1760-if.c
 create mode 100644 drivers/usb/isp1760/isp1760-regs.h
 create mode 100644 drivers/usb/isp1760/isp1760-uboot.c
 create mode 100644 drivers/usb/isp1760/isp1760-uboot.h
 rename drivers/usb/musb-new/usb-compat.h => include/linux/usb/usb_urb_compat.h (59%)
Signature · 1 line
2.37.0
author maintainer
#1 lore raw

PATCH v5 1/3 usb: common: move urb code to common

Move urb code from musb only use to a more common scope, so other drivers in the future can use the handling of urb in usb.

---
 drivers/usb/common/Makefile                   |   3 +
 drivers/usb/common/usb_urb.c                  | 160 ++++++++++++++++++
 drivers/usb/host/r8a66597-hcd.c               |  30 +---
 drivers/usb/musb-new/musb_core.c              |   2 +-
 drivers/usb/musb-new/musb_host.c              |   2 +-
 drivers/usb/musb-new/musb_host.h              |   2 +-
 drivers/usb/musb-new/musb_uboot.c             |  38 +----
 drivers/usb/musb-new/musb_uboot.h             |   2 +-
 .../linux/usb/usb_urb_compat.h                |  47 ++++-
 include/usb_defs.h                            |  32 ++++
 10 files changed, 242 insertions(+), 76 deletions(-)
 create mode 100644 drivers/usb/common/usb_urb.c
 rename drivers/usb/musb-new/usb-compat.h => include/linux/usb/usb_urb_compat.h (59%)
drivers/usb/common/Makefile +3 -0
index 3bedbf213f47..7eacc909f2d9 100644
@@ -4,5 +4,8 @@
 #
 
 obj-$(CONFIG_$(SPL_)DM_USB) += common.o
+obj-$(CONFIG_USB_MUSB_HOST) += usb_urb.o
+obj-$(CONFIG_USB_MUSB_GADGET) += usb_urb.o
+obj-$(CONFIG_USB_R8A66597_HCD) += usb_urb.o
 obj-$(CONFIG_USB_EHCI_FSL) += fsl-dt-fixup.o fsl-errata.o
 obj-$(CONFIG_USB_XHCI_FSL) += fsl-dt-fixup.o fsl-errata.o
drivers/usb/common/usb_urb.c new file +160 -0

160 lines not on this page · raw message

drivers/usb/host/r8a66597-hcd.c +1 -29
index f1fc93f3d403..3ccbc16da379 100644
@@ -14,6 +14,7 @@
 #include <dm/device_compat.h>
 #include <linux/delay.h>
 #include <linux/iopoll.h>
+#include <linux/usb/usb_urb_compat.h>
 #include <power/regulator.h>
 
 #include "r8a66597.h"
@@ -24,35 +25,6 @@
 #define R8A66597_DPRINT(...)
 #endif
 
-static inline struct usb_device *usb_dev_get_parent(struct usb_device *udev)
-{
-	struct udevice *parent = udev->dev->parent;
-
-	/*
-	 * When called from usb-uclass.c: usb_scan_device() udev->dev points
-	 * to the parent udevice, not the actual udevice belonging to the
-	 * udev as the device is not instantiated yet.
-	 *
-	 * If dev is an usb-bus, then we are called from usb_scan_device() for
-	 * an usb-device plugged directly into the root port, return NULL.
-	 */
-	if (device_get_uclass_id(udev->dev) == UCLASS_USB)
-		return NULL;
-
-	/*
-	 * If these 2 are not the same we are being called from
-	 * usb_scan_device() and udev itself is the parent.
-	 */
-	if (dev_get_parent_priv(udev->dev) != udev)
-		return udev;
-
-	/* We are being called normally, use the parent pointer */
-	if (device_get_uclass_id(parent) == UCLASS_USB_HUB)
-		return dev_get_parent_priv(parent);
-
-	return NULL;
-}
-
 static void get_hub_data(struct usb_device *dev, u16 *hub_devnum, u16 *hubport)
 {
 	struct usb_device *parent = usb_dev_get_parent(dev);
drivers/usb/musb-new/musb_core.c +1 -1
index 18d9bc805f8a..fc7af7484e4c 100644
@@ -89,9 +89,9 @@
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
 #include <linux/usb/musb.h>
+#include <linux/usb/usb_urb_compat.h>
 #include <asm/io.h>
 #include "linux-compat.h"
-#include "usb-compat.h"
 #endif
 
 #include "musb_core.h"
drivers/usb/musb-new/musb_host.c +1 -1
index acb2d40f3b5a..e5905d90d66f 100644
@@ -26,8 +26,8 @@
 #include <dm/device_compat.h>
 #include <usb.h>
 #include <linux/bug.h>
+#include <linux/usb/usb_urb_compat.h>
 #include "linux-compat.h"
-#include "usb-compat.h"
 #endif
 
 #include "musb_core.h"
drivers/usb/musb-new/musb_host.h +1 -1
index afc8fa35a738..5a604bdb0cf2 100644
@@ -10,7 +10,7 @@
 #ifndef _MUSB_HOST_H
 #define _MUSB_HOST_H
 #ifdef __UBOOT__
-#include "usb-compat.h"
+#include <linux/usb/usb_urb_compat.h>
 #endif
 
 static inline struct usb_hcd *musb_to_hcd(struct musb *musb)
drivers/usb/musb-new/musb_uboot.c +1 -37
index 61ff68def2fa..d186facc7e02 100644
@@ -8,10 +8,10 @@
 #include <linux/errno.h>
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
+#include <linux/usb/usb_urb_compat.h>
 
 #include <usb.h>
 #include "linux-compat.h"
-#include "usb-compat.h"
 #include "musb_core.h"
 #include "musb_host.h"
 #include "musb_gadget.h"
@@ -453,39 +453,3 @@ struct musb *musb_register(struct musb_hdrc_platform_data *plat, void *bdata,
 
 	return *musbp;
 }
-
-#if CONFIG_IS_ENABLED(DM_USB)
-struct usb_device *usb_dev_get_parent(struct usb_device *udev)
-{
-	struct udevice *parent = udev->dev->parent;
-
-	/*
-	 * When called from usb-uclass.c: usb_scan_device() udev->dev points
-	 * to the parent udevice, not the actual udevice belonging to the
-	 * udev as the device is not instantiated yet.
-	 *
-	 * If dev is an usb-bus, then we are called from usb_scan_device() for
-	 * an usb-device plugged directly into the root port, return NULL.
-	 */
-	if (device_get_uclass_id(udev->dev) == UCLASS_USB)
-		return NULL;
-
-	/*
-	 * If these 2 are not the same we are being called from
-	 * usb_scan_device() and udev itself is the parent.
-	 */
-	if (dev_get_parent_priv(udev->dev) != udev)
-		return udev;
-
-	/* We are being called normally, use the parent pointer */
-	if (device_get_uclass_id(parent) == UCLASS_USB_HUB)
-		return dev_get_parent_priv(parent);
-
-	return NULL;
-}
-#else
-struct usb_device *usb_dev_get_parent(struct usb_device *udev)
-{
-	return udev->parent;
-}
-#endif
drivers/usb/musb-new/musb_uboot.h +1 -1
index 18282efccc9d..6b162f03b19e 100644
@@ -8,8 +8,8 @@
 #define __MUSB_UBOOT_H__
 
 #include <usb.h>
+#include <linux/usb/usb_urb_compat.h>
 #include "linux-compat.h"
-#include "usb-compat.h"
 #include "musb_core.h"
 
 struct musb_host_data {
include/linux/usb/usb_urb_compat.h renamed from drivers/usb/musb-new/usb-compat.h +41 -6

69 lines not on this page · raw message

include/usb_defs.h +32 -0
index 6dd2c997f9b3..ec00161710a5 100644
@@ -81,6 +81,32 @@
 #define EndpointOutRequest \
 	((USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_INTERFACE) << 8)
 
+/* class requests from the USB 2.0 hub spec, table 11-15 */
+#define HUB_CLASS_REQ(dir, type, request) ((((dir) | (type)) << 8) | (request))
+/* GetBusState and SetHubDescriptor are optional, omitted */
+#define ClearHubFeature		HUB_CLASS_REQ(USB_DIR_OUT, USB_RT_HUB, \
+					      USB_REQ_CLEAR_FEATURE)
+#define ClearPortFeature	HUB_CLASS_REQ(USB_DIR_OUT, USB_RT_PORT, \
+					      USB_REQ_CLEAR_FEATURE)
+#define GetHubDescriptor	HUB_CLASS_REQ(USB_DIR_IN, USB_RT_HUB, \
+					      USB_REQ_GET_DESCRIPTOR)
+#define GetHubStatus		HUB_CLASS_REQ(USB_DIR_IN, USB_RT_HUB, \
+					      USB_REQ_GET_STATUS)
+#define GetPortStatus		HUB_CLASS_REQ(USB_DIR_IN, USB_RT_PORT, \
+					      USB_REQ_GET_STATUS)
+#define SetHubFeature		HUB_CLASS_REQ(USB_DIR_OUT, USB_RT_HUB, \
+					      USB_REQ_SET_FEATURE)
+#define SetPortFeature		HUB_CLASS_REQ(USB_DIR_OUT, USB_RT_PORT, \
+					      USB_REQ_SET_FEATURE)
+#define ClearTTBuffer		HUB_CLASS_REQ(USB_DIR_OUT, USB_RT_PORT, \
+					      HUB_CLEAR_TT_BUFFER)
+#define ResetTT			HUB_CLASS_REQ(USB_DIR_OUT, USB_RT_PORT, \
+					      HUB_RESET_TT)
+#define GetTTState		HUB_CLASS_REQ(USB_DIR_IN, USB_RT_PORT, \
+					      HUB_GET_TT_STATE)
+#define StopTT			HUB_CLASS_REQ(USB_DIR_OUT, USB_RT_PORT, \
+					      HUB_STOP_TT)
+
 /* Descriptor types */
 #define USB_DT_DEVICE        0x01
 #define USB_DT_CONFIG        0x02
@@ -289,10 +315,16 @@
 #define USB_SS_PORT_STAT_C_CONFIG_ERROR	0x0080
 
 /* wHubCharacteristics (masks) */
+#define HUB_CHAR_COMMON_OCPM        0x0000 /* All ports Over-Current reporting */
+#define HUB_CHAR_INDV_PORT_LPSM     0x0001 /* per-port power control */
+#define HUB_CHAR_NO_LPSM            0x0002 /* no power switching */
 #define HUB_CHAR_LPSM               0x0003
 #define HUB_CHAR_COMPOUND           0x0004
+#define HUB_CHAR_INDV_PORT_OCPM     0x0008 /* per-port Over-current reporting */
+#define HUB_CHAR_NO_OCPM            0x0010 /* No Over-current Protection support */
 #define HUB_CHAR_OCPM               0x0018
 #define HUB_CHAR_TTTT               0x0060 /* TT Think Time mask */
+#define HUB_CHAR_PORTIND            0x0080 /* per-port indicators (LEDs) */
 
 /*
  * Hub Status & Hub Change bit masks
Signature · 1 line
2.37.0
author maintainer
#2 lore raw

PATCH v5 2/3 usb: add isp1760 family driver

In reply to Rui Miguel Silva

ISP1760/61/63 are a family of usb controllers, here the main goal is to support the ISP1763 hcd part found in the MPS3 FPGA board form Arm. This is based on the kernel driver and ported to u-boot.

---
 Makefile                            |    1 +
 drivers/usb/Kconfig                 |    2 +
 drivers/usb/common/Makefile         |    1 +
 drivers/usb/isp1760/Kconfig         |   12 +
 drivers/usb/isp1760/Makefile        |    6 +
 drivers/usb/isp1760/isp1760-core.c  |  380 ++++
 drivers/usb/isp1760/isp1760-core.h  |   96 ++
 drivers/usb/isp1760/isp1760-hcd.c   | 2477 +++++++++++++++++++++++++++
 drivers/usb/isp1760/isp1760-hcd.h   |   81 +
 drivers/usb/isp1760/isp1760-if.c    |  125 ++
 drivers/usb/isp1760/isp1760-regs.h  |  292 ++++
 drivers/usb/isp1760/isp1760-uboot.c |   75 +
 drivers/usb/isp1760/isp1760-uboot.h |   27 +
 13 files changed, 3575 insertions(+)
 create mode 100644 drivers/usb/isp1760/Kconfig
 create mode 100644 drivers/usb/isp1760/Makefile
 create mode 100644 drivers/usb/isp1760/isp1760-core.c
 create mode 100644 drivers/usb/isp1760/isp1760-core.h
 create mode 100644 drivers/usb/isp1760/isp1760-hcd.c
 create mode 100644 drivers/usb/isp1760/isp1760-hcd.h
 create mode 100644 drivers/usb/isp1760/isp1760-if.c
 create mode 100644 drivers/usb/isp1760/isp1760-regs.h
 create mode 100644 drivers/usb/isp1760/isp1760-uboot.c
 create mode 100644 drivers/usb/isp1760/isp1760-uboot.h
Makefile +1 -0
index 9575d43683a2..9c13c8a79f1d 100644
@@ -841,6 +841,7 @@ libs-y += drivers/usb/host/
 libs-y += drivers/usb/mtu3/
 libs-y += drivers/usb/musb/
 libs-y += drivers/usb/musb-new/
+libs-y += drivers/usb/isp1760/
 libs-y += drivers/usb/phy/
 libs-y += drivers/usb/ulpi/
 ifdef CONFIG_POST
drivers/usb/Kconfig +2 -0
index ab1d061bd0d5..86804166de3e 100644
@@ -68,6 +68,8 @@ config SPL_DM_USB_GADGET
 
 source "drivers/usb/host/Kconfig"
 
+source "drivers/usb/isp1760/Kconfig"
+
 source "drivers/usb/cdns3/Kconfig"
 
 source "drivers/usb/dwc3/Kconfig"
drivers/usb/common/Makefile +1 -0
index 7eacc909f2d9..2e9353b76a6e 100644
@@ -4,6 +4,7 @@
 #
 
 obj-$(CONFIG_$(SPL_)DM_USB) += common.o
+obj-$(CONFIG_USB_ISP1760) += usb_urb.o
 obj-$(CONFIG_USB_MUSB_HOST) += usb_urb.o
 obj-$(CONFIG_USB_MUSB_GADGET) += usb_urb.o
 obj-$(CONFIG_USB_R8A66597_HCD) += usb_urb.o
drivers/usb/isp1760/Kconfig new file +12 -0
new file mode 100644
index 000000000000..993d71e74cd2
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config USB_ISP1760
+	tristate "NXP ISP 1760/1761/1763 support"
+	select DM_USB
+	select USB_HOST
+	help
+	  Say Y or M here if your system as an ISP1760/1761/1763 USB host
+	  controller.
+
+	  This USB controller is usually attached to a non-DMA-Master
+	  capable bus.
drivers/usb/isp1760/Makefile new file +6 -0
new file mode 100644
index 000000000000..2c809c01b118
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+isp1760-y := isp1760-core.o isp1760-if.o isp1760-uboot.o isp1760-hcd.o
+
+#isp1760-hcd.o
+
+obj-$(CONFIG_USB_ISP1760) += isp1760.o
drivers/usb/isp1760/isp1760-core.c new file +380 -0

380 lines not on this page · raw message

drivers/usb/isp1760/isp1760-core.h new file +96 -0

96 lines not on this page · raw message

drivers/usb/isp1760/isp1760-hcd.c new file +2477 -0

2,477 lines not on this page · raw message

drivers/usb/isp1760/isp1760-hcd.h new file +81 -0

7 lines not on this page · raw message

drivers/usb/isp1760/isp1760-if.c new file +125 -0

125 lines not on this page · raw message

drivers/usb/isp1760/isp1760-regs.h new file +292 -0

292 lines not on this page · raw message

drivers/usb/isp1760/isp1760-uboot.c new file +75 -0

75 lines not on this page · raw message

drivers/usb/isp1760/isp1760-uboot.h new file +27 -0
new file mode 100644
index 000000000000..812355b48bcb

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.37.0

Part of the diff is not shown here. View the raw message.

author maintainer
#3 lore raw

PATCH v5 3/3 corstone1000: enable isp1763 usb controller and mmc

In reply to Rui Miguel Silva

MPS3 board have a ISP1763 usb controller, enable it to be used for mass storage access for example. Enable the usb command also and for the FVP support for mass storage enable the mmc command.

---
 configs/corstone1000_defconfig | 3 +++
 include/configs/corstone1000.h | 6 ++++++
 2 files changed, 9 insertions(+)
configs/corstone1000_defconfig +3 -0
index 49a651aba238..dcf0a59a088c 100644
@@ -27,6 +27,8 @@ CONFIG_CMD_BOOTZ=y
 # CONFIG_CMD_XIMG is not set
 CONFIG_CMD_LOADM=y
 # CONFIG_CMD_LOADS is not set
+CONFIG_CMD_MMC=y
+CONFIG_CMD_USB=y
 # CONFIG_CMD_SETEXPR is not set
 # CONFIG_CMD_NFS is not set
 CONFIG_CMD_CACHE=y
@@ -49,4 +51,5 @@ CONFIG_DM_RTC=y
 CONFIG_RTC_EMULATION=y
 CONFIG_DM_SERIAL=y
 CONFIG_USB=y
+CONFIG_USB_ISP1760=y
 CONFIG_ERRNO_STR=y
include/configs/corstone1000.h +6 -0
index 38d7fe8d0d42..8e0230c135e3 100644
@@ -24,4 +24,10 @@
 
 #define CONFIG_SYS_SDRAM_BASE	PHYS_SDRAM_1
 
+#define BOOT_TARGET_DEVICES(func) \
+	func(USB, usb, 0)
+
+#include <config_distro_bootcmd.h>
+
+
 #endif
Signature · 1 line
2.37.0