Skip to content

Commit

Permalink
Merge branch 'master' of git://git.denx.de/u-boot-usb
Browse files Browse the repository at this point in the history
  • Loading branch information
trini committed Oct 6, 2014
2 parents 04de09f + e214058 commit 8a6b088
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 86 deletions.
27 changes: 15 additions & 12 deletions common/cmd_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,16 @@ static int do_usbboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
}
#endif /* CONFIG_USB_STORAGE */

static int do_usb_stop_keyboard(int force)
{
#ifdef CONFIG_USB_KEYBOARD
if (usb_kbd_deregister(force) != 0) {
printf("USB not stopped: usbkbd still using USB\n");
return 1;
}
#endif
return 0;
}

/******************************************************************************
* usb command intepreter
Expand All @@ -450,6 +460,8 @@ static int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
if ((strncmp(argv[1], "reset", 5) == 0) ||
(strncmp(argv[1], "start", 5) == 0)) {
bootstage_mark_name(BOOTSTAGE_ID_USB_START, "usb_start");
if (do_usb_stop_keyboard(1) != 0)
return 1;
usb_stop();
printf("(Re)start USB...\n");
if (usb_init() >= 0) {
Expand All @@ -468,19 +480,10 @@ static int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return 0;
}
if (strncmp(argv[1], "stop", 4) == 0) {
#ifdef CONFIG_USB_KEYBOARD
if (argc == 2) {
if (usb_kbd_deregister() != 0) {
printf("USB not stopped: usbkbd still"
" using USB\n");
return 1;
}
} else {
/* forced stop, switch console in to serial */
if (argc != 2)
console_assign(stdin, "serial");
usb_kbd_deregister();
}
#endif
if (do_usb_stop_keyboard(0) != 0)
return 1;
printf("stopping USB..\n");
usb_stop();
return 0;
Expand Down
13 changes: 10 additions & 3 deletions common/stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" };
#define CONFIG_SYS_DEVICE_NULLDEV 1
#endif

#ifdef CONFIG_SYS_STDIO_DEREGISTER
#define CONFIG_SYS_DEVICE_NULLDEV 1
#endif

#ifdef CONFIG_SYS_DEVICE_NULLDEV
void nulldev_putc(struct stdio_dev *dev, const char c)
Expand Down Expand Up @@ -172,7 +175,7 @@ int stdio_register(struct stdio_dev *dev)
* returns 0 if success, -1 if device is assigned and 1 if devname not found
*/
#ifdef CONFIG_SYS_STDIO_DEREGISTER
int stdio_deregister_dev(struct stdio_dev *dev)
int stdio_deregister_dev(struct stdio_dev *dev, int force)
{
int l;
struct list_head *pos;
Expand All @@ -181,6 +184,10 @@ int stdio_deregister_dev(struct stdio_dev *dev)
/* get stdio devices (ListRemoveItem changes the dev list) */
for (l=0 ; l< MAX_FILES; l++) {
if (stdio_devices[l] == dev) {
if (force) {
strcpy(temp_names[l], "nulldev");
continue;
}
/* Device is assigned -> report error */
return -1;
}
Expand All @@ -202,7 +209,7 @@ int stdio_deregister_dev(struct stdio_dev *dev)
return 0;
}

int stdio_deregister(const char *devname)
int stdio_deregister(const char *devname, int force)
{
struct stdio_dev *dev;

Expand All @@ -211,7 +218,7 @@ int stdio_deregister(const char *devname)
if (!dev) /* device not found */
return -ENODEV;

return stdio_deregister_dev(dev);
return stdio_deregister_dev(dev, force);
}
#endif /* CONFIG_SYS_STDIO_DEREGISTER */

Expand Down
26 changes: 11 additions & 15 deletions common/usb_kbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <errno.h>
#include <malloc.h>
#include <stdio_dev.h>
#include <asm/byteorder.h>
Expand Down Expand Up @@ -170,11 +171,12 @@ static void usb_kbd_setled(struct usb_device *dev)
{
struct usb_interface *iface = &dev->config.if_desc[0];
struct usb_kbd_pdata *data = dev->privptr;
uint32_t leds = data->flags & USB_KBD_LEDMASK;
ALLOC_ALIGN_BUFFER(uint32_t, leds, 1, USB_DMA_MINALIGN);

*leds = data->flags & USB_KBD_LEDMASK;
usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
USB_REQ_SET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
0x200, iface->desc.bInterfaceNumber, (void *)&leds, 1, 0);
0x200, iface->desc.bInterfaceNumber, leds, 1, 0);
}

