Skip to content

Commit 54f683d

Browse files
committed
2 parents 58f3dc5 + 16aabfe commit 54f683d

29 files changed

+3874
-92
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ libs-y += drivers/usb/host/
847847
libs-y += drivers/usb/mtu3/
848848
libs-y += drivers/usb/musb/
849849
libs-y += drivers/usb/musb-new/
850+
libs-y += drivers/usb/isp1760/
850851
libs-y += drivers/usb/phy/
851852
libs-y += drivers/usb/ulpi/
852853
ifdef CONFIG_POST

arch/arm/Kconfig

-1
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,6 @@ config ARCH_KEYSTONE
810810
select CMD_POWEROFF
811811
select CPU_V7A
812812
select DDR_SPD
813-
select GPIO_EXTRA_HEADER
814813
select SUPPORT_SPL
815814
select SYS_ARCH_TIMER
816815
select SYS_THUMB_BUILD

common/spl/spl_sdp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static int spl_sdp_load_image(struct spl_image_info *spl_image,
1919

2020
usb_gadget_initialize(controller_index);
2121

22-
board_usb_init(0, USB_INIT_DEVICE);
22+
board_usb_init(controller_index, USB_INIT_DEVICE);
2323

2424
g_dnl_clear_detach();
2525
ret = g_dnl_register("usb_dnl_sdp");

common/usb_hub.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
#define HUB_SHORT_RESET_TIME 20
4848
#define HUB_LONG_RESET_TIME 200
4949

50+
#define HUB_DEBOUNCE_TIMEOUT 1000
51+
5052
#define PORT_OVERCURRENT_MAX_SCAN_COUNT 3
5153

5254
struct usb_device_scan {
@@ -208,10 +210,10 @@ static void usb_hub_power_on(struct usb_hub_device *hub)
208210
* will be done based on this value in the USB port loop in
209211
* usb_hub_configure() later.
210212
*/
211-
hub->connect_timeout = hub->query_delay + 1000;
213+
hub->connect_timeout = hub->query_delay + HUB_DEBOUNCE_TIMEOUT;
212214
debug("devnum=%d poweron: query_delay=%d connect_timeout=%d\n",
213215
dev->devnum, max(100, (int)pgood_delay),
214-
max(100, (int)pgood_delay) + 1000);
216+
max(100, (int)pgood_delay) + HUB_DEBOUNCE_TIMEOUT);
215217
}
216218

217219
#if !CONFIG_IS_ENABLED(DM_USB)

common/usb_kbd.c

+13-12
Original file line numberDiff line numberDiff line change
@@ -581,21 +581,22 @@ static int probe_usb_keyboard(struct usb_device *dev)
581581

582582
stdinname = env_get("stdin");
583583
#if CONFIG_IS_ENABLED(CONSOLE_MUX)
584-
error = iomux_doenv(stdin, stdinname);
585-
if (error)
586-
return error;
584+
if (strstr(stdinname, DEVNAME) != NULL) {
585+
error = iomux_doenv(stdin, stdinname);
586+
if (error)
587+
return error;
588+
}
587589
#else
588590
/* Check if this is the standard input device. */
589-
if (strcmp(stdinname, DEVNAME))
590-
return 1;
591-
592-
/* Reassign the console */
593-
if (overwrite_console())
594-
return 1;
591+
if (!strcmp(stdinname, DEVNAME)) {
592+
/* Reassign the console */
593+
if (overwrite_console())
594+
return 1;
595595

596-
error = console_assign(stdin, DEVNAME);
597-
if (error)
598-
return error;
596+
error = console_assign(stdin, DEVNAME);
597+
if (error)
598+
return error;
599+
}
599600
#endif
600601

601602
return 0;

configs/corstone1000_defconfig

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ CONFIG_SYS_BOOTM_LEN=0x800000
2828
# CONFIG_CMD_XIMG is not set
2929
CONFIG_CMD_LOADM=y
3030
# CONFIG_CMD_LOADS is not set
31+
CONFIG_CMD_MMC=y
32+
CONFIG_CMD_USB=y
3133
# CONFIG_CMD_SETEXPR is not set
3234
# CONFIG_CMD_NFS is not set
3335
CONFIG_CMD_CACHE=y
@@ -50,4 +52,5 @@ CONFIG_DM_RTC=y
5052
CONFIG_RTC_EMULATION=y
5153
CONFIG_DM_SERIAL=y
5254
CONFIG_USB=y
55+
CONFIG_USB_ISP1760=y
5356
CONFIG_ERRNO_STR=y

