Commit 3c3f13f81942134edff280fcb5e7137c623e7dac

Authored by Tom Rini

Merge branch 'master' of git://git.denx.de/u-boot-usb

Showing 40 changed files Side-by-side Diff

... ... @@ -1484,13 +1484,6 @@
1484 1484 for your device
1485 1485 - CONFIG_USBD_PRODUCTID 0xFFFF
1486 1486  
1487   - Some USB device drivers may need to check USB cable attachment.
1488   - In this case you can enable following config in BoardName.h:
1489   - CONFIG_USB_CABLE_CHECK
1490   - This enables function definition:
1491   - - usb_cable_connected() in include/usb.h
1492   - Implementation of this function is board-specific.
1493   -
1494 1487 - ULPI Layer Support:
1495 1488 The ULPI (UTMI Low Pin (count) Interface) PHYs are supported via
1496 1489 the generic ULPI layer. The generic layer accesses the ULPI PHY
arch/arm/include/asm/arch-rmobile/ehci-rmobile.h
  1 +/*
  2 + * Copyright (C) 2013,2014 Renesas Electronics Corporation
  3 + * Copyright (C) 2014 Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
  4 + *
  5 + * SPDX-License-Identifier: GPL-2.0
  6 + */
  7 +
  8 +#ifndef __EHCI_RMOBILE_H__
  9 +#define __EHCI_RMOBILE_H__
  10 +
  11 +/* Register offset */
  12 +#define OHCI_OFFSET 0x00
  13 +#define OHCI_SIZE 0x1000
  14 +#define EHCI_OFFSET 0x1000
  15 +#define EHCI_SIZE 0x1000
  16 +
  17 +#define EHCI_USBCMD (EHCI_OFFSET + 0x0020)
  18 +
  19 +/* USBCTR */
  20 +#define DIRPD (1 << 8)
  21 +#define PLL_RST (1 << 2)
  22 +#define PCICLK_MASK (1 << 1)
  23 +#define USBH_RST (1 << 0)
  24 +
  25 +/* CMND_STS */
  26 +#define SERREN (1 << 8)
  27 +#define PERREN (1 << 6)
  28 +#define MASTEREN (1 << 2)
  29 +#define MEMEN (1 << 1)
  30 +
  31 +/* PCIAHB_WIN1_CTR and PCIAHB_WIN2_CTR */
  32 +#define PCIAHB_WIN_PREFETCH ((1 << 1)|(1 << 0))
  33 +
  34 +/* AHBPCI_WIN1_CTR */
  35 +#define PCIWIN1_PCICMD ((1 << 3)|(1 << 1))
  36 +#define AHB_CFG_AHBPCI 0x40000000
  37 +#define AHB_CFG_HOST 0x80000000
  38 +
  39 +/* AHBPCI_WIN2_CTR */
  40 +#define PCIWIN2_PCICMD ((1 << 2)|(1 << 1))
  41 +
  42 +/* PCI_INT_ENABLE */
  43 +#define USBH_PMEEN (1 << 19)
  44 +#define USBH_INTBEN (1 << 17)
  45 +#define USBH_INTAEN (1 << 16)
  46 +
  47 +/* AHB_BUS_CTR */
  48 +#define SMODE_READY_CTR (1 << 17)
  49 +#define SMODE_READ_BURST (1 << 16)
  50 +#define MMODE_HBUSREQ (1 << 7)
  51 +#define MMODE_BOUNDARY ((1 << 6)|(1 << 5))
  52 +#define MMODE_BURST_WIDTH ((1 << 4)|(1 << 3))
  53 +#define MMODE_SINGLE_MODE ((1 << 4)|(1 << 3))
  54 +#define MMODE_WR_INCR (1 << 2)
  55 +#define MMODE_BYTE_BURST (1 << 1)
  56 +#define MMODE_HTRANS (1 << 0)
  57 +
  58 +/* PCI_ARBITER_CTR */
  59 +#define PCIBUS_PARK_TIMER 0x00FF0000
  60 +#define PCIBUS_PARK_TIMER_SET 0x00070000
  61 +#define PCIBP_MODE (1 << 12)
  62 +#define PCIREQ7 (1 << 7)
  63 +#define PCIREQ6 (1 << 6)
  64 +#define PCIREQ5 (1 << 5)
  65 +#define PCIREQ4 (1 << 4)
  66 +#define PCIREQ3 (1 << 3)
  67 +#define PCIREQ2 (1 << 2)
  68 +#define PCIREQ1 (1 << 1)
  69 +#define PCIREQ0 (1 << 0)
  70 +
  71 +#define SMSTPCR7 0xE615014C
  72 +#define SMSTPCR703 (1 << 3)
  73 +
  74 +/* Init AHB master and slave functions of the host logic */
  75 +#define AHB_BUS_CTR_INIT \
  76 + (SMODE_READY_CTR | MMODE_HBUSREQ | MMODE_WR_INCR | \
  77 + MMODE_BYTE_BURST | MMODE_HTRANS)
  78 +
  79 +#define USBCTR_WIN_SIZE_1GB 0x800
  80 +
  81 +/* PCI Configuration Registers */
  82 +#define PCI_CONF_OHCI_OFFSET 0x10000
  83 +#define PCI_CONF_EHCI_OFFSET 0x10100
  84 +struct ahb_pciconf {
  85 + u32 vid_did;
  86 + u32 cmnd_sts;
  87 + u32 rev;
  88 + u32 cache_line;
  89 + u32 basead;
  90 +};
  91 +
  92 +/* PCI Configuration Registers for AHB-PCI Bridge Registers */
  93 +#define PCI_CONF_AHBPCI_OFFSET 0x10000
  94 +struct ahbconf_pci_bridge {
  95 + u32 vid_did; /* 0x00 */
  96 + u32 cmnd_sts;
  97 + u32 revid_cc;
  98 + u32 cls_lt_ht_bist;
  99 + u32 basead; /* 0x10 */
  100 + u32 win1_basead;
  101 + u32 win2_basead;
  102 + u32 dummy0[5];
  103 + u32 ssvdi_ssid; /* 0x2C */
  104 + u32 dummy1[4];
  105 + u32 intr_line_pin;
  106 +};
  107 +
  108 +/* AHB-PCI Bridge PCI Communication Registers */
  109 +#define AHBPCI_OFFSET 0x10800
  110 +struct ahbcom_pci_bridge {
  111 + u32 pciahb_win1_ctr; /* 0x00 */
  112 + u32 pciahb_win2_ctr;
  113 + u32 pciahb_dct_ctr;
  114 + u32 dummy0;
  115 + u32 ahbpci_win1_ctr; /* 0x10 */
  116 + u32 ahbpci_win2_ctr;
  117 + u32 dummy1;
  118 + u32 ahbpci_dct_ctr;
  119 + u32 pci_int_enable; /* 0x20 */
  120 + u32 pci_int_status;
  121 + u32 dummy2[2];
  122 + u32 ahb_bus_ctr; /* 0x30 */
  123 + u32 usbctr;
  124 + u32 dummy3[2];
  125 + u32 pci_arbiter_ctr; /* 0x40 */
  126 + u32 dummy4;
  127 + u32 pci_unit_rev; /* 0x48 */
  128 +};
  129 +
  130 +struct rmobile_ehci_reg {
  131 + u32 hciversion; /* hciversion/caplength */
  132 + u32 hcsparams; /* hcsparams */
  133 + u32 hccparams; /* hccparams */
  134 + u32 hcsp_portroute; /* hcsp_portroute */
  135 + u32 usbcmd; /* usbcmd */
  136 + u32 usbsts; /* usbsts */
  137 + u32 usbintr; /* usbintr */
  138 + u32 frindex; /* frindex */
  139 + u32 ctrldssegment; /* ctrldssegment */
  140 + u32 periodiclistbase; /* periodiclistbase */
  141 + u32 asynclistaddr; /* asynclistaddr */
  142 + u32 dummy[9];
  143 + u32 configflag; /* configflag */
  144 + u32 portsc; /* portsc */
  145 +};
  146 +
  147 +#endif /* __EHCI_RMOBILE_H__ */
board/samsung/common/ums.c
... ... @@ -66,12 +66,10 @@
66 66  
67 67 struct ums *ums_init(unsigned int dev_num)
68 68 {
69   - struct mmc *mmc = NULL;
  69 + struct mmc *mmc = find_mmc_device(dev_num);
70 70  
71   - mmc = find_mmc_device(dev_num);
72   - if (!mmc)
  71 + if (!mmc || mmc_init(mmc))
73 72 return NULL;
74   -
75 73 return ums_disk_init(mmc);
76 74 }
board/samsung/origen/origen.c
... ... @@ -30,13 +30,6 @@
30 30 return 0;
31 31 }
32 32  
33   -#ifdef CONFIG_USB_CABLE_CHECK
34   -int usb_cable_connected(void)
35   -{
36   - return 0;
37   -}
38   -#endif
39   -
40 33 #ifdef CONFIG_BOARD_EARLY_INIT_F
41 34 int exynos_early_init_f(void)
42 35 {
board/samsung/trats/trats.c
... ... @@ -430,8 +430,7 @@
430 430 return s3c_udc_probe(&s5pc210_otg_data);
431 431 }
432 432  
433   -#ifdef CONFIG_USB_CABLE_CHECK
434   -int usb_cable_connected(void)
  433 +int g_dnl_board_usb_cable_connected(void)