#define CAPITAL_MASK 0x20
Expand Down Expand Up @@ -488,7 +490,7 @@ static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum)
/* Search for keyboard and register it if found. */
int drv_usb_kbd_init(void)
{
struct stdio_dev usb_kbd_dev, *old_dev;
struct stdio_dev usb_kbd_dev;
struct usb_device *dev;
char *stdinname = getenv("stdin");
int error, i;
Expand All @@ -507,16 +509,6 @@ int drv_usb_kbd_init(void)
if (usb_kbd_probe(dev, 0) != 1)
continue;

/* We found a keyboard, check if it is already registered. */
debug("USB KBD: found set up device.\n");
old_dev = stdio_get_by_name(DEVNAME);
if (old_dev) {
/* Already registered, just return ok. */
debug("USB KBD: is already registered.\n");
usb_kbd_deregister();
return 1;
}

/* Register the keyboard */
debug("USB KBD: register.\n");
memset(&usb_kbd_dev, 0, sizeof(struct stdio_dev));
Expand Down Expand Up @@ -555,10 +547,14 @@ int drv_usb_kbd_init(void)
}

/* Deregister the keyboard. */
int usb_kbd_deregister(void)
int usb_kbd_deregister(int force)
{
#ifdef CONFIG_SYS_STDIO_DEREGISTER
return stdio_deregister(DEVNAME);
int ret = stdio_deregister(DEVNAME, force);
if (ret && ret != -ENODEV)
return ret;

return 0;
#else
return 1;
#endif
Expand Down
2 changes: 1 addition & 1 deletion drivers/serial/serial-uclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ static int serial_pre_remove(struct udevice *dev)
#ifdef CONFIG_SYS_STDIO_DEREGISTER
struct serial_dev_priv *upriv = dev->uclass_priv;

if (stdio_deregister_dev(upriv->sdev))
if (stdio_deregister_dev(upriv->sdev), 0)
return -EPERM;
#endif

Expand Down
5 changes: 5 additions & 0 deletions drivers/usb/gadget/ci_udc.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,11 @@ static int ci_pullup(struct usb_gadget *gadget, int is_on)
/* select DEVICE mode */
writel(USBMODE_DEVICE, &udc->usbmode);

#if !defined(CONFIG_USB_GADGET_DUALSPEED)
/* Port force Full-Speed Connect */
setbits_le32(&udc->portsc, PFSC);
#endif

writel(0xffffffff, &udc->epflush);

/* Turn on the USB connection by enabling the pullup resistor */
Expand Down
11 changes: 3 additions & 8 deletions drivers/usb/gadget/f_dfu.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ static struct usb_descriptor_header *dfu_runtime_descs[] = {
NULL,
};

static const struct usb_qualifier_descriptor dev_qualifier = {
.bLength = sizeof dev_qualifier,
.bDescriptorType = USB_DT_DEVICE_QUALIFIER,
.bcdUSB = __constant_cpu_to_le16(0x0200),
.bDeviceClass = USB_CLASS_VENDOR_SPEC,
.bNumConfigurations = 1,
};

static const char dfu_name[] = "Device Firmware Upgrade";

/*
Expand Down Expand Up @@ -237,13 +229,15 @@ static inline void to_dfu_mode(struct f_dfu *f_dfu)
{
f_dfu->usb_function.strings = dfu_strings;
f_dfu->usb_function.hs_descriptors = f_dfu->function;
f_dfu->usb_function.descriptors = f_dfu->function;
f_dfu->dfu_state = DFU_STATE_dfuIDLE;
}

static inline void to_runtime_mode(struct f_dfu *f_dfu)
{
f_dfu->usb_function.strings = NULL;
f_dfu->usb_function.hs_descriptors = dfu_runtime_descs;
f_dfu->usb_function.descriptors = dfu_runtime_descs;
}

static int handle_upload(struct usb_request *req, u16 len)
Expand Down Expand Up @@ -808,6 +802,7 @@ static int dfu_bind_config(struct usb_configuration *c)
return -ENOMEM;
f_dfu->usb_function.name = "dfu";
f_dfu->usb_function.hs_descriptors = dfu_runtime_descs;
f_dfu->usb_function.descriptors = dfu_runtime_descs;
f_dfu->usb_function.bind = dfu_bind;
f_dfu->usb_function.unbind = dfu_unbind;
f_dfu->usb_function.set_alt = dfu_set_alt;
Expand Down
28 changes: 20 additions & 8 deletions drivers/usb/gadget/f_fastboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,11 @@ static void cb_getvar(struct usb_ep *ep, struct usb_request *req)
strncat(response, FASTBOOT_VERSION, chars_left);
} else if (!strcmp_l1("bootloader-version", cmd)) {
strncat(response, U_BOOT_VERSION, chars_left);
} else if (!strcmp_l1("downloadsize", cmd)) {
} else if (!strcmp_l1("downloadsize", cmd) ||
!strcmp_l1("max-download-size", cmd)) {
char str_num[12];

sprintf(str_num, "%08x", CONFIG_USB_FASTBOOT_BUF_SIZE);
sprintf(str_num, "0x%08x", CONFIG_USB_FASTBOOT_BUF_SIZE);
strncat(response, str_num, chars_left);
} else if (!strcmp_l1("serialno", cmd)) {
s = getenv("serial#");
Expand Down Expand Up @@ -386,6 +387,7 @@ static void rx_handler_dl_image(struct usb_ep *ep, struct usb_request *req)
unsigned int transfer_size = download_size - download_bytes;
const unsigned char *buffer = req->buf;
unsigned int buffer_size = req->actual;
unsigned int pre_dot_num, now_dot_num;

if (req->status != 0) {
printf("Bad status: %d\n", req->status);
Expand All @@ -398,7 +400,15 @@ static void rx_handler_dl_image(struct usb_ep *ep, struct usb_request *req)
memcpy((void *)CONFIG_USB_FASTBOOT_BUF_ADDR + download_bytes,
buffer, transfer_size);

pre_dot_num = download_bytes / BYTES_PER_DOT;
download_bytes += transfer_size;
now_dot_num = download_bytes / BYTES_PER_DOT;

if (pre_dot_num != now_dot_num) {
putc('.');
if (!(now_dot_num % 74))
putc('\n');
}

/* Check if transfer is done */
if (download_bytes >= download_size) {
Expand All @@ -420,11 +430,6 @@ static void rx_handler_dl_image(struct usb_ep *ep, struct usb_request *req)
req->length = ep->maxpacket;
}

if (download_bytes && !(download_bytes % BYTES_PER_DOT)) {
putc('.');
if (!(download_bytes % (74 * BYTES_PER_DOT)))
putc('\n');
}
req->actual = 0;
usb_ep_queue(ep, req, 0);
}
Expand Down Expand Up @@ -541,7 +546,14 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
error("unknown command: %s\n", cmdbuf);
fastboot_tx_write_str("FAILunknown command");
} else {
func_cb(ep, req);
if (req->actual < req->length) {
u8 *buf = (u8 *)req->buf;
buf[req->actual] = 0;
func_cb(ep, req);
} else {
error("buffer overflow\n");
fastboot_tx_write_str("FAILbuffer overflow");
}
}