drivers/usb/Kconfig

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ config SPL_DM_USB_GADGET
6868

6969
source "drivers/usb/host/Kconfig"
7070

71+
source "drivers/usb/isp1760/Kconfig"
72+
7173
source "drivers/usb/cdns3/Kconfig"
7274

7375
source "drivers/usb/dwc3/Kconfig"

drivers/usb/common/Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44
#
55

66
obj-$(CONFIG_$(SPL_)DM_USB) += common.o
7+
obj-$(CONFIG_USB_ISP1760) += usb_urb.o
8+
obj-$(CONFIG_USB_MUSB_HOST) += usb_urb.o
9+
obj-$(CONFIG_USB_MUSB_GADGET) += usb_urb.o
10+
obj-$(CONFIG_USB_R8A66597_HCD) += usb_urb.o
711
obj-$(CONFIG_USB_EHCI_FSL) += fsl-dt-fixup.o fsl-errata.o
812
obj-$(CONFIG_USB_XHCI_FSL) += fsl-dt-fixup.o fsl-errata.o

drivers/usb/common/usb_urb.c

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Common code for usb urb handling, based on the musb-new code
4+
*
5+
* Copyright 2021 Linaro, Rui Miguel Silva <[email protected]>
6+
*
7+
*/
8+
9+
#include <dm/device.h>
10+
#include <dm/device_compat.h>
11+
#include <linux/usb/usb_urb_compat.h>
12+
13+
#include <time.h>
14+
#include <usb.h>
15+
16+
#if CONFIG_IS_ENABLED(DM_USB)
17+
struct usb_device *usb_dev_get_parent(struct usb_device *udev)
18+
{
19+
struct udevice *parent = udev->dev->parent;
20+
21+
/*
22+
* When called from usb-uclass.c: usb_scan_device() udev->dev points
23+
* to the parent udevice, not the actual udevice belonging to the
24+
* udev as the device is not instantiated yet.
25+
*
26+
* If dev is an usb-bus, then we are called from usb_scan_device() for
27+
* an usb-device plugged directly into the root port, return NULL.
28+
*/
29+
if (device_get_uclass_id(udev->dev) == UCLASS_USB)
30+
return NULL;
31+
32+
/*
33+
* If these 2 are not the same we are being called from
34+
* usb_scan_device() and udev itself is the parent.
35+
*/
36+
if (dev_get_parent_priv(udev->dev) != udev)
37+
return udev;
38+
39+
/* We are being called normally, use the parent pointer */
40+
if (device_get_uclass_id(parent) == UCLASS_USB_HUB)
41+
return dev_get_parent_priv(parent);
42+
43+
return NULL;
44+
}
45+
#else
46+
struct usb_device *usb_dev_get_parent(struct usb_device *udev)
47+
{
48+
return udev->parent;
49+
}
50+
#endif
51+
52+
static void usb_urb_complete(struct urb *urb)
53+
{
54+
urb->dev->status &= ~USB_ST_NOT_PROC;
55+
urb->dev->act_len = urb->actual_length;
56+
57+
if (urb->status == -EINPROGRESS)
58+
urb->status = 0;
59+
}
60+
61+
void usb_urb_fill(struct urb *urb, struct usb_host_endpoint *hep,
62+
struct usb_device *dev, int endpoint_type,
63+
unsigned long pipe, void *buffer, int len,
64+
struct devrequest *setup, int interval)
65+
{
66+
int epnum = usb_pipeendpoint(pipe);
67+
int is_in = usb_pipein(pipe);
68+
u16 maxpacketsize = is_in ? dev->epmaxpacketin[epnum] :
69+
dev->epmaxpacketout[epnum];
70+
71+
memset(urb, 0, sizeof(struct urb));
72+
memset(hep, 0, sizeof(struct usb_host_endpoint));
73+
INIT_LIST_HEAD(&hep->urb_list);
74+
INIT_LIST_HEAD(&urb->urb_list);
75+
urb->ep = hep;
76+
urb->complete = usb_urb_complete;
77+
urb->status = -EINPROGRESS;
78+
urb->dev = dev;
79+
urb->pipe = pipe;
80+
urb->transfer_buffer = buffer;
81+
urb->transfer_dma = (unsigned long)buffer;
82+
urb->transfer_buffer_length = len;
83+
urb->setup_packet = (unsigned char *)setup;
84+
85+
urb->ep->desc.wMaxPacketSize = __cpu_to_le16(maxpacketsize);
86+
urb->ep->desc.bmAttributes = endpoint_type;
87+
urb->ep->desc.bEndpointAddress = ((is_in ? USB_DIR_IN : USB_DIR_OUT) |
88+
epnum);
89+
urb->ep->desc.bInterval = interval;
90+
}
91+
92+
int usb_urb_submit(struct usb_hcd *hcd, struct urb *urb)
93+
{
94+
const struct usb_urb_ops *ops = hcd->urb_ops;
95+
unsigned long timeout;
96+
int ret;
97+
98+
if (!ops)
99+
return -EINVAL;
100+
101+
ret = ops->urb_enqueue(hcd, urb, 0);
102+
if (ret < 0) {
103+
printf("Failed to enqueue URB to controller\n");
104+
return ret;
105+
}
106+
107+
timeout = get_timer(0) + USB_TIMEOUT_MS(urb->pipe);
108+
do {
109+
if (ctrlc())
110+
return -EIO;
111+
ops->isr(0, hcd);
112+
} while (urb->status == -EINPROGRESS && get_timer(0) < timeout);
113+
114+
if (urb->status == -EINPROGRESS)
115+
ops->urb_dequeue(hcd, urb, -ETIME);
116+
117+
return urb->status;
118+
}
119+
120+
int usb_urb_submit_control(struct usb_hcd *hcd, struct urb *urb,
121+
struct usb_host_endpoint *hep,
122+
struct usb_device *dev, unsigned long pipe,
123+
void *buffer, int len, struct devrequest *setup,
124+
int interval, enum usb_device_speed speed)
125+
{
126+
const struct usb_urb_ops *ops = hcd->urb_ops;
127+
128+
usb_urb_fill(urb, hep, dev, USB_ENDPOINT_XFER_CONTROL, pipe, buffer,
129+
len, setup, 0);
130+
131+
/* Fix speed for non hub-attached devices */
132+
if (!usb_dev_get_parent(dev)) {
133+
dev->speed = speed;
134+
if (ops->hub_control)
135+
return ops->hub_control(hcd, dev, pipe, buffer, len,
136+
setup);
137+
}
138+
139+
return usb_urb_submit(hcd, urb);
140+
}
141+
142+
int usb_urb_submit_bulk(struct usb_hcd *hcd, struct urb *urb,
143+
struct usb_host_endpoint *hep, struct usb_device *dev,
144+
unsigned long pipe, void *buffer, int len)
145+
{
146+
usb_urb_fill(urb, hep, dev, USB_ENDPOINT_XFER_BULK, pipe, buffer, len,
147+
NULL, 0);
148+
149+
return usb_urb_submit(hcd, urb);
150+
}
151+
152+
int usb_urb_submit_irq(struct usb_hcd *hcd, struct urb *urb,
153+
struct usb_host_endpoint *hep, struct usb_device *dev,
154+
unsigned long pipe, void *buffer, int len, int interval)
155+
{
156+
usb_urb_fill(urb, hep, dev, USB_ENDPOINT_XFER_INT, pipe, buffer, len,
157+
NULL, interval);
158+
159+
return usb_urb_submit(hcd, urb);
160+
}