435 434 {
436 435 struct pmic *muic = pmic_get("MAX8997_MUIC");
437 436 if (!muic)
... ... @@ -439,7 +438,6 @@
439 438  
440 439 return !!muic->chrg->chrg_type(muic);
441 440 }
442   -#endif
443 441 #endif
444 442  
445 443 static void pmic_reset(void)
board/samsung/trats2/trats2.c
... ... @@ -312,8 +312,7 @@
312 312 return s3c_udc_probe(&s5pc210_otg_data);
313 313 }
314 314  
315   -#ifdef CONFIG_USB_CABLE_CHECK
316   -int usb_cable_connected(void)
  315 +int g_dnl_board_usb_cable_connected(void)
317 316 {
318 317 struct pmic *muic = pmic_get("MAX77693_MUIC");
319 318 if (!muic)
... ... @@ -321,7 +320,6 @@
321 320  
322 321 return !!muic->chrg->chrg_type(muic);
323 322 }
324   -#endif
325 323 #endif
326 324  
327 325 static int pmic_init_max77686(void)
board/samsung/universal_c210/universal.c
... ... @@ -197,13 +197,6 @@
197 197 return s3c_udc_probe(&s5pc210_otg_data);
198 198 }
199 199  
200   -#ifdef CONFIG_USB_CABLE_CHECK
201   -int usb_cable_connected(void)
202   -{
203   - return 0;
204   -}
205   -#endif
206   -
207 200 int exynos_early_init_f(void)
208 201 {
209 202 wdt_stop();
... ... @@ -22,7 +22,6 @@
22 22 char *interface = argv[2];
23 23 char *devstring = argv[3];
24 24  
25   - char *s = "dfu";
26 25 int ret, i = 0;
27 26  
28 27 ret = dfu_init_env_entities(interface, simple_strtoul(devstring,
... ... @@ -38,7 +37,7 @@
38 37 int controller_index = simple_strtoul(usb_controller, NULL, 0);
39 38 board_usb_init(controller_index, USB_INIT_DEVICE);
40 39  
41   - g_dnl_register(s);
  40 + g_dnl_register("usb_dnl_dfu");
42 41 while (1) {
43 42 if (dfu_reset())
44 43 /*
common/cmd_thordown.c
... ... @@ -22,7 +22,6 @@
22 22 char *interface = argv[2];
23 23 char *devstring = argv[3];
24 24  
25   - const char *s = "thor";
26 25 int ret;
27 26  
28 27 puts("TIZEN \"THOR\" Downloader\n");
... ... @@ -40,7 +39,7 @@
40 39 goto exit;
41 40 }
42 41  
43   - g_dnl_register(s);
  42 + g_dnl_register("usb_dnl_thor");
44 43  
45 44 ret = thor_init();
46 45 if (ret) {
common/cmd_usb_mass_storage.c
... ... @@ -40,15 +40,19 @@
40 40 return CMD_RET_FAILURE;
41 41 }
42 42  
43   - g_dnl_register("ums");
  43 + g_dnl_register("usb_dnl_ums");
44 44  
45 45 /* Timeout unit: seconds */
46 46 int cable_ready_timeout = UMS_CABLE_READY_TIMEOUT;
47 47  
48   - if (!usb_cable_connected()) {
  48 + if (!g_dnl_board_usb_cable_connected()) {
  49 + /*
  50 + * Won't execute if we don't know whether the cable is
  51 + * connected.
  52 + */
49 53 puts("Please connect USB cable.\n");
50 54  
51   - while (!usb_cable_connected()) {
  55 + while (!g_dnl_board_usb_cable_connected()) {
52 56 if (ctrlc()) {
53 57 puts("\rCTRL+C - Operation aborted.\n");
54 58 goto exit;
... ... @@ -91,6 +91,12 @@
91 91 #define USB_KBD_LEDMASK \
92 92 (USB_KBD_NUMLOCK | USB_KBD_CAPSLOCK | USB_KBD_SCROLLLOCK)
93 93  
  94 +/*
  95 + * USB Keyboard reports are 8 bytes in boot protocol.
  96 + * Appendix B of HID Device Class Definition 1.11
  97 + */
  98 +#define USB_KBD_BOOT_REPORT_SIZE 8
  99 +
94 100 struct usb_kbd_pdata {
95 101 uint32_t repeat_delay;
96 102  
... ... @@ -99,7 +105,7 @@
99 105 uint8_t usb_kbd_buffer[USB_KBD_BUFFER_LEN];
100 106  
101 107 uint8_t *new;
102   - uint8_t old[8];
  108 + uint8_t old[USB_KBD_BOOT_REPORT_SIZE];
103 109  
104 110 uint8_t flags;
105 111 };
... ... @@ -131,7 +137,8 @@
131 137 /* Submit a interrupt transfer request */
132 138 maxp = usb_maxpacket(usb_kbd_dev, pipe);
133 139 usb_submit_int_msg(usb_kbd_dev, pipe, data->new,
134   - maxp > 8 ? 8 : maxp, ep->bInterval);
  140 + min(maxp, USB_KBD_BOOT_REPORT_SIZE),
  141 + ep->bInterval);
135 142 }
136 143  
137 144 /* Puts character in the queue and sets up the in and out pointer. */
138 145  
... ... @@ -266,8 +273,11 @@
266 273 old = data->old;
267 274 }
268 275  
269   - if ((old[i] > 3) && (memscan(new + 2, old[i], 6) == new + 8))
  276 + if ((old[i] > 3) &&
  277 + (memscan(new + 2, old[i], USB_KBD_BOOT_REPORT_SIZE - 2) ==
  278 + new + USB_KBD_BOOT_REPORT_SIZE)) {
270 279 res |= usb_kbd_translate(data, old[i], data->new[0], up);
  280 + }
271 281  
272 282 return res;
273 283 }
... ... @@ -285,7 +295,7 @@
285 295 else if ((data->new[0] == LEFT_CNTR) || (data->new[0] == RIGHT_CNTR))
286 296 data->flags |= USB_KBD_CTRL;
287 297  
288   - for (i = 2; i < 8; i++) {
  298 + for (i = 2; i < USB_KBD_BOOT_REPORT_SIZE; i++) {
289 299 res |= usb_kbd_service_key(dev, i, 0);
290 300 res |= usb_kbd_service_key(dev, i, 1);
291 301 }
... ... @@ -297,7 +307,7 @@
297 307 if (res == 1)
298 308 usb_kbd_setled(dev);
299 309  
300   - memcpy(data->old, data->new, 8);
  310 + memcpy(data->old, data->new, USB_KBD_BOOT_REPORT_SIZE);
301 311  
302 312 return 1;
303 313 }
... ... @@ -305,7 +315,8 @@
305 315 /* Keyboard interrupt handler */
306 316 static int usb_kbd_irq(struct usb_device *dev)
307 317 {
308   - if ((dev->irq_status != 0) || (dev->irq_act_len != 8)) {
  318 + if ((dev->irq_status != 0) ||
  319 + (dev->irq_act_len != USB_KBD_BOOT_REPORT_SIZE)) {
309 320 debug("USB KBD: Error %lX, len %d\n",
310 321 dev->irq_status, dev->irq_act_len);
311 322 return 1;
... ... @@ -333,7 +344,8 @@
333 344 /* Submit a interrupt transfer request */
334 345 maxp = usb_maxpacket(dev, pipe);
335 346 usb_submit_int_msg(dev, pipe, &data->new[0],
336   - maxp > 8 ? 8 : maxp, ep->bInterval);
  347 + min(maxp, USB_KBD_BOOT_REPORT_SIZE),
  348 + ep->bInterval);
337 349  
338 350 usb_kbd_irq_worker(dev);
339 351 #elif defined(CONFIG_SYS_USB_EVENT_POLL_VIA_CONTROL_EP)
... ... @@ -341,8 +353,8 @@
341 353 struct usb_kbd_pdata *data = dev->privptr;
342 354 iface = &dev->config.if_desc[0];
343 355 usb_get_report(dev, iface->desc.bInterfaceNumber,
344   - 1, 0, data->new, sizeof(data->new));
345   - if (memcmp(data->old, data->new, sizeof(data->new)))
  356 + 1, 0, data->new, USB_KBD_BOOT_REPORT_SIZE);
  357 + if (memcmp(data->old, data->new, USB_KBD_BOOT_REPORT_SIZE))
346 358 usb_kbd_irq_worker(dev);
347 359 #endif
348 360 }
... ... @@ -441,7 +453,8 @@
441 453 memset(data, 0, sizeof(struct usb_kbd_pdata));
442 454  
443 455 /* allocate input buffer aligned and sized to USB DMA alignment */
444   - data->new = memalign(USB_DMA_MINALIGN, roundup(8, USB_DMA_MINALIGN));
  456 + data->new = memalign(USB_DMA_MINALIGN,
  457 + roundup(USB_KBD_BOOT_REPORT_SIZE, USB_DMA_MINALIGN));
445 458  
446 459 /* Insert private data into USB device structure */
447 460 dev->privptr = data;
... ... @@ -459,7 +472,8 @@
459 472 usb_set_idle(dev, iface->desc.bInterfaceNumber, REPEAT_RATE, 0);
460 473  
461 474 debug("USB KBD: enable interrupt pipe...\n");
462   - if (usb_submit_int_msg(dev, pipe, data->new, maxp > 8 ? 8 : maxp,
  475 + if (usb_submit_int_msg(dev, pipe, data->new,
  476 + min(maxp, USB_KBD_BOOT_REPORT_SIZE),
463 477 ep->bInterval) < 0) {
464 478 printf("Failed to get keyboard state from device %04x:%04x\n",
465 479 dev->descriptor.idVendor, dev->descriptor.idProduct);
... ... @@ -219,7 +219,7 @@
219 219 ret = tret;
220 220 }
221 221  
222   - return ret = 0 ? size : ret;
  222 + return ret;
223 223 }
224 224  
225 225 static int dfu_read_buffer_fill(struct dfu_entity *dfu, void *buf, int size)
drivers/dfu/dfu_mmc.c
... ... @@ -184,66 +184,95 @@
184 184 return ret;
185 185 }
186 186  
  187 +/*
  188 + * @param s Parameter string containing space-separated arguments:
  189 + * 1st:
  190 + * raw (raw read/write)
  191 + * fat (files)
  192 + * ext4 (^)
  193 + * part (partition image)
  194 + * 2nd and 3rd:
  195 + * lba_start and lba_size, for raw write
  196 + * mmc_dev and mmc_part, for filesystems and part
  197 + */
187 198 int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s)
188 199 {
189   - int dev, part;
  200 + const char *entity_type;
  201 + size_t second_arg;
  202 + size_t third_arg;
  203 +
190 204 struct mmc *mmc;
191   - block_dev_desc_t *blk_dev;
192   - disk_partition_t partinfo;
193   - char *st;
194 205  
195   - dfu->dev_type = DFU_DEV_MMC;
196   - st = strsep(&s, " ");
197   - if (!strcmp(st, "mmc")) {
198   - dfu->layout = DFU_RAW_ADDR;
199   - dfu->data.mmc.lba_start = simple_strtoul(s, &s, 16);
200   - dfu->data.mmc.lba_size = simple_strtoul(++s, &s, 16);
201   - dfu->data.mmc.lba_blk_size = get_mmc_blk_size(dfu->dev_num);
202   - } else if (!strcmp(st, "fat")) {
203   - dfu->layout = DFU_FS_FAT;
204   - } else if (!strcmp(st, "ext4")) {
205   - dfu->layout = DFU_FS_EXT4;
206   - } else if (!strcmp(st, "part")) {
  206 + const char *argv[3];
  207 + const char **parg = argv;
207 208  
208   - dfu->layout = DFU_RAW_ADDR;
209   -
210   - dev = simple_strtoul(s, &s, 10);
211   - s++;
212   - part = simple_strtoul(s, &s, 10);
213   -
214   - mmc = find_mmc_device(dev);
215   - if (mmc == NULL || mmc_init(mmc)) {
216   - printf("%s: could not find mmc device #%d!\n",
217   - __func__, dev);
  209 + for (; parg < argv + sizeof(argv) / sizeof(*argv); ++parg) {
  210 + *parg = strsep(&s, " ");
  211 + if (*parg == NULL) {
  212 + error("Invalid number of arguments.\n");
218 213 return -ENODEV;
219 214 }
  215 + }
220 216  
221   - blk_dev = &mmc->block_dev;
222   - if (get_partition_info(blk_dev, part, &partinfo) != 0) {
223   - printf("%s: could not find partition #%d on mmc device #%d!\n",
224   - __func__, part, dev);
  217 + entity_type = argv[0];
  218 + /*
  219 + * Base 0 means we'll accept (prefixed with 0x or 0) base 16, 8,
  220 + * with default 10.
  221 + */
  222 + second_arg = simple_strtoul(argv[1], NULL, 0);
  223 + third_arg = simple_strtoul(argv[2], NULL, 0);
  224 +
  225 + mmc = find_mmc_device(dfu->dev_num);
  226 + if (mmc == NULL) {
  227 + error("Couldn't find MMC device no. %d.\n", dfu->dev_num);
  228 + return -ENODEV;
  229 + }
  230 +
  231 + if (mmc_init(mmc)) {
  232 + error("Couldn't init MMC device.\n");
  233 + return -ENODEV;
  234 + }
  235 +
  236 + if (!strcmp(entity_type, "raw")) {
  237 + dfu->layout = DFU_RAW_ADDR;
  238 + dfu->data.mmc.lba_start = second_arg;
  239 + dfu->data.mmc.lba_size = third_arg;
  240 + dfu->data.mmc.lba_blk_size = mmc->read_bl_len;
  241 + } else if (!strcmp(entity_type, "part")) {
  242 + disk_partition_t partinfo;
  243 + block_dev_desc_t *blk_dev = &mmc->block_dev;
  244 + int mmcdev = second_arg;
  245 + int mmcpart = third_arg;
  246 +
  247 + if (get_partition_info(blk_dev, mmcpart, &partinfo) != 0) {
  248 + error("Couldn't find part #%d on mmc device #%d\n",
  249 + mmcpart, mmcdev);
225 250 return -ENODEV;
226 251 }
227 252  
228   - dfu->data.mmc.lba_start = partinfo.start;
229   - dfu->data.mmc.lba_size = partinfo.size;
230   - dfu->data.mmc.lba_blk_size = partinfo.blksz;
231   -
  253 + dfu->layout = DFU_RAW_ADDR;
  254 + dfu->data.mmc.lba_start = partinfo.start;
  255 + dfu->data.mmc.lba_size = partinfo.size;
  256 + dfu->data.mmc.lba_blk_size = partinfo.blksz;
  257 + } else if (!strcmp(entity_type, "fat")) {
  258 + dfu->layout = DFU_FS_FAT;
  259 + } else if (!strcmp(entity_type, "ext4")) {
  260 + dfu->layout = DFU_FS_EXT4;
232 261 } else {
233   - printf("%s: Memory layout (%s) not supported!\n", __func__, st);
  262 + error("Memory layout (%s) not supported!\n", entity_type);
234 263 return -ENODEV;
235 264 }
236 265  
237   - if (dfu->layout == DFU_FS_EXT4 || dfu->layout == DFU_FS_FAT) {
238   - dfu->data.mmc.dev = simple_strtoul(s, &s, 10);
239   - dfu->data.mmc.part = simple_strtoul(++s, &s, 10);
  266 + /* if it's NOT a raw write */
  267 + if (strcmp(entity_type, "raw")) {
  268 + dfu->data.mmc.dev = second_arg;
  269 + dfu->data.mmc.part = third_arg;
240 270 }
241 271  
  272 + dfu->dev_type = DFU_DEV_MMC;
242 273 dfu->read_medium = dfu_read_medium_mmc;
243 274 dfu->write_medium = dfu_write_medium_mmc;
244 275 dfu->flush_medium = dfu_flush_medium_mmc;
245   -
246   - /* initial state */
247 276 dfu->inited = 0;
248 277  
249 278 return 0;
drivers/usb/gadget/Makefile
... ... @@ -13,6 +13,7 @@
13 13 obj-$(CONFIG_USB_GADGET_ATMEL_USBA) += atmel_usba_udc.o
14 14 obj-$(CONFIG_USB_GADGET_S3C_UDC_OTG) += s3c_udc_otg.o
15 15 obj-$(CONFIG_USB_GADGET_FOTG210) += fotg210.o
  16 +obj-$(CONFIG_CI_UDC) += ci_udc.o
16 17 obj-$(CONFIG_THOR_FUNCTION) += f_thor.o
17 18 obj-$(CONFIG_USBDOWNLOAD_GADGET) += g_dnl.o
18 19 obj-$(CONFIG_DFU_FUNCTION) += f_dfu.o
drivers/usb/gadget/ci_udc.c
... ... @@ -321,7 +321,7 @@
321 321 if (addr == ba)
322 322 return; /* not a bounce */
323 323  
324   - memcpy(ep->req.buf, ep->b_buf, ep->req.length);
  324 + memcpy(ep->req.buf, ep->b_buf, ep->req.actual);
325 325 free:
326 326 /* Large payloads use allocated buffer, free it. */
327 327 if (ep->b_buf != ep->b_fast)
... ... @@ -350,6 +350,9 @@
350 350 item->info = INFO_BYTES(len) | INFO_IOC | INFO_ACTIVE;
351 351 item->page0 = (uint32_t)ci_ep->b_buf;
352 352 item->page1 = ((uint32_t)ci_ep->b_buf & 0xfffff000) + 0x1000;
  353 + item->page2 = ((uint32_t)ci_ep->b_buf & 0xfffff000) + 0x2000;
  354 + item->page3 = ((uint32_t)ci_ep->b_buf & 0xfffff000) + 0x3000;
  355 + item->page4 = ((uint32_t)ci_ep->b_buf & 0xfffff000) + 0x4000;
353 356 ci_flush_qtd(num);
354 357  
355 358 head->next = (unsigned) item;
... ... @@ -385,7 +388,7 @@
385 388 num, in ? "in" : "out", item->info, item->page0);
386 389  
387 390 len = (item->info >> 16) & 0x7fff;
388   - ep->req.length -= len;
  391 + ep->req.actual = ep->req.length - len;
389 392 ci_debounce(ep, in);
390 393  
391 394 DBG("ept%d %s complete %x\n",
392 395  
... ... @@ -413,7 +416,11 @@
413 416  
414 417 ci_invalidate_qh(0);
415 418 memcpy(&r, head->setup_data, sizeof(struct usb_ctrlrequest));
  419 +#ifdef CONFIG_CI_UDC_HAS_HOSTPC
  420 + writel(EPT_RX(0), &udc->epsetupstat);
  421 +#else
416 422 writel(EPT_RX(0), &udc->epstat);
  423 +#endif
417 424 DBG("handle setup %s, %x, %x index %x value %x\n", reqname(r.bRequest),
418 425 r.bRequestType, r.bRequest, r.wIndex, r.wValue);
419 426  
... ... @@ -480,6 +487,9 @@
480 487 struct ept_queue_head *head;
481 488 struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
482 489 writel(readl(&udc->epcomp), &udc->epcomp);
  490 +#ifdef CONFIG_CI_UDC_HAS_HOSTPC
  491 + writel(readl(&udc->epsetupstat), &udc->epsetupstat);
  492 +#endif
483 493 writel(readl(&udc->epstat), &udc->epstat);
484 494 writel(0xffffffff, &udc->epflush);
485 495  
486 496  
... ... @@ -521,7 +531,11 @@
521 531 int max = 64;
522 532 int speed = USB_SPEED_FULL;
523 533  
  534 +#ifdef CONFIG_CI_UDC_HAS_HOSTPC
  535 + bit = (readl(&udc->hostpc1_devlc) >> 25) & 3;
  536 +#else
524 537 bit = (readl(&udc->portsc) >> 26) & 3;
  538 +#endif
525 539 DBG("-- portchange %x %s\n", bit, (bit == 2) ? "High" : "Full");
526 540 if (bit == 2) {
527 541 speed = USB_SPEED_HIGH;
528 542  
... ... @@ -538,7 +552,11 @@
538 552 printf("<UEI %x>\n", readl(&udc->epcomp));
539 553  
540 554 if ((n & STS_UI) || (n & STS_UEI)) {
  555 +#ifdef CONFIG_CI_UDC_HAS_HOSTPC
  556 + n = readl(&udc->epsetupstat);
  557 +#else
541 558 n = readl(&udc->epstat);
  559 +#endif
542 560 if (n & EPT_RX(0))
543 561 handle_setup();
544 562  
... ... @@ -699,7 +717,6 @@
699 717  
700 718 int usb_gadget_register_driver(struct usb_gadget_driver *driver)
701 719 {
702   - struct ci_udc *udc;
703 720 int ret;
704 721  
705 722 if (!driver)
706 723  
707 724  
... ... @@ -714,12 +731,18 @@
714 731 return ret;
715 732  
716 733 ret = ci_udc_probe();
  734 +#if defined(CONFIG_USB_EHCI_MX6) || defined(CONFIG_USB_EHCI_MXS)
  735 + /*
  736 + * FIXME: usb_lowlevel_init()->ehci_hcd_init() should be doing all
  737 + * HW-specific initialization, e.g. ULPI-vs-UTMI PHY selection
  738 + */
717 739 if (!ret) {
718   - udc = (struct ci_udc *)controller.ctrl->hcor;
  740 + struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
719 741  
720 742 /* select ULPI phy */
721 743 writel(PTS(PTS_ENABLE) | PFSC, &udc->portsc);
722 744 }
  745 +#endif
723 746  
724 747 ret = driver->bind(&controller.gadget);
725 748 if (ret) {
drivers/usb/gadget/ci_udc.h
... ... @@ -8,45 +8,74 @@
8 8  
9 9 #define NUM_ENDPOINTS 6
10 10  
  11 +#ifdef CONFIG_CI_UDC_HAS_HOSTPC
11 12 struct ci_udc {
12   -#define MICRO_8FRAME 0x8
13   -#define USBCMD_ITC(x) ((((x) > 0xff) ? 0xff : x) << 16)
14   -#define USBCMD_FS2 (1 << 15)
15   -#define USBCMD_RST (1 << 1)
16   -#define USBCMD_RUN (1)
  13 + u32 usbcmd; /* 0x130 */
  14 + u32 usbsts; /* 0x134 */
  15 + u32 pad1[3];
  16 + u32 devaddr; /* 0x144 */
  17 + u32 epinitaddr; /* 0x148 */
  18 + u32 pad2[10];
  19 + u32 portsc; /* 0x174 */
  20 + u32 pad178[(0x1b4 - (0x174 + 4)) / 4];
  21 + u32 hostpc1_devlc; /* 0x1b4 */
  22 + u32 pad1b8[(0x1f8 - (0x1b4 + 4)) / 4];
  23 + u32 usbmode; /* 0x1f8 */
  24 + u32 pad1fc[(0x208 - (0x1f8 + 4)) / 4];
  25 + u32 epsetupstat; /* 0x208 */
  26 + u32 epprime; /* 0x20c */
  27 + u32 epflush; /* 0x210 */
  28 + u32 epstat; /* 0x214 */
  29 + u32 epcomp; /* 0x218 */
  30 + u32 epctrl[16]; /* 0x21c */
  31 +};
  32 +#else
  33 +struct ci_udc {
17 34 u32 usbcmd; /* 0x140 */
18   -#define STS_SLI (1 << 8)
19   -#define STS_URI (1 << 6)
20   -#define STS_PCI (1 << 2)
21   -#define STS_UEI (1 << 1)
22   -#define STS_UI (1 << 0)
23 35 u32 usbsts; /* 0x144 */
24 36 u32 pad1[3];
25 37 u32 devaddr; /* 0x154 */
26 38 u32 epinitaddr; /* 0x158 */
27 39 u32 pad2[10];
28   -#define PTS_ENABLE 2
29   -#define PTS(x) (((x) & 0x3) << 30)
30   -#define PFSC (1 << 24)
31 40 u32 portsc; /* 0x184 */
32 41 u32 pad3[8];
33   -#define USBMODE_DEVICE 2
34 42 u32 usbmode; /* 0x1a8 */
35 43 u32 epstat; /* 0x1ac */
36   -#define EPT_TX(x) (1 << (((x) & 0xffff) + 16))
37   -#define EPT_RX(x) (1 << ((x) & 0xffff))
38 44 u32 epprime; /* 0x1b0 */
39 45 u32 epflush; /* 0x1b4 */
40 46 u32 pad4;
41 47 u32 epcomp; /* 0x1bc */
  48 + u32 epctrl[16]; /* 0x1c0 */
  49 +};
  50 +
  51 +#define PTS_ENABLE 2
  52 +#define PTS(x) (((x) & 0x3) << 30)
  53 +#define PFSC (1 << 24)
  54 +#endif
  55 +
  56 +#define MICRO_8FRAME 0x8
  57 +#define USBCMD_ITC(x) ((((x) > 0xff) ? 0xff : x) << 16)
  58 +#define USBCMD_FS2 (1 << 15)
  59 +#define USBCMD_RST (1 << 1)
  60 +#define USBCMD_RUN (1)
  61 +
  62 +#define STS_SLI (1 << 8)
  63 +#define STS_URI (1 << 6)
  64 +#define STS_PCI (1 << 2)
  65 +#define STS_UEI (1 << 1)
  66 +#define STS_UI (1 << 0)
  67 +
  68 +#define USBMODE_DEVICE 2
  69 +
  70 +#define EPT_TX(x) (1 << (((x) & 0xffff) + 16))
  71 +#define EPT_RX(x) (1 << ((x) & 0xffff))
  72 +
42 73 #define CTRL_TXE (1 << 23)
43 74 #define CTRL_TXR (1 << 22)
44 75 #define CTRL_RXE (1 << 7)
45 76 #define CTRL_RXR (1 << 6)
46 77 #define CTRL_TXT_BULK (2 << 18)
47 78 #define CTRL_RXT_BULK (2 << 2)
48   - u32 epctrl[16]; /* 0x1c0 */
49   -};
50 79  
51 80 struct ci_ep {
52 81 struct usb_ep ep;
drivers/usb/gadget/f_dfu.c
... ... @@ -24,6 +24,7 @@
24 24 #include <linux/usb/composite.h>
25 25  
26 26 #include <dfu.h>
  27 +#include <g_dnl.h>
27 28 #include "f_dfu.h"
28 29  
29 30 struct f_dfu {
... ... @@ -817,4 +818,6 @@
817 818  
818 819 return dfu_bind_config(c);
819 820 }
  821 +
  822 +DECLARE_GADGET_BIND_CALLBACK(usb_dnl_dfu, dfu_add);
drivers/usb/gadget/f_mass_storage.c
... ... @@ -243,7 +243,7 @@
243 243 #include <config.h>
244 244 #include <malloc.h>
245 245 #include <common.h>
246   -#include <usb.h>
  246 +#include <g_dnl.h>
247 247  
248 248 #include <linux/err.h>
249 249 #include <linux/usb/ch9.h>
... ... @@ -255,6 +255,7 @@
255 255 #include <linux/usb/gadget.h>
256 256 #include <linux/usb/composite.h>
257 257 #include <usb/lin_gadget_compat.h>
  258 +#include <g_dnl.h>
258 259  
259 260 /*------------------------------------------------------------------------*/
260 261  
261 262  
262 263  
... ... @@ -680,11 +681,11 @@
680 681 /* Handle CTRL+C */
681 682 if (ctrlc())
682 683 return -EPIPE;
683   -#ifdef CONFIG_USB_CABLE_CHECK
  684 +
684 685 /* Check cable connection */
685   - if (!usb_cable_connected())
  686 + if (!g_dnl_board_usb_cable_connected())
686 687 return -EIO;
687   -#endif
  688 +
688 689 k = 0;
689 690 }
690 691  
... ... @@ -2778,4 +2779,6 @@
2778 2779  
2779 2780 return 0;
2780 2781 }
  2782 +
  2783 +DECLARE_GADGET_BIND_CALLBACK(usb_dnl_ums, fsg_add);
drivers/usb/gadget/f_thor.c
... ... @@ -204,14 +204,14 @@
204 204  
205 205 static int download_tail(long long int left, int cnt)
206 206 {
  207 + struct dfu_entity *dfu_entity = dfu_get_entity(alt_setting_num);
207 208 void *transfer_buffer = dfu_get_buf();
208 209 int ret;
209 210  
210 211 debug("%s: left: %llu cnt: %d\n", __func__, left, cnt);
211 212  
212 213 if (left) {
213   - ret = dfu_write(dfu_get_entity(alt_setting_num),
214   - transfer_buffer, left, cnt++);
  214 + ret = dfu_write(dfu_entity, transfer_buffer, left, cnt++);
215 215 if (ret) {
216 216 error("DFU write failed [%d]: left: %llu", ret, left);
217 217 return ret;
218 218  
... ... @@ -225,11 +225,16 @@
225 225 * This also frees memory malloc'ed by dfu_get_buf(), so no explicit
226 226 * need fo call dfu_free_buf() is needed.
227 227 */
228   - ret = dfu_write(dfu_get_entity(alt_setting_num),
229   - transfer_buffer, 0, cnt);
  228 + ret = dfu_write(dfu_entity, transfer_buffer, 0, cnt);
230 229 if (ret)
231 230 error("DFU write failed [%d] cnt: %d", ret, cnt);
232 231  
  232 + ret = dfu_flush(dfu_entity, transfer_buffer, 0, cnt);
  233 + if (ret) {
  234 + error("DFU flush failed!");
  235 + return ret;
  236 + }
  237 +
233 238 return ret;
234 239 }
235 240  
... ... @@ -999,4 +1004,6 @@
999 1004 debug("%s:\n", __func__);
1000 1005 return thor_func_init(c);
1001 1006 }
  1007 +
  1008 +DECLARE_GADGET_BIND_CALLBACK(usb_dnl_thor, thor_add);
drivers/usb/gadget/g_dnl.c
... ... @@ -41,7 +41,6 @@
41 41  
42 42 #define DRIVER_VERSION "usb_dnl 2.0"
43 43  
44   -static const char shortname[] = "usb_dnl_";
45 44 static const char product[] = "USB download gadget";
46 45 static char g_dnl_serial[MAX_STRING_SERIAL];
47 46 static const char manufacturer[] = CONFIG_G_DNL_MANUFACTURER;
48 47  
49 48  
50 49  
... ... @@ -96,29 +95,36 @@
96 95 free(cdev->config);
97 96 cdev->config = NULL;
98 97 debug("%s: calling usb_gadget_disconnect for "
99   - "controller '%s'\n", shortname, gadget->name);
  98 + "controller '%s'\n", __func__, gadget->name);
100 99 usb_gadget_disconnect(gadget);
101 100  
102 101 return 0;
103 102 }
104 103  
  104 +static inline struct g_dnl_bind_callback *g_dnl_bind_callback_first(void)
  105 +{
  106 + return ll_entry_start(struct g_dnl_bind_callback,
  107 + g_dnl_bind_callbacks);
  108 +}
  109 +
  110 +static inline struct g_dnl_bind_callback *g_dnl_bind_callback_end(void)
  111 +{
  112 + return ll_entry_end(struct g_dnl_bind_callback,
  113 + g_dnl_bind_callbacks);
  114 +}
  115 +
105 116 static int g_dnl_do_config(struct usb_configuration *c)
106 117 {
107 118 const char *s = c->cdev->driver->name;
108   - int ret = -1;
  119 + struct g_dnl_bind_callback *callback = g_dnl_bind_callback_first();
109 120  
110 121 debug("%s: configuration: 0x%p composite dev: 0x%p\n",
111 122 __func__, c, c->cdev);
112 123  
113   - printf("GADGET DRIVER: %s\n", s);
114   - if (!strcmp(s, "usb_dnl_dfu"))
115   - ret = dfu_add(c);
116   - else if (!strcmp(s, "usb_dnl_ums"))
117   - ret = fsg_add(c);
118   - else if (!strcmp(s, "usb_dnl_thor"))
119   - ret = thor_add(c);
120   -
121   - return ret;
  124 + for (; callback != g_dnl_bind_callback_end(); callback++)
  125 + if (!strcmp(s, callback->usb_function_name))
  126 + return callback->fptr(c);
  127 + return -ENODEV;
122 128 }
123 129  
124 130 static int g_dnl_config_register(struct usb_composite_dev *cdev)
... ... @@ -152,6 +158,11 @@
152 158 return gcnum;
153 159 }
154 160  
  161 +__weak int g_dnl_board_usb_cable_connected(void)
  162 +{
  163 + return -EOPNOTSUPP;
  164 +}
  165 +
155 166 static int g_dnl_get_bcd_device_number(struct usb_composite_dev *cdev)
156 167 {
157 168 struct usb_gadget *gadget = cdev->gadget;
158 169  
... ... @@ -203,12 +214,12 @@
203 214 device_desc.bcdDevice = cpu_to_le16(gcnum);
204 215 else {
205 216 debug("%s: controller '%s' not recognized\n",
206   - shortname, gadget->name);
  217 + __func__, gadget->name);
207 218 device_desc.bcdDevice = __constant_cpu_to_le16(0x9999);
208 219 }
209 220  
210 221 debug("%s: calling usb_gadget_connect for "
211   - "controller '%s'\n", shortname, gadget->name);
  222 + "controller '%s'\n", __func__, gadget->name);
212 223 usb_gadget_connect(gadget);
213 224  
214 225 return 0;
215 226  
216 227  
217 228  
218 229  
219 230  
... ... @@ -227,36 +238,23 @@
227 238 .unbind = g_dnl_unbind,
228 239 };
229 240  
230   -int g_dnl_register(const char *type)
  241 +/*
  242 + * NOTICE:
  243 + * Registering via USB function name won't be necessary after rewriting
  244 + * g_dnl to support multiple USB functions.
  245 + */
  246 +int g_dnl_register(const char *name)
231 247 {
232   - /* The largest function name is 4 */
233   - static char name[sizeof(shortname) + 4];
234 248 int ret;
235 249  
236   - if (!strcmp(type, "dfu")) {
237   - strcpy(name, shortname);
238   - strcat(name, type);
239   - } else if (!strcmp(type, "ums")) {
240   - strcpy(name, shortname);
241   - strcat(name, type);
242   - } else if (!strcmp(type, "thor")) {
243   - strcpy(name, shortname);
244   - strcat(name, type);
245   - } else {
246   - printf("%s: unknown command: %s\n", __func__, type);
247   - return -EINVAL;
248   - }
249   -
  250 + debug("%s: g_dnl_driver.name = %s\n", __func__, name);
250 251 g_dnl_driver.name = name;
251 252  
252   - debug("%s: g_dnl_driver.name: %s\n", __func__, g_dnl_driver.name);
253 253 ret = usb_composite_register(&g_dnl_driver);
254   -
255 254 if (ret) {
256 255 printf("%s: failed!, error: %d\n", __func__, ret);
257 256 return ret;
258 257 }
259   -
260 258 return 0;
261 259 }
262 260  
drivers/usb/gadget/storage_common.c
... ... @@ -311,7 +311,11 @@
311 311 #define DELAYED_STATUS (EP0_BUFSIZE + 999) /* An impossibly large value */
312 312  
313 313 /* Number of buffers we will use. 2 is enough for double-buffering */
  314 +#ifndef CONFIG_CI_UDC
314 315 #define FSG_NUM_BUFFERS 2
  316 +#else
  317 +#define FSG_NUM_BUFFERS 1 /* ci_udc only allows 1 req per ep at present */
  318 +#endif
315 319  
316 320 /* Default size of buffer length. */
317 321 #define FSG_BUFLEN ((u32)16384)
drivers/usb/gadget/usbstring.c
... ... @@ -108,6 +108,9 @@
108 108 struct usb_string *s;
109 109 int len;
110 110  
  111 + if (!table)
  112 + return -EINVAL;
  113 +
111 114 /* descriptor 0 has the language id */
112 115 if (id == 0) {
113 116 buf[0] = 4;
drivers/usb/host/Makefile
... ... @@ -36,6 +36,7 @@
36 36 obj-$(CONFIG_USB_EHCI_SPEAR) += ehci-spear.o
37 37 obj-$(CONFIG_USB_EHCI_TEGRA) += ehci-tegra.o
38 38 obj-$(CONFIG_USB_EHCI_VCT) += ehci-vct.o
  39 +obj-$(CONFIG_USB_EHCI_RMOBILE) += ehci-rmobile.o
39 40  
40 41 # xhci
41 42 obj-$(CONFIG_USB_XHCI) += xhci.o xhci-mem.o xhci-ring.o
drivers/usb/host/ehci-exynos.c
... ... @@ -197,7 +197,8 @@
197 197  
198 198 #ifdef CONFIG_OF_CONTROL
199 199 /* setup the Vbus gpio here */
200   - if (!fdtdec_setup_gpio(&ctx->vbus_gpio))
  200 + if (fdt_gpio_isvalid(&ctx->vbus_gpio) &&
  201 + !fdtdec_setup_gpio(&ctx->vbus_gpio))
201 202 gpio_direction_output(ctx->vbus_gpio.gpio, 1);
202 203 #endif
203 204  
drivers/usb/host/ehci-hcd.c
... ... @@ -998,8 +998,8 @@
998 998 if (!ehcic[index].periodic_list)
999 999 return -ENOMEM;
1000 1000 for (i = 0; i < 1024; i++) {
1001   - ehcic[index].periodic_list[i] = (uint32_t)periodic
1002   - | QH_LINK_TYPE_QH;
  1001 + ehcic[index].periodic_list[i] = cpu_to_hc32((uint32_t)periodic
  1002 + | QH_LINK_TYPE_QH);
1003 1003 }
1004 1004  
1005 1005 flush_dcache_range((uint32_t)ehcic[index].periodic_list,
... ... @@ -1089,7 +1089,7 @@
1089 1089 struct qTD *tds;
1090 1090 };
1091 1091  
1092   -#define NEXT_QH(qh) (struct QH *)((qh)->qh_link & ~0x1f)
  1092 +#define NEXT_QH(qh) (struct QH *)(hc32_to_cpu((qh)->qh_link) & ~0x1f)
1093 1093  
1094 1094 static int
1095 1095 enable_periodic(struct ehci_ctrl *ctrl)
1096 1096  
1097 1097  
1098 1098  
1099 1099  
1100 1100  
1101 1101  
1102 1102  
1103 1103  
... ... @@ -1184,41 +1184,47 @@
1184 1184 struct qTD *td = result->tds + i;
1185 1185 void **buf = &qh->buffer;
1186 1186  
1187   - qh->qh_link = (uint32_t)(qh+1) | QH_LINK_TYPE_QH;
  1187 + qh->qh_link = cpu_to_hc32((uint32_t)(qh+1) | QH_LINK_TYPE_QH);
1188 1188 if (i == queuesize - 1)
1189   - qh->qh_link = QH_LINK_TERMINATE;
  1189 + qh->qh_link = cpu_to_hc32(QH_LINK_TERMINATE);
1190 1190  
1191   - qh->qh_overlay.qt_next = (uint32_t)td;
1192   - qh->qh_overlay.qt_altnext = QT_NEXT_TERMINATE;
1193   - qh->qh_endpt1 = (0 << 28) | /* No NAK reload (ehci 4.9) */
  1191 + qh->qh_overlay.qt_next = cpu_to_hc32((uint32_t)td);
  1192 + qh->qh_overlay.qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE);
  1193 + qh->qh_endpt1 =
  1194 + cpu_to_hc32((0 << 28) | /* No NAK reload (ehci 4.9) */
1194 1195 (usb_maxpacket(dev, pipe) << 16) | /* MPS */
1195 1196 (1 << 14) |
1196 1197 QH_ENDPT1_EPS(ehci_encode_speed(dev->speed)) |
1197 1198 (usb_pipeendpoint(pipe) << 8) | /* Endpoint Number */
1198   - (usb_pipedevice(pipe) << 0);
1199   - qh->qh_endpt2 = (1 << 30) | /* 1 Tx per mframe */
1200   - (1 << 0); /* S-mask: microframe 0 */
  1199 + (usb_pipedevice(pipe) << 0));
  1200 + qh->qh_endpt2 = cpu_to_hc32((1 << 30) | /* 1 Tx per mframe */
  1201 + (1 << 0)); /* S-mask: microframe 0 */
1201 1202 if (dev->speed == USB_SPEED_LOW ||
1202 1203 dev->speed == USB_SPEED_FULL) {
1203 1204 debug("TT: port: %d, hub address: %d\n",
1204 1205 dev->portnr, dev->parent->devnum);
1205   - qh->qh_endpt2 |= (dev->portnr << 23) |
  1206 + qh->qh_endpt2 |= cpu_to_hc32((dev->portnr << 23) |
1206 1207 (dev->parent->devnum << 16) |
1207   - (0x1c << 8); /* C-mask: microframes 2-4 */
  1208 + (0x1c << 8)); /* C-mask: microframes 2-4 */
1208 1209 }
1209 1210  
1210   - td->qt_next = QT_NEXT_TERMINATE;
1211   - td->qt_altnext = QT_NEXT_TERMINATE;
  1211 + td->qt_next = cpu_to_hc32(QT_NEXT_TERMINATE);
  1212 + td->qt_altnext = cpu_to_hc32(QT_NEXT_TERMINATE);
1212 1213 debug("communication direction is '%s'\n",
1213 1214 usb_pipein(pipe) ? "in" : "out");
1214   - td->qt_token = (elementsize << 16) |
  1215 + td->qt_token = cpu_to_hc32((elementsize << 16) |
1215 1216 ((usb_pipein(pipe) ? 1 : 0) << 8) | /* IN/OUT token */
1216   - 0x80; /* active */
1217   - td->qt_buffer[0] = (uint32_t)buffer + i * elementsize;
1218   - td->qt_buffer[1] = (td->qt_buffer[0] + 0x1000) & ~0xfff;
1219   - td->qt_buffer[2] = (td->qt_buffer[0] + 0x2000) & ~0xfff;
1220   - td->qt_buffer[3] = (td->qt_buffer[0] + 0x3000) & ~0xfff;
1221   - td->qt_buffer[4] = (td->qt_buffer[0] + 0x4000) & ~0xfff;
  1217 + 0x80); /* active */
  1218 + td->qt_buffer[0] =
  1219 + cpu_to_hc32((uint32_t)buffer + i * elementsize);
  1220 + td->qt_buffer[1] =
  1221 + cpu_to_hc32((td->qt_buffer[0] + 0x1000) & ~0xfff);
  1222 + td->qt_buffer[2] =
  1223 + cpu_to_hc32((td->qt_buffer[0] + 0x2000) & ~0xfff);
  1224 + td->qt_buffer[3] =
  1225 + cpu_to_hc32((td->qt_buffer[0] + 0x3000) & ~0xfff);
  1226 + td->qt_buffer[4] =
  1227 + cpu_to_hc32((td->qt_buffer[0] + 0x4000) & ~0xfff);
1222 1228  
1223 1229 *buf = buffer + i * elementsize;
1224 1230 }
... ... @@ -1241,7 +1247,7 @@
1241 1247 /* hook up to periodic list */
1242 1248 struct QH *list = &ctrl->periodic_queue;
1243 1249 result->last->qh_link = list->qh_link;
1244   - list->qh_link = (uint32_t)result->first | QH_LINK_TYPE_QH;
  1250 + list->qh_link = cpu_to_hc32((uint32_t)result->first | QH_LINK_TYPE_QH);
1245 1251  
1246 1252 flush_dcache_range((uint32_t)result->last,
1247 1253 ALIGN_END_ADDR(struct QH, result->last, 1));
... ... @@ -1280,7 +1286,7 @@
1280 1286 /* still active */
1281 1287 invalidate_dcache_range((uint32_t)cur,
1282 1288 ALIGN_END_ADDR(struct QH, cur, 1));
1283   - if (cur->qh_overlay.qt_token & 0x80) {
  1289 + if (cur->qh_overlay.qt_token & cpu_to_hc32(0x80)) {
1284 1290 debug("Exit poll_int_queue with no completed intr transfer. "
1285 1291 "token is %x\n", cur->qh_overlay.qt_token);
1286 1292 return NULL;
... ... @@ -1311,7 +1317,7 @@
1311 1317  
1312 1318 struct QH *cur = &ctrl->periodic_queue;
1313 1319 timeout = get_timer(0) + 500; /* abort after 500ms */
1314   - while (!(cur->qh_link & QH_LINK_TERMINATE)) {
  1320 + while (!(cur->qh_link & cpu_to_hc32(QH_LINK_TERMINATE))) {
1315 1321 debug("considering %p, with qh_link %x\n", cur, cur->qh_link);
1316 1322 if (NEXT_QH(cur) == queue->first) {
1317 1323 debug("found candidate. removing from chain\n");
drivers/usb/host/ehci-rmobile.c
  1 +/*
  2 + * EHCI HCD (Host Controller Driver) for USB.
  3 + *
  4 + * Copyright (C) 2013,2014 Renesas Electronics Corporation
  5 + * Copyright (C) 2014 Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
  6 + *
  7 + * SPDX-License-Identifier: GPL-2.0
  8 + */
  9 +
  10 +#include <common.h>
  11 +#include <asm/io.h>
  12 +#include <asm/arch/ehci-rmobile.h>
  13 +#include "ehci.h"
  14 +
  15 +#if defined(CONFIG_R8A7740)
  16 +static u32 usb_base_address[CONFIG_USB_MAX_CONTROLLER_COUNT] = {
  17 + 0xC6700000
  18 +};
  19 +#elif defined(CONFIG_R8A7790)
  20 +static u32 usb_base_address[CONFIG_USB_MAX_CONTROLLER_COUNT] = {
  21 + 0xEE080000, /* USB0 (EHCI) */
  22 + 0xEE0A0000, /* USB1 */
  23 + 0xEE0C0000, /* USB2 */
  24 + 0xEE000000 /* USB3 (USB3.0 Host)*/
  25 +};
  26 +#elif defined(CONFIG_R8A7791)
  27 +static u32 usb_base_address[CONFIG_USB_MAX_CONTROLLER_COUNT] = {
  28 + 0xEE080000, /* USB0 (EHCI) */
  29 + 0xEE0C0000, /* USB1 */
  30 + 0xEE000000 /* USB3 (USB3.0 Host)*/
  31 +};
  32 +#else
  33 +#error rmobile EHCI USB driver not supported on this platform
  34 +#endif
  35 +
  36 +int ehci_hcd_stop(int index)
  37 +{
  38 + int i;
  39 + u32 base;
  40 + struct ahbcom_pci_bridge *ahbcom_pci;
  41 +
  42 + base = usb_base_address[index];
  43 + ahbcom_pci = (struct ahbcom_pci_bridge *)(base + AHBPCI_OFFSET);
  44 + writel(0, &ahbcom_pci->ahb_bus_ctr);
  45 +
  46 + /* reset ehci */
  47 + setbits_le32(base + EHCI_USBCMD, CMD_RESET);
  48 + for (i = 100; i > 0; i--) {
  49 + if (!(readl(base + EHCI_USBCMD) & CMD_RESET))
  50 + break;
  51 + udelay(100);
  52 + }
  53 +
  54 + if (!i)
  55 + printf("error : ehci(%d) reset failed.\n", index);
  56 +
  57 + if (index == (CONFIG_USB_MAX_CONTROLLER_COUNT - 1))
  58 + setbits_le32(SMSTPCR7, SMSTPCR703);
  59 +
  60 + return 0;
  61 +}
  62 +
  63 +int ehci_hcd_init(int index, enum usb_init_type init,
  64 + struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  65 +{
  66 + u32 base;
  67 + u32 phys_base;
  68 + struct rmobile_ehci_reg *rehci;
  69 + struct ahbcom_pci_bridge *ahbcom_pci;
  70 + struct ahbconf_pci_bridge *ahbconf_pci;
  71 + struct ahb_pciconf *ahb_pciconf_ohci;
  72 + struct ahb_pciconf *ahb_pciconf_ehci;
  73 + uint32_t cap_base;
  74 +
  75 + base = usb_base_address[index];
  76 + phys_base = base;
  77 + if (index == 0)
  78 + clrbits_le32(SMSTPCR7, SMSTPCR703);
  79 +
  80 + rehci = (struct rmobile_ehci_reg *)(base + EHCI_OFFSET);
  81 + ahbcom_pci = (struct ahbcom_pci_bridge *)(base + AHBPCI_OFFSET);
  82 + ahbconf_pci =
  83 + (struct ahbconf_pci_bridge *)(base + PCI_CONF_AHBPCI_OFFSET);
  84 + ahb_pciconf_ohci = (struct ahb_pciconf *)(base + PCI_CONF_OHCI_OFFSET);
  85 + ahb_pciconf_ehci = (struct ahb_pciconf *)(base + PCI_CONF_EHCI_OFFSET);
  86 +
  87 + /* Clock & Reset & Direct Power Down */
  88 + clrsetbits_le32(&ahbcom_pci->usbctr,
  89 + (DIRPD | PCICLK_MASK | USBH_RST), USBCTR_WIN_SIZE_1GB);
  90 + clrbits_le32(&ahbcom_pci->usbctr, PLL_RST);
  91 +
  92 + /* AHB-PCI Bridge Communication Registers */
  93 + writel(AHB_BUS_CTR_INIT, &ahbcom_pci->ahb_bus_ctr);
  94 + writel((CONFIG_SYS_SDRAM_BASE & 0xf0000000) | PCIAHB_WIN_PREFETCH,
  95 + &ahbcom_pci->pciahb_win1_ctr);
  96 + writel(0xf0000000 | PCIAHB_WIN_PREFETCH,
  97 + &ahbcom_pci->pciahb_win2_ctr);
  98 + writel(phys_base | PCIWIN2_PCICMD, &ahbcom_pci->ahbpci_win2_ctr);
  99 +
  100 + setbits_le32(&ahbcom_pci->pci_arbiter_ctr,
  101 + PCIBP_MODE | PCIREQ1 | PCIREQ0);
  102 +
  103 + /* PCI Configuration Registers for AHBPCI */
  104 + writel(PCIWIN1_PCICMD | AHB_CFG_AHBPCI,
  105 + &ahbcom_pci->ahbpci_win1_ctr);
  106 + writel(phys_base + AHBPCI_OFFSET, &ahbconf_pci->basead);
  107 + writel(CONFIG_SYS_SDRAM_BASE & 0xf0000000, &ahbconf_pci->win1_basead);
  108 + writel(0xf0000000, &ahbconf_pci->win2_basead);
  109 + writel(SERREN | PERREN | MASTEREN | MEMEN,
  110 + &ahbconf_pci->cmnd_sts);
  111 +
  112 + /* PCI Configuration Registers for EHCI */
  113 + writel(PCIWIN1_PCICMD | AHB_CFG_HOST, &ahbcom_pci->ahbpci_win1_ctr);
  114 + writel(phys_base + OHCI_OFFSET, &ahb_pciconf_ohci->basead);
  115 + writel(phys_base + EHCI_OFFSET, &ahb_pciconf_ehci->basead);
  116 + writel(SERREN | PERREN | MASTEREN | MEMEN,
  117 + &ahb_pciconf_ohci->cmnd_sts);
  118 + writel(SERREN | PERREN | MASTEREN | MEMEN,
  119 + &ahb_pciconf_ehci->cmnd_sts);
  120 +
  121 + /* Enable PCI interrupt */
  122 + setbits_le32(&ahbcom_pci->pci_int_enable,
  123 + USBH_PMEEN | USBH_INTBEN | USBH_INTAEN);
  124 +
  125 + *hccr = (struct ehci_hccr *)((uint32_t)&rehci->hciversion);
  126 + cap_base = ehci_readl(&(*hccr)->cr_capbase);
  127 + *hcor = (struct ehci_hcor *)((uint32_t)*hccr + HC_LENGTH(cap_base));
  128 +
  129 + return 0;
  130 +}
drivers/usb/host/xhci-exynos5.c
... ... @@ -298,7 +298,8 @@
298 298  
299 299 #ifdef CONFIG_OF_CONTROL
300 300 /* setup the Vbus gpio here */
301   - if (!fdtdec_setup_gpio(&ctx->vbus_gpio))
  301 + if (fdt_gpio_isvalid(&ctx->vbus_gpio) &&
  302 + !fdtdec_setup_gpio(&ctx->vbus_gpio))
302 303 gpio_direction_output(ctx->vbus_gpio.gpio, 1);
303 304 #endif
304 305  
drivers/usb/musb-new/musb_uboot.c
... ... @@ -204,7 +204,10 @@
204 204  
205 205 int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
206 206 {
207   - /* TODO: implement me */
  207 + if (driver->disconnect)
  208 + driver->disconnect(&gadget->g);
  209 + if (driver->unbind)
  210 + driver->unbind(&gadget->g);
208 211 return 0;
209 212 }
210 213 #endif /* CONFIG_MUSB_GADGET */
include/configs/am335x_evm.h
... ... @@ -312,6 +312,7 @@
312 312 #endif
313 313  
314 314 /* USB Device Firmware Update support */
  315 +#ifndef CONFIG_SPL_BUILD
315 316 #define CONFIG_DFU_FUNCTION
316 317 #define CONFIG_DFU_MMC
317 318 #define CONFIG_CMD_DFU
... ... @@ -320,10 +321,10 @@
320 321 "boot part 0 1;" \
321 322 "rootfs part 0 2;" \
322 323 "MLO fat 0 1;" \
323   - "MLO.raw mmc 100 100;" \
324   - "u-boot.img.raw mmc 300 400;" \
325   - "spl-os-args.raw mmc 80 80;" \
326   - "spl-os-image.raw mmc 900 2000;" \
  324 + "MLO.raw mmc 0x100 0x100;" \
  325 + "u-boot.img.raw mmc 0x300 0x400;" \
  326 + "spl-os-args.raw mmc 0x80 0x80;" \
  327 + "spl-os-image.raw mmc 0x900 0x2000;" \
327 328 "spl-os-args fat 0 1;" \
328 329 "spl-os-image fat 0 1;" \
329 330 "u-boot.img fat 0 1;" \
... ... @@ -354,6 +355,7 @@
354 355 DFU_ALT_INFO_MMC \
355 356 DFU_ALT_INFO_RAM \
356 357 DFU_ALT_INFO_NAND
  358 +#endif
357 359  
358 360 /*
359 361 * Default to using SPI for environment, etc.
include/configs/exynos4-dt.h
... ... @@ -127,7 +127,6 @@
127 127 #define CONFIG_USB_GADGET_S3C_UDC_OTG
128 128 #define CONFIG_USB_GADGET_DUALSPEED
129 129 #define CONFIG_USB_GADGET_VBUS_DRAW 2
130   -#define CONFIG_USB_CABLE_CHECK
131 130  
132 131 #define CONFIG_CMD_USB_MASS_STORAGE
133 132 #define CONFIG_USB_GADGET_MASS_STORAGE
include/configs/trats.h
... ... @@ -101,7 +101,7 @@
101 101 "name="PARTS_UMS",size=-,uuid=${uuid_gpt_"PARTS_UMS"}\0" \
102 102  
103 103 #define CONFIG_DFU_ALT \
104   - "u-boot mmc 80 400;" \
  104 + "u-boot raw 0x80 0x400;" \
105 105 "uImage ext4 0 2;" \
106 106 "modem.bin ext4 0 2;" \
107 107 "exynos4210-trats.dtb ext4 0 2;" \
... ... @@ -112,7 +112,7 @@
112 112 ""PARTS_ROOT" part 0 5;" \
113 113 ""PARTS_DATA" part 0 6;" \
114 114 ""PARTS_UMS" part 0 7;" \
115   - "params.bin mmc 0x38 0x8 0x38 0x8\0""
  115 + "params.bin raw 0x38 0x8 0x38 0x8\0""
116 116  
117 117 #define CONFIG_EXTRA_ENV_SETTINGS \
118 118 "bootk=" \
include/configs/trats2.h
... ... @@ -91,7 +91,7 @@
91 91 "name="PARTS_UMS",size=-,uuid=${uuid_gpt_"PARTS_UMS"}\0" \
92 92  
93 93 #define CONFIG_DFU_ALT \
94   - "u-boot mmc 80 800;" \
  94 + "u-boot raw 0x80 0x800;" \
95 95 "uImage ext4 0 2;" \
96 96 "modem.bin ext4 0 2;" \
97 97 "exynos4412-trats2.dtb ext4 0 2;" \
... ... @@ -102,7 +102,7 @@
102 102 ""PARTS_ROOT" part 0 5;" \
103 103 ""PARTS_DATA" part 0 6;" \
104 104 ""PARTS_UMS" part 0 7;" \
105   - "params.bin mmc 0x38 0x8 0x38 0x8\0""
  105 + "params.bin raw 0x38 0x8 0x38 0x8\0""
106 106  
107 107 #define CONFIG_EXTRA_ENV_SETTINGS \
108 108 "bootk=" \
... ... @@ -64,11 +64,6 @@
64 64 unsigned int size;
65 65 };
66 66  
67   -static inline unsigned int get_mmc_blk_size(int dev)
68   -{
69   - return find_mmc_device(dev)->read_bl_len;
70   -}
71   -
72 67 #define DFU_NAME_SIZE 32
73 68 #define DFU_CMD_BUF_SIZE 128
74 69 #ifndef CONFIG_SYS_DFU_DATA_BUF_SIZE
75 70  
... ... @@ -173,13 +168,6 @@
173 168 }
174 169 #endif
175 170  
176   -#ifdef CONFIG_DFU_FUNCTION
177 171 int dfu_add(struct usb_configuration *c);
178   -#else
179   -int dfu_add(struct usb_configuration *c)
180   -{
181   - return 0;
182   -}
183   -#endif
184 172 #endif /* __DFU_ENTITY_H_ */
... ... @@ -10,7 +10,31 @@
10 10  
11 11 #include <linux/usb/ch9.h>
12 12 #include <linux/usb/gadget.h>
  13 +#include <linux/usb/composite.h>
  14 +#include <linker_lists.h>
  15 +
  16 +/*
  17 + * @usb_fname: unescaped USB function name
  18 + * @callback_ptr: bind callback, one per function name
  19 + */
  20 +#define DECLARE_GADGET_BIND_CALLBACK(usb_fname, callback_ptr) \
  21 + ll_entry_declare(struct g_dnl_bind_callback, \
  22 + __usb_function_name_##usb_fname, \
  23 + g_dnl_bind_callbacks) = { \
  24 + .usb_function_name = #usb_fname, \
  25 + .fptr = callback_ptr \
  26 + }
  27 +
  28 +typedef int (*g_dnl_bind_callback_f)(struct usb_configuration *);
  29 +
  30 +/* used in Gadget downloader callback linker list */
  31 +struct g_dnl_bind_callback {
  32 + const char *usb_function_name;
  33 + g_dnl_bind_callback_f fptr;
  34 +};
  35 +
13 36 int g_dnl_bind_fixup(struct usb_device_descriptor *, const char *);
  37 +int g_dnl_board_usb_cable_connected(void);
14 38 int g_dnl_register(const char *s);
15 39 void g_dnl_unregister(void);
16 40 void g_dnl_set_serialnumber(char *);
include/linker_lists.h
... ... @@ -228,7 +228,7 @@
228 228 * and it's name.
229 229 *
230 230 * Example:
231   - * ll_entry_declare(struct my_sub_cmd, my_sub_cmd, cmd_sub, cmd.sub) = {
  231 + * ll_entry_declare(struct my_sub_cmd, my_sub_cmd, cmd_sub) = {
232 232 * .x = 3,
233 233 * .y = 4,
234 234 * };
... ... @@ -12,6 +12,7 @@
12 12  
13 13 #include <linux/list.h>
14 14 #include <linux/compiler.h>
  15 +#include <part.h>
15 16  
16 17 #define SD_VERSION_SD 0x20000
17 18 #define SD_VERSION_3 (SD_VERSION_SD | 0x300)
... ... @@ -8,6 +8,7 @@
8 8 #define _PART_H
9 9  
10 10 #include <ide.h>
  11 +#include <common.h>
11 12  
12 13 typedef struct block_dev_desc {
13 14 int if_type; /* type of the interface */
... ... @@ -15,14 +15,6 @@
15 15  
16 16 int thor_handle(void);
17 17 int thor_init(void);
18   -
19   -#ifdef CONFIG_THOR_FUNCTION
20 18 int thor_add(struct usb_configuration *c);
21   -#else
22   -int thor_add(struct usb_configuration *c)
23   -{
24   - return 0;
25   -}
26   -#endif
27 19 #endif /* __THOR_H_ */
... ... @@ -197,16 +197,6 @@
197 197 */
198 198 int board_usb_cleanup(int index, enum usb_init_type init);
199 199  
200   -/*
201   - * If CONFIG_USB_CABLE_CHECK is set then this function
202   - * should be defined in board file.
203   - *
204   - * @return 1 if cable is connected and 0 otherwise.
205   - */
206   -#ifdef CONFIG_USB_CABLE_CHECK
207   -int usb_cable_connected(void);
208   -#endif
209   -
210 200 #ifdef CONFIG_USB_STORAGE
211 201  
212 202 #define USB_MAX_STOR_DEV 5
include/usb_mass_storage.h
... ... @@ -40,14 +40,6 @@
40 40 void fsg_cleanup(void);
41 41 struct ums *ums_init(unsigned int);
42 42 int fsg_main_thread(void *);
43   -
44   -#ifdef CONFIG_USB_GADGET_MASS_STORAGE
45 43 int fsg_add(struct usb_configuration *c);
46   -#else
47   -int fsg_add(struct usb_configuration *c)
48   -{
49   - return 0;
50   -}
51   -#endif
52 44 #endif /* __USB_MASS_STORAGE_H__ */