Skip to content

Commit

Permalink
added timeout when force entering UMS mode
Browse files Browse the repository at this point in the history
Change-Id: I971d105a86628fa4282d1d801e05fabebf0b6569
Reviewed-on: https://tp-biosrd-v02/gerrit/82236
Reviewed-by: Jamess Huang(黃以民) <Jamess_Huang@asus.com>
Tested-by: Jamess Huang(黃以民) <Jamess_Huang@asus.com>
  • Loading branch information
jamess-huang committed Feb 22, 2018
1 parent 3fb8da4 commit 879646d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
4 changes: 3 additions & 1 deletion arch/arm/mach-rockchip/rk3288-board.c
Expand Up @@ -101,6 +101,7 @@ void usb_current_limit_ctrl(bool unlock_current)
{
int tmp;

printf("%s: unlock_current = %d\n", __func__, unlock_current);
tmp = readl(RKIO_GPIO6_PHYS + GPIO_SWPORT_DR);
if(unlock_current == true)
writel(tmp | 0x40, RKIO_GPIO6_PHYS + GPIO_SWPORT_DR);
Expand All @@ -120,6 +121,7 @@ void rk3288_maskrom_ctrl(bool enable_emmc)
{
int tmp;

printf("%s: enable_emmc = %d\n", __func__, enable_emmc);
tmp = readl(RKIO_GPIO6_PHYS + GPIO_SWPORT_DR);
if(enable_emmc == true)
writel(tmp | 0x80, RKIO_GPIO6_PHYS + GPIO_SWPORT_DR);
Expand Down Expand Up @@ -163,7 +165,7 @@ int check_force_enter_ums_mode(void)
// GPIO6_A5 set to input
tmp = readl(RKIO_GPIO6_PHYS + GPIO_SWPORT_DDR);
writel(tmp & ~(0x20), RKIO_GPIO6_PHYS + GPIO_SWPORT_DDR);

mdelay(10);

// read GPIO2_A3/GPIO2_A2/GPIO2_A1 value
Expand Down
4 changes: 4 additions & 0 deletions cmd/usb_mass_storage.c
Expand Up @@ -215,6 +215,10 @@ int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
usb_gadget_handle_interrupts(controller_index);

rc = fsg_main_thread(NULL);

if (rc == -ETIMEDOUT) {
goto cleanup_register;
}
if (rc) {
/* Check I/O error */
if (rc == -EIO)
Expand Down
8 changes: 6 additions & 2 deletions common/autoboot.c
Expand Up @@ -29,6 +29,7 @@ DECLARE_GLOBAL_DATA_PTR;
static int stored_bootdelay;

bool force_ums = false;
bool getdescriptor = false;

#if defined(CONFIG_AUTOBOOT_KEYED)
#if defined(CONFIG_AUTOBOOT_STOP_STR_SHA256)
Expand Down Expand Up @@ -356,8 +357,11 @@ void autoboot_command(const char *s)
local_args[1]=str2;
local_args[2]=str3;
local_args[3]=str4;
do_usb_mass_storage(NULL, 0, 4, local_args);
return;

if (do_usb_mass_storage(NULL, 0, 4, local_args) == -ETIMEDOUT) {
rk3288_maskrom_ctrl(false);
usb_current_limit_ctrl(false);
}
}

if (stored_bootdelay != -1 && s && !abortboot(stored_bootdelay)) {
Expand Down
1 change: 1 addition & 0 deletions drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c 100644 → 100755
Expand Up @@ -1368,6 +1368,7 @@ static void dwc2_ep0_setup(struct dwc2_udc *dev)
debug_cond(DEBUG_SETUP != 0,
"%s: *** USB_REQ_GET_DESCRIPTOR\n",
__func__);
getdescriptor = true;
break;

case USB_REQ_SET_INTERFACE:
Expand Down
10 changes: 9 additions & 1 deletion drivers/usb/gadget/f_mass_storage.c 100644 → 100755
Expand Up @@ -666,7 +666,7 @@ static void busy_indicator(void)
static int sleep_thread(struct fsg_common *common)
{
int rc = 0;
int i = 0, k = 0;
int i = 0, k = 0, j = 0;

/* Wait until a signal arrives or we are woken up */
for (;;) {
Expand All @@ -677,6 +677,7 @@ static int sleep_thread(struct fsg_common *common)
busy_indicator();
i = 0;
k++;
j++;
}

if (k == 10) {
Expand All @@ -691,6 +692,13 @@ static int sleep_thread(struct fsg_common *common)
k = 0;
}

if (j == 300) { //about 3 seconds
if(force_ums && !getdescriptor) {
printf("wait for usb get descriptor cmd timeout\n");
return -ETIMEDOUT;
}
}

usb_gadget_handle_interrupts(0);
}
common->thread_wakeup_needed = 0;
Expand Down
3 changes: 3 additions & 0 deletions include/linux/usb/gadget.h 100644 → 100755
Expand Up @@ -24,6 +24,9 @@

struct usb_ep;

extern bool force_ums;
extern bool getdescriptor;

/**
* struct usb_request - describes one i/o request
* @buf: Buffer used for data. Always provide this; some controllers
Expand Down

0 comments on commit 879646d

Please sign in to comment.