From ede4d5e3872d04c75a30c5e234786b012f1c6d34 Mon Sep 17 00:00:00 2001 From: Nobuhiro Iwamatsu Date: Thu, 3 Apr 2014 13:55:54 +0900 Subject: usb: ehci: rmobile: Add support ehci host driver of rmobile SoCs The rmobile SoC has usb host controller. This supports USB controllers listed in the R8A7790, R8A7791 and R8A7740. Signed-off-by: Nobuhiro Iwamatsu Reviewed-by: Marek Vasut --- arch/arm/include/asm/arch-rmobile/ehci-rmobile.h | 147 +++++++++++++++++++++++ drivers/usb/host/Makefile | 1 + drivers/usb/host/ehci-rmobile.c | 130 ++++++++++++++++++++ 3 files changed, 278 insertions(+) create mode 100644 arch/arm/include/asm/arch-rmobile/ehci-rmobile.h create mode 100644 drivers/usb/host/ehci-rmobile.c diff --git a/arch/arm/include/asm/arch-rmobile/ehci-rmobile.h b/arch/arm/include/asm/arch-rmobile/ehci-rmobile.h new file mode 100644 index 0000000..463654e --- /dev/null +++ b/arch/arm/include/asm/arch-rmobile/ehci-rmobile.h @@ -0,0 +1,147 @@ +/* + * Copyright (C) 2013,2014 Renesas Electronics Corporation + * Copyright (C) 2014 Nobuhiro Iwamatsu + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#ifndef __EHCI_RMOBILE_H__ +#define __EHCI_RMOBILE_H__ + +/* Register offset */ +#define OHCI_OFFSET 0x00 +#define OHCI_SIZE 0x1000 +#define EHCI_OFFSET 0x1000 +#define EHCI_SIZE 0x1000 + +#define EHCI_USBCMD (EHCI_OFFSET + 0x0020) + +/* USBCTR */ +#define DIRPD (1 << 8) +#define PLL_RST (1 << 2) +#define PCICLK_MASK (1 << 1) +#define USBH_RST (1 << 0) + +/* CMND_STS */ +#define SERREN (1 << 8) +#define PERREN (1 << 6) +#define MASTEREN (1 << 2) +#define MEMEN (1 << 1) + +/* PCIAHB_WIN1_CTR and PCIAHB_WIN2_CTR */ +#define PCIAHB_WIN_PREFETCH ((1 << 1)|(1 << 0)) + +/* AHBPCI_WIN1_CTR */ +#define PCIWIN1_PCICMD ((1 << 3)|(1 << 1)) +#define AHB_CFG_AHBPCI 0x40000000 +#define AHB_CFG_HOST 0x80000000 + +/* AHBPCI_WIN2_CTR */ +#define PCIWIN2_PCICMD ((1 << 2)|(1 << 1)) + +/* PCI_INT_ENABLE */ +#define USBH_PMEEN (1 << 19) +#define USBH_INTBEN (1 << 17) +#define USBH_INTAEN (1 << 16) + +/* AHB_BUS_CTR */ +#define SMODE_READY_CTR (1 << 17) +#define SMODE_READ_BURST (1 << 16) +#define MMODE_HBUSREQ (1 << 7) +#define MMODE_BOUNDARY ((1 << 6)|(1 << 5)) +#define MMODE_BURST_WIDTH ((1 << 4)|(1 << 3)) +#define MMODE_SINGLE_MODE ((1 << 4)|(1 << 3)) +#define MMODE_WR_INCR (1 << 2) +#define MMODE_BYTE_BURST (1 << 1) +#define MMODE_HTRANS (1 << 0) + +/* PCI_ARBITER_CTR */ +#define PCIBUS_PARK_TIMER 0x00FF0000 +#define PCIBUS_PARK_TIMER_SET 0x00070000 +#define PCIBP_MODE (1 << 12) +#define PCIREQ7 (1 << 7) +#define PCIREQ6 (1 << 6) +#define PCIREQ5 (1 << 5) +#define PCIREQ4 (1 << 4) +#define PCIREQ3 (1 << 3) +#define PCIREQ2 (1 << 2) +#define PCIREQ1 (1 << 1) +#define PCIREQ0 (1 << 0) + +#define SMSTPCR7 0xE615014C +#define SMSTPCR703 (1 << 3) + +/* Init AHB master and slave functions of the host logic */ +#define AHB_BUS_CTR_INIT \ + (SMODE_READY_CTR | MMODE_HBUSREQ | MMODE_WR_INCR | \ + MMODE_BYTE_BURST | MMODE_HTRANS) + +#define USBCTR_WIN_SIZE_1GB 0x800 + +/* PCI Configuration Registers */ +#define PCI_CONF_OHCI_OFFSET 0x10000 +#define PCI_CONF_EHCI_OFFSET 0x10100 +struct ahb_pciconf { + u32 vid_did; + u32 cmnd_sts; + u32 rev; + u32 cache_line; + u32 basead; +}; + +/* PCI Configuration Registers for AHB-PCI Bridge Registers */ +#define PCI_CONF_AHBPCI_OFFSET 0x10000 +struct ahbconf_pci_bridge { + u32 vid_did; /* 0x00 */ + u32 cmnd_sts; + u32 revid_cc; + u32 cls_lt_ht_bist; + u32 basead; /* 0x10 */ + u32 win1_basead; + u32 win2_basead; + u32 dummy0[5]; + u32 ssvdi_ssid; /* 0x2C */ + u32 dummy1[4]; + u32 intr_line_pin; +}; + +/* AHB-PCI Bridge PCI Communication Registers */ +#define AHBPCI_OFFSET 0x10800 +struct ahbcom_pci_bridge { + u32 pciahb_win1_ctr; /* 0x00 */ + u32 pciahb_win2_ctr; + u32 pciahb_dct_ctr; + u32 dummy0; + u32 ahbpci_win1_ctr; /* 0x10 */ + u32 ahbpci_win2_ctr; + u32 dummy1; + u32 ahbpci_dct_ctr; + u32 pci_int_enable; /* 0x20 */ + u32 pci_int_status; + u32 dummy2[2]; + u32 ahb_bus_ctr; /* 0x30 */ + u32 usbctr; + u32 dummy3[2]; + u32 pci_arbiter_ctr; /* 0x40 */ + u32 dummy4; + u32 pci_unit_rev; /* 0x48 */ +}; + +struct rmobile_ehci_reg { + u32 hciversion; /* hciversion/caplength */ + u32 hcsparams; /* hcsparams */ + u32 hccparams; /* hccparams */ + u32 hcsp_portroute; /* hcsp_portroute */ + u32 usbcmd; /* usbcmd */ + u32 usbsts; /* usbsts */ + u32 usbintr; /* usbintr */ + u32 frindex; /* frindex */ + u32 ctrldssegment; /* ctrldssegment */ + u32 periodiclistbase; /* periodiclistbase */ + u32 asynclistaddr; /* asynclistaddr */ + u32 dummy[9]; + u32 configflag; /* configflag */ + u32 portsc; /* portsc */ +}; + +#endif /* __EHCI_RMOBILE_H__ */ diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile index 578b097..b301e28 100644 --- a/drivers/usb/host/Makefile +++ b/drivers/usb/host/Makefile @@ -36,6 +36,7 @@ obj-$(CONFIG_USB_EHCI_PCI) += ehci-pci.o obj-$(CONFIG_USB_EHCI_SPEAR) += ehci-spear.o obj-$(CONFIG_USB_EHCI_TEGRA) += ehci-tegra.o obj-$(CONFIG_USB_EHCI_VCT) += ehci-vct.o +obj-$(CONFIG_USB_EHCI_RMOBILE) += ehci-rmobile.o # xhci obj-$(CONFIG_USB_XHCI) += xhci.o xhci-mem.o xhci-ring.o diff --git a/drivers/usb/host/ehci-rmobile.c b/drivers/usb/host/ehci-rmobile.c new file mode 100644 index 0000000..049e4c4 --- /dev/null +++ b/drivers/usb/host/ehci-rmobile.c @@ -0,0 +1,130 @@ +/* + * EHCI HCD (Host Controller Driver) for USB. + * + * Copyright (C) 2013,2014 Renesas Electronics Corporation + * Copyright (C) 2014 Nobuhiro Iwamatsu + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#include +#include +#include +#include "ehci.h" + +#if defined(CONFIG_R8A7740) +static u32 usb_base_address[CONFIG_USB_MAX_CONTROLLER_COUNT] = { + 0xC6700000 +}; +#elif defined(CONFIG_R8A7790) +static u32 usb_base_address[CONFIG_USB_MAX_CONTROLLER_COUNT] = { + 0xEE080000, /* USB0 (EHCI) */ + 0xEE0A0000, /* USB1 */ + 0xEE0C0000, /* USB2 */ + 0xEE000000 /* USB3 (USB3.0 Host)*/ +}; +#elif defined(CONFIG_R8A7791) +static u32 usb_base_address[CONFIG_USB_MAX_CONTROLLER_COUNT] = { + 0xEE080000, /* USB0 (EHCI) */ + 0xEE0C0000, /* USB1 */ + 0xEE000000 /* USB3 (USB3.0 Host)*/ +}; +#else +#error rmobile EHCI USB driver not supported on this platform +#endif + +int ehci_hcd_stop(int index) +{ + int i; + u32 base; + struct ahbcom_pci_bridge *ahbcom_pci; + + base = usb_base_address[index]; + ahbcom_pci = (struct ahbcom_pci_bridge *)(base + AHBPCI_OFFSET); + writel(0, &ahbcom_pci->ahb_bus_ctr); + + /* reset ehci */ + setbits_le32(base + EHCI_USBCMD, CMD_RESET); + for (i = 100; i > 0; i--) { + if (!(readl(base + EHCI_USBCMD) & CMD_RESET)) + break; + udelay(100); + } + + if (!i) + printf("error : ehci(%d) reset failed.\n", index); + + if (index == (CONFIG_USB_MAX_CONTROLLER_COUNT - 1)) + setbits_le32(SMSTPCR7, SMSTPCR703); + + return 0; +} + +int ehci_hcd_init(int index, enum usb_init_type init, + struct ehci_hccr **hccr, struct ehci_hcor **hcor) +{ + u32 base; + u32 phys_base; + struct rmobile_ehci_reg *rehci; + struct ahbcom_pci_bridge *ahbcom_pci; + struct ahbconf_pci_bridge *ahbconf_pci; + struct ahb_pciconf *ahb_pciconf_ohci; + struct ahb_pciconf *ahb_pciconf_ehci; + uint32_t cap_base; + + base = usb_base_address[index]; + phys_base = base; + if (index == 0) + clrbits_le32(SMSTPCR7, SMSTPCR703); + + rehci = (struct rmobile_ehci_reg *)(base + EHCI_OFFSET); + ahbcom_pci = (struct ahbcom_pci_bridge *)(base + AHBPCI_OFFSET); + ahbconf_pci = + (struct ahbconf_pci_bridge *)(base + PCI_CONF_AHBPCI_OFFSET); + ahb_pciconf_ohci = (struct ahb_pciconf *)(base + PCI_CONF_OHCI_OFFSET); + ahb_pciconf_ehci = (struct ahb_pciconf *)(base + PCI_CONF_EHCI_OFFSET); + + /* Clock & Reset & Direct Power Down */ + clrsetbits_le32(&ahbcom_pci->usbctr, + (DIRPD | PCICLK_MASK | USBH_RST), USBCTR_WIN_SIZE_1GB); + clrbits_le32(&ahbcom_pci->usbctr, PLL_RST); + + /* AHB-PCI Bridge Communication Registers */ + writel(AHB_BUS_CTR_INIT, &ahbcom_pci->ahb_bus_ctr); + writel((CONFIG_SYS_SDRAM_BASE & 0xf0000000) | PCIAHB_WIN_PREFETCH, + &ahbcom_pci->pciahb_win1_ctr); + writel(0xf0000000 | PCIAHB_WIN_PREFETCH, + &ahbcom_pci->pciahb_win2_ctr); + writel(phys_base | PCIWIN2_PCICMD, &ahbcom_pci->ahbpci_win2_ctr); + + setbits_le32(&ahbcom_pci->pci_arbiter_ctr, + PCIBP_MODE | PCIREQ1 | PCIREQ0); + + /* PCI Configuration Registers for AHBPCI */ + writel(PCIWIN1_PCICMD | AHB_CFG_AHBPCI, + &ahbcom_pci->ahbpci_win1_ctr); + writel(phys_base + AHBPCI_OFFSET, &ahbconf_pci->basead); + writel(CONFIG_SYS_SDRAM_BASE & 0xf0000000, &ahbconf_pci->win1_basead); + writel(0xf0000000, &ahbconf_pci->win2_basead); + writel(SERREN | PERREN | MASTEREN | MEMEN, + &ahbconf_pci->cmnd_sts); + + /* PCI Configuration Registers for EHCI */ + writel(PCIWIN1_PCICMD | AHB_CFG_HOST, &ahbcom_pci->ahbpci_win1_ctr); + writel(phys_base + OHCI_OFFSET, &ahb_pciconf_ohci->basead); + writel(phys_base + EHCI_OFFSET, &ahb_pciconf_ehci->basead); + writel(SERREN | PERREN | MASTEREN | MEMEN, + &ahb_pciconf_ohci->cmnd_sts); + writel(SERREN | PERREN | MASTEREN | MEMEN, + &ahb_pciconf_ehci->cmnd_sts); + + /* Enable PCI interrupt */ + setbits_le32(&ahbcom_pci->pci_int_enable, + USBH_PMEEN | USBH_INTBEN | USBH_INTAEN); + + *hccr = (struct ehci_hccr *)((uint32_t)&rehci->hciversion); + cap_base = ehci_readl(&(*hccr)->cr_capbase); + *hcor = (struct ehci_hcor *)((uint32_t)*hccr + HC_LENGTH(cap_base)); + + return 0; +} -- cgit v1.1 From ea427775677a4147147b64fce4d0ad1acac04e47 Mon Sep 17 00:00:00 2001 From: Adrian Cox Date: Thu, 10 Apr 2014 13:29:45 +0100 Subject: usb: Add endian support macros to interrupt transfers in the EHCI driver. Update the EHCI driver to support interrupt transfers on PowerPC. Signed-off-by: Adrian Cox --- drivers/usb/host/ehci-hcd.c | 56 +++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 6017090..eaf5913 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c @@ -998,8 +998,8 @@ int usb_lowlevel_init(int index, enum usb_init_type init, void **controller) if (!ehcic[index].periodic_list) return -ENOMEM; for (i = 0; i < 1024; i++) { - ehcic[index].periodic_list[i] = (uint32_t)periodic - | QH_LINK_TYPE_QH; + ehcic[index].periodic_list[i] = cpu_to_hc32((uint32_t)periodic + | QH_LINK_TYPE_QH); } flush_dcache_range((uint32_t)ehcic[index].periodic_list, @@ -1089,7 +1089,7 @@ struct int_queue { struct qTD *tds; }; -#define NEXT_QH(qh) (struct QH *)((qh)->qh_link & ~0x1f) +#define NEXT_QH(qh) (struct QH *)(hc32_to_cpu((qh)->qh_link) & ~0x1f) static int enable_periodic(struct ehci_ctrl *ctrl) @@ -1184,41 +1184,47 @@ create_int_queue(struct usb_device *dev, unsigned long pipe, int queuesize, struct qTD *td = result->tds + i; void **buf = &qh->buffer; - qh->qh_link = (uint32_t)(qh+1) | QH_LINK_TYPE_QH; + qh->qh_link = cpu_to_hc32((uint32_t)(qh+1) | QH_LINK_TYPE_QH); if (i == queuesize - 1) - qh->qh_link = QH_LINK_TERMINATE; + qh->qh_link = cpu_to_hc32(QH_LINK_TERMINATE); - qh->qh_overlay.qt_next = (uint32_t)td; - qh->qh_overlay.qt_altnext = QT_NEXT_TERMINATE; - qh->qh_endpt1 = (0 << 28) | /* No NAK reload (ehci 4.9) */ + qh->qh_overlay.qt_next = cpu_to_hc32((uint32_t)td); + qh->qh_overlay.qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE); + qh->qh_endpt1 = + cpu_to_hc32((0 << 28) | /* No NAK reload (ehci 4.9) */ (usb_maxpacket(dev, pipe) << 16) | /* MPS */ (1 << 14) | QH_ENDPT1_EPS(ehci_encode_speed(dev->speed)) | (usb_pipeendpoint(pipe) << 8) | /* Endpoint Number */ - (usb_pipedevice(pipe) << 0); - qh->qh_endpt2 = (1 << 30) | /* 1 Tx per mframe */ - (1 << 0); /* S-mask: microframe 0 */ + (usb_pipedevice(pipe) << 0)); + qh->qh_endpt2 = cpu_to_hc32((1 << 30) | /* 1 Tx per mframe */ + (1 << 0)); /* S-mask: microframe 0 */ if (dev->speed == USB_SPEED_LOW || dev->speed == USB_SPEED_FULL) { debug("TT: port: %d, hub address: %d\n", dev->portnr, dev->parent->devnum); - qh->qh_endpt2 |= (dev->portnr << 23) | + qh->qh_endpt2 |= cpu_to_hc32((dev->portnr << 23) | (dev->parent->devnum << 16) | - (0x1c << 8); /* C-mask: microframes 2-4 */ + (0x1c << 8)); /* C-mask: microframes 2-4 */ } - td->qt_next = QT_NEXT_TERMINATE; - td->qt_altnext = QT_NEXT_TERMINATE; + td->qt_next = cpu_to_hc32(QT_NEXT_TERMINATE); + td->qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE); debug("communication direction is '%s'\n", usb_pipein(pipe) ? "in" : "out"); - td->qt_token = (elementsize << 16) | + td->qt_token = cpu_to_hc32((elementsize << 16) | ((usb_pipein(pipe) ? 1 : 0) << 8) | /* IN/OUT token */ - 0x80; /* active */ - td->qt_buffer[0] = (uint32_t)buffer + i * elementsize; - td->qt_buffer[1] = (td->qt_buffer[0] + 0x1000) & ~0xfff; - td->qt_buffer[2] = (td->qt_buffer[0] + 0x2000) & ~0xfff; - td->qt_buffer[3] = (td->qt_buffer[0] + 0x3000) & ~0xfff; - td->qt_buffer[4] = (td->qt_buffer[0] + 0x4000) & ~0xfff; + 0x80); /* active */ + td->qt_buffer[0] = + cpu_to_hc32((uint32_t)buffer + i * elementsize); + td->qt_buffer[1] = + cpu_to_hc32((td->qt_buffer[0] + 0x1000) & ~0xfff); + td->qt_buffer[2] = + cpu_to_hc32((td->qt_buffer[0] + 0x2000) & ~0xfff); + td->qt_buffer[3] = + cpu_to_hc32((td->qt_buffer[0] + 0x3000) & ~0xfff); + td->qt_buffer[4] = + cpu_to_hc32((td->qt_buffer[0] + 0x4000) & ~0xfff); *buf = buffer + i * elementsize; } @@ -1241,7 +1247,7 @@ create_int_queue(struct usb_device *dev, unsigned long pipe, int queuesize, /* hook up to periodic list */ struct QH *list = &ctrl->periodic_queue; result->last->qh_link = list->qh_link; - list->qh_link = (uint32_t)result->first | QH_LINK_TYPE_QH; + list->qh_link = cpu_to_hc32((uint32_t)result->first | QH_LINK_TYPE_QH); flush_dcache_range((uint32_t)result->last, ALIGN_END_ADDR(struct QH, result->last, 1)); @@ -1280,7 +1286,7 @@ void *poll_int_queue(struct usb_device *dev, struct int_queue *queue) /* still active */ invalidate_dcache_range((uint32_t)cur, ALIGN_END_ADDR(struct QH, cur, 1)); - if (cur->qh_overlay.qt_token & 0x80) { + if (cur->qh_overlay.qt_token & cpu_to_hc32(0x80)) { debug("Exit poll_int_queue with no completed intr transfer. " "token is %x\n", cur->qh_overlay.qt_token); return NULL; @@ -1311,7 +1317,7 @@ destroy_int_queue(struct usb_device *dev, struct int_queue *queue) struct QH *cur = &ctrl->periodic_queue; timeout = get_timer(0) + 500; /* abort after 500ms */ - while (!(cur->qh_link & QH_LINK_TERMINATE)) { + while (!(cur->qh_link & cpu_to_hc32(QH_LINK_TERMINATE))) { debug("considering %p, with qh_link %x\n", cur, cur->qh_link); if (NEXT_QH(cur) == queue->first) { debug("found candidate. removing from chain\n"); -- cgit v1.1 From 08a98b89df39d25a1260f390c19be4649dfd303d Mon Sep 17 00:00:00 2001 From: Adrian Cox Date: Thu, 10 Apr 2014 14:02:44 +0100 Subject: usb: Fix USB keyboard polling via control endpoint USB keyboard polling failed for some keyboards on PowerPC 5020. This was caused by requesting only 4 bytes of data from keyboards that produce an 8 byte HID report. Signed-off-by: Adrian Cox Signed-off-by: Wolfgang Denk Cc: Marek Vasut --- common/usb_kbd.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/common/usb_kbd.c b/common/usb_kbd.c index 1ad67ca..0b77c16 100644 --- a/common/usb_kbd.c +++ b/common/usb_kbd.c @@ -91,6 +91,12 @@ static const unsigned char usb_kbd_arrow[] = { #define USB_KBD_LEDMASK \ (USB_KBD_NUMLOCK | USB_KBD_CAPSLOCK | USB_KBD_SCROLLLOCK) +/* + * USB Keyboard reports are 8 bytes in boot protocol. + * Appendix B of HID Device Class Definition 1.11 + */ +#define USB_KBD_BOOT_REPORT_SIZE 8 + struct usb_kbd_pdata { uint32_t repeat_delay; @@ -99,7 +105,7 @@ struct usb_kbd_pdata { uint8_t usb_kbd_buffer[USB_KBD_BUFFER_LEN]; uint8_t *new; - uint8_t old[8]; + uint8_t old[USB_KBD_BOOT_REPORT_SIZE]; uint8_t flags; }; @@ -131,7 +137,8 @@ void usb_kbd_generic_poll(void) /* Submit a interrupt transfer request */ maxp = usb_maxpacket(usb_kbd_dev, pipe); usb_submit_int_msg(usb_kbd_dev, pipe, data->new, - maxp > 8 ? 8 : maxp, ep->bInterval); + min(maxp, USB_KBD_BOOT_REPORT_SIZE), + ep->bInterval); } /* Puts character in the queue and sets up the in and out pointer. */ @@ -266,8 +273,11 @@ static uint32_t usb_kbd_service_key(struct usb_device *dev, int i, int up) old = data->old; } - if ((old[i] > 3) && (memscan(new + 2, old[i], 6) == new + 8)) + if ((old[i] > 3) && + (memscan(new + 2, old[i], USB_KBD_BOOT_REPORT_SIZE - 2) == + new + USB_KBD_BOOT_REPORT_SIZE)) { res |= usb_kbd_translate(data, old[i], data->new[0], up); + } return res; } @@ -285,7 +295,7 @@ static int usb_kbd_irq_worker(struct usb_device *dev) else if ((data->new[0] == LEFT_CNTR) || (data->new[0] == RIGHT_CNTR)) data->flags |= USB_KBD_CTRL; - for (i = 2; i < 8; i++) { + for (i = 2; i < USB_KBD_BOOT_REPORT_SIZE; i++) { res |= usb_kbd_service_key(dev, i, 0); res |= usb_kbd_service_key(dev, i, 1); } @@ -297,7 +307,7 @@ static int usb_kbd_irq_worker(struct usb_device *dev) if (res == 1) usb_kbd_setled(dev); - memcpy(data->old, data->new, 8); + memcpy(data->old, data->new, USB_KBD_BOOT_REPORT_SIZE); return 1; } @@ -305,7 +315,8 @@ static int usb_kbd_irq_worker(struct usb_device *dev) /* Keyboard interrupt handler */ static int usb_kbd_irq(struct usb_device *dev) { - if ((dev->irq_status != 0) || (dev->irq_act_len != 8)) { + if ((dev->irq_status != 0) || + (dev->irq_act_len != USB_KBD_BOOT_REPORT_SIZE)) { debug("USB KBD: Error %lX, len %d\n", dev->irq_status, dev->irq_act_len); return 1; @@ -333,7 +344,8 @@ static inline void usb_kbd_poll_for_event(struct usb_device *dev) /* Submit a interrupt transfer request */ maxp = usb_maxpacket(dev, pipe); usb_submit_int_msg(dev, pipe, &data->new[0], - maxp > 8 ? 8 : maxp, ep->bInterval); + min(maxp, USB_KBD_BOOT_REPORT_SIZE), + ep->bInterval); usb_kbd_irq_worker(dev); #elif defined(CONFIG_SYS_USB_EVENT_POLL_VIA_CONTROL_EP) @@ -341,8 +353,8 @@ static inline void usb_kbd_poll_for_event(struct usb_device *dev) struct usb_kbd_pdata *data = dev->privptr; iface = &dev->config.if_desc[0]; usb_get_report(dev, iface->desc.bInterfaceNumber, - 1, 0, data->new, sizeof(data->new)); - if (memcmp(data->old, data->new, sizeof(data->new))) + 1, 0, data->new, USB_KBD_BOOT_REPORT_SIZE); + if (memcmp(data->old, data->new, USB_KBD_BOOT_REPORT_SIZE)) usb_kbd_irq_worker(dev); #endif } @@ -441,7 +453,8 @@ static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum) memset(data, 0, sizeof(struct usb_kbd_pdata)); /* allocate input buffer aligned and sized to USB DMA alignment */ - data->new = memalign(USB_DMA_MINALIGN, roundup(8, USB_DMA_MINALIGN)); + data->new = memalign(USB_DMA_MINALIGN, + roundup(USB_KBD_BOOT_REPORT_SIZE, USB_DMA_MINALIGN)); /* Insert private data into USB device structure */ dev->privptr = data; @@ -459,7 +472,8 @@ static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum) usb_set_idle(dev, iface->desc.bInterfaceNumber, REPEAT_RATE, 0); debug("USB KBD: enable interrupt pipe...\n"); - if (usb_submit_int_msg(dev, pipe, data->new, maxp > 8 ? 8 : maxp, + if (usb_submit_int_msg(dev, pipe, data->new, + min(maxp, USB_KBD_BOOT_REPORT_SIZE), ep->bInterval) < 0) { printf("Failed to get keyboard state from device %04x:%04x\n", dev->descriptor.idVendor, dev->descriptor.idProduct); -- cgit v1.1 From adfc17bf09ba67cff11472ffa58fc0208defa29c Mon Sep 17 00:00:00 2001 From: Przemyslaw Marczak Date: Fri, 18 Apr 2014 09:48:24 +0200 Subject: usb:gadget:f_thor: code cleanup in function download_tail() In thor's download_tail() function, dfu_get_entity() is called before each dfu_write() call and the returned entity pointers are the same. So dfu_get_entity() can be called just once and this patch changes this. Signed-off-by: Przemyslaw Marczak Cc: Lukasz Majewski Cc: Marek Vasut Cc: Heiko Schocher Cc: Tom Rini --- drivers/usb/gadget/f_thor.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/f_thor.c b/drivers/usb/gadget/f_thor.c index f5c0224..231f9c0 100644 --- a/drivers/usb/gadget/f_thor.c +++ b/drivers/usb/gadget/f_thor.c @@ -204,14 +204,14 @@ static long long int download_head(unsigned long long total, static int download_tail(long long int left, int cnt) { + struct dfu_entity *dfu_entity = dfu_get_entity(alt_setting_num); void *transfer_buffer = dfu_get_buf(); int ret; debug("%s: left: %llu cnt: %d\n", __func__, left, cnt); if (left) { - ret = dfu_write(dfu_get_entity(alt_setting_num), - transfer_buffer, left, cnt++); + ret = dfu_write(dfu_entity, transfer_buffer, left, cnt++); if (ret) { error("DFU write failed [%d]: left: %llu", ret, left); return ret; @@ -225,8 +225,7 @@ static int download_tail(long long int left, int cnt) * This also frees memory malloc'ed by dfu_get_buf(), so no explicit * need fo call dfu_free_buf() is needed. */ - ret = dfu_write(dfu_get_entity(alt_setting_num), - transfer_buffer, 0, cnt); + ret = dfu_write(dfu_entity, transfer_buffer, 0, cnt); if (ret) error("DFU write failed [%d] cnt: %d", ret, cnt); -- cgit v1.1 From fd2a89b20ba66d76929f672b03f392733fb1b2a6 Mon Sep 17 00:00:00 2001 From: Przemyslaw Marczak Date: Fri, 18 Apr 2014 09:48:25 +0200 Subject: usb:gadget:f_thor: fix write to filesystem by add dfu_flush() Since dfu read/write operations needs to be flushed manually, writing to filesystem on MMC by thor was broken. MMC raw write actually is working fine because current dfu_flush() function writes filesystem only. This commit adds dfu_flush() to f_thor and now filesystem write is working. This change was tested on Trats2 board. Signed-off-by: Przemyslaw Marczak Cc: Lukasz Majewski Cc: Marek Vasut Cc: Heiko Schocher Cc: Tom Rini --- drivers/usb/gadget/f_thor.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/usb/gadget/f_thor.c b/drivers/usb/gadget/f_thor.c index 231f9c0..ba47945 100644 --- a/drivers/usb/gadget/f_thor.c +++ b/drivers/usb/gadget/f_thor.c @@ -229,6 +229,12 @@ static int download_tail(long long int left, int cnt) if (ret) error("DFU write failed [%d] cnt: %d", ret, cnt); + ret = dfu_flush(dfu_entity, transfer_buffer, 0, cnt); + if (ret) { + error("DFU flush failed!"); + return ret; + } + return ret; } -- cgit v1.1 From 52d45012ff66dee716b8dfcb7d67d3ab54a3208a Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Fri, 18 Apr 2014 08:54:28 -0500 Subject: usb: handle NULL table in usb_gadget_get_string Allow a NULL table to be passed to usb_gadget_get_string for cases when a string table may not be populated. Signed-off-by: Rob Herring Reviewed-by: Tom Rini Acked-by: Marek Vasut Acked-by: Lukasz Majewski --- drivers/usb/gadget/usbstring.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/gadget/usbstring.c b/drivers/usb/gadget/usbstring.c index de5fa3f..8c3ff64 100644 --- a/drivers/usb/gadget/usbstring.c +++ b/drivers/usb/gadget/usbstring.c @@ -108,6 +108,9 @@ usb_gadget_get_string(struct usb_gadget_strings *table, int id, u8 *buf) struct usb_string *s; int len; + if (!table) + return -EINVAL; + /* descriptor 0 has the language id */ if (id == 0) { buf[0] = 4; -- cgit v1.1 From 078d7302ac9263e582d625c377c8289ae07436b7 Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Fri, 18 Apr 2014 08:54:30 -0500 Subject: usb: musb: fill in usb_gadget_unregister_driver Add missing missing disconnect and unbind calls to the musb gadget driver's usb_gadget_unregister_driver function. Otherwise, any gadget drivers fail to uninitialize and run a 2nd time. Signed-off-by: Rob Herring --- drivers/usb/musb-new/musb_uboot.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/musb-new/musb_uboot.c b/drivers/usb/musb-new/musb_uboot.c index 0512680..0d7b89f 100644 --- a/drivers/usb/musb-new/musb_uboot.c +++ b/drivers/usb/musb-new/musb_uboot.c @@ -204,7 +204,10 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) { - /* TODO: implement me */ + if (driver->disconnect) + driver->disconnect(&gadget->g); + if (driver->unbind) + driver->unbind(&gadget->g); return 0; } #endif /* CONFIG_MUSB_GADGET */ -- cgit v1.1 From e6e493f341b0488843efe0c5b2c1274997fbbfe8 Mon Sep 17 00:00:00 2001 From: "andrey.konovalov@linaro.org" Date: Tue, 22 Apr 2014 21:23:49 +0400 Subject: exynos: usb: Fix data abort on boards w/o vbus-gpio node in the DT Commit 4a271cb1b4ff doesn't take into account that fdtdec_setup_gpio() returns success when the gpio passed to it is FDT_GPIO_NONE (no gpio node found in the fdtdec_decode_gpio() call). This results in calling gpio_direction_output() on invalid gpio. For this reason executing "usb start" command on Arndale causes data abort in the ehci-exynos driver. Add the fdt_gpio_isvalid() check to fix that problem. Signed-off-by: Andrey Konovalov Cc: Julius Werner Cc: Simon Glass Cc: Minkyu Kang Cc: Marek Vasut --- drivers/usb/host/ehci-exynos.c | 3 ++- drivers/usb/host/xhci-exynos5.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c index 9356878..edd91a8 100644 --- a/drivers/usb/host/ehci-exynos.c +++ b/drivers/usb/host/ehci-exynos.c @@ -197,7 +197,8 @@ int ehci_hcd_init(int index, enum usb_init_type init, #ifdef CONFIG_OF_CONTROL /* setup the Vbus gpio here */ - if (!fdtdec_setup_gpio(&ctx->vbus_gpio)) + if (fdt_gpio_isvalid(&ctx->vbus_gpio) && + !fdtdec_setup_gpio(&ctx->vbus_gpio)) gpio_direction_output(ctx->vbus_gpio.gpio, 1); #endif diff --git a/drivers/usb/host/xhci-exynos5.c b/drivers/usb/host/xhci-exynos5.c index 1146d10..b4946a3 100644 --- a/drivers/usb/host/xhci-exynos5.c +++ b/drivers/usb/host/xhci-exynos5.c @@ -298,7 +298,8 @@ int xhci_hcd_init(int index, struct xhci_hccr **hccr, struct xhci_hcor **hcor) #ifdef CONFIG_OF_CONTROL /* setup the Vbus gpio here */ - if (!fdtdec_setup_gpio(&ctx->vbus_gpio)) + if (fdt_gpio_isvalid(&ctx->vbus_gpio) && + !fdtdec_setup_gpio(&ctx->vbus_gpio)) gpio_direction_output(ctx->vbus_gpio.gpio, 1); #endif -- cgit v1.1 From 672ad18c276e6c37e2e140294ec35ee96ae47d38 Mon Sep 17 00:00:00 2001 From: Lukasz Majewski Date: Thu, 24 Apr 2014 10:24:53 +0200 Subject: dfu:fix: Replace wrong return value with proper one This patch remove always false (since we tested ret = 0) ternary operator with ret value returned. Signed-off-by: Lukasz Majewski --- drivers/dfu/dfu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c index 8a09aaf..51b1026 100644 --- a/drivers/dfu/dfu.c +++ b/drivers/dfu/dfu.c @@ -219,7 +219,7 @@ int dfu_write(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num) ret = tret; } - return ret = 0 ? size : ret; + return ret; } static int dfu_read_buffer_fill(struct dfu_entity *dfu, void *buf, int size) -- cgit v1.1 From f5c03006dd1794362a2be7136fed9e664bc1775b Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Thu, 24 Apr 2014 17:52:36 -0600 Subject: usb: ci_udc: Support larger packets ci_ep_queue() currently only fills in the page0/page1 fields in the queue item. If the buffer is larger than 4KiB (unaligned) or 8KiB (page-aligned), then this prevents the HW from knowing where to write the balance of the data. Fix this by initializing all 5 pageN pointers, which allows up to 16KiB (potentially non-page-aligned) buffers. Signed-off-by: Stephen Warren --- drivers/usb/gadget/ci_udc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c index 14b1e9b..815ce7b 100644 --- a/drivers/usb/gadget/ci_udc.c +++ b/drivers/usb/gadget/ci_udc.c @@ -350,6 +350,9 @@ static int ci_ep_queue(struct usb_ep *ep, item->info = INFO_BYTES(len) | INFO_IOC | INFO_ACTIVE; item->page0 = (uint32_t)ci_ep->b_buf; item->page1 = ((uint32_t)ci_ep->b_buf & 0xfffff000) + 0x1000; + item->page2 = ((uint32_t)ci_ep->b_buf & 0xfffff000) + 0x2000; + item->page3 = ((uint32_t)ci_ep->b_buf & 0xfffff000) + 0x3000; + item->page4 = ((uint32_t)ci_ep->b_buf & 0xfffff000) + 0x4000; ci_flush_qtd(num); head->next = (unsigned) item; -- cgit v1.1 From 8aac6e9c537a2dd0c76acc3a0768ae7af5e166ab Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Thu, 24 Apr 2014 17:52:37 -0600 Subject: usb: ci_udc: set ep->req.actual after transfer At least drivers/usb/gadget/storage_common.c expects that ep->req.actual contain the number of bytes actually transferred. (At least in practice, I observed it failing to work correctly unless this was the case). However, ci_udc.c modifies ep->req.length instead. I assume that .length is supposed to represent the allocated buffer size, whereas .actual is supposed to represent the actual number of bytes transferred. In the OUT transaction case, this may happen simply because the host sends a smaller packet than the max possible size, which is quite legal. In the IN case, transferring fewer bytes than requested could presumably happen as an error. Modify handle_ep_complete() to write to .actual rather than modifying .length. Signed-off-by: Stephen Warren --- drivers/usb/gadget/ci_udc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c index 815ce7b..832606f 100644 --- a/drivers/usb/gadget/ci_udc.c +++ b/drivers/usb/gadget/ci_udc.c @@ -321,7 +321,7 @@ static void ci_debounce(struct ci_ep *ep, int in) if (addr == ba) return; /* not a bounce */ - memcpy(ep->req.buf, ep->b_buf, ep->req.length); + memcpy(ep->req.buf, ep->b_buf, ep->req.actual); free: /* Large payloads use allocated buffer, free it. */ if (ep->b_buf != ep->b_fast) @@ -388,7 +388,7 @@ static void handle_ep_complete(struct ci_ep *ep) num, in ? "in" : "out", item->info, item->page0); len = (item->info >> 16) & 0x7fff; - ep->req.length -= len; + ep->req.actual = ep->req.length - len; ci_debounce(ep, in); DBG("ept%d %s complete %x\n", -- cgit v1.1 From 0c51dc6db9ea0e3912d1d3e2d953bc22de433c60 Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Thu, 24 Apr 2014 17:52:38 -0600 Subject: usb: ci_udc: make PHY initialization conditional usb_gadget_register_driver() currently unconditionally programs PORTSC to select a ULPI PHY. This is incorrect on at least the Tegra boards I am testing with, which use a UTMI PHY for the OTG ports. Make the PHY selection code conditional upon the specific EHCI controller that is in use. Ideally, I believe that the PHY initialization code should be part of ehci_hcd_init() in the relevant EHCI controller driver, or some board- specific function that ehci_hcd_init() calls. For MX6, I'm not sure this PHY initialization code is correct even before this patch, since ehci-mx6's ehci_hcd_init() already configures PORTSC to a board-specific value, and it seems likely that the code in ci_udc.c is incorrectly undoing this. Perhaps this is not an issue if the PHY selection register bits aren't implemented on this instance of the MX6 USB controller? ehci-mxs.c doens't appear to touch PORTSC, so this code is likely still required there. Signed-off-by: Stephen Warren --- drivers/usb/gadget/ci_udc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c index 832606f..fd751a2 100644 --- a/drivers/usb/gadget/ci_udc.c +++ b/drivers/usb/gadget/ci_udc.c @@ -702,7 +702,6 @@ static int ci_udc_probe(void) int usb_gadget_register_driver(struct usb_gadget_driver *driver) { - struct ci_udc *udc; int ret; if (!driver) @@ -717,12 +716,18 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) return ret; ret = ci_udc_probe(); +#if defined(CONFIG_USB_EHCI_MX6) || defined(CONFIG_USB_EHCI_MXS) + /* + * FIXME: usb_lowlevel_init()->ehci_hcd_init() should be doing all + * HW-specific initialization, e.g. ULPI-vs-UTMI PHY selection + */ if (!ret) { - udc = (struct ci_udc *)controller.ctrl->hcor; + struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor; /* select ULPI phy */ writel(PTS(PTS_ENABLE) | PFSC, &udc->portsc); } +#endif ret = driver->bind(&controller.gadget); if (ret) { -- cgit v1.1 From fcf2ede190e054edcb804ba7786dd024b388a160 Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Thu, 24 Apr 2014 17:52:39 -0600 Subject: usb: ci_udc: support variants with hostpc register Tegra's USB controller appears to be a variant of the ChipIdea controller; perhaps derived from it, or simply a different version of the IP core to what U-Boot supports today. In this variant, at least the following difference are present: - Some registers are moved about. - Setup transaction completion is reported in a separate 'epsetupstat' register, rather than in 'epstat' (which still exists, perhaps for other transaction types). - USB connection speed is reported in a separate 'hostpc1_devlc' register, rather than 'portsc'. - The registers used by ci_udc.c begin at offset 0x130 from the USB register base, rather than offset 0x140. However, this is handled by the associated EHCI controller driver, since the register address is stored in controller.ctrl->hcor. Introduce define CONFIG_CI_UDC_HAS_HOSTPC to indicate which variant of the controller should be supported. The "HAS_HOSTPC" part of this name mirrors the similar "has_hostpc" field used by the Linux EHCI controller core to represent the presence/absence of the hostpc1_devlc register. Signed-off-by: Stephen Warren --- drivers/usb/gadget/ci_udc.c | 15 +++++++++++ drivers/usb/gadget/ci_udc.h | 65 ++++++++++++++++++++++++++++++++------------- 2 files changed, 62 insertions(+), 18 deletions(-) diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c index fd751a2..02d3fda 100644 --- a/drivers/usb/gadget/ci_udc.c +++ b/drivers/usb/gadget/ci_udc.c @@ -416,7 +416,11 @@ static void handle_setup(void) ci_invalidate_qh(0); memcpy(&r, head->setup_data, sizeof(struct usb_ctrlrequest)); +#ifdef CONFIG_CI_UDC_HAS_HOSTPC + writel(EPT_RX(0), &udc->epsetupstat); +#else writel(EPT_RX(0), &udc->epstat); +#endif DBG("handle setup %s, %x, %x index %x value %x\n", reqname(r.bRequest), r.bRequestType, r.bRequest, r.wIndex, r.wValue); @@ -483,6 +487,9 @@ static void stop_activity(void) struct ept_queue_head *head; struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor; writel(readl(&udc->epcomp), &udc->epcomp); +#ifdef CONFIG_CI_UDC_HAS_HOSTPC + writel(readl(&udc->epsetupstat), &udc->epsetupstat); +#endif writel(readl(&udc->epstat), &udc->epstat); writel(0xffffffff, &udc->epflush); @@ -524,7 +531,11 @@ void udc_irq(void) int max = 64; int speed = USB_SPEED_FULL; +#ifdef CONFIG_CI_UDC_HAS_HOSTPC + bit = (readl(&udc->hostpc1_devlc) >> 25) & 3; +#else bit = (readl(&udc->portsc) >> 26) & 3; +#endif DBG("-- portchange %x %s\n", bit, (bit == 2) ? "High" : "Full"); if (bit == 2) { speed = USB_SPEED_HIGH; @@ -541,7 +552,11 @@ void udc_irq(void) printf("\n", readl(&udc->epcomp)); if ((n & STS_UI) || (n & STS_UEI)) { +#ifdef CONFIG_CI_UDC_HAS_HOSTPC + n = readl(&udc->epsetupstat); +#else n = readl(&udc->epstat); +#endif if (n & EPT_RX(0)) handle_setup(); diff --git a/drivers/usb/gadget/ci_udc.h b/drivers/usb/gadget/ci_udc.h index 42f6ef4..4425fd9 100644 --- a/drivers/usb/gadget/ci_udc.h +++ b/drivers/usb/gadget/ci_udc.h @@ -8,45 +8,74 @@ #define NUM_ENDPOINTS 6 +#ifdef CONFIG_CI_UDC_HAS_HOSTPC +struct ci_udc { + u32 usbcmd; /* 0x130 */ + u32 usbsts; /* 0x134 */ + u32 pad1[3]; + u32 devaddr; /* 0x144 */ + u32 epinitaddr; /* 0x148 */ + u32 pad2[10]; + u32 portsc; /* 0x174 */ + u32 pad178[(0x1b4 - (0x174 + 4)) / 4]; + u32 hostpc1_devlc; /* 0x1b4 */ + u32 pad1b8[(0x1f8 - (0x1b4 + 4)) / 4]; + u32 usbmode; /* 0x1f8 */ + u32 pad1fc[(0x208 - (0x1f8 + 4)) / 4]; + u32 epsetupstat; /* 0x208 */ + u32 epprime; /* 0x20c */ + u32 epflush; /* 0x210 */ + u32 epstat; /* 0x214 */ + u32 epcomp; /* 0x218 */ + u32 epctrl[16]; /* 0x21c */ +}; +#else struct ci_udc { -#define MICRO_8FRAME 0x8 -#define USBCMD_ITC(x) ((((x) > 0xff) ? 0xff : x) << 16) -#define USBCMD_FS2 (1 << 15) -#define USBCMD_RST (1 << 1) -#define USBCMD_RUN (1) u32 usbcmd; /* 0x140 */ -#define STS_SLI (1 << 8) -#define STS_URI (1 << 6) -#define STS_PCI (1 << 2) -#define STS_UEI (1 << 1) -#define STS_UI (1 << 0) u32 usbsts; /* 0x144 */ u32 pad1[3]; u32 devaddr; /* 0x154 */ u32 epinitaddr; /* 0x158 */ u32 pad2[10]; -#define PTS_ENABLE 2 -#define PTS(x) (((x) & 0x3) << 30) -#define PFSC (1 << 24) u32 portsc; /* 0x184 */ u32 pad3[8]; -#define USBMODE_DEVICE 2 u32 usbmode; /* 0x1a8 */ u32 epstat; /* 0x1ac */ -#define EPT_TX(x) (1 << (((x) & 0xffff) + 16)) -#define EPT_RX(x) (1 << ((x) & 0xffff)) u32 epprime; /* 0x1b0 */ u32 epflush; /* 0x1b4 */ u32 pad4; u32 epcomp; /* 0x1bc */ + u32 epctrl[16]; /* 0x1c0 */ +}; + +#define PTS_ENABLE 2 +#define PTS(x) (((x) & 0x3) << 30) +#define PFSC (1 << 24) +#endif + +#define MICRO_8FRAME 0x8 +#define USBCMD_ITC(x) ((((x) > 0xff) ? 0xff : x) << 16) +#define USBCMD_FS2 (1 << 15) +#define USBCMD_RST (1 << 1) +#define USBCMD_RUN (1) + +#define STS_SLI (1 << 8) +#define STS_URI (1 << 6) +#define STS_PCI (1 << 2) +#define STS_UEI (1 << 1) +#define STS_UI (1 << 0) + +#define USBMODE_DEVICE 2 + +#define EPT_TX(x) (1 << (((x) & 0xffff) + 16)) +#define EPT_RX(x) (1 << ((x) & 0xffff)) + #define CTRL_TXE (1 << 23) #define CTRL_TXR (1 << 22) #define CTRL_RXE (1 << 7) #define CTRL_RXR (1 << 6) #define CTRL_TXT_BULK (2 << 18) #define CTRL_RXT_BULK (2 << 2) - u32 epctrl[16]; /* 0x1c0 */ -}; struct ci_ep { struct usb_ep ep; -- cgit v1.1 From a022c1e13c01d88edd3436c291630d4b8c642787 Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Thu, 24 Apr 2014 17:52:40 -0600 Subject: usb: ums: use only 1 buffer for CI_UDC ci_udc.c allocates only a single buffer for each endpoint, which ci_ep_alloc_request() returns as a hard-coded value rather than dynamically allocating. Consequently, storage_common.c must limit itself to using a single buffer at a time. Add a special case to the definition of FSG_NUM_BUFFERS for this. Another option would be to fix ci_ep_alloc_request() to dynamically allocate the buffers like some/all(?) other device mode drivers do. However, I don't think that ci_ep_queue() supports queueing up multiple buffers either yet, and I'm not familiar enough with the controller yet to implement that. As such, any attempt to use multiple buffers simply results in data corruption and other errors. Signed-off-by: Stephen Warren --- drivers/usb/gadget/storage_common.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c index 02803df..7430074 100644 --- a/drivers/usb/gadget/storage_common.c +++ b/drivers/usb/gadget/storage_common.c @@ -311,7 +311,11 @@ static struct fsg_lun *fsg_lun_from_dev(struct device *dev) #define DELAYED_STATUS (EP0_BUFSIZE + 999) /* An impossibly large value */ /* Number of buffers we will use. 2 is enough for double-buffering */ +#ifndef CONFIG_CI_UDC #define FSG_NUM_BUFFERS 2 +#else +#define FSG_NUM_BUFFERS 1 /* ci_udc only allows 1 req per ep at present */ +#endif /* Default size of buffer length. */ #define FSG_BUFLEN ((u32)16384) -- cgit v1.1 From 2fc5dab2ed19b6e15ba0726905b6311793397806 Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Mon, 28 Apr 2014 15:42:00 -0600 Subject: usb: gadget: allow ci_udc to build with new gadget framework Allow ci_udc.o to be built when using the new(?) USB gadget framework, as enabled by CONFIG_USB_GADGET. Note that this duplicates the Makefile entry for ci_udc.o, since it's also included inside #ifdef CONFIG_USB_ETHER. I'm not sure what that define means; perhaps an old style of Ethernet-specific USB gadget implementation? I wonder if the line that this patch adds shouldn't be outside all of the ifdefs, so it stands on its own, similar to how e.g. epautoconf.o is shared between the two? Signed-off-by: Stephen Warren --- drivers/usb/gadget/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index 804a2bd..896c8d4 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile @@ -13,6 +13,7 @@ ifdef CONFIG_USB_GADGET obj-$(CONFIG_USB_GADGET_ATMEL_USBA) += atmel_usba_udc.o obj-$(CONFIG_USB_GADGET_S3C_UDC_OTG) += s3c_udc_otg.o obj-$(CONFIG_USB_GADGET_FOTG210) += fotg210.o +obj-$(CONFIG_CI_UDC) += ci_udc.o obj-$(CONFIG_THOR_FUNCTION) += f_thor.o obj-$(CONFIG_USBDOWNLOAD_GADGET) += g_dnl.o obj-$(CONFIG_DFU_FUNCTION) += f_dfu.o -- cgit v1.1 From 07a2d42cd4964168b98c895dd2bb9c0c8275992d Mon Sep 17 00:00:00 2001 From: Mateusz Zalega Date: Wed, 30 Apr 2014 13:04:15 +0200 Subject: mmc: mmc header fix Structure definition used type block_dev_desc_t, defined in part.h, which wasn't included in mmc.h. It worked only in circumstances when common.h, or another header using part.h was incuded in implementation files. Change-Id: I5b203928b689887e3e78beb00a378955e0553eb7 Signed-off-by: Mateusz Zalega Acked-by: Pantelis Antoniou Cc: Minkyu Kang --- include/mmc.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/mmc.h b/include/mmc.h index 42d0125..bc11f45 100644 --- a/include/mmc.h +++ b/include/mmc.h @@ -12,6 +12,7 @@ #include #include +#include #define SD_VERSION_SD 0x20000 #define SD_VERSION_3 (SD_VERSION_SD | 0x300) -- cgit v1.1 From 6b423b752b24bf69962821754314418621fc71cc Mon Sep 17 00:00:00 2001 From: Mateusz Zalega Date: Mon, 28 Apr 2014 21:13:22 +0200 Subject: part: header fix Implementation made use of types defined in common.h, even though it wasn't #included. It worked in circumstances when .c files included every needed header (all). Signed-off-by: Mateusz Zalega Cc: Tom Rini Cc: Minkyu Kang --- include/part.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/part.h b/include/part.h index 4beb6db..53532dc 100644 --- a/include/part.h +++ b/include/part.h @@ -8,6 +8,7 @@ #define _PART_H #include +#include typedef struct block_dev_desc { int if_type; /* type of the interface */ -- cgit v1.1 From 75504e9592745021006cb8905b5ff5a51d9d1cb3 Mon Sep 17 00:00:00 2001 From: Mateusz Zalega Date: Wed, 30 Apr 2014 13:07:48 +0200 Subject: usb: dfu: fix boards wo USB cable detection Former usb_cable_connected() patch broke compilation of boards which do not support this feature. I've renamed usb_cable_connected() to g_dnl_usb_cable_connected() and added its default implementation to gadget downloader driver code. There's only one driver of this kind and it's unlikely there'll be another, so there's no point in keeping it in /common. Previously this function was declared in usb.h. I've moved it, since it's more appropriate to keep it in g_dnl.h - usb.h seems to be intended for USB host implementation. Existing code, confronted with default -EOPNOTSUPP return value, continues as if the cable was connected. CONFIG_USB_CABLE_CHECK was removed. Change-Id: Ib9198621adee2811b391c64512f14646cefd0369 Signed-off-by: Mateusz Zalega Acked-by: Marek Vasut Acked-by: Lukasz Majewski --- README | 7 ------- board/samsung/origen/origen.c | 7 ------- board/samsung/trats/trats.c | 4 +--- board/samsung/trats2/trats2.c | 4 +--- board/samsung/universal_c210/universal.c | 7 ------- common/cmd_usb_mass_storage.c | 8 ++++++-- drivers/usb/gadget/f_mass_storage.c | 8 ++++---- drivers/usb/gadget/g_dnl.c | 5 +++++ include/configs/exynos4-dt.h | 1 - include/g_dnl.h | 1 + include/usb.h | 10 ---------- 11 files changed, 18 insertions(+), 44 deletions(-) diff --git a/README b/README index 12758dc..b973344 100644 --- a/README +++ b/README @@ -1484,13 +1484,6 @@ The following options need to be configured: for your device - CONFIG_USBD_PRODUCTID 0xFFFF - Some USB device drivers may need to check USB cable attachment. - In this case you can enable following config in BoardName.h: - CONFIG_USB_CABLE_CHECK - This enables function definition: - - usb_cable_connected() in include/usb.h - Implementation of this function is board-specific. - - ULPI Layer Support: The ULPI (UTMI Low Pin (count) Interface) PHYs are supported via the generic ULPI layer. The generic layer accesses the ULPI PHY diff --git a/board/samsung/origen/origen.c b/board/samsung/origen/origen.c index d502f02..a539267 100644 --- a/board/samsung/origen/origen.c +++ b/board/samsung/origen/origen.c @@ -30,13 +30,6 @@ int board_usb_init(int index, enum usb_init_type init) return 0; } -#ifdef CONFIG_USB_CABLE_CHECK -int usb_cable_connected(void) -{ - return 0; -} -#endif - #ifdef CONFIG_BOARD_EARLY_INIT_F int exynos_early_init_f(void) { diff --git a/board/samsung/trats/trats.c b/board/samsung/trats/trats.c index 7c79e7b..ab0ad1d 100644 --- a/board/samsung/trats/trats.c +++ b/board/samsung/trats/trats.c @@ -430,8 +430,7 @@ int board_usb_init(int index, enum usb_init_type init) return s3c_udc_probe(&s5pc210_otg_data); } -#ifdef CONFIG_USB_CABLE_CHECK -int usb_cable_connected(void) +int g_dnl_board_usb_cable_connected(void) { struct pmic *muic = pmic_get("MAX8997_MUIC"); if (!muic) @@ -440,7 +439,6 @@ int usb_cable_connected(void) return !!muic->chrg->chrg_type(muic); } #endif -#endif static void pmic_reset(void) { diff --git a/board/samsung/trats2/trats2.c b/board/samsung/trats2/trats2.c index f558ef9..4709525 100644 --- a/board/samsung/trats2/trats2.c +++ b/board/samsung/trats2/trats2.c @@ -312,8 +312,7 @@ int board_usb_init(int index, enum usb_init_type init) return s3c_udc_probe(&s5pc210_otg_data); } -#ifdef CONFIG_USB_CABLE_CHECK -int usb_cable_connected(void) +int g_dnl_board_usb_cable_connected(void) { struct pmic *muic = pmic_get("MAX77693_MUIC"); if (!muic) @@ -322,7 +321,6 @@ int usb_cable_connected(void) return !!muic->chrg->chrg_type(muic); } #endif -#endif static int pmic_init_max77686(void) { diff --git a/board/samsung/universal_c210/universal.c b/board/samsung/universal_c210/universal.c index f9d71b6..8e49195 100644 --- a/board/samsung/universal_c210/universal.c +++ b/board/samsung/universal_c210/universal.c @@ -197,13 +197,6 @@ int board_usb_init(int index, enum usb_init_type init) return s3c_udc_probe(&s5pc210_otg_data); } -#ifdef CONFIG_USB_CABLE_CHECK -int usb_cable_connected(void) -{ - return 0; -} -#endif - int exynos_early_init_f(void) { wdt_stop(); diff --git a/common/cmd_usb_mass_storage.c b/common/cmd_usb_mass_storage.c index 5f557d5..14a5b6a 100644 --- a/common/cmd_usb_mass_storage.c +++ b/common/cmd_usb_mass_storage.c @@ -45,10 +45,14 @@ int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag, /* Timeout unit: seconds */ int cable_ready_timeout = UMS_CABLE_READY_TIMEOUT; - if (!usb_cable_connected()) { + if (!g_dnl_board_usb_cable_connected()) { + /* + * Won't execute if we don't know whether the cable is + * connected. + */ puts("Please connect USB cable.\n"); - while (!usb_cable_connected()) { + while (!g_dnl_board_usb_cable_connected()) { if (ctrlc()) { puts("\rCTRL+C - Operation aborted.\n"); goto exit; diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index f896169..4fae5cd 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -243,7 +243,7 @@ #include #include #include -#include +#include #include #include @@ -680,11 +680,11 @@ static int sleep_thread(struct fsg_common *common) /* Handle CTRL+C */ if (ctrlc()) return -EPIPE; -#ifdef CONFIG_USB_CABLE_CHECK + /* Check cable connection */ - if (!usb_cable_connected()) + if (!g_dnl_board_usb_cable_connected()) return -EIO; -#endif + k = 0; } diff --git a/drivers/usb/gadget/g_dnl.c b/drivers/usb/gadget/g_dnl.c index dd95afe..973d737 100644 --- a/drivers/usb/gadget/g_dnl.c +++ b/drivers/usb/gadget/g_dnl.c @@ -152,6 +152,11 @@ __weak int g_dnl_get_board_bcd_device_number(int gcnum) return gcnum; } +__weak int g_dnl_board_usb_cable_connected(void) +{ + return -EOPNOTSUPP; +} + static int g_dnl_get_bcd_device_number(struct usb_composite_dev *cdev) { struct usb_gadget *gadget = cdev->gadget; diff --git a/include/configs/exynos4-dt.h b/include/configs/exynos4-dt.h index 2040bf7..cbd2d20 100644 --- a/include/configs/exynos4-dt.h +++ b/include/configs/exynos4-dt.h @@ -127,7 +127,6 @@ #define CONFIG_USB_GADGET_S3C_UDC_OTG #define CONFIG_USB_GADGET_DUALSPEED #define CONFIG_USB_GADGET_VBUS_DRAW 2 -#define CONFIG_USB_CABLE_CHECK #define CONFIG_CMD_USB_MASS_STORAGE #define CONFIG_USB_GADGET_MASS_STORAGE diff --git a/include/g_dnl.h b/include/g_dnl.h index 8f813c2..f4e8d10 100644 --- a/include/g_dnl.h +++ b/include/g_dnl.h @@ -11,6 +11,7 @@ #include #include int g_dnl_bind_fixup(struct usb_device_descriptor *, const char *); +int g_dnl_board_usb_cable_connected(void); int g_dnl_register(const char *s); void g_dnl_unregister(void); void g_dnl_set_serialnumber(char *); diff --git a/include/usb.h b/include/usb.h index 736730e..d9fedee 100644 --- a/include/usb.h +++ b/include/usb.h @@ -197,16 +197,6 @@ int board_usb_init(int index, enum usb_init_type init); */ int board_usb_cleanup(int index, enum usb_init_type init); -/* - * If CONFIG_USB_CABLE_CHECK is set then this function - * should be defined in board file. - * - * @return 1 if cable is connected and 0 otherwise. - */ -#ifdef CONFIG_USB_CABLE_CHECK -int usb_cable_connected(void); -#endif - #ifdef CONFIG_USB_STORAGE #define USB_MAX_STOR_DEV 5 -- cgit v1.1 From 711b931f90e44ff1248cd73c15f64485470d86ff Mon Sep 17 00:00:00 2001 From: Mateusz Zalega Date: Mon, 28 Apr 2014 21:13:24 +0200 Subject: dfu: mmc: raw data write fix When user attempted to perform a raw write using DFU (vide dfu_fill_entity_mmc) with MMC interface not initialized before, get_mmc_blk_size() reported invalid (zero) block size - it wasn't possible to write ie. a new u-boot image. This commit fixes that by initializing MMC device before use in dfu_fill_entity_mmc(). While fixing initialization sequence, I had to change about half of dfu_fill_entity_mmc's body, so I refactored it on the way to make it, IMHO, considerably more comprehensible. Being left as dead code, get_mmc_blk_size() was removed. Tested on Samsung Goni. Signed-off-by: Mateusz Zalega Signed-off-by: Kyungmin Park Acked-by: Lukasz Majewski Acked-by: Tom Rini Cc: Minkyu Kang --- drivers/dfu/dfu_mmc.c | 105 +++++++++++++++++++++++++++++++------------------- include/dfu.h | 5 --- 2 files changed, 65 insertions(+), 45 deletions(-) diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c index 651cfff..b41785d 100644 --- a/drivers/dfu/dfu_mmc.c +++ b/drivers/dfu/dfu_mmc.c @@ -184,66 +184,91 @@ int dfu_read_medium_mmc(struct dfu_entity *dfu, u64 offset, void *buf, return ret; } +/* + * @param s Parameter string containing space-separated arguments: + * 1st: + * raw (raw read/write) + * fat (files) + * ext4 (^) + * part (partition image) + * 2nd and 3rd: + * lba_start and lba_size, for raw write + * mmc_dev and mmc_part, for filesystems and part + */ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s) { - int dev, part; - struct mmc *mmc; - block_dev_desc_t *blk_dev; - disk_partition_t partinfo; - char *st; + const char *entity_type; + size_t second_arg; + size_t third_arg; - dfu->dev_type = DFU_DEV_MMC; - st = strsep(&s, " "); - if (!strcmp(st, "mmc")) { - dfu->layout = DFU_RAW_ADDR; - dfu->data.mmc.lba_start = simple_strtoul(s, &s, 16); - dfu->data.mmc.lba_size = simple_strtoul(++s, &s, 16); - dfu->data.mmc.lba_blk_size = get_mmc_blk_size(dfu->dev_num); - } else if (!strcmp(st, "fat")) { - dfu->layout = DFU_FS_FAT; - } else if (!strcmp(st, "ext4")) { - dfu->layout = DFU_FS_EXT4; - } else if (!strcmp(st, "part")) { - - dfu->layout = DFU_RAW_ADDR; + struct mmc *mmc; - dev = simple_strtoul(s, &s, 10); - s++; - part = simple_strtoul(s, &s, 10); + const char *argv[3]; + const char **parg = argv; - mmc = find_mmc_device(dev); - if (mmc == NULL || mmc_init(mmc)) { - printf("%s: could not find mmc device #%d!\n", - __func__, dev); + for (; parg < argv + sizeof(argv) / sizeof(*argv); ++parg) { + *parg = strsep(&s, " "); + if (*parg == NULL) { + error("Invalid number of arguments.\n"); return -ENODEV; } + } - blk_dev = &mmc->block_dev; - if (get_partition_info(blk_dev, part, &partinfo) != 0) { - printf("%s: could not find partition #%d on mmc device #%d!\n", - __func__, part, dev); + entity_type = argv[0]; + second_arg = simple_strtoul(argv[1], NULL, 16); + third_arg = simple_strtoul(argv[2], NULL, 16); + + mmc = find_mmc_device(dfu->dev_num); + if (mmc == NULL) { + error("Couldn't find MMC device no. %d.\n", dfu->dev_num); + return -ENODEV; + } + + if (mmc_init(mmc)) { + error("Couldn't init MMC device.\n"); + return -ENODEV; + } + + if (!strcmp(entity_type, "raw")) { + dfu->layout = DFU_RAW_ADDR; + dfu->data.mmc.lba_start = second_arg; + dfu->data.mmc.lba_size = third_arg; + dfu->data.mmc.lba_blk_size = mmc->read_bl_len; + } else if (!strcmp(entity_type, "part")) { + disk_partition_t partinfo; + block_dev_desc_t *blk_dev = &mmc->block_dev; + int mmcdev = second_arg; + int mmcpart = third_arg; + + if (get_partition_info(blk_dev, mmcpart, &partinfo) != 0) { + error("Couldn't find part #%d on mmc device #%d\n", + mmcpart, mmcdev); return -ENODEV; } - dfu->data.mmc.lba_start = partinfo.start; - dfu->data.mmc.lba_size = partinfo.size; - dfu->data.mmc.lba_blk_size = partinfo.blksz; - + dfu->layout = DFU_RAW_ADDR; + dfu->data.mmc.lba_start = partinfo.start; + dfu->data.mmc.lba_size = partinfo.size; + dfu->data.mmc.lba_blk_size = partinfo.blksz; + } else if (!strcmp(entity_type, "fat")) { + dfu->layout = DFU_FS_FAT; + } else if (!strcmp(entity_type, "ext4")) { + dfu->layout = DFU_FS_EXT4; } else { - printf("%s: Memory layout (%s) not supported!\n", __func__, st); + error("Memory layout (%s) not supported!\n", entity_type); return -ENODEV; } - if (dfu->layout == DFU_FS_EXT4 || dfu->layout == DFU_FS_FAT) { - dfu->data.mmc.dev = simple_strtoul(s, &s, 10); - dfu->data.mmc.part = simple_strtoul(++s, &s, 10); + /* if it's NOT a raw write */ + if (strcmp(entity_type, "raw")) { + dfu->data.mmc.dev = second_arg; + dfu->data.mmc.part = third_arg; } + dfu->dev_type = DFU_DEV_MMC; dfu->read_medium = dfu_read_medium_mmc; dfu->write_medium = dfu_write_medium_mmc; dfu->flush_medium = dfu_flush_medium_mmc; - - /* initial state */ dfu->inited = 0; return 0; diff --git a/include/dfu.h b/include/dfu.h index 6c71ecb..dcd3215 100644 --- a/include/dfu.h +++ b/include/dfu.h @@ -64,11 +64,6 @@ struct ram_internal_data { unsigned int size; }; -static inline unsigned int get_mmc_blk_size(int dev) -{ - return find_mmc_device(dev)->read_bl_len; -} - #define DFU_NAME_SIZE 32 #define DFU_CMD_BUF_SIZE 128 #ifndef CONFIG_SYS_DFU_DATA_BUF_SIZE -- cgit v1.1 From b7d4259af298402b7d65c876d8e39e5b9e6c8934 Mon Sep 17 00:00:00 2001 From: Mateusz Zalega Date: Mon, 28 Apr 2014 21:13:25 +0200 Subject: dfu: mmc: change offset base handling Previously offsets handled by dfu_fill_entity_mmc(), defined in boards' CONFIG_DFU_ALT were treated as hexadecimal regardless of their prefix, which sometimes led to confusion. This patch forces usage of explicit numerical base prefixes. Signed-off-by: Mateusz Zalega Acked-by: Lukasz Majewski Cc: Tom Rini Cc: Minkyu Kang --- drivers/dfu/dfu_mmc.c | 8 ++++++-- include/configs/am335x_evm.h | 8 ++++---- include/configs/trats.h | 4 ++-- include/configs/trats2.h | 4 ++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c index b41785d..5e10ea7 100644 --- a/drivers/dfu/dfu_mmc.c +++ b/drivers/dfu/dfu_mmc.c @@ -215,8 +215,12 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s) } entity_type = argv[0]; - second_arg = simple_strtoul(argv[1], NULL, 16); - third_arg = simple_strtoul(argv[2], NULL, 16); + /* + * Base 0 means we'll accept (prefixed with 0x or 0) base 16, 8, + * with default 10. + */ + second_arg = simple_strtoul(argv[1], NULL, 0); + third_arg = simple_strtoul(argv[2], NULL, 0); mmc = find_mmc_device(dfu->dev_num); if (mmc == NULL) { diff --git a/include/configs/am335x_evm.h b/include/configs/am335x_evm.h index ea9e758..4147f9f 100644 --- a/include/configs/am335x_evm.h +++ b/include/configs/am335x_evm.h @@ -320,10 +320,10 @@ "boot part 0 1;" \ "rootfs part 0 2;" \ "MLO fat 0 1;" \ - "MLO.raw mmc 100 100;" \ - "u-boot.img.raw mmc 300 400;" \ - "spl-os-args.raw mmc 80 80;" \ - "spl-os-image.raw mmc 900 2000;" \ + "MLO.raw mmc 0x100 0x100;" \ + "u-boot.img.raw mmc 0x300 0x400;" \ + "spl-os-args.raw mmc 0x80 0x80;" \ + "spl-os-image.raw mmc 0x900 0x2000;" \ "spl-os-args fat 0 1;" \ "spl-os-image fat 0 1;" \ "u-boot.img fat 0 1;" \ diff --git a/include/configs/trats.h b/include/configs/trats.h index 5d8bd60..c4afecf 100644 --- a/include/configs/trats.h +++ b/include/configs/trats.h @@ -101,7 +101,7 @@ "name="PARTS_UMS",size=-,uuid=${uuid_gpt_"PARTS_UMS"}\0" \ #define CONFIG_DFU_ALT \ - "u-boot mmc 80 400;" \ + "u-boot raw 0x80 0x400;" \ "uImage ext4 0 2;" \ "modem.bin ext4 0 2;" \ "exynos4210-trats.dtb ext4 0 2;" \ @@ -112,7 +112,7 @@ ""PARTS_ROOT" part 0 5;" \ ""PARTS_DATA" part 0 6;" \ ""PARTS_UMS" part 0 7;" \ - "params.bin mmc 0x38 0x8\0" + "params.bin raw 0x38 0x8\0" #define CONFIG_EXTRA_ENV_SETTINGS \ "bootk=" \ diff --git a/include/configs/trats2.h b/include/configs/trats2.h index 53d449c..14def7d 100644 --- a/include/configs/trats2.h +++ b/include/configs/trats2.h @@ -91,7 +91,7 @@ "name="PARTS_UMS",size=-,uuid=${uuid_gpt_"PARTS_UMS"}\0" \ #define CONFIG_DFU_ALT \ - "u-boot mmc 80 800;" \ + "u-boot raw 0x80 0x800;" \ "uImage ext4 0 2;" \ "modem.bin ext4 0 2;" \ "exynos4412-trats2.dtb ext4 0 2;" \ @@ -102,7 +102,7 @@ ""PARTS_ROOT" part 0 5;" \ ""PARTS_DATA" part 0 6;" \ ""PARTS_UMS" part 0 7;" \ - "params.bin mmc 0x38 0x8\0" + "params.bin raw 0x38 0x8\0" #define CONFIG_EXTRA_ENV_SETTINGS \ "bootk=" \ -- cgit v1.1 From 41c2d60b3abad79f94a872d53ede016b1a891abc Mon Sep 17 00:00:00 2001 From: Mateusz Zalega Date: Mon, 28 Apr 2014 21:13:26 +0200 Subject: ums: always initialize mmc before ums_disk_init() In cases when MMC hadn't been initialized before, ie. by the user or other subsystem, it was still uninitialized while UMS media capacity check, leading to broken ums command. UMS has to initialize resources it uses. Tested on Samsung Goni. Signed-off-by: Mateusz Zalega Tested-by: Mateusz Zalega Acked-by: Lukasz Majewski Cc: Minkyu Kang --- board/samsung/common/ums.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/board/samsung/common/ums.c b/board/samsung/common/ums.c index dc155ad..cebabe9 100644 --- a/board/samsung/common/ums.c +++ b/board/samsung/common/ums.c @@ -66,11 +66,9 @@ static struct ums *ums_disk_init(struct mmc *mmc) struct ums *ums_init(unsigned int dev_num) { - struct mmc *mmc = NULL; + struct mmc *mmc = find_mmc_device(dev_num); - mmc = find_mmc_device(dev_num); - if (!mmc) + if (!mmc || mmc_init(mmc)) return NULL; - return ums_disk_init(mmc); } -- cgit v1.1 From fad8edf0f72b8aba8885d2d137ebb58b3428806a Mon Sep 17 00:00:00 2001 From: Mateusz Zalega Date: Mon, 28 Apr 2014 21:13:27 +0200 Subject: am335x: dfu: disable DFU in am335x_evm SPL build Future patches will make DFU too large to fit in this board's SPL build. Signed-off-by: Mateusz Zalega Acked-by: Tom Rini Reviewed-by: Lukasz Majewski --- include/configs/am335x_evm.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/configs/am335x_evm.h b/include/configs/am335x_evm.h index 4147f9f..670e3f1 100644 --- a/include/configs/am335x_evm.h +++ b/include/configs/am335x_evm.h @@ -312,6 +312,7 @@ #endif /* USB Device Firmware Update support */ +#ifndef CONFIG_SPL_BUILD #define CONFIG_DFU_FUNCTION #define CONFIG_DFU_MMC #define CONFIG_CMD_DFU @@ -354,6 +355,7 @@ DFU_ALT_INFO_MMC \ DFU_ALT_INFO_RAM \ DFU_ALT_INFO_NAND +#endif /* * Default to using SPI for environment, etc. -- cgit v1.1 From c4d0e856047f2689278ffea63a562c4f22a35ee3 Mon Sep 17 00:00:00 2001 From: Mateusz Zalega Date: Mon, 28 Apr 2014 21:13:28 +0200 Subject: USB: gadget: added a saner gadget downloader registration API Preprocessor definitions and hardcoded implementation selection in g_dnl core were replaced by a linker list made of (usb_function_name, bind_callback) pairs. Signed-off-by: Mateusz Zalega Acked-by: Lukasz Majewski Acked-by: Marek Vasut --- common/cmd_dfu.c | 3 +- common/cmd_thordown.c | 3 +- common/cmd_usb_mass_storage.c | 2 +- drivers/usb/gadget/f_dfu.c | 3 ++ drivers/usb/gadget/f_mass_storage.c | 3 ++ drivers/usb/gadget/f_thor.c | 2 ++ drivers/usb/gadget/g_dnl.c | 64 ++++++++++++++++--------------------- include/dfu.h | 7 ---- include/g_dnl.h | 23 +++++++++++++ include/thor.h | 8 ----- include/usb_mass_storage.h | 8 ----- 11 files changed, 62 insertions(+), 64 deletions(-) diff --git a/common/cmd_dfu.c b/common/cmd_dfu.c index 5547678..a03538d 100644 --- a/common/cmd_dfu.c +++ b/common/cmd_dfu.c @@ -22,7 +22,6 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) char *interface = argv[2]; char *devstring = argv[3]; - char *s = "dfu"; int ret, i = 0; ret = dfu_init_env_entities(interface, simple_strtoul(devstring, @@ -38,7 +37,7 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) int controller_index = simple_strtoul(usb_controller, NULL, 0); board_usb_init(controller_index, USB_INIT_DEVICE); - g_dnl_register(s); + g_dnl_register("usb_dnl_dfu"); while (1) { if (dfu_reset()) /* diff --git a/common/cmd_thordown.c b/common/cmd_thordown.c index c4b3511..2dd7509 100644 --- a/common/cmd_thordown.c +++ b/common/cmd_thordown.c @@ -22,7 +22,6 @@ int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) char *interface = argv[2]; char *devstring = argv[3]; - const char *s = "thor"; int ret; puts("TIZEN \"THOR\" Downloader\n"); @@ -40,7 +39,7 @@ int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) goto exit; } - g_dnl_register(s); + g_dnl_register("usb_dnl_thor"); ret = thor_init(); if (ret) { diff --git a/common/cmd_usb_mass_storage.c b/common/cmd_usb_mass_storage.c index 14a5b6a..d8d9efd 100644 --- a/common/cmd_usb_mass_storage.c +++ b/common/cmd_usb_mass_storage.c @@ -40,7 +40,7 @@ int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag, return CMD_RET_FAILURE; } - g_dnl_register("ums"); + g_dnl_register("usb_dnl_ums"); /* Timeout unit: seconds */ int cable_ready_timeout = UMS_CABLE_READY_TIMEOUT; diff --git a/drivers/usb/gadget/f_dfu.c b/drivers/usb/gadget/f_dfu.c index de75ff1..1b1e179 100644 --- a/drivers/usb/gadget/f_dfu.c +++ b/drivers/usb/gadget/f_dfu.c @@ -24,6 +24,7 @@ #include #include +#include #include "f_dfu.h" struct f_dfu { @@ -817,3 +818,5 @@ int dfu_add(struct usb_configuration *c) return dfu_bind_config(c); } + +DECLARE_GADGET_BIND_CALLBACK(usb_dnl_dfu, dfu_add); diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 4fae5cd..6374bb9 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -255,6 +255,7 @@ #include #include #include +#include /*------------------------------------------------------------------------*/ @@ -2778,3 +2779,5 @@ int fsg_init(struct ums *ums_dev) return 0; } + +DECLARE_GADGET_BIND_CALLBACK(usb_dnl_ums, fsg_add); diff --git a/drivers/usb/gadget/f_thor.c b/drivers/usb/gadget/f_thor.c index ba47945..feef9e4 100644 --- a/drivers/usb/gadget/f_thor.c +++ b/drivers/usb/gadget/f_thor.c @@ -1004,3 +1004,5 @@ int thor_add(struct usb_configuration *c) debug("%s:\n", __func__); return thor_func_init(c); } + +DECLARE_GADGET_BIND_CALLBACK(usb_dnl_thor, thor_add); diff --git a/drivers/usb/gadget/g_dnl.c b/drivers/usb/gadget/g_dnl.c index 973d737..743bae5 100644 --- a/drivers/usb/gadget/g_dnl.c +++ b/drivers/usb/gadget/g_dnl.c @@ -41,7 +41,6 @@ #define DRIVER_VERSION "usb_dnl 2.0" -static const char shortname[] = "usb_dnl_"; static const char product[] = "USB download gadget"; static char g_dnl_serial[MAX_STRING_SERIAL]; static const char manufacturer[] = CONFIG_G_DNL_MANUFACTURER; @@ -96,29 +95,36 @@ static int g_dnl_unbind(struct usb_composite_dev *cdev) free(cdev->config); cdev->config = NULL; debug("%s: calling usb_gadget_disconnect for " - "controller '%s'\n", shortname, gadget->name); + "controller '%s'\n", __func__, gadget->name); usb_gadget_disconnect(gadget); return 0; } +static inline struct g_dnl_bind_callback *g_dnl_bind_callback_first(void) +{ + return ll_entry_start(struct g_dnl_bind_callback, + g_dnl_bind_callbacks); +} + +static inline struct g_dnl_bind_callback *g_dnl_bind_callback_end(void) +{ + return ll_entry_end(struct g_dnl_bind_callback, + g_dnl_bind_callbacks); +} + static int g_dnl_do_config(struct usb_configuration *c) { const char *s = c->cdev->driver->name; - int ret = -1; + struct g_dnl_bind_callback *callback = g_dnl_bind_callback_first(); debug("%s: configuration: 0x%p composite dev: 0x%p\n", __func__, c, c->cdev); - printf("GADGET DRIVER: %s\n", s); - if (!strcmp(s, "usb_dnl_dfu")) - ret = dfu_add(c); - else if (!strcmp(s, "usb_dnl_ums")) - ret = fsg_add(c); - else if (!strcmp(s, "usb_dnl_thor")) - ret = thor_add(c); - - return ret; + for (; callback != g_dnl_bind_callback_end(); callback++) + if (!strcmp(s, callback->usb_function_name)) + return callback->fptr(c); + return -ENODEV; } static int g_dnl_config_register(struct usb_composite_dev *cdev) @@ -208,12 +214,12 @@ static int g_dnl_bind(struct usb_composite_dev *cdev) device_desc.bcdDevice = cpu_to_le16(gcnum); else { debug("%s: controller '%s' not recognized\n", - shortname, gadget->name); + __func__, gadget->name); device_desc.bcdDevice = __constant_cpu_to_le16(0x9999); } debug("%s: calling usb_gadget_connect for " - "controller '%s'\n", shortname, gadget->name); + "controller '%s'\n", __func__, gadget->name); usb_gadget_connect(gadget); return 0; @@ -232,36 +238,22 @@ static struct usb_composite_driver g_dnl_driver = { .unbind = g_dnl_unbind, }; -int g_dnl_register(const char *type) +/* + * NOTICE: + * Registering via USB function name won't be necessary after rewriting + * g_dnl to support multiple USB functions. + */ +int g_dnl_register(const char *name) { - /* The largest function name is 4 */ - static char name[sizeof(shortname) + 4]; - int ret; - - if (!strcmp(type, "dfu")) { - strcpy(name, shortname); - strcat(name, type); - } else if (!strcmp(type, "ums")) { - strcpy(name, shortname); - strcat(name, type); - } else if (!strcmp(type, "thor")) { - strcpy(name, shortname); - strcat(name, type); - } else { - printf("%s: unknown command: %s\n", __func__, type); - return -EINVAL; - } + int ret = usb_composite_register(&g_dnl_driver); + debug("%s: g_dnl_driver.name = %s\n", __func__, name); g_dnl_driver.name = name; - debug("%s: g_dnl_driver.name: %s\n", __func__, g_dnl_driver.name); - ret = usb_composite_register(&g_dnl_driver); - if (ret) { printf("%s: failed!, error: %d\n", __func__, ret); return ret; } - return 0; } diff --git a/include/dfu.h b/include/dfu.h index dcd3215..2409168 100644 --- a/include/dfu.h +++ b/include/dfu.h @@ -168,12 +168,5 @@ static inline int dfu_fill_entity_ram(struct dfu_entity *dfu, char *s) } #endif -#ifdef CONFIG_DFU_FUNCTION int dfu_add(struct usb_configuration *c); -#else -int dfu_add(struct usb_configuration *c) -{ - return 0; -} -#endif #endif /* __DFU_ENTITY_H_ */ diff --git a/include/g_dnl.h b/include/g_dnl.h index f4e8d10..1b1b35e 100644 --- a/include/g_dnl.h +++ b/include/g_dnl.h @@ -10,6 +10,29 @@ #include #include +#include +#include + +/* + * @usb_fname: unescaped USB function name + * @callback_ptr: bind callback, one per function name + */ +#define DECLARE_GADGET_BIND_CALLBACK(usb_fname, callback_ptr) \ + ll_entry_declare(struct g_dnl_bind_callback, \ + __usb_function_name_##usb_fname, \ + g_dnl_bind_callbacks) = { \ + .usb_function_name = #usb_fname, \ + .fptr = callback_ptr \ + } + +typedef int (*g_dnl_bind_callback_f)(struct usb_configuration *); + +/* used in Gadget downloader callback linker list */ +struct g_dnl_bind_callback { + const char *usb_function_name; + g_dnl_bind_callback_f fptr; +}; + int g_dnl_bind_fixup(struct usb_device_descriptor *, const char *); int g_dnl_board_usb_cable_connected(void); int g_dnl_register(const char *s); diff --git a/include/thor.h b/include/thor.h index afeade4..5051be7 100644 --- a/include/thor.h +++ b/include/thor.h @@ -15,13 +15,5 @@ int thor_handle(void); int thor_init(void); - -#ifdef CONFIG_THOR_FUNCTION int thor_add(struct usb_configuration *c); -#else -int thor_add(struct usb_configuration *c) -{ - return 0; -} -#endif #endif /* __THOR_H_ */ diff --git a/include/usb_mass_storage.h b/include/usb_mass_storage.h index 058dcf1..ed46064 100644 --- a/include/usb_mass_storage.h +++ b/include/usb_mass_storage.h @@ -40,13 +40,5 @@ int fsg_init(struct ums *); void fsg_cleanup(void); struct ums *ums_init(unsigned int); int fsg_main_thread(void *); - -#ifdef CONFIG_USB_GADGET_MASS_STORAGE int fsg_add(struct usb_configuration *c); -#else -int fsg_add(struct usb_configuration *c) -{ - return 0; -} -#endif #endif /* __USB_MASS_STORAGE_H__ */ -- cgit v1.1 From 25fbf96b24fd3fe0a5252c374b445be32f42b0c8 Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Thu, 1 May 2014 15:45:16 -0600 Subject: USB: gadget: save driver name before registering it g_dnl_register() currently first attempts to register a composite driver by name, and then saves the driver name once it's registered. Internally to the registration code, g_dnl_do_config() is called and attempts to compare the composite device's name with the list of known device names. This fails since the composite device's name has not yet been stored. This means that the first time "ums 0 0" is run, it fails, but subsequent attempts succeed. Re-order the name-saving and registration code to solve this. Fixes: e5b834e07f51 ("USB: gadget: added a saner gadget downloader registration API") Signed-off-by: Stephen Warren --- drivers/usb/gadget/g_dnl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/g_dnl.c b/drivers/usb/gadget/g_dnl.c index 743bae5..25611ac 100644 --- a/drivers/usb/gadget/g_dnl.c +++ b/drivers/usb/gadget/g_dnl.c @@ -245,11 +245,12 @@ static struct usb_composite_driver g_dnl_driver = { */ int g_dnl_register(const char *name) { - int ret = usb_composite_register(&g_dnl_driver); + int ret; debug("%s: g_dnl_driver.name = %s\n", __func__, name); g_dnl_driver.name = name; + ret = usb_composite_register(&g_dnl_driver); if (ret) { printf("%s: failed!, error: %d\n", __func__, ret); return ret; -- cgit v1.1 From af41d6b4cb1602abebaaa9c8774a9b0ece564796 Mon Sep 17 00:00:00 2001 From: Mateusz Zalega Date: Tue, 29 Apr 2014 20:14:22 +0200 Subject: common: fixed linker-list example Last argument shouldn't be there. Signed-off-by: Mateusz Zalega Acked-by: Marek Vasut Cc: Tom Rini --- include/linker_lists.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linker_lists.h b/include/linker_lists.h index 997d149..557e627 100644 --- a/include/linker_lists.h +++ b/include/linker_lists.h @@ -228,7 +228,7 @@ * and it's name. * * Example: - * ll_entry_declare(struct my_sub_cmd, my_sub_cmd, cmd_sub, cmd.sub) = { + * ll_entry_declare(struct my_sub_cmd, my_sub_cmd, cmd_sub) = { * .x = 3, * .y = 4, * }; -- cgit v1.1