if (req->status == 0) {
Expand Down
1 change: 1 addition & 0 deletions drivers/usb/gadget/f_mass_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,7 @@ static int do_inquiry(struct fsg_common *common, struct fsg_buffhd *bh)

memset(buf, 0, 8);
buf[0] = TYPE_DISK;
buf[1] = curlun->removable ? 0x80 : 0;
buf[2] = 2; /* ANSI SCSI level 2 */
buf[3] = 2; /* SCSI-2 INQUIRY data format */
buf[4] = 31; /* Additional length */
Expand Down
10 changes: 0 additions & 10 deletions drivers/usb/gadget/f_thor.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,16 +458,6 @@ static struct usb_endpoint_descriptor hs_int_desc = {
.bInterval = 0x9,
};

static struct usb_qualifier_descriptor dev_qualifier = {
.bLength = sizeof(dev_qualifier),
.bDescriptorType = USB_DT_DEVICE_QUALIFIER,

.bcdUSB = __constant_cpu_to_le16(0x0200),
.bDeviceClass = USB_CLASS_VENDOR_SPEC,

.bNumConfigurations = 2,
};

/*
* This attribute vendor descriptor is necessary for correct operation with
* Windows version of THOR download program
Expand Down
Loading

0 comments on commit 8a6b088

Please sign in to comment.