Merge branch 'next' of git://source.denx.de/u-boot-usb into next

- Rework gadget device handling
This commit is contained in:
Tom Rini 2023-09-16 12:14:08 -04:00
commit 8fcd28aae5
39 changed files with 215 additions and 192 deletions

View File

@ -299,9 +299,9 @@ static struct dwc3_device dwc3_device_data = {
.hsphy_mode = USBPHY_INTERFACE_MODE_UTMIW,
};
int usb_gadget_handle_interrupts(int index)
int dm_usb_gadget_handle_interrupts(struct udevice *dev)
{
dwc3_uboot_handle_interrupt(0);
dwc3_uboot_handle_interrupt(dev);
return 0;
}

View File

@ -418,9 +418,9 @@ out:
return rv;
}
int usb_gadget_handle_interrupts(int index)
int dm_usb_gadget_handle_interrupts(struct udevice *dev)
{
dwc3_uboot_handle_interrupt(0);
dwc3_uboot_handle_interrupt(dev);
return 0;
}

View File

@ -126,9 +126,9 @@ static struct dwc3_device dwc3_device_data = {
.index = 0,
};
int usb_gadget_handle_interrupts(int index)
int dm_usb_gadget_handle_interrupts(struct udevice *dev)
{
dwc3_uboot_handle_interrupt(0);
dwc3_uboot_handle_interrupt(dev);
return 0;
}

View File

@ -50,9 +50,9 @@ static struct dwc3_device dwc3_device_data = {
.index = 0,
};
int usb_gadget_handle_interrupts(int index)
int dm_usb_gadget_handle_interrupts(struct udevice *dev)
{
dwc3_uboot_handle_interrupt(index);
dwc3_uboot_handle_interrupt(dev);
return 0;
}

View File

@ -760,13 +760,13 @@ static struct ti_usb_phy_device usb_phy2_device = {
.index = 1,
};
int usb_gadget_handle_interrupts(int index)
int dm_usb_gadget_handle_interrupts(struct udevice *dev)
{
u32 status;
status = dwc3_omap_uboot_interrupt_status(index);
status = dwc3_omap_uboot_interrupt_status(dev);
if (status)
dwc3_uboot_handle_interrupt(index);
dwc3_uboot_handle_interrupt(dev);
return 0;
}

View File