drivers/usb/dwc3/dwc3-generic.c

+30
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <reset.h>
2727
#include <clk.h>
2828
#include <usb/xhci.h>
29+
#include <asm/gpio.h>
2930

3031
struct dwc3_glue_data {
3132
struct clk_bulk clks;
@@ -43,6 +44,7 @@ struct dwc3_generic_priv {
4344
void *base;
4445
struct dwc3 dwc3;
4546
struct phy_bulk phys;
47+
struct gpio_desc ulpi_reset;
4648
};
4749

4850
struct dwc3_generic_host_priv {
@@ -78,6 +80,27 @@ static int dwc3_generic_probe(struct udevice *dev,
7880
if (rc && rc != -ENOTSUPP)
7981
return rc;
8082

83+
if (CONFIG_IS_ENABLED(DM_GPIO) &&
84+
device_is_compatible(dev->parent, "xlnx,zynqmp-dwc3")) {
85+
rc = gpio_request_by_name(dev->parent, "reset-gpios", 0,
86+
&priv->ulpi_reset, GPIOD_ACTIVE_LOW);
87+
if (rc)
88+
return rc;
89+
90+
/* Toggle ulpi to reset the phy. */
91+
rc = dm_gpio_set_value(&priv->ulpi_reset, 1);
92+
if (rc)
93+
return rc;
94+
95+
mdelay(5);
96+
97+
rc = dm_gpio_set_value(&priv->ulpi_reset, 0);
98+
if (rc)
99+
return rc;
100+
101+
mdelay(5);
102+
}
103+
81104
if (device_is_compatible(dev->parent, "rockchip,rk3399-dwc3"))
82105
reset_deassert_bulk(&glue->resets);
83106

@@ -99,6 +122,13 @@ static int dwc3_generic_remove(struct udevice *dev,
99122
{
100123
struct dwc3 *dwc3 = &priv->dwc3;
101124

125+
if (CONFIG_IS_ENABLED(DM_GPIO) &&
126+
device_is_compatible(dev->parent, "xlnx,zynqmp-dwc3")) {
127+
struct gpio_desc *ulpi_reset = &priv->ulpi_reset;
128+
129+
dm_gpio_free(ulpi_reset->dev, ulpi_reset);
130+
}
131+
102132
dwc3_remove(dwc3);
103133
dwc3_shutdown_phy(dev, &priv->phys);
104134
unmap_physmem(dwc3->regs, MAP_NOCACHE);

drivers/usb/host/r8a66597-hcd.c

+1-29
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <dm/device_compat.h>
1515
#include <linux/delay.h>
1616
#include <linux/iopoll.h>
17+
#include <linux/usb/usb_urb_compat.h>
1718
#include <power/regulator.h>
1819

1920
#include "r8a66597.h"
@@ -24,35 +25,6 @@
2425
#define R8A66597_DPRINT(...)
2526
#endif
2627

27-
static inline struct usb_device *usb_dev_get_parent(struct usb_device *udev)
28-
{
29-
struct udevice *parent = udev->dev->parent;
30-
31-
/*
32-
* When called from usb-uclass.c: usb_scan_device() udev->dev points
33-
* to the parent udevice, not the actual udevice belonging to the
34-
* udev as the device is not instantiated yet.
35-
*
36-
* If dev is an usb-bus, then we are called from usb_scan_device() for
37-
* an usb-device plugged directly into the root port, return NULL.
38-
*/
39-
if (device_get_uclass_id(udev->dev) == UCLASS_USB)
40-
return NULL;
41-
42-
/*
43-
* If these 2 are not the same we are being called from
44-
* usb_scan_device() and udev itself is the parent.
45-
*/
46-
if (dev_get_parent_priv(udev->dev) != udev)
47-
return udev;
48-
49-
/* We are being called normally, use the parent pointer */
50-
if (device_get_uclass_id(parent) == UCLASS_USB_HUB)
51-
return dev_get_parent_priv(parent);
52-
53-
return NULL;
54-
}
55-
5628
static void get_hub_data(struct usb_device *dev, u16 *hub_devnum, u16 *hubport)
5729
{
5830
struct usb_device *parent = usb_dev_get_parent(dev);

drivers/usb/isp1760/Kconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
config USB_ISP1760
4+
tristate "NXP ISP 1760/1761/1763 support"
5+
select DM_USB
6+
select USB_HOST
7+
help
8+
Say Y or M here if your system as an ISP1760/1761/1763 USB host
9+
controller.
10+
11+
This USB controller is usually attached to a non-DMA-Master
12+
capable bus.

drivers/usb/isp1760/Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
isp1760-y := isp1760-core.o isp1760-if.o isp1760-uboot.o isp1760-hcd.o
3+
4+
#isp1760-hcd.o
5+
6+
obj-$(CONFIG_USB_ISP1760) += isp1760.o

0 commit comments

Comments
 (0)