mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-22 04:44:46 +00:00
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). Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com> Reviewed-by: Lukasz Majewski <lukma@denx.de>
This commit is contained in:
parent
57dbc15143
commit
a06955ae1e
8 changed files with 28 additions and 46 deletions
|
@ -51,7 +51,7 @@ static int do_fastboot_usb(int argc, char *const argv[],
|
||||||
return CMD_RET_FAILURE;
|
return CMD_RET_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = board_usb_init(controller_index, USB_INIT_DEVICE);
|
ret = usb_gadget_initialize(controller_index);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pr_err("USB init failed: %d\n", ret);
|
pr_err("USB init failed: %d\n", ret);
|
||||||
return CMD_RET_FAILURE;
|
return CMD_RET_FAILURE;
|
||||||
|
@ -82,7 +82,7 @@ static int do_fastboot_usb(int argc, char *const argv[],
|
||||||
exit:
|
exit:
|
||||||
g_dnl_unregister();
|
g_dnl_unregister();
|
||||||
g_dnl_clear_detach();
|
g_dnl_clear_detach();
|
||||||
board_usb_cleanup(controller_index, USB_INIT_DEVICE);
|
usb_gadget_release(controller_index);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -33,7 +33,7 @@ static int do_rockusb(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
|
||||||
dev_index = simple_strtoul(devnum, NULL, 0);
|
dev_index = simple_strtoul(devnum, NULL, 0);
|
||||||
rockusb_dev_init(devtype, dev_index);
|
rockusb_dev_init(devtype, dev_index);
|
||||||
|
|
||||||
ret = board_usb_init(controller_index, USB_INIT_DEVICE);
|
ret = usb_gadget_initialize(controller_index);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printf("USB init failed: %d\n", ret);
|
printf("USB init failed: %d\n", ret);
|
||||||
return CMD_RET_FAILURE;
|
return CMD_RET_FAILURE;
|
||||||
|
@ -62,7 +62,7 @@ static int do_rockusb(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
|
||||||
exit:
|
exit:
|
||||||
g_dnl_unregister();
|
g_dnl_unregister();
|
||||||
g_dnl_clear_detach();
|
g_dnl_clear_detach();
|
||||||
board_usb_cleanup(controller_index, USB_INIT_DEVICE);
|
usb_gadget_release(controller_index);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
int controller_index = simple_strtoul(usb_controller, NULL, 0);
|
int controller_index = simple_strtoul(usb_controller, NULL, 0);
|
||||||
ret = board_usb_init(controller_index, USB_INIT_DEVICE);
|
ret = usb_gadget_initialize(controller_index);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pr_err("USB init failed: %d\n", ret);
|
pr_err("USB init failed: %d\n", ret);
|
||||||
ret = CMD_RET_FAILURE;
|
ret = CMD_RET_FAILURE;
|
||||||
|
@ -55,7 +55,7 @@ int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
g_dnl_unregister();
|
g_dnl_unregister();
|
||||||
board_usb_cleanup(controller_index, USB_INIT_DEVICE);
|
usb_gadget_release(controller_index);
|
||||||
done:
|
done:
|
||||||
dfu_free_entities();
|
dfu_free_entities();
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ static int do_sdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
|
|
||||||
char *usb_controller = argv[1];
|
char *usb_controller = argv[1];
|
||||||
int controller_index = simple_strtoul(usb_controller, NULL, 0);
|
int controller_index = simple_strtoul(usb_controller, NULL, 0);
|
||||||
board_usb_init(controller_index, USB_INIT_DEVICE);
|
usb_gadget_initialize(controller_index);
|
||||||
|
|
||||||
g_dnl_clear_detach();
|
g_dnl_clear_detach();
|
||||||
g_dnl_register("usb_dnl_sdp");
|
g_dnl_register("usb_dnl_sdp");
|
||||||
|
@ -37,7 +37,7 @@ static int do_sdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
g_dnl_unregister();
|
g_dnl_unregister();
|
||||||
board_usb_cleanup(controller_index, USB_INIT_DEVICE);
|
usb_gadget_release(controller_index);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,7 +160,7 @@ static int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
|
||||||
|
|
||||||
controller_index = (unsigned int)(simple_strtoul(
|
controller_index = (unsigned int)(simple_strtoul(
|
||||||
usb_controller, NULL, 0));
|
usb_controller, NULL, 0));
|
||||||
if (board_usb_init(controller_index, USB_INIT_DEVICE)) {
|
if (usb_gadget_initialize(controller_index)) {
|
||||||
pr_err("Couldn't init USB controller.\n");
|
pr_err("Couldn't init USB controller.\n");
|
||||||
rc = CMD_RET_FAILURE;
|
rc = CMD_RET_FAILURE;
|
||||||
goto cleanup_ums_init;
|
goto cleanup_ums_init;
|
||||||
|
@ -231,7 +231,7 @@ static int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
|
||||||
cleanup_register:
|
cleanup_register:
|
||||||
g_dnl_unregister();
|
g_dnl_unregister();
|
||||||
cleanup_board:
|
cleanup_board:
|
||||||
board_usb_cleanup(controller_index, USB_INIT_DEVICE);
|
usb_gadget_release(controller_index);
|
||||||
cleanup_ums_init:
|
cleanup_ums_init:
|
||||||
ums_fini();
|
ums_fini();
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,9 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
|
||||||
bool dfu_reset = false;
|
bool dfu_reset = false;
|
||||||
int ret, i = 0;
|
int ret, i = 0;
|
||||||
|
|
||||||
ret = board_usb_init(usbctrl_index, USB_INIT_DEVICE);
|
ret = usb_gadget_initialize(usbctrl_index);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pr_err("board usb init failed\n");
|
pr_err("usb_gadget_initialize failed\n");
|
||||||
return CMD_RET_FAILURE;
|
return CMD_RET_FAILURE;
|
||||||
}
|
}
|
||||||
g_dnl_clear_detach();
|
g_dnl_clear_detach();
|
||||||
|
@ -84,7 +84,7 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
|
||||||
}
|
}
|
||||||
exit:
|
exit:
|
||||||
g_dnl_unregister();
|
g_dnl_unregister();
|
||||||
board_usb_cleanup(usbctrl_index, USB_INIT_DEVICE);
|
usb_gadget_release(usbctrl_index);
|
||||||
|
|
||||||
if (dfu_reset)
|
if (dfu_reset)
|
||||||
do_reset(NULL, 0, 0, NULL);
|
do_reset(NULL, 0, 0, NULL);
|
||||||
|
|
|
@ -100,9 +100,6 @@ struct eth_dev {
|
||||||
struct usb_gadget *gadget;
|
struct usb_gadget *gadget;
|
||||||
struct usb_request *req; /* for control responses */
|
struct usb_request *req; /* for control responses */
|
||||||
struct usb_request *stat_req; /* for cdc & rndis status */
|
struct usb_request *stat_req; /* for cdc & rndis status */
|
||||||
#if CONFIG_IS_ENABLED(DM_USB)
|
|
||||||
struct udevice *usb_udev;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
u8 config;
|
u8 config;
|
||||||
struct usb_ep *in_ep, *out_ep, *status_ep;
|
struct usb_ep *in_ep, *out_ep, *status_ep;
|
||||||
|
@ -2336,40 +2333,17 @@ fail:
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#if CONFIG_IS_ENABLED(DM_USB)
|
|
||||||
int dm_usb_init(struct eth_dev *e_dev)
|
|
||||||
{
|
|
||||||
struct udevice *dev = NULL;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = uclass_first_device(UCLASS_USB_DEV_GENERIC, &dev);
|
|
||||||
if (!dev || ret) {
|
|
||||||
pr_err("No USB device found\n");
|
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
|
|
||||||
e_dev->usb_udev = dev;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int _usb_eth_init(struct ether_priv *priv)
|
static int _usb_eth_init(struct ether_priv *priv)
|
||||||
{
|
{
|
||||||
struct eth_dev *dev = &priv->ethdev;
|
struct eth_dev *dev = &priv->ethdev;
|
||||||
struct usb_gadget *gadget;
|
struct usb_gadget *gadget;
|
||||||
unsigned long ts;
|
unsigned long ts;
|
||||||
|
int ret;
|
||||||
unsigned long timeout = USB_CONNECT_TIMEOUT;
|
unsigned long timeout = USB_CONNECT_TIMEOUT;
|
||||||
|
|
||||||
#if CONFIG_IS_ENABLED(DM_USB)
|
ret = usb_gadget_initialize(0);
|
||||||
if (dm_usb_init(dev)) {
|
if (ret)
|
||||||
pr_err("USB ether not found\n");
|
return ret;
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
board_usb_init(0, USB_INIT_DEVICE);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Configure default mac-addresses for the USB ethernet device */
|
/* Configure default mac-addresses for the USB ethernet device */
|
||||||
#ifdef CONFIG_USBNET_DEV_ADDR
|
#ifdef CONFIG_USBNET_DEV_ADDR
|
||||||
|
@ -2541,9 +2515,7 @@ void _usb_eth_halt(struct ether_priv *priv)
|
||||||
}
|
}
|
||||||
|
|
||||||
usb_gadget_unregister_driver(&priv->eth_driver);
|
usb_gadget_unregister_driver(&priv->eth_driver);
|
||||||
#if !CONFIG_IS_ENABLED(DM_USB)
|
usb_gadget_release(0);
|
||||||
board_usb_cleanup(0, USB_INIT_DEVICE);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef CONFIG_DM_ETH
|
#ifndef CONFIG_DM_ETH
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#define __LINUX_USB_GADGET_H
|
#define __LINUX_USB_GADGET_H
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <usb.h>
|
||||||
#include <linux/compat.h>
|
#include <linux/compat.h>
|
||||||
#include <linux/list.h>
|
#include <linux/list.h>
|
||||||
|
|
||||||
|
@ -926,4 +927,13 @@ extern void usb_ep_autoconfig_reset(struct usb_gadget *);
|
||||||
|
|
||||||
extern int usb_gadget_handle_interrupts(int index);
|
extern int usb_gadget_handle_interrupts(int index);
|
||||||
|
|
||||||
|
static inline int usb_gadget_initialize(int index)
|
||||||
|
{
|
||||||
|
return board_usb_init(index, USB_INIT_DEVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int usb_gadget_release(int index)
|
||||||
|
{
|
||||||
|
return board_usb_cleanup(index, USB_INIT_DEVICE);
|
||||||
|
}
|
||||||
#endif /* __LINUX_USB_GADGET_H */
|
#endif /* __LINUX_USB_GADGET_H */
|
||||||
|
|
Loading…
Add table
Reference in a new issue