@ -61,6 +61,7 @@ static int do_fastboot_usb(int argc, char *const argv[],
{
int controller_index;
char *usb_controller;
struct udevice *udc;
char *endp;
int ret;
@ -79,7 +80,7 @@ static int do_fastboot_usb(int argc, char *const argv[],
return CMD_RET_FAILURE;
}
ret = usb_gadget_initialize(controller_index);
ret = udc_device_get_by_index(controller_index, &udc);
if (ret) {
pr_err("USB init failed: %d\n", ret);
return CMD_RET_FAILURE;
@ -103,13 +104,13 @@ static int do_fastboot_usb(int argc, char *const argv[],
if (ctrlc())
break;
schedule();
usb_gadget_handle_interrupts(controller_index);
dm_usb_gadget_handle_interrupts(udc);
}
ret = CMD_RET_SUCCESS;
exit:
usb_gadget_release(controller_index);
udc_device_put(udc);
g_dnl_unregister();
g_dnl_clear_detach();

View File

@ -15,6 +15,7 @@ static int do_rockusb(struct cmd_tbl *cmdtp, int flag, int argc,
{
int controller_index, dev_index;
char *usb_controller;
struct udevice *udc;
char *devtype;
char *devnum;
int ret;
@ -34,7 +35,7 @@ static int do_rockusb(struct cmd_tbl *cmdtp, int flag, int argc,
dev_index = simple_strtoul(devnum, NULL, 0);
rockusb_dev_init(devtype, dev_index);
ret = usb_gadget_initialize(controller_index);
ret = udc_device_get_by_index(controller_index, &udc);
if (ret) {
printf("USB init failed: %d\n", ret);
return CMD_RET_FAILURE;
@ -56,14 +57,14 @@ static int do_rockusb(struct cmd_tbl *cmdtp, int flag, int argc,
break;
if (ctrlc())
break;
usb_gadget_handle_interrupts(controller_index);
dm_usb_gadget_handle_interrupts(udc);
}
ret = CMD_RET_SUCCESS;
exit:
g_dnl_unregister();
g_dnl_clear_detach();
usb_gadget_release(controller_index);
udc_device_put(udc);
return ret;
}

View File

@ -15,23 +15,25 @@
int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
char *interface, *devstring;
int controller_index;
struct udevice *udc;
int ret;
if (argc < 4)
return CMD_RET_USAGE;
char *usb_controller = argv[1];
char *interface = argv[2];
char *devstring = argv[3];
int ret;
puts("TIZEN \"THOR\" Downloader\n");
interface = argv[2];
devstring = argv[3];
ret = dfu_init_env_entities(interface, devstring);
if (ret)
goto done;
int controller_index = simple_strtoul(usb_controller, NULL, 0);
ret = usb_gadget_initialize(controller_index);
controller_index = simple_strtoul(argv[1], NULL, 0);
ret = udc_device_get_by_index(controller_index, &udc);
if (ret) {
pr_err("USB init failed: %d\n", ret);
ret = CMD_RET_FAILURE;
@ -45,7 +47,7 @@ int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
goto exit;
}
ret = thor_init();
ret = thor_init(udc);
if (ret) {
pr_err("THOR DOWNLOAD failed: %d\n", ret);
ret = CMD_RET_FAILURE;
@ -53,7 +55,7 @@ int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
}
do {
ret = thor_handle();
ret = thor_handle(udc);
if (ret == THOR_DFU_REINIT_NEEDED) {
dfu_free_entities();
ret = dfu_init_env_entities(interface, devstring);
@ -66,7 +68,7 @@ int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
} while (ret == 0);
exit:
g_dnl_unregister();
usb_gadget_release(controller_index);
udc_device_put(udc);
done:
dfu_free_entities();

View File

@ -14,14 +14,17 @@
static int do_sdp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
int controller_index;
struct udevice *udc;
int ret;
if (argc < 2)
return CMD_RET_USAGE;
char *usb_controller = argv[1];
int controller_index = simple_strtoul(usb_controller, NULL, 0);
usb_gadget_initialize(controller_index);
controller_index = simple_strtoul(argv[1], NULL, 0);
ret = udc_device_get_by_index(controller_index, &udc);
if (ret)
return ret;
g_dnl_clear_detach();
ret = g_dnl_register("usb_dnl_sdp");
@ -30,20 +33,20 @@ static int do_sdp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
goto exit_register;
}
ret = sdp_init(controller_index);
ret = sdp_init(udc);
if (ret) {
pr_err("SDP init failed: %d\n", ret);
goto exit;
}
/* This command typically does not return but jumps to an image */
sdp_handle(controller_index);
sdp_handle(udc);
pr_err("SDP ended\n");
exit:
g_dnl_unregister();
exit_register:
usb_gadget_release(controller_index);
udc_device_put(udc);
return CMD_RET_FAILURE;
}

View File

@ -143,6 +143,7 @@ static int do_usb_mass_storage(struct cmd_tbl *cmdtp, int flag,
const char *devtype;
const char *devnum;
unsigned int controller_index;
struct udevice *udc;
int rc;
int cable_ready_timeout __maybe_unused;
@ -164,13 +165,14 @@ static int do_usb_mass_storage(struct cmd_tbl *cmdtp, int flag,
controller_index = (unsigned int)(simple_strtoul(
usb_controller, NULL, 0));
if (usb_gadget_initialize(controller_index)) {
rc = udc_device_get_by_index(controller_index, &udc);
if (rc) {
pr_err("Couldn't init USB controller.\n");
rc = CMD_RET_FAILURE;
goto cleanup_ums_init;
}
rc = fsg_init(ums, ums_count, controller_index);
rc = fsg_init(ums, ums_count, udc);
if (rc) {
pr_err("fsg_init failed\n");
rc = CMD_RET_FAILURE;
@ -215,7 +217,7 @@ static int do_usb_mass_storage(struct cmd_tbl *cmdtp, int flag,
}
while (1) {
usb_gadget_handle_interrupts(controller_index);
dm_usb_gadget_handle_interrupts(udc);
rc = fsg_main_thread(NULL);
if (rc) {
@ -247,7 +249,7 @@ static int do_usb_mass_storage(struct cmd_tbl *cmdtp, int flag,
cleanup_register:
g_dnl_unregister();
cleanup_board:
usb_gadget_release(controller_index);
udc_device_put(udc);
cleanup_ums_init:
ums_fini();

View File

@ -23,18 +23,20 @@
int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
{
bool dfu_reset = false;
struct udevice *udc;
int ret, i = 0;
ret = usb_gadget_initialize(usbctrl_index);
ret = udc_device_get_by_index(usbctrl_index, &udc);
if (ret) {
pr_err("usb_gadget_initialize failed\n");
pr_err("udc_device_get_by_index failed\n");
return CMD_RET_FAILURE;
}
g_dnl_clear_detach();
ret = g_dnl_register(usb_dnl_gadget);
if (ret) {
pr_err("g_dnl_register failed");
return CMD_RET_FAILURE;
ret = CMD_RET_FAILURE;
goto err_detach;
}
#ifdef CONFIG_DFU_TIMEOUT
@ -54,7 +56,7 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
}
/*
* This extra number of usb_gadget_handle_interrupts()
* This extra number of dm_usb_gadget_handle_interrupts()
* calls is necessary to assure correct transmission
* completion with dfu-util
*/
@ -67,7 +69,7 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
if (dfu_get_defer_flush()) {
/*
* Call to usb_gadget_handle_interrupts() is necessary
* Call to dm_usb_gadget_handle_interrupts() is necessary
* to act on ZLP OUT transaction from HOST PC after
* transmitting the whole file.
*
@ -76,7 +78,7 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
* 5 seconds). In such situation the dfu-util program
* exits with error message.
*/
usb_gadget_handle_interrupts(usbctrl_index);
dm_usb_gadget_handle_interrupts(udc);
ret = dfu_flush(dfu_get_defer_flush(), NULL, 0, 0);
dfu_set_defer_flush(NULL);
if (ret) {
@ -102,11 +104,12 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)
goto exit;
schedule();
usb_gadget_handle_interrupts(usbctrl_index);
dm_usb_gadget_handle_interrupts(udc);
}
exit:
g_dnl_unregister();
usb_gadget_release(usbctrl_index);
err_detach:
udc_device_put(udc);
if (dfu_reset)
do_reset(NULL, 0, 0, NULL);

View File

@ -14,10 +14,13 @@
static int spl_sdp_load_image(struct spl_image_info *spl_image,
struct spl_boot_device *bootdev)
{
int ret;
const int controller_index = CONFIG_SPL_SDP_USB_DEV;
struct udevice *udc;
int ret;
usb_gadget_initialize(controller_index);
ret = udc_device_get_by_index(controller_index, &udc);
if (ret)
return ret;
board_usb_init(controller_index, USB_INIT_DEVICE);
@ -25,13 +28,13 @@ static int spl_sdp_load_image(struct spl_image_info *spl_image,
ret = g_dnl_register("usb_dnl_sdp");
if (ret) {
pr_err("SDP dnl register failed: %d\n", ret);
return ret;
goto err_detach;
}
ret = sdp_init(controller_index);
ret = sdp_init(udc);
if (ret) {
pr_err("SDP init failed: %d\n", ret);
return -ENODEV;
goto err_unregister;
}
/*
@ -39,10 +42,13 @@ static int spl_sdp_load_image(struct spl_image_info *spl_image,
* or it loads a FIT image and returns it to be handled by the SPL
* code.
*/
ret = spl_sdp_handle(controller_index, spl_image, bootdev);
ret = spl_sdp_handle(udc, spl_image, bootdev);
debug("SDP ended\n");
usb_gadget_release(controller_index);
err_unregister:
g_dnl_unregister();
err_detach:
udc_device_put(udc);
return ret;
}
SPL_LOAD_IMAGE_METHOD("USB SDP", 0, BOOT_DEVICE_BOARD, spl_sdp_load_image);

View File

@ -237,6 +237,7 @@ CONFIG_TIMER=y
CONFIG_TIMER_EARLY=y
CONFIG_SANDBOX_TIMER=y
CONFIG_USB=y
CONFIG_DM_USB_GADGET=y
CONFIG_USB_EMUL=y
CONFIG_USB_KEYBOARD=y
CONFIG_VIDEO=y

View File

@ -299,6 +299,7 @@ CONFIG_TIMER=y
CONFIG_TIMER_EARLY=y
CONFIG_SANDBOX_TIMER=y
CONFIG_USB=y
CONFIG_DM_USB_GADGET=y
CONFIG_USB_EMUL=y
CONFIG_USB_KEYBOARD=y
CONFIG_USB_GADGET=y

View File

@ -203,6 +203,7 @@ CONFIG_TIMER=y
CONFIG_TIMER_EARLY=y
CONFIG_SANDBOX_TIMER=y
CONFIG_USB=y
CONFIG_DM_USB_GADGET=y
CONFIG_USB_EMUL=y
CONFIG_USB_KEYBOARD=y
CONFIG_VIDEO=y

View File

@ -217,6 +217,7 @@ CONFIG_TIMER=y
CONFIG_TIMER_EARLY=y
CONFIG_SANDBOX_TIMER=y
CONFIG_USB=y
CONFIG_DM_USB_GADGET=y
CONFIG_USB_EMUL=y
CONFIG_USB_KEYBOARD=y
CONFIG_VIDEO=y

View File

@ -223,6 +223,7 @@ CONFIG_TIMER=y
CONFIG_TIMER_EARLY=y
CONFIG_SANDBOX_TIMER=y
CONFIG_USB=y
CONFIG_DM_USB_GADGET=y
CONFIG_USB_EMUL=y
CONFIG_USB_KEYBOARD=y
CONFIG_VIDEO=y

View File

@ -236,6 +236,7 @@ CONFIG_VPL_TIMER=y
CONFIG_TIMER_EARLY=y
CONFIG_SANDBOX_TIMER=y
CONFIG_USB=y
CONFIG_DM_USB_GADGET=y
CONFIG_USB_EMUL=y
CONFIG_USB_KEYBOARD=y
CONFIG_VIDEO=y

View File

@ -986,18 +986,18 @@ void dwc3_uboot_exit(int index)
/**
* dwc3_uboot_handle_interrupt - handle dwc3 core interrupt
* @index: index of this controller
* @dev: device of this controller
*
* Invokes dwc3 gadget interrupts.
*
* Generally called from board file.
*/
void dwc3_uboot_handle_interrupt(int index)
void dwc3_uboot_handle_interrupt(struct udevice *dev)
{
struct dwc3 *dwc = NULL;
list_for_each_entry(dwc, &dwc3_list, list) {
if (dwc->index != index)
if (dwc->dev != dev)
continue;
dwc3_gadget_uboot_handle_interrupt(dwc);

View File

@ -119,7 +119,7 @@
#define USBOTGSS_UTMI_OTG_STATUS_VBUSVALID (1 << 1)
struct dwc3_omap {
struct device *dev;
struct udevice *dev;
void __iomem *base;
@ -429,19 +429,19 @@ void dwc3_omap_uboot_exit(int index)
/**
* dwc3_omap_uboot_interrupt_status - check the status of interrupt
* @index: index of this controller
* @dev: device of this controller
*
* Checks the status of interrupts and returns true if an interrupt
* is detected or false otherwise.
*
* Generally called from board file.
*/
int dwc3_omap_uboot_interrupt_status(int index)
int dwc3_omap_uboot_interrupt_status(struct udevice *dev)
{
struct dwc3_omap *omap = NULL;
list_for_each_entry(omap, &dwc3_omap_list, list)
if (omap->index == index)
if (omap->dev == dev)
return dwc3_omap_interrupt(-1, omap);
return 0;

View File

@ -1429,7 +1429,7 @@ static const struct at91_udc_caps at91sam9261_udc_caps = {
};
#endif
int usb_gadget_handle_interrupts(int index)
int dm_usb_gadget_handle_interrupts(struct udevice *dev)
{
struct at91_udc *udc = controller;

View File

@ -1198,14 +1198,13 @@ static struct usba_udc controller = {
},
};
int usb_gadget_handle_interrupts(int index)
int dm_usb_gadget_handle_interrupts(struct udevice *dev)
{
struct usba_udc *udc = &controller;
return usba_udc_irq(udc);
}
int usb_gadget_register_driver(struct usb_gadget_driver *driver)
{
struct usba_udc *udc = &controller;

View File

@ -869,10 +869,10 @@ void udc_irq(void)
}
}
int usb_gadget_handle_interrupts(int index)
int dm_usb_gadget_handle_interrupts(struct udevice *dev)
{
u32 value;
struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
u32 value;
value = readl(&udc->usbsts);
if (value)

View File

@ -941,15 +941,12 @@ int dwc2_udc_handle_interrupt(void)
return 0;
}
#if !CONFIG_IS_ENABLED(DM_USB_GADGET)
int usb_gadget_handle_interrupts(int index)
int dm_usb_gadget_handle_interrupts(struct udevice *dev)
{
return dwc2_udc_handle_interrupt();
}
#else /* CONFIG_IS_ENABLED(DM_USB_GADGET) */
#if CONFIG_IS_ENABLED(DM_USB_GADGET)
struct dwc2_priv_data {
struct clk_bulk clks;
struct reset_ctl_bulk resets;
@ -957,11 +954,6 @@ struct dwc2_priv_data {
struct udevice *usb33d_supply;
};
int dm_usb_gadget_handle_interrupts(struct udevice *dev)
{
return dwc2_udc_handle_interrupt();
}
static int dwc2_phy_setup(struct udevice *dev, struct phy_bulk *phys)
{
int ret;

View File

@ -1880,8 +1880,10 @@ static void eth_start(struct eth_dev *dev, gfp_t gfp_flags)
}
}
static int eth_stop(struct eth_dev *dev)
static int eth_stop(struct udevice *udev)
{
struct ether_priv *priv = dev_get_priv(udev);
struct eth_dev *dev = &priv->ethdev;
#ifdef RNDIS_COMPLETE_SIGNAL_DISCONNECT
unsigned long ts;
unsigned long timeout = CONFIG_SYS_HZ; /* 1 sec to stop RNDIS */
@ -1895,7 +1897,7 @@ static int eth_stop(struct eth_dev *dev)
/* Wait until host receives OID_GEN_MEDIA_CONNECT_STATUS */
ts = get_timer(0);
while (get_timer(ts) < timeout)
usb_gadget_handle_interrupts(0);
dm_usb_gadget_handle_interrupts(udev->parent);
#endif
rndis_uninit(dev->rndis_config);
@ -2300,7 +2302,7 @@ static int usb_eth_start(struct udevice *udev)
pr_err("The remote end did not respond in time.");
goto fail;
}
usb_gadget_handle_interrupts(0);
dm_usb_gadget_handle_interrupts(udev->parent);
}
packet_received = 0;
@ -2370,7 +2372,7 @@ static int usb_eth_send(struct udevice *udev, void *packet, int length)
printf("timeout sending packets to usb ethernet\n");
return -1;
}
usb_gadget_handle_interrupts(0);
dm_usb_gadget_handle_interrupts(udev->parent);
}
free(rndis_pkt);
@ -2400,13 +2402,13 @@ static void usb_eth_stop(struct udevice *udev)
* 2) 'pullup' callback in your UDC driver can be improved to perform
* this deinitialization.
*/
eth_stop(dev);
eth_stop(udev);
usb_gadget_disconnect(dev->gadget);
/* Clear pending interrupt */
if (dev->network_started) {
usb_gadget_handle_interrupts(0);
dm_usb_gadget_handle_interrupts(udev->parent);
dev->network_started = 0;
}
}
@ -2416,7 +2418,7 @@ static int usb_eth_recv(struct udevice *dev, int flags, uchar **packetp)
struct ether_priv *priv = dev_get_priv(dev);
struct eth_dev *ethdev = &priv->ethdev;
usb_gadget_handle_interrupts(0);
dm_usb_gadget_handle_interrupts(dev->parent);
if (packet_received) {
if (ethdev->rx_req) {
@ -2467,7 +2469,7 @@ int usb_ether_init(void)
return ret;
}
return usb_gadget_initialize(0);
return 0;
}
static int usb_eth_probe(struct udevice *dev)
@ -2528,7 +2530,7 @@ static int usb_eth_remove(struct udevice *dev)
static int usb_eth_unbind(struct udevice *dev)
{
usb_gadget_release(0);
udc_device_put(dev->parent);
return 0;
}

View File

@ -51,7 +51,7 @@ struct f_acm {
#define ACM_CTRL_RTS BIT(1) /* unused with full duplex */
#define ACM_CTRL_DTR BIT(0) /* host is ready for data r/w */
int controller_index;
struct udevice *udc;
};
static struct f_acm *default_acm_function;
@ -489,7 +489,7 @@ static void __acm_tx(struct f_acm *f_acm)
int len, ret;
do {
usb_gadget_handle_interrupts(f_acm->controller_index);
dm_usb_gadget_handle_interrupts(f_acm->udc);
if (!(f_acm->handshake_bits & ACM_CTRL_DTR))
break;
@ -520,7 +520,7 @@ static bool acm_connected(struct stdio_dev *dev)
struct f_acm *f_acm = stdio_to_acm(dev);
/* give a chance to process udc irq */
usb_gadget_handle_interrupts(f_acm->controller_index);
dm_usb_gadget_handle_interrupts(f_acm->udc);
return f_acm->connected;
}
@ -543,7 +543,10 @@ static int acm_add(struct usb_configuration *c)
f_acm->usb_function.descriptors = acm_fs_function;
f_acm->usb_function.hs_descriptors = acm_hs_function;
f_acm->usb_function.setup = acm_setup;
f_acm->controller_index = 0;
status = udc_device_get_by_index(0, &f_acm->udc);
if (status)
return status;
status = usb_add_function(c, &f_acm->usb_function);
if (status) {
@ -567,7 +570,7 @@ static int acm_stdio_tstc(struct stdio_dev *dev)
{
struct f_acm *f_acm = stdio_to_acm(dev);
usb_gadget_handle_interrupts(f_acm->controller_index);
dm_usb_gadget_handle_interrupts(f_acm->udc);
return (f_acm->rx_buf.size > 0);
}

View File

@ -435,7 +435,7 @@ static void set_bulk_out_req_length(struct fsg_common *common,
static struct ums *ums;
static int ums_count;
static struct fsg_common *the_fsg_common;
static unsigned int controller_index;
static struct udevice *udcdev;
static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
{
@ -680,7 +680,7 @@ static int sleep_thread(struct fsg_common *common)
k = 0;
}
usb_gadget_handle_interrupts(controller_index);
dm_usb_gadget_handle_interrupts(udcdev);
}
common->thread_wakeup_needed = 0;
return rc;
@ -2764,11 +2764,11 @@ int fsg_add(struct usb_configuration *c)
return fsg_bind_config(c->cdev, c, fsg_common);
}
int fsg_init(struct ums *ums_devs, int count, unsigned int controller_idx)
int fsg_init(struct ums *ums_devs, int count, struct udevice *udc)
{
ums = ums_devs;
ums_count = count;
controller_index = controller_idx;
udcdev = udc;
return 0;
}

View File

@ -702,7 +702,7 @@ static int sdp_bind_config(struct usb_configuration *c)
return status;
}
int sdp_init(int controller_index)
int sdp_init(struct udevice *udc)
{
printf("SDP: initialize...\n");
while (!sdp_func->configuration_done) {
@ -712,7 +712,7 @@ int sdp_init(int controller_index)
}
schedule();
usb_gadget_handle_interrupts(controller_index);
dm_usb_gadget_handle_interrupts(udc);
}
return 0;
@ -911,9 +911,9 @@ static void sdp_handle_out_ep(void)
}
#ifndef CONFIG_SPL_BUILD
int sdp_handle(int controller_index)
int sdp_handle(struct udevice *udc)
#else
int spl_sdp_handle(int controller_index, struct spl_image_info *spl_image,
int spl_sdp_handle(struct udevice *udc, struct spl_image_info *spl_image,
struct spl_boot_device *bootdev)
#endif
{
@ -929,7 +929,7 @@ int spl_sdp_handle(int controller_index, struct spl_image_info *spl_image,
return 0;
schedule();
usb_gadget_handle_interrupts(controller_index);
dm_usb_gadget_handle_interrupts(udc);
#ifdef CONFIG_SPL_BUILD
flag = sdp_handle_in_ep(spl_image, bootdev);

View File

@ -15,9 +15,10 @@
*/
#include <command.h>
#include <errno.h>
#include <common.h>
#include <console.h>
#include <dm.h>
#include <errno.h>
#include <init.h>
#include <log.h>
#include <malloc.h>
@ -34,9 +35,9 @@
#include "f_thor.h"
static void thor_tx_data(unsigned char *data, int len);
static void thor_tx_data(struct udevice *udc, unsigned char *data, int len);
static void thor_set_dma(void *addr, int len);
static int thor_rx_data(void);
static int thor_rx_data(struct udevice *udc);
static struct f_thor *thor_func;
static inline struct f_thor *func_to_thor(struct usb_function *f)
@ -56,15 +57,15 @@ DEFINE_CACHE_ALIGN_BUFFER(char, f_name, F_NAME_BUF_SIZE + 1);
static unsigned long long int thor_file_size;
static int alt_setting_num;
static void send_rsp(const struct rsp_box *rsp)
static void send_rsp(struct udevice *udc, const struct rsp_box *rsp)
{
memcpy(thor_tx_data_buf, rsp, sizeof(struct rsp_box));
thor_tx_data(thor_tx_data_buf, sizeof(struct rsp_box));
thor_tx_data(udc, thor_tx_data_buf, sizeof(struct rsp_box));
debug("-RSP: %d, %d\n", rsp->rsp, rsp->rsp_data);
}
static void send_data_rsp(s32 ack, s32 count)
static void send_data_rsp(struct udevice *udc, s32 ack, s32 count)
{
ALLOC_CACHE_ALIGN_BUFFER(struct data_rsp_box, rsp,
sizeof(struct data_rsp_box));
@ -73,12 +74,12 @@ static void send_data_rsp(s32 ack, s32 count)
rsp->count = count;
memcpy(thor_tx_data_buf, rsp, sizeof(struct data_rsp_box));
thor_tx_data(thor_tx_data_buf, sizeof(struct data_rsp_box));
thor_tx_data(udc, thor_tx_data_buf, sizeof(struct data_rsp_box));
debug("-DATA RSP: %d, %d\n", ack, count);
}
static int process_rqt_info(const struct rqt_box *rqt)
static int process_rqt_info(struct udevice *udc, const struct rqt_box *rqt)
{
ALLOC_CACHE_ALIGN_BUFFER(struct rsp_box, rsp, sizeof(struct rsp_box));
memset(rsp, 0, sizeof(struct rsp_box));
@ -111,11 +112,11 @@ static int process_rqt_info(const struct rqt_box *rqt)
return -EINVAL;
}
send_rsp(rsp);
send_rsp(udc, rsp);
return true;
}
static int process_rqt_cmd(const struct rqt_box *rqt)
static int process_rqt_cmd(struct udevice *udc, const struct rqt_box *rqt)
{
ALLOC_CACHE_ALIGN_BUFFER(struct rsp_box, rsp, sizeof(struct rsp_box));
memset(rsp, 0, sizeof(struct rsp_box));
@ -126,7 +127,7 @@ static int process_rqt_cmd(const struct rqt_box *rqt)
switch (rqt->rqt_data) {
case RQT_CMD_REBOOT:
debug("TARGET RESET\n");
send_rsp(rsp);
send_rsp(udc, rsp);
g_dnl_unregister();
dfu_free_entities();
#ifdef CONFIG_THOR_RESET_OFF
@ -136,7 +137,7 @@ static int process_rqt_cmd(const struct rqt_box *rqt)
break;
case RQT_CMD_POWEROFF:
case RQT_CMD_EFSCLEAR:
send_rsp(rsp);
send_rsp(udc, rsp);
default:
printf("Command not supported -> cmd: %d\n", rqt->rqt_data);
return -EINVAL;
@ -145,7 +146,8 @@ static int process_rqt_cmd(const struct rqt_box *rqt)
return true;
}
static long long int download_head(unsigned long long total,
static long long int download_head(struct udevice *udc,
unsigned long long total,
unsigned int packet_size,
long long int *left,
int *cnt)
@ -166,7 +168,7 @@ static long long int download_head(unsigned long long total,
while (total - rcv_cnt >= packet_size) {
thor_set_dma(buf, packet_size);
buf += packet_size;
ret_rcv = thor_rx_data();
ret_rcv = thor_rx_data(udc);
if (ret_rcv < 0)
return ret_rcv;
rcv_cnt += ret_rcv;
@ -184,7 +186,7 @@ static long long int download_head(unsigned long long total,
}
buf = transfer_buffer;
}
send_data_rsp(0, ++usb_pkt_cnt);
send_data_rsp(udc, 0, ++usb_pkt_cnt);
}
/* Calculate the amount of data to arrive from PC (in bytes) */
@ -200,11 +202,11 @@ static long long int download_head(unsigned long long total,
if (left_to_rcv) {
thor_set_dma(buf, packet_size);
ret_rcv = thor_rx_data();
ret_rcv = thor_rx_data(udc);
if (ret_rcv < 0)
return ret_rcv;
rcv_cnt += ret_rcv;
send_data_rsp(0, ++usb_pkt_cnt);
send_data_rsp(udc, 0, ++usb_pkt_cnt);
}
debug("%s: %llu total: %llu cnt: %d\n", __func__, rcv_cnt, total, *cnt);
@ -254,7 +256,7 @@ static int download_tail(long long int left, int cnt)
return ret;
}
static long long int process_rqt_download(const struct rqt_box *rqt)
static long long int process_rqt_download(struct udevice *udc, const struct rqt_box *rqt)
{
ALLOC_CACHE_ALIGN_BUFFER(struct rsp_box, rsp, sizeof(struct rsp_box));
static long long int left, ret_head;
@ -301,8 +303,8 @@ static long long int process_rqt_download(const struct rqt_box *rqt)
}
break;
case RQT_DL_FILE_START:
send_rsp(rsp);
ret_head = download_head(thor_file_size, THOR_PACKET_SIZE,
send_rsp(udc, rsp);
ret_head = download_head(udc, thor_file_size, THOR_PACKET_SIZE,
&left, &cnt);
if (ret_head < 0) {
left = 0;
@ -324,11 +326,11 @@ static long long int process_rqt_download(const struct rqt_box *rqt)
ret = -ENOTSUPP;
}
send_rsp(rsp);
send_rsp(udc, rsp);
return ret;
}
static int process_data(void)
static int process_data(struct udevice *udc)
{
ALLOC_CACHE_ALIGN_BUFFER(struct rqt_box, rqt, sizeof(struct rqt_box));
int ret = -EINVAL;
@ -339,13 +341,13 @@ static int process_data(void)
switch (rqt->rqt) {
case RQT_INFO:
ret = process_rqt_info(rqt);
ret = process_rqt_info(udc, rqt);
break;
case RQT_CMD:
ret = process_rqt_cmd(rqt);
ret = process_rqt_cmd(udc, rqt);
break;
case RQT_DL:
ret = (int) process_rqt_download(rqt);
ret = (int) process_rqt_download(udc, rqt);
break;
case RQT_UL:
puts("RQT: UPLOAD not supported!\n");
@ -536,7 +538,7 @@ static struct usb_request *alloc_ep_req(struct usb_ep *ep, unsigned length)
return req;
}
static int thor_rx_data(void)
static int thor_rx_data(struct udevice *udc)
{
struct thor_dev *dev = thor_func->dev;
int data_to_rx, tmp, status;
@ -557,7 +559,7 @@ static int thor_rx_data(void)
}
while (!dev->rxdata) {
usb_gadget_handle_interrupts(0);
dm_usb_gadget_handle_interrupts(udc);
if (ctrlc())
return -1;
}
@ -568,7 +570,7 @@ static int thor_rx_data(void)
return tmp;
}
static void thor_tx_data(unsigned char *data, int len)
static void thor_tx_data(struct udevice *udc, unsigned char *data, int len)
{
struct thor_dev *dev = thor_func->dev;
unsigned char *ptr = dev->in_req->buf;
@ -591,7 +593,7 @@ static void thor_tx_data(unsigned char *data, int len)
/* Wait until tx interrupt received */
while (!dev->txdata)
usb_gadget_handle_interrupts(0);
dm_usb_gadget_handle_interrupts(udc);
dev->txdata = 0;
}
@ -685,18 +687,18 @@ static void thor_set_dma(void *addr, int len)
dev->out_req->length = len;
}
int thor_init(void)
int thor_init(struct udevice *udc)
{
struct thor_dev *dev = thor_func->dev;
/* Wait for a device enumeration and configuration settings */
debug("THOR enumeration/configuration setting....\n");
while (!dev->configuration_done)
usb_gadget_handle_interrupts(0);
dm_usb_gadget_handle_interrupts(udc);
thor_set_dma(thor_rx_data_buf, strlen("THOR"));
/* detect the download request from Host PC */
if (thor_rx_data() < 0) {
if (thor_rx_data(udc) < 0) {
printf("%s: Data not received!\n", __func__);
return -1;
}
@ -706,7 +708,7 @@ int thor_init(void)
udelay(30 * 1000); /* 30 ms */
strcpy((char *)thor_tx_data_buf, "ROHT");
thor_tx_data(thor_tx_data_buf, strlen("ROHT"));
thor_tx_data(udc, thor_tx_data_buf, strlen("ROHT"));
} else {
puts("Wrong reply information\n");
return -1;
@ -715,17 +717,17 @@ int thor_init(void)
return 0;
}
int thor_handle(void)
int thor_handle(struct udevice *udc)
{
int ret;
/* receive the data from Host PC */
while (1) {
thor_set_dma(thor_rx_data_buf, sizeof(struct rqt_box));
ret = thor_rx_data();
ret = thor_rx_data(udc);
if (ret > 0) {
ret = process_data();
ret = process_data(udc);
#ifdef CONFIG_THOR_RESET_OFF
if (ret == RESET_DONE)
break;

View File

@ -7,4 +7,4 @@ obj-$(CONFIG_USB_DWC3_GADGET) += udc-core.o
endif
obj-$(CONFIG_$(SPL_)DM_USB_GADGET) += udc-core.o
obj-$(CONFIG_$(SPL_)DM) += udc-uclass.o
obj-y += udc-uclass.o

View File

@ -12,55 +12,54 @@
#include <linux/usb/gadget.h>
#if CONFIG_IS_ENABLED(DM_USB_GADGET)
#define MAX_UDC_DEVICES 4
static struct udevice *dev_array[MAX_UDC_DEVICES];
int usb_gadget_initialize(int index)
int udc_device_get_by_index(int index, struct udevice **udev)
{
int ret;
struct udevice *dev = NULL;
int ret;
if (index < 0 || index >= ARRAY_SIZE(dev_array))
return -EINVAL;
if (dev_array[index])
return 0;
ret = uclass_get_device_by_seq(UCLASS_USB_GADGET_GENERIC, index, &dev);
if (!dev || ret) {
ret = uclass_get_device(UCLASS_USB_GADGET_GENERIC, index, &dev);
if (!dev || ret) {
pr_err("No USB device found\n");
return -ENODEV;
}
if (!ret && dev) {
*udev = dev;
return 0;
}
dev_array[index] = dev;
return 0;
ret = uclass_get_device(UCLASS_USB_GADGET_GENERIC, index, &dev);
if (!ret && dev) {
*udev = dev;
return 0;
}
pr_err("No USB device found\n");
return -ENODEV;
}
int usb_gadget_release(int index)
int udc_device_put(struct udevice *udev)
{
#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
int ret;
if (index < 0 || index >= ARRAY_SIZE(dev_array))
return -EINVAL;
ret = device_remove(dev_array[index], DM_REMOVE_NORMAL);
if (!ret)
dev_array[index] = NULL;
return ret;
return device_remove(udev, DM_REMOVE_NORMAL);
#else
return -ENOSYS;
#endif
}
int usb_gadget_handle_interrupts(int index)
#else
/* Backwards hardware compatibility -- switch to DM_USB_GADGET */
static int legacy_index;
int udc_device_get_by_index(int index, struct udevice **udev)
{
if (index < 0 || index >= ARRAY_SIZE(dev_array))
return -EINVAL;
return dm_usb_gadget_handle_interrupts(dev_array[index]);
legacy_index = index;
return board_usb_init(index, USB_INIT_DEVICE);
}
int udc_device_put(struct udevice *udev)
{
return board_usb_cleanup(legacy_index, USB_INIT_DEVICE);
}
#endif
#if CONFIG_IS_ENABLED(DM)
UCLASS_DRIVER(usb_gadget_generic) = {
.id = UCLASS_USB_GADGET_GENERIC,
.name = "usb",
.flags = DM_UC_FLAG_SEQ_ALIAS,
};
#endif

View File

@ -124,11 +124,12 @@ static int sandbox_submit_int(struct udevice *bus, struct usb_device *udev,
return ret;
}
int usb_gadget_handle_interrupts(int index)
#if CONFIG_IS_ENABLED(DM_USB_GADGET)
int dm_usb_gadget_handle_interrupts(struct udevice *dev)
{
return 0;
}
#else
int usb_gadget_register_driver(struct usb_gadget_driver *driver)
{
struct sandbox_udc *dev = this_controller;
@ -144,6 +145,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
return 0;
}
#endif
static int sandbox_alloc_device(struct udevice *dev, struct usb_device *udev)
{

View File

@ -376,7 +376,7 @@ struct dm_usb_ops musb_usb_ops = {
#if defined(CONFIG_USB_MUSB_GADGET) && !CONFIG_IS_ENABLED(DM_USB_GADGET)
static struct musb *gadget;
int usb_gadget_handle_interrupts(int index)
int dm_usb_gadget_handle_interrupts(struct udevice *dev)
{
schedule();
if (!gadget || !gadget->isr)

View File

@ -27,5 +27,5 @@ struct dwc3_omap_device {
int dwc3_omap_uboot_init(struct dwc3_omap_device *dev);
void dwc3_omap_uboot_exit(int index);
int dwc3_omap_uboot_interrupt_status(int index);
int dwc3_omap_uboot_interrupt_status(struct udevice *dev);
#endif /* __DWC3_OMAP_UBOOT_H_ */

View File

@ -44,7 +44,7 @@ struct dwc3_device {
int dwc3_uboot_init(struct dwc3_device *dev);
void dwc3_uboot_exit(int index);
void dwc3_uboot_handle_interrupt(int index);
void dwc3_uboot_handle_interrupt(struct udevice *dev);
struct phy;
#if CONFIG_IS_ENABLED(PHY) && CONFIG_IS_ENABLED(DM_USB)

View File

@ -968,23 +968,23 @@ extern struct usb_ep *usb_ep_autoconfig(struct usb_gadget *,
extern void usb_ep_autoconfig_reset(struct usb_gadget *);
extern int usb_gadget_handle_interrupts(int index);
extern int dm_usb_gadget_handle_interrupts(struct udevice *);
#if CONFIG_IS_ENABLED(DM_USB_GADGET)
int usb_gadget_initialize(int index);
int usb_gadget_release(int index);
int dm_usb_gadget_handle_interrupts(struct udevice *dev);
#else
#include <usb.h>
static inline int usb_gadget_initialize(int index)
{
return board_usb_init(index, USB_INIT_DEVICE);
}
/**
* udc_device_get_by_index() - Get UDC udevice by index
* @index: UDC device index
* @udev: UDC udevice matching the index (if found)
*
* Return: 0 if Ok, -ve on error
*/
int udc_device_get_by_index(int index, struct udevice **udev);
static inline int usb_gadget_release(int index)
{
return board_usb_cleanup(index, USB_INIT_DEVICE);
}
#endif
/**
* udc_device_put() - Put UDC udevice
* @udev: UDC udevice
*
* Return: 0 if Ok, -ve on error
*/
int udc_device_put(struct udevice *udev);
#endif /* __LINUX_USB_GADGET_H */

View File

@ -9,15 +9,15 @@
#ifndef __SDP_H_
#define __SDP_H_
int sdp_init(int controller_index);
int sdp_init(struct udevice *udc);
#ifdef CONFIG_SPL_BUILD
#include <spl.h>
int spl_sdp_handle(int controller_index, struct spl_image_info *spl_image,
int spl_sdp_handle(struct udevice *udc, struct spl_image_info *spl_image,
struct spl_boot_device *bootdev);
#else
int sdp_handle(int controller_index);
int sdp_handle(struct udevice *udc);
#endif
#endif /* __SDP_H_ */

View File

@ -14,7 +14,7 @@
#define THOR_DFU_REINIT_NEEDED 0xFFFFFFFE
int thor_handle(void);
int thor_init(void);
int thor_handle(struct udevice *udc);
int thor_init(struct udevice *udc);
int thor_add(struct usb_configuration *c);
#endif /* __THOR_H_ */

View File

@ -25,7 +25,7 @@ struct ums {
struct blk_desc block_dev;
};
int fsg_init(struct ums *ums_devs, int count, unsigned int controller_idx);
int fsg_init(struct ums *ums_devs, int count, struct udevice *udc);
void fsg_cleanup(void);
int fsg_main_thread(void *);
int fsg_add(struct usb_configuration *c);