Skip to content

Commit b95d444

Browse files
Jean-Jacques HiblotFrank Wang
authored andcommitted
UPSTREAM: usb: gadget: Do not call board_usb_xxx() directly in USB gadget drivers
Add 2 functions to wrap the calls to board_usb_init() and board_usb_cleanup(). This is a preparatory work for DM support for UDC drivers (DM_USB_GADGET). Conflicts: cmd/fastboot.c cmd/rockusb.c cmd/usb_mass_storage.c Change-Id: I2b3a567d9dff75a03176d76d9fd9775cd8a0792e Signed-off-by: Jean-Jacques Hiblot <[email protected]> Reviewed-by: Lukasz Majewski <[email protected]> Signed-off-by: Frank Wang <[email protected]> (cherry picked from commit a06955a)
1 parent 3da53cb commit b95d444

File tree

8 files changed

+30
-47
lines changed

8 files changed

+30
-47
lines changed

cmd/fastboot.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
4747
usb_controller = argv[2];
4848
controller_index = simple_strtoul(usb_controller, NULL, 0);
4949

50-
ret = board_usb_init(controller_index, USB_INIT_DEVICE);
50+
ret = usb_gadget_initialize(controller_index);
5151
if (ret) {
5252
pr_err("USB init failed: %d", ret);
5353
return CMD_RET_FAILURE;
@@ -88,7 +88,7 @@ static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
8888
sysmem_free(CONFIG_FASTBOOT_BUF_ADDR);
8989
g_dnl_unregister();
9090
g_dnl_clear_detach();
91-
board_usb_cleanup(controller_index, USB_INIT_DEVICE);
91+
usb_gadget_release(controller_index);
9292

9393
return ret;
9494
#endif

cmd/rockusb.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ static int do_rkusb(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
166166

167167
controller_index = (unsigned int)(simple_strtoul(
168168
usb_controller, NULL, 0));
169-
if (board_usb_init(controller_index, USB_INIT_DEVICE)) {
169+
rc = usb_gadget_initialize(controller_index);
170+
if (rc) {
170171
pr_err("Couldn't init USB controller.");
171172
rc = CMD_RET_FAILURE;
172173
goto cleanup_rkusb;
@@ -251,7 +252,7 @@ static int do_rkusb(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
251252
cleanup_register:
252253
g_dnl_unregister();
253254
cleanup_board:
254-
board_usb_cleanup(controller_index, USB_INIT_DEVICE);
255+
usb_gadget_release(controller_index);
255256
cleanup_rkusb:
256257
rkusb_fini();
257258

cmd/thordown.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3131
goto done;
3232

3333
int controller_index = simple_strtoul(usb_controller, NULL, 0);
34-
ret = board_usb_init(controller_index, USB_INIT_DEVICE);
34+
ret = usb_gadget_initialize(controller_index);
3535
if (ret) {
3636
pr_err("USB init failed: %d", ret);
3737
ret = CMD_RET_FAILURE;
@@ -56,7 +56,7 @@ int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
5656

5757
exit:
5858
g_dnl_unregister();
59-
board_usb_cleanup(controller_index, USB_INIT_DEVICE);
59+
usb_gadget_release(controller_index);
6060
done:
6161
dfu_free_entities();
6262

cmd/usb_gadget_sdp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static int do_sdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
2121

2222
char *usb_controller = argv[1];
2323
int controller_index = simple_strtoul(usb_controller, NULL, 0);
24-
board_usb_init(controller_index, USB_INIT_DEVICE);
24+
usb_gadget_initialize(controller_index);
2525

2626
g_dnl_clear_detach();
2727
g_dnl_register("usb_dnl_sdp");
@@ -38,7 +38,7 @@ static int do_sdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3838

3939
exit:
4040
g_dnl_unregister();
41-
board_usb_cleanup(controller_index, USB_INIT_DEVICE);
41+
usb_gadget_release(controller_index);
4242

4343
return ret;
4444
}

cmd/usb_mass_storage.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ static int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
161161

162162
controller_index = (unsigned int)(simple_strtoul(
163163
usb_controller, NULL, 0));
164-
if (board_usb_init(controller_index, USB_INIT_DEVICE)) {
165-
pr_err("Couldn't init USB controller.");
164+
if (usb_gadget_initialize(controller_index)) {
165+
pr_err("Couldn't init USB controller.\n");
166166
rc = CMD_RET_FAILURE;
167167
goto cleanup_ums_init;
168168
}
@@ -232,7 +232,7 @@ static int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
232232
cleanup_register:
233233
g_dnl_unregister();
234234
cleanup_board:
235-
board_usb_cleanup(controller_index, USB_INIT_DEVICE);
235+
usb_gadget_release(controller_index);
236236
cleanup_ums_init:
237237
ums_fini();
238238

common/dfu.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
2424
bool dfu_reset = false;
2525
int ret, i = 0;
2626

27-
ret = board_usb_init(usbctrl_index, USB_INIT_DEVICE);
27+
ret = usb_gadget_initialize(usbctrl_index);
2828
if (ret) {
29-
pr_err("board usb init failed\n");
29+
pr_err("usb_gadget_initialize failed\n");
3030
return CMD_RET_FAILURE;
3131
}
3232
g_dnl_clear_detach();
@@ -85,7 +85,7 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
8585
}
8686
exit:
8787
g_dnl_unregister();
88-
board_usb_cleanup(usbctrl_index, USB_INIT_DEVICE);
88+
usb_gadget_release(usbctrl_index);
8989

9090
if (dfu_reset)
9191
do_reset(NULL, 0, 0, NULL);

drivers/usb/gadget/ether.c

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@ struct eth_dev {
105105
struct usb_gadget *gadget;
106106
struct usb_request *req; /* for control responses */
107107
struct usb_request *stat_req; /* for cdc & rndis status */
108-
#if CONFIG_IS_ENABLED(DM_USB)
109-
struct udevice *usb_udev;
110-
#endif
111108

112109
u8 config;
113110
struct usb_ep *in_ep, *out_ep, *status_ep;
@@ -2341,40 +2338,17 @@ static int eth_bind(struct usb_gadget *gadget)
23412338
}
23422339

23432340
/*-------------------------------------------------------------------------*/
2344-
2345-
#if CONFIG_IS_ENABLED(DM_USB)
2346-
int dm_usb_init(struct eth_dev *e_dev)
2347-
{
2348-
struct udevice *dev = NULL;
2349-
int ret;
2350-
2351-
ret = uclass_first_device(UCLASS_USB_DEV_GENERIC, &dev);
2352-
if (!dev || ret) {
2353-
pr_err("No USB device found\n");
2354-
return -ENODEV;
2355-
}
2356-
2357-
e_dev->usb_udev = dev;
2358-
2359-
return ret;
2360-
}
2361-
#endif
2362-
23632341
static int _usb_eth_init(struct ether_priv *priv)
23642342
{
23652343
struct eth_dev *dev = &priv->ethdev;
23662344
struct usb_gadget *gadget;
23672345
unsigned long ts;
2346+
int ret;
23682347
unsigned long timeout = USB_CONNECT_TIMEOUT;
23692348

2370-
#if CONFIG_IS_ENABLED(DM_USB)
2371-
if (dm_usb_init(dev)) {
2372-
pr_err("USB ether not found\n");
2373-
return -ENODEV;
2374-
}
2375-
#else
2376-
board_usb_init(0, USB_INIT_DEVICE);
2377-
#endif
2349+
ret = usb_gadget_initialize(0);
2350+
if (ret)
2351+
return ret;
23782352

23792353
/* Configure default mac-addresses for the USB ethernet device */
23802354
#ifdef CONFIG_USBNET_DEV_ADDR
@@ -2546,9 +2520,7 @@ void _usb_eth_halt(struct ether_priv *priv)
25462520
}
25472521

25482522
usb_gadget_unregister_driver(&priv->eth_driver);
2549-
#if !CONFIG_IS_ENABLED(DM_USB)
2550-
board_usb_cleanup(0, USB_INIT_DEVICE);
2551-
#endif
2523+
usb_gadget_release(0);
25522524
}
25532525

25542526
#ifndef CONFIG_DM_ETH

include/linux/usb/gadget.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define __LINUX_USB_GADGET_H
2020

2121
#include <errno.h>
22+
#include <usb.h>
2223
#include <linux/compat.h>
2324
#include <linux/list.h>
2425

@@ -937,4 +938,13 @@ extern void usb_ep_autoconfig_reset(struct usb_gadget *);
937938

938939
extern int usb_gadget_handle_interrupts(int index);
939940

941+
static inline int usb_gadget_initialize(int index)
942+
{
943+
return board_usb_init(index, USB_INIT_DEVICE);
944+
}
945+
946+
static inline int usb_gadget_release(int index)
947+
{
948+
return board_usb_cleanup(index, USB_INIT_DEVICE);
949+
}
940950
#endif /* __LINUX_USB_GADGET_H */

0 commit comments

Comments
 (